<?php

class line_menu extends module {
	
	var $templ = "menu.htm";
	var $_loc_vars = array( 'templ', 'root', 'noexit'  );
	var $obj;

	function _on_() {
		global $R, $core_db, $cat;
		$tpl = $R->getTpl( $this->templ, 'body' );
		$tpli = $R->getTpl( $this->templ, 'item' );
		$tplis = $R->getTpl( $this->templ, 'item_sel' );
		$tplsep = $R->getTpl( $this->templ, 'sep' );
		if (!$this->root ) $this->root = $cat->cat;
		$this->obj = new cobject(__REAL_CAT_OBJ_);
		
		$sql_where = '';
		if ($this->noexit) {
			$sql_where = ' AND id not in (18) ';
			global $auth;	
 			if ($auth->is_login) {
		    	$tpl = $R->set('current_user_name', $auth->user_obj->assign('{name}'), $tpl);
	    	}
		}

		$tpl = $R->set('root', 'root'.crc32($this->root), $tpl);
		
		$db2 = $core_db->q( $this->obj->getSelect(' AND `cat_id` = "'.db_escape_string($this->root).'"') );
		if ($db2->nr() ) {
			$this->obj->lRow($db2);
			$tpl = $this->obj->assign($tpl);	
		}

		$db2 = $core_db->q( $this->obj->getSelect( ' AND `parent_cat` = "' . $this->root .  '" AND `_sys_unvisible` = "0" '.$sql_where.' ORDER BY `_sys_order`') );
		$first = true;
		while ( $db2->r() ) {
			$this->obj->lRow( $db2 );
			if ( !in_array($db2->f('cat_id'), $cat->path) ) {
				$tt = $this->obj->assign( $tpli );
			} else {
				$tt = $this->obj->assign( $tplis );
			}
			if ( $first ) $first = false;
			 else 
			$tpl = $R->parse( 'menu_item', $tplsep, $tpl );
			
			$tpl = $R->parse( 'menu_item', $tt, $tpl );
		}
		
		return $R->clear( $tpl );
	}
	

}	

?>