getTypeName() static public method

Name of the type
static public getTypeName ( $nb )
$nb integer number of item in the type (default 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>";
 }
 static function dropdownService($ID, $options = array())
 {
     global $CFG_GLPI;
     $p = array();
     $p['name'] = 'networkports_id';
     $p['comments'] = 1;
     $p['entity'] = -1;
     $p['entity_sons'] = false;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $p[$key] = $val;
         }
     }
     // Manage entity_sons
     if (!($p['entity'] < 0) && $p['entity_sons']) {
         if (is_array($p['entity'])) {
             echo "entity_sons options is not available with array of entity";
         } else {
             $p['entity'] = getSonsOf('glpi_entities', $p['entity']);
         }
     }
     $rand = mt_rand();
     echo "<select name='itemtype[{$ID}]' id='itemtype{$rand}'>";
     echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>";
     //      $a_types =array();
     echo "<option value='Computer'>" . Computer::getTypeName() . "</option>";
     echo "<option value='NetworkEquipment'>" . NetworkEquipment::getTypeName() . "</option>";
     echo "</select>";
     $params = array('itemtype' => '__VALUE__', 'entity_restrict' => $p['entity'], 'current' => $ID, 'comments' => $p['comments'], 'myname' => $p['name'], 'rand' => $rand);
     ajaxUpdateItemOnSelectEvent("itemtype{$rand}", "show_" . $p['name'] . "{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownServiceHostType.php", $params);
     echo "<span id='show_" . $p['name'] . "{$rand}'><input type='hidden' name='services_id[]' value='0'/></span>\n";
     return $rand;
 }
 /**
  * @see CommonGLPI::getTabNameForItem()
  **/
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     $nb = 0;
     switch ($item->getType()) {
         case 'SoftwareLicense':
             if (!$withtemplate) {
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     $nb = self::countForLicense($item->getID());
                 }
                 return array(1 => __('Summary'), 2 => self::createTabEntry(Computer::getTypeName(Session::getPluralNumber()), $nb));
             }
             break;
     }
     return '';
 }
      Dropdown::show('PluginMonitoringServicescatalog', array('name'=>'items_id'));
      break;

   case 'PluginMonitoringComponentscatalog':
      Dropdown::show('PluginMonitoringComponentscatalog', array('name'=>'items_id'));
      echo "<br/>".__('Display minemap', 'monitoring')." : ";
      Dropdown::showYesNo('is_minemap');
      break;

   case 'PluginMonitoringService':
      $rand = mt_rand();
      echo "<select name='itemtype' id='itemtype$rand'>";
      echo "<option value='0'>".Dropdown::EMPTY_VALUE."</option>";

//      $a_types =array();
      echo "<option value='Computer'>".Computer::getTypeName()."</option>";
      echo "<option value='NetworkEquipment'>".NetworkEquipment::getTypeName()."</option>";
      echo "</select>";

      $params = array('itemtype'        => '__VALUE__',
                      'entity_restrict' => $_POST['a_entities'],
                      'selectgraph'     => '1',
                      'rand'            => $rand);

      Ajax::updateItemOnSelectEvent("itemtype$rand", "show_itemtype$rand",
                                  $CFG_GLPI["root_doc"]."/plugins/monitoring/ajax/dropdownServiceHostType.php",
                                  $params);

      echo "<span id='show_itemtype$rand'><input type='hidden' name='services_id[]' value='0'/></span>\n";
      break;
