source: trunk/admin/cat_options.php @ 627

Last change on this file since 627 was 627, checked in by plg, 19 years ago

no PHP error if form submitted while no category selected

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 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-11-30 20:36:20 +0000 (Tue, 30 Nov 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 627 $
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// +-----------------------------------------------------------------------+
34// |                       modification registration                       |
35// +-----------------------------------------------------------------------+
36// print '<pre>';
37// print_r($_POST);
38// print '</pre>';
39if (isset($_POST['falsify'])
40    and isset($_POST['cat_true'])
41    and count($_POST['cat_true']) > 0)
42{
43  switch ($_GET['section'])
44  {
45    case 'upload' :
46    {
47      $query = '
48UPDATE '.CATEGORIES_TABLE.'
49  SET uploadable = \'false\'
50  WHERE id IN ('.implode(',', $_POST['cat_true']).')
51;';
52      pwg_query($query);
53      break;
54    }
55    case 'comments' :
56    {
57      $query = '
58UPDATE '.CATEGORIES_TABLE.'
59  SET commentable = \'false\'
60  WHERE id IN ('.implode(',', $_POST['cat_true']).')
61;';
62      pwg_query($query);
63      break;
64    }
65    case 'visible' :
66    {
67      // locking a category   => all its child categories become locked
68      $subcats = get_subcat_ids($_POST['cat_true']);
69      $query = '
70UPDATE '.CATEGORIES_TABLE.'
71  SET visible = \'false\'
72  WHERE id IN ('.implode(',', $subcats).')
73;';
74      pwg_query($query);
75      break;
76    }
77    case 'status' :
78    {
79      // make a category private => all its child categories become private
80      $subcats = get_subcat_ids($_POST['cat_true']);
81      $query = '
82UPDATE '.CATEGORIES_TABLE.'
83  SET status = \'private\'
84  WHERE id IN ('.implode(',', $subcats).')
85;';
86      pwg_query($query);
87      break;
88    }
89  }
90}
91else if (isset($_POST['trueify'])
92         and isset($_POST['cat_false'])
93         and count($_POST['cat_false']) > 0)
94{
95  switch ($_GET['section'])
96  {
97    case 'upload' :
98    {
99      $query = '
100UPDATE '.CATEGORIES_TABLE.'
101  SET uploadable = \'true\'
102  WHERE id IN ('.implode(',', $_POST['cat_false']).')
103;';
104      pwg_query($query);
105      break;
106    }
107    case 'comments' :
108    {
109      $query = '
110UPDATE '.CATEGORIES_TABLE.'
111  SET commentable = \'true\'
112  WHERE id IN ('.implode(',', $_POST['cat_false']).')
113;';
114      pwg_query($query);
115      break;
116    }
117    case 'visible' :
118    {
119      // unlocking a category => all its parent categories become unlocked
120      $uppercats = array();
121      $query = '
122SELECT uppercats
123  FROM '.CATEGORIES_TABLE.'
124  WHERE id IN ('.implode(',', $_POST['cat_false']).')
125;';
126      $result = pwg_query($query);
127      while ($row = mysql_fetch_array($result))
128      {
129        $uppercats = array_merge($uppercats,
130                                 explode(',', $row['uppercats']));
131      }
132      $uppercats = array_unique($uppercats);
133     
134      $query = '
135UPDATE '.CATEGORIES_TABLE.'
136  SET visible = \'true\'
137  WHERE id IN ('.implode(',', $uppercats).')
138;';
139      pwg_query($query);
140      break;
141    }
142    case 'status' :
143    {
144      // make public a category => all its parent categories become public
145      $uppercats = array();
146      $query = '
147SELECT uppercats
148  FROM '.CATEGORIES_TABLE.'
149  WHERE id IN ('.implode(',', $_POST['cat_false']).')
150;';
151      $result = pwg_query($query);
152      while ($row = mysql_fetch_array($result))
153      {
154        $uppercats = array_merge($uppercats,
155                                 explode(',', $row['uppercats']));
156      }
157      $uppercats = array_unique($uppercats);
158     
159      $query = '
160UPDATE '.CATEGORIES_TABLE.'
161  SET status = \'public\'
162  WHERE id IN ('.implode(',', $uppercats).')
163;';
164      pwg_query($query);
165      break;
166    }
167  }
168}
169// +-----------------------------------------------------------------------+
170// |                             template init                             |
171// +-----------------------------------------------------------------------+
172$template->set_filenames(array('cat_options'=>'admin/cat_options.tpl'));
173
174if (!isset($_GET['section']))
175{
176  $page['section'] = 'upload';
177}
178else
179{
180  $page['section'] = $_GET['section'];
181}
182
183$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
184$template->assign_vars(
185  array(
186    'L_SUBMIT'=>$lang['submit'],
187    'L_RESET'=>$lang['reset'],
188   
189    'F_ACTION'=>add_session_id($base_url.$page['section'])
190   )
191 );
192
193$template->assign_vars(array(strtoupper($page['section']).'_CLASS'=>'opened'));
194// +-----------------------------------------------------------------------+
195// |                              form display                             |
196// +-----------------------------------------------------------------------+
197
198// for each section, categories in the multiselect field can be :
199//
200// - true : uploadable for upload section
201// - false : un-uploadable for upload section
202// - NA : (not applicable) for virtual categories
203//
204// for true and false status, we associates an array of category ids,
205// function display_select_categories will use the given CSS class for each
206// option
207$cats_true = array();
208$cats_false = array();
209switch ($page['section'])
210{
211  case 'upload' :
212  {
213    $query_true = '
214SELECT id,name,uppercats,global_rank
215  FROM '.CATEGORIES_TABLE.'
216  WHERE uploadable = \'true\'
217    AND dir IS NOT NULL
218    AND site_id = 1
219;';
220    $query_false = '
221SELECT id,name,uppercats,global_rank
222  FROM '.CATEGORIES_TABLE.'
223  WHERE uploadable = \'false\'
224    AND dir IS NOT NULL
225    AND site_id = 1
226;';
227    $template->assign_vars(
228      array(
229        'L_CAT_TITLE' => $lang['cat_upload_title'],
230        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
231        'L_CAT_OPTIONS_FALSE' => $lang['forbidden'],
232        'L_CAT_OPTIONS_INFO' => $lang['cat_upload_info'],
233        )
234      );
235    $template->assign_block_vars('upload', array());
236    break;
237  }
238  case 'comments' :
239  {
240    $query_true = '
241SELECT id,name,uppercats,global_rank
242  FROM '.CATEGORIES_TABLE.'
243  WHERE commentable = \'true\'
244;';
245    $query_false = '
246SELECT id,name,uppercats,global_rank
247  FROM '.CATEGORIES_TABLE.'
248  WHERE commentable = \'false\'
249;';
250    $template->assign_vars(
251      array(
252        'L_CAT_TITLE' => $lang['cat_comments_title'],
253        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
254        'L_CAT_OPTIONS_FALSE' => $lang['forbidden'],
255        'L_CAT_OPTIONS_INFO' => $lang['cat_comments_info'],
256        )
257      );
258    $template->assign_block_vars('comments', array());
259    break;
260  }
261  case 'visible' :
262  {
263    $query_true = '
264SELECT id,name,uppercats,global_rank
265  FROM '.CATEGORIES_TABLE.'
266  WHERE visible = \'true\'
267;';
268    $query_false = '
269SELECT id,name,uppercats,global_rank
270  FROM '.CATEGORIES_TABLE.'
271  WHERE visible = \'false\'
272;';
273    $template->assign_vars(
274      array(
275        'L_CAT_TITLE' => $lang['cat_lock_title'],
276        'L_CAT_OPTIONS_TRUE' => $lang['lock'],
277        'L_CAT_OPTIONS_FALSE' => $lang['unlock'],
278        'L_CAT_OPTIONS_INFO' => $lang['cat_lock_info'],
279        )
280      );
281    $template->assign_block_vars('visible', array());
282    break;
283  }
284  case 'status' :
285  {
286    $query_true = '
287SELECT id,name,uppercats,global_rank
288  FROM '.CATEGORIES_TABLE.'
289  WHERE status = \'public\'
290;';
291    $query_false = '
292SELECT id,name,uppercats,global_rank
293  FROM '.CATEGORIES_TABLE.'
294  WHERE status = \'private\'
295;';
296    $template->assign_vars(
297      array(
298        'L_CAT_TITLE' => $lang['cat_status_title'],
299        'L_CAT_OPTIONS_TRUE' => $lang['cat_public'],
300        'L_CAT_OPTIONS_FALSE' => $lang['cat_private'],
301        'L_CAT_OPTIONS_INFO' => $lang['cat_status_info'],
302        )
303      );
304    $template->assign_block_vars('status', array());
305    break;
306  }
307}
308display_select_cat_wrapper($query_true,array(),'category_option_true');
309display_select_cat_wrapper($query_false,array(),'category_option_false');
310// +-----------------------------------------------------------------------+
311// |                           sending html code                           |
312// +-----------------------------------------------------------------------+
313$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
314?>
Note: See TracBrowser for help on using the repository browser.