source: trunk/admin/cat_options.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: cat_options.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48if (!defined('PHPWG_ROOT_PATH'))
49{
50  die ("Hacking attempt!");
51}
52
53include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
54include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
55
56// +-----------------------------------------------------------------------+
57// | Check Access and exit when user status is not ok                      |
58// +-----------------------------------------------------------------------+
59check_status(ACCESS_ADMINISTRATOR);
60
61// +-----------------------------------------------------------------------+
62// |                       modification registration                       |
63// +-----------------------------------------------------------------------+
64
65// print '<pre>';
66// print_r($_POST);
67// print '</pre>';
68if (isset($_POST['falsify'])
69    and isset($_POST['cat_true'])
70    and count($_POST['cat_true']) > 0)
71{
72  switch ($_GET['section'])
73  {
74    case 'upload' :
75    {
76      $query = '
77UPDATE '.CATEGORIES_TABLE.'
78  SET uploadable = \'false\'
79  WHERE id IN ('.implode(',', $_POST['cat_true']).')
80;';
81      pwg_query($query);
82      break;
83    }
84    case 'comments' :
85    {
86      $query = '
87UPDATE '.CATEGORIES_TABLE.'
88  SET commentable = \'false\'
89  WHERE id IN ('.implode(',', $_POST['cat_true']).')
90;';
91      pwg_query($query);
92      break;
93    }
94    case 'visible' :
95    {
96      set_cat_visible($_POST['cat_true'], 'false');
97      break;
98    }
99    case 'status' :
100    {
101      set_cat_status($_POST['cat_true'], 'private');
102      break;
103    }
104    case 'representative' :
105    {
106      $query = '
107UPDATE '.CATEGORIES_TABLE.'
108  SET representative_picture_id = NULL
109  WHERE id IN ('.implode(',', $_POST['cat_true']).')
110;';
111      pwg_query($query);
112      break;
113    }
114  }
115}
116else if (isset($_POST['trueify'])
117         and isset($_POST['cat_false'])
118         and count($_POST['cat_false']) > 0)
119{
120  switch ($_GET['section'])
121  {
122    case 'upload' :
123    {
124      $query = '
125UPDATE '.CATEGORIES_TABLE.'
126  SET uploadable = \'true\'
127  WHERE id IN ('.implode(',', $_POST['cat_false']).')
128;';
129      pwg_query($query);
130      break;
131    }
132    case 'comments' :
133    {
134      $query = '
135UPDATE '.CATEGORIES_TABLE.'
136  SET commentable = \'true\'
137  WHERE id IN ('.implode(',', $_POST['cat_false']).')
138;';
139      pwg_query($query);
140      break;
141    }
142    case 'visible' :
143    {
144      set_cat_visible($_POST['cat_false'], 'true');
145      break;
146    }
147    case 'status' :
148    {
149      set_cat_status($_POST['cat_false'], 'public');
150      break;
151    }
152    case 'representative' :
153    {
154      // theoretically, all categories in $_POST['cat_false'] contain at
155      // least one element, so PhpWebGallery can find a representant.
156      set_random_representant($_POST['cat_false']);
157      break;
158    }
159  }
160}
161
162// +-----------------------------------------------------------------------+
163// |                             template init                             |
164// +-----------------------------------------------------------------------+
165
166$template->set_filenames(
167  array(
168    'cat_options' => 'admin/cat_options.tpl',
169    'double_select' => 'admin/double_select.tpl'
170    )
171  );
172
173$page['section'] = isset($_GET['section']) ? $_GET['section'] : 'status';
174$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
175
176$template->assign(
177  array(
178    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_options',
179    'F_ACTION'=>$base_url.$page['section']
180   )
181 );
182
183// TabSheet
184$tabsheet = new tabsheet();
185// TabSheet initialization
186$opt_link = $link_start.'cat_options&amp;section=';
187$tabsheet->add('status', l10n('cat_security'), $opt_link.'status');
188$tabsheet->add('visible', l10n('lock'), $opt_link.'visible');
189$tabsheet->add('upload', l10n('upload'), $opt_link.'upload');
190$tabsheet->add('comments', l10n('comments'), $opt_link.'comments');
191if ($conf['allow_random_representative'])
192{
193  $tabsheet->add('representative', l10n('Representative'), $opt_link.'representative');
194}
195// TabSheet selection
196$tabsheet->select($page['section']);
197// Assign tabsheet to template
198$tabsheet->assign();
199
200// +-----------------------------------------------------------------------+
201// |                              form display                             |
202// +-----------------------------------------------------------------------+
203
204// for each section, categories in the multiselect field can be :
205//
206// - true : uploadable for upload section
207// - false : un-uploadable for upload section
208// - NA : (not applicable) for virtual categories
209//
210// for true and false status, we associates an array of category ids,
211// function display_select_categories will use the given CSS class for each
212// option
213$cats_true = array();
214$cats_false = array();
215switch ($page['section'])
216{
217  case 'upload' :
218  {
219    $query_true = '
220SELECT id,name,uppercats,global_rank
221  FROM '.CATEGORIES_TABLE.'
222  WHERE uploadable = \'true\'
223    AND dir IS NOT NULL
224    AND site_id = 1
225;';
226    $query_false = '
227SELECT id,name,uppercats,global_rank
228  FROM '.CATEGORIES_TABLE.'
229  WHERE uploadable = \'false\'
230    AND dir IS NOT NULL
231    AND site_id = 1
232;';
233    $template->assign(
234      array(
235        'L_SECTION' => l10n('cat_upload_title'),
236        'L_CAT_OPTIONS_TRUE' => l10n('authorized'),
237        'L_CAT_OPTIONS_FALSE' => l10n('forbidden'),
238        )
239      );
240    break;
241  }
242  case 'comments' :
243  {
244    $query_true = '
245SELECT id,name,uppercats,global_rank
246  FROM '.CATEGORIES_TABLE.'
247  WHERE commentable = \'true\'
248;';
249    $query_false = '
250SELECT id,name,uppercats,global_rank
251  FROM '.CATEGORIES_TABLE.'
252  WHERE commentable = \'false\'
253;';
254    $template->assign(
255      array(
256        'L_SECTION' => l10n('cat_comments_title'),
257        'L_CAT_OPTIONS_TRUE' => l10n('authorized'),
258        'L_CAT_OPTIONS_FALSE' => l10n('forbidden'),
259        )
260      );
261    break;
262  }
263  case 'visible' :
264  {
265    $query_true = '
266SELECT id,name,uppercats,global_rank
267  FROM '.CATEGORIES_TABLE.'
268  WHERE visible = \'true\'
269;';
270    $query_false = '
271SELECT id,name,uppercats,global_rank
272  FROM '.CATEGORIES_TABLE.'
273  WHERE visible = \'false\'
274;';
275    $template->assign(
276      array(
277        'L_SECTION' => l10n('cat_lock_title'),
278        'L_CAT_OPTIONS_TRUE' => l10n('unlocked'),
279        'L_CAT_OPTIONS_FALSE' => l10n('locked'),
280        )
281      );
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(
297      array(
298        'L_SECTION' => l10n('cat_status_title'),
299        'L_CAT_OPTIONS_TRUE' => l10n('cat_public'),
300        'L_CAT_OPTIONS_FALSE' => l10n('cat_private'),
301        )
302      );
303    break;
304  }
305  case 'representative' :
306  {
307    $query_true = '
308SELECT id,name,uppercats,global_rank
309  FROM '.CATEGORIES_TABLE.'
310  WHERE representative_picture_id IS NOT NULL
311;';
312    $query_false = '
313SELECT id,name,uppercats,global_rank
314  FROM '.CATEGORIES_TABLE.'
315  WHERE nb_images != 0
316    AND representative_picture_id IS NULL
317;';
318    $template->assign(
319      array(
320        'L_SECTION' => l10n('Representative'),
321        'L_CAT_OPTIONS_TRUE' => l10n('singly represented'),
322        'L_CAT_OPTIONS_FALSE' => l10n('randomly represented')
323        )
324      );
325    break;
326  }
327}
328display_select_cat_wrapper($query_true,array(),'category_option_true');
329display_select_cat_wrapper($query_false,array(),'category_option_false');
330
331// +-----------------------------------------------------------------------+
332// |                           sending html code                           |
333// +-----------------------------------------------------------------------+
334
335$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
336$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
337?>
Note: See TracBrowser for help on using the repository browser.