ksort($dates_to_add); if (count($dates_to_add) && count($_POST['items']) && isset($_POST['users_id'])) { foreach ($_POST['items'] as $reservationitems_id) { $input = array(); $input['reservationitems_id'] = $reservationitems_id; $input['comment'] = $_POST['comment']; if (count($dates_to_add)) { $input['group'] = $rr->getUniqueGroupFor($reservationitems_id); } foreach ($dates_to_add as $begin => $end) { $input['begin'] = $begin; $input['end'] = $end; $input['users_id'] = $_POST['users_id']; if (Session::haveRight("reservation", UPDATE) || Session::getLoginUserID() === $input["users_id"]) { unset($rr->fields["id"]); if ($newID = $rr->add($input)) { Event::log($newID, "reservation", 4, "inventory", sprintf(__('%1$s adds the reservation %2$s for item %3$s'), $_SESSION["glpiname"], $newID, $reservationitems_id)); } else { $all_ok = false; } } } } } else { $all_ok = false; } if ($all_ok) { $toadd = ""; // Only one reservation : move to correct month if (count($_POST['items']) == 1) { $toadd = "?reservationitems_id={$reservationitems_id}";
/** Generate bigdump : make an item reservable * * @param $type item type * @param $ID item ID * @param $ID_entity item entity ID **/ function addReservation($type, $ID, $ID_entity) { global $percent, $DB, $FIRST, $LAST; $current_year = date("Y"); if (mt_rand(0,100)<$percent['reservationitems']) { $ri = new Reservationitem(); $r = new Reservation(); $tID = $ri->add(toolbox::addslashes_deep( array('itemtype' => $type, 'entities_id' => $ID_entity, 'is_recursive' => 0, 'items_id' => $ID, 'comment' => "comment ' $ID $type", 'is_active' => 1))); $date1 = strtotime('-2 week'); // reservations since 2 weeks $date2 = $date1; $i = 0; while (mt_rand(0,100)<$percent['reservations']) { $date1 = $date2+HOUR_TIMESTAMP*(1+mt_rand(0,10)); // min 10 hours between each resa max $date2 = $date1+HOUR_TIMESTAMP*mt_rand(1,10); // A reservation from 1 to 5 hours // echo $tID.' '.date("Y-m-d H:i:s", $date1).'->'.date("Y-m-d H:i:s", $date2).'<br>'; $r->add(toolbox::addslashes_deep( array('reservationitems_id' => $tID, 'begin' => date("Y-m-d H:i:s", $date1), 'end' => date("Y-m-d H:i:s", $date2), 'users_id' => mt_rand($FIRST['users_normal'], $LAST['users_postonly']), 'comment' => "comments '$i ".Toolbox::getRandomString(15)))); $i++; } } }
$times = $_POST["periodicity_times"]; $begin = $_POST["begin"]; list($begin_year, $begin_month, $begin_day) = explode("-", $_POST["begin"]); $end = $_POST["end"]; $to_add = 1; if ($_POST["periodicity"] == "week") { $to_add = 7; } $_POST['_target'] = $_SERVER['PHP_SELF']; $_POST['_ok'] = true; for ($i = 0; $i < $times && $_POST['_ok']; $i++) { $_POST["begin"] = date('Y-m-d H:i:s', strtotime($begin) + $i * $to_add * DAY_TIMESTAMP); $_POST["end"] = date('Y-m-d H:i:s', strtotime($end) + $i * $to_add * DAY_TIMESTAMP); if (haveRight("reservation_central", "w") || getLoginUserID() === $_POST["users_id"]) { unset($rr->fields["id"]); $_POST['_ok'] = $rr->add($_POST); } } // Positionnement du calendrier au mois de debut $_GET["mois_courant"] = $begin_month; $_GET["annee_courant"] = $begin_year; if ($_POST['_ok']) { Event::log($_POST["reservationitems_id"], "reservation", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][20]); } else { $all_ok = false; } } if ($all_ok) { $toadd = ""; // Only one reservation if (count($_POST['items']) == 1) {