Example #5
0
 /**
  * Get search function for the class
  *
  * @since version 0.85
  *
  * @return array of search option
  **/
 function getSearchOptions()
 {
     $tab = parent::getSearchOptions();
     $tab[21]['table'] = $this->getTable();
     $tab[21]['field'] = 'is_visible_computer';
     $tab[21]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Computer::getTypeName(Session::getPluralNumber()));
     $tab[21]['datatype'] = 'bool';
     $tab[22]['table'] = $this->getTable();
     $tab[22]['field'] = 'is_visible_softwareversion';
     $tab[22]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), SoftwareVersion::getTypeName(Session::getPluralNumber()));
     $tab[22]['datatype'] = 'bool';
     $tab[23]['table'] = $this->getTable();
     $tab[23]['field'] = 'is_visible_monitor';
     $tab[23]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Monitor::getTypeName(Session::getPluralNumber()));
     $tab[23]['datatype'] = 'bool';
     $tab[24]['table'] = $this->getTable();
     $tab[24]['field'] = 'is_visible_printer';
     $tab[24]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Printer::getTypeName(Session::getPluralNumber()));
     $tab[24]['datatype'] = 'bool';
     $tab[25]['table'] = $this->getTable();
     $tab[25]['field'] = 'is_visible_peripheral';
     $tab[25]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Peripheral::getTypeName(Session::getPluralNumber()));
     $tab[25]['datatype'] = 'bool';
     $tab[26]['table'] = $this->getTable();
     $tab[26]['field'] = 'is_visible_phone';
     $tab[26]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), Phone::getTypeName(Session::getPluralNumber()));
     $tab[26]['datatype'] = 'bool';
     $tab[27]['table'] = $this->getTable();
     $tab[27]['field'] = 'is_visible_networkequipment';
     $tab[27]['name'] = sprintf(__('%1$s - %2$s'), __('Visibility'), NetworkEquipment::getTypeName(Session::getPluralNumber()));
     $tab[27]['datatype'] = 'bool';
     return $tab;
 }
