source: trunk/admin/cat_modify.php @ 825

Last change on this file since 825 was 825, checked in by plg, 19 years ago
  • improvement : screen admin/picture_modify rewritten. Presentation copied from admin/cat_modify : fieldsets regroup fields. Ability to synchronize metadata for the displayed item.
  • bug 110 fixed : "return to element view from element edition fails depending on permissions". If a reachable (for the connected admin) category is available, a "jump to" link is displayed, by default, using the category given in URL.
  • bug fixed : in mass_updates function, the first item of $fieldsupdate has not always 0 for id (as in any array).
  • modification : get_keywords function understands spaces as separator, allow less than 3 chars keywords, allow quotes.
  • new : ability to allow HTML in picture or category description (false by default)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-08-18 17:59:00 +0000 (Thu, 18 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 825 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28if (!defined('PHPWG_ROOT_PATH'))
29{
30  die('Hacking attempt!');
31}
32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33//---------------------------------------------------------------- verification
34if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) )
35{
36  $_GET['cat_id'] = '-1';
37}
38
39$template->set_filenames( array('categories'=>'admin/cat_modify.tpl') );
40
41//--------------------------------------------------------- form criteria check
42if (isset($_POST['submit']))
43{
44  $data =
45    array(
46      'id' => $_GET['cat_id'],
47      'name' => @$_POST['name'],
48      'commentable' => $_POST['commentable'],
49      'uploadable' =>
50        isset($_POST['uploadable']) ? $_POST['uploadable'] : 'false',
51      'comment' =>
52        $conf['allow_html_descriptions'] ?
53          @$_POST['comment'] : strip_tags(@$_POST['comment'])
54      );
55
56  mass_updates(
57    CATEGORIES_TABLE,
58    array(
59      'primary' => array('id'),
60      'update' => array_diff(array_keys($data), array('id'))
61      ),
62    array($data)
63    );
64 
65  set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
66  set_cat_status(array($_GET['cat_id']), $_POST['status']);
67
68  if (isset($_POST['parent']))
69  {
70    move_category($_GET['cat_id'], $_POST['parent']);
71  }
72
73  array_push($page['infos'], $lang['editcat_confirm']);
74}
75else if (isset($_POST['set_random_representant']))
76{
77  set_random_representant(array($_GET['cat_id']));
78}
79else if (isset($_POST['delete_representant']))
80{
81  $query = '
82UPDATE '.CATEGORIES_TABLE.'
83  SET representative_picture_id = NULL
84  WHERE id = '.$_GET['cat_id'].'
85;';
86  pwg_query($query);
87}
88
89$query = '
90SELECT *
91  FROM '.CATEGORIES_TABLE.'
92  WHERE id = '.$_GET['cat_id'].'
93;';
94$category = mysql_fetch_array( pwg_query( $query ) );
95// nullable fields
96foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
97{
98  if (!isset($category[$nullable]))
99  {
100    $category[$nullable] = '';
101  }
102}
103
104$category['is_virtual'] = empty($category['dir']) ? true : false;
105
106// Navigation path
107$url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&amp;parent_id=';
108$navigation = '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.'admin.php?page=cat_list').'">';
109$navigation.= $lang['home'].'</a>'.$conf['level_separator'];
110
111$navigation.= get_cat_display_name_cache(
112  $category['uppercats'],
113  $url);
114
115$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
116$status = ($category['status']=='public')?'STATUS_PUBLIC':'STATUS_PRIVATE'; 
117$lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED';
118
119if ($category['commentable'] == 'true')
120{
121  $commentable = 'COMMENTABLE_TRUE';
122}
123else
124{
125  $commentable = 'COMMENTABLE_FALSE';
126}
127if ($category['uploadable'] == 'true')
128{
129  $uploadable = 'UPLOADABLE_TRUE';
130}
131else
132{
133  $uploadable = 'UPLOADABLE_FALSE';
134}
135
136//----------------------------------------------------- template initialization
137
138$base_url = PHPWG_ROOT_PATH.'admin.php?page=';
139$cat_list_url = $base_url.'cat_list';
140 
141$self_url = $cat_list_url;
142if (!empty($category['id_uppercat']))
143{
144  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
145}
146
147$template->assign_vars(array( 
148  'CATEGORIES_NAV'=>$navigation,
149  'CAT_NAME'=>$category['name'],
150  'CAT_COMMENT'=>$category['comment'],
151 
152  $status=>'checked="checked"',
153  $lock=>'checked="checked"',
154  $commentable=>'checked="checked"',
155  $uploadable=>'checked="checked"',
156 
157  'L_EDIT_NAME'=>$lang['name'],
158  'L_STORAGE'=>$lang['storage'],
159  'L_REMOTE_SITE'=>$lang['remote_site'],
160  'L_EDIT_COMMENT'=>$lang['description'],
161  'L_EDIT_CAT_OPTIONS'=>$lang['cat_options'],
162  'L_EDIT_STATUS'=>$lang['conf_access'],
163  'L_EDIT_STATUS_INFO'=>$lang['cat_access_info'],
164  'L_STATUS_PUBLIC'=>$lang['public'],
165  'L_STATUS_PRIVATE'=>$lang['private'],
166  'L_EDIT_LOCK'=>$lang['lock'],
167  'L_EDIT_LOCK_INFO'=>$lang['editcat_lock_info'],
168  'L_EDIT_UPLOADABLE'=>$lang['editcat_uploadable'],
169  'L_EDIT_UPLOADABLE_INFO'=>$lang['editcat_uploadable_info'],
170  'L_EDIT_COMMENTABLE'=>$lang['comments'],
171  'L_EDIT_COMMENTABLE_INFO'=>$lang['editcat_commentable_info'],
172  'L_YES'=>$lang['yes'],
173  'L_NO'=>$lang['no'],
174  'L_SUBMIT'=>$lang['submit'],
175  'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
176
177  'U_JUMPTO'=>
178    add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']),
179  'U_CHILDREN'=>
180    add_session_id($cat_list_url.'&amp;parent_id='.$category['id']),
181   
182  'F_ACTION'=>add_session_id($form_action)
183  ));
184
185
186if ('private' == $category['status'])
187{
188  $template->assign_block_vars(
189    'permissions',
190    array(
191      'URL'=>add_session_id($base_url.'cat_perm&amp;cat='.$category['id'])
192        )
193    );
194}
195
196// manage category elements link
197if ($category['nb_images'] > 0)
198{
199  $template->assign_block_vars(
200    'elements',
201    array(
202      'URL'=>add_session_id($base_url.'element_set&amp;cat='.$category['id'])
203      )
204    );
205}
206
207// representant management
208if ($category['nb_images'] > 0
209    or !empty($category['representative_picture_id']))
210{
211  $template->assign_block_vars('representant', array());
212
213  // picture to display : the identified representant or the generic random
214  // representant ?
215  if (!empty($category['representative_picture_id']))
216  {
217    $query = '
218SELECT tn_ext,path
219  FROM '.IMAGES_TABLE.'
220  WHERE id = '.$category['representative_picture_id'].'
221;';
222    $row = mysql_fetch_array(pwg_query($query));
223    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
224    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
225    $url.= '&amp;image_id='.$category['representative_picture_id'];
226 
227    $template->assign_block_vars(
228      'representant.picture',
229      array(
230        'SRC' => $src,
231        'URL' => $url
232        )
233      );
234  }
235  else // $category['nb_images'] > 0
236  {
237    $template->assign_block_vars('representant.random', array());
238  }
239
240  // can the admin choose to set a new random representant ?
241  if ($category['nb_images'] > 0)
242  {
243    $template->assign_block_vars('representant.set_random', array());
244  }
245
246  // can the admin delete the current representant ?
247  if (
248    ($category['nb_images'] > 0
249     and $conf['allow_random_representative'])
250    or
251    ($category['nb_images'] == 0
252     and !empty($category['representative_picture_id'])))
253  {
254    $template->assign_block_vars('representant.delete_representant', array());
255  }
256}
257
258if (!$category['is_virtual']) //!empty($category['dir']))
259{
260  $template->assign_block_vars(
261    'storage',
262    array('CATEGORY_DIR'=>preg_replace('/\/$/',
263                                       '',
264                                       get_complete_dir($category['id']))));
265  $template->assign_block_vars('upload' ,array());
266}
267else
268{
269  $template->assign_block_vars(
270    'delete',
271    array(
272      'URL'=>add_session_id($self_url.'&amp;delete='.$category['id'])
273      )
274    );
275
276  $template->assign_block_vars('move', array());
277
278  // the category can be moved in any category but in itself, in any
279  // sub-category
280  $unmovables = get_subcat_ids(array($category['id']));
281 
282  $blockname = 'move.parent_option';
283
284  $template->assign_block_vars(
285    $blockname,
286    array(
287      'SELECTED'
288        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
289      'VALUE'=> 0,
290      'OPTION' => '------------'
291      )
292    );
293 
294  $query = '
295SELECT id,name,uppercats,global_rank
296  FROM '.CATEGORIES_TABLE.'
297  WHERE id NOT IN ('.implode(',', $unmovables).')
298;';
299 
300  display_select_cat_wrapper(
301    $query,
302    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
303    $blockname
304    );
305}
306
307if (is_numeric($category['site_id']) and $category['site_id'] != 1)
308{
309  $query = '
310SELECT galleries_url
311  FROM '.SITES_TABLE.'
312  WHERE id = '.$category['site_id'].'
313;';
314  list($galleries_url) = mysql_fetch_array(pwg_query($query));
315  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
316}
317
318//----------------------------------------------------------- sending html code
319$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
320?>
Note: See TracBrowser for help on using the repository browser.