Location: PHPKode > projects > HikaShop > back/controllers/toggle.php
<?php
/**
 * @package		HikaShop for Joomla!
 * @version		1.4.3
 * @author		hikashop.com
 * @copyright	(C) 2010 HIKARI SOFTWARE. All rights reserved.
 * @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php
class ToggleController extends JController{
	function __construct($config = array())
	{
		parent::__construct($config);
		$this->registerDefaultTask('toggle');
		header( 'Cache-Control: no-store, no-cache, must-revalidate' );
		header( 'Cache-Control: post-check=0, pre-check=0', false );
		header( 'Pragma: no-cache' );
	}
	function toggle(){
		$completeTask = JRequest::getCmd('task');
		$task = substr($completeTask,0,strrpos($completeTask,'-'));
		$elementPkey = substr($completeTask,strrpos($completeTask,'-') +1);
		$value =  JRequest::getVar('value','','','cmd');
		$controllerName =  JRequest::getVar('table','','','word');
		$controller = hikashop::get('controller.'.$controllerName);
		if(empty($controller)){
			echo 'No controller';
			exit;
		}
		if(!$controller->authorize('toggle')){
			echo 'Forbidden';
			exit;
		}
		$function = $controllerName.$task;
		if(method_exists($this,$function)){
			$this->$function($elementId,$value);
		}else{
			$class = hikashop::get('class.'.$controllerName);
			if(empty($class->toggle[$task])){
				echo 'Forbidden';
				exit;
			}
			if(method_exists($class,'getTable')){
				$table = $class->getTable();
			}else{
				$table = hikashop::table($controllerName);
			}
			$db	=& JFactory::getDBO();
			$db->setQuery('UPDATE '.$table.' SET '.$task.' = '.$db->Quote($value).' WHERE '.$class->toggle[$task].' = '.$db->Quote($elementPkey).' LIMIT 1');
			$db->query();
		}
		$toggleClass = hikashop::get('helper.toggle');
		$extra = JRequest::getVar('extra',array(),'','array');
		if(!empty($extra)){
			foreach($extra as $key => $val){
				$extra[$key] = urldecode($val);
			}
		}
		echo $toggleClass->toggle(JRequest::getCmd('task',''),$value,$controllerName,$extra);
		exit;
	}
	function delete(){
		list($value1,$value2) = explode('-',JRequest::getCmd('value'));
		$table =  JRequest::getVar('table','','','word');
		$controller = hikashop::get('controller.'.$table);
		if(empty($controller)){
			echo 'No controller';
			exit;
		}
		if(!$controller->authorize('delete')){
			echo 'Forbidden';
			exit;
		}
		$function = 'delete'.$table;
		if(method_exists($this,$function)){
			$this->$function($value1,$value2);
			exit;
		}
		$class = hikashop::get('class.'.$table);
		list($key1,$key2) = reset($class->deleteToggle);
		$table = key($class->deleteToggle);
		if(empty($key1) OR empty($key2) OR empty($value1) OR empty($value2)){
			echo 'No value';
			exit;
		}
		$db	=& JFactory::getDBO();
		$db->setQuery('DELETE FROM '.hikashop::table($table).' WHERE '.$key1.' = '.$db->Quote($value1).' AND '.$key2.' = '.$db->Quote($value2));
		$db->query();
		exit;
	}
	function deleteconfig($namekey,$val){
		$config = hikashop::config();
		$newConfig = null;
		$newConfig->$namekey = $val;
		$config->save($newConfig);
	}
}
Return current item: HikaShop