source: trunk/admin/cat_modify.php @ 1072

Last change on this file since 1072 was 1072, checked in by rub, 18 years ago

Step 2 improvement issue 0000301:

o Add and use Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.5 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-03-09 22:46:28 +0000 (Thu, 09 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1072 $
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    $query = '
118INSERT
119  INTO '.CATEGORIES_LINK_TABLE.'
120  (source, destination)
121  VALUES
122  ('.$_GET['cat_id'].', '.$output_create['id'].')
123;';
124    pwg_query($query);
125
126    check_links(array($output_create['id']));
127    update_category(array($output_create['id']));
128  }
129}
130else if (isset($_POST['destination_trueify'])
131         and isset($_POST['destination_false'])
132         and count($_POST['destination_false']))
133{
134  $datas = array();
135 
136  foreach ($_POST['destination_false'] as $category_id)
137  {
138    array_push(
139      $datas,
140      array(
141        'source'      => $_GET['cat_id'],
142        'destination' => $category_id,
143        )
144      );
145  }
146 
147  mass_inserts(
148    CATEGORIES_LINK_TABLE,
149    array('source', 'destination'),
150    $datas
151    );
152
153  check_links($_POST['destination_false']);
154  update_category(
155    $_POST['destination_false'],
156    true                          // recursive update
157    );
158}
159else if (isset($_POST['destination_falsify'])
160         and isset($_POST['destination_true'])
161         and count($_POST['destination_true']))
162{
163  foreach ($_POST['destination_true'] as $destination)
164  {
165    delete_sources($destination, array($_GET['cat_id']));
166  }
167
168  update_category(
169    $_POST['destination_true'],
170    true                          // recursive update
171    );
172}
173else if (isset($_POST['source_trueify'])
174         and isset($_POST['source_false'])
175         and count($_POST['source_false']))
176{
177  $datas = array();
178 
179  foreach ($_POST['source_false'] as $category_id)
180  {
181    array_push(
182      $datas,
183      array(
184        'source'      => $category_id,
185        'destination' => $_GET['cat_id'],
186        )
187      );
188  }
189 
190  mass_inserts(
191    CATEGORIES_LINK_TABLE,
192    array('source', 'destination'),
193    $datas
194    );
195
196  check_links(array($_GET['cat_id']));
197  update_category(
198    array($_GET['cat_id']),
199    true                          // recursive update
200    );
201}
202else if (isset($_POST['source_falsify'])
203         and isset($_POST['source_true'])
204         and count($_POST['source_true']))
205{
206  delete_sources($_GET['cat_id'], $_POST['source_true']);
207 
208  update_category(
209    array($_GET['cat_id']),
210    true                          // recursive update
211    );
212}
213
214
215$query = '
216SELECT *
217  FROM '.CATEGORIES_TABLE.'
218  WHERE id = '.$_GET['cat_id'].'
219;';
220$category = mysql_fetch_array( pwg_query( $query ) );
221// nullable fields
222foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
223{
224  if (!isset($category[$nullable]))
225  {
226    $category[$nullable] = '';
227  }
228}
229
230$category['is_virtual'] = empty($category['dir']) ? true : false;
231
232// Navigation path
233$url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=';
234
235$navigation = get_cat_display_name_cache(
236  $category['uppercats'],
237  PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='
238  );
239
240$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
241$status = ($category['status']=='public')?'STATUS_PUBLIC':'STATUS_PRIVATE'; 
242$lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED';
243
244if ($category['commentable'] == 'true')
245{
246  $commentable = 'COMMENTABLE_TRUE';
247}
248else
249{
250  $commentable = 'COMMENTABLE_FALSE';
251}
252if ($category['uploadable'] == 'true')
253{
254  $uploadable = 'UPLOADABLE_TRUE';
255}
256else
257{
258  $uploadable = 'UPLOADABLE_FALSE';
259}
260
261//----------------------------------------------------- template initialization
262
263$base_url = PHPWG_ROOT_PATH.'admin.php?page=';
264$cat_list_url = $base_url.'cat_list';
265 
266$self_url = $cat_list_url;
267if (!empty($category['id_uppercat']))
268{
269  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
270}
271
272$template->assign_vars(array( 
273  'CATEGORIES_NAV'=>$navigation,
274  'CAT_NAME'=>$category['name'],
275  'CAT_COMMENT'=>$category['comment'],
276 
277  $status=>'checked="checked"',
278  $lock=>'checked="checked"',
279  $commentable=>'checked="checked"',
280  $uploadable=>'checked="checked"',
281 
282  'L_EDIT_NAME'=>$lang['name'],
283  'L_STORAGE'=>$lang['storage'],
284  'L_REMOTE_SITE'=>$lang['remote_site'],
285  'L_EDIT_COMMENT'=>$lang['description'],
286  'L_EDIT_STATUS'=>$lang['conf_access'],
287  'L_STATUS_PUBLIC'=>$lang['public'],
288  'L_STATUS_PRIVATE'=>$lang['private'],
289  'L_EDIT_LOCK'=>$lang['lock'],
290  'L_EDIT_UPLOADABLE'=>$lang['editcat_uploadable'],
291  'L_EDIT_COMMENTABLE'=>$lang['comments'],
292  'L_YES'=>$lang['yes'],
293  'L_NO'=>$lang['no'],
294  'L_SUBMIT'=>$lang['submit'],
295  'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
296
297  'U_JUMPTO'=>PHPWG_ROOT_PATH.'category.php?cat='.$category['id'],
298  'U_CHILDREN'=>$cat_list_url.'&amp;parent_id='.$category['id'],
299  'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_modify',
300   
301  'F_ACTION'=>$form_action
302  ));
303
304
305if ('private' == $category['status'])
306{
307  $template->assign_block_vars(
308    'permissions',
309    array(
310      'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
311        )
312    );
313}
314
315// manage category elements link
316if ($category['nb_images'] > 0)
317{
318  $template->assign_block_vars(
319    'elements',
320    array(
321      'URL'=>$base_url.'element_set&amp;cat='.$category['id']
322      )
323    );
324}
325
326// representant management
327if ($category['nb_images'] > 0
328    or !empty($category['representative_picture_id']))
329{
330  $template->assign_block_vars('representant', array());
331
332  // picture to display : the identified representant or the generic random
333  // representant ?
334  if (!empty($category['representative_picture_id']))
335  {
336    $query = '
337SELECT tn_ext,path
338  FROM '.IMAGES_TABLE.'
339  WHERE id = '.$category['representative_picture_id'].'
340;';
341    $row = mysql_fetch_array(pwg_query($query));
342    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
343    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
344    $url.= '&amp;image_id='.$category['representative_picture_id'];
345 
346    $template->assign_block_vars(
347      'representant.picture',
348      array(
349        'SRC' => $src,
350        'URL' => $url
351        )
352      );
353  }
354  else // $category['nb_images'] > 0
355  {
356    $template->assign_block_vars('representant.random', array());
357  }
358
359  // can the admin choose to set a new random representant ?
360  if ($category['nb_images'] > 0)
361  {
362    $template->assign_block_vars('representant.set_random', array());
363  }
364
365  // can the admin delete the current representant ?
366  if (
367    ($category['nb_images'] > 0
368     and $conf['allow_random_representative'])
369    or
370    ($category['nb_images'] == 0
371     and !empty($category['representative_picture_id'])))
372  {
373    $template->assign_block_vars('representant.delete_representant', array());
374  }
375}
376
377if (!$category['is_virtual']) //!empty($category['dir']))
378{
379  $template->assign_block_vars(
380    'storage',
381    array('CATEGORY_DIR'=>preg_replace('/\/$/',
382                                       '',
383                                       get_complete_dir($category['id']))));
384}
385else
386{
387  $template->assign_block_vars(
388    'delete',
389    array(
390      'URL'=>$self_url.'&amp;delete='.$category['id']
391      )
392    );
393
394  $template->assign_block_vars('move', array());
395
396  // the category can be moved in any category but in itself, in any
397  // sub-category
398  $unmovables = get_subcat_ids(array($category['id']));
399 
400  $blockname = 'move.parent_option';
401
402  $template->assign_block_vars(
403    $blockname,
404    array(
405      'SELECTED'
406        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
407      'VALUE'=> 0,
408      'OPTION' => '------------'
409      )
410    );
411 
412  $query = '
413SELECT id,name,uppercats,global_rank
414  FROM '.CATEGORIES_TABLE.'
415  WHERE id NOT IN ('.implode(',', $unmovables).')
416;';
417 
418  display_select_cat_wrapper(
419    $query,
420    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
421    $blockname
422    );
423}
424
425$category['cat_dir'] = get_complete_dir($_GET['cat_id']);
426if (is_numeric($category['site_id']) and url_is_remote($category['cat_dir']) )
427{
428  $query = '
429SELECT galleries_url
430  FROM '.SITES_TABLE.'
431  WHERE id = '.$category['site_id'].'
432;';
433  list($galleries_url) = mysql_fetch_array(pwg_query($query));
434  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
435}
436
437if (!$category['is_virtual'] and !url_is_remote($category['cat_dir']) )
438{
439  $template->assign_block_vars('upload' ,array());
440}
441
442$blockname = 'category_option_parent';
443
444$template->assign_block_vars(
445  $blockname,
446  array(
447    'VALUE'=> 0,
448    'OPTION' => '------------'
449    )
450  );
451
452$query = '
453SELECT id,name,uppercats,global_rank
454  FROM '.CATEGORIES_TABLE.'
455;';
456
457display_select_cat_wrapper(
458  $query,
459  array(),
460  $blockname
461  );
462
463// destination categories
464$query = '
465SELECT DISTINCT id, name, uppercats, global_rank
466  FROM '.CATEGORIES_TABLE.'
467    INNER JOIN '.CATEGORIES_LINK_TABLE.' ON destination = id
468  WHERE source = '.$_GET['cat_id'].'
469;';
470display_select_cat_wrapper($query, array(), 'destination_option_true');
471
472// non destination categories
473$destinations = array_merge(
474  array($_GET['cat_id']),
475  array_from_query($query, 'id')
476  );
477
478$query = '
479SELECT DISTINCT id, name, uppercats, global_rank
480  FROM '.CATEGORIES_TABLE.'
481  WHERE id NOT IN ('.implode(',', $destinations).')
482;';
483display_select_cat_wrapper($query, array(), 'destination_option_false');
484
485// source categories
486$query = '
487SELECT DISTINCT id, name, uppercats, global_rank
488  FROM '.CATEGORIES_TABLE.'
489    INNER JOIN '.CATEGORIES_LINK_TABLE.' ON source = id
490  WHERE destination = '.$_GET['cat_id'].'
491;';
492display_select_cat_wrapper($query, array(), 'source_option_true');
493
494// non source categories
495$sources = array_merge(
496  array($_GET['cat_id']),
497  array_from_query($query, 'id')
498  );
499
500$query = '
501SELECT DISTINCT id, name, uppercats, global_rank
502  FROM '.CATEGORIES_TABLE.'
503  WHERE id NOT IN ('.implode(',', $sources).')
504;';
505display_select_cat_wrapper($query, array(), 'source_option_false');
506
507//----------------------------------------------------------- sending html code
508$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
509?>
Note: See TracBrowser for help on using the repository browser.