system/lib-admin.php
author Dirk Haun <dirk@haun-online.de>
Mon, 28 Sep 2009 22:20:30 +0200
branchHEAD
changeset 7394 fdb273c78589
parent 7341 db4c6eb6e843
child 7395 bb675c876cb9
permissions -rw-r--r--
Added an icon to make the plugin update option somewhat more obvious
     1 <?php
     2 
     3 /* Reminder: always indent with 4 spaces (no tabs). */
     4 // +---------------------------------------------------------------------------+
     5 // | Geeklog 1.6                                                               |
     6 // +---------------------------------------------------------------------------+
     7 // | lib-admin.php                                                             |
     8 // |                                                                           |
     9 // | Admin-related functions needed in more than one place.                    |
    10 // +---------------------------------------------------------------------------+
    11 // | Copyright (C) 2000-2009 by the following authors:                         |
    12 // |                                                                           |
    13 // | Authors: Tony Bibbs         - tony AT tonybibbs DOT com                   |
    14 // |          Mark Limburg       - mlimburg AT users DOT sourceforge DOT net   |
    15 // |          Jason Whittenburg  - jwhitten AT securitygeeks DOT com           |
    16 // |          Dirk Haun          - dirk AT haun-online DOT de                  |
    17 // |          Oliver Spiesshofer - oliver AT spiesshofer DOT com               |
    18 // +---------------------------------------------------------------------------+
    19 // |                                                                           |
    20 // | This program is free software; you can redistribute it and/or             |
    21 // | modify it under the terms of the GNU General Public License               |
    22 // | as published by the Free Software Foundation; either version 2            |
    23 // | of the License, or (at your option) any later version.                    |
    24 // |                                                                           |
    25 // | This program is distributed in the hope that it will be useful,           |
    26 // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
    27 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
    28 // | GNU General Public License for more details.                              |
    29 // |                                                                           |
    30 // | You should have received a copy of the GNU General Public License         |
    31 // | along with this program; if not, write to the Free Software Foundation,   |
    32 // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
    33 // |                                                                           |
    34 // +---------------------------------------------------------------------------+
    35 
    36 /**
    37 * This file contains functions used in the admin panels (mostly for the
    38 * various lists of stories, users, etc.).
    39 *
    40 */
    41 
    42 if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-admin.php') !== false) {
    43     die('This file can not be used on its own!');
    44 }
    45 
    46 /**
    47 * Common function used in Admin scripts to display a list of items
    48 *
    49 * @param    string  $fieldfunction  Name of a function used to display the list item row details
    50 * @param    array   $header_arr     array of header fields with sortables and table fields
    51 * @param    array   $text_arr       array with different text strings
    52 * @param    array   $data_arr       array with sql query data - array of list records
    53 * @param    array   $options        array of options - intially just used for the Check-All feature
    54 * @param    array   $form_arr       optional extra forms at top or bottom
    55 * @return   string                  HTML output of function
    56 *
    57 */
    58 function ADMIN_simpleList($fieldfunction, $header_arr, $text_arr,
    59                            $data_arr, $options = '', $form_arr='')
    60 {
    61     global $_CONF, $_TABLES, $LANG01, $LANG_ADMIN, $LANG_ACCESS, $MESSAGE,
    62            $_IMAGE_TYPE;
    63 
    64     $retval = '';
    65 
    66     $help_url = '';
    67     if (!empty($text_arr['help_url'])) {
    68         $help_url = $text_arr['help_url'];
    69     }
    70 
    71     $title = '';
    72     if (!empty($text_arr['title'])) {
    73         $title = $text_arr['title'];
    74     }
    75 
    76     $form_url = '';
    77     if (!empty($text_arr['form_url'])) {
    78         $form_url = $text_arr['form_url'];
    79     }
    80 
    81     $admin_templates = new Template($_CONF['path_layout'] . 'admin/lists');
    82     $admin_templates->set_file (
    83         array (
    84             'list' => 'list.thtml',
    85             'header' => 'header.thtml',
    86             'row' => 'listitem.thtml',
    87             'field' => 'field.thtml'
    88         )
    89     );
    90     $admin_templates->set_var( 'xhtml', XHTML );
    91     $admin_templates->set_var('site_url', $_CONF['site_url']);
    92     $admin_templates->set_var('site_admin_url', $_CONF['site_admin_url']);
    93     $admin_templates->set_var('layout_url', $_CONF['layout_url']);
    94     $admin_templates->set_var('form_url', $form_url);
    95     $admin_templates->set_var('lang_edit', $LANG_ADMIN['edit']);
    96     $admin_templates->set_var('lang_deleteall', $LANG01[124]);
    97     $admin_templates->set_var('lang_delconfirm', $LANG01[125]);
    98     if (isset($form_arr['top'])) {
    99         $admin_templates->set_var('formfields_top', $form_arr['top']);
   100     }
   101     if (isset($form_arr['bottom'])) {
   102         $admin_templates->set_var('formfields_bottom', $form_arr['bottom']);
   103     }
   104 
   105     # define icon paths. Those will be transmitted to $fieldfunction.
   106     $icons_type_arr = array('edit', 'copy', 'list', 'addchild');
   107     $icon_arr = array();
   108     foreach ($icons_type_arr as $icon_type) {
   109         $icon_url = "{$_CONF['layout_url']}/images/$icon_type.$_IMAGE_TYPE";
   110         $icon_arr[$icon_type] = COM_createImage($icon_url, $LANG_ADMIN[$icon_type]);
   111     }
   112 
   113     // Check if the delete checkbox and support for the delete all feature should be displayed
   114     $min_data = 1;
   115     if (is_array($options) && isset($options['chkminimum'])) {
   116         $min_data = $options['chkminimum'];
   117     }
   118     if (count($data_arr) > $min_data AND is_array($options) AND $options['chkdelete']) {
   119         $admin_templates->set_var('header_text', '<input type="checkbox" name="chk_selectall" title="'.$LANG01[126].'" onclick="caItems(this.form);"' . XHTML . '>');
   120         $admin_templates->set_var('class', "admin-list-field");
   121         $admin_templates->set_var('show_deleteimage', '');
   122         $admin_templates->parse('header_row', 'header', true);
   123         $admin_templates->clear_var('on_click');
   124     } else {
   125         $admin_templates->set_var('show_deleteimage','display:none;');
   126     }
   127 
   128     # HEADER FIELDS array(text, field, sort)
   129     for ($i=0; $i < count( $header_arr ); $i++) {
   130         $admin_templates->set_var('header_text', $header_arr[$i]['text']);
   131         if (!empty($header_arr[$i]['header_class'])) {
   132             $admin_templates->set_var('class', $header_arr[$i]['header_class']);
   133         } else {
   134             $admin_templates->set_var('class', "admin-list-headerfield");
   135         }
   136         $admin_templates->parse('header_row', 'header', true);
   137     }
   138 
   139     if (count($data_arr) == 0) {
   140         if (isset($text_arr['no_data'])) {
   141             $message = $text_arr['no_data'];
   142         } else {
   143             $message = $LANG_ADMIN['no_results'];
   144         }
   145         $admin_templates->set_var('message', $message);
   146     } else if ($data_arr === false) {
   147         $admin_templates->set_var('message', $LANG_ADMIN['data_error']);
   148     } else {
   149         $admin_templates->set_var('show_message', 'display:none;');
   150         for ($i = 0; $i < count($data_arr); $i++) {
   151             if (count($data_arr) > $min_data AND is_array($options) AND $options['chkdelete']) {
   152                 $admin_templates->set_var('itemtext', '<input type="checkbox" name="delitem[]" value="' . $data_arr[$i][$options['chkfield']].'"' . XHTML . '>');
   153                 $admin_templates->set_var('class', "admin-list-field");
   154                 $admin_templates->parse('item_field', 'field', true);
   155             }
   156             for ($j = 0; $j < count($header_arr); $j++) {
   157                 $fieldname = $header_arr[$j]['field'];
   158                 $fieldvalue = '';
   159                 if (!empty($data_arr[$i][$fieldname])) {
   160                     $fieldvalue = $data_arr[$i][$fieldname];
   161                 }
   162                 if (!empty($fieldfunction)) {
   163                     $fieldvalue = $fieldfunction($fieldname, $fieldvalue, $data_arr[$i], $icon_arr);
   164                 } else {
   165                     $fieldvalue = $fieldvalue;
   166                 }
   167                 if (!empty($header_arr[$j]['field_class'])) {
   168                     $admin_templates->set_var('class', $header_arr[$j]['field_class']);
   169                 } else {
   170                       $admin_templates->set_var('class', "admin-list-field");
   171                 }
   172                 if ($fieldvalue !== false) {
   173                     $admin_templates->set_var('itemtext', $fieldvalue);
   174                     $admin_templates->parse('item_field', 'field', true);
   175                 }
   176             }
   177             $admin_templates->set_var('cssid', ($i%2)+1);
   178             $admin_templates->parse('item_row', 'row', true);
   179             $admin_templates->clear_var('item_field');
   180         }
   181     }
   182 
   183     $admin_templates->parse('output', 'list');
   184 
   185     if (!empty($title)) {
   186         $retval .= COM_startBlock($title, $help_url,
   187                             COM_getBlockTemplate('_admin_block', 'header'));
   188     }
   189     $retval .= $admin_templates->finish($admin_templates->get_var('output'));
   190     if (!empty($title)) {
   191         $retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
   192     }
   193 
   194     return $retval;
   195 }
   196 
   197 /**
   198 * Creates a list of data with a search, filter, clickable headers etc.
   199 *
   200 * @param    string  $component      name of the list
   201 * @param    string  $fieldfunction  name of the function that handles special entries
   202 * @param    array   $header_arr     array of header fields with sortables and table fields
   203 * @param    array   $text_arr       array with different text strings
   204 * @param    array   $query_arr      array with sql-options
   205 * @param    array   $defsort_arr    default sorting values
   206 * @param    string  $filter         additional drop-down filters
   207 * @param    string  $extra          additional values passed to fieldfunction
   208 * @param    array   $options        array of options - intially just used for the Check-All feature
   209 * @param    array   $form_arr       optional extra forms at top or bottom
   210 * @return   string                  HTML output of function
   211 *
   212 */
   213 function ADMIN_list($component, $fieldfunction, $header_arr, $text_arr,
   214             $query_arr, $defsort_arr, $filter = '', $extra = '',
   215             $options = '', $form_arr='')
   216 {
   217     global $_CONF, $_TABLES, $LANG_ADMIN, $LANG_ACCESS, $LANG01, $_IMAGE_TYPE, $MESSAGE;
   218 
   219     // set all variables to avoid warnings
   220     $retval = '';
   221     $filter_str = '';
   222     $order_sql = '';
   223     $limit = '';
   224     $prevorder = '';
   225     if (isset ($_GET['prevorder'])) { # what was the last sorting?
   226         $prevorder = COM_applyFilter ($_GET['prevorder']);
   227     }
   228 
   229     $query = '';
   230     if (isset ($_REQUEST['q'])) { // get query (text-search)
   231         $query = strip_tags(COM_stripslashes($_REQUEST['q']));
   232     }
   233 
   234     $query_limit = '';
   235     if (isset($_REQUEST['query_limit'])) { // get query-limit (list-length)
   236         $query_limit = COM_applyFilter($_REQUEST['query_limit'], true);
   237         if ($query_limit == 0) {
   238             $query_limit = 50;
   239         }
   240     }
   241 
   242     // we assume that the current page is 1 to set it.
   243     $curpage = 1;
   244     $page = '';
   245     // get the current page from the interface. The variable is linked to the
   246     // component, i.e. the plugin/function calling this here to avoid overlap
   247     if (isset ($_REQUEST[$component . 'listpage'])) {
   248         $page = COM_applyFilter ($_REQUEST[$component . 'listpage'], true);
   249         $curpage = $page;
   250     }
   251     if ($curpage <= 0) {
   252         $curpage = 1; #current page has to be larger 0
   253     }
   254 
   255     $help_url = ''; # do we have a help url for the block-header?
   256     if (!empty ($text_arr['help_url'])) {
   257         $help_url = $text_arr['help_url'];
   258     }
   259 
   260     $form_url = ''; # what is the form-url for the search button and list sorters?
   261     if (!empty ($text_arr['form_url'])) {
   262         $form_url = $text_arr['form_url'];
   263     }
   264 
   265     $title = ''; # what is the title of the page?
   266     if (!empty ($text_arr['title'])) {
   267         $title = $text_arr['title'];
   268     }
   269 
   270     $inline_form = false;
   271     if (isset($text_arr['inline'])) {
   272         $inline_form = $text_arr['inline'];
   273     }
   274 
   275     # get all template fields.
   276     $admin_templates = new Template($_CONF['path_layout'] . 'admin/lists');
   277     $admin_templates->set_file (array (
   278         'search' => 'searchmenu.thtml',
   279         'list'   => ($inline_form ? 'inline.thtml' : 'list.thtml'),
   280         'header' => 'header.thtml',
   281         'row'    => 'listitem.thtml',
   282         'field'  => 'field.thtml'
   283     ));
   284 
   285     # insert std. values into the template
   286     $admin_templates->set_var( 'xhtml', XHTML );
   287     $admin_templates->set_var('site_url', $_CONF['site_url']);
   288     $admin_templates->set_var('site_admin_url', $_CONF['site_admin_url']);
   289     $admin_templates->set_var('layout_url', $_CONF['layout_url']);
   290     $admin_templates->set_var('form_url', $form_url);
   291     $admin_templates->set_var('lang_edit', $LANG_ADMIN['edit']);
   292     $admin_templates->set_var('lang_deleteall', $LANG01[124]);
   293     $admin_templates->set_var('lang_delconfirm', $LANG01[125]);
   294     if (isset($form_arr['top'])) {
   295         $admin_templates->set_var('formfields_top', $form_arr['top']);
   296     }
   297     if (isset($form_arr['bottom'])) {
   298         $admin_templates->set_var('formfields_bottom', $form_arr['bottom']);
   299     }
   300     // Check if the delete checkbox and support for the delete all feature should be displayed
   301     if (is_array($options) AND $options['chkdelete']) {
   302         $admin_templates->set_var('header_text', '<input type="checkbox" name="chk_selectall" title="'.$LANG01[126].'" onclick="caItems(this.form);"' . XHTML . '>');
   303         $admin_templates->set_var('class', "admin-list-field");
   304         $admin_templates->set_var('show_deleteimage', '');
   305         $admin_templates->parse('header_row', 'header', true);
   306         $admin_templates->clear_var('on_click');
   307     } else {
   308         $admin_templates->set_var('show_deleteimage','display:none;');
   309     }
   310 
   311     # define icon paths. Those will be transmitted to $fieldfunction.
   312     $icons_type_arr = array('edit', 'copy', 'list', 'addchild');
   313     $icon_arr = array();
   314     foreach ($icons_type_arr as $icon_type) {
   315         $icon_url = "{$_CONF['layout_url']}/images/$icon_type.$_IMAGE_TYPE";
   316         $icon_arr[$icon_type] = COM_createImage($icon_url, $LANG_ADMIN[$icon_type]);
   317     }
   318 
   319     $has_extras = '';
   320     if (isset($text_arr['has_extras'])) { # does this one use extras? (search, google paging)
   321         $has_extras = $text_arr['has_extras'];
   322     }
   323     if ($has_extras) { // show search
   324         $admin_templates->set_var('lang_search', $LANG_ADMIN['search']);
   325         $admin_templates->set_var('lang_submit', $LANG_ADMIN['submit']);
   326         $admin_templates->set_var('lang_limit_results',
   327                                   $LANG_ADMIN['limit_results']);
   328         $admin_templates->set_var('last_query', htmlspecialchars($query));
   329         $admin_templates->set_var('filter', $filter);
   330     }
   331 
   332     $sql_query = addslashes($query); // replace quotes etc for security
   333     $sql = $query_arr['sql']; // get sql from array that builds data
   334 
   335     $order_var = ''; # number that is displayed in URL
   336     $order = '';     # field that is used in SQL
   337     $order_var_link = ''; # Variable for google paging.
   338 
   339     // is the order set in the link (when sorting the list)
   340     if (!isset ($_GET['order'])) {
   341         $order = $defsort_arr['field']; // no, get the default
   342     } else {
   343         $order_var = COM_applyFilter ($_GET['order'], true);
   344         $order_var_link = "&amp;order=$order_var"; # keep the variable for the google paging
   345         $order = $header_arr[$order_var]['field'];  # current order field name
   346     }
   347     $order_for_query = $order;
   348     // this code sorts only by the field if its in table.field style.
   349     // removing this however makes match for arrow-display impossible, so removed it.
   350     // maybe now for more fields the table has to be added to the sortfield?
   351     //$order = explode ('.', $order);
   352     //if (count ($order) > 1) {
   353     //    $order = $order[1];
   354     //} else {
   355     //    $order = $order[0];
   356     //}
   357 
   358     $direction = '';
   359     if (!isset ($_GET['direction'])) { # get direction to sort after
   360         $direction = $defsort_arr['direction'];
   361     } else {
   362         $direction = COM_applyFilter ($_GET['direction']);
   363     }
   364     $direction = strtoupper ($direction);
   365     if ($order == $prevorder) { #reverse direction if prev. order was the same
   366         $direction = ($direction == 'DESC') ? 'ASC' : 'DESC';
   367     } else {
   368         $direction = ($direction == 'DESC') ? 'DESC' : 'ASC';
   369     }
   370 
   371     if ($direction == 'ASC') { # assign proper arrow img name dep. on sort order
   372         $arrow = 'bararrowdown';
   373     } else {
   374         $arrow = 'bararrowup';
   375     }
   376     # make actual order arrow image
   377     $img_arrow_url = "{$_CONF['layout_url']}/images/$arrow.$_IMAGE_TYPE";
   378     $img_arrow = '&nbsp;' . COM_createImage($img_arrow_url, $arrow);
   379 
   380     if (!empty ($order_for_query)) { # concat order string
   381         $order_sql = "ORDER BY $order_for_query $direction";
   382     }
   383     $th_subtags = ''; // other tags in the th, such as onclick and mouseover
   384     $header_text = ''; // title as displayed to the user
   385     // HEADER FIELDS array(text, field, sort, class)
   386     // this part defines the contents & format of the header fields
   387 
   388     for ($i=0; $i < count( $header_arr ); $i++) { #iterate through all headers
   389         $header_text = $header_arr[$i]['text'];
   390         $th_subtags = '';
   391         if ($header_arr[$i]['sort'] != false) { # is this sortable?
   392             if ($order==$header_arr[$i]['field']) { # is this currently sorted?
   393                 $header_text .= $img_arrow;
   394             }
   395             # make the mouseover effect is sortable
   396             $th_subtags = " onmouseover=\"this.style.cursor='pointer';\"";
   397             $order_var = $i; # assign number to field so we know what to sort
   398             if (strpos ($form_url, '?') > 0) {
   399                 $separator = '&amp;';
   400             } else {
   401                 $separator = '?';
   402             }
   403             $th_subtags .= " onclick=\"window.location.href='$form_url$separator" // onclick action
   404                     ."order=$order_var&amp;prevorder=$order&amp;direction=$direction";
   405             if (!empty($page)) {
   406                 $th_subtags .= '&amp;' . $component . 'listpage=' . $page;
   407             }
   408             if (!empty($query)) {
   409                 $th_subtags .= '&amp;q=' . urlencode($query);
   410             }
   411             if (!empty($query_limit)) {
   412                 $th_subtags .= '&amp;query_limit=' . $query_limit;
   413             }
   414             $th_subtags .= "';\"";
   415         }
   416 
   417         if (!empty($header_arr[$i]['header_class'])) {
   418             $admin_templates->set_var('class', $header_arr[$i]['header_class']);
   419         } else {
   420             $admin_templates->set_var('class', "admin-list-headerfield");
   421         }
   422         $admin_templates->set_var('header_text', $header_text);
   423         $admin_templates->set_var('th_subtags', $th_subtags);
   424         $admin_templates->parse('header_row', 'header', true);
   425         $admin_templates->clear_var('th_subtags'); // clear all for next header
   426         $admin_templates->clear_var('class');
   427         $admin_templates->clear_var('header_text');
   428     }
   429 
   430     if ($has_extras) {
   431         $limit = 50; # default query limit if not other chosen.
   432                      # maybe this could be a setting from the list?
   433         if (!empty($query_limit)) {
   434             $limit = $query_limit;
   435         }
   436         if ($query != '') { # set query into form after search
   437             $admin_templates->set_var ('query', urlencode($query) );
   438         } else {
   439             $admin_templates->set_var ('query', '');
   440         }
   441         $admin_templates->set_var ('query_limit', $query_limit);
   442         # choose proper dropdown field for query limit
   443         $admin_templates->set_var($limit . '_selected', 'selected="selected"');
   444 
   445         if (!empty($query_arr['default_filter'])){ # add default filter to sql
   446             $filter_str = " {$query_arr['default_filter']}";
   447         }
   448         if (!empty ($query)) { # add query fields with search term
   449             $filter_str .= " AND (";
   450             for ($f = 0; $f < count($query_arr['query_fields']); $f++) {
   451                 $filter_str .= $query_arr['query_fields'][$f]
   452                             . " LIKE '%$sql_query%'";
   453                 if ($f < (count($query_arr['query_fields']) - 1)) {
   454                     $filter_str .= " OR ";
   455                 }
   456             }
   457             $filter_str .= ")";
   458         }
   459         $num_pages_sql = $sql . $filter_str;
   460         $num_pages_result = DB_query($num_pages_sql);
   461         $num_rows = DB_numRows($num_pages_result);
   462         $num_pages = ceil ($num_rows / $limit);
   463         if ($num_pages < $curpage) { # make sure we dont go beyond possible results
   464                $curpage = 1;
   465         }
   466         $offset = (($curpage - 1) * $limit);
   467         $limit = "LIMIT $offset,$limit"; # get only current page data
   468         $admin_templates->set_var ('lang_records_found',
   469                                    $LANG_ADMIN['records_found']);
   470         $admin_templates->set_var ('records_found',
   471                                    COM_numberFormat ($num_rows));
   472         $admin_templates->parse('search_menu', 'search', true);
   473     }
   474 
   475     # SQL
   476     $sql .= "$filter_str $order_sql $limit;";
   477     // echo $sql;
   478     $result = DB_query($sql);
   479     $nrows = DB_numRows($result);
   480     $r = 1; # r is the counter for the actual displayed rows for correct coloring
   481     for ($i = 0; $i < $nrows; $i++) { # now go through actual data
   482         $A = DB_fetchArray($result);
   483         $this_row = false; # as long as no fields are returned, dont print row
   484         if (is_array($options) AND $options['chkdelete']) {
   485             $admin_templates->set_var('class', "admin-list-field");
   486             $admin_templates->set_var('itemtext', '<input type="checkbox" name="delitem[]" value="' . $A[$options['chkfield']].'"' . XHTML . '>');
   487             $admin_templates->parse('item_field', 'field', true);
   488         }
   489         for ($j = 0; $j < count($header_arr); $j++) {
   490             $fieldname = $header_arr[$j]['field']; # get field name from headers
   491             $fieldvalue = '';
   492             if (!empty($A[$fieldname])) { # is there a field in data like that?
   493                 $fieldvalue = $A[$fieldname]; # yes, get its data
   494             }
   495             if (!empty ($fieldfunction) && !empty ($extra)) {
   496                 $fieldvalue = $fieldfunction ($fieldname, $fieldvalue, $A, $icon_arr, $extra);
   497             } else if (!empty ($fieldfunction)) { # do we have a fieldfunction?
   498                 $fieldvalue = $fieldfunction ($fieldname, $fieldvalue, $A, $icon_arr);
   499             } else { # if not just take the value
   500                 $fieldvalue = $fieldvalue;
   501             }
   502             if ($fieldvalue !== false) { # return was there, so write line
   503                 $this_row = true;
   504             } else {
   505                 $fieldvalue = ''; // dont give emtpy fields
   506             }
   507             if (!empty($header_arr[$j]['field_class'])) {
   508                 $admin_templates->set_var('class', $header_arr[$j]['field_class']);
   509             } else {
   510                 $admin_templates->set_var('class', "admin-list-field");
   511             }
   512             $admin_templates->set_var('itemtext', $fieldvalue); # write field
   513             $admin_templates->parse('item_field', 'field', true);
   514         }
   515         if ($this_row) { # there was data in at least one field, so print line
   516             $r++; # switch to next color
   517             $admin_templates->set_var('cssid', ($r%2)+1); # make alternating table color
   518             $admin_templates->parse('item_row', 'row', true); # process the complete row
   519         }
   520         $admin_templates->clear_var('item_field'); # clear field
   521     }
   522 
   523     if ($nrows==0) { # there is no data. return notification message.
   524         if (isset($text_arr['no_data'])) {
   525             $message = $text_arr['no_data']; # there is a user-message
   526         } else {
   527             $message = $LANG_ADMIN['no_results']; # take std.
   528         }
   529         $admin_templates->set_var('message', $message);
   530     }
   531 
   532     if ($has_extras) { # now make google-paging
   533         $hasargs = strstr( $form_url, '?' );
   534         if( $hasargs ) {
   535             $sep = '&amp;';
   536         } else {
   537             $sep = '?';
   538         }
   539         if (!empty($query)) { # port query to next page
   540             $base_url = $form_url . $sep . 'q=' . urlencode($query) . "&amp;query_limit=$query_limit$order_var_link&amp;direction=$direction";
   541         } else {
   542             $base_url = $form_url . $sep ."query_limit=$query_limit$order_var_link&amp;direction=$direction";
   543         }
   544 
   545         if ($num_pages > 1) { # print actual google-paging
   546             $admin_templates->set_var('google_paging',COM_printPageNavigation($base_url,$curpage,$num_pages, $component . 'listpage='));
   547         } else {
   548             $admin_templates->set_var('google_paging', '');
   549         }
   550     }
   551 
   552     $admin_templates->parse('output', 'list');
   553 
   554     // Do the actual output
   555     if (!empty($title)) {
   556         $retval .= COM_startBlock($title, $help_url,
   557                             COM_getBlockTemplate('_admin_block', 'header'));
   558     }
   559     $retval .= $admin_templates->finish($admin_templates->get_var('output'));
   560     if (!empty($title)) {
   561         $retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
   562     }
   563 
   564     return $retval;
   565 }
   566 
   567 /**
   568 * Creates a menu with an optional icon and optional text below
   569 * this is used in the admin screens but may be used elsewhere also.
   570 *
   571 * @param    array   $menu_arr       array of text & URL of the menu entries
   572 * @param    string  $text           instructions to be displayed
   573 * @param    string  icon            url of an icon that will be displayed
   574 * @return   string                  HTML output of function
   575 *
   576 */
   577 function ADMIN_createMenu($menu_arr, $text, $icon = '')
   578 {
   579     global $_CONF;
   580 
   581     $admin_templates = new Template($_CONF['path_layout'] . 'admin/lists');
   582     $admin_templates->set_file (
   583         array ('top_menu' => 'topmenu.thtml')
   584     );
   585 
   586     $menu_fields = '';
   587     $attr = array('class' => 'admin-menu-item');
   588     for ($i = 0; $i < count($menu_arr); $i++) { # iterate through menu
   589         $menu_fields .= COM_createLink($menu_arr[$i]['text'], $menu_arr[$i]['url'], $attr);
   590         if ($i < (count($menu_arr) -1)) {
   591             $menu_fields .= ' | '; # add separator
   592         }
   593     }
   594     if (!empty ($icon)) {
   595         $attr = array('class' => 'admin-menu-icon');
   596         $icon = COM_createImage($icon, '', $attr);
   597         $admin_templates->set_var('icon', $icon);
   598     }
   599     $admin_templates->set_var('menu_fields', $menu_fields);
   600     $admin_templates->set_var('lang_instructions', $text);
   601     $admin_templates->set_var('xhtml', XHTML);
   602     $admin_templates->set_var('site_url', $_CONF['site_url']);
   603     $admin_templates->set_var('site_admin_url', $_CONF['site_admin_url']);
   604     $admin_templates->set_var('layout_url', $_CONF['layout_url']);
   605     $admin_templates->parse('top_menu', 'top_menu');
   606     $retval = $admin_templates->finish($admin_templates->get_var('top_menu'));
   607     return $retval;
   608 }
   609 
   610 
   611 /**
   612  * The following functions are helper functions used as $fieldfunction with
   613  * ADMIN_list and ADMIN_simpleList (see above)
   614  *
   615  */
   616 
   617 
   618 /**
   619  * used for the list of blocks in admin/block.php
   620  *
   621  */
   622 function ADMIN_getListField_blocks($fieldname, $fieldvalue, $A, $icon_arr, $token)
   623 {
   624     global $_CONF, $LANG_ADMIN, $LANG21, $_IMAGE_TYPE;
   625 
   626     $retval = false;
   627 
   628     $access = SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'],$A['perm_group'],$A['perm_members'],$A['perm_anon']);
   629 
   630     if (($access > 0) && (hasBlockTopicAccess ($A['tid']) > 0)) {
   631         switch($fieldname) {
   632             case 'edit':
   633                 if ($access == 3) {
   634                     $retval = COM_createLink($icon_arr['edit'],
   635                         "{$_CONF['site_admin_url']}/block.php?mode=edit&amp;bid={$A['bid']}");
   636                 }
   637                 break;
   638             case 'title':
   639                 $retval = stripslashes ($A['title']);
   640                 if (empty ($retval)) {
   641                     $retval = '(' . $A['name'] . ')';
   642                 }
   643                 break;
   644             case 'blockorder':
   645                 $retval .= $A['blockorder'];
   646                 break;
   647             case 'is_enabled':
   648                 if ($access == 3) {
   649                     if ($A['is_enabled'] == 1) {
   650                         $switch = ' checked="checked"';
   651                     } else {
   652                         $switch = '';
   653                     }
   654                     $retval = "<input type=\"checkbox\" name=\"enabledblocks[{$A['bid']}]\" "
   655                         . "onclick=\"submit()\" value=\"{$A['onleft']}\"$switch" . XHTML . ">";
   656                     $retval .= "<input type=\"hidden\" name=\"" . CSRF_TOKEN . "\" value=\"{$token}\"" . XHTML . ">";
   657                 }
   658                 break;
   659             case 'move':
   660                 if ($access == 3) {
   661                     if ($A['onleft'] == 1) {
   662                         $side = $LANG21[40];
   663                         $blockcontrol_image = 'block-right.' . $_IMAGE_TYPE;
   664                         $moveTitleMsg = $LANG21[59];
   665                         $switchside = '1';
   666                     } else {
   667                         $blockcontrol_image = 'block-left.' . $_IMAGE_TYPE;
   668                         $moveTitleMsg = $LANG21[60];
   669                         $switchside = '0';
   670                     }
   671                     $retval.="<img src=\"{$_CONF['layout_url']}/images/admin/$blockcontrol_image\" width=\"45\" height=\"20\" usemap=\"#arrow{$A['bid']}\" alt=\"\"" . XHTML . ">"
   672                             ."<map id=\"arrow{$A['bid']}\" name=\"arrow{$A['bid']}\">"
   673                             ."<area coords=\"0,0,12,20\"  title=\"{$LANG21[58]}\" href=\"{$_CONF['site_admin_url']}/block.php?mode=move&amp;bid={$A['bid']}&amp;where=up&amp;".CSRF_TOKEN."={$token}\" alt=\"{$LANG21[58]}\"" . XHTML . ">"
   674                             ."<area coords=\"13,0,29,20\" title=\"$moveTitleMsg\" href=\"{$_CONF['site_admin_url']}/block.php?mode=move&amp;bid={$A['bid']}&amp;where=$switchside&amp;".CSRF_TOKEN."={$token}\" alt=\"$moveTitleMsg\"" . XHTML . ">"
   675                             ."<area coords=\"30,0,43,20\" title=\"{$LANG21[57]}\" href=\"{$_CONF['site_admin_url']}/block.php?mode=move&amp;bid={$A['bid']}&amp;where=dn&amp;".CSRF_TOKEN."={$token}\" alt=\"{$LANG21[57]}\"" . XHTML . ">"
   676                             ."</map>";
   677                 }
   678                 break;
   679             default:
   680                 $retval = $fieldvalue;
   681                 break;
   682         }
   683     }
   684     return $retval;
   685 }
   686 
   687 /**
   688  * used for the list of groups and in the group editor in admin/group.php
   689  *
   690  */
   691 function ADMIN_getListField_groups($fieldname, $fieldvalue, $A, $icon_arr, $selected = '')
   692 {
   693     global $_CONF, $LANG_ACCESS, $LANG_ADMIN, $thisUsersGroups;
   694 
   695     $retval = false;
   696 
   697     if(! is_array($thisUsersGroups)) {
   698         $thisUsersGroups = SEC_getUserGroups();
   699     }
   700 
   701     $show_all_groups = false;
   702     if (isset($_REQUEST['chk_showall']) && ($_REQUEST['chk_showall'] == 1)) {
   703         $show_all_groups = true;
   704     }
   705 
   706     if (in_array($A['grp_id'], $thisUsersGroups) ||
   707           SEC_groupIsRemoteUserAndHaveAccess($A['grp_id'], $thisUsersGroups)) {
   708         switch($fieldname) {
   709         case 'edit':
   710             $url = $_CONF['site_admin_url'] . '/group.php?mode=edit&amp;grp_id='
   711                  . $A['grp_id'];
   712             if ($show_all_groups) {
   713                 $url .= '&amp;chk_showall=1';
   714             }
   715             $retval = COM_createLink($icon_arr['edit'], $url);
   716             break;
   717 
   718         case 'grp_gl_core':
   719             if ($A['grp_gl_core'] == 1) {
   720                 $retval = $LANG_ACCESS['yes'];
   721             } else {
   722                 $retval = $LANG_ACCESS['no'];
   723             }
   724             break;
   725 
   726         case 'list':
   727             $url = $_CONF['site_admin_url'] . '/group.php?mode=';
   728             if ($show_all_groups) {
   729                 $param = '&amp;grp_id=' . $A['grp_id'] . '&amp;chk_showall=1';
   730             } else {
   731                 $param = '&amp;grp_id=' . $A['grp_id'];
   732             }
   733 
   734             $retval = COM_createLink($icon_arr['list'],
   735                                      $url . 'listusers' . $param);
   736             if (($A['grp_name'] != 'All Users') &&
   737                     ($A['grp_name'] != 'Logged-in Users')) {
   738                 $retval .= '&nbsp;&nbsp;' . COM_createLink($icon_arr['edit'],
   739                                                 $url . 'editusers' . $param);
   740             }
   741             break;
   742 
   743         case 'checkbox':
   744             $retval = '<input type="checkbox" name="groups[]" value="'
   745                     . $A['grp_id'] . '"';
   746             if (is_array($selected) && in_array($A['grp_id'], $selected)) {
   747                 $retval .= ' checked="checked"';
   748             }
   749             $retval .= XHTML . '>';
   750             break;
   751 
   752         case 'disabled-checkbox':
   753             $retval = '<input type="checkbox" checked="checked" '
   754                     . 'disabled="disabled"' . XHTML . '>'
   755                     . '<input type="hidden" name="groups[]" value="'
   756                     . $A['grp_id'] . '"' . XHTML . '>';
   757             break;
   758 
   759         case 'grp_name':
   760             $retval = ucwords($fieldvalue);
   761             break;
   762 
   763         default:
   764             $retval = $fieldvalue;
   765             break;
   766         }
   767     }
   768 
   769     return $retval;
   770 }
   771 
   772 /**
   773  * used for the list of users in admin/user.php
   774  *
   775  */
   776 function ADMIN_getListField_users($fieldname, $fieldvalue, $A, $icon_arr)
   777 {
   778     global $_CONF, $_TABLES, $LANG_ADMIN, $LANG04, $LANG28, $_IMAGE_TYPE;
   779 
   780     $retval = '';
   781 
   782     switch ($fieldname) {
   783         case 'delete':
   784             $retval = '<input type="checkbox" name="delitem[]" checked="checked"' . XHTML . '>';
   785             break;
   786         case 'edit':
   787             $retval = COM_createLink($icon_arr['edit'],
   788                 "{$_CONF['site_admin_url']}/user.php?mode=edit&amp;uid={$A['uid']}");
   789             break;
   790         case 'username':
   791             $photoico = '';
   792             if (!empty ($A['photo'])) {
   793                 $photoico = "&nbsp;<img src=\"{$_CONF['layout_url']}/images/smallcamera."
   794                           . $_IMAGE_TYPE . '" alt="{$LANG04[77]}"' . XHTML . '>';
   795             } else {
   796                 $photoico = '';
   797             }
   798             $retval = COM_createLink($fieldvalue, $_CONF['site_url']
   799                     . '/users.php?mode=profile&amp;uid=' .  $A['uid']) . $photoico;
   800             break;
   801         case 'lastlogin':
   802             if ($fieldvalue < 1) {
   803                 // if the user never logged in, show the registration date
   804                 $regdate = strftime ($_CONF['shortdate'], strtotime($A['regdate']));
   805                 $retval = "({$LANG28[36]}, {$LANG28[53]} $regdate)";
   806             } else {
   807                 $retval = strftime ($_CONF['shortdate'], $fieldvalue);
   808             }
   809             break;
   810         case 'lastlogin_short':
   811             if ($fieldvalue < 1) {
   812                 // if the user never logged in, show the registration date
   813                 $regdate = strftime ($_CONF['shortdate'], strtotime($A['regdate']));
   814                 $retval = "({$LANG28[36]})";
   815             } else {
   816                 $retval = strftime ($_CONF['shortdate'], $fieldvalue);
   817             }
   818             break;
   819         case 'online_days':
   820             if ($fieldvalue < 0){
   821                 // users that never logged in, would have a negative online days
   822                 $retval = $LANG_ADMIN['na'];
   823             } else {
   824                 $retval = $fieldvalue;
   825             }
   826             break;
   827         case 'phantom_date':
   828         case 'offline_months':
   829             $retval = COM_numberFormat(round($fieldvalue / 2592000));
   830             break;
   831         case 'online_hours':
   832             $retval = COM_numberFormat(round($fieldvalue / 3600, 3));
   833             break;
   834         case 'regdate':
   835             $retval = strftime ($_CONF['shortdate'], strtotime($fieldvalue));
   836             break;
   837         case $_TABLES['users'] . '.uid':
   838             $retval = $A['uid'];
   839             break;
   840         default:
   841             $retval = $fieldvalue;
   842             break;
   843     }
   844 
   845     if (isset($A['status']) && ($A['status'] == USER_ACCOUNT_DISABLED)) {
   846         if (($fieldname != 'edit') && ($fieldname != 'username')) {
   847             $retval = sprintf ('<span class="strike" title="%s">%s</span>',
   848                                $LANG28[42], $retval);
   849         }
   850     }
   851 
   852     return $retval;
   853 }
   854 
   855 /**
   856  * used for the list of stories in admin/story.php
   857  *
   858  */
   859 function ADMIN_getListField_stories($fieldname, $fieldvalue, $A, $icon_arr)
   860 {
   861     global $_CONF, $_TABLES, $LANG_ADMIN, $LANG24, $LANG_ACCESS, $_IMAGE_TYPE;
   862 
   863     static $topics, $topic_access, $topic_anon;
   864 
   865     if (!isset($topics)) {
   866         $topics = array();
   867     }
   868     if (!isset($topic_access)) {
   869         $topic_access = array();
   870     }
   871 
   872     $retval = '';
   873 
   874     switch ($fieldname) {
   875     case 'unixdate':
   876         $curtime = COM_getUserDateTimeFormat($A['unixdate']);
   877         $retval = strftime($_CONF['daytime'], $curtime[1]);
   878         break;
   879 
   880     case 'title':
   881         $A['title'] = str_replace('$', '&#36;', $A['title']);
   882         $article_url = COM_buildUrl($_CONF['site_url'] . '/article.php?story='
   883                                     . $A['sid']);
   884         $retval = COM_createLink(stripslashes($A['title']), $article_url);
   885         break;
   886 
   887     case 'draft_flag':
   888         if ($A['draft_flag'] == 1) {
   889             $retval = $LANG24[35];
   890         } else {
   891             $retval = $LANG24[36];
   892         }
   893         break;
   894 
   895     case 'access':
   896     case 'edit':
   897     case 'edit_adv':
   898         $access = SEC_hasAccess($A['owner_id'], $A['group_id'],
   899                                 $A['perm_owner'], $A['perm_group'],
   900                                 $A['perm_members'], $A['perm_anon']);
   901         if ($access == 3) {
   902             if (!isset($topic_access[$A['tid']])) {
   903                 $topic_access[$A['tid']] = SEC_hasTopicAccess($A['tid']);
   904             }
   905             if ($topic_access[$A['tid']] == 3) {
   906                 $access = $LANG_ACCESS['edit'];
   907             } else {
   908                 $access = $LANG_ACCESS['readonly'];
   909             }
   910         } else {
   911             $access = $LANG_ACCESS['readonly'];
   912         }
   913         if ($fieldname == 'access') {
   914             $retval = $access;
   915         } elseif ($access == $LANG_ACCESS['edit']) {
   916             if ($fieldname == 'edit_adv') {
   917                 $editmode = 'adv';
   918             } elseif ($fieldname == 'edit') {
   919                 $editmode = 'std';
   920             }
   921             $editurl = $_CONF['site_admin_url']
   922                      . '/story.php?mode=edit&amp;editor=' . $editmode
   923                      . '&amp;sid=' . $A['sid'];
   924             $retval = COM_createLink($icon_arr['edit'], $editurl);
   925         }
   926         break;
   927 
   928     case 'featured':
   929         if ($A['featured'] == 1) {
   930             $retval = $LANG24[35];
   931         } else {
   932             $retval = $LANG24[36];
   933         }
   934         break;
   935 
   936     case 'ping':
   937         if (!isset($topic_anon[$A['tid']])) {
   938             $topic_anon[$A['tid']] = DB_getItem($_TABLES['topics'], 'perm_anon',
   939                 "tid = '" . addslashes($A['tid']) . "'");
   940         }
   941         if (($A['draft_flag'] == 0) && ($A['unixdate'] < time()) &&
   942                 ($A['perm_anon'] != 0) && ($topic_anon[$A['tid']] != 0)) {
   943             $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.'
   944                      . $_IMAGE_TYPE . '" alt="' . $LANG24[21] . '" title="'
   945                      . $LANG24[21] . '"' . XHTML . '>';
   946             $url = $_CONF['site_admin_url']
   947                  . '/trackback.php?mode=sendall&amp;id=' . $A['sid'];
   948             $retval = COM_createLink($pingico, $url);
   949         } else {
   950             $retval = '';
   951         }
   952         break;
   953 
   954     case 'tid':
   955         if (!isset($topics[$A['tid']])) {
   956             $topics[$A['tid']] = DB_getItem($_TABLES['topics'], 'topic',
   957                                             "tid = '{$A['tid']}'");
   958         }
   959         $retval = $topics[$A['tid']];
   960         break;
   961 
   962     case 'username':
   963         $retval = COM_getDisplayName($A['uid'], $A['username'], $A['fullname']);
   964         break;
   965 
   966     default:
   967         $retval = $fieldvalue;
   968         break;
   969     }
   970 
   971     return $retval;
   972 }
   973 
   974 /**
   975  * used for the list of feeds in admin/syndication.php
   976  *
   977  */
   978 function ADMIN_getListField_syndication($fieldname, $fieldvalue, $A, $icon_arr, $token)
   979 {
   980     global $_CONF, $_TABLES, $LANG_ADMIN, $LANG33, $_IMAGE_TYPE;
   981 
   982     $retval = '';
   983 
   984     switch($fieldname) {
   985         case 'edit':
   986             $retval = COM_createLink($icon_arr['edit'],
   987                 "{$_CONF['site_admin_url']}/syndication.php?mode=edit&amp;fid={$A['fid']}");
   988             break;
   989         case 'type':
   990             if ($A['type'] == 'article') {
   991                 $retval = $LANG33[55];
   992             } else {
   993                 $retval = ucwords($A['type']);
   994             }
   995             break;
   996         case 'format':
   997             $retval = str_replace ('-' , ' ', ucwords ($A['format']));
   998             break;
   999         case 'updated':
  1000             $retval = strftime ($_CONF['daytime'], $A['date']);
  1001             break;
  1002         case 'is_enabled':
  1003             if ($A['is_enabled'] == 1) {
  1004                 $switch = ' checked="checked"';
  1005             } else {
  1006                 $switch = '';
  1007             }
  1008             $retval = "<input type=\"checkbox\" name=\"enabledfeeds[]\" "
  1009                 . "onclick=\"submit()\" value=\"{$A['fid']}\"$switch" . XHTML . ">";
  1010             $retval .= "<input type=\"hidden\" name=\"" . CSRF_TOKEN . "\" value=\"{$token}\"" . XHTML . ">";
  1011             break;
  1012         case 'header_tid':
  1013             if ($A['header_tid'] == 'all') {
  1014                 $retval = $LANG33[43];
  1015             } elseif ($A['header_tid'] == 'none') {
  1016                 $retval = $LANG33[44];
  1017             } else {
  1018                 $retval = DB_getItem ($_TABLES['topics'], 'topic',
  1019                                       "tid = '{$A['header_tid']}'");
  1020             }
  1021             break;
  1022         case 'filename':
  1023             $url = SYND_getFeedUrl ();
  1024             $retval = COM_createLink($A['filename'], $url . $A['filename']);
  1025             break;
  1026         default:
  1027             $retval = $fieldvalue;
  1028             break;
  1029     }
  1030     return $retval;
  1031 }
  1032 
  1033 /**
  1034  * used for the list of plugins in admin/plugins.php
  1035  *
  1036  */
  1037 function ADMIN_getListField_plugins($fieldname, $fieldvalue, $A, $icon_arr, $token)
  1038 {
  1039     global $_CONF, $LANG_ADMIN, $LANG32;
  1040 
  1041     static $added_token;
  1042 
  1043     $retval = '';
  1044     
  1045     switch($fieldname) {
  1046         case 'edit':
  1047             $retval = COM_createLink($icon_arr['edit'],
  1048                 "{$_CONF['site_admin_url']}/plugins.php?mode=edit&amp;pi_name={$A['pi_name']}");
  1049             break;
  1050         case 'pi_name':
  1051             $retval = plugin_get_pluginname($A['pi_name']);
  1052             break;
  1053         case 'pi_version':
  1054             $plugin_code_version = PLG_chkVersion ($A['pi_name']);
  1055             if (empty ($plugin_code_version)) {
  1056                 $code_version = $LANG_ADMIN['na'];
  1057             } else {
  1058                 $code_version = $plugin_code_version;
  1059             }
  1060             $pi_installed_version = $A['pi_version'];
  1061             if (empty ($plugin_code_version) ||
  1062                     ($pi_installed_version == $code_version)) {
  1063                 $retval = $pi_installed_version;
  1064             } else {
  1065                 $retval = "{$LANG32[37]}: $pi_installed_version,&nbsp;{$LANG32[36]}: $plugin_code_version";
  1066                 if ($A['pi_enabled'] == 1) {
  1067                     $retval .= " <b>{$LANG32[38]}</b>"
  1068                         . ' <input type="image" src="' . $_CONF['layout_url']
  1069                         . '/images/update.png" alt="[' . $LANG32[38]
  1070                         . ']" name="updatethisplugin" value="' . $A['pi_name']
  1071                         . '" onclick="submit()" title="' . $LANG32[42] . '"'
  1072                         . XHTML . '>';
  1073                     if (! isset($added_token)) {
  1074                         $retval .= '<input type="hidden" name="' . CSRF_TOKEN
  1075                                 . '" ' . 'value="' . $token . '"' . XHTML . '>';
  1076                         $added_token = true;
  1077                     }
  1078                 }
  1079             }
  1080             break;
  1081         case 'enabled':
  1082             $not_present = false;
  1083             if ($A['pi_enabled'] == 1) {
  1084                 $switch = ' checked="checked"';
  1085             } else {
  1086                 $switch = '';
  1087                 if (! file_exists($_CONF['path'] . 'plugins/' . $A['pi_name']
  1088                                   . '/functions.inc')) {
  1089                     $not_present = true;
  1090                 }
  1091             }
  1092             if ($not_present) {
  1093                 $retval = '<input type="checkbox" name="enabledplugins['
  1094                         . $A['pi_name'] . ']" disabled="disabled"' . XHTML . '>';
  1095             } else {
  1096                 $retval = '<input type="checkbox" name="enabledplugins['
  1097                         . $A['pi_name'] . ']" onclick="submit()" value="1"'
  1098                         . $switch . XHTML . '>';
  1099                 if (! isset($added_token)) {
  1100                     $retval .= '<input type="hidden" name="' . CSRF_TOKEN . '" '
  1101                             . 'value="' . $token . '"' . XHTML . '>';
  1102                     $added_token = true;
  1103                 }
  1104             }
  1105             break;
  1106         default:
  1107             $retval = $fieldvalue;
  1108             break;
  1109     }
  1110     return $retval;
  1111 }
  1112 
  1113 /**
  1114  * used for the lists of submissions and draft stories in admin/moderation.php
  1115  *
  1116  */
  1117 function ADMIN_getListField_moderation($fieldname, $fieldvalue, $A, $icon_arr)
  1118 {
  1119     global $_CONF, $_TABLES, $LANG_ADMIN;
  1120 
  1121     $retval = '';
  1122 
  1123     $type = '';
  1124     if (isset($A['_moderation_type'])) {
  1125         $type = $A['_moderation_type'];
  1126     }
  1127     switch ($fieldname) {
  1128     case 'edit':
  1129         $retval = COM_createLink($icon_arr['edit'], $A['edit']);
  1130         break;
  1131 
  1132     case 'delete':
  1133         $retval = "<input type=\"radio\" name=\"action[{$A['row']}]\" value=\"delete\"" . XHTML . ">";
  1134         break;
  1135 
  1136     case 'approve':
  1137         $retval = "<input type=\"radio\" name=\"action[{$A['row']}]\" value=\"approve\"" . XHTML . ">"
  1138                  ."<input type=\"hidden\" name=\"id[{$A['row']}]\" value=\"{$A[0]}\"" . XHTML . ">";
  1139         break;
  1140 
  1141     case 'day':
  1142         $retval = strftime($_CONF['daytime'], $A['day']);
  1143         break;
  1144 
  1145     case 'tid':
  1146         $retval = DB_getItem($_TABLES['topics'], 'topic',
  1147                              "tid = '{$A['tid']}'");
  1148         break;
  1149 
  1150     case 'uid':
  1151         $name = '';
  1152         if ($A['uid'] == 1) {
  1153             $name = htmlspecialchars(COM_stripslashes(DB_getItem($_TABLES['commentsubmissions'], 'name', "cid = '{$A['id']}'")));
  1154         }
  1155         if (empty($name)) {
  1156             $name = COM_getDisplayName($A['uid']);
  1157         }
  1158         if ($A['uid'] == 1) {
  1159             $retval = $name;
  1160         } else {
  1161             $retval = COM_createLink($name, $_CONF['site_url']
  1162                             . '/users.php?mode=profile&amp;uid=' . $A['uid']);
  1163         }
  1164         break;
  1165 
  1166     case 'publishfuture':
  1167         if (!SEC_inGroup('Comment Submitters', $A['uid']) && ($A['uid'] > 1)) {
  1168             $retval = "<input type=\"checkbox\" name=\"publishfuture[]\" value=\"{$A['uid']}\"" . XHTML . ">";
  1169         } else {
  1170             $retval = $LANG_ADMIN['na'];
  1171         }
  1172         break;
  1173 
  1174     default:
  1175         if (($fieldname == 3) && ($type == 'story')) {
  1176             $retval = DB_getItem($_TABLES['topics'], 'topic',
  1177                                   "tid = '{$A[3]}'");
  1178         } elseif (($fieldname == 2) && ($type == 'comment')) {
  1179             $commenttext = COM_getTextContent($A['comment']);
  1180             $excerpt = htmlspecialchars(COM_truncate($commenttext, 140, '...'));
  1181 
  1182             // try to provide a link to the parent item (e.g. article, poll)
  1183             $info = PLG_getItemInfo($A['type'], $A['sid'], 'title,url');
  1184             if (empty($info) || empty($info[0]) || empty($info[1])) {
  1185                 // if not available, display excerpt from the comment
  1186                 $retval = htmlspecialchars(COM_truncate($commenttext, 40,
  1187                                                         '...'));
  1188                 if (strlen($commenttext) > 40) {
  1189                     $retval = '<span title="' . $excerpt . '">' . $retval
  1190                             . '</span>';
  1191                 }
  1192             } else {
  1193                 $retval = COM_createLink($info[0], $info[1],
  1194                                          array('title' => $excerpt));
  1195             }
  1196         } else {
  1197             $retval = COM_makeClickableLinks(stripslashes($fieldvalue));
  1198         }
  1199         break;
  1200     }
  1201 
  1202     return $retval;
  1203 }
  1204 
  1205 /**
  1206  * used for the list of ping services in admin/trackback.php
  1207  *
  1208  */
  1209 function ADMIN_getListField_trackback($fieldname, $fieldvalue, $A, $icon_arr, $token)
  1210 {
  1211     global $_CONF, $LANG_TRB;
  1212 
  1213     $retval = '';
  1214 
  1215     switch($fieldname) {
  1216         case "edit":
  1217             $retval = COM_createLink($icon_arr['edit'],
  1218                 "{$_CONF['site_admin_url']}/trackback.php?mode=editservice&amp;service_id={$A['pid']}");
  1219             break;
  1220         case "name":
  1221             $retval = COM_createLink($A['name'], $A['site_url']);
  1222             break;
  1223         case "method":
  1224             if ($A['method'] == 'weblogUpdates.ping') {
  1225                 $retval = $LANG_TRB['ping_standard'];
  1226             } else if ($A['method'] == 'weblogUpdates.extendedPing') {
  1227                 $retval = $LANG_TRB['ping_extended'];
  1228             } else {
  1229                 $retval = '<span class="warningsmall">' .
  1230                         $LANG_TRB['ping_unknown'] .  '</span>';
  1231             }
  1232             break;
  1233         case "is_enabled":
  1234             if ($A['is_enabled'] == 1) {
  1235                 $switch = ' checked="checked"';
  1236             } else {
  1237                 $switch = '';
  1238             }
  1239             $retval = "<input type=\"checkbox\" name=\"changedservices[]\" "
  1240                 . "onclick=\"submit()\" value=\"{$A['pid']}\"$switch" . XHTML . ">";
  1241             $retval .= "<input type=\"hidden\" name=\"" . CSRF_TOKEN
  1242                     . "\" value=\"{$token}\"" . XHTML . ">";
  1243             break;
  1244         default:
  1245             $retval = $fieldvalue;
  1246             break;
  1247     }
  1248 
  1249     return $retval;
  1250 }
  1251 
  1252 /**
  1253  * used in the user editor in admin/user.php
  1254  *
  1255  */
  1256 function ADMIN_getListField_usergroups($fieldname, $fieldvalue, $A, $icon_arr, $selected = '')
  1257 {
  1258     global $thisUsersGroups;
  1259 
  1260     $retval = false;
  1261 
  1262     if(! is_array($thisUsersGroups)) {
  1263         $thisUsersGroups = SEC_getUserGroups();
  1264     }
  1265 
  1266     if (in_array($A['grp_id'], $thisUsersGroups ) ||
  1267           SEC_groupIsRemoteUserAndHaveAccess($A['grp_id'], $thisUsersGroups)) {
  1268         switch($fieldname) {
  1269         case 'checkbox':
  1270             $checked = '';
  1271             if (is_array($selected) && in_array($A['grp_id'], $selected)) {
  1272                 $checked = ' checked="checked"';
  1273             }
  1274             if (($A['grp_name'] == 'All Users') ||
  1275                 ($A['grp_name'] == 'Logged-in Users') ||
  1276                 ($A['grp_name'] == 'Remote Users')) {
  1277                 $retval = '<input type="checkbox" disabled="disabled"'
  1278                         . $checked . XHTML . '>'
  1279                         . '<input type="hidden" name="groups[]" value="'
  1280                         . $A['grp_id'] . '"' . $checked . XHTML . '>';
  1281             } else {
  1282                 $retval = '<input type="checkbox" name="groups[]" value="'
  1283                         . $A['grp_id'] . '"' . $checked . XHTML . '>';
  1284             }
  1285             break;
  1286 
  1287         case 'grp_name':
  1288             $retval = ucwords($fieldvalue);
  1289             break;
  1290 
  1291         default:
  1292             $retval = $fieldvalue;
  1293             break;
  1294         }
  1295     }
  1296 
  1297     return $retval;
  1298 }
  1299 
  1300 ?>