Inheritance: extends CommonDBChild
 /**
  * @param $computers_id
  * @param $date
  * @param $computer_updates
  * @return array
  */
 static function addInfocomsForComputer($computers_id, $date, $computer_updates)
 {
     global $DB;
     $infocom = new Infocom();
     $use_date = substr($date, 0, 10);
     if ($infocom->getFromDBByQuery("WHERE `items_id` = {$computers_id} AND `itemtype` = 'Computer'")) {
         if (empty($infocom->fields['use_date']) || $infocom->fields['use_date'] == 'NULL') {
             //add use_date
             $infocom->update(array('id' => $infocom->fields['id'], 'use_date' => $use_date));
         }
     } else {
         //add infocom
         $infocom->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'use_date' => $use_date));
     }
     //Add lock
     $ocslink = new PluginOcsinventoryngOcslink();
     if ($ocslink->getFromDBforComputer($computers_id)) {
         $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($ocslink->fields["plugin_ocsinventoryng_ocsservers_id"]);
         if ($cfg_ocs["use_locks"]) {
             $computer_updates[] = "use_date";
             $query = "UPDATE `glpi_plugin_ocsinventoryng_ocslinks`\n                         SET `computer_update` = '" . addslashes(exportArrayToDB($computer_updates)) . "'\n                         WHERE `computers_id` = '{$computers_id}'";
             $DB->query($query);
         }
     }
     return $computer_updates;
 }
 function post_addItem()
 {
     global $CFG_GLPI;
     $itemtype = 'Software';
     $dupid = $this->fields["softwares_id"];
     if (isset($this->input["_duplicate_license"])) {
         $itemtype = 'SoftwareLicense';
         $dupid = $this->input["_duplicate_license"];
     }
     // Add infocoms if exists for the licence
     $ic = new Infocom();
     $ic->cloneItem('Software', $dupid, $this->fields['id'], $this->getType());
 }
示例#3
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();
 }
 /**
  * Transfer infocoms of an item
  *
  * @param $itemtype type of the item to transfer
  * @param $ID original ID of the item
  * @param $newID new ID of the item
  **/
 function transferInfocoms($itemtype, $ID, $newID)
 {
     global $DB;
     $ic = new Infocom();
     if ($ic->getFromDBforDevice($itemtype, $ID)) {
         switch ($this->options['keep_infocom']) {
             // delete
             case 0:
                 // Same item -> delete
                 if ($ID == $newID) {
                     $query = "DELETE\n                            FROM `glpi_infocoms`\n                            WHERE `itemtype` = '{$itemtype}'\n                                  AND `items_id` = '{$ID}'";
                     $result = $DB->query($query);
                 }
                 // Copy : nothing to do
                 break;
                 // Keep
             // Keep
             default:
                 // Transfer enterprise
                 $suppliers_id = 0;
                 if ($ic->fields['suppliers_id'] > 0) {
                     $suppliers_id = $this->transferSingleSupplier($ic->fields['suppliers_id']);
                 }
                 // Copy : copy infocoms
                 if ($ID != $newID) {
                     // Copy items
                     $input = $ic->fields;
                     $input['items_id'] = $newID;
                     $input['suppliers_id'] = $suppliers_id;
                     unset($input['id']);
                     unset($ic->fields);
                     $ic->add($input);
                 } else {
                     // Same Item : manage only enterprise move
                     // Update enterprise
                     if ($suppliers_id > 0 && $suppliers_id != $ic->fields['suppliers_id']) {
                         $ic->update(array('id' => $ic->fields['id'], 'suppliers_id' => $suppliers_id));
                     }
                 }
                 break;
         }
     }
 }
示例#5
0
 static function saveInfocoms($options)
 {
     //valeurs d'origine
     $warranty_date = "";
     $buy_date = "";
     $warranty_duration = "";
     $suppliers_id = "";
     $ic_comments = "";
     //nouvelles valeurs
     $input_infocom = array();
     if ($options["supplierId"] != 0) {
         $input_infocom["suppliers_id"] = $options["supplierId"];
     }
     $input_infocom["warranty_date"] = $options["maDate"];
     $input_infocom["warranty_duration"] = $options["warranty"];
     $input_infocom["buy_date"] = $options["maDate"];
     $input_infocom["items_id"] = $options["ID"];
     $input_infocom["itemtype"] = $options["itemtype"];
     //add new infocoms
     $ic = new infocom();
     if ($ic->getfromDBforDevice($options["itemtype"], $options["ID"])) {
         //valeurs d'origine
         $warranty_date = Html::convdate($ic->fields["warranty_date"]);
         $warranty_duration = $ic->fields["warranty_duration"];
         $buy_date = $ic->fields["buy_date"];
         $suppliers_id = Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]);
         $ic_comment = $ic->fields["comment"];
         //nouvelles valeurs
         $input_infocom["id"] = $ic->fields["id"];
         if ($options["addcomments"]) {
             $input_infocom["comment"] = $ic_comment . "\n" . __('Imported from web site', 'manufacturersimports') . " " . $options["suppliername"] . " " . __('With the manufacturersimports plugin', 'manufacturersimports') . " (" . Html::convdate($options["date"]) . ")";
         }
         $infocom = new Infocom();
         $infocom->update($input_infocom);
     } else {
         if ($options["addcomments"]) {
             $input_infocom["comment"] = __('Imported from web site', 'manufacturersimports') . " " . $options["suppliername"] . " " . __('With the manufacturersimports plugin', 'manufacturersimports') . " (" . Html::convdate($options["date"]) . ")";
         }
         $infocom = new Infocom();
         $infocom->add($input_infocom);
     }
     //post message
     echo "<td><span class='plugin_manufacturersimports_import_OK'>";
     echo __('Import OK', 'manufacturersimports') . " (" . Html::convdate($options["date"]) . ")";
     echo "</span></td>";
     echo "<td>";
     echo _n('Supplier', 'Suppliers', 1) . ": ";
     echo $suppliers_id . "->" . Dropdown::getDropdownName("glpi_suppliers", $options["supplierId"]) . "<br>";
     echo __('Date of purchase') . ": ";
     echo Html::convdate($buy_date) . "->" . Html::convdate($options["maDate"]) . "<br>";
     echo __('Start date of warranty') . ": ";
     echo $warranty_date . "->" . Html::convdate($options["maDate"]) . "<br>";
     if ($warranty_duration == -1) {
         $warranty_duration = __('Lifelong');
         $warranty = __('Lifelong');
     } else {
         $warranty = $options["warranty"];
     }
     echo __('Warranty duration') . ": " . $warranty_duration . "->" . $warranty . "<br>";
     echo "</td>";
 }
 function post_addItem()
 {
     global $DB, $CFG_GLPI;
     // Manage add from template
     if (isset($this->input["_oldID"])) {
         // ADD Devices
         Item_devices::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Infocoms
         Infocom::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Ports
         NetworkPort::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Contract
         Contract_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Documents
         Document_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Computers
         Computer_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
     }
 }
示例#7
0
 function post_addItem()
 {
     global $DB;
     // Manage add from template
     if (isset($this->input["_oldID"])) {
         // ADD Devices
         Item_devices::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Infocoms
         Infocom::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD volumes
         ComputerDisk::cloneComputer($this->input["_oldID"], $this->fields['id']);
         // ADD software
         Computer_SoftwareVersion::cloneComputer($this->input["_oldID"], $this->fields['id']);
         Computer_SoftwareLicense::cloneComputer($this->input["_oldID"], $this->fields['id']);
         // ADD Contract
         Contract_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Documents
         Document_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Ports
         NetworkPort::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // Add connected devices
         Computer_Item::cloneComputer($this->input["_oldID"], $this->fields['id']);
     }
 }
 function post_addItem()
 {
     // Manage add from template
     if (isset($this->input["_oldID"])) {
         // ADD Documents
         Document_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
         // ADD Infocoms
         Infocom::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
     }
 }
示例#9
0
 /**
  * to list infos in debug tab
  **/
 function showDebugInfo()
 {
     global $CFG_GLPI;
     $class = $this->getType();
     if (method_exists($class, 'showDebug')) {
         $this->showDebug();
     }
     if (InfoCom::canApplyOn($class)) {
         $infocom = new Infocom();
         if ($infocom->getFromDBforDevice($class, $this->fields['id'])) {
             $infocom->showDebug();
         }
     }
     if (in_array($class, $CFG_GLPI["reservation_types"])) {
         $resitem = new ReservationItem();
         if ($resitem->getFromDBbyItem($class, $this->fields['id'])) {
             $resitem->showDebugResa();
         }
     }
 }
