getField() public method

Return a field Value if exists
public getField ( $field ) : value
$field field name
return value of the field / false if not exists
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $DB, $CFG_GLPIG;
     if (!Session::haveRight("contract", "r")) {
         return false;
     }
     $type = $item->getType();
     $ID = $item->getField('id');
     $con = new Contract();
     $query = "SELECT *\n                FROM `glpi_contracts_items`\n                WHERE `glpi_contracts_items`.`items_id` = '" . $ID . "'\n                      AND `glpi_contracts_items`.`itemtype` = '" . $type . "'";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = $j = 0;
     $pdf->setColumnsSize(100);
     if ($number > 0) {
         $pdf->displayTitle('<b>' . _N('Associated contract', 'Associated contracts', 2) . '</b>');
         $pdf->setColumnsSize(19, 19, 19, 16, 11, 16);
         $pdf->displayTitle(__('Name'), _x('phone', 'Number'), __('Contract type'), __('Supplier'), __('Start date'), __('Initial contract period'));
         $i++;
         while ($j < $number) {
             $cID = $DB->result($result, $j, "contracts_id");
             $assocID = $DB->result($result, $j, "id");
             if ($con->getFromDB($cID)) {
                 $pdf->displayLine(empty($con->fields["name"]) ? "(" . $con->fields["id"] . ")" : $con->fields["name"], $con->fields["num"], Html::clean(Dropdown::getDropdownName("glpi_contracttypes", $con->fields["contracttypes_id"])), str_replace("<br>", " ", $con->getSuppliersNames()), Html::convDate($con->fields["begin_date"]), sprintf(_n('%d month', '%d months', $con->fields["duration"]), $con->fields["duration"]));
             }
             $j++;
         }
     } else {
         $pdf->displayTitle("<b>" . __('No item found') . "</b>");
     }
     $pdf->displaySpace();
 }
Example #2
0
 /**
  * @param CommonDBTM $item
  **/
 static function countForItem(CommonDBTM $item)
 {
     global $DB;
     $query = "SELECT COUNT(*) AS cpt FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n         LEFT JOIN `glpi_plugin_monitoring_services`\n            ON `glpi_plugin_monitoring_services`.`plugin_monitoring_componentscatalogs_hosts_id` =\n               `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n         WHERE `itemtype` = '" . $item->getType() . "'\n            AND `items_id` ='" . $item->getField('id') . "'\n            AND `glpi_plugin_monitoring_services`.`id` IS NOT NULL";
     $result = $DB->query($query);
     $ligne = $DB->fetch_assoc($result);
     return $ligne['cpt'];
 }
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $DB;
     $ID = $item->getField('id');
     $type = $item->getType();
     $crit = $type == 'Software' ? 'softwares_id' : 'id';
     if ($type == 'Software') {
         $crit = 'softwares_id';
         // Software ID
         $innerjoin = "INNER JOIN `glpi_softwareversions`\n                           ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                               = `glpi_softwareversions`.`id`)";
         $where = "WHERE `glpi_softwareversions`.`softwares_id` = '" . $ID . "'";
     } else {
         $crit = 'id';
         //SoftwareVersion ID
         $innerjoin = '';
         $where = "WHERE `glpi_computers_softwareversions`.`softwareversions_id` = '" . $ID . "'";
     }
     $query_number = "SELECT COUNT(*) AS cpt\n                       FROM `glpi_computers_softwareversions`\n                       {$innerjoin}\n                       INNER JOIN `glpi_computers`\n                           ON (`glpi_computers_softwareversions`.`computers_id` = `glpi_computers`.`id`)\n                       {$where}" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                            AND `glpi_computers`.`is_deleted` = '0'\n                            AND `glpi_computers`.`is_template` = '0'";
     $total = 0;
     if ($result = $DB->query($query_number)) {
         $total = $DB->result($result, 0, 0);
     }
     $query = "SELECT DISTINCT `glpi_computers_softwareversions`.*,\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_softwareversions`.`name` AS version,\n                          `glpi_softwareversions`.`id` AS vID,\n                          `glpi_softwareversions`.`softwares_id` AS sID,\n                          `glpi_softwareversions`.`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                FROM `glpi_computers_softwareversions`\n                INNER JOIN `glpi_softwareversions`\n                     ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                              = `glpi_softwareversions`.`id`)\n                INNER JOIN `glpi_computers`\n                     ON (`glpi_computers_softwareversions`.`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_softwareversions`.`{$crit}` = '{$ID}') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n                      AND `glpi_computers`.`is_deleted` = '0'\n                      AND `glpi_computers`.`is_template` = '0'\n                ORDER BY version, compname\n                LIMIT 0," . intval($_SESSION['glpilist_limit']);
     $pdf->setColumnsSize(100);
     if (($result = $DB->query($query)) && ($number = $DB->numrows($result)) > 0) {
         if ($number == $total) {
             $pdf->displayTitle('<b>' . sprintf(__('%1$s: %2$s'), _n('Installation', 'Installations', 2), $number) . "</b>");
         } else {
             $pdf->displayTitle('<b>' . sprintf(__('%1$s: %2$s'), _n('Installation', 'Installations', 2), $number / $total) . "</b>");
         }
         $pdf->setColumnsSize(12, 16, 15, 15, 22, 20);
         $pdf->displayTitle('<b><i>' . _n('Version', 'Versions', 2), __('Name'), __('Serial number'), __('Inventory number'), __('Location'), _n('License', 'Licenses', 2) . '</i></b>');
         while ($data = $DB->fetch_assoc($result)) {
             $compname = $data['compname'];
             if (empty($compname) || $_SESSION['glpiis_ids_visible']) {
                 $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']);
             }
             $lics = Computer_SoftwareLicense::GetLicenseForInstallation($data['cID'], $data['vID']);
             $tmp = array();
             if (count($lics)) {
                 foreach ($lics as $lic) {
                     $licname = $lic['name'];
                     if (!empty($lic['type'])) {
                         $licname = sprintf(__('%1$s (%2$s)'), $licname, $lic['type']);
                     }
                     $tmp[] = $licname;
                 }
             }
             $pdf->displayLine($data['version'], $compname, $data['serial'], $data['otherserial'], $data['location'], implode(', ', $tmp));
         }
     } else {
         $pdf->displayTitle('<b>' . _n('Installation', 'Installations', 2) . '</b>');
         $pdf->displayLine(__('No item found'));
     }
     $pdf->displaySpace();
 }
Example #4
0
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $DB;
     $ID = $item->getField('id');
     $type = get_class($item);
     if (!Session::haveRight("link", "r")) {
         return false;
     }
     $query = "SELECT `glpi_links`.`id` AS ID, `glpi_links`.`link`, `glpi_links`.`name`,\n                       `glpi_links`.`data`\n                FROM `glpi_links`\n                INNER JOIN `glpi_links_itemtypes`\n                     ON `glpi_links`.`id` = `glpi_links_itemtypes`.`links_id`\n                WHERE `glpi_links_itemtypes`.`itemtype` = '" . $type . "'\n                ORDER BY `glpi_links`.`name`";
     $result = $DB->query($query);
     $pdf->setColumnsSize(100);
     if ($DB->numrows($result) > 0) {
         $pdf->displayTitle('<b>' . __('External Links') . '</b>');
         while ($data = $DB->fetch_assoc($result)) {
             $name = $data["name"];
             if (empty($name)) {
                 $name = $data["link"];
             }
             $link = $data["link"];
             $file = trim($data["data"]);
             if (empty($file)) {
                 $links = Link::generateLinkContents($data['link'], $item, $name);
                 $i = 1;
                 foreach ($links as $key => $link) {
                     $url = $link;
                     $pdf->displayLine(sprintf(__('%1$s: %2$s'), "<b>{$name} #{$i}</b>", $link));
                     $i++;
                     $i++;
                 }
             } else {
                 // Generated File
                 $files = Link::generateLinkContents($data['link'], $item);
                 $links = Link::generateLinkContents($data['data'], $item);
                 $i = 1;
                 foreach ($links as $key => $data) {
                     if (isset($files[$key])) {
                         // a different name for each file, ex name = foo-[IP].txt
                         $file = $files[$key];
                     } else {
                         // same name for all files, ex name = foo.txt
                         $file = reset($files);
                     }
                     $pdf->displayText(sprintf(__('%1$s: %2$s'), "<b>{$name} #{$i} - {$file}</b>", trim($data), 1, 10));
                     $i++;
                 }
             }
         }
         // Each link
     } else {
         $pdf->displayTitle('<b>' . __('No link defined') . '</b>');
     }
     $pdf->displaySpace();
 }
