source: trunk/admin/cat_modify.php @ 1250

Last change on this file since 1250 was 1250, checked in by nikrou, 19 years ago

bug fixed: popuhelp (slash)
svn merge -r1248:1249 from branch-1_6 into trunk

  • 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-21 21:16:37 +0000 (Fri, 21 Apr 2006) $
10// | last modifier : $Author: nikrou $
11// | revision      : $Revision: 1250 $
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        'cat_name' => $category['name'],
248        )
249      ),
250
251    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
252    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=cat_modify',
253
254    'F_ACTION' => $form_action,
255    )
256  );
257
258
259if ('private' == $category['status'])
260{
261  $template->assign_block_vars(
262    'permissions',
263    array(
264      'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
265        )
266    );
267}
268
269// manage category elements link
270if ($category['nb_images'] > 0)
271{
272  $template->assign_block_vars(
273    'elements',
274    array(
275      'URL'=>$base_url.'element_set&amp;cat='.$category['id']
276      )
277    );
278}
279
280// representant management
281if ($category['nb_images'] > 0
282    or !empty($category['representative_picture_id']))
283{
284  $template->assign_block_vars('representant', array());
285
286  // picture to display : the identified representant or the generic random
287  // representant ?
288  if (!empty($category['representative_picture_id']))
289  {
290    $query = '
291SELECT tn_ext,path
292  FROM '.IMAGES_TABLE.'
293  WHERE id = '.$category['representative_picture_id'].'
294;';
295    $row = mysql_fetch_array(pwg_query($query));
296    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
297    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
298    $url.= '&amp;image_id='.$category['representative_picture_id'];
299
300    $template->assign_block_vars(
301      'representant.picture',
302      array(
303        'SRC' => $src,
304        'URL' => $url
305        )
306      );
307  }
308  else // $category['nb_images'] > 0
309  {
310    $template->assign_block_vars('representant.random', array());
311  }
312
313  // can the admin choose to set a new random representant ?
314  if ($category['nb_images'] > 0)
315  {
316    $template->assign_block_vars('representant.set_random', array());
317  }
318
319  // can the admin delete the current representant ?
320  if (
321    ($category['nb_images'] > 0
322     and $conf['allow_random_representative'])
323    or
324    ($category['nb_images'] == 0
325     and !empty($category['representative_picture_id'])))
326  {
327    $template->assign_block_vars('representant.delete_representant', array());
328  }
329}
330
331if (!$category['is_virtual'])
332{
333  $template->assign_block_vars(
334    'storage',
335    array('CATEGORY_DIR'=>preg_replace('/\/$/',
336                                       '',
337                                       get_complete_dir($category['id']))));
338}
339else
340{
341  $template->assign_block_vars(
342    'delete',
343    array(
344      'URL'=>$self_url.'&amp;delete='.$category['id']
345      )
346    );
347
348  $template->assign_block_vars('move', array());
349
350  // the category can be moved in any category but in itself, in any
351  // sub-category
352  $unmovables = get_subcat_ids(array($category['id']));
353
354  $blockname = 'move.parent_option';
355
356  $template->assign_block_vars(
357    $blockname,
358    array(
359      'SELECTED'
360        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
361      'VALUE'=> 0,
362      'OPTION' => '------------'
363      )
364    );
365
366  $query = '
367SELECT id,name,uppercats,global_rank
368  FROM '.CATEGORIES_TABLE.'
369  WHERE id NOT IN ('.implode(',', $unmovables).')
370;';
371
372  display_select_cat_wrapper(
373    $query,
374    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
375    $blockname
376    );
377}
378
379$category['cat_dir'] = get_complete_dir($_GET['cat_id']);
380if (is_numeric($category['site_id']) and url_is_remote($category['cat_dir']) )
381{
382  $query = '
383SELECT galleries_url
384  FROM '.SITES_TABLE.'
385  WHERE id = '.$category['site_id'].'
386;';
387  list($galleries_url) = mysql_fetch_array(pwg_query($query));
388  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
389}
390
391if (!$category['is_virtual'] and !url_is_remote($category['cat_dir']) )
392{
393  $template->assign_block_vars('upload' ,array());
394}
395
396$blockname = 'category_option_parent';
397
398$template->assign_block_vars(
399  $blockname,
400  array(
401    'VALUE'=> 0,
402    'OPTION' => '------------'
403    )
404  );
405
406$query = '
407SELECT id,name,uppercats,global_rank
408  FROM '.CATEGORIES_TABLE.'
409;';
410
411display_select_cat_wrapper(
412  $query,
413  array(),
414  $blockname
415  );
416
417// destination categories
418$query = '
419SELECT id,name,uppercats,global_rank
420  FROM '.CATEGORIES_TABLE.'
421  WHERE id != '.$category['id'].'
422;';
423
424display_select_cat_wrapper(
425  $query,
426  array(),
427  'category_option_destination'
428  );
429
430
431//----------------------------------------------------------- sending html code
432$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
433?>
Note: See TracBrowser for help on using the repository browser.