Example #6
0
 /**
  * Print the computers antiviruses
  *
  * @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='computerantivirus.form.php?computers_id={$ID}&amp;withtemplate=" . $withtemplate . "'>";
         _e('Add an antivirus');
         echo "</a></div>\n";
     }
     echo "<div class='spaced center'>";
     if ($result = $DB->request('glpi_computerantiviruses', array('computers_id' => $ID, 'is_deleted' => 0))) {
         echo "<table class='tab_cadre_fixehov'>";
         $colspan = 7;
         if (Plugin::haveImport()) {
             $colspan++;
         }
         echo "<tr class='noHover'><th colspan='{$colspan}'>" . self::getTypeName($result->numrows()) . "</th></tr>";
         if ($result->numrows() != 0) {
             $header = "<tr><th>" . __('Name') . "</th>";
             if (Plugin::haveImport()) {
                 $header .= "<th>" . __('Automatic inventory') . "</th>";
             }
             $header .= "<th>" . __('Manufacturer') . "</th>";
             $header .= "<th>" . __('Antivirus version') . "</th>";
             $header .= "<th>" . __('Signature database version') . "</th>";
             $header .= "<th>" . __('Active') . "</th>";
             $header .= "<th>" . __('Up to date') . "</th>";
             $header .= "<th>" . __('Expiration date') . "</th>";
             $header .= "</tr>";
             echo $header;
             Session::initNavigateListItems(__CLASS__, sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
             $antivirus = new self();
             foreach ($result as $data) {
                 $antivirus->getFromDB($data['id']);
                 echo "<tr class='tab_bg_2'>";
                 echo "<td>" . $antivirus->getLink() . "</td>";
                 if (Plugin::haveImport()) {
                     echo "<td>" . Dropdown::getYesNo($data['is_dynamic']) . "</td>";
                 }
                 echo "<td>";
                 if ($data['manufacturers_id']) {
                     echo Dropdown::getDropdownName('glpi_manufacturers', $data['manufacturers_id']) . "</td>";
                 } else {
                     echo "</td>";
                 }
                 echo "<td>" . $data['antivirus_version'] . "</td>";
                 echo "<td>" . $data['signature_version'] . "</td>";
                 echo "<td>" . Dropdown::getYesNo($data['is_active']) . "</td>";
                 echo "<td>" . Dropdown::getYesNo($data['is_uptodate']) . "</td>";
                 echo "<td>" . Html::convDate($data['date_expiration']) . "</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>";
 }
 /**
  * Show software installed on a computer
  *
  * @param $comp            Computer object
  * @param $withtemplate    template case of the view process (default '')
  *
  * @return nothing
  **/
 static function showForComputer(Computer $comp, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (!Software::canView()) {
         return false;
     }
     $computers_id = $comp->getField('id');
     $rand = mt_rand();
     $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE));
     $entities_id = $comp->fields["entities_id"];
     $crit = Session::getSavedOption(__CLASS__, 'criterion', -1);
     $where = '';
     if ($crit > -1) {
         $where = " AND `glpi_softwares`.`softwarecategories_id` = {$crit}";
     }
     $add_dynamic = '';
     if (Plugin::haveImport()) {
         $add_dynamic = "`glpi_computers_softwareversions`.`is_dynamic`,";
     }
     $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n                       `glpi_softwares`.`name` AS softname,\n                       `glpi_computers_softwareversions`.`id`,\n                       {$add_dynamic}\n                       `glpi_states`.`name` AS state,\n                       `glpi_softwareversions`.`id` AS verid,\n                       `glpi_softwareversions`.`softwares_id`,\n                       `glpi_softwareversions`.`name` AS version,\n                       `glpi_softwares`.`is_valid` AS softvalid\n                FROM `glpi_computers_softwareversions`\n                LEFT JOIN `glpi_softwareversions`\n                     ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                           = `glpi_softwareversions`.`id`)\n                LEFT JOIN `glpi_states`\n                     ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                LEFT JOIN `glpi_softwares`\n                     ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n                WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n                      AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n                      {$where}\n                ORDER BY `softname`, `version`";
     $result = $DB->query($query);
     $i = 0;
     if ((empty($withtemplate) || $withtemplate != 2) && $canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>";
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><td class='center'>";
         echo _n('Software', 'Software', Session::getPluralNumber()) . "&nbsp;&nbsp;";
         echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         Software::dropdownSoftwareToInstall("softwareversions_id", $entities_id);
         echo "</td><td width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Install') . "\"\n                class='submit'>";
         echo "</td>";
         echo "</tr>\n";
         echo "</table></div>\n";
         Html::closeForm();
     }
     echo "<div class='spaced'>";
     $cat = -1;
     Session::initNavigateListItems('Software', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
     Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
     // Mini Search engine
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'><th colspan='2'>" . Software::getTypeName(Session::getPluralNumber()) . "</th></tr>";
     echo "<tr class='tab_bg_1'><td class='center'>";
     echo __('Category') . "</td><td>";
     SoftwareCategory::dropdown(array('value' => $crit, 'toadd' => array('-1' => __('All categories')), 'emptylabel' => __('Uncategorized software'), 'on_change' => 'reloadTab("start=0&criterion="+this.value)'));
     echo "</td></tr></table></div>";
     $number = $DB->numrows($result);
     $start = isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0;
     if ($start >= $number) {
         $start = 0;
     }
     $installed = array();
     if ($number) {
         echo "<div class='spaced'>";
         Html::printAjaxPager('', $start, $number);
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
             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' . __CLASS__ . $rand);
             $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_end .= "</th>";
         }
         $header_end .= "<th>" . __('Name') . "</th><th>" . __('Status') . "</th>";
         $header_end .= "<th>" . __('Version') . "</th><th>" . __('License') . "</th>";
         if (Plugin::haveImport()) {
             $header_end .= "<th>" . __('Automatic inventory') . "</th>";
         }
         $header_end .= "<th>" . SoftwareCategory::getTypeName(1) . "</th>";
         $header_end .= "<th>" . __('Valid license') . "</th>";
         $header_end .= "</tr>\n";
         echo $header_begin . $header_top . $header_end;
         for ($row = 0; $data = $DB->fetch_assoc($result); $row++) {
             if ($row >= $start && $row < $start + $_SESSION['glpilist_limit']) {
                 $licids = self::softsByCategory($data, $computers_id, $withtemplate, $canedit, true);
             } else {
                 $licids = self::softsByCategory($data, $computers_id, $withtemplate, $canedit, false);
             }
             Session::addToNavigateListItems('Software', $data["softwares_id"]);
             foreach ($licids as $licid) {
                 Session::addToNavigateListItems('SoftwareLicense', $licid);
                 $installed[] = $licid;
             }
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
     } else {
         echo "<p class='center b'>" . __('No item found') . "</p>";
     }
     echo "</div>\n";
     if ((empty($withtemplate) || $withtemplate != 2) && $canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>";
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         echo _n('License', 'Licenses', Session::getPluralNumber()) . "&nbsp;&nbsp;";
         echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         Software::dropdownLicenseToInstall("softwarelicenses_id", $entities_id);
         echo "</td><td width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>\n";
         echo "</table></div>\n";
         Html::closeForm();
     }
     echo "<div class='spaced'>";
     // Affected licenses NOT installed
     $query = "SELECT `glpi_softwarelicenses`.*,\n                       `glpi_computers_softwarelicenses`.`id` AS linkID,\n                       `glpi_softwares`.`name` AS softname,\n                       `glpi_softwareversions`.`name` AS version,\n                       `glpi_states`.`name` AS state\n                FROM `glpi_softwarelicenses`\n                LEFT JOIN `glpi_computers_softwarelicenses`\n                      ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n                              = `glpi_softwarelicenses`.`id`)\n                INNER JOIN `glpi_softwares`\n                      ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n                LEFT JOIN `glpi_softwareversions`\n                      ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n                              = `glpi_softwareversions`.`id`\n                           OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n                               AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n                                       = `glpi_softwareversions`.`id`))\n                LEFT JOIN `glpi_states`\n                     ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$computers_id}'\n                      AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'\n                      {$where}";
     if (count($installed)) {
         $query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")";
     }
     $query .= " ORDER BY `softname`, `version`;";
     $req = $DB->request($query);
     if ($number = $req->numrows()) {
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('massSoftwareLicense' . $rand);
             $actions = array('Computer_SoftwareLicense' . MassiveAction::CLASS_ACTION_SEPARATOR . 'install' => _x('button', 'Install'));
             if (SoftwareLicense::canUpdate()) {
                 $actions['purge'] = _x('button', 'Delete permanently');
             }
             $massiveactionparams = array('num_displayed' => $number, 'container' => 'massSoftwareLicense' . $rand, 'specific_actions' => $actions);
             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('massSoftwareLicense' . $rand);
             $header_bottom .= Html::getCheckAllAsCheckbox('massSoftwareLicense' . $rand);
             $header_end .= "</th>";
         }
         $header_end .= "<th>" . __('Name') . "</th><th>" . __('Status') . "</th>";
         $header_end .= "<th>" . __('Version') . "</th><th>" . __('License') . "</th>";
         $header_end .= "</tr>\n";
         echo $header_begin . $header_top . $header_end;
         $cat = true;
         foreach ($req as $data) {
             self::displaySoftsByLicense($data, $computers_id, $withtemplate, $canedit);
             Session::addToNavigateListItems('SoftwareLicense', $data["id"]);
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
     }
     echo "</div>\n";
 }
