<?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>             		  |



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



App::import('Sanitize');



class HelpsController extends AppController



{



    var $name = "Help";



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



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



	var $uses = array('Help'); 



	var $paginate = array('limit' => 25,'order' => array('Help.type' => 'asc'));



    function index()



    {



       $this->__validateLoginStatus();


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



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



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



			exit();



		}



		$criteria="";



		$cmbSearchType	=	"";



		$txtSearch		=	"";



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

			$cmbSearchType	=	$_GET["cmbSearchType"];

			$txtSearch		=	$_GET["txtSearch"];

			if($cmbSearchType == "title"){

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

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

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

			}

		}

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

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

		{

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

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

			if($cmbSearchType == "title"){

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

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

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

			}

		}

		else{



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



		}



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



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

		

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

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



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



		$this->layout = 'adm';



    } 



	



   function beforeFilter()



    {



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



        {  



             $this->Setting->load();  



        } 



		global $sitefolder; 



		global $meta_description;



		global $meta_keywords;



		global $page_title;



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



		$sitefolder			=	$cnfg["sitebasefolder"];



		$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->set('sitefolder', $sitefolder);

		$httpHost	=	$_SERVER['HTTP_HOST'];

		$this->set('sitebase','http://'.$httpHost);

    }



	function beforeRender()



    {



        



    }



    function __validateLoginStatus()



    {



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



            {



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



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



            }



    }  



	function add() {


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



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



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



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



			exit();



		}



		if (!empty($this->data)) {	



			$pdt = $this->Help->findByTitle($this->data["Help"]["title"]);



            if (!empty($pdt['Help']['id'])){



				$this->Session->setFlash(__('The Page Title Already Exist!', true));



				$this->redirect(array('controller'=>'helps','action'=>'add'));



				exit;



			}else{

			     

						 if(trim($this->data["Help"]["content"]) == '' && trim($this->data["Help"]["title"]) == '')

						 {

						    $this->Session->setFlash(__('Page title and content cannot be empty!', true));

						 }

						 else if(trim($this->data["Help"]["title"]) == '')

						 {

						   $this->Session->setFlash(__('Page title  cannot be empty!', true));

						 }

						 else if(trim($this->data["Help"]["content"]) == '')

						 {

						   $this->Session->setFlash(__('Page content cannot be empty!', true));

						 

						 }

						 else  if ($this->Help->save($this->data))

						  {

		

							$this->Session->setFlash(__('Help data added Successfully!', true));

		

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

		

							exit;

		     			 }

				}

				



			}



		



		$this->layout = 'adm';



	}



	function edit($id=0) {

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

		if($id == 0){



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



			exit();



		}



		$this->__validateLoginStatus();



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



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



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



			exit();



		}



		$this->Help->id = $id; 



		if (!empty($this->data)) {



			$pdt = $this->Help->findByTitle($this->data["Help"]["title"]);



            if (!empty($pdt['Help']['id']) && $pdt['Help']['id'] <> $id){



				$this->Session->setFlash(__('The Page Title Already Exist!', true));



				$this->data = $this->Help->read(); 



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



			}else{

			            if(trim($this->data["Help"]["content"]) == '' && trim($this->data["Help"]["title"]) == '')

						 {

						    $this->Session->setFlash(__('Page title and content cannot be empty!', true));

						 }

						 else if(trim($this->data["Help"]["title"]) == '')

						 {

						   $this->Session->setFlash(__('Page title  cannot be empty!', true));

						 }

						 else if(trim($this->data["Help"]["content"]) == '')

						 {

						   $this->Session->setFlash(__('Page content cannot be empty!', true));

						 

						 }



				         else if ($this->Help->save($this->data)) {



					     $this->Session->setFlash(__('Help data Edited Successfully!', '/Help'));



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



					    exit;

						



				        }



				$this->data = $this->Help->read(); 



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



			}



		}else{



			$this->data = $this->Help->read(); 



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



		}



		$this->layout = 'adm';



	} 



	function delete($id){



		$this->__validateLoginStatus();



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



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



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



			exit();



		}



		$this->Help->del($id,true);



		 $this->Session->setFlash(__('Help data Removed from Database!', '/helps'));



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



		exit;



	} 	



	



	function adminHelp($id=0) 



	{


$cnfg 				=	Configure::read('Neutrino');
        $style				=	$cnfg["style"];
        $this->set('style', "admin/".$style);
		 $data = $this->Help->find('list', array('conditions' => array('Help.type' => 'A'),'order' => array('Help.Order ASC')));						



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



		 $dfltid = $id; 



		 if(!empty($data) && $dfltid == 0)



		 {



		  $dfltid=$this->Help->getMinid('A');	



		 }



		$helpdata= $this->Help->findById($dfltid); 



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



	    $this->layout = 'adminhelp';



	}



	



	function userHelp($id=0) 



	{



		 $data = $this->Help->find('list', array('conditions' => array('Help.type' => 'U')));						



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



		 $dfltid = $id; 



		 if(!empty($data) && $dfltid == 0)



		 {



		  $dfltid=$this->Help->getMinid('U');	



		 }



		$helpdata= $this->Help->findById($dfltid); 



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



	    $this->layout = 'userhelp';



	}	



}



?>