source: trunk/admin/cat_modify.php @ 1861

Last change on this file since 1861 was 1861, checked in by rvelices, 17 years ago
  • refactoring pagecategory before 1.7 release

pagecategory is not an id anymore, but an associative array of category info
all of pagecat_xxx or pageuppercats merged into one
simplifies calls to make_index_url
give plugins a clean start for page variables for version 1.7

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.0 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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: cat_modify.php 1861 2007-02-27 01:56:16Z rvelices $
8// | last update   : $Date: 2007-02-27 01:56:16 +0000 (Tue, 27 Feb 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1861 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27if (!defined('PHPWG_ROOT_PATH'))
28{
29  die('Hacking attempt!');
30}
31
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_ADMINISTRATOR);
38
39//---------------------------------------------------------------- verification
40if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) )
41{
42  $_GET['cat_id'] = '-1';
43}
44
45$template->set_filenames( array('categories'=>'admin/cat_modify.tpl') );
46
47//--------------------------------------------------------- form criteria check
48if (isset($_POST['submit']))
49{
50  $data =
51    array(
52      'id' => $_GET['cat_id'],
53      'name' => @$_POST['name'],
54      'commentable' => $_POST['commentable'],
55      'uploadable' =>
56        isset($_POST['uploadable']) ? $_POST['uploadable'] : 'false',
57      'comment' =>
58        $conf['allow_html_descriptions'] ?
59          @$_POST['comment'] : strip_tags(@$_POST['comment'])
60      );
61
62  mass_updates(
63    CATEGORIES_TABLE,
64    array(
65      'primary' => array('id'),
66      'update' => array_diff(array_keys($data), array('id'))
67      ),
68    array($data)
69    );
70
71  set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
72  set_cat_status(array($_GET['cat_id']), $_POST['status']);
73
74  if (isset($_POST['parent']))
75  {
76    move_categories(
77      array($_GET['cat_id']),
78      $_POST['parent']
79      );
80  }
81
82  $image_order = '';
83  if ( !isset($_POST['image_order_default']) )
84  {
85    for ($i=1; $i<=3; $i++)
86    {
87      if ( !empty($_POST['order_field_'.$i]) )
88      {
89        if (! empty($image_order) )
90        {
91          $image_order .= ',';
92        }
93        $image_order .= $_POST['order_field_'.$i];
94        if ($_POST['order_direction_'.$i]=='DESC')
95        {
96          $image_order .= ' DESC';
97        }
98      }
99    }
100  }
101  $image_order = empty($image_order) ? 'null' : "'$image_order'";
102  $query = '
103UPDATE '.CATEGORIES_TABLE.' SET image_order='.$image_order.'
104WHERE ';
105  if (isset($_POST['image_order_subcats']))
106  {
107    $query .= 'uppercats REGEXP \'(^|,)'.$_GET['cat_id'].'(,|$)\'';
108  }
109  else
110  {
111    $query .= 'id='.$_GET['cat_id'].';';
112  }
113  pwg_query($query);
114
115  array_push($page['infos'], $lang['editcat_confirm']);
116}
117else if (isset($_POST['set_random_representant']))
118{
119  set_random_representant(array($_GET['cat_id']));
120}
121else if (isset($_POST['delete_representant']))
122{
123  $query = '
124UPDATE '.CATEGORIES_TABLE.'
125  SET representative_picture_id = NULL
126  WHERE id = '.$_GET['cat_id'].'
127;';
128  pwg_query($query);
129}
130else if (isset($_POST['submitAdd']))
131{
132  $output_create = create_virtual_category(
133    $_POST['virtual_name'],
134    (0 == $_POST['parent'] ? null : $_POST['parent'])
135    );
136
137  if (isset($output_create['error']))
138  {
139    array_push($page['errors'], $output_create['error']);
140  }
141  else
142  {
143    // Virtual category creation succeeded
144    //
145    // Add the information in the information list
146    array_push($page['infos'], $output_create['info']);
147
148    // Link the new category to the current category
149    associate_categories_to_categories(
150      array($_GET['cat_id']),
151      array($output_create['id'])
152      );
153
154    // information
155    array_push(
156      $page['infos'],
157      sprintf(
158        l10n('Category elements associated to the following categories: %s'),
159        '<ul><li>'
160        .get_cat_display_name_from_id($output_create['id'])
161        .'</li></ul>'
162        )
163      );
164  }
165}
166else if (isset($_POST['submitDestinations'])
167         and isset($_POST['destinations'])
168         and count($_POST['destinations']) > 0)
169{
170  associate_categories_to_categories(
171    array($_GET['cat_id']),
172    $_POST['destinations']
173    );
174
175  $category_names = array();
176  foreach ($_POST['destinations'] as $category_id)
177  {
178    array_push(
179      $category_names,
180      get_cat_display_name_from_id($category_id)
181      );
182  }
183
184  array_push(
185    $page['infos'],
186    sprintf(
187      l10n('Category elements associated to the following categories: %s'),
188      '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
189      )
190    );
191}
192
193$query = '
194SELECT *
195  FROM '.CATEGORIES_TABLE.'
196  WHERE id = '.$_GET['cat_id'].'
197;';
198$category = mysql_fetch_array( pwg_query( $query ) );
199// nullable fields
200foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
201{
202  if (!isset($category[$nullable]))
203  {
204    $category[$nullable] = '';
205  }
206}
207
208$category['is_virtual'] = empty($category['dir']) ? true : false;
209
210// Navigation path
211$url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id=';
212
213$navigation = get_cat_display_name_cache(
214  $category['uppercats'],
215  PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='
216  );
217
218$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
219$status = ($category['status']=='public')?'STATUS_PUBLIC':'STATUS_PRIVATE';
220$lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED';
221
222if ($category['commentable'] == 'true')
223{
224  $commentable = 'COMMENTABLE_TRUE';
225}
226else
227{
228  $commentable = 'COMMENTABLE_FALSE';
229}
230if ($category['uploadable'] == 'true')
231{
232  $uploadable = 'UPLOADABLE_TRUE';
233}
234else
235{
236  $uploadable = 'UPLOADABLE_FALSE';
237}
238
239//----------------------------------------------------- template initialization
240
241$base_url = PHPWG_ROOT_PATH.'admin.php?page=';
242$cat_list_url = $base_url.'cat_list';
243
244$self_url = $cat_list_url;
245if (!empty($category['id_uppercat']))
246{
247  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
248}
249
250$template->assign_vars(
251  array(
252    'CATEGORIES_NAV'     => $navigation,
253    'CAT_NAME'           => $category['name'],
254    'CAT_COMMENT'        => $category['comment'],
255
256    $status              => 'checked="checked"',
257    $lock                => 'checked="checked"',
258    $commentable         => 'checked="checked"',
259    $uploadable          => 'checked="checked"',
260
261    'IMG_ORDER_DEFAULT'  => empty($category['image_order']) ?
262                              'checked="checked"' : '',
263
264    'L_EDIT_NAME'        => $lang['name'],
265    'L_STORAGE'          => $lang['storage'],
266    'L_REMOTE_SITE'      => $lang['remote_site'],
267    'L_EDIT_COMMENT'     => $lang['description'],
268    'L_EDIT_STATUS'      => $lang['conf_access'],
269    'L_STATUS_PUBLIC'    => $lang['public'],
270    'L_STATUS_PRIVATE'   => $lang['private'],
271    'L_EDIT_LOCK'        => $lang['lock'],
272    'L_EDIT_UPLOADABLE'  => $lang['editcat_uploadable'],
273    'L_EDIT_COMMENTABLE' => $lang['comments'],
274    'L_YES'              => $lang['yes'],
275    'L_NO'               => $lang['no'],
276    'L_SUBMIT'           => $lang['submit'],
277    'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
278
279    'U_JUMPTO' => make_index_url(
280      array(
281        'category' => $category
282        )
283      ),
284
285    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
286    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=cat_modify',
287
288    'F_ACTION' => $form_action,
289    )
290  );
291
292
293if ('private' == $category['status'])
294{
295  $template->assign_block_vars(
296    'permissions',
297    array(
298      'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
299        )
300    );
301}
302
303// manage category elements link
304if ($category['nb_images'] > 0)
305{
306  $template->assign_block_vars(
307    'elements',
308    array(
309      'URL'=>$base_url.'element_set&amp;cat='.$category['id']
310      )
311    );
312}
313
314// image order management
315$matches = array();
316if ( !empty( $category['image_order'] ) )
317{
318  preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i',
319    $category['image_order'], $matches);
320}
321
322$sort_fields = array(
323  '' => '',
324  'date_creation' => l10n('Creation date'),
325  'date_available' => l10n('Post date'),
326  'average_rate' => l10n('Average rate'),
327  'hit' => l10n('most_visited_cat'),
328  'file' => l10n('File name'),
329  'id' => 'Id',
330  );
331
332for ($i=0; $i<3; $i++) // 3 fields
333{
334  $template->assign_block_vars('image_order', array('NUMBER'=>$i+1) );
335  foreach ($sort_fields as $sort_field => $name)
336  {
337    $selected='';
338    if ( isset($matches[1][$i]) and $matches[1][$i]==$sort_field )
339    {
340      $selected='selected="selected"';
341    }
342    elseif ( empty($sort_field) )
343    {
344      $selected='selected="selected"';
345    }
346
347    $template->assign_block_vars('image_order.field',
348      array(
349        'SELECTED' => $selected,
350        'VALUE' => $sort_field,
351        'OPTION' => $name
352        )
353      );
354  }
355
356  $template->assign_block_vars('image_order.order',
357    array(
358      'SELECTED' =>
359        ( empty($matches[2][$i]) or strcasecmp($matches[2][$i],'ASC')==0 )
360          ? 'selected="selected"' : '',
361      'VALUE' => 'ASC',
362      'OPTION' => 'Ascending'
363      )
364    );
365
366  $template->assign_block_vars('image_order.order',
367    array(
368      'SELECTED' =>
369        ( isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0 )
370          ? 'selected="selected"' : '',
371      'VALUE' => 'DESC',
372      'OPTION' => 'Descending'
373      )
374    );
375}
376
377
378// representant management
379if ($category['nb_images'] > 0
380    or !empty($category['representative_picture_id']))
381{
382  $template->assign_block_vars('representant', array());
383
384  // picture to display : the identified representant or the generic random
385  // representant ?
386  if (!empty($category['representative_picture_id']))
387  {
388    $query = '
389SELECT id,tn_ext,path
390  FROM '.IMAGES_TABLE.'
391  WHERE id = '.$category['representative_picture_id'].'
392;';
393    $row = mysql_fetch_array(pwg_query($query));
394    $src = get_thumbnail_url($row);
395    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
396    $url.= '&amp;image_id='.$category['representative_picture_id'];
397
398    $template->assign_block_vars(
399      'representant.picture',
400      array(
401        'SRC' => $src,
402        'URL' => $url
403        )
404      );
405  }
406  else // $category['nb_images'] > 0
407  {
408    $template->assign_block_vars('representant.random', array());
409  }
410
411  // can the admin choose to set a new random representant ?
412  if ($category['nb_images'] > 0)
413  {
414    $template->assign_block_vars('representant.set_random', array());
415  }
416
417  // can the admin delete the current representant ?
418  if (
419    ($category['nb_images'] > 0
420     and $conf['allow_random_representative'])
421    or
422    ($category['nb_images'] == 0
423     and !empty($category['representative_picture_id'])))
424  {
425    $template->assign_block_vars('representant.delete_representant', array());
426  }
427}
428
429if (!$category['is_virtual'])
430{
431  $template->assign_block_vars(
432    'storage',
433    array('CATEGORY_DIR'=>preg_replace('/\/$/',
434                                       '',
435                                       get_complete_dir($category['id']))));
436}
437else
438{
439  $template->assign_block_vars(
440    'delete',
441    array(
442      'URL'=>$self_url.'&amp;delete='.$category['id']
443      )
444    );
445
446  $template->assign_block_vars('move', array());
447
448  // the category can be moved in any category but in itself, in any
449  // sub-category
450  $unmovables = get_subcat_ids(array($category['id']));
451
452  $blockname = 'move.parent_option';
453
454  $template->assign_block_vars(
455    $blockname,
456    array(
457      'SELECTED'
458        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
459      'VALUE'=> 0,
460      'OPTION' => '------------'
461      )
462    );
463
464  $query = '
465SELECT id,name,uppercats,global_rank
466  FROM '.CATEGORIES_TABLE.'
467  WHERE id NOT IN ('.implode(',', $unmovables).')
468;';
469
470  display_select_cat_wrapper(
471    $query,
472    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
473    $blockname
474    );
475}
476
477$category['cat_dir'] = get_complete_dir($_GET['cat_id']);
478if (is_numeric($category['site_id']) and url_is_remote($category['cat_dir']) )
479{
480  $query = '
481SELECT galleries_url
482  FROM '.SITES_TABLE.'
483  WHERE id = '.$category['site_id'].'
484;';
485  list($galleries_url) = mysql_fetch_array(pwg_query($query));
486  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
487}
488
489if (!$category['is_virtual'] and !url_is_remote($category['cat_dir']) )
490{
491  $template->assign_block_vars('upload' ,array());
492}
493
494$blockname = 'category_option_parent';
495
496$template->assign_block_vars(
497  $blockname,
498  array(
499    'VALUE'=> 0,
500    'OPTION' => '------------'
501    )
502  );
503
504$query = '
505SELECT id,name,uppercats,global_rank
506  FROM '.CATEGORIES_TABLE.'
507;';
508
509display_select_cat_wrapper(
510  $query,
511  array(),
512  $blockname
513  );
514
515// destination categories
516$query = '
517SELECT id,name,uppercats,global_rank
518  FROM '.CATEGORIES_TABLE.'
519  WHERE id != '.$category['id'].'
520;';
521
522display_select_cat_wrapper(
523  $query,
524  array(),
525  'category_option_destination'
526  );
527
528
529//----------------------------------------------------------- sending html code
530$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
531?>
Note: See TracBrowser for help on using the repository browser.