Example #8
0
            $computer->check($_POST['id'], DELETE);
            if ($computer->restore($_POST)) {
                Event::log($_POST["id"], "computers", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
            }
            $computer->redirectToList();
        } else {
            if (isset($_POST["purge"])) {
                $computer->check($_POST['id'], PURGE);
                if ($computer->delete($_POST, 1)) {
                    Event::log($_POST["id"], "computers", 4, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
                }
                $computer->redirectToList();
                //update a computer
            } else {
                if (isset($_POST["update"])) {
                    $computer->check($_POST['id'], UPDATE);
                    $computer->update($_POST);
                    Event::log($_POST["id"], "computers", 4, "inventory", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
                    Html::back();
                    // Disconnect a computer from a printer/monitor/phone/peripheral
                } else {
                    //print computer information
                    Html::header(Computer::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "assets", "computer");
                    //show computer form to add
                    $computer->display(array('id' => $_GET["id"], 'withtemplate' => $_GET["withtemplate"]));
                    Html::footer();
                }
            }
        }
    }
}
 /**
  * Print the form for devices linked to a computer or a template
  *
  * @param $computer Computer object
  * @param $withtemplate='' boolean : template or basic computer
  *
  * @return Nothing (display)
  **/
 static function showForComputer(Computer $computer, $withtemplate = '')
 {
     global $DB, $LANG;
     $devtypes = self::getDeviceTypes();
     $ID = $computer->getField('id');
     if (!$computer->can($ID, 'r')) {
         return false;
     }
     $canedit = $withtemplate != 2 && $computer->can($ID, 'w');
     echo "<div class='spaced'>";
     if ($canedit) {
         echo "<form name='form_device_action' action='" . getItemTypeFormURL(__CLASS__) . "' method='post'>";
         echo "<input type='hidden' name='computers_id' value='{$ID}'>";
     }
     echo "<table class='tab_cadre_fixe' >";
     echo "<tr><th colspan='63'>" . $LANG['title'][30] . "</th></tr>";
     $nb = 0;
     $specificity_units = array('DeviceProcessor' => $LANG['setup'][35], 'DeviceMemory' => $LANG['common'][82], 'DeviceHardDrive' => $LANG['common'][82], 'DeviceGraphicCard' => $LANG['common'][82]);
     foreach ($devtypes as $itemtype) {
         initNavigateListItems($itemtype, $computer->getTypeName() . " = " . $computer->getName());
         $device = new $itemtype();
         $specificities = $device->getSpecifityLabel();
         $specif_fields = array_keys($specificities);
         $specif_text = implode(',', $specif_fields);
         if (!empty($specif_text)) {
             $specif_text = " ," . $specif_text . " ";
         }
         $linktable = getTableForItemType('Computer_' . $itemtype);
         $fk = getForeignKeyFieldForTable(getTableForItemType($itemtype));
         $query = "SELECT COUNT(*) AS NB,\n                          `id`,\n                          `{$fk}`\n                          {$specif_text}\n                   FROM `{$linktable}`\n                   WHERE `computers_id` = '{$ID}'\n                   GROUP BY `{$fk}` {$specif_text}";
         $prev = '';
         foreach ($DB->request($query) as $data) {
             addToNavigateListItems($itemtype, $data[$fk]);
             if ($device->getFromDB($data[$fk])) {
                 echo "<tr class='tab_bg_2'>";
                 echo "<td class='center'>";
                 Dropdown::showInteger("quantity_" . $itemtype . "_" . $data['id'], $data['NB']);
                 echo "</td><td>";
                 if ($device->canCreate()) {
                     echo "<a href='" . $device->getSearchURL() . "'>" . $device->getTypeName() . "</a>";
                 } else {
                     echo $device->getTypeName();
                 }
                 echo "</td><td>" . $device->getLink() . "</td>";
                 $spec = $device->getFormData();
                 if (isset($spec['label']) && count($spec['label'])) {
                     $colspan = 60 / count($spec['label']);
                     foreach ($spec['label'] as $i => $label) {
                         if (isset($spec['value'][$i])) {
                             echo "<td colspan='{$colspan}'>" . $spec['label'][$i] . "&nbsp;: ";
                             echo $spec['value'][$i] . "</td>";
                         } else {
                             if ($canedit) {
                                 // Specificity
                                 echo "<td class='right' colspan='{$colspan}'>" . $spec['label'][$i] . "&nbsp;: ";
                                 echo "<input type='text' name='value_" . $itemtype . "_" . $data['id'] . "' value='" . $data['specificity'] . "' size='" . $spec['size'] . "'>";
                                 if (isset($specificity_units[$device->getType()])) {
                                     echo '&nbsp;' . $specificity_units[$device->getType()];
                                 }
                                 echo "</td>";
                             } else {
                                 echo "<td colspan='{$colspan}'>" . $spec['label'][$i] . "&nbsp;: ";
                                 echo $data['specificity'];
                                 if (isset($specificity_units[$device->getType()])) {
                                     echo '&nbsp;' . $specificity_units[$device->getType()];
                                 }
                                 echo "</td>";
                             }
                         }
                     }
                 } else {
                     echo "<td colspan='60'>&nbsp;</td>";
                 }
                 echo "</tr>";
                 $nb++;
             }
         }
     }
     if ($canedit) {
         if ($nb > 0) {
             echo "<tr><td colspan='63' class='tab_bg_1 center'>";
             echo "<input type='submit' class='submit' name='updateall' value='" . $LANG['buttons'][7] . "'></td></tr>";
         }
         echo "<tr><td colspan='63' class='tab_bg_1 center'>";
         echo $LANG['devices'][0] . "&nbsp;: ";
         Dropdown::showAllItems('items_id', '', 0, -1, $devtypes);
         echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
         echo "</tr></table></form>";
     } else {
         echo "</table>";
     }
     echo "</div>";
 }
