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/catmgr.php,v $
15
  $Revision: 1.7 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:10 $
18
**********************************************/
19
 
20
define('IN_COPPERMINE', true);
21
define('CATMGR_PHP', true);
22
 
23
require('include/init.inc.php');
24
 
25
if (!GALLERY_ADMIN_MODE) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
26
// Fix categories that have an invalid parent
27
function fix_cat_table()
28
{
29
    global $CONFIG;
30
 
31
    $result = db_query("SELECT cid FROM {$CONFIG['TABLE_CATEGORIES']} WHERE 1");
32
    if (mysql_num_rows($result) > 0) {
33
        $set = '';
34
        while ($row = mysql_fetch_array($result)) $set .= $row['cid'] . ',';
35
        $set = '(' . substr($set, 0, -1) . ')';
36
        $sql = "UPDATE {$CONFIG['TABLE_CATEGORIES']} " . "SET parent = '0' " . "WHERE parent=cid OR parent NOT IN $set";
37
        $result = db_query($sql);
38
    }
39
}
40
 
41
function get_subcat_data($parent, $ident = '')
42
{
43
    global $CONFIG, $CAT_LIST;
44
 
45
    $sql = "SELECT cid, name, description " . "FROM {$CONFIG['TABLE_CATEGORIES']} " . "WHERE parent = '$parent' " . "ORDER BY pos";
46
    $result = db_query($sql);
47
 
48
    if (($cat_count = mysql_num_rows($result)) > 0) {
49
        $rowset = db_fetch_rowset($result);
50
        $pos = 0;
51
        foreach ($rowset as $subcat) {
52
            if ($pos > 0) {
53
                $CAT_LIST[] = array('cid' => $subcat['cid'],
54
                    'parent' => $parent,
55
                    'pos' => $pos++,
56
                    'prev' => $prev_cid,
57
                    'cat_count' => $cat_count,
58
                    'name' => $ident . $subcat['name']);
59
                $CAT_LIST[$last_index]['next'] = $subcat['cid'];
60
            } else {
61
                $CAT_LIST[] = array('cid' => $subcat['cid'],
62
                    'parent' => $parent,
63
                    'pos' => $pos++,
64
                    'cat_count' => $cat_count,
65
                    'name' => $ident . $subcat['name']);
66
            }
67
            $prev_cid = $subcat['cid'];
68
            $last_index = count($CAT_LIST) -1;
69
            get_subcat_data($subcat['cid'], $ident . '&nbsp;&nbsp;&nbsp;');
70
        }
71
    }
72
}
73
 
74
function update_cat_order()
75
{
76
    global $CAT_LIST, $CONFIG;
77
 
78
    foreach ($CAT_LIST as $category)
79
    db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos='{$category['pos']}' WHERE cid = '{$category['cid']}' LIMIT 1");
80
}
81
 
82
function cat_list_box($highlight = 0, $curr_cat, $on_change_refresh = true)
83
{
84
    global $CAT_LIST, $PHP_SELF,$lang_albmgr_php;
85
 
86
    if ($on_change_refresh) {
87
        $lb = <<< EOT
88
                        <select onChange="if(this.options[this.selectedIndex].value) window.location.href='$PHP_SELF?op=setparent&cid=$curr_cat&parent='+this.options[this.selectedIndex].value;"  name="parent" class="listbox">
89
 
90
EOT;
91
    } else {
92
        $lb = <<< EOT
93
                        <select name="parent" class="listbox">
94
 
95
EOT;
96
    }
97
    $lb .= '                        <option value="0"' . ($highlight == 0 ? ' selected': '') . '>' . $lang_albmgr_php['no_category'] . "</option>\n";
98
    foreach($CAT_LIST as $category) if ($category['cid'] != 1 && $category['cid'] != $curr_cat) {
99
        $lb .= '                        <option value="' . $category['cid'] . '"' . ($highlight == $category['cid'] ? ' selected': '') . ">" . $category['name'] . "</option>\n";
100
    } elseif ($category['cid'] != 1 && $category['cid'] == $curr_cat) {
101
        $lb .= '                        <option value="' . $category['parent'] . '"' . ($highlight == $category['cid'] ? ' selected': '') . ">" . $category['name'] . "</option>\n";
102
    }
103
 
104
    $lb .= <<<EOT
105
                        </select>
106
 
107
EOT;
108
 
109
    return $lb;
110
}
111
 
