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

Last change on this file since 12575 was 12575, checked in by plg, 9 years ago

bug 2491 fixed: on album admin screen, don't display "1 album moved" message
when the album is not really moved.

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