source: trunk/admin/cat_modify.php @ 12906

Last change on this file since 12906 was 12887, checked in by mistic100, 12 years ago

feature:2549 Allow to disable comments for everybody

  • Property svn:eol-style set to LF
File size: 13.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die('Hacking attempt!');
27}
28
29include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36trigger_action('loc_begin_cat_modify');
37
38//---------------------------------------------------------------- verification
39if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) )
40{
41  trigger_error( 'missing cat_id param', E_USER_ERROR);
42}
43
44//--------------------------------------------------------- form criteria check
45if (isset($_POST['submit']))
46{
47  $data =
48    array(
49      'id' => $_GET['cat_id'],
50      'name' => @$_POST['name'],
51      'comment' =>
52        $conf['allow_html_descriptions'] ?
53          @$_POST['comment'] : strip_tags(@$_POST['comment']),
54      );
55     
56  if ($conf['activate_comments'])
57  {
58    $data['commentable'] = isset($_POST['commentable'])?$_POST['commentable']:'false';
59  }
60
61  mass_updates(
62    CATEGORIES_TABLE,
63    array(
64      'primary' => array('id'),
65      'update' => array_diff(array_keys($data), array('id'))
66      ),
67    array($data)
68    );
69
70  // retrieve cat infos before continuing (following updates are expensive)
71  $cat_info = get_cat_info($_GET['cat_id']);
72
73  if ($cat_info['visible'] != get_boolean( $_POST['visible'] ) )
74  {
75    set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
76  }
77  if ($cat_info['status'] != $_POST['status'] )
78  {
79    set_cat_status(array($_GET['cat_id']), $_POST['status']);
80  }
81
82  // in case the use moves his album to the gallery root, we force
83  // $_POST['parent'] from 0 to null to be compared with
84  // $cat_info['id_uppercat']
85  if (empty($_POST['parent']))
86  {
87    $_POST['parent'] = null;
88  }
89
90  // only move virtual albums
91  if (empty($cat_info['dir']) and $cat_info['id_uppercat'] != $_POST['parent'])
92  {
93    move_categories( array($_GET['cat_id']), $_POST['parent'] );
94  }
95
96  array_push($page['infos'], l10n('Album updated successfully'));
97}
98elseif (isset($_POST['set_random_representant']))
99{
100  set_random_representant(array($_GET['cat_id']));
101}
102elseif (isset($_POST['delete_representant']))
103{
104  $query = '
105UPDATE '.CATEGORIES_TABLE.'
106  SET representative_picture_id = NULL
107  WHERE id = '.$_GET['cat_id'].'
108;';
109  pwg_query($query);
110}
111elseif (isset($_POST['submitAdd']))
112{
113  $output_create = create_virtual_category(
114    $_POST['virtual_name'],
115    (0 == $_POST['parent'] ? null : $_POST['parent'])
116    );
117
118  if (isset($output_create['error']))
119  {
120    array_push($page['errors'], $output_create['error']);
121  }
122  else
123  {
124    // Virtual album creation succeeded
125    //
126    // Add the information in the information list
127    array_push($page['infos'], $output_create['info']);
128
129    // Link the new category to the current category
130    associate_categories_to_categories(
131      array($_GET['cat_id']),
132      array($output_create['id'])
133      );
134
135    // information
136    array_push(
137      $page['infos'],
138      sprintf(
139        l10n('Album photos associated to the following albums: %s'),
140        '<ul><li>'
141        .get_cat_display_name_from_id($output_create['id'])
142        .'</li></ul>'
143        )
144      );
145  }
146}
147elseif (isset($_POST['submitDestinations'])
148         and isset($_POST['destinations'])
149         and count($_POST['destinations']) > 0)
150{
151  associate_categories_to_categories(
152    array($_GET['cat_id']),
153    $_POST['destinations']
154    );
155
156  $category_names = array();
157  foreach ($_POST['destinations'] as $category_id)
158  {
159    array_push(
160      $category_names,
161      get_cat_display_name_from_id($category_id)
162      );
163  }
164
165  array_push(
166    $page['infos'],
167    sprintf(
168      l10n('Album photos associated to the following albums: %s'),
169      '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
170      )
171    );
172}
173
174$query = '
175SELECT *
176  FROM '.CATEGORIES_TABLE.'
177  WHERE id = '.$_GET['cat_id'].'
178;';
179$category = pwg_db_fetch_assoc( pwg_query( $query ) );
180// nullable fields
181foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
182{
183  if (!isset($category[$nullable]))
184  {
185    $category[$nullable] = '';
186  }
187}
188
189$category['is_virtual'] = empty($category['dir']) ? true : false;
190
191$query = 'SELECT DISTINCT category_id
192  FROM '.IMAGE_CATEGORY_TABLE.'
193  WHERE category_id = '.$_GET['cat_id'].'
194  LIMIT 1';
195$result = pwg_query($query);
196$category['has_images'] = pwg_db_num_rows($result)>0 ? true : false;
197
198// Navigation path
199$navigation = get_cat_display_name_cache(
200  $category['uppercats'],
201  get_root_url().'admin.php?page=cat_modify&amp;cat_id='
202  );
203
204$form_action = get_root_url().'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
205
206//----------------------------------------------------- template initialization
207$template->set_filename( 'categories', 'cat_modify.tpl');
208
209$base_url = get_root_url().'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(
219  array(
220    'CATEGORIES_NAV'     => $navigation,
221    'CAT_ID'             => $category['id'],
222    'CAT_NAME'           => @htmlspecialchars($category['name']),
223    'CAT_COMMENT'        => @htmlspecialchars($category['comment']),
224
225    'status_values'     => array('public','private'),
226
227    'CAT_STATUS'        => $category['status'],
228    'CAT_VISIBLE'       => boolean_to_string($category['visible']),
229
230    'U_JUMPTO' => make_index_url(
231      array(
232        'category' => $category
233        )
234      ),
235
236    'MAIL_CONTENT' => empty($_POST['mail_content'])
237        ? '' : stripslashes($_POST['mail_content']),
238    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
239    'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_modify',
240
241    'F_ACTION' => $form_action,
242    )
243  );
244 
245if ($conf['activate_comments'])
246{
247  $template->assign('CAT_COMMENTABLE', boolean_to_string($category['commentable']));
248}
249
250
251if ('private' == $category['status'])
252{
253  $template->assign( 'U_MANAGE_PERMISSIONS',
254      $base_url.'cat_perm&amp;cat='.$category['id']
255    );
256}
257
258// manage album elements link
259if ($category['has_images'])
260{
261  $template->assign(
262    'U_MANAGE_ELEMENTS',
263    $base_url.'batch_manager&amp;cat='.$category['id']
264    );
265}
266
267$template->assign(
268  'U_MANAGE_RANKS',
269  $base_url.'element_set_ranks&amp;cat_id='.$category['id']
270  );
271
272if ($category['is_virtual'])
273{
274  $template->assign(
275    array(
276      'U_DELETE' => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
277      )
278    );
279}
280else
281{
282  $category['cat_full_dir'] = get_complete_dir($_GET['cat_id']);
283  $template->assign(
284    array(
285      'CAT_FULL_DIR'       => preg_replace('/\/$/',
286                                    '',
287                                    $category['cat_full_dir'] )
288      )
289    );
290
291  if ($conf['enable_synchronization'])
292  {
293    $template->assign(
294      'U_SYNC',
295      $base_url.'site_update&amp;site=1&amp;cat_id='.$category['id']
296      );
297  }
298
299}
300
301// representant management
302if ($category['has_images']
303    or !empty($category['representative_picture_id']))
304{
305  $tpl_representant = array();
306
307  // picture to display : the identified representant or the generic random
308  // representant ?
309  if (!empty($category['representative_picture_id']))
310  {
311    $query = '
312SELECT id,representative_ext,path
313  FROM '.IMAGES_TABLE.'
314  WHERE id = '.$category['representative_picture_id'].'
315;';
316    $row = pwg_db_fetch_assoc(pwg_query($query));
317    $src = DerivativeImage::thumb_url($row);
318    $url = get_root_url().'admin.php?page=picture_modify';
319    $url.= '&amp;image_id='.$category['representative_picture_id'];
320
321    $tpl_representant['picture'] =
322      array(
323        'SRC' => $src,
324        'URL' => $url
325      );
326  }
327
328  // can the admin choose to set a new random representant ?
329  $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false;
330
331  // can the admin delete the current representant ?
332  if (
333    ($category['has_images']
334     and $conf['allow_random_representative'])
335    or
336    (!$category['has_images']
337     and !empty($category['representative_picture_id'])))
338  {
339    $tpl_representant['ALLOW_DELETE'] = true;
340  }
341  $template->assign('representant', $tpl_representant);
342}
343
344if ($category['is_virtual'])
345{
346  // the category can be moved in any category but in itself, in any
347  // sub-category
348  $unmovables = get_subcat_ids(array($category['id']));
349
350  $query = '
351SELECT id,name,uppercats,global_rank
352  FROM '.CATEGORIES_TABLE.'
353  WHERE id NOT IN ('.implode(',', $unmovables).')
354;';
355
356  display_select_cat_wrapper(
357    $query,
358    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
359    'move_cat_options'
360    );
361}
362
363
364// create virtual in parent and link
365$query = '
366SELECT id,name,uppercats,global_rank
367  FROM '.CATEGORIES_TABLE.'
368;';
369display_select_cat_wrapper(
370  $query,
371  array(),
372  'create_new_parent_options'
373  );
374
375
376// destination categories
377$query = '
378SELECT id,name,uppercats,global_rank
379  FROM '.CATEGORIES_TABLE.'
380  WHERE id != '.$category['id'].'
381;';
382display_select_cat_wrapper(
383  $query,
384  array(),
385  'category_destination_options'
386  );
387
388// info by email to an access granted group of category informations
389if (isset($_POST['submitEmail']) and !empty($_POST['group']))
390{
391  set_make_full_url();
392
393  /* TODO: if $category['representative_picture_id']
394    is empty find child representative_picture_id */
395  if (!empty($category['representative_picture_id']))
396  {
397    $query = '
398SELECT id, file, path, representative_ext
399  FROM '.IMAGES_TABLE.'
400  WHERE id = '.$category['representative_picture_id'].'
401;';
402
403    $result = pwg_query($query);
404    if (pwg_db_num_rows($result) > 0)
405    {
406      $element = pwg_db_fetch_assoc($result);
407
408      $img_url  = '<a href="'.
409                      make_picture_url(array(
410                          'image_id' => $element['id'],
411                          'image_file' => $element['file'],
412                          'category' => $category
413                        ))
414                      .'" class="thumblnk"><img src="'.DerivativeImage::thumb_url($element).'"></a>';
415    }
416  }
417
418  if (!isset($img_url))
419  {
420    $img_url = '';
421  }
422
423  // TODO Mettre un array pour traduction subjet
424  pwg_mail_group(
425    $_POST['group'],
426    get_str_email_format(true), /* TODO add a checkbox in order to choose format*/
427    get_l10n_args('[%s] Visit album %s',
428      array($conf['gallery_title'], $category['name'])),
429    'cat_group_info',
430    array
431    (
432      'IMG_URL' => $img_url,
433      'CAT_NAME' => $category['name'],
434      'LINK' => make_index_url(
435          array(
436            'category' => array(
437              'id' => $category['id'],
438              'name' => $category['name'],
439              'permalink' => $category['permalink']
440              ))),
441      'CPL_CONTENT' => empty($_POST['mail_content'])
442                          ? '' : stripslashes($_POST['mail_content'])
443    ),
444    '' /* TODO Add listbox in order to choose Language selected */);
445
446  unset_make_full_url();
447
448  $query = '
449SELECT
450    name
451  FROM '.GROUPS_TABLE.'
452  WHERE id = '.$_POST['group'].'
453;';
454  list($group_name) = pwg_db_fetch_row(pwg_query($query));
455
456  array_push(
457    $page['infos'],
458    sprintf(
459      l10n('An information email was sent to group "%s"'),
460      $group_name
461      )
462    );
463}
464
465if ('private' == $category['status'])
466{
467  $query = '
468SELECT
469    group_id
470  FROM '.GROUP_ACCESS_TABLE.'
471  WHERE cat_id = '.$category['id'].'
472;';
473}
474else
475{
476  $query = '
477SELECT
478    id AS group_id
479  FROM '.GROUPS_TABLE.'
480;';
481}
482$group_ids = array_from_query($query, 'group_id');
483
484if (count($group_ids) > 0)
485{
486  $query = '
487SELECT
488    id,
489    name
490  FROM '.GROUPS_TABLE.'
491  WHERE id IN ('.implode(',', $group_ids).')
492  ORDER BY name ASC
493;';
494  $template->assign('group_mail_options',
495      simple_hash_from_query($query, 'id', 'name')
496    );
497}
498
499trigger_action('loc_end_cat_modify');
500
501//----------------------------------------------------------- sending html code
502$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
503?>
Note: See TracBrowser for help on using the repository browser.