strtolower() static public method

strtolower function for utf8 string
static public strtolower ( $str ) : lower
$str string
return lower case string
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI;
     if ($event == 'AlertNotValidatedTypology') {
         $this->datas['##typology.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
         $this->datas['##lang.typology.entity##'] = __('Entity');
         $this->datas['##typology.action##'] = __('Elements not match with the typology', 'typology');
         $this->datas['##lang.typology.name##'] = PluginTypologyTypology::getTypeName(1);
         $this->datas['##lang.typology.itemtype##'] = __('Type');
         $this->datas['##lang.typology.items_id##'] = __('Name');
         $this->datas['##lang.typology.error##'] = __('Error');
         $this->datas['##lang.typology.url##'] = __('Link to the typology', 'typology');
         $this->datas['##lang.typology.itemurl##'] = __('Link to the element', 'typology');
         $this->datas['##lang.typology.itemuser##'] = __('User');
         $this->datas['##lang.typology.itemlocation##'] = __('Location');
         foreach ($options['items'] as $id => $item) {
             $tmp = array();
             $tmp['##typology.name##'] = $item['name'];
             $itemtype = new $item['itemtype']();
             $itemtype->getFromDB($item["items_id"]);
             $tmp['##typology.itemtype##'] = $itemtype->getTypeName();
             $tmp['##typology.items_id##'] = $itemtype->getName();
             $tmp['##typology.error##'] = PluginTypologyTypology_Item::displayErrors($item['error'], false);
             $tmp['##typology.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_typology_" . $item['plugin_typology_typologies_id']);
             $tmp['##typology.itemurl##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=" . Toolbox::strtolower($item['itemtype']) . "_" . $item["items_id"]);
             $tmp['##typology.itemuser##'] = getUserName($itemtype->fields["users_id"]);
             $tmp['##typology.itemlocation##'] = Dropdown::getDropdownName("glpi_locations", $itemtype->fields['locations_id']);
             $this->datas['typologyitems'][] = $tmp;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @see CommonDBTM::prepareInputForAdd()
  **/
 function prepareInputForAdd($input)
 {
     //LDAP parameters MUST be in lower case
     //because the are retieved in lower case  from the directory
     $input["value"] = Toolbox::strtolower($input["value"]);
     return $input;
 }
Ejemplo n.º 3
0
 /**
  * Function that try to load from LDAP the user membership
  * by searching in the attribute of the User
  *
  * @param $ldap_connection    ldap connection descriptor
  * @param $ldap_method        LDAP method
  * @param $userdn             Basedn of the user
  * @param $login              User login
  *
  * @return String : basedn of the user / false if not founded
  **/
 private function getFromLDAPGroupVirtual($ldap_connection, $ldap_method, $userdn, $login)
 {
     global $DB;
     // Search in DB the ldap_field we need to search for in LDAP
     $query = "SELECT DISTINCT `ldap_field`\n                FROM `glpi_groups`\n                WHERE `ldap_field` != ''\n                ORDER BY `ldap_field`";
     $group_fields = array();
     foreach ($DB->request($query) as $data) {
         $group_fields[] = Toolbox::strtolower($data["ldap_field"]);
     }
     if (count($group_fields)) {
         //Need to sort the array because edirectory don't like it!
         sort($group_fields);
         // If the groups must be retrieve from the ldap user object
         $sr = @ldap_read($ldap_connection, $userdn, "objectClass=*", $group_fields);
         $v = AuthLDAP::get_entries_clean($ldap_connection, $sr);
         for ($i = 0; $i < count($v['count']); $i++) {
             //Try to find is DN in present and needed: if yes, then extract only the OU from it
             if (($ldap_method["group_field"] == 'dn' || in_array('ou', $group_fields)) && isset($v[$i]['dn'])) {
                 $v[$i]['ou'] = array();
                 for ($tmp = $v[$i]['dn']; count($tmptab = explode(',', $tmp, 2)) == 2; $tmp = $tmptab[1]) {
                     $v[$i]['ou'][] = $tmptab[1];
                 }
                 // Search in DB for group with ldap_group_dn
                 if ($ldap_method["group_field"] == 'dn' && count($v[$i]['ou']) > 0) {
                     $query = "SELECT `id`\n                            FROM `glpi_groups`\n                            WHERE `ldap_group_dn`\n                                       IN ('" . implode("', '", Toolbox::addslashes_deep($v[$i]['ou'])) . "')";
                     foreach ($DB->request($query) as $group) {
                         $this->fields["_groups"][] = $group['id'];
                     }
                 }
                 // searching with ldap_field='OU' and ldap_value is also possible
                 $v[$i]['ou']['count'] = count($v[$i]['ou']);
             }
             // For each attribute retrieve from LDAP, search in the DB
             foreach ($group_fields as $field) {
                 if (isset($v[$i][$field]) && isset($v[$i][$field]['count']) && $v[$i][$field]['count'] > 0) {
                     unset($v[$i][$field]['count']);
                     $query = "SELECT `id`\n                            FROM `glpi_groups`\n                            WHERE `ldap_field` = '{$field}'\n                                  AND `ldap_value`\n                                       IN ('" . implode("', '", Toolbox::addslashes_deep($v[$i][$field])) . "')";
                     foreach ($DB->request($query) as $group) {
                         $this->fields["_groups"][] = $group['id'];
                     }
                 }
             }
         }
         // for each ldapresult
     }
     // count($group_fields)
 }
 /**
  * Get all the fields needed to perform the rule
  *
  * @see RuleCollection::getFieldsToLookFor()
  **/
 function getFieldsToLookFor()
 {
     global $DB;
     $params = array();
     $sql = "SELECT DISTINCT `value`\n              FROM `glpi_rules`,\n                   `glpi_rulecriterias`,\n                   `glpi_rulerightparameters`\n              WHERE `glpi_rules`.`sub_type` = 'RuleRight'\n                    AND `glpi_rulecriterias`.`rules_id` = `glpi_rules`.`id`\n                    AND `glpi_rulecriterias`.`criteria` = `glpi_rulerightparameters`.`value`";
     $result = $DB->query($sql);
     while ($param = $DB->fetch_assoc($result)) {
         //Dn is alwsays retreived from ldap : don't need to ask for it !
         if ($param["value"] != "dn") {
             $params[] = Toolbox::strtolower($param["value"]);
         }
     }
     return $params;
 }
Ejemplo n.º 5
0
 /**
  * This function is use full to Get Header info from particular mail
  *
  * @param $mid               = Mail Id of a Mailbox
  *
  * @return Return Associative array with following keys
  * subject   => Subject of Mail
  * to        => To Address of that mail
  * toOth     => Other To address of mail
  * toNameOth => To Name of Mail
  * from      => From address of mail
  * fromName  => Form Name of Mail
  **/
 function getHeaders($mid)
 {
     // Get Header info
     $mail_header = imap_header($this->marubox, $mid);
     $sender = $mail_header->from[0];
     $to = $mail_header->to[0];
     $date = date("Y-m-d H:i:s", strtotime($mail_header->date));
     $mail_details = array();
     if (Toolbox::strtolower($sender->mailbox) != 'mailer-daemon' && Toolbox::strtolower($sender->mailbox) != 'postmaster') {
         // Construct to and cc arrays
         $tos = array();
         $ccs = array();
         if (count($mail_header->to)) {
             foreach ($mail_header->to as $data) {
                 $mailto = Toolbox::strtolower($data->mailbox) . '@' . $data->host;
                 if ($mailto === $this->fields['name']) {
                     $to = $data;
                 }
                 $tos[] = $mailto;
             }
         }
         if (isset($mail_header->cc) && count($mail_header->cc)) {
             foreach ($mail_header->cc as $data) {
                 $ccs[] = Toolbox::strtolower($data->mailbox) . '@' . $data->host;
             }
         }
         // secu on subject setting
         if (!isset($mail_header->subject)) {
             $mail_header->subject = '';
         }
         $mail_details = array('from' => Toolbox::strtolower($sender->mailbox) . '@' . $sender->host, 'subject' => $mail_header->subject, 'to' => Toolbox::strtolower($to->mailbox) . '@' . $to->host, 'message_id' => $mail_header->message_id, 'tos' => $tos, 'ccs' => $ccs, 'date' => $date);
         if (isset($mail_header->references)) {
             $mail_details['references'] = $mail_header->references;
         }
         if (isset($mail_header->in_reply_to)) {
             $mail_details['in_reply_to'] = $mail_header->in_reply_to;
         }
         //Add additional headers in X-
         foreach ($this->getAdditionnalHeaders($mid) as $header => $value) {
             $mail_details[$header] = $value;
         }
     }
     return $mail_details;
 }
Ejemplo n.º 6
0
 function prepareInputForUpdate($input)
 {
     if (isset($input["rootdn_passwd"])) {
         if (empty($input["rootdn_passwd"])) {
             unset($input["rootdn_passwd"]);
         } else {
             $input["rootdn_passwd"] = Toolbox::encrypt(stripslashes($input["rootdn_passwd"]), GLPIKEY);
         }
     }
     if (isset($input["_blank_passwd"]) && $input["_blank_passwd"]) {
         $input['rootdn_passwd'] = '';
     }
     // Set attributes in lower case
     if (count($input)) {
         foreach ($input as $key => $val) {
             if (preg_match('/_field$/', $key)) {
                 $input[$key] = Toolbox::strtolower($val);
             }
         }
     }
     return $input;
 }
Ejemplo n.º 7
0
 /**
  * Try to match a definied rule
  *
  * @param &$criterion         RuleCriteria object
  * @param $field              the field to match
  * @param &$criterias_results
  * @param &$regex_result
  *
  * @return true if the field match the rule, false if it doesn't match
  **/
 static function match(RuleCriteria &$criterion, $field, &$criterias_results, &$regex_result)
 {
     $condition = $criterion->fields['condition'];
     $pattern = $criterion->fields['pattern'];
     $criteria = $criterion->fields['criteria'];
     //If pattern is wildcard, don't check the rule and return true
     //or if the condition is "already present in GLPI" : will be processed later
     if ($pattern == Rule::RULE_WILDCARD || $condition == Rule::PATTERN_FIND) {
         return true;
     }
     $pattern = trim($pattern);
     switch ($condition) {
         case Rule::PATTERN_EXISTS:
             return !empty($field);
         case Rule::PATTERN_DOES_NOT_EXISTS:
             return empty($field);
         case Rule::PATTERN_IS:
             if (is_array($field)) {
                 // Special case (used only by UNIQUE_PROFILE, for now)
                 // $pattern is an ID
                 if (in_array($pattern, $field)) {
                     $criterias_results[$criteria] = $pattern;
                     return true;
                 }
             } else {
                 //Perform comparison with fields in lower case
                 $field = Toolbox::strtolower($field);
                 $pattern = Toolbox::strtolower($pattern);
                 if ($field == $pattern) {
                     $criterias_results[$criteria] = $pattern;
                     return true;
                 }
             }
             return false;
         case Rule::PATTERN_IS_NOT:
             //Perform comparison with fields in lower case
             $field = Toolbox::strtolower($field);
             $pattern = Toolbox::strtolower($pattern);
             if ($field != $pattern) {
                 $criterias_results[$criteria] = $pattern;
                 return true;
             }
             return false;
         case Rule::PATTERN_UNDER:
             $table = getTableNameForForeignKeyField($criteria);
             $values = getSonsOf($table, $pattern);
             if (isset($values[$field])) {
                 return true;
             }
             return false;
         case Rule::PATTERN_NOT_UNDER:
             $table = getTableNameForForeignKeyField($criteria);
             $values = getSonsOf($table, $pattern);
             if (isset($values[$field])) {
                 return false;
             }
             return true;
         case Rule::PATTERN_END:
             $value = "/" . $pattern . "\$/i";
             if (preg_match($value, $field) > 0) {
                 $criterias_results[$criteria] = $pattern;
                 return true;
             }
             return false;
         case Rule::PATTERN_BEGIN:
             if (empty($pattern)) {
                 return false;
             }
             $value = mb_stripos($field, $pattern, 0, 'UTF-8');
             if ($value !== false && $value == 0) {
                 $criterias_results[$criteria] = $pattern;
                 return true;
             }
             return false;
         case Rule::PATTERN_CONTAIN:
             if (empty($pattern)) {
                 return false;
             }
             $value = mb_stripos($field, $pattern, 0, 'UTF-8');
             if ($value !== false && $value >= 0) {
                 $criterias_results[$criteria] = $pattern;
                 return true;
             }
             return false;
         case Rule::PATTERN_NOT_CONTAIN:
             if (empty($pattern)) {
                 return false;
             }
             $value = mb_stripos($field, $pattern, 0, 'UTF-8');
             if ($value === false) {
                 $criterias_results[$criteria] = $pattern;
                 return true;
             }
             return false;
         case Rule::REGEX_MATCH:
             $results = array();
             // Permit use < and >
             $pattern = Toolbox::unclean_cross_side_scripting_deep($pattern);
             if (preg_match_all($pattern . "i", $field, $results) > 0) {
                 // Drop $result[0] : complete match result
                 array_shift($results);
                 // And add to $regex_result array
                 $regex_result[] = $results[1];
                 $criterias_results[$criteria] = $pattern;
                 return true;
             }
             return false;
         case Rule::REGEX_NOT_MATCH:
             // Permit use < and >
             $pattern = Toolbox::unclean_cross_side_scripting_deep($pattern);
             if (preg_match($pattern . "i", $field) == 0) {
                 $criterias_results[$criteria] = $pattern;
                 return true;
             }
             return false;
         case Rule::PATTERN_FIND:
         case Rule::PATTERN_IS_EMPTY:
             // Global criteria will be evaluated later
             return true;
     }
     return false;
 }
 /**
  * Fonction permettant d'afficher les materiels disponibles et de faire une nouvelle reservation
  * C'est juste une interface differente de celle de GLPI. Pour les nouvelles reservations, on utilise les fonctions du coeur de GLPI
  **/
 function showDispoAndFormResa()
 {
     global $DB, $CFG_GLPI, $datesresa;
     $showentity = Session::isMultiEntitiesMode();
     $begin = $datesresa["begin"];
     $end = $datesresa["end"];
     $left = "";
     $where = "";
     echo "<div class='center'>";
     echo "<form name='form' method='GET' action='../../../front/reservation.form.php'>";
     echo "<table class='tab_cadre' style=\"border-spacing:20px;\">";
     echo "<tr>";
     foreach ($CFG_GLPI["reservation_types"] as $itemtype) {
         if (!($item = getItemForItemtype($itemtype))) {
             continue;
         }
         $itemtable = getTableForItemType($itemtype);
         $otherserial = "'' AS otherserial";
         if ($item->isField('otherserial')) {
             $otherserial = "`{$itemtable}`.`otherserial`";
         }
         if (isset($begin) && isset($end)) {
             $left = "LEFT JOIN `glpi_reservations`\n\t  ON (`glpi_reservationitems`.`id` = `glpi_reservations`.`reservationitems_id`\n\t      AND '" . $begin . "' < `glpi_reservations`.`end`\n\t      AND '" . $end . "' > `glpi_reservations`.`begin`)";
             $where = " AND `glpi_reservations`.`id` IS NULL ";
         }
         $query = "SELECT `glpi_reservationitems`.`id`,\n\t`glpi_reservationitems`.`comment`,\n\t`{$itemtable}`.`id` AS materielid,\n\t`{$itemtable}`.`name` AS name,\n\t`{$itemtable}`.`entities_id` AS entities_id,\n\t{$otherserial},\n\t`glpi_locations`.`completename` AS location,\n\t`glpi_reservationitems`.`items_id` AS items_id\n\t  FROM `glpi_reservationitems`\n\t  {$left}\n\t  INNER JOIN `{$itemtable}`\n\t  ON (`glpi_reservationitems`.`itemtype` = '{$itemtype}'\n\t      AND `glpi_reservationitems`.`items_id` = `{$itemtable}`.`id`)\n\t  LEFT JOIN `glpi_locations`\n\t  ON (`{$itemtable}`.`locations_id` = `glpi_locations`.`id`)\n\t  WHERE `glpi_reservationitems`.`is_active` = '1'\n\t  AND `glpi_reservationitems`.`is_deleted` = '0'\n\t  AND `{$itemtable}`.`is_deleted` = '0'\n\t  {$where} " . getEntitiesRestrictRequest(" AND", $itemtable, '', $_SESSION['glpiactiveentities'], $item->maybeRecursive()) . "\n\t  ORDER BY `{$itemtable}`.`entities_id`,\n\t`{$itemtable}`.`name`";
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result)) {
                 echo "<td>";
                 echo "<table class='tab_cadre'>";
                 echo "<tr><th colspan='" . ($showentity ? "6" : "5") . "'>" . $item->getTypeName() . "</th></tr>\n";
             }
             while ($row = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2'><td>";
                 echo "<input type='checkbox' name='item[" . $row["id"] . "]' value='" . $row["id"] . "'>" . "</td>";
                 $typename = $item->getTypeName();
                 if ($itemtype == 'Peripheral') {
                     $item->getFromDB($row['items_id']);
                     if (isset($item->fields["peripheraltypes_id"]) && $item->fields["peripheraltypes_id"] != 0) {
                         $typename = Dropdown::getDropdownName("glpi_peripheraltypes", $item->fields["peripheraltypes_id"]);
                     }
                 }
                 echo "<td white-space: nowrap ><a href='" . getGLPIUrl() . "front/" . Toolbox::strtolower($itemtype) . ".form.php?id=" . $row['materielid'] . "&forcetab=Reservation\$1" . "'>" . sprintf(__('%1$s'), $row["name"]) . "</a></td>";
                 echo "<td>" . nl2br($row["comment"]) . "</td>";
                 if ($showentity) {
                     echo "<td>" . Dropdown::getDropdownName("glpi_entities", $row["entities_id"]) . "</td>";
                 }
                 echo "<td><a title=\"Voir le planning\" href='../../../front/reservation.php?reservationitems_id=" . $row['id'] . "'>" . "<img title=\"\" alt=\"\" src=\"" . getGLPIUrl() . "pics/reservation-3.png\"></img></a></td>";
                 echo "</tr>\n";
             }
         }
         if ($DB->numrows($result)) {
             echo "</td>";
             echo "</table>\n";
         }
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1 center'><td colspan='" . ($showentity ? "5" : "4") . "'>";
     echo "<input type='submit' value=\"Réserver\" class='submit'></td></tr>\n";
     echo "</table>\n";
     echo "<input type='hidden' name='id' value=''>";
     Html::closeForm();
     echo "</div>\n";
 }
Ejemplo n.º 9
0
 /**
  * Add new mail with lang to current email array
  *
  * @param $data   array of data (mail, lang[, id for user])
  **/
 function addToAddressesList(array $data)
 {
     global $CFG_GLPI;
     // No email set : get default for user
     if (!isset($data['email']) && isset($data['users_id'])) {
         $data['email'] = UserEmail::getDefaultForUser($data['users_id']);
     }
     $new_mail = trim(Toolbox::strtolower($data['email']));
     $new_lang = '';
     // Default USER TYPE is ANONYMOUS
     $notificationoption = array('usertype' => self::ANONYMOUS_USER);
     if (isset($data['language'])) {
         $new_lang = trim($data['language']);
     }
     $username = '';
     if (isset($data['name']) && !empty($data['name'])) {
         $username = $data['name'];
     }
     if (isset($data['users_id']) && $data['users_id'] > 0) {
         $user = new User();
         if (!$user->getFromDB($data['users_id']) || $user->getField('is_deleted') == 1 || $user->getField('is_active') == 0 || !is_null($user->getField('begin_date')) && $user->getField('begin_date') > $_SESSION["glpi_currenttime"] || !is_null($user->getField('end_date')) && $user->getField('end_date') < $_SESSION["glpi_currenttime"]) {
             // unknown, deleted or disabled user
             return false;
         }
         $filt = getEntitiesRestrictRequest('AND', 'glpi_profiles_users', '', $this->getEntity(), true);
         $prof = Profile_User::getUserProfiles($data['users_id'], $filt);
         if (!count($prof)) {
             // No right on the entity of the object
             return false;
         }
         if (empty($username)) {
             $username = formatUserName(0, $user->getField('name'), $user->getField('realname'), $user->getField('firstname'), 0, 0, true);
         }
         // It is a GLPI user :
         $notificationoption['usertype'] = self::GLPI_USER;
         if (Auth::isAlternateAuth($user->fields['authtype']) || $user->fields['authtype'] == Auth::NOT_YET_AUTHENTIFIED && Auth::isAlternateAuth(Auth::checkAlternateAuthSystems())) {
             $notificationoption['usertype'] = self::EXTERNAL_USER;
         }
     }
     // Pass user type as argument ? forced for specific cases
     if (isset($data['usertype'])) {
         $notificationoption['usertype'] = $data['usertype'];
     }
     $notificationoption = array_merge($this->addAdditionnalUserInfo($data), $notificationoption);
     if (!empty($new_mail)) {
         if (NotificationMail::isUserAddressValid($new_mail) && !isset($this->target[$new_mail])) {
             $param = array('language' => empty($new_lang) ? $CFG_GLPI["language"] : $new_lang, 'email' => $new_mail, 'additionnaloption' => $notificationoption, 'username' => $username);
             if (isset($data['users_id']) && $data['users_id']) {
                 $param['users_id'] = $data['users_id'];
             }
             $this->target[$new_mail] = $param;
         }
     }
 }
 /**
  * Get all the fields needed to perform the rule
  **/
 function getFieldsToLookFor()
 {
     global $DB;
     $params = array();
     $query = "SELECT DISTINCT `glpi_rulecriterias`.`criteria` AS `criteria`\n                FROM `glpi_rules`,\n                     `glpi_rulecriterias`\n                WHERE `glpi_rules`.`sub_type` = '" . $this->getRuleClassName() . "'\n                      AND `glpi_rulecriterias`.`rules_id` = `glpi_rules`.`id`\n                      AND `glpi_rules`.`is_active` = '1'";
     foreach ($DB->request($query) as $param) {
         $params[] = Toolbox::strtolower($param["criteria"]);
     }
     return $params;
 }
Ejemplo n.º 11
0
 /**
  * Generic Function to display Items
  *
  * @param $itemtype              item type
  * @param $ID                    ID of the SEARCH_OPTION item
  * @param $data            array containing data results
  * @param $num                   item num in the request
  * @param $meta                  is a meta item ? (default 0)
  * @param $addobjectparams array added parameters for union search
  *
  * @return string to print
  **/
 static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array())
 {
     global $CFG_GLPI;
     $showuserlink = 0;
     if (Session::haveRight('user', READ)) {
         $showuserlink = 1;
     }
     $searchopt =& self::getOptions($itemtype);
     if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) {
         if (isset($searchopt[$ID]['addobjectparams']) && $searchopt[$ID]['addobjectparams']) {
             return self::giveItem($data["TYPE"], $ID, $data, $num, $meta, $searchopt[$ID]['addobjectparams']);
         }
         return self::giveItem($data["TYPE"], $ID, $data, $num, $meta);
     }
     if (count($addobjectparams)) {
         $searchopt[$ID] = array_merge($searchopt[$ID], $addobjectparams);
     }
     // Plugin can override core definition for its type
     if ($plug = isPluginItemType($itemtype)) {
         $function = 'plugin_' . $plug['plugin'] . '_giveItem';
         if (function_exists($function)) {
             $out = $function($itemtype, $ID, $data, $num);
             if (!empty($out)) {
                 return $out;
             }
         }
     }
     $NAME = "ITEM_";
     if ($meta) {
         $NAME = "META_";
     }
     $table = $searchopt[$ID]["table"];
     $field = $searchopt[$ID]["field"];
     $linkfield = $searchopt[$ID]["linkfield"];
     /// TODO try to clean all specific cases using SpecificToDisplay
     switch ($table . '.' . $field) {
         case "glpi_users.name":
             // USER search case
             if ($itemtype != 'User' && isset($searchopt[$ID]["forcegroupby"]) && $searchopt[$ID]["forcegroupby"]) {
                 $out = "";
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $count_display = 0;
                 $added = array();
                 for ($k = 0; $k < count($split); $k++) {
                     if ($split[$k] > 0) {
                         if ($count_display) {
                             $out .= "<br>";
                         }
                         $count_display++;
                         if ($itemtype == 'Ticket') {
                             $userdata = getUserName($split[$k], 2);
                             $tooltip = "";
                             if (Session::haveRight('user', READ)) {
                                 $tooltip = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                             }
                             $out .= sprintf(__('%1$s %2$s'), $userdata['name'], $tooltip);
                         } else {
                             $out .= getUserName($split[$k], $showuserlink);
                         }
                     }
                 }
                 // Manage alternative_email for tickets_users
                 if ($itemtype == 'Ticket' && isset($data[$NAME . $num . '_2'])) {
                     $split = explode("\$\$\$\$", $data[$NAME . $num . '_2']);
                     for ($k = 0; $k < count($split); $k++) {
                         $split2 = explode(" ", $split[$k]);
                         if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>";
                         }
                     }
                 }
                 return $out;
             }
             if ($itemtype != 'User') {
                 $toadd = '';
                 if ($itemtype == 'Ticket' && $data[$NAME . $num . "_3"] > 0) {
                     $userdata = getUserName($data[$NAME . $num . "_3"], 2);
                     $toadd = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                 }
                 if (Session::haveRight('user', READ)) {
                     $usernameformat = formatUserName($data[$NAME . $num . "_3"], $data[$NAME . $num], $data[$NAME . $num . "_2"], $data[$NAME . $num . "_4"], 1);
                 } else {
                     $usernameformat = formatUserName($data[$NAME . $num . "_3"], $data[$NAME . $num], $data[$NAME . $num . "_2"], $data[$NAME . $num . "_4"], 0);
                 }
                 return sprintf(__('%1$s %2$s'), $usernameformat, $toadd);
             }
             break;
         case "glpi_profiles.interface":
             return Profile::getInterfaceName($data[$NAME . $num]);
         case "glpi_profiles.name":
             if ($itemtype == 'User' && $ID == 20) {
                 $out = "";
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]);
                 $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]);
                 $split4 = explode("\$\$\$\$", $data[$NAME . $num . "_4"]);
                 $count_display = 0;
                 $added = array();
                 for ($k = 0; $k < count($split); $k++) {
                     if (strlen(trim($split[$k])) > 0) {
                         $text = sprintf(__('%1$s - %2$s'), $split[$k], Dropdown::getDropdownName('glpi_entities', $split2[$k]));
                         $comp = '';
                         if ($split3[$k]) {
                             $comp = __(READ);
                             if ($split4[$k]) {
                                 $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                             }
                         }
                         if ($split4[$k]) {
                             $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                         }
                         if (!empty($comp)) {
                             $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                         }
                         if (!in_array($text, $added)) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= $text;
                             $added[] = $text;
                         }
                     }
                 }
                 return $out;
             }
             break;
         case "glpi_entities.completename":
             if ($itemtype == 'User') {
                 $out = "";
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]);
                 $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]);
                 $split4 = explode("\$\$\$\$", $data[$NAME . $num . "_4"]);
                 $added = array();
                 $count_display = 0;
                 for ($k = 0; $k < count($split); $k++) {
                     if (strlen(trim($split[$k])) > 0) {
                         $text = sprintf(__('%1$s - %2$s'), $split[$k], Dropdown::getDropdownName('glpi_profiles', $split2[$k]));
                         $comp = '';
                         if ($split3[$k]) {
                             $comp = __(READ);
                             if ($split4[$k]) {
                                 $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                             }
                         }
                         if ($split4[$k]) {
                             $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                         }
                         if (!empty($comp)) {
                             $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                         }
                         if (!in_array($text, $added)) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= $text;
                             $added[] = $text;
                         }
                     }
                 }
                 return $out;
             }
             break;
         case "glpi_documenttypes.icon":
             if (!empty($data[$NAME . $num])) {
                 return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$NAME . $num] . "'>";
             }
             return "&nbsp;";
         case "glpi_documents.filename":
             $doc = new Document();
             if ($doc->getFromDB($data['id'])) {
                 return $doc->getDownloadLink();
             }
             return NOT_AVAILABLE;
         case "glpi_deviceharddrives.specificity":
         case "glpi_devicememories.specificity":
         case "glpi_deviceprocessors.specificity":
             return $data[$NAME . $num];
         case "glpi_networkports.mac":
             $out = "";
             if ($itemtype == 'Computer') {
                 $displayed = array();
                 if (!empty($data[$NAME . $num . "_2"])) {
                     $split = explode("\$\$\$\$", $data[$NAME . $num . "_2"]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         $lowstr = Toolbox::strtolower($split[$k]);
                         if (strlen(trim($split[$k])) > 0 && !in_array($lowstr, $displayed)) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= $split[$k];
                             $displayed[] = $lowstr;
                         }
                     }
                     if (!empty($data[$NAME . $num])) {
                         $out .= "<br>";
                     }
                 }
                 if (!empty($data[$NAME . $num])) {
                     $split = explode("\$\$\$\$", $data[$NAME . $num]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         $lowstr = Toolbox::strtolower($split[$k]);
                         if (strlen(trim($split[$k])) > 0 && !in_array($lowstr, $displayed)) {
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= $split[$k];
                             $displayed[] = $lowstr;
                         }
                     }
                 }
                 return $out;
             }
             break;
         case "glpi_contracts.duration":
         case "glpi_contracts.notice":
         case "glpi_contracts.periodicity":
         case "glpi_contracts.billing":
             if (!empty($data[$NAME . $num])) {
                 $split = explode('$$$$', $data[$NAME . $num]);
                 $output = "";
                 foreach ($split as $duration) {
                     $output .= (empty($output) ? '' : '<br>') . sprintf(_n('%d month', '%d months', $duration), $duration);
                 }
                 return $output;
             }
             return "&nbsp;";
         case "glpi_contracts.renewal":
             return Contract::getContractRenewalName($data[$NAME . $num]);
             //          case "glpi_infocoms.sink_time" :
             //             if (!empty($data[$NAME.$num])) {
             //                $split = explode("$$$$", $data[$NAME.$num]);
             //                $out   = '';
             //                foreach ($split as $val) {
             //                   $out .= (empty($out)?'':'<br>');
             //                   if ($val > 0) {
             //                      //TRANS: %d is a number of years
             //                      $out .= sprintf(_n('%d year', '%d years', $val), $val);
             //                   }
             //                }
             //                return $out;
             //             }
             //             return "&nbsp;";
             //
             //          case "glpi_infocoms.warranty_duration" :
             //             if (!empty($data[$NAME.$num])) {
             //                $split = explode("$$$$", $data[$NAME.$num]);
             //                $out   = '';
             //                foreach ($split as $val) {
             //                   $out .= (empty($out)?'':'<br>');
             //                   if ($val > 0) {
             //                      $out .= sprintf(_n('%d month', '%d months', $val), $val);
             //                   }
             //                   if ($val < 0) {
             //                      $out .= __('Lifelong');
             //                   }
             //                }
             //                return $out;
             //             }
             //             return "&nbsp;";
         //          case "glpi_infocoms.sink_time" :
         //             if (!empty($data[$NAME.$num])) {
         //                $split = explode("$$$$", $data[$NAME.$num]);
         //                $out   = '';
         //                foreach ($split as $val) {
         //                   $out .= (empty($out)?'':'<br>');
         //                   if ($val > 0) {
         //                      //TRANS: %d is a number of years
         //                      $out .= sprintf(_n('%d year', '%d years', $val), $val);
         //                   }
         //                }
         //                return $out;
         //             }
         //             return "&nbsp;";
         //
         //          case "glpi_infocoms.warranty_duration" :
         //             if (!empty($data[$NAME.$num])) {
         //                $split = explode("$$$$", $data[$NAME.$num]);
         //                $out   = '';
         //                foreach ($split as $val) {
         //                   $out .= (empty($out)?'':'<br>');
         //                   if ($val > 0) {
         //                      $out .= sprintf(_n('%d month', '%d months', $val), $val);
         //                   }
         //                   if ($val < 0) {
         //                      $out .= __('Lifelong');
         //                   }
         //                }
         //                return $out;
         //             }
         //             return "&nbsp;";
         case "glpi_infocoms.sink_type":
             $split = explode("\$\$\$\$", $data[$NAME . $num]);
             $out = '';
             foreach ($split as $val) {
                 $out .= (empty($out) ? '' : '<br>') . Infocom::getAmortTypeName($val);
             }
             return $out;
         case "glpi_infocoms.alert":
             if ($data[$NAME . $num] == pow(2, Alert::END)) {
                 return __s('Warranty expiration date');
             }
             return "";
         case "glpi_contracts.alert":
             switch ($data[$NAME . $num]) {
                 case pow(2, Alert::END):
                     return __('End');
                 case pow(2, Alert::NOTICE):
                     return __('Notice');
                 case pow(2, Alert::END) + pow(2, Alert::NOTICE):
                     return __('End + Notice');
             }
             return "";
         case "glpi_tickets_tickets.tickets_id_1":
             $out = "";
             $split = explode("\$\$\$\$", $data[$NAME . $num]);
             $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]);
             $displayed = array();
             for ($k = 0; $k < count($split); $k++) {
                 $linkid = $split[$k] == $data['id'] ? $split2[$k] : $split[$k];
                 if ($linkid > 0 && !isset($displayed[$linkid])) {
                     $text = "<a ";
                     $text .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id={$linkid}\">";
                     $text .= Dropdown::getDropdownName('glpi_tickets', $linkid) . "</a>";
                     if (count($displayed)) {
                         $out .= "<br>";
                     }
                     $displayed[$linkid] = $linkid;
                     $out .= $text;
                 }
             }
             return $out;
         case "glpi_problems.count":
             if ($data[$NAME . $num] > 0 && Session::haveRight("problem", Problem::READALL)) {
                 if ($itemtype == 'ITILCategory') {
                     $options['field'][0] = 7;
                     $options['searchtype'][0] = 'equals';
                     $options['contains'][0] = $data['id'];
                     $options['link'][0] = 'AND';
                 }
                 $options['reset'] = 'reset';
                 $out = "<a id='problem{$itemtype}" . $data['id'] . "' ";
                 $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/problem.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                 $out .= $data[$NAME . $num] . "</a>";
             } else {
                 $out = $data[$NAME . $num];
             }
             return $out;
         case "glpi_tickets.count":
             if ($data[$NAME . $num] > 0 && Session::haveRight("ticket", Ticket::READALL)) {
                 if ($itemtype == 'User') {
                     $options['field'][0] = 4;
                     $options['searchtype'][0] = 'equals';
                     $options['contains'][0] = $data['id'];
                     $options['link'][0] = 'AND';
                     $options['field'][1] = 22;
                     $options['searchtype'][1] = 'equals';
                     $options['contains'][1] = $data['id'];
                     $options['link'][1] = 'OR';
                     $options['field'][2] = 5;
                     $options['searchtype'][2] = 'equals';
                     $options['contains'][2] = $data['id'];
                     $options['link'][2] = 'OR';
                 } else {
                     if ($itemtype == 'ITILCategory') {
                         $options['field'][0] = 7;
                         $options['searchtype'][0] = 'equals';
                         $options['contains'][0] = $data['id'];
                         $options['link'][0] = 'AND';
                     } else {
                         $options['field'][0] = 12;
                         $options['searchtype'][0] = 'equals';
                         $options['contains'][0] = 'all';
                         $options['link'][0] = 'AND';
                         $options['itemtype2'][0] = $itemtype;
                         $options['field2'][0] = self::getOptionNumber($itemtype, 'name');
                         $options['searchtype2'][0] = 'equals';
                         $options['contains2'][0] = $data['id'];
                         $options['link2'][0] = 'AND';
                     }
                 }
                 $options['reset'] = 'reset';
                 $out = "<a id='ticket{$itemtype}" . $data['id'] . "' ";
                 $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                 $out .= $data[$NAME . $num] . "</a>";
             } else {
                 $out = $data[$NAME . $num];
             }
             return $out;
         case "glpi_tickets.due_date":
             // Due date + progress
             if ($ID == 151) {
                 $out = Html::convDate($data[$NAME . $num]);
                 // No due date in waiting status
                 if ($data[$NAME . $num . '_2'] == CommonITILObject::WAITING) {
                     return '';
                 }
                 if (empty($data[$NAME . $num])) {
                     return '';
                 }
                 if ($data[$NAME . $num . '_2'] == Ticket::SOLVED || $data[$NAME . $num . '_2'] == Ticket::CLOSED) {
                     return $data[$NAME . $num];
                 }
                 $ticket = new Ticket();
                 $ticket->getFromDB($data['ITEM_0']);
                 $percentage = 0;
                 $totaltime = 0;
                 $currenttime = 0;
                 if ($ticket->fields['slas_id'] != 0) {
                     // Have SLA
                     $sla = new SLA();
                     $sla->getFromDB($ticket->fields['slas_id']);
                     $currenttime = $sla->getActiveTimeBetween($ticket->fields['date'], date('Y-m-d H:i:s'));
                     $totaltime = $sla->getActiveTimeBetween($ticket->fields['date'], $data[$NAME . $num]);
                 } else {
                     $calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']);
                     if ($calendars_id != 0) {
                         // Ticket entity have calendar
                         $calendar = new Calendar();
                         $calendar->getFromDB($calendars_id);
                         $currenttime = $calendar->getActiveTimeBetween($ticket->fields['date'], date('Y-m-d H:i:s'));
                         $totaltime = $calendar->getActiveTimeBetween($ticket->fields['date'], $data[$NAME . $num]);
                     } else {
                         // No calendar
                         $currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($ticket->fields['date']);
                         $totaltime = strtotime($data[$NAME . $num]) - strtotime($ticket->fields['date']);
                     }
                 }
                 if ($totaltime != 0) {
                     $percentage = round(100 * $currenttime / $totaltime);
                 } else {
                     // Total time is null : no active time
                     $percentage = 100;
                 }
                 if ($percentage > 100) {
                     $percentage = 100;
                 }
                 $percentage_text = $percentage;
                 if ($_SESSION['glpiduedatewarning_unit'] == '%') {
                     $less_warn_limit = $_SESSION['glpiduedatewarning_less'];
                     $less_warn = 100 - $percentage;
                 } else {
                     if ($_SESSION['glpiduedatewarning_unit'] == 'hours') {
                         $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP;
                         $less_warn = $totaltime - $currenttime;
                     } else {
                         if ($_SESSION['glpiduedatewarning_unit'] == 'days') {
                             $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP;
                             $less_warn = $totaltime - $currenttime;
                         }
                     }
                 }
                 if ($_SESSION['glpiduedatecritical_unit'] == '%') {
                     $less_crit_limit = $_SESSION['glpiduedatecritical_less'];
                     $less_crit = 100 - $percentage;
                 } else {
                     if ($_SESSION['glpiduedatecritical_unit'] == 'hours') {
                         $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * HOUR_TIMESTAMP;
                         $less_crit = $totaltime - $currenttime;
                     } else {
                         if ($_SESSION['glpiduedatecritical_unit'] == 'days') {
                             $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * DAY_TIMESTAMP;
                             $less_crit = $totaltime - $currenttime;
                         }
                     }
                 }
                 $color = $_SESSION['glpiduedateok_color'];
                 if ($less_crit < $less_crit_limit) {
                     $color = $_SESSION['glpiduedatecritical_color'];
                 } else {
                     if ($less_warn < $less_warn_limit) {
                         $color = $_SESSION['glpiduedatewarning_color'];
                     }
                 }
                 //Calculate bar progress
                 $out .= "<div class='center' style='background-color: #ffffff; width: 100%;\n                         border: 1px solid #9BA563;' >";
                 $out .= "<div style='position:absolute;'>&nbsp;" . $percentage_text . "%</div>";
                 $out .= "<div class='center' style='background-color: " . $color . ";\n                         width: " . $percentage . "%; height: 12px' ></div>";
                 $out .= "</div>";
                 return $out;
             }
             break;
         case "glpi_softwarelicenses.number":
             if ($data[$NAME . $num . "_2"] == -1) {
                 return __('Unlimited');
             }
             if (empty($data[$NAME . $num])) {
                 return 0;
             }
             return $data[$NAME . $num];
         case "glpi_auth_tables.name":
             return Auth::getMethodName($data[$NAME . $num], $data[$NAME . $num . "_2"], 1, $data[$NAME . $num . "_3"] . $data[$NAME . $num . "_4"]);
         case "glpi_reservationitems.comment":
             if (empty($data[$NAME . $num])) {
                 return "<a title=\"" . __s('Modify the comment') . "\"\n                        href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . __('None') . "</a>";
             }
             return "<a title=\"" . __s('Modify the comment') . "\"\n                     href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . Html::resume_text($data[$NAME . $num]) . "</a>";
         case 'glpi_notifications.mode':
             return Notification::getMode($data[$NAME . $num]);
         case 'glpi_notifications.event':
             $item = NotificationTarget::getInstanceByType($data['itemtype']);
             if ($item) {
                 $events = $item->getAllEvents();
                 if (isset($events[$data[$NAME . $num]])) {
                     return $events[$data[$NAME . $num]];
                 }
             }
             return '';
         case 'glpi_reminders.state':
             return Planning::getState($data[$NAME . $num]);
         case 'glpi_crontasks.description':
             $tmp = new CronTask();
             return $tmp->getDescription($data['id']);
         case 'glpi_crontasks.state':
             return CronTask::getStateName($data[$NAME . $num]);
         case 'glpi_crontasks.mode':
             return CronTask::getModeName($data[$NAME . $num]);
         case 'glpi_crontasks.itemtype':
             if ($plug = isPluginItemType($data[$NAME . $num])) {
                 return $plug['plugin'];
             }
             return '';
         case 'glpi_changes.status':
             $status = Change::getStatus($data[$NAME . $num]);
             return "<img src=\"" . Change::getStatusIconURL($data[$NAME . $num]) . "\"\n                     alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
         case 'glpi_problems.status':
             $status = Problem::getStatus($data[$NAME . $num]);
             return "<img src=\"" . Problem::getStatusIconURL($data[$NAME . $num]) . "\"\n                     alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
         case 'glpi_tickets.status':
             $status = Ticket::getStatus($data[$NAME . $num]);
             return "<img src=\"" . Ticket::getStatusIconURL($data[$NAME . $num]) . "\"\n                     alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
         case 'glpi_tickets.items_id':
             if (!empty($data[$NAME . $num . "_2"]) && ($item = getItemForItemtype($data[$NAME . $num . "_2"]))) {
                 if ($item->getFromDB($data[$NAME . $num])) {
                     return $item->getLink(array('comments' => true));
                 }
             }
             return '&nbsp;';
         case 'glpi_tickets.name':
             if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 $link = Toolbox::getItemTypeFormURL('Ticket');
                 foreach ($split as $val) {
                     if (!empty($val)) {
                         $split2 = self::explodeWithID("\$\$", $val);
                         $out .= "<a id='ticket" . $split2[1] . "' href=\"" . $link;
                         $out .= strstr($link, '?') ? '&amp;' : '?';
                         $out .= 'id=' . $split2[1];
                         $out .= "\">";
                         $name = $split2[0];
                         if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) {
                             $name = sprintf(__('%1$s (%2$s)'), $name, $split2[1]);
                         }
                         $out .= $name . "</a><br>";
                     }
                 }
                 return $out;
             }
             $link = Toolbox::getItemTypeFormURL('Ticket');
             $out = "<a id='ticket" . $data[$NAME . $num . "_2"] . "' href=\"" . $link;
             $out .= strstr($link, '?') ? '&amp;' : '?';
             $out .= 'id=' . $data[$NAME . $num . "_2"];
             // Force solution tab if solved
             if ($data[$NAME . $num . "_4"] == CommonITILObject::SOLVED) {
                 $out .= "&amp;forcetab=Ticket\$2";
             }
             $out .= "\">";
             $name = $data[$NAME . $num];
             if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) {
                 $name = sprintf(__('%1$s (%2$s)'), $name, $data[$NAME . $num . "_2"]);
             }
             $out .= $name . "</a>";
             $out = sprintf(__('%1$s %2$s'), $out, Html::showToolTip(nl2br($data[$NAME . $num . "_3"]), array('applyto' => 'ticket' . $data[$NAME . $num . "_2"], 'display' => false)));
             return $out;
         case 'glpi_ticketvalidations.status':
             $split = explode("\$\$\$\$", $data[$NAME . $num]);
             $out = '';
             foreach ($split as $val) {
                 if (!empty($val)) {
                     $split2 = self::explodeWithID("\$\$", $val);
                     $status = TicketValidation::getStatus($split2[0]);
                     $bgcolor = TicketValidation::getStatusColor($split2[0]);
                     $out .= (empty($out) ? '' : '<br>') . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>';
                 }
             }
             return $out;
         case 'glpi_ticketsatisfactions.type':
             return TicketSatisfaction::getTypeInquestName($data[$NAME . $num]);
         case 'glpi_ticketsatisfactions.satisfaction':
             return TicketSatisfaction::displaySatisfaction($data[$NAME . $num]);
         case 'glpi_notimportedemails.reason':
             return NotImportedEmail::getReason($data[$NAME . $num]);
         case 'glpi_notimportedemails.messageid':
             $clean = array('<' => '', '>' => '');
             return strtr($data[$NAME . $num], $clean);
     }
     //// Default case
     // Link with plugin tables : need to know left join structure
     if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $table . '.' . $field, $matches)) {
         if (count($matches) == 2) {
             $plug = $matches[1];
             $function = 'plugin_' . $plug . '_giveItem';
             if (function_exists($function)) {
                 $out = $function($itemtype, $ID, $data, $num);
                 if (!empty($out)) {
                     return $out;
                 }
             }
         }
     }
     $unit = '';
     if (isset($searchopt[$ID]['unit'])) {
         $unit = $searchopt[$ID]['unit'];
     }
     /// TODO try to use getvalueToDisplay instead of redefine display system
     // Preformat items
     if (isset($searchopt[$ID]["datatype"])) {
         switch ($searchopt[$ID]["datatype"]) {
             case "itemlink":
                 $linkitemtype = getItemTypeForTable($searchopt[$ID]["table"]);
                 if (isset($data[$NAME . $num . "_2"]) && strlen($data[$NAME . $num . "_2"])) {
                     $link = Toolbox::getItemTypeFormURL($linkitemtype);
                     $out = "<a id='" . $itemtype . "_" . $data[$NAME . $num . "_2"] . "' href=\"" . $link;
                     $out .= strstr($link, '?') ? '&amp;' : '?';
                     $out .= 'id=' . $data[$NAME . $num . "_2"];
                     if (isset($searchopt[$ID]['forcetab'])) {
                         $out .= "&amp;forcetab=" . $searchopt[$ID]['forcetab'];
                     }
                     $out .= "\">";
                     $name = Dropdown::getValueWithUnit($data[$NAME . $num], $unit);
                     if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) {
                         $name = sprintf(__('%1$s (%2$s)'), $name, $data[$NAME . $num . "_2"]);
                     }
                     $out .= $name . "</a>";
                     return $out;
                 }
                 $out = "";
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $count_display = 0;
                 $separate = '<br>';
                 if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                     $separate = '<hr>';
                 }
                 for ($k = 0; $k < count($split); $k++) {
                     if (strlen(trim($split[$k])) > 0) {
                         $split2 = self::explodeWithID("\$\$", $split[$k]);
                         if (isset($split2[1]) && $split2[1] > 0) {
                             if ($count_display) {
                                 $out .= $separate;
                             }
                             $count_display++;
                             $page = Toolbox::getItemTypeFormURL($linkitemtype);
                             $page .= strpos($page, '?') ? '&id' : '?id';
                             $name = Dropdown::getValueWithUnit($split2[0], $unit);
                             if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) {
                                 $name = sprintf(__('%1$s (%2$s)'), $name, $split2[1]);
                             }
                             $out .= "<a id='" . $linkitemtype . "_" . $data['id'] . "_" . $split2[1] . "' href='{$page}=" . $split2[1] . "'>" . $name . "</a>";
                         }
                     }
                 }
                 return $out;
             case "text":
                 $separate = '<br>';
                 if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                     $separate = '<hr>';
                 }
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 $count_display = 0;
                 foreach ($split as $val) {
                     if (strlen(trim($val)) > 0) {
                         $split2 = self::explodeWithID("\$\$", $val);
                         if ($count_display) {
                             $out .= $separate;
                         }
                         $count_display++;
                         if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) {
                             $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep(nl2br($split2[0])));
                         } else {
                             $text = nl2br($split2[0]);
                         }
                         if (self::$output_type == self::HTML_OUTPUT && Toolbox::strlen($text) > $CFG_GLPI['cut']) {
                             $rand = mt_rand();
                             $out .= sprintf(__('%1$s %2$s'), "<span id='text{$rand}'>" . Html::resume_text($text, $CFG_GLPI['cut']) . '</span>', Html::showToolTip($text, array('applyto' => "text{$rand}", 'display' => false)));
                         } else {
                             $out .= $text;
                         }
                     }
                 }
                 return $out;
             case "date":
             case "date_delay":
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 foreach ($split as $val) {
                     $out .= (empty($out) ? '' : '<br>') . Html::convDate($val);
                 }
                 return $out;
             case "datetime":
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 foreach ($split as $val) {
                     $out .= (empty($out) ? '' : '<br>') . Html::convDateTime($val);
                 }
                 return $out;
             case "timestamp":
                 $withseconds = false;
                 if (isset($searchopt[$ID]['withseconds'])) {
                     $withseconds = $searchopt[$ID]['withseconds'];
                 }
                 $withdays = true;
                 if (isset($searchopt[$ID]['withdays'])) {
                     $withdays = $searchopt[$ID]['withdays'];
                 }
                 $split = explode("\$\$\$\$", $data[$NAME . $num]);
                 $out = '';
                 foreach ($split as $val) {
                     $out .= (empty($out) ? '' : '<br>') . Html::timestampToString($val, $withseconds, $withdays);
                 }
                 return $out;
             case "email":
                 $split = explode('$$$$', $data[$NAME . $num]);
                 $out = '';
                 $count_display = 0;
                 foreach ($split as $val) {
                     $split2 = self::explodeWithID("\$\$", $val);
                     if ($count_display) {
                         $out .= "<br>";
                     }
                     $count_display++;
                     if (!empty($val)) {
                         $out .= empty($out) ? '' : '<br>';
                         $out .= "<a href='mailto:{$split2['0']}'>{$split2['0']}</a>";
                     }
                 }
                 return empty($out) ? "&nbsp;" : $out;
             case "weblink":
                 $orig_link = trim($data[$NAME . $num]);
                 if (!empty($orig_link)) {
                     // strip begin of link
                     $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link);
                     $link = preg_replace('/\\/$/', '', $link);
                     if (Toolbox::strlen($link) > $CFG_GLPI["url_maxlength"]) {
                         $link = Toolbox::substr($link, 0, $CFG_GLPI["url_maxlength"]) . "...";
                     }
                     return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}</a>";
                 }
                 return "&nbsp;";
             case "number":
                 if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
                     $out = "";
                     $split = explode("\$\$\$\$", $data[$NAME . $num]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         if (strlen(trim($split[$k])) > 0) {
                             $split2 = self::explodeWithID("\$\$", $split[$k]);
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split2[0]])) {
                                 $out .= $searchopt[$ID]['toadd'][$split2[0]];
                             } else {
                                 $number = str_replace(' ', '&nbsp;', Html::formatNumber($split2[0], false, 0));
                                 $out .= Dropdown::getValueWithUnit($number, $unit);
                             }
                         }
                     }
                     return $out;
                 }
                 if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$NAME . $num]])) {
                     return $searchopt[$ID]['toadd'][$data[$NAME . $num]];
                 } else {
                     $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$NAME . $num], false, 0));
                     return Dropdown::getValueWithUnit($number, $unit);
                 }
             case "decimal":
                 if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
                     $out = "";
                     $split = explode("\$\$\$\$", $data[$NAME . $num]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         if (strlen(trim($split[$k])) > 0) {
                             $split2 = self::explodeWithID("\$\$", $split[$k]);
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split2[0]])) {
                                 $out .= $searchopt[$ID]['toadd'][$split2[0]];
                             } else {
                                 $number = str_replace(' ', '&nbsp;', Html::formatNumber($split2[0]));
                                 $out .= Dropdown::getValueWithUnit($number, $unit);
                             }
                         }
                     }
                     return $out;
                 }
                 $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$NAME . $num]));
                 return Dropdown::getValueWithUnit($number, $unit);
             case "bool":
                 if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
                     $out = "";
                     $split = explode("\$\$\$\$", $data[$NAME . $num]);
                     $count_display = 0;
                     for ($k = 0; $k < count($split); $k++) {
                         if (strlen(trim($split[$k])) > 0) {
                             $split2 = self::explodeWithID("\$\$", $split[$k]);
                             if ($count_display) {
                                 $out .= "<br>";
                             }
                             $count_display++;
                             $out .= Dropdown::getValueWithUnit(Dropdown::getYesNo($split2[0]), $unit);
                         }
                     }
                     return $out;
                 }
                 return Dropdown::getValueWithUnit(Dropdown::getYesNo($data[$NAME . $num]), $unit);
             case "right":
                 return Profile::getRightValue($data[$NAME . $num]);
             case "itemtypename":
                 if ($obj = getItemForItemtype($data[$NAME . $num])) {
                     return $obj->getTypeName();
                 }
                 return "";
             case "language":
                 if (isset($CFG_GLPI['languages'][$data[$NAME . $num]])) {
                     return $CFG_GLPI['languages'][$data[$NAME . $num]][0];
                 }
                 return __('Default value');
         }
     }
     // Manage items with need group by / group_concat
     if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) {
         $out = "";
         $split = explode("\$\$\$\$", $data[$NAME . $num]);
         $count_display = 0;
         $separate = '<br>';
         if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
             $separate = '<hr>';
         }
         for ($k = 0; $k < count($split); $k++) {
             if (strlen(trim($split[$k])) > 0) {
                 if ($count_display) {
                     $out .= $separate;
                 }
                 $withoutid = self::explodeWithID("\$\$", $split[$k]);
                 $count_display++;
                 // Get specific display if available
                 $itemtype = getItemTypeForTable($table);
                 if ($item = getItemForItemtype($itemtype)) {
                     $tmpdata = array($field => $withoutid[0]);
                     $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true));
                 }
                 if (!empty($specific)) {
                     $out .= $specific;
                 } else {
                     $out .= Dropdown::getValueWithUnit($withoutid[0], $unit);
                 }
             }
         }
         return $out;
     }
     // Get specific display if available
     $itemtype = getItemTypeForTable($table);
     if ($item = getItemForItemtype($itemtype)) {
         $tmpdata = array($field => $data[$NAME . $num]);
         if (isset($searchopt[$ID]['additionalfields']) && count($searchopt[$ID]['additionalfields'])) {
             foreach ($searchopt[$ID]['additionalfields'] as $key) {
                 $tmpdata[$key] = $data[$NAME . $num . '_' . $key];
             }
         }
         $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true));
         if (!empty($specific)) {
             return $specific;
         }
     }
     // Manage auto CONCAT id
     $split = self::explodeWithID('$$', $data[$NAME . $num]);
     $split[0] = trim($split[0]);
     if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split[0]])) {
         return $searchopt[$ID]['toadd'][$split[0]];
     }
     // Empty is 0 or empty
     if (empty($split[0]) && isset($searchopt[$ID]['emptylabel'])) {
         return $searchopt[$ID]['emptylabel'];
     }
     return Dropdown::getValueWithUnit($split[0], $unit);
 }
 /**
  * Get all data needed for template processing
  *
  * @param $event
  * @param $options array
  **/
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI;
     $events = $this->getAllEvents();
     $objettype = strtolower($this->obj->getType());
     // Get datas from ITIL objects
     if ($event != 'alertnotclosed') {
         $this->datas = $this->getDatasForObject($this->obj, $options);
     } else {
         if (isset($options['entities_id']) && isset($options['items'])) {
             $entity = new Entity();
             if ($entity->getFromDB($options['entities_id'])) {
                 $this->datas["##{$objettype}.entity##"] = $entity->getField('completename');
                 $this->datas["##{$objettype}.shortentity##"] = $entity->getField('name');
             }
             if ($item = getItemForItemtype($objettype)) {
                 $objettypes = Toolbox::strtolower(getPlural($objettype));
                 $items = array();
                 foreach ($options['items'] as $object) {
                     $item->getFromDB($object['id']);
                     $tmp = $this->getDatasForObject($item, $options, true);
                     $this->datas[$objettypes][] = $tmp;
                 }
             }
         }
     }
     if ($event == 'validation' && isset($options['validation_status'])) {
         $this->datas["##{$objettype}.action##"] = sprintf(__('%1$s - %2$s'), __('Approval'), TicketValidation::getStatus($options['validation_status']));
     } else {
         $this->datas["##{$objettype}.action##"] = $events[$event];
     }
     $this->getTags();
     foreach ($this->tag_descriptions[parent::TAG_LANGUAGE] as $tag => $values) {
         if (!isset($this->datas[$tag])) {
             $this->datas[$tag] = $values['label'];
         }
     }
 }
