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

A category can have its representative picture

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.