<?php
/*
 * design/template/LoadList.class.php
 * 
 * CopyRight(C) 2010 Shopformer Development Team. All Right Reserved
 * URL: http://sourceforge.jp/projects/shopformer/
 * 
 * 
 * Mail: m_nakashima@users.sourceforge.jp
 * Auther: Masanori Nakashima
 * Last Update: 2010-06-18
 */
require_once( dirname(dirname(dirname(__FILE__)))
	.DIRECTORY_SEPARATOR.'system'
	.DIRECTORY_SEPARATOR.'login'
	.DIRECTORY_SEPARATOR.'ModuleBase.class.php');
require_once( dirname(dirname(__FILE__))
	.DIRECTORY_SEPARATOR.'DaoTemplate.class.php');
class design_template_LoadList extends system_login_ModuleBase {
	
	function design_template_LoadList() {
	}
	function execute( & $request ) {
		$variableObject		= new content_Variable($request);
		$variableObject->getKeyArray( $request );
		// 利用可能なテンプレートファイルの一覧を取得する
		$templateInfoHash	= array();
		$targetDir			= DIR_PATH_DATA.DIRECTORY_SEPARATOR.'design'.DIRECTORY_SEPARATOR.'template';
		if( is_dir($targetDir) ) {
			if ($dh = opendir($targetDir)) {
				while (($fileName = readdir($dh)) !== false) {
					if( preg_match('/^\\./',$fileName)==0 ) {
						$absolutePath	= $targetDir.DIRECTORY_SEPARATOR.$fileName;
						if( is_dir($absolutePath) ) {
							$templateObject	= new design_DaoTemplate($fileName);
							$templateObject->loadInfo( $request );
							$keyArray	= $templateObject->getRelatedVariableKeys( $request );
							foreach( $keyArray as $key ) {
								if( !$variableObject->existsKey( $key ) ) {
									$templateObject->isSetup	= false;
									break;
								}
							}
							$templateInfoHash[$fileName]	= $templateObject;
						}
					}
				}
				closedir($dh);
			}
		}
		ksort($templateInfoHash);
		$request->setAttribute('design.template.templateInfoHash',$templateInfoHash );
	}
}
?>