source: trunk/admin/cat_modify.php @ 9491

Last change on this file since 9491 was 9051, checked in by plg, 14 years ago

bug 2172 fixed: the "sort order" options are removed from the album administration main page.

bug 2173 fixed: rename "manual order" into "automatic order" and "by rank" into "manual order"

bug 2174 fixed: only show the automatic order options when it's relevant

new icon for the "manage photo order" screen

hide the numeric rank below the thumbnail (it is confusing for users)

tell users that you can drag'n drop to reorder photos

bug fixed: the "apply to sub-albums" options for photo orders was not working

  • Property svn:eol-style set to LF
File size: 12.9 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
275// representant management
276if ($category['has_images']
277    or !empty($category['representative_picture_id']))
278{
279  $tpl_representant = array();
280
281  // picture to display : the identified representant or the generic random
282  // representant ?
283  if (!empty($category['representative_picture_id']))
284  {
285    $query = '
286SELECT id,tn_ext,path
287  FROM '.IMAGES_TABLE.'
288  WHERE id = '.$category['representative_picture_id'].'
289;';
290    $row = pwg_db_fetch_assoc(pwg_query($query));
291    $src = get_thumbnail_url($row);
292    $url = get_root_url().'admin.php?page=picture_modify';
293    $url.= '&amp;image_id='.$category['representative_picture_id'];
294
295    $tpl_representant['picture'] =
296      array(
297        'SRC' => $src,
298        'URL' => $url
299      );
300  }
301
302  // can the admin choose to set a new random representant ?
303  $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false;
304
305  // can the admin delete the current representant ?
306  if (
307    ($category['has_images']
308     and $conf['allow_random_representative'])
309    or
310    (!$category['has_images']
311     and !empty($category['representative_picture_id'])))
312  {
313    $tpl_representant['ALLOW_DELETE'] = true;
314  }
315  $template->assign('representant', $tpl_representant);
316}
317
318if ($category['is_virtual'])
319{
320  // the category can be moved in any category but in itself, in any
321  // sub-category
322  $unmovables = get_subcat_ids(array($category['id']));
323
324  $query = '
325SELECT id,name,uppercats,global_rank
326  FROM '.CATEGORIES_TABLE.'
327  WHERE id NOT IN ('.implode(',', $unmovables).')
328;';
329
330  display_select_cat_wrapper(
331    $query,
332    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
333    'move_cat_options'
334    );
335}
336
337
338// create virtual in parent and link
339$query = '
340SELECT id,name,uppercats,global_rank
341  FROM '.CATEGORIES_TABLE.'
342;';
343display_select_cat_wrapper(
344  $query,
345  array(),
346  'create_new_parent_options'
347  );
348
349
350// destination categories
351$query = '
352SELECT id,name,uppercats,global_rank
353  FROM '.CATEGORIES_TABLE.'
354  WHERE id != '.$category['id'].'
355;';
356display_select_cat_wrapper(
357  $query,
358  array(),
359  'category_destination_options'
360  );
361
362// info by email to an access granted group of category informations
363if (isset($_POST['submitEmail']) and !empty($_POST['group']))
364{
365  set_make_full_url();
366
367  /* TODO: if $category['representative_picture_id']
368    is empty find child representative_picture_id */
369  if (!empty($category['representative_picture_id']))
370  {
371    $query = '
372SELECT id, file, path, tn_ext
373  FROM '.IMAGES_TABLE.'
374  WHERE id = '.$category['representative_picture_id'].'
375;';
376
377    $result = pwg_query($query);
378    if (pwg_db_num_rows($result) > 0)
379    {
380      $element = pwg_db_fetch_assoc($result);
381
382      $img_url  = '<a href="'.
383                      make_picture_url(array(
384                          'image_id' => $element['id'],
385                          'image_file' => $element['file'],
386                          'category' => $category
387                        ))
388                      .'" class="thumblnk"><img src="'.get_thumbnail_url($element).'"></a>';
389    }
390  }
391
392  if (!isset($img_url))
393  {
394    $img_url = '';
395  }
396
397  // TODO Mettre un array pour traduction subjet
398  pwg_mail_group(
399    $_POST['group'],
400    get_str_email_format(true), /* TODO add a checkbox in order to choose format*/
401    get_l10n_args('[%s] Visit album %s',
402      array($conf['gallery_title'], $category['name'])),
403    'cat_group_info',
404    array
405    (
406      'IMG_URL' => $img_url,
407      'CAT_NAME' => $category['name'],
408      'LINK' => make_index_url(
409          array(
410            'category' => array(
411              'id' => $category['id'],
412              'name' => $category['name'],
413              'permalink' => $category['permalink']
414              ))),
415      'CPL_CONTENT' => empty($_POST['mail_content'])
416                          ? '' : stripslashes($_POST['mail_content'])
417    ),
418    '' /* TODO Add listbox in order to choose Language selected */);
419
420  unset_make_full_url();
421
422  $query = '
423SELECT
424    name
425  FROM '.GROUPS_TABLE.'
426  WHERE id = '.$_POST['group'].'
427;';
428  list($group_name) = pwg_db_fetch_row(pwg_query($query));
429
430  array_push(
431    $page['infos'],
432    sprintf(
433      l10n('An information email was sent to group "%s"'),
434      $group_name
435      )
436    );
437}
438
439if ('private' == $category['status'])
440{
441  $query = '
442SELECT
443    group_id
444  FROM '.GROUP_ACCESS_TABLE.'
445  WHERE cat_id = '.$category['id'].'
446;';
447}
448else
449{
450  $query = '
451SELECT
452    id AS group_id
453  FROM '.GROUPS_TABLE.'
454;';
455}
456$group_ids = array_from_query($query, 'group_id');
457
458if (count($group_ids) > 0)
459{
460  $query = '
461SELECT
462    id,
463    name
464  FROM '.GROUPS_TABLE.'
465  WHERE id IN ('.implode(',', $group_ids).')
466  ORDER BY name ASC
467;';
468  $template->assign('group_mail_options',
469      simple_hash_from_query($query, 'id', 'name')
470    );
471}
472
473trigger_action('loc_end_cat_modify');
474
475//----------------------------------------------------------- sending html code
476$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
477?>
Note: See TracBrowser for help on using the repository browser.