コード例 #1
1
ファイル: search.class.php プロジェクト: jose-martins/glpi
 /**
  * Display datas extracted from DB
  *
  * @param $data array of search datas prepared to get datas
  *
  * @return nothing
  **/
 static function displayDatas(array &$data)
 {
     global $CFG_GLPI;
     $item = null;
     if (class_exists($data['itemtype'])) {
         $item = new $data['itemtype']();
     }
     $rand = mt_rand();
     if (!isset($data['data']) || !isset($data['data']['totalcount'])) {
         return false;
     }
     // Contruct Pager parameters
     $globallinkto = Toolbox::append_params(array('criteria' => Toolbox::stripslashes_deep($data['search']['criteria']), 'metacriteria' => Toolbox::stripslashes_deep($data['search']['metacriteria'])), '&');
     $parameters = "sort=" . $data['search']['sort'] . "&order=" . $data['search']['order'] . '&' . $globallinkto;
     if (isset($_GET['_in_modal'])) {
         $parameters .= "&_in_modal=1";
     }
     // Global search header
     if ($data['display_type'] == self::GLOBAL_SEARCH) {
         if ($data['item']) {
             echo "<div class='center'><h2>" . $data['item']->getTypeName();
             // More items
             if ($data['data']['totalcount'] > $data['search']['start'] + self::GLOBAL_DISPLAY_COUNT) {
                 echo " <a href='" . $data['search']['target'] . "?{$parameters}'>" . __('All') . "</a>";
             }
             echo "</h2></div>\n";
         } else {
             return false;
         }
     }
     // If the begin of the view is before the number of items
     if ($data['data']['count'] > 0) {
         // Display pager only for HTML
         if ($data['display_type'] == self::HTML_OUTPUT) {
             // For plugin add new parameter if available
             if ($plug = isPluginItemType($data['itemtype'])) {
                 $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport';
                 if (function_exists($function)) {
                     $out = $function($data['itemtype']);
                     if (is_array($out) && count($out)) {
                         $parameters .= Toolbox::append_params($out, '&amp;');
                     }
                 }
             }
             $search_config_top = "";
             $search_config_bottom = "";
             if (!isset($_GET['_in_modal']) && Session::haveRightsOr('search_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL))) {
                 $search_config_top = $search_config_bottom = "<div class='pager_controls'><img alt=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                 $search_config_top .= " class='pointer' onClick=\"";
                 $search_config_top .= Html::jsGetElementbyID('search_config_top') . ".dialog('open');\">";
                 $search_config_bottom .= " class='pointer' onClick=\"";
                 $search_config_bottom .= Html::jsGetElementbyID('search_config_bottom') . ".dialog('open');\">";
                 $search_config_top .= Ajax::createIframeModalWindow('search_config_top', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false));
                 $search_config_bottom .= Ajax::createIframeModalWindow('search_config_bottom', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false));
             }
             if ($item !== null && $item->maybeDeleted()) {
                 $delete_ctrl = self::isDeletedSwitch($data['search']['is_deleted']);
                 $search_config_top .= $delete_ctrl;
             }
             Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, $data['itemtype'], 0, $search_config_top);
             $search_config_top .= "</div>";
             $search_config_bottom .= "</div>";
         }
         // Define begin and end var for loop
         // Search case
         $begin_display = $data['data']['begin'];
         $end_display = $data['data']['end'];
         // Form to massive actions
         $isadmin = $data['item'] && $data['item']->canUpdate();
         if (!$isadmin && InfoCom::canApplyOn($data['itemtype'])) {
             $isadmin = Infocom::canUpdate() || Infocom::canCreate();
         }
         if ($data['itemtype'] != 'AllAssets') {
             $showmassiveactions = count(MassiveAction::getAllMassiveActions($data['item'], $data['search']['is_deleted']));
         } else {
             $showmassiveactions = true;
         }
         $massformid = 'massform' . $data['itemtype'];
         if ($showmassiveactions && $data['display_type'] == self::HTML_OUTPUT) {
             Html::openMassiveActionsForm($massformid);
             $massiveactionparams = $data['search']['massiveactionparams'];
             $massiveactionparams['num_displayed'] = $end_display - $begin_display;
             $massiveactionparams['fixed'] = false;
             $massiveactionparams['is_deleted'] = $data['search']['is_deleted'];
             $massiveactionparams['container'] = $massformid;
             Html::showMassiveActions($massiveactionparams);
         }
         // Compute number of columns to display
         // Add toview elements
         $nbcols = count($data['data']['cols']);
         if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
             // HTML display - massive modif
             $nbcols++;
         }
         // Display List Header
         echo self::showHeader($data['display_type'], $end_display - $begin_display + 1, $nbcols);
         // New Line for Header Items Line
         $headers_line = '';
         $headers_line_top = '';
         $headers_line_bottom = '';
         $headers_line_top .= self::showBeginHeader($data['display_type']);
         $headers_line_top .= self::showNewLine($data['display_type']);
         if ($data['display_type'] == self::HTML_OUTPUT) {
             //          $headers_line_bottom .= self::showBeginHeader($data['display_type']);
             $headers_line_bottom .= self::showNewLine($data['display_type']);
         }
         $header_num = 1;
         if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
             // HTML display - massive modif
             $headers_line_top .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']);
             if ($data['display_type'] == self::HTML_OUTPUT) {
                 $headers_line_bottom .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']);
             }
         }
         // Display column Headers for toview items
         $metanames = array();
         foreach ($data['data']['cols'] as $key => $val) {
             $linkto = '';
             if (!$val['meta'] && (!isset($val['searchopt']['nosort']) || !$val['searchopt']['nosort'])) {
                 $linkto = $data['search']['target'] . (strpos($data['search']['target'], '?') ? '&amp;' : '?') . "itemtype=" . $data['itemtype'] . "&amp;sort=" . $val['id'] . "&amp;order=" . ($data['search']['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $data['search']['start'] . "&amp;" . $globallinkto;
             }
             $name = $val["name"];
             // prefix by group name (corresponding to optgroup in dropdown) if exists
             if (isset($val['groupname'])) {
                 $name = $val['groupname'] . " - " . $name;
             }
             // Not main itemtype add itemtype to display
             if ($data['itemtype'] != $val['itemtype']) {
                 if (!isset($metanames[$val['itemtype']])) {
                     if ($metaitem = getItemForItemtype($val['itemtype'])) {
                         $metanames[$val['itemtype']] = $metaitem->getTypeName();
                     }
                 }
                 $name = sprintf(__('%1$s - %2$s'), $metanames[$val['itemtype']], $val["name"]);
             }
             $headers_line .= self::showHeaderItem($data['display_type'], $name, $header_num, $linkto, !$val['meta'] && $data['search']['sort'] == $val['id'], $data['search']['order']);
         }
         // Add specific column Header
         if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
             $headers_line .= self::showHeaderItem($data['display_type'], __('Item type'), $header_num);
         }
         // End Line for column headers
         $headers_line .= self::showEndLine($data['display_type']);
         $headers_line_top .= $headers_line;
         if ($data['display_type'] == self::HTML_OUTPUT) {
             $headers_line_bottom .= $headers_line;
         }
         $headers_line_top .= self::showEndHeader($data['display_type']);
         //          $headers_line_bottom .= self::showEndHeader($data['display_type']);
         echo $headers_line_top;
         // Init list of items displayed
         if ($data['display_type'] == self::HTML_OUTPUT) {
             Session::initNavigateListItems($data['itemtype']);
         }
         // Num of the row (1=header_line)
         $row_num = 1;
         $massiveaction_field = 'id';
         if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
             $massiveaction_field = 'refID';
         }
         $typenames = array();
         // Display Loop
         foreach ($data['data']['rows'] as $rowkey => $row) {
             // Column num
             $item_num = 1;
             $row_num++;
             // New line
             echo self::showNewLine($data['display_type'], $row_num % 2, $data['search']['is_deleted']);
             $current_type = isset($row['TYPE']) ? $row['TYPE'] : $data['itemtype'];
             $massiveaction_type = $current_type;
             if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
                 $massiveaction_type = $data['itemtype'];
             }
             // Add item in item list
             Session::addToNavigateListItems($current_type, $row["id"]);
             if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
                 // HTML display - massive modif
                 $tmpcheck = "";
                 if ($data['itemtype'] == 'Entity' && !in_array($row["id"], $_SESSION["glpiactiveentities"])) {
                     $tmpcheck = "&nbsp;";
                 } else {
                     if ($data['item'] instanceof CommonDBTM && $data['item']->maybeRecursive() && !in_array($row["entities_id"], $_SESSION["glpiactiveentities"])) {
                         $tmpcheck = "&nbsp;";
                     } else {
                         $tmpcheck = Html::getMassiveActionCheckBox($massiveaction_type, $row[$massiveaction_field]);
                     }
                 }
                 echo self::showItem($data['display_type'], $tmpcheck, $item_num, $row_num, "width='10'");
             }
             // Print other toview items
             foreach ($data['data']['cols'] as $colkey => $col) {
                 if (!$col['meta']) {
                     echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num, self::displayConfigItem($data['itemtype'], $col['id'], $row, $colkey));
                 } else {
                     // META case
                     echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num);
                 }
             }
             if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
                 if (!isset($typenames[$row["TYPE"]])) {
                     if ($itemtmp = getItemForItemtype($row["TYPE"])) {
                         $typenames[$row["TYPE"]] = $itemtmp->getTypeName();
                     }
                 }
                 echo self::showItem($data['display_type'], $typenames[$row["TYPE"]], $item_num, $row_num);
             }
             // End Line
             echo self::showEndLine($data['display_type']);
         }
         // Create title
         $title = '';
         if ($data['display_type'] == self::PDF_OUTPUT_LANDSCAPE || $data['display_type'] == self::PDF_OUTPUT_PORTRAIT) {
             $title = self::computeTitle($data);
         }
         if ($data['display_type'] == self::HTML_OUTPUT) {
             echo $headers_line_bottom;
         }
         // Display footer
         echo self::showFooter($data['display_type'], $title);
         // Delete selected item
         if ($data['display_type'] == self::HTML_OUTPUT) {
             if ($showmassiveactions) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($massiveactionparams);
                 // End form for delete item
                 Html::closeForm();
             } else {
                 echo "<br>";
             }
         }
         if ($data['display_type'] == self::HTML_OUTPUT) {
             // In case of HTML display
             Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, '', 0, $search_config_bottom);
         }
     } else {
         if ($item !== null && $item->maybeDeleted()) {
             echo "<div class='center'>" . self::isDeletedSwitch($data['search']['is_deleted']) . "</div><br/>";
         }
         echo self::showError($data['display_type']);
     }
 }
コード例 #2
0
 function displayValue($output_type, $row)
 {
     if (!isset($row[$this->name]) || !$row[$this->name]) {
         return '';
     }
     if (!$this->obj || !$this->obj->getFromDB($row[$this->name])) {
         return $row[$this->name];
     }
     if ($this->with_navigate) {
         Session::addToNavigateListItems($this->obj->getType(), $row[$this->name]);
     }
     if ($output_type == Search::HTML_OUTPUT) {
         return $this->obj->getLink($this->with_comment);
     }
     return $this->obj->getNameID();
 }
コード例 #3
0
 /**
  * @param $index
  * @param $options   array
  **/
 function displayCell($index, array $options = array())
 {
     if ($index >= $this->start && $index < $this->start + $this->numberOfLines) {
         if ($index == $this->start) {
             if ($this->item instanceof CommonDBTM) {
                 Session::addToNavigateListItems($this->item->getType(), $this->item->getID());
             }
             echo "\t\t\t<td colspan='" . $this->header->getColSpan() . "'";
             if ($this->numberOfLines > 1) {
                 echo " rowspan='" . $this->numberOfLines . "'";
             }
             $this->displayEntityAttributs($options);
             echo ">";
             $this->displayContent();
             echo "</td>\n";
         }
         return true;
     }
     return false;
 }
