Example #1
0
function initDashboard()
{
    include_once ABSPATH . "/php/CDBConn.php";
    include_once ABSPATH . "/php/hostconfig.php";
    $conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123");
    if (!$conn->connect_no_localhost()) {
        http_response_code(503);
        exit;
    }
    $cur_login = $_SESSION['g_username'];
    $get_hostel_id_sql = "SELECT hostel_id FROM users WHERE login = '******'";
    $conn->run_query($get_hostel_id_sql);
    $line = $conn->fetch_array();
    // We almost now from which hostel is user
    $hostel_id = $line['hostel_id'];
    // in case if hostel id is not set, it's an indicator that hostel  definetely has not been configured yet.
    if ($hostel_id === NULL) {
        header("Location: /configure/index.php");
        exit;
    }
    $get_is_configured_sql = "SELECT is_configured FROM hostels WHERE id = {$hostel_id}";
    $conn->run_query($get_is_configured_sql);
    $line = $conn->fetch_array();
    $is_configured = $line['is_configured'];
    // This is the case when user almost configured not
    if ($is_configured === 'f') {
        header("Location: /configure/index.php");
        // exit();
    }
    $conn->close();
}
Example #2
0
if (!isset($_SESSION['g_username'])) {
    http_response_code(401);
    exit;
}
$date_in = $_POST['date_in'];
$date_out = $_POST['date_out'];
$bed_index = $_POST['bed_index'];
$room_id = $_POST['room_id'];
require_once '../app-config.php';
include_once ABSPATH . '/php/CDBConn.php';
include_once ABSPATH . '/php/hostconfig.php';
$conn = new CDBConn($jet_ip, $db_name, $db_user, 'qwerty123', FALSE);
$conn->connect();
// Finding whether it overlaps with some of existing orders
$check_availability = "SELECT  guest_id, date_in, date_out, date_overlap(date_in, date_out, '{$date_in}', '{$date_out}') FROM orders WHERE bed_index={$bed_index} AND room_id={$room_id}";
$conn->run_query($check_availability);
$order_info = new stdClass();
while ($line = $conn->fetch_array()) {
    if ($line['date_overlap'] == 1) {
        // avail = 0; does mean there exists at least on order
        // which conflicts with the current order.
        $order_info->avail = 0;
        $order_info->date_in = $line['date_in'];
        $order_info->date_out = $line['date_out'];
        $guest_id = $line['guest_id'];
        $guest_query = "SELECT * FROM guests WHERE id = '{$guest_id}'";
        $conn->run_query($guest_query);
        if ($conn->affected_rows() == 1) {
            $guest_row = $conn->fetch_array();
            $order_info->first_name = $guest_row['first_name'];
            $order_info->last_name = $guest_row['last_name'];
Example #3
0
<?php

session_start();
if (!isset($_SESSION['g_username'])) {
    header("Location: /login/index.php");
    exit;
}
$path_to_cdbconn = $_SERVER["DOCUMENT_ROOT"] . "/php/CDBConn.php";
include_once $path_to_cdbconn;
$hostel_info = json_decode($_POST["hostel_info"]);
$rooms = json_decode($_POST["rooms"]);
$conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123", TRUE);
$conn->connect();
// Creating new hostel
$insert_query = "INSERT INTO hostels (name, room_count, is_configured) VALUES('{$hostel_info->hostel_name}', {$hostel_info->room_count}, TRUE) RETURNING id";
$conn->run_query($insert_query);
echo $conn->affected_rows() . " rows inserted.";
$new_hostel_id = 0;
while ($line = $conn->fetch_array()) {
    echo "id = " . $line[0];
    $new_hostel_id = $line[0];
}
// Associating email with hostel
$login_from_session = $_SESSION['g_username'];
$update_query = "UPDATE users SET hostel_id = {$new_hostel_id} WHERE login = '******'";
$conn->run_query($update_query);
$_SESSION['g_hostel_id'] = $new_hostel_id;
// Associating rooms with hostel
for ($i = 0; $i < count($rooms); $i++) {
    $cur_room_name = $rooms[$i]->name;
    $cur_room_capacity = $rooms[$i]->capacity;
Example #4
0
<?php

session_start();
require_once "../app-config.php";
include_once ABSPATH . "/php/hostconfig.php";
include_once ABSPATH . "/php/CDBConn.php";
$input_email = $_POST['email'];
$input_reg_token = $_POST['reg_token'];
$input_password1 = $_POST['password1'];
$input_password2 = $_POST['password2'];
//printf("input_email=%s<br>input_reg_token=%s<br>input_password1=%s<br>input_password2=%s<br>", $input_email, $input_reg_token, $input_password1, $input_password2);
$conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123", FALSE);
$conn->connect();
$query = "SELECT reg_token, is_activated FROM users WHERE login='******'";
if ($conn->run_query($query)) {
    switch ($conn->affected_rows()) {
        case 0:
            echo "This email has no associated registration inquiry. Link is invalid. Please, review whether you fully copied the activation link. If you don't know what's happened, just try signup again.<br>";
            http_response_code(422);
            break;
        case 1:
            $arr = $conn->fetch_array();
            //var_dump($arr['reg_token']);
            //var_dump($_POST['reg_token']);
            if ($arr["reg_token"] == $input_reg_token) {
                $adduser_query = "UPDATE users SET is_activated = TRUE, password='******' WHERE login='******'";
                if ($arr["is_activated"] === 't') {
                    echo "Your email has been activated. You may log in to your account";
                    http_response_code(422);
                    exit;
                }
Example #5
0
    exit;
}
require_once "../app-config.php";
include_once ABSPATH . "/php/CDBConn.php";
include_once ABSPATH . "/php/hostconfig.php";
$login = json_decode($_POST['login']);
$password = json_decode($_POST['password']);
$conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123");
if (!$conn->connect()) {
    http_response_code(503);
    exit;
}
$check_user_sql = "SELECT * FROM users WHERE login='******' AND password='******'";
echo $conn->run_select($check_user_sql);
if ($conn->affected_rows() != 1) {
    echo "user with login:'******'; and password:'******' doesnot exists" . "<br>";
    http_response_code(401);
    exit;
} else {
    $_SESSION['g_username'] = $login;
    $get_hostel_id_sql = "SELECT hostel_id FROM users WHERE login='******'";
    $conn->run_query($get_hostel_id_sql);
    $row = $conn->fetch_array();
    $hostel_id = $row['hostel_id'];
    // Even in case if hostel_id is null,
    // doConfigure.php script will create it
    $_SESSION['g_hostel_id'] = $hostel_id;
    http_response_code(200);
    exit;
}
$conn->close();
Example #6
0
$room_ids = $_POST['room_ids'];
require_once '../app-config.php';
include_once ABSPATH . '/php/CDBConn.php';
include_once ABSPATH . '/php/hostconfig.php';
$conn = new CDBConn($jet_ip, $db_name, $db_user, 'qwerty123');
$conn->connect();
// Generating SQL query
$select_rooms_orders = "SELECT * FROM orders WHERE ";
//echo "Select rooms orders query(before)= ".$select_rooms_orders;
$append = "";
//echo "\n".sizeof($room_ids)."\n";
for ($i = 0; $i < sizeof($room_ids); $i++) {
    $current_id = $room_ids[$i];
    if ($i != 0) {
        $append = $append . " OR room_id={$current_id}";
    } else {
        $append = $append . " room_id={$current_id}";
    }
}
//echo "\nappend = ".$append."\n";
$select_rooms_orders = $select_rooms_orders . $append;
//echo "Select rooms orders query(after) = ".$select_rooms_orders;
$conn->run_query($select_rooms_orders);
$orders = [];
$i = 0;
while ($order = $conn->fetch_array()) {
    $orders[$i] = $order;
    $i++;
}
echo json_encode($orders);
$conn->close();
Example #7
0
$telephone = $_POST['telephone'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$date_in = $_POST['date_in'];
$date_out = $_POST['date_out'];
require_once '../app-config.php';
include_once ABSPATH . '/php/CDBConn.php';
include_once ABSPATH . '/php/hostconfig.php';
$conn = new CDBConn($jet_ip, $db_name, $db_user, 'qwerty123', TRUE);
$conn->connect();
/*
SELECT date_overlap(date_in, date_out, '2016-01-12', '2016-01-13') FROM orders WHERE bed_index=1 AND room_id=328
*/
// check avalability
$check_availability = "SELECT date_overlap(date_in, date_out, '{$date_in}', '{$date_out}') FROM orders WHERE bed_index={$bed_index} AND room_id={$room_id}";
$conn->run_query($check_availability);
$line = $conn->fetch_array();
if ($line['date_overlap'] == 1) {
    echo 'dates are not available';
    http_response_code(409);
    exit;
}
$get_guest = "SELECT id FROM guests WHERE first_name='{$first_name}' AND last_name='{$last_name}' AND telephone = '{$telephone}'";
$conn->run_query($get_guest);
$guest_id = 0;
if ($conn->affected_rows() == 0) {
    $insert_guest = "INSERT INTO guests(first_name, last_name, telephone) VALUES('{$first_name}','{$last_name}','{$telephone}') RETURNING id";
    $conn->run_query($insert_guest);
    $arr = $conn->fetch_array();
    $guest_id = $arr['id'];
    echo "New guest id = " . $guest_id . "<br>";
Example #8
0
<?php

session_start();
if (!isset($_SESSION['g_username'])) {
    http_response_code(401);
    exit;
}
$hostel_id = $_POST['hostel_id'];
require_once "../app-config.php";
include_once ABSPATH . "/php/CDBConn.php";
include_once ABSPATH . "/php/hostconfig.php";
$conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123");
$conn->connect_no_localhost();
$room_count_query = "SELECT room_count FROM hostels WHERE id = '{$hostel_id}'";
$conn->run_query($room_count_query);
$row = $conn->fetch_array();
if ($conn->affected_rows() == 1) {
    echo $row['room_count'];
    http_response_code(200);
    exit;
} else {
    http_response_code(401);
    exit;
}
Example #9
0
<?php

session_start();
if (!isset($_SESSION['g_username'])) {
    http_response_code(401);
    exit;
}
$room_id = $_POST['room_id'];
require_once '../app-config.php';
include_once ABSPATH . '/php/CDBConn.php';
include_once ABSPATH . '/php/hostconfig.php';
$conn = new CDBConn($jet_ip, $db_name, $db_user, 'qwerty123');
$conn->connect();
$select_orders = "SELECT * FROM orders WHERE room_id = {$room_id}";
$conn->run_query($select_orders);
$orders = [];
$i = 0;
while ($order = $conn->fetch_array()) {
    $orders[$i] = $order;
    $i++;
}
echo json_encode($orders);
$conn->close();
Example #10
0
include_once "../app-config.php";
include_once ABSPATH . "/php/CDBConn.php";
include_once ABSPATH . "/php/hostconfig.php";
if (!isset($_SESSION['g_username'])) {
    header("Location: /login/index.php");
    exit;
} else {
    //
    $conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123");
    if (!$conn->connect_no_localhost()) {
        echo "Database error<br>";
        exit;
    }
    $cur_login = $_SESSION['g_username'];
    $get_hostel_id_query = "SELECT hostel_id,login FROM users WHERE login='******'";
    $res = $conn->run_query($get_hostel_id_query);
    if ($conn->affected_rows() == 0) {
        echo "There is no such login in database. <br>";
        exit;
    }
    $line = $conn->fetch_array();
    $hostel_id = $line['hostel_id'];
    if ($hostel_id != NULL) {
        header("Location: /dashboard/");
        exit;
    }
}
// insert is_configured flag checking
?>
<!DOCTYPE html>
<html>
Example #11
0
 function putRoomsToDatabase(&$arr, $rcount)
 {
     $path_to_hostconfig = $_SERVER['DOCUMENT_ROOT'] . "/php/hostconfig.php";
     include_once $path_to_hostconfig;
     $path_to_cdbconn = $_SERVER["DOCUMENT_ROOT"] . "/php/CDBConn.php";
     include_once $path_to_cdbconn;
     $my_conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123", FALSE);
     $my_conn->connect();
     for ($i = 1; $i <= $rcount; $i++) {
         $nazv = "nazv" . $i;
         $room_info[$i] .= "<br><br>Room name: " . $arr[$nazv];
         $type_id = "type" . $i;
         $q_select = "SELECT room_type_name FROM room_type WHERE room_type_id = '" . $arr[$type_id] . "'";
         $my_conn->run_query($q_select);
         $line = pg_fetch_array($my_conn->getResult());
         $type_name = "type_name" . $i;
         $arr[$type_name] = $line[0];
         $room_info[$i] .= "<br><br>Category of room: " . $arr[$type_name];
         $capacity = "capacity" . $i;
         $room_info[$i] .= "<br><br>Capacity of the room: " . $arr[$capacity];
         //$q_insert = "INSERT INTO room (room_name, room_type_id, bed_count) VALUES('".$arr[$nazv]."',".$arr[$type_id].",".$arr[$capacity].")";
         //$my_conn->run_insert($q_insert);
     }
     $my_conn->close();
     return $room_info;
 }
Example #12
0
<?php

$path_to_hostconfig = $_SERVER["DOCUMENT_ROOT"] . "/php/hostconfig.php";
$path_to_cdbconn = $_SERVER["DOCUMENT_ROOT"] . "/php/CDBConn.php";
include_once $path_to_hostconfig;
include_once $path_to_cdbconn;
$conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123");
$conn->connect();
$sql = "SELECT * FROM room_types";
$conn->run_query($sql);
$data = array();
/*while ($line = pg_fetch_array($conn->getResult()))
{
  // echo $arr["room_type_id"].$arr["room_type_name"]."<br>";
   $data[$line["room_type_id"]] = $line["room_type_name"];
}

foreach($data as $id => $name)
{
   echo $id.$name."<br>";
}*/
while ($line = pg_fetch_row($conn->getResult())) {
    $data[] = $line;
}
echo json_encode($data);
$conn->close();
Example #13
0
<?php

session_start();
if (!isset($_SESSION['g_username'])) {
    http_response_code(401);
    exit;
}
require_once '../app-config.php';
include_once ABSPATH . "/php/CDBConn.php";
include_once ABSPATH . "/php/hostconfig.php";
//$hostel_id = $_POST['hostel_id'];
$hostel_id = $_SESSION['g_hostel_id'];
$conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123");
$conn->connect();
$sql = "SELECT name, bed_count,id FROM rooms WHERE hostel_id ={$hostel_id} ORDER BY id DESC";
$rooms = array();
$result = $conn->run_query($sql);
if (!$result) {
    http_response_code(404);
    exit;
} else {
    $i = 0;
    while ($room = $conn->fetch_array()) {
        $rooms[$i]->name = $room['name'];
        $rooms[$i]->bed_count = $room['bed_count'];
        $rooms[$i]->id = $room['id'];
        $i++;
    }
    echo json_encode($rooms);
}
$conn->close();