/** Generate bigdump : add infocoms to an item
 *
 * @param $type            item type
 * @param $ID              item ID
 * @param $ID_entity       entity ID
 * @param $is_recursive    (default 0)
**/
function addInfocoms($type, $ID, $ID_entity, $is_recursive=0) {
   global $DB, $FIRST, $LAST;

   $current_year = date('Y');

   $orderdate     = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
   $buydate       = $orderdate+mt_rand(0, 60)*DAY_TIMESTAMP;
   $deliverydate  = $orderdate+mt_rand(0, 60)*DAY_TIMESTAMP;
   $usedate       = $deliverydate+mt_rand(0, 60)*DAY_TIMESTAMP;
   $warrantydate  = $deliverydate;
   $inventorydate = $deliverydate;

   $orderdate     = date("Y-m-d", intval($orderdate));
   $buydate       = date("Y-m-d", intval($buydate));
   $deliverydate  = date("Y-m-d", intval($deliverydate));
   $usedate       = date("Y-m-d", intval($usedate));
   $warrantydate  = date("Y-m-d", intval($warrantydate));
   $inventorydate = date("Y-m-d", intval($inventorydate));

   $i = new Infocom();
   $i->add(toolbox::addslashes_deep(
           array('itemtype'           => $type,
                  'items_id'          => $ID,
                  'entities_id'       => $ID_entity,
                  'is_recursive'      => $is_recursive,
                  'buy_date'          => $buydate,
                  'use_date'          => $usedate,
                  'warranty_duration' => mt_rand(12,36),
                  'warranty_info'     => "infowar ' $type $ID",
                  'suppliers_id'      => mt_rand($FIRST["enterprises"], $LAST['enterprises']),
                  'order_number'      => "commande ' $type $ID",
                  'delivery_number'   => "BL ' $type $ID",
                  'immo_number'       => "immo ' $type $ID",
                  'value'             => mt_rand(0,5000),
                  'warranty_value'    => mt_rand(0,500),
                  'sink_time'         => mt_rand(1,7),
                  'sink_type'         => mt_rand(1,2),
                  'sink_coeff'        => mt_rand(2,5),
                  'comment'           => "comment ' $type $ID",
                  'bill'              => "bill ' $type $ID",
                  'budgets_id'        => mt_rand($FIRST['budget'], $LAST['budget']),
                  'order_date'        => $orderdate,
                  'delivery_date'     => $deliverydate,
                  'inventory_date'    => $inventorydate,
                  'warranty_date'     => $warrantydate)));
}
示例#11
0
/** Display an infocom report
 *
 * @param $itemtype item type
 * @param $begin begin date
 * @param $end end date
**/
function display_infocoms_report($itemtype, $begin, $end)
{
    global $DB, $valeurtot, $valeurnettetot, $valeurnettegraphtot, $valeurgraphtot, $LANG, $CFG_GLPI;
    $itemtable = getTableForItemType($itemtype);
    $query = "SELECT `glpi_infocoms`.*,\n                    `{$itemtable}`.`name` AS name,\n                    `{$itemtable}`.`ticket_tco`,\n                    `glpi_entities`.`completename` AS entname,\n                    `glpi_entities`.`id` AS entID\n             FROM `glpi_infocoms`\n             INNER JOIN `{$itemtable}` ON (`{$itemtable}`.`id` = `glpi_infocoms`.`items_id`\n                                         AND `glpi_infocoms`.`itemtype` = '{$itemtype}')\n             LEFT JOIN `glpi_entities` ON (`{$itemtable}`.`entities_id` = `glpi_entities`.`id`)\n             WHERE `{$itemtable}`.`is_template` = '0' " . getEntitiesRestrictRequest("AND", $itemtable);
    if (!empty($begin)) {
        $query .= " AND (`glpi_infocoms`.`buy_date` >= '{$begin}'\n                       OR `glpi_infocoms`.`use_date` >= '{$begin}') ";
    }
    if (!empty($end)) {
        $query .= " AND (`glpi_infocoms`.`buy_date` <= '{$end}'\n                       OR `glpi_infocoms`.`use_date` <= '{$end}') ";
    }
    $query .= " ORDER BY entname ASC, `buy_date`, `use_date`";
    $display_entity = isMultiEntitiesMode();
    $result = $DB->query($query);
    if ($DB->numrows($result) > 0) {
        $item = new $itemtype();
        echo "<h2>" . $item->getTypeName() . "</h2>";
        echo "<table class='tab_cadre'><tr><th>" . $LANG['common'][16] . "</th>";
        if ($display_entity) {
            echo "<th>" . $LANG['entity'][0] . "</th>";
        }
        echo "<th>" . $LANG['financial'][21] . "</th><th>" . $LANG['financial'][92] . "</th>";
        echo "<th>" . $LANG['financial'][91] . "</th><th>" . $LANG['financial'][14] . "</th>";
        echo "<th>" . $LANG['financial'][76] . "</th><th>" . $LANG['financial'][80] . "</th></tr>";
        $valeursoustot = 0;
        $valeurnettesoustot = 0;
        $valeurnettegraph = array();
        $valeurgraph = array();
        while ($line = $DB->fetch_array($result)) {
            if (isset($line["is_global"]) && $line["is_global"]) {
                $line["value"] *= Computer_Item::countForItem($itemtype, $line["items_id"]);
            }
            if ($line["value"] > 0) {
                $valeursoustot += $line["value"];
            }
            $valeurnette = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "n");
            $tmp = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "all");
            if (is_array($tmp) && count($tmp) > 0) {
                foreach ($tmp["annee"] as $key => $val) {
                    if ($tmp["vcnetfin"][$key] > 0) {
                        if (!isset($valeurnettegraph[$val])) {
                            $valeurnettegraph[$val] = 0;
                        }
                        $valeurnettegraph[$val] += $tmp["vcnetdeb"][$key];
                    }
                }
            }
            if (!empty($line["buy_date"])) {
                $year = substr($line["buy_date"], 0, 4);
                if ($line["value"] > 0) {
                    if (!isset($valeurgraph[$year])) {
                        $valeurgraph[$year] = 0;
                    }
                    $valeurgraph[$year] += $line["value"];
                }
            }
            $valeurnettesoustot += str_replace(" ", "", $valeurnette);
            echo "<tr class='tab_bg_1'><td>" . $line["name"] . "</td>";
            if ($display_entity) {
                if ($line['entID'] == 0) {
                    echo "<td>" . $LANG['entity'][2] . "</td>";
                } else {
                    echo "<td>" . $line['entname'] . "</td>";
                }
            }
            echo "<td class='right'>" . formatNumber($line["value"]) . "</td><td class='right'>" . formatNumber($valeurnette) . "</td><td class='right'>" . Infocom::showTco($line["ticket_tco"], $line["value"]) . "</td><td>" . convDate($line["buy_date"]) . "</td><td>" . convDate($line["use_date"]) . "</td><td>" . getWarrantyExpir($line["buy_date"], $line["warranty_duration"]) . "</td></tr>";
        }
        $valeurtot += $valeursoustot;
        $valeurnettetot += $valeurnettesoustot;
        echo "<tr><td colspan='6' class='center'><h3>" . $LANG['common'][33] . "&nbsp;: " . $LANG['financial'][21] . "=" . formatNumber($valeursoustot) . " - " . $LANG['financial'][81] . "=" . formatNumber($valeurnettesoustot) . "</h3></td></tr>";
        if (count($valeurnettegraph) > 0) {
            echo "<tr><td colspan='5' class='center'>";
            ksort($valeurnettegraph);
            $valeurnettegraphdisplay = array_map('round', $valeurnettegraph);
            foreach ($valeurnettegraph as $key => $val) {
                if (!isset($valeurnettegraphtot[$key])) {
                    $valeurnettegraphtot[$key] = 0;
                }
                $valeurnettegraphtot[$key] += $valeurnettegraph[$key];
            }
            Stat::showGraph(array($LANG['financial'][81] => $valeurnettegraphdisplay), array('title' => $LANG['financial'][81], 'width' => 400));
            echo "</td></tr>";
        }
        if (count($valeurgraph) > 0) {
            echo "<tr><td colspan='5' class='center'>";
            ksort($valeurgraph);
            $valeurgraphdisplay = array_map('round', $valeurgraph);
            foreach ($valeurgraph as $key => $val) {
                if (!isset($valeurgraphtot[$key])) {
                    $valeurgraphtot[$key] = 0;
                }
                $valeurgraphtot[$key] += $valeurgraph[$key];
            }
            Stat::showGraph(array($LANG['financial'][21] => $valeurgraphdisplay), array('title' => $LANG['financial'][21], 'width' => 400));
            echo "</td></tr>";
        }
        echo "</table>";
        return true;
    }
    return false;
}
示例#12
0
/** Display an infocom report
 *
 * @param $itemtype  item type
 * @param $begin     begin date
 * @param $end       end date
**/
function display_infocoms_report($itemtype, $begin, $end)
{
    global $DB, $valeurtot, $valeurnettetot, $valeurnettegraphtot, $valeurgraphtot, $CFG_GLPI;
    $itemtable = getTableForItemType($itemtype);
    $query = "SELECT `glpi_infocoms`.*,\n                    `{$itemtable}`.`name` AS name,\n                    `{$itemtable}`.`ticket_tco`,\n                    `glpi_entities`.`completename` AS entname,\n                    `glpi_entities`.`id` AS entID\n             FROM `glpi_infocoms`\n             INNER JOIN `{$itemtable}` ON (`{$itemtable}`.`id` = `glpi_infocoms`.`items_id`\n                                         AND `glpi_infocoms`.`itemtype` = '{$itemtype}')\n             LEFT JOIN `glpi_entities` ON (`{$itemtable}`.`entities_id` = `glpi_entities`.`id`)\n             WHERE `{$itemtable}`.`is_template` = '0' " . getEntitiesRestrictRequest("AND", $itemtable);
    if (!empty($begin)) {
        $query .= " AND (`glpi_infocoms`.`buy_date` >= '{$begin}'\n                       OR `glpi_infocoms`.`use_date` >= '{$begin}') ";
    }
    if (!empty($end)) {
        $query .= " AND (`glpi_infocoms`.`buy_date` <= '{$end}'\n                       OR `glpi_infocoms`.`use_date` <= '{$end}') ";
    }
    $query .= " ORDER BY entname ASC, `buy_date`, `use_date`";
    $display_entity = Session::isMultiEntitiesMode();
    $result = $DB->query($query);
    if ($DB->numrows($result) > 0 && ($item = getItemForItemtype($itemtype))) {
        echo "<h2>" . $item->getTypeName(1) . "</h2>";
        echo "<table class='tab_cadre'><tr><th>" . __('Name') . "</th>";
        if ($display_entity) {
            echo "<th>" . __('Entity') . "</th>";
        }
        echo "<th>" . _x('price', 'Value') . "</th><th>" . __('ANV') . "</th>";
        echo "<th>" . __('TCO') . "</th><th>" . __('Date of purchase') . "</th>";
        echo "<th>" . __('Startup date') . "</th><th>" . __('Warranty expiration date') . "</th></tr>";
        $valeursoustot = 0;
        $valeurnettesoustot = 0;
        $valeurnettegraph = array();
        $valeurgraph = array();
        while ($line = $DB->fetch_assoc($result)) {
            if (isset($line["is_global"]) && $line["is_global"] && $item->getFromDB($line["items_id"])) {
                $line["value"] *= Computer_Item::countForItem($item);
            }
            if ($line["value"] > 0) {
                $valeursoustot += $line["value"];
            }
            $valeurnette = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "n");
            $tmp = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "all");
            if (is_array($tmp) && count($tmp) > 0) {
                foreach ($tmp["annee"] as $key => $val) {
                    if ($tmp["vcnetfin"][$key] > 0) {
                        if (!isset($valeurnettegraph[$val])) {
                            $valeurnettegraph[$val] = 0;
                        }
                        $valeurnettegraph[$val] += $tmp["vcnetdeb"][$key];
                    }
                }
            }
            if (!empty($line["buy_date"])) {
                $year = substr($line["buy_date"], 0, 4);
                if ($line["value"] > 0) {
                    if (!isset($valeurgraph[$year])) {
                        $valeurgraph[$year] = 0;
                    }
                    $valeurgraph[$year] += $line["value"];
                }
            }
            $valeurnettesoustot += str_replace(" ", "", $valeurnette);
            echo "<tr class='tab_bg_1'><td>" . $line["name"] . "</td>";
            if ($display_entity) {
                echo "<td>" . $line['entname'] . "</td>";
            }
            echo "<td class='right'>" . Html::formatNumber($line["value"]) . "</td>" . "<td class='right'>" . Html::formatNumber($valeurnette) . "</td>" . "<td class='right'>" . Infocom::showTco($line["ticket_tco"], $line["value"]) . "</td>" . "<td>" . Html::convDate($line["buy_date"]) . "</td>" . "<td>" . Html::convDate($line["use_date"]) . "</td>" . "<td>" . Infocom::getWarrantyExpir($line["buy_date"], $line["warranty_duration"]) . "</td></tr>";
        }
        $valeurtot += $valeursoustot;
        $valeurnettetot += $valeurnettesoustot;
        $tmpmsg = sprintf(__('Total: Value=%1$s - Account net value=%2$s'), Html::formatNumber($valeursoustot), Html::formatNumber($valeurnettesoustot));
        echo "<tr><td colspan='6' class='center'><h3>{$tmpmsg}</h3></td></tr>";
        if (count($valeurnettegraph) > 0) {
            echo "<tr><td colspan='5' class='center'>";
            ksort($valeurnettegraph);
            $valeurnettegraphdisplay = array_map('round', $valeurnettegraph);
            foreach ($valeurnettegraph as $key => $val) {
                if (!isset($valeurnettegraphtot[$key])) {
                    $valeurnettegraphtot[$key] = 0;
                }
                $valeurnettegraphtot[$key] += $valeurnettegraph[$key];
            }
            Stat::showGraph(array(__('Account net value') => $valeurnettegraphdisplay), array('title' => __('Account net value'), 'width' => 400));
            echo "</td></tr>";
        }
        if (count($valeurgraph) > 0) {
            echo "<tr><td colspan='5' class='center'>";
            ksort($valeurgraph);
            $valeurgraphdisplay = array_map('round', $valeurgraph);
            foreach ($valeurgraph as $key => $val) {
                if (!isset($valeurgraphtot[$key])) {
                    $valeurgraphtot[$key] = 0;
                }
                $valeurgraphtot[$key] += $valeurgraph[$key];
            }
            Stat::showGraph(array(_x('price', 'Value') => $valeurgraphdisplay), array('title' => _x('price', 'Value'), 'width' => 400));
            echo "</td></tr>";
        }
        echo "</table>";
        return true;
    }
    return false;
}
示例#13
0
 /**
  * Show infocom link to display modal
  *
  * @param $itemtype   integer  item type
  * @param $device_id  integer  item ID
  *
  * @return float
  **/
 static function showDisplayLink($itemtype, $device_id)
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight(self::$rightname, READ) || !($item = getItemForItemtype($itemtype))) {
         return false;
     }
     $query = "SELECT COUNT(*)\n                FROM `glpi_infocoms`\n                WHERE `items_id` = '{$device_id}'\n                      AND `itemtype` = '{$itemtype}'";
     $add = "add";
     $text = __('Add');
     $result = $DB->query($query);
     if ($DB->result($result, 0, 0) > 0) {
         $add = "";
         $text = _x('button', 'Show');
     } else {
         if (!Infocom::canUpdate()) {
             return false;
         }
     }
     if ($item->canView()) {
         echo "<span onClick=\"" . Html::jsGetElementbyID('infocom' . $itemtype . $device_id) . ".\n                dialog('open');\" style='cursor:pointer'>\n               <img src=\"" . $CFG_GLPI["root_doc"] . "/pics/dollar{$add}.png\" alt=\"{$text}\" title=\"{$text}\">\n               </span>";
         Ajax::createIframeModalWindow('infocom' . $itemtype . $device_id, $CFG_GLPI["root_doc"] . "/front/infocom.form.php" . "?itemtype={$itemtype}&items_id={$device_id}", array('height' => 600));
     }
 }
