<?php
class Service_management
{

 // add property_master
        public function check_property($con,$property_type,$property_name,$country,$state){
            try {
                $sql=$con->prepare("Select id from  cnf_mst_property_master where fk_property_type_main=:var1 AND property_name=:var2  AND fk_utm_country_id=:var3 AND fk_utm_state_id=:var4 ");
                $sql->bindParam(':var1',$property_type);
                $sql->bindParam(':var2',$property_name);
                $sql->bindParam(':var3',$country);
                $sql->bindParam(':var4',$state);
                $sql->execute();
                $rowcount=$sql->rowCount(PDO::FETCH_ASSOC);
                return $rowcount;
            } catch (Exception $exception) {
                echo "Execution Error: ".$exception->getMessage();
            }
        }
        public function ins_property($con,$property_type,$property_name,$fdate,$construction_status,$country,$state,$service_type,
        $service_category,$price,$area_no,$area_unit,$bedroom,$bathroom,$balconies,$roof,$furnishing_status,
        $facing,$parking,$total_floor,$pfloor,$agep,$short_des,$newfilename,$newfilename1,$long_detail,$add_by,$address,$city,$zip){
            try {
                $maxidquery=$con->prepare("select max(id) as maxid from cnf_mst_property_master");
                $maxidquery->execute();
                $maxrow=$maxidquery->fetch(PDO::FETCH_ASSOC); 
                $maxid=$maxrow['maxid']+1;
                $property_id='P'.$maxid;
               
                $qy="Insert into  cnf_mst_property_master(pk_property_id,fk_property_type_main,property_name,fdate,
                                        fk_construction_status,fk_utm_country_id,fk_utm_state_id,
                                        fk_service_type,fk_service_category,price,area_no,fk_area_unit,
                                        fk_bedroom_type,bathroom,balconies,roof,furnishing_status,
                                        facing,parking,total_floor,pfloor,agep,short_des,icon,
                                        cover,long_detail,add_by,address,city,zip)
                                VALUES(:var1,:var2,:var3,:var4,:var5,:var6,:var7,:var8,:var9,:var10,:var11,:var12,
                                :var13,:var14,:var15,:var16,:var17,:var18,:var19,:var20,:var21,:var22,:var23,
                                :var25,:var26,:var27,:var28,:var29,:var30,:var31)";
                $sql=$con->prepare($qy);
                $sql->bindParam(':var1',$property_id);
                $sql->bindParam(':var2',$property_type);
                $sql->bindParam(':var3',$property_name);
                $sql->bindParam(':var4',$fdate);
                $sql->bindParam(':var5',$construction_status);
                $sql->bindParam(':var6',$country);
                $sql->bindParam(':var7',$state);
                $sql->bindParam(':var8',$service_type);
                $sql->bindParam(':var9',$service_category);
                $sql->bindParam(':var10',$price);
                $sql->bindParam(':var11',$area_no);
                $sql->bindParam(':var12',$area_unit);
                $sql->bindParam(':var13',$bedroom);
                $sql->bindParam(':var14',$bathroom);
                $sql->bindParam(':var15',$balconies);
                $sql->bindParam(':var16',$roof);
                $sql->bindParam(':var17',$furnishing_status);
                $sql->bindParam(':var18',$facing);
                $sql->bindParam(':var19',$parking);

                $sql->bindParam(':var20',$total_floor);
                $sql->bindParam(':var21',$pfloor);
                $sql->bindParam(':var22',$agep);
                $sql->bindParam(':var23',$short_des);
                $sql->bindParam(':var25',$newfilename);
                $sql->bindParam(':var26',$newfilename1);
                $sql->bindParam(':var27',$long_detail);
                $sql->bindParam(':var28',$add_by);

                $sql->bindParam(':var29',$address);
                $sql->bindParam(':var30',$city);
                $sql->bindParam(':var31',$zip);
                
                $result=$sql->execute();
                if ($result){
                    return $property_id;
                }else{
                    return 0;
                }  
            } catch (Exception $exception) {
                echo "Exception Error: ".$exception->getMessage();
                
            }
        }
    //property gallery image add
    public function ins_gallery_image($con,$property_id,$newfilename){
        try {
            $qy="Insert into  property_cover_image(fk_property_id,gallery_image)
            VALUES(:var1,:var2)";
            $sql=$con->prepare($qy);
            $sql->bindParam(':var1',$property_id);
            $sql->bindParam(':var2',$newfilename);
            
            
            $result=$sql->execute();
            if ($result) return 1; else  return 0;
        } catch (Exception $exception) {
            echo "Exception Error: ".$exception->getMessage();
            
        }
    } 
    //property aminity add
    public function ins_property_aminity($con,$property_id,$aminityselected){
        try {
            $qy="Insert into  property_aminity(fk_property_id,aminityselected)
            VALUES(:var1,:var2)";
            $sql=$con->prepare($qy);
            $sql->bindParam(':var1',$property_id);
            $sql->bindParam(':var2',$aminityselected);
            
            
            $result=$sql->execute();
            if ($result) return 1; else  return 0;
        } catch (Exception $exception) {
            echo "Exception Error: ".$exception->getMessage();
            
        }
    } 
    //user profile edit
    public function update_profile($con,$user_name,$useremail,$usertype,$userphone,$userid){
        try {
            $sql=$con->prepare("Update users set name=:var1, email=:var2, usertype=:var3,phone=:var4 where id=:var5");
            $sql->bindParam(':var1',$user_name);
            $sql->bindParam(':var2',$useremail);
            $sql->bindParam(':var3',$usertype);
            $sql->bindParam(':var4',$userphone);
            $sql->bindParam(':var5',$userid);
            $result=$sql->execute();
            if ($result) return 1; else  return 0;
        } catch (Exception $exception) {
            echo "Execution Error: ".$exception->getMessage();
        }
    }
      //user password check
      public function check_password($con,$oldpass,$userid){
        try {
            $sql=$con->prepare("Select * from users where password=:var1 AND id=:var2");
            $sql->bindParam(':var1',$oldpass);
            $sql->bindParam(':var2',$userid);
            $sql->execute();
                $rowcount=$sql->rowCount(PDO::FETCH_ASSOC);
                return $rowcount;
        } catch (Exception $exception) {
            echo "Execution Error: ".$exception->getMessage();
        }
    }
    //user password edit
    public function update_password($con,$newpass,$userid){
        try {
            $sql=$con->prepare("Update users set password=:var1 where id=:var2");
            $sql->bindParam(':var1',$newpass);
            $sql->bindParam(':var2',$userid);
            $result=$sql->execute();
            if ($result) return 1; else  return 0;
        } catch (Exception $exception) {
            echo "Execution Error: ".$exception->getMessage();
        }
    }
    //select user property
    public function  select_user_property($con,$userid){
        try {
            $sql=$con->prepare("SELECT * from cnf_mst_property_master where add_by=:var1");
            $sql->bindParam(':var1',$userid);
            $sql->execute();
            $rowcount=$sql->rowCount();
            if($rowcount>0){
                $data=$sql->fetchAll(PDO::FETCH_ASSOC);
                return $data;
            }else{
                return $rowcount;
            }
 
            
        } catch (Exception $exception) {
            echo "Exception error: ".$exception->getMessage();
            //throw $th;
        }
    }
 //select  property
 public function  select_property($con){
    try {
        $sql=$con->prepare("SELECT * from cnf_mst_property_master where transaction_status=1");
       
        $sql->execute();
        $rowcount=$sql->rowCount();
        if($rowcount>0){
            $data=$sql->fetchAll(PDO::FETCH_ASSOC);
            return $data;
        }else{
            return $rowcount;
        }

        
    } catch (Exception $exception) {
        echo "Exception error: ".$exception->getMessage();
        //throw $th;
    }
}

}

$service_query = new Service_management();
?>
