ok

Mini Shell

Direktori : /home/gainstransformin/public_html/Gains_admin/application/models/
Upload File :
Current File : /home/gainstransformin/public_html/Gains_admin/application/models/Main_model.php

<?php

class Main_model extends CI_Model{
	//insert data

//******************************************************************************	
	 function web_enq_list()
    {
         $result =$this->db->query("SELECT `web_inq_id`, `inq_person_name`, `inq_per_mob_no`, `inq_per_email`, `inq_per_img`, `inq_per_msg`, 
                                           `inq_date_time`, `web_per_type`, `inq_per_is_delete` 
                                           FROM `tbl_web_inquiry`
                                           WHERE inq_per_is_delete=0 ORDER BY web_inq_id DESC
                                            ");

		return $result->result();
    }
	 function get_user_list()
    {
         $result =$this->db->query("SELECT * FROM `tbl_user_registration` 
                                             WHERE 1 ORDER BY user_id DESC
                                            ");

		return $result->result();
    }
	 
	function delete_user($id)
	{
		$this->db->where('user_id',$id);
		
		if($this->db->delete('tbl_user_registration'))
		{
			return true;
		}else{
			return false;
		}
	}
	 
    function get_category_list()
    {
         $result =$this->db->query("SELECT * FROM `tbl_category` 
                                             WHERE 1 ORDER BY cate_id DESC
                                            ");

		return $result->result();
		
	
        
    }

	 
	 function get_category_by_id($id)
    {
         $result =$this->db->query("SELECT * FROM `tbl_category` 
                                             WHERE cate_id='".$id."'
                                            ");

		return $result->result();
    }
//******************************************************************************
function verify($id)
	{
	     $result =$this->db->query("SELECT * FROM `tbl_user_registration` 
                                             WHERE user_id='".$id."'
                                            ");

		$resu=$result->result_array();
		foreach($resu as $data)
		{
		    $status=$data['admin_status'];
		}
		if($status==1)
		{
		    $data=['admin_status'=>0];
		}
		else
		{
		   $data=['admin_status'=>1];
		}
		$this->db->where('user_id',$id);

		if($this->db->update('tbl_user_registration',$data))
		{
			return true;
		}else{
			return false;
		}
	}
 
 function delete_category($id)
	{
		$this->db->where('cate_id',$id);
		
		if($this->db->delete('tbl_category'))
		{
			return true;
		}else{
			return false;
		}
	}
	
	function update_category($id)
	{
	    $this->db->where('cate_id',$id);
	    $fileName = $_FILES['img']['name'];
    if ($fileName != "") {

        $fileName = rand().$_FILES['img']['name'];
        $fileTmpLoc = $_FILES['img']['tmp_name'];
        $pathAndName = "uploads/".$fileName;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
    } else
    {
         $fileName = "";
    }
	
    if ($fileName != "") {
		
	$data=[ 
	        'category_name'=>$this->input->post('category_name'),
	        'comp_name'=>$this->input->post('comp_name'),
	        'category_img'=>$fileName];
	
    }
    else
    {
        $data=[
            'category_name'=>$this->input->post('category_name'),
            'comp_name'=>$this->input->post('comp_name')
            ];
    }
		
		if($this->db->update('tbl_category',$data))
		{
			return true;
		}else{
			return false;
		}
	}
 
	function save_category()
	{
	    
	    $fileName = $_FILES['img']['name'];
    if ($fileName != "") {

        $fileName = rand().$_FILES['img']['name'];
        $fileTmpLoc = $_FILES['img']['tmp_name'];
        $pathAndName = "uploads/".$fileName;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
    } else {
         $fileName = "";
    }
	
   
		
	$data=[
	        'category_name'=>$this->input->post('category_name'),
	        'comp_name'=>$this->input->post('comp_name'),
	        'category_img'=>$fileName];
	
		if($this->db->insert('tbl_category',$data))
		{ 
		    ?><script>alert('Category Save Successfully!');</script><?php
			return true;
		}else{
			return false;
		}
	}
 
 
 	function save_crop_schedule()
	{
	    
	    $fileName = $_FILES['crop_image']['name'];
    if ($fileName != "") {

        $fileName = rand().$_FILES['crop_image']['name'];
        $fileTmpLoc = $_FILES['crop_image']['tmp_name'];
        $pathAndName = "uploads/".$fileName;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
    } else {
         $fileName = "";
    }
	
   	    $fileName1 = $_FILES['crop_schedule_image']['name'];
    if ($fileName1 != "") {

        $fileName1 = rand().$_FILES['crop_schedule_image']['name'];
        $fileTmpLoc = $_FILES['crop_schedule_image']['tmp_name'];
        $pathAndName1 = "uploads/".$fileName1;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName1);
    } else {
         $fileName1 = "";
    }
	
		
	$data=[
	        'crop_name'=>$this->input->post('crop_name'),
	        'fk_comp_id'=>$this->input->post('fk_comp_id'),
	        'crop_schedule_image'=>$fileName1,
	        'crop_image'=>$fileName
	        ];
	
		if($this->db->insert('tbl_crop_schedule',$data))
		{ 
		    ?><script>alert('Crop Schedule Save Successfully!');</script><?php
			return true;
		}else{
			return false;
		}
	}
	function crop_schedule_list()
    {
         $result =$this->db->query("SELECT `crop_sch_id`, `crop_name`, fk_comp_id,`crop_image`, `crop_schedule_image`, `crop_is_delete`
                                     FROM `tbl_crop_schedule`
                                     WHERE crop_is_delete=0
                                            ");
		return $result->result();
    }
    
    
    
    function get_crop_schedule_by_id($id)
    {
         $result =$this->db->query("SELECT * FROM `tbl_crop_schedule` 
                                             WHERE crop_sch_id='".$id."'
                                            ");

		return $result->result();
    }
    
    
    
    
  function update_crop_schedule($id)
{
    $this->db->where('crop_sch_id', $id);

    $fileNameCrop = "";
    $fileNameSchedule = "";

    if (!empty($_FILES['crop_image']['name'])) {
        $fileNameCrop = rand() . $_FILES['crop_image']['name'];
        $fileTmpLoc = $_FILES['crop_image']['tmp_name'];
        $pathAndName = "uploads/" . $fileNameCrop;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
        if (!$moveResult) {
            return false; // Handle file upload error
        }
    }

    if (!empty($_FILES['crop_schedule_image']['name'])) {
        $fileNameSchedule = rand() . $_FILES['crop_schedule_image']['name'];
        $fileTmpLoc = $_FILES['crop_schedule_image']['tmp_name'];
        $pathAndName = "uploads/" . $fileNameSchedule;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
        if (!$moveResult) {
            return false; // Handle file upload error
        }
    }

    $data = [
        'crop_name' => $this->input->post('crop_name'),
        'fk_comp_id' => $this->input->post('fk_comp_id'),
    ];

    if (!empty($fileNameCrop)) {
        $data['crop_image'] = $fileNameCrop;
    }

    if (!empty($fileNameSchedule)) {
        $data['crop_schedule_image'] = $fileNameSchedule;
    }

    if ($this->db->update('tbl_crop_schedule', $data)) {
        return true;
    } else {
        return false;
    }
}


 function delete_crop_schedule($id)
	{
		$this->db->where('crop_sch_id',$id);
		$data=[
		    'crop_is_delete'=>1
		    ];
		if($this->db->update('tbl_crop_schedule',$data))
		{
			return true;
		
		}else{
			return false;
		}
	}
	
	
	



//*****************************************************************************
 function get_product_list()
    {
         $result =$this->db->query("SELECT * FROM `tbl_product` A, `tbl_category` B
                                             WHERE A.fk_category_id=B.cate_id 
                                             ORDER BY A.product_id DESC
                                            ");

		return $result->result();
    }
   function get_product_list_by()
    {
        $fk_category_id=$this->input->post('fk_category_id');
        if($fk_category_id=='All')
        {
            $result =$this->db->query("SELECT * FROM `tbl_product` A, `tbl_category` B
                                             WHERE A.fk_category_id=B.cate_id 
                                             ORDER BY A.product_id DESC
                                            ");
        }
        else
        {
         $result =$this->db->query("SELECT * FROM `tbl_product` A, `tbl_category` B
                                             WHERE A.fk_category_id=B.cate_id 
                                             AND A.fk_category_id='".$fk_category_id."'
                                             ORDER BY A.product_id DESC
                                            ");
        }
		return $result->result();
    } 
    function delete_product($id)
	{
		$this->db->where('product_id',$id);
		
		if($this->db->delete('tbl_product'))
		{
			return true;
		}else{
			return false;
		}
	}
	
	function get_product_by_id($id)
    {
         $result =$this->db->query("SELECT * FROM  `tbl_product` A, `tbl_category` B
                                             WHERE A.product_id='".$id."'
                                             AND  A.fk_category_id=B.cate_id 
                                            ");

		return $result->result();
    }
    
	function save_product()
	{
	    
	    $fileName1 = $_FILES['img1']['name'];
    if ($fileName1 != "") {

        $fileName1 = rand().$_FILES['img1']['name'];
        $fileTmpLoc = $_FILES['img1']['tmp_name'];
        $pathAndName = "uploads/".$fileName1;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
    } else {
         $fileName1 = "";
    }
    
    $fileName2 = $_FILES['img2']['name'];
    if ($fileName2 != "") {

        $fileName2 = rand().$_FILES['img2']['name'];
        $fileTmpLoc = $_FILES['img2']['tmp_name'];
        $pathAndName2 = "uploads/".$fileName2;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName2);
    } else {
         $fileName2 = "";
    }
     $fileName3 = $_FILES['img2']['name'];
    if ($fileName3 != "") {

        $fileName3 = rand().$_FILES['img3']['name'];
        $fileTmpLoc = $_FILES['img3']['tmp_name'];
        $pathAndName3 = "uploads/".$fileName3;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName3);
    } else {
         $fileName3 = "";
    }
     $fileName4 = $_FILES['img4']['name'];
    if ($fileName4 != "") {

        $fileName4 = rand().$_FILES['img4']['name'];
        $fileTmpLoc = $_FILES['img4']['tmp_name'];
        $pathAndName4 = "uploads/".$fileName4;
        $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName4);
    } else {
         $fileName4 = "";
    }
	
	$tdate=date('Y-m-d');	
	$data=[
	        'fk_category_id'=>$this->input->post('fk_category_id'),
	        'product_name'=>$this->input->post('product_name'),
	        'product_discription'=>$this->input->post('product_discription'),
	        'img1'=>$fileName1 ,
	        'pro_contain'=>$this->input->post('pro_contain'),
	        'pro_direction_to_use'=>$this->input->post('pro_direction_to_use'),
	        'img2'=>$fileName2,
	        'img3'=>$fileName3,
	        'img4'=>$fileName4
	        ];
		if($this->db->insert('tbl_product',$data))
		{ 
		    ?><script>alert('Product Save Successfully!');</script><?php
			return true;
		}else{
			return false;
		}
	}
	
	
		function update_product($id)
{
    $this->db->where('product_id', $id);
    
    $uploaded_files = [];
    $upload_dir = "uploads/";

    for ($i = 1; $i <= 4; $i++) {
        $file_input_name = 'img' . $i;
        $file_name = $_FILES[$file_input_name]['name'];

        if (!empty($file_name)) {
            $file_name = rand() . $file_name;
            $file_tmp_loc = $_FILES[$file_input_name]['tmp_name'];
            $path_and_name = $upload_dir . $file_name;
            $move_result = move_uploaded_file($file_tmp_loc, $path_and_name);
            if ($move_result) {
                $uploaded_files[$file_input_name] = $file_name;
            }
        } else {
            $uploaded_files[$file_input_name] = "";
        }
    }

    $tdate = date('Y-m-d');
    
    $data = [
        'fk_category_id' => $this->input->post('fk_category_id'),
        'product_name' => $this->input->post('product_name'),
        'product_discription' => $this->input->post('product_discription'),
        'pro_contain' => $this->input->post('pro_contain'),
        'pro_direction_to_use' => $this->input->post('pro_direction_to_use')
    ];

    // Add uploaded files to $data array conditionally
    foreach ($uploaded_files as $key => $value) {
        if (!empty($value)) {
            $data[$key] = $value;
        }
    }

    if ($this->db->update('tbl_product', $data)) {
        return true;
    } else {
        return false;
    }
}

	
	function get_inquiry_list()
	{
	    $result =$this->db->query("SELECT * FROM `tbl_web_inquiry` WHERE  1 ORDER BY inquiry_id DESC");
	   // inquiry_id=$id
	    
	    
	    	return $result->result();
	}
	
	
	
	
	
	



//******************************************************************************
}
?>

Zerion Mini Shell 1.0