source: temp/trunk/html/admin/system/update.php @ 6309

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