コード例 #4
0
ファイル: rule.class.php プロジェクト: pvasener/glpi
 /**
  * @param $item
  **/
 function showAndAddRuleForm($item)
 {
     $rand = mt_rand();
     $canedit = self::canUpdate();
     if ($canedit && $item->getType() == 'Entity') {
         $this->showNewRuleForm($item->getField('id'));
     }
     //Get all rules and actions
     $crit = array('field' => getForeignKeyFieldForTable($item->getTable()), 'value' => $item->getField('id'));
     $rules = $this->getRulesForCriteria($crit);
     $nb = count($rules);
     echo "<div class='spaced'>";
     if (!$nb) {
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th>" . __('No item found') . "</th>";
         echo "</tr>\n";
         echo "</table>\n";
     } else {
         if ($canedit) {
             Html::openMassiveActionsForm('mass' . get_called_class() . $rand);
             $massiveactionparams = array('num_displayed' => $nb, 'specific_actions' => array('update' => _x('button', 'Update'), 'purge' => _x('button', 'Delete permanently')));
             //     'extraparams'
             //           => array('rule_class_name' => $this->getRuleClassName()));
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov'>";
         $header_begin = "<tr>";
         $header_top = '';
         $header_bottom = '';
         $header_end = '';
         if ($canedit) {
             $header_begin .= "<th width='10'>";
             $header_top .= Html::getCheckAllAsCheckbox('mass' . get_called_class() . $rand);
             $header_bottom .= Html::getCheckAllAsCheckbox('mass' . get_called_class() . $rand);
             $header_end .= "</th>";
         }
         $header_end .= "<th>" . $this->getTitle() . "</th>";
         $header_end .= "<th>" . __('Description') . "</th>";
         $header_end .= "<th>" . __('Active') . "</th>";
         $header_end .= "</tr>\n";
         echo $header_begin . $header_top . $header_end;
         Session::initNavigateListItems(get_class($this), sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($rules as $rule) {
             Session::addToNavigateListItems(get_class($this), $rule->fields["id"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $rule->fields["id"]);
                 echo "</td>";
                 echo "<td><a href='" . Toolbox::getItemTypeFormURL(get_class($this)) . "?id=" . $rule->fields["id"] . "&amp;onglet=1'>" . $rule->fields["name"] . "</a></td>";
             } else {
                 echo "<td>" . $rule->fields["name"] . "</td>";
             }
             echo "<td>" . $rule->fields["description"] . "</td>";
             echo "<td>" . Dropdown::getYesNo($rule->fields["is_active"]) . "</td>";
             echo "</tr>\n";
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>\n";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
     }
     echo "</div>";
 }
コード例 #5
0
ファイル: profile_user.class.php プロジェクト: Ixertec/glpi
 /**
  * Show users of an entity
  *
  * @param $entity Entity object
  **/
 static function showForEntity(Entity $entity)
 {
     global $DB;
     $ID = $entity->getField('id');
     if (!$entity->can($ID, READ)) {
         return false;
     }
     $canedit = $entity->canEdit($ID);
     $canshowuser = User::canView();
     $nb_per_line = 3;
     $rand = mt_rand();
     if ($canedit) {
         $headerspan = $nb_per_line * 2;
     } else {
         $headerspan = $nb_per_line;
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='entityuser_form{$rand}' id='entityuser_form{$rand}' method='post' action='";
         echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Add an authorization to a user') . "</tr>";
         echo "<tr class='tab_bg_1'><td class='tab_bg_2 center'>" . __('User') . "&nbsp;";
         echo "<input type='hidden' name='entities_id' value='{$ID}'>";
         User::dropdown(array('right' => 'all'));
         echo "</td><td class='tab_bg_2 center'>" . self::getTypeName(1) . "</td><td>";
         Profile::dropdownUnder(array('value' => Profile::getDefault()));
         echo "</td><td class='tab_bg_2 center'>" . __('Recursive') . "</td><td>";
         Dropdown::showYesNo("is_recursive", 0);
         echo "</td><td class='tab_bg_2 center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     $query = "SELECT DISTINCT `glpi_profiles`.`id`, `glpi_profiles`.`name`\n                FROM `glpi_profiles_users`\n                LEFT JOIN `glpi_profiles`\n                     ON (`glpi_profiles_users`.`profiles_id` = `glpi_profiles`.`id`)\n                LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n                     AND `glpi_users`.`is_deleted` = '0'";
     $result = $DB->query($query);
     $nb = $DB->numrows($result);
     echo "<div class='spaced'>";
     if ($canedit && $nb) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<thead><tr>";
     echo "<th class='noHover' colspan='{$headerspan}'>";
     printf(__('%1$s (%2$s)'), _n('User', 'Users', Session::getPluralNumber()), __('D=Dynamic, R=Recursive'));
     echo "</th></tr></thead>";
     if ($nb) {
         Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Entity::getTypeName(1), $entity->getName()));
         while ($data = $DB->fetch_assoc($result)) {
             echo "<tbody><tr class='noHover'>";
             $reduce_header = 0;
             if ($canedit && $nb) {
                 echo "<th width='10'>";
                 echo Html::checkAllAsCheckbox("profile" . $data['id'] . "_{$rand}");
                 echo "</th>";
                 $reduce_header++;
             }
             echo "<th colspan='" . ($headerspan - $reduce_header) . "'>";
             printf(__('%1$s: %2$s'), __('Profile'), $data["name"]);
             echo "</th></tr></tbody>";
             echo "<tbody id='profile" . $data['id'] . "_{$rand}'>";
             $query = "SELECT `glpi_users`.*,\n                             `glpi_profiles_users`.`id` AS linkID,\n                             `glpi_profiles_users`.`is_recursive`,\n                             `glpi_profiles_users`.`is_dynamic`\n                      FROM `glpi_profiles_users`\n                      LEFT JOIN `glpi_users`\n                           ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n                      WHERE `glpi_profiles_users`.`entities_id` = '{$ID}'\n                            AND `glpi_users`.`is_deleted` = '0'\n                            AND `glpi_profiles_users`.`profiles_id` = '" . $data['id'] . "'\n                      ORDER BY `glpi_profiles_users`.`profiles_id`,\n                               `glpi_users`.`name`,\n                               `glpi_users`.`realname`,\n                               `glpi_users`.`firstname`";
             $result2 = $DB->query($query);
             if ($DB->numrows($result2) > 0) {
                 $i = 0;
                 while ($data2 = $DB->fetch_assoc($result2)) {
                     Session::addToNavigateListItems('User', $data2["id"]);
                     if ($i % $nb_per_line == 0) {
                         if ($i != 0) {
                             echo "</tr>";
                         }
                         echo "<tr class='tab_bg_1'>";
                     }
                     if ($canedit) {
                         echo "<td width='10'>";
                         Html::showMassiveActionCheckBox(__CLASS__, $data2["linkID"]);
                         echo "</td>";
                     }
                     $username = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"], $canshowuser);
                     if ($data2["is_dynamic"] || $data2["is_recursive"]) {
                         $username = sprintf(__('%1$s %2$s'), $username, "<span class='b'>(");
                         if ($data2["is_dynamic"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, __('D'));
                         }
                         if ($data2["is_dynamic"] && $data2["is_recursive"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, ", ");
                         }
                         if ($data2["is_recursive"]) {
                             $username = sprintf(__('%1$s%2$s'), $username, __('R'));
                         }
                         $username = sprintf(__('%1$s%2$s'), $username, ")</span>");
                     }
                     echo "<td>" . $username . "</td>";
                     $i++;
                 }
                 while ($i % $nb_per_line != 0) {
                     echo "<td>&nbsp;</td>";
                     if ($canedit) {
                         echo "<td>&nbsp;</td>";
                     }
                     $i++;
                 }
                 echo "</tr>";
                 echo "</tbody>";
             } else {
                 echo "<tr colspan='{$headerspan}'>" . __('Item not found') . "</tr>";
             }
         }
     }
     echo "</table>";
     if ($canedit && $nb) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
コード例 #6
0
 /**
  * Print the computers disks
  *
  * @param $comp Computer object
  *
  * @return Nothing (call to classes members)
  **/
 static function showForComputer(Computer $comp)
 {
     global $DB;
     $ID = $comp->fields['id'];
     if (!$comp->getFromDB($ID) || !$comp->can($ID, "r")) {
         return false;
     }
     $canedit = $comp->can($ID, "w");
     echo "<div class='spaced center'>";
     $virtualmachines = getAllDatasFromTable('glpi_computervirtualmachines', "`computers_id` = '{$ID}' AND `is_deleted` = '0'");
     echo "<table class='tab_cadre_fixe'>";
     Session::initNavigateListItems('ComputerVirtualMachine', sprintf(__('%1$s = %2$s'), __('Computer'), empty($comp->fields['name']) ? "({$ID})" : $comp->fields['name']));
     if (empty($virtualmachines)) {
         echo "<tr><th>" . __('No virtual machine associated with the computer') . "</th></tr>";
     } else {
         echo "<tr><th colspan='10'>" . __('List of virtual machines') . "</th></tr>";
         echo "<tr><th>" . __('Name') . "</th>";
         if (Plugin::haveImport()) {
             echo "<th>" . __('Automatic inventory') . "</th>";
         }
         echo "<th>" . __('Virtualization system') . "</th>";
         echo "<th>" . __('Virtualization model') . "</th>";
         echo "<th>" . __('State of the virtual machine') . "</th>";
         echo "<th>" . __('UUID') . "</th>";
         echo "<th>" . _x('quantity', 'Processors number') . "</th>";
         echo "<th>" . sprintf(__('%1$s (%2$s)'), __('Memory'), __('Mio')) . "</th>";
         echo "<th>" . __('Machine') . "</th>";
         echo "</tr>";
         $vm = new self();
         foreach ($virtualmachines as $virtualmachine) {
             $vm->getFromDB($virtualmachine['id']);
             echo "<tr class='tab_bg_2'>";
             echo "<td>" . $vm->getLink() . "</td>";
             if (Plugin::haveImport()) {
                 echo "<td>";
                 echo Dropdown::getYesNo($vm->isDynamic());
                 echo "</td>";
             }
             echo "<td>";
             echo Dropdown::getDropdownName('glpi_virtualmachinetypes', $virtualmachine['virtualmachinetypes_id']);
             echo "</td>";
             echo "<td>";
             echo Dropdown::getDropdownName('glpi_virtualmachinesystems', $virtualmachine['virtualmachinesystems_id']);
             echo "</td>";
             echo "<td>";
             echo Dropdown::getDropdownName('glpi_virtualmachinestates', $virtualmachine['virtualmachinestates_id']);
             echo "</td>";
             echo "<td>" . $virtualmachine['uuid'] . "</a></td>";
             echo "<td>" . $virtualmachine['vcpu'] . "</td>";
             echo "<td>" . $virtualmachine['ram'] . "</td>";
             echo "<td>";
             if ($link_computer = self::findVirtualMachine($virtualmachine)) {
                 $computer = new Computer();
                 if ($computer->can($link_computer, 'r')) {
                     $url = "<a href='computer.form.php?id=" . $link_computer . "'>";
                     $url .= $computer->fields["name"] . "</a>";
                     $tooltip = "<table><tr><td>" . __('Name') . "</td><td>" . $computer->fields['name'] . '</td></tr>';
                     $tooltip .= "<tr><td>" . __('Serial number') . "</td><td>" . $computer->fields['serial'] . '</td></tr>';
                     $tooltip .= "<tr><td>" . __('Comments') . "</td><td>" . $computer->fields['comment'] . '</td></tr></table>';
                     $url .= "&nbsp; " . Html::showToolTip($tooltip, array('display' => false));
                 } else {
                     $url = $computer->fields['name'];
                 }
                 echo $url;
             }
             echo "</td>";
             echo "</tr>";
             Session::addToNavigateListItems('ComputerVirtualMachine', $virtualmachine['id']);
         }
     }
     if ($canedit) {
         echo "<tr class='tab_bg_1'><td colspan='8' class='center'>";
         echo "<a class='vsubmit' href='computervirtualmachine.form.php?computers_id={$ID}'>" . __('Add a virtual machine') . "</a></td></tr>";
     }
     echo "</table>";
     echo "</div>";
 }
コード例 #7
0
ファイル: change.class.php プロジェクト: jose-martins/glpi
 /**
  * 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
 }
コード例 #8
0
ファイル: item_devices.class.php プロジェクト: pvasener/glpi
 /**
  * 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);
         }
     }
 }
コード例 #9
0
ファイル: script.class.php プロジェクト: geldarr/hack-space
 function showScripts(PluginDatabasesDatabase $database)
 {
     global $DB, $CFG_GLPI;
     $instID = $database->fields['id'];
     if (!$database->can($instID, "r")) {
         return false;
     }
     $rand = mt_rand();
     $canedit = $database->can($instID, 'w');
     $query = "SELECT `glpi_plugin_databases_scripts`.`name` AS name,\n                        `glpi_plugin_databases_scripts`.`id`,\n                        `glpi_plugin_databases_scripts`.`plugin_databases_databases_id`,\n                        `glpi_plugin_databases_scripts`.`path`,\n                        `glpi_plugin_databases_scripts`.`comment`,\n                        `glpi_plugin_databases_scripttypes`.`name` AS type\n               FROM `glpi_plugin_databases_scripts` ";
     $query .= " LEFT JOIN `glpi_plugin_databases_scripttypes`\n      ON (`glpi_plugin_databases_scripttypes`.`id` = `glpi_plugin_databases_scripts`.`plugin_databases_scripttypes_id`)";
     $query .= " LEFT JOIN `glpi_plugin_databases_databases`\n      ON (`glpi_plugin_databases_databases`.`id` = `glpi_plugin_databases_scripts`.`plugin_databases_databases_id`)";
     $query .= " WHERE `glpi_plugin_databases_scripts`.`plugin_databases_databases_id` = '{$instID}'\n          ORDER BY `glpi_plugin_databases_scripts`.`name`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array();
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     if ($number != 0) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr>";
         if ($canedit && $number) {
             echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
         }
         echo "<th>" . __('Name') . "</th>";
         echo "<th>" . __('Type') . "</th>";
         echo "<th>" . __('Path', 'databases') . "</th>";
         echo "<th>" . __('Comments') . "</th>";
         echo "</tr>";
         Session::initNavigateListItems($this->getType(), PluginDatabasesDatabase::getTypeName(2) . " = " . $database->fields["name"]);
         $i = 0;
         $row_num = 1;
         while ($data = $DB->fetch_array($result)) {
             Session::addToNavigateListItems($this->getType(), $data['id']);
             $i++;
             $row_num++;
             echo "<tr class='tab_bg_1 center'>";
             echo "<td width='10'>";
             if ($canedit) {
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
             }
             echo "</td>";
             echo "<td class='center'>";
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/databases/front/script.form.php?id=" . $data["id"] . "&amp;plugin_databases_databases_id=" . $data["plugin_databases_databases_id"] . "'>";
             echo $data["name"];
             if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                 echo " (" . $data["id"] . ")";
             }
             echo "</a></td>";
             echo "<td class='center'>" . $data["type"] . "</td>";
             echo "<td class='left'>" . $data["path"] . "</td>";
             echo "<td class='center'>" . nl2br($data["comment"]) . "</td>";
             echo "</tr>";
         }
         echo "</table>";
     }
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
コード例 #10
0
ファイル: reception.class.php プロジェクト: biet-j/order
 public function showOrderReception($orders_id)
 {
     global $DB, $CFG_GLPI;
     $order_order = new PluginOrderOrder();
     $order_item = new PluginOrderOrder_Item();
     $reference = new PluginOrderReference();
     $order_order->getFromDB($orders_id);
     Session::initNavigateListItems($this->getType(), __("Order", "order") . " = " . $order_order->fields["name"]);
     $canedit = self::canCreate() && !$order_order->canUpdateOrder() && !$order_order->isCanceled();
     $result_ref = $order_item->queryDetail($orders_id);
     $numref = $DB->numrows($result_ref);
     while ($data_ref = $DB->fetch_array($result_ref)) {
         echo "<div class='center'><table class='tab_cadre_fixe'>";
         if (!$numref) {
             echo "<tr><th>" . __("No item to take delivery of", "order") . "</th></tr></table></div>";
         } else {
             $references_id = $data_ref["id"];
             $typeRef = $data_ref["itemtype"];
             $price_taxfree = $data_ref["price_taxfree"];
             $discount = $data_ref["discount"];
             $item = new $typeRef();
             $rand = mt_rand();
             echo "<tr><th><ul><li>";
             echo "<a href=\"javascript:showHideDiv('reception{$rand}','reception_img{$rand}', '" . $CFG_GLPI['root_doc'] . "/pics/plus.png','" . $CFG_GLPI['root_doc'] . "/pics/moins.png');\">";
             echo "<img alt='' name='reception_img{$rand}' src=\"" . $CFG_GLPI['root_doc'] . "/pics/plus.png\">";
             echo "</a>";
             echo "</li></ul></th>";
             echo "<th>" . __("Type") . "</th>";
             echo "<th>" . __("Manufacturer") . "</th>";
             echo "<th>" . __("Product reference", "order") . "</th>";
             echo "<th>" . __("Delivered items", "order") . "</th>";
             echo "</tr>";
             echo "<tr class='tab_bg_1 center'>";
             echo "<td></td>";
             echo "<td align='center'>" . $item->getTypeName() . "</td>";
             echo "<td align='center'>" . Dropdown::getDropdownName("glpi_manufacturers", $data_ref["manufacturers_id"]) . "</td>";
             echo "<td>" . $reference->getReceptionReferenceLink($data_ref) . "</td>";
             $total = $order_item->getTotalQuantityByRefAndDiscount($orders_id, $references_id, $data_ref["price_taxfree"], $data_ref["discount"]);
             echo "<td>" . $order_item->getDeliveredQuantity($orders_id, $references_id, $data_ref["price_taxfree"], $data_ref["discount"]) . " / " . $total . "</td>";
             echo "</tr></table>";
             echo "<div class='center' id='reception{$rand}' style='display:none'>";
             echo "<form method='post' name='order_reception_form{$rand}' id='order_reception_form{$rand}'" . " action=\"" . Toolbox::getItemTypeFormURL("PluginOrderReception") . "\">";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr>";
             echo "<th width='15'></th>";
             if ($typeRef != 'SoftwareLicense') {
                 echo "<th>" . __("ID") . "</th>";
             }
             echo "<th>" . __("Reference") . "</th>";
             echo "<th>" . __("Status") . "</th>";
             echo "<th>" . __("Delivery date") . "</th>";
             echo "<th>" . __("Delivery form") . "</th>";
             echo "<th>" . __("Delivery status", "order") . "</th>";
             echo "</tr>";
             $query = "SELECT `glpi_plugin_order_orders_items`.`id` AS IDD,\n                             `glpi_plugin_order_references`.`id` AS id,\n                             `glpi_plugin_order_references`.`templates_id`,\n                             `glpi_plugin_order_orders_items`.`states_id`,\n                             `glpi_plugin_order_orders_items`.`comment`,\n                             `glpi_plugin_order_orders_items`.`plugin_order_deliverystates_id`,\n                             `glpi_plugin_order_orders_items`.`delivery_date`,\n                             `glpi_plugin_order_orders_items`.`delivery_number`,\n                             `glpi_plugin_order_references`.`name`,\n                             `glpi_plugin_order_references`.`itemtype`,\n                             `glpi_plugin_order_orders_items`.`items_id`\n                    FROM `glpi_plugin_order_orders_items`, `glpi_plugin_order_references`\n                    WHERE `plugin_order_orders_id` = '{$orders_id}'\n                    AND `glpi_plugin_order_orders_items`.`plugin_order_references_id` = '" . $references_id . "'\n                    AND `glpi_plugin_order_orders_items`.`plugin_order_references_id` = `glpi_plugin_order_references`.`id`\n                    AND `glpi_plugin_order_orders_items`.`discount` LIKE '" . $discount . "'\n                    AND `glpi_plugin_order_orders_items`.`price_taxfree` LIKE '" . $price_taxfree . "' ";
             if ($typeRef == 'SoftwareLicense') {
                 $query .= " GROUP BY `glpi_plugin_order_references`.`name` ";
             }
             $query .= " ORDER BY `glpi_plugin_order_references`.`name` ";
             $result = $DB->query($query);
             $num = $DB->numrows($result);
             while ($data = $DB->fetch_array($result)) {
                 $random = mt_rand();
                 $detailID = $data["IDD"];
                 Session::addToNavigateListItems($this->getType(), $detailID);
                 echo "<tr class='tab_bg_2'>";
                 $status = 1;
                 if ($typeRef != 'SoftwareLicense') {
                     $status = $this->checkThisItemStatus($detailID, PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED);
                 }
                 if ($order_order->canDeliver() && $status) {
                     echo "<td width='15' align='left'>";
                     $sel = "";
                     if (isset($_GET["select"]) && $_GET["select"] == "all") {
                         $sel = "checked";
                     }
                     echo "<input type='checkbox' name='item[" . $detailID . "]' value='1' {$sel}>";
                     echo "</td>";
                 } else {
                     echo "<td width='15' align='left'></td>";
                 }
                 if ($typeRef != 'SoftwareLicense') {
                     echo "<td align='center'>" . $data["IDD"] . "&nbsp;";
                     Html::showTooltip($data['comment']);
                     echo "</td>";
                 }
                 echo "<td align='center'>" . $reference->getReceptionReferenceLink($data) . "</td>";
                 echo "<td align='center'>";
                 $link = Toolbox::getItemTypeFormURL($this->getType());
                 if ($canedit && $data["states_id"] == PluginOrderOrder::ORDER_DEVICE_DELIVRED) {
                     echo "<a href=\"" . $link . "?id=" . $data["IDD"] . "\">";
                 }
                 echo $this->getReceptionStatus($detailID);
                 if ($canedit && $data["states_id"] == PluginOrderOrder::ORDER_DEVICE_DELIVRED) {
                     echo "</a>";
                 }
                 echo "</td>";
                 echo "<td align='center'>" . Html::convDate($data["delivery_date"]) . "</td>";
                 echo "<td align='center'>" . $data["delivery_number"] . "</td>";
                 echo "<td align='center'>" . Dropdown::getDropdownName("glpi_plugin_order_deliverystates", $data["plugin_order_deliverystates_id"]) . "</td>";
                 echo "<input type='hidden' name='id[{$detailID}]' value='{$detailID}'>";
                 echo "<input type='hidden' name='name[{$detailID}]' value='" . $data["name"] . "'>";
                 echo "<input type='hidden' name='plugin_order_references_id[{$detailID}]' value='" . $data["id"] . "'>";
                 echo "<input type='hidden' name='itemtype[{$detailID}]' value='" . $data["itemtype"] . "'>";
                 echo "<input type='hidden' name='templates_id[{$detailID}]' value='" . $data["templates_id"] . "'>";
                 echo "<input type='hidden' name='states_id[{$detailID}]' value='" . $data["states_id"] . "'>";
             }
             echo "</table>";
             if ($order_order->canDeliver() && $this->checkItemStatus($orders_id, $references_id, PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED)) {
                 Html::openArrowMassives("order_reception_form{$rand}", true);
                 echo "<input type='hidden' name='plugin_order_orders_id' value='{$orders_id}'>";
                 $this->dropdownReceptionActions($typeRef, $references_id, $orders_id);
                 Html::closeArrowMassives(array());
                 $rand = mt_rand();
                 if ($typeRef != 'SoftwareLicense') {
                     echo "<div id='massreception" . $orders_id . $rand . "'></div>\n";
                     echo "<script type='text/javascript' >\n";
                     echo "function viewmassreception" . $orders_id . "{$rand}(){\n";
                     $params = array('plugin_order_orders_id' => $orders_id, 'plugin_order_references_id' => $references_id);
                     Ajax::updateItemJsCode("massreception" . $orders_id . $rand, $CFG_GLPI["root_doc"] . "/plugins/order/ajax/massreception.php", $params, false);
                     echo "};";
                     echo "</script>\n";
                     echo "<p><a href='javascript:viewmassreception" . $orders_id . "{$rand}();'>";
                     echo __("Take item delivery (bulk)", "order") . "</a></p><br>\n";
                 }
             }
             Html::closeForm();
             echo "</div>";
         }
         echo "<br>";
     }
 }
コード例 #11
0
 /**
  * Print out list kb item
  *
  * @param $options            $_GET
  * @param $type      string   search type : browse / search (default search)
  **/
 static function showList($options, $type = 'search')
 {
     global $DB, $CFG_GLPI;
     // Default values of parameters
     $params['faq'] = !Session::haveRight(self::$rightname, READ);
     $params["start"] = "0";
     $params["knowbaseitemcategories_id"] = "0";
     $params["contains"] = "";
     $params["target"] = $_SERVER['PHP_SELF'];
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $ki = new self();
     switch ($type) {
         case 'myunpublished':
             if (!Session::haveRightsOr(self::$rightname, array(UPDATE, self::PUBLISHFAQ))) {
                 return false;
             }
             break;
         case 'allunpublished':
             if (!Session::haveRight(self::$rightname, self::KNOWBASEADMIN)) {
                 return false;
             }
             break;
         default:
             break;
     }
     if (!$params["start"]) {
         $params["start"] = 0;
     }
     $query = self::getListRequest($params, $type);
     // Get it from database
     if ($result = $DB->query($query)) {
         $KbCategory = new KnowbaseItemCategory();
         $title = "";
         if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) {
             $title = empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name'];
             $title = sprintf(__('%1$s: %2$s'), __('Category'), $title);
         }
         Session::initNavigateListItems('KnowbaseItem', $title);
         $numrows = $DB->numrows($result);
         $list_limit = $_SESSION['glpilist_limit'];
         $showwriter = in_array($type, array('myunpublished', 'allunpublished', 'allmy'));
         // Limit the result, if no limit applies, use prior result
         if ($numrows > $list_limit && !isset($_GET['export_all'])) {
             $query_limit = $query . " LIMIT " . intval($params["start"]) . ", " . intval($list_limit) . " ";
             $result_limit = $DB->query($query_limit);
             $numrows_limit = $DB->numrows($result_limit);
         } else {
             $numrows_limit = $numrows;
             $result_limit = $result;
         }
         if ($numrows_limit > 0) {
             // Set display type for export if define
             $output_type = Search::HTML_OUTPUT;
             if (isset($_GET["display_type"])) {
                 $output_type = $_GET["display_type"];
             }
             // Pager
             $parameters = "start=" . $params["start"] . "&amp;knowbaseitemcategories_id=" . $params['knowbaseitemcategories_id'] . "&amp;contains=" . $params["contains"] . "&amp;is_faq=" . $params['faq'];
             if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
                 $parameters .= "&amp;item_items_id=" . $options['item_items_id'] . "&amp;item_itemtype=" . $options['item_itemtype'];
             }
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
             $nbcols = 1;
             // Display List Header
             echo Search::showHeader($output_type, $numrows_limit + 1, $nbcols);
             echo Search::showNewLine($output_type);
             $header_num = 1;
             echo Search::showHeaderItem($output_type, __('Subject'), $header_num);
             if ($output_type != Search::HTML_OUTPUT) {
                 echo Search::showHeaderItem($output_type, __('Content'), $header_num);
             }
             if ($showwriter) {
                 echo Search::showHeaderItem($output_type, __('Writer'), $header_num);
             }
             echo Search::showHeaderItem($output_type, __('Category'), $header_num);
             if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) {
                 echo Search::showHeaderItem($output_type, '&nbsp;', $header_num);
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             for ($i = 0; $i < $numrows_limit; $i++) {
                 $data = $DB->fetch_assoc($result_limit);
                 Session::addToNavigateListItems('KnowbaseItem', $data["id"]);
                 // Column num
                 $item_num = 1;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 $item = new self();
                 $item->getFromDB($data["id"]);
                 $name = $data["name"];
                 $answer = $data["answer"];
                 // Manage translations
                 if (isset($data['transname']) && !empty($data['transname'])) {
                     $name = $data["transname"];
                 }
                 if (isset($data['transanswer']) && !empty($data['transanswer'])) {
                     $answer = $data["transanswer"];
                 }
                 if ($output_type == Search::HTML_OUTPUT) {
                     $toadd = '';
                     if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
                         $href = " href='#' onClick=\"" . Html::jsGetElementbyID('kbshow' . $data["id"]) . ".dialog('open');\"";
                         $toadd = Ajax::createIframeModalWindow('kbshow' . $data["id"], $CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $data["id"], array('display' => false));
                     } else {
                         $href = " href=\"" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\" ";
                     }
                     echo Search::showItem($output_type, "<div class='kb'>{$toadd}<a " . ($data['is_faq'] ? " class='pubfaq' title='" . __("This item is part of the FAQ") . "' " : " class='knowbase' ") . " {$href}>" . Html::resume_text($name, 80) . "</a></div>\n                                          <div class='kb_resume'>" . Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($answer)), 600) . "</div>", $item_num, $row_num);
                 } else {
                     echo Search::showItem($output_type, $name, $item_num, $row_num);
                     echo Search::showItem($output_type, Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($answer, ENT_QUOTES, "UTF-8"))), $item_num, $row_num);
                 }
                 $showuserlink = 0;
                 if (Session::haveRight('user', READ)) {
                     $showuserlink = 1;
                 }
                 if ($showwriter) {
                     echo Search::showItem($output_type, getUserName($data["users_id"], $showuserlink), $item_num, $row_num);
                 }
                 $categ = $data["category"];
                 if ($output_type == Search::HTML_OUTPUT) {
                     $cathref = $ki->getSearchURL() . "?knowbaseitemcategories_id=" . $data["knowbaseitemcategories_id"] . '&amp;forcetab=Knowbase$2';
                     $categ = "<a href='{$cathref}'>" . $categ . '</a>';
                 }
                 echo Search::showItem($output_type, $categ, $item_num, $row_num);
                 if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) {
                     $forcetab = $options['item_itemtype'];
                     if (!$_SESSION['glpiticket_timeline'] || $_SESSION['glpiticket_timeline_keep_replaced_tabs']) {
                         $forcetab .= '$2';
                         //Solution tab
                     } else {
                         $forcetab .= '$1';
                         //Timeline tab
                     }
                     $content = "<a href='" . Toolbox::getItemTypeFormURL($options['item_itemtype']) . "?load_kb_sol=" . $data['id'] . "&amp;id=" . $options['item_items_id'] . "&amp;forcetab=" . $forcetab . "'>" . __('Use as a solution') . "</a>";
                     echo Search::showItem($output_type, $content, $item_num, $row_num);
                 }
                 // End Line
                 echo Search::showEndLine($output_type);
             }
             // Display footer
             if ($output_type == Search::PDF_OUTPUT_LANDSCAPE || $output_type == Search::PDF_OUTPUT_PORTRAIT) {
                 echo Search::showFooter($output_type, Dropdown::getDropdownName("glpi_knowbaseitemcategories", $params['knowbaseitemcategories_id']));
             } else {
                 echo Search::showFooter($output_type);
             }
             echo "<br>";
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
         } else {
             echo "<div class='center b'>" . __('No item found') . "</div>";
         }
     }
 }
