<?php
/***************************************************************************
 *                                                                          *
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.   *
 *                                                                          *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.                                                    *
 *                                                                          *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
 ****************************************************************************/
//
//$Id: OtpCountryController, v 1.0 2019/05/27 11:32:09
//
class OtpcountryController extends Controller {
        public function indexAction()    {
                $ObjOtpCountry    	= 	new OtpCountryModel();
                $languageIDs		= 	$this->ObjView->languageIDs;		
                $link	=	'otpcountry/index/';
                if (isset($_POST['search'])){			
                        if (isset($_POST['countryCode']) && $_POST['countryCode'] != ""){
                                $link .= "countryCode/" . $this->encodeUrlString($_POST['countryCode']) . "/";
                        }			
                        if (isset($_POST['countryName']) && $_POST['countryName'] != ""){
                                $link .= "countryName/" . $this->encodeUrlString($_POST['countryName']) . "/";
                        }
                        $this->setRedirect($link);
                }
                else{
                        $sortby		=	$this->getRequestValue("sortby");
                        $orderby	=	($this->getRequestValue("orderby")=="")?"asc":$this->getRequestValue("orderby");
                $countryCode='';			
                        if($this->getRequestValue('countryCode')){
                                $countryCode		= 	$this->decodeUrlString($this->getRequestValue('countryCode'));
                                $link.="countryCode/".$this->encodeUrlString($countryCode). "/";
                        }$countryName='';			
                        if($this->getRequestValue('countryName')){
                                $countryName		= 	$this->decodeUrlString($this->getRequestValue('countryName'));
                                $link.="countryName/".$this->encodeUrlString($countryName). "/";
                        }	
                }		
                if (isset($_POST['select_status'])){
                        $params=array(
                                'status'=>$_POST['select_status'],
                                'countryCodeIDs'=>$_POST['countryCodeID']
                        );
                        $ObjOtpCountry->changeStatus($params);
                        $this->setMessage('language.lblOtpCountrystatusUpdatedSuccess','success');
                        $this->setRedirect($link);
                }
                list($limitFrom, $limitTo) = $this->getPageSettings($key = 'page', $rows = 10); 

                $params =array(
                        'limitFrom'=>$limitFrom,
                        'limitTo'=>$limitTo,
                        'languageIDs'=>$languageIDs,
                        'sortby'=>$sortby,
                        'orderby'=>$orderby,
                        'countryCode'=>$countryCode ,'countryName'=>$countryName 
                );
                $listOtpCountry    = $ObjOtpCountry->listOtpCountry($params);	

                $resPagesCount = $this->setPagesCount($key = 'page');
                $this->ObjView->assign("page", $page);	
                $this->ObjView->assign("sortby", $sortby); $this->ObjView->assign("orderby", ($orderby=="asc")?'desc':'asc'); $this->ObjView->assign("countryCode", $countryCode); $this->ObjView->assign("countryName", $countryName);
                $this->ObjView->assign('listOtpCountry', $listOtpCountry);	

                $editPrivilege	=	$this->ObjCommon->hasPrivilege('otpcountry/edit/');
                $this->ObjView->assign("editPrivilege", $editPrivilege);
                $deletePrivilege	=	$this->ObjCommon->hasPrivilege('otpcountry/destroy/');
                $this->ObjView->assign("deletePrivilege", $deletePrivilege);

                $this->ObjView->assign("link", $link);
                $this->ObjView->display('OtpCountryList.tpl');
        }




        public function newAction()    {
                $ObjOtpCountry    	= 	new OtpCountryModel();
                $languageIDs        = $this->ObjView->languageIDs;
                if($this->ObjForm->isValid('formOtpCountry','submitOtpCountry')){
                        $ObjOtpCountry->insert($languageIDs);
                        $this->setMessage('language.lblOtpCountryaddSuccess','success');
                        $this->setRedirect('otpcountry/index/');
                } 
                $this->ObjView->display('OtpCountryAdd.tpl');
        }

        public function editAction()    {
                $countryCodeID =   $this->getRequestValue('id');
                $ObjOtpCountry    	= 	new OtpCountryModel();
                $languageIDs        = 	$this->ObjView->languageIDs;
                $params=array(
                        'countryCodeID'=>$countryCodeID,
                        'languageIDs'=>$languageIDs
                );
                $getOtpCountry	= $ObjOtpCountry->getOtpCountry($params);
                if(empty($getOtpCountry)){
                         $this->setRedirect('otpcountry');
                }


                if($this->ObjForm->isValid('formOtpCountry','submitOtpCountry')){


                        $ObjOtpCountry->insert($languageIDs,$countryCodeID);
                        $this->setMessage('language.lblOtpCountryupdatedSuccess','success');
                        $this->setRedirect('otpcountry/index/');

                } 
                $this->ObjView->assignValues($getOtpCountry);
                $this->ObjView->assign('countryCodeID', $countryCodeID);
                $this->ObjView->display('OtpCountryAdd.tpl');

        }

        public function viewAction()    {
                $countryCodeID  =   $this->getRequestValue('id');
                $ObjOtpCountry    	= 	new OtpCountryModel();
                $languageIDs        = $this->ObjView->languageIDs;
                $params=array(
                        'countryCodeID'=>$countryCodeID,
                        'languageIDs'=>$languageIDs
                );
                $getOtpCountry	= $ObjOtpCountry->getOtpCountry($params);
                if(empty($getOtpCountry)){
                         $this->setRedirect('otpcountry/index/');
                }
                $this->ObjView->assign('getOtpCountry', $getOtpCountry);
                $this->ObjView->assign('countryCodeID', $countryCodeID);
                $editPrivilege	=	$this->ObjCommon->hasPrivilege('otpcountry/edit/');
                $this->ObjView->assign("editPrivilege", $editPrivilege);
                $this->ObjView->assign("previousURl", $this->getPreviousURL());
                $this->ObjView->display('OtpCountryView.tpl');

        }

        public function ajaxstatusAction()    {
                $countryCodeID 	=   $this->getRequestValue('id');
                $status					  	=   $this->getRequestValue('status');
                $ObjOtpCountry    	= 	new OtpCountryModel();
                $params=array(
                        'status'=>$status,
                        'countryCodeIDs'=>array($countryCodeID)
                );
                $changeStatus = $ObjOtpCountry->changeStatus($params);
                $this->setMessage('language.lblOtpCountrystatusUpdatedSuccess','success');

        }

        public function destroyAction()    {
                $countryCodeID  =   $this->getRequestValue('id');
                if(isset($countryCodeID)){
                        $ObjOtpCountry    	= 	new OtpCountryModel();
                        $params=array(
                                'status'=>'D',
                                'countryCodeIDs'=>array($countryCodeID)
                        );
                        $changeStatus = $ObjOtpCountry->changeStatus($params);
                        $this->setMessage('language.lblOtpCountrydeletedSuccess','success');
                        $this->setRedirect('otpcountry/index/');

                }
        }
}