Ejemplo n.º 13
0
 function _putfonts()
 {
     $nf = $this->n;
     foreach ($this->diffs as $diff) {
         //Encodings
         $this->_newobj();
         $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $diff . ']>>');
         $this->_out('endobj');
     }
     $mqr = Toolbox::get_magic_quotes_runtime();
     ini_set("magic_quotes_runtime", 0);
     foreach ($this->FontFiles as $file => $info) {
         //Font file embedding
         $this->_newobj();
         $this->FontFiles[$file]['n'] = $this->n;
         $font = '';
         $f = fopen($this->_getfontpath() . $file, 'rb', 1);
         if (!$f) {
             $this->Error('Font file not found');
         }
         while (!feof($f)) {
             $font .= fread($f, 8192);
         }
         fclose($f);
         $compressed = substr($file, -2) == '.z';
         if (!$compressed && isset($info['length2'])) {
             $header = ord($font[0]) == 128;
             if ($header) {
                 //Strip first binary header
                 $font = substr($font, 6);
             }
             if ($header && ord($font[$info['length1']]) == 128) {
                 //Strip second binary header
                 $font = substr($font, 0, $info['length1']) . substr($font, $info['length1'] + 6);
             }
         }
         $this->_out('<</Length ' . strlen($font));
         if ($compressed) {
             $this->_out('/Filter /FlateDecode');
         }
         $this->_out('/Length1 ' . $info['length1']);
         if (isset($info['length2'])) {
             $this->_out('/Length2 ' . $info['length2'] . ' /Length3 0');
         }
         $this->_out('>>');
         $this->_putstream($font);
         $this->_out('endobj');
     }
     ini_set("magic_quotes_runtime", $mqr);
     foreach ($this->fonts as $k => $font) {
         //Font objects
         $this->fonts[$k]['n'] = $this->n + 1;
         $type = $font['type'];
         $name = $font['name'];
         if ($type == 'core') {
             //Standard font
             $this->_newobj();
             $this->_out('<</Type /Font');
             $this->_out('/BaseFont /' . $name);
             $this->_out('/Subtype /Type1');
             if ($name != 'Symbol' && $name != 'ZapfDingbats') {
                 $this->_out('/Encoding /WinAnsiEncoding');
             }
             $this->_out('>>');
             $this->_out('endobj');
         } else {
             if ($type == 'Type1' || $type == 'TrueType') {
                 //Additional Type1 or TrueType font
                 $this->_newobj();
                 $this->_out('<</Type /Font');
                 $this->_out('/BaseFont /' . $name);
                 $this->_out('/Subtype /' . $type);
                 $this->_out('/FirstChar 32 /LastChar 255');
                 $this->_out('/Widths ' . ($this->n + 1) . ' 0 R');
                 $this->_out('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
                 if ($font['enc']) {
                     if (isset($font['diff'])) {
                         $this->_out('/Encoding ' . ($nf + $font['diff']) . ' 0 R');
                     } else {
                         $this->_out('/Encoding /WinAnsiEncoding');
                     }
                 }
                 $this->_out('>>');
                 $this->_out('endobj');
                 //Widths
                 $this->_newobj();
                 $cw =& $font['cw'];
                 $s = '[';
                 for ($i = 32; $i <= 255; $i++) {
                     $s .= $cw[chr($i)] . ' ';
                 }
                 $this->_out($s . ']');
                 $this->_out('endobj');
                 //Descriptor
                 $this->_newobj();
                 $s = '<</Type /FontDescriptor /FontName /' . $name;
                 foreach ($font['desc'] as $k => $v) {
                     $s .= ' /' . $k . ' ' . $v;
                 }
                 $file = $font['file'];
                 if ($file) {
                     $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$file]['n'] . ' 0 R';
                 }
                 $this->_out($s . '>>');
                 $this->_out('endobj');
             } else {
                 //Allow for additional types
                 $mtd = '_put' . Toolbox::strtolower($type);
                 if (!method_exists($this, $mtd)) {
                     $this->Error('Unsupported font type: ' . $type);
                 }
                 $this->{$mtd}($font);
             }
         }
     }
 }