Example #5
0
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     $type = get_class($item);
     if (!Session::haveRight("reservation_central", "r")) {
         return;
     }
     $user = new User();
     $ri = new ReservationItem();
     $pdf->setColumnsSize(100);
     if ($ri->getFromDBbyItem($type, $ID)) {
         $now = $_SESSION["glpi_currenttime"];
         $query = "SELECT *\n                   FROM `glpi_reservationitems`\n                   INNER JOIN `glpi_reservations`\n                        ON (`glpi_reservations`.`reservationitems_id` = `glpi_reservationitems`.`id`)\n                   WHERE `end` > '" . $now . "'\n                         AND `glpi_reservationitems`.`items_id` = '{$ID}'\n                   ORDER BY `begin`";
         $result = $DB->query($query);
         $pdf->setColumnsSize(100);
         $pdf->displayTitle("<b>" . __('Current and future reservations') . "</b>");
         if (!$DB->numrows($result)) {
             $pdf->displayLine("<b>" . __('No reservation') . "</b>");
         } else {
             $pdf->setColumnsSize(14, 14, 26, 46);
             $pdf->displayTitle('<i>' . __('Start date'), __('End date'), __('By'), __('Comments') . '</i>');
             while ($data = $DB->fetch_assoc($result)) {
                 if ($user->getFromDB($data["users_id"])) {
                     $name = formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]);
                 } else {
                     $name = "(" . $data["users_id"] . ")";
                 }
                 $pdf->displayLine(Html::convDateTime($data["begin"]), Html::convDateTime($data["end"]), $name, str_replace(array("\r", "\n"), " ", $data["comment"]));
             }
         }
         $query = "SELECT *\n                   FROM `glpi_reservationitems`\n                   INNER JOIN `glpi_reservations`\n                        ON (`glpi_reservations`.`reservationitems_id` = `glpi_reservationitems`.`id`)\n                   WHERE `end` <= '" . $now . "'\n                         AND `glpi_reservationitems`.`items_id` = '{$ID}'\n                   ORDER BY `begin`\n                   DESC";
         $result = $DB->query($query);
         $pdf->setColumnsSize(100);
         $pdf->displayTitle("<b>" . __('Past reservations') . "</b>");
         if (!$DB->numrows($result)) {
             $pdf->displayLine("<b>" . __('No reservation') . "</b>");
         } else {
             $pdf->setColumnsSize(14, 14, 26, 46);
             $pdf->displayTitle('<i>' . __('Start date'), __('End date'), __('By'), __('Comments') . '</i>');
             while ($data = $DB->fetch_assoc($result)) {
                 if ($user->getFromDB($data["users_id"])) {
                     $name = formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]);
                 } else {
                     $name = "(" . $data["users_id"] . ")";
                 }
                 $pdf->displayLine(Html::convDateTime($data["begin"]), Html::convDateTime($data["end"]), $name, str_replace(array("\r", "\n"), " ", $data["comment"]));
             }
         }
     }
     $pdf->displaySpace();
 }
 static function countForItem(CommonDBTM $item)
 {
     $restrict = "`glpi_documents_items`.`documents_id` = `glpi_documents`.`id`\n                   AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'\n                   AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "'";
     if (getLoginUserID()) {
         $restrict .= getEntitiesRestrictRequest(" AND ", "glpi_documents", '', '', true);
     } else {
         // Anonymous access from FAQ
         $restrict .= " AND `glpi_documents`.`entities_id` = '0' ";
     }
     $nb = countElementsInTable(array('glpi_documents_items', 'glpi_documents'), $restrict);
     // Document case : search in both
     if ($item->getType() == 'Document') {
         $restrict = "`glpi_documents_items`.`items_id` = `glpi_documents`.`id`\n                      AND `glpi_documents_items`.`documents_id` = '" . $item->getField('id') . "'\n                      AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "'";
         if (getLoginUserID()) {
             $restrict .= getEntitiesRestrictRequest(" AND ", "glpi_documents", '', '', true);
         } else {
             // Anonymous access from FAQ
             $restrict .= " AND `glpi_documents`.`entities_id` = '0' ";
         }
         $nb += countElementsInTable(array('glpi_documents_items', 'glpi_documents'), $restrict);
     }
     return $nb;
 }
 /**
  * Show OcsLink of an item
  *
  * @param $item CommonDBTM object
  *
  * @return nothing
  **/
 static function showForItem(CommonDBTM $item)
 {
     global $DB, $LANG;
     if (in_array($item->getType(), array('Computer'))) {
         $items_id = $item->getField('id');
         $query = "SELECT `glpi_ocslinks`.`tag` AS tag\n                   FROM `glpi_ocslinks`\n                   WHERE `glpi_ocslinks`.`computers_id` = '{$items_id}' " . getEntitiesRestrictRequest("AND", "glpi_ocslinks");
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             $data = $DB->fetch_assoc($result);
             $data = clean_cross_side_scripting_deep(addslashes_deep($data));
             echo "<div class='center'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr><th>" . $LANG['ocsng'][0] . "</th>";
             echo "<tr class='tab_bg_2'>";
             echo "<td class='center'>" . $LANG['ocsconfig'][39] . "&nbsp;: " . $data['tag'] . "</td></tr>";
         }
     }
 }
Example #8
0
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $CFG_GLPI;
     $ID = $item->getField('id');
     if (!Session::haveRight("infocom", "r")) {
         return false;
     }
     $ic = new Infocom();
     $pdf->setColumnsSize(100);
     if ($ic->getFromDBforDevice(get_class($item), $ID)) {
         $pdf->displayTitle("<b>" . __('Financial and administrative information') . "</b>");
         $pdf->setColumnsSize(50, 50);
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Supplier') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Budget') . "</i></b>", Html::clean(Dropdown::getDropdownName("glpi_budgets", $ic->fields["budgets_id"]))));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Order number') . "</i></b>", $ic->fields["order_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Order date') . "</i></b>", Html::convDate($ic->fields["order_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Immobilization number') . "</i></b>", $ic->fields["immo_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Date of purchase') . "</i></b>", Html::convDate($ic->fields["buy_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Invoice number') . "</i></b>", $ic->fields["bill"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Delivery date') . "</i></b>", Html::convDate($ic->fields["delivery_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Delivery form') . "</i></b>", $ic->fields["delivery_number"]), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Startup date') . "</i></b>", Html::convDate($ic->fields["use_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Value') . "</i></b>", Html::clean(Html::formatNumber($ic->fields["value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), _('Date of last physical inventory') . "</i></b>", Html::convDate($ic->fields["inventory_date"])));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty extension value') . "</i></b>", Html::clean(Html::formatNumber($ic->fields["warranty_value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Amortization duration') . "</i></b>", sprintf(__('%1$s (%2$s)'), sprintf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]), Infocom::getAmortTypeName($ic->fields["sink_type"]))));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Account net value') . "</i></b>", Infocom::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $CFG_GLPI['date_tax'], "n")), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Amortization coefficient') . "</i></b>", $ic->fields["sink_coeff"]));
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('TCO (value + tracking cost)') . "</i></b>", Html::clean(Infocom::showTco($item->getField('ticket_tco'), $ic->fields["value"]))), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Monthly TCO') . "</i></b>", Html::clean(Infocom::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]))));
         PluginPdfCommon::mainLine($pdf, $ic, 'comment');
         $pdf->setColumnsSize(100);
         $pdf->displayTitle("<b>" . __('Warranty information') . "</b>");
         $pdf->setColumnsSize(50, 50);
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Start date of warranty') . "</i></b>", Html::convDate($ic->fields["warranty_date"])), "<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty duration') . "</i></b>", sprintf(__('%1$s - %2$s'), sprintf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]), sprintf(__('Valid to %s'), Infocom::getWarrantyExpir($ic->fields["buy_date"], $ic->fields["warranty_duration"])))));
         $col1 = "<b><i>" . __('Alarms on financial and administrative information') . "</i></b>";
         if ($ic->fields["alert"] == 0) {
             $col1 = sprintf(__('%1$s: %2$s'), $col1, __('No'));
         } else {
             if ($ic->fields["alert"] == 4) {
                 $col1 = sprintf(__('%1$s: %2$s'), $col1, __('Warranty expiration date'));
             }
         }
         $pdf->displayLine("<b><i>" . sprintf(__('%1$s: %2$s'), __('Warranty information') . "</i></b>", $ic->fields["warranty_info"]), $col1);
     } else {
         $pdf->displayTitle("<b>" . __('No financial information', 'pdf') . "</b>");
     }
     $pdf->displaySpace();
 }
Example #9
0
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
 {
     global $DB;
     $ID = $item->getField('id');
     $type = get_class($item);
     if (!Session::haveRight("document", "r")) {
         return false;
     }
     $query = "SELECT `glpi_documents_items`.`id` AS assocID,\n                       `glpi_documents`.*\n                FROM `glpi_documents_items`\n                LEFT JOIN `glpi_documents`\n                     ON (`glpi_documents_items`.`documents_id` = `glpi_documents`.`id`)\n                WHERE `glpi_documents_items`.`items_id` = '" . $ID . "'\n                      AND `glpi_documents_items`.`itemtype` = '" . $type . "'";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $pdf->setColumnsSize(100);
     if (!$number) {
         $pdf->displayTitle('<b>' . __('No associated documents', 'pdf') . '</b>');
     } else {
         $pdf->displayTitle('<b>' . __('Associated documents', 'pdf') . '</b>');
         $pdf->setColumnsSize(32, 15, 21, 19, 13);
         $pdf->displayTitle('<b>' . __('Name'), __('File'), __('Web link'), __('Heading'), _('MIME type') . '</b>');
         while ($data = $DB->fetch_assoc($result)) {
             $pdf->displayLine($data["name"], basename($data["filename"]), $data["link"], Html::clean(Dropdown::getDropdownName("glpi_documentcategories", $data["documentcategories_id"])), $data["mime"]);
         }
     }
     $pdf->displaySpace();
 }
