strlen() static public method

strlen function for utf8 string
static public strlen ( $str ) : length
$str string
return length of the string
Exemplo n.º 1
2
 /**
  * Generate the Vcard for the current Contact
  *
  *@return Nothing (display)
  **/
 function generateVcard()
 {
     if (!$this->can($this->fields['id'], READ)) {
         return false;
     }
     // build the Vcard
     $vcard = new VObject\Component\VCard(['N' => [$this->fields["name"], $this->fields["firstname"]], 'EMAIL' => $this->fields["email"], 'NOTE' => $this->fields["comment"]]);
     $vcard->add('TEL', $this->fields["phone"], ['type' => 'PREF;WORK;VOICE']);
     $vcard->add('TEL', $this->fields["phone2"], ['type' => 'HOME;VOICE']);
     $vcard->add('TEL', $this->fields["mobile"], ['type' => 'WORK;CELL']);
     $vcard->add('URL', $this->GetWebsite(), ['type' => 'WORK']);
     $addr = $this->GetAddress();
     if (is_array($addr)) {
         $addr_string = implode(";", array_filter($addr));
         $vcard->add('ADR', $addr_string, ['type' => 'WORK;POSTAL']);
     }
     // send the  VCard
     $output = $vcard->serialize();
     $filename = $this->fields["name"] . "_" . $this->fields["firstname"] . ".vcf";
     @Header("Content-Disposition: attachment; filename=\"{$filename}\"");
     @Header("Content-Length: " . Toolbox::strlen($output));
     @Header("Connection: close");
     @Header("content-type: text/x-vcard; charset=UTF-8");
     echo $output;
 }
Exemplo n.º 2
0
 static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item)
 {
     global $DB;
     $ID = $item->getField('id');
     if (!Session::haveRight('knowbase', 'r') || !Session::haveRight('faq', 'r')) {
         return false;
     }
     $knowbaseitemcategories_id = $item->getField('knowbaseitemcategories_id');
     $fullcategoryname = Html::clean(getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id));
     $question = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('name'), ENT_QUOTES, "UTF-8")));
     $answer = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('answer'), ENT_QUOTES, "UTF-8")));
     $pdf->setColumnsSize(100);
     if (Toolbox::strlen($fullcategoryname) > 0) {
         $pdf->displayTitle('<b>' . __('Category name') . '</b>');
         $pdf->displayLine($fullcategoryname);
     }
     if (Toolbox::strlen($question) > 0) {
         $pdf->displayTitle('<b>' . __('Subject') . '</b>');
         $pdf->displayText('', $question, 5);
     } else {
         $pdf->displayTitle('<b>' . __('No question found', 'pdf') . '</b>');
     }
     if (Toolbox::strlen($answer) > 0) {
         $pdf->displayTitle('<b>' . __('Content') . '</b>');
         $pdf->displayText('', $answer, 5);
     } else {
         $pdf->displayTitle('<b>' . __('No answer found') . '</b>');
     }
     $pdf->setColumnsSize(50, 15, 15, 10, 10);
     $pdf->displayTitle(__('Writer'), __('Creation date'), __('Last update'), __('FAQ'), _n('View', 'Views', 2));
     $pdf->displayLine(getUserName($item->fields["users_id"]), Html::convDateTime($item->fields["date"]), Html::convDateTime($item->fields["date_mod"]), Dropdown::getYesNo($item->fields["is_faq"]), $item->fields["view"]);
     $pdf->displaySpace();
 }
Exemplo n.º 3
0
 public function showFirstLevel($message)
 {
     global $LANG, $CFG_GLPI;
     $menu = $this->getMenu();
     if ($message != '') {
         echo "<div class='ui-loader ui-body-a ui-corner-all' id='messagebox' style='top: 75px;display:block'>";
         echo "<h1>{$message}</h1>";
         echo "</div>";
         echo "<script>\n               \$('#messagebox').delay(800).fadeOut(2000);\n         </script>";
     }
     echo "<div data-role='content'>";
     echo "<ul data-role='listview' data-inset='true' data-theme='c' data-dividertheme='a'>";
     echo "<li data-role='list-divider'>" . $LANG['plugin_mobile']["title"] . "</li>";
     $i = 1;
     foreach ($menu as $part => $data) {
         if (isset($data['content']) && count($data['content'])) {
             echo "<li id='menu{$i}'>";
             $link = $CFG_GLPI["root_doc"] . "/plugins/mobile/front/ss_menu.php?menu=" . $part;
             if (Toolbox::strlen($data['title']) > 14) {
                 $data['title'] = utf8_substr($data['title'], 0, 14) . "...";
             }
             if (isset($data['icon'])) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/pics/" . $data['icon'] . "' class='ui-li-icon round-icon' />";
             }
             echo "<a href=\"{$link}\" data-back='false'>" . $data['title'] . "</a>";
             echo "</li>";
             $i++;
         }
     }
     echo "</ul>";
     echo "</div>";
 }
Exemplo n.º 4
0
 /**
  * Permet l'affichage dynamique d'une liste d�roulante imbriquee
  *
  * @static
  * @param array ($itemtype,$options)
  */
 public static function dropdownReferencesByEnterprise($itemtype, $options = array())
 {
     global $DB, $CFG_GLPI;
     $item = getItemForItemtype($itemtype);
     if ($itemtype && !($item = getItemForItemtype($itemtype))) {
         return false;
     }
     $table = $item->getTable();
     $params['comments'] = true;
     $params['condition'] = '';
     $params['entity'] = -1;
     $params['name'] = "reference";
     $params['value'] = 0;
     $params['entity_sons'] = false;
     $params['rand'] = mt_rand();
     $params['used'] = array();
     $params['table'] = $table;
     $params['emptylabel'] = Dropdown::EMPTY_VALUE;
     //specific
     $params['action'] = "";
     $params['itemtype'] = "";
     $params['span'] = "";
     $params['orders_id'] = 0;
     $params['suppliers_id'] = 0;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $name = $params['emptylabel'];
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     if (strlen($params['value']) == 0 || !is_numeric($params['value'])) {
         $params['value'] = 0;
     }
     if ($params['value'] > 0) {
         $tmpname = Dropdown::getDropdownName($table, $params['value'], 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
             if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
                 if ($item instanceof CommonTreeDropdown) {
                     $pos = strrpos($name, ">");
                     $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
                     if (Toolbox::strlen($name) > $limit_length) {
                         $name = "&hellip;" . Toolbox::substr($name, -$limit_length);
                     }
                 } else {
                     $limit_length = Toolbox::strlen($name);
                 }
             } else {
                 $limit_length = $_SESSION["glpidropdown_chars_limit"];
             }
         }
     }
     // Manage entity_sons
     if (!($params['entity'] < 0) && $params['entity_sons']) {
         if (is_array($params['entity'])) {
             echo "entity_sons options is not available with array of entity";
         } else {
             $params['entity'] = getSonsOf('glpi_entities', $params['entity']);
         }
     }
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax_autocompletion"]) {
         $nb = 0;
         $query = "SELECT COUNT(*) AS cpt\n                   FROM `{$table}` as t\n                   LEFT JOIN `glpi_plugin_order_references_suppliers` as s\n                      ON (`t`.`id` = `s`.`plugin_order_references_id`)\n                   WHERE `s`.`suppliers_id` = '{$params['suppliers_id']}'\n                   AND `t`.`itemtype` = '{$params['itemtype']}'";
         if ($item->isEntityAssign()) {
             if (!($params['entity'] < 0)) {
                 $query .= getEntitiesRestrictRequest("AND", 't', '', $params['entity'], true);
             } else {
                 $query .= getEntitiesRestrictRequest("AND", 't', '', '', true);
             }
         }
         $result = $DB->query($query);
         if ($DB->numrows($result) == 1) {
             $nb = $DB->result($result, 0, "cpt");
         }
         $nb -= count($params['used']);
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $params['itemtype'], 'myname' => $params['name'], 'limit' => $limit_length, 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'used' => $params['used'], 'condition' => $params['condition'], 'table' => $params['table'], 'action' => $params['action'], 'span' => $params['span'], 'orders_id' => $params['orders_id'], 'suppliers_id' => $params['suppliers_id']);
     $default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>";
     $default .= "<option value='" . $params['value'] . "'>{$name}</option></select>";
     Ajax::Dropdown($use_ajax, "/plugins/order/ajax/dropdownValue.php", $param, $default, $params['rand']);
     // Display comment
     if ($params['comments']) {
         $options_tooltip = array('contentid' => "comment_" . $param['myname'] . $params['rand']);
         if ($params['value'] && $item->getFromDB($params['value'])) {
             $options_tooltip['link'] = $item->getLinkURL();
             $options_tooltip['linktarget'] = '_blank';
         }
         Html::showToolTip($comment, $options_tooltip);
         if ($itemtype::canCreate() && !isset($_GET['popup'])) {
             echo "<img alt='' title=\"" . __("Add") . "\" src='" . $CFG_GLPI["root_doc"] . "\n               /pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n               onClick=\"var w = window . open('" . $item->getFormURL() . "?popup=1&amp;rand=" . $params['rand'] . "&amp;itemtype=" . $params['itemtype'] . "&amp;entities_id=" . $params['entity'] . "', " . "'glpipopup', 'height=400,width=1000, top=100, left=100,\n               scrollbars=yes' );w.focus();\">";
         }
     }
     return $params['rand'];
 }
Exemplo n.º 5
0
 /**
  * Log history
  *
  * @param $items_id
  * @param $itemtype
  * @param $changes
  * @param $itemtype_link   (default '')
  * @param $linked_action   (default '0')
  *
  * @return boolean success
  **/
 static function history($items_id, $itemtype, $changes, $itemtype_link = '', $linked_action = '0')
 {
     global $DB;
     $date_mod = $_SESSION["glpi_currenttime"];
     if (empty($changes)) {
         return false;
     }
     // create a query to insert history
     $id_search_option = $changes[0];
     $old_value = $changes[1];
     $new_value = $changes[2];
     if ($uid = Session::getLoginUserID(false)) {
         if (is_numeric($uid)) {
             $username = sprintf(__('%1$s (%2$s)'), getUserName($uid), $uid);
         } else {
             // For cron management
             $username = $uid;
         }
     } else {
         $username = "";
     }
     $old_value = $DB->escape(Toolbox::substr(stripslashes($old_value), 0, 180));
     $new_value = $DB->escape(Toolbox::substr(stripslashes($new_value), 0, 180));
     // Security to be sure that values do not pass over the max length
     if (Toolbox::strlen($old_value) > 255) {
         $old_value = Toolbox::substr($old_value, 0, 250);
     }
     if (Toolbox::strlen($new_value) > 255) {
         $new_value = Toolbox::substr($new_value, 0, 250);
     }
     // Build query
     $query = "INSERT INTO `glpi_logs`\n                       (`items_id`, `itemtype`, `itemtype_link`, `linked_action`, `user_name`,\n                        `date_mod`, `id_search_option`, `old_value`, `new_value`)\n                VALUES ('{$items_id}', '{$itemtype}', '{$itemtype_link}', '{$linked_action}',\n                        '" . addslashes($username) . "', '{$date_mod}', '{$id_search_option}',\n                        '{$old_value}', '{$new_value}')";
     if ($DB->query($query)) {
         return $_SESSION['glpi_maxhistory'] = $DB->insert_id();
     }
     return false;
 }
Exemplo n.º 6
0
 function dropdownVlan($used = array())
 {
     global $DB;
     $limit = $_SESSION["glpidropdown_chars_limit"];
     $where = "";
     if (count($used)) {
         $where = "WHERE `id` NOT IN (0";
         foreach ($used as $ID) {
             $where .= ",{$ID}";
         }
         $where .= ")";
     }
     $query = "SELECT *\n                FROM `glpi_vlans`\n                {$where}\n                ORDER BY `name`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if ($number != "0") {
         echo "<select name='vlans_id'>\n";
         echo "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option>\n";
         echo "<option value='-1'>" . __('All VLANs', 'archires') . "</option>\n";
         while ($data = $DB->fetch_array($result)) {
             $output = $data["name"];
             if (Toolbox::strlen($output) > $limit) {
                 $output = Toolbox::substr($output, 0, $limit) . "&hellip;";
             }
             echo "<option value='" . $data["id"] . "'>" . $output . "</option>";
         }
         echo "</select>";
     }
 }
Exemplo n.º 7
0
 static function pdfNote(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     $ID = $item->getField('id');
     $note = trim($item->getField('notepad'));
     $pdf->setColumnsSize(100);
     if (Toolbox::strlen($note) > 0) {
         $pdf->displayTitle('<b>' . __('Notes') . '</b>');
         $pdf->displayText('', $note, 5);
     } else {
         $pdf->displayTitle('<b>' . __('No note found', 'pdf') . '</b>');
     }
     $pdf->displaySpace();
 }
Exemplo n.º 8
0
                         }
                         $to_display = "<option disabled value='{$work_parentID}' {$class2}\n                                           title=\"" . Html::cleanInputText($item->fields['completename'] . $addcomment) . "\">" . str_repeat("&nbsp;&nbsp;&nbsp;", $work_level) . $raquo2 . $output2 . "</option>" . $to_display;
                         $last_level_displayed[$work_level] = $item->fields['id'];
                         $work_level--;
                         $work_parentID = $item->fields[$item->getForeignKeyField()];
                     } else {
                         // Error getting item : stop
                         $work_level = -1;
                     }
                 } while ($work_level > 1 && (!isset($last_level_displayed[$work_level]) || $last_level_displayed[$work_level] != $work_parentID));
                 echo $to_display;
             }
         }
         $last_level_displayed[$level] = $data['id'];
     }
     if (Toolbox::strlen($output) > $_POST["limit"]) {
         if ($_SESSION['glpiuse_flat_dropdowntree']) {
             $output = "&hellip;" . Toolbox::substr($output, -$_POST["limit"]);
         } else {
             $output = Toolbox::substr($output, 0, $_POST["limit"]) . "&hellip;";
         }
     }
     if ($_SESSION["glpiis_ids_visible"] || strlen($output) == 0) {
         $output .= " ({$ID})";
     }
     $addcomment = "";
     if (isset($data["comment"])) {
         $addcomment = " - " . $data["comment"];
     }
     echo "<option value='{$ID}' {$class} title=\"" . Html::cleanInputText($data['completename'] . $addcomment) . "\">" . str_repeat("&nbsp;&nbsp;&nbsp;", $level) . $raquo . $output . "</option>";
 }
Exemplo n.º 9
0
 /**
  * Print generic normal Item Cell
  *
  * @param $type         display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
  * @param $value        value to display
  * @param &$num         column number
  * @param $row          row number
  * @param $extraparam   extra parameters for display (default '')
  *
  *@return string to display
  **/
 static function showItem($type, $value, &$num, $row, $extraparam = '')
 {
     $out = "";
     switch ($type) {
         case self::PDF_OUTPUT_LANDSCAPE:
             //pdf
         //pdf
         case self::PDF_OUTPUT_PORTRAIT:
             global $PDF_TABLE;
             $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
             $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
             $PDF_TABLE .= "<td {$extraparam} valign='top'>";
             $PDF_TABLE .= Html::weblink_extract(Html::clean($value));
             $PDF_TABLE .= "</td>\n";
             break;
         case self::SYLK_OUTPUT:
             //sylk
             global $SYLK_ARRAY, $SYLK_HEADER, $SYLK_SIZE;
             $value = Html::weblink_extract($value);
             $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
             $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
             $SYLK_ARRAY[$row][$num] = self::sylk_clean($value);
             $SYLK_SIZE[$num] = max($SYLK_SIZE[$num], Toolbox::strlen($SYLK_ARRAY[$row][$num]));
             break;
         case self::CSV_OUTPUT:
             //csv
             $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
             $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
             $value = Html::weblink_extract($value);
             $out = "\"" . self::csv_clean($value) . "\"" . $_SESSION["glpicsv_delimiter"];
             break;
         default:
             $out = "<td {$extraparam} valign='top'>";
             if (!preg_match('/' . self::LBHR . '/', $value)) {
                 $values = preg_split('/' . self::LBBR . '/i', $value);
                 $line_delimiter = '<br>';
             } else {
                 $values = preg_split('/' . self::LBHR . '/i', $value);
                 $line_delimiter = '<hr>';
             }
             $limitto = 20;
             if (count($values) > $limitto) {
                 for ($i = 0; $i < $limitto; $i++) {
                     $out .= $values[$i] . $line_delimiter;
                 }
                 //                $rand=mt_rand();
                 $out .= "...&nbsp;";
                 $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
                 $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
                 $out .= Html::showToolTip($value, array('display' => false, 'autoclose' => false));
             } else {
                 $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
                 $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
                 $out .= $value;
             }
             $out .= "</td>\n";
     }
     $num++;
     return $out;
 }
