Subversion Repositories svnkaklik

Rev

Go to most recent revision | 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/config.php,v $
15
  $Revision: 1.13 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:10 $
18
**********************************************/
19
 
20
define('IN_COPPERMINE', true);
21
define('CONFIG_PHP', true);
22
 
23
require('include/init.inc.php');
24
require('include/sql_parse.php');
25
 
26
if (!GALLERY_ADMIN_MODE) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
27
 
28
function form_label($text)
29
{
30
    echo <<<EOT
31
        <tr>
32
                <td class="tableh2" colspan="2">
33
                        <b>$text</b>
34
                </td>
35
        </tr>
36
 
37
EOT;
38
}
39
 
40
function form_input($text, $name)
41
{
42
    global $CONFIG;
43
 
44
    $value = $CONFIG[$name];
45
 
46
    echo <<<EOT
47
        <tr>
48
            <td width="60%" class="tableb">
49
                        $text
50
        </td>
51
        <td width="40%" class="tableb" valign="top">
52
                <input type="text" maxlength="255" class="textinput" style="width: 100%" name="$name" value="$value">
53
                </td>
54
        </tr>
55
 
56
EOT;
57
}
58
 
59
function form_yes_no($text, $name)
60
{
61
    global $CONFIG, $lang_yes, $lang_no;
62
 
63
    $value = $CONFIG[$name];
64
    $yes_selected = $value ? 'checked="checked"' : '';
65
    $no_selected = !$value ? 'checked="checked"' : '';
66
 
67
    echo <<<EOT
68
        <tr>
69
            <td class="tableb">
70
                        $text
71
        </td>
72
        <td class="tableb" valign="top">
73
                        <input type="radio" id="{$name}1" name="$name" value="1" $yes_selected /><label for="{$name}1" class="clickable_option">$lang_yes</label>
74
                        &nbsp;&nbsp;
75
                        <input type="radio" id="{$name}0" name="$name" value="0" $no_selected /><label for="{$name}0" class="clickable_option">$lang_no</label>
76
                </td>
77
        </tr>
78
 
79
EOT;
80
}
81
 
82
function form_img_pkg($text, $name)
83
{
84
    global $CONFIG;
85
 
86
    $value = $CONFIG[$name];
87
    $im_selected = ($value == 'im') ? 'selected' : '';
88
    $gd1_selected = ($value == 'gd1') ? 'selected' : '';
89
    $gd2_selected = ($value == 'gd2') ? 'selected' : '';
90
 
91
    echo <<<EOT
92
        <tr>
93
            <td class="tableb">
94
                        $text
95
        </td>
96
        <td class="tableb" valign="top">
97
                        <select name="$name" class="listbox">
98
                                <option value="im" $im_selected>Image Magick</option>
99
                                <option value="gd1" $gd1_selected>GD version 1.x</option>
100
                                <option value="gd2" $gd2_selected>GD version 2.x</option>
101
                        </select>
102
                </td>
103
        </tr>
104
 
105
EOT;
106
}
107
 
108
function form_sort_order($text, $name)
109
{
110
    global $CONFIG, $lang_config_php;
111
 
112
    $value = $CONFIG[$name];
113
    $ta_selected = ($value == 'ta') ? 'selected' : '';
114
    $td_selected = ($value == 'td') ? 'selected' : '';
115
    $na_selected = ($value == 'na') ? 'selected' : '';
116
    $nd_selected = ($value == 'nd') ? 'selected' : '';
117
    $da_selected = ($value == 'da') ? 'selected' : '';
118
    $dd_selected = ($value == 'dd') ? 'selected' : '';
119
 
120
    echo <<<EOT
121
        <tr>
122
            <td class="tableb">
123
                        $text
124
        </td>
125
        <td class="tableb" valign="top">
126
                        <select name="$name" class="listbox">
127
                                <option value="ta" $ta_selected>{$lang_config_php['title_a']}</option>
128
                                <option value="td" $td_selected>{$lang_config_php['title_d']}</option>
129
                                <option value="na" $na_selected>{$lang_config_php['name_a']}</option>
130
                                <option value="nd" $nd_selected>{$lang_config_php['name_d']}</option>
131
                                <option value="da" $da_selected>{$lang_config_php['date_a']}</option>
132
                                <option value="dd" $dd_selected>{$lang_config_php['date_d']}</option>
133
                        </select>
134
                </td>
135
        </tr>
136
 
137
EOT;
138
}
139
 
