<?php
/*
	Copyright(c) 2010 Shift Tech Inc. All Rights Reserved.
 	http://www.shift-tech.jp/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

require_once (LIB_PATH.'/common/sectionIdxDB.php');
require_once (LIB_PATH.'/common/categoryDB.php');
require_once (LIB_PATH.'/common/pageView.php');
class Admin_admin_contents_Index extends sectionIdxDB
{
	function prepare($view)
	{
		return null;
	}

	function perform($view)
	{
		//公開処理
		$errors = null;
		if($this->getRequest("BTNdispflg")) {
			if(!check_token($_REQUEST["token"])) {
				$this->putTokenError();
			}
			if(is_numeric($this->getRequest("pubcode"))) {
				$pubcode = $this->getRequest("pubcode");
			}
			if($this->setPublicData($pubcode)) {
				$errors[]="公開しました";
				require_once (LIB_PATH.'/common/unitCache.php');
				$cache = new unitCache();
				$cache->makeCache(&$view);
			} else {
				$errors[]="公開に失敗しました";
			}
		}
		//編集処理
		else if($this->getRequest("BTNeditflg")) {
			if(!check_token($_REQUEST["token"])) {
				$this->putTokenError();
			}
			if(is_numeric($this->getRequest("pubcode"))) {
				$pubcode = $this->getRequest("pubcode");
			}
			if($this->setPublicToEditData($pubcode)) {
				//$errors[]="保存しました";
			} else {
				$errors[]="編集モードへの移行に失敗しました";
			}
		}
		//表示順保存処理
		else if($this->getRequest("BTNOrderSAVE")) {
			if(!check_token($_REQUEST["token"])) {
				$this->putTokenError();
			}
			$orderlist = $this->getRequest("order");
			if(is_array($orderlist)) {
				if($this->setOrder($orderlist)) {
					$errors[]="表示順を保存しました";
				} else {
					$errors[]="表示順の保存に失敗しました";
				}
			}
		}
		$view->assign('ERROR',$errors);
		
		if($_SESSION["usr_info"]["usr_kanri"]!=1){
			$list = $this->getlistAll($_SESSION["usr_info"]["usr_code"]);
		} else {
			$list = $this->getlistAll();
			$view->assign('NewBTNDisp', 1);
		}
		
		//url取得&公開ボタン数取得
		$pubCnt = 0;
		if(is_array($list)) {
			foreach($list as $key=>$val) {
				$list[$key]["url"] = pageView::getSiteURL($val["sidx_dir"],$c=null,$p=null,$val["sidx_ssl"]);
				$list[$key]["preurl"] = pageView::getSiteURL($val["sidx_dir_tmp"],$c=null,$p=null,$val["sidx_ssl_tmp"],$prev=true);
				$list[$key]["preurlfordisp"] = pageView::getSiteURL($val["sidx_dir_tmp"],$c=null,$p=null,$val["sidx_ssl_tmp"]);
				$list[$key]["ulist"]	= sectionuserDB::getusrlist($val["sidx_code_tmp"]);
				if($val["sidx_view_tmp"]==1) {
					$pubCnt++;
				}
			}
		}
		$view->assign('list', $list);
		$view->assign('pubCnt', $pubCnt);
		
		//デザインテンプレート一覧取得
		$tpllist = templateDB::getList();
		$view->assign('tpllist', $tpllist);
		//ツリービュー
		//$view->assign("treeView", $this->getTreeView());
		///////////////////
		$view->assign("token", $this->getToken());
        return 'contents/index.tpl';
	}
}
?>
