<?php  

class cleanto_services_methods{
		
		public $id;
		public $service_id;
		public $method_title;
        public $status;
		public $table_name="ct_services_method";
		public $conn;
        public $table_name1="ct_bookings";
        public $table_name2="ct_service_methods_units";
		public $position;
		
		/*Function for Add service*/
		public function add_services_method(){
			$query="insert into `".$this->table_name."` (`id`,`service_id`,`method_title`,`status`,`position`) values(NULL,'".$this->service_id."','".$this->method_title."','".$this->status."','0')";
			$result=mysqli_query($this->conn,$query);
			$value=mysqli_insert_id($this->conn);
			return $value;
		}
		/*Function for Update service-Not Used in this*/
		public function update_services_method(){
			$query="update `".$this->table_name."` set  `method_title`='".$this->method_title."' where `id`='".$this->id."'";
			$result=mysqli_query($this->conn,$query);
			return $result;
		}
		/*Function for Delete service*/
		public function delete_services_method(){
			$query="delete from `".$this->table_name."` where `id`='".$this->id."' ";
			$result=mysqli_query($this->conn,$query);
			return $result;
		}
		/*Function for Read All data from table*/
		public function readall(){
			$query="select * from `".$this->table_name."` where `service_id`=".$this->service_id;
			$result=mysqli_query($this->conn,$query);			
			return $result;
		}
		/*Function for Read Only one data matched with Id*/
		public function readone(){
			$query="select * from `".$this->table_name."` where `id`='".$this->id."'";
			$result=mysqli_query($this->conn,$query);
			$value=mysqli_fetch_row($result);
			return $value;
		}
        /*Function to update the status of  services */
        public function  changestatus()
        {
            $query="update `".$this->table_name."` set `status`='".$this->status."' where `id`='".$this->id."' ";
            $result=mysqli_query($this->conn,$query);
            return $result;
        }
        /*Function to update the status of  services */
        public function methodsbyserviceid()
        {
            $query="select * from `".$this->table_name."` where `service_id`='".$this->service_id."' and `status` = 'E' ";
            $result=mysqli_query($this->conn,$query);
            return $result;
        }
        public function count_ser_method(){
            $query="select count(`id`) from `".$this->table_name."` where `service_id`=".$this->service_id;
            $result=mysqli_query($this->conn,$query);
            $val=mysqli_fetch_row($result);
            return $val;
        }
        /* changed by  for export popup in adminpael( working) */
        public function display_booking_method($order_id){
            $query="select * from `".$this->table_name1 ."` where `order_id`='".$order_id."'";
            $result=mysqli_query($this->conn,$query);
            return $result;
        }
        public function display_name_method(){
            $query="select * from `".$this->table_name. "` where `id`='".$this->id."'";
            $result=mysqli_query($this->conn,$query);
            $val=mysqli_fetch_row($result);
            return $val;
        }
        public function display_method_unit(){
            $query="select * from `".$this->table_name2. "` where `id`='".$this->id."'";
            $result=mysqli_query($this->conn,$query);
            $val=mysqli_fetch_row($result);
            return $val;
        }
	
		 /*Function to update the status of  services */
       public function methodsbyserviceid_front()
       {
           $query="select DISTINCT `sm`.* from `ct_service_methods_units` as `smu`,`ct_services_method` as `sm` where `sm`.`status` = 'E' and `smu`.`status` = 'E' and `sm`.`service_id`=".$this->service_id." and `sm`.`id`=`smu`.`methods_id` and `sm`.`service_id`=`smu`.`services_id`  ORDER BY `sm`.`position`";
           $result=mysqli_query($this->conn,$query);
           return $result;
       }
    /* Check for the bookings of the services */
    public function method_isin_use($id)
    {
        $query = "select * from `ct_bookings` where `ct_bookings`.`method_id` = $id and `ct_bookings`.`booking_date_time` >= CURDATE()LIMIT 1";
        $result=mysqli_query($this->conn,$query);
        $value=mysqli_fetch_row($result);
        return $value= isset($value[0])? $value[0] : '' ;
    }
    /* check for the entry of the same title */
    public function check_same_title(){
        $query = "select * from `".$this->table_name."` where `service_id` = '".$this->service_id."' and `method_title`='".ucwords($this->method_title)."'";
        $result=mysqli_query($this->conn,$query);
        return $result;
    }
	
	
	/*  function to update the position of the services_method*/
	public function updateposition(){
		$query="update `".$this->table_name."` set `position`='".$this->position."' where `id`='".$this->id."' ";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
}
?>