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/modifyalb.php,v $
15
  $Revision: 1.7 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
/*
20
$Id: modifyalb.php,v 1.7 2005/04/19 03:17:11 gaugau Exp $
21
*/
22
 
23
define('IN_COPPERMINE', true);
24
define('MODIFYALB_PHP', true);
25
 
26
include("include/init.inc.php");
27
 
28
if (!(GALLERY_ADMIN_MODE || USER_ADMIN_MODE)) {
29
    cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
30
}
31
// Type 0 => input
32
// 1 => yes/no
33
// 2 => Category
34
// 3 => Textarea
35
// 4 => Album thumbnail
36
// 5 => Album visibility
37
 
38
// add footnote
39
$notice1 = ' *';
40
 
41
$captionLabel = $lang_modifyalb_php['alb_desc'];
42
if ($CONFIG['show_bbcode_help']) {$captionLabel .= '<hr />'.$lang_bbcode_help;}
43
$data = array($lang_modifyalb_php['general_settings'],
44
    array($lang_modifyalb_php['alb_title'], 'title', 0),
45
    array($lang_modifyalb_php['alb_cat'], 'category', 2),
46
    array($captionLabel, 'description', 3),
47
    array($lang_modifyalb_php['alb_thumb'], 'thumb', 4),
48
    $lang_modifyalb_php['alb_perm'],
49
    array($lang_modifyalb_php['can_view'], 'visibility', 5),
50
    array($lang_modifyalb_php['can_upload'].$notice1, 'uploads', 1),
51
    array($lang_modifyalb_php['can_post_comments'].$notice1, 'comments', 1),
52
    array($lang_modifyalb_php['can_rate'].$notice1, 'votes', 1),
53
    );
54
 
55
function get_subcat_data($parent, $ident = '')
56
{
57
    global $CONFIG, $CAT_LIST;
58
 
59
    $result = db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
60
    if (mysql_num_rows($result) > 0) {
61
        $rowset = db_fetch_rowset($result);
62
        foreach ($rowset as $subcat) {
63
            $CAT_LIST[] = array($subcat['cid'], $ident . $subcat['name']);
64
            get_subcat_data($subcat['cid'], $ident . '&nbsp;&nbsp;&nbsp;');
65
        }
66
    }
67
}
68
 
69
function form_label($text)
70
{
71
    echo <<<EOT
72
        <tr>
73
                <td class="tableh2" colspan="2">
74
                        <b>$text</b>
75
                </td>
76
        </tr>
77
 
78
EOT;
79
}
80
 
81
function form_input($text, $name)
82
{
83
    global $ALBUM_DATA;
84
 
85
    $value = $ALBUM_DATA[$name];
86
 
87
    echo <<<EOT
88
        <tr>
89
            <td width="40%" class="tableb">
90
                        $text
91
        </td>
92
        <td width="60%" class="tableb" valign="top">
93
                <input type="text" style="width: 100%" name="$name" value="$value" class="textinput">
94
                </td>
95
        </tr>
96
 
97
EOT;
98
}
99
 
100
function form_yes_no($text, $name)
101
{
102
    global $ALBUM_DATA, $lang_yes, $lang_no;
103
 
104
    if ($name == 'uploads' && USER_ADMIN_MODE) {
105
        echo "        <input type=\"hidden\" name=\"$name\" value=\"{$ALBUM_DATA['uploads']}\">";
106
        return;
107
    }
108
 
109
    $value = isset($ALBUM_DATA[$name]) ? $ALBUM_DATA[$name] : false;
110
    $yes_selected = $value == 'YES' ? 'checked="checked"' : '';
111
    $no_selected = $value == 'NO' ? 'checked="checked"' : '';
112
 
113
    echo <<<EOT
114
        <tr>
115
            <td class="tableb">
116
                        $text
117
        </td>
118
        <td class="tableb" valign="top">
119
                        <input type="radio" id="{$name}1" name="$name" value="YES" $yes_selected /><label for="{$name}1" class="clickable_option">$lang_yes</label>
120
                        &nbsp;&nbsp;
121
                        <input type="radio" id="{$name}0" name="$name" value="NO" $no_selected /><label for="{$name}0" class="clickable_option">$lang_no</label>
122
                </td>
123
        </tr>
124
 
125
EOT;
126
}
127
 
