Ignore:
Timestamp:
Apr 10, 2010, 3:25:20 PM (15 years ago)
Author:
nikrou
Message:

Feature 1031 : Automatically sort photos by rank when manual ranks are edited
Add fields to choose sorting mode.
If order of images is changed, checked automaticaly rank for sorting mode.

Need refactoring between admin/element_set_ranks.php admin/cat_modify.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/element_set_ranks.php

    r5196 r5759  
    8585// +-----------------------------------------------------------------------+
    8686
     87$image_order_choices = array('default', 'rank', 'user_define');
     88$image_order_choice = 'default';
     89
    8790if (isset($_POST['submit']))
    8891{
     
    98101    l10n('Images manual order was saved')
    99102    );
     103
     104  $image_order = null;
     105  if (!empty($_POST['image_order_choice'])
     106      && in_array($_POST['image_order_choice'], $image_order_choices))
     107  {
     108    $image_order_choice = $_POST['image_order_choice'];
     109  }
     110     
     111  if ($image_order_choice=='user_define')
     112  {
     113    for ($i=1; $i<=3; $i++)
     114    {
     115      if ( !empty($_POST['order_field_'.$i]) )
     116      {
     117        if (! empty($image_order) )
     118        {
     119          $image_order .= ',';
     120        }
     121        $image_order .= $_POST['order_field_'.$i];
     122        if ($_POST['order_direction_'.$i]=='DESC')
     123        {
     124          $image_order .= ' DESC';
     125        }
     126      }
     127    }
     128  }
     129  elseif ($image_order_choice=='rank')
     130  {
     131    $image_order = 'rank';
     132  }
     133  $query = '
     134UPDATE '.CATEGORIES_TABLE.' SET image_order=\''.$image_order.'\'
     135  WHERE id='.$page['category_id'];
     136  pwg_query($query);
    100137}
    101138
     
    109146$base_url = get_root_url().'admin.php';
    110147
    111 // $form_action = $base_url.'?page=element_set_global';
    112 
    113148$query = '
    114 SELECT uppercats
     149SELECT *
    115150  FROM '.CATEGORIES_TABLE.'
    116151  WHERE id = '.$page['category_id'].'
    117152;';
    118153$category = pwg_db_fetch_assoc(pwg_query($query));
     154
     155if ($category['image_order']=='rank')
     156{
     157  $image_order_choice = 'rank';
     158}
     159elseif ($category['image_order']!='')
     160{
     161  $image_order_choice = 'user_define';
     162}
    119163
    120164// Navigation path
     
    175219}
    176220
     221// image order management
     222$sort_fields = array(
     223  '' => '',
     224  'date_creation' => l10n('Creation date'),
     225  'date_available' => l10n('Post date'),
     226  'average_rate' => l10n('Average rate'),
     227  'hit' => l10n('Most visited'),
     228  'file' => l10n('File name'),
     229  'id' => 'Id',
     230  'rank' => l10n('Rank'),
     231  );
     232
     233$sort_directions = array(
     234  'ASC' => l10n('ascending'),
     235  'DESC' => l10n('descending'),
     236  );
     237
     238$template->assign('image_order_field_options', $sort_fields);
     239$template->assign('image_order_direction_options', $sort_directions);
     240
     241$matches = array();
     242if ( !empty( $category['image_order'] ) )
     243{
     244  preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i',
     245    $category['image_order'], $matches);
     246}
     247
     248for ($i=0; $i<3; $i++) // 3 fields
     249{
     250  $tpl_image_order_select = array(
     251      'ID' => $i+1,
     252      'FIELD' => array(''),
     253      'DIRECTION' => array('ASC'),
     254    );
     255
     256  if ( isset($matches[1][$i]) )
     257  {
     258    $tpl_image_order_select['FIELD'] = array($matches[1][$i]);
     259  }
     260
     261  if (isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0)
     262  {
     263    $tpl_image_order_select['DIRECTION'] = array('DESC');
     264  }
     265  $template->append( 'image_orders', $tpl_image_order_select);
     266}
     267
     268$template->assign('image_order_choice', $image_order_choice);
     269
     270
    177271// +-----------------------------------------------------------------------+
    178272// |                          sending html code                            |
Note: See TracChangeset for help on using the changeset viewer.