Esempio n. 1
0
 static function afterAdd(Group_Ticket $item)
 {
     global $DB;
     //Toolbox::logDebug(__METHOD__, $item);
     $config = PluginBehaviorsConfig::getInstance();
     if ($config->getField('add_notif')) {
         if ($item->getField('type') == CommonITILActor::ASSIGN) {
             $ticket = new Ticket();
             if ($ticket->getFromDB($item->getField('tickets_id'))) {
                 NotificationEvent::raiseEvent('plugin_behaviors_ticketnewgrp', $ticket);
             }
         }
     }
     // Check is the connected user is a tech
     if (!is_numeric(Session::getLoginUserID(false)) || !Session::haveRight('own_ticket', 1)) {
         return false;
         // No check
     }
     $config = PluginBehaviorsConfig::getInstance();
     if ($config->getField('single_tech_mode') != 0 && $item->input['type'] == CommonITILActor::ASSIGN) {
         $crit = array('tickets_id' => $item->input['tickets_id'], 'type' => CommonITILActor::ASSIGN);
         foreach ($DB->request('glpi_groups_tickets', $crit) as $data) {
             if ($data['id'] != $item->getID()) {
                 $gu = new Group_Ticket();
                 $gu->delete($data);
             }
         }
         if ($config->getField('single_tech_mode') == 2) {
             foreach ($DB->request('glpi_tickets_users', $crit) as $data) {
                 $gu = new Ticket_User();
                 $gu->delete($data);
             }
         }
     }
 }
 static function afterUpdate(TicketSatisfaction $ticketsatisfaction)
 {
     $config = PluginBehaviorsConfig::getInstance();
     $ticket = new Ticket();
     if ($config->getField('add_notif') && $ticket->getFromDB($ticketsatisfaction->getField('tickets_id')) && $ticketsatisfaction->input["date_answered"]) {
         NotificationEvent::raiseEvent('plugin_behaviors_replysurvey', $ticket);
     }
 }
 static function afterPurge(Document_Item $document_item)
 {
     $config = PluginBehaviorsConfig::getInstance();
     if ($config->getField('add_notif') && $document_item->fields['itemtype'] == 'Ticket' && isset($_POST['item'])) {
         // prevent not use in case of purge ticket
         $ticket = new Ticket();
         $ticket->getFromDB($document_item->fields['items_id']);
         NotificationEvent::raiseEvent('plugin_behaviors_document_itemdel', $ticket);
     }
 }
 function post_deleteFromDB()
 {
     global $CFG_GLPI;
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
         $donotif = false;
     }
     $t = new Ticket();
     if ($t->getFromDB($this->fields['tickets_id'])) {
         if ($t->fields["suppliers_id_assign"] == 0 && $t->countUsers(Ticket::ASSIGN) == 0 && $t->countGroups(Ticket::ASSIGN) == 0) {
             $t->update(array('id' => $this->fields['tickets_id'], 'status' => 'new'));
         } else {
             $t->updateDateMod($this->fields['tickets_id']);
             if ($donotif) {
                 NotificationEvent::raiseEvent("update", $t);
             }
         }
     }
     parent::post_deleteFromDB();
 }