128
function form_category($text, $name)
129
{
130
    global $ALBUM_DATA, $CAT_LIST, $USER_DATA, $lang_modifyalb_php;
131
 
132
    if (!GALLERY_ADMIN_MODE || $ALBUM_DATA['category'] > FIRST_USER_CAT) {
133
        echo <<<EOT
134
        <tr>
135
            <td class="tableb">
136
                        $text
137
        </td>
138
        <td class="tableb" valign="top">
139
                        <i>{$lang_modifyalb_php['user_gal']}</i>
140
                        <input type="hidden" name="$name" value="{$ALBUM_DATA['category']}">
141
                </td>
142
 
143
EOT;
144
        return;
145
    }
146
 
147
    $CAT_LIST = array();
148
    $CAT_LIST[] = array(0, $lang_modifyalb_php['no_cat']);
149
    get_subcat_data(0, '');
150
 
151
    echo <<<EOT
152
        <tr>
153
            <td class="tableb">
154
                        $text
155
        </td>
156
        <td class="tableb" valign="top">
157
                        <select name="$name" class="listbox">
158
EOT;
159
    foreach($CAT_LIST as $category) {
160
        echo '                                <option value="' . $category[0] . '"' . ($ALBUM_DATA['category'] == $category[0] ? ' selected': '') . ">" . $category[1] . "</option>\n";
161
    }
162
    echo <<<EOT
163
                        </select>
164
                </td>
165
        </tr>
166
 
167
EOT;
168
}
169
 
170
function form_textarea($text, $name)
171
{
172
    global $ALBUM_DATA;
173
 
174
    $value = $ALBUM_DATA[$name];
175
 
176
    echo <<<EOT
177
        <tr>
178
                <td class="tableb" valign="top">
179
                        $text
180
                </td>
181
                <td class="tableb" valign="top">
182
                        <textarea name="$name" rows="5" cols="40" wrap="virtual" class="textinput" style="width: 100%;">{$ALBUM_DATA['description']}</textarea>
183
                </td>
184
        </tr>
185
EOT;
186
}
187
 
188
function form_alb_thumb($text, $name)
189
{
190
    global $CONFIG, $ALBUM_DATA, $album, $lang_modifyalb_php;
191
 
192
    $results = db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='$album' AND approved='YES' ORDER BY filename");
193
    if (mysql_num_rows($results) == 0) {
194
        echo <<<EOT
195
        <tr>
196
                <td class="tableb" valign="top">
197
                        $text
198
                </td>
199
                <td class="tableb" valign="top">
200
                        <i>{$lang_modifyalb_php['alb_empty']}</i>
201
                        <input type="hidden" name="$name" value="0">
202
                </td>
203
        </tr>
204
 
205
EOT;
206
        return;
207
    }
208
 
209
    echo <<<EOT
210
<script language="JavaScript" type="text/JavaScript">
211
var Pic = new Array()
212
 
213
Pic[0] = 'images/nopic.jpg'
214
 
215
EOT;
216
 
217
    $initial_thumb_url = 'images/nopic.jpg';
218
    $img_list = array(0 => $lang_modifyalb_php['last_uploaded']);
219
    while ($picture = mysql_fetch_array($results)) {
220
        $thumb_url = get_pic_url($picture, 'thumb');
221
        echo "Pic[{$picture['pid']}] = '" . $thumb_url . "'\n";
222
        if ($picture['pid'] == $ALBUM_DATA[$name]) $initial_thumb_url = $thumb_url;
223
        $img_list[$picture['pid']] = htmlspecialchars($picture['filename']);
224
    } // while
225
    echo <<<EOT
226
 
227
function ChangeThumb(index)
228
{
229
        document.images.Thumb.src = Pic[index]
230
}
231
</script>
232
 
233
EOT;
234
    $thumb_cell_height = $CONFIG['thumb_width'] + 17;
235
    echo <<<EOT
236
        <tr>
237
                <td class="tableb" valign="top">
238
                        $text
239
                </td>
240
                <td class="tableb" align="center">
241
                        <table cellspacing="0" cellpadding="5" border="0">
242
                                <tr>
243
                                        <td width="$thumb_cell_height" height="$thumb_cell_height" align="center"><img src="$initial_thumb_url" name='Thumb' class='image' /><br /></td>
244
                                </tr>
245
                        </table>
246
                        <select name="$name" class="listbox" onChange="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);" onKeyUp="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);">
247
 
248
EOT;
249
    foreach($img_list as $pid => $pic_name) {
250
        echo '                                <option value="' . $pid . '"' . ($pid == $ALBUM_DATA[$name] ? ' selected':'') . '>' . $pic_name . "</option>\n";
251
    }
252
    echo <<<EOT
253
                        </select>
254
                </td>
255
        </tr>
256
 
257
EOT;
258
}
259
 
