Example #1
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'activate':
             $ic = new self();
             if ($ic->canCreate()) {
                 $itemtype = $item->getType();
                 foreach ($ids as $key) {
                     if (!$ic->getFromDBforDevice($itemtype, $key)) {
                         $input = array('itemtype' => $itemtype, 'items_id' => $key);
                         if ($ic->can(-1, CREATE, $input)) {
                             if ($ic->add($input)) {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                                 $ma->addMessage($ic->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_NORIGHT);
                             $ma->addMessage($ic->getErrorMessage(ERROR_RIGHT));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO);
                         $ma->addMessage($ic->getErrorMessage(ERROR_NOT_FOUND));
                     }
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Example #2
0
 /**
  * Duplicate infocoms from an item template to its clone
  *
  * @param $itemtype     itemtype of the item
  * @param $oldid        ID of the item to clone
  * @param $newid        ID of the item cloned
  * @param $newitemtype  itemtype of the new item (= $itemtype if empty) (default '')
  **/
 static function cloneItem($itemtype, $oldid, $newid, $newitemtype = '')
 {
     global $DB;
     $ic = new self();
     if ($ic->getFromDBforDevice($itemtype, $oldid)) {
         $input = $ic->fields;
         $input = Toolbox::addslashes_deep($input);
         $input['items_id'] = $newid;
         if (!empty($newitemtype)) {
             $input['itemtype'] = $newitemtype;
         }
         unset($input["id"]);
         if (isset($input["immo_number"])) {
             $input["immo_number"] = autoName($input["immo_number"], "immo_number", 1, 'Infocom', $input['entities_id']);
         }
         $date_fields = array('buy_date', 'delivery_date', 'inventory_date', 'order_date', 'use_date', 'warranty_date');
         foreach ($date_fields as $f) {
             if (empty($input[$f])) {
                 unset($input[$f]);
             }
         }
         $ic2 = new self();
         $ic2->add($input);
     }
 }
 /**
  * Show Infocom form for an item (not a standard showForm)
  *
  * @param $item CommonDBTM object
  * @param $withtemplate integer: template or basic item
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $CFG_GLPI, $LANG;
     // Show Infocom or blank form
     if (!haveRight("infocom", "r")) {
         return false;
     }
     if (!$item) {
         echo "<div class='spaced'>" . $LANG['financial'][85] . "</div>";
     } else {
         $date_tax = $CFG_GLPI["date_tax"];
         $dev_ID = $item->getField('id');
         $ic = new self();
         $option = "";
         if ($withtemplate == 2) {
             $option = " readonly ";
         }
         if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) {
             echo "<div class='firstbloc center'>" . $LANG['financial'][84] . "</div>";
         }
         if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) {
             $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID());
             if ($ic->can(-1, "w", $input) && $withtemplate != 2) {
                 echo "<div class='spaced b'>";
                 echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>";
                 echo $item->getTypeName() . " - " . $item->getName() . "</th></tr>";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php?itemtype=" . $item->getType() . "&amp;items_id={$dev_ID}&amp;add=add'>" . $LANG['financial'][68];
                 echo "</a></td></tr></table></div>";
             }
         } else {
             // getFromDBforDevice
             $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2;
             if ($canedit) {
                 echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>";
             }
             echo "<div class='spaced'>";
             echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>";
             echo "<tr><th colspan='4'>" . $LANG['financial'][3] . "</th></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][26] . "&nbsp;:</td>";
             echo "<td>";
             if ($withtemplate == 2) {
                 echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]);
             } else {
                 Dropdown::show('Supplier', array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID()));
             }
             echo "</td>";
             if (haveRight("budget", "r")) {
                 echo "<td>" . $LANG['financial'][87] . "&nbsp;:</td><td >";
                 Dropdown::show('Budget', array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1));
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td></tr>";
             // Can edit calendar ?
             $editcalendar = $withtemplate != 2;
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][18] . "&nbsp;:</td>";
             echo "<td >";
             autocompletionTextField($ic, "order_number", array('option' => $option));
             echo "</td>";
             echo "<td>" . $LANG['financial'][28] . "&nbsp;:</td><td>";
             showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][20] . "*&nbsp;:</td>";
             echo "<td>";
             $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID());
             autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option));
             echo "</td>";
             echo "<td>" . $LANG['financial'][14] . "&nbsp;:</td><td>";
             showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][82] . "&nbsp;:</td>";
             echo "<td>";
             autocompletionTextField($ic, "bill", array('option' => $option));
             echo "</td>";
             echo "<td>" . $LANG['financial'][27] . "&nbsp;:</td><td>";
             showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][19] . "&nbsp;:</td><td>";
             autocompletionTextField($ic, "delivery_number", array('option' => $option));
             echo "</td>";
             echo "<td>" . $LANG['financial'][76] . "&nbsp;:</td><td>";
             showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][21] . "&nbsp;:</td>";
             echo "<td><input type='text' name='value' {$option} value='" . formatNumber($ic->fields["value"], true) . "' size='14'></td>";
             echo "</td>";
             echo "<td>" . $LANG['financial'][114] . "&nbsp;:</td><td>";
             showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][78] . "&nbsp;:</td>";
             echo "<td><input type='text' {$option} name='warranty_value' value='" . formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>";
             echo "<td rowspan='5'>" . $LANG['common'][25] . "&nbsp;:</td>";
             echo "<td rowspan='5' class='middle'>";
             echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"];
             echo "</textarea></td></tr>\n";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][81] . "&nbsp;:</td><td>";
             echo formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n"));
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][22] . "&nbsp;:</td><td >";
             if ($withtemplate == 2) {
                 echo self::getAmortTypeName($ic->fields["sink_type"]);
             } else {
                 self::dropdownAmortType("sink_type", $ic->fields["sink_type"]);
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][23] . "&nbsp;:</td><td>";
             if ($withtemplate == 2) {
                 echo $ic->fields["sink_time"];
             } else {
                 Dropdown::showInteger("sink_time", $ic->fields["sink_time"], 0, 15);
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][77] . "&nbsp;:</td>";
             echo "<td>";
             autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option));
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) {
                 echo "<td>" . $LANG['financial'][89] . "&nbsp;:</td><td>";
                 echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]);
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td>";
             if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) {
                 echo "<td>" . $LANG['financial'][90] . "&nbsp;:</td><td>";
                 echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]);
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td></tr>";
             echo "<tr><th colspan='4'>" . $LANG['financial'][7] . "</th></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][29] . "&nbsp;:</td><td>";
             showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar);
             echo "</td>";
             echo "<td>" . $LANG['financial'][15] . "&nbsp;:</td><td>";
             if ($withtemplate == 2) {
                 // -1 = life
                 if ($ic->fields["warranty_duration"] == -1) {
                     echo $LANG['financial'][2];
                 } else {
                     echo $ic->fields["warranty_duration"];
                 }
             } else {
                 Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => $LANG['financial'][2]));
             }
             if ($ic->fields["warranty_duration"] >= 0) {
                 echo " " . $LANG['financial'][57];
             }
             echo "<span class='small_space'>" . $LANG['financial'][88] . "</span>&nbsp;";
             echo getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"]);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . $LANG['financial'][16] . "&nbsp;:</td>";
             echo "<td >";
             autocompletionTextField($ic, "warranty_info", array('option' => $option));
             echo "</td>";
             if ($CFG_GLPI['use_mailing']) {
                 echo "<td>" . $LANG['setup'][247] . "&nbsp;:</td>";
                 echo "<td>";
                 echo self::dropdownAlert("alert", $ic->fields["alert"]);
                 Alert::displayLastAlert('Infocom', $ic->fields['id']);
                 echo "</td>";
             } else {
                 echo "</td><td colspan='2'>";
             }
             echo "</td></tr>";
             if ($canedit) {
                 echo "<tr>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>";
                 echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\"\n                      class='submit'>";
                 echo "</td>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='submit' name='delete' value=\"" . $LANG['buttons'][6] . "\"\n                      class='submit'>";
                 echo "</td></tr>";
                 echo "</table></div></form>";
             } else {
                 echo "</table></div>";
             }
         }
     }
 }