source: trunk/admin/cat_modify.php @ 8665

Last change on this file since 8665 was 8651, checked in by plg, 13 years ago

feature 2108 added: user upload removed from core. It will come back as a
"new generation" user upload in the Community plugin.

  • Property svn:eol-style set to LF
File size: 14.9 KB
RevLine 
[21]1<?php
[362]2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[5196]5// | Copyright(C) 2008-2010 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{
[2490]47  $image_order = null;
48  if ( !isset($_POST['image_order_default']) )
49  {
50    for ($i=1; $i<=3; $i++)
51    {
52      if ( !empty($_POST['order_field_'.$i]) )
53      {
54        if (! empty($image_order) )
55        {
56          $image_order .= ',';
57        }
58        $image_order .= $_POST['order_field_'.$i];
59        if ($_POST['order_direction_'.$i]=='DESC')
60        {
61          $image_order .= ' DESC';
62        }
63      }
64    }
65  }
66
[825]67  $data =
68    array(
69      'id' => $_GET['cat_id'],
70      'name' => @$_POST['name'],
[4367]71      'commentable' => isset($_POST['commentable'])?$_POST['commentable']:'false',
[825]72      'comment' =>
73        $conf['allow_html_descriptions'] ?
[2490]74          @$_POST['comment'] : strip_tags(@$_POST['comment']),
75      'image_order' => $image_order,
[825]76      );
[38]77
[825]78  mass_updates(
79    CATEGORIES_TABLE,
80    array(
81      'primary' => array('id'),
82      'update' => array_diff(array_keys($data), array('id'))
83      ),
84    array($data)
85    );
[1131]86
[2490]87  // retrieve cat infos before continuing (following updates are expensive)
88  $cat_info = get_cat_info($_GET['cat_id']);
[345]89
[2490]90  if (isset($_POST['image_order_subcats']))
[809]91  {
[2490]92    $query = '
[6550]93UPDATE '.CATEGORIES_TABLE.' SET image_order='.(isset($image_order) ? 'NULL':'\''.$image_order.'\'').'
94  WHERE uppercats LIKE \''.$cat_info['uppercats'].',%\'';
[2490]95    pwg_query($query);
[809]96  }
97
[2490]98  if ($cat_info['visible'] != get_boolean( $_POST['visible'] ) )
[1500]99  {
[2490]100    set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
[1500]101  }
[2653]102  if ($cat_info['status'] != $_POST['status'] )
[1500]103  {
[2490]104    set_cat_status(array($_GET['cat_id']), $_POST['status']);
[1500]105  }
[2490]106
107  if (isset($_POST['parent']) and $cat_info['id_uppercat'] != $_POST['parent'])
[1500]108  {
[2490]109    move_categories( array($_GET['cat_id']), $_POST['parent'] );
[1500]110  }
111
[6988]112  array_push($page['infos'], l10n('Album updated successfully'));
[21]113}
[2490]114elseif (isset($_POST['set_random_representant']))
[633]115{
116  set_random_representant(array($_GET['cat_id']));
117}
[2490]118elseif (isset($_POST['delete_representant']))
[809]119{
120  $query = '
121UPDATE '.CATEGORIES_TABLE.'
122  SET representative_picture_id = NULL
123  WHERE id = '.$_GET['cat_id'].'
124;';
125  pwg_query($query);
126}
[2490]127elseif (isset($_POST['submitAdd']))
[1064]128{
129  $output_create = create_virtual_category(
130    $_POST['virtual_name'],
131    (0 == $_POST['parent'] ? null : $_POST['parent'])
132    );
[1131]133
[1064]134  if (isset($output_create['error']))
135  {
136    array_push($page['errors'], $output_create['error']);
137  }
138  else
139  {
[6969]140    // Virtual album creation succeeded
[1064]141    //
142    // Add the information in the information list
143    array_push($page['infos'], $output_create['info']);
[1131]144
[1064]145    // Link the new category to the current category
[1121]146    associate_categories_to_categories(
147      array($_GET['cat_id']),
148      array($output_create['id'])
149      );
[21]150
[1121]151    // information
[1064]152    array_push(
[1121]153      $page['infos'],
154      sprintf(
[6988]155        l10n('Album elements associated to the following albums: %s'),
[1121]156        '<ul><li>'
157        .get_cat_display_name_from_id($output_create['id'])
158        .'</li></ul>'
[1064]159        )
160      );
161  }
162}
[2490]163elseif (isset($_POST['submitDestinations'])
[1121]164         and isset($_POST['destinations'])
165         and count($_POST['destinations']) > 0)
[1064]166{
[1121]167  associate_categories_to_categories(
168    array($_GET['cat_id']),
169    $_POST['destinations']
170    );
[1064]171
[1121]172  $category_names = array();
173  foreach ($_POST['destinations'] as $category_id)
[1064]174  {
175    array_push(
[1121]176      $category_names,
177      get_cat_display_name_from_id($category_id)
[1064]178      );
179  }
180
[1121]181  array_push(
182    $page['infos'],
183    sprintf(
[6988]184      l10n('Album elements associated to the following albums: %s'),
[1121]185      '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
186      )
[1064]187    );
188}
189
[632]190$query = '
191SELECT *
192  FROM '.CATEGORIES_TABLE.'
193  WHERE id = '.$_GET['cat_id'].'
194;';
[4325]195$category = pwg_db_fetch_assoc( pwg_query( $query ) );
[530]196// nullable fields
[809]197foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
[530]198{
199  if (!isset($category[$nullable]))
200  {
201    $category[$nullable] = '';
202  }
203}
[345]204
[809]205$category['is_virtual'] = empty($category['dir']) ? true : false;
206
[2324]207$query = 'SELECT DISTINCT category_id
208  FROM '.IMAGE_CATEGORY_TABLE.'
209  WHERE category_id = '.$_GET['cat_id'].'
210  LIMIT 1';
211$result = pwg_query($query);
[4325]212$category['has_images'] = pwg_db_num_rows($result)>0 ? true : false;
[2223]213
[403]214// Navigation path
[834]215$navigation = get_cat_display_name_cache(
[635]216  $category['uppercats'],
[2286]217  get_root_url().'admin.php?page=cat_modify&amp;cat_id='
[834]218  );
[345]219
[2286]220$form_action = get_root_url().'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
[403]221
222//----------------------------------------------------- template initialization
[2530]223$template->set_filename( 'categories', 'cat_modify.tpl');
[809]224
[2286]225$base_url = get_root_url().'admin.php?page=';
[809]226$cat_list_url = $base_url.'cat_list';
[1131]227
[809]228$self_url = $cat_list_url;
229if (!empty($category['id_uppercat']))
230{
231  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
232}
233
[2223]234$template->assign(
[1131]235  array(
[1082]236    'CATEGORIES_NAV'     => $navigation,
[2777]237    'CAT_ID'             => $category['id'],
[2223]238    'CAT_NAME'           => @htmlspecialchars($category['name']),
239    'CAT_COMMENT'        => @htmlspecialchars($category['comment']),
[1131]240
[2223]241    'status_values'     => array('public','private'),
[1131]242
[2223]243    'CAT_STATUS'        => $category['status'],
[4385]244    'CAT_VISIBLE'       => boolean_to_string($category['visible']),
245    'CAT_COMMENTABLE'   => boolean_to_string($category['commentable']),
[2223]246
[1500]247    'IMG_ORDER_DEFAULT'  => empty($category['image_order']) ?
248                              'checked="checked"' : '',
249
[1082]250    'U_JUMPTO' => make_index_url(
251      array(
[1861]252        'category' => $category
[1082]253        )
254      ),
[1131]255
[1916]256    'MAIL_CONTENT' => empty($_POST['mail_content'])
257        ? '' : stripslashes($_POST['mail_content']),
[1082]258    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
[5920]259    'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_modify',
[1131]260
[1082]261    'F_ACTION' => $form_action,
262    )
263  );
[633]264
[809]265
266if ('private' == $category['status'])
267{
[2223]268  $template->assign( 'U_MANAGE_PERMISSIONS',
269      $base_url.'cat_perm&amp;cat='.$category['id']
[809]270    );
271}
272
[6988]273// manage album elements link
[2324]274if ($category['has_images'])
[633]275{
[2517]276  $template->assign(
277    'U_MANAGE_ELEMENTS',
[8417]278    $base_url.'batch_manager&amp;cat='.$category['id']
[2223]279    );
[2517]280  $template->assign(
281    'U_MANAGE_RANKS',
282    $base_url.'element_set_ranks&amp;cat_id='.$category['id']
283    );
[2223]284}
285
286if ($category['is_virtual'])
287{
288  $template->assign(
[809]289    array(
[5335]290      'U_DELETE' => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
[809]291      )
292    );
293}
[2223]294else
[1500]295{
[2223]296  $category['cat_full_dir'] = get_complete_dir($_GET['cat_id']);
297  $template->assign(
298    array(
299      'CAT_FULL_DIR'       => preg_replace('/\/$/',
300                                    '',
301                                    $category['cat_full_dir'] )
302      )
303    );
[1500]304}
305
[2223]306// image order management
307
[1500]308$sort_fields = array(
309  '' => '',
310  'date_creation' => l10n('Creation date'),
311  'date_available' => l10n('Post date'),
312  'average_rate' => l10n('Average rate'),
[5021]313  'hit' => l10n('Most visited'),
[1500]314  'file' => l10n('File name'),
315  'id' => 'Id',
[2517]316  'rank' => l10n('Rank'),
[1500]317  );
318
[2223]319$sort_directions = array(
320  'ASC' => l10n('ascending'),
321  'DESC' => l10n('descending'),
322  );
323
324$template->assign( 'image_order_field_options', $sort_fields);
325$template->assign( 'image_order_direction_options', $sort_directions);
326
327$matches = array();
328if ( !empty( $category['image_order'] ) )
329{
330  preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i',
331    $category['image_order'], $matches);
332}
333
[1500]334for ($i=0; $i<3; $i++) // 3 fields
335{
[2223]336  $tpl_image_order_select = array(
337      'ID' => $i+1,
338      'FIELD' => array(''),
339      'DIRECTION' => array('ASC'),
340    );
[5335]341
[2223]342  if ( isset($matches[1][$i]) )
[1500]343  {
[2223]344    $tpl_image_order_select['FIELD'] = array($matches[1][$i]);
[1500]345  }
[5335]346
[2223]347  if (isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0)
348  {
349    $tpl_image_order_select['DIRECTION'] = array('DESC');
350  }
351  $template->append( 'image_orders', $tpl_image_order_select);
[1500]352}
353
354
[809]355// representant management
[2324]356if ($category['has_images']
[809]357    or !empty($category['representative_picture_id']))
358{
[2223]359  $tpl_representant = array();
[809]360
361  // picture to display : the identified representant or the generic random
362  // representant ?
363  if (!empty($category['representative_picture_id']))
364  {
365    $query = '
[1609]366SELECT id,tn_ext,path
[633]367  FROM '.IMAGES_TABLE.'
368  WHERE id = '.$category['representative_picture_id'].'
369;';
[4325]370    $row = pwg_db_fetch_assoc(pwg_query($query));
[1609]371    $src = get_thumbnail_url($row);
[2286]372    $url = get_root_url().'admin.php?page=picture_modify';
[809]373    $url.= '&amp;image_id='.$category['representative_picture_id'];
[1131]374
[2223]375    $tpl_representant['picture'] =
[809]376      array(
377        'SRC' => $src,
378        'URL' => $url
379      );
380  }
381
382  // can the admin choose to set a new random representant ?
[2324]383  $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false;
[809]384
385  // can the admin delete the current representant ?
386  if (
[2324]387    ($category['has_images']
[809]388     and $conf['allow_random_representative'])
389    or
[2324]390    (!$category['has_images']
[809]391     and !empty($category['representative_picture_id'])))
392  {
[2223]393    $tpl_representant['ALLOW_DELETE'] = true;
[809]394  }
[2223]395  $template->assign('representant', $tpl_representant);
[633]396}
397
[2223]398if ($category['is_virtual'])
[68]399{
[809]400  // the category can be moved in any category but in itself, in any
401  // sub-category
402  $unmovables = get_subcat_ids(array($category['id']));
[1131]403
[809]404  $query = '
405SELECT id,name,uppercats,global_rank
406  FROM '.CATEGORIES_TABLE.'
407  WHERE id NOT IN ('.implode(',', $unmovables).')
408;';
[1131]409
[809]410  display_select_cat_wrapper(
411    $query,
412    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
[2223]413    'move_cat_options'
[809]414    );
415}
416
[403]417
[2223]418// create virtual in parent and link
[1064]419$query = '
420SELECT id,name,uppercats,global_rank
421  FROM '.CATEGORIES_TABLE.'
422;';
423display_select_cat_wrapper(
424  $query,
425  array(),
[2223]426  'create_new_parent_options'
[1064]427  );
428
[2223]429
[1064]430// destination categories
431$query = '
[1121]432SELECT id,name,uppercats,global_rank
[1064]433  FROM '.CATEGORIES_TABLE.'
[1121]434  WHERE id != '.$category['id'].'
[1064]435;';
[1121]436display_select_cat_wrapper(
437  $query,
438  array(),
[2223]439  'category_destination_options'
[1064]440  );
441
[1895]442// info by email to an access granted group of category informations
[2140]443if (isset($_POST['submitEmail']) and !empty($_POST['group']))
[1895]444{
[1904]445  set_make_full_url();
446
[5335]447  /* TODO: if $category['representative_picture_id']
[1904]448    is empty find child representative_picture_id */
449  if (!empty($category['representative_picture_id']))
450  {
451    $query = '
452SELECT id, file, path, tn_ext
453  FROM '.IMAGES_TABLE.'
454  WHERE id = '.$category['representative_picture_id'].'
[1895]455;';
[1064]456
[1904]457    $result = pwg_query($query);
[4325]458    if (pwg_db_num_rows($result) > 0)
[1904]459    {
[4325]460      $element = pwg_db_fetch_assoc($result);
[1904]461
462      $img_url  = '<a href="'.
463                      make_picture_url(array(
464                          'image_id' => $element['id'],
465                          'image_file' => $element['file'],
466                          'category' => $category
467                        ))
[3185]468                      .'" class="thumblnk"><img src="'.get_thumbnail_url($element).'"></a>';
[1904]469    }
470  }
[5335]471
[1904]472  if (!isset($img_url))
[1895]473  {
[1904]474    $img_url = '';
475  }
476
477  // TODO Mettre un array pour traduction subjet
478  pwg_mail_group(
479    $_POST['group'],
480    get_str_email_format(true), /* TODO add a checkbox in order to choose format*/
[7024]481    get_l10n_args('[%s] Visit album %s',
[1916]482      array($conf['gallery_title'], $category['name'])),
[1904]483    'cat_group_info',
484    array
485    (
486      'IMG_URL' => $img_url,
[1916]487      'CAT_NAME' => $category['name'],
[1904]488      'LINK' => make_index_url(
[1895]489          array(
490            'category' => array(
491              'id' => $category['id'],
492              'name' => $category['name'],
[1904]493              'permalink' => $category['permalink']
494              ))),
[1916]495      'CPL_CONTENT' => empty($_POST['mail_content'])
496                          ? '' : stripslashes($_POST['mail_content'])
[1904]497    ),
498    '' /* TODO Add listbox in order to choose Language selected */);
[1895]499
[1904]500  unset_make_full_url();
501
[1895]502  $query = '
503SELECT
504    name
505  FROM '.GROUPS_TABLE.'
506  WHERE id = '.$_POST['group'].'
507;';
[4325]508  list($group_name) = pwg_db_fetch_row(pwg_query($query));
[5335]509
[1895]510  array_push(
511    $page['infos'],
512    sprintf(
[5207]513      l10n('An information email was sent to group "%s"'),
[1895]514      $group_name
515      )
516    );
517}
518
519if ('private' == $category['status'])
520{
521  $query = '
522SELECT
523    group_id
524  FROM '.GROUP_ACCESS_TABLE.'
525  WHERE cat_id = '.$category['id'].'
526;';
527}
528else
529{
530  $query = '
531SELECT
532    id AS group_id
533  FROM '.GROUPS_TABLE.'
534;';
535}
536$group_ids = array_from_query($query, 'group_id');
537
538if (count($group_ids) > 0)
539{
540  $query = '
541SELECT
542    id,
543    name
544  FROM '.GROUPS_TABLE.'
545  WHERE id IN ('.implode(',', $group_ids).')
546  ORDER BY name ASC
547;';
[2223]548  $template->assign('group_mail_options',
549      simple_hash_from_query($query, 'id', 'name')
550    );
[1895]551}
552
[5933]553trigger_action('loc_end_cat_modify');
554
[21]555//----------------------------------------------------------- sending html code
[403]556$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
[7024]557?>
Note: See TracBrowser for help on using the repository browser.