aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
Diffstat (limited to 'admin')
-rw-r--r--admin/element_set_global.php134
-rw-r--r--admin/element_set_unit.php34
-rw-r--r--admin/include/functions.php196
-rw-r--r--admin/include/functions_metadata.php34
-rw-r--r--admin/picture_modify.php31
-rw-r--r--admin/site_update.php53
-rw-r--r--admin/tags.php265
7 files changed, 593 insertions, 154 deletions
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 61ef2d6ee..f4b8aae2b 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -44,40 +44,6 @@ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
check_status(ACCESS_ADMINISTRATOR);
// +-----------------------------------------------------------------------+
-// | functions |
-// +-----------------------------------------------------------------------+
-
-/**
- * returns the list of uniq keywords among given elements
- *
- * @param array element_ids
- */
-function get_elements_keywords($element_ids)
-{
- if (0 == count($element_ids))
- {
- return array();
- }
-
- $keywords = array();
-
- $query = '
-SELECT keywords
- FROM '.IMAGES_TABLE.'
- WHERE id IN ('.implode(',', $element_ids).')
-;';
- $result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
- {
- if (isset($row['keywords']) and !empty($row['keywords']))
- {
- $keywords = array_merge($keywords, explode(',', $row['keywords']));
- }
- }
- return array_unique($keywords);
-}
-
-// +-----------------------------------------------------------------------+
// | global mode form submission |
// +-----------------------------------------------------------------------+
@@ -111,6 +77,22 @@ if (isset($_POST['submit']))
}
}
+ if (isset($_POST['add_tags']) and count($collection) > 0)
+ {
+ add_tags($_POST['add_tags'], $collection);
+ }
+
+ if (isset($_POST['del_tags']) and count($collection) > 0)
+ {
+ $query = '
+DELETE
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE image_id IN ('.implode(',', $collection).')
+ AND tag_id IN ('.implode(',', $_POST['del_tags']).')
+;';
+ pwg_query($query);
+ }
+
if ($_POST['associate'] != 0 and count($collection) > 0)
{
$datas = array();
@@ -192,11 +174,6 @@ DELETE
$datas = array();
$dbfields = array('primary' => array('id'), 'update' => array());
- if (!empty($_POST['add_keywords']) or $_POST['remove_keyword'] != '0')
- {
- array_push($dbfields['update'], 'keywords');
- }
-
$formfields = array('author', 'name', 'date_creation');
foreach ($formfields as $formfield)
{
@@ -210,7 +187,7 @@ DELETE
if (count($dbfields['update']) > 0 and count($collection) > 0)
{
$query = '
-SELECT id, keywords
+SELECT id
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $collection).')
;';
@@ -221,44 +198,6 @@ SELECT id, keywords
$data = array();
$data['id'] = $row['id'];
- if (!empty($_POST['add_keywords']))
- {
- $data['keywords'] =
- implode(
- ',',
- array_unique(
- array_merge(
- get_keywords(empty($row['keywords']) ? '' : $row['keywords']),
- get_keywords($_POST['add_keywords'])
- )
- )
- );
- }
-
- if ($_POST['remove_keyword'] != '0')
- {
- if (!isset($data['keywords']))
- {
- $data['keywords'] = empty($row['keywords']) ? '' : $row['keywords'];
- }
-
- $data['keywords'] =
- implode(
- ',',
- array_unique(
- array_diff(
- get_keywords($data['keywords']),
- array($_POST['remove_keyword'])
- )
- )
- );
-
- if ($data['keywords'] == '')
- {
- unset($data['keywords']);
- }
- }
-
if ('set' == $_POST['author_action'])
{
$data['author'] = $_POST['author'];
@@ -384,25 +323,36 @@ SELECT DISTINCT(category_id) AS id, c.name, uppercats, global_rank
display_select_cat_wrapper($query, array(), $blockname, true);
}
-$blockname = 'remove_keyword_option';
-
-$template->assign_block_vars(
- $blockname,
- array('VALUE'=> 0,
- 'OPTION' => '------------'
- ));
+// add tags
+$template->assign_vars(
+ array(
+ 'ADD_TAG_SELECTION' => get_html_tag_selection(get_all_tags(), 'add_tags'),
+ )
+ );
-$keywords = get_elements_keywords($page['cat_elements_id']);
+// remove tags
+$query = '
+SELECT tag_id, name, url_name, count(*) counter
+ FROM '.IMAGE_TAG_TABLE.'
+ INNER JOIN '.TAGS_TABLE.' ON tag_id = id
+ WHERE image_id IN ('.implode(',', $page['cat_elements_id']).')
+ GROUP BY tag_id
+ ORDER BY name ASC
+;';
+$result = pwg_query($query);
-foreach ($keywords as $keyword)
+$tags = array();
+while($row = mysql_fetch_array($result))
{
- $template->assign_block_vars(
- $blockname,
- array('VALUE'=> $keyword,
- 'OPTION' => $keyword
- ));
+ array_push($tags, $row);
}
+$template->assign_vars(
+ array(
+ 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
+ )
+ );
+
// creation date
$day =
empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
diff --git a/admin/element_set_unit.php b/admin/element_set_unit.php
index c43522894..f6800f399 100644
--- a/admin/element_set_unit.php
+++ b/admin/element_set_unit.php
@@ -103,25 +103,21 @@ SELECT id, date_creation
{
$data{'date_creation'} = $row['date_creation'];
}
+
+ array_push($datas, $data);
- $keywords = get_keywords($_POST['keywords-'.$row['id']]);
- if (count($keywords) > 0)
- {
- $data{'keywords'} = implode(',', $keywords);
- }
- else
+ // tags management
+ if (isset($_POST[ 'tags-'.$row['id'] ]))
{
- $data{'keywords'} = '';
+ set_tags($_POST[ 'tags-'.$row['id'] ], $row['id']);
}
-
- array_push($datas, $data);
}
mass_updates(
IMAGES_TABLE,
array(
'primary' => array('id'),
- 'update' => array('name','author','comment','date_creation','keywords')
+ 'update' => array('name','author','comment','date_creation')
),
$datas
);
@@ -192,11 +188,13 @@ if (count($page['cat_elements_id']) > 0)
);
$template->assign_vars(array('NAV_BAR' => $nav_bar));
+ // tags
+ $all_tags = get_all_tags();
$element_ids = array();
$query = '
-SELECT id,path,tn_ext,name,date_creation,comment,keywords,author,file
+SELECT id,path,tn_ext,name,date_creation,comment,author,file
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $page['cat_elements_id']).')
'.$conf['order_by'].'
@@ -210,6 +208,13 @@ SELECT id,path,tn_ext,name,date_creation,comment,keywords,author,file
array_push($element_ids, $row['id']);
$src = get_thumbnail_src($row['path'], @$row['tn_ext']);
+
+ $query = '
+SELECT tag_id
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE image_id = '.$row['id'].'
+;';
+ $selected_tags = array_from_query($query, 'tag_id');
// creation date
if (!empty($row['date_creation']))
@@ -237,7 +242,12 @@ SELECT id,path,tn_ext,name,date_creation,comment,keywords,author,file
'AUTHOR' => @$row['author'],
'DESCRIPTION' => @$row['comment'],
'DATE_CREATION_YEAR' => $year,
- 'KEYWORDS' => @$row['keywords']
+
+ 'TAG_SELECTION' => get_html_tag_selection(
+ $all_tags,
+ 'tags-'.$row['id'],
+ $selected_tags
+ ),
)
);
diff --git a/admin/include/functions.php b/admin/include/functions.php
index dc477f6d1..3a8c6b506 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -269,6 +269,14 @@ DELETE FROM '.IMAGE_CATEGORY_TABLE.'
;';
pwg_query($query);
+ // destruction of the links between images and tags
+ $query = '
+DELETE FROM '.IMAGE_TAG_TABLE.'
+ WHERE image_id IN (
+'.wordwrap(implode(', ', $ids), 80, "\n").')
+;';
+ pwg_query($query);
+
// destruction of the favorites associated with the picture
$query = '
DELETE FROM '.FAVORITES_TABLE.'
@@ -577,25 +585,6 @@ function date_convert_back( $date )
}
/**
- * returns an array with relevant keywords found in the given string.
- *
- * Keywords must be separated by comma or space characters.
- *
- * @param string keywords_string
- * @return array
- */
-function get_keywords($keywords_string)
-{
- return
- array_unique(
- preg_split(
- '/[\s,]+/',
- $keywords_string
- )
- );
-}
-
-/**
* returns an array containing sub-directories which can be a category,
* recursive by default
*
@@ -2094,6 +2083,173 @@ UPDATE
}
/**
+ * Set tags to an image. Warning: given tags are all tags associated to the
+ * image, not additionnal tags.
+ *
+ * @param array tag ids
+ * @param int image id
+ * @return void
+ */
+function set_tags($tags, $image_id)
+{
+ $query = '
+DELETE
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE image_id = '.$image_id.'
+;';
+ pwg_query($query);
+
+ if (count($tags) > 0)
+ {
+ $inserts = array();
+ foreach ($tags as $tag_id)
+ {
+ array_push(
+ $inserts,
+ array(
+ 'tag_id' => $tag_id,
+ 'image_id' => $image_id
+ )
+ );
+ }
+ mass_inserts(
+ IMAGE_TAG_TABLE,
+ array_keys($inserts[0]),
+ $inserts
+ );
+ }
+}
+
+/**
+ * Add new tags to a set of images.
+ *
+ * @param array tag ids
+ * @param array image ids
+ * @return void
+ */
+function add_tags($tags, $images)
+{
+ if (count($tags) == 0 or count($tags) == 0)
+ {
+ return;
+ }
+
+ // we can't insert twice the same {image_id,tag_id} so we must first
+ // delete lines we'll insert later
+ $query = '
+DELETE
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE image_id IN ('.implode(',', $images).')
+ AND tag_id IN ('.implode(',', $tags).')
+;';
+ pwg_query($query);
+
+ $inserts = array();
+ foreach ($images as $image_id)
+ {
+ foreach ($tags as $tag_id)
+ {
+ array_push(
+ $inserts,
+ array(
+ 'image_id' => $image_id,
+ 'tag_id' => $tag_id,
+ )
+ );
+ }
+ }
+ mass_inserts(
+ IMAGE_TAG_TABLE,
+ array_keys($inserts[0]),
+ $inserts
+ );
+}
+
+function tag_id_from_tag_name($tag_name)
+{
+ global $page;
+
+ if (isset($page['tag_id_from_tag_name_cache'][$tag_name]))
+ {
+ return $page['tag_id_from_tag_name_cache'][$tag_name];
+ }
+
+ if (function_exists('mysql_real_escape_string'))
+ {
+ $tag_name = mysql_real_escape_string($tag_name);
+ }
+ else
+ {
+ $tag_name = mysql_escape_string($tag_name);
+ }
+
+ // does the tag already exist?
+ $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' => str2url($tag_name),
+ )
+ )
+ );
+
+ $page['tag_id_from_tag_name_cache'][$tag_name] = mysql_insert_id();
+ }
+ else
+ {
+ $page['tag_id_from_tag_name_cache'][$tag_name] = $existing_tags[0];
+ }
+
+ return $page['tag_id_from_tag_name_cache'][$tag_name];
+}
+
+function set_tags_of($tags_of)
+{
+ if (count($tags_of) > 0)
+ {
+ $query = '
+DELETE
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE image_id IN ('.implode(',', array_keys($tags_of)).')
+;';
+ pwg_query($query);
+
+ $inserts = array();
+
+ foreach ($tags_of as $image_id => $tag_ids)
+ {
+ foreach ($tag_ids as $tag_id)
+ {
+ array_push(
+ $inserts,
+ array(
+ 'image_id' => $image_id,
+ 'tag_id' => $tag_id,
+ )
+ );
+ }
+ }
+
+ mass_inserts(
+ IMAGE_TAG_TABLE,
+ array_keys($inserts[0]),
+ $inserts
+ );
+ }
+}
+
+/**
* Do maintenance on all PWG tables
*
* @return nono
@@ -2143,6 +2299,4 @@ function do_maintenance_all_tables()
pwg_query($query);
}
-
-
?>
diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php
index 337019b2e..21897c2cd 100644
--- a/admin/include/functions_metadata.php
+++ b/admin/include/functions_metadata.php
@@ -50,10 +50,7 @@ function get_sync_iptc_data($file)
if (isset($iptc['keywords']))
{
- // keywords separator is the comma, nothing else. Allowed characters in
- // keywords : [A-Za-z0-9], "-" and "_". All other characters will be
- // considered as separators
- $iptc['keywords'] = preg_replace('/[^\w-]+/', ',', $iptc['keywords']);
+ // keywords separator is the comma
$iptc['keywords'] = preg_replace('/^,+|,+$/', '', $iptc['keywords']);
}
@@ -90,6 +87,7 @@ function update_metadata($files)
}
$datas = array();
+ $tags_of = array();
foreach ($files as $id => $file)
{
@@ -123,7 +121,25 @@ function update_metadata($files)
{
foreach (array_keys($iptc) as $key)
{
- $data[$key] = addslashes($iptc[$key]);
+ if ($key == 'keywords' or $key == 'tags')
+ {
+ if (!isset($tags_of[$id]))
+ {
+ $tags_of[$id] = array();
+ }
+
+ foreach (explode(',', $iptc[$key]) as $tag_name)
+ {
+ array_push(
+ $tags_of[$id],
+ tag_id_from_tag_name($tag_name)
+ );
+ }
+ }
+ else
+ {
+ $data[$key] = addslashes($iptc[$key]);
+ }
}
}
}
@@ -157,7 +173,10 @@ function update_metadata($files)
$update_fields =
array_merge(
$update_fields,
- array_keys($conf['use_iptc_mapping'])
+ array_diff(
+ array_keys($conf['use_iptc_mapping']),
+ array('tags', 'keywords')
+ )
);
}
@@ -166,8 +185,11 @@ function update_metadata($files)
'primary' => array('id'),
'update' => array_unique($update_fields)
);
+ echo '<pre>'; print_r($datas); echo '</pre>';
mass_updates(IMAGES_TABLE, $fields, $datas);
}
+
+ set_tags_of(tags_of);
}
/**
diff --git a/admin/picture_modify.php b/admin/picture_modify.php
index be7497a07..83bf09a23 100644
--- a/admin/picture_modify.php
+++ b/admin/picture_modify.php
@@ -100,16 +100,6 @@ if (isset($_POST['submit']) and count($page['errors']) == 0)
}
}
- $keywords = get_keywords($_POST['keywords']);
- if (count($keywords) > 0)
- {
- $data{'keywords'} = implode(',', $keywords);
- }
- else
- {
- $data{'keywords'} = '';
- }
-
mass_updates(
IMAGES_TABLE,
array(
@@ -119,6 +109,11 @@ if (isset($_POST['submit']) and count($page['errors']) == 0)
array($data)
);
+ set_tags(
+ isset($_POST['tags']) ? $_POST['tags'] : array(),
+ $_GET['image_id']
+ );
+
array_push($page['infos'], l10n('Picture informations updated'));
}
// associate the element to other categories than its storage category
@@ -215,6 +210,14 @@ $row = mysql_fetch_array(pwg_query($query));
$storage_category_id = $row['category_id'];
$image_file = $row['file'];
+// tags
+$query = '
+SELECT tag_id
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE image_id = '.$_GET['image_id'].'
+;';
+$selected_tags = array_from_query($query, 'tag_id');
+
// Navigation path
$date = isset($_POST['date_creation']) && empty($page['errors'])
@@ -257,9 +260,11 @@ $template->assign_vars(
'CREATION_DATE' => $date,
- 'KEYWORDS' =>
- isset($_POST['keywords']) ?
- stripslashes($_POST['keywords']) : @$row['keywords'],
+ 'TAG_SELECTION' => get_html_tag_selection(
+ get_all_tags(),
+ 'tags',
+ $selected_tags
+ ),
'DESCRIPTION' =>
isset($_POST['description']) ?
diff --git a/admin/site_update.php b/admin/site_update.php
index b68ce2b28..c7c31106c 100644
--- a/admin/site_update.php
+++ b/admin/site_update.php
@@ -715,6 +715,7 @@ if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])
$start = get_moment();
$datas = array();
+ $tags_of = array();
foreach ( $files as $id=>$file )
{
$data = $site_reader->get_element_update_attributes($file);
@@ -723,23 +724,55 @@ if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])
$data['date_metadata_update'] = CURRENT_DATE;
$data['id']=$id;
array_push($datas, $data);
+
+ foreach (array('keywords', 'tags') as $key)
+ {
+ if (isset($data[$key]))
+ {
+ if (!isset($tags_of[$id]))
+ {
+ $tags_of[$id] = array();
+ }
+
+ foreach (explode(',', $data[$key]) as $tag_name)
+ {
+ array_push(
+ $tags_of[$id],
+ tag_id_from_tag_name($tag_name)
+ );
+ }
+ }
+ }
}
else
{
array_push($errors, array('path' => $file, 'type' => 'PWG-ERROR-NO-FS'));
}
}
- $update_fields = $site_reader->get_update_attributes();
- $update_fields = array_merge($update_fields, array('date_metadata_update'));
- $fields =
- array(
- 'primary' => array('id'),
- 'update' => array_unique($update_fields)
- );
- //print_r($datas);
- if (!$simulate and count($datas)>0 )
+
+ if (!$simulate)
{
- mass_updates(IMAGES_TABLE, $fields, $datas);
+ if (count($datas) > 0)
+ {
+ mass_updates(
+ IMAGES_TABLE,
+ // fields
+ array(
+ 'primary' => array('id'),
+ 'update' => array_unique(
+ array_merge(
+ array_diff(
+ $site_reader->get_update_attributes(),
+ // keywords and tags fields are managed separately
+ array('keywords', 'tags')
+ ),
+ array('date_metadata_update'))
+ )
+ ),
+ $datas
+ );
+ }
+ set_tags_of($tags_of);
}
echo '<!-- metadata update : ';
diff --git a/admin/tags.php b/admin/tags.php
new file mode 100644
index 000000000..7ff29727c
--- /dev/null
+++ b/admin/tags.php
@@ -0,0 +1,265 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $RCSfile$
+// | last update : $Date: 2006-03-09 23:46:28 +0100 (jeu, 09 mar 2006) $
+// | last modifier : $Author: rub $
+// | revision : $Revision: 1072 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+if( !defined("PHPWG_ROOT_PATH") )
+{
+ die ("Hacking attempt!");
+}
+
+include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+check_status(ACCESS_ADMINISTRATOR);
+
+// +-----------------------------------------------------------------------+
+// | edit tags |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['submit']))
+{
+ $query = '
+SELECT name
+ FROM '.TAGS_TABLE.'
+;';
+ $existing_names = array_from_query($query, 'name');
+
+
+ $current_name_of = array();
+ $query = '
+SELECT id, name
+ FROM '.TAGS_TABLE.'
+ WHERE id IN ('.$_POST['edit_list'].')
+;';
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
+ {
+ $current_name_of[ $row['id'] ] = $row['name'];
+ }
+
+ $updates = array();
+ // we must not rename tag with an already existing name
+ foreach (explode(',', $_POST['edit_list']) as $tag_id)
+ {
+ if (function_exists('mysql_real_escape_string'))
+ {
+ $tag_name = mysql_real_escape_string($_POST['tag_name-'.$tag_id]);
+ }
+ else
+ {
+ $tag_name = mysql_escape_string($_POST['tag_name-'.$tag_id]);
+ }
+
+ if ($tag_name != $current_name_of[$tag_id])
+ {
+ if (in_array($tag_name, $existing_names))
+ {
+ array_push(
+ $page['errors'],
+ sprintf(
+ l10n('Tag "%s" already exist'),
+ $tag_name
+ )
+ );
+ }
+ else if (!empty($tag_name))
+ {
+ array_push(
+ $updates,
+ array(
+ 'id' => $tag_id,
+ 'name' => $tag_name,
+ 'url_name' => str2url($tag_name),
+ )
+ );
+ }
+ }
+ }
+ mass_updates(
+ TAGS_TABLE,
+ array(
+ 'primary' => array('id'),
+ 'update' => array('name', 'url_name'),
+ ),
+ $updates
+ );
+}
+
+// +-----------------------------------------------------------------------+
+// | delete tags |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['delete']) and isset($_POST['tags']))
+{
+ $query = '
+SELECT name
+ FROM '.TAGS_TABLE.'
+ WHERE id IN ('.implode(',', $_POST['tags']).')
+;';
+ $tag_names = array_from_query($query, 'name');
+
+ $query = '
+DELETE
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE tag_id IN ('.implode(',', $_POST['tags']).')
+;';
+ pwg_query($query);
+
+ $query = '
+DELETE
+ FROM '.TAGS_TABLE.'
+ WHERE id IN ('.implode(',', $_POST['tags']).')
+;';
+ pwg_query($query);
+
+ array_push(
+ $page['infos'],
+ sprintf(
+ l10n('The %d following tags were deleted : %s'),
+ count($tag_names),
+ implode(', ', $tag_names)
+ )
+ );
+}
+
+// +-----------------------------------------------------------------------+
+// | add a tag |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['add_tag']) and !empty($_POST['add_tag']))
+{
+ if (function_exists('mysql_real_escape_string'))
+ {
+ $tag_name = mysql_real_escape_string($_POST['add_tag']);
+ }
+ else
+ {
+ $tag_name = mysql_escape_string($_POST['add_tag']);
+ }
+
+ // does the tag already exist?
+ $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' => str2url($tag_name),
+ )
+ )
+ );
+
+ array_push(
+ $page['infos'],
+ sprintf(
+ l10n('Tag "%s" was added'),
+ $tag_name
+ )
+ );
+ }
+ else
+ {
+ array_push(
+ $page['errors'],
+ sprintf(
+ l10n('Tag "%s" already exist'),
+ $tag_name
+ )
+ );
+ }
+}
+
+// +-----------------------------------------------------------------------+
+// | template init |
+// +-----------------------------------------------------------------------+
+
+$template->set_filenames(array('tags' => 'admin/tags.tpl'));
+
+$template->assign_vars(
+ array(
+ 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=tags'
+ )
+ );
+
+// +-----------------------------------------------------------------------+
+// | form creation |
+// +-----------------------------------------------------------------------+
+
+$template->assign_vars(
+ array(
+ 'TAG_SELECTION' => get_html_tag_selection(
+ get_all_tags(),
+ 'tags'
+ ),
+ )
+ );
+
+if (isset($_POST['edit']) and isset($_POST['tags']))
+{
+ $template->assign_block_vars(
+ 'edit_tags',
+ array(
+ 'LIST' => implode(',', $_POST['tags']),
+ )
+ );
+
+ $query = '
+SELECT id, name
+ FROM '.TAGS_TABLE.'
+ WHERE id IN ('.implode(',', $_POST['tags']).')
+;';
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
+ {
+ $name_of[ $row['id'] ] = $row['name'];
+ }
+
+ foreach ($_POST['tags'] as $tag_id)
+ {
+ $template->assign_block_vars(
+ 'edit_tags.tag',
+ array(
+ 'ID' => $tag_id,
+ 'NAME' => $name_of[$tag_id],
+ )
+ );
+ }
+}
+
+// +-----------------------------------------------------------------------+
+// | sending html code |
+// +-----------------------------------------------------------------------+
+
+$template->assign_var_from_handle('ADMIN_CONTENT', 'tags');
+
+?>