<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | Common database model class. It use for common functions             |
// | File name : common.php                                               |
// | PHP version >= 5.2                                                   |
// | Created On 4 January 2012                                            |
// +----------------------------------------------------------------------+
// | Author: Rajath Kamal <rajath.k@armiasystems.com>                     |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems ? 2010                                      |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------|



class ControllerPaypal extends BaseController
{
	/*
		construction function. we can initialize the models here
	*/
    public $userName   =   '';
    public $userPass   =   '';
    public $userId     =   0;
    public $listId='';
    public $UserDetails='';

     public function init()
    {
        parent::init();
         /*       if(LibSession::get('user_id')=="")
                   {
                       $this->switchmodule(ConfigUrl::base('default'));
                       exit;
                   }*/


                 $this->_common		= new ModelCommon;
                 $this->_postads = new ModelPostads;
                 $this->_session = new LibSession();
	        //$this->_modelpaypal	  = new ModelPaypal;
                //$this->_indexmodel      = new ModelIndex;
               // LibSession::set('user_id',1);
			   /*------------- Categories End -------------------*/
        $categroy_flag = true;
        $categories = $this->_common->getAllData('nCategoryId, vCategoryDesc', 'category','','','','ASC','vRoute');
        if($categories) {
            foreach($categories as $cat_val) {
                $products = $this->_common->selectResult('product','nBusId, nCatid, Title', "nCatid = {$cat_val->nCategoryId} LIMIT 0, 10");
                $category[$cat_val->nCategoryId] = array();
                if($products) {
                    foreach($products as $prd_val) {
                        $category[$cat_val->nCategoryId][$prd_val->nBusId] = $prd_val->Title;
                    }
                }
                unset($products);

                $category_title[$cat_val->nCategoryId] = $cat_val->vCategoryDesc;
            }
        }
        else {
            $categroy_flag = false;
        }
        // get Site Settings ***************************************
            $settings = $this->_common->selectResult('settings','*');

            foreach($settings as $field ) {
                $setting[$field->settingfield]= $field->value;
            } // End Foreach

            $this->view->setting = $setting;
            $this->siteSettings = $setting;
        // get Site Settings end ***************************************
        $this->categoryTitle = $category_title;
        $this->view->category_flag      = $categroy_flag;
        $this->view->category           = $category;
        $this->view->category_title     = $category_title;
        /*------------- Categories End -------------------*/
   
            
            
    }
      public function paymentdetails($id)
     {
          //if(isset($_SESSION['user']['userID']))
             // {
           $this->listId   =   $this->_common->selectRow("product","max(`nBusId`)","nUserId='$id'");
           $_SESSION['busid']=$this->listId;
		    
           //   }

            //else{
         // $this->listId   =   $this->_common->selectRow("product","nBusId","nUserId='$id'");
         // $_SESSION['busid']=$this->listId;
           // }
          $userId = $_SESSION['nUserid'];
          $this->UserDetails =  $this->_common->selectRecord("users","*","nUserId='".$id."'");
          $this->view->UserDetails->firstname =$this->UserDetails->vFirstName;
          $this->view->UserDetails->lastname  =$this->UserDetails->vLastName;
          $this->view->UserDetails->Email    =$this->UserDetails->vEmail;
          $this->view->UserDetails->Address1 =$this->UserDetails->vAddress1;
          $this->view->UserDetails->ZipCode      =$this->UserDetails->nZip;
          $authorizeEnable      =   $this->_common->selectRow("settings","value","settingfield='authorize_enable'");
        $paypalEnable      =   $this->_common->selectRow("settings","value","settingfield='enablepaypal'");

        $this->view->paypalEnabled =($paypalEnable=='Y')? true :false;
        $this->view->authorizeEnabled = ($authorizeEnable=='Y')? true : false;
        $this->view->message=($paypalEnable!='Y' && $authorizeEnable!='Y') ? 'No Payment Option Available. Please Contact Administrator.':'';

     }



    
	public function process($mode='',$listId='')