Exemplo n.º 10
0
 /**
  *  Generate ical file content
  *
  * @param $who             user ID
  * @param $who_group       group ID
  * @param $limititemtype   itemtype only display this itemtype (default '')
  *
  * @return icalendar string
  **/
 static function generateIcal($who, $who_group, $limititemtype = '')
 {
     global $CFG_GLPI;
     if ($who === 0 && $who_group === 0) {
         return false;
     }
     if (!empty($CFG_GLPI["version"])) {
         $unique_id = "GLPI-Planning-" . trim($CFG_GLPI["version"]);
     } else {
         $unique_id = "GLPI-Planning-UnknownVersion";
     }
     // create vcalendar
     $vcalendar = new VObject\Component\VCalendar();
     // $xprops = array( "X-LIC-LOCATION" => $tz );
     // iCalUtilityFunctions::createTimezone( $v, $tz, $xprops );
     $interv = array();
     $begin = time() - MONTH_TIMESTAMP * 12;
     $end = time() + MONTH_TIMESTAMP * 12;
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     $params = array('genical' => true, 'who' => $who, 'who_group' => $who_group, 'whogroup' => $who_group, 'begin' => $begin, 'end' => $end);
     $interv = array();
     if (empty($limititemtype)) {
         foreach ($CFG_GLPI['planning_types'] as $itemtype) {
             $interv = array_merge($interv, $itemtype::populatePlanning($params));
         }
     } else {
         $interv = $limititemtype::populatePlanning($params);
     }
     if (count($interv) > 0) {
         foreach ($interv as $key => $val) {
             if (isset($val['itemtype'])) {
                 if (isset($val[getForeignKeyFieldForItemType($val['itemtype'])])) {
                     $uid = $val['itemtype'] . "#" . $val[getForeignKeyFieldForItemType($val['itemtype'])];
                 } else {
                     $uid = "Other#" . $key;
                 }
             } else {
                 $uid = "Other#" . $key;
             }
             $vevent['UID'] = $uid;
             $vevent['DTSTART'] = new \DateTime($val["begin"]);
             $vevent['DTEND'] = new \DateTime($val["end"]);
             if (isset($val["tickets_id"])) {
                 $summary = sprintf(__('Ticket #%1$s %2$s'), $val["tickets_id"], $val["name"]);
             } else {
                 if (isset($val["name"])) {
                     $summary = $val["name"];
                 }
             }
             $vevent['SUMMARY'] = $summary;
             if (isset($val["content"])) {
                 $description = $val["content"];
                 // be sure to replace nl by \r\n
                 $description = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $description);
                 $description = Html::clean($description);
             } else {
                 if (isset($val["name"])) {
                     $description = $val["name"];
                     // be sure to replace nl by \r\n
                     $description = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $description);
                     $description = Html::clean($description);
                 }
             }
             $vevent['DESCRIPTION'] = $description;
             if (isset($val["url"])) {
                 $vevent['URL'] = $val["url"];
             }
             $vcalendar->add('VEVENT', $vevent);
         }
     }
     $output = $vcalendar->serialize();
     $filename = date('YmdHis') . '.ics';
     @Header("Content-Disposition: attachment; filename=\"{$filename}\"");
     @Header("Content-Length: " . Toolbox::strlen($output));
     @Header("Connection: close");
     @Header("content-type: text/calendar; charset=utf-8");
     echo $output;
 }
