Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/update.php,v $
15
  $Revision: 1.9 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
 
20
// Report all errors except E_NOTICE
21
// This is the default value set in php.ini
22
error_reporting (E_ALL ^ E_NOTICE);
23
 
24
require ('include/sql_parse.php');
25
require ('include/config.inc.php');
26
// ---------------------------- TEST PREREQUIRED --------------------------- //
27
function test_fs()
28
{
29
    global $errors, $DFLT;
30
    // No Filesystem Updates yet
31
}
32
 
33
function update_system_thumbs()
34
{
35
    global $CONFIG;
36
 
37
    $results = mysql_query("SELECT * FROM ".$CONFIG['TABLE_PREFIX']."config;");
38
    while ($row = mysql_fetch_array($results)) {
39
        $CONFIG[$row['name']] = $row['value'];
40
    } // while
41
    mysql_free_result($results);
42
 
43
    // Code to rename system thumbs in images folder (except nopic.jpg and private.jpg)
44
    $old_thumb_pfx = 'thumb_';
45
 
46
    if ($old_thumb_pfx != $CONFIG['thumb_pfx']) {
47
        $folders = array('images/', $THEME_DIR.'images/');
48
        foreach ($folders as $folder) {
49
            $thumbs = cpg_get_system_thumb_list($folder);
50
            foreach ($thumbs as $thumb) {
51
                @rename($folder.$thumb['filename'],
52
                        $folder.str_replace($old_thumb_pfx,$CONFIG['thumb_pfx'],$thumb['filename']));
53
            }
54
        }
55
    }
56
}
57
 
58
/**
59
 * Return an array containing the system thumbs in a directory
60
 */
61
function cpg_get_system_thumb_list($search_folder = 'images/')
62
{
63
        global $CONFIG;
64
        static $thumbs = array();
65
 
66
        $folder = 'images/';
67
 
68
        $thumb_pfx =& $CONFIG['thumb_pfx'];
69
        // If thumb array is empty get list from coppermine 'images' folder
70
        if ((count($thumbs) == 0) && ($folder == $search_folder)) {
71
                $dir = opendir($folder);
72
                while (($file = readdir($dir))!==false) {
73
                        if (is_file($folder . $file) && strpos($file,$thumb_pfx) === 0) {
74
                                // Store filenames in an array
75
                                $thumbs[] = array('filename' => $file);
76
                        }
77
                }
78
                closedir($dir);
79
                return $thumbs;
80
        } elseif ($folder == $search_folder) {
81
                // Search folder is the same as coppermine images folder; just return the array
82
                return $thumbs;
83
        } else {
84
                // Search folder is the different; check for files in the given folder
85
                $results = array();
86
                foreach ($thumbs as $thumb) {
87
                        if (is_file($search_folder.$thumb['filename'])) {
88
                                $results[] = array('filename' => $thumb['filename']);
89
                        }
90
                }
91
                return $results;
92
        }
93
}
94
 
95
// ----------------------------- TEST FUNCTIONS ---------------------------- //
96
function test_sql_connection()
97
{
98
    global $errors, $HTTP_POST_VARS, $CONFIG;
99
 
100
    if (! $connect_id = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass'])) {
101
        $errors .= "<hr /><br />Could not create a mySQL connection, please check the SQL values in include/config.inc.php<br /><br />MySQL error was : " . mysql_error() . "<br /><br />";
102
    } elseif (! mysql_select_db($CONFIG['dbname'], $connect_id)) {
103
        $errors .= "<hr /><br />mySQL could not locate a database called '{$CONFIG['dbname']}' please check the value entered for this in include/config.inc.php<br /><br />";
104
    }
105
}
106
// ------------------------- HTML OUTPUT FUNCTIONS ------------------------- //
107
function html_header()
108
{
109
 
110
    ?>
111
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
112
<html>
113
<head>
114
<title>Coppermine - Upgrade</title><link type="text/css" rel="stylesheet" href="installer.css">
115
</head>
116
<body>
117
 <div align="center">
118
  <div style="width:600px;">
119
<?php
120
}
121
 
122
function html_logo()
123
{
124
 
125
    ?>
126
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
127
       <tr>
128
        <td valign="top" bgcolor="#EFEFEF"><img src="images/logo.gif"><br />
129
        </td>
130
       </tr>
131
      </table>
132
<?php
133
}
134
 
135
function html_prereq_errors($error_msg)
136
{
137
 
138
    ?>
139
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
140
       <tr>
141
            <form action="install.php">
142
        <td class="tableh1" colspan="2"><h2>Welcome to Coppermine installation</h2>
143
        </td>
144
       </tr>
145
       <tr>
146
        <td class="tableh2" colspan="2" align="center"><span class="error">&#149;&nbsp;&#149;&nbsp;&#149;&nbsp;ERROR&nbsp;&#149;&nbsp;&#149;&nbsp;&#149;</span>
147
        </td>
148
       </tr>
149
       <tr>
150
        <td class="tableb" colspan="2"> Before you continue with the Coppermine upgrade, there are some problems that need to be fixed.<br /><br /><b><?php echo $error_msg ?></b>Once you are done, hit the "Try again" button.<br />
151
        </td>
152
       </tr>
153
       <tr>
154
        <td colspan="2" align="center"><br />
155
                <input type="submit" value="Try again !"><br /><br />
156
        </td>
157
                </form>
158
       </tr>
159
      </table>
160
<?php
161
}
162
 
