Changeset 258


Ignore:
Timestamp:
Jan 3, 2004, 10:36:59 PM (20 years ago)
Author:
z0rglub
Message:

for virtual category to picture association, if the number of categories is
more than $confmax_LOV_categories, we only show a text box asking parent
category id

Location:
branches/release-1_3/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/release-1_3/admin/infos_images.php

    r138 r258  
    2121include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' );
    2222//-------------------------------------------------------------- initialization
     23$page['nb_image_page'] = 5;
     24
    2325check_cat_id( $_GET['cat_id'] );
    2426if ( isset( $page['cat'] ) )
    2527{
    2628//--------------------------------------------------- update individual options
    27   $query = 'SELECT id,file';
    28   $query.= ' FROM '.PREFIX_TABLE.'images';
    29   $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
    30   $query.= ' WHERE category_id = '.$page['cat'];
    31   $query.= ';';
    32   $result = mysql_query( $query );
    33   $i = 1;
    34   while ( $row = mysql_fetch_array( $result ) )
    35   {
    36     $name          = 'name-'.$row['id'];
    37     $author        = 'author-'.$row['id'];
    38     $comment       = 'comment-'.$row['id'];
    39     $date_creation = 'date_creation-'.$row['id'];
    40     $keywords      = 'keywords-'.$row['id'];
    41     if ( isset( $_POST[$name] ) )
    42     {
    43       $query = 'UPDATE '.PREFIX_TABLE.'images';
    44 
    45       $query.= ' SET name = ';
    46       if ( $_POST[$name] == '' )
    47         $query.= 'NULL';
     29  if ( isset( $_POST['submit'] ) )
     30  {
     31    $errors = array();
     32    if ( isset( $_POST['associate'] ) )
     33    {
     34      // does the uppercat id exists in the database ?
     35      if ( !is_numeric( $_POST['associate'] ) )
     36      {
     37        array_push( $errors, $lang['cat_unknown_id'] );
     38      }
    4839      else
    49         $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
    50 
    51       $query.= ', author = ';
    52       if ( $_POST[$author] == '' )
    53         $query.= 'NULL';
    54       else
    55         $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
    56 
    57       $query.= ', comment = ';
    58       if ( $_POST[$comment] == '' )
    59         $query.= 'NULL';
    60       else
    61         $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
    62 
    63       $query.= ', date_creation = ';
    64       if ( check_date_format( $_POST[$date_creation] ) )
    65         $query.= "'".date_convert( $_POST[$date_creation] )."'";
    66       else if ( $_POST[$date_creation] == '' )
    67         $query.= 'NULL';
    68 
    69       $query.= ', keywords = ';
    70       $keywords_array = get_keywords( $_POST[$keywords] );
    71       if ( count( $keywords_array ) == 0 )
    72         $query.= 'NULL';
    73       else
    74       {
    75         $query.= "'";
    76         foreach ( $keywords_array as $i => $keyword ) {
    77           if ( $i > 0 ) $query.= ',';
    78           $query.= $keyword;
    79         }
    80         $query.= "'";
    81       }
    82 
    83       $query.= ' WHERE id = '.$row['id'];
    84       $query.= ';';
    85       mysql_query( $query );
    86     }
    87     // add link to another category
    88     if ( $_POST['check-'.$row['id']] == 1 )
    89     {
    90       $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
    91       $query.= ' (image_id,category_id) VALUES';
    92       $query.= ' ('.$row['id'].','.$_POST['associate'].')';
    93       $query.= ';';
    94       mysql_query( $query );
    95     }
    96   }
    97   update_category( $_POST['associate'] );
     40      {
     41        $query = 'SELECT id';
     42        $query.= ' FROM '.PREFIX_TABLE.'categories';
     43        $query.= ' WHERE id = '.$_POST['associate'];
     44        $query.= ';';
     45        if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
     46          array_push( $errors, $lang['cat_unknown_id'] );
     47      }
     48    }
     49
     50    $query = 'SELECT id,file';
     51    $query.= ' FROM '.PREFIX_TABLE.'images';
     52    $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
     53    $query.= ' WHERE category_id = '.$page['cat'];
     54    $query.= ';';
     55    $result = mysql_query( $query );
     56    $i = 1;
     57    while ( $row = mysql_fetch_array( $result ) )
     58    {
     59      $name          = 'name-'.$row['id'];
     60      $author        = 'author-'.$row['id'];
     61      $comment       = 'comment-'.$row['id'];
     62      $date_creation = 'date_creation-'.$row['id'];
     63      $keywords      = 'keywords-'.$row['id'];
     64      if ( isset( $_POST[$name] ) )
     65      {
     66        $query = 'UPDATE '.PREFIX_TABLE.'images';
     67
     68        $query.= ' SET name = ';
     69        if ( $_POST[$name] == '' )
     70          $query.= 'NULL';
     71        else
     72          $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
     73
     74        $query.= ', author = ';
     75        if ( $_POST[$author] == '' )
     76          $query.= 'NULL';
     77        else
     78          $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
     79
     80        $query.= ', comment = ';
     81        if ( $_POST[$comment] == '' )
     82          $query.= 'NULL';
     83        else
     84          $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
     85
     86        $query.= ', date_creation = ';
     87        if ( check_date_format( $_POST[$date_creation] ) )
     88          $query.= "'".date_convert( $_POST[$date_creation] )."'";
     89        else if ( $_POST[$date_creation] == '' )
     90          $query.= 'NULL';
     91
     92        $query.= ', keywords = ';
     93        $keywords_array = get_keywords( $_POST[$keywords] );
     94        if ( count( $keywords_array ) == 0 )
     95          $query.= 'NULL';
     96        else
     97        {
     98          $query.= "'";
     99          foreach ( $keywords_array as $i => $keyword ) {
     100            if ( $i > 0 ) $query.= ',';
     101            $query.= $keyword;
     102          }
     103          $query.= "'";
     104        }
     105
     106        $query.= ' WHERE id = '.$row['id'];
     107        $query.= ';';
     108        mysql_query( $query );
     109      }
     110      // add link to another category
     111      if ( $_POST['check-'.$row['id']] == 1 and count( $errors ) == 0 )
     112      {
     113        $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
     114        $query.= ' (image_id,category_id) VALUES';
     115        $query.= ' ('.$row['id'].','.$_POST['associate'].')';
     116        $query.= ';';
     117        mysql_query( $query );
     118      }
     119    }
     120    update_category( $_POST['associate'] );
    98121//------------------------------------------------------ update general options
    99   if ( $_POST['use_common_author'] == 1 )
    100   {
    101     $query = 'SELECT image_id';
    102     $query.= ' FROM '.PREFIX_TABLE.'image_category';
    103     $query.= ' WHERE category_id = '.$page['cat'];
    104     $result = mysql_query( $query );
    105     while ( $row = mysql_fetch_array( $result ) )
    106     {
    107       $query = 'UPDATE '.PREFIX_TABLE.'images';
    108       if ( $_POST['author_cat'] == '' )
    109       {
    110         $query.= ' SET author = NULL';
    111       }
    112       else
    113       {
    114         $query.= ' SET author = ';
    115         $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
    116       }
    117       $query.= ' WHERE id = '.$row['image_id'];
    118       $query.= ';';
    119       mysql_query( $query );
    120     }
    121   }
    122   if ( $_POST['use_common_date_creation'] == 1 )
    123   {
    124     if ( check_date_format( $_POST['date_creation_cat'] ) )
    125     {
    126       $date = date_convert( $_POST['date_creation_cat'] );
     122    if ( $_POST['use_common_author'] == 1 )
     123    {
    127124      $query = 'SELECT image_id';
    128125      $query.= ' FROM '.PREFIX_TABLE.'image_category';
     
    132129      {
    133130        $query = 'UPDATE '.PREFIX_TABLE.'images';
    134         if ( $_POST['date_creation_cat'] == '' )
    135         {
    136           $query.= ' SET date_creation = NULL';
    137         }
    138         else
    139         {
    140           $query.= " SET date_creation = '".$date."'";
     131        if ( $_POST['author_cat'] == '' )
     132        {
     133          $query.= ' SET author = NULL';
     134        }
     135        else
     136        {
     137          $query.= ' SET author = ';
     138          $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
    141139        }
    142140        $query.= ' WHERE id = '.$row['image_id'];
     
    145143      }
    146144    }
    147     else
    148     {
    149       echo $lang['err_date'];
    150     }
    151   }
    152   if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
    153   {
    154     $query = 'SELECT id,keywords';
    155     $query.= ' FROM '.PREFIX_TABLE.'images';
    156     $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
    157     $query.= ' WHERE category_id = '.$page['cat'];
    158     $query.= ';';
    159     $result = mysql_query( $query );
    160     while ( $row = mysql_fetch_array( $result ) )
    161     {
    162       $specific_keywords = explode( ',', $row['keywords'] );
    163       $common_keywords   = get_keywords( $_POST['keywords_cat'] );
    164       // first possiblity : adding the given keywords to all the pictures
    165       if ( $_POST['common_keywords'] == 'add' )
    166       {
    167         $keywords = array_merge( $specific_keywords, $common_keywords );
    168         $keywords = array_unique( $keywords );
    169       }
    170       // second possiblity : removing the given keywords from all pictures
    171       // (without deleting the other specific keywords
    172       if ( $_POST['common_keywords'] == 'remove' )
    173       {
    174         $keywords = array_diff( $specific_keywords, $common_keywords );
    175       }
    176       // cleaning the keywords array, sometimes, an empty value still remain
    177       $keywords = array_remove( $keywords, '' );
    178       // updating the picture with new keywords array
    179       $query = 'UPDATE '.PREFIX_TABLE.'images';
    180       $query.= ' SET keywords = ';
    181       if ( count( $keywords ) == 0 )
    182       {
    183         $query.= 'NULL';
     145    if ( $_POST['use_common_date_creation'] == 1 )
     146    {
     147      if ( check_date_format( $_POST['date_creation_cat'] ) )
     148      {
     149        $date = date_convert( $_POST['date_creation_cat'] );
     150        $query = 'SELECT image_id';
     151        $query.= ' FROM '.PREFIX_TABLE.'image_category';
     152        $query.= ' WHERE category_id = '.$page['cat'];
     153        $result = mysql_query( $query );
     154        while ( $row = mysql_fetch_array( $result ) )
     155        {
     156          $query = 'UPDATE '.PREFIX_TABLE.'images';
     157          if ( $_POST['date_creation_cat'] == '' )
     158          {
     159            $query.= ' SET date_creation = NULL';
     160          }
     161          else
     162          {
     163            $query.= " SET date_creation = '".$date."'";
     164          }
     165          $query.= ' WHERE id = '.$row['image_id'];
     166          $query.= ';';
     167          mysql_query( $query );
     168        }
    184169      }
    185170      else
    186171      {
    187         $query.= '"';
    188         $i = 0;
    189         foreach ( $keywords as $keyword ) {
    190           if ( $i++ > 0 ) $query.= ',';
    191           $query.= $keyword;
    192         }
    193         $query.= '"';
    194       }
    195       $query.= ' WHERE id = '.$row['id'];
     172        array_push( $errors, $lang['err_date'] );
     173      }
     174    }
     175    if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
     176    {
     177      $query = 'SELECT id,keywords';
     178      $query.= ' FROM '.PREFIX_TABLE.'images';
     179      $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
     180      $query.= ' WHERE category_id = '.$page['cat'];
    196181      $query.= ';';
    197       mysql_query( $query );
     182      $result = mysql_query( $query );
     183      while ( $row = mysql_fetch_array( $result ) )
     184      {
     185        $specific_keywords = explode( ',', $row['keywords'] );
     186        $common_keywords   = get_keywords( $_POST['keywords_cat'] );
     187        // first possiblity : adding the given keywords to all the pictures
     188        if ( $_POST['common_keywords'] == 'add' )
     189        {
     190          $keywords = array_merge( $specific_keywords, $common_keywords );
     191          $keywords = array_unique( $keywords );
     192        }
     193        // second possiblity : removing the given keywords from all pictures
     194        // (without deleting the other specific keywords
     195        if ( $_POST['common_keywords'] == 'remove' )
     196        {
     197          $keywords = array_diff( $specific_keywords, $common_keywords );
     198        }
     199        // cleaning the keywords array, sometimes, an empty value still remain
     200        $keywords = array_remove( $keywords, '' );
     201        // updating the picture with new keywords array
     202        $query = 'UPDATE '.PREFIX_TABLE.'images';
     203        $query.= ' SET keywords = ';
     204        if ( count( $keywords ) == 0 )
     205        {
     206          $query.= 'NULL';
     207        }
     208        else
     209        {
     210          $query.= '"';
     211          $i = 0;
     212          foreach ( $keywords as $keyword ) {
     213            if ( $i++ > 0 ) $query.= ',';
     214            $query.= $keyword;
     215          }
     216          $query.= '"';
     217        }
     218        $query.= ' WHERE id = '.$row['id'];
     219        $query.= ';';
     220        mysql_query( $query );
     221      }
    198222    }
    199223  }
    200224//--------------------------------------------------------- form initialization
    201   $page['nb_image_page'] = 5;
    202 
    203225  if( !isset( $_GET['start'] )
    204226      or !is_numeric( $_GET['start'] )
     
    218240  }
    219241  // retrieving category information
    220   $page['plain_structure'] = get_plain_structure();
    221242  $result = get_cat_info( $page['cat'] );
    222243  $cat['name'] = $result['name'];
     
    229250                'infoimage_creation_date','keywords',
    230251                'infoimage_addtoall','infoimage_removefromall',
    231                 'infoimage_keyword_separation','infoimage_associate' );
     252                'infoimage_keyword_separation','infoimage_associate',
     253                'errors_title' );
    232254  templatize_array( $tpl, 'lang', $sub );
    233255  $vtp->setGlobalVar( $sub, 'user_template',   $user['template'] );
     256//-------------------------------------------------------------- errors display
     257if ( count( $errors ) != 0 )
     258{
     259  $vtp->addSession( $sub, 'errors' );
     260  foreach ( $errors as $error ) {
     261    $vtp->addSession( $sub, 'li' );
     262    $vtp->setVar( $sub, 'li.content', $error );
     263    $vtp->closeSession( $sub, 'li' );
     264  }
     265  $vtp->closeSession( $sub, 'errors' );
     266}
    234267//------------------------------------------------------------------------ form
    235268  $url = './admin.php?page=infos_images&cat_id='.$page['cat'];
     
    284317    $vtp->closeSession( $sub, 'picture' );
    285318  }
    286   $structure = create_structure( '', array() );
    287   display_categories( $structure, ' ' );
     319  // Virtualy associate a picture to a category
     320  //
     321  // We only show a List Of Values if the number of categories is less than
     322  // $conf['max_LOV_categories']
     323  $query = 'SELECT COUNT(id) AS nb_total_categories';
     324  $query.= ' FROM '.PREFIX_TABLE.'categories';
     325  $query.= ';';
     326  $row = mysql_fetch_array( mysql_query( $query ) );
     327  if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
     328  {
     329    $vtp->addSession( $sub, 'associate_LOV' );
     330    $page['plain_structure'] = get_plain_structure( true );
     331    $structure = create_structure( '', array() );
     332    display_categories( $structure, '&nbsp;' );
     333    $vtp->closeSession( $sub, 'associate_LOV' );
     334  }
     335  // else, we only display a small text field, we suppose the administrator
     336  // knows the id of its category
     337  else
     338  {
     339    $vtp->addSession( $sub, 'associate_text' );
     340    $vtp->closeSession( $sub, 'associate_text' );
     341  }
    288342}
    289343//----------------------------------------------------------- sending html code
  • branches/release-1_3/admin/picture_modify.php

    r133 r258  
    1919
    2020include_once( './include/isadmin.inc.php' );
    21 //----------------------------------------- categories structure initialization
    22 $page['plain_structure'] = get_plain_structure();
    2321//--------------------------------------------------------- update informations
    2422$errors = array();
     
    107105    }
    108106  }
     107  $associate_or_dissociate = false;
    109108  // associate with a new category ?
    110   if ( $_POST['associate'] != '-1' )
     109  if ( $_POST['associate'] != '-1' and $_POST['associate'] != '' )
     110  {
     111    // does the uppercat id exists in the database ?
     112    if ( !is_numeric( $_POST['associate'] ) )
     113    {
     114      array_push( $errors, $lang['cat_unknown_id'] );
     115    }
     116    else
     117    {
     118      $query = 'SELECT id';
     119      $query.= ' FROM '.PREFIX_TABLE.'categories';
     120      $query.= ' WHERE id = '.$_POST['associate'];
     121      $query.= ';';
     122      if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
     123        array_push( $errors, $lang['cat_unknown_id'] );
     124    }
     125  }
     126  if ( $_POST['associate'] != '-1'
     127       and $_POST['associate'] != ''
     128       and count( $errors ) == 0 )
    111129  {
    112130    $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
     
    115133    $query.= ';';
    116134    mysql_query( $query);
     135    $associate_or_dissociate = true;
    117136    update_category( $_POST['associate'] );
    118137  }
     
    133152      $query.= ';';
    134153      mysql_query( $query );
     154      $associate_or_dissociate = true;
    135155      update_category( $row['category_id'] );
    136156    }
     157  }
     158  if ( $associate_or_dissociate )
     159  {
     160    synchronize_all_users();
    137161  }
    138162}
     
    307331}
    308332// associate to another category ?
    309 $vtp->addSession( $sub, 'associate_cat' );
    310 $vtp->setVar( $sub, 'associate_cat.value', '-1' );
    311 $vtp->setVar( $sub, 'associate_cat.content', '' );
    312 $vtp->closeSession( $sub, 'associate_cat' );
    313 $structure = create_structure( '', array() );
    314 display_categories( $structure, '&nbsp;' );
     333//
     334// We only show a List Of Values if the number of categories is less than
     335// $conf['max_LOV_categories']
     336$query = 'SELECT COUNT(id) AS nb_total_categories';
     337$query.= ' FROM '.PREFIX_TABLE.'categories';
     338$query.= ';';
     339$row = mysql_fetch_array( mysql_query( $query ) );
     340if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
     341{
     342  $vtp->addSession( $sub, 'associate_LOV' );
     343  $vtp->addSession( $sub, 'associate_cat' );
     344  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
     345  $vtp->setVar( $sub, 'associate_cat.content', '' );
     346  $vtp->closeSession( $sub, 'associate_cat' );
     347  $page['plain_structure'] = get_plain_structure( true );
     348  $structure = create_structure( '', array() );
     349  display_categories( $structure, '&nbsp;' );
     350  $vtp->closeSession( $sub, 'associate_LOV' );
     351}
     352// else, we only display a small text field, we suppose the administrator
     353// knows the id of its category
     354else
     355{
     356  $vtp->addSession( $sub, 'associate_text' );
     357  $vtp->closeSession( $sub, 'associate_text' );
     358}
    315359//----------------------------------------------------------- sending html code
    316360$vtp->Parse( $handle , 'sub', $sub );
Note: See TracChangeset for help on using the changeset viewer.