function executeActions($output, $params) { if (count($this->actions)) { foreach ($this->actions as $action) { switch ($action->fields["action_type"]) { case "assign": $output[$action->fields["field"]] = $action->fields["value"]; break; case "regex_result": //Assign entity using the regex's result if ($action->fields["field"] == "_affect_entity_by_tag") { //Get the TAG from the regex's results if (isset($this->regex_results[0])) { $res = RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]); } else { $res = $action->fields["value"]; } if ($res != null) { //Get the entity associated with the TAG $target_entity = EntityData::getEntityIDByTag($res); if ($target_entity != '') { $output["entities_id"] = $target_entity; } } } break; } } } return $output; }
if (haveRight('own_ticket', 1) && haveRight('update_ticket', 1)) { $users_id_requester = 0; } // Set default value... $values = array('_users_id_requester' => $users_id_requester, '_users_id_requester_notif' => array('use_notification' => 1), '_groups_id_requester' => 0, '_users_id_assign' => 0, '_users_id_assign_notif' => array('use_notification' => 1), '_groups_id_assign' => 0, '_users_id_observer' => 0, '_users_id_observer_notif' => array('use_notification' => 1), '_groups_id_observer' => 0, 'suppliers_id_assign' => 0, 'name' => '', 'content' => '', 'ticketcategories_id' => 0, 'urgency' => 3, 'impact' => 3, 'priority' => Ticket::computePriority(3, 3), 'requesttypes_id' => $_SESSION["glpidefault_requesttypes_id"], 'hour' => 0, 'minute' => 0, 'date' => $_SESSION["glpi_currenttime"], 'entities_id' => $_SESSION["glpiactive_entity"], 'status' => 'new', 'followup' => array(), 'itemtype' => '', 'items_id' => 0, 'plan' => array(), 'global_validation' => 'none', 'due_date' => '', 'slas_id' => 0, '_add_validation' => 0, 'type' => -1); // Restore saved value or override with page parameter foreach ($values as $name => $value) { if (isset($_REQUEST[$name])) { $values[$name] = $_REQUEST[$name]; } else { if (isset($_SESSION["helpdeskSaved"][$name])) { $values[$name] = $_SESSION["helpdeskSaved"]["{$name}"]; } } } // Clean text fields $values['name'] = stripslashes($values['name']); $values['content'] = cleanPostForTextArea($values['content']); if (isset($_SESSION["helpdeskSaved"])) { unset($_SESSION["helpdeskSaved"]); } if ($values['type'] <= 0) { $values['type'] = EntityData::getUsedConfig('tickettype', $values['entities_id']); } $track->showForm(0, $values); } if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") { helpFooter(); } else { commonFooter(); }
/** * Display content of Tab * * @param $ID of the item * @param $tab number of the tab * * @return true if handled (for class stack) */ function showTabContent($ID, $tab) { global $CFG_GLPI; if (!$this->isNewID($ID)) { switch ($tab) { case -1: // All $this->showChildren($ID); EntityData::showStandardOptions($this); Profile_User::showForEntity($this); $collection = new RuleRightCollection(); if ($collection->canList()) { $ldaprule = new RuleRight(); $ldaprule->showAndAddRuleForm($this); } $collection = new RuleOcsCollection(); if ($collection->canList()) { $ocsrule = new RuleOcs(); $ocsrule->showAndAddRuleForm($this); } $collection = new RuleMailCollectorCollection(); if ($collection->canList()) { $mailcollector = new RuleMailCollector(); $mailcollector->showAndAddRuleForm($this); } Document::showAssociated($this); EntityData::showNotificationOptions($this); EntityData::showHelpdeskOptions($this); EntityData::showInventoryOptions($this); Plugin::displayAction($this, $tab); break; case 2: EntityData::showStandardOptions($this); break; case 3: Profile_User::showForEntity($this); break; case 4: $collection = new RuleRightCollection(); if ($collection->canList()) { $ldaprule = new RuleRight(); $ldaprule->showAndAddRuleForm($this); } $collection = new RuleOcsCollection(); if ($collection->canList()) { $ocsrule = new RuleOcs(); $ocsrule->showAndAddRuleForm($this); } $collection = new RuleMailCollectorCollection(); if ($collection->canList()) { $mailcollector = new RuleMailCollector(); $mailcollector->showAndAddRuleForm($this); } break; case 5: EntityData::showAdvancedOptions($this); break; case 6: Document::showAssociated($this); break; case 7: EntityData::showNotificationOptions($this); break; case 8: EntityData::showHelpdeskOptions($this); break; case 9: EntityData::showInventoryOptions($this); break; case 10: showNotesForm(getItemTypeFormURL('EntityData'), 'EntityData', $_POST["id"]); break; default: if (!Plugin::displayAction($this, $tab)) { $this->showChildren($ID); } return false; } } return false; }
/** * Recovery datas of current entity or parent entity * * @param $fieldref string name of the referent field to know if we look at parent entity * @param $entities_id * @param $fieldval string name of the field that we want value **/ static function getUsedConfig($fieldref, $entities_id, $fieldval = '') { // for calendar if (empty($fieldval)) { $fieldval = $fieldref; } $entdata = new EntityData(); // Search in entity data of the current entity if ($entdata->getFromDB($entities_id)) { // Value is defined : use it if (isset($entdata->fields[$fieldref]) && ($entdata->fields[$fieldref] > 0 || !is_numeric($entdata->fields[$fieldref]))) { return $entdata->fields[$fieldval]; } } // Entity data not found or not defined : search in parent one if ($entities_id > 0) { $current = new Entity(); if ($current->getFromDB($entities_id)) { return self::getUsedConfig($fieldref, $current->fields['entities_id'], $fieldval); } } switch ($fieldval) { case "tickettype": // Default is Incident if not set return Ticket::INCIDENT_TYPE; } return 0; }
function executeActions($output, $params) { if (count($this->actions)) { foreach ($this->actions as $action) { switch ($action->fields["action_type"]) { case "assign": switch ($action->fields["field"]) { default: $output[$action->fields["field"]] = $action->fields["value"]; break; case "_affect_entity_by_user_entity": //3 cases : //1 - rule contains a criteria like : Profil is XXXX // -> in this case, profiles_id is stored in // $this->criterias_results['PROFILES'] (one value possible) //2- rule contains criteria "User has only one profile" // -> in this case, profiles_id is stored in // $this->criterias_results['PROFILES'] (one value possible) (same as 1) //3 -> rule contains only one profile $profile = 0; //Case 2: if (isset($this->criterias_results['ONE_PROFILE'])) { $profile = $this->criterias_results['ONE_PROFILE']; //Case 3 } else { if (isset($this->criterias_results['UNIQUE_PROFILE'])) { $profile = $this->criterias_results['UNIQUE_PROFILE']; //Case 1 } else { if (isset($this->criterias_results['PROFILES'])) { $profile = $this->criterias_results['PROFILES']; } } } if ($profile) { $entities = array(); if (isset($params['_users_id_requester'])) { // Not set when testing $entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile); } //Case 2 : check if there's only one profile for this user if (isset($this->criterias_results['ONE_PROFILE']) && count($entities) == 1 || !isset($this->criterias_results['ONE_PROFILE'])) { if (count($entities) == 1) { //User has right on only one entity $output['entities_id'] = array_pop($entities); } else { if (isset($this->criterias_results['UNIQUE_PROFILE'])) { $output['entities_id'] = array_pop($entities); } else { //Rights on more than one entity : get the user's prefered entity if (isset($params['_users_id_requester'])) { // Not set when testing $user = new User(); $user->getFromDB($params['_users_id_requester']); //If an entity is defined in user's preferences, use this one //else do not set the rule as matched if (is_integer($user->getField('entities_id'))) { $output['entities_id'] = $user->fields['entities_id']; } } } } } } } break; case "regex_result": foreach ($this->regex_results as $regex_result) { $entity_found = -1; $res = RuleAction::getRegexResultById($action->fields["value"], $regex_result); if ($res != null) { switch ($action->fields["field"]) { case "_affect_entity_by_domain": $entity_found = EntityData::getEntityIDByDomain($res); break; case "_affect_entity_by_tag": $entity_found = EntityData::getEntityIDByTag($res); break; } //If an entity was found if ($entity_found > -1) { $output['entities_id'] = $entity_found; break; } } } // switch (field) break; } } } return $output; }
the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------- */ define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; $data = new EntityData(); if (isset($_POST["add"])) { $data->check(-1, 'w', $_POST); if ($data->add($_POST)) { Event::log($_POST["entities_id"], "entity", 4, "setup", $_SESSION["glpiname"] . " " . $LANG['log'][21]); } glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["update"])) { $data->check($_POST["entities_id"], 'w'); if ($data->update($_POST)) { Event::log($_POST["entities_id"], "entity", 4, "setup", $_SESSION["glpiname"] . " " . $LANG['log'][21]); } glpi_header($_SERVER['HTTP_REFERER']); } }
function prepareInputForUpdate($input) { $infocom = new self(); $infocom->getFromDB($input['id']); $entitydata = new EntityData(); $entitydata->getFromDB($infocom->fields['entities_id']); if (isset($input['warranty_duration'])) { $input['_warranty_duration'] = $this->fields['warranty_duration']; } //Check if one or more dates needs to be updated foreach (self::getAutoManagemendDatesFields() as $key => $field) { $result = EntityData::getUsedConfig($key, $infocom->fields['entities_id']); //Only update date if it's empty in DB. Otherwise do nothing if ($result > 0 && !isset($infocom->fields[$field])) { self::autofillDates($input, $field, $result); } } return $input; }
private function groups($closed = true) { global $DB; $DB->connect(); $a_storedate_temp = self::$storedate; $a_states = getAllDatasFromTable('glpi_plugin_timelineticket_assigngroups', '', FALSE, 'id'); $this->assertEquals(3, count($a_states), 'Number of lines in assigngroup table of plugin'); $ticket = new Ticket(); $calendar = new Calendar(); $ticket->getFromDB(1); $calendars_id = EntityData::getUsedConfig('calendars_id', $ticket->fields['entities_id']); // * 07/ if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) { $begin = $calendar->getActiveTimeBetween($ticket->fields['date'], $a_storedate_temp[3]); } else { // case 24/24 - 7/7 $begin = strtotime($a_storedate_temp[3]) - strtotime($ticket->fields['date']); } $a_ref = array('id' => '1', 'tickets_id' => '1', 'date' => $a_storedate_temp[3], 'groups_id' => '1', 'begin' => $begin, 'delay' => strtotime($a_storedate_temp[7]) - strtotime($a_storedate_temp[3])); $this->assertEquals($a_ref, $a_states[1], '(07/) Group 1'); // * 14/ if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) { $begin = $calendar->getActiveTimeBetween($ticket->fields['date'], $a_storedate_temp[9]); } else { // case 24/24 - 7/7 $begin = strtotime($a_storedate_temp[9]) - strtotime($ticket->fields['date']); } $a_ref = array('id' => '2', 'tickets_id' => '1', 'date' => $a_storedate_temp[9], 'groups_id' => '2', 'begin' => $begin, 'delay' => strtotime($a_storedate_temp[13]) - strtotime($a_storedate_temp[9])); $this->assertEquals($a_ref, $a_states[2], '(14/) Group 2'); // * 20/ if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) { $begin = $calendar->getActiveTimeBetween($ticket->fields['date'], $a_storedate_temp[13]); } else { // case 24/24 - 7/7 $begin = strtotime($a_storedate_temp[13]) - strtotime($ticket->fields['date']); } $a_ref = array('id' => '3', 'tickets_id' => '1', 'date' => $a_storedate_temp[13], 'groups_id' => '1', 'begin' => $begin, 'delay' => NULL); $this->assertEquals($a_ref, $a_states[3], '(20/) Group 1'); }
/** * form for satisfaction * * @param $ticket Object : the ticket **/ function showSatisfactionForm($ticket) { global $LANG; $tid = $ticket->fields['id']; $options = array(); $options['colspan'] = 1; // for external inquest => link if ($this->fields["type"] == 2) { $url = EntityData::generateLinkSatisfaction($ticket); echo "<div class='center spaced'>" . "<a href='{$url}'>" . $LANG['satisfaction'][10] . "</a><br>({$url})</div>"; // for internal inquest => form } else { $this->showFormHeader($options); // Set default satisfaction to 3 if not set if (is_null($this->fields["satisfaction"])) { $this->fields["satisfaction"] = 3; } echo "<tr class='tab_bg_2'>"; echo "<td>" . $LANG['satisfaction'][1] . " : </td>"; echo "<td>"; echo "<input type='hidden' name='tickets_id' value='{$tid}'>"; echo "<input type='hidden' id='satisfaction' name='satisfaction' value='" . $this->fields["satisfaction"] . "'>"; echo "<script type='text/javascript'>\n\n Ext.onReady(function() {\n var md = new Ext.form.StarRate({\n hiddenName: 'satisfaction',\n starConfig: {\n \tminValue: 0,\n \tmaxValue: 5,\n value:" . $this->fields["satisfaction"] . "\n },\n applyTo : 'satisfaction'\n });\n })\n </script>"; echo "</td></tr>"; echo "<tr class='tab_bg_2'>"; echo "<td rowspan='1'>" . $LANG['common'][25] . " : </td>"; echo "<td rowspan='1' class='middle'>"; echo "<textarea cols='45' rows='7' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; if ($this->fields["date_answered"] > 0) { echo "<tr class='tab_bg_2'>"; echo "<td colspan='2'>" . $LANG['satisfaction'][4] . " : "; echo convDateTime($this->fields["date_answered"]) . "</td></tr>\n"; } $options['candel'] = false; $this->showFormButtons($options); } }
/** * Get all data needed for template processing **/ function getDatasForTemplate($event, $options = array()) { global $LANG, $CFG_GLPI; //----------- Ticket infos -------------- // if ($event != 'alertnotclosed') { $fields = array('ticket.title' => 'name', 'ticket.content' => 'content', 'ticket.description' => 'content', 'ticket.costfixed' => 'cost_fixed', 'ticket.costmaterial' => 'cost_material'); foreach ($fields as $tag => $table_field) { $this->datas['##' . $tag . '##'] = $this->obj->getField($table_field); } $this->datas['##ticket.id##'] = sprintf("%07d", $this->obj->getField("id")); $this->datas['##ticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id")); $this->datas['##ticket.urlapprove##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_4"); $this->datas['##ticket.urlvalidation##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_7"); $this->datas['##ticket.entity##'] = Dropdown::getDropdownName('glpi_entities', $this->getEntity()); $events = $this->getAllEvents(); if ($event == 'validation' && isset($options['validation_status'])) { $this->datas['##ticket.action##'] = $LANG['validation'][0] . ' - ' . TicketValidation::getStatus($options['validation_status']); } else { $this->datas['##ticket.action##'] = $events[$event]; } $this->datas['##ticket.storestatus##'] = $this->obj->getField('status'); $this->datas['##ticket.status##'] = Ticket::getStatus($this->obj->getField('status')); $this->datas['##ticket.globalvalidation##'] = TicketValidation::getStatus($this->obj->getField('global_validation')); $this->datas['##ticket.type##'] = Ticket::getTicketTypeName($this->obj->getField('type')); $this->datas['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $this->obj->getField('requesttypes_id')); $this->datas['##ticket.urgency##'] = Ticket::getUrgencyName($this->obj->getField('urgency')); $this->datas['##ticket.impact##'] = Ticket::getImpactName($this->obj->getField('impact')); $this->datas['##ticket.priority##'] = Ticket::getPriorityName($this->obj->getField('priority')); $this->datas['##ticket.time##'] = Ticket::getActionTime($this->obj->getField('actiontime')); $this->datas['##ticket.costtime##'] = $this->obj->getField('cost_time'); $this->datas['##ticket.creationdate##'] = convDateTime($this->obj->getField('date')); $this->datas['##ticket.closedate##'] = convDateTime($this->obj->getField('closedate')); $this->datas['##ticket.solvedate##'] = convDateTime($this->obj->getField('solvedate')); $this->datas['##ticket.duedate##'] = convDateTime($this->obj->getField('due_date')); $entitydata = new EntityData(); $autoclose_value = $CFG_GLPI['autoclose_delay']; if ($entitydata->getFromDB($this->getEntity())) { $autoclose_value = $entitydata->getField('autoclose_delay'); // Set global config value if ($autoclose_value == -1) { $autoclose_value = $CFG_GLPI['autoclose_delay']; } } if ($autoclose_value > 0) { $this->datas['##ticket.autoclose##'] = $autoclose_value; $this->datas['##lang.ticket.autoclosewarning##'] = $LANG['job'][54] . " " . $autoclose_value . " " . $LANG['stats'][31]; } else { $this->datas['##ticket.autoclose##'] = $LANG['setup'][307]; $this->datas['##lang.ticket.autoclosewarning##'] = ""; } if ($this->obj->getField('ticketcategories_id')) { $this->datas['##ticket.category##'] = Dropdown::getDropdownName('glpi_ticketcategories', $this->obj->getField('ticketcategories_id')); } else { $this->datas['##ticket.category##'] = ''; } if ($this->obj->getField('slas_id')) { $this->datas['##ticket.sla##'] = Dropdown::getDropdownName('glpi_slas', $this->obj->getField('slas_id')); } else { $this->datas['##ticket.sla##'] = ''; } if ($this->obj->countUsers(Ticket::REQUESTER)) { $users = array(); foreach ($this->obj->getUsers(Ticket::REQUESTER) as $uid => $tmp) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); $tmp = array(); $tmp['##author.id##'] = $uid; $tmp['##author.name##'] = $user_tmp->getName(); if ($user_tmp->getField('locations_id')) { $tmp['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id')); } else { $tmp['##author.location##'] = ''; } $tmp['##author.phone##'] = $user_tmp->getField('phone'); $tmp['##author.phone2##'] = $user_tmp->getField('phone2'); $this->datas['authors'][] = $tmp; } $this->datas['##ticket.authors##'] = implode(', ', $users); } else { $this->datas['##ticket.authors##'] = ''; } if ($this->obj->getField('users_id_recipient')) { $user_tmp = new User(); $user_tmp->getFromDB($this->obj->getField('users_id_recipient')); $this->datas['##ticket.openbyuser##'] = $user_tmp->getName(); } else { $this->datas['##ticket.openbyuser##'] = ''; } if ($this->obj->countUsers(Ticket::ASSIGN)) { $users = array(); foreach ($this->obj->getUsers(Ticket::ASSIGN) as $uid => $tmp) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); } $this->datas['##ticket.assigntousers##'] = implode(', ', $users); } else { $this->datas['##ticket.assigntousers##'] = ''; } if ($this->obj->countUsers(Ticket::OBSERVER)) { $users = array(); foreach ($this->obj->getUsers(Ticket::OBSERVER) as $uid => $tmp) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); } $this->datas['##ticket.observerusers##'] = implode(', ', $users); } else { $this->datas['##ticket.observerusers##'] = ''; } if ($this->obj->getField('suppliers_id_assign')) { $this->datas['##ticket.assigntosupplier##'] = Dropdown::getDropdownName('glpi_suppliers', $this->obj->getField('suppliers_id_assign')); } else { $this->datas['##ticket.assigntosupplier##'] = ''; } if ($this->obj->countGroups(Ticket::REQUESTER)) { $groups = array(); foreach ($this->obj->getUsers(Ticket::REQUESTER) as $gid => $tmp) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $this->datas['##ticket.groups##'] = implode(', ', $groups); } else { $this->datas['##ticket.groups##'] = ''; } if ($this->obj->countGroups(Ticket::OBSERVER)) { $groups = array(); foreach ($this->obj->getGroups(Ticket::OBSERVER) as $gid => $tmp) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $this->datas['##ticket.observergroups##'] = implode(', ', $groups); } else { $this->datas['##ticket.observergroups##'] = ''; } if ($this->obj->countGroups(Ticket::ASSIGN)) { $groups = array(); foreach ($this->obj->getGroups(Ticket::ASSIGN) as $gid => $tmp) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $this->datas['##ticket.assigntogroups##'] = implode(', ', $groups); } else { $this->datas['##ticket.assigntogroups##'] = ''; } //Tags associated with the object linked to the ticket if ($this->target_object != null) { //Object type $this->datas['##ticket.itemtype##'] = $this->target_object->getTypeName(); //Object name $this->datas['##ticket.item.name##'] = $this->target_object->getField('name'); //Object serial if ($this->target_object->isField('serial')) { $this->datas['##ticket.item.serial##'] = $this->target_object->getField('serial'); } else { $this->datas['##ticket.item.serial##'] = ''; } //Object contact if ($this->target_object->isField('contact')) { $this->datas['##ticket.item.contact##'] = $this->target_object->getField('contact'); } else { $this->datas['##ticket.item.contact##'] = ''; } //Object contact num if ($this->target_object->isField('contact_num')) { $this->datas['##ticket.item.contactnumber##'] = $this->target_object->getField('contact_num'); } else { $this->datas['##ticket.item.contactnumber##'] = ''; } //Object otherserial if ($this->target_object->isField('otherserial')) { $this->datas['##ticket.item.otherserial##'] = $this->target_object->getField('otherserial'); } else { $this->datas['##ticket.item.otherserial##'] = ''; } //Object location if ($this->target_object->isField('locations_id')) { $this->datas['##ticket.item.location##'] = Dropdown::getDropdownName('glpi_locations', $this->target_object->getField('locations_id')); } else { $this->datas['##ticket.item.location##'] = ''; } //Object user $this->datas['##ticket.item.user##'] = ''; if ($this->obj->getField('users_id')) { $user_tmp = new User(); if ($user_tmp->getFromDB($this->target_object->getField('users_id'))) { $this->datas['##ticket.item.user##'] = $user_tmp->getName(); } } //Object group if ($this->obj->getField('groups_id')) { $this->datas['##ticket.item.group##'] = Dropdown::getDropdownName('glpi_groups', $this->target_object->getField('groups_id')); } else { $this->datas['##ticket.item.group##'] = ''; } $modeltable = getSingular($this->getTable()) . "models"; $modelfield = getForeignKeyFieldForTable($modeltable); if ($this->target_object->isField($modelfield)) { $this->datas['##ticket.item.model##'] = $this->target_object->getField($modelfield); } else { $this->datas['##ticket.item.model##'] = ''; } } else { $this->datas['##ticket.itemtype##'] = ''; $this->datas['##ticket.item.name##'] = ''; $this->datas['##ticket.item.serial##'] = ''; $this->datas['##ticket.item.otherserial##'] = ''; $this->datas['##ticket.item.location##'] = ''; } if ($this->obj->getField('ticketsolutiontypes_id')) { $this->datas['##ticket.solution.type##'] = Dropdown::getDropdownName('glpi_ticketsolutiontypes', $this->obj->getField('ticketsolutiontypes_id')); } else { $this->datas['##ticket.solution.type##'] = ''; } $this->datas['##ticket.solution.description##'] = unclean_cross_side_scripting_deep($this->obj->getField('solution')); // Linked tickets $linked_tickets = Ticket_Ticket::getLinkedTicketsTo($this->obj->getField('id')); if (count($linked_tickets)) { $linkedticket = new Ticket(); foreach ($linked_tickets as $data) { if ($linkedticket->getFromDB($data['tickets_id'])) { $tmp = array(); $tmp['##linkedticket.id##'] = $data['tickets_id']; $tmp['##linkedticket.link##'] = Ticket_Ticket::getLinkName($data['link']); $tmp['##linkedticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php" . "?redirect=ticket_" . $data['tickets_id']); $tmp['##linkedticket.title##'] = $linkedticket->getField('name'); $tmp['##linkedticket.content##'] = $linkedticket->getField('content'); $this->datas['linkedtickets'][] = $tmp; } } } if (!empty($this->datas['linkedtickets'])) { $this->datas['##ticket.numberoflinkedtickets##'] = count($this->datas['linkedtickets']); } else { $this->datas['##ticket.numberoflinkedtickets##'] = 0; } $restrict = "`tickets_id`='" . $this->obj->getField('id') . "'"; if (!isset($options['additionnaloption']) || !$options['additionnaloption']) { $restrict .= " AND `is_private` = '0'"; } $restrict .= " ORDER BY `date` DESC, `id` ASC"; //Task infos $tasks = getAllDatasFromTable('glpi_tickettasks', $restrict); foreach ($tasks as $task) { $tmp = array(); $tmp['##task.isprivate##'] = Dropdown::getYesNo($task['is_private']); $tmp['##task.author##'] = html_clean(getUserName($task['users_id'])); $tmp['##task.category##'] = Dropdown::getDropdownName('glpi_taskcategories', $task['taskcategories_id']); $tmp['##task.date##'] = convDateTime($task['date']); $tmp['##task.description##'] = $task['content']; $tmp['##task.time##'] = Ticket::getActionTime($task['actiontime']); $plan = new TicketPlanning(); if ($plan->getFromDBbyTask($task['id'])) { $tmp['##task.planning.user##'] = html_clean(getUserName($plan->fields['users_id'])); $tmp['##task.planning.begin##'] = convDateTime($plan->fields['begin']); $tmp['##task.planning.end##'] = convDateTime($plan->fields['end']); $tmp['##task.planning.status##'] = Planning::getState($plan->fields['state']); } else { $tmp['##task.planning.user##'] = ""; $tmp['##task.planning.begin##'] = ""; $tmp['##task.planning.end##'] = ""; $tmp['##task.planning.status##'] = ""; } $this->datas['tasks'][] = $tmp; } if (!empty($this->datas['tasks'])) { $this->datas['##ticket.numberoftasks##'] = count($this->datas['tasks']); } else { $this->datas['##ticket.numberoftasks##'] = 0; } //Followup infos $followups = getAllDatasFromTable('glpi_ticketfollowups', $restrict); foreach ($followups as $followup) { $tmp = array(); $tmp['##followup.isprivate##'] = Dropdown::getYesNo($followup['is_private']); $tmp['##followup.author##'] = html_clean(getUserName($followup['users_id'])); $tmp['##followup.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $followup['requesttypes_id']); $tmp['##followup.date##'] = convDateTime($followup['date']); $tmp['##followup.description##'] = $followup['content']; $this->datas['followups'][] = $tmp; } if (isset($this->datas['followups'])) { $this->datas['##ticket.numberoffollowups##'] = count($this->datas['followups']); } else { $this->datas['##ticket.numberoffollowups##'] = 0; } //Validation infos $restrict = "`tickets_id`='" . $this->obj->getField('id') . "'"; if (isset($options['validation_id']) && $options['validation_id']) { $restrict .= " AND `glpi_ticketvalidations`.`id` = '" . $options['validation_id'] . "'"; } $restrict .= " ORDER BY `submission_date` DESC, `id` ASC"; $validations = getAllDatasFromTable('glpi_ticketvalidations', $restrict); foreach ($validations as $validation) { $tmp = array(); $tmp['##validation.submission.title##'] = $LANG['validation'][27] . " (" . $LANG['job'][4] . " " . html_clean(getUserName($validation['users_id'])) . ")"; $tmp['##validation.answer.title##'] = $LANG['validation'][32] . " (" . $LANG['validation'][21] . " " . html_clean(getUserName($validation['users_id_validate'])) . ")"; $tmp['##validation.author##'] = html_clean(getUserName($validation['users_id'])); $tmp['##validation.status##'] = TicketValidation::getStatus($validation['status']); $tmp['##validation.storestatus##'] = $validation['status']; $tmp['##validation.submissiondate##'] = convDateTime($validation['submission_date']); $tmp['##validation.commentsubmission##'] = $validation['comment_submission']; $tmp['##validation.validationdate##'] = convDateTime($validation['validation_date']); $tmp['##validation.validator##'] = html_clean(getUserName($validation['users_id_validate'])); $tmp['##validation.commentvalidation##'] = $validation['comment_validation']; $this->datas['validations'][] = $tmp; } // Ticket Satisfaction $inquest = new TicketSatisfaction(); if ($inquest->getFromDB($this->obj->getField('id'))) { // internal inquest if ($inquest->fields['type'] == 1) { $this->datas['##ticket.urlsatisfaction##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $this->obj->getField("id") . "_10"); // external inquest } else { if ($inquest->fields['type'] == 2) { $this->datas['##ticket.urlsatisfaction##'] = EntityData::generateLinkSatisfaction($this->obj); } } $this->datas['##satisfaction.type##'] = $inquest->getTypeInquestName($inquest->getfield('type')); $this->datas['##satisfaction.datebegin##'] = convDateTime($inquest->fields['date_begin']); $this->datas['##satisfaction.dateanswered##'] = convDateTime($inquest->fields['date_answered']); $this->datas['##satisfaction.satisfaction##'] = $inquest->fields['satisfaction']; $this->datas['##satisfaction.description##'] = $inquest->fields['comment']; } else { $this->datas['##satisfaction.type##'] = ''; $this->datas['##satisfaction.datebegin##'] = ''; $this->datas['##satisfaction.dateanswered##'] = ''; $this->datas['##satisfaction.satisfaction##'] = ''; $this->datas['##satisfaction.description##'] = ''; } // Use list_limit_max or load the full history ? foreach (Log::getHistoryData($this->obj, 0, $CFG_GLPI['list_limit_max']) as $data) { $tmp = array(); $tmp['##ticket.log.date##'] = $data['date_mod']; $tmp['##ticket.log.user##'] = $data['user_name']; $tmp['##ticket.log.field##'] = $data['field']; $tmp['##ticket.log.content##'] = $data['change']; $this->datas['log'][] = $tmp; } if (isset($this->datas['log'])) { $this->datas['##ticket.numberoflogs##'] = count($this->datas['log']); } else { $this->datas['##ticket.numberoflogs##'] = 0; } } else { if (isset($options['entities_id']) && isset($options['tickets'])) { $this->datas['##ticket.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']); $this->datas['##ticket.action##'] = $LANG['crontask'][15]; $t = new Ticket(); foreach ($options['tickets'] as $ticket) { $tmp = array(); $t->getFromDB($ticket['id']); $tmp['##ticket.id##'] = sprintf("%07d", $ticket['id']); $tmp['##ticket.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=ticket_" . $ticket['id']); $tmp['##ticket.title##'] = $ticket['name']; $tmp['##ticket.status##'] = Ticket::getStatus($ticket['status']); $tmp['##ticket.globalvalidation##'] = TicketValidation::getStatus($ticket['global_validation']); $tmp['##ticket.requesttype##'] = Dropdown::getDropdownName('glpi_requesttypes', $ticket['requesttypes_id']); $tmp['##ticket.urgency##'] = Ticket::getUrgencyName($ticket['urgency']); $tmp['##ticket.impact##'] = Ticket::getImpactName($ticket['impact']); $tmp['##ticket.priority##'] = Ticket::getPriorityName($ticket['priority']); $tmp['##ticket.time##'] = Ticket::getActionTime($ticket['actiontime']); $tmp['##ticket.costtime##'] = $ticket['cost_time']; $tmp['##ticket.creationdate##'] = convDateTime($ticket['date']); $tmp['##ticket.content##'] = $ticket['content']; if ($t->getField('ticketsolutiontypes_id')) { $tmp['##ticket.solution.type##'] = Dropdown::getDropdownName('glpi_ticketsolutiontypes', $t->getField('ticketsolutiontypes_id')); } else { $this->datas['##ticket.solution.type##'] = ''; } $tmp['##ticket.solution.description##'] = unclean_cross_side_scripting_deep($t->getField('solution')); if ($t->countUsers(Ticket::REQUESTER)) { $users = array(); foreach ($t->getUsers(Ticket::REQUESTER) as $uid => $val) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); $tmp2 = array(); $tmp2['##author.id##'] = $uid; $tmp2['##author.name##'] = $user_tmp->getName(); if ($user_tmp->getField('locations_id')) { $tmp2['##author.location##'] = Dropdown::getDropdownName('glpi_locations', $user_tmp->getField('locations_id')); } else { $tmp2['##author.location##'] = ''; } $tmp2['##author.phone##'] = $user_tmp->getField('phone'); $tmp2['##author.phone2##'] = $user_tmp->getField('phone2'); $tmp['authors'][] = $tmp2; } $tmp['##ticket.authors##'] = implode(', ', $users); } else { $tmp['##ticket.authors##'] = ''; } if ($t->countUsers(Ticket::ASSIGN)) { $users = array(); foreach ($t->getUsers(Ticket::ASSIGN) as $uid => $val) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); } $tmp['##ticket.assigntousers##'] = implode(', ', $users); } else { $tmp['##ticket.assigntousers##'] = ''; } if ($t->countGroups(Ticket::ASSIGN)) { $groups = array(); foreach ($t->getGroups(Ticket::ASSIGN) as $gid => $val) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $tmp['##ticket.assigntogroups##'] = implode(', ', $groups); } else { $tmp['##ticket.assigntogroups##'] = ''; } if ($t->countGroups(Ticket::REQUESTER)) { $groups = array(); foreach ($t->getGroups(Ticket::REQUESTER) as $gid => $val) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $tmp['##ticket.groups##'] = implode(', ', $groups); } else { $tmp['##ticket.groups##'] = ''; } if ($t->countUsers(Ticket::OBSERVER)) { $users = array(); foreach ($t->getUsers(Ticket::OBSERVER) as $uid => $tmp) { $user_tmp = new User(); $user_tmp->getFromDB($uid); $users[$uid] = $user_tmp->getName(); } $tmp['##ticket.observerusers##'] = implode(', ', $users); } else { $tmp['##ticket.observerusers##'] = ''; } if ($t->countGroups(Ticket::OBSERVER)) { $groups = array(); foreach ($t->getGroups(Ticket::OBSERVER) as $gid => $tmp) { $groups[$gid] = Dropdown::getDropdownName('glpi_groups', $gid); } $tmp['##ticket.observergroups##'] = implode(', ', $groups); } else { $tmp['##ticket.observergroups##'] = ''; } if ($ticket['suppliers_id_assign']) { $tmp['##ticket.assigntosupplier##'] = Dropdown::getDropdownName('glpi_suppliers', $ticket['suppliers_id_assign']); } else { $tmp['##ticket.assigntosupplier##'] = ''; } $this->datas['tickets'][] = $tmp; } } } $this->getTags(); foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { if (!isset($this->datas[$tag])) { $this->datas[$tag] = $values['label']; } } }
public function __construct(EntityMap $EntityMap, array $EntityProperties, array $EntityData = []) { parent::__construct($EntityMap, $EntityProperties, $EntityData); }
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -------------------------------------------------------------------------- */ // ---------------------------------------------------------------------- // Original Author of file: Nelly Mahu-Lasson // Purpose of file: // ---------------------------------------------------------------------- // Direct access to file if (strpos($_SERVER['PHP_SELF'], "ticketsatisfaction.php")) { $AJAX_INCLUDE = 1; define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); header_nocache(); } $entity = new EntityData(); if (isset($_REQUEST['inquest_config']) && isset($_REQUEST['entities_id'])) { if ($entity->getFromDB($_REQUEST['entities_id'])) { $inquest_config = $entity->getfield('inquest_config'); $inquest_delay = $entity->getfield('inquest_delay'); $inquest_rate = $entity->getfield('inquest_rate'); $max_closedate = $entity->getfield('max_closedate'); } else { $inquest_config = $_REQUEST['inquest_config']; $inquest_delay = -1; $inquest_rate = -1; $max_closedate = ''; } if ($_REQUEST['inquest_config'] > 0) { echo "<table class='tab_cadre_fixe' width='50%'>"; echo "<tr class='tab_bg_1'><td width='50%'>" . $LANG['entity'][20] . " : </td>";
public function __construct(EntityMap $EntityMap, array $IdentityData = []) { parent::__construct($EntityMap, $EntityMap->GetIdentityProperties(), $IdentityData); }
/** * Make a select box with all glpi users where select key = name * * Parameters which could be used in options array : * - name : string / name of the select (default is users_id) * - right : string / limit user who have specific right : * id -> only current user (default case); * interface -> central ; * all -> all users ; * specific right like show_all_ticket, create_ticket.... * - comments : boolean / is the comments displayed near the dropdown (default true) * - entity : integer or array / restrict to a defined entity or array of entities * (default -1 : no restriction) * - entity_sons : boolean / if entity restrict specified auto select its sons * only available if entity is a single value not an array(default false) * - all : Nobody or All display for none selected * all=0 (default) -> Nobody * all=1 -> All * all=-1-> nothing * - rand : integer / already computed rand value * - toupdate : array / Update a specific item on select change on dropdown * (need value_fieldname, to_update, url (see ajaxUpdateItemOnSelectEvent for informations) * and may have moreparams) * - used : array / Already used items ID: not to display in dropdown (default empty) * - auto_submit : boolean / autosubmit on change (default false) * * @param $options possible options * * @return nothing (print out an HTML select box) **/ static function dropdown($options = array()) { global $DB, $CFG_GLPI, $LANG; // Defautl values $p['name'] = 'users_id'; $p['value'] = ''; $p['right'] = 'id'; $p['all'] = 0; $p['auto_submit'] = false; $p['comments'] = 1; $p['entity'] = -1; $p['entity_sons'] = false; $p['used'] = array(); $p['ldap_import'] = false; $p['toupdate'] = ''; $p['rand'] = mt_rand(); if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } if (!($p['entity'] < 0) && $p['entity_sons']) { if (is_array($p['entity'])) { echo "entity_sons options is not available with array of entity"; } else { $p['entity'] = getSonsOf('glpi_entities', $p['entity']); } } // Make a select box with all glpi users $use_ajax = false; if ($CFG_GLPI["use_ajax"]) { $res = self::getSqlSearchResult(true, $p['right'], $p['entity'], $p['value'], $p['used']); $nb = $res ? $DB->result($res, 0, "cpt") : 0; if ($nb > $CFG_GLPI["ajax_limit_count"]) { $use_ajax = true; } } $user = getUserName($p['value'], 2); $default_display = "<select id='dropdown_" . $p['name'] . $p['rand'] . "' name='" . $p['name'] . "'>"; $default_display .= "<option value='" . $p['value'] . "'>"; $default_display .= utf8_substr($user["name"], 0, $_SESSION["glpidropdown_chars_limit"]); $default_display .= "</option></select>"; $view_users = haveRight("user", "r"); $params = array('searchText' => '__VALUE__', 'value' => $p['value'], 'myname' => $p['name'], 'all' => $p['all'], 'right' => $p['right'], 'comment' => $p['comments'], 'rand' => $p['rand'], 'auto_submit' => $p['auto_submit'], 'entity_restrict' => $p['entity'], 'used' => $p['used'], 'update_item' => $p['toupdate']); if ($view_users) { $params['update_link'] = $view_users; } $default = ""; if (!empty($p['value']) && $p['value'] > 0) { $default = $default_display; } else { $default = "<select name='" . $p['name'] . "' id='dropdown_" . $p['name'] . $p['rand'] . "'>"; if ($p['all']) { $default .= "<option value='0'>[ " . $LANG['common'][66] . " ]</option></select>"; } else { $default .= "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option></select>\n"; } } ajaxDropdown($use_ajax, "/ajax/dropdownUsers.php", $params, $default, $p['rand']); // Display comment if ($p['comments']) { if (!$view_users) { $user["link"] = ''; } else { if (empty($user["link"])) { $user["link"] = $CFG_GLPI['root_doc'] . "/front/user.php"; } } showToolTip($user["comment"], array('contentid' => "comment_" . $p['name'] . $p['rand'], 'link' => $user["link"], 'linkid' => "comment_link_" . $p["name"] . $p['rand'])); } if (haveRight('import_externalauth_users', 'w') && $p['ldap_import'] && EntityData::isEntityDirectoryConfigured($_SESSION['glpiactive_entity'])) { echo "<img alt='' title=\"" . $LANG['ldap'][35] . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n onClick=\"var w = window.open('" . $CFG_GLPI['root_doc'] . "/front/popup.php?popup=add_ldapuser&rand=" . $p['rand'] . "&entity=" . $_SESSION['glpiactive_entity'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">"; } return $p['rand']; }
static function manageValuesInSession($options = array(), $delete = false) { $fields = array('action', 'authldaps_id', 'basedn', 'criterias', 'days', 'entities_id', 'interface', 'ldap_filter', 'mode', 'operator'); //If form accessed via popup, do not show expert mode link if (isset($options['popup'])) { //If coming form the helpdesk form : reset all criterias $_SESSION['ldap_import']['popup'] = 1; $_SESSION['ldap_import']['no_expert_mode'] = 1; $_SESSION['ldap_import']['action'] = 'show'; $_SESSION['ldap_import']['interface'] = self::SIMPLE_INTERFACE; $_SESSION['ldap_import']['mode'] = self::ACTION_IMPORT; } if (!$delete) { if (isset($options["rand"])) { $_SESSION["glpipopup"]["rand"] = $options["rand"]; } if (!isset($_SESSION['ldap_import']['entities_id'])) { $options['entities_id'] = $_SESSION['glpiactive_entity']; } if (isset($options['toprocess'])) { $_SESSION['ldap_import']['action'] = 'process'; } if (isset($options['change_directory'])) { $options['ldap_filter'] = ''; } if (!isset($_SESSION['ldap_import']['authldaps_id'])) { $_SESSION['ldap_import']['authldaps_id'] = NOT_AVAILABLE; } if (!haveRight('config', 'w') && !haveRight('entity', 'w') || !isset($_SESSION['ldap_import']['interface']) && !isset($options['interface'])) { $options['interface'] = self::SIMPLE_INTERFACE; } foreach ($fields as $field) { if (isset($options[$field])) { $_SESSION['ldap_import'][$field] = $options[$field]; } } if (!isset($_SESSION['ldap_import']['criterias'])) { $_SESSION['ldap_import']['criterias'] = array(); } $authldap = new self(); //Filter computation if ($_SESSION['ldap_import']['interface'] == self::SIMPLE_INTERFACE) { $entitydata = new EntityData(); if ($entitydata->getFromDB($_SESSION['ldap_import']['entities_id']) && $entitydata->getField('authldaps_id') > 0) { $authldap->getFromDB($_SESSION['ldap_import']['authldaps_id']); $_SESSION['ldap_import']['authldaps_id'] = $entitydata->getField('authldaps_id'); $_SESSION['ldap_import']['basedn'] = $entitydata->getField('ldap_dn'); // No dn specified in entity : use standard one if (empty($_SESSION['ldap_import']['basedn'])) { $_SESSION['ldap_import']['basedn'] = $authldap->getField('basedn'); } if ($entitydata->getField('entity_ldapfilter') != NOT_AVAILABLE) { $_SESSION['ldap_import']['entity_filter'] = $entitydata->getField('entity_ldapfilter'); } } else { $_SESSION['ldap_import']['authldaps_id'] = self::getDefault(); if ($_SESSION['ldap_import']['authldaps_id'] > 0) { $authldap->getFromDB($_SESSION['ldap_import']['authldaps_id']); $_SESSION['ldap_import']['basedn'] = $authldap->getField('basedn'); } } if ($_SESSION['ldap_import']['authldaps_id'] > 0) { $_SESSION['ldap_import']['ldap_filter'] = self::buildLdapFilter($authldap); } } else { if ($_SESSION['ldap_import']['authldaps_id'] == NOT_AVAILABLE || !$_SESSION['ldap_import']['authldaps_id']) { $_SESSION['ldap_import']['authldaps_id'] = self::getDefault(); if ($_SESSION['ldap_import']['authldaps_id'] > 0) { $authldap->getFromDB($_SESSION['ldap_import']['authldaps_id']); $_SESSION['ldap_import']['basedn'] = $authldap->getField('basedn'); } } if (!isset($_SESSION['ldap_import']['ldap_filter']) || $_SESSION['ldap_import']['ldap_filter'] == '') { $authldap->getFromDB($_SESSION['ldap_import']['authldaps_id']); $_SESSION['ldap_import']['basedn'] = $authldap->getField('basedn'); $_SESSION['ldap_import']['ldap_filter'] = self::buildLdapFilter($authldap); } } //Unset all values in session } else { unset($_SESSION['ldap_import']); } }
/** * Execute the actions as defined in the rule * @param $output the result of the actions * @param $params the parameters * @return the fields modified **/ function executeActions($output, $params) { global $CFG_GLPI; $entity = ''; $right = ''; $is_recursive = 0; $continue = true; $output_src = $output; if (count($this->actions)) { foreach ($this->actions as $action) { switch ($action->fields["action_type"]) { case "assign": switch ($action->fields["field"]) { case "entities_id": $entity = $action->fields["value"]; break; case "profiles_id": $right = $action->fields["value"]; break; case "is_recursive": $is_recursive = $action->fields["value"]; break; case "is_active": $output["is_active"] = $action->fields["value"]; break; case "_ignore_user_import": $continue = false; $output_src["_stop_import"] = true; break; } // switch (field) break; case "regex_result": switch ($action->fields["field"]) { case "_affect_entity_by_dn": case "_affect_entity_by_tag": case "_affect_entity_by_domain": $match_entity = false; $entity = array(); foreach ($this->regex_results as $regex_result) { $res = RuleAction::getRegexResultById($action->fields["value"], $regex_result); if ($res != null) { switch ($action->fields["field"]) { case "_affect_entity_by_dn": $entity_found = EntityData::getEntityIDByDN($res); break; case "_affect_entity_by_tag": $entity_found = EntityData::getEntityIDByTag($res); break; case "_affect_entity_by_domain": $entity_found = EntityData::getEntityIDByDomain($res); break; default: $entity_found = -1; break; } //If an entity was found if ($entity_found > -1) { array_push($entity, array($entity_found, $is_recursive)); $match_entity = true; } } } if (!$match_entity) { //Not entity assigned : action processing must be stopped for this rule $continue = false; } break; } // switch (field) break; } // switch (action_type) } // foreach (action) } // count (actions) if ($continue) { //Nothing to be returned by the function : //Store in session the entity and/or right if ($entity != '' && $right != '') { $output["_ldap_rules"]["rules_entities_rights"][] = array($entity, $right, $is_recursive); } else { if ($entity != '') { if (!is_array($entity)) { $entities_array = array($entity, $is_recursive); $output["_ldap_rules"]["rules_entities"][] = array($entities_array); //If it comes from a regex with multiple results } else { $output["_ldap_rules"]["rules_entities"][] = $entity; } } else { if ($right != '') { $output["_ldap_rules"]["rules_rights"][] = $right; } } } return $output; } return $output_src; }
/** * Cron for ticketsatisfaction's automatic generated * * @param $task : crontask object * * @return integer (0 : nothing done - 1 : done) **/ static function cronCreateInquest($task) { global $DB; $conf = new Entitydata(); $inquest = new TicketSatisfaction(); $tot = 0; $maxentity = array(); $tabentities = array(); $rate = EntityData::getUsedConfig('inquest_config', 0, 'inquest_rate'); if ($rate > 0) { $tabentities[0] = $rate; } foreach ($DB->request('glpi_entities') as $entity) { $rate = EntityData::getUsedConfig('inquest_config', $entity['id'], 'inquest_rate'); $parent = EntityData::getUsedConfig('inquest_config', $entity['id'], 'entities_id'); if ($rate > 0) { $tabentities[$entity['id']] = $rate; } } foreach ($tabentities as $entity => $rate) { $parent = EntityData::getUsedConfig('inquest_config', $entity, 'entities_id'); $delay = EntityData::getUsedConfig('inquest_config', $entity, 'inquest_delay'); $type = EntityData::getUsedConfig('inquest_config', $entity); $max_closedate = EntityData::getUsedConfig('inquest_config', $entity, 'max_closedate'); $query = "SELECT `glpi_tickets`.`id`,\n `glpi_tickets`.`closedate`,\n `glpi_tickets`.`entities_id`\n FROM `glpi_tickets`\n LEFT JOIN `glpi_ticketsatisfactions`\n ON `glpi_ticketsatisfactions`.`tickets_id` = `glpi_tickets`.`id`\n WHERE `glpi_tickets`.`entities_id` = '{$entity}'\n AND `glpi_tickets`.`status` = 'closed'\n AND `glpi_tickets`.`closedate` > '{$max_closedate}'\n AND ADDDATE(`glpi_tickets`.`closedate`, INTERVAL {$delay} DAY)<=NOW()\n AND `glpi_ticketsatisfactions`.`id` IS NULL\n ORDER BY `closedate` ASC"; $nb = 0; $max_closedate = ''; foreach ($DB->request($query) as $tick) { $max_closedate = $tick['closedate']; if (mt_rand(1, 100) <= $rate) { if ($inquest->add(array('tickets_id' => $tick['id'], 'date_begin' => $_SESSION["glpi_currenttime"], 'entities_id' => $tick['entities_id'], 'type' => $type))) { $nb++; } } } // conservation de toutes les max_closedate des entites filles if (!empty($max_closedate) && (!isset($maxentity[$parent]) || $max_closedate > $maxentity[$parent])) { $maxentity[$parent] = $max_closedate; } if ($nb) { $tot += $nb; $task->addVolume($nb); $task->log(Dropdown::getDropdownName('glpi_entities', $entity) . " : {$nb}"); } } // Sauvegarde du max_closedate pour ne pas tester les même tickets 2 fois foreach ($maxentity as $parent => $maxdate) { $conf->getFromDB($parent); $conf->update(array('id' => $conf->fields['id'], 'entities_id' => $parent, 'max_closedate' => $maxdate)); } return $tot > 0; }
function prepareInputDataForProcess($input, $params) { $input['mailcollector'] = $params['mailcollector']; $input['_users_id_requester'] = $params['_users_id_requester']; $fields = $this->getFieldsToLookFor(); //Add needed ticket datas for rules processing if (isset($params['ticket']) && is_array($params['ticket'])) { foreach ($params['ticket'] as $key => $value) { if (in_array($key, $fields) && !isset($input[$key])) { $input[$key] = $value; } } } //Add needed headers for rules processing if (isset($params['headers']) && is_array($params['headers'])) { foreach ($params['headers'] as $key => $value) { if (in_array($key, $fields) && !isset($input[$key])) { $input[$key] = $value; } } } //Add all user's groups if (in_array('groups', $fields)) { foreach (Group_User::getUserGroups($input['_users_id_requester']) as $group) { $input['GROUPS'][] = $group['id']; } } //Add all user's profiles if (in_array('profiles', $fields)) { foreach (Profile_User::getForUser($input['_users_id_requester']) as $profile) { $input['PROFILES'][$profile['profiles_id']] = $profile['profiles_id']; } } //If the criteria is "user has only one time the profile xxx" if (in_array('unique_profile', $fields)) { //Get all profiles $profiles = Profile_User::getForUser($input['_users_id_requester']); foreach ($profiles as $profile) { if (Profile_User::haveUniqueRight($input['_users_id_requester'], $profile['profiles_id'])) { $input['UNIQUE_PROFILE'][$profile['profiles_id']] = $profile['profiles_id']; } } } //Store the number of profiles of which the user belongs to if (in_array('one_profile', $fields)) { $profiles = Profile_User::getForUser($input['_users_id_requester']); if (count($profiles) == 1) { $tmp = array_pop($profiles); $input['ONE_PROFILE'] = $tmp['profiles_id']; } } //Store the number of profiles of which the user belongs to if (in_array('known_domain', $fields)) { if (preg_match("/@(.*)/", $input['from'], $results)) { if (EntityData::getEntityIDByDomain($results[1]) != -1) { $input['KNOWN_DOMAIN'] = 1; } else { $input['KNOWN_DOMAIN'] = 0; } } } return $input; }