getID() 공개 메소드

Get the identifier of the current item
public getID ( ) : ID
리턴 ID
 function showNetworkEquipmentInformation(CommonDBTM $item, $options)
 {
     global $DB;
     $id = $item->getID();
     if (!($data = $this->find("`networkequipments_id`='" . $id . "'", '', 1))) {
         // Add in database if not exist
         $input = array();
         $input['networkequipments_id'] = $id;
         $_SESSION['glpi_plugins_fusinvsnmp_table'] = 'glpi_networkequipments';
         $ID_tn = $this->add($input);
         $this->getFromDB($ID_tn);
     } else {
         foreach ($data as $datas) {
             $this->fields = $datas;
         }
     }
     // Form networking informations
     echo "<form name='form' method='post' action='" . $options['target'] . "'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th colspan='4'>";
     echo __('SNMP information', 'fusioninventory');
     echo "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td align='center' rowspan='4'>";
     echo __('Sysdescr', 'fusioninventory') . "&nbsp;:";
     echo "</td>";
     echo "<td rowspan='4'>";
     echo "<textarea name='sysdescr' cols='45' rows='5'>";
     echo $this->fields['sysdescr'];
     echo "</textarea>";
     echo "<td align='center'></td>";
     echo "<td align='center'>";
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td align='center'>" . __('SNMP authentication', 'fusioninventory') . "&nbsp;:</td>";
     echo "<td align='center'>";
     PluginFusioninventoryConfigSecurity::auth_dropdown($this->fields['plugin_fusioninventory_configsecurities_id']);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td align='center'>";
     echo __('CPU usage (in %)', 'fusioninventory') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     Html::displayProgressBar(250, $this->fields['cpu'], array('simple' => TRUE));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td align='center'>";
     echo __('Memory usage (in %)', 'fusioninventory') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     $query2 = "SELECT *\n                 FROM `glpi_networkequipments`\n                 WHERE `id`='" . $id . "';";
     $result2 = $DB->query($query2);
     $data2 = $DB->fetch_assoc($result2);
     $ram_pourcentage = 0;
     if (!empty($data2["ram"]) and !empty($this->fields['memory'])) {
         $ram_pourcentage = ceil(100 * ($data2["ram"] - $this->fields['memory']) / $data2["ram"]);
     }
     if ($data2["ram"] - $this->fields['memory'] < 0 or empty($this->fields['memory'])) {
         echo "<center><strong>" . __('Datas not available', 'fusioninventory') . "</strong></center>";
     } else {
         Html::displayProgressBar(250, $ram_pourcentage, array('title' => " (" . ($data2["ram"] - $this->fields['memory']) . " Mo / " . $data2["ram"] . " Mo)"));
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2 center'>";
     echo "<td colspan='4'>";
     echo "<input type='hidden' name='id' value='" . $id . "'>";
     echo "<input type='submit' name='update' value=\"" . __('Update') . "\" class='submit' >";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
 }
예제 #2
0
 /**
  * Show ports for an item
  *
  * @param $item                     CommonDBTM object
  * @param $withtemplate   integer   withtemplate param (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $rand = mt_rand();
     $itemtype = $item->getType();
     $items_id = $item->getField('id');
     if (!Session::haveRight('networking', 'r') || !$item->can($items_id, 'r')) {
         return false;
     }
     $netport = new self();
     $netport->item = $item;
     if ($itemtype == 'NetworkPort') {
         $canedit = false;
     } else {
         $canedit = $item->can($items_id, 'w');
     }
     $showmassiveactions = false;
     if ($withtemplate != 2) {
         $showmassiveactions = $canedit;
     }
     // Show Add Form
     if ($canedit && (empty($withtemplate) || $withtemplate != 2)) {
         echo "\n<form method='get' action='" . $netport->getFormURL() . "'>\n";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>\n";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>\n";
         echo "<div class='firstbloc'><table class='tab_cadre_fixe'>\n";
         echo "<tr class='tab_bg_2'><td class='center'>\n";
         _e('Network port type to be added');
         echo "&nbsp;";
         $instantiations = array();
         foreach (self::getNetworkPortInstantiations() as $inst_type) {
             if (call_user_func(array($inst_type, 'canCreate'))) {
                 $instantiations[$inst_type] = call_user_func(array($inst_type, 'getTypeName'));
             }
         }
         Dropdown::showFromArray('instantiation_type', $instantiations, array('value' => 'NetworkPortEthernet'));
         echo "</td>\n";
         echo "<td class='tab_bg_2 center' width='50%'>";
         _e('Add several ports');
         echo "&nbsp;<input type='checkbox' name='several' value='1'></td>\n";
         echo "<td>\n";
         echo "<input type='submit' name='create' value=\"" . _sx('button', 'Add') . "\" class='submit'>\n";
         echo "</td></tr></table></div>\n";
         Html::closeForm();
     }
     if ($showmassiveactions) {
         $checkbox_column = true;
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
     } else {
         $checkbox_column = false;
     }
     $is_active_network_port = false;
     Session::initNavigateListItems('NetworkPort', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
     if ($itemtype == 'NetworkPort') {
         $porttypes = array('NetworkPortAlias', 'NetworkPortAggregate');
     } else {
         $porttypes = self::getNetworkPortInstantiations();
         // Manage NetworkportMigration
         $porttypes[] = '';
     }
     $display_options = self::getDisplayOptions($itemtype);
     $table = new HTMLTableMain();
     $number_port = self::countForItem($item);
     $table_options = array('canedit' => $canedit, 'display_options' => &$display_options);
     // Make table name and add the correct show/hide parameters
     $table_name = sprintf(__('%1$s: %2$d'), self::getTypeName($number_port), $number_port);
     // Add the link to the popup to display the options ...
     $table_namelink = self::getDisplayOptionsLink($itemtype);
     $table_name = sprintf(__('%1$s - %2$s'), $table_name, $table_namelink);
     $table->setTitle($table_name);
     $c_main = $table->addHeader('main', self::getTypeName(2));
     if ($display_options['dynamic_import'] && $item->isDynamic()) {
         $table_options['display_isDynamic'] = true;
     } else {
         $table_options['display_isDynamic'] = false;
     }
     if ($display_options['characteristics']) {
         $c_instant = $table->addHeader('Instantiation', __('Characteristics'));
         $c_instant->setHTMLClass('center');
     }
     if ($display_options['internet']) {
         $options = array('names' => 'NetworkName', 'aliases' => 'NetworkAlias', 'ipaddresses' => 'IPAddress', 'ipnetworks' => 'IPNetwork');
         $table_options['dont_display'] = array();
         foreach ($options as $option => $itemtype_for_option) {
             if (!$display_options[$option]) {
                 $table_options['dont_display'][$itemtype_for_option] = true;
             }
         }
         $c_network = $table->addHeader('Internet', _n(__('Internet information'), __('Internet information'), 2));
         $c_network->setHTMLClass('center');
     } else {
         $c_network = NULL;
     }
     foreach ($porttypes as $portType) {
         if (empty($portType)) {
             $group_name = 'Migration';
             $group_title = __('Network ports waiting for manual migration');
         } else {
             $group_name = $portType;
             $group_title = $portType::getTypeName(2);
         }
         $t_group = $table->createGroup($group_name, $group_title);
         if ($withtemplate != 2 && $canedit) {
             $c_checkbox = $t_group->addHeader('checkbox', Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand, '__RAND__'), $c_main);
         } else {
             $c_checkbox = NULL;
         }
         $c_number = $t_group->addHeader('NetworkPort', "#", $c_main);
         $c_name = $t_group->addHeader("Name", __('Name'), $c_main);
         $c_name->setItemType('NetworkPort');
         $c_name->setHTMLClass('center');
         if ($table_options['display_isDynamic']) {
             $c_dynamic = $t_group->addHeader("Dynamic", __('Automatic inventory'), $c_main);
             $c_dynamic->setHTMLClass('center');
         }
         if ($display_options['characteristics']) {
             if (empty($portType)) {
                 NetworkPortMigration::getMigrationInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options);
             } else {
                 $instantiation = new $portType();
                 $instantiation->getInstantiationHTMLTableHeaders($t_group, $c_instant, $c_network, NULL, $table_options);
                 unset($instantiation);
             }
         }
         if ($display_options['internet'] && !$display_options['characteristics']) {
             NetworkName::getHTMLTableHeader(__CLASS__, $t_group, $c_network, NULL, $table_options);
         }
         if ($itemtype == 'NetworkPort') {
             switch ($portType) {
                 case 'NetworkPortAlias':
                     $search_table = 'glpi_networkportaliases';
                     $search_request = "`networkports_id_alias`='{$items_id}'";
                     break;
                 case 'NetworkPortAggregate':
                     $search_table = 'glpi_networkportaggregates';
                     $search_request = "`networkports_id_list` like '%\"{$items_id}\"%'";
                     break;
             }
             $query = "SELECT `networkports_id` AS id\n                      FROM  `{$search_table}`\n                      WHERE {$search_request}";
         } else {
             $query = "SELECT `id`\n                      FROM `glpi_networkports`\n                      WHERE `items_id` = '{$items_id}'\n                            AND `itemtype` = '{$itemtype}'\n                            AND `instantiation_type` = '{$portType}'\n                            AND `is_deleted` = '0'\n                      ORDER BY `name`,\n                               `logical_number`";
         }
         if ($result = $DB->query($query)) {
             echo "<div class='spaced'>";
             $number_port = $DB->numrows($result);
             if ($number_port != 0) {
                 $is_active_network_port = true;
                 $save_canedit = $canedit;
                 if (!empty($portType)) {
                     $name = sprintf(__('%1$s (%2$s)'), self::getTypeName($number_port), call_user_func(array($portType, 'getTypeName')));
                     $name = sprintf(__('%1$s: %2$s'), $name, $number_port);
                 } else {
                     $name = __('Network ports waiting for manual migration');
                     $canedit = false;
                 }
                 while ($devid = $DB->fetch_row($result)) {
                     $t_row = $t_group->createRow();
                     $netport->getFromDB(current($devid));
                     // No massive action for migration ports
                     if ($withtemplate != 2 && $canedit && !empty($portType)) {
                         $ce_checkbox = $t_row->addCell($c_checkbox, "<input type='checkbox' name='item[" . $netport->fields["id"] . "]' value='1'>");
                     } else {
                         $ce_checkbox = NULL;
                     }
                     $content = "<span class='b'>";
                     // Display link based on default rights
                     if ($save_canedit && $withtemplate != 2) {
                         if (!empty($portType)) {
                             $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkport.form.php?id=" . $netport->fields["id"] . "\">";
                         } else {
                             $content .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/networkportmigration.form.php?id=" . $netport->fields["id"] . "\">";
                         }
                     }
                     $content .= $netport->fields["logical_number"];
                     if ($canedit && $withtemplate != 2) {
                         $content .= "</a>";
                     }
                     $content .= "</span>";
                     $content .= Html::showToolTip($netport->fields['comment'], array('display' => false));
                     $t_row->addCell($c_number, $content);
                     $value = $netport->fields["name"];
                     $t_row->addCell($c_name, $value, NULL, $netport);
                     if ($table_options['display_isDynamic']) {
                         $t_row->addCell($c_dynamic, Dropdown::getYesNo($netport->fields['is_dynamic']));
                     }
                     $instant_cell = NULL;
                     if ($display_options['characteristics']) {
                         $instantiation = $netport->getInstantiation();
                         if ($instantiation !== false) {
                             $instantiation->getInstantiationHTMLTable($netport, $t_row, NULL, $table_options);
                             unset($instantiation);
                         }
                     } else {
                         if ($display_options['internet']) {
                             NetworkName::getHTMLTableCellsForItem($t_row, $netport, NULL, $table_options);
                         }
                     }
                 }
                 $canedit = $save_canedit;
             }
             echo "</div>";
         }
     }
     if ($is_active_network_port && $showmassiveactions) {
         $massiveactionparams = array('num_displayed' => $number_port, 'check_itemtype' => $itemtype, 'check_items_id' => $items_id);
         Html::showMassiveActions('NetworkPort', $massiveactionparams);
     }
     $table->display(array('display_thead' => false, 'display_tfoot' => false));
     unset($table);
     if (!$is_active_network_port) {
         echo "<table class='tab_cadre_fixe'><tr><th>" . __('No network port found') . "</th></tr>";
         echo "</table>";
     }
     if ($showmassiveactions) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions('NetworkPort', $massiveactionparams);
         Html::closeForm();
     }
 }
예제 #3
0
파일: link.class.php 프로젝트: Ixertec/glpi
 /**
  * Show Links for an item
  *
  * @param $item                     CommonDBTM object
  * @param $withtemplate    integer  withtemplate param (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (!self::canView()) {
         return false;
     }
     if ($item->isNewID($item->getID())) {
         return false;
     }
     $restrict = $item->getEntityID();
     if ($item->getType() == 'User') {
         $restrict = Profile_User::getEntitiesForUser($item->getID());
     }
     $query = "SELECT `glpi_links`.`id`,\n                       `glpi_links`.`link` AS link,\n                       `glpi_links`.`name` AS name ,\n                       `glpi_links`.`data` AS data,\n                       `glpi_links`.`open_window` AS open_window\n                FROM `glpi_links`\n                INNER JOIN `glpi_links_itemtypes`\n                     ON `glpi_links`.`id` = `glpi_links_itemtypes`.`links_id`\n                WHERE `glpi_links_itemtypes`.`itemtype`='" . $item->getType() . "' " . getEntitiesRestrictRequest(" AND", "glpi_links", "entities_id", $restrict, true) . "\n                ORDER BY name";
     $result = $DB->query($query);
     echo "<div class='spaced'><table class='tab_cadre_fixe'>";
     if ($DB->numrows($result) > 0) {
         echo "<tr><th>" . self::getTypeName(Session::getPluralNumber()) . "</th></tr>";
         while ($data = $DB->fetch_assoc($result)) {
             $links = self::getAllLinksFor($item, $data);
             foreach ($links as $link) {
                 echo "<tr class='tab_bg_2'>";
                 echo "<td class='center'>{$link}</td></tr>";
             }
         }
         echo "</table></div>";
     } else {
         echo "<tr class='tab_bg_2'><th>" . self::getTypeName(Session::getPluralNumber()) . "</th></tr>";
         echo "<tr class='tab_bg_2'><td class='center b'>" . __('No link defined') . "</td></tr>";
         echo "</table></div>";
     }
 }
예제 #4
0
 static function showForItem(CommonDBTM $item)
 {
     global $DB, $LANG;
     if (!$item->canView()) {
         return false;
     }
     //       if (PluginSimcardSimcard::canCreate()) {
     //       	 if ($item->canEdit($item->getField('id'))) {
     // 	         $url = Toolbox::getItemTypeFormURL('PluginSimcardSimcard');
     // 	         $url.= "?itemtype=".$item->getType()."&items_id=".$item->getID()."&id=-1";
     // 	         echo "<div class='center'><a href='$url'>".__s('New SIM card', 'simcard')."</a></div><br>";
     //       	 }
     //       }
     $results = getAllDatasFromTable(getTableForItemType(__CLASS__), "`items_id` = '" . $item->getID() . "' AND `itemtype`='" . get_class($item) . "'");
     echo "<div class='spaced'>";
     echo "<form id='items' name='items' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='6'>" . __s('Associated item') . "</th></tr>";
     if (!empty($results)) {
         echo "<tr><th></th>";
         echo "<th>" . __s('Entity') . "</th>";
         echo "<th>" . __s('Name') . "</th>";
         echo "<th>" . __s('IMSI') . "</th>";
         echo "<th>" . __s('Inventory number') . "</th>";
         echo "</tr>";
         foreach ($results as $data) {
             $tmp = new PluginSimcardSimcard();
             $tmp->getFromDB($data['plugin_simcard_simcards_id']);
             echo "<tr>";
             echo "<td>";
             if (PluginSimcardSimcard::canDelete()) {
                 echo "<input type='checkbox' name='todelete[" . $data['id'] . "]'>";
             }
             echo "</td>";
             echo "<td>";
             echo Dropdown::getDropdownName('glpi_entities', $tmp->fields['entities_id']);
             echo "</td>";
             echo "<td>";
             echo $tmp->getLink();
             echo "</td>";
             echo "<td>";
             echo $tmp->fields['serial'];
             echo "</td>";
             echo "<td>";
             echo $tmp->fields['otherserial'];
             echo "</td>";
             echo "</tr>";
         }
     }
     if (PluginSimcardSimcard::canUpdate()) {
         echo "<tr class='tab_bg_1'><td colspan='4' class='center'>";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         $used = array();
         $query = "SELECT `id`\n                   FROM `glpi_plugin_simcard_simcards`\n                   WHERE `is_template`='0'\n                      AND `id` IN (SELECT `plugin_simcard_simcards_id`\n                                   FROM `glpi_plugin_simcard_simcards_items`)";
         foreach ($DB->request($query) as $use) {
             $used[] = $use['id'];
         }
         Dropdown::show('PluginSimcardSimcard', array('name' => "plugin_simcard_simcards_id", 'entity' => $item->fields['entities_id'], 'used' => $used));
         echo "</td>";
         echo "<td colspan='2' class='center' class='tab_bg_2'>";
         echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Save') . "\" class='submit'>";
         echo "</td></tr>";
         if (!empty($results)) {
             Html::openArrowMassives('items', true);
             Html::closeArrowMassives(array('delete_items' => _sx('button', 'Disconnect')));
         }
     }
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
예제 #5
0
 /**
  * Get the group of elements regarding given item.
  * Two kind of item :
  *              - Device* feed by a link to the attached item (Computer, Printer ...)
  *              - Computer, Printer ...: feed by the "global" properties of the CommonDevice
  * Then feed with the specificities of the Item_Device elements
  * In cas of $item is an instance, then $options contains the type of the item (Computer,
  * Printer ...).
  *
  * @param $item
  * @param $table
  * @param $options            array
  * @param $delete_all_column          (default NULL)
  * @param $common_column
  * @param $specific_column
  * @param $delete_column               (default NULL)
  * @param $dynamic_column
  **/
 function getTableGroup(CommonDBTM $item, HTMLTableMain $table, array $options, HTMLTableSuperHeader $delete_all_column = NULL, HTMLTableSuperHeader $common_column, HTMLTableSuperHeader $specific_column, HTMLTableSuperHeader $delete_column = NULL, $dynamic_column)
 {
     global $DB;
     $is_device = $item instanceof CommonDevice;
     if ($is_device) {
         $peer_type = $options['itemtype'];
         if (empty($peer_type)) {
             $column_label = __('Dissociated devices');
             $group_name = 'None';
         } else {
             $column_label = $peer_type::getTypeName(Session::getPluralNumber());
             $group_name = $peer_type;
         }
         $table_group = $table->createGroup($group_name, '');
         $peer_column = $table_group->addHeader('item', $column_label, $common_column, NULL);
         if (!empty($peer_type)) {
             //TRANS : %1$s is the type of the device
             //        %2$s is the type of the item
             //        %3$s is the name of the item (used for headings of a list),
             $itemtype_nav_title = sprintf(__('%1$s of %2$s: %3$s'), $peer_type::getTypeName(Session::getPluralNumber()), $item->getTypeName(1), $item->getName());
             $peer_column->setItemType($peer_type, $itemtype_nav_title);
         }
     } else {
         $peer_type = $this->getDeviceType();
         $table_group = $table->createGroup($peer_type, '');
         //TRANS : %1$s is the type of the device
         //        %2$s is the type of the item
         //        %3$s is the name of the item (used for headings of a list),
         $options['itemtype_title'] = sprintf(__('%1$s of %2$s: %3$s'), $peer_type::getTypeName(Session::getPluralNumber()), $item->getTypeName(1), $item->getName());
         $peer_type::getHTMLTableHeader($item->getType(), $table_group, $common_column, NULL, $options);
     }
     $specificity_columns = array();
     $link_column = $table_group->addHeader('spec_link', '', $specific_column);
     $spec_column = $link_column;
     foreach ($this->getSpecificities() as $field => $attributs) {
         $spec_column = $table_group->addHeader('spec_' . $field, $attributs['long name'], $specific_column, $spec_column);
         $specificity_columns[$field] = $spec_column;
     }
     $infocom_column = $table_group->addHeader('infocom', Infocom::getTypeName(Session::getPluralNumber()), $specific_column, $spec_column);
     $document_column = $table_group->addHeader('document', Document::getTypeName(Session::getPluralNumber()), $specific_column, $spec_column);
     if ($item->isDynamic()) {
         $dynamics_column = $table_group->addHeader('one', '&nbsp;', $dynamic_column, $spec_column);
         $previous_column = $dynamics_column;
     } else {
         $previous_column = $spec_column;
     }
     if ($options['canedit']) {
         $group_checkbox_tag = empty($peer_type) ? '__' : $peer_type;
         $content = Html::getCheckbox(array('criterion' => array('tag_for_massive' => $group_checkbox_tag)));
         $delete_one = $table_group->addHeader('one', $content, $delete_column, $previous_column);
     }
     if ($is_device) {
         $fk = 'items_id';
         // Entity restrict
         $leftjoin = '';
         $where = "";
         if (!empty($peer_type)) {
             $leftjoin = "LEFT JOIN `" . getTableForItemType($peer_type) . "`\n                        ON (`" . $this->getTable() . "`.`items_id` = `" . getTableForItemType($peer_type) . "`.`id`\n                            AND `" . $this->getTable() . "`.`itemtype` = '{$peer_type}')";
             $where = getEntitiesRestrictRequest(" AND", getTableForItemType($peer_type));
         }
         $query = "SELECT `" . $this->getTable() . "`.*\n                   FROM `" . $this->getTable() . "`\n                   {$leftjoin}\n                   WHERE `" . $this->getDeviceForeignKey() . "` = '" . $item->getID() . "'\n                         AND `" . $this->getTable() . "`.`itemtype` = '{$peer_type}'\n                         AND `" . $this->getTable() . "`.`is_deleted` = '0'\n                         {$where}\n                   ORDER BY `" . $this->getTable() . "`.`itemtype`, `" . $this->getTable() . "`.`{$fk}`";
     } else {
         $fk = $this->getDeviceForeignKey();
         $query = "SELECT *\n                   FROM `" . $this->getTable() . "`\n                   WHERE `itemtype` = '" . $item->getType() . "'\n                         AND `items_id` = '" . $item->getID() . "'\n                         AND `is_deleted` = '0'\n                   ORDER BY {$fk}";
     }
     if (!empty($peer_type)) {
         $peer = new $peer_type();
         $peer->getEmpty();
     } else {
         $peer = NULL;
     }
     foreach ($DB->request($query) as $link) {
         Session::addToNavigateListItems(static::getType(), $link["id"]);
         $this->getFromDB($link['id']);
         if (is_null($peer) || $link[$fk] != $peer->getID()) {
             if ($peer instanceof CommonDBTM) {
                 $peer->getFromDB($link[$fk]);
             }
             $current_row = $table_group->createRow();
             $peer_group = $peer_type . '_' . $link[$fk] . '_' . mt_rand();
             $current_row->setHTMLID($peer_group);
             if ($options['canedit']) {
                 $cell_value = Html::getCheckAllAsCheckbox($peer_group);
                 $current_row->addCell($delete_all_column, $cell_value);
             }
             if ($is_device) {
                 $cell = $current_row->addCell($peer_column, $peer ? $peer->getLink() : __('None'), NULL, $peer);
                 if (is_null($peer)) {
                     $cell->setHTMLClass('center');
                 }
             } else {
                 $peer->getHTMLTableCellForItem($current_row, $item, NULL, $options);
             }
         }
         if (Session::haveRight('device', UPDATE)) {
             $mode = __s('Update');
         } else {
             $mode = __s('View');
         }
         $spec_cell = $current_row->addCell($link_column, "<a href='" . $this->getLinkURL() . "'>{$mode}</a>");
         foreach ($this->getSpecificities() as $field => $attributs) {
             if (!empty($link[$field])) {
                 $content = $link[$field];
             } else {
                 $content = '';
             }
             $spec_cell = $current_row->addCell($specificity_columns[$field], $content, $spec_cell);
         }
         if (countElementsInTable('glpi_infocoms', "`itemtype`='" . $this->getType() . "' AND\n                                                    `items_id`='" . $link['id'] . "'")) {
             $content = array(array('function' => 'Infocom::showDisplayLink', 'parameters' => array($this->getType(), $link['id'])));
         } else {
             $content = '';
         }
         $current_row->addCell($infocom_column, $content, $spec_cell);
         $content = array();
         // The order is to be sure that specific documents appear first
         $query = "SELECT `documents_id`\n                   FROM `glpi_documents_items`\n                   WHERE (`itemtype` = '" . $this->getType() . "' AND `items_id` = '" . $link['id'] . "')\n                          OR (`itemtype` = '" . $this->getDeviceType() . "'\n                              AND `items_id` = '" . $link[$this->getDeviceForeignKey()] . "')\n                   ORDER BY `itemtype` = '" . $this->getDeviceType() . "'";
         $document = new Document();
         foreach ($DB->request($query) as $document_link) {
             if ($document->can($document_link['documents_id'], READ)) {
                 $content[] = $document->getLink();
             }
         }
         $content = implode('<br>', $content);
         $current_row->addCell($document_column, $content, $spec_cell);
         if ($item->isDynamic()) {
             $previous_cell = $current_row->addCell($dynamics_column, Dropdown::getYesNo($link['is_dynamic']), $spec_cell);
         } else {
             $previous_cell = $spec_cell;
         }
         if ($options['canedit']) {
             $cell_value = Html::getMassiveActionCheckBox($this->getType(), $link['id'], array('massive_tags' => $group_checkbox_tag));
             $current_row->addCell($delete_one, $cell_value, $previous_cell);
         }
     }
 }
예제 #6
0
 /**
  * Display form to unlock fields and links
  *
  * @param CommonDBTM $item the source item
  **/
 static function showForItem(CommonDBTM $item)
 {
     global $DB;
     $ID = $item->getID();
     $itemtype = $item->getType();
     $header = false;
     //If user doesn't have write right on the item, lock form must not be displayed
     if (!$item->canCreate()) {
         return false;
     }
     echo "<div width='50%'>";
     echo "<form method='post' id='lock_form'\n             name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<input type='hidden' name='id' value='{$ID}'>\n";
     echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>";
     //Use a hook to allow external inventory tools to manage per field lock
     $results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header));
     $header |= $results['header'];
     //Special locks for computers only
     if ($itemtype == 'Computer') {
         //Locks for items recorded in glpi_computers_items table
         $types = array('Monitor', 'Peripheral', 'Printer');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type);
             $params['FIELDS'] = array('id', 'items_id');
             $first = true;
             foreach ($DB->request('glpi_computers_items', $params) as $line) {
                 $tmp = new $type();
                 $tmp->getFromDB($line['items_id']);
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>";
                 echo "</tr>\n";
             }
         }
         $types = array('ComputerDisk', 'ComputerVirtualMachine');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
             $params['FIELDS'] = array('id', 'name');
             $first = true;
             foreach ($DB->request(getTableForItemType($type), $params) as $line) {
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $line['name'] . "</td>";
                 echo "</tr>\n";
             }
         }
         //Software versions
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwareversions` AS csv\n                    LEFT JOIN `glpi_softwareversions` AS sv\n                       ON (`csv`.`softwareversions_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
         //Software licenses
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwarelicenses` AS csv\n                    LEFT JOIN `glpi_softwarelicenses` AS sv\n                       ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
     }
     $first = true;
     $item = new NetworkPort();
     $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype);
     $params['FIELDS'] = array('id');
     foreach ($DB->request('glpi_networkports', $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new NetworkName();
     $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_networknames' => 'id');
     foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $first = true;
     $item = new IPAddress();
     $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype);
     $params['FIELDS'] = array('glpi_ipaddresses' => 'id');
     foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) {
         $item->getFromDB($line['id']);
         $header = true;
         if ($first) {
             echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n";
             $first = false;
         }
         echo "<tr class='tab_bg_1'><td class='center' width='10'>";
         echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>";
         echo "<td class='left' width='95%'>" . $item->getName() . "</td>";
         echo "</tr>\n";
     }
     $types = Item_Devices::getDeviceTypes();
     $nb = 0;
     foreach ($types as $old => $type) {
         $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n                                         AND `itemtype`='{$itemtype}'\n                                         AND `is_dynamic`='1'\n                                         AND `is_deleted`='1'");
     }
     if ($nb) {
         $header = true;
         echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n";
         foreach ($types as $old => $type) {
             $associated_type = str_replace('Item_', '', $type);
             $associated_table = getTableForItemType($associated_type);
             $fk = getForeignKeyFieldForTable($associated_table);
             $query = "SELECT `i`.`id`,\n                             `t`.`designation` AS `name`\n                      FROM `" . getTableForItemType($type) . "` AS i\n                      LEFT JOIN `{$associated_table}` AS t\n                         ON (`t`.`id` = `i`.`{$fk}`)\n                      WHERE `itemtype` = '{$itemtype}'\n                            AND `items_id` = '{$ID}'\n                            AND `is_dynamic` = '1'\n                            AND `is_deleted` = '1'";
             foreach ($DB->request($query) as $data) {
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>";
                 printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']);
                 echo "</td></tr>\n";
             }
         }
     }
     if ($header) {
         echo "</table>";
         Html::openArrowMassives('lock_form', true);
         Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock')));
     } else {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>";
         echo "</table>";
     }
     Html::closeForm();
     echo "</div>\n";
 }
예제 #7
0
 /**
  * @param $row                HTMLTableRow object (default NULL)
  * @param $item               CommonDBTM object (default NULL)
  * @param $father             HTMLTableCell object (default NULL)
  * @param $options   array
  **/
 static function getHTMLTableCellsForItem(HTMLTableRow $row = NULL, CommonDBTM $item = NULL, HTMLTableCell $father = NULL, array $options = array())
 {
     global $DB, $CFG_GLPI;
     if ($item !== NULL && $item->getType() == 'IPNetwork') {
         $queries = array();
         foreach ($CFG_GLPI["networkport_types"] as $itemtype) {
             $table = getTableForItemType($itemtype);
             $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n                                  ADDR.`binary_1` AS binary_1,\n                                  ADDR.`binary_2` AS binary_2,\n                                  ADDR.`binary_3` AS binary_3,\n                                  ADDR.`name`     AS ip,\n                                  ADDR.`id`       AS id,\n                                  ADDR.`itemtype` AS addr_item_type,\n                                  ADDR.`items_id` AS addr_item_id,\n                                  `glpi_entities`.`completename` AS entity,\n                                  NAME.`id`       AS name_id,\n                                  PORT.`id`       AS port_id,\n                                  ITEM.`id`       AS item_id,\n                                  '{$itemtype}'     AS item_type\n                           FROM `glpi_ipaddresses_ipnetworks` AS LINK\n                           JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n                                                               AND ADDR.`itemtype` = 'NetworkName'\n                                                               AND ADDR.`is_deleted` = '0')\n                           LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n                           JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n                                                                AND NAME.`itemtype` = 'NetworkPort')\n                           JOIN `glpi_networkports` AS PORT ON (NAME.`items_id` = PORT.`id`\n                                                                AND PORT.`itemtype` = '{$itemtype}')\n                           JOIN `{$table}` AS ITEM ON (ITEM.`id` = PORT.`items_id`)\n                           WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')";
         }
         $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n                               ADDR.`binary_1` AS binary_1,\n                               ADDR.`binary_2` AS binary_2,\n                               ADDR.`binary_3` AS binary_3,\n                               ADDR.`name`     AS ip,\n                               ADDR.`id`       AS id,\n                               ADDR.`itemtype` AS addr_item_type,\n                               ADDR.`items_id` AS addr_item_id,\n                               `glpi_entities`.`completename` AS entity,\n                               NAME.`id`       AS name_id,\n                               PORT.`id`       AS port_id,\n                               NULL            AS item_id,\n                               NULL            AS item_type\n                        FROM `glpi_ipaddresses_ipnetworks` AS LINK\n                        JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n                                                            AND ADDR.`itemtype` = 'NetworkName'\n                                                            AND ADDR.`is_deleted` = '0')\n                        LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n                        JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n                                                             AND NAME.`itemtype` = 'NetworkPort')\n                        JOIN `glpi_networkports` AS PORT\n                           ON (NAME.`items_id` = PORT.`id`\n                               AND PORT.`itemtype`\n                                    NOT IN ('" . implode("', '", $CFG_GLPI["networkport_types"]) . "'))\n                        WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')";
         $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n                               ADDR.`binary_1` AS binary_1,\n                               ADDR.`binary_2` AS binary_2,\n                               ADDR.`binary_3` AS binary_3,\n                               ADDR.`name`     AS ip,\n                               ADDR.`id`       AS id,\n                               ADDR.`itemtype` AS addr_item_type,\n                               ADDR.`items_id` AS addr_item_id,\n                               `glpi_entities`.`completename` AS entity,\n                               NAME.`id`       AS name_id,\n                               NULL            AS port_id,\n                               NULL            AS item_id,\n                               NULL            AS item_type\n                        FROM `glpi_ipaddresses_ipnetworks` AS LINK\n                        JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n                                                            AND ADDR.`itemtype` = 'NetworkName'\n                                                            AND ADDR.`is_deleted` = '0')\n                        LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n                        JOIN `glpi_networknames` AS NAME ON (NAME.`id` = ADDR.`items_id`\n                                                             AND NAME.`itemtype` != 'NetworkPort')\n                        WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')";
         $queries[] = "(SELECT ADDR.`binary_0` AS binary_0,\n                               ADDR.`binary_1` AS binary_1,\n                               ADDR.`binary_2` AS binary_2,\n                               ADDR.`binary_3` AS binary_3,\n                               ADDR.`name`     AS ip,\n                               ADDR.`id`       AS id,\n                               ADDR.`itemtype` AS addr_item_type,\n                               ADDR.`items_id` AS addr_item_id,\n                               `glpi_entities`.`completename` AS entity,\n                               NULL            AS name_id,\n                               NULL            AS port_id,\n                               NULL            AS item_id,\n                               NULL            AS item_type\n                        FROM `glpi_ipaddresses_ipnetworks` AS LINK\n                        JOIN `glpi_ipaddresses` AS ADDR ON (ADDR.`id` = LINK.`ipaddresses_id`\n                                                            AND ADDR.`itemtype` != 'NetworkName'\n                                                            AND ADDR.`is_deleted` = '0')\n                        LEFT JOIN `glpi_entities` ON (ADDR.`entities_id` = `glpi_entities`.`id`)\n                        WHERE LINK.`ipnetworks_id` = '" . $item->getID() . "')";
         $query = implode('UNION ', $queries);
         if ($options['order'] == 'ip' || $options['order'] == 'itemtype') {
             $query .= " ORDER BY binary_0, binary_1, binary_2, binary_3";
         }
         if (isset($options['SQL_options'])) {
             $query .= "\n" . $options['SQL_options'];
         }
         $canedit = isset($options['canedit']) && $options['canedit'];
         $options['createRow'] = false;
         $address = new self();
         $ipaddress = new self();
         $networkname = new NetworkName();
         $networkport = new NetworkPort();
         $item = NULL;
         foreach ($DB->request($query) as $line) {
             unset($row);
             if ($options['order'] == 'itemtype' && !empty($line['item_type'])) {
                 $row = $options['group_' . $line['item_type']]->createRow();
             }
             if (!isset($row)) {
                 $row = $options['group_None']->createRow();
             }
             $ip_header = $row->getGroup()->getSuperHeaderByName('IP Address');
             $item_header = $row->getGroup()->getHeaderByName('Item', 'Item');
             $port_header = $row->getGroup()->getHeaderByName('Item', 'NetworkPort');
             $name_header = $row->getGroup()->getHeaderByName('Item', 'NetworkName');
             $entity_header = $row->getGroup()->getHeaderByName('Item', 'Entity');
             $row->addCell($ip_header, $line['ip'], $father);
             if (!empty($line['name_id'])) {
                 $networkname->getFromDB($line['name_id']);
                 $row->addCell($name_header, $networkname->getLink(), $father);
                 if (!empty($line['port_id'])) {
                     $networkport->getFromDB($line['port_id']);
                     $row->addCell($port_header, $networkport->getLink(), $father);
                     if (!empty($line['item_id']) && !empty($line['item_type'])) {
                         $itemtype = $line['item_type'];
                         $item = new $itemtype();
                         $item->getFromDB($line['item_id']);
                         $row->addCell($item_header, $item->getLink(), $father);
                     }
                 }
                 $row->addCell($entity_header, $line['entity'], $father);
             } else {
                 if (!empty($line['addr_item_id']) && !empty($line['addr_item_type'])) {
                     $itemtype = $line['addr_item_type'];
                     $item = new $itemtype();
                     $item->getFromDB($line['addr_item_id']);
                     if ($item instanceof CommonDBChild) {
                         $items = $item->recursivelyGetItems();
                         $elements = array($item->getLink());
                         foreach ($items as $item_) {
                             $elements[] = $item_->getLink();
                         }
                         $row->addCell($item_header, implode(' > ', $elements), $father);
                     } else {
                         $row->addCell($item_header, $item->getLink(), $father);
                     }
                     $row->addCell($entity_header, $line['entity'], $father);
                 }
             }
         }
     } else {
         if (isset($options['dont_display']['IPAddress'])) {
             return;
         }
         $header = $row->getGroup()->getHeaderByName('Internet', __CLASS__);
         if (!$header) {
             return;
         }
         if (empty($item)) {
             if (empty($father)) {
                 return;
             }
             $item = $father->getItem();
         }
         $query = "SELECT `id`\n                                  FROM `glpi_ipaddresses`\n                                  WHERE `items_id` = '" . $item->getID() . "'\n                                        AND `itemtype` = '" . $item->getType() . "'\n                                        AND `is_deleted` = '0'";
         $canedit = isset($options['canedit']) && $options['canedit'];
         $createRow = isset($options['createRow']) && $options['createRow'];
         $options['createRow'] = false;
         $address = new self();
         foreach ($DB->request($query) as $ipaddress) {
             if ($address->getFromDB($ipaddress['id'])) {
                 if ($createRow) {
                     $row = $row->createRow();
                 }
                 $content = $address->fields['name'];
                 $this_cell = $row->addCell($header, $content, $father);
                 if (isset($options['display_isDynamic']) && $options['display_isDynamic']) {
                     $dyn_header = $row->getGroup()->getHeaderByName('Internet', __CLASS__ . '_dynamic');
                     $this_cell = $row->addCell($dyn_header, Dropdown::getYesNo($address->fields['is_dynamic']), $this_cell);
                 }
                 IPNetwork::getHTMLTableCellsForItem($row, $address, $this_cell, $options);
             }
         }
     }
 }
예제 #8
0
 static function getTableGroup(CommonDBTM $item, HTMLTableMain $table, array $options, HTMLTableSuperHeader $delete_all_column = NULL, HTMLTableSuperHeader $common_column, HTMLTableSuperHeader $specific_column, HTMLTableSuperHeader $delete_column = NULL, $dynamic_column)
 {
     global $DB;
     $device_type = static::getDeviceType();
     $table_group = $table->createGroup($device_type, '');
     //TRANS : %1$s is the type of the device
     //        %2$s is the type of the item
     //        %3$s is the name of the item (used for headings of a list),
     $options['itemtype_title'] = sprintf(__('%1$s of %2$s: %3$s'), $device_type::getTypeName(2), $item->getTypeName(1), $item->getName());
     $device_type::getHTMLTableHeader($item->getType(), $table_group, $common_column, NULL, $options);
     $spec_column = NULL;
     $specificity_columns = array();
     foreach (static::getSpecificities() as $field => $attributs) {
         $spec_column = $table_group->addHeader('spec_' . $field, $attributs['long name'], $specific_column, $spec_column);
         $specificity_columns[$field] = $spec_column;
     }
     if ($item->isDynamic()) {
         $dynamics_column = $table_group->addHeader('one', '&nbsp;', $dynamic_column, $spec_column);
         $previous_column = $dynamics_column;
     } else {
         $previous_column = $spec_column;
     }
     if ($options['canedit']) {
         $delete_one = $table_group->addHeader('one', '&nbsp;', $delete_column, $previous_column);
     }
     $fk = static::getDeviceForeignKey();
     $query = "SELECT *\n                FROM `" . static::getTable() . "`\n                WHERE `itemtype` = '" . $item->getType() . "'\n                      AND `items_id` = '" . $item->getID() . "'\n                      AND `is_deleted` = '0'\n                ORDER BY {$fk}";
     $device = new $device_type();
     $device->getEmpty();
     foreach ($DB->request($query) as $link) {
         if ($link[$fk] != $device->getID()) {
             $device->getFromDB($link[$fk]);
             $current_row = $table_group->createRow();
             $device_group = $device_type . '_' . $link[$fk] . '_' . mt_rand();
             $current_row->setHTMLID($device_group);
             if ($options['canedit']) {
                 $cell_value = Html::getCheckAllAsCheckbox($device_group);
                 $current_row->addCell($delete_all_column, $cell_value);
             }
             $device->getHTMLTableCellForItem($current_row, $item, NULL, $options);
         }
         $spec_cell = NULL;
         foreach (static::getSpecificities() as $field => $attributs) {
             $content = $link[$field];
             if ($options['canedit']) {
                 $content = "<input type='text' name='value_" . $device_type . "_" . $link['id'] . "_" . $field . "' value='{$content}' size='" . $attributs['size'] . "'>";
             }
             $spec_cell = $current_row->addCell($specificity_columns[$field], $content, $spec_cell);
         }
         if ($item->isDynamic()) {
             $previous_cell = $current_row->addCell($dynamics_column, Dropdown::getYesNo($link['is_dynamic']), $spec_cell);
         } else {
             $previous_cell = $spec_cell;
         }
         if ($options['canedit']) {
             $cell_value = "<input type='checkbox' name='remove_" . $device_type . "_" . $link['id'] . "' value='1'>";
             $current_row->addCell($delete_one, $cell_value, $previous_cell);
         }
     }
 }
 static function countForItem(CommonDBTM $item)
 {
     return countElementsInTable('glpi_plugin_webapplications_webapplications', "`suppliers_id` = '" . $item->getID() . "'");
 }
예제 #10
0
 /**
  * Display the mount toolbox
  *
  * @param CommonDBTM $item        Item referenced with the mount
  * @param string     $formName    Name of the form
  * @param string     $mountAction Action to perform
  * @param array      $data        Default data (if modified)
  * @param bool       $showDelete  Display "Delete" action button
  */
 static function rackview_mount_toolbox($item, $formName = "mountForm", $mountAction = "mount", $data = array(), $showDelete = false)
 {
     global $CFG_GLPI, $DB, $LANG;
     print '<div>';
     print '<form name="' . $formName . '" method="post" action="' . $CFG_GLPI['root_doc'] . '/plugins/rackview/front/plugin_rackview_mount.php">';
     print '<table class="tab_cadre_fixe" style="width: 100%">';
     print '<input type="hidden" name="mount_action" value="' . $mountAction . '" />';
     print '<input type="hidden" name="object_type" ' . 'value="' . $item->getType() . '" />';
     print '<input type="hidden" name="object_id" ' . 'value="' . $item->getID() . '" />';
     if (isset($data['id'])) {
         print '<input type="hidden" name="mount_id" ' . 'value="' . $data['id'] . '" />';
     }
     print '<tr class="tab_bg_1">';
     $title = $LANG['plugin_rackview']['label_addmount'];
     if (isset($data['rack_id'])) {
         // Get rack name
         $table = getTableForItemType('PluginRackviewRack');
         $rack = $DB->request($table, array('id' => $data['rack_id']));
         if ($rack->numrows() == 0) {
             Html::displayErrorAndDie($LANG['plugin_rackview']['error_invalidrackid']);
         }
         $rack = $rack->next();
         $rackLink = sprintf('<a href="%s?id=%s">%s</a>', Toolbox::getItemTypeFormURL('PluginRackviewRack'), $data['rack_id'], $rack['name']);
         $title = sprintf($LANG['plugin_rackview']['label_mount'], $rackLink);
     }
     print '<th colspan="2">' . $title . '</th>';
     print '</tr>';
     // Rack
     print '<tr>';
     print '<td title="' . $LANG['plugin_rackview']['help_rack'] . '">' . $LANG['plugin_rackview']['field_rack'] . '</td>';
     print '<td>';
     $value = -1;
     if (isset($data['rack_id'])) {
         $value = $data['rack_id'];
     }
     $mount_id = -1;
     if (isset($data['id'])) {
         $mount_id = $data['id'];
     }
     $startuCode = 'rackview_startu_';
     if (isset($data['id'])) {
         $startuCode .= $data['id'];
     } else {
         $startuCode .= 'new';
     }
     $onChangeCode = sprintf('rackview_display_rack("%s", "id", "%s", "plugin_rackview_racks_id", ' . '%d, "mini=true&startu=%s", "%s")', $CFG_GLPI["root_doc"] . '/plugins/rackview/ajax/ajax_show_rack.php', $formName, $mount_id, $startuCode, $LANG['plugin_rackview']['label_selectarack']);
     Dropdown::show('PluginRackviewRack', array('value' => $value, 'on_change' => $onChangeCode));
     print '</td>';
     print '</tr>';
     // Start-U
     print '<tr>';
     print '<td title="' . $LANG['plugin_rackview']['help_startu'] . '">' . $LANG['plugin_rackview']['field_startu'] . '</td>';
     print '<td>';
     $startuId = 'new';
     if (isset($data['id'])) {
         $startuId = $data['id'];
     }
     print '<input type="text" name="startu" id="' . 'rackview_startu_' . $startuId . '" maxlength="4" ';
     if (isset($data['startu'])) {
         print 'value="' . $data['startu'] . '"';
     }
     print '/>';
     print '</td>';
     print '</tr>';
     // Mount-Size
     print '<tr>';
     print '<td title="' . $LANG['plugin_rackview']['help_mount_size'] . '">' . $LANG['plugin_rackview']['field_mount_size'] . '</td>';
     print '<td>';
     print '<input type="checkbox" name="use_default" value="true"';
     if (!isset($data['mount_size']) || is_null($data['mount_size'])) {
         print ' checked="checked"';
     }
     $mount_size_id = 'new';
     if (isset($data['id'])) {
         $mount_size_id = $data['id'];
     }
     print sprintf('onClick = "rackview_toggle(this, \'rackview_mount_size_%s\')"', $mount_size_id);
     print '/> ' . $LANG['plugin_rackview']['label_usedefault'] . '&nbsp;';
     print sprintf('<input type="text" name="mount_size" id="rackview_mount_size_%s" ' . 'maxlength="4" ', $mount_size_id);
     if (isset($data['mount_size']) && !is_null($data['mount_size'])) {
         print 'value="' . $data['mount_size'] . '"';
     } else {
         print 'disabled="disabled"';
     }
     print '/>';
     print '</td>';
     print '</tr>';
     // Depth
     print '<tr>';
     print '<td title="' . $LANG['plugin_rackview']['help_depth'] . '">' . $LANG['plugin_rackview']['field_depth'] . '</td>';
     print '<td>';
     print '<select name="depth">';
     $value = 0;
     if (isset($data['depth'])) {
         $value = $data['depth'];
     }
     print '<option value="0"';
     if ($value == 0) {
         print 'selected="selected"';
     }
     print '>' . $LANG['plugin_rackview']['option_depth_full'] . '</option>';
     print '<option value="1"';
     if ($value == 1) {
         print 'selected="selected"';
     }
     print '>' . $LANG['plugin_rackview']['option_depth_front'] . '</option>';
     print '<option value="2"';
     if ($value == 2) {
         print 'selected="selected"';
     }
     print '>' . $LANG['plugin_rackview']['option_depth_back'] . '</option>';
     print '</select>';
     print '</td>';
     print '</tr>';
     // Horizontal
     print '<tr>';
     print '<td title="' . $LANG['plugin_rackview']['help_horizontal'] . '">' . $LANG['plugin_rackview']['field_horizontal'] . '</td>';
     print '<td>';
     print '<select name="horizontal">';
     $value = 0;
     if (isset($data['horizontal'])) {
         $value = $data['horizontal'];
     }
     print '<option value="0"';
     if ($value == 0) {
         print 'selected="selected"';
     }
     print '>' . $LANG['plugin_rackview']['option_horizontal_full'] . '</option>';
     print '<option value="1"';
     if ($value == 1) {
         print 'selected="selected"';
     }
     print '>' . $LANG['plugin_rackview']['option_horizontal_left'] . '</option>';
     print '<option value="2"';
     if ($value == 2) {
         print 'selected="selected"';
     }
     print '>' . $LANG['plugin_rackview']['option_horizontal_center'] . '</option>';
     print '<option value="3"';
     if ($value == 3) {
         print 'selected="selected"';
     }
     print '>' . $LANG['plugin_rackview']['option_horizontal_right'] . '</option>';
     print '</select>';
     print '</td>';
     print '</tr>';
     // Description
     print '<tr>';
     print '<td title="' . $LANG['plugin_rackview']['help_description'] . '">' . $LANG['plugin_rackview']['field_description'] . '</td>';
     print '<td>';
     $value = '&nbsp;';
     if (isset($data['description'])) {
         $value = $data['description'];
     }
     print '<textarea name="description" cols="40" rows="4">' . $value . '</textarea>';
     print '</td>';
     print '</tr>';
     print '<tr>';
     print '<td colspan="2" align="center">';
     // Submit
     print '<input type="submit" class="submit" value="' . $LANG['plugin_rackview']['label_update'] . '" />';
     if ($showDelete) {
         // Delete
         print '&nbsp;<input type="button" onClick="';
         print 'document.' . $formName . '.mount_action.value = \'unmount\'; ' . 'document.' . $formName . '.submit();';
         print '" class="submit" value="' . $LANG['plugin_rackview']['label_delete'] . '" />';
     }
     print '</td>';
     print '</tr>';
     print '</table>';
     Html::closeForm();
     print '</div>';
 }
 static function countForItem(CommonDBTM $item)
 {
     return countElementsInTable('glpi_plugin_databases_instances', "`plugin_databases_databases_id` = '" . $item->getID() . "'");
 }
예제 #12
0
 static function generateLinkContents($link, CommonDBTM $item)
 {
     if (strstr($link, "[EXAMPLE_ID]")) {
         $link = str_replace("[EXAMPLE_ID]", $item->getID(), $link);
         return array($link);
     }
     return parent::generateLinkContents($link, $item);
 }
예제 #13
0
 static function showForItem(CommonDBTM $item)
 {
     global $DB, $LANG;
     if (!$item->can($item->getID(), 'r')) {
         return false;
     }
     if (Session::haveRight('simcard', 'w')) {
         $url = Toolbox::getItemTypeFormURL('PluginSimcardSimcard');
         $url .= "?itemtype=" . $item->getType() . "&items_id=" . $item->getID() . "&id=-1";
         echo "<div class='center'><a href='{$url}'>" . $LANG['plugin_simcard'][10] . "</a></div><br>";
     }
     $results = getAllDatasFromTable(getTableForItemType(__CLASS__), "`items_id` = '" . $item->getID() . "' AND `itemtype`='" . get_class($item) . "'");
     echo "<div class='spaced'>";
     echo "<form id='items' name='items' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='6'>" . $LANG['document'][19] . "</th></tr>";
     if (!empty($results)) {
         echo "<tr><th></th>";
         echo "<th>" . $LANG['entity'][0] . "</th>";
         echo "<th>" . $LANG['common'][16] . "</th>";
         echo "<th>" . $LANG['common'][19] . "</th>";
         echo "<th>" . $LANG['common'][20] . "</th>";
         echo "</tr>";
         foreach ($results as $data) {
             $tmp = new PluginSimcardSimcard();
             $tmp->getFromDB($data['plugin_simcard_simcards_id']);
             echo "<tr>";
             echo "<td>";
             if (Session::haveRight('simcard', 'w')) {
                 echo "<input type='checkbox' name='todelete[" . $data['id'] . "]'>";
             }
             echo "</td>";
             echo "<td>";
             echo Dropdown::getDropdownName('glpi_entities', $tmp->fields['entities_id']);
             echo "</td>";
             echo "<td>";
             echo $tmp->getLink();
             echo "</td>";
             echo "<td>";
             echo $tmp->fields['serial'];
             echo "</td>";
             echo "<td>";
             echo $tmp->fields['otherserial'];
             echo "</td>";
             echo "</tr>";
         }
     }
     if (Session::haveRight('simcard', 'w')) {
         echo "<tr class='tab_bg_1'><td colspan='4' class='center'>";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         $used = array();
         $query = "SELECT `id`\n                   FROM `glpi_plugin_simcard_simcards`\n                   WHERE `is_template`='0'\n                      AND `id` IN (SELECT `plugin_simcard_simcards_id`\n                                   FROM `glpi_plugin_simcard_simcards_items`)";
         foreach ($DB->request($query) as $use) {
             $used[$use['id']] = $use['id'];
         }
         Dropdown::show('PluginSimcardSimcard', array('name' => "plugin_simcard_simcards_id", 'entity' => $item->fields['entities_id'], 'used' => $used));
         echo "</td>";
         echo "<td colspan='2' class='center' class='tab_bg_2'>";
         echo "<input type='submit' name='additem' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
         echo "</td></tr>";
         if (!empty($results)) {
             Html::openArrowMassives('items');
             Html::closeArrowMassives(array('delete_items' => $LANG['buttons'][10]));
         }
     }
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
예제 #14
0
 /**
  * We can add several single CommonDBChild to a given Item. In such case, we display a "+"
  * button and the fields already entered.
  * This method display the fields
  *
  * @since version 0.84
  *
  * @todo study if we cannot use these methods for the user emails
  * @see showAddChildButtonForItemForm()
  *
  * @param $item         CommonDBTM object the item on which to add the current CommenDBChild
  * @param $field_name   the name of the HTML field inside Item's form
  * @param $canedit      (default NULL) NULL to use default behaviour
  *
  * @return nothing (display only)
  **/
 static function showChildsForItemForm(CommonDBTM $item, $field_name, $canedit = NULL)
 {
     global $DB, $CFG_GLPI;
     $items_id = $item->getID();
     if (is_null($canedit)) {
         if ($item->isNewItem()) {
             if (!$item->canCreate()) {
                 return false;
             }
             $canedit = $item->canUpdate();
         } else {
             if (!$item->can($items_id, 'r')) {
                 return false;
             }
             $canedit = $item->can($items_id, "w");
         }
     }
     $lower_name = strtolower(get_called_class());
     $div_id = "add_" . $lower_name . "_to_" . $item->getType() . "_" . $items_id;
     // To be sure not to load bad datas from this table
     if ($items_id == 0) {
         $items_id = -99;
     }
     $query = "SELECT *\n                FROM `" . static::getTable() . "`\n                WHERE `" . static::$items_id . "` = '" . $item->getID() . "'";
     if (preg_match('/^itemtype/', static::$itemtype)) {
         $query .= " AND `itemtype` = '" . $item->getType() . "'";
     }
     $current_item = new static();
     if ($current_item->maybeDeleted()) {
         $query .= " AND `is_deleted` = '0'";
     }
     $count = 0;
     foreach ($DB->request($query) as $data) {
         $current_item->fields = $data;
         if ($count) {
             echo '<br>';
         }
         $count++;
         $current_item->showChildForItemForm($canedit, $field_name . "[" . $current_item->getID() . "]");
     }
     if ($canedit) {
         echo "<div id='{$div_id}'>";
         // No Child display field
         if ($count == 0) {
             $current_item->getEmpty();
             $current_item->showChildForItemForm($canedit, $field_name . "[-100]");
         }
         echo "</div>";
     }
 }
예제 #15
0
 /**
  * Update lockable fields of an item
  *
  * @param $item                     CommonDBTM object
  * @param $withtemplate    integer  withtemplate param (default '')
  *
  * @return nothing
  **/
 static function updateComputer(CommonDBTM $item, $withtemplate = '')
 {
     global $DB;
     // Manage changes for OCS if more than 1 element (date_mod)
     // Need dohistory==1 if dohistory==2 no locking fields
     if ($item->fields["is_dynamic"] && countElementsInTable('glpi_plugin_ocsinventoryng_ocslinks', "`computers_id`='" . $item->getID() . "'") && $item->dohistory == 1 && count($item->updates) > 1 && !isset($item->input["_nolock"])) {
         PluginOcsinventoryngOcsServer::mergeOcsArray($item->fields["id"], $item->updates, "computer_update");
     }
     if (isset($item->input["_auto_update_ocs"])) {
         $query = "UPDATE `glpi_plugin_ocsinventoryng_ocslinks`\n                   SET `use_auto_update` = '" . $item->input["_auto_update_ocs"] . "'\n                   WHERE `computers_id` = '" . $item->input["id"] . "'";
         $DB->query($query);
     }
 }
예제 #16
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     $input = $ma->getInput();
     switch ($ma->getAction()) {
         case 'move_under':
             if (isset($input['parent'])) {
                 $fk = $item->getForeignKeyField();
                 $parent = clone $item;
                 if (!$parent->getFromDB($input['parent'])) {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                     $ma->addMessage($parent->getErrorMessage(ERROR_NOT_FOUND));
                     return;
                 }
                 foreach ($ids as $id) {
                     if ($item->can($id, UPDATE)) {
                         // Check if parent is not a child of the original one
                         if (!in_array($parent->getID(), getSonsOf($item->getTable(), $item->getID()))) {
                             if ($item->update(array('id' => $id, $fk => $parent->getID()))) {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_COMPAT));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 $ma->addMessage($parent->getErrorMessage(ERROR_COMPAT));
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 static function countForItem(CommonDBTM $item)
 {
     return countElementsInTable('glpi_plugin_webapplications_webapplications_items', "`itemtype`='" . $item->getType() . "'\n                                   AND `items_id` = '" . $item->getID() . "'");
 }
 /**
  * @param CommonDBTM $item
  * @return int
  */
 static function countForItem(CommonDBTM $item)
 {
     return countElementsInTable('glpi_plugin_ocsinventoryng_registrykeys', "`computers_id` = '" . $item->getID() . "'");
 }
 /**
  * Get link object between 2 items
  *
  * @since version 0.84
  *
  * @param $item1 object 1
  * @param $item2 object 2
  *
  * @return boolean founded ?
  **/
 function getFromDBForItems(CommonDBTM $item1, CommonDBTM $item2)
 {
     // Check items ID
     if ($item1->getID() < 0 || $item2->getID() < 0) {
         return false;
     }
     $wheres = array();
     $wheres[] = "`" . static::$items_id_1 . "` = '" . $item1->getID() . "'";
     $wheres[] = "`" . static::$items_id_2 . "` = '" . $item2->getID() . "'";
     // Check item 1 type
     if (preg_match('/^itemtype/', static::$itemtype_1)) {
         $wheres[] = "`" . static::$itemtype_1 . "` = '" . $item1->getType() . "'";
     } else {
         if (!is_a($item1, static::$itemtype_1)) {
             return false;
         }
     }
     // Check item 1 type
     if (preg_match('/^itemtype/', static::$itemtype_2)) {
         $wheres[] = "`" . static::$itemtype_2 . "` = '" . $item2->getType() . "'";
     } else {
         if (!is_a($item2, static::$itemtype_2)) {
             return false;
         }
     }
     return $this->getFromDBByQuery("WHERE " . implode(' AND ', $wheres));
 }
예제 #20
0
 /**
  * @since version 0.90
  *
  * @param $item
  * @param $withtemplate    (default '')
  * @param $options         array
  *
  * @return boolean
  **/
 static function showAddFormForItem(CommonDBTM $item, $withtemplate = '', $options = array())
 {
     global $DB, $CFG_GLPI;
     //default options
     $params['rand'] = mt_rand();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     // find documents already associated to the item
     $doc_item = new self();
     $used_found = $doc_item->find("`items_id` = '" . $item->getID() . "'\n                                    AND `itemtype` = '" . $item->getType() . "'");
     $used = array_keys($used_found);
     $used = array_combine($used, $used);
     if ($item->canAddItem('Document') && $withtemplate < 2) {
         // 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_documents", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_documents`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         if ($item->getType() == 'Document') {
             $used[$item->getID()] = $item->getID();
         }
         echo "<div class='firstbloc'>";
         echo "<form name='documentitem_form" . $params['rand'] . "' id='documentitem_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL('Document') . "' enctype=\"multipart/form-data\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         _e('Heading');
         echo "</td><td width='20%'>";
         DocumentCategory::dropdown(array('entity' => $entities));
         echo "</td>";
         echo "<td class='right'>";
         echo "<input type='hidden' name='entities_id' value='{$entity}'>";
         echo "<input type='hidden' name='is_recursive' value='" . $item->isRecursive() . "'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
         if ($item->getType() == 'Ticket') {
             echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
         }
         echo Html::file(array('multiple' => true));
         echo "</td><td class='left'>(" . Document::getMaxUploadSize() . ")&nbsp;</td>";
         echo "<td class='center' width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n                class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         if (Document::canView() && $nb > count($used)) {
             echo "<form name='document_form" . $params['rand'] . "' id='document_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             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='" . $item->getID() . "'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
                 echo "<input type='hidden' name='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>";
             }
             Document::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate an existing document') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
 }
