source: trunk/admin/tags.php @ 11487

Last change on this file since 11487 was 11487, checked in by mistic100, 13 years ago

feature:2322 display all localisations as independant tags in TokenInput

  • Property svn:eol-style set to LF
File size: 8.1 KB
RevLine 
[1119]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[1119]23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30check_status(ACCESS_ADMINISTRATOR);
31
[5195]32if (!empty($_POST))
33{
34  check_pwg_token();
35}
36
[1119]37// +-----------------------------------------------------------------------+
38// |                                edit tags                              |
39// +-----------------------------------------------------------------------+
40
[8126]41if (isset($_POST['submit']))
[1119]42{
43  $query = '
44SELECT name
45  FROM '.TAGS_TABLE.'
46;';
47  $existing_names = array_from_query($query, 'name');
48 
49
50  $current_name_of = array();
51  $query = '
52SELECT id, name
53  FROM '.TAGS_TABLE.'
54  WHERE id IN ('.$_POST['edit_list'].')
55;';
56  $result = pwg_query($query);
[4325]57  while ($row = pwg_db_fetch_assoc($result))
[1119]58  {
59    $current_name_of[ $row['id'] ] = $row['name'];
60  }
61 
62  $updates = array();
63  // we must not rename tag with an already existing name
64  foreach (explode(',', $_POST['edit_list']) as $tag_id)
65  {
[2098]66    $tag_name = stripslashes($_POST['tag_name-'.$tag_id]);
[1119]67
68    if ($tag_name != $current_name_of[$tag_id])
69    {
70      if (in_array($tag_name, $existing_names))
71      {
72        array_push(
73          $page['errors'],
74          sprintf(
[5036]75            l10n('Tag "%s" already exists'),
[1119]76            $tag_name
77            )
78          );
79      }
80      else if (!empty($tag_name))
81      {
82        array_push(
83          $updates,
84          array(
85            'id' => $tag_id,
[2098]86            'name' => addslashes($tag_name),
[11317]87            'url_name' => str2url(trigger_event('render_tag_url', $tag_name)),
[1119]88            )
89          );
90      }
91    }
92  }
93  mass_updates(
94    TAGS_TABLE,
95    array(
96      'primary' => array('id'),
97      'update' => array('name', 'url_name'),
98      ),
99    $updates
100    );
101}
102
103// +-----------------------------------------------------------------------+
104// |                               delete tags                             |
105// +-----------------------------------------------------------------------+
106
[8126]107if (isset($_POST['delete']) and isset($_POST['tags']))
[1119]108{
109  $query = '
110SELECT name
111  FROM '.TAGS_TABLE.'
112  WHERE id IN ('.implode(',', $_POST['tags']).')
113;';
114  $tag_names = array_from_query($query, 'name');
115 
116  $query = '
117DELETE
118  FROM '.IMAGE_TAG_TABLE.'
119  WHERE tag_id IN ('.implode(',', $_POST['tags']).')
120;';
121  pwg_query($query);
122 
123  $query = '
124DELETE
125  FROM '.TAGS_TABLE.'
126  WHERE id IN ('.implode(',', $_POST['tags']).')
127;';
128  pwg_query($query);
129 
130  array_push(
131    $page['infos'],
[1932]132    l10n_dec(
[5036]133      'The following tag was deleted', 
[1932]134      'The %d following tags were deleted',
135      count($tag_names)).' : '.
[1119]136      implode(', ', $tag_names)
137    );
138}
139
140// +-----------------------------------------------------------------------+
[8762]141// |                           delete orphan tags                          |
142// +-----------------------------------------------------------------------+
143
144if (isset($_GET['action']) and 'delete_orphans' == $_GET['action'])
145{
146  check_pwg_token();
147 
148  delete_orphan_tags();
149  $_SESSION['page_infos'] = array(l10n('Orphan tags deleted'));
150  redirect(get_root_url().'admin.php?page=tags');
151}
152
153// +-----------------------------------------------------------------------+
[1119]154// |                               add a tag                               |
155// +-----------------------------------------------------------------------+
156
[8126]157if (isset($_POST['add']) and !empty($_POST['add_tag']))
[1119]158{
[2098]159  $tag_name = $_POST['add_tag'];
[1119]160
[1452]161  // does the tag already exists?
[1119]162  $query = '
163SELECT id
164  FROM '.TAGS_TABLE.'
[1717]165  WHERE name = \''.$tag_name.'\'
[1119]166;';
167  $existing_tags = array_from_query($query, 'id');
168
169  if (count($existing_tags) == 0)
170  {
171    mass_inserts(
172      TAGS_TABLE,
173      array('name', 'url_name'),
174      array(
175        array(
[1717]176          'name' => $tag_name,
[11317]177          'url_name' => str2url(trigger_event('render_tag_url', $tag_name)),
[1119]178          )
179        )
180      );
181   
182    array_push(
183      $page['infos'],
184      sprintf(
[5036]185        l10n('Tag "%s" was added'),
[1717]186        stripslashes($tag_name)
[1119]187        )
188      );
189  }
190  else
191  {
192    array_push(
193      $page['errors'],
194      sprintf(
[5036]195        l10n('Tag "%s" already exists'),
[1717]196        stripslashes($tag_name)
[1119]197        )
198      );
199  }
200}
201
202// +-----------------------------------------------------------------------+
203// |                             template init                             |
204// +-----------------------------------------------------------------------+
205
[2530]206$template->set_filenames(array('tags' => 'tags.tpl'));
[1119]207
[2277]208$template->assign(
[1119]209  array(
[5195]210    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=tags',
211    'PWG_TOKEN' => get_pwg_token(),
[1119]212    )
213  );
214
215// +-----------------------------------------------------------------------+
[8762]216// |                              orphan tags                              |
217// +-----------------------------------------------------------------------+
218
219$orphan_tags = get_orphan_tags();
220
221$orphan_tag_names = array();
222foreach ($orphan_tags as $tag)
223{
[11487]224  array_push($orphan_tag_names, trigger_event('render_tag_name', $tag['name']));
[8762]225}
226
227if (count($orphan_tag_names) > 0)
228{
229  array_push(
230    $page['warnings'],
231    sprintf(
232      l10n('You have %d orphan tags: %s.').' <a href="%s">'.l10n('Delete orphan tags').'</a>',
233      count($orphan_tag_names),
234      implode(', ', $orphan_tag_names),
235      get_root_url().'admin.php?page=tags&amp;action=delete_orphans&amp;pwg_token='.get_pwg_token()
236      )
237    );
238}
239
240// +-----------------------------------------------------------------------+
[1119]241// |                             form creation                             |
242// +-----------------------------------------------------------------------+
243
[2277]244$template->assign(
[1119]245  array(
246    'TAG_SELECTION' => get_html_tag_selection(
247      get_all_tags(),
248      'tags'
249      ),
250    )
251  );
252
253if (isset($_POST['edit']) and isset($_POST['tags']))
254{
[2277]255  $template->assign(
[1119]256    array(
[2277]257      'EDIT_TAGS_LIST' => implode(',', $_POST['tags']),
[1119]258      )
259    );
260
261  $query = '
262SELECT id, name
263  FROM '.TAGS_TABLE.'
264  WHERE id IN ('.implode(',', $_POST['tags']).')
265;';
266  $result = pwg_query($query);
[4325]267  while ($row = pwg_db_fetch_assoc($result))
[1119]268  {
269    $name_of[ $row['id'] ] = $row['name'];
270  }
271
272  foreach ($_POST['tags'] as $tag_id)
273  {
[2277]274    $template->append(
275      'tags',
[1119]276      array(
277        'ID' => $tag_id,
278        'NAME' => $name_of[$tag_id],
279        )
280      );
281  }
282}
283
284// +-----------------------------------------------------------------------+
285// |                           sending html code                           |
286// +-----------------------------------------------------------------------+
287
288$template->assign_var_from_handle('ADMIN_CONTENT', 'tags');
289
290?>
Note: See TracBrowser for help on using the repository browser.