112
function form_alb_thumb()
113
{
114
    global $CONFIG, $lang_catmgr_php, $lang_modifyalb_php, $current_category, $cid;
115
    $results = db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_ALBUMS']}.category = '$cid' AND approved='YES' ORDER BY filename");
116
    if (mysql_num_rows($results) == 0) {
117
        echo <<<EOT
118
        <tr>
119
                <td class="tableb" valign="top">
120
                        {$lang_modifyalb_php['alb_thumb']}
121
                </td>
122
                <td class="tableb" valign="top">
123
                        <i>{$lang_modifyalb_php['alb_empty']}</i>
124
                        <input type="hidden" name="thumb" value="0">
125
                </td>
126
        </tr>
127
 
128
EOT;
129
        return;
130
    }
131
 
132
    echo <<<EOT
133
<script language="JavaScript" type="text/JavaScript">
134
var Pic = new Array()
135
 
136
Pic[0] = 'images/nopic.jpg'
137
 
138
EOT;
139
 
140
    $initial_thumb_url = 'images/nopic.jpg';
141
    $img_list = array(0 => $lang_modifyalb_php['last_uploaded']);
142
    while ($picture = mysql_fetch_array($results)) {
143
        $thumb_url = get_pic_url($picture, 'thumb');
144
        echo "Pic[{$picture['pid']}] = '" . $thumb_url . "'\n";
145
        if ($picture['pid'] == $current_category['thumb']) $initial_thumb_url = $thumb_url;
146
        $img_list[$picture['pid']] = htmlspecialchars($picture['filename']);
147
    } // while
148
    echo <<<EOT
149
 
150
function ChangeThumb(index)
151
{
152
        document.images.Thumb.src = Pic[index]
153
}
154
</script>
155
 
156
EOT;
157
    $thumb_cell_height = $CONFIG['thumb_width'] + 17;
158
    echo <<<EOT
159
        <tr>
160
                <td class="tableb" valign="top">
161
                        {$lang_catmgr_php['cat_thumb']}
162
                </td>
163
                <td class="tableb" align="center">
164
                        <table cellspacing="0" cellpadding="5" border="0">
165
                                <tr>
166
                                        <td width="$thumb_cell_height" height="$thumb_cell_height" align="center"><img src="$initial_thumb_url" name='Thumb' class='image' /><br /></td>
167
                                </tr>
168
                        </table>
169
                        <select name="thumb" 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);">
170
 
171
EOT;
172
    foreach($img_list as $pid => $pic_name) {
173
        echo '                                <option value="' . $pid . '"' . ($pid == $current_category['thumb'] ? ' selected':'') . '>' . $pic_name . "</option>\n";
174
    }
175
    echo <<<EOT
176
                        </select>
177
                </td>
178
        </tr>
179
 
180
EOT;
181
}
182
 
183
function display_cat_list()
184
{
185
    global $CAT_LIST, $PHP_SELF;
186
 
187
    $CAT_LIST3 = $CAT_LIST;
188
 
189
    foreach ($CAT_LIST3 as $key => $category) {
190
        echo "        <tr>\n";
191
        echo '                <td class="tableb" width="80%"><b>' . $category['name'] . '</b></td>' . "\n";
192
 
193
        if ($category['pos'] > 0) {
194
            echo '                <td class="tableb" width="4%"><a href="' . $PHP_SELF . '?op=move&cid1=' . $category['cid'] . '&pos1=' . ($category['pos']-1) . '&cid2=' . $category['prev'] . '&pos2=' . ($category['pos']) . '">' . '<img src="images/up.gif"  border="0">' . '</a></td>' . "\n";
195
        } else {
196
            echo '                <td class="tableb" width="4%">' . '&nbsp;' . '</td>' . "\n";
197
        }
198
 
199
        if ($category['pos'] < $category['cat_count']-1) {
200
            echo '                <td class="tableb" width="4%"><a href="' . $PHP_SELF . '?op=move&cid1=' . $category['cid'] . '&pos1=' . ($category['pos'] + 1) . '&cid2=' . $category['next'] . '&pos2=' . ($category['pos']) . '">' . '<img src="images/down.gif"  border="0">' . '</a></td>' . "\n";
201
        } else {
202
            echo '                <td class="tableb" width="4%">' . '&nbsp;' . '</td>' . "\n";
203
        }
204
 
205
        if ($category['cid'] != 1) {
206
            echo '                <td class="tableb" width="4%"><a href="' . $PHP_SELF . '?op=deletecat&cid=' . $category['cid'] . '" onClick="return confirmDel(\'' . addslashes(str_replace('&nbsp;', '', $category['name'])) . '\')">' . '<img src="images/delete.gif"  border="0">' . '</a></td>' . "\n";
207
        } else {
208
            echo '                <td class="tableb" width="4%">' . '&nbsp;' . '</td>' . "\n";
209
        }
210
 
211
        echo '                <td class="tableb" width="4%">' . '<a href="' . $PHP_SELF . '?op=editcat&cid=' . $category['cid'] . '">' . '<img src="images/edit.gif" border="0">' . '</a></td>' . "\n";
212
        echo '                <td class="tableb" width="4%">' . "\n" . cat_list_box($category['parent'], $category['cid']) . "\n" . '</td>' . "\n";
213
        echo "        </tr>\n";
214
    }
215
}
216
 
