source: trunk/admin/cat_modify.php @ 8727

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

feature 2102: add a few language keys to remove all image/picture/element and replace by photo

  • Property svn:eol-style set to LF
File size: 14.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 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  $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
67  $data =
68    array(
69      'id' => $_GET['cat_id'],
70      'name' => @$_POST['name'],
71      'commentable' => isset($_POST['commentable'])?$_POST['commentable']:'false',
72      'comment' =>
73        $conf['allow_html_descriptions'] ?
74          @$_POST['comment'] : strip_tags(@$_POST['comment']),
75      'image_order' => $image_order,
76      );
77
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    );
86
87  // retrieve cat infos before continuing (following updates are expensive)
88  $cat_info = get_cat_info($_GET['cat_id']);
89
90  if (isset($_POST['image_order_subcats']))
91  {
92    $query = '
93UPDATE '.CATEGORIES_TABLE.' SET image_order='.(isset($image_order) ? 'NULL':'\''.$image_order.'\'').'
94  WHERE uppercats LIKE \''.$cat_info['uppercats'].',%\'';
95    pwg_query($query);
96  }
97
98  if ($cat_info['visible'] != get_boolean( $_POST['visible'] ) )
99  {
100    set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
101  }
102  if ($cat_info['status'] != $_POST['status'] )
103  {
104    set_cat_status(array($_GET['cat_id']), $_POST['status']);
105  }
106
107  if (isset($_POST['parent']) and $cat_info['id_uppercat'] != $_POST['parent'])
108  {
109    move_categories( array($_GET['cat_id']), $_POST['parent'] );
110  }
111
112  array_push($page['infos'], l10n('Album updated successfully'));
113}
114elseif (isset($_POST['set_random_representant']))
115{
116  set_random_representant(array($_GET['cat_id']));
117}
118elseif (isset($_POST['delete_representant']))
119{
120  $query = '
121UPDATE '.CATEGORIES_TABLE.'
122  SET representative_picture_id = NULL
123  WHERE id = '.$_GET['cat_id'].'
124;';
125  pwg_query($query);
126}
127elseif (isset($_POST['submitAdd']))
128{
129  $output_create = create_virtual_category(
130    $_POST['virtual_name'],
131    (0 == $_POST['parent'] ? null : $_POST['parent'])
132    );
133
134  if (isset($output_create['error']))
135  {
136    array_push($page['errors'], $output_create['error']);
137  }
138  else
139  {
140    // Virtual album creation succeeded
141    //
142    // Add the information in the information list
143    array_push($page['infos'], $output_create['info']);
144
145    // Link the new category to the current category
146    associate_categories_to_categories(
147      array($_GET['cat_id']),
148      array($output_create['id'])
149      );
150
151    // information
152    array_push(
153      $page['infos'],
154      sprintf(
155        l10n('Album photos associated to the following albums: %s'),
156        '<ul><li>'
157        .get_cat_display_name_from_id($output_create['id'])
158        .'</li></ul>'
159        )
160      );
161  }
162}
163elseif (isset($_POST['submitDestinations'])
164         and isset($_POST['destinations'])
165         and count($_POST['destinations']) > 0)
166{
167  associate_categories_to_categories(
168    array($_GET['cat_id']),
169    $_POST['destinations']
170    );
171
172  $category_names = array();
173  foreach ($_POST['destinations'] as $category_id)
174  {
175    array_push(
176      $category_names,
177      get_cat_display_name_from_id($category_id)
178      );
179  }
180
181  array_push(
182    $page['infos'],
183    sprintf(
184      l10n('Album photos associated to the following albums: %s'),
185      '<ul><li>'.implode('</li><li>', $category_names).'</li></ul>'
186      )
187    );
188}
189
190$query = '
191SELECT *
192  FROM '.CATEGORIES_TABLE.'
193  WHERE id = '.$_GET['cat_id'].'
194;';
195$category = pwg_db_fetch_assoc( pwg_query( $query ) );
196// nullable fields
197foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
198{
199  if (!isset($category[$nullable]))
200  {
201    $category[$nullable] = '';
202  }
203}
204
205$category['is_virtual'] = empty($category['dir']) ? true : false;
206
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);
212$category['has_images'] = pwg_db_num_rows($result)>0 ? true : false;
213
214// Navigation path
215$navigation = get_cat_display_name_cache(
216  $category['uppercats'],
217  get_root_url().'admin.php?page=cat_modify&amp;cat_id='
218  );
219
220$form_action = get_root_url().'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
221
222//----------------------------------------------------- template initialization
223$template->set_filename( 'categories', 'cat_modify.tpl');
224
225$base_url = get_root_url().'admin.php?page=';
226$cat_list_url = $base_url.'cat_list';
227
228$self_url = $cat_list_url;
229if (!empty($category['id_uppercat']))
230{
231  $self_url.= '&amp;parent_id='.$category['id_uppercat'];
232}
233
234$template->assign(
235  array(
236    'CATEGORIES_NAV'     => $navigation,
237    'CAT_ID'             => $category['id'],
238    'CAT_NAME'           => @htmlspecialchars($category['name']),
239    'CAT_COMMENT'        => @htmlspecialchars($category['comment']),
240
241    'status_values'     => array('public','private'),
242
243    'CAT_STATUS'        => $category['status'],
244    'CAT_VISIBLE'       => boolean_to_string($category['visible']),
245    'CAT_COMMENTABLE'   => boolean_to_string($category['commentable']),
246
247    'IMG_ORDER_DEFAULT'  => empty($category['image_order']) ?
248                              'checked="checked"' : '',
249
250    'U_JUMPTO' => make_index_url(
251      array(
252        'category' => $category
253        )
254      ),
255
256    'MAIL_CONTENT' => empty($_POST['mail_content'])
257        ? '' : stripslashes($_POST['mail_content']),
258    'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
259    'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_modify',
260
261    'F_ACTION' => $form_action,
262    )
263  );
264
265
266if ('private' == $category['status'])
267{
268  $template->assign( 'U_MANAGE_PERMISSIONS',
269      $base_url.'cat_perm&amp;cat='.$category['id']
270    );
271}
272
273// manage album elements link
274if ($category['has_images'])
275{
276  $template->assign(
277    'U_MANAGE_ELEMENTS',
278    $base_url.'batch_manager&amp;cat='.$category['id']
279    );
280  $template->assign(
281    'U_MANAGE_RANKS',
282    $base_url.'element_set_ranks&amp;cat_id='.$category['id']
283    );
284}
285
286if ($category['is_virtual'])
287{
288  $template->assign(
289    array(
290      'U_DELETE' => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
291      )
292    );
293}
294else
295{
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    );
304}
305
306// image order management
307
308$sort_fields = array(
309  '' => '',
310  'date_creation' => l10n('Creation date'),
311  'date_available' => l10n('Post date'),
312  'average_rate' => l10n('Average rate'),
313  'hit' => l10n('Most visited'),
314  'file' => l10n('File name'),
315  'id' => 'Id',
316  'rank' => l10n('Rank'),
317  );
318
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
334for ($i=0; $i<3; $i++) // 3 fields
335{
336  $tpl_image_order_select = array(
337      'ID' => $i+1,
338      'FIELD' => array(''),
339      'DIRECTION' => array('ASC'),
340    );
341
342  if ( isset($matches[1][$i]) )
343  {
344    $tpl_image_order_select['FIELD'] = array($matches[1][$i]);
345  }
346
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);
352}
353
354
355// representant management
356if ($category['has_images']
357    or !empty($category['representative_picture_id']))
358{
359  $tpl_representant = array();
360
361  // picture to display : the identified representant or the generic random
362  // representant ?
363  if (!empty($category['representative_picture_id']))
364  {
365    $query = '
366SELECT id,tn_ext,path
367  FROM '.IMAGES_TABLE.'
368  WHERE id = '.$category['representative_picture_id'].'
369;';
370    $row = pwg_db_fetch_assoc(pwg_query($query));
371    $src = get_thumbnail_url($row);
372    $url = get_root_url().'admin.php?page=picture_modify';
373    $url.= '&amp;image_id='.$category['representative_picture_id'];
374
375    $tpl_representant['picture'] =
376      array(
377        'SRC' => $src,
378        'URL' => $url
379      );
380  }
381
382  // can the admin choose to set a new random representant ?
383  $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false;
384
385  // can the admin delete the current representant ?
386  if (
387    ($category['has_images']
388     and $conf['allow_random_representative'])
389    or
390    (!$category['has_images']
391     and !empty($category['representative_picture_id'])))
392  {
393    $tpl_representant['ALLOW_DELETE'] = true;
394  }
395  $template->assign('representant', $tpl_representant);
396}
397
398if ($category['is_virtual'])
399{
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']));
403
404  $query = '
405SELECT id,name,uppercats,global_rank
406  FROM '.CATEGORIES_TABLE.'
407  WHERE id NOT IN ('.implode(',', $unmovables).')
408;';
409
410  display_select_cat_wrapper(
411    $query,
412    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
413    'move_cat_options'
414    );
415}
416
417
418// create virtual in parent and link
419$query = '
420SELECT id,name,uppercats,global_rank
421  FROM '.CATEGORIES_TABLE.'
422;';
423display_select_cat_wrapper(
424  $query,
425  array(),
426  'create_new_parent_options'
427  );
428
429
430// destination categories
431$query = '
432SELECT id,name,uppercats,global_rank
433  FROM '.CATEGORIES_TABLE.'
434  WHERE id != '.$category['id'].'
435;';
436display_select_cat_wrapper(
437  $query,
438  array(),
439  'category_destination_options'
440  );
441
442// info by email to an access granted group of category informations
443if (isset($_POST['submitEmail']) and !empty($_POST['group']))
444{
445  set_make_full_url();
446
447  /* TODO: if $category['representative_picture_id']
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'].'
455;';
456
457    $result = pwg_query($query);
458    if (pwg_db_num_rows($result) > 0)
459    {
460      $element = pwg_db_fetch_assoc($result);
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                        ))
468                      .'" class="thumblnk"><img src="'.get_thumbnail_url($element).'"></a>';
469    }
470  }
471
472  if (!isset($img_url))
473  {
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*/
481    get_l10n_args('[%s] Visit album %s',
482      array($conf['gallery_title'], $category['name'])),
483    'cat_group_info',
484    array
485    (
486      'IMG_URL' => $img_url,
487      'CAT_NAME' => $category['name'],
488      'LINK' => make_index_url(
489          array(
490            'category' => array(
491              'id' => $category['id'],
492              'name' => $category['name'],
493              'permalink' => $category['permalink']
494              ))),
495      'CPL_CONTENT' => empty($_POST['mail_content'])
496                          ? '' : stripslashes($_POST['mail_content'])
497    ),
498    '' /* TODO Add listbox in order to choose Language selected */);
499
500  unset_make_full_url();
501
502  $query = '
503SELECT
504    name
505  FROM '.GROUPS_TABLE.'
506  WHERE id = '.$_POST['group'].'
507;';
508  list($group_name) = pwg_db_fetch_row(pwg_query($query));
509
510  array_push(
511    $page['infos'],
512    sprintf(
513      l10n('An information email was sent to group "%s"'),
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;';
548  $template->assign('group_mail_options',
549      simple_hash_from_query($query, 'id', 'name')
550    );
551}
552
553trigger_action('loc_end_cat_modify');
554
555//----------------------------------------------------------- sending html code
556$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
557?>
Note: See TracBrowser for help on using the repository browser.