Esempio n. 5
0
 /**
  * @param $output
  * @param $params
  **/
 function executeActions($output, $params)
 {
     if (count($this->actions)) {
         foreach ($this->actions as $action) {
             switch ($action->fields["action_type"]) {
                 case "send":
                     $ticket = new Ticket();
                     if ($ticket->getFromDB($output['id'])) {
                         NotificationEvent::raiseEvent('recall', $ticket);
                     }
                     break;
                 case "add_validation":
                     if (isset($output['_add_validation']) && !is_array($output['_add_validation'])) {
                         $output['_add_validation'] = array($output['_add_validation']);
                     }
                     switch ($action->fields['field']) {
                         case 'users_id_validate_requester_supervisor':
                             $output['_add_validation'][] = 'requester_supervisor';
                             break;
                         case 'users_id_validate_assign_supervisor':
                             $output['_add_validation'][] = 'assign_supervisor';
                             break;
                         case 'groups_id_validate':
                             $output['_add_validation']['group'][] = $action->fields["value"];
                             break;
                         case 'users_id_validate':
                             $output['_add_validation'][] = $action->fields["value"];
                             break;
                         case 'validation_percent':
                             $output[$action->fields["field"]] = $action->fields["value"];
                             break;
                         default:
                             $output['_add_validation'][] = $action->fields["value"];
                             break;
                     }
                     break;
                 case "assign":
                     $output[$action->fields["field"]] = $action->fields["value"];
                     // Special case of users_id_requester
                     if ($action->fields["field"] === '_users_id_requester') {
                         // Add groups of requester
                         if (!isset($output['_groups_id_of_requester'])) {
                             $output['_groups_id_of_requester'] = array();
                         }
                         foreach (Group_User::getUserGroups($action->fields["value"]) as $g) {
                             $output['_groups_id_of_requester'][$g['id']] = $g['id'];
                         }
                     }
                     break;
                 case "append":
                     $actions = $this->getActions();
                     $value = $action->fields["value"];
                     if (isset($actions[$action->fields["field"]]["appendtoarray"]) && isset($actions[$action->fields["field"]]["appendtoarrayfield"])) {
                         $value = $actions[$action->fields["field"]]["appendtoarray"];
                         $value[$actions[$action->fields["field"]]["appendtoarrayfield"]] = $action->fields["value"];
                     }
                     $output[$actions[$action->fields["field"]]["appendto"]][] = $value;
                     // Special case of users_id_requester
                     if ($action->fields["field"] === '_users_id_requester') {
                         // Add groups of requester
                         if (!isset($output['_groups_id_of_requester'])) {
                             $output['_groups_id_of_requester'] = array();
                         }
                         foreach (Group_User::getUserGroups($action->fields["value"]) as $g) {
                             $output['_groups_id_of_requester'][$g['id']] = $g['id'];
                         }
                     }
                     break;
                 case 'fromuser':
                     if ($action->fields['field'] == 'locations_id' && isset($output['users_locations'])) {
                         $output['locations_id'] = $output['users_locations'];
                     }
                     break;
                 case 'fromitem':
                     if ($action->fields['field'] == 'locations_id' && isset($output['items_locations'])) {
                         $output['locations_id'] = $output['items_locations'];
                     }
                     if ($action->fields['field'] == 'groups_id' && isset($output['items_groups'])) {
                         $output['groups_id'] = $output['items_groups'];
                     }
                     break;
                 case 'compute':
                     // Value could be not set (from test)
                     $urgency = isset($output['urgency']) ? $output['urgency'] : 3;
                     $impact = isset($output['impact']) ? $output['impact'] : 3;
                     // Apply priority_matrix from config
                     $output['priority'] = Ticket::computePriority($urgency, $impact);
                     break;
                 case "affectbyip":
                 case "affectbyfqdn":
                 case "affectbymac":
                     if (!isset($output["entities_id"])) {
                         $output["entities_id"] = $params["entities_id"];
                     }
                     if (isset($this->regex_results[0])) {
                         $regexvalue = RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]);
                     } else {
                         $regexvalue = $action->fields["value"];
                     }
                     switch ($action->fields["action_type"]) {
                         case "affectbyip":
                             $result = IPAddress::getUniqueItemByIPAddress($regexvalue, $output["entities_id"]);
                             break;
                         case "affectbyfqdn":
                             $result = FQDNLabel::getUniqueItemByFQDN($regexvalue, $output["entities_id"]);
                             break;
                         case "affectbymac":
                             $result = NetworkPortInstantiation::getUniqueItemByMac($regexvalue, $output["entities_id"]);
                             break;
                         default:
                             $result = array();
                     }
                     if (!empty($result)) {
                         $output["items_id"][$result["itemtype"]][] = $result["id"];
                     }
                     break;
             }
         }
     }
     return $output;
 }
Esempio n. 6
0
 function post_addItem()
 {
     global $CFG_GLPI;
     parent::post_addItem();
     if (isset($this->input['_tickets_id'])) {
         $ticket = new Ticket();
         if ($ticket->getFromDB($this->input['_tickets_id'])) {
             $pt = new Change_Ticket();
             $pt->add(array('tickets_id' => $this->input['_tickets_id'], 'changes_id' => $this->fields['id']));
             if (!empty($ticket->fields['itemtype']) && $ticket->fields['items_id'] > 0) {
                 $it = new Change_Item();
                 $it->add(array('changes_id' => $this->fields['id'], 'itemtype' => $ticket->fields['itemtype'], 'items_id' => $ticket->fields['items_id']));
             }
         }
     }
     if (isset($this->input['_problems_id'])) {
         $problem = new Problem();
         if ($problem->getFromDB($this->input['_problems_id'])) {
             $cp = new Change_Problem();
             $cp->add(array('problems_id' => $this->input['_problems_id'], 'changes_id' => $this->fields['id']));
         }
     }
     // Processing Email
     if ($CFG_GLPI["use_mailing"]) {
         // Clean reload of the change
         $this->getFromDB($this->fields['id']);
         $type = "new";
         if (isset($this->fields["status"]) && in_array($this->input["status"], $this->getSolvedStatusArray())) {
             $type = "solved";
         }
         NotificationEvent::raiseEvent($type, $this);
     }
 }
 /**
  * Display debug information for current object
  **/
 function showDebug()
 {
     $license = array('softname' => '', 'name' => '', 'serial' => '', 'expire' => '');
     $options['entities_id'] = $this->getEntityID();
     $options['licenses'] = array($license);
     NotificationEvent::debugEvent($this, $options);
 }
