Ejemplo n.º 1
0
 /**
  *  Adds a reservation
  *
  *  @param  -   $item_id,$auto_accept,$max_users,$start_at,$end_at,$subscribe_until,$notes
  *  @return -   FALSE if there is something wrong with the dates, a mysql_insert_id() if everything went perfectly
  */
 function add_reservation($item_id, $auto_accept, $max_users, $start_at, $end_at, $subscribe_from, $subscribe_until, $notes, $timepicker, $min, $max, $subid)
 {
     $stamp_start = Rsys::mysql_datetime_to_timestamp($start_at);
     $stamp_end = Rsys::mysql_datetime_to_timestamp($end_at);
     $stamp_start_date = date('Y-m-d', $stamp_start);
     $stamp_end_date = date('Y-m-d', $stamp_end);
     if (Rsys::check_date($item_id, $stamp_start, $stamp_end, $start_at, $end_at) != 0) {
         return 1;
     }
     if ($subscribe_until != 0) {
         $stamp_until = Rsys::mysql_datetime_to_timestamp($subscribe_until);
         if ($stamp_until > $stamp_start) {
             return 2;
         }
     }
     if ($start_at < date('Y-m-d H:i:s', time())) {
         return 3;
     }
     if ($stamp_start_date != $stamp_end_date && $timepicker == '1') {
         return 4;
     }
     if ($timepicker == '0') {
         if ($min != '0' || $max != '0') {
             //kan niet verschillen van 0!
             return 5;
         }
     } else {
         if (!($max == 0 && $min == 0)) {
             if ($max < $min) {
                 return 6;
                 //maximum kan niet kleiner zijn dan minimum
             } else {
                 $stamp = ($stamp_end - $stamp_start) / 60;
                 if ($stamp / $max < 1) {
                     return 7;
                     // er past geen blok van het tijdverschil
                 }
             }
         }
     }
     $sql = "INSERT INTO " . Rsys::getTable("reservation") . " (item_id,auto_accept,max_users,start_at,end_at,subscribe_from,subscribe_until,notes,timepicker,timepicker_min,timepicker_max,subid) VALUES ('" . Database::escape_string($item_id) . "','" . Database::escape_string($auto_accept) . "','" . (intval($max_users) > 1 ? $max_users : 1) . "','" . Database::escape_string($start_at) . "','" . Database::escape_string($end_at) . "','" . Database::escape_string($subscribe_from) . "','" . Database::escape_string($subscribe_until) . "','" . Database::escape_string($notes) . "','" . $timepicker . "','" . $min . "','" . $max . "','" . ($subid == 0 ? 0 : $subid) . "')";
     Database::query($sql);
     return 0;
 }