source: trunk/admin/cat_options.php @ 1038

Last change on this file since 1038 was 1004, checked in by nikrou, 19 years ago

Improve security of sessions:

  • use only cookies to store session id on client side
  • use default php session system with database handler to store sessions on server side
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-01-15 13:45:42 +0000 (Sun, 15 Jan 2006) $
10// | last modifier : $Author: nikrou $
11// | revision      : $Revision: 1004 $
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// +-----------------------------------------------------------------------+
35// |                       modification registration                       |
36// +-----------------------------------------------------------------------+
37
38// print '<pre>';
39// print_r($_POST);
40// print '</pre>';
41if (isset($_POST['falsify'])
42    and isset($_POST['cat_true'])
43    and count($_POST['cat_true']) > 0)
44{
45  switch ($_GET['section'])
46  {
47    case 'upload' :
48    {
49      $query = '
50UPDATE '.CATEGORIES_TABLE.'
51  SET uploadable = \'false\'
52  WHERE id IN ('.implode(',', $_POST['cat_true']).')
53;';
54      pwg_query($query);
55      break;
56    }
57    case 'comments' :
58    {
59      $query = '
60UPDATE '.CATEGORIES_TABLE.'
61  SET commentable = \'false\'
62  WHERE id IN ('.implode(',', $_POST['cat_true']).')
63;';
64      pwg_query($query);
65      break;
66    }
67    case 'visible' :
68    {
69      set_cat_visible($_POST['cat_true'], 'false');
70      break;
71    }
72    case 'status' :
73    {
74      set_cat_status($_POST['cat_true'], 'private');
75      break;
76    }
77    case 'representative' :
78    {
79      $query = '
80UPDATE '.CATEGORIES_TABLE.'
81  SET representative_picture_id = NULL
82  WHERE id IN ('.implode(',', $_POST['cat_true']).')
83;';
84      pwg_query($query);
85      break;
86    }
87  }
88}
89else if (isset($_POST['trueify'])
90         and isset($_POST['cat_false'])
91         and count($_POST['cat_false']) > 0)
92{
93  switch ($_GET['section'])
94  {
95    case 'upload' :
96    {
97      $query = '
98UPDATE '.CATEGORIES_TABLE.'
99  SET uploadable = \'true\'
100  WHERE id IN ('.implode(',', $_POST['cat_false']).')
101;';
102      pwg_query($query);
103      break;
104    }
105    case 'comments' :
106    {
107      $query = '
108UPDATE '.CATEGORIES_TABLE.'
109  SET commentable = \'true\'
110  WHERE id IN ('.implode(',', $_POST['cat_false']).')
111;';
112      pwg_query($query);
113      break;
114    }
115    case 'visible' :
116    {
117      set_cat_visible($_POST['cat_false'], 'true');
118      break;
119    }
120    case 'status' :
121    {
122      set_cat_status($_POST['cat_false'], 'public');
123      break;
124    }
125    case 'representative' :
126    {
127      // theoretically, all categories in $_POST['cat_false'] contain at
128      // least one element, so PhpWebGallery can find a representant.
129      set_random_representant($_POST['cat_false']);
130      break;
131    }
132  }
133}
134
135// +-----------------------------------------------------------------------+
136// |                             template init                             |
137// +-----------------------------------------------------------------------+
138
139$template->set_filenames(
140  array(
141    'cat_options' => 'admin/cat_options.tpl',
142    'double_select' => 'admin/double_select.tpl'
143    )
144  );
145
146$page['section'] = isset($_GET['section']) ? $_GET['section'] : 'upload';
147$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
148
149$template->assign_vars(
150  array(
151    'L_SUBMIT'=>$lang['submit'],
152    'L_RESET'=>$lang['reset'],
153
154    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_options',
155   
156    'F_ACTION'=>$base_url.$page['section']
157   )
158 );
159
160// +-----------------------------------------------------------------------+
161// |                              form display                             |
162// +-----------------------------------------------------------------------+
163
164// for each section, categories in the multiselect field can be :
165//
166// - true : uploadable for upload section
167// - false : un-uploadable for upload section
168// - NA : (not applicable) for virtual categories
169//
170// for true and false status, we associates an array of category ids,
171// function display_select_categories will use the given CSS class for each
172// option
173$cats_true = array();
174$cats_false = array();
175switch ($page['section'])
176{
177  case 'upload' :
178  {
179    $query_true = '
180SELECT id,name,uppercats,global_rank
181  FROM '.CATEGORIES_TABLE.'
182  WHERE uploadable = \'true\'
183    AND dir IS NOT NULL
184    AND site_id = 1
185;';
186    $query_false = '
187SELECT id,name,uppercats,global_rank
188  FROM '.CATEGORIES_TABLE.'
189  WHERE uploadable = \'false\'
190    AND dir IS NOT NULL
191    AND site_id = 1
192;';
193    $template->assign_vars(
194      array(
195        'L_SECTION' => $lang['cat_upload_title'],
196        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
197        'L_CAT_OPTIONS_FALSE' => $lang['forbidden'],
198        )
199      );
200    break;
201  }
202  case 'comments' :
203  {
204    $query_true = '
205SELECT id,name,uppercats,global_rank
206  FROM '.CATEGORIES_TABLE.'
207  WHERE commentable = \'true\'
208;';
209    $query_false = '
210SELECT id,name,uppercats,global_rank
211  FROM '.CATEGORIES_TABLE.'
212  WHERE commentable = \'false\'
213;';
214    $template->assign_vars(
215      array(
216        'L_SECTION' => $lang['cat_comments_title'],
217        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
218        'L_CAT_OPTIONS_FALSE' => $lang['forbidden'],
219        )
220      );
221    break;
222  }
223  case 'visible' :
224  {
225    $query_true = '
226SELECT id,name,uppercats,global_rank
227  FROM '.CATEGORIES_TABLE.'
228  WHERE visible = \'true\'
229;';
230    $query_false = '
231SELECT id,name,uppercats,global_rank
232  FROM '.CATEGORIES_TABLE.'
233  WHERE visible = \'false\'
234;';
235    $template->assign_vars(
236      array(
237        'L_SECTION' => $lang['cat_lock_title'],
238        'L_CAT_OPTIONS_TRUE' => $lang['unlocked'],
239        'L_CAT_OPTIONS_FALSE' => $lang['locked'],
240        )
241      );
242    break;
243  }
244  case 'status' :
245  {
246    $query_true = '
247SELECT id,name,uppercats,global_rank
248  FROM '.CATEGORIES_TABLE.'
249  WHERE status = \'public\'
250;';
251    $query_false = '
252SELECT id,name,uppercats,global_rank
253  FROM '.CATEGORIES_TABLE.'
254  WHERE status = \'private\'
255;';
256    $template->assign_vars(
257      array(
258        'L_SECTION' => $lang['cat_status_title'],
259        'L_CAT_OPTIONS_TRUE' => $lang['cat_public'],
260        'L_CAT_OPTIONS_FALSE' => $lang['cat_private'],
261        )
262      );
263    break;
264  }
265  case 'representative' :
266  {
267    $query_true = '
268SELECT id,name,uppercats,global_rank
269  FROM '.CATEGORIES_TABLE.'
270  WHERE representative_picture_id IS NOT NULL
271;';
272    $query_false = '
273SELECT id,name,uppercats,global_rank
274  FROM '.CATEGORIES_TABLE.'
275  WHERE nb_images != 0
276    AND representative_picture_id IS NULL
277;';
278    $template->assign_vars(
279      array(
280        'L_SECTION' => l10n('Representative'),
281        'L_CAT_OPTIONS_TRUE' => l10n('singly represented'),
282        'L_CAT_OPTIONS_FALSE' => l10n('randomly represented')
283        )
284      );
285    break;
286  }
287}
288display_select_cat_wrapper($query_true,array(),'category_option_true');
289display_select_cat_wrapper($query_false,array(),'category_option_false');
290
291// +-----------------------------------------------------------------------+
292// |                           sending html code                           |
293// +-----------------------------------------------------------------------+
294
295$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
296$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
297?>
Note: See TracBrowser for help on using the repository browser.