Esempio n. 8
0
 function post_updateItem($history = 1)
 {
     global $CFG_GLPI;
     $job = new Ticket();
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->input['_disablenotif'])) {
         $donotif = false;
     }
     if ($job->getFromDB($this->fields["tickets_id"])) {
         if (count($this->updates) && $donotif) {
             $options = array('validation_id' => $this->fields["id"], 'validation_status' => $this->fields["status"]);
             NotificationEvent::raiseEvent('validation_answer', $job, $options);
         }
         // Set global validation to accepted to define one
         if ($job->fields['global_validation'] == 'waiting' || self::getNumberValidationForTicket($this->fields["tickets_id"]) == 1 || self::isAllValidationsHaveSameStatusForTicket($this->fields["tickets_id"])) {
             $input['id'] = $this->fields["tickets_id"];
             $input['global_validation'] = $this->fields["status"];
             $job->update($input);
         }
     }
     parent::post_updateItem($history);
 }
Esempio n. 9
0
 /**
  *  Cron process to check DB replicate state
  *
  * @param $task to log and get param
  **/
 static function cronCheckDBreplicate($task)
 {
     global $DB;
     //Lauch cron only is :
     // 1 the master database is avalaible
     // 2 the slave database is configurated
     if (!$DB->isSlave() && self::isDBSlaveActive()) {
         $DBslave = self::getDBSlaveConf();
         if (is_array($DBslave->dbhost)) {
             $hosts = $DBslave->dbhost;
         } else {
             $hosts = array($DBslave->dbhost);
         }
         foreach ($hosts as $num => $name) {
             $diff = self::getReplicateDelay($num);
             // Quite strange, but allow simple stat
             $task->addVolume($diff);
             if ($diff > 1000000000) {
                 // very large means slave is disconnect
                 $task->log(sprintf(__s("Mysql server: %s can't connect to the database"), $name));
             } else {
                 //TRANS: %1$s is the server name, %2$s is the time
                 $task->log(sprintf(__('Mysql server: %1$s, difference between master and slave: %2$s'), $name, Html::timestampToString($diff, true)));
             }
             if ($diff > $task->fields['param'] * 60) {
                 //Raise event if replicate is not synchronized
                 $options = array('diff' => $diff, 'name' => $name, 'entities_id' => 0);
                 // entity to avoid warning in getReplyTo
                 NotificationEvent::raiseEvent('desynchronization', new self(), $options);
             }
         }
         return 1;
     }
     return 0;
 }
Esempio n. 10
0
 /**
  * Display debug information for current object
  **/
 function showDebug()
 {
     $options['entities_id'] = $this->getEntityID();
     $options['contracts'] = array();
     NotificationEvent::debugEvent($this, $options);
 }
Esempio n. 11
0
 static function cronAdditionalalertsNewOcs($task = NULL)
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $CronTask = new CronTask();
     if ($CronTask->getFromDBbyName("PluginAdditionalalertsOcsAlert", "AdditionalalertsNewOcs")) {
         if ($CronTask->fields["state"] == CronTask::STATE_DISABLE) {
             return 0;
         }
     } else {
         return 0;
     }
     $message = array();
     $cron_status = 0;
     foreach (self::getEntitiesToNotify('use_newocs_alert') as $entity => $repeat) {
         foreach ($DB->request("glpi_plugin_ocsinventoryng_ocsservers", "`is_active` = 1") as $config) {
             $query_newocsmachine = self::queryNew($config, $entity);
             $newocsmachine_infos = array();
             $newocsmachine_messages = array();
             $type = Alert::END;
             $newocsmachine_infos[$type] = array();
             foreach ($DB->request($query_newocsmachine) as $data) {
                 $entity = $data['entities_id'];
                 $message = $data["name"];
                 $newocsmachine_infos[$type][$entity][] = $data;
                 if (!isset($newocsmachines_infos[$type][$entity])) {
                     $newocsmachine_messages[$type][$entity] = __('New imported computers from OCS-NG', 'additionalalerts') . "<br />";
                 }
                 $newocsmachine_messages[$type][$entity] .= $message;
             }
             $delay_ocs = 0;
             foreach ($newocsmachine_infos[$type] as $entity => $newocsmachines) {
                 Plugin::loadLang('additionalalerts');
                 if (NotificationEvent::raiseEvent("newocs", new PluginAdditionalalertsOcsAlert(), array('entities_id' => $entity, 'ocsmachines' => $newocsmachines, 'delay_ocs' => $delay_ocs))) {
                     $message = $newocsmachine_messages[$type][$entity];
                     $cron_status = 1;
                     if ($task) {
                         $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}\n");
                         $task->addVolume(1);
                     } else {
                         Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}");
                     }
                 } else {
                     if ($task) {
                         $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send newocsmachines alert failed\n");
                     } else {
                         Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send newocsmachines alert failed", false, ERROR);
                     }
                 }
             }
         }
     }
     return $cron_status;
 }
