source: trunk/admin/cat_modify.php @ 2250

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