OSDN Git Service

FIX: super-admin disallowed from uploading files if not on any teamlists.
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / upgrades / upgrade.functions.php
1 <?php
2
3     /*
4      * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5      * Copyright (C) 2002-2009 The Nucleus Group
6      *
7      * This program is free software; you can redistribute it and/or
8      * modify it under the terms of the GNU General Public License
9      * as published by the Free Software Foundation; either version 2
10      * of the License, or (at your option) any later version.
11      * (see nucleus/documentation/index.html#license for more info)
12      */
13     /**
14      * Some functions common to all upgrade scripts
15      *
16      * @license http://nucleuscms.org/license.txt GNU General Public License
17      * @copyright Copyright (C) 2002-2009 The Nucleus Group
18      * @version $Id$
19      * $NucleusJP: upgrade.functions.php,v 1.10 2007/04/26 06:20:19 kimitake Exp $
20      */
21
22 /*************************************************************
23  *     NOTE: With upgrade to 3.6, need to set this to use sql_* API           *
24  **************************************************************/
25
26     include('../../config.php');
27
28     // sql_table function did not exists in nucleus <= 2.0
29     if (!function_exists('sql_table'))
30     {
31         function sql_table($name) {
32             return 'nucleus_' . $name;
33         }
34     }
35
36     //intGetVar did not exist in very early versions
37     if (!function_exists('intGetVar')) {
38         function intGetVar($name) {
39             if (defined($_GET)) {
40                 return intval($_GET[$name]);
41             } else {
42                 global $HTTP_GET_VARS;
43                 return intval($HTTP_GET_VARS[$name]);
44             }
45         }
46     }
47
48     function upgrade_checkinstall($version) {
49         $installed = 0;
50
51         switch($version) {
52             case '95':
53                 $query = 'SELECT bconvertbreaks FROM '.sql_table('blog').' LIMIT 1';
54                 $minrows = -1;
55                 break;
56             case '96':
57                 $query = 'SELECT cip FROM '.sql_table('comment').' LIMIT 1';
58                 $minrows = -1;
59                 break;
60             case '100':
61                 $query = 'SELECT mcookiekey FROM '.sql_table('member').' LIMIT 1';
62                 $minrows = -1;
63                 break;
64             case '110':
65                 $query = 'SELECT bnotifytype FROM '.sql_table('blog').' LIMIT 1';
66                 $minrows = -1;
67                 break;
68             case '150':
69                 $query = 'SELECT * FROM '.sql_table('plugin_option').' LIMIT 1';
70                 $minrows = -1;
71                 break;
72             case '200':
73                 $query = 'SELECT sdincpref FROM '.sql_table('skin_desc').' LIMIT 1';
74                 $minrows = -1;
75                 break;
76             // dev only (v2.2)
77             case '220':
78                 $query = 'SELECT oid FROM '.sql_table('plugin_option_desc').' LIMIT 1';
79                 $minrows = -1;
80                 break;
81             // v2.5 beta
82             case '240':
83                 $query = 'SELECT bincludesearch FROM ' . sql_table('blog') . ' LIMIT 1';
84                 $minrows = -1;
85                 break;
86             case '250':
87                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 250 LIMIT 1';
88                 $minrows = 1;
89                 break;
90             case '300':
91                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 300 LIMIT 1';
92                 $minrows = 1;
93                 break;
94             case '310':
95                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 310 LIMIT 1';
96                 $minrows = 1;
97                 break;
98             case '320':
99                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 320 LIMIT 1';
100                 $minrows = 1;
101                 break;
102             case '330':
103                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 330 LIMIT 1';
104                 $minrows = 1;
105                 break;
106             case '331':
107                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 331 LIMIT 1';
108                 $minrows = 1;
109                 break;
110             case '340':
111                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 340 LIMIT 1';
112                 $minrows = 1;
113                 break;
114             case '350':
115                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 350 LIMIT 1';
116                 $minrows = 1;
117                 break;
118         }
119
120         $res = mysql_query($query);
121         $installed = ($res != 0) && (mysql_num_rows($res) >= $minrows);
122
123         return $installed;
124     }
125
126
127     /** this function gets the nucleus version, even if the getNucleusVersion
128      * function does not exist yet
129      * return 96 for all versions < 100
130      */
131     function upgrade_getNucleusVersion() {
132         if (!function_exists('getNucleusVersion')) return 96;
133         return getNucleusVersion();
134     }
135
136     function upgrade_showLogin($type) {
137         upgrade_head();
138     ?>
139         <h1>まずはログインして下さい</h1>
140         <p>下記の情報を入力して下さい:</p>
141
142         <form method="post" action="<?php echo $type?>">
143
144             <ul>
145                 <li>名前: <input name="login" /></li>
146                 <li>パスワード <input name="password" type="password" /></li>
147             </ul>
148
149             <p>
150                 <input name="action" value="login" type="hidden" />
151                 <input type="submit" value="ログイン" />
152             </p>
153
154         </form>
155     <?php       upgrade_foot();
156         exit;
157     }
158
159     function upgrade_head() {
160     ?>
161             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
162             <html xmlns="http://www.w3.org/1999/xhtml">
163             <head>
164                 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
165                 <title>Nucleus アップグレード</title>
166 <?php if (file_exists("../styles/manual.css")) { ?>
167                 <link rel="stylesheet" href="../styles/manual.css" type="text/css" />
168 <?php }else{ ?>
169                 <style type="text/css"><!--
170                     .warning {
171                         color: red;
172                     }
173                     .ok {
174                         color: green;
175                     }
176                 --></style>
177 <?php } ?>
178             </head>
179             <body>
180     <?php   }
181
182     function upgrade_foot() {
183     ?>
184             </body>
185             </html>
186     <?php   }
187
188     function upgrade_error($msg) {
189         upgrade_head();
190         ?>
191         <h1>エラー!</h1>
192
193         <p>メッセージは以下の通り:</p>
194
195         <blockquote><div>
196         <?php echo $msg?>
197         </div></blockquote>
198
199         <p><a href="index.php" onclick="history.back();">戻る</a></p>
200         <?php
201         upgrade_foot();
202         exit;
203     }
204
205
206     function upgrade_start() {
207         global $upgrade_failures;
208         $upgrade_failures = 0;
209
210         upgrade_head();
211         ?>
212         <h1>アップグレードの実行</h1>
213         <ul>
214         <?php   }
215
216     function upgrade_end($msg = "") {
217         global $upgrade_failures;
218         $from = intGetVar('from');
219         if ($upgrade_failures > 0)
220             $msg = "いくつかのデータベース操作に失敗しました。もし以前にこのアップグレードスクリプトを実行していたのであれば、問題ないと思われます。";
221
222         ?>
223         </ul>
224
225         <h1>アップグレード完了!</h1>
226
227         <p><?php echo $msg?></p>
228
229         <p><a href="index.php?from=<?php echo $from; ?>">アップグレード最初のページ</a>にもどる</p>
230
231         <?php
232         upgrade_foot();
233         exit;
234     }
235
236     /**
237       * Tries to execute a query, gives a message when failed
238       *
239       * @param friendly name
240       * @param query
241       */
242     function upgrade_query($friendly, $query) {
243         global $upgrade_failures;
244
245         echo "<li>$friendly ... ";
246         $res = mysql_query($query);
247         if (!$res) {
248             echo "<span style='color:red'>失敗</span>\n";
249             echo "<blockquote>失敗の理由: " . mysql_error() . " </blockquote>";
250             $upgrade_failures++;
251         } else {
252             echo "<span style='color:green'>成功!</span><br />\n";
253         }
254         echo "</li>";
255         return $res;
256     }
257
258     /**
259       * Tries to update database version, gives a message when failed
260       *
261       * @param $version
262       *     Schema version the database has been upgraded to
263       */
264     function update_version($version) {
265         global $upgrade_failures;
266         $message='Updating DatabaseVersion in config table to '.$version;
267         if(0==$upgrade_failures){
268             $query = 'UPDATE ' . sql_table('config') . ' set value=\''.$version.'\' where name=\'DatabaseVersion\'';
269             upgrade_query($message, $query);
270         }else
271             echo '<li>'.$message.' ... <span class="warning">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>';
272     }
273
274     /**
275      * @param $table
276      *      table to check (without prefix)
277      * @param $aColumns
278      *      array of column names included
279      */
280     function upgrade_checkIfIndexExists($table, $aColumns) {
281         // get info for indices from database
282
283         $aIndices = array();
284         $query = 'show index from ' . sql_table($table);
285         $res = mysql_query($query);
286         while ($o = mysql_fetch_object($res)) {
287             if (!$aIndices[$o->Key_name]) {
288                 $aIndices[$o->Key_name] = array();
289             }
290             array_push($aIndices[$o->Key_name], $o->Column_name);
291         }
292
293         // compare each index with parameter
294         foreach ($aIndices as $keyName => $aIndexColumns) {
295             $aDiff = array_diff($aIndexColumns, $aColumns);
296             if (count($aDiff) == 0) return 1;
297         }
298
299         return 0;
300
301     }
302
303     /**
304       * Checks to see if a given table exists
305       *
306       * @param $table
307       *     Name of table to check for existance of
308       *     Uses sql_table internally
309       * @return true if table exists, false otherwise.
310       */
311     function upgrade_checkIfTableExists($table){
312         $query = 'SHOW TABLES LIKE \''.sql_table($table).'\'';
313         $res = mysql_query($query);
314         return ($res != 0) && (mysql_num_rows($res) == 1);
315     }
316
317     /**
318       * Checks to see if a given configuration value exists
319       *
320       * @param $value
321       *     Config value to check for existance of.
322       *     Paramater must be MySQL escaped
323       * @return true if configuration value exists, false otherwise.
324       */
325     function upgrade_checkIfCVExists($value){
326         $query = 'SELECT name from '.sql_table('config').' WHERE name = \''.$value.'\'';
327         $res = mysql_query($query);
328         return ($res != 0) && (mysql_num_rows($res) == 1);
329     }
330
331     /**
332       * Checks to see if a given column exists
333       *
334       * @param $table
335       *     Name of table to check for column in
336       *     Uses sql_table internally
337       * @param $col
338       *     Name of column to check for existance of
339       * @return true if column exists, false otherwise.
340       */
341     function upgrade_checkIfColumnExists($table, $col){
342         $query = 'DESC `'.sql_table($table).'` `'.$col.'`';
343         $res = mysql_query($query);
344         return ($res != 0) && (mysql_num_rows($res) == 1);
345     }
346 ?>