<?php



/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/



// +----------------------------------------------------------------------+



// | PHP version 4/5                                                      |



// +----------------------------------------------------------------------+



// | Copyright (c) 2004-2010 ARMIA INC                                    |



// +----------------------------------------------------------------------+



// | This source file is a part of iScripts VistaCart                     |



// +----------------------------------------------------------------------+



// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |



// +----------------------------------------------------------------------+



class RefundsController extends AppController



{



    var $name = "Refunds";



    var $helpers = array('Html', 'Form','Pagination');   



	var $components = array ('Catmenu','Pagination'); // Added



	var $uses = array('Refund','Refundreason','Refundoption','Refundstatus','Order','Product','Category','Productdetail','Currency','UserAddress','OrderStatus','OrderDetail','User','Cart','Cmspage','Coupon','Refundproducts','Giftcard'); 



	var $paginate = array('limit' => 25,'order' => array('Refund.date' => 'desc'));



	function index()



    {



        $this->__validateLoginStatus();

$cnfg 				=	Configure::read('Neutrino');
        $style				=	$cnfg["style"];
        $this->set('style', "admin/".$style);

		$admsess	=	$this->Session->read('Admin');



		if($admsess["refund"] <> 1){



		 	$this->redirect(array('controller' => 'admins', 'action' => 'index')); 



			exit();



		}



		$cmbSearchType	=	"";

		$txtSearch		=	"";

		if(isset($_GET["cmbSearchType"]) && isset($_GET["txtSearch"]) && $_GET["txtSearch"] <> ''){

					$cmbSearchType	=	$_GET["cmbSearchType"];

					$txtSearch		=	$_GET["txtSearch"];

					if($cmbSearchType == "oid"){

						$data = $this->paginate('Refund', array('Refund.id  = ' => addslashes($txtSearch)));

					}elseif($cmbSearchType == "orderstatus"){

						$data = $this->paginate('Refund', array('Refund.status LIKE ' => "%".addslashes($txtSearch)."%"));

					}elseif($cmbSearchType == "username"){

						$data = $this->paginate('Refund', array('User.uname LIKE ' => "%".addslashes($txtSearch)."%"));

					}elseif($cmbSearchType == "dateoforder"){

						$split_date=explode('-',$txtSearch);

						if(isset($split_date[0]) && isset($split_date[1]) &&  isset($split_date[2]))

						$srch_date=trim($split_date[2]).'-'.trim($split_date[0]).'-'.trim($split_date[1]);

						else

						$srch_date='00-00-1000';						

						$data = $this->paginate('Refund', array('Refund.date LIKE ' => "%".addslashes($srch_date)."%"));

		

					}elseif($cmbSearchType == "ordernumber"){

						$data = $this->paginate('Refund', array('Refund.order_id =' => addslashes($txtSearch)));

					}else{

						$data = $this->paginate('Refund');

					}

		}

		else if(isset($this->passedArgs["cmbSearchType"]) && isset($this->passedArgs["txtSearch"]) && 

		 $this->passedArgs["txtSearch"] <> '')

		{

		             $cmbSearchType	=	$this->passedArgs["cmbSearchType"];

			          $txtSearch		=	$this->passedArgs["txtSearch"];

					 if($cmbSearchType == "oid"){

						$data = $this->paginate('Refund', array('Refund.id  = ' => addslashes($txtSearch)));

					}elseif($cmbSearchType == "orderstatus"){

						$data = $this->paginate('Refund', array('Refund.status LIKE ' => "%".addslashes($txtSearch)."%"));

					}elseif($cmbSearchType == "username"){

						$data = $this->paginate('Refund', array('User.uname LIKE ' => "%".addslashes($txtSearch)."%"));

					}elseif($cmbSearchType == "dateoforder"){

						$split_date=explode('-',$txtSearch);

						if(isset($split_date[0]) && isset($split_date[1]) &&  isset($split_date[2]))

						$srch_date=trim($split_date[2]).'-'.trim($split_date[0]).'-'.trim($split_date[1]);

						else

						$srch_date='00-00-1000';						

						$data = $this->paginate('Refund', array('Refund.date LIKE ' => "%".addslashes($srch_date)."%"));

		

					}elseif($cmbSearchType == "ordernumber"){

						$data = $this->paginate('Refund', array('Refund.order_id =' => addslashes($txtSearch)));

					}else{

						$data = $this->paginate('Refund');

					}

		

		}

		else

		{

			$data = $this->paginate('Refund');

		}



		$this->set('cmbSearchType', $cmbSearchType);

		$this->set('txtSearch', $txtSearch);	

		$this->passedArgs['limit']=$this->paginate["limit"];

         $this->set('passedarg',$this->passedArgs);





		$this->set('odr', $data);



		$this->layout = 'adm';



    }