예제 #21
0
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tree = false)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     $type = $item->getType();
     if (!Session::haveRight("show_all_ticket", "1")) {
         return;
     }
     switch ($item->getType()) {
         case 'User':
             $restrict = "(`glpi_tickets_users`.`users_id` = '" . $item->getID() . "'\n                            AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             break;
         case 'SLA':
             $restrict = "(`slas_id` = '" . $item->getID() . "')";
             $order = '`glpi_tickets`.`due_date` DESC';
             break;
         case 'Supplier':
             $restrict = "(`glpi_suppliers_tickets`.`suppliers_id` = '" . $item->getID() . "'\n                           AND `glpi_suppliers_tickets`.`type` = " . CommonITILActor::ASSIGN . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             break;
         case 'Group':
             if ($tree) {
                 $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")";
             } else {
                 $restrict = "='" . $item->getID() . "'";
             }
             $restrict = "(`glpi_groups_tickets`.`groups_id` {$restrict}\n                            AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             break;
         default:
             $restrict = "(`items_id` = '" . $item->getID() . "'  AND `itemtype` = '{$type}')";
             $order = '`glpi_tickets`.`date_mod` DESC';
     }
     $query = "SELECT " . Ticket::getCommonSelect() . "\n                FROM glpi_tickets " . Ticket::getCommonLeftJoin() . "\n                WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                ORDER BY {$order}\n                LIMIT " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $pdf->setColumnsSize(100);
     if (!$number) {
         $pdf->displayTitle('<b>' . __('Last tickets') . '</b>');
     } else {
         $pdf->displayTitle("<b>" . sprintf(__('Last %d ticket') . "</b>", $number));
         $job = new Ticket();
         while ($data = $DB->fetch_assoc($result)) {
             if (!$job->getFromDB($data["id"])) {
                 continue;
             }
             $pdf->setColumnsAlign('center');
             $col = '<b><i>ID ' . $job->fields["id"] . '</i></b>, ' . sprintf(__('%1$s: %2$s'), __('Status'), Ticket::getStatus($job->fields["status"]));
             if (count($_SESSION["glpiactiveentities"]) > 1) {
                 if ($job->fields['entities_id'] == 0) {
                     $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity'));
                 } else {
                     $col = sprintf(__('%1$s (%2$s)'), $col, Dropdown::getDropdownName("glpi_entities", $job->fields['entities_id']));
                 }
             }
             $pdf->displayLine($col);
             $pdf->setColumnsAlign('left');
             $col = '<b><i>' . sprintf(__('Opened on %s') . '</i></b>', Html::convDateTime($job->fields['date']));
             if ($job->fields['begin_waiting_date']) {
                 $col = sprintf(__('%1$s, %2$s'), $col, '<b><i>' . sprintf(__('Put on hold on %s') . '</i></b>', Html::convDateTime($job->fields['begin_waiting_date'])));
             }
             if (in_array($job->fields["status"], $job->getSolvedStatusArray()) || in_array($job->fields["status"], $job->getClosedStatusArray())) {
                 $col = sprintf(__('%1$s, %2$s'), $col, '<b><i>' . sprintf(__('Solved on %s') . '</i></b>', Html::convDateTime($job->fields['solvedate'])));
             }
             if (in_array($job->fields["status"], $job->getClosedStatusArray())) {
                 $col = sprintf(__('%1$s, %2$s'), $col, '<b><i>' . sprintf(__('Closed on %s') . '</i></b>', Html::convDateTime($job->fields['closedate'])));
             }
             if ($job->fields['due_date']) {
                 $col = sprintf(__('%1$s, %2$s'), $col, '<b><i>' . sprintf(__('%1$s: %2$s') . '</i></b>', __('Due date'), Html::convDateTime($job->fields['due_date'])));
             }
             $pdf->displayLine($col);
             $col = '<b><i>' . sprintf(__('%1$s: %2$s'), __('Priority') . '</i></b>', Ticket::getPriorityName($job->fields["priority"]));
             if ($job->fields["itilcategories_id"]) {
                 $col = sprintf(__('%1$s - %2$s'), $col, '<b><i>' . sprintf(__('%1$s: %2$s') . '</i></b>', __('Category'), Dropdown::getDropdownName('glpi_itilcategories', $job->fields["itilcategories_id"])));
             }
             $pdf->displayLine($col);
             $col = '';
             $users = $job->getUsers(CommonITILActor::REQUESTER);
             if (count($users)) {
                 foreach ($users as $d) {
                     if (empty($col)) {
                         $col = getUserName($d['users_id']);
                     } else {
                         $col = sprintf(__('%1$s, %2$s'), $col, getUserName($d['users_id']));
                     }
                 }
             }
             $grps = $job->getGroups(CommonITILActor::REQUESTER);
             if (count($grps)) {
                 if (empty($col)) {
                     $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' </i></b>');
                 } else {
                     $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' </i></b>');
                 }
                 $first = true;
                 foreach ($grps as $d) {
                     if ($first) {
                         $col = sprintf(__('%1$s  %2$s'), $col, Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
                     } else {
                         $col = sprintf(__('%1$s, %2$s'), $col, Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
                     }
                     $first = false;
                 }
             }
             if ($col) {
                 $texte = '<b><i>' . sprintf(__('%1$s: %2$s'), __('Requester') . '</i></b>', '');
                 $pdf->displayText($texte, $col, 1);
             }
             $col = '';
             $users = $job->getUsers(CommonITILActor::ASSIGN);
             if (count($users)) {
                 foreach ($users as $d) {
                     if (empty($col)) {
                         $col = getUserName($d['users_id']);
                     } else {
                         $col = sprintf(__('%1$s, %2$s'), $col, getUserName($d['users_id']));
                     }
                 }
             }
             $grps = $job->getGroups(CommonITILActor::ASSIGN);
             if (count($grps)) {
                 if (empty($col)) {
                     $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' </i></b>');
                 } else {
                     $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' </i></b>');
                 }
                 $first = true;
                 foreach ($grps as $d) {
                     if ($first) {
                         $col = sprintf(__('%1$s  %2$s'), $col, Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
                     } else {
                         $col = sprintf(__('%1$s, %2$s'), $col, Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
                     }
                     $first = false;
                 }
             }
             if ($col) {
                 $texte = '<b><i>' . sprintf(__('%1$s: %2$s') . '</i></b>', 'Assigned to', '');
                 $pdf->displayText($texte, $col, 1);
             }
             $texte = '<b><i>' . sprintf(__('%1$s: %2$s') . '</i></b>', 'Title', '');
             $pdf->displayText($texte, $job->fields["name"], 1);
         }
     }
     $pdf->displaySpace();
 }
 /**
  * Summary of preItemUpdate
  * will add or update record in DB
  * @param CommonDBTM $parm 
  */
 static function preItemUpdate(CommonDBTM $parm)
 {
     global $DB;
     if ($parm->getType() == 'User' && isset($parm->input['plugin_timezones_users_timezone'])) {
         //$query = "REPLACE INTO `glpi_plugin_timezones_users` (`users_id`, `timezone`) VALUES (".$parm->getID().", '".$parm->input['plugin_timezones_users_timezone']."');";
         //$DB->query( $query ) ;
         $tzUser = new self();
         $data = array('users_id' => $parm->getID(), 'timezone' => $parm->input['plugin_timezones_users_timezone']);
         //check if datas already inserted
         $found = $tzUser->getIDFromUserID($parm->getID());
         if (!$found) {
             $tzUser->add($data);
         } else {
             $data['id'] = $found;
             $tzUser->update($data);
         }
     }
 }