Esempio n. 12
0
 function post_addItem()
 {
     global $CFG_GLPI;
     parent::post_addItem();
     if (isset($this->input['_tickets_id'])) {
         $ticket = new Ticket();
         if ($ticket->getFromDB($this->input['_tickets_id'])) {
             $pt = new Problem_Ticket();
             $pt->add(array('tickets_id' => $this->input['_tickets_id'], 'problems_id' => $this->fields['id'], '_no_notif' => true));
             if (!empty($ticket->fields['itemtype']) && $ticket->fields['items_id'] > 0) {
                 $it = new Item_Problem();
                 $it->add(array('problems_id' => $this->fields['id'], 'itemtype' => $ticket->fields['itemtype'], 'items_id' => $ticket->fields['items_id'], '_no_notif' => true));
             }
         }
     }
     // Processing Email
     if ($CFG_GLPI["use_mailing"]) {
         // Clean reload of the problem
         $this->getFromDB($this->fields['id']);
         $type = "new";
         if (isset($this->fields["status"]) && $this->fields["status"] == self::SOLVED) {
             $type = "solved";
         }
         NotificationEvent::raiseEvent($type, $this);
     }
 }
Esempio n. 13
0
 function post_addItem()
 {
     global $CFG_GLPI;
     if ($CFG_GLPI["use_mailing"]) {
         NotificationEvent::raiseEvent("new", $this);
     }
     parent::post_addItem();
 }
Esempio n. 14
0
 /**
  * Display debug information for current object
  **/
 function showDebug()
 {
     $params = array('message' => '', 'action_type' => true, 'action_user' => getUserName(Session::getLoginUserID()), 'entities_id' => $_SESSION['glpiactive_entity'], 'itemtype' => get_class($this), 'date' => $_SESSION['glpi_currenttime'], 'refuse' => true);
     NotificationEvent::debugEvent($this, $params);
 }
Esempio n. 15
0
 function post_addItem()
 {
     global $CFG_GLPI;
     if (isset($this->input['_planningrecall'])) {
         $this->input['_planningrecall']['items_id'] = $this->fields['id'];
         PlanningRecall::manageDatas($this->input['_planningrecall']);
     }
     $donotif = $CFG_GLPI["use_mailing"];
     if (isset($this->fields["begin"]) && !empty($this->fields["begin"])) {
         Planning::checkAlreadyPlanned($this->fields["users_id_tech"], $this->fields["begin"], $this->fields["end"], array($this->getType() => array($this->fields["id"])));
         $calendars_id = Entity::getUsedConfig('calendars_id', $this->input["_job"]->fields['entities_id']);
         $calendar = new Calendar();
         // Using calendar
         if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
             if (!$calendar->isAWorkingHour(strtotime($this->fields["begin"]))) {
                 Session::addMessageAfterRedirect(__('Start of the selected timeframe is not a working hour.'), false, ERROR);
             }
             if (!$calendar->isAWorkingHour(strtotime($this->fields["end"]))) {
                 Session::addMessageAfterRedirect(__('End of the selected timeframe is not a working hour.'), false, ERROR);
             }
         }
     }
     $this->input["_job"]->updateDateMod($this->input[$this->input["_job"]->getForeignKeyField()]);
     if (isset($this->input["actiontime"]) && $this->input["actiontime"] > 0) {
         $this->input["_job"]->updateActionTime($this->input[$this->input["_job"]->getForeignKeyField()]);
     }
     //change status only if input change
     if (isset($this->input['_status']) && $this->input['_status'] != $this->input['_job']->fields['status']) {
         $update['status'] = $this->input['_status'];
         $update['id'] = $this->input['_job']->fields['id'];
         $update['_disablenotif'] = true;
         $this->input['_job']->update($update);
     }
     if (!empty($this->fields['begin']) && $this->input["_job"]->isStatusExists(CommonITILObject::PLANNED) && ($this->input["_job"]->fields["status"] == CommonITILObject::INCOMING || $this->input["_job"]->fields["status"] == CommonITILObject::ASSIGNED)) {
         $input2['id'] = $this->input["_job"]->getID();
         $input2['status'] = CommonITILObject::PLANNED;
         $input2['_disablenotif'] = true;
         $this->input["_job"]->update($input2);
     }
     if ($donotif) {
         $options = array('task_id' => $this->fields["id"], 'is_private' => $this->isPrivate());
         NotificationEvent::raiseEvent('add_task', $this->input["_job"], $options);
     }
     // Add log entry in the ITIL object
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = $this->fields['id'];
     Log::history($this->getField($this->input["_job"]->getForeignKeyField()), $this->input["_job"]->getTYpe(), $changes, $this->getType(), Log::HISTORY_ADD_SUBITEM);
 }