	function requestrefund($id=0){
            $this->__validateLoginStatus('U');
            
            $cnfg 				= Configure::read('Neutrino');
                
            if(trim($_SERVER['HTTP_HOST']) == 'localhost'){ 
                include_once("../phpmailer/class.phpmailer.php");
            }else{
                include_once($_SERVER["DOCUMENT_ROOT"].$cnfg["sitebasefolder"]."/app/phpmailer/class.phpmailer.php");
            }

		



		$sus		=	$this->Session->read('Userlog');



		$data		=	$this->Order->findById($id);



		global $currency;



		$curr		=	$this->Currency->findByCode($currency);		



		$this->set('curlogo',$curr["Currency"]["logo"]);



		if($sus["id"] <> $data["Order"]["user_id"]){



			$this->Session->setFlash('You are not authoized to request for a refund.');



			$this->redirect(array('controller' => 'pages', 'action' => 'display')); 



			exit;



		}



		if(empty($data)){



			$this->Session->setFlash('Invalid order for request a refund.');



			$this->redirect(array('controller' => 'pages', 'action' => 'display')); 



			exit;



		}



		$orderid	=	$id;



		/************* Section to insert onto database......................*/



		if($_SERVER['REQUEST_METHOD'] == "POST"){



			if(!isset($_POST["chbx"])){



				$this->Session->setFlash('select atleast one product to return.');



				$this->redirect(array('controller' => 'refunds', 'action' => 'requestrefund/'.$orderid)); 



				exit;



			}



			$rstat						=	$this->Refundstatus->findById(1);



			$rfd["user_id"]				=	$sus["id"];



			$rfd["order_id"]			=	$orderid;			



			$rfd["customer_feedback"]	=	$_POST["customer_feedback"];



			$rfd["status"]				=	$rstat["Refundstatus"]["title"];



			$rfd["date"]				=	date("Y-m-d");



			$this->Refund->save($rfd);



			$refid	=	$this->Refund->id;

//************************ Send refund mail admin ***********


                       
                        
                       $checked_array = explode(',',$_POST['checked_arry']);
                      

                        $cnfg 				=	Configure::read('Neutrino');
$mailRefundSubject = "Refund Request from ".$cnfg["site_name"];
$mailRefundBody = "<table width='90%'  border='0' cellspacing='2' cellpadding='2' align='left'>

	  <tr>

		<td colspan='2' align='left'>

		<p>Dear Administrator,</p>

                New refund request have been received.</br>";

                if(trim($_POST["customer_feedback"]) != ''){
                    $mailRefundBody .= "<br>Customer Feedback : ".$_POST["customer_feedback"];
                }
                   
                 $mailRefundBody .= "<br> <b>Product Details :</b><br>";
             
                for($j=0;$j<count($checked_array); $j++){
                 
                    $product_details1 = $this->OrderDetail->findById($checked_array[$j]);
                    $product_details = $this->Product->findById($product_details1["OrderDetail"]["product_id"]);
                   
                   
                        $prd_name = $product_details['Product']['pname'];
                        $prd_desc = $product_details['Product']['descr'];
                        $prd_retPrice = $product_details['Product']['price'];
                        $prd_wholePrice = $product_details['Product']['wholesale_price'];
                        $prd_stock = $product_details['Product']['stock'];
                        $prd_reorder = $product_details['Product']['reorderlevel'];
                    //echo $_POST['chbx'][$i];exit;
                   $mailRefundBody .= "<br />
                    # &nbsp; : &nbsp; "  . ($j+1) . "<br>
                   Product Name &nbsp; : &nbsp; "  . $prd_name . "<br>
                   Product Description &nbsp; : &nbsp; "  . $prd_desc . "<br>
                   Product Retail Price &nbsp; : &nbsp; "  .$curr["Currency"]["logo"].' '. $prd_retPrice . "<br>
                   Product Wholesale Price &nbsp; : &nbsp; "  .$curr["Currency"]["logo"].' '. $prd_wholePrice . "<br> ";
                  
                }
                
                $mailRefundBody .= "Please  <a href = '". FULL_BASE_URL. $cnfg["sitebasefolder"] ."/refunds/details/".$refid."'>click here</a>  for more details.
               

		</td>

	  </tr>
          </table>
";
                


$headers 		= "From: ".$cnfg["site_name"]."<".$cnfg["admin_email"].">\r\n";

$headers 		.= "MIME-Version: 1.0\r\n";

$headers 		.= "Content-type: text/html; charset=iso-8859-1\r\n";

$pdt 			= 	$this->Cmspage->findByTitle('Order status change mail');

$path			=	"SiteLogo_disp.gif";

$mcont			=	"<table width='90%'  border='0' cellspacing='2' cellpadding='2' align='center'>

			  <tr><td><a href='".FULL_BASE_URL. $cnfg["sitebasefolder"]."' target='_blank'><img src='".FULL_BASE_URL. $cnfg["sitebasefolder"]."/app/webroot/".IMAGES_URL.$path."' border='0'></a></td></tr></table>";

//$cnfg["site_name"]	=	"<a href='".FULL_BASE_URL. $cnfg["sitebasefolder"]."' target='_blank'>".$cnfg["site_name"]."</a>";
$mailcontent = $mcont.$mailRefundBody;

//echo $mailcontent;exit;
//$mailsent 		= mail($cnfg["admin_email"],$mailRefundSubject,$mailcontent,$headers);

    /*#################################### EMAIL SEGMENT ###############################*/        

        /******************************* MAIL TO THE ADMINISTRATOR ****************************/
        $site_name      = "";
        $admin_email    = "";
        if(trim($cnfg["site_name"]) <> ""){
            $site_name  = trim($cnfg["site_name"]);                            
        }else{
            $site_name = $cnfg["smtp_user"];                            
        }  
        if(trim($cnfg["admin_email"]) <> ""){
            $admin_email = trim($cnfg["admin_email"]);
        }else{
            $admin_email = $cnfg["smtp_user"];
        }
        $mail             = new PHPMailer(true);                
        $body             = trim($mailcontent);
        //$body           = eregi_replace("[\]",'',$body);
        $mail->IsSMTP(); 
        $mail->SMTPSecure = 'tls';
        //$mail->SMTPDebug  = 2;                    
        $mail->SMTPAuth   = true;  
            
        $mail->Host       = $cnfg["smtp_host"]; 
        $mail->Port       = $cnfg["smtp_port"];   
        $mail->Username   = $cnfg["smtp_user"];
        $mail->Password   = $cnfg["smtp_password"];      
        $mail->SetFrom($admin_email,$site_name);
        $mail->AddReplyTo($admin_email,$site_name);
        $mail->Subject    = $mailRefundSubject;
        $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
        $mail->MsgHTML($body);                    
        $mail->AddAddress($admin_email, "Administrator - ".trim($site_name)); 
        $mail->Send();
        /******************************* MAIL TO THE ADMINISTRATOR ****************************/    

        /*#################################### EMAIL SEGMENT ###############################*/

 //********************Send refund mail admin ends ***********

			$chkarr	=	$_POST["chbx"];

			

			$maxpdt	=	sizeof($_POST["orderdetid"]);



			for($t=0;$t < $maxpdt; $t++){



				

				if(in_array($_POST["orderdetid"][$t],$chkarr)){

				

				    $this->Refundproducts->create($rdet = array());



					$orddet						=	$this->OrderDetail->findById($_POST["orderdetid"][$t]);



					$rdet["refund_id"]			=	$refid;



					$rdet["product_id"]			=	$_POST["productid"][$t];



					$rdet["combination_id"]		=	$_POST["combid"][$t];



					$rdet["return_reason"]		=	$_POST["returnreason"][$t];



					$rdet["quantity"]			=	$_POST["quantity"][$t];



					$rdet["product_price"]		=	$orddet["OrderDetail"]["product_price"];



					$rdet["extra_price"]		=	$orddet["OrderDetail"]["extra_price"];



                    if(isset($orddet["OrderDetail"]["discount"]) && $orddet["OrderDetail"]["discount"] <> '')
					$rdet["discount"]			=	$orddet["OrderDetail"]["discount"];
					else
					$rdet["discount"]			=	0.00;

					

					$rdet["discount_type"]	    =	$orddet["OrderDetail"]["discount_type"];

					

					$rdet["type"]			    =	$orddet["OrderDetail"]["type"];

					

					$rdet["price_type"]			=	$orddet["OrderDetail"]["price_type"];



					$this->Refundproducts->save($rdet);

				}



			}

   

			$this->Session->setFlash('Your refund request has been sent to administrator.');



			$this->redirect(array('controller' => 'users', 'action' => 'myaccount')); 



			exit;



		}



		/************* Section to insert onto database......................*/



		



		$reasons	=	$this->Refundreason->find('list',array('fields'=>array('Refundreason.id', 'Refundreason.title')));

		



		for($j=0;$j < sizeof($data["OrderDetail"]);$j++)



		{		

			    if($data["OrderDetail"][$j]["type"]=='P')

				  {

					$pdet	=	$this->Product->findById($data["OrderDetail"][$j]["product_id"]);				  	

					$data["OrderDetail"][$j]["Product"]	=	$pdet["Product"]["pname"];

				  }

				  else if($data["OrderDetail"][$j]["type"]=='G')

				  {

					$gdet	=	$this->Giftcard->findById($data["OrderDetail"][$j]["product_id"]);								

					$data["OrderDetail"][$j]["Product"]	=	$gdet["Giftcard"]["gift_code"].'(Gift Card)';

				  }			



			//$pdet	=	$this->Product->findById($data["OrderDetail"][$j]["product_id"]);



			//$data["OrderDetail"][$j]["Product"]	=	$pdet["Product"];			



			//Fetching the  product combination details

                if($data["OrderDetail"][$j]["type"]=='P')

				 {

				  if($pdet["Product"]["combination"]=='Y')



				      {



			                 $pcombndet	=	$this->Productdetail->findById($data["OrderDetail"][$j]["combination_id"]);						



						       $pcmbnid=explode(',',$pcombndet["Productdetail"]["customvalue_id"]);



								 foreach($pcmbnid as $key => $val)



								 {



								   if($val!='')



								   {



									$combnstr[]=$this->Product->getpdctcmbn($val);



									$combinations=implode(" ,",$combnstr);				  



									$data["OrderDetail"][$j]["combinations"]= $combinations;									



								   }					



								 } 



								 $data["OrderDetail"][$j]["skuno"]= $pcombndet["Productdetail"]["skuno"];	



								 unset($combnstr);unset($combinations);			



					 }

					 }	//end of if stmt.. 



				   //Fetching the  product combination details			



		} // end of for loop..		



		//echo "<pre>";print_r($data);echo "</pre>";



		$this->set('odr', $data);



		$this->set('reason', $reasons);



		



	} 



	



