<?php

class ContentSearchView extends Slot {

	var $ModuleID = 1;
	var $SectionID = 2;
	var $search = '';
	var $log = array();
	var $qty = array(
		'5' => '5',
		'10' => '10',
		'15' => '15',
		'20' => '20',
		'25' => '25',
		'30' => '30',
		'40' => '40',
		'50' => '50',
		'60' => '60',
		'70' => '70',
		'80' => '80',
		'90' => '90',
		'100' => '100',
	);
	var $selected_qty = 10;

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

	function init() {
		global $TOOLS_PATH, $REGISTRY;
		$this->type_search='or';
		if(!empty($this->Request) && !empty($this->Request['search_string'])) {
			header("Location: ".$this->Home.'/Registar/ContentSearch/'.preg_replace('~\.~','&dot;',preg_replace('~%2F~','^',urlencode($this->Request['search_string']))).'/'.$this->Request['type_search'].(!empty($this->Request['qty'])? '/'.$this->Request['qty'] : '').$this->SID);
		}
		elseif(!empty($this->LocalTarget[0])) {
			$this->search = urldecode(preg_replace('~&dot;~','.',preg_replace('~\^~','/',$this->LocalTarget[0])));
			if(isset($this->LocalTarget[1])){
				if($this->LocalTarget[1]=='or'||$this->LocalTarget[1]=='and'||$this->LocalTarget[1]=='phrase'||$this->LocalTarget[1]=='url'||$this->LocalTarget[1]=='id')
					$this->type_search=$this->LocalTarget[1];
			}
			else $this->LocalTarget[1]=$this->type_search;
			if(!empty($this->LocalTarget[2]) && in_array($this->LocalTarget[2],$this->qty)) $this->selected_qty = $this->LocalTarget[2];
			include($TOOLS_PATH.'/search.php');
			$curPageNumber = isset($this->LocalTarget[3])? $this->LocalTarget[3]+1 : 1;
			$this->log = site_search($this->search,$this,$this->Home.'/Registar/ContentSearch/'.$this->LocalTarget[0].'/'.$this->type_search.'/'.$this->selected_qty,$curPageNumber,$this->type_search,$this->selected_qty);
		}
		$this->Scheme = 'default';
		$this->setSchemeTemplate($this->Scheme);
	}

	function fillElements() {
		$this->TempFillEls['search_string'] = inputText('search_string',(@preg_replace('~\^~','/',$this->search)),50,'style="width:160px;"');
		empty($this->log['result']) and $this->log['result'] = array();
		foreach($this->log['result'] as $key => $value) {
			$this->TempFillEls['log'][] = array(
				'key' => $key+1,
				'value' => $value,
			);
		}
		switch($this->type_search){
			case 'or': $this->TempFillEls['checkedOr']='checked';break;
			case 'and': $this->TempFillEls['checkedAnd']='checked';  break;
			case 'phrase':$this->TempFillEls['checkedPhrase']='checked'; break;
			case 'url':$this->TempFillEls['checkedUrl']='checked'; break;
			case 'id':$this->TempFillEls['checkedId']='checked'; break;
			default :$this->TempFillEls['checkedOr']='checked'; break;
		}
		$this->TempFillEls['qty'] = inputSelect('qty',$this->qty,$this->selected_qty);
	}
}
?>