Index: /branches/release-1_3/admin/infos_images.php
===================================================================
--- /branches/release-1_3/admin/infos_images.php	(revision 257)
+++ /branches/release-1_3/admin/infos_images.php	(revision 258)
@@ -21,108 +21,105 @@
 include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' );
 //-------------------------------------------------------------- initialization
+$page['nb_image_page'] = 5;
+
 check_cat_id( $_GET['cat_id'] );
 if ( isset( $page['cat'] ) )
 {
 //--------------------------------------------------- update individual options
-  $query = 'SELECT id,file';
-  $query.= ' FROM '.PREFIX_TABLE.'images';
-  $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
-  $query.= ' WHERE category_id = '.$page['cat'];
-  $query.= ';';
-  $result = mysql_query( $query );
-  $i = 1;
-  while ( $row = mysql_fetch_array( $result ) )
-  {
-    $name          = 'name-'.$row['id'];
-    $author        = 'author-'.$row['id'];
-    $comment       = 'comment-'.$row['id'];
-    $date_creation = 'date_creation-'.$row['id'];
-    $keywords      = 'keywords-'.$row['id'];
-    if ( isset( $_POST[$name] ) )
-    {
-      $query = 'UPDATE '.PREFIX_TABLE.'images';
-
-      $query.= ' SET name = ';
-      if ( $_POST[$name] == '' )
-        $query.= 'NULL';
+  if ( isset( $_POST['submit'] ) )
+  {
+    $errors = array();
+    if ( isset( $_POST['associate'] ) )
+    {
+      // does the uppercat id exists in the database ?
+      if ( !is_numeric( $_POST['associate'] ) )
+      {
+        array_push( $errors, $lang['cat_unknown_id'] );
+      }
       else
-        $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
-
-      $query.= ', author = ';
-      if ( $_POST[$author] == '' )
-        $query.= 'NULL';
-      else
-        $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
-
-      $query.= ', comment = ';
-      if ( $_POST[$comment] == '' )
-        $query.= 'NULL';
-      else
-        $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
-
-      $query.= ', date_creation = ';
-      if ( check_date_format( $_POST[$date_creation] ) )
-        $query.= "'".date_convert( $_POST[$date_creation] )."'";
-      else if ( $_POST[$date_creation] == '' )
-        $query.= 'NULL';
-
-      $query.= ', keywords = ';
-      $keywords_array = get_keywords( $_POST[$keywords] );
-      if ( count( $keywords_array ) == 0 )
-        $query.= 'NULL';
-      else
-      {
-        $query.= "'";
-        foreach ( $keywords_array as $i => $keyword ) {
-          if ( $i > 0 ) $query.= ',';
-          $query.= $keyword;
-        }
-        $query.= "'";
-      }
-
-      $query.= ' WHERE id = '.$row['id'];
-      $query.= ';';
-      mysql_query( $query );
-    }
-    // add link to another category
-    if ( $_POST['check-'.$row['id']] == 1 )
-    {
-      $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
-      $query.= ' (image_id,category_id) VALUES';
-      $query.= ' ('.$row['id'].','.$_POST['associate'].')';
-      $query.= ';';
-      mysql_query( $query );
-    }
-  }
-  update_category( $_POST['associate'] );
+      {
+        $query = 'SELECT id';
+        $query.= ' FROM '.PREFIX_TABLE.'categories';
+        $query.= ' WHERE id = '.$_POST['associate'];
+        $query.= ';';
+        if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
+          array_push( $errors, $lang['cat_unknown_id'] );
+      }
+    }
+
+    $query = 'SELECT id,file';
+    $query.= ' FROM '.PREFIX_TABLE.'images';
+    $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+    $query.= ' WHERE category_id = '.$page['cat'];
+    $query.= ';';
+    $result = mysql_query( $query );
+    $i = 1;
+    while ( $row = mysql_fetch_array( $result ) )
+    {
+      $name          = 'name-'.$row['id'];
+      $author        = 'author-'.$row['id'];
+      $comment       = 'comment-'.$row['id'];
+      $date_creation = 'date_creation-'.$row['id'];
+      $keywords      = 'keywords-'.$row['id'];
+      if ( isset( $_POST[$name] ) )
+      {
+        $query = 'UPDATE '.PREFIX_TABLE.'images';
+
+        $query.= ' SET name = ';
+        if ( $_POST[$name] == '' )
+          $query.= 'NULL';
+        else
+          $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
+
+        $query.= ', author = ';
+        if ( $_POST[$author] == '' )
+          $query.= 'NULL';
+        else
+          $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
+
+        $query.= ', comment = ';
+        if ( $_POST[$comment] == '' )
+          $query.= 'NULL';
+        else
+          $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
+
+        $query.= ', date_creation = ';
+        if ( check_date_format( $_POST[$date_creation] ) )
+          $query.= "'".date_convert( $_POST[$date_creation] )."'";
+        else if ( $_POST[$date_creation] == '' )
+          $query.= 'NULL';
+
+        $query.= ', keywords = ';
+        $keywords_array = get_keywords( $_POST[$keywords] );
+        if ( count( $keywords_array ) == 0 )
+          $query.= 'NULL';
+        else
+        {
+          $query.= "'";
+          foreach ( $keywords_array as $i => $keyword ) {
+            if ( $i > 0 ) $query.= ',';
+            $query.= $keyword;
+          }
+          $query.= "'";
+        }
+
+        $query.= ' WHERE id = '.$row['id'];
+        $query.= ';';
+        mysql_query( $query );
+      }
+      // add link to another category
+      if ( $_POST['check-'.$row['id']] == 1 and count( $errors ) == 0 )
+      {
+        $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
+        $query.= ' (image_id,category_id) VALUES';
+        $query.= ' ('.$row['id'].','.$_POST['associate'].')';
+        $query.= ';';
+        mysql_query( $query );
+      }
+    }
+    update_category( $_POST['associate'] );
 //------------------------------------------------------ update general options
-  if ( $_POST['use_common_author'] == 1 )
-  {
-    $query = 'SELECT image_id';
-    $query.= ' FROM '.PREFIX_TABLE.'image_category';
-    $query.= ' WHERE category_id = '.$page['cat'];
-    $result = mysql_query( $query );
-    while ( $row = mysql_fetch_array( $result ) )
-    {
-      $query = 'UPDATE '.PREFIX_TABLE.'images';
-      if ( $_POST['author_cat'] == '' )
-      {
-        $query.= ' SET author = NULL';
-      }
-      else
-      {
-        $query.= ' SET author = ';
-        $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
-      }
-      $query.= ' WHERE id = '.$row['image_id'];
-      $query.= ';';
-      mysql_query( $query );
-    }
-  }
-  if ( $_POST['use_common_date_creation'] == 1 )
-  {
-    if ( check_date_format( $_POST['date_creation_cat'] ) )
-    {
-      $date = date_convert( $_POST['date_creation_cat'] );
+    if ( $_POST['use_common_author'] == 1 )
+    {
       $query = 'SELECT image_id';
       $query.= ' FROM '.PREFIX_TABLE.'image_category';
@@ -132,11 +129,12 @@
       {
         $query = 'UPDATE '.PREFIX_TABLE.'images';
-        if ( $_POST['date_creation_cat'] == '' )
-        {
-          $query.= ' SET date_creation = NULL';
-        }
-        else
-        {
-          $query.= " SET date_creation = '".$date."'";
+        if ( $_POST['author_cat'] == '' )
+        {
+          $query.= ' SET author = NULL';
+        }
+        else
+        {
+          $query.= ' SET author = ';
+          $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
         }
         $query.= ' WHERE id = '.$row['image_id'];
@@ -145,60 +143,84 @@
       }
     }
-    else
-    {
-      echo $lang['err_date'];
-    }
-  }
-  if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
-  {
-    $query = 'SELECT id,keywords';
-    $query.= ' FROM '.PREFIX_TABLE.'images';
-    $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
-    $query.= ' WHERE category_id = '.$page['cat'];
-    $query.= ';';
-    $result = mysql_query( $query );
-    while ( $row = mysql_fetch_array( $result ) )
-    {
-      $specific_keywords = explode( ',', $row['keywords'] );
-      $common_keywords   = get_keywords( $_POST['keywords_cat'] );
-      // first possiblity : adding the given keywords to all the pictures
-      if ( $_POST['common_keywords'] == 'add' )
-      {
-        $keywords = array_merge( $specific_keywords, $common_keywords );
-        $keywords = array_unique( $keywords );
-      }
-      // second possiblity : removing the given keywords from all pictures
-      // (without deleting the other specific keywords
-      if ( $_POST['common_keywords'] == 'remove' )
-      {
-        $keywords = array_diff( $specific_keywords, $common_keywords );
-      }
-      // cleaning the keywords array, sometimes, an empty value still remain
-      $keywords = array_remove( $keywords, '' );
-      // updating the picture with new keywords array
-      $query = 'UPDATE '.PREFIX_TABLE.'images';
-      $query.= ' SET keywords = ';
-      if ( count( $keywords ) == 0 )
-      {
-        $query.= 'NULL';
+    if ( $_POST['use_common_date_creation'] == 1 )
+    {
+      if ( check_date_format( $_POST['date_creation_cat'] ) )
+      {
+        $date = date_convert( $_POST['date_creation_cat'] );
+        $query = 'SELECT image_id';
+        $query.= ' FROM '.PREFIX_TABLE.'image_category';
+        $query.= ' WHERE category_id = '.$page['cat'];
+        $result = mysql_query( $query );
+        while ( $row = mysql_fetch_array( $result ) )
+        {
+          $query = 'UPDATE '.PREFIX_TABLE.'images';
+          if ( $_POST['date_creation_cat'] == '' )
+          {
+            $query.= ' SET date_creation = NULL';
+          }
+          else
+          {
+            $query.= " SET date_creation = '".$date."'";
+          }
+          $query.= ' WHERE id = '.$row['image_id'];
+          $query.= ';';
+          mysql_query( $query );
+        }
       }
       else
       {
-        $query.= '"';
-        $i = 0;
-        foreach ( $keywords as $keyword ) {
-          if ( $i++ > 0 ) $query.= ',';
-          $query.= $keyword;
-        }
-        $query.= '"';
-      }
-      $query.= ' WHERE id = '.$row['id'];
+        array_push( $errors, $lang['err_date'] );
+      }
+    }
+    if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
+    {
+      $query = 'SELECT id,keywords';
+      $query.= ' FROM '.PREFIX_TABLE.'images';
+      $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+      $query.= ' WHERE category_id = '.$page['cat'];
       $query.= ';';
-      mysql_query( $query );
+      $result = mysql_query( $query );
+      while ( $row = mysql_fetch_array( $result ) )
+      {
+        $specific_keywords = explode( ',', $row['keywords'] );
+        $common_keywords   = get_keywords( $_POST['keywords_cat'] );
+        // first possiblity : adding the given keywords to all the pictures
+        if ( $_POST['common_keywords'] == 'add' )
+        {
+          $keywords = array_merge( $specific_keywords, $common_keywords );
+          $keywords = array_unique( $keywords );
+        }
+        // second possiblity : removing the given keywords from all pictures
+        // (without deleting the other specific keywords
+        if ( $_POST['common_keywords'] == 'remove' )
+        {
+          $keywords = array_diff( $specific_keywords, $common_keywords );
+        }
+        // cleaning the keywords array, sometimes, an empty value still remain
+        $keywords = array_remove( $keywords, '' );
+        // updating the picture with new keywords array
+        $query = 'UPDATE '.PREFIX_TABLE.'images';
+        $query.= ' SET keywords = ';
+        if ( count( $keywords ) == 0 )
+        {
+          $query.= 'NULL';
+        }
+        else
+        {
+          $query.= '"';
+          $i = 0;
+          foreach ( $keywords as $keyword ) {
+            if ( $i++ > 0 ) $query.= ',';
+            $query.= $keyword;
+          }
+          $query.= '"';
+        }
+        $query.= ' WHERE id = '.$row['id'];
+        $query.= ';';
+        mysql_query( $query );
+      }
     }
   }
 //--------------------------------------------------------- form initialization
-  $page['nb_image_page'] = 5;
-
   if( !isset( $_GET['start'] )
       or !is_numeric( $_GET['start'] )
@@ -218,5 +240,4 @@
   }
   // retrieving category information
-  $page['plain_structure'] = get_plain_structure();
   $result = get_cat_info( $page['cat'] );
   $cat['name'] = $result['name'];
@@ -229,7 +250,19 @@
                 'infoimage_creation_date','keywords',
                 'infoimage_addtoall','infoimage_removefromall',
-                'infoimage_keyword_separation','infoimage_associate' );
+                'infoimage_keyword_separation','infoimage_associate',
+                'errors_title' );
   templatize_array( $tpl, 'lang', $sub );
   $vtp->setGlobalVar( $sub, 'user_template',   $user['template'] );
+//-------------------------------------------------------------- errors display
+if ( count( $errors ) != 0 )
+{
+  $vtp->addSession( $sub, 'errors' );
+  foreach ( $errors as $error ) {
+    $vtp->addSession( $sub, 'li' );
+    $vtp->setVar( $sub, 'li.content', $error );
+    $vtp->closeSession( $sub, 'li' );
+  }
+  $vtp->closeSession( $sub, 'errors' );
+}
 //------------------------------------------------------------------------ form
   $url = './admin.php?page=infos_images&amp;cat_id='.$page['cat'];
@@ -284,6 +317,27 @@
     $vtp->closeSession( $sub, 'picture' );
   }
-  $structure = create_structure( '', array() );
-  display_categories( $structure, '&nbsp;' );
+  // Virtualy associate a picture to a category
+  //
+  // We only show a List Of Values if the number of categories is less than
+  // $conf['max_LOV_categories']
+  $query = 'SELECT COUNT(id) AS nb_total_categories';
+  $query.= ' FROM '.PREFIX_TABLE.'categories';
+  $query.= ';';
+  $row = mysql_fetch_array( mysql_query( $query ) );
+  if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
+  {
+    $vtp->addSession( $sub, 'associate_LOV' );
+    $page['plain_structure'] = get_plain_structure( true );
+    $structure = create_structure( '', array() );
+    display_categories( $structure, '&nbsp;' );
+    $vtp->closeSession( $sub, 'associate_LOV' );
+  }
+  // else, we only display a small text field, we suppose the administrator
+  // knows the id of its category
+  else
+  {
+    $vtp->addSession( $sub, 'associate_text' );
+    $vtp->closeSession( $sub, 'associate_text' );
+  }
 }
 //----------------------------------------------------------- sending html code
Index: /branches/release-1_3/admin/picture_modify.php
===================================================================
--- /branches/release-1_3/admin/picture_modify.php	(revision 257)
+++ /branches/release-1_3/admin/picture_modify.php	(revision 258)
@@ -19,6 +19,4 @@
 
 include_once( './include/isadmin.inc.php' );
-//----------------------------------------- categories structure initialization
-$page['plain_structure'] = get_plain_structure();
 //--------------------------------------------------------- update informations
 $errors = array();
@@ -107,6 +105,26 @@
     }
   }
