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();
 }
 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();
 }
 /**
  * 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;
 }
 /**
  * Show Licenses of a software
  *
  * @param $software Software object
  *
  * @return nothing
  **/
 static function showForSoftware(Software $software)
 {
     global $DB, $CFG_GLPI;
     $softwares_id = $software->getField('id');
     $license = new self();
     $computer = new Computer();
     if (!$software->can($softwares_id, READ)) {
         return false;
     }
     $columns = array('name' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'number' => _x('quantity', 'Number'), '_affected' => __('Affected computers'), 'typename' => __('Type'), 'buyname' => __('Purchase version'), 'usename' => __('Version in use'), 'expire' => __('Expiration'));
     if (!$software->isRecursive()) {
         unset($columns['entity']);
     }
     if (isset($_GET["start"])) {
         $start = $_GET["start"];
     } else {
         $start = 0;
     }
     if (isset($_GET["order"]) && $_GET["order"] == "DESC") {
         $order = "DESC";
     } else {
         $order = "ASC";
     }
     if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
         $sort = "`" . $_GET["sort"] . "`";
     } else {
         $sort = "`entity` {$order}, `name`";
     }
     // Righ type is enough. Can add a License on a software we have Read access
     $canedit = Software::canUpdate();
     $showmassiveactions = $canedit;
     // Total Number of events
     $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true));
     echo "<div class='spaced'>";
     Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $software->getName()));
     if ($canedit) {
         echo "<div class='center firstbloc'>";
         echo "<a class='vsubmit' href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . _x('button', 'Add a license') . "</a>";
         echo "</div>";
     }
     $rand = mt_rand();
     $query = "SELECT `glpi_softwarelicenses`.*,\n                       `buyvers`.`name` AS buyname,\n                       `usevers`.`name` AS usename,\n                       `glpi_entities`.`completename` AS entity,\n                       `glpi_softwarelicensetypes`.`name` AS typename\n                FROM `glpi_softwarelicenses`\n                LEFT JOIN `glpi_softwareversions` AS buyvers\n                     ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n                LEFT JOIN `glpi_softwareversions` AS usevers\n                     ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n                LEFT JOIN `glpi_entities`\n                     ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n                LEFT JOIN `glpi_softwarelicensetypes`\n                     ON (`glpi_softwarelicensetypes`.`id`\n                          = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n                WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n                ORDER BY {$sort} {$order}\n                LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     if ($result = $DB->query($query)) {
         if ($num_displayed = $DB->numrows($result)) {
             // Display the pager
             Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number);
             if ($showmassiveactions) {
                 Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
                 $massiveactionparams = array('num_displayed' => $num_displayed, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('options' => array('glpi_softwareversions.name' => array('condition' => "`glpi_softwareversions`.`softwares_id`\n                                                                  = {$softwares_id}"), 'glpi_softwarelicenses.name' => array('itemlink_as_string' => true))));
                 Html::showMassiveActions($massiveactionparams);
             }
             $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
             $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
             echo "<table class='tab_cadre_fixehov'>";
             $header_begin = "<tr><th>";
             $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_end = '';
             foreach ($columns as $key => $val) {
                 // Non order column
                 if ($key[0] == '_') {
                     $header_end .= "<th>{$val}</th>";
                 } else {
                     $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "&amp;start=0\");'>{$val}</a></th>";
                 }
             }
             $header_end .= "</tr>\n";
             echo $header_begin . $header_top . $header_end;
             $tot_assoc = 0;
             for ($tot = 0; $data = $DB->fetch_assoc($result);) {
                 Session::addToNavigateListItems('SoftwareLicense', $data['id']);
                 $expired = true;
                 if (is_null($data['expire']) || $data['expire'] > date('Y-m-d')) {
                     $expired = false;
                 }
                 echo "<tr class='tab_bg_2" . ($expired ? '_2' : '') . "'>";
                 if ($license->canEdit($data['id'])) {
                     echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
                 } else {
                     echo "<td>&nbsp;</td>";
                 }
                 echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a></td>";
                 if (isset($columns['entity'])) {
                     echo "<td>";
                     echo $data['entity'];
                     echo "</td>";
                 }
                 echo "<td>" . $data['serial'] . "</td>";
                 echo "<td class='numeric'>" . ($data['number'] > 0 ? $data['number'] : __('Unlimited')) . "</td>";
                 $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']);
                 $tot_assoc += $nb_assoc;
                 $color = $data['is_valid'] ? 'green' : 'red';
                 echo "<td class='numeric {$color}'>" . $nb_assoc . "</td>";
                 echo "<td>" . $data['typename'] . "</td>";
                 echo "<td>" . $data['buyname'] . "</td>";
                 echo "<td>" . $data['usename'] . "</td>";
                 echo "<td class='center'>" . Html::convDate($data['expire']) . "</td>";
                 echo "</tr>";
                 if ($data['number'] < 0) {
                     // One illimited license, total is illimited
                     $tot = -1;
                 } else {
                     if ($tot >= 0) {
                         // Expire license not count
                         if (!$expired) {
                             // Not illimited, add the current number
                             $tot += $data['number'];
                         }
                     }
                 }
             }
             echo "<tr class='tab_bg_1 noHover'>";
             echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . __('Total') . "</td>";
             echo "<td class='numeric'>" . ($tot > 0 ? $tot . "" : __('Unlimited')) . "</td>";
             $color = $software->fields['is_valid'] ? 'green' : 'red';
             echo "<td class='numeric {$color}'>" . $tot_assoc . "</td><td></td><td></td><td></td><td></td>";
             echo "</tr>";
             echo "</table>\n";
             if ($showmassiveactions) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($massiveactionparams);
                 Html::closeForm();
             }
             Html::printAjaxPager(self::getTypeName(Session::getPluralNumber()), $start, $number);
         } else {
             echo "<table class='tab_cadre_fixe'><tr><th>" . __('No item found') . "</th></tr></table>";
         }
     }
     echo "</div>";
 }
 /**
  * Show installation of a Software
  *
  * @param $software object
  *
  * @return nothing
  **/
 static function showForSoftware(Software $software)
 {
     self::showInstallations($software->getField('id'), 'softwares_id');
 }
 /**
  * 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>";
 }
Example #7
0
File: Import.php Project: btry/glpi
 /**
  * Test software category Rule and putInTrash / removeFromTrash
  */
 public function testSoftwareCategory()
 {
     global $CFG_GLPI;
     $ent0 = $this->sharedFixture['entity'][0];
     // Clean preload rules
     $tmp = SingletonRuleList::getInstance('RuleSoftwareCategory');
     $tmp->load = 0;
     $this->assertArrayHasKey('softwarecategories_id_ondelete', $CFG_GLPI, "Fail: no softwarecategories_id_ondelete");
     $idcat[0] = Dropdown::import('SoftwareCategory', array('name' => 'Trashed'));
     $this->assertGreaterThan(0, $idcat[0], "Fail: can't create SoftwareCategory");
     $idcat[1] = Dropdown::import('SoftwareCategory', array('name' => 'OpenSource'));
     $this->assertGreaterThan(0, $idcat[1], "Fail: can't create SoftwareCategory");
     $rule = new RuleSoftwareCategory();
     $crit = new RuleCriteria();
     $acte = new RuleAction();
     $idr[0] = $rule->add(array('name' => 'OSS', 'sub_type' => 'RuleSoftwareCategory', 'match' => 'AND', 'is_active' => 1));
     $this->assertGreaterThan(0, $idr[0], "Fail: can't create rule 1");
     $this->assertTrue($rule->getFromDB($idr[0]));
     $this->assertEquals(1, $rule->fields['ranking'], "Fail: ranking not set");
     $idc[0] = $crit->add(array('rules_id' => $idr[0], 'criteria' => 'manufacturer', 'condition' => Rule::PATTERN_IS, 'pattern' => 'Indepnet'));
     $this->assertGreaterThan(0, $idc[0], "Fail: can't create rule 1 criteria");
     $ida[0] = $acte->add(array('rules_id' => $idr[0], 'action_type' => 'assign', 'field' => 'softwarecategories_id', 'value' => $idcat[1]));
     $this->assertGreaterThan(0, $ida[0], "Fail: can't create rule 1 action");
     // Createthe software
     $soft = new Software();
     $id[0] = $soft->addOrRestoreFromTrash('GLPI', 'Indepnet', $ent0);
     $this->assertGreaterThan(0, $id[0], "Fail: can't create software 1");
     // Check name
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $this->assertEquals('GLPI', $soft->getField('name'), "Fail: name not set");
     // Check category
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[1], $catid, "Fail: category not set");
     // Change configuration
     $CFG_GLPI["softwarecategories_id_ondelete"] = $idcat[0];
     // Delete
     $this->assertTrue($soft->putInTrash($id[0]), "Fail: can't put soft in trash");
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[0], $catid, "Fail: category not set");
     $this->assertEquals(1, $soft->getField('is_deleted'), "Fail: soft not deleted");
     // Restore
     $this->assertTrue($soft->removeFromTrash($id[0]), "Fail: can't put soft in trash");
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[1], $catid, "Fail: category not set");
     $this->assertEquals(0, $soft->getField('is_deleted'), "Fail: soft not restored");
     // Clean
     $this->assertTrue($soft->delete(array('id' => $id[0]), true), "Fail: can't delete software 1)");
 }