	/****** Function to display returns submitted by a user at user end................*/



	function myreturns(){



		$this->__validateLoginStatus('U');



		$sus		=	$this->Session->read('Userlog');



		$data = $this->paginate('Refund', array('Refund.user_id  = ' => $sus["id"]));



		$this->set('data',$data);



	}



	function details($id=0){

            $this->__validateLoginStatus();

            $cnfg 		= Configure::read('Neutrino');

            if(trim($_SERVER['HTTP_HOST']) == 'localhost'){ 
                include_once("../phpmailer/class.phpmailer.php");
            }else{
                include_once($_SERVER["DOCUMENT_ROOT"].$cnfg["sitebasefolder"]."/app/phpmailer/class.phpmailer.php");
            }
                
            $style          = $cnfg["style"];
            $this->set('style', "admin/".$style);
            $admsess        = $this->Session->read('Admin');
	
            if($admsess["refund"] <> 1){
                $this->redirect(array('controller' => 'admins', 'action' => 'index')); 
                exit();
            }



		$this->Refund->id	=	$id;



		$data		=	$this->Refund->findById($id);

                

		if(empty($data)){

                    

			$this->Session->setFlash('Invalid refund request.');



			$this->redirect(array('controller' => 'admins', 'action' => 'index')); 



			exit;



		}



		global $currency;



		$curr		=	$this->Currency->findByCode($currency);		



		$this->set('curlogo',$curr["Currency"]["logo"]);



		if($_SERVER['REQUEST_METHOD'] == "POST"){

  

			$rfd["additional_info"]		=	$_POST["additional_info"];



			$rfd["refund_mode"]			=	$_POST["refund_mode"];



			$rfd["reference_number"]	=	$_POST["reference_number"];



			$rfd["status"]				=	$_POST["status"];



			$this->Refund->save($rfd);

			$this->Session->setFlash('Your refund reply have been sent.');
                       // print '<pre />';print_r($_POST);EXIT;
                        /********************* Send mail to user for Refumd request ******************/
                        
                          $refid                        = $_POST['id'];                   
                        
                       $checked_array                   =  explode(',',$_POST['productId']);
                        $cnfg 				=	Configure::read('Neutrino');
                        $mailRefundSubject = "Refund Request Reply from ".$cnfg["site_name"];
                        $mailRefundBody = "<table width='90%'  border='0' cellspacing='2' cellpadding='2' align='left'>

                                            <tr>

                                                  <td colspan='2' align='left'>

                                                  <p>Dear ".addslashes($_POST['uname']).",</p>

                                                  Refund request reply has been received From ".$cnfg["site_name"]."</br>";

                                                  if(trim($_POST["customer_feedback"]) != ''){
                                                     
                                                      $mailRefundBody .= "<br>Refund Status : ".$_POST["status"]."<br />";
                                                      $mailRefundBody .= "<br>Reference Number : ".$_POST["reference_number"]."<br />";
                                                  }

                                                   $mailRefundBody .= "<br> <b>Product Details :</b><br>";
             
                                for($j=0;$j<count($checked_array); $j++){
                                    if(!empty($checked_array[$j])){

                                    $product_details = $this->Product->findById($checked_array[$j]);


                                        $prd_name = $product_details['Product']['pname'];
                                        $prd_desc = $product_details['Product']['descr'];
                                        $prd_retPrice = $product_details['Product']['price'];
                                        $prd_wholePrice = $product_details['Product']['wholesale_price'];
                                        $prd_stock = $product_details['Product']['stock'];
                                        $prd_reorder = $product_details['Product']['reorderlevel'];
                                    //echo $_POST['chbx'][$i];exit;
                                   $mailRefundBody .= "<br />
                                    # &nbsp; : &nbsp; "  . ($j+1) . "<br>
                                   Product Name &nbsp; : &nbsp; "  . $prd_name . "<br>
                                   Product Description &nbsp; : &nbsp; "  . $prd_desc . "<br>
                                   Product Retail Price &nbsp; : &nbsp; "  .$curr["Currency"]["logo"].' '. $prd_retPrice . "<br>
                                   Product Wholesale Price &nbsp; : &nbsp; "  .$curr["Currency"]["logo"].' '. $prd_wholePrice . "<br>";
                                    }

                                }
                
                $mailRefundBody .= "Please  <a href = '". FULL_BASE_URL. $cnfg["sitebasefolder"] ."/refunds/refundetails/".$refid."'>click here</a>  for more details.
                                    </td>
                                  </tr>
                                  </table>";
                


$headers 		= "From: ".$cnfg["site_name"]."<".$cnfg["admin_email"].">\r\n";
$headers 		.= "MIME-Version: 1.0\r\n";
$headers 		.= "Content-type: text/html; charset=iso-8859-1\r\n";
$pdt 			= 	$this->Cmspage->findByTitle('Order status change mail');
$path			=	"SiteLogo_disp.gif";
$mcont			=	"<table width='90%'  border='0' cellspacing='2' cellpadding='2' align='center'>
                                 <tr><td><a href='".FULL_BASE_URL. $cnfg["sitebasefolder"]."' target='_blank'><img src='".FULL_BASE_URL. $cnfg["sitebasefolder"]."/app/webroot/".IMAGES_URL.$path."' border='0'></a></td></tr></table>";
//$cnfg["site_name"]	=	"<a href='".FULL_BASE_URL. $cnfg["sitebasefolder"]."' target='_blank'>".$cnfg["site_name"]."</a>";
$mailcontent = $mcont.$mailRefundBody;

//echo $mailcontent;exit;
//$mailsent 		= mail($_POST['user_email'],$mailRefundSubject,$mailcontent,$headers);

/*#################################### EMAIL SEGMENT ###############################*/        

        /******************************* MAIL TO THE USER ****************************/
        $site_name      = "";
        $admin_email    = "";
        if(trim($cnfg["site_name"]) <> ""){
            $site_name  = trim($cnfg["site_name"]);                            
        }else{
            $site_name = $cnfg["smtp_user"];                            
        }  
        if(trim($cnfg["admin_email"]) <> ""){
            $admin_email = trim($cnfg["admin_email"]);
        }else{
            $admin_email = $cnfg["smtp_user"];
        }
        
        $mail             = new PHPMailer(true);                
        $body             = trim($mailcontent);
        //$body           = eregi_replace("[\]",'',$body);
        $mail->IsSMTP(); 
        $mail->SMTPSecure = 'tls';
        //$mail->SMTPDebug  = 2;                    
        $mail->SMTPAuth   = true;  
            
       $mail->Host       = $cnfg["smtp_host"]; 
       $mail->Port       = $cnfg["smtp_port"];   
       $mail->Username   = $cnfg["smtp_user"];
       $mail->Password   = $cnfg["smtp_password"];      
        $mail->SetFrom($admin_email,$site_name);
        $mail->AddReplyTo($admin_email,$site_name);
        $mail->Subject    = $mailRefundSubject;
        $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
        $mail->MsgHTML($body);                    
        $mail->AddAddress($_POST['user_email'], ""); 
        $mail->Send();
        /******************************* MAIL TO THE USER ****************************/    

    /*#################################### EMAIL SEGMENT ###############################*/
        
                         /********************* Send mail to user for Refumd request ******************/
                        
			
                        $this->redirect(array('controller' => 'refunds', 'action' => 'details/'.$id)); 

			

			exit();



		}



		$refundoptions	=	$this->Refundoption->find('list',array('fields'=>array('Refundoption.id', 'Refundoption.title')));



		$rstat			=	$this->Refundstatus->find('list',array('fields'=>array('Refundstatus.id', 'Refundstatus.title')));

		

		



		for($j=0;$j < sizeof($data["Refundproducts"]);$j++)
		{
	   

			    if($data["Refundproducts"][$j]["type"]=='P')

				  {

					$pdet	=	$this->Product->findById($data["Refundproducts"][$j]["product_id"]);				  	

					$data["Refundproducts"][$j]["Product"]	=	$pdet["Product"]["pname"];

				  }

				  else if($data["Refundproducts"][$j]["type"]=='G')

				  {

					$gdet	=	$this->Giftcard->findById($data["Refundproducts"][$j]["product_id"]);								

					$data["Refundproducts"][$j]["Product"]	=	$gdet["Giftcard"]["gift_code"].'(Gift Card)';

				  }			

			

			

			//$pdet	=	$this->Product->findById($data["Refundproducts"][$j]["product_id"]);



			//$data["Refundproducts"][$j]["Product"]	=	$pdet["Product"];			



			//Fetching the  product combination details

              //Fetching the  product combination details

                if($data["Refundproducts"][$j]["type"]=='P')

				 {

				  if($pdet["Product"]["combination"]=='Y')



				      {



			                 $pcombndet	=	$this->Productdetail->findById($data["Refundproducts"][$j]["combination_id"]);						



						       $pcmbnid=explode(',',$pcombndet["Productdetail"]["customvalue_id"]);



								 foreach($pcmbnid as $key => $val)



								 {



								   if($val!='')



								   {



									$combnstr[]=$this->Product->getpdctcmbn($val);



									$combinations=implode(" ,",$combnstr);				  



									$data["Refundproducts"][$j]["combinations"]= $combinations;									



								   }					



								 } 



								 $data["Refundproducts"][$j]["skuno"]= $pcombndet["Productdetail"]["skuno"];	



								 unset($combnstr);unset($combinations);			



					 }	}//end of if stmt.. 



				   //Fetching the  product combination details			



		} // end of for loop..		



		//echo "<pre>";print_r($data);echo "</pre>";exit;

	

		$this->set('odr', $data);

		

    	$this->set('refundoptions', $refundoptions);



		$this->set('refundstatus', $rstat);



		$this->layout = 'adm';



	}



function refundetails($id=0)
{


		
		$this->__validateLoginStatus('U');



		$sus		=	$this->Session->read('Userlog');
		
		$this->Refund->id	=	$id;



		$data		=	$this->Refund->findById($id);



		if(empty($data)){



			$this->Session->setFlash('Invalid refund request.');



			$this->redirect(array('controller' => 'admins', 'action' => 'index')); 



			exit;



		}



		global $currency;



		$curr		=	$this->Currency->findByCode($currency);		



		$this->set('curlogo',$curr["Currency"]["logo"]);



		if($_SERVER['REQUEST_METHOD'] == "POST"){


			
			$this->Refund->id = $id;

		    $this->Refund->saveField('customer_feedback',$_POST["customer_feedback"]);			

			$this->redirect(array('controller' => 'refunds', 'action' => 'refundetails/'.$id)); 
			

			exit();


		}



		$refundoptions	=	$this->Refundoption->find('list',array('fields'=>array('Refundoption.id', 'Refundoption.title')));



		$rstat			=	$this->Refundstatus->find('list',array('fields'=>array('Refundstatus.id', 'Refundstatus.title')));

		

		



		for($j=0;$j < sizeof($data["Refundproducts"]);$j++)



		{

		   

			    if($data["Refundproducts"][$j]["type"]=='P')

				  {

					$pdet	=	$this->Product->findById($data["Refundproducts"][$j]["product_id"]);				  	

					$data["Refundproducts"][$j]["Product"]	=	$pdet["Product"]["pname"];

				  }

				  else if($data["Refundproducts"][$j]["type"]=='G')

				  {

					$gdet	=	$this->Giftcard->findById($data["Refundproducts"][$j]["product_id"]);								

					$data["Refundproducts"][$j]["Product"]	=	$gdet["Giftcard"]["gift_code"].'(Gift Card)';

				  }			

			

			

			//$pdet	=	$this->Product->findById($data["Refundproducts"][$j]["product_id"]);



			//$data["Refundproducts"][$j]["Product"]	=	$pdet["Product"];			



			//Fetching the  product combination details

              //Fetching the  product combination details

                if($data["Refundproducts"][$j]["type"]=='P')

				 {

				  if($pdet["Product"]["combination"]=='Y')



				      {



			                 $pcombndet	=	$this->Productdetail->findById($data["Refundproducts"][$j]["combination_id"]);						



						       $pcmbnid=explode(',',$pcombndet["Productdetail"]["customvalue_id"]);



								 foreach($pcmbnid as $key => $val)



								 {



								   if($val!='')



								   {



									$combnstr[]=$this->Product->getpdctcmbn($val);



									$combinations=implode(" ,",$combnstr);				  



									$data["Refundproducts"][$j]["combinations"]= $combinations;									



								   }					



								 } 



								 $data["Refundproducts"][$j]["skuno"]= $pcombndet["Productdetail"]["skuno"];	



								 unset($combnstr);unset($combinations);			



					 }	}//end of if stmt.. 



				   //Fetching the  product combination details			



		} // end of for loop..		



		//echo "<pre>";print_r($data);echo "</pre>";exit;

	

		$this->set('odr', $data);

		

    	$this->set('refundoptions', $refundoptions);



		$this->set('refundstatus', $rstat);

 }


	

