/** * Edits a reservation * * @param - int $id The reservation-ID * @param - $item_id,$auto_accept,$max_users,$start_at,$end_at,$subscribe_until,$notes * @return - FALSE if there is something wrong with the dates, TRUE if everything went perfectly * */ function edit_reservation($id, $item_id, $auto_accept, $max_users, $start_at, $end_at, $subscribe_from, $subscribe_until, $notes, $timepicker) { $id = Database::escape_string($id); if (!Rsys::item_allow($item_id, 'm_reservation')) { return false; } $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_edit($item_id, $stamp_start, $stamp_end, $start_at, $end_at, $id) != 0) { return 1; } if ($subscribe_until != 0) { $stamp_until = Rsys::mysql_datetime_to_timestamp($subscribe_until); if ($stamp_until > $stamp_start) { return 2; } } $sql = "SELECT timepicker, subscribers FROM " . Rsys::getTable("reservation") . " WHERE id='" . $id . "'"; $result = Database::fetch_array(Database::query($sql)); if ($result[0] == 0 && $result[1] > $max_users) { return 3; } if ($stamp_start_date != $stamp_end_date && $timepicker == '1') { return 4; } if ($auto_accept == 1) { $sql = "SELECT dummy FROM " . Rsys::getTable("subscription") . " WHERE reservation_id='" . $id . "'"; $result = Database::query($sql); while ($array = Database::fetch_array($result, 'NUM')) { Rsys::set_accepted($array[0], 1); } } else { $auto_accept = 0; } $sql = "UPDATE " . Rsys::getTable("reservation") . " SET item_id='" . Database::escape_string($item_id) . "',auto_accept='" . Database::escape_string($auto_accept) . "',max_users='" . ($max_users > 1 ? $max_users : 1) . "',start_at='" . Database::escape_string($start_at) . "',end_at='" . Database::escape_string($end_at) . "',subscribe_from='" . Database::escape_string($subscribe_from) . "',subscribe_until='" . Database::escape_string($subscribe_until) . "',notes='" . Database::escape_string($notes) . "' WHERE id='" . $id . "'"; Database::query($sql); return 0; }