source: temp/trunk/html/admin/downloads/module/module.php @ 6434

Revision 6434, 7.4 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/* @version    CVS: $Id$ */
4
5require_once("../../require.php");
6
7//¥Ú¡¼¥¸´ÉÍý¥¯¥é¥¹
8class LC_Page {
9    //¥³¥ó¥¹¥È¥é¥¯¥¿
10    function LC_Page() {
11        //¥á¥¤¥ó¥Æ¥ó¥×¥ì¡¼¥È¤Î»ØÄê
12        $this->tpl_mainpage = HTML_PATH . 'admin/downloads/module/module.tpl';
13        $this->tpl_subnavi = 'system/subnavi.tpl';
14        $this->tpl_mainno = 'system';       
15        $this->tpl_subno = 'module';
16        $this->tpl_subtitle = '¥â¥¸¥å¡¼¥ë´ÉÍý';
17    }
18}
19
20$objPage = new LC_Page();
21$objView = new SC_AdminView();
22$objQuery = new SC_Query();
23
24// ¥»¥Ã¥·¥ç¥ó¥¯¥é¥¹
25$objSess = new SC_Session();
26// ǧ¾Ú²ÄÈݤÎȽÄê
27sfIsSuccess($objSess);
28
29switch($_POST['mode']) {
30// ¥¢¥Ã¥×¥Ç¡¼¥È¾ðÊó¥Õ¥¡¥¤¥ë¤ò¼èÆÀ
31case 'edit':
32    // ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
33    lfLoadUpdateList();
34    break;
35// ¥¤¥ó¥¹¥È¡¼¥ë
36case 'install':
37    // ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
38    lfLoadUpdateList();
39    // ¥â¥¸¥å¡¼¥ë·´¤Î¥¤¥ó¥¹¥È¡¼¥ë
40    lfInstallModule();
41    break;
42// ¥¢¥ó¥¤¥ó¥¹¥È¡¼¥ë
43case 'uninstall':
44    // ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
45    lfLoadUpdateList();
46    // ¥â¥¸¥å¡¼¥ë·´¤Î¥¤¥ó¥¹¥È¡¼¥ë   
47    lfUninstallModule();
48    break;
49default:
50    break;
51}
52
53$col = "module_id, module_name, now_version, latest_version, module_explain, create_date, release_date";
54$objQuery->setorder("module_id");
55$objPage->arrUpdate = $objQuery->select($col, "dtb_update");
56
57$objView->assignobj($objPage);      //ÊÑ¿ô¤ò¥Æ¥ó¥×¥ì¡¼¥È¤Ë¥¢¥µ¥¤¥ó¤¹¤ë
58$objView->display(MAIN_FRAME);      //¥Æ¥ó¥×¥ì¡¼¥È¤Î½ÐÎÏ
59//-------------------------------------------------------------------------------------------------------
60// ¹¹¿·¥Õ¥¡¥¤¥ë¤Î¼èÆÀ
61function lfCopyUpdateFile($file) {
62    global $objPage;
63   
64    $src_path = sfRmDupSlash(UPDATE_HTTP . $file . ".txt");
65    $dst_path = sfRmDupSlash(DATA_PATH . $file);
66    $flg_ok = true; // ½èÍý¤ÎÀ®¸ùȽÄê
67   
68    $src_fp = @fopen($src_path, "rb");
69   
70    if(!$src_fp) {
71        sfErrorHeader(">> " . $src_path . "¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
72        $flg_ok = false;
73    } else {
74        // ¥Õ¥¡¥¤¥ë¤ò¤¹¤Ù¤ÆÆÉ¤ß¹þ¤à
75        $contents = '';
76        while (!feof($src_fp)) {
77            $contents .= fread($src_fp, 1024);
78        }
79        fclose($src_fp);
80       
81        // ¥Ç¥£¥ì¥¯¥È¥êºîÀ®¤ò»î¤ß¤ë
82        lfMakeDirectory($dst_path);
83        // ¥Õ¥¡¥¤¥ë½ñ¹þ¤ß       
84        $dst_fp = @fopen($dst_path, "wb");
85        if(!$dst_fp) {
86            sfErrorHeader(">> " . $dst_path . "¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
87            $flg_ok = false;
88        } else {
89            fwrite($dst_fp, $contents);
90            fclose($dst_fp);
91        }
92    }
93   
94    if($flg_ok) {
95        $objPage->update_mess.= ">> " . $dst_path . "¡§¥³¥Ô¡¼À®¸ù<br>";
96    } else {
97        $objPage->update_mess.= ">> " . $dst_path . "¡§¥³¥Ô¡¼¼ºÇÔ<br>";     
98    }
99   
100    return $flg_ok;
101}
102
103// ¤¹¤Ù¤Æ¤Î¥Ñ¥¹¤Î¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¤¹¤ë
104function lfMakeDirectory($path) {
105    $pos = 0;
106    $cnt = 0;               // ̵¸Â¥ë¡¼¥×Âкö
107    $len = strlen($path);   // ̵¸Â¥ë¡¼¥×Âкö
108   
109    while($cnt <= $len) {
110        $pos = strpos($path, "/", $pos);
111        // ¤³¤³¤Ç¤ÎȽÄê¤Ï¡¢Åù¹æ3¤Ä¤ò»ÈÍÑ
112        if($pos === false) {
113            // ¥¹¥é¥Ã¥·¥å¤¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï¥ë¡¼¥×¤«¤éÈ´¤±¤ë
114            break;
115        }
116        $pos++; // ʸ»úȯ¸«°ÌÃÖ¤ò°ìʸ»ú¿Ê¤á¤ë
117        $dir = substr($path, 0, $pos);
118       
119        // ¤¹¤Ç¤Ë¸ºß¤¹¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë
120        if(!file_exists($dir)) {
121            mkdir($dir);
122        }
123        $cnt++; // ̵¸Â¥ë¡¼¥×Âкö
124    }
125}
126
127// ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
128function lfLoadUpdateList() {
129    $objQuery = new SC_Query();
130    $path = UPDATE_HTTP . "update.txt";
131    $fp = @fopen($path, "rb");
132
133    if(!$fp) {
134        sfErrorHeader(">> " . $path . "¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
135    } else {
136        while (!feof($fp)) {
137            $arrCSV = fgetcsv($fp, UPDATE_CSV_LINE_MAX);
138            // ¥«¥é¥à¿ô¤¬Àµ¾ï¤Ç¤¢¤Ã¤¿¾ì¹ç¤Î¤ß
139            if(count($arrCSV) == UPDATE_CSV_COL_MAX) {
140                // ¼èÆÀ¤·¤¿¥¢¥Ã¥×¥Ç¡¼¥È¾ðÊó¤òDB¤Ë½ñ¤­¹þ¤à
141                $sqlval['module_id'] = $arrCSV[0];
142                $sqlval['module_name'] = $arrCSV[1];
143                $sqlval['latest_version'] = $arrCSV[3];
144                $sqlval['module_explain'] = $arrCSV[4];
145                $sqlval['main_php'] = $arrCSV[5];
146                $sqlval['extern_php'] = $arrCSV[6];
147                $sqlval['install_sql'] = $arrCSV[7];
148                $sqlval['uninstall_sql'] = $arrCSV[8];             
149                $sqlval['other_files'] = $arrCSV[9];
150                $sqlval['del_flg'] = $arrCSV[10];
151                $sqlval['update_date'] = "now()";
152                $sqlval['release_date'] = $arrCSV[12];
153                // ´û¸¥ì¥³¡¼¥É¤Î¥Á¥§¥Ã¥¯
154                $cnt = $objQuery->count("dtb_update", "module_id = ?", array($sqlval['module_id']));
155                if($cnt > 0) {
156                    // ¤¹¤Ç¤Ë¼èÆÀ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¹¹¿·¤¹¤ë¡£
157                    $objQuery->update("dtb_update", $sqlval, "module_id = ?", array($sqlval['module_id']));
158                } else {
159                    // ¿·µ¬¥ì¥³¡¼¥É¤ÎÄɲÃ
160                    $sqlval['create_date'] = "now()";
161                    $objQuery->insert("dtb_update", $sqlval);
162                }
163            } else {
164                sfErrorHeader(">> ¥«¥é¥à¿ô¤¬°ìÃפ·¤Þ¤»¤ó¡£¡§".count($arrCSV));
165            }
166        }
167        fclose($fp);
168    }
169}
170
171// ¥¤¥ó¥¹¥È¡¼¥ë½èÍý
172function lfInstallModule() {
173    global $objPage;
174   
175    $objQuery = new SC_Query();
176    $arrRet = $objQuery->select("module_id, extern_php, other_files, install_sql, latest_version", "dtb_update", "module_id = ?", array($_POST['module_id']));
177    $flg_ok = true; // ½èÍý¤ÎÀ®¸ùȽÄê
178   
179    if(count($arrRet) > 0) {
180        $arrFiles = array();
181        if($arrRet[0]['other_files'] != "") {
182            $arrFiles = split("\|", $arrRet[0]['other_files']);
183        }
184        $arrFiles[] = $arrRet[0]['extern_php'];
185        foreach($arrFiles as $val) {
186            // ¹¹¿·¥Õ¥¡¥¤¥ë¤Î¼èÆÀ
187            $ret=lfCopyUpdateFile($val);
188            if(!$ret) {
189                $flg_ok = false;
190            }
191        }
192    } else {
193        sfErrorHeader(">> Âоݤε¡Ç½¤Ï¡¢ÇÛÉÛ¤ò½ªÎ»¤·¤Æ¤ª¤ê¤Þ¤¹¡£");
194        $flg_ok = false;
195    }
196   
197    // ɬÍפÊSQLʸ¤Î¼Â¹Ô
198    if($arrRet[0]['install_sql'] != "") {
199        // SQLʸ¼Â¹Ô¡¢¥Ñ¥é¡¼¥á¡¼¥¿¤Ê¤·¡¢¥¨¥é¡¼Ìµ»ë
200        $arrInstallSql = split(";",$arrRet[0]['install_sql']);
201        foreach($arrInstallSql as $key => $val){
202            if (trim($val) != ""){
203                $ret = $objQuery->query(trim($val),"",true);
204            }
205        }
206        if(DB::isError($ret)) {
207            // ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
208            ereg("\[(.*)\]", $ret->userinfo, $arrKey);
209            $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";
210            $objPage->update_mess.= $arrKey[0] . "<br>";
211            $flg_ok = false;
212        } else {
213            $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤ò¹Ô¤¤¤Þ¤·¤¿¡£<br>";
214        }
215    }
216   
217    if($flg_ok) {
218        $sqlval['now_version'] = $arrRet[0]['latest_version'];
219        $sqlval['update_date'] = "now()";
220        $objQuery->update("dtb_update", $sqlval, "module_id = ?", array($arrRet[0]['module_id']));
221    }
222}
223
224// ¥¢¥ó¥¤¥ó¥¹¥È¡¼¥ë½èÍý
225function lfUninstallModule() {
226    global $objPage;
227   
228    $objQuery = new SC_Query();
229    $arrRet = $objQuery->select("module_id, extern_php, other_files, install_sql, uninstall_sql, latest_version", "dtb_update", "module_id = ?", array($_POST['module_id']));
230    $flg_ok = true; // ½èÍý¤ÎÀ®¸ùȽÄê
231   
232    if(count($arrRet) > 0) {
233        $arrFiles = array();
234        if($arrRet[0]['other_files'] != "") {
235            $arrFiles = split("\|", $arrRet[0]['other_files']);
236        }
237        $arrFiles[] = $arrRet[0]['extern_php'];
238        foreach($arrFiles as $val) {
239            $path = DATA_PATH . $val;
240            if(file_exists($path)) {
241                // ¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë
242                if(unlink($path)) {
243                    $objPage->update_mess.= ">> " . $path . "¡§ºï½üÀ®¸ù<br>";
244                } else {
245                    $objPage->update_mess.= ">> " . $path . "¡§ºï½ü¼ºÇÔ<br>";
246                }
247            }
248        }
249       
250        // ɬÍפÊSQLʸ¤Î¼Â¹Ô
251        if($arrRet[0]['uninstall_sql'] != "") {
252            // SQLʸ¼Â¹Ô¡¢¥Ñ¥é¡¼¥á¡¼¥¿¤Ê¤·¡¢¥¨¥é¡¼Ìµ»ë
253            $ret = $objQuery->query($arrRet[0]['uninstall_sql'],"",true);
254            if(DB::isError($ret)) {
255                // ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
256                ereg("\[(.*)\]", $ret->userinfo, $arrKey);
257                $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";
258                $objPage->update_mess.= $arrKey[0] . "<br>";
259                $flg_ok = false;
260            } else {
261                $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤ò¹Ô¤¤¤Þ¤·¤¿¡£<br>";
262            }
263        }       
264    } else {
265        sfErrorHeader(">> Âоݤε¡Ç½¤Ï¡¢ÇÛÉÛ¤ò½ªÎ»¤·¤Æ¤ª¤ê¤Þ¤¹¡£");
266    }
267   
268    if($flg_ok) {
269        // ¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤òºï½ü¤¹¤ë¡£
270        $sqlval['now_version'] = "";
271        $sqlval['update_date'] = "now()";
272        $objQuery->update("dtb_update", $sqlval, "module_id = ?", array($arrRet[0]['module_id']));
273    }
274}
275
276
277?>
Note: See TracBrowser for help on using the repository browser.