コード例 #12
0
 public static function showOrderSupplierInfos($ID)
 {
     //TODO : en cours
     global $DB;
     $order = new PluginOrderOrder();
     $order->getFromDB($ID);
     $suppliers_id = $order->fields["suppliers_id"];
     Session::initNavigateListItems(__CLASS__, __("Order", "order") . " = " . $order->fields["name"]);
     $candelete = $order->can($ID, UPDATE);
     $rand = mt_rand();
     $link = Toolbox::getItemTypeFormURL(__CLASS__);
     echo "<form method='post' name='show_supplierinfos{$rand}' id='show_supplierinfos{$rand}' " . "action=\"" . $link . "\">";
     echo "<div class='center'>";
     echo "<input type='hidden' name='plugin_order_orders_id' value='" . $ID . "'>";
     $table = getTableForItemType(__CLASS__);
     $nb_elements = countElementsInTable($table, "`plugin_order_orders_id` = '{$ID}'");
     if ($nb_elements > 0) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='4'>" . __("Supplier Detail", "order") . "</th></tr>";
         echo "<tr>";
         echo "<th>&nbsp;</th>";
         echo "<th>" . __("Supplier") . "</th>";
         echo "<th>" . __("Quote number", "order") . "</th>";
         echo "<th>" . __("Order number") . "</th>";
         echo "</tr>";
         $datas = getAllDatasFromTable($table, "`plugin_order_orders_id` = '{$ID}'");
         foreach ($datas as $data) {
             Session::addToNavigateListItems(__CLASS__, $data['id']);
             echo "<input type='hidden' name='item[" . $data["id"] . "]' value='" . $ID . "'>";
             echo "<tr class='tab_bg_1 center'>";
             echo "<td>";
             if ($candelete) {
                 echo "<input type='checkbox' name='check[" . $data["id"] . "]'";
                 if (isset($_POST['check']) && $_POST['check'] == 'all') {
                     echo " checked ";
                 }
                 echo ">";
             }
             echo "</td>";
             echo "<td><a href='" . $link . "?id=" . $data["id"] . "&plugin_order_orders_id=" . $ID . "'>" . Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]) . "</a></td>";
             echo "<td>" . $data["num_quote"] . "</td>";
             echo "<td>" . $data["num_order"] . "</td>";
             echo "</tr>";
         }
         echo "</table></div>";
         if ($candelete) {
             Html::openArrowMassives("show_supplierinfos{$rand}", true);
             Html::closeArrowMassives(array('delete' => __("Delete permanently")));
         }
     }
     Html::closeForm();
 }
コード例 #13
0
 /**
  * Show users of a group
  *
  * @since version 0.83
  *
  * @param $group  Group object: the group
  **/
 static function showForGroup(Group $group)
 {
     global $DB, $CFG_GLPI;
     $ID = $group->getID();
     if (!User::canView() || !$group->can($ID, READ)) {
         return false;
     }
     // Have right to manage members
     $canedit = self::canUpdate();
     $rand = mt_rand();
     $user = new User();
     $crit = Session::getSavedOption(__CLASS__, 'criterion', '');
     $tree = Session::getSavedOption(__CLASS__, 'tree', 0);
     $used = array();
     $ids = array();
     // Retrieve member list
     $entityrestrict = self::getDataForGroup($group, $used, $ids, $crit, $tree);
     if ($canedit) {
         self::showAddUserForm($group, $ids, $entityrestrict, $crit);
     }
     // Mini Search engine
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'><th colspan='2'>" . User::getTypeName(Session::getPluralNumber()) . "</th></tr>";
     echo "<tr class='tab_bg_1'><td class='center'>";
     echo _n('Criterion', 'Criteria', 1) . "&nbsp;";
     $crits = array('' => Dropdown::EMPTY_VALUE, 'is_manager' => __('Manager'), 'is_userdelegate' => __('Delegatee'));
     Dropdown::showFromArray('crit', $crits, array('value' => $crit, 'on_change' => 'reloadTab("start=0&criterion="+this.value)'));
     if ($group->haveChildren()) {
         echo "</td><td class='center'>" . __('Child groups');
         Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)'));
     } else {
         $tree = 0;
     }
     echo "</td></tr></table>";
     $number = count($used);
     $start = isset($_GET['start']) ? intval($_GET['start']) : 0;
     if ($start >= $number) {
         $start = 0;
     }
     // Display results
     if ($number) {
         echo "<div class='spaced'>";
         Html::printAjaxPager(sprintf(__('%1$s (%2$s)'), User::getTypeName(Session::getPluralNumber()), __('D=Dynamic')), $start, $number);
         Session::initNavigateListItems('User', sprintf(__('%1$s = %2$s'), Group::getTypeName(1), $group->getName()));
         if ($canedit) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => min($number - $start, $_SESSION['glpilist_limit']), 'container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov table-striped table-hover'>";
         $header_begin = "<tr>";
         $header_top = '';
         $header_bottom = '';
         $header_end = '';
         if ($canedit) {
             $header_begin .= "<th width='10'>";
             $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_end .= "</th>";
         }
         $header_end .= "<th>" . User::getTypeName(1) . "</th>";
         if ($tree) {
             $header_end .= "<th>" . Group::getTypeName(1) . "</th>";
         }
         $header_end .= "<th>" . __('Dynamic') . "</th>";
         $header_end .= "<th>" . __('Manager') . "</th>";
         $header_end .= "<th>" . __('Delegatee') . "</th></tr>";
         echo $header_begin . $header_top . $header_end;
         $tmpgrp = new Group();
         for ($i = $start, $j = 0; $i < $number && $j < $_SESSION['glpilist_limit']; $i++, $j++) {
             $data = $used[$i];
             $user->getFromDB($data["id"]);
             Session::addToNavigateListItems('User', $data["id"]);
             echo "\n<tr class='tab_bg_" . ($user->isDeleted() ? '1_2' : '1') . "'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                 echo "</td>";
             }
             echo "<td>" . $user->getLink();
             if ($tree) {
                 echo "</td><td>";
                 if ($tmpgrp->getFromDB($data['groups_id'])) {
                     echo $tmpgrp->getLink(array('comments' => true));
                 }
             }
             echo "</td><td class='center'>";
             if ($data['is_dynamic']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Dynamic') . "\">";
             }
             echo "</td><td class='center'>";
             if ($data['is_manager']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Manager') . "\">";
             }
             echo "</td><td class='center'>";
             if ($data['is_userdelegate']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Delegatee') . "\">";
             }
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
         Html::printAjaxPager(sprintf(__('%1$s (%2$s)'), User::getTypeName(Session::getPluralNumber()), __('D=Dynamic')), $start, $number);
         echo "</div>";
     } else {
         echo "<p class='center b'>" . __('No item found') . "</p>";
     }
 }