예제 #23
0
 /**
  * Display tickets for an item
  *
  * Will also display tickets of linked items
  *
  * @param $item CommonDBTM object
  *
  * @return nothing (display a table)
  **/
 static function showListForItem(CommonDBTM $item)
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRightsOr(self::$rightname, array(self::READALL, self::READMY, self::READASSIGN, CREATE))) {
         return false;
     }
     if ($item->isNewID($item->getID())) {
         return false;
     }
     $restrict = '';
     $order = '';
     $options['reset'] = 'reset';
     switch ($item->getType()) {
         case 'User':
             $restrict = "(`glpi_tickets_users`.`users_id` = '" . $item->getID() . "' " . " AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             $options['reset'] = 'reset';
             $options['criteria'][0]['field'] = 4;
             // status
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         case 'SLT':
             $restrict = "`slts_tto_id` = '" . $item->getID() . "'\n                           OR `slts_ttr_id` = '" . $item->getID() . "'";
             $order = '`glpi_tickets`.`due_date` DESC';
             $options['criteria'][0]['field'] = 30;
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         case 'Supplier':
             $restrict = "(`glpi_suppliers_tickets`.`suppliers_id` = '" . $item->getID() . "' " . "  AND `glpi_suppliers_tickets`.`type` = " . CommonITILActor::ASSIGN . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 6;
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         case 'Group':
             // Mini search engine
             if ($item->haveChildren()) {
                 $tree = Session::getSavedOption(__CLASS__, 'tree', 0);
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr class='tab_bg_1'><th>" . __('Last tickets') . "</th></tr>";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 echo __('Child groups') . "&nbsp;";
                 Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)'));
             } else {
                 $tree = 0;
             }
             echo "</td></tr></table>";
             if ($tree) {
                 $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")";
             } else {
                 $restrict = "='" . $item->getID() . "'";
             }
             $restrict = "(`glpi_groups_tickets`.`groups_id` {$restrict}" . " AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 71;
             $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         default:
             $restrict = "(`glpi_items_tickets`.`items_id` = '" . $item->getID() . "' " . " AND `glpi_items_tickets`.`itemtype` = '" . $item->getType() . "')";
             // you can only see your tickets
             if (!Session::haveRight(self::$rightname, self::READALL)) {
                 $restrict .= " AND (`glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "'\n                                   OR (`glpi_tickets_users`.`tickets_id` = '" . $item->getID() . "'\n                                       AND `glpi_tickets_users`.`users_id`\n                                            = '" . Session::getLoginUserID() . "'))";
             }
             $order = '`glpi_tickets`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 12;
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = 'all';
             $options['criteria'][0]['link'] = 'AND';
             $options['metacriteria'][0]['itemtype'] = $item->getType();
             $options['metacriteria'][0]['field'] = Search::getOptionNumber($item->getType(), 'id');
             $options['metacriteria'][0]['searchtype'] = 'equals';
             $options['metacriteria'][0]['value'] = $item->getID();
             $options['metacriteria'][0]['link'] = 'AND';
             break;
     }
     $query = "SELECT " . self::getCommonSelect() . "\n                FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n                WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                ORDER BY {$order}\n                LIMIT " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $colspan = 11;
     if (count($_SESSION["glpiactiveentities"]) > 1) {
         $colspan++;
     }
     // Ticket for the item
     echo "<div class='firstbloc'>";
     // Link to open a new ticket
     if ($item->getID() && Ticket::isPossibleToAssignType($item->getType()) && self::canCreate()) {
         Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('itemtype' => $item->getType(), 'items_id' => $item->getID()));
     }
     echo "</div><div>";
     if ($number > 0) {
         echo "<table class='tab_cadre_fixehov'>";
         if (Session::haveRight(self::$rightname, self::READALL)) {
             Session::initNavigateListItems('Ticket', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
             echo "<tr class='noHover'><th colspan='{$colspan}'>";
             $title = sprintf(_n('Last %d ticket', 'Last %d tickets', $number), $number);
             $link = "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&amp;') . "'>" . __('Show all') . "</a>";
             $title = printf(__('%1$s (%2$s)'), $title, $link);
             echo "</th></tr>";
         } else {
             echo "<tr><th colspan='{$colspan}'>" . __("You don't have right to see all tickets") . "</th></tr>";
         }
     } else {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . __('No ticket found.') . "</th></tr>";
     }
     if ($item->getID() && $item->getType() == 'User' && self::canCreate()) {
         echo "<tr><td class='tab_bg_2 center b' colspan='{$colspan}'>";
         Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/ticket.form.php", '_add_fromitem', __('New ticket for this item...'), array('_users_id_requester' => $item->getID()));
         echo "</td></tr>";
     }
     // Ticket list
     if ($number > 0) {
         self::commonListHeader(Search::HTML_OUTPUT);
         while ($data = $DB->fetch_assoc($result)) {
             Session::addToNavigateListItems('Ticket', $data["id"]);
             self::showShort($data["id"]);
         }
         self::commonListHeader(Search::HTML_OUTPUT);
     }
     echo "</table></div>";
     // Tickets for linked items
     $linkeditems = $item->getLinkedItems();
     $restrict = array();
     if (count($linkeditems)) {
         foreach ($linkeditems as $ltype => $tab) {
             foreach ($tab as $lID) {
                 $restrict[] = "(`glpi_items_tickets`.`itemtype` = '{$ltype}' AND `glpi_items_tickets`.`items_id` = '{$lID}')";
             }
         }
     }
     if (count($restrict) && Session::haveRight(self::$rightname, self::READALL)) {
         $query = "SELECT " . self::getCommonSelect() . "\n                   FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n                   WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_tickets') . "\n                   ORDER BY `glpi_tickets`.`date_mod` DESC\n                   LIMIT " . intval($_SESSION['glpilist_limit']);
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='12'>";
         echo _n('Ticket on linked items', 'Tickets on linked items', $number);
         echo "</th></tr>";
         if ($number > 0) {
             self::commonListHeader(Search::HTML_OUTPUT);
             while ($data = $DB->fetch_assoc($result)) {
                 // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]);
                 self::showShort($data["id"]);
             }
             self::commonListHeader(Search::HTML_OUTPUT);
         } else {
             echo "<tr><th>" . __('No ticket found.') . "</th></tr>";
         }
         echo "</table></div>";
     }
     // Subquery for linked item
 }
 function showForm(CommonDBTM $item, $options = array())
 {
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     $rand = mt_rand();
     $a_data = getAllDatasFromTable('glpi_plugin_fusioninventory_ipranges_configsecurities', "`plugin_fusioninventory_ipranges_id`='" . $item->getID() . "'", false, '`rank`');
     $a_used = array();
     foreach ($a_data as $data) {
         $a_used[] = $data['plugin_fusioninventory_configsecurities_id'];
     }
     echo "<div class='firstbloc'>";
     echo "<form name='iprange_configsecurity_form{$rand}' id='iprange_configsecurity_form{$rand}' method='post'\n             action='" . Toolbox::getItemTypeFormURL('PluginFusioninventoryIPRange_ConfigSecurity') . "' >";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_2'>";
     echo "<th colspan='2'>" . __('Add a SNMP authentication') . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>";
     Dropdown::show('PluginFusioninventoryConfigSecurity', array('used' => $a_used));
     echo "</td>";
     echo "<td>";
     echo Html::hidden('plugin_fusioninventory_ipranges_id', array('value' => $item->getID()));
     echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate') . "\" class='submit'>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
     // Display list of auth associated with IP range
     $rand = mt_rand();
     echo "<div class='spaced'>";
     Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
     $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand);
     Html::showMassiveActions($massiveactionparams);
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_2'>";
     echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     echo "<th>";
     echo __('SNMP Authentication', 'fusioninventory');
     echo "</th>";
     echo "<th>";
     echo __('Version', 'fusioninventory');
     echo "</th>";
     echo "<th>";
     echo __('Rank');
     echo "</th>";
     echo "</tr>";
     $pfConfigSecurity = new PluginFusioninventoryConfigSecurity();
     foreach ($a_data as $data) {
         echo "<tr class='tab_bg_2'>";
         echo "<td>";
         Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
         echo "</td>";
         echo "<td>";
         $pfConfigSecurity->getFromDB($data['plugin_fusioninventory_configsecurities_id']);
         echo $pfConfigSecurity->getLink();
         echo "</td>";
         echo "<td>";
         echo $pfConfigSecurity->getSNMPVersion($pfConfigSecurity->fields['snmpversion']);
         echo "</td>";
         echo "<td>";
         echo $data['rank'];
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
     $massiveactionparams['ontop'] = false;
     Html::showMassiveActions($massiveactionparams);
     echo "</div>";
 }
