source: trunk/admin/cat_modify.php @ 1900

Last change on this file since 1900 was 1900, checked in by rub, 17 years ago

Apply property svn:eol-style Value: LF

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 15.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: cat_modify.php 1900 2007-03-12 22:33:53Z rub $
8// | last update   : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1900 $
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');
33include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.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
283        )
284      ),
285
286    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
287    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=cat_modify',
288
289    'F_ACTION' => $form_action,
290    )
291  );
292
293
294if ('private' == $category['status'])
295{
296  $template->assign_block_vars(
297    'permissions',
298    array(
299      'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
300        )
301    );
302}
303
304// manage category elements link
305if ($category['nb_images'] > 0)
306{
307  $template->assign_block_vars(
308    'elements',
309    array(
310      'URL'=>$base_url.'element_set&amp;cat='.$category['id']
311      )
312    );
313}
314
315// image order management
316$matches = array();
317if ( !empty( $category['image_order'] ) )
318{
319  preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i',
320    $category['image_order'], $matches);
321}
322
323$sort_fields = array(
324  '' => '',
325  'date_creation' => l10n('Creation date'),
326  'date_available' => l10n('Post date'),
327  'average_rate' => l10n('Average rate'),
328  'hit' => l10n('most_visited_cat'),
329  'file' => l10n('File name'),
330  'id' => 'Id',
331  );
332
333for ($i=0; $i<3; $i++) // 3 fields
334{
335  $template->assign_block_vars('image_order', array('NUMBER'=>$i+1) );
336  foreach ($sort_fields as $sort_field => $name)
337  {
338    $selected='';
339    if ( isset($matches[1][$i]) and $matches[1][$i]==$sort_field )
340    {
341      $selected='selected="selected"';
342    }
343    elseif ( empty($sort_field) )
344    {
345      $selected='selected="selected"';
346    }
347
348    $template->assign_block_vars('image_order.field',
349      array(
350        'SELECTED' => $selected,
351        'VALUE' => $sort_field,
352        'OPTION' => $name
353        )
354      );
355  }
356
357  $template->assign_block_vars('image_order.order',
358    array(
359      'SELECTED' =>
360        ( empty($matches[2][$i]) or strcasecmp($matches[2][$i],'ASC')==0 )
361          ? 'selected="selected"' : '',
362      'VALUE' => 'ASC',
363      'OPTION' => 'Ascending'
364      )
365    );
366
367  $template->assign_block_vars('image_order.order',
368    array(
369      'SELECTED' =>
370        ( isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0 )
371          ? 'selected="selected"' : '',
372      'VALUE' => 'DESC',
373      'OPTION' => 'Descending'
374      )
375    );
376}
377
378
379// representant management
380if ($category['nb_images'] > 0
381    or !empty($category['representative_picture_id']))
382{
383  $template->assign_block_vars('representant', array());
384
385  // picture to display : the identified representant or the generic random
386  // representant ?
387  if (!empty($category['representative_picture_id']))
388  {
389    $query = '
390SELECT id,tn_ext,path
391  FROM '.IMAGES_TABLE.'
392  WHERE id = '.$category['representative_picture_id'].'
393;';
394    $row = mysql_fetch_array(pwg_query($query));
395    $src = get_thumbnail_url($row);
396    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
397    $url.= '&amp;image_id='.$category['representative_picture_id'];
398
399    $template->assign_block_vars(
400      'representant.picture',
401      array(
402        'SRC' => $src,
403        'URL' => $url
404        )
405      );
406  }
407  else // $category['nb_images'] > 0
408  {
409    $template->assign_block_vars('representant.random', array());
410  }
411
412  // can the admin choose to set a new random representant ?
413  if ($category['nb_images'] > 0)
414  {
415    $template->assign_block_vars('representant.set_random', array());
416  }
417
418  // can the admin delete the current representant ?
419  if (
420    ($category['nb_images'] > 0
421     and $conf['allow_random_representative'])
422    or
423    ($category['nb_images'] == 0
424     and !empty($category['representative_picture_id'])))
425  {
426    $template->assign_block_vars('representant.delete_representant', array());
427  }
428}
429
430if (!$category['is_virtual'])
431{
432  $template->assign_block_vars(
433    'storage',
434    array('CATEGORY_DIR'=>preg_replace('/\/$/',
435                                       '',
436                                       get_complete_dir($category['id']))));
437}
438else
439{
440  $template->assign_block_vars(
441    'delete',
442    array(
443      'URL'=>$self_url.'&amp;delete='.$category['id']
444      )
445    );
446
447  $template->assign_block_vars('move', array());
448
449  // the category can be moved in any category but in itself, in any
450  // sub-category
451  $unmovables = get_subcat_ids(array($category['id']));
452
453  $blockname = 'move.parent_option';
454
455  $template->assign_block_vars(
456    $blockname,
457    array(
458      'SELECTED'
459        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
460      'VALUE'=> 0,
461      'OPTION' => '------------'
462      )
463    );
464
465  $query = '
466SELECT id,name,uppercats,global_rank
467  FROM '.CATEGORIES_TABLE.'
468  WHERE id NOT IN ('.implode(',', $unmovables).')
469;';
470
471  display_select_cat_wrapper(
472    $query,
473    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
474    $blockname
475    );
476}
477
478$category['cat_dir'] = get_complete_dir($_GET['cat_id']);
479if (is_numeric($category['site_id']) and url_is_remote($category['cat_dir']) )
480{
481  $query = '
482SELECT galleries_url
483  FROM '.SITES_TABLE.'
484  WHERE id = '.$category['site_id'].'
485;';
486  list($galleries_url) = mysql_fetch_array(pwg_query($query));
487  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
488}
489
490if (!$category['is_virtual'] and !url_is_remote($category['cat_dir']) )
491{
492  $template->assign_block_vars('upload' ,array());
493}
494
495$blockname = 'category_option_parent';
496
497$template->assign_block_vars(
498  $blockname,
499  array(
500    'VALUE'=> 0,
501    'OPTION' => '------------'
502    )
503  );
504
505$query = '
506SELECT id,name,uppercats,global_rank
507  FROM '.CATEGORIES_TABLE.'
508;';
509
510display_select_cat_wrapper(
511  $query,
512  array(),
513  $blockname
514  );
515
516// destination categories
517$query = '
518SELECT id,name,uppercats,global_rank
519  FROM '.CATEGORIES_TABLE.'
520  WHERE id != '.$category['id'].'
521;';
522
523display_select_cat_wrapper(
524  $query,
525  array(),
526  'category_option_destination'
527  );
528
529// info by email to an access granted group of category informations
530if (isset($_POST['submitEmail']))
531{
532  $query = '
533SELECT
534    user_id,
535    '.$conf['user_fields']['email'].' AS email
536  FROM '.USER_GROUP_TABLE.'
537    INNER JOIN '.USERS_TABLE.' ON '.$conf['user_fields']['id'].' = user_id
538  WHERE '.$conf['user_fields']['email'].' IS NOT NULL
539    AND group_id = '.$_POST['group'].'
540;';
541  $result = pwg_query($query);
542
543  while ($row = mysql_fetch_array($result))
544  {
545    pwg_mail(
546      $row['email'],
547      array(
548        'content' => get_absolute_root_url().make_index_url(
549          array(
550            'category' => array(
551              'id' => $category['id'],
552              'name' => $category['name'],
553              'permalink' => $category['permalink'],
554              )
555            )
556          ),
557        'subject' => $category['name']
558        )
559      );
560  }
561
562  $query = '
563SELECT
564    name
565  FROM '.GROUPS_TABLE.'
566  WHERE id = '.$_POST['group'].'
567;';
568  list($group_name) = mysql_fetch_row(pwg_query($query));
569 
570  array_push(
571    $page['infos'],
572    sprintf(
573      l10n('An information email was sent to group "%s"'),
574      $group_name
575      )
576    );
577}
578
579if ('private' == $category['status'])
580{
581  $query = '
582SELECT
583    group_id
584  FROM '.GROUP_ACCESS_TABLE.'
585  WHERE cat_id = '.$category['id'].'
586;';
587}
588else
589{
590  $query = '
591SELECT
592    id AS group_id
593  FROM '.GROUPS_TABLE.'
594;';
595}
596$group_ids = array_from_query($query, 'group_id');
597
598if (count($group_ids) > 0)
599{
600  $query = '
601SELECT
602    id,
603    name
604  FROM '.GROUPS_TABLE.'
605  WHERE id IN ('.implode(',', $group_ids).')
606  ORDER BY name ASC
607;';
608  $result = pwg_query($query);
609
610  while ($row = mysql_fetch_array($result))
611  {
612    $template->assign_block_vars(
613      'group_option',
614      array(
615        'VALUE' => $row['id'],
616        'OPTION' => $row['name'],
617        )
618      );
619  }
620}
621
622//----------------------------------------------------------- sending html code
623$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
624?>
Note: See TracBrowser for help on using the repository browser.