<?php

class StoreRSSView extends Slot {

	var $SectionID = 25;
	var $ModuleID = 2;

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

	function init() {
		if(!empty($this->ID)) {
			$this->Action->processEvent($this->SectionID,'open_chart',array('parent' => $this->ID),$this);
			if(!empty($this->PreparedTemplates['_error'])) header('Location: '.$this->Home.$this->SID);
		}
		else header('Location: '.$this->Home.$this->SID);
		$this->PreparedTemplates = $this->Action->getTemplate($this->SectionID, 'open_chart');
	}

	function fillElements() {
		header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate, post-check=0, pre-check=0, max-age=0",true);
		header("Pragma: no-cache",true);
		header("Content-type: text/xml");
		$this->TempFillEls['pubdate'] = gmdate("D, d M Y H:i:s").' GMT';
		$this->TempFillEls['channel'] = $this->PreparedTemplates['parent']['name'];
		$this->TempFillEls['item'] = $this->makeItems();
	}

	function makeItems($items = array()) {
		foreach($this->PreparedTemplates as $key => $value) {
			switch($key) {
				case 'parent':
					if(!empty($value['categorylineitems'])) {
						foreach($value['categorylineitems'] as $id => $item) {
							$items[$item['item']['id']] = array(
								'title' => !empty($item['item']['nav_name'])? $item['item']['nav_name'] : $item['item']['name'],
								'desc' => htmlspecialchars(strip_tags($item['item']['full_desc'])),
								'link' => $value['cat_type']==1? '/units/accessoriesandkits#'.$item['item']['id'] : $item['item']['url'],
								'pubdate' => gmdate("D, d M Y H:i:s").' GMT',
								'category' => $value['name'],
							);
						}
					}
				break;
				default:
					if(!empty($value['subcat'])) {
						foreach($value['subcat'] as $k => $v) {
							if(!empty($v['categorylineitems'])) {
								foreach($v['categorylineitems'] as $id => $item) {
									$items[$item['item']['id']] = array(
										'title' => !empty($item['item']['nav_name'])? $item['item']['nav_name'] : $item['item']['name'],
										'desc' => htmlspecialchars(strip_tags($item['item']['full_desc'])),
										'link' => $v['cat_type']==1? '/units/accessoriesandkits#'.$item['item']['id'] : $item['item']['url'],
										'pubdate' => gmdate("D, d M Y H:i:s").' GMT',
										'category' => $value['name'],
									);
								}
							}
						}
					}
					else {
						if(!empty($value['categorylineitems'])) {
							foreach($value['categorylineitems'] as $id => $item) {
								$items[$item['item']['id']] = array(
									'title' => !empty($item['item']['nav_name'])? $item['item']['nav_name'] : $item['item']['name'],
									'desc' => htmlspecialchars(strip_tags($item['item']['full_desc'])),
									'link' => $value['cat_type']==1? '/units/accessoriesandkits#'.$item['item']['id'] : $item['item']['url'],
									'pubdate' => gmdate("D, d M Y H:i:s").' GMT',
									'category' => $value['name'],
								);
							}
						}
					}
				break;
			}
		}
		$this->PreparedTemplates = $this->Action->clearTemplate($this->SectionID,'open_chart');
		return $items;
	}
}
?>