Example #10
0
 static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tree = false)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     $type = $item->getType();
     if (!Session::haveRight("show_all_ticket", "1")) {
         return;
     }
     switch ($item->getType()) {
         case 'User':
             $restrict = "(`glpi_tickets_users`.`users_id` = '" . $item->getID() . "'\n                            AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             break;
         case 'SLA':
             $restrict = "(`slas_id` = '" . $item->getID() . "')";
             $order = '`glpi_tickets`.`due_date` DESC';
             break;
         case 'Supplier':
             $restrict = "(`glpi_suppliers_tickets`.`suppliers_id` = '" . $item->getID() . "'\n                           AND `glpi_suppliers_tickets`.`type` = " . CommonITILActor::ASSIGN . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             break;
         case 'Group':
             if ($tree) {
                 $restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")";
             } else {
                 $restrict = "='" . $item->getID() . "'";
             }
             $restrict = "(`glpi_groups_tickets`.`groups_id` {$restrict}\n                            AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")";
             $order = '`glpi_tickets`.`date_mod` DESC';
             break;
         default:
             $restrict = "(`items_id` = '" . $item->getID() . "'  AND `itemtype` = '{$type}')";
             $order = '`glpi_tickets`.`date_mod` DESC';
     }
     $query = "SELECT " . Ticket::getCommonSelect() . "\n                FROM glpi_tickets " . Ticket::getCommonLeftJoin() . "\n                WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                ORDER BY {$order}\n                LIMIT " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $pdf->setColumnsSize(100);
     if (!$number) {
         $pdf->displayTitle('<b>' . __('Last tickets') . '</b>');
     } else {
         $pdf->displayTitle("<b>" . sprintf(__('Last %d ticket') . "</b>", $number));
         $job = new Ticket();
         while ($data = $DB->fetch_assoc($result)) {
             if (!$job->getFromDB($data["id"])) {
                 continue;
             }
             $pdf->setColumnsAlign('center');
             $col = '<b><i>ID ' . $job->fields["id"] . '</i></b>, ' . sprintf(__('%1$s: %2$s'), __('Status'), Ticket::getStatus($job->fields["status"]));
             if (count($_SESSION["glpiactiveentities"]) > 1) {
                 if ($job->fields['entities_id'] == 0) {
                     $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity'));
                 } else {
                     $col = sprintf(__('%1$s (%2$s)'), $col, Dropdown::getDropdownName("glpi_entities", $job->fields['entities_id']));
                 }
             }
             $pdf->displayLine($col);
             $pdf->setColumnsAlign('left');
             $col = '<b><i>' . sprintf(__('Opened on %s') . '</i></b>', Html::convDateTime($job->fields['date']));
             if ($job->fields['begin_waiting_date']) {
                 $col = sprintf(__('%1$s, %2$s'), $col, '<b><i>' . sprintf(__('Put on hold on %s') . '</i></b>', Html::convDateTime($job->fields['begin_waiting_date'])));
             }
             if (in_array($job->fields["status"], $job->getSolvedStatusArray()) || in_array($job->fields["status"], $job->getClosedStatusArray())) {
                 $col = sprintf(__('%1$s, %2$s'), $col, '<b><i>' . sprintf(__('Solved on %s') . '</i></b>', Html::convDateTime($job->fields['solvedate'])));
             }
             if (in_array($job->fields["status"], $job->getClosedStatusArray())) {
                 $col = sprintf(__('%1$s, %2$s'), $col, '<b><i>' . sprintf(__('Closed on %s') . '</i></b>', Html::convDateTime($job->fields['closedate'])));
             }
             if ($job->fields['due_date']) {
                 $col = sprintf(__('%1$s, %2$s'), $col, '<b><i>' . sprintf(__('%1$s: %2$s') . '</i></b>', __('Due date'), Html::convDateTime($job->fields['due_date'])));
             }
             $pdf->displayLine($col);
             $col = '<b><i>' . sprintf(__('%1$s: %2$s'), __('Priority') . '</i></b>', Ticket::getPriorityName($job->fields["priority"]));
             if ($job->fields["itilcategories_id"]) {
                 $col = sprintf(__('%1$s - %2$s'), $col, '<b><i>' . sprintf(__('%1$s: %2$s') . '</i></b>', __('Category'), Dropdown::getDropdownName('glpi_itilcategories', $job->fields["itilcategories_id"])));
             }
             $pdf->displayLine($col);
             $col = '';
             $users = $job->getUsers(CommonITILActor::REQUESTER);
             if (count($users)) {
                 foreach ($users as $d) {
                     if (empty($col)) {
                         $col = getUserName($d['users_id']);
                     } else {
                         $col = sprintf(__('%1$s, %2$s'), $col, getUserName($d['users_id']));
                     }
                 }
             }
             $grps = $job->getGroups(CommonITILActor::REQUESTER);
             if (count($grps)) {
                 if (empty($col)) {
                     $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' </i></b>');
                 } else {
                     $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' </i></b>');
                 }
                 $first = true;
                 foreach ($grps as $d) {
                     if ($first) {
                         $col = sprintf(__('%1$s  %2$s'), $col, Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
                     } else {
                         $col = sprintf(__('%1$s, %2$s'), $col, Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
                     }
                     $first = false;
                 }
             }
             if ($col) {
                 $texte = '<b><i>' . sprintf(__('%1$s: %2$s'), __('Requester') . '</i></b>', '');
                 $pdf->displayText($texte, $col, 1);
             }
             $col = '';
             $users = $job->getUsers(CommonITILActor::ASSIGN);
             if (count($users)) {
                 foreach ($users as $d) {
                     if (empty($col)) {
                         $col = getUserName($d['users_id']);
                     } else {
                         $col = sprintf(__('%1$s, %2$s'), $col, getUserName($d['users_id']));
                     }
                 }
             }
             $grps = $job->getGroups(CommonITILActor::ASSIGN);
             if (count($grps)) {
                 if (empty($col)) {
                     $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' </i></b>');
                 } else {
                     $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' </i></b>');
                 }
                 $first = true;
                 foreach ($grps as $d) {
                     if ($first) {
                         $col = sprintf(__('%1$s  %2$s'), $col, Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
                     } else {
                         $col = sprintf(__('%1$s, %2$s'), $col, Dropdown::getDropdownName("glpi_groups", $d['groups_id']));
                     }
                     $first = false;
                 }
             }
             if ($col) {
                 $texte = '<b><i>' . sprintf(__('%1$s: %2$s') . '</i></b>', 'Assigned to', '');
                 $pdf->displayText($texte, $col, 1);
             }
             $texte = '<b><i>' . sprintf(__('%1$s: %2$s') . '</i></b>', 'Title', '');
             $pdf->displayText($texte, $job->fields["name"], 1);
         }
     }
     $pdf->displaySpace();
 }
