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

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