+  $associate_or_dissociate = false;
   // associate with a new category ?
-  if ( $_POST['associate'] != '-1' )
+  if ( $_POST['associate'] != '-1' and $_POST['associate'] != '' )
+  {
+    // does the uppercat id exists in the database ?
+    if ( !is_numeric( $_POST['associate'] ) )
+    {
+      array_push( $errors, $lang['cat_unknown_id'] );
+    }
+    else
+    {
+      $query = 'SELECT id';
+      $query.= ' FROM '.PREFIX_TABLE.'categories';
+      $query.= ' WHERE id = '.$_POST['associate'];
+      $query.= ';';
+      if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
+        array_push( $errors, $lang['cat_unknown_id'] );
+    }
+  }
+  if ( $_POST['associate'] != '-1'
+       and $_POST['associate'] != ''
+       and count( $errors ) == 0 )
   {
     $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
@@ -115,4 +133,5 @@
     $query.= ';';
     mysql_query( $query);
+    $associate_or_dissociate = true;
     update_category( $_POST['associate'] );
   }
@@ -133,6 +152,11 @@
       $query.= ';';
       mysql_query( $query );
+      $associate_or_dissociate = true;
       update_category( $row['category_id'] );
     }
+  }
+  if ( $associate_or_dissociate )
+  {
+    synchronize_all_users();
   }
 }
