aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/element_set_global.php109
-rw-r--r--admin/include/functions.php41
-rw-r--r--admin/template/goto/element_set_global.tpl16
-rw-r--r--language/en_UK/admin.lang.php5
-rw-r--r--language/fr_FR/admin.lang.php5
5 files changed, 175 insertions, 1 deletions
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 3a3e79546..43b447012 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -40,6 +40,91 @@ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
check_status(ACCESS_ADMINISTRATOR);
// +-----------------------------------------------------------------------+
+// | deletion form submission |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['delete']))
+{
+ if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion'])
+ {
+ $collection = array();
+
+ switch ($_POST['target_deletion'])
+ {
+ case 'all' :
+ {
+ $collection = $page['cat_elements_id'];
+ break;
+ }
+ case 'selection' :
+ {
+ if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
+ {
+ array_push($page['errors'], l10n('Select at least one picture'));
+ }
+ else
+ {
+ $collection = $_POST['selection'];
+ }
+ break;
+ }
+ }
+
+ // 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)
+ {
+ // what will be the categories to update? (to avoid orphan on
+ // representative_picture_id)
+ $query = '
+SELECT
+ category_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE image_id IN ('.implode(',', $deletables).')
+;';
+ $categories_to_update = array_from_query($query, 'category_id');
+
+ $physical_deletion = true;
+ delete_elements($deletables, $physical_deletion);
+
+ update_category($categories_to_update);
+
+ array_push(
+ $page['infos'],
+ sprintf(
+ l10n_dec(
+ '%d photo was deleted',
+ '%d photos were deleted',
+ count($deletables)
+ ),
+ count($deletables)
+ )
+ );
+ }
+ else
+ {
+ array_push($page['errors'], l10n('No photo can be deleted'));
+ }
+ }
+ }
+ else
+ {
+ array_push($page['errors'], l10n('You need to confirm deletion'));
+ }
+}
+
+// +-----------------------------------------------------------------------+
// | global mode form submission |
// +-----------------------------------------------------------------------+
@@ -237,6 +322,30 @@ $template->assign(
$template->assign('IN_CADDIE', 'caddie' == $_GET['cat'] ? true : false );
// +-----------------------------------------------------------------------+
+// | deletion form |
+// +-----------------------------------------------------------------------+
+
+// 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
+if (count($page['cat_elements_id']) > 0)
+{
+ $query = '
+SELECT
+ COUNT(*)
+ FROM '.IMAGES_TABLE.'
+ WHERE id IN ('.implode(',', $page['cat_elements_id']).')
+ AND storage_category_id IS NULL
+;';
+ list($counter) = mysql_fetch_row(pwg_query($query));
+
+ if ($counter > 0)
+ {
+ $template->assign('show_delete_form', true);
+ }
+}
+
+// +-----------------------------------------------------------------------+
// | global mode form |
// +-----------------------------------------------------------------------+
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 932578963..4b0713226 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -127,7 +127,7 @@ DELETE FROM '.OLD_PERMALINKS_TABLE.'
// - all the comments related to elements
// - all the links between categories and elements
// - all the favorites associated to elements
-function delete_elements($ids)
+function delete_elements($ids, $physical_deletion=false)
{
if (count($ids) == 0)
{
@@ -135,6 +135,45 @@ function delete_elements($ids)
}
trigger_action('begin_delete_elements', $ids);
+ if ($physical_deletion)
+ {
+ 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
+ $query = '
+SELECT
+ id,
+ path,
+ tn_ext,
+ has_high
+ FROM '.IMAGES_TABLE.'
+ WHERE id IN ('.implode(',', $ids).')
+ AND storage_category_id IS NULL
+;';
+ $result = pwg_query($query);
+ while ($row = mysql_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']))
+ {
+ $high_path = get_high_path($row);
+ }
+
+ foreach (array($file_path, $thumbnail_path, $high_path) as $path)
+ {
+ if (isset($path) and !unlink($path))
+ {
+ die('"'.$path.'" cannot be removed');
+ }
+ }
+ }
+ }
+
// destruction of the comments on the image
$query = '
DELETE FROM '.COMMENTS_TABLE.'
diff --git a/admin/template/goto/element_set_global.tpl b/admin/template/goto/element_set_global.tpl
index 649948854..7e3e64643 100644
--- a/admin/template/goto/element_set_global.tpl
+++ b/admin/template/goto/element_set_global.tpl
@@ -65,6 +65,22 @@
</fieldset>
+ {if $show_delete_form}
+ <fieldset>
+ <legend>{'Deletions'|@translate}</legend>
+ <p style="font-style:italic">{'Note: Only deletes photos added with pLoader'|@translate}</p>
+ <p>
+ {'target'|@translate}
+ <label><input type="radio" name="target_deletion" value="all" /> {'all'|@translate}</label>
+ <label><input type="radio" name="target_deletion" value="selection" checked="checked" /> {'selection'|@translate}</label>
+ </p>
+ <p>
+ <label><input type="checkbox" name="confirm_deletion" value="1" /> {'confirm'|@translate}</label>
+ <input class="submit" type="submit" value="{'Delete selected photos'|@translate}" name="delete" {$TAG_INPUT_ENABLED}/>
+ </p>
+ </fieldset>
+ {/if}
+
<fieldset>
<legend>{'Form'|@translate}</legend>
diff --git a/language/en_UK/admin.lang.php b/language/en_UK/admin.lang.php
index bcf3dfb97..cbc4edd91 100644
--- a/language/en_UK/admin.lang.php
+++ b/language/en_UK/admin.lang.php
@@ -639,4 +639,9 @@ $lang['ranks'] = 'ranks';
$lang['Drag to re-order'] = 'Drag to re-order';
$lang['Unable to retrieve server informations since allow_url_fopen is disabled.'] = 'Unable to retrieve server informations since allow_url_fopen is disabled.';
$lang['Quick Local Synchronization'] = 'Quick Local Synchronization';
+$lang['No photo can be deleted'] = 'No photo can be deleted';
+$lang['Note: Only deletes photos added with pLoader'] = 'Note: Only deletes photos added with pLoader';
+$lang['Delete selected photos'] = 'Delete selected photos';
+$lang['%d photo was deleted'] = '%d photo was deleted';
+$lang['%d photos were deleted'] = '%d photos were deleted';
?>
diff --git a/language/fr_FR/admin.lang.php b/language/fr_FR/admin.lang.php
index dad599162..0ee213afb 100644
--- a/language/fr_FR/admin.lang.php
+++ b/language/fr_FR/admin.lang.php
@@ -638,4 +638,9 @@ $lang['ranks'] = 'rangs';
$lang['Drag to re-order'] = 'Cliquer-glisser pour ré-organiser';
$lang['Unable to retrieve server informations since allow_url_fopen is disabled.'] = 'Impossible de se connecter au server car la fonction allow_url_fopen est désactivée.';
$lang['Quick Local Synchronization'] = 'Synchronisation Rapide';
+$lang['No photo can be deleted'] = 'Aucune photo ne peut être supprimée';
+$lang['Note: Only deletes photos added with pLoader'] = 'Note: seules les photos ajoutées via pLoader peuvent être supprimées';
+$lang['Delete selected photos'] = 'Supprimer les photos';
+$lang['%d photo was deleted'] = '%d photo a été supprimée';
+$lang['%d photos were deleted'] = '%d photos ont été supprimées';
?>