static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $item) { global $DB; $sID = $item->getField('id'); $query = "SELECT `glpi_softwareversions`.*,\n `glpi_states`.`name` AS sname,\n `glpi_operatingsystems`.`name` AS osname\n FROM `glpi_softwareversions`\n LEFT JOIN `glpi_states`\n ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`)\n LEFT JOIN `glpi_operatingsystems`\n ON (`glpi_operatingsystems`.`id` = `glpi_softwareversions`.`operatingsystems_id`)\n WHERE (`softwares_id` = '" . $sID . "')\n ORDER BY `name`"; $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . SoftwareVersion::getTypeName(2) . '</b>'); if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { $pdf->setColumnsSize(13, 13, 30, 14, 30); $pdf->displayTitle('<b><i>' . SoftwareVersion::getTypeName(2) . '</i></b>', '<b><i>' . __('Status') . '</i></b>', '<b><i>' . __('Operating system') . '</i></b>', '<b><i>' . _n('Installation', 'Installations', 2) . '</i></b>', '<b><i>' . __('Comments') . '</i></b>'); $pdf->setColumnsAlign('left', 'left', 'left', 'right', 'left'); for ($tot = $nb = 0; $data = $DB->fetch_assoc($result); $tot += $nb) { $nb = Computer_SoftwareVersion::countForVersion($data['id']); $pdf->displayLine(empty($data['name']) ? "(" . $data['id'] . ")" : $data['name'], $data['sname'], $data['osname'], $nb, str_replace(array("\r", "\n"), " ", $data['comment'])); } $pdf->setColumnsAlign('left', 'right', 'left', 'right', 'left'); $pdf->displayTitle('', '', "<b>" . sprintf(__('%1$s: %2$s'), __('Total') . "</b>", ''), $tot, ''); } else { $pdf->displayLine(__('No item found')); } } else { $pdf->displayLine(__('No item found')); } $pdf->displaySpace(); }
function index() { $conn = Db::get_connection(); if (isset($_GET['software_name'])) { $software_factory = new Software(); $softwares = $software_factory->find_all(array('where_clause' => "`name` = '{$conn->escape($_GET['software_name'])}' AND (`name` != 'guidatv' OR `type` = 'macosx')", 'limit' => 1)); if (count($softwares) > 0) { $this->software = $softwares[0]; $this->software->has_many('software_releases'); // Sort releases $releases = $this->software->software_releases; usort($releases, array($releases[0], 'sort_releases')); $this->software->release = $releases[0]; $this->software->release->has_many('software_artifacts'); // Horrible hack to enable per-software caching. $_REQUEST['id'] = $this->software->id; } } else { if (isset($_GET['id'])) { $this->software = new Software(); $this->software->find_by_id($_GET['id']); $this->software->has_many('software_releases'); // Sort releases $releases = $this->software->software_releases; usort($releases, array($releases[0], 'sort_releases')); $this->software->release = $releases[0]; $this->software->release->has_many('software_artifacts'); } else { $this->render_error(); } } Db::close_connection($conn); }
static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $software, $infocom = false) { global $DB; $sID = $software->getField('id'); $license = new SoftwareLicense(); $query = "SELECT `id`\n FROM `glpi_softwarelicenses`\n WHERE `softwares_id` = '" . $sID . "' " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n ORDER BY `name`"; $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . _n('License', 'Licenses', 2) . '</b>'); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { for ($tot = 0; $data = $DB->fetch_assoc($result);) { if ($license->getFromDB($data['id'])) { self::pdfMain($pdf, $license, false); if ($infocom) { PluginPdfInfocom::pdfForItem($pdf, $license); } } } } else { $pdf->displayLine(__('No item found')); } } else { $pdf->displayLine(__('No item found')); } $pdf->displaySpace(); }
/** * Este serve para inserir objeto em um software. * @param Objeto $objeto * @param Software $software * @return boolean */ public function inserir(Objeto $objeto, Software $software) { $idSoftware = $software->getId(); $nomeDoObjeto = $objeto->getNome(); $persistenciaObjeto = $objeto->getPersistencia(); $insert = "INSERT into objeto\n\t\t(software_id_software, nome, persistencia) \n\t\tvalues({$idSoftware}, '{$nomeDoObjeto}', '{$persistenciaObjeto}')"; if ($this->conexao->query($insert)) { return true; } else { //echo "<br>".$insert; return false; } }
/** * @fn update_versiontracker_ratings * @short Action method that updates the VersionTracker ratings for software products. */ public function update_versiontracker_ratings() { $conn = Db::get_connection(); error_reporting(E_ALL | E_STRICT); $sw = new Software(); $softwares = $sw->find_all(); foreach ($softwares as $software) { $software->has_one('version_tracker_entries'); if ($software->version_tracker_entry && $software->version_tracker_entry->vt_id != 0) { $vt = new VTRatingsParser($software->version_tracker_entry->vt_id); $vt->parse(); $software->version_tracker_entry->rating = $vt->rating; $software->version_tracker_entry->save(); } } $this->render(NULL); Db::close_connection($conn); }
/** * Show table with linked licenses to user * @param Software $software * @return bool */ private static function showUsersLicenses(Software $software) { global $DB; $softwareId = $software->getField("id"); $totalRecordsCount = self::countLicenses($software); $currentPage = isset($_GET["start"]) ? $_GET["start"] : 0; $sortingOrder = SortingOrder::getFromString($_GET["order"]); $columnKeys = array_keys(self::getColumns()); $sortingColumn = array_key_exists($_GET["sort"], self::getColumns()) ? $_GET["sort"] : reset($columnKeys); $queryResult = $DB->query(self::getDataQuery($softwareId, $currentPage, $sortingColumn, $sortingOrder)); $options = PluginFpsoftwareConfig::getConfigValues(array('group_by_users')); Html::printAjaxPager(self::getTypeName(2), $currentPage, $totalRecordsCount); echo self::printTableBegin(); echo self::printGridColumnsHeaders($sortingOrder, $sortingColumn); if ($totalRecordsCount > 0) { while ($data = $DB->fetch_assoc($queryResult)) { echo "<tr class='tab_bg_1'>"; echo "<td class='left'><a href='softwarelicense.form.php?id=" . $data['license_id'] . "'>" . $data["license_name"] . "</a> - " . $data["license_serial"] . " (" . $data["license_type"] . ") " . "</td>"; echo "<td class='left'><a href='user.form.php?id=" . $data['user_id'] . "'>" . $data["user_name"] . "</a></td>"; if ($options['group_by_users']) { $computers = array(); if ($data['computer_ids']) { $computer_ids = explode(';|;', $data['computer_ids']); $computer_names = explode(';|;', $data['computer_names']); foreach ($computer_ids as $index => $computer_id) { $computers[] = " <a href='computer.form.php?id=" . $computer_id . "'>" . $computer_names[$index] . "</a>"; } } echo "<td class='left'>"; echo implode("<br /><br />", $computers) . "</td>"; } else { echo "<td class='left'><a href='computer.form.php?id=" . $data['computer_id'] . "'>" . $data["computer_name"] . "</a></td>"; } echo "<td class='left'><a href='location.form.php?id=" . $data['location_id'] . "'>" . $data["location_name"] . "</a></td>"; echo "</tr>"; } } else { echo "<tr class='tab_bg_1'><td class='center' colspan='3'>No results.</td></tr>"; } Html::printAjaxPager(self::getTypeName(2), $currentPage, $totalRecordsCount); echo self::printTableEnd(); return true; }
/** * @param $info array * @param $option array **/ function showAdditionalInformation($info = array(), $option = array()) { $name = "info[" . $option['linkfield'] . "]"; switch ($option['displaytype']) { case 'computer': Computer::dropdown(array('name' => $name, 'entity' => $_SESSION['glpiactive_entity'], 'entity_sons' => false)); break; case 'software': Software::dropdown(array('name' => $name, 'entity' => $_SESSION['glpiactive_entity'], 'entity_sons' => false)); break; default: break; } }
public function retornaSoftwareDetalhado(Software $software) { if ($software->getId()) { //Pega dados do software. $idSoftware = $software->getId(); $selectSoftware = "Select * From software Where id_software = {$idSoftware}"; $result = $this->conexao->query($selectSoftware); foreach ($result as $linha) { $software->setLinguagem($linha['linguagem']); $software->setNome($linha['nome']); } //Buscaremos dados a respeito do banco de dados escolhido. $selectBanco = "SELECT * FROM banco_de_dados WHERE software_id_software"; $result = $this->conexao->query($selectBanco); $banco = new BancoDeDados(); foreach ($result as $linha) { $banco->setSistemaGerenciadorDeBancoDeDados($linha['sistema_gerenciador_de_banco']); $banco->setNomeDoBanco($linha['nome_do_banco']); $banco->setHost($linha['host']); $banco->setPass($linha['pass']); $banco->setUsuario($linha['usuario']); } if ($banco) { $software->setBancoDeDados($banco); } //Pegaremos agora a lista de Objetos //Aqui também podemos buscar os atributos, mas implementarei isso daqui a pouco $selectObjetos = "SELECT * FROM objeto WHERE software_id_software = {$idSoftware}"; $result = $this->conexao->query($selectObjetos); foreach ($result as $linha) { $objeto = new Objeto(); $objeto->setNome($linha['nome']); $objeto->setPersistencia($linha['persistencia']); $objeto->setId($linha['id_objeto']); $idObjeto = $linha['id_objeto']; $selectAtributo = "SELECT * FROM atributo WHERE objeto_id_objeto = {$idObjeto}"; $resultAtributo = $this->conexao->query($selectAtributo); foreach ($resultAtributo as $linhaatributo) { $atributo = new Atributo(); $atributo->setId($linhaatributo['id_atributo']); $atributo->setNome($linhaatributo['nome']); $atributo->setTipo($linhaatributo['tipo']); $atributo->setIndice($linhaatributo['indice']); $atributo->setTipoDeRelacionamentoComObjeto($linhaatributo['relacionamento_com_objeto']); $objeto->addAtributo($atributo); } $software->addObjetoNaLista($objeto); } return $software; } else { return null; } }
/** Generate bigdump : generate items for an entity * * @param $ID_entity entity ID **/ function generate_entity($ID_entity) { global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK, $DOCUMENTS, $NET_PORT, $NET_LOC; regenerateTreeCompleteName("glpi_entities"); $current_year = date("Y"); // DOMAIN $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine"); $dp = new Domain(); $FIRST["domain"] = getMaxItem("glpi_domains")+1; for ($i=0 ; $i<$MAX['domain'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "domain $ID_entity '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); } $LAST["domain"] = getMaxItem("glpi_domains"); // STATUS $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'"); $dp = new State(); $FIRST["state"] = getMaxItem("glpi_states")+1; for ($i=0 ; $i<$MAX['state'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "State $ID_entity '$i"; } $state_id = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); // generate sub status for ($j=0 ; $j<$MAX['state'] ; $j++) { $val2 = "Sub $val $j"; $dp->add(toolbox::addslashes_deep(array('name' => $val2, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'states_id' => $state_id, 'comment' => "comment $val"))); } } $LAST["state"] = getMaxItem("glpi_states"); // glpi_groups $FIRST["groups"] = getMaxItem("glpi_groups")+1; $group = new Group(); for ($i=0 ; $i<$MAX['groups'] ; $i++) { $gID = $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "group d'$i", 'comment' => "comment group d'$i", 'is_assign' => 0))); // Generate sub group for ($j=0 ; $j<$MAX['groups'] ; $j++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "subgroup d'$j", 'comment' => "comment subgroup d'$j of group $i", 'groups_id' => $gID, 'is_assign' => 0))); } } $LAST["groups"] = getMaxItem("glpi_groups"); $FIRST["techgroups"] = $LAST["groups"]+1; for ($i=0 ; $i<$MAX['groups'] ; $i++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "tech group d'$i", 'comment' => "comment tech group d'$i"))); } $LAST["techgroups"] = getMaxItem("glpi_groups"); regenerateTreeCompleteName("glpi_groups"); // glpi_users $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1; $user = new User(); $gu = new Group_User(); for ($i=0 ; $i<$MAX['users_sadmin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "sadmin$i-$ID_entity", 'password' => "sadmin'$i", 'password2' => "sadmin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "sadmin '$i name", 'firstname' => "sadmin '$i firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 4, '_entities_id' => $ID_entity, '_is_recursive' => 1 ))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_sadmin"] = getMaxItem("glpi_users"); $FIRST["users_admin"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_admin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "admin$i-$ID_entity", 'password' => "admin'$i", 'password2' => "admin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "admin$i 'name", 'firstname' => "admin$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 3, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']), 'is_manager' => 1, 'is_delegate' => 1)); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'is_manager' => 1, 'is_delegate' => 1)); } $LAST["users_admin"] = getMaxItem("glpi_users"); $FIRST["users_normal"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_normal'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "normal$i-$ID_entity", 'password' => "normal'$i", 'password2' => "normal'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "normal$i 'name", 'firstname' => "normal$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 2, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_normal"] = getMaxItem("glpi_users"); $FIRST["users_postonly"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_postonly'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "postonly$i-$ID_entity", 'password' => "postonly'$i", 'password2' => "postonly'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "postonly$i 'name", 'firstname' => "postonly$i 'firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 1, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); } $LAST["users_postonly"] = getMaxItem("glpi_users"); $FIRST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories")+1; $kbc = new KnowbaseItemCategory(); for ($i=0 ; $i<max(1,pow($MAX['kbcategories'],1/3)) ; $i++) { $newID = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ' categorie $i", 'comment' => "comment ' categorie $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $j++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity s-categorie '$j", 'comment' => "comment s-categorie '$j", 'knowbaseitemcategories_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $k++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ss-categorie' $k", 'comment' => "comment ss-categorie' $k", 'knowbaseitemcategories_id' => $newID2))); } } } $query = "OPTIMIZE TABLE `glpi_knowbaseitemcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_knowbaseitemcategories"); $LAST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories"); // LOCATIONS $added = 0; $FIRST["locations"] = getMaxItem("glpi_locations")+1; $loc = new Location(); for ($i=0 ; $i<pow($MAX['locations'],1/5)&&$added<$MAX['locations'] ; $i++) { $added++; $newID = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "location' $i", 'comment' => "comment 'location $i", 'building' => "building $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $added++; $newID2 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "s-location '$j", 'comment' => "comment s-location '$j", 'building' => "building $i", 'room' => "stage '$j", 'locations_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $k++) { $added++; $newID3 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ss-location '$k", 'comment' => "comment ss-location' $k", 'building' => "building $i", 'room' => "part' $k", 'locations_id' => $newID2))); for ($l=0 ; $l<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $l++) { $added++; $newID4 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "sss-location' $l", 'comment' => "comment sss-location' $l", 'building' => "building $i", 'room' => "room' $l", 'locations_id' => $newID3))); for ($m=0 ; $m<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $m++) { $added++; $newID5 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ssss-location' $m", 'comment' => "comment ssss-location' $m", 'building' => "building $i", 'room' => "room' $l-$m", 'locations_id' => $newID4))); } } } } } $query = "OPTIMIZE TABLE `glpi_locations`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_locations"); $LAST["locations"]=getMaxItem("glpi_locations"); // Task categories $added = 0; $FIRST["taskcategory"] = getMaxItem("glpi_taskcategories")+1; $tc = new TaskCategory(); for ($i=0 ; $i<pow($MAX['taskcategory'],1/5)&&$added<$MAX['taskcategory'] ; $i++) { $added++; $newID = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $newID2 = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i", 'taskcategories_id' => $newID))); $added++; } } $query = "OPTIMIZE TABLE `glpi_taskcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_taskcategories"); $LAST["taskcategory"] = getMaxItem("glpi_taskcategories"); $ic = new ItilCategory(); // Specific ticket categories $newID = $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "category for entity' $ID_entity", 'comment' => "comment category for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'],$LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'],$LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1))); for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) { $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "scategory for entity' $ID_entity", 'comment' => "comment scategory for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID))); } regenerateTreeCompleteName("glpi_itilcategories"); $FIRST["solutiontypes"] = getMaxItem("glpi_solutiontypes")+1; $items = array("d'après KB"); $st = new SolutionType(); for ($i=0 ; $i<$MAX['solutiontypes'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de solution ' $i"; } $st->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val", 'entities_id' => $ID_entity, 'is_recursive' => 1))); } $LAST["solutiontypes"] = getMaxItem("glpi_solutiontypes"); $FIRST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates")+1; $nb_items = mt_rand(0,$MAX['solutiontemplates']); $st = new SolutionTemplate(); for ($i=0 ; $i<$nb_items ; $i++) { $st-> add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "solution' $i-$ID_entity", 'content' => "content solution' $i-$ID_entity", 'solutiontypes_id' => mt_rand(0,$MAX['solutiontypes']), 'comment' => "comment solution' $i-$ID_entity"))); } $LAST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates"); // Add Specific questions $k = 0; $FIRST["kbitems"] = getMaxItem("glpi_knowbaseitems")+1; $ki = new KnowbaseItem(); $eki = new Entity_KnowbaseItem(); for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 0)); } } // Add global questions for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Recursive Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 1)); } } $LAST["kbitems"] = getMaxItem("glpi_knowbaseitems"); // Ajout documents specific $FIRST["document"] = getMaxItem("glpi_documents")+1; $doc = new Document(); for ($i=0 ; $i<$MAX['document'] ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "commen't $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-0"; } // Global ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "comment' $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-1"; } $LAST["document"] = getMaxItem("glpi_documents"); // Ajout budgets specific $FIRST["budget"] = getMaxItem("glpi_budgets")+1; $b = new Budget(); for ($i=0 ; $i<$MAX['budget'] ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 0, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["budget"] = getMaxItem("glpi_budgets"); // GLobal ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "Recursive budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 1, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["document"] = getMaxItem("glpi_documents"); // glpi_suppliers $items = array("DELL", "IBM", "ACER", "Microsoft", "Epson", "Xerox", "Hewlett Packard", "Nikon", "Targus", "LG", "Samsung", "Lexmark"); $FIRST["enterprises"] = getMaxItem("glpi_suppliers")+1; $ent = new Supplier(); // Global ones for ($i=0 ; $i<$MAX['enterprises']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive' $val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes enterprises' $i"))); addDocuments('Supplier', $entID); } // Specific ones for ($i=0 ; $i<$MAX['enterprises'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "'$val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes supplier' $i", 'comment' => "comment supplier' $i"))); addDocuments('Supplier', $entID); } $LAST["enterprises"] = getMaxItem("glpi_suppliers"); // Ajout contracts $FIRST["contract"] = getMaxItem("glpi_contracts")+1; $c = new Contract(); $cs = new Contract_Supplier(); $cc = new ContractCost(); // Specific for ($i=0 ; $i<$MAX['contract'] ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "contract' $i-$ID_entity", 'num' => "num' $i", 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); // Add a cost $cc->add(toolbox::addslashes_deep( array('contracts_id' => $contractID, 'cost' => mt_rand(100,10000), 'name' => "Initial 'cost", 'begin_date' => $date, 'budgets_id' => mt_rand($FIRST['budget'], $LAST['budget'])))); } for ($i=0 ; $i<$MAX['contract']/2 ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive contract' $i-$ID_entity", 'num' => "num' $i", 'cost' => mt_rand(100,10000), 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); } $LAST["contract"] = getMaxItem("glpi_contracts"); // Ajout contacts $prenoms = array("Jean", "John", "Louis", "Pierre", "Auguste", "Albert", "Julien", "Guillaume", "Bruno", "Maurice", "Francois", "Laurent", "Richard", "Henri", "Clement", "d'avy"); $noms = array("Dupont", "Smith", "Durand", "Martin", "Dubois", "Dufour", "Dupin", "Duval", "Petit", "Grange", "Bernard", "Bonnet", "Richard", "Leroy", "Dumont", "Fontaine", "d'orleans"); $FIRST["contacts"] = getMaxItem("glpi_contacts")+1; $c = new Contact(); $cs = new Contact_Supplier(); for ($i=0 ; $i<$MAX['contacts'] ; $i++) { if (isset($noms[$i])) { $val = $noms[$i]; } else { $val = "name $i"; } if (isset($prenoms[$i])) { $val2 = $prenoms[$i]; } else { $val2 = "firstname $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val-$ID_entity", 'firstname' => $val2, 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } for ($i=0 ; $i<$MAX['contacts']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive contact $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val'-$ID_entity", 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } $LAST["contacts"] = getMaxItem("glpi_contacts"); // TYPE DE CONSOMMABLES $FIRST["type_of_consumables"] = getMaxItem("glpi_consumableitems")+1; $ci = new Consumableitem(); for ($i=0 ; $i<$MAX['type_of_consumables'] ; $i++) { $consID = $ci->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "consumable type' $i", 'ref' => "ref d' $i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'consumableitemtypes_id' => mt_rand(0,$MAX['consumable_type']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment' $i", 'notepad' => "notes consumableitem' $i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('ConsumableItem', $consID); // AJOUT INFOCOMS addInfocoms('ConsumableItem', $consID, $ID_entity); // Ajout consommable en stock $c = new Consumable(); for ($j=0 ; $j<mt_rand(0,$MAX['consumables_stock']) ; $j++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } // Ajout consommable donne for ($j=0 ; $j<mt_rand(0,$MAX['consumables_given']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date, 'date_out' => date("Y-m-d"))); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } } $LAST["type_of_consumables"] = getMaxItem("glpi_consumableitems"); // TYPE DE CARTOUCHES $FIRST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems")+1; $ct = new CartridgeItem(); for ($i=0 ; $i<$MAX['type_of_cartridges'] ; $i++) { $cartID = $ct->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "cartridge ' type $i", 'ref' => "ref '$i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment '$i", 'notepad' => "notes cartridgeitem '$i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('CartridgeItem', $cartID); // AJOUT INFOCOMS addInfocoms('CartridgeItem', $cartID, $ID_entity); $c = new Cartridge(); $cipm = new CartridgeItem_PrinterModel(); // Ajout cartouche en stock for ($j=0 ; $j<mt_rand(0,$MAX['cartridges_stock']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $cartID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Cartridge', $ID, $ID_entity); } // Assoc printer type to cartridge type $cipm->add(array('cartridgeitems_id' => $cartID, 'printermodels_id' => mt_rand(1,$MAX['type_printers']), )); } $LAST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems"); // Networking $NET_LOC = array(); $FIRST["networking"] = getMaxItem("glpi_networkequipments")+1; $FIRST["printers"] = getMaxItem("glpi_printers")+1; $ne = new NetworkEquipment(); $p = new Printer(); $np = new Netpoint(); $c = new Cartridge(); foreach ($DB->request('glpi_locations') as $data) { $i = $data["id"]; $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $infoIP = getNextIP(); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); // insert networking $netwID = $ne->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "networking '$i-$ID_entity", 'ram' => mt_rand(32,256), 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num '$i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment '$i", 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'networkequipmenttypes_id' => mt_rand(1,$MAX['type_networking']), 'networkequipmentmodels_id' => mt_rand(1,$MAX['model_networking']), 'networkequipmentfirmwares_id' => mt_rand(1,$MAX['firmware']), 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'mac' => getNextMAC(), 'ip' => $infoIP["ip"], 'notepad' => "notes networking '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); $NET_LOC[$data['id']] = $netwID; addDocuments('NetworkEquipment', $netwID); addContracts('NetworkEquipment', $netwID); // AJOUT INFOCOMS addInfocoms('NetworkEquipment', $netwID, $ID_entity); // Link with father addNetworkEthernetPort('NetworkEquipment', $netwID, $ID_entity, $i); // Ajout imprimantes reseaux : 1 par loc + connexion d un matos reseau + ajout de cartouches // Add trackings addTracking('NetworkEquipment', $netwID, $ID_entity); $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $recur = mt_rand(0,1); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recur, 'name' => "printer of loc '$i", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'is_global' => 1, 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity, $recur); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result2 = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result2)>0) { $ctypeID = $DB->result($result2,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = abs(round(($date2-$date1)/$oldnb)); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => $date, 'date_use' => date("Y-m-d",$date2))); } $iface = mt_rand(1,$MAX['iface']); // Add networking ports addNetworkEthernetPort('Printer', $printID, $ID_entity, $i); } unset($NET_LOC); $LAST["networking"] = getMaxItem("glpi_networkequipments"); //////////// INVENTORY // glpi_computers $FIRST["computers"] = getMaxItem("glpi_computers")+1; $FIRST["monitors"] = getMaxItem("glpi_monitors")+1; $FIRST["phones"] = getMaxItem("glpi_phones")+1; $FIRST["peripherals"] = getMaxItem("glpi_peripherals")+1; $c = new Computer(); $mon = new Monitor(); $cdevmb = new Item_DeviceMotherBoard(); $cdevproc = new Item_DeviceProcessor(); $cdevmem = new Item_DeviceMemory(); $cdevhd = new Item_DeviceHardDrive(); $cdevnc = new Item_DeviceNetworkCard(); $cdevdr = new Item_DeviceDrive(); $cdevcon = new Item_DeviceControl(); $cdevgc = new Item_DeviceGraphicCard(); $cdevsc = new Item_DeviceSoundCard(); $cdevpci = new Item_DevicePci(); $cdevcase = new Item_DeviceCase(); $cdevps = new Item_DevicePowerSupply(); $cdisk = new ComputerDisk(); $np = new Netpoint(); $ci = new Computer_Item(); $phone = new Phone(); $print = new Printer(); $periph = new Peripheral(); $cart = new Cartridge(); for ($i=0 ; $i<$MAX['computers'] ; $i++) { $loc = mt_rand($FIRST["locations"],$LAST['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $userID = mt_rand($FIRST['users_normal'],$LAST['users_postonly']); $groupID = mt_rand($FIRST["groups"],$LAST["groups"]); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); $compID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "computer ' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'operatingsystems_id' => mt_rand(1,$MAX['os']), 'operatingsystemversions_id' => mt_rand(1,$MAX['os_version']), 'operatingsystemservicepacks_id' => mt_rand(1,$MAX['os_sp']), 'os_license_number' => "os sn $i", 'os_licenseid' => "os id $i", 'autoupdatesystems_id' => mt_rand(1,$MAX['os_sp']), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'computertypes_id' => mt_rand(1,$MAX['type_computers']), 'computermodels_id' => mt_rand(1,$MAX['model']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes computer '$i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'uuid' => Toolbox::getRandomString(30) ))); addDocuments('Computer', $compID); addContracts('Computer', $compID); $NET_PORT['Computer'][$compID] = 0; // Add trackings addTracking('Computer', $compID, $ID_entity); // Add reservation addReservation('Computer', $compID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Computer', $compID, $ID_entity); // ADD DEVICE $cdevmb->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevproc->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevmem->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevhd->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $cdevnc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15), 'mac' => getNextMAC())); $cdevdr->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevcon->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevgc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevsc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); for($nb = 0; $nb<$max; $nb++) { $cdevpci->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); } $cdevcase->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial'=> Toolbox::getRandomString(15))); $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevps->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } // insert disk $nb_disk = mt_rand(1,$MAX_DISK); for ($j=1 ; $j<=$nb_disk ; $j++) { $totalsize = mt_rand(10000,1000000); $freesize = mt_rand(0,$totalsize); $cdisk->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'computers_id' => $compID, 'name' => "disk '$j", 'device' => "/dev/disk$j", 'mountpoint' => "/mnt/disk$j", 'filesystems_id' => mt_rand(1,10), 'totalsize' => $totalsize, 'freesize' => $freesize))); } // Add networking ports addNetworkEthernetPort('Computer', $compID, $ID_entity, $loc); // Ajout d'un ecran sur l'ordi $monID = $mon->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "monitor' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'size' => mt_rand(14,22), 'have_micro' => mt_rand(0,1), 'have_speaker' => mt_rand(0,1), 'have_subd' => mt_rand(0,1), 'have_bnc' => mt_rand(0,1), 'have_dvi' => mt_rand(0,1), 'have_pivot' => mt_rand(0,1), 'have_hdmi' => mt_rand(0,1), 'have_displayport' => mt_rand(0,1), 'locations_id' => $loc, 'monitortypes_id' => mt_rand(1,$MAX['type_monitors']), 'monitormodels_id' => mt_rand(1,$MAX['model_monitors']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes monitor' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Monitor', $monID); addContracts('Monitor', $monID); // Add trackings addTracking('Monitor', $monID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Monitor', $monID, $ID_entity); $ci->add(array('itemtype' => 'Monitor', 'items_id' => $monID, 'computers_id' => $compID, )); // Ajout d'un telephhone avec l'ordi $telID = $phone->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "phone' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'firmware' => Toolbox::getRandomString(10), 'brand' => "brand' $i", 'phonepowersupplies_id' => mt_rand(0,$MAX['phone_power']), 'number_line' => Toolbox::getRandomString(10), 'have_headset' => mt_rand(0,1), 'have_hp' => mt_rand(0,1), 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_phones']), 'phonemodels_id' => mt_rand(1,$MAX['model_phones']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes phone' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Phone', $telID); addContracts('Phone', $telID); // Add trackings addTracking('Phone', $telID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Phone', $telID, $ID_entity); $ci->add(array('itemtype' => 'Phone', 'items_id' => $telID, 'computers_id' => $compID)); // Ajout des periphs externes en connection directe while (mt_rand(0,100)<$percent['peripherals']) { $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes peripheral' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => $compID)); } // Ajout d'une imprimante connection directe pour X% des computers + ajout de cartouches if (mt_rand(0,100)<=$percent['printer']) { // Add printer $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "printer of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_postonly'], $LAST['users_postonly']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Printer', 'items_id' => $printID, 'computers_id' => $compID)); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result)>0) { $ctypeID = $DB->result($result,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = round(($date2-$date1)/$oldnb); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date2))); } } } $LAST["computers"] = getMaxItem("glpi_computers"); $LAST["monitors"] = getMaxItem("glpi_monitors"); $LAST["phones"] = getMaxItem("glpi_phones"); // Add global peripherals $periph = new Peripheral(); $ci = new Computer_Item(); for ($i=0 ; $i<$MAX['global_peripherals'] ; $i++) { $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph '$i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes peripheral' $i", 'users_id' => mt_rand($FIRST['users_normal'], $LAST['users_normal']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add reservation addReservation('Peripheral', $periphID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Peripheral', $periphID, $ID_entity); // Add connections $val = mt_rand(1,$MAX['connect_for_peripherals']); for ($j=1 ; $j<$val ; $j++) { $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => mt_rand($FIRST["computers"],$LAST['computers']))); } } $LAST["peripherals"] = getMaxItem("glpi_peripherals"); $FIRST["software"] = getMaxItem("glpi_softwares")+1; // Ajout logiciels + licences associees a divers PCs $items = array(array("Open'Office", "1.1.4", "2.0", "2.0.1"), array("Microsoft Office", "95", "97", "XP", "2000", "2003", "2007"), array("Acrobat Reader", "6.0", "7.0", "7.04"), array("Gimp", "2.0", "2.2"), array("InkScape", "0.4")); $soft = new Software(); $softvers = new SoftwareVersion(); $softlic = new SoftwareLicense(); $csv = new Computer_SoftwareVersion(); $csl = new Computer_SoftwareLicense(); for ($i=0 ; $i<$MAX['software'] ; $i++) { if (isset($items[$i])) { $name = $items[$i][0]; } else { $name = "software '$i"; } $loc = mt_rand(1,$MAX['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $recursive = mt_rand(0,1); $softID = $soft->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'name' => $name, 'comment' => "comment '$i", 'locations_id' => $loc, 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes software '$i", 'users_id' => mt_rand($FIRST['users_admin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'is_helpdesk_visible' => 1, 'softwarecategories_id' => mt_rand(1,$MAX['softwarecategory']) ))); addDocuments('Software', $softID); addContracts('Software', $softID); // Add trackings addTracking('Software', $softID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Software', $softID, $ID_entity); // Add versions $FIRST["version"] = getMaxItem("glpi_softwareversions")+1; if (isset($items[$i])) { $val2 = count($items[$i]); } else { $val2 = mt_rand(1,$MAX['softwareversions']+1); } for ($j=1 ; $j<=$val2 ; $j++) { if (isset($items[$i])) { $version = $items[$i][mt_rand(1,count($items[$i])-1)]; } else { $version = "$j.0"; } $os = mt_rand(1,$MAX['os']); $versID = $softvers->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'name' => $version, 'comment' => "comment '$version", 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'operatingsystems_id' => $os))); $val3 = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$val3 ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csv->add(array('computers_id' => $comp_id, 'softwareversions_id' => $versID)); } } $LAST["version"] = getMaxItem("glpi_softwareversions"); // Add licenses $val2 = mt_rand(1,$MAX['softwarelicenses']); for ($j=0 ; $j<$val2 ; $j++) { $softwareversions_id_buy = mt_rand($FIRST["version"],$LAST["version"]); $softwareversions_id_use = mt_rand($softwareversions_id_buy,$LAST["version"]); $nbused = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $licID = $softlic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'number' => $nbused, 'softwarelicensetypes_id' => mt_rand(1,$MAX['licensetype']), 'name' => "license '$j", 'serial' => "serial $j", 'otherserial' => "otherserial $j", 'comment' => "comment license '$j", 'softwareversions_id_buy' => $softwareversions_id_buy, 'softwareversions_id_use' => $softwareversions_id_use))); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$nbused ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csl->add(array('computers_id' => $comp_id, 'softwarelicenses_id' => $licID)); } } } $LAST["software"] = getMaxItem("glpi_softwares"); }
/** * Display form to unlock fields and links * * @param CommonDBTM $item the source item **/ static function showForItem(CommonDBTM $item) { global $DB; $ID = $item->getID(); $itemtype = $item->getType(); $header = false; //If user doesn't have write right on the item, lock form must not be displayed if (!$item->canCreate()) { return false; } echo "<div width='50%'>"; echo "<form method='post' id='lock_form'\n name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>"; echo "<input type='hidden' name='id' value='{$ID}'>\n"; echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>"; //Use a hook to allow external inventory tools to manage per field lock $results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header)); $header |= $results['header']; //Special locks for computers only if ($itemtype == 'Computer') { //Locks for items recorded in glpi_computers_items table $types = array('Monitor', 'Peripheral', 'Printer'); foreach ($types as $type) { $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type); $params['FIELDS'] = array('id', 'items_id'); $first = true; foreach ($DB->request('glpi_computers_items', $params) as $line) { $tmp = new $type(); $tmp->getFromDB($line['items_id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>"; echo "</tr>\n"; } } $types = array('ComputerDisk', 'ComputerVirtualMachine'); foreach ($types as $type) { $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $params['FIELDS'] = array('id', 'name'); $first = true; foreach ($DB->request(getTableForItemType($type), $params) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['name'] . "</td>"; echo "</tr>\n"; } } //Software versions $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $first = true; $query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwareversions` AS csv\n LEFT JOIN `glpi_softwareversions` AS sv\n ON (`csv`.`softwareversions_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'"; foreach ($DB->request($query) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>"; echo "</tr>\n"; } //Software licenses $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID); $first = true; $query = "SELECT `csv`.`id` AS `id`,\n `sv`.`name` AS `version`,\n `s`.`name` AS `software`\n FROM `glpi_computers_softwarelicenses` AS csv\n LEFT JOIN `glpi_softwarelicenses` AS sv\n ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n LEFT JOIN `glpi_softwares` AS s\n ON (`sv`.`softwares_id` = `s`.`id`)\n WHERE `csv`.`is_deleted` = '1'\n AND `csv`.`is_dynamic` = '1'\n AND `csv`.`computers_id` = '{$ID}'"; foreach ($DB->request($query) as $line) { $header = true; if ($first) { echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>"; echo "</tr>\n"; } } $first = true; $item = new NetworkPort(); $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype); $params['FIELDS'] = array('id'); foreach ($DB->request('glpi_networkports', $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . NetworkPort::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='NetworkPort[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $first = true; $item = new NetworkName(); $params = array('`glpi_networknames`.`is_dynamic`' => 1, '`glpi_networknames`.`is_deleted`' => 1, '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype); $params['FIELDS'] = array('glpi_networknames' => 'id'); foreach ($DB->request(array('glpi_networknames', 'glpi_networkports'), $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . NetworkName::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='NetworkName[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $first = true; $item = new IPAddress(); $params = array('`glpi_ipaddresses`.`is_dynamic`' => 1, '`glpi_ipaddresses`.`is_deleted`' => 1, '`glpi_ipaddresses`.`itemtype`' => 'Networkname', '`glpi_ipaddresses`.`items_id`' => '`glpi_networknames`.`id`', '`glpi_networknames`.`itemtype`' => 'NetworkPort', '`glpi_networknames`.`items_id`' => '`glpi_networkports`.`id`', '`glpi_networkports`.`items_id`' => $ID, '`glpi_networkports`.`itemtype`' => $itemtype); $params['FIELDS'] = array('glpi_ipaddresses' => 'id'); foreach ($DB->request(array('glpi_ipaddresses', 'glpi_networknames', 'glpi_networkports'), $params) as $line) { $item->getFromDB($line['id']); $header = true; if ($first) { echo "<tr><th colspan='2'>" . IPAddress::getTypeName(2) . "</th></tr>\n"; $first = false; } echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='IPAddress[" . $line['id'] . "]'></td>"; echo "<td class='left' width='95%'>" . $item->getName() . "</td>"; echo "</tr>\n"; } $types = Item_Devices::getDeviceTypes(); $nb = 0; foreach ($types as $old => $type) { $nb += countElementsInTable(getTableForItemType($type), "`items_id`='{$ID}'\n AND `itemtype`='{$itemtype}'\n AND `is_dynamic`='1'\n AND `is_deleted`='1'"); } if ($nb) { $header = true; echo "<tr><th colspan='2'>" . _n('Component', 'Components', 2) . "</th></tr>\n"; foreach ($types as $old => $type) { $associated_type = str_replace('Item_', '', $type); $associated_table = getTableForItemType($associated_type); $fk = getForeignKeyFieldForTable($associated_table); $query = "SELECT `i`.`id`,\n `t`.`designation` AS `name`\n FROM `" . getTableForItemType($type) . "` AS i\n LEFT JOIN `{$associated_table}` AS t\n ON (`t`.`id` = `i`.`{$fk}`)\n WHERE `itemtype` = '{$itemtype}'\n AND `items_id` = '{$ID}'\n AND `is_dynamic` = '1'\n AND `is_deleted` = '1'"; foreach ($DB->request($query) as $data) { echo "<tr class='tab_bg_1'><td class='center' width='10'>"; echo "<input type='checkbox' name='" . $type . "[" . $data['id'] . "]'></td>"; echo "<td class='left' width='95%'>"; printf(__('%1$s: %2$s'), $associated_type::getTypeName(), $data['name']); echo "</td></tr>\n"; } } } if ($header) { echo "</table>"; Html::openArrowMassives('lock_form', true); Html::closeArrowMassives(array('unlock' => _sx('button', 'Unlock'))); } else { echo "<tr class='tab_bg_2'>"; echo "<td class='center' colspan='2'>" . __('No locked item') . "</td></tr>"; echo "</table>"; } Html::closeForm(); echo "</div>\n"; }
function cleanSoftwares() { if (!isset($this->already_transfer['Software'])) { return; } $soft = new Software(); foreach ($this->already_transfer['Software'] as $old => $new) { if (countElementsInTable("glpi_softwarelicenses", "softwares_id={$old}") == 0 && countElementsInTable("glpi_softwareversions", "softwares_id={$old}") == 0) { if ($this->options['clean_software'] == 1) { // delete $soft->delete(array('id' => $old), 0); } else { if ($this->options['clean_software'] == 2) { // purge $soft->delete(array('id' => $old), 1); } } } } }
/** * Print the Software / version form * * @param $ID Integer : Id of the version or the template to print * @param $options array * - target form target * - softwares_id ID of the software for add process * * @return true if displayed false if item not found or not right to display * **/ function showForm($ID, $options = array()) { global $CFG_GLPI, $LANG; $softwares_id = -1; if (isset($options['softwares_id'])) { $softwares_id = $options['softwares_id']; } if (!haveRight("software", "r")) { return false; } if ($ID > 0) { $this->check($ID, 'r'); } else { $soft = new Software(); $soft->getFromDB($softwares_id); // Create item $input = array('entities_id' => $soft->getEntityID(), 'is_recursive' => $soft->isRecursive()); $this->check(-1, 'w', $input); } $this->showTabs($options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'><td>" . $LANG['help'][31] . " :</td>"; echo "<td>"; if ($ID > 0) { $softwares_id = $this->fields["softwares_id"]; } else { echo "<input type='hidden' name='softwares_id' value='{$softwares_id}'>"; } echo "<a href='software.form.php?id=" . $softwares_id . "'>" . Dropdown::getDropdownName("glpi_softwares", $softwares_id) . "</a>"; echo "</td>"; echo "<td rowspan='4' class='middle'>" . $LANG['common'][25] . " :</td>"; echo "<td class='center middle' rowspan='4'>"; echo "<textarea cols='45' rows='3' name='comment' >" . $this->fields["comment"]; echo "</textarea></td></tr>\n"; echo "<tr class='tab_bg_1'><td>" . $LANG['common'][16] . " :</td>"; echo "<td>"; autocompletionTextField($this, "name"); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'><td>" . $LANG['setup'][5] . " :</td><td>"; Dropdown::show('OperatingSystem', array('value' => $this->fields["operatingsystems_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'><td>" . $LANG['state'][0] . " :</td><td>"; Dropdown::show('State', array('value' => $this->fields["states_id"])); echo "</td></tr>\n"; // Only count softwareversions_id_buy (don't care of softwareversions_id_use if no installation) if (SoftwareLicense::countForVersion($ID) > 0 || Computer_SoftwareVersion::countForVersion($ID) > 0) { $options['candel'] = false; } $this->showFormButtons($options); $this->addDivForTabs(); return true; }
function get_version_list($conn, $data) { $response = array(); $model = $data['model']; ossim_valid($model, OSS_NULLABLE, OSS_ALPHA, OSS_PUNC_EXT, 'illegal:' . _("Model")); check_ossim_error(); if (empty($model)) { $items = array(); } else { $model = escape_sql($model, $conn); $items = Software::get_versions_by_cpe($conn, $model, TRUE); } $response['error'] = FALSE; $response['data']['items'] = $items; return $response; }
/** * @test */ public function AddComputerStep3() { global $DB; $this->mark_incomplete(); return; // TODO: recode this test $DB->connect(); $DB->query("UPDATE `glpi_entities`\n SET `entities_id_software` = '-2'\n WHERE `id`='1'"); $_SESSION['glpiactive_entity'] = 0; $_SESSION['glpiactiveentities_string'] = 0; $_SESSION['glpishowallentities'] = 1; $_SESSION['glpiname'] = 'glpi'; $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory(); $computer = new Computer(); $software = new Software(); $input = array('id' => 1, 'is_recursive' => 0); $software->update($input); $computer->add(array('name' => 'pc2', 'entities_id' => 1)); $a_inventory = array(); $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc2'); $a_inventory['CONTENT']['SOFTWARES'][] = array('COMMENTS' => "Non-interactive tool to get files from FTP, GOPHER, HTTP(S)", 'NAME' => "curl", 'VERSION' => "7.24.0_1"); // ** Add agent $pfAgent = new PluginFusioninventoryAgent(); $a_agents_id = $pfAgent->add(array('name' => 'pc-2013-02-13', 'device_id' => 'pc-2013-02-13')); $_SESSION['plugin_fusioninventory_agents_id'] = $a_agents_id; // ** Add $pfiComputerInv->import("pc2-2013-02-13", "", $a_inventory); // creation $computer->getFromDB(2); $this->assertEquals(1, $computer->fields['entities_id'], 'Add computer'); $nbSoftwares = countElementsInTable("glpi_softwares"); $softs = getAllDatasFromTable("glpi_softwares"); $this->assertEquals(2, $nbSoftwares, 'Nb softwares ' . print_r($softs, true)); $software->getFromDB(2); $this->assertEquals(1, $software->fields['entities_id'], "May be on entity 1"); // Software not in same entity as computer, may be recursive $this->assertEquals(0, $software->fields['is_recursive'], 'Software may have recursive = 0'); }
// ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["sort"])) { $_GET["sort"] = ""; } if (!isset($_GET["order"])) { $_GET["order"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $soft = new Software(); if (isset($_POST["add"])) { $soft->check(-1, 'w', $_POST); $newID = $soft->add($_POST); Event::log($newID, "software", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][20] . " " . $_POST["name"] . "."); glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["delete"])) { $soft->check($_POST["id"], 'd'); $soft->delete($_POST); Event::log($_POST["id"], "software", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][22]); $soft->redirectToList(); } else { if (isset($_POST["restore"])) { $soft->check($_POST["id"], 'd'); $soft->restore($_POST);
/** * Make a select box for Ticket my devices * * * @param $userID User ID for my device section * @param $entity_restrict restrict to a specific entity * @param $itemtype of selected item * @param $items_id of selected item * * @return nothing (print out an HTML select box) **/ static function dropdownMyDevices($userID = 0, $entity_restrict = -1, $itemtype = 0, $items_id = 0) { global $DB, $LANG, $CFG_GLPI; if ($userID == 0) { $userID = getLoginUserID(); } $rand = mt_rand(); $already_add = array(); if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, HELPDESK_MY_HARDWARE)) { $my_devices = ""; $my_item = $itemtype . '_' . $items_id; // My items foreach ($CFG_GLPI["linkuser_types"] as $itemtype) { if (class_exists($itemtype) && self::isPossibleToAssignType($itemtype)) { $itemtable = getTableForItemType($itemtype); $item = new $itemtype(); $query = "SELECT *\n FROM `{$itemtable}`\n WHERE `users_id` = '{$userID}'"; if ($item->maybeDeleted()) { $query .= " AND `is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `is_template` = '0' "; } if (in_array($itemtype, $CFG_GLPI["helpdesk_visible_types"])) { $query .= " AND `is_helpdesk_visible` = '1' "; } $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive()); "\n ORDER BY `name` "; $result = $DB->query($query); $nb = $DB->numrows($result); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName($nb); while ($data = $DB->fetch_array($result)) { $output = $data["name"]; if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output .= " (" . $data['id'] . ")"; } $output = $type_name . " - " . $output; if ($itemtype != 'Software') { if (!empty($data['serial'])) { $output .= " - " . $data['serial']; } if (!empty($data['otherserial'])) { $output .= " - " . $data['otherserial']; } } $my_devices .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } if (!empty($my_devices)) { $my_devices = "<optgroup label=\"" . $LANG['tracking'][1] . "\">" . $my_devices . "</optgroup>"; } // My group items if (haveRight("show_group_hardware", "1")) { $group_where = ""; $query = "SELECT `glpi_groups_users`.`groups_id`, `glpi_groups`.`name`\n FROM `glpi_groups_users`\n LEFT JOIN `glpi_groups`\n ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`)\n WHERE `glpi_groups_users`.`users_id` = '{$userID}' " . getEntitiesRestrictRequest("AND", "glpi_groups", "", $entity_restrict, true); $result = $DB->query($query); $first = true; if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_array($result)) { if ($first) { $first = false; } else { $group_where .= " OR "; } $group_where .= " `groups_id` = '" . $data["groups_id"] . "' "; } $tmp_device = ""; foreach ($CFG_GLPI["linkgroup_types"] as $itemtype) { if (class_exists($itemtype) && self::isPossibleToAssignType($itemtype)) { $itemtable = getTableForItemType($itemtype); $item = new $itemtype(); $query = "SELECT *\n FROM `{$itemtable}`\n WHERE ({$group_where}) " . getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive()); if ($item->maybeDeleted()) { $query .= " AND `is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `is_template` = '0' "; } $result = $DB->query($query); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName(); if (!isset($already_add[$itemtype])) { $already_add[$itemtype] = array(); } while ($data = $DB->fetch_array($result)) { if (!in_array($data["id"], $already_add[$itemtype])) { $output = ''; if (isset($data["name"])) { $output = $data["name"]; } if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output .= " (" . $data['id'] . ")"; } $output = $type_name . " - " . $output; if (isset($data['serial'])) { $output .= " - " . $data['serial']; } if (isset($data['otherserial'])) { $output .= " - " . $data['otherserial']; } $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . $LANG['tracking'][1] . " - " . $LANG['common'][35] . "\">" . $tmp_device . "</optgroup>"; } } } // Get linked items to computers if (isset($already_add['Computer']) && count($already_add['Computer'])) { $search_computer = " XXXX IN (" . implode(',', $already_add['Computer']) . ') '; $tmp_device = ""; // Direct Connection $types = array('Peripheral', 'Monitor', 'Printer', 'Phone'); foreach ($types as $itemtype) { if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]) && class_exists($itemtype)) { $itemtable = getTableForItemType($itemtype); $item = new $itemtype(); if (!isset($already_add[$itemtype])) { $already_add[$itemtype] = array(); } $query = "SELECT DISTINCT `{$itemtable}`.*\n FROM `glpi_computers_items`\n LEFT JOIN `{$itemtable}`\n ON (`glpi_computers_items`.`items_id` = `{$itemtable}`.`id`)\n WHERE `glpi_computers_items`.`itemtype` = '{$itemtype}'\n AND " . str_replace("XXXX", "`glpi_computers_items`.`computers_id`", $search_computer); if ($item->maybeDeleted()) { $query .= " AND `is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `is_template` = '0' "; } $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict) . "\n ORDER BY `{$itemtable}`.`name`"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName(); while ($data = $DB->fetch_array($result)) { if (!in_array($data["id"], $already_add[$itemtype])) { $output = $data["name"]; if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output .= " (" . $data['id'] . ")"; } $output = $type_name . " - " . $output; if ($itemtype != 'Software') { $output .= " - " . $data['serial'] . " - " . $data['otherserial']; } $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . $LANG['reports'][36] . "\">" . $tmp_device . "</optgroup>"; } // Software if (in_array('Software', $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) { $query = "SELECT DISTINCT `glpi_softwareversions`.`name` AS version,\n `glpi_softwares`.`name` AS name, `glpi_softwares`.`id`\n FROM `glpi_computers_softwareversions`, `glpi_softwares`,\n `glpi_softwareversions`\n WHERE `glpi_computers_softwareversions`.`softwareversions_id` =\n `glpi_softwareversions`.`id`\n AND `glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`\n AND " . str_replace("XXXX", "`glpi_computers_softwareversions`.`computers_id`", $search_computer) . "\n AND `glpi_softwares`.`is_helpdesk_visible` = '1' " . getEntitiesRestrictRequest("AND", "glpi_softwares", "", $entity_restrict) . "\n ORDER BY `glpi_softwares`.`name`"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $tmp_device = ""; $item = new Software(); $type_name = $item->getTypeName(); if (!isset($already_add['Software'])) { $already_add['Software'] = array(); } while ($data = $DB->fetch_array($result)) { if (!in_array($data["id"], $already_add['Software'])) { $output = "{$type_name} - " . $data["name"] . " (v. " . $data["version"] . ")" . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["id"] . ")" : ""); $tmp_device .= "<option title=\"{$output}\" value='Software_" . $data["id"] . "' " . ($my_item == 'Software' . "_" . $data["id"] ? "selected" : "") . ">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add['Software'][] = $data["id"]; } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . ucfirst($LANG['software'][17]) . "\">"; $my_devices .= $tmp_device . "</optgroup>"; } } } } echo "<div id='tracking_my_devices'>"; echo $LANG['tracking'][1] . " : <select id='my_items' name='_my_items'>"; echo "<option value=''>--- "; echo $LANG['help'][30] . " ---</option>{$my_devices}</select></div>"; } }
/** * 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}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&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"; }
private function processImport($file) { if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) { if (!in_array($file->getClientOriginalExtension(), array("xls", "xlsx", "csv"))) { Input::flash(); return Redirect::to('assets/software/import')->with('message', "Invalid file selected."); } else { $filename = "upload-" . str_random(9) . "." . $file->getClientOriginalExtension(); $file->move("uploads", $filename); $readFile = "uploads/" . $filename; $reader = Excel::selectSheetsByIndex(0)->load($readFile, function ($reader) { })->get(); /* * Before validating each rows of the file uploaded, the file itself is checked if it has the valid attributes (columns) * using the algorithm found below. * * 1. File is read. * 2. Boolean variable $excelIsValid to check if the file is valid. Set to false by default. * */ $excelChecker = Excel::selectSheetsByIndex(0)->load($readFile, function ($reader) { })->get()->toArray(); $excelIsValid = false; /* * 3. Loop through the excel file and check if at least once all the columns have been present. * 4. If it does, $excelIsValid is set to true. * 5. If $excelIsValid is still false by end of the loop, it is automatically assumed that the file is: * A.) Empty * B.) Does not have the right attributes. * C.) Has valid columns, but does not have any valid entry. * */ foreach ($excelChecker as $ex) { if (isset($ex["productkey"]) && isset($ex["softwaretype"]) && isset($ex["status"])) { $excelIsValid = true; } } /* 6. If file is invalid, redirect to import form and return an error. */ if (!$excelIsValid) { Input::flash(); File::delete($readFile); return Redirect::to('assets/software/import')->with('message', "Excel file has invalid attributes. Please download the form."); } /* * CHECKING EXCEL FILE FOR ERRORS WHILE READING THE ROWS * * 1. $hasError is a Boolean variable that is simply used to tell if any error has been found. * This variable is, by default, set to false. If any error has been detected, it is set to true, * regardless of how many errors has been detected. * * 2. $rowIndex indexes which row the reader is currently reading. Default value set to 1 because * the first row of excel files is automatically set as the attribute row. When the reader reads each row, * $rowIndex is incremented. For example, reader is currently reading row 2, $rowIndex will then be incremented, * setting its value to 2, thus the row number. * * 3. $rowsWithErrors is the array of the rows with errors. To explain further, let's say excel file has 10 readable (non-attrib) * rows. No errors were found from rows number 2-8, but errors were found in rows 9, 10, and 11. These 9, 10, and 11 * will then be in the $rowsWithError. * * 4. $error array is the variable that will be used to collect all errors found from the excel file. * This is a two-dimensional array. * * */ $hasError = false; //Detects if there are any errors. $hasCorrectRows = false; $rowIndex = 1; //Indexes which row the reader is reading. $rowsWithErrors = array(); //This is used to contain in an array the row numbers of the rows with error. $error = array(); //Error details collector. foreach ($reader as $r) { /* * 5. Here, we immediately increment the value of $rowIndex, since the variable will be used in the core logic of this method. * * 6. $errorCount variable is a variable used in every loop. Set to 0 when the loop begins, so it always comes back to 0 for every loop. * $errorCount is used to track the number of errors for the current row. This variable goes hand in hand with the * $rowsWithError array when publishing the rows with errors, and the error details for each row with error. * * This is how $rowsWithError and $rowCount will be used: * * for each $rowWithErrors: * Row $rowWithErrors Index: * Errors Found : * $rowCount 1. Foo bar * $rowCount 2. Jane Doe etc.. * * */ $rowIndex += 1; $errorCount = 0; //Counts the number of errors for the currect row. $rowHasError = false; //Check if this row has error. I will use this before the reading of the row ends. // If $rowHasError is still false by end of the reading, then I will write it in the database. $warranty_start = !empty(trim($r->warrantystart)) ? trim($r->warrantystart) : "1994-04-16"; $validator = Validator::make(array("software asset tag" => trim($r->assettag), "product key" => trim($r->productkey), "employee number" => trim($r->employeenumber), "laptop serial number" => trim($r->laptopsn), "software type" => trim($r->softwaretype), "warranty start date" => trim($r->warrantystart), "warranty end date" => trim($r->warrantyend), "status" => trim($r->status)), array("software asset tag" => "required|unique:tbl_software_assets,asset_tag|unique:tbl_assets,asset_tag", "product key" => "required", "employee number" => "exists:tbl_employees,employee_number", "laptop serial number" => "exists:tbl_assets,serial_number", "software type" => "required|exists:tbl_software_types,software_type", "warranty start date" => "required_with:warranty end date|date:Y-m-d", "warranty end date" => "date:Y-m-d|after:" . $warranty_start, "status" => "required|in:Available,PWU,Retired,Test Case,Lost"), array("after" => "The :attribute must be after the warranty start date.")); if ($validator->fails()) { /* 7. When error has been found, $rowsWithError is immediately updated. Also, $hasError and $rowHasError are set to true.*/ $hasError = true; $rowHasError = true; $rowsWithErrors[$rowIndex] = $rowIndex; /* 8. Then I will check which fields have errors. * * 9. If an error has been found in a certain field, * I will loop through the errors found on that field, increment the $errorCount (which, again, tracks * how many errors has been found on a certain row.), update the two-dimensional $error array. * Please note that the first array of $error contains the row number which the errors found belong to. * */ if ($validator->messages()->get("software asset tag")) { foreach ($validator->messages()->get("software asset tag") as $e) { $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>"; } } if ($validator->messages()->get("product key")) { foreach ($validator->messages()->get("product key") as $e) { $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>"; } } if ($validator->messages()->get("employee number")) { foreach ($validator->messages()->get("employee number") as $e) { $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>"; } } if ($validator->messages()->get("laptop serial number")) { foreach ($validator->messages()->get("laptop serial number") as $e) { $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>"; } } if ($validator->messages()->get("software type")) { foreach ($validator->messages()->get("software type") as $e) { $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>"; } } if ($validator->messages()->get("warranty start date")) { foreach ($validator->messages()->get("warranty start date") as $e) { $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>"; } } if ($validator->messages()->get("warranty end date")) { foreach ($validator->messages()->get("warranty end date") as $e) { $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>"; } } if ($validator->messages()->get("status")) { foreach ($validator->messages()->get("status") as $e) { $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>"; } } } if ($r->status != "Lost" && Employee::where("employee_number", "=", $r->employeenumber)->whereIn("status", array("OJT Graduate", "Graduate", "Resigned", "Obsolete"))->first()) { $hasError = true; //This will only matter if no errors has been found above. $rowHasError = true; //This will only matter if no errors has been found above. $rowsWithErrors[$rowIndex] = $rowIndex; //This will only matter if no errors has been found above. $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . "Cannot assign an asset to employees no longer working in the company." . "<br/>"; } if (trim($r->laptopsn) != null && !Asset::where("serial_number", "=", $r->laptopsn)->whereHas("classification", function ($q) { $q->where("name", "=", "Laptops"); })->first()) { $hasError = true; //This will only matter if no errors has been found above. $rowHasError = true; //This will only matter if no errors has been found above. $rowsWithErrors[$rowIndex] = $rowIndex; //This will only matter if no errors has been found above. $errorCount += 1; $error[$rowIndex][$errorCount] = $errorCount . ". " . "Cannot assign software asset to non-laptop assets. Please check the serial number and try again." . "<br/>"; } if (!$rowHasError) { $hasCorrectRows = true; $software_type_id = SoftwareType::where("software_type", "=", $r->softwaretype)->get(array("id"))->first(); //Create the asset $software = new Software(); $software->asset_tag = trim($r->assettag) != null ? trim($r->assettag) : null; $software->product_key = trim($r->productkey); $software->employee_number = trim($r->employeenumber) != null ? trim($r->employeenumber) : null; $software->assigned_to_serial_number = trim($r->laptopsn) != null ? trim($r->laptopsn) : null; $software->location = trim($r->location) != null ? trim($r->location) : null; $software->software_type_id = $software_type_id->id; $software->warranty_start = trim($r->warrantystart); $software->warranty_end = trim($r->warrantyend); $software->status = trim($r->status); $software->notes = trim($r->notes) != null ? trim($r->notes) : null; $software->date_added = date("Y-m-d H:i:s"); $software->save(); //Log the new asset to asset logs if (!empty(trim($r->employeenumber))) { $employee = Employee::where("employee_number", "=", trim($r->employeenumber))->first(); $desc = "Software Asset <strong>" . $software->asset_tag . "</strong> added to the database and assigned to employee <strong>" . $employee->first_name . " " . $employee->last_name . "</strong> with asset status <strong>" . $software->status . "</strong>."; } else { $desc = "Software Asset <strong>" . $software->asset_tag . "</strong> added to the database with status <strong>" . $software->status . "</strong>."; } $softwareLog = new SoftwareLog(); $softwareLog->user_id = Session::get("user_id"); $softwareLog->software_id = $software->id; $softwareLog->employee_id = !empty($software->employee->id) ? $software->employee->id : null; $softwareLog->description = $desc; $softwareLog->transaction = "History"; $softwareLog->save(); //Parallel logging to system logs $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> added software asset <strong>" . $software->asset_tag . "</strong>."; $newLog = new UserLog(); $newLog->description = $desc; $newLog->user_id = Session::get('user_id'); $newLog->type = "System"; $newLog->save(); } } File::delete($readFile); if ($hasCorrectRows) { //Log the changes made $desc = "(" . Session::get("user_type") . ") <b>" . Session::get("username") . "</b> has imported data to software assets database. "; $newLog = new UserLog(); $newLog->description = $desc; $newLog->user_id = Session::get('user_id'); $newLog->type = "System"; $newLog->save(); } return $this->importResult($hasError, $hasCorrectRows, $rowsWithErrors, $error); } } else { return Redirect::to('/'); } }
/** * Delete a list of softwares * * @param $soft_ids array containing replay software need to be dustbined **/ function putOldSoftsInTrash(array $soft_ids) { global $DB; if (count($soft_ids) > 0) { $ids = implode("','", $soft_ids); //Try to delete all the software that are not used anymore // (which means that don't have version associated anymore) $res_countsoftinstall = $DB->query("SELECT `glpi_softwares`.`id`,\n COUNT(`glpi_softwareversions`.`softwares_id`) AS `cpt`\n FROM `glpi_softwares`\n LEFT JOIN `glpi_softwareversions`\n ON `glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`\n WHERE `glpi_softwares`.`id` IN ('{$ids}')\n AND `is_deleted` = '0'\n GROUP BY `glpi_softwares`.`id`\n HAVING `cpt` = '0'\n ORDER BY `cpt`"); $software = new Software(); while ($soft = $DB->fetch_assoc($res_countsoftinstall)) { $software->putInTrash($soft["id"], __('Software deleted by GLPI dictionary rules')); } } }
/** * 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>"; }
/** * Make a select box for Ticket my devices * * @param $userID User ID for my device section (default 0) * @param $entity_restrict restrict to a specific entity (default -1) * @param $itemtype of selected item (default 0) * @param $items_id of selected item (default 0) * * @return nothing (print out an HTML select box) **/ static function dropdownMyDevices($userID = 0, $entity_restrict = -1, $itemtype = 0, $items_id = 0) { global $DB, $CFG_GLPI; if ($userID == 0) { $userID = Session::getLoginUserID(); } $rand = mt_rand(); $already_add = array(); if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, self::HELPDESK_MY_HARDWARE)) { $my_devices = ""; $my_item = $itemtype . '_' . $items_id; // My items foreach ($CFG_GLPI["linkuser_types"] as $itemtype) { if (($item = getItemForItemtype($itemtype)) && parent::isPossibleToAssignType($itemtype)) { $itemtable = getTableForItemType($itemtype); $query = "SELECT *\n FROM `{$itemtable}`\n WHERE `users_id` = '{$userID}'"; if ($item->maybeDeleted()) { $query .= " AND `is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `is_template` = '0' "; } if (in_array($itemtype, $CFG_GLPI["helpdesk_visible_types"])) { $query .= " AND `is_helpdesk_visible` = '1' "; } $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive()) . "\n ORDER BY `name` "; $result = $DB->query($query); $nb = $DB->numrows($result); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName($nb); while ($data = $DB->fetch_assoc($result)) { $output = $data["name"]; if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']); } $output = sprintf(__('%1$s - %2$s'), $type_name, $output); if ($itemtype != 'Software') { if (!empty($data['serial'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['serial']); } if (!empty($data['otherserial'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']); } } $my_devices .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } if (!empty($my_devices)) { $my_devices = "<optgroup label=\"" . __s('My devices') . "\">" . $my_devices . "</optgroup>"; } // My group items if (Session::haveRight("show_group_hardware", "1")) { $group_where = ""; $query = "SELECT `glpi_groups_users`.`groups_id`, `glpi_groups`.`name`\n FROM `glpi_groups_users`\n LEFT JOIN `glpi_groups`\n ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`)\n WHERE `glpi_groups_users`.`users_id` = '{$userID}' " . getEntitiesRestrictRequest("AND", "glpi_groups", "", $entity_restrict, true); $result = $DB->query($query); $first = true; if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_assoc($result)) { if ($first) { $first = false; } else { $group_where .= " OR "; } $a_groups = getAncestorsOf("glpi_groups", $data["groups_id"]); $a_groups[$data["groups_id"]] = $data["groups_id"]; $group_where .= " `groups_id` IN (" . implode(',', $a_groups) . ") "; } $tmp_device = ""; foreach ($CFG_GLPI["linkgroup_types"] as $itemtype) { if (($item = getItemForItemtype($itemtype)) && parent::isPossibleToAssignType($itemtype)) { $itemtable = getTableForItemType($itemtype); $query = "SELECT *\n FROM `{$itemtable}`\n WHERE ({$group_where}) " . getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive()); if ($item->maybeDeleted()) { $query .= " AND `is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `is_template` = '0' "; } $result = $DB->query($query); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName(); if (!isset($already_add[$itemtype])) { $already_add[$itemtype] = array(); } while ($data = $DB->fetch_assoc($result)) { if (!in_array($data["id"], $already_add[$itemtype])) { $output = ''; if (isset($data["name"])) { $output = $data["name"]; } if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']); } $output = sprintf(__('%1$s - %2$s'), $type_name, $output); if (isset($data['serial'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['serial']); } if (isset($data['otherserial'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']); } $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . __s('Devices own by my groups') . "\">" . $tmp_device . "</optgroup>"; } } } // Get linked items to computers if (isset($already_add['Computer']) && count($already_add['Computer'])) { $search_computer = " XXXX IN (" . implode(',', $already_add['Computer']) . ') '; $tmp_device = ""; // Direct Connection $types = array('Monitor', 'Peripheral', 'Phone', 'Printer'); foreach ($types as $itemtype) { if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]) && ($item = getItemForItemtype($itemtype))) { $itemtable = getTableForItemType($itemtype); if (!isset($already_add[$itemtype])) { $already_add[$itemtype] = array(); } $query = "SELECT DISTINCT `{$itemtable}`.*\n FROM `glpi_computers_items`\n LEFT JOIN `{$itemtable}`\n ON (`glpi_computers_items`.`items_id` = `{$itemtable}`.`id`)\n WHERE `glpi_computers_items`.`itemtype` = '{$itemtype}'\n AND " . str_replace("XXXX", "`glpi_computers_items`.`computers_id`", $search_computer); if ($item->maybeDeleted()) { $query .= " AND `{$itemtable}`.`is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0' "; } $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict) . "\n ORDER BY `{$itemtable}`.`name`"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName(); while ($data = $DB->fetch_assoc($result)) { if (!in_array($data["id"], $already_add[$itemtype])) { $output = $data["name"]; if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']); } $output = sprintf(__('%1$s - %2$s'), $type_name, $output); if ($itemtype != 'Software') { $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']); } $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . __s('Connected devices') . "\">" . $tmp_device . "</optgroup>"; } // Software if (in_array('Software', $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) { $query = "SELECT DISTINCT `glpi_softwareversions`.`name` AS version,\n `glpi_softwares`.`name` AS name, `glpi_softwares`.`id`\n FROM `glpi_computers_softwareversions`, `glpi_softwares`,\n `glpi_softwareversions`\n WHERE `glpi_computers_softwareversions`.`softwareversions_id` =\n `glpi_softwareversions`.`id`\n AND `glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`\n AND " . str_replace("XXXX", "`glpi_computers_softwareversions`.`computers_id`", $search_computer) . "\n AND `glpi_softwares`.`is_helpdesk_visible` = '1' " . getEntitiesRestrictRequest("AND", "glpi_softwares", "", $entity_restrict) . "\n ORDER BY `glpi_softwares`.`name`"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $tmp_device = ""; $item = new Software(); $type_name = $item->getTypeName(); if (!isset($already_add['Software'])) { $already_add['Software'] = array(); } while ($data = $DB->fetch_assoc($result)) { if (!in_array($data["id"], $already_add['Software'])) { $output = sprintf(__('%1$s - %2$s'), $type_name, $data["name"]); $output = sprintf(__('%1$s (%2$s)'), $output, sprintf(__('%1$s: %2$s'), __('version'), $data["version"])); if ($_SESSION["glpiis_ids_visible"]) { $output = sprintf(__('%1$s (%2$s)'), $output, $data["id"]); } $tmp_device .= "<option title=\"{$output}\" value='Software_" . $data["id"] . "' " . ($my_item == 'Software' . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add['Software'][] = $data["id"]; } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . _sn('Installed software', 'Installed software', 2) . "\">"; $my_devices .= $tmp_device . "</optgroup>"; } } } } echo "<div id='tracking_my_devices'>"; echo "<select id='my_items' name='_my_items'>"; echo "<option value=''>--- "; echo __('General') . " ---</option>{$my_devices}</select></div>"; // Auto update summary of active or just solved tickets $params = array('my_items' => '__VALUE__'); Ajax::updateItemOnSelectEvent("my_items", "item_ticket_selection_information", $CFG_GLPI["root_doc"] . "/ajax/ticketiteminformation.php", $params); } }
You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRight("software", READ); if (!isset($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $soft = new Software(); if (isset($_POST["add"])) { $soft->check(-1, CREATE, $_POST); if ($newID = $soft->add($_POST)) { Event::log($newID, "software", 4, "inventory", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])); if ($_SESSION['glpibackcreated']) { Html::redirect($soft->getFormURL() . "?id=" . $newID); } } Html::back(); } else { if (isset($_POST["delete"])) { $soft->check($_POST["id"], DELETE); $soft->delete($_POST); Event::log($_POST["id"], "software", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"])); $soft->redirectToList();
/** * Print the Software form * * @param $ID integer ID of the item * @param $options array of possible options: * - target filename : where to go when done. * - withtemplate boolean : template or basic item * *@return boolean item found **/ function showForm($ID, $options = array()) { $this->initForm($ID, $options); $this->showTabs($options); $this->showFormHeader($options); $canedit = $this->can($ID, 'w'); echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Name') . "</td>"; echo "<td>"; Html::autocompletionTextField($this, "name"); echo "</td>"; echo "<td>" . __('Publisher') . "</td><td>"; Manufacturer::dropdown(array('value' => $this->fields["manufacturers_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Location') . "</td><td>"; Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Category') . "</td><td>"; SoftwareCategory::dropdown(array('value' => $this->fields["softwarecategories_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Technician in charge of the hardware') . "</td><td>"; User::dropdown(array('name' => 'users_id_tech', 'value' => $this->fields["users_id_tech"], 'right' => 'own_ticket', 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Associable to a ticket') . "</td><td>"; Dropdown::showYesNo('is_helpdesk_visible', $this->fields['is_helpdesk_visible']); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group in charge of the hardware') . "</td>"; echo "<td>"; Group::dropdown(array('name' => 'groups_id_tech', 'value' => $this->fields['groups_id_tech'], 'entity' => $this->fields['entities_id'], 'condition' => '`is_assign`')); echo "</td>"; echo "<td rowspan='5' class='middle'>" . __('Comments') . "</td>"; echo "<td class='center middle' rowspan='5'>"; echo "<textarea cols='45' rows='8' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td >" . __('User') . "</td>"; echo "<td >"; User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group') . "</td><td>"; Group::dropdown(array('value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"], 'condition' => '`is_itemgroup`')); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>"; if ((!isset($options['withtemplate']) || $options['withtemplate'] == 0) && !empty($this->fields['template_name'])) { echo "<span class='small_space'>"; printf(__('Created from the template %s'), $this->fields['template_name']); echo "</span>"; } else { echo " "; } echo "</td><td>"; if (isset($options['withtemplate']) && $options['withtemplate']) { //TRANS: %s is the datetime of insertion printf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"])); } else { //TRANS: %s is the datetime of insertion printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"])); } echo "</td></tr>\n"; // UPDATE echo "<tr class='tab_bg_1'>"; //TRANS: a noun, (ex : this software is an upgrade of..) echo "<td>" . __('Upgrade') . "</td><td>"; Dropdown::showYesNo("is_update", $this->fields['is_update']); echo " " . __('from') . " "; Software::dropdown(array('value' => $this->fields["softwares_id"])); echo "</td></tr>\n"; $this->showFormButtons($options); $this->addDivForTabs(); return true; }
public function softwareAssetsReports() { if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin" || Session::get("user_type") == "User")) { $view = View::make("Reports.software_assets_reports"); $view->nav = "system"; $view->tab = "software"; $totalSoftwareAssets = Software::all()->count(); $softwareTypes = SoftwareType::orderBy("software_type")->get(); $available = Software::where("status", "=", "Available")->count(); $pwu = Software::where("status", "=", "PWU")->count(); $retired = Software::where("status", "=", "Retired")->count(); $test_case = Software::where("status", "=", "Test Case")->count(); $lost = Software::where("status", "=", "Lost")->count(); $view->softwareTypes = $softwareTypes; $view->available = $available; $view->pwu = $pwu; $view->retired = $retired; $view->test_case = $test_case; $view->lost = $lost; $view->totalSoftwareAssets = $totalSoftwareAssets; return $view; } else { return Redirect::to("/"); } }
You should have received a copy of the GNU General Public License along with reports. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ // Original Author of file: Remi Collet // Purpose of file: // ---------------------------------------------------------------------- $USEDBREPLICATE = 1; $DBCONNECTION_REQUIRED = 1; // Really a big SQL request include "../../../../inc/includes.php"; includeLocales("histoinst"); plugin_reports_checkRight('reports', "histoinst", "r"); $computer = new Computer(); $computer->checkGlobal('r'); $software = new Software(); $software->checkGlobal('r'); //TRANS: The name of the report = History of last software's installations Html::header(__('histoinst_report_title', 'reports'), $_SERVER['PHP_SELF'], "utils", "report"); Report::title(); echo "<div class='center'>"; echo "<table class='tab_cadrehov' cellpadding='5'>\n"; echo "<tr class='tab_bg_1 center'>" . "<th colspan='4'>" . __("History of last software's installations", "reports") . "</th></tr>\n"; echo "<tr class='tab_bg_2'><th>" . __('Date of inventory', 'reports') . "</th>" . "<th>" . __('User') . "</th>" . "<th>" . __("Computer's name") . "</th>" . "<th>" . sprintf(__('%1$s (%2$s)'), _n('Software', 'Software', 1), __('version')) . "</th></tr>\n"; $sql = "SELECT a.`date_mod` AS dat, a.`new_value`, `glpi_computers`.`id` AS cid, `name`,\n a.`user_name`\n FROM (SELECT `date_mod`, `new_value`, `user_name`, `items_id`, `id`\n FROM `glpi_logs`\n WHERE `glpi_logs`.`date_mod` > DATE_SUB(Now(), INTERVAL 21 DAY)\n AND `linked_action` = '" . Log::HISTORY_INSTALL_SOFTWARE . "'\n AND `itemtype` = 'Computer') a\n LEFT JOIN `glpi_computers` ON (a.`items_id` = `glpi_computers`.`id`)\n WHERE `glpi_computers`.`entities_id` = '" . $_SESSION["glpiactive_entity"] . "'\n ORDER BY a.`id` DESC\n LIMIT 0,200"; $result = $DB->query($sql); $prev = ""; $class = "tab_bg_2"; while ($data = $DB->fetch_array($result)) { if ($prev == $data["dat"] . $data["name"]) { echo "<br />";
/** * @fn _init_software * @short Private method that initializes repetitive members of software product page actions. */ private function _init_software() { $conn = Db::get_connection(); if (isset($_REQUEST['software_name'])) { $software_factory = new Software(); $softwares = $software_factory->find_all(array('where_clause' => '`name` = \'' . $conn->escape($_REQUEST['software_name']) . '\' AND `type` = \'' . $conn->escape($_REQUEST['software_type']) . '\'', 'limit' => 1)); if (count($softwares) > 0) { $this->software = $softwares[0]; } else { $softwares = $software_factory->find_by_query('SELECT `softwares`.`id` ' . 'FROM `softwares` ' . 'LEFT JOIN `software_typos` ON `softwares`.`id` = `software_typos`.`software_id` ' . 'WHERE `software_typos`.`typo` = \'' . $conn->escape($_REQUEST['software_name']) . '\' ' . 'LIMIT 1'); if (count($softwares) > 0) { $this->software = $softwares[0]; header(sprintf('Location: http://%s%s', $_SERVER['HTTP_HOST'], $this->software->url_to_detail($_REQUEST['subview']))); exit; } else { HTTP::error(404); } } $_REQUEST['id'] = $this->software->id; } else { if (isset($_GET['id'])) { $this->software = new Software(); if ($this->software->find_by_id($_GET['id']) === FALSE) { $this->flash(l('No such software product!'), 'error'); $this->redirect_to(array('action' => 'index')); } } else { HTTP::error(404); } } $this->software->has_many('software_releases', array('where_clause' => '`released` = \'1\'')); $releases = $this->software->software_releases; usort($releases, array($releases[0], 'sort_releases')); $this->release = $releases[0]; $this->software->software_releases = $releases; Db::close_connection($conn); }
/** * 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}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&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> </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>"; }
function post_deleteFromDB() { $vers = new SoftwareVersion(); if (!$vers->getFromDB($this->fields['softwareversions_id'])) { return false; } /// Could not be possible : because several computers may be linked to a version // Update affected licenses // $lic = new SoftwareLicense(); // $query = "SELECT `id` // FROM `glpi_softwarelicenses` // WHERE `softwares_id` = '".$vers->fields['softwares_id']."' // AND `computers_id` = '".$this->fields['computers_id']."' // AND `softwareversions_id_use` = '".$this->fields['softwareversions_id']."'"; // foreach ($DB->request($query) as $data) { // $data['softwareversions_id_use'] = 0; // $lic->update($data); // } if (isset($this->input['_no_history']) && $this->input['_no_history']) { return false; } $soft = new Software(); if ($soft->getFromDB($vers->fields['softwares_id'])) { $changes[0] = '0'; $changes[1] = addslashes($soft->fields["name"] . " " . $vers->fields["name"]); $changes[2] = ""; // Log on Computer history Log::history($this->fields['computers_id'], 'Computer', $changes, 0, HISTORY_UNINSTALL_SOFTWARE); } $comp = new Computer(); if ($comp->getFromDB($this->fields['computers_id'])) { $changes[0] = '0'; $changes[1] = addslashes($comp->fields["name"]); $changes[2] = ""; // Log on SoftwareVersion history Log::history($this->fields['softwareversions_id'], 'SoftwareVersion', $changes, 0, HISTORY_UNINSTALL_SOFTWARE); } }
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * MA 02110-1301 USA * * * On Debian GNU/Linux systems, the complete text of the GNU General * Public License can be found in `/usr/share/common-licenses/GPL-2'. * * Otherwise you can read it here: http://www.gnu.org/licenses/gpl-2.0.txt * */ require_once 'av_init.php'; Session::logcheck('environment-menu', 'PolicyHosts'); //CPE Types $_cpe_types = array('os' => 'o', 'hardware' => 'h', 'software' => 'a'); $_cpe = GET('q'); $_cpe_type = GET('cpe_type'); ossim_valid($_cpe, OSS_NULLABLE, OSS_ALPHA, OSS_PUNC_EXT, 'illegal:' . _('CPE')); ossim_valid($_cpe_type, 'os | software | hardware', 'illegal:' . _('CPE Type')); if (ossim_error() || !array_key_exists($_cpe_type, $_cpe_types)) { exit; } $db = new Ossim_db(); $conn = $db->connect(); $_cpe = escape_sql($_cpe, $conn); $filters = array('where' => "`cpe` LIKE 'cpe:/" . $_cpe_types[$_cpe_type] . "%' AND `line` LIKE '%{$_cpe}%'", 'limit' => 20); $software = new Software($conn, $filters); $db->close(); foreach ($software->get_software() as $cpe_info) { echo $cpe_info['cpe'] . '###' . $cpe_info['line'] . "\n"; } /* End of file search_cpe.php */
based on GLPI - Gestionnaire Libre de Parc Informatique Copyright (C) 2003-2014 by the INDEPNET Development Team. ------------------------------------------------------------------------- LICENSE This file is part of GLPI. GLPI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRight("software", READ); Html::header(Software::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "assets", "software"); Search::show('Software'); Html::footer();