source: branches/2.3/admin/cat_modify.php @ 23983

Last change on this file since 23983 was 12590, checked in by plg, 13 years ago

bug 2497 fixed: never try to move a physical album

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