Index: temp/trunk/data/downloads/module/module.php
===================================================================
--- temp/trunk/data/downloads/module/module.php	(revision 6420)
+++ temp/trunk/data/downloads/module/module.php	(revision 6421)
@@ -12,5 +12,5 @@
 	function LC_Page() {
 		//¥á¥¤¥ó¥Æ¥ó¥×¥ì¡¼¥È¤Î»ØÄê
-		$this->tpl_mainpage = DATA_PATH . 'update/module/system/module.tpl';
+		$this->tpl_mainpage = DATA_PATH . 'downloads/module/module.tpl';
 		$this->tpl_subnavi = 'system/subnavi.tpl';
 		$this->tpl_mainno = 'system';		
Index: temp/trunk/html/admin/downloads/module/module.php
===================================================================
--- temp/trunk/html/admin/downloads/module/module.php	(revision 6421)
+++ temp/trunk/html/admin/downloads/module/module.php	(revision 6421)
@@ -0,0 +1,279 @@
+<?php
+/*
+ * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ */
+require_once("../require.php");
+
+//¥Ú¡¼¥¸´ÉÍý¥¯¥é¥¹
+class LC_Page {
+	//¥³¥ó¥¹¥È¥é¥¯¥¿
+	function LC_Page() {
+		//¥á¥¤¥ó¥Æ¥ó¥×¥ì¡¼¥È¤Î»ØÄê
+		$this->tpl_mainpage = DATA_PATH . 'downloads/module/module.tpl';
+		$this->tpl_subnavi = 'system/subnavi.tpl';
+		$this->tpl_mainno = 'system';		
+		$this->tpl_subno = 'module';
+		$this->tpl_subtitle = '¥â¥¸¥å¡¼¥ë´ÉÍý';
+	}
+}
+
+$objPage = new LC_Page();
+$objView = new SC_AdminView();
+$objQuery = new SC_Query();
+
+// ¥»¥Ã¥·¥ç¥ó¥¯¥é¥¹
+$objSess = new SC_Session();
+// Ç§¾Ú²ÄÈÝ¤ÎÈ½Äê
+sfIsSuccess($objSess);
+
+switch($_POST['mode']) {
+// ¥¢¥Ã¥×¥Ç¡¼¥È¾ðÊó¥Õ¥¡¥¤¥ë¤ò¼èÆÀ
+case 'edit':
+	// ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
+	lfLoadUpdateList();
+	break;
+// ¥¤¥ó¥¹¥È¡¼¥ë
+case 'install':
+	// ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
+	lfLoadUpdateList();
+	// ¥â¥¸¥å¡¼¥ë·´¤Î¥¤¥ó¥¹¥È¡¼¥ë
+	lfInstallModule();
+	break;
+// ¥¢¥ó¥¤¥ó¥¹¥È¡¼¥ë
+case 'uninstall':
+	// ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
+	lfLoadUpdateList();
+	// ¥â¥¸¥å¡¼¥ë·´¤Î¥¤¥ó¥¹¥È¡¼¥ë	
+	lfUninstallModule();
+	break;
+default:
+	break;
+}
+
+$col = "module_id, module_name, now_version, latest_version, module_explain, create_date, release_date";
+$objQuery->setorder("module_id");
+$objPage->arrUpdate = $objQuery->select($col, "dtb_update");
+
+$objView->assignobj($objPage);		//ÊÑ¿ô¤ò¥Æ¥ó¥×¥ì¡¼¥È¤Ë¥¢¥µ¥¤¥ó¤¹¤ë
+$objView->display(MAIN_FRAME);		//¥Æ¥ó¥×¥ì¡¼¥È¤Î½ÐÎÏ
+//-------------------------------------------------------------------------------------------------------
+// ¹¹¿·¥Õ¥¡¥¤¥ë¤Î¼èÆÀ
+function lfCopyUpdateFile($file) {
+	global $objPage;
+	
+	$src_path = sfRmDupSlash(UPDATE_HTTP . $file . ".txt");
+	$dst_path = sfRmDupSlash(DATA_PATH . $file);
+	$flg_ok = true;	// ½èÍý¤ÎÀ®¸ùÈ½Äê
+	
+	$src_fp = @fopen($src_path, "rb");
+	
+	if(!$src_fp) {
+		sfErrorHeader(">> " . $src_path . "¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
+		$flg_ok = false;
+	} else {
+		// ¥Õ¥¡¥¤¥ë¤ò¤¹¤Ù¤ÆÆÉ¤ß¹þ¤à
+		$contents = '';
+		while (!feof($src_fp)) {
+			$contents .= fread($src_fp, 1024);
+		}
+		fclose($src_fp);
+		
+		// ¥Ç¥£¥ì¥¯¥È¥êºîÀ®¤ò»î¤ß¤ë
+		lfMakeDirectory($dst_path);
+		// ¥Õ¥¡¥¤¥ë½ñ¹þ¤ß		
+		$dst_fp = @fopen($dst_path, "wb");
+		if(!$dst_fp) {
+			sfErrorHeader(">> " . $dst_path . "¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
+			$flg_ok = false;
+		} else {
+			fwrite($dst_fp, $contents);
+			fclose($dst_fp);
+		}
+	}
+	
+	if($flg_ok) {
+		$objPage->update_mess.= ">> " . $dst_path . "¡§¥³¥Ô¡¼À®¸ù<br>";
+	} else {
+		$objPage->update_mess.= ">> " . $dst_path . "¡§¥³¥Ô¡¼¼ºÇÔ<br>";		
+	}
+	
+	return $flg_ok;
+}
+
+// ¤¹¤Ù¤Æ¤Î¥Ñ¥¹¤Î¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¤¹¤ë
+function lfMakeDirectory($path) {
+	$pos = 0;
+	$cnt = 0;				// Ìµ¸Â¥ë¡¼¥×ÂÐºö
+	$len = strlen($path);	// Ìµ¸Â¥ë¡¼¥×ÂÐºö
+	
+	while($cnt <= $len) {
+		$pos = strpos($path, "/", $pos);
+		// ¤³¤³¤Ç¤ÎÈ½Äê¤Ï¡¢Åù¹æ3¤Ä¤ò»ÈÍÑ
+		if($pos === false) {
+			// ¥¹¥é¥Ã¥·¥å¤¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï¥ë¡¼¥×¤«¤éÈ´¤±¤ë
+			break;
+		}
+		$pos++; // Ê¸»úÈ¯¸«°ÌÃÖ¤ò°ìÊ¸»ú¿Ê¤á¤ë
+		$dir = substr($path, 0, $pos);
+		
+		// ¤¹¤Ç¤ËÂ¸ºß¤¹¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë
+		if(!file_exists($dir)) {
+			mkdir($dir);
+		}
+		$cnt++; // Ìµ¸Â¥ë¡¼¥×ÂÐºö
+	}
+}
+
+// ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
+function lfLoadUpdateList() {
+	$objQuery = new SC_Query();
+	$path = UPDATE_HTTP . "update.txt";
+	$fp = @fopen($path, "rb");
+		
+	if(!$fp) {
+		sfErrorHeader(">> " . $path . "¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
+	} else {
+		while (!feof($fp)) {
+			$arrCSV = fgetcsv($fp, UPDATE_CSV_LINE_MAX);
+			// ¥«¥é¥à¿ô¤¬Àµ¾ï¤Ç¤¢¤Ã¤¿¾ì¹ç¤Î¤ß
+			if(count($arrCSV) == UPDATE_CSV_COL_MAX) {
+				// ¼èÆÀ¤·¤¿¥¢¥Ã¥×¥Ç¡¼¥È¾ðÊó¤òDB¤Ë½ñ¤­¹þ¤à
+				$sqlval['module_id'] = $arrCSV[0];
+				$sqlval['module_name'] = $arrCSV[1];
+				$sqlval['latest_version'] = $arrCSV[3];
+				$sqlval['module_explain'] = $arrCSV[4];
+				$sqlval['main_php'] = $arrCSV[5];
+				$sqlval['extern_php'] = $arrCSV[6];
+				$sqlval['install_sql'] = $arrCSV[7];
+				$sqlval['uninstall_sql'] = $arrCSV[8];				
+				$sqlval['other_files'] = $arrCSV[9];
+				$sqlval['del_flg'] = $arrCSV[10];
+				$sqlval['update_date'] = "now()";
+				$sqlval['release_date'] = $arrCSV[12];
+				// ´ûÂ¸¥ì¥³¡¼¥É¤Î¥Á¥§¥Ã¥¯
+				$cnt = $objQuery->count("dtb_update", "module_id = ?", array($sqlval['module_id']));
+				if($cnt > 0) {
+					// ¤¹¤Ç¤Ë¼èÆÀ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¹¹¿·¤¹¤ë¡£	
+					$objQuery->update("dtb_update", $sqlval, "module_id = ?", array($sqlval['module_id']));
+				} else {
+					// ¿·µ¬¥ì¥³¡¼¥É¤ÎÄÉ²Ã
+					$sqlval['create_date'] = "now()";
+					$objQuery->insert("dtb_update", $sqlval);
+				}
+			} else {
+				sfErrorHeader(">> ¥«¥é¥à¿ô¤¬°ìÃ×¤·¤Þ¤»¤ó¡£¡§".count($arrCSV));
+			}
+		}
+		fclose($fp);
+	}
+}
+
+// ¥¤¥ó¥¹¥È¡¼¥ë½èÍý
+function lfInstallModule() {
+	global $objPage;
+	
+	$objQuery = new SC_Query();
+	$arrRet = $objQuery->select("module_id, extern_php, other_files, install_sql, latest_version", "dtb_update", "module_id = ?", array($_POST['module_id']));
+	$flg_ok = true;	// ½èÍý¤ÎÀ®¸ùÈ½Äê
+	
+	if(count($arrRet) > 0) {
+		$arrFiles = array();
+		if($arrRet[0]['other_files'] != "") {
+			$arrFiles = split("\|", $arrRet[0]['other_files']);
+		}
+		$arrFiles[] = $arrRet[0]['extern_php'];
+		foreach($arrFiles as $val) {
+			// ¹¹¿·¥Õ¥¡¥¤¥ë¤Î¼èÆÀ
+			$ret=lfCopyUpdateFile($val);
+			if(!$ret) {
+				$flg_ok = false;
+			}
+		}
+	} else {
+		sfErrorHeader(">> ÂÐ¾Ý¤Îµ¡Ç½¤Ï¡¢ÇÛÉÛ¤ò½ªÎ»¤·¤Æ¤ª¤ê¤Þ¤¹¡£");
+		$flg_ok = false;
+	}
+	
+	// É¬Í×¤ÊSQLÊ¸¤Î¼Â¹Ô
+	if($arrRet[0]['install_sql'] != "") {
+		// SQLÊ¸¼Â¹Ô¡¢¥Ñ¥é¡¼¥á¡¼¥¿¤Ê¤·¡¢¥¨¥é¡¼Ìµ»ë
+		$arrInstallSql = split(";",$arrRet[0]['install_sql']);
+		foreach($arrInstallSql as $key => $val){
+			if (trim($val) != ""){
+				$ret = $objQuery->query(trim($val),"",true);
+			}
+		}
+		if(DB::isError($ret)) {
+			// ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
+			ereg("\[(.*)\]", $ret->userinfo, $arrKey);
+			$objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊÑ¹¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";
+			$objPage->update_mess.= $arrKey[0] . "<br>";
+			$flg_ok = false;
+		} else {
+			$objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊÑ¹¹¤ò¹Ô¤¤¤Þ¤·¤¿¡£<br>";
+		}
+	}
+	
+	if($flg_ok) {
+		$sqlval['now_version'] = $arrRet[0]['latest_version'];
+		$sqlval['update_date'] = "now()";
+		$objQuery->update("dtb_update", $sqlval, "module_id = ?", array($arrRet[0]['module_id']));
+	}
+}
+
+// ¥¢¥ó¥¤¥ó¥¹¥È¡¼¥ë½èÍý
+function lfUninstallModule() {
+	global $objPage;
+	
+	$objQuery = new SC_Query();
+	$arrRet = $objQuery->select("module_id, extern_php, other_files, install_sql, uninstall_sql, latest_version", "dtb_update", "module_id = ?", array($_POST['module_id']));
+	$flg_ok = true;	// ½èÍý¤ÎÀ®¸ùÈ½Äê
+	
+	if(count($arrRet) > 0) {
+		$arrFiles = array();
+		if($arrRet[0]['other_files'] != "") {
+			$arrFiles = split("\|", $arrRet[0]['other_files']);
+		}
+		$arrFiles[] = $arrRet[0]['extern_php'];
+		foreach($arrFiles as $val) {
+			$path = DATA_PATH . $val;
+			if(file_exists($path)) {
+				// ¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë
+				if(unlink($path)) {
+					$objPage->update_mess.= ">> " . $path . "¡§ºï½üÀ®¸ù<br>";
+				} else {
+					$objPage->update_mess.= ">> " . $path . "¡§ºï½ü¼ºÇÔ<br>";
+				}
+			}
+		}
+		
+		// É¬Í×¤ÊSQLÊ¸¤Î¼Â¹Ô
+		if($arrRet[0]['uninstall_sql'] != "") {
+			// SQLÊ¸¼Â¹Ô¡¢¥Ñ¥é¡¼¥á¡¼¥¿¤Ê¤·¡¢¥¨¥é¡¼Ìµ»ë
+			$ret = $objQuery->query($arrRet[0]['uninstall_sql'],"",true);
+			if(DB::isError($ret)) {
+				// ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
+				ereg("\[(.*)\]", $ret->userinfo, $arrKey);
+				$objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊÑ¹¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";
+				$objPage->update_mess.= $arrKey[0] . "<br>";
+				$flg_ok = false;
+			} else {
+				$objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊÑ¹¹¤ò¹Ô¤¤¤Þ¤·¤¿¡£<br>";
+			}
+		}		
+	} else {
+		sfErrorHeader(">> ÂÐ¾Ý¤Îµ¡Ç½¤Ï¡¢ÇÛÉÛ¤ò½ªÎ»¤·¤Æ¤ª¤ê¤Þ¤¹¡£");
+	}
+	
+	if($flg_ok) {
+		// ¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤òºï½ü¤¹¤ë¡£
+		$sqlval['now_version'] = "";
+		$sqlval['update_date'] = "now()";
+		$objQuery->update("dtb_update", $sqlval, "module_id = ?", array($arrRet[0]['module_id']));
+	}
+}
+
+
+?>
