<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Order_process extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->model(array('admin_model','Db_model'));
		
		$this->load->library(array('user_loginfunctions','encrypt'));
		
		$this->load->helper('basic_helper');
		
		//if logged out, redirect to login page
		if($this->user_loginfunctions->checkloggedin()===FALSE)
		{
			redirect('User/login') ;
		}

		
	}
	
	public function index()
	{
		$this->cancel();
	}
	
	public function cancel()
	{
		//$admin_mail = 'rahul@annvision.com';
		
		$admin_mail = 'pookkaniflowers@gmail.com';
		
		$user_mail = '';
		
		$order_id = $this->encrypt->decode($this->input->post('orid')); 
		
		$this->Db_model->update('shop_shipdetails',array('status'=>'C'),array('order_id'=>$order_id));
		
		$user_id = $this->encrypt->decode($this->input->post('uid'));
		
		$user_det = $this->Db_model->get_one('shop_checkoutusers',array('id'=>$user_id)) ;
																	   
		if( $user_det!==FALSE)
		{
			$user_mail = $user_det->email; 
		}
		

		// send cancel mail to user and admin
		
		$this->load->library('email');
		
		$config['charset'] = 'iso-8859-1';
		$config['mailtype'] = 'html';
		$config['wordwrap'] = TRUE;
		
		$this->email->initialize($config);

		$this->email->from($user_mail, 'Pookkani');
		
		$this->email->to($admin_mail);
		
		$this->email->subject('Order Cancellation');
		
		//mail to admin
		
		$msg='<div style="width:95%; padding:10px ; background-color:#E0E0E0;">
					
					<table width="100%"  border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#FBFBFB" 
					style="padding:20px;font-family:Arial, Helvetica, sans-serif; color:#2C2C2C; font-size:13px;">
					
					<tr><td colspan="2"><font style="font-size:18px;">Order Cancellation</font></td></tr>
					<tr height="20"><td colspan="2"></td></tr>
					<tr><td width="30%" height="30">
					
					<p>Dear Admin,</p>
					<p>An order has been cancelled.</p>
					<p>Details are given below : </p>
					<p>&nbsp;</p>
					<p>Order ID: <b>'.$order_id.'</b> </p>
					<p>Customer Email : '.$user_mail.' </p>
					<p>&nbsp;</p>
					<p>
					Thank You,<br /><br />
					Team
					</p>
					
					</td></tr>
					
					<tr height="40"></tr>
					
					<tr><td colspan="2">
				
					<div style="font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#575757;">
					<p>This is a system generated message, Please do not reply to this email.</p>
					</div>
					
					</td></tr>
					</table>
					
					</div>    
					';
					
					
		$this->email->message($msg);
		

		
		if($this->email->send())
		{
			//echo 'Mail sent to admin';
		}
		else
		{
			//echo 'Mail not sent  admin';
		}
		
		
		
	
		
		
		
		/*$this->email->from('auto_confirm@maxxmagic.com', 'Maxxmagic');
		
		$this->email->to($user_mail);
		
		$this->email->subject('Order Cancellation');
		
		//mail to user
		
		$msg='<div style="width:95%; padding:10px ; background-color:#E0E0E0;">
					
					<table width="100%"  border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#FBFBFB" 
					style="padding:20px;font-family:Arial, Helvetica, sans-serif; color:#2C2C2C; font-size:13px;">
					
					<tr><td colspan="2"><font style="font-size:18px;">Order Cancellation</font></td></tr>
					<tr height="20"><td colspan="2"></td></tr>
					<tr><td width="30%" height="30">
					
					<p>Dear Customer,</p>
					<p>You have cancelled an order.</p>
					<p>Details are given below : </p>
					<p>&nbsp;</p>
					<p>Order ID: <b>'.$order_id.'</b> </p>
					<p>&nbsp;</p>
					<p>
					Thank You,<br /><br />
					Team
					</p>
					
					</td></tr>
					
					<tr height="40"></tr>
					
					<tr><td colspan="2">

					<div style="font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#575757;">
					<p>This is a system generated message, Please do not reply to this email.</p>
					</div>
					
					</td></tr>
					</table>
					
					</div>    
					';*/
					
					
		//$this->email->message($msg);
		
				
		/*if($this->email->send())
		{
			//echo 'Mail sent to user';
		}
		else
		{
			//echo 'Mail not sent  user';
		}*/
		
		
		redirect('Userpage/vieworders');
	}
	
	public function book()
	{
		
		$order_id = $this->encrypt->decode($this->input->post('orid'));
		
		$this->Db_model->update('shop_shipdetails',array('status'=>'P'),array('order_id'=>$order_id));
				
		redirect('Userpage/vieworders');
	}
}