260
function form_visibility($text, $name)
261
{
262
    global $CONFIG, $USER_DATA, $ALBUM_DATA, $lang_modifyalb_php;
263
 
264
    if (!$CONFIG['allow_private_albums']) {
265
        echo '        <input type="hidden" name="' . $name . '" value="0">' . "\n";
266
        return;
267
    }
268
 
269
    if (GALLERY_ADMIN_MODE) {
270
        $options = array(0 => $lang_modifyalb_php['public_alb'], FIRST_USER_CAT + USER_ID => $lang_modifyalb_php['me_only']);
271
        if ($ALBUM_DATA['category'] > FIRST_USER_CAT) {
272
            if (defined('UDB_INTEGRATION')) {
273
                $owner_name = udb_get_user_name($ALBUM_DATA['category'] - FIRST_USER_CAT);
274
            } else {
275
                $result = db_query("SELECT user_name FROM {$CONFIG['TABLE_USERS']} WHERE user_id='" . ($ALBUM_DATA['category'] - FIRST_USER_CAT) . "'");
276
                if (mysql_num_rows($result)) {
277
                    $user = mysql_fetch_array($result);
278
                    $owner_name = $user['user_name'];
279
                }
280
            }
281
            $options[$ALBUM_DATA['category']] = sprintf($lang_modifyalb_php['owner_only'], $owner_name);
282
        }
283
        $result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
284
        while ($group = mysql_fetch_array($result)) {
285
            $options[$group['group_id']] = sprintf($lang_modifyalb_php['groupp_only'], $group['group_name']);
286
        } // while
287
    } else {
288
        $options = array(0 => $lang_modifyalb_php['public_alb'],
289
            FIRST_USER_CAT + USER_ID => $lang_modifyalb_php['me_only'],
290
            );
291
        $result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id IN " . USER_GROUP_SET);
292
        while ($group = mysql_fetch_array($result)) {
293
            $options[$group['group_id']] = sprintf($lang_modifyalb_php['groupp_only'], $group['group_name']);
294
        } // while
295
    }
296
    echo <<<EOT
297
        <tr>
298
                <td class="tableb">
299
                        $text
300
                </td>
301
                <td class="tableb" valign="top">
302
                        <select name="$name" class="listbox">
303
 
304
EOT;
305
    foreach ($options as $value => $caption) {
306
        echo '                                <option value ="' . $value . '"' . ($ALBUM_DATA['visibility'] == $value ? ' selected': '') . '>' . $caption . "</option>\n";
307
    }
308
    echo <<<EOT
309
                        </select>
310
                </td>
311
        </tr>
312
 
313
EOT;
314
}
315
 
316
function create_form(&$data)
317
{
318
    foreach($data as $element) {
319
        if ((is_array($element))) {
320
            switch ($element[2]) {
321
                case 0 :
322
                    form_input($element[0], $element[1]);
323
                    break;
324
                case 1 :
325
                    form_yes_no($element[0], $element[1]);
326
                    break;
327
                case 2 :
328
                    form_category($element[0], $element[1]);
329
                    break;
330
                case 3 :
331
                    form_textarea($element[0], $element[1]);
332
                    break;
333
                case 4 :
334
                    form_alb_thumb($element[0], $element[1]);
335
                    break;
336
                case 5 :
337
                    form_visibility($element[0], $element[1]);
338
                    break;
339
                default:
340
                    cpg_die(CRITICAL_ERROR, 'Invalid action for form creation', __FILE__, __LINE__);
341
            } // switch
342
        } else {
343
            form_label($element);
344
        }
345
    }
346
}
347
 
