<?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/pagecontainerDB.php');
require_once (LIB_PATH.'/common/sectionIdxDB.php');
require_once (LIB_PATH.'/common/categoryDB.php');
class Admin_admin_contents_page_Layoutin extends pagecontainerDB
{
	function prepare($view)
	{
		$this->_mprev = $this->getRequest('mprev') ? true : false;
		$view->assign("mprev",$this->_mprev);
		$this->_sidx_code = $this->getRequest('sidx_code') ? $this->getRequest('sidx_code') : "";
		$this->_cat_code = $this->getRequest('cat_code') ? $this->getRequest('cat_code') : "";
		$this->_pidx_code = $this->getRequest('pidx_code') ? $this->getRequest('pidx_code') : "";
		$this->_form = new HTML_QuickForm('form','post','layout.php','_top',null,true);
		$this->setElements();
		$this->setRules();
		$this->setButtons();
		
		if(is_numeric($this->_sidx_code)) {
			$this->_sidx_data = sectionIdxDB::getData($this->_sidx_code,$this->_mprev);
		}
		if(is_numeric($this->_cat_code)) {
			$this->_cat_data = categoryDB::getData($this->_cat_code,$this->_mprev);
		}
		
				
		//ユニット選択プルダウンメニュー生成 v1.2
		$view->assign('unitpullmenu', unitDB::getUnitsMasterList());
		$view->assign('unitlist',unitDB::getUnits("1:0", UNIT_PAGER_LIMIT, 0));
		$view->assign('unitlistpaging',unitDB::getUnitPaging("1:0", UNIT_PAGER_LIMIT, 0));
		
		/*
		//ユニット一覧
		$unitlist = unitDB::getlist($unit_type=array(1));
		//タイプ別に分別
		foreach($unitlist as $ukey=>$uval) {
			$tmp[$uval["unit_type"]][$uval["unit_code"]] = $uval;
		}
		$view->assign('unitlist',$tmp);
		*/
		
		return null;
	}

	function perform($view)
	{
	
		$view->assign('items',$this->ContainerAdminmakeHTML($view,$_SESSION["page_container"], $_SESSION["page_unit"]));
		$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($view);
		$this->_form->accept($renderer);
		$view->assign('form',$renderer->toArray());
		
		//一般ページの情報セット
		require_once (LIB_PATH.'/common/pageView.php');
		$pageView = new pageView();
		$pageView->_prev = 1;
		if(!$pageView->initPage(&$view)) {
			return '404.tpl';
		}
		$htmldata = $pageView->getPageData(&$view);

		//モジュール共通CSSの取得
		$view->assign('UNITSCSS', $pageView->_allunitCSS.'<link href="../../css/imported_layout.css" rel="stylesheet" type="text/css" media="all" />');
		$view->assign('preview', ($this->_prev) ? 1 : 0);
		//サブナビゲーションの取得
		//$sub_menu = $pageView->getCategoryMenu();
		$view->assign('header',$pageView->_header);
		$view->assign('footer',$pageView->_footer);
		$view->assign('m_menu',$pageView->_gmenu);
		$view->assign('sub_menu',$pageView->_smenu);
		$view->assign('SIDE',$pageView->_sidebar);
		if($pageView->_skin_data["skin_path"]!=null) {
			$view->assign("CSS",$pageView->_skincss_path);
		}
		
		$view->assign('sidx_data',$pageView->_sidx_data);
		$view->assign('sidx_code',$this->_sidx_code);
		$view->assign('cat_data',$pageView->_cat_data);
		$view->assign('cat_code',$this->_cat_code);
		$view->assign('pidx_data',$pageView->_pidx_data);
		$view->assign('pidx_code',$this->_pidx_code);
		$view->assign('PAGEC_IMGPATH',str_replace(BASE_PATH,"",PAGEC_PATH));//サムネイル画像取得用

		$view->assign('WWW', WWW);
		$view->assign('WWW_SSL', WWW_SSL);
		$view->assign('SITENAME', SITENAME);
		$view->assign('ADMIN_MAIL', ADMIN_MAIL);

		//管理画面ではカウントさせない
		$view->assign('ANALYTICS', '');

		$view->assign("PAGENAVI",$pageView->getPagenavi());
		
		//url変換
		$url = pageView::getSiteURL($d=$this->_sidx_data["sidx_dir"],$c=$this->_cat_data["cat_dir"],$p=$pageView->_pidx_data["pidx_url"],$this->_sidx_data["sidx_ssl"],$prev=true,$mprev=$this->_mprev);
		$view->assign('previewurl',$url);
		
		$html = $view->fetch("contents/page/layout-in.tpl")."\n";
		$view->assign('items',$html);
		return $pageView->_sidx_data["skin_path"];
	}
}
?>