コード例 #14
0
 /**
  * Show changes for a ticket
  *
  * @param $ticket Ticket object
  **/
 static function showForTicket(Ticket $ticket)
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->getField('id');
     if (!$ticket->can($ID, READ)) {
         return false;
     }
     $canedit = $ticket->canEdit($ID);
     $rand = mt_rand();
     $query = "SELECT DISTINCT `glpi_changes_tickets`.`id` AS linkID,\n                                `glpi_changes`.*\n                FROM `glpi_changes_tickets`\n                LEFT JOIN `glpi_changes`\n                     ON (`glpi_changes_tickets`.`changes_id` = `glpi_changes`.`id`)\n                WHERE `glpi_changes_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY `glpi_changes`.`name`";
     $result = $DB->query($query);
     $changes = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $changes[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='changeticket_form{$rand}' id='changeticket_form{$rand}' method='post'\n               action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='3'>" . __('Add a change') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td>";
         echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
         Change::dropdown(array('used' => $used, 'entity' => $ticket->getEntityID()));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td><td>";
         if (Session::haveRight('change', CREATE)) {
             echo "<a href='" . Toolbox::getItemTypeFormURL('Change') . "?tickets_id={$ID}'>";
             _e('Create a change from this ticket');
             echo "</a>";
         }
         echo "</td></tr></table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $numrows) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr class='noHover'><th colspan='12'>" . Change::getTypeName($numrows) . "</th>";
     echo "</tr>";
     if ($numrows) {
         Change::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
         Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), Ticket::getTypeName(1), $ticket->fields["name"]));
         $i = 0;
         foreach ($changes as $data) {
             Session::addToNavigateListItems('Change', $data["id"]);
             Change::showShort($data['id'], array('row_num' => $i, 'type_for_massiveaction' => __CLASS__, 'id_for_massiveaction' => $data['linkID']));
             $i++;
         }
         Change::commonListHeader(Search::HTML_OUTPUT, 'mass' . __CLASS__ . $rand);
     }
     echo "</table>";
     if ($canedit && $numrows) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
コード例 #15
0
 /**
  * Show Versions of a software
  *
  * @param $soft Software object
  *
  * @return nothing
  **/
 static function showForSoftware(Software $soft)
 {
     global $DB, $CFG_GLPI;
     $softwares_id = $soft->getField('id');
     if (!$soft->can($softwares_id, READ)) {
         return false;
     }
     $canedit = $soft->canEdit($softwares_id);
     echo "<div class='spaced'>";
     if ($canedit) {
         echo "<div class='center firstbloc'>";
         echo "<a class='vsubmit' href='softwareversion.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a version') . "</a>";
         echo "</div>";
     }
     $query = "SELECT `glpi_softwareversions`.*,\n                       `glpi_states`.`name` AS sname\n                FROM `glpi_softwareversions`\n                LEFT JOIN `glpi_states` ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                WHERE `softwares_id` = '{$softwares_id}'\n                ORDER BY `name`";
     Session::initNavigateListItems('SoftwareVersion', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->getName()));
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result)) {
             echo "<table class='tab_cadre_fixehov'><tr>";
             echo "<th>" . self::getTypeName(Session::getPluralNumber()) . "</th>";
             echo "<th>" . __('Status') . "</th>";
             echo "<th>" . __('Operating system') . "</th>";
             echo "<th>" . _n('Installation', 'Installations', Session::getPluralNumber()) . "</th>";
             echo "<th>" . __('Comments') . "</th>";
             echo "</tr>\n";
             for ($tot = $nb = 0; $data = $DB->fetch_assoc($result); $tot += $nb) {
                 Session::addToNavigateListItems('SoftwareVersion', $data['id']);
                 $nb = Computer_SoftwareVersion::countForVersion($data['id']);
                 echo "<tr class='tab_bg_2'>";
                 echo "<td><a href='softwareversion.form.php?id=" . $data['id'] . "'>";
                 echo $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a></td>";
                 echo "<td>" . $data['sname'] . "</td>";
                 echo "<td class='right'>" . Dropdown::getDropdownName('glpi_operatingsystems', $data['operatingsystems_id']);
                 echo "</td>";
                 echo "<td class='numeric'>{$nb}</td>";
                 echo "<td>" . $data['comment'] . "</td></tr>\n";
             }
             echo "<tr class='tab_bg_1 noHover'><td class='right b' colspan='3'>" . __('Total') . "</td>";
             echo "<td class='numeric b'>{$tot}</td><td></td></tr>";
             echo "</table>\n";
         } else {
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr><th>" . __('No item found') . "</th></tr>";
             echo "</table>\n";
         }
     }
     echo "</div>";
 }
コード例 #16
0
ファイル: knowbaseitem.class.php プロジェクト: gaforeror/glpi
 /**
  * Print out list kb item
  *
  * @param $options            $_GET
  * @param $type      string   search type : browse / search (default search)
  **/
 static function showList($options, $type = 'search')
 {
     global $DB, $CFG_GLPI;
     // Default values of parameters
     $params['faq'] = !Session::haveRight("knowbase", "r");
     $params["start"] = "0";
     $params["knowbaseitemcategories_id"] = "0";
     $params["contains"] = "";
     $params["target"] = $_SERVER['PHP_SELF'];
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $ki = new self();
     switch ($type) {
         case 'myunpublished':
             if (!Session::haveRight('knowbase', 'w') && !Session::haveRight('faq', 'w')) {
                 return false;
             }
             break;
         case 'allunpublished':
             if (!Session::haveRight('knowbase_admin', 1)) {
                 return false;
             }
             break;
         default:
             break;
     }
     if (!$params["start"]) {
         $params["start"] = 0;
     }
     $query = self::getListRequest($params, $type);
     // Get it from database
     if ($result = $DB->query($query)) {
         $KbCategory = new KnowbaseItemCategory();
         $title = "";
         if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) {
             $title = empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name'];
             $title = sprintf(__('%1$s: %2$s'), __('Category'), $title);
         }
         Session::initNavigateListItems('KnowbaseItem', $title);
         $numrows = $DB->numrows($result);
         $list_limit = $_SESSION['glpilist_limit'];
         $showwriter = in_array($type, array('myunpublished', 'allunpublished', 'allmy'));
         // Limit the result, if no limit applies, use prior result
         if ($numrows > $list_limit && !isset($_GET['export_all'])) {
             $query_limit = $query . " LIMIT " . intval($params["start"]) . ", " . intval($list_limit) . " ";
             $result_limit = $DB->query($query_limit);
             $numrows_limit = $DB->numrows($result_limit);
         } else {
             $numrows_limit = $numrows;
             $result_limit = $result;
         }
         if ($numrows_limit > 0) {
             // Set display type for export if define
             $output_type = Search::HTML_OUTPUT;
             if (isset($_GET["display_type"])) {
                 $output_type = $_GET["display_type"];
             }
             // Pager
             $parameters = "start=" . $params["start"] . "&amp;knowbaseitemcategories_id=" . $params['knowbaseitemcategories_id'] . "&amp;contains=" . $params["contains"] . "&amp;is_faq=" . $params['faq'];
             if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
                 $parameters .= "&amp;item_items_id=" . $options['item_items_id'] . "&amp;item_itemtype=" . $options['item_itemtype'];
             }
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
             $nbcols = 1;
             // Display List Header
             echo Search::showHeader($output_type, $numrows_limit + 1, $nbcols);
             $header_num = 1;
             echo Search::showHeaderItem($output_type, __('Subject'), $header_num);
             if ($output_type != Search::HTML_OUTPUT) {
                 echo Search::showHeaderItem($output_type, __('Content'), $header_num);
             }
             if ($showwriter) {
                 echo Search::showHeaderItem($output_type, __('Writer'), $header_num);
             }
             echo Search::showHeaderItem($output_type, __('Category'), $header_num);
             if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) {
                 echo Search::showHeaderItem($output_type, '&nbsp;', $header_num);
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             for ($i = 0; $i < $numrows_limit; $i++) {
                 $data = $DB->fetch_assoc($result_limit);
                 Session::addToNavigateListItems('KnowbaseItem', $data["id"]);
                 // Column num
                 $item_num = 1;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 if ($output_type == Search::HTML_OUTPUT) {
                     if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
                         $href = " href='#' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=show_kb&amp;id=" . $data['id'] . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' );" . "w.focus();\"";
                     } else {
                         $href = " href=\"" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\" ";
                     }
                     echo Search::showItem($output_type, "<div class='kb'><a " . ($data['is_faq'] ? " class='pubfaq' " : " class='knowbase' ") . " {$href}>" . Html::resume_text($data["name"], 80) . "</a></div>\n                                          <div class='kb_resume'>" . Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($data["answer"])), 600) . "</div>", $item_num, $row_num);
                 } else {
                     echo Search::showItem($output_type, $data["name"], $item_num, $row_num);
                     echo Search::showItem($output_type, Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($data["answer"], ENT_QUOTES, "UTF-8"))), $item_num, $row_num);
                 }
                 if ($showwriter) {
                     echo Search::showItem($output_type, getUserName($data["users_id"], 1), $item_num, $row_num);
                 }
                 $categ = $data["category"];
                 if ($output_type == Search::HTML_OUTPUT) {
                     $cathref = $ki->getSearchURL() . "?knowbaseitemcategories_id=" . $data["knowbaseitemcategories_id"] . '&amp;forcetab=Knowbase$2';
                     $categ = "<a href='{$cathref}'>" . $categ . '</a>';
                 }
                 echo Search::showItem($output_type, $categ, $item_num, $row_num);
                 if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) {
                     $content = "<a href='" . Toolbox::getItemTypeFormURL($options['item_itemtype']) . "?load_kb_sol=" . $data['id'] . "&amp;id=" . $options['item_items_id'] . "&amp;forcetab=" . $options['item_itemtype'] . "\$2'>" . __('Use as a solution') . "</a>";
                     echo Search::showItem($output_type, $content, $item_num, $row_num);
                 }
                 // End Line
                 echo Search::showEndLine($output_type);
             }
             // Display footer
             if ($output_type == Search::PDF_OUTPUT_LANDSCAPE || $output_type == Search::PDF_OUTPUT_PORTRAIT) {
                 echo Search::showFooter($output_type, Dropdown::getDropdownName("glpi_knowbaseitemcategories", $params['knowbaseitemcategories_id']));
             } else {
                 echo Search::showFooter($output_type);
             }
             echo "<br>";
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
         } else {
             echo "<div class='center b'>" . __('No item found') . "</div>";
         }
     }
 }
コード例 #17
0
ファイル: aeskey.class.php プロジェクト: geldarr/hack-space
 public function showAesKey($ID)
 {
     global $DB;
     $this->h->getFromDB($ID);
     Session::initNavigateListItems("PluginAccountsAesKey", __('Hash', 'accounts') . " = " . $this->h->fields["name"]);
     $candelete = $this->h->can($ID, 'w');
     $query = "SELECT *\n      FROM `glpi_plugin_accounts_aeskeys`\n      WHERE `plugin_accounts_hashes_id` = '{$ID}' ";
     $result = $DB->query($query);
     $rand = mt_rand();
     echo "<div class='center'>";
     echo "<form method='post' name='show_aeskey{$rand}' id='show_aeskey{$rand}' action=\"./aeskey.form.php\">";
     echo "<input type='hidden' name='plugin_accounts_hashes_id' value='" . $ID . "'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='5'>" . __('Encryption key', 'accounts') . "</th></tr>";
     echo "<tr><th>&nbsp;</th>";
     echo "<th class='left'>" . __('Name') . "</th>";
     echo "</tr>";
     if ($DB->numrows($result) > 0) {
         while ($data = $DB->fetch_array($result)) {
             Session::addToNavigateListItems("PluginAccountsAesKey", $data['id']);
             echo "<input type='hidden' name='item[" . $data["id"] . "]' value='" . $ID . "'>";
             echo "<tr class='tab_bg_1 center'>";
             echo "<td width='10'>";
             if ($candelete) {
                 echo "<input type='checkbox' name='check[" . $data["id"] . "]'";
                 if (isset($_POST['check']) && $_POST['check'] == 'all') {
                     echo " checked ";
                 }
                 echo ">";
             }
             echo "</td>";
             $link = Toolbox::getItemTypeFormURL("PluginAccountsAesKey");
             echo "<td class='left'><a href='" . $link . "?id=" . $data["id"] . "&plugin_accounts_hashes_id=" . $ID . "'>";
             echo __('Encryption key', 'accounts') . "</a></td>";
             echo "</tr>";
         }
         echo "</table>";
         if ($candelete) {
             Html::openArrowMassives("show_aeskey{$rand}", true);
             Html::closeArrowMassives(array('delete' => __('Delete permanently')));
         }
     } else {
         echo "</table>";
     }
     Html::closeForm();
     echo "</div>";
 }
