<?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/unitDB.php');
require_once (LIB_PATH.'/common/sidebarDB.php');

class Admin_admin_template_sideunitdetail extends sidebarDB
{
	var $_pageu_code = null;
	
	function prepare($view)
	{
		$this->_pageu_code = $this->getRequest('pageu_code') ? $this->getRequest('pageu_code') : "";
		$imgs = $this->getRequest('imgs') ? $this->getRequest('imgs') : "";
		$this->_img_size = array();
		if($imgs) {
			$tmp = explode(":",$imgs);
			if(is_array($tmp)&&count($tmp)>0) {
				foreach($tmp as $key=>$val) {
					if($val!=null){
						list($width,$height) = explode(",",$val);
						$this->_img_size[] = array("w"=>$width,"h"=>$height);
					}
				}
			}
		}
		$view->assign("imgsize",$this->_img_size);
		return null;
	}

	function perform($view)
	{
		if(is_numeric($this->_pageu_code)) {
			//ユニットコードからプログラムファイルがどこか取得
			$unitdata = $this->getDetail($this->_pageu_code);
			//プログラムファイルの読み込み
			if(isset($unitdata["unit_php_path"])) {
				$units_dir = explode(".", $unitdata["unit_php_path"]);
				//require_once(UNITS_PATH."/".$units_dir[0]."/".$unitdata["unit_php_path"]);
				switch($unitdata["unit_type"]) {
					case 2:
					case 3:
						require_once(UNITS_PATH."/".$units_dir[0]."/".$unitdata["unit_php_path"]);
						break;
					case 4:
					case 5:
						require_once(EXT_UNITS_PATH."/".$units_dir[0]."/".$unitdata["unit_php_path"]);
						break;
					case 6:
							require_once(MODULES_PATH."/".unitDB::getModuleUnitPath($unitdata["extmodule_path"]).$units_dir[0]."/".$unitdata["unit_php_path"]);
						break;
					default :
						break;
				}
			}
			list($unit_class_name,$trash) = explode('.', $unitdata["unit_php_path"]);
			$unit_class = new $unit_class_name;
			
			//管理画面メソッドの読み出し
			$unit_class->init($this->_pageu_code, $unit_class_name, $view, $prev=true,$unitdata);
            $html .= $unit_class->initAdmin();
            
			$view->assign("html", $html);
	        return 'template/unitdetail.tpl';
		} else {
			return 'template/uniterr.tpl';
		}
	}
}
?>
