source: branches/2.4/admin/cat_options.php @ 16926

Revision 16926, 8.3 KB checked in by mistic100, 8 years ago (diff)

Merged revision(s) 16925 from trunk:
feature 2703: make it easy for plugins to add tabs in admin screens
add a trigger a give an id to each core tabsheets

  • Property svn:eol-style set to LF
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 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
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
31
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35check_status(ACCESS_ADMINISTRATOR);
36
37// +-----------------------------------------------------------------------+
38// |                       modification registration                       |
39// +-----------------------------------------------------------------------+
40
41// print '<pre>';
42// print_r($_POST);
43// print '</pre>';
44if (isset($_POST['falsify'])
45    and isset($_POST['cat_true'])
46    and count($_POST['cat_true']) > 0)
47{
48  switch ($_GET['section'])
49  {
50    case 'comments' :
51    {
52      $query = '
53UPDATE '.CATEGORIES_TABLE.'
54  SET commentable = \'false\'
55  WHERE id IN ('.implode(',', $_POST['cat_true']).')
56;';
57      pwg_query($query);
58      break;
59    }
60    case 'visible' :
61    {
62      set_cat_visible($_POST['cat_true'], 'false');
63      break;
64    }
65    case 'status' :
66    {
67      set_cat_status($_POST['cat_true'], 'private');
68      break;
69    }
70    case 'representative' :
71    {
72      $query = '
73UPDATE '.CATEGORIES_TABLE.'
74  SET representative_picture_id = NULL
75  WHERE id IN ('.implode(',', $_POST['cat_true']).')
76;';
77      pwg_query($query);
78      break;
79    }
80  }
81}
82else if (isset($_POST['trueify'])
83         and isset($_POST['cat_false'])
84         and count($_POST['cat_false']) > 0)
85{
86  switch ($_GET['section'])
87  {
88    case 'comments' :
89    {
90      $query = '
91UPDATE '.CATEGORIES_TABLE.'
92  SET commentable = \'true\'
93  WHERE id IN ('.implode(',', $_POST['cat_false']).')
94;';
95      pwg_query($query);
96      break;
97    }
98    case 'visible' :
99    {
100      set_cat_visible($_POST['cat_false'], 'true');
101      break;
102    }
103    case 'status' :
104    {
105      set_cat_status($_POST['cat_false'], 'public');
106      break;
107    }
108    case 'representative' :
109    {
110      // theoretically, all categories in $_POST['cat_false'] contain at
111      // least one element, so Piwigo can find a representant.
112      set_random_representant($_POST['cat_false']);
113      break;
114    }
115  }
116}
117
118// +-----------------------------------------------------------------------+
119// |                             template init                             |
120// +-----------------------------------------------------------------------+
121
122$template->set_filenames(
123  array(
124    'cat_options' => 'cat_options.tpl',
125    'double_select' => 'double_select.tpl'
126    )
127  );
128
129$page['section'] = isset($_GET['section']) ? $_GET['section'] : 'status';
130$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_options&amp;section=';
131
132$template->assign(
133  array(
134    'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_options',
135    'F_ACTION'=>$base_url.$page['section']
136   )
137 );
138
139// TabSheet
140$tabsheet = new tabsheet();
141$tabsheet->set_id('cat_options');
142// TabSheet initialization
143$opt_link = $link_start.'cat_options&amp;section=';
144$tabsheet->add('status', l10n('Public / Private'), $opt_link.'status');
145$tabsheet->add('visible', l10n('Lock'), $opt_link.'visible');
146if ($conf['activate_comments'])
147{
148  $tabsheet->add('comments', l10n('Comments'), $opt_link.'comments');
149}
150if ($conf['allow_random_representative'])
151{
152  $tabsheet->add('representative', l10n('Representative'), $opt_link.'representative');
153}
154// TabSheet selection
155$tabsheet->select($page['section']);
156// Assign tabsheet to template
157$tabsheet->assign();
158
159// +-----------------------------------------------------------------------+
160// |                              form display                             |
161// +-----------------------------------------------------------------------+
162
163// for each section, categories in the multiselect field can be :
164//
165// - true : commentable for comment section
166// - false : un-commentable for comment section
167// - NA : (not applicable) for virtual categories
168//
169// for true and false status, we associates an array of category ids,
170// function display_select_categories will use the given CSS class for each
171// option
172$cats_true = array();
173$cats_false = array();
174switch ($page['section'])
175{
176  case 'comments' :
177  {
178    $query_true = '
179SELECT id,name,uppercats,global_rank
180  FROM '.CATEGORIES_TABLE.'
181  WHERE commentable = \'true\'
182;';
183    $query_false = '
184SELECT id,name,uppercats,global_rank
185  FROM '.CATEGORIES_TABLE.'
186  WHERE commentable = \'false\'
187;';
188    $template->assign(
189      array(
190        'L_SECTION' => l10n('Authorize users to add comments on selected albums'),
191        'L_CAT_OPTIONS_TRUE' => l10n('Authorized'),
192        'L_CAT_OPTIONS_FALSE' => l10n('Forbidden'),
193        )
194      );
195    break;
196  }
197  case 'visible' :
198  {
199    $query_true = '
200SELECT id,name,uppercats,global_rank
201  FROM '.CATEGORIES_TABLE.'
202  WHERE visible = \'true\'
203;';
204    $query_false = '
205SELECT id,name,uppercats,global_rank
206  FROM '.CATEGORIES_TABLE.'
207  WHERE visible = \'false\'
208;';
209    $template->assign(
210      array(
211        'L_SECTION' => l10n('Lock albums'),
212        'L_CAT_OPTIONS_TRUE' => l10n('Unlocked'),
213        'L_CAT_OPTIONS_FALSE' => l10n('Locked'),
214        )
215      );
216    break;
217  }
218  case 'status' :
219  {
220    $query_true = '
221SELECT id,name,uppercats,global_rank
222  FROM '.CATEGORIES_TABLE.'
223  WHERE status = \'public\'
224;';
225    $query_false = '
226SELECT id,name,uppercats,global_rank
227  FROM '.CATEGORIES_TABLE.'
228  WHERE status = \'private\'
229;';
230    $template->assign(
231      array(
232        'L_SECTION' => l10n('Manage authorizations for selected albums'),
233        'L_CAT_OPTIONS_TRUE' => l10n('Public'),
234        'L_CAT_OPTIONS_FALSE' => l10n('Private'),
235        )
236      );
237    break;
238  }
239  case 'representative' :
240  {
241    $query_true = '
242SELECT id,name,uppercats,global_rank
243  FROM '.CATEGORIES_TABLE.'
244  WHERE representative_picture_id IS NOT NULL
245;';
246    $query_false = '
247SELECT DISTINCT id,name,uppercats,global_rank
248  FROM '.CATEGORIES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=category_id
249  WHERE representative_picture_id IS NULL
250;';
251    $template->assign(
252      array(
253        'L_SECTION' => l10n('Representative'),
254        'L_CAT_OPTIONS_TRUE' => l10n('singly represented'),
255        'L_CAT_OPTIONS_FALSE' => l10n('randomly represented')
256        )
257      );
258    break;
259  }
260}
261display_select_cat_wrapper($query_true,array(),'category_option_true');
262display_select_cat_wrapper($query_false,array(),'category_option_false');
263
264// +-----------------------------------------------------------------------+
265// |                           sending html code                           |
266// +-----------------------------------------------------------------------+
267
268$template->assign_var_from_handle('DOUBLE_SELECT', 'double_select');
269$template->assign_var_from_handle('ADMIN_CONTENT', 'cat_options');
270?>
Note: See TracBrowser for help on using the repository browser.