<?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("../../app_path.php");
require_once(APP_PATH.'/AdminController.php');
require_once (LIB_PATH.'/common/unitDB.php');
$obj = new AdminController();
$obj->model =new unitDB();

$page = $obj->model->getRequest("page");
if(!is_numeric($page)) {
	$page = 0;
}
$data = $obj->model->getUnits($obj->model->getRequest("code"), UNIT_PAGER_LIMIT, $page);
$html = "";

define('PAGEC_IMGPATH',str_replace(BASE_PATH,"",PAGEC_PATH));//サムネイル画像取得用
if(is_array($data)&&count($data)>0) {
	foreach($data as $key=>$val) {
		if(isset($val["pageu_code"]) && is_numeric($val["pageu_code"])) {//コピー済みユニット
			if($val["unit_type"]==2 ||$val["unit_type"]==3) {
				$html .= '<li id="'.$val["unit_idname"].'-'.$val["unit_code"].'_'.$val["pageu_code"].'" class="unit" onmouseout="dispUnitName();" onmouseover="dispUnitName(\''.$val["unitclip_name"].'\');" ><img src="'.BINGOTOPURL.UNITS_DIR.'/'.$val["unit_idname"].'/'.$val["unit_idname"].'.gif"></li>'."\n";
			} else if($val["unit_type"]==6){
				$html .= '<li id="'.$val["unit_idname"].'-'.$val["unit_code"].'_'.$val["pageu_code"].'" class="unit" onmouseout="dispUnitName();" onmouseover="dispUnitName(\''.$val["unitclip_name"].'\');" ><img src="'.BINGOTOPURL.MODULES_DIR.'/'.unitDB::getModuleUnitPath($val["extmodule_path"]).$val["unit_idname"].'/'.$val["unit_idname"].'.gif"></li>'."\n";
			} else {
				$html .= '<li id="'.$val["unit_idname"].'-'.$val["unit_code"].'_'.$val["pageu_code"].'" class="unit" onmouseout="dispUnitName();" onmouseover="dispUnitName(\''.$val["unitclip_name"].'\');" ><img src="'.BINGOTOPURL.EXT_UNITS_DIR.'/'.$val["unit_idname"].'/'.$val["unit_idname"].'.gif"></li>'."\n";
			}
			$html .= '<script type="text/javascript">
//<![CDATA[
new Draggable("'.$val["unit_idname"].'-'.$val["unit_code"].'_'.$val["pageu_code"].'", {ghosting:true,revert:true});
//]]>
</script>';
		} else {
			if($val["unit_type"]==1) {
				$html .= '<li id="'.$val["unit_idname"].'" class="unit" onmouseout="dispUnitName();" onmouseover="dispUnitName(\''.$val["unit_name"].'\');" ><img src="'.BINGOTOPURL.PAGEC_IMGPATH.'/'.$val["unit_idname"].'.gif"></li>'."\n";
			} else if($val["unit_type"]==2 ||$val["unit_type"]==3) {
				$html .= '<li id="'.$val["unit_idname"].'-'.$val["unit_code"].'" class="unit" onmouseout="dispUnitName();" onmouseover="dispUnitName(\''.$val["unit_name"].'\');" ><img src="'.BINGOTOPURL.UNITS_DIR.'/'.$val["unit_idname"].'/'.$val["unit_idname"].'.gif"></li>'."\n";
			} else if($val["unit_type"]==6){
				$html .= '<li id="'.$val["unit_idname"].'-'.$val["unit_code"].'" class="unit" onmouseout="dispUnitName();" onmouseover="dispUnitName(\''.$val["unit_name"].'\');" ><img src="'.BINGOTOPURL.MODULES_DIR.'/'.unitDB::getModuleUnitPath($val["extmodule_path"]).$val["unit_idname"].'/'.$val["unit_idname"].'.gif"></li>'."\n";
			} else {
				$html .= '<li id="'.$val["unit_idname"].'-'.$val["unit_code"].'" class="unit" onmouseout="dispUnitName();" onmouseover="dispUnitName(\''.$val["unit_name"].'\');" ><img src="'.BINGOTOPURL.EXT_UNITS_DIR.'/'.$val["unit_idname"].'/'.$val["unit_idname"].'.gif"></li>'."\n";
			}
			if($val["unit_type"]==1) {
						$html .= '<script type="text/javascript">
			//<![CDATA[
			new Draggable("'.$val["unit_idname"].'", {ghosting:true,revert:true});
			//]]>
			</script>';
			} else {
						$html .= '<script type="text/javascript">
			//<![CDATA[
			new Draggable("'.$val["unit_idname"].'-'.$val["unit_code"].'", {ghosting:true,revert:true});
			//]]>
			</script>';
			}
		}
	}
	//次へ、戻る数値取得
	$html .= $obj->model->getUnitPaging($obj->model->getRequest("code"), UNIT_PAGER_LIMIT, $page);
}
echo $html;
?>