示例#14
0
 /**
  * Print out the cartridges of a defined type
  *
  * @param $cartitem  object   of CartridgeItem class
  * @param $show_old  boolean  show old cartridges or not (default 0)
  *
  * @return Nothing (displays)
  **/
 static function showForCartridgeItem(CartridgeItem $cartitem, $show_old = 0)
 {
     global $DB, $CFG_GLPI;
     $tID = $cartitem->getField('id');
     if (!$cartitem->can($tID, READ)) {
         return false;
     }
     $canedit = $cartitem->can($tID, UPDATE);
     $query = "SELECT COUNT(*) AS count\n                FROM `glpi_cartridges`\n                WHERE (`cartridgeitems_id` = '{$tID}')";
     if ($result = $DB->query($query)) {
         $total = $DB->result($result, 0, "count");
         if (!$show_old) {
             // NEW
             $where = " AND `glpi_cartridges`.`date_out` IS NULL";
         } else {
             //OLD
             $where = " AND `glpi_cartridges`.`date_out` IS NOT NULL";
         }
         $stock_time = 0;
         $use_time = 0;
         $pages_printed = 0;
         $nb_pages_printed = 0;
         $ORDER = " `glpi_cartridges`.`date_use` ASC,\n                    `glpi_cartridges`.`date_out` DESC,\n                    `glpi_cartridges`.`date_in`";
         if (!$show_old) {
             $ORDER = " `glpi_cartridges`.`date_out` ASC,\n                       `glpi_cartridges`.`date_use` ASC,\n                       `glpi_cartridges`.`date_in`";
         }
         $query = "SELECT `glpi_cartridges`.*,\n                        `glpi_printers`.`id` AS printID,\n                        `glpi_printers`.`name` AS printname,\n                        `glpi_printers`.`init_pages_counter`\n                   FROM `glpi_cartridges`\n                   LEFT JOIN `glpi_printers`\n                        ON (`glpi_cartridges`.`printers_id` = `glpi_printers`.`id`)\n                   WHERE `glpi_cartridges`.`cartridgeitems_id` = '{$tID}'\n                         {$where}\n                   ORDER BY {$ORDER}";
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         echo "<div class='spaced'>";
         if ($canedit && $number) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $actions = array('purge' => _x('button', 'Delete permanently'), 'Infocom' . MassiveAction::CLASS_ACTION_SEPARATOR . 'activate' => __('Enable the financial and administrative information'));
             if ($show_old) {
                 $actions['Cartridge' . MassiveAction::CLASS_ACTION_SEPARATOR . 'backtostock'] = __('Back to stock');
             }
             $massiveactionparams = array('num_displayed' => $number, 'specific_actions' => $actions, 'container' => 'mass' . __CLASS__ . $rand, 'rand' => $rand);
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov'>";
         if (!$show_old) {
             echo "<tr class='noHover'><th colspan='" . ($canedit ? '7' : '6') . "'>" . self::getCount($tID, -1) . "</th>";
             echo "</tr>";
         } else {
             // Old
             echo "<tr class='noHover'><th colspan='" . ($canedit ? '9' : '8') . "'>" . __('Worn cartridges');
             echo "</th></tr>";
         }
         $i = 0;
         $header_begin = "<tr>";
         $header_top = '';
         $header_bottom = '';
         $header_end = '';
         if ($canedit && $number) {
             $header_begin .= "<th width='10'>";
             $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_end .= "</th>";
         }
         $header_end .= "<th>" . __('ID') . "</th>";
         $header_end .= "<th>" . _x('item', 'State') . "</th>";
         $header_end .= "<th>" . __('Add date') . "</th><th>" . __('Use date') . "</th>";
         $header_end .= "<th>" . __('Used on') . "</th>";
         if ($show_old) {
             $header_end .= "<th>" . __('End date') . "</th>";
             $header_end .= "<th>" . __('Printer counter') . "</th>";
         }
         $header_end .= "<th width='18%'>" . __('Financial and administrative information') . "</th>";
         $header_end .= "</tr>";
         echo $header_begin . $header_top . $header_end;
     }
     $pages = array();
     if ($number) {
         while ($data = $DB->fetch_assoc($result)) {
             $date_in = Html::convDate($data["date_in"]);
             $date_use = Html::convDate($data["date_use"]);
             $date_out = Html::convDate($data["date_out"]);
             $printer = $data["printers_id"];
             $page = $data["pages"];
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                 echo "</td>";
             }
             echo "<td>" . $data['id'] . '</td>';
             echo "<td class='center'>" . self::getStatus($data["date_use"], $data["date_out"]);
             echo "</td><td class='center'>" . $date_in . "</td>";
             echo "<td class='center'>" . $date_use . "</td>";
             echo "<td class='center'>";
             if (!is_null($date_use)) {
                 if ($data["printID"] > 0) {
                     $printname = $data["printname"];
                     if ($_SESSION['glpiis_ids_visible'] || empty($printname)) {
                         $printname = sprintf(__('%1$s (%2$s)'), $printname, $data["printID"]);
                     }
                     echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/printer.form.php?id=" . $data["printID"] . "'><span class='b'>" . $printname . "</span></a>";
                 } else {
                     echo NOT_AVAILABLE;
                 }
                 $tmp_dbeg = explode("-", $data["date_in"]);
                 $tmp_dend = explode("-", $data["date_use"]);
                 $stock_time_tmp = mktime(0, 0, 0, $tmp_dend[1], $tmp_dend[2], $tmp_dend[0]) - mktime(0, 0, 0, $tmp_dbeg[1], $tmp_dbeg[2], $tmp_dbeg[0]);
                 $stock_time += $stock_time_tmp;
             }
             if ($show_old) {
                 echo "</td><td class='center'>";
                 echo $date_out;
                 $tmp_dbeg = explode("-", $data["date_use"]);
                 $tmp_dend = explode("-", $data["date_out"]);
                 $use_time_tmp = mktime(0, 0, 0, $tmp_dend[1], $tmp_dend[2], $tmp_dend[0]) - mktime(0, 0, 0, $tmp_dbeg[1], $tmp_dbeg[2], $tmp_dbeg[0]);
                 $use_time += $use_time_tmp;
             }
             echo "</td>";
             if ($show_old) {
                 // Get initial counter page
                 if (!isset($pages[$printer])) {
                     $pages[$printer] = $data['init_pages_counter'];
                 }
                 echo "<td class='center'>";
                 if ($pages[$printer] < $data['pages']) {
                     $pages_printed += $data['pages'] - $pages[$printer];
                     $nb_pages_printed++;
                     $pp = $data['pages'] - $pages[$printer];
                     printf(_n('%d printed page', '%d printed pages', $pp), $pp);
                     $pages[$printer] = $data['pages'];
                 } else {
                     if ($data['pages'] != 0) {
                         echo "<span class='tab_bg_1_2'>" . __('Counter error') . "</span>";
                     }
                 }
                 echo "</td>";
             }
             echo "<td class='center'>";
             Infocom::showDisplayLink('Cartridge', $data["id"]);
             echo "</td>";
             echo "</tr>";
         }
         if ($show_old && $number > 0) {
             if ($nb_pages_printed == 0) {
                 $nb_pages_printed = 1;
             }
             echo "<tr class='tab_bg_2'><td colspan='" . ($canedit ? '4' : '3') . "'>&nbsp;</td>";
             echo "<td class='center b'>" . __('Average time in stock') . "<br>";
             echo round($stock_time / $number / 60 / 60 / 24 / 30.5, 1) . " " . __('month') . "</td>";
             echo "<td>&nbsp;</td>";
             echo "<td class='center b'>" . __('Average time in use') . "<br>";
             echo round($use_time / $number / 60 / 60 / 24 / 30.5, 1) . " " . __('month') . "</td>";
             echo "<td class='center b'>" . __('Average number of printed pages') . "<br>";
             echo round($pages_printed / $nb_pages_printed) . "</td>";
             echo "<td colspan='" . ($canedit ? '3' : '1') . "'>&nbsp;</td></tr>";
         } else {
             echo $header_begin . $header_bottom . $header_end;
         }
     }
     echo "</table>";
     if ($canedit && $number) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>\n\n";
 }
示例#15
0
 /**
  * Return the instance fields of itemtype identified by id
  *
  * @param $itemtype    string  itemtype (class) of object
  * @param $id          integer identifier of object
  * @param $params      array   with theses options :
  *    - 'expand_dropdowns': Show dropdown's names instead of id. default: false. Optionnal
  *    - 'get_hateoas':      Show relation of current item in a links attribute. default: true. Optionnal
  *    - 'get_sha1':         Get a sha1 signature instead of the full answer. default: false. Optionnal
  *    - 'with_components':  Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal.
  *    - 'with_disks':       Only for Computer, retrieve the associated filesystems. Optionnal.
  *    - 'with_softwares':   Only for Computer, retrieve the associated softwares installations. Optionnal.
  *    - 'with_connections': Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal.
  *    - 'with_networkports':Retrieve all network connections and advanced network informations. Optionnal.
  *    - 'with_infocoms':    Retrieve financial and administrative informations. Optionnal.
  *    - 'with_contracts':   Retrieve associated contracts. Optionnal.
  *    - 'with_documents':   Retrieve associated external documents. Optionnal.
  *    - 'with_tickets':     Retrieve associated itil tickets. Optionnal.
  *    - 'with_problems':    Retrieve associated itil problems. Optionnal.
  *    - 'with_changes':     Retrieve associated itil changes. Optionnal.
  *    - 'with_notes':       Retrieve Notes (if exists, not all itemtypes have notes). Optionnal.
  *    - 'with_logs':        Retrieve historical. Optionnal.
  *
  * @return     array    fields of found object
  **/
 protected function getItem($itemtype, $id, $params = array())
 {
     global $CFG_GLPI, $DB;
     $this->initEndpoint();
     // default params
     $default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'get_sha1' => false, 'with_components' => false, 'with_disks' => false, 'with_softwares' => false, 'with_connections' => false, 'with_networkports' => false, 'with_infocoms' => false, 'with_contracts' => false, 'with_documents' => false, 'with_tickets' => false, 'with_problems' => false, 'with_changes' => false, 'with_notes' => false, 'with_logs' => false);
     $params = array_merge($default, $params);
     $item = new $itemtype();
     if (!$item->getFromDB($id)) {
         return $this->messageNotfoundError();
     }
     if (!$item->can($id, READ)) {
         return $this->messageRightError();
     }
     $fields = $item->fields;
     // avoid disclosure of critical fields
     $item::unsetUndisclosedFields($fields);
     // retrieve devices
     if (isset($params['with_devices']) && $params['with_devices'] && in_array($itemtype, Item_Devices::getConcernedItems())) {
         $all_devices = array();
         foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) {
             $found_devices = getAllDatasFromTable($device_type::getTable(), "`items_id` = '" . $item->getID() . "'\n                                                   AND `itemtype` = '" . $item->getType() . "'\n                                                   AND `is_deleted` = '0'", true);
             foreach ($found_devices as $devices_id => &$device) {
                 unset($device['items_id']);
                 unset($device['itemtype']);
                 unset($device['is_deleted']);
             }
             if (!empty($found_devices)) {
                 $all_devices[$device_type] = $found_devices;
             }
         }
         $fields['_devices'] = $all_devices;
     }
     // retrieve computer disks
     if (isset($params['with_disks']) && $params['with_disks'] && $itemtype == "Computer") {
         // build query to retrive filesystems
         $query = "SELECT `glpi_filesystems`.`name` AS fsname,\n                          `glpi_computerdisks`.*\n                   FROM `glpi_computerdisks`\n                   LEFT JOIN `glpi_filesystems`\n                             ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`)\n                   WHERE `computers_id` = '{$id}'\n                         AND `is_deleted` = '0'";
         $fields['_disks'] = array();
         if ($result = $DB->query($query)) {
             while ($data = $DB->fetch_assoc($result)) {
                 unset($data['computers_id']);
                 unset($data['is_deleted']);
                 $fields['_disks'][] = array('name' => $data);
             }
         }
     }
     // retrieve computer softwares
     if (isset($params['with_softwares']) && $params['with_softwares'] && $itemtype == "Computer") {
         $fields['_softwares'] = array();
         if (!Software::canView()) {
             $fields['_softwares'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_softwares`.`softwarecategories_id`,\n                             `glpi_softwares`.`id` AS softwares_id,\n                             `glpi_softwareversions`.`id` AS softwareversions_id,\n                             `glpi_computers_softwareversions`.`is_dynamic`,\n                             `glpi_softwareversions`.`states_id`,\n                             `glpi_softwares`.`is_valid`\n                      FROM `glpi_computers_softwareversions`\n                      LEFT JOIN `glpi_softwareversions`\n                           ON (`glpi_computers_softwareversions`.`softwareversions_id`\n                                 = `glpi_softwareversions`.`id`)\n                      LEFT JOIN `glpi_softwares`\n                           ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`)\n                      WHERE `glpi_computers_softwareversions`.`computers_id` = '{$id}'\n                            AND `glpi_computers_softwareversions`.`is_deleted` = '0'\n                      ORDER BY `glpi_softwares`.`name`, `glpi_softwareversions`.`name`";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_softwares'][] = $data;
                 }
             }
         }
     }
     // retrieve item connections
     if (isset($params['with_connections']) && $params['with_connections'] && $itemtype == "Computer") {
         $fields['_connections'] = array();
         foreach ($CFG_GLPI["directconnect_types"] as $connect_type) {
             $connect_item = new $connect_type();
             if ($connect_item->canView()) {
                 $query = "SELECT `glpi_computers_items`.`id` AS assoc_id,\n                         `glpi_computers_items`.`computers_id` AS assoc_computers_id,\n                         `glpi_computers_items`.`itemtype` AS assoc_itemtype,\n                         `glpi_computers_items`.`items_id` AS assoc_items_id,\n                         `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic,\n                         " . getTableForItemType($connect_type) . ".*\n                         FROM `glpi_computers_items`\n                         LEFT JOIN `" . getTableForItemType($connect_type) . "`\n                           ON (`" . getTableForItemType($connect_type) . "`.`id`\n                                 = `glpi_computers_items`.`items_id`)\n                         WHERE `computers_id` = '{$id}'\n                               AND `itemtype` = '" . $connect_type . "'\n                               AND `glpi_computers_items`.`is_deleted` = '0'";
                 if ($result = $DB->query($query)) {
                     while ($data = $DB->fetch_assoc($result)) {
                         $fields['_connections'][$connect_type][] = $data;
                     }
                 }
             }
         }
     }
     // retrieve item networkports
     if (isset($params['with_networkports']) && $params['with_networkports']) {
         $fields['_networkports'] = array();
         if (!NetworkEquipment::canView()) {
             $fields['_networkports'] = self::arrayRightError();
         } else {
             foreach (NetworkPort::getNetworkPortInstantiations() as $networkport_type) {
                 $netport_table = $networkport_type::getTable();
                 $query = "SELECT\n                           netp.`id` as netport_id,\n                           netp.`entities_id`,\n                           netp.`is_recursive`,\n                           netp.`logical_number`,\n                           netp.`name`,\n                           netp.`mac`,\n                           netp.`comment`,\n                           netp.`is_dynamic`,\n                           netp_subtable.*\n                         FROM glpi_networkports AS netp\n                         LEFT JOIN `{$netport_table}` AS netp_subtable\n                           ON netp_subtable.`networkports_id` = netp.`id`\n                         WHERE netp.`instantiation_type` = '{$networkport_type}'\n                           AND netp.`items_id` = '{$id}'\n                           AND netp.`itemtype` = '{$itemtype}'\n                           AND netp.`is_deleted` = '0'";
                 if ($result = $DB->query($query)) {
                     while ($data = $DB->fetch_assoc($result)) {
                         if (isset($data['netport_id'])) {
                             // append network name
                             $query_netn = "SELECT\n                              GROUP_CONCAT(CONCAT(ipadr.`id`, '" . Search::SHORTSEP . "' , ipadr.`name`)\n                                           SEPARATOR '" . Search::LONGSEP . "') as ipadresses,\n                              netn.`id` as networknames_id,\n                              netn.`name` as networkname,\n                              netn.`fqdns_id`,\n                              fqdn.`name` as fqdn_name,\n                              fqdn.`fqdn`\n                           FROM `glpi_networknames` AS netn\n                           LEFT JOIN `glpi_ipaddresses` AS ipadr\n                              ON ipadr.`itemtype` = 'NetworkName' AND ipadr.`items_id` = netn.`id`\n                           LEFT JOIN `glpi_fqdns` AS fqdn\n                              ON fqdn.`id` = netn.`fqdns_id`\n                           LEFT JOIN `glpi_ipaddresses_ipnetworks` ipadnet\n                              ON ipadnet.`ipaddresses_id` = ipadr.`id`\n                           LEFT JOIN `glpi_ipnetworks` `ipnet`\n                              ON ipnet.`id` = ipadnet.`ipnetworks_id`\n                           WHERE netn.`itemtype` = 'NetworkPort'\n                             AND netn.`items_id` = " . $data['netport_id'] . "\n                           GROUP BY netn.`id`, netn.`name`, netn.fqdns_id, fqdn.name, fqdn.fqdn";
                             if ($result_netn = $DB->query($query_netn)) {
                                 $data_netn = $DB->fetch_assoc($result_netn);
                                 $raw_ipadresses = explode(Search::LONGSEP, $data_netn['ipadresses']);
                                 $ipadresses = array();
                                 foreach ($raw_ipadresses as $ipadress) {
                                     $ipadress = explode(Search::SHORTSEP, $ipadress);
                                     //find ip network attached to these ip
                                     $ipnetworks = array();
                                     $query_ipnet = "SELECT\n                                    ipnet.`id`,\n                                    ipnet.`completename`,\n                                    ipnet.`name`,\n                                    ipnet.`address`,\n                                    ipnet.`netmask`,\n                                    ipnet.`gateway`,\n                                    ipnet.`ipnetworks_id`,\n                                    ipnet.`comment`\n                                 FROM `glpi_ipnetworks` ipnet\n                                 INNER JOIN `glpi_ipaddresses_ipnetworks` ipadnet\n                                    ON ipnet.`id` = ipadnet.`ipnetworks_id`\n                                    AND ipadnet.`ipaddresses_id` = " . $ipadress[0];
                                     if ($result_ipnet = $DB->query($query_ipnet)) {
                                         while ($data_ipnet = $DB->fetch_assoc($result_ipnet)) {
                                             $ipnetworks[] = $data_ipnet;
                                         }
                                     }
                                     $ipadresses[] = array('id' => $ipadress[0], 'name' => $ipadress[1], 'IPNetwork' => $ipnetworks);
                                 }
                                 $data['NetworkName'] = array('id' => $data_netn['networknames_id'], 'name' => $data_netn['networkname'], 'fqdns_id' => $data_netn['fqdns_id'], 'FQDN' => array('id' => $data_netn['fqdns_id'], 'name' => $data_netn['fqdn_name'], 'fqdn' => $data_netn['fqdn']), 'IPAddress' => $ipadresses);
                             }
                         }
                         $fields['_networkports'][$networkport_type][] = $data;
                     }
                 }
             }
         }
     }
     // retrieve item infocoms
     if (isset($params['with_infocoms']) && $params['with_infocoms']) {
         $fields['_infocoms'] = array();
         if (!Infocom::canView()) {
             $fields['_infocoms'] = self::arrayRightError();
         } else {
             $ic = new Infocom();
             if ($ic->getFromDBforDevice($itemtype, $id)) {
                 $fields['_infocoms'] = $ic->fields;
             }
         }
     }
     // retrieve item contracts
     if (isset($params['with_contracts']) && $params['with_contracts']) {
         $fields['_contracts'] = array();
         if (!Contract::canView()) {
             $fields['_contracts'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_contracts_items`.*\n                     FROM `glpi_contracts_items`,\n                          `glpi_contracts`\n                     LEFT JOIN `glpi_entities` ON (`glpi_contracts`.`entities_id`=`glpi_entities`.`id`)\n                     WHERE `glpi_contracts`.`id`=`glpi_contracts_items`.`contracts_id`\n                           AND `glpi_contracts_items`.`items_id` = '{$id}'\n                           AND `glpi_contracts_items`.`itemtype` = '{$itemtype}'" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n                     ORDER BY `glpi_contracts`.`name`";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_contracts'][] = $data;
                 }
             }
         }
     }
     // retrieve item contracts
     if (isset($params['with_documents']) && $params['with_documents']) {
         $fields['_documents'] = array();
         if (!$itemtype != 'Ticket' && $itemtype != 'KnowbaseItem' && $itemtype != 'Reminder' && !Document::canView()) {
             $fields['_documents'] = self::arrayRightError();
         } else {
             $query = "SELECT `glpi_documents_items`.`id` AS assocID,\n                             `glpi_documents_items`.`date_mod` AS assocdate,\n                             `glpi_entities`.`id` AS entityID,\n                             `glpi_entities`.`completename` AS entity,\n                             `glpi_documentcategories`.`completename` AS headings,\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                      LEFT JOIN `glpi_documentcategories`\n                              ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n                      WHERE `glpi_documents_items`.`items_id` = '{$id}'\n                            AND `glpi_documents_items`.`itemtype` = '{$itemtype}' ";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_documents'][] = $data;
                 }
             }
         }
     }
     // retrieve item tickets
     if (isset($params['with_tickets']) && $params['with_tickets']) {
         $fields['_tickets'] = array();
         if (!Ticket::canView()) {
             $fields['_tickets'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Ticket::getCommonSelect() . "\n                      FROM `glpi_tickets` " . Ticket::getCommonLeftJoin() . "\n                      WHERE `glpi_items_tickets`.`items_id` = '{$id}'\n                             AND `glpi_items_tickets`.`itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                      ORDER BY `glpi_tickets`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_tickets'][] = $data;
                 }
             }
         }
     }
     // retrieve item problems
     if (isset($params['with_problems']) && $params['with_problems']) {
         $fields['_problems'] = array();
         if (!Problem::canView()) {
             $fields['_problems'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Problem::getCommonSelect() . "\n                            FROM `glpi_problems`\n                            LEFT JOIN `glpi_items_problems`\n                              ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) " . Problem::getCommonLeftJoin() . "\n                            WHERE `items_id` = '{$id}'\n                                  AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_problems") . "\n                            ORDER BY `glpi_problems`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_problems'][] = $data;
                 }
             }
         }
     }
     // retrieve item changes
     if (isset($params['with_changes']) && $params['with_changes']) {
         $fields['_changes'] = array();
         if (!Change::canView()) {
             $fields['_changes'] = self::arrayRightError();
         } else {
             $query = "SELECT " . Change::getCommonSelect() . "\n                            FROM `glpi_changes`\n                            LEFT JOIN `glpi_changes_items`\n                              ON (`glpi_changes`.`id` = `glpi_changes_items`.`problems_id`) " . Change::getCommonLeftJoin() . "\n                            WHERE `items_id` = '{$id}'\n                                  AND `itemtype` = '{$itemtype}' " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n                            ORDER BY `glpi_changes`.`date_mod` DESC";
             if ($result = $DB->query($query)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $fields['_changes'][] = $data;
                 }
             }
         }
     }
     // retrieve item notes
     if (isset($params['with_notes']) && $params['with_notes']) {
         $fields['_notes'] = array();
         if (!Session::haveRight($itemtype::$rightname, READNOTE)) {
             $fields['_notes'] = self::arrayRightError();
         } else {
             $fields['_notes'] = Notepad::getAllForItem($item);
         }
     }
     // retrieve item logs
     if (isset($params['with_logs']) && $params['with_logs']) {
         $fields['_logs'] = array();
         if (!Session::haveRight($itemtype::$rightname, READNOTE)) {
             $fields['_logs'] = self::arrayRightError();
         } else {
             $fields['_logs'] = getAllDatasFromTable("glpi_logs", "`items_id` = '" . $item->getID() . "'\n                                                    AND `itemtype` = '" . $item->getType() . "'");
         }
     }
     // expand dropdown (retrieve name of dropdowns) and get hateoas from foreign keys
     $fields = self::parseDropdowns($fields, $params);
     // get hateoas from children
     if ($params['get_hateoas']) {
         $hclasses = self::getHatoasClasses($itemtype);
         foreach ($hclasses as $hclass) {
             $fields['links'][] = array('rel' => $hclass, 'href' => self::$api_url . "/{$itemtype}/" . $item->getID() . "/{$hclass}/");
         }
     }
     // get sha1 footprint if needed
     if ($params['get_sha1']) {
         $fields = sha1(json_encode($fields, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK));
     }
     return $fields;
 }
