-
Notifications
You must be signed in to change notification settings - Fork 19
/
lib-admin.php
1770 lines (1561 loc) · 65.8 KB
/
lib-admin.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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 2.1 |
// +---------------------------------------------------------------------------+
// | lib-admin.php |
// | |
// | Admin-related functions needed in more than one place. |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2011 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
// | Mark Limburg - mlimburg AT users DOT sourceforge DOT net |
// | Jason Whittenburg - jwhitten AT securitygeeks DOT com |
// | Dirk Haun - dirk AT haun-online DOT de |
// | Oliver Spiesshofer - oliver AT spiesshofer DOT com |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
/**
* This file contains functions used in the admin panels (mostly for the
* various lists of stories, users, etc.).
*/
if (stripos($_SERVER['PHP_SELF'], basename(__FILE__)) !== false) {
die('This file can not be used on its own!');
}
/**
* Default number of list entries per page
*/
if (!defined('DEFAULT_ENTRIES_PER_PAGE')) {
define('DEFAULT_ENTRIES_PER_PAGE', 50);
}
/**
* Common function used in Admin scripts to display a list of items
*
* @param string $fieldFunction Name of a function used to display the list item row details
* @param array $header_arr array of header fields with sortables and table fields
* @param array $text_arr array with different text strings
* @param array $data_arr array with sql query data - array of list records
* @param array $options array of options - intially just used for the Check-All feature
* @param array $form_arr optional extra forms at top or bottom
* @return string HTML output of function
*/
function ADMIN_simpleList($fieldFunction, $header_arr, $text_arr,
$data_arr, $options = array(), $form_arr = array())
{
global $_CONF, $LANG01, $LANG_ADMIN, $_IMAGE_TYPE;
$retval = '';
$help_url = '';
if (!empty($text_arr['help_url'])) {
$help_url = $text_arr['help_url'];
}
$title = '';
if (!empty($text_arr['title'])) {
$title = $text_arr['title'];
}
$form_url = '';
if (!empty($text_arr['form_url'])) {
$form_url = $text_arr['form_url'];
}
$admin_templates = COM_newTemplate($_CONF['path_layout'] . 'admin/lists');
$admin_templates->set_file(
array(
'list' => 'list.thtml',
'header' => 'header.thtml',
'row' => 'listitem.thtml',
'field' => 'field.thtml',
)
);
$admin_templates->set_var('form_url', $form_url);
$admin_templates->set_var('lang_edit', $LANG_ADMIN['edit']);
$admin_templates->set_var('lang_deleteall', $LANG01[124]);
$admin_templates->set_var('lang_delconfirm', $LANG01[125]);
if (isset($form_arr['top'])) {
$admin_templates->set_var('formfields_top', $form_arr['top']);
}
if (isset($form_arr['bottom'])) {
$admin_templates->set_var('formfields_bottom', $form_arr['bottom']);
}
# define icon paths. Those will be transmitted to $fieldfunction.
$icons_type_arr = array('edit', 'copy', 'list', 'addchild', 'install', 'unavailable', 'info');
$icon_arr = array();
foreach ($icons_type_arr as $icon_type) {
$icon_url = "{$_CONF['layout_url']}/images/$icon_type.$_IMAGE_TYPE";
$icon_arr[$icon_type] = COM_createImage($icon_url, $LANG_ADMIN[$icon_type]);
}
// Check if the delete checkbox and support for the delete all feature should be displayed
$min_data = 1;
if (is_array($options) && isset($options['chkminimum'])) {
$min_data = $options['chkminimum'];
}
if (count($data_arr) > $min_data && is_array($options) && isset($options['chkdelete']) && $options['chkdelete']) {
$admin_templates->set_var('header_text', '<input type="checkbox" name="chk_selectall" title="' . $LANG01[126] . '" onclick="caItems(this.form);"' . XHTML . '>');
$admin_templates->set_var('class', "admin-list-field");
$admin_templates->set_var('show_deleteimage', '');
$admin_templates->parse('header_row', 'header', true);
$admin_templates->clear_var('on_click');
} else {
$admin_templates->set_var('show_deleteimage', 'display:none;');
}
# HEADER FIELDS array(text, field, sort)
for ($i = 0; $i < count($header_arr); $i++) {
$admin_templates->set_var('header_text', $header_arr[$i]['text']);
if (!empty($header_arr[$i]['header_class'])) {
$admin_templates->set_var('class', $header_arr[$i]['header_class']);
} else {
$admin_templates->set_var('class', "admin-list-headerfield");
}
$admin_templates->parse('header_row', 'header', true);
}
if (count($data_arr) == 0) {
if (isset($text_arr['no_data'])) {
$message = $text_arr['no_data'];
} else {
$message = $LANG_ADMIN['no_results'];
}
$admin_templates->set_var('message', $message);
} elseif ($data_arr === false) {
$admin_templates->set_var('message', $LANG_ADMIN['data_error']);
} else {
$admin_templates->set_var('show_message', 'display:none;');
$useFieldFunction = is_callable($fieldFunction);
for ($i = 0; $i < count($data_arr); $i++) {
if (count($data_arr) > $min_data && is_array($options) && isset($options['chkdelete']) && $options['chkdelete']) {
$admin_templates->set_var('itemtext', '<input type="checkbox" name="delitem[]" value="' . $data_arr[$i][$options['chkfield']] . '"' . XHTML . '>');
$admin_templates->set_var('class', "admin-list-field");
$admin_templates->parse('item_field', 'field', true);
}
for ($j = 0; $j < count($header_arr); $j++) {
$fieldName = $header_arr[$j]['field'];
if (isset($data_arr[$i][$fieldName]) &&
!empty($data_arr[$i][$fieldName])
) {
$fieldValue = strval($data_arr[$i][$fieldName]);
} else {
$fieldValue = '';
}
if ($useFieldFunction) {
$fieldValue = call_user_func($fieldFunction, $fieldName, $fieldValue, $data_arr[$i], $icon_arr);
}
if (!empty($header_arr[$j]['field_class'])) {
$admin_templates->set_var('class', $header_arr[$j]['field_class']);
} else {
$admin_templates->set_var('class', "admin-list-field");
}
if ($fieldValue !== false) {
$admin_templates->set_var('itemtext', $fieldValue);
$admin_templates->parse('item_field', 'field', true);
}
}
$admin_templates->set_var('cssid', ($i % 2) + 1);
$admin_templates->parse('item_row', 'row', true);
$admin_templates->clear_var('item_field');
}
}
$admin_templates->parse('output', 'list');
if (!empty($title)) {
$retval .= COM_startBlock($title, $help_url,
COM_getBlockTemplate('_admin_block', 'header'));
}
$retval .= $admin_templates->finish($admin_templates->get_var('output'));
if (!empty($title)) {
$retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
}
return $retval;
}
/**
* Creates a list of data with a search, filter, clickable headers etc.
*
* @param string $component name of the list
* @param string $fieldFunction name of the function that handles special entries
* @param array $header_arr array of header fields with sortables and table fields
* @param array $text_arr array with different text strings
* @param array $query_arr array with sql-options
* @param array $defSort_arr default sorting values
* @param string $filter additional drop-down filters
* @param string $extra additional values passed to fieldfunction
* @param array $options array of options - intially just used for the Check-All feature
* @param array $form_arr optional extra forms at top or bottom
* @param bool $showSearch whether to show the search functionality
* @param string $pageNavUrl additional url values that page navigation and sorting by columns may need for any
* additional filters
* @return string HTML output of function
*/
function ADMIN_list($component, $fieldFunction, $header_arr, $text_arr,
$query_arr, $defSort_arr, $filter = '', $extra = '',
$options = array(), $form_arr = array(), $showSearch = true, $pageNavUrl = '')
{
global $_CONF, $LANG_ADMIN, $LANG01, $_IMAGE_TYPE;
// set all variables to avoid warnings
$retval = '';
$filter_str = '';
$order_sql = '';
$group_by_sql = '';
$limit = '';
$prevOrder = '';
if (isset ($_GET['prevorder'])) { # what was the last sorting?
$prevOrder = COM_applyFilter($_GET['prevorder']);
}
$query = '';
if (isset ($_REQUEST['q'])) { // get query (text-search)
$query = strip_tags(COM_stripslashes($_REQUEST['q']));
}
$query_limit = '';
if (isset($_REQUEST['query_limit'])) { // get query-limit (list-length)
$query_limit = COM_applyFilter($_REQUEST['query_limit'], true);
if ($query_limit == 0) {
$query_limit = DEFAULT_ENTRIES_PER_PAGE;
}
}
// we assume that the current page is 1 to set it.
$currentPage = 1;
$page = '';
// get the current page from the interface. The variable is linked to the
// component, i.e. the plugin/function calling this here to avoid overlap
if (isset ($_REQUEST[$component . 'listpage'])) {
$page = COM_applyFilter($_REQUEST[$component . 'listpage'], true);
$currentPage = $page;
}
if ($currentPage <= 0) {
$currentPage = 1; #current page has to be larger 0
}
$help_url = ''; # do we have a help url for the block-header?
if (!empty($text_arr['help_url'])) {
$help_url = $text_arr['help_url'];
}
$form_url = ''; # what is the form-url for the search button and list sorters?
if (!empty($text_arr['form_url'])) {
$form_url = $text_arr['form_url'];
}
$title = ''; # what is the title of the page?
if (!empty($text_arr['title'])) {
$title = $text_arr['title'];
}
$inline_form = false;
if (isset($text_arr['inline'])) {
$inline_form = $text_arr['inline'];
}
# get all template fields.
$admin_templates = COM_newTemplate($_CONF['path_layout'] . 'admin/lists');
$template_files = array(
'list' => ($inline_form ? 'inline.thtml' : 'list.thtml'),
'header' => 'header.thtml',
'row' => 'listitem.thtml',
'field' => 'field.thtml',
);
if ($showSearch) {
$template_files['search'] = 'searchmenu.thtml';
}
$admin_templates->set_file($template_files);
$admin_templates->set_var('form_url', $form_url);
$admin_templates->set_var('lang_edit', $LANG_ADMIN['edit']);
$admin_templates->set_var('lang_deleteall', $LANG01[124]);
$admin_templates->set_var('lang_delconfirm', $LANG01[125]);
if (isset($form_arr['top'])) {
$admin_templates->set_var('formfields_top', $form_arr['top']);
}
if (isset($form_arr['bottom'])) {
$admin_templates->set_var('formfields_bottom', $form_arr['bottom']);
}
// Check if the delete checkbox and support for the delete all feature should be displayed
if (is_array($options) && isset($options['chkdelete']) && $options['chkdelete']) {
$admin_templates->set_var('header_text', '<input type="checkbox" name="chk_selectall" title="' . $LANG01[126] . '" onclick="caItems(this.form);"' . XHTML . '>');
$admin_templates->set_var('class', "admin-list-field");
$admin_templates->set_var('show_deleteimage', '');
$admin_templates->parse('header_row', 'header', true);
$admin_templates->clear_var('on_click');
} else {
$admin_templates->set_var('show_deleteimage', 'display:none;');
}
// define icon paths. Those will be transmitted to $fieldFunction.
$icons_type_arr = array('edit', 'copy', 'list', 'addchild', 'deleteitem', 'enabled', 'disabled', 'unavailable', 'warning', 'info');
$icon_arr = array();
foreach ($icons_type_arr as $icon_type) {
$icon_url = "{$_CONF['layout_url']}/images/$icon_type.$_IMAGE_TYPE";
$icon_arr[$icon_type] = COM_createImage($icon_url, $LANG_ADMIN[$icon_type], array('style' => 'vertical-align: middle;'));
}
$has_extras = '';
if (isset($text_arr['has_extras'])) { # does this one use extras? (search, google paging)
$has_extras = $text_arr['has_extras'];
}
if ($has_extras) { // show search
$admin_templates->set_var('lang_search', $LANG_ADMIN['search']);
$admin_templates->set_var('lang_submit', $LANG_ADMIN['submit']);
$admin_templates->set_var('lang_limit_results',
$LANG_ADMIN['limit_results']);
$admin_templates->set_var('last_query', htmlspecialchars($query));
$admin_templates->set_var('filter', $filter);
}
$sql_query = DB_escapeString($query); // replace quotes etc for security
$sql = $query_arr['sql']; // get sql from array that builds data
$order_var = ''; # number that is displayed in URL
$order_var_link = ''; # Variable for google paging.
// is the order set in the link (when sorting the list)
if (!isset ($_GET['order'])) {
$order = $defSort_arr['field']; // no, get the default
} else {
$order_var = COM_applyFilter($_GET['order'], true);
$order_var_link = "&order=$order_var"; # keep the variable for the google paging
$order = $header_arr[$order_var]['field']; # current order field name
}
if (isset($header_arr[$order_var]['sort_field'])) {
// See if specific sort fields are set for the current field
$order_for_query = $header_arr[$order_var]['sort_field'];
} else {
$order_for_query = $order;
}
// this code sorts only by the field if its in table.field style.
// removing this however makes match for arrow-display impossible, so removed it.
// maybe now for more fields the table has to be added to the sortfield?
//$order = explode ('.', $order);
//if (count ($order) > 1) {
// $order = $order[1];
//} else {
// $order = $order[0];
//}
if (!isset ($_GET['direction'])) { # get direction to sort after
$direction = $defSort_arr['direction'];
} else {
$direction = COM_applyFilter($_GET['direction']);
}
$direction = strtoupper($direction);
if ($order == $prevOrder) { #reverse direction if prev. order was the same
$direction = ($direction === 'DESC') ? 'ASC' : 'DESC';
} else {
$direction = ($direction === 'DESC') ? 'DESC' : 'ASC';
}
if ($direction == 'ASC') { # assign proper arrow img name dep. on sort order
$arrow = 'bararrowdown';
} else {
$arrow = 'bararrowup';
}
# make actual order arrow image
$img_arrow_url = "{$_CONF['layout_url']}/images/$arrow.$_IMAGE_TYPE";
$img_arrow = ' ' . COM_createImage($img_arrow_url, $arrow);
if (!empty($order_for_query)) { # concat order string
$order_sql = "ORDER BY $order_for_query $direction";
}
$th_subtags = ''; // other tags in the th, such as onclick and mouseover
$header_text = ''; // title as displayed to the user
// HEADER FIELDS array(text, field, sort, class)
// this part defines the contents & format of the header fields
for ($i = 0; $i < count($header_arr); $i++) { #iterate through all headers
$header_text = $header_arr[$i]['text'];
$th_subtags = '';
if ($header_arr[$i]['sort'] != false) { # is this sortable?
if ($order == $header_arr[$i]['field']) { # is this currently sorted?
$header_text .= $img_arrow;
}
# make the mouseover effect is sortable
$th_subtags = " onmouseover=\"this.style.cursor='pointer';\"";
$order_var = $i; # assign number to field so we know what to sort
if (strpos($form_url, '?') > 0) {
$separator = '&';
} else {
$separator = '?';
}
$th_subtags .= " onclick=\"window.location.href='$form_url$separator" // onclick action
. "order=$order_var&prevorder=$order&direction=$direction";
if (!empty($page)) {
$th_subtags .= '&' . $component . 'listpage=' . $page;
}
if (!empty($query)) {
$th_subtags .= '&q=' . urlencode($query);
}
if (!empty($query_limit)) {
$th_subtags .= '&query_limit=' . $query_limit;
}
if (!empty($pageNavUrl)) { // used for any additional filters
$th_subtags .= $pageNavUrl;
}
$th_subtags .= "';\"";
}
if (!empty($header_arr[$i]['header_class'])) {
$admin_templates->set_var('class', $header_arr[$i]['header_class']);
} else {
$admin_templates->set_var('class', "admin-list-headerfield");
}
$admin_templates->set_var('header_text', $header_text);
$admin_templates->set_var('th_subtags', $th_subtags);
$admin_templates->parse('header_row', 'header', true);
$admin_templates->clear_var('th_subtags'); // clear all for next header
$admin_templates->clear_var('class');
$admin_templates->clear_var('header_text');
}
if (!empty($query_arr['query_group'])) { # add group by to sql
$group_by_sql = " GROUP BY {$query_arr['query_group']}";
}
if ($has_extras && $showSearch) {
/**
* default query limit if no other ch osen.
*
* @todo maybe this could be a setting from the list?
*/
$limit = DEFAULT_ENTRIES_PER_PAGE;
if (!empty($query_limit)) {
$limit = $query_limit;
}
if ($query != '') { # set query into form after search
$admin_templates->set_var('query', urlencode($query));
} else {
$admin_templates->set_var('query', '');
}
$admin_templates->set_var('query_limit', $query_limit);
// choose proper dropdown field for query limit
$admin_templates->set_var($limit . '_selected', 'selected="selected"');
if (!empty($query_arr['default_filter'])) { # add default filter to sql
$filter_str = " {$query_arr['default_filter']}";
}
if (!empty($query)) { # add query fields with search term
$filter_str .= " AND (";
for ($f = 0; $f < count($query_arr['query_fields']); $f++) {
$filter_str .= $query_arr['query_fields'][$f]
. " LIKE '%$sql_query%'";
if ($f < (count($query_arr['query_fields']) - 1)) {
$filter_str .= " OR ";
}
}
$filter_str .= ")";
}
$num_pages_sql = $sql . $filter_str . $group_by_sql;
$num_pages_result = DB_query($num_pages_sql);
$num_rows = DB_numRows($num_pages_result);
$num_pages = ceil($num_rows / $limit);
if ($num_pages < $currentPage) { # make sure we dont go beyond possible results
$currentPage = 1;
}
$offset = (($currentPage - 1) * $limit);
$limit = "LIMIT $offset,$limit"; # get only current page data
$admin_templates->set_var('lang_records_found',
$LANG_ADMIN['records_found']);
$admin_templates->set_var('records_found',
COM_numberFormat($num_rows));
$admin_templates->parse('search_menu', 'search', true);
}
if (is_callable($fieldFunction)) {
if (!empty($extra)) {
$useFieldFunction = 2;
} else {
$useFieldFunction = 1;
}
} else {
$useFieldFunction = 0;
}
// SQL
$sql .= "$filter_str $group_by_sql $order_sql $limit;";
$result = DB_query($sql);
$numRows = DB_numRows($result);
$r = 1; // r is the counter for the actual displayed rows for correct coloring
for ($i = 0; $i < $numRows; $i++) { # now go through actual data
$A = DB_fetchArray($result);
$this_row = false; # as long as no fields are returned, dont print row
if (is_array($options) && isset($options['chkdelete']) && $options['chkdelete']) {
$admin_templates->set_var('class', "admin-list-field");
$admin_templates->set_var('itemtext', '<input type="checkbox" name="delitem[]" value="' . $A[$options['chkfield']] . '"' . XHTML . '>');
$admin_templates->parse('item_field', 'field', true);
}
for ($j = 0; $j < count($header_arr); $j++) {
$fieldName = $header_arr[$j]['field']; # get field name from headers
if (isset($A[$fieldName])) {
$fieldValue = strval($A[$fieldName]); # yes, get its data
} else {
$fieldValue = '';
}
switch ($useFieldFunction) {
case 2:
$fieldValue = call_user_func($fieldFunction, $fieldName, $fieldValue, $A, $icon_arr, $extra);
break;
case 1:
$fieldValue = call_user_func($fieldFunction, $fieldName, $fieldValue, $A, $icon_arr);
break;
default:
break;
}
if ($fieldValue !== false) { # return was there, so write line
$this_row = true;
} else {
$fieldValue = ''; // dont give emtpy fields
}
if (!empty($header_arr[$j]['field_class'])) {
$admin_templates->set_var('class', $header_arr[$j]['field_class']);
} else {
$admin_templates->set_var('class', "admin-list-field");
}
$admin_templates->set_var('itemtext', $fieldValue); # write field
$admin_templates->parse('item_field', 'field', true);
}
if ($this_row) { # there was data in at least one field, so print line
$r++; # switch to next color
$admin_templates->set_var('cssid', ($r % 2) + 1); # make alternating table color
$admin_templates->parse('item_row', 'row', true); # process the complete row
}
$admin_templates->clear_var('item_field'); # clear field
}
if ($numRows == 0) { # there is no data. return notification message.
if (isset($text_arr['no_data'])) {
$message = $text_arr['no_data']; # there is a user-message
} else {
$message = $LANG_ADMIN['no_results']; # take std.
}
$admin_templates->set_var('message', $message);
}
if ($has_extras && $showSearch) {
$hasArgs = strstr($form_url, '?');
if ($hasArgs) {
$sep = '&';
} else {
$sep = '?';
}
if (!empty($query)) { # port query to next page
$base_url = $form_url . $sep . 'q=' . urlencode($query)
. "&query_limit=$query_limit$order_var_link&direction=$direction$pageNavUrl";
} else {
$base_url = $form_url . $sep . "query_limit=$query_limit$order_var_link&direction=$direction$pageNavUrl";
}
if ($num_pages > 1) { # print actual google-paging
$admin_templates->set_var('google_paging', COM_printPageNavigation($base_url, $currentPage, $num_pages, $component . 'listpage='));
} else {
$admin_templates->set_var('google_paging', '');
}
}
$admin_templates->parse('output', 'list');
// Do the actual output
if (!empty($title)) {
$retval .= COM_startBlock($title, $help_url,
COM_getBlockTemplate('_admin_block', 'header'));
}
$retval .= $admin_templates->finish($admin_templates->get_var('output'));
if (!empty($title)) {
$retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
}
return $retval;
}
/**
* Creates a menu with an optional icon and optional text below
* this is used in the admin screens but may be used elsewhere also.
*
* @param array $menu_arr array of text & URL of the menu entries
* @param string $text instructions to be displayed
* @param string $icon url of an icon that will be displayed
* @return string HTML output of function
*/
function ADMIN_createMenu($menu_arr, $text, $icon = '')
{
global $_CONF;
$admin_templates = COM_newTemplate($_CONF['path_layout'] . 'admin/lists');
$admin_templates->set_file(
array('top_menu' => 'topmenu.thtml')
);
$menu_fields = '';
$attr = array('class' => 'admin-menu-item');
for ($i = 0; $i < count($menu_arr); $i++) { # iterate through menu
$menu_fields .= COM_createLink($menu_arr[$i]['text'], $menu_arr[$i]['url'], $attr);
if ($i < (count($menu_arr) - 1)) {
$menu_fields .= ' | '; # add separator
}
}
if (!empty($icon)) {
$attr = array('class' => 'admin-menu-icon');
$icon = COM_createImage($icon, '', $attr);
$admin_templates->set_var('icon', $icon);
}
$admin_templates->set_var('menu_fields', $menu_fields);
$admin_templates->set_var('lang_instructions', $text);
$admin_templates->parse('top_menu', 'top_menu');
$retval = $admin_templates->finish($admin_templates->get_var('top_menu'));
return $retval;
}
/**
* The following functions are helper functions used as $fieldfunction with
* ADMIN_list and ADMIN_simpleList (see above)
*/
/**
* used for the list of blocks in admin/block.php
*
* @param string $fieldName
* @param string $fieldValue
* @param array $A
* @param array $icon_arr
* @param string $token
* @return string
*/
function ADMIN_getListField_blocks($fieldName, $fieldValue, $A, $icon_arr, $token)
{
global $_CONF, $LANG_ADMIN, $LANG21, $_IMAGE_TYPE;
$retval = false;
$access = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'],
$A['perm_group'], $A['perm_members'], $A['perm_anon']
);
if (($access > 0) && (TOPIC_hasMultiTopicAccess('block', $A['bid']) > 0)) {
switch ($fieldName) {
case 'edit':
if ($access == 3) {
$retval = COM_createLink($icon_arr['edit'],
"{$_CONF['site_admin_url']}/block.php?mode=edit&bid={$A['bid']}");
}
break;
case 'title':
$retval = stripslashes($A['title']);
if (empty($retval)) {
$retval = '(' . $A['name'] . ')';
}
break;
case 'device':
switch ($A['device']) {
case Device::ALL:
$retval = $LANG_ADMIN['all'];
break;
case Device::MOBILE:
$retval = $LANG_ADMIN['mobile'];
break;
case Device::COMPUTER:
$retval = $LANG_ADMIN['computer'];
break;
default:
$retval = '';
break;
}
break;
case 'onleft':
switch ($A['onleft']) {
case BLOCK_NONE_POSITION:
$retval = $LANG21[47];
break;
case BLOCK_LEFT_POSITION:
$retval = $LANG21[40];
break;
case BLOCK_RIGHT_POSITION:
$retval = $LANG21[41];
break;
default:
$retval = '';
break;
}
break;
case 'blockorder':
if ($A['onleft'] == BLOCK_NONE_POSITION) {
$retval .= '';
} else {
$retval .= $A['blockorder'];
}
break;
case 'is_enabled':
if ($access == 3) {
if ($A['is_enabled'] == 1) {
$switch = ' checked="checked"';
} else {
$switch = '';
}
$retval = '<input type="checkbox" name="enabledblocks[]" '
. 'onclick="submit()" value="' . $A['bid'] . '"'
. $switch . XHTML . '>'
. '<input type="hidden" name="visibleblocks[]" value="'
. $A['bid'] . '"' . XHTML . '>';
}
break;
case 'move':
if ($access == 3) {
if ($A['onleft'] != BLOCK_NONE_POSITION) {
if ($A['onleft'] == 1) {
$side = $LANG21[40];
$blockControlImage = 'block-right.' . $_IMAGE_TYPE;
$moveTitleMsg = $LANG21[59];
$switchSide = '1';
} else {
$blockControlImage = 'block-left.' . $_IMAGE_TYPE;
$moveTitleMsg = $LANG21[60];
$switchSide = '0';
}
$csrfToken = '&' . CSRF_TOKEN . '=' . $token;
$retval .= "<img src=\"{$_CONF['layout_url']}/images/admin/$blockControlImage\" width=\"45\" height=\"20\" usemap=\"#arrow{$A['bid']}\" alt=\"\"" . XHTML . ">"
. "<map id=\"arrow{$A['bid']}\" name=\"arrow{$A['bid']}\">"
. "<area coords=\"0,0,12,20\" title=\"{$LANG21[58]}\" href=\"{$_CONF['site_admin_url']}/block.php?mode=move&bid={$A['bid']}&where=up{$csrfToken}\" alt=\"{$LANG21[58]}\"" . XHTML . ">"
. "<area coords=\"13,0,29,20\" title=\"$moveTitleMsg\" href=\"{$_CONF['site_admin_url']}/block.php?mode=move&bid={$A['bid']}&where=$switchSide{$csrfToken}\" alt=\"$moveTitleMsg\"" . XHTML . ">"
. "<area coords=\"30,0,43,20\" title=\"{$LANG21[57]}\" href=\"{$_CONF['site_admin_url']}/block.php?mode=move&bid={$A['bid']}&where=dn${csrfToken}\" alt=\"{$LANG21[57]}\"" . XHTML . ">"
. "</map>";
}
}
break;
case 'topic':
$retval = TOPIC_getTopicAdminColumn('block', $A['bid']);
break;
default:
$retval = $fieldValue;
break;
}
}
return $retval;
}
/**
* used for the list of blocks in admin/block.php
*
* @param string $fieldName
* @param string $fieldValue
* @param array $A
* @param array $icon_arr
* @return string
*/
function ADMIN_getListField_dynamicblocks($fieldName, $fieldValue, $A, $icon_arr)
{
global $LANG21, $_TABLES;
switch ($fieldName) {
case 'onleft':
switch ($A['onleft']) {
case BLOCK_NONE_POSITION:
$retval = $LANG21[47];
break;
case BLOCK_LEFT_POSITION:
$retval = $LANG21[40];
break;
case BLOCK_RIGHT_POSITION:
$retval = $LANG21[41];
break;
default:
$retval = '';
break;
}
break;
case 'title':
$retval = stripslashes($A['title']);
if (empty($retval)) {
$retval = '(' . $A['name'] . ')';
}
break;
case 'is_enabled':
if ($A['enable'] == 1) {
$retval = $LANG21[5]; // Yes
} else {
$retval = $LANG21[6]; // No
}
break;
case 'topic':
if ($A['topic_option'] == TOPIC_ALL_OPTION) {
$retval = $LANG21[7];
} elseif ($A['topic_option'] == TOPIC_HOMEONLY_OPTION) {
$retval = $LANG21[43];
} else {
$element_num = count($A['topic']);
if ($element_num == 0) {
$retval = $LANG21[47]; // None
} elseif ($element_num > 1) {
$retval = $LANG21[44]; // Multiple
} else {
$retval = DB_getItem($_TABLES['topics'], 'topic', "tid = '{$A['topic'][0]}'");
}
}
break;
default:
$retval = $fieldValue;
break;
}
return $retval;
}
/**
* used for the list of groups and in the group editor in admin/group.php
*
* @param string $fieldName
* @param string $fieldValue
* @param array $A
* @param array $icon_arr
* @param string $selected
* @return string
*/
function ADMIN_getListField_groups($fieldName, $fieldValue, $A, $icon_arr, $selected = '')
{
global $_CONF, $LANG_ACCESS, $thisUsersGroups;
$retval = false;
if (!is_array($thisUsersGroups)) {
$thisUsersGroups = SEC_getUserGroups();
}
$show_all_groups = false;
if (isset($_REQUEST['chk_showall']) && ($_REQUEST['chk_showall'] == 1)) {
$show_all_groups = true;
}
if (in_array($A['grp_id'], $thisUsersGroups) ||
SEC_groupIsRemoteUserAndHaveAccess($A['grp_id'], $thisUsersGroups)
) {
switch ($fieldName) {
case 'edit':
$url = $_CONF['site_admin_url'] . '/group.php?mode=edit&grp_id='
. $A['grp_id'];
if ($show_all_groups) {
$url .= '&chk_showall=1';
}
$retval = COM_createLink($icon_arr['edit'], $url);
break;
case 'grp_gl_core':
if ($A['grp_gl_core'] == 1) {
$retval = $LANG_ACCESS['yes'];
} else {
$retval = $LANG_ACCESS['no'];
}
break;
case 'grp_default':
if ($A['grp_default'] != 0) {
$retval = $LANG_ACCESS['yes'];
} else {
$retval = $LANG_ACCESS['no'];
}
break;
case 'list':
$url = $_CONF['site_admin_url'] . '/group.php?mode=';
if ($show_all_groups) {
$param = '&grp_id=' . $A['grp_id'] . '&chk_showall=1';
} else {
$param = '&grp_id=' . $A['grp_id'];
}
$retval = COM_createLink($icon_arr['list'],
$url . 'listusers' . $param);
if (($A['grp_name'] != 'All Users') &&
($A['grp_name'] != 'Logged-in Users')
) {
$retval .= ' ' . COM_createLink($icon_arr['edit'],
$url . 'editusers' . $param);
}
break;
case 'checkbox':
$retval = '<input type="checkbox" name="groups[]" value="'
. $A['grp_id'] . '"';
if (is_array($selected) && in_array($A['grp_id'], $selected)) {
$retval .= ' checked="checked"';
}
$retval .= XHTML . '>';
break;
case 'disabled-checkbox':
$retval = '<input type="checkbox" checked="checked" '
. 'disabled="disabled"' . XHTML . '>'
. '<input type="hidden" name="groups[]" value="'
. $A['grp_id'] . '"' . XHTML . '>';
break;
case 'grp_name':
$retval = ucwords($fieldValue);
break;
default:
$retval = $fieldValue;
break;
}
}
return $retval;
}
/**
* used for the list of users in admin/user.php
*
* @param string $fieldName
* @param string $fieldValue
* @param array $A
* @param array $icon_arr
* @return string
*/
function ADMIN_getListField_users($fieldName, $fieldValue, $A, $icon_arr)
{
global $_CONF, $_TABLES, $LANG_ADMIN, $LANG28, $_IMAGE_TYPE;
switch ($fieldName) {
case 'delete':
$retval = '<input type="checkbox" name="delitem[]" checked="checked"' . XHTML . '>';
break;
case 'edit':
$retval = COM_createLink($icon_arr['edit'],
"{$_CONF['site_admin_url']}/user.php?mode=edit&uid={$A['uid']}");
break;
case 'username':
if (!empty($A['photo'])) {
$photoIcon = " <img src=\"{$_CONF['layout_url']}/images/smallcamera."
. $_IMAGE_TYPE . '" alt="{$LANG04[77]}"' . XHTML . '>';
} else {
$photoIcon = '';
}
$retval = COM_createLink($fieldValue, $_CONF['site_url']
. '/users.php?mode=profile&uid=' . $A['uid']) . $photoIcon;
break;
case 'lastlogin':
if ($fieldValue < 1) {