source: trunk/admin/cat_options.php @ 1878

Last change on this file since 1878 was 1878, checked in by rub, 17 years ago

Add tabsheet on administration pages.

Step 2: Regroup categories options into sheet Batch management.

On next commit, use of this new method on history and configuration

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-03-07 22:53:42 +0000 (Wed, 07 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1878 $
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}
32
33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34include_once(PHPWG_ROOT_PATH.'admin/include/functions_tabsheet.inc.php');
35
36// +-----------------------------------------------------------------------+
37// | Check Access and exit when user status is not ok                      |
38// +-----------------------------------------------------------------------+
39check_status(ACCESS_ADMINISTRATOR);
40
41// +-----------------------------------------------------------------------+
42// |                       modification registration                       |
43// +-----------------------------------------------------------------------+
44
45// print '<pre>';
46// print_r($_POST);
47// print '</pre>';
48if (isset($_POST['falsify'])
49    and isset($_POST['cat_true'])
50    and count($_POST['cat_true']) > 0)
51{
52  switch ($_GET['section'])
53  {
54    case 'upload' :
55    {
56      $query = '
57UPDATE '.CATEGORIES_TABLE.'
58  SET uploadable = \'false\'
59  WHERE id IN ('.implode(',', $_POST['cat_true']).')
60;';
61      pwg_query($query);
62      break;
63    }
64    case 'comments' :
65    {
66      $query = '
67UPDATE '.CATEGORIES_TABLE.'
68  SET commentable = \'false\'
69  WHERE id IN ('.implode(',', $_POST['cat_true']).')
70;';
71      pwg_query($query);
72      break;
73    }
74    case 'visible' :
75    {
76      set_cat_visible($_POST['cat_true'], 'false');
77      break;
78    }
79    case 'status' :
80    {
81      set_cat_status($_POST['cat_true'], 'private');
82      break;
83    }
84    case 'representative' :
85    {
86      $query = '
87UPDATE '.CATEGORIES_TABLE.'
88  SET representative_picture_id = NULL
89  WHERE id IN ('.implode(',', $_POST['cat_true']).')
90;';
91      pwg_query($query);
92      break;
93    }
94  }
95}
96else if (isset($_POST['trueify'])
97         and isset($_POST['cat_false'])
98         and count($_POST['cat_false']) > 0)
99{
100  switch ($_GET['section'])
101  {
102    case 'upload' :
103    {
104      $query = '
105UPDATE '.CATEGORIES_TABLE.'
106  SET uploadable = \'true\'
107  WHERE id IN ('.implode(',', $_POST['cat_false']).')
108;';
109      pwg_query($query);
110      break;
111    }
112    case 'comments' :
113    {
114      $query = '
115UPDATE '.CATEGORIES_TABLE.'
116  SET commentable = \'true\'
117  WHERE id IN ('.implode(',', $_POST['cat_false']).')
118;';
119      pwg_query($query);
120      break;
121    }
122    case 'visible' :
123    {
124      set_cat_visible($_POST['cat_false'], 'true');
125      break;
126    }
127    case 'status' :
128    {
129      set_cat_status($_POST['cat_false'], 'public');
130      break;
131    }
132    case 'representative' :
133    {
134      // theoretically, all categories in $_POST['cat_false'] contain at
135      // least one element, so PhpWebGallery can find a representant.
136      set_random_representant($_POST['cat_false']);
137      break;
138    }
139  }
140}
141
142// +-----------------------------------------------------------------------+
143// |                             template init                             |
144// +-----------------------------------------------------------------------+
145
146$template->set_filenames(
147  array(
148    'cat_options' => 'admin/cat_options.tpl',
149    'double_select' => 'admin/double_select.tpl'
150    )
151  );
152
153$page['section'] = isset($_GET['section']) ? $_GET['section'] : 'upload';
154$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
155
156$template->assign_vars(
157  array(
158    'L_SUBMIT'=>$lang['submit'],
159    'L_RESET'=>$lang['reset'],
160
161    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_options',
162   
163    'F_ACTION'=>$base_url.$page['section']
164   )
165 );
166
167// TabSheet initialization
168$opt_link = $link_start.'cat_options&amp;section=';
169$page['tabsheet'] = array
170(
171  'upload' => array
172   (
173    'caption' => l10n('upload'),
174    'url' => $opt_link.'upload'
175   ),
176  'comments' => array
177   (
178    'caption' => l10n('comments'),
179    'url' => $opt_link.'comments'
180   ),
181  'visible' => array
182   (
183    'caption' => l10n('lock'),
184    'url' => $opt_link.'visible'
185   ),
186  'status' => array
187   (
188    'caption' => l10n('cat_security'),
189    'url' => $opt_link.'status'
190   )
191);
192
193if ($conf['allow_random_representative'])
194{
195  $page['tabsheet']['representative'] =
196    array
197    (
198      'caption' => l10n('Representative'),
199      'url' => $opt_link.'representative'
200    );
201}
202$page['tabsheet'][$page['section']]['selected'] = true;
203
204// Assign tabsheet to template
205template_assign_tabsheet();
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_vars(
241      array(
242        'L_SECTION' => $lang['cat_upload_title'],
243        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
244        'L_CAT_OPTIONS_FALSE' => $lang['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_vars(
262      array(
263        'L_SECTION' => $lang['cat_comments_title'],
264        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
265        'L_CAT_OPTIONS_FALSE' => $lang['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_vars(
283      array(
284        'L_SECTION' => $lang['cat_lock_title'],
285        'L_CAT_OPTIONS_TRUE' => $lang['unlocked'],
286        'L_CAT_OPTIONS_FALSE' => $lang['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_vars(
304      array(
305        'L_SECTION' => $lang['cat_status_title'],
306        'L_CAT_OPTIONS_TRUE' => $lang['cat_public'],
307        'L_CAT_OPTIONS_FALSE' => $lang['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_vars(
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.