Index: /trunk/admin/cat_modify.php
===================================================================
--- /trunk/admin/cat_modify.php	(revision 25018)
+++ /trunk/admin/cat_modify.php	(revision 25019)
@@ -115,12 +115,11 @@
 if (isset($_POST['submit']))
 {
-  $data =
-    array(
-      'id' => $_GET['cat_id'],
-      'name' => @$_POST['name'],
-      'comment' =>
-        $conf['allow_html_descriptions'] ?
-          @$_POST['comment'] : strip_tags(@$_POST['comment']),
-      );
+  $data = array(
+    'id' => $_GET['cat_id'],
+    'name' => @$_POST['name'],
+    'comment' =>
+      $conf['allow_html_descriptions'] ?
+        @$_POST['comment'] : strip_tags(@$_POST['comment']),
+    );
      
   if ($conf['activate_comments'])
@@ -128,12 +127,9 @@
     $data['commentable'] = isset($_POST['commentable'])?$_POST['commentable']:'false';
   }
-
-  mass_updates(
+  
+  single_update(
     CATEGORIES_TABLE,
-    array(
-      'primary' => array('id'),
-      'update' => array_diff(array_keys($data), array('id'))
-      ),
-    array($data)
+    $data,
+    array('id' => $data['id'])
     );
 
Index: /trunk/admin/include/functions.php
===================================================================
--- /trunk/admin/include/functions.php	(revision 25018)
+++ /trunk/admin/include/functions.php	(revision 25019)
@@ -1817,12 +1817,9 @@
   if (count($existing_tags) == 0)
   {
-    mass_inserts(
+    single_insert(
       TAGS_TABLE,
-      array('name', 'url_name'),
       array(
-        array(
-          'name' => $tag_name,
-          'url_name' => trigger_event('render_tag_url', $tag_name),
-          )
+        'name' => $tag_name,
+        'url_name' => trigger_event('render_tag_url', $tag_name),
         )
       );
@@ -1831,8 +1828,5 @@
 
     return array(
-      'info' => sprintf(
-        l10n('Tag "%s" was added'),
-        stripslashes($tag_name)
-        ),
+      'info' => l10n('Tag "%s" was added', stripslashes($tag_name)),
       'id' => $inserted_id,
       );
@@ -1841,8 +1835,5 @@
   {
     return array(
-      'error' => sprintf(
-        l10n('Tag "%s" already exists'),
-        stripslashes($tag_name)
-        )
+      'error' => l10n('Tag "%s" already exists', stripslashes($tag_name))
       );
   }
Index: /trunk/admin/picture_modify.php
===================================================================
--- /trunk/admin/picture_modify.php	(revision 25018)
+++ /trunk/admin/picture_modify.php	(revision 25019)
@@ -155,11 +155,8 @@
   }
 
-  mass_updates(
+  single_update(
     IMAGES_TABLE,
-    array(
-      'primary' => array('id'),
-      'update' => array_diff(array_keys($data), array('id'))
-      ),
-    array($data)
+    $data,
+    array('id' => $data['id'])
     );
 
Index: /trunk/admin/tags.php
===================================================================
--- /trunk/admin/tags.php	(revision 25018)
+++ /trunk/admin/tags.php	(revision 25019)
@@ -130,14 +130,12 @@
       else if (!empty($tag_name))
       {
-        mass_inserts(
+        single_insert(
           TAGS_TABLE,
-          array('name', 'url_name'),
           array(
-            array(
-              'name' => $tag_name,
-              'url_name' => trigger_event('render_tag_url', $tag_name),
-              )
+            'name' => $tag_name,
+            'url_name' => trigger_event('render_tag_url', $tag_name),
             )
           );
+
         $query = '
         SELECT id
@@ -147,4 +145,5 @@
         $destination_tag = array_from_query($query, 'id');
         $destination_tag_id = $destination_tag[0];
+
         $query = '
         SELECT
@@ -154,4 +153,5 @@
         ;';
         $destination_tag_image_ids = array_from_query($query, 'image_id');
+
         $inserts = array();
         foreach ($destination_tag_image_ids as $image_id)
@@ -180,4 +180,5 @@
     }
   }
+
   mass_updates(
     TAGS_TABLE,
@@ -324,32 +325,13 @@
 if (isset($_POST['add']) and !empty($_POST['add_tag']))
 {
-  $tag_name = $_POST['add_tag'];
-
-  // does the tag already exists?
-  $query = '
-SELECT id
-  FROM '.TAGS_TABLE.'
-  WHERE name = \''.$tag_name.'\'
-;';
-  $existing_tags = array_from_query($query, 'id');
-
-  if (count($existing_tags) == 0)
-  {
-    mass_inserts(
-      TAGS_TABLE,
-      array('name', 'url_name'),
-      array(
-        array(
-          'name' => $tag_name,
-          'url_name' => trigger_event('render_tag_url', $tag_name),
-          )
-        )
-      );
-
-    $page['infos'][] = l10n('Tag "%s" was added', stripslashes($tag_name));
+  $ret = create_tag($_POST['add_tag']);
+  
+  if (isset($ret['error']))
+  {
+    $page['errors'][] = $ret['error'];
   }
   else
   {
-    $page['errors'][] = l10n('Tag "%s" already exists', stripslashes($tag_name));
+    $page['infos'][] = $ret['info'];
   }
 }
Index: /trunk/include/functions_user.inc.php
===================================================================
--- /trunk/include/functions_user.inc.php	(revision 25018)
+++ /trunk/include/functions_user.inc.php	(revision 25019)
@@ -187,5 +187,5 @@
         );
 
-    mass_inserts(USERS_TABLE, array_keys($insert), array($insert));
+    single_insert(USERS_TABLE, $insert);
 
     // Assign by default groups
@@ -436,12 +436,10 @@
       // insert. This may happen when cache needs refresh and that Piwigo is
       // called "very simultaneously".
-      mass_inserts
-      (
+      mass_inserts(
         USER_CACHE_CATEGORIES_TABLE,
-        array
-        (
+        array(
           'user_id', 'cat_id',
           'date_last', 'max_date_last', 'nb_images', 'count_images', 'nb_categories', 'count_categories'
-        ),
+          ),
         $user_cache_cats,
         array('ignore' => true)
Index: /trunk/include/ws_functions.inc.php
===================================================================
--- /trunk/include/ws_functions.inc.php	(revision 25018)
+++ /trunk/include/ws_functions.inc.php	(revision 25019)
@@ -406,6 +406,9 @@
   if (count($datas))
   {
-    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
-    mass_inserts(CADDIE_TABLE, array('element_id','user_id'), $datas);
+    mass_inserts(
+      CADDIE_TABLE,
+      array('element_id','user_id'),
+      $datas
+      );
   }
   return count($datas);
@@ -1727,6 +1730,4 @@
   if ($params['image_id'] > 0)
   {
-    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
-
     $query='
 SELECT *
@@ -1885,6 +1886,4 @@
   if ($params['image_id'] > 0)
   {
-    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
-
     $query='
 SELECT *
@@ -1936,19 +1935,17 @@
   {
     $update['id'] = $image_id;
-
+    
+    single_update(
+      IMAGES_TABLE,
+      $update,
+      array('id', $update['id'])
+      );
+  }
+
+
+  if (isset($params['tags']) and !empty($params['tags']))
+  {
     include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
-    mass_updates(
-      IMAGES_TABLE,
-      array(
-        'primary' => array('id'),
-        'update'  => array_diff(array_keys($update), array('id'))
-        ),
-      array($update)
-      );
-  }
-
-
-  if (isset($params['tags']) and !empty($params['tags']))
-  {
+    
     $tag_ids = array();
     if (is_array($params['tags']))
@@ -2565,11 +2562,8 @@
     $update['id'] = $params['image_id'];
 
-    mass_updates(
+    single_update(
       IMAGES_TABLE,
-      array(
-        'primary' => array('id'),
-        'update'  => array_diff(array_keys($update), array('id'))
-        ),
-      array($update)
+      $update,
+      array('id', $update['id'])
       );
   }
@@ -2806,5 +2800,4 @@
   }
 
-  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
   mass_inserts(
     IMAGE_CATEGORY_TABLE,
@@ -2813,4 +2806,5 @@
     );
 
+  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
   update_category($new_cat_ids);
 }
@@ -2861,15 +2855,10 @@
   if ($perform_update)
   {
-    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
-    mass_updates(
+    single_update(
       CATEGORIES_TABLE,
-      array(
-        'primary' => array('id'),
-        'update'  => array_diff(array_keys($update), array('id'))
-        ),
-      array($update)
+      $update,
+      array('id', $update['id'])
       );
   }
-
 }
 