コード例 #18
0
 /**
  * Print the validation list into ticket
  *
  * @param $ticket class
  **/
 function showSummary($ticket)
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight('validate_request', 1) && !Session::haveRight('validate_incident', 1) && !Session::haveRight('create_incident_validation', 1) && !Session::haveRight('create_request_validation', 1)) {
         return false;
     }
     $tID = $ticket->fields['id'];
     $tmp = array('tickets_id' => $tID);
     $canadd = $this->can(-1, 'w', $tmp);
     $rand = mt_rand();
     echo "<div id='viewfollowup" . $tID . "{$rand}'></div>\n";
     if ($canadd) {
         echo "<script type='text/javascript' >\n";
         echo "function viewAddValidation" . $tID . "{$rand}() {\n";
         $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $tID, 'id' => -1);
         Ajax::updateItemJsCode("viewfollowup" . $tID . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "};";
         echo "</script>\n";
         if ($ticket->fields["status"] != CommonITILObject::SOLVED && $ticket->fields["status"] != CommonITILObject::CLOSED) {
             echo "<div class='center'>";
             echo "<a class='vsubmit' href='javascript:viewAddValidation" . $tID . "{$rand}();'>";
             echo __('Send an approval request') . "</a></div><br>\n";
         }
     }
     $query = "SELECT *\n                FROM `" . $this->getTable() . "`\n                WHERE `tickets_id` = '" . $ticket->getField('id') . "'";
     if (!$canadd) {
         $query .= " AND `users_id_validate` = '" . Session::getLoginUserID() . "' ";
     }
     $query .= " ORDER BY submission_date DESC";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if ($number) {
         $colonnes = array(__('State'), sprintf(__('%1$s: %2$s'), __('Request'), __('Date')), __('Approval requester'), sprintf(__('%1$s: %2$s'), __('Request'), __('Comments')), __('Approval date'), __('Approver'), sprintf(__('%1$s: %2$s'), __('Approval'), __('Comments')));
         $nb_colonnes = count($colonnes);
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th colspan='" . $nb_colonnes . "'>" . __('Approvals for the ticket') . "</th></tr>";
         echo "<tr>";
         foreach ($colonnes as $colonne) {
             echo "<th>" . $colonne . "</th>";
         }
         echo "</tr>";
         Session::initNavigateListItems('TicketValidation', sprintf(__('%1$s = %2$s'), $ticket->getTypeName(1), $ticket->fields["name"]));
         while ($row = $DB->fetch_assoc($result)) {
             $canedit = $this->can($row["id"], 'w');
             Session::addToNavigateListItems('TicketValidation', $row["id"]);
             $bgcolor = $this->getStatusColor($row['status']);
             $status = $this->getStatus($row['status']);
             echo "<tr class='tab_bg_1' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditValidation" . $ticket->fields['id'] . $row["id"] . "{$rand}();\"" : '') . " id='viewfollowup" . $this->fields['tickets_id'] . $row["id"] . "{$rand}'>";
             echo "<td>";
             if ($canedit) {
                 echo "\n<script type='text/javascript' >\n";
                 echo "function viewEditValidation" . $ticket->fields['id'] . $row["id"] . "{$rand}() {\n";
                 $params = array('type' => __CLASS__, 'parenttype' => 'Ticket', 'tickets_id' => $this->fields["tickets_id"], 'id' => $row["id"]);
                 Ajax::updateItemJsCode("viewfollowup" . $ticket->fields['id'] . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
                 echo "};";
                 echo "</script>\n";
             }
             echo "<div style='background-color:" . $bgcolor . ";'>" . $status . "</div></td>";
             echo "<td>" . Html::convDateTime($row["submission_date"]) . "</td>";
             echo "<td>" . getUserName($row["users_id"]) . "</td>";
             echo "<td>" . $row["comment_submission"] . "</td>";
             echo "<td>" . Html::convDateTime($row["validation_date"]) . "</td>";
             echo "<td>" . getUserName($row["users_id_validate"]) . "</td>";
             echo "<td>" . $row["comment_validation"] . "</td>";
             echo "</tr>";
         }
         echo "</table>";
     } else {
         echo "<div class='center b'>" . __('No item found') . "</div>";
     }
 }
コード例 #19
0
ファイル: ticket.class.php プロジェクト: glpi-project/glpi
 /**
  * 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
 }
コード例 #20
0
 /**
  * Print the contract costs
  *
  * @param $contract               Contract object
  * @param $withtemplate  boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForContract(Contract $contract, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $contract->fields['id'];
     if (!$contract->getFromDB($ID) || !$contract->can($ID, READ)) {
         return false;
     }
     $canedit = $contract->can($ID, UPDATE);
     echo "<div class='center'>";
     $query = "SELECT *\n                FROM `glpi_contractcosts`\n                WHERE `contracts_id` = '{$ID}'\n                ORDER BY `begin_date`";
     $rand = mt_rand();
     if ($canedit) {
         echo "<div id='viewcost" . $ID . "_{$rand}'></div>\n";
         echo "<script type='text/javascript' >\n";
         echo "function viewAddCost" . $ID . "_{$rand}() {\n";
         $params = array('type' => __CLASS__, 'parenttype' => 'Contract', 'contracts_id' => $ID, 'id' => -1);
         Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "};";
         echo "</script>\n";
         echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='javascript:viewAddCost" . $ID . "_{$rand}();'>";
         echo __('Add a new cost') . "</a></div>\n";
     }
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr><th colspan='5'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>";
         if ($DB->numrows($result)) {
             echo "<tr><th>" . __('Name') . "</th>";
             echo "<th>" . __('Begin date') . "</th>";
             echo "<th>" . __('End date') . "</th>";
             echo "<th>" . __('Budget') . "</th>";
             echo "<th>" . __('Cost') . "</th>";
             echo "</tr>";
             Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Contract::getTypeName(1), $contract->getName()));
             $total = 0;
             while ($data = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2' " . ($canedit ? "style='cursor:pointer' onClick=\"viewEditCost" . $data['contracts_id'] . "_" . $data['id'] . "_{$rand}();\"" : '') . ">";
                 $name = empty($data['name']) ? sprintf(__('%1$s (%2$s)'), $data['name'], $data['id']) : $data['name'];
                 echo "<td>";
                 printf(__('%1$s %2$s'), $name, Html::showToolTip($data['comment'], array('display' => false)));
                 if ($canedit) {
                     echo "\n<script type='text/javascript' >\n";
                     echo "function viewEditCost" . $data['contracts_id'] . "_" . $data["id"] . "_{$rand}() {\n";
                     $params = array('type' => __CLASS__, 'parenttype' => 'Contract', 'contracts_id' => $data["contracts_id"], 'id' => $data["id"]);
                     Ajax::updateItemJsCode("viewcost" . $ID . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
                     echo "};";
                     echo "</script>\n";
                 }
                 echo "</td>";
                 echo "<td>" . Html::convDate($data['begin_date']) . "</td>";
                 echo "<td>" . Html::convDate($data['end_date']) . "</td>";
                 echo "<td>" . Dropdown::getDropdownName('glpi_budgets', $data['budgets_id']) . "</td>";
                 echo "<td class='numeric'>" . Html::formatNumber($data['cost']) . "</td>";
                 $total += $data['cost'];
                 echo "</tr>";
                 Session::addToNavigateListItems(__CLASS__, $data['id']);
             }
             echo "<tr class='b noHover'><td colspan='3'>&nbsp;</td>";
             echo "<td class='right'>" . __('Total cost') . '</td>';
             echo "<td class='numeric'>" . Html::formatNumber($total) . '</td></tr>';
         } else {
             echo "<tr><th colspan='5'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
     }
     echo "</div><br>";
 }
コード例 #21
0
 /**
  * Show holidays for a calendar
  *
  * @param $calendar Calendar object
  **/
 static function showForCalendar(Calendar $calendar)
 {
     global $DB, $CFG_GLPI;
     $ID = $calendar->getField('id');
     if (!$calendar->can($ID, 'r')) {
         return false;
     }
     $canedit = $calendar->can($ID, 'w');
     $rand = mt_rand();
     $query = "SELECT DISTINCT `glpi_calendars_holidays`.`id` AS linkID,\n                                `glpi_holidays`.*\n                FROM `glpi_calendars_holidays`\n                LEFT JOIN `glpi_holidays`\n                     ON (`glpi_calendars_holidays`.`holidays_id` = `glpi_holidays`.`id`)\n                WHERE `glpi_calendars_holidays`.`calendars_id` = '{$ID}'\n                ORDER BY `glpi_holidays`.`name`";
     $result = $DB->query($query);
     $holidays = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $holidays[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='calendarsegment_form{$rand}' id='calendarsegment_form{$rand}' method='post'\n                action='";
         echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='7'>" . __('Add a close time') . "</tr>";
         echo "<tr class='tab_bg_2'><td class='right'  colspan='4'>";
         echo "<input type='hidden' name='calendars_id' value='{$ID}'>";
         Holiday::dropdown(array('used' => $used, 'entity' => $calendar->fields["entities_id"]));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $numrows) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $paramsma = array('num_displayed' => $numrows);
         Html::showMassiveActions(__CLASS__, $paramsma);
     }
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr>";
     if ($canedit && $numrows) {
         echo "<th width='10'>";
         Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
         echo "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('Start') . "</th>";
     echo "<th>" . __('End') . "</th>";
     echo "<th>" . __('Recurrent') . "</th>";
     echo "</tr>";
     $used = array();
     if ($numrows) {
         Session::initNavigateListItems('Holiday', sprintf(__('%1$s = %2$s'), Calendar::getTypeName(1), $calendar->fields["name"]));
         foreach ($holidays as $data) {
             Session::addToNavigateListItems('Holiday', $data["id"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                 echo "</td>";
             }
             echo "<td><a href='" . Toolbox::getItemTypeFormURL('Holiday') . "?id=" . $data['id'] . "'>" . $data["name"] . "</a></td>";
             echo "<td>" . Html::convDate($data["begin_date"]) . "</td>";
             echo "<td>" . Html::convDate($data["end_date"]) . "</td>";
             echo "<td>" . Dropdown::getYesNo($data["is_perpetual"]) . "</td>";
             echo "</tr>";
         }
     }
     echo "</table>";
     if ($canedit && $numrows) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
コード例 #22
0
 /**
  * Show computers linked to a License
  *
  * @param $license SoftwareLicense object
  *
  * @return nothing
  **/
 static function showForLicense(SoftwareLicense $license)
 {
     global $DB, $CFG_GLPI;
     $searchID = $license->getField('id');
     if (!Software::canView() || !$searchID) {
         return false;
     }
     $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE));
     $canshowcomputer = Computer::canView();
     if (isset($_GET["start"])) {
         $start = $_GET["start"];
     } else {
         $start = 0;
     }
     if (isset($_GET["order"]) && $_GET["order"] == "DESC") {
         $order = "DESC";
     } else {
         $order = "ASC";
     }
     if (isset($_GET["sort"]) && !empty($_GET["sort"])) {
         // manage several param like location,compname : order first
         $tmp = explode(",", $_GET["sort"]);
         $sort = "`" . implode("` {$order},`", $tmp) . "`";
     } else {
         $sort = "`entity` {$order}, `compname`";
     }
     //SoftwareLicense ID
     $query_number = "SELECT COUNT(*) AS cpt\n                       FROM `glpi_computers_softwarelicenses`\n                       INNER JOIN `glpi_computers`\n                           ON (`glpi_computers_softwarelicenses`.`computers_id`\n                                 = `glpi_computers`.`id`)\n                       WHERE `glpi_computers_softwarelicenses`.`softwarelicenses_id` = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                             AND `glpi_computers`.`is_deleted` = '0'\n                             AND `glpi_computers`.`is_template` = '0'\n                             AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'";
     $number = 0;
     if ($result = $DB->query($query_number)) {
         $number = $DB->result($result, 0, 0);
     }
     echo "<div class='center'>";
     if ($canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>";
         echo "<input type='hidden' name='softwarelicenses_id' value='{$searchID}'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2 center'>";
         echo "<td>";
         Computer::dropdown(array('entity' => $license->fields['entities_id'], 'entity_sons' => $license->fields['is_recursive']));
         echo "</td>";
         echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
     }
     if ($number < 1) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . __('No item found') . "</th></tr>";
         echo "</table></div>\n";
         return;
     }
     // Display the pager
     Html::printAjaxPager(__('Affected computers'), $start, $number);
     $query = "SELECT `glpi_computers_softwarelicenses`.*,\n                       `glpi_computers`.`name` AS compname,\n                       `glpi_computers`.`id` AS cID,\n                       `glpi_computers`.`serial`,\n                       `glpi_computers`.`otherserial`,\n                       `glpi_users`.`name` AS username,\n                       `glpi_users`.`id` AS userid,\n                       `glpi_users`.`realname` AS userrealname,\n                       `glpi_users`.`firstname` AS userfirstname,\n                       `glpi_softwarelicenses`.`name` AS license,\n                       `glpi_softwarelicenses`.`id` AS vID,\n                       `glpi_softwarelicenses`.`name` AS vername,\n                       `glpi_entities`.`completename` AS entity,\n                       `glpi_locations`.`completename` AS location,\n                       `glpi_states`.`name` AS state,\n                       `glpi_groups`.`name` AS groupe,\n                       `glpi_softwarelicenses`.`name` AS lname,\n                       `glpi_softwarelicenses`.`id` AS lID,\n                       `glpi_softwarelicenses`.`softwares_id` AS softid\n                FROM `glpi_computers_softwarelicenses`\n                INNER JOIN `glpi_softwarelicenses`\n                     ON (`glpi_computers_softwarelicenses`.`softwarelicenses_id`\n                          = `glpi_softwarelicenses`.`id`)\n                INNER JOIN `glpi_computers`\n                     ON (`glpi_computers_softwarelicenses`.`computers_id` = `glpi_computers`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`)\n                LEFT JOIN `glpi_locations`\n                     ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`)\n                LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`)\n                LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`)\n                LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`)\n                WHERE (`glpi_softwarelicenses`.`id` = '{$searchID}') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                       AND `glpi_computers`.`is_deleted` = '0'\n                       AND `glpi_computers`.`is_template` = '0'\n                       AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'\n                ORDER BY {$sort} {$order}\n                LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     $rand = mt_rand();
     if ($result = $DB->query($query)) {
         if ($data = $DB->fetch_assoc($result)) {
             if ($canedit) {
                 $rand = mt_rand();
                 Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
                 $massiveactionparams = array('num_displayed' => $_SESSION['glpilist_limit'], 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
                 // show transfer only if multi licenses for this software
                 if (self::countLicenses($data['softid']) > 1) {
                     $massiveactionparams['specific_actions'][__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'move_license'] = _x('button', 'Move');
                 }
                 // Options to update license
                 $massiveactionparams['extraparams']['options']['move']['used'] = array($searchID);
                 $massiveactionparams['extraparams']['options']['move']['softwares_id'] = $license->fields['softwares_id'];
                 Html::showMassiveActions($massiveactionparams);
             }
             $soft = new Software();
             $soft->getFromDB($license->fields['softwares_id']);
             $showEntity = $license->isRecursive();
             $linkUser = User::canView();
             $text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]);
             $text = sprintf(__('%1$s - %2$s'), $text, $data["vername"]);
             Session::initNavigateListItems('Computer', $text);
             $sort_img = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "' alt='' title=''>";
             echo "<table class='tab_cadre_fixehov'>";
             $columns = array('compname' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'otherserial' => __('Inventory number'), 'location,compname' => __('Location'), 'state,compname' => __('Status'), 'groupe,compname' => __('Group'), 'username,compname' => __('User'));
             if (!$showEntity) {
                 unset($columns['entity']);
             }
             $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
             $header_begin = "<tr>";
             $header_top = '';
             $header_bottom = '';
             $header_end = '';
             if ($canedit) {
                 $header_begin .= "<th width='10'>";
                 $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                 $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
                 $header_end .= "</th>";
             }
             foreach ($columns as $key => $val) {
                 // Non order column
                 if ($key[0] == '_') {
                     $header_end .= "<th>{$val}</th>";
                 } else {
                     $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
                 }
             }
             $header_end .= "</tr>\n";
             echo $header_begin . $header_top . $header_end;
             do {
                 Session::addToNavigateListItems('Computer', $data["cID"]);
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit) {
                     echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
                 }
                 $compname = $data['compname'];
                 if (empty($compname) || $_SESSION['glpiis_ids_visible']) {
                     $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']);
                 }
                 if ($canshowcomputer) {
                     echo "<td><a href='computer.form.php?id=" . $data['cID'] . "'>{$compname}</a></td>";
                 } else {
                     echo "<td>" . $compname . "</td>";
                 }
                 if ($showEntity) {
                     echo "<td>" . $data['entity'] . "</td>";
                 }
                 echo "<td>" . $data['serial'] . "</td>";
                 echo "<td>" . $data['otherserial'] . "</td>";
                 echo "<td>" . $data['location'] . "</td>";
                 echo "<td>" . $data['state'] . "</td>";
                 echo "<td>" . $data['groupe'] . "</td>";
                 echo "<td>" . formatUserName($data['userid'], $data['username'], $data['userrealname'], $data['userfirstname'], $linkUser) . "</td>";
                 echo "</tr>\n";
             } while ($data = $DB->fetch_assoc($result));
             echo $header_begin . $header_bottom . $header_end;
             echo "</table>\n";
             if ($canedit) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($massiveactionparams);
                 Html::closeForm();
             }
         } else {
             // Not found
             _e('No item found');
         }
     }
     // Query
     Html::printAjaxPager(__('Affected computers'), $start, $number);
     echo "</div>\n";
 }
