Changeset 764 for trunk/admin


Ignore:
Timestamp:
Apr 16, 2005, 6:56:32 PM (20 years ago)
Author:
plg
Message:
  • elements batch management : element_set page becomes the frontend to element_set_global and element_set_unit, infos_images (after a long time of use) become deprecated : the more powerful element_set is used instead. Consequently, batch management concerns caddie but also "normal categories".
  • refactoring code in admin.php to include the sub-file (clearer)
  • caddie : function fill_caddie replaces the code in category.php and can be used in admin/element_set.php
  • caddie : caddie table is added in delete_elements function
Location:
trunk/admin
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_list.php

    r728 r764  
    452452     
    453453      'U_INFO_IMG'
    454       => add_session_id($base_url.'infos_images&cat_id='.$category['id'])
     454      => add_session_id($base_url.'element_set&cat='.$category['id'])
    455455      ));
    456456 
  • trunk/admin/element_set_global.php

    r763 r764  
    7373
    7474// +-----------------------------------------------------------------------+
    75 // |                          caddie management                            |
    76 // +-----------------------------------------------------------------------+
    77 if (isset($_POST['submit_caddie']))
    78 {
    79   if (isset($_POST['caddie_action']))
    80   {
    81     switch ($_POST['caddie_action'])
    82     {
    83       case 'empty_all' :
    84       {
    85           $query = '
    86 DELETE FROM '.CADDIE_TABLE.'
    87   WHERE user_id = '.$user['id'].'
    88 ;';
    89           pwg_query($query);
    90           break;
    91       }
    92       case 'empty_selected' :
    93       {
    94         if (isset($_POST['selection']) and count($_POST['selection']) > 0)
    95         {
    96           $query = '
    97 DELETE
    98   FROM '.CADDIE_TABLE.'
    99   WHERE element_id IN ('.implode(',', $_POST['selection']).')
    100     AND user_id = '.$user['id'].'
    101 ;';
    102           pwg_query($query);
    103         }
    104         else
    105         {
    106           // TODO : add error
    107         }
    108         break;
    109       }
    110     }
    111   }
    112   else
    113   {
    114     // TODO : add error
    115   }
    116 }
    117 
    118 // +-----------------------------------------------------------------------+
    11975// |                       global mode form submission                     |
    12076// +-----------------------------------------------------------------------+
     
    13490    case 'all' :
    13591    {
    136       $query = '
    137 SELECT element_id
    138   FROM '.CADDIE_TABLE.'
    139   WHERE user_id = '.$user['id'].'
    140 ;';
    141       $result = pwg_query($query);
    142       while ($row = mysql_fetch_array($result))
    143       {
    144         array_push($collection, $row['element_id']);
    145       }
     92      $collection = $page['cat_elements_id'];
    14693      break;
    14794    }
     
    182129  if ($_POST['dissociate'] != 0)
    183130  {
    184     // physical links must be broken, so we must first retrieve image_id
     131    // physical links must not be broken, so we must first retrieve image_id
    185132    // which create virtual links with the category to "dissociate from".
    186133    $query = '
     
    321268$template->assign_vars(
    322269  array(
     270    'CATEGORY_TITLE'=>$page['title'],
     271   
    323272    'L_SUBMIT'=>$lang['submit'],
    324273
    325     'U_ELEMENTS_LINE'=>$base_url.get_query_string_diff(array('display')),
    326     'U_UNIT_MODE'=>add_session_id($base_url.'?page=element_set_unit'),
     274    'U_COLS'=>$base_url.get_query_string_diff(array('cols')),
     275    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
     276   
     277    'U_UNIT_MODE'
     278    =>
     279    $base_url
     280    .get_query_string_diff(array('mode','display'))
     281    .'&mode=unit',
    327282   
    328283    'F_ACTION'=>$base_url.get_query_string_diff(array()),
    329284   )
    330285 );
     286
     287// +-----------------------------------------------------------------------+
     288// |                            caddie options                             |
     289// +-----------------------------------------------------------------------+
     290
     291if ('caddie' == $_GET['cat'])
     292{
     293  $template->assign_block_vars('in_caddie', array());
     294}
     295else
     296{
     297  $template->assign_block_vars('not_in_caddie', array());
     298}
     299
    331300// +-----------------------------------------------------------------------+
    332301// |                           global mode form                            |
     
    361330    ));
    362331
    363 $query = '
     332if (count($page['cat_elements_id']) > 0)
     333{
     334  $query = '
    364335SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
    365336  FROM '.IMAGE_CATEGORY_TABLE.' AS ic,
    366        '.CADDIE_TABLE.' AS caddie,
    367337       '.CATEGORIES_TABLE.' AS c,
    368338       '.IMAGES_TABLE.' AS i
    369   WHERE ic.image_id = caddie.element_id
     339  WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).')
    370340    AND ic.category_id = c.id
    371341    AND ic.image_id = i.id
    372342    AND ic.category_id != i.storage_category_id
    373     AND caddie.user_id = '.$user['id'].'
    374 ;';
    375 display_select_cat_wrapper($query, array(), $blockname, true);
     343;';
     344  display_select_cat_wrapper($query, array(), $blockname, true);
     345}
    376346
    377347$blockname = 'remove_keyword_option';
     
    383353    ));
    384354
    385 $query = '
    386 SELECT element_id
    387   FROM '.CADDIE_TABLE.'
    388   WHERE user_id = '.$user['id'].'
    389 ;';
    390 $keywords = get_elements_keywords(array_from_query($query, 'element_id'));
     355$keywords = get_elements_keywords($page['cat_elements_id']);
    391356
    392357foreach ($keywords as $keyword)
     
    428393// +-----------------------------------------------------------------------+
    429394
    430 $page['nb_image_line'] = !empty($_GET['display']) ? $_GET['display'] : 5;
    431 
    432 $query = '
    433 SELECT element_id,path,tn_ext
    434   FROM '.IMAGES_TABLE.' INNER JOIN '.CADDIE_TABLE.' ON id=element_id
    435   WHERE user_id = '.$user['id'].'
     395$page['cols'] = !empty($_GET['cols']) ? intval($_GET['cols']) : 5;
     396$page['nb_images'] = !empty($_GET['display']) ? intval($_GET['display']) : 20;
     397
     398if (count($page['cat_elements_id']) > 0)
     399{
     400  $nav_bar = create_navigation_bar(
     401    $base_url.get_query_string_diff(array('start')),
     402    count($page['cat_elements_id']),
     403    $page['start'],
     404    $page['nb_images'],
     405    '');
     406  $template->assign_vars(array('NAV_BAR' => $nav_bar));
     407
     408  $query = '
     409SELECT id,path,tn_ext
     410  FROM '.IMAGES_TABLE.'
     411  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
    436412  '.$conf['order_by'].'
    437 ;';
    438 //echo '<pre>'.$query.'</pre>';
    439 $result = pwg_query($query);
    440 
    441 // template thumbnail initialization
    442 if (mysql_num_rows($result) > 0)
    443 {
    444   $template->assign_block_vars('thumbnails', array());
    445   // first line
    446   $template->assign_block_vars('thumbnails.line', array());
    447   // current row displayed
    448   $row_number = 0;
    449 }
    450 
    451 while ($row = mysql_fetch_array($result))
    452 {
    453   $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    454      
    455   $template->assign_block_vars(
    456     'thumbnails.line.thumbnail',
    457     array(
    458       'ID' => $row['element_id'],
    459       'SRC' => $src,
    460       'ALT' => 'TODO',
    461       'TITLE' => 'TODO'
    462       )
    463     );
    464  
    465   // create a new line ?
    466   if (++$row_number == $page['nb_image_line'])
    467   {
     413  LIMIT '.$page['start'].', '.$page['nb_images'].'
     414;';
     415  //echo '<pre>'.$query.'</pre>';
     416  $result = pwg_query($query);
     417
     418  // template thumbnail initialization
     419  if (mysql_num_rows($result) > 0)
     420  {
     421    $template->assign_block_vars('thumbnails', array());
     422    // first line
     423    $template->assign_block_vars('thumbnails.line', array());
     424    // current row displayed
     425    $row_number = 0;
     426  }
     427
     428  while ($row = mysql_fetch_array($result))
     429  {
     430    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     431   
     432    $template->assign_block_vars(
     433      'thumbnails.line.thumbnail',
     434      array(
     435        'ID' => $row['id'],
     436        'SRC' => $src,
     437        'ALT' => 'TODO',
     438        'TITLE' => 'TODO'
     439        )
     440      );
     441   
     442    // create a new line ?
     443    if (++$row_number == $page['cols'])
     444    {
    468445    $template->assign_block_vars('thumbnails.line', array());
    469446    $row_number = 0;
     447    }
    470448  }
    471449}
  • trunk/admin/element_set_unit.php

    r763 r764  
    100100
    101101// +-----------------------------------------------------------------------+
    102 // |                         page information init                         |
    103 // +-----------------------------------------------------------------------+
    104 
    105 // $page['start'] contains the number of the first element in its
    106 // category. For exampe, $page['start'] = 12 means we must show elements #12
    107 // and $page['nb_images'] next elements
    108 if (!isset($_GET['start'])
    109     or !is_numeric($_GET['start'])
    110     or $_GET['start'] < 0)
    111 {
    112   $page['start'] = 0;
    113 }
    114 else
    115 {
    116   $page['start'] = $_GET['start'];
    117 }
    118 
    119 // $page['nb_images'] is the number of elements to show in the page
    120 $page['nb_images'] = !empty($_GET['display']) ? $_GET['display'] : 5;
    121 
    122 // $page['cat_nb_images'] is the total number of elements to show in the
    123 // category
    124 $query = '
    125 SELECT COUNT(*)
    126   FROM '.CADDIE_TABLE.'
    127   WHERE user_id = '.$user['id'].'
    128 ;';
    129 list($page['cat_nb_images']) = mysql_fetch_row(pwg_query($query));
    130 
    131 // +-----------------------------------------------------------------------+
    132102// |                             template init                             |
    133103// +-----------------------------------------------------------------------+
     
    142112$template->assign_vars(
    143113  array(
     114    'CATEGORY_TITLE'=>$page['title'],
     115
    144116    'L_SUBMIT'=>$lang['submit'],
    145117   
     
    148120   
    149121    'U_GLOBAL_MODE'
    150 //    =>$base_url.get_query_string_diff(array('mode','display','start')),
    151     =>add_session_id($base_url.'?page=element_set_global'),
     122    =>
     123    $base_url
     124    .get_query_string_diff(array('mode','display'))
     125    .'&amp;mode=global',
    152126   
    153127    'F_ACTION'=>$base_url.get_query_string_diff(array()),
     
    159133// +-----------------------------------------------------------------------+
    160134
    161 $element_ids = array();
    162 
    163 $query = '
    164 SELECT element_id,path,tn_ext,name,date_creation,comment,keywords,author
    165   FROM '.IMAGES_TABLE.' INNER JOIN '.CADDIE_TABLE.' ON id=element_id
    166   WHERE user_id = '.$user['id'].'
     135$page['nb_images'] = !empty($_GET['display']) ? intval($_GET['display']) : 5;
     136
     137
     138if (count($page['cat_elements_id']) > 0)
     139{
     140  $nav_bar = create_navigation_bar(
     141    $base_url.get_query_string_diff(array('start')),
     142    count($page['cat_elements_id']),
     143    $page['start'],
     144    $page['nb_images'],
     145    '');
     146  $template->assign_vars(array('NAV_BAR' => $nav_bar));
     147
     148 
     149  $element_ids = array();
     150
     151  $query = '
     152SELECT id,path,tn_ext,name,date_creation,comment,keywords,author
     153  FROM '.IMAGES_TABLE.'
     154  WHERE id IN ('.implode(',', $page['cat_elements_id']).')
    167155  '.$conf['order_by'].'
    168156  LIMIT '.$page['start'].', '.$page['nb_images'].'
    169157;';
    170 $result = pwg_query($query);
    171 
    172 while ($row = mysql_fetch_array($result))
    173 {
    174   // echo '<pre>'; print_r($row); echo '</pre>';
    175   array_push($element_ids, $row['element_id']);
    176  
    177   $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    178 
    179   // creation date
    180   if (!empty($row['date_creation']))
     158  $result = pwg_query($query);
     159
     160  while ($row = mysql_fetch_array($result))
    181161  {
    182     list($year,$month,$day) = explode('-', $row['date_creation']);
     162    // echo '<pre>'; print_r($row); echo '</pre>';
     163    array_push($element_ids, $row['id']);
     164   
     165    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     166   
     167    // creation date
     168    if (!empty($row['date_creation']))
     169    {
     170      list($year,$month,$day) = explode('-', $row['date_creation']);
     171    }
     172    else
     173    {
     174      list($year,$month,$day) = array('','','');
     175    }
     176   
     177    $template->assign_block_vars(
     178      'element',
     179      array(
     180        'ID' => $row['id'],
     181        'FILENAME' => $row['path'],
     182        'TN_SRC' => $src,
     183        'NAME' => @$row['name'],
     184        'AUTHOR' => @$row['author'],
     185        'COMMENT' => @$row['comment'],
     186        'DATE_CREATION_YEAR' => $year,
     187        'KEYWORDS' => @$row['keywords']
     188        )
     189      );
     190   
     191    get_day_list('element.date_creation_day', $day);
     192    get_month_list('element.date_creation_month', $month);
    183193  }
    184   else
    185   {
    186     list($year,$month,$day) = array('','','');
    187   }
    188 
    189   $template->assign_block_vars(
    190     'element',
    191     array(
    192       'ID' => $row['element_id'],
    193       'FILENAME' => $row['path'],
    194       'TN_SRC' => $src,
    195       'NAME' => @$row['name'],
    196       'AUTHOR' => @$row['author'],
    197       'COMMENT' => @$row['comment'],
    198       'DATE_CREATION_YEAR' => $year,
    199       'KEYWORDS' => @$row['keywords']
    200       )
    201     );
    202  
    203   get_day_list('element.date_creation_day', $day);
    204   get_month_list('element.date_creation_month', $month);
     194
     195  $template->assign_vars(array('IDS_LIST' => implode(',', $element_ids)));
    205196}
    206 
    207 $template->assign_vars(array('IDS_LIST' => implode(',', $element_ids)));
    208 
    209 $nav_bar = create_navigation_bar(
    210   $base_url.get_query_string_diff(array('start')),
    211   $page['cat_nb_images'],
    212   $page['start'],
    213   $page['nb_images'],
    214   '');
    215 $template->assign_vars(array('NAV_BAR' => $nav_bar));
    216197
    217198// +-----------------------------------------------------------------------+
  • trunk/admin/include/functions.php

    r680 r764  
    297297  $query = '
    298298DELETE FROM '.RATE_TABLE.'
     299  WHERE element_id IN (
     300'.wordwrap(implode(', ', $ids), 80, "\n").')
     301;';
     302  pwg_query($query);
     303
     304  // destruction of the rates associated to this element
     305  $query = '
     306DELETE FROM '.CADDIE_TABLE.'
    299307  WHERE element_id IN (
    300308'.wordwrap(implode(', ', $ids), 80, "\n").')
Note: See TracChangeset for help on using the changeset viewer.