source: temp/trunk/html/admin/system/module.php @ 6652

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