<?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/>.
 */

include_once("../../app_path.php");
include_once(APP_PATH.'/AdminController.php');
$obj = new AdminController();
$obj->model =new Model();

$mode = $obj->model->getRequest("mode");
$tdir = UNITS_IMG_PATH;

if($mode=="ttlimg") {
	$tdir = UNITS_TTLIMG_PATH;
} else if ($mode=="header") {
	$tdir = HEADER_IMG_PATH;
}

$dir = @opendir(BASE_PATH.$tdir);
$imgs = array();
if($dir) {
	while (false !== ($file = @readdir($dir))) {
		if(ereg("(([a-z0-9]+)\.(jpg|gif|png))", $file)){
			$size = getImageSize(BASE_PATH.$tdir.$file);
			$stat = stat(BASE_PATH.$tdir.$file);
			$mtimes[] = $stat["mtime"];
	        $imgs[] = array("name"=>$file,"mtime"=>$stat["mtime"], "src"=>BINGOTOPURL.$tdir.$file,"w"=>$size[0],"h"=>$size[1]);
	    }
	}
	closedir($dir);
	if(is_array($imgs)&&is_array($mtimes)&&count($mtimes)>0&&count($imgs)>0) {
		array_multisort($mtimes, SORT_DESC, SORT_NUMERIC, $imgs);
	}
}

$obj->view->assign("imgs",$imgs);
$html = null;
$html = $obj->view->fetch("imgselecter.tpl")."\n";
print_r($html);
?>