348
function alb_list_box()
349
{
350
    global $CONFIG, $album, $PHP_SELF;
351
 
352
    if (GALLERY_ADMIN_MODE) {
353
        $result = db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < '" . FIRST_USER_CAT . "' ORDER BY title");
354
        $rowset = db_fetch_rowset($result);
355
        mysql_free_result($result);
356
 
357
        if (defined('UDB_INTEGRATION')) {
358
            $sql = udb_get_admin_album_list();
359
        } else {
360
            $sql = "SELECT aid, CONCAT('(', user_name, ') ', title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (" . FIRST_USER_CAT . " + user_id) " . "ORDER BY title";
361
        }
362
        $result = db_query($sql);
363
        while ($row = mysql_fetch_array($result)) $rowset[] = $row;
364
        mysql_free_result($result);
365
    } else {
366
        $result = db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = '" . (FIRST_USER_CAT + USER_ID) . "' ORDER BY title");
367
        $rowset = db_fetch_rowset($result);
368
        mysql_free_result($result);
369
    }
370
 
371
    if (count($rowset)) {
372
        $lb = "<select name=\"album_listbox\" class=\"listbox\" onChange=\"if(this.options[this.selectedIndex].value) window.location.href='$PHP_SELF?album='+this.options[this.selectedIndex].value;\">\n";
373
        foreach ($rowset as $row) {
374
            $selected = ($row['aid'] == $album) ? "SELECTED" : "";
375
            $lb .= "        <option value=\"" . $row['aid'] . "\" $selected>" . $row['title'] . "</option>\n";
376
        }
377
        $lb .= "</select>\n";
378
        return $lb;
379
    }
380
}
381
 
382
if (!isset($HTTP_GET_VARS['album'])) {
383
    if (GALLERY_ADMIN_MODE) {
384
        $results = db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE 1 LIMIT 1");
385
    } else {
386
        $results = db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . (FIRST_USER_CAT + USER_ID) . " LIMIT 1");
387
    }
388
    if (mysql_num_rows($results) == 0) cpg_die(ERROR, $lang_modifyalb_php['err_no_alb_to_modify'], __FILE__, __LINE__);
389
    $ALBUM_DATA = mysql_fetch_array($results);
390
    $album = $ALBUM_DATA['aid'];
391
} else {
392
    $album = (int)$HTTP_GET_VARS['album'];
393
    $results = db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='$album'");
394
    if (!mysql_num_rows($results)) cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
395
    $ALBUM_DATA = mysql_fetch_array($results);
396
}
397
 
398
$cat = $ALBUM_DATA['category'];
399
$actual_cat = $cat;
400
 
401
if (!GALLERY_ADMIN_MODE && $ALBUM_DATA['category'] != FIRST_USER_CAT + USER_ID) {
402
    cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
403
}
404
 
405
pageheader(sprintf($lang_modifyalb_php['upd_alb_n'], $ALBUM_DATA['title']));
406
starttable("100%");
407
 
408
$album_lb = alb_list_box();
409
 
410
echo <<<EOT
411
        <tr>
412
                <td colspan="2" class="tableh1">
413
                <table width="100%" cellpadding="0" cellspacing="0" border="0">
414
                        <tr>
415
                        <td class="statlink"><h2>{$lang_modifyalb_php['update']}</h2></td>
416
                        <td align="right">$album_lb</td>
417
                        </tr>
418
                </table>
419
                </td>
420
        </tr>
421
        <form method="post" action="db_input.php">
422
        <input type="hidden" name="event" value="album_update">
423
        <input type="hidden" name="aid" value="$album">
424
 
425
EOT;
426
create_form($data);
427
echo <<<EOT
428
<tr>
429
        <td colspan="2" align="left" class="tablef">
430
EOT;
431
if (GALLERY_ADMIN_MODE) {
432
printf($lang_modifyalb_php['notice1'],'<a href="groupmgr.php">','</a>');
433
}
434
else {
435
printf($lang_modifyalb_php['notice1'],'','');
436
}
437
echo <<<EOT
438
        </td>
439
</tr>
440
<tr>
441
        <td colspan="2" align="center" class="tablef">
442
        <input type="submit" class="button" value="{$lang_modifyalb_php['update']}">
443
        </td>
444
        </form>
445
</tr>
446
EOT;
447
 
448
endtable();
449
pagefooter();
450
ob_end_flush();
451
 
452
?>