예제 #25
0
 /**
  * @param $item      CommonDBTM object
  **/
 static function countForItem(CommonDBTM $item)
 {
     global $DB;
     switch ($item->getType()) {
         case 'FQDN':
             return countElementsInTable('glpi_networknames', "`fqdns_id` = '" . $item->fields["id"] . "'\n                                             AND `is_deleted` = '0'");
         case 'NetworkPort':
             return countElementsInTable('glpi_networknames', "itemtype = '" . $item->getType() . "'\n                                             AND items_id = '" . $item->getID() . "'\n                                             AND `is_deleted` = '0'");
         case 'NetworkEquipment':
             $query = "SELECT DISTINCT COUNT(*) AS cpt\n                      FROM `glpi_networknames`, `glpi_networkports`\n                      WHERE `glpi_networkports`.`itemtype` = '" . $item->getType() . "'\n                            AND `glpi_networkports`.`items_id` ='" . $item->getID() . "'\n                            AND `glpi_networkports`.`is_deleted` ='0'\n                            AND `glpi_networknames`.`itemtype` = 'NetworkPort'\n                            AND `glpi_networknames`.`items_id` = `glpi_networkports`.`id`\n                            AND `glpi_networknames`.`is_deleted` = '0'";
             $result = $DB->query($query);
             $ligne = $DB->fetch_assoc($result);
             return $ligne['cpt'];
     }
 }
