Location: PHPKode > projects > HikaShop > back/classes/menus.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 hikashopMenusClass extends hikashopClass{
	var $pkeys=array('id');
	var $toggle = array('published'=>'id');
	function getTable(){
		return hikashop::table('menu',false);
	}
	function get($id){
		$obj = parent::get($id);
		$config =& hikashop::config();
		if(!empty($obj->id)){
			$obj->hikashop_params = $config->get('menu_'.$obj->id,null);
		}
		if(empty($obj->hikashop_params)){
			$obj->hikashop_params = $config->get('default_params',null);
		}
		$this->_loadParams($obj);
		return $obj;
	}
	function _loadParams(&$result){
		if(!empty($result->params)){
			$lines = explode("\n",$result->params);
			$result->params = array();
			foreach($lines as $line){
				$param = explode('=',$line,2);
				if(count($param)==2){
					$result->params[$param[0]]=$param[1];
				}
			}
		}
	}
	function saveForm(){
		$module = null;
		$formData = JRequest::getVar( 'menu', array(), '', 'array' );
		if(!empty($formData)){
			foreach($formData as $column => $value){
				hikashop::secureField($column);
				if(is_array($value)){
					$module->$column=array();
					foreach($value as $k2 => $v2){
						hikashop::secureField($k2);
						$module->{$column}[$k2] = strip_tags($v2);
					}
				}else{
					$module->$column = strip_tags($value);
				}
			}
			if($module->content_type=='category'){
				$module->link='index.php?option=com_hikashop&view=category&layout=listing';
			}else{
				$module->link='index.php?option=com_hikashop&view=product&layout=listing';
			}
			$content_type = $module->content_type;
			unset($module->content_type);
		}
		$new = false;
		if(empty($module->id)){
			$new = true;
			if(empty($module->alias)){
				if(version_compare(JVERSION,'1.6','<')){
					$module->alias = $module->name;
				}else{
					$module->alias = $module->title;
				}
				$module->alias = preg_replace('#[^a-z_-0-9]#i','',$module->alias);
			}
		}
		$result = $this->save($module);
		if($result){
			$element = array();
			$formData = JRequest::getVar( 'config', array(), '', 'array' );
			$params_name = 'menu_'.(int)$module->id;
			if($new){
				$post_name = 'menu_0';
			}else{
				$post_name = $params_name;
			}
			if(!empty($formData[$post_name])){
				foreach($formData[$post_name] as $column => $value){
					hikashop::secureField($column);
					$element[$column] = strip_tags($value);
				}
				if(empty($element['selectparentlisting'])){
					$cat = hikashop::get('class.category');
					$mainProductCategory = 'product';
					$cat->getMainElement($mainProductCategory);
					$element['selectparentlisting']=$mainProductCategory;
				}
			}
			$element['content_type']=$content_type;	
			if($element['content_type']=='category' && empty($element['modules'])){
				$app =& JFactory::getApplication();
				$app->enqueueMessage(JText::_('MENU_WITHOUT_ASSOCIATED_MODULE'));
				$app->enqueueMessage(JText::_('ASSOCIATED_MODULE_NEEDED'));
				$app->enqueueMessage(JText::sprintf('ADD_MODULE_AUTO',hikashop::completeLink('menus&task=add_module&cid='.(int)$module->id.'&'.JUtility::getToken().'=1')));
			}
			$configClass = hikashop::config();
			$config=null;
			$config->$params_name = $element;
			if($configClass->save($config)){
				$configClass->set($params_name,$element);
			}
		}
		return $result;
	}
	function save(&$element){
		if(version_compare(JVERSION,'1.6','<')){
			$query="SELECT a.id FROM ".hikashop::table('components',false).' AS a WHERE a.option=\''.HIKASHOP_COMPONENT.'\'';
			$this->database->setQuery($query);
			$element->componentid = $this->database->loadResult();
		}else{
			$query="SELECT a.extension_id FROM ".hikashop::table('extensions',false).' AS a WHERE a.type=\'component\' AND a.element=\''.HIKASHOP_COMPONENT.'\'';
			$this->database->setQuery($query);
			$element->component_id = $this->database->loadResult();
		}
		if(empty($element->id)){
			$element->params['show_page_title']=1;
		}
		if(!empty($element->params)&&is_array($element->params)){
			$params = '';
			foreach($element->params as $k => $v){
				$params.=$k.'='.$v."\n";
			}
			$element->params = rtrim($params,"\n");
		}
		$element->id = parent::save($element);
		return $element->id;
	}
	function delete(&$elements){
		$result = parent::delete($elements);
		if($result){
			if(!is_array($elements)){
				$elements=array($elements);
			}
			if(!empty($elements)){
				$ids = array();
				foreach($elements as $id){
					$ids[]=$this->database->Quote('menu_'.(int)$id);
				}
				$query = 'DELETE FROM '.hikashop::table('config').' WHERE config_namekey IN ('.implode(',',$ids).');';
				$this->database->setQuery($query);
				return $this->database->query();
			}
		}
		return $result;
	}
}
Return current item: HikaShop