1<?php
2/*************************
3  Coppermine Photo Gallery
4  ************************
5  Copyright (c) 2003-2016 Coppermine Dev Team
6  v1.0 originally 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 version 3
10  as published by the Free Software Foundation.
11
12  ********************************************
13  Coppermine version: 1.6.03
14  $HeadURL$
15**********************************************/
16
17define('IN_COPPERMINE', true);
18define('MODIFYALB_PHP', true);
19
20include("include/init.inc.php");
21
22if ($superCage->get->keyExists('album')) {
23    $CLEAN['album'] = $superCage->get->getInt('album');
24} else {
25    $CLEAN['album'] = 0;
26}
27
28if (!(GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && user_is_allowed(false)))) {
29    cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
30}
31
32// Type 0 => input
33// 1 => yes/no
34// 2 => Category
35// 3 => Textarea
36// 4 => Album thumbnail
37// 5 => Album visibility
38
39// add footnote
40$notice1 = ' <a href="#notice1" class="">*</a>';
41$help = array();
42$help['table'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop&amp;ae=album_prop_end&amp;top=1', '600', '400');
43$help['related_tasks'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_related_tasks&amp;ae=album_prop_controls_related_tasks_end', '500', '250');
44$help['choose_album'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_album_dropdown&amp;ae=album_prop_controls_album_dropdown_end', '500', '250');
45$help['album_title'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_album_title&amp;ae=album_prop_controls_album_title_end', '500', '250');
46$help['album_category'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_album_category&amp;ae=album_prop_controls_album_category_end', '500', '250');
47$help['album_keywords'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_album_keyword&amp;ae=album_prop_controls_album_keyword_end', '500', '250');
48$help['album_thumbnail'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_album_thumbnail&amp;ae=album_prop_controls_album_thumbnail_end', '500', '250');
49$help['album_can_be_viewed_by'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_album_can_be_viewed_by&amp;ae=album_prop_controls_album_can_be_viewed_by_end', '500', '250');
50$help['album_password'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_password_protection&amp;ae=album_prop_controls_password_protection_end&amp', '500', '250');
51$help['can_upload'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_visitor_upload&amp;ae=album_prop_controls_visitor_upload_end&amp', '400', '200');
52$help['can_post_comments'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_can_post_comment&amp;ae=album_prop_controls_can_post_comment_end&amp', '400', '200');
53$help['can_rate'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_can_rate_files&amp;ae=album_prop_controls_can_rate_files_end&amp', '400', '200');
54$help['can_moderate'] = '&nbsp;'.cpg_display_help('f=albums.htm&amp;as=album_prop_controls_album_moderation&amp;ae=album_prop_controls_album_moderation_end&amp', '400', '200');
55
56// Define the icons
57$icon_array = array(
58    'album_properties'   => cpg_fetch_icon('modifyalb', 2),
59    'thumbnail'          => cpg_fetch_icon('thumbnails', 1),
60    'album_thumbnail'    => cpg_fetch_icon('thumbnails', 2),
61    'password'           => cpg_fetch_icon('key_enter', 2),
62    'album'              => cpg_fetch_icon('alb_mgr', 2),
63    'upload'             => cpg_fetch_icon('upload', 2),
64    'move'               => cpg_fetch_icon('move', 1),
65    'title'              => cpg_fetch_icon('title', 2),
66    'view'               => cpg_fetch_icon('groups_mgr', 2),
67    'description'        => cpg_fetch_icon('text_left', 2),
68    'keyword'            => cpg_fetch_icon('keyword_mgr', 2),
69    'views'              => cpg_fetch_icon('stats', 2),
70    'ok'                 => cpg_fetch_icon('ok', 1),
71    'category'           => cpg_fetch_icon('category', 1),
72    'album_category'     => cpg_fetch_icon('category', 2),
73    'file'               => cpg_fetch_icon('file', 2),
74    'comment'            => cpg_fetch_icon('comment', 2),
75    'rate'               => cpg_fetch_icon('top_rated', 2),
76    'blank'              => cpg_fetch_icon('blank', 2),
77    'edit_files'         => cpg_fetch_icon('edit', 1),
78    'stop'               => cpg_fetch_icon('stop', 0, '', '', 'png', 1),  // Only get the image path and not the embedding <img>-tag
79);
80
81$captionLabel = $lang_modifyalb_php['alb_desc'];
82
83if ($CONFIG['show_bbcode_help']) {
84    $captionLabel .= '&nbsp;'. cpg_display_help('f=empty.htm&amp;h=lang_bbcode_help_title&amp;t=lang_bbcode_help', 470, 245);
85}
86
87$data = array($lang_modifyalb_php['general_settings'],
88    array($icon_array['title'].$lang_modifyalb_php['alb_title'].$help['album_title'], 'title', 0),
89    array($icon_array['album_category'].$lang_modifyalb_php['alb_cat'].$help['album_category'], 'category', 2),
90    array($icon_array['description'].$captionLabel, 'description', 3),
91    array($icon_array['keyword'].$lang_modifyalb_php['alb_keyword'].$help['album_keywords'], 'keyword', 0),
92    array($lang_modifyalb_php['alb_thumb'], 'thumb', 4),
93    $lang_modifyalb_php['alb_perm'],
94    array($icon_array['view'].$lang_modifyalb_php['can_view'].$help['album_can_be_viewed_by'], 'visibility', 5),
95    array($icon_array['password'].$lang_modifyalb_php['password_protect'].$help['album_password'], 'password_protect', 9),
96    array($icon_array['blank'].$lang_modifyalb_php['alb_password'], 'alb_password', 6),
97    array($icon_array['blank'].$lang_modifyalb_php['alb_password_hint'], 'alb_password_hint', 7),
98    array($icon_array['upload'].$lang_modifyalb_php['can_upload'].$notice1.$help['can_upload'], 'uploads', 1),
99    array($icon_array['comment'].$lang_modifyalb_php['can_post_comments'].$notice1.$help['can_post_comments'], 'comments', 1),
100    array($icon_array['rate'].$lang_modifyalb_php['can_rate'].$notice1.$help['can_rate'], 'votes', 1),
101);
102
103/* TODO: re-enable and test feature when it's clear how it should work (see http://forum.coppermine-gallery.net/index.php/topic,64408.0.html)
104if (GALLERY_ADMIN_MODE) {
105    $data[] = array($lang_modifyalb_php['can_moderate'].$help['can_moderate'], 'moderator_group', 8);
106}
107*/
108
109function form_label($text)
110{
111    echo <<< EOT
112    <tr>
113        <td class="tableh2" colspan="2">
114            <strong>$text</strong>
115        </td>
116    </tr>
117
118EOT;
119}
120
121function form_input($text, $name)
122{
123    global $ALBUM_DATA, $CONFIG;
124
125    $value = $ALBUM_DATA[$name];
126    $disabled = '';
127
128    if ($name == 'keyword' && !GALLERY_ADMIN_MODE && $CONFIG['allow_user_album_keyword'] != 1) {
129        $disabled = ' disabled="disabled" style="background-color:InactiveCaptionText;color:GrayText"';
130    }
131
132    switch ($name) {
133        case 'title':
134            $maxlength = ' maxlength="255"';
135            break;
136
137        case 'keyword':
138            $maxlength = ' maxlength="50"';
139            break;
140
141        default:
142            $maxlength = '';
143            break;
144    }
145
146    echo <<< EOT
147    <tr>
148        <td width="40%">
149            $text
150        </td>
151        <td width="60%" valign="top">
152            <input type="text" style="width: 98%" name="$name" value="$value" class="textinput"{$maxlength}{$disabled} />
153        </td>
154    </tr>
155
156EOT;
157}
158
159function form_yes_no($text, $name)
160{
161    global $ALBUM_DATA, $lang_common;
162
163    if ($name == 'uploads' && USER_ADMIN_MODE) {
164        echo "        <input type=\"hidden\" name=\"$name\" value=\"{$ALBUM_DATA['uploads']}\" />";
165        return;
166    }
167
168    $value = isset($ALBUM_DATA[$name]) ? $ALBUM_DATA[$name] : false;
169    $yes_selected = $value == 'YES' ? 'checked="checked"' : '';
170    $no_selected = $value == 'NO' ? 'checked="checked"' : '';
171
172    echo <<< EOT
173    <tr>
174        <td>
175            $text
176        </td>
177        <td valign="top">
178            <input type="radio" id="{$name}1" name="$name" value="YES" $yes_selected />
179            <label for="{$name}1" class="clickable_option">{$lang_common['yes']}</label>
180            &nbsp;&nbsp;
181            <input type="radio" id="{$name}0" name="$name" value="NO" $no_selected />
182            <label for="{$name}0" class="clickable_option">{$lang_common['no']}</label>
183        </td>
184    </tr>
185
186EOT;
187}
188
189function form_category($text, $name)
190{
191    global $ALBUM_DATA, $CAT_LIST, $USER_DATA, $lang_modifyalb_php, $CONFIG, $icon_array, $LINEBREAK;
192
193    //check if users are allowed to move their albums
194    if (!GALLERY_ADMIN_MODE && $CONFIG['allow_user_move_album'] == 0) {
195
196        //get category name
197        $cat_name = $lang_modifyalb_php['user_gal'];
198
199        if ($ALBUM_DATA['category'] != (FIRST_USER_CAT + USER_ID)) {
200            $result = cpg_db_query("SELECT name FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '" . $ALBUM_DATA['category'] . "' LIMIT 1");
201            $cat_name = $result->fetchAssoc(true);
202            $cat_name = $cat_name['name'];
203        }
204
205        echo <<< EOT
206    <tr>
207        <td>
208            $text
209        </td>
210        <td valign="top">
211            <em>{$cat_name}</em>
212            <input type="hidden" name="$name" value="{$ALBUM_DATA['category']}" />
213        </td>
214    </tr>
215
216EOT;
217        return;
218    }
219
220    $CAT_LIST = array();
221
222    //only add 'no category' when user is admin
223    if (GALLERY_ADMIN_MODE) {
224        $CAT_LIST[] = array(0, $lang_modifyalb_php['no_cat']);
225    }
226
227    //add user catergory
228    $CAT_LIST[] = array((FIRST_USER_CAT + USER_ID), $lang_modifyalb_php['my_gal']);
229
230    get_cat_data();
231
232    echo <<< EOT
233    <tr>
234        <td>
235            $text
236        </td>
237        <td valign="top">
238            {$icon_array['move']}<select name="$name" class="listbox">
239EOT;
240
241    foreach ($CAT_LIST as $category) {
242        echo '                <option value="' . $category[0] . '"' . ($ALBUM_DATA['category'] == $category[0] ? ' selected="selected"': '') . ($category[0] == USER_GAL_CAT ? ' disabled="disabled"' : '') . ">" . $category[1] . '</option>' . $LINEBREAK;
243    }
244
245    echo <<< EOT
246            </select>
247        </td>
248    </tr>
249
250EOT;
251}
252
253function form_textarea($text, $name)
254{
255    global $ALBUM_DATA;
256
257    $value = $ALBUM_DATA[$name];
258
259    echo <<< EOT
260    <tr>
261        <td valign="top">
262            $text
263        </td>
264        <td valign="top">
265            <textarea name="$name" rows="5" cols="40" class="textinput" style="width: 98%;">{$ALBUM_DATA['description']}</textarea>
266        </td>
267    </tr>
268
269EOT;
270}
271
272function form_alb_thumb($text, $name)
273{
274    global $CONFIG, $ALBUM_DATA, $CLEAN, $lang_modifyalb_php, $USER_DATA, $LINEBREAK, $help, $icon_array;
275
276    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $USER_DATA['user_id']);
277
278    $keyword = '';
279
280    if ($ALBUM_DATA['keyword']) {
281        $keyword = "OR (keywords LIKE '%{$ALBUM_DATA['keyword']}%')";
282    }
283
284    $query = "SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND (aid = '{$CLEAN['album']}' $keyword ) ORDER BY filename";
285
286    $results = cpg_db_query($query);
287
288    if ($results->numRows() == 0) {
289
290        echo <<< EOT
291    <tr>
292        <td valign="top">
293            {$text}
294        </td>
295        <td valign="top">
296            <em>{$lang_modifyalb_php['alb_empty']}</em>
297            <input type="hidden" name="$name" value="0" />
298        </td>
299    </tr>
300
301EOT;
302        return;
303    }
304
305    $thumbs = array(
306        0 => $cpg_nopic_data['thumb'],
307    );
308
309    $img_list = array(
310        0 => $lang_modifyalb_php['last_uploaded'],
311        -1 => $lang_modifyalb_php['random_image'],
312    );
313
314    while ($picture = $results->fetchAssoc()) {
315
316        $thumb_url = get_pic_url($picture, 'thumb');
317
318        $thumbs[$picture['pid']] = $thumb_url;
319
320        if ($picture['pid'] == $ALBUM_DATA[$name]) {
321            $thumbs[0] = $thumb_url;
322        }
323
324        $img_list[$picture['pid']] = htmlspecialchars($picture['filename']);
325    }
326
327    $results->free();
328
329    $thumbs_json = json_encode($thumbs);
330
331    $thumb_cell_height = $CONFIG['thumb_width'] + 17;
332
333    echo <<< EOT
334    <tr>
335        <td valign="top">
336            {$icon_array['album_thumbnail']}{$text}{$help['album_thumbnail']}
337        </td>
338        <td align="left">
339            <img src="{$thumbs[0]}" name="Thumb" class="image" alt="$text" />
340            <br />
341
342EOT;
343
344    echo <<< EOT
345            <script language="JavaScript" type="text/JavaScript">
346                var Pic = $thumbs_json;
347            </script>
348
349EOT;
350
351    echo <<< EOT
352            <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);">
353
354EOT;
355    foreach ($img_list as $pid => $pic_name) {
356        echo '                <option value="' . $pid . '"' . ($pid == $ALBUM_DATA[$name] ? ' selected="selected"' : '') . '>' . $pic_name . '</option>' . $LINEBREAK;
357    }
358
359    echo <<< EOT
360            </select>
361        </td>
362    </tr>
363
364EOT;
365}
366
367function form_password_protect($text, $name)
368{
369    global $ALBUM_DATA;
370
371    if (!empty($ALBUM_DATA['alb_password'])) {
372        $checked = ' checked="checked"';
373    } else {
374        $checked = '';
375    }
376
377    echo <<< EOT
378    <tr>
379        <td width="40%">
380            $text
381        </td>
382        <td width="60%" valign="top">
383            <input id="$name" type="checkbox" name="$name" value="yes"$checked />
384        </td>
385    </tr>
386
387EOT;
388}
389
390function form_password($text, $name)
391{
392    global $ALBUM_DATA;
393
394    $value = $ALBUM_DATA[$name];
395
396    echo <<<EOT
397    <tr>
398        <td width="40%">
399            $text
400        </td>
401        <td width="60%" valign="top">
402            <input type="password" name="$name" class="textinput" size="34" />
403        </td>
404    </tr>
405
406EOT;
407}
408
409function form_password_hint($text, $name)
410{
411    global $ALBUM_DATA;
412
413    $value = $ALBUM_DATA[$name];
414
415    echo <<< EOT
416    <tr>
417        <td width="40%">
418            $text
419        </td>
420        <td width="60%" valign="top">
421            <input type="text" name="$name" value="$value" class="textinput" size="34" />
422        </td>
423    </tr>
424
425EOT;
426}
427
428function form_visibility($text, $name)
429{
430    global $CONFIG, $USER_DATA, $ALBUM_DATA, $lang_modifyalb_php, $cpg_udb, $LINEBREAK;
431
432    if (!$CONFIG['allow_private_albums']) {
433        echo '        <input type="hidden" name="' . $name . '" value="0" />' . $LINEBREAK;
434        return;
435    }
436
437    if (GALLERY_ADMIN_MODE) {
438
439        $options = array(
440            0 => $lang_modifyalb_php['public_alb'],
441            FIRST_USER_CAT + USER_ID => $lang_modifyalb_php['me_only'],
442        );
443
444        if ($ALBUM_DATA['category'] > FIRST_USER_CAT) {
445
446            $owner_name = $cpg_udb->get_user_name($ALBUM_DATA['category'] - FIRST_USER_CAT);
447
448            $options[$ALBUM_DATA['category']] = sprintf($lang_modifyalb_php['owner_only'], $owner_name);
449        }
450
451        $result = cpg_db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']}");
452
453        while ($group = $result->fetchAssoc()) {
454            $options[$group['group_id']] = sprintf($lang_modifyalb_php['group_only'], $group['group_name']);
455        }
456
457        $result->free();
458
459    } else {
460
461        $options = array(
462            0 => $lang_modifyalb_php['public_alb'],
463            FIRST_USER_CAT + USER_ID => $lang_modifyalb_php['me_only'],
464        );
465
466        $result = cpg_db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id IN " . USER_GROUP_SET);
467
468        while ($group = $result->fetchAssoc()) {
469            $options[$group['group_id']] = sprintf($lang_modifyalb_php['group_only'], $group['group_name']);
470        }
471
472        $result->free();
473    }
474
475    echo <<< EOT
476    <tr>
477        <td>
478            $text
479        </td>
480        <td valign="top">
481            <select name="$name" class="listbox">
482
483EOT;
484
485    foreach ($options as $value => $caption) {
486        echo '                <option value="' . $value . '"' . ($ALBUM_DATA['visibility'] == $value ? ' selected="selected"' : '') . '>' . $caption . '</option>' . $LINEBREAK;
487    }
488
489    echo <<< EOT
490            </select>
491        </td>
492    </tr>
493
494EOT;
495}
496
497function form_moderator($text, $name)
498{
499    global $CONFIG, $ALBUM_DATA, $lang_modifyalb_php, $LINEBREAK;
500
501    $options = array(
502        0 => $lang_modifyalb_php['admins_only'],
503    );
504
505    $result = cpg_db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id > 1");
506
507    while ($group = $result->fetchAssoc()) {
508        $options[$group['group_id']] = sprintf($lang_modifyalb_php['group_only'], $group['group_name']);
509    }
510
511    $result->free();
512
513    echo <<< EOT
514    <tr>
515        <td>
516            $text
517        </td>
518        <td valign="top">
519            <select name="$name" class="listbox">
520
521EOT;
522
523    foreach ($options as $value => $caption) {
524        echo '                <option value="' . $value . '"' . ($ALBUM_DATA['moderator_group'] == $value ? ' selected="selected"' : '') . '>' . $caption . '</option>' . $LINEBREAK;
525    }
526
527    echo <<< EOT
528            </select>
529        </td>
530    </tr>
531
532EOT;
533}
534
535function create_form(&$data)
536{
537    foreach ($data as $element) {
538        if (is_array($element)) {
539            switch ($element[2]) {
540            case 0:
541                form_input($element[0], $element[1]);
542                break;
543            case 1:
544                form_yes_no($element[0], $element[1]);
545                break;
546            case 2:
547                form_category($element[0], $element[1]);
548                break;
549            case 3:
550                form_textarea($element[0], $element[1]);
551                break;
552            case 4:
553                form_alb_thumb($element[0], $element[1]);
554                break;
555            case 5:
556                form_visibility($element[0], $element[1]);
557                break;
558            case 6:
559                form_password($element[0], $element[1]);
560                break;
561            case 7:
562                form_password_hint($element[0], $element[1]);
563                break;
564            case 8:
565                form_moderator($element[0], $element[1]);
566                break;
567            case 9:
568                form_password_protect($element[0], $element[1]);
569                break;
570            default:
571                cpg_die(CRITICAL_ERROR, 'Invalid action for form creation', __FILE__, __LINE__);
572            }
573        } else {
574            form_label($element);
575        }
576    }
577}
578
579function alb_list_box()
580{
581    global $CONFIG, $CLEAN, $cpg_udb, $CPG_PHP_SELF, $lang_modifyalb_php, $LINEBREAK;
582
583    $rowset = array();
584
585    if (GALLERY_ADMIN_MODE) {
586
587        $result = cpg_db_query("SELECT a.aid, a.title, c.name FROM {$CONFIG['TABLE_ALBUMS']} AS a INNER JOIN {$CONFIG['TABLE_CATEGORIES']} AS c ON a.category = c.cid WHERE a.category < '" . FIRST_USER_CAT . "'");
588
589        while ($row = $result->fetchAssoc()) {
590            // Add to multi-dim array for later sorting
591            $rowset[] = array(
592                'cat'   => $row['name'],
593                'aid'   => $row['aid'],
594                'title' => $row['title'],
595            );
596        }
597
598        $result->free();
599
600        //now we need to select the albums without a category
601        $result = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = 0");
602
603        while ($row = $result->fetchAssoc()) {
604            // Add to multi-dim array for later sorting
605            $rowset[] = array(
606                'cat'   => $lang_modifyalb_php['no_cat'],
607                'aid'   => $row['aid'],
608                'title' => $row['title'],
609            );
610        }
611
612        $result->free();
613
614        $sql = $cpg_udb->get_admin_album_list();
615
616        $result = cpg_db_query($sql);
617
618        while ($row = $result->fetchAssoc()) {
619            // Add to multi-dim array for later sorting
620            $rowset[] = array(
621                'cat'   => $lang_modifyalb_php['user_gal'],
622                'aid'   => $row['aid'],
623                'title' => $row['title'],
624            );
625        }
626
627        $result->free();
628
629    } else {
630        //Only list the albums owned by the user
631
632        //get albums in "my albums"
633        $result = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = ".(USER_ID + FIRST_USER_CAT)." AND owner = ".USER_ID);
634
635        while ($row = $result->fetchAssoc()) {
636            // Add to multi-dim array for later sorting
637            $rowset[] = array(
638                'cat'   => $lang_modifyalb_php['my_gal'],
639                'aid'   => $row['aid'],
640                'title' => $row['title'],
641            );
642        }
643
644        $result->free();
645
646        //get public albums
647        $result = cpg_db_query("SELECT a.aid, a.title, c.name FROM {$CONFIG['TABLE_ALBUMS']} AS a INNER JOIN {$CONFIG['TABLE_CATEGORIES']} AS c ON a.category = c.cid WHERE a.owner = ".USER_ID);
648
649        while ($row = $result->fetchAssoc()) {
650            // Add to multi-dim array for later sorting
651            $rowset[] = array(
652                'cat'   => $row['name'],
653                'aid'   => $row['aid'],
654                'title' => $row['title'],
655            );
656        }
657
658        $result->free();
659
660        //now we need to select the albums without a category
661        $result = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = 0 AND owner = ".USER_ID);
662
663        while ($row = $result->fetchAssoc()) {
664            // Add to multi-dim array for later sorting
665            $rowset[] = array(
666                'cat'   => $lang_modifyalb_php['no_cat'],
667                'aid'   => $row['aid'],
668                'title' => $row['title'],
669            );
670        }
671
672        $result->free();
673    }
674
675    // Sort by category and album title
676    $rowset = array_csort($rowset, 'cat', 'title');
677
678    if (count($rowset)) {
679
680         // Create the nicely sorted and formatted drop down list
681        $alb_cat = '';
682        $select = "<select name=\"album_listbox\" class=\"listbox\" onchange=\"if(this.options[this.selectedIndex].value) window.location.href='{$CPG_PHP_SELF}?album='+this.options[this.selectedIndex].value;\">" . $LINEBREAK;
683
684        foreach ($rowset as $val) {
685            if ($val['cat'] != $alb_cat) {
686                if ($alb_cat) {
687                    $select .= '</optgroup>' . $LINEBREAK;
688                }
689                $select .= '<optgroup label="' . $val['cat'] . '">' . $LINEBREAK;
690                $alb_cat = $val['cat'];
691            }
692            $select .= '<option value="' . $val['aid'] . '"' . ($val['aid'] == $CLEAN['album'] ? ' selected="selected"' : '') . '>   ' . $val['title'] . '</option>' . $LINEBREAK;
693        }
694
695        if ($alb_cat) {
696            $select .= '</optgroup>' . $LINEBREAK;
697        }
698
699        $select .= '</select>' . $LINEBREAK;
700
701        return $select;
702    }
703}
704
705if (!$CLEAN['album']) {
706
707    if (GALLERY_ADMIN_MODE) {
708        $results = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE 1 LIMIT 1");
709    } else {
710        $results = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . (FIRST_USER_CAT + USER_ID) . " OR owner = '" . USER_ID . "' LIMIT 1");
711    }
712
713    if ($results->numRows() == 0) {
714        cpg_die(ERROR, $lang_modifyalb_php['err_no_alb_to_modify'], __FILE__, __LINE__);
715    }
716
717    $ALBUM_DATA = $results->fetchAssoc(true);
718
719    $CLEAN['album'] = $ALBUM_DATA['aid'];
720
721} else {
722
723    $results = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='{$CLEAN['album']}'");
724
725    if (!$results->numRows()) {
726        cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
727    }
728
729    $ALBUM_DATA = $results->fetchAssoc(true);
730}
731
732$cat = $ALBUM_DATA['category'];
733$actual_cat = $cat;
734
735//////////// main code start ///////////////////
736
737js_include('js/modifyalb.js');
738
739set_js_var('reset_views_confirm', $lang_modifyalb_php['reset_views_confirm']);
740set_js_var('cursor_stop', $icon_array['stop']);
741
742pageheader(sprintf($lang_modifyalb_php['upd_alb_n'], $ALBUM_DATA['title']));
743
744$album_lb = alb_list_box();
745
746
747
748echo <<< EOT
749    <form method="post" name="modifyalbum" action="db_input.php">
750    <input type="hidden" name="event" value="album_update" />
751    <input type="hidden" name="aid" value="{$CLEAN['album']}" />
752EOT;
753
754starttable("100%", cpg_fetch_icon('modifyalb', 1) . $lang_common['album_properties'] . ' - ' . $lang_modifyalb_php['update'].$help['table'], 2, 'cpg_zebra');
755
756echo <<< EOT
757    <tr>
758        <td class="tableh2">
759            <strong>{$lang_modifyalb_php['related_tasks']}</strong>{$help['related_tasks']}
760        </td>
761        <td class="tableh2" align="center">
762            <a href="editpics.php?album={$CLEAN['album']}" class="admin_menu">{$icon_array['edit_files']}{$lang_modifyalb_php['edit_files']}</a>
763            &nbsp;&nbsp;-&nbsp;&nbsp;
764            <a href="index.php?cat={$ALBUM_DATA['category']}" class="admin_menu">{$icon_array['category']}{$lang_modifyalb_php['parent_category']}</a>
765            &nbsp;&nbsp;-&nbsp;&nbsp;
766            <a href="thumbnails.php?album={$CLEAN['album']}" class="admin_menu">{$icon_array['thumbnail']}{$lang_modifyalb_php['thumbnail_view']}</a>
767        </td>
768    </tr>
769    <tr>
770        <td>
771            {$icon_array['album']}{$lang_modifyalb_php['choose_album']}{$help['choose_album']}
772        </td>
773        <td align="left">
774            $album_lb
775        </td>
776    </tr>
777
778EOT;
779
780create_form($data);
781
782echo <<< EOT
783    <tr>
784        <td colspan="2" align="left" class="tablef">
785            <a name="notice1"></a>
786EOT;
787
788if (GALLERY_ADMIN_MODE) {
789    printf($lang_modifyalb_php['notice1'], '<a href="groupmgr.php">', '</a>');
790} else {
791    printf($lang_modifyalb_php['notice1'], '', '');
792}
793list($timestamp, $form_token) = getFormToken();
794echo <<< EOT
795        </td>
796    </tr>
797    <tr>
798        <td colspan="2" align="center" class="tablef">
799            <button type="submit" class="button" name="update_album" value="{$lang_modifyalb_php['update']}">{$icon_array['ok']}{$lang_modifyalb_php['update']}</button>
800            <input type="hidden" name="form_token" value="{$form_token}" />
801            <input type="hidden" name="timestamp" value="{$timestamp}" />
802        </td>
803    </tr>
804
805EOT;
806
807endtable();
808echo '</form>';
809
810if (GALLERY_ADMIN_MODE) {
811
812    // get the album stats
813    $result = cpg_db_query("SELECT SUM(hits) FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='{$CLEAN['album']}'");
814    $nbEnr = $result->fetchArray(true);
815    $hits = $nbEnr[0];
816
817    if (!$hits) {
818        $hits = 0;
819    }
820
821    $result = cpg_db_query("SELECT SUM(votes) FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='{$CLEAN['album']}' AND votes > 0");
822    $nbEnr = $result->fetchArray(true);
823    $votes = $nbEnr[0];
824
825    if (!$votes) {
826        $votes = 0;
827    }
828
829    $result = cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='{$CLEAN['album']}'");
830    $nbEnr = $result->fetchArray(true);
831    $files = $nbEnr[0];
832
833    if (!$files) {
834        $files = 0;
835    }
836
837    $result = cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_COMMENTS']} AS c INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.pid = c.pid WHERE aid='{$CLEAN['album']}'");
838    $nbEnr = $result->fetchArray(true);
839    $comments = $nbEnr[0];
840
841    if (!$comments) {
842        $comments = 0;
843    }
844
845    echo <<< EOT
846    <br />
847    <form action="db_input.php" method="post" name="reset_views_form" onsubmit="return defaultagree(this)">
848    <input type="hidden" name="event" value="album_reset" />
849    <input type="hidden" name="aid" value="{$CLEAN['album']}" />
850EOT;
851
852    // set up the translation strings
853    $translation_reset_views     = sprintf($lang_modifyalb_php['reset_views'], '&quot;'.$ALBUM_DATA['title'].'&quot;');
854    $translation_reset_rating    = sprintf($lang_modifyalb_php['reset_rating'], '&quot;'.$ALBUM_DATA['title'].'&quot;');
855    $translation_delete_comments = sprintf($lang_modifyalb_php['delete_comments'], '&quot;'.$ALBUM_DATA['title'].'&quot;');
856    $translation_delete_files    = sprintf($lang_modifyalb_php['delete_files'], '<span style="color:red;font-weight:bold">', '</span>', '&quot;'.$ALBUM_DATA['title'].'&quot;');
857
858    starttable('100%', cpg_fetch_icon('modifyalb', 1) . $lang_common['album_properties'] . ' - ' . $lang_modifyalb_php['reset_album'], 2);
859
860    echo <<< EOT
861    <tr>
862            <td align="left" class="tableb">
863                {$icon_array['views']} <strong>$hits</strong> {$lang_modifyalb_php['views']}
864            </td>
865            <td align="left" class="tableb">
866                <input type="checkbox" name="reset_views" id="reset_views" value="1" class="checkbox" />
867                <label for="reset_views" class="clickable_option">$translation_reset_views</label>
868            </td>
869    </tr>
870    <tr>
871            <td align="left" class="tableb tableb_alternate">
872                {$icon_array['rate']} <strong>$votes</strong> {$lang_modifyalb_php['votes']}
873            </td>
874            <td align="left" class="tableb tableb_alternate">
875                <input type="checkbox" name="reset_rating" id="reset_rating" value="1" class="checkbox" />
876                <label for="reset_rating" class="clickable_option">$translation_reset_rating</label>
877            </td>
878    </tr>
879    <tr>
880            <td align="left" class="tableb">
881                {$icon_array['comment']} <strong>$comments</strong> {$lang_modifyalb_php['comments']}
882            </td>
883            <td align="left" class="tableb">
884                <input type="checkbox" name="delete_comments" id="delete_comments" value="1" class="checkbox" />
885                <label for="delete_comments" class="clickable_option">$translation_delete_comments</label>
886            </td>
887    </tr>
888    <tr>
889            <td align="left" class="tableb tableb_alternate">
890                {$icon_array['file']} <strong>$files</strong> {$lang_modifyalb_php['files']}
891            </td>
892            <td align="left" class="tableb tableb_alternate">
893                <input type="checkbox" name="delete_files" id="delete_files" value="1" class="checkbox" />
894                <label for="delete_files" class="clickable_option">$translation_delete_files</label>
895            </td>
896    </tr>
897    <tr>
898            <td class="tablef" colspan="2" align="center" valign="bottom">
899                <button type="submit" class="button cursor_stop" name="reset_submit" value="{$lang_modifyalb_php['submit_reset']}" disabled="disabled" style="cursor:url({$icon_array['stop']}),text;">{$icon_array['ok']}{$lang_modifyalb_php['submit_reset']}</button>
900                <input name="agreecheck" id="agreecheck" type="checkbox" onclick="agreesubmit(this)" /><label for="agreecheck" class="clickable_option">{$lang_modifyalb_php['reset_views_confirm']}</label>
901            </td>
902    </tr>
903
904EOT;
905    endtable();
906    echo <<< EOT
907        <input type="hidden" name="form_token" value="{$form_token}" />
908        <input type="hidden" name="timestamp" value="{$timestamp}" />
909    </form>
910
911EOT;
912}
913pagefooter();
914
915//EOF