source: trunk/admin/cat_modify.php @ 13082

Last change on this file since 13082 was 13077, checked in by plg, 12 years ago

feature 2564: redesign on photo administration screen.

  • one screen with several tabs (for now: properties + coi)
  • double select boxes for album associations and representation have been converted to simple multiple select boxes with jQuery Chosen
  • more details about the photo in an introduction text
  • Property svn:eol-style set to LF
File size: 11.1 KB
RevLine 
[21]1<?php
[362]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 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
[12954]31
32// get_complete_dir returns the concatenation of get_site_url and
33// get_local_dir
34// Example : "pets > rex > 1_year_old" is on the the same site as the
35// Piwigo files and this category has 22 for identifier
36// get_complete_dir(22) returns "./galleries/pets/rex/1_year_old/"
37function get_complete_dir( $category_id )
38{
39  return get_site_url($category_id).get_local_dir($category_id);
40}
41
42// get_local_dir returns an array with complete path without the site url
43// Example : "pets > rex > 1_year_old" is on the the same site as the
44// Piwigo files and this category has 22 for identifier
45// get_local_dir(22) returns "pets/rex/1_year_old/"
46function get_local_dir( $category_id )
47{
48  global $page;
49
50  $uppercats = '';
51  $local_dir = '';
52
53  if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) )
54  {
55    $uppercats = $page['plain_structure'][$category_id]['uppercats'];
56  }
57  else
58  {
59    $query = 'SELECT uppercats';
60    $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id;
61    $query.= ';';
62    $row = pwg_db_fetch_assoc( pwg_query( $query ) );
63    $uppercats = $row['uppercats'];
64  }
65
66  $upper_array = explode( ',', $uppercats );
67
68  $database_dirs = array();
69  $query = 'SELECT id,dir';
70  $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')';
71  $query.= ';';
72  $result = pwg_query( $query );
73  while( $row = pwg_db_fetch_assoc( $result ) )
74  {
75    $database_dirs[$row['id']] = $row['dir'];
76  }
77  foreach ($upper_array as $id)
78  {
79    $local_dir.= $database_dirs[$id].'/';
80  }
81
82  return $local_dir;
83}
84
85// retrieving the site url : "http://domain.com/gallery/" or
86// simply "./galleries/"
87function get_site_url($category_id)
88{
89  global $page;
90
91  $query = '
92SELECT galleries_url
93  FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c
94  WHERE s.id = c.site_id
95    AND c.id = '.$category_id.'
96;';
97  $row = pwg_db_fetch_assoc(pwg_query($query));
98  return $row['galleries_url'];
99}
100
[1072]101// +-----------------------------------------------------------------------+
102// | Check Access and exit when user status is not ok                      |
103// +-----------------------------------------------------------------------+
104check_status(ACCESS_ADMINISTRATOR);
105
[5933]106trigger_action('loc_begin_cat_modify');
107
[21]108//---------------------------------------------------------------- verification
[403]109if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) )
[21]110{
[2490]111  trigger_error( 'missing cat_id param', E_USER_ERROR);
[21]112}
[403]113
[21]114//--------------------------------------------------------- form criteria check
[825]115if (isset($_POST['submit']))
[21]116{
[825]117  $data =
118    array(
119      'id' => $_GET['cat_id'],
120      'name' => @$_POST['name'],
121      'comment' =>
122        $conf['allow_html_descriptions'] ?
[2490]123          @$_POST['comment'] : strip_tags(@$_POST['comment']),
[825]124      );
[12887]125     
126  if ($conf['activate_comments'])
127  {
128    $data['commentable'] = isset($_POST['commentable'])?$_POST['commentable']:'false';
129  }
[38]130
[825]131  mass_updates(
132    CATEGORIES_TABLE,
133    array(
134      'primary' => array('id'),
135      'update' => array_diff(array_keys($data), array('id'))
136      ),
137    array($data)
138    );
[1131]139
[2490]140  // retrieve cat infos before continuing (following updates are expensive)
141  $cat_info = get_cat_info($_GET['cat_id']);
[345]142
[2490]143  if ($cat_info['visible'] != get_boolean( $_POST['visible'] ) )
[1500]144  {
[2490]145    set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
[1500]146  }
[2653]147  if ($cat_info['status'] != $_POST['status'] )
[1500]148  {
[2490]149    set_cat_status(array($_GET['cat_id']), $_POST['status']);
[1500]150  }
[2490]151
[12576]152  // in case the use moves his album to the gallery root, we force
153  // $_POST['parent'] from 0 to null to be compared with
154  // $cat_info['id_uppercat']
155  if (empty($_POST['parent']))
[1500]156  {
[12576]157    $_POST['parent'] = null;
158  }
[12591]159
160  // only move virtual albums
161  if (empty($cat_info['dir']) and $cat_info['id_uppercat'] != $_POST['parent'])
[12576]162  {
[2490]163    move_categories( array($_GET['cat_id']), $_POST['parent'] );
[1500]164  }
165
[13013]166  // we redirect to hide/show the "permissions" tab if the category status
167  // has changed
168  $_SESSION['page_infos'] = array(l10n('Album updated successfully'));
169  redirect($admin_album_base_url);
[21]170}
[2490]171elseif (isset($_POST['set_random_representant']))
[633]172{
173  set_random_representant(array($_GET['cat_id']));
174}
[2490]175elseif (isset($_POST['delete_representant']))
[809]176{
177  $query = '
178UPDATE '.CATEGORIES_TABLE.'
179  SET representative_picture_id = NULL
180  WHERE id = '.$_GET['cat_id'].'
181;';
182  pwg_query($query);
183}
[1131]184
[530]185// nullable fields
[809]186foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
[530]187{
188  if (!isset($category[$nullable]))
189  {
190    $category[$nullable] = '';
191  }
192}
[345]193
[809]194$category['is_virtual'] = empty($category['dir']) ? true : false;
195
[2324]196$query = 'SELECT DISTINCT category_id
197  FROM '.IMAGE_CATEGORY_TABLE.'
198  WHERE category_id = '.$_GET['cat_id'].'
199  LIMIT 1';
200$result = pwg_query($query);
[4325]201$category['has_images'] = pwg_db_num_rows($result)>0 ? true : false;
[2223]202
[403]203// Navigation path
[834]204$navigation = get_cat_display_name_cache(
[635]205  $category['uppercats'],
[13013]206  get_root_url().'admin.php?page=album-'
[834]207  );
[345]208
[13013]209$form_action = $admin_album_base_url.'-properties';
[403]210
211//----------------------------------------------------- template initialization
[13013]212$template->set_filename( 'album_properties', 'cat_modify.tpl');
[809]213
[2286]214$base_url = get_root_url().'admin.php?page=';
[809]215$cat_list_url = $base_url.'cat_list';
[1131]216
[809]217$self_url = $cat_list_url;
218if (!empty($category['id_uppercat']))
219{
220  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
221}
222
[2223]223$template->assign(
[1131]224  array(
[1082]225    'CATEGORIES_NAV'     => $navigation,
[2777]226    'CAT_ID'             => $category['id'],
[2223]227    'CAT_NAME'           => @htmlspecialchars($category['name']),
228    'CAT_COMMENT'        => @htmlspecialchars($category['comment']),
[1131]229
[2223]230    'status_values'     => array('public','private'),
[1131]231
[2223]232    'CAT_STATUS'        => $category['status'],
[4385]233    'CAT_VISIBLE'       => boolean_to_string($category['visible']),
[2223]234
[1082]235    'U_JUMPTO' => make_index_url(
236      array(
[1861]237        'category' => $category
[1082]238        )
239      ),
[1131]240
[1082]241    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
[5920]242    'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_modify',
[1131]243
[1082]244    'F_ACTION' => $form_action,
245    )
246  );
[12887]247 
248if ($conf['activate_comments'])
249{
250  $template->assign('CAT_COMMENTABLE', boolean_to_string($category['commentable']));
251}
[633]252
[6988]253// manage album elements link
[2324]254if ($category['has_images'])
[633]255{
[2517]256  $template->assign(
257    'U_MANAGE_ELEMENTS',
[8417]258    $base_url.'batch_manager&amp;cat='.$category['id']
[2223]259    );
[13013]260
261  $query = '
262SELECT
263    COUNT(image_id),
264    MIN(DATE(date_available)),
265    MAX(DATE(date_available))
266  FROM '.IMAGES_TABLE.'
267    JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id
268  WHERE category_id = '.$category['id'].'
269;';
270  list($image_count, $min_date, $max_date) = pwg_db_fetch_row(pwg_query($query));
271
272  if ($min_date == $max_date)
273  {
274    $intro = sprintf(
275      l10n('This album contains %d photos, added on %s.'),
276      $image_count,
277      format_date($min_date)
278      );
279  }
280  else
281  {
282    $intro = sprintf(
283      l10n('This album contains %d photos, added between %s and %s.'),
284      $image_count,
285      format_date($min_date),
286      format_date($max_date)
287      );
288  }
[2223]289}
[13013]290else
291{
292  $intro = l10n('This album contains no photo.');
293}
[2223]294
[13013]295$template->assign('INTRO', $intro);
296
[9051]297$template->assign(
298  'U_MANAGE_RANKS',
299  $base_url.'element_set_ranks&amp;cat_id='.$category['id']
300  );
301
[2223]302if ($category['is_virtual'])
303{
304  $template->assign(
[809]305    array(
[5335]306      'U_DELETE' => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
[809]307      )
308    );
309}
[2223]310else
[1500]311{
[2223]312  $category['cat_full_dir'] = get_complete_dir($_GET['cat_id']);
313  $template->assign(
314    array(
[13013]315      'CAT_FULL_DIR' => preg_replace('/\/$/', '', $category['cat_full_dir'])
[2223]316      )
317    );
[11041]318
319  if ($conf['enable_synchronization'])
320  {
321    $template->assign(
322      'U_SYNC',
323      $base_url.'site_update&amp;site=1&amp;cat_id='.$category['id']
324      );
325  }
326
[1500]327}
328
[809]329// representant management
[2324]330if ($category['has_images']
[809]331    or !empty($category['representative_picture_id']))
332{
[2223]333  $tpl_representant = array();
[809]334
335  // picture to display : the identified representant or the generic random
336  // representant ?
337  if (!empty($category['representative_picture_id']))
338  {
339    $query = '
[12796]340SELECT id,representative_ext,path
[633]341  FROM '.IMAGES_TABLE.'
342  WHERE id = '.$category['representative_picture_id'].'
343;';
[4325]344    $row = pwg_db_fetch_assoc(pwg_query($query));
[12796]345    $src = DerivativeImage::thumb_url($row);
[13077]346    $url = get_root_url().'admin.php?page=photo-'.$category['representative_picture_id'];
[1131]347
[2223]348    $tpl_representant['picture'] =
[809]349      array(
350        'SRC' => $src,
351        'URL' => $url
352      );
353  }
354
355  // can the admin choose to set a new random representant ?
[2324]356  $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false;
[809]357
358  // can the admin delete the current representant ?
359  if (
[2324]360    ($category['has_images']
[809]361     and $conf['allow_random_representative'])
362    or
[2324]363    (!$category['has_images']
[809]364     and !empty($category['representative_picture_id'])))
365  {
[2223]366    $tpl_representant['ALLOW_DELETE'] = true;
[809]367  }
[2223]368  $template->assign('representant', $tpl_representant);
[633]369}
370
[2223]371if ($category['is_virtual'])
[68]372{
[809]373  // the category can be moved in any category but in itself, in any
374  // sub-category
375  $unmovables = get_subcat_ids(array($category['id']));
[1131]376
[809]377  $query = '
378SELECT id,name,uppercats,global_rank
379  FROM '.CATEGORIES_TABLE.'
380  WHERE id NOT IN ('.implode(',', $unmovables).')
381;';
[1131]382
[809]383  display_select_cat_wrapper(
384    $query,
385    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
[2223]386    'move_cat_options'
[809]387    );
388}
389
[5933]390trigger_action('loc_end_cat_modify');
391
[21]392//----------------------------------------------------------- sending html code
[13013]393$template->assign_var_from_handle('ADMIN_CONTENT', 'album_properties');
[7024]394?>
Note: See TracBrowser for help on using the repository browser.