Chris@76
|
1 <?php
|
Chris@76
|
2
|
Chris@76
|
3 /**
|
Chris@76
|
4 * Simple Machines Forum (SMF)
|
Chris@76
|
5 *
|
Chris@76
|
6 * @package SMF
|
Chris@76
|
7 * @author Simple Machines http://www.simplemachines.org
|
Chris@76
|
8 * @copyright 2011 Simple Machines
|
Chris@76
|
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
|
Chris@76
|
10 *
|
Chris@76
|
11 * @version 2.0
|
Chris@76
|
12 */
|
Chris@76
|
13
|
Chris@76
|
14 if (!defined('SMF'))
|
Chris@76
|
15 die('Hacking attempt...');
|
Chris@76
|
16
|
Chris@76
|
17 /* This file is exclusively for generating reports to help assist forum
|
Chris@76
|
18 administrators keep track of their forum configuration and state. The
|
Chris@76
|
19 core report generation is done in two areas. Firstly, a report "generator"
|
Chris@76
|
20 will fill context with relevant data. Secondly, the choice of sub-template
|
Chris@76
|
21 will determine how this data is shown to the user. It has the following
|
Chris@76
|
22 functions:
|
Chris@76
|
23
|
Chris@76
|
24 void ReportsMain()
|
Chris@76
|
25 - requires the admin_forum permission.
|
Chris@76
|
26 - loads the Reports template and language files.
|
Chris@76
|
27 - decides which type of report to generate, if this isn't passed
|
Chris@76
|
28 through the querystring it will set the report_type sub-template to
|
Chris@76
|
29 force the user to choose which type.
|
Chris@76
|
30 - when generating a report chooses which sub_template to use.
|
Chris@76
|
31 - depends on the cal_enabled setting, and many of the other cal_
|
Chris@76
|
32 settings.
|
Chris@76
|
33 - will call the relevant report generation function.
|
Chris@76
|
34 - if generating report will call finishTables before returning.
|
Chris@76
|
35 - accessed through ?action=admin;area=reports.
|
Chris@76
|
36
|
Chris@76
|
37 void xxxxxxReport()
|
Chris@76
|
38 - functions ending with "Report" are responsible for generating data
|
Chris@76
|
39 for reporting.
|
Chris@76
|
40 - they are all called from ReportsMain.
|
Chris@76
|
41 - never access the context directly, but use the data handling
|
Chris@76
|
42 functions to do so.
|
Chris@76
|
43
|
Chris@76
|
44 void newTable(string title = '', string default_value = '',
|
Chris@76
|
45 string shading = 'all', string width_normal = 'auto',
|
Chris@76
|
46 string align_normal = 'center', string width_shaded = 'auto',
|
Chris@76
|
47 string align_shaded = 'auto')
|
Chris@76
|
48 - the core of this file, it creates a new, but empty, table of data in
|
Chris@76
|
49 context, ready for filling using addData().
|
Chris@76
|
50 - takes a lot of possible attributes, these have the following effect:
|
Chris@76
|
51 + title = Title to be displayed with this data table.
|
Chris@76
|
52 + default_value = Value to be displayed if a key is missing from a
|
Chris@76
|
53 row.
|
Chris@76
|
54 + shading = Should the left, top or both (all) parts of the table
|
Chris@76
|
55 beshaded?
|
Chris@76
|
56 + width_normal = width of an unshaded column (auto means not
|
Chris@76
|
57 defined).
|
Chris@76
|
58 + align_normal = alignment of data in an unshaded column.
|
Chris@76
|
59 + width_shaded = width of a shaded column (auto means not
|
Chris@76
|
60 defined).
|
Chris@76
|
61 + align_shaded = alignment of data in a shaded column.
|
Chris@76
|
62 - fills the context variable current_table with the ID of the table
|
Chris@76
|
63 created.
|
Chris@76
|
64 - keeps track of the current table count using context variable
|
Chris@76
|
65 table_count.
|
Chris@76
|
66
|
Chris@76
|
67 void addData(array inc_data, int custom_table = null)
|
Chris@76
|
68 - adds an array of data into an existing table.
|
Chris@76
|
69 - if there are no existing tables, will create one with default
|
Chris@76
|
70 attributes.
|
Chris@76
|
71 - if custom_table isn't specified, it will use the last table created,
|
Chris@76
|
72 if it is specified and doesn't exist the function will return false.
|
Chris@76
|
73 - if a set of keys have been specified, the function will check each
|
Chris@76
|
74 required key is present in the incoming data. If this data is missing
|
Chris@76
|
75 the current tables default value will be used.
|
Chris@76
|
76 - if any key in the incoming data begins with '#sep#', the function
|
Chris@76
|
77 will add a separator accross the table at this point.
|
Chris@76
|
78 - once the incoming data has been sanitized, it is added to the table.
|
Chris@76
|
79
|
Chris@76
|
80 void addSeparator(string title = '', int custom_table = null)
|
Chris@76
|
81 - adds a separator with title given by attribute "title" after the
|
Chris@76
|
82 current row in the table.
|
Chris@76
|
83 - if there are no existing tables, will create one with default
|
Chris@76
|
84 attributes.
|
Chris@76
|
85 - if custom_table isn't specified, it will use the last table created,
|
Chris@76
|
86 if it is specified and doesn't exist the function will return false.
|
Chris@76
|
87 - if the table is currently having data added by column this may have
|
Chris@76
|
88 unpredictable visual results.
|
Chris@76
|
89
|
Chris@76
|
90 void finishTables()
|
Chris@76
|
91 - is (unfortunately) required to create some useful variables for
|
Chris@76
|
92 templates.
|
Chris@76
|
93 - foreach data table created, it will count the number of rows and
|
Chris@76
|
94 columns in the table.
|
Chris@76
|
95 - will also create a max_width variable for the table, to give an
|
Chris@76
|
96 estimate width for the whole table - if it can.
|
Chris@76
|
97
|
Chris@76
|
98 void setKeys(string method = 'rows', array keys = array(),
|
Chris@76
|
99 bool reverse = false)
|
Chris@76
|
100 - sets the current set of "keys" expected in each data array passed to
|
Chris@76
|
101 addData. It also sets the way we are adding data to the data table.
|
Chris@76
|
102 - method specifies whether the data passed to addData represents a new
|
Chris@76
|
103 column, or a new row.
|
Chris@76
|
104 - keys is an array whose keys are the keys for data being passed to
|
Chris@76
|
105 addData().
|
Chris@76
|
106 - if reverse is set to true, then the values of the variable "keys"
|
Chris@76
|
107 are used as oppossed to the keys(!)
|
Chris@76
|
108 */
|
Chris@76
|
109
|
Chris@76
|
110 // Handling function for generating reports.
|
Chris@76
|
111 function ReportsMain()
|
Chris@76
|
112 {
|
Chris@76
|
113 global $txt, $modSettings, $context, $scripturl;
|
Chris@76
|
114
|
Chris@76
|
115 // Only admins, only EVER admins!
|
Chris@76
|
116 isAllowedTo('admin_forum');
|
Chris@76
|
117
|
Chris@76
|
118 // Let's get our things running...
|
Chris@76
|
119 loadTemplate('Reports');
|
Chris@76
|
120 loadLanguage('Reports');
|
Chris@76
|
121
|
Chris@76
|
122 $context['page_title'] = $txt['generate_reports'];
|
Chris@76
|
123
|
Chris@76
|
124 // These are the types of reports which exist - and the functions to generate them.
|
Chris@76
|
125 $context['report_types'] = array(
|
Chris@76
|
126 'boards' => 'BoardReport',
|
Chris@76
|
127 'board_perms' => 'BoardPermissionsReport',
|
Chris@76
|
128 'member_groups' => 'MemberGroupsReport',
|
Chris@76
|
129 'group_perms' => 'GroupPermissionsReport',
|
Chris@76
|
130 'staff' => 'StaffReport',
|
Chris@76
|
131 );
|
Chris@76
|
132
|
Chris@76
|
133 $is_first = 0;
|
Chris@76
|
134 foreach ($context['report_types'] as $k => $temp)
|
Chris@76
|
135 $context['report_types'][$k] = array(
|
Chris@76
|
136 'id' => $k,
|
Chris@76
|
137 'title' => isset($txt['gr_type_' . $k]) ? $txt['gr_type_' . $k] : $type['id'],
|
Chris@76
|
138 'description' => isset($txt['gr_type_desc_' . $k]) ? $txt['gr_type_desc_' . $k] : null,
|
Chris@76
|
139 'function' => $temp,
|
Chris@76
|
140 'is_first' => $is_first++ == 0,
|
Chris@76
|
141 );
|
Chris@76
|
142
|
Chris@76
|
143 // If they haven't choosen a report type which is valid, send them off to the report type chooser!
|
Chris@76
|
144 if (empty($_REQUEST['rt']) || !isset($context['report_types'][$_REQUEST['rt']]))
|
Chris@76
|
145 {
|
Chris@76
|
146 $context['sub_template'] = 'report_type';
|
Chris@76
|
147 return;
|
Chris@76
|
148 }
|
Chris@76
|
149 $context['report_type'] = $_REQUEST['rt'];
|
Chris@76
|
150
|
Chris@76
|
151 // What are valid templates for showing reports?
|
Chris@76
|
152 $reportTemplates = array(
|
Chris@76
|
153 'main' => array(
|
Chris@76
|
154 'layers' => null,
|
Chris@76
|
155 ),
|
Chris@76
|
156 'print' => array(
|
Chris@76
|
157 'layers' => array('print'),
|
Chris@76
|
158 ),
|
Chris@76
|
159 );
|
Chris@76
|
160
|
Chris@76
|
161 // Specific template? Use that instead of main!
|
Chris@76
|
162 if (isset($_REQUEST['st']) && isset($reportTemplates[$_REQUEST['st']]))
|
Chris@76
|
163 {
|
Chris@76
|
164 $context['sub_template'] = $_REQUEST['st'];
|
Chris@76
|
165
|
Chris@76
|
166 // Are we disabling the other layers - print friendly for example?
|
Chris@76
|
167 if ($reportTemplates[$_REQUEST['st']]['layers'] !== null)
|
Chris@76
|
168 $context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
|
Chris@76
|
169 }
|
Chris@76
|
170
|
Chris@76
|
171 // Make the page title more descriptive.
|
Chris@76
|
172 $context['page_title'] .= ' - ' . (isset($txt['gr_type_' . $context['report_type']]) ? $txt['gr_type_' . $context['report_type']] : $context['report_type']);
|
Chris@76
|
173 // Now generate the data.
|
Chris@76
|
174 $context['report_types'][$context['report_type']]['function']();
|
Chris@76
|
175
|
Chris@76
|
176 // Finish the tables before exiting - this is to help the templates a little more.
|
Chris@76
|
177 finishTables();
|
Chris@76
|
178 }
|
Chris@76
|
179
|
Chris@76
|
180 // Standard report about what settings the boards have.
|
Chris@76
|
181 function BoardReport()
|
Chris@76
|
182 {
|
Chris@76
|
183 global $context, $txt, $sourcedir, $smcFunc;
|
Chris@76
|
184
|
Chris@76
|
185 // Load the permission profiles.
|
Chris@76
|
186 require_once($sourcedir . '/ManagePermissions.php');
|
Chris@76
|
187 loadLanguage('ManagePermissions');
|
Chris@76
|
188 loadPermissionProfiles();
|
Chris@76
|
189
|
Chris@76
|
190 // Get every moderator.
|
Chris@76
|
191 $request = $smcFunc['db_query']('', '
|
Chris@76
|
192 SELECT mods.id_board, mods.id_member, mem.real_name
|
Chris@76
|
193 FROM {db_prefix}moderators AS mods
|
Chris@76
|
194 INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)',
|
Chris@76
|
195 array(
|
Chris@76
|
196 )
|
Chris@76
|
197 );
|
Chris@76
|
198 $moderators = array();
|
Chris@76
|
199 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
200 $moderators[$row['id_board']][] = $row['real_name'];
|
Chris@76
|
201 $smcFunc['db_free_result']($request);
|
Chris@76
|
202
|
Chris@76
|
203 // Get all the possible membergroups!
|
Chris@76
|
204 $request = $smcFunc['db_query']('', '
|
Chris@76
|
205 SELECT id_group, group_name, online_color
|
Chris@76
|
206 FROM {db_prefix}membergroups',
|
Chris@76
|
207 array(
|
Chris@76
|
208 )
|
Chris@76
|
209 );
|
Chris@76
|
210 $groups = array(-1 => $txt['guest_title'], 0 => $txt['full_member']);
|
Chris@76
|
211 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
212 $groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
|
Chris@76
|
213 $smcFunc['db_free_result']($request);
|
Chris@76
|
214
|
Chris@76
|
215 // All the fields we'll show.
|
Chris@76
|
216 $boardSettings = array(
|
Chris@76
|
217 'category' => $txt['board_category'],
|
Chris@76
|
218 'parent' => $txt['board_parent'],
|
Chris@76
|
219 'num_topics' => $txt['board_num_topics'],
|
Chris@76
|
220 'num_posts' => $txt['board_num_posts'],
|
Chris@76
|
221 'count_posts' => $txt['board_count_posts'],
|
Chris@76
|
222 'theme' => $txt['board_theme'],
|
Chris@76
|
223 'override_theme' => $txt['board_override_theme'],
|
Chris@76
|
224 'profile' => $txt['board_profile'],
|
Chris@76
|
225 'moderators' => $txt['board_moderators'],
|
Chris@76
|
226 'groups' => $txt['board_groups'],
|
Chris@76
|
227 );
|
Chris@76
|
228
|
Chris@76
|
229 // Do it in columns, it's just easier.
|
Chris@76
|
230 setKeys('cols');
|
Chris@76
|
231
|
Chris@76
|
232 // Go through each board!
|
Chris@76
|
233 $request = $smcFunc['db_query']('order_by_board_order', '
|
Chris@76
|
234 SELECT b.id_board, b.name, b.num_posts, b.num_topics, b.count_posts, b.member_groups, b.override_theme, b.id_profile,
|
Chris@76
|
235 c.name AS cat_name, IFNULL(par.name, {string:text_none}) AS parent_name, IFNULL(th.value, {string:text_none}) AS theme_name
|
Chris@76
|
236 FROM {db_prefix}boards AS b
|
Chris@76
|
237 LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
|
Chris@76
|
238 LEFT JOIN {db_prefix}boards AS par ON (par.id_board = b.id_parent)
|
Chris@76
|
239 LEFT JOIN {db_prefix}themes AS th ON (th.id_theme = b.id_theme AND th.variable = {string:name})',
|
Chris@76
|
240 array(
|
Chris@76
|
241 'name' => 'name',
|
Chris@76
|
242 'text_none' => $txt['none'],
|
Chris@76
|
243 )
|
Chris@76
|
244 );
|
Chris@76
|
245 $boards = array(0 => array('name' => $txt['global_boards']));
|
Chris@76
|
246 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
247 {
|
Chris@76
|
248 // Each board has it's own table.
|
Chris@76
|
249 newTable($row['name'], '', 'left', 'auto', 'left', 200, 'left');
|
Chris@76
|
250
|
Chris@76
|
251 // First off, add in the side key.
|
Chris@76
|
252 addData($boardSettings);
|
Chris@76
|
253
|
Chris@76
|
254 // Format the profile name.
|
Chris@76
|
255 $profile_name = $context['profiles'][$row['id_profile']]['name'];
|
Chris@76
|
256
|
Chris@76
|
257 // Create the main data array.
|
Chris@76
|
258 $boardData = array(
|
Chris@76
|
259 'category' => $row['cat_name'],
|
Chris@76
|
260 'parent' => $row['parent_name'],
|
Chris@76
|
261 'num_posts' => $row['num_posts'],
|
Chris@76
|
262 'num_topics' => $row['num_topics'],
|
Chris@76
|
263 'count_posts' => empty($row['count_posts']) ? $txt['yes'] : $txt['no'],
|
Chris@76
|
264 'theme' => $row['theme_name'],
|
Chris@76
|
265 'profile' => $profile_name,
|
Chris@76
|
266 'override_theme' => $row['override_theme'] ? $txt['yes'] : $txt['no'],
|
Chris@76
|
267 'moderators' => empty($moderators[$row['id_board']]) ? $txt['none'] : implode(', ', $moderators[$row['id_board']]),
|
Chris@76
|
268 );
|
Chris@76
|
269
|
Chris@76
|
270 // Work out the membergroups who can access it.
|
Chris@76
|
271 $allowedGroups = explode(',', $row['member_groups']);
|
Chris@76
|
272 foreach ($allowedGroups as $key => $group)
|
Chris@76
|
273 {
|
Chris@76
|
274 if (isset($groups[$group]))
|
Chris@76
|
275 $allowedGroups[$key] = $groups[$group];
|
Chris@76
|
276 else
|
Chris@76
|
277 unset($allowedGroups[$key]);
|
Chris@76
|
278 }
|
Chris@76
|
279 $boardData['groups'] = implode(', ', $allowedGroups);
|
Chris@76
|
280
|
Chris@76
|
281 // Next add the main data.
|
Chris@76
|
282 addData($boardData);
|
Chris@76
|
283 }
|
Chris@76
|
284 $smcFunc['db_free_result']($request);
|
Chris@76
|
285 }
|
Chris@76
|
286
|
Chris@76
|
287 // Generate a report on the current permissions by board and membergroup.
|
Chris@76
|
288 function BoardPermissionsReport()
|
Chris@76
|
289 {
|
Chris@76
|
290 global $context, $txt, $modSettings, $smcFunc;
|
Chris@76
|
291
|
Chris@76
|
292 // Get as much memory as possible as this can be big.
|
Chris@76
|
293 @ini_set('memory_limit', '256M');
|
Chris@76
|
294
|
Chris@76
|
295 if (isset($_REQUEST['boards']))
|
Chris@76
|
296 {
|
Chris@76
|
297 if (!is_array($_REQUEST['boards']))
|
Chris@76
|
298 $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
|
Chris@76
|
299 foreach ($_REQUEST['boards'] as $k => $dummy)
|
Chris@76
|
300 $_REQUEST['boards'][$k] = (int) $dummy;
|
Chris@76
|
301
|
Chris@76
|
302 $board_clause = 'id_board IN ({array_int:boards})';
|
Chris@76
|
303 }
|
Chris@76
|
304 else
|
Chris@76
|
305 $board_clause = '1=1';
|
Chris@76
|
306
|
Chris@76
|
307 if (isset($_REQUEST['groups']))
|
Chris@76
|
308 {
|
Chris@76
|
309 if (!is_array($_REQUEST['groups']))
|
Chris@76
|
310 $_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
|
Chris@76
|
311 foreach ($_REQUEST['groups'] as $k => $dummy)
|
Chris@76
|
312 $_REQUEST['groups'][$k] = (int) $dummy;
|
Chris@76
|
313
|
Chris@76
|
314 $group_clause = 'id_group IN ({array_int:groups})';
|
Chris@76
|
315 }
|
Chris@76
|
316 else
|
Chris@76
|
317 $group_clause = '1=1';
|
Chris@76
|
318
|
Chris@76
|
319 // Fetch all the board names.
|
Chris@76
|
320 $request = $smcFunc['db_query']('', '
|
Chris@76
|
321 SELECT id_board, name, id_profile
|
Chris@76
|
322 FROM {db_prefix}boards
|
Chris@76
|
323 WHERE ' . $board_clause . '
|
Chris@76
|
324 ORDER BY id_board',
|
Chris@76
|
325 array(
|
Chris@76
|
326 'boards' => isset($_REQUEST['boards']) ? $_REQUEST['boards'] : array(),
|
Chris@76
|
327 )
|
Chris@76
|
328 );
|
Chris@76
|
329 $profiles = array();
|
Chris@76
|
330 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
331 {
|
Chris@76
|
332 $boards[$row['id_board']] = array(
|
Chris@76
|
333 'name' => $row['name'],
|
Chris@76
|
334 'profile' => $row['id_profile'],
|
Chris@76
|
335 );
|
Chris@76
|
336 $profiles[] = $row['id_profile'];
|
Chris@76
|
337 }
|
Chris@76
|
338 $smcFunc['db_free_result']($request);
|
Chris@76
|
339
|
Chris@76
|
340 // Get all the possible membergroups, except admin!
|
Chris@76
|
341 $request = $smcFunc['db_query']('', '
|
Chris@76
|
342 SELECT id_group, group_name
|
Chris@76
|
343 FROM {db_prefix}membergroups
|
Chris@76
|
344 WHERE ' . $group_clause . '
|
Chris@76
|
345 AND id_group != {int:admin_group}' . (empty($modSettings['permission_enable_postgroups']) ? '
|
Chris@76
|
346 AND min_posts = {int:min_posts}' : '') . '
|
Chris@76
|
347 ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
|
Chris@76
|
348 array(
|
Chris@76
|
349 'admin_group' => 1,
|
Chris@76
|
350 'min_posts' => -1,
|
Chris@76
|
351 'newbie_group' => 4,
|
Chris@76
|
352 'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
|
Chris@76
|
353 )
|
Chris@76
|
354 );
|
Chris@76
|
355 if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
|
Chris@76
|
356 $member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
|
Chris@76
|
357 else
|
Chris@76
|
358 $member_groups = array('col' => '');
|
Chris@76
|
359 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
360 $member_groups[$row['id_group']] = $row['group_name'];
|
Chris@76
|
361 $smcFunc['db_free_result']($request);
|
Chris@76
|
362
|
Chris@76
|
363 // Make sure that every group is represented - plus in rows!
|
Chris@76
|
364 setKeys('rows', $member_groups);
|
Chris@76
|
365
|
Chris@76
|
366 // Cache every permission setting, to make sure we don't miss any allows.
|
Chris@76
|
367 $permissions = array();
|
Chris@76
|
368 $board_permissions = array();
|
Chris@76
|
369 $request = $smcFunc['db_query']('', '
|
Chris@76
|
370 SELECT id_profile, id_group, add_deny, permission
|
Chris@76
|
371 FROM {db_prefix}board_permissions
|
Chris@76
|
372 WHERE id_profile IN ({array_int:profile_list})
|
Chris@76
|
373 AND ' . $group_clause . (empty($modSettings['permission_enable_deny']) ? '
|
Chris@76
|
374 AND add_deny = {int:not_deny}' : '') . '
|
Chris@76
|
375 ORDER BY id_profile, permission',
|
Chris@76
|
376 array(
|
Chris@76
|
377 'profile_list' => $profiles,
|
Chris@76
|
378 'not_deny' => 1,
|
Chris@76
|
379 'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
|
Chris@76
|
380 )
|
Chris@76
|
381 );
|
Chris@76
|
382 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
383 {
|
Chris@76
|
384 foreach ($boards as $id => $board)
|
Chris@76
|
385 if ($board['profile'] == $row['id_profile'])
|
Chris@76
|
386 $board_permissions[$id][$row['id_group']][$row['permission']] = $row['add_deny'];
|
Chris@76
|
387
|
Chris@76
|
388 // Make sure we get every permission.
|
Chris@76
|
389 if (!isset($permissions[$row['permission']]))
|
Chris@76
|
390 {
|
Chris@76
|
391 // This will be reused on other boards.
|
Chris@76
|
392 $permissions[$row['permission']] = array(
|
Chris@76
|
393 'title' => isset($txt['board_perms_name_' . $row['permission']]) ? $txt['board_perms_name_' . $row['permission']] : $row['permission'],
|
Chris@76
|
394 );
|
Chris@76
|
395 }
|
Chris@76
|
396 }
|
Chris@76
|
397 $smcFunc['db_free_result']($request);
|
Chris@76
|
398
|
Chris@76
|
399 // Now cycle through the board permissions array... lots to do ;)
|
Chris@76
|
400 foreach ($board_permissions as $board => $groups)
|
Chris@76
|
401 {
|
Chris@76
|
402 // Create the table for this board first.
|
Chris@76
|
403 newTable($boards[$board]['name'], 'x', 'all', 100, 'center', 200, 'left');
|
Chris@76
|
404
|
Chris@76
|
405 // Add the header row - shows all the membergroups.
|
Chris@76
|
406 addData($member_groups);
|
Chris@76
|
407
|
Chris@76
|
408 // Add the separator.
|
Chris@76
|
409 addSeparator($txt['board_perms_permission']);
|
Chris@76
|
410
|
Chris@76
|
411 // Here cycle through all the detected permissions.
|
Chris@76
|
412 foreach ($permissions as $ID_PERM => $perm_info)
|
Chris@76
|
413 {
|
Chris@76
|
414 // Is this identical to the global?
|
Chris@76
|
415 $identicalGlobal = $board == 0 ? false : true;
|
Chris@76
|
416
|
Chris@76
|
417 // Default data for this row.
|
Chris@76
|
418 $curData = array('col' => $perm_info['title']);
|
Chris@76
|
419
|
Chris@76
|
420 // Now cycle each membergroup in this set of permissions.
|
Chris@76
|
421 foreach ($member_groups as $id_group => $name)
|
Chris@76
|
422 {
|
Chris@76
|
423 // Don't overwrite the key column!
|
Chris@76
|
424 if ($id_group === 'col')
|
Chris@76
|
425 continue;
|
Chris@76
|
426
|
Chris@76
|
427 $group_permissions = isset($groups[$id_group]) ? $groups[$id_group] : array();
|
Chris@76
|
428
|
Chris@76
|
429 // Do we have any data for this group?
|
Chris@76
|
430 if (isset($group_permissions[$ID_PERM]))
|
Chris@76
|
431 {
|
Chris@76
|
432 // Set the data for this group to be the local permission.
|
Chris@76
|
433 $curData[$id_group] = $group_permissions[$ID_PERM];
|
Chris@76
|
434 }
|
Chris@76
|
435 // Otherwise means it's set to disallow..
|
Chris@76
|
436 else
|
Chris@76
|
437 {
|
Chris@76
|
438 $curData[$id_group] = 'x';
|
Chris@76
|
439 }
|
Chris@76
|
440
|
Chris@76
|
441 // Now actually make the data for the group look right.
|
Chris@76
|
442 if (empty($curData[$id_group]))
|
Chris@76
|
443 $curData[$id_group] = '<span style="color: red;">' . $txt['board_perms_deny'] . '</span>';
|
Chris@76
|
444 elseif ($curData[$id_group] == 1)
|
Chris@76
|
445 $curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
|
Chris@76
|
446 else
|
Chris@76
|
447 $curData[$id_group] = 'x';
|
Chris@76
|
448
|
Chris@76
|
449 // Embolden those permissions different from global (makes it a lot easier!)
|
Chris@76
|
450 if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM])
|
Chris@76
|
451 $curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
|
Chris@76
|
452 }
|
Chris@76
|
453
|
Chris@76
|
454 // Now add the data for this permission.
|
Chris@76
|
455 addData($curData);
|
Chris@76
|
456 }
|
Chris@76
|
457 }
|
Chris@76
|
458 }
|
Chris@76
|
459
|
Chris@76
|
460 // Show what the membergroups are made of.
|
Chris@76
|
461 function MemberGroupsReport()
|
Chris@76
|
462 {
|
Chris@76
|
463 global $context, $txt, $settings, $modSettings, $smcFunc;
|
Chris@76
|
464
|
Chris@76
|
465 // Fetch all the board names.
|
Chris@76
|
466 $request = $smcFunc['db_query']('', '
|
Chris@76
|
467 SELECT id_board, name, member_groups, id_profile
|
Chris@76
|
468 FROM {db_prefix}boards',
|
Chris@76
|
469 array(
|
Chris@76
|
470 )
|
Chris@76
|
471 );
|
Chris@76
|
472 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
473 {
|
Chris@76
|
474 if (trim($row['member_groups']) == '')
|
Chris@76
|
475 $groups = array(1);
|
Chris@76
|
476 else
|
Chris@76
|
477 $groups = array_merge(array(1), explode(',', $row['member_groups']));
|
Chris@76
|
478
|
Chris@76
|
479 $boards[$row['id_board']] = array(
|
Chris@76
|
480 'id' => $row['id_board'],
|
Chris@76
|
481 'name' => $row['name'],
|
Chris@76
|
482 'profile' => $row['id_profile'],
|
Chris@76
|
483 'groups' => $groups,
|
Chris@76
|
484 );
|
Chris@76
|
485 }
|
Chris@76
|
486 $smcFunc['db_free_result']($request);
|
Chris@76
|
487
|
Chris@76
|
488 // Standard settings.
|
Chris@76
|
489 $mgSettings = array(
|
Chris@76
|
490 'name' => '',
|
Chris@76
|
491 '#sep#1' => $txt['member_group_settings'],
|
Chris@76
|
492 'color' => $txt['member_group_color'],
|
Chris@76
|
493 'min_posts' => $txt['member_group_min_posts'],
|
Chris@76
|
494 'max_messages' => $txt['member_group_max_messages'],
|
Chris@76
|
495 'stars' => $txt['member_group_stars'],
|
Chris@76
|
496 '#sep#2' => $txt['member_group_access'],
|
Chris@76
|
497 );
|
Chris@76
|
498
|
Chris@76
|
499 // Add on the boards!
|
Chris@76
|
500 foreach ($boards as $board)
|
Chris@76
|
501 $mgSettings['board_' . $board['id']] = $board['name'];
|
Chris@76
|
502
|
Chris@76
|
503 // Add all the membergroup settings, plus we'll be adding in columns!
|
Chris@76
|
504 setKeys('cols', $mgSettings);
|
Chris@76
|
505
|
Chris@76
|
506 // Only one table this time!
|
Chris@76
|
507 newTable($txt['gr_type_member_groups'], '-', 'all', 100, 'center', 200, 'left');
|
Chris@76
|
508
|
Chris@76
|
509 // Get the shaded column in.
|
Chris@76
|
510 addData($mgSettings);
|
Chris@76
|
511
|
Chris@76
|
512 // Now start cycling the membergroups!
|
Chris@76
|
513 $request = $smcFunc['db_query']('', '
|
Chris@76
|
514 SELECT mg.id_group, mg.group_name, mg.online_color, mg.min_posts, mg.max_messages, mg.stars,
|
Chris@76
|
515 CASE WHEN bp.permission IS NOT NULL OR mg.id_group = {int:admin_group} THEN 1 ELSE 0 END AS can_moderate
|
Chris@76
|
516 FROM {db_prefix}membergroups AS mg
|
Chris@76
|
517 LEFT JOIN {db_prefix}board_permissions AS bp ON (bp.id_group = mg.id_group AND bp.id_profile = {int:default_profile} AND bp.permission = {string:moderate_board})
|
Chris@76
|
518 ORDER BY mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name',
|
Chris@76
|
519 array(
|
Chris@76
|
520 'admin_group' => 1,
|
Chris@76
|
521 'default_profile' => 1,
|
Chris@76
|
522 'newbie_group' => 4,
|
Chris@76
|
523 'moderate_board' => 'moderate_board',
|
Chris@76
|
524 )
|
Chris@76
|
525 );
|
Chris@76
|
526
|
Chris@76
|
527 // Cache them so we get regular members too.
|
Chris@76
|
528 $rows = array(
|
Chris@76
|
529 array(
|
Chris@76
|
530 'id_group' => -1,
|
Chris@76
|
531 'group_name' => $txt['membergroups_guests'],
|
Chris@76
|
532 'online_color' => '',
|
Chris@76
|
533 'min_posts' => -1,
|
Chris@76
|
534 'max_messages' => null,
|
Chris@76
|
535 'stars' => ''
|
Chris@76
|
536 ),
|
Chris@76
|
537 array(
|
Chris@76
|
538 'id_group' => 0,
|
Chris@76
|
539 'group_name' => $txt['membergroups_members'],
|
Chris@76
|
540 'online_color' => '',
|
Chris@76
|
541 'min_posts' => -1,
|
Chris@76
|
542 'max_messages' => null,
|
Chris@76
|
543 'stars' => ''
|
Chris@76
|
544 ),
|
Chris@76
|
545 );
|
Chris@76
|
546 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
547 $rows[] = $row;
|
Chris@76
|
548 $smcFunc['db_free_result']($request);
|
Chris@76
|
549
|
Chris@76
|
550 foreach ($rows as $row)
|
Chris@76
|
551 {
|
Chris@76
|
552 $row['stars'] = explode('#', $row['stars']);
|
Chris@76
|
553
|
Chris@76
|
554 $group = array(
|
Chris@76
|
555 'name' => $row['group_name'],
|
Chris@76
|
556 'color' => empty($row['online_color']) ? '-' : '<span style="color: ' . $row['online_color'] . ';">' . $row['online_color'] . '</span>',
|
Chris@76
|
557 'min_posts' => $row['min_posts'] == -1 ? 'N/A' : $row['min_posts'],
|
Chris@76
|
558 'max_messages' => $row['max_messages'],
|
Chris@76
|
559 'stars' => !empty($row['stars'][0]) && !empty($row['stars'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/' . $row['stars'][1] . '" alt="*" />', $row['stars'][0]) : '',
|
Chris@76
|
560 );
|
Chris@76
|
561
|
Chris@76
|
562 // Board permissions.
|
Chris@76
|
563 foreach ($boards as $board)
|
Chris@76
|
564 $group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>' : 'x';
|
Chris@76
|
565
|
Chris@76
|
566 addData($group);
|
Chris@76
|
567 }
|
Chris@76
|
568 }
|
Chris@76
|
569
|
Chris@76
|
570 // Show the large variety of group permissions assigned to each membergroup.
|
Chris@76
|
571 function GroupPermissionsReport()
|
Chris@76
|
572 {
|
Chris@76
|
573 global $context, $txt, $modSettings, $smcFunc;
|
Chris@76
|
574
|
Chris@76
|
575 if (isset($_REQUEST['groups']))
|
Chris@76
|
576 {
|
Chris@76
|
577 if (!is_array($_REQUEST['groups']))
|
Chris@76
|
578 $_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
|
Chris@76
|
579 foreach ($_REQUEST['groups'] as $k => $dummy)
|
Chris@76
|
580 $_REQUEST['groups'][$k] = (int) $dummy;
|
Chris@76
|
581 $_REQUEST['groups'] = array_diff($_REQUEST['groups'], array(3));
|
Chris@76
|
582
|
Chris@76
|
583 $clause = 'id_group IN ({array_int:groups})';
|
Chris@76
|
584 }
|
Chris@76
|
585 else
|
Chris@76
|
586 $clause = 'id_group != {int:moderator_group}';
|
Chris@76
|
587
|
Chris@76
|
588 // Get all the possible membergroups, except admin!
|
Chris@76
|
589 $request = $smcFunc['db_query']('', '
|
Chris@76
|
590 SELECT id_group, group_name
|
Chris@76
|
591 FROM {db_prefix}membergroups
|
Chris@76
|
592 WHERE ' . $clause . '
|
Chris@76
|
593 AND id_group != {int:admin_group}' . (empty($modSettings['permission_enable_postgroups']) ? '
|
Chris@76
|
594 AND min_posts = {int:min_posts}' : '') . '
|
Chris@76
|
595 ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
|
Chris@76
|
596 array(
|
Chris@76
|
597 'admin_group' => 1,
|
Chris@76
|
598 'min_posts' => -1,
|
Chris@76
|
599 'newbie_group' => 4,
|
Chris@76
|
600 'moderator_group' => 3,
|
Chris@76
|
601 'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
|
Chris@76
|
602 )
|
Chris@76
|
603 );
|
Chris@76
|
604 if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
|
Chris@76
|
605 $groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
|
Chris@76
|
606 else
|
Chris@76
|
607 $groups = array('col' => '');
|
Chris@76
|
608 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
609 $groups[$row['id_group']] = $row['group_name'];
|
Chris@76
|
610 $smcFunc['db_free_result']($request);
|
Chris@76
|
611
|
Chris@76
|
612 // Make sure that every group is represented!
|
Chris@76
|
613 setKeys('rows', $groups);
|
Chris@76
|
614
|
Chris@76
|
615 // Create the table first.
|
Chris@76
|
616 newTable($txt['gr_type_group_perms'], '-', 'all', 100, 'center', 200, 'left');
|
Chris@76
|
617
|
Chris@76
|
618 // Show all the groups
|
Chris@76
|
619 addData($groups);
|
Chris@76
|
620
|
Chris@76
|
621 // Add a separator
|
Chris@76
|
622 addSeparator($txt['board_perms_permission']);
|
Chris@76
|
623
|
Chris@76
|
624 // Now the big permission fetch!
|
Chris@76
|
625 $request = $smcFunc['db_query']('', '
|
Chris@76
|
626 SELECT id_group, add_deny, permission
|
Chris@76
|
627 FROM {db_prefix}permissions
|
Chris@76
|
628 WHERE ' . $clause . (empty($modSettings['permission_enable_deny']) ? '
|
Chris@76
|
629 AND add_deny = {int:not_denied}' : '') . '
|
Chris@76
|
630 ORDER BY permission',
|
Chris@76
|
631 array(
|
Chris@76
|
632 'not_denied' => 1,
|
Chris@76
|
633 'moderator_group' => 3,
|
Chris@76
|
634 'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
|
Chris@76
|
635 )
|
Chris@76
|
636 );
|
Chris@76
|
637 $lastPermission = null;
|
Chris@76
|
638 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
639 {
|
Chris@76
|
640 // If this is a new permission flush the last row.
|
Chris@76
|
641 if ($row['permission'] != $lastPermission)
|
Chris@76
|
642 {
|
Chris@76
|
643 // Send the data!
|
Chris@76
|
644 if ($lastPermission !== null)
|
Chris@76
|
645 addData($curData);
|
Chris@76
|
646
|
Chris@76
|
647 // Add the permission name in the left column.
|
Chris@76
|
648 $curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
|
Chris@76
|
649
|
Chris@76
|
650 $lastPermission = $row['permission'];
|
Chris@76
|
651 }
|
Chris@76
|
652
|
Chris@76
|
653 // Good stuff - add the permission to the list!
|
Chris@76
|
654 if ($row['add_deny'])
|
Chris@76
|
655 $curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
|
Chris@76
|
656 else
|
Chris@76
|
657 $curData[$row['id_group']] = '<span style="color: red;">' . $txt['board_perms_deny'] . '</span>';
|
Chris@76
|
658 }
|
Chris@76
|
659 $smcFunc['db_free_result']($request);
|
Chris@76
|
660
|
Chris@76
|
661 // Flush the last data!
|
Chris@76
|
662 addData($curData);
|
Chris@76
|
663 }
|
Chris@76
|
664
|
Chris@76
|
665 // Report for showing all the forum staff members - quite a feat!
|
Chris@76
|
666 function StaffReport()
|
Chris@76
|
667 {
|
Chris@76
|
668 global $sourcedir, $context, $txt, $smcFunc;
|
Chris@76
|
669
|
Chris@76
|
670 require_once($sourcedir . '/Subs-Members.php');
|
Chris@76
|
671
|
Chris@76
|
672 // Fetch all the board names.
|
Chris@76
|
673 $request = $smcFunc['db_query']('', '
|
Chris@76
|
674 SELECT id_board, name
|
Chris@76
|
675 FROM {db_prefix}boards',
|
Chris@76
|
676 array(
|
Chris@76
|
677 )
|
Chris@76
|
678 );
|
Chris@76
|
679 $boards = array();
|
Chris@76
|
680 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
681 $boards[$row['id_board']] = $row['name'];
|
Chris@76
|
682 $smcFunc['db_free_result']($request);
|
Chris@76
|
683
|
Chris@76
|
684 // Get every moderator.
|
Chris@76
|
685 $request = $smcFunc['db_query']('', '
|
Chris@76
|
686 SELECT mods.id_board, mods.id_member
|
Chris@76
|
687 FROM {db_prefix}moderators AS mods',
|
Chris@76
|
688 array(
|
Chris@76
|
689 )
|
Chris@76
|
690 );
|
Chris@76
|
691 $moderators = array();
|
Chris@76
|
692 $local_mods = array();
|
Chris@76
|
693 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
694 {
|
Chris@76
|
695 $moderators[$row['id_member']][] = $row['id_board'];
|
Chris@76
|
696 $local_mods[$row['id_member']] = $row['id_member'];
|
Chris@76
|
697 }
|
Chris@76
|
698 $smcFunc['db_free_result']($request);
|
Chris@76
|
699
|
Chris@76
|
700 // Get a list of global moderators (i.e. members with moderation powers).
|
Chris@76
|
701 $global_mods = array_intersect(membersAllowedTo('moderate_board', 0), membersAllowedTo('approve_posts', 0), membersAllowedTo('remove_any', 0), membersAllowedTo('modify_any', 0));
|
Chris@76
|
702
|
Chris@76
|
703 // How about anyone else who is special?
|
Chris@76
|
704 $allStaff = array_merge(membersAllowedTo('admin_forum'), membersAllowedTo('manage_membergroups'), membersAllowedTo('manage_permissions'), $local_mods, $global_mods);
|
Chris@76
|
705
|
Chris@76
|
706 // Make sure everyone is there once - no admin less important than any other!
|
Chris@76
|
707 $allStaff = array_unique($allStaff);
|
Chris@76
|
708
|
Chris@76
|
709 // This is a bit of a cop out - but we're protecting their forum, really!
|
Chris@76
|
710 if (count($allStaff) > 300)
|
Chris@76
|
711 fatal_lang_error('report_error_too_many_staff');
|
Chris@76
|
712
|
Chris@76
|
713 // Get all the possible membergroups!
|
Chris@76
|
714 $request = $smcFunc['db_query']('', '
|
Chris@76
|
715 SELECT id_group, group_name, online_color
|
Chris@76
|
716 FROM {db_prefix}membergroups',
|
Chris@76
|
717 array(
|
Chris@76
|
718 )
|
Chris@76
|
719 );
|
Chris@76
|
720 $groups = array(0 => $txt['full_member']);
|
Chris@76
|
721 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
722 $groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
|
Chris@76
|
723 $smcFunc['db_free_result']($request);
|
Chris@76
|
724
|
Chris@76
|
725 // All the fields we'll show.
|
Chris@76
|
726 $staffSettings = array(
|
Chris@76
|
727 'position' => $txt['report_staff_position'],
|
Chris@76
|
728 'moderates' => $txt['report_staff_moderates'],
|
Chris@76
|
729 'posts' => $txt['report_staff_posts'],
|
Chris@76
|
730 'last_login' => $txt['report_staff_last_login'],
|
Chris@76
|
731 );
|
Chris@76
|
732
|
Chris@76
|
733 // Do it in columns, it's just easier.
|
Chris@76
|
734 setKeys('cols');
|
Chris@76
|
735
|
Chris@76
|
736 // Get each member!
|
Chris@76
|
737 $request = $smcFunc['db_query']('', '
|
Chris@76
|
738 SELECT id_member, real_name, id_group, posts, last_login
|
Chris@76
|
739 FROM {db_prefix}members
|
Chris@76
|
740 WHERE id_member IN ({array_int:staff_list})
|
Chris@76
|
741 ORDER BY real_name',
|
Chris@76
|
742 array(
|
Chris@76
|
743 'staff_list' => $allStaff,
|
Chris@76
|
744 )
|
Chris@76
|
745 );
|
Chris@76
|
746 while ($row = $smcFunc['db_fetch_assoc']($request))
|
Chris@76
|
747 {
|
Chris@76
|
748 // Each member gets their own table!.
|
Chris@76
|
749 newTable($row['real_name'], '', 'left', 'auto', 'left', 200, 'center');
|
Chris@76
|
750
|
Chris@76
|
751 // First off, add in the side key.
|
Chris@76
|
752 addData($staffSettings);
|
Chris@76
|
753
|
Chris@76
|
754 // Create the main data array.
|
Chris@76
|
755 $staffData = array(
|
Chris@76
|
756 'position' => isset($groups[$row['id_group']]) ? $groups[$row['id_group']] : $groups[0],
|
Chris@76
|
757 'posts' => $row['posts'],
|
Chris@76
|
758 'last_login' => timeformat($row['last_login']),
|
Chris@76
|
759 'moderates' => array(),
|
Chris@76
|
760 );
|
Chris@76
|
761
|
Chris@76
|
762 // What do they moderate?
|
Chris@76
|
763 if (in_array($row['id_member'], $global_mods))
|
Chris@76
|
764 $staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
|
Chris@76
|
765 elseif (isset($moderators[$row['id_member']]))
|
Chris@76
|
766 {
|
Chris@76
|
767 // Get the names
|
Chris@76
|
768 foreach ($moderators[$row['id_member']] as $board)
|
Chris@76
|
769 if (isset($boards[$board]))
|
Chris@76
|
770 $staffData['moderates'][] = $boards[$board];
|
Chris@76
|
771
|
Chris@76
|
772 $staffData['moderates'] = implode(', ', $staffData['moderates']);
|
Chris@76
|
773 }
|
Chris@76
|
774 else
|
Chris@76
|
775 $staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
|
Chris@76
|
776
|
Chris@76
|
777 // Next add the main data.
|
Chris@76
|
778 addData($staffData);
|
Chris@76
|
779 }
|
Chris@76
|
780 $smcFunc['db_free_result']($request);
|
Chris@76
|
781 }
|
Chris@76
|
782
|
Chris@76
|
783 // This function creates a new table of data, most functions will only use it once.
|
Chris@76
|
784 function newTable($title = '', $default_value = '', $shading = 'all', $width_normal = 'auto', $align_normal = 'center', $width_shaded = 'auto', $align_shaded = 'auto')
|
Chris@76
|
785 {
|
Chris@76
|
786 global $context;
|
Chris@76
|
787
|
Chris@76
|
788 // Set the table count if needed.
|
Chris@76
|
789 if (empty($context['table_count']))
|
Chris@76
|
790 $context['table_count'] = 0;
|
Chris@76
|
791
|
Chris@76
|
792 // Create the table!
|
Chris@76
|
793 $context['tables'][$context['table_count']] = array(
|
Chris@76
|
794 'title' => $title,
|
Chris@76
|
795 'default_value' => $default_value,
|
Chris@76
|
796 'shading' => array(
|
Chris@76
|
797 'left' => $shading == 'all' || $shading == 'left',
|
Chris@76
|
798 'top' => $shading == 'all' || $shading == 'top',
|
Chris@76
|
799 ),
|
Chris@76
|
800 'width' => array(
|
Chris@76
|
801 'normal' => $width_normal,
|
Chris@76
|
802 'shaded' => $width_shaded,
|
Chris@76
|
803 ),
|
Chris@76
|
804 'align' => array(
|
Chris@76
|
805 'normal' => $align_normal,
|
Chris@76
|
806 'shaded' => $align_shaded,
|
Chris@76
|
807 ),
|
Chris@76
|
808 'data' => array(),
|
Chris@76
|
809 );
|
Chris@76
|
810
|
Chris@76
|
811 $context['current_table'] = $context['table_count'];
|
Chris@76
|
812
|
Chris@76
|
813 // Increment the count...
|
Chris@76
|
814 $context['table_count']++;
|
Chris@76
|
815 }
|
Chris@76
|
816
|
Chris@76
|
817 // Add an extra slice of data to the table
|
Chris@76
|
818 function addData($inc_data, $custom_table = null)
|
Chris@76
|
819 {
|
Chris@76
|
820 global $context;
|
Chris@76
|
821
|
Chris@76
|
822 // No tables? Create one even though we are probably already in a bad state!
|
Chris@76
|
823 if (empty($context['table_count']))
|
Chris@76
|
824 newTable();
|
Chris@76
|
825
|
Chris@76
|
826 // Specific table?
|
Chris@76
|
827 if ($custom_table !== null && !isset($context['tables'][$custom_table]))
|
Chris@76
|
828 return false;
|
Chris@76
|
829 elseif ($custom_table !== null)
|
Chris@76
|
830 $table = $custom_table;
|
Chris@76
|
831 else
|
Chris@76
|
832 $table = $context['current_table'];
|
Chris@76
|
833
|
Chris@76
|
834 // If we have keys, sanitise the data...
|
Chris@76
|
835 if (!empty($context['keys']))
|
Chris@76
|
836 {
|
Chris@76
|
837 // Basically, check every key exists!
|
Chris@76
|
838 foreach ($context['keys'] as $key => $dummy)
|
Chris@76
|
839 {
|
Chris@76
|
840 $data[$key] = array(
|
Chris@76
|
841 'v' => empty($inc_data[$key]) ? $context['tables'][$table]['default_value'] : $inc_data[$key],
|
Chris@76
|
842 );
|
Chris@76
|
843 // Special "hack" the adding separators when doing data by column.
|
Chris@76
|
844 if (substr($key, 0, 5) == '#sep#')
|
Chris@76
|
845 $data[$key]['separator'] = true;
|
Chris@76
|
846 }
|
Chris@76
|
847 }
|
Chris@76
|
848 else
|
Chris@76
|
849 {
|
Chris@76
|
850 $data = $inc_data;
|
Chris@76
|
851 foreach ($data as $key => $value)
|
Chris@76
|
852 {
|
Chris@76
|
853 $data[$key] = array(
|
Chris@76
|
854 'v' => $value,
|
Chris@76
|
855 );
|
Chris@76
|
856 if (substr($key, 0, 5) == '#sep#')
|
Chris@76
|
857 $data[$key]['separator'] = true;
|
Chris@76
|
858 }
|
Chris@76
|
859 }
|
Chris@76
|
860
|
Chris@76
|
861 // Is it by row?
|
Chris@76
|
862 if (empty($context['key_method']) || $context['key_method'] == 'rows')
|
Chris@76
|
863 {
|
Chris@76
|
864 // Add the data!
|
Chris@76
|
865 $context['tables'][$table]['data'][] = $data;
|
Chris@76
|
866 }
|
Chris@76
|
867 // Otherwise, tricky!
|
Chris@76
|
868 else
|
Chris@76
|
869 {
|
Chris@76
|
870 foreach ($data as $key => $item)
|
Chris@76
|
871 $context['tables'][$table]['data'][$key][] = $item;
|
Chris@76
|
872 }
|
Chris@76
|
873 }
|
Chris@76
|
874
|
Chris@76
|
875 // Add a separator row, only really used when adding data by rows.
|
Chris@76
|
876 function addSeparator($title = '', $custom_table = null)
|
Chris@76
|
877 {
|
Chris@76
|
878 global $context;
|
Chris@76
|
879
|
Chris@76
|
880 // No tables - return?
|
Chris@76
|
881 if (empty($context['table_count']))
|
Chris@76
|
882 return;
|
Chris@76
|
883
|
Chris@76
|
884 // Specific table?
|
Chris@76
|
885 if ($custom_table !== null && !isset($context['tables'][$table]))
|
Chris@76
|
886 return false;
|
Chris@76
|
887 elseif ($custom_table !== null)
|
Chris@76
|
888 $table = $custom_table;
|
Chris@76
|
889 else
|
Chris@76
|
890 $table = $context['current_table'];
|
Chris@76
|
891
|
Chris@76
|
892 // Plumb in the separator
|
Chris@76
|
893 $context['tables'][$table]['data'][] = array(0 => array(
|
Chris@76
|
894 'separator' => true,
|
Chris@76
|
895 'v' => $title
|
Chris@76
|
896 ));
|
Chris@76
|
897 }
|
Chris@76
|
898
|
Chris@76
|
899 // This does the necessary count of table data before displaying them.
|
Chris@76
|
900 function finishTables()
|
Chris@76
|
901 {
|
Chris@76
|
902 global $context;
|
Chris@76
|
903
|
Chris@76
|
904 if (empty($context['tables']))
|
Chris@76
|
905 return;
|
Chris@76
|
906
|
Chris@76
|
907 // Loop through each table counting up some basic values, to help with the templating.
|
Chris@76
|
908 foreach ($context['tables'] as $id => $table)
|
Chris@76
|
909 {
|
Chris@76
|
910 $context['tables'][$id]['id'] = $id;
|
Chris@76
|
911 $context['tables'][$id]['row_count'] = count($table['data']);
|
Chris@76
|
912 $curElement = current($table['data']);
|
Chris@76
|
913 $context['tables'][$id]['column_count'] = count($curElement);
|
Chris@76
|
914
|
Chris@76
|
915 // Work out the rough width - for templates like the print template. Without this we might get funny tables.
|
Chris@76
|
916 if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto')
|
Chris@76
|
917 $context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
|
Chris@76
|
918 elseif ($table['width']['normal'] != 'auto')
|
Chris@76
|
919 $context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
|
Chris@76
|
920 else
|
Chris@76
|
921 $context['tables'][$id]['max_width'] = 'auto';
|
Chris@76
|
922 }
|
Chris@76
|
923 }
|
Chris@76
|
924
|
Chris@76
|
925 // Set the keys in use by the tables - these ensure entries MUST exist if the data isn't sent.
|
Chris@76
|
926 function setKeys($method = 'rows', $keys = array(), $reverse = false)
|
Chris@76
|
927 {
|
Chris@76
|
928 global $context;
|
Chris@76
|
929
|
Chris@76
|
930 // Do we want to use the keys of the keys as the keys? :P
|
Chris@76
|
931 if ($reverse)
|
Chris@76
|
932 $context['keys'] = array_flip($keys);
|
Chris@76
|
933 else
|
Chris@76
|
934 $context['keys'] = $keys;
|
Chris@76
|
935
|
Chris@76
|
936 // Rows or columns?
|
Chris@76
|
937 $context['key_method'] = $method == 'rows' ? 'rows' : 'cols';
|
Chris@76
|
938 }
|
Chris@76
|
939
|
Chris@76
|
940 ?> |