	{
           if($listId=='') {
            $listId = $_SESSION['busid'];
           }
           $userId = $_SESSION['nUserid'];
      
          
           $this->Libpaypal_class = new  LibPaypal_class();

           $paypalEnable    =   $this->_common->selectRow("settings","value","settingfield='enablepaypal'");

           $paypalTestMode  =   $this->_common->selectRow("settings","value","settingfield='enablepaypalsandbox'");

           $paypalEmail     =   $this->_common->selectRow("settings","value","settingfield='paypalemail'");
            if($mode =='F'){//Featured
               $paymentAmount   =   $this->_common->selectRow("settings","value","settingfield='nFeatured_Amount'");
            }
            elseif($mode=='R'){//Renewal
                 $join   =" INNER JOIN ".MYSQL_TABLE_PREFIX."plans AS plans ON plans.nPlanId = product.nPlanId";
                $where  =" WHERE  product.nBusId =".$listId;
                $row_listings    =   $this->_common->getAllData('plans.vPlanAmount,plans.vPlanDuration','product AS product',$join ,$where);
               //echopre1($row_listings);
                $paymentAmount = $row_listings[0]->vPlanAmount;
                //exit;
                $duration = $row_listings[0]->vPlanDuration;
            }
           else{//Listing
            $paymentAmount   =   $this->_common->selectRow("plans","vPlanAmount","nPlanId='".$_SESSION['planid']."'");
           }

           $paymentCurrency =   $this->_common->selectRow("settings","value","settingfield='admin_currency'");

            if($paypalTestMode == "Y"){
                //$paypalurl ="http://192.168.0.11/sudheesh/paypal.php";
                    $paypalurl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
                    $paypalbuttonurl = "https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" ;
            }else{
                //$paypalurl ="http://192.168.0.11/sudheesh/paypal.php";
                    $paypalurl = "https://www.paypal.com/cgi-bin/webscr";
                    $paypalbuttonurl = "https://www.paypal.com/en_US/i/btn/x-click-but23.gif" ;
            }

        // User Information

        $this->userName = $this->_session->get('user_login');
        $this->userPass = $this->_session->get('user_pass');
        $this->userId   = $this->_session->get('user_id');
        
        if($mode =='F'){//Featured
            $this_script_success    = BASE_URL."default/paypal/success/".$listId."/F";

            $this_script_cancel     = BASE_URL."default/paypal/cancel";

            $this_script_ipn        = BASE_URL."default/paypal/ipnfeatured";
            
        }
        elseif($mode=='R'){//Renewal
          $this_script_success    = BASE_URL."default/paypal/success/".$listId."/R";

          $this_script_cancel     = BASE_URL."default/paypal/cancel";

          $this_script_ipn        = BASE_URL."default/paypal/ipnrenew";  
        }
        else{//Listing
            $this_script_success    = BASE_URL."default/paypal/success/".$listId;

            $this_script_cancel     = BASE_URL."default/paypal/cancel";

            $this_script_ipn        = BASE_URL."default/paypal/ipn";
            
        }
        

        $txtUserFirstName =  $this->_common->selectRow("users","vFirstName","nUserId='".$userId."'");

        $txtUserLastName =  $this->_common->selectRow("users","vLastName","nUserId='".$userId."'");

        $listName        = $this->_common->selectRow("product","Title","nBusId='".$listId."'");
        

        $this->view->txtUserFirstName       = $txtUserFirstName;

        $this->view->txtUserLastName        = $txtUserLastName;

        $this->view->paypalEmail             = $paypalEmail;
        
        $this->view->paypalEmail             = $paypalEmail;
        
        $this->view->this_script_success     = $this_script_success;
        
        $this->view->this_script_cancel      = $this_script_cancel;

        $this->view->this_script_ipn         = $this_script_ipn;
        
        $this->view->paymentAmount           = $paymentAmount;

        $this->view->paymentCurrency         = $paymentCurrency;
        
        
        $this->view->submit_paypal_post      = 'submit_paypal_post';

        $this->view->paypalUrl               = $paypalurl;
        
        
         $this->view->Libpaypal_class       = $this->Libpaypal_class;

         $this->view->listName              = $listName;

         $this->view->listId              = $listId;


            
	}


