Index: /trunk/admin/element_set_global.php
===================================================================
--- /trunk/admin/element_set_global.php	(revision 6872)
+++ /trunk/admin/element_set_global.php	(revision 6873)
@@ -78,22 +78,9 @@
     }
 
-    // filter selection on photos that have no storage_category_id (ie that
-    // were added via pLoader)
     if (count($collection) > 0)
     {
-      $query = '
-SELECT
-    id
-  FROM '.IMAGES_TABLE.'
-  WHERE id IN ('.implode(',', $collection).')
-    AND storage_category_id IS NULL
-;';
-      $deletables = array_from_query($query, 'id');
-
-      if (count($deletables) > 0)
-      {
-        $physical_deletion = true;
-        delete_elements($deletables, $physical_deletion);
-
+      $deleted_count = delete_elements($collection, true);
+      if ($deleted_count > 0)
+      {
         array_push(
           $page['infos'],
@@ -102,7 +89,7 @@
               '%d photo was deleted',
               '%d photos were deleted',
-              count($deletables)
+              $deleted_count
               ),
-            count($deletables)
+            $deleted_count
             )
           );
@@ -322,7 +309,5 @@
 // +-----------------------------------------------------------------------+
 
-// we can only remove photos that have no storage_category_id, in other
-// word, it currently (Butterfly) means that the photo was added with
-// pLoader
+// we can only remove photos that are not remote
 if (count($page['cat_elements_id']) > 0)
 {
@@ -332,5 +317,5 @@
   FROM '.IMAGES_TABLE.'
   WHERE id IN ('.implode(',', $page['cat_elements_id']).')
-    AND storage_category_id IS NULL
+    AND path NOT LIKE "http%"
 ;';
   list($counter) = pwg_db_fetch_row(pwg_query($query));
Index: /trunk/admin/include/functions.php
===================================================================
--- /trunk/admin/include/functions.php	(revision 6872)
+++ /trunk/admin/include/functions.php	(revision 6873)
@@ -132,9 +132,10 @@
 //    - all the links between categories and elements
 //    - all the favorites associated to elements
+// @return number of deleted elements
 function delete_elements($ids, $physical_deletion=false)
 {
   if (count($ids) == 0)
   {
-    return;
+    return 0;
   }
   trigger_action('begin_delete_elements', $ids);
@@ -143,9 +144,6 @@
   {
     include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
-
-    // we can currently delete physically only photo with no
-    // storage_category_id (added via pLoader)
-    //
-    // we assume that the element is a photo, with no representative
+    $new_ids=array();
+
     $query = '
 SELECT
@@ -153,27 +151,46 @@
     path,
     tn_ext,
-    has_high
+    has_high,
+    representative_ext
   FROM '.IMAGES_TABLE.'
   WHERE id IN ('.implode(',', $ids).')
-    AND storage_category_id IS NULL
 ;';
     $result = pwg_query($query);
     while ($row = pwg_db_fetch_assoc($result))
     {
-      $file_path = $row['path'];
-      $thumbnail_path = get_thumbnail_path($row);
-      $high_path = null;
-      if (isset($row['has_high']) and get_boolean($row['has_high']))
+      if (url_is_remote($row['path']))
+        continue;
+      $files = array();
+      $files[] = get_element_path($row);
+      if (!empty($row['tn_ext']))
+        $files[] = get_thumbnail_path($row);
+      if (!empty($row['has_high']) and get_boolean($row['has_high']))
+        $files[] = get_high_path($row);
+      if (!empty($row['representative_ext']))
       {
-        $high_path = get_high_path($row);
+        $pi = pathinfo($row['path']);
+        $file_wo_ext = get_filename_wo_extension($pi['basename']);
+        $files[] = PHPWG_ROOT_PATH.$pi['dirname'].'/pwg_representative/'.$file_wo_ext.'.'.$element_info['representative_ext'];
       }
 
-      foreach (array($file_path, $thumbnail_path, $high_path) as $path)
+      $ok = true;
+      foreach ($files as $path)
       {
-        if (isset($path) and is_file($path) and !unlink($path))
+        if (is_file($path) and !unlink($path))
         {
-          die('"'.$path.'" cannot be removed');
+          $ok = false;
+          trigger_error('"'.$path.'" cannot be removed', E_USER_WARNING);
+          break;
         }
       }
+      if ($ok)
+        $new_ids[] += $row['id'];
+      else
+        break;
+    }
+    $ids = $new_ids;
+    if (count($ids)==0)
+    {
+      return 0;
     }
   }
@@ -250,4 +267,5 @@
 
   trigger_action('delete_elements', $ids);
+  return count($ids);
 }
 
Index: /trunk/admin/themes/default/template/element_set_global.tpl
===================================================================
--- /trunk/admin/themes/default/template/element_set_global.tpl	(revision 6872)
+++ /trunk/admin/themes/default/template/element_set_global.tpl	(revision 6873)
@@ -86,7 +86,4 @@
   <fieldset>
     <legend>{'Deletions'|@translate}</legend>
-{if $ENABLE_SYNCHRONIZATION}
-    <p style="font-style:italic">{'Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'|@translate}</p>
-{/if}
     <p>
       {'target'|@translate}
Index: /trunk/language/en_UK/admin.lang.php
===================================================================
--- /trunk/language/en_UK/admin.lang.php	(revision 6872)
+++ /trunk/language/en_UK/admin.lang.php	(revision 6873)
@@ -607,5 +607,4 @@
 $lang['Quick Local Synchronization'] = "Quick Local Synchronization";
 $lang['No photo can be deleted'] = "No photo can be deleted";
-$lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = "Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.";
 $lang['Delete selected photos'] = "Delete selected photos";
 $lang['%d photo was deleted'] = "%d photo deleted";
Index: /trunk/language/fr_CA/admin.lang.php
===================================================================
--- /trunk/language/fr_CA/admin.lang.php	(revision 6872)
+++ /trunk/language/fr_CA/admin.lang.php	(revision 6873)
@@ -618,5 +618,4 @@
 $lang['Quick Local Synchronization'] = "Synchronisation rapide";
 $lang['No photo can be deleted'] = "Aucune photo ne peut être supprimée";
-$lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = "Note : Cette suppression des photos ne s'applique pas pour les photos ajoutées à l'aide de la synchronisation (méthode classique par chargement FTP). Pour ces photos, supprimez-les de votre serveur et refaites une synchronisation.";
 $lang['Delete selected photos'] = "Supprimer les photos sélectionnées";
 $lang['%d photo was deleted'] = "%d photo a été supprimée";
Index: /trunk/language/fr_FR/admin.lang.php
===================================================================
--- /trunk/language/fr_FR/admin.lang.php	(revision 6872)
+++ /trunk/language/fr_FR/admin.lang.php	(revision 6873)
@@ -608,5 +608,4 @@
 $lang['Quick Local Synchronization'] = "Synchronisation Rapide";
 $lang['No photo can be deleted'] = "Aucune photo ne peut être supprimée";
-$lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = "Note : Cette suppression des photos ne s'applique pas pour les photos ajoutées à l'aide de la synchronisation (méthode classique par chargement FTP). Pour ces photos, supprimez-les de votre serveur et refaites une synchronisation.";
 $lang['Delete selected photos'] = "Supprimer les photos sélectionnées";
 $lang['%d photo was deleted'] = "%d photo a été supprimée";
Index: /trunk/language/hu_HU/admin.lang.php
===================================================================
--- /trunk/language/hu_HU/admin.lang.php	(revision 6872)
+++ /trunk/language/hu_HU/admin.lang.php	(revision 6873)
@@ -602,5 +602,4 @@
 $lang['Quick Local Synchronization'] = 'Helyi szinkronizálás';
 $lang['No photo can be deleted'] = 'Nincs törölhető kép';
-$lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = "Megjegyzés: a képek törlése nem vonatkozik a szinkronizálással hozzáadott képekre. A szinkronizálással hozzáadott képeket törölni kell a fájlrendszerből, majd ismételt szinkronizálás szükséges.";
 $lang['Delete selected photos'] = 'Kijelölt képek törlése';
 $lang['%d photo was deleted'] = '%d kép törölve';
Index: /trunk/language/pl_PL/admin.lang.php
===================================================================
--- /trunk/language/pl_PL/admin.lang.php	(revision 6872)
+++ /trunk/language/pl_PL/admin.lang.php	(revision 6873)
@@ -753,5 +753,4 @@
 $lang['Who can see this photo?'] = 'Kto może oglądać o zdjęcie?';
 $lang['Pending Comments'] = 'Oczekujące komentarze';
-$lang['Note: photo deletion does not apply to photos added by synchronization. For photos added by synchronization, remove them from the filesystem and then perform another synchronization.'] = 'Info: usunięcie zdjęcia nie dotyczy zdjęć dodanych podczas synchroniazacji. Zdjęcia dodanew ten sposób należy usunąć z systemu plików, a następnie wykonać synchronizację.';
 $lang['In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'] = 'W twoim pliku php.ini, parametr upload_max_filesize (%sB) jest większy niż post_max_size (%sB), powinieneś zmienić toe ustawienia';
 $lang['Exif extension not available, admin should disable exif use'] = 'Rozszerzenie exif jest nie dostępne, administrato powinien usunąć korzystanie z exif';
