source: trunk/admin/cat_modify.php @ 1082

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

new: cleaner URL. Instead of category.php?cat=search&search=123&start=42,
you now have category.php?/search/123/start-42. Functions make_index_url and
make_picture_url build these new URLs. Functions duplicate_picture_url and
duplicate_index_url provide shortcuts to URL creation. The current main page
page is still category.php but this can be modified easily in make_index_url
function. In this first version, no backward compatibility. Calendar
definition in URL must be discussed with rvelices.

improvement: picture.php redesigned. First actions like "set as
representative" or "delete a comment" which all lead to a redirection. Then
the page (the big mess) and includes of new sub pages to manage specific
parts of the page (metadata, user comments, rates).

new: with the cleaner URL comes a new terminology. $pagecat doesn't
exist anymore. $pagesection is among 'categories', 'tags' (TODO),
'list', 'most_seen'... And sub parameters are set : $pagecategory if
$pagesection is "categories". See URL analyse in
include/section_init.inc.php for details.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-15 22:44:35 +0000 (Wed, 15 Mar 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1082 $
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(
273  array( 
274    'CATEGORIES_NAV'     => $navigation,
275    'CAT_NAME'           => $category['name'],
276    'CAT_COMMENT'        => $category['comment'],
277   
278    $status              => 'checked="checked"',
279    $lock                => 'checked="checked"',
280    $commentable         => 'checked="checked"',
281    $uploadable          => 'checked="checked"',
282   
283    'L_EDIT_NAME'        => $lang['name'],
284    'L_STORAGE'          => $lang['storage'],
285    'L_REMOTE_SITE'      => $lang['remote_site'],
286    'L_EDIT_COMMENT'     => $lang['description'],
287    'L_EDIT_STATUS'      => $lang['conf_access'],
288    'L_STATUS_PUBLIC'    => $lang['public'],
289    'L_STATUS_PRIVATE'   => $lang['private'],
290    'L_EDIT_LOCK'        => $lang['lock'],
291    'L_EDIT_UPLOADABLE'  => $lang['editcat_uploadable'],
292    'L_EDIT_COMMENTABLE' => $lang['comments'],
293    'L_YES'              => $lang['yes'],
294    'L_NO'               => $lang['no'],
295    'L_SUBMIT'           => $lang['submit'],
296    'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
297
298    'U_JUMPTO' => make_index_url(
299      array(
300        'category' => $category['id'],
301        )
302      ),
303   
304    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
305    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_modify',
306   
307    'F_ACTION' => $form_action,
308    )
309  );
310
311
312if ('private' == $category['status'])
313{
314  $template->assign_block_vars(
315    'permissions',
316    array(
317      'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
318        )
319    );
320}
321
322// manage category elements link
323if ($category['nb_images'] > 0)
324{
325  $template->assign_block_vars(
326    'elements',
327    array(
328      'URL'=>$base_url.'element_set&amp;cat='.$category['id']
329      )
330    );
331}
332
333// representant management
334if ($category['nb_images'] > 0
335    or !empty($category['representative_picture_id']))
336{
337  $template->assign_block_vars('representant', array());
338
339  // picture to display : the identified representant or the generic random
340  // representant ?
341  if (!empty($category['representative_picture_id']))
342  {
343    $query = '
344SELECT tn_ext,path
345  FROM '.IMAGES_TABLE.'
346  WHERE id = '.$category['representative_picture_id'].'
347;';
348    $row = mysql_fetch_array(pwg_query($query));
349    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
350    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
351    $url.= '&amp;image_id='.$category['representative_picture_id'];
352 
353    $template->assign_block_vars(
354      'representant.picture',
355      array(
356        'SRC' => $src,
357        'URL' => $url
358        )
359      );
360  }
361  else // $category['nb_images'] > 0
362  {
363    $template->assign_block_vars('representant.random', array());
364  }
365
366  // can the admin choose to set a new random representant ?
367  if ($category['nb_images'] > 0)
368  {
369    $template->assign_block_vars('representant.set_random', array());
370  }
371
372  // can the admin delete the current representant ?
373  if (
374    ($category['nb_images'] > 0
375     and $conf['allow_random_representative'])
376    or
377    ($category['nb_images'] == 0
378     and !empty($category['representative_picture_id'])))
379  {
380    $template->assign_block_vars('representant.delete_representant', array());
381  }
382}
383
384if (!$category['is_virtual']) //!empty($category['dir']))
385{
386  $template->assign_block_vars(
387    'storage',
388    array('CATEGORY_DIR'=>preg_replace('/\/$/',
389                                       '',
390                                       get_complete_dir($category['id']))));
391}
392else
393{
394  $template->assign_block_vars(
395    'delete',
396    array(
397      'URL'=>$self_url.'&amp;delete='.$category['id']
398      )
399    );
400
401  $template->assign_block_vars('move', array());
402
403  // the category can be moved in any category but in itself, in any
404  // sub-category
405  $unmovables = get_subcat_ids(array($category['id']));
406 
407  $blockname = 'move.parent_option';
408
409  $template->assign_block_vars(
410    $blockname,
411    array(
412      'SELECTED'
413        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
414      'VALUE'=> 0,
415      'OPTION' => '------------'
416      )
417    );
418 
419  $query = '
420SELECT id,name,uppercats,global_rank
421  FROM '.CATEGORIES_TABLE.'
422  WHERE id NOT IN ('.implode(',', $unmovables).')
423;';
424 
425  display_select_cat_wrapper(
426    $query,
427    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
428    $blockname
429    );
430}
431
432$category['cat_dir'] = get_complete_dir($_GET['cat_id']);
433if (is_numeric($category['site_id']) and url_is_remote($category['cat_dir']) )
434{
435  $query = '
436SELECT galleries_url
437  FROM '.SITES_TABLE.'
438  WHERE id = '.$category['site_id'].'
439;';
440  list($galleries_url) = mysql_fetch_array(pwg_query($query));
441  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
442}
443
444if (!$category['is_virtual'] and !url_is_remote($category['cat_dir']) )
445{
446  $template->assign_block_vars('upload' ,array());
447}
448
449$blockname = 'category_option_parent';
450
451$template->assign_block_vars(
452  $blockname,
453  array(
454    'VALUE'=> 0,
455    'OPTION' => '------------'
456    )
457  );
458
459$query = '
460SELECT id,name,uppercats,global_rank
461  FROM '.CATEGORIES_TABLE.'
462;';
463
464display_select_cat_wrapper(
465  $query,
466  array(),
467  $blockname
468  );
469
470// destination categories
471$query = '
472SELECT DISTINCT id, name, uppercats, global_rank
473  FROM '.CATEGORIES_TABLE.'
474    INNER JOIN '.CATEGORIES_LINK_TABLE.' ON destination = id
475  WHERE source = '.$_GET['cat_id'].'
476;';
477display_select_cat_wrapper($query, array(), 'destination_option_true');
478
479// non destination categories
480$destinations = array_merge(
481  array($_GET['cat_id']),
482  array_from_query($query, 'id')
483  );
484
485$query = '
486SELECT DISTINCT id, name, uppercats, global_rank
487  FROM '.CATEGORIES_TABLE.'
488  WHERE id NOT IN ('.implode(',', $destinations).')
489;';
490display_select_cat_wrapper($query, array(), 'destination_option_false');
491
492// source categories
493$query = '
494SELECT DISTINCT id, name, uppercats, global_rank
495  FROM '.CATEGORIES_TABLE.'
496    INNER JOIN '.CATEGORIES_LINK_TABLE.' ON source = id
497  WHERE destination = '.$_GET['cat_id'].'
498;';
499display_select_cat_wrapper($query, array(), 'source_option_true');
500
501// non source categories
502$sources = array_merge(
503  array($_GET['cat_id']),
504  array_from_query($query, 'id')
505  );
506
507$query = '
508SELECT DISTINCT id, name, uppercats, global_rank
509  FROM '.CATEGORIES_TABLE.'
510  WHERE id NOT IN ('.implode(',', $sources).')
511;';
512display_select_cat_wrapper($query, array(), 'source_option_false');
513
514//----------------------------------------------------------- sending html code
515$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
516?>
Note: See TracBrowser for help on using the repository browser.