Esempio n. 1
0
function plugin_resources_install()
{
    global $DB;
    foreach (glob(GLPI_ROOT . '/plugins/resources/inc/*.php') as $file) {
        if (!preg_match('/resourceinjection/', $file) && !preg_match('/clientinjection/', $file) && !preg_match('/resourcepdf/', $file) && !preg_match('/datecriteria/', $file)) {
            include_once $file;
        }
    }
    $update = false;
    $update78 = false;
    $update80 = false;
    $update804 = false;
    $update83 = false;
    $install = false;
    if (!TableExists("glpi_plugin_resources_resources") && !TableExists("glpi_plugin_resources_employments")) {
        $install = true;
        //      $DB->runFile(GLPI_ROOT ."/plugins/resources/sql/empty-1.9.0.sql");
        //      $DB->runFile(GLPI_ROOT ."/plugins/resources/sql/update-1.9.1.sql");
        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/empty-1.9.1.sql");
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n         VALUES (1, '" . __('Long term contract', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n               VALUES (2, '" . __('Fixed term contract', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n               VALUES (3, '" . __('Trainee', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
    } else {
        if (TableExists("glpi_plugin_resources") && !TableExists("glpi_plugin_resources_employee")) {
            $update = true;
            $update78 = true;
            $update80 = true;
            $update804 = true;
            $update83 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.4.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
        } else {
            if (TableExists("glpi_plugin_resources_profiles") && FieldExists("glpi_plugin_resources_profiles", "interface")) {
                $update = true;
                $update78 = true;
                $update80 = true;
                $update804 = true;
                $update83 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
            } else {
                if (TableExists("glpi_plugin_resources") && !FieldExists("glpi_plugin_resources", "helpdesk_visible")) {
                    $update = true;
                    $update78 = true;
                    $update80 = true;
                    $update804 = true;
                    $update83 = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                } else {
                    if (!TableExists("glpi_plugin_resources_contracttypes")) {
                        $update = true;
                        $update78 = true;
                        $update80 = true;
                        $update804 = true;
                        $update83 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                    } else {
                        if (TableExists("glpi_plugin_resources_contracttypes") && !FieldExists("glpi_plugin_resources_resources", "plugin_resources_resourcestates_id")) {
                            $update = true;
                            $update80 = true;
                            $update804 = true;
                            $update83 = true;
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                        } else {
                            if (!TableExists("glpi_plugin_resources_reportconfigs")) {
                                $update = true;
                                $update80 = true;
                                $update804 = true;
                                $update83 = true;
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                            } else {
                                if (!TableExists("glpi_plugin_resources_checklistconfigs")) {
                                    $update80 = true;
                                    $update804 = true;
                                    $update83 = true;
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                } else {
                                    if (!TableExists("glpi_plugin_resources_choiceitems")) {
                                        $update804 = true;
                                        $update83 = true;
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                    } else {
                                        if (!TableExists("glpi_plugin_resources_employments")) {
                                            $update83 = true;
                                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                            $query = "SELECT *\n               FROM `glpi_plugin_resources_employers`";
                                            $result = $DB->query($query);
                                            if ($DB->numrows($result) > 0) {
                                                while ($data = $DB->fetch_array($result)) {
                                                    $queryUpdate = "UPDATE `glpi_plugin_resources_employers`\n                            SET `completename`= '" . $data["name"] . "'\n                            WHERE `id`= '" . $data["id"] . "'";
                                                    $DB->query($queryUpdate) or die($DB->error());
                                                }
                                            }
                                        } else {
                                            if (TableExists("glpi_plugin_resources_ranks") && !FieldExists("glpi_plugin_resources_ranks", "begin_date")) {
                                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($update78 || $install) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resources'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.url##  : ##resource.url##\n\n   ##lang.resource.entity## : ##resource.entity##\n   ##IFresource.name####lang.resource.name## : ##resource.name##\n   ##ENDIFresource.name## ##IFresource.firstname####lang.resource.firstname## : ##resource.firstname##\n   ##ENDIFresource.firstname## ##IFresource.type####lang.resource.type## : ##resource.type##\n   ##ENDIFresource.type## ##IFresource.users####lang.resource.users## : ##resource.users##\n   ##ENDIFresource.users## ##IFresource.usersrecipient####lang.resource.usersrecipient## : ##resource.usersrecipient##\n   ##ENDIFresource.usersrecipient## ##IFresource.datedeclaration####lang.resource.datedeclaration## : ##resource.datedeclaration##\n   ##ENDIFresource.datedeclaration## ##IFresource.datebegin####lang.resource.datebegin## : ##resource.datebegin##\n   ##ENDIFresource.datebegin## ##IFresource.dateend####lang.resource.dateend## : ##resource.dateend##\n   ##ENDIFresource.dateend## ##IFresource.department####lang.resource.department## : ##resource.department##\n   ##ENDIFresource.department## ##IFresource.status####lang.resource.status## : ##resource.status##\n   ##ENDIFresource.status## ##IFresource.location####lang.resource.location## : ##resource.location##\n   ##ENDIFresource.location## ##IFresource.comment####lang.resource.comment## : ##resource.comment##\n   ##ENDIFresource.comment## ##IFresource.usersleaving####lang.resource.usersleaving## : ##resource.usersleaving##\n   ##ENDIFresource.usersleaving## ##IFresource.leaving####lang.resource.leaving## : ##resource.leaving##\n   ##ENDIFresource.leaving## ##IFresource.helpdesk####lang.resource.helpdesk## : ##resource.helpdesk##\n   ##ENDIFresource.helpdesk## ##FOREACHupdates##----------\n   ##lang.update.title## :\n   ##IFupdate.name####lang.resource.name## : ##update.name##\n   ##ENDIFupdate.name## ##IFupdate.firstname####lang.resource.firstname## : ##update.firstname##\n   ##ENDIFupdate.firstname## ##IFupdate.type####lang.resource.type## : ##update.type##\n   ##ENDIFupdate.type## ##IFupdate.users####lang.resource.users## : ##update.users##\n   ##ENDIFupdate.users## ##IFupdate.usersrecipient####lang.resource.usersrecipient## : ##update.usersrecipient##\n   ##ENDIFupdate.usersrecipient## ##IFupdate.datedeclaration####lang.resource.datedeclaration## : ##update.datedeclaration##\n   ##ENDIFupdate.datedeclaration## ##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin##\n   ##ENDIFupdate.datebegin## ##IFupdate.dateend####lang.resource.dateend## : ##update.dateend##\n   ##ENDIFupdate.dateend## ##IFupdate.department####lang.resource.department## : ##update.department##\n   ##ENDIFupdate.department## ##IFupdate.status####lang.resource.status## : ##update.status##\n   ##ENDIFupdate.status## ##IFupdate.location####lang.resource.location## : ##update.location##\n   ##ENDIFupdate.location## ##IFupdate.comment####lang.resource.comment## : ##update.comment##\n   ##ENDIFupdate.comment## ##IFupdate.usersleaving####lang.resource.usersleaving## : ##update.usersleaving##\n   ##ENDIFupdate.usersleaving## ##IFupdate.leaving####lang.resource.leaving## : ##update.leaving##\n   ##ENDIFupdate.leaving## ##IFupdate.helpdesk####lang.resource.helpdesk## : ##update.helpdesk##\n   ##ENDIFupdate.helpdesk## ----------##ENDFOREACHupdates##\n   ##FOREACHtasks####lang.task.title## :\n   ##IFtask.name####lang.task.name## : ##task.name##\n   ##ENDIFtask.name## ##IFtask.type####lang.task.type## : ##task.type##\n   ##ENDIFtask.type## ##IFtask.users####lang.task.users## : ##task.users##\n   ##ENDIFtask.users## ##IFtask.groups####lang.task.groups## : ##task.groups##\n   ##ENDIFtask.groups## ##IFtask.datebegin####lang.task.datebegin## : ##task.datebegin##\n   ##ENDIFtask.datebegin## ##IFtask.dateend####lang.task.dateend## : ##task.dateend##\n   ##ENDIFtask.dateend## ##IFtask.comment####lang.task.comment## : ##task.comment##\n   ##ENDIFtask.comment## ##IFtask.finished####lang.task.finished## : ##task.finished##\n   ##ENDIFtask.finished## ##IFtask.realtime####lang.task.realtime## : ##task.realtime##\n   ##ENDIFtask.realtime## ----------##ENDFOREACHtasks## ',\n                        '<p><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.url##\n                        </strong> :\n                        <a href=\"##resource.url##\">##resource.url##\n                        </a></span> <br /><br />\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.entity##</strong> : ##resource.entity##\n                        </span> <br /> ##IFresource.name##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.name##</strong> : ##resource.name##\n                        <br /></span>##ENDIFresource.name## ##IFresource.firstname##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.firstname##</strong> : ##resource.firstname##\n                        <br /></span>##ENDIFresource.firstname## ##IFresource.type##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.type##</strong> :  ##resource.type##<br />\n                        </span>##ENDIFresource.type## ##IFresource.status##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.status##</strong> :  ##resource.status##<br />\n                        </span>##ENDIFresource.status## ##IFresource.users##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.users##</strong> :  ##resource.users##<br />\n                        </span>##ENDIFresource.users## ##IFresource.usersrecipient##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.usersrecipient##\n                        </strong> :  ##resource.usersrecipient##<br />\n                        </span>##ENDIFresource.usersrecipient## ##IFresource.datedeclaration##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.datedeclaration##\n                        </strong> :  ##resource.datedeclaration##<br />\n                        </span>##ENDIFresource.datedeclaration## ##IFresource.datebegin##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.datebegin##</strong> :  ##resource.datebegin##\n                        <br /></span>##ENDIFresource.datebegin## ##IFresource.dateend##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.dateend##</strong> :  ##resource.dateend##\n                        <br /></span>##ENDIFresource.dateend## ##IFresource.department##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.department##</strong> :  ##resource.department##\n                        <br /></span>##ENDIFresource.department## ##IFresource.location##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.location##</strong> :  ##resource.location##\n                        <br /></span>##ENDIFresource.location## ##IFresource.comment##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.comment##</strong> :  ##resource.comment##\n                        <br /></span>##ENDIFresource.comment## ##IFresource.usersleaving##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.usersleaving##</strong> :  ##resource.usersleaving##\n                        <br /></span>##ENDIFresource.usersleaving## ##IFresource.leaving##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.leaving##</strong> :  ##resource.leaving##\n                        <br /></span>##ENDIFresource.leaving## ##IFresource.helpdesk##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.helpdesk##</strong> :  ##resource.helpdesk##\n                        <br /></span>##ENDIFresource.helpdesk##   ##FOREACHupdates##----------\n                        <br />\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.update.title## :</strong></span>\n                        <br /> ##IFupdate.name##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.name##</strong> : ##update.name##<br />\n                        </span>##ENDIFupdate.name## ##IFupdate.firstname##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.firstname##</strong> : ##update.firstname##\n                        <br /></span>##ENDIFupdate.firstname## ##IFupdate.type##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.type##</strong> : ##update.type##<br />\n                        </span>##ENDIFupdate.type## ##IFupdate.status##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.status##</strong> : ##update.status##<br />\n                        </span>##ENDIFupdate.status## ##IFupdate.users##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.users##</strong> : ##update.users##<br />\n                        </span>##ENDIFupdate.users## ##IFupdate.usersrecipient##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.usersrecipient##</strong> : ##update.usersrecipient##\n                        <br /></span>##ENDIFupdate.usersrecipient## ##IFupdate.datedeclaration##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.datedeclaration##\n                        </strong> : ##update.datedeclaration##<br />\n                        </span>##ENDIFupdate.datedeclaration## ##IFupdate.datebegin##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.datebegin##</strong> : ##update.datebegin##\n                        <br /></span>##ENDIFupdate.datebegin## ##IFupdate.dateend##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.dateend##</strong> : ##update.dateend##\n                        <br /></span>##ENDIFupdate.dateend## ##IFupdate.department##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.department##</strong> : ##update.department##\n                        <br /></span>##ENDIFupdate.department## ##IFupdate.location##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.location##</strong> : ##update.location##\n                        <br /></span>##ENDIFupdate.location## ##IFupdate.comment##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.comment##</strong> : ##update.comment##\n                        <br /></span>##ENDIFupdate.comment## ##IFupdate.usersleaving##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.usersleaving##\n                        </strong> : ##update.usersleaving##<br />\n                        </span>##ENDIFupdate.usersleaving## ##IFupdate.leaving##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.leaving##</strong> : ##update.leaving##\n                        <br /></span>##ENDIFupdate.leaving## ##IFupdate.helpdesk##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.resource.helpdesk##</strong> : ##update.helpdesk##\n                        <br /></span>##ENDIFupdate.helpdesk####ENDFOREACHupdates##   ##FOREACHtasks##----------\n                        <br /><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.title## :</strong></span> <br /> ##IFtask.name##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.name##</strong> : ##task.name##<br />\n                        </span>##ENDIFtask.name## ##IFtask.type##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.type##</strong> : ##task.type##<br />\n                        </span>##ENDIFtask.type## ##IFtask.users##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.users##</strong> : ##task.users##<br />\n                        </span>##ENDIFtask.users## ##IFtask.groups##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.groups##</strong> : ##task.groups##<br />\n                        </span>##ENDIFtask.groups## ##IFtask.datebegin##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.datebegin##</strong> : ##task.datebegin##<br />\n                        </span>##ENDIFtask.datebegin## ##IFtask.dateend##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.dateend##</strong> : ##task.dateend##<br />\n                        </span>##ENDIFtask.dateend## ##IFtask.comment##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.comment##</strong> : ##task.comment##<br />\n                        </span>##ENDIFtask.comment## ##IFtask.finished##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.finished##</strong> : ##task.finished##<br />\n                        </span>##ENDIFtask.finished## ##IFtask.realtime##\n                        <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n                        <strong>##lang.task.realtime##</strong> : ##task.realtime##\n                        </span>##ENDIFtask.realtime##<br />----------##ENDFOREACHtasks##</p>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource', 0, 'PluginResourcesResource', 'new',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource', 0, 'PluginResourcesResource', 'update',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource', 0, 'PluginResourcesResource', 'delete',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Task', 0, 'PluginResourcesResource', 'newtask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Task', 0, 'PluginResourcesResource', 'updatetask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Task', 0, 'PluginResourcesResource', 'deletetask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Resources Tasks'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##resource.action## : ##resource.entity##',\n                        '##FOREACHtasks##\n   ##lang.task.name## : ##task.name##\n   ##lang.task.type## : ##task.type##\n   ##lang.task.users## : ##task.users##\n   ##lang.task.groups## : ##task.groups##\n   ##lang.task.datebegin## : ##task.datebegin##\n   ##lang.task.dateend## : ##task.dateend##\n   ##lang.task.comment## : ##task.comment##\n   ##lang.task.resource## : ##task.resource##\n   ##ENDFOREACHtasks##',\n                           '<table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n   <tbody>\n   <tr>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.name##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.type##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.users##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.groups##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.datebegin##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.dateend##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.comment##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.resource##</span></td>\n   </tr>\n   ##FOREACHtasks##\n   <tr>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.name##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.type##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.users##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.groups##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.datebegin##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.dateend##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.comment##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.resource##</span></td>\n   </tr>\n   ##ENDFOREACHtasks##\n   </tbody>\n   </table>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Expired Resources Tasks', 0, 'PluginResourcesResource', 'AlertExpiredTasks',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Leaving Resources'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##resource.action## : ##resource.entity##',\n                        '##FOREACHresources##\n   ##lang.resource.name## : ##resource.name##\n   ##lang.resource.firstname## : ##resource.firstname##\n   ##lang.resource.type## : ##resource.type##\n   ##lang.resource.location## : ##resource.location##\n   ##lang.resource.users## : ##resource.users##\n   ##lang.resource.dateend## : ##resource.dateend##\n   ##ENDFOREACHresources##',\n                           '<table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n   <tbody>\n   <tr>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.name##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.firstname##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.type##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.location##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.users##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.dateend##</span></td>\n   </tr>\n   ##FOREACHresources##\n   <tr>\n   <td><a href=\"##resource.url##\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.name##</span></a></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.firstname##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.type##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.location##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.users##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.dateend##</span></td>\n   </tr>\n   ##ENDFOREACHresources##\n   </tbody>\n   </table>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Leaving Resources', 0, 'PluginResourcesResource', 'AlertLeavingResources',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Resources Checklists'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##checklist.action## : ##checklist.entity##',\n                        '##lang.checklist.title##\n\n   ##FOREACHchecklists##\n   ##lang.checklist.name## ##lang.checklist.firstname## : ##checklist.name## ##checklist.firstname##\n   ##lang.checklist.datebegin## : ##checklist.datebegin##\n   ##lang.checklist.dateend## : ##checklist.dateend##\n   ##lang.checklist.entity## : ##checklist.entity##\n   ##lang.checklist.location## : ##checklist.location##\n   ##lang.checklist.type## : ##checklist.type##\n\n   ##lang.checklist.title2## :\n   ##tasklist.name##\n   ##ENDFOREACHchecklists##',\n                           '<table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n   <tbody>\n   <tr bgcolor=\"#d9c4b8\">\n   <th colspan=\"7\"><span style=\"font-family: Verdana; font-size: 11px; text-align: center;\">##lang.checklist.title##</span></th>\n   </tr>\n   <tr>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checklist.name## ##lang.checklist.firstname##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checklist.datebegin##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checklist.dateend##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checklist.entity##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checklist.location##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checklist.type##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.checklist.title2##</span></td>\n   </tr>\n   ##FOREACHchecklists##\n   <tr>\n   <td><a href=\"##checklist.url##\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checklist.name## ##checklist.firstname##</span></a></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checklist.datebegin##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checklist.dateend##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checklist.entity##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checklist.location##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##checklist.type##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n   <table width=\"100%\">\n   <tbody>\n   <tr>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"> ##tasklist.name## </span></td>\n   </tr>\n   </tbody>\n   </table>\n   </span></td>\n   </tr>\n   ##ENDFOREACHchecklists##\n   </tbody>\n   </table>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Arrival Checklists', 0, 'PluginResourcesResource', 'AlertArrivalChecklists',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Leaving Checklists', 0, 'PluginResourcesResource', 'AlertLeavingChecklists',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Leaving Resource'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.title2##\n\n   ##lang.resource.url## : ##resource.url##\n\n   ##lang.resource.entity## : ##resource.entity##\n   ##IFresource.name## ##lang.resource.name## : ##resource.name##\n   ##ENDIFresource.name##\n   ##IFresource.firstname## ##lang.resource.firstname## : ##resource.firstname##\n   ##ENDIFresource.firstname##\n\n   ##lang.resource.badge##',\n                        '<p><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.resource.title2##</strong>\n   <p><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n   <strong>##lang.resource.url##</strong> :\n   <a href=\"##resource.url##\">##resource.url##</a>\n   </span> <br /><br />\n   <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n   <strong>##lang.resource.entity##</strong> : ##resource.entity##</span>\n   <br /> ##IFresource.name##\n   <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n   <strong>##lang.resource.name##</strong> : ##resource.name##<br />\n   </span>##ENDIFresource.name## ##IFresource.firstname##\n   <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n   <strong>##lang.resource.firstname##</strong> : ##resource.firstname##\n   <br /></span>##ENDIFresource.firstname##</p>\n   <p><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.resource.badge##</strong></span></p>\n   </span></p>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Leaving Resource', 0, 'PluginResourcesResource', 'LeavingResource',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        $profiles = getAllDatasFromTable("glpi_plugin_resources_profiles");
        if (!empty($profiles)) {
            foreach ($profiles as $profile) {
                $query = "UPDATE `glpi_plugin_resources_profiles`\n                  SET `profiles_id` = '" . $resource["id"] . "'\n                  WHERE `id` = '" . $resource["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        $tables = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs", "glpi_tickets");
        foreach ($tables as $table) {
            $query = "DELETE FROM `{$table}` WHERE (`itemtype` = '4302' ) ";
            $DB->query($query);
        }
        Plugin::migrateItemType(array(4300 => 'PluginResourcesResource', 4301 => 'PluginResourcesTask', 4303 => 'PluginResourcesDirectory'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_resources_resources_items", "glpi_plugin_resources_choices", "glpi_plugin_resources_tasks_items"));
        Plugin::migrateItemType(array(1600 => "PluginBadgesBadge"), array("glpi_plugin_resources_resources_items", "glpi_plugin_resources_choices", "glpi_plugin_resources_tasks_items"));
    }
    if ($update || $install) {
        //Do One time on 0.78 for 1.6.2
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Report Creation'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.creationtitle##\n\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n##lang.resource.department## : ##resource.department##\n##lang.resource.location## : ##resource.location##\n##lang.resource.users## : ##resource.users##\n##lang.resource.usersrecipient## : ##resource.usersrecipient##\n##lang.resource.datedeclaration## : ##resource.datedeclaration##\n##lang.resource.datebegin## : ##resource.datebegin##\n\n##lang.resource.creation##\n\n##lang.resource.datecreation## : ##resource.datecreation##\n##lang.resource.login## : ##resource.login##\n##lang.resource.email## : ##resource.email##\n\n##lang.resource.informationtitle##\n\n##IFresource.commentaires####lang.resource.commentaires## : ##resource.commentaires####ENDIFresource.commentaires##\n\n##IFresource.informations####lang.resource.informations## : ##resource.informations####ENDIFresource.informations##',\n                        '<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.resource.creationtitle##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n<tr>\n<td style=\"text-align: left;\" colspan=\"2\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.entity##</span></td>\n<td style=\"text-align: left;\" colspan=\"2\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.entity##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.name##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.name##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.firstname##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.firstname##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.department##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.department##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.location##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.location##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.users##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.users##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.usersrecipient##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.usersrecipient##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.datedeclaration##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.datedeclaration##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.datebegin##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.datebegin##</span></td>\n</tr>\n</tbody>\n</table>\n<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.resource.creation##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.datecreation##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.datecreation##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.login##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.login##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.email##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.email##</span></td>\n</tr>\n</tbody>\n</table>\n<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.resource.informationtitle##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n##IFresource.commentaires##\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.commentaires##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.commentaires##</span></td>\n</tr>\n##ENDIFresource.commentaires## ##IFresource.informations##\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.informations##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.informations##</span></td>\n</tr>\n##ENDIFresource.informations##\n</tbody>\n</table>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Resource Report Creation', 0, 'PluginResourcesResource', 'report',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-11-16 11:36:46');";
        $result = $DB->query($query);
    }
    if ($update80) {
        $restrict = "`plugin_resources_resources_id` ='-1'";
        $checklists = getAllDatasFromTable("glpi_plugin_resources_checklists", $restrict);
        $PluginResourcesChecklistconfig = new PluginResourcesChecklistconfig();
        if (!empty($checklists)) {
            foreach ($checklists as $checklist) {
                $values["name"] = addslashes($checklist["name"]);
                $values["address"] = addslashes($checklist["address"]);
                $values["comment"] = addslashes($checklist["comment"]);
                $values["tag"] = $checklist["tag"];
                $values["entities_id"] = $checklist["entities_id"];
                $PluginResourcesChecklistconfig->add($values);
            }
        }
        $query = "DELETE FROM `glpi_plugin_resources_checklists`\n               WHERE `plugin_resources_resources_id` ='-1'\n                  OR `plugin_resources_resources_id` ='0';";
        $DB->query($query);
        // Put realtime in seconds
        if (FieldExists('glpi_plugin_resources_tasks', 'realtime')) {
            $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n            ADD `actiontime` INT( 11 ) NOT NULL DEFAULT 0 ;";
            $DB->queryOrDie($query, $this->version . " 0.80 Add actiontime in glpi_plugin_resources_tasks");
            $query = "UPDATE `glpi_plugin_resources_tasks`\n                   SET `actiontime` = ROUND(realtime * 3600)";
            $DB->queryOrDie($query, $this->version . " 0.80 Compute actiontime value in glpi_plugin_resources_tasks");
            $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n            DROP `realtime` ;";
            $DB->queryOrDie($query, $this->version . " 0.80 DROP realtime in glpi_plugin_resources_tasks");
        }
        // ADD plannings for tasks
        $tasks = getAllDatasFromTable("glpi_plugin_resources_tasks");
        if (!empty($tasks)) {
            foreach ($tasks as $task) {
                $query = "INSERT INTO `glpi_plugin_resources_taskplannings`\n               ( `id` , `plugin_resources_tasks_id` , `begin` , `end` )\n               VALUES (NULL , '" . $task["id"] . "', '" . $task["date_begin"] . "', '" . $task["date_end"] . "') ;";
                $DB->query($query);
            }
        }
        unset($input);
        $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n               DROP `date_begin`, DROP `date_end` ;";
        $DB->queryOrDie($query, $this->version . " 0.80 Drop date_begin and date_end in glpi_plugin_resources_tasks");
        // ADD tasks
        $PluginResourcesResource = new PluginResourcesResource();
        $taches = getAllDatasFromTable("glpi_plugin_resources_tasks");
        if (!empty($taches)) {
            foreach ($taches as $tache) {
                $PluginResourcesResource->getFromDB($tache["plugin_resources_resources_id"]);
                $input["entities_id"] = $PluginResourcesResource->fields["entities_id"];
                $query = "UPDATE `glpi_plugin_resources_tasks`\n               SET `entities_id` =  '" . $PluginResourcesResource->fields["entities_id"] . "' WHERE `id` = '" . $tache["id"] . "' ;";
                $DB->query($query);
            }
        }
    }
    if ($install || $update80) {
        $restrict = "`itemtype` = 'PluginResourcesResource'";
        $unicities = getAllDatasFromTable("glpi_fieldunicities", $restrict);
        if (empty($unicities)) {
            $query = "INSERT INTO `glpi_fieldunicities`\n                                      VALUES (NULL, 'Resources creation', 1, 'PluginResourcesResource', '0',\n                                             'name,firstname','1',\n                                             '1', '1', '');";
            $DB->queryOrDie($query, " 0.80 Create fieldunicities check");
        }
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Resting'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.restingtitle##\n##lang.resource.openby## : ##resource.openby##\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n\n##lang.resource.department## : ##resource.department##\n##lang.resource.users## : ##resource.users##\n\n##lang.resource.resting##\n\n##lang.resource.location## : ##resource.location##\n##lang.resource.home## : ##resource.home##\n##lang.resource.datebegin## : ##resource.datebegin##\n##lang.resource.dateend## : ##resource.dateend##\n\n##lang.resource.commentaires## : ##resource.commentaires##\n\n##FOREACHupdates##\n##lang.update.title##\n\n##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin####ENDIFupdate.datebegin##\n##IFupdate.dateend####lang.resource.dateend## : ##update.dateend####ENDIFupdate.dateend##\n##IFupdate.location####lang.resource.location## : ##update.location###ENDIFupdate.location##\n##IFupdate.home####lang.resource.home## : ##update.home####ENDIFupdate.home##\n##IFupdate.comment####lang.resource.comment## : ##update.comment####ENDIFupdate.comment##\n##ENDFOREACHupdates##',\n                        '<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.resource.restingtitle##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.entity##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.entity##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.openby##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.openby##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.name##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.name##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.firstname##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.firstname##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.department##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.department##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.users##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.users##</span></td>\n</tr>\n</tbody>\n</table>\n<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.resource.resting##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.location##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.location##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.home##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.home##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.datebegin##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.datebegin##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.dateend##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.dateend##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.commentaires##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.commentaires##</span></td>\n</tr>\n</tbody>\n</table>\n<p>##FOREACHupdates##</p>\n<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.update.title##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n##IFupdate.datebegin##\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.datebegin## : ##update.datebegin##\n</span></span></td>\n</tr>\n##ENDIFupdate.datebegin## ##IFupdate.dateend##\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.dateend## : ##update.dateend##\n</span></span></td>\n</tr>\n##ENDIFupdate.dateend## ##IFupdate.location##\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.location## : ##update.location##\n</span></span></td>\n</tr>\n##ENDIFupdate.location## ##IFupdate.home##\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.home## : ##update.home##\n</span></span></td>\n</tr>\n##ENDIFupdate.home## ##IFupdate.comment##\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.comment## : ##update.comment##\n</span></span></td>\n</tr>\n##ENDIFupdate.comment##\n</tbody>\n</table>\n<p>##ENDFOREACHupdates##</p>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Resting', 0, 'PluginResourcesResource', 'newresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Resting', 0, 'PluginResourcesResource', 'updateresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Resting', 0, 'PluginResourcesResource', 'deleteresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Holiday'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.holidaytitle##\n##lang.resource.openby## : ##resource.openby##\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n\n##lang.resource.department## : ##resource.department##\n##lang.resource.users## : ##resource.users##\n\n##lang.resource.holiday##\n\n##lang.resource.datebegin## : ##resource.datebegin##\n##lang.resource.dateend## : ##resource.dateend##\n\n##lang.resource.commentaires## : ##resource.commentaires##\n\n##FOREACHupdates##\n##lang.update.title##\n\n##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin####ENDIFupdate.datebegin##\n##IFupdate.dateend####lang.resource.dateend## : ##update.dateend####ENDIFupdate.dateend##\n##IFupdate.comment####lang.resource.comment## : ##update.comment####ENDIFupdate.comment##\n##ENDFOREACHupdates##',\n                        '<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.resource.holidaytitle##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.entity##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.entity##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.openby##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.openby##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.name##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.name##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.firstname##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.firstname##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.department##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.department##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.users##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.users##</span></td>\n</tr>\n</tbody>\n</table>\n<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.resource.holiday##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n<tr>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.datebegin##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.datebegin##</span></td>\n<td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.dateend##</span></td>\n<td style=\"text-align: left;\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.dateend##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.commentaires##</span></td>\n</tr>\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##resource.commentaires##</span></td>\n</tr>\n</tbody>\n</table>\n<p>##FOREACHupdates##</p>\n<p style=\"text-align: center;\"><span style=\"font-size: 11px; font-family: verdana;\">##lang.update.title##</span></p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\">\n<tbody>\n##IFupdate.datebegin##\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.datebegin## : ##update.datebegin##\n</span></span></td>\n</tr>\n##ENDIFupdate.datebegin## ##IFupdate.dateend##\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.dateend## : ##update.dateend##\n</span></span></td>\n</tr>\n##ENDIFupdate.dateend## ##IFupdate.comment##\n<tr>\n<td style=\"text-align: left;\" colspan=\"4\" width=\"auto\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">\n<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.resource.comment## : ##update.comment##\n</span></span></td>\n</tr>\n##ENDIFupdate.comment##\n</tbody>\n</table>\n<p>##ENDFOREACHupdates##</p>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Holiday', 0, 'PluginResourcesResource', 'newholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Holiday', 0, 'PluginResourcesResource', 'updateholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Holiday', 0, 'PluginResourcesResource', 'deleteholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update804) {
        $query = "SELECT * FROM `glpi_plugin_resources_choices`\n      WHERE `itemtype`!= ''\n      GROUP BY `comment`,`itemtype`";
        $result = $DB->query($query);
        $number = $DB->numrows($result);
        $affectedchoices = array();
        if (!empty($number)) {
            while ($data = $DB->fetch_assoc($result)) {
                $restrictaffected = "`itemtype` = '" . $data["itemtype"] . "'\n               AND `comment` = '" . addslashes($data["comment"]) . "'";
                $affected = getAllDatasFromTable("glpi_plugin_resources_choices", $restrictaffected);
                if (!empty($affected)) {
                    foreach ($affected as $affect) {
                        if ($affect["itemtype"] == $data["itemtype"] && $affect["comment"] == $data["comment"]) {
                            $affectedchoices[$data["id"]][] = $affect["plugin_resources_resources_id"];
                        }
                    }
                }
            }
        }
        $i = 0;
        if (!empty($affectedchoices)) {
            foreach ($affectedchoices as $key => $ressources) {
                $i++;
                $choice = new PluginResourcesChoice();
                $choice_item = new PluginResourcesChoiceItem();
                $types = array(__('Computer') => 'Computer', __('Monitor') => 'Monitor', __('Software') => 'Software', __('Network device') => 'NetworkEquipment', __('Printer') => 'Printer', __('Peripheral') => 'Peripheral', __('Phone') => 'Phone', __('Consumable model') => 'ConsumableItem', __('Specific network rights', 'resources') => '4303', __('Access to the applications', 'resources') => '4304', __('Specific securities groups', 'resources') => '4305', __('Specific distribution lists', 'resources') => '4306', __('Others needs', 'resources') => '4307', 'PluginBadgesBadge' => 'PluginBadgesBadge');
                if ($choice->getFromDB($key)) {
                    $key = array_search($choice->fields["itemtype"], $types);
                    if ($key) {
                        $name = $key;
                    } else {
                        $name = $choice->fields["itemtype"];
                    }
                    $valuesparent["name"] = $i . "." . $name;
                    $valuesparent["entities_id"] = 0;
                    $valuesparent["is_recursive"] = 1;
                    $newidparent = $choice_item->add($valuesparent);
                    $comment = "N/A";
                    if (!empty($choice->fields["comment"])) {
                        $comment = $choice->fields["comment"];
                    }
                    $valueschild["name"] = addslashes(Html::resume_text($comment, 50));
                    $valueschild["comment"] = addslashes($comment);
                    $valueschild["entities_id"] = 0;
                    $valueschild["is_recursive"] = 1;
                    $valueschild["plugin_resources_choiceitems_id"] = $newidparent;
                    $newidchild = $choice_item->add($valueschild);
                    foreach ($ressources as $id => $val) {
                        $query = "UPDATE `glpi_plugin_resources_choices`\n                           SET `plugin_resources_choiceitems_id` = '" . $newidchild . "'\n                          WHERE `plugin_resources_resources_id` = '" . $val . "'\n                          AND `itemtype` = '" . $choice->fields["itemtype"] . "'\n                           AND `comment` = '" . addslashes($choice->fields["comment"]) . "';";
                        $result = $DB->query($query);
                    }
                }
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_choices`\n   DROP `itemtype`,\n   DROP `comment`,\n   ADD UNIQUE KEY `unicity` (`plugin_resources_resources_id`,`plugin_resources_choiceitems_id`);";
        $result = $DB->query($query);
        $query = "ALTER TABLE `glpi_plugin_resources_choices`\n   ADD `comment` text collate utf8_unicode_ci;";
        $result = $DB->query($query);
    }
    //0.83 - Drop Matricule
    if (TableExists("glpi_plugin_resources_employees") && FieldExists("glpi_plugin_resources_employees", "matricule")) {
        $query = "SELECT * FROM `glpi_users`";
        $result = $DB->query($query);
        $number = $DB->numrows($result);
        if (!empty($number)) {
            while ($data = $DB->fetch_assoc($result)) {
                $restrict = "`items_id` = '" . $data["id"] . "'\n               AND `itemtype` = 'User'";
                $links = getAllDatasFromTable("glpi_plugin_resources_resources_items", $restrict);
                if (!empty($links)) {
                    foreach ($links as $link) {
                        $employee = new PluginResourcesEmployee();
                        if ($employee->getFromDBbyResources($link["plugin_resources_resources_id"])) {
                            $matricule = $employee->fields["matricule"];
                            if (isset($matricule) && !empty($matricule)) {
                                $query = "UPDATE `glpi_users`\n                           SET `registration_number` = '" . $matricule . "'\n                           WHERE `id` ='" . $link["items_id"] . "'";
                                $DB->query($query);
                            }
                        }
                    }
                }
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_employees`\n               DROP `matricule` ;";
        $result = $DB->query($query);
    }
    $rep_files_resources = GLPI_PLUGIN_DOC_DIR . "/resources";
    if (!is_dir($rep_files_resources)) {
        mkdir($rep_files_resources);
    }
    CronTask::Register('PluginResourcesResource', 'Resources', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesTask', 'ResourcesTask', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesChecklist', 'ResourcesChecklist', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesEmployment', 'ResourcesLeaving', DAY_TIMESTAMP, array('state' => CronTask::STATE_DISABLE));
    PluginResourcesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}