示例#16
0
         default:
             Plugin::displayAction($monitor, $_REQUEST['glpi_tab'], $_POST["withtemplate"]);
     }
 } else {
     switch ($_REQUEST['glpi_tab']) {
         case -1:
             Computer_Item::showForItem($monitor);
             Infocom::showForItem($monitor);
             Contract::showAssociated($monitor);
             Document::showAssociated($monitor, $_POST["withtemplate"]);
             Ticket::showListForItem('Monitor', $_POST["id"]);
             Link::showForItem('Monitor', $_POST["id"]);
             Plugin::displayAction($monitor, $_REQUEST['glpi_tab']);
             break;
         case 4:
             Infocom::showForItem($monitor);
             Contract::showAssociated($monitor);
             break;
         case 5:
             Document::showAssociated($monitor, $_POST["withtemplate"]);
             break;
         case 6:
             Ticket::showListForItem('Monitor', $_POST["id"]);
             break;
         case 7:
             Link::showForItem('Monitor', $_POST["id"]);
             break;
         case 10:
             showNotesForm($_POST['target'], 'Monitor', $_POST["id"]);
             break;
         case 11:
示例#17
0
                    echo "<td> " . Html::convDate($data['buy_date']) . " </td>";
                    if ($data["warranty_duration"]) {
                        echo "<td> " . Infocom::getWarrantyExpir($data["buy_date"], $data["warranty_duration"]) . " </td>";
                    } else {
                        echo "<td> " . NOT_AVAILABLE . " </td>";
                    }
                } else {
                    echo "<td> " . NOT_AVAILABLE . " </td><td> " . NOT_AVAILABLE . " </td>";
                }
                if ($data['type']) {
                    echo "<td class='b'> " . $data['type'] . " </td>";
                } else {
                    echo "<td> " . NOT_AVAILABLE . " </td>";
                }
                if ($data['begin_date']) {
                    echo "<td> " . Html::convDate($data['begin_date']) . " </td>";
                    if ($data["duration"]) {
                        echo "<td> " . Infocom::getWarrantyExpir($data["begin_date"], $data["duration"]) . " </td>";
                    } else {
                        echo "<td> " . NOT_AVAILABLE . " </td>";
                    }
                } else {
                    echo "<td> " . NOT_AVAILABLE . " </td><td> " . NOT_AVAILABLE . " </td>";
                }
                echo "</tr>\n";
            }
            echo "</table><br><hr><br>";
        }
    }
}
Html::footer();
示例#18
0
 /**
  * @param $type
  * @param $model_id
  * @param $tab_ids
  * @param $location
  **/
 static function replace($type, $model_id, $tab_ids, $location)
 {
     global $DB, $CFG_GLPI, $PLUGIN_HOOKS;
     $model = new PluginUninstallModel();
     $model->getConfig($model_id);
     $overwrite = $model->fields["overwrite"];
     echo "<div class='center'>";
     echo "<table class='tab_cadre_fixe'><tr><th>" . __('Replacement', 'uninstall') . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>";
     $count = 0;
     $tot = count($tab_ids);
     Html::createProgressBar(__('Please wait, replacement is running...', 'uninstall'));
     foreach ($tab_ids as $olditem_id => $newitem_id) {
         $count++;
         $olditem = new $type();
         $olditem->getFromDB($olditem_id);
         $newitem = new $type();
         $newitem->getFromDB($newitem_id);
         //Hook to perform actions before item is being replaced
         $olditem->fields['_newid'] = $newitem_id;
         $olditem->fields['_uninstall_event'] = $model_id;
         $olditem->fields['_action'] = 'replace';
         Plugin::doHook("plugin_uninstall_replace_before", $olditem);
         // Retrieve informations
         //States
         if ($model->fields['states_id'] != 0) {
             $olditem->update(array('id' => $olditem_id, 'states_id' => $model->fields['states_id']), false);
         }
         // METHOD REPLACEMENT 1 : Archive
         if ($model->fields['replace_method'] == self::METHOD_PURGE) {
             $name_out = str_shuffle(Toolbox::getRandomString(5) . time());
             $plugin = new Plugin();
             if ($plugin->isActivated('PDF')) {
                 // USE PDF EXPORT
                 $plugin->load('pdf', true);
                 include_once GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php";
                 //Get all item's tabs
                 $tab = array_keys($olditem->defineTabs());
                 //Tell PDF to also export item's main tab, and in first position
                 array_unshift($tab, "_main_");
                 $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($olditem);
                 $out = $itempdf->generatePDF(array($olditem_id), $tab, 1, false);
                 $name_out .= ".pdf";
             } else {
                 //TODO Which datas ? Add Defaults...
                 $out = __('Replacement', 'uninstall') . "\r\n";
                 $datas = $olditem->fields;
                 unset($datas['comment']);
                 foreach ($datas as $k => $v) {
                     $out .= $k . ";";
                 }
                 $out .= "\r\n";
                 foreach ($datas as $k => $v) {
                     $out .= $v . ";";
                 }
                 // USE CSV EXPORT
                 $name_out .= ".csv";
             }
             // Write document
             $out_file = GLPI_DOC_DIR . "/_uploads/" . $name_out;
             $open_file = fopen($out_file, 'a');
             fwrite($open_file, $out);
             fclose($open_file);
             // Compute comment text
             $comment = __('This document is the archive of this replaced item', 'uninstall') . " " . self::getCommentsForReplacement($olditem, false, false);
             // Create & Attach new document to current item
             $doc = new Document();
             $input = array('name' => addslashes(__('Archive of old material', 'uninstall')), 'upload_file' => $name_out, 'comment' => addslashes($comment), 'add' => __('Add'), 'entities_id' => $newitem->getEntityID(), 'is_recursive' => $newitem->isRecursive(), 'link' => "", 'documentcategories_id' => 0, 'items_id' => $olditem_id, 'itemtype' => $type);
             //Attached the document to the old item, to generate an accurate name
             $document_added = $doc->add($input);
             //Attach the document to the new item, once the document's name is correct
             $docItem = new Document_Item();
             $docItemId = $docItem->add(array('documents_id' => $document_added, 'itemtype' => $type, 'items_id' => (int) $newitem_id));
         }
         // General Informations - NAME
         if ($model->fields["replace_name"]) {
             if ($overwrite || empty($newitem->fields['name'])) {
                 $newitem->update(array('id' => $newitem_id, 'name' => $olditem->getField('name')), false);
             }
         }
         $data['id'] = $newitem->getID();
         // General Informations - SERIAL
         if ($model->fields["replace_serial"]) {
             if ($overwrite || empty($newitem->fields['serial'])) {
                 $newitem->update(array('id' => $newitem_id, 'serial' => $olditem->getField('serial')), false);
             }
         }
         // General Informations - OTHERSERIAL
         if ($model->fields["replace_otherserial"]) {
             if ($overwrite || empty($newitem->fields['otherserial'])) {
                 $newitem->update(array('id' => $newitem_id, 'otherserial' => $olditem->getField('otherserial')), false);
             }
         }
         // Documents
         if ($model->fields["replace_documents"] && in_array($type, $CFG_GLPI["document_types"])) {
             $doc_item = new Document_Item();
             foreach (self::getAssociatedDocuments($olditem) as $document) {
                 $doc_item->update(array('id' => $document['assocID'], 'itemtype' => $type, 'items_id' => $newitem_id), false);
             }
         }
         // Contracts
         if ($model->fields["replace_contracts"] && in_array($type, $CFG_GLPI["contract_types"])) {
             $contract_item = new Contract_Item();
             foreach (self::getAssociatedContracts($olditem) as $contract) {
                 $contract_item->update(array('id' => $contract['id'], 'itemtype' => $type, 'items_id' => $newitem_id), false);
             }
         }
         // Infocoms
         if ($model->fields["replace_infocoms"] && in_array($type, $CFG_GLPI["infocom_types"])) {
             $infocom = new Infocom();
             if ($overwrite) {
                 // Delete current Infocoms of new item
                 if ($infocom->getFromDBforDevice($type, $newitem_id)) {
                     //Do not log infocom deletion in the new item's history
                     $infocom->dohistory = false;
                     $infocom->deleteFromDB(1);
                 }
             }
             // Update current Infocoms of old item
             if ($infocom->getFromDBforDevice($type, $olditem_id)) {
                 $infocom->update(array('id' => $infocom->getID(), 'itemtype' => $type, 'items_id' => $newitem_id), false);
             }
         }
         // Reservations
         if ($model->fields["replace_reservations"] && in_array($type, $CFG_GLPI["reservation_types"])) {
             $resaitem = new ReservationItem();
             if ($overwrite) {
                 // Delete current reservation of new item
                 $resa_new = new Reservation();
                 $resa_new->getFromDB($newitem_id);
                 if ($resa_new->is_reserved()) {
                     $resa_new = new ReservationItem();
                     $resa_new->getFromDBbyItem($type, $newitem_id);
                     if (count($resa_new->fields)) {
                         $resa_new->deleteFromDB(1);
                     }
                 }
             }
             // Update old reservation for attribute to new item
             $resa_old = new Reservation();
             $resa_old->getFromDB($olditem_id);
             if ($resa_old->is_reserved()) {
                 $resa_old = new ReservationItem();
                 $resa_old->getFromDBbyItem($type, $olditem_id);
                 if (count($resa_old->fields)) {
                     $resa_old->update(array('id' => $resa_old->getID(), 'itemtype' => $type, 'items_id' => $newitem_id), false);
                 }
             }
         }
         // User
         if ($model->fields["replace_users"] && in_array($type, $CFG_GLPI["linkuser_types"])) {
             $data = array();
             $data['id'] = $newitem->getID();
             if ($newitem->isField('users_id') && ($overwrite || empty($data['users_id']))) {
                 $data['users_id'] = $olditem->getField('users_id');
             }
             if ($newitem->isField('contact') && ($overwrite || empty($data['contact']))) {
                 $data['contact'] = $olditem->getField('contact');
             }
             if ($newitem->isField('contact_num') && ($overwrite || empty($data['contact_num']))) {
                 $data['contact_num'] = $olditem->getField('contact_num');
             }
             $newitem->update($data, false);
         }
         // Group
         if ($model->fields["replace_groups"] && in_array($type, $CFG_GLPI["linkgroup_types"])) {
             if ($newitem->isField('groups_id') && ($overwrite || empty($data['groups_id']))) {
                 $newitem->update(array('id' => $newitem_id, 'groups_id' => $olditem->getField('groups_id')), false);
             }
         }
         // Tickets
         if ($model->fields["replace_tickets"] && in_array($type, $CFG_GLPI["ticket_types"])) {
             $ticket_item = new Item_Ticket();
             foreach (self::getAssociatedTickets($type, $olditem_id) as $ticket) {
                 $ticket_item->update(array('id' => $ticket['id'], 'items_id' => $newitem_id), false);
             }
         }
         //Array netport_types renamed in networkport_types in GLPI 0.80
         if (isset($CFG_GLPI["netport_types"])) {
             $netport_types = $CFG_GLPI["netport_types"];
         } else {
             $netport_types = $CFG_GLPI["networkport_types"];
         }
         // NetPorts
         if ($model->fields["replace_netports"] && in_array($type, $netport_types)) {
             $netport_item = new NetworkPort();
             foreach (self::getAssociatedNetports($type, $olditem_id) as $netport) {
                 $netport_item->update(array('id' => $netport['id'], 'itemtype' => $type, 'items_id' => $newitem_id), false);
             }
         }
         // Directs connections
         if ($model->fields["replace_direct_connections"] && in_array($type, array('Computer'))) {
             $comp_item = new Computer_Item();
             foreach (self::getAssociatedItems($olditem) as $itemtype => $connections) {
                 foreach ($connections as $connection) {
                     $comp_item->update(array('id' => $connection['id'], 'computers_id' => $newitem_id, 'itemtype' => $itemtype), false);
                 }
             }
         }
         // Location
         if ($location != 0 && $olditem->isField('locations_id')) {
             $olditem->getFromDB($olditem_id);
             switch ($location) {
                 case -1:
                     break;
                 default:
                     $olditem->update(array('id' => $olditem_id, 'locations_id' => $location), false);
                     break;
             }
         }
         $plug = new Plugin();
         if ($plug->isActivated('ocsinventoryng')) {
             //Delete computer from OCS
             if ($model->fields["remove_from_ocs"] == 1) {
                 PluginUninstallUninstall::deleteComputerInOCSByGlpiID($olditem_id);
             }
             //Delete link in glpi_ocs_link
             if ($model->fields["delete_ocs_link"] || $model->fields["remove_from_ocs"]) {
                 PluginUninstallUninstall::deleteOcsLink($olditem_id);
             }
         }
         if ($plug->isActivated('fusioninventory')) {
             if ($model->fields['raz_fusioninventory']) {
                 PluginUninstallUninstall::deleteFusionInventoryLink(get_class($olditem), $olditem_id);
             }
         }
         // METHOD REPLACEMENT 1 : Purge
         if ($model->fields['replace_method'] == self::METHOD_PURGE) {
             // Retrieve, Compute && Update NEW comment field
             $comment = self::getCommentsForReplacement($olditem, true);
             $comment .= "\n- " . __('See attached document', 'uninstall');
             $newitem->update(array('id' => $newitem_id, 'comment' => addslashes($comment)), false);
             // If old item is attached in PDF/CSV
             // Delete AND Purge it in DB
             if ($document_added) {
                 $olditem->delete(array('id' => $olditem_id), true);
             }
         }
         // METHOD REPLACEMENT 2 : Delete AND Comment
         if ($model->fields['replace_method'] == self::METHOD_DELETE_AND_COMMENT) {
             //Add comment on the new item first
             $comment = self::getCommentsForReplacement($olditem, true);
             $newitem->update(array('id' => $newitem_id, 'comment' => Toolbox::addslashes_deep($comment)), false);
             // Retrieve, Compute && Update OLD comment field
             $comment = self::getCommentsForReplacement($newitem, false);
             $olditem->update(array('id' => $olditem_id, 'comment' => Toolbox::addslashes_deep($comment)), false);
             // Delete OLD item from DB (not PURGE)
             PluginUninstallUninstall::addUninstallLog($type, $olditem_id, 'replaced_by');
             $olditem->delete(array('id' => $olditem_id), 0, false);
         }
         //Plugin hook after replacement
         Plugin::doHook("plugin_uninstall_replace_after", $olditem);
         //Add history
         PluginUninstallUninstall::addUninstallLog($type, $newitem_id, 'replace');
         Html::changeProgressBarPosition($count, $tot + 1);
     }
     Html::changeProgressBarPosition($count, $tot, __('Replacement successful', 'uninstall'));
     echo "</td></tr>";
     echo "</table></div>";
 }