예제 #26
0
 /**
  * Show Links for an item
  *
  * @param $item                     CommonDBTM object
  * @param $withtemplate    integer  withtemplate param (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight("link", "r")) {
         return false;
     }
     if ($item->isNewID($item->getID())) {
         return false;
     }
     $query = "SELECT `glpi_links`.`id`,\n                       `glpi_links`.`link` AS link,\n                       `glpi_links`.`name` AS name ,\n                       `glpi_links`.`data` AS data\n                FROM `glpi_links`\n                INNER JOIN `glpi_links_itemtypes`\n                     ON `glpi_links`.`id` = `glpi_links_itemtypes`.`links_id`\n                WHERE `glpi_links_itemtypes`.`itemtype`='" . $item->getType() . "' " . getEntitiesRestrictRequest(" AND", "glpi_links", "entities_id", $item->getEntityID(), true) . "\n                ORDER BY name";
     $result = $DB->query($query);
     echo "<div class='spaced'><table class='tab_cadre_fixe'>";
     if ($DB->numrows($result) > 0) {
         echo "<tr><th>" . self::getTypeName(2) . "</th></tr>";
         while ($data = $DB->fetch_assoc($result)) {
             $name = $data["name"];
             if (empty($name)) {
                 $name = $data["link"];
             }
             $names = self::generateLinkContents($name, $item);
             $file = trim($data["data"]);
             if (empty($file)) {
                 // Generate links
                 $links = self::generateLinkContents($data['link'], $item);
                 $i = 1;
                 foreach ($links as $key => $link) {
                     $name = isset($names[$key]) ? $names[$key] : reset($names);
                     echo "<tr class='tab_bg_2'>";
                     $url = $link;
                     echo "<td class='center'><a href='{$url}' target='_blank'>";
                     $linkname = sprintf(__('%1$s #%2$s'), $name, $i);
                     $linkname = printf(__('%1$s: %2$s'), $linkname, $link);
                     echo "</a></td></tr>";
                     $i++;
                 }
             } else {
                 // Generate files
                 $files = self::generateLinkContents($data['link'], $item);
                 $links = self::generateLinkContents($data['data'], $item);
                 $i = 1;
                 foreach ($links as $key => $link) {
                     $name = isset($names[$key]) ? $names[$key] : reset($names);
                     if (isset($files[$key])) {
                         // a different name for each file, ex name = foo-[IP].txt
                         $file = $files[$key];
                     } else {
                         // same name for all files, ex name = foo.txt
                         $file = reset($files);
                     }
                     echo "<tr class='tab_bg_2'>";
                     $url = $CFG_GLPI["root_doc"] . "/front/link.send.php?lID=" . $data['id'] . "&amp;itemtype=" . $item->getType() . "&amp;id=" . $item->getID() . "&amp;rank={$key}";
                     echo "<td class='center'><a href='{$url}' target='_blank'>";
                     $linkname = sprintf(__('%1$s #%2$s'), $name, $i);
                     $linkname = printf(__('%1$s: %2$s'), $linkname, $file);
                     echo "</a></td></tr>";
                     $i++;
                 }
             }
         }
         echo "</table></div>";
     } else {
         echo "<tr class='tab_bg_2'><th>" . self::getTypeName(2) . "</th></tr>";
         echo "<tr class='tab_bg_2'><td class='center b'>" . __('No link defined') . "</td></tr>";
         echo "</table></div>";
     }
 }
예제 #27
0
 /**
  * Display changes for an item
  *
  * Will also display changes of linked items
  *
  * @param $item CommonDBTM object
  *
  * @return nothing (display a table)
  **/
 static function showListForItem(CommonDBTM $item)
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight(self::$rightname, self::READALL)) {
         return false;
     }
     if ($item->isNewID($item->getID())) {
         return false;
     }
     $restrict = '';
     $order = '';
     $options['reset'] = 'reset';
     switch ($item->getType()) {
         case 'User':
             $restrict = "(`glpi_changes_users`.`users_id` = '" . $item->getID() . "')";
             $order = '`glpi_changes`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 4;
             // status
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'OR';
             $options['criteria'][1]['field'] = 66;
             // status
             $options['criteria'][1]['searchtype'] = 'equals';
             $options['criteria'][1]['value'] = $item->getID();
             $options['criteria'][1]['link'] = 'OR';
             $options['criteria'][5]['field'] = 5;
             // status
             $options['criteria'][5]['searchtype'] = 'equals';
             $options['criteria'][5]['value'] = $item->getID();
             $options['criteria'][5]['link'] = 'OR';
             break;
         case 'Supplier':
             $restrict = "(`glpi_changes_suppliers`.`suppliers_id` = '" . $item->getID() . "')";
             $order = '`glpi_changes`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 6;
             $options['criteria'][0]['searchtype'] = 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         case 'Group':
             // Mini search engine
             if ($item->haveChildren()) {
                 $tree = Session::getSavedOption(__CLASS__, 'tree', 0);
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr class='tab_bg_1'><th>" . __('Last changes') . "</th></tr>";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 _e('Child groups');
                 Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)'));
             } else {
                 $tree = 0;
             }
             echo "</td></tr></table>";
             if ($tree) {
                 $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")";
             } else {
                 $restrict = "='" . $item->getID() . "'";
             }
             $restrict = "(`glpi_changes_groups`.`groups_id` {$restrict}\n                            AND `glpi_changes_groups`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_changes`.`date_mod` DESC';
             $options['criteria'][0]['field'] = 71;
             $options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals';
             $options['criteria'][0]['value'] = $item->getID();
             $options['criteria'][0]['link'] = 'AND';
             break;
         default:
             $restrict = "(`items_id` = '" . $item->getID() . "'\n                            AND `itemtype` = '" . $item->getType() . "')";
             $order = '`glpi_changes`.`date_mod` DESC';
             break;
     }
     $query = "SELECT " . self::getCommonSelect() . "\n                FROM `glpi_changes`\n                LEFT JOIN `glpi_changes_items`\n                  ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n                WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n                ORDER BY {$order}\n                LIMIT " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     // Ticket for the item
     echo "<div class='firstbloc'><table class='tab_cadre_fixe'>";
     $colspan = 11;
     if (count($_SESSION["glpiactiveentities"]) > 1) {
         $colspan++;
     }
     if ($number > 0) {
         Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         echo "<tr><th colspan='{$colspan}'>";
         //TRANS : %d is the number of problems
         echo sprintf(_n('Last %d change', 'Last %d changes', $number), $number);
         //             echo "<span class='small_space'><a href='".$CFG_GLPI["root_doc"]."/front/ticket.php?".
         //                    Toolbox::append_params($options,'&amp;')."'>".__('Show all')."</a></span>";
         echo "</th></tr>";
     } else {
         echo "<tr><th>" . __('No change found.') . "</th></tr>";
     }
     // Ticket list
     if ($number > 0) {
         self::commonListHeader(Search::HTML_OUTPUT);
         while ($data = $DB->fetch_assoc($result)) {
             Session::addToNavigateListItems('Problem', $data["id"]);
             self::showShort($data["id"]);
         }
         self::commonListHeader(Search::HTML_OUTPUT);
     }
     echo "</table></div>";
     // Tickets for linked items
     $linkeditems = $item->getLinkedItems();
     $restrict = array();
     if (count($linkeditems)) {
         foreach ($linkeditems as $ltype => $tab) {
             foreach ($tab as $lID) {
                 $restrict[] = "(`itemtype` = '{$ltype}' AND `items_id` = '{$lID}')";
             }
         }
     }
     if (count($restrict)) {
         $query = "SELECT " . self::getCommonSelect() . "\n                   FROM `glpi_changes`\n                   LEFT JOIN `glpi_changes_items`\n                        ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n                   WHERE " . implode(' OR ', $restrict) . getEntitiesRestrictRequest(' AND ', 'glpi_changes') . "\n                   ORDER BY `glpi_changes`.`date_mod` DESC\n                   LIMIT " . intval($_SESSION['glpilist_limit']);
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='{$colspan}'>";
         _e('Changes on linked items');
         echo "</th></tr>";
         if ($number > 0) {
             self::commonListHeader(Search::HTML_OUTPUT);
             while ($data = $DB->fetch_assoc($result)) {
                 // Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]);
                 self::showShort($data["id"]);
             }
             self::commonListHeader(Search::HTML_OUTPUT);
         } else {
             echo "<tr><th>" . __('No change found.') . "</th></tr>";
         }
         echo "</table></div>";
     }
     // Subquery for linked item
 }
