index.php
index.php
php
session_start();
Class Action {
private $db;
$this->db = $conn;
}
function __destruct() {
$this->db->close();
ob_end_flush();
}
function login(){
extract($_POST);
$qry = $this->db->query("SELECT * FROM users where username = '".
$username."' and password = '".$password."' ");
if($qry->num_rows > 0){
foreach ($qry->fetch_array() as $key => $value) {
if($key != 'passwors' && !is_numeric($key))
$_SESSION['login_'.$key] = $value;
}
if($_SESSION['login_type'] == 1)
return 1;
else
return 2;
}else{
return 3;
}
}
function logout(){
session_destroy();
foreach ($_SESSION as $key => $value) {
unset($_SESSION[$key]);
}
header("location:login.php");
}
function save_user(){
extract($_POST);
$data = " name = '$name' ";
$data .= ", username = '$username' ";
$data .= ", password = '$password' ";
$data .= ", type = '$type' ";
if(empty($id)){
$save = $this->db->query("INSERT INTO users set ".$data);
}else{
$save = $this->db->query("UPDATE users set ".$data." where id =
".$id);
}
if($save){
return 1;
}
}
function save_settings(){
extract($_POST);
$data = " hotel_name = '$name' ";
$data .= ", email = '$email' ";
$data .= ", contact = '$contact' ";
$data .= ", about_content = '".htmlentities(str_replace("'","’",
$about))."' ";
if($_FILES['img']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.
$_FILES['img']['name'];
$move = move_uploaded_file($_FILES['img']
['tmp_name'],'../assets/img/'. $fname);
$data .= ", cover_img = '$fname' ";
return 1;
}
}
function save_category(){
extract($_POST);
$data = " name = '$name' ";
$data .= ", price = '$price' ";
if($_FILES['img']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.
$_FILES['img']['name'];
$move = move_uploaded_file($_FILES['img']
['tmp_name'],'../assets/img/'. $fname);
$data .= ", cover_img = '$fname' ";
}
if(empty($id)){
$save = $this->db->query("INSERT INTO room_categories set ".
$data);
}else{
$save = $this->db->query("UPDATE room_categories set ".$data."
where id=".$id);
}
if($save)
return 1;
}
function delete_category(){
extract($_POST);
$delete = $this->db->query("DELETE FROM room_categories where id = ".
$id);
if($delete)
return 1;
}
function save_room(){
extract($_POST);
$data = " room = '$room' ";
$data .= ", category_id = '$category_id' ";
$data .= ", status = '$status' ";
if(empty($id)){
$save = $this->db->query("INSERT INTO rooms set ".$data);
}else{
$save = $this->db->query("UPDATE rooms set ".$data." where id=".
$id);
}
if($save)
return 1;
}
function delete_room(){
extract($_POST);
$delete = $this->db->query("DELETE FROM rooms where id = ".$id);
if($delete)
return 1;
}
function save_check_in(){
extract($_POST);
$data = " room_id = '$rid' ";
$data .= ", name = '$name' ";
$data .= ", contact_no = '$contact' ";
$data .= ", status = 1 ";
if(empty($id)){
$save = $this->db->query("INSERT INTO checked set ".$data);
$id=$this->db->insert_id;
}else{
$save = $this->db->query("UPDATE checked set ".$data." where
id=".$id);
}
if($save){
}
function save_book(){
extract($_POST);
$data = " booked_cid = '$cid' ";
$data .= ", name = '$name' ";
$data .= ", contact_no = '$contact' ";
$data .= ", status = 0 ";
if($save){
return $id;
}
}