<?PHP

class PagesAdmin extends Buyers
{
	function fetch()
	{
		if($this->request->method('post'))
		{
			// Действия с выбранными
			$ids = $this->request->post('check');
			if(is_array($ids))
			switch($this->request->post('action'))
			{
			    case 'disable':
			    {
			    	foreach($ids as $id)
						$this->pages->update_page($id, array('visible'=>0));
					break;
			    }
			    case 'enable':
			    {
			    	foreach($ids as $id)
						$this->pages->update_page($id, array('visible'=>1));
			        break;
			    }
			    case 'delete':
			    {
					$this->pages->delete_page($ids);
			        break;
			    }
			}

			// Сортировка
			$positions = $this->request->post('positions');
	 		$ids = array_keys($positions);
			sort($positions);
			foreach($positions as $i=>$position)
				$this->pages->update_page($ids[$i], array('position'=>$position));
		}

		$pages = $this->pages->get_pages_tree();


		$this->design->assign('pages', $pages);
		return $this->design->fetch('pages.tpl');
	}
}