Esempio n. 16
0
 /**
  * Check zombie crontask
  *
  * @param $task for log
  **/
 static function cronWatcher($task)
 {
     global $CFG_GLPI, $DB;
     $cron_status = 0;
     // Crontasks running for more than 1 hour or 2 frequency
     $query = "SELECT *\n                FROM `glpi_crontasks`\n                WHERE `state` = '" . self::STATE_RUNNING . "'\n                      AND ((unix_timestamp(`lastrun`) + 2 * `frequency` < unix_timestamp(now()))\n                           OR (unix_timestamp(`lastrun`) + 2*" . HOUR_TIMESTAMP . " < unix_timestamp(now())))";
     $crontasks = array();
     foreach ($DB->request($query) as $data) {
         $crontasks[$data['id']] = $data;
     }
     if (count($crontasks)) {
         $task = new self();
         $task->getFromDBByQuery("WHERE `itemtype` = 'Crontask' AND `name` = 'watcher'");
         if (NotificationEvent::raiseEvent("alert", $task, array('items' => $crontasks))) {
             $cron_status = 1;
             $task->addVolume(1);
         }
         QueuedMail::forceSendFor($task->getType(), $task->fields['id']);
     }
     return 1;
 }
Esempio n. 17
0
 /**
  * Display debug information for current object
  **/
 function showDebug()
 {
     NotificationEvent::debugEvent($this);
 }
 /**
  * Display debug information for current object
  * NotificationTemplateTranslation => translation preview
  *
  * @since version 0.84
  **/
 function showDebug()
 {
     $template = new NotificationTemplate();
     if (!$template->getFromDB($this->fields['notificationtemplates_id'])) {
         return;
     }
     $itemtype = $template->getField('itemtype');
     if (!($item = getItemForItemtype($itemtype))) {
         return;
     }
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . __('Preview') . "</th></tr>";
     $oktypes = array('CartridgeItem', 'Change', 'ConsumableItem', 'Contract', 'Crontask', 'Problem', 'Project', 'Ticket', 'User');
     if (!in_array($itemtype, $oktypes)) {
         // this itemtype doesn't work, need to be fixed
         echo "<tr class='tab_bg_2 center'><td>" . NOT_AVAILABLE . "</td>";
         echo "</table></div>";
         return;
     }
     // Criteria Form
     $key = getForeignKeyFieldForItemType($item->getType());
     $id = Session::getSavedOption(__CLASS__, $key, 0);
     $event = Session::getSavedOption(__CLASS__, $key . '_event', '');
     echo "<tr class='tab_bg_2'><td>" . $item->getTypeName(1) . "&nbsp;";
     $item->dropdown(array('value' => $id, 'on_change' => 'reloadTab("' . $key . '="+this.value)'));
     echo "</td><td>" . NotificationEvent::getTypeName(1) . "&nbsp;";
     NotificationEvent::dropdownEvents($item->getType(), array('value' => $event, 'on_change' => 'reloadTab("' . $key . '_event="+this.value)'));
     echo "</td>";
     // Preview
     if ($event && $item->getFromDB($id)) {
         $options = array('_debug' => true);
         // TODO Awfull Hack waiting for https://forge.indepnet.net/issues/3439
         $multi = array('alert', 'alertnotclosed', 'end', 'notice', 'periodicity', 'periodicitynotice');
         if (in_array($event, $multi)) {
             // Won't work for Cardridge and Consumable
             $options['entities_id'] = $item->getEntityID();
             $options['items'] = array($item->getID() => $item->fields);
         }
         $target = NotificationTarget::getInstance($item, $event, $options);
         $infos = array('language' => $_SESSION['glpilanguage'], 'additionnaloption' => array('usertype' => NotificationTarget::GLPI_USER));
         $template->resetComputedTemplates();
         $template->setSignature(Notification::getMailingSignature($_SESSION['glpiactive_entity']));
         if ($tid = $template->getTemplateByLanguage($target, $infos, $event, $options)) {
             $data = $template->templates_by_languages[$tid];
             echo "<tr><th colspan='2'>" . __('Subject') . "</th></tr>";
             echo "<tr class='tab_bg_2 b'><td colspan='2'>" . $data['subject'] . "</td></tr>";
             echo "<tr><th>" . __('Email text body') . "</th>";
             echo "<th>" . __('Email HTML body') . "</th></tr>";
             echo "<tr class='tab_bg_2'><td>" . nl2br($data['content_text']) . "</td>";
             echo "<td>" . $data['content_html'] . "</td></tr>";
         }
     }
     echo "</table></div>";
 }
