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

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