<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
/**
	 * 
	 */
	class Add_order_model extends CI_Model
	{
		
		function __construct()
		{
			parent::__construct();
		}

//        function db_insert() {
//		    $smt = 0;
//		    $total = 0;
//            $to_email = "buypakistan.com.pk@gmail.com";
//            $from_email = $_POST['email'];;
//                $name = $_POST['fullname'];
//                $slug = $_POST['product_slug'];
//                $query = $this->db->where('slug', $slug);
//                $query = $this->db->get('product');
//                if($query->num_rows() > 0){
//                    $data = $query->row();
//                    $pname = $data->name;
//                    $price = $data->price;
//                    $fee = $data->dliveryfee;
//                    $qnt = $_POST['qnt'];
//                    $smt = $price * $qnt;
//                    $total = $smt + $fee;
//                    $fullname = $_POST['fullname'];
//			$phone = $_POST['phone'];
//			$email = $_POST['email'];
//			$phone2 = $_POST['phone2'];
//			$country = $_POST['country'];
//			$city = $_POST['city'];
//			$address = $_POST['address'];
//                    $htmlContent = '<h1>BUYPAKISTAN.COM.PK Orders Email </h1>';
//                    $htmlContent .= '<h3>BUYPAKISTAN.COM.PK Recive New Order .</h3>';
//                    $htmlContent .= '<h3>Order Information .</h3>';
//                    $htmlContent .= '<p>Product Name: '.$pname.'  .</p>';
//                    $htmlContent .= '<p>Product Price:RS '.$price.'  .</p>';
//                    $htmlContent .= '<p>Product Quantity: '.$qnt.'  .</p>';
//                    $htmlContent .= '<p>Product Delivery Fees:RS '.$fee.'  .</p>';
//                    $htmlContent .= '<p>Total Bill: '.$total.'  .</p>';
//                    $htmlContent .= '<h3>Customer Information .</h3>';
//                    $htmlContent .= '<p>Customer Name: '.$fullname.'  .</p>';
//                    $htmlContent .= '<p>Customer Phone: '.$phone.'  .</p>';
//                    $htmlContent .= '<p>Customer email: '.$email.'  .</p>';
//                    $htmlContent .= '<p>Customer phone2: '.$phone2.'  .</p>';
//                    $htmlContent .= '<p>Customer Country: '.$country.'  .</p>';
//                    $htmlContent .= '<p>Customer City: '.$city.'  .</p>';
//                    $htmlContent .= '<p>Customer Street Address: '.$address.'  .</p>';
//
//                    $this->load->library('email');
//                    $config['mailtype'] = 'html';
//                    $this->email->initialize($config);
//                    $this->email->from($from_email, $name);
//                    $this->email->to($to_email);
//                    $this->email->subject($pname);
//                    $this->email->message($htmlContent);
//
//
//                    if($this->email->send()){
//                        return 1;
//                    }else {
//                        return 2;
//                    }
//                }
//
//		}


		function db_insert()
		{
			$product_slug = $_POST['product_slug'];
			$fullname = $_POST['fullname'];
			$phone = $_POST['phone'];
			$email = $_POST['email'];
			$city = $_POST['city'];
			$address = $_POST['address'];
			$qnt = $_POST['qnt'];

			if($product_slug == '' || $fullname == '' || $phone == '' || $email == '' || $city == '' || $address == '' || $qnt == '' || $qnt == '0'){
			    return 4;
            }
					$data =  array(
						'product_slug' =>$product_slug,
						'fullname' =>$fullname,
						'phone' =>$phone,
						'email' =>$email,
						'city' =>$city,
						'address' =>$address,
						'qnt' =>$qnt
					);

					$q = $this->db->insert('orders', $data);
					if($q){
						return 1;
					}else{
						return 2;
					}


		}


// REVIEW CODEX GOSE CRAZY
// REVIEW CODEX GOSE CRAZY
		function db_insert_review()
		{
			$product_slug = $_POST['product_slug'];
			$fullname = $_POST['name'];
			$email = $_POST['email'];
			$review = $_POST['review'];
			$stars = $_POST['stars'];
			
					$data =  array(
						'product_slug' =>$product_slug,
						'name' =>$fullname,
						'email' =>$email,
						'stars' =>$stars,
						'review' =>$review
					);

					$q = $this->db->insert('reviews', $data);
					if($q){
						return 1;
					}else{
						return 2;
					}

				
		}

		
		function get_all_review(){
			$q = $this->db->where('status', 0);
			$q = $this->db->get('reviews');
			if($q->num_rows() > 0){
				// return $q->num_rows();
				return $q->result();
			}else{
				return 0;
			}
		}

		function markx($id)
			{
				$st = 1;
				$arr = array(
						'status'=>$st
				);
				$data = $this->db->where('id', $id);
				$data = $this->db->update('reviews', $arr);
				if($data){
						return 1;
					}else{
						return 0;
					}
			}

			function deletex($id)
				{
					$data = $this->db->where('id', $id);
					$data = $this->db->delete('reviews');
					if($data){
						return 1;
					}else{
						return 0;
					}
				}

				function delete_old_X($id)
				{
					$data = $this->db->where('id', $id);
					$data = $this->db->delete('reviews');
					if($data){
						return 1;
					}else{
						return 0;
					}
				}

				function get_all_oldx(){
			$q = $this->db->where('status', 1);
			$q = $this->db->order_by('id', 'desc');
			$q = $this->db->get('reviews');
			if($q->num_rows() > 0){
				// return $q->num_rows();
				return $q->result();
			}else{
				return 0;
			}
		}



// REVIEW CODEX GOSE CRAZY
// REVIEW CODEX GOSE CRAZY




		function get_all(){
			$q = $this->db->where('status', 0);
            $q = $this->db->order_by('date', 'desc');
			$q = $this->db->get('orders');
			if($q->num_rows() > 0){
				// return $q->num_rows();
				return $q->result();
			}else{
				return 0;
			}
		}

		function get_all_old(){
			$q = $this->db->where('status', 1);
            $q = $this->db->order_by('id', 'desc');
			$q = $this->db->get('orders');
			if($q->num_rows() > 0){
				// return $q->num_rows();
				return $q->result();
			}else{
				return 0;
			}
		}

			function select($id)
			{
				$st = 1;
				$arr = array(
						'status'=>$st
				);
				$data = $this->db->where('id', $id);
				$data = $this->db->update('orders', $arr);
				if($data){
						return 1;
					}else{
						return 0;
					}
			}

			

				function delete($id)
				{
					$data = $this->db->where('id', $id);
					$data = $this->db->delete('orders');
					if($data){
						return 1;
					}else{
						return 0;
					}
				}


	}	

?>