source: trunk/admin/cat_modify.php @ 1121

Last change on this file since 1121 was 1121, checked in by plg, 18 years ago

feature deleted: code for categories link was too complicated for such a
simple fature. Replaced by static association. Links are not persistent
anymore.

modification removed: #image_category.is_storage replaced by
#images.storage_category_id as in branche 1.5..

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-04-04 22:29:35 +0000 (Tue, 04 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1121 $
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}
32
33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40//---------------------------------------------------------------- verification
41if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) )
42{
43  $_GET['cat_id'] = '-1';
44}
45
46$template->set_filenames( array('categories'=>'admin/cat_modify.tpl') );
47
48//--------------------------------------------------------- form criteria check
49if (isset($_POST['submit']))
50{
51  $data =
52    array(
53      'id' => $_GET['cat_id'],
54      'name' => @$_POST['name'],
55      'commentable' => $_POST['commentable'],
56      'uploadable' =>
57        isset($_POST['uploadable']) ? $_POST['uploadable'] : 'false',
58      'comment' =>
59        $conf['allow_html_descriptions'] ?
60          @$_POST['comment'] : strip_tags(@$_POST['comment'])
61      );
62
63  mass_updates(
64    CATEGORIES_TABLE,
65    array(
66      'primary' => array('id'),
67      'update' => array_diff(array_keys($data), array('id'))
68      ),
69    array($data)
70    );
71 
72  set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
73  set_cat_status(array($_GET['cat_id']), $_POST['status']);
74
75  if (isset($_POST['parent']))
76  {
77    move_categories(
78      array($_GET['cat_id']),
79      $_POST['parent']
80      );
81  }
82
83  array_push($page['infos'], $lang['editcat_confirm']);
84}
85else if (isset($_POST['set_random_representant']))
86{
87  set_random_representant(array($_GET['cat_id']));
88}
89else if (isset($_POST['delete_representant']))
90{
91  $query = '
92UPDATE '.CATEGORIES_TABLE.'
93  SET representative_picture_id = NULL
94  WHERE id = '.$_GET['cat_id'].'
95;';
96  pwg_query($query);
97}
98else if (isset($_POST['submitAdd']))
99{
100  $output_create = create_virtual_category(
101    $_POST['virtual_name'],
102    (0 == $_POST['parent'] ? null : $_POST['parent'])
103    );
104 
105  if (isset($output_create['error']))
106  {
107    array_push($page['errors'], $output_create['error']);
108  }
109  else
110  {
111    // Virtual category creation succeeded
112    //
113    // Add the information in the information list
114    array_push($page['infos'], $output_create['info']);
115   
116    // Link the new category to the current category
117    associate_categories_to_categories(
118      array($_GET['cat_id']),
119      array($output_create['id'])
120      );
121
122    // information
123    array_push(
124      $page['infos'],
125      sprintf(
126        l10n('Category elements associated to the following categories: %s'),
127        '<ul><li>'
128        .get_cat_display_name_from_id($output_create['id'])
129        .'</li></ul>'
130        )
131      );
132  }
133}
134else if (isset($_POST['submitDestinations'])
135         and isset($_POST['destinations'])
136         and count($_POST['destinations']) > 0)
137{
138  associate_categories_to_categories(
139    array($_GET['cat_id']),
140    $_POST['destinations']
141    );
142
143  $category_names = array();
144  foreach ($_POST['destinations'] as $category_id)
145  {
146    array_push(
147      $category_names,
148      get_cat_display_name_from_id($category_id)
149      );
150  }
151
152  array_push(
153    $page['infos'],
154    sprintf(
155      l10n('Category elements associated to the following categories: %s'),
156      '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
157      )
158    );
159}
160
161$query = '
162SELECT *
163  FROM '.CATEGORIES_TABLE.'
164  WHERE id = '.$_GET['cat_id'].'
165;';
166$category = mysql_fetch_array( pwg_query( $query ) );
167// nullable fields
168foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
169{
170  if (!isset($category[$nullable]))
171  {
172    $category[$nullable] = '';
173  }
174}
175
176$category['is_virtual'] = empty($category['dir']) ? true : false;
177
178// Navigation path
179$url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=';
180
181$navigation = get_cat_display_name_cache(
182  $category['uppercats'],
183  PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='
184  );
185
186$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
187$status = ($category['status']=='public')?'STATUS_PUBLIC':'STATUS_PRIVATE'; 
188$lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED';
189
190if ($category['commentable'] == 'true')
191{
192  $commentable = 'COMMENTABLE_TRUE';
193}
194else
195{
196  $commentable = 'COMMENTABLE_FALSE';
197}
198if ($category['uploadable'] == 'true')
199{
200  $uploadable = 'UPLOADABLE_TRUE';
201}
202else
203{
204  $uploadable = 'UPLOADABLE_FALSE';
205}
206
207//----------------------------------------------------- template initialization
208
209$base_url = PHPWG_ROOT_PATH.'admin.php?page=';
210$cat_list_url = $base_url.'cat_list';
211 
212$self_url = $cat_list_url;
213if (!empty($category['id_uppercat']))
214{
215  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
216}
217
218$template->assign_vars(
219  array( 
220    'CATEGORIES_NAV'     => $navigation,
221    'CAT_NAME'           => $category['name'],
222    'CAT_COMMENT'        => $category['comment'],
223   
224    $status              => 'checked="checked"',
225    $lock                => 'checked="checked"',
226    $commentable         => 'checked="checked"',
227    $uploadable          => 'checked="checked"',
228   
229    'L_EDIT_NAME'        => $lang['name'],
230    'L_STORAGE'          => $lang['storage'],
231    'L_REMOTE_SITE'      => $lang['remote_site'],
232    'L_EDIT_COMMENT'     => $lang['description'],
233    'L_EDIT_STATUS'      => $lang['conf_access'],
234    'L_STATUS_PUBLIC'    => $lang['public'],
235    'L_STATUS_PRIVATE'   => $lang['private'],
236    'L_EDIT_LOCK'        => $lang['lock'],
237    'L_EDIT_UPLOADABLE'  => $lang['editcat_uploadable'],
238    'L_EDIT_COMMENTABLE' => $lang['comments'],
239    'L_YES'              => $lang['yes'],
240    'L_NO'               => $lang['no'],
241    'L_SUBMIT'           => $lang['submit'],
242    'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
243
244    'U_JUMPTO' => make_index_url(
245      array(
246        'category' => $category['id'],
247        )
248      ),
249   
250    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
251    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_modify',
252   
253    'F_ACTION' => $form_action,
254    )
255  );
256
257
258if ('private' == $category['status'])
259{
260  $template->assign_block_vars(
261    'permissions',
262    array(
263      'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
264        )
265    );
266}
267
268// manage category elements link
269if ($category['nb_images'] > 0)
270{
271  $template->assign_block_vars(
272    'elements',
273    array(
274      'URL'=>$base_url.'element_set&amp;cat='.$category['id']
275      )
276    );
277}
278
279// representant management
280if ($category['nb_images'] > 0
281    or !empty($category['representative_picture_id']))
282{
283  $template->assign_block_vars('representant', array());
284
285  // picture to display : the identified representant or the generic random
286  // representant ?
287  if (!empty($category['representative_picture_id']))
288  {
289    $query = '
290SELECT tn_ext,path
291  FROM '.IMAGES_TABLE.'
292  WHERE id = '.$category['representative_picture_id'].'
293;';
294    $row = mysql_fetch_array(pwg_query($query));
295    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
296    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
297    $url.= '&amp;image_id='.$category['representative_picture_id'];
298 
299    $template->assign_block_vars(
300      'representant.picture',
301      array(
302        'SRC' => $src,
303        'URL' => $url
304        )
305      );
306  }
307  else // $category['nb_images'] > 0
308  {
309    $template->assign_block_vars('representant.random', array());
310  }
311
312  // can the admin choose to set a new random representant ?
313  if ($category['nb_images'] > 0)
314  {
315    $template->assign_block_vars('representant.set_random', array());
316  }
317
318  // can the admin delete the current representant ?
319  if (
320    ($category['nb_images'] > 0
321     and $conf['allow_random_representative'])
322    or
323    ($category['nb_images'] == 0
324     and !empty($category['representative_picture_id'])))
325  {
326    $template->assign_block_vars('representant.delete_representant', array());
327  }
328}
329
330if (!$category['is_virtual'])
331{
332  $template->assign_block_vars(
333    'storage',
334    array('CATEGORY_DIR'=>preg_replace('/\/$/',
335                                       '',
336                                       get_complete_dir($category['id']))));
337}
338else
339{
340  $template->assign_block_vars(
341    'delete',
342    array(
343      'URL'=>$self_url.'&amp;delete='.$category['id']
344      )
345    );
346
347  $template->assign_block_vars('move', array());
348
349  // the category can be moved in any category but in itself, in any
350  // sub-category
351  $unmovables = get_subcat_ids(array($category['id']));
352 
353  $blockname = 'move.parent_option';
354
355  $template->assign_block_vars(
356    $blockname,
357    array(
358      'SELECTED'
359        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
360      'VALUE'=> 0,
361      'OPTION' => '------------'
362      )
363    );
364 
365  $query = '
366SELECT id,name,uppercats,global_rank
367  FROM '.CATEGORIES_TABLE.'
368  WHERE id NOT IN ('.implode(',', $unmovables).')
369;';
370 
371  display_select_cat_wrapper(
372    $query,
373    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
374    $blockname
375    );
376}
377
378$category['cat_dir'] = get_complete_dir($_GET['cat_id']);
379if (is_numeric($category['site_id']) and url_is_remote($category['cat_dir']) )
380{
381  $query = '
382SELECT galleries_url
383  FROM '.SITES_TABLE.'
384  WHERE id = '.$category['site_id'].'
385;';
386  list($galleries_url) = mysql_fetch_array(pwg_query($query));
387  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
388}
389
390if (!$category['is_virtual'] and !url_is_remote($category['cat_dir']) )
391{
392  $template->assign_block_vars('upload' ,array());
393}
394
395$blockname = 'category_option_parent';
396
397$template->assign_block_vars(
398  $blockname,
399  array(
400    'VALUE'=> 0,
401    'OPTION' => '------------'
402    )
403  );
404
405$query = '
406SELECT id,name,uppercats,global_rank
407  FROM '.CATEGORIES_TABLE.'
408;';
409
410display_select_cat_wrapper(
411  $query,
412  array(),
413  $blockname
414  );
415
416// destination categories
417$query = '
418SELECT id,name,uppercats,global_rank
419  FROM '.CATEGORIES_TABLE.'
420  WHERE id != '.$category['id'].'
421;';
422
423display_select_cat_wrapper(
424  $query,
425  array(),
426  'category_option_destination'
427  );
428
429
430//----------------------------------------------------------- sending html code
431$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
432?>
Note: See TracBrowser for help on using the repository browser.