Esempio n. 19
0
 /**
  * Send Alarms on mailgate errors
  *
  * @since version 0.85
  *
  * @param $task for log
  **/
 static function cronMailgateError($task)
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $cron_status = 0;
     $query = "SELECT `glpi_mailcollectors`.*\n                FROM `glpi_mailcollectors`\n                WHERE `glpi_mailcollectors`.`errors`  > 0\n                      AND `glpi_mailcollectors`.`is_active`";
     $items = array();
     foreach ($DB->request($query) as $data) {
         $items[$data['id']] = $data;
     }
     if (count($items)) {
         if (NotificationEvent::raiseEvent('error', new self(), array('items' => $items))) {
             $cron_status = 1;
             if ($task) {
                 $task->setVolume(count($items));
             }
         }
     }
     return $cron_status;
 }
 /**
  * @return int
  */
 static function sendAlert()
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $items_infos = array();
     $query = "SELECT `glpi_plugin_ocsinventoryng_notimportedcomputers`.*\n               FROM `glpi_plugin_ocsinventoryng_notimportedcomputers`\n               LEFT JOIN `glpi_alerts`\n                  ON (`glpi_plugin_ocsinventoryng_notimportedcomputers`.`id` = `glpi_alerts`.`items_id`\n                      AND `glpi_alerts`.`itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\n                      AND `glpi_alerts`.`type` = '" . Alert::END . "')\n               WHERE `glpi_alerts`.`date` IS NULL";
     foreach ($DB->request($query) as $notimported) {
         $items_infos[$notimported['entities_id']][$notimported['id']] = $notimported;
     }
     foreach ($items_infos as $entity => $items) {
         if (NotificationEvent::raiseEvent('not_imported', new PluginOcsinventoryngNotimportedcomputer(), array('entities_id' => $entity, 'notimported' => $items))) {
             $alert = new Alert();
             $input["itemtype"] = 'PluginOcsinventoryngNotimportedcomputer';
             $input["type"] = Alert::END;
             foreach ($items as $id => $item) {
                 $input["items_id"] = $id;
                 $alert->add($input);
                 unset($alert->fields['id']);
             }
         } else {
             Toolbox::logDebug(__('%1$s: %2$s') . "\n", Dropdown::getDropdownName("glpi_entities", $entity), __('Send OCSNG not imported computers alert failed', 'ocsinventoryng'));
         }
     }
 }
