source: trunk/admin/cat_options.php @ 1865

Last change on this file since 1865 was 1865, checked in by rvelices, 17 years ago

admin pages: merge Categories/comments page into Configuration/comments page
(they are related and we reduce the # of links in the menu)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 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-02-28 00:16:53 +0000 (Wed, 28 Feb 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1865 $
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');
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 'visible' :
64    {
65      set_cat_visible($_POST['cat_true'], 'false');
66      break;
67    }
68    case 'status' :
69    {
70      set_cat_status($_POST['cat_true'], 'private');
71      break;
72    }
73    case 'representative' :
74    {
75      $query = '
76UPDATE '.CATEGORIES_TABLE.'
77  SET representative_picture_id = NULL
78  WHERE id IN ('.implode(',', $_POST['cat_true']).')
79;';
80      pwg_query($query);
81      break;
82    }
83  }
84}
85else if (isset($_POST['trueify'])
86         and isset($_POST['cat_false'])
87         and count($_POST['cat_false']) > 0)
88{
89  switch ($_GET['section'])
90  {
91    case 'upload' :
92    {
93      $query = '
94UPDATE '.CATEGORIES_TABLE.'
95  SET uploadable = \'true\'
96  WHERE id IN ('.implode(',', $_POST['cat_false']).')
97;';
98      pwg_query($query);
99      break;
100    }
101    case 'visible' :
102    {
103      set_cat_visible($_POST['cat_false'], 'true');
104      break;
105    }
106    case 'status' :
107    {
108      set_cat_status($_POST['cat_false'], 'public');
109      break;
110    }
111    case 'representative' :
112    {
113      // theoretically, all categories in $_POST['cat_false'] contain at
114      // least one element, so PhpWebGallery can find a representant.
115      set_random_representant($_POST['cat_false']);
116      break;
117    }
118  }
119}
120
121// +-----------------------------------------------------------------------+
122// |                             template init                             |
123// +-----------------------------------------------------------------------+
124
125$template->set_filenames(
126  array(
127    'cat_options' => 'admin/cat_options.tpl',
128    'double_select' => 'admin/double_select.tpl'
129    )
130  );
131
132$page['section'] = isset($_GET['section']) ? $_GET['section'] : 'upload';
133$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
134
135$template->assign_vars(
136  array(
137    'L_SUBMIT'=>$lang['submit'],
138    'L_RESET'=>$lang['reset'],
139
140    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_options',
141   
142    'F_ACTION'=>$base_url.$page['section']
143   )
144 );
145
146// +-----------------------------------------------------------------------+
147// |                              form display                             |
148// +-----------------------------------------------------------------------+
149
150// for each section, categories in the multiselect field can be :
151//
152// - true : uploadable for upload section
153// - false : un-uploadable for upload section
154// - NA : (not applicable) for virtual categories
155//
156// for true and false status, we associates an array of category ids,
157// function display_select_categories will use the given CSS class for each
158// option
159$cats_true = array();
160$cats_false = array();
161switch ($page['section'])
162{
163  case 'upload' :
164  {
165    $query_true = '
166SELECT id,name,uppercats,global_rank
167  FROM '.CATEGORIES_TABLE.'
168  WHERE uploadable = \'true\'
169    AND dir IS NOT NULL
170    AND site_id = 1
171;';
172    $query_false = '
173SELECT id,name,uppercats,global_rank
174  FROM '.CATEGORIES_TABLE.'
175  WHERE uploadable = \'false\'
176    AND dir IS NOT NULL
177    AND site_id = 1
178;';
179    $template->assign_vars(
180      array(
181        'L_SECTION' => $lang['cat_upload_title'],
182        'L_CAT_OPTIONS_TRUE' => $lang['authorized'],
183        'L_CAT_OPTIONS_FALSE' => $lang['forbidden'],
184        )
185      );
186    break;
187  }
188  case 'visible' :
189  {
190    $query_true = '
191SELECT id,name,uppercats,global_rank
192  FROM '.CATEGORIES_TABLE.'
193  WHERE visible = \'true\'
194;';
195    $query_false = '
196SELECT id,name,uppercats,global_rank
197  FROM '.CATEGORIES_TABLE.'
198  WHERE visible = \'false\'
199;';
200    $template->assign_vars(
201      array(
202        'L_SECTION' => $lang['cat_lock_title'],
203        'L_CAT_OPTIONS_TRUE' => $lang['unlocked'],
204        'L_CAT_OPTIONS_FALSE' => $lang['locked'],
205        )
206      );
207    break;
208  }
209  case 'status' :
210  {
211    $query_true = '
212SELECT id,name,uppercats,global_rank
213  FROM '.CATEGORIES_TABLE.'
214  WHERE status = \'public\'
215;';
216    $query_false = '
217SELECT id,name,uppercats,global_rank
218  FROM '.CATEGORIES_TABLE.'
219  WHERE status = \'private\'
220;';
221    $template->assign_vars(
222      array(
223        'L_SECTION' => $lang['cat_status_title'],
224        'L_CAT_OPTIONS_TRUE' => $lang['cat_public'],
225        'L_CAT_OPTIONS_FALSE' => $lang['cat_private'],
226        )
227      );
228    break;
229  }
230  case 'representative' :
231  {
232    $query_true = '
233SELECT id,name,uppercats,global_rank
234  FROM '.CATEGORIES_TABLE.'
235  WHERE representative_picture_id IS NOT NULL
236;';
237    $query_false = '
238SELECT id,name,uppercats,global_rank
239  FROM '.CATEGORIES_TABLE.'
240  WHERE nb_images != 0
241    AND representative_picture_id IS NULL
242;';
243    $template->assign_vars(
244      array(
245        'L_SECTION' => l10n('Representative'),
246        'L_CAT_OPTIONS_TRUE' => l10n('singly represented'),
247        'L_CAT_OPTIONS_FALSE' => l10n('randomly represented')
248        )
249      );
250    break;
251  }
252}
253display_select_cat_wrapper($query_true,array(),'category_option_true');
254display_select_cat_wrapper($query_false,array(),'category_option_false');
255
256// +-----------------------------------------------------------------------+
257// |                           sending html code                           |
258// +-----------------------------------------------------------------------+
259
260$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
261$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
262?>
Note: See TracBrowser for help on using the repository browser.