source: trunk/admin/cat_modify.php @ 12482

Last change on this file since 12482 was 11041, checked in by plg, 13 years ago

merge r11040 from branch 2.2 to trunk

bug 1786 fixed: ability to prefilter the synchronize screen with a specific
album by clicking on the new "Synchronize" icon on album admin page or album
admin list.

This is not the solution proposed by Gotcha (ie a treeview to select the album
on the synchronize screen) but it solves the same problem.

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