Esempio n. 21
0
 /**
  * Cron action on tasks : ExpiredTasks
  *
  * @param $task for log, if NULL display
  *
  **/
 static function cronResourcesTask($task = NULL)
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $message = array();
     $cron_status = 0;
     $resourcetask = new self();
     $query_expired = $resourcetask->queryAlert();
     $querys = array(Alert::END => $query_expired);
     $task_infos = array();
     $task_messages = array();
     foreach ($querys as $type => $query) {
         $task_infos[$type] = array();
         foreach ($DB->request($query) as $data) {
             $entity = $data['entities_id'];
             $message = $data["name"] . ": " . Html::convDate($data["date_end"]) . "<br>\n";
             $task_infos[$type][$entity][] = $data;
             if (!isset($tasks_infos[$type][$entity])) {
                 $task_messages[$type][$entity] = __('Not finished tasks', 'resources') . "<br />";
             }
             $task_messages[$type][$entity] .= $message;
         }
     }
     foreach ($querys as $type => $query) {
         foreach ($task_infos[$type] as $entity => $tasks) {
             Plugin::loadLang('resources');
             if (NotificationEvent::raiseEvent("AlertExpiredTasks", new PluginResourcesResource(), array('entities_id' => $entity, 'tasks' => $tasks))) {
                 $message = $task_messages[$type][$entity];
                 $cron_status = 1;
                 if ($task) {
                     $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}\n");
                     $task->addVolume(1);
                 } else {
                     Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}");
                 }
             } else {
                 if ($task) {
                     $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send tasks alert failed\n");
                 } else {
                     Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send tasks alert failed", false, ERROR);
                 }
             }
         }
     }
     return $cron_status;
 }
 /**
  * Display debug information for dbslave
  **/
 function showDebug()
 {
     $options['diff'] = 0;
     $options['name'] = '';
     NotificationEvent::debugEvent(new DBConnection(), $options);
 }
 function post_addItem()
 {
     global $CFG_GLPI;
     $donotif = $CFG_GLPI["use_mailing"];
     //       if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
     //          $donotif = false;
     //       }
     $this->input["_job"]->updateDateMod($this->input["tickets_id"], false, $this->input["users_id"]);
     if (isset($this->input["_close"]) && $this->input["_close"] && $this->input["_job"]->fields["status"] == CommonITILObject::SOLVED) {
         $update['id'] = $this->input["_job"]->fields['id'];
         $update['status'] = CommonITILObject::CLOSED;
         $update['closedate'] = $_SESSION["glpi_currenttime"];
         // Use update method for history
         $this->input["_job"]->update($update);
         $donotif = false;
         // Done for ticket update (new status)
     }
     if (isset($this->input["_reopen"]) && $this->input["_reopen"] && in_array($this->input["_job"]->fields["status"], array(CommonITILObject::CLOSED, CommonITILObject::SOLVED, CommonITILObject::WAITING))) {
         if ($this->input["_job"]->countUsers(CommonITILActor::ASSIGN) > 0 || $this->input["_job"]->countGroups(CommonITILActor::ASSIGN) > 0 || $this->input["_job"]->countSuppliers(CommonITILActor::ASSIGN) > 0) {
             $update['status'] = CommonITILObject::ASSIGNED;
         } else {
             $update['status'] = CommonITILObject::INCOMING;
         }
         $update['id'] = $this->input["_job"]->fields['id'];
         // Use update method for history
         $this->input["_job"]->update($update);
         $donotif = false;
         // Done for ticket update (new status)
     }
     if ($donotif) {
         $options = array('followup_id' => $this->fields["id"], 'is_private' => $this->fields['is_private']);
         NotificationEvent::raiseEvent("add_followup", $this->input["_job"], $options);
     }
     // Add log entry in the ticket
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = $this->fields['id'];
     Log::history($this->getField('tickets_id'), 'Ticket', $changes, $this->getType(), Log::HISTORY_ADD_SUBITEM);
 }
Esempio n. 24
0
 public static function cronComputeLateOrders($task)
 {
     global $CFG_GLPI, $DB;
     $nblate = 0;
     $table = getTableForItemType(__CLASS__);
     foreach (getAllDatasFromTable($table, "`is_template`='0'") as $values) {
         $order = new self();
         $order->fields = $values;
         if (!$order->fields['is_late'] && $order->shouldBeAlreadyDelivered(true)) {
             $order->setIsLate();
             $nblate++;
         }
     }
     $task->addVolume($nblate);
     $cron_status = 1;
     if ($CFG_GLPI["use_mailing"]) {
         $message = __("Order is late", "order");
         $alert = new Alert();
         $config = PluginOrderConfig::getConfig();
         $entities[] = 0;
         foreach ($DB->request("SELECT `id` FROM `glpi_entities` ORDER BY `id` ASC") as $entity) {
             $entities[] = $entity['id'];
         }
         foreach ($entities as $entity) {
             $query_alert = "SELECT `{$table}`.`id` AS id,\n                                   `{$table}`.`name` AS name,\n                                   `{$table}`.`num_order` AS num_order,\n                                   `{$table}`.`order_date` AS order_date,\n                                   `{$table}`.`duedate` AS duedate,\n                                   `{$table}`.`deliverydate` AS deliverydate,\n                                   `{$table}`.`comment` AS comment,\n                                   `{$table}`.`plugin_order_orderstates_id` AS plugin_order_orderstates_id,\n                                   `glpi_alerts`.`id` AS alertID,\n                                   `glpi_alerts`.`date`\n                            FROM `{$table}`\n                            LEFT JOIN `glpi_alerts`\n                                  ON (`{$table}`.`id` = `glpi_alerts`.`items_id`\n                                      AND `glpi_alerts`.`itemtype` = '" . __CLASS__ . "')\n                            WHERE `{$table}`.`entities_id` = '" . $entity . "'\n                                   AND (`glpi_alerts`.`date` IS NULL) AND `{$table}`.`is_late`='1'\n                                      AND `plugin_order_orderstates_id`!='" . $config->getDeliveredState() . "';";
             $orders = array();
             foreach ($DB->request($query_alert) as $order) {
                 $orders[$order['id']] = $order;
             }
             if (!empty($orders)) {
                 $options['entities_id'] = $entity;
                 $options['orders'] = $orders;
                 if (NotificationEvent::raiseEvent('duedate', new PluginOrderOrder(), $options)) {
                     if ($task) {
                         $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . "&nbsp;:  {$message}\n");
                         $task->addVolume(1);
                     } else {
                         Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . "&nbsp;:  {$message}");
                     }
                     $input["type"] = Alert::THRESHOLD;
                     $input["itemtype"] = 'PluginOrderOrder';
                     // add alerts
                     foreach ($orders as $ID => $tmp) {
                         $input["items_id"] = $ID;
                         $alert->add($input);
                         unset($alert->fields['id']);
                     }
                 } else {
                     if ($task) {
                         $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . "&nbsp;: Send order alert failed\n");
                     } else {
                         Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . "&nbsp;: Send order alert failed", false, ERROR);
                     }
                 }
             }
         }
     }
     return true;
 }