@@ -307,10 +331,30 @@
 }
 // associate to another category ?
-$vtp->addSession( $sub, 'associate_cat' );
-$vtp->setVar( $sub, 'associate_cat.value', '-1' );
-$vtp->setVar( $sub, 'associate_cat.content', '' );
-$vtp->closeSession( $sub, 'associate_cat' );
-$structure = create_structure( '', array() );
-display_categories( $structure, '&nbsp;' );
+//
+// We only show a List Of Values if the number of categories is less than
+// $conf['max_LOV_categories']
+$query = 'SELECT COUNT(id) AS nb_total_categories';
+$query.= ' FROM '.PREFIX_TABLE.'categories';
+$query.= ';';
+$row = mysql_fetch_array( mysql_query( $query ) );
+if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
+{
+  $vtp->addSession( $sub, 'associate_LOV' );
+  $vtp->addSession( $sub, 'associate_cat' );
+  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
+  $vtp->setVar( $sub, 'associate_cat.content', '' );
+  $vtp->closeSession( $sub, 'associate_cat' );
+  $page['plain_structure'] = get_plain_structure( true );
+  $structure = create_structure( '', array() );
+  display_categories( $structure, '&nbsp;' );
+  $vtp->closeSession( $sub, 'associate_LOV' );
+}
+// else, we only display a small text field, we suppose the administrator
+// knows the id of its category
+else
+{
+  $vtp->addSession( $sub, 'associate_text' );
+  $vtp->closeSession( $sub, 'associate_text' );
+}
 //----------------------------------------------------------- sending html code
 $vtp->Parse( $handle , 'sub', $sub );