コード例 #23
0
ファイル: task.class.php プロジェクト: geldarr/hack-space
 static function showMinimalList($params = array())
 {
     global $DB, $CFG_GLPI;
     $item = new self();
     $itemtype = $item->getType();
     $itemtable = $item->getTable();
     // Default values of parameters
     $p['link'] = array();
     //
     $p['field'] = array();
     //
     $p['contains'] = array();
     //
     $p['searchtype'] = array();
     //
     $p['sort'] = '1';
     //
     $p['order'] = 'ASC';
     //
     $p['start'] = 0;
     //
     $p['is_deleted'] = 0;
     $p['id'] = 0;
     $p['export_all'] = 0;
     $p['link2'] = '';
     //
     $p['contains2'] = '';
     //
     $p['field2'] = '';
     //
     $p['itemtype2'] = '';
     $p['searchtype2'] = '';
     $p['withtemplate'] = 0;
     foreach ($params as $key => $val) {
         $p[$key] = $val;
     }
     $PluginResourcesResource = new PluginResourcesResource();
     $PluginResourcesResource->getFromDB($p['id']);
     $canedit = $PluginResourcesResource->can($p['id'], 'w');
     if (isset($_POST["start"])) {
         $p['start'] = $_POST["start"];
     } else {
         $p['start'] = 0;
     }
     if (isset($_POST["sort"])) {
         $p['sort'] = $_POST["sort"];
     } else {
         $p['sort'] = 1;
     }
     if (isset($_POST["order"]) && $_POST["order"] == "DESC") {
         $p['order'] = "DESC";
     } else {
         $p['order'] = "ASC";
     }
     // Manage defautll seachtype value : for bookmark compatibility
     if (count($p['contains'])) {
         foreach ($p['contains'] as $key => $val) {
             if (!isset($p['searchtype'][$key])) {
                 $p['searchtype'][$key] = 'contains';
             }
         }
     }
     if (is_array($p['contains2']) && count($p['contains2'])) {
         foreach ($p['contains2'] as $key => $val) {
             if (!isset($p['searchtype2'][$key])) {
                 $p['searchtype2'][$key] = 'contains';
             }
         }
     }
     $target = Toolbox::getItemTypeSearchURL($itemtype);
     $limitsearchopt = Search::getCleanedOptions($itemtype);
     $LIST_LIMIT = $_SESSION['glpilist_limit'];
     // Set display type for export if define
     $output_type = Search::HTML_OUTPUT;
     if (isset($_GET['display_type'])) {
         $output_type = $_GET['display_type'];
         // Limit to 10 element
         if ($_GET['display_type'] == Search::GLOBAL_SEARCH) {
             $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT;
         }
     }
     $entity_restrict = $item->isEntityAssign();
     // Get the items to display
     $toview = Search::addDefaultToView($itemtype);
     // Add items to display depending of personal prefs
     $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID());
     if (count($displaypref)) {
         foreach ($displaypref as $val) {
             array_push($toview, $val);
         }
     }
     // Add searched items
     if (count($p['field']) > 0) {
         foreach ($p['field'] as $key => $val) {
             if (!in_array($val, $toview) && $val != 'all' && $val != 'view') {
                 array_push($toview, $val);
             }
         }
     }
     // Add order item
     if (!in_array($p['sort'], $toview)) {
         array_push($toview, $p['sort']);
     }
     // Clean toview array
     $toview = array_unique($toview);
     foreach ($toview as $key => $val) {
         if (!isset($limitsearchopt[$val])) {
             unset($toview[$key]);
         }
     }
     $toview_count = count($toview);
     //// 1 - SELECT
     $query = "SELECT " . Search::addDefaultSelect($itemtype);
     // Add select for all toview item
     foreach ($toview as $key => $val) {
         $query .= Search::addSelect($itemtype, $val, $key, 0);
     }
     $query .= "`" . $itemtable . "`.`id` AS id ";
     //// 2 - FROM AND LEFT JOIN
     // Set reference table
     $query .= " FROM `" . $itemtable . "`";
     // Init already linked tables array in order not to link a table several times
     $already_link_tables = array();
     // Put reference table
     array_push($already_link_tables, $itemtable);
     // Add default join
     $COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
     $query .= $COMMONLEFTJOIN;
     $searchopt = array();
     $searchopt[$itemtype] =& Search::getOptions($itemtype);
     // Add all table for toview items
     foreach ($toview as $key => $val) {
         $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]);
     }
     // Search all case :
     if (in_array("all", $p['field'])) {
         foreach ($searchopt[$itemtype] as $key => $val) {
             // Do not search on Group Name
             if (is_array($val)) {
                 $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]);
             }
         }
     }
     $query .= " WHERE `" . $itemtable . "`.`plugin_resources_resources_id` = '" . $p['id'] . "'";
     $query .= " AND `" . $itemtable . "`.`is_deleted` = '" . $p['is_deleted'] . "' ";
     //// 7 - Manage GROUP BY
     $GROUPBY = "";
     // Meta Search / Search All / Count tickets
     if (in_array('all', $p['field'])) {
         $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
     }
     if (empty($GROUPBY)) {
         foreach ($toview as $key2 => $val2) {
             if (!empty($GROUPBY)) {
                 break;
             }
             if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) {
                 $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
             }
         }
     }
     $query .= $GROUPBY;
     //// 4 - ORDER
     $ORDER = " ORDER BY `id` ";
     foreach ($toview as $key => $val) {
         if ($p['sort'] == $val) {
             $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key);
         }
     }
     $query .= $ORDER;
     // Get it from database
     if ($result = $DB->query($query)) {
         $numrows = $DB->numrows($result);
         $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']);
         $parameters = "sort=" . $p['sort'] . "&amp;order=" . $p['order'] . $globallinkto;
         if ($output_type == Search::GLOBAL_SEARCH) {
             if (class_exists($itemtype)) {
                 echo "<div class='center'><h2>" . $item->getTypeName();
                 // More items
                 if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) {
                     echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>";
                 }
                 echo "</h2></div>\n";
             } else {
                 return false;
             }
         }
         if ($p['start'] < $numrows) {
             if ($output_type == Search::HTML_OUTPUT && !$p['withtemplate']) {
                 echo "<div align='center'>";
                 echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.php?contains%5B0%5D=" . $p['id'] . "&field%5B0%5D=13&sort=1&is_deleted=0&start=0'>" . _x('button', 'Search') . "</a><br>";
                 echo "</div>";
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $search_config = "";
                 if ($item->canCreate() && $canedit) {
                     $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&amp;itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\"";
                     $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                     $search_config .= $tmp . ">";
                 }
                 //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']);
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows, $search_config);
                 echo "<br>";
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = $p['start'] + $LIST_LIMIT;
             // Export All case
             if ($p['export_all']) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             //massive action
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 Html::openMassiveActionsForm('massform' . $itemtype);
                 $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => true, 'is_deleted' => $p['is_deleted']);
                 Html::showMassiveActions($itemtype, $massiveactionparams);
             }
             // Add toview elements
             $nbcols = $toview_count;
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $nbcols++;
             }
             // Display List Header
             echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols, 1);
             $header_num = 1;
             // Display column Headers for toview items
             $headers_line = '';
             $headers_line_top = '';
             $headers_line_bottom = '';
             echo Search::showNewLine($output_type);
             if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) {
                 // HTML display - massive modif
                 $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
                 $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
             }
             // Display column Headers for toview items
             foreach ($toview as $key => $val) {
                 $linkto = '';
                 if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) {
                     $linkto = "javascript:reloadTab('sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $p['start'] . $globallinkto . "')";
                 }
                 $headers_line .= Search::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']);
             }
             // End Line for column headers
             $headers_line .= Search::showEndLine($output_type);
             $headers_line_top .= $headers_line;
             $headers_line_bottom .= $headers_line;
             echo $headers_line_top;
             $DB->data_seek($result, $p['start']);
             // Define begin and end var for loop
             // Search case
             $i = $begin_display;
             // Init list of items displayed
             if ($output_type == Search::HTML_OUTPUT) {
                 Session::initNavigateListItems($itemtype, PluginResourcesResource::getTypeName(2) . " = " . (empty($PluginResourcesResource->fields['name']) ? "(" . $p['id'] . ")" : $PluginResourcesResource->fields['name']));
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             // Display Loop
             while ($i < $numrows && $i < $end_display) {
                 $item_num = 1;
                 $data = $DB->fetch_array($result);
                 $i++;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 Session::addToNavigateListItems($itemtype, $data['id']);
                 $tmpcheck = "";
                 if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                     $sel = "";
                     $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>";
                 }
                 echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'");
                 foreach ($toview as $key => $val) {
                     echo Search::showItem($output_type, Search::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, Search::displayConfigItem($itemtype, $val, $data, $key));
                 }
                 echo Search::showEndLine($output_type);
             }
             // Close Table
             $title = "";
             // Create title
             if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
                 $title .= __('Tasks list', 'resources');
             }
             // Display footer
             echo Search::showFooter($output_type, $title);
             //massive action
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($itemtype, $massiveactionparams);
                 Html::closeForm();
             } else {
                 echo "</table></div>";
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<br>";
                 Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows);
             }
         } else {
             echo Search::showError($output_type);
         }
     }
 }
コード例 #24
0
 function showMinimalList($params)
 {
     global $DB, $CFG_GLPI;
     $itemtype = "PluginResourcesDirectory";
     $itemtable = $this->table;
     if (class_exists($itemtype)) {
         $item = new $itemtype();
     }
     // Default values of parameters
     $p['link'] = array();
     //
     $p['field'] = array();
     //
     $p['contains'] = array();
     //
     $p['searchtype'] = array();
     //
     $p['sort'] = '1';
     //
     $p['order'] = 'ASC';
     //
     $p['start'] = 0;
     //
     $p['is_deleted'] = 0;
     $p['id'] = 0;
     $p['withtemplate'] = 0;
     $p['export_all'] = 0;
     $p['link2'] = '';
     //
     $p['contains2'] = '';
     //
     $p['field2'] = '';
     //
     $p['itemtype2'] = '';
     $p['searchtype2'] = '';
     foreach ($params as $key => $val) {
         $p[$key] = $val;
     }
     if ($p['export_all']) {
         $p['start'] = 0;
     }
     $PluginResourcesResource = new PluginResourcesResource();
     $canedit = $PluginResourcesResource->can($p['id'], 'w');
     // Manage defautlt seachtype value : for bookmark compatibility
     if (count($p['contains'])) {
         foreach ($p['contains'] as $key => $val) {
             if (!isset($p['searchtype'][$key])) {
                 $p['searchtype'][$key] = 'contains';
             }
         }
     }
     if (is_array($p['contains2']) && count($p['contains2'])) {
         foreach ($p['contains2'] as $key => $val) {
             if (!isset($p['searchtype2'][$key])) {
                 $p['searchtype2'][$key] = 'contains';
             }
         }
     }
     $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php";
     $limitsearchopt = Search::getCleanedOptions("PluginResourcesDirectory");
     $LIST_LIMIT = $_SESSION['glpilist_limit'];
     // Set display type for export if define
     $output_type = Search::HTML_OUTPUT;
     if (isset($_GET['display_type'])) {
         $output_type = $_GET['display_type'];
         // Limit to 10 element
         if ($_GET['display_type'] == Search::GLOBAL_SEARCH) {
             $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT;
         }
     }
     $entity_restrict = $PluginResourcesResource->isEntityAssign();
     // Get the items to display
     $toview = Search::addDefaultToView("User");
     // Add items to display depending of personal prefs
     $displaypref = DisplayPreference::getForTypeUser("PluginResourcesDirectory", Session::getLoginUserID());
     if (count($displaypref)) {
         foreach ($displaypref as $val) {
             array_push($toview, $val);
         }
     }
     // Add searched items
     if (count($p['field']) > 0) {
         foreach ($p['field'] as $key => $val) {
             if (!in_array($val, $toview) && $val != 'all' && $val != 'view') {
                 array_push($toview, $val);
             }
         }
     }
     // Add order item
     if (!in_array($p['sort'], $toview)) {
         array_push($toview, $p['sort']);
     }
     // Clean toview array
     $toview = array_unique($toview);
     foreach ($toview as $key => $val) {
         if (!isset($limitsearchopt[$val])) {
             unset($toview[$key]);
         }
     }
     $toview_count = count($toview);
     //// 1 - SELECT
     $query = "SELECT " . Search::addDefaultSelect("User");
     // Add select for all toview item
     foreach ($toview as $key => $val) {
         $query .= self::addSelect("PluginResourcesDirectory", $val, $key, 0);
     }
     $query .= "`glpi_plugin_resources_resources`.`id` AS id ";
     //// 2 - FROM AND LEFT JOIN
     // Set reference table
     $query .= " FROM `" . $itemtable . "`";
     // Init already linked tables array in order not to link a table several times
     $already_link_tables = array();
     // Put reference table
     array_push($already_link_tables, $itemtable);
     // Add default join
     $COMMONLEFTJOIN = Search::addDefaultJoin("PluginResourcesDirectory", $itemtable, $already_link_tables);
     $query .= $COMMONLEFTJOIN;
     $searchopt = array();
     $searchopt["PluginResourcesDirectory"] =& Search::getOptions("PluginResourcesDirectory");
     // Add all table for toview items
     foreach ($toview as $key => $val) {
         $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$val]["table"], $searchopt["PluginResourcesDirectory"][$val]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$val]["joinparams"]);
     }
     // Search all case :
     if (in_array("all", $p['field'])) {
         foreach ($searchopt[$itemtype] as $key => $val) {
             // Do not search on Group Name
             if (is_array($val)) {
                 $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$key]["table"], $searchopt["PluginResourcesDirectory"][$key]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$key]["joinparams"]);
             }
         }
     }
     $ASSIGN = " `glpi_plugin_resources_resources`.`is_leaving` = 0 AND `glpi_users`.`is_active` = 1 AND ";
     //// 3 - WHERE
     // default string
     $COMMONWHERE = Search::addDefaultWhere($itemtype);
     $first = empty($COMMONWHERE);
     // Add deleted if item have it
     if ($PluginResourcesResource && $PluginResourcesResource->maybeDeleted()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_deleted` = '" . $p['is_deleted'] . "' ";
     }
     // Remove template items
     if ($PluginResourcesResource && $PluginResourcesResource->maybeTemplate()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_template` = '0' ";
     }
     // Add Restrict to current entities
     if ($entity_restrict) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         if (isset($CFG_GLPI["union_search_type"][$itemtype])) {
             // Will be replace below in Union/Recursivity Hack
             $COMMONWHERE .= $LINK . " ENTITYRESTRICT ";
         } else {
             $COMMONWHERE .= getEntitiesRestrictRequest($LINK, "glpi_plugin_resources_resources", '', '', $PluginResourcesResource->maybeRecursive());
         }
     }
     $WHERE = "";
     $HAVING = "";
     // Add search conditions
     // If there is search items
     if ($_SESSION["glpisearchcount"]["PluginResourcesDirectory"] > 0 && count($p['contains']) > 0) {
         for ($key = 0; $key < $_SESSION["glpisearchcount"]["PluginResourcesDirectory"]; $key++) {
             // if real search (strlen >0) and not all and view search
             if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) {
                 // common search
                 if ($p['field'][$key] != "all" && $p['field'][$key] != "view") {
                     $LINK = " ";
                     $NOT = 0;
                     $tmplink = "";
                     if (is_array($p['link']) && isset($p['link'][$key])) {
                         if (strstr($p['link'][$key], "NOT")) {
                             $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]);
                             $NOT = 1;
                         } else {
                             $tmplink = " " . $p['link'][$key];
                         }
                     } else {
                         $tmplink = " AND ";
                     }
                     if (isset($searchopt["PluginResourcesDirectory"][$p['field'][$key]]["usehaving"])) {
                         // Manage Link if not first item
                         if (!empty($HAVING)) {
                             $LINK = $tmplink;
                         }
                         // Find key
                         $item_num = array_search($p['field'][$key], $toview);
                         $HAVING .= Search::addHaving($LINK, $NOT, "PluginResourcesDirectory", $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num);
                     } else {
                         // Manage Link if not first item
                         if (!empty($WHERE)) {
                             $LINK = $tmplink;
                         }
                         $WHERE .= self::addWhere($LINK, $NOT, "PluginResourcesDirectory", $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]);
                     }
                     // view and all search
                 } else {
                     $LINK = " OR ";
                     $NOT = 0;
                     $globallink = " AND ";
                     if (is_array($p['link']) && isset($p['link'][$key])) {
                         switch ($p['link'][$key]) {
                             case "AND":
                                 $LINK = " OR ";
                                 $globallink = " AND ";
                                 break;
                             case "AND NOT":
                                 $LINK = " AND ";
                                 $NOT = 1;
                                 $globallink = " AND ";
                                 break;
                             case "OR":
                                 $LINK = " OR ";
                                 $globallink = " OR ";
                                 break;
                             case "OR NOT":
                                 $LINK = " AND ";
                                 $NOT = 1;
                                 $globallink = " OR ";
                                 break;
                         }
                     } else {
                         $tmplink = " AND ";
                     }
                     // Manage Link if not first item
                     if (!empty($WHERE)) {
                         $WHERE .= $globallink;
                     }
                     $WHERE .= " ( ";
                     $first2 = true;
                     $items = array();
                     if ($p['field'][$key] == "all") {
                         $items = $searchopt["PluginResourcesDirectory"];
                     } else {
                         // toview case : populate toview
                         foreach ($toview as $key2 => $val2) {
                             $items[$val2] = $searchopt["PluginResourcesDirectory"][$val2];
                         }
                     }
                     foreach ($items as $key2 => $val2) {
                         if (is_array($val2)) {
                             // Add Where clause if not to be done in HAVING CLAUSE
                             if (!isset($val2["usehaving"])) {
                                 $tmplink = $LINK;
                                 if ($first2) {
                                     $tmplink = " ";
                                     $first2 = false;
                                 }
                                 $WHERE .= self::addWhere($tmplink, $NOT, "PluginResourcesDirectory", $key2, $p['searchtype'][$key], $p['contains'][$key]);
                             }
                         }
                     }
                     $WHERE .= " ) ";
                 }
             }
         }
     }
     if (!empty($WHERE) || !empty($COMMONWHERE)) {
         if (!empty($COMMONWHERE)) {
             $WHERE = ' WHERE ' . $ASSIGN . ' ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : '');
         } else {
             $WHERE = ' WHERE ' . $ASSIGN . ' ' . $WHERE . ' ';
         }
         $first = false;
     }
     $query .= $WHERE;
     //// 7 - Manage GROUP BY
     $GROUPBY = "";
     // Meta Search / Search All / Count tickets
     if (in_array('all', $p['field'])) {
         $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
     }
     if (empty($GROUPBY)) {
         foreach ($toview as $key2 => $val2) {
             if (!empty($GROUPBY)) {
                 break;
             }
             if (isset($searchopt["PluginResourcesDirectory"][$val2]["forcegroupby"])) {
                 $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
             }
         }
     }
     $query .= $GROUPBY;
     //// 4 - ORDER
     $ORDER = " ORDER BY `id` ";
     foreach ($toview as $key => $val) {
         if ($p['sort'] == $val) {
             $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key);
         }
     }
     $query .= $ORDER;
     // Get it from database
     if ($result = $DB->query($query)) {
         $numrows = $DB->numrows($result);
         $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("searchtype", $p['searchtype']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("searchtype2", $p['searchtype2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']);
         $parameters = "sort=" . $p['sort'] . "&amp;order=" . $p['order'] . $globallinkto;
         if ($output_type == Search::GLOBAL_SEARCH) {
             if (class_exists($itemtype)) {
                 echo "<div class='center'><h2>" . $this->getTypeName();
                 // More items
                 if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) {
                     echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>";
                 }
                 echo "</h2></div>\n";
             } else {
                 return false;
             }
         }
         if ($p['start'] < $numrows) {
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $search_config = "";
                 if ($item->canCreate() && $canedit) {
                     $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&amp;itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\"";
                     $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                     $search_config .= $tmp . ">";
                 }
                 //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']);
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config);
                 echo "<br>";
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = $p['start'] + $LIST_LIMIT;
             // Export All case
             if ($p['export_all']) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             //massive action
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 Html::openMassiveActionsForm('massform' . $itemtype);
                 $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']);
                 Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams);
             }
             // Add toview elements
             $nbcols = $toview_count;
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $nbcols++;
             }
             // Display List Header
             echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols);
             $header_num = 1;
             // Display column Headers for toview items
             $headers_line = '';
             $headers_line_top = '';
             $headers_line_bottom = '';
             echo Search::showNewLine($output_type);
             if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) {
                 // HTML display - massive modif
                 $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
                 $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
             }
             // Display column Headers for toview items
             foreach ($toview as $key => $val) {
                 $linkto = '';
                 if (!isset($searchopt["PluginResourcesDirectory"][$val]['nosort']) || !$searchopt["PluginResourcesDirectory"][$val]['nosort']) {
                     $linkto = "javascript:reloadTab('sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $p['start'] . $globallinkto . "')";
                 }
                 $headers_line .= Search::showHeaderItem($output_type, $searchopt["PluginResourcesDirectory"][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']);
             }
             // End Line for column headers
             $headers_line .= Search::showEndLine($output_type);
             $headers_line_top .= $headers_line;
             $headers_line_bottom .= $headers_line;
             echo $headers_line_top;
             $DB->data_seek($result, $p['start']);
             // Define begin and end var for loop
             // Search case
             $i = $begin_display;
             // Init list of items displayed
             if ($output_type == Search::HTML_OUTPUT) {
                 Session::initNavigateListItems($itemtype);
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             // Display Loop
             while ($i < $numrows && $i < $end_display) {
                 $item_num = 1;
                 $data = $DB->fetch_array($result);
                 $i++;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 Session::addToNavigateListItems($itemtype, $data['id']);
                 $tmpcheck = "";
                 if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                     $sel = "";
                     $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>";
                     echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'");
                 }
                 foreach ($toview as $key => $val) {
                     echo Search::showItem($output_type, Search::giveItem("PluginResourcesDirectory", $val, $data, $key), $item_num, $row_num, Search::displayConfigItem("PluginResourcesDirectory", $val, $data, $key));
                 }
                 echo Search::showEndLine($output_type);
             }
             // Close Table
             $title = "";
             // Create title
             if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
                 $title .= self::getTypeName(1);
             }
             // Display footer
             echo Search::showFooter($output_type, $title);
             //massive action
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 $massiveactionparams['ontop'] = false;
                 $massiveactionparams['fixed'] = false;
                 Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams);
                 Html::closeForm();
             } else {
                 echo "</table></div>";
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<br>";
                 Html::printPager($p['start'], $numrows, $target, $parameters, "PluginResourcesDirectory", 0, $search_config);
             }
         } else {
             echo Search::showError($output_type);
         }
     }
 }
