grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * SoftwareVersion Class **/ class SoftwareVersion extends CommonDBChild { // From CommonDBTM public $dohistory = true; // From CommonDBChild static public $itemtype = 'Software'; static public $items_id = 'softwares_id'; static function getTypeName($nb=0) { return _n('Version', 'Versions', $nb); } function cleanDBonPurge() { global $DB; $csv = new Computer_SoftwareVersion(); $csv->cleanDBonItemDelete(__CLASS__, $this->fields['id']); } function defineTabs($options=array()) { $ong = array(); $this->addDefaultFormTab($ong); $this->addStandardTab('Computer_SoftwareVersion',$ong, $options); $this->addStandardTab('Log',$ong, $options); return $ong; } /** * @since version 0.84 * * @see CommonDBTM::getPreAdditionalInfosForName **/ function getPreAdditionalInfosForName() { $soft = new Software(); if ($soft->getFromDB($this->fields['softwares_id'])) { return $soft->getName(); } return ''; } /** * Print the Software / version form * * @param $ID integer Id of the version or the template to print * @param $options array of possible options: * - 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; if ($ID > 0) { $this->check($ID, READ); $softwares_id = $this->fields['softwares_id']; } else { $softwares_id = $options['softwares_id']; $this->check(-1, CREATE, $options); } $this->showFormHeader($options); echo ""._n('Software', 'Software', Session::getPluralNumber()).""; echo ""; if ($this->isNewID($ID)) { echo ""; } echo "". Dropdown::getDropdownName("glpi_softwares", $softwares_id).""; echo ""; echo "".__('Comments').""; echo ""; echo "\n"; echo "".__('Name').""; echo ""; Html::autocompletionTextField($this,"name"); echo "\n"; echo "" . __('Operating system') . ""; OperatingSystem::dropdown(array('value' => $this->fields["operatingsystems_id"])); echo "\n"; echo "" . __('Status') . ""; State::dropdown(array('value' => $this->fields["states_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_visible_softwareversion`")); echo "\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); return true; } function getSearchOptions() { $tab = array(); $tab['common'] = __('Characteristics'); $tab[2]['table'] = $this->getTable(); $tab[2]['field'] = 'name'; $tab[2]['name'] = __('Name'); $tab[2]['datatype'] = 'string'; $tab[4]['table'] = 'glpi_operatingsystems'; $tab[4]['field'] = 'name'; $tab[4]['name'] = __('Operating system'); $tab[4]['datatype'] = 'dropdown'; $tab[16]['table'] = $this->getTable(); $tab[16]['field'] = 'comment'; $tab[16]['name'] = __('Comments'); $tab[16]['datatype'] = 'text'; $tab[31]['table'] = 'glpi_states'; $tab[31]['field'] = 'completename'; $tab[31]['name'] = __('Status'); $tab[31]['datatype'] = 'dropdown'; $tab[31]['condition'] = "`is_visible_softwareversion`"; $tab[121]['table'] = $this->getTable(); $tab[121]['field'] = 'date_creation'; $tab[121]['name'] = __('Creation date'); $tab[121]['datatype'] = 'datetime'; $tab[121]['massiveaction'] = false; return $tab; } /** * Make a select box for software to install * * @param $options array of possible options: * - name : string / name of the select (default is softwareversions_id) * - softwares_id : integer / ID of the software (mandatory) * - value : integer / value of the selected version * - used : array / already used items * * @return nothing (print out an HTML select box) **/ static function dropdownForOneSoftware($options=array()) { global $CFG_GLPI, $DB; //$softwares_id,$value=0 $p['softwares_id'] = 0; $p['value'] = 0; $p['name'] = 'softwareversions_id'; $p['used'] = array(); $p['display_emptychoice'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $where = ''; if (count($p['used'])) { $where = " AND `glpi_softwareversions`.`id` NOT IN (".implode(",",$p['used']).")"; } // Make a select box $query = "SELECT DISTINCT `glpi_softwareversions`.*, `glpi_states`.`name` AS sname FROM `glpi_softwareversions` LEFT JOIN `glpi_states` ON (`glpi_softwareversions`.`states_id` = `glpi_states`.`id`) WHERE `glpi_softwareversions`.`softwares_id` = '".$p['softwares_id']."' $where ORDER BY `name`"; $result = $DB->query($query); $number = $DB->numrows($result); $values = array(); if ($number) { while ($data = $DB->fetch_assoc($result)) { $ID = $data['id']; $output = $data['name']; if (empty($output) || $_SESSION['glpiis_ids_visible']) { $output = sprintf(__('%1$s (%2$s)'), $output, $ID); } if (!empty($data['sname'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['sname']); } $values[$ID] = $output; } } return Dropdown::showFromArray($p['name'], $values, $p); } /** * 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 "
"; if ($canedit) { echo "
"; echo "". _x('button', 'Add a version').""; echo "
"; } $query = "SELECT `glpi_softwareversions`.*, `glpi_states`.`name` AS sname FROM `glpi_softwareversions` LEFT JOIN `glpi_states` ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`) WHERE `softwares_id` = '$softwares_id' ORDER BY `name`"; Session::initNavigateListItems('SoftwareVersion', //TRANS : %1$s is the itemtype name, // %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->getName())); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; for ($tot=$nb=0 ; $data=$DB->fetch_assoc($result) ; $tot+=$nb) { Session::addToNavigateListItems('SoftwareVersion',$data['id']); $nb = Computer_SoftwareVersion::countForVersion($data['id']); echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; } echo ""; echo ""; echo "
".self::getTypeName(Session::getPluralNumber())."".__('Status')."".__('Operating system').""._n('Installation', 'Installations', Session::getPluralNumber())."".__('Comments')."
"; echo $data['name'].(empty($data['name'])?"(".$data['id'].")":"")."".$data['sname']."".Dropdown::getDropdownName('glpi_operatingsystems', $data['operatingsystems_id']); echo "$nb".$data['comment']."
".__('Total')."$tot
\n"; } else { echo ""; echo ""; echo "
".__('No item found')."
\n"; } } echo "
"; } function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { if (!$withtemplate) { $nb = 0; switch ($item->getType()) { case 'Software' : if ($_SESSION['glpishow_count_on_tabs']) { $nb = countElementsInTable($this->getTable(), "softwares_id = '".$item->getID()."'"); } return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb); } } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { if ($item->getType() == 'Software') { self::showForSoftware($item); } return true; } } ?>