        public function ipn()
        {

            $paypalTestMode  =   $this->_common->selectRow("settings","value","settingfield='enablepaypalsandbox'");

             if($paypalTestMode == "Y"){
                //$paypalurl ="http://192.168.0.11/sudheesh/paypal.php";
                    $paypalurl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
                    $paypalbuttonurl = "https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" ;
            }else{
                //$paypalurl ="http://192.168.0.11/sudheesh/paypal.php";
                    $paypalurl = "https://www.paypal.com/cgi-bin/webscr";
                    $paypalbuttonurl = "https://www.paypal.com/en_US/i/btn/x-click-but23.gif" ;
            }

               
            $this->Libpaypal_class = new  LibPaypal_class();
            if ($this->Libpaypal_class->validate_ipn($paypalurl)) {

         foreach ($this->Libpaypal_class->ipn_data as $key => $value) { $body2 .= "\n$key: $value"; }

//            $f3 = fopen("testipn.txt","a+");
//            fwrite($f3, $body2);
//            fclose($f3);
//            mail('smitha.m@armiasystems.com','testing ipn',$body2);

                $paymentAmount = $this->Libpaypal_class->ipn_data['mc_gross'];

                $transaction_id = $this->Libpaypal_class->ipn_data['txn_id'];
          
                if($this->Libpaypal_class->ipn_data['custom']!='') {

                $Custom_Array = $this->Libpaypal_class->ipn_data['custom'];

                $Exp = explode('=>',$Custom_Array);

                $ListingId              = $Exp[0];

                $ListName               = $Exp[1];

                $txtUserFirstName       = $Exp[2];


                $txtUserLastName       = $Exp[3];


                $listName               = $Exp[4];

                
                   }
            }

           $paymentType   =   $this->_common->selectRow("plans","vPlantype","nPlanId='".$_SESSION['planid']."'");
            
            if($transaction_id!='')
                {
                    $paymentId = $this->_common->selectRow("payments","nPaymentId","vTransactionId='".$transaction_id."'  AND nListId=".$ListingId."");
           
                    $arrProfile =   array("nListId"=>$ListingId,
                                        "vUserFirstName"=>$txtUserFirstName,
                                        "vUserLastName"=>$txtUserLastName,
                                        "vAmount"=>$paymentAmount,
                                        "vProductName"=>$ListName,
                                        "vTransactionId"=>$transaction_id
                                       );

               if($paymentId==''){
                    $paymentId =   $this->_common->addFields("payments",$arrProfile);
                }
                    $arrProfile         =   array("nPaymentStatus"=>N);
                    $this->_common->updateFields("product",$arrProfile,"nBusId='".$ListingId."'");
             

            }

            

        }
        public function ipnfeatured()
        {

            $paypalTestMode  =   $this->_common->selectRow("settings","value","settingfield='enablepaypalsandbox'");

             if($paypalTestMode == "Y"){
                //$paypalurl ="http://192.168.0.11/sudheesh/paypal.php";
                    $paypalurl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
                    $paypalbuttonurl = "https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" ;
            }else{
                //$paypalurl ="http://192.168.0.11/sudheesh/paypal.php";
                    $paypalurl = "https://www.paypal.com/cgi-bin/webscr";
                    $paypalbuttonurl = "https://www.paypal.com/en_US/i/btn/x-click-but23.gif" ;
            }

               
            $this->Libpaypal_class = new  LibPaypal_class();
            if ($this->Libpaypal_class->validate_ipn($paypalurl)) {

          /*foreach ($this->Libpaypal_class->ipn_data as $key => $value) { $body2 .= "\n$key: $value"; }

            $f3 = fopen("testipn.txt","a+");
            fwrite($f3, $body2);
            fclose($f3);*/

                $paymentAmount = $this->Libpaypal_class->ipn_data['mc_gross'];

                $transaction_id = $this->Libpaypal_class->ipn_data['txn_id'];
          
                if($this->Libpaypal_class->ipn_data['custom']!='') {

                $Custom_Array = $this->Libpaypal_class->ipn_data['custom'];

                $Exp = explode('=>',$Custom_Array);

                $ListingId              = $Exp[0];

                $ListName               = $Exp[1];

                $txtUserFirstName       = $Exp[2];


                $txtUserLastName       = $Exp[3];


                $listName               = $Exp[4];

                
                   }
            }

           $paymentType   =   $this->_common->selectRow("plans","vPlantype","nPlanId='".$_SESSION['planid']."'");
            
            if($transaction_id!='')
                {
                    $paymentId = $this->_common->selectRow("payments","nPaymentId","vTransactionId='".$transaction_id."'  AND nListId=".$ListingId."");
           
                    $arrProfile =   array("nListId"=>$ListingId,
                                        "vUserFirstName"=>$txtUserFirstName,
                                        "vUserLastName"=>$txtUserLastName,
                                        "vAmount"=>$paymentAmount,
                                        "vProductName"=>$ListName,
                                        "vTransactionId"=>$transaction_id
                                       );

if($paymentId==''){
                    $paymentId =   $this->_common->addFields("payments",$arrProfile);
                }


//                    $arrProfile         =   array("nPaymentStatus"=>N);
//
//                    $this->_common->updateFields("product",$arrProfile,"nBusId='".$ListingId."'");
                    
//                    $arrProfile         =   array("nFeatured"=>1);
//
//                    $this->_common->updateFields("product",$arrProfile,"nBusId='".$ListingId."'");
                 

            }

            

        }
         public function ipnrenew()
        {

            $paypalTestMode  =   $this->_common->selectRow("settings","value","settingfield='enablepaypalsandbox'");

             if($paypalTestMode == "Y"){
                //$paypalurl ="http://192.168.0.11/sudheesh/paypal.php";
                    $paypalurl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
                    $paypalbuttonurl = "https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" ;
            }else{
                //$paypalurl ="http://192.168.0.11/sudheesh/paypal.php";
                    $paypalurl = "https://www.paypal.com/cgi-bin/webscr";
                    $paypalbuttonurl = "https://www.paypal.com/en_US/i/btn/x-click-but23.gif" ;
            }

               
            $this->Libpaypal_class = new  LibPaypal_class();
            if ($this->Libpaypal_class->validate_ipn($paypalurl)) {

          /*foreach ($this->Libpaypal_class->ipn_data as $key => $value) { $body2 .= "\n$key: $value"; }

            $f3 = fopen("testipn.txt","a+");
            fwrite($f3, $body2);
            fclose($f3);*/

                $paymentAmount = $this->Libpaypal_class->ipn_data['mc_gross'];

                $transaction_id = $this->Libpaypal_class->ipn_data['txn_id'];
          
                if($this->Libpaypal_class->ipn_data['custom']!='') {

                $Custom_Array = $this->Libpaypal_class->ipn_data['custom'];

                $Exp = explode('=>',$Custom_Array);

                $ListingId              = $Exp[0];

                $ListName               = $Exp[1];

                $txtUserFirstName       = $Exp[2];


                $txtUserLastName       = $Exp[3];


                $listName               = $Exp[4];

                
                   }
            }

           $paymentType   =   $this->_common->selectRow("plans","vPlantype","nPlanId='".$_SESSION['planid']."'");
            
            if($transaction_id!='')
                {
                    $paymentId = $this->_common->selectRow("payments","nPaymentId","vTransactionId='".$transaction_id."'  AND nListId=".$ListingId."");
           
                    $arrProfile =   array("nListId"=>$ListingId,
                                        "vUserFirstName"=>$txtUserFirstName,
                                        "vUserLastName"=>$txtUserLastName,
                                        "vAmount"=>$paymentAmount,
                                        "vProductName"=>$ListName,
                                        "vTransactionId"=>$transaction_id
                                       );

if($paymentId==''){
                    $paymentId =   $this->_common->addFields("payments",$arrProfile);
                }


                    $arrProfile         =   array("nPaymentStatus"=>N);

                    $this->_common->updateFields("product",$arrProfile,"nBusId='".$ListingId."'");
                 

            }

            

        }