140
function form_charset($text, $name)
141
{
142
    global $CONFIG;
143
 
144
    $charsets = array('Default' => 'language file',
145
        'Arabic' => 'iso-8859-6',
146
        'Baltic' => 'iso-8859-4',
147
        'Central European' => 'iso-8859-2',
148
        'Chinese Simplified' => 'euc-cn',
149
        'Chinese Traditional' => 'big5',
150
        'Cyrillic' => 'koi8-r',
151
        'Greek' => 'iso-8859-7',
152
        'Hebrew' => 'iso-8859-8-i',
153
        'Icelandic' => 'x-mac-icelandic',
154
        'Japanese' => 'euc-jp',
155
        'Korean' => 'euc-kr',
156
        'Maltese' => 'iso-8859-3',
157
        'Thai' => 'windows-874 ',
158
        'Turkish' => 'iso-8859-9',
159
        'Unicode' => 'utf-8',
160
        'Vietnamese' => 'windows-1258',
161
        'Western' => 'iso-8859-1'
162
        );
163
 
164
    $value = strtolower($CONFIG[$name]);
165
 
166
    echo <<<EOT
167
        <tr>
168
            <td class="tableb">
169
                        $text
170
        </td>
171
        <td class="tableb" valign="top">
172
                        <select name="$name" class="listbox">
173
 
174
EOT;
175
    foreach ($charsets as $country => $charset) {
176
        echo "                                <option value=\"$charset\" " . ($value == $charset ? 'selected' : '') . ">$country ($charset)</option>\n";
177
    }
178
    echo <<<EOT
179
                        </select>
180
                </td>
181
        </tr>
182
 
183
EOT;
184
}
185
 
186
function form_language($text, $name)
187
{
188
    global $CONFIG;
189
 
190
    $value = strtolower($CONFIG[$name]);
191
    $lang_dir = 'lang/';
192
 
193
    $dir = opendir($lang_dir);
194
    while ($file = readdir($dir)) {
195
        if (is_file($lang_dir . $file) && strtolower(substr($file, -4)) == '.php') {
196
            $lang_array[] = strtolower(substr($file, 0 , -4));
197
        }
198
    }
199
    closedir($dir);
200
 
201
    natcasesort($lang_array);
202
 
203
    echo <<<EOT
204
        <tr>
205
            <td class="tableb">
206
                        $text
207
        </td>
208
        <td class="tableb" valign="top">
209
                        <select name="$name" class="listbox">
210
 
211
EOT;
212
    foreach ($lang_array as $language) {
213
        echo "                                <option value=\"$language\" " . ($value == $language ? 'selected' : '') . ">" . ucfirst($language) . "</option>\n";
214
    }
215
    echo <<<EOT
216
                        </select>
217
                </td>
218
        </tr>
219
 
220
EOT;
221
}
222
 
223
function form_theme($text, $name)
224
{
225
    global $CONFIG;
226
 
227
    $result = db_query("SELECT value FROM {$CONFIG['TABLE_CONFIG']} WHERE name = 'theme'");
228
    list($value) = mysql_fetch_row($result);
229
    mysql_free_result($result);
230
 
231
    $theme_dir = 'themes/';
232
 
233
    $dir = opendir($theme_dir);
234
    while ($file = readdir($dir)) {
235
        if (is_dir($theme_dir . $file) && $file != "." && $file != "..") {
236
            $theme_array[] = $file;
237
        }
238
    }
239
    closedir($dir);
240
 
241
    natcasesort($theme_array);
242
 
243
    echo <<<EOT
244
        <tr>
245
            <td class="tableb">
246
                        $text
247
        </td>
248
        <td class="tableb" valign="top">
249
                        <select name="$name" class="listbox">
250
 
251
EOT;
252
    foreach ($theme_array as $theme) {
253
        echo "                                <option value=\"$theme\" " . ($value == $theme ? 'selected' : '') . ">" . strtr(ucfirst($theme), '_', ' ') . "</option>\n";
254
    }
255
    echo <<<EOT
256
                        </select>
257
                </td>
258
        </tr>
259
 
260
EOT;
261
}
262
// Added for allowing user to select which aspect of thumbnails to scale
263
function form_scale($text, $name)
264
{
265
   global $CONFIG, $lang_config_php ;
266
 
267
    $value = $CONFIG[$name];
268
    $any_selected = ($value == 'max') ? 'selected' : '';
269
    $ht_selected = ($value == 'ht') ? 'selected' : '';
270
    $wd_selected = ($value == 'wd') ? 'selected' : '';
271
 
272
    echo <<<EOT
273
        <tr>
274
            <td class="tableb">
275
                        $text
276
        </td>
277
        <td class="tableb" valign="top">
278
                        <select name="$name" class="listbox">
279
                                <option value="any" $any_selected>{$lang_config_php['th_any']}</option>
280
                                <option value="ht" $ht_selected>{$lang_config_php['th_ht']}</option>
281
                                <option value="wd" $wd_selected>{$lang_config_php['th_wd']}</option>
282
                        </select>
283
                </td>
284
        </tr>
285
 
286
EOT;
287
}
288
 
