<?php

class LeftMenuView extends Slot {

	var $ModuleID = 1;
	var $SectionID = 2;
	var $color;

	function __construct($pquery) {
		parent::__construct($pquery);
	}

	function init() {   return;
		global $REGISTRY;
		$this->category = $this->Db->SelectGuide(array('category c','color g'),array('c.id','g.value as name'),array('c.color::int' => 'g.id'));
		$this->Action->processEvent($this->SectionID,'get_menu',array('id' => 94),$this);
	}

	function fillElements() {  return;
		$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID,'get_menu');
		$this->setTargetArray($this->PreparedTemplates,0);
//printArray($this->PreparedTemplates);
	}

	function setTargetArray($array = array(),$level = 1,$subitems = array()) {
		global $REGISTRY;
		$i = 0;
//printArray($this->category);
		foreach($array as $key => $value) {
			foreach($REGISTRY['VirtualSlotTarget']['main'] as $path => $handler) {
				if(strval($path)==$value['path']) {
					$query = explode('?',$handler);
					$target = explode(':',array_shift($query));
					$properties = array_shift($query);
					$pair = explode('=',$properties);
					$name = array_shift($target);
//					if($name=='StoreView') $this->color = $this->category[$pair[1]];
				}
			}
			if(empty($REGISTRY['Request']['RawTarget'])) {
				$real_path = array(0 => '');
				$raw_target = '/';
			}
			else {
				$real_path = explode('/',$REGISTRY['Request']['RawTarget']);
				$raw_target = $REGISTRY['Request']['RawTarget'];
			}
			$curr_path = explode('/',$value['path']);
			if(count($curr_path) > count($real_path)) $pos = strpos($value['path'],$raw_target);
			else $pos = strpos($raw_target,$value['path']);
			if(!empty($REGISTRY['Page']['color']) && $this->color==$REGISTRY['Page']['color']) $pos = 0;
			if(empty($this->color) && !empty($REGISTRY['Page']['color'])) $this->color = $REGISTRY['Page']['color'];
			$this->TempFillEls['items'][$key] = array(
				'id' => $key,
				'url' => $value['path']=='/'.implode('/',$this->LocalTarget)? 'javascript:;' : $value['path'],
				'title' => strip_tags(trim($value['label'])),
				'parent' => !$level? array(array('color' => $this->color,'name' => trim($value['label']))) : array(),
				'inner' => !$level? array() : array(array('name' => trim($value['label']))),
			);
			if(!empty($value['subcat']) && strval($pos)=='0') $this->setTargetArray($value['subcat'],$level+1);
			$i++;
		}
	}
}
?>