Example #10
0
}
$disk = new ComputerDisk();
if (isset($_POST["add"])) {
    $disk->check(-1, 'w', $_POST);
    if ($newID = $disk->add($_POST)) {
        Event::log($_POST['computers_id'], "computers", 4, "inventory", sprintf(__('%s adds a volume'), $_SESSION["glpiname"]));
    }
    Html::back();
} else {
    if (isset($_POST["delete"])) {
        $disk->check($_POST["id"], 'd');
        if ($disk->delete($_POST)) {
            Event::log($disk->fields['computers_id'], "computers", 4, "inventory", sprintf(__('%s deletes a volume'), $_SESSION["glpiname"]));
        }
        $computer = new Computer();
        $computer->getFromDB($disk->fields['computers_id']);
        Html::redirect(Toolbox::getItemTypeFormURL('Computer') . '?id=' . $disk->fields['computers_id'] . ($computer->fields['is_template'] ? "&withtemplate=1" : ""));
    } else {
        if (isset($_POST["update"])) {
            $disk->check($_POST["id"], 'w');
            if ($disk->update($_POST)) {
                Event::log($disk->fields['computers_id'], "computers", 4, "inventory", sprintf(__('%s updates a volume'), $_SESSION["glpiname"]));
            }
            Html::back();
        } else {
            Html::header(Computer::getTypeName(2), $_SERVER['PHP_SELF'], "inventory", "computer");
            $disk->showForm($_GET["id"], array('computers_id' => $_GET["computers_id"]));
            Html::footer();
        }
    }
}
 /**
  * Show software installed on a computer
  *
  * @param $comp            Computer object
  * @param $withtemplate    template case of the view process (default '')
  *
  * @return nothing
  **/
 static function showForComputer(Computer $comp, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight("software", "r")) {
         return false;
     }
     $computers_id = $comp->getField('id');
     $rand = mt_rand();
     $canedit = Session::haveRight("software", "w");
     $entities_id = $comp->fields["entities_id"];
     $add_dynamic = '';
     if (Plugin::haveImport()) {
         $add_dynamic = "`glpi_computers_softwareversions`.`is_dynamic`,";
     }
     $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n                       `glpi_softwares`.`name` AS softname,\n                       `glpi_computers_softwareversions`.`id`,\n                       {$add_dynamic}\n                       `glpi_states`.`name` AS state,\n                       `glpi_softwareversions`.`id` AS verid,\n                       `glpi_softwareversions`.`softwares_id`,\n                       `glpi_softwareversions`.`name` AS version\n                FROM `glpi_computers_softwareversions`\n                LEFT JOIN `glpi_softwareversions`\n                     ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                           = `glpi_softwareversions`.`id`)\n                LEFT JOIN `glpi_states`\n                     ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                LEFT JOIN `glpi_softwares`\n                     ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n                WHERE `glpi_computers_softwareversions`.`computers_id` = '{$computers_id}'\n                      AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n                ORDER BY `softwarecategories_id`, `softname`, `version`";
     $result = $DB->query($query);
     $i = 0;
     if ((empty($withtemplate) || $withtemplate != 2) && $canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>";
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><td class='center'>";
         echo _n('Software', 'Software', 2) . "&nbsp;&nbsp;";
         echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         Software::dropdownSoftwareToInstall("softwareversions_id", $entities_id);
         echo "</td><td width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Install') . "\"\n                class='submit'>";
         echo "</td>";
         echo "</tr>\n";
         echo "</table></div>\n";
         Html::closeForm();
     }
     echo "<div class='spaced'>";
     $cat = -1;
     Session::initNavigateListItems('Software', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
     Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName()));
     $installed = array();
     if ($number = $DB->numrows($result)) {
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $paramsma = array('num_displayed' => $number, 'specific_actions' => array('purge' => _x('button', 'Delete permanently')));
             Html::showMassiveActions(__CLASS__, $paramsma);
         }
         echo "<table class='tab_cadre_fixe'>";
         while ($data = $DB->fetch_assoc($result)) {
             if ($data["softwarecategories_id"] != $cat) {
                 self::displayCategoryFooter($cat, $rand, $canedit);
                 $cat = self::displayCategoryHeader($computers_id, $data, $rand, $canedit);
             }
             $licids = self::displaySoftsByCategory($data, $computers_id, $withtemplate, $canedit);
             Session::addToNavigateListItems('Software', $data["softwares_id"]);
             foreach ($licids as $licid) {
                 Session::addToNavigateListItems('SoftwareLicense', $licid);
                 $installed[] = $licid;
             }
         }
         self::displayCategoryFooter($cat, $rand, $canedit);
         echo "</table>";
         if ($canedit) {
             $paramsma['ontop'] = false;
             Html::showMassiveActions(__CLASS__, $paramsma);
             Html::closeForm();
         }
     }
     echo "</div>\n";
     if ((empty($withtemplate) || $withtemplate != 2) && $canedit) {
         echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>";
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         echo _n('License', 'Licenses', 2) . "&nbsp;&nbsp;";
         echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         Software::dropdownLicenseToInstall("softwarelicenses_id", $entities_id);
         echo "</td><td width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>\n";
         echo "</table></div>\n";
         Html::closeForm();
     }
     echo "<div class='spaced'>";
     // Affected licenses NOT installed
     $query = "SELECT `glpi_softwarelicenses`.*,\n                       `glpi_computers_softwarelicenses`.`id` AS linkID,\n                       `glpi_softwares`.`name` AS softname,\n                       `glpi_softwareversions`.`name` AS version,\n                       `glpi_states`.`name` AS state\n                FROM `glpi_softwarelicenses`\n                LEFT JOIN `glpi_computers_softwarelicenses`\n                      ON (`glpi_computers_softwarelicenses`.softwarelicenses_id\n                              = `glpi_softwarelicenses`.`id`)\n                INNER JOIN `glpi_softwares`\n                      ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`)\n                LEFT JOIN `glpi_softwareversions`\n                      ON (`glpi_softwarelicenses`.`softwareversions_id_use`\n                              = `glpi_softwareversions`.`id`\n                           OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0'\n                               AND `glpi_softwarelicenses`.`softwareversions_id_buy`\n                                       = `glpi_softwareversions`.`id`))\n                LEFT JOIN `glpi_states`\n                     ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n                WHERE `glpi_computers_softwarelicenses`.`computers_id` = '{$computers_id}'\n                      AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'";
     if (count($installed)) {
         $query .= " AND `glpi_softwarelicenses`.`id` NOT IN (" . implode(',', $installed) . ")";
     }
     $req = $DB->request($query);
     if ($number = $req->numrows()) {
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('massSoftwareLicense' . $rand);
             $actions = array('install' => _x('button', 'Install'));
             if (SoftwareLicense::canUpdate()) {
                 $actions['purge'] = _x('button', 'Delete permanently');
             }
             $paramsma = array('num_displayed' => $number, 'specific_actions' => $actions);
             Html::showMassiveActions('Computer_SoftwareLicense', $paramsma);
             echo "<input type='hidden' name='computers_id' value='{$computers_id}'>";
         }
         echo "<table class='tab_cadre_fixe'>";
         $cat = true;
         foreach ($req as $data) {
             if ($cat) {
                 self::displayCategoryHeader($computers_id, $data, $rand, $canedit);
                 $cat = false;
             }
             self::displaySoftsByLicense($data, $computers_id, $withtemplate, $canedit);
             Session::addToNavigateListItems('SoftwareLicense', $data["id"]);
         }
         self::displayCategoryFooter(NULL, $rand, $canedit);
         echo "</table>";
         if ($canedit) {
             $paramsma['ontop'] = false;
             Html::showMassiveActions('Computer_SoftwareLicense', $paramsma);
             Html::closeForm();
         }
     }
     echo "</div>\n";
 }
