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(); }
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; }
$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 { $order_info->first_name = 'Name'; $order_info->last_name = 'Surname'; $order_info->telephone = ''; } echo json_encode($order_info); // Not available http_response_code(200); exit; } } // if it passes the while cause // That's a good sign of availability of the current order // for selected dates $order_info->avail = 1; echo json_encode($order_info); // Available http_response_code(200); exit; $conn->close();
<?php 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, $db_pass); echo "CDBConn::connect_no_locathost();<br>"; $conn->connect_no_localhost(); $conn->printinfo(); $sql = "SELECT * FROM hostels"; echo "<div style=\"background-color:#00FF00\">" . $conn->run_select($sql) . "</div>"; $conn->close(); $conn2 = new CDBConn("127.0.0.1", $db_name, $db_user, $db_pass); echo "<br>--------------<br>"; echo "CDBConn::connect()<br>"; $conn2->connect_no_localhost(); $conn2->printinfo(); $sql = "SELECT * FROM rooms"; echo "<div style=\"background-color:#00FF00\">" . $conn2->run_select($sql) . "</div>"; $conn2->close();