コード例 #25
0
 /**
  * Show Licenses of a software
  *
  * @param $software Software object
  *
  * @return nothing
  **/
 static function showForSoftware(Software $software)
 {
     global $DB, $CFG_GLPI;
     $softwares_id = $software->getField('id');
     $license = new self();
     $computer = new Computer();
     if (!$software->can($softwares_id, READ)) {
         return false;
     }
     $columns = array('name' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'number' => _x('quantity', 'Number'), '_affected' => __('Affected computers'), 'typename' => __('Type'), 'buyname' => __('Purchase version'), 'usename' => __('Version in use'), 'expire' => __('Expiration'));
     if (!$software->isRecursive()) {
         unset($columns['entity']);
     }
     if (isset($_GET["start"])) {
         $start = $_GET["start"];
     } else {
         $start = 0;
     }
     if (isset($_GET["order"]) && $_GET["order"] == "DESC") {
         $order = "DESC";
     } else {
         $order = "ASC";
     }
     if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
         $sort = "`" . $_GET["sort"] . "`";
     } else {
         $sort = "`entity` {$order}, `name`";
     }
     // Righ type is enough. Can add a License on a software we have Read access
     $canedit = Software::canUpdate();
     $showmassiveactions = $canedit;
     // Total Number of events
     $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true));
     echo "<div class='spaced'>";
     Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $software->getName()));
     if ($canedit) {
         echo "<div class='center firstbloc'>";
         echo "<a class='vsubmit' href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a license') . "</a>";
         echo "</div>";
     }
     $rand = mt_rand();
     $query = "SELECT `glpi_softwarelicenses`.*,\n                       `buyvers`.`name` AS buyname,\n                       `usevers`.`name` AS usename,\n                       `glpi_entities`.`completename` AS entity,\n                       `glpi_softwarelicensetypes`.`name` AS typename\n                FROM `glpi_softwarelicenses`\n                LEFT JOIN `glpi_softwareversions` AS buyvers\n                     ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n                LEFT JOIN `glpi_softwareversions` AS usevers\n                     ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n                LEFT JOIN `glpi_entities`\n                     ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n                LEFT JOIN `glpi_softwarelicensetypes`\n                     ON (`glpi_softwarelicensetypes`.`id`\n                          = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n                WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n                ORDER BY {$sort} {$order}\n                LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     if ($result = $DB->query($query)) {
         if ($num_displayed = $DB->numrows($result)) {
             // Display the pager
             Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number);
             if ($showmassiveactions) {
                 Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
                 $massiveactionparams = array('num_displayed' => $num_displayed, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('options' => array('glpi_softwareversions.name' => array('condition' => "`glpi_softwareversions`.`softwares_id`\n                                                                  = {$softwares_id}"), 'glpi_softwarelicenses.name' => array('itemlink_as_string' => true))));
                 Html::showMassiveActions($massiveactionparams);
             }
             $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
             $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
             echo "<table class='tab_cadre_fixehov'>";
             $header_begin = "<tr><th>";
             $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_end = '';
             foreach ($columns as $key => $val) {
                 // Non order column
                 if ($key[0] == '_') {
                     $header_end .= "<th>{$val}</th>";
                 } else {
                     $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
                 }
             }
             $header_end .= "</tr>\n";
             echo $header_begin . $header_top . $header_end;
             $tot_assoc = 0;
             for ($tot = 0; $data = $DB->fetch_assoc($result);) {
                 Session::addToNavigateListItems('SoftwareLicense', $data['id']);
                 $expired = true;
                 if (is_null($data['expire']) || $data['expire'] > date('Y-m-d')) {
                     $expired = false;
                 }
                 echo "<tr class='tab_bg_2" . ($expired ? '_2' : '') . "'>";
                 if ($license->canEdit($data['id'])) {
                     echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
                 } else {
                     echo "<td>&nbsp;</td>";
                 }
                 echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a></td>";
                 if (isset($columns['entity'])) {
                     echo "<td>";
                     echo $data['entity'];
                     echo "</td>";
                 }
                 echo "<td>" . $data['serial'] . "</td>";
                 echo "<td class='numeric'>" . ($data['number'] > 0 ? $data['number'] : __('Unlimited')) . "</td>";
                 $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']);
                 $tot_assoc += $nb_assoc;
                 $color = $data['is_valid'] ? 'green' : 'red';
                 echo "<td class='numeric {$color}'>" . $nb_assoc . "</td>";
                 echo "<td>" . $data['typename'] . "</td>";
                 echo "<td>" . $data['buyname'] . "</td>";
                 echo "<td>" . $data['usename'] . "</td>";
                 echo "<td class='center'>" . Html::convDate($data['expire']) . "</td>";
                 echo "</tr>";
                 if ($data['number'] < 0) {
                     // One illimited license, total is illimited
                     $tot = -1;
                 } else {
                     if ($tot >= 0) {
                         // Expire license not count
                         if (!$expired) {
                             // Not illimited, add the current number
                             $tot += $data['number'];
                         }
                     }
                 }
             }
             echo "<tr class='tab_bg_1 noHover'>";
             echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . __('Total') . "</td>";
             echo "<td class='numeric'>" . ($tot > 0 ? $tot . "" : __('Unlimited')) . "</td>";
             $color = $software->fields['is_valid'] ? 'green' : 'red';
             echo "<td class='numeric {$color}'>" . $tot_assoc . "</td><td></td><td></td><td></td><td></td>";
             echo "</tr>";
             echo "</table>\n";
             if ($showmassiveactions) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($massiveactionparams);
                 Html::closeForm();
             }
             Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number);
         } else {
             echo "<table class='tab_cadre_fixe'><tr><th>" . __('No item found') . "</th></tr></table>";
         }
     }
     echo "</div>";
 }
コード例 #26
0
 /**
  * @param $template        NotificationTemplate object
  * @param $options   array
  **/
 function showSummary(NotificationTemplate $template, $options = array())
 {
     global $DB, $CFG_GLPI;
     $nID = $template->getField('id');
     $canedit = Config::canUpdate();
     if ($canedit) {
         echo "<div class='center'>" . "<a class='vsubmit' href='" . Toolbox::getItemTypeFormURL('NotificationTemplateTranslation') . "?notificationtemplates_id=" . $nID . "'>" . __('Add a new translation') . "</a></div><br>";
     }
     echo "<div class='center' id='tabsbody'>";
     Session::initNavigateListItems('NotificationTemplateTranslation', sprintf(__('%1$s = %2$s'), NotificationTemplate::getTypeName(1), $template->getName()));
     if ($canedit) {
         $rand = mt_rand();
         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_1'>";
     if ($canedit) {
         echo "<th width='10'>";
         Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
         echo "</th>";
     }
     echo "<th>" . __('Language') . "</th></tr>";
     foreach ($DB->request('glpi_notificationtemplatetranslations', array('notificationtemplates_id' => $nID)) as $data) {
         if ($this->getFromDB($data['id'])) {
             Session::addToNavigateListItems('NotificationTemplateTranslation', $data['id']);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td class='center'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                 echo "</td>";
             }
             echo "<td class='center'>";
             echo "<a href='" . Toolbox::getItemTypeFormURL('NotificationTemplateTranslation') . "?id=" . $data['id'] . "&amp;notificationtemplates_id=" . $nID . "'>";
             if ($data['language'] != '') {
                 echo $CFG_GLPI['languages'][$data['language']][0];
             } else {
                 _e('Default translation');
             }
             echo "</a></td></tr>";
         }
     }
     echo "</table>";
     if ($canedit) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
コード例 #27
0
 /**
  * Show the aliases contained by the alias
  *
  * @param $item                     the FQDN owning the aliases
  * @param $withtemplate  integer    withtemplate param
  **/
 static function showForFQDN(CommonGLPI $item, $withtemplate)
 {
     global $DB;
     $alias = new self();
     $address = new NetworkName();
     $item->check($item->getID(), 'r');
     $canedit = $item->can($item->getID(), 'w');
     if (isset($_POST["start"])) {
         $start = $_POST["start"];
     } else {
         $start = 0;
     }
     if (!empty($_POST["order"])) {
         $order = $_POST["order"];
     } else {
         $order = "alias";
     }
     $number = countElementsInTable($alias->getTable(), "`fqdns_id`='" . $item->getID() . "'");
     echo "<br><div class='center'>";
     if ($number < 1) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . self::getTypeName(1) . "</th><th>" . __('No item found') . "</th></tr>";
         echo "</table>\n";
     } else {
         Html::printAjaxPager(self::getTypeName($number), $start, $number);
         echo "<table class='tab_cadre_fixe'><tr>";
         echo "<th><a href='javascript:reloadTab(\"order=alias\");'>" . self::getTypeName(1) . "</a></th>";
         // Alias
         echo "<th><a href='javascript:reloadTab(\"order=realname\");'>" . __("Computer's name") . "</a></th>";
         echo "<th>" . __('Comments') . "</th>";
         echo "</tr>\n";
         Session::initNavigateListItems($item->getType(), sprintf(__('%1$s = %2$s'), self::getTypeName(1), $item->fields['name']));
         $query = "SELECT `glpi_networkaliases`.`id` AS alias_id,\n                          `glpi_networkaliases`.`name` AS alias,\n                          `glpi_networknames`.`id` AS address_id,\n                          `glpi_networkaliases`.`comment` AS comment\n                   FROM `glpi_networkaliases`, `glpi_networknames`\n                   WHERE `glpi_networkaliases`.`fqdns_id` = '" . $item->getID() . "'\n                         AND  `glpi_networknames`.`id` = `glpi_networkaliases`.`networknames_id`\n                   ORDER BY `{$order}`\n                   LIMIT " . $_SESSION['glpilist_limit'] . "\n                   OFFSET {$start}";
         foreach ($DB->request($query) as $data) {
             Session::addToNavigateListItems($alias->getType(), $data["alias_id"]);
             if ($address->getFromDB($data["address_id"])) {
                 echo "<tr class='tab_bg_1'>";
                 echo "<td><a href='" . $alias->getFormURL() . '?id=' . $data['alias_id'] . "'>" . $data['alias'] . "</a></td>";
                 echo "<td><a href='" . $address->getLinkURL() . "'>" . $address->getInternetName() . "</a></td>";
                 echo "<td>" . $data['comment'] . "</td>";
                 echo "</tr>\n";
             }
         }
         echo "</table>\n";
         Html::printAjaxPager(self::getTypeName($number), $start, $number);
     }
     echo "</div>\n";
 }