include "../../../inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
switch ($_POST['itemtype']) {
    case 'PluginMonitoringServicescatalog':
        Dropdown::show('PluginMonitoringServicescatalog', array('name' => 'items_id'));
        break;
    case 'PluginMonitoringComponentscatalog':
        Dropdown::show('PluginMonitoringComponentscatalog', array('name' => 'items_id'));
        echo "<br/>" . __('Display minemap', 'monitoring') . " : ";
        Dropdown::showYesNo('is_minemap');
        break;
    case 'PluginMonitoringService':
        $rand = mt_rand();
        $elements = array('0' => Dropdown::EMPTY_VALUE, 'Computer' => Computer::getTypeName(), 'NetworkEquipment' => NetworkEquipment::getTypeName());
        Dropdown::showFromArray('itemtype', $elements, array('rand' => $rand, 'emptylabel' => true, 'display_emptychoice' => true));
        $params = array('itemtype' => '__VALUE__', 'entity_restrict' => $_POST['a_entities'], 'selectgraph' => '1', 'rand' => $rand);
        Ajax::updateItemOnSelectEvent("dropdown_itemtype{$rand}", "show_itemtype{$rand}", $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownServiceHostType.php", $params);
        echo "<span id='show_itemtype{$rand}'><input type='hidden' name='services_id[]' value='0'/></span>\n";
        break;
    case 'PluginMonitoringWeathermap':
        $toadd = array('-1' => "[" . __('Legend', 'monitoring') . "]");
        Dropdown::show('PluginMonitoringWeathermap', array('name' => 'items_id', 'toadd' => $toadd));
        echo "<br/>" . __('% of the width of the frame', 'monitoring') . "&nbsp: ";
        Dropdown::showNumber("extra_infos", array('value' => 100, 'min' => 0, 'max' => 100, 'step' => 5));
        break;
    case 'PluginMonitoringDisplayview':
        if (isset($_POST['sliders_id'])) {
            Dropdown::show('PluginMonitoringDisplayview', array('name' => 'items_id'));
        } else {
 /**
  * Get types of datas available to select for taskjob definition for WakeOnLan method
  *
  * @param $a_itemtype array types yet added for definitions
  *
  * @return array ('itemtype'=>'value', 'itemtype'=>'value'...)
  *   itemtype itemtype of object
  *   value name of the itemtype
  **/
 static function task_definitiontype_wakeonlan($a_itemtype)
 {
     $a_itemtype['Computer'] = Computer::getTypeName();
     $a_itemtype['PluginFusioninventoryDeployGroup'] = __('Dynamic Group');
     return $a_itemtype;
 }