<span class="big_text"><?php 
    echo Translate($booking_action, 1);
    ?>
</span>
	<br>
	<span style="font-weight:bold"><?php 
    echo $family_name . " / " . $object_name . "</span> <span class=\"small_text\">(" . $managers_names . ")</span>";
    ?>

	<div class="colorframe" style="padding:10px">

		<table class="table3">

			<tr>
				<?php 
    if (getObjectInfos($_REQUEST["object_id"], "object_is_managed") || intval($_COOKIE["bookings_profile_id"]) > 3) {
        ?>

				<td><?php 
        echo Translate("Booker", 1);
        ?>
<br><select id="booker_id" name="booker_id" style="width:200px"><?php 
        echo $users_list;
        ?>
</select></td>

				<?php 
    } else {
        ?>

				<td>
        $update_status = "";
    } else {
        $booking_action = "Edit booking";
        $sql = "SELECT user_id, book_start, book_end, validated, misc_info ";
        $sql .= "FROM rs_data_bookings ";
        $sql .= "WHERE book_id = " . $_REQUEST["book_id"] . " ";
        $sql .= "AND object_id = " . $_REQUEST["object_id"] . ";";
        $booking = db_query($database_name, $sql, "no", "no");
        $booking_ = fetch_array($booking);
        $booker_id = $booking_["user_id"];
        $start_date = date($date_format, strtotime($booking_["book_start"]));
        $start_hour = date("H:i", strtotime($booking_["book_start"]));
        $misc_info = $booking_["misc_info"];
        $array_duration = getDuration(strtotime($booking_["book_end"]) - strtotime($booking_["book_start"]));
        $action_ = "update_booking";
        if ($booker_id == $_COOKIE["bookings_user_id"] || getObjectInfos($_REQUEST["object_id"], "current_user_is_manager") || $_COOKIE["bookings_profile_id"] == "4") {
            $update_status = "";
        }
    }
    $duration_days = $array_duration["days"];
    $duration_hours = $array_duration["hours"];
    $duration_minutes = $array_duration["minutes"];
    ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Exemplo n.º 3
0
function insertBooking($action, $book_id, $booker_id, $object_id, $booking_start, $booking_end, $misc_info, $validated)
{
    global $app_url, $database_name, $time_offset;
    $misc_info = addslashes($misc_info);
    // extracts booker name from booker id
    $sql = "SELECT first_name, last_name, email ";
    $sql .= "FROM rs_data_users ";
    $sql .= "WHERE user_id = " . $booker_id . ";";
    $temp = db_query($database_name, $sql, "no", "no");
    $temp_ = fetch_array($temp);
    $booker_name = $temp_["first_name"] . " " . $temp_["last_name"];
    $booker_email = $temp_["email"];
    // extracts object name from object id
    $sql = "SELECT object_name, email_bookings FROM rs_data_objects WHERE object_id = " . $object_id . ";";
    $temp = db_query($database_name, $sql, "no", "no");
    $temp_ = fetch_array($temp);
    $object_name = $temp_["object_name"];
    $email_bookings = $temp_["email_bookings"];
    switch ($action) {
        case "update":
            $sql = "UPDATE rs_data_bookings SET ";
            $sql .= "book_start = '" . date("Y-m-d H:i:s", strtotime($booking_start) + $time_offset) . "', ";
            $sql .= "book_end = '" . date("Y-m-d H:i:s", strtotime($booking_end) + $time_offset) . "', ";
            $sql .= "validated = " . $validated . ", ";
            $sql .= "misc_info = '" . $misc_info . "' ";
            $sql .= "WHERE book_id = " . $_REQUEST["book_id"] . ";";
            db_query($database_name, $sql, "no", "no");
            break;
        case "insert":
            // creates a random code
            $rand_code = rand(0, 65535);
            // inserts the new booking associated with the random code
            $sql = "INSERT INTO rs_data_bookings ( rand_code, object_id, book_date, user_id, book_start, book_end, misc_info, validated ) VALUES ( ";
            $sql .= $rand_code . ", ";
            $sql .= $object_id . ", ";
            $sql .= "'" . date("Y-m-d H:i:s") . "', ";
            $sql .= $booker_id . ", ";
            $sql .= "'" . date("Y-m-d H:i:s", strtotime($booking_start) + $time_offset) . "', ";
            $sql .= "'" . date("Y-m-d H:i:s", strtotime($booking_end) + $time_offset) . "', ";
            $sql .= "'" . $misc_info . "', ";
            $sql .= $validated . " );";
            db_query($database_name, $sql, "no", "no");
            // gets new booking id using the random code
            $sql = "SELECT book_id FROM rs_data_bookings WHERE rand_code = " . $rand_code . ";";
            $new_booking = db_query($database_name, $sql, "no", "no");
            $new_booking_ = fetch_array($new_booking);
            $book_id = $new_booking_["book_id"];
            // clears random code
            $sql = "UPDATE rs_data_bookings SET rand_code = '' WHERE rand_code = " . $rand_code . ";";
            db_query($database_name, $sql, "no", "no");
            if (!$validated && getObjectInfos($object_id, "is_managed") && $email_bookings == "yes") {
                // sends an email for the object's manager to validate the new booking
                $headers = "MIME-Version: 1.0\r\n";
                $headers .= "Content-type: text/html; charset=utf-8\r\n";
                $headers .= "From: " . $booker_name . " <" . $booker_email . ">\r\n";
                $message = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
                $message .= "<html>\n";
                $message .= "<head>\n";
                $message .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";
                $message .= "<title>iframe</title>\n";
                $message .= "<style type=\"text/css\">\n";
                $message .= "a:link {color:black; text-decoration: none; }\n";
                $message .= "a:visited {color:black; text-decoration: none; }\n";
                $message .= "a:hover {color:red; text-decoration: none; }\n";
                $message .= "table { border-collapse: collapse; }\n";
                $message .= "td { padding: 3px; }\n";
                $message .= "</style>\n";
                $message .= "</head>\n";
                $message .= "<body>\n";
                $message .= $booker_name . " " . Translate("has sent the following booking request", 1) . " :\n";
                $message .= "<p>\n";
                $message .= Translate("Object", 1) . " : " . $object_name . "<br>\n";
                $message .= Translate("Start", 1) . " : " . date($date_format . " H:i", strtotime($booking_start)) . "<br>\n";
                $message .= Translate("End", 1) . date($date_format . " H:i", strtotime($booking_end)) . "<p>\n";
                $message .= Translate("This booking has already been recorded to the calendar but needs one of the following action", 1) . " :<p>\n";
                $message .= "<table><tr><td>\n";
                $message .= "<a\thref=\"" . $app_url . "actions.php?action_=confirm_booking&book_id=" . $book_id . "&validated=yes\" target=\"action_iframe\">[ " . Translate("Accept", 1) . " ]</A>\n";
                $message .= "</td><td style=\"width:20px\"></td><td>\n";
                $message .= "<a\thref=\"" . $app_url . "actions.php?action_=confirm_booking&book_id=" . $book_id . "&validated=no\" target=\"action_iframe\">[ " . Translate("Cancel", 1) . " ]</A>\n";
                $message .= "</td></tr></table>\n";
                $message .= "<iframe frameborder=\"0\" name=\"action_iframe\" id=\"action_iframe\" style=\"border:none; width:500px; height:100px\">\n";
                $message .= "</body>\n";
                $message .= "</html>";
                mail(getObjectInfos($object_id, "managers_emails"), Translate("Booking validation request", 1), $message, $headers);
            }
            return true;
    }
}