217
function verify_children($parent, $cid)
218
{
219
    global $CONFIG, $children;
220
 
221
    $sql = "SELECT cid " . "FROM {$CONFIG['TABLE_CATEGORIES']} " . "WHERE parent = '$parent' ";
222
    $result = db_query($sql);
223
 
224
    if (($cat_count = mysql_num_rows($result)) > 0) {
225
                while ($row = mysql_fetch_array($result)) {
226
                       $children[]=$row['cid'];
227
       // call this function again to this this
228
       // child's children
229
                       verify_children($row['cid'], $cid);
230
              }
231
    }
232
        return false;
233
}
234
 
235
$op = isset($HTTP_GET_VARS['op']) ? $HTTP_GET_VARS['op'] : '';
236
$current_category = array('cid' => '0', 'name' => '', 'parent' => '0', 'description' => '');
237
 
238
switch ($op) {
239
    case 'move':
240
        if (!isset($HTTP_GET_VARS['cid1']) || !isset($HTTP_GET_VARS['cid2']) || !isset($HTTP_GET_VARS['pos1']) || !isset($HTTP_GET_VARS['pos2'])) cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'move'), __FILE__, __LINE__);
241
 
242
        $cid1 = (int)$HTTP_GET_VARS['cid1'];
243
        $cid2 = (int)$HTTP_GET_VARS['cid2'];
244
        $pos1 = (int)$HTTP_GET_VARS['pos1'];
245
        $pos2 = (int)$HTTP_GET_VARS['pos2'];
246
 
247
        db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos='$pos1' WHERE cid = '$cid1' LIMIT 1");
248
        db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos='$pos2' WHERE cid = '$cid2' LIMIT 1");
249
        break;
250
 
251
    case 'setparent':
252
        if (!isset($HTTP_GET_VARS['cid']) || !isset($HTTP_GET_VARS['parent'])) cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'setparent'), __FILE__, __LINE__);
253
 
254
        $cid = (int)$HTTP_GET_VARS['cid'];
255
        $parent = (int)$HTTP_GET_VARS['parent'];
256
                $children=array();
257
                verify_children($cid, $cid);
258
                if (!in_array($parent, $children)){
259
                db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', pos='-1' WHERE cid = '$cid' LIMIT 1");
260
                }else{
261
                        cpg_die(ERROR, "You cannot move a category into its own child", __FILE__, __LINE__);
262
                }
263
                break;
264
 
265
    case 'editcat':
266
        if (!isset($HTTP_GET_VARS['cid'])) cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'editcat'), __FILE__, __LINE__);
267
 
268
        $cid = (int)$HTTP_GET_VARS['cid'];
269
        $result = db_query("SELECT cid, name, parent, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");
270
 
271
        if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__);
272
        $current_category = mysql_fetch_array($result);
273
        break;
274
 
275
    case 'updatecat':
276
        if (!isset($HTTP_POST_VARS['cid']) || !isset($HTTP_POST_VARS['parent']) || !isset($HTTP_POST_VARS['name']) || !isset($HTTP_POST_VARS['description'])) cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'updatecat'), __FILE__, __LINE__);
277
 
278
                $name = trim($HTTP_POST_VARS['name']);
279
                if (empty($name)){
280
                        break;
281
                }
282
 
283
 
284
        $cid = (int)$HTTP_POST_VARS['cid'];
285
        $parent = (int)$HTTP_POST_VARS['parent'];
286
        $thumb = (int)$HTTP_POST_VARS['thumb'];
287
        $name = trim($HTTP_POST_VARS['name']) ? addslashes($HTTP_POST_VARS['name']) : '&lt;???&gt;';
288
        $description = addslashes($HTTP_POST_VARS['description']);
289
                $children=array();
290
                verify_children($cid, $cid);
291
                if (!in_array($parent, $children)){
292
                db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
293
                }else{
294
                        db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
295
                }
296
        break;
297
 
298
    case 'createcat':
299
        if (!isset($HTTP_POST_VARS['parent']) || !isset($HTTP_POST_VARS['name']) || !isset($HTTP_POST_VARS['description'])) cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'createcat'), __FILE__, __LINE__);
