<?
$CLS='wyroznia_nas';
class wyroznia_nas
{
	function init() {
		global $X;

		$X->NAVI[] 					= $X->ADMIN->module_name();
		$this->TABLE_KATEGORIE	= 'wyroznia_nas';

		$this->TABLE=$this->TABLE_KATEGORIE;
		$this->PARENT_DEPTH = 1;
		$X->ADMIN->tree_path($this);

		switch($_GET['action']) {
			default:	 			return $this->_list(); 		break;
			case 'form':		return $this->_form();		break;
			case 'save':		return $this->_save();		break;
			case 'delete':		return $this->_delete();	break;
			case 'batch':		return $this->_batch();		break;
		}
	}


	function _list() {
		global $X;
		$this->TABLE=$this->TABLE_KATEGORIE;
		$table['sortable_table_id']	= $this->TABLE;
		$table['order_by']				= 'pozycja';
		$table['order_dir']				= 'asc';


		$split=$X->DB->split('
			SELECT this.*,
			(SELECT COUNT(id) FROM '.$this->TABLE.' WHERE parent_id=this.id) AS subs
			FROM '.$this->TABLE.' this
			WHERE 1
				'.(empty($_GET['filter']) || (!empty($_GET['filter']) && !empty($_GET['parent_id'])) ? 'AND parent_id="'.(int)$_GET['parent_id'].'"':'').'
			'.$X->DB->set_order($table).'
		', 0);

		$table['top_left'] = $X->FORM->dodaj();
		$table['head']='
			'.$X->ADMIN->sortable_col($table,$split,'th').'
			'.$X->ADMIN->head_col('ID','id',30,'center').'
			'.$X->ADMIN->head_col('Nazwa pozycji','title',false,'left').'
			'.$X->ADMIN->head_col('Aktywna','active',100,'center').'
			'.$X->ADMIN->head_col(false,false,70,'center').'
			'.$X->ADMIN->head_col(false,false,66,'center').'
		';
		while($dane=$X->DB->fa($split['sql'])) {
			$rows.='
				<tr id="R:'.$dane['id'].'">
					'.$X->ADMIN->sortable_col($table,$split,'td').'
					<td class="center">'.$dane['id'].'</td>
					<td>'.$X->ADMIN->go_parent('page&parent_id='.$dane['id'], '<b>'.$X->STR->outt($dane['title']).'</b>', $dane['subs'], $this->PARENT_DEPTH, $dane['dis_enter'], $dane['x_special']).'</td>
					<td class="center">'.$X->FORM->ajax_checkbox($this->TABLE, $dane, 'active').'</td>
					<td class="center">'.$X->FORM->button('Edytuj', $X->URL->get('action=form&id='.$dane['id']), false, false, $dane['dis_edit']).'</td>
					<td class="center">'.$X->FORM->button_potwierdzenie('Usuń', $X->URL->get('action=delete&id='.$dane['id'])).'</td>
				</tr>
			';
		}
		return $X->ADMIN->listbox($this, $table, $rows, $split).$html;
	}


	function _form() {
		$this->TABLE=$this->TABLE_KATEGORIE;
		require(START_FORM);

        $X->DB->q('SET sql_mode ="NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"');
		if($new==true) {
			$dane['active']=1;
			$dane['parent_id']=$_GET['parent_id'];
		}
		$REQ[]=array('text', 2, 'title');

		$html='
			'.$X->ADMIN->form_actions($edit).'
			<table class="form padd3">
				<tr>
					<td width="140">'.$X->FORM->label('title','Nazwa pozycji').'</td>
					<td>'.$X->FORM->input('title',600,$X->STR->outt($dane['title'])).'</td>
				</tr>
				<tr>
					<td>'.$X->FORM->label('active','Aktywna').'</td>
					<td>'.$X->FORM->checkbox('active',1,$X->STR->outt($dane['active'])).'</td>
				</tr>
			</table>
			'.$X->ADMIN->form_actions($edit).'
		';
/*
				<tr><td><br /></td></tr>
				<tr>
					<td>'.$X->FORM->label('seo_t','SEO - Title').'</td>
					<td>'.$X->FORM->input('seo_t',600,$X->STR->outt($dane['seo_t'])).'</td>
				</tr>
				<tr>
					<td>'.$X->FORM->label('seo_k','SEO - Keywords').'</td>
					<td>'.$X->FORM->input('seo_k',600,$X->STR->outt($dane['seo_k'])).'</td>
				</tr>
				<tr>
					<td>'.$X->FORM->label('seo_d','SEO - Desc').'</td>
					<td>'.$X->FORM->input('seo_d',600,$X->STR->outt($dane['seo_d'])).'</td>
				</tr>
*/
		return $X->ADMIN->formbox($X->FORM->get($FORM_NAME, $REQ, $html));
	}


	function _save() {
		$this->TABLE=$this->TABLE_KATEGORIE;
		require(START_SAVE);
		array_push($SAVE,'parent_id','title','active');

        $X->DB->q('SET sql_mode ="NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"');
		$X->DB->q(' UPDATE '.$this->TABLE.' SET '.$X->DB->save($SAVE).' WHERE id="'.$_GET['id'].'" ');
		$X->URL->go2('action&id');
	}


	function _delete($id=false) {
		$this->TABLE=$this->TABLE_KATEGORIE;
		require(START_DELETE);

        $X->DB->q('SET sql_mode ="NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"');
		$X->DB->q(' DELETE FROM '.$this->TABLE.' WHERE id="'.$_GET['id'].'" ');
		$X->URL->go2('action&id');
	}
}
?>