Changeset 633


Ignore:
Timestamp:
Dec 4, 2004, 6:42:07 PM (19 years ago)
Author:
plg
Message:
  • shows the element representing a non empty category in cat_modify
  • possibility to set a random representing element for a category
  • bug fixed : update_category function could not update nb_images
  • bug fixed : mass_updates was inserting in the wrong table
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_modify.php

    r632 r633  
    8080
    8181  $template->assign_block_vars('confirmation' ,array());
     82}
     83else if (isset($_POST['set_random_representant']))
     84{
     85  set_random_representant(array($_GET['cat_id']));
    8286}
    8387
     
    158162  'L_NO'=>$lang['no'],
    159163  'L_SUBMIT'=>$lang['submit'],
     164  'L_SET_RANDOM_REPRESENTANT'=>$lang['set_random_representant'],
    160165   
    161166  'F_ACTION'=>add_session_id($form_action)
    162167  ));
    163  
     168
     169if ($category['nb_images'] > 0)
     170{
     171  $query = '
     172SELECT tn_ext,path
     173  FROM '.IMAGES_TABLE.'
     174  WHERE id = '.$category['representative_picture_id'].'
     175;';
     176  $row = mysql_fetch_array(pwg_query($query));
     177  $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     178  $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
     179  $url.= '&image_id='.$category['representative_picture_id'];
     180  $template->assign_block_vars('representant',
     181                               array('SRC' => $src,
     182                                     'URL' => $url));
     183}
     184
    164185if (!empty($category['dir']))
    165186{
  • trunk/admin/include/functions.php

    r632 r633  
    454454 
    455455  $query = '
    456 SELECT category_id, COUNT(image_id) AS count, max(date_available) AS date_last
     456SELECT category_id,
     457       COUNT(image_id) AS nb_images,
     458       MAX(date_available) AS date_last
    457459  FROM '.IMAGES_TABLE.'
    458460    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
     
    472474    array_push($datas, array('id' => $row['category_id'],
    473475                             'date_last' => $row['date_last'],
    474                              'count' => $row['count']));
     476                             'nb_images' => $row['nb_images']));
    475477  }
    476478  $fields = array('primary' => array('id'),
    477                   'update'  => array('date_last', 'count'));
     479                  'update'  => array('date_last', 'nb_images'));
    478480  mass_updates(CATEGORIES_TABLE, $fields, $datas);
    479481
     
    840842  $query = 'SELECT VERSION() AS version;';
    841843  $row = mysql_fetch_array(pwg_query($query));
    842   if (version_compare($row['version'],'4.0.4') < 0)
     844  if (count($datas) < 10 or version_compare($row['version'],'4.0.4') < 0)
    843845  {
    844846    // MySQL is prior to version 4.0.4, multi table update feature is not
    845847    // available
    846     echo 'MySQL is prior to version 4.0.4, multi table update feature is not available<br />';
    847848    foreach ($datas as $data)
    848849    {
     
    915916;';
    916917    pwg_query($query);
    917     mass_inserts($tablename, $all_fields, $datas);
     918    mass_inserts($tablename.'_temporary', $all_fields, $datas);
    918919    // update of images table by joining with temporary table
    919920    $query = '
     
    10931094  }
    10941095}
     1096
     1097/**
     1098 * set a new random representant to the categories
     1099 *
     1100 * @param array categories
     1101 */
     1102function set_random_representant($categories)
     1103{
     1104  $datas = array();
     1105  foreach ($categories as $category_id)
     1106  {
     1107    $query = '
     1108SELECT image_id
     1109  FROM '.IMAGE_CATEGORY_TABLE.'
     1110  WHERE category_id = '.$category_id.'
     1111  ORDER BY RAND()
     1112  LIMIT 0,1
     1113;';
     1114    list($representative) = mysql_fetch_array(pwg_query($query));
     1115    $data = array('id' => $category_id,
     1116                  'representative_picture_id' => $representative);
     1117    array_push($datas, $data);
     1118  }
     1119
     1120  $fields = array('primary' => array('id'),
     1121                  'update' => array('representative_picture_id'));
     1122  mass_updates(CATEGORIES_TABLE, $fields, $datas);
     1123}
    10951124?>
  • trunk/admin/update.php

    r625 r633  
    516516    pwg_query($query);
    517517
    518     // set a new representative element for this category
    519     $query = '
    520 SELECT image_id
    521   FROM '.IMAGE_CATEGORY_TABLE.'
    522   WHERE category_id = '.$category_id.'
    523   ORDER BY RAND()
    524   LIMIT 0,1
    525 ;';
    526     list($representative) = mysql_fetch_array(pwg_query($query));
    527     $query = '
    528 UPDATE '.CATEGORIES_TABLE.'
    529   SET representative_picture_id = '.$representative.'
    530   WHERE id = '.$category_id.'
    531 ;';
    532     pwg_query($query);
     518    set_random_representant(array($category_id));
    533519  }
    534520  return $output;
  • trunk/language/en_UK.iso-8859-1/admin.lang.php

    r632 r633  
    345345$lang['cat_list_virtual_category_added'] = 'virtual category added';
    346346$lang['cat_list_virtual_category_deleted'] = 'virtual category deleted';
     347$lang['set_random_representant'] = 'set new random representant';
    347348?>
  • trunk/template/default/admin/cat_modify.tpl

    r632 r633  
    66<form action="{F_ACTION}" method="POST">
    77<table style="width:100%;">
     8    <!-- BEGIN representant -->
     9    <tr>
     10      <td style="width:50%;" align="center">
     11        <a href="{representant.URL}"><img src="{representant.SRC}" alt="" class="miniature" /></a>
     12      </td>
     13      <td class="row1"><input type="submit" name="set_random_representant" value="{L_SET_RANDOM_REPRESENTANT}" class="bouton" /></td>
     14    </tr>
     15    <!-- END representant -->
    816    <!-- BEGIN server -->
    917    <tr>
Note: See TracChangeset for help on using the changeset viewer.