コード例 #28
0
ファイル: netpoint.class.php プロジェクト: jose-martins/glpi
 /**
  * Print the HTML array of the Netpoint associated to a Location
  *
  * @param $item Location
  *
  * @return Nothing (display)
  **/
 static function showForLocation($item)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     $netpoint = new self();
     $item->check($ID, READ);
     $canedit = $item->canEdit($ID);
     if (isset($_GET["start"])) {
         $start = intval($_GET["start"]);
     } else {
         $start = 0;
     }
     $number = countElementsInTable('glpi_netpoints', "`locations_id`='{$ID}'");
     if ($canedit) {
         echo "<div class='first-bloc'>";
         // Minimal form for quick input.
         echo "<form action='" . $netpoint->getFormURL() . "' method='post'>";
         echo "<br><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2 center'>";
         echo "<td class='b'>" . _n('Network outlet', 'Network outlets', 1) . "</td>";
         echo "<td>" . __('Name') . "</td><td>";
         Html::autocompletionTextField($item, "name", array('value' => ''));
         echo "<input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'>";
         echo "<input type='hidden' name='locations_id' value='{$ID}'></td>";
         echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>\n";
         echo "</table>\n";
         Html::closeForm();
         // Minimal form for massive input.
         echo "<form action='" . $netpoint->getFormURL() . "' method='post'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2 center'>";
         echo "<td class='b'>" . _n('Network outlet', 'Network outlets', Session::getPluralNumber()) . "</td>";
         echo "<td>" . __('Name') . "</td><td>";
         echo "<input type='text' maxlength='100' size='10' name='_before'>&nbsp;";
         Dropdown::showNumber('_from', array('value' => 0, 'min' => 0, 'max' => 400));
         echo "&nbsp;-->&nbsp;";
         Dropdown::showNumber('_to', array('value' => 0, 'min' => 0, 'max' => 400));
         echo "&nbsp;<input type='text' maxlength='100' size='10' name='_after'><br>";
         echo "<input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'>";
         echo "<input type='hidden' name='locations_id' value='{$ID}'>";
         echo "<input type='hidden' name='_method' value='AddMulti'></td>";
         echo "<td><input type='submit' name='execute' value=\"" . _sx('button', 'Add') . "\"\n                    class='submit'>";
         echo "</td></tr>\n";
         echo "</table>\n";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($number < 1) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . self::getTypeName(1) . "</th>";
         echo "<th>" . __('No item found') . "</th></tr>";
         echo "</table>\n";
     } else {
         Html::printAjaxPager(sprintf(__('Network outlets for %s'), $item->getTreeLink()), $start, $number);
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $_SESSION['glpilist_limit'], 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixe'><tr>";
         if ($canedit) {
             echo "<th width='10'>";
             Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
             echo "</th>";
         }
         echo "<th>" . __('Name') . "</th>";
         // Name
         echo "<th>" . __('Comments') . "</th>";
         // Comment
         echo "</tr>\n";
         $crit = array('locations_id' => $ID, 'ORDER' => 'name', 'START' => $start, 'LIMIT' => $_SESSION['glpilist_limit']);
         Session::initNavigateListItems('Netpoint', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($DB->request('glpi_netpoints', $crit) as $data) {
             Session::addToNavigateListItems('Netpoint', $data["id"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
             }
             echo "<td><a href='" . $netpoint->getFormURL();
             echo '?id=' . $data['id'] . "'>" . $data['name'] . "</a></td>";
             echo "<td>" . $data['comment'] . "</td>";
             echo "</tr>\n";
         }
         echo "</table>\n";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
         Html::printAjaxPager(sprintf(__('Network outlets for %s'), $item->getTreeLink()), $start, $number);
     }
     echo "</div>\n";
 }
コード例 #29
0
 /**
  * Show projecttasks for a ticket
  *
  * @param $ticket Ticket object
  **/
 static function showForTicket(Ticket $ticket)
 {
     global $DB, $CFG_GLPI;
     $ID = $ticket->getField('id');
     if (!$ticket->can($ID, READ)) {
         return false;
     }
     $canedit = $ticket->canEdit($ID);
     $rand = mt_rand();
     $query = "SELECT DISTINCT `glpi_projecttasks_tickets`.`id` AS linkID,\n                                `glpi_projecttasks`.*\n                FROM `glpi_projecttasks`\n                LEFT JOIN `glpi_projecttasks_tickets`\n                   ON (`glpi_projecttasks_tickets`.`projecttasks_id` = `glpi_projecttasks`.`id`)\n                WHERE `glpi_projecttasks_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY `glpi_projecttasks`.`name`";
     $result = $DB->query($query);
     $pjtasks = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $pjtasks[$data['id']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     //       if ($canedit) {
     //          echo "<div class='firstbloc'>";
     //          echo "<form name='projecttaskticket_form$rand' id='projecttaskticket_form$rand'
     //                 method='post' action='".Toolbox::getItemTypeFormURL(__CLASS__)."'>";
     //
     //          echo "<table class='tab_cadre_fixe'>";
     //          echo "<tr class='tab_bg_2'><th colspan='3'>".__('Add a project task')."</th></tr>";
     //
     //          echo "<tr class='tab_bg_2'><td class='right'>";
     //          echo "<input type='hidden' name='tickets_id' value='$ID'>";
     //          $condition = "`glpi_projecttasks`.`projectstates_id` <> 3";
     //          ProjectTask::dropdown(array('used'        => $used,
     //                                      'entity'      => $ticket->getEntityID(),
     //                                      'entity_sons' => $ticket->isRecursive(),
     //                                      'condition'   => $condition,
     //                                      'displaywith' => array('id')));
     //          echo "</td><td width='20%'>";
     // //          echo "<a href='".Toolbox::getItemTypeFormURL('ProjectTask')."?tickets_id=$ID'>";
     // //                 _e('Create a project task from this ticket');
     // //          echo "</a>";
     //          echo "</td><td class='center'>";
     //          echo "<input type='submit' name='add' value=\""._sx('button', 'Add')."\" class='submit'>";
     //          echo "</td></tr>";
     //
     //          echo "</table>";
     //          Html::closeForm();
     //          echo "</div>";
     //       }
     echo "<div class='spaced'>";
     if ($numrows) {
         $columns = array('projectname' => Project::getTypeName(Session::getPluralNumber()), 'name' => ProjectTask::getTypeName(Session::getPluralNumber()), 'tname' => __('Type'), 'sname' => __('Status'), 'percent_done' => __('Percent done'), 'plan_start_date' => __('Planned start date'), 'plan_end_date' => __('Planned end date'), 'planned_duration' => __('Planned duration'), '_effect_duration' => __('Effective duration'), 'fname' => __('Father'));
         if (isset($_GET["order"]) && $_GET["order"] == "DESC") {
             $order = "DESC";
         } else {
             $order = "ASC";
         }
         if (!isset($_GET["sort"]) || empty($_GET["sort"])) {
             $_GET["sort"] = "plan_start_date";
         }
         if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
             $sort = "`" . $_GET["sort"] . "`";
         } else {
             $sort = "`plan_start_date` {$order}, `name`";
         }
         $query = "SELECT `glpi_projecttasks`.*,\n                       `glpi_projecttasktypes`.`name` AS tname,\n                       `glpi_projectstates`.`name` AS sname,\n                       `glpi_projectstates`.`color`,\n                       `father`.`name` AS fname,\n                       `father`.`id` AS fID,\n                       `glpi_projects`.`name` AS projectname,\n                       `glpi_projects`.`content` AS projectcontent\n                FROM `glpi_projecttasks`\n                LEFT JOIN `glpi_projecttasktypes`\n                   ON (`glpi_projecttasktypes`.`id` = `glpi_projecttasks`.`projecttasktypes_id`)\n                LEFT JOIN `glpi_projectstates`\n                   ON (`glpi_projectstates`.`id` = `glpi_projecttasks`.`projectstates_id`)\n                LEFT JOIN `glpi_projecttasks` as father\n                   ON (`father`.`id` = `glpi_projecttasks`.`projecttasks_id`)\n                LEFT JOIN `glpi_projecttasks_tickets`\n                   ON (`glpi_projecttasks_tickets`.`projecttasks_id` = `glpi_projecttasks`.`id`)\n                LEFT JOIN `glpi_projects`\n                   ON (`glpi_projecttasks`.`projects_id` = `glpi_projects`.`id`)\n                WHERE `glpi_projecttasks_tickets`.`tickets_id` = '{$ID}'\n                ORDER BY {$sort} {$order}";
         Session::initNavigateListItems('ProjectTask', sprintf(__('%1$s = %2$s'), $ticket::getTypeName(1), $ticket->getName()));
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result)) {
                 echo "<table class='tab_cadre_fixehov'>";
                 echo "<tr><th colspan='10'>" . ProjectTask::getTypeName($numrows) . "</th>";
                 echo "</tr>";
                 $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
                 $header = '<tr>';
                 foreach ($columns as $key => $val) {
                     // Non order column
                     if ($key[0] == '_') {
                         $header .= "<th>{$val}</th>";
                     } else {
                         $header .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
                     }
                 }
                 $header .= "</tr>\n";
                 echo $header;
                 while ($data = $DB->fetch_assoc($result)) {
                     Session::addToNavigateListItems('ProjectTask', $data['id']);
                     $rand = mt_rand();
                     echo "<tr class='tab_bg_2'>";
                     echo "<td>";
                     $link = "<a id='Project" . $data["projects_id"] . $rand . "' href='project.form.php?id=" . $data['projects_id'] . "'>" . $data['projectname'] . (empty($data['projectname']) ? "(" . $data['projects_id'] . ")" : "") . "</a>";
                     echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['projectcontent'], array('display' => false, 'applyto' => "Project" . $data["projects_id"] . $rand)));
                     echo "</td>";
                     echo "<td>";
                     $link = "<a id='ProjectTask" . $data["id"] . $rand . "' href='projecttask.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a>";
                     echo sprintf(__('%1$s %2$s'), $link, Html::showToolTip($data['content'], array('display' => false, 'applyto' => "ProjectTask" . $data["id"] . $rand)));
                     echo "</td>";
                     echo "<td>" . $data['tname'] . "</td>";
                     echo "<td";
                     echo " style=\"background-color:" . $data['color'] . "\"";
                     echo ">" . $data['sname'] . "</td>";
                     echo "<td>";
                     echo Dropdown::getValueWithUnit($data["percent_done"], "%");
                     echo "</td>";
                     echo "<td>" . Html::convDateTime($data['plan_start_date']) . "</td>";
                     echo "<td>" . Html::convDateTime($data['plan_end_date']) . "</td>";
                     echo "<td>" . Html::timestampToString($data['planned_duration'], false) . "</td>";
                     echo "<td>" . Html::timestampToString(ProjectTask::getTotalEffectiveDuration($data['id']), false) . "</td>";
                     echo "<td>";
                     if ($data['projecttasks_id'] > 0) {
                         $father = Dropdown::getDropdownName('glpi_projecttasks', $data['projecttasks_id']);
                         echo "<a id='ProjectTask" . $data["projecttasks_id"] . $rand . "' href='projecttask.form.php?id=" . $data['projecttasks_id'] . "'>" . $father . (empty($father) ? "(" . $data['projecttasks_id'] . ")" : "") . "</a>";
                     }
                     echo "</td></tr>";
                 }
                 echo $header;
                 echo "</table>\n";
             } else {
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr><th>" . __('No item found') . "</th></tr>";
                 echo "</table>\n";
             }
         }
         echo "</div>";
     }
 }
コード例 #30
0
 /**
  * Print the computers disks
  *
  * @param $comp                  Computer object
  * @param $withtemplate boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForComputer(Computer $comp, $withtemplate = '')
 {
     global $DB;
     $ID = $comp->fields['id'];
     if (!$comp->getFromDB($ID) || !$comp->can($ID, READ)) {
         return false;
     }
     $canedit = $comp->canEdit($ID);
     if ($canedit && !(!empty($withtemplate) && $withtemplate == 2)) {
         echo "<div class='center firstbloc'>" . "<a class='vsubmit' href='computerdisk.form.php?computers_id={$ID}&amp;withtemplate=" . $withtemplate . "'>";
         _e('Add a volume');
         echo "</a></div>\n";
     }
     echo "<div class='center'>";
     $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n                       `glpi_computerdisks`.*\n                FROM `glpi_computerdisks`\n                LEFT JOIN `glpi_filesystems`\n                          ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n                WHERE `computers_id` = '{$ID}'\n                      AND `is_deleted` = '0'";
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixehov table-striped table-hover'>";
         $colspan = 7;
         if (Plugin::haveImport()) {
             $colspan++;
         }
         echo "<tr class='noHover'><th colspan='{$colspan}'>" . self::getTypeName($DB->numrows($result)) . "</th></tr>";
         if ($DB->numrows($result)) {
             $header = "<tr><th>" . __('Name') . "</th>";
             if (Plugin::haveImport()) {
                 $header .= "<th>" . __('Automatic inventory') . "</th>";
             }
             $header .= "<th>" . __('Partition') . "</th>";
             $header .= "<th>" . __('Mount point') . "</th>";
             $header .= "<th>" . __('File system') . "</th>";
             $header .= "<th>" . __('Global size') . "</th>";
             $header .= "<th>" . __('Free size') . "</th>";
             $header .= "<th>" . __('Free percentage') . "</th>";
             $header .= "</tr>";
             echo $header;
             Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
             $disk = new self();
             while ($data = $DB->fetch_assoc($result)) {
                 $disk->getFromDB($data['id']);
                 echo "<tr class='tab_bg_2'>";
                 echo "<td>" . $disk->getLink() . "</td>";
                 if (Plugin::haveImport()) {
                     echo "<td>" . Dropdown::getYesNo($data['is_dynamic']) . "</td>";
                 }
                 echo "<td>" . $data['device'] . "</td>";
                 echo "<td>" . $data['mountpoint'] . "</td>";
                 echo "<td>" . $data['fsname'] . "</td>";
                 //TRANS: %s is a size
                 $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['totalsize'], false, 0));
                 echo "<td class='right'>{$tmp}<span class='small_space'></span></td>";
                 $tmp = sprintf(__('%s Mio'), Html::formatNumber($data['freesize'], false, 0));
                 echo "<td class='right'>{$tmp}<span class='small_space'></span></td>";
                 echo "<td>";
                 $percent = 0;
                 if ($data['totalsize'] > 0) {
                     $percent = round(100 * $data['freesize'] / $data['totalsize']);
                 }
                 Html::displayProgressBar('100', $percent, array('simple' => true, 'forcepadding' => false));
                 echo "</td>";
                 echo "</tr>";
                 Session::addToNavigateListItems(__CLASS__, $data['id']);
             }
             echo $header;
         } else {
             echo "<tr class='tab_bg_2'><th colspan='{$colspan}'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
     }
     echo "</div><br>";
 }