MRBS: Check if user has booked 2 rooms at the same time

Posted on 17. Oktober 2013 Comments

This little function checks if the same user has booked $room1 and $room2 at the same time.

function checkForSameUser($room1,$room2,$user,$starttime,$endtime,$tbl_entry) {
$sql = "SELECT id, name, start_time, create_by, status
FROM $tbl_entry
WHERE start_time < $endtime
AND end_time > $starttime
AND (room_id=$room1 OR room_id=$room2)
AND create_by=\"$user\"";
$res = sql_query($sql);
if (empty($res))
{
// probably because the table hasn't been created properly
trigger_error(sql_error(), E_USER_WARNING);
fatal_error(TRUE, get_vocab("fatal_db_error"));
}
if (sql_count($res) != 0)
{
sql_free($res);
return "error";
}
}

 

You can use it e.g. in mrbs_sql.inc in the function mrbsCheckFree(..) to check if a user is allowed to book a certain room like this.

// 1 and 2 are the roomIDs
$result = checkForSameUser(1,2,$user,$starttime,$endtime,$tbl_entry);
if ($result == "error"){
$err[] = get_vocab("multiple_rooms");
return $err;
}
}

As you can see the first function returns the string „error“ in case an error occured. I translated the string for multiple_rooms in every language used on this MRBS system and edited the the lang.x file in the main folder, e.g. lang.de:

$vocab["multiple_rooms"] = "Mehrere Räume können nicht gleichzeitig vom selben User gebucht werden";

Flattr this!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.