Example #11
0
 /**
  * Hook called After an item is uninstall or purge
  */
 static function cleanForItem(CommonDBTM $item)
 {
     $temp = new self();
     $temp->deleteByCriteria(array('itemtype' => $item->getType(), 'items_id' => $item->getField('id')));
 }
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $CFG_GLPI;
     switch ($ma->getAction()) {
         case 'Generate':
             $pbQRcode = new PluginBarcodeQRcode();
             $rand = mt_rand();
             $number = 0;
             $codes = array();
             if ($ma->POST['eliminate'] > 0) {
                 for ($nb = 0; $nb < $ma->POST['eliminate']; $nb++) {
                     $codes[] = '';
                 }
             }
             if ($ma->POST['type'] == 'QRcode') {
                 foreach ($ids as $key) {
                     $filename = $pbQRcode->generateQRcode($item->getType(), $key, $rand, $number, $ma->POST);
                     if ($filename) {
                         $codes[] = $filename;
                         $number++;
                     }
                 }
             } else {
                 foreach ($ids as $key) {
                     $item->getFromDB($key);
                     if ($item->isField('otherserial')) {
                         $codes[] = $item->getField('otherserial');
                     }
                 }
             }
             if (count($codes) > 0) {
                 $params['codes'] = $codes;
                 $params['type'] = $ma->POST['type'];
                 $params['size'] = $ma->POST['size'];
                 $params['border'] = $ma->POST['border'];
                 $params['orientation'] = $ma->POST['orientation'];
                 $barcode = new PluginBarcodeBarcode();
                 $file = $barcode->printPDF($params);
                 $filePath = explode('/', $file);
                 $filename = $filePath[count($filePath) - 1];
                 $msg = "<a href='" . $CFG_GLPI['root_doc'] . '/plugins/barcode/front/send.php?file=' . urlencode($filename) . "'>" . __('Generated file', 'barcode') . "</a>";
                 Session::addMessageAfterRedirect($msg);
                 $pbQRcode->cleanQRcodefiles($rand, $number);
             }
             $ma->itemDone($item->getType(), 0, MassiveAction::ACTION_OK);
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 /**
  * Show rack associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated rack must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID) || !self::canView() || !$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginRacksRack');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $itemtype = $item->getType() . "Model";
     $query = "SELECT `glpi_plugin_racks_racks_items`.`id` AS assocID,\n                       `glpi_plugin_racks_racks_items`.`faces_id`,\n                       `glpi_plugin_racks_racks_items`.`position`,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_racks_racks`.`name` AS assocName,\n                       `glpi_plugin_racks_racks`.*\n                FROM `glpi_plugin_racks_racks_items`\n                LEFT JOIN `glpi_plugin_racks_racks`\n                 ON (`glpi_plugin_racks_racks_items`.`plugin_racks_racks_id`=`glpi_plugin_racks_racks`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_racks_racks`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_racks_racks_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_racks_racks_items`.`itemtype` = '" . $itemtype . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_racks_racks", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $racks = array();
     $rack = new PluginRacksRack();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $racks[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Disposition', 'racks') . "</th>";
     echo "<th>" . __('Position', 'racks') . "</th>";
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . __('Place', 'racks') . "</th>";
     echo "<th>" . __('Manufacturer') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginRacksRack', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($racks as $data) {
             $rackID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($rack->getFromDB($rackID)) {
                 $link = $rack->getLink();
             }
             Session::addToNavigateListItems('PluginRacksRack', $rackID);
             $used[$rackID] = $rackID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             if ($data["faces_id"] == PluginRacksRack::FRONT_FACE) {
                 $faces_id = __('Front', 'racks');
             } else {
                 $faces_id = _x('Rack enclosure', 'Back', 'racks');
             }
             echo "<td class='center'>" . $faces_id . "</td>";
             echo "<td class='center'>" . $data["position"] . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_locations", $data["locations_id"]) . "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_racks_roomlocations", $data["plugin_racks_roomlocations_id"], 0) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Example #14
0
 /**
  * Generate link
  *
  * @param $link    string   original string content
  * @param $item             CommonDBTM object: item used to make replacements
  *
  * @return array of link contents (may have several when item have several IP / MAC cases)
  **/
 static function generateLinkContents($link, CommonDBTM $item)
 {
     global $DB;
     if (strstr($link, "[ID]")) {
         $link = str_replace("[ID]", $item->fields['id'], $link);
     }
     if (strstr($link, "[LOGIN]") && isset($_SESSION["glpiname"])) {
         $link = str_replace("[LOGIN]", $_SESSION["glpiname"], $link);
     }
     if (strstr($link, "[NAME]")) {
         $link = str_replace("[NAME]", $item->getName(), $link);
     }
     if (strstr($link, "[SERIAL]") && $item->isField('serial')) {
         $link = str_replace("[SERIAL]", $item->getField('serial'), $link);
     }
     if (strstr($link, "[OTHERSERIAL]") && $item->isField('otherserial')) {
         $link = str_replace("[OTHERSERIAL]", $item->getField('otherserial'), $link);
     }
     if (strstr($link, "[LOCATIONID]") && $item->isField('locations_id')) {
         $link = str_replace("[LOCATIONID]", $item->getField('locations_id'), $link);
     }
     if (strstr($link, "[LOCATION]") && $item->isField('locations_id')) {
         $link = str_replace("[LOCATION]", Dropdown::getDropdownName("glpi_locations", $item->getField('locations_id')), $link);
     }
     if (strstr($link, "[NETWORK]") && $item->isField('networks_id')) {
         $link = str_replace("[NETWORK]", Dropdown::getDropdownName("glpi_networks", $item->getField('networks_id')), $link);
     }
     if (strstr($link, "[DOMAIN]") && $item->isField('domains_id')) {
         $link = str_replace("[DOMAIN]", Dropdown::getDropdownName("glpi_domains", $item->getField('domains_id')), $link);
     }
     if (strstr($link, "[USER]") && $item->isField('users_id')) {
         $link = str_replace("[USER]", Dropdown::getDropdownName("glpi_users", $item->getField('users_id')), $link);
     }
     if (strstr($link, "[GROUP]") && $item->isField('groups_id')) {
         $link = str_replace("[GROUP]", Dropdown::getDropdownName("glpi_groups", $item->getField('groups_id')), $link);
     }
     if (strstr($link, "[REALNAME]") && $item->isField('realname')) {
         $link = str_replace("[REALNAME]", $item->getField('realname'), $link);
     }
     if (strstr($link, "[FIRSTNAME]") && $item->isField('firstname')) {
         $link = str_replace("[FIRSTNAME]", $item->getField('firstname'), $link);
     }
     $replace_IP = strstr($link, "[IP]");
     $replace_MAC = strstr($link, "[MAC]");
     if (!$replace_IP && !$replace_MAC) {
         return array($link);
     }
     // Return several links id several IP / MAC
     $ipmac = array();
     if (get_class($item) == 'NetworkEquipment') {
         if ($replace_IP) {
             $query2 = "SELECT `glpi_ipaddresses`.`id`,\n                              `glpi_ipaddresses`.`name` AS ip\n                       FROM `glpi_networknames`, `glpi_ipaddresses`\n                       WHERE `glpi_networknames`.`items_id` = '" . $item->getID() . "'\n                             AND `glpi_networknames`.`itemtype` = 'NetworkEquipment'\n                             AND `glpi_ipaddresses`.`itemtype` = 'NetworkName'\n                             AND `glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`";
             foreach ($DB->request($query2) as $data2) {
                 $ipmac['ip' . $data2['id']]['ip'] = $data2["ip"];
                 $ipmac['ip' . $data2['id']]['mac'] = $item->getField('mac');
             }
         }
         if ($replace_MAC) {
             // If there is no entry, then, we must at least define the mac of the item ...
             if (count($ipmac) == 0) {
                 $ipmac['mac0']['ip'] = '';
                 $ipmac['mac0']['mac'] = $item->getField('mac');
             }
         }
     }
     if ($replace_IP) {
         $query2 = "SELECT `glpi_ipaddresses`.`id`,\n                           `glpi_networkports`.`mac`,\n                           `glpi_ipaddresses`.`name` AS ip\n                    FROM `glpi_networkports`, `glpi_networknames`, `glpi_ipaddresses`\n                    WHERE `glpi_networkports`.`items_id` = '" . $item->getID() . "'\n                          AND `glpi_networkports`.`itemtype` = '" . $item->getType() . "'\n                          AND `glpi_networknames`.`itemtype` = 'NetworkPort'\n                          AND `glpi_networknames`.`items_id` = `glpi_networkports`.`id`\n                          AND `glpi_ipaddresses`.`itemtype` = 'NetworkName'\n                          AND `glpi_ipaddresses`.`items_id` = `glpi_networknames`.`id`";
         foreach ($DB->request($query2) as $data2) {
             $ipmac['ip' . $data2['id']]['ip'] = $data2["ip"];
             $ipmac['ip' . $data2['id']]['mac'] = $data2["mac"];
         }
     }
     if ($replace_MAC) {
         $left = '';
         $where = '';
         if ($replace_IP) {
             $left = " LEFT JOIN `glpi_networknames`\n                             ON (`glpi_networknames`.`items_id` = `glpi_networkports`.`id`\n                                 AND `glpi_networknames`.`itemtype` = 'NetworkPort')";
             $where = " AND `glpi_networknames`.`id` IS NULL";
         }
         $query2 = "SELECT `glpi_networkports`.`id`,\n                           `glpi_networkports`.`mac`\n                    FROM `glpi_networkports`\n                    {$left}\n                    WHERE `glpi_networkports`.`items_id` = '" . $item->getID() . "'\n                          AND `glpi_networkports`.`itemtype` = '" . $item->getType() . "'\n                    {$where}\n                    GROUP BY `glpi_networkports`.`mac`";
         foreach ($DB->request($query2) as $data2) {
             $ipmac['mac' . $data2['id']]['ip'] = '';
             $ipmac['mac' . $data2['id']]['mac'] = $data2["mac"];
         }
     }
     $links = array();
     if (count($ipmac) > 0) {
         foreach ($ipmac as $key => $val) {
             $tmplink = $link;
             $disp = 1;
             if (strstr($link, "[IP]")) {
                 if (empty($val['ip'])) {
                     $disp = 0;
                 } else {
                     $tmplink = str_replace("[IP]", $val['ip'], $tmplink);
                 }
             }
             if (strstr($link, "[MAC]")) {
                 if (empty($val['mac'])) {
                     $disp = 0;
                 } else {
                     $tmplink = str_replace("[MAC]", $val['mac'], $tmplink);
                 }
             }
             if ($disp) {
                 $links[$key] = $tmplink;
             }
         }
     }
     if (count($links)) {
         return $links;
     }
     return array($link);
 }
Example #15
0
 /**
  * Show documents associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated documents must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if ($item->getType() != 'Ticket' && $item->getType() != 'KnowbaseItem' && $item->getType() != 'Reminder' && !Document::canView()) {
         return false;
     }
     $params = array();
     $params['rand'] = mt_rand();
     self::showAddFormForItem($item, $withtemplate, $params);
     self::showListForItem($item, $withtemplate, $params);
 }
Example #16
0
 /**
  * Show OcsLink of an item
  *
  * @param $item                   CommonDBTM object
  * @param $withtemplate  integer  withtemplate param (default '')
  *
  * @return nothing
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $target = Toolbox::getItemTypeFormURL(__CLASS__);
     if (in_array($item->getType(), array('Computer'))) {
         $items_id = $item->getField('id');
         if (!empty($items_id) && $item->fields["is_dynamic"] && Session::haveRight("plugin_ocsinventoryng_view", READ)) {
             $query = "SELECT *\n                      FROM `glpi_plugin_ocsinventoryng_ocslinks`\n                      WHERE `computers_id` = '{$items_id}' " . getEntitiesRestrictRequest("AND", "glpi_plugin_ocsinventoryng_ocslinks");
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 $data = $DB->fetch_assoc($result);
                 $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data));
                 if (count($data)) {
                     $ocs_config = PluginOcsinventoryngOcsServer::getConfig(PluginOcsinventoryngOcsServer::getByMachineID($items_id));
                     echo "<div class='center'>";
                     echo "<form method='post' action=\"{$target}\">";
                     echo "<input type='hidden' name='id' value='{$items_id}'>";
                     echo "<table class='tab_cadre_fixe'>";
                     echo "<tr><th colspan = '4'>OCS Inventory NG</th>";
                     echo "<tr class='tab_bg_1'>";
                     $colspan = 4;
                     if (Session::haveRight("plugin_ocsinventoryng_view", READ) && Session::haveRight("plugin_ocsinventoryng_sync", UPDATE)) {
                         $colspan = 2;
                         echo "<td class='center'>" . __('Automatic update OCSNG', 'ocsinventoryng') . "</td>";
                         echo "<td class='left'>";
                         Dropdown::showYesNo("use_auto_update", $data["use_auto_update"]);
                         echo "</td>";
                     }
                     echo "<td class='center' colspan='" . $colspan . "'>";
                     printf(__('%1$s: %2$s'), __('OCSNG TAG', 'ocsinventoryng'), $data['tag']);
                     echo "</td></tr>";
                     if (Session::haveRight("plugin_ocsinventoryng_sync", UPDATE)) {
                         echo "<tr class='tab_bg_1'>";
                         $colspan = 4;
                         echo "<td class='center' colspan='2'>";
                         echo "<input type='hidden' name='resynch_id' value='" . $data["id"] . "'>";
                         echo "<input class=submit type='submit' name='force_ocs_resynch' value=\"" . _sx('button', 'Force synchronization', 'ocsinventoryng') . "\">";
                         echo "</td>";
                         //echo "<tr class='tab_bg_1'>";
                         echo "<td class='center' colspan='2'>";
                         echo "<input type='hidden' name='link_id' value='" . $data["id"] . "'>";
                         echo "<input class=submit type='submit' name='update' value=\"" . _sx('button', 'Save') . "\">";
                         echo "</td></tr>";
                     }
                     echo "</table>\n";
                     Html::closeForm();
                     echo "</div>";
                 }
             }
         }
     }
 }
Example #17
0
 static function addNewTasks(CommonDBTM $item, $withtemplate = '')
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $ID = $item->getField('id');
     $entities_id = $item->getField('entities_id');
     $canedit = $item->can($ID, 'w');
     if (plugin_resources_haveRight('task', 'w') && $canedit && $withtemplate < 2) {
         echo "<div align='center'>";
         echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.form.php?plugin_resources_resources_id=" . $ID . "&entities_id=" . $entities_id . "' >" . __('Add a new task') . "</a></div>";
         echo "</div>";
     }
 }
 /**
  * Show resource associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated resource must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_resources_haveRight('resources', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginResourcesResource');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_resources_resources_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_resources_resources`.`name` AS assocName,\n                       `glpi_plugin_resources_resources`.*\n                FROM `glpi_plugin_resources_resources_items`\n                LEFT JOIN `glpi_plugin_resources_resources`\n                 ON (`glpi_plugin_resources_resources_items`.`plugin_resources_resources_id`=`glpi_plugin_resources_resources`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_resources_resources`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_resources_resources_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_resources_resources_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_resources_resources", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $resources = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $resources[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     $resource = new PluginResourcesResource();
     $more = true;
     if ($item->getType() == "User" && $number != 0) {
         $more = false;
     }
     if ($canedit && $withtemplate < 2 && $more) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_resources_resources", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_resources_resources`\n               WHERE `is_deleted` = '0'\n               AND `is_template` = '0' ";
         if ($item->getType() != 'User') {
             $q .= " {$limit}";
         }
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_resources_haveRight('resources', 'r') && $nb > count($used)) {
             echo "<form name='resource_form{$rand}' id='resource_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginResourcesResource') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             PluginResourcesResource::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . __s('Associate a resource', 'resources') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('First name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . PluginResourcesContractType::getTypeName(1) . "</th>";
     echo "<th>" . PluginResourcesDepartment::getTypeName(1) . "</th>";
     echo "<th>" . __('Arrival date', 'resources') . "</th>";
     echo "<th>" . __('Departure date', 'resources') . "</th>";
     echo "</tr>";
     $used = array();
     $resourceID = 0;
     if ($number) {
         Session::initNavigateListItems('PluginResourcesResource', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($resources as $data) {
             $resourceID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($resource->getFromDB($resourceID)) {
                 $link = $resource->getLink();
             }
             Session::addToNavigateListItems('PluginResourcesResource', $resourceID);
             $used[$resourceID] = $resourceID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             echo "<td class='center'>" . $data['firstname'] . "</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_locations", $data["locations_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_resources_contracttypes", $data["plugin_resources_contracttypes_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_resources_departments", $data["plugin_resources_departments_id"]);
             echo "</td>";
             echo "<td class='center'>" . Html::convDate($data["date_begin"]) . "</td>";
             if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) {
                 echo "<td class='center'>";
                 echo "<span class='plugin_resources_date_color'>";
                 echo Html::convDate($data["date_end"]);
                 echo "</span>";
                 echo "</td>";
             } else {
                 if (empty($data["date_end"])) {
                     echo "<td class='center'>" . __('Not defined', 'resources') . "</td>";
                 } else {
                     echo "<td class='center'>" . Html::convDate($data["date_end"]) . "</td>";
                 }
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
     if ($item->getType() == "User") {
         $PluginResourcesEmployee = new PluginResourcesEmployee();
         $PluginResourcesEmployee->showForm($resourceID, $ID, 0);
     }
 }
Example #19
0
 static function showUsers(CommonDBTM $item)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_projet_haveRight('projet', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     $canread = $item->can($ID, 'r');
     $query = "SELECT `glpi_plugin_projet_projets`.* FROM `glpi_plugin_projet_projets` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_projet_projets`.`entities_id`) ";
     if ($item->getType() == 'User') {
         $query .= " WHERE `glpi_plugin_projet_projets`.`users_id` = '" . $ID . "' ";
     } else {
         $query .= " WHERE `glpi_plugin_projet_projets`.`groups_id` = '" . $ID . "' ";
     }
     $query .= "AND `glpi_plugin_projet_projets`.`is_template` = 0 " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', '', $item->maybeRecursive());
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($number > 0) {
         echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php\">";
         echo "<div align='center'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='" . (4 + $colsup) . "'>" . __('Responsible of projects', 'projet') . ":</th></tr>";
         echo "<tr><th>" . __('Name') . "</th>";
         if (Session::isMultiEntitiesMode()) {
             echo "<th>" . __('Entity') . "</th>";
         }
         echo "<th>" . __('Description') . "</th>";
         echo "<th>" . __('Progress') . "</th>";
         echo "</tr>";
         while ($data = $DB->fetch_array($result)) {
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] == '1' ? "_2" : "") . "'>";
             if ($canread && (in_array($data['entities_id'], $_SESSION['glpiactiveentities']) || $data["recursive"])) {
                 echo "<td class='center'><a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php?id=" . $data["id"] . "'>" . $data["name"];
                 if ($_SESSION["glpiis_ids_visible"]) {
                     echo " (" . $data["id"] . ")";
                 }
                 echo "</a></td>";
             } else {
                 echo "<td class='center'>" . $data["name"];
                 if ($_SESSION["glpiis_ids_visible"]) {
                     echo " (" . $data["id"] . ")";
                 }
                 echo "</td>";
             }
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>";
             echo "<td align='center'>" . $data["advance"] . " %</td>";
             echo "</tr>";
         }
         echo "</table></div>";
         Html::closeForm();
         echo "<br>";
     } else {
         echo "<div align='center'><table class='tab_cadre_fixe' style='text-align:center'>";
         echo "<tr><th>" . __('Responsible of projects', 'projet') . " - " . __('No item found');
         echo "</th></tr></table></div><br>";
     }
 }
 function showForm(CommonDBTM $item, $options = array())
 {
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     $rand = mt_rand();
     $a_data = getAllDatasFromTable('glpi_plugin_fusioninventory_ipranges_configsecurities', "`plugin_fusioninventory_ipranges_id`='" . $item->getID() . "'", false, '`rank`');
     $a_used = array();
     foreach ($a_data as $data) {
         $a_used[] = $data['plugin_fusioninventory_configsecurities_id'];
     }
     echo "<div class='firstbloc'>";
     echo "<form name='iprange_configsecurity_form{$rand}' id='iprange_configsecurity_form{$rand}' method='post'\n             action='" . Toolbox::getItemTypeFormURL('PluginFusioninventoryIPRange_ConfigSecurity') . "' >";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_2'>";
     echo "<th colspan='2'>" . __('Add a SNMP authentication') . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>";
     Dropdown::show('PluginFusioninventoryConfigSecurity', array('used' => $a_used));
     echo "</td>";
     echo "<td>";
     echo Html::hidden('plugin_fusioninventory_ipranges_id', array('value' => $item->getID()));
     echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate') . "\" class='submit'>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
     // Display list of auth associated with IP range
     $rand = mt_rand();
     echo "<div class='spaced'>";
     Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
     $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand);
     Html::showMassiveActions($massiveactionparams);
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_2'>";
     echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     echo "<th>";
     echo __('SNMP Authentication', 'fusioninventory');
     echo "</th>";
     echo "<th>";
     echo __('Version', 'fusioninventory');
     echo "</th>";
     echo "<th>";
     echo __('Rank');
     echo "</th>";
     echo "</tr>";
     $pfConfigSecurity = new PluginFusioninventoryConfigSecurity();
     foreach ($a_data as $data) {
         echo "<tr class='tab_bg_2'>";
         echo "<td>";
         Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
         echo "</td>";
         echo "<td>";
         $pfConfigSecurity->getFromDB($data['plugin_fusioninventory_configsecurities_id']);
         echo $pfConfigSecurity->getLink();
         echo "</td>";
         echo "<td>";
         echo $pfConfigSecurity->getSNMPVersion($pfConfigSecurity->fields['snmpversion']);
         echo "</td>";
         echo "<td>";
         echo $data['rank'];
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
     $massiveactionparams['ontop'] = false;
     Html::showMassiveActions($massiveactionparams);
     echo "</div>";
 }
   /**
    * Show certificates associated to an item
    *
    * @since version 0.84
    *
    * @param $item            CommonDBTM object for which associated certificates must be displayed
    * @param $withtemplate    (default '')
   **/
   static function showForItem(CommonDBTM $item, $withtemplate='') {
      global $DB, $CFG_GLPI;

      $ID = $item->getField('id');

      if ($item->isNewID($ID)) {
         return false;
      }
      if (!Session::haveRight("plugin_certificates", READ)) {
         return false;
      }

      if (!$item->can($item->fields['id'], READ)) {
         return false;
      }

      if (empty($withtemplate)) {
         $withtemplate = 0;
      }

      $canedit       =  $item->canadditem('PluginCertificatesCertificate');
      $rand          = mt_rand();
      $is_recursive  = $item->isRecursive();

      $query = "SELECT `glpi_plugin_certificates_certificates_items`.`id` AS assocID,
                       `glpi_entities`.`id` AS entity,
                       `glpi_plugin_certificates_certificates`.`name` AS assocName,
                       `glpi_plugin_certificates_certificates`.*
                FROM `glpi_plugin_certificates_certificates_items`
                LEFT JOIN `glpi_plugin_certificates_certificates`
                 ON (`glpi_plugin_certificates_certificates_items`.`plugin_certificates_certificates_id`=`glpi_plugin_certificates_certificates`.`id`)
                LEFT JOIN `glpi_entities` ON (`glpi_plugin_certificates_certificates`.`entities_id`=`glpi_entities`.`id`)
                WHERE `glpi_plugin_certificates_certificates_items`.`items_id` = '$ID'
                      AND `glpi_plugin_certificates_certificates_items`.`itemtype` = '".$item->getType()."' ";

      $query .= getEntitiesRestrictRequest(" AND","glpi_plugin_certificates_certificates",'','',true);

      $query .= " ORDER BY `assocName`";

      $result = $DB->query($query);
      $number = $DB->numrows($result);
      $i      = 0;

      $certificates      = array();
      $certificate       = new PluginCertificatesCertificate();
      $used      = array();
      if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
            $certificates[$data['assocID']] = $data;
            $used[$data['id']] = $data['id'];
         }
      }

      if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity   = $_SESSION["glpiactive_entity"];

         if ($item->isEntityAssign()) {
            /// Case of personal items : entity = -1 : create on active entity (Reminder case))
            if ($item->getEntityID() >=0 ) {
               $entity = $item->getEntityID();
            }

            if ($item->isRecursive()) {
               $entities = getSonsOf('glpi_entities',$entity);
            } else {
               $entities = $entity;
            }
         }
         $limit = getEntitiesRestrictRequest(" AND ","glpi_plugin_certificates_certificates",'',$entities,true);
         $q = "SELECT COUNT(*)
               FROM `glpi_plugin_certificates_certificates`
               WHERE `is_deleted` = '0'
               $limit";

         $result = $DB->query($q);
         $nb     = $DB->result($result,0,0);

         echo "<div class='firstbloc'>";       
         
         
         if (Session::haveRight("plugin_certificates", READ)
             && ($nb > count($used))) {
            echo "<form name='certificate_form$rand' id='certificate_form$rand' method='post'
                   action='".Toolbox::getItemTypeFormURL('PluginCertificatesCertificate')."'>";
            echo "<table class='tab_cadre_fixe'>";
            echo "<tr class='tab_bg_1'>";
            echo "<td colspan='4' class='center'>";
            echo "<input type='hidden' name='entities_id' value='$entity'>";
            echo "<input type='hidden' name='is_recursive' value='$is_recursive'>";
            echo "<input type='hidden' name='itemtype' value='".$item->getType()."'>";
            echo "<input type='hidden' name='items_id' value='$ID'>";
            if ($item->getType() == 'Ticket') {
               echo "<input type='hidden' name='tickets_id' value='$ID'>";
            }

            PluginCertificatesCertificate::dropdown(array('entity' => $entities ,
                                                            'used'   => $used));
                                     
            echo "</td><td class='center' width='20%'>";
            echo "<input type='submit' name='additem' value=\"".
                     _sx('button', 'Associate a certificate', 'certificates')."\" class='submit'>";
            echo "</td>";
            echo "</tr>";
            echo "</table>";
            Html::closeForm();
         }

         echo "</div>";
      }

      echo "<div class='spaced'>";
      if ($canedit && $number && ($withtemplate < 2)) {
         Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
         $massiveactionparams = array('num_displayed'  => $number);
         Html::showMassiveActions($massiveactionparams);
      }
      echo "<table class='tab_cadre_fixe'>";

      echo "<tr>";
      if ($canedit && $number && ($withtemplate < 2)) {
         echo "<th width='10'>".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)."</th>";
      }
      echo "<th>".__('Name')."</th>";
      if (Session::isMultiEntitiesMode()) {
         echo "<th>".__('Entity')."</th>";
      }
      echo "<th>".__('Type')."</th>";
      echo "<th>".__('DNS name', 'certificates')."</th>";
      echo "<th>".__('DNS suffix', 'certificates')."</th>";
      echo "<th>".__('Creation date')."</th>";
      echo "<th>".__('Expiration date')."</th>";
      echo "<th>".__('Status')."</th>";
      echo "</tr>";
      $used = array();

      if ($number) {

         Session::initNavigateListItems('PluginCertificatesCertificate',
                           //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'),
                                                $item->getTypeName(1), $item->getName()));

         
         foreach  ($certificates as $data) {
            $certificateID        = $data["id"];
            $link         = NOT_AVAILABLE;

            if ($certificate->getFromDB($certificateID)) {
               $link         = $certificate->getLink();
            }

            Session::addToNavigateListItems('PluginCertificatesCertificate', $certificateID);
            
            $used[$certificateID] = $certificateID;
            $assocID      = $data["assocID"];

            echo "<tr class='tab_bg_1".($data["is_deleted"]?"_2":"")."'>";
            if ($canedit && ($withtemplate < 2)) {
               echo "<td width='10'>";
               Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
               echo "</td>";
            }
            echo "<td class='center'>$link</td>";
            if (Session::isMultiEntitiesMode()) {
               echo "<td class='center'>".Dropdown::getDropdownName("glpi_entities", $data['entities_id']).
                    "</td>";
            }
            echo "<td class='center'>";
            echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatetypes",
                                          $data["plugin_certificates_certificatetypes_id"]);
            echo "</td>";
            echo "<td class='center'>".$data["dns_name"]."</td>";
            echo "<td class='center'>".$data["dns_suffix"]."</td>";
            echo "<td class='center'>".Html::convdate($data["date_query"])."</td>";
            if ($data["date_expiration"] <= date('Y-m-d') 
                  && !empty($data["date_expiration"])) {
               echo "<td class='center'>";
               echo "<div class='deleted'>".Html::convdate($data["date_expiration"])."</div>";
               echo "</td>";
            } else if (empty($data["date_expiration"])) {
               echo "<td class='center'>".__('Does not expire', 'certificates')."</td>";
            } else {
               echo "<td class='center'>".Html::convdate($data["date_expiration"])."</td>";
            }
            echo "<td class='center'>";
            echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatestates",
                                                $data["plugin_certificates_certificatestates_id"]);
            echo "</td>";
            echo "</tr>";
            $i++;
         }
      }


      echo "</table>";
      if ($canedit && $number && ($withtemplate < 2)) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
      }
      echo "</div>";
   }
 /**
  * @param $item    CommonDBTM object
  **/
 static function countForItem(CommonDBTM $item)
 {
     return countElementsInTable('glpi_contracts_items', "`itemtype` = '" . $item->getType() . "'\n                                   AND `items_id` ='" . $item->getField('id') . "'");
 }
 /**
  * Build an unicity error message
  *
  * @param $message the string to be display on the screen, or to be sent in a notification
  * @param $unicity the unicity criterion that failed to match
  * @param $doubles the items that are already present in DB
  **/
 function getUncityErrorMessage($message, $unicity, $doubles)
 {
     global $LANG;
     if ($unicity['action_refuse']) {
         $message_text = $LANG['setup'][813];
     } else {
         $message_text = $LANG['setup'][823];
     }
     $message_text .= " " . implode('&nbsp;&&nbsp;', $message);
     $message_text .= $LANG['setup'][818];
     foreach ($doubles as $double) {
         $doubles_text = array();
         if (in_array('CommonDBChild', class_parents($this))) {
             if ($this->getField($this->itemtype)) {
                 $item = new $double['itemtype']();
             } else {
                 $item = new $this->itemtype();
             }
             $item->getFromDB($double['items_id']);
         } else {
             $item = new CommonDBTM();
             $item->fields = $double;
         }
         foreach ($this->getUnicityFieldsToDisplayInErrorMessage() as $key => $value) {
             $field_value = $item->getField($key);
             if ($field_value != NOT_AVAILABLE) {
                 if (getTableNameForForeignKeyField($key) != '') {
                     $field_value = Dropdown::getDropdownName(getTableNameForForeignKeyField($key), $field_value);
                 }
                 $doubles_text[] = $value . ": " . $field_value;
             }
         }
         $message_text .= "<br>[" . implode(', ', $doubles_text) . "]";
     }
     return $message_text;
 }
 /**
  * Show webapplications associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated webapplications must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!Session::haveRight("plugin_webapplications", READ)) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginWebapplicationsWebapplication');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_webapplications_webapplications_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_webapplications_webapplications`.`name` AS assocName,\n                       `glpi_plugin_webapplications_webapplications`.*\n                FROM `glpi_plugin_webapplications_webapplications_items`\n                LEFT JOIN `glpi_plugin_webapplications_webapplications`\n                 ON (`glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id`=`glpi_plugin_webapplications_webapplications`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_webapplications_webapplications`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_webapplications_webapplications_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_webapplications_webapplications_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_webapplications_webapplications", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $webs = array();
     $web = new PluginWebapplicationsWebapplication();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $webs[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_webapplications_webapplications", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_webapplications_webapplications`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (Session::haveRight("plugin_webapplications", READ) && $nb > count($used)) {
             echo "<form name='webapplication_form{$rand}' id='webapplication_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginWebapplicationsWebapplication') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             PluginWebapplicationsWebapplication::dropdownWebapplication(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . __s('Associate a web application', 'webapplications') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . PluginWebapplicationsWebapplicationType::getTypeName(1) . "</th>";
     echo "<th>" . __('URL') . "</th>";
     echo "<th>" . __('Server') . "</th>";
     echo "<th>" . __('Language') . "</th>";
     echo "<th>" . __('Version') . "</th>";
     echo "<th>" . __('Comments') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginWebapplicationsWebapplication', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($webs as $data) {
             $webID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($web->getFromDB($webID)) {
                 $link = $web->getLink();
             }
             Session::addToNavigateListItems('PluginWebapplicationsWebapplication', $webID);
             $used[$webID] = $webID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtypes", $data["plugin_webapplications_webapplicationtypes_id"]) . "</td>";
             $link = Toolbox::substr($data["address"], 0, 30) . "...";
             echo "<td class='center'>" . "<a href=\"" . str_replace("&", "&amp;", $data["address"]) . "\" target=\"_blank\">" . "<u>" . $link . "</u></a></td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationservertypes", $data["plugin_webapplications_webapplicationservertypes_id"]) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtechnics", $data["plugin_webapplications_webapplicationtechnics_id"]) . "</td>";
             echo "<td>" . $data["version"] . "</td>";
             echo "<td>" . $data["comment"] . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Example #25
0
 /**
  * Show Infocom form for an item (not a standard showForm)
  *
  * @param $item                  CommonDBTM object
  * @param $withtemplate integer  template or basic item (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $CFG_GLPI;
     // Show Infocom or blank form
     if (!Session::haveRight("infocom", "r")) {
         return false;
     }
     if (!$item) {
         echo "<div class='spaced'>" . __('Requested item not found') . "</div>";
     } else {
         $date_tax = $CFG_GLPI["date_tax"];
         $dev_ID = $item->getField('id');
         $ic = new self();
         $option = "";
         if ($withtemplate == 2) {
             $option = " readonly ";
         }
         if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) {
             echo "<div class='firstbloc center'>" . __('For this type of item, the financial and administrative information are only a model for the items which you should add.') . "</div>";
         }
         if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) {
             $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID());
             if ($ic->can(-1, "w", $input) && $withtemplate != 2) {
                 echo "<div class='spaced b'>";
                 echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>";
                 echo sprintf(__('%1$s - %2$s'), $item->getTypeName(1), $item->getName()) . "</th></tr>";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/infocom.form.php", 'add', __('Enable the financial and administrative information'), array('itemtype' => $item->getType(), 'items_id' => $dev_ID));
                 echo "</td></tr></table></div>";
             }
         } else {
             // getFromDBforDevice
             $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2;
             if ($canedit) {
                 echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>";
             }
             echo "<div class='spaced'>";
             echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>";
             echo "<tr><th colspan='4'>" . __('Financial and administrative information') . "</th></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Supplier') . "</td>";
             echo "<td>";
             if ($withtemplate == 2) {
                 echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]);
             } else {
                 Supplier::dropdown(array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID()));
             }
             echo "</td>";
             if (Session::haveRight("budget", "r")) {
                 echo "<td>" . __('Budget') . "</td><td >";
                 Budget::dropdown(array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1));
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td></tr>";
             // Can edit calendar ?
             $editcalendar = $withtemplate != 2;
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Order number') . "</td>";
             echo "<td >";
             Html::autocompletionTextField($ic, "order_number", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Order date') . "</td><td>";
             Html::showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             $istemplate = '';
             if ($item->isTemplate() || in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) {
                 $istemplate = '*';
             }
             echo "<td>" . sprintf(__('%1$s%2$s'), __('Immobilization number'), $istemplate) . "</td>";
             echo "<td>";
             $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID());
             Html::autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option));
             echo "</td>";
             echo "<td>" . __('Date of purchase') . "</td><td>";
             Html::showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Invoice number') . "</td>";
             echo "<td>";
             Html::autocompletionTextField($ic, "bill", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Delivery date') . "</td><td>";
             Html::showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Delivery form') . "</td><td>";
             Html::autocompletionTextField($ic, "delivery_number", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Startup date') . "</td><td>";
             Html::showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Value') . "</td>";
             echo "<td><input type='text' name='value' {$option} value='" . Html::formatNumber($ic->fields["value"], true) . "' size='14'></td>";
             echo "</td>";
             echo "<td>" . __('Date of last physical inventory') . "</td><td>";
             Html::showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Warranty extension value') . "</td>";
             echo "<td><input type='text' {$option} name='warranty_value' value='" . Html::formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>";
             echo "<td rowspan='5'>" . __('Comments') . "</td>";
             echo "<td rowspan='5' class='middle'>";
             echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"];
             echo "</textarea></td></tr>\n";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Account net value') . "</td><td>";
             echo Html::formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n"));
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization type') . "</td><td >";
             if ($withtemplate == 2) {
                 echo self::getAmortTypeName($ic->fields["sink_type"]);
             } else {
                 self::dropdownAmortType("sink_type", $ic->fields["sink_type"]);
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization duration') . "</td><td>";
             if ($withtemplate == 2) {
                 printf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]);
             } else {
                 Dropdown::showNumber("sink_time", array('value' => $ic->fields["sink_time"], 'max' => 15, 'unit' => 'year'));
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization coefficient') . "</td>";
             echo "<td>";
             Html::autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option));
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) {
                 echo "<td>" . __('TCO (value + tracking cost)') . "</td><td>";
                 echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]);
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td>";
             if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) {
                 echo "<td>" . __('Monthly TCO') . "</td><td>";
                 echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]);
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td></tr>";
             echo "<tr><th colspan='4'>" . __('Warranty information') . "</th></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Start date of warranty') . "</td><td>";
             Html::showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar);
             echo "</td>";
             echo "<td>" . __('Warranty duration') . "</td><td>";
             if ($withtemplate == 2) {
                 // -1 = life
                 if ($ic->fields["warranty_duration"] == -1) {
                     _e('Lifelong');
                 } else {
                     printf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]);
                 }
             } else {
                 Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => __('Lifelong')), array('unit' => 'month'));
             }
             $tmpdat = self::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"], 0, true);
             if ($tmpdat) {
                 echo "<span class='small_space'>" . sprintf(__('Valid to %s'), $tmpdat) . "</span>";
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Warranty information') . "</td>";
             echo "<td >";
             Html::autocompletionTextField($ic, "warranty_info", array('option' => $option));
             echo "</td>";
             if ($CFG_GLPI['use_mailing']) {
                 echo "<td>" . __('Alarms on financial and administrative information') . "</td>";
                 echo "<td>";
                 self::dropdownAlert(array('name' => "alert", 'value' => $ic->fields["alert"]));
                 Alert::displayLastAlert('Infocom', $ic->fields['id']);
                 echo "</td>";
             } else {
                 echo "</td><td colspan='2'>";
             }
             echo "</td></tr>";
             if ($canedit) {
                 echo "<tr>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>";
                 echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n                      class='submit'>";
                 echo "</td>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='submit' name='delete' value=\"" . _sx('button', 'Delete permanently') . "\"\n                      class='submit'>";
                 echo "</td></tr>";
                 echo "</table></div>";
                 Html::closeForm();
             } else {
                 echo "</table></div>";
             }
         }
     }
 }
Example #26
0
 /**
  * Retrieve last history Data for an item
  *
  * @param $item                     CommonDBTM object
  * @param $start        integer     first line to retrieve (default 0)
  * @param $limit        integer     max number of line to retrive (0 for all) (default 0)
  * @param $sqlfilter    string      to add an SQL filter (default '')
  *
  * @return array of localized log entry (TEXT only, no HTML)
  **/
 static function getHistoryData(CommonDBTM $item, $start = 0, $limit = 0, $sqlfilter = '')
 {
     global $DB;
     $itemtype = $item->getType();
     $items_id = $item->getField('id');
     $itemtable = $item->getTable();
     $SEARCHOPTION = Search::getOptions($itemtype);
     $query = "SELECT *\n                FROM `glpi_logs`\n                WHERE `items_id` = '{$items_id}'\n                      AND `itemtype` = '{$itemtype}' ";
     if ($sqlfilter) {
         $query .= "AND ({$sqlfilter}) ";
     }
     $query .= "ORDER BY `id` DESC";
     if ($limit) {
         $query .= " LIMIT " . intval($start) . "," . intval($limit);
     }
     $changes = array();
     foreach ($DB->request($query) as $data) {
         $tmp = array();
         $tmp['display_history'] = true;
         $tmp['id'] = $data["id"];
         $tmp['date_mod'] = Html::convDateTime($data["date_mod"]);
         $tmp['user_name'] = $data["user_name"];
         $tmp['field'] = "";
         $tmp['change'] = "";
         $tmp['datatype'] = "";
         // This is an internal device ?
         if ($data["linked_action"]) {
             // Yes it is an internal device
             switch ($data["linked_action"]) {
                 case self::HISTORY_CREATE_ITEM:
                     $tmp['change'] = __('Add the item');
                     break;
                 case self::HISTORY_DELETE_ITEM:
                     $tmp['change'] = __('Delete the item');
                     break;
                 case self::HISTORY_LOCK_ITEM:
                     $tmp['change'] = __('Lock the item');
                     break;
                 case self::HISTORY_UNLOCK_ITEM:
                     $tmp['change'] = __('Unlock the item');
                     break;
                 case self::HISTORY_RESTORE_ITEM:
                     $tmp['change'] = __('Restore the item');
                     break;
                 case self::HISTORY_ADD_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     //TRANS: %s is the component name
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Add the component'), $data["new_value"]);
                     break;
                 case self::HISTORY_UPDATE_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     $change = '';
                     $linktype_field = explode('#', $data["itemtype_link"]);
                     $linktype = $linktype_field[0];
                     $field = $linktype_field[1];
                     $devicetype = $linktype::getDeviceType();
                     $tmp['field'] = $devicetype;
                     $specif_fields = $linktype::getSpecificities();
                     if (isset($specif_fields[$field]['short name'])) {
                         $tmp['field'] = $devicetype;
                         $tmp['field'] .= " (" . $specif_fields[$field]['short name'] . ")";
                     }
                     //TRANS: %1$s is the old_value, %2$s is the new_value
                     $tmp['change'] = sprintf(__('Change the component %1$s: %2$s'), $tmp['field'], sprintf(__('%1$s by %2$s'), $data["old_value"], $data["new_value"]));
                     break;
                 case self::HISTORY_DELETE_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     //TRANS: %s is the component name
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Delete the component'), $data["old_value"]);
                     break;
                 case self::HISTORY_LOCK_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     //TRANS: %s is the component name
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Lock the component'), $data["old_value"]);
                     break;
                 case self::HISTORY_UNLOCK_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     //TRANS: %s is the component name
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Unlock the component'), $data["new_value"]);
                     break;
                 case self::HISTORY_INSTALL_SOFTWARE:
                     $tmp['field'] = _n('Software', 'Software', 1);
                     //TRANS: %s is the software name
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Install the software'), $data["new_value"]);
                     break;
                 case self::HISTORY_UNINSTALL_SOFTWARE:
                     $tmp['field'] = _n('Software', 'Software', 1);
                     //TRANS: %s is the software name
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Uninstall the software'), $data["old_value"]);
                     break;
                 case self::HISTORY_DISCONNECT_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     //TRANS: %s is the item name
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Disconnect the item'), $data["old_value"]);
                     break;
                 case self::HISTORY_CONNECT_DEVICE:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     //TRANS: %s is the item name
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Connect the item'), $data["new_value"]);
                     break;
                 case self::HISTORY_LOG_SIMPLE_MESSAGE:
                     $tmp['field'] = "";
                     $tmp['change'] = $data["new_value"];
                     break;
                 case self::HISTORY_ADD_RELATION:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Add a link with an item'), $data["new_value"]);
                     break;
                 case self::HISTORY_DEL_RELATION:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Delete a link with an item'), $data["old_value"]);
                     break;
                 case self::HISTORY_LOCK_RELATION:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Lock a link with an item'), $data["old_value"]);
                     break;
                 case self::HISTORY_UNLOCK_RELATION:
                     $tmp['field'] = NOT_AVAILABLE;
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Unlock a link with an item'), $data["new_value"]);
                     break;
                 case self::HISTORY_ADD_SUBITEM:
                     $tmp['field'] = '';
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Add the item'), sprintf(__('%1$s (%2$s)'), $tmp['field'], $data["new_value"]));
                     break;
                 case self::HISTORY_UPDATE_SUBITEM:
                     $tmp['field'] = '';
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Update the item'), sprintf(__('%1$s (%2$s)'), $tmp['field'], $data["new_value"]));
                     break;
                 case self::HISTORY_DELETE_SUBITEM:
                     $tmp['field'] = '';
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Delete the item'), sprintf(__('%1$s (%2$s)'), $tmp['field'], $data["old_value"]));
                     break;
                 case self::HISTORY_LOCK_SUBITEM:
                     $tmp['field'] = '';
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Lock an item'), sprintf(__('%1$s (%2$s)'), $tmp['field'], $data["old_value"]));
                     break;
                 case self::HISTORY_UNLOCK_SUBITEM:
                     $tmp['field'] = '';
                     if ($item2 = getItemForItemtype($data["itemtype_link"])) {
                         $tmp['field'] = $item2->getTypeName(1);
                     }
                     $tmp['change'] = sprintf(__('%1$s: %2$s'), __('Unlock an item'), sprintf(__('%1$s (%2$s)'), $tmp['field'], $data["new_value"]));
                     break;
                 default:
                     $fct = array($data['itemtype_link'], 'getHistoryEntry');
                     if ($data['linked_action'] >= self::HISTORY_PLUGIN && $data['itemtype_link'] && is_callable($fct)) {
                         $tmp['field'] = $data['itemtype_link']::getTypeName(1);
                         $tmp['change'] = call_user_func($fct, $data);
                     }
                     $tmp['display_history'] = !empty($tmp['change']);
             }
         } else {
             $fieldname = "";
             $searchopt = array();
             $tablename = '';
             // It's not an internal device
             foreach ($SEARCHOPTION as $key2 => $val2) {
                 if ($key2 == $data["id_search_option"]) {
                     $tmp['field'] = $val2["name"];
                     $tablename = $val2["table"];
                     $fieldname = $val2["field"];
                     $searchopt = $val2;
                     if (isset($val2['datatype'])) {
                         $tmp['datatype'] = $val2["datatype"];
                     }
                     break;
                 }
             }
             if ($itemtable == $tablename) {
                 switch ($tmp['datatype']) {
                     // specific case for text field
                     case 'text':
                         $tmp['change'] = __('Update of the field');
                         break;
                     default:
                         $data["old_value"] = $item->getValueToDisplay($searchopt, $data["old_value"]);
                         $data["new_value"] = $item->getValueToDisplay($searchopt, $data["new_value"]);
                         break;
                 }
             }
             if (empty($tmp['change'])) {
                 $tmp['change'] = sprintf(__('Change %1$s by %2$s'), $data["old_value"], $data["new_value"]);
             }
         }
         $changes[] = $tmp;
     }
     return $changes;
 }
