source: trunk/admin/tags.php @ 2277

Last change on this file since 2277 was 2277, checked in by plg, 16 years ago

Modification: admin/tags goes smarty

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 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 2277 2008-03-12 22:23:12Z plg $
8// | last update   : $Date: 2008-03-12 22:23:12 +0000 (Wed, 12 Mar 2008) $
9// | last modifier : $Author: plg $
10// | revision      : $Revision: 2277 $
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    $tag_name = stripslashes($_POST['tag_name-'.$tag_id]);
65
66    if ($tag_name != $current_name_of[$tag_id])
67    {
68      if (in_array($tag_name, $existing_names))
69      {
70        array_push(
71          $page['errors'],
72          sprintf(
73            l10n('Tag "%s" already exists'),
74            $tag_name
75            )
76          );
77      }
78      else if (!empty($tag_name))
79      {
80        array_push(
81          $updates,
82          array(
83            'id' => $tag_id,
84            'name' => addslashes($tag_name),
85            'url_name' => str2url($tag_name),
86            )
87          );
88      }
89    }
90  }
91  mass_updates(
92    TAGS_TABLE,
93    array(
94      'primary' => array('id'),
95      'update' => array('name', 'url_name'),
96      ),
97    $updates
98    );
99}
100
101// +-----------------------------------------------------------------------+
102// |                               delete tags                             |
103// +-----------------------------------------------------------------------+
104
105if (isset($_POST['delete']) and isset($_POST['tags']) and !is_adviser())
106{
107  $query = '
108SELECT name
109  FROM '.TAGS_TABLE.'
110  WHERE id IN ('.implode(',', $_POST['tags']).')
111;';
112  $tag_names = array_from_query($query, 'name');
113 
114  $query = '
115DELETE
116  FROM '.IMAGE_TAG_TABLE.'
117  WHERE tag_id IN ('.implode(',', $_POST['tags']).')
118;';
119  pwg_query($query);
120 
121  $query = '
122DELETE
123  FROM '.TAGS_TABLE.'
124  WHERE id IN ('.implode(',', $_POST['tags']).')
125;';
126  pwg_query($query);
127 
128  array_push(
129    $page['infos'],
130    l10n_dec(
131      'The %d following tag were deleted', 
132      'The %d following tags were deleted',
133      count($tag_names)).' : '.
134      implode(', ', $tag_names)
135    );
136}
137
138// +-----------------------------------------------------------------------+
139// |                               add a tag                               |
140// +-----------------------------------------------------------------------+
141
142if (isset($_POST['add']) and !empty($_POST['add_tag']) and !is_adviser())
143{
144  $tag_name = $_POST['add_tag'];
145
146  // does the tag already exists?
147  $query = '
148SELECT id
149  FROM '.TAGS_TABLE.'
150  WHERE name = \''.$tag_name.'\'
151;';
152  $existing_tags = array_from_query($query, 'id');
153
154  if (count($existing_tags) == 0)
155  {
156    mass_inserts(
157      TAGS_TABLE,
158      array('name', 'url_name'),
159      array(
160        array(
161          'name' => $tag_name,
162          'url_name' => str2url($tag_name),
163          )
164        )
165      );
166   
167    array_push(
168      $page['infos'],
169      sprintf(
170        l10n('Tag "%s" was added'),
171        stripslashes($tag_name)
172        )
173      );
174  }
175  else
176  {
177    array_push(
178      $page['errors'],
179      sprintf(
180        l10n('Tag "%s" already exists'),
181        stripslashes($tag_name)
182        )
183      );
184  }
185}
186
187// +-----------------------------------------------------------------------+
188// |                             template init                             |
189// +-----------------------------------------------------------------------+
190
191$template->set_filenames(array('tags' => 'admin/tags.tpl'));
192
193$template->assign(
194  array(
195    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=tags'
196    )
197  );
198
199// +-----------------------------------------------------------------------+
200// |                             form creation                             |
201// +-----------------------------------------------------------------------+
202
203$template->assign(
204  array(
205    'TAG_SELECTION' => get_html_tag_selection(
206      get_all_tags(),
207      'tags'
208      ),
209    )
210  );
211
212if (isset($_POST['edit']) and isset($_POST['tags']))
213{
214  $template->assign(
215    array(
216      'EDIT_TAGS_LIST' => implode(',', $_POST['tags']),
217      )
218    );
219
220  $query = '
221SELECT id, name
222  FROM '.TAGS_TABLE.'
223  WHERE id IN ('.implode(',', $_POST['tags']).')
224;';
225  $result = pwg_query($query);
226  while ($row = mysql_fetch_array($result))
227  {
228    $name_of[ $row['id'] ] = $row['name'];
229  }
230
231  foreach ($_POST['tags'] as $tag_id)
232  {
233    $template->append(
234      'tags',
235      array(
236        'ID' => $tag_id,
237        'NAME' => $name_of[$tag_id],
238        )
239      );
240  }
241}
242
243// +-----------------------------------------------------------------------+
244// |                           sending html code                           |
245// +-----------------------------------------------------------------------+
246
247$template->assign_var_from_handle('ADMIN_CONTENT', 'tags');
248
249?>
Note: See TracBrowser for help on using the repository browser.