<?php
require_once('db_config.php');
 date_default_timezone_set("Asia/Calcutta");

$db_config = new db_config();

 class website extends db_config
{
    public $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
    public $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');



      public function admin_login($info)
      {
      	$username = mysqli_real_escape_string($this->con,trim($info['username']));
      	$password = md5(trim($info['password']));
      	
        //echo "select id from tbl_admin_login where username = '".$username."' && password = '".$password."' && status='Active'"; die;
      	$sql=$this->con->query("select id from tbl_admin_login where username = '".$username."' && password = '".$password."' && status='Active'");
      	if($sql->num_rows==0)
      	{
      		$_SESSION['status']='Login failed';
      	    header('location:index.php?login-failed='.str_replace(' ', '-', $_SESSION['status']));
      	}
      	else
      	{
          $id = 1;
          $this->portal_log($id,"Admin Login");
      		$_SESSION['admin_login']=1;
      		header('location:dashboard.php');
      	}
      	
      }
      public function admin_password()
      {
      	
      	
      	$sql=$this->con->query("select * from tbl_admin_login where id=1 and status='Active'");
      	$fetch_password = $sql->fetch_array();
      	$password = $fetch_password['pass'];
         
         return $password; 
      	
      }

      public function change_password($info)
      {
        $oldpass     = $info['oldpassword'];
        $newpassword = $info['newpassword'];
        $cpassword   = $info['retypepassword'];
        if($newpassword!=$cpassword)
        {
          echo "<script>window.location.href='change_password.php';
          alert('New Password And Confirm Password did not match')</script>";
        }
        if($oldpass)
        {

          $check_pass = $this->con->query("select id from tbl_admin_login where password = '".md5($oldpass)."' && status='Active'");
          if($check_pass->num_rows>0)
          {
            $sql = $this->con->query("update tbl_admin_login set password='".md5($newpassword)."',pass='".$newpassword."' where id=1");
            if($sql>0)
            {
              $id = 1;
              $this->portal_log($id,"Admin Password Update");
              echo "<script>window.location.href='logout.php';
              alert('Password Update Successfully')</script>";
              //header('location:logout.php');   
            }
          }
          else
          {
            echo "<script>window.location.href='change_password.php';
          alert('Please Enter Correct Old Password')</script>";
          }
        }
      	else
        {
          echo "<script>window.location.href='change_password.php';
          alert('Please Enter Old Password')</script>";
        }
      	
      }

      public function logout()
      {

      	session_destroy();
        $id = 1;
        $this->portal_log($id,"Admin Logout");
      	$_SESSION['status']='Logout Successfully';
      	header('location:index.php?logout='.str_replace(' ', '-',$_SESSION['status']));
      }
 
      public function view_list($tbl,$where,$limit)
      {
        $fetch_list = array();  
      	$sql = $this->con->query("select * from $tbl where $where $limit");
      	while($list = $sql->fetch_assoc())
      	{
      		$fetch_list[] = $list;
      	}
      	return @$fetch_list;

      }

      public function active($tbl,$where,$total_row,$page)
      {

      	$sql = $this->con->query("UPDATE $tbl set status='1' $where");
      	if($sql>0)
      	{
      		$_SESSION['total_data']=$total_row.' Rows Actived Successfully';
      		header('location:'.$page);

      	}
      }
        
          public function deactive($tbl,$where,$total_row,$page)
      {
        
      	$sql = $this->con->query("UPDATE $tbl set status='0' $where");
      	if($sql>0)
      	{
      		$_SESSION['total_data']=$total_row.' Rows Deactived Successfully';
      		header('location:'.$page);

      	}
      }
          public function delete($tbl,$where,$total_row,$page)
      {
      	$sql = $this->con->query("DELETE FROM $tbl $where");
      	if($sql>0)
      	{
      		$_SESSION['total_data']=$total_row.' Rows Deleted Successfully';
      		header('location:'.$page);

      	}
      }
public function delete_image($image_name,$sql,$page)
      {
        $sql = $this->con->query($sql);
        if($sql>0)
        {
           $path="../images/main_img/".$image_name;
           unlink($path);

          $_SESSION['total_data']=$total_row.' Images Removed Successfully';
          header('location:'.$page);

        }
      }

