<?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/sidebarDB.php');
require_once (LIB_PATH.'/common/pageView.php');
class Admin_admin_template_Sidelayoutin extends sidebarDB
{
	var $_tpl_code;
	function prepare($view)
	{
		$this->_tpl_code = $this->getrequest("tpl_code");
		$view->assign("tpl_code",$this->_tpl_code);
		
		//ユニット選択プルダウンメニュー生成 v1.2
		$view->assign('unitpullmenu', unitDB::getUnitsMasterList());
		$view->assign('unitlist',unitDB::getUnits("2:0", UNIT_PAGER_LIMIT, 0));
		$view->assign('unitlistpaging',unitDB::getUnitPaging("2:0", UNIT_PAGER_LIMIT, 0));
		//ユニット一覧 v1.1
		/*$unitlist = unitDB::getlist($unit_type=array(2,3));
		//タイプ別に分別
		foreach($unitlist as $ukey=>$uval) {
			$tmp[$uval["unit_type"]][$uval["unit_code"]] = $uval;
		}
		$view->assign('unitlist',$tmp);
		*/
		$view->assign('PAGEU_IMGPATH',str_replace(BASE_PATH,"",UNITS_PATH));//サムネイル画像取得用
		
		$this->_form = new HTML_QuickForm('form','post','sidelayout.php','_top',null,true);
		//フォームエレメントの作成
		$this->_form->addElement('hidden','sdbr_tpl_code', $this->_tpl_code, array("id"=>"sdbr_tpl_code"));
		$this->_form->addElement('hidden','tpl_code', $this->_tpl_code, array("id"=>"tpl_code"));
		
		//フォーム入力エラーチェックの設定
		$this->_form->applyFilter('__ALL__','trim');
		$this->_form->_submitValues = DataBase::ConvColumnVals($this->_form->_submitValues,$this->columns); //ルールに従った値変換、タグの除去
		$this->_form->setJsWarnings('下記の項目が不正です。','');		
		$this->_form->addRule('sdbr_tpl_code','・「テンプレートコード」が不明です。テンプレート設定よりやり直してください','required',null,$this->erchk);
		
		//ボタン作成
		$buttons = array();
		$buttons[] = $this->_form->createElement('submit','BTNsave','保存',array('id'=>'BTNsave','class'=>'bBtnBlueS'));
		$this->_form->addGroup($buttons,"buttons", null, '&nbsp;&nbsp;');
		
		return null;
	}
	
	function perform($view)
	{
		$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($view);
		$this->_form->accept($renderer);
		$view->assign('form',$renderer->toArray());
		
		$pageView = new pageView();
		$pageView->_prev = 1;
		$pageView->_tpl_editting = true;
		if(!$pageView->initPage()) {
			return '404.tpl';
		}
		$view->assign('preview', ($this->_prev) ? 1 : 0);
		$view->assign('header',$pageView->_header);
		$view->assign('footer',$pageView->_footer);
		$view->assign('m_menu',$pageView->_gmenu);
		$view->assign('sub_menu',$pageView->_smenu);
		
		$view->assign('sidx_data',$pageView->_sidx_data);
		
		$view->assign('WWW', WWW);
		$view->assign('WWW_SSL', WWW_SSL);
		$view->assign('SITENAME', SITENAME);
		$view->assign('ADMIN_MAIL', ADMIN_MAIL);
		//管理画面ではカウントさせない
		$view->assign('ANALYTICS', '');
		//登録済みコンテナ＆ユニット情報
		$htmldata  .= $view->fetch("template/body.tpl")."\n";
		$view->assign('items',$htmldata);
		$html_ar =  $this->makeUnitListHTML($view,$_SESSION["sidebar_unit"]);
		$side = $this->SidebarAdminmakeHTML($html_ar);
		
		$view->assign('ULIST',$side);
		$html = $view->fetch('template/sidelayout-in.tpl')."\n";//管理画面用パーツHTMLを生成
		$view->assign('SIDE',$html);
		
		if($pageView->_skin_data["skin_path"]!=null) {
			$view->assign("CSS",$pageView->_skincss_path);
		}
		$view->assign('UNITSCSS', $pageView->_allunitCSS.'<link href="../css/imported_unitlayout_in.css" rel="stylesheet" type="text/css" media="all" />');
		
        return $pageView->_sidx_data["skin_path"];
	}
}
?>