Example #27
0
 /**
  * @param CommonDBTM $item
  **/
 static function countForItem(CommonDBTM $item)
 {
     return countElementsInTable('glpi_networkports', "`itemtype` = '" . $item->getType() . "'\n                                      AND `items_id` ='" . $item->getField('id') . "'\n                                      AND `is_deleted` = '0'");
 }
Example #28
0
 /**
  * Get documents associated to an item
  *
  * @param $item            CommonDBTM object for which associated documents must be displayed
  * @param $withtemplate    (default '')
  **/
 static function getAssociatedDocuments(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (!($item instanceof KnowbaseItem && $CFG_GLPI["use_public_faq"] && !$item->getEntityID())) {
         if ($item->isNewID($item->getField('id'))) {
             return array();
         }
         switch ($item->getType()) {
             case 'Ticket':
             case 'KnowbaseItem':
                 break;
             default:
                 if (Session::haveRight('document', READ)) {
                     return array();
                 }
         }
         if (!$item->can($item->fields['id'], READ)) {
             return array();
         }
     }
     $query = "SELECT `glpi_documents_items`.`id` as assocID,\n                       `glpi_documents`.*\n                FROM `glpi_documents_items`\n                LEFT JOIN `glpi_documents`\n                          ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'\n                      AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
     if (Session::getLoginUserID()) {
         $query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
     } else {
         // Anonymous access from FAQ
         $query .= " AND `glpi_documents`.`entities_id`= '0' ";
     }
     $docs = array();
     foreach ($DB->request($query) as $data) {
         $docs[] = $data;
     }
     return $docs;
 }
 /**
  * @param $item   CommonDBTM object
  **/
 static function countForItem(CommonDBTM $item)
 {
     $restrict = "`glpi_items_problems`.`problems_id` = `glpi_problems`.`id`\n                   AND `glpi_items_problems`.`items_id` = '" . $item->getField('id') . "'\n                   AND `glpi_items_problems`.`itemtype` = '" . $item->getType() . "'" . getEntitiesRestrictRequest(" AND ", "glpi_problems", '', '', true);
     $nb = countElementsInTable(array('glpi_items_problems', 'glpi_problems'), $restrict);
     return $nb;
 }
 /**
  * Contruct parameters restriction for listInventoryObjects sql request
  *
  * @param $params    the input parameters
  * @param $item      CommonDBTM object
  * @param $table
  * @param $where
  **/
 static function listInventoryObjectsRequestParameters($params, CommonDBTM $item, $table, $where = "WHERE 1")
 {
     $already_used = array();
     foreach ($params as $key => $value) {
         //Key representing the FK associated with the _name value
         $key_transformed = preg_replace("/_name/", "s_id", $key);
         $fk_table = getTableNameForForeignKeyField($key);
         $option = $item->getSearchOptionByField('field', $key_transformed);
         if (!empty($option)) {
             if (!in_array($key, $already_used) && isset($params[$key]) && $params[$key] && ($item->getField($option['linkfield']) != NOT_AVAILABLE || $item->getField($option['field']) != NOT_AVAILABLE)) {
                 if (getTableNameForForeignKeyField($key)) {
                     $where .= " AND `{$table}`.`{$key}`='" . Toolbox::addslashes_deep($params[$key]) . "'";
                 } else {
                     //
                     if ($key != $key_transformed || $table != $option['table']) {
                         $where .= " AND `" . Toolbox::addslashes_deep($option['table']) . "`.`" . Toolbox::addslashes_deep($option['field']) . "`\n                                    LIKE '%" . Toolbox::addslashes_deep($params[$key]) . "%'";
                     } else {
                         $where .= " AND `{$table}`.`{$key}`\n                                    LIKE '%" . Toolbox::addslashes_deep($params[$key]) . "%'";
                     }
                 }
                 $already_used[] = $key;
             }
         }
     }
     return $where;
 }