source: trunk/admin/tags.php @ 1932

Last change on this file since 1932 was 1932, checked in by rub, 17 years ago

o add missing $lang
o use of l10n_dec
o normalize file header

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