source: trunk/admin/cat_options.php @ 2223

Last change on this file since 2223 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: 9.5 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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: cat_options.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.'admin/include/functions_tabsheet.inc.php');
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40// +-----------------------------------------------------------------------+
41// |                       modification registration                       |
42// +-----------------------------------------------------------------------+
43
44// print '<pre>';
45// print_r($_POST);
46// print '</pre>';
47if (isset($_POST['falsify'])
48    and isset($_POST['cat_true'])
49    and count($_POST['cat_true']) > 0)
50{
51  switch ($_GET['section'])
52  {
53    case 'upload' :
54    {
55      $query = '
56UPDATE '.CATEGORIES_TABLE.'
57  SET uploadable = \'false\'
58  WHERE id IN ('.implode(',', $_POST['cat_true']).')
59;';
60      pwg_query($query);
61      break;
62    }
63    case 'comments' :
64    {
65      $query = '
66UPDATE '.CATEGORIES_TABLE.'
67  SET commentable = \'false\'
68  WHERE id IN ('.implode(',', $_POST['cat_true']).')
69;';
70      pwg_query($query);
71      break;
72    }
73    case 'visible' :
74    {
75      set_cat_visible($_POST['cat_true'], 'false');
76      break;
77    }
78    case 'status' :
79    {
80      set_cat_status($_POST['cat_true'], 'private');
81      break;
82    }
83    case 'representative' :
84    {
85      $query = '
86UPDATE '.CATEGORIES_TABLE.'
87  SET representative_picture_id = NULL
88  WHERE id IN ('.implode(',', $_POST['cat_true']).')
89;';
90      pwg_query($query);
91      break;
92    }
93  }
94}
95else if (isset($_POST['trueify'])
96         and isset($_POST['cat_false'])
97         and count($_POST['cat_false']) > 0)
98{
99  switch ($_GET['section'])
100  {
101    case 'upload' :
102    {
103      $query = '
104UPDATE '.CATEGORIES_TABLE.'
105  SET uploadable = \'true\'
106  WHERE id IN ('.implode(',', $_POST['cat_false']).')
107;';
108      pwg_query($query);
109      break;
110    }
111    case 'comments' :
112    {
113      $query = '
114UPDATE '.CATEGORIES_TABLE.'
115  SET commentable = \'true\'
116  WHERE id IN ('.implode(',', $_POST['cat_false']).')
117;';
118      pwg_query($query);
119      break;
120    }
121    case 'visible' :
122    {
123      set_cat_visible($_POST['cat_false'], 'true');
124      break;
125    }
126    case 'status' :
127    {
128      set_cat_status($_POST['cat_false'], 'public');
129      break;
130    }
131    case 'representative' :
132    {
133      // theoretically, all categories in $_POST['cat_false'] contain at
134      // least one element, so PhpWebGallery can find a representant.
135      set_random_representant($_POST['cat_false']);
136      break;
137    }
138  }
139}
140
141// +-----------------------------------------------------------------------+
142// |                             template init                             |
143// +-----------------------------------------------------------------------+
144
145$template->set_filenames(
146  array(
147    'cat_options' => 'admin/cat_options.tpl',
148    'double_select' => 'admin/double_select.tpl'
149    )
150  );
151
152$page['section'] = isset($_GET['section']) ? $_GET['section'] : 'status';
153$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
154
155$template->assign(
156  array(
157    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_options',
158    'F_ACTION'=>$base_url.$page['section']
159   )
160 );
161
162// TabSheet initialization
163$opt_link = $link_start.'cat_options&amp;section=';
164$tabsheet = array
165(
166  'status' => array
167   (
168    'caption' => l10n('cat_security'),
169    'url' => $opt_link.'status'
170   ),
171  'visible' => array
172   (
173    'caption' => l10n('lock'),
174    'url' => $opt_link.'visible'
175   ),
176  'upload' => array
177   (
178    'caption' => l10n('upload'),
179    'url' => $opt_link.'upload'
180   ),
181  'comments' => array
182   (
183    'caption' => l10n('comments'),
184    'url' => $opt_link.'comments'
185   ),
186);
187
188if ($conf['allow_random_representative'])
189{
190  $tabsheet['representative'] =
191    array
192    (
193      'caption' => l10n('Representative'),
194      'url' => $opt_link.'representative'
195    );
196}
197$tabsheet[$page['section']]['selected'] = true;
198
199// Assign tabsheet to template
200$template->assign(
201    array(
202      'tabsheet' => $tabsheet,
203      'TABSHEET_TITLE' => $tabsheet[$page['section']]['caption']
204    )
205  );
206
207// +-----------------------------------------------------------------------+
208// |                              form display                             |
209// +-----------------------------------------------------------------------+
210
211// for each section, categories in the multiselect field can be :
212//
213// - true : uploadable for upload section
214// - false : un-uploadable for upload section
215// - NA : (not applicable) for virtual categories
216//
217// for true and false status, we associates an array of category ids,
218// function display_select_categories will use the given CSS class for each
219// option
220$cats_true = array();
221$cats_false = array();
222switch ($page['section'])
223{
224  case 'upload' :
225  {
226    $query_true = '
227SELECT id,name,uppercats,global_rank
228  FROM '.CATEGORIES_TABLE.'
229  WHERE uploadable = \'true\'
230    AND dir IS NOT NULL
231    AND site_id = 1
232;';
233    $query_false = '
234SELECT id,name,uppercats,global_rank
235  FROM '.CATEGORIES_TABLE.'
236  WHERE uploadable = \'false\'
237    AND dir IS NOT NULL
238    AND site_id = 1
239;';
240    $template->assign(
241      array(
242        'L_SECTION' => l10n('cat_upload_title'),
243        'L_CAT_OPTIONS_TRUE' => l10n('authorized'),
244        'L_CAT_OPTIONS_FALSE' => l10n('forbidden'),
245        )
246      );
247    break;
248  }
249  case 'comments' :
250  {
251    $query_true = '
252SELECT id,name,uppercats,global_rank
253  FROM '.CATEGORIES_TABLE.'
254  WHERE commentable = \'true\'
255;';
256    $query_false = '
257SELECT id,name,uppercats,global_rank
258  FROM '.CATEGORIES_TABLE.'
259  WHERE commentable = \'false\'
260;';
261    $template->assign(
262      array(
263        'L_SECTION' => l10n('cat_comments_title'),
264        'L_CAT_OPTIONS_TRUE' => l10n('authorized'),
265        'L_CAT_OPTIONS_FALSE' => l10n('forbidden'),
266        )
267      );
268    break;
269  }
270  case 'visible' :
271  {
272    $query_true = '
273SELECT id,name,uppercats,global_rank
274  FROM '.CATEGORIES_TABLE.'
275  WHERE visible = \'true\'
276;';
277    $query_false = '
278SELECT id,name,uppercats,global_rank
279  FROM '.CATEGORIES_TABLE.'
280  WHERE visible = \'false\'
281;';
282    $template->assign(
283      array(
284        'L_SECTION' => l10n('cat_lock_title'),
285        'L_CAT_OPTIONS_TRUE' => l10n('unlocked'),
286        'L_CAT_OPTIONS_FALSE' => l10n('locked'),
287        )
288      );
289    break;
290  }
291  case 'status' :
292  {
293    $query_true = '
294SELECT id,name,uppercats,global_rank
295  FROM '.CATEGORIES_TABLE.'
296  WHERE status = \'public\'
297;';
298    $query_false = '
299SELECT id,name,uppercats,global_rank
300  FROM '.CATEGORIES_TABLE.'
301  WHERE status = \'private\'
302;';
303    $template->assign(
304      array(
305        'L_SECTION' => l10n('cat_status_title'),
306        'L_CAT_OPTIONS_TRUE' => l10n('cat_public'),
307        'L_CAT_OPTIONS_FALSE' => l10n('cat_private'),
308        )
309      );
310    break;
311  }
312  case 'representative' :
313  {
314    $query_true = '
315SELECT id,name,uppercats,global_rank
316  FROM '.CATEGORIES_TABLE.'
317  WHERE representative_picture_id IS NOT NULL
318;';
319    $query_false = '
320SELECT id,name,uppercats,global_rank
321  FROM '.CATEGORIES_TABLE.'
322  WHERE nb_images != 0
323    AND representative_picture_id IS NULL
324;';
325    $template->assign(
326      array(
327        'L_SECTION' => l10n('Representative'),
328        'L_CAT_OPTIONS_TRUE' => l10n('singly represented'),
329        'L_CAT_OPTIONS_FALSE' => l10n('randomly represented')
330        )
331      );
332    break;
333  }
334}
335display_select_cat_wrapper($query_true,array(),'category_option_true');
336display_select_cat_wrapper($query_false,array(),'category_option_false');
337
338// +-----------------------------------------------------------------------+
339// |                           sending html code                           |
340// +-----------------------------------------------------------------------+
341
342$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
343$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
344?>
Note: See TracBrowser for help on using the repository browser.