Exemple #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();
}
$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;
                }
                if ($conn->run_insert($adduser_query) != 0) {
                    $_SESSION['g_username'] = $input_email;
                    $_SESSION['g_hostel_id'] = NULL;
                    echo "Congratulation, registration completed!";
                    http_response_code(200);
                    exit;
    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'];
            $order_info->telephone = $guest_row['telephone'];
        } else {
Exemple #4
0
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;
    $cur_room_type = $rooms[$i]->type;
    $cur_room_rate = $rooms[$i]->rate;
    $sql_room_add = "INSERT INTO rooms (name, bed_count, type_id, rate, hostel_id) VALUES('{$cur_room_name}', {$cur_room_capacity},   {$cur_room_type}, {$cur_room_rate}, {$new_hostel_id})";
$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();
Exemple #6
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();
Exemple #7
0
$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>";
} else {
Exemple #8
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();