forked from coppermine-gallery/cpg1.6.x
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcatmgr.php
815 lines (596 loc) · 28.3 KB
/
catmgr.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2016 Coppermine Dev Team
v1.0 originally written by Gregory Demar
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3
as published by the Free Software Foundation.
********************************************
Coppermine version: 1.6.01
$HeadURL$
**********************************************/
/*
The category manager needs to be able to work with hundreds of categories
without hitting the PHP memory limit. The way it does this is to delay
populating the dropdown boxes until they are actually clicked on.
It loads the list of categories using javascript from the main selector
at the bottom of the screen. All other selectors contain only the current
parent category until clicked on.
This means the page is much smaller and is usable with lots of categories.
Without this, the dropdown boxes grow exponentially as each category has the
option to be moved into all other categories.
If you make major changes to this page, please test with 200-300 categories
nested several levels deep.
*/
define('IN_COPPERMINE', true);
define('CATMGR_PHP', true);
require('include/init.inc.php');
set_js_var('lang_confirm_delete', $lang_catmgr_php['confirm_delete']);
list($timestamp, $form_token) = getFormToken();
set_js_var('form_token', $form_token);
set_js_var('timestamp', $timestamp);
js_include('js/catmgr.js');
if (!GALLERY_ADMIN_MODE) {
cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
}
$CAT_LIST = array(
0 => array(
'cid' => 0,
'cat_count' => 0,
),
);
$icon_array['submit'] = cpg_fetch_icon('ok', 1);
function get_subcat_data($parent, $ident = '')
{
global $CONFIG, $CAT_LIST;
$sql = "SELECT rgt, cid, parent, name, pos FROM {$CONFIG['TABLE_CATEGORIES']} ORDER BY lft ASC";
$result = cpg_db_query($sql);
if ($result->numRows() > 0) {
$rowset = cpg_db_fetch_rowset($result, true);
$right = array();
foreach ($rowset as $subcat) {
if (count($right) > 0) {
// check if we should remove a node from the stack
while ($right && $right[count($right) - 1]['rgt'] < $subcat['rgt']) {
$prev = array_pop($right);
$last_index = $prev_cid = $prev['cid'];
}
}
$ident = str_repeat(' ', count($right));
$right[] = $subcat;
if ($subcat['pos'] > 0) {
$CAT_LIST[$subcat['cid']] = array(
'cid' => $subcat['cid'],
'parent' => $subcat['parent'],
'pos' => $subcat['pos'],
'prev' => $prev_cid,
'cat_count' => 0,
'name' => $ident . $subcat['name'],
);
$CAT_LIST[$last_index]['next'] = $subcat['cid'];
} else {
$CAT_LIST[$subcat['cid']] = array(
'cid' => $subcat['cid'],
'parent' => $subcat['parent'],
'pos' => $subcat['pos'],
'cat_count' => 0,
'name' => $ident . $subcat['name'],
);
}
$CAT_LIST[$subcat['parent']]['cat_count']++;
}
}
}
function cat_list_box($cid, &$parent, $on_change_refresh = true)
{
global $lang_catmgr_php, $CAT_LIST, $LINEBREAK;
$lb = '';
if ($on_change_refresh) {
$lb .= '<select name="parent" onmouseover="setbuild(this, '. (int) $parent['cid'] . ', ' . $cid . ')" onchange="updateParent(this, ' . $cid . ')" class="listbox">';
if ($parent['cid'] == 0) {
$lb .= '<option value="0" selected="selected">' . $lang_catmgr_php['no_category'] . '</option>';
} else {
$lb .= '<option value="' . $parent['cid'] . '" selected="selected">' . $parent['name'] . '</option>';
}
$lb .= '</select>';
} else {
$lb .= '<select name="parent" id="build_source" class="listbox">' . $LINEBREAK;
$lb .= ' <option value="0"' . ($parent == 0 ? ' selected="selected"': '') . '>' . $lang_catmgr_php['no_category'] . '</option>' . $LINEBREAK;
foreach ($CAT_LIST as $category) {
if ($category['cid'] > 1 && $category['cid'] != $cid) {
$lb .= ' <option value="' . $category['cid'] . '"' . ($parent == $category['cid'] ? '" selected="selected"': '') . ">" . $category['name'] . '</option>' . $LINEBREAK;
}
}
$lb .= '</select>';
}
return $lb;
}
/**
* usergroup_list_box()
*
* @param integer $cid
*
* @return string $usergroup_listbox
**/
function usergroup_list_box($cid)
{
global $CONFIG, $LINEBREAK, $cpg_udb;
$add = $cpg_udb->use_post_based_groups ? 100 : 0;
$exclude_groups = array($cpg_udb->guestgroup + $add);
foreach ($cpg_udb->admingroups as $id) {
$exclude_groups[] = $id + $add;
}
//get the category info from the db
$sql = "SELECT ug.group_name AS name, ug.group_id AS id, catm.group_id AS catm_gid FROM {$CONFIG['TABLE_USERGROUPS']} AS ug LEFT JOIN {$CONFIG['TABLE_CATMAP']} AS catm ON catm.group_id = ug.group_id AND catm.cid = $cid";
$sql .= " HAVING id NOT IN (".implode(', ', $exclude_groups).")"; // don't list administrator and guest groups
$result = cpg_db_query($sql);
$rowset = cpg_db_fetch_rowset($result, true);
//put the values in an array for ease of use and clean code for now
foreach ($rowset as $row) {
$groups[$row['id']]['name'] = $row['name'];
if ($row['catm_gid'] != null) {
$groups[$row['id']]['selected'] = 'true';
} else {
$groups[$row['id']]['selected'] = 'false';
}
}
//create listbox
$usergroup_listbox = '<select name="user_groups[]" class="listbox" multiple="multiple">' . $LINEBREAK;
//loop through all groups
foreach ($groups as $id => $values) {
$usergroup_listbox .= ' <option value="' . $id . '"' . ($values['selected'] == 'true'? 'selected="selected"' : '') . ' >' . $values['name'] . '</option>' . $LINEBREAK;
}
$usergroup_listbox .= '</select>' . $LINEBREAK;
//return listbox
return $usergroup_listbox;
}
function form_alb_thumb()
{
global $CONFIG, $lang_catmgr_php, $lang_modifyalb_php, $current_category, $cid, $USER_DATA, $LINEBREAK;
function cpg_get_alb_keyword($sql) {
$keyword = '';
$result = cpg_db_query($sql);
if ($result->numRows()) {
while ($row = $result->fetchAssoc()) {
$keyword .= "OR (keywords LIKE '%{$row['keyword']}%') ";
}
}
$result->free();
return $keyword;
}
if ($cid == USER_GAL_CAT) {
$keyword = cpg_get_alb_keyword("SELECT DISTINCT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE category > ".FIRST_USER_CAT." AND keyword != ''");
$results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE (a.category > ".FIRST_USER_CAT." $keyword) AND approved = 'YES' ORDER BY filename");
} else {
$keyword = cpg_get_alb_keyword("SELECT DISTINCT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $cid AND keyword != ''");
$results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE (a.category = $cid $keyword) AND approved = 'YES' ORDER BY filename");
}
if ($results->numRows() == 0) {
echo <<<EOT
<tr>
<td class="tableb" valign="top">
{$lang_modifyalb_php['alb_thumb']}
</td>
<td class="tableb" valign="top">
<i>{$lang_modifyalb_php['alb_empty']}</i>
<input type="hidden" name="thumb" value="0" />
</td>
</tr>
EOT;
return;
}
$cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $USER_DATA['user_id']);
$initial_thumb_url = $cpg_nopic_data['thumb']; //'images/nopic.jpg';
echo <<< EOT
<script language="JavaScript" type="text/JavaScript">
var Pic = new Array()
Pic[0] = '$initial_thumb_url'
EOT;
$img_list = array(0 => $lang_modifyalb_php['last_uploaded']);
while ($picture = $results->fetchAssoc()) {
$thumb_url = get_pic_url($picture, 'thumb');
echo "Pic[{$picture['pid']}] = '" . $thumb_url . "'\n";
if ($picture['pid'] == $current_category['thumb']) {
$initial_thumb_url = $thumb_url;
}
$img_list[$picture['pid']] = htmlspecialchars($picture['filename']);
} // while
$results->free();
echo <<< EOT
</script>
EOT;
$thumb_cell_height = $CONFIG['thumb_width'] + 17;
echo <<<EOT
<tr>
<td class="tableb" valign="top">
{$lang_catmgr_php['cat_thumb']}
</td>
<td class="tableb" align="center">
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<td width="$thumb_cell_height" height="$thumb_cell_height" align="center"><img src="$initial_thumb_url" name='Thumb' class='image' /><br /></td>
</tr>
</table>
<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);">
EOT;
foreach ($img_list as $pid => $pic_name) {
echo ' <option value="' . $pid . '"' . (!empty($current_category['thumb']) && $pid == $current_category['thumb'] ? ' selected':'') . '>' . $pic_name . '</option>' . $LINEBREAK;
}
echo <<<EOT
</select>
</td>
</tr>
EOT;
}
function display_cat_list()
{
global $CAT_LIST, $CONFIG, $lang_catmgr_php, $lang_common, $CPG_PHP_SELF, $LINEBREAK;
$CAT_LIST3 = $CAT_LIST;
$loop_counter = 0;
list($timestamp, $form_token) = getFormToken();
$form_token = "&form_token={$form_token}&timestamp={$timestamp}";
foreach ($CAT_LIST3 as $key => $category) {
if ($category['cid'] == 0) {
continue;
}
if ($loop_counter == 0) {
$row_style_class = 'tableb';
} else {
$row_style_class = 'tableb tableb_alternate';
}
$loop_counter++;
if ($loop_counter > 1) {
$loop_counter = 0;
}
echo ' <tr>' . $LINEBREAK;
echo ' <td class="'.$row_style_class.'" width="80%"><strong>' . $category['name'] . '</strong></td>' . $LINEBREAK;
if ($category['pos'] > 0 && $CONFIG['categories_alpha_sort'] != 1) {
echo ' <td class="'.$row_style_class.'" width="4%"><a href="' . $CPG_PHP_SELF . '?op=movetop&cid1=' . $category['cid'] . '&pos1=' . ($category['pos']) . $form_token . '" class="rounded_menu"><span>' . cpg_fetch_icon('upup', 0, $lang_common['move_top']) . '</span></a></td>' . $LINEBREAK;
echo ' <td class="'.$row_style_class.'" width="4%"><a href="' . $CPG_PHP_SELF . '?op=move&cid1=' . $category['cid'] . '&pos1=' . ($category['pos']-1) . '&cid2=' . $category['prev'] . '&pos2=' . ($category['pos']) . $form_token . '" class="rounded_menu"><span>' . cpg_fetch_icon('up', 0, $lang_common['move_up']) . '</span></a></td>' . $LINEBREAK;
} else {
echo ' <td class="'.$row_style_class.'" width="4%">' . ' ' . '</td>' . $LINEBREAK;
echo ' <td class="'.$row_style_class.'" width="4%">' . ' ' . '</td>' . $LINEBREAK;
}
if ($category['pos'] < $CAT_LIST[$category['parent']]['cat_count']-1 && $CONFIG['categories_alpha_sort'] != 1) {
echo ' <td class="'.$row_style_class.'" width="4%"><a href="' . $CPG_PHP_SELF . '?op=move&cid1=' . $category['cid'] . '&pos1=' . ($category['pos'] + 1) . '&cid2=' . $category['next'] . '&pos2=' . ($category['pos']) . $form_token . '" class="rounded_menu"><span>' . cpg_fetch_icon('down', 0, $lang_common['move_down']) . '</span></a></td>' . $LINEBREAK;
echo ' <td class="'.$row_style_class.'" width="4%"><a href="' . $CPG_PHP_SELF . '?op=movebottom&cid1=' . $category['cid'] . '&pos1=' . ($category['pos']) . $form_token . '" class="rounded_menu"><span>' . cpg_fetch_icon('downdown', 0, $lang_common['move_bottom']) . '</span></a></td>' . $LINEBREAK;
} else {
echo ' <td class="'.$row_style_class.'" width="4%">' . ' ' . '</td>' . $LINEBREAK;
echo ' <td class="'.$row_style_class.'" width="4%">' . ' ' . '</td>' . $LINEBREAK;
}
if ($category['cid'] != 1) {
echo ' <td class="'.$row_style_class.'" width="4%"><a href="' . $CPG_PHP_SELF . '?op=deletecat&cid=' . $category['cid'] . $form_token . '" onclick="return confirmDel(\'' . addslashes(str_replace(' ', '', $category['name'])) . '\')" class="rounded_menu"><span>' . cpg_fetch_icon('delete', 0, $lang_common['delete']) . '</span></a></td>' . $LINEBREAK;
} else {
echo ' <td class="'.$row_style_class.'" width="4%">' . ' ' . '</td>' . $LINEBREAK;
}
echo ' <td class="'.$row_style_class.'" width="4%">' . '<a href="' . $CPG_PHP_SELF . '?op=editcat&cid=' . $category['cid'] . $form_token . '" class="rounded_menu"><span>' . cpg_fetch_icon('edit', 0, $lang_common['edit']) . '</span></a></td>' . $LINEBREAK;
echo ' <td class="'.$row_style_class.'" width="4%">' . $LINEBREAK . cat_list_box($category['cid'], $CAT_LIST3[$category['parent']]) . $LINEBREAK . '</td>' . $LINEBREAK;
echo ' </tr>' . $LINEBREAK;
}
}
function verify_children($parent, $cid)
{
global $CONFIG, $children;
$sql = "SELECT cid FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = $parent";
$result = cpg_db_query($sql);
if (($cat_count = $result->numRows()) > 0) {
while ($row = $result->fetchAssoc()) {
$children[] = $row['cid'];
verify_children($row['cid'], $cid);
}
}
$result->free();
return false;
}
if ($superCage->post->keyExists('update_config')) {
//Check if the form token is valid
if(!checkFormToken()){
cpg_die(ERROR, $lang_errors['invalid_form_token'], __FILE__, __LINE__);
}
$value = $superCage->post->getInt('categories_alpha_sort');
cpg_config_set('categories_alpha_sort', $value);
rebuild_tree();
}
if ($superCage->get->keyExists('op')) {
$op = $superCage->get->getAlpha('op');
//Check if the form token is valid
if(!checkFormToken()){
cpg_die(ERROR, $lang_errors['invalid_form_token'], __FILE__, __LINE__);
}
} else {
$op = '';
}
$current_category = array(
'cid' => 0,
'name' => '',
'parent' => 0,
'description' => '',
);
switch ($op) {
case 'move':
if (!$superCage->get->keyExists('cid1') || !$superCage->get->keyExists('cid2') || !$superCage->get->keyExists('pos1') || !$superCage->get->keyExists('pos2')) {
cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'move'), __FILE__, __LINE__);
}
$cid1 = $superCage->get->getInt('cid1');
$cid2 = $superCage->get->getInt('cid2');
$pos1 = $superCage->get->getInt('pos1');
$pos2 = $superCage->get->getInt('pos2');
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos = $pos1, lft = 0 WHERE cid = $cid1");
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos = $pos2, lft = 0 WHERE cid = $cid2");
break;
case 'movetop':
if (!$superCage->get->keyExists('cid1') || !$superCage->get->keyExists('pos1')) {
cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'movetop'), __FILE__, __LINE__);
}
$cid1 = $superCage->get->getInt('cid1'); // cat to move to top
$pos1 = $superCage->get->getInt('pos1'); // current pos for cat
get_subcat_data(0);
$cid_array = array();
foreach ($CAT_LIST as $iCat) {
$cid_array[$iCat['cid']] = $iCat;
}
$CAT_LIST = array();
$iCID = $cid1;
$iPos = $pos1;
while ($iPos > 0) {
$jPos = $iPos - 1;
$jCID = isset($cid_array[$iCID]) && array_key_exists('prev', $cid_array[$iCID]) ? $cid_array[$iCID]['prev'] : 0;
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos = $jPos, lft = 0 WHERE cid = $cid1");
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos = $iPos, lft = 0 WHERE cid = $jCID");
$iCID = $jCID;
$iPos = $jPos;
}
break;
case 'movebottom':
if (!$superCage->get->keyExists('cid1') || !$superCage->get->keyExists('pos1')) {
cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'movebottom'), __FILE__, __LINE__);
}
$cid1 = $superCage->get->getInt('cid1'); // cat to move to bottom
$pos1 = $superCage->get->getInt('pos1'); // current pos for cat
get_subcat_data(0);
$cid_array = array();
foreach ($CAT_LIST as $iCat) {
$cid_array[$iCat['cid']] = $iCat;
}
$CAT_LIST = array();
$iCID = $cid1;
$iPos = $pos1;
$cat_count = $cid_array[$cid_array[$cid1]['parent']]['cat_count'];
while ($iPos < $cat_count - 1) {
$jPos = $iPos + 1;
$jCID = isset($cid_array[$iCID]) && array_key_exists('next', $cid_array[$iCID]) ? $cid_array[$iCID]['next'] : 0;
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos = $jPos, lft = 0 WHERE cid = $cid1");
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET pos = $iPos, lft = 0 WHERE cid = $jCID");
$iCID = $jCID;
$iPos = $jPos;
}
break;
case 'setparent':
if (!$superCage->get->keyExists('cid') || !$superCage->get->keyExists('parent')) {
cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'setparent'), __FILE__, __LINE__);
}
$cid = $superCage->get->getInt('cid');
$parent = $superCage->get->getInt('parent');
$children = array();
verify_children($cid, $cid);
if (!in_array($parent, $children)) {
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent = $parent, pos = -1, lft = 0 WHERE cid = $cid");
} else {
cpg_die(ERROR, "You cannot move a category into its own child", __FILE__, __LINE__);
}
break;
case 'editcat':
if (!$superCage->get->keyExists('cid')) {
cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'editcat'), __FILE__, __LINE__);
}
$cid = $superCage->get->getInt('cid');
$result = cpg_db_query("SELECT cid, name, parent, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = $cid");
if (!$result->numRows()) {
cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__);
}
$current_category = $result->fetchAssoc(true);
break;
case 'updatecat':
if (!$superCage->post->keyExists('cid') || !$superCage->post->keyExists('parent') || !$superCage->post->keyExists('name') || !$superCage->post->keyExists('description')) {
cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'updatecat'), __FILE__, __LINE__);
}
if ($superCage->post->keyExists('name')) {
$name = $superCage->post->getEscaped('name');
$name = trim($name);
}
if (empty($name)){
$name = '<???>';
break;
}
$cid = $superCage->post->getInt('cid');
$parent = $superCage->post->getInt('parent');
$thumb = $superCage->post->getInt('thumb');
$description = $superCage->post->getEscaped('description');
$children = array();
verify_children($cid, $cid);
if (!in_array($parent, $children)) {
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent = $parent, name = '$name', description = '$description', thumb = $thumb, lft = 0 WHERE cid = $cid");
} else {
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name = '$name', description = '$description', thumb = $thumb, lft = 0 WHERE cid = $cid");
}
//insert in categorymap
//first delete all of this category in categorymap
cpg_db_query("DELETE FROM {$CONFIG['TABLE_CATMAP']} WHERE cid = $cid");
//then add the new ones
if ($superCage->post->keyExists('user_groups')) {
foreach ($superCage->post->getInt('user_groups') as $key) {
cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATMAP']} (cid, group_id) VALUES ($cid, $key)");
}
}
break;
case 'createcat':
if (!$superCage->post->keyExists('parent') || !$superCage->post->keyExists('name') || !$superCage->post->keyExists('description')) {
cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'createcat'), __FILE__, __LINE__);
}
if ($superCage->post->keyExists('name')) {
$name = $superCage->post->getEscaped('name');
$name = trim($name);
}
if (empty($name)) {
$name = '<???>';
break;
}
$parent = $superCage->post->getInt('parent');
$description = $superCage->post->getEscaped('description');
cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description) VALUES (".FIRST_USER_CAT.", $parent, '$name', '$description')");
//insert in categorymap
$cid = cpg_db_last_insert_id();
if ($superCage->post->keyExists('user_groups')) {
foreach ($superCage->post->getInt('user_groups') as $key) {
cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATMAP']} (cid, group_id) VALUES ($cid, $key)");
}
}
break;
case 'deletecat':
if (!$superCage->get->keyExists('cid')) {
cpg_die(CRITICAL_ERROR, sprintf($lang_catmgr_php['miss_param'], 'deletecat'), __FILE__, __LINE__);
}
$cid = $superCage->get->getInt('cid');
if ($cid == 1) {
cpg_die(ERROR, $lang_catmgr_php['usergal_cat_ro'], __FILE__, __LINE__);
}
$result = cpg_db_query("SELECT parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = $cid");
if (!$result->numRows()) {
cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__);
}
$del_category = $result->fetchAssoc(true);
$parent = $del_category['parent'];
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent = $parent, lft = 0 WHERE parent = $cid");
cpg_db_query("UPDATE {$CONFIG['TABLE_ALBUMS']} SET category = $parent WHERE category = $cid");
cpg_db_query("DELETE FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = $cid");
//delete from categorymap
cpg_db_query("DELETE FROM {$CONFIG['TABLE_CATMAP']} WHERE cid = $cid");
break;
}
if ($op) {
check_rebuild_tree();
}
get_subcat_data(0);
pageheader($lang_catmgr_php['manage_cat']);
starttable('100%', cpg_fetch_icon('cat_mgr', 2) . $lang_catmgr_php['category'] . ' ' . cpg_display_help('f=categories.htm&as=cat_cp&ae=cat_cp_end&top=1', '800', '600'),1);
echo <<< EOT
<tr>
<td class="tableb">
EOT;
starttable('100%');
// configure sort category alphabetically
$yes_selected = $CONFIG['categories_alpha_sort'] ? 'checked="checked"' : '';
$no_selected = !$CONFIG['categories_alpha_sort'] ? 'checked="checked"' : '';
$help = ' ' . cpg_display_help('f=configuration.htm&as=admin_album_list_alphasort_start&ae=admin_album_list_alphasort_end&top=1', '600', '250');
echo <<<EOT
<tr>
<td class="tablef" colspan="8">
<form name="catsortconfig" action="$CPG_PHP_SELF" method="post">
{$lang_catmgr_php['categories_alpha_sort']}
{$help}
<input type="radio" id="categories_alpha_sort1" name="categories_alpha_sort" value="1" onclick="checkFormSubmit()" $yes_selected />
<label for="categories_alpha_sort1" class="clickable_option">{$lang_common['yes']}</label>
<input type="radio" id="categories_alpha_sort0" name="categories_alpha_sort" value="0" onclick="checkFormSubmit()" $no_selected />
<label for="categories_alpha_sort0" class="clickable_option">{$lang_common['no']}</label>
<input type="hidden" name="update_config" value="{$lang_catmgr_php['save_cfg']}" class="button" />
<input type="hidden" name="form_token" value="{$form_token}" />
<input type="hidden" name="timestamp" value="{$timestamp}" />
</form>
</td>
</tr>
EOT;
endtable();
echo <<< EOT
</td>
</tr>
<tr>
<td class="tableb">
EOT;
starttable('100%');
$help = ' ' . cpg_display_help('f=categories.htm&as=cat_cp_page_controls_categories&ae=cat_cp_page_controls_categories_end&top=1', '800', '600');
$icon = cpg_fetch_icon('cat_mgr', 2);
echo <<<EOT
<tr>
<th class="tableh1"><span class="statlink">{$lang_catmgr_php['manage_cat']}</span>$help</th>
<th colspan="6" class="tableh1" align="center"><strong><span class="statlink">{$lang_catmgr_php['operations']}</span></strong></th>
<th class="tableh1" align="center"><strong><span class="statlink">{$lang_catmgr_php['move_into']}</span></strong></th>
</tr>
EOT;
display_cat_list();
endtable();
$op = $current_category['cid'] ? 'updatecat' : 'createcat';
echo <<< EOT
</td>
</tr>
<tr>
<td class="tableb">
<form method="post" action="catmgr.php?op=$op">
EOT;
$help_update_create = ' ' . cpg_display_help('f=categories.htm&as=cat_cp_page_controls_create&ae=cat_cp_page_controls_create_end&top=1', '800', '600');
starttable('100%', $lang_catmgr_php['update_create'] . $help_update_create, 2);
$lb = cat_list_box($current_category['cid'], $current_category['parent'], false);
$ug_lb = usergroup_list_box($current_category['cid']);
$description_help = ' ' . cpg_display_help('f=categories.htm&as=cat_album_create&ae=cat_album_create_end&top=1', '600', '250');
$albumCreateHelp = ' ' . cpg_display_help('f=categories.htm&as=cat_album_create&ae=cat_album_create_end&top=1', '600', '250');
echo <<<EOT
<tr>
<td width="40%" class="tableb">
{$lang_catmgr_php['parent_cat']}
</td>
<td width="60%" class="tableb" valign="top">
$lb
</td>
</tr>
<tr>
<td width="40%" class="tableb">
{$lang_catmgr_php['group_create_alb']}{$albumCreateHelp}
</td>
<td width="60%" class="tableb" valign="top">
$ug_lb
</td>
</tr>
<tr>
<td width="40%" class="tableb">
{$lang_catmgr_php['cat_title']}
</td>
<td width="60%" class="tableb" valign="top">
<input type="text" style="width: 100%" name="name" value="{$current_category['name']}" class="textinput" />
</td>
</tr>
<tr>
<td class="tableb" valign="top">
{$lang_catmgr_php['cat_desc']}$description_help
</td>
<td class="tableb" valign="top">
<textarea name="description" rows="5" cols="40" style="width: 100%;" class="textinput">{$current_category['description']}</textarea>
</td>
</tr>
EOT;
$op = $superCage->get->getAlpha('op');
if ($op == 'editcat') {
form_alb_thumb();
}
echo <<<EOT
<tr>
<td colspan="2" align="center" class="tablef">
<button type="submit" class="button" name="cat_submit" value="{$lang_catmgr_php['update_create']}">{$icon_array['submit']}{$lang_catmgr_php['update_create']}</button>
<input type="hidden" name="form_token" value="{$form_token}" />
<input type="hidden" name="timestamp" value="{$timestamp}" />
<input type="hidden" name="cid" value ="{$current_category['cid']}" />
</td>
</tr>
EOT;
endtable();
echo <<< EOT
</form>
</td>
</tr>
EOT;
endtable();
pagefooter();
//EOF