subscribe.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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('reservation');
  8. if (!empty($_GET['cat']) && !empty($_GET['item'] )) {
  9. $cat = (int)$_GET['cat'];
  10. $item = (int)$_GET['item'];
  11. $interbreadcrumb[] = array ('url' => "reservation.php?cat=$cat&item=$item", 'name' => get_lang('Booking'));
  12. } else {
  13. $interbreadcrumb[] = array ('url' => 'reservation.php', 'name' => get_lang('Booking'));
  14. }
  15. $tool_name = get_lang('BookIt');
  16. Display :: display_header($tool_name);
  17. api_display_tool_title($tool_name);
  18. $reservationid = Database::escape_string($_GET['rid']);
  19. $reservation = Rsys :: get_reservation($reservationid);
  20. $item = Rsys :: get_item($reservation[0][2]);
  21. if ($reservation[0][9] < $reservation[0][4]) {
  22. ob_start();
  23. $form = new FormValidator('reservation', 'post', 'subscribe.php?rid='.Security::remove_XSS($_GET['rid']));
  24. $form->addElement('hidden', 'timepicker', $reservation[0][11]);
  25. $form->addElement('hidden', 'accepted', $reservation[0][3]);
  26. if ($reservation[0][11] == 1) {
  27. //$subscribe_timepicker_information="Gelieve voor #name# een peroide te kiezen #from_till tussen :#start_end";
  28. $min_timepicker = $reservation[0][12];
  29. $max_timepicker = $reservation[0][13];
  30. $min_timepicker_min = fmod($min_timepicker,60);
  31. $min_timepicker_hour = floor($min_timepicker/60);
  32. $max_timepicker_min = fmod($max_timepicker,60);
  33. $max_timepicker_hour = floor($max_timepicker/60);
  34. $min_timepicker_show = $min_timepicker_hour."h".$min_timepicker_min."m";
  35. $max_timepicker_show = $max_timepicker_hour."h".$max_timepicker_min."m";
  36. if (!($min_timepicker == 0 && $max_timepicker == 0)) {
  37. if($min_timepicker_show == $max_timepicker_show) {
  38. $from_till = "van ".$min_timepicker_show;
  39. } else {
  40. $from_till = "van ".$min_timepicker_show." tot ".$max_timepicker_show;
  41. }
  42. } else {
  43. $from_till = "";
  44. $min_timepicker = 1;
  45. //een reservatieperiode moet toch wel minimum 1 minuut zijn
  46. }
  47. $res_start_at = $reservation[0][5];
  48. $res_end_at = $reservation[0][6];
  49. //echo time()."-".$res_start_at;
  50. if (time() > Rsys :: mysql_datetime_to_timestamp($res_start_at)) {
  51. $time_start = time();
  52. } else {
  53. $time_start = Rsys :: mysql_datetime_to_timestamp($res_start_at);
  54. }
  55. $sql = "SELECT start_at, end_at FROM ".Rsys :: getTable('subscription')."
  56. WHERE reservation_id='".$reservationid."' and end_at > NOW() ORDER BY start_at";
  57. $result = Database::query($sql);
  58. if (Database::num_rows($result) != 0){
  59. $start_end = "<ul>";
  60. while ($array = Database::fetch_array($result)) {
  61. //print_r($array);
  62. if (time() < Rsys :: mysql_datetime_to_timestamp($array["start_at"]))
  63. {
  64. if (((Rsys :: mysql_datetime_to_timestamp($array["start_at"]) - $time_start) >= ($min_timepicker*60)) && ($time_start < Rsys :: mysql_datetime_to_timestamp($array["start_at"])))
  65. {
  66. $start_end .= "<li>".Rsys :: timestamp_to_datetime($time_start)." en ".$array["start_at"]."</li>";
  67. }
  68. }
  69. $time_start = Rsys :: mysql_datetime_to_timestamp($array["end_at"]);
  70. $end_time_last_block = $array["end_at"];
  71. }
  72. if ((Rsys :: mysql_datetime_to_timestamp($res_end_at) - Rsys :: mysql_datetime_to_timestamp($end_time_last_block)) >= ($min_timepicker*60))
  73. {
  74. $start_end .= "<li>".$end_time_last_block." en ".$res_end_at."</li>";
  75. }
  76. $start_end .= "</ul>";
  77. } else {
  78. $start_end = " ".Rsys :: timestamp_to_datetime($time_start)." en ".$res_end_at;
  79. }
  80. //$form->addElement('html', "timestart:".$time_start."-".Rsys :: mysql_datetime_to_timestamp($res_start_at));
  81. $form->addElement('html', "<p>".str_replace('#start_end',$start_end,str_replace('#from_till', $from_till,str_replace('#name#', "<b>".$item[3]."</b>",str_replace('#start#', "<b>".$reservation[0][5]."</b>", str_replace('#end#', "<b>".$reservation[0][6]."</b>", get_lang("SubscribeTimePickerInformation"))))))." </p>");
  82. $form->add_timewindow('startpicker', 'endpicker', get_lang('StartDate'), get_lang('EndDate'));
  83. $form->addElement('hidden', 'min', $reservation[0][12]);
  84. $form->addElement('hidden', 'max', $reservation[0][13]);
  85. $datum = $_GET['timestart'];
  86. $defaultvalues['startpicker'] = Rsys :: timestamp_to_datetime($datum);
  87. //$defaultvalues['endpicker'] = Rsys :: timestamp_to_datetime($datum +900);
  88. $defaultvalues['endpicker'] = Rsys :: timestamp_to_datetime($datum +($min_timepicker*60));
  89. $form->setDefaults($defaultvalues);
  90. } else {
  91. $form->addElement('html', "<p> * ".str_replace('#name#', "<b>".$item[3]."</b>",str_replace('#start#', "<b>".$reservation[0][5]."</b>", str_replace('#end#', "<b>".$reservation[0][6]."</b>", get_lang('SubscribeInformation'))))." *</p>");
  92. }
  93. $buttons[] = $form->createElement('submit', 'submit', get_lang('Ok'));
  94. $buttons[] = $form->createElement('button', 'cancel', get_lang('Cancel'), array ('onclick' => 'location.href="reservation.php?cat='.$item[1].'&item='.$item[0].'"'));
  95. $form->addGroup($buttons, null, '', '', false);
  96. $buffer = ob_get_contents();
  97. ob_end_clean();
  98. if ($form->validate()) {
  99. $values = $form->exportValues();
  100. if ($values['timepicker'] == 0) {
  101. $result = Rsys :: add_subscription($_GET['rid'], api_get_user_id(),$values['accepted']);
  102. switch ($result) {
  103. case 0 :
  104. Display :: display_normal_message(Rsys :: get_return_msg2(get_lang('ReservationAdded'), "javascript:history.go(-2)", get_lang('BookingView')),false);
  105. break;
  106. case 1 :
  107. Display :: display_normal_message(Rsys :: get_return_msg2(str_replace('#END#', "<b>".$GLOBALS['end_date']."</b>",str_replace('#START#', "<b>".$GLOBALS['start_date']."</b>",get_lang('ReservationAlready'))),"reservation.php?cat=".$item[1]."&item=".$item[0]."", get_lang('BookingView')),false);
  108. break;
  109. }
  110. } else {
  111. $result = Rsys :: add_subscription_timepicker($_GET['rid'], api_get_user_id(), $values['startpicker'], $values['endpicker'],$values['accepted'],$values['min'],$values['max']);
  112. switch ($result) {
  113. case 0 :
  114. Display :: display_normal_message(Rsys :: get_return_msg2(get_lang('ReservationAdded'), "reservation.php?cat=".$item[1]."&item=".$item[0]."&date=".date( 'Y-m-d',Rsys :: mysql_datetime_to_timestamp($values['startpicker']))."&changemonth=yes", get_lang('BookingView')),false);
  115. break;
  116. case 1 :
  117. Display :: display_normal_message(str_replace('#END#', "<b>".$GLOBALS['end_date']."</b>",str_replace('#START#', "<b>".$GLOBALS['start_date']."</b>",get_lang('ReservationOutOfDate'))),false);
  118. $form->display();
  119. echo $buffer;
  120. break;
  121. case 2 :
  122. Display :: display_normal_message(get_lang('BookingPeriodTooSmall'),false);
  123. $form->display();
  124. //echo $buffer;
  125. break;
  126. case 3 :
  127. Display :: display_normal_message(get_lang('BookingPeriodTooBig'),false);
  128. $form->display();
  129. //echo $buffer;
  130. break;
  131. }
  132. }
  133. } else
  134. $form->display();
  135. } else {
  136. Display :: display_normal_message(Rsys :: get_return_msg2(get_lang('ReservationTresspassing'), "javascript:history.go(-2)", get_lang('BookingView')),false);
  137. }
  138. Display :: display_footer();