<?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/sidebarDB.php');
require_once (LIB_PATH.'/common/pageView.php');
class Admin_admin_template_Sideunitin extends Model
{
	var $_tpl_code;
	function prepare($view)
	{
		$this->_tpl_code = $this->getrequest("tpl_code");
		$view->assign("tpl_code",$this->_tpl_code);
		
		return null;
	}
	
	function perform($view)
	{
		
		$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);
		
		$sidebarDB=new sidebarDB();
		$html_ar =  $sidebarDB->makeUnitListHTML($view,$sidebarDB->getData($this->_tpl_code));
		$side = $this->makeHTML($html_ar);
		$_SESSION["USERAREAWIDTH"]=isset($pageView->_skinsetting["SIDEBARAREAWIDTH"])?$pageView->_skinsetting["SIDEBARAREAWIDTH"]:100;
		
		$view->assign('ULIST',$side);
		$html = $view->fetch("template/sideunit-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_unitlist_in.css" rel="stylesheet" type="text/css" media="all" />');
		return $pageView->_sidx_data["skin_path"];
	}
	
	function makeHTML($unit) {
		$html=null;
		if(is_array($unit)) {
			foreach($unit as $ukey => $uval) {
				$html .= "<div id='u".$ukey."' onmouseout=\"Element.hide('u".$ukey."-inner')\" onmouseover=\"Element.show('u".$ukey."-inner');\" >
								<div id='u".$ukey."-inner' style=\"position:absolute;display:none;text-align:center;z-index:10;\">
								<input type='button' class='bBtnUnitReedition' onclick=\"var imgs=getImageSize('u".$ukey."');return parent.showBox('', '../../admin/template/sideunitdetail.php?pageu_code=".$ukey."&imgs='+imgs, 840, 500)\" value='このユニットを編集する'>
								</div>
								".$uval."
								</div>";
			
			}
		}
		return $html;
	}
	
}
?>