Esempio n. 25
0
 /**
  * Actions done after the PURGE of the item in the database
  * Delete answers
  *
  * @return nothing
  **/
 public function post_purgeItem()
 {
     $table = getTableForItemType('PluginFormcreatorAnswer');
     $query = "DELETE FROM `{$table}` WHERE `plugin_formcreator_formanwers_id` = {$this->getID()};";
     $GLOBALS['DB']->query($query);
     // If the form was waiting for validation
     if ($this->fields['status'] == 'waiting') {
         // Notify the requester
         NotificationEvent::raiseEvent('plugin_formcreator_deleted', $this);
     }
 }
Esempio n. 26
0
 function pre_deleteItem()
 {
     global $CFG_GLPI;
     if ($CFG_GLPI["use_mailing"]) {
         NotificationEvent::raiseEvent("delete", $this);
     }
     return true;
 }
Esempio n. 27
0
 /**
  * Display debug information for current object
  **/
 function showDebug()
 {
     NotificationEvent::debugEvent($this);
     $this->showLdapDebug();
 }
Esempio n. 28
0
 /**
  * Display debug information for infocom of current object
  **/
 function showDebug()
 {
     $item = array('item_name' => '', 'warrantyexpiration' => '', 'itemtype' => $this->fields['itemtype'], 'items_id' => $this->fields['items_id']);
     $options['entities_id'] = $this->getEntityID();
     $options['items'] = array($item);
     NotificationEvent::debugEvent($this, $options);
 }
Esempio n. 29
0
 /**
  * Display debug information for reservation of current object
  **/
 function showDebugResa()
 {
     $resa = new Reservation();
     $resa->fields['id'] = '1';
     $resa->fields['reservationitems_id'] = $this->getField('id');
     $resa->fields['begin'] = $_SESSION['glpi_currenttime'];
     $resa->fields['end'] = $_SESSION['glpi_currenttime'];
     $resa->fields['users_id'] = Session::getLoginUserID();
     $resa->fields['comment'] = '';
     NotificationEvent::debugEvent($resa);
 }
Esempio n. 30
0
 function post_deleteFromDB()
 {
     global $CFG_GLPI;
     $donotif = $CFG_GLPI["use_mailing"];
     //       if (isset($this->input["_no_notif"]) && $this->input["_no_notif"]) {
     //          $donotif = false;
     //       }
     $item = $this->getConnexityItem(static::$itemtype_1, static::getItilObjectForeignKey());
     if ($item instanceof CommonDBTM) {
         if ($item->countSuppliers(CommonITILActor::ASSIGN) == 0 && $item->countUsers(CommonITILActor::ASSIGN) == 0 && $item->countGroups(CommonITILActor::ASSIGN) == 0 && $item->fields['status'] != CommonITILObject::CLOSED && $item->fields['status'] != CommonITILObject::SOLVED) {
             $status = CommonITILObject::INCOMING;
             if (in_array($item->fields['status'], Change::getNewStatusArray())) {
                 $status = $item->fields['status'];
             }
             $item->update(array('id' => $this->fields[static::getItilObjectForeignKey()], 'status' => $status));
         } else {
             $item->updateDateMod($this->fields[static::getItilObjectForeignKey()]);
             if ($donotif) {
                 $options = array();
                 if (isset($this->fields['users_id'])) {
                     $options = array('_old_user' => $this->fields);
                 }
                 NotificationEvent::raiseEvent("update", $item, $options);
             }
         }
     }
     parent::post_deleteFromDB();
 }