source: trunk/admin/cat_modify.php @ 635

Last change on this file since 635 was 635, checked in by plg, 19 years ago
  • on picture.php, related categories under the element are displayed in global_rank order
  • when adding a new virtual category, initializes its global_rank
  • bug fixed : in admin/cat_list, false next rank
  • in admin/cat_modify, complete directory is calculated only if category is not virtual
  • admin/picture_modify rewritten : graphically nearer to admin/cat_modify, virtual associations are back
  • update_category partially rewritten : take an array of categories in parameter, becomes optionnaly recursive, use the set_random_representant function, set a random representant for categories with elements and no representant
  • bug fixed : on a search results screen, elements belonging to more than 1 category were shown more than once
  • bug fixed : in admin/cat_modify, changing a value in a textefield and hitting enter was setting a new random representant
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-12-05 21:28:40 +0000 (Sun, 05 Dec 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 635 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28if (!defined('PHPWG_ROOT_PATH'))
29{
30  die('Hacking attempt!');
31}
32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33//---------------------------------------------------------------- verification
34if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) )
35{
36  $_GET['cat_id'] = '-1';
37}
38
39$template->set_filenames( array('categories'=>'admin/cat_modify.tpl') );
40
41//--------------------------------------------------------- form criteria check
42if ( isset( $_POST['submit'] ) )
43{
44  $query = 'SELECT status';
45  $query.= ' FROM '.CATEGORIES_TABLE;
46  $query.= ' WHERE id = '.$_GET['cat_id'];
47  $query.= ';';
48  $row = mysql_fetch_array( pwg_query( $query ) );
49 
50  $query = 'UPDATE '.CATEGORIES_TABLE;
51  $query.= ' SET name = ';
52  if ( empty($_POST['name']))
53    $query.= 'NULL';
54  else
55    $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES)."'";
56
57  $query.= ', comment = ';
58  if ( empty($_POST['comment']))
59    $query.= 'NULL';
60  else
61    $query.= "'".htmlentities( $_POST['comment'], ENT_QUOTES )."'";
62
63  if ( isset( $_POST['uploadable'] ) )
64    $query.= ", uploadable = '".$_POST['uploadable']."'";
65
66  if ( isset( $_POST['associate'] ) )
67  {
68    $query.= ', id_uppercat = ';
69    if ( $_POST['associate'] == -1 or $_POST['associate'] == '' )
70      $query.= 'NULL';
71    else
72      $query.= $_POST['associate'];
73  }
74  $query.= ' WHERE id = '.$_GET['cat_id'];
75  $query.= ';';
76  pwg_query( $query );
77
78  set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
79  set_cat_status(array($_GET['cat_id']), $_POST['status']);
80
81  $template->assign_block_vars('confirmation' ,array());
82}
83else if (isset($_POST['set_random_representant']))
84{
85  set_random_representant(array($_GET['cat_id']));
86}
87
88$query = '
89SELECT *
90  FROM '.CATEGORIES_TABLE.'
91  WHERE id = '.$_GET['cat_id'].'
92;';
93$category = mysql_fetch_array( pwg_query( $query ) );
94// nullable fields
95foreach (array('comment','dir','site_id') as $nullable)
96{
97  if (!isset($category[$nullable]))
98  {
99    $category[$nullable] = '';
100  }
101}
102
103// Navigation path
104$url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&amp;parent_id=';
105$navigation = '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.'admin.php?page=cat_list').'">';
106$navigation.= $lang['home'].'</a> <span style="font-size:15px">&rarr;</span>';
107
108$navigation.= get_cat_display_name_cache(
109  $category['uppercats'],
110  ' <span style="font-size:15px">&rarr;</span>',
111  $url);
112
113$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$_GET['cat_id'];
114$status = ($category['status']=='public')?'STATUS_PUBLIC':'STATUS_PRIVATE'; 
115$lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED';
116
117if ($category['commentable'] == 'true')
118{
119  $commentable = 'COMMENTABLE_TRUE';
120}
121else
122{
123  $commentable = 'COMMENTABLE_FALSE';
124}
125if ($category['uploadable'] == 'true')
126{
127  $uploadable = 'UPLOADABLE_TRUE';
128}
129else
130{
131  $uploadable = 'UPLOADABLE_FALSE';
132}
133
134//----------------------------------------------------- template initialization
135$template->assign_vars(array( 
136  'CATEGORIES_NAV'=>$navigation,
137  'CAT_NAME'=>$category['name'],
138  'CAT_COMMENT'=>$category['comment'],
139 
140  $status=>'checked="checked"',
141  $lock=>'checked="checked"',
142  $commentable=>'checked="checked"',
143  $uploadable=>'checked="checked"',
144 
145  'L_EDIT_CONFIRM'=>$lang['editcat_confirm'],
146  'L_EDIT_NAME'=>$lang['description'],
147  'L_STORAGE'=>$lang['storage'],
148  'L_REMOTE_SITE'=>$lang['remote_site'],
149  'L_EDIT_COMMENT'=>$lang['comment'],
150  'L_EDIT_STATUS'=>$lang['conf_access'],
151  'L_EDIT_STATUS_INFO'=>$lang['cat_access_info'],
152  'L_STATUS_PUBLIC'=>$lang['public'],
153  'L_STATUS_PRIVATE'=>$lang['private'],
154  'L_EDIT_LOCK'=>$lang['lock'],
155  'L_EDIT_LOCK_INFO'=>$lang['editcat_visible_info'],
156  'L_EDIT_UPLOADABLE'=>$lang['editcat_uploadable'],
157  'L_EDIT_UPLOADABLE_INFO'=>$lang['editcat_uploadable_info'],
158  'L_EDIT_COMMENTABLE'=>$lang['editcat_commentable'],
159  'L_EDIT_COMMENTABLE_INFO'=>$lang['editcat_commentable_info'],
160  'L_YES'=>$lang['yes'],
161  'L_NO'=>$lang['no'],
162  'L_SUBMIT'=>$lang['submit'],
163  'L_SET_RANDOM_REPRESENTANT'=>$lang['set_random_representant'],
164   
165  'F_ACTION'=>add_session_id($form_action)
166  ));
167
168if ($category['nb_images'] > 0)
169{
170  $query = '
171SELECT tn_ext,path
172  FROM '.IMAGES_TABLE.'
173  WHERE id = '.$category['representative_picture_id'].'
174;';
175  $row = mysql_fetch_array(pwg_query($query));
176  $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
177  $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
178  $url.= '&amp;image_id='.$category['representative_picture_id'];
179  $template->assign_block_vars('representant',
180                               array('SRC' => $src,
181                                     'URL' => $url));
182}
183
184if (!empty($category['dir']))
185{
186  $template->assign_block_vars(
187    'storage',
188    array('CATEGORY_DIR'=>preg_replace('/\/$/',
189                                       '',
190                                       get_complete_dir($category['id']))));
191  $template->assign_block_vars('upload' ,array());
192}
193
194if (is_numeric($category['site_id']) and $category['site_id'] != 1)
195{
196  $query = '
197SELECT galleries_url
198  FROM '.SITES_TABLE.'
199  WHERE id = '.$category['site_id'].'
200;';
201  list($galleries_url) = mysql_fetch_array(pwg_query($query));
202  $template->assign_block_vars('server', array('SITE_URL' => $galleries_url));
203}
204
205//----------------------------------------------------------- sending html code
206$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
207?>
Note: See TracBrowser for help on using the repository browser.