Exemplo n.º 1
0
function update072to0721()
{
    global $DB, $CFG_GLPI, $LANG;
    echo "<h3>" . $LANG['install'][4] . " -&gt; 0.72.1</h3>";
    displayMigrationMessage("0721");
    // Start
    if (!isIndex("glpi_groups", "ldap_group_dn")) {
        $query = "ALTER TABLE `glpi_groups` ADD INDEX `ldap_group_dn` ( `ldap_group_dn` );";
        $DB->query($query) or die("0.72.1 add index on ldap_group_dn in glpi_groups" . $LANG['update'][140] . $DB->error());
    }
    if (!isIndex("glpi_groups", "ldap_value")) {
        $query = "ALTER TABLE `glpi_groups` ADD INDEX `ldap_value`  ( `ldap_value` );";
        $DB->query($query) or die("0.72.1 add index on ldap_value in glpi_groups" . $LANG['update'][140] . $DB->error());
    }
    if (!isIndex('glpi_tracking', 'date_mod')) {
        $query = " ALTER TABLE `glpi_tracking` ADD INDEX `date_mod` (`date_mod`)  ";
        $DB->query($query) or die("0.72.1 add date_mod index in glpi_tracking " . $LANG['update'][90] . $DB->error());
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("0721");
    // End
}
Exemplo n.º 2
0
function update072to0721()
{
    global $DB, $CFG_GLPI;
    //TRANS: %s is the number of new version
    echo "<h3>" . sprintf(__('Update to %s'), '0.72.1') . "</h3>";
    displayMigrationMessage("0721");
    // Start
    if (!isIndex("glpi_groups", "ldap_group_dn")) {
        $query = "ALTER TABLE `glpi_groups` ADD INDEX `ldap_group_dn` ( `ldap_group_dn` );";
        $DB->query($query, "0.72.1 add index on ldap_group_dn in glpi_groups");
    }
    if (!isIndex("glpi_groups", "ldap_value")) {
        $query = "ALTER TABLE `glpi_groups` ADD INDEX `ldap_value`  ( `ldap_value` );";
        $DB->query($query, "0.72.1 add index on ldap_value in glpi_groups");
    }
    if (!isIndex('glpi_tracking', 'date_mod')) {
        $query = " ALTER TABLE `glpi_tracking` ADD INDEX `date_mod` (`date_mod`)  ";
        $DB->query($query, "0.72.1 add date_mod index in glpi_tracking");
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("0721");
    // End
}
function update0722to0723()
{
    global $DB, $CFG_GLPI;
    //TRANS: %s is the number of new version
    echo "<h3>" . sprintf(__('Update to %s'), '0.72.3') . "</h3>";
    displayMigrationMessage("0723");
    // Start
    //// Correct search.constant numbers : problem in previous update
    $updates = array();
    // serial / otherserial
    $updates[] = array('type' => STATE_TYPE, 'from' => 9, 'to' => 6);
    $updates[] = array('type' => STATE_TYPE, 'from' => 8, 'to' => 5);
    foreach ($updates as $data) {
        $query = "UPDATE `glpi_display`\n                SET `num` = " . $data['to'] . "\n                WHERE `num` = " . $data['from'] . "\n                     AND `type` = '" . $data['type'] . "'";
        $DB->queryOrDie($query, "0.72.3 reorder search.constant");
    }
    $LINK_ID_TABLE = array(1 => "glpi_computers", 2 => "glpi_networking", 3 => "glpi_printers", 4 => "glpi_monitors", 5 => "glpi_peripherals", 6 => "glpi_software", 7 => "glpi_contacts", 8 => "glpi_enterprises", 9 => "glpi_infocoms", 10 => "glpi_contracts", 11 => "glpi_cartridges_type", 12 => "glpi_type_docs", 13 => "glpi_docs", 14 => "glpi_kbitems", 15 => "glpi_users", 16 => "glpi_tracking", 17 => "glpi_consumables_type", 18 => "glpi_consumables", 19 => "glpi_cartridges", 20 => "glpi_softwarelicenses", 21 => "glpi_links", 23 => "glpi_phones", 25 => "glpi_reminder", 27 => "glpi_groups", 28 => "glpi_entities", 29 => "glpi_reservation_item", 32 => "glpi_ocs_config", 33 => "glpi_registry", 34 => "glpi_profiles", 35 => "glpi_mailgate", 36 => "glpi_rules_descriptions", 37 => "glpi_transfers", 39 => "glpi_softwareversions", 41 => "glpi_computerdisks", 42 => "glpi_networking_ports", 43 => "glpi_followups");
    $query = "SELECT DISTINCT `device_type`\n             FROM `glpi_doc_device`";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0) {
            while ($data = $DB->fetch_assoc($result)) {
                if (isset($LINK_ID_TABLE[$data['device_type']])) {
                    $table = $LINK_ID_TABLE[$data['device_type']];
                    $query2 = "DELETE\n                          FROM `glpi_doc_device`\n                          WHERE `device_type` = " . $data['device_type'] . "\n                                AND `FK_device` NOT IN (SELECT `ID`\n                                                        FROM `{$table}`)";
                    $DB->queryOrDie($query2, "0.72.3 clean doc_device table");
                }
            }
        }
    }
    if (FieldExists("glpi_auth_ldap", "ldap_group_condition", false)) {
        $query = "ALTER TABLE `glpi_auth_ldap`\n                CHANGE `ldap_group_condition` `ldap_group_condition` TEXT NULL DEFAULT NULL";
        $DB->queryOrDie($query, "0.72.3 alter ldap_group_condition in glpi_auth_ldap");
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("0723");
    // End
}
Exemplo n.º 4
0
function update0722to0723()
{
    global $DB, $CFG_GLPI, $LANG;
    echo "<h3>" . $LANG['install'][4] . " -&gt; 0.72.3</h3>";
    displayMigrationMessage("0723");
    // Start
    //// Correct search.constant numbers : problem in previous update
    $updates = array();
    // serial / otherserial
    $updates[] = array('type' => STATE_TYPE, 'from' => 9, 'to' => 6);
    $updates[] = array('type' => STATE_TYPE, 'from' => 8, 'to' => 5);
    foreach ($updates as $data) {
        $query = "UPDATE `glpi_display` SET num=" . $data['to'] . " WHERE num=" . $data['from'] . " AND type=" . $data['type'] . ";";
        $DB->query($query) or die("0.72.3 reorder search.constant " . $LANG['update'][90] . $DB->error());
    }
    $LINK_ID_TABLE = array(1 => "glpi_computers", 2 => "glpi_networking", 3 => "glpi_printers", 4 => "glpi_monitors", 5 => "glpi_peripherals", 6 => "glpi_software", 7 => "glpi_contacts", 8 => "glpi_enterprises", 9 => "glpi_infocoms", 10 => "glpi_contracts", 11 => "glpi_cartridges_type", 12 => "glpi_type_docs", 13 => "glpi_docs", 14 => "glpi_kbitems", 15 => "glpi_users", 16 => "glpi_tracking", 17 => "glpi_consumables_type", 18 => "glpi_consumables", 19 => "glpi_cartridges", 20 => "glpi_softwarelicenses", 21 => "glpi_links", 23 => "glpi_phones", 25 => "glpi_reminder", 27 => "glpi_groups", 28 => "glpi_entities", 29 => "glpi_reservation_item", 32 => "glpi_ocs_config", 33 => "glpi_registry", 34 => "glpi_profiles", 35 => "glpi_mailgate", 36 => "glpi_rules_descriptions", 37 => "glpi_transfers", 39 => "glpi_softwareversions", 41 => "glpi_computerdisks", 42 => "glpi_networking_ports", 43 => "glpi_followups");
    $query = "SELECT DISTINCT device_type FROM glpi_doc_device";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0) {
            while ($data = $DB->fetch_assoc($result)) {
                if (isset($LINK_ID_TABLE[$data['device_type']])) {
                    $table = $LINK_ID_TABLE[$data['device_type']];
                    $query2 = "DELETE FROM glpi_doc_device\n                        WHERE device_type=" . $data['device_type'] . "\n                           AND FK_device NOT IN (SELECT ID FROM {$table})";
                    $DB->query($query2) or die("0.72.3 clean doc_device table " . $LANG['update'][90] . $DB->error());
                }
            }
        }
    }
    if (FieldExists("glpi_auth_ldap", "ldap_group_condition")) {
        $query = "ALTER TABLE `glpi_auth_ldap` CHANGE `ldap_group_condition` `ldap_group_condition` TEXT NULL DEFAULT NULL;";
        $DB->query($query) or die("0.72.3 alter ldap_group_condition in glpi_auth_ldap" . $LANG['update'][90] . $DB->error());
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("0723");
    // End
}
Exemplo n.º 5
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.º 6
0
function update0721to0722()
{
    global $DB, $CFG_GLPI;
    //TRANS: %s is the number of new version
    echo "<h3>" . sprintf(__('Update to %s'), '0.72.2') . "</h3>";
    displayMigrationMessage("0722");
    // Start
    // Delete state from reservation search
    $query = "DELETE\n             FROM `glpi_display`\n             WHERE `type` = " . RESERVATION_TYPE . "\n                   AND `num` = 31";
    $DB->queryOrDie($query, "0.72.2 delete search of state from reservations");
    // Clean licences alerts
    $query = "DELETE\n             FROM `glpi_alerts`\n             WHERE `device_type` = '" . SOFTWARELICENSE_TYPE . "'";
    $DB->queryOrDie($query, "0.72.2 delete search of state from reservations");
    //// Correct search.constant numbers
    $updates = array();
    // location :
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 3, 'to' => 34);
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 6, 'to' => 3);
    $updates[] = array('type' => CONSUMABLEITEM_TYPE, 'from' => 3, 'to' => 34);
    $updates[] = array('type' => CONSUMABLEITEM_TYPE, 'from' => 6, 'to' => 3);
    $updates[] = array('type' => USER_TYPE, 'from' => 3, 'to' => 34);
    $updates[] = array('type' => USER_TYPE, 'from' => 7, 'to' => 3);
    // serial / otherserial
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 40, 'to' => 46);
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 5, 'to' => 40);
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 8, 'to' => 5);
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 6, 'to' => 45);
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 9, 'to' => 6);
    $updates[] = array('type' => STATE_TYPE, 'from' => 9, 'to' => 6);
    $updates[] = array('type' => STATE_TYPE, 'from' => 8, 'to' => 5);
    // Manufacturer
    $updates[] = array('type' => CONSUMABLEITEM_TYPE, 'from' => 5, 'to' => 23);
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 5, 'to' => 23);
    // tech_num
    $updates[] = array('type' => CONSUMABLEITEM_TYPE, 'from' => 7, 'to' => 24);
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 7, 'to' => 24);
    // date_mod
    $updates[] = array('type' => NETWORKING_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => PRINTER_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => MONITOR_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => PERIPHERAL_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => SOFTWARE_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => PHONE_TYPE, 'from' => 9, 'to' => 19);
    // comments
    $updates[] = array('type' => NETWORKING_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => PRINTER_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => MONITOR_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => PERIPHERAL_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => SOFTWARE_TYPE, 'from' => 6, 'to' => 16);
    $updates[] = array('type' => CONTACT_TYPE, 'from' => 7, 'to' => 16);
    $updates[] = array('type' => ENTERPRISE_TYPE, 'from' => 7, 'to' => 16);
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => DOCUMENT_TYPE, 'from' => 6, 'to' => 16);
    $updates[] = array('type' => USER_TYPE, 'from' => 12, 'to' => 16);
    $updates[] = array('type' => PHONE_TYPE, 'from' => 10, 'to' => 16);
    foreach ($updates as $data) {
        $query = "UPDATE `glpi_display`\n                SET `num` = " . $data['to'] . "\n                WHERE `num` = " . $data['from'] . "\n                      AND `type` = '" . $data['type'] . "'";
        $DB->queryOrDie($query, "0.72.2 reorder search.constant");
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("0722");
    // End
}
Exemplo n.º 7
0
function update0721to0722()
{
    global $DB, $CFG_GLPI, $LANG;
    echo "<h3>" . $LANG['install'][4] . " -&gt; 0.72.2</h3>";
    displayMigrationMessage("0722");
    // Start
    // Delete state from reservation search
    $query = "DELETE FROM `glpi_display` WHERE type=" . RESERVATION_TYPE . " AND num=31;";
    $DB->query($query) or die("0.72.2 delete search of state from reservations" . $LANG['update'][90] . $DB->error());
    // Clean licences alerts
    $query = "DELETE FROM `glpi_alerts` WHERE device_type=" . SOFTWARELICENSE_TYPE . ";";
    $DB->query($query) or die("0.72.2 delete search of state from reservations" . $LANG['update'][90] . $DB->error());
    //// Correct search.constant numbers
    $updates = array();
    // location :
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 3, 'to' => 34);
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 6, 'to' => 3);
    $updates[] = array('type' => CONSUMABLEITEM_TYPE, 'from' => 3, 'to' => 34);
    $updates[] = array('type' => CONSUMABLEITEM_TYPE, 'from' => 6, 'to' => 3);
    $updates[] = array('type' => USER_TYPE, 'from' => 3, 'to' => 34);
    $updates[] = array('type' => USER_TYPE, 'from' => 7, 'to' => 3);
    // serial / otherserial
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 40, 'to' => 46);
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 5, 'to' => 40);
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 8, 'to' => 5);
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 6, 'to' => 45);
    $updates[] = array('type' => COMPUTER_TYPE, 'from' => 9, 'to' => 6);
    $updates[] = array('type' => STATE_TYPE, 'from' => 9, 'to' => 6);
    $updates[] = array('type' => STATE_TYPE, 'from' => 8, 'to' => 5);
    // Manufacturer
    $updates[] = array('type' => CONSUMABLEITEM_TYPE, 'from' => 5, 'to' => 23);
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 5, 'to' => 23);
    // tech_num
    $updates[] = array('type' => CONSUMABLEITEM_TYPE, 'from' => 7, 'to' => 24);
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 7, 'to' => 24);
    // date_mod
    $updates[] = array('type' => NETWORKING_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => PRINTER_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => MONITOR_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => PERIPHERAL_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => SOFTWARE_TYPE, 'from' => 9, 'to' => 19);
    $updates[] = array('type' => PHONE_TYPE, 'from' => 9, 'to' => 19);
    // comments
    $updates[] = array('type' => NETWORKING_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => PRINTER_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => MONITOR_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => PERIPHERAL_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => SOFTWARE_TYPE, 'from' => 6, 'to' => 16);
    $updates[] = array('type' => CONTACT_TYPE, 'from' => 7, 'to' => 16);
    $updates[] = array('type' => ENTERPRISE_TYPE, 'from' => 7, 'to' => 16);
    $updates[] = array('type' => CARTRIDGEITEM_TYPE, 'from' => 10, 'to' => 16);
    $updates[] = array('type' => DOCUMENT_TYPE, 'from' => 6, 'to' => 16);
    $updates[] = array('type' => USER_TYPE, 'from' => 12, 'to' => 16);
    $updates[] = array('type' => PHONE_TYPE, 'from' => 10, 'to' => 16);
    foreach ($updates as $data) {
        $query = "UPDATE `glpi_display` SET num=" . $data['to'] . " WHERE num=" . $data['from'] . " AND type=" . $data['type'] . ";";
        $DB->query($query) or die("0.72.2 reorder search.constant " . $LANG['update'][90] . $DB->error());
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("0722");
    // End
}
Exemplo n.º 8
0
/**
 * Update from 0.78.1 to 0.78.2
 *
 * @param $output string for format
 *       HTML (default) for standard upgrade
 *       empty = no ouput for PHPUnit
 *
 * @return bool for success (will die for most error)
 */
function update0781to0782($output = 'HTML')
{
    global $DB, $LANG;
    $updateresult = true;
    if ($output) {
        echo "<h3>" . $LANG['install'][4] . " -&gt; 0.78.2</h3>";
    }
    displayMigrationMessage("0782");
    // Start
    displayMigrationMessage("0782", $LANG['update'][142]);
    // Updating schema
    /// Add document types
    $types = array('docx' => array('name' => 'Word XML', 'icon' => 'doc-dist.png'), 'xlsx' => array('name' => 'Excel XML', 'icon' => 'xls-dist.png'), 'pptx' => array('name' => 'PowerPoint XML', 'icon' => 'ppt-dist.png'));
    foreach ($types as $ext => $data) {
        $query = "SELECT *\n                FROM `glpi_documenttypes`\n                WHERE `ext` = '{$ext}'";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) == 0) {
                $query = "INSERT INTO `glpi_documenttypes`\n                             (`name`, `ext`, `icon`, `is_uploadable`, `date_mod`)\n                      VALUES ('" . $data['name'] . "', '{$ext}', '" . $data['icon'] . "', '1', NOW())";
                $DB->query($query) or die("0.78.2 add document type {$ext} " . $LANG['update'][90] . $DB->error());
            }
        }
    }
    // Drop nl_be langage
    $query = "UPDATE `glpi_configs`\n             SET `language` = 'nl_NL'\n             WHERE `language` = 'nl_BE';";
    $DB->query($query) or die("0.78.2 drop nl_be langage " . $LANG['update'][90] . $DB->error());
    $query = "UPDATE `glpi_users`\n             SET `language` = 'nl_NL'\n             WHERE `language` = 'nl_BE';";
    $DB->query($query) or die("0.78.2 drop nl_be langage " . $LANG['update'][90] . $DB->error());
    // CLean sl_SL
    $query = "UPDATE `glpi_configs`\n             SET `language` = 'sl_SI'\n             WHERE `language` = 'sl_SL';";
    $DB->query($query) or die("0.78.2 clean sl_SL langage " . $LANG['update'][90] . $DB->error());
    $query = "UPDATE `glpi_users`\n             SET `language` = 'sl_SI'\n             WHERE `language` = 'sl_SL';";
    $DB->query($query) or die("0.78.2 clean sl_SL langage " . $LANG['update'][90] . $DB->error());
    if (isIndex('glpi_computers_items', 'unicity')) {
        $query = "ALTER TABLE `glpi_computers_items` DROP INDEX `unicity`";
        $DB->query($query) or die("0.78.2 drop unicity index for glpi_computers_items " . $LANG['update'][90] . $DB->error());
        $query = "ALTER TABLE `glpi_computers_items` ADD INDEX `item` ( `itemtype` , `items_id` ) ";
        $DB->query($query) or die("0.78.2 add index for glpi_computers_items " . $LANG['update'][90] . $DB->error());
    }
    // For Rule::RULE_TRACKING_AUTO_ACTION
    $changes['RuleMailCollector'] = array('X-Priority' => 'x-priority');
    $DB->query("SET SESSION group_concat_max_len = 9999999;");
    foreach ($changes as $ruletype => $tab) {
        // Get rules
        $query = "SELECT GROUP_CONCAT(`id`)\n                FROM `glpi_rules`\n                WHERE `sub_type` = '" . $ruletype . "'\n                GROUP BY `sub_type`";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                // Get rule string
                $rules = $DB->result($result, 0, 0);
                // Update actions
                foreach ($tab as $old => $new) {
                    $query = "UPDATE `glpi_ruleactions`\n                         SET `field` = '{$new}'\n                         WHERE `field` = '{$old}'\n                               AND `rules_id` IN ({$rules})";
                    $DB->query($query) or die("0.78.2 update datas for rules actions " . $LANG['update'][90] . $DB->error());
                }
                // Update criterias
                foreach ($tab as $old => $new) {
                    $query = "UPDATE `glpi_rulecriterias`\n                         SET `criteria` = '{$new}'\n                         WHERE `criteria` = '{$old}'\n                               AND `rules_id` IN ({$rules})";
                    $DB->query($query) or die("0.78.2 update datas for rules criterias " . $LANG['update'][90] . $DB->error());
                }
            }
        }
    }
    // Reorder ranking : start with 1
    $query = " SELECT DISTINCT `sub_type` \n               FROM `glpi_rules` \n               WHERE ranking = '0'";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0) {
            while ($data = $DB->fetch_assoc($result)) {
                $query = "UPDATE `glpi_rules` \n                        SET `ranking` = ranking +1 \n                        WHERE `sub_type` = '" . $data['sub_type'] . "';";
                $DB->query($query) or die("0.78.2 reorder rule ranking for " . $data['sub_type'] . " " . $LANG['update'][90] . $DB->error());
            }
        }
    }
    // Check existing rule
    if (countElementsInTable('glpi_rulecriterias', "`criteria` IN ('auto-submitted','x-auto-response-suppress')") == 0) {
        /// Reorder ranking
        $query = "UPDATE `glpi_rules` \n                  SET `ranking` = ranking +2 \n                  WHERE `sub_type` = 'RuleMailCollector';";
        $DB->query($query) or die("0.78.2 reorder rule ranking for RuleMailCollector " . $LANG['update'][90] . $DB->error());
        /// Insert new rule
        $query = "INSERT INTO `glpi_rules`\n                        (`entities_id`, `sub_type`, `ranking`, `name`,\n                        `description`, `match`, `is_active`, `date_mod`, `is_recursive`)\n                  VALUES ('0', 'RuleMailCollector', '1', 'Auto-Reply X-Auto-Response-Suppress',\n                        'Exclude Auto-Reply emails using X-Auto-Response-Suppress header', 'AND', 0, NOW(), 1)";
        $DB->query($query) or die("0.78.2 add new rule RuleMailCollector " . $LANG['update'][90] . $DB->error());
        $rule_id = $DB->insert_id();
        /// Insert criteria and action
        $query = "INSERT INTO `glpi_rulecriterias`\n                        (`rules_id`, `criteria`, `condition`, `pattern`)\n                  VALUES ('{$rule_id}', 'x-auto-response-suppress', '6', '/\\\\S+/')";
        $DB->query($query) or die("0.78.2 add new criteria RuleMailCollector " . $LANG['update'][90] . $DB->error());
        $query = "INSERT INTO `glpi_ruleactions`\n                        (`rules_id`, `action_type`, `field`, `value`)\n                  VALUES ('{$rule_id}', 'assign', '_refuse_email_no_response', '1')";
        $DB->query($query) or die("0.78.2 add new action RuleMailCollector " . $LANG['update'][90] . $DB->error());
        /// Insert new rule
        $query = "INSERT INTO `glpi_rules`\n                        (`entities_id`, `sub_type`, `ranking`, `name`,\n                        `description`, `match`, `is_active`, `date_mod`, `is_recursive`)\n                  VALUES ('0', 'RuleMailCollector', '2', 'Auto-Reply Auto-Submitted',\n                        'Exclude Auto-Reply emails using Auto-Submitted header', 'AND', 0, NOW(), 1)";
        $DB->query($query) or die("0.78.2 add new rule RuleMailCollector " . $LANG['update'][90] . $DB->error());
        $rule_id = $DB->insert_id();
        /// Insert criteria and action
        $query = "INSERT INTO `glpi_rulecriterias`\n                        (`rules_id`, `criteria`, `condition`, `pattern`)\n                  VALUES ('{$rule_id}', 'auto-submitted', '6', '/\\\\S+/')";
        $DB->query($query) or die("0.78.2 add new criteria RuleMailCollector " . $LANG['update'][90] . $DB->error());
        $query = "INSERT INTO `glpi_rulecriterias`\n                        (`rules_id`, `criteria`, `condition`, `pattern`)\n                  VALUES ('{$rule_id}', 'auto-submitted', '1', 'no')";
        $DB->query($query) or die("0.78.2 add new criteria RuleMailCollector " . $LANG['update'][90] . $DB->error());
        $query = "INSERT INTO `glpi_ruleactions`\n                        (`rules_id`, `action_type`, `field`, `value`)\n                  VALUES ('{$rule_id}', 'assign', '_refuse_email_no_response', '1')";
        $DB->query($query) or die("0.78.2 add new action RuleMailCollector " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_ocsservers', 'ocs_db_utf8')) {
        $query = "ALTER TABLE `glpi_ocsservers`\n                ADD `ocs_db_utf8` tinyint(1) NOT NULL default '0' AFTER `ocs_db_name`";
        $DB->query($query) or die("0.78.2 add ocs_db_utf8 in glpi_ocsservers" . $LANG['update'][90] . $DB->error());
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("0782");
    // End
    return $updateresult;
}
Exemplo n.º 9
0
/**
 * Update from 0.78 to 0.78.1
 *
 * @param $output string for format
 *       HTML (default) for standard upgrade
 *       empty = no ouput for PHPUnit
 *
 * @return bool for success (will die for most error)
 */
function update078to0781($output = 'HTML')
{
    global $DB, $LANG;
    $updateresult = true;
    if ($output) {
        echo "<h3>" . $LANG['install'][4] . " -&gt; 0.78.1</h3>";
    }
    displayMigrationMessage("0781");
    // Start
    displayMigrationMessage("0781", $LANG['update'][142] . ' - Clean reservation entity link');
    // Updating schema
    $entities = getAllDatasFromTable('glpi_entities');
    $entities[0] = "Root";
    $query = "SELECT DISTINCT `itemtype` FROM `glpi_reservationitems`";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0) {
            while ($data = $DB->fetch_assoc($result)) {
                $itemtable = getTableForItemType($data['itemtype']);
                // ajout d'un contrôle pour voir si la table existe ( cas migration plugin non fait)
                if (!TableExists($itemtable)) {
                    if ($output) {
                        echo "<p class='red'>*** Skip : no table {$itemtable} ***</p>";
                    }
                    continue;
                }
                $do_recursive = false;
                if (FieldExists($itemtable, 'is_recursive')) {
                    $do_recursive = true;
                }
                foreach ($entities as $entID => $val) {
                    if ($do_recursive) {
                        // Non recursive ones
                        $query3 = "UPDATE `glpi_reservationitems`\n                           SET `entities_id`={$entID}, `is_recursive`=0\n                           WHERE `itemtype`='" . $data['itemtype'] . "'\n                              AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                              WHERE `entities_id`={$entID} AND `is_recursive`=0)";
                        $DB->query($query3) or die("0.78.1 update entities_id and is_recursive=0\n                        in glpi_reservationitems for " . $data['itemtype'] . " " . $LANG['update'][90] . $DB->error());
                        // Recursive ones
                        $query3 = "UPDATE `glpi_reservationitems`\n                           SET `entities_id`={$entID}, `is_recursive`=1\n                           WHERE `itemtype`='" . $data['itemtype'] . "'\n                              AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                              WHERE `entities_id`={$entID} AND `is_recursive`=1)";
                        $DB->query($query3) or die("0.78.1 update entities_id and is_recursive=1\n                        in glpi_reservationitems for " . $data['itemtype'] . " " . $LANG['update'][90] . $DB->error());
                    } else {
                        $query3 = "UPDATE `glpi_reservationitems`\n                           SET `entities_id`={$entID}\n                           WHERE `itemtype`='" . $data['itemtype'] . "'\n                              AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                              WHERE `entities_id`={$entID})";
                        $DB->query($query3) or die("0.78.1 update entities_id in glpi_reservationitems\n                        for " . $data['itemtype'] . " " . $LANG['update'][90] . $DB->error());
                    }
                }
            }
        }
    }
    $query = "ALTER TABLE `glpi_tickets`\n             CHANGE `global_validation` `global_validation` VARCHAR(255) DEFAULT 'none'";
    $DB->query($query) or die("0.78.1 change ticket global_validation default state");
    $query = "UPDATE `glpi_tickets`\n             SET `global_validation`='none'\n             WHERE `id` NOT IN (SELECT DISTINCT `tickets_id`\n                                FROM `glpi_ticketvalidations`)";
    $DB->query($query) or die("0.78.1 update ticket global_validation state");
    if (!FieldExists('glpi_knowbaseitemcategories', 'entities_id')) {
        $query = "ALTER TABLE `glpi_knowbaseitemcategories`\n                    ADD `entities_id` INT NOT NULL DEFAULT '0' AFTER `id`,\n                    ADD `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `entities_id`,\n                    ADD INDEX `entities_id` (`entities_id`),ADD INDEX `is_recursive` (`is_recursive`)";
        $DB->query($query) or die("0.78.1 add entities_id,is_recursive in glpi_knowbaseitemcategories" . $LANG['update'][90] . $DB->error());
        // Set existing categories recursive global
        $query = "UPDATE `glpi_knowbaseitemcategories` SET `is_recursive` = '1'";
        $DB->query($query) or die("0.78.1 set value of is_recursive in glpi_knowbaseitemcategories" . $LANG['update'][90] . $DB->error());
        $query = "ALTER TABLE `glpi_knowbaseitemcategories` DROP INDEX `unicity` ,\n               ADD UNIQUE `unicity` ( `entities_id`, `knowbaseitemcategories_id` , `name` ) ";
        $DB->query($query) or die("0.78.1 update unicity index on glpi_knowbaseitemcategories" . $LANG['update'][90] . $DB->error());
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("0781");
    // End
    return $updateresult;
}
Exemplo n.º 10
0
/**
 * Update from 0.72.3 to 0.78
 *
 * @param $output string for format
 *       HTML (default) for standard upgrade
 *       empty = no ouput for PHPUnit
 *
 * @return bool for success (will die for most error)
 */
