/**
  * Set parameters
  *
  * @param string $parameters
  * @return void
  * @throws CentreonClapiException
  */
 public function setparam($parameters = null)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < self::NB_UPDATE_PARAMS) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $serviceDesc = $params[0];
     $elements = $this->object->getList("service_id", -1, 0, null, null, array('service_description' => $serviceDesc, 'service_register' => 0), "AND");
     if (!count($elements)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $serviceDesc);
     }
     $objectId = $elements[0]['service_id'];
     $extended = false;
     $commandObject = new CentreonCommand();
     switch ($params[1]) {
         case "check_command":
             $params[1] = "command_command_id";
             $params[2] = $commandObject->getId($params[2]);
             break;
         case "check_command_arguments":
             $params[1] = "command_command_id_arg";
             break;
         case "event_handler":
             $params[1] = "command_command_id2";
             $params[2] = $commandObject->getId($params[2]);
             break;
         case "event_handler_arguments":
             $params[1] = "command_command_id_arg2";
             break;
         case "check_period":
             $params[1] = "timeperiod_tp_id";
             $tpObj = new CentreonTimePeriod();
             $params[2] = $tpObj->getTimeperiodId($params[2]);
             break;
         case "notification_period":
             $params[1] = "timeperiod_tp_id2";
             $tpObj = new CentreonTimePeriod();
             $params[2] = $tpObj->getTimeperiodId($params[2]);
             break;
         case "flap_detection_options":
             break;
         case "template":
             $params[1] = "service_template_model_stm_id";
             $tmp = $this->object->getList($this->object->getPrimaryKey(), -1, 0, null, null, array('service_description' => $params[2], 'service_register' => '0'), "AND");
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]);
             }
             $params[2] = $tmp[0][$this->object->getPrimaryKey()];
             break;
         case "graphtemplate":
             $extended = true;
             $graphObj = new Centreon_Object_Graph_Template();
             $tmp = $graphObj->getIdByParameter($graphObj->getUniqueLabelField(), $params[2]);
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]);
             }
             $params[1] = "graph_id";
             $params[2] = $tmp[0];
             break;
         case "contact_additive_inheritance":
             break;
         case "cg_additive_inheritance":
             break;
         case "notes":
             $extended = true;
             break;
         case "notes_url":
             $extended = true;
             break;
         case "action_url":
             $extended = true;
             break;
         case "icon_image":
             $extended = true;
             break;
         case "icon_image_alt":
             $extended = true;
             break;
         default:
             if (!preg_match("/^service_/", $params[1])) {
                 $params[1] = "service_" . $params[1];
             }
             break;
     }
     if ($extended == false) {
         $updateParams = array($params[1] => $params[2]);
         parent::setparam($objectId, $updateParams);
     } else {
         if ($params[1] != "graph_id") {
             $params[1] = "esi_" . $params[1];
             if ($params[1] == "esi_icon_image") {
                 if ($params[2]) {
                     $id = CentreonUtils::getImageId($params[2]);
                     if (is_null($id)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]);
                     }
                     $params[2] = $id;
                 } else {
                     $params[2] = null;
                 }
             }
         }
         $extended = new Centreon_Object_Service_Extended();
         $extended->update($objectId, array($params[1] => $params[2]));
     }
 }
 /**
  * Export data
  *
  * @param string $parameters
  * @return void
  */
 public function export()
 {
     $elements = $this->object->getList("*", -1, 0);
     foreach ($elements as $element) {
         $addStr = $this->action . $this->delim . "ADD";
         foreach ($this->insertParams as $param) {
             $addStr .= $this->delim . $element[$param];
         }
         $addStr .= "\n";
         echo $addStr;
         foreach ($element as $parameter => $value) {
             if (!in_array($parameter, $this->exportExcludedParams)) {
                 if (!is_null($value) && $value != "") {
                     $value = CentreonUtils::convertLineBreak($value);
                     echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $parameter . $this->delim . $value . "\n";
                 }
             }
             if ($parameter == "graph_id" && !empty($value)) {
                 $graphObject = new Centreon_Object_Graph_Template();
                 $tmp = $graphObject->getParameters($value, array($graphObject->getUniqueLabelField()));
                 if (!count($tmp)) {
                     throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $value);
                 }
                 $v = $tmp[$graphObject->getUniqueLabelField()];
                 $v = CentreonUtils::convertLineBreak($v);
                 echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $this->getClapiActionName($parameter) . $this->delim . $v . "\n";
             }
         }
     }
 }
 /**
  * Set parameters
  *
  * @param string $parameters
  * @throws CentreonClapiException
  */
 public function setparam($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < self::NB_UPDATE_PARAMS) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) {
         if (!preg_match("/^command_/", $params[1])) {
             if (!in_array($params[1], array('graph', 'enable_shell'))) {
                 $params[1] = "command_" . $params[1];
             } elseif ($params[1] == "graph") {
                 $params[1] = "graph_id";
             }
         }
         if ($params[1] == "command_type") {
             if (!isset($this->typeConversion[$params[2]])) {
                 throw new CentreonClapiException(self::UNKNOWN_CMD_TYPE . ":" . $params[2]);
             }
             if (!is_numeric($params[2])) {
                 $params[2] = $this->typeConversion[$params[2]];
             }
         } elseif ($params[1] == "graph_id") {
             $graphObject = new Centreon_Object_Graph_Template();
             $tmp = $graphObject->getIdByParameter($graphObject->getUniqueLabelField(), $params[2]);
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]);
             }
             $params[2] = $tmp[0];
         }
         $updateParams = array($params[1] => $params[2]);
         parent::setparam($objectId, $updateParams);
     } else {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]);
     }
 }
 /**
  * Set parameters
  *
  * @param string $parameters
  * @return void
  * @throws CentreonClapiException
  */
 public function setparam($parameters = null)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < self::NB_UPDATE_PARAMS) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $hostName = $params[0];
     $serviceDesc = $params[1];
     $relObject = new Centreon_Object_Relation_Host_Service();
     $elements = $relObject->getMergedParameters(array("host_id"), array("service_id"), -1, 0, null, null, array("host_name" => $hostName, "service_description" => $serviceDesc), "AND");
     if (!count($elements)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $hostName . "/" . $serviceDesc);
     }
     $objectId = $elements[0]['service_id'];
     $extended = false;
     $commandObject = new CentreonCommand();
     switch ($params[2]) {
         case "check_command":
             $params[2] = "command_command_id";
             $params[3] = $commandObject->getId($params[3]);
             break;
         case "check_command_arguments":
             $params[2] = "command_command_id_arg";
             break;
         case "event_handler":
             $params[2] = "command_command_id2";
             $params[3] = $commandObject->getId($params[3]);
             break;
         case "event_handler_arguments":
             $params[2] = "command_command_id_arg2";
             break;
         case "check_period":
             $params[2] = "timeperiod_tp_id";
             $tpObj = new CentreonTimePeriod();
             $params[3] = $tpObj->getTimeperiodId($params[3]);
             break;
         case "notification_period":
             $params[2] = "timeperiod_tp_id2";
             $tpObj = new CentreonTimePeriod();
             $params[3] = $tpObj->getTimeperiodId($params[3]);
             break;
         case "flap_detection_options":
             break;
         case "template":
             $params[2] = "service_template_model_stm_id";
             $tmp = $this->object->getList($this->object->getPrimaryKey(), -1, 0, null, null, array('service_description' => $params[3], 'service_register' => '0'), "AND");
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]);
             }
             $params[3] = $tmp[0][$this->object->getPrimaryKey()];
             break;
         case "graphtemplate":
             $extended = true;
             $graphObj = new Centreon_Object_Graph_Template();
             $tmp = $graphObj->getIdByParameter($graphObj->getUniqueLabelField(), $params[3]);
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]);
             }
             $params[2] = "graph_id";
             $params[3] = $tmp[0];
             break;
         case "contact_additive_inheritance":
             break;
         case "cg_additive_inheritance":
             break;
         case "notes":
             $extended = true;
             break;
         case "notes_url":
             $extended = true;
             break;
         case "action_url":
             $extended = true;
             break;
         case "icon_image":
             $extended = true;
             break;
         case "icon_image_alt":
             $extended = true;
             break;
         case "service_notification_options":
             $aNotifs = explode(",", $params[3]);
             foreach ($aNotifs as $notif) {
                 if (!array_key_exists($notif, self::$aAuthorizedNotificationsOptions)) {
                     throw new CentreonClapiException(self::UNKNOWN_NOTIFICATION_OPTIONS);
                 }
             }
             break;
         default:
             if (!preg_match("/^service_/", $params[2])) {
                 $params[2] = "service_" . $params[2];
             }
             break;
     }
     if ($extended == false) {
         $updateParams = array($params[2] => $params[3]);
         if ($params[2] == 'service_description' && $this->serviceExists($hostName, $params[3])) {
             throw new CentreonClapiException(self::OBJECTALREADYEXISTS);
         }
         $this->object->update($objectId, $updateParams);
         $this->addAuditLog('c', $objectId, $hostName . ' - ' . $serviceDesc, $updateParams);
     } else {
         if ($params[2] != "graph_id") {
             $params[2] = "esi_" . $params[2];
             if ($params[2] == "esi_icon_image") {
                 if ($params[3]) {
                     $id = CentreonUtils::getImageId($params[3]);
                     if (is_null($id)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]);
                     }
                     $params[3] = $id;
                 } else {
                     $params[3] = null;
                 }
             }
         }
         $extended = new Centreon_Object_Service_Extended();
         $extended->update($objectId, array($params[2] => $params[3]));
         $this->addAuditLog('c', $objectId, $hostName . ' - ' . $serviceDesc, array($params[2] => $params[3]));
     }
 }