source: trunk/admin/cat_modify.php @ 1609

Last change on this file since 1609 was 1609, checked in by rvelices, 17 years ago

completely replaced get_thumbnail_src it get_thumbnail_url
or get_thumbnail_path

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