source: trunk/admin/cat_options.php @ 614

Last change on this file since 614 was 614, checked in by plg, 19 years ago
  • global categories' options : instead of N horizontal tabs on a single page, N options in the left menu (but the same backend)
  • categories.global_rank : new calculated field. It gives a global rank of the category among all others (updated during ordering)
  • category.php page : menu is generated faster thanks to categories.global_rank, recursivity becomes useless :-)
  • new function to display select box with a set of categories : display_select_cat_wrapper
  • cat_options : instead of using 1 multiselect for true/false items, using 1 multiselect for true, and another one for false. The form provides buttons with arrows to switch categories from one multiselect to another
  • deletion of obsolete function display_categories (working with the old template system)
  • deletion of obsolete functions get_user_plain_structure, create_user_structure, get_user_subcat_ids, update_structure, count_images : useless thanks to global_rank
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-23 22:31:24 +0000 (Tue, 23 Nov 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 614 $
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}
32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
33// +-----------------------------------------------------------------------+
34// |                       modification registration                       |
35// +-----------------------------------------------------------------------+
36// print '<pre>';
37// print_r($_POST);
38// print '</pre>';
39if (isset($_POST['falsify']) and count($_POST['cat_true']) > 0)
40{
41  switch ($_GET['section'])
42  {
43    case 'upload' :
44    {
45      $query = '
46UPDATE '.CATEGORIES_TABLE.'
47  SET uploadable = \'false\'
48  WHERE id IN ('.implode(',', $_POST['cat_true']).')
49;';
50      pwg_query($query);
51      break;
52    }
53    case 'comments' :
54    {
55      $query = '
56UPDATE '.CATEGORIES_TABLE.'
57  SET commentable = \'false\'
58  WHERE id IN ('.implode(',', $_POST['cat_true']).')
59;';
60      pwg_query($query);
61      break;
62    }
63    case 'visible' :
64    {
65      // locking a category   => all its child categories become locked
66      $subcats = get_subcat_ids($_POST['cat_true']);
67      $query = '
68UPDATE '.CATEGORIES_TABLE.'
69  SET visible = \'false\'
70  WHERE id IN ('.implode(',', $subcats).')
71;';
72      pwg_query($query);
73      break;
74    }
75    case 'status' :
76    {
77      // make a category private => all its child categories become private
78      $subcats = get_subcat_ids($_POST['cat_true']);
79      $query = '
80UPDATE '.CATEGORIES_TABLE.'
81  SET status = \'private\'
82  WHERE id IN ('.implode(',', $subcats).')
83;';
84      pwg_query($query);
85      break;
86    }
87  }
88}
89else if (isset($_POST['trueify']) and count($_POST['cat_false']) > 0)
90{
91  switch ($_GET['section'])
92  {
93    case 'upload' :
94    {
95      $query = '
96UPDATE '.CATEGORIES_TABLE.'
97  SET uploadable = \'true\'
98  WHERE id IN ('.implode(',', $_POST['cat_false']).')
99;';
100      pwg_query($query);
101      break;
102    }
103    case 'comments' :
104    {
105      $query = '
106UPDATE '.CATEGORIES_TABLE.'
107  SET commentable = \'true\'
108  WHERE id IN ('.implode(',', $_POST['cat_false']).')
109;';
110      pwg_query($query);
111      break;
112    }
113    case 'visible' :
114    {
115      // unlocking a category => all its parent categories become unlocked
116      $uppercats = array();
117      $query = '
118SELECT uppercats
119  FROM '.CATEGORIES_TABLE.'
120  WHERE id IN ('.implode(',', $_POST['cat_false']).')
121;';
122      $result = pwg_query($query);
123      while ($row = mysql_fetch_array($result))
124      {
125        $uppercats = array_merge($uppercats,
126                                 explode(',', $row['uppercats']));
127      }
128      $uppercats = array_unique($uppercats);
129     
130      $query = '
131UPDATE '.CATEGORIES_TABLE.'
132  SET visible = \'true\'
133  WHERE id IN ('.implode(',', $uppercats).')
134;';
135      pwg_query($query);
136      break;
137    }
138    case 'status' :
139    {
140      // make public a category => all its parent categories become public
141      $uppercats = array();
142      $query = '
143SELECT uppercats
144  FROM '.CATEGORIES_TABLE.'
145  WHERE id IN ('.implode(',', $_POST['cat_false']).')
146;';
147      $result = pwg_query($query);
148      while ($row = mysql_fetch_array($result))
149      {
150        $uppercats = array_merge($uppercats,
151                                 explode(',', $row['uppercats']));
152      }
153      $uppercats = array_unique($uppercats);
154     
155      $query = '
156UPDATE '.CATEGORIES_TABLE.'
157  SET status = \'public\'
158  WHERE id IN ('.implode(',', $uppercats).')
159;';
160      pwg_query($query);
161      break;
162    }
163  }
164}
165// +-----------------------------------------------------------------------+
166// |                             template init                             |
167// +-----------------------------------------------------------------------+
168$template->set_filenames(array('cat_options'=>'admin/cat_options.tpl'));
169
170if (!isset($_GET['section']))
171{
172  $page['section'] = 'upload';
173}
174else
175{
176  $page['section'] = $_GET['section'];
177}
178
179$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
180$template->assign_vars(
181  array(
182    'L_SUBMIT'=>$lang['submit'],
183    'L_RESET'=>$lang['reset'],
184   
185    'U_UPLOAD'=>add_session_id($base_url.'upload'),
186    'U_VISIBLE'=>add_session_id($base_url.'visible'),
187    'U_COMMENTS'=>add_session_id($base_url.'comments'),
188    'U_STATUS'=>add_session_id($base_url.'status'),
189   
190    'F_ACTION'=>add_session_id($base_url.$page['section'])
191   )
192 );
193
194$template->assign_vars(array(strtoupper($page['section']).'_CLASS'=>'opened'));
195// +-----------------------------------------------------------------------+
196// |                              form display                             |
197// +-----------------------------------------------------------------------+
198
199// for each section, categories in the multiselect field can be :
200//
201// - true : uploadable for upload section
202// - false : un-uploadable for upload section
203// - NA : (not applicable) for virtual categories
204//
205// for true and false status, we associates an array of category ids,
206// function display_select_categories will use the given CSS class for each
207// option
208$cats_true = array();
209$cats_false = array();
210switch ($page['section'])
211{
212  case 'upload' :
213  {
214    $query_true = '
215SELECT id,name,uppercats,global_rank
216  FROM '.CATEGORIES_TABLE.'
217  WHERE uploadable = \'true\'
218    AND dir IS NOT NULL
219    AND site_id = 1
220;';
221    $query_false = '
222SELECT id,name,uppercats,global_rank
223  FROM '.CATEGORIES_TABLE.'
224  WHERE uploadable = \'false\'
225    AND dir IS NOT NULL
226    AND site_id = 1
227;';
228    $template->assign_vars(
229      array(
230        'L_TITLE' => $lang['cat_options_upload_title'],
231        'L_CAT_OPTIONS_TRUE' => $lang['cat_options_upload_true'],
232        'L_CAT_OPTIONS_FALSE' => $lang['cat_options_upload_false'],
233        'L_CAT_OPTIONS_INFO' => $lang['cat_options_upload_info'],
234        )
235      );
236    $template->assign_block_vars('upload', array());
237    break;
238  }
239  case 'comments' :
240  {
241    $query_true = '
242SELECT id,name,uppercats,global_rank
243  FROM '.CATEGORIES_TABLE.'
244  WHERE commentable = \'true\'
245;';
246    $query_false = '
247SELECT id,name,uppercats,global_rank
248  FROM '.CATEGORIES_TABLE.'
249  WHERE commentable = \'false\'
250;';
251    $template->assign_vars(
252      array(
253        'L_TITLE' => $lang['cat_options_comments_title'],
254        'L_CAT_OPTIONS_TRUE' => $lang['cat_options_comments_true'],
255        'L_CAT_OPTIONS_FALSE' => $lang['cat_options_comments_false'],
256        'L_CAT_OPTIONS_INFO' => $lang['cat_options_comments_info'],
257        )
258      );
259    $template->assign_block_vars('comments', array());
260    break;
261  }
262  case 'visible' :
263  {
264    $query_true = '
265SELECT id,name,uppercats,global_rank
266  FROM '.CATEGORIES_TABLE.'
267  WHERE visible = \'true\'
268;';
269    $query_false = '
270SELECT id,name,uppercats,global_rank
271  FROM '.CATEGORIES_TABLE.'
272  WHERE visible = \'false\'
273;';
274    $template->assign_vars(
275      array(
276        'L_TITLE' => $lang['cat_options_visible_title'],
277        'L_CAT_OPTIONS_TRUE' => $lang['cat_options_visible_true'],
278        'L_CAT_OPTIONS_FALSE' => $lang['cat_options_visible_false'],
279        'L_CAT_OPTIONS_INFO' => $lang['cat_options_visible_info'],
280        )
281      );
282    $template->assign_block_vars('visible', array());
283    break;
284  }
285  case 'status' :
286  {
287    $query_true = '
288SELECT id,name,uppercats,global_rank
289  FROM '.CATEGORIES_TABLE.'
290  WHERE status = \'public\'
291;';
292    $query_false = '
293SELECT id,name,uppercats,global_rank
294  FROM '.CATEGORIES_TABLE.'
295  WHERE status = \'private\'
296;';
297    $template->assign_vars(
298      array(
299        'L_TITLE' => $lang['cat_options_status_title'],
300        'L_CAT_OPTIONS_TRUE' => $lang['cat_options_status_true'],
301        'L_CAT_OPTIONS_FALSE' => $lang['cat_options_status_false'],
302        'L_CAT_OPTIONS_INFO' => $lang['cat_options_status_info'],
303        )
304      );
305    $template->assign_block_vars('status', array());
306    break;
307  }
308}
309display_select_cat_wrapper($query_true,array(),'category_option_true');
310display_select_cat_wrapper($query_false,array(),'category_option_false');
311// +-----------------------------------------------------------------------+
312// |                           sending html code                           |
313// +-----------------------------------------------------------------------+
314$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
315?>
Note: See TracBrowser for help on using the repository browser.