本文整理汇总了PHP中Entity::getUsedConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::getUsedConfig方法的具体用法?PHP Entity::getUsedConfig怎么用?PHP Entity::getUsedConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity::getUsedConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post_addItem
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);
}
示例2: cronContract
/**
* Cron action on contracts : alert depending of the config : on notice and expire
*
* @param $task for log, if NULL display (default NULL)
**/
static function cronContract($task = NULL)
{
global $DB, $CFG_GLPI;
if (!$CFG_GLPI["use_mailing"]) {
return 0;
}
$message = array();
$items_notice = array();
$items_end = array();
$cron_status = 0;
$contract_infos[Alert::END] = array();
$contract_infos[Alert::NOTICE] = array();
$contract_messages = array();
foreach (Entity::getEntitiesToNotify('use_contracts_alert') as $entity => $value) {
$before = Entity::getUsedConfig('send_contracts_alert_before_delay', $entity);
$query_notice = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n LEFT JOIN `glpi_alerts`\n ON (`glpi_contracts`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'Contract'\n AND `glpi_alerts`.`type`='" . Alert::NOTICE . "')\n WHERE (`glpi_contracts`.`alert` & " . pow(2, Alert::NOTICE) . ") >'0'\n AND `glpi_contracts`.`is_deleted` = '0'\n AND `glpi_contracts`.`begin_date` IS NOT NULL\n AND `glpi_contracts`.`duration` <> '0'\n AND `glpi_contracts`.`notice` <> '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL `glpi_contracts`.`duration` MONTH),\n CURDATE()) > '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL (`glpi_contracts`.`duration`\n -`glpi_contracts`.`notice`) MONTH),\n CURDATE()) < '{$before}'\n AND `glpi_alerts`.`date` IS NULL\n AND `glpi_contracts`.`entities_id` = '" . $entity . "'";
$query_end = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n LEFT JOIN `glpi_alerts`\n ON (`glpi_contracts`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'Contract'\n AND `glpi_alerts`.`type`='" . Alert::END . "')\n WHERE (`glpi_contracts`.`alert` & " . pow(2, Alert::END) . ") > '0'\n AND `glpi_contracts`.`is_deleted` = '0'\n AND `glpi_contracts`.`begin_date` IS NOT NULL\n AND `glpi_contracts`.`duration` <> '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL (`glpi_contracts`.`duration`) MONTH),\n CURDATE()) < '{$before}'\n AND `glpi_alerts`.`date` IS NULL\n AND `glpi_contracts`.`entities_id` = '" . $entity . "'";
$querys = array('notice' => $query_notice, 'end' => $query_end);
foreach ($querys as $type => $query) {
foreach ($DB->request($query) as $data) {
$entity = $data['entities_id'];
$message = sprintf(__('%1$s: %2$s') . "<br>\n", $data["name"], Infocom::getWarrantyExpir($data["begin_date"], $data["duration"], $data["notice"]));
$contract_infos[$type][$entity][$data['id']] = $data;
if (!isset($contract_messages[$type][$entity])) {
switch ($type) {
case 'notice':
$contract_messages[$type][$entity] = __('Contract entered in notice time') . "<br>";
break;
case 'end':
$contract_messages[$type][$entity] = __('Contract ended') . "<br>";
break;
}
}
$contract_messages[$type][$entity] .= $message;
}
}
// Get contrats with periodicity alerts
$query_periodicity = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n WHERE `glpi_contracts`.`alert` & " . pow(2, Alert::PERIODICITY) . " > '0'\n AND `glpi_contracts`.`entities_id` = '" . $entity . "' ";
// Foreach ones :
foreach ($DB->request($query_periodicity) as $data) {
$entity = $data['entities_id'];
// Compute end date + 12 month : do not send alerts after
$end_alert = date('Y-m-d', strtotime($data['begin_date'] . " +" . ($data['duration'] + 12) . " month"));
if (!empty($data['begin_date']) && $data['periodicity'] && $end_alert > date('Y-m-d')) {
$todo = array('periodicity' => Alert::PERIODICITY);
if ($data['alert'] & pow(2, Alert::NOTICE)) {
$todo['periodicitynotice'] = Alert::NOTICE;
}
// Get previous alerts
foreach ($todo as $type => $event) {
$previous_alerts[$type] = Alert::getAlertDate(__CLASS__, $data['id'], $event);
}
// compute next alert date based on already send alerts (or not)
foreach ($todo as $type => $event) {
$next_alerts[$type] = date('Y-m-d', strtotime($data['begin_date'] . " -" . $before . " day"));
if ($type == Alert::NOTICE) {
$next_alerts[$type] = date('Y-m-d', strtotime($next_alerts[$type] . " -" . $data['notice'] . " month"));
}
$today_limit = date('Y-m-d', strtotime(date('Y-m-d') . " -" . $data['periodicity'] . " month"));
// Init previous by begin date if not set
if (empty($previous_alerts[$type])) {
$previous_alerts[$type] = $today_limit;
}
while ($next_alerts[$type] < $previous_alerts[$type] && $next_alerts[$type] < $end_alert) {
$next_alerts[$type] = date('Y-m-d', strtotime($next_alerts[$type] . " +" . $data['periodicity'] . " month"));
}
// If this date is passed : clean alerts and send again
if ($next_alerts[$type] <= date('Y-m-d')) {
$alert = new Alert();
$alert->clear(__CLASS__, $data['id'], $event);
$real_alert_date = date('Y-m-d', strtotime($next_alerts[$type] . " +" . $before . " day"));
$message = sprintf(__('%1$s: %2$s') . "<br>\n", $data["name"], Html::convDate($real_alert_date));
$data['alert_date'] = $real_alert_date;
$data['items'] = Contract_Item::getItemsForContract($data['id'], $entity);
$contract_infos[$type][$entity][$data['id']] = $data;
switch ($type) {
case 'periodicitynotice':
$contract_messages[$type][$entity] = __('Contract entered in notice time for period') . "<br>";
break;
case 'periodicity':
$contract_messages[$type][$entity] = __('Contract period ended') . "<br>";
break;
}
$contract_messages[$type][$entity] .= $message;
}
}
}
}
}
foreach (array('notice' => Alert::NOTICE, 'end' => Alert::END, 'periodicity' => Alert::PERIODICITY, 'periodicitynotice' => Alert::NOTICE) as $event => $type) {
if (isset($contract_infos[$event]) && count($contract_infos[$event])) {
foreach ($contract_infos[$event] as $entity => $contracts) {
if (NotificationEvent::raiseEvent($event, new self(), array('entities_id' => $entity, 'items' => $contracts))) {
$message = $contract_messages[$event][$entity];
$cron_status = 1;
//.........这里部分代码省略.........
示例3: qualification
/**
* On ticket category change, add ticket category group and user
* @param CommonDBTM $item
* @return nothing
*/
static function qualification(CommonDBTM $item)
{
global $DB;
//get auto-assign mode (config in entity)
$auto_assign_mode = Entity::getUsedConfig('auto_assign_mode', $_SESSION['glpiactive_entity']);
if ($auto_assign_mode == Entity::CONFIG_NEVER) {
return true;
}
//get category
$category = new ITILCategory();
$category->getFromDB($item->input['itilcategories_id']);
//category group
if (!empty($category->fields['groups_id']) && $_SESSION['plugins']['escalade']['config']['reassign_group_from_cat']) {
$group_ticket = new Group_Ticket();
//check if group is not already present
$group_found = $group_ticket->find("tickets_id = '" . $item->fields['id'] . "' AND groups_id = '" . $category->fields['groups_id'] . "' AND type = 2");
if (empty($group_found)) {
//add group to ticket
$group_ticket->add(array('tickets_id' => $item->fields['id'], 'groups_id' => $category->fields['groups_id'], 'type' => CommonITILActor::ASSIGN));
}
}
//category user
if (!empty($category->fields['users_id']) && $_SESSION['plugins']['escalade']['config']['reassign_tech_from_cat']) {
$ticket_user = new Ticket_User();
//check if user is not already present
$user_found = $ticket_user->find("tickets_id = '" . $item->fields['id'] . "' AND users_id = '" . $category->fields['users_id'] . "' AND type = 2");
if (empty($user_found)) {
//add user to ticket
$ticket_user->add(array('tickets_id' => $item->fields['id'], 'users_id' => $category->fields['users_id'], 'type' => CommonITILActor::ASSIGN));
}
}
}
示例4: getCalendar
/**
* Get correct Calendar: Entity or Sla
*
* @since 0.90.4
*
**/
function getCalendar()
{
return Entity::getUsedConfig('calendars_id', $this->fields['entities_id']);
}
示例5: giveItem
//.........这里部分代码省略.........
return $out;
}
}
break;
case "glpi_tickets.due_date":
case "glpi_problems.due_date":
case "glpi_changes.due_date":
// Due date + progress
if ($ID == 151) {
$out = Html::convDate($data[$num][0]['name']);
// No due date in waiting status
if ($data[$num][0]['status'] == CommonITILObject::WAITING) {
return '';
}
if (empty($data[$num][0]['name'])) {
return '';
}
if ($data[$num][0]['status'] == Ticket::SOLVED || $data[$num][0]['status'] == Ticket::CLOSED) {
return $out;
}
$itemtype = getItemTypeForTable($table);
$item = new $itemtype();
$item->getFromDB($data['id']);
$percentage = 0;
$totaltime = 0;
$currenttime = 0;
if ($item->isField('slas_id') && $item->fields['slas_id'] != 0) {
// Have SLA
$sla = new SLA();
$sla->getFromDB($item->fields['slas_id']);
$currenttime = $sla->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s'));
$totaltime = $sla->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']);
} else {
$calendars_id = Entity::getUsedConfig('calendars_id', $item->fields['entities_id']);
if ($calendars_id != 0) {
// Ticket entity have calendar
$calendar = new Calendar();
$calendar->getFromDB($calendars_id);
$currenttime = $calendar->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s'));
$totaltime = $calendar->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']);
} else {
// No calendar
$currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($item->fields['date']);
$totaltime = strtotime($data[$num][0]['name']) - strtotime($item->fields['date']);
}
}
if ($totaltime != 0) {
$percentage = round(100 * $currenttime / $totaltime);
} else {
// Total time is null : no active time
$percentage = 100;
}
if ($percentage > 100) {
$percentage = 100;
}
$percentage_text = $percentage;
if ($_SESSION['glpiduedatewarning_unit'] == '%') {
$less_warn_limit = $_SESSION['glpiduedatewarning_less'];
$less_warn = 100 - $percentage;
} else {
if ($_SESSION['glpiduedatewarning_unit'] == 'hour') {
$less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP;
$less_warn = $totaltime - $currenttime;
} else {
if ($_SESSION['glpiduedatewarning_unit'] == 'day') {
$less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP;
示例6: cronSoftware
/**
* Cron action on softwares : alert on expired licences
*
* @param $task to log, if NULL display (default NULL)
*
* @return 0 : nothing to do 1 : done with success
**/
static function cronSoftware($task = NULL)
{
global $DB, $CFG_GLPI;
$cron_status = 1;
if (!$CFG_GLPI['use_mailing']) {
return 0;
}
$message = array();
$items_notice = array();
$items_end = array();
foreach (Entity::getEntitiesToNotify('use_licenses_alert') as $entity => $value) {
$before = Entity::getUsedConfig('send_licenses_alert_before_delay', $entity);
// Check licenses
$query = "SELECT `glpi_softwarelicenses`.*,\n `glpi_softwares`.`name` AS softname\n FROM `glpi_softwarelicenses`\n INNER JOIN `glpi_softwares`\n ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n LEFT JOIN `glpi_alerts`\n ON (`glpi_softwarelicenses`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'SoftwareLicense'\n AND `glpi_alerts`.`type` = '" . Alert::END . "')\n WHERE `glpi_alerts`.`date` IS NULL\n AND `glpi_softwarelicenses`.`expire` IS NOT NULL\n AND DATEDIFF(`glpi_softwarelicenses`.`expire`,\n CURDATE()) < '{$before}'\n AND `glpi_softwares`.`is_template` = '0'\n AND `glpi_softwares`.`is_deleted` = '0'\n AND `glpi_softwares`.`entities_id` = '" . $entity . "'";
$message = "";
$items = array();
foreach ($DB->request($query) as $license) {
$name = $license['softname'] . ' - ' . $license['name'] . ' - ' . $license['serial'];
//TRANS: %1$s the license name, %2$s is the expiration date
$message .= sprintf(__('License %1$s expired on %2$s'), Html::convDate($license["expire"]), $name) . "<br>\n";
$items[$license['id']] = $license;
}
if (!empty($items)) {
$alert = new Alert();
$options['entities_id'] = $entity;
$options['licenses'] = $items;
if (NotificationEvent::raiseEvent('alert', new self(), $options)) {
$entityname = Dropdown::getDropdownName("glpi_entities", $entity);
if ($task) {
//TRANS: %1$s is the entity, %2$s is the message
$task->log(sprintf(__('%1$s: %2$s') . "\n", $entityname, $message));
$task->addVolume(1);
} else {
Session::addMessageAfterRedirect(sprintf(__('%1$s: %2$s'), $entityname, $message));
}
$input["type"] = Alert::END;
$input["itemtype"] = 'SoftwareLicense';
// add alerts
foreach ($items as $ID => $consumable) {
$input["items_id"] = $ID;
$alert->add($input);
unset($alert->fields['id']);
}
} else {
$entityname = Dropdown::getDropdownName('glpi_entities', $entity);
//TRANS: %s is entity name
$msg = sprintf(__('%1$s: %2$s'), $entityname, __('Send licenses alert failed'));
if ($task) {
$task->log($msg);
} else {
Session::addMessageAfterRedirect($msg, false, ERROR);
}
}
}
}
return $cron_status;
}
示例7: computerSoftwareTransformation
function computerSoftwareTransformation($a_inventory, $entities_id)
{
/*
* Sometimes we can have 2 same software, but one without manufacturer and
* one with. So in this case, delete the software without manufacturer
*/
$softwareWithManufacturer = array();
$softwareWithoutManufacturer = array();
$entities_id_software = Entity::getUsedConfig('entities_id_software', $entities_id);
$is_software_recursive = 0;
$nb_RuleDictionnarySoftware = countElementsInTable("glpi_rules", "`sub_type`='RuleDictionnarySoftware'\n AND `is_active`='1'");
//Configuration says that software can be created in the computer's entity
if ($entities_id_software < 0) {
$entities_id_software = $entities_id;
} else {
//Software will be created in an entity which is not the computer's entity.
//It should be set as recursive
$is_software_recursive = 1;
}
$a_inventory['software'] = array();
$rulecollection = new RuleDictionnarySoftwareCollection();
foreach ($a_inventory['SOFTWARES'] as $a_softwares) {
if (isset($a_softwares['PUBLISHER']) && gettype($a_softwares['PUBLISHER']) == 'array') {
$a_softwares['PUBLISHER'] = current($a_softwares['PUBLISHER']);
}
$array_tmp = $this->addValues($a_softwares, array('PUBLISHER' => 'manufacturers_id', 'NAME' => 'name', 'VERSION' => 'version'));
if (!isset($array_tmp['name']) || $array_tmp['name'] == '') {
if (isset($a_softwares['GUID']) && $a_softwares['GUID'] != '') {
$array_tmp['name'] = $a_softwares['GUID'];
}
}
if (!(!isset($array_tmp['name']) || $array_tmp['name'] == '')) {
if (count($array_tmp) > 0) {
$res_rule = array();
if ($nb_RuleDictionnarySoftware > 0) {
$res_rule = $rulecollection->processAllRules(array("name" => $array_tmp['name'], "manufacturer" => $array_tmp['manufacturers_id'], "old_version" => $array_tmp['version'], "entities_id" => $entities_id_software));
}
if (isset($res_rule['_ignore_import']) && $res_rule['_ignore_import'] == 1) {
} else {
if (isset($res_rule["name"])) {
$array_tmp['name'] = $res_rule["name"];
}
if (isset($res_rule["version"])) {
$array_tmp['version'] = $res_rule["version"];
}
if (isset($res_rule["manufacturer"])) {
$array_tmp['manufacturers_id'] = Dropdown::import("Manufacturer", array('name' => $res_rule["manufacturer"]));
} else {
if (isset($array_tmp['manufacturers_id']) && $array_tmp['manufacturers_id'] != '' && $array_tmp['manufacturers_id'] != '0') {
if (!isset($this->manufacturer_cache[$array_tmp['manufacturers_id']])) {
$new_value = Dropdown::importExternal('Manufacturer', $array_tmp['manufacturers_id']);
$this->manufacturer_cache[$array_tmp['manufacturers_id']] = $new_value;
}
$array_tmp['manufacturers_id'] = $this->manufacturer_cache[$array_tmp['manufacturers_id']];
} else {
$array_tmp['manufacturers_id'] = 0;
}
}
if (isset($res_rule['new_entities_id'])) {
$array_tmp['entities_id'] = $res_rule['new_entities_id'];
$is_software_recursive = 1;
}
if (!isset($array_tmp['entities_id']) || $array_tmp['entities_id'] == '') {
$array_tmp['entities_id'] = $entities_id_software;
}
if (!isset($array_tmp['version'])) {
$array_tmp['version'] = "";
}
$array_tmp['is_template_computer'] = 0;
$array_tmp['is_deleted_computer'] = 0;
$array_tmp['is_recursive'] = $is_software_recursive;
$comp_key = strtolower($array_tmp['name']) . "\$\$\$\$" . strtolower($array_tmp['version']) . "\$\$\$\$" . $array_tmp['manufacturers_id'] . "\$\$\$\$" . $array_tmp['entities_id'];
$comp_key_simple = strtolower($array_tmp['name']) . "\$\$\$\$" . strtolower($array_tmp['version']) . "\$\$\$\$" . $array_tmp['entities_id'];
if ($array_tmp['manufacturers_id'] == 0) {
$softwareWithoutManufacturer[$comp_key_simple] = $array_tmp;
} else {
if (!isset($a_inventory['software'][$comp_key])) {
$softwareWithManufacturer[$comp_key_simple] = 1;
$a_inventory['software'][$comp_key] = $array_tmp;
}
}
}
}
}
}
foreach ($softwareWithoutManufacturer as $key => $array_tmp) {
if (!isset($softwareWithManufacturer[$key])) {
$comp_key = strtolower($array_tmp['name']) . "\$\$\$\$" . strtolower($array_tmp['version']) . "\$\$\$\$" . $array_tmp['manufacturers_id'] . "\$\$\$\$" . $array_tmp['entities_id'];
if (!isset($a_inventory['software'][$comp_key])) {
$a_inventory['software'][$comp_key] = $array_tmp;
}
}
}
unset($a_inventory['SOFTWARES']);
return $a_inventory;
}
示例8: cronInfocom
/**
* Cron action on infocom : alert on expired warranty
*
* @param $task to log, if NULL use display (default NULL)
*
* @return 0 : nothing to do 1 : done with success
**/
static function cronInfocom($task = NULL)
{
global $DB, $CFG_GLPI;
if (!$CFG_GLPI["use_mailing"]) {
return 0;
}
$message = array();
$cron_status = 0;
$items_infos = array();
$items_messages = array();
foreach (Entity::getEntitiesToNotify('use_infocoms_alert') as $entity => $value) {
$before = Entity::getUsedConfig('send_infocoms_alert_before_delay', $entity);
$query_end = "SELECT `glpi_infocoms`.*\n FROM `glpi_infocoms`\n LEFT JOIN `glpi_alerts` ON (`glpi_infocoms`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'Infocom'\n AND `glpi_alerts`.`type`='" . Alert::END . "')\n WHERE (`glpi_infocoms`.`alert` & " . pow(2, Alert::END) . ") >'0'\n AND `glpi_infocoms`.`entities_id`='" . $entity . "'\n AND `glpi_infocoms`.`warranty_duration`>'0'\n AND `glpi_infocoms`.`warranty_date` IS NOT NULL\n AND DATEDIFF(ADDDATE(`glpi_infocoms`.`warranty_date`,\n INTERVAL (`glpi_infocoms`.`warranty_duration`)\n MONTH),\n CURDATE() ) < '{$before}'\n AND `glpi_alerts`.`date` IS NULL";
foreach ($DB->request($query_end) as $data) {
if ($item_infocom = getItemForItemtype($data["itemtype"])) {
if ($item_infocom->getFromDB($data["items_id"])) {
$entity = $data['entities_id'];
$warranty = self::getWarrantyExpir($data["warranty_date"], $data["warranty_duration"]);
//TRANS: %1$s is a type, %2$s is a name (used in croninfocom)
$name = sprintf(__('%1$s - %2$s'), $item_infocom->getTypeName(1), $item_infocom->getName());
//TRANS: %1$s is the warranty end date and %2$s the name of the item
$message = sprintf(__('Item reaching the end of warranty on %1$s: %2$s'), $warranty, $name) . "<br>";
$data['warrantyexpiration'] = $warranty;
$data['item_name'] = $item_infocom->getName();
$items_infos[$entity][$data['id']] = $data;
if (!isset($items_messages[$entity])) {
$items_messages[$entity] = __('No item reaching the end of warranty.') . "<br>";
}
$items_messages[$entity] .= $message;
}
}
}
}
foreach ($items_infos as $entity => $items) {
if (NotificationEvent::raiseEvent("alert", new self(), array('entities_id' => $entity, 'items' => $items))) {
$message = $items_messages[$entity];
$cron_status = 1;
if ($task) {
$task->log(sprintf(__('%1$s: %2$s') . "\n", Dropdown::getDropdownName("glpi_entities", $entity), $message));
$task->addVolume(1);
} else {
Session::addMessageAfterRedirect(sprintf(__('%1$s: %2$s'), Dropdown::getDropdownName("glpi_entities", $entity), $message));
}
$alert = new Alert();
$input["itemtype"] = 'Infocom';
$input["type"] = Alert::END;
foreach ($items as $id => $item) {
$input["items_id"] = $id;
$alert->add($input);
unset($alert->fields['id']);
}
} else {
$entityname = Dropdown::getDropdownName('glpi_entities', $entity);
//TRANS: %s is entity name
$msg = sprintf(__('%1$s: %2$s'), $entityname, __('send infocom alert failed'));
if ($task) {
$task->log($msg);
} else {
Session::addMessageAfterRedirect($msg, false, ERROR);
}
}
}
return $cron_status;
}
示例9: deleteGroupTicket
static function deleteGroupTicket(Group_Ticket $item)
{
global $DB;
$ticket = new Ticket();
$ptAssignGroup = new PluginTimelineticketAssignGroup();
$ticket->getFromDB($item->fields['tickets_id']);
$calendar = new Calendar();
$calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
$query = "SELECT MAX(`date`) AS datedebut, id\n FROM `" . $ptAssignGroup->getTable() . "`\n WHERE `tickets_id` = '" . $item->fields['tickets_id'] . "'\n AND `groups_id`='" . $item->fields['groups_id'] . "'\n AND `delay` IS NULL";
$result = $DB->query($query);
$datedebut = '';
$input = array();
if ($result && $DB->numrows($result)) {
$datedebut = $DB->result($result, 0, 'datedebut');
$input['id'] = $DB->result($result, 0, 'id');
} else {
return;
}
if (!$datedebut) {
$delay = 0;
// Utilisation calendrier
} else {
if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
$delay = $calendar->getActiveTimeBetween($datedebut, $_SESSION["glpi_currenttime"]);
} else {
// cas 24/24 - 7/7
$delay = strtotime($_SESSION["glpi_currenttime"]) - strtotime($datedebut);
}
}
$input['delay'] = $delay;
$ptAssignGroup->update($input);
}
示例10: giveItem
//.........这里部分代码省略.........
$out = "<a id='ticket{$itemtype}" . $data['id'] . "' ";
$out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&') . "\">";
$out .= $data[$NAME . $num] . "</a>";
} else {
$out = $data[$NAME . $num];
}
return $out;
case "glpi_tickets.due_date":
// Due date + progress
if ($ID == 151) {
$out = Html::convDate($data[$NAME . $num]);
// No due date in waiting status
if ($data[$NAME . $num . '_2'] == CommonITILObject::WAITING) {
return '';
}
if (empty($data[$NAME . $num])) {
return '';
}
if ($data[$NAME . $num . '_2'] == Ticket::SOLVED || $data[$NAME . $num . '_2'] == Ticket::CLOSED) {
return $data[$NAME . $num];
}
$ticket = new Ticket();
$ticket->getFromDB($data['ITEM_0']);
$percentage = 0;
$totaltime = 0;
$currenttime = 0;
if ($ticket->fields['slas_id'] != 0) {
// Have SLA
$sla = new SLA();
$sla->getFromDB($ticket->fields['slas_id']);
$currenttime = $sla->getActiveTimeBetween($ticket->fields['date'], date('Y-m-d H:i:s'));
$totaltime = $sla->getActiveTimeBetween($ticket->fields['date'], $data[$NAME . $num]);
} else {
$calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
if ($calendars_id != 0) {
// Ticket entity have calendar
$calendar = new Calendar();
$calendar->getFromDB($calendars_id);
$currenttime = $calendar->getActiveTimeBetween($ticket->fields['date'], date('Y-m-d H:i:s'));
$totaltime = $calendar->getActiveTimeBetween($ticket->fields['date'], $data[$NAME . $num]);
} else {
// No calendar
$currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($ticket->fields['date']);
$totaltime = strtotime($data[$NAME . $num]) - strtotime($ticket->fields['date']);
}
}
if ($totaltime != 0) {
$percentage = round(100 * $currenttime / $totaltime);
} else {
// Total time is null : no active time
$percentage = 100;
}
if ($percentage > 100) {
$percentage = 100;
}
$percentage_text = $percentage;
if ($_SESSION['glpiduedatewarning_unit'] == '%') {
$less_warn_limit = $_SESSION['glpiduedatewarning_less'];
$less_warn = 100 - $percentage;
} else {
if ($_SESSION['glpiduedatewarning_unit'] == 'hours') {
$less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP;
$less_warn = $totaltime - $currenttime;
} else {
if ($_SESSION['glpiduedatewarning_unit'] == 'days') {
$less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP;
示例11: showTimeline
function showTimeline(Ticket $ticket, $params = array())
{
global $DB, $CFG_GLPI;
/* Create and populate the pData object */
$MyData = new pData();
/* Create the pChart object */
$myPicture = new pImage(820, 29, $MyData);
/* Create the pIndicator object */
$Indicator = new pIndicator($myPicture);
$myPicture->setFontProperties(array("FontName" => GLPI_ROOT . "/plugins/timelineticket/lib/pChart2.1.4/fonts/pf_arma_five.ttf", "FontSize" => 6));
/* Define the indicator sections */
$IndicatorSections = array();
$a_states = array(Ticket::INCOMING, Ticket::ASSIGNED, Ticket::PLANNED, Ticket::WAITING, Ticket::SOLVED, Ticket::CLOSED);
$a_status_color = array();
$a_status_color[Ticket::INCOMING] = array('R' => 197, 'G' => 204, 'B' => 79);
$a_status_color[Ticket::ASSIGNED] = array('R' => 38, 'G' => 174, 'B' => 38);
$a_status_color[Ticket::PLANNED] = array('R' => 255, 'G' => 102, 'B' => 0);
$a_status_color[Ticket::WAITING] = array('R' => 229, 'G' => 184, 'B' => 0);
$a_status_color[Ticket::SOLVED] = array('R' => 83, 'G' => 141, 'B' => 184);
$a_status_color[Ticket::CLOSED] = array('R' => 51, 'G' => 51, 'B' => 51);
$delaystatus = array();
foreach ($a_states as $status) {
$IndicatorSections[$status] = '';
$delaystatus[$status] = 0;
}
$a_status = $this->find("`tickets_id`='" . $ticket->getField('id') . "'", "`date`");
$begin = 0;
if ($params['totaltime'] > 0) {
foreach ($a_status as $data) {
foreach ($a_states as $statusSection) {
$R = 235;
$G = 235;
$B = 235;
$caption = '';
if ($statusSection == $data['old_status']) {
$R = $a_status_color[$statusSection]['R'];
$G = $a_status_color[$statusSection]['G'];
$B = $a_status_color[$statusSection]['B'];
//$caption = $status;
$delaystatus[$statusSection] += round($data['delay'] * 100 / $params['totaltime'], 2);
}
$IndicatorSections[$statusSection][] = array("Start" => $begin, "End" => $begin + $data['delay'], "Caption" => $caption, "R" => $R, "G" => $G, "B" => $B);
}
$begin += $data['delay'];
}
if ($ticket->fields['status'] != Ticket::CLOSED) {
foreach ($a_states as $statusSection) {
$R = 235;
$G = 235;
$B = 235;
$caption = ' ';
if ($statusSection == $ticket->fields['status']) {
$R = $a_status_color[$statusSection]['R'];
$G = $a_status_color[$statusSection]['G'];
$B = $a_status_color[$statusSection]['B'];
//$caption = $status;
$delaystatus[$statusSection] += round(($params['totaltime'] - $begin) * 100 / $params['totaltime'], 2);
}
$IndicatorSections[$statusSection][] = array("Start" => $begin, "End" => $begin + ($params['totaltime'] - $begin), "Caption" => $caption, "R" => $R, "G" => $G, "B" => $B);
}
}
}
if (count($a_status) > 1) {
foreach ($a_states as $status) {
echo "<tr class='tab_bg_2'>";
echo "<td width='100'>";
echo Ticket::getStatus($status);
echo "<br/>(" . $delaystatus[$status] . "%)";
echo "</td>";
echo "<td>";
if ($ticket->fields['status'] != Ticket::CLOSED) {
$IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => FALSE, "ValueDisplay" => false, "IndicatorSections" => $IndicatorSections[$status], "SectionsMargin" => 0);
$Indicator->draw(2, 2, 805, 25, $IndicatorSettings);
} else {
$IndicatorSettings = array("Values" => array(100, 201), "CaptionPosition" => INDICATOR_CAPTION_BOTTOM, "CaptionLayout" => INDICATOR_CAPTION_DEFAULT, "CaptionR" => 0, "CaptionG" => 0, "CaptionB" => 0, "DrawLeftHead" => FALSE, "DrawRightHead" => FALSE, "ValueDisplay" => false, "IndicatorSections" => $IndicatorSections[$status], "SectionsMargin" => 0);
$Indicator->draw(2, 2, 814, 25, $IndicatorSettings);
}
$filename = $uid = Session::getLoginUserID(false) . "_test" . $status;
$myPicture->render(GLPI_GRAPH_DIR . "/" . $filename . ".png");
echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file=" . $filename . ".png'><br/>";
echo "</td>";
echo "</tr>";
}
}
// Display ticket have Due date
if ($ticket->fields['due_date'] && strtotime(date('Y-m-d H:i:s') - strtotime($ticket->fields['due_date'])) > 0) {
$calendar = new Calendar();
$calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
$duedate = $calendar->getActiveTimeBetween($ticket->fields['date'], $ticket->fields['due_date']);
if ($ticket->fields['closedate']) {
$dateend = $calendar->getActiveTimeBetween($ticket->fields['due_date'], $ticket->fields['closedate']);
} else {
$dateend = $calendar->getActiveTimeBetween($ticket->fields['due_date'], date('Y-m-d H:i:s'));
}
} else {
// cas 24/24 - 7/7
$duedate = strtotime($ticket->fields['due_date']) - strtotime($ticket->fields['date']);
if ($ticket->fields['closedate']) {
$dateend = strtotime($ticket->fields['closedate']) - strtotime($ticket->fields['due_date']);
//.........这里部分代码省略.........
示例12: plugin_timelineticket_giveItem
function plugin_timelineticket_giveItem($type, $ID, $data, $num)
{
global $CFG_GLPI, $DB;
$searchopt =& Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
switch ($table . '.' . $field) {
case "glpi_plugin_timelineticket_grouplevels.groups":
if (empty($data["ITEM_{$num}"])) {
$out = __('None');
} else {
$out = "";
$groups = json_decode($data["ITEM_{$num}"], true);
if (!empty($groups)) {
foreach ($groups as $key => $val) {
$out .= Dropdown::getDropdownName("glpi_groups", $val) . "<br>";
}
}
}
return $out;
break;
case "glpi_plugin_timelineticket_assigngroups.groups_id":
$ptAssignGroup = new PluginTimelineticketAssignGroup();
$group = new Group();
$ticket = new Ticket();
$out = "";
$a_out = array();
$a_groupname = array();
if (!isset($data["ITEM_{$num}"]) or !strstr($data["ITEM_{$num}"], '$$')) {
return "";
}
$splitg = explode("\$\$\$\$", $data["ITEM_{$num}"]);
foreach ($splitg as $datag) {
$split = explode("\$\$", $datag);
$group->getFromDB($split[0]);
$ptAssignGroup->getFromDB($split[1]);
$time = $ptAssignGroup->fields['delay'];
if ($ptAssignGroup->fields['delay'] === NULL) {
$ticket->getFromDB($data["ITEM_0"]);
$calendar = new Calendar();
$calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
$datedebut = $ptAssignGroup->fields['date'];
$enddate = $_SESSION["glpi_currenttime"];
if ($ticket->fields['status'] == Ticket::CLOSED) {
$enddate = $ticket->fields['closedate'];
}
if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) {
$time = $calendar->getActiveTimeBetween($datedebut, $enddate);
} else {
// cas 24/24 - 7/7
$time = strtotime($enddate) - strtotime($datedebut);
}
} else {
if ($ptAssignGroup->fields['delay'] == 0) {
$time = 0;
}
}
$a_groupname[$group->fields['id']] = $group->getLink();
if (isset($a_out[$group->fields['id']])) {
$a_out[$group->fields['id']] += $time;
} else {
$a_out[$group->fields['id']] = $time;
}
}
$a_out_comp = array();
foreach ($a_out as $groups_id => $time) {
$a_out_comp[] = $a_groupname[$groups_id] . " : " . Html::timestampToString($time, TRUE, FALSE);
}
$out = implode("<hr/>", $a_out_comp);
return $out;
break;
}
return "";
}
示例13: prepareInputForAdd
function prepareInputForAdd($input)
{
global $DB;
if (!isset($input['create_time']) || empty($input['create_time'])) {
$input['create_time'] = $_SESSION["glpi_currenttime"];
}
if (!isset($input['send_time']) || empty($input['send_time'])) {
$toadd = 0;
if (isset($input['entities_id'])) {
$toadd = Entity::getUsedConfig('delay_send_emails', $input['entities_id']);
}
if ($toadd > 0) {
$input['send_time'] = date("Y-m-d H:i:s", strtotime($_SESSION["glpi_currenttime"]) + $toadd * MINUTE_TIMESTAMP);
} else {
$input['send_time'] = $_SESSION["glpi_currenttime"];
}
}
$input['sent_try'] = 0;
if (isset($input['headers']) && is_array($input['headers']) && count($input['headers'])) {
$input["headers"] = exportArrayToDB($input['headers']);
} else {
$input['headers'] = '';
}
if (isset($input['documents']) && is_array($input['documents']) && count($input['documents'])) {
$input["documents"] = exportArrayToDB($input['documents']);
} else {
$input['documents'] = '';
}
// Force items_id to integer
if (!isset($input['items_id']) || empty($input['items_id'])) {
$input['items_id'] = 0;
}
// Drop existing mails in queue for the same event and item and recipient
if (isset($input['itemtype']) && !empty($input['itemtype']) && isset($input['entities_id']) && $input['entities_id'] >= 0 && isset($input['items_id']) && $input['items_id'] >= 0 && isset($input['notificationtemplates_id']) && !empty($input['notificationtemplates_id']) && isset($input['recipient'])) {
$query = "NOT `is_deleted`\n AND `itemtype` = '" . $input['itemtype'] . "'\n AND `items_id` = '" . $input['items_id'] . "'\n AND `entities_id` = '" . $input['entities_id'] . "'\n AND `notificationtemplates_id` = '" . $input['notificationtemplates_id'] . "'\n AND `recipient` = '" . $input['recipient'] . "'";
foreach ($DB->request($this->getTable(), $query) as $data) {
$this->delete(array('id' => $data['id']), 1);
}
}
return $input;
}
示例14: getDatasForObject
/**
* @see NotificationTargetCommonITILObject::getDatasForObject()
**/
function getDatasForObject(CommonDBTM $item, array $options, $simple = false)
{
global $CFG_GLPI;
// Common ITIL datas
$datas = parent::getDatasForObject($item, $options, $simple);
$datas['##ticket.description##'] = Html::clean($datas['##ticket.description##']);
$datas['##ticket.description##'] = $item->convertContentForNotification($datas['##ticket.description##'], $item);
$datas['##ticket.content##'] = $datas['##ticket.description##'];
// Specific datas
$datas['##ticket.urlvalidation##'] = $this->formatURL($options['additionnaloption']['usertype'], "ticket_" . $item->getField("id") . "_TicketValidation\$1");
$datas['##ticket.globalvalidation##'] = TicketValidation::getStatus($item->getField('global_validation'));
$datas['##ticket.type##'] = Ticket::getTicketTypeName($item->getField('type'));
$datas['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $item->getField('requesttypes_id'));
$autoclose_value = Entity::getUsedConfig('autoclose_delay', $this->getEntity(), '', Entity::CONFIG_NEVER);
$datas['##ticket.autoclose##'] = __('Never');
$datas['##lang.ticket.autoclosewarning##'] = "";
if ($autoclose_value > 0) {
$datas['##ticket.autoclose##'] = $autoclose_value;
$datas['##lang.ticket.autoclosewarning##'] = sprintf(_n('Without a reply, the ticket will be automatically closed after %s day', 'Without a reply, the ticket will be automatically closed after %s days', $autoclose_value), $autoclose_value);
}
$datas['##ticket.sla##'] = '';
if ($item->getField('slas_id')) {
$datas['##ticket.sla##'] = Dropdown::getDropdownName('glpi_slas', $item->getField('slas_id'));
}
$datas['##ticket.location##'] = '';
if ($item->getField('locations_id')) {
$datas['##ticket.location##'] = Dropdown::getDropdownName('glpi_locations', $item->getField('locations_id'));
}
// is ticket deleted
$datas['##ticket.isdeleted##'] = Dropdown::getYesNo($item->getField('is_deleted'));
//Tags associated with the object linked to the ticket
$datas['##ticket.itemtype##'] = '';
$datas['##ticket.item.name##'] = '';
$datas['##ticket.item.serial##'] = '';
$datas['##ticket.item.otherserial##'] = '';
$datas['##ticket.item.location##'] = '';
$datas['##ticket.item.contact##'] = '';
$datas['##ticket.item.contactnumber##'] = '';
$datas['##ticket.item.user##'] = '';
$datas['##ticket.item.group##'] = '';
$datas['##ticket.item.model##'] = '';
$item_ticket = new Item_Ticket();
$items = $item_ticket->find("`tickets_id` = '" . $item->getField('id') . "'");
$datas['items'] = array();
if (count($items)) {
foreach ($items as $val) {
if (isset($val['itemtype']) && ($hardware = getItemForItemtype($val['itemtype'])) && isset($val["items_id"]) && $hardware->getFromDB($val["items_id"])) {
$tmp = array();
//Object type
$tmp['##ticket.itemtype##'] = $hardware->getTypeName();
//Object name
$tmp['##ticket.item.name##'] = $hardware->getField('name');
//Object serial
if ($hardware->isField('serial')) {
$tmp['##ticket.item.serial##'] = $hardware->getField('serial');
}
//Object contact
if ($hardware->isField('contact')) {
$tmp['##ticket.item.contact##'] = $hardware->getField('contact');
}
//Object contact num
if ($hardware->isField('contact_num')) {
$tmp['##ticket.item.contactnumber##'] = $hardware->getField('contact_num');
}
//Object otherserial
if ($hardware->isField('otherserial')) {
$tmp['##ticket.item.otherserial##'] = $hardware->getField('otherserial');
}
//Object location
if ($hardware->isField('locations_id')) {
$tmp['##ticket.item.location##'] = Dropdown::getDropdownName('glpi_locations', $hardware->getField('locations_id'));
}
//Object user
if ($hardware->getField('users_id')) {
$user_tmp = new User();
if ($user_tmp->getFromDB($hardware->getField('users_id'))) {
$tmp['##ticket.item.user##'] = $user_tmp->getName();
}
}
//Object group
if ($hardware->getField('groups_id')) {
$tmp['##ticket.item.group##'] = Dropdown::getDropdownName('glpi_groups', $hardware->getField('groups_id'));
}
$modeltable = getSingular($hardware->getTable()) . "models";
$modelfield = getForeignKeyFieldForTable($modeltable);
if ($hardware->isField($modelfield)) {
$tmp['##ticket.item.model##'] = Dropdown::getDropdownName($modeltable, $hardware->getField($modelfield));
}
$datas['items'][] = $tmp;
}
}
}
$datas['##ticket.numberofitems##'] = count($datas['items']);
// Get followups, log, validation, satisfaction, linked tickets
if (!$simple) {
// Linked tickets
$linked_tickets = Ticket_Ticket::getLinkedTicketsTo($item->getField('id'));
//.........这里部分代码省略.........
示例15: getPeriodTime
static function getPeriodTime(CommonGLPI $ticket, $start, $end)
{
$totaltime = 0;
if ($ticket->fields['slas_id'] != 0) {
// Have SLA
$sla = new SLA();
$sla->getFromDB($ticket->fields['slas_id']);
$totaltime = $sla->getActiveTimeBetween($start, $end);
} else {
$calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
if ($calendars_id != 0) {
// Ticket entity have calendar
$calendar = new Calendar();
$calendar->getFromDB($calendars_id);
$totaltime = $calendar->getActiveTimeBetween($start, $end);
} else {
// No calendar
$totaltime = strtotime($end) - strtotime($start);
}
}
return $totaltime;
}