source: trunk/admin/cat_modify.php @ 849

Last change on this file since 849 was 834, checked in by plg, 19 years ago
  • improvement : standardization of categories navigation bar on top of administration screen element_set_(global|unit), cat_modify, cat_list, cat_perm.
  • new : direct link to admin/cat_modify from category.php.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 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-19 17:00:20 +0000 (Fri, 19 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 834 $
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_modify&amp;cat_id=';
108
109$navigation = get_cat_display_name_cache(
110  $category['uppercats'],
111  PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='
112  );
113
114$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
115$status = ($category['status']=='public')?'STATUS_PUBLIC':'STATUS_PRIVATE'; 
116$lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED';
117
118if ($category['commentable'] == 'true')
119{
120  $commentable = 'COMMENTABLE_TRUE';
121}
122else
123{
124  $commentable = 'COMMENTABLE_FALSE';
125}
126if ($category['uploadable'] == 'true')
127{
128  $uploadable = 'UPLOADABLE_TRUE';
129}
130else
131{
132  $uploadable = 'UPLOADABLE_FALSE';
133}
134
135//----------------------------------------------------- template initialization
136
137$base_url = PHPWG_ROOT_PATH.'admin.php?page=';
138$cat_list_url = $base_url.'cat_list';
139 
140$self_url = $cat_list_url;
141if (!empty($category['id_uppercat']))
142{
143  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
144}
145
146$template->assign_vars(array( 
147  'CATEGORIES_NAV'=>$navigation,
148  'CAT_NAME'=>$category['name'],
149  'CAT_COMMENT'=>$category['comment'],
150 
151  $status=>'checked="checked"',
152  $lock=>'checked="checked"',
153  $commentable=>'checked="checked"',
154  $uploadable=>'checked="checked"',
155 
156  'L_EDIT_NAME'=>$lang['name'],
157  'L_STORAGE'=>$lang['storage'],
158  'L_REMOTE_SITE'=>$lang['remote_site'],
159  'L_EDIT_COMMENT'=>$lang['description'],
160  'L_EDIT_CAT_OPTIONS'=>$lang['cat_options'],
161  'L_EDIT_STATUS'=>$lang['conf_access'],
162  'L_EDIT_STATUS_INFO'=>$lang['cat_access_info'],
163  'L_STATUS_PUBLIC'=>$lang['public'],
164  'L_STATUS_PRIVATE'=>$lang['private'],
165  'L_EDIT_LOCK'=>$lang['lock'],
166  'L_EDIT_LOCK_INFO'=>$lang['editcat_lock_info'],
167  'L_EDIT_UPLOADABLE'=>$lang['editcat_uploadable'],
168  'L_EDIT_UPLOADABLE_INFO'=>$lang['editcat_uploadable_info'],
169  'L_EDIT_COMMENTABLE'=>$lang['comments'],
170  'L_EDIT_COMMENTABLE_INFO'=>$lang['editcat_commentable_info'],
171  'L_YES'=>$lang['yes'],
172  'L_NO'=>$lang['no'],
173  'L_SUBMIT'=>$lang['submit'],
174  'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
175
176  'U_JUMPTO'=>
177    add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']),
178  'U_CHILDREN'=>
179    add_session_id($cat_list_url.'&amp;parent_id='.$category['id']),
180   
181  'F_ACTION'=>add_session_id($form_action)
182  ));
183
184
185if ('private' == $category['status'])
186{
187  $template->assign_block_vars(
188    'permissions',
189    array(
190      'URL'=>add_session_id($base_url.'cat_perm&amp;cat='.$category['id'])
191        )
192    );
193}
194
195// manage category elements link
196if ($category['nb_images'] > 0)
197{
198  $template->assign_block_vars(
199    'elements',
200    array(
201      'URL'=>add_session_id($base_url.'element_set&amp;cat='.$category['id'])
202      )
203    );
204}
205
206// representant management
207if ($category['nb_images'] > 0
208    or !empty($category['representative_picture_id']))
209{
210  $template->assign_block_vars('representant', array());
211
212  // picture to display : the identified representant or the generic random
213  // representant ?
214  if (!empty($category['representative_picture_id']))
215  {
216    $query = '
217SELECT tn_ext,path
218  FROM '.IMAGES_TABLE.'
219  WHERE id = '.$category['representative_picture_id'].'
220;';
221    $row = mysql_fetch_array(pwg_query($query));
222    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
223    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
224    $url.= '&amp;image_id='.$category['representative_picture_id'];
225 
226    $template->assign_block_vars(
227      'representant.picture',
228      array(
229        'SRC' => $src,
230        'URL' => $url
231        )
232      );
233  }
234  else // $category['nb_images'] > 0
235  {
236    $template->assign_block_vars('representant.random', array());
237  }
238
239  // can the admin choose to set a new random representant ?
240  if ($category['nb_images'] > 0)
241  {
242    $template->assign_block_vars('representant.set_random', array());
243  }
244
245  // can the admin delete the current representant ?
246  if (
247    ($category['nb_images'] > 0
248     and $conf['allow_random_representative'])
249    or
250    ($category['nb_images'] == 0
251     and !empty($category['representative_picture_id'])))
252  {
253    $template->assign_block_vars('representant.delete_representant', array());
254  }
255}
256
257if (!$category['is_virtual']) //!empty($category['dir']))
258{
259  $template->assign_block_vars(
260    'storage',
261    array('CATEGORY_DIR'=>preg_replace('/\/$/',
262                                       '',
263                                       get_complete_dir($category['id']))));
264  $template->assign_block_vars('upload' ,array());
265}
266else
267{
268  $template->assign_block_vars(
269    'delete',
270    array(
271      'URL'=>add_session_id($self_url.'&amp;delete='.$category['id'])
272      )
273    );
274
275  $template->assign_block_vars('move', array());
276
277  // the category can be moved in any category but in itself, in any
278  // sub-category
279  $unmovables = get_subcat_ids(array($category['id']));
280 
281  $blockname = 'move.parent_option';
282
283  $template->assign_block_vars(
284    $blockname,
285    array(
286      'SELECTED'
287        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
288      'VALUE'=> 0,
289      'OPTION' => '------------'
290      )
291    );
292 
293  $query = '
294SELECT id,name,uppercats,global_rank
295  FROM '.CATEGORIES_TABLE.'
296  WHERE id NOT IN ('.implode(',', $unmovables).')
297;';
298 
299  display_select_cat_wrapper(
300    $query,
301    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
302    $blockname
303    );
304}
305
306if (is_numeric($category['site_id']) and $category['site_id'] != 1)
307{
308  $query = '
309SELECT galleries_url
310  FROM '.SITES_TABLE.'
311  WHERE id = '.$category['site_id'].'
312;';
313  list($galleries_url) = mysql_fetch_array(pwg_query($query));
314  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
315}
316
317//----------------------------------------------------------- sending html code
318$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
319?>
Note: See TracBrowser for help on using the repository browser.