source: trunk/admin/cat_options.php @ 2226

Last change on this file since 2226 was 2226, checked in by rub, 16 years ago

0000809: Use more php classes implementation

Use class for tabsheet like grum class
Change way for tabsheet

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 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 2226 2008-02-28 23:41:47Z rub $
8// | last update   : $Date: 2008-02-28 23:41:47 +0000 (Thu, 28 Feb 2008) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 2226 $
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/tabsheet.class.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
163$tabsheet = new tabsheet();
164// TabSheet initialization
165$opt_link = $link_start.'cat_options&amp;section=';
166$tabsheet->add('status', l10n('cat_security'), $opt_link.'status');
167$tabsheet->add('visible', l10n('lock'), $opt_link.'visible');
168$tabsheet->add('upload', l10n('upload'), $opt_link.'upload');
169$tabsheet->add('comments', l10n('comments'), $opt_link.'comments');
170if ($conf['allow_random_representative'])
171{
172  $tabsheet->add('representative', l10n('Representative'), $opt_link.'representative');
173}
174// TabSheet selection
175$tabsheet->select($page['section']);
176// Assign tabsheet to template
177$tabsheet->assign();
178
179// +-----------------------------------------------------------------------+
180// |                              form display                             |
181// +-----------------------------------------------------------------------+
182
183// for each section, categories in the multiselect field can be :
184//
185// - true : uploadable for upload section
186// - false : un-uploadable for upload section
187// - NA : (not applicable) for virtual categories
188//
189// for true and false status, we associates an array of category ids,
190// function display_select_categories will use the given CSS class for each
191// option
192$cats_true = array();
193$cats_false = array();
194switch ($page['section'])
195{
196  case 'upload' :
197  {
198    $query_true = '
199SELECT id,name,uppercats,global_rank
200  FROM '.CATEGORIES_TABLE.'
201  WHERE uploadable = \'true\'
202    AND dir IS NOT NULL
203    AND site_id = 1
204;';
205    $query_false = '
206SELECT id,name,uppercats,global_rank
207  FROM '.CATEGORIES_TABLE.'
208  WHERE uploadable = \'false\'
209    AND dir IS NOT NULL
210    AND site_id = 1
211;';
212    $template->assign(
213      array(
214        'L_SECTION' => l10n('cat_upload_title'),
215        'L_CAT_OPTIONS_TRUE' => l10n('authorized'),
216        'L_CAT_OPTIONS_FALSE' => l10n('forbidden'),
217        )
218      );
219    break;
220  }
221  case 'comments' :
222  {
223    $query_true = '
224SELECT id,name,uppercats,global_rank
225  FROM '.CATEGORIES_TABLE.'
226  WHERE commentable = \'true\'
227;';
228    $query_false = '
229SELECT id,name,uppercats,global_rank
230  FROM '.CATEGORIES_TABLE.'
231  WHERE commentable = \'false\'
232;';
233    $template->assign(
234      array(
235        'L_SECTION' => l10n('cat_comments_title'),
236        'L_CAT_OPTIONS_TRUE' => l10n('authorized'),
237        'L_CAT_OPTIONS_FALSE' => l10n('forbidden'),
238        )
239      );
240    break;
241  }
242  case 'visible' :
243  {
244    $query_true = '
245SELECT id,name,uppercats,global_rank
246  FROM '.CATEGORIES_TABLE.'
247  WHERE visible = \'true\'
248;';
249    $query_false = '
250SELECT id,name,uppercats,global_rank
251  FROM '.CATEGORIES_TABLE.'
252  WHERE visible = \'false\'
253;';
254    $template->assign(
255      array(
256        'L_SECTION' => l10n('cat_lock_title'),
257        'L_CAT_OPTIONS_TRUE' => l10n('unlocked'),
258        'L_CAT_OPTIONS_FALSE' => l10n('locked'),
259        )
260      );
261    break;
262  }
263  case 'status' :
264  {
265    $query_true = '
266SELECT id,name,uppercats,global_rank
267  FROM '.CATEGORIES_TABLE.'
268  WHERE status = \'public\'
269;';
270    $query_false = '
271SELECT id,name,uppercats,global_rank
272  FROM '.CATEGORIES_TABLE.'
273  WHERE status = \'private\'
274;';
275    $template->assign(
276      array(
277        'L_SECTION' => l10n('cat_status_title'),
278        'L_CAT_OPTIONS_TRUE' => l10n('cat_public'),
279        'L_CAT_OPTIONS_FALSE' => l10n('cat_private'),
280        )
281      );
282    break;
283  }
284  case 'representative' :
285  {
286    $query_true = '
287SELECT id,name,uppercats,global_rank
288  FROM '.CATEGORIES_TABLE.'
289  WHERE representative_picture_id IS NOT NULL
290;';
291    $query_false = '
292SELECT id,name,uppercats,global_rank
293  FROM '.CATEGORIES_TABLE.'
294  WHERE nb_images != 0
295    AND representative_picture_id IS NULL
296;';
297    $template->assign(
298      array(
299        'L_SECTION' => l10n('Representative'),
300        'L_CAT_OPTIONS_TRUE' => l10n('singly represented'),
301        'L_CAT_OPTIONS_FALSE' => l10n('randomly represented')
302        )
303      );
304    break;
305  }
306}
307display_select_cat_wrapper($query_true,array(),'category_option_true');
308display_select_cat_wrapper($query_false,array(),'category_option_false');
309
310// +-----------------------------------------------------------------------+
311// |                           sending html code                           |
312// +-----------------------------------------------------------------------+
313
314$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
315$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
316?>
Note: See TracBrowser for help on using the repository browser.