/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { switch ($ma->getAction()) { case 'add_followup': $input = $ma->getInput(); $fup = new self(); foreach ($ids as $id) { if ($item->getFromDB($id)) { $input2 = array('tickets_id' => $id, 'is_private' => $input['is_private'], 'requesttypes_id' => $input['requesttypes_id'], 'content' => $input['content']); if ($fup->can(-1, CREATE, $input2)) { if ($fup->add($input2)) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT); $ma->addMessage($item->getErrorMessage(ERROR_RIGHT)); } } else { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); } } } parent::processMassiveActionsForOneItemtype($ma, $item, $ids); }
/** Print the user personnal information for check * * @param $userid Interger ID of the user * * @since version 0.84 **/ static function showPersonalInformation($userid) { global $CFG_GLPI; $user = new self(); if (!$user->can($userid, 'r') && $userid != Session::getLoginUserID()) { return false; } echo "<table class='tab_glpi left' width='100%'>"; echo "<tr class='tab_bg_1'>"; echo "<td class='b' width='20%'>"; _e('Name'); echo "</td><td width='30%'>"; echo getUserName($userid); echo "</td>"; echo "<td class='b' width='20%'>"; _e('Phone'); echo "</td><td width='30%'>"; echo $user->getField('phone'); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td class='b'>"; _e('Phone 2'); echo "</td><td>"; echo $user->getField('phone2'); echo "</td>"; echo "<td class='b'>"; _e('Mobile phone'); echo "</td><td>"; echo $user->getField('mobile'); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td class='b'>"; _e('Location'); echo "</td><td>"; echo Dropdown::getDropdownName('glpi_locations', $user->getField('locations_id')); echo "</td>"; echo "<td colspan='2' class='center'>"; if ($userid == Session::getLoginUserID()) { echo "<a href='" . $CFG_GLPI['root_doc'] . "/front/preference.php' class='vsubmit'>" . __('Edit') . "</a>"; } else { echo " "; } echo "</td>"; echo "</tr>"; echo "</table>"; }
/** * Show Infocom form for an item (not a standard showForm) * * @param $item CommonDBTM object * @param $withtemplate integer template or basic item (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $CFG_GLPI; // Show Infocom or blank form if (!Session::haveRight("infocom", "r")) { return false; } if (!$item) { echo "<div class='spaced'>" . __('Requested item not found') . "</div>"; } else { $date_tax = $CFG_GLPI["date_tax"]; $dev_ID = $item->getField('id'); $ic = new self(); $option = ""; if ($withtemplate == 2) { $option = " readonly "; } if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) { echo "<div class='firstbloc center'>" . __('For this type of item, the financial and administrative information are only a model for the items which you should add.') . "</div>"; } if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) { $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID()); if ($ic->can(-1, "w", $input) && $withtemplate != 2) { echo "<div class='spaced b'>"; echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>"; echo sprintf(__('%1$s - %2$s'), $item->getTypeName(1), $item->getName()) . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/infocom.form.php", 'add', __('Enable the financial and administrative information'), array('itemtype' => $item->getType(), 'items_id' => $dev_ID)); echo "</td></tr></table></div>"; } } else { // getFromDBforDevice $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2; if ($canedit) { echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>"; echo "<tr><th colspan='4'>" . __('Financial and administrative information') . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Supplier') . "</td>"; echo "<td>"; if ($withtemplate == 2) { echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]); } else { Supplier::dropdown(array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID())); } echo "</td>"; if (Session::haveRight("budget", "r")) { echo "<td>" . __('Budget') . "</td><td >"; Budget::dropdown(array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1)); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; // Can edit calendar ? $editcalendar = $withtemplate != 2; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Order number') . "</td>"; echo "<td >"; Html::autocompletionTextField($ic, "order_number", array('option' => $option)); echo "</td>"; echo "<td>" . __('Order date') . "</td><td>"; Html::showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; $istemplate = ''; if ($item->isTemplate() || in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) { $istemplate = '*'; } echo "<td>" . sprintf(__('%1$s%2$s'), __('Immobilization number'), $istemplate) . "</td>"; echo "<td>"; $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID()); Html::autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option)); echo "</td>"; echo "<td>" . __('Date of purchase') . "</td><td>"; Html::showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Invoice number') . "</td>"; echo "<td>"; Html::autocompletionTextField($ic, "bill", array('option' => $option)); echo "</td>"; echo "<td>" . __('Delivery date') . "</td><td>"; Html::showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Delivery form') . "</td><td>"; Html::autocompletionTextField($ic, "delivery_number", array('option' => $option)); echo "</td>"; echo "<td>" . __('Startup date') . "</td><td>"; Html::showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Value') . "</td>"; echo "<td><input type='text' name='value' {$option} value='" . Html::formatNumber($ic->fields["value"], true) . "' size='14'></td>"; echo "</td>"; echo "<td>" . __('Date of last physical inventory') . "</td><td>"; Html::showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Warranty extension value') . "</td>"; echo "<td><input type='text' {$option} name='warranty_value' value='" . Html::formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>"; echo "<td rowspan='5'>" . __('Comments') . "</td>"; echo "<td rowspan='5' class='middle'>"; echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"]; echo "</textarea></td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Account net value') . "</td><td>"; echo Html::formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n")); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization type') . "</td><td >"; if ($withtemplate == 2) { echo self::getAmortTypeName($ic->fields["sink_type"]); } else { self::dropdownAmortType("sink_type", $ic->fields["sink_type"]); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization duration') . "</td><td>"; if ($withtemplate == 2) { printf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]); } else { Dropdown::showNumber("sink_time", array('value' => $ic->fields["sink_time"], 'max' => 15, 'unit' => 'year')); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Amortization coefficient') . "</td>"; echo "<td>"; Html::autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option)); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . __('TCO (value + tracking cost)') . "</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]); } else { echo "<td colspan='2'>"; } echo "</td>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . __('Monthly TCO') . "</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; echo "<tr><th colspan='4'>" . __('Warranty information') . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Start date of warranty') . "</td><td>"; Html::showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar); echo "</td>"; echo "<td>" . __('Warranty duration') . "</td><td>"; if ($withtemplate == 2) { // -1 = life if ($ic->fields["warranty_duration"] == -1) { _e('Lifelong'); } else { printf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]); } } else { Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => __('Lifelong')), array('unit' => 'month')); } $tmpdat = self::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"], 0, true); if ($tmpdat) { echo "<span class='small_space'>" . sprintf(__('Valid to %s'), $tmpdat) . "</span>"; } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Warranty information') . "</td>"; echo "<td >"; Html::autocompletionTextField($ic, "warranty_info", array('option' => $option)); echo "</td>"; if ($CFG_GLPI['use_mailing']) { echo "<td>" . __('Alarms on financial and administrative information') . "</td>"; echo "<td>"; self::dropdownAlert(array('name' => "alert", 'value' => $ic->fields["alert"])); Alert::displayLastAlert('Infocom', $ic->fields['id']); echo "</td>"; } else { echo "</td><td colspan='2'>"; } echo "</td></tr>"; if ($canedit) { echo "<tr>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n class='submit'>"; echo "</td>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='submit' name='delete' value=\"" . _sx('button', 'Delete permanently') . "\"\n class='submit'>"; echo "</td></tr>"; echo "</table></div>"; Html::closeForm(); } else { echo "</table></div>"; } } } }
/** * Get the full name (internet name) of a NetworkName * * @param $ID ID of the NetworkName * * @return its internet name, or empty string if invalid NetworkName **/ static function getInternetNameFromID($ID) { $networkName = new self(); if ($networkName->can($ID, READ)) { return FQDNLabel::getInternetNameFromLabelAndDomainID($this->fields["name"], $this->fields["fqdns_id"]); } return ""; }
/** * Show Licenses of a software * * @param $software Software object * * @return nothing **/ static function showForSoftware(Software $software) { global $DB, $CFG_GLPI; $softwares_id = $software->getField('id'); $license = new self(); $computer = new Computer(); if (!$software->can($softwares_id, "r")) { return false; } if (isset($_POST["start"])) { $start = $_POST["start"]; } else { $start = 0; } if (isset($_POST["order"]) && $_POST["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_POST["sort"]) && !empty($_POST["sort"])) { $sort = "`" . $_POST["sort"] . "`"; } else { $sort = "`entity` {$order}, `name`"; } // Righ type is enough. Can add a License on a software we have Read access $canedit = Session::haveRight("software", "w"); $showmassiveactions = $canedit; // Total Number of events $number = countElementsInTable("glpi_softwarelicenses", "glpi_softwarelicenses.softwares_id = {$softwares_id} " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true)); echo "<div class='spaced'>"; Session::initNavigateListItems('SoftwareLicense', sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $software->getName())); if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>\n"; if ($canedit) { echo "<tr class='tab_bg_2'><td class='center'>"; echo "<a class='vsubmit' href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . _sx('button', 'Add a license') . "</a>"; echo "</td></tr>\n"; } echo "</table></div>\n"; return; } // Display the pager Html::printAjaxPager(self::getTypeName(2), $start, $number); $rand = mt_rand(); $query = "SELECT `glpi_softwarelicenses`.*,\n `buyvers`.`name` AS buyname,\n `usevers`.`name` AS usename,\n `glpi_entities`.`completename` AS entity,\n `glpi_softwarelicensetypes`.`name` AS typename\n FROM `glpi_softwarelicenses`\n LEFT JOIN `glpi_softwareversions` AS buyvers\n ON (`buyvers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_buy`)\n LEFT JOIN `glpi_softwareversions` AS usevers\n ON (`usevers`.`id` = `glpi_softwarelicenses`.`softwareversions_id_use`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `glpi_softwarelicenses`.`entities_id`)\n LEFT JOIN `glpi_softwarelicensetypes`\n ON (`glpi_softwarelicensetypes`.`id`\n = `glpi_softwarelicenses`.`softwarelicensetypes_id`)\n WHERE (`glpi_softwarelicenses`.`softwares_id` = '{$softwares_id}') " . getEntitiesRestrictRequest('AND', 'glpi_softwarelicenses', '', '', true) . "\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); if ($result = $DB->query($query)) { if ($num_displayed = $DB->numrows($result)) { if ($showmassiveactions) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $num_displayed, 'extraparams' => array('options' => array('condition' => "`glpi_softwareversions`.`softwares_id` = {$softwares_id}"))); Html::showMassiveActions(__CLASS__, $massiveactionparams); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; echo "<table class='tab_cadre_fixehov'><tr>"; echo "<th>"; Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand); echo "</th>"; echo "<th>" . ($sort == "`name`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=name&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . __('Name') . "</a></th>"; if ($software->isRecursive()) { // Ereg to search entity in string for match default order echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . __('Entity') . "</a></th>"; } echo "<th>" . ($sort == "`serial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=serial&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . __('Serial number') . "</a></th>"; echo "<th>" . ($sort == "`number`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=number&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . _x('quantity', 'Number') . "</a></th>"; echo "<th>" . __('Affected computers') . "</th>"; echo "<th>" . ($sort == "`typename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=typename&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . __('Type') . "</a></th>"; echo "<th>" . ($sort == "`buyname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=buyname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . __('Purchase version') . "</a></th>"; echo "<th>" . ($sort == "`usename`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=usename&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . __('Version in use') . "</a></th>"; echo "<th>" . ($sort == "`expire`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=expire&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . __('Expiration') . "</a></th>"; echo "</tr>\n"; $tot_assoc = 0; for ($tot = 0; $data = $DB->fetch_assoc($result);) { Session::addToNavigateListItems('SoftwareLicense', $data['id']); $expired = true; if (is_null($data['expire']) || $data['expire'] > date('Y-m-d')) { $expired = false; } echo "<tr class='tab_bg_2" . ($expired ? '_2' : '') . "'>"; if ($license->can($data['id'], "w")) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } else { echo "<td> </td>"; } echo "<td><a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name'] . (empty($data['name']) ? "(" . $data['id'] . ")" : "") . "</a></td>"; if ($software->isRecursive()) { echo "<td>" . $data['entity'] . "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td class='numeric'>" . ($data['number'] > 0 ? $data['number'] : __('Unlimited')) . "</td>"; $nb_assoc = Computer_SoftwareLicense::countForLicense($data['id']); $tot_assoc += $nb_assoc; echo "<td class='numeric'>" . $nb_assoc . "</td>"; echo "<td>" . $data['typename'] . "</td>"; echo "<td>" . $data['buyname'] . "</td>"; echo "<td>" . $data['usename'] . "</td>"; echo "<td class='center'>" . Html::convDate($data['expire']) . "</td>"; echo "</tr>"; if ($data['number'] < 0) { // One illimited license, total is illimited $tot = -1; } else { if ($tot >= 0) { // Expire license not count if (!$expired) { // Not illimited, add the current number $tot += $data['number']; } } } } echo "<tr class='tab_bg_1'>"; echo "<td colspan='" . ($software->isRecursive() ? 4 : 3) . "' class='right b'>" . __('Total') . "</td>"; echo "<td class='numeric'>" . ($tot > 0 ? $tot . "" : __('Unlimited')) . "</td>"; echo "<td class='numeric'>" . $tot_assoc . "</td>"; echo "<td colspan='4' class='center'>"; if ($canedit) { echo "<a class='vsubmit' href='softwarelicense.form.php?softwares_id={$softwares_id}'>" . _sx('button', 'Add a license') . "</a>"; } echo "</td></tr>"; echo "</table>\n"; if ($showmassiveactions) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } } else { _e('No item found'); } } Html::printAjaxPager(self::getTypeName(2), $start, $number); echo "</div>"; }
static function methodGetAppliance($params, $protocol) { global $DB; if (isset($params['help'])) { return array('help' => 'bool,optional', 'id2name' => 'bool,optional', 'externalid OR id' => 'string'); } if (!Session::getLoginUserID()) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } if (!isset($params['externalid']) && !isset($params['id'])) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER); } $appli = new self(); $found = false; if (isset($params['id'])) { $found = $appli->getFromDB(intval($params['id'])); } else { if (isset($params['externalid'])) { $found = $appli->getFromDBbyExternalID(addslashes($params["externalid"])); } } if (!$found || !$appli->can($appli->fields["id"], 'r')) { return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTFOUND); } $resp = $appli->fields; if (isset($params['id2name'])) { $resp['plugin_appliances_appliancetypes_name'] = Html::clean(Dropdown::getDropdownName('glpi_plugin_appliances_appliancetypes', $resp['plugin_appliances_appliancetypes_id'])); $resp['plugin_appliances_environments_name'] = Html::clean(Dropdown::getDropdownName('glpi_plugin_appliances_environments', $resp['plugin_appliances_environments_id'])); $resp['users_name'] = Html::clean(Dropdown::getDropdownName('glpi_users', $resp['users_id'])); $resp['groups_name'] = Html::clean(Dropdown::getDropdownName('glpi_groups', $resp['groups_id'])); } return $resp; }
/** * Display for reservation * * @param $ID ID of the reservation (empty for create new) * @param $options array of possibles options: * - item reservation items ID for creation process * - date date for creation process **/ function showForm($ID, $options = array()) { global $CFG_GLPI; if (!Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) { return false; } $resa = new self(); if (!empty($ID)) { if (!$resa->getFromDB($ID)) { return false; } if (!$resa->can($ID, UPDATE)) { return false; } // Set item if not set if ((!isset($options['item']) || count($options['item']) == 0) && ($itemid = $resa->getField('reservationitems_id'))) { $options['item'][$itemid] = $itemid; } } else { $resa->getEmpty(); $resa->fields["begin"] = $options['begin']; if (!isset($options['end'])) { $resa->fields["end"] = date("Y-m-d H:00:00", strtotime($resa->fields["begin"]) + HOUR_TIMESTAMP); } else { $resa->fields["end"] = $options['end']; } } // No item : problem if (!isset($options['item']) || count($options['item']) == 0) { return false; } echo "<div class='center'><form method='post' name=form action='reservation.form.php'>"; if (!empty($ID)) { echo "<input type='hidden' name='id' value='{$ID}'>"; } echo "<table class='tab_cadre' width='700px'>"; echo "<tr><th colspan='2'>" . __('Reserve an item') . "</th></tr>\n"; // Add Hardware name $r = new ReservationItem(); echo "<tr class='tab_bg_1'><td>" . __('Item') . "</td>"; echo "<td>"; foreach ($options['item'] as $itemID) { $r->getFromDB($itemID); $type = $r->fields["itemtype"]; $name = NOT_AVAILABLE; $item = NULL; if ($item = getItemForItemtype($r->fields["itemtype"])) { $type = $item->getTypeName(); if ($item->getFromDB($r->fields["items_id"])) { $name = $item->getName(); } else { $item = NULL; } } echo "<span class='b'>" . sprintf(__('%1$s - %2$s'), $type, $name) . "</span><br>"; echo "<input type='hidden' name='items[{$itemID}]' value='{$itemID}'>"; } echo "</td></tr>\n"; if (!Session::haveRight("reservation", UPDATE) || is_null($item) || !Session::haveAccessToEntity($item->fields["entities_id"])) { echo "<input type='hidden' name='users_id' value='" . Session::getLoginUserID() . "'>"; } else { echo "<tr class='tab_bg_2'><td>" . __('By') . "</td>"; echo "<td>"; if (empty($ID)) { User::dropdown(array('value' => Session::getLoginUserID(), 'entity' => $item->getEntityID(), 'right' => 'all')); } else { User::dropdown(array('value' => $resa->fields["users_id"], 'entity' => $item->getEntityID(), 'right' => 'all')); } echo "</td></tr>\n"; } echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>"; $rand_begin = Html::showDateTimeField("resa[begin]", array('value' => $resa->fields["begin"], 'timestep' => -1, 'maybeempty' => false)); echo "</td></tr>\n"; $default_delay = floor((strtotime($resa->fields["end"]) - strtotime($resa->fields["begin"])) / $CFG_GLPI['time_step'] / MINUTE_TIMESTAMP) * $CFG_GLPI['time_step'] * MINUTE_TIMESTAMP; echo "<tr class='tab_bg_2'><td>" . __('Duration') . "</td><td>"; $rand = Dropdown::showTimeStamp("resa[_duration]", array('min' => 0, 'max' => 24 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date'))); echo "<br><div id='date_end{$rand}'></div>"; $params = array('duration' => '__VALUE__', 'end' => $resa->fields["end"], 'name' => "resa[end]"); Ajax::updateItemOnSelectEvent("dropdown_resa[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); if ($default_delay == 0) { $params['duration'] = 0; Ajax::updateItem("date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); } Alert::displayLastAlert('Reservation', $ID); echo "</td></tr>\n"; if (empty($ID)) { echo "<tr class='tab_bg_2'><td>" . __('Rehearsal') . "</td>"; echo "<td>"; $values = array('' => _x('periodicity', 'None'), 'day' => _x('periodicity', 'Daily'), 'week' => _x('periodicity', 'Weekly'), 'month' => _x('periodicity', 'Monthly')); $rand = Dropdown::showFromArray('periodicity[type]', $values); $field_id = Html::cleanId("dropdown_periodicity[type]{$rand}"); $params = array('type' => '__VALUE__', 'end' => $resa->fields["end"]); Ajax::updateItemOnSelectEvent($field_id, "resaperiodcontent{$rand}", $CFG_GLPI["root_doc"] . "/ajax/resaperiod.php", $params); echo "<br><div id='resaperiodcontent{$rand}'></div>"; echo "</td></tr>\n"; } echo "<tr class='tab_bg_2'><td>" . __('Comments') . "</td>"; echo "<td><textarea name='comment' rows='8' cols='60'>" . $resa->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; if (empty($ID)) { echo "<tr class='tab_bg_2'>"; echo "<td colspan='2' class='top center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; } else { if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRightsOr(static::$rightname, array(PURGE, UPDATE))) { echo "<tr class='tab_bg_2'>"; if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRight(static::$rightname, PURGE)) { echo "<td class='top center'>"; echo "<input type='submit' name='purge' value=\"" . _sx('button', 'Delete permanently') . "\"\n class='submit'>"; if ($resa->fields["group"] > 0) { echo "<br><input type='checkbox' name='_delete_group'> " . __s('Delete all rehearsals'); } echo "</td>"; } if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRight(static::$rightname, UPDATE)) { echo "<td class='top center'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n class='submit'>"; echo "</td>"; } echo "</tr>\n"; } } echo "</table>"; Html::closeForm(); echo "</div>\n"; }
/** * Manage recall set * * @param $data array of data to manage **/ static function manageDatas(array $data) { // Check data informations if (!isset($data['itemtype']) || !isset($data['items_id']) || !isset($data['users_id']) || !isset($data['before_time']) || !isset($data['field'])) { return false; } $pr = new self(); // Datas OK : check if recall already exists if ($pr->getFromDBForItemAndUser($data['itemtype'], $data['items_id'], $data['users_id'])) { if ($data['before_time'] != $pr->fields['before_time']) { // Recall exists and is different : update datas and clean alert if ($pr->can($pr->fields['id'], 'w')) { if ($item = getItemForItemtype($data['itemtype'])) { if ($item->getFromDB($data['items_id']) && isset($item->fields[$data['field']]) && !empty($item->fields[$data['field']])) { $when = date("Y-m-d H:i:s", strtotime($item->fields[$data['field']]) - $data['before_time']); if ($data['before_time'] >= 0) { $pr->update(array('id' => $pr->fields['id'], 'before_time' => $data['before_time'], 'when' => $when)); } else { $pr->delete(array('id' => $pr->fields['id'])); } } } } } } else { // Recall does not exists : create it if ($pr->can(-1, 'w', $data)) { if ($item = getItemForItemtype($data['itemtype'])) { $item->getFromDB($data['items_id']); if ($item->getFromDB($data['items_id']) && isset($item->fields[$data['field']]) && !empty($item->fields[$data['field']])) { $data['when'] = date("Y-m-d H:i:s", strtotime($item->fields[$data['field']]) - $data['before_time']); if ($data['before_time'] >= 0) { $pr->add($data); } } } } } }
/** * @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); }
/** * 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() . "&items_id={$dev_ID}&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] . " :</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] . " :</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] . " :</td>"; echo "<td >"; autocompletionTextField($ic, "order_number", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][28] . " :</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] . "* :</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] . " :</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] . " :</td>"; echo "<td>"; autocompletionTextField($ic, "bill", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][27] . " :</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] . " :</td><td>"; autocompletionTextField($ic, "delivery_number", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][76] . " :</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] . " :</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] . " :</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] . " :</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] . " :</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] . " :</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] . " :</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] . " :</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] . " :</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] . " :</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] . " :</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] . " :</td><td>"; showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar); echo "</td>"; echo "<td>" . $LANG['financial'][15] . " :</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> "; echo getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"]); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][16] . " :</td>"; echo "<td >"; autocompletionTextField($ic, "warranty_info", array('option' => $option)); echo "</td>"; if ($CFG_GLPI['use_mailing']) { echo "<td>" . $LANG['setup'][247] . " :</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>"; } } } }
/** * Display a reservation * * @param $ID ID a the reservation item * @param $date date to display **/ static function displayReservationsForAnItem($ID, $date) { global $DB, $LANG; $users_id = getLoginUserID(); $resa = new self(); $user = new User(); list($year, $month, $day) = explode("-", $date); $debut = $date . " 00:00:00"; $fin = $date . " 23:59:59"; $query = "SELECT *\n FROM `glpi_reservations`\n WHERE '{$debut}' < `end`\n AND '{$fin}' > `begin`\n AND `reservationitems_id` = '{$ID}'\n ORDER BY `begin`"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { echo "<table width='100%'>"; while ($row = $DB->fetch_array($result)) { echo "<tr>"; $user->getFromDB($row["users_id"]); $display = ""; if ($debut > $row['begin']) { $heure_debut = "00:00"; } else { $heure_debut = get_hour_from_sql($row['begin']); } if ($fin < $row['end']) { $heure_fin = "24:00"; } else { $heure_fin = get_hour_from_sql($row['end']); } if (strcmp($heure_debut, "00:00") == 0 && strcmp($heure_fin, "24:00") == 0) { $display = $LANG['planning'][5]; } else { if (strcmp($heure_debut, "00:00") == 0) { $display = $LANG['reservation'][16] . " " . $heure_fin; } else { if (strcmp($heure_fin, "24:00") == 0) { $display = $LANG['reservation'][17] . " " . $heure_debut; } else { $display = $heure_debut . "-" . $heure_fin; } } } $rand = mt_rand(); $modif = $modif_end = ""; if ($resa->can($row['id'], "w")) { $modif = "<a id='content_" . $ID . $rand . "'\n href='reservation.form.php?id=" . $row['id'] . "'>"; $modif_end = "</a>"; $modif_end .= showToolTip($row["comment"], array('applyto' => "content_" . $ID . $rand, 'display' => false)); } echo "<td class='tab_resa center'>" . $modif . "<span>" . $display . "<br><strong>" . formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]); echo "</strong></span>"; echo $modif_end; echo "</td></tr>\n"; } echo "</table>\n"; } } }