Exemplo n.º 11
0
function update0713to072()
{
    global $DB, $CFG_GLPI;
    //TRANS: %s is the number of new version
    echo "<h3>" . sprintf(__('Update to %s'), '0.72') . "</h3>";
    displayMigrationMessage("072");
    // Start
    if (!FieldExists("glpi_networking", "recursive", false)) {
        $query = "ALTER TABLE `glpi_networking`\n                ADD `recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `FK_entities`";
        $DB->queryOrDie($query, "0.72 add recursive in glpi_networking");
    }
    if (!FieldExists("glpi_printers", "recursive", false)) {
        $query = "ALTER TABLE `glpi_printers`\n                ADD `recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `FK_entities`";
        $DB->queryOrDie($query, "0.72 add recursive in glpi_printers");
    }
    if (!FieldExists("glpi_links", "FK_entities", false)) {
        $query = "ALTER TABLE `glpi_links`\n                ADD `FK_entities` INT( 11 ) NOT NULL DEFAULT '0' AFTER `ID`";
        $DB->queryOrDie($query, "0.72 add FK_entities in glpi_links");
    }
    if (!FieldExists("glpi_links", "recursive", false)) {
        $query = "ALTER TABLE `glpi_links`\n                ADD `recursive` INT( 1 ) NOT NULL DEFAULT '1' AFTER `FK_entities`";
        $DB->queryOrDie($query, "0.72 add recursive in glpi_links");
    }
    // Clean datetime fields
    $date_fields = array('glpi_docs.date_mod', 'glpi_event_log.date', 'glpi_monitors.date_mod', 'glpi_networking.date_mod', 'glpi_ocs_link.last_update', 'glpi_peripherals.date_mod', 'glpi_phones.date_mod', 'glpi_printers.date_mod', 'glpi_reservation_resa.begin', 'glpi_reservation_resa.end', 'glpi_tracking.closedate', 'glpi_tracking_planning.begin', 'glpi_tracking_planning.end', 'glpi_users.last_login', 'glpi_users.date_mod');
    foreach ($date_fields as $tablefield) {
        displayMigrationMessage("072", "Date format (1) ({$tablefield})");
        list($table, $field) = explode('.', $tablefield);
        if (FieldExists($table, $field, false)) {
            $query = "ALTER TABLE `{$table}`\n                   CHANGE `{$field}` `{$field}` DATETIME NULL";
            $DB->queryOrDie($query, "0.72 alter {$field} in {$table}");
        }
    }
    $date_fields[] = "glpi_computers.date_mod";
    $date_fields[] = "glpi_followups.date";
    $date_fields[] = "glpi_history.date_mod";
    $date_fields[] = "glpi_kbitems.date";
    $date_fields[] = "glpi_kbitems.date_mod";
    $date_fields[] = "glpi_ocs_config.date_mod";
    $date_fields[] = "glpi_ocs_link.last_ocs_update";
    $date_fields[] = "glpi_reminder.date";
    $date_fields[] = "glpi_reminder.begin";
    $date_fields[] = "glpi_reminder.end";
    $date_fields[] = "glpi_reminder.date_mod";
    $date_fields[] = "glpi_software.date_mod";
    $date_fields[] = "glpi_tracking.date";
    $date_fields[] = "glpi_tracking.date_mod";
    $date_fields[] = "glpi_type_docs.date_mod";
    foreach ($date_fields as $tablefield) {
        displayMigrationMessage("072", "Date format (2) ({$tablefield})");
        list($table, $field) = explode('.', $tablefield);
        if (FieldExists($table, $field, false)) {
            $query = "UPDATE `{$table}`\n                   SET `{$field}` = NULL\n                   WHERE `{$field}` = '0000-00-00 00:00:00'";
            $DB->queryOrDie($query, "0.72 update data of {$field} in {$table}");
        }
    }
    // Clean date fields
    $date_fields = array('glpi_infocoms.buy_date', 'glpi_infocoms.use_date');
    foreach ($date_fields as $tablefield) {
        list($table, $field) = explode('.', $tablefield);
        if (FieldExists($table, $field, false)) {
            $query = "ALTER TABLE `{$table}`\n                   CHANGE `{$field}` `{$field}` DATE NULL";
            $DB->queryOrDie($query, "0.72 alter {$field} in {$table}");
        }
    }
    $date_fields[] = "glpi_cartridges.date_in";
    $date_fields[] = "glpi_cartridges.date_use";
    $date_fields[] = "glpi_cartridges.date_out";
    $date_fields[] = "glpi_consumables.date_in";
    $date_fields[] = "glpi_consumables.date_out";
    $date_fields[] = "glpi_contracts.begin_date";
    $date_fields[] = "glpi_licenses.expire";
    foreach ($date_fields as $tablefield) {
        list($table, $field) = explode('.', $tablefield);
        if (FieldExists($table, $field, false)) {
            $query = "UPDATE `{$table}`\n                   SET `{$field}` = NULL\n                   WHERE `{$field}` = '0000-00-00'";
            $DB->queryOrDie($query, "0.72 update data of {$field} in {$table}");
        }
    }
    // Software Updates
    displayMigrationMessage("072", _n('Software', 'Software', 2));
    // Make software recursive
    if (!FieldExists("glpi_software", "recursive", false)) {
        $query = "ALTER TABLE `glpi_software`\n                ADD `recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `FK_entities`";
        $DB->queryOrDie($query, "0.72 add recursive in glpi_software");
    }
    if (!FieldExists("glpi_inst_software", "vID", false)) {
        $query = "ALTER TABLE `glpi_inst_software`\n                CHANGE `license` `vID` INT( 11 ) NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 alter inst_software rename license to vID");
    }
    if (TableExists("glpi_softwarelicenses")) {
        if (TableExists("glpi_softwarelicenses_backup")) {
            $query = "DROP TABLE `glpi_softwarelicenses_backup`";
            $DB->queryOrDie($query, "0.72 drop backup table glpi_softwarelicenses_backup");
        }
        $query = "RENAME TABLE `glpi_softwarelicenses`\n                TO `glpi_softwarelicenses_backup`";
        $DB->queryOrDie($query, "0.72 backup table glpi_softwareversions");
        echo "<span class='b'><p>glpi_softwarelicenses table already exists.\n            A backup have been done to glpi_softwarelicenses_backup.</p>\n            <p>You can delete it if you have no need of it.</p></span>";
    }
    // Create licenses
    if (!TableExists("glpi_softwarelicenses")) {
        $query = "CREATE TABLE `glpi_softwarelicenses` (\n                  `ID` int(11) NOT NULL auto_increment,\n                  `sID` int(11) NOT NULL default '0',\n                  `FK_entities` int(11) NOT NULL default '0',\n                  `recursive` tinyint(1) NOT NULL DEFAULT '0',\n                  `number` int(11) NOT NULL default '0',\n                  `type` int(11) NOT NULL default '0',\n                  `name` varchar(255) NULL default NULL,\n                  `serial` varchar(255) NULL default NULL,\n                  `otherserial` varchar(255) NULL default NULL,\n                  `buy_version` int(11) NOT NULL default '0',\n                  `use_version` int(11) NOT NULL default '0',\n                  `expire` date default NULL,\n                  `FK_computers` int(11) NOT NULL default '0',\n                  `comments` text,\n                  PRIMARY KEY (`ID`),\n                  KEY `name` (`name`),\n                  KEY `type` (`type`),\n                  KEY `sID` (`sID`),\n                  KEY `FK_entities` (`FK_entities`),\n                  KEY `buy_version` (`buy_version`),\n                  KEY `use_version` (`use_version`),\n                  KEY `FK_computers` (`FK_computers`),\n                  KEY `serial` (`serial`),\n                  KEY `otherserial` (`otherserial`),\n                  KEY `expire` (`expire`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create glpi_softwarelicenses");
    }
    if (TableExists("glpi_softwareversions")) {
        if (TableExists("glpi_softwareversions_backup")) {
            $query = "DROP TABLE `glpi_softwareversions_backup`";
            $DB->queryOrDie($query, "0.72 drop backup table glpi_softwareversions_backup");
        }
        $query = "RENAME TABLE `glpi_softwareversions`\n               TO `glpi_softwareversions_backup`";
        $DB->queryOrDie($query, "0.72 backup table glpi_softwareversions");
        echo "<p><span class='b'>glpi_softwareversions table already exists.\n            A backup have been done to glpi_softwareversions_backup.</p><p>\n            You can delete it if you have no need of it.</p></span>";
    }
    if (!TableExists("glpi_softwareversions")) {
        $query = "CREATE TABLE `glpi_softwareversions` (\n                  `ID` int(11) NOT NULL auto_increment,\n                  `sID` int(11) NOT NULL default '0',\n                  `state` int(11) NOT NULL default '0',\n                  `name` varchar(255) NULL default NULL,\n                  `comments` text,\n                  PRIMARY KEY (`ID`),\n                  KEY `sID` (`sID`),\n                  KEY `name` (`name`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create glpi_softwareversions");
    }
    if (TableExists("glpi_licenses")) {
        // Update Infocoms to device_type 9999
        $query = "UPDATE `glpi_infocoms`\n                SET `device_type` = '9999'\n                WHERE `device_type` = '" . SOFTWARELICENSE_TYPE . "'";
        $DB->queryOrDie($query, "0.72 prepare infocoms for update softwares");
        // Foreach software
        $query_softs = "SELECT *\n                      FROM `glpi_software`\n                      ORDER BY `FK_entities`";
        if ($result_softs = $DB->query($query_softs)) {
            $nbsoft = $DB->numrows($result_softs);
            $step = round($nbsoft / 100);
            if (!$step) {
                $step = 1;
            }
            if ($step > 500) {
                $step = 500;
            }
            for ($numsoft = 0; $soft = $DB->fetch_assoc($result_softs); $numsoft++) {
                // To avoid navigator timeout on by DB
                if (!($numsoft % $step)) {
                    displayMigrationMessage("072 ", "Licenses : {$numsoft} / {$nbsoft}");
                }
                // oldstate present if migration run more than once
                if (isset($soft["oldstate"])) {
                    $soft["state"] = $soft["oldstate"];
                }
                // Foreach lics
                $query_versions = "SELECT `glpi_licenses`.*,\n                                      `glpi_infocoms`.`ID` AS infocomID\n                               FROM `glpi_licenses`\n                               LEFT JOIN `glpi_infocoms`\n                                  ON (`glpi_infocoms`.`device_type` = '9999'\n                                      AND `glpi_infocoms`.`FK_device` = `glpi_licenses`.`ID`)\n                               WHERE `sID` = '" . $soft['ID'] . "'\n                               ORDER BY `ID`";
                if ($result_vers = $DB->query($query_versions)) {
                    if ($DB->numrows($result_vers) > 0) {
                        while ($vers = $DB->fetch_assoc($result_vers)) {
                            $install_count = 0;
                            $vers_ID = $vers['ID'];
                            // init : count installations
                            $query_count = "SELECT COUNT(*)\n                                     FROM `glpi_inst_software`\n                                     WHERE `vID` = '" . $vers['ID'] . "'";
                            if ($result_count = $DB->query($query_count)) {
                                $install_count = $DB->result($result_count, 0, 0);
                                $DB->free_result($result_count);
                            }
                            // 1 - Is version already exists ?
                            $query_search_version = "SELECT *\n                                              FROM `glpi_softwareversions`\n                                              WHERE `sID` = '" . $soft['ID'] . "'\n                                                    AND `name` = '" . $vers['version'] . "'";
                            if ($result_searchvers = $DB->query($query_search_version)) {
                                // Version already exists : update inst_software
                                if ($DB->numrows($result_searchvers) == 1) {
                                    $found_vers = $DB->fetch_assoc($result_searchvers);
                                    $vers_ID = $found_vers['ID'];
                                    $query = "UPDATE `glpi_inst_software`\n                                     SET `vID` = '" . $found_vers['ID'] . "'\n                                     WHERE `vID` = '" . $vers['ID'] . "'";
                                    $DB->query($query);
                                } else {
                                    // Re Create new entry
                                    $query = "INSERT INTO `glpi_softwareversions`\n                                            SELECT `ID`, `sID`, '" . $soft["state"] . "', `version`,''\n                                            FROM `glpi_licenses`\n                                            WHERE `ID` = '" . $vers_ID . "'";
                                    $DB->query($query);
                                    // Transfert History for this version
                                    $findstr = " (v. " . $vers['version'] . ")";
                                    // Log event format in 0.71
                                    $findlen = Toolbox::strlen($findstr);
                                    $DB->query("UPDATE `glpi_history`\n                                      SET `FK_glpi_device` = '" . $vers_ID . "',\n                                          `device_type` = '" . SOFTWAREVERSION_TYPE . "'\n                                      WHERE `FK_glpi_device` = '" . $soft['ID'] . "'\n                                            AND `device_type` = '" . SOFTWARE_TYPE . "'\n                                            AND ((`linked_action` = '" . Log::HISTORY_INSTALL_SOFTWARE . "'\n                                                   AND RIGHT(new_value, {$findlen}) = '{$findstr}')\n                                                 OR (`linked_action` = '" . Log::HISTORY_UNINSTALL_SOFTWARE . "'\n                                                      AND RIGHT(old_value, {$findlen}) = '{$findstr}'))");
                                }
                                $DB->free_result($result_searchvers);
                            }
                            // 2 - Create glpi_licenses
                            if ($vers['buy'] || !empty($vers['serial']) && !in_array($vers['serial'], array('free', 'global')) || !empty($vers['comments']) || !empty($vers['expire']) || $vers['oem_computer'] > 0 || !empty($vers['infocomID'])) {
                                // with and infocoms
                                $found_lic = -1;
                                // No infocoms try to find already exists license
                                if (empty($vers['infocomID'])) {
                                    $query_search_lic = "SELECT `ID`\n                                                FROM `glpi_softwarelicenses`\n                                                WHERE `buy_version` = '{$vers_ID}'\n                                                      AND `serial` = '" . $vers['serial'] . "'\n                                                      AND `FK_computers` = '" . $vers['oem_computer'] . "'\n                                                      AND `comments` = '" . $vers['comments'] . "'";
                                    if (empty($vers['expire'])) {
                                        $query .= " AND `expire` IS NULL";
                                    } else {
                                        $query .= " AND `expire` = '" . $vers['expire'] . "'";
                                    }
                                    if ($result_searchlic = $DB->query($query_search_lic)) {
                                        if ($DB->numrows($result_searchlic) > 0) {
                                            $found_lic = $DB->result($result_searchlic, 0, 0);
                                            $DB->free_result($result_searchlic);
                                        }
                                    }
                                }
                                if ($install_count == 0) {
                                    $install_count = 1;
                                    // license exists so count 1
                                }
                                // Found license : merge with found one
                                if ($found_lic > 0) {
                                    $query = "UPDATE `glpi_softwarelicenses`\n                                     SET `number` = `number`+1\n                                     WHERE `ID` = '{$found_lic}'";
                                    $DB->query($query);
                                } else {
                                    // Create new license
                                    if (empty($vers['expire'])) {
                                        $vers['expire'] = 'NULL';
                                    } else {
                                        $vers['expire'] = "'" . $vers['expire'] . "'";
                                    }
                                    $query = "INSERT INTO `glpi_softwarelicenses`\n                                            (`sID` ,`FK_entities`,\n                                             `number` ,`type` ,`name` ,\n                                             `serial` ,`buy_version`,\n                                             `use_version`, `expire`,\n                                             `FK_computers` ,\n                                             `comments`)\n                                     VALUES ('" . $soft['ID'] . "', '" . $soft["FK_entities"] . "',\n                                             {$install_count}, 0, '" . $vers['serial'] . "',\n                                             '" . addslashes($vers['serial']) . "' , '{$vers_ID}',\n                                             '{$vers_ID}', " . $vers['expire'] . ",\n                                             '" . $vers['oem_computer'] . "',\n                                             '" . addslashes($vers['comments']) . "')";
                                    if ($DB->query($query)) {
                                        $lic_ID = $DB->insert_id();
                                        // Update infocoms link
                                        if (!empty($vers['infocomID'])) {
                                            $query = "UPDATE `glpi_infocoms`\n                                           SET `device_type` = '" . SOFTWARELICENSE_TYPE . "',\n                                               `FK_device` = '{$lic_ID}'\n                                           WHERE `device_type` = '9999'\n                                                 AND `FK_device` = '" . $vers['ID'] . "'";
                                            $DB->query($query);
                                        }
                                    }
                                }
                                // Create licence
                            }
                            // Buy licence
                        }
                        // Each license
                    }
                    // while
                    $DB->free_result($result_vers);
                }
                // Clean History for this software (old versions no more installed)
                $DB->query("DELETE\n                        FROM `glpi_history`\n                        WHERE `FK_glpi_device` = '" . $soft['ID'] . "'\n                              AND `device_type` = '" . SOFTWARE_TYPE . "'\n                              AND (`linked_action` = '" . Log::HISTORY_INSTALL_SOFTWARE . "'\n                                   OR `linked_action` = '" . Log::HISTORY_UNINSTALL_SOFTWARE . "')");
            }
            // For
        }
        // Each Software
        $query = "DROP TABLE `glpi_licenses`";
        $DB->queryOrDie($query, "0.72 drop table glpi_licenses");
        // Drop alerts on licenses : 2 = Alert::END
        $query = "DELETE\n                FROM `glpi_alerts`\n                WHERE `glpi_alerts`.`device_type` = '" . SOFTWARELICENSE_TYPE . "'\n                      AND `glpi_alerts`.`type` = '2'";
        $DB->queryOrDie($query, "0.72 clean alerts for licenses infocoms");
    }
    // TableExists("glpi_licenses")
    // Change software search pref
    $query = "SELECT DISTINCT `FK_users`\n             FROM `glpi_display`\n             WHERE `type` = '" . SOFTWARE_TYPE . "'";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0) {
            while ($data = $DB->fetch_assoc($result)) {
                $query = "SELECT max(`rank`)\n                      FROM `glpi_display`\n                      WHERE `FK_users` = '" . $data['FK_users'] . "'\n                            AND `type` = '" . SOFTWARE_TYPE . "'";
                $result = $DB->query($query);
                $rank = $DB->result($result, 0, 0);
                $rank++;
                $query = "SELECT *\n                      FROM `glpi_display`\n                      WHERE `FK_users` = '" . $data['FK_users'] . "'\n                            AND `num` = '72'\n                            AND `type` = '" . SOFTWARE_TYPE . "'";
                if ($result2 = $DB->query($query)) {
                    if ($DB->numrows($result2) == 0) {
                        $query = "INSERT INTO `glpi_display`\n                                   (`type` ,`num` ,`rank` ,\n                                    `FK_users`)\n                            VALUES ('" . SOFTWARE_TYPE . "', '72', '" . $rank++ . "',\n                                    '" . $data['FK_users'] . "')";
                        $DB->query($query);
                    }
                }
                $query = "SELECT *\n                      FROM `glpi_display`\n                      WHERE `FK_users` = '" . $data['FK_users'] . "'\n                            AND `num` = '163'\n                            AND `type` = '" . SOFTWARE_TYPE . "'";
                if ($result2 = $DB->query($query)) {
                    if ($DB->numrows($result2) == 0) {
                        $query = "INSERT INTO `glpi_display`\n                                   (`type` ,`num` ,`rank` ,\n                                    `FK_users`)\n                            VALUES ('" . SOFTWARE_TYPE . "', '163', '" . $rank++ . "',\n                                    '" . $data['FK_users'] . "');";
                        $DB->query($query);
                    }
                }
            }
        }
    }
    displayMigrationMessage("072", _n('Software', 'Software', 2));
    // If migration run more than once
    if (!FieldExists("glpi_softwareversions", "state", false)) {
        $query = "ALTER TABLE `glpi_softwareversions`\n                ADD `state` INT NOT NULL DEFAULT '0' AFTER `sID`";
        $DB->queryOrDie($query, "0.72 add state to softwareversion table");
    }
    // To allow migration to be run more than once
    if (FieldExists("glpi_software", "state", false)) {
        $query = "ALTER TABLE `glpi_software`\n                CHANGE `state` `oldstate` INT( 11 ) NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 change state to to oldtsate in softwareversion table");
    }
    if (!TableExists("glpi_dropdown_licensetypes")) {
        $query = "CREATE TABLE `glpi_dropdown_licensetypes` (\n                  `ID` int(11) NOT NULL auto_increment,\n                  `name` varchar(255) NULL default NULL,\n                  `comments` text,\n                  PRIMARY KEY (`ID`),\n                  KEY `name` (`name`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create glpi_dropdown_licensetypes table");
        $input["tablename"] = "glpi_dropdown_licensetypes";
        $input["value"] = "OEM";
        $input['type'] = "first";
        $input["comment"] = "";
        $input["entities_id"] = -1;
        $query = "INSERT INTO `glpi_dropdown_licensetypes`\n                       (`name`)\n                VALUES ('OEM')";
        if ($result = $DB->query($query)) {
            $oemtype = $DB->insert_id();
            $query = "UPDATE `glpi_softwarelicenses`\n                      SET `type` = '{$oemtype}'\n                      WHERE `FK_computers` > '0'";
            $DB->queryOrDie($query, "0.72 affect OEM as licensetype");
        }
    }
    displayMigrationMessage("072", _n('User', 'Users', 2));
    if (!FieldExists("glpi_groups", "recursive", false)) {
        $query = "ALTER TABLE `glpi_groups`\n                ADD `recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `FK_entities`";
        $DB->queryOrDie($query, "0.72 add recursive in glpi_groups");
    }
    if (!FieldExists("glpi_auth_ldap", "ldap_field_title", false)) {
        $query = "ALTER TABLE `glpi_auth_ldap`\n                ADD `ldap_field_title` VARCHAR( 255 ) DEFAULT NULL ";
        $DB->queryOrDie($query, "0.72 add ldap_field_title in glpi_auth_ldap");
    }
    //Add user title retrieval from LDAP
    if (!TableExists("glpi_dropdown_user_titles")) {
        $query = "CREATE TABLE `glpi_dropdown_user_titles` (\n                  `ID` int( 11 ) NOT NULL AUTO_INCREMENT ,\n                  `name` varchar( 255 ) NULL default NULL ,\n                  `comments` text ,\n                  PRIMARY KEY ( `ID` ) ,\n                  KEY `name` (`name`)\n                ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create glpi_dropdown_user_titles table");
    }
    if (!FieldExists("glpi_users", "title", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `title` INT( 11 ) NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 add title in glpi_users");
    }
    if (!isIndex("glpi_users", "title")) {
        $query = " ALTER TABLE `glpi_users`\n                ADD INDEX `title` (`title`)";
        $DB->queryOrDie($query, "0.72 add index on title in glpi_users");
    }
    if (!FieldExists("glpi_auth_ldap", "ldap_field_type", false)) {
        $query = "ALTER TABLE `glpi_auth_ldap`\n                ADD `ldap_field_type` VARCHAR( 255 ) DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add ldap_field_title in glpi_auth_ldap");
    }
    //Add user type retrieval from LDAP
    if (!TableExists("glpi_dropdown_user_types")) {
        $query = "CREATE TABLE `glpi_dropdown_user_types` (\n                  `ID` int( 11 ) NOT NULL AUTO_INCREMENT,\n                  `name` varchar( 255 ) NULL default NULL,\n                  `comments` text,\n                  PRIMARY KEY (`ID`),\n                  KEY `name` (`name`)\n                ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create glpi_dropdown_user_types table");
    }
    if (!FieldExists("glpi_users", "type", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `type` INT( 11 ) NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 add type in glpi_users");
    }
    if (!isIndex("glpi_users", "type")) {
        $query = " ALTER TABLE `glpi_users`\n                 ADD INDEX `type` (`type`)";
        $DB->queryOrDie($query, "0.72 add index on type in glpi_users");
    }
    if (!isIndex("glpi_users", "active")) {
        $query = " ALTER TABLE `glpi_users`\n                 ADD INDEX `active` (`active`)";
        $DB->queryOrDie($query, "0.72 add index on active in glpi_users");
    }
    if (!FieldExists("glpi_auth_ldap", "ldap_field_language", false)) {
        $query = "ALTER TABLE `glpi_auth_ldap`\n                ADD `ldap_field_language` VARCHAR( 255 ) NULL DEFAULT NULL ";
        $DB->queryOrDie($query, "0.72 add ldap_field_language in glpi_auth_ldap");
    }
    if (!FieldExists("glpi_ocs_config", "tag_exclude", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                ADD `tag_exclude` VARCHAR( 255 ) NULL AFTER `tag_limit`";
        $DB->queryOrDie($query, "0.72 add tag_exclude in glpi_ocs_config");
    }
    if (!FieldExists("glpi_config", "cache_max_size", false)) {
        $query = "ALTER TABLE `glpi_config`\n                ADD `cache_max_size` INT( 11 ) NOT NULL DEFAULT '20' AFTER `use_cache`";
        $DB->queryOrDie($query, "0.72 add cache_max_size in glpi_config");
    }
    displayMigrationMessage("072", _n('Volume', 'Volumes', 2));
    if (!TableExists("glpi_dropdown_filesystems")) {
        $query = "CREATE TABLE `glpi_dropdown_filesystems` (\n                  `ID` int(11) NOT NULL auto_increment,\n                  `name` varchar(255) NULL default NULL,\n                  `comments` text ,\n                  PRIMARY KEY (`ID`),\n                  KEY `name` (`name`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create glpi_dropdown_filesystems table");
        $fstype = array('ext', 'ext2', 'ext3', 'ext4', 'FAT', 'FAT32', 'VFAT', 'HFS', 'HPFS', 'HTFS', 'JFS', 'JFS2', 'NFS', 'NTFS', 'ReiserFS', 'SMBFS', 'UDF', 'UFS', 'XFS', 'ZFS');
        foreach ($fstype as $fs) {
            $query = "INSERT INTO `glpi_dropdown_filesystems`\n                         (`name`)\n                   VALUES ('{$fs}')";
            $DB->queryOrDie($query, "0.72 add filesystems type");
        }
    }
    if (!TableExists("glpi_computerdisks")) {
        $query = "CREATE TABLE `glpi_computerdisks` (\n                  `ID` int(11) NOT NULL auto_increment,\n                  `FK_computers` int(11) NOT NULL default 0,\n                  `name` varchar(255)  NULL default NULL,\n                  `device` varchar(255) NULL default NULL,\n                  `mountpoint` varchar(255) NULL default NULL,\n                  `FK_filesystems` int(11) NOT NULL default 0,\n                  `totalsize` int(11) NOT NULL default 0,\n                  `freesize` int(11) NOT NULL default 0,\n                  PRIMARY KEY  (`ID`),\n                  KEY `name` (`name`),\n                  KEY `FK_filesystems` (`FK_filesystems`),\n                  KEY `FK_computers` (`FK_computers`),\n                  KEY `device` (`device`),\n                  KEY `mountpoint` (`mountpoint`),\n                  KEY `totalsize` (`totalsize`),\n                  KEY `freesize` (`freesize`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create glpi_computerfilesystems table");
    }
    if (!FieldExists("glpi_ocs_config", "import_disk", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                ADD `import_disk` INT( 2 ) NOT NULL DEFAULT '0' AFTER `import_ip`";
        $DB->queryOrDie($query, "0.72 add import_disk in glpi_ocs_config");
    }
    if (!FieldExists("glpi_ocs_link", "import_disk", false)) {
        $query = "ALTER TABLE `glpi_ocs_link`\n                ADD `import_disk` LONGTEXT NULL AFTER `import_device`";
        $DB->queryOrDie($query, "0.72 add import_device in glpi_ocs_link");
    }
    // Clean software ocs
    if (FieldExists("glpi_ocs_config", "import_software_buy", false)) {
        $query = " ALTER TABLE `glpi_ocs_config`\n                 DROP `import_software_buy`";
        $DB->queryOrDie($query, "0.72 drop import_software_buy in glpi_ocs_config");
    }
    if (FieldExists("glpi_ocs_config", "import_software_licensetype", false)) {
        $query = " ALTER TABLE `glpi_ocs_config`\n                 DROP `import_software_licensetype`";
        $DB->queryOrDie($query, "0.72 drop import_software_licensetype in glpi_ocs_config");
    }
    //// Clean interface use for GFX card
    // Insert default values
    update_importDropdown("glpi_dropdown_interface", "AGP");
    update_importDropdown("glpi_dropdown_interface", "PCI");
    update_importDropdown("glpi_dropdown_interface", "PCIe");
    update_importDropdown("glpi_dropdown_interface", "PCI-X");
    if (!FieldExists("glpi_device_gfxcard", "FK_interface", false)) {
        $query = "ALTER TABLE `glpi_device_gfxcard`\n                ADD `FK_interface` INT NOT NULL DEFAULT '0' AFTER `interface` ";
        $DB->queryOrDie($query, "0.72 alter glpi_device_gfxcard add new field interface");
        // Get all data from interface_old / Insert in glpi_dropdown_interface if needed
        $query = "SELECT DISTINCT `interface` AS OLDNAME\n                FROM `glpi_device_gfxcard`";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                while ($data = $DB->fetch_assoc($result)) {
                    $data = Toolbox::addslashes_deep($data);
                    // Update datas
                    if ($newID = update_importDropdown("glpi_dropdown_interface", $data['OLDNAME'])) {
                        $query2 = "UPDATE `glpi_device_gfxcard`\n                             SET `FK_interface` = '{$newID}'\n                             WHERE `interface` = '" . $data['OLDNAME'] . "'";
                        $DB->queryOrDie($query2, "0.72 update glpi_device_gfxcard set new interface value");
                    }
                }
            }
        }
        $query = "ALTER TABLE `glpi_device_gfxcard`\n                DROP `interface` ";
        $DB->queryOrDie($query, "0.72 alter {$table} drop tmp enum field");
    }
    if (!FieldExists("glpi_config", "existing_auth_server_field_clean_domain", false)) {
        $query = "ALTER TABLE `glpi_config`\n                ADD `existing_auth_server_field_clean_domain` SMALLINT NOT NULL DEFAULT '0'\n                                                              AFTER `existing_auth_server_field`";
        $DB->queryOrDie($query, "0.72 alter config add existing_auth_server_field_clean_domain");
    }
    if (FieldExists("glpi_profiles", "contract_infocom", false)) {
        $query = "ALTER TABLE `glpi_profiles`\n                CHANGE `contract_infocom` `contract` CHAR( 1 ) NULL DEFAULT NULL ";
        $DB->queryOrDie($query, "0.72 alter profiles rename contract_infocom to contract");
        $query = "ALTER TABLE `glpi_profiles`\n                ADD `infocom` CHAR( 1 ) NULL DEFAULT NULL AFTER `contract`";
        $DB->queryOrDie($query, "0.72 alter profiles create infocom");
        $query = "UPDATE `glpi_profiles`\n                SET `infocom` = `contract`";
        $DB->queryOrDie($query, "0.72 update data for infocom in profiles");
    }
    // Debug mode in user pref to allow debug in production environment
    if (FieldExists("glpi_config", "debug", false)) {
        $query = "ALTER TABLE `glpi_config`\n                DROP `debug`";
        $DB->queryOrDie($query, "0.72 drop debug mode in config");
    }
    if (!FieldExists("glpi_users", "use_mode", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `use_mode` SMALLINT NOT NULL DEFAULT '0' AFTER `language`";
        $DB->queryOrDie($query, "0.72 create use_mode in glpi_users");
    }
    // Default bookmark as default view
    if (!TableExists("glpi_display_default")) {
        $query = "CREATE TABLE IF NOT EXISTS `glpi_display_default` (\n                  `ID` int(11) NOT NULL auto_increment,\n                  `FK_users` int(11) NOT NULL,\n                  `device_type` int(11) NOT NULL,\n                  `FK_bookmark` int(11) NOT NULL,\n                  PRIMARY KEY (`ID`),\n                  UNIQUE KEY `FK_users` (`FK_users`,`device_type`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create table glpi_display_default");
    }
    // Correct cost contract data type
    if (FieldExists("glpi_contracts", "cost", false)) {
        $query = " ALTER TABLE `glpi_contracts`\n               CHANGE `cost` `cost` DECIMAL( 20, 4 ) NOT NULL DEFAULT '0.0000'";
        $DB->queryOrDie($query, "0.72 alter contract cost data type");
    }
    // Plugins table
    if (!TableExists("glpi_plugins")) {
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugins` (\n                  `ID` int(11) NOT NULL auto_increment,\n                  `directory` varchar(255) NOT NULL,\n                  `name` varchar(255)  NOT NULL,\n                  `version` varchar(255)  NOT NULL,\n                  `state` tinyint(4) NOT NULL default '0',\n                  `author` varchar(255) NULL default NULL,\n                  `homepage` varchar(255) NULL default NULL,\n                  PRIMARY KEY (`ID`),\n                  UNIQUE KEY `name` (`directory`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, "0.72 create table glpi_plugins");
    }
    //// CORRECT glpi_config field type
    if (FieldExists("glpi_config", "num_of_events", false)) {
        $query = "ALTER TABLE `glpi_config`\n                CHANGE `num_of_events` `num_of_events` INT( 11 ) NOT NULL DEFAULT '10'";
        $DB->queryOrDie($query, "0.72 alter config num_of_events");
    }
    if (FieldExists("glpi_config", "jobs_at_login", false)) {
        $query = "ALTER TABLE `glpi_config`\n                CHANGE `jobs_at_login` `jobs_at_login` SMALLINT( 6 ) NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 alter config jobs_at_login");
    }
    if (FieldExists("glpi_config", "cut", false)) {
        $query = "UPDATE `glpi_config`\n                SET `cut` = ROUND(`cut`/50)*50";
        $DB->queryOrDie($query, "0.72 update config cut value to prepare update");
        $query = "ALTER TABLE `glpi_config`\n                CHANGE `cut` `cut` INT( 11 ) NOT NULL DEFAULT '255'";
        $DB->queryOrDie($query, "0.72 alter config cut");
    }
    if (FieldExists("glpi_config", "list_limit", false)) {
        $query = "ALTER TABLE `glpi_config`\n                CHANGE `list_limit` `list_limit` INT( 11 ) NOT NULL DEFAULT '20'";
        $DB->queryOrDie($query, "0.72 alter config list_limit");
    }
    if (FieldExists("glpi_config", "expire_events", false)) {
        $query = "ALTER TABLE `glpi_config`\n                CHANGE `expire_events` `expire_events` INT( 11 ) NOT NULL DEFAULT '30'";
        $DB->queryOrDie($query, "0.72 alter config expire_events");
    }
    if (FieldExists("glpi_config", "event_loglevel", false)) {
        $query = "ALTER TABLE `glpi_config`\n                CHANGE `event_loglevel` `event_loglevel` SMALLINT( 6 ) NOT NULL DEFAULT '5'";
        $DB->queryOrDie($query, "0.72 alter config event_loglevel");
    }
    if (FieldExists("glpi_config", "permit_helpdesk", false)) {
        $query = "UPDATE `glpi_config`\n                SET `permit_helpdesk` = '0'\n                WHERE `permit_helpdesk` = ''";
        $DB->queryOrDie($query, "0.72 update config permit_helpdesk value to prepare update");
        $query = "ALTER TABLE `glpi_config`\n                CHANGE `permit_helpdesk` `permit_helpdesk` SMALLINT NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 alter config permit_helpdesk");
    }
    if (!FieldExists("glpi_config", "language", false)) {
        $query = "ALTER TABLE `glpi_config`\n                CHANGE `default_language` `language` VARCHAR( 255 ) NULL DEFAULT 'en_GB'";
        $DB->queryOrDie($query, "0.72 alter config default_language");
    }
    if (!FieldExists("glpi_config", "tracking_order", false)) {
        $query = "ALTER TABLE `glpi_config`\n                ADD `tracking_order` SMALLINT NOT NULL default '0'";
        $DB->queryOrDie($query, "0.72 alter config add tracking_order");
    }
    if (!FieldExists("glpi_users", "dateformat", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `dateformat` SMALLINT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add dateformat in users");
    }
    if (FieldExists("glpi_users", "list_limit", false)) {
        $query = "ALTER TABLE `glpi_users`\n                CHANGE `list_limit` `list_limit` INT( 11 ) NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 alter list_limit in users");
    }
    if (FieldExists("glpi_users", "tracking_order", false)) {
        $query = "ALTER TABLE `glpi_users`\n                CHANGE `tracking_order` `tracking_order` SMALLINT( 6 ) NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 alter tracking_order in users");
    }
    if (!FieldExists("glpi_users", "numberformat", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `numberformat` SMALLINT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add numberformat in users");
    }
    if (!FieldExists("glpi_users", "view_ID", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `view_ID` SMALLINT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add view_ID in users");
    }
    if (!FieldExists("glpi_users", "dropdown_limit", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `dropdown_limit` INT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add dropdown_limit in users");
    }
    if (!FieldExists("glpi_users", "flat_dropdowntree", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `flat_dropdowntree` SMALLINT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add flat_dropdowntree in users");
    }
    if (!FieldExists("glpi_users", "num_of_events", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `num_of_events` INT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add num_of_events in users");
    }
    if (!FieldExists("glpi_users", "nextprev_item", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `nextprev_item` VARCHAR( 255 ) NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add nextprev_item in users");
    }
    if (!FieldExists("glpi_users", "jobs_at_login", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `jobs_at_login` SMALLINT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add jobs_at_login in users");
    }
    if (!FieldExists("glpi_users", "priority_1", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `priority_1` VARCHAR( 255 ) NULL DEFAULT NULL,\n                ADD `priority_2` VARCHAR( 255 ) NULL DEFAULT NULL,\n                ADD `priority_3` VARCHAR( 255 ) NULL DEFAULT NULL,\n                ADD `priority_4` VARCHAR( 255 ) NULL DEFAULT NULL,\n                ADD `priority_5` VARCHAR( 255 ) NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add priority_X in users");
    }
    if (!FieldExists("glpi_users", "expand_soft_categorized", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `expand_soft_categorized` INT( 1 ) NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add expand_soft_categorized in users");
    }
    if (!FieldExists("glpi_users", "expand_soft_not_categorized", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `expand_soft_not_categorized` INT( 1 ) NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add expand_soft_not_categorized in users");
    }
    if (!FieldExists("glpi_users", "followup_private", false)) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `followup_private` SMALLINT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72 add followup_private in users");
    }
    if (!FieldExists("glpi_config", "followup_private", false)) {
        $query = "ALTER TABLE `glpi_config`\n                ADD `followup_private` SMALLINT NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 add followup_private in config");
    }
    // INDEX key order change
    if (isIndex("glpi_contract_device", "FK_contract")) {
        $query = "ALTER TABLE `glpi_contract_device`\n                DROP INDEX `FK_contract`";
        $DB->queryOrDie($query, "0.72 drop index FK_contract on glpi_contract_device");
    }
    if (!isIndex("glpi_contract_device", "FK_contract_device")) {
        $query = "ALTER TABLE `glpi_contract_device`\n                ADD UNIQUE INDEX `FK_contract_device` (`FK_contract` , `device_type`, `FK_device` )";
        $DB->queryOrDie($query, "0.72 add index FK_contract_device in glpi_contract_device");
    }
    if (isIndex("glpi_doc_device", "FK_doc")) {
        $query = "ALTER TABLE `glpi_doc_device`\n                DROP INDEX `FK_doc`";
        $DB->queryOrDie($query, "0.72 drop index FK_doc on glpi_doc_device");
    }
    if (!isIndex("glpi_doc_device", "FK_doc_device")) {
        $query = "ALTER TABLE `glpi_doc_device`\n                ADD UNIQUE INDEX `FK_doc_device` (`FK_doc` , `device_type`, `FK_device` )";
        $DB->queryOrDie($query, "0.72 add index FK_doc_device in glpi_doc_device");
    }
    //(AD) DistinguishedName criteria is wrong. DN in AD is not distinguishedName but DN.
    $query = "SELECT `ID`\n             FROM `glpi_rules_ldap_parameters`\n             WHERE `value` = 'distinguishedname'";
    $result = $DB->query($query);
    //If (AD) DistinguishedName criteria is still present
    if ($DB->numrows($result) == 1) {
        $query = "SELECT COUNT(`ID`) AS cpt\n                FROM `glpi_rules_criterias`\n                WHERE `criteria` = 'distinguishedname'";
        $result = $DB->query($query);
        if ($DB->result($result, 0, "cpt") > 0) {
            echo "<div class='center spaced'>";
            echo "<span class='red'>LDAP Criteria (AD)Distinguishedname must be removed.<br>" . "As it is used in one or more LDAP rules, you need to remove it manually</span>";
            echo "</div><br>";
        } else {
            //Delete If (AD) DistinguishedName criteria
            $query = "DELETE\n                   FROM `glpi_rules_ldap_parameters`\n                   WHERE `value` = 'distinguishedname'";
            $result = $DB->query($query);
        }
    }
    //// Clean DB
    if (isIndex("glpi_alerts", "item") && isIndex("glpi_alerts", "alert")) {
        $query = "ALTER TABLE `glpi_alerts`\n                DROP INDEX `item`";
        $DB->queryOrDie($query, "0.72 drop item index on glpi_alerts");
    }
    if (isIndex("glpi_alerts", "device_type") && isIndex("glpi_alerts", "alert")) {
        $query = "ALTER TABLE `glpi_alerts`\n                DROP INDEX `device_type`";
        $DB->queryOrDie($query, "0.72 drop device_type index on glpi_alerts");
    }
    if (isIndex("glpi_cartridges_assoc", "FK_glpi_type_printer_2") && isIndex("glpi_cartridges_assoc", "FK_glpi_type_printer")) {
        $query = "ALTER TABLE `glpi_cartridges_assoc`\n                DROP INDEX `FK_glpi_type_printer_2`";
        $DB->queryOrDie($query, "0.72 drop FK_glpi_type_printer_2 index on glpi_cartridges_assoc");
    }
    if (isIndex("glpi_computer_device", "device_type") && isIndex("glpi_computer_device", "device_type_2")) {
        $query = "ALTER TABLE `glpi_computer_device`\n                DROP INDEX `device_type`";
        $DB->queryOrDie($query, "0.72 drop device_type index on glpi_computer_device");
        $query = "ALTER TABLE `glpi_computer_device`\n                DROP INDEX `device_type_2`,\n                ADD INDEX `device_type` (`device_type` , `FK_device`) ";
        $DB->queryOrDie($query, "0.72 rename device_type_2 index on glpi_computer_device");
    }
    if (isIndex("glpi_connect_wire", "end1") && isIndex("glpi_connect_wire", "end1_1")) {
        $query = "ALTER TABLE `glpi_connect_wire`\n                DROP INDEX `end1`";
        $DB->queryOrDie($query, "0.72 drop end1 index on glpi_connect_wire");
        $query = "ALTER TABLE `glpi_connect_wire`\n                DROP INDEX `end1_1`,\n                ADD UNIQUE `connect` (`end1` , `end2` , `type`)";
        $DB->queryOrDie($query, "0.72 rename end1_1 index on glpi_connect_wire");
    }
    if (isIndex("glpi_contract_enterprise", "FK_enterprise") && isIndex("glpi_contract_enterprise", "FK_enterprise_2")) {
        $query = "ALTER TABLE `glpi_contract_enterprise`\n                DROP INDEX `FK_enterprise_2`";
        $DB->queryOrDie($query, "0.72 drop FK_enterprise_2 index on glpi_contract_enterprise");
    }
    if (isIndex("glpi_contact_enterprise", "FK_enterprise") && isIndex("glpi_contact_enterprise", "FK_enterprise_2")) {
        $query = "ALTER TABLE `glpi_contact_enterprise`\n                DROP INDEX `FK_enterprise_2`";
        $DB->queryOrDie($query, "0.72 drop FK_enterprise_2 index on glpi_contact_enterprise");
    }
    if (isIndex("glpi_contract_device", "FK_contract_2") && isIndex("glpi_contract_device", "FK_contract_device")) {
        $query = "ALTER TABLE `glpi_contract_device`\n                DROP INDEX `FK_contract_2`";
        $DB->queryOrDie($query, "0.72 drop FK_contract_2 index on glpi_contract_device");
    }
    if (isIndex("glpi_display", "type") && isIndex("glpi_display", "type_2")) {
        $query = "ALTER TABLE `glpi_display`\n                DROP INDEX `type`";
        $DB->queryOrDie($query, "0.72 drop type index on glpi_display");
        $query = "ALTER TABLE `glpi_display`\n                DROP INDEX `type_2`,\n                ADD UNIQUE `display` (`type` , `num` , `FK_users`)";
        $DB->queryOrDie($query, "0.72 rename type_2 index on glpi_display");
    }
    if (isIndex("glpi_doc_device", "FK_doc_2") && isIndex("glpi_doc_device", "FK_doc_device")) {
        $query = "ALTER TABLE `glpi_doc_device`\n                DROP INDEX `FK_doc_2`";
        $DB->queryOrDie($query, "0.72 drop FK_doc_2 index on glpi_doc_device");
    }
    if (isIndex("glpi_links_device", "device_type") && isIndex("glpi_links_device", "device_type_2")) {
        $query = "ALTER TABLE `glpi_links_device`\n                DROP INDEX `device_type`";
        $DB->queryOrDie($query, "0.72 drop device_type index on glpi_links_device");
        $query = "ALTER TABLE `glpi_links_device`\n                DROP INDEX `device_type_2`,\n                ADD UNIQUE `link` (`device_type` , `FK_links`)";
        $DB->queryOrDie($query, "0.72 rename device_type_2 index on glpi_links_device");
    }
    if (isIndex("glpi_mailing", "item_type") && isIndex("glpi_mailing", "items")) {
        $query = "ALTER TABLE `glpi_mailing`\n                DROP INDEX `item_type`";
        $DB->queryOrDie($query, "0.72 drop item_type index on glpi_mailing");
    }
    if (isIndex("glpi_mailing", "type") && isIndex("glpi_mailing", "mailings")) {
        $query = "ALTER TABLE `glpi_mailing`\n                DROP INDEX `type`";
        $DB->queryOrDie($query, "0.72 drop type index on glpi_mailing");
    }
    if (isIndex("glpi_networking_ports", "on_device_2") && isIndex("glpi_networking_ports", "on_device")) {
        $query = "ALTER TABLE `glpi_networking_ports`\n                DROP INDEX `on_device_2`";
        $DB->queryOrDie($query, "0.72 drop on_device_2 index on glpi_networking_ports");
    }
    if (isIndex("glpi_networking_vlan", "FK_port") && isIndex("glpi_networking_vlan", "FK_port_2")) {
        $query = "ALTER TABLE `glpi_networking_vlan`\n                DROP INDEX `FK_port`";
        $DB->queryOrDie($query, "0.72 drop FK_port index on glpi_networking_vlan");
        $query = "ALTER TABLE `glpi_networking_vlan`\n                DROP INDEX `FK_port_2`,\n                ADD UNIQUE `portvlan` (`FK_port`, `FK_vlan`)";
        $DB->queryOrDie($query, "0.72 rename FK_port_2 index on glpi_networking_vlan");
    }
    if (isIndex("glpi_networking_wire", "end1") && isIndex("glpi_networking_wire", "end1_1")) {
        $query = "ALTER TABLE `glpi_networking_wire`\n                DROP INDEX `end1`";
        $DB->queryOrDie($query, "0.72 drop end1 index on glpi_networking_wire");
        $query = "ALTER TABLE `glpi_networking_wire`\n                DROP INDEX `end1_1`,\n                ADD UNIQUE `netwire` (`end1`, `end2`)";
        $DB->queryOrDie($query, "0.72 rename end1_1 index on glpi_networking_wire");
    }
    if (isIndex("glpi_reservation_item", "device_type") && isIndex("glpi_reservation_item", "device_type_2")) {
        $query = "ALTER TABLE `glpi_reservation_item`\n                DROP INDEX `device_type`";
        $DB->queryOrDie($query, "0.72 drop device_type index on glpi_reservation_item");
        $query = "ALTER TABLE `glpi_reservation_item`\n                DROP INDEX `device_type_2`,\n                ADD INDEX `reservationitem` (`device_type`, `id_device`)";
        $DB->queryOrDie($query, "0.72 rename device_type_2 index on glpi_reservation_item");
    }
    if (isIndex("glpi_users_groups", "FK_users") && isIndex("glpi_users_groups", "FK_users_2")) {
        $query = "ALTER TABLE `glpi_users_groups`\n                DROP INDEX `FK_users_2`";
        $DB->queryOrDie($query, "0.72 drop FK_users_2 index on glpi_users_groups");
        $query = "ALTER TABLE `glpi_users_groups`\n                DROP INDEX `FK_users`,\n                ADD UNIQUE `usergroup` (`FK_users`, `FK_groups`)";
        $DB->queryOrDie($query, "0.72 rename FK_users index on glpi_users_groups");
    }
    if (!FieldExists("glpi_config", "software_helpdesk_visible", false)) {
        $query = " ALTER TABLE `glpi_config`\n                 ADD `software_helpdesk_visible` INT(1) NOT NULL DEFAULT '1'";
        $DB->queryOrDie($query, "0.72 add software_helpdesk_visible in config");
    }
    if (!FieldExists("glpi_entities_data", "ldap_dn", false)) {
        $query = "ALTER TABLE `glpi_entities_data`\n                ADD `ldap_dn` VARCHAR( 255 ) NULL";
        $DB->queryOrDie($query, "0.72 add ldap_dn in config");
    }
    if (!FieldExists("glpi_entities_data", "tag", false)) {
        $query = "ALTER TABLE `glpi_entities_data`\n                ADD `tag` VARCHAR( 255 ) NULL";
        $DB->queryOrDie($query, "0.72 add tag in config");
    }
    if (FieldExists("glpi_rules_ldap_parameters", "rule_type", false)) {
        $query = "ALTER TABLE `glpi_rules_ldap_parameters`\n                CHANGE `rule_type` `sub_type` SMALLINT( 6 ) NOT NULL DEFAULT '1'";
        $DB->queryOrDie($query, "0.72 rename rule_type to sub_type in glpi_rules_ldap_parameters");
    }
    if (FieldExists("glpi_rules_descriptions", "rule_type", false)) {
        $query = "ALTER TABLE `glpi_rules_descriptions`\n                CHANGE `rule_type` `sub_type` SMALLINT( 4 ) NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 rename rule_type to sub_type in glpi_rules_descriptions");
    }
    //Add title criteria
    $result = $DB->query("SELECT COUNT(*) AS cpt\n                          FROM `glpi_rules_ldap_parameters`\n                          WHERE `value` = 'title'\n                          AND `sub_type` = '1'");
    if (!$DB->result($result, 0, "cpt")) {
        $DB->query("INSERT INTO `glpi_rules_ldap_parameters`\n                         (`ID` ,`name` ,`value` ,`sub_type`)\n                  VALUES (NULL , '(LDAP) Title', 'title', '1')");
    }
    // Duplicate index with PRIMARY
    if (isIndex("glpi_monitors", "ID")) {
        $query = "ALTER TABLE `glpi_monitors`\n                DROP INDEX `ID`";
        $DB->queryOrDie($query, "0.72 drop ID index on glpi_monitors");
    }
    if (FieldExists("glpi_ocs_config", "is_template", false)) {
        $query = "DELETE\n                FROM `glpi_ocs_config`\n                WHERE `is_template` = '1'";
        $DB->queryOrDie($query, "0.72 delete templates in glpi_ocs_config");
        $query = "ALTER TABLE `glpi_ocs_config`\n                DROP `is_template`";
        $DB->queryOrDie($query, "0.72 drop is_template in glpi_ocs_config");
    }
    if (FieldExists("glpi_ocs_config", "tplname", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                DROP `tplname`";
        $DB->queryOrDie($query, "0.72 drop tplname in glpi_ocs_config");
    }
    if (FieldExists("glpi_ocs_config", "date_mod", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                DROP `date_mod`";
        $DB->queryOrDie($query, "0.72 drop date_mod in glpi_ocs_config");
    }
    if (FieldExists("glpi_ocs_config", "glpi_link_enabled", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                CHANGE `glpi_link_enabled` `glpi_link_enabled` INT(1) NOT NULL DEFAULT '0' ";
        $DB->queryOrDie($query, "0.72 alter glpi_link_enabled in glpi_ocs_config");
    }
    if (FieldExists("glpi_ocs_config", "link_ip", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                CHANGE `link_ip` `link_ip` INT( 1 ) NOT NULL DEFAULT '0' ";
        $DB->queryOrDie($query, "0.72 alter link_ip in glpi_ocs_config");
    }
    if (FieldExists("glpi_ocs_config", "link_name", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                CHANGE `link_name` `link_name` INT (1) NOT NULL DEFAULT '0' ";
        $DB->queryOrDie($query, "0.72 alter link_name in glpi_ocs_config");
    }
    if (FieldExists("glpi_ocs_config", "link_mac_address", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                CHANGE `link_mac_address` `link_mac_address` INT( 1 ) NOT NULL DEFAULT '0' ";
        $DB->queryOrDie($query, "0.72 alter link_mac_address in glpi_ocs_config");
    }
    if (FieldExists("glpi_ocs_config", "link_serial", false)) {
        $query = "ALTER TABLE `glpi_ocs_config`\n                CHANGE `link_serial` `link_serial` INT( 1 ) NOT NULL DEFAULT '0' ";
        $DB->queryOrDie($query, "0.72 alter link_serial in glpi_ocs_config");
    }
    if (!FieldExists("glpi_config", "name_display_order", false)) {
        $query = "ALTER TABLE `glpi_config`\n                ADD `name_display_order` TINYINT NOT NULL DEFAULT '0'";
        $DB->queryOrDie($query, "0.72 add name_display_order in glpi_config");
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("072");
    // End
}
Exemplo n.º 12
0
 /**
  * Print out an HTML "<select>" for a dropdown with preselected value
  *
  * @param $itemtype        itemtype used for create dropdown
  * @param $options   array of possible options:
  *    - name                 : string / name of the select (default is depending itemtype)
  *    - value                : integer / preselected value (default -1)
  *    - comments             : boolean / is the comments displayed near the dropdown (default true)
  *    - toadd                : array / array of specific values to add at the begining
  *    - entity               : integer or array / restrict to a defined entity or array of entities
  *                                                (default -1 : no restriction)
  *    - entity_sons          : boolean / if entity restrict specified auto select its sons
  *                                       only available if entity is a single value not an array
  *                                       (default false)
  *    - toupdate             : array / Update a specific item on select change on dropdown
  *                                     (need value_fieldname, to_update,
  *                                      url (see Ajax::updateItemOnSelectEvent for information)
  *                                      and may have moreparams)
  *    - used                 : array / Already used items ID: not to display in dropdown
  *                                    (default empty)
  *    - on_change            : string / value to transmit to "onChange"
  *    - rand                 : integer / already computed rand value
  *    - condition            : string / aditional SQL condition to limit display
  *    - displaywith          : array / array of field to display with request
  *    - emptylabel           : Empty choice's label (default self::EMPTY_VALUE)
  *    - display_emptychoice  : Display emptychoice ? (default true)
  *    - display              : boolean / display or get string (default true)
  *    - width                : specific width needed (default 80%)
  *    - permit_select_parent : boolean / for tree dropdown permit to see parent items
  *                                       not available by default (default false)
  *    - specific_tags        : array of HTML5 tags to add the the field
  *
  * @return boolean : false if error and random id if OK
  **/
 static function show($itemtype, $options = array())
 {
     global $DB, $CFG_GLPI;
     if ($itemtype && !($item = getItemForItemtype($itemtype))) {
         return false;
     }
     $table = $item->getTable();
     $params['name'] = $item->getForeignKeyField();
     $params['value'] = $itemtype == 'Entity' ? $_SESSION['glpiactive_entity'] : '';
     $params['comments'] = true;
     $params['entity'] = -1;
     $params['entity_sons'] = false;
     $params['toupdate'] = '';
     $params['width'] = '80%';
     $params['used'] = array();
     $params['toadd'] = array();
     $params['on_change'] = '';
     $params['condition'] = '';
     $params['rand'] = mt_rand();
     $params['displaywith'] = array();
     //Parameters about choice 0
     //Empty choice's label
     $params['emptylabel'] = self::EMPTY_VALUE;
     //Display emptychoice ?
     $params['display_emptychoice'] = $itemtype != 'Entity';
     $params['display'] = true;
     $params['permit_select_parent'] = false;
     $params['addicon'] = true;
     $params['specific_tags'] = array();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $output = '';
     $name = $params['emptylabel'];
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     // Check default value for dropdown : need to be a numeric
     if (strlen($params['value']) == 0 || !is_numeric($params['value']) && $params['value'] != 'mygroups') {
         $params['value'] = 0;
     }
     if (isset($params['toadd'][$params['value']])) {
         $name = $params['toadd'][$params['value']];
     } else {
         if ($params['value'] > 0 || $itemtype == "Entity" && $params['value'] >= 0) {
             $tmpname = self::getDropdownName($table, $params['value'], 1);
             if ($tmpname["name"] != "&nbsp;") {
                 $name = $tmpname["name"];
                 $comment = $tmpname["comment"];
                 if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
                     if ($item instanceof CommonTreeDropdown) {
                         $pos = strrpos($name, ">");
                         $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
                         if (Toolbox::strlen($name) > $limit_length) {
                             $name = "..." . Toolbox::substr($name, -$limit_length);
                         }
                     } else {
                         $limit_length = Toolbox::strlen($name);
                     }
                 } else {
                     $limit_length = $_SESSION["glpidropdown_chars_limit"];
                 }
             }
         }
     }
     // Manage entity_sons
     if (!($params['entity'] < 0) && $params['entity_sons']) {
         if (is_array($params['entity'])) {
             // translation not needed - only for debug
             $output .= "entity_sons options is not available with entity option as array";
         } else {
             $params['entity'] = getSonsOf('glpi_entities', $params['entity']);
         }
     }
     $field_id = Html::cleanId("dropdown_" . $params['name'] . $params['rand']);
     // Manage condition
     if (!empty($params['condition'])) {
         $params['condition'] = static::addNewCondition($params['condition']);
     }
     if (!$item instanceof CommonTreeDropdown) {
         $name = Toolbox::unclean_cross_side_scripting_deep($name);
     }
     $p = array('value' => $params['value'], 'valuename' => $name, 'width' => $params['width'], 'itemtype' => $itemtype, 'display_emptychoice' => $params['display_emptychoice'], 'displaywith' => $params['displaywith'], 'emptylabel' => $params['emptylabel'], 'condition' => $params['condition'], 'used' => $params['used'], 'toadd' => $params['toadd'], 'entity_restrict' => is_array($params['entity']) ? json_encode(array_values($params['entity'])) : $params['entity'], 'limit' => $limit_length, 'on_change' => $params['on_change'], 'permit_select_parent' => $params['permit_select_parent'], 'specific_tags' => $params['specific_tags']);
     $output = Html::jsAjaxDropdown($params['name'], $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownValue.php", $p);
     // Display comment
     if ($params['comments']) {
         $comment_id = Html::cleanId("comment_" . $params['name'] . $params['rand']);
         $link_id = Html::cleanId("comment_link_" . $params['name'] . $params['rand']);
         $options_tooltip = array('contentid' => $comment_id, 'linkid' => $link_id, 'display' => false);
         if ($item->canView()) {
             if ($params['value'] && $item->getFromDB($params['value']) && $item->canViewItem()) {
                 $options_tooltip['link'] = $item->getLinkURL();
             } else {
                 $options_tooltip['link'] = $item->getSearchURL();
             }
             $options_tooltip['linktarget'] = '_blank';
         }
         $output .= "&nbsp;" . Html::showToolTip($comment, $options_tooltip);
         if ($item instanceof CommonDropdown && $item->canCreate() && !isset($_REQUEST['_in_modal']) && $params['addicon']) {
             $output .= "<img alt='' title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n                            onClick=\"" . Html::jsGetElementbyID('add_dropdown' . $params['rand']) . ".dialog('open');\">";
             $output .= Ajax::createIframeModalWindow('add_dropdown' . $params['rand'], $item->getFormURL(), array('display' => false));
         }
         // Display specific Links
         if ($itemtype == "Supplier") {
             if ($item->getFromDB($params['value'])) {
                 $output .= $item->getLinks();
             }
         }
         if ($itemtype == 'ITILCategory' && Session::haveRight('knowbase', READ)) {
             if ($params['value'] && $item->getFromDB($params['value'])) {
                 $output .= '&nbsp;' . $item->getLinks();
             }
         }
         $paramscomment = array('value' => '__VALUE__', 'table' => $table);
         if ($item->canView()) {
             $paramscomment['withlink'] = $link_id;
         }
         $output .= Ajax::updateItemOnSelectEvent($field_id, $comment_id, $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false);
     }
     $output .= Ajax::commonDropdownUpdateItem($params, false);
     if ($params['display']) {
         echo $output;
         return $params['rand'];
     }
     return $output;
 }
Exemplo n.º 13
0
 /**
  * Print generic normal Item Cell
  *
  * @param $type         display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
  * @param $value        value to display
  * @param &$num         column number
  * @param $row          row number
  * @param $extraparam   extra parameters for display (default '')
  *
  *@return string to display
  **/
 static function showItem($type, $value, &$num, $row, $extraparam = '')
 {
     $out = "";
     switch ($type) {
         case self::PDF_OUTPUT_LANDSCAPE:
             //pdf
         //pdf
         case self::PDF_OUTPUT_PORTRAIT:
             global $PDF_ARRAY, $PDF_HEADER;
             $value = Html::weblink_extract($value);
             $PDF_ARRAY[$row][$num] = Toolbox::decodeFromUtf8(Html::clean($value), 'windows-1252');
             break;
         case self::SYLK_OUTPUT:
             //sylk
             global $SYLK_ARRAY, $SYLK_HEADER, $SYLK_SIZE;
             $value = Html::weblink_extract($value);
             $SYLK_ARRAY[$row][$num] = self::sylk_clean($value);
             $SYLK_SIZE[$num] = max($SYLK_SIZE[$num], Toolbox::strlen($SYLK_ARRAY[$row][$num]));
             break;
         case self::CSV_OUTPUT:
             //csv
             $value = Html::weblink_extract($value);
             $out = "\"" . self::csv_clean($value) . "\"" . $_SESSION["glpicsv_delimiter"];
             break;
         default:
             //TODO supprimer valign pour mettre class mais conflit avec $extraparam
             $out = "<td {$extraparam} valign='top'>";
             /*            if (!preg_match('/<hr>/',$value)) {
                            $values = preg_split("/<br>/i",$value);
                            $line_delimiter = '<br>';
                         } else {
                            $values = preg_split("/<hr>/i",$value);
                            $line_delimiter = '<hr>';
                         }
             
                         $limitto = 20;
                         if (count($values) > $limitto) {
                            for ( $i=0 ; $i<$limitto ; $i++) {
                               $out .= $values[$i].$line_delimiter;
                            }
                            $rand=mt_rand();
                            $out .= "...&nbsp;";
                            $out .= Html::showToolTip($value,array('display'   => false,
                                                                   'autoclose' => false));
             
                         } else {*/
             $out .= $value;
             //             }
             $out .= "</td>\n";
     }
     $num++;
     return $out;
 }
Exemplo n.º 14
0
 /**
  * Print out an HTML "<select>" for a dropdown with preselected value
  *
  * @param $itemtype        itemtype used for create dropdown
  * @param $options   array of possible options:
  *    - name                : string / name of the select (default is depending itemtype)
  *    - value               : integer / preselected value (default -1)
  *    - comments            : boolean / is the comments displayed near the dropdown (default true)
  *    - toadd               : array / array of specific values to add at the begining
  *    - entity              : integer or array / restrict to a defined entity or array of entities
  *                                               (default -1 : no restriction)
  *    - entity_sons         : boolean / if entity restrict specified auto select its sons
  *                                      only available if entity is a single value not an array
  *                                      (default false)
  *    - toupdate            : array / Update a specific item on select change on dropdown
  *                                    (need value_fieldname, to_update,
  *                                     url (see Ajax::updateItemOnSelectEvent for information)
  *                                     and may have moreparams)
  *    - used                : array / Already used items ID: not to display in dropdown
  *                                    (default empty)
  *    - on_change           : string / value to transmit to "onChange"
  *    - rand                : integer / already computed rand value
  *    - condition           : string / aditional SQL condition to limit display
  *    - displaywith         : array / array of field to display with request
  *    - emptylabel          : Empty choice's label (default self::EMPTY_VALUE)
  *    - display_emptychoice : Display emptychoice ? (default true)
  *    - display             : boolean / display or get string (default true)
  *    - permit_select_parent : boolean / for tree dropdown permit to see parent items not available by default (default false)
  *
  * @return boolean : false if error and random id if OK
  **/
 static function show($itemtype, $options = array())
 {
     global $DB, $CFG_GLPI;
     if ($itemtype && !($item = getItemForItemtype($itemtype))) {
         return false;
     }
     $table = $item->getTable();
     $params['name'] = $item->getForeignKeyField();
     $params['value'] = $itemtype == 'Entity' ? $_SESSION['glpiactive_entity'] : '';
     $params['comments'] = true;
     $params['entity'] = -1;
     $params['entity_sons'] = false;
     $params['toupdate'] = '';
     $params['used'] = array();
     $params['toadd'] = array();
     $params['on_change'] = '';
     $params['condition'] = '';
     $params['rand'] = mt_rand();
     $params['displaywith'] = array();
     //Parameters about choice 0
     //Empty choice's label
     $params['emptylabel'] = self::EMPTY_VALUE;
     //Display emptychoice ?
     $params['display_emptychoice'] = $itemtype != 'Entity';
     $params['display'] = true;
     $params['permit_select_parent'] = false;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $output = '';
     $name = $params['emptylabel'];
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     // Check default value for dropdown : need to be a numeric
     if (strlen($params['value']) == 0 || !is_numeric($params['value'])) {
         $params['value'] = 0;
     }
     if ($params['value'] > 0 || $itemtype == "Entity" && $params['value'] >= 0) {
         $tmpname = self::getDropdownName($table, $params['value'], 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
             if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
                 if ($item instanceof CommonTreeDropdown) {
                     $pos = strrpos($name, ">");
                     $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
                     if (Toolbox::strlen($name) > $limit_length) {
                         $name = "&hellip;" . Toolbox::substr($name, -$limit_length);
                     }
                 } else {
                     $limit_length = Toolbox::strlen($name);
                 }
             } else {
                 $limit_length = $_SESSION["glpidropdown_chars_limit"];
             }
         }
     }
     // Manage entity_sons
     if (!($params['entity'] < 0) && $params['entity_sons']) {
         if (is_array($params['entity'])) {
             // translation not needed - only for debug
             $output .= "entity_sons options is not available with entity option as array";
         } else {
             $params['entity'] = getSonsOf('glpi_entities', $params['entity']);
         }
     }
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         $nb = 0;
         if ($item->isEntityAssign()) {
             if (!($params['entity'] < 0)) {
                 $nb = countElementsInTableForEntity($table, $params['entity'], $params['condition']);
             } else {
                 $nb = countElementsInTableForMyEntities($table, $params['condition']);
             }
         } else {
             $nb = countElementsInTable($table, $params['condition']);
         }
         $nb -= count($params['used']);
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $itemtype, 'myname' => $params['name'], 'limit' => $limit_length, 'toadd' => $params['toadd'], 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'update_item' => $params['toupdate'], 'used' => $params['used'], 'on_change' => $params['on_change'], 'condition' => $params['condition'], 'emptylabel' => $params['emptylabel'], 'display_emptychoice' => $params['display_emptychoice'], 'displaywith' => $params['displaywith'], 'display' => false, 'permit_select_parent' => $params['permit_select_parent']);
     if ($item->canView()) {
         $param['update_link'] = 1;
     }
     $default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>";
     $default .= "<option value='" . $params['value'] . "'>{$name}</option></select>";
     $output .= Ajax::dropdown($use_ajax, "/ajax/dropdownValue.php", $param, $default, $params['rand'], false);
     // Display comment
     if ($params['comments']) {
         $options_tooltip = array('contentid' => "comment_" . $params['name'] . $params['rand'], 'display' => false);
         if ($item->canView()) {
             if ($params['value'] && $item->getFromDB($params['value']) && $item->canViewItem()) {
                 $options_tooltip['link'] = $item->getLinkURL();
             } else {
                 $options_tooltip['link'] = $item->getSearchURL();
             }
             $options_tooltip['linkid'] = "comment_link_" . $params['name'] . $params['rand'];
             $options_tooltip['linktarget'] = '_blank';
         }
         $output .= Html::showToolTip($comment, $options_tooltip);
         if ($item instanceof CommonDropdown && $item->canCreate() && !isset($_GET['popup'])) {
             $output .= "<img alt='' title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n                            onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&amp;rand=" . $params['rand'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
         }
         // Display specific Links
         if ($itemtype == "Supplier") {
             if ($item->getFromDB($params['value'])) {
                 $output .= $item->getLinks();
             }
         }
         if ($itemtype == 'ITILCategory' && Session::haveRight('knowbase', 'r')) {
             if ($params['value'] && $item->getFromDB($params['value'])) {
                 $output .= '&nbsp;' . $item->getLinks();
             }
         }
     }
     if ($params['display']) {
         echo $output;
         return $params['rand'];
     } else {
         return $output;
     }
 }
Exemplo n.º 15
0
 /**
  * display a field using standard system
  *
  * @since version 0.83
  *
  * @param $field_id_or_search_options  integer/string/array id of the search option field
  *                                                             or field name
  *                                                             or search option array
  * @param $values                                           mixed value to display
  * @param $options                     array                of possible options:
  * Parameters which could be used in options array :
  *    - comments : boolean / is the comments displayed near the value (default false)
  *    - any others options passed to specific display method
  *
  * @return return the string to display
  **/
 function getValueToDisplay($field_id_or_search_options, $values, $options = array())
 {
     global $CFG_GLPI;
     $param['comments'] = false;
     $param['html'] = false;
     foreach ($param as $key => $val) {
         if (!isset($options[$key])) {
             $options[$key] = $val;
         }
     }
     $searchoptions = array();
     if (is_array($field_id_or_search_options)) {
         $searchoptions = $field_id_or_search_options;
     } else {
         $searchopt = $this->getSearchOptions();
         // Get if id of search option is passed
         if (is_numeric($field_id_or_search_options)) {
             if (isset($searchopt[$field_id_or_search_options])) {
                 $searchoptions = $searchopt[$field_id_or_search_options];
             }
         } else {
             // Get if field name is passed
             $searchoptions = $this->getSearchOptionByField('field', $field_id_or_search_options, $this->getTable());
         }
     }
     if (count($searchoptions)) {
         $field = $searchoptions['field'];
         // Normalize option
         if (is_array($values)) {
             $value = $values[$field];
         } else {
             $value = $values;
             $values = array($field => $value);
         }
         if (isset($searchoptions['datatype'])) {
             $unit = '';
             if (isset($searchoptions['unit'])) {
                 $unit = $searchoptions['unit'];
             }
             switch ($searchoptions['datatype']) {
                 case "count":
                 case "number":
                     if (isset($searchoptions['toadd']) && isset($searchoptions['toadd'][$value])) {
                         return $searchoptions['toadd'][$value];
                     }
                     if ($options['html']) {
                         return Dropdown::getValueWithUnit(Html::formatNumber($value, false, 0), $unit);
                     }
                     return $value;
                 case "decimal":
                     if ($options['html']) {
                         return Dropdown::getValueWithUnit(Html::formatNumber($value), $unit);
                     }
                     return $value;
                 case "string":
                 case "mac":
                 case "ip":
                     return $value;
                 case "text":
                     if ($options['html']) {
                         $text = nl2br($value);
                     } else {
                         $text = $value;
                     }
                     if (isset($searchoptions['htmltext']) && $searchoptions['htmltext']) {
                         $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep($text));
                     }
                     return $text;
                 case "bool":
                     return Dropdown::getYesNo($value);
                 case "date":
                 case "date_delay":
                     if (isset($options['relative_dates']) && $options['relative_dates']) {
                         $dates = Html::getGenericDateTimeSearchItems(array('with_time' => true, 'with_future' => true));
                         return $dates[$value];
                     }
                     return Html::convDate(Html::computeGenericDateTimeSearch($value, true));
                 case "datetime":
                     if (isset($options['relative_dates']) && $options['relative_dates']) {
                         $dates = Html::getGenericDateTimeSearchItems(array('with_time' => true, 'with_future' => true));
                         return $dates[$value];
                     }
                     return Html::convDateTime(Html::computeGenericDateTimeSearch($value, false));
                 case "timestamp":
                     if ($value == 0 && isset($searchoptions['emptylabel'])) {
                         return $searchoptions['emptylabel'];
                     }
                     $withseconds = false;
                     if (isset($searchoptions['withseconds'])) {
                         $withseconds = $searchoptions['withseconds'];
                     }
                     return Html::timestampToString($value, $withseconds);
                 case "email":
                     if ($options['html']) {
                         return "<a href='mailto:{$value}'>{$value}</a>";
                     }
                     return $value;
                 case "weblink":
                     $orig_link = trim($value);
                     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 "itemlink":
                     if ($searchoptions['table'] == $this->getTable()) {
                         break;
                     }
                 case "dropdown":
                     if (isset($searchoptions['toadd']) && isset($searchoptions['toadd'][$value])) {
                         return $searchoptions['toadd'][$value];
                     }
                     if (!is_numeric($value)) {
                         return $value;
                     }
                     if ($value == 0 && isset($searchoptions['emptylabel'])) {
                         return $searchoptions['emptylabel'];
                     }
                     if ($searchoptions['table'] == 'glpi_users') {
                         if ($param['comments']) {
                             $tmp = getUserName($value, 2);
                             return $tmp['name'] . '&nbsp;' . Html::showToolTip($tmp['comment'], array('display' => false));
                         }
                         return getUserName($value);
                     }
                     if ($param['comments']) {
                         $tmp = Dropdown::getDropdownName($searchoptions['table'], $value, 1);
                         return $tmp['name'] . '&nbsp;' . Html::showToolTip($tmp['comment'], array('display' => false));
                     }
                     return Dropdown::getDropdownName($searchoptions['table'], $value);
                 case "itemtypename":
                     if ($obj = getItemForItemtype($value)) {
                         return $obj->getTypeName(1);
                     }
                     break;
                 case "language":
                     if (isset($CFG_GLPI['languages'][$value])) {
                         return $CFG_GLPI['languages'][$value][0];
                     }
                     return __('Default value');
             }
         }
         // Get specific display if available
         $itemtype = getItemTypeForTable($searchoptions['table']);
         if ($item = getItemForItemtype($itemtype)) {
             $options['searchopt'] = $searchoptions;
             $specific = $item->getSpecificValueToDisplay($field, $values, $options);
             if (!empty($specific)) {
                 return $specific;
             }
         }
     }
     return $value;
 }
/**
 * Create a new name using a autoname field defined in a template
 *
 * @param $objectName      autoname template
 * @param $field           field to autoname
 * @param $isTemplate      true if create an object from a template
 * @param $itemtype        item type
 * @param $entities_id     limit generation to an entity (default -1)
 *
 * @return new auto string
**/
function autoName($objectName, $field, $isTemplate, $itemtype, $entities_id = -1)
{
    global $DB, $CFG_GLPI;
    $len = Toolbox::strlen($objectName);
    if ($isTemplate && $len > 8 && Toolbox::substr($objectName, 0, 4) === '&lt;' && Toolbox::substr($objectName, $len - 4, 4) === '&gt;') {
        $autoNum = Toolbox::substr($objectName, 4, $len - 8);
        $mask = '';
        if (preg_match("/\\#{1,10}/", $autoNum, $mask)) {
            $global = strpos($autoNum, '\\g') !== false && $itemtype != 'Infocom' ? 1 : 0;
            $autoNum = str_replace(array('\\y', '\\Y', '\\m', '\\d', '_', '%', '\\g'), array(date('y'), date('Y'), date('m'), date('d'), '\\_', '\\%', ''), $autoNum);
            $mask = $mask[0];
            $pos = strpos($autoNum, $mask) + 1;
            $len = Toolbox::strlen($mask);
            $like = str_replace('#', '_', $autoNum);
            if ($global == 1) {
                $query = "";
                $first = 1;
                $types = array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer');
                foreach ($types as $t) {
                    $table = getTableForItemType($t);
                    $query .= ($first ? "SELECT " : " UNION SELECT  ") . " {$field} AS code\n                         FROM `{$table}`\n                         WHERE `{$field}` LIKE '{$like}'\n                               AND `is_deleted` = '0'\n                               AND `is_template` = '0'";
                    if ($CFG_GLPI["use_autoname_by_entity"] && $entities_id >= 0) {
                        $query .= " AND `entities_id` = '{$entities_id}' ";
                    }
                    $first = 0;
                }
                $query = "SELECT CAST(SUBSTRING(code, {$pos}, {$len}) AS unsigned) AS no\n                      FROM ({$query}) AS codes";
            } else {
                $table = getTableForItemType($itemtype);
                $query = "SELECT CAST(SUBSTRING({$field}, {$pos}, {$len}) AS unsigned) AS no\n                      FROM `{$table}`\n                      WHERE `{$field}` LIKE '{$like}' ";
                if ($itemtype != 'Infocom') {
                    $query .= " AND `is_deleted` = '0'\n                           AND `is_template` = '0'";
                    if ($CFG_GLPI["use_autoname_by_entity"] && $entities_id >= 0) {
                        $query .= " AND `entities_id` = '{$entities_id}' ";
                    }
                }
            }
            $query = "SELECT MAX(Num.no) AS lastNo\n                   FROM (" . $query . ") AS Num";
            $resultNo = $DB->query($query);
            if ($DB->numrows($resultNo) > 0) {
                $data = $DB->fetch_assoc($resultNo);
                $newNo = $data['lastNo'] + 1;
            } else {
                $newNo = 0;
            }
            $objectName = str_replace(array($mask, '\\_', '\\%'), array(Toolbox::str_pad($newNo, $len, '0', STR_PAD_LEFT), '_', '%'), $autoNum);
        }
    }
    return $objectName;
}
 /**
  * Get download link for a document
  *
  * @param $params    additonal parameters to be added to the link (default '')
  * @param $len       maximum length of displayed string (default 20)
  *
  **/
 function getDownloadLink($params = '', $len = 20)
 {
     global $DB, $CFG_GLPI;
     $splitter = explode("/", $this->fields['filename']);
     if (count($splitter) == 2) {
         // Old documents in EXT/filename
         $fileout = $splitter[1];
     } else {
         // New document
         $fileout = $this->fields['filename'];
     }
     $initfileout = $fileout;
     if (Toolbox::strlen($fileout) > $len) {
         $fileout = Toolbox::substr($fileout, 0, $len) . "&hellip;";
     }
     $out = '';
     $open = '';
     $close = '';
     if (self::canView() || self::canViewFile(array('tickets_id' => $this->fields['tickets_id']))) {
         $open = "<a href='" . $CFG_GLPI["root_doc"] . "/front/document.send.php?docid=" . $this->fields['id'] . $params . "' alt=\"" . $initfileout . "\"\n                    title=\"" . $initfileout . "\"target='_blank'>";
         $close = "</a>";
     }
     $splitter = explode("/", $this->fields['filepath']);
     if (count($splitter)) {
         $query = "SELECT *\n                   FROM `glpi_documenttypes`\n                   WHERE `ext` LIKE '" . $splitter[0] . "'\n                         AND `icon` <> ''";
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result) > 0) {
                 $icon = $DB->result($result, 0, 'icon');
                 $out .= "&nbsp;<img class='middle' style='margin-left:3px; margin-right:6px;' alt=\"" . $initfileout . "\" title=\"" . $initfileout . "\" src='" . $CFG_GLPI["typedoc_icon_dir"] . "/{$icon}'>";
             }
         }
     }
     $out .= "{$open}<span class='b'>{$fileout}</span>{$close}";
     return $out;
 }
Exemplo n.º 18
0
 /**
  * Generate vcard for the current user
  **/
 function generateVcard()
 {
     // prepare properties for the Vcard
     if (!empty($this->fields["realname"]) || !empty($this->fields["firstname"])) {
         $name = [$this->fields["realname"], $this->fields["firstname"], "", "", ""];
     } else {
         $name = [$this->fields["name"], "", "", "", ""];
     }
     // create vcard
     $vcard = new VObject\Component\VCard(['N' => $name, 'EMAIL' => $this->getDefaultEmail(), 'NOTE' => $this->fields["comment"]]);
     $vcard->add('TEL', $this->fields["phone"], ['type' => 'PREF;WORK;VOICE']);
     $vcard->add('TEL', $this->fields["phone2"], ['type' => 'HOME;VOICE']);
     $vcard->add('TEL', $this->fields["mobile"], ['type' => 'WORK;CELL']);
     // send the  VCard
     $output = $vcard->serialize();
     $filename = implode("_", array_filter($name)) . ".vcf";
     @Header("Content-Disposition: attachment; filename=\"{$filename}\"");
     @Header("Content-Length: " . Toolbox::strlen($output));
     @Header("Connection: close");
     @Header("content-type: text/x-vcard; charset=UTF-8");
     echo $output;
 }
Exemplo n.º 19
0
 /**
  * Permet l'affichage dynamique d'une liste déroulante imbriquee
  *
  * @static
  * @param array ($itemtype,$myname,$value,$entity_restrict,$action,$span)
  */
 static function showGenericDropdown($itemtype, $options = array())
 {
     global $DB, $CFG_GLPI;
     $item = getItemForItemtype($itemtype);
     if ($itemtype && !($item = getItemForItemtype($itemtype))) {
         return false;
     }
     $table = $item->getTable();
     /*$options["table"] = $table;
       $options["rand"] = $rand;
       
       $params['name']        = $item->getForeignKeyField();
       $params['value']       = ($itemtype=='Entity' ? $_SESSION['glpiactive_entity'] : '');
       
       $params['entity']      = -1;
       $params['entity_sons'] = false;
       $params['toupdate']    = '';
       $params['used']        = array();
       $params['toadd']       = array();
       $params['on_change']   = '';
       $params['condition']   = '';
       $params['rand']        = mt_rand();
       $params['displaywith'] = array();
       //Parameters about choice 0
       //Empty choice's label
       $params['emptylabel'] = self::EMPTY_VALUE;*/
     $params['comments'] = true;
     $params['condition'] = '';
     $params['entity'] = -1;
     $params['entity_sons'] = false;
     $params['rand'] = mt_rand();
     $params['used'] = array();
     $params['table'] = $table;
     $params['emptylabel'] = Dropdown::EMPTY_VALUE;
     //Display emptychoice ?
     $params['display_emptychoice'] = true;
     //In case of Entity dropdown, display root entity ?
     $params['display_rootentity'] = false;
     //specific
     $params['action'] = "";
     $params['span'] = "";
     $params['sort'] = false;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $name = $params['emptylabel'];
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     if (strlen($params['value']) == 0 || !is_numeric($params['value'])) {
         $params['value'] = 0;
     }
     if ($params['value'] > 0) {
         $tmpname = Dropdown::getDropdownName($table, $params['value'], 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
             if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
                 if ($item instanceof CommonTreeDropdown) {
                     $pos = strrpos($name, ">");
                     $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
                     if (Toolbox::strlen($name) > $limit_length) {
                         $name = "&hellip;" . Toolbox::substr($name, -$limit_length);
                     }
                 } else {
                     $limit_length = Toolbox::strlen($name);
                 }
             } else {
                 $limit_length = $_SESSION["glpidropdown_chars_limit"];
             }
         }
     }
     // Manage entity_sons
     if (!($params['entity'] < 0) && $params['entity_sons']) {
         if (is_array($params['entity'])) {
             echo "entity_sons options is not available with array of entity";
         } else {
             $params['entity'] = getSonsOf('glpi_entities', $params['entity']);
         }
     }
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         $nb = 0;
         if ($item->isEntityAssign()) {
             if (!($params['entity'] < 0)) {
                 $nb = countElementsInTableForEntity($table, $params['entity'], $params['condition']);
             } else {
                 $nb = countElementsInTableForMyEntities($table, $params['condition']);
             }
         } else {
             $nb = countElementsInTable($table, $params['condition']);
         }
         $nb -= count($params['used']);
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $itemtype, 'myname' => $params['name'], 'limit' => $limit_length, 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'used' => $params['used'], 'condition' => $params['condition'], 'emptylabel' => $params['emptylabel'], 'display_emptychoice' => $params['display_emptychoice'], 'display_rootentity' => $params['display_rootentity'], 'action' => $params['action'], 'span' => $params['span'], 'sort' => $params['sort']);
     $default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>";
     $default .= "<option value='" . $params['value'] . "'>{$name}</option></select>";
     Ajax::dropdown($use_ajax, "/plugins/resources/ajax/dropdownValue.php", $param, $default, $params['rand']);
     // Display comment
     if ($params['comments']) {
         $options_tooltip = array('contentid' => "comment_" . $param['myname'] . $params['rand']);
         if ($params['value'] && $item->getFromDB($params['value'])) {
             $options_tooltip['link'] = $item->getLinkURL();
             $options_tooltip['linktarget'] = '_blank';
         }
         Html::showToolTip($comment, $options_tooltip);
         if ($item instanceof CommonDropdown && $item->canCreate() && !isset($_GET['popup'])) {
             echo "<img alt='' title=\"" . _sx('button', 'Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n                     onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&amp;rand=" . $params['rand'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
         }
     }
     return $params['rand'];
 }
Exemplo n.º 20
0
 function showTabs($options = array())
 {
     global $CFG_GLPI;
     // for objects not in table like central
     $ID = 0;
     if (isset($this->fields['id'])) {
         $ID = $this->fields['id'];
     }
     $target = $_SERVER['PHP_SELF'];
     $extraparamhtml = "";
     $extraparam = "";
     $withtemplate = "";
     if (is_array($options) && count($options)) {
         if (isset($options['withtemplate'])) {
             $withtemplate = $options['withtemplate'];
         }
         foreach ($options as $key => $val) {
             $extraparamhtml .= "&amp;{$key}={$val}";
             $extraparam .= "&{$key}={$val}";
         }
     }
     if (empty($withtemplate) && $ID && $this->getType() && $this->displaylist) {
         $glpilistitems =& $_SESSION['glpilistitems'][$this->getType()];
         $glpilisttitle =& $_SESSION['glpilisttitle'][$this->getType()];
         $glpilisturl =& $_SESSION['glpilisturl'][$this->getType()];
         if (empty($glpilisturl)) {
             $glpilisturl = $this->getSearchURL();
         }
         echo "<div id='menu_navigate'>";
         $next = $prev = $first = $last = -1;
         $current = false;
         if (is_array($glpilistitems)) {
             $current = array_search($ID, $glpilistitems);
             if ($current !== false) {
                 if (isset($glpilistitems[$current + 1])) {
                     $next = $glpilistitems[$current + 1];
                 }
                 if (isset($glpilistitems[$current - 1])) {
                     $prev = $glpilistitems[$current - 1];
                 }
                 $first = $glpilistitems[0];
                 if ($first == $ID) {
                     $first = -1;
                 }
                 $last = $glpilistitems[count($glpilistitems) - 1];
                 if ($last == $ID) {
                     $last = -1;
                 }
             }
         }
         $cleantarget = Html::cleanParametersURL($target);
         echo "<ul>";
         echo "<li><a href=\"javascript:showHideDiv('tabsbody','tabsbodyimg','" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png','" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png')\">";
         echo "<img alt='' name='tabsbodyimg' src=\"" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png\">";
         echo "</a></li>";
         echo "<li><a href=\"" . $glpilisturl . "\">";
         if ($glpilisttitle) {
             if (Toolbox::strlen($glpilisttitle) > $_SESSION['glpidropdown_chars_limit']) {
                 $glpilisttitle = Toolbox::substr($glpilisttitle, 0, $_SESSION['glpidropdown_chars_limit']) . "&hellip;";
             }
             echo $glpilisttitle;
         } else {
             echo __('List');
         }
         echo "</a>&nbsp;:&nbsp;</li>";
         if ($first > 0) {
             echo "<li><a href='{$cleantarget}?id={$first}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __('First') . "\" title=\"" . __('First') . "\"></a></li>";
         } else {
             echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/first_off.png' alt=\"" . __('First') . "\" title=\"" . __('First') . "\"></li>";
         }
         if ($prev > 0) {
             echo "<li><a href='{$cleantarget}?id={$prev}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __('Previous') . "\" title=\"" . __('Previous') . "\"></a></li>";
         } else {
             echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/left_off.png' alt=\"" . __('Previous') . "\" title=\"" . __('Previous') . "\"></li>";
         }
         if ($current !== false) {
             echo "<li>" . ($current + 1) . "/" . count($glpilistitems) . "</li>";
         }
         if ($next > 0) {
             echo "<li><a href='{$cleantarget}?id={$next}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __('Next') . "\" title=\"" . __('Next') . "\"></a></li>";
         } else {
             echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/right_off.png' alt=\"" . __('Next') . "\" title=\"" . __('Next') . "\"></li>";
         }
         if ($last > 0) {
             echo "<li><a href='{$cleantarget}?id={$last}{$extraparamhtml}'><img src=\"" . $CFG_GLPI["root_doc"] . "/pics/last.png\" alt=\"" . __('Last') . "\" title=\"" . __('Last') . "\"></a></li>";
         } else {
             echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/last_off.png' alt=\"" . __('Last') . "\" title=\"" . __('Last') . "\"></li>";
         }
         echo "</ul></div>";
         echo "<div class='sep'></div>";
     }
     echo "<div id='tabspanel' class='center-h'></div>";
     $onglets = $this->defineTabs($options);
     $display_all = true;
     if (isset($onglets['no_all_tab'])) {
         $display_all = false;
         unset($onglets['no_all_tab']);
     }
     $class = $this->getType();
     if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && ($ID > 0 || $this->showdebug) && (method_exists($class, 'showDebug') || in_array($class, $CFG_GLPI["infocom_types"]) || in_array($class, $CFG_GLPI["reservation_types"]))) {
         $onglets[-2] = __('Debug');
     }
     if (count($onglets)) {
         $tabpage = $this->getTabsURL();
         $tabs = array();
         foreach ($onglets as $key => $val) {
             $tabs[$key] = array('title' => $val, 'url' => $tabpage, 'params' => "target={$target}&itemtype=" . $this->getType() . "&glpi_tab={$key}&id={$ID}{$extraparam}");
         }
         $plug_tabs = Plugin::getTabs($target, $this, $withtemplate);
         $tabs += $plug_tabs;
         // Not all tab for templates and if only 1 tab
         if ($display_all && empty($withtemplate) && count($tabs) > 1) {
             $tabs[-1] = array('title' => __('All'), 'url' => $tabpage, 'params' => "target={$target}&itemtype=" . $this->getType() . "&glpi_tab=-1&id={$ID}{$extraparam}");
         }
         Ajax::createTabs('tabspanel', 'tabcontent', $tabs, $this->getType(), "'100%'");
     }
 }
Exemplo n.º 21
0
                 } else {
                     // Error getting item : stop
                     $work_level = -1;
                 }
             } while ($work_level >= 1 && (!isset($last_level_displayed[$work_level]) || $last_level_displayed[$work_level] != $work_parentID));
             // Add parents
             foreach ($parent_datas as $val) {
                 array_push($datastoadd, $val);
             }
         }
     }
     $last_level_displayed[$level] = $data['id'];
 }
 // Do not do for first item for next page load
 if (!$firstitem) {
     if ($_SESSION["glpiis_ids_visible"] || Toolbox::strlen($outputval) == 0) {
         $outputval = sprintf(__('%1$s (%2$s)'), $outputval, $ID);
     }
     if (isset($data['transcompletename']) && !empty($data['transcompletename'])) {
         $title = $data['transcompletename'];
     } else {
         $title = $data['completename'];
     }
     if (isset($data["comment"])) {
         if (isset($data['transcomment']) && !empty($data['transcomment'])) {
             $addcomment = $data['transcomment'];
         } else {
             $addcomment = $data['comment'];
         }
         $title = sprintf(__('%1$s - %2$s'), $title, $addcomment);
     }
Exemplo n.º 22
0
 /**
  * Print pager for search option (first/previous/next/last)
  *
  * @param $start                       from witch item we start
  * @param $numrows                     total items
  * @param $target                      page would be open when click on the option (last,previous etc)
  * @param $parameters                  parameters would be passed on the URL.
  * @param $item_type_output            item type display - if >0 display export PDF et Sylk form
  *                                     (default 0)
  * @param $item_type_output_param      item type parameter for export (default 0)
  * @param $additional_info             Additional information to display (default '')
  *
  * @return nothing (print a pager)
  *
  * */
 function printPager($start, $numrows, $target, $parameters, $item_type_output = 0, $item_type_output_param = 0, $additional_info = '')
 {
     global $CFG_GLPI;
     $list_limit = $_SESSION['glpilist_limit'];
     // Forward is the next step forward
     $forward = $start + $list_limit;
     // This is the end, my friend
     $end = $numrows - $list_limit;
     // Human readable count starts here
     $current_start = $start + 1;
     // And the human is viewing from start to end
     $current_end = $current_start + $list_limit - 1;
     if ($current_end > $numrows) {
         $current_end = $numrows;
     }
     // Empty case
     if ($current_end == 0) {
         $current_start = 0;
     }
     // Backward browsing
     if ($current_start - $list_limit <= 0) {
         $back = 0;
     } else {
         $back = $start - $list_limit;
     }
     // Print it
     echo "<div><table class='tab_cadre_pager'>";
     echo "<tr>";
     // Back and fast backward button
     if (!$start == 0) {
         echo "<th class='left'>";
         echo "<a href='{$target}?{$parameters}&amp;start=0'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __s('Start') . "\" title=\"" . __s('Start') . "\">";
         echo "</a></th>";
         echo "<th class='left'>";
         echo "<a href='{$target}?{$parameters}&amp;start={$back}'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __s('Previous') . "\" title=\"" . __s('Previous') . "\">";
         echo "</a></th>";
     }
     // Print the "where am I?"
     echo "<td width='50%' class='tab_bg_2'>";
     Html::printPagerForm("{$target}?{$parameters}&amp;start={$start}");
     echo "</td>";
     if (!empty($additional_info)) {
         echo "<td class='tab_bg_2'>";
         echo $additional_info;
         echo "</td>";
     }
     if (!empty($item_type_output) && isset($_SESSION["glpiactiveprofile"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central") {
         echo "<td class='tab_bg_2' width='30%'>";
         echo "<form method='GET' action='" . $target . "' target='_blank'>";
         echo Html::hidden('item_type', array('value' => $item_type_output));
         if ($item_type_output_param != 0) {
             echo Html::hidden('item_type_param', array('value' => Toolbox::prepareArrayForInput($item_type_output_param)));
         }
         $split = explode("&amp;", $parameters);
         for ($i = 0; $i < count($split); $i++) {
             $pos = Toolbox::strpos($split[$i], '=');
             $length = Toolbox::strlen($split[$i]);
             echo Html::hidden(Toolbox::substr($split[$i], 0, $pos), array('value' => urldecode(Toolbox::substr($split[$i], $pos + 1))));
         }
         Dropdown::showOutputFormat();
         $this->showCSVOptions();
         echo "<script type='text/javascript'>";
         echo "\$('select[name=display_type]').change(function() {\r\n                  switch(\$(this).val()){\r\n                     case '3' :case '-3' :\r\n                        \$('#display_csv_preferences').css('display', 'block');\r\n                        break;\r\n                     default : \r\n                        \$('#display_csv_preferences').css('display', 'none');\r\n                        break;\r\n                  }\r\n               });";
         echo "</script>";
         Html::closeForm();
         echo "</td>";
     }
     echo "<td width='50%' class='tab_bg_2 b'>";
     //TRANS: %1$d, %2$d, %3$d are page numbers
     printf(__('From %1$d to %2$d on %3$d'), $current_start, $current_end, $numrows);
     echo "</td>\n";
     // Forward and fast forward button
     if ($forward < $numrows) {
         echo "<th class='right'>";
         echo "<a href='{$target}?{$parameters}&amp;start={$forward}'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __s('Next') . "\" title=\"" . __s('Next') . "\">";
         echo "</a></th>\n";
         echo "<th class='right'>";
         echo "<a href='{$target}?{$parameters}&amp;start={$end}'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/last.png' alt=\"" . __s('End') . "\" title=\"" . __s('End') . "\">";
         echo "</a></th>\n";
     }
     // End pager
     echo "</tr></table></div>";
 }
Exemplo n.º 23
0
 /**
  * Generate the Vcard for the current Contact
  *
  *@return Nothing (display)
  **/
 function generateVcard()
 {
     include GLPI_ROOT . "/lib/vcardclass/classes-vcard.php";
     if (!$this->can($this->fields['id'], READ)) {
         return false;
     }
     // build the Vcard
     $vcard = new vCard();
     $vcard->setName($this->fields["name"], $this->fields["firstname"], "", "");
     $vcard->setPhoneNumber($this->fields["phone"], "PREF;WORK;VOICE");
     $vcard->setPhoneNumber($this->fields["phone2"], "HOME;VOICE");
     $vcard->setPhoneNumber($this->fields["mobile"], "WORK;CELL");
     $addr = $this->GetAddress();
     if (is_array($addr)) {
         $vcard->setAddress($addr["name"], "", $addr["address"], $addr["town"], $addr["state"], $addr["postcode"], $addr["country"], "WORK;POSTAL");
     }
     $vcard->setEmail($this->fields["email"]);
     $vcard->setNote($this->fields["comment"]);
     $vcard->setURL($this->GetWebsite(), "WORK");
     // send the  VCard
     $output = $vcard->getVCard();
     $filename = $vcard->getFileName();
     // "xxx xxx.vcf"
     @Header("Content-Disposition: attachment; filename=\"{$filename}\"");
     @Header("Content-Length: " . Toolbox::strlen($output));
     @Header("Connection: close");
     @Header("content-type: text/x-vcard; charset=UTF-8");
     echo $output;
 }
Exemplo n.º 24
0
 /**
  * Print out an HTML "<select>" for a dropdown with preselected value
  *
  * @param $myname             the name of the HTML select
  * @param $value              the preselected value we want (default 0)
  * @param $locations_id       default location ID for search (default -1)
  * @param $display_comment    display the comment near the dropdown (default 1)
  * @param $entity_restrict    Restrict to a defined entity(default -1)
  * @param $devtype            (default '')
  *
  * @return nothing (display the select box)
  **/
 static function dropdownNetpoint($myname, $value = 0, $locations_id = -1, $display_comment = 1, $entity_restrict = -1, $devtype = '')
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $name = Dropdown::EMPTY_VALUE;
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     if (empty($value)) {
         $value = 0;
     }
     if ($value > 0) {
         $tmpname = Dropdown::getDropdownName("glpi_netpoints", $value, 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
             $limit_length = max(Toolbox::strlen($name), $_SESSION["glpidropdown_chars_limit"]);
         }
     }
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         if ($locations_id < 0 || $devtype == 'NetworkEquipment') {
             $nb = countElementsInTableForEntity("glpi_netpoints", $entity_restrict);
         } else {
             if ($locations_id > 0) {
                 $nb = countElementsInTable("glpi_netpoints", "locations_id={$locations_id} ");
             } else {
                 $nb = countElementsInTable("glpi_netpoints", "locations_id=0 " . getEntitiesRestrictRequest(" AND ", "glpi_netpoints", '', $entity_restrict));
             }
         }
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $params = array('searchText' => '__VALUE__', 'value' => $value, 'locations_id' => $locations_id, 'myname' => $myname, 'limit' => $limit_length, 'comment' => $display_comment, 'rand' => $rand, 'entity_restrict' => $entity_restrict, 'devtype' => $devtype);
     $default = "<select name='{$myname}'><option value='{$value}'>{$name}</option></select>";
     Ajax::dropdown($use_ajax, "/ajax/dropdownNetpoint.php", $params, $default, $rand);
     // Display comment
     if ($display_comment) {
         Html::showToolTip($comment);
         $item = new self();
         if ($item->canCreate()) {
             echo "<img alt='' title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;' " . "onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&amp;rand={$rand}' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
         }
     }
     return $rand;
 }
 /**
  * Validate password based on security rules
  *
  * @since version 0.84
  *
  * @param $password  string   password to validate
  * @param $display   boolean  display errors messages? (true by default)
  *
  * @return boolean is password valid?
  **/
 static function validatePassword($password, $display = true)
 {
     global $CFG_GLPI;
     $ok = true;
     if ($CFG_GLPI["use_password_security"]) {
         if (Toolbox::strlen($password) < $CFG_GLPI['password_min_length']) {
             $ok = false;
             if ($display) {
                 Session::addMessageAfterRedirect(__('Password too short!'), false, ERROR);
             }
         }
         if ($CFG_GLPI["password_need_number"] && !preg_match("/[0-9]+/", $password)) {
             $ok = false;
             if ($display) {
                 Session::addMessageAfterRedirect(__('Password must include at least a digit!'), false, ERROR);
             }
         }
         if ($CFG_GLPI["password_need_letter"] && !preg_match("/[a-z]+/", $password)) {
             $ok = false;
             if ($display) {
                 Session::addMessageAfterRedirect(__('Password must include at least a lowercase letter!'), false, ERROR);
             }
         }
         if ($CFG_GLPI["password_need_caps"] && !preg_match("/[A-Z]+/", $password)) {
             $ok = false;
             if ($display) {
                 Session::addMessageAfterRedirect(__('Password must include at least a uppercase letter!'), false, ERROR);
             }
         }
         if ($CFG_GLPI["password_need_symbol"] && !preg_match("/\\W+/", $password)) {
             $ok = false;
             if ($display) {
                 Session::addMessageAfterRedirect(__('Password must include at least a symbol!'), false, ERROR);
             }
         }
     }
     return $ok;
 }
Exemplo n.º 26
0
 function prepareInputForAdd($input)
 {
     if (!isset($input['url']) || !isset($input['type'])) {
         return false;
     }
     $taburl = parse_url(rawurldecode($input['url']));
     $index = strpos($taburl["path"], "plugins");
     if (!$index) {
         $index = strpos($taburl["path"], "front");
     }
     $input['path'] = Toolbox::substr($taburl["path"], $index, Toolbox::strlen($taburl["path"]) - $index);
     $query_tab = array();
     if (isset($taburl["query"])) {
         parse_str($taburl["query"], $query_tab);
     }
     $input['query'] = Toolbox::append_params($this->prepareQueryToStore($input['type'], $query_tab, $input['itemtype']));
     return $input;
 }
Exemplo n.º 27
0
 /**
  * Print pager for search option (first/previous/next/last)
  *
  * @param $start                       from witch item we start
  * @param $numrows                     total items
  * @param $target                      page would be open when click on the option (last,previous etc)
  * @param $parameters                  parameters would be passed on the URL.
  * @param $item_type_output            item type display - if >0 display export PDF et Sylk form
  *                                     (default 0)
  * @param $item_type_output_param      item type parameter for export (default 0)
  * @param $additional_info             Additional information to display (default '')
  *
  * @return nothing (print a pager)
  *
  **/
 static function printPager($start, $numrows, $target, $parameters, $item_type_output = 0, $item_type_output_param = 0, $additional_info = '')
 {
     global $CFG_GLPI;
     $list_limit = $_SESSION['glpilist_limit'];
     // Forward is the next step forward
     $forward = $start + $list_limit;
     // This is the end, my friend
     $end = $numrows - $list_limit;
     // Human readable count starts here
     $current_start = $start + 1;
     // And the human is viewing from start to end
     $current_end = $current_start + $list_limit - 1;
     if ($current_end > $numrows) {
         $current_end = $numrows;
     }
     // Empty case
     if ($current_end == 0) {
         $current_start = 0;
     }
     // Backward browsing
     if ($current_start - $list_limit <= 0) {
         $back = 0;
     } else {
         $back = $start - $list_limit;
     }
     // Print it
     echo "<div><table class='tab_cadre_pager'>";
     echo "<tr>";
     if (strpos($target, '?') == false) {
         $fulltarget = $target . "?" . $parameters;
     } else {
         $fulltarget = $target . "&" . $parameters;
     }
     // Back and fast backward button
     if (!$start == 0) {
         echo "<th class='left'>";
         echo "<a href='{$fulltarget}&amp;start=0'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __s('Start') . "\" title=\"" . __s('Start') . "\" class='pointer'>";
         echo "</a></th>";
         echo "<th class='left'>";
         echo "<a href='{$fulltarget}&amp;start={$back}'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __s('Previous') . "\" title=\"" . __s('Previous') . "\" class='pointer'>";
         echo "</a></th>";
     }
     // Print the "where am I?"
     echo "<td width='31%' class='tab_bg_2'>";
     self::printPagerForm("{$fulltarget}&amp;start={$start}");
     echo "</td>";
     if (!empty($additional_info)) {
         echo "<td class='tab_bg_2'>";
         echo $additional_info;
         echo "</td>";
     }
     if (!empty($item_type_output) && isset($_SESSION["glpiactiveprofile"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central") {
         echo "<td class='tab_bg_2 responsive_hidden' width='30%'>";
         echo "<form method='GET' action='" . $CFG_GLPI["root_doc"] . "/front/report.dynamic.php'\n                target='_blank'>";
         echo Html::hidden('item_type', array('value' => $item_type_output));
         if ($item_type_output_param != 0) {
             echo Html::hidden('item_type_param', array('value' => Toolbox::prepareArrayForInput($item_type_output_param)));
         }
         $split = explode("&amp;", $parameters);
         for ($i = 0; $i < count($split); $i++) {
             $pos = Toolbox::strpos($split[$i], '=');
             $length = Toolbox::strlen($split[$i]);
             echo Html::hidden(Toolbox::substr($split[$i], 0, $pos), array('value' => urldecode(Toolbox::substr($split[$i], $pos + 1))));
         }
         Dropdown::showOutputFormat();
         Html::closeForm();
         echo "</td>";
     }
     echo "<td width='20%' class='tab_bg_2 b'>";
     //TRANS: %1$d, %2$d, %3$d are page numbers
     printf(__('From %1$d to %2$d on %3$d'), $current_start, $current_end, $numrows);
     echo "</td>\n";
     // Forward and fast forward button
     if ($forward < $numrows) {
         echo "<th class='right'>";
         echo "<a href='{$fulltarget}&amp;start={$forward}'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __s('Next') . "\" title=\"" . __s('Next') . "\" class='pointer'>";
         echo "</a></th>\n";
         echo "<th class='right'>";
         echo "<a href='{$fulltarget}&amp;start={$end}'>";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/last.png' alt=\"" . __s('End') . "\" title=\"" . __s('End') . "\" class='pointer'>";
         echo "</a></th>\n";
     }
     // End pager
     echo "</tr></table></div>";
 }
Exemplo n.º 28
0
 /**
  * Show tabs
  *
  * @since version 0.85
  * @param $options array of parameters to add to URLs and ajax
  *     - withtemplate is a template view ?
  * @deprecated  Only for compatibility usage
  * @return Nothing ()
  **/
 function showNavigationHeaderOld($options = array())
 {
     global $CFG_GLPI;
     // for objects not in table like central
     if (isset($this->fields['id'])) {
         $ID = $this->fields['id'];
     } else {
         $ID = 0;
     }
     $target = $_SERVER['PHP_SELF'];
     $extraparamhtml = "";
     $extraparam = "";
     $withtemplate = "";
     if (is_array($options) && count($options)) {
         if (isset($options['withtemplate'])) {
             $withtemplate = $options['withtemplate'];
         }
         foreach ($options as $key => $val) {
             // Do not include id options
             if ($key[0] != '_' && $key != 'id') {
                 $extraparamhtml .= "&amp;{$key}={$val}";
                 $extraparam .= "&{$key}={$val}";
             }
         }
     }
     if (empty($withtemplate) && !$this->isNewID($ID) && $this->getType() && $this->displaylist) {
         $glpilistitems =& $_SESSION['glpilistitems'][$this->getType()];
         $glpilisttitle =& $_SESSION['glpilisttitle'][$this->getType()];
         $glpilisturl =& $_SESSION['glpilisturl'][$this->getType()];
         if (empty($glpilisturl)) {
             $glpilisturl = $this->getSearchURL();
         }
         echo "<div id='menu_navigate'>";
         $next = $prev = $first = $last = -1;
         $current = false;
         if (is_array($glpilistitems)) {
             $current = array_search($ID, $glpilistitems);
             if ($current !== false) {
                 if (isset($glpilistitems[$current + 1])) {
                     $next = $glpilistitems[$current + 1];
                 }
                 if (isset($glpilistitems[$current - 1])) {
                     $prev = $glpilistitems[$current - 1];
                 }
                 $first = $glpilistitems[0];
                 if ($first == $ID) {
                     $first = -1;
                 }
                 $last = $glpilistitems[count($glpilistitems) - 1];
                 if ($last == $ID) {
                     $last = -1;
                 }
             }
         }
         $cleantarget = HTML::cleanParametersURL($target);
         echo "<ul>";
         //          echo "<li><a href=\"javascript:showHideDiv('tabsbody','tabsbodyimg','".$CFG_GLPI["root_doc"].
         //                     "/pics/deplier_down.png','".$CFG_GLPI["root_doc"]."/pics/deplier_up.png')\">";
         //          echo "<img alt='' name='tabsbodyimg' src=\"".$CFG_GLPI["root_doc"]."/pics/deplier_up.png\">";
         //          echo "</a></li>";
         echo "<li><a href=\"javascript:toggleTableDisplay('mainformtable','tabsbodyimg','" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png','" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png')\">";
         echo "<img alt='' name='tabsbodyimg' src=\"" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png\" class='pointer'>";
         echo "</a></li>";
         echo "<li><a href=\"" . $glpilisturl . "\">";
         if ($glpilisttitle) {
             if (Toolbox::strlen($glpilisttitle) > $_SESSION['glpidropdown_chars_limit']) {
                 $glpilisttitle = Toolbox::substr($glpilisttitle, 0, $_SESSION['glpidropdown_chars_limit']) . "&hellip;";
             }
             echo $glpilisttitle;
         } else {
             _e('List');
         }
         echo "</a></li>";
         if ($first >= 0) {
             echo "<li><a href='{$cleantarget}?id={$first}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __s('First') . "\" title=\"" . __s('First') . "\" class='pointer'></a></li>";
         } else {
             echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/first_off.png' alt=\"" . __s('First') . "\" title=\"" . __s('First') . "\" class='pointer'></li>";
         }
         if ($prev >= 0) {
             echo "<li><a href='{$cleantarget}?id={$prev}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __s('Previous') . "\" title=\"" . __s('Previous') . "\" class='pointer'></a></li>";
         } else {
             echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/left_off.png' alt=\"" . __s('Previous') . "\" title=\"" . __s('Previous') . "\" class='pointer'></li>";
         }
         if ($current !== false) {
             echo "<li>" . ($current + 1) . "/" . count($glpilistitems) . "</li>";
         }
         if ($next >= 0) {
             echo "<li><a href='{$cleantarget}?id={$next}{$extraparamhtml}'><img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __s('Next') . "\" title=\"" . __s('Next') . "\" class='pointer'></a></li>";
         } else {
             echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/right_off.png' alt=\"" . __s('Next') . "\" title=\"" . __s('Next') . "\" class='pointer'></li>";
         }
         if ($last >= 0) {
             echo "<li><a href='{$cleantarget}?id={$last}{$extraparamhtml}'><img src=\"" . $CFG_GLPI["root_doc"] . "/pics/last.png\" alt=\"" . __s('Last') . "\" title=\"" . __s('Last') . "\" class='pointer'></a></li>";
         } else {
             echo "<li><img src='" . $CFG_GLPI["root_doc"] . "/pics/last_off.png' alt=\"" . __s('Last') . "\" title=\"" . __s('Last') . "\" class='pointer'></li>";
         }
         echo "</ul></div>";
         echo "<div class='sep'></div>";
     }
 }
Exemplo n.º 29
0
 /**
  * Generate vcard for the current user
  **/
 function generateVcard()
 {
     include_once GLPI_ROOT . "/lib/vcardclass/classes-vcard.php";
     // build the Vcard
     $vcard = new vCard();
     if (!empty($this->fields["realname"]) || !empty($this->fields["firstname"])) {
         $vcard->setName($this->fields["realname"], $this->fields["firstname"], "", "");
     } else {
         $vcard->setName($this->fields["name"], "", "", "");
     }
     $vcard->setPhoneNumber($this->fields["phone"], "PREF;WORK;VOICE");
     $vcard->setPhoneNumber($this->fields["phone2"], "HOME;VOICE");
     $vcard->setPhoneNumber($this->fields["mobile"], "WORK;CELL");
     $vcard->setEmail($this->getDefaultEmail());
     $vcard->setNote($this->fields["comment"]);
     // send the  VCard
     $output = $vcard->getVCard();
     $filename = $vcard->getFileName();
     // "xxx xxx.vcf"
     @Header("Content-Disposition: attachment; filename=\"{$filename}\"");
     @Header("Content-Length: " . Toolbox::strlen($output));
     @Header("Connection: close");
     @Header("content-type: text/x-vcard; charset=UTF-8");
     echo $output;
 }
Exemplo n.º 30
0
 /**
  * Displays a list of computers that can be cleaned.
  *
  * @param $plugin_ocsinventoryng_ocsservers_id int : id of ocs server in GLPI
  * @param $check string : parameter for HTML input checkbox
  * @param $start int : parameter for Html::printPager method
  *
  * @return nothing
  **/
 static function showComputersToClean($plugin_ocsinventoryng_ocsservers_id, $check, $start)
 {
     global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI;
     self::checkOCSconnection($plugin_ocsinventoryng_ocsservers_id);
     if (!plugin_ocsinventoryng_haveRight("clean_ocsng", "r")) {
         return false;
     }
     $canedit = plugin_ocsinventoryng_haveRight("clean_ocsng", "w");
     // Select unexisting OCS hardware
     $query_ocs = "SELECT*\n                     FROM `hardware`";
     $result_ocs = $PluginOcsinventoryngDBocs->query($query_ocs);
     $hardware = array();
     if ($PluginOcsinventoryngDBocs->numrows($result_ocs) > 0) {
         while ($data = $PluginOcsinventoryngDBocs->fetch_array($result_ocs)) {
             $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data));
             $hardware[$data["ID"]] = $data["DEVICEID"];
         }
     }
     $query = "SELECT `ocsid`\n                FROM `glpi_plugin_ocsinventoryng_ocslinks`\n                WHERE `plugin_ocsinventoryng_ocsservers_id`\n                           = '{$plugin_ocsinventoryng_ocsservers_id}'";
     $result = $DB->query($query);
     $ocs_missing = array();
     if ($DB->numrows($result) > 0) {
         while ($data = $DB->fetch_array($result)) {
             $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data));
             if (!isset($hardware[$data["ocsid"]])) {
                 $ocs_missing[$data["ocsid"]] = $data["ocsid"];
             }
         }
     }
     $sql_ocs_missing = "";
     if (count($ocs_missing)) {
         $sql_ocs_missing = " OR `ocsid` IN ('" . implode("','", $ocs_missing) . "')";
     }
     //Select unexisting computers
     $query_glpi = "SELECT `glpi_plugin_ocsinventoryng_ocslinks`.`entities_id` AS entities_id,\n                            `glpi_plugin_ocsinventoryng_ocslinks`.`ocs_deviceid` AS ocs_deviceid,\n                            `glpi_plugin_ocsinventoryng_ocslinks`.`last_update` AS last_update,\n                            `glpi_plugin_ocsinventoryng_ocslinks`.`ocsid` AS ocsid,\n                            `glpi_plugin_ocsinventoryng_ocslinks`.`id`,\n                            `glpi_computers`.`name` AS name\n                     FROM `glpi_plugin_ocsinventoryng_ocslinks`\n                     LEFT JOIN `glpi_computers`\n                           ON `glpi_computers`.`id` = `glpi_plugin_ocsinventoryng_ocslinks`.`computers_id`\n                     WHERE ((`glpi_computers`.`id` IS NULL\n                             AND `glpi_plugin_ocsinventoryng_ocslinks`.`plugin_ocsinventoryng_ocsservers_id`\n                                    = '{$plugin_ocsinventoryng_ocsservers_id}')" . $sql_ocs_missing . ")" . getEntitiesRestrictRequest(" AND", "glpi_plugin_ocsinventoryng_ocslinks");
     $result_glpi = $DB->query($query_glpi);
     // fetch all links missing between glpi and OCS
     $already_linked = array();
     if ($DB->numrows($result_glpi) > 0) {
         while ($data = $DB->fetch_assoc($result_glpi)) {
             $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data));
             $already_linked[$data["ocsid"]]["entities_id"] = $data["entities_id"];
             if (Toolbox::strlen($data["ocs_deviceid"]) > 20) {
                 // Strip datetime tag
                 $already_linked[$data["ocsid"]]["ocs_deviceid"] = substr($data["ocs_deviceid"], 0, -20);
             } else {
                 $already_linked[$data["ocsid"]]["ocs_deviceid"] = $data["ocs_deviceid"];
             }
             $already_linked[$data["ocsid"]]["date"] = $data["last_update"];
             $already_linked[$data["ocsid"]]["id"] = $data["id"];
             $already_linked[$data["ocsid"]]["in_ocs"] = isset($hardware[$data["ocsid"]]);
             if ($data["name"] == null) {
                 $already_linked[$data["ocsid"]]["in_glpi"] = 0;
             } else {
                 $already_linked[$data["ocsid"]]["in_glpi"] = 1;
             }
         }
     }
     echo "<div class='center'>";
     echo "<h2>" . __('Clean links between GLPI and OCSNG', 'ocsinventoryng') . "</h2>";
     $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.clean.php';
     if (($numrows = count($already_linked)) > 0) {
         $parameters = "check={$check}";
         Html::printPager($start, $numrows, $target, $parameters);
         // delete end
         array_splice($already_linked, $start + $_SESSION['glpilist_limit']);
         // delete begin
         if ($start > 0) {
             array_splice($already_linked, 0, $start);
         }
         echo "<form method='post' id='ocsng_form' name='ocsng_form' action='" . $target . "'>";
         if ($canedit) {
             self::checkBox($target);
         }
         echo "<table class='tab_cadre'>";
         echo "<tr><th>" . __('Item') . "</th><th>" . __('Import date in GLPI', 'ocsinventoryng') . "</th>";
         echo "<th>" . __('Existing in GLPI', 'ocsinventoryng') . "</th>";
         echo "<th>" . __('Existing in OCSNG', 'ocsinventoryng') . "</th>";
         if (Session::isMultiEntitiesMode()) {
             echo "<th>" . __('Entity') . "</th>";
         }
         if ($canedit) {
             echo "<th>&nbsp;</th>";
         }
         echo "</tr>\n";
         echo "<tr class='tab_bg_1'><td colspan='6' class='center'>";
         if ($canedit) {
             echo "<input class='submit' type='submit' name='clean_ok' value=\"" . _sx('button', 'Clean') . "\">";
         }
         echo "</td></tr>\n";
         foreach ($already_linked as $ID => $tab) {
             echo "<tr class='tab_bg_2 center'>";
             echo "<td>" . $tab["ocs_deviceid"] . "</td>\n";
             echo "<td>" . Html::convDateTime($tab["date"]) . "</td>\n";
             echo "<td>" . Dropdown::getYesNo($tab["in_glpi"]) . "</td>\n";
             echo "<td>" . Dropdown::getYesNo($tab["in_ocs"]) . "</td>\n";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td>" . Dropdown::getDropdownName('glpi_entities', $tab['entities_id']) . "</td>\n";
             }
             if ($canedit) {
                 echo "<td><input type='checkbox' name='toclean[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . "></td>";
             }
             echo "</tr>\n";
         }
         echo "<tr class='tab_bg_1'><td colspan='6' class='center'>";
         if ($canedit) {
             echo "<input class='submit' type='submit' name='clean_ok' value=\"" . _sx('button', 'Clean') . "\">";
         }
         echo "</td></tr>";
         echo "</table>\n";
         Html::closeForm();
         Html::printPager($start, $numrows, $target, $parameters);
     } else {
         echo "<div class='center b '>" . __('No item to clean', 'ocsinventoryng') . "</div>";
         Html::displayBackLink();
     }
     echo "</div>";
 }