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

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