Changeset 133


Ignore:
Timestamp:
Sep 19, 2003, 11:40:52 PM (21 years ago)
Author:
z0rglub
Message:

A category can have its representative picture

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r68 r133  
    292292
    293293// update_category updates calculated informations about a category :
    294 // date_last and nb_images
     294// date_last and nb_images. It also verifies that the representative picture
     295// is really linked to the category.
    295296function update_category( $id = 'all' )
    296297{
     
    334335    $query.= ';';
    335336    mysql_query( $query );
     337    // updating the representative_picture_id : if the representative
     338    // picture of the category is not any more linked to the category, we
     339    // have to set representative_picture_id to NULL
     340    $query = 'SELECT representative_picture_id';
     341    $query.= ' FROM '.PREFIX_TABLE.'categories';
     342    $query.= ' WHERE id = '.$id;
     343    $row = mysql_fetch_array( mysql_query( $query ) );
     344    // if the category has no representative picture (ie
     345    // representative_picture_id == NULL) we don't update anything
     346    if ( $row['representative_picture_id'] != '' )
     347    {
     348      $query = 'SELECT image_id';
     349      $query.= ' FROM '.PREFIX_TABLE.'image_category';
     350      $query.= ' WHERE category_id = '.$id;
     351      $query.= ' AND image_id = '.$row['representative_picture_id'];
     352      $query.= ';';
     353      $result = mysql_query( $query );
     354      if ( mysql_num_rows( $result ) == 0 )
     355      {
     356        $query = 'UPDATE '.PREFIX_TABLE.'categories';
     357        $query.= ' SET representative_picture_id = NULL';
     358        $query.= ' WHERE id = '.$id;
     359        $query.= ';';
     360        mysql_query( $query );
     361      }
     362    }
    336363  }
    337364}
  • trunk/admin/picture_modify.php

    r61 r133  
    7474  $query.= ';';
    7575  mysql_query( $query );
     76  // make the picture representative of a category ?
     77  $query = 'SELECT DISTINCT(category_id) as category_id';
     78  $query.= ',representative_picture_id';
     79  $query.= ' FROM '.PREFIX_TABLE.'image_category AS ic';
     80  $query.= ', '.PREFIX_TABLE.'categories AS c';
     81  $query.= ' WHERE c.id = ic.category_id';
     82  $query.= ' AND image_id = '.$_GET['image_id'];
     83  $query.= ';';
     84  $result = mysql_query( $query );
     85  while ( $row = mysql_fetch_array( $result ) )
     86  {
     87    // if the user ask the picture to be the representative picture of its
     88    // category, the category is updated in the database (without wondering
     89    // if this picture was already the representative one)
     90    if ( $_POST['representative-'.$row['category_id']] == 1 )
     91    {
     92      $query = 'UPDATE '.PREFIX_TABLE.'categories';
     93      $query.= ' SET representative_picture_id = '.$_GET['image_id'];
     94      $query.= ' WHERE id = '.$row['category_id'];
     95      $query.= ';';
     96      mysql_query( $query );
     97    }
     98    // if the user ask this picture to be not any more the representative,
     99    // we have to set the representative_picture_id of this category to NULL
     100    else if ( $row['representative_picture_id'] == $_GET['image_id'] )
     101    {
     102      $query = 'UPDATE '.PREFIX_TABLE.'categories';
     103      $query.= ' SET representative_picture_id = NULL';
     104      $query.= ' WHERE id = '.$row['category_id'];
     105      $query.= ';';
     106      mysql_query( $query );
     107    }
     108  }
    76109  // associate with a new category ?
    77110  if ( $_POST['associate'] != '-1' )
     
    112145              'author','creation_date','keywords','comment', 'upload_name',
    113146              'dissociate','categories','infoimage_associate',
    114               'cat_image_info' );
     147              'cat_image_info','category_representative' );
    115148templatize_array( $tpl, 'lang', $sub );
    116149$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
     
    206239  $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
    207240}
     241$vtp->setVar( $sub, 'linked_category.id', $row['storage_category_id'] );
     242if ( $result['representative_picture_id'] == $_GET['image_id'] )
     243{
     244  $vtp->setVar( $sub, 'linked_category.representative_checked',
     245                ' checked="checked"' );
     246}
    208247$vtp->closeSession( $sub, 'linked_category' );
    209248// retrieving all the linked categories
    210249$query = 'SELECT DISTINCT(category_id) as category_id,status,visible';
     250$query.= ',representative_picture_id';
    211251$query.= ' FROM '.PREFIX_TABLE.'image_category';
    212252$query.= ','.PREFIX_TABLE.'categories';
     
    219259{
    220260  $vtp->addSession( $sub, 'linked_category' );
     261  $vtp->setVar( $sub, 'linked_category.id', $row['category_id'] );
    221262
    222263  $vtp->addSession( $sub, 'checkbox' );
     
    250291  }
    251292
     293  if ( $row['representative_picture_id'] == $_GET['image_id'] )
     294  {
     295    $vtp->setVar( $sub, 'linked_category.representative_checked',
     296                  ' checked="checked"' );
     297  }
     298 
    252299  $vtp->closeSession( $sub, 'linked_category' );
    253300}
  • trunk/include/functions_category.inc.php

    r83 r133  
    289289               
    290290  $query = 'SELECT nb_images,id_uppercat,comment,site_id,galleries_url,dir';
    291   $query.= ',date_last,uploadable,status,visible';
     291  $query.= ',date_last,uploadable,status,visible,representative_picture_id';
    292292  $query.= ' FROM '.PREFIX_TABLE.'categories AS a';
    293293  $query.= ', '.PREFIX_TABLE.'sites AS b';
     
    304304  $cat['status']      = $row['status'];
    305305  $cat['visible']     = get_boolean( $row['visible'] );
     306  $cat['representative_picture_id'] = $row['representative_picture_id'];
    306307
    307308  $cat['name'] = array();
  • trunk/language/francais.php

    r128 r133  
    3434$lang['default'] = 'défaut';
    3535$lang['comments'] = 'commentaires';
     36$lang['category_representative'] = 'représentant';
    3637// end version 1.3
    3738
  • trunk/template/default/admin/picture_modify.vtp

    r74 r133  
    6666                <!--VTP_linked_category-->
    6767                <tr>
    68                   <td><!--VTP_checkbox--><input type="checkbox" name="dissociate-{#id}" value="1" /><!--/VTP_checkbox--><a href="{#url}">{#name}</a> [ <a href="{#infos_images_link}">{#cat_image_info}</a> ] {#private} {#invisible}
     68                  <td><!--VTP_checkbox--><input type="checkbox" name="dissociate-{#id}" value="1" /><!--/VTP_checkbox--><a href="{#url}">{#name}</a> [ <a href="{#infos_images_link}">{#cat_image_info}</a> ] {#private} {#invisible} [ <input type="checkbox" name="representative-{#id}" value="1"{#representative_checked} /> {#category_representative} ]
    6969                </tr>
    7070                <!--/VTP_linked_category-->
Note: See TracChangeset for help on using the changeset viewer.