    function beforeFilter()



    {



       if (isset($this->Setting) && !empty($this->Setting->table))  



        {  



             $this->Setting->load();  



        } 



		global $sitefolder; 



		global $meta_description;



		global $meta_keywords;



		global $page_title;



		global $currency;



		$cnfg 				=	Configure::read('Neutrino');



		$sitefolder			=	$cnfg["sitebasefolder"];



		$currency			=	$cnfg["currency"];



		$meta_description	=	$cnfg["meta_description"];



		$meta_keywords		=	$cnfg["meta_keywords"];



		$page_title			=	$cnfg["page_title"];



		global $style; 



		$style				=	$cnfg["style"];



		$this->set('style', $style);



		$this->set('meta_description', $meta_description);



		$this->set('meta_keywords', $meta_keywords);



		$this->pageTitle = $page_title	; 



		$this->set('cnfg',$cnfg);



		$this->paginate["limit"]=$cnfg["items_perpage"]; //Setting pagination limit per page.

		

		$this->paginate["limit"]=$cnfg["items_perpage"]; //Setting pagination limit per page.

		$this->set('sitefolder', $sitefolder);

		$httpHost	=	$_SERVER['HTTP_HOST'];

		$this->set('sitebase','http://'.$httpHost);
                //get cart count
                 $sus = $this->Session->read();
                if ($this->Session->check('Userlog') === true) {
                  $userid = $sus["Userlog"]["id"];
                    $cartCount = $this->Cart->getCartCount($userid,'user');
                }else {
                  $sessid = $this->Session->id();
                    $cartCount = $this->Cart->getCartCount($sessid,'G');
                }
                $this->set('cartcount',$cartCount);



    }



