<?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_category_Index extends categoryDB
{
	function prepare($view)
	{
		$this->_cat_sidx_code = $this->getRequest('sidx_code') ? $this->getRequest('sidx_code') : 0;
		return null;
	}

	function perform($view)
	{
		//表示順保存処理
		if($this->getRequest("BTNOrderSAVE")) {
			$orderlist = $this->getRequest("order");
			if(is_array($orderlist)) {
				if($this->setOrder($orderlist)) {
					$view->assign("ERROR",array("表示順を保存しました"));
				} else {
					$view->assign("ERROR",array("表示順の保存に失敗しました"));
				}
			}
		}
		
		if(is_numeric($this->_cat_sidx_code)&& $this->_cat_sidx_code>0) {
			$sidxdata_tmp = sectionIdxDB::getData($this->_cat_sidx_code,$prev=true);
			if($sidxdata_tmp["sidx_dir"]!=null) {
				$sidxdata_tmp["sidx_url"] = pageView::getSiteURL($sidxdata_tmp["sidx_dir"],$c=null,$p=null,$sidxdata_tmp["sidx_ssl"]);
				$sidxdata_tmp["sidx_preurl"] = pageView::getSiteURL($sidxdata_tmp["sidx_dir"],$c=null,$p=null,$sidxdata_tmp["sidx_ssl"],$prev=true,$mprev=true);
			}
			//$sidxdata = sectionIdxDB::getData($this->_cat_sidx_code,$prev=false);
			//if($sidxdata["sidx_dir"]!=null) {
			//	$sidxdata["sidx_url"] = pageView::getSiteURL($sidxdata["sidx_dir"],$c=null,$p=null,$sidxdata["sidx_ssl"]);
			//}
			$list = $this->getlistAll($this->_cat_sidx_code);
		}
		//url変換
		if(is_array($list)) {
			foreach($list as $key => $val) {
				//$list[$key]["url"] = pageView::getSiteURL($sidxdata["sidx_dir"],$c=$val["cat_dir"],$p=null,$sidxdata_tmp["sidx_ssl"]);
				$list[$key]["preurl"] = pageView::getSiteURL($sidxdata_tmp["sidx_dir"],$c=$val["cat_dir_tmp"],$p=null,$sidxdata_tmp["sidx_ssl"],$prev=true,$mprev=true);
				$list[$key]["preurldisp"] = pageView::getSiteURL($sidxdata_tmp["sidx_dir"],$c=$val["cat_dir_tmp"],$p=null,$sidxdata_tmp["sidx_ssl"]);
			}
		}
		
		$view->assign('list', $list);
		//$view->assign('sidx_data',$sidxdata);
		$view->assign('sidx_data_tmp',$sidxdata_tmp);
		$view->assign('sidx_code',$this->_cat_sidx_code);
		//ツリービュー
		//$sectionIdxDB = New sectionIdxDB();
		//$view->assign("treeView", $sectionIdxDB->getTreeView());
		///////////////////
		if(is_numeric($this->_cat_sidx_code)&& $this->_cat_sidx_code>0) {
			return 'contents/category/index.tpl';
		} else {
			return 'contents/category/top.tpl';
		}
		
        
	}
}
?>