      public function check_row_status($tbl,$where)
      {

      	$sql = $this->con->query("select * from $tbl $where");
      	$get_row = $sql->num_rows;
      	return $get_row; 
      }

     
      public function fetch_rows($tbl,$where)
      {
      	$sql = $this->con->query("select * from $tbl $where");
      	$fetch_all_row = $sql->fetch_assoc();
      	return $fetch_all_row;
      	
      }
      public function base_url()
      {
        return $this->baseurl;
   
      }
      public function self_query($query)
      {   
          $row = array();
          $sql = $this->con->query($query);
         
          while($data = $sql->fetch_assoc())
          {
              $row[] = $data;
          }
         return @$row;
       
      }


       
      public function user_email_verify($id,$email,$account_type)
      {
        
        if(isset($id) && isset($email) && isset($account_type))
        {

          $sql = $this->con->query("update tbl_user set email_status=1 where id='".(int)$id."' && email_id='".$email."' && account_type='".(int)$account_type."'");
          $this->portal_log($id,"$email -Email Verified By User");
        }
      }

      public function user_login($info,$account_type)
      {
        
           $baseurl = $this->baseurl;
          $email = $info['email'];
          $email_validation = $this->valid_email($email);
          if($email_validation!=0)
          {
            
            
            $sql = $this->con->query("select id from tbl_user where email_id='".$email."' && password='".md5($info['password'])."' && account_type='".$account_type."' and status=1");
            $user_detail = $sql->fetch_assoc();

            if($user_detail['id']<1)
            {

              unset($_SESSION['account_status']);
              $_SESSION['account_status']="Failed : Username and password did not match";
              header('location:'.$baseurl.'/login');
            }
            else
            {
             
            $id = $user_detail['id'];
            //echo 'hello'; die;
            $this->portal_log($id,"$email -User Login");
            $_SESSION['user_email']=$email;
            $_SESSION['account_type']=$account_type;
            header('location:'.$baseurl);
            }
          }
           else
           {

            unset($_SESSION['failed']);
            $_SESSION['failed'] = "Failed : Employer Enter Invalid Email Id";
            header('location:'.$baseurl.'/login');
            }
            
      }

      
     
      

      public function portal_log($insert_id,$description)
      {
        $description = mysqli_real_escape_string($this->con,$description);

        $sql = $this->con->query("INSERT INTO tbl_log (activity_id,description,add_date) values('".$insert_id."','".$description."',now())");
      }

  
          

  


       
      public function update_address($info,$id)
      {
        $baseurl = $this->base_url();

        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

         $phone1 = mysqli_real_escape_string($this->con,$info['phone1']);
         $phone2 = mysqli_real_escape_string($this->con,$info['phone2']);
          $email1 = mysqli_real_escape_string($this->con,$info['email1']);
           $email2 = mysqli_real_escape_string($this->con,$info['email2']);
            $fb = mysqli_real_escape_string($this->con,$info['fb']);
          $twitter = mysqli_real_escape_string($this->con,$info['twitter']);
           $youtube = mysqli_real_escape_string($this->con,$info['youtube']);
           $insta = mysqli_real_escape_string($this->con,$info['insta']);
         $address = mysqli_real_escape_string($this->con,$info['address']);

           $logo = "";

            if(@$_FILES['image']['name'] != '') 
            {
            @$logo =$_FILES["image"]["name"];
            $path=$_SERVER["DOCUMENT_ROOT"]."/kidz/images/main_img/".$logo;
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            //echo "update tbl_address set `phone1`='".$phone1."',`phone2`='".$phone2."',`email1`='".$email1."',`email2`='".$email2."',`fb`='".$fb."',`twitter`='".$twitter."',`youtube`='".$youtube."',`insta`='".$insta."',`address`='".$address."'"; die;
          $query = "update tbl_address set `phone1`='".$phone1."',`phone2`='".$phone2."',`email1`='".$email1."',`email2`='".$email2."',`fb`='".$fb."',`twitter`='".$twitter."',`youtube`='".$youtube."',`insta`='".$insta."',`address`='".$address."'";
          
          if($logo!='')
          {
            $query.=",`image`='".$logo."' ";
          }

          $query.=",`mod_date`=now() where `id`='".(int)$id."'";
          


           $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - Address Page Updated");
            unset($_SESSION['msg']);
            unset($_SESSION['error']);
            $_SESSION['msg']='Data Updated Successfully';
            header('location:update-address.php?edit=1');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
             header('location:update-address.php?edit=1');
          }   
        
      }


