m_reservation.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. Reservation-manager (add, edit & delete)
  5. */
  6. require_once('rsys.php');
  7. Rsys :: protect_script('m_reservation', $_GET['item_id']);
  8. $tool_name = get_lang('BookingPeriodList');
  9. /**
  10. * Filter to display the modify-buttons
  11. *
  12. * @param - int $id The reservation-id
  13. */
  14. function modify_filter($id) {
  15. $out = ' <a href="m_reservation.php?action=accept&amp;rid='.$id.'" alt="'.get_lang('AutoAccept').'"><img title="'.get_lang('AutoAccept').'" alt="'.get_lang('AutoAccept').'" src="../img/students.gif" /></a>';
  16. $out .= '<a href="m_reservation.php?action=edit&amp;id='.$id.'" alt="'.get_lang('EditBookingPeriod').'"><img title="'.get_lang('EditBookingPeriod').'" alt="'.get_lang('EditBookingPeriod').'" src="../img/edit.gif" /></a>';
  17. $out .= ' <a href="m_reservation.php?action=delete&amp;id='.$id.'" alt="'.get_lang('DeleteBookingPeriod').'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmDeleteBookingPeriod")))."'".')) return false;"><img title="'.get_lang('DeleteBookingPeriod').'" alt="'.get_lang('DeleteBookingPeriod').'" src="../img/delete.gif" /></a>';
  18. return $out;
  19. }
  20. if (isset ($_POST['action'])) {
  21. switch ($_POST['action']) {
  22. case 'accept_users' :
  23. $ids = $_POST['accepting'];
  24. //echo count($ids);
  25. if (count($ids) > 0) {
  26. foreach ($ids as $id) {
  27. //echo $id;
  28. $result = Rsys :: set_accepted($id, 1);
  29. }
  30. }
  31. $_GET['action'] = 'accept';
  32. break;
  33. case 'unaccept_users' :
  34. $ids = $_POST['accepting'];
  35. //echo count($ids);
  36. if (count($ids) > 0) {
  37. foreach ($ids as $id) {
  38. //echo $id;
  39. $result = Rsys :: set_accepted($id, 0);
  40. }
  41. }
  42. $_GET['action'] = 'accept';
  43. break;
  44. case 'delete_subscriptions' :
  45. $res_id = $_GET['rid'];
  46. $ids = $_POST['accepting'];
  47. //echo count($ids);
  48. if (count($ids) > 0) {
  49. foreach ($ids as $id) {
  50. $result = Rsys :: delete_subscription($res_id,$id);
  51. }
  52. }
  53. $_GET['action'] = 'accept';
  54. break;
  55. }
  56. }
  57. /**
  58. ---------------------------------------------------------------------
  59. */
  60. switch ($_GET['action']) {
  61. case 'overviewsubscriptions' :
  62. $interbreadcrumb[] = array ("url" => "mysubscriptions.php", "name" => get_lang('Booking'));
  63. $interbreadcrumb[] = array ("url" => "m_reservation.php", "name" => get_lang('ManageBookingPeriods'));
  64. Display :: display_header(get_lang('OverviewSubscriptions'));
  65. api_display_tool_title(get_lang('Overview'));
  66. echo '<div class="actions">';
  67. echo '<form id="cat_form" action="m_reservation.php" method="get">';
  68. echo '<input type="hidden" name="action" value="overviewsubscriptions"/>';
  69. echo '<input type="text" name="keyword" /><button type="submit" class="search" value="'.get_lang('Search').'" >'.get_lang('Search').'</button></form>';
  70. echo '</div><br>';
  71. $table = new SortableTable('reservation', array ('Rsys', 'get_num_subscriptions_overview'), array ('Rsys', 'get_table_subcribed_reservations'), 1);
  72. $table->set_additional_parameters(array ('action' => 'overviewsubscriptions','keyword' => $_GET['keyword']));
  73. $table->set_header(0, get_lang('ResourceName'), true);
  74. $table->set_header(1, get_lang('ResourceTypeName'), true);
  75. $table->set_header(2, get_lang('StartDate'), true);
  76. $table->set_header(3, get_lang('EndDate'), true);
  77. $table->set_header(4, get_lang('SubscribedPerson'), true);
  78. $table->set_header(5, get_lang('SubscribedStartDate'), true);
  79. $table->set_header(6, get_lang('SubscribedEndDate'), true);
  80. $table->set_header(7, get_lang('Accept'), true);
  81. $table->display();
  82. break;
  83. case 'accept' :
  84. $NoSearchResults = get_lang('NoReservation');
  85. if (empty ($_GET['rid'])) {
  86. $_GET['rid'] = $_POST['rid'];
  87. }
  88. if ($_GET['switch'] == 'edit') {
  89. Rsys :: set_accepted($_GET['dummy'], $_GET['set']);
  90. }
  91. if ($_GET['switch'] == 'delete') {
  92. Rsys :: delete_subscription($_GET['rid'],$_GET['dummy']);
  93. }
  94. $interbreadcrumb[] = array ("url" => "mysubscriptions.php", "name" => get_lang('Booking'));
  95. $interbreadcrumb[] = array ("url" => "m_reservation.php", "name" => get_lang('ManageBookingPeriods'));
  96. Display :: display_header(get_lang('AutoAccept'));
  97. api_display_tool_title(get_lang('AutoAccept'));
  98. $table = new SortableTable('accepting', array ('Rsys', 'get_num_waiting_users'), array ('Rsys', 'get_table_waiting_users'), 1);
  99. $table->set_additional_parameters(array ('rid' => $_GET['rid'], 'action' => 'accept'));
  100. $table->set_header(0, '', false, array ('style' => 'width:10px'));
  101. $table->set_header(1, get_lang('SubscribedPerson'), true);
  102. $table->set_header(2, get_lang('Class'), true);
  103. $table->set_header(3, get_lang('SubscribedStartDate'), false);
  104. $table->set_header(4, get_lang('SubscribedEndDate'), false);
  105. $table->set_header(5, get_lang('Accept'), false, array ('style' => 'width:30px;'));
  106. $table->set_header(6, get_lang('Delete'), false, array ('style' => 'width:30px;'));
  107. $table->set_form_actions(array ('accept_users' => get_lang('AcceptUsers'), 'unaccept_users' => get_lang('UnacceptedUsers'), 'delete_subscriptions' => get_lang('DeleteSubscriptions')), 'accepting');
  108. //$table->set_form_actions(array ('accept_users' => get_lang('AcceptUsers'), 'unaccept_users' => get_lang('UnacceptedUsers')), 'accepting');
  109. $table->display();
  110. break;
  111. case 'add' :
  112. if (!isset ($_GET['cat_id']))
  113. $_GET['cat_id'] = 0;
  114. $interbreadcrumb[] = array ("url" => "mysubscriptions.php", "name" => get_lang('Booking'));
  115. $interbreadcrumb[] = array ("url" => "m_reservation.php", "name" => get_lang('ManageBookingPeriods'));
  116. Display :: display_header(get_lang('AddNewBookingPeriod'));
  117. api_display_tool_title(get_lang('AddNewBookingPeriod'));
  118. ob_start();
  119. $cats = Rsys :: get_category_rights();
  120. echo '<form id="cat_form" action="m_reservation.php" method="get">';
  121. echo '<input type="hidden" name="action" value="add"/>';
  122. echo '<div class="row">';
  123. echo '<div class="label">'.get_lang('ResourceType').': </div>';
  124. echo '<div class="formw">';
  125. echo '<select name="cat_id" onchange="this.form.submit();">';
  126. echo '<option value="0">&nbsp;</option>';
  127. foreach ($cats as $catid => $cat)
  128. echo '<option value="'.$catid.'"'. ($catid == $_GET['cat_id'] ? ' selected="selected"' : '').'>'.$cat.'</option>';
  129. echo '</select></div>';
  130. echo '</div></form>';
  131. $itemlist = Rsys :: get_cat_r_items($_GET['cat_id']);
  132. $form = new FormValidator('reservation', 'post', 'm_reservation.php?action=add&cat_id='.$_GET['cat_id']);
  133. $choices[] = $form->createElement('radio', 'forever', '', get_lang('NoPeriod'), 0, array ('onclick' => 'javascript:window_hide(\'forever_timewindow\')'));
  134. $choices[] = $form->createElement('radio', 'forever', '', get_lang('FixedPeriod'), 1 , array ('onclick' => 'javascript:window_show(\'forever_timewindow\')'));
  135. $form->addElement('select', 'itemid', get_lang('Resource'), $itemlist);
  136. $form->add_timewindow('start', 'end', get_lang('StartDate'), get_lang('EndDate'));
  137. $form->addElement('html', '<div class="row"><div class="label"></div><div class="formw">'.get_lang('TimePickerLimitation').'</div></div><br />');
  138. $form->addElement('text', 'maxuser', get_lang('MaxUsers'));
  139. $form->addElement('html', '<div class="row"><div class="label"></div><div class="formw">'.get_lang('TimePickerMaxUsers').'</div></div><br />');
  140. $form->addGroup($choices, null, get_lang('SubscriptionPeriod'), '<br />', false);
  141. $form->addElement('html', '<div style="margin-left:25px;display:block;" id="forever_timewindow">');
  142. $form->add_timewindow('subscribe_from', 'subscribe_until', '', '');
  143. $form->addElement('html', '</div>');
  144. $form->addElement('checkbox', 'auto_accept', get_lang('AutoAccept'));
  145. //$form->addElement('checkbox', 'timepicker', get_lang('TimePicker'));
  146. $timepicker_arr[] = $form->createElement('radio', 'timepicker', '', get_lang('NoTimePicker'), 0, array ('onclick' => 'javascript:window_hide(\'timepicker_timewindow\')'));
  147. $timepicker_arr[] = $form->createElement('radio', 'timepicker', '', get_lang('TimePicker'), 1 , array ('onclick' => 'javascript:window_show(\'timepicker_timewindow\')'));
  148. $form->addGroup($timepicker_arr, null, get_lang('TimePicker'), '<br />', false);
  149. $form->addElement('html', '<div style="margin-left:25px;display:block;" id="timepicker_timewindow">');
  150. $min_arr = array();
  151. //todo this will be fixed
  152. $min_arr[10] = 10;
  153. $min_arr[20] = 20;
  154. $min_arr[30] = 30;
  155. $min_arr[40] = 40;
  156. $min_arr[50] = 50;
  157. $min_arr[60] = 60;
  158. for ($i = 0; $i < 1441; $i++) {
  159. //$min_arr[$i] = $i;
  160. }
  161. $max_arr = $min_arr;
  162. $form->addElement('select',min,get_lang('Minimum'),$min_arr);
  163. $form->addElement('select',max,get_lang('Maximum'),$max_arr);
  164. $form->addElement('html', '<div class="row"><div class="label"></div><div class="formw">'.get_lang('TimePickerMinMaxNull').'</div></div><br />');
  165. $form->addElement('html', '</div>');
  166. $recurrence[] = $form->createElement('radio', 'recurrence_c', '', get_lang('NoRecurrence'), 0, array ('onclick' => 'javascript:window_hide(\'recurrence_timewindow\')'));
  167. $recurrence[] = $form->createElement('radio', 'recurrence_c', '', get_lang('UntilRecurrence'), 1 , array ('onclick' => 'javascript:window_show(\'recurrence_timewindow\')'));
  168. $form->addGroup($recurrence, null, get_lang('Recurrence'), '<br />', false);
  169. $form->addElement('html', '<div style="margin-left:25px;display:block;" id="recurrence_timewindow">');
  170. $list_time = Rsys:: recurrence_list();
  171. $period[] = $form->createElement('text','repeater','',array('size'=>'3'));
  172. $period[] = $form->createElement('select','recurrence_selector','',$list_time);
  173. $form->addGroup($period, null, get_lang('RepeatFor'), ' ', false);
  174. $form->add_datepicker('recurrence_until',get_lang('RepeatUntil'));
  175. $form->addElement('html', '</div>');
  176. $form->addElement('textarea', 'notes', get_lang('Notes'), array ('cols' => 40, 'rows' => 4));
  177. $form->addElement('style_submit_button', 'submit', get_lang('AddNewBookingPeriod'),'class="add"');
  178. $str='';
  179. if(!$_POST['forever']) $str.="window_hide('forever_timewindow');";
  180. if(!$_POST['recurrence_c']) $str.="window_hide('recurrence_timewindow');";
  181. if(!$_POST['timepicker']) $str.="window_hide('timepicker_timewindow');";
  182. $form->addElement('html', "<script type=\"text/javascript\">
  183. /* <![CDATA[ */
  184. ".$str."
  185. function window_show(item) {
  186. el = document.getElementById(item);
  187. el.style.display='';
  188. }
  189. function window_hide(item) {
  190. el = document.getElementById(item);
  191. el.style.display='none';
  192. }
  193. /* ]]> */
  194. </script>\n");
  195. if (count($itemlist) > 0) {
  196. // here we set the default start and end time that we will see in the form 1h 30m after now()
  197. // 1h after now
  198. $date_defaults_start = array(
  199. 'd' => date('d'),
  200. 'F' => date('n'),
  201. 'Y' => date('Y'),
  202. 'H' => date('H',time()+60*60),
  203. 'i' => '00'
  204. );
  205. //2h after now
  206. $date_defaults_end = array(
  207. 'd' => date('d'),
  208. 'F' => date('n'),
  209. 'Y' => date('Y'),
  210. 'H' => date('H',time()+60*60*2),
  211. 'i' => '00'
  212. );
  213. // 1h after now
  214. $date_defaults_start_sub = array(
  215. 'd' => date('d'),
  216. 'F' => date('n'),
  217. 'Y' => date('Y'),
  218. 'H' => date('H',time()-60*60),
  219. 'i' => '00'
  220. );
  221. //2h after now
  222. $date_defaults_end_sub = array(
  223. 'd' => date('d'),
  224. 'F' => date('n'),
  225. 'Y' => date('Y'),
  226. 'H' => date('H',time()),
  227. 'i' => '00'
  228. );
  229. $defaultvalues['start'] = $date_defaults_start;
  230. $defaultvalues['end'] = $date_defaults_end;
  231. $defaultvalues['subscribe_from'] = $date_defaults_start_sub;
  232. $defaultvalues['subscribe_until'] = $date_defaults_end_sub;
  233. $defaultvalues['recurrence_until'] = $date_defaults_end;
  234. $defaultvalues['recurrence_c'] = '0';
  235. $defaultvalues['forever'] = '0';
  236. $defaultvalues['timepicker'] = '0';
  237. $defaultvalues['maxuser'] = '1';
  238. $defaultvalues['repeater'] = '1';
  239. $defaultvalues['auto_accept'] = '1';
  240. $form->setDefaults($defaultvalues);
  241. $form->Display();
  242. } else {
  243. if ($_GET['cat_id'] != 0)
  244. Display :: display_normal_message(get_lang('NoItems'),false);
  245. }
  246. $buffer = ob_get_contents();
  247. ob_end_clean();
  248. if ($form->validate()) {
  249. $values = $form->exportValues();
  250. if ($values['forever'] == 0) {
  251. $values['subscribe_from'] = 0;
  252. $values['subscribe_until'] = 0;
  253. }
  254. $msg_number = Rsys :: add_reservation($values['itemid'], $values['auto_accept'], $values['maxuser'], $values['start'], $values['end'], $values['subscribe_from'], $values['subscribe_until'], $values['notes'], $values['timepicker'],$values['min'],$values['max'],0);
  255. switch($msg_number) {
  256. case 0 :
  257. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('BookingPeriodAdded'), "m_reservation.php", $tool_name),false);
  258. break;
  259. case 1 :
  260. Display :: display_normal_message(str_replace('#END#', "<b>".$GLOBALS['end_date']."</b>",str_replace('#START#', "<b>".$GLOBALS['start_date']."</b>",get_lang('BookingPeriodDateOverlap'))),false);
  261. break;
  262. case 2 :
  263. Display :: display_normal_message(get_lang('BookingPeriodSubscribeUntilAfterStart'),false);
  264. break;
  265. case 3:
  266. Display :: display_normal_message(get_lang('BookingPeriodPast'),false);
  267. break;
  268. case 4:
  269. Display :: display_normal_message(get_lang('BookingPeriodTimePickerLimitation'),false);
  270. break;
  271. case 5:
  272. Display :: display_normal_message(get_lang('BookingPeriodTimePickerError1'),false);
  273. break;
  274. case 6:
  275. Display :: display_normal_message(get_lang('BookingPeriodTimePickerError2'),false);
  276. break;
  277. case 7:
  278. Display :: display_normal_message(get_lang('BookingPeriodTimePickerError3'),false);
  279. break;
  280. default :
  281. break;
  282. }
  283. }
  284. if($_POST['recurrence_c'] && $msg_number == 0){
  285. $Inserted_id = Database::insert_id();
  286. $recurrence_date_start = Rsys :: mysql_datetime_to_timestamp($values['start']);
  287. $recurrence_date_end = Rsys :: mysql_datetime_to_timestamp($values['end']);
  288. $recurrence_period_end = Rsys :: mysql_datetime_to_timestamp($values['recurrence_until']);
  289. $recurrence_subscribe_from = Rsys :: mysql_datetime_to_timestamp($values['subscribe_from']);
  290. $count = 0;
  291. $recurrence_date_start = $recurrence_date_start + (60 * 60 * 24 * $values['repeater'] * $values['recurrence_selector']);
  292. $recurrence_date_end = $recurrence_date_end + (60 * 60 * 24 * $values['repeater'] * $values['recurrence_selector']);
  293. while($recurrence_date_end < $recurrence_period_end){
  294. if ($values['forever'] == 0) {
  295. $recurrence_subscribe_from = 0;
  296. $recurrence_subscribe_until = 0;
  297. }else{
  298. $recurrence_subscribe_from = $recurrence_subscribe_from + (60 * 60 * 24 * $values['repeater'] * $values['recurrence_selector']);
  299. $recurrence_subscribe_until = $recurrence_subscribe_until + (60 * 60 * 24 * $values['repeater'] * $values['recurrence_selector']);
  300. }
  301. $errors[]=Rsys :: add_reservation($values['itemid'], $values['auto_accept'], $values['maxuser'], Rsys :: timestamp_to_datetime($recurrence_date_start), Rsys :: timestamp_to_datetime($recurrence_date_end), $values['forever'] == 0 ? 0 : Rsys :: timestamp_to_datetime($recurrence_subscribe_from), $values['forever'] == 0 ? 0 : Rsys :: timestamp_to_datetime($recurrence_subscribe_until), $values['notes'], $values['timepicker'],$values['min'],$values['max'],$Inserted_id);
  302. if($errors[$count] <> 0){
  303. $msg .= str_replace('#START#', "<b>".Rsys :: timestamp_to_datetime($recurrence_date_start)."</b>",str_replace('#END#', "<b>".Rsys :: timestamp_to_datetime($recurrence_date_end)."</b>",get_lang('ReservationFromUntilError')));
  304. }
  305. $count++;
  306. $recurrence_date_start = $recurrence_date_start + (60 * 60 * 24 * $values['repeater'] * $values['recurrence_selector']);
  307. $recurrence_date_end = $recurrence_date_end + (60 * 60 * 24 * $values['repeater'] * $values['recurrence_selector']);
  308. }
  309. }
  310. if(!empty ($msg))
  311. Display :: display_normal_message($msg);
  312. echo $buffer;
  313. break;
  314. case 'edit' :
  315. if (isset ($_GET["id"]))
  316. $Reservation_id = $_GET["id"];
  317. else
  318. $Reservation_id = $_POST["id"];
  319. $result = Rsys :: get_num_subscriptions_ReservationPeriods($Reservation_id);
  320. if($result != '0')
  321. {
  322. $interbreadcrumb[] = array ("url" => "mysubscriptions.php", "name" => get_lang('Booking'));
  323. $interbreadcrumb[] = array ("url" => "m_reservation.php", "name" => get_lang('ManageBookingPeriods'));
  324. Display :: display_header('');
  325. api_display_tool_title($tool_name);
  326. Display :: display_normal_message(Rsys :: get_return_msg(str_replace('#NUM#', $result, get_lang('BookingPeriodHasSubscriptions')),"m_reservation.php",get_lang('BookingPeriodList')),false);
  327. }
  328. else
  329. {
  330. $interbreadcrumb[] = array ("url" => "mysubscriptions.php", "name" => get_lang('Booking'));
  331. $interbreadcrumb[] = array ("url" => "m_reservation.php", "name" => get_lang('ManageBookingPeriods'));
  332. Display :: display_header(get_lang('EditBookingPeriod'));
  333. api_display_tool_title(get_lang('EditNewBookingPeriod'));
  334. $reservation = Rsys :: get_reservation($Reservation_id);
  335. $item_category = Rsys :: get_item($reservation[0][2]);
  336. $categori = Rsys :: get_category($item_category[1]);
  337. $cats = Rsys :: get_category_rights();
  338. $tijdelijke_cat = $categori[0];
  339. if (isset ($_GET['cat_id']))
  340. $categori[0] = $_GET['cat_id'];
  341. ob_start();
  342. echo '<form id="cat_form" action="m_reservation.php" method="get">';
  343. echo '<input type="hidden" name="id" value="'.$Reservation_id.'" />';
  344. echo '<input type="hidden" name="action" value="edit"/>';
  345. echo '<div class="row">';
  346. echo '<div class="label">'.get_lang('ResourceType').': </div>';
  347. echo '<div class="formw">';
  348. echo '<select name="cat_id" onchange="this.form.submit();">';
  349. echo '<option value="0">&nbsp;</option>';
  350. foreach ($cats as $catid => $cat)
  351. echo '<option value="'.$catid.'"'. ($catid == $categori[0] ? ' selected="selected"' : '').'>'.$cat.'</option>';
  352. echo '</select></div>';
  353. echo '</div>';
  354. echo '</form>';
  355. $itemlist = Rsys :: get_cat_r_items($categori[0]);
  356. $form = new FormValidator('reservation', 'post', 'm_reservation.php?action=edit&id='.$Reservation_id);
  357. $choices[] = $form->createElement('radio', 'forever', '', get_lang('NoPeriod'), '0', array ('onclick' => 'javascript:timewindow_hide(\'forever_timewindow\')'));
  358. $choices[] = $form->createElement('radio', 'forever', '', get_lang('FixedPeriod'), '1', array ('onclick' => 'javascript:timewindow_show(\'forever_timewindow\')'));
  359. $form->addElement('select', 'item_id', get_lang('Resource'), $itemlist);
  360. $form->add_timewindow('start', 'end', get_lang('StartDate'), get_lang('EndDate'));
  361. $form->addElement('html', '<div class="row"><div class="label"></div><div class="formw">'.get_lang('TimePickerLimitation').'</div></div><br />');
  362. $form->addElement('text', 'maxuser', get_lang('MaxUsers'));
  363. $form->addGroup($choices, null, get_lang('SubscriptionPeriod'), '<br />', false);
  364. $form->addElement('html', '<div style="margin-left:25px;display:block;" id="forever_timewindow">');
  365. $form->add_timewindow('subscribe_from', 'subscribe_until', '', '');
  366. $form->addElement('html', '</div>');
  367. $form->addElement('html', "<script type=\"text/javascript\">
  368. /* <![CDATA[ */
  369. ". ($reservation[0][7] == '0000-00-00 00:00:00' && $reservation[0][8] == '0000-00-00 00:00:00' ? "timewindow_hide('forever_timewindow');" : "")."
  370. function timewindow_show(item) {
  371. el = document.getElementById(item);
  372. el.style.display='';
  373. }
  374. function timewindow_hide(item) {
  375. el = document.getElementById(item);
  376. el.style.display='none';
  377. }
  378. /* ]]> */
  379. </script>\n");
  380. $form->addElement('checkbox', 'auto_accept', get_lang('AutoAccept'));
  381. $form->addElement('checkbox', 'timepicker', get_lang('TimePicker'),'',array('disabled'=>'disabled'));
  382. $form->addElement('textarea', 'notes', get_lang('Notes'), array ('cols' => 40, 'rows' => 4));
  383. $form->addElement('style_submit_button', 'submit', get_lang('EditNewBookingPeriod'),'class="save"');
  384. $form->addElement('hidden', 'id', $Reservation_id);
  385. $form->addElement('hidden', 'timepicker2');
  386. $form->addElement('hidden', 'period', ($reservation[0][7] == '0000-00-00 00:00:00' && $reservation[0][8] == '0000-00-00 00:00:00' ? 0 : 1));
  387. if ($categori[0] == $tijdelijke_cat)
  388. $defaultvalues['item_id'] = $reservation[0][2];
  389. $defaultvalues['auto_accept'] = $reservation[0][3];
  390. $defaultvalues['maxuser'] = $reservation[0][4];
  391. $defaultvalues['start'] = $reservation[0][5];
  392. $defaultvalues['end'] = $reservation[0][6];
  393. $defaultvalues['forever']=($reservation[0][7] == '0000-00-00 00:00:00' && $reservation[0][8] == '0000-00-00 00:00:00' ? 0 : 1);
  394. $my_start_date = Rsys :: mysql_datetime_to_timestamp($reservation[0][5]);
  395. if ($defaultvalues['forever']==0) {
  396. //here we set the default dates
  397. $defaultvalues['subscribe_from'] = $my_start_date - 60*60 ;
  398. $defaultvalues['subscribe_until'] = $my_start_date - 60 ;
  399. }
  400. else {
  401. $defaultvalues['subscribe_from'] = $reservation[0][7];
  402. $defaultvalues['subscribe_until'] = $reservation[0][8];
  403. }
  404. $defaultvalues['notes'] = $reservation[0][10];
  405. $defaultvalues['timepicker'] = $reservation[0][11];
  406. $defaultvalues['timepicker2'] = $reservation[0][11];
  407. $form->setDefaults($defaultvalues);
  408. if (count($reservation) > 0) {
  409. $form->Display();
  410. } else {
  411. Display :: display_normal_message(get_lang('NoItems'),false);
  412. }
  413. $buffer = ob_get_contents();
  414. ob_end_clean();
  415. if ($form->validate()) {
  416. $values = $form->exportValues();
  417. //print_r($values);
  418. $auto_accept = true;
  419. if (($values['forever'] == $values['period']) || $values['forever']=='0') {
  420. $values['subscribe_from'] = 0;
  421. $values['subscribe_until'] = 0;
  422. }
  423. $msg_number = Rsys :: edit_reservation($values['id'], $_POST['item_id'], $values['auto_accept'], $values['maxuser'], $values['start'], $values['end'], $values['subscribe_from'], $values['subscribe_until'], $values['notes'], $values['timepicker2']);
  424. switch ($msg_number) {
  425. case 0 :
  426. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('BookingPeriodEdited'), "m_reservation.php", $tool_name),false);
  427. break;
  428. case 1 :
  429. Display :: display_normal_message(str_replace('#END#', "<b>".$GLOBALS['end_date']."</b>",str_replace('#START#', "<b>".$GLOBALS['start_date']."</b>",get_lang('BookingPeriodDateOverlap'))),false);
  430. break;
  431. case 2 :
  432. Display :: display_normal_message(get_lang('BookingPeriodSubscribeUntilAfterStart'),false);
  433. break;
  434. case 3:
  435. Display :: display_normal_message(get_lang('ReservationMaxUsersOverrun'),false);
  436. break;
  437. case 4:
  438. Display :: display_normal_message(get_lang('BookingPeriodTimepickerLimitation'),false);
  439. break;
  440. default :
  441. break;
  442. }
  443. }
  444. echo $buffer;
  445. }
  446. break;
  447. case 'delete' :
  448. Rsys :: delete_reservation($_GET["id"]);
  449. ob_start();
  450. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('BookingPeriodDeleted'), "m_reservation.php", $tool_name),false);
  451. $msg = ob_get_contents();
  452. ob_end_clean();
  453. default :
  454. $NoSearchResults = get_lang('NoReservations');
  455. if ($_GET['view']=='calendar') {
  456. $interbreadcrumb[] = array ("url" => "reservation.php", "name" => get_lang('Booking'));
  457. }
  458. else {
  459. $interbreadcrumb[] = array ("url" => "mysubscriptions.php", "name" => get_lang('Booking'));
  460. }
  461. $interbreadcrumb[] = array ("url" => "m_reservation.php", "name" => get_lang('ManageBookingPeriods'));
  462. Display :: display_header('');
  463. api_display_tool_title($tool_name);
  464. echo '<form id="cat_form" action="m_reservation.php" method="get">';
  465. echo '<div class="actions">';
  466. echo '<a href="m_reservation.php?action=add"><img src="../img/view_more_stats.gif" border="0" alt="" title="'.get_lang('AddNewBookingPeriod').'"/>'.get_lang('AddNewBookingPeriod').'</a>';
  467. echo '&nbsp;&nbsp;&nbsp;<a href="m_reservation.php?action=overviewsubscriptions">'.get_lang('OverviewReservedPeriods').'</a>';
  468. echo '</div>';
  469. echo '<div style="text-align: right; "><input type="text" name="keyword" /><button type="submit" class="search" value="'.get_lang('Search').'" >'.get_lang('Search').'</button></div></form>';
  470. echo '<br>';
  471. if (isset ($_POST['action'])) {
  472. switch ($_POST['action']) {
  473. case 'delete_reservations' :
  474. $ids = $_POST['reservations'];
  475. if (count($ids) > 0) {
  476. foreach ($ids as $index => $id)
  477. Rsys :: delete_reservation($id);
  478. }
  479. break;
  480. }
  481. }
  482. $table = new SortableTable('reservation', array ('Rsys', 'get_num_reservations'), array ('Rsys', 'get_table_reservations'), 1);
  483. $table->set_additional_parameters(array ('keyword' => $_GET['keyword']));
  484. $table->set_header(0, '', false, array ('style' => 'width:10px'));
  485. $table->set_header(1, get_lang('ResourceName'), true);
  486. $table->set_header(2, get_lang('StartDate'), true);
  487. $table->set_header(3, get_lang('EndDate'), true);
  488. $table->set_header(4, get_lang('SubscribeFrom'), true);
  489. $table->set_header(5, get_lang('SubscribeUntil'), true);
  490. $table->set_header(6, get_lang('Subscribers'), true);
  491. $table->set_header(7, get_lang('Notes'), false);
  492. $table->set_header(8, '', false, array ('style' => 'width:65px;'));
  493. $table->set_column_filter(8, 'modify_filter');
  494. $table->set_form_actions(array ('delete_reservations' => get_lang('DeleteSelectedBookingPeriod')), 'reservations');
  495. $table->display();
  496. }
  497. /**
  498. ---------------------------------------------------------------------
  499. */
  500. Display :: display_footer();
  501. ?>