        public function success($listId,$mode='')
        {
            
                 if($_GET['tx']!='')
                     {

                   $transaction_id = $_GET['tx'];


                   $paymentId = $this->_common->selectRow("payments","nPaymentId","vTransactionId='".$transaction_id."' AND vPaymentStatus='P' AND nListId=".$listId."");

                  
                   if($mode=='F'){
                       if($paymentId!='')
                        {
                            $arrUpdate  =   array("vPaymentStatus"=>'C',"vPaymentType"=>'F');
                            
                            $this->_common->updateFields("payments",$arrUpdate,"nPaymentId='".$paymentId."'");
                            $arrProfile         =   array("nFeatured"=>1);
                            $this->_common->updateFields("product",$arrProfile,"nBusId='".$listId."'");
                            $this->redirect('paypal/creditsuccess/1/F');
                            exit;
                      }
                      else{
                          
                         // $paymentId = $this->_common->selectRow("payments","nPaymentId","vTransactionId='".$transaction_id."'  AND nListId=".$ListingId."");
                          $userId = ($_SESSION['nUserid']!='')?$_SESSION['nUserid']:$this->_common->selectRow("product","nUserId","nBusId='".$listId."'");
                          $txtUserFirstName =  $this->_common->selectRow("users","vFirstName","nUserId='".$userId."'");
                          $txtUserLastName =  $this->_common->selectRow("users","vLastName","nUserId='".$userId."'");
                          $listName        = $this->_common->selectRow("product","Title","nBusId='".$listId."'");
                            $arrProfile =   array("nListId"=>$listId,
                                                "vUserFirstName"=>$txtUserFirstName,
                                                "vUserLastName"=>$txtUserLastName,
                                                "vAmount"=>$_GET['amt'],
                                                "vProductName"=>$listName,
                                                "vTransactionId"=>$transaction_id,
                                                "vPaymentStatus"=>'C',
                                                "vPaymentType"=>'F'
                                               );
                            $paymentId =   $this->_common->addFields("payments",$arrProfile);
                            $arrProfile         =   array("nFeatured"=>1);
                            $this->_common->updateFields("product",$arrProfile,"nBusId='".$listId."'");
                            $this->redirect('paypal/creditsuccess/1/F');
                           exit;
                          
                      }
                       
                       
                   }
                   elseif($mode=='R'){
                       if($paymentId!='')
                        {
                            $arrUpdate  =   array("vPaymentStatus"=>'C',"vPaymentType"=>'R');
                            $this->_common->updateFields("payments",$arrUpdate,"nPaymentId='".$paymentId."'");
                            $join   =" INNER JOIN ".MYSQL_TABLE_PREFIX."plans AS plans ON plans.nPlanId = product.nPlanId";
                            $where  =" WHERE  product.nBusId =".$listId;
                            $row_listings    =   $this->_common->getAllData('plans.vPlanAmount,plans.vPlanDuration','product AS product',$join ,$where);
                            $duration = $row_listings[0]->vPlanDuration;
                            $res = mysql_query("SELECT ADDDATE(CURDATE(),INTERVAL $duration Month) AS Expiry_date");
                            $row = mysql_fetch_row($res);
                            $expiry_date=$row['0'];
                            $arrProfile         =   array("nStatus"=>1,
                                                        "nPaymentStatus"=>P,
                                                         "nPlanExpiryDate"=>$expiry_date);

                           $this->_common->updateFields("product",$arrProfile,"nBusId='".$listId."'");
                           $this->redirect('paypal/creditsuccess/1/R');
                            exit;
                      }
                      else{
                          $userId = ($_SESSION['nUserid']!='')?$_SESSION['nUserid']:$this->_common->selectRow("product","nUserId","nBusId='".$listId."'");
                          $txtUserFirstName =  $this->_common->selectRow("users","vFirstName","nUserId='".$userId."'");
                          $txtUserLastName =  $this->_common->selectRow("users","vLastName","nUserId='".$userId."'");
                          $listName        = $this->_common->selectRow("product","Title","nBusId='".$listId."'");
                            $arrProfile =   array("nListId"=>$listId,
                                                "vUserFirstName"=>$txtUserFirstName,
                                                "vUserLastName"=>$txtUserLastName,
                                                "vAmount"=>$_GET['amt'],
                                                "vProductName"=>$listName,
                                                "vTransactionId"=>$transaction_id,
                                                "vPaymentStatus"=>'C',
                                                "vPaymentType"=>'R'
                                               );
                            $paymentId =   $this->_common->addFields("payments",$arrProfile);
                            $join   =" INNER JOIN ".MYSQL_TABLE_PREFIX."plans AS plans ON plans.nPlanId = product.nPlanId";
                            $where  =" WHERE  product.nBusId =".$listId;
                            $row_listings    =   $this->_common->getAllData('plans.vPlanAmount,plans.vPlanDuration','product AS product',$join ,$where);
                            $duration = $row_listings[0]->vPlanDuration;
                            $res = mysql_query("SELECT ADDDATE(CURDATE(),INTERVAL $duration Month) AS Expiry_date");
                            $row = mysql_fetch_row($res);
                            $expiry_date=$row['0'];
                            $arrProfile         =   array("nStatus"=>1,
                                                        "nPaymentStatus"=>P,
                                                         "nPlanExpiryDate"=>$expiry_date);

                           $this->_common->updateFields("product",$arrProfile,"nBusId='".$listId."'");
                           $this->redirect('paypal/creditsuccess/1/R');
                           exit;
                          
                      }
                       
                   }
                   else{
                    if($paymentId!='')
                        {
                             $arrUpdate  =   array("vPaymentStatus"=>'C',
                                                    "vPaymentType"=>'L');
                             $this->_common->updateFields("payments",$arrUpdate,"nPaymentId='".$paymentId."'");
                              $arrProfile         =   array("nPaymentStatus"=>P);
                               $this->_common->updateFields("product",$arrProfile,"nBusId='".$listId."'");
                             
                             $this->view->message='success';
                             $this->redirect('paypal/creditsuccess/1/L');
                             exit;
                      }
                      else{
                          
                         // $paymentId = $this->_common->selectRow("payments","nPaymentId","vTransactionId='".$transaction_id."'  AND nListId=".$ListingId."");
                          $userId = ($_SESSION['nUserid']!='')?$_SESSION['nUserid']:$this->_common->selectRow("product","nUserId","nBusId='".$listId."'");
                          $txtUserFirstName =  $this->_common->selectRow("users","vFirstName","nUserId='".$userId."'");
                          $txtUserLastName =  $this->_common->selectRow("users","vLastName","nUserId='".$userId."'");
                          $listName        = $this->_common->selectRow("product","Title","nBusId='".$listId."'");
                          $arrProfile =   array("nListId"=>$listId,
                                                "vUserFirstName"=>$txtUserFirstName,
                                                "vUserLastName"=>$txtUserLastName,
                                                "vAmount"=>$_GET['amt'],
                                                "vProductName"=>$listName,
                                                "vTransactionId"=>$transaction_id,
                                                "vPaymentStatus"=>'C',
                                                "vPaymentType"=>'L'
                                               );

                    
                            $paymentId =   $this->_common->addFields("payments",$arrProfile);
                            $arrProfile         =   array("nPaymentStatus"=>P);
                            $this->_common->updateFields("product",$arrProfile,"nBusId='".$listId."'");
                            $this->redirect('paypal/creditsuccess/1/L');
                            exit;
                          
                      }
                   }
                   //}

                }


            
        }
        