	function beforeRender(){



				//$lst	=	$this->Catmenu->getCatList(1);



				//$this->set('catmenu', $lst);



		//Code Added By shyam for Category Menu Listing starts here..



		// $lst	=	$this->Category->findAll();
                 $lst	=	$this->Category->findAll(null, NULL, 'Category.cname ASC', null, null);


		 foreach($lst as $det)



		 $menu_array[$det["Category"]["id"]] = array('name' => $det["Category"]["cname"],'parent' => $det["Category"]["parent_id"]);



		 $this->set('menu_array', $menu_array);		


$footer_links = $this->Cmspage->find('list',array('conditions' => array('Cmspage.type' => 'content','Cmspage.status' => 'Y')));	
		$this->set('footerlinks', $footer_links);			
		//Code Added By shyam for Category Menu Listing ends here..



	}



	function __validateLoginStatus($typ='A')



    {



           if($typ == 'A'){



				if($this->Session->check('Admin') == false)



				{



					$this->redirect(array('controller' => 'admins', 'action' => 'login')); 



					$this->Session->setFlash('The URL you\'ve followed requires you login.');



				}



			}else{



				if($this->Session->check('Userlog') == false)



				{



					$this->redirect(array('controller' => 'users', 'action' => 'login')); 



					$this->Session->setFlash('The URL you\'ve followed requires you login.');



				}



			}



    } 



	



}



?>