289
function form_lang_theme($text, $name)
290
{
291
    global $CONFIG, $lang_yes, $lang_no, $lang_config_php;
292
 
293
    $value = $CONFIG[$name];
294
    $no_selected = ($value == '0') ? 'checked="checked"' : '';
295
    $yes_1_selected = ($value == '1') ? 'checked="checked"' : '';
296
    $yes_2_selected = ($value == '2') ? 'checked="checked"' : '';
297
 
298
    echo <<<EOT
299
        <tr>
300
            <td class="tableb">
301
                        $text
302
        </td>
303
        <td class="tableb" valign="top">
304
                        <input type="radio" id="{$name}0" name="$name" value="0" $no_selected /><label for="{$name}0" class="clickable_option">$lang_no</label>
305
                        &nbsp;&nbsp;
306
                        <input type="radio" id="{$name}1" name="$name" value="1" $yes_1_selected /><label for="{$name}1" class="clickable_option">$lang_yes:{$lang_config_php['item']}</label>
307
                        &nbsp;&nbsp;
308
                        <input type="radio" id="{$name}2" name="$name" value="2" $yes_2_selected /><label for="{$name}2" class="clickable_option">$lang_yes:{$lang_config_php['label']}+{$lang_config_php['item']}</label>
309
        </td>
310
        </tr>
311
 
312
EOT;
313
}
314
 
315
function form_lang_debug($text, $name)
316
{
317
    global $CONFIG, $lang_yes, $lang_no, $lang_config_php;
318
 
319
    $value = $CONFIG[$name];
320
    $no_selected = ($value == '0') ? 'checked="checked"' : '';
321
    $yes_1_selected = ($value == '1') ? 'checked="checked"' : '';
322
    $yes_2_selected = ($value == '2') ? 'checked="checked"' : '';
323
 
324
    echo <<<EOT
325
        <tr>
326
            <td class="tableb">
327
                        $text
328
        </td>
329
        <td class="tableb" valign="top">
330
                        <input type="radio" id="{$name}0" name="$name" value="0" $no_selected /><label for="{$name}0" class="clickable_option">$lang_no</label>
331
                        &nbsp;&nbsp;
332
                        <input type="radio" id="{$name}1" name="$name" value="1" $yes_1_selected /><label for="{$name}1" class="clickable_option">$lang_yes:{$lang_config_php['debug_everyone']}</label>
333
                        &nbsp;&nbsp;
334
                        <input type="radio" id="{$name}2" name="$name" value="2" $yes_2_selected /><label for="{$name}2" class="clickable_option">$lang_yes:{$lang_config_php['debug_admin']}</label>
335
        </td>
336
        </tr>
337
 
338
EOT;
339
}
340
 
341
function form_number_dropdown($text, $name)
342
{
343
   global $CONFIG, $lang_config_php ;
344
 
345
    echo <<<EOT
346
        <tr>
347
            <td class="tableb">
348
                        $text
349
        </td>
350
        <td class="tableb" valign="top">
351
                        <select name="$name" class="listbox">
352
EOT;
353
        for ($i = 5; $i <= 25; $i++) {
354
        echo "<option value=\"".$i."\"";
355
        if ($i == $CONFIG[$name]) { echo " selected=\"selected\"";}
356
        echo ">".$i."</option>\n";
357
        }
358
     echo <<<EOT
359
     </select>
360
                </td>
361
        </tr>
362
EOT;
363
}
364
 
365
 
366
function create_form(&$data)
367
{
368
    foreach($data as $element) {
369
        if ((is_array($element))) {
370
            switch ($element[2]) {
371
                case 0 :
372
                    form_input($element[0], $element[1]);
373
                    break;
374
                case 1 :
375
                    form_yes_no($element[0], $element[1]);
376
                    break;
377
                case 2 :
378
                    form_img_pkg($element[0], $element[1]);
379
                    break;
380
                case 3 :
381
                    form_sort_order($element[0], $element[1]);
382
                    break;
383
                case 4 :
384
                    form_charset($element[0], $element[1]);
385
                    break;
386
                case 5 :
387
                    form_language($element[0], $element[1]);
388
                    break;
389
                case 6 :
390
                    form_theme($element[0], $element[1]);
391
                    break;
392
                // Thumbnail scaling
393
                case 7 :
394
                    form_scale($element[0], $element[1]);
395
                    break;
396
                // Language + Theme selection
397
                case 8 :
398
                    form_lang_theme($element[0], $element[1]);
399
                    break;
400
                // debug mode selection
401
                case 9 :
402
                    form_lang_debug($element[0], $element[1]);
403
                    break;
404
                // tabbed display fix
405
                case 10 :
406
                    form_number_dropdown($element[0], $element[1]);
407
                    break;
408
                default:
409
                    die('Invalid action');
410
            } // switch
411
        } else {
412
            form_label($element);
413
        }
414
    }
415
}
416
 