   public function creditsuccess($flag,$mode='')
     {
         if($flag==1)
         {
             $this->operationMode = $this->_common->selectResult("settings","settingfield,value","settingfield='operationMode'");
             if($mode=='L'){
                if($_SESSION['autoregister'] =='1'){
                    if($this->operationMode[0]->value == "paid") {
                        $this->_postads->sendUserEmail($_SESSION['nUserid'],$this->siteSettings['userApproval'],$this->siteSettings['adminEmail']);
                      //  $this->view->msg = 'Payment is successfull.Posting has been saved and is in pending status. Please activate your account through the activation e-mail. Thank You!';
                   }
                }
                else{
                    //$this->view->msg = 'Payment is successfull.Your posting has been saved ,waiting for the admin to approve!'; 
                }
             }
             if($this->siteSettings['userApproval']=='email' && $_SESSION['autoregister']=='1'){   
                        $this->view->msg = 'Posting has been saved and waiting for the admin approval. Please activate your account through the activation e-mail. Thank You!';
                        

                     }
                     elseif($this->siteSettings['userApproval']=='admin' && $_SESSION['autoregister']=='1'){ 
                        $this->view->msg = 'Payment is successfull,Posting has been saved ,waiting for the admin approval!';
                        
                     }elseif($this->siteSettings['userApproval']=='automatic' && $_SESSION['autoregister']=='1'){ 
                         $this->view->msg = 'Payment is successfull,Posting has been saved,You can Sign in to your account,Please check the mail for login credentials';
                         
                     }elseif($this->siteSettings['userApproval']=='email' && $_SESSION['autoregister']!='1'){   
                        $this->view->msg = 'Payment is successfull,Posting has been saved and waiting for the admin approval.Thank You!';
                        

                     }elseif($this->siteSettings['userApproval']=='admin' && $_SESSION['autoregister']!='1'){ 
                        $this->view->msg = 'Payment is successfull,Posting has been saved ,waiting for the admin approval!';
                       
                     }elseif($this->siteSettings['userApproval']=='automatic' && $_SESSION['autoregister']!='1'){ 
                         $this->view->msg = 'Payment is successfull,Your Posting has been submited';
                        
                     }
             if($this->operationMode[0]->value == "paid") {
                 $this->_postads->sendPostNotificationToAdmin($this->siteSettings['adminEmail']);
            }

         }
         else{
              $this->view->errorMsg = 'Payment failure';
         }

     }
	
	/*
	function to load the index template
	*/
    
    public function loadComments()
    {

         if((!$this->_session->get('user_id'))){
            $this->redirect("index");
            exit;
        }
        $userId =   $this->_session->get('user_id');
        $this->view->disableLayout();
        $id =    $this->get('id');
        $resComments    =    $this->_common->getDatas("PC.*,P.Title","productcomment AS PC","product AS P ON P.nBusId=PC.nProductId","LEFT JOIN","nId='".$id."' AND P.nUserId='".$userId."'","","","","1");
        $this->view->resComments=$resComments[0];
    }
    

		

}
?>