       public function add_slider($info)
      {
       
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');
        $title = mysqli_real_escape_string($this->con,$info['title']);
        $link = mysqli_real_escape_string($this->con,$info['link']);
         
        $url = mysqli_real_escape_string($this->con,str_replace($find,$replace,strtolower($title)));

         
        $description = mysqli_real_escape_string($this->con,$info['description']);
        $category = $info['category'];
        

         
          
         $image = "";

        if(@$_FILES['image']['name'] != '') 
            {
             
            @$image = rand() . '_' .str_replace($find,$replace,strtolower($_FILES["image"]["name"]));
            
            $path="../images/main_img/".$image;
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            

       
        $sql = $this->con->query("INSERT INTO tbl_slider(`title`,`description`,`link`,`image`,`add_date`) values ('".$title."','".$description."','".$link."','".$image."',now())");
        if($sql)
        {

        $id = mysqli_insert_id($this->con);
        $this->portal_log($id,"$title - Added");
        unset($_SESSION['error']);
        $_SESSION['msg']='Data Inserted Successfully';
        header('location:add-slider.php');

        }
        else
        {
        unset($_SESSION['msg']);  
        $_SESSION['error']='Something Went Wrong';
        header('location:add-slider.php');
        }

        
      }

       public function update_slider($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
        $link = mysqli_real_escape_string($this->con,$info['link']);
         
        
        
       
        $description = mysqli_real_escape_string($this->con,$info['description']);

         
           $image = "";


        if(@$_FILES['image']['name'] != '') 
            {
              
            @$image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["image"]["name"]));

            $path="../images/main_img/".$image;

            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }
            
          

            
          $query = "update tbl_slider set `title`='".$title."',`description`='".$description."',`link`='".$link."' ";
          
          
          if($image!='')
          {
            $query.=",`image`='".$image."' ";
          }
          