function update0723to078($output = 'HTML')
{
    global $DB, $LANG;
    $updateresult = true;
    if ($output) {
        echo "<h3>" . $LANG['install'][4] . " -&gt; 0.78</h3>";
    }
    displayMigrationMessage("078");
    // Start
    displayMigrationMessage("078", $LANG['update'][141] . ' - Clean DB : rename tables');
    // Updating schema
    $changes = array();
    $glpi_tables = array('glpi_alerts' => 'glpi_alerts', 'glpi_auth_ldap' => 'glpi_authldaps', 'glpi_auth_ldap_replicate' => 'glpi_authldapreplicates', 'glpi_auth_mail' => 'glpi_authmails', 'glpi_dropdown_auto_update' => 'glpi_autoupdatesystems', 'glpi_bookmark' => 'glpi_bookmarks', 'glpi_display_default' => 'glpi_bookmarks_users', 'glpi_dropdown_budget' => 'glpi_budgets', 'glpi_cartridges' => 'glpi_cartridges', 'glpi_cartridges_type' => 'glpi_cartridgeitems', 'glpi_cartridges_assoc' => 'glpi_cartridges_printermodels', 'glpi_dropdown_cartridge_type' => 'glpi_cartridgeitemtypes', 'glpi_computers' => 'glpi_computers', 'glpi_computerdisks' => 'glpi_computerdisks', 'glpi_dropdown_model' => 'glpi_computermodels', 'glpi_type_computers' => 'glpi_computertypes', 'glpi_connect_wire' => 'glpi_computers_items', 'glpi_inst_software' => 'glpi_computers_softwareversions', 'glpi_config' => 'glpi_configs', 'glpi_consumables' => 'glpi_consumables', 'glpi_consumables_type' => 'glpi_consumableitems', 'glpi_dropdown_consumable_type' => 'glpi_consumableitemtypes', 'glpi_contact_enterprise' => 'glpi_contacts_suppliers', 'glpi_contacts' => 'glpi_contacts', 'glpi_dropdown_contact_type' => 'glpi_contacttypes', 'glpi_contracts' => 'glpi_contracts', 'glpi_dropdown_contract_type' => 'glpi_contracttypes', 'glpi_contract_device' => 'glpi_contracts_items', 'glpi_contract_enterprise' => 'glpi_contracts_suppliers', 'glpi_device_case' => 'glpi_devicecases', 'glpi_dropdown_case_type' => 'glpi_devicecasetypes', 'glpi_device_control' => 'glpi_devicecontrols', 'glpi_device_drive' => 'glpi_devicedrives', 'glpi_device_gfxcard' => 'glpi_devicegraphiccards', 'glpi_device_hdd' => 'glpi_deviceharddrives', 'glpi_device_iface' => 'glpi_devicenetworkcards', 'glpi_device_moboard' => 'glpi_devicemotherboards', 'glpi_device_pci' => 'glpi_devicepcis', 'glpi_device_power' => 'glpi_devicepowersupplies', 'glpi_device_processor' => 'glpi_deviceprocessors', 'glpi_device_ram' => 'glpi_devicememories', 'glpi_dropdown_ram_type' => 'glpi_devicememorytypes', 'glpi_device_sndcard' => 'glpi_devicesoundcards', 'glpi_display' => 'glpi_displaypreferences', 'glpi_docs' => 'glpi_documents', 'glpi_dropdown_rubdocs' => 'glpi_documentcategories', 'glpi_type_docs' => 'glpi_documenttypes', 'glpi_doc_device' => 'glpi_documents_items', 'glpi_dropdown_domain' => 'glpi_domains', 'glpi_entities' => 'glpi_entities', 'glpi_entities_data' => 'glpi_entitydatas', 'glpi_event_log' => 'glpi_events', 'glpi_dropdown_filesystems' => 'glpi_filesystems', 'glpi_groups' => 'glpi_groups', 'glpi_users_groups' => 'glpi_groups_users', 'glpi_infocoms' => 'glpi_infocoms', 'glpi_dropdown_interface' => 'glpi_interfacetypes', 'glpi_kbitems' => 'glpi_knowbaseitems', 'glpi_dropdown_kbcategories' => 'glpi_knowbaseitemcategories', 'glpi_links' => 'glpi_links', 'glpi_links_device' => 'glpi_links_itemtypes', 'glpi_dropdown_locations' => 'glpi_locations', 'glpi_history' => 'glpi_logs', 'glpi_mailgate' => 'glpi_mailcollectors', 'glpi_mailing' => 'glpi_mailingsettings', 'glpi_dropdown_manufacturer' => 'glpi_manufacturers', 'glpi_monitors' => 'glpi_monitors', 'glpi_dropdown_model_monitors' => 'glpi_monitormodels', 'glpi_type_monitors' => 'glpi_monitortypes', 'glpi_dropdown_netpoint' => 'glpi_netpoints', 'glpi_networking' => 'glpi_networkequipments', 'glpi_dropdown_firmware' => 'glpi_networkequipmentfirmwares', 'glpi_dropdown_model_networking' => 'glpi_networkequipmentmodels', 'glpi_type_networking' => 'glpi_networkequipmenttypes', 'glpi_dropdown_iface' => 'glpi_networkinterfaces', 'glpi_networking_ports' => 'glpi_networkports', 'glpi_networking_vlan' => 'glpi_networkports_vlans', 'glpi_networking_wire' => 'glpi_networkports_networkports', 'glpi_dropdown_network' => 'glpi_networks', 'glpi_ocs_admin_link' => 'glpi_ocsadmininfoslinks', 'glpi_ocs_link' => 'glpi_ocslinks', 'glpi_ocs_config' => 'glpi_ocsservers', 'glpi_dropdown_os' => 'glpi_operatingsystems', 'glpi_dropdown_os_sp' => 'glpi_operatingsystemservicepacks', 'glpi_dropdown_os_version' => 'glpi_operatingsystemversions', 'glpi_peripherals' => 'glpi_peripherals', 'glpi_dropdown_model_peripherals' => 'glpi_peripheralmodels', 'glpi_type_peripherals' => 'glpi_peripheraltypes', 'glpi_phones' => 'glpi_phones', 'glpi_dropdown_model_phones' => 'glpi_phonemodels', 'glpi_dropdown_phone_power' => 'glpi_phonepowersupplies', 'glpi_type_phones' => 'glpi_phonetypes', 'glpi_plugins' => 'glpi_plugins', 'glpi_printers' => 'glpi_printers', 'glpi_dropdown_model_printers' => 'glpi_printermodels', 'glpi_type_printers' => 'glpi_printertypes', 'glpi_profiles' => 'glpi_profiles', 'glpi_users_profiles' => 'glpi_profiles_users', 'glpi_registry' => 'glpi_registrykeys', 'glpi_reminder' => 'glpi_reminders', 'glpi_reservation_resa' => 'glpi_reservations', 'glpi_reservation_item' => 'glpi_reservationitems', 'glpi_rules_descriptions' => 'glpi_rules', 'glpi_rules_actions' => 'glpi_ruleactions', 'glpi_rule_cache_model_computer' => 'glpi_rulecachecomputermodels', 'glpi_rule_cache_type_computer' => 'glpi_rulecachecomputertypes', 'glpi_rule_cache_manufacturer' => 'glpi_rulecachemanufacturers', 'glpi_rule_cache_model_monitor' => 'glpi_rulecachemonitormodels', 'glpi_rule_cache_type_monitor' => 'glpi_rulecachemonitortypes', 'glpi_rule_cache_model_networking' => 'glpi_rulecachenetworkequipmentmodels', 'glpi_rule_cache_type_networking' => 'glpi_rulecachenetworkequipmenttypes', 'glpi_rule_cache_os' => 'glpi_rulecacheoperatingsystems', 'glpi_rule_cache_os_sp' => 'glpi_rulecacheoperatingsystemservicepacks', 'glpi_rule_cache_os_version' => 'glpi_rulecacheoperatingsystemversions', 'glpi_rule_cache_model_peripheral' => 'glpi_rulecacheperipheralmodels', 'glpi_rule_cache_type_peripheral' => 'glpi_rulecacheperipheraltypes', 'glpi_rule_cache_model_phone' => 'glpi_rulecachephonemodels', 'glpi_rule_cache_type_phone' => 'glpi_rulecachephonetypes', 'glpi_rule_cache_model_printer' => 'glpi_rulecacheprintermodels', 'glpi_rule_cache_type_printer' => 'glpi_rulecacheprintertypes', 'glpi_rule_cache_software' => 'glpi_rulecachesoftwares', 'glpi_rules_criterias' => 'glpi_rulecriterias', 'glpi_rules_ldap_parameters' => 'glpi_rulerightparameters', 'glpi_software' => 'glpi_softwares', 'glpi_dropdown_software_category' => 'glpi_softwarecategories', 'glpi_softwarelicenses' => 'glpi_softwarelicenses', 'glpi_dropdown_licensetypes' => 'glpi_softwarelicensetypes', 'glpi_softwareversions' => 'glpi_softwareversions', 'glpi_dropdown_state' => 'glpi_states', 'glpi_enterprises' => 'glpi_suppliers', 'glpi_dropdown_enttype' => 'glpi_suppliertypes', 'glpi_tracking' => 'glpi_tickets', 'glpi_dropdown_tracking_category' => 'glpi_ticketcategories', 'glpi_followups' => 'glpi_ticketfollowups', 'glpi_tracking_planning' => 'glpi_ticketplannings', 'glpi_transfers' => 'glpi_transfers', 'glpi_users' => 'glpi_users', 'glpi_dropdown_user_titles' => 'glpi_usertitles', 'glpi_dropdown_user_types' => 'glpi_usercategories', 'glpi_dropdown_vlan' => 'glpi_vlans');
    $backup_tables = false;
    foreach ($glpi_tables as $original_table => $new_table) {
        if (strcmp($original_table, $new_table) != 0) {
            // Original table exists ?
            if (TableExists($original_table)) {
                // rename new tables if exists ?
                if (TableExists($new_table)) {
                    if (TableExists("backup_{$new_table}")) {
                        $query = "DROP TABLE `backup_" . $new_table . "`";
                        $DB->query($query) or die("0.78 drop backup table backup_{$new_table} " . $LANG['update'][90] . $DB->error());
                    }
                    if ($output) {
                        echo "<p><b>{$new_table} table already exists. ";
                        echo "A backup have been done to backup_{$new_table}.</b></p>";
                    }
                    $backup_tables = true;
                    $query = "RENAME TABLE `{$new_table}` TO `backup_{$new_table}`";
                    $DB->query($query) or die("0.78 backup table {$new_table} " . $LANG['update'][90] . $DB->error());
                }
                // rename original table
                $query = "RENAME TABLE `{$original_table}` TO `{$new_table}`";
                $DB->query($query) or die("0.78 rename {$original_table} to {$new_table} " . $LANG['update'][90] . $DB->error());
            }
        }
        if (FieldExists($new_table, 'ID')) {
            // ALTER ID -> id
            $changes[$new_table][] = "CHANGE `ID` `id` INT( 11 ) NOT NULL AUTO_INCREMENT";
        }
    }
    if ($backup_tables && $output) {
        echo "<div class='red'><p>You can delete backup tables if you have no need of them.</p></div>";
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - Clean DB : rename foreign keys');
    // Updating schema
    $foreignkeys = array('assign' => array(array('to' => 'users_id_assign', 'tables' => array('glpi_tickets'))), 'assign_group' => array(array('to' => 'groups_id_assign', 'tables' => array('glpi_tickets'))), 'assign_ent' => array(array('to' => 'suppliers_id_assign', 'tables' => array('glpi_tickets'))), 'auth_method' => array(array('to' => 'authtype', 'noindex' => array('glpi_users'), 'tables' => array('glpi_users'))), 'author' => array(array('to' => 'users_id', 'tables' => array('glpi_ticketfollowups', 'glpi_knowbaseitems', 'glpi_tickets'))), 'auto_update' => array(array('to' => 'autoupdatesystems_id', 'tables' => array('glpi_computers'))), 'budget' => array(array('to' => 'budgets_id', 'tables' => array('glpi_infocoms'))), 'buy_version' => array(array('to' => 'softwareversions_id_buy', 'tables' => array('glpi_softwarelicenses'))), 'category' => array(array('to' => 'ticketcategories_id', 'tables' => array('glpi_tickets')), array('to' => 'softwarecategories_id', 'tables' => array('glpi_softwares'))), 'categoryID' => array(array('to' => 'knowbaseitemcategories_id', 'tables' => array('glpi_knowbaseitems'))), 'category_on_software_delete' => array(array('to' => 'softwarecategories_id_ondelete', 'noindex' => array('glpi_configs'), 'tables' => array('glpi_configs'), 'comments' => array('glpi_configs' => 'category applyed when a software is deleted'))), 'cID' => array(array('to' => 'computers_id', 'tables' => array('glpi_computers_softwareversions'))), 'computer' => array(array('to' => 'items_id', 'noindex' => array('glpi_tickets'), 'tables' => array('glpi_tickets'))), 'computer_id' => array(array('to' => 'computers_id', 'tables' => array('glpi_registrykeys'))), 'contract_type' => array(array('to' => 'contracttypes_id', 'tables' => array('glpi_contracts'))), 'default_rubdoc_tracking' => array(array('to' => 'documentcategories_id_forticket', 'noindex' => array('glpi_configs'), 'tables' => array('glpi_configs'), 'comments' => array('glpi_configs' => 'default category for documents added with a ticket'))), 'default_state' => array(array('to' => 'states_id_default', 'noindex' => array('glpi_ocsservers'), 'tables' => array('glpi_ocsservers'))), 'device_type' => array(array('to' => 'itemtype', 'noindex' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_bookmarks_users', 'glpi_documents_items', 'glpi_infocoms', 'glpi_links_itemtypes', 'glpi_networkports', 'glpi_reservationitems', 'glpi_tickets'), 'tables' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms', 'glpi_bookmarks', 'glpi_bookmarks_users', 'glpi_links_itemtypes', 'glpi_networkports', 'glpi_reservationitems', 'glpi_tickets'))), 'domain' => array(array('to' => 'domains_id', 'tables' => array('glpi_computers', 'glpi_networkequipments', 'glpi_printers'))), 'end1' => array(array('to' => 'items_id', 'noindex' => array('glpi_computers_items'), 'tables' => array('glpi_computers_items'), 'comments' => array('glpi_computers_items' => 'RELATION to various table, according to itemtype (ID)')), array('to' => 'networkports_id_1', 'noindex' => array('glpi_networkports_networkports'), 'tables' => array('glpi_networkports_networkports'))), 'end2' => array(array('to' => 'computers_id', 'tables' => array('glpi_computers_items')), array('to' => 'networkports_id_2', 'tables' => array('glpi_networkports_networkports'))), 'extra_ldap_server' => array(array('to' => 'authldaps_id_extra', 'noindex' => array('glpi_configs'), 'tables' => array('glpi_configs'), 'comments' => array('glpi_configs' => 'extra server'))), 'firmware' => array(array('to' => 'networkequipmentfirmwares_id', 'tables' => array('glpi_networkequipments'))), 'FK_bookmark' => array(array('to' => 'bookmarks_id', 'tables' => array('glpi_bookmarks_users'))), 'FK_computers' => array(array('to' => 'computers_id', 'tables' => array('glpi_computerdisks', 'glpi_softwarelicenses'))), 'FK_contact' => array(array('to' => 'contacts_id', 'tables' => array('glpi_contacts_suppliers'))), 'FK_contract' => array(array('to' => 'contracts_id', 'noindex' => array('glpi_contracts_items'), 'tables' => array('glpi_contracts_suppliers', 'glpi_contracts_items'))), 'FK_device' => array(array('to' => 'items_id', 'noindex' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms'), 'tables' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms'))), 'FK_doc' => array(array('to' => 'documents_id', 'noindex' => array('glpi_documents_items'), 'tables' => array('glpi_documents_items'))), 'FK_enterprise' => array(array('to' => 'suppliers_id', 'noindex' => array('glpi_contacts_suppliers', 'glpi_contracts_suppliers'), 'tables' => array('glpi_contacts_suppliers', 'glpi_contracts_suppliers', 'glpi_infocoms'))), 'FK_entities' => array(array('to' => 'entities_id', 'noindex' => array('glpi_locations', 'glpi_netpoints', 'glpi_entitydatas'), 'tables' => array('glpi_bookmarks', 'glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_locations', 'glpi_netpoints', 'glpi_suppliers', 'glpi_entitydatas', 'glpi_groups', 'glpi_knowbaseitems', 'glpi_links', 'glpi_mailcollectors', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_reminders', 'glpi_rules', 'glpi_softwares', 'glpi_softwarelicenses', 'glpi_tickets', 'glpi_users', 'glpi_profiles_users'), 'default' => array('glpi_bookmarks' => "-1"))), 'FK_filesystems' => array(array('to' => 'filesystems_id', 'tables' => array('glpi_computerdisks'))), 'FK_glpi_cartridges_type' => array(array('to' => 'cartridgeitems_id', 'tables' => array('glpi_cartridges', 'glpi_cartridges_printermodels'))), 'FK_glpi_consumables_type' => array(array('to' => 'consumableitems_id', 'noindex' => array(''), 'tables' => array('glpi_consumables'))), 'FK_glpi_dropdown_model_printers' => array(array('to' => 'printermodels_id', 'noindex' => array('glpi_cartridges_printermodels'), 'tables' => array('glpi_cartridges_printermodels'))), 'FK_glpi_enterprise' => array(array('to' => 'manufacturers_id', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_devicecases', 'glpi_devicecontrols', 'glpi_devicedrives', 'glpi_devicegraphiccards', 'glpi_deviceharddrives', 'glpi_devicenetworkcards', 'glpi_devicemotherboards', 'glpi_devicepcis', 'glpi_devicepowersupplies', 'glpi_deviceprocessors', 'glpi_devicememories', 'glpi_devicesoundcards', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'FK_glpi_printers' => array(array('to' => 'printers_id', 'tables' => array('glpi_cartridges'))), 'FK_group' => array(array('to' => 'groups_id', 'tables' => array('glpi_tickets'))), 'FK_groups' => array(array('to' => 'groups_id', 'tables' => array('glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares', 'glpi_groups_users'))), 'FK_interface' => array(array('to' => 'interfacetypes_id', 'tables' => array('glpi_devicegraphiccards'))), 'FK_item' => array(array('to' => 'items_id', 'noindex' => array('glpi_mailingsettings'), 'tables' => array('glpi_mailingsettings'))), 'FK_links' => array(array('to' => 'links_id', 'tables' => array('glpi_links_itemtypes'))), 'FK_port' => array(array('to' => 'networkports_id', 'noindex' => array('glpi_networkports_vlans'), 'tables' => array('glpi_networkports_vlans'))), 'FK_profiles' => array(array('to' => 'profiles_id', 'tables' => array('glpi_profiles_users', 'glpi_users'))), 'FK_rules' => array(array('to' => 'rules_id', 'tables' => array('glpi_rulecriterias', 'glpi_ruleactions'))), 'FK_tracking' => array(array('to' => 'tickets_id', 'tables' => array('glpi_documents'))), 'FK_users' => array(array('to' => 'users_id', 'noindex' => array('glpi_displaypreferences', 'glpi_bookmarks_users', 'glpi_groups_users'), 'tables' => array('glpi_bookmarks', 'glpi_displaypreferences', 'glpi_documents', 'glpi_groups', 'glpi_reminders', 'glpi_bookmarks_users', 'glpi_groups_users', 'glpi_profiles_users', 'glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'FK_vlan' => array(array('to' => 'vlans_id', 'tables' => array('glpi_networkports_vlans'))), 'glpi_id' => array(array('to' => 'computers_id', 'tables' => array('glpi_ocslinks'))), 'id_assign' => array(array('to' => 'users_id', 'tables' => array('glpi_ticketplannings'))), 'id_auth' => array(array('to' => 'auths_id', 'noindex' => array('glpi_users'), 'tables' => array('glpi_users'))), 'id_device' => array(array('to' => 'items_id', 'noindex' => array('glpi_reservationitems'), 'tables' => array('glpi_reservationitems'))), 'id_followup' => array(array('to' => 'ticketfollowups_id', 'tables' => array('glpi_ticketplannings'))), 'id_item' => array(array('to' => 'reservationitems_id', 'tables' => array('glpi_reservations'))), 'id_user' => array(array('to' => 'users_id', 'tables' => array('glpi_consumables', 'glpi_reservations'))), 'iface' => array(array('to' => 'networkinterfaces_id', 'tables' => array('glpi_networkports'))), 'interface' => array(array('to' => 'interfacetypes_id', 'tables' => array('glpi_devicecontrols', 'glpi_deviceharddrives', 'glpi_devicedrives'))), 'item' => array(array('to' => 'items_id', 'noindex' => array('glpi_events'), 'tables' => array('glpi_events'))), 'link_if_status' => array(array('to' => 'states_id_linkif', 'noindex' => array('glpi_ocsservers'), 'tables' => array('glpi_ocsservers'))), 'location' => array(array('to' => 'locations_id', 'noindex' => array('glpi_netpoints'), 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_netpoints', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_users', 'glpi_softwares'))), 'model' => array(array('to' => 'computermodels_id', 'tables' => array('glpi_computers')), array('to' => 'monitormodels_id', 'tables' => array('glpi_monitors')), array('to' => 'networkequipmentmodels_id', 'tables' => array('glpi_networkequipments')), array('to' => 'peripheralmodels_id', 'tables' => array('glpi_peripherals')), array('to' => 'phonemodels_id', 'tables' => array('glpi_phones')), array('to' => 'printermodels_id', 'tables' => array('glpi_printers'))), 'netpoint' => array(array('to' => 'netpoints_id', 'tables' => array('glpi_networkports'))), 'network' => array(array('to' => 'networks_id', 'tables' => array('glpi_computers', 'glpi_networkequipments', 'glpi_printers'))), 'ocs_id' => array(array('to' => 'ocsid', 'noindex' => array('glpi_ocslinks'), 'tables' => array('glpi_ocslinks'))), 'ocs_server_id' => array(array('to' => 'ocsservers_id', 'noindex' => array('glpi_ocslinks'), 'tables' => array('glpi_ocsadmininfoslinks', 'glpi_ocslinks'))), 'on_device' => array(array('to' => 'items_id', 'noindex' => array('glpi_networkports'), 'tables' => array('glpi_networkports'))), 'os' => array(array('to' => 'operatingsystems_id', 'tables' => array('glpi_computers'))), 'os_sp' => array(array('to' => 'operatingsystemservicepacks_id', 'tables' => array('glpi_computers'))), 'os_version' => array(array('to' => 'operatingsystemversions_id', 'tables' => array('glpi_computers'))), 'parentID' => array(array('to' => 'knowbaseitemcategories_id', 'noindex' => array('glpi_knowbaseitemcategories'), 'tables' => array('glpi_knowbaseitemcategories')), array('to' => 'locations_id', 'tables' => array('glpi_locations')), array('to' => 'ticketcategories_id', 'tables' => array('glpi_ticketcategories')), array('to' => 'entities_id', 'tables' => array('glpi_entities'))), 'platform' => array(array('to' => 'operatingsystems_id', 'tables' => array('glpi_softwares'))), 'power' => array(array('to' => 'phonepowersupplies_id', 'tables' => array('glpi_phones'))), 'recipient' => array(array('to' => 'users_id_recipient', 'tables' => array('glpi_tickets'))), 'rubrique' => array(array('to' => 'documentcategories_id', 'tables' => array('glpi_documents'))), 'rule_id' => array(array('to' => 'rules_id', 'tables' => array('glpi_rulecachemanufacturers', 'glpi_rulecachecomputermodels', 'glpi_rulecachemonitormodels', 'glpi_rulecachenetworkequipmentmodels', 'glpi_rulecacheperipheralmodels', 'glpi_rulecachephonemodels', 'glpi_rulecacheprintermodels', 'glpi_rulecacheoperatingsystems', 'glpi_rulecacheoperatingsystemservicepacks', 'glpi_rulecacheoperatingsystemversions', 'glpi_rulecachesoftwares', 'glpi_rulecachecomputertypes', 'glpi_rulecachemonitortypes', 'glpi_rulecachenetworkequipmenttypes', 'glpi_rulecacheperipheraltypes', 'glpi_rulecachephonetypes', 'glpi_rulecacheprintertypes'))), 'server_id' => array(array('to' => 'authldaps_id', 'tables' => array('glpi_authldapreplicates'))), 'sID' => array(array('to' => 'softwares_id', 'tables' => array('glpi_softwarelicenses', 'glpi_softwareversions'))), 'state' => array(array('to' => 'states_id', 'tables' => array('glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwareversions'))), 'tech_num' => array(array('to' => 'users_id_tech', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'title' => array(array('to' => 'usertitles_id', 'tables' => array('glpi_users'))), 'tracking' => array(array('to' => 'tickets_id', 'tables' => array('glpi_ticketfollowups'))), 'type' => array(array('to' => 'cartridgeitemtypes_id', 'tables' => array('glpi_cartridgeitems')), array('to' => 'computertypes_id', 'tables' => array('glpi_computers')), array('to' => 'consumableitemtypes_id', 'tables' => array('glpi_consumableitems')), array('to' => 'contacttypes_id', 'tables' => array('glpi_contacts')), array('to' => 'devicecasetypes_id', 'tables' => array('glpi_devicecases')), array('to' => 'devicememorytypes_id', 'tables' => array('glpi_devicememories')), array('to' => 'suppliertypes_id', 'tables' => array('glpi_suppliers')), array('to' => 'monitortypes_id', 'tables' => array('glpi_monitors')), array('to' => 'networkequipmenttypes_id', 'tables' => array('glpi_networkequipments')), array('to' => 'peripheraltypes_id', 'tables' => array('glpi_peripherals')), array('to' => 'phonetypes_id', 'tables' => array('glpi_phones')), array('to' => 'printertypes_id', 'tables' => array('glpi_printers')), array('to' => 'softwarelicensetypes_id', 'tables' => array('glpi_softwarelicenses')), array('to' => 'usercategories_id', 'tables' => array('glpi_users')), array('to' => 'itemtype', 'noindex' => array('glpi_computers_items'), 'tables' => array('glpi_computers_items', 'glpi_displaypreferences'))), 'update_software' => array(array('to' => 'softwares_id', 'tables' => array('glpi_softwares'))), 'use_version' => array(array('to' => 'softwareversions_id_use', 'tables' => array('glpi_softwarelicenses'))), 'vID' => array(array('to' => 'softwareversions_id', 'tables' => array('glpi_computers_softwareversions'))));
    foreach ($foreignkeys as $oldname => $newnames) {
        foreach ($newnames as $tab) {
            $newname = $tab['to'];
            foreach ($tab['tables'] as $table) {
                $doindex = true;
                if (isset($tab['noindex']) && in_array($table, $tab['noindex'])) {
                    $doindex = false;
                }
                // Rename field
                if (FieldExists($table, $oldname)) {
                    $addcomment = '';
                    if (isset($tab['comments']) && isset($tab['comments'][$table])) {
                        $addcomment = " COMMENT '" . $tab['comments'][$table] . "' ";
                    }
                    $default_value = 0;
                    if (isset($tab['default']) && isset($tab['default'][$table])) {
                        $default_value = $tab['default'][$table];
                    }
                    // Manage NULL fields
                    $query = "UPDATE `{$table}` SET `{$oldname}`='{$default_value}' WHERE `{$oldname}` IS NULL ";
                    $DB->query($query) or die("0.78 prepare datas for update {$oldname} to {$newname} in {$table} " . $LANG['update'][90] . $DB->error());
                    $changes[$table][] = "CHANGE COLUMN `{$oldname}` `{$newname}` INT( 11 ) NOT NULL DEFAULT '{$default_value}' {$addcomment}";
                } else {
                    $updateresult = false;
                    if ($output) {
                        echo "<div class='red'><p>Error : {$table}.{$oldname} does not exist.</p></div>";
                    }
                }
                // If do index : delete old one / create new one
                if ($doindex) {
                    if (!isIndex($table, $newname)) {
                        $changes[$table][] = "ADD INDEX `{$newname}` (`{$newname}`)";
                    }
                    if ($oldname != $newname && isIndex($table, $oldname)) {
                        $changes[$table][] = "DROP INDEX `{$oldname}`";
                    }
                }
            }
        }
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - Clean DB : rename bool values');
    // Updating schema
    $boolfields = array('glpi_authldaps' => array(array('from' => 'ldap_use_tls', 'to' => 'use_tls', 'default' => 0, 'noindex' => true), array('from' => 'use_dn', 'to' => 'use_dn', 'default' => 1, 'noindex' => true)), 'glpi_bookmarks' => array(array('from' => 'private', 'to' => 'is_private', 'default' => 1), array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0)), 'glpi_cartridgeitems' => array(array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0)), 'glpi_computers' => array(array('from' => 'is_template', 'to' => 'is_template', 'default' => 0), array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'ocs_import', 'to' => 'is_ocs_import', 'default' => 0)), 'glpi_configs' => array(array('from' => 'jobs_at_login', 'to' => 'show_jobs_at_login', 'default' => 0, 'noindex' => true), array('from' => 'mailing', 'to' => 'use_mailing', 'default' => 0, 'noindex' => true), array('from' => 'permit_helpdesk', 'to' => 'use_anonymous_helpdesk', 'default' => 0, 'noindex' => true), array('from' => 'existing_auth_server_field_clean_domain', 'to' => 'existing_auth_server_field_clean_domain', 'default' => 0, 'noindex' => true), array('from' => 'auto_assign', 'to' => 'use_auto_assign_to_tech', 'default' => 0, 'noindex' => true), array('from' => 'public_faq', 'to' => 'use_public_faq', 'default' => 0, 'noindex' => true), array('from' => 'url_in_mail', 'to' => 'show_link_in_mail', 'default' => 0, 'noindex' => true), array('from' => 'use_ajax', 'to' => 'use_ajax', 'default' => 0, 'noindex' => true), array('from' => 'ajax_autocompletion', 'to' => 'use_ajax_autocompletion', 'default' => 1, 'noindex' => true), array('from' => 'auto_add_users', 'to' => 'is_users_auto_add', 'default' => 1, 'noindex' => true), array('from' => 'view_ID', 'to' => 'is_ids_visible', 'default' => 0, 'noindex' => true), array('from' => 'ocs_mode', 'to' => 'use_ocs_mode', 'default' => 0, 'noindex' => true), array('from' => 'followup_on_update_ticket', 'to' => 'add_followup_on_update_ticket', 'default' => 1, 'noindex' => true), array('from' => 'licenses_alert', 'to' => 'use_licenses_alert', 'default' => 0, 'noindex' => true), array('from' => 'keep_tracking_on_delete', 'to' => 'keep_tickets_on_delete', 'default' => 1, 'noindex' => true), array('from' => 'use_errorlog', 'to' => 'use_log_in_files', 'default' => 0, 'noindex' => true), array('from' => 'autoupdate_link_contact', 'to' => 'is_contact_autoupdate', 'default' => 1, 'noindex' => true), array('from' => 'autoupdate_link_user', 'to' => 'is_user_autoupdate', 'default' => 1, 'noindex' => true), array('from' => 'autoupdate_link_group', 'to' => 'is_group_autoupdate', 'default' => 1, 'noindex' => true), array('from' => 'autoupdate_link_location', 'to' => 'is_location_autoupdate', 'default' => 1, 'noindex' => true), array('from' => 'autoclean_link_contact', 'to' => 'is_contact_autoclean', 'default' => 0, 'noindex' => true), array('from' => 'autoclean_link_user', 'to' => 'is_user_autoclean', 'default' => 0, 'noindex' => true), array('from' => 'autoclean_link_group', 'to' => 'is_group_autoclean', 'default' => 0, 'noindex' => true), array('from' => 'autoclean_link_location', 'to' => 'is_location_autoclean', 'default' => 0, 'noindex' => true), array('from' => 'flat_dropdowntree', 'to' => 'use_flat_dropdowntree', 'default' => 0, 'noindex' => true), array('from' => 'autoname_entity', 'to' => 'use_autoname_by_entity', 'default' => 1, 'noindex' => true), array('from' => 'expand_soft_categorized', 'to' => 'is_categorized_soft_expanded', 'default' => 1, 'noindex' => true), array('from' => 'expand_soft_not_categorized', 'to' => 'is_not_categorized_soft_expanded', 'default' => 1, 'noindex' => true), array('from' => 'ticket_title_mandatory', 'to' => 'is_ticket_title_mandatory', 'default' => 0, 'noindex' => true), array('from' => 'ticket_content_mandatory', 'to' => 'is_ticket_content_mandatory', 'default' => 1, 'noindex' => true), array('from' => 'ticket_category_mandatory', 'to' => 'is_ticket_category_mandatory', 'default' => 0, 'noindex' => true), array('from' => 'followup_private', 'to' => 'followup_private', 'default' => 0, 'noindex' => true), array('from' => 'software_helpdesk_visible', 'to' => 'default_software_helpdesk_visible', 'default' => 1, 'noindex' => true)), 'glpi_consumableitems' => array(array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0)), 'glpi_contacts' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true), array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0)), 'glpi_contracts' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true), array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'monday', 'to' => 'use_monday', 'default' => 0), array('from' => 'saturday', 'to' => 'use_saturday', 'default' => 0)), 'glpi_devicecontrols' => array(array('from' => 'raid', 'to' => 'is_raid', 'default' => 0, 'noindex' => true)), 'glpi_devicedrives' => array(array('from' => 'is_writer', 'to' => 'is_writer', 'default' => 1, 'noindex' => true)), 'glpi_devicepowersupplies' => array(array('from' => 'atx', 'to' => 'is_atx', 'default' => 1, 'noindex' => true)), 'glpi_documents' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true), array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0)), 'glpi_documenttypes' => array(array('from' => 'upload', 'to' => 'is_uploadable', 'default' => 1)), 'glpi_groups' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true)), 'glpi_knowbaseitems' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 1, 'noindex' => true), array('from' => 'faq', 'to' => 'is_faq', 'default' => 0)), 'glpi_links' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 1, 'noindex' => true)), 'glpi_monitors' => array(array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'is_template', 'to' => 'is_template', 'default' => 0, 'noindex' => true), array('from' => 'is_global', 'to' => 'is_global', 'default' => 0, 'noindex' => true), array('from' => 'flags_micro', 'to' => 'have_micro', 'default' => 0, 'noindex' => true), array('from' => 'flags_speaker', 'to' => 'have_speaker', 'default' => 0, 'noindex' => true), array('from' => 'flags_subd', 'to' => 'have_subd', 'default' => 0, 'noindex' => true), array('from' => 'flags_bnc', 'to' => 'have_bnc', 'default' => 0, 'noindex' => true), array('from' => 'flags_dvi', 'to' => 'have_dvi', 'default' => 0, 'noindex' => true), array('from' => 'flags_pivot', 'to' => 'have_pivot', 'default' => 0, 'noindex' => true)), 'glpi_networkequipments' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true), array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'is_template', 'to' => 'is_template', 'default' => 0, 'noindex' => true)), 'glpi_ocslinks' => array(array('from' => 'auto_update', 'to' => 'use_auto_update', 'default' => 1)), 'glpi_ocsservers' => array(array('from' => 'import_periph', 'to' => 'import_periph', 'default' => 0, 'noindex' => true), array('from' => 'import_monitor', 'to' => 'import_monitor', 'default' => 0, 'noindex' => true), array('from' => 'import_software', 'to' => 'import_software', 'default' => 0, 'noindex' => true), array('from' => 'import_printer', 'to' => 'import_printer', 'default' => 0, 'noindex' => true), array('from' => 'import_general_name', 'to' => 'import_general_name', 'default' => 0, 'noindex' => true), array('from' => 'import_general_os', 'to' => 'import_general_os', 'default' => 0, 'noindex' => true), array('from' => 'import_general_serial', 'to' => 'import_general_serial', 'default' => 0, 'noindex' => true), array('from' => 'import_general_model', 'to' => 'import_general_model', 'default' => 0, 'noindex' => true), array('from' => 'import_general_enterprise', 'to' => 'import_general_manufacturer', 'default' => 0, 'noindex' => true), array('from' => 'import_general_type', 'to' => 'import_general_type', 'default' => 0, 'noindex' => true), array('from' => 'import_general_domain', 'to' => 'import_general_domain', 'default' => 0, 'noindex' => true), array('from' => 'import_general_contact', 'to' => 'import_general_contact', 'default' => 0, 'noindex' => true), array('from' => 'import_general_comments', 'to' => 'import_general_comment', 'default' => 0, 'noindex' => true), array('from' => 'import_device_processor', 'to' => 'import_device_processor', 'default' => 0, 'noindex' => true), array('from' => 'import_device_memory', 'to' => 'import_device_memory', 'default' => 0, 'noindex' => true), array('from' => 'import_device_hdd', 'to' => 'import_device_hdd', 'default' => 0, 'noindex' => true), array('from' => 'import_device_iface', 'to' => 'import_device_iface', 'default' => 0, 'noindex' => true), array('from' => 'import_device_gfxcard', 'to' => 'import_device_gfxcard', 'default' => 0, 'noindex' => true), array('from' => 'import_device_sound', 'to' => 'import_device_sound', 'default' => 0, 'noindex' => true), array('from' => 'import_device_drives', 'to' => 'import_device_drive', 'default' => 0, 'noindex' => true), array('from' => 'import_device_ports', 'to' => 'import_device_port', 'default' => 0, 'noindex' => true), array('from' => 'import_device_modems', 'to' => 'import_device_modem', 'default' => 0, 'noindex' => true), array('from' => 'import_registry', 'to' => 'import_registry', 'default' => 0, 'noindex' => true), array('from' => 'import_os_serial', 'to' => 'import_os_serial', 'default' => 0, 'noindex' => true), array('from' => 'import_ip', 'to' => 'import_ip', 'default' => 0, 'noindex' => true), array('from' => 'import_disk', 'to' => 'import_disk', 'default' => 0, 'noindex' => true), array('from' => 'import_monitor_comments', 'to' => 'import_monitor_comment', 'default' => 0, 'noindex' => true), array('from' => 'glpi_link_enabled', 'to' => 'is_glpi_link_enabled', 'default' => 0, 'noindex' => true), array('from' => 'link_ip', 'to' => 'use_ip_to_link', 'default' => 0, 'noindex' => true), array('from' => 'link_name', 'to' => 'use_name_to_link', 'default' => 0, 'noindex' => true), array('from' => 'link_mac_address', 'to' => 'use_mac_to_link', 'default' => 0, 'noindex' => true), array('from' => 'link_serial', 'to' => 'use_serial_to_link', 'default' => 0, 'noindex' => true), array('from' => 'use_soft_dict', 'to' => 'use_soft_dict', 'default' => 0, 'noindex' => true)), 'glpi_peripherals' => array(array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'is_template', 'to' => 'is_template', 'default' => 0, 'noindex' => true), array('from' => 'is_global', 'to' => 'is_global', 'default' => 0, 'noindex' => true)), 'glpi_phones' => array(array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'is_template', 'to' => 'is_template', 'default' => 0, 'noindex' => true), array('from' => 'is_global', 'to' => 'is_global', 'default' => 0, 'noindex' => true), array('from' => 'flags_hp', 'to' => 'have_hp', 'default' => 0, 'noindex' => true), array('from' => 'flags_casque', 'to' => 'have_headset', 'default' => 0, 'noindex' => true)), 'glpi_printers' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true), array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'is_template', 'to' => 'is_template', 'default' => 0, 'noindex' => true), array('from' => 'is_global', 'to' => 'is_global', 'default' => 0, 'noindex' => true), array('from' => 'flags_usb', 'to' => 'have_usb', 'default' => 0, 'noindex' => true), array('from' => 'flags_par', 'to' => 'have_parallel', 'default' => 0, 'noindex' => true), array('from' => 'flags_serial', 'to' => 'have_serial', 'default' => 0, 'noindex' => true)), 'glpi_profiles_users' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 1), array('from' => 'dynamic', 'to' => 'is_dynamic', 'default' => 0)), 'glpi_profiles' => array(array('from' => 'is_default', 'to' => 'is_default', 'default' => 0)), 'glpi_reminders' => array(array('from' => 'private', 'to' => 'is_private', 'default' => 1), array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0), array('from' => 'rv', 'to' => 'is_planned', 'default' => 0)), 'glpi_reservationitems' => array(array('from' => 'active', 'to' => 'is_active', 'default' => 1)), 'glpi_rules' => array(array('from' => 'active', 'to' => 'is_active', 'default' => 1)), 'glpi_suppliers' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true), array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0)), 'glpi_softwares' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true), array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'helpdesk_visible', 'to' => 'is_helpdesk_visible', 'default' => 1), array('from' => 'is_template', 'to' => 'is_template', 'default' => 0, 'noindex' => true), array('from' => 'is_update', 'to' => 'is_update', 'default' => 0, 'noindex' => true)), 'glpi_softwarelicenses' => array(array('from' => 'recursive', 'to' => 'is_recursive', 'default' => 0, 'noindex' => true)), 'glpi_tickets' => array(array('from' => 'emailupdates', 'to' => 'use_email_notification', 'default' => 0, 'noindex' => true)), 'glpi_ticketfollowups' => array(array('from' => 'private', 'to' => 'is_private', 'default' => 0)), 'glpi_users' => array(array('from' => 'deleted', 'to' => 'is_deleted', 'default' => 0), array('from' => 'active', 'to' => 'is_active', 'default' => 1), array('from' => 'jobs_at_login', 'to' => 'show_jobs_at_login', 'default' => NULL, 'maybenull' => true, 'noindex' => true), array('from' => 'followup_private', 'to' => 'followup_private', 'default' => NULL, 'maybenull' => true, 'noindex' => true), array('from' => 'expand_soft_categorized', 'to' => 'is_categorized_soft_expanded', 'default' => NULL, 'maybenull' => true, 'noindex' => true), array('from' => 'expand_soft_not_categorized', 'to' => 'is_not_categorized_soft_expanded', 'default' => NULL, 'maybenull' => true, 'noindex' => true), array('from' => 'flat_dropdowntree', 'to' => 'use_flat_dropdowntree', 'default' => NULL, 'maybenull' => true, 'noindex' => true), array('from' => 'view_ID', 'to' => 'is_ids_visible', 'default' => NULL, 'maybenull' => true, 'noindex' => true)));
    foreach ($boolfields as $table => $tab) {
        foreach ($tab as $update) {
            $newname = $update['to'];
            $oldname = $update['from'];
            $doindex = true;
            if (isset($update['noindex']) && $update['noindex']) {
                $doindex = false;
            }
            // Rename field
            if (FieldExists($table, $oldname)) {
                $NULL = "NOT NULL";
                if (isset($update['maybenull']) && $update['maybenull']) {
                    $NULL = "NULL";
                    // Manage not zero values
                    $query = "UPDATE `{$table}` SET `{$oldname}`=1 WHERE `{$oldname}` <> 0 AND `{$oldname}` IS NOT NULL; ";
                    $DB->query($query) or die("0.78 prepare datas for update {$oldname} to {$newname} in {$table} " . $LANG['update'][90] . $DB->error());
                } else {
                    // Manage NULL fields
                    $query = "UPDATE `{$table}` SET `{$oldname}`=0 WHERE `{$oldname}` IS NULL ;";
                    $DB->query($query) or die("0.78 prepare datas for update {$oldname} to {$newname} in {$table} " . $LANG['update'][90] . $DB->error());
                    // Manage not zero values
                    $query = "UPDATE `{$table}` SET `{$oldname}`=1 WHERE `{$oldname}` <> 0; ";
                    $DB->query($query) or die("0.78 prepare datas for update {$oldname} to {$newname} in {$table} " . $LANG['update'][90] . $DB->error());
                }
                $default = "DEFAULT NULL";
                if (isset($update['default']) && !is_null($update['default'])) {
                    $default = "DEFAULT " . $update['default'];
                }
                $changes[$table][] = "CHANGE `{$oldname}` `{$newname}` TINYINT( 1 ) {$NULL} {$default}";
            } else {
                $updateresult = false;
                if ($output) {
                    echo "<div class='red'><p>Error : {$table}.{$oldname} does not exist.</p></div>";
                }
            }
            // If do index : delete old one / create new one
            if ($doindex) {
                if (!isIndex($table, $newname)) {
                    $changes[$table][] = "ADD INDEX `{$newname}` (`{$newname}`)";
                }
                if ($newname != $oldname && isIndex($table, $oldname)) {
                    $changes[$table][] = "DROP INDEX `{$oldname}`";
                }
            }
        }
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - Clean DB : update text fields');
    // Updating schema
    $textfields = array('comments' => array('to' => 'comment', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_autoupdatesystems', 'glpi_budgets', 'glpi_cartridgeitemtypes', 'glpi_devicecasetypes', 'glpi_consumableitemtypes', 'glpi_contacttypes', 'glpi_contracttypes', 'glpi_domains', 'glpi_suppliertypes', 'glpi_filesystems', 'glpi_networkequipmentfirmwares', 'glpi_networkinterfaces', 'glpi_interfacetypes', 'glpi_knowbaseitemcategories', 'glpi_softwarelicensetypes', 'glpi_locations', 'glpi_manufacturers', 'glpi_computermodels', 'glpi_monitormodels', 'glpi_networkequipmentmodels', 'glpi_peripheralmodels', 'glpi_phonemodels', 'glpi_printermodels', 'glpi_netpoints', 'glpi_networks', 'glpi_operatingsystems', 'glpi_operatingsystemservicepacks', 'glpi_operatingsystemversions', 'glpi_phonepowersupplies', 'glpi_devicememorytypes', 'glpi_documentcategories', 'glpi_softwarecategories', 'glpi_states', 'glpi_ticketcategories', 'glpi_usertitles', 'glpi_usercategories', 'glpi_vlans', 'glpi_suppliers', 'glpi_entities', 'glpi_groups', 'glpi_infocoms', 'glpi_monitors', 'glpi_phones', 'glpi_printers', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_reservationitems', 'glpi_rules', 'glpi_softwares', 'glpi_softwarelicenses', 'glpi_softwareversions', 'glpi_computertypes', 'glpi_monitortypes', 'glpi_networkequipmenttypes', 'glpi_peripheraltypes', 'glpi_phonetypes', 'glpi_printertypes', 'glpi_users')), 'notes' => array('to' => 'notepad', 'long' => true, 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_suppliers', 'glpi_entitydatas', 'glpi_printers', 'glpi_monitors', 'glpi_phones', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_softwares')), 'ldap_condition' => array('to' => 'condition', 'tables' => array('glpi_authldaps')), 'import_printers' => array('to' => 'import_printer', 'long' => true, 'tables' => array('glpi_ocslinks')), 'contents' => array('to' => 'content', 'long' => true, 'tables' => array('glpi_tickets', 'glpi_ticketfollowups')));
    foreach ($textfields as $oldname => $tab) {
        $newname = $tab['to'];
        $type = "TEXT";
        if (isset($tab['long']) && $tab['long']) {
            $type = "LONGTEXT";
        }
        foreach ($tab['tables'] as $table) {
            // Rename field
            if (FieldExists($table, $oldname)) {
                $query = "ALTER TABLE `{$table}` CHANGE `{$oldname}` `{$newname}` {$type} NULL DEFAULT NULL  ";
                $DB->query($query) or die("0.78 rename {$oldname} to {$newname} in {$table} " . $LANG['update'][90] . $DB->error());
            } else {
                $updateresult = false;
                if ($output) {
                    echo "<div class='red'><p>Error : {$table}.{$oldname} does not exist.</p></div>";
                }
            }
        }
    }
    $varcharfields = array('glpi_authldaps' => array(array('from' => 'ldap_host', 'to' => 'host', 'noindex' => true), array('from' => 'ldap_basedn', 'to' => 'basedn', 'noindex' => true), array('from' => 'ldap_rootdn', 'to' => 'rootdn', 'noindex' => true), array('from' => 'ldap_pass', 'to' => 'rootdn_password', 'noindex' => true), array('from' => 'ldap_login', 'to' => 'login_field', 'default' => 'uid', 'noindex' => true, ''), array('from' => 'ldap_field_group', 'to' => 'group_field', 'noindex' => true), array('from' => 'ldap_group_condition', 'to' => 'group_condition', 'noindex' => true), array('from' => 'ldap_field_group_member', 'to' => 'group_member_field', 'noindex' => true), array('from' => 'ldap_field_email', 'to' => 'email_field', 'noindex' => true), array('from' => 'ldap_field_realname', 'to' => 'realname_field', 'noindex' => true), array('from' => 'ldap_field_firstname', 'to' => 'firstname_field', 'noindex' => true), array('from' => 'ldap_field_phone', 'to' => 'phone_field', 'noindex' => true), array('from' => 'ldap_field_phone2', 'to' => 'phone2_field', 'noindex' => true), array('from' => 'ldap_field_mobile', 'to' => 'mobile_field', 'noindex' => true), array('from' => 'ldap_field_comments', 'to' => 'comment_field', 'noindex' => true), array('from' => 'ldap_field_title', 'to' => 'title_field', 'noindex' => true), array('from' => 'ldap_field_type', 'to' => 'category_field', 'noindex' => true), array('from' => 'ldap_field_language', 'to' => 'language_field', 'noindex' => true)), 'glpi_authldapreplicates' => array(array('from' => 'ldap_host', 'to' => 'host', 'noindex' => true)), 'glpi_authmails' => array(array('from' => 'imap_auth_server', 'to' => 'connect_string', 'noindex' => true), array('from' => 'imap_host', 'to' => 'host', 'noindex' => true)), 'glpi_computers' => array(array('from' => 'os_license_id', 'to' => 'os_licenseid', 'noindex' => true), array('from' => 'tplname', 'to' => 'template_name', 'noindex' => true)), 'glpi_configs' => array(array('from' => 'helpdeskhelp_url', 'to' => 'helpdesk_doc_url', 'noindex' => true), array('from' => 'centralhelp_url', 'to' => 'central_doc_url', 'noindex' => true)), 'glpi_contracts' => array(array('from' => 'compta_num', 'to' => 'accounting_number', 'noindex' => true)), 'glpi_events' => array(array('from' => 'itemtype', 'to' => 'type', 'noindex' => true)), 'glpi_infocoms' => array(array('from' => 'num_commande', 'to' => 'order_number', 'noindex' => true), array('from' => 'bon_livraison', 'to' => 'delivery_number', 'noindex' => true), array('from' => 'num_immo', 'to' => 'immo_number', 'noindex' => true), array('from' => 'facture', 'to' => 'bill', 'noindex' => true)), 'glpi_monitors' => array(array('from' => 'tplname', 'to' => 'template_name', 'noindex' => true)), 'glpi_networkequipments' => array(array('from' => 'tplname', 'to' => 'template_name', 'noindex' => true), array('from' => 'ifmac', 'to' => 'mac', 'noindex' => true), array('from' => 'ifaddr', 'to' => 'ip', 'noindex' => true)), 'glpi_networkports' => array(array('from' => 'ifmac', 'to' => 'mac', 'noindex' => true), array('from' => 'ifaddr', 'to' => 'ip', 'noindex' => true)), 'glpi_peripherals' => array(array('from' => 'tplname', 'to' => 'template_name', 'noindex' => true)), 'glpi_phones' => array(array('from' => 'tplname', 'to' => 'template_name', 'noindex' => true)), 'glpi_printers' => array(array('from' => 'tplname', 'to' => 'template_name', 'noindex' => true), array('from' => 'ramSize', 'to' => 'memory_size', 'noindex' => true)), 'glpi_registrykeys' => array(array('from' => 'registry_hive', 'to' => 'hive', 'noindex' => true), array('from' => 'registry_path', 'to' => 'path', 'noindex' => true), array('from' => 'registry_value', 'to' => 'value', 'noindex' => true), array('from' => 'registry_ocs_name', 'to' => 'ocs_name', 'noindex' => true)), 'glpi_softwares' => array(array('from' => 'tplname', 'to' => 'template_name', 'noindex' => true)), 'glpi_tickets' => array(array('from' => 'uemail', 'to' => 'user_email', 'noindex' => true)));
    foreach ($varcharfields as $table => $tab) {
        foreach ($tab as $update) {
            $newname = $update['to'];
            $oldname = $update['from'];
            $doindex = true;
            if (isset($update['noindex']) && $update['noindex']) {
                $doindex = false;
            }
            $default = "DEFAULT NULL";
            if (isset($update['default']) && !is_null($update['default'])) {
                $default = "DEFAULT '" . $update['default'] . "'";
            }
            // Rename field
            if (FieldExists($table, $oldname)) {
                $query = "ALTER TABLE `{$table}` CHANGE `{$oldname}` `{$newname}` VARCHAR( 255 ) NULL {$default}  ";
                $DB->query($query) or die("0.78 rename {$oldname} to {$newname} in {$table} " . $LANG['update'][90] . $DB->error());
            } else {
                $updateresult = false;
                if ($output) {
                    echo "<div class='red'><p>Error : {$table}.{$oldname} does not exist.</p></div>";
                }
            }
            // If do index : delete old one / create new one
            if ($doindex) {
                if (!isIndex($table, $newname)) {
                    $changes[$table][] = "ADD INDEX `{$newname}` (`{$newname}`)";
                }
                if ($newname != $oldname && isIndex($table, $oldname)) {
                    $changes[$table][] = "DROP INDEX `{$oldname}`";
                }
            }
        }
    }
    $charfields = array('glpi_profiles' => array(array('from' => 'user_auth_method', 'to' => 'user_authtype', 'length' => 1, 'default' => NULL, 'noindex' => true), array('from' => 'rule_tracking', 'to' => 'rule_ticket', 'length' => 1, 'default' => NULL, 'noindex' => true), array('from' => 'rule_softwarecategories', 'to' => 'rule_softwarecategories', 'length' => 1, 'default' => NULL, 'noindex' => true), array('from' => 'rule_dictionnary_software', 'to' => 'rule_dictionnary_software', 'length' => 1, 'default' => NULL, 'noindex' => true), array('from' => 'rule_dictionnary_dropdown', 'to' => 'rule_dictionnary_dropdown', 'length' => 1, 'default' => NULL, 'noindex' => true)), 'glpi_configs' => array(array('from' => 'version', 'to' => 'version', 'length' => 10, 'default' => NULL, 'noindex' => true), array('from' => 'version', 'to' => 'version', 'length' => 10, 'default' => NULL, 'noindex' => true), array('from' => 'language', 'to' => 'language', 'length' => 10, 'default' => 'en_GB', 'noindex' => true, 'comments' => 'see define.php CFG_GLPI[language] array'), array('from' => 'priority_1', 'to' => 'priority_1', 'length' => 20, 'default' => '#fff2f2', 'noindex' => true), array('from' => 'priority_2', 'to' => 'priority_2', 'length' => 20, 'default' => '#ffe0e0', 'noindex' => true), array('from' => 'priority_3', 'to' => 'priority_3', 'length' => 20, 'default' => '#ffcece', 'noindex' => true), array('from' => 'priority_4', 'to' => 'priority_4', 'length' => 20, 'default' => '#ffbfbf', 'noindex' => true), array('from' => 'priority_5', 'to' => 'priority_5', 'length' => 20, 'default' => '#ffadad', 'noindex' => true), array('from' => 'founded_new_version', 'to' => 'founded_new_version', 'length' => 10, 'default' => NULL, 'noindex' => true)), 'glpi_rules' => array(array('from' => 'match', 'to' => 'match', 'length' => 10, 'default' => NULL, 'noindex' => true, 'comments' => 'see define.php *_MATCHING constant')), 'glpi_users' => array(array('from' => 'language', 'to' => 'language', 'length' => 10, 'default' => NULL, 'noindex' => true, 'comments' => 'see define.php CFG_GLPI[language] array'), array('from' => 'priority_1', 'to' => 'priority_1', 'length' => 20, 'default' => NULL, 'noindex' => true), array('from' => 'priority_2', 'to' => 'priority_2', 'length' => 20, 'default' => NULL, 'noindex' => true), array('from' => 'priority_3', 'to' => 'priority_3', 'length' => 20, 'default' => NULL, 'noindex' => true), array('from' => 'priority_4', 'to' => 'priority_4', 'length' => 20, 'default' => NULL, 'noindex' => true), array('from' => 'priority_5', 'to' => 'priority_5', 'length' => 20, 'default' => NULL, 'noindex' => true)));
    foreach ($charfields as $table => $tab) {
        foreach ($tab as $update) {
            $newname = $update['to'];
            $oldname = $update['from'];
            $length = $update['length'];
            $doindex = true;
            if (isset($update['noindex']) && $update['noindex']) {
                $doindex = false;
            }
            $default = "DEFAULT NULL";
            if (isset($update['default']) && !is_null($update['default'])) {
                $default = "DEFAULT '" . $update['default'] . "'";
            }
            $addcomment = "";
            if (isset($update['comments'])) {
                $addcomment = "COMMENT '" . $update['comments'] . "'";
            }
            // Rename field
            if (FieldExists($table, $oldname)) {
                $query = "ALTER TABLE `{$table}` CHANGE `{$oldname}` `{$newname}` CHAR( {$length} ) NULL {$default} {$addcomment} ";
                $DB->query($query) or die("0.78 rename {$oldname} to {$newname} in {$table} " . $LANG['update'][90] . $DB->error());
            } else {
                $updateresult = false;
                if ($output) {
                    echo "<div class='red'><p>Error : {$table}.{$oldname} does not exist.</p></div>";
                }
            }
            // If do index : delete old one / create new one
            if ($doindex) {
                if (!isIndex($table, $newname)) {
                    $changes[$table][] = "ADD INDEX `{$newname}` (`{$newname}`)";
                }
                if ($oldname != $newname && isIndex($table, $oldname)) {
                    $changes[$table][] = "DROP INDEX `{$oldname}`";
                }
            }
        }
    }
    $intfields = array('glpi_authldaps' => array(array('from' => 'ldap_port', 'to' => 'port', 'default' => 389, 'noindex' => true, 'checkdatas' => true), array('from' => 'ldap_search_for_groups', 'to' => 'group_search_type', 'default' => 0, 'noindex' => true), array('from' => 'ldap_opt_deref', 'to' => 'deref_option', 'default' => 0, 'noindex' => true), array('from' => 'timezone', 'to' => 'time_offset', 'default' => 0, 'noindex' => true, 'comments' => 'in seconds')), 'glpi_authldapreplicates' => array(array('from' => 'ldap_port', 'to' => 'port', 'default' => 389, 'noindex' => true, 'checkdatas' => true)), 'glpi_bookmarks' => array(array('from' => 'type', 'to' => 'type', 'default' => 0, 'noindex' => true, 'comments' => 'see define.php BOOKMARK_* constant')), 'glpi_cartridgeitems' => array(array('from' => 'alarm', 'to' => 'alarm_threshold', 'default' => 10)), 'glpi_configs' => array(array('from' => 'glpi_timezone', 'to' => 'time_offset', 'default' => 0, 'noindex' => true, 'comments' => 'in seconds'), array('from' => 'cartridges_alarm', 'to' => 'default_alarm_threshold', 'default' => 10, 'noindex' => true), array('from' => 'event_loglevel', 'to' => 'event_loglevel', 'default' => 5, 'noindex' => true), array('from' => 'cas_port', 'to' => 'cas_port', 'default' => 443, 'noindex' => true, 'checkdatas' => true), array('from' => 'auto_update_check', 'to' => 'auto_update_check', 'default' => 0, 'noindex' => true), array('from' => 'dateformat', 'to' => 'date_format', 'default' => 0, 'noindex' => true), array('from' => 'numberformat', 'to' => 'number_format', 'default' => 0, 'noindex' => true), array('from' => 'proxy_port', 'to' => 'proxy_port', 'default' => 8080, 'noindex' => true, 'checkdatas' => true), array('from' => 'contract_alerts', 'to' => 'default_contract_alert', 'default' => 0, 'noindex' => true), array('from' => 'infocom_alerts', 'to' => 'default_infocom_alert', 'default' => 0, 'noindex' => true), array('from' => 'cartridges_alert', 'to' => 'cartridges_alert_repeat', 'default' => 0, 'noindex' => true, 'comments' => 'in seconds'), array('from' => 'consumables_alert', 'to' => 'consumables_alert_repeat', 'default' => 0, 'noindex' => true, 'comments' => 'in seconds'), array('from' => 'monitors_management_restrict', 'to' => 'monitors_management_restrict', 'default' => 2, 'noindex' => true), array('from' => 'phones_management_restrict', 'to' => 'phones_management_restrict', 'default' => 2, 'noindex' => true), array('from' => 'peripherals_management_restrict', 'to' => 'peripherals_management_restrict', 'default' => 2, 'noindex' => true), array('from' => 'printers_management_restrict', 'to' => 'printers_management_restrict', 'default' => 2, 'noindex' => true), array('from' => 'autoupdate_link_state', 'to' => 'state_autoupdate_mode', 'default' => 0, 'noindex' => true), array('from' => 'autoclean_link_state', 'to' => 'state_autoclean_mode', 'default' => 0, 'noindex' => true), array('from' => 'name_display_order', 'to' => 'names_format', 'default' => 0, 'noindex' => true, 'comments' => 'see *NAME_BEFORE constant in define.php'), array('from' => 'dropdown_limit', 'to' => 'dropdown_chars_limit', 'default' => 50, 'noindex' => true), array('from' => 'smtp_mode', 'to' => 'smtp_mode', 'default' => 0, 'noindex' => true, 'comments' => 'see define.php MAIL_* constant'), array('from' => 'mailgate_filesize_max', 'to' => 'default_mailcollector_filesize_max', 'default' => 2097152, 'noindex' => true)), 'glpi_consumableitems' => array(array('from' => 'alarm', 'to' => 'alarm_threshold', 'default' => 10)), 'glpi_contracts' => array(array('from' => 'duration', 'to' => 'duration', 'default' => 0, 'noindex' => true), array('from' => 'notice', 'to' => 'notice', 'default' => 0, 'noindex' => true), array('from' => 'periodicity', 'to' => 'periodicity', 'default' => 0, 'noindex' => true), array('from' => 'facturation', 'to' => 'billing', 'default' => 0, 'noindex' => true), array('from' => 'device_countmax', 'to' => 'max_links_allowed', 'default' => 0, 'noindex' => true), array('from' => 'alert', 'to' => 'alert', 'default' => 0), array('from' => 'renewal', 'to' => 'renewal', 'default' => 0, 'noindex' => true)), 'glpi_displaypreferences' => array(array('from' => 'num', 'to' => 'num', 'default' => 0), array('from' => 'rank', 'to' => 'rank', 'default' => 0)), 'glpi_events' => array(array('from' => 'level', 'to' => 'level', 'default' => 0)), 'glpi_infocoms' => array(array('from' => 'warranty_duration', 'to' => 'warranty_duration', 'default' => 0, 'noindex' => true), array('from' => 'amort_time', 'to' => 'sink_time', 'default' => 0, 'noindex' => true), array('from' => 'amort_type', 'to' => 'sink_type', 'default' => 0, 'noindex' => true), array('from' => 'alert', 'to' => 'alert', 'default' => 0)), 'glpi_mailingsettings' => array(array('from' => 'item_type', 'to' => 'mailingtype', 'default' => 0, 'noindex' => true, 'comments' => 'see define.php *_MAILING_TYPE constant')), 'glpi_monitors' => array(array('from' => 'size', 'to' => 'size', 'default' => 0, 'noindex' => true)), 'glpi_printers' => array(array('from' => 'initial_pages', 'to' => 'init_pages_counter', 'default' => 0, 'noindex' => true, 'checkdatas' => true)), 'glpi_profiles' => array(array('from' => 'helpdesk_hardware', 'to' => 'helpdesk_hardware', 'default' => 0, 'noindex' => true)), 'glpi_plugins' => array(array('from' => 'state', 'to' => 'state', 'default' => 0, 'comments' => 'see define.php PLUGIN_* constant')), 'glpi_reminders' => array(array('from' => 'state', 'to' => 'state', 'default' => 0)), 'glpi_ticketplannings' => array(array('from' => 'state', 'to' => 'state', 'default' => 1)), 'glpi_rulecriterias' => array(array('from' => 'condition', 'to' => 'condition', 'default' => 0, 'comments' => 'see define.php PATTERN_* and REGEX_* constant')), 'glpi_rules' => array(array('from' => 'sub_type', 'to' => 'sub_type', 'default' => 0, 'comments' => 'see define.php RULE_* constant')), 'glpi_tickets' => array(array('from' => 'request_type', 'to' => 'request_type', 'default' => 0, 'noindex' => true), array('from' => 'priority', 'to' => 'priority', 'default' => 1, 'noindex' => true)), 'glpi_transfers' => array(array('from' => 'keep_tickets', 'to' => 'keep_ticket', 'default' => 0, 'noindex' => true), array('from' => 'keep_networklinks', 'to' => 'keep_networklink', 'default' => 0, 'noindex' => true), array('from' => 'keep_reservations', 'to' => 'keep_reservation', 'default' => 0, 'noindex' => true), array('from' => 'keep_history', 'to' => 'keep_history', 'default' => 0, 'noindex' => true), array('from' => 'keep_devices', 'to' => 'keep_device', 'default' => 0, 'noindex' => true), array('from' => 'keep_infocoms', 'to' => 'keep_infocom', 'default' => 0, 'noindex' => true), array('from' => 'keep_dc_monitor', 'to' => 'keep_dc_monitor', 'default' => 0, 'noindex' => true), array('from' => 'clean_dc_monitor', 'to' => 'clean_dc_monitor', 'default' => 0, 'noindex' => true), array('from' => 'keep_dc_phone', 'to' => 'keep_dc_phone', 'default' => 0, 'noindex' => true), array('from' => 'clean_dc_phone', 'to' => 'clean_dc_phone', 'default' => 0, 'noindex' => true), array('from' => 'keep_dc_peripheral', 'to' => 'keep_dc_peripheral', 'default' => 0, 'noindex' => true), array('from' => 'clean_dc_peripheral', 'to' => 'clean_dc_peripheral', 'default' => 0, 'noindex' => true), array('from' => 'keep_dc_printer', 'to' => 'keep_dc_printer', 'default' => 0, 'noindex' => true), array('from' => 'clean_dc_printer', 'to' => 'clean_dc_printer', 'default' => 0, 'noindex' => true), array('from' => 'keep_enterprises', 'to' => 'keep_supplier', 'default' => 0, 'noindex' => true), array('from' => 'clean_enterprises', 'to' => 'clean_supplier', 'default' => 0, 'noindex' => true), array('from' => 'keep_contacts', 'to' => 'keep_contact', 'default' => 0, 'noindex' => true), array('from' => 'clean_contacts', 'to' => 'clean_contact', 'default' => 0, 'noindex' => true), array('from' => 'keep_contracts', 'to' => 'keep_contract', 'default' => 0, 'noindex' => true), array('from' => 'clean_contracts', 'to' => 'clean_contract', 'default' => 0, 'noindex' => true), array('from' => 'keep_softwares', 'to' => 'keep_software', 'default' => 0, 'noindex' => true), array('from' => 'clean_softwares', 'to' => 'clean_software', 'default' => 0, 'noindex' => true), array('from' => 'keep_documents', 'to' => 'keep_document', 'default' => 0, 'noindex' => true), array('from' => 'clean_documents', 'to' => 'clean_document', 'default' => 0, 'noindex' => true), array('from' => 'keep_cartridges_type', 'to' => 'keep_cartridgeitem', 'default' => 0, 'noindex' => true), array('from' => 'clean_cartridges_type', 'to' => 'clean_cartridgeitem', 'default' => 0, 'noindex' => true), array('from' => 'keep_cartridges', 'to' => 'keep_cartridge', 'default' => 0, 'noindex' => true), array('from' => 'keep_consumables', 'to' => 'keep_consumable', 'default' => 0, 'noindex' => true)), 'glpi_users' => array(array('from' => 'dateformat', 'to' => 'date_format', 'default' => NULL, 'noindex' => true, 'maybenull' => true), array('from' => 'numberformat', 'to' => 'number_format', 'default' => NULL, 'noindex' => true, 'maybenull' => true), array('from' => 'use_mode', 'to' => 'use_mode', 'default' => 0, 'noindex' => true), array('from' => 'dropdown_limit', 'to' => 'dropdown_chars_limit', 'default' => NULL, 'maybenull' => true, 'noindex' => true)));
    foreach ($intfields as $table => $tab) {
        foreach ($tab as $update) {
            $newname = $update['to'];
            $oldname = $update['from'];
            $doindex = true;
            if (isset($update['noindex']) && $update['noindex']) {
                $doindex = false;
            }
            $default = "DEFAULT NULL";
            if (isset($update['default']) && !is_null($update['default'])) {
                $default = "DEFAULT " . $update['default'] . "";
            }
            $NULL = "NOT NULL";
            if (isset($update['maybenull']) && $update['maybenull']) {
                $NULL = "NULL";
            }
            $check_datas = false;
            if (isset($update['checkdatas'])) {
                $check_datas = $update['checkdatas'];
            }
            $addcomment = "";
            if (isset($update['comments'])) {
                $addcomment = "COMMENT '" . $update['comments'] . "'";
            }
            // Rename field
            if (FieldExists($table, $oldname)) {
                if ($check_datas) {
                    $query = "SELECT id, {$oldname} FROM {$table};";
                    if ($result = $DB->query($query)) {
                        if ($DB->numrows($result) > 0) {
                            while ($data = $DB->fetch_assoc($result)) {
                                if (empty($data[$oldname]) && isset($update['default'])) {
                                    $data[$oldname] = $update['default'];
                                }
                                $query = "UPDATE {$table} SET {$oldname}='" . intval($data[$oldname]) . "' WHERE id = " . $data['id'] . ";";
                                $DB->query($query);
                            }
                        }
                    }
                }
                $changes[$table][] = "CHANGE `{$oldname}` `{$newname}` INT( 11 ) {$NULL} {$default} {$addcomment}";
            } else {
                $updateresult = false;
                if ($output) {
                    echo "<div class='red'><p>Error : {$table}.{$oldname} does not exist.</p></div>";
                }
            }
            // If do index : delete old one / create new one
            if ($doindex) {
                if (!isIndex($table, $newname)) {
                    $changes[$table][] = "ADD INDEX `{$newname}` (`{$newname}`)";
                }
                if ($newname != $oldname && isIndex($table, $oldname)) {
                    $changes[$table][] = "DROP INDEX `{$oldname}`";
                }
            }
        }
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - Clean DB : others field changes');
    // Updating schema
    if (FieldExists('glpi_alerts', 'date')) {
        $changes['glpi_alerts'][] = "CHANGE `date` `date` DATETIME NOT NULL";
    }
    if (FieldExists('glpi_configs', 'date_fiscale')) {
        $changes['glpi_configs'][] = "CHANGE `date_fiscale` `date_tax` DATE NOT NULL DEFAULT '2005-12-31'";
    }
    if (FieldExists('glpi_configs', 'sendexpire')) {
        $changes['glpi_configs'][] = "DROP `sendexpire`";
    }
    if (FieldExists('glpi_configs', 'show_admin_doc')) {
        $changes['glpi_configs'][] = "DROP `show_admin_doc`";
    }
    if (FieldExists('glpi_configs', 'licenses_management_restrict')) {
        $changes['glpi_configs'][] = "DROP `licenses_management_restrict`";
    }
    if (FieldExists('glpi_configs', 'nextprev_item')) {
        $changes['glpi_configs'][] = "DROP `nextprev_item`";
    }
    if (FieldExists('glpi_configs', 'logotxt')) {
        $changes['glpi_configs'][] = "DROP `logotxt`";
    }
    if (FieldExists('glpi_configs', 'num_of_events')) {
        $changes['glpi_configs'][] = "DROP `num_of_events`";
    }
    if (FieldExists('glpi_configs', 'tracking_order')) {
        $changes['glpi_configs'][] = "DROP `tracking_order`";
    }
    if (FieldExists('glpi_contracts', 'bill_type')) {
        $changes['glpi_contracts'][] = "DROP `bill_type`";
    }
    if (FieldExists('glpi_infocoms', 'amort_coeff')) {
        $changes['glpi_infocoms'][] = "CHANGE `amort_coeff` `sink_coeff` FLOAT NOT NULL DEFAULT '0'";
    }
    if (FieldExists('glpi_ocsservers', 'import_software_comments')) {
        $changes['glpi_ocsservers'][] = "DROP `import_software_comments`";
    }
    if (FieldExists('glpi_users', 'nextprev_item')) {
        $changes['glpi_users'][] = "DROP `nextprev_item`";
    }
    if (FieldExists('glpi_users', 'num_of_events')) {
        $changes['glpi_users'][] = "DROP `num_of_events`";
    }
    if (FieldExists('glpi_users', 'tracking_order')) {
        $changes['glpi_users'][] = "DROP `tracking_order`";
    }
    if (FieldExists('glpi_rulerightparameters', 'sub_type')) {
        $changes['glpi_rulerightparameters'][] = "DROP `sub_type`";
    }
    if (FieldExists('glpi_softwares', 'oldstate')) {
        $changes['glpi_softwares'][] = "DROP `oldstate`";
    }
    if (FieldExists('glpi_users', 'password')) {
        $changes['glpi_users'][] = "DROP `password`";
    }
    if (FieldExists('glpi_users', 'password_md5')) {
        $changes['glpi_users'][] = "CHANGE `password_md5` `password` CHAR( 40 )  NULL DEFAULT NULL";
    }
    if (!FieldExists('glpi_mailcollectors', 'filesize_max')) {
        $changes['glpi_mailcollectors'][] = "ADD `filesize_max` INT(11) NOT NULL DEFAULT 2097152";
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - Clean DB : index management');
    // Updating schema
    if (!isIndex('glpi_alerts', 'unicity')) {
        $changes['glpi_alerts'][] = "ADD UNIQUE `unicity` ( `itemtype` , `items_id` , `type` )";
    }
    if (!isIndex('glpi_cartridges_printermodels', 'unicity')) {
        $changes['glpi_cartridges_printermodels'][] = "ADD UNIQUE `unicity` ( `printermodels_id` , `cartridgeitems_id`)";
    }
    if (!isIndex('glpi_computers_items', 'unicity')) {
        $changes['glpi_computers_items'][] = "ADD UNIQUE `unicity` ( `itemtype` , `items_id`, `computers_id`)";
    }
    if (!isIndex('glpi_contacts_suppliers', 'unicity')) {
        $changes['glpi_contacts_suppliers'][] = "ADD UNIQUE `unicity` ( `suppliers_id` , `contacts_id`)";
    }
    if (!isIndex('glpi_contracts_items', 'unicity')) {
        $changes['glpi_contracts_items'][] = "ADD UNIQUE `unicity` ( `contracts_id` ,  `itemtype` , `items_id`)";
    }
    if (!isIndex('glpi_contracts_items', 'item')) {
        $changes['glpi_contracts_items'][] = "ADD INDEX `item` ( `itemtype` , `items_id`)";
    }
    if (!isIndex('glpi_contracts_suppliers', 'unicity')) {
        $changes['glpi_contracts_suppliers'][] = "ADD UNIQUE `unicity` ( `suppliers_id` , `contracts_id`)";
    }
    if (!isIndex('glpi_displaypreferences', 'unicity')) {
        $changes['glpi_displaypreferences'][] = "ADD UNIQUE `unicity` ( `users_id` , `itemtype`, `num`)";
    }
    if (!isIndex('glpi_bookmarks_users', 'unicity')) {
        $changes['glpi_bookmarks_users'][] = "ADD UNIQUE `unicity` ( `users_id` , `itemtype`)";
    }
    if (!isIndex('glpi_documents_items', 'unicity')) {
        $changes['glpi_documents_items'][] = "ADD UNIQUE `unicity` ( `documents_id` , `itemtype`, `items_id`)";
    }
    if (!isIndex('glpi_documents_items', 'item')) {
        $changes['glpi_documents_items'][] = "ADD INDEX `item` (  `itemtype`, `items_id`)";
    }
    if (!isIndex('glpi_knowbaseitemcategories', 'unicity')) {
        $changes['glpi_knowbaseitemcategories'][] = "ADD UNIQUE `unicity` ( `knowbaseitemcategories_id` , `name`) ";
    }
    if (!isIndex('glpi_locations', 'unicity')) {
        $changes['glpi_locations'][] = "ADD UNIQUE `unicity` ( `entities_id`, `locations_id` , `name`) ";
    }
    if (isIndex('glpi_locations', 'name')) {
        $changes['glpi_locations'][] = "DROP INDEX `name` ";
    }
    if (!isIndex('glpi_netpoints', 'complete')) {
        $changes['glpi_netpoints'][] = "ADD INDEX `complete` (`entities_id`,`locations_id`,`name`) ";
    }
    if (!isIndex('glpi_netpoints', 'location_name')) {
        $changes['glpi_netpoints'][] = "ADD INDEX `location_name` (`locations_id`,`name`)";
    }
    if (!isIndex('glpi_entities', 'unicity')) {
        $changes['glpi_entities'][] = "ADD UNIQUE `unicity` (`entities_id`,`name`)  ";
    }
    if (!isIndex('glpi_entitydatas', 'unicity')) {
        $changes['glpi_entitydatas'][] = "ADD UNIQUE `unicity` (`entities_id`) ";
    }
    if (!isIndex('glpi_events', 'item')) {
        $changes['glpi_events'][] = "ADD INDEX `item` (`type`,`items_id`) ";
    }
    if (!isIndex('glpi_infocoms', 'unicity')) {
        $changes['glpi_infocoms'][] = "ADD UNIQUE `unicity` (`itemtype`,`items_id`)  ";
    }
    if (!isIndex('glpi_knowbaseitems', 'date_mod')) {
        $changes['glpi_knowbaseitems'][] = "ADD INDEX `date_mod` (`date_mod`) ";
    }
    if (!isIndex('glpi_networkequipments', 'date_mod')) {
        $changes['glpi_networkequipments'][] = "ADD INDEX `date_mod` (`date_mod`)  ";
    }
    if (!isIndex('glpi_links_itemtypes', 'unicity')) {
        $changes['glpi_links_itemtypes'][] = "ADD UNIQUE `unicity` (`itemtype`,`links_id`)   ";
    }
    if (!isIndex('glpi_mailingsettings', 'unicity')) {
        $changes['glpi_mailingsettings'][] = "ADD UNIQUE `unicity` (`type`,`items_id`,`mailingtype`)  ";
    }
    if (!isIndex('glpi_networkports', 'item')) {
        $changes['glpi_networkports'][] = "ADD INDEX `item` (`itemtype`,`items_id`) ";
    }
    if (!isIndex('glpi_networkports_vlans', 'unicity')) {
        $changes['glpi_networkports_vlans'][] = "ADD UNIQUE `unicity` (`networkports_id`,`vlans_id`) ";
    }
    if (!isIndex('glpi_networkports_networkports', 'unicity')) {
        $changes['glpi_networkports_networkports'][] = "ADD UNIQUE `unicity` (`networkports_id_1`,`networkports_id_2`)  ";
    }
    if (!isIndex('glpi_ocslinks', 'unicity')) {
        $changes['glpi_ocslinks'][] = "ADD UNIQUE `unicity` (`ocsservers_id`,`ocsid`)   ";
    }
    if (!isIndex('glpi_peripherals', 'date_mod')) {
        $changes['glpi_peripherals'][] = "ADD INDEX `date_mod` (`date_mod`)  ";
    }
    if (!isIndex('glpi_phones', 'date_mod')) {
        $changes['glpi_phones'][] = "ADD INDEX `date_mod` (`date_mod`)  ";
    }
    if (!isIndex('glpi_plugins', 'unicity')) {
        $changes['glpi_plugins'][] = "ADD UNIQUE `unicity` (`directory`)   ";
    }
    if (!isIndex('glpi_printers', 'date_mod')) {
        $changes['glpi_printers'][] = "ADD INDEX `date_mod` (`date_mod`)  ";
    }
    if (!isIndex('glpi_reminders', 'date_mod')) {
        $changes['glpi_reminders'][] = "ADD INDEX `date_mod` (`date_mod`)  ";
    }
    if (!isIndex('glpi_reservationitems', 'item')) {
        $changes['glpi_reservationitems'][] = "ADD INDEX `item` (`itemtype`,`items_id`)   ";
    }
    if (!isIndex('glpi_tickets', 'item')) {
        $changes['glpi_tickets'][] = "ADD INDEX `item` (`itemtype`,`items_id`)  ";
    }
    if (!isIndex('glpi_documenttypes', 'date_mod')) {
        $changes['glpi_documenttypes'][] = "ADD INDEX `date_mod` (`date_mod`)  ";
    }
    if (!isIndex('glpi_documenttypes', 'unicity')) {
        $changes['glpi_documenttypes'][] = "ADD UNIQUE `unicity` (`ext`)  ";
    }
    if (!isIndex('glpi_users', 'unicity')) {
        $changes['glpi_users'][] = "ADD UNIQUE `unicity` (`name`)  ";
    }
    if (!isIndex('glpi_users', 'date_mod')) {
        $changes['glpi_users'][] = "ADD INDEX `date_mod` (`date_mod`)  ";
    }
    if (!isIndex('glpi_users', 'authitem')) {
        $changes['glpi_users'][] = "ADD INDEX `authitem` (`authtype`,`auths_id`) ";
    }
    if (!isIndex('glpi_groups_users', 'unicity')) {
        $changes['glpi_groups_users'][] = "ADD UNIQUE `unicity` (`users_id`,`groups_id`)  ";
    }
    $indextodrop = array('glpi_alerts' => array('alert', 'FK_device'), 'glpi_cartridges_printermodels' => array('FK_glpi_type_printer'), 'glpi_computers_items' => array('connect', 'type', 'end1', 'end1_2'), 'glpi_consumables' => array('FK_glpi_cartridges_type'), 'glpi_contacts_suppliers' => array('FK_enterprise'), 'glpi_contracts_items' => array('FK_contract_device', 'device_type'), 'glpi_contracts_suppliers' => array('FK_enterprise'), 'glpi_displaypreferences' => array('display', 'FK_users'), 'glpi_bookmarks_users' => array('FK_users'), 'glpi_documents_items' => array('FK_doc_device', 'device_type', 'FK_device'), 'glpi_knowbaseitemcategories' => array('parentID_2', 'parentID'), 'glpi_locations' => array('FK_entities'), 'glpi_netpoints' => array('FK_entities', 'location'), 'glpi_entities' => array('name'), 'glpi_entitydatas' => array('FK_entities'), 'glpi_events' => array('comp', 'itemtype'), 'glpi_infocoms' => array('FK_device'), 'glpi_computers_softwareversions' => array('sID'), 'glpi_links_itemtypes' => array('link'), 'glpi_mailingsettings' => array('mailings', 'FK_item'), 'glpi_networkports' => array('device_type'), 'glpi_networkports_vlans' => array('portvlan'), 'glpi_networkports_networkports' => array('netwire', 'end1', 'end1_2'), 'glpi_ocslinks' => array('ocs_server_id'), 'glpi_plugins' => array('name'), 'glpi_reservationitems' => array('reservationitem'), 'glpi_tickets' => array('computer', 'device_type'), 'glpi_documenttypes' => array('extension'), 'glpi_users' => array('name'), 'glpi_groups_users' => array('usergroup'));
    foreach ($indextodrop as $table => $tab) {
        foreach ($tab as $indexname) {
            if (isIndex($table, $indexname)) {
                $changes[$table][] = "DROP INDEX `{$indexname}`";
            }
        }
    }
    foreach ($changes as $table => $tab) {
        displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $table);
        // Updating schema
        $query = "ALTER TABLE `{$table}` " . implode($tab, " ,\n") . ";";
        $DB->query($query) or die("0.78 multiple alter in {$table} " . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - Update itemtype fields');
    // Updating schema
    // Convert itemtype to Class names
    $typetoname = array(GENERAL_TYPE => "", COMPUTER_TYPE => "Computer", NETWORKING_TYPE => "NetworkEquipment", PRINTER_TYPE => "Printer", MONITOR_TYPE => "Monitor", PERIPHERAL_TYPE => "Peripheral", SOFTWARE_TYPE => "Software", CONTACT_TYPE => "Contact", ENTERPRISE_TYPE => "Supplier", INFOCOM_TYPE => "Infocom", CONTRACT_TYPE => "Contract", CARTRIDGEITEM_TYPE => "CartridgeItem", TYPEDOC_TYPE => "DocumentType", DOCUMENT_TYPE => "Document", KNOWBASE_TYPE => "KnowbaseItem", USER_TYPE => "User", TRACKING_TYPE => "Ticket", CONSUMABLEITEM_TYPE => "ConsumableItem", CONSUMABLE_TYPE => "Consumable", CARTRIDGE_TYPE => "Cartridge", SOFTWARELICENSE_TYPE => "SoftwareLicense", LINK_TYPE => "Link", STATE_TYPE => "States", PHONE_TYPE => "Phone", DEVICE_TYPE => "Device", REMINDER_TYPE => "Reminder", STAT_TYPE => "Stat", GROUP_TYPE => "Group", ENTITY_TYPE => "Entity", RESERVATION_TYPE => "ReservationItem", AUTHMAIL_TYPE => "AuthMail", AUTHLDAP_TYPE => "AuthLDAP", OCSNG_TYPE => "OcsServer", REGISTRY_TYPE => "RegistryKey", PROFILE_TYPE => "Profile", MAILGATE_TYPE => "MailCollector", RULE_TYPE => "Rule", TRANSFER_TYPE => "Transfer", BOOKMARK_TYPE => "Bookmark", SOFTWAREVERSION_TYPE => "SoftwareVersion", PLUGIN_TYPE => "Plugin", COMPUTERDISK_TYPE => "ComputerDisk", NETWORKING_PORT_TYPE => "NetworkPort", FOLLOWUP_TYPE => "TicketFollowup", BUDGET_TYPE => "Budget");
    $devtypetoname = array(MOBOARD_DEVICE => 'DeviceMotherboard', PROCESSOR_DEVICE => 'DeviceProcessor', RAM_DEVICE => 'DeviceMemory', HDD_DEVICE => 'DeviceHardDrive', NETWORK_DEVICE => 'DeviceNetworkCard', DRIVE_DEVICE => 'DeviceDrive', CONTROL_DEVICE => 'DeviceControl', GFX_DEVICE => 'DeviceGraphicCard', SND_DEVICE => 'DeviceSoundCard', PCI_DEVICE => 'DevicePci', CASE_DEVICE => 'DeviceCase', POWER_DEVICE => 'DevicePowerSupply');
    $itemtype_tables = array("glpi_alerts", "glpi_bookmarks", "glpi_bookmarks_users", "glpi_computers_items", "glpi_contracts_items", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_links_itemtypes", "glpi_networkports", "glpi_reservationitems", "glpi_tickets");
    foreach ($itemtype_tables as $table) {
        displayMigrationMessage("078", $LANG['update'][142] . " - {$table}");
        // Updating data
        // Alter itemtype field
        $query = "ALTER TABLE `{$table}` CHANGE `itemtype` `itemtype` VARCHAR( 100 ) NOT NULL";
        $DB->query($query) or die("0.78 alter itemtype of table {$table} " . $LANG['update'][90] . $DB->error());
        // Update values
        foreach ($typetoname as $key => $val) {
            $query = "UPDATE `{$table}` SET `itemtype` = '{$val}' WHERE `itemtype` = '{$key}'";
            $DB->query($query) or die("0.78 update itemtype of table {$table} for {$val} " . $LANG['update'][90] . $DB->error());
        }
    }
    if (FieldExists('glpi_logs', 'device_type')) {
        // History migration, handled separatly for optimization
        displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_logs - 1');
        // Updating schema
        $query = "ALTER TABLE `glpi_logs`\n               CHANGE `ID` `id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n               ADD `itemtype` VARCHAR(100) NOT NULL DEFAULT ''  AFTER `device_type`,\n               ADD `items_id` INT( 11 ) NOT NULL DEFAULT '0' AFTER `itemtype`,\n               ADD `itemtype_link` VARCHAR(100) NOT NULL DEFAULT '' AFTER `device_internal_type`,\n               CHANGE `linked_action` `linked_action` INT( 11 ) NOT NULL DEFAULT '0'\n                        COMMENT 'see define.php HISTORY_* constant'";
        $DB->query($query) or die("0.78 add item* fields to table glpi_logs " . $LANG['update'][90] . $DB->error());
        // Update values
        displayMigrationMessage("078", $LANG['update'][142] . ' - glpi_logs');
        // Updating schema
        // Copy data
        $query = "UPDATE `glpi_logs` SET `itemtype` = `device_type`, `items_id`=`FK_glpi_device`, `itemtype_link`=`device_internal_type`";
        $DB->query($query) or die("0.78 update glpi_logs default values " . $LANG['update'][90] . $DB->error());
        foreach ($typetoname as $key => $val) {
            $query = "UPDATE `glpi_logs` SET `itemtype` = '{$val}' WHERE `device_type` = '{$key}'";
            $DB->query($query) or die("0.78 update itemtype of table glpi_logs for {$val} " . $LANG['update'][90] . $DB->error());
            $query = "UPDATE `glpi_logs` SET `itemtype_link` = '{$val}'\n                  WHERE `device_internal_type` = '{$key}'\n                     AND `linked_action` IN (" . HISTORY_ADD_RELATION . "," . HISTORY_DEL_RELATION . "," . HISTORY_DISCONNECT_DEVICE . "," . HISTORY_CONNECT_DEVICE . ")";
            $DB->query($query) or die("0.78 update itemtype of table glpi_logs for {$val} " . $LANG['update'][90] . $DB->error());
        }
        foreach ($devtypetoname as $key => $val) {
            $query = "UPDATE `glpi_logs` SET `itemtype_link` = '{$val}'\n                  WHERE `device_internal_type` = '{$key}'\n                     AND `linked_action` IN (" . HISTORY_ADD_DEVICE . "," . HISTORY_UPDATE_DEVICE . "," . HISTORY_DELETE_DEVICE . ")";
            $DB->query($query) or die("0.78 update itemtype of table glpi_logs for {$val} " . $LANG['update'][90] . $DB->error());
        }
        // Clean link
        $query = "UPDATE `glpi_logs` SET `itemtype_link` = ''\n               WHERE `itemtype_link` = '0'";
        $DB->query($query) or die("0.78 update itemtype of table glpi_logs " . $LANG['update'][90] . $DB->error());
        displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_logs - 2');
        // Updating schema
        $query = "ALTER TABLE `glpi_logs`\n               DROP `device_type`,\n               DROP `FK_glpi_device`,\n               DROP `device_internal_type`,\n               ADD INDEX `itemtype_link` (`itemtype_link`),\n               ADD INDEX `item` (`itemtype`,`items_id`)";
        $DB->query($query) or die("0.78 drop device* fields to table glpi_logs " . $LANG['update'][90] . $DB->error());
    }
    // Update glpi_profiles item_type
    displayMigrationMessage("078", $LANG['update'][141] . ' - Clean DB : post actions after renaming');
    // Updating schema
    if (!isIndex('glpi_locations', 'name')) {
        $query = " ALTER TABLE `glpi_locations` ADD INDEX `name` (`name`)";
        $DB->query($query) or die("0.78 add name index in glpi_locations " . $LANG['update'][90] . $DB->error());
    }
    // Update values of mailcollectors
    $query = "SELECT default_mailcollector_filesize_max FROM glpi_configs WHERE id=1";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0) {
            $query = "UPDATE glpi_mailcollectors SET filesize_max='" . $DB->result($result, 0, 0) . "';";
            $DB->query($query);
        }
    }
    // For compatiblity with updates from past versions
    regenerateTreeCompleteName("glpi_locations");
    regenerateTreeCompleteName("glpi_knowbaseitemcategories");
    regenerateTreeCompleteName("glpi_ticketcategories");
    // Update timezone values
    if (FieldExists('glpi_configs', 'time_offset')) {
        $query = "UPDATE glpi_configs SET time_offset=time_offset*3600";
        $DB->query($query) or die("0.78 update time_offset value in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_authldaps', 'time_offset')) {
        $query = "UPDATE glpi_authldaps SET time_offset=time_offset*3600";
        $DB->query($query) or die("0.78 update time_offset value in glpi_authldaps " . $LANG['update'][90] . $DB->error());
    }
    // Change defaults store values :
    if (FieldExists('glpi_softwares', 'sofwtares_id')) {
        $query = "UPDATE glpi_softwares SET sofwtares_id=0 WHERE sofwtares_id < 0";
        $DB->query($query) or die("0.78 update default value of sofwtares_id in glpi_softwares " . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_users', 'authtype')) {
        $query = "UPDATE glpi_users SET authtype=0 WHERE authtype < 0";
        $DB->query($query) or die("0.78 update default value of authtype in glpi_users " . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_users', 'auths_id')) {
        $query = "UPDATE glpi_users SET auths_id=0 WHERE auths_id < 0";
        $DB->query($query) or die("0.78 update default value of auths_id in glpi_users " . $LANG['update'][90] . $DB->error());
    }
    // Update glpi_ocsadmininfoslinks table for new field name
    if (FieldExists('glpi_ocsadmininfoslinks', 'glpi_column')) {
        $query = "UPDATE glpi_ocsadmininfoslinks SET glpi_column='locations_id' WHERE glpi_column = 'location'";
        $DB->query($query) or die("0.78 update value of glpi_column in glpi_ocsadmininfoslinks " . $LANG['update'][90] . $DB->error());
        $query = "UPDATE glpi_ocsadmininfoslinks SET glpi_column='networks_id' WHERE glpi_column = 'network'";
        $DB->query($query) or die("0.78 update value of glpi_column in glpi_ocsadmininfoslinks " . $LANG['update'][90] . $DB->error());
        $query = "UPDATE glpi_ocsadmininfoslinks SET glpi_column='groups_id' WHERE glpi_column = 'FK_groups'";
        $DB->query($query) or die("0.78 update value of glpi_column in glpi_ocsadmininfoslinks " . $LANG['update'][90] . $DB->error());
    }
    // Update bookmarks for new columns fields
    if (FieldExists('glpi_bookmarks', 'is_private')) {
        $query = "UPDATE glpi_bookmarks SET entities_id=-1 WHERE is_private = 1";
        $DB->query($query) or die("0.78 update value of entities_id in glpi_bookmarks " . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_reminders', 'is_private')) {
        $query = "UPDATE glpi_reminders SET entities_id=-1 WHERE is_private = 1";
        $DB->query($query) or die("0.78 update value of entities_id in glpi_reminders " . $LANG['update'][90] . $DB->error());
    }
    // Update bookmarks for new columns fields
    if (FieldExists('glpi_bookmarks', 'query')) {
        // All search
        $olds = array("deleted");
        $news = array("is_deleted");
        foreach ($olds as $key => $val) {
            $olds[$key] = "/&{$val}=/";
        }
        foreach ($news as $key => $val) {
            $news[$key] = "/&{$val}=/";
        }
        // Manage meta search
        foreach ($typetoname as $key => $val) {
            $olds[$key] = "/&type2\\[(\\d+)\\]={$key}/";
            $news[$key] = "&itemtype2[\\1]={$val}";
        }
        $query = "SELECT id, query FROM glpi_bookmarks WHERE type=" . BOOKMARK_SEARCH . " ;";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                while ($data = $DB->fetch_assoc($result)) {
                    $query2 = "UPDATE glpi_bookmarks SET query='" . addslashes(preg_replace($olds, $news, $data['query'])) . "' WHERE id=" . $data['id'] . ";";
                    $DB->query($query2) or die("0.78 update all bookmarks " . $LANG['update'][90] . $DB->error());
                }
            }
        }
        // Update bookmarks due to FHS change
        $query2 = "UPDATE glpi_bookmarks SET path='front/documenttype.php' WHERE path='front/typedoc.php';";
        $DB->query($query2) or die("0.78 update typedoc bookmarks " . $LANG['update'][90] . $DB->error());
        $query2 = "UPDATE glpi_bookmarks SET path='front/consumableitem.php' WHERE path='front/consumable.php';";
        $DB->query($query2) or die("0.78 update consumable bookmarks " . $LANG['update'][90] . $DB->error());
        $query2 = "UPDATE glpi_bookmarks SET path='front/cartridgeitem.php' WHERE path='front/cartridge.php';";
        $DB->query($query2) or die("0.78 update cartridge bookmarks " . $LANG['update'][90] . $DB->error());
        $query2 = "UPDATE glpi_bookmarks SET path='front/ticket.php' WHERE path='front/tracking.php';";
        $DB->query($query2) or die("0.78 update ticket bookmarks " . $LANG['update'][90] . $DB->error());
        $query2 = "UPDATE glpi_bookmarks SET path='front/mailcollector.php' WHERE path='front/mailgate.php';";
        $DB->query($query2) or die("0.78 update mailcollector bookmarks " . $LANG['update'][90] . $DB->error());
        $query2 = "UPDATE glpi_bookmarks SET path='front/ocsserver.php' WHERE path='front/setup.ocsng.php';";
        $DB->query($query2) or die("0.78 update ocsserver bookmarks " . $LANG['update'][90] . $DB->error());
        $query2 = "UPDATE glpi_bookmarks SET path='front/supplier.php' WHERE path='front/enterprise.php';";
        $DB->query($query2) or die("0.78 update supplier bookmarks " . $LANG['update'][90] . $DB->error());
        $query2 = "UPDATE glpi_bookmarks SET path='front/networkequipment.php' WHERE path='front/networking.php';";
        $DB->query($query2) or die("0.78 update networkequipment bookmarks " . $LANG['update'][90] . $DB->error());
        $query2 = "UPDATE glpi_bookmarks SET path='front/states.php' WHERE path='front/state.php';";
        $DB->query($query2) or die("0.78 update states bookmarks " . $LANG['update'][90] . $DB->error());
    }
    //// Upgrade rules datas
    // For Rule::RULE_AFFECT_RIGHTS
    $changes[1] = array('FK_entities' => 'entities_id', 'FK_profiles' => 'profiles_id', 'recursive' => 'is_recursive', 'active' => 'is_active');
    // For Rule::RULE_DICTIONNARY_SOFTWARE
    $changes[4] = array('helpdesk_visible' => 'is_helpdesk_visible');
    // For Rule::RULE_OCS_AFFECT_COMPUTER
    $changes[0] = array('FK_entities' => 'entities_id');
    // For Rule::RULE_SOFTWARE_CATEGORY
    $changes[3] = array('category' => 'softwarecategories_id', 'comment' => 'comment');
    // For Rule::RULE_TRACKING_AUTO_ACTION
    $changes[2] = array('category' => 'ticketcategories_id', 'author' => 'users_id', 'author_location' => 'users_locations', 'FK_group' => 'groups_id', 'assign' => 'users_id_assign', 'assign_group' => 'groups_id_assign', 'device_type' => 'itemtype', 'FK_entities' => 'entities_id', 'contents' => 'content', 'request_type' => 'requesttypes_id');
    $DB->query("SET SESSION group_concat_max_len = 9999999;");
    foreach ($changes as $ruletype => $tab) {
        // Get rules
        $query = "SELECT GROUP_CONCAT(id) FROM glpi_rules WHERE sub_type=" . $ruletype . " GROUP BY sub_type;";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                // Get rule string
                $rules = $DB->result($result, 0, 0);
                // Update actions
                foreach ($tab as $old => $new) {
                    $query = "UPDATE glpi_ruleactions SET field='{$new}' WHERE field='{$old}' AND rules_id IN ({$rules});";
                    $DB->query($query) or die("0.78 update datas for rules actions " . $LANG['update'][90] . $DB->error());
                }
                // Update criterias
                foreach ($tab as $old => $new) {
                    $query = "UPDATE glpi_rulecriterias SET criteria='{$new}' WHERE criteria='{$old}' AND rules_id IN ({$rules});";
                    $DB->query($query) or die("0.78 update datas for rules criterias " . $LANG['update'][90] . $DB->error());
                }
            }
        }
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_rulecachesoftwares');
    // Updating schema
    $query = "ALTER TABLE `glpi_rules` CHANGE `sub_type` `sub_type` VARCHAR( 255 ) NOT NULL DEFAULT ''";
    $DB->query($query) or die("0.78 change subtype from INT(11) to VARCHAR(255) in glpi_rules " . $LANG['update'][90] . $DB->error());
    $subtypes = array(0 => 'RuleOcs', 1 => 'RuleRight', 2 => 'RuleTicket', 3 => 'RuleSoftwareCategory', 4 => 'RuleDictionnarySoftware', 5 => 'RuleDictionnaryManufacturer', 6 => 'RuleDictionnaryComputerModel', 7 => 'RuleDictionnaryComputerType', 8 => 'RuleDictionnaryMonitorModel', 9 => 'RuleDictionnaryMonitorType', 10 => 'RuleDictionnaryPrinterModel', 11 => 'RuleDictionnaryPrinterType', 12 => 'RuleDictionnaryPhoneModel', 13 => 'RuleDictionnaryPhoneType', 14 => 'RuleDictionnaryPeripheralModel', 15 => 'RuleDictionnaryPeripheralType', 16 => 'RuleDictionnaryNetworkEquipmentModel', 17 => 'RuleDictionnaryNetworkEquipmentType', 18 => 'RuleDictionnaryOperatingSystem', 19 => 'RuleDictionnaryOperatingSystemServicePack', 20 => 'RuleDictionnaryOperatingSystemVersion', 21 => 'RuleMailCollector');
    foreach ($subtypes as $old_subtype => $new_subtype) {
        $query = "UPDATE `glpi_rules` SET `sub_type`='{$new_subtype}' WHERE `sub_type`='{$old_subtype}'";
        $DB->query($query) or die("0.78 change sub_type {$old_subtype} in {$new_subtype} in glpi_rules " . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists("glpi_rulecachesoftwares", "ignore_ocs_import")) {
        $query = "ALTER TABLE `glpi_rulecachesoftwares` CHANGE `ignore_ocs_import` `ignore_ocs_import` CHAR( 1 ) NULL DEFAULT NULL ";
        $DB->query($query) or die("0.78 alter table glpi_rulecachesoftwares " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_rulecachesoftwares", "is_helpdesk_visible")) {
        $query = "ALTER TABLE `glpi_rulecachesoftwares` ADD `is_helpdesk_visible` CHAR( 1 ) NULL ";
        $DB->query($query) or die("0.78 add is_helpdesk_visible in glpi_rulecachesoftwares " . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_entities');
    // Updating schema
    if (!FieldExists("glpi_entities", "sons_cache")) {
        $query = "ALTER TABLE `glpi_entities` ADD `sons_cache` LONGTEXT NULL ; ";
        $DB->query($query) or die("0.78 add sons_cache field in glpi_entities " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_entities", "ancestors_cache")) {
        $query = "ALTER TABLE `glpi_entities` ADD `ancestors_cache` LONGTEXT NULL ; ";
        $DB->query($query) or die("0.78 add ancestors_cache field in glpi_entities " . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_configs');
    // Updating schema
    if (!FieldExists("glpi_configs", "default_graphtype")) {
        $query = "ALTER TABLE `glpi_configs` ADD `default_graphtype` char( 3 ) NOT NULL DEFAULT 'svg'";
        $DB->query($query) or die("0.78 add default_graphtype in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_configs', 'license_deglobalisation')) {
        $query = "ALTER TABLE `glpi_configs` DROP `license_deglobalisation`;";
        $DB->query($query) or die("0.78 alter clean glpi_configs table " . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists("glpi_configs", "use_cache")) {
        $query = "ALTER TABLE `glpi_configs`  DROP `use_cache`;";
        $DB->query($query) or die("0.78 drop use_cache in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists("glpi_configs", "cache_max_size")) {
        $query = "ALTER TABLE `glpi_configs`  DROP `cache_max_size`;";
        $DB->query($query) or die("0.78 drop cache_max_size in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_configs", "default_request_type")) {
        $query = "ALTER TABLE `glpi_configs` ADD `default_request_type` INT( 11 ) NOT NULL DEFAULT 1";
        $DB->query($query) or die("0.78 add default_request_type in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_users", "default_request_type")) {
        $query = "ALTER TABLE `glpi_users` ADD `default_request_type` INT( 11 ) NULL";
        $DB->query($query) or die("0.78 add default_request_type in glpi_users " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_configs", "use_noright_users_add")) {
        $query = "ALTER TABLE `glpi_configs` ADD `use_noright_users_add` tinyint( 1 ) NOT NULL DEFAULT '1'";
        $DB->query($query) or die("0.78 add use_noright_users_add in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_budgets');
    // Updating schema
    if (!FieldExists("glpi_profiles", "budget")) {
        $query = "ALTER TABLE `glpi_profiles` ADD `budget` CHAR( 1 ) NULL ";
        $DB->query($query) or die("0.78 add budget in glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `budget`=`infocom`";
        $DB->query($query) or die("0.78 update default budget rights" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "is_recursive")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `is_recursive` tinyint(1) NOT NULL DEFAULT '0' AFTER `name`,\n                                          ADD INDEX `is_recursive` (`is_recursive`)";
        $DB->query($query) or die("0.78 add is_recursive field in glpi_budgets" . $LANG['update'][90] . $DB->error());
        // budgets in 0.72 were global
        $query = "UPDATE `glpi_budgets` SET `is_recursive` = '1';";
        $DB->query($query) or die("0.78 set is_recursive to true in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "entities_id")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `entities_id` int(11) NOT NULL default '0' AFTER `name`,\n                                          ADD INDEX `entities_id` (`entities_id`);";
        $DB->query($query) or die("0.78 add entities_id field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "is_deleted")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `is_deleted` tinyint(1) NOT NULL DEFAULT '0',\n                                       ADD INDEX `is_deleted` (`is_deleted`)";
        $DB->query($query) or die("0.78 add is_deleted field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "begin_date")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `begin_date` DATE NULL,\n                                          ADD INDEX `begin_date` (`begin_date`)";
        $DB->query($query) or die("0.78 add begin_date field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "end_date")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `end_date` DATE NULL,\n                                          ADD INDEX `end_date` (`begin_date`)";
        $DB->query($query) or die("0.78 add end_date field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "value")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `value` DECIMAL( 20, 4 )  NOT NULL default '0.0000'";
        $DB->query($query) or die("0.78 add value field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "is_template")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `is_template` tinyint(1) NOT NULL default '0',\n                                          ADD INDEX `is_template` (`is_template`);";
        $DB->query($query) or die("0.78 add is_template field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "template_name")) {
        $query = "ALTER TABLE `glpi_budgets`  ADD `template_name` varchar(255) default NULL";
        $DB->query($query) or die("0.78 add template_name field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "date_mod")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `date_mod`  DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_budgets", "notepad")) {
        $query = "ALTER TABLE `glpi_budgets` ADD `notepad` LONGTEXT NULL collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add notepad field in glpi_budgets" . $LANG['update'][90] . $DB->error());
    }
    // Change budget search pref : date_mod
    $ADDTODISPLAYPREF['Budget'] = array(2, 3, 4, 19);
    displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $LANG['crontask'][0]);
    // Updating schema
    if (!TableExists('glpi_crontasks')) {
        $query = "CREATE TABLE `glpi_crontasks` (\n        `id` int(11) NOT NULL AUTO_INCREMENT,\n        `itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n        `name` varchar(150) COLLATE utf8_unicode_ci NOT NULL COMMENT 'task name',\n        `frequency` int(11) NOT NULL COMMENT 'second between launch',\n        `param` int(11) DEFAULT NULL COMMENT 'task specify parameter',\n        `state` int(11) NOT NULL DEFAULT '1' COMMENT '0:disabled, 1:waiting, 2:running',\n        `mode` int(11) NOT NULL DEFAULT '1' COMMENT '1:internal, 2:external',\n        `allowmode` int(11) NOT NULL DEFAULT '3' COMMENT '1:internal, 2:external, 3:both',\n        `hourmin` int(11) NOT NULL DEFAULT '0',\n        `hourmax` int(11) NOT NULL DEFAULT '24',\n        `logs_lifetime` int(11) NOT NULL DEFAULT '30' COMMENT 'number of days',\n        `lastrun` datetime DEFAULT NULL COMMENT 'last run date',\n        `lastcode` int(11) DEFAULT NULL COMMENT 'last run return code',\n        `comment` text COLLATE utf8_unicode_ci,\n        PRIMARY KEY (`id`),\n        UNIQUE KEY `unicity` (`itemtype`,`name`),\n        KEY `mode` (`mode`)\n      ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci\n        COMMENT='Task run by internal / external cron.';";
        $DB->query($query) or die("0.78 create glpi_crontasks" . $LANG['update'][90] . $DB->error());
        $query = "INSERT INTO `glpi_crontasks`\n         (`itemtype`, `name`, `frequency`, `param`, `state`, `mode`, `allowmode`, `hourmin`, `hourmax`, `logs_lifetime`, `lastrun`, `lastcode`, `comment`)\n         VALUES\n         ('OcsServer', 'ocsng', 300, NULL, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('CartridgeItem', 'cartridge', 86400, 10, 0, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('ConsumableItem', 'consumable', 86400, 10, 0, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('SoftwareLicense', 'software', 86400, NULL, 0, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('Contract', 'contract', 86400, NULL, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('InfoCom', 'infocom', 86400, NULL, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('CronTask', 'logs', 86400, 10, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('CronTask', 'optimize', 604800, NULL, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('MailCollector', 'mailgate', 600, 10, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('DBconnection', 'checkdbreplicate', 300, NULL, 0, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('CronTask', 'checkupdate', 604800, NULL, 0, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('CronTask', 'session', 86400, NULL, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('CronTask', 'graph', 3600, NULL, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('ReservationItem', 'reservation', 3600, NULL, 1, 1, 3, 0, 24, 30, NULL, NULL, NULL),\n         ('Ticket','closeticket','43200',NULL,'1','1','3','0','24','30',NULL,NULL,NULL),\n         ('Ticket','alertnotclosed','43200',NULL,'1','1','3','0','24','30',NULL,NULL,NULL)";
        $DB->query($query) or die("0.78 populate glpi_crontasks" . $LANG['update'][90] . $DB->error());
    }
    $ADDTODISPLAYPREF['Crontask'] = array(8, 3, 4, 7);
    if (!TableExists('glpi_crontasklogs')) {
        $query = "CREATE TABLE `glpi_crontasklogs` (\n        `id` int(11) NOT NULL AUTO_INCREMENT,\n        `crontasks_id` int(11) NOT NULL,\n        `crontasklogs_id` int(11) NOT NULL COMMENT 'id of ''start'' event',\n        `date` datetime NOT NULL,\n        `state` int(11) NOT NULL COMMENT '0:start, 1:run, 2:stop',\n        `elapsed` float NOT NULL COMMENT 'time elapsed since start',\n        `volume` int(11) NOT NULL COMMENT 'for statistics',\n        `content` varchar(255) COLLATE utf8_unicode_ci NULL COMMENT 'message',\n        PRIMARY KEY (`id`),\n        KEY `date` (`date`),\n        KEY `crontasks_id` (`crontasks_id`),\n        KEY `crontasklogs_id_state` (`crontasklogs_id`,`state`)\n      ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;";
        $DB->query($query) or die("0.78 create glpi_crontasklogs" . $LANG['update'][90] . $DB->error());
    }
    // Retrieve core task lastrun date
    $tasks = array('ocsng', 'cartridge', 'consumable', 'software', 'contract', 'infocom', 'logs', 'optimize', 'mailgate', 'DBConnection', 'check_update', 'session');
    foreach ($tasks as $task) {
        $lock = GLPI_CRON_DIR . '/' . $task . '.lock';
        if (is_readable($lock) && ($stat = stat($lock))) {
            $DB->query("UPDATE `glpi_crontasks` SET `lastrun`='" . date('Y-m-d H:i:s', $stat['mtime']) . "'\n                     WHERE `name`='{$task}'");
            unlink($lock);
        }
    }
    // Clean plugin lock
    foreach (glob(GLPI_CRON_DIR . '/*.lock') as $lock) {
        unlink($lock);
    }
    // disable ocsng cron if not activate
    if (FieldExists('glpi_configs', 'use_ocs_mode')) {
        $query = "SELECT `use_ocs_mode` FROM `glpi_configs` WHERE `id`=1";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                $value = $DB->result($result, 0, 0);
                if ($value == 0) {
                    $query = "UPDATE `glpi_crontasks` SET `state`='0' WHERE `name`='ocsng';";
                    $DB->query($query);
                }
            }
        }
    }
    // Move glpi_config.expire_events to glpi_crontasks.param
    if (FieldExists('glpi_configs', 'expire_events')) {
        $query = "SELECT `expire_events` FROM `glpi_configs` WHERE `id`=1";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                $value = $DB->result($result, 0, 0);
                if ($value > 0) {
                    $query = "UPDATE `glpi_crontasks` SET `state`='1', `param`='{$value}' WHERE `name`='logs';";
                } else {
                    $query = "UPDATE `glpi_crontasks` SET `state`='0' WHERE `name`='logs';";
                }
                $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_configs` DROP `expire_events`";
        $DB->query($query) or die("0.78 drop expire_events in glpi_configs" . $LANG['update'][90] . $DB->error());
    }
    // Move glpi_config.auto_update_check to glpi_crontasks.state
    if (FieldExists('glpi_configs', 'auto_update_check')) {
        $query = "SELECT `auto_update_check` FROM `glpi_configs` WHERE id=1";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                $value = $DB->result($result, 0, 0);
                if ($value > 0) {
                    $value *= DAY_TIMESTAMP;
                    $query = "UPDATE `glpi_crontasks` SET `state`='1', `frequency`='{$value}' WHERE `name`='check_update';";
                } else {
                    $query = "UPDATE `glpi_crontasks` SET `state`='0' WHERE `name`='logs';";
                }
                $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_configs` DROP `auto_update_check`";
        $DB->query($query) or die("0.78 drop auto_update_check in check_update" . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_configs', 'dbreplicate_maxdelay')) {
        $query = "SELECT `dbreplicate_maxdelay` FROM `glpi_configs` WHERE id=1";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                $value = $DB->result($result, 0, 0);
                $value = intval($value / 60);
                $query = "UPDATE `glpi_crontasks` SET `state`='1', `frequency`='{$value}' WHERE `name`='check_dbreplicate';";
                $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_configs` DROP `dbreplicate_maxdelay`";
        $DB->query($query) or die("0.78 drop dbreplicate_maxdelay in check_update" . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_configs', 'dbreplicate_notify_desynchronization')) {
        $query = "ALTER TABLE `glpi_configs` DROP `dbreplicate_notify_desynchronization`";
        $DB->query($query) or die("0.78 drop dbreplicate_notify_desynchronization in check_update" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_configs', 'cron_limit')) {
        $query = "ALTER TABLE `glpi_configs` ADD `cron_limit` TINYINT NOT NULL DEFAULT '1'\n                           COMMENT 'Number of tasks execute by external cron'";
        $DB->query($query) or die("0.78 add cron_limit in glpi_configs" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_documents', 'sha1sum')) {
        $query = "ALTER TABLE `glpi_documents`\n                   ADD `sha1sum` CHAR(40) NULL DEFAULT NULL ,\n                   ADD INDEX `sha1sum` (`sha1sum`)";
        $DB->query($query) or die("0.78 add sha1sum in glpi_documents" . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_documents', 'filename')) {
        $query = "ALTER TABLE `glpi_documents`\n                  CHANGE `filename` `filename` VARCHAR( 255 ) NULL DEFAULT NULL\n                  COMMENT 'for display and transfert'";
        $DB->query($query) or die("0.78 alter filename in glpi_documents" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_documents', 'filepath')) {
        $query = "ALTER TABLE `glpi_documents`\n                ADD `filepath` VARCHAR( 255 ) NULL\n                COMMENT 'file storage path' AFTER `filename`";
        $DB->query($query) or die("0.78 add filepath in glpi_documents" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_documents` SET `filepath`=`filename`";
        $DB->query($query) or die("0.78 set value of filepath in glpi_documents" . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $LANG['setup'][79]);
    // Updating schema
    if (!FieldExists('glpi_tickets', 'solvedate')) {
        $query = "ALTER TABLE `glpi_tickets` ADD `solvedate` datetime default NULL AFTER `closedate`,\n                                       ADD INDEX `solvedate` (`solvedate`)";
        $DB->query($query) or die("0.78 add solvedate to glpi_tickets " . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_tickets` SET `solvedate` = `closedate`";
        $DB->query($query) or die("0.78 update solvedate values in glpi_tickets " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_ticketcategories', 'entities_id')) {
        $query = "ALTER TABLE `glpi_ticketcategories`\n                    ADD `entities_id` INT NOT NULL DEFAULT '0' AFTER `id`,\n                    ADD `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `entities_id`,\n                    ADD INDEX `entities_id` (`entities_id`),ADD INDEX `is_recursive` (`is_recursive`)";
        $DB->query($query) or die("0.78 add entities_id,is_recursive in glpi_ticketcategories" . $LANG['update'][90] . $DB->error());
        // Set existing categories recursive global
        $query = "UPDATE `glpi_ticketcategories` SET `is_recursive` = '1'";
        $DB->query($query) or die("0.78 set value of is_recursive in glpi_ticketcategories" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_ticketcategories', 'knowbaseitemcategories_id')) {
        $query = "ALTER TABLE `glpi_ticketcategories`\n                      ADD `knowbaseitemcategories_id` INT NOT NULL DEFAULT '0',\n                      ADD INDEX `knowbaseitemcategories_id` ( `knowbaseitemcategories_id` )";
        $DB->query($query) or die("0.78 add knowbaseitemcategories_id in glpi_ticketcategories" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_ticketcategories', 'users_id')) {
        $query = "ALTER TABLE `glpi_ticketcategories`\n                        ADD `users_id` INT NOT NULL DEFAULT '0',\n                        ADD INDEX `users_id` ( `users_id` ) ";
        $DB->query($query) or die("0.78 add users_id in glpi_ticketcategories" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_ticketcategories', 'groups_id')) {
        $query = "ALTER TABLE `glpi_ticketcategories`\n                        ADD `groups_id` INT NOT NULL DEFAULT '0',\n                        ADD INDEX `groups_id` ( `groups_id` ) ";
        $DB->query($query) or die("0.78 add groups_id in glpi_ticketcategories" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_ticketcategories', 'ancestors_cache')) {
        $query = "ALTER TABLE `glpi_ticketcategories`\n                        ADD `ancestors_cache` LONGTEXT NULL,\n                        ADD `sons_cache` LONGTEXT NULL";
        $DB->query($query) or die("0.78 add cache in glpi_ticketcategories" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_ticketcategories', 'is_helpdeskvisible')) {
        $query = "ALTER TABLE `glpi_ticketcategories`\n                        ADD `is_helpdeskvisible` TINYINT( 1 ) NOT NULL DEFAULT '1',\n                        ADD INDEX `is_helpdeskvisible` (`is_helpdeskvisible`)";
        $DB->query($query) or die("0.78 add cache in glpi_ticketcategories" . $LANG['update'][90] . $DB->error());
    }
    // change item type management for helpdesk
    if (FieldExists('glpi_profiles', 'helpdesk_hardware_type')) {
        $query = "ALTER TABLE `glpi_profiles` ADD `helpdesk_item_type` TEXT NULL DEFAULT NULL AFTER `helpdesk_hardware_type` ;";
        $DB->query($query) or die("0.78 add  helpdesk_item_type in glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "SELECT id, helpdesk_hardware_type FROM glpi_profiles";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                while ($data = $DB->fetch_assoc($result)) {
                    $types = $data['helpdesk_hardware_type'];
                    $CFG_GLPI["ticket_types"] = array(COMPUTER_TYPE, NETWORKING_TYPE, PRINTER_TYPE, MONITOR_TYPE, PERIPHERAL_TYPE, SOFTWARE_TYPE, PHONE_TYPE);
                    $tostore = array();
                    foreach ($CFG_GLPI["ticket_types"] as $itemtype) {
                        if (pow(2, $itemtype) & $types) {
                            $tostore[] = $typetoname[$itemtype];
                        }
                    }
                    $query = "UPDATE `glpi_profiles`\n                     SET `helpdesk_item_type`='" . exportArrayToDB($tostore) . "'\n                     WHERE `id`='" . $data['id'] . "'";
                    $DB->query($query) or die("0.78 populate helpdesk_item_type" . $LANG['update'][90] . $DB->error());
                }
            }
        }
        $query = "ALTER TABLE `glpi_profiles` DROP `helpdesk_hardware_type`;";
        $DB->query($query) or die("0.78 drop helpdesk_hardware_type in glpi_profiles" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_profiles', 'helpdesk_status')) {
        $query = "ALTER TABLE `glpi_profiles`\n                   ADD `helpdesk_status` TEXT NULL\n                        COMMENT 'json encoded array of from/dest allowed status change'\n                        AFTER `helpdesk_item_type`";
        $DB->query($query) or die("0.78 add helpdesk_status in glpi_profiles" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_profiles', 'update_priority')) {
        $query = "ALTER TABLE `glpi_profiles`\n                ADD `update_priority` CHAR( 1 ) NULL DEFAULT NULL AFTER `update_ticket`";
        $DB->query($query) or die("0.78 add update_priority in glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `update_priority`=`update_ticket`";
        $DB->query($query) or die("0.78 set update_priority in glpi_profiles" . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_profiles', 'comment_ticket')) {
        $query = "ALTER TABLE `glpi_profiles`\n                CHANGE `comment_ticket` `add_followups` CHAR(1) NULL DEFAULT NULL";
        $DB->query($query) or die("0.78 add add_followups in glpi_profiles" . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_profiles', 'comment_all_ticket')) {
        $query = "ALTER TABLE `glpi_profiles`\n                CHANGE `comment_all_ticket` `global_add_followups`  CHAR(1) NULL DEFAULT NULL";
        $DB->query($query) or die("0.78 add add_followups in glpi_profiles" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_profiles', 'update_tasks')) {
        $query = "ALTER TABLE `glpi_profiles`\n                ADD `global_add_tasks` CHAR( 1 ) NULL AFTER `global_add_followups`,\n                ADD `update_tasks` CHAR( 1 ) NULL AFTER `update_followups`";
        $DB->query($query) or die("0.78 add global_add_tasks, update_tasks in glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles`\n                SET `update_tasks`=`update_followups`, `global_add_tasks`=`global_add_followups`";
        $DB->query($query) or die("0.78 set update_tasks, global_add_tasks in glpi_profiles" . $LANG['update'][90] . $DB->error());
    }
    if (!TableExists('glpi_taskcategories')) {
        $query = "CREATE TABLE `glpi_taskcategories` (\n           `id` int(11) NOT NULL auto_increment,\n           `entities_id` int(11) NOT NULL default '0',\n           `is_recursive` tinyint(1) NOT NULL default '0',\n           `taskcategories_id` int(11) NOT NULL default '0',\n           `name` varchar(255) default NULL,\n           `completename` text,\n           `comment` text,\n           `level` int(11) NOT NULL default '0',\n           `ancestors_cache` longtext,\n           `sons_cache` longtext,\n           `is_helpdeskvisible` tinyint(1) NOT NULL default '1',\n           PRIMARY KEY  (`id`),\n           KEY `name` (`name`),\n           KEY `taskcategories_id` (`taskcategories_id`),\n           KEY `entities_id` (`entities_id`),\n           KEY `is_recursive` (`is_recursive`),\n           KEY `is_helpdeskvisible` (`is_helpdeskvisible`)\n         ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query) or die("0.78 create glpi_taskcategories" . $LANG['update'][90] . $DB->error());
    }
    if (!TableExists('glpi_ticketsolutiontypes')) {
        $query = "CREATE TABLE `glpi_ticketsolutiontypes` (\n           `id` int(11) NOT NULL auto_increment,\n           `name` varchar(255) default NULL,\n           `comment` text,\n           PRIMARY KEY  (`id`),\n           KEY `name` (`name`)\n         ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query) or die("0.78 create glpi_ticketsolutiontypes" . $LANG['update'][90] . $DB->error());
        // Populate only required for migration of ticket status
        $query = "INSERT INTO `glpi_ticketsolutiontypes`\n                (`id` ,`name` ,`comment`)\n                VALUES\n                ('1', '" . $LANG['joblist'][17] . "', NULL),\n                ('2', '" . $LANG['joblist'][10] . "', NULL)";
        $DB->query($query) or die("0.78 populate glpi_ticketsolutiontypes" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_tickets', 'solution')) {
        $query = "ALTER TABLE `glpi_tickets`\n                  ADD `ticketsolutiontypes_id` INT( 11 ) NOT NULL DEFAULT '0',\n                  ADD `solution` TEXT NULL,\n                  ADD INDEX `ticketsolutiontypes_id` ( `ticketsolutiontypes_id` ) ";
        $DB->query($query) or die("0.78 create glpi_ticketsolutions" . $LANG['update'][90] . $DB->error());
        // Move old status "old_done"", "old_notdone" as solution
        // and change to new "solved" / "closed" status
        $query = "UPDATE `glpi_tickets`\n                SET `ticketsolutiontypes_id`='2', `status`='closed'\n                WHERE `status`='old_done'";
        $DB->query($query) or die("0.78 migration of glpi_tickets status" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_tickets`\n                SET `ticketsolutiontypes_id`='1', `status`='closed'\n                WHERE `status`='old_notdone'";
        $DB->query($query) or die("0.78 migration of glpi_tickets status" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_documenttypes', 'comment')) {
        $query = "ALTER TABLE `glpi_documenttypes` ADD `comment` TEXT NULL ";
        $DB->query($query) or die("0.78 add comment in glpi_documenttypes" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_locations', 'is_recursive')) {
        $query = "ALTER TABLE `glpi_locations`\n                        ADD `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `entities_id`,\n                        ADD `ancestors_cache` LONGTEXT NULL,\n                        ADD `sons_cache` LONGTEXT NULL,\n                        ADD INDEX `is_recursive` (`is_recursive`)";
        $DB->query($query) or die("0.78 add recursive, cache in glpi_locations" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_locations', 'building')) {
        $query = "ALTER TABLE `glpi_locations` ADD `building` VARCHAR( 255 ) NULL ,\n                                             ADD `room` VARCHAR( 255 ) NULL ";
        $DB->query($query) or die("0.78 add building, room in glpi_locations" . $LANG['update'][90] . $DB->error());
    }
    if (!TableExists('glpi_requesttypes')) {
        $query = "CREATE TABLE `glpi_requesttypes` (\n              `id` int(11) NOT NULL AUTO_INCREMENT,\n              `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n              `is_helpdesk_default` tinyint(1) NOT NULL DEFAULT '0',\n              `is_mail_default` tinyint(1) NOT NULL DEFAULT '0',\n              `comment` text COLLATE utf8_unicode_ci,\n              PRIMARY KEY (`id`),\n              KEY `name` (`name`),\n              KEY `is_helpdesk_default` (`is_helpdesk_default`),\n              KEY `is_mail_default` (`is_mail_default`)\n            ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("0.78 create glpi_requesttypes" . $LANG['update'][90] . $DB->error());
        $DB->query("INSERT INTO `glpi_requesttypes` VALUES(1, '" . addslashes($LANG['Menu'][31]) . "', 1, 0, NULL)");
        $DB->query("INSERT INTO `glpi_requesttypes` VALUES(2, '" . addslashes($LANG['setup'][14]) . "', 0, 1, NULL)");
        $DB->query("INSERT INTO `glpi_requesttypes` VALUES(3, '" . addslashes($LANG['help'][35]) . "', 0, 0, NULL)");
        $DB->query("INSERT INTO `glpi_requesttypes` VALUES(4, '" . addslashes($LANG['tracking'][34]) . "', 0, 0, NULL)");
        $DB->query("INSERT INTO `glpi_requesttypes` VALUES(5, '" . addslashes($LANG['tracking'][35]) . "', 0, 0, NULL)");
        $DB->query("INSERT INTO `glpi_requesttypes` VALUES(6, '" . addslashes($LANG['common'][62]) . "', 0, 0, NULL)");
    }
    // Add default display
    $ADDTODISPLAYPREF['RequestType'] = array(14, 15);
    if (FieldExists('glpi_tickets', 'request_type')) {
        $query = "ALTER TABLE `glpi_tickets`\n                      CHANGE `request_type` `requesttypes_id` INT( 11 ) NOT NULL DEFAULT '0'";
        $DB->query($query) or die("0.78 change requesttypes_id in glpi_tickets" . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_configs', 'default_request_type')) {
        $query = "ALTER TABLE `glpi_configs`\n            CHANGE `default_request_type` `default_requesttypes_id` INT( 11 ) NOT NULL DEFAULT '1'";
        $DB->query($query) or die("0.78 change requesttypes_id in glpi_configs" . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_users', 'default_request_type')) {
        $query = "ALTER TABLE `glpi_users`\n                CHANGE `default_request_type` `default_requesttypes_id` INT( 11 ) NULL DEFAULT NULL";
        $DB->query($query) or die("0.78 change requesttypes_id in glpi_users" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_groups', 'date_mod')) {
        $query = "ALTER TABLE `glpi_groups`\n                ADD `date_mod` DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod to glpi_groups" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_configs", "priority_matrix")) {
        $query = "ALTER TABLE `glpi_configs`\n                   ADD `priority_matrix` VARCHAR( 255 ) NULL\n                      COMMENT 'json encoded array for Urgence / Impact to Protority'";
        $DB->query($query) or die("0.78 add priority_matrix  in glpi_configs " . $LANG['update'][90] . $DB->error());
        $matrix = array(1 => array(1 => 1, 2 => 1, 3 => 2, 4 => 2, 4 => 2, 5 => 2), 2 => array(1 => 1, 2 => 2, 3 => 2, 4 => 3, 4 => 3, 5 => 3), 3 => array(1 => 2, 2 => 2, 3 => 3, 4 => 4, 4 => 4, 5 => 4), 4 => array(1 => 2, 2 => 3, 3 => 4, 4 => 4, 4 => 4, 5 => 5), 5 => array(1 => 2, 2 => 3, 3 => 4, 4 => 5, 4 => 5, 5 => 5));
        $matrix = exportArrayToDB($matrix);
        $query = "UPDATE `glpi_configs` SET `priority_matrix`='{$matrix}' WHERE `id`='1'";
        $DB->query($query) or die("0.78 set default priority_matrix  in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_configs", "urgency_mask")) {
        $query = "ALTER TABLE `glpi_configs`\n                      ADD `urgency_mask` INT( 11 ) NOT NULL DEFAULT '62',\n                      ADD `impact_mask` INT( 11 ) NOT NULL DEFAULT '62'";
        $DB->query($query) or die("0.78 add urgency/impact_mask  in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_users", "priority_6")) {
        $query = "ALTER TABLE `glpi_users`\n                      ADD `priority_6` CHAR( 20 ) NULL DEFAULT NULL AFTER `priority_5`";
        $DB->query($query) or die("0.78 add priority_6  in glpi_users " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_configs", "priority_6")) {
        $query = "ALTER TABLE `glpi_configs`\n                       ADD `priority_6` CHAR( 20 ) NOT NULL DEFAULT '#ff5555' AFTER `priority_5`";
        $DB->query($query) or die("0.78 add priority_6  in glpi_configs " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_tickets', 'urgency')) {
        $query = "ALTER TABLE `glpi_tickets`\n                      ADD `urgency` INT NOT NULL DEFAULT '1' AFTER `content`,\n                      ADD `impact` INT NOT NULL DEFAULT '1' AFTER `urgency`,\n                      ADD INDEX `urgency` (`urgency`),\n                      ADD INDEX `impact` (`impact`)";
        $DB->query($query) or die("0.78 add urgency, impact to glpi_tickets" . $LANG['update'][90] . $DB->error());
        // set default trivial values for Impact and Urgence
        $query = "UPDATE `glpi_tickets` SET `urgency` = `priority`, `impact` = `priority`";
        $DB->query($query) or die("0.78 set urgency, impact in glpi_tickets" . $LANG['update'][90] . $DB->error());
        // Replace 'priority' (user choice un 0.72) by 'urgency' as criteria
        // Don't change "action" which is the result of user+tech evaluation.
        $query = "UPDATE `glpi_rulecriterias`\n                SET `criteria`='urgency'\n                WHERE `criteria`='priority'\n                  AND `rules_id` IN (SELECT `id`\n                                     FROM `glpi_rules`\n                                     WHERE `sub_type`='RuleTicket')";
        $DB->query($query) or die("0.78 fix priority/urgency in business rules " . $LANG['update'][90] . $DB->error());
    }
    if (!TableExists('glpi_tickettasks')) {
        $query = "CREATE TABLE `glpi_tickettasks` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `tickets_id` int(11) NOT NULL default '0',\n                  `taskcategories_id` int(11) NOT NULL default '0',\n                  `date` datetime default NULL,\n                  `users_id` int(11) NOT NULL default '0',\n                  `content` longtext collate utf8_unicode_ci,\n                  `is_private` tinyint(1) NOT NULL default '0',\n                  `realtime` float NOT NULL default '0',\n                  PRIMARY KEY  (`id`),\n                  KEY `date` (`date`),\n                  KEY `users_id` (`users_id`),\n                  KEY `tickets_id` (`tickets_id`),\n                  KEY `is_private` (`is_private`),\n                  KEY `taskcategories_id` (`taskcategories_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("0.78 create glpi_tickettasks" . $LANG['update'][90] . $DB->error());
        // Required for migration from ticketfollowups to tickettasks - planned followups
        $query = "INSERT INTO `glpi_tickettasks`\n                    (`id`, `tickets_id`, `date`, `users_id`, `content`, `is_private`, `realtime`)\n                   SELECT `glpi_ticketfollowups`.`id`,\n                          `glpi_ticketfollowups`.`tickets_id`,\n                          `glpi_ticketfollowups`.`date`,\n                          `glpi_ticketfollowups`.`users_id`,\n                          `glpi_ticketfollowups`.`content`,\n                          `glpi_ticketfollowups`.`is_private`,\n                          `glpi_ticketfollowups`.`realtime`\n                   FROM `glpi_ticketfollowups`\n                   INNER JOIN `glpi_ticketplannings`\n                     ON (`glpi_ticketplannings`.`ticketfollowups_id` = `glpi_ticketfollowups`.`id`)";
        $DB->query($query) or die("0.78 populate glpi_tickettasks" . $LANG['update'][90] . $DB->error());
        // delete from ticketfollowups - planned followups, previously copied
        $query = "DELETE FROM `glpi_ticketfollowups`\n                WHERE `glpi_ticketfollowups`.`id` IN\n                  (SELECT `glpi_ticketplannings`.`ticketfollowups_id`\n                   FROM `glpi_ticketplannings`)";
        $DB->query($query) or die("0.78 delete from glpi_ticketfollowups" . $LANG['update'][90] . $DB->error());
        // Required for migration from ticketfollowups to tickettasks - followups with a duration
        $query = "INSERT INTO `glpi_tickettasks`\n                    (`id`, `tickets_id`, `date`, `users_id`, `content`, `is_private`, `realtime`)\n                   SELECT `glpi_ticketfollowups`.`id`,\n                          `glpi_ticketfollowups`.`tickets_id`,\n                          `glpi_ticketfollowups`.`date`,\n                          `glpi_ticketfollowups`.`users_id`,\n                          `glpi_ticketfollowups`.`content`,\n                          `glpi_ticketfollowups`.`is_private`,\n                          `glpi_ticketfollowups`.`realtime`\n                   FROM `glpi_ticketfollowups`\n                   WHERE `realtime`>0";
        $DB->query($query) or die("0.78 populate glpi_tickettasks" . $LANG['update'][90] . $DB->error());
        // delete from ticketfollowups - followups with duration, previously copied
        $query = "DELETE FROM `glpi_ticketfollowups`\n                WHERE `realtime`>0";
        $DB->query($query) or die("0.78 delete from glpi_ticketfollowups" . $LANG['update'][90] . $DB->error());
        // ticketplannings is for tickettasks
        $query = "ALTER TABLE `glpi_ticketplannings`\n                  CHANGE `ticketfollowups_id` `tickettasks_id` int(11) NOT NULL default '0'";
        $DB->query($query) or die("0.78 alter glpi_ticketplannings" . $LANG['update'][90] . $DB->error());
        // add requesttype for glpi_ticketfollowups
        $query = "ALTER TABLE `glpi_ticketfollowups`\n                  DROP `realtime`,\n                  ADD `requesttypes_id` int(11) NOT NULL default '0',\n                  ADD INDEX `requesttypes_id` (`requesttypes_id`)";
        $DB->query($query) or die("0.78 alter glpi_ticketplannings" . $LANG['update'][90] . $DB->error());
    }
    // Migrate devices
    if (TableExists('glpi_computer_device')) {
        displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $LANG['title'][30]);
        // Updating schema
        foreach ($devtypetoname as $key => $itemtype) {
            displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $LANG['title'][30] . ' - ' . $itemtype);
            // Updating schema
            $linktype = "Computer_{$itemtype}";
            $linktable = getTableForItemType($linktype);
            $itemtable = getTableForItemType($itemtype);
            $fkname = getForeignKeyFieldForTable($itemtable);
            $withspecifity = array(MOBOARD_DEVICE => false, PROCESSOR_DEVICE => 'int', RAM_DEVICE => 'int', HDD_DEVICE => 'int', NETWORK_DEVICE => 'varchar', DRIVE_DEVICE => false, CONTROL_DEVICE => false, GFX_DEVICE => 'int', SND_DEVICE => false, PCI_DEVICE => false, CASE_DEVICE => false, POWER_DEVICE => false);
            if (FieldExists($itemtable, 'specif_default')) {
                // Convert default specifity
                if ($withspecifity[$key]) {
                    // Convert data to int
                    if ($withspecifity[$key] == 'int') {
                        // clean non integer values
                        $query = "UPDATE `{$itemtable}` SET `specif_default` = 0\n                             WHERE `specif_default` NOT REGEXP '^[0-9]*\$' OR `specif_default` = '' OR `specif_default` IS NULL";
                        $DB->query($query) or die("0.78 update specif_default in {$itemtable} " . $LANG['update'][90] . $DB->error());
                        $query = "ALTER TABLE `{$itemtable}` CHANGE `specif_default` `specif_default` INT(11) NOT NULL";
                        $DB->query($query) or die("0.78 alter specif_default in {$itemtable} " . $LANG['update'][90] . $DB->error());
                    }
                } else {
                    // Drop default specificity
                    $query = "ALTER TABLE `{$itemtable}` DROP `specif_default`";
                    $DB->query($query) or die("0.78 drop specif_default in {$itemtable} " . $LANG['update'][90] . $DB->error());
                }
            }
            if (!TableExists($linktable)) {
                // create table
                $query = "CREATE TABLE `{$linktable}` (\n                        `id` int(11) NOT NULL auto_increment,\n                        `computers_id` int(11) NOT NULL default '0',\n                        `{$fkname}` int(11) NOT NULL default '0',";
                if ($withspecifity[$key]) {
                    if ($withspecifity[$key] == 'int') {
                        $query .= "`specificity` int(11) NOT NULL,";
                    } else {
                        $query .= "`specificity` varchar(255) collate utf8_unicode_ci default NULL,";
                    }
                }
                $query .= "PRIMARY KEY  (`id`),\n                     KEY `computers_id` (`computers_id`),\n                     KEY `{$fkname}` (`{$fkname}`)";
                if ($withspecifity[$key]) {
                    $query .= ",KEY `specificity` (`specificity`)";
                }
                $query .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
                $DB->query($query) or die("0.78 create {$linktable} " . $LANG['update'][90] . $DB->error());
                // Update data before copy
                if ($withspecifity[$key]) {
                    // Convert data to int
                    if ($withspecifity[$key] == 'int') {
                        // clean non integer values
                        $query = "UPDATE `glpi_computer_device` SET `specificity` = 0\n                        WHERE device_type={$key}\n                           AND `specificity` NOT REGEXP '^[0-9]*\$' OR `specificity` = ''";
                        $DB->query($query) or die("0.78 update specificity in glpi_computer_device for {$itemtype}" . $LANG['update'][90] . $DB->error());
                    }
                }
                // copy datas to new table : keep id for ocs sync
                $query = "INSERT INTO `{$linktable}` (`id`,`computers_id`,`{$fkname}`\n                     " . ($withspecifity[$key] ? ",`specificity`" : '') . ")\n                        SELECT ID, FK_computers,FK_device" . ($withspecifity[$key] ? ",specificity" : '') . "\n                        FROM glpi_computer_device\n                        WHERE device_type={$key}";
                $DB->query($query) or die("0.78 populate {$linktable} " . $LANG['update'][90] . $DB->error());
            }
        }
        // Drop computer_device_table
        $query = "DROP TABLE `glpi_computer_device`";
        $DB->query($query) or die("0.78 drop glpi_computer_device " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_users', 'task_private')) {
        $query = "ALTER TABLE `glpi_users`\n                ADD `task_private` TINYINT(1) DEFAULT NULL AFTER `followup_private`";
        $DB->query($query) or die("0.78 add task_private to glpi_users" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_configs', 'task_private')) {
        $query = "ALTER TABLE `glpi_configs`\n                ADD `task_private` TINYINT(1) NOT NULL DEFAULT '0' AFTER `followup_private`";
        $DB->query($query) or die("0.78 add task_private to glpi_users" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_rules', 'date_mod')) {
        $query = "ALTER TABLE `glpi_rules`\n                ADD `date_mod` DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod to glpi_rules" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_authldaps', 'entity_field')) {
        $query = "ALTER TABLE `glpi_authldaps` ADD `entity_field` VARCHAR( 255 ) DEFAULT NULL";
        $DB->query($query) or die("0.78 add entity_field to glpi_authldaps" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_authldaps', 'entity_condition')) {
        $query = "ALTER TABLE `glpi_authldaps` ADD `entity_condition`  TEXT NULL collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add entity_condition to glpi_authldaps" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_entitydatas', 'ldapservers_id')) {
        $query = "ALTER TABLE `glpi_entitydatas` ADD `ldapservers_id` INT( 11 ) NOT NULL DEFAULT '0'";
        $DB->query($query) or die("0.78 add ldapservers_id to glpi_entitydatas" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_entitydatas', 'mail_domain')) {
        $query = "ALTER TABLE `glpi_entitydatas` ADD `mail_domain` VARCHAR( 255 ) DEFAULT NULL";
        $DB->query($query) or die("0.78 add mail_domain to glpi_entitydatas" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_entitydatas', 'entity_ldapfilter')) {
        $query = "ALTER TABLE `glpi_entitydatas` ADD `entity_ldapfilter`  TEXT NULL collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add entity_ldapfilter to glpi_entitydatas" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_profiles', 'import_externalauth_users')) {
        $query = "ALTER TABLE `glpi_profiles` ADD `import_externalauth_users` CHAR( 1 ) NULL";
        $DB->query($query) or die("0.78 add import_externalauth_users in glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `import_externalauth_users`='w' WHERE `user` ='w'";
        $DB->query($query) or die("0.78 add import_externalauth_users right users which are able to write users " . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $LANG['setup'][704]);
    // Updating schema
    $templates = array();
    if (!TableExists('glpi_notificationtemplates')) {
        $query = "CREATE TABLE `glpi_notificationtemplates` (\n                 `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,\n                 `name` VARCHAR( 255 ) default NULL ,\n                 `itemtype` VARCHAR( 100 ) NOT NULL,\n                 `date_mod` DATETIME DEFAULT NULL ,\n                 `comment` text collate utf8_unicode_ci,\n                 PRIMARY KEY ( `ID` ),\n                 KEY `itemtype` (`itemtype`),\n                 KEY `date_mod` (`date_mod`),\n                 KEY `name` (`name`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("0.78 create glpi_notificationtemplates" . $LANG['update'][90] . $DB->error());
        $queries['DBConnection'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'MySQL Synchronization', 'DBConnection', NOW(),'');";
        $queries['Reservation'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Reservations', 'Reservation', NOW(),'');";
        $queries['Reservation2'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Alert Reservation', 'Reservation', NOW(),'');";
        $queries['Ticket'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Tickets', 'Ticket', NOW(),'');";
        $queries['Ticket2'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Tickets (Simple)', 'Ticket', NOW(),'');";
        $queries['Ticket3'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Alert Tickets not closed', 'Ticket', NOW(),'');";
        $queries['TicketValidation'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Tickets Validation', 'Ticket', NOW(),'');";
        $queries['Cartridge'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Cartridges', 'Cartridge', NOW(),'');";
        $queries['Consumable'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Consumables', 'Consumable', NOW(),'');";
        $queries['Infocom'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Infocoms', 'Infocom', NOW(),'');";
        $queries['SoftwareLicense'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Licenses', 'SoftwareLicense', NOW(),'');";
        $queries['Contract'] = "INSERT INTO `glpi_notificationtemplates`\n               VALUES(NULL, 'Contracts', 'Contract', NOW(),'');";
        foreach ($queries as $itemtype => $query) {
            $DB->query($query) or die("0.78 insert notification template for {$itemtype} " . $LANG['update'][90] . $DB->error());
            $templates[$itemtype] = $DB->insert_id();
        }
        $ADDTODISPLAYPREF['NotificationTemplate'] = array(4, 16);
        //There was a problem with GLPI < 0.78 : smtp_port field wans'nt used : migrate it
        $query = "SELECT `smtp_host` FROM `glpi_configs` WHERE `id`='1'";
        $result = $DB->query($query);
        $host = $DB->result($result, 0, 'smtp_host');
        $results = array();
        preg_match("/(.*):([0-9]*)/", $host, $results);
        if (!empty($results)) {
            $query = "UPDATE `glpi_configs` SET `smtp_host`='" . $results[1] . "' ,\n                                             `smtp_port`='" . $results[2] . "' WHERE `id`='1'";
            $DB->query($query);
        }
    }
    if (!TableExists('glpi_notificationtemplatetranslations')) {
        $query = "CREATE TABLE `glpi_notificationtemplatetranslations` (\n            `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,\n            `notificationtemplates_id` INT( 11 ) NOT NULL DEFAULT '0',\n            `language` CHAR ( 5 ) NOT NULL DEFAULT '',\n            `subject` VARCHAR( 255 ) NOT NULL ,\n            `content_text` TEXT NULL ,\n            `content_html` TEXT NULL ,\n            PRIMARY KEY ( `id` ),\n            KEY `notificationtemplates_id` (`notificationtemplates_id`)\n            )ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("0.78 create glpi_notificationtemplatetranslations" . $LANG['update'][90] . $DB->error());
        $queries = array();
        $queries['DBConnection'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $templates['DBConnection'] . ", '','##lang.dbconnection.title##',\n                        '##lang.dbconnection.delay## : ##dbconnection.delay##\r\n',\n                        '&lt;p&gt;##lang.dbconnection.delay## : ##dbconnection.delay##&lt;/p&gt;');";
        $content_text_reservation = "======================================================================\r\n" . "##lang.reservation.user##: ##reservation.user##\r\n" . "##lang.reservation.item.name##: ##reservation.itemtype## - ##reservation.item.name##\r\n" . "##IFreservation.tech## ##lang.reservation.tech## ##reservation.tech## ##ENDIFreservation.tech##\r\n" . "##lang.reservation.begin##: ##reservation.begin##\r\n" . "##lang.reservation.end##: ##reservation.end##\r\n" . "##lang.reservation.comment##: ##reservation.comment##\r\n" . "======================================================================\r\n";
        $content_html_reservation = "&lt;!-- description{ color: inherit; background: #ebebeb;" . "border-style: solid;border-color: #8d8d8d; border-width: 0px 1px 1px 0px; }" . " --&gt;\r\n&lt;p&gt;&lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;" . "##lang.reservation.user##:&lt;/span&gt;##reservation.user##" . "&lt;br /&gt; &lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;" . "##lang.reservation.item.name##:&lt;/span&gt;" . "##reservation.itemtype## - ##reservation.item.name##&lt;br /&gt;" . "##IFreservation.tech## ##lang.reservation.tech## ##reservation.tech##" . "##ENDIFreservation.tech##&lt;br /&gt; &lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;" . "##lang.reservation.begin##:&lt;/span&gt; ##reservation.begin##" . "&lt;br /&gt; &lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;" . "##lang.reservation.end##:&lt;/span&gt;" . "##reservation.end##&lt;br /&gt; &lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;" . "##lang.reservation.comment##:&lt;/span&gt; ##reservation.comment##" . "&lt;/p&gt;";
        $queries['Reservation'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                        VALUES(NULL,\n                                                 " . $templates['Reservation'] . ",\n                                                    '',\n                                                    '##reservation.action##',\n                                                   '{$content_text_reservation}',\n                                                   '{$content_html_reservation}');";
        $queries['Reservation2'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                    VALUES(NULL, " . $templates['Reservation2'] . ", '',\n                                    '##reservation.action##  ##reservation.entity##',\n                                    '##lang.reservation.entity## : ##reservation.entity## \r\n\n \r\n##FOREACHreservations## \r\n##lang.reservation.itemtype## : ##reservation.itemtype##\r\n\n ##lang.reservation.item## : ##reservation.item##\r\n \r\n ##reservation.url## \r\n\n ##ENDFOREACHreservations##',\n '&lt;p&gt;##lang.reservation.entity## : ##reservation.entity## &lt;br /&gt; &lt;br /&gt;\n##FOREACHreservations## &lt;br /&gt;##lang.reservation.itemtype## : ##reservation.itemtype##&lt;br /&gt;\n ##lang.reservation.item## : ##reservation.item##&lt;br /&gt; &lt;br /&gt;\n &lt;a href=\"##reservation.url##\"&gt; ##reservation.url##&lt;/a&gt;&lt;br /&gt;\n ##ENDFOREACHreservations##&lt;/p&gt;');";
        $queries['Ticket'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                            VALUES(NULL, '" . $templates['Ticket'] . "', '',\n                            '##ticket.action## ##ticket.title##',\n' ##IFticket.storestatus=solved##\n ##lang.ticket.url## : ##ticket.urlapprove##\n ##lang.ticket.autoclosewarning##\n ##lang.ticket.solvedate## : ##ticket.solvedate##\n ##lang.ticket.solution.type## : ##ticket.solution.type##\n ##lang.ticket.solution.description## : ##ticket.solution.description## ##ENDIFticket.storestatus##\n ##ELSEticket.storestatus## ##lang.ticket.url## : ##ticket.url## ##ENDELSEticket.storestatus##\n\n ##lang.ticket.description##\n\n ##lang.ticket.title## : ##ticket.title##\n ##lang.ticket.author.name## : ##IFticket.author.name## ##ticket.author.name## ##ENDIFticket.author.name## ##ELSEticket.author.name##--##ENDELSEticket.author.name##\n ##lang.ticket.creationdate## : ##ticket.creationdate##\n ##lang.ticket.closedate## : ##ticket.closedate##\n ##lang.ticket.requesttype## : ##ticket.requesttype##\n ##IFticket.itemtype## ##lang.ticket.item.name## : ##ticket.itemtype## - ##ticket.item.name## ##IFticket.item.model## - ##ticket.item.model## ##ENDIFticket.item.model## ##IFticket.item.serial## - ##ticket.item.serial## ##ENDIFticket.item.serial##  ##IFticket.item.otherserial## -##ticket.item.otherserial## ##ENDIFticket.item.otherserial## ##ENDIFticket.itemtype##\n##IFticket.assigntouser## ##lang.ticket.assigntouser## : ##ticket.assigntouser## ##ENDIFticket.assigntouser##\n ##lang.ticket.status## : ##ticket.status##\n##IFticket.assigntogroup## ##lang.ticket.assigntogroup## : ##ticket.assigntogroup## ##ENDIFticket.assigntogroup##\n ##lang.ticket.urgency## : ##ticket.urgency##\n ##lang.ticket.impact## : ##ticket.impact##\n ##lang.ticket.priority## : ##ticket.priority##\n##IFticket.user.email## ##lang.ticket.user.email## : ##ticket.user.email ##ENDIFticket.user.email##\n##IFticket.category## ##lang.ticket.category## : ##ticket.category## ##ENDIFticket.category## ##ELSEticket.category## ##lang.ticket.nocategoryassigned## ##ENDELSEticket.category##\n ##lang.ticket.content## : ##ticket.content##\n\n ##IFticket.storestatus=closed##\n\n ##lang.ticket.solvedate## : ##ticket.solvedate##\n ##lang.ticket.solution.type## : ##ticket.solution.type##\n ##lang.ticket.solution.description## : ##ticket.solution.description##\n ##ENDIFticket.storestatus##\n ##lang.ticket.numberoffollowups## : ##ticket.numberoffollowups##\n\n##FOREACHfollowups##\n\n [##followup.date##] ##lang.followup.isprivate## : ##followup.isprivate##\n ##lang.followup.author## ##followup.author##\n ##lang.followup.description## ##followup.description##\n ##lang.followup.date## ##followup.date##\n ##lang.followup.requesttype## ##followup.requesttype##\n\n##ENDFOREACHfollowups##\n ##lang.ticket.numberoftasks## : ##ticket.numberoftasks##\n\n##FOREACHtasks##\n\n [##task.date##] ##lang.task.isprivate## : ##task.isprivate##\n ##lang.task.author## ##task.author##\n ##lang.task.description## ##task.description##\n ##lang.task.time## ##task.time##\n ##lang.task.category## ##task.category##\n\n##ENDFOREACHtasks##',\n'<!-- description{ color: inherit; background: #ebebeb; border-style: solid;border-color: #8d8d8d; border-width: 0px 1px 1px 0px; }    -->\n<div>##IFticket.storestatus=solved##</div>\n<div>##lang.ticket.url## : <a href=\"##ticket.urlapprove##\">##ticket.urlapprove##</a> <strong>&#160;</strong></div>\n<div><strong>##lang.ticket.autoclosewarning##</strong> </div>\n<div><span style=\"color: #888888;\"><strong><span style=\"text-decoration: underline;\">##lang.ticket.solvedate##</span></strong></span> : ##ticket.solvedate##<br /><span style=\"text-decoration: underline; color: #888888;\"><strong>##lang.ticket.solution.type##</strong></span> : ##ticket.solution.type##<br /><span style=\"text-decoration: underline; color: #888888;\"><strong>##lang.ticket.solution.description##</strong></span> : ##ticket.solution.description## ##ENDIFticket.storestatus##</div>\n<div>##ELSEticket.storestatus## ##lang.ticket.url## : <a href=\"##ticket.url##\">##ticket.url##</a> ##ENDELSEticket.storestatus##</div>\n<div class=\"description b\"><strong>##lang.ticket.description##</strong></div>\n<p><span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.title##</span>&#160;:##ticket.title## <br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.author.name##</span>&#160;:##IFticket.author.name## ##ticket.author.name## ##ENDIFticket.author.name##    ##ELSEticket.author.name##--##ENDELSEticket.author.name## <br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.creationdate##</span>&#160;:##ticket.creationdate## <br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.closedate##</span>&#160;:##ticket.closedate## <br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.requesttype##</span>&#160;:##ticket.requesttype##<br /> ##IFticket.itemtype## <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.item.name##</span>&#160;: ##ticket.itemtype## - ##ticket.item.name##    ##IFticket.item.model## - ##ticket.item.model##    ##ENDIFticket.item.model## ##IFticket.item.serial## -##ticket.item.serial## ##ENDIFticket.item.serial##&#160; ##IFticket.item.otherserial## -##ticket.item.otherserial##  ##ENDIFticket.item.otherserial## ##ENDIFticket.itemtype## <br /> ##IFticket.assigntouser## <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.assigntouser##</span>&#160;: ##ticket.assigntouser## ##ENDIFticket.assigntouser##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\">##lang.ticket.status## </span>&#160;: ##ticket.status##<br /> ##IFticket.assigntogroup## <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.assigntogroup##</span>&#160;: ##ticket.assigntogroup## ##ENDIFticket.assigntogroup##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.urgency##</span>&#160;: ##ticket.urgency##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.impact##</span>&#160;: ##ticket.impact##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.priority##</span>&#160;: ##ticket.priority## <br /> ##IFticket.user.email##<span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.user.email##</span>&#160;: ##ticket.user.email ##ENDIFticket.user.email##    <br /> ##IFticket.category##<span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\">##lang.ticket.category## </span>&#160;:##ticket.category## ##ENDIFticket.category## ##ELSEticket.category## ##lang.ticket.nocategoryassigned## ##ENDELSEticket.category##    <br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.ticket.content##</span>&#160;: ##ticket.content##</p>\n<br />##IFticket.storestatus=closed##<br /><span style=\"text-decoration: underline;\"><strong><span style=\"color: #888888;\">##lang.ticket.solvedate##</span></strong></span> : ##ticket.solvedate##<br /><span style=\"color: #888888;\"><strong><span style=\"text-decoration: underline;\">##lang.ticket.solution.type##</span></strong></span> : ##ticket.solution.type##<br /><span style=\"text-decoration: underline; color: #888888;\"><strong>##lang.ticket.solution.description##</strong></span> : ##ticket.solution.description##<br />##ENDIFticket.storestatus##</p>\n<div class=\"description b\">##lang.ticket.numberoffollowups##&#160;: ##ticket.numberoffollowups##</div>\n<p>##FOREACHfollowups##</p>\n<div class=\"description b\"><br /> <strong> [##followup.date##] <em>##lang.followup.isprivate## : ##followup.isprivate## </em></strong><br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.followup.author## </span> ##followup.author##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.followup.description## </span> ##followup.description##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.followup.date## </span> ##followup.date##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.followup.requesttype## </span> ##followup.requesttype##</div>\n<p>##ENDFOREACHfollowups##</p>\n<div class=\"description b\">##lang.ticket.numberoftasks##&#160;: ##ticket.numberoftasks##</div>\n<p>##FOREACHtasks##</p>\n<div class=\"description b\"><br /> <strong> [##task.date##] <em>##lang.task.isprivate## : ##task.isprivate## </em></strong><br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.task.author##</span> ##task.author##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.task.description##</span> ##task.description##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.task.time##</span> ##task.time##<br /> <span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"> ##lang.task.category##</span> ##task.category##</div>\n<p>##ENDFOREACHtasks##</p>');";
        $queries['Contract'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                              VALUES(NULL, " . $templates['Contract'] . ", '',\n                              '##contract.action##  ##contract.entity##',\n                              '##lang.contract.entity## : ##contract.entity##\r\n" . "\r\n##FOREACHcontracts##\r\n" . "##lang.contract.name## : ##contract.name##\r\n" . "##lang.contract.number## : ##contract.number##\r\n" . "##lang.contract.time## : ##contract.time##\r\n" . "##IFcontract.type####lang.contract.type## : ##contract.type##" . "##ENDIFcontract.type##\r\n" . "##contract.url##\r\n" . "##ENDFOREACHcontracts##',\n'&lt;p&gt;##lang.contract.entity## : ##contract.entity##&lt;br /&gt;\n&lt;br /&gt;##FOREACHcontracts##&lt;br /&gt;##lang.contract.name## :\n##contract.name##&lt;br /&gt;\n##lang.contract.number## : ##contract.number##&lt;br /&gt;\n##lang.contract.time## : ##contract.time##&lt;br /&gt;\n##IFcontract.type####lang.contract.type## : ##contract.type##\n##ENDIFcontract.type##&lt;br /&gt;\n&lt;a href=\"##contract.url##\"&gt;\n##contract.url##&lt;/a&gt;&lt;br /&gt;\n##ENDFOREACHcontracts##&lt;/p&gt;');";
        $queries['Ticket2'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                             VALUES(NULL, " . $templates['Ticket2'] . ", '',\n                            '##ticket.action## ##ticket.title##',\n'##lang.ticket.url## : ##ticket.url## \r\n\n##lang.ticket.description## \r\n\n\n##lang.ticket.title## &#160;:##ticket.title## \n\n##lang.ticket.author.name## &#160;:##IFticket.author.name##\n##ticket.author.name## ##ENDIFticket.author.name##\n##ELSEticket.author.name##--##ENDELSEticket.author.name## &#160; \n\n##IFticket.category## ##lang.ticket.category## &#160;:##ticket.category##\n##ENDIFticket.category## ##ELSEticket.category##\n##lang.ticket.nocategoryassigned## ##ENDELSEticket.category##\n\n##lang.ticket.content## &#160;: ##ticket.content##\n##IFticket.itemtype##\n##lang.ticket.item.name## &#160;: ##ticket.itemtype## - ##ticket.item.name##\n##ENDIFticket.itemtype##',\n'&lt;div&gt;##lang.ticket.url## : &lt;a href=\"##ticket.url##\"&gt;\n##ticket.url##&lt;/a&gt;&lt;/div&gt;\r\n&lt;div class=\"description b\"&gt;\n##lang.ticket.description##&lt;/div&gt;\r\n&lt;p&gt;&lt;span\nstyle=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;\n##lang.ticket.title##&lt;/span&gt;&#160;:##ticket.title##\n&lt;br /&gt; &lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;\n##lang.ticket.author.name##&lt;/span&gt;\n##IFticket.author.name## ##ticket.author.name##\n##ENDIFticket.author.name##\n##ELSEticket.author.name##--##ENDELSEticket.author.name##\n&lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;&#160\n;&lt;/span&gt;&lt;br /&gt; &lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt; &lt;/span&gt;\n##IFticket.category##&lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;\n##lang.ticket.category## &lt;/span&gt;&#160;:##ticket.category##\n##ENDIFticket.category## ##ELSEticket.category##\n##lang.ticket.nocategoryassigned## ##ENDELSEticket.category##\n&lt;br /&gt; &lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;\n##lang.ticket.content##&lt;/span&gt;&#160;:\n##ticket.content##&lt;br /&gt;##IFticket.itemtype##\n&lt;span style=\"color: #8b8c8f; font-weight: bold; text-decoration: underline;\"&gt;\n##lang.ticket.item.name##&lt;/span&gt;&#160;:\n##ticket.itemtype## - ##ticket.item.name##\n##ENDIFticket.itemtype##&lt;/p&gt;');";
        $queries['TicketValidation'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                             VALUES(NULL, " . $templates['TicketValidation'] . ", '',\n                            '##ticket.action## ##ticket.title##',\n'##FOREACHvalidations##\n\n##IFvalidation.storestatus=waiting##\n##validation.submission.title##\n##lang.validation.commentsubmission## : ##validation.commentsubmission##\n##ENDIFvalidation.storestatus##\n##ELSEvalidation.storestatus## ##validation.answer.title## ##ENDELSEvalidation.storestatus##\n\n##lang.ticket.url## : ##ticket.urlvalidation##\n\n##IFvalidation.status## ##lang.validation.validationstatus## ##ENDIFvalidation.status##\n##IFvalidation.commentvalidation##\n##lang.validation.commentvalidation## : ##validation.commentvalidation##\n##ENDIFvalidation.commentvalidation##\n##ENDFOREACHvalidations##',\n'&lt;div&gt;##FOREACHvalidations##&lt;/div&gt;\n&lt;p&gt;##IFvalidation.storestatus=waiting##&lt;/p&gt;\n&lt;div&gt;##validation.submission.title##&lt;/div&gt;\n&lt;div&gt;##lang.validation.commentsubmission## : ##validation.commentsubmission##&lt;/div&gt;\n&lt;div&gt;##ENDIFvalidation.storestatus##&lt;/div&gt;\n&lt;div&gt;##ELSEvalidation.storestatus## ##validation.answer.title## ##ENDELSEvalidation.storestatus##&lt;/div&gt;\n&lt;div&gt;&lt;/div&gt;\n&lt;div&gt;\n&lt;div&gt;##lang.ticket.url## : &lt;a href=\"##ticket.urlvalidation##\"&gt; ##ticket.urlvalidation## &lt;/a&gt;&lt;/div&gt;\n&lt;/div&gt;\n&lt;p&gt;##IFvalidation.status## ##lang.validation.validationstatus## ##ENDIFvalidation.status##\n&lt;br /&gt; ##IFvalidation.commentvalidation##&lt;br /&gt; ##lang.validation.commentvalidation## :\n&#160; ##validation.commentvalidation##&lt;br /&gt; ##ENDIFvalidation.commentvalidation##\n&lt;br /&gt;##ENDFOREACHvalidations##&lt;/p&gt;');";
        $queries['Ticket3'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                             VALUES(NULL, " . $templates['Ticket3'] . ", '',\n                             '##ticket.action## ##ticket.entity##',\n'##lang.ticket.entity## : ##ticket.entity##\n \n##FOREACHtickets##\n\n##lang.ticket.title## : ##ticket.title##\n ##lang.ticket.status## : ##ticket.status##\n\n ##ticket.url## \n ##ENDFOREACHtickets##',\n'&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##lang.ticket.author.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##lang.ticket.title##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##lang.ticket.priority##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##lang.ticket.status##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##lang.ticket.attribution##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##lang.ticket.creationdate##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##lang.ticket.content##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##FOREACHtickets##\n&lt;tr&gt;\n&lt;td width=\"auto\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##ticket.author.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td width=\"auto\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;&lt;a href=\"##ticket.url##\"&gt;##ticket.title##&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;td width=\"auto\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##ticket.priority##&lt;/span&gt;&lt;/td&gt;\n&lt;td width=\"auto\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##ticket.status##&lt;/span&gt;&lt;/td&gt;\n&lt;td width=\"auto\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##IFticket.assigntouser####ticket.assigntouser##&lt;br /&gt;##ENDIFticket.assigntouser####IFticket.assigntogroup##&lt;br /&gt;##ticket.assigntogroup## ##ENDIFticket.assigntogroup####IFticket.assigntosupplier##&lt;br /&gt;##ticket.assigntosupplier## ##ENDIFticket.assigntosupplier##&lt;/span&gt;&lt;/td&gt;\n&lt;td width=\"auto\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##ticket.creationdate##&lt;/span&gt;&lt;/td&gt;\n&lt;td width=\"auto\"&gt;&lt;span style=\"font-size: 11px; text-align: left;\"&gt;##ticket.content##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDFOREACHtickets##\n&lt;/tbody&gt;\n&lt;/table&gt;');";
        $queries['Consumable'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                           VALUES(NULL, " . $templates['Consumable'] . ", '',\n                           '##consumable.action##  ##consumable.entity##',\n'##lang.consumable.entity## : ##consumable.entity##\n \n\n##FOREACHconsumables##\n##lang.consumable.item## : ##consumable.item##\n \n\n##lang.consumable.reference## : ##consumable.reference##\n\n##lang.consumable.remaining## : ##consumable.remaining##\n\n##consumable.url## \n\n##ENDFOREACHconsumables##', '&lt;p&gt;\n##lang.consumable.entity## : ##consumable.entity##\n&lt;br /&gt; &lt;br /&gt;##FOREACHconsumables##\n&lt;br /&gt;##lang.consumable.item## : ##consumable.item##&lt;br /&gt;\n&lt;br /&gt;##lang.consumable.reference## : ##consumable.reference##&lt;br /&gt;\n##lang.consumable.remaining## : ##consumable.remaining##&lt;br /&gt;\n&lt;a href=\"##consumable.url##\"&gt; ##consumable.url##&lt;/a&gt;&lt;br /&gt;\n   ##ENDFOREACHconsumables##&lt;/p&gt;');";
        $queries['Cartridge'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                               VALUES(NULL, " . $templates['Cartridge'] . ", '',\n                               '##cartridge.action##  ##cartridge.entity##',\n'##lang.cartridge.entity## : ##cartridge.entity##\n \n\n##FOREACHcartridges##\n##lang.cartridge.item## : ##cartridge.item##\n \n\n##lang.cartridge.reference## : ##cartridge.reference##\n\n##lang.cartridge.remaining## : ##cartridge.remaining##\n\n##cartridge.url## \n ##ENDFOREACHcartridges##',\n'&lt;p&gt;##lang.cartridge.entity## :##cartridge.entity##\n&lt;br /&gt; &lt;br /&gt;##FOREACHcartridges##\n&lt;br /&gt;##lang.cartridge.item## :\n##cartridge.item##&lt;br /&gt; &lt;br /&gt;\n##lang.cartridge.reference## :\n##cartridge.reference##&lt;br /&gt;\n##lang.cartridge.remaining## :\n##cartridge.remaining##&lt;br /&gt;\n&lt;a href=\"##cartridge.url##\"&gt;\n##cartridge.url##&lt;/a&gt;&lt;br /&gt;\n##ENDFOREACHcartridges##&lt;/p&gt;');";
        $queries['Infocom'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                              VALUES(NULL, " . $templates['Infocom'] . ", '',\n                             '##infocom.action##  ##infocom.entity##',\n'##lang.infocom.entity## : ##infocom.entity## \n \n\n##FOREACHinfocoms## \n\n##lang.infocom.itemtype## : ##infocom.itemtype##\n\n##lang.infocom.item## : ##infocom.item##\n \n\n##lang.infocom.expirationdate## : ##infocom.expirationdate##\n\n##infocom.url## \n ##ENDFOREACHinfocoms##',\n'&lt;p&gt;##lang.infocom.entity## : ##infocom.entity##\n&lt;br /&gt; &lt;br /&gt;##FOREACHinfocoms##\n&lt;br /&gt;##lang.infocom.itemtype## : ##infocom.itemtype##&lt;br /&gt;\n##lang.infocom.item## : ##infocom.item##&lt;br /&gt; &lt;br /&gt;\n##lang.infocom.expirationdate## : ##infocom.expirationdate##\n&lt;br /&gt; &lt;a href=\"##infocom.url##\"&gt;\n##infocom.url##&lt;/a&gt;&lt;br /&gt;\n##ENDFOREACHinfocoms##&lt;/p&gt;');";
        $queries['SoftwareLicense'] = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                     VALUES(NULL, " . $templates['SoftwareLicense'] . ", '',\n                                    '##license.action##  ##license.entity##',\n'##lang.license.entity## : ##license.entity##\r\n\n##FOREACHlicenses## \r\n\n##lang.license.item## : ##license.item##\r\n\n##lang.license.serial## : ##license.serial##\r\n\n##lang.license.expirationdate## : ##license.expirationdate##\r\n\n##license.url## \r\n ##ENDFOREACHlicenses##', '&lt;p&gt;\n##lang.license.entity## : ##license.entity##&lt;br /&gt;\n##FOREACHlicenses##\n&lt;br /&gt;##lang.license.item## : ##license.item##&lt;br /&gt;\n##lang.license.serial## : ##license.serial##&lt;br /&gt;\n##lang.license.expirationdate## : ##license.expirationdate##\n&lt;br /&gt; &lt;a href=\"##license.url##\"&gt; ##license.url##\n&lt;/a&gt;&lt;br /&gt; ##ENDFOREACHlicenses##&lt;/p&gt;');";
        foreach ($queries as $itemtype => $query) {
            $DB->query($query) or die("0.78 insert notification template default translation\n                                             for {$itemtype} " . $LANG['update'][90] . $DB->error());
        }
        unset($queries);
    }
    $notifications = array();
    if (!TableExists('glpi_notifications')) {
        $query = "CREATE TABLE `glpi_notifications` (\n                 `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,\n                 `name` VARCHAR( 255 ) DEFAULT NULL ,\n                 `entities_id` INT( 11 ) NOT NULL DEFAULT '0',\n                 `itemtype` VARCHAR( 100 ) NOT NULL ,\n                 `event` VARCHAR( 255 ) NOT NULL ,\n                 `mode` VARCHAR( 255 ) NOT NULL ,\n                 `notificationtemplates_id` INT( 11 ) NOT NULL DEFAULT '0',\n                 `comment` TEXT DEFAULT NULL ,\n                 `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0',\n                 `is_active` TINYINT( 1 ) NOT NULL DEFAULT '0',\n                 `date_mod` DATETIME DEFAULT NULL ,\n                  PRIMARY KEY ( `id` ),\n                  KEY `name` (`name`),\n                  KEY `itemtype` (`itemtype`),\n                  KEY `entities_id` (`entities_id`),\n                  KEY `is_active` (`is_active`),\n                  KEY `date_mod` (`date_mod`),\n                  KEY `is_recursive` (`is_recursive`),\n                  KEY `notificationtemplates_id` (`notificationtemplates_id`)\n                  ) ENGINE = MYISAM CHARSET utf8 COLLATE utf8_unicode_ci;";
        $DB->query($query) or die("0.78 create glpi_notifications" . $LANG['update'][90] . $DB->error());
        $queries = array();
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Alert Tickets not closed', 0, 'Ticket', 'alertnotclosed',\n                                       'mail'," . $templates['Ticket3'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'New Ticket', 0, 'Ticket', 'new',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Update Ticket', 0, 'Ticket', 'update',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Close Ticket', 0, 'Ticket', 'closed',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Add Followup', 0, 'Ticket', 'add_followup',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Add Task', 0, 'Ticket', 'add_task',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Update Followup', 0, 'Ticket', 'update_followup',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Update Task', 0, 'Ticket', 'update_task',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Delete Followup', 0, 'Ticket', 'delete_followup',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Delete Task', 0, 'Ticket', 'delete_task',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Resolve ticket', 0, 'Ticket', 'solved',\n                                       'mail'," . $templates['Ticket'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Ticket Validation', 0, 'Ticket', 'validation',\n                                       'mail'," . $templates['TicketValidation'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'New Reservation', 0, 'Reservation', 'new',\n                                       'mail'," . $templates['Reservation'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Update Reservation', 0, 'Reservation', 'update',\n                                       'mail'," . $templates['Reservation'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Delete Reservation', 0, 'Reservation', 'delete',\n                                       'mail'," . $templates['Reservation'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Alert Reservation', 0, 'Reservation', 'alert',\n                                       'mail'," . $templates['Reservation2'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Contract Notice', 0, 'Contract', 'notice',\n                                       'mail'," . $templates['Contract'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Contract End', 0, 'Contract', 'end',\n                                       'mail'," . $templates['Contract'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'MySQL Synchronization', 0, 'DBConnection', 'desynchronization',\n                                       'mail'," . $templates['DBConnection'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Cartridges', 0, 'Cartridge', 'alert',\n                                       'mail'," . $templates['Cartridge'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Consumables', 0, 'Consumable', 'alert',\n                                       'mail'," . $templates['Consumable'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Infocoms', 0, 'Infocom', 'alert',\n                                       'mail'," . $templates['Infocom'] . ",\n                                       '', 1, 1, NOW());";
        $queries[] = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Software Licenses', 0, 'SoftwareLicense', 'alert',\n                                       'mail'," . $templates['SoftwareLicense'] . ",\n                                       '', 1, 1, NOW());";
        foreach ($queries as $query) {
            $DB->query($query) or die("0.78 insert notification" . $LANG['update'][90] . $DB->error());
        }
        $ADDTODISPLAYPREF['Notification'] = array(5, 6, 2, 4, 80, 86);
        unset($queries);
    }
    if (!TableExists('glpi_notificationtargets') && TableExists('glpi_mailingsettings')) {
        $query = "RENAME TABLE `glpi_mailingsettings`  TO `glpi_notificationtargets`;";
        $DB->query($query) or die("0.78 rename table glpi_mailingsettings in glpi_notificationtargets" . $LANG['update'][90] . $DB->error());
        $query = "ALTER TABLE `glpi_notificationtargets` ADD `notifications_id` INT( 11 ) NOT NULL DEFAULT '0',\n                                             ADD INDEX `notifications_id` (`notifications_id`)";
        $DB->query($query) or die("0.78 add field notifications_id to glpi_notificationtargets" . $LANG['update'][90] . $DB->error());
        $query = "ALTER TABLE `glpi_notificationtargets` CHANGE `type` `oldtype` VARCHAR( 255 )\n                     CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL";
        $DB->query($query) or die("0.78 change field type in oldtype" . $LANG['update'][90] . $DB->error());
        $query = "ALTER TABLE `glpi_notificationtargets` CHANGE `mailingtype` `type`\n                     INT( 11 ) NOT NULL DEFAULT '0'";
        $DB->query($query) or die("0.78 change field mailingtype in type" . $LANG['update'][90] . $DB->error());
        $fields = array('new' => array('itemtype' => 'Ticket', 'newaction' => 'new'), 'update' => array('itemtype' => 'Ticket', 'newaction' => 'update'), 'finish' => array('itemtype' => 'Ticket', 'newaction' => 'closed'), 'resa' => array('itemtype' => 'Reservation', 'newaction' => 'new'), 'followup' => array('itemtype' => 'Ticket', 'newaction' => 'add_followup'), 'alertconsumable' => array('itemtype' => 'Consumable', 'newaction' => 'alert'), 'alertcartridge' => array('itemtype' => 'Cartridge', 'newaction' => 'alert'), 'alertlicense' => array('itemtype' => 'SoftwareLicense', 'newaction' => 'alert'), 'alertinfocom' => array('itemtype' => 'Infocom', 'newaction' => 'alert'), 'alertcontract' => array('itemtype' => 'Contract', 'newaction' => 'end'));
        $query = "SELECT `oldtype` FROM `glpi_notificationtargets` GROUP BY `oldtype`";
        foreach ($DB->request($query) as $data) {
            $infos = $fields[$data['oldtype']];
            $query_type = "SELECT `id`\n                        FROM `glpi_notifications`\n                        WHERE `itemtype`='" . $infos['itemtype'] . "' AND `event`='" . $infos['newaction'] . "'";
            $result = $DB->query($query_type) or die("0.78 get notificationtargets_id " . $LANG['update'][90] . $DB->error());
            if ($DB->numrows($result)) {
                $id = $DB->result($result, 0, 'id');
                $query_update = "UPDATE `glpi_notificationtargets`\n                             SET `notifications_id`='{$id}'\n                             WHERE `oldtype`='" . $data['oldtype'] . "'";
                $DB->query($query_update) or die("0.78 set notificationtargets_id " . $LANG['update'][90] . $DB->error());
            }
        }
        $query = "ALTER TABLE `glpi_notificationtargets` DROP INDEX `unicity` ";
        $DB->query($query) or die("0.78 drop index unicity from glpi_notificationtargets" . $LANG['update'][90] . $DB->error());
        $query = "ALTER TABLE `glpi_notificationtargets` DROP `oldtype`";
        $DB->query($query) or die("0.78 drop field oldtype in glpi_notificationtargets" . $LANG['update'][90] . $DB->error());
        //Add administrator as target for MySQL Synchronization notification
        $query_type = "SELECT `id` FROM `glpi_notifications` WHERE `itemtype`='DBConnection'";
        $result = $DB->query($query_type) or die("0.78 get notificationtargets_id " . $LANG['update'][90] . $DB->error());
        if ($DB->numrows($result)) {
            $id = $DB->result($result, 0, 'id');
            $query = "INSERT INTO `glpi_notificationtargets`\n                     (`id`, `notifications_id`, `type`, `items_id`)\n                     VALUES (NULL, " . $id . ", 1, 1);";
            $DB->query($query) or die("0.78 add target for dbsynchronization " . $LANG['update'][90] . $DB->error());
        }
        //Add validator as target for Ticket Validation
        $query_type = "SELECT `id` FROM `glpi_notifications` WHERE `itemtype`='Ticket' AND event='validation'";
        $result = $DB->query($query_type) or die("0.78 get notificationtargets_id " . $LANG['update'][90] . $DB->error());
        if ($DB->numrows($result)) {
            $id = $DB->result($result, 0, 'id');
            $query = "INSERT INTO `glpi_notificationtargets`\n                     (`id`, `notifications_id`, `type`, `items_id`)\n                     VALUES (NULL, " . $id . ", 1, 14);";
            $DB->query($query) or die("0.78 add target for Ticket Validation " . $LANG['update'][90] . $DB->error());
        }
        //Manage Reservation update & delete
        $query_type = "SELECT `id`\n                     FROM `glpi_notifications`\n                     WHERE `itemtype`='Reservation'\n                        AND `event` IN ('update', 'delete')";
        foreach ($DB->request($query_type) as $data_resa) {
            $query_targets = "SELECT `glpi_notificationtargets` . *\n                        FROM `glpi_notifications` , `glpi_notificationtargets`\n                        WHERE `glpi_notifications`.`itemtype` = 'Reservation'\n                           AND `glpi_notifications`.`event` = 'new'\n                              AND `glpi_notificationtargets`.notifications_id =\n                                    `glpi_notifications`.id";
            foreach ($DB->request($query_targets) as $data_targets) {
                $query_insert = "INSERT INTO `glpi_notificationtargets`\n                        (`id`, `notifications_id`, `type`, `items_id`)\n                        VALUES (NULL, " . $data_resa['id'] . ", " . $data_targets['type'] . ", " . $data_targets['items_id'] . ");";
                $DB->query($query_insert) or die("0.78 add target for reservations " . $LANG['update'][90] . $DB->error());
            }
        }
        //Manage contract notice
        $query_type = "SELECT `id`\n                     FROM `glpi_notifications`\n                     WHERE `itemtype`='Contract'\n                        AND `event`='notice'";
        foreach ($DB->request($query_type) as $data_contract) {
            $query_targets = "SELECT `glpi_notificationtargets` . *\n                        FROM `glpi_notifications` , `glpi_notificationtargets`\n                        WHERE `glpi_notifications`.`itemtype` = 'Contract'\n                           AND `glpi_notifications`.`event` = 'end'\n                              AND `glpi_notificationtargets`.notifications_id =\n                                    `glpi_notifications`.id";
            foreach ($DB->request($query_targets) as $data_targets) {
                $query_insert = "INSERT INTO `glpi_notificationtargets`\n                        (`id`, `notifications_id`, `type`, `items_id`)\n                        VALUES (NULL, " . $data_contract['id'] . ", " . $data_targets['type'] . ", " . $data_targets['items_id'] . ");";
                $DB->query($query_insert) or die("0.78 add target for contract " . $LANG['update'][90] . $DB->error());
            }
        }
        //Manage ticket tasks & followups
        $query_type = "SELECT `id`\n                     FROM `glpi_notifications`\n                     WHERE `itemtype`='Ticket'\n                        AND `event` IN ('add_task', 'update_task', 'update_followup',\n                                        'delete_task', 'delete_followup')";
        foreach ($DB->request($query_type) as $data_ticket) {
            $query_targets = "SELECT `glpi_notificationtargets` . *\n                        FROM `glpi_notifications` , `glpi_notificationtargets`\n                        WHERE `glpi_notifications`.`itemtype` = 'Ticket'\n                           AND `glpi_notifications`.`event` = 'add_followup'\n                              AND `glpi_notificationtargets`.notifications_id =\n                                    `glpi_notifications`.id";
            foreach ($DB->request($query_targets) as $data_targets) {
                $query_insert = "INSERT INTO `glpi_notificationtargets`\n                        (`id`, `notifications_id`, `type`, `items_id`)\n                        VALUES (NULL, " . $data_ticket['id'] . ", " . $data_targets['type'] . ", " . $data_targets['items_id'] . ");";
                $DB->query($query_insert) or die("0.78 add target for tickets " . $LANG['update'][90] . $DB->error());
            }
        }
        //Manage ticket solved
        $query_type = "SELECT `id`\n                     FROM `glpi_notifications`\n                     WHERE `itemtype`='Ticket'\n                        AND `event`='solved'";
        foreach ($DB->request($query_type) as $data_ticket) {
            $query_targets = "SELECT `glpi_notificationtargets` . *\n                        FROM `glpi_notifications` , `glpi_notificationtargets`\n                        WHERE `glpi_notifications`.`itemtype` = 'Ticket'\n                           AND `glpi_notifications`.`event` = 'closed'\n                              AND `glpi_notificationtargets`.notifications_id =\n                                    `glpi_notifications`.id";
            foreach ($DB->request($query_targets) as $data_targets) {
                $query_insert = "INSERT INTO `glpi_notificationtargets`\n                        (`id`, `notifications_id`, `type`, `items_id`)\n                        VALUES (NULL, " . $data_ticket['id'] . ", " . $data_targets['type'] . ", " . $data_targets['items_id'] . ");";
                $DB->query($query_insert) or die("0.78 add target for tickets action solved" . $LANG['update'][90] . $DB->error());
            }
        }
    }
    if (!FieldExists('glpi_profiles', 'notification')) {
        $query = "ALTER TABLE `glpi_profiles` ADD `notification` CHAR( 1 ) NULL";
        $DB->query($query) or die("0.78 add notification in glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `notification`='w' WHERE `config` ='w'";
        $DB->query($query) or die("0.78 add notification write right user which have config right " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_entitydatas', 'mailing_signature')) {
        $query = "ALTER TABLE `glpi_entitydatas` ADD `mailing_signature` TEXT DEFAULT NULL ,\n                                 ADD `cartridges_alert_repeat` INT( 11 ) NOT NULL DEFAULT '-1',\n                                 ADD `consumables_alert_repeat` INT( 11 ) NOT NULL DEFAULT '-1',\n                                 ADD `use_licenses_alert` TINYINT( 1 ) NOT NULL DEFAULT '-1',\n                                 ADD `use_contracts_alert` TINYINT( 1 ) NOT NULL DEFAULT '-1',\n                                 ADD `use_infocoms_alert` TINYINT( 1 ) NOT NULL DEFAULT '-1',\n                                 ADD `use_reservations_alert` INT( 11 ) NOT NULL DEFAULT '-1',\n                                 ADD `autoclose_delay` INT( 11 ) NOT NULL DEFAULT '-1',\n                                 ADD `notclosed_delay` INT( 11 ) NOT NULL DEFAULT '-1'";
        $DB->query($query) or die("0.78 add notifications fields in glpi_entitydatas" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_configs', 'use_reservations_alert')) {
        $query = "ALTER TABLE `glpi_configs` ADD `use_infocoms_alert` TINYINT( 1 ) NOT NULL DEFAULT '0',\n                                           ADD `use_contracts_alert` TINYINT( 1 ) NOT NULL DEFAULT '0',\n                                           ADD `use_reservations_alert` TINYINT( 1 ) NOT NULL DEFAULT '0',\n                                           ADD `autoclose_delay` INT( 11 ) NOT NULL DEFAULT '0',\n                                           ADD `notclosed_delay` INT( 11 ) NOT NULL DEFAULT '0'";
        $DB->query($query) or die("0.78 add notifications fields in glpi_configs" . $LANG['update'][90] . $DB->error());
    }
    if (TableExists('glpi_mailingsettings')) {
        $query = "DROP TABLE `glpi_mailingsettings`;";
        $DB->query($query) or die("0.78 drop table glpi_mailingsettings" . $LANG['update'][90] . $DB->error());
    }
    $tables = array('glpi_infocoms' => $LANG['financial'][3], 'glpi_reservationitems' => $LANG['Menu'][17], 'glpi_networkports' => $LANG['networking'][6]);
    foreach ($tables as $table => $label) {
        // Migrate infocoms entity information
        if (!FieldExists($table, 'entities_id')) {
            displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $label);
            // Updating schema
            $query = "ALTER TABLE `{$table}` ADD `entities_id` int(11) NOT NULL DEFAULT 0 AFTER `itemtype`,\n                           ADD `is_recursive` tinyint(1) NOT NULL DEFAULT 0 AFTER `entities_id`,\n                           ADD INDEX `entities_id` ( `entities_id` ),\n                           ADD INDEX `is_recursive` (`is_recursive`)";
            $DB->query($query) or die("0.78 add entities_id and is_recursive in {$table}" . $LANG['update'][90] . $DB->error());
            $entities = getAllDatasFromTable('glpi_entities');
            $entities[0] = "Root";
            $query = "SELECT DISTINCT `itemtype` FROM `{$table}`";
            if ($result = $DB->query($query)) {
                if ($DB->numrows($result) > 0) {
                    while ($data = $DB->fetch_assoc($result)) {
                        displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $label . ' - ' . $data['itemtype']);
                        // Updating schema
                        $itemtable = getTableForItemType($data['itemtype']);
                        // ajout d'un contrôle pour voir si la table existe ( cas migration plugin non fait)
                        if (!TableExists($itemtable)) {
                            if ($output) {
                                echo "<p class='red'>*** Skip : no table {$itemtable} ***</p>";
                            }
                            continue;
                        }
                        $do_recursive = false;
                        if (FieldExists($itemtable, 'is_recursive')) {
                            $do_recursive = true;
                        }
                        // This is duplicated in Plugin::migrateItemType() for plugin object
                        foreach ($entities as $entID => $val) {
                            if ($do_recursive) {
                                // Non recursive ones
                                $query3 = "UPDATE `{$table}`\n                                 SET `entities_id`={$entID}, `is_recursive`=0\n                                 WHERE `itemtype`='" . $data['itemtype'] . "'\n                                    AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                                    WHERE `entities_id`={$entID} AND `is_recursive`=0)";
                                $DB->query($query3) or die("0.78 update entities_id and is_recursive=0\n                              in {$table} for " . $data['itemtype'] . " " . $LANG['update'][90] . $DB->error());
                                // Recursive ones
                                $query3 = "UPDATE `{$table}`\n                                 SET `entities_id`={$entID}, `is_recursive`=1\n                                 WHERE `itemtype`='" . $data['itemtype'] . "'\n                                    AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                                    WHERE `entities_id`={$entID} AND `is_recursive`=1)";
                                $DB->query($query3) or die("0.78 update entities_id and is_recursive=1\n                              in {$table} for " . $data['itemtype'] . " " . $LANG['update'][90] . $DB->error());
                            } else {
                                $query3 = "UPDATE `{$table}`\n                                 SET `entities_id`={$entID}\n                                 WHERE `itemtype`='" . $data['itemtype'] . "'\n                                    AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                                    WHERE `entities_id`={$entID})";
                                $DB->query($query3) or die("0.78 update entities_id in {$table}\n                              for " . $data['itemtype'] . " " . $LANG['update'][90] . $DB->error());
                            }
                        }
                    }
                }
            }
        }
    }
    // Migrate consumable and cartridge and computerdisks entity information
    $items = array('glpi_cartridges' => 'glpi_cartridgeitems', 'glpi_consumables' => 'glpi_consumableitems', 'glpi_computerdisks' => 'glpi_computers');
    foreach ($items as $linkitem => $sourceitem) {
        if (!FieldExists($linkitem, 'entities_id')) {
            displayMigrationMessage("078", $LANG['update'][141] . ' - ' . $linkitem);
            // Updating schema
            $query = "ALTER TABLE `{$linkitem}` ADD `entities_id` int(11) NOT NULL DEFAULT 0 AFTER `id`,\n                           ADD INDEX `entities_id` ( `entities_id` )";
            $DB->query($query) or die("0.78 add entities_id in {$linkitem} " . $LANG['update'][90] . $DB->error());
            $entities = getAllDatasFromTable('glpi_entities');
            $entities[0] = "Root";
            foreach ($entities as $entID => $val) {
                $query3 = "UPDATE {$linkitem}\n                     SET `entities_id`='{$entID}'\n                     WHERE " . getForeignKeyFieldForTable($sourceitem) . " IN\n                        (SELECT `id` FROM {$sourceitem} WHERE `entities_id`='{$entID}' )";
                $DB->query($query3) or die("0.78 update entities_id in {$linkitem} " . $LANG['update'][90] . $DB->error());
            }
        }
    }
    // Migrate softwareversions entity information
    if (!FieldExists('glpi_softwareversions', 'entities_id')) {
        displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_softwareversions');
        // Updating schema
        $query = "ALTER TABLE `glpi_softwareversions` ADD `entities_id` int(11) NOT NULL DEFAULT 0 AFTER `id`,\n                        ADD INDEX `entities_id` ( `entities_id` ),\n                        ADD `is_recursive` tinyint(1) NOT NULL DEFAULT 0 AFTER `entities_id`,\n                        ADD INDEX `is_recursive` ( `is_recursive` )";
        $DB->query($query) or die("0.78 add entities_id in glpi_softwareversion " . $LANG['update'][90] . $DB->error());
        $entities = getAllDatasFromTable('glpi_entities');
        $entities[0] = "Root";
        foreach ($entities as $entID => $val) {
            // Non recursive ones
            $query3 = "UPDATE `glpi_softwareversions`\n                  SET `entities_id`={$entID}, `is_recursive`=0\n                  WHERE `softwares_id` IN (SELECT `id` FROM `glpi_softwares`\n                     WHERE `entities_id`={$entID} AND `is_recursive`=0)";
            $DB->query($query3) or die("0.78 update entities_id and is_recursive=0\n               in glpi_softwareversions for " . $data['itemtype'] . " " . $LANG['update'][90] . $DB->error());
            // Recursive ones
            $query3 = "UPDATE `glpi_softwareversions`\n                  SET `entities_id`={$entID}, `is_recursive`=1\n                  WHERE `softwares_id` IN (SELECT `id` FROM `glpi_softwares`\n                     WHERE `entities_id`={$entID} AND `is_recursive`=1)";
            $DB->query($query3) or die("0.78 update entities_id and is_recursive=1\n               in glpi_softwareversions for " . $data['itemtype'] . " " . $LANG['update'][90] . $DB->error());
        }
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_mailcollectors');
    // Updating schema
    if (!FieldExists("glpi_mailcollectors", "is_active")) {
        $query = "ALTER TABLE `glpi_mailcollectors` ADD `is_active` tinyint( 1 ) NOT NULL DEFAULT '1',\n                           ADD INDEX `is_active` (`is_active`) ;";
        $DB->query($query) or die("0.78 add is_active in glpi_mailcollectors " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_mailcollectors', 'date_mod')) {
        $query = "ALTER TABLE `glpi_mailcollectors`\n                ADD `date_mod` DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod to glpi_mailcollectors" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_mailcollectors', 'comment')) {
        $query = "ALTER TABLE `glpi_mailcollectors`\n                ADD `comment` text collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add comment to glpi_mailcollectors" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_profiles', 'rule_mailcollector')) {
        $query = "ALTER TABLE `glpi_profiles` ADD `rule_mailcollector` CHAR( 1 ) NULL ";
        $DB->query($query) or die("0.78 add rule_mailcollector to glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `rule_mailcollector`=`rule_ticket`";
        $DB->query($query) or die("0.78 set default rule_mailcollector same as rule_ticket " . $LANG['update'][90] . $DB->error());
    }
    // Change search pref : add active / date_mod
    $ADDTODISPLAYPREF['MailCollector'] = array(2, 19);
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_authldaps');
    // Updating schema
    if (!FieldExists('glpi_authldaps', 'date_mod')) {
        $query = "ALTER TABLE `glpi_authldaps`\n                ADD `date_mod` DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod to glpi_authldaps" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_authldaps', 'comment')) {
        $query = "ALTER TABLE `glpi_authldaps`\n                ADD `comment` text collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add comment to glpi_authldaps" . $LANG['update'][90] . $DB->error());
    }
    // Change search pref : host, date_mod
    $ADDTODISPLAYPREF['AuthLDAP'] = array(3, 19);
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_authldaps');
    // Updating schema
    if (!FieldExists('glpi_authmails', 'date_mod')) {
        $query = "ALTER TABLE `glpi_authmails`\n                ADD `date_mod` DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod to glpi_authmails" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_authmails', 'comment')) {
        $query = "ALTER TABLE `glpi_authmails`\n                ADD `comment` text collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add comment to glpi_authmails" . $LANG['update'][90] . $DB->error());
    }
    // Change search pref : host, date_mod
    $ADDTODISPLAYPREF['AuthMail'] = array(3, 19);
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_ocsservers');
    // Updating schema
    if (!FieldExists('glpi_ocsservers', 'date_mod')) {
        $query = "ALTER TABLE `glpi_ocsservers`\n                ADD `date_mod` DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod to glpi_ocsservers" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_ocsservers', 'comment')) {
        $query = "ALTER TABLE `glpi_ocsservers`\n                ADD `comment` text collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add comment to glpi_ocsservers" . $LANG['update'][90] . $DB->error());
    }
    // Change search pref : date_mod / host
    $ADDTODISPLAYPREF['OcsServer'] = array(3, 19);
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_profiles');
    // Updating schema
    if (!FieldExists('glpi_profiles', 'date_mod')) {
        $query = "ALTER TABLE `glpi_profiles`\n                ADD `date_mod` DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod to glpi_profiles" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_profiles', 'comment')) {
        $query = "ALTER TABLE `glpi_profiles`\n                ADD `comment` text collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add comment to glpi_profiles" . $LANG['update'][90] . $DB->error());
    }
    // Change search pref : date_mod / host
    $ADDTODISPLAYPREF['Profile'] = array(2, 3, 19);
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_printers');
    // Updating schema
    if (!FieldExists('glpi_printers', 'have_ethernet')) {
        $query = "ALTER TABLE `glpi_printers` ADD `have_ethernet` TINYINT( 1 ) NOT NULL\n                  DEFAULT '0' AFTER `have_usb`;";
        $DB->query($query) or die("0.78 add have_ethernet to glpi_printers" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_printers', 'have_wifi')) {
        $query = "ALTER TABLE `glpi_printers` ADD `have_wifi` TINYINT( 1 ) NOT NULL\n               DEFAULT '0' AFTER `have_usb` ;";
        $DB->query($query) or die("0.78 add have_wifi to glpi_printers" . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][141] . ' - glpi_profiles');
    // Updating schema
    if (!FieldExists('glpi_transfers', 'date_mod')) {
        $query = "ALTER TABLE `glpi_transfers`\n                ADD `date_mod` DATETIME NULL, ADD INDEX `date_mod` (`date_mod`)";
        $DB->query($query) or die("0.78 add date_mod to glpi_transfers" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_transfers', 'comment')) {
        $query = "ALTER TABLE `glpi_transfers`\n                ADD `comment` text collate utf8_unicode_ci";
        $DB->query($query) or die("0.78 add comment to glpi_transfers" . $LANG['update'][90] . $DB->error());
    }
    // Change search pref : date_mod
    $ADDTODISPLAYPREF['Transfer'] = array(19);
    // Convert events
    displayMigrationMessage("078", $LANG['update'][142] . ' - glpi_events');
    $convert_types = array('tracking' => 'ticket', 'networking' => 'networkequipment', 'knowbase' => 'knowbaseitem', 'typedocs' => 'documenttype', 'mailgate' => 'mailcollector');
    //$convert_service=array('tracking'=>'ticket');
    foreach ($convert_types as $from => $to) {
        $query2 = "UPDATE glpi_events SET type='{$to}' WHERE type='{$from}';";
        $DB->query($query2) or die("0.78 update events data " . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][142] . ' - ticket bookmarks');
    $query = "SELECT * FROM `glpi_bookmarks`\n            WHERE `itemtype`='Ticket' AND `type`='" . BOOKMARK_SEARCH . "';";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0) {
            while ($data = $DB->fetch_assoc($result)) {
                $num = 0;
                $num2 = 0;
                $options = array();
                parse_str($data["query"], $options);
                $newoptions = array();
                foreach ($options as $key => $val) {
                    switch ($key) {
                        case "status":
                            $newoptions['field'][$num] = 12;
                            $newoptions['searchtype'][$num] = 'equals';
                            $newoptions['link'][$num] = 'AND';
                            if ($val == 'old_done' || $val == 'old_notdone') {
                                $newoptions['contains'][$num] = 'closed';
                            } else {
                                $newoptions['contains'][$num] = $val;
                            }
                            $num++;
                            break;
                        case "priority":
                            if ($val != 0) {
                                $newoptions['field'][$num] = 3;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "category":
                            if ($val > 0) {
                                $newoptions['field'][$num] = 7;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "request_type":
                            if ($val > 0) {
                                $newoptions['field'][$num] = 9;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "type":
                            if ($val > 0 && isset($data['item']) && $data['item'] > 0) {
                                $newoptions['itemtype2'][$num2] = $typetoname[$val];
                                $newoptions['field2'][$num2] = 1;
                                $newoptions['searchtype2'][$num2] = 'equals';
                                $newoptions['contains2'][$num2] = $data['item'];
                                $newoptions['link2'][$num2] = 'AND';
                                $num2++;
                            }
                            break;
                        case "author":
                            if ($val > 0) {
                                $newoptions['field'][$num] = 4;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "group":
                            if ($val > 0) {
                                $newoptions['field'][$num] = 71;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "assign":
                            if ($val > 0) {
                                $newoptions['field'][$num] = 5;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "assign_group":
                            if ($val > 0) {
                                $newoptions['field'][$num] = 8;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "assign_ent":
                            if ($val > 0) {
                                $newoptions['field'][$num] = 6;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "recipient":
                            if ($val > 0) {
                                $newoptions['field'][$num] = 22;
                                $newoptions['searchtype'][$num] = 'equals';
                                $newoptions['contains'][$num] = $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "date1":
                            // begin from
                            if (strlen($val) > 0 && $val != 'NULL') {
                                $newoptions['field'][$num] = 15;
                                $newoptions['searchtype'][$num] = 'contains';
                                $newoptions['contains'][$num] = '&gt;=' . $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "date2":
                            // begin to
                            if (strlen($val) > 0 && $val != 'NULL') {
                                $newoptions['field'][$num] = 15;
                                $newoptions['searchtype'][$num] = 'contains';
                                $newoptions['contains'][$num] = '&lt;=' . $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "enddate1":
                            // end from
                            if (strlen($val) > 0 && $val != 'NULL') {
                                $newoptions['field'][$num] = 16;
                                $newoptions['searchtype'][$num] = 'contains';
                                $newoptions['contains'][$num] = '&gt;=' . $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "enddate2":
                            // end to
                            if (strlen($val) > 0 && $val != 'NULL') {
                                $newoptions['field'][$num] = 16;
                                $newoptions['searchtype'][$num] = 'contains';
                                $newoptions['contains'][$num] = '&lt;=' . $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "datemod1":
                            // mod from
                            if (strlen($val) > 0 && $val != 'NULL') {
                                $newoptions['field'][$num] = 19;
                                $newoptions['searchtype'][$num] = 'contains';
                                $newoptions['contains'][$num] = '&gt;=' . $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "datemod2":
                            // mod to
                            if (strlen($val) > 0 && $val != 'NULL') {
                                $newoptions['field'][$num] = 19;
                                $newoptions['searchtype'][$num] = 'contains';
                                $newoptions['contains'][$num] = '&lt;=' . $val;
                                $newoptions['link'][$num] = 'AND';
                                $num++;
                            }
                            break;
                        case "tosearch":
                            if (isset($data['search'])) {
                                $search = trim($data['search']);
                                if (strlen($search) > 0) {
                                    $first = false;
                                    if (strstr($data['search'], 'name')) {
                                        $newoptions['field'][$num] = 1;
                                        $newoptions['searchtype'][$num] = 'contains';
                                        $newoptions['contains'][$num] = $val;
                                        $newoptions['link'][$num] = $first ? 'AND' : 'OR';
                                        $first = false;
                                        $num++;
                                    }
                                    if (strstr($data['search'], 'contents')) {
                                        $newoptions['field'][$num] = 21;
                                        $newoptions['searchtype'][$num] = 'contains';
                                        $newoptions['contains'][$num] = $val;
                                        $newoptions['link'][$num] = $first ? 'AND' : 'OR';
                                        $first = false;
                                        $num++;
                                    }
                                    if (strstr($data['search'], 'followup')) {
                                        $newoptions['field'][$num] = 25;
                                        $newoptions['searchtype'][$num] = 'contains';
                                        $newoptions['contains'][$num] = $val;
                                        $newoptions['link'][$num] = $first ? 'AND' : 'OR';
                                        $first = false;
                                        $num++;
                                    }
                                    if (strstr($data['search'], 'ID')) {
                                        $newoptions['field'][$num] = 2;
                                        $newoptions['searchtype'][$num] = 'contains';
                                        $newoptions['contains'][$num] = $val;
                                        $newoptions['link'][$num] = 'AND';
                                        $first = false;
                                        $num++;
                                    }
                                }
                            }
                            break;
                    }
                }
                if ($num > 0 || $num2 > 0) {
                    $newoptions['glpisearchcount'] = $num;
                    $newoptions['glpisearchcount2'] = $num2;
                    $newoptions['itemtype'] = 'Ticket';
                    $query2 = "UPDATE glpi_bookmarks SET query='" . addslashes(append_params($newoptions)) . "' WHERE id=" . $data['id'] . ";";
                    $DB->query($query2) or die("0.78 update ticket bookmarks " . $LANG['update'][90] . $DB->error());
                } else {
                    $query2 = "DELETE FROM glpi_bookmarks WHERE id=" . $data['id'] . ";";
                    $DB->query($query2) or die("0.78 delete ticket bookmarks : cannot convert " . $LANG['update'][90] . $DB->error());
                }
                // Lost paramaters
                //only_computers=1&contains=dddd&field=moboard.designation&
            }
        }
    }
    if (!TableExists('glpi_ticketvalidations')) {
        $query = "CREATE TABLE `glpi_ticketvalidations` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `entities_id` int(11) NOT NULL default '0',\n                  `users_id` int(11) NOT NULL default '0',\n                  `tickets_id` int(11) NOT NULL default '0',\n                  `users_id_validate` int(11) NOT NULL default '0',\n                  `comment_submission` text collate utf8_unicode_ci,\n                  `comment_validation` text collate utf8_unicode_ci,\n                  `status` varchar(255) collate utf8_unicode_ci default 'waiting',\n                  `submission_date` datetime default NULL,\n                  `validation_date` datetime default NULL,\n                  PRIMARY KEY  (`id`),\n                  KEY `entities_id` (`entities_id`),\n                  KEY `users_id` (`users_id`),\n                  KEY `users_id_validate` (`users_id_validate`),\n                  KEY `tickets_id` (`tickets_id`),\n                  KEY `submission_date` (`submission_date`),\n                  KEY `validation_date` (`validation_date`),\n                  KEY `status` (`status`)\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("0.78 create glpi_ticketvalidations " . $LANG['update'][90] . $DB->error());
        $ADDTODISPLAYPREF['TicketValidation'] = array(3, 2, 8, 4, 9, 7);
    }
    if (!FieldExists('glpi_tickets', 'global_validation')) {
        $query = "ALTER TABLE `glpi_tickets` ADD `global_validation` varchar(255) collate utf8_unicode_ci default 'accepted',\n                                       ADD INDEX `global_validation` (`global_validation`)";
        $DB->query($query) or die("0.78 add global_validation to glpi_tickets " . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_profiles', 'validate_ticket')) {
        $query = "ALTER TABLE `glpi_profiles` ADD `validate_ticket` char(1) collate utf8_unicode_ci default NULL";
        $DB->query($query) or die("0.78 add validate_ticket to glpi_profiles " . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `validate_ticket`='1' WHERE `interface` = 'central' ";
        $DB->query($query) or die("0.78 add validate_ticket write right to super-admin and admin profiles" . $LANG['update'][90] . $DB->error());
        $query = "ALTER TABLE `glpi_profiles` ADD `create_validation` char(1) collate utf8_unicode_ci default NULL";
        $DB->query($query) or die("0.78 add create_validation to glpi_profiles " . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `create_validation`=`own_ticket`";
        $DB->query($query) or die("0.78 add create_validation right if can own ticket" . $LANG['update'][90] . $DB->error());
    }
    if (FieldExists('glpi_mailcollectors', 'entities_id')) {
        $ranking = 1;
        // No mailcollector : set a default rule
        if (countElementsInTable('glpi_mailcollectors') == 0) {
            $query = "INSERT INTO `glpi_rules` VALUES(NULL, -1, 'RuleMailCollector', {$ranking},\n                                                      'Root',\n                                                      '', 'OR', 1, NULL, NULL);";
            $DB->query($query) or die("0.78 error inserting new default maigate rule " . $LANG['update'][90] . $DB->error());
            if ($newID = $DB->insert_id()) {
                $query = "INSERT INTO `glpi_rulecriterias` VALUES(NULL, {$newID}, 'subject', 6,\n                                                               '/.*/');";
                $DB->query($query) or die("0.78 error getting new criteria for rule" . $LANG['update'][90] . $DB->error());
                $query = "INSERT INTO `glpi_ruleactions` VALUES(NULL, {$newID}, 'assign',\n                                                               'entities_id',\n                                                               '0');";
                $DB->query($query) or die("0.78 error getting new action for rule" . $LANG['update'][90] . $DB->error());
            }
        } else {
            foreach (getAllDatasFromTable('glpi_mailcollectors') as $collector) {
                $query = "INSERT INTO `glpi_rules` VALUES(NULL, -1, 'RuleMailCollector', {$ranking},\n                                                      '" . $collector['name'] . "',\n                                                      '', 'AND', 1, NULL, NULL);";
                $DB->query($query) or die("0.78 error inserting new maigate rule" . $collector['name'] . " " . $LANG['update'][90] . $DB->error());
                if ($newID = $DB->insert_id()) {
                    $query = "INSERT INTO `glpi_rulecriterias` VALUES(NULL, {$newID}, 'mailcollector', 0,\n                                                               '" . $collector['id'] . "');";
                    $DB->query($query) or die("0.78 error getting new criteria for rule" . $collector['name'] . " " . $LANG['update'][90] . $DB->error());
                    $query = "INSERT INTO `glpi_ruleactions` VALUES(NULL, {$newID}, 'assign',\n                                                               'entities_id',\n                                                               '" . $collector['entities_id'] . "');";
                    $DB->query($query) or die("0.78 error getting new action for rule" . $collector['name'] . " " . $LANG['update'][90] . $DB->error());
                }
                $ranking++;
            }
        }
        $query = "ALTER TABLE `glpi_mailcollectors` DROP INDEX `entities_id` ";
        $DB->query($query) or die("0.78 drop index entities_id from glpi_mailcollectors" . $LANG['update'][90] . $DB->error());
        $query = "ALTER TABLE `glpi_mailcollectors` DROP `entities_id` ";
        $DB->query($query) or die("0.78 drop entities_id from glpi_mailcollectors" . $LANG['update'][90] . $DB->error());
        $query = "DELETE FROM `glpi_displaypreferences` WHERE `itemtype`='MailCollector' AND `num`='80'";
        $DB->query($query) or die("0.78 drop entities_id from collector's display preferences'" . $LANG['update'][90] . $DB->error());
    }
    if (!TableExists('glpi_notimportedemails')) {
        $query = "CREATE TABLE `glpi_notimportedemails` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `from` varchar(255) NOT NULL,\n                  `to` varchar(255) NOT NULL,\n                  `mailcollectors_id` int(11) NOT NULL DEFAULT '0',\n                  `date` datetime NOT NULL,\n                  `subject` text,\n                  `messageid` varchar(255) NOT NULL,\n                  `reason` int(11) NOT NULL DEFAULT '0',\n                  `users_id` int(11) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  KEY `users_id` (`users_id`),\n                  KEY `mailcollectors_id` (`mailcollectors_id`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
        $DB->query($query) or die("0.78 add table glpi_notimportedemails" . $LANG['update'][90] . $DB->error());
        $ADDTODISPLAYPREF['NotImportedEmail'] = array(2, 5, 4, 6, 16, 19);
    }
    if (!FieldExists("glpi_profiles", "entity_rule_ticket")) {
        $query = "ALTER TABLE `glpi_profiles` ADD `entity_rule_ticket` CHAR( 1 ) NULL AFTER `rule_ticket`";
        $DB->query($query) or die("0.78 add entity_rule_ldap in glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `entity_rule_ticket`=`rule_ticket`";
        $DB->query($query) or die("0.78 update default entity_rule_ticket rights" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `rule_ticket`='r' WHERE `rule_ticket`='w'";
        $DB->query($query) or die("0.78 update rule_ticket rights" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_authldaps', 'is_default')) {
        $query = "ALTER TABLE `glpi_authldaps` ADD `is_default` TINYINT( 1 ) NOT NULL DEFAULT '0',\n                                             ADD INDEX `is_default` (`is_default`)";
        $DB->query($query) or die("0.78 add is_default to glpi_authldaps " . $LANG['update'][90] . $DB->error());
        $query = "SELECT count(*) as cpt FROM `glpi_authldaps`";
        $result = $DB->query($query);
        $number_servers = $DB->result($result, 0, 'cpt');
        if ($number_servers >= 1) {
            //If only one server defined
            if ($number_servers == 1) {
                $query = "SELECT `id` FROM `glpi_authldaps`";
                $result = $DB->query($query);
                $ldapservers_id = $DB->result($result, 0, 'id');
            } else {
                $query = "SELECT `auths_id`, count(auths_id) as cpt\n                FROM `glpi_users`\n                WHERE `authtype` = '3'\n                GROUP BY `auths_id`\n                ORDER BY `cpt` DESC";
                $result = $DB->query($query);
                $ldapservers_id = $DB->result($result, 0, 'auths_id');
            }
            $query = "UPDATE `glpi_authldaps` SET `is_default`='1' WHERE `id`='" . $ldapservers_id . "'";
            $DB->query($query) or die("0.78 set default directory " . $LANG['update'][90] . $DB->error());
        }
    }
    if (TableExists('glpi_rulerightparameters')) {
        $query = "ALTER TABLE `glpi_rulerightparameters` ADD `comment` TEXT NOT NULL ";
        $DB->query($query) or die("0.78 add comment to glpi_rulerightparameters" . $LANG['update'][90] . $DB->error());
        $ADDTODISPLAYPREF['RuleRightParameter'] = array(11);
    }
    if (!FieldExists('glpi_rules', 'is_recursive')) {
        $query = "ALTER TABLE `glpi_rules` ADD `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0',\n                           ADD INDEX `is_recursive` (`is_recursive`)";
        $DB->query($query) or die("0.78 add is_recursive to glpi_rules" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_rules` SET `entities_id`='0' WHERE `entities_id`='-1'";
        $DB->query($query) or die("0.78 set entities_id to 0 where value is -1 in glpi_rules" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_rules` SET `is_recursive`='1' WHERE `sub_type`='RuleTicket'";
        $DB->query($query) or die("0.78 set is_recursive to 1 for RuleTicket in glpi_rules" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists('glpi_configs', 'user_deleted_ldap')) {
        $query = "ALTER TABLE `glpi_configs` ADD `user_deleted_ldap` TINYINT( 1 ) NOT NULL DEFAULT '0'";
        $DB->query($query) or die("0.78 add user_deleted_ldap to glpi_configs" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_profiles", "group_add_followup")) {
        $query = "ALTER TABLE `glpi_profiles` ADD `group_add_followups` CHAR(1) NULL AFTER `add_followups`";
        $DB->query($query) or die("0.78 add budget in glpi_profiles" . $LANG['update'][90] . $DB->error());
        $query = "UPDATE `glpi_profiles` SET `group_add_followups`=`global_add_followups`";
        $DB->query($query) or die("0.78 update default budget rights" . $LANG['update'][90] . $DB->error());
    }
    if (!FieldExists("glpi_groups_users", "is_dynamic")) {
        $query = "ALTER TABLE `glpi_groups_users` ADD `is_dynamic` TINYINT( 1 ) NOT NULL DEFAULT '0'";
        $DB->query($query) or die("0.78 add is_dynamic in glpi_groups_users " . $LANG['update'][90] . $DB->error());
        //If group comes from an LDAP directory, then update users belonging to it
        //by setting is_dynamic to 1
        $query = "UPDATE `glpi_groups_users` SET `is_dynamic`='1'\n               WHERE groups_id IN (\n                  SELECT `id`\n                  FROM `glpi_groups`\n                  WHERE (`ldap_group_dn` IS NOT NULL AND `ldap_group_dn` <> '')\n                    OR ((`ldap_field` IS NOT NULL AND `ldap_field` <> '')\n                       AND (`ldap_value` IS NOT NULL AND `ldap_value` <> '')))";
        $DB->query($query) or die("0.78 update is_dynamic in glpi_groups_users " . $LANG['update'][90] . $DB->error());
    }
    displayMigrationMessage("078", $LANG['update'][142] . ' - glpi_displaypreferences');
    // Add search values for tickets
    $ADDTODISPLAYPREF['Ticket'] = array(12, 19, 15, 3, 4, 5, 7);
    foreach ($ADDTODISPLAYPREF as $type => $tab) {
        $query = "SELECT DISTINCT users_id FROM glpi_displaypreferences WHERE itemtype='{$type}';";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                while ($data = $DB->fetch_assoc($result)) {
                    $query = "SELECT max(rank) FROM glpi_displaypreferences\n                           WHERE users_id='" . $data['users_id'] . "' AND `itemtype`='{$type}';";
                    $result = $DB->query($query);
                    $rank = $DB->result($result, 0, 0);
                    $rank++;
                    foreach ($tab as $newval) {
                        $query = "SELECT * FROM glpi_displaypreferences\n                           WHERE users_id='" . $data['users_id'] . "' AND num={$newval} AND itemtype='{$type}';";
                        if ($result2 = $DB->query($query)) {
                            if ($DB->numrows($result2) == 0) {
                                $query = "INSERT INTO glpi_displaypreferences (`itemtype` ,`num` ,`rank` ,`users_id`)\n                                 VALUES ('{$type}', '{$newval}', '" . $rank++ . "', '" . $data['users_id'] . "');";
                                $DB->query($query);
                            }
                        }
                    }
                }
            } else {
                // Add for default user
                $rank = 1;
                foreach ($tab as $newval) {
                    $query = "INSERT INTO glpi_displaypreferences (`itemtype` ,`num` ,`rank` ,`users_id`)\n                        VALUES ('{$type}', '{$newval}', '" . $rank++ . "', '0');";
                    $DB->query($query);
                }
            }
        }
    }
    // Display "Work ended." message - Keep this as the last action.
    displayMigrationMessage("078");
    // End
    return $updateresult;
}