/**
  * Show resource associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated resource must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_resources_haveRight('resources', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginResourcesResource');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_resources_resources_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_resources_resources`.`name` AS assocName,\n                       `glpi_plugin_resources_resources`.*\n                FROM `glpi_plugin_resources_resources_items`\n                LEFT JOIN `glpi_plugin_resources_resources`\n                 ON (`glpi_plugin_resources_resources_items`.`plugin_resources_resources_id`=`glpi_plugin_resources_resources`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_resources_resources`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_resources_resources_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_resources_resources_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_resources_resources", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $resources = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $resources[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     $resource = new PluginResourcesResource();
     $more = true;
     if ($item->getType() == "User" && $number != 0) {
         $more = false;
     }
     if ($canedit && $withtemplate < 2 && $more) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_resources_resources", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_resources_resources`\n               WHERE `is_deleted` = '0'\n               AND `is_template` = '0' ";
         if ($item->getType() != 'User') {
             $q .= " {$limit}";
         }
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_resources_haveRight('resources', 'r') && $nb > count($used)) {
             echo "<form name='resource_form{$rand}' id='resource_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginResourcesResource') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             PluginResourcesResource::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . __s('Associate a resource', 'resources') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('First name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . PluginResourcesContractType::getTypeName(1) . "</th>";
     echo "<th>" . PluginResourcesDepartment::getTypeName(1) . "</th>";
     echo "<th>" . __('Arrival date', 'resources') . "</th>";
     echo "<th>" . __('Departure date', 'resources') . "</th>";
     echo "</tr>";
     $used = array();
     $resourceID = 0;
     if ($number) {
         Session::initNavigateListItems('PluginResourcesResource', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($resources as $data) {
             $resourceID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($resource->getFromDB($resourceID)) {
                 $link = $resource->getLink();
             }
             Session::addToNavigateListItems('PluginResourcesResource', $resourceID);
             $used[$resourceID] = $resourceID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             echo "<td class='center'>" . $data['firstname'] . "</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_locations", $data["locations_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_resources_contracttypes", $data["plugin_resources_contracttypes_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_resources_departments", $data["plugin_resources_departments_id"]);
             echo "</td>";
             echo "<td class='center'>" . Html::convDate($data["date_begin"]) . "</td>";
             if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) {
                 echo "<td class='center'>";
                 echo "<span class='plugin_resources_date_color'>";
                 echo Html::convDate($data["date_end"]);
                 echo "</span>";
                 echo "</td>";
             } else {
                 if (empty($data["date_end"])) {
                     echo "<td class='center'>" . __('Not defined', 'resources') . "</td>";
                 } else {
                     echo "<td class='center'>" . Html::convDate($data["date_end"]) . "</td>";
                 }
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
     if ($item->getType() == "User") {
         $PluginResourcesEmployee = new PluginResourcesEmployee();
         $PluginResourcesEmployee->showForm($resourceID, $ID, 0);
     }
 }
Example #2
0
This file is part of Resources.

Resources is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Resources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Resources. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
//from helpdesk
Html::helpHeader(PluginResourcesResource::getTypeName(2));
$employee = new PluginResourcesEmployee();
//add employee informations from helpdesk
//next step : show list needs of the new ressource
if (isset($_POST["add_helpdesk_employee"])) {
    $newID = $employee->add($_POST);
    Html::redirect("./resource_item.list.php?id=" . $_POST["plugin_resources_resources_id"] . "&exist=0");
} else {
    //show form employee informations from helpdesk
    $employee->showFormHelpdesk($_GET["id"], 0);
}
Html::helpFooter();
Example #3
0
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Resources is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Resources. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
$resource = new PluginResourcesResource();
$employee = new PluginResourcesEmployee();
$choice = new PluginResourcesChoice();
$resource->checkGlobal("r");
if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
    //from central
    Html::header(PluginResourcesResource::getTypeName(2), '', "plugins", "resources");
} else {
    //from helpdesk
    Html::helpHeader(PluginResourcesResource::getTypeName(2));
}
if (isset($_POST["first_step"]) || isset($_GET["first_step"])) {
    if (!isset($_POST["template"])) {
        $_POST["template"] = $_GET["template"];
    }
    if (!isset($_POST["withtemplate"])) {
        $_POST["withtemplate"] = $_GET["withtemplate"];
Example #4
0
You should have received a copy of the GNU General Public License
along with Resources. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (!isset($_GET["withtemplate"])) {
    $_GET["withtemplate"] = "";
}
$resource = new PluginResourcesResource();
$checklist = new PluginResourcesChecklist();
$checklistconfig = new PluginResourcesChecklistconfig();
$employee = new PluginResourcesEmployee();
$choice = new PluginResourcesChoice();
$resource_item = new PluginResourcesResource_Item();
$cat = new PluginResourcesTicketCategory();
$task = new PluginResourcesTask();
/////////////////////////////////resource from helpdesk///////////////////////////////
if (isset($_POST["resend"])) {
    $resource->reSendResourceCreation($_POST);
    $resource->redirectToList();
    //from helpdesk
    //add items needs of a resource
} else {
    if (isset($_POST["addhelpdeskitem"])) {
        if ($_POST['plugin_resources_choiceitems_id'] > 0 && $_POST['plugin_resources_resources_id'] > 0) {
            if ($resource->canCreate()) {
                $choice->addHelpdeskItem($_POST);
Example #5
0
 function showForm($ID, $options = array())
 {
     if (!Session::haveRight("profile", "r")) {
         return false;
     }
     $prof = new Profile();
     if ($ID) {
         $this->getFromDBByProfile($ID);
         $prof->getFromDB($ID);
     }
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_2'>";
     echo "<th colspan='4'>" . sprintf(__('%1$s - %2$s'), __('Rights management', 'resources'), $prof->fields["name"]) . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . PluginResourcesResource::getTypeName(2) . "</td><td>";
     Profile::dropdownNoneReadWrite("resources", $this->fields["resources"], 1, 1, 1);
     echo "</td>";
     echo "<td>" . PluginResourcesTask::getTypeName(2) . "</td><td>";
     if ($prof->fields['interface'] != 'helpdesk') {
         Profile::dropdownNoneReadWrite("task", $this->fields["task"], 1, 1, 1);
     } else {
         _e('No access');
         // No access;
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . PluginResourcesChecklist::getTypeName(2) . "</td><td>";
     if ($prof->fields['interface'] != 'helpdesk') {
         Profile::dropdownNoneReadWrite("checklist", $this->fields["checklist"], 1, 1, 1);
     } else {
         _e('No access');
         // No access;
     }
     echo "</td>";
     echo "<td>" . PluginResourcesEmployee::getTypeName(2) . "</td><td>";
     Profile::dropdownNoneReadWrite("employee", $this->fields["employee"], 1, 1, 1);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('All resources access', 'resources') . "</td><td>";
     Profile::dropdownNoneReadWrite("all", $this->fields["all"], 1, 0, 1);
     echo "</td>";
     echo "<td>" . __('Associable items to a ticket') . " - " . PluginResourcesResource::getTypeName(2) . "</td><td>";
     if ($prof->fields['create_ticket']) {
         Dropdown::showYesNo("open_ticket", $this->fields["open_ticket"]);
     } else {
         echo Dropdown::getYesNo(0);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<th colspan='4' class='center b'>" . __('Service company management', 'resources') . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . PluginResourcesResourceResting::getTypeName(2) . "</td><td>";
     Profile::dropdownNoneReadWrite("resting", $this->fields["resting"], 1, 0, 1);
     echo "</td>";
     echo "<td>" . PluginResourcesResourceHoliday::getTypeName(2) . "</td><td>";
     Profile::dropdownNoneReadWrite("holiday", $this->fields["holiday"], 1, 0, 1);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<th colspan='4' class='center b'>" . __('Public service management', 'resources') . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . PluginResourcesEmployment::getTypeName(2) . "</td><td>";
     Profile::dropdownNoneReadWrite("employment", $this->fields["employment"], 1, 1, 1);
     echo "</td>";
     echo "<td>" . PluginResourcesBudget::getTypeName(2) . ":</td><td>";
     Profile::dropdownNoneReadWrite("budget", $this->fields["budget"], 1, 1, 1);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Dropdown management', 'resources') . "</td><td>";
     Profile::dropdownNoneReadWrite("dropdown_public", $this->fields["dropdown_public"], 1, 1, 1);
     echo "</td><td></td><td></td>";
     echo "</tr>";
     echo "<input type='hidden' name='id' value=" . $this->fields["id"] . ">";
     $options['candel'] = false;
     $this->showFormButtons($options);
 }
Example #6
0
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     $resource_item = new PluginResourcesResource_Item();
     switch ($input['action']) {
         case "Transfert":
             if ($input['itemtype'] == 'PluginResourcesResource') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $this->getFromDB($key);
                         $contracttype = PluginResourcesContractType::transfer($PluginResourcesResource->fields["plugin_resources_contracttypes_id"], $input['entities_id']);
                         if ($contracttype > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_contracttypes_id"] = $contracttype;
                             $this->update($values);
                         }
                         unset($values);
                         $resourcestate = PluginResourcesResourceState::transfer($PluginResourcesResource->fields["plugin_resources_resourcestates_id"], $input['entities_id']);
                         if ($resourcestate > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_resourcestates_id"] = $resourcestate;
                             $this->update($values);
                         }
                         unset($values);
                         $department = PluginResourcesDepartment::transfer($PluginResourcesResource->fields["plugin_resources_departments_id"], $input['entities_id']);
                         if ($department > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_departments_id"] = $department;
                             $this->update($values);
                         }
                         unset($values);
                         $situation = PluginResourcesResourceSituation::transfer($PluginResourcesResource->fields["plugin_resources_resourcesituations_id"], $input['entities_id']);
                         if ($situation > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_resourcesituations_id"] = $situation;
                             $this->update($values);
                         }
                         unset($values);
                         $contractnature = PluginResourcesContractNature::transfer($PluginResourcesResource->fields["plugin_resources_contractnatures_id"], $input['entities_id']);
                         if ($contractnature > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_contractnatures_id"] = $contractnature;
                             $this->update($values);
                         }
                         unset($values);
                         $rank = PluginResourcesRank::transfer($PluginResourcesResource->fields["plugin_resources_ranks_id"], $input['entities_id']);
                         if ($rank > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_ranks_id"] = $rank;
                             $this->update($values);
                         }
                         unset($values);
                         $speciality = PluginResourcesResourceSpeciality::transfer($PluginResourcesResource->fields["plugin_resources_resourcespecialities_id"], $input['entities_id']);
                         if ($speciality > 0) {
                             $values["id"] = $key;
                             $values["plugin_resources_resourcespecialities_id"] = $speciality;
                             $this->update($values);
                         }
                         unset($values);
                         $PluginResourcesTask = new PluginResourcesTask();
                         $restrict = "`plugin_resources_resources_id` = '" . $key . "'";
                         $tasks = getAllDatasFromTable("glpi_plugin_resources_tasks", $restrict);
                         if (!empty($tasks)) {
                             foreach ($tasks as $task) {
                                 $PluginResourcesTask->getFromDB($task["id"]);
                                 $tasktype = PluginResourcesTaskType::transfer($PluginResourcesTask->fields["plugin_resources_tasktypes_id"], $input['entities_id']);
                                 if ($tasktype > 0) {
                                     $values["id"] = $task["id"];
                                     $values["plugin_resources_tasktypes_id"] = $tasktype;
                                     $PluginResourcesTask->update($values);
                                 }
                                 $values["id"] = $task["id"];
                                 $values["entities_id"] = $input['entities_id'];
                                 $PluginResourcesTask->update($values);
                             }
                         }
                         unset($values);
                         $PluginResourcesEmployment = new PluginResourcesEmployment();
                         $restrict = "`plugin_resources_resources_id` = '" . $key . "'";
                         $employments = getAllDatasFromTable("glpi_plugin_resources_employments", $restrict);
                         if (!empty($employments)) {
                             foreach ($employments as $employment) {
                                 $PluginResourcesEmployment->getFromDB($employment["id"]);
                                 $rank = PluginResourcesRank::transfer($PluginResourcesEmployment->fields["plugin_resources_ranks_id"], $input['entities_id']);
                                 if ($rank > 0) {
                                     $values["id"] = $employment["id"];
                                     $values["plugin_resources_ranks_id"] = $rank;
                                     $PluginResourcesEmployment->update($values);
                                 }
                                 $PluginResourcesEmployment->getFromDB($employment["id"]);
                                 $profession = PluginResourcesProfession::transfer($PluginResourcesEmployment->fields["plugin_resources_professions_id"], $input['entities_id']);
                                 if ($profession > 0) {
                                     $values["id"] = $employment["id"];
                                     $values["plugin_resources_professions_id"] = $profession;
                                     $PluginResourcesEmployment->update($values);
                                 }
                                 $values["id"] = $employment["id"];
                                 $values["entities_id"] = $input['entities_id'];
                                 $PluginResourcesEmployment->update($values);
                             }
                         }
                         unset($values);
                         $PluginResourcesEmployee = new PluginResourcesEmployee();
                         $restrict = "`plugin_resources_resources_id` = '" . $key . "'";
                         $employees = getAllDatasFromTable("glpi_plugin_resources_employees", $restrict);
                         if (!empty($employees)) {
                             foreach ($employees as $employee) {
                                 $employer = PluginResourcesEmployer::transfer($employee["plugin_resources_employers_id"], $input['entities_id']);
                                 if ($employer > 0) {
                                     $values["id"] = $employee["id"];
                                     $values["plugin_resources_employers_id"] = $employer;
                                     $PluginResourcesEmployee->update($values);
                                 }
                                 $client = PluginResourcesClient::transfer($employee["plugin_resources_clients_id"], $input['entities_id']);
                                 if ($client > 0) {
                                     $values["id"] = $employee["id"];
                                     $values["plugin_resources_clients_id"] = $client;
                                     $PluginResourcesEmployee->update($values);
                                 }
                             }
                         }
                         unset($values);
                         $query = "UPDATE `glpi_plugin_resources_checklists`\n                        SET `entities_id` = '" . $input['entities_id'] . "'\n                        WHERE `plugin_resources_resources_id` ='{$key}'";
                         $DB->query($query);
                         $values["id"] = $key;
                         $values["entities_id"] = $input['entities_id'];
                         if ($this->update($values)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "Install":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     $values = array('plugin_resources_resources_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($resource_item->add($values)) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         case "Desinstall":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($resource_item->deleteItemByResourcesAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         case "Send":
             if ($this->sendEmail($input)) {
                 $res['ok']++;
             } else {
                 $res['ko']++;
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
             break;
     }
     return $res;
 }
Example #7
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                        '&lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.url##\n                        &lt;/strong&gt; :\n                        &lt;a href=\"##resource.url##\"&gt;##resource.url##\n                        &lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.entity##&lt;/strong&gt; : ##resource.entity##\n                        &lt;/span&gt; &lt;br /&gt; ##IFresource.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##resource.name##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.name## ##IFresource.firstname##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##resource.firstname##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.firstname## ##IFresource.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.type##&lt;/strong&gt; :  ##resource.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.type## ##IFresource.status##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.status##&lt;/strong&gt; :  ##resource.status##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.status## ##IFresource.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.users##&lt;/strong&gt; :  ##resource.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.users## ##IFresource.usersrecipient##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersrecipient##\n                        &lt;/strong&gt; :  ##resource.usersrecipient##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.usersrecipient## ##IFresource.datedeclaration##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datedeclaration##\n                        &lt;/strong&gt; :  ##resource.datedeclaration##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.datedeclaration## ##IFresource.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datebegin##&lt;/strong&gt; :  ##resource.datebegin##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.datebegin## ##IFresource.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.dateend##&lt;/strong&gt; :  ##resource.dateend##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.dateend## ##IFresource.department##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.department##&lt;/strong&gt; :  ##resource.department##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.department## ##IFresource.location##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.location##&lt;/strong&gt; :  ##resource.location##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.location## ##IFresource.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.comment##&lt;/strong&gt; :  ##resource.comment##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.comment## ##IFresource.usersleaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersleaving##&lt;/strong&gt; :  ##resource.usersleaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.usersleaving## ##IFresource.leaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.leaving##&lt;/strong&gt; :  ##resource.leaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.leaving## ##IFresource.helpdesk##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.helpdesk##&lt;/strong&gt; :  ##resource.helpdesk##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.helpdesk##   ##FOREACHupdates##----------\n                        &lt;br /&gt;\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.update.title## :&lt;/strong&gt;&lt;/span&gt;\n                        &lt;br /&gt; ##IFupdate.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##update.name##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.name## ##IFupdate.firstname##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##update.firstname##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.firstname## ##IFupdate.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.type##&lt;/strong&gt; : ##update.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.type## ##IFupdate.status##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.status##&lt;/strong&gt; : ##update.status##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.status## ##IFupdate.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.users##&lt;/strong&gt; : ##update.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.users## ##IFupdate.usersrecipient##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersrecipient##&lt;/strong&gt; : ##update.usersrecipient##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.usersrecipient## ##IFupdate.datedeclaration##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datedeclaration##\n                        &lt;/strong&gt; : ##update.datedeclaration##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.datedeclaration## ##IFupdate.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datebegin##&lt;/strong&gt; : ##update.datebegin##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.datebegin## ##IFupdate.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.dateend##&lt;/strong&gt; : ##update.dateend##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.dateend## ##IFupdate.department##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.department##&lt;/strong&gt; : ##update.department##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.department## ##IFupdate.location##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.location##&lt;/strong&gt; : ##update.location##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.location## ##IFupdate.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.comment##&lt;/strong&gt; : ##update.comment##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.comment## ##IFupdate.usersleaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersleaving##\n                        &lt;/strong&gt; : ##update.usersleaving##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.usersleaving## ##IFupdate.leaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.leaving##&lt;/strong&gt; : ##update.leaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.leaving## ##IFupdate.helpdesk##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.helpdesk##&lt;/strong&gt; : ##update.helpdesk##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.helpdesk####ENDFOREACHupdates##   ##FOREACHtasks##----------\n                        &lt;br /&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.title## :&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt; ##IFtask.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.name##&lt;/strong&gt; : ##task.name##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.name## ##IFtask.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.type##&lt;/strong&gt; : ##task.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.type## ##IFtask.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.users##&lt;/strong&gt; : ##task.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.users## ##IFtask.groups##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.groups##&lt;/strong&gt; : ##task.groups##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.groups## ##IFtask.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.datebegin##&lt;/strong&gt; : ##task.datebegin##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.datebegin## ##IFtask.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.dateend##&lt;/strong&gt; : ##task.dateend##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.dateend## ##IFtask.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.comment##&lt;/strong&gt; : ##task.comment##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.comment## ##IFtask.finished##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.finished##&lt;/strong&gt; : ##task.finished##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.finished## ##IFtask.realtime##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.realtime##&lt;/strong&gt; : ##task.realtime##\n                        &lt;/span&gt;##ENDIFtask.realtime##&lt;br /&gt;----------##ENDFOREACHtasks##&lt;/p&gt;');";
        $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                           '&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;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.groups##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.comment##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.resource##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHtasks##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.groups##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.comment##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.resource##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHtasks##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $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                           '&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;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHresources##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##resource.url##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHresources##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $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                           '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr bgcolor=\"#d9c4b8\"&gt;\n   &lt;th colspan=\"7\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: center;\"&gt;##lang.checklist.title##&lt;/span&gt;&lt;/th&gt;\n   &lt;/tr&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.name## ##lang.checklist.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.entity##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.title2##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHchecklists##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##checklist.url##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.name## ##checklist.firstname##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.entity##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;table width=\"100%\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt; ##tasklist.name## &lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   &lt;/tbody&gt;\n   &lt;/table&gt;\n   &lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHchecklists##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $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                        '&lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.resource.title2##&lt;/strong&gt;\n   &lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.url##&lt;/strong&gt; :\n   &lt;a href=\"##resource.url##\"&gt;##resource.url##&lt;/a&gt;\n   &lt;/span&gt; &lt;br /&gt;&lt;br /&gt;\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.entity##&lt;/strong&gt; : ##resource.entity##&lt;/span&gt;\n   &lt;br /&gt; ##IFresource.name##\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##resource.name##&lt;br /&gt;\n   &lt;/span&gt;##ENDIFresource.name## ##IFresource.firstname##\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##resource.firstname##\n   &lt;br /&gt;&lt;/span&gt;##ENDIFresource.firstname##&lt;/p&gt;\n   &lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.resource.badge##&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;\n   &lt;/span&gt;&lt;/p&gt;');";
        $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                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.creationtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"2\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" colspan=\"2\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.usersrecipient##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.usersrecipient##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datedeclaration##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datedeclaration##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.creation##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&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-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datecreation##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datecreation##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.login##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.login##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.email##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.email##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.informationtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFresource.commentaires##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFresource.commentaires## ##IFresource.informations##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.informations##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.informations##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFresource.informations##\n&lt;/tbody&gt;\n&lt;/table&gt;');";
        $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                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.restingtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&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-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.resting##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&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-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.home##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.home##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##FOREACHupdates##&lt;/p&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.update.title##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFupdate.datebegin##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin## : ##update.datebegin##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.datebegin## ##IFupdate.dateend##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend## : ##update.dateend##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.dateend## ##IFupdate.location##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location## : ##update.location##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.location## ##IFupdate.home##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.home## : ##update.home##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.home## ##IFupdate.comment##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.comment## : ##update.comment##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.comment##\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##ENDFOREACHupdates##&lt;/p&gt;');";
        $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                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.holidaytitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&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-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.holiday##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&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-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##FOREACHupdates##&lt;/p&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.update.title##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFupdate.datebegin##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin## : ##update.datebegin##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.datebegin## ##IFupdate.dateend##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend## : ##update.dateend##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.dateend## ##IFupdate.comment##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.comment## : ##update.comment##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.comment##\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##ENDFOREACHupdates##&lt;/p&gt;');";
        $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;
}