417
if (count($HTTP_POST_VARS) > 0) {
418
    if (isset($HTTP_POST_VARS['update_config'])) {
419
        $need_to_be_positive = array('albums_per_page',
420
            'album_list_cols',
421
            'max_tabs',
422
            'picture_width',
423
            'subcat_level',
424
            'thumb_width',
425
            'thumbcols',
426
            'thumbrows',
427
            // Show filmstrip
428
            'max_film_strip_items');
429
 
430
        // Code to rename system thumbs in images folder
431
        $old_thumb_pfx =& $CONFIG['thumb_pfx'];
432
 
433
        if ($old_thumb_pfx != $HTTP_POST_VARS['thumb_pfx']) {
434
            $folders = array('images/', $THEME_DIR.'images/');
435
            foreach ($folders as $folder) {
436
                $thumbs = cpg_get_system_thumb_list($folder);
437
                foreach ($thumbs as $thumb) {
438
                    @rename($folder.$thumb['filename'],
439
                            $folder.str_replace($old_thumb_pfx,$HTTP_POST_VARS['thumb_pfx'],$thumb['filename']));
440
                }
441
            }
442
        }
443
 
444
        foreach ($need_to_be_positive as $parameter)
445
        $HTTP_POST_VARS[$parameter] = max(1, (int)$HTTP_POST_VARS[$parameter]);
446
 
447
        foreach($lang_config_data as $element) {
448
            if ((is_array($element))) {
449
                if ((!isset($HTTP_POST_VARS[$element[1]]))) cpg_die(CRITICAL_ERROR, "Missing config value for '{$element[1]}'", __FILE__, __LINE__);
450
                $value = addslashes($HTTP_POST_VARS[$element[1]]);
451
                db_query("UPDATE {$CONFIG['TABLE_CONFIG']} SET  value = '$value' WHERE name = '{$element[1]}'");
452
            }
453
        }
454
        pageheader($lang_config_php['title']);
455
        msg_box($lang_config_php['info'], $lang_config_php['upd_success'], $lang_continue, 'index.php');
456
 
457
    } elseif (isset($HTTP_POST_VARS['restore_config'])) {
458
        $default_config = 'sql/basic.sql';
459
        $sql_query = fread(fopen($default_config, 'r'), filesize($default_config));
460
        $sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);
461
        db_query("TRUNCATE TABLE {$CONFIG['TABLE_CONFIG']}");
462
        db_query("TRUNCATE TABLE {$CONFIG['TABLE_FILETYPES']}");
463
        $sql_query = remove_remarks($sql_query);
464
        $sql_query = split_sql_file($sql_query, ';');
465
 
466
        $sql_count = count($sql_query);
467
        for($i = 0; $i < $sql_count; $i++) if (strpos($sql_query[$i],'_config') || strpos($sql_query[$i],'_filetypes')) db_query($sql_query[$i]);
468
              pageheader($lang_config_php['title']);
469
            msg_box($lang_config_php['info'], $lang_config_php['restore_success'], $lang_continue, $PHP_SELF);
470
    }
471
    pagefooter();
472
    exit;
473
}
474
 
475
pageheader($lang_config_php['title']);
476
 
477
$signature = 'Coppermine Photo Gallery ' . COPPERMINE_VERSION;
478
 
479
starttable('100%', "{$lang_config_php['title']} - $signature", 2);
480
echo <<<EOT
481
        <form action="$PHP_SELF" method="post">
482
 
483
EOT;
484
create_form($lang_config_data);
485
echo <<<EOT
486
        <tr>
487
            <td colspan="2" align="center" class="tablef">
488
                        <input type="submit" class="button" name="update_config" value="{$lang_config_php['save_cfg']}">
489
                        &nbsp;&nbsp;
490
                        <input type="submit" class="button" name="restore_config" value="{$lang_config_php['restore_cfg']}">
491
                </td>
492
        </form>
493
        </tr>
494
 
495
EOT;
496
endtable();
497
pagefooter();
498
ob_end_flush();
499
 
500
?>