source: trunk/admin/cat_modify.php @ 3282

Last change on this file since 3282 was 3282, checked in by plg, 15 years ago

change: according to topic:15067, svn:keywords property was removed

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