300
 
301
                $name = trim($HTTP_POST_VARS['name']);
302
 
303
                if (empty($name)){
304
                        break;
305
                }
306
 
307
 
308
                $parent = (int)$HTTP_POST_VARS['parent'];
309
        $name = trim($HTTP_POST_VARS['name']) ? addslashes($HTTP_POST_VARS['name']) : '&lt;???&gt;';
310
        $description = addslashes($HTTP_POST_VARS['description']);
311
 
312
        db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description) VALUES ('10000', '$parent', '$name', '$description')");
313
        break;
314
 
315
    case 'deletecat':
316
        if (!isset($HTTP_GET_VARS['cid'])) cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'deletecat'), __FILE__, __LINE__);
317
 
318
        $cid = (int)$HTTP_GET_VARS['cid'];
319
 
320
        $result = db_query("SELECT parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");
321
        if ($cid == 1) cpg_die(ERROR, $lang_catmgr_php['usergal_cat_ro'], __FILE__, __LINE__);
322
        if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__);
323
        $del_category = mysql_fetch_array($result);
324
        $parent = $del_category['parent'];
325
        $result = db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent' WHERE parent = '$cid'");
326
        $result = db_query("UPDATE {$CONFIG['TABLE_ALBUMS']} SET category='$parent' WHERE category = '$cid'");
327
        $result = db_query("DELETE FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid='$cid' LIMIT 1");
328
        break;
329
}
330
 
331
fix_cat_table();
332
get_subcat_data(0);
333
update_cat_order();
334
 
335
pageheader($lang_catmgr_php['manage_cat']);
336
echo <<<EOT
337
 
338
<script language="javascript">
339
function confirmDel(catName)
340
{
341
    return confirm("{$lang_catmgr_php['confirm_delete']} (" + catName + ") ?");
342
}
343
</script>
344
 
345
 
346
EOT;
347
 
348
starttable('100%');
349
 
350
echo <<<EOT
351
        <tr>
352
                <td class="tableh1"><b><span class="statlink">{$lang_catmgr_php['category']}</span></b></td>
353
                <td colspan="4" class="tableh1" align="center"><b><span class="statlink">{$lang_catmgr_php['operations']}</span></b></td>
354
                <td class="tableh1" align="center"><b><span class="statlink">{$lang_catmgr_php['move_into']}</span></b></td>
355
        </tr>
356
        <form method="get" action="$PHP_SELF">
357
 
358
EOT;
359
 
360
display_cat_list();
361
 
362
echo <<<EOT
363
        </form>
364
 
365
EOT;
366
 
367
endtable();
368
 
369
echo "<br />\n";
370
 
371
starttable('100%', $lang_catmgr_php['update_create'], 2);
372
$lb = cat_list_box($current_category['parent'], $current_category['cid'], false);
373
$op = $current_category['cid'] ? 'updatecat' : 'createcat';
374
echo <<<EOT
375
        <form method="post" action="$PHP_SELF?op=$op">
376
        <input type="hidden" name="cid" value ="{$current_category['cid']}">
377
        <tr>
378
            <td width="40%" class="tableb">
379
                        {$lang_catmgr_php['parent_cat']}
380
        </td>
381
        <td width="60%" class="tableb" valign="top">
382
                $lb
383
                </td>
384
        </tr>
385
        <tr>
386
            <td width="40%" class="tableb">
387
                        {$lang_catmgr_php['cat_title']}
388
        </td>
389
        <td width="60%" class="tableb" valign="top">
390
                <input type="text" style="width: 100%" name="name" value="{$current_category['name']}" class="textinput">
391
                </td>
392
        </tr>
393
        <tr>
394
                <td class="tableb" valign="top">
395
                        {$lang_catmgr_php['cat_desc']}
396
                </td>
397
                <td class="tableb" valign="top">
398
                        <textarea name="description" ROWS="5" COLS="40" SIZE="9"  WRAP="virtual" STYLE="WIDTH: 100%;" class="textinput">{$current_category['description']}</textarea>
399
                </td>
400
        </tr>
401
EOT;
402
 
403
form_alb_thumb();
404
 
405
echo <<<EOT
406
        <tr>
407
                <td colspan="2" align="center" class="tablef">
408
                <input type="submit" value="{$lang_catmgr_php['update_create']}" class="button">
409
                </td>
410
                </form>
411
        </tr>
412
 
413
EOT;
414
 
415
endtable();
416
pagefooter();
417
ob_end_flush();
418
 
419
?>