Manage planning posted datas (must have begin + duration or end)
Compute end if duration is set
static public manageBeginAndEndPlanDates ( &$data ) : processed | ||
$data | array data to process | |
return | processed | datas |
static function showListSimple() { global $DB, $CFG_GLPI; if (!Session::haveRight(self::$rightname, self::RESERVEANITEM)) { return false; } $ri = new self(); $ok = false; $showentity = Session::isMultiEntitiesMode(); $values = array(); if (isset($_SESSION['glpi_saved']['ReservationItem'])) { $_POST = $_SESSION['glpi_saved']['ReservationItem']; } if (isset($_POST['reserve'])) { echo "<div id='viewresasearch' class='center'>"; Toolbox::manageBeginAndEndPlanDates($_POST['reserve']); echo "<div id='nosearch' class='center firstbloc'>" . "<a href=\"" . $CFG_GLPI['root_doc'] . "/front/reservationitem.php\">"; echo __('See all reservable items') . "</a></div>\n"; } else { echo "<div id='makesearch' class='center firstbloc'>" . "<a class='pointer' onClick=\"javascript:showHideDiv('viewresasearch','','','');" . "showHideDiv('makesearch','','','')\">"; echo __('Find a free item in a specific period') . "</a></div>\n"; echo "<div id='viewresasearch' style=\"display:none;\" class='center'>"; $begin_time = time(); $begin_time -= $begin_time % HOUR_TIMESTAMP; $_POST['reserve']["begin"] = date("Y-m-d H:i:s", $begin_time); $_POST['reserve']["end"] = date("Y-m-d H:i:s", $begin_time + HOUR_TIMESTAMP); $_POST['reservation_types'] = ''; } echo "<form method='post' name='form' action='" . Toolbox::getItemTypeSearchURL(__CLASS__) . "'>"; echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'>"; echo "<th colspan='3'>" . __('Find a free item in a specific period') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>"; Html::showDateTimeField("reserve[begin]", array('value' => $_POST['reserve']["begin"], 'maybeempty' => false)); echo "</td><td rowspan='3'>"; echo "<input type='submit' class='submit' name='submit' value=\"" . _sx('button', 'Search') . "\">"; echo "</td></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Duration') . "</td><td>"; $default_delay = floor((strtotime($_POST['reserve']["end"]) - strtotime($_POST['reserve']["begin"])) / $CFG_GLPI['time_step'] / MINUTE_TIMESTAMP) * $CFG_GLPI['time_step'] * MINUTE_TIMESTAMP; $rand = Dropdown::showTimeStamp("reserve[_duration]", array('min' => 0, 'max' => 48 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date'))); echo "<br><div id='date_end{$rand}'></div>"; $params = array('duration' => '__VALUE__', 'end' => $_POST['reserve']["end"], 'name' => "reserve[end]"); Ajax::updateItemOnSelectEvent("dropdown_reserve[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); echo "</td></tr>"; echo "<tr class='tab_bg_2'><td>" . __('Item type') . "</td><td>"; $sql = "SELECT DISTINCT(`itemtype`)\n FROM `glpi_reservationitems`\n WHERE `is_active` = 1" . getEntitiesRestrictRequest(" AND", 'glpi_reservationitems', 'entities_id', $_SESSION['glpiactiveentities']); $result = $DB->query($sql); while ($data = $DB->fetch_assoc($result)) { $values[$data['itemtype']] = $data['itemtype']::getTypeName(); } $query = "SELECT `glpi_peripheraltypes`.`name`, `glpi_peripheraltypes`.`id`\n FROM `glpi_peripheraltypes`\n LEFT JOIN `glpi_peripherals`\n ON `glpi_peripherals`.`peripheraltypes_id` = `glpi_peripheraltypes`.`id`\n LEFT JOIN `glpi_reservationitems`\n ON `glpi_reservationitems`.`items_id` = `glpi_peripherals`.`id`\n WHERE `itemtype` = 'Peripheral'\n AND `is_active` = 1\n AND `peripheraltypes_id`" . getEntitiesRestrictRequest(" AND", 'glpi_reservationitems', 'entities_id', $_SESSION['glpiactiveentities']) . "\n ORDER BY `glpi_peripheraltypes`.`name`"; foreach ($DB->request($query) as $ptype) { $id = $ptype['id']; $values["Peripheral#{$id}"] = $ptype['name']; } Dropdown::showFromArray("reservation_types", $values, array('value' => $_POST['reservation_types'], 'display_emptychoice' => true)); echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; // GET method passed to form creation echo "<div id='nosearch' class='center'>"; echo "<form name='form' method='GET' action='reservation.form.php'>"; echo "<table class='tab_cadre_fixehov'>"; echo "<tr><th colspan='" . ($showentity ? "5" : "4") . "'>" . self::getTypeName(1) . "</th></tr>\n"; foreach ($CFG_GLPI["reservation_types"] as $itemtype) { if (!($item = getItemForItemtype($itemtype))) { continue; } $itemtable = getTableForItemType($itemtype); $otherserial = "'' AS otherserial"; if ($item->isField('otherserial')) { $otherserial = "`{$itemtable}`.`otherserial`"; } $begin = $_POST['reserve']["begin"]; $end = $_POST['reserve']["end"]; $left = ""; $where = ""; if (isset($_POST['submit']) && isset($begin) && isset($end)) { $left = "LEFT JOIN `glpi_reservations`\n ON (`glpi_reservationitems`.`id` = `glpi_reservations`.`reservationitems_id`\n AND '" . $begin . "' < `glpi_reservations`.`end`\n AND '" . $end . "' > `glpi_reservations`.`begin`)"; $where = " AND `glpi_reservations`.`id` IS NULL "; } if (isset($_POST["reservation_types"]) && !empty($_POST["reservation_types"])) { $tmp = explode('#', $_POST["reservation_types"]); $where .= " AND `glpi_reservationitems`.`itemtype` = '" . $tmp[0] . "'"; if (isset($tmp[1]) && $tmp[0] == 'Peripheral' && $itemtype == 'Peripheral') { $left .= " LEFT JOIN `glpi_peripheraltypes`\n ON (`glpi_peripherals`.`peripheraltypes_id` = `glpi_peripheraltypes`.`id`)"; $where .= " AND `{$itemtable}`.`peripheraltypes_id` = '" . $tmp[1] . "'"; } } $query = "SELECT `glpi_reservationitems`.`id`,\n `glpi_reservationitems`.`comment`,\n `{$itemtable}`.`name` AS name,\n `{$itemtable}`.`entities_id` AS entities_id,\n {$otherserial},\n `glpi_locations`.`id` AS location,\n `glpi_reservationitems`.`items_id` AS items_id\n FROM `glpi_reservationitems`\n INNER JOIN `{$itemtable}`\n ON (`glpi_reservationitems`.`itemtype` = '{$itemtype}'\n AND `glpi_reservationitems`.`items_id` = `{$itemtable}`.`id`)\n {$left}\n LEFT JOIN `glpi_locations`\n ON (`{$itemtable}`.`locations_id` = `glpi_locations`.`id`)\n WHERE `glpi_reservationitems`.`is_active` = '1'\n AND `glpi_reservationitems`.`is_deleted` = '0'\n AND `{$itemtable}`.`is_deleted` = '0'\n {$where} " . getEntitiesRestrictRequest(" AND", $itemtable, '', $_SESSION['glpiactiveentities'], $item->maybeRecursive()) . "\n ORDER BY `{$itemtable}`.`entities_id`,\n `{$itemtable}`.`name`"; if ($result = $DB->query($query)) { while ($row = $DB->fetch_assoc($result)) { echo "<tr class='tab_bg_2'><td>"; echo "<input type='checkbox' name='item[" . $row["id"] . "]' value='" . $row["id"] . "'>" . "</td>"; $typename = $item->getTypeName(); if ($itemtype == 'Peripheral') { $item->getFromDB($row['items_id']); if (isset($item->fields["peripheraltypes_id"]) && $item->fields["peripheraltypes_id"] != 0) { $typename = Dropdown::getDropdownName("glpi_peripheraltypes", $item->fields["peripheraltypes_id"]); } } echo "<td><a href='reservation.php?reservationitems_id=" . $row['id'] . "'>" . sprintf(__('%1$s - %2$s'), $typename, $row["name"]) . "</a></td>"; echo "<td>" . Dropdown::getDropdownName("glpi_locations", $row["location"]) . "</td>"; echo "<td>" . nl2br($row["comment"]) . "</td>"; if ($showentity) { echo "<td>" . Dropdown::getDropdownName("glpi_entities", $row["entities_id"]) . "</td>"; } echo "</tr>\n"; $ok = true; } } } if ($ok) { echo "<tr class='tab_bg_1 center'><td colspan='" . ($showentity ? "5" : "4") . "'>"; if (isset($_POST['reserve'])) { echo Html::hidden('begin', array('value' => $_POST['reserve']["begin"])); echo Html::hidden('end', array('value' => $_POST['reserve']["end"])); } echo "<input type='submit' value=\"" . _sx('button', 'Add') . "\" class='submit'></td></tr>\n"; } echo "</table>\n"; echo "<input type='hidden' name='id' value=''>"; echo "</form>"; // No CSRF token needed echo "</div>\n"; }
function prepareInputForUpdate($input) { Toolbox::manageBeginAndEndPlanDates($input['plan']); if (isset($input["hour"]) && isset($input["minute"])) { $input["actiontime"] = $input["hour"] * HOUR_TIMESTAMP + $input["minute"] * MINUTE_TIMESTAMP; unset($input["hour"]); unset($input["minute"]); } if (isset($input["plan"])) { $input["_plan"] = $input["plan"]; unset($input["plan"]); } $this->getFromDB($input["id"]); $input["_old_name"] = $this->fields["name"]; $input["_old_plugin_resources_tasktypes_id"] = $this->fields["plugin_resources_tasktypes_id"]; $input["_old_users_id"] = $this->fields["users_id"]; $input["_old_groups_id"] = $this->fields["groups_id"]; $input["_old_actiontime"] = $this->fields["actiontime"]; $input["_old_is_finished"] = $this->fields["is_finished"]; $input["_old_comment"] = $this->fields["comment"]; return $input; }
/** * @see CommonDBTM::prepareInputForUpdate() **/ function prepareInputForUpdate($input) { Toolbox::manageBeginAndEndPlanDates($input['plan']); if (isset($input['_planningrecall'])) { PlanningRecall::manageDatas($input['_planningrecall']); } if (isset($input["name"])) { $input["name"] = trim($input["name"]); if (empty($input["name"])) { $input["name"] = __('Without title'); } } if (isset($input['plan'])) { if (!empty($input['plan']["begin"]) && !empty($input['plan']["end"]) && $input['plan']["begin"] < $input['plan']["end"]) { $input['_plan'] = $input['plan']; unset($input['plan']); $input['is_planned'] = 1; $input["begin"] = $input['_plan']["begin"]; $input["end"] = $input['_plan']["end"]; } else { Session::addMessageAfterRedirect(__('Error in entering dates. The starting date is later than the ending date'), false, ERROR); } } return $input; }
function prepareInputForUpdate($input) { global $CFG_GLPI; Toolbox::manageBeginAndEndPlanDates($input['plan']); if (isset($input["hour"]) && isset($input["minute"])) { $input["actiontime"] = $input["hour"] * HOUR_TIMESTAMP + $input["minute"] * MINUTE_TIMESTAMP; unset($input["hour"]); unset($input["minute"]); } if (isset($input["plan"])) { $input["_plan"] = $input["plan"]; unset($input["plan"]); } if (isset($input['plugin_projet_taskstates_id']) && !empty($input['plugin_projet_taskstates_id'])) { $archived = " `for_dependency` = '1' "; $states = getAllDatasFromTable("glpi_plugin_projet_taskstates", $archived); $tab = array(); if (!empty($states)) { foreach ($states as $state) { $tab[] = $state['id']; } } if (!empty($tab) && in_array($input['plugin_projet_taskstates_id'], $tab)) { $input['advance'] = '100'; } } if (isset($input['_link'])) { $task_task = new PluginProjetTask_Task(); if (!empty($input['_link']['plugin_projet_tasks_id_2'])) { if ($task_task->can(-1, 'w', $input['_link'])) { $task_task->add($input['_link']); } else { Session::addMessageAfterRedirect(__('Unknown project task', 'projet'), false, ERROR); } } } $this->getFromDB($input["id"]); $input["_old_name"] = $this->fields["name"]; $input["_old_users_id"] = $this->fields["users_id"]; $input["_old_groups_id"] = $this->fields["groups_id"]; $input["_old_contacts_id"] = $this->fields["contacts_id"]; $input["_old_plugin_projet_tasktypes_id"] = $this->fields["plugin_projet_tasktypes_id"]; $input["_old_plugin_projet_taskstates_id"] = $this->fields["plugin_projet_taskstates_id"]; $input["_old_actiontime"] = $this->fields["actiontime"]; $input["_old_advance"] = $this->fields["advance"]; $input["_old_priority"] = $this->fields["priority"]; $input["_old_comment"] = $this->fields["comment"]; $input["_old_sub"] = $this->fields["sub"]; $input["_old_others"] = $this->fields["others"]; $input["_old_affect"] = $this->fields["affect"]; $input["_old_plugin_projet_projets_id"] = $this->fields["plugin_projet_projets_id"]; $input["_old_depends"] = $this->fields["depends"]; $input["_old_show_gantt"] = $this->fields["show_gantt"]; $input["_old_locations_id"] = $this->fields["locations_id"]; return $input; }
function prepareInputForAdd($input) { $itemtype = $this->getItilObjectItemType(); Toolbox::manageBeginAndEndPlanDates($input['plan']); if (isset($input["plan"])) { $input["begin"] = $input['plan']["begin"]; $input["end"] = $input['plan']["end"]; $timestart = strtotime($input["begin"]); $timeend = strtotime($input["end"]); $input["actiontime"] = $timeend - $timestart; unset($input["plan"]); if (!$this->test_valid_date($input)) { Session::addMessageAfterRedirect(__('Error in entering dates. The starting date is later than the ending date'), false, ERROR); return false; } } $input["_job"] = new $itemtype(); if (!$input["_job"]->getFromDB($input[$input["_job"]->getForeignKeyField()])) { return false; } // Pass old assign From object in case of assign change if (isset($input["_old_assign"])) { $input["_job"]->fields["_old_assign"] = $input["_old_assign"]; } if (!isset($input["users_id"]) && ($uid = Session::getLoginUserID())) { $input["users_id"] = $uid; } if (!isset($input["date"])) { $input["date"] = $_SESSION["glpi_currenttime"]; } if (!isset($input["is_private"])) { $input['is_private'] = 0; } // Manage File attached (from mailgate) // Pass filename if set to ticket if (isset($input['_filename'])) { $input["_job"]->input['_filename'] = $input['_filename']; } // Add docs without notif $docadded = $input["_job"]->addFiles(0, 1); return $input; }
} else { if (isset($_POST["purge"])) { $reservationitems_id = key($_POST["items"]); if ($rr->delete($_POST, 1)) { Event::log($_POST["id"], "reservation", 4, "inventory", sprintf(__('%1$s purges the reservation for item %2$s'), $_SESSION["glpiname"], $reservationitems_id)); } list($begin_year, $begin_month, $begin_day) = explode("-", $rr->fields["begin"]); Html::redirect($CFG_GLPI["root_doc"] . "/front/reservation.php?reservationitems_id=" . "{$reservationitems_id}&mois_courant={$begin_month}&annee_courante={$begin_year}"); } else { if (isset($_POST["add"])) { $all_ok = true; $reservationitems_id = 0; if (empty($_POST['users_id'])) { $_POST['users_id'] = Session::getLoginUserID(); } Toolbox::manageBeginAndEndPlanDates($_POST['resa']); $dates_to_add = array(); list($begin_year, $begin_month, $begin_day) = explode("-", $_POST['resa']["begin"]); if (isset($_POST['resa']["end"])) { // Compute dates to add. $dates_to_add[$_POST['resa']["begin"]] = $_POST['resa']["end"]; if (isset($_POST['periodicity']) && is_array($_POST['periodicity']) && isset($_POST['periodicity']['type']) && !empty($_POST['periodicity']['type'])) { // Compute others dates to add. $dates_to_add += Reservation::computePeriodicities($_POST['resa']["begin"], $_POST['resa']["end"], $_POST['periodicity']); } } // Sort dates ksort($dates_to_add); if (count($dates_to_add) && count($_POST['items']) && isset($_POST['users_id'])) { foreach ($_POST['items'] as $reservationitems_id) { $input = array();