<?php
namespace carabi_cms;

/**
 * Работа с новостями на сайте (для них используется документ "тема форума")
 *
 * @author sasha
 */

include_once CARABI_DIR . '/classes/wave_editor/class.WaveEditorUtils.php';

//class pagehandler_news extends \SimplePagehandler {
class pagehandler_news extends \pagehandler_forumCommon {
	var $size = 0;
	
	var $newsColModel = '[
	{ name: "NAME", label: "Заголовок", sortable: false/*, width: 600, fixed: true*/},
	{ name: "DATE_CREATE", label: "Дата создания", sortable: false, width: 150, fixed: true},
	{ name: "FTEMA_COUNT_MES", label: "Коммент.", sortable: false, width: 64, fixed: true},
	{ name: "FTEMA_NEW", label: "Новых к.", sortable: false, width: 64, fixed: true},
	{ name: "FTEMA_LINK", label: "ID", sortable: false, width: 65, fixed: true}
]';
	var $newsColModelSearch = '[
	{ name: "NAME", label: "Заголовок", sortable: false},
	{ name: "DATE_CREATE", label: "Дата создания", sortable: false, width: 150, fixed: true},
	{ name: "FTEMA_LINK", label: "ID", sortable: false, width: 64, fixed: true}
]';
	
	public function __construct(\SimpleUrl $simpleUrl) {
		parent::__construct($simpleUrl, false);
		global $DATABASE_SCHEMAS;
		$this->rootChapters = $DATABASE_SCHEMAS[\Auth::getCurrentSchema()]["webnewsChapters"];
	}
	
	public function process() {
		if (\lib_cms::hasPermission($this->user(), \lib_cms::PERMISSION_NEWS)) {
			$this->executeAction();
		} else {
			header("Location: " . \lib_cms::loginPage());
		}
	}
	
	protected function index() {
		$tpl = $this->renderer()->createTemplate("carabi_cms/content.news.tpl");
		$this->selectChapters(true);
		$tpl->assign('colModel', $this->newsColModel);
		$tpl->assign('size', $this->size);
		$tpl->assign("pagehandler", $this);
		$tpl->display();
	}
	
}
?>
