source: trunk/admin/cat_options.php @ 1846

Last change on this file since 1846 was 1072, checked in by rub, 18 years ago

Step 2 improvement issue 0000301:

o Add and use Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
RevLine 
[604]1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[604]6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-09 22:46:28 +0000 (Thu, 09 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1072 $
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}
[817]32
[1072]33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
[604]35// +-----------------------------------------------------------------------+
[1072]36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40// +-----------------------------------------------------------------------+
[604]41// |                       modification registration                       |
42// +-----------------------------------------------------------------------+
[817]43
[604]44// print '<pre>';
45// print_r($_POST);
46// print '</pre>';
[627]47if (isset($_POST['falsify'])
48    and isset($_POST['cat_true'])
49    and count($_POST['cat_true']) > 0)
[604]50{
51  switch ($_GET['section'])
52  {
53    case 'upload' :
54    {
55      $query = '
56UPDATE '.CATEGORIES_TABLE.'
[614]57  SET uploadable = \'false\'
58  WHERE id IN ('.implode(',', $_POST['cat_true']).')
[604]59;';
60      pwg_query($query);
61      break;
62    }
63    case 'comments' :
64    {
65      $query = '
66UPDATE '.CATEGORIES_TABLE.'
[614]67  SET commentable = \'false\'
68  WHERE id IN ('.implode(',', $_POST['cat_true']).')
[604]69;';
70      pwg_query($query);
71      break;
72    }
73    case 'visible' :
74    {
[632]75      set_cat_visible($_POST['cat_true'], 'false');
[614]76      break;
77    }
78    case 'status' :
79    {
[632]80      set_cat_status($_POST['cat_true'], 'private');
[614]81      break;
82    }
[809]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    }
[614]93  }
94}
[627]95else if (isset($_POST['trueify'])
96         and isset($_POST['cat_false'])
97         and count($_POST['cat_false']) > 0)
[614]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    {
[632]123      set_cat_visible($_POST['cat_false'], 'true');
[604]124      break;
125    }
126    case 'status' :
127    {
[632]128      set_cat_status($_POST['cat_false'], 'public');
[604]129      break;
130    }
[809]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    }
[604]138  }
139}
[817]140
[604]141// +-----------------------------------------------------------------------+
142// |                             template init                             |
143// +-----------------------------------------------------------------------+
144
[817]145$template->set_filenames(
146  array(
147    'cat_options' => 'admin/cat_options.tpl',
148    'double_select' => 'admin/double_select.tpl'
149    )
150  );
[604]151
[817]152$page['section'] = isset($_GET['section']) ? $_GET['section'] : 'upload';
[604]153$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
[817]154
[604]155$template->assign_vars(
156  array(
157    'L_SUBMIT'=>$lang['submit'],
158    'L_RESET'=>$lang['reset'],
[862]159
160    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_options',
[604]161   
[1004]162    'F_ACTION'=>$base_url.$page['section']
[604]163   )
164 );
165
166// +-----------------------------------------------------------------------+
167// |                              form display                             |
168// +-----------------------------------------------------------------------+
169
170// for each section, categories in the multiselect field can be :
171//
172// - true : uploadable for upload section
173// - false : un-uploadable for upload section
174// - NA : (not applicable) for virtual categories
175//
176// for true and false status, we associates an array of category ids,
177// function display_select_categories will use the given CSS class for each
178// option
179$cats_true = array();
180$cats_false = array();
181switch ($page['section'])
182{
183  case 'upload' :
184  {
[614]185    $query_true = '
186SELECT id,name,uppercats,global_rank
[604]187  FROM '.CATEGORIES_TABLE.'
188  WHERE uploadable = \'true\'
189    AND dir IS NOT NULL
190    AND site_id = 1
191;';
[614]192    $query_false = '
193SELECT id,name,uppercats,global_rank
[604]194  FROM '.CATEGORIES_TABLE.'
195  WHERE uploadable = \'false\'
196    AND dir IS NOT NULL
197    AND site_id = 1
198;';
[614]199    $template->assign_vars(
200      array(
[817]201        'L_SECTION' => $lang['cat_upload_title'],
[622]202        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
203        'L_CAT_OPTIONS_FALSE' => $lang['forbidden'],
[614]204        )
205      );
[604]206    break;
207  }
208  case 'comments' :
209  {
[614]210    $query_true = '
211SELECT id,name,uppercats,global_rank
[604]212  FROM '.CATEGORIES_TABLE.'
213  WHERE commentable = \'true\'
214;';
[614]215    $query_false = '
216SELECT id,name,uppercats,global_rank
[604]217  FROM '.CATEGORIES_TABLE.'
218  WHERE commentable = \'false\'
219;';
[614]220    $template->assign_vars(
221      array(
[817]222        'L_SECTION' => $lang['cat_comments_title'],
[622]223        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
224        'L_CAT_OPTIONS_FALSE' => $lang['forbidden'],
[614]225        )
226      );
[604]227    break;
228  }
229  case 'visible' :
230  {
[614]231    $query_true = '
232SELECT id,name,uppercats,global_rank
[604]233  FROM '.CATEGORIES_TABLE.'
234  WHERE visible = \'true\'
235;';
[614]236    $query_false = '
237SELECT id,name,uppercats,global_rank
[604]238  FROM '.CATEGORIES_TABLE.'
239  WHERE visible = \'false\'
240;';
[614]241    $template->assign_vars(
242      array(
[817]243        'L_SECTION' => $lang['cat_lock_title'],
[632]244        'L_CAT_OPTIONS_TRUE' => $lang['unlocked'],
245        'L_CAT_OPTIONS_FALSE' => $lang['locked'],
[614]246        )
247      );
[604]248    break;
249  }
250  case 'status' :
251  {
[614]252    $query_true = '
253SELECT id,name,uppercats,global_rank
[604]254  FROM '.CATEGORIES_TABLE.'
255  WHERE status = \'public\'
256;';
[614]257    $query_false = '
258SELECT id,name,uppercats,global_rank
[604]259  FROM '.CATEGORIES_TABLE.'
260  WHERE status = \'private\'
261;';
[614]262    $template->assign_vars(
263      array(
[817]264        'L_SECTION' => $lang['cat_status_title'],
[622]265        'L_CAT_OPTIONS_TRUE' => $lang['cat_public'],
266        'L_CAT_OPTIONS_FALSE' => $lang['cat_private'],
[614]267        )
268      );
[604]269    break;
270  }
[809]271  case 'representative' :
272  {
273    $query_true = '
274SELECT id,name,uppercats,global_rank
275  FROM '.CATEGORIES_TABLE.'
276  WHERE representative_picture_id IS NOT NULL
277;';
278    $query_false = '
279SELECT id,name,uppercats,global_rank
280  FROM '.CATEGORIES_TABLE.'
281  WHERE nb_images != 0
282    AND representative_picture_id IS NULL
283;';
284    $template->assign_vars(
285      array(
[817]286        'L_SECTION' => l10n('Representative'),
[809]287        'L_CAT_OPTIONS_TRUE' => l10n('singly represented'),
[862]288        'L_CAT_OPTIONS_FALSE' => l10n('randomly represented')
[809]289        )
290      );
291    break;
292  }
[604]293}
[614]294display_select_cat_wrapper($query_true,array(),'category_option_true');
295display_select_cat_wrapper($query_false,array(),'category_option_false');
[817]296
[604]297// +-----------------------------------------------------------------------+
298// |                           sending html code                           |
299// +-----------------------------------------------------------------------+
[817]300
301$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
[604]302$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
303?>
Note: See TracBrowser for help on using the repository browser.