예제 #28
0
 /**
  * @param $item   CommonDBTM object
  **/
 static function getAllForItem(CommonDBTM $item)
 {
     global $DB;
     $data = array();
     $query = "SELECT `glpi_notepads`.*, `glpi_users`.`picture`\n                FROM `glpi_notepads`\n                LEFT JOIN `glpi_users` ON (`glpi_notepads`.`users_id_lastupdater` = `glpi_users`.`id`)\n                WHERE `glpi_notepads`.`itemtype` = '" . $item->getType() . "'\n                     AND `glpi_notepads`.`items_id` = '" . $item->getID() . "'\n                ORDER BY `date_mod` DESC";
     foreach ($DB->request($query) as $note) {
         $data[] = $note;
     }
     return $data;
 }
예제 #29
0
 /**
  * @param $item   CommonDBTM object
  **/
 static function showActivationFormForItem(CommonDBTM $item)
 {
     if (!self::canUpdate()) {
         return false;
     }
     if ($item->getID()) {
         // Recursive type case => need entity right
         if ($item->isRecursive()) {
             if (!Session::haveAccessToEntity($item->fields["entities_id"])) {
                 return false;
             }
         }
     } else {
         return false;
     }
     $ri = new self();
     echo "<div>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . __('Reserve an item') . "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     if ($ri->getFromDBbyItem($item->getType(), $item->getID())) {
         echo "<td class='center'>";
         //Switch reservation state
         if ($ri->fields["is_active"]) {
             Html::showSimpleForm(static::getFormURL(), 'update', __('Make unavailable'), array('id' => $ri->fields['id'], 'is_active' => 0));
         } else {
             Html::showSimpleForm(static::getFormURL(), 'update', __('Make available'), array('id' => $ri->fields['id'], 'is_active' => 1));
         }
         echo '</td><td>';
         Html::showSimpleForm(static::getFormURL(), 'purge', __('Prohibit reservations'), array('id' => $ri->fields['id']), '', '', array(__('Are you sure you want to return this non-reservable item?'), __('That will remove all the reservations in progress.')));
         echo "</td>";
     } else {
         echo "<td class='center'>";
         Html::showSimpleForm(static::getFormURL(), 'add', __('Authorize reservations'), array('items_id' => $item->getID(), 'itemtype' => $item->getType(), 'entities_id' => $item->getEntityID(), 'is_recursive' => $item->isRecursive()));
         echo "</td>";
     }
     echo "</tr></table>";
     echo "</div>";
 }
예제 #30
0
 /**
  * Close linked tickets when ticket passed in parameter is closed
  * @param  CommonDBTM $item the ticket object
  * @return nothing
  */
 static function linkedTickets(CommonDBTM $ticket, $status = CommonITILObject::SOLVED)
 {
     if ($_SESSION['plugins']['escalade']['config']['close_linkedtickets']) {
         $input = array('status' => $status);
         $tickets = Ticket_Ticket::getLinkedTicketsTo($ticket->getID());
         if (count($tickets)) {
             foreach ($tickets as $data) {
                 $input['id'] = $data['tickets_id'];
                 if ($ticket->can($input['id'], UPDATE) && $data['link'] == Ticket_Ticket::DUPLICATE_WITH) {
                     $ticket->update($input);
                 }
             }
         }
     }
 }