163
function html_error($error_msg = '')
164
{
165
    global $HTTP_POST_VARS, $im_installed;
166
 
167
    ?>
168
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
169
       <tr>
170
            <form action="upgrade.php" method="post">
171
        <td class="tableh1" colspan="2"><h2>Welcome to the Coppermine upgrade program</h2>
172
        </td>
173
       </tr>
174
<?php
175
    if ($error_msg) {
176
 
177
        ?>
178
       <tr>
179
        <td class="tableh2" colspan="2" align="center"><span class="error">&#149;&nbsp;&#149;&nbsp;&#149;&nbsp;ERROR&nbsp;&#149;&nbsp;&#149;&nbsp;&#149;</span>
180
        </td>
181
       </tr>
182
       <tr>
183
        <td class="tableb" colspan="2"> The following errors were encountered and need to be corrected first:<br /><br /><b><?php echo $error_msg ?></b>
184
        </td>
185
       </tr>
186
<?php
187
    }
188
 
189
    ?>
190
 
191
       </tr>
192
      </table>
193
<?php
194
}
195
 
196
function html_install_success($notes)
197
{
198
    global $DFLT, $HTTP_POST_VARS;
199
 
200
    ?>
201
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
202
       <tr>
203
            <td class="tableh1" colspan="2"><h2>Upgrade completed</h2>
204
        </td>
205
       </tr>
206
       <tr>
207
        <td class="tableb" colspan="2"> Coppermine is now upgraded and ready to roll.<br /><?php echo $notes ?>
208
        </td>
209
       </tr>
210
       <tr>
211
        <td colspan="2" align="center" class="tableh2"><br />
212
                <a href="index.php">Let's continue !</a><br />
213
        </td>
214
                </form>
215
       </tr>
216
      </table>
217
<?php
218
}
219
 
220
function html_footer()
221
{
222
 
223
    ?>
224
  </div>
225
 </div>
226
</body>
227
</html>
228
<noscript><plaintext>
229
<?php
230
}
231
// ------------------------- SQL QUERIES TO CREATE TABLES ------------------ //
232
function update_tables()
233
{
234
    global $HTTP_POST_VARS, $HTTP_SERVER_VARS, $errors, $CONFIG;
235
 
236
    $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
237
    $gallery_dir = strtr(dirname($PHP_SELF), '\\', '/');
238
    $gallery_url_prefix = 'http://' . $HTTP_SERVER_VARS['HTTP_HOST'] . $gallery_dir . (substr($gallery_dir, -1) == '/' ? '' : '/');
239
 
240
    $db_update = 'sql/update.sql';
241
    $sql_query = fread(fopen($db_update, 'r'), filesize($db_update));
242
    // Update table prefix
243
    $sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);
244
 
245
    $sql_query = remove_remarks($sql_query);
246
    $sql_query = split_sql_file($sql_query, ';');
247
 
248
    ?>
249
        <table class="maintable">
250
    <tr>
251
      <th colspan=2 class="tableh1">Performing Database Updates</th>
252
    </tr>
253
 <?php
254
 
255
    foreach($sql_query as $q) {
256
        echo "<tr><td class='tableb'>$q</td>";
257
        if (mysql_query($q)) {
258
            echo "<td class='updatesOK'>OK</td>";
259
        } else {
260
            echo "<td class='updatesFail'>Already Done</td>";
261
        }
262
    }
263
}
264
// --------------------------------- MAIN CODE ----------------------------- //
265
// The defaults values
266
$table_prefix = $HTTP_POST_VARS['table_prefix'];
267
$DFLT = array('lck_f' => 'install.lock', // Name of install lock file
268
    'cfg_d' => 'include', // The config file dir
269
    'cfg_f' => 'include/config.inc.php', // The config file name
270
    'alb_d' => 'albums', // The album dir
271
    'upl_d' => 'userpics' // The uploaded pic dir
272
    );
273
 
274
$errors = '';
275
$notes = '';
276
// The installer
277
html_header();
278
html_logo();
279
 
280
test_fs();
281
if ($errors != '')
282
    html_prereq_errors($errors);
283
else {
284
    test_sql_connection();
285
    if ($errors == '') {
286
        update_tables();
287
        update_system_thumbs();
288
    } else {
289
        html_error($errors);
290
    }
291
    if ($errors == '') {
292
        html_install_success($notes);
293
    } else {
294
        html_error($errors);
295
    }
296
}
297
 
298
html_footer();
299
 
300
?>