source: trunk/admin/cat_modify.php @ 11041

Last change on this file since 11041 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
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    );
[11041]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
[1500]282}
283
[809]284// representant management
[2324]285if ($category['has_images']
[809]286    or !empty($category['representative_picture_id']))
287{
[2223]288  $tpl_representant = array();
[809]289
290  // picture to display : the identified representant or the generic random
291  // representant ?
292  if (!empty($category['representative_picture_id']))
293  {
294    $query = '
[1609]295SELECT id,tn_ext,path
[633]296  FROM '.IMAGES_TABLE.'
297  WHERE id = '.$category['representative_picture_id'].'
298;';
[4325]299    $row = pwg_db_fetch_assoc(pwg_query($query));
[1609]300    $src = get_thumbnail_url($row);
[2286]301    $url = get_root_url().'admin.php?page=picture_modify';
[809]302    $url.= '&amp;image_id='.$category['representative_picture_id'];
[1131]303
[2223]304    $tpl_representant['picture'] =
[809]305      array(
306        'SRC' => $src,
307        'URL' => $url
308      );
309  }
310
311  // can the admin choose to set a new random representant ?
[2324]312  $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false;
[809]313
314  // can the admin delete the current representant ?
315  if (
[2324]316    ($category['has_images']
[809]317     and $conf['allow_random_representative'])
318    or
[2324]319    (!$category['has_images']
[809]320     and !empty($category['representative_picture_id'])))
321  {
[2223]322    $tpl_representant['ALLOW_DELETE'] = true;
[809]323  }
[2223]324  $template->assign('representant', $tpl_representant);
[633]325}
326
[2223]327if ($category['is_virtual'])
[68]328{
[809]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']));
[1131]332
[809]333  $query = '
334SELECT id,name,uppercats,global_rank
335  FROM '.CATEGORIES_TABLE.'
336  WHERE id NOT IN ('.implode(',', $unmovables).')
337;';
[1131]338
[809]339  display_select_cat_wrapper(
340    $query,
341    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
[2223]342    'move_cat_options'
[809]343    );
344}
345
[403]346
[2223]347// create virtual in parent and link
[1064]348$query = '
349SELECT id,name,uppercats,global_rank
350  FROM '.CATEGORIES_TABLE.'
351;';
352display_select_cat_wrapper(
353  $query,
354  array(),
[2223]355  'create_new_parent_options'
[1064]356  );
357
[2223]358
[1064]359// destination categories
360$query = '
[1121]361SELECT id,name,uppercats,global_rank
[1064]362  FROM '.CATEGORIES_TABLE.'
[1121]363  WHERE id != '.$category['id'].'
[1064]364;';
[1121]365display_select_cat_wrapper(
366  $query,
367  array(),
[2223]368  'category_destination_options'
[1064]369  );
370
[1895]371// info by email to an access granted group of category informations
[2140]372if (isset($_POST['submitEmail']) and !empty($_POST['group']))
[1895]373{
[1904]374  set_make_full_url();
375
[5335]376  /* TODO: if $category['representative_picture_id']
[1904]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'].'
[1895]384;';
[1064]385
[1904]386    $result = pwg_query($query);
[4325]387    if (pwg_db_num_rows($result) > 0)
[1904]388    {
[4325]389      $element = pwg_db_fetch_assoc($result);
[1904]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                        ))
[3185]397                      .'" class="thumblnk"><img src="'.get_thumbnail_url($element).'"></a>';
[1904]398    }
399  }
[5335]400
[1904]401  if (!isset($img_url))
[1895]402  {
[1904]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*/
[7024]410    get_l10n_args('[%s] Visit album %s',
[1916]411      array($conf['gallery_title'], $category['name'])),
[1904]412    'cat_group_info',
413    array
414    (
415      'IMG_URL' => $img_url,
[1916]416      'CAT_NAME' => $category['name'],
[1904]417      'LINK' => make_index_url(
[1895]418          array(
419            'category' => array(
420              'id' => $category['id'],
421              'name' => $category['name'],
[1904]422              'permalink' => $category['permalink']
423              ))),
[1916]424      'CPL_CONTENT' => empty($_POST['mail_content'])
425                          ? '' : stripslashes($_POST['mail_content'])
[1904]426    ),
427    '' /* TODO Add listbox in order to choose Language selected */);
[1895]428
[1904]429  unset_make_full_url();
430
[1895]431  $query = '
432SELECT
433    name
434  FROM '.GROUPS_TABLE.'
435  WHERE id = '.$_POST['group'].'
436;';
[4325]437  list($group_name) = pwg_db_fetch_row(pwg_query($query));
[5335]438
[1895]439  array_push(
440    $page['infos'],
441    sprintf(
[5207]442      l10n('An information email was sent to group "%s"'),
[1895]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;';
[2223]477  $template->assign('group_mail_options',
478      simple_hash_from_query($query, 'id', 'name')
479    );
[1895]480}
481
[5933]482trigger_action('loc_end_cat_modify');
483
[21]484//----------------------------------------------------------- sending html code
[403]485$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
[7024]486?>
Note: See TracBrowser for help on using the repository browser.