          $query.=",`update_date`=now() where `id`='".(int)$id."'";
         
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - Slider Updated");
            $_SESSION['total_data']='Data Updated Successfully';
            header('location:manage-slider.php');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
       
      }


         public function update_about($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
        //$author_name = mysqli_real_escape_string($this->con,$info['author_name']);
        
        $url = mysqli_real_escape_string($this->con,str_replace($find,$replace,strtolower($title)));
        $metakey = mysqli_real_escape_string($this->con,$info['metakey']);
        $metadesc = mysqli_real_escape_string($this->con,$info['metadesc']);
        $description = mysqli_real_escape_string($this->con,$info['description']);
            
           $image = "";


        if(@$_FILES['image']['name'] != '') 
            {
              
            @$image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["image"]["name"]));

            $path="../images/main_img/".$image;

            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            
          $query = "update tbl_about set `title`='".$title."',`url`='".$url."',`meta_keyword`='".$metakey."',`meta_description`='".$metadesc."',`description`='".$description."' ";
          
          if($image!='')
          {
            $query.=",`image`='".$image."' ";
          }

          $query.=",`mod_date`=now() where `id`='".(int)$id."'";
          
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - About Page Updated");
            unset($_SESSION['msg']);
            unset($_SESSION['error']);
            $_SESSION['msg']='Data Updated Successfully';
            header('location:update-about.php?edit=1');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
        
      }




       public function add_category($info)
      {
       
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');
        $title = mysqli_real_escape_string($this->con,$info['title']);
        $url = mysqli_real_escape_string($this->con,str_replace($find,$replace,strtolower($title)));
          $metakey = mysqli_real_escape_string($this->con,$info['metakey']);
        $metadesc = mysqli_real_escape_string($this->con,$info['metadesc']);
         
        $description = mysqli_real_escape_string($this->con,$info['description']);
          
        $exist_category = $this->con->query("select * from tbl_category where title='".$title."'");
        if($exist_category->num_rows>0)
        {
          unset($_SESSION['msg']);
          $_SESSION['error']='This Category is already exist';
            echo "<script>alert('This Category is already exist');</script>
            window.location.href='add-category.php';";
       
        }
        else
        {
         $image = "";

        if(@$_FILES['image']['name'] != '') 
            {
             
            @$image = rand() . '_' .str_replace($find,$replace,strtolower($_FILES["image"]["name"]));
            
            $path="../images/main_img/".$image;
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            

       
        $sql = $this->con->query("INSERT INTO tbl_category(`title`,`url`,`metakey`,`metadesc`,`description`,`image`,`add_date`) values ('".$title."','".$url."','".$metakey."','".$metadesc."','".$description."','".$image."',now())");
        if($sql)
        {

        $id = mysqli_insert_id($this->con);
        $this->portal_log($id,"$title - Added");
        unset($_SESSION['error']);
        $_SESSION['msg']='Data Inserted Successfully';
        header('location:add-category.php');

        }
        else
        {
        unset($_SESSION['msg']);  
        $_SESSION['error']='Something Went Wrong';
        header('location:add-category.php');
        }

        }
      }

       public function update_category($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
        $url = mysqli_real_escape_string($this->con,str_replace($find,$replace,strtolower($title)));
         
         $metakey = mysqli_real_escape_string($this->con,$info['metakey']);
        $metadesc = mysqli_real_escape_string($this->con,$info['metadesc']);
        
       
        $description = mysqli_real_escape_string($this->con,$info['description']);

 $exist_category = $this->con->query("select * from tbl_category where title='".$title."' and id!=$id");
        if($exist_category->num_rows>0)
        {
          echo "<script>alert('This Category Already Exist')</script>";
        }
        else

        {
         
           $image = "";


        if(@$_FILES['image']['name'] != '') 
            {
              
            @$image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["image"]["name"]));

            $path="../images/main_img/".$image;

            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }
            
          

            
          $query = "update tbl_category set `title`='".$title."',`metakey`='".$metakey."',`metadesc`='".$metadesc."',`description`='".$description."',`url`='".$url."' ";
          
          
          if($image!='')
          {
            $query.=",`image`='".$image."' ";
          }
          

          $query.=",`update_date`=now() where `id`='".(int)$id."'";
         
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - Category Updated");
            $_SESSION['total_data']='Data Updated Successfully';
            header('location:manage-category.php');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
       }
      }



       public function add_service($info)
      {
       
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');
        $title = mysqli_real_escape_string($this->con,$info['title']);

        
        $url = mysqli_real_escape_string($this->con,str_replace($find,$replace,strtolower($title)));
         $youtube_link = mysqli_real_escape_string($this->con,$info['youtube_link']);
        $metakey = mysqli_real_escape_string($this->con,$info['metakey']);
        $metadesc = mysqli_real_escape_string($this->con,$info['metadesc']);
        $age = mysqli_real_escape_string($this->con,$info['age']);
        $time = mysqli_real_escape_string($this->con,$info['time']);
        $capacity = mysqli_real_escape_string($this->con,$info['capacity']);
        $description = mysqli_real_escape_string($this->con,$info['description']);
          $category_id = $info['category_id'];

         $header_image = "";

        if(@$_FILES['header_image']['name'] != '') 
            {
             
            @$header_image = rand() . '_' .str_replace($find,$replace,strtolower($_FILES["header_image"]["name"]));
            
            $path="../images/main_img/".$header_image;
            move_uploaded_file($_FILES['header_image']['tmp_name'], $path);
            }
            
             $sub_page_image = "";

        if(@$_FILES['image']['name'] != '') 
            {
             
            @$sub_page_image = rand() . '_' .str_replace($find,$replace,strtolower($_FILES["image"]["name"]));
            
            $path="../images/main_img/".$sub_page_image;
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }
           // echo "INSERT INTO tbl_service(`category_id`,`title`,`url`,`youtube_link`,`meta_keyword`,`meta_description`,`description`,`image`,`header_image`,`add_date`) values ('".$category_id."','".$title."','".$url."','".$youtube_link."','".$metakey."','".$metadesc."','".$description."','".$sub_page_image."','".$header_image."',now())";die;
     $sql = $this->con->query("INSERT INTO tbl_service(`category_id`,`title`,`url`,`youtube_link`,`meta_keyword`,`meta_description`,`age`,`time`,`capacity`,`description`,`image`,`header_image`,`add_date`) values ('".$category_id."','".$title."','".$url."','".$youtube_link."','".$metakey."','".$metadesc."','".$age."','".$time."','".$capacity."','".$description."','".$sub_page_image."','".$header_image."',now())");
        if($sql)
        {

        
         $id = mysqli_insert_id($this->con);
           
        $this->portal_log($id,"$title - Added");
        unset($_SESSION['error']);
        $_SESSION['msg']='Data Inserted Successfully';
        header('location:add-service.php');

        }
        else
        {
        unset($_SESSION['msg']);  
        $_SESSION['error']='Something Went Wrong';
        header('location:add-service.php');
        }

         
      }

       public function update_service($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
        //$author_name = mysqli_real_escape_string($this->con,$info['author_name']);
        
        $url = mysqli_real_escape_string($this->con,str_replace($find,$replace,strtolower($title)));
        $metakey = mysqli_real_escape_string($this->con,$info['metakey']);
        $metadesc = mysqli_real_escape_string($this->con,$info['metadesc']);
        $age = mysqli_real_escape_string($this->con,$info['age']);
        $time = mysqli_real_escape_string($this->con,$info['time']);
        $capacity = mysqli_real_escape_string($this->con,$info['capacity']);
        $description = mysqli_real_escape_string($this->con,$info['description']);
        $youtube_link = mysqli_real_escape_string($this->con,$info['youtube_link']);
         $category_id = $info['category_id'];
        
            
              $header_image = "";


        if(@$_FILES['header_image']['name'] != '') 
            {
              
            @$header_image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["header_image"]["name"]));

            $path="../images/main_img/".$header_image;

            move_uploaded_file($_FILES['header_image']['tmp_name'], $path);
            }
            
           $sub_page_image = "";


        if(@$_FILES['image']['name'] != '') 
            {
              
            @$sub_page_image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["image"]["name"]));

            $path="../images/main_img/".$sub_page_image;

            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            
          $query = "update tbl_service set `category_id`='".$category_id."',`title`='".$title."',`url`='".$url."',`youtube_link`='".$youtube_link."',`meta_keyword`='".$metakey."',`meta_description`='".$metadesc."',`age`='".$age."',`time`='".$time."',`capacity`='".$capacity."',`description`='".$description."' ";
          
           if($header_image!='')
          {
            $query.=",`header_image`='".$header_image."' ";
          } 
          
          if($sub_page_image!='')
          {
            $query.=",`image`='".$sub_page_image."' ";
          }  
          $query.=",`update_date`=now() where `id`='".(int)$id."'";
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
         
            
            $this->portal_log($id,"$title - Updated");
            $_SESSION['total_data']='Data Updated Successfully';
            header('location:manage-service.php');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
         
      }





       public function add_gallery($info)
      {
       
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');
        $title = mysqli_real_escape_string($this->con,$info['title']);
         
          
         $image = "";

        if(@$_FILES['image']['name'] != '') 
            {
             
            @$image = rand() . '_' .str_replace($find,$replace,strtolower($_FILES["image"]["name"]));
            
            $path="../images/main_img/".$image;
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            

       
        $sql = $this->con->query("INSERT INTO tbl_gallery(`title`,`image`,`add_date`) values ('".$title."','".$image."',now())");
        if($sql)
        {

        $id = mysqli_insert_id($this->con);
        $this->portal_log($id,"$title - Image Added");
        unset($_SESSION['error']);
        $_SESSION['msg']='Data Inserted Successfully';
        header('location:add-gallery.php');

        }
        else
        {
        unset($_SESSION['msg']);  
        $_SESSION['error']='Something Went Wrong';
        header('location:add-gallery.php');
        }

        
      }

       public function update_gallery($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
         
         
           $image = "";


        if(@$_FILES['image']['name'] != '') 
            {
              
            @$image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["image"]["name"]));

            $path="../images/main_img/".$image;

            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }
            
          

            
          $query = "update tbl_gallery set `title`='".$title."' ";
          
          
          if($image!='')
          {
            $query.=",`image`='".$image."' ";
          }
          

          $query.=",`update_date`=now() where `id`='".(int)$id."'";
         
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - Image Updated");
            $_SESSION['total_data']='Data Updated Successfully';
            header('location:manage-gallery.php');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
       
      }



      public function add_video($info)
      {
       
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');
        $title = mysqli_real_escape_string($this->con,$info['title']);
         $video_url = mysqli_real_escape_string($this->con,$info['video_url']);
          //echo "INSERT INTO tbl_video(`title`,`video_url`,`add_date`) values ('".$title."','".$video_url."',now())"; die;
        $sql = $this->con->query("INSERT INTO tbl_video(`title`,`video_url`,`add_date`) values ('".$title."','".$video_url."',now())");
        if($sql)
        {

        $id = mysqli_insert_id($this->con);
        $this->portal_log($id,"$title - Video Added");
        unset($_SESSION['error']);
        $_SESSION['msg']='Data Inserted Successfully';
        header('location:add-video.php');

        }
        else
        {
        unset($_SESSION['msg']);  
        $_SESSION['error']='Something Went Wrong';
        header('location:add-video.php');
        }

        
      }

       public function update_video($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
         
        $video_url = mysqli_real_escape_string($this->con,$info['video_url']);
          
        $query = "update tbl_video set `title`='".$title."',`video_url`='".$video_url."' ";
            $query.=",`update_date`=now() where `id`='".(int)$id."'";
         
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - Image Updated");
            $_SESSION['total_data']='Data Updated Successfully';
            header('location:manage-video.php');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
       
      }




       public function add_testimonial($info)
      {
       
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');
        $title = mysqli_real_escape_string($this->con,$info['title']);
         
        $description = mysqli_real_escape_string($this->con,$info['description']);
          
        
         $image = "";

        if(@$_FILES['image']['name'] != '') 
            {
             
            @$image = rand() . '_' .str_replace($find,$replace,strtolower($_FILES["image"]["name"]));
            
            $path="../images/main_img/".$image;
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            

       
        $sql = $this->con->query("INSERT INTO tbl_testimonial(`title`,`description`,`image`,`add_date`) values ('".$title."','".$description."','".$image."',now())");
        if($sql)
        {

        $id = mysqli_insert_id($this->con);
        $this->portal_log($id,"$title - Added");
        unset($_SESSION['error']);
        $_SESSION['msg']='Data Inserted Successfully';
        header('location:add-testimonial.php');

        }
        else
        {
        unset($_SESSION['msg']);  
        $_SESSION['error']='Something Went Wrong';
        header('location:add-testimonial.php');
        }

        
      }

       public function update_testimonial($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
         
        $description = mysqli_real_escape_string($this->con,$info['description']);
 
           $image = "";


        if(@$_FILES['image']['name'] != '') 
            {
              
            @$image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["image"]["name"]));

            $path="../images/main_img/".$image;

            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }
            
          

            
          $query = "update tbl_testimonial set `title`='".$title."',`description`='".$description."' ";
          
          
          if($image!='')
          {
            $query.=",`image`='".$image."' ";
          }
          

          $query.=",`update_date`=now() where `id`='".(int)$id."'";
         
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - testimonial Updated");
            $_SESSION['total_data']='Data Updated Successfully';
            header('location:manage-testimonial.php');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
       
      }



       public function add_blog($info)
      {
       
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');
        $title = mysqli_real_escape_string($this->con,$info['title']);
        $url = mysqli_real_escape_string($this->con,str_replace($find,$replace,strtolower($title)));
          $metakey = mysqli_real_escape_string($this->con,$info['metakey']);
        $metadesc = mysqli_real_escape_string($this->con,$info['metadesc']);
         
        $description = mysqli_real_escape_string($this->con,$info['description']);
          
        $exist_blog = $this->con->query("select * from tbl_blog where title='".$title."'");
        if($exist_blog->num_rows>0)
        {
          unset($_SESSION['msg']);
          $_SESSION['error']='This blog is already exist';
            echo "<script>alert('This blog is already exist');</script>
            window.location.href='add-blog.php';";
       
        }
        else
        {
         $image = "";

        if(@$_FILES['image']['name'] != '') 
            {
             
            @$image = rand() . '_' .str_replace($find,$replace,strtolower($_FILES["image"]["name"]));
            
            $path="../images/main_img/".$image;
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            

       
        $sql = $this->con->query("INSERT INTO tbl_blog(`title`,`url`,`metakey`,`metadesc`,`description`,`image`,`add_date`) values ('".$title."','".$url."','".$metakey."','".$metadesc."','".$description."','".$image."',now())");
        if($sql)
        {

        $id = mysqli_insert_id($this->con);
        $this->portal_log($id,"$title - Added");
        unset($_SESSION['error']);
        $_SESSION['msg']='Data Inserted Successfully';
        header('location:add-blog.php');

        }
        else
        {
        unset($_SESSION['msg']);  
        $_SESSION['error']='Something Went Wrong';
        header('location:add-blog.php');
        }

        }
      }

       public function update_blog($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
        $url = mysqli_real_escape_string($this->con,str_replace($find,$replace,strtolower($title)));
         
         $metakey = mysqli_real_escape_string($this->con,$info['metakey']);
        $metadesc = mysqli_real_escape_string($this->con,$info['metadesc']);
        
       
        $description = mysqli_real_escape_string($this->con,$info['description']);

 $exist_blog = $this->con->query("select * from tbl_blog where title='".$title."' and id!=$id");
        if($exist_blog->num_rows>0)
        {
          echo "<script>alert('This blog Already Exist')</script>";
        }
        else

        {
         
           $image = "";


        if(@$_FILES['image']['name'] != '') 
            {
              
            @$image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["image"]["name"]));

            $path="../images/main_img/".$image;

            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }
            
          

            
          $query = "update tbl_blog set `title`='".$title."',`metakey`='".$metakey."',`metadesc`='".$metadesc."',`description`='".$description."',`url`='".$url."' ";
          
          
          if($image!='')
          {
            $query.=",`image`='".$image."' ";
          }
          

          $query.=",`update_date`=now() where `id`='".(int)$id."'";
         
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - blog Updated");
            $_SESSION['total_data']='Data Updated Successfully';
            header('location:manage-blog.php');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
       }
    }




     public function add_partner($info)
      {
       
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');
        $title = mysqli_real_escape_string($this->con,$info['title']);
        $designation = mysqli_real_escape_string($this->con,$info['designation']);
         
          
         $image = "";

        if(@$_FILES['image']['name'] != '') 
            {
             
            @$image = rand() . '_' .str_replace($find,$replace,strtolower($_FILES["image"]["name"]));
            
            $path="../images/main_img/".$image;
            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }

            

       
        $sql = $this->con->query("INSERT INTO tbl_partner(`title`,`designation`,`image`,`add_date`) values ('".$title."','".$designation."','".$image."',now())");
        if($sql)
        {

        $id = mysqli_insert_id($this->con);
        $this->portal_log($id,"$title - Image Added");
        unset($_SESSION['error']);
        $_SESSION['msg']='Data Inserted Successfully';
        header('location:add-partner.php');

        }
        else
        {
        unset($_SESSION['msg']);  
        $_SESSION['error']='Something Went Wrong';
        header('location:add-partner.php');
        }

        
      }

       public function update_partner($info,$id)
      {
        $find = array(' ','+',',','_','@','#','$','%','^','&','*','(',')','{','}','[',']',':',';','/');
        $replace = array('-','-','-','-','-','-','-','-','-','and','-','-','-','-','-','-','-','-','-','-');

        $title = mysqli_real_escape_string($this->con,$info['title']);
        $designation = mysqli_real_escape_string($this->con,$info['designation']);
         
         
           $image = "";


        if(@$_FILES['image']['name'] != '') 
            {
              
            @$image = rand() .'_'.str_replace($find,$replace,strtolower($_FILES["image"]["name"]));

            $path="../images/main_img/".$image;

            move_uploaded_file($_FILES['image']['tmp_name'], $path);
            }
            
          

            
          $query = "update tbl_partner set `title`='".$title."',`designation`='".$designation."' ";
          
          
          if($image!='')
          {
            $query.=",`image`='".$image."' ";
          }
          

          $query.=",`update_date`=now() where `id`='".(int)$id."'";
         
          
          $sql = $this->con->query($query);
          if($sql>0)
          {
            $this->portal_log($id,"$title - Image Updated");
            $_SESSION['total_data']='Data Updated Successfully';
            header('location:manage-partner.php');
          }
          else
          {
            $_SESSIONP['error']='Data Not Updated';
          }
       
      }

      

     public function delete_product_image($sql,$product_id)
      {
        $sql = $this->con->query($sql);
        if($sql>0)
        {
           

          $_SESSION['total_data']=$total_row.' Images Removed Successfully';
           unset($_SESSION['error']);
         $_SESSION['msg']='Image Delete Success';
      header('location:add-service.php?edit='.$product_id);

        }
        
         else {
      unset($_SESSION['msg']);
          $_SESSION['error']='This Image Not Delete';
        header('location:add-service.php?edit=$product_id');
  }
  
      }
 
 
 
      
        public function manage_query($info)
      {
          

     $baseurl = $this->baseurl;
     
        $f_name = mysqli_real_escape_string($this->con,$info['name']);
       
        $email = mysqli_real_escape_string($this->con,$info['email']);
        $mobile = mysqli_real_escape_string($this->con,$info['mobile']);
        $class = mysqli_real_escape_string($this->con,$info['class']);
        $description = mysqli_real_escape_string($this->con,$info['message']);
         

       // echo "INSERT INTO tbl_enquiry(`name`,`email`,`mobile`,`class`,`message`,`add_date`) values ('".$f_name."','".$email."','".$mobile."','".$class."','".$description."',now())"; die;

      $sql = $this->con->query("INSERT INTO tbl_enquiry(`name`,`email`,`mobile`,`class`,`message`,`add_date`) values ('".$f_name."','".$email."','".$mobile."','".$class."','".$description."',now())");
        if($sql)
        {

        $id = mysqli_insert_id($this->con);
        $this->portal_log($id,"$title - Enquiry Insterted");
          echo "<script>window.location.href='$baseurl';
          alert('Enquiry Send Successfully. We Will Contact You Soon')</script>";

        }
        else
        {
        echo "<script>window.location.href='$baseurl/contact';
          alert('Enquiry Not Send, Plz Try Again')</script>"; 
      
        }
      } 

    
      

}


   
?>