aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php30
-rw-r--r--admin/tags.php128
-rw-r--r--admin/themes/default/template/tags.tpl37
-rw-r--r--admin/themes/default/theme.css2
4 files changed, 181 insertions, 16 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index f5498ac8b..1d229eea3 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -1394,6 +1394,36 @@ DELETE
);
}
+/**
+ *
+ */
+function delete_tags($tag_ids)
+{
+ if (is_numeric($tag_ids))
+ {
+ $tag_ids = array($tag_ids);
+ }
+
+ if (!is_array($tag_ids))
+ {
+ return false;
+ }
+
+ $query = '
+DELETE
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE tag_id IN ('.implode(',', $tag_ids).')
+;';
+ pwg_query($query);
+
+ $query = '
+DELETE
+ FROM '.TAGS_TABLE.'
+ WHERE id IN ('.implode(',', $tag_ids).')
+;';
+ pwg_query($query);
+}
+
function tag_id_from_tag_name($tag_name)
{
global $page;
diff --git a/admin/tags.php b/admin/tags.php
index 67cc9bf3c..a879806fb 100644
--- a/admin/tags.php
+++ b/admin/tags.php
@@ -101,31 +101,121 @@ SELECT id, name
}
// +-----------------------------------------------------------------------+
-// | delete tags |
+// | merge tags |
// +-----------------------------------------------------------------------+
-if (isset($_POST['delete']) and isset($_POST['tags']))
+if (isset($_POST['confirm_merge']))
{
- $query = '
-SELECT name
+ if (!isset($_POST['destination_tag']))
+ {
+ array_push(
+ $page['errors'],
+ l10n('No destination tag selected')
+ );
+ }
+ else
+ {
+ $destination_tag_id = $_POST['destination_tag'];
+ $tag_ids = explode(',', $_POST['merge_list']);
+
+ if (is_array($tag_ids) and count($tag_ids) > 1)
+ {
+ $name_of_tag = array();
+ $query = '
+SELECT
+ id,
+ name
FROM '.TAGS_TABLE.'
- WHERE id IN ('.implode(',', $_POST['tags']).')
+ WHERE id IN ('.implode(',', $tag_ids).')
;';
- $tag_names = array_from_query($query, 'name');
-
- $query = '
-DELETE
+ $result = pwg_query($query);
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ $name_of_tag[ $row['id'] ] = trigger_event('render_tag_name', $row['name']);
+ }
+
+ $tag_ids_to_delete = array_diff(
+ $tag_ids,
+ array($destination_tag_id)
+ );
+
+ $query = '
+SELECT
+ DISTINCT(image_id)
FROM '.IMAGE_TAG_TABLE.'
- WHERE tag_id IN ('.implode(',', $_POST['tags']).')
+ WHERE tag_id IN ('.implode(',', $tag_ids_to_delete).')
;';
- pwg_query($query);
-
+ $image_ids = array_from_query($query, 'image_id');
+
+ delete_tags($tag_ids_to_delete);
+
+ $query = '
+SELECT
+ image_id
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE tag_id = '.$destination_tag_id.'
+;';
+ $destination_tag_image_ids = array_from_query($query, 'image_id');
+
+ $image_ids_to_link = array_diff(
+ $image_ids,
+ $destination_tag_image_ids
+ );
+
+ $inserts = array();
+ foreach ($image_ids_to_link as $image_id)
+ {
+ array_push(
+ $inserts,
+ array(
+ 'tag_id' => $destination_tag_id,
+ 'image_id' => $image_id
+ )
+ );
+ }
+
+ if (count($inserts) > 0)
+ {
+ mass_inserts(
+ IMAGE_TAG_TABLE,
+ array_keys($inserts[0]),
+ $inserts
+ );
+ }
+
+ $tags_deleted = array();
+ foreach ($tag_ids_to_delete as $tag_id)
+ {
+ $tags_deleted[] = $name_of_tag[$tag_id];
+ }
+
+ array_push(
+ $page['infos'],
+ sprintf(
+ l10n('Tags <em>%s</em> merged into tag <em>%s</em>'),
+ implode(', ', $tags_deleted),
+ $name_of_tag[$destination_tag_id]
+ )
+ );
+ }
+ }
+}
+
+
+// +-----------------------------------------------------------------------+
+// | delete tags |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['delete']) and isset($_POST['tags']))
+{
$query = '
-DELETE
+SELECT name
FROM '.TAGS_TABLE.'
WHERE id IN ('.implode(',', $_POST['tags']).')
;';
- pwg_query($query);
+ $tag_names = array_from_query($query, 'name');
+
+ delete_tags($_POST['tags']);
array_push(
$page['infos'],
@@ -250,11 +340,17 @@ $template->assign(
)
);
-if (isset($_POST['edit']) and isset($_POST['tags']))
+if ((isset($_POST['edit']) or isset($_POST['merge'])) and isset($_POST['tags']))
{
+ $list_name = 'EDIT_TAGS_LIST';
+ if (isset($_POST['merge']))
+ {
+ $list_name = 'MERGE_TAGS_LIST';
+ }
+
$template->assign(
array(
- 'EDIT_TAGS_LIST' => implode(',', $_POST['tags']),
+ $list_name => implode(',', $_POST['tags']),
)
);
diff --git a/admin/themes/default/template/tags.tpl b/admin/themes/default/template/tags.tpl
index 10a4f8b84..51b8c3614 100644
--- a/admin/themes/default/template/tags.tpl
+++ b/admin/themes/default/template/tags.tpl
@@ -1,5 +1,28 @@
{include file='include/tag_selection.inc.tpl'}
+{footer_script}{literal}
+jQuery(document).ready(function(){
+ function displayDeletionWarnings() {
+ jQuery(".warningDeletion").show();
+ jQuery("input[name=destination_tag]:checked").parent("label").children(".warningDeletion").hide();
+ }
+
+ displayDeletionWarnings();
+
+ jQuery("#mergeTags label").click(function() {
+ displayDeletionWarnings();
+ });
+
+ jQuery("input[name=merge]").click(function() {
+ if (jQuery("ul.tagSelection input[type=checkbox]:checked").length < 2) {
+ alert("{/literal}{'Select at least two tags for merging'|@translate}{literal}");
+ return false;
+ }
+ });
+});
+{/literal}{/footer_script}
+
+
<div class="titrePage">
<h2>{'Manage tags'|@translate}</h2>
</div>
@@ -30,6 +53,19 @@
</fieldset>
{/if}
+ {if isset($MERGE_TAGS_LIST)}
+ <input type="hidden" name="merge_list" value="{$MERGE_TAGS_LIST}">
+
+ <fieldset id="mergeTags">
+ <legend>{'Merge tags'|@translate}</legend>
+ {'Select the destination tag'|@translate}<br><br>
+ {foreach from=$tags item=tag name=tagloop}
+ <label><input type="radio" name="destination_tag" value="{$tag.ID}"{if $smarty.foreach.tagloop.index == 0} checked="checked"{/if}> {$tag.NAME}<span class="warningDeletion"> {'(this tag will be deleted)'|@translate}</span></label><br>
+ {/foreach}
+ <br><input type="submit" name="confirm_merge" value="{'Confirm merge'|@translate}">
+ </fieldset>
+ {/if}
+
<fieldset>
<legend>{'Add a tag'|@translate}</legend>
@@ -49,6 +85,7 @@
<p>
<input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
<input class="submit" type="submit" name="edit" value="{'Edit selected tags'|@translate}">
+ <input class="submit" type="submit" name="merge" value="{'Merge selected tags'|@translate}">
<input class="submit" type="submit" name="delete" value="{'Delete selected tags'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');">
</p>
</fieldset>
diff --git a/admin/themes/default/theme.css b/admin/themes/default/theme.css
index f8bf70be1..433d62ffb 100644
--- a/admin/themes/default/theme.css
+++ b/admin/themes/default/theme.css
@@ -1078,3 +1078,5 @@ p#uploadModeInfos {text-align:left;margin-top:1em;font-size:90%;color:#999;}
#progressbar {border:1px solid #ccc; background-color:#eee;}
.ui-progressbar-value { background-image: url(images/pbar-ani.gif); height:10px;margin:-1px;border:1px solid #E78F08;}
+/* Tag Manager */
+.warningDeletion {display:none;font-style:italic;} \ No newline at end of file