/**
  * Delete custom macro
  *
  * @param string $parameters
  * @return void
  * @throws CentreonClapiException
  */
 public function delmacro($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < 3) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $hostName = $params[0];
     $serviceDescription = $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" => $serviceDescription), "AND");
     if (!count($elements)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $hostName . "/" . $serviceDescription);
     }
     $macroObj = new Centreon_Object_Service_Macro_Custom();
     $macroList = $macroObj->getList($macroObj->getPrimaryKey(), -1, 0, null, null, array("svc_svc_id" => $elements[0]['service_id'], "svc_macro_name" => $this->wrapMacro($params[2])), "AND");
     if (count($macroList)) {
         $macroObj->delete($macroList[0][$macroObj->getPrimaryKey()]);
     }
     $this->addAuditLog('c', $elements[0]['service_id'], $hostName . ' - ' . $serviceDescription, array($params[2] => ''));
 }
 /**
  * Delete custom macro
  *
  * @param string $parameters
  * @return void
  * @throws CentreonClapiException
  */
 public function delmacro($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < 2) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $elements = $this->object->getList("service_id", -1, 0, null, null, array('service_description' => $params[0], 'service_register' => 0), "AND");
     if (!count($elements)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[0]);
     }
     $macroObj = new Centreon_Object_Service_Macro_Custom();
     $macroList = $macroObj->getList($macroObj->getPrimaryKey(), -1, 0, null, null, array("svc_svc_id" => $elements[0]['service_id'], "svc_macro_name" => $this->wrapMacro($params[1])), "AND");
     if (count($macroList)) {
         $macroObj->delete($macroList[0][$macroObj->getPrimaryKey()]);
     }
 }
 /**
  * Export
  *
  * @return void
  */
 public function export()
 {
     $hostRel = new Centreon_Object_Relation_Host_Group_Service();
     $elements = $hostRel->getMergedParameters(array("hg_name"), array('*'), -1, 0, null, null, array("service_register" => $this->register), "AND");
     $extendedObj = new Centreon_Object_Service_Extended();
     $commandObj = new Centreon_Object_Command();
     $tpObj = new Centreon_Object_Timeperiod();
     $macroObj = new Centreon_Object_Service_Macro_Custom();
     foreach ($elements as $element) {
         $addStr = $this->action . $this->delim . "ADD";
         foreach ($this->insertParams as $param) {
             $addStr .= $this->delim;
             if ($param == "service_template_model_stm_id") {
                 $tmp = $this->object->getParameters($element[$param], 'service_description');
                 if (isset($tmp) && isset($tmp['service_description']) && $tmp['service_description']) {
                     $element[$param] = $tmp['service_description'];
                 }
                 if (!$element[$param]) {
                     $element[$param] = "";
                 }
             }
             $addStr .= $element[$param];
         }
         $addStr .= "\n";
         echo $addStr;
         foreach ($element as $parameter => $value) {
             if (!in_array($parameter, $this->exportExcludedParams) && !is_null($value) && $value != "") {
                 if ($parameter == "timeperiod_tp_id" || $parameter == "timeperiod_tp_id2") {
                     $tmpObj = $tpObj;
                 } elseif ($parameter == "command_command_id" || $parameter == "command_command_id2") {
                     $tmpObj = $commandObj;
                 }
                 if (isset($tmpObj)) {
                     $tmp = $tmpObj->getParameters($value, $tmpObj->getUniqueLabelField());
                     if (isset($tmp) && isset($tmp[$tmpObj->getUniqueLabelField()])) {
                         $value = $tmp[$tmpObj->getUniqueLabelField()];
                     }
                     unset($tmpObj);
                 }
                 echo $this->action . $this->delim . "setparam" . $this->delim . $element['hg_name'] . $this->delim . $element['service_description'] . $this->delim . $this->getClapiActionName($parameter) . $this->delim . $value . "\n";
             }
         }
         $params = $extendedObj->getParameters($element[$this->object->getPrimaryKey()], array("esi_notes", "esi_notes_url", "esi_action_url", "esi_icon_image", "esi_icon_image_alt"));
         if (isset($params) && is_array($params)) {
             foreach ($params as $k => $v) {
                 if (!is_null($v) && $v != "") {
                     echo $this->action . $this->delim . "setparam" . $this->delim . $element['hg_name'] . $this->delim . $element['service_description'] . $this->delim . $this->getClapiActionName($k) . $this->delim . $v . "\n";
                 }
             }
         }
         $macros = $macroObj->getList("*", -1, 0, null, null, array($macroObj->getPrimaryKey() => $element[$this->object->getPrimaryKey()]), "AND");
         foreach ($macros as $macro) {
             echo $this->action . $this->delim . "setmacro" . $this->delim . $element['hg_name'] . $this->delim . $element['service_description'] . $this->delim . $this->stripMacro($macro['svc_macro_name']) . $this->delim . $macro['svc_macro_value'] . "\n";
         }
         $cgRel = new Centreon_Object_Relation_Contact_Group_Service();
         $cgelements = $cgRel->getMergedParameters(array("cg_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register, "service_id" => $element['service_id']), "AND");
         foreach ($cgelements as $cgelement) {
             echo $this->action . $this->delim . "addcontactgroup" . $this->delim . $element['hg_name'] . $this->delim . $cgelement['service_description'] . $this->delim . $cgelement['cg_name'] . "\n";
         }
         $contactRel = new Centreon_Object_Relation_Contact_Service();
         $celements = $contactRel->getMergedParameters(array("contact_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register, "service_id" => $element['service_id']), "AND");
         foreach ($celements as $celement) {
             echo $this->action . $this->delim . "addcontact" . $this->delim . $element['hg_name'] . $this->delim . $celement['service_description'] . $this->delim . $celement['contact_name'] . "\n";
         }
     }
 }