Ejemplo n.º 14
0
 static function mainLine(PluginPdfSimplePDF $pdf, $item, $field)
 {
     $type = Toolbox::strtolower($item->getType());
     switch ($field) {
         case 'name-status':
             return $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Name') . '</i></b>', $item->fields['name']), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Status') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_states', $item->fields['states_id']))));
         case 'location-type':
             return $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Location') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_locations', $item->fields['locations_id']))), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Type') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_' . $type . 'types', $item->fields[$type . 'types_id']))));
         case 'tech-manufacturer':
             return $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Technician in charge of the hardware') . '</i></b>', getUserName($item->fields['users_id_tech'])), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Manufacturer') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_manufacturers', $item->fields['manufacturers_id']))));
         case 'group-model':
             return $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Group in charge of the hardware') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id_tech']))), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Model') . '</i></b>', Html::clean(Dropdown::getDropdownName('glpi_' . $type . 'models', $item->fields[$type . 'models_id']))));
         case 'contactnum-serial':
             return $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Alternate username number') . '</i></b>', $item->fields['contact_num']), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Serial number') . '</i></b>', $item->fields['serial']));
         case 'contact-otherserial':
             return $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('Alternate username') . '</i></b>', $item->fields['contact']), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Inventory number') . '</i></b>', $item->fields['otherserial']));
         case 'user-management':
             return $pdf->displayLine('<b><i>' . sprintf(__('%1$s: %2$s'), __('User') . '</i></b>', getUserName($item->fields['users_id'])), '<b><i>' . sprintf(__('%1$s: %2$s'), __('Management type') . '</i></b>', $item->fields['is_global'] ? __('Global management') : __('Unit management')));
         case 'comment':
             return $pdf->displayText('<b><i>' . sprintf(__('%1$s: %2$s'), __('Comments') . '</i></b>', $item->fields['comment']));
         default:
             return;
     }
 }