source: branches/2.1/admin/tags.php @ 6276

Last change on this file since 6276 was 6276, checked in by plg, 14 years ago

merge r6265 from trunk to branch 2.1

Correct text alignement in .infos, .errors
30px => 53px

File size: 6.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
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
32if (!empty($_POST))
33{
34  check_pwg_token();
35}
36
37// +-----------------------------------------------------------------------+
38// |                                edit tags                              |
39// +-----------------------------------------------------------------------+
40
41if (isset($_POST['submit']) and !is_adviser())
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);
57  while ($row = pwg_db_fetch_assoc($result))
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  {
66    $tag_name = stripslashes($_POST['tag_name-'.$tag_id]);
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(
75            l10n('Tag "%s" already exists'),
76            $tag_name
77            )
78          );
79      }
80      else if (!empty($tag_name))
81      {
82        array_push(
83          $updates,
84          array(
85            'id' => $tag_id,
86            'name' => addslashes($tag_name),
87            'url_name' => str2url($tag_name),
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
107if (isset($_POST['delete']) and isset($_POST['tags']) and !is_adviser())
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'],
132    l10n_dec(
133      'The following tag was deleted', 
134      'The %d following tags were deleted',
135      count($tag_names)).' : '.
136      implode(', ', $tag_names)
137    );
138}
139
140// +-----------------------------------------------------------------------+
141// |                               add a tag                               |
142// +-----------------------------------------------------------------------+
143
144if (isset($_POST['add']) and !empty($_POST['add_tag']) and !is_adviser())
145{
146  $tag_name = $_POST['add_tag'];
147
148  // does the tag already exists?
149  $query = '
150SELECT id
151  FROM '.TAGS_TABLE.'
152  WHERE name = \''.$tag_name.'\'
153;';
154  $existing_tags = array_from_query($query, 'id');
155
156  if (count($existing_tags) == 0)
157  {
158    mass_inserts(
159      TAGS_TABLE,
160      array('name', 'url_name'),
161      array(
162        array(
163          'name' => $tag_name,
164          'url_name' => str2url($tag_name),
165          )
166        )
167      );
168   
169    array_push(
170      $page['infos'],
171      sprintf(
172        l10n('Tag "%s" was added'),
173        stripslashes($tag_name)
174        )
175      );
176  }
177  else
178  {
179    array_push(
180      $page['errors'],
181      sprintf(
182        l10n('Tag "%s" already exists'),
183        stripslashes($tag_name)
184        )
185      );
186  }
187}
188
189// +-----------------------------------------------------------------------+
190// |                             template init                             |
191// +-----------------------------------------------------------------------+
192
193$template->set_filenames(array('tags' => 'tags.tpl'));
194
195$template->assign(
196  array(
197    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=tags',
198    'PWG_TOKEN' => get_pwg_token(),
199    )
200  );
201
202// +-----------------------------------------------------------------------+
203// |                             form creation                             |
204// +-----------------------------------------------------------------------+
205
206$template->assign(
207  array(
208    'TAG_SELECTION' => get_html_tag_selection(
209      get_all_tags(),
210      'tags'
211      ),
212    )
213  );
214
215if (isset($_POST['edit']) and isset($_POST['tags']))
216{
217  $template->assign(
218    array(
219      'EDIT_TAGS_LIST' => implode(',', $_POST['tags']),
220      )
221    );
222
223  $query = '
224SELECT id, name
225  FROM '.TAGS_TABLE.'
226  WHERE id IN ('.implode(',', $_POST['tags']).')
227;';
228  $result = pwg_query($query);
229  while ($row = pwg_db_fetch_assoc($result))
230  {
231    $name_of[ $row['id'] ] = $row['name'];
232  }
233
234  foreach ($_POST['tags'] as $tag_id)
235  {
236    $template->append(
237      'tags',
238      array(
239        'ID' => $tag_id,
240        'NAME' => $name_of[$tag_id],
241        )
242      );
243  }
244}
245
246// +-----------------------------------------------------------------------+
247// |                           sending html code                           |
248// +-----------------------------------------------------------------------+
249
250$template->assign_var_from_handle('ADMIN_CONTENT', 'tags');
251
252?>
Note: See TracBrowser for help on using the repository browser.