@co-author 
  @comment   
  @copyright Copyright (c) 2011-2013 Plugin Monitoring for GLPI team
  @license   AGPL License 3.0 or (at your option) any later version
             http://www.gnu.org/licenses/agpl-3.0-standalone.html
  @link      https://forge.indepnet.net/projects/monitoring/
  @since     2011

  ------------------------------------------------------------------------
*/
include "../../../inc/includes.php";
Session::checkCentralAccess();
Html::header(__('Monitoring', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "monitoring", "servicedef");
$pmServicedef = new PluginMonitoringServicedef();
if (isset($_POST["add"])) {
    $pmServicedef->add($_POST);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        $pmServicedef->update($_POST);
        Html::back();
    } else {
        if (isset($_POST["delete"])) {
            $pmServicedef->delete($_POST);
            Html::back();
        }
    }
}
if (isset($_GET["id"])) {
    $pmServicedef->showForm($_GET["id"]);
} else {
         foreach ($_POST as $key => $value) {
             if (strstr($key, "arg" . $id . "||")) {
                 $a_ex = explode("||", $key);
                 $a_arguments[$a_ex[1]] = $value;
             }
         }
         $input['arguments'] = exportArrayToDB($a_arguments);
         $pMonitoringService->update($input);
     }
 } else {
     $pMonitoringServicedef = new PluginMonitoringServicedef();
     if ($_POST['plugin_monitoring_servicedefs_id'] == '0') {
         // Add the service
         $id = $_POST['id'];
         unset($_POST['id']);
         $_POST['plugin_monitoring_servicedefs_id'] = $pMonitoringServicedef->add($_POST);
         $_POST['id'] = $id;
     } else {
         $pMonitoringServicedef->getFromDB($_POST['plugin_monitoring_servicedefs_id']);
         if ($pMonitoringServicedef->fields['is_template'] == '0') {
             $pMonitoringServicedef->update($_POST);
         }
     }
     if (isset($_POST['arg'])) {
         $_POST['arguments'] = exportArrayToDB($_POST['arg']);
     }
     if (isset($_POST['alias_commandservice'])) {
         $_POST['alias_command'] = $_POST['alias_commandservice'];
     }
     $pMonitoringService->update($_POST);
 }