static function uninstall() { global $DB; $displayPreference = new DisplayPreference(); $displayPreference->deleteByCriteria(array('itemtype' => __CLASS__)); // Remove dropdowns localization $dropdownTranslation = new DropdownTranslation(); $dropdownTranslation->deleteByCriteria(array("itemtype = 'PluginSimcardSimcardSize'"), 1); $table = getTableForItemType(__CLASS__); $DB->query("DROP TABLE IF EXISTS `{$table}`"); }
static function uninstall() { global $DB; foreach (array('DisplayPreference', 'Bookmark') as $itemtype) { $item = new $itemtype(); $item->deleteByCriteria(array('itemtype' => __CLASS__)); } // Remove dropdowns localization $dropdownTranslation = new DropdownTranslation(); $dropdownTranslation->deleteByCriteria(array("itemtype = 'PluginSimcardSimcardType'"), 1); $table = getTableForItemType(__CLASS__); $DB->query("DROP TABLE IF EXISTS `{$table}`"); }
/** * @covers NotificationTargetTicket::getTags * @covers NotificationTargetCommonITILObject::getTags * @covers NotificationTargetTicket::getDatasForObject * @covers NotificationTargetCommonITILObject::getDatasForObject */ public function testgetDatasForObject() { global $CFG_GLPI; $tkt = getItemByTypeName('Ticket', '_ticket01'); $notiftargetticket = new NotificationTargetTicket(getItemByTypeName('Entity', '_test_root_entity', true), 'new', $tkt); $notiftargetticket->getTags(); // basic test for ##task.categorycomment## tag $expected = ['tag' => 'task.categorycomment', 'value' => true, 'label' => 'Category comment', 'events' => 0, 'foreach' => false, 'lang' => true, 'allowed_values' => []]; $this->assertEquals($expected, $notiftargetticket->tag_descriptions['lang']['##lang.task.categorycomment##']); $this->assertEquals($expected, $notiftargetticket->tag_descriptions['tag']['##task.categorycomment##']); // basic test for ##task.categorid## tag $expected = ['tag' => 'task.categoryid', 'value' => true, 'label' => 'Category id', 'events' => 0, 'foreach' => false, 'lang' => true, 'allowed_values' => []]; $this->assertEquals($expected, $notiftargetticket->tag_descriptions['lang']['##lang.task.categoryid##']); $this->assertEquals($expected, $notiftargetticket->tag_descriptions['tag']['##task.categoryid##']); // advanced test for ##task.categorycomment## and ##task.categoryid## tags // test of the getDatasForObject for default language en_US $taskcat = getItemByTypeName('TaskCategory', '_subcat_1'); $expected = [['##task.id##' => 1, '##task.isprivate##' => 'No', '##task.author##' => '_test_user', '##task.categoryid##' => $taskcat->getID(), '##task.category##' => '_cat_1 > _subcat_1', '##task.categorycomment##' => 'Comment for sub-category _subcat_1', '##task.date##' => '2016-10-19 11:50', '##task.description##' => 'Task to be done', '##task.time##' => '0 seconds', '##task.status##' => 'To do', '##task.user##' => '_test_user', '##task.group##' => '', '##task.begin##' => '', '##task.end##' => '']]; $ret = $notiftargetticket->getDatasForObject($tkt, array()); $this->assertEquals($expected, $ret['tasks']); // test of the getDatasForObject for default language fr_FR $CFG_GLPI['translate_dropdowns'] = 1; $_SESSION["glpilanguage"] = Session::loadLanguage('fr_FR'); $_SESSION['glpi_dropdowntranslations'] = DropdownTranslation::getAvailableTranslations($_SESSION["glpilanguage"]); $ret = $notiftargetticket->getDatasForObject($tkt, array()); $expected = [['##task.id##' => 1, '##task.isprivate##' => 'Non', '##task.author##' => '_test_user', '##task.categoryid##' => $taskcat->getID(), '##task.category##' => 'FR - _cat_1 > FR - _subcat_1', '##task.categorycomment##' => 'FR - Commentaire pour sous-catégorie _subcat_1', '##task.date##' => '2016-10-19 11:50', '##task.description##' => 'Task to be done', '##task.time##' => '0 seconde', '##task.status##' => 'A faire', '##task.user##' => '_test_user', '##task.group##' => '', '##task.begin##' => '', '##task.end##' => '']]; $this->assertEquals($expected, $ret['tasks']); // switch back to default language $_SESSION["glpilanguage"] = Session::loadLanguage('en_US'); }
// Last parent is not the good one need to display arbo if (!isset($last_level_displayed[$level - 1]) || $last_level_displayed[$level - 1] != $data[$item->getForeignKeyField()]) { $work_level = $level - 1; $work_parentID = $data[$item->getForeignKeyField()]; $parent_datas = array(); do { // Get parent if ($item->getFromDB($work_parentID)) { // Do not do for first item for next page load if (!$firstitem) { $title = $item->fields['completename']; if (isset($item->fields["comment"])) { $addcomment = DropdownTranslation::getTranslatedValue($ID, $_POST['itemtype'], 'comment', $_SESSION['glpilanguage'], $item->fields['comment']); $title = sprintf(__('%1$s - %2$s'), $title, $addcomment); } $output2 = DropdownTranslation::getTranslatedValue($item->fields['id'], $_POST['itemtype'], 'name', $_SESSION['glpilanguage'], $item->fields['name']); // $output2 = $item->getName(); $temp = array('id' => $ID, 'text' => $output2, 'level' => $work_level, 'disabled' => true); if ($_POST['permit_select_parent']) { unset($temp['disabled']); } array_unshift($parent_datas, $temp); } $last_level_displayed[$work_level] = $item->fields['id']; $work_level--; $work_parentID = $item->fields[$item->getForeignKeyField()]; } else { // Error getting item : stop $work_level = -1; } } while ($work_level >= 1 && (!isset($last_level_displayed[$work_level]) || $last_level_displayed[$work_level] != $work_parentID));
/** * Regenerate all completename translations for an item * * @param $itemtype itemtype * @param $items_id item ID * * @return the value translated if a translation is available, or the same value if not **/ static function regenerateAllCompletenameTranslationsFor($itemtype, $items_id) { foreach (self::getTranslationsForAnItem($itemtype, $items_id, 'completename') as $data) { $dt = new DropdownTranslation(); $dt->generateCompletename($data, false); } }
/** * @param $target NotificationTarget object * @param $user_infos array * @param $event * @param $options array * * @return id of the template in templates_by_languages / false if computation failed **/ function getTemplateByLanguage(NotificationTarget $target, $user_infos = array(), $event, $options = array()) { $lang = array(); $language = $user_infos['language']; if (isset($user_infos['additionnaloption'])) { $additionnaloption = $user_infos['additionnaloption']; } else { $additionnaloption = array(); } $tid = $language; $tid .= serialize($additionnaloption); $tid = sha1($tid); if (!isset($this->templates_by_languages[$tid])) { //Switch to the desired language $bak_dropdowntranslations = $_SESSION['glpi_dropdowntranslations']; $_SESSION['glpi_dropdowntranslations'] = DropdownTranslation::getAvailableTranslations($language); Session::loadLanguage($language); $bak_language = $_SESSION["glpilanguage"]; $_SESSION["glpilanguage"] = $language; //If event is raised by a plugin, load it in order to get the language file available if ($plug = isPluginItemType(get_class($target->obj))) { Plugin::loadLang(strtolower($plug['plugin']), $language); } //Get template's language data for in this language $options['additionnaloption'] = $additionnaloption; $data =& $target->getForTemplate($event, $options); $footer_string = Html::entity_decode_deep(sprintf(__('Automatically generated by GLPI %s'), GLPI_VERSION)); $add_header = Html::entity_decode_deep($target->getContentHeader()); $add_footer = Html::entity_decode_deep($target->getContentFooter()); //Restore default language $_SESSION["glpilanguage"] = $bak_language; Session::loadLanguage(); $_SESSION['glpi_dropdowntranslations'] = $bak_dropdowntranslations; if ($plug = isPluginItemType(get_class($target->obj))) { Plugin::loadLang(strtolower($plug['plugin'])); } if ($template_datas = $this->getByLanguage($language)) { //Template processing // Decode html chars to have clean text $template_datas['content_text'] = Html::entity_decode_deep($template_datas['content_text']); $save_data = $data; $data = Html::entity_decode_deep($data); $template_datas['subject'] = Html::entity_decode_deep($template_datas['subject']); $this->signature = Html::entity_decode_deep($this->signature); $lang['subject'] = $target->getSubjectPrefix($event) . self::process($template_datas['subject'], $data); $lang['content_html'] = ''; //If no html content, then send only in text if (!empty($template_datas['content_html'])) { // Encode in HTML all chars $data_html = Html::entities_deep($data); $data_html = Html::nl2br_deep($data_html); // Restore HTML tags if (count($target->html_tags)) { foreach ($target->html_tags as $tag) { if (isset($save_data[$tag])) { $data_html[$tag] = $save_data[$tag]; } } } $signature_html = Html::entities_deep($this->signature); $signature_html = Html::nl2br_deep($signature_html); $template_datas['content_html'] = self::process($template_datas['content_html'], $data_html); $lang['content_html'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>" . "<html>\n <head>\n <META http-equiv='Content-Type' content='text/html; charset=utf-8'>\n <title>" . Html::entities_deep($lang['subject']) . "</title>\n <style type='text/css'>\n " . $this->fields['css'] . "\n </style>\n </head>\n <body>\n" . (!empty($add_header) ? $add_header . "\n<br><br>" : '') . $template_datas['content_html'] . "<br><br>-- \n<br>" . $signature_html . "<br>{$footer_string}" . "<br><br>\n" . (!empty($add_footer) ? $add_footer . "\n<br><br>" : '') . "\n</body></html>"; } $lang['content_text'] = (!empty($add_header) ? $add_header . "\n\n" : '') . Html::clean(self::process($template_datas['content_text'], $data) . "\n\n-- \n" . $this->signature . "\n" . Html::entity_decode_deep(sprintf(__('Automatically generated by GLPI %s'), GLPI_VERSION))) . "\n\n" . $add_footer; $this->templates_by_languages[$tid] = $lang; } } if (isset($this->templates_by_languages[$tid])) { return $tid; } return false; }
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. GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief * @since version 0.85 **/ include '../inc/includes.php'; $translation = new DropdownTranslation(); if (isset($_POST['add'])) { $translation->add($_POST); } else { if (isset($_POST['update'])) { $translation->update($_POST); } else { if (isset($_POST['purge'])) { $translation->delete($_POST, 1); } } } Html::back();
/** * @param $ID * @param $updateName * @param $changeParent **/ function regenerateTreeUnderID($ID, $updateName, $changeParent) { global $DB; if ($updateName || $changeParent) { $currentNode = clone $this; if ($currentNode->getFromDB($ID)) { $currentNodeCompleteName = $currentNode->getField("completename"); $nextNodeLevel = $currentNode->getField("level") + 1; } else { $nextNodeLevel = 1; } $query = "SELECT `id`, `name`\n FROM `" . $this->getTable() . "`\n WHERE `" . $this->getForeignKeyField() . "` = '{$ID}'"; if (Session::haveTranslations($this->getType(), 'completename')) { DropdownTranslation::regenerateAllCompletenameTranslationsFor($this->getType(), $ID); } foreach ($DB->request($query) as $data) { $query = "UPDATE `" . $this->getTable() . "`\n SET "; $fieldsToUpdate = array(); if ($updateName || $changeParent) { if (isset($currentNodeCompleteName)) { $fieldsToUpdate[] = "`completename`='" . self::getCompleteNameFromParents($currentNodeCompleteName, addslashes($data["name"])) . "'"; } else { $fieldsToUpdate[] = "`completename`='" . addslashes($data["name"]) . "'"; } } if ($changeParent) { // We have to reset the ancestors as only these changes (ie : not the children). $fieldsToUpdate[] = "`ancestors_cache` = NULL"; // And we must update the level of the current node ... $fieldsToUpdate[] = "`level` = '{$nextNodeLevel}'"; } $query .= implode(', ', $fieldsToUpdate) . " WHERE `id`= '" . $data["id"] . "'"; $DB->query($query); // Translations : if (Session::haveTranslations($this->getType(), 'completename')) { DropdownTranslation::regenerateAllCompletenameTranslationsFor($this->getType(), $data['id']); } $this->regenerateTreeUnderID($data["id"], $updateName, $changeParent); } } }
// Need to check if parent is the good one // Do not do if only get one item if ($level > 1 && $one_item < 0) { // Last parent is not the good one need to display arbo if (!isset($last_level_displayed[$level - 1]) || $last_level_displayed[$level - 1] != $data[$item->getForeignKeyField()]) { $work_level = $level - 1; $work_parentID = $data[$item->getForeignKeyField()]; $to_display = ''; do { // Get parent if ($item->getFromDB($work_parentID)) { // Do not do for first item for next page load if (!$firstitem) { $title = $item->fields['completename']; if (isset($item->fields["comment"])) { $addcomment = DropdownTranslation::getTranslatedValue($ID, $_GET['itemtype'], 'comment', $_SESSION['glpilanguage'], $item->fields['comment']); $title = sprintf(__('%1$s - %2$s'), $title, $addcomment); } $output2 = $item->getName(); $temp = array('id' => $ID, 'text' => $output2, 'level' => $work_level, 'disabled' => true); if ($_GET['permit_select_parent']) { unset($temp['disabled']); } array_push($datastoadd, $temp); } $last_level_displayed[$work_level] = $item->fields['id']; $work_level--; $work_parentID = $item->fields[$item->getForeignKeyField()]; } else { // Error getting item : stop $work_level = -1;
function defineTabs($options = array()) { $ong = array(); $this->addDefaultFormTab($ong); if ($this->dohistory) { $this->addStandardTab('Log', $ong, $options); } if (DropdownTranslation::canBeTranslated($this)) { $this->addStandardTab('DropdownTranslation', $ong, $options); } return $ong; }
/** * Clean translations associated to a dropdown * * @since version 0.85 **/ function cleanTranslations() { //Do not try to clean is dropdown translation is globally off if (DropdownTranslation::isDropdownTranslationActive()) { $translation = new DropdownTranslation(); $translation->deleteByCriteria(array('itemtype' => get_class($this), 'items_id' => $this->getID())); } }
This file is part of GLPI. GLPI 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. GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief * @since version 0.85 **/ $AJAX_INCLUDE = 1; include '../inc/includes.php'; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); Session::checkRight("dropdown", UPDATE); if (isset($_POST['itemtype']) && isset($_POST['language'])) { $item = new $_POST['itemtype'](); $item->getFromDB($_POST['items_id']); DropdownTranslation::dropdownFields($item, $_POST['language']); }
/** * @covers Dropdown::getDropdownName * @covers ::getTreeValueCompleteName */ public function testGetDropdownName() { global $CFG_GLPI; $cat = getItemByTypeName('TaskCategory', '_cat_1'); $subCat = getItemByTypeName('TaskCategory', '_subcat_1'); // basic test returns string only $expected = $cat->fields['name'] . " > " . $subCat->fields['name']; $ret = Dropdown::getDropdownName('glpi_taskcategories', $subCat->getID()); $this->assertEquals($expected, $ret); // test of return with comments $expected = array('name' => $cat->fields['name'] . " > " . $subCat->fields['name'], 'comment' => "<span class='b'>Complete name</span>: " . $cat->fields['name'] . " > " . $subCat->fields['name'] . "<br><span class='b'> Comments </span>" . $subCat->fields['comment']); $ret = Dropdown::getDropdownName('glpi_taskcategories', $subCat->getID(), true); $this->assertEquals($expected, $ret); // test of return without $tooltip $expected = array('name' => $cat->fields['name'] . " > " . $subCat->fields['name'], 'comment' => $subCat->fields['comment']); $ret = Dropdown::getDropdownName('glpi_taskcategories', $subCat->getID(), true, true, false); $this->assertEquals($expected, $ret); // test of return with translations $CFG_GLPI['translate_dropdowns'] = 1; $_SESSION["glpilanguage"] = Session::loadLanguage('fr_FR'); $_SESSION['glpi_dropdowntranslations'] = DropdownTranslation::getAvailableTranslations($_SESSION["glpilanguage"]); $expected = array('name' => 'FR - _cat_1 > FR - _subcat_1', 'comment' => 'FR - Commentaire pour sous-catégorie _subcat_1'); $ret = Dropdown::getDropdownName('glpi_taskcategories', $subCat->getID(), true, true, false); $this->assertEquals($expected, $ret); // switch back to default language $_SESSION["glpilanguage"] = Session::loadLanguage('en_US'); //////////////////////////////// // test for other dropdown types //////////////////////////////// /////////// // Computer $computer = getItemByTypeName('Computer', '_test_pc01'); $ret = Dropdown::getDropdownName('glpi_computers', $computer->getID()); $this->assertEquals($computer->getName(), $ret); $expected = array('name' => $computer->getName(), 'comment' => $computer->fields['comment']); $ret = Dropdown::getDropdownName('glpi_computers', $computer->getID(), true); $this->assertEquals($expected, $ret); ////////// // Contact $contact = getItemByTypeName('Contact', '_contact01_name'); $expected = $contact->getName(); $ret = Dropdown::getDropdownName('glpi_contacts', $contact->getID()); $this->assertEquals($expected, $ret); // test of return with comments $expected = array('name' => $contact->getName(), 'comment' => "Comment for contact _contact01_name<br><span class='b'>" . "Phone: </span>0123456789<br><span class='b'>Phone 2: </span>0123456788<br><span class='b'>" . "Mobile phone: </span>0623456789<br><span class='b'>Fax: </span>0123456787<br>" . "<span class='b'>Email: </span>_contact01_firstname._contact01_name@glpi.com"); $ret = Dropdown::getDropdownName('glpi_contacts', $contact->getID(), true); $this->assertEquals($expected, $ret); // test of return without $tooltip $expected = array('name' => $contact->getName(), 'comment' => $contact->fields['comment']); $ret = Dropdown::getDropdownName('glpi_contacts', $contact->getID(), true, true, false); $this->assertEquals($expected, $ret); /////////// // Supplier $supplier = getItemByTypeName('Supplier', '_suplier01_name'); $expected = $supplier->getName(); $ret = Dropdown::getDropdownName('glpi_suppliers', $supplier->getID()); $this->assertEquals($expected, $ret); // test of return with comments $expected = array('name' => $supplier->getName(), 'comment' => "Comment for supplier _suplier01_name<br><span class='b'>Phone: </span>0123456789<br>" . "<span class='b'>Fax: </span>0123456787<br><span class='b'>Email: </span>info@_supplier01_name.com"); $ret = Dropdown::getDropdownName('glpi_suppliers', $supplier->getID(), true); $this->assertEquals($expected, $ret); // test of return without $tooltip $expected = array('name' => $supplier->getName(), 'comment' => $supplier->fields['comment']); $ret = Dropdown::getDropdownName('glpi_suppliers', $supplier->getID(), true, true, false); $this->assertEquals($expected, $ret); /////////// // Netpoint $netpoint = getItemByTypeName('Netpoint', '_netpoint01'); $location = getItemByTypeName('Location', '_location01'); $expected = $netpoint->getName() . " (" . $location->getName() . ")"; $ret = Dropdown::getDropdownName('glpi_netpoints', $netpoint->getID()); $this->assertEquals($expected, $ret); // test of return with comments $expected = array('name' => $expected, 'comment' => "Comment for netpoint _netpoint01"); $ret = Dropdown::getDropdownName('glpi_netpoints', $netpoint->getID(), true); $this->assertEquals($expected, $ret); // test of return without $tooltip $ret = Dropdown::getDropdownName('glpi_netpoints', $netpoint->getID(), true, true, false); $this->assertEquals($expected, $ret); /////////// // Budget $budget = getItemByTypeName('Budget', '_budget01'); $expected = $budget->getName(); $ret = Dropdown::getDropdownName('glpi_budgets', $budget->getID()); $this->assertEquals($expected, $ret); // test of return with comments $expected = array('name' => $budget->getName(), 'comment' => "Comment for budget _budget01<br><span class='b'>Location</span>: " . "_location01<br><span class='b'>Type</span>: _budgettype01<br><span class='b'>" . "Start date</span>: 2016-10-18 <br><span class='b'>End date</span>: 2016-12-31 "); $ret = Dropdown::getDropdownName('glpi_budgets', $budget->getID(), true); $this->assertEquals($expected, $ret); // test of return without $tooltip $expected = array('name' => $budget->getName(), 'comment' => $budget->fields['comment']); $ret = Dropdown::getDropdownName('glpi_budgets', $budget->getID(), true, true, false); $this->assertEquals($expected, $ret); }
public function showResult($output_type, $limit = 0, $params = array()) { global $DB; $arrayRet = $this->execQuery($_REQUEST); $result = $arrayRet['query_result']; $query = $arrayRet['query']; $nbtot = $result ? $DB->numrows($result) : 0; if ($limit) { $start = isset($_REQUEST["start"]) ? $_REQUEST["start"] : 0; if ($start >= $nbtot) { $start = 0; } if ($start > 0 || $start + $limit < $nbtot) { $result = $DB->query($query . " LIMIT {$start},{$limit}"); } } else { $start = 0; } $nbCols = $DB->num_fields($result); $nbrows = $DB->numrows($result); $groupByRackName = true; if (isset($_REQUEST['groupByRackName']) && $_REQUEST['groupByRackName'] == "on") { $groupByRackName = false; } $title = date("d/m/Y H:i"); if ($nbtot == 0) { echo "<div class='center'><font class='red b'>" . __("No item found") . "</font></div>"; Html::footer(); } else { if ($output_type == Search::HTML_OUTPUT) { echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th>{$title}</th></tr>\n"; echo "<tr class='tab_bg_2 center'><td class='center'>"; $parameters = null; $parameters .= Toolbox::append_params($_REQUEST, '&'); $this->printPager($start, $nbtot, $_SERVER["PHP_SELF"], $parameters, 'PluginRacksRack'); } } if ($nbtot > 0) { if ($output_type == Search::HTML_OUTPUT) { echo "<form method='POST' action='" . $_SERVER["PHP_SELF"] . "?start={$start}'>\n"; } echo Search::showHeader($output_type, $nbrows, $nbCols, true); echo Search::showNewLine($output_type); $showAllFieds = true; $listFields = array(); $cptField = 0; $showAllFieds = (!isset($_REQUEST['cb_object_name']) || $_REQUEST['cb_object_name'] != "on") && (!isset($_REQUEST['cb_object_location']) || $_REQUEST['cb_object_location'] != "on") && (!isset($_REQUEST['cb_group']) || $_REQUEST['cb_group'] != "on") && (!isset($_REQUEST['cb_manufacturer']) || $_REQUEST['cb_manufacturer'] != "on") && (!isset($_REQUEST['cb_model']) || $_REQUEST['cb_model'] != "on") && (!isset($_REQUEST['cb_serial_number']) || $_REQUEST['cb_serial_number'] != "on"); $num = 1; $cptRow = 1; if (!$showAllFieds) { $this->showTitle($output_type, $num, __("Bay name", "racks"), 'name', false, $params); $cptField++; $this->showTitle($output_type, $num, __("Location"), 'location', false, $params); $cptField++; $this->showTitle($output_type, $num, _n("Place", "Places", 1, "racks"), 'roomlocation', false, $params); $cptField++; $this->showTitle($output_type, $num, __("U", "racks"), 'u', false, $params); $cptField++; $this->showTitle($output_type, $num, __("Front", "racks") . " / " . _x('Rack enclosure', 'Back', 'racks'), 'front_rear', false, $params); $cptField++; if (isset($_REQUEST['cb_object_name']) && $_REQUEST['cb_object_name'] == "on") { $listFields['object_name'] = $_REQUEST['cb_object_name']; $this->showTitle($output_type, $num, __("Object name", "racks"), 'object_name', false, $params); $cptField++; } // Lieu if (isset($_REQUEST['cb_object_location']) && $_REQUEST['cb_object_location'] == "on") { $listFields['object_location'] = $_REQUEST['cb_object_location']; $this->showTitle($output_type, $num, __("Object location", "racks"), 'object_location', false, $params); $cptField++; } // Groupe if (isset($_REQUEST['cb_group']) && $_REQUEST['cb_group'] == "on") { $listFields['group'] = $_REQUEST['cb_group']; $this->showTitle($output_type, $num, __("Group"), 'group', false, $params); $cptField++; } // Fabricant if (isset($_REQUEST['cb_manufacturer']) && $_REQUEST['cb_manufacturer'] == "on") { $listFields['manufacturer'] = $_REQUEST['cb_manufacturer']; $this->showTitle($output_type, $num, __("Manufacturer"), 'manufacturer', false, $params); $cptField++; } // Modèle if (isset($_REQUEST['cb_model']) && $_REQUEST['cb_model'] == "on") { $listFields['model'] = $_REQUEST['cb_model']; $this->showTitle($output_type, $num, __("Model"), 'model', false, $params); $cptField++; } // Numéro de série if (isset($_REQUEST['cb_serial_number']) && $_REQUEST['cb_serial_number'] == "on") { $listFields['serial_number'] = $_REQUEST['cb_serial_number']; $this->showTitle($output_type, $num, __("Serial number"), 'group', false, $params); $cptField++; } } else { $this->showTitle($output_type, $num, __("Bay name", "racks"), 'rack_name', false, $params); $listFields['rack_name'] = true; $this->showTitle($output_type, $num, __("Location"), 'location', false, $params); $listFields['location'] = true; $this->showTitle($output_type, $num, _n("Place", "Places", 1, "racks"), 'roomlocation', false, $params); $listFields['roomlocation'] = true; $this->showTitle($output_type, $num, __("U", "racks"), 'u', false, $params); $listFields['u'] = true; $this->showTitle($output_type, $num, __("Front", "racks") . " / " . _x('Rack enclosure', 'Back', 'racks'), 'front_rear', false, $params); $listFields['front_rear'] = true; $this->showTitle($output_type, $num, __("Object name", "racks"), 'object_name', false, $params); $listFields['object_name'] = true; $this->showTitle($output_type, $num, __("Object location", "racks"), 'object_location', false, $params); $listFields['object_location'] = true; $this->showTitle($output_type, $num, __("Group"), 'group', false, $params); $listFields['group'] = true; $this->showTitle($output_type, $num, __("Type"), 'type', false, $params); $listFields['type'] = true; $this->showTitle($output_type, $num, __("Manufacturer"), 'manufacturer', false, $params); $listFields['manufacturer'] = true; $this->showTitle($output_type, $num, __("Model"), 'model', false, $params); $listFields['model'] = true; $this->showTitle($output_type, $num, __("Serial number"), 'serial_number', false, $params); $listFields['serial_number'] = true; $this->showTitle($output_type, $num, __("Inventory number"), 'other_serial', false, $params); $listFields['other_serial'] = true; $cptField = 13; } echo self::showEndLine($output_type, $params); $num = 1; $cptRow = 1; $currentRack = -1; while ($row = $DB->fetch_array($result)) { // itemtype $itemtype = $row['itemtype']; $num = 1; $cptRow++; echo Search::showNewLine($output_type); if (isset($row['itemtype']) && $row['itemtype'] != "") { $class = substr($itemtype, 0, -5); $item = new $class(); $table = getTableForItemType($class); $r = $DB->query("SELECT * FROM `" . $table . "` WHERE `id` = '" . $row["items_id"] . "' "); $device = $DB->fetch_array($r); } // nom $link = Toolbox::getItemTypeFormURL("PluginRacksRack"); if ($groupByRackName || $currentRack != $row['id']) { if ($output_type == Search::HTML_OUTPUT) { echo self::showItem($output_type, "<a href=\"" . $link . "?id=" . $row["id"] . "\">" . $row["name"] . "</a>", $num, $cptRow, null, $params); } else { echo self::showItem($output_type, $row["name"], $num, $cptRow, null, $params); } } else { echo self::showItem($output_type, " ", $num, $cptRow, null, $params); } // lieu if ($groupByRackName || $currentRack != $row['id']) { if (isset($row['locations_id'])) { echo self::showItem($output_type, Dropdown::getDropdownName("glpi_locations", $row['locations_id']), $num, $cptRow, null, $params); } else { echo self::showItem($output_type, " ", $num, $cptRow, null, $params); } } else { echo self::showItem($output_type, " ", $num, $cptRow, null, $params); } // Emplacement if ($groupByRackName || $currentRack != $row['id']) { $tmpId = $row['plugin_racks_roomlocations_id']; $tmpId = $row['plugin_racks_roomlocations_id']; $tmpObj = new PluginRacksRoomLocation(); $trans_name = ""; if ($tmpObj->getFromDB($tmpId)) { $trans_name = $tmpObj->fields['name']; } $trans = DropdownTranslation::getTranslatedValue($tmpId, "PluginRacksRoomLocation", 'name', $_SESSION['glpilanguage']); if (!empty($trans)) { $trans_name = $trans; } if (isset($tmpId)) { echo self::showItem($output_type, $trans_name, $num, $cptRow, null, $params); } else { echo self::showItem($output_type, ' ', $num, $cptRow, null, $params); } } else { echo self::showItem($output_type, " ", $num, $cptRow, null, $params); } if (isset($row['itemtype']) && $row['itemtype'] != "") { // U if (isset($row['position']) && $row['position'] != "") { echo self::showItem($output_type, $row['position'], $num, $cptRow, null, $params); } else { echo self::showItem($output_type, " ", $num, $cptRow, null, $params); } // avant / arrière if ($row['faces_id'] == 1) { echo self::showItem($output_type, __("Front", "racks"), $num, $cptRow, null, $params); } else { echo self::showItem($output_type, _x('Rack enclosure', 'Back', 'racks'), $num, $cptRow, null, $params); } // Nom de l'objet if (array_key_exists("object_name", $listFields)) { $link = Toolbox::getItemTypeFormURL(substr($itemtype, 0, -5)); if ($itemtype != 'PluginRacksOtherModel') { if ($output_type == Search::HTML_OUTPUT) { echo self::showItem($output_type, "<a href=\"" . $link . "?id=" . $row["items_id"] . "\">" . $device["name"] . "</a>", $num, $cptRow, null, $params); } else { echo self::showItem($output_type, $device["name"], $num, $cptRow, null, $params); } } else { echo self::showItem($output_type, $device["name"], $num, $cptRow, null, $params); } } // Lieu de l'objet if (array_key_exists("object_location", $listFields)) { if ($itemtype != 'PluginRacksOtherModel') { echo self::showItem($output_type, Dropdown::getDropdownName("glpi_locations", $device["locations_id"]), $num, $cptRow, null, $params); } else { echo self::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow, null, $params); } } // Groupe if (array_key_exists("group", $listFields)) { // Groupe if ($itemtype != 'PluginRacksOtherModel') { echo self::showItem($output_type, Dropdown::getDropdownName("glpi_groups", $device["groups_id_tech"]), $num, $cptRow, null, $params); } else { echo self::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow, null, $params); } } // type if (array_key_exists("type", $listFields)) { echo self::showItem($output_type, $item->getTypeName(), $num, $cptRow, null, $params); } // fabricant if (array_key_exists("manufacturer", $listFields)) { if ($itemtype != 'PluginRacksOtherModel') { echo self::showItem($output_type, Dropdown::getDropdownName("glpi_manufacturers", $device["manufacturers_id"]), $num, $cptRow, null, $params); } else { echo self::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow, null, $params); } } // modèle if (array_key_exists("model", $listFields)) { $model_table = getTableForItemType($itemtype); $modelfield = getForeignKeyFieldForTable(getTableForItemType($itemtype)); echo self::showItem($output_type, Dropdown::getDropdownName($model_table, $device[$modelfield]), $num, $cptRow, null, $params); } // numéro de série if (array_key_exists("serial_number", $listFields)) { if ($itemtype != 'PluginRacksOtherModel') { echo self::showItem($output_type, $device['serial'], $num, $cptRow, null, $params); } else { echo self::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow, null, $params); } } // numéro d'inventaire if (array_key_exists("other_serial", $listFields)) { if ($itemtype != 'PluginRacksOtherModel') { echo self::showItem($output_type, $device['otherserial'], $num, $cptRow, null, $params); } else { echo self::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow, null, $params); } } $currentRack = $row['id']; } else { for ($k = 0; $k < $cptField - 3; $k++) { echo self::showItem($output_type, " ", $num, $cptRow, null, $params); } } echo self::showEndLine($output_type, $params); } echo self::showFooter($output_type, $title, $params); if ($output_type == Search::HTML_OUTPUT) { Html::closeForm(); } } }
function prepareInputForUpdate($input) { global $CFG_GLPI; //picture manually uploaded by user if (isset($input["_blank_picture"]) && $input["_blank_picture"]) { self::dropPictureFiles($this->fields['picture']); $input['picture'] = 'NULL'; } else { if (isset($_FILES['picture'])) { if (!count($_FILES['picture']) || empty($_FILES['picture']['name']) || !is_file($_FILES['picture']['tmp_name'])) { switch ($_FILES['picture']['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: Session::addMessageAfterRedirect(__('File too large to be added.'), false, ERROR); break; case UPLOAD_ERR_NO_FILE: // Session::addMessageAfterRedirect(__('No file specified.'),false,ERROR); break; } } else { if (toolbox::getMime($_FILES['picture']['tmp_name'], 'image')) { // Unlink old picture (clean on changing format) self::dropPictureFiles($this->fields['picture']); // Move uploaded file $filename = uniqid($this->fields['id'] . '_'); $sub = substr($filename, -2); /* 2 hex digit */ $tmp = explode(".", $_FILES['picture']['name']); $extension = array_pop($tmp); @mkdir(GLPI_PICTURE_DIR . "/{$sub}"); $picture_path = GLPI_PICTURE_DIR . "/{$sub}/{$filename}.{$extension}"; self::dropPictureFiles($filename . "." . $extension); if (in_array($extension, array('jpg', 'jpeg', 'png', 'bmp', 'gif')) && Document::renameForce($_FILES['picture']['tmp_name'], $picture_path)) { Session::addMessageAfterRedirect(__('The file is valid. Upload is successful.')); // For display $input['picture'] = "{$sub}/{$filename}.{$extension}"; //prepare a thumbnail $thumb_path = GLPI_PICTURE_DIR . "/{$sub}/{$filename}_min.{$extension}"; Toolbox::resizePicture($picture_path, $thumb_path); } else { Session::addMessageAfterRedirect(__('Potential upload attack or file too large. Moving temporary file failed.'), false, ERROR); } } else { Session::addMessageAfterRedirect(__('The file is not an image file.'), false, ERROR); } } } else { //ldap jpegphoto synchronisation. if (isset($this->fields["authtype"]) && ($this->fields["authtype"] == Auth::LDAP || Auth::isAlternateAuth($this->fields['authtype'])) && ($picture = $this->syncLdapPhoto())) { if (!empty($picture)) { $input['picture'] = $picture; } } } } if (isset($input["password2"])) { // Empty : do not update if (empty($input["password"])) { unset($input["password"]); } else { if ($input["password"] == $input["password2"]) { // Check right : my password of user with lesser rights if (isset($input['id']) && Config::validatePassword($input["password"]) && ($input['id'] == Session::getLoginUserID() || $this->currentUserHaveMoreRightThan($input['id']) || $input['password_forget_token'] == $this->fields['password_forget_token'] && abs(strtotime($_SESSION["glpi_currenttime"]) - strtotime($this->fields['password_forget_token_date'])) < DAY_TIMESTAMP && $this->isEmail($input['email']))) { $input["password"] = Auth::getPasswordHash(Toolbox::unclean_cross_side_scripting_deep(stripslashes($input["password"]))); } else { unset($input["password"]); } unset($input["password2"]); } else { Session::addMessageAfterRedirect(__('Error: the two passwords do not match'), false, ERROR); return false; } } } else { if (isset($input["password"])) { // From login unset($input["password"]); } } // Update User in the database if (!isset($input["id"]) && isset($input["name"])) { if ($this->getFromDBbyName($input["name"])) { $input["id"] = $this->fields["id"]; } } if (isset($input["entities_id"]) && Session::getLoginUserID() === $input['id']) { $_SESSION["glpidefault_entity"] = $input["entities_id"]; } // Security on default profile update if (isset($input['profiles_id'])) { if (!in_array($input['profiles_id'], Profile_User::getUserProfiles($input['id']))) { unset($input['profiles_id']); } } // Security on default entity update if (isset($input['entities_id'])) { if (!in_array($input['entities_id'], Profile_User::getUserEntities($input['id']))) { unset($input['entities_id']); } } if (isset($input['_reset_personal_token'])) { $input['personal_token'] = self::getUniquePersonalToken(); $input['personal_token_date'] = $_SESSION['glpi_currenttime']; } // Manage preferences fields if (Session::getLoginUserID() === $input['id']) { if (isset($input['use_mode']) && $_SESSION['glpi_use_mode'] != $input['use_mode']) { $_SESSION['glpi_use_mode'] = $input['use_mode']; //Session::loadLanguage(); } } foreach ($CFG_GLPI['user_pref_field'] as $f) { if (isset($input[$f])) { if (Session::getLoginUserID() === $input['id']) { if ($_SESSION["glpi{$f}"] != $input[$f]) { $_SESSION["glpi{$f}"] = $input[$f]; // reinit translations if ($f == 'language') { $_SESSION['glpi_dropdowntranslations'] = DropdownTranslation::getAvailableTranslations($_SESSION["glpilanguage"]); unset($_SESSION['glpimenu']); } } } if ($input[$f] == $CFG_GLPI[$f]) { $input[$f] = "NULL"; } } } return $input; }
/** * Init session for the user is defined * * @param $auth Auth object to init session * * @return nothing **/ static function init(Auth $auth) { global $CFG_GLPI; if ($auth->auth_succeded) { // Restart GLPi session : complete destroy to prevent lost datas $tosave = array('glpi_plugins', 'glpicookietest', 'phpCAS', 'glpicsrftokens', 'glpiskipMaintenance'); $save = array(); foreach ($tosave as $t) { if (isset($_SESSION[$t])) { $save[$t] = $_SESSION[$t]; } } self::destroy(); session_regenerate_id(); self::start(); $_SESSION = $save; $_SESSION['valid_id'] = session_id(); // Define default time : $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); // Normal mode for this request $_SESSION["glpi_use_mode"] = self::NORMAL_MODE; // Check ID exists and load complete user from DB (plugins...) if (isset($auth->user->fields['id']) && $auth->user->getFromDB($auth->user->fields['id'])) { if (!$auth->user->fields['is_deleted'] && ($auth->user->fields['is_active'] && ($auth->user->fields['begin_date'] < $_SESSION["glpi_currenttime"] || is_null($auth->user->fields['begin_date'])) && ($auth->user->fields['end_date'] > $_SESSION["glpi_currenttime"] || is_null($auth->user->fields['end_date'])))) { $_SESSION["glpiID"] = $auth->user->fields['id']; $_SESSION["glpiname"] = $auth->user->fields['name']; $_SESSION["glpirealname"] = $auth->user->fields['realname']; $_SESSION["glpifirstname"] = $auth->user->fields['firstname']; $_SESSION["glpidefault_entity"] = $auth->user->fields['entities_id']; $_SESSION["glpiusers_idisation"] = true; $_SESSION["glpiextauth"] = $auth->extauth; $_SESSION["glpiauthtype"] = $auth->user->fields['authtype']; $_SESSION["glpiroot"] = $CFG_GLPI["root_doc"]; $_SESSION["glpi_use_mode"] = $auth->user->fields['use_mode']; $_SESSION["glpicrontimer"] = time(); // Default tab // $_SESSION['glpi_tab']=1; $_SESSION['glpi_tabs'] = array(); $auth->user->computePreferences(); foreach ($CFG_GLPI['user_pref_field'] as $field) { if (isset($auth->user->fields[$field])) { $_SESSION["glpi{$field}"] = $auth->user->fields[$field]; } } // Do it here : do not reset on each page, cause export issue if ($_SESSION["glpilist_limit"] > $CFG_GLPI['list_limit_max']) { $_SESSION["glpilist_limit"] = $CFG_GLPI['list_limit_max']; } // Init not set value for language if (empty($_SESSION["glpilanguage"])) { $_SESSION["glpilanguage"] = $CFG_GLPI['language']; } $_SESSION['glpi_dropdowntranslations'] = DropdownTranslation::getAvailableTranslations($_SESSION["glpilanguage"]); self::loadLanguage(); // glpiprofiles -> other available profile with link to the associated entities Plugin::doHook("init_session"); self::initEntityProfiles(self::getLoginUserID()); // Use default profile if exist if (isset($_SESSION['glpiprofiles'][$auth->user->fields['profiles_id']])) { self::changeProfile($auth->user->fields['profiles_id']); } else { // Else use first self::changeProfile(key($_SESSION['glpiprofiles'])); } if (!isset($_SESSION["glpiactiveprofile"]["interface"])) { $auth->auth_succeded = false; $auth->addToError(__("You don't have right to connect")); } } else { $auth->auth_succeded = false; $auth->addToError(__("You don't have access to this application because your account was deactivated or removed")); } } else { $auth->auth_succeded = false; $auth->addToError(__("You don't have right to connect")); } } }
function showItemFromPlugin($instID, $face) { global $DB, $CFG_GLPI; if (!$this->canView()) { return false; } $rand = mt_rand(); $PluginRacksRack = new PluginRacksRack(); $PluginRacksConfig = new PluginRacksConfig(); if ($PluginRacksRack->getFromDB($instID)) { $canedit = $PluginRacksRack->can($instID, UPDATE); if ($canedit) { $this->AddItemToRack($PluginRacksRack, $instID, $face); } //LIST echo "<form method='post' name='racks_form{$rand}' id='racks_form{$rand}' \r\n action=\"" . PluginRacksRack::getFormURL(true) . "\">"; echo "<div class='center'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='12'>" . __('Rack enclosure arrangement', 'racks') . ":</th></tr><tr>"; if ($face == PluginRacksRack::FRONT_FACE) { $query = "SELECT `" . $this->getTable() . "`.*\r\n FROM `" . $this->getTable() . "`,`glpi_plugin_racks_itemspecifications`\r\n WHERE `" . $this->getTable() . "`.`plugin_racks_itemspecifications_id` = `glpi_plugin_racks_itemspecifications`.`id` \r\n AND `" . $this->getTable() . "`.`plugin_racks_racks_id` = '{$instID}'\r\n AND (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::FRONT_FACE . "' \r\n OR (`" . $this->getTable() . "`.`faces_id` ='" . PluginRacksRack::BACK_FACE . "' \r\n AND `glpi_plugin_racks_itemspecifications`.`length` = 1 ))\r\n ORDER BY `" . $this->getTable() . "`.`position` ASC"; } else { $query = "SELECT `" . $this->getTable() . "`.*\r\n FROM `" . $this->getTable() . "`,`glpi_plugin_racks_itemspecifications`\r\n WHERE `" . $this->getTable() . "`.`plugin_racks_itemspecifications_id` = `glpi_plugin_racks_itemspecifications`.`id` \r\n AND `" . $this->getTable() . "`.`plugin_racks_racks_id` = '{$instID}'\r\n AND (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::BACK_FACE . "' \r\n OR (`" . $this->getTable() . "`.`faces_id` ='" . PluginRacksRack::FRONT_FACE . "' \r\n AND `glpi_plugin_racks_itemspecifications`.`length` = 1 ))\r\n ORDER BY `" . $this->getTable() . "`.`position` ASC"; } $result = $DB->query($query); $number = $DB->numrows($result); $amps_tot = 0; $flow_rate_tot = 0; $dissip_tot = 0; $weight_tot = $PluginRacksRack->fields["weight"]; $nbcordons = 0; $nbcordons_tot = 0; $cordons_amps_tot = 0; $computer_tot = 0; $computer_size_tot = 0; $networking_tot = 0; $networking_size_tot = 0; $peripheral_tot = 0; $peripheral_size_tot = 0; $others_tot = 0; $others_size_tot = 0; $next = 0; $device_size = 0; echo "<th> </th>"; echo "<th>" . __('Position', 'racks') . "</th>"; echo "<th>" . __('Name') . "</th>"; // nom echo "<th>" . __('Type') . "</th>"; // type de materiel echo "<th>" . __('Model') . "</th>"; echo "<th>" . __('Power supply 1', 'racks') . "</th>"; //alim1 echo "<th>" . __('Power supply 2', 'racks') . "</th>"; //alim2 echo "<th>" . __('C13 Power Cord Quantity', 'racks') . "</th>"; // nb cordons echo "<th>" . __('Total Current', 'racks') . "<br>(" . __('amps', 'racks') . ")</th>"; // Courant consommé echo "<th>" . __('Calorific waste', 'racks') . "<br>"; // Dissipation calorifique echo " ("; $PluginRacksConfig->getUnit("dissipation"); echo ")</th>"; echo "<th>" . __('Flow Rate', 'racks') . "<br>"; // Débit d'air frais echo " ("; $PluginRacksConfig->getUnit("rate"); echo ")</th>"; echo "<th>" . __('Weight', 'racks') . "<br>"; // poids echo " ("; $PluginRacksConfig->getUnit("weight"); echo ")</th>"; echo "</tr>"; for ($i = $PluginRacksRack->fields['rack_size']; $i >= 1; $i--) { $alim1 = 0; $alim2 = 0; $j = $i; if ($i < 10) { $j = "0" . $i; } if ($face == PluginRacksRack::FRONT_FACE) { // recherche de l'equipement a la position courante $query = "SELECT `" . $this->getTable() . "`.*\r\n FROM `" . $this->getTable() . "`,`glpi_plugin_racks_itemspecifications`\r\n WHERE `" . $this->getTable() . "`.`plugin_racks_itemspecifications_id` = `glpi_plugin_racks_itemspecifications`.`id` \r\n AND `" . $this->getTable() . "`.`plugin_racks_racks_id` = '{$instID}'\r\n AND (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::FRONT_FACE . "' \r\n OR (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::BACK_FACE . "' \r\n AND `glpi_plugin_racks_itemspecifications`.`length` = 1)) AND `position` ='{$j}'\r\n ORDER BY `" . $this->getTable() . "`.`position` ASC"; } else { $query = "SELECT `" . $this->getTable() . "`.*\r\n FROM `" . $this->getTable() . "`,`glpi_plugin_racks_itemspecifications`\r\n WHERE `" . $this->getTable() . "`.`plugin_racks_itemspecifications_id` = `glpi_plugin_racks_itemspecifications`.`id` \r\n AND `" . $this->getTable() . "`.`plugin_racks_racks_id` = '{$instID}'\r\n AND (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::BACK_FACE . "' \r\n OR (`" . $this->getTable() . "`.`faces_id` = '" . PluginRacksRack::FRONT_FACE . "' \r\n AND `glpi_plugin_racks_itemspecifications`.`length` = 1)) AND `position` ='{$j}'\r\n ORDER BY `" . $this->getTable() . "`.`position` ASC"; } $result = $DB->query($query); $number = $DB->numrows($result); // Si equipement if ($number != 0) { $data = $DB->fetch_array($result); $class = substr($data["itemtype"], 0, -5); $item = new $class(); $table = getTableForItemType($class); $r = $DB->query("SELECT * FROM `" . $table . "` WHERE `id` = '" . $data["items_id"] . "' "); $device = $DB->fetch_array($r); $modelclass = $data["itemtype"]; $model_table = getTableForItemType($modelclass); $modelfield = getForeignKeyFieldForTable(getTableForItemType($modelclass)); $query = "SELECT `" . $model_table . "`.`name` AS model,`" . $model_table . "`.`id` AS modelid, `glpi_plugin_racks_itemspecifications`.* \r\n FROM `glpi_plugin_racks_itemspecifications` " . " LEFT JOIN `" . $model_table . "` \r\n ON (`glpi_plugin_racks_itemspecifications`.`model_id` = `" . $model_table . "`.`id`)" . " LEFT JOIN `" . $table . "` \r\n ON (`glpi_plugin_racks_itemspecifications`.`model_id` = `" . $table . "`.`" . $modelfield . "` \r\n AND `glpi_plugin_racks_itemspecifications`.`itemtype` = '" . $modelclass . "')" . " WHERE `" . $table . "`.`id` = '" . $data["items_id"] . "' "; //Rack recursivity .getEntitiesRestrictRequest(" AND ",$table,'','',$item->maybeRecursive()) $res = $DB->query($query); $device_spec = $DB->fetch_array($res); $device_size = $device_spec["size"]; if ($data["first_powersupply"] > 0) { $nbcordons += 1; $nbcordons_tot += 1; } if ($data["second_powersupply"] > 0) { $nbcordons += 1; $nbcordons_tot += 1; } if ($data["itemtype"] == 'ComputerModel') { $computer_tot += 1; $computer_size_tot += $device_spec["size"]; } else { if ($data["itemtype"] == 'PeripheralModel') { $peripheral_tot += 1; $peripheral_size_tot += $device_spec["size"]; } else { if ($data["itemtype"] == 'NetworkEquipmentModel') { $networking_tot += 1; $networking_size_tot += $device_spec["size"]; } else { if ($data["itemtype"] == 'PluginRacksOtherModel') { $others_tot += 1; $others_size_tot += $device_spec["size"]; } } } } for ($t = 0; $t < $device_size; $t++) { if ($t == 0) { if ($data["itemtype"] == 'ComputerModel') { echo "<tr class='plugin_racks_device_computers_color'>"; } else { if ($data["itemtype"] == 'PeripheralModel') { echo "<tr class='plugin_racks_device_peripherals_color'>"; } else { if ($data["itemtype"] == 'NetworkEquipmentModel') { echo "<tr class='plugin_racks_device_networking_color'>"; } else { if ($data["itemtype"] == 'PluginRacksOtherModel') { echo "<tr class='plugin_racks_device_others_color'>"; } } } } echo "<td width='10' rowspan='" . $device_size . "'>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>"; echo "</td>"; echo "<td class='center'>U"; if ($canedit) { echo "<input type='text' size='3' name='position" . $data["id"] . "' value='{$j}'>"; echo " <input type='image' name='updateDevice[" . $data["id"] . "]' value=\"" . _sx('button', 'Save') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/actualiser.png' class='calendrier'>"; } else { echo $j; } echo "</td>"; $link = Toolbox::getItemTypeFormURL(substr($data["itemtype"], 0, -5)); if ($data["itemtype"] != 'PluginRacksOtherModel') { $name = "<a href=\"" . $link . "?id=" . $data["items_id"] . "\">" . $device["name"] . "</a>"; } else { $name = $device["name"]; } echo "<input type='hidden' name='plugin_racks_racks_id' value='" . $PluginRacksRack->fields['id'] . "'>"; echo "<input type='hidden' name='rack_size' value='" . $PluginRacksRack->fields['rack_size'] . "'>"; echo "<input type='hidden' name='type" . $data["id"] . "' value='" . $data["itemtype"] . "'>"; echo "<input type='hidden' name='items_id" . $data["id"] . "' value='" . $data["items_id"] . "'>"; echo "<input type='hidden' name='plugin_racks_itemspecifications_id" . $data["id"] . "' value='" . $data["plugin_racks_itemspecifications_id"] . "'>"; echo "<input type='hidden' name='update_server' value='1'>"; echo "<input type='hidden' name='faces_id' value='" . $face . "'>"; if ($data["itemtype"] != 'PluginRacksOtherModel') { echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . " >" . $name . "</td>"; } else { $PluginRacksOther = new PluginRacksOther(); $PluginRacksOther->GetfromDB($data["items_id"]); echo "<td class='center'><input type='text' name='name" . $data["id"] . "' value='" . $PluginRacksOther->fields["name"] . "' size='10'></td>"; } echo "<td class='center'>" . $item::getTypeName(2) . "</td>"; $linkmodel = Toolbox::getItemTypeFormURL($modelclass); $trans = DropdownTranslation::getTranslatedValue($device_spec["modelid"], $modelclass, 'name', $_SESSION['glpilanguage']); $trans_name = $device_spec["model"]; if (!empty($trans)) { $trans_name = $trans; } echo "<td class='center'><a href=\"" . $linkmodel . "?id=" . $device_spec["modelid"] . "\">" . $trans_name . " (" . $device_spec["size"] . "U)</a></td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_racks_connections", $data["first_powersupply"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_racks_connections", $data["second_powersupply"]); echo "</td>"; echo "<td class='center'>" . $nbcordons . "</td>"; if ($data["amps"] == '0.0000') { $amps = $device_spec["amps"]; } else { $amps = $data["amps"]; } $cordons_amps_tot += $amps * $nbcordons; echo "<td class='center'>" . Html::formatNumber($amps, true) . "</td>"; if ($data["dissipation"] == '0.0000') { $dissipation = $device_spec["dissipation"]; } else { $dissipation = $data["dissipation"]; } echo "<td class='center'>" . Html::formatNumber($dissipation, true) . "</td>"; if ($data["flow_rate"] == '0.0000') { $flow_rate = $device_spec["flow_rate"]; } else { $flow_rate = $data["flow_rate"]; } echo "<td class='center'>" . Html::formatNumber($flow_rate, true) . "</td>"; if ($data["weight"] == '0.0000') { $weight = $device_spec["weight"]; } else { $weight = $data["weight"]; } echo "<td class='center'>" . Html::formatNumber($weight, true) . "</td>"; echo "</tr>"; if ($data["amps"] == '0.0000') { $amps_tot += $device_spec["amps"]; } else { $amps_tot += $data["amps"]; } if ($data["flow_rate"] == '0.0000') { $flow_rate_tot += $device_spec["flow_rate"]; } else { $flow_rate_tot += $data["flow_rate"]; } if ($data["dissipation"] == '0.0000') { $dissip_tot += $device_spec["dissipation"]; } else { $dissip_tot += $data["dissipation"]; } if ($data["weight"] == '0.0000') { $weight_tot += $device_spec["weight"]; } else { $weight_tot += $data["weight"]; } } else { $name = $j - $t; if ($data["itemtype"] == 'ComputerModel') { echo "<tr class='plugin_racks_device_computers_color'>"; } else { if ($data["itemtype"] == 'PeripheralModel') { echo "<tr class='plugin_racks_device_peripherals_color'>"; } else { if ($data["itemtype"] == 'NetworkEquipmentModel') { echo "<tr class='plugin_racks_device_networking_color'>"; } else { if ($data["itemtype"] == 'PluginRacksOtherModel') { echo "<tr class='plugin_racks_device_others_color'>"; } } } } echo "<td class='center'>U{$name}</td><td colspan='10'></td></tr>"; } } if ($device_size > 1) { for ($d = 1; $d < $device_size; $d++) { $i--; } } } else { // Si pas d'equipement a la position courante echo "<tr class='tab_bg_1'><td></td><td class='center'>" . __('U', 'racks') . $j; echo "</td><td colspan='10'></td></tr>"; } $nbcordons = 0; } echo "<tr class='tab_bg_1'>"; echo "<td></td>"; echo "<td class='center'><b>" . __('Total') . "</b></td>"; echo "<td colspan='3' class='center'><b>"; if ($computer_tot != 0) { echo __('Total Servers', 'racks') . " : " . $computer_tot . " (" . $computer_size_tot . __('U', 'racks') . ")<br>"; } if ($networking_tot != 0) { echo __('Total Network equipements', 'racks') . " : " . $networking_tot . " (" . $networking_size_tot . __('U', 'racks') . ")<br>"; } if ($peripheral_tot != 0) { echo __('Total Peripherals', 'racks') . " : " . $peripheral_tot . " (" . $peripheral_size_tot . __('U', 'racks') . ")<br>"; } if ($others_tot != 0) { echo __('Total Others', 'racks') . " : " . $others_tot . " (" . $others_size_tot . __('U', 'racks') . ")<br>"; } //number of U availables $available = $PluginRacksRack->fields['rack_size'] - $computer_size_tot - $networking_size_tot - $peripheral_size_tot - $others_size_tot; if ($available > 0) { echo "<font color='green'>" . $available . " " . __('U availables', 'racks') . "</font>"; } else { echo "<font color='red'>" . $available . " " . __('U availables', 'racks') . "</font>"; } echo "</b></td>"; echo "<td colspan='3' class='center'><b>" . __('Total power Cords', 'racks') . " : " . $nbcordons_tot . "</b><br>"; echo "<b>" . __('Amperage on power Cords', 'racks') . " : " . $cordons_amps_tot . " " . __('amps', 'racks') . "</b></td>"; echo "<td class='center'><b>" . Html::formatNumber($amps_tot, true) . " " . __('amps', 'racks') . "</b></td>"; echo "<td class='center'><b>" . Html::formatNumber($dissip_tot, true) . " "; $PluginRacksConfig->getUnit("dissipation"); echo "</b></td>"; echo "<td class='center'><b>" . Html::formatNumber($flow_rate_tot, true) . " "; $PluginRacksConfig->getUnit("rate"); echo "</b></td>"; echo "<td class='center'><b>" . Html::formatNumber($weight_tot, true) . " "; $PluginRacksConfig->getUnit("weight"); echo "</b></td>"; echo "</tr>"; echo "</table></div>"; if ($canedit) { Html::openArrowMassives("racks_form{$rand}", true); Html::closeArrowMassives(array('deleteDevice' => _sx('button', 'Delete permanently'))); } else { echo "<input type='hidden' name='rack_size' value='" . $PluginRacksRack->fields['rack_size'] . "'>"; echo "</table></div>"; } Html::closeForm(); //////////////////////////////////////////////////// // Recherche des racks a gauche et a droite // Recuperation de la rangee $qPos = "SELECT `name`\r\n FROM `glpi_plugin_racks_roomlocations`\r\n WHERE `id` = '" . $PluginRacksRack->fields['plugin_racks_roomlocations_id'] . "' "; $rPos = $DB->query($qPos); $nbPos = $DB->numrows($rPos); $pos = ""; $next = ""; $prev = ""; if ($nbPos != 0) { $dataPos = $DB->fetch_array($rPos); $pos = $dataPos['name']; } // Incrementation & docrementation de la lettre de rang if (!empty($pos)) { // Z is the last letter... if ($pos[0] != "Z") { $next = chr(ord($pos[0]) + 1); for ($h = 1; $h < strlen($pos); $h++) { $next .= $pos[$h]; } } // A is the first letter.... if ($pos[0] != "A") { $prev = chr(ord($pos[0]) - 1); for ($h = 1; $h < strlen($pos); $h++) { $prev .= $pos[$h]; } } $qLeft = "SELECT `glpi_plugin_racks_racks`.`id`, `glpi_plugin_racks_roomlocations`.`name`\r\n FROM `glpi_plugin_racks_racks`\r\n LEFT JOIN `glpi_plugin_racks_roomlocations`\r\n ON (`glpi_plugin_racks_roomlocations`.`id` = `glpi_plugin_racks_racks`.`plugin_racks_roomlocations_id`)\r\n WHERE `glpi_plugin_racks_racks`.`is_deleted` = '0' AND `glpi_plugin_racks_roomlocations`.`name` = '" . $prev . "' " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_racks_racks", '', '', $PluginRacksRack->maybeRecursive()); $rLeft = $DB->query($qLeft); $nb = $DB->numrows($rLeft); echo "<br><br>"; echo "<div align='center'><table border='0' width='950px'><tr><td class='left'>"; if ($nb != 0) { $left_racks = $DB->fetch_array($rLeft); echo "<a href =\"" . $CFG_GLPI["root_doc"] . "/plugins/racks/front/rack.form.php?id=" . $left_racks['id'] . "\">\r\n <img src=\"" . $CFG_GLPI["root_doc"] . "/pics/left.png\" alt=''> " . __('Left rack enclosure', 'racks') . " " . $left_racks['name'] . "</a>"; } else { echo __('No rack enclosure on the left', 'racks'); } echo "</td>"; echo "<td>"; echo "</td>"; echo "<td class='right'>"; $qRight = "SELECT `glpi_plugin_racks_racks`.`id`, `glpi_plugin_racks_roomlocations`.`name`\r\n FROM `glpi_plugin_racks_racks`\r\n LEFT JOIN `glpi_plugin_racks_roomlocations`\r\n ON (`glpi_plugin_racks_roomlocations`.`id` = `glpi_plugin_racks_racks`.`plugin_racks_roomlocations_id`)\r\n WHERE `glpi_plugin_racks_racks`.`is_deleted` = '0' AND `glpi_plugin_racks_roomlocations`.`name` = '" . $next . "' " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_racks_racks", '', '', $PluginRacksRack->maybeRecursive()); $rRight = $DB->query($qRight); $nb = $DB->numrows($rRight); if ($nb != 0) { $right_racks = $DB->fetch_array($rRight); echo "<a href =\"" . $CFG_GLPI["root_doc"] . "/plugins/racks/front/rack.form.php?id=" . $right_racks['id'] . "\">" . __('Right rack enclosure', 'racks') . " " . $right_racks['name'] . " <img src=\"" . $CFG_GLPI["root_doc"] . "/pics/right.png\" alt=''></a>"; } else { echo __('No rack enclosure on the right', 'racks'); } echo "</td></tr></table></div>"; } } }