summaryrefslogtreecommitdiffstats
path: root/tools/infra-dashboard/utils/book.php
diff options
context:
space:
mode:
authorjose.lausuch <jose.lausuch@ericsson.com>2016-06-01 23:00:08 +0200
committerjose.lausuch <jose.lausuch@ericsson.com>2016-06-02 20:12:49 +0200
commitaf427a992a96519c00ac9f98db8745f9fc1198fb (patch)
tree36f69164b289ce2405419f3946b7af0ba8f8b08e /tools/infra-dashboard/utils/book.php
parent43b44d05ed662d7e9e4f0a66b5f1744685d7b5cc (diff)
OPNFV Infra Dashboard
JIRA: RELENG-12 Change-Id: I7451a3d234e4e5d946cdb905d5720be6159b6544 Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
Diffstat (limited to 'tools/infra-dashboard/utils/book.php')
-rw-r--r--tools/infra-dashboard/utils/book.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/tools/infra-dashboard/utils/book.php b/tools/infra-dashboard/utils/book.php
new file mode 100644
index 00000000..6d4c5b20
--- /dev/null
+++ b/tools/infra-dashboard/utils/book.php
@@ -0,0 +1,82 @@
+<?php
+
+ include 'database.php';
+
+ function book() {
+ $resource_id = $_POST['resource_id'];
+ $resource_name = $_POST['resource_name'];
+ $user_id = $_POST['user_id'];
+ $start = $_POST['start'];
+ $end = $_POST['end'];
+ $purpose = $_POST['purpose'];
+
+ $query = "select role.name as rolename from user, role, user_role where user.user_id = ".$user_id." and role.role_id=user_role.role_id and user_role.user_id=user.user_id;";
+ $result = mysql_query($query);
+
+ if(mysql_num_rows($result) == 0) {
+ echo "1"; //return a code instead of a meesage. Display the message later in javascript according to the returned code.
+ //echo "Booking not possible (your account is not associated with a role). Please contact the administrator.";
+ exit;
+ }
+ $is_only_lab_owner = true;
+ while ($row = mysql_fetch_array($result)) {
+ $rolename = $row['rolename'];
+ if ($rolename != "lab_owner") $is_only_lab_owner = false;
+ }
+ if ($is_only_lab_owner) {
+ $query = "select * from user u inner join user_resource r on r.user_id=u.user_id and u.user_id=".$user_id." and r.resource_id=".$resource_id.";";
+ $result = mysql_query($query);
+ if(mysql_num_rows($result) == 0) {
+ echo "2";
+ //echo "You are not allowed to book this resource. ";
+ exit;
+ }
+ }
+ $query = "INSERT INTO booking (resource_id, user_id, starttime, endtime, purpose) VALUES (".$resource_id.",".$user_id.",'".$start."','".$end."', '".$purpose."');";
+ $result = mysql_query($query);
+ if(mysql_insert_id()>0){
+ echo "Booking successful. The resource '".$resource_name."' is booked from ".$start." to ".$end.".";
+ }
+ else{
+ echo "Mysql Error : ".mysql_error().". Query = ".$query;
+ }
+
+ }
+
+ function getBookedDates() {
+ $resource_id = $_POST['resource_id'];
+ $query = "SELECT b.booking_id, b.resource_id,u.name as username,u.email,b.starttime,b.endtime,b.creation,b.purpose FROM booking as b,user as u WHERE b.resource_id=".$resource_id." AND b.user_id=u.user_id;";
+ $result = mysql_query($query);
+
+ $events = array();
+ while ($row = mysql_fetch_array($result)) {
+ $e = array();
+ $e['id'] = $row['booking_id'];
+ $e['booker_name'] = $row['username'];
+ $e['booker_email'] = $row['email'];
+ $e['title'] = $row['purpose'];
+ $e['start'] = $row['starttime'];
+ $e['end'] = $row['endtime'];
+ $e['bookdate'] = $row['creation'];
+
+ // Merge the event array into the return array
+ array_push($events, $e);
+ }
+
+ echo json_encode($events);
+ }
+
+
+
+ $action = $_POST['action'];
+
+ connectDB();
+ if ($action == "book") {
+ book();
+ } elseif ($action == "getBookedDates" ) {
+ getBookedDates();
+ } else {
+ echo "Invalid POST action.";
+ }
+ closeDB();
+?>