Esempio n. 1
0
 function prepareInputForAdd($input)
 {
     global $CFG_GLPI, $LANG;
     // Check mandatory
     $mandatory_ok = true;
     // Do not check mandatory on auto import (mailgates)
     if (!isset($input['_auto_import'])) {
         $_SESSION["helpdeskSaved"] = $input;
         if (!isset($input["urgency"])) {
             addMessageAfterRedirect($LANG['tracking'][4], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_content_mandatory"] && (!isset($input['content']) || empty($input['content']))) {
             addMessageAfterRedirect($LANG['tracking'][8], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_title_mandatory"] && (!isset($input['name']) || empty($input['name']))) {
             addMessageAfterRedirect($LANG['help'][40], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_category_mandatory"] && (!isset($input['ticketcategories_id']) || empty($input['ticketcategories_id']))) {
             addMessageAfterRedirect($LANG['help'][41], false, ERROR);
             $mandatory_ok = false;
         }
         //          if (isset($input['use_email_notification']) && $input['use_email_notification']
         //              && (!isset($input['user_email']) || empty($input['user_email']))) {
         //
         //             addMessageAfterRedirect($LANG['help'][16], false, ERROR);
         //             $mandatory_ok = false;
         //          }
         if (!$mandatory_ok) {
             return false;
         }
     }
     if (!isset($input["urgency"]) || !($CFG_GLPI['urgency_mask'] & 1 << $input["urgency"])) {
         $input["urgency"] = 3;
     }
     if (!isset($input["impact"]) || !($CFG_GLPI['impact_mask'] & 1 << $input["impact"])) {
         $input["impact"] = 3;
     }
     if (!isset($input["priority"])) {
         $input["priority"] = $this->computePriority($input["urgency"], $input["impact"]);
     }
     unset($_SESSION["helpdeskSaved"]);
     // No Auto set Import for external source
     if (!isset($input['_auto_import'])) {
         if (!isset($input["_users_id_requester"])) {
             if ($uid = getLoginUserID()) {
                 $input["_users_id_requester"] = $uid;
             }
         }
     }
     // set last updater
     if ($lastupdater = getLoginUserID(true)) {
         $input['users_id_lastupdater'] = $lastupdater;
     }
     // No Auto set Import for external source
     if (($uid = getLoginUserID()) && !isset($input['_auto_import'])) {
         $input["users_id_recipient"] = $uid;
     } else {
         if (isset($input["_users_id_requester"]) && $input["_users_id_requester"]) {
             $input["users_id_recipient"] = $input["_users_id_requester"];
         }
     }
     if (!isset($input["requesttypes_id"])) {
         $input["requesttypes_id"] = RequestType::getDefault('helpdesk');
     }
     if (!isset($input["status"])) {
         $input["status"] = "new";
     }
     if (!isset($input['global_validation'])) {
         $input['global_validation'] = 'none';
     }
     if (!isset($input["date"]) || empty($input["date"])) {
         $input["date"] = $_SESSION["glpi_currenttime"];
     }
     if (!isset($input["_users_id_assign"])) {
         $input["_users_id_assign"] = 0;
     }
     if (!isset($input["_groups_id_assign"])) {
         $input["_groups_id_assign"] = 0;
     }
     // Set default dropdown
     $dropdown_fields = array('entities_id', 'items_id', 'suppliers_id_assign', 'ticketcategories_id');
     foreach ($dropdown_fields as $field) {
         if (!isset($input[$field])) {
             $input[$field] = 0;
         }
     }
     if (!isset($input['itemtype']) || !($input['items_id'] > 0)) {
         $input['itemtype'] = '';
     }
     $item = NULL;
     if ($input["items_id"] > 0 && !empty($input["itemtype"])) {
         if (class_exists($input["itemtype"])) {
             $item = new $input["itemtype"]();
             if (!$item->getFromDB($input["items_id"])) {
                 $item = NULL;
             }
         }
     }
     // Auto group define from item
     //       if ($item != NULL) {
     //          if ($item->isField('groups_id')
     //              && (!isset($input["_groups_id_requester"]) || $input["_groups_id_requester"]==0)) {
     //             $input["_groups_id_requester"] = $item->getField('groups_id');
     //          }
     //       }
     // Manage auto assign
     $entitydata = new EntityData();
     $auto_assign_mode = $CFG_GLPI['auto_assign_mode'];
     if ($entitydata->getFromDB($input['entities_id'])) {
         $auto_assign_mode = $entitydata->getField('auto_assign_mode');
         // Set global config value
         if ($auto_assign_mode == -1) {
             $auto_assign_mode = $CFG_GLPI['auto_assign_mode'];
         }
     }
     switch ($auto_assign_mode) {
         case NO_AUTO_ASSIGN:
             break;
         case AUTO_ASSIGN_HARDWARE_CATEGORY:
             // Auto assign tech from item
             if ($input["_users_id_assign"] == 0 && $item != NULL) {
                 if ($item->isField('users_id_tech')) {
                     $input["_users_id_assign"] = $item->getField('users_id_tech');
                     if ($input["_users_id_assign"] > 0) {
                         $input["status"] = "assign";
                     }
                 }
             }
             // Auto assign tech/group from Category
             if ($input['ticketcategories_id'] > 0 && (!$input['_users_id_assign'] || !$input['_groups_id_assign'])) {
                 $cat = new TicketCategory();
                 $cat->getFromDB($input['ticketcategories_id']);
                 if (!$input['_users_id_assign'] && $cat->isField('users_id')) {
                     $input['_users_id_assign'] = $cat->getField('users_id');
                 }
                 if (!$input['_groups_id_assign'] && $cat->isField('groups_id')) {
                     $input['_groups_id_assign'] = $cat->getField('groups_id');
                 }
             }
             break;
         case AUTO_ASSIGN_CATEGORY_HARDWARE:
             // Auto assign tech/group from Category
             if ($input['ticketcategories_id'] > 0 && (!$input['_users_id_assign'] || !$input['_groups_id_assign'])) {
                 $cat = new TicketCategory();
                 $cat->getFromDB($input['ticketcategories_id']);
                 if (!$input['_users_id_assign'] && $cat->isField('users_id')) {
                     $input['_users_id_assign'] = $cat->getField('users_id');
                 }
                 if (!$input['_groups_id_assign'] && $cat->isField('groups_id')) {
                     $input['_groups_id_assign'] = $cat->getField('groups_id');
                 }
             }
             // Auto assign tech from item
             if ($input["_users_id_assign"] == 0 && $item != NULL) {
                 if ($item->isField('users_id_tech')) {
                     $input["_users_id_assign"] = $item->getField('users_id_tech');
                     if ($input["_users_id_assign"] > 0) {
                         $input["status"] = "assign";
                     }
                 }
             }
             break;
     }
     // Process Business Rules
     $rules = new RuleTicketCollection($input['entities_id']);
     // Set unset variables with are needed
     $user = new User();
     if (isset($input["_users_id_requester"]) && $user->getFromDB($input["_users_id_requester"])) {
         $input['users_locations'] = $user->fields['locations_id'];
     }
     $input = $rules->processAllRules($input, $input, array('recursive' => true));
     //       if (isset($input["use_email_notification"])
     //           && $input["use_email_notification"]
     //           && empty($input["user_email"])) {
     //
     //          if ($user->getFromDB($input["users_id"])) {
     //             $input["user_email"] = $user->fields["email"];
     //          }
     //       }
     if ((isset($input["_users_id_assign"]) && $input["_users_id_assign"] > 0 || isset($input["_groups_id_assign"]) && $input["_groups_id_assign"] > 0 || isset($input["suppliers_id_assign"]) && $input["suppliers_id_assign"] > 0) && $input["status"] == "new") {
         $input["status"] = "assign";
     }
     if (isset($input["hour"]) && isset($input["minute"])) {
         $input["actiontime"] = $input["hour"] * HOUR_TIMESTAMP + $input["minute"] * MINUTE_TIMESTAMP;
         $input["_hour"] = $input["hour"];
         $input["_minute"] = $input["minute"];
         unset($input["hour"]);
         unset($input["minute"]);
     }
     if (isset($input["status"]) && $input["status"] == "solved") {
         if (isset($input["date"])) {
             $input["solvedate"] = $input["date"];
         } else {
             $input["solvedate"] = $_SESSION["glpi_currenttime"];
         }
     }
     if (isset($input["status"]) && $input["status"] == "closed") {
         if (isset($input["date"])) {
             $input["closedate"] = $input["date"];
         } else {
             $input["closedate"] = $_SESSION["glpi_currenttime"];
         }
         $input['solvedate'] = $input["closedate"];
     }
     // Set begin waiting time if status is waiting
     if (isset($input["status"]) && $input["status"] == "waiting") {
         $input['begin_waiting_date'] = $input['date'];
     }
     // No name set name
     if (empty($input["name"])) {
         $input["name"] = preg_replace('/\\r\\n/', ' ', $input['content']);
         $input["name"] = preg_replace('/\\n/', ' ', $input['name']);
         $input["name"] = utf8_substr($input['name'], 0, 70);
     }
     //// Manage SLA assignment
     // due date defined : no SLA
     if (isset($input["due_date"]) && $input['due_date'] != 'NULL') {
         // Valid due date
         if ($input['due_date'] > $input['date']) {
             if (isset($input["slas_id"])) {
                 unset($input["slas_id"]);
             }
         } else {
             // Unset due date
             unset($input["due_date"]);
         }
     }
     if (isset($input["slas_id"]) && $input["slas_id"] > 0) {
         $sla = new SLA();
         if ($sla->getFromDB($input["slas_id"])) {
             // Get first SLA Level
             $input["slalevels_id"] = SlaLevel::getFirstSlaLevel($input["slas_id"]);
             // Compute due_date
             $input['due_date'] = $sla->computeDueDate($input['date']);
             $input['sla_waiting_duration'] = 0;
         } else {
             $input["slalevels_id"] = 0;
             $input["slas_id"] = 0;
             $input['sla_waiting_duration'] = 0;
         }
     }
     // auto set type if not set
     if (!isset($input["type"])) {
         $input['type'] = EntityData::getUsedConfig('tickettype', $input['entities_id']);
     }
     return $input;
 }
Esempio n. 2
0
 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']);
     }
 }
 /**
  * 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;
 }
Esempio n. 4
0
 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;
 }
 /**
  * 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'];
         }
     }
 }
*/
// ----------------------------------------------------------------------
// 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] . "&nbsp;:&nbsp;</td>";
        echo "<td>";
        Dropdown::showInteger('inquest_delay', $inquest_delay, 0, 90, 1);