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
RevLine 
[21]1<?php
[362]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[21]23
[632]24if (!defined('PHPWG_ROOT_PATH'))
[403]25{
[632]26  die('Hacking attempt!');
[403]27}
[1072]28
[1895]29include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
[1072]30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
[5933]36trigger_action('loc_begin_cat_modify');
37
[21]38//---------------------------------------------------------------- verification
[403]39if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) )
[21]40{
[2490]41  trigger_error( 'missing cat_id param', E_USER_ERROR);
[21]42}
[403]43
[21]44//--------------------------------------------------------- form criteria check
[825]45if (isset($_POST['submit']))
[21]46{
[825]47  $data =
48    array(
49      'id' => $_GET['cat_id'],
50      'name' => @$_POST['name'],
[4367]51      'commentable' => isset($_POST['commentable'])?$_POST['commentable']:'false',
[825]52      'comment' =>
53        $conf['allow_html_descriptions'] ?
[2490]54          @$_POST['comment'] : strip_tags(@$_POST['comment']),
[825]55      );
[38]56
[825]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    );
[1131]65
[2490]66  // retrieve cat infos before continuing (following updates are expensive)
67  $cat_info = get_cat_info($_GET['cat_id']);
[345]68
[2490]69  if ($cat_info['visible'] != get_boolean( $_POST['visible'] ) )
[1500]70  {
[2490]71    set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
[1500]72  }
[2653]73  if ($cat_info['status'] != $_POST['status'] )
[1500]74  {
[2490]75    set_cat_status(array($_GET['cat_id']), $_POST['status']);
[1500]76  }
[2490]77
78  if (isset($_POST['parent']) and $cat_info['id_uppercat'] != $_POST['parent'])
[1500]79  {
[2490]80    move_categories( array($_GET['cat_id']), $_POST['parent'] );
[1500]81  }
82
[6988]83  array_push($page['infos'], l10n('Album updated successfully'));
[21]84}
[2490]85elseif (isset($_POST['set_random_representant']))
[633]86{
87  set_random_representant(array($_GET['cat_id']));
88}
[2490]89elseif (isset($_POST['delete_representant']))
[809]90{
91  $query = '
92UPDATE '.CATEGORIES_TABLE.'
93  SET representative_picture_id = NULL
94  WHERE id = '.$_GET['cat_id'].'
95;';
96  pwg_query($query);
97}
[2490]98elseif (isset($_POST['submitAdd']))
[1064]99{
100  $output_create = create_virtual_category(
101    $_POST['virtual_name'],
102    (0 == $_POST['parent'] ? null : $_POST['parent'])
103    );
[1131]104
[1064]105  if (isset($output_create['error']))
106  {
107    array_push($page['errors'], $output_create['error']);
108  }
109  else
110  {
[6969]111    // Virtual album creation succeeded
[1064]112    //
113    // Add the information in the information list
114    array_push($page['infos'], $output_create['info']);
[1131]115
[1064]116    // Link the new category to the current category
[1121]117    associate_categories_to_categories(
118      array($_GET['cat_id']),
119      array($output_create['id'])
120      );
[21]121
[1121]122    // information
[1064]123    array_push(
[1121]124      $page['infos'],
125      sprintf(
[8727]126        l10n('Album photos associated to the following albums: %s'),
[1121]127        '<ul><li>'
128        .get_cat_display_name_from_id($output_create['id'])
129        .'</li></ul>'
[1064]130        )
131      );
132  }
133}
[2490]134elseif (isset($_POST['submitDestinations'])
[1121]135         and isset($_POST['destinations'])
136         and count($_POST['destinations']) > 0)
[1064]137{
[1121]138  associate_categories_to_categories(
139    array($_GET['cat_id']),
140    $_POST['destinations']
141    );
[1064]142
[1121]143  $category_names = array();
144  foreach ($_POST['destinations'] as $category_id)
[1064]145  {
146    array_push(
[1121]147      $category_names,
148      get_cat_display_name_from_id($category_id)
[1064]149      );
150  }
151
[1121]152  array_push(
153    $page['infos'],
154    sprintf(
[8727]155      l10n('Album photos associated to the following albums: %s'),
[1121]156      '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
157      )
[1064]158    );
159}
160
[632]161$query = '
162SELECT *
163  FROM '.CATEGORIES_TABLE.'
164  WHERE id = '.$_GET['cat_id'].'
165;';
[4325]166$category = pwg_db_fetch_assoc( pwg_query( $query ) );
[530]167// nullable fields
[809]168foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
[530]169{
170  if (!isset($category[$nullable]))
171  {
172    $category[$nullable] = '';
173  }
174}
[345]175
[809]176$category['is_virtual'] = empty($category['dir']) ? true : false;
177
[2324]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);
[4325]183$category['has_images'] = pwg_db_num_rows($result)>0 ? true : false;
[2223]184
[403]185// Navigation path
[834]186$navigation = get_cat_display_name_cache(
[635]187  $category['uppercats'],
[2286]188  get_root_url().'admin.php?page=cat_modify&amp;cat_id='
[834]189  );
[345]190
[2286]191$form_action = get_root_url().'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
[403]192
193//----------------------------------------------------- template initialization
[2530]194$template->set_filename( 'categories', 'cat_modify.tpl');
[809]195
[2286]196$base_url = get_root_url().'admin.php?page=';
[809]197$cat_list_url = $base_url.'cat_list';
[1131]198
[809]199$self_url = $cat_list_url;
200if (!empty($category['id_uppercat']))
201{
202  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
203}
204
[2223]205$template->assign(
[1131]206  array(
[1082]207    'CATEGORIES_NAV'     => $navigation,
[2777]208    'CAT_ID'             => $category['id'],
[2223]209    'CAT_NAME'           => @htmlspecialchars($category['name']),
210    'CAT_COMMENT'        => @htmlspecialchars($category['comment']),
[1131]211
[2223]212    'status_values'     => array('public','private'),
[1131]213
[2223]214    'CAT_STATUS'        => $category['status'],
[4385]215    'CAT_VISIBLE'       => boolean_to_string($category['visible']),
216    'CAT_COMMENTABLE'   => boolean_to_string($category['commentable']),
[2223]217
[1082]218    'U_JUMPTO' => make_index_url(
219      array(
[1861]220        'category' => $category
[1082]221        )
222      ),
[1131]223
[1916]224    'MAIL_CONTENT' => empty($_POST['mail_content'])
225        ? '' : stripslashes($_POST['mail_content']),
[1082]226    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
[5920]227    'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_modify',
[1131]228
[1082]229    'F_ACTION' => $form_action,
230    )
231  );
[633]232
[809]233
234if ('private' == $category['status'])
235{
[2223]236  $template->assign( 'U_MANAGE_PERMISSIONS',
237      $base_url.'cat_perm&amp;cat='.$category['id']
[809]238    );
239}
240
[6988]241// manage album elements link
[2324]242if ($category['has_images'])
[633]243{
[2517]244  $template->assign(
245    'U_MANAGE_ELEMENTS',
[8417]246    $base_url.'batch_manager&amp;cat='.$category['id']
[2223]247    );
248}
249
[9051]250$template->assign(
251  'U_MANAGE_RANKS',
252  $base_url.'element_set_ranks&amp;cat_id='.$category['id']
253  );
254
[2223]255if ($category['is_virtual'])
256{
257  $template->assign(
[809]258    array(
[5335]259      'U_DELETE' => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
[809]260      )
261    );
262}
[2223]263else
[1500]264{
[2223]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    );
[1500]273}
274
[809]275// representant management
[2324]276if ($category['has_images']
[809]277    or !empty($category['representative_picture_id']))
278{
[2223]279  $tpl_representant = array();
[809]280
281  // picture to display : the identified representant or the generic random
282  // representant ?
283  if (!empty($category['representative_picture_id']))
284  {
285    $query = '
[1609]286SELECT id,tn_ext,path
[633]287  FROM '.IMAGES_TABLE.'
288  WHERE id = '.$category['representative_picture_id'].'
289;';
[4325]290    $row = pwg_db_fetch_assoc(pwg_query($query));
[1609]291    $src = get_thumbnail_url($row);
[2286]292    $url = get_root_url().'admin.php?page=picture_modify';
[809]293    $url.= '&amp;image_id='.$category['representative_picture_id'];
[1131]294
[2223]295    $tpl_representant['picture'] =
[809]296      array(
297        'SRC' => $src,
298        'URL' => $url
299      );
300  }
301
302  // can the admin choose to set a new random representant ?
[2324]303  $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false;
[809]304
305  // can the admin delete the current representant ?
306  if (
[2324]307    ($category['has_images']
[809]308     and $conf['allow_random_representative'])
309    or
[2324]310    (!$category['has_images']
[809]311     and !empty($category['representative_picture_id'])))
312  {
[2223]313    $tpl_representant['ALLOW_DELETE'] = true;
[809]314  }
[2223]315  $template->assign('representant', $tpl_representant);
[633]316}
317
[2223]318if ($category['is_virtual'])
[68]319{
[809]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']));
[1131]323
[809]324  $query = '
325SELECT id,name,uppercats,global_rank
326  FROM '.CATEGORIES_TABLE.'
327  WHERE id NOT IN ('.implode(',', $unmovables).')
328;';
[1131]329
[809]330  display_select_cat_wrapper(
331    $query,
332    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
[2223]333    'move_cat_options'
[809]334    );
335}
336
[403]337
[2223]338// create virtual in parent and link
[1064]339$query = '
340SELECT id,name,uppercats,global_rank
341  FROM '.CATEGORIES_TABLE.'
342;';
343display_select_cat_wrapper(
344  $query,
345  array(),
[2223]346  'create_new_parent_options'
[1064]347  );
348
[2223]349
[1064]350// destination categories
351$query = '
[1121]352SELECT id,name,uppercats,global_rank
[1064]353  FROM '.CATEGORIES_TABLE.'
[1121]354  WHERE id != '.$category['id'].'
[1064]355;';
[1121]356display_select_cat_wrapper(
357  $query,
358  array(),
[2223]359  'category_destination_options'
[1064]360  );
361
[1895]362// info by email to an access granted group of category informations
[2140]363if (isset($_POST['submitEmail']) and !empty($_POST['group']))
[1895]364{
[1904]365  set_make_full_url();
366
[5335]367  /* TODO: if $category['representative_picture_id']
[1904]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'].'
[1895]375;';
[1064]376
[1904]377    $result = pwg_query($query);
[4325]378    if (pwg_db_num_rows($result) > 0)
[1904]379    {
[4325]380      $element = pwg_db_fetch_assoc($result);
[1904]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                        ))
[3185]388                      .'" class="thumblnk"><img src="'.get_thumbnail_url($element).'"></a>';
[1904]389    }
390  }
[5335]391
[1904]392  if (!isset($img_url))
[1895]393  {
[1904]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*/
[7024]401    get_l10n_args('[%s] Visit album %s',
[1916]402      array($conf['gallery_title'], $category['name'])),
[1904]403    'cat_group_info',
404    array
405    (
406      'IMG_URL' => $img_url,
[1916]407      'CAT_NAME' => $category['name'],
[1904]408      'LINK' => make_index_url(
[1895]409          array(
410            'category' => array(
411              'id' => $category['id'],
412              'name' => $category['name'],
[1904]413              'permalink' => $category['permalink']
414              ))),
[1916]415      'CPL_CONTENT' => empty($_POST['mail_content'])
416                          ? '' : stripslashes($_POST['mail_content'])
[1904]417    ),
418    '' /* TODO Add listbox in order to choose Language selected */);
[1895]419
[1904]420  unset_make_full_url();
421
[1895]422  $query = '
423SELECT
424    name
425  FROM '.GROUPS_TABLE.'
426  WHERE id = '.$_POST['group'].'
427;';
[4325]428  list($group_name) = pwg_db_fetch_row(pwg_query($query));
[5335]429
[1895]430  array_push(
431    $page['infos'],
432    sprintf(
[5207]433      l10n('An information email was sent to group "%s"'),
[1895]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;';
[2223]468  $template->assign('group_mail_options',
469      simple_hash_from_query($query, 'id', 'name')
470    );
[1895]471}
472
[5933]473trigger_action('loc_end_cat_modify');
474
[21]475//----------------------------------------------------------- sending html code
[403]476$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
[7024]477?>
Note: See TracBrowser for help on using the repository browser.