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

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