示例#19
0
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
$ic = new Infocom();
if (isset($_POST['add'])) {
    $ic->check(-1, CREATE, $_POST);
    $newID = $ic->add($_POST, false);
    Event::log($newID, "infocom", 4, "financial", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $newID));
    Html::back();
} else {
    if (isset($_POST["purge"])) {
        $ic->check($_POST["id"], PURGE);
        $ic->delete($_POST, 1);
        Event::log($_POST["id"], "infocom", 4, "financial", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
        Html::back();
    } else {
        if (isset($_POST["update"])) {
            $ic->check($_POST["id"], UPDATE);
            $ic->update($_POST);
 /**
  * Get all data needed for template processing
  *
  * @param $event
  * @param $options   array
  **/
 function getDatasForTemplate($event, $options = array())
 {
     $this->datas['##contract.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
     $events = $this->getEvents();
     $this->datas['##contract.action##'] = sprintf(__('%1$s - %2$s'), __('Contracts alarm'), $events[$event]);
     foreach ($options['items'] as $id => $contract) {
         $tmp = array();
         $tmp['##contract.name##'] = $contract['name'];
         $tmp['##contract.number##'] = $contract['num'];
         if ($contract['contracttypes_id']) {
             $tmp['##contract.type##'] = Dropdown::getDropdownName('glpi_contracttypes', $contract['contracttypes_id']);
         } else {
             $tmp['##contract.type##'] = "";
         }
         switch ($event) {
             case 'end':
                 $tmp['##contract.time##'] = Infocom::getWarrantyExpir($contract["begin_date"], $contract["duration"]);
                 break;
             case 'notice':
                 $tmp['##contract.time##'] = Infocom::getWarrantyExpir($contract["begin_date"], $contract["duration"], $contract["notice"]);
                 break;
             case 'periodicity':
             case 'periodicitynotice':
                 if (isset($contract["alert_date"])) {
                     $tmp['##contract.time##'] = Html::convDate($contract["alert_date"]);
                 } else {
                     if (isset($options['_debug'])) {
                         $tmp['##contract.time##'] = Html::convDate($_SESSION['glpi_currenttime']);
                     }
                 }
                 break;
         }
         $tmp['##contract.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "Contract_" . $id);
         $tmp['##contract.items.number##'] = 0;
         $tmp['##contract.items##'] = '';
         if (isset($contract['items']) && count($contract['items'])) {
             $toadd = array();
             foreach ($contract['items'] as $itemtype => $item) {
                 if ($type = getItemForItemtype($itemtype)) {
                     $typename = $type->getTypeName();
                     foreach ($item as $item_data) {
                         $toadd[] = sprintf(__('%1$s - %2$s'), $typename, $item_data['name']);
                         $tmp['##contract.items.number##']++;
                     }
                 }
             }
             if (count($toadd)) {
                 $tmp["##contract.items##"] = implode(', ', $toadd);
             }
         }
         $this->datas['contracts'][] = $tmp;
     }
     switch ($event) {
         case 'end':
             $this->datas['##lang.contract.time##'] = __('Contract expired since the');
             break;
         case 'notice':
             $this->datas['##lang.contract.time##'] = __('Contract with notice since the');
             break;
         case 'periodicity':
             $this->datas['##lang.contract.time##'] = __('Contract reached the end of a period since the');
             break;
         case 'periodicitynotice':
             $this->datas['##lang.contract.time##'] = __('Contract with notice for the current period since the');
             break;
     }
     $this->getTags();
     foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
         if (!isset($this->datas[$tag])) {
             $this->datas[$tag] = $values['label'];
         }
     }
 }
示例#21
0
 /**
  * Get the group of elements regarding given item.
  * Two kind of item :
  *              - Device* feed by a link to the attached item (Computer, Printer ...)
  *              - Computer, Printer ...: feed by the "global" properties of the CommonDevice
  * Then feed with the specificities of the Item_Device elements
  * In cas of $item is an instance, then $options contains the type of the item (Computer,
  * Printer ...).
  *
  * @param $item
  * @param $table
  * @param $options            array
  * @param $delete_all_column          (default NULL)
  * @param $common_column
  * @param $specific_column
  * @param $delete_column               (default NULL)
  * @param $dynamic_column
  **/
 function getTableGroup(CommonDBTM $item, HTMLTableMain $table, array $options, HTMLTableSuperHeader $delete_all_column = NULL, HTMLTableSuperHeader $common_column, HTMLTableSuperHeader $specific_column, HTMLTableSuperHeader $delete_column = NULL, $dynamic_column)
 {
     global $DB;
     $is_device = $item instanceof CommonDevice;
     if ($is_device) {
         $peer_type = $options['itemtype'];
         if (empty($peer_type)) {
             $column_label = __('Dissociated devices');
             $group_name = 'None';
         } else {
             $column_label = $peer_type::getTypeName(Session::getPluralNumber());
             $group_name = $peer_type;
         }
         $table_group = $table->createGroup($group_name, '');
         $peer_column = $table_group->addHeader('item', $column_label, $common_column, NULL);
         if (!empty($peer_type)) {
             //TRANS : %1$s is the type of the device
             //        %2$s is the type of the item
             //        %3$s is the name of the item (used for headings of a list),
             $itemtype_nav_title = sprintf(__('%1$s of %2$s: %3$s'), $peer_type::getTypeName(Session::getPluralNumber()), $item->getTypeName(1), $item->getName());
             $peer_column->setItemType($peer_type, $itemtype_nav_title);
         }
     } else {
         $peer_type = $this->getDeviceType();
         $table_group = $table->createGroup($peer_type, '');
         //TRANS : %1$s is the type of the device
         //        %2$s is the type of the item
         //        %3$s is the name of the item (used for headings of a list),
         $options['itemtype_title'] = sprintf(__('%1$s of %2$s: %3$s'), $peer_type::getTypeName(Session::getPluralNumber()), $item->getTypeName(1), $item->getName());
         $peer_type::getHTMLTableHeader($item->getType(), $table_group, $common_column, NULL, $options);
     }
     $specificity_columns = array();
     $link_column = $table_group->addHeader('spec_link', '', $specific_column);
     $spec_column = $link_column;
     foreach ($this->getSpecificities() as $field => $attributs) {
         $spec_column = $table_group->addHeader('spec_' . $field, $attributs['long name'], $specific_column, $spec_column);
         $specificity_columns[$field] = $spec_column;
     }
     $infocom_column = $table_group->addHeader('infocom', Infocom::getTypeName(Session::getPluralNumber()), $specific_column, $spec_column);
     $document_column = $table_group->addHeader('document', Document::getTypeName(Session::getPluralNumber()), $specific_column, $spec_column);
     if ($item->isDynamic()) {
         $dynamics_column = $table_group->addHeader('one', '&nbsp;', $dynamic_column, $spec_column);
         $previous_column = $dynamics_column;
     } else {
         $previous_column = $spec_column;
     }
     if ($options['canedit']) {
         $group_checkbox_tag = empty($peer_type) ? '__' : $peer_type;
         $content = Html::getCheckbox(array('criterion' => array('tag_for_massive' => $group_checkbox_tag)));
         $delete_one = $table_group->addHeader('one', $content, $delete_column, $previous_column);
     }
     if ($is_device) {
         $fk = 'items_id';
         // Entity restrict
         $leftjoin = '';
         $where = "";
         if (!empty($peer_type)) {
             $leftjoin = "LEFT JOIN `" . getTableForItemType($peer_type) . "`\n                        ON (`" . $this->getTable() . "`.`items_id` = `" . getTableForItemType($peer_type) . "`.`id`\n                            AND `" . $this->getTable() . "`.`itemtype` = '{$peer_type}')";
             $where = getEntitiesRestrictRequest(" AND", getTableForItemType($peer_type));
         }
         $query = "SELECT `" . $this->getTable() . "`.*\n                   FROM `" . $this->getTable() . "`\n                   {$leftjoin}\n                   WHERE `" . $this->getDeviceForeignKey() . "` = '" . $item->getID() . "'\n                         AND `" . $this->getTable() . "`.`itemtype` = '{$peer_type}'\n                         AND `" . $this->getTable() . "`.`is_deleted` = '0'\n                         {$where}\n                   ORDER BY `" . $this->getTable() . "`.`itemtype`, `" . $this->getTable() . "`.`{$fk}`";
     } else {
         $fk = $this->getDeviceForeignKey();
         $query = "SELECT *\n                   FROM `" . $this->getTable() . "`\n                   WHERE `itemtype` = '" . $item->getType() . "'\n                         AND `items_id` = '" . $item->getID() . "'\n                         AND `is_deleted` = '0'\n                   ORDER BY {$fk}";
     }
     if (!empty($peer_type)) {
         $peer = new $peer_type();
         $peer->getEmpty();
     } else {
         $peer = NULL;
     }
     foreach ($DB->request($query) as $link) {
         Session::addToNavigateListItems(static::getType(), $link["id"]);
         $this->getFromDB($link['id']);
         if (is_null($peer) || $link[$fk] != $peer->getID()) {
             if ($peer instanceof CommonDBTM) {
                 $peer->getFromDB($link[$fk]);
             }
             $current_row = $table_group->createRow();
             $peer_group = $peer_type . '_' . $link[$fk] . '_' . mt_rand();
             $current_row->setHTMLID($peer_group);
             if ($options['canedit']) {
                 $cell_value = Html::getCheckAllAsCheckbox($peer_group);
                 $current_row->addCell($delete_all_column, $cell_value);
             }
             if ($is_device) {
                 $cell = $current_row->addCell($peer_column, $peer ? $peer->getLink() : __('None'), NULL, $peer);
                 if (is_null($peer)) {
                     $cell->setHTMLClass('center');
                 }
             } else {
                 $peer->getHTMLTableCellForItem($current_row, $item, NULL, $options);
             }
         }
         if (Session::haveRight('device', UPDATE)) {
             $mode = __s('Update');
         } else {
             $mode = __s('View');
         }
         $spec_cell = $current_row->addCell($link_column, "<a href='" . $this->getLinkURL() . "'>{$mode}</a>");
         foreach ($this->getSpecificities() as $field => $attributs) {
             if (!empty($link[$field])) {
                 $content = $link[$field];
             } else {
                 $content = '';
             }
             $spec_cell = $current_row->addCell($specificity_columns[$field], $content, $spec_cell);
         }
         if (countElementsInTable('glpi_infocoms', "`itemtype`='" . $this->getType() . "' AND\n                                                    `items_id`='" . $link['id'] . "'")) {
             $content = array(array('function' => 'Infocom::showDisplayLink', 'parameters' => array($this->getType(), $link['id'])));
         } else {
             $content = '';
         }
         $current_row->addCell($infocom_column, $content, $spec_cell);
         $content = array();
         // The order is to be sure that specific documents appear first
         $query = "SELECT `documents_id`\n                   FROM `glpi_documents_items`\n                   WHERE (`itemtype` = '" . $this->getType() . "' AND `items_id` = '" . $link['id'] . "')\n                          OR (`itemtype` = '" . $this->getDeviceType() . "'\n                              AND `items_id` = '" . $link[$this->getDeviceForeignKey()] . "')\n                   ORDER BY `itemtype` = '" . $this->getDeviceType() . "'";
         $document = new Document();
         foreach ($DB->request($query) as $document_link) {
             if ($document->can($document_link['documents_id'], READ)) {
                 $content[] = $document->getLink();
             }
         }
         $content = implode('<br>', $content);
         $current_row->addCell($document_column, $content, $spec_cell);
         if ($item->isDynamic()) {
             $previous_cell = $current_row->addCell($dynamics_column, Dropdown::getYesNo($link['is_dynamic']), $spec_cell);
         } else {
             $previous_cell = $spec_cell;
         }
         if ($options['canedit']) {
             $cell_value = Html::getMassiveActionCheckBox($this->getType(), $link['id'], array('massive_tags' => $group_checkbox_tag));
             $current_row->addCell($delete_one, $cell_value, $previous_cell);
         }
     }
 }
示例#22
0
/** Display an infocom report for items like consumables
 *
 * @param $itemtype  item type
 * @param $begin     begin date
 * @param $end       end date
**/
function display_infocoms_report($itemtype, $begin, $end)
{
    global $DB, $valeurtot, $valeurnettetot, $valeurnettegraphtot, $valeurgraphtot, $CFG_GLPI;
    $itemtable = getTableForItemType($itemtype);
    $query = "SELECT `glpi_infocoms`.*\n             FROM `glpi_infocoms`\n             INNER JOIN `{$itemtable}`\n                  ON (`{$itemtable}`.`id` = `glpi_infocoms`.`items_id`\n                      AND `glpi_infocoms`.`itemtype`='{$itemtype}') ";
    switch ($itemtype) {
        case 'Consumable':
            $query .= " INNER JOIN `glpi_consumableitems`\n                        ON (`glpi_consumables`.`consumableitems_id` = `glpi_consumableitems`.`id`) " . getEntitiesRestrictRequest("WHERE", "glpi_consumableitems");
            break;
        case 'Cartridge':
            $query .= " INNER JOIN `glpi_cartridgeitems`\n                        ON (`glpi_cartridges`.`cartridgeitems_id` = `glpi_cartridgeitems`.`id`) " . getEntitiesRestrictRequest("WHERE", "glpi_cartridgeitems");
            break;
        case 'SoftwareLicense':
            $query .= " INNER JOIN `glpi_softwares`\n                        ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`) " . getEntitiesRestrictRequest("WHERE", "glpi_softwarelicenses");
            break;
    }
    if (!empty($begin)) {
        $query .= " AND (`glpi_infocoms`.`buy_date` >= '{$begin}'\n                       OR `glpi_infocoms`.`use_date` >= '{$begin}')";
    }
    if (!empty($end)) {
        $query .= " AND (`glpi_infocoms`.`buy_date` <= '{$end}'\n                       OR `glpi_infocoms`.`use_date` <= '{$end}')";
    }
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0 && ($item = getItemForItemtype($itemtype))) {
            echo "<h2>" . $item->getTypeName(1) . "</h2>";
            echo "<table class='tab_cadre'>";
            $valeursoustot = 0;
            $valeurnettesoustot = 0;
            $valeurnettegraph = array();
            $valeurgraph = array();
            while ($line = $DB->fetch_assoc($result)) {
                if ($itemtype == 'SoftwareLicense') {
                    $item->getFromDB($line["items_id"]);
                    if ($item->fields["serial"] == "global") {
                        if ($item->fields["number"] > 0) {
                            $line["value"] *= $item->fields["number"];
                        }
                    }
                }
                if ($line["value"] > 0) {
                    $valeursoustot += $line["value"];
                }
                $valeurnette = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "n");
                $tmp = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "all");
                if (is_array($tmp) && count($tmp) > 0) {
                    foreach ($tmp["annee"] as $key => $val) {
                        if ($tmp["vcnetfin"][$key] > 0) {
                            if (!isset($valeurnettegraph[$val])) {
                                $valeurnettegraph[$val] = 0;
                            }
                            $valeurnettegraph[$val] += $tmp["vcnetdeb"][$key];
                        }
                    }
                }
                if (!empty($line["buy_date"])) {
                    $year = substr($line["buy_date"], 0, 4);
                    if ($line["value"] > 0) {
                        if (!isset($valeurgraph[$year])) {
                            $valeurgraph[$year] = 0;
                        }
                        $valeurgraph[$year] += $line["value"];
                    }
                }
                $valeurnettesoustot += str_replace(" ", "", $valeurnette);
            }
            $valeurtot += $valeursoustot;
            $valeurnettetot += $valeurnettesoustot;
            if (count($valeurnettegraph) > 0) {
                echo "<tr><td colspan='5' class='center'>";
                ksort($valeurnettegraph);
                $valeurnettegraphdisplay = array_map('round', $valeurnettegraph);
                foreach ($valeurnettegraph as $key => $val) {
                    if (!isset($valeurnettegraphtot[$key])) {
                        $valeurnettegraphtot[$key] = 0;
                    }
                    $valeurnettegraphtot[$key] += $valeurnettegraph[$key];
                }
                Stat::showGraph(array(__('Account net value') => $valeurnettegraphdisplay), array('title' => __('Account net value'), 'width' => 400));
                echo "</td></tr>\n";
            }
            if (count($valeurgraph) > 0) {
                echo "<tr><td colspan='5' class='center'>";
                ksort($valeurgraph);
                $valeurgraphdisplay = array_map('round', $valeurgraph);
                foreach ($valeurgraph as $key => $val) {
                    if (!isset($valeurgraphtot[$key])) {
                        $valeurgraphtot[$key] = 0;
                    }
                    $valeurgraphtot[$key] += $valeurgraph[$key];
                }
                Stat::showGraph(array(_x('price', 'Value') => $valeurgraphdisplay), array('title' => _x('price', 'Value'), 'width' => 400));
                echo "</td></tr>";
            }
            echo "</table>\n";
            return true;
        }
    }
    return false;
}
示例#23
0
 /**
  * Get the SEARCH_OPTION array
  *
  * @param $itemtype
  * @param $withplugins boolean get search options from plugins (true by default)
  *
  * @return the reference to  array of search options for the given item type
  **/
 static function &getOptions($itemtype, $withplugins = true)
 {
     global $CFG_GLPI;
     static $search = array();
     $item = NULL;
     if (!isset($search[$itemtype])) {
         // standard type first
         switch ($itemtype) {
             case 'Internet':
                 $search[$itemtype]['common'] = __('Characteristics');
                 $search[$itemtype][1]['table'] = 'networkport_types';
                 $search[$itemtype][1]['field'] = 'name';
                 $search[$itemtype][1]['name'] = __('Name');
                 $search[$itemtype][1]['datatype'] = 'itemlink';
                 $search[$itemtype][1]['searchtype'] = 'contains';
                 $search[$itemtype][2]['table'] = 'networkport_types';
                 $search[$itemtype][2]['field'] = 'id';
                 $search[$itemtype][2]['name'] = __('ID');
                 $search[$itemtype][2]['searchtype'] = 'contains';
                 $search[$itemtype][31]['table'] = 'glpi_states';
                 $search[$itemtype][31]['field'] = 'completename';
                 $search[$itemtype][31]['name'] = __('Status');
                 $search[$itemtype] += NetworkPort::getSearchOptionsToAdd('networkport_types');
                 break;
             case 'AllAssets':
                 $search[$itemtype]['common'] = __('Characteristics');
                 $search[$itemtype][1]['table'] = 'asset_types';
                 $search[$itemtype][1]['field'] = 'name';
                 $search[$itemtype][1]['name'] = __('Name');
                 $search[$itemtype][1]['datatype'] = 'itemlink';
                 $search[$itemtype][1]['searchtype'] = 'contains';
                 $search[$itemtype][2]['table'] = 'asset_types';
                 $search[$itemtype][2]['field'] = 'id';
                 $search[$itemtype][2]['name'] = __('ID');
                 $search[$itemtype][2]['searchtype'] = 'contains';
                 $search[$itemtype][31]['table'] = 'glpi_states';
                 $search[$itemtype][31]['field'] = 'completename';
                 $search[$itemtype][31]['name'] = __('Status');
                 $search[$itemtype] += Location::getSearchOptionsToAdd();
                 $search[$itemtype][5]['table'] = 'asset_types';
                 $search[$itemtype][5]['field'] = 'serial';
                 $search[$itemtype][5]['name'] = __('Serial number');
                 $search[$itemtype][6]['table'] = 'asset_types';
                 $search[$itemtype][6]['field'] = 'otherserial';
                 $search[$itemtype][6]['name'] = __('Inventory number');
                 $search[$itemtype][16]['table'] = 'asset_types';
                 $search[$itemtype][16]['field'] = 'comment';
                 $search[$itemtype][16]['name'] = __('Comments');
                 $search[$itemtype][16]['datatype'] = 'text';
                 $search[$itemtype][70]['table'] = 'glpi_users';
                 $search[$itemtype][70]['field'] = 'name';
                 $search[$itemtype][70]['name'] = __('User');
                 $search[$itemtype][7]['table'] = 'asset_types';
                 $search[$itemtype][7]['field'] = 'contact';
                 $search[$itemtype][7]['name'] = __('Alternate username');
                 $search[$itemtype][7]['datatype'] = 'string';
                 $search[$itemtype][8]['table'] = 'asset_types';
                 $search[$itemtype][8]['field'] = 'contact_num';
                 $search[$itemtype][8]['name'] = __('Alternate username number');
                 $search[$itemtype][8]['datatype'] = 'string';
                 $search[$itemtype][71]['table'] = 'glpi_groups';
                 $search[$itemtype][71]['field'] = 'completename';
                 $search[$itemtype][71]['name'] = __('Group');
                 $search[$itemtype][19]['table'] = 'asset_types';
                 $search[$itemtype][19]['field'] = 'date_mod';
                 $search[$itemtype][19]['name'] = __('Last update');
                 $search[$itemtype][19]['datatype'] = 'datetime';
                 $search[$itemtype][19]['massiveaction'] = false;
                 $search[$itemtype][23]['table'] = 'glpi_manufacturers';
                 $search[$itemtype][23]['field'] = 'name';
                 $search[$itemtype][23]['name'] = __('Manufacturer');
                 $search[$itemtype][24]['table'] = 'glpi_users';
                 $search[$itemtype][24]['field'] = 'name';
                 $search[$itemtype][24]['linkfield'] = 'users_id_tech';
                 $search[$itemtype][24]['name'] = __('Technician in charge of the hardware');
                 $search[$itemtype][80]['table'] = 'glpi_entities';
                 $search[$itemtype][80]['field'] = 'completename';
                 $search[$itemtype][80]['name'] = __('Entity');
                 break;
             default:
                 if ($item = getItemForItemtype($itemtype)) {
                     $search[$itemtype] = $item->getSearchOptions();
                 }
                 break;
         }
         if (Session::getLoginUserID() && in_array($itemtype, $CFG_GLPI["ticket_types"])) {
             $search[$itemtype]['tracking'] = __('Assistance');
             $search[$itemtype][60]['table'] = 'glpi_tickets';
             $search[$itemtype][60]['field'] = 'id';
             $search[$itemtype][60]['datatype'] = 'count';
             $search[$itemtype][60]['name'] = _x('quantity', 'Number of tickets');
             $search[$itemtype][60]['forcegroupby'] = true;
             $search[$itemtype][60]['usehaving'] = true;
             $search[$itemtype][60]['massiveaction'] = false;
             $search[$itemtype][60]['joinparams'] = array('beforejoin' => array('table' => 'glpi_items_tickets', 'joinparams' => array('jointype' => 'itemtype_item')), 'condition' => getEntitiesRestrictRequest('AND', 'NEWTABLE'));
             $search[$itemtype][140]['table'] = 'glpi_problems';
             $search[$itemtype][140]['field'] = 'id';
             $search[$itemtype][140]['datatype'] = 'count';
             $search[$itemtype][140]['name'] = _x('quantity', 'Number of problems');
             $search[$itemtype][140]['forcegroupby'] = true;
             $search[$itemtype][140]['usehaving'] = true;
             $search[$itemtype][140]['massiveaction'] = false;
             $search[$itemtype][140]['joinparams'] = array('beforejoin' => array('table' => 'glpi_items_problems', 'joinparams' => array('jointype' => 'itemtype_item')), 'condition' => getEntitiesRestrictRequest('AND', 'NEWTABLE'));
         }
         if (in_array($itemtype, $CFG_GLPI["networkport_types"]) || $itemtype == 'AllAssets') {
             $search[$itemtype] += NetworkPort::getSearchOptionsToAdd($itemtype);
         }
         if (in_array($itemtype, $CFG_GLPI["contract_types"]) || $itemtype == 'AllAssets') {
             $search[$itemtype] += Contract::getSearchOptionsToAdd();
         }
         if (Document::canApplyOn($itemtype) || $itemtype == 'AllAssets') {
             $search[$itemtype] += Document::getSearchOptionsToAdd();
         }
         if (InfoCom::canApplyOn($itemtype) || $itemtype == 'AllAssets') {
             $search[$itemtype] += Infocom::getSearchOptionsToAdd($itemtype);
         }
         if (in_array($itemtype, $CFG_GLPI["link_types"])) {
             $search[$itemtype]['link'] = _n('External link', 'External links', Session::getPluralNumber());
             $search[$itemtype] += Link::getSearchOptionsToAdd($itemtype);
         }
         if ($withplugins) {
             // Search options added by plugins
             $plugsearch = Plugin::getAddSearchOptions($itemtype);
             if (count($plugsearch)) {
                 $search[$itemtype] += array('plugins' => _n('Plugin', 'Plugins', Session::getPluralNumber()));
                 $search[$itemtype] += $plugsearch;
             }
         }
         // Complete linkfield if not define
         if (is_null($item)) {
             // Special union type
             $itemtable = $CFG_GLPI['union_search_type'][$itemtype];
         } else {
             if ($item = getItemForItemtype($itemtype)) {
                 $itemtable = $item->getTable();
             }
         }
         foreach ($search[$itemtype] as $key => $val) {
             if (!is_array($val)) {
                 // skip sub-menu
                 continue;
             }
             // Compatibility before 0.80 : Force massive action to false if linkfield is empty :
             if (isset($val['linkfield']) && empty($val['linkfield'])) {
                 $search[$itemtype][$key]['massiveaction'] = false;
             }
             // Set default linkfield
             if (!isset($val['linkfield']) || empty($val['linkfield'])) {
                 if (strcmp($itemtable, $val['table']) == 0 && (!isset($val['joinparams']) || count($val['joinparams']) == 0)) {
                     $search[$itemtype][$key]['linkfield'] = $val['field'];
                 } else {
                     $search[$itemtype][$key]['linkfield'] = getForeignKeyFieldForTable($val['table']);
                 }
             }
             // Set default datatype
             //             if (!isset($val['datatype']) || empty($val['datatype'])) {
             //                if ((strcmp($itemtable,$val['table']) != 0)
             //                    && ($val['field'] == 'name' || $val['field'] == 'completename')) {
             //                   $search[$itemtype][$key]['datatype'] = 'dropdown';
             //                } else {
             //                   $search[$itemtype][$key]['datatype'] = 'string';
             //                }
             //             }
             // Add default joinparams
             if (!isset($val['joinparams'])) {
                 $search[$itemtype][$key]['joinparams'] = array();
             }
         }
     }
     return $search[$itemtype];
 }
示例#24
0
 /**
  * Cron action on contracts : alert depending of the config : on notice and expire
  *
  * @param $task for log, if NULL display (default NULL)
  **/
 static function cronContract($task = NULL)
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $message = array();
     $items_notice = array();
     $items_end = array();
     $cron_status = 0;
     $contract_infos[Alert::END] = array();
     $contract_infos[Alert::NOTICE] = array();
     $contract_messages = array();
     foreach (Entity::getEntitiesToNotify('use_contracts_alert') as $entity => $value) {
         $before = Entity::getUsedConfig('send_contracts_alert_before_delay', $entity);
         $query_notice = "SELECT `glpi_contracts`.*\n                          FROM `glpi_contracts`\n                          LEFT JOIN `glpi_alerts`\n                              ON (`glpi_contracts`.`id` = `glpi_alerts`.`items_id`\n                                  AND `glpi_alerts`.`itemtype` = 'Contract'\n                                  AND `glpi_alerts`.`type`='" . Alert::NOTICE . "')\n                          WHERE (`glpi_contracts`.`alert` & " . pow(2, Alert::NOTICE) . ") >'0'\n                                AND `glpi_contracts`.`is_deleted` = '0'\n                                AND `glpi_contracts`.`begin_date` IS NOT NULL\n                                AND `glpi_contracts`.`duration` <> '0'\n                                AND `glpi_contracts`.`notice` <> '0'\n                                AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n                                                     INTERVAL `glpi_contracts`.`duration` MONTH),\n                                             CURDATE()) > '0'\n                                AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n                                                     INTERVAL (`glpi_contracts`.`duration`\n                                                                -`glpi_contracts`.`notice`) MONTH),\n                                             CURDATE()) < '{$before}'\n                                AND `glpi_alerts`.`date` IS NULL\n                                AND `glpi_contracts`.`entities_id` = '" . $entity . "'";
         $query_end = "SELECT `glpi_contracts`.*\n                       FROM `glpi_contracts`\n                       LEFT JOIN `glpi_alerts`\n                           ON (`glpi_contracts`.`id` = `glpi_alerts`.`items_id`\n                               AND `glpi_alerts`.`itemtype` = 'Contract'\n                               AND `glpi_alerts`.`type`='" . Alert::END . "')\n                       WHERE (`glpi_contracts`.`alert` & " . pow(2, Alert::END) . ") > '0'\n                             AND `glpi_contracts`.`is_deleted` = '0'\n                             AND `glpi_contracts`.`begin_date` IS NOT NULL\n                             AND `glpi_contracts`.`duration` <> '0'\n                             AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n                                                  INTERVAL (`glpi_contracts`.`duration`) MONTH),\n                                          CURDATE()) < '{$before}'\n                             AND `glpi_alerts`.`date` IS NULL\n                             AND `glpi_contracts`.`entities_id` = '" . $entity . "'";
         $querys = array('notice' => $query_notice, 'end' => $query_end);
         foreach ($querys as $type => $query) {
             foreach ($DB->request($query) as $data) {
                 $entity = $data['entities_id'];
                 $message = sprintf(__('%1$s: %2$s') . "<br>\n", $data["name"], Infocom::getWarrantyExpir($data["begin_date"], $data["duration"], $data["notice"]));
                 $contract_infos[$type][$entity][$data['id']] = $data;
                 if (!isset($contract_messages[$type][$entity])) {
                     switch ($type) {
                         case 'notice':
                             $contract_messages[$type][$entity] = __('Contract entered in notice time') . "<br>";
                             break;
                         case 'end':
                             $contract_messages[$type][$entity] = __('Contract ended') . "<br>";
                             break;
                     }
                 }
                 $contract_messages[$type][$entity] .= $message;
             }
         }
         // Get contrats with periodicity alerts
         $query_periodicity = "SELECT `glpi_contracts`.*\n                               FROM `glpi_contracts`\n                               WHERE `glpi_contracts`.`alert` & " . pow(2, Alert::PERIODICITY) . " > '0'\n                                     AND `glpi_contracts`.`entities_id` = '" . $entity . "' ";
         // Foreach ones :
         foreach ($DB->request($query_periodicity) as $data) {
             $entity = $data['entities_id'];
             // Compute end date + 12 month : do not send alerts after
             $end_alert = date('Y-m-d', strtotime($data['begin_date'] . " +" . ($data['duration'] + 12) . " month"));
             if (!empty($data['begin_date']) && $data['periodicity'] && $end_alert > date('Y-m-d')) {
                 $todo = array('periodicity' => Alert::PERIODICITY);
                 if ($data['alert'] & pow(2, Alert::NOTICE)) {
                     $todo['periodicitynotice'] = Alert::NOTICE;
                 }
                 // Get previous alerts
                 foreach ($todo as $type => $event) {
                     $previous_alerts[$type] = Alert::getAlertDate(__CLASS__, $data['id'], $event);
                 }
                 // compute next alert date based on already send alerts (or not)
                 foreach ($todo as $type => $event) {
                     $next_alerts[$type] = date('Y-m-d', strtotime($data['begin_date'] . " -" . $before . " day"));
                     if ($type == Alert::NOTICE) {
                         $next_alerts[$type] = date('Y-m-d', strtotime($next_alerts[$type] . " -" . $data['notice'] . " month"));
                     }
                     $today_limit = date('Y-m-d', strtotime(date('Y-m-d') . " -" . $data['periodicity'] . " month"));
                     // Init previous by begin date if not set
                     if (empty($previous_alerts[$type])) {
                         $previous_alerts[$type] = $today_limit;
                     }
                     while ($next_alerts[$type] < $previous_alerts[$type] && $next_alerts[$type] < $end_alert) {
                         $next_alerts[$type] = date('Y-m-d', strtotime($next_alerts[$type] . " +" . $data['periodicity'] . " month"));
                     }
                     // If this date is passed : clean alerts and send again
                     if ($next_alerts[$type] <= date('Y-m-d')) {
                         $alert = new Alert();
                         $alert->clear(__CLASS__, $data['id'], $event);
                         $real_alert_date = date('Y-m-d', strtotime($next_alerts[$type] . " +" . $before . " day"));
                         $message = sprintf(__('%1$s: %2$s') . "<br>\n", $data["name"], Html::convDate($real_alert_date));
                         $data['alert_date'] = $real_alert_date;
                         $data['items'] = Contract_Item::getItemsForContract($data['id'], $entity);
                         $contract_infos[$type][$entity][$data['id']] = $data;
                         switch ($type) {
                             case 'periodicitynotice':
                                 $contract_messages[$type][$entity] = __('Contract entered in notice time for period') . "<br>";
                                 break;
                             case 'periodicity':
                                 $contract_messages[$type][$entity] = __('Contract period ended') . "<br>";
                                 break;
                         }
                         $contract_messages[$type][$entity] .= $message;
                     }
                 }
             }
         }
     }
     foreach (array('notice' => Alert::NOTICE, 'end' => Alert::END, 'periodicity' => Alert::PERIODICITY, 'periodicitynotice' => Alert::NOTICE) as $event => $type) {
         if (isset($contract_infos[$event]) && count($contract_infos[$event])) {
             foreach ($contract_infos[$event] as $entity => $contracts) {
                 if (NotificationEvent::raiseEvent($event, new self(), array('entities_id' => $entity, 'items' => $contracts))) {
                     $message = $contract_messages[$event][$entity];
                     $cron_status = 1;
                     $entityname = Dropdown::getDropdownName("glpi_entities", $entity);
                     if ($task) {
                         $task->log(sprintf(__('%1$s: %2$s') . "\n", $entityname, $message));
                         $task->addVolume(1);
                     } else {
                         Session::addMessageAfterRedirect(sprintf(__('%1$s: %2$s'), $entityname, $message));
                     }
                     $alert = new Alert();
                     $input["itemtype"] = __CLASS__;
                     $input["type"] = $type;
                     foreach ($contracts as $id => $contract) {
                         $input["items_id"] = $id;
                         $alert->add($input);
                         unset($alert->fields['id']);
                     }
                 } else {
                     $entityname = Dropdown::getDropdownName('glpi_entities', $entity);
                     //TRANS: %1$s is entity name, %2$s is the message
                     $msg = sprintf(__('%1$s: %2$s'), $entityname, __('send contract alert failed'));
                     if ($task) {
                         $task->log($msg);
                     } else {
                         Session::addMessageAfterRedirect($msg, false, ERROR);
                     }
                 }
             }
         }
     }
     return $cron_status;
 }
示例#25
0
 /**
  * Print an HTML array with contracts associated to the enterprise
  *
  * @since version 0.84
  *
  * @param $supplier   Supplier object
  *
  * @return Nothing (display)
  **/
 static function showForSupplier(Supplier $supplier)
 {
     global $DB, $CFG_GLPI;
     $ID = $supplier->fields['id'];
     if (!Session::haveRight("contract", "r") || !$supplier->can($ID, 'r')) {
         return false;
     }
     $canedit = $supplier->can($ID, 'w');
     $rand = mt_rand();
     $query = "SELECT `glpi_contracts`.*,\n                       `glpi_contracts_suppliers`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity\n                FROM `glpi_contracts_suppliers`, `glpi_contracts`\n                LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contracts`.`entities_id`)\n                WHERE `glpi_contracts_suppliers`.`suppliers_id` = '{$ID}'\n                      AND `glpi_contracts_suppliers`.`contracts_id`=`glpi_contracts`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n                ORDER BY `glpi_entities`.`completename`,\n                         `glpi_contracts`.`name`";
     $result = $DB->query($query);
     $contracts = array();
     $used = array();
     if ($number = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $contracts[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='contractsupplier_form{$rand}' id='contractsupplier_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<input type='hidden' name='suppliers_id' value='{$ID}'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a contract') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         Contract::dropdown(array('used' => $used, 'entity' => $supplier->fields["entities_id"], 'entity_sons' => $supplier->fields["is_recursive"], 'nochecklimit' => true));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('Entity') . "</th>";
     echo "<th>" . _x('phone', 'Number') . "</th>";
     echo "<th>" . __('Contract type') . "</th>";
     echo "<th>" . __('Start date') . "</th>";
     echo "<th>" . __('Initial contract period') . "</th>";
     echo "</tr>";
     $used = array();
     foreach ($contracts as $data) {
         $cID = $data["id"];
         $used[$cID] = $cID;
         $assocID = $data["assocID"];
         echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
         if ($canedit) {
             echo "<td>";
             Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
             echo "</td>";
         }
         $name = $data["name"];
         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
             $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
         }
         echo "<td class='center b'>\n               <a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>" . $name . "</a>";
         echo "</td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]);
         echo "</td><td class='center'>" . $data["num"] . "</td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contracttypes", $data["contracttypes_id"]) . "</td>";
         echo "<td class='center'>" . Html::convDate($data["begin_date"]) . "</td>";
         echo "<td class='center'>";
         sprintf(_n('%d month', '%d months', $data["duration"]), $data["duration"]);
         if ($data["begin_date"] != '' && !empty($data["begin_date"])) {
             echo " -> " . Infocom::getWarrantyExpir($data["begin_date"], $data["duration"], 0, true);
         }
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
示例#26
0
 /**
  * @since version 0.84
  *
  * @param $field
  * @param $name               (default '')
  * @param $values             (default '')
  * @param $options      array
  **/
 static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = array())
 {
     global $DB;
     if (!is_array($values)) {
         $values = array($field => $values);
     }
     $options['display'] = false;
     switch ($field) {
         case 'use_licenses_alert':
         case 'use_contracts_alert':
         case 'use_infocoms_alert':
             $options['name'] = $name;
             $options['value'] = $values[$field];
             return Alert::dropdownYesNo($options);
         case 'cartridges_alert_repeat':
         case 'consumables_alert_repeat':
             $options['name'] = $name;
             $options['value'] = $values[$field];
             return Alert::dropdown($options);
         case 'send_contracts_alert_before_delay':
         case 'send_infocoms_alert_before_delay':
         case 'send_licenses_alert_before_delay':
             $options['unit'] = 'day';
             $options['never_string'] = __('No');
             return Alert::dropdownIntegerNever($name, $values[$field], $options);
         case 'use_reservations_alert':
             $options['unit'] = 'hour';
             return Alert::dropdownIntegerNever($name, $values[$field], $options);
         case 'notclosed_delay':
             $options['unit'] = 'hour';
             return Alert::dropdownIntegerNever($name, $values[$field], $options);
         case 'auto_assign_mode':
             $options['name'] = $name;
             $options['value'] = $values[$field];
             return self::dropdownAutoAssignMode($options);
         case 'tickettype':
             $options['value'] = $values[$field];
             $options['toadd'] = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'));
             return Ticket::dropdownType($name, $options);
         case 'autofill_buy_date':
         case 'autofill_order_date':
         case 'autofill_delivery_date':
         case 'autofill_use_date':
             $tab[0] = __('No autofill');
             $tab[self::CONFIG_PARENT] = __('Inheritance of the parent entity');
             foreach (getAllDatasFromTable('glpi_states') as $state) {
                 $tab[Infocom::ON_STATUS_CHANGE . '_' . $state['id']] = sprintf(__('Fill when shifting to state %s'), $state['name']);
             }
             $tab[Infocom::COPY_WARRANTY_DATE] = __('Copy the start date of warranty');
             if ($field != 'autofill_buy_date') {
                 $tab[Infocom::COPY_BUY_DATE] = __('Copy the date of purchase');
                 if ($field != 'autofill_order_date') {
                     $tab[Infocom::COPY_ORDER_DATE] = __('Copy the order date');
                     if ($field != 'autofill_delivery_date') {
                         $options[Infocom::COPY_DELIVERY_DATE] = __('Copy the delivery date');
                     }
                 }
             }
             $options['value'] = $values[$field];
             return Dropdown::showFromArray($name, $tab, $options);
         case 'autofill_warranty_date':
             $tab = array(0 => __('No autofill'), Infocom::COPY_BUY_DATE => __('Copy the date of purchase'), Infocom::COPY_ORDER_DATE => __('Copy the order date'), Infocom::COPY_DELIVERY_DATE => __('Copy the delivery date'), self::CONFIG_PARENT => __('Inheritance of the parent entity'));
             $options['value'] = $values[$field];
             return Dropdown::showFromArray($name, $tab, $options);
         case 'inquest_config':
             $typeinquest = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'), 1 => __('Internal survey'), 2 => __('External survey'));
             $options['value'] = $values[$field];
             return Dropdown::showFromArray($name, $typeinquest, $options);
         case 'default_contract_alert':
             $options['name'] = $name;
             $options['value'] = $values[$field];
             return Contract::dropdownAlert($options);
         case 'default_infocom_alert':
             $options['name'] = $name;
             $options['value'] = $values[$field];
             return Infocom::dropdownAlert($options);
         case 'entities_id_software':
             $options['toadd'] = array(self::CONFIG_NEVER => __('No change of entity'));
             // Keep software in PC entity
             $options['toadd'][self::CONFIG_PARENT] = __('Inheritance of the parent entity');
             return self::dropdown($options);
     }
     return parent::getSpecificValueToSelect($field, $name, $values, $options);
 }
                }
        }
    }
} else {
    switch ($_REQUEST['glpi_tab']) {
        case -1:
            NetworkPort::showForItem('NetworkEquipment', $_POST["id"]);
            Infocom::showForItem($netdevice);
            Contract::showAssociated($netdevice);
            Document::showAssociated($netdevice, $_POST["withtemplate"]);
            Ticket::showListForItem('NetworkEquipment', $_POST["id"]);
            Link::showForItem('NetworkEquipment', $_POST["id"]);
            Plugin::displayAction($netdevice, $_REQUEST['glpi_tab']);
            break;
        case 4:
            Infocom::showForItem($netdevice);
            Contract::showAssociated($netdevice);
            break;
        case 5:
            Document::showAssociated($netdevice, $_POST["withtemplate"]);
            break;
        case 6:
            Ticket::showListForItem('NetworkEquipment', $_POST["id"]);
            break;
        case 7:
            Link::showForItem('NetworkEquipment', $_POST["id"]);
            break;
        case 10:
            showNotesForm($_POST['target'], 'NetworkEquipment', $_POST["id"]);
            break;
        case 11:
示例#28
0
 public function post_updateItem($history = 1)
 {
     global $DB;
     $config = PluginOrderConfig::getConfig();
     if ($config->fields['transmit_budget_change'] && in_array('budgets_id', $this->updates)) {
         $infocom = new Infocom();
         $query = "SELECT `items_id`, `itemtype`\n                   FROM `glpi_plugin_order_orders_items`\n                   WHERE `plugin_order_orders_id`='" . $this->getID() . "'";
         foreach ($DB->request($query) as $infos) {
             $infocom->getFromDBforDevice($infos['itemtype'], $infos['items_id']);
             $infocom->update(array('id' => $infocom->getID(), 'budgets_id' => $this->fields['budgets_id']));
         }
     }
 }
示例#29
0
    $bill->redirectToList();
}
if (isset($_POST['action'])) {
    // Retrieve configuration for generate assets feature
    $order_item = new PluginOrderOrder_Item();
    switch ($_POST['chooseAction']) {
        case 'bill':
        case 'state':
            if (isset($_POST["item"])) {
                foreach ($_POST["item"] as $key => $val) {
                    if ($val == 1) {
                        $tmp = $_POST;
                        $tmp['id'] = $key;
                        $order_item->update($tmp);
                        // Update infocom
                        $ic = new Infocom();
                        $ic->getFromDBforDevice($order_item->fields['itemtype'], $order_item->fields['items_id']);
                        $config = PluginOrderConfig::getConfig();
                        if ($config->canAddBillDetails()) {
                            if ($bill->getFromDB($_POST["plugin_order_bills_id"])) {
                                $fields['id'] = $ic->fields['id'];
                                $fields['bill'] = $bill->fields['number'];
                                $fields['warranty_date'] = $bill->fields['billdate'];
                            }
                        }
                        $ic->update($fields);
                    }
                }
            }
            break;
    }
 /**
  * Show report title
  **/
 static function title()
 {
     global $PLUGIN_HOOKS, $CFG_GLPI;
     // Report generation
     // Default Report included
     $report_list["default"]["name"] = __('Default report');
     $report_list["default"]["file"] = "report.default.php";
     if (Contract::canView()) {
         // Rapport ajoute par GLPI V0.2
         $report_list["Contrats"]["name"] = __('By contract');
         $report_list["Contrats"]["file"] = "report.contract.php";
     }
     if (Infocom::canView()) {
         $report_list["Par_annee"]["name"] = __('By year');
         $report_list["Par_annee"]["file"] = "report.year.php";
         $report_list["Infocoms"]["name"] = __('Hardware financial and administrative information');
         $report_list["Infocoms"]["file"] = "report.infocom.php";
         $report_list["Infocoms2"]["name"] = __('Other financial and administrative information (licenses, cartridges, consumables)');
         $report_list["Infocoms2"]["file"] = "report.infocom.conso.php";
     }
     if (Session::haveRight("networking", READ)) {
         $report_list["Rapport prises reseau"]["name"] = __('Network report');
         $report_list["Rapport prises reseau"]["file"] = "report.networking.php";
     }
     if (Session::haveRight("reservation", READ)) {
         $report_list["reservation"]["name"] = __('Loan');
         $report_list["reservation"]["file"] = "report.reservation.php";
     }
     if (Computer::canView() || Monitor::canView() || Session::haveRight("networking", READ) || Peripheral::canView() || Printer::canView() || Phone::canView()) {
         $report_list["state"]["name"] = _n('Status', 'Statuses', Session::getPluralNumber());
         $report_list["state"]["file"] = "report.state.php";
     }
     //Affichage du tableau de presentation des stats
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . __('Select the report you want to generate') . "</th></tr>";
     echo "<tr class='tab_bg_1'><td class='center'>";
     $count = count($report_list);
     $selected = -1;
     $values = array($CFG_GLPI["root_doc"] . '/front/report.php' => Dropdown::EMPTY_VALUE);
     while ($data = each($report_list)) {
         $val = $data[0];
         $name = $report_list["{$val}"]["name"];
         $file = $report_list["{$val}"]["file"];
         $key = $CFG_GLPI["root_doc"] . "/front/" . $file;
         $values[$key] = $name;
         if (stripos($_SERVER['REQUEST_URI'], $key) !== false) {
             $selected = $key;
         }
     }
     $names = array();
     $optgroup = array();
     if (isset($PLUGIN_HOOKS["reports"]) && is_array($PLUGIN_HOOKS["reports"])) {
         foreach ($PLUGIN_HOOKS["reports"] as $plug => $pages) {
             if (is_array($pages) && count($pages)) {
                 foreach ($pages as $page => $name) {
                     $names[$plug . '/' . $page] = array("name" => $name, "plug" => $plug);
                     $optgroup[$plug] = Plugin::getInfo($plug, 'name');
                 }
             }
         }
         asort($names);
     }
     foreach ($optgroup as $opt => $title) {
         $group = $title;
         foreach ($names as $key => $val) {
             if ($opt == $val["plug"]) {
                 $file = $CFG_GLPI["root_doc"] . "/plugins/" . $key;
                 $values[$group][$file] = $val["name"];
                 if (stripos($_SERVER['REQUEST_URI'], $file) !== false) {
                     $selected = $file;
                 }
             }
         }
     }
     Dropdown::showFromArray('statmenu', $values, array('on_change' => "window.location.href=this.options[this.selectedIndex].value", 'value' => $selected));
     echo "</td>";
     echo "</tr>";
     echo "</table>";
 }