Location: PHPKode > projects > HikaShop > back/views/menus/view.html.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 MenusViewMenus extends JView{
	var $ctrl= 'menus';
	var $nameListing = 'MENUS';
	var $nameForm = 'MENU';
	var $icon = 'menu';
	function display($tpl = null,$params=null){
		$this->paramBase = HIKASHOP_COMPONENT.'.'.$this->getName();
		$function = $this->getLayout();
		if(method_exists($this,$function)) $this->$function($params);
		parent::display($tpl);
	}
	function _loadCategory(&$element){
		if(empty($element->hikashop_params['selectparentlisting'])){
			$db 	=& JFactory::getDBO();
			$query = 'SELECT category_id FROM '.hikashop::table('category').' WHERE category_type=\'root\' AND category_parent_id=0 LIMIT 1';
			$db->setQuery($query);
			$root = $db->loadResult();
			$query = 'SELECT category_id FROM '.hikashop::table('category').' WHERE category_type=\'product\' AND category_parent_id='.$root.' LIMIT 1';
			$db->setQuery($query);
			$element->hikashop_params['selectparentlisting'] = $db->loadResult();
		}
		if(!empty($element->hikashop_params['selectparentlisting'])){
			$class=hikashop::get('class.category');
			$element->category = $class->get($element->hikashop_params['selectparentlisting']);
		}
	}
	function _assignTypes(){
		$js = "
		function switchPanel(name,options,type){
			var len = options.length;
			for (var i = 0; i < len; i++){
				var el = document.getElementById(type+'_'+options[i]);
				if(el) el.style.display='none';
			}
			var el2 = document.getElementById(type+'_'+name);
			if(el2) el2.style.display='block';
		}
		function switchDisplay(value,name,activevalue){
			var el = document.getElementById(name);
			if(el){
				if(value==activevalue){
					el.style.display='';
				}else{
					el.style.display='none';
				}
			}
		}
		"; 
		$document=& JFactory::getDocument();
		$document->addScriptDeclaration($js);
		JHTML::_('behavior.modal');
		$colorType = hikashop::get('type.color');
		$this->assignRef('colorType',$colorType);
		$listType = hikashop::get('type.list');
		$this->assignRef('listType',$listType);
		$contentType = hikashop::get('type.content');
		$this->assignRef('contentType',$contentType);
		$layoutType = hikashop::get('type.layout');
		$this->assignRef('layoutType',$layoutType);
		$orderdirType = hikashop::get('type.orderdir');
		$this->assignRef('orderdirType',$orderdirType);
		$orderType = hikashop::get('type.order');
		$this->assignRef('orderType',$orderType);
		$itemType = hikashop::get('type.item');
		$this->assignRef('itemType',$itemType);
		$childdisplayType = hikashop::get('type.childdisplay');
		$this->assignRef('childdisplayType',$childdisplayType);
		$pricetaxType = hikashop::get('type.pricetax');
		$this->assignRef('pricetaxType',$pricetaxType);
		$priceDisplayType = hikashop::get('type.pricedisplay');
		$this->assignRef('priceDisplayType',$priceDisplayType);
		$discountDisplayType = hikashop::get('type.discount_display');
		$this->assignRef('discountDisplayType',$discountDisplayType);
		JToolBarHelper::divider();
		JToolBarHelper::save();
		JToolBarHelper::apply();
		JToolBarHelper::cancel();
		JToolBarHelper::divider();
		$bar = & JToolBar::getInstance('toolbar');
		$bar->appendButton( 'Pophelp',$this->ctrl.'-form');
	}
	function form(){
		$cid = hikashop::getCID('id');
		if(empty($cid)){
			$element = null;
			$config = hikashop::config();
			$element->hikashop_params = $config->get('default_params');
			$task='add';
			$control = 'config[menu_0]';
			$element->hikashop_params['link_to_product_page'] = '1';
		}else{
			$modulesClass = hikashop::get('class.menus');
			$element = $modulesClass->get($cid);
			$task='edit';
			$config = hikashop::config();
			$control = 'config[menu_'.$cid.']';
			if(strpos($element->link,'view=product')!==false){
				$element->hikashop_params['content_type'] = 'product';
			}else{
				$element->hikashop_params['content_type'] = 'category';
			}
			$element->content_type = $element->hikashop_params['content_type'];
			if(!isset($element->hikashop_params['link_to_product_page'])){
				$element->hikashop_params['link_to_product_page'] = '1';
			}
		}
		hikashop::setTitle(JText::_($this->nameForm),$this->icon,$this->ctrl.'&task='.$task.'&cid[]='.$cid);
		$this->_loadCategory($element);
		$bar = & JToolBar::getInstance('toolbar');
		if(!empty($cid)){
			if(version_compare(JVERSION,'1.6','<')){
				$bar->appendButton( 'Link', 'upload', JText::_('JOOMLA_MENU_OPTIONS'), JRoute::_('index.php?option=com_menus&task=edit&cid[]='.$element->id) );
			}else{
				$bar->appendButton( 'Link', 'upload', JText::_('JOOMLA_MENU_OPTIONS'), JRoute::_('index.php?option=com_menus&task=item.edit&id='.$element->id) );
			}
		}
		$this->assignRef('element',$element);
		$this->assignRef('control',$control);
		$this->_assignTypes();
	}
	function listing(){
		$app =& JFactory::getApplication();
		$pageInfo = null;
		$pageInfo->search = $app->getUserStateFromRequest( $this->paramBase.".search", 'search', '', 'string' );
		$pageInfo->filter->order->value = $app->getUserStateFromRequest( $this->paramBase.".filter_order", 'filter_order',	'id','cmd' );
		$pageInfo->filter->order->dir	= $app->getUserStateFromRequest( $this->paramBase.".filter_order_Dir", 'filter_order_Dir',	'desc',	'word' );
		$database	=& JFactory::getDBO();
		if(version_compare(JVERSION,'1.6','<')){
			$query = 'SELECT id FROM '.hikashop::table('components',false).' WHERE link=\'option='.HIKASHOP_COMPONENT.'\' LIMIT 1';
			$database->setQuery($query);
			$filters = array('(componentid='.$database->loadResult().' OR (componentid=0 AND link LIKE \'%option='.HIKASHOP_COMPONENT.'%\'))','type=\'component\'');
			$searchMap = array('alias','link','name');
		}else{
			$query = 'SELECT extension_id FROM '.hikashop::table('extensions',false).' WHERE type=\'component\' AND element=\''.HIKASHOP_COMPONENT.'\' LIMIT 1';
			$database->setQuery($query);
			$filters = array('(component_id='.$database->loadResult().' OR (component_id=0 AND link LIKE \'%option='.HIKASHOP_COMPONENT.'%\'))','type=\'component\'','client_id=0');
			$searchMap = array('alias','link','title');
		}
		$filters[] = 'published>-2';
		if(!empty($pageInfo->search)){
			$searchVal = '\'%'.$database->getEscaped(JString::strtolower( $pageInfo->search ),true).'%\'';
			$filters[] =  implode(" LIKE $searchVal OR ",$searchMap)." LIKE $searchVal";
		}
		$order = '';
		if(!empty($pageInfo->filter->order->value)){
			$order = ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
		}
		if(!empty($filters)){
			$filters = ' WHERE '. implode(' AND ',$filters);
		}else{
			$filters = '';
		}
		$query = ' FROM '.hikashop::table('menu',false).' '.$filters.$order;
		$database->setQuery('SELECT *'.$query);
		$rows = $database->loadObjectList();
		if(!empty($pageInfo->search)){
			$rows = hikashop::search($pageInfo->search,$rows,'id');
		}
		$database->setQuery('SELECT COUNT(*)'.$query);
		$pageInfo->elements->total = $database->loadResult();
		$pageInfo->elements->page = count($rows);
		$toggleClass = hikashop::get('helper.toggle');
		$this->assignRef('toggleClass',$toggleClass);
		$config =& hikashop::config();
		$unset=array();
		foreach($rows as $k => $row){
			if(strpos($row->link,'view=product')!==false  && strpos($row->link,'layout=show')===false){
				$rows[$k]->hikashop_params = $config->get('menu_'.$row->id);
				$rows[$k]->hikashop_params['content_type'] = 'product';
			}elseif(strpos($row->link,'view=category')!==false || strpos($row->link,'view=')===false){
				$rows[$k]->hikashop_params = $config->get('menu_'.$row->id);
				$rows[$k]->hikashop_params['content_type'] = 'category';
			}else{ 
				$unset[]=$k;
				continue;
			}
			if(empty($rows[$k]->hikashop_params)){
				$rows[$k]->hikashop_params = $config->get('default_params');
			}
			$rows[$k]->content_type = $rows[$k]->hikashop_params['content_type'];
		}
		foreach($unset as $u){
			unset($rows[$u]);
		}
		$this->assignRef('rows',$rows);
		$this->assignRef('pageInfo',$pageInfo);
		hikashop::setTitle(JText::_($this->nameListing),$this->icon,$this->ctrl);
		$bar = & JToolBar::getInstance('toolbar');
		JToolBarHelper::addNew();
		JToolBarHelper::editList();
		JToolBarHelper::deleteList(JText::_('HIKA_VALIDDELETEITEMS'));
		JToolBarHelper::divider();
		$bar->appendButton( 'Pophelp',$this->ctrl.'-listing');
		$bar->appendButton( 'Link', 'hikashop', JText::_('HIKASHOP_CPANEL'), hikashop::completeLink('dashboard') );
	}
}
Return current item: HikaShop