r1498: In construct_custom_fields() and process_custom_fields(), change the query...
[bugdar.git] / includes / functions.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 // ###################################################################
23 /**
24 * Constructs HTML code <select>s from an array. You use they keys when
25 * you need to access a multi-dimensional array of data.
26 *
27 * @access public
28 *
29 * @param string HTML name of the select
30 * @param array Array of <option>s
31 * @param integer ID of the selected item, 0 for none
32 * @param string Name of the index where values are stored in the $array
33 * @param string Name of the iddex where the labels are stored in $array
34 * @param bool Value of the blank option, FALSE turns it off
35 * @param bool Construct a multiple-selection <select> menu and append "[]" to the end of the name
36 *
37 * @return string Constructed HTML output
38 */
39 function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false, $multiple = false)
40 {
41 global $bugsys;
42
43 if ($multiple)
44 {
45 $selected = explode(',', $selected);
46 }
47
48 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
49 if ($includenil !== false)
50 {
51 $opts[] = '<option value="' . $includenil . '"' . ((!$selected OR (is_array($selected) AND in_array($includenil, $selected))) ? ' selected="selected"' : '') . '> ---------</option>';
52 }
53 foreach ($array AS $value => $label)
54 {
55 $newval = ($valuekey ? $label["$valuekey"] : $value);
56 $newlab = ($labelkey ? $label["$labelkey"] : $label);
57 $opts[] = '<option value="' . $newval . '"' . (($selected == $newval OR (is_array($selected) AND in_array($newval, $selected))) ? ' selected="selected"' : '') . '>' . $newlab . '</option>';
58 }
59 return '<select class="input" name="' . $name . ($multiple ? '[]' : '') . '"' . ($multiple ? ' multiple="multiple" size="' . (sizeof($array) < 8 ? sizeof($array) + 1 : 8) . '"' : '') . '>' . implode("\n\t", $opts) . "\r</select>";
60 }
61
62 // ################### Start construct_user_display ##################
63 // $userinfo needs userid, email, displayname, and showemail
64 function construct_user_display($userinfo, $html = true)
65 {
66 global $bugsys;
67
68 if (!$userinfo['userid'])
69 {
70 $userinfo['displayname'] = _('Guest');
71 $userinfo['showemail'] = false;
72 }
73
74 if ($html)
75 {
76 eval('$username = "' . $bugsys->template->fetch('username_display') . '";');
77 }
78 else
79 {
80 if ($userinfo['showemail'])
81 {
82 $username = sprintf(_('%1$s &lt;%2$s&gt;'), $userinfo['displayname'], $userinfo['email']);
83 }
84 else
85 {
86 $username = $userinfo['displayname'];
87 }
88 }
89
90 return $username;
91 }
92
93 // ######################## Start can_perform ########################
94 // short-hand for bitwise &
95 function can_perform($bitmask, $productid = 0, $userinfo = null)
96 {
97 global $bugsys;
98
99 // masks that aren't product-specific
100 static $inspecific = array(
101 'cansearch',
102 'canbeassignedto',
103 'canadminpanel',
104 'canadminbugs',
105 'canadminfields',
106 'canadminversions',
107 'canadminusers',
108 'canadmingroups',
109 'canadmintools'
110 );
111
112 if ($userinfo == null)
113 {
114 $userinfo =& $bugsys->userinfo;
115 }
116
117 $permissions =& $bugsys->datastore['permission'];
118
119 if (!isset($bugsys->permissions["$bitmask"]))
120 {
121 trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING);
122 }
123
124 if (!$userinfo['permissions'])
125 {
126 $userinfo['permissions'] = FetchUserPermissions($userinfo);
127 }
128
129 if ($productid AND !in_array($bitmask, $inspecific))
130 {
131 $verdict = (isset($permissions["$userinfo[usergroupid]"]["$productid"]) ? ($permissions["$userinfo[usergroupid]"]["$productid"] & $bugsys->permissions["$bitmask"]) : ($userinfo['permissions'] & $bugsys->permissions["$bitmask"]));
132
133 foreach ($userinfo['groupids'] AS $group)
134 {
135 if (isset($permissions["$group"]["$productid"]))
136 {
137 $verdict |= ($permissions["$group"]["$productid"] & $bugsys->permissions["$bitmask"]);
138 }
139 }
140 $bugsys->debug("verdict* on can_perform($bitmask, $productid, $userinfo[userid]) = $verdict");
141 return $verdict;
142 }
143
144 $bugsys->debug("verdict on can_perform($bitmask, $productid, $userinfo[userid]) = " . ($userinfo['permissions'] & $bugsys->permissions["$bitmask"]));
145 return ($userinfo['permissions'] & $bugsys->permissions["$bitmask"]);
146 }
147
148 // ###################################################################
149 /**
150 * Runs through a given datastore item and creates a series of <select>
151 * options.
152 *
153 * @access public
154 *
155 * @param string Datastore name
156 * @param string Array index for the label
157 * @param string Array index for the value
158 * @param mixed The selected value(s)
159 * @param bool Include a blank option? TRUE will set a null value, FALSE turns it off, anything else is used as the value for the blank option
160 * @param bool Generate it using admin printers?
161 *
162 * @return string Unelss in admin mode, returns the constructed options
163 */
164 function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false, $adminmode = false)
165 {
166 global $bugsys;
167
168 if ($adminmode)
169 {
170 global $admin;
171 }
172
173 $select = '';
174
175 if ($includeblank === true OR $includeblank !== false)
176 {
177 $newval = ($inclueblank === true ? '' : $includeblank);
178 if ($adminmode)
179 {
180 $admin->list_item('', '', ((!$selectedvalue OR (is_array($selectedvalue) AND in_array($newval, $selectedvalue))) ? true : false));
181 }
182 else
183 {
184 $label = '';
185 $value = $newval;
186 $selected = ((!$selectedvalue OR (is_array($selectedvalue) AND in_array($newval, $selectedvalue))) ? true : false);
187 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
188 }
189 }
190
191 foreach ($bugsys->datastore["$datastore"] AS $item)
192 {
193 $label = $item["$labelname"];
194 $value = $item["$valuename"];
195 $selected = (($value == $selectedvalue OR (is_array($selectedvalue) AND in_array($value, $selectedvalue))) ? true : false);
196
197 if ($adminmode)
198 {
199 $admin->list_item($label, $value, $selected);
200 }
201 else
202 {
203 eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
204 }
205 }
206
207 if (!$adminmode)
208 {
209 return $select;
210 }
211 }
212
213 // ################## Start construct_custom_fields ##################
214 function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefault = false, $searchMode = false)
215 {
216 global $bugsys;
217 static $fields;
218
219 if (!is_array($fields))
220 {
221 $fields = array();
222 $fields_fetch = $bugsys->db->query("
223 SELECT bugfield.*, MAX(permission.mask) AS mask
224 FROM " . TABLE_PREFIX . "bugfield AS bugfield
225 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
226 ON (bugfield.fieldid = permission.fieldid)
227 WHERE (permission.mask = 2 OR permission.mask = 1)
228 AND permission.usergroupid IN ({$bugsys->userinfo['usergroupid']}" . (sizeof($bugsys->userinfo['groupids']) != 0 ? ',' . implode(',', $bugsys->userinfo['groupids']) : '') . ")
229 GROUP BY (bugfield.fieldid)
230 ");
231 while ($field = $bugsys->db->fetch_array($fields_fetch))
232 {
233 $fields["$field[fieldid]"] = $field;
234 }
235 }
236
237 $fieldbits = array();
238
239 foreach ($fields AS $field)
240 {
241 if ($nodefault)
242 {
243 $field['defaultvalue'] = '';
244 }
245
246 if (!is_null($bug["custom$field[fieldid]"]))
247 {
248 $bugsys->debug("not null: $field[fieldid]");
249 $value = $bug["custom$field[fieldid]"];
250 }
251 else
252 {
253 $value = $field['defaultvalue'];
254 }
255
256 if ($ignore21mask AND $field['mask'] != 0)
257 {
258 $field['mask'] = 2;
259 }
260
261 if ($field['mask'] == 2)
262 {
263 switch ($field['type'])
264 {
265 case 'input_text':
266 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_text') . '";');
267 break;
268
269 case 'input_checkbox':
270 $selected = ($value ? ' checked="checked"' : '');
271 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_checkbox') . '";');
272 break;
273
274 case 'select_single':
275 $selects = unserialize($field['selects']);
276 $value = trim($value);
277
278 $options = '';
279
280 $id = -1;
281 $select = '';
282 if (!$field['usedefault'] AND !trim($value))
283 {
284 $selected = ' selected="selected"';
285 }
286 else
287 {
288 $selected = '';
289 }
290 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
291
292 foreach ($selects AS $id => $select)
293 {
294 $selected = '';
295 $select = stripslashes(trim($select));
296 if ($select == $value)
297 {
298 $selected = ' selected="selected"';
299 }
300 else if ($field['usedefault'] AND $id == 0)
301 {
302 $selected = ' selected="selected"';
303 }
304 eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
305 }
306 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";');
307 break;
308 }
309 }
310 else
311 {
312 $bugsys->debug('mask 1 processing');
313 if (is_null($bug["custom$field[fieldid]"]))
314 {
315 $bugsys->debug("is null: $field[fieldid]");
316 if ($field['type'] == 'select_single')
317 {
318 if ($field['usedefault'])
319 {
320 $temp = unserialize($field['selects']);
321 $value = trim($temp[0]);
322 }
323 else
324 {
325 $value = $bug["custom$field[fieldid]"];
326 }
327 }
328 else
329 {
330 $value = $field['defaultvalue'];
331 }
332 }
333 else
334 {
335 $value = $bug["custom$field[fieldid]"];
336 }
337
338 if ($field['type'] == 'input_checkbox')
339 {
340 $value = ($value ? 'True' : 'False');
341 }
342 $field['value'] = $value;
343 eval('$tempfield = "' . $bugsys->template->fetch('bugfield_static_text') . '";');
344 }
345 $fieldbits[] = $tempfield;
346 }
347
348 return $fieldbits;
349 }
350
351 // ###################################################################
352 /**
353 * This takes the bug API object and input data and then sanitizes, verifies,
354 * and processes the data for custom fields. If there are any errors,
355 * they are passed to the message reporter.
356 *
357 * @param object A BugAPI object
358 * @param object MessageReporter object
359 * @param bool If there are errors, add them to an errorbox format? If not, then display-on-encounter
360 * @param bool Search mode: don't change certain fields when they're 0 or empty
361 *
362 * @return mixed NULL if an ID is passed, string if bugid is NULL
363 */
364 function process_custom_fields(&$bugapi, &$msg, $errorbox = false, $searchMode = false)
365 {
366 global $bugsys;
367
368 if (!$inputdata)
369 {
370 $inputdata =& $bugsys->in;
371 }
372
373 $fields = $bugsys->db->query("
374 SELECT bugfield.*, MAX(permission.mask) AS mask
375 FROM " . TABLE_PREFIX . "bugfield AS bugfield
376 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
377 ON (bugfield.fieldid = permission.fieldid)
378 WHERE permission.mask = 2
379 AND permission.usergroupid IN ({$bugsys->userinfo['usergroupid']}" . (sizeof($bugsys->userinfo['groupids']) != 0 ? ',' . implode(',', $bugsys->userinfo['groupids']) : '') . ")
380 GROUP BY (bugfield.fieldid)
381 ");
382 while ($field = $bugsys->db->fetch_array($fields))
383 {
384 $fieldname = "custom$field[fieldid]";
385
386 if ($field['type'] == 'input_checkbox')
387 {
388 if ($searchMode AND intval($inputdata["$fieldname"]) == 0)
389 {
390 continue;
391 }
392 $bugapi->set($fieldname, intval($inputdata["$fieldname"]));
393 continue;
394 }
395
396 // field data wasn't passed, so skip it
397 if (!isset($inputdata["$fieldname"]))
398 {
399 continue;
400 }
401
402 if ($field['required'] AND empty($inputdata["$fieldname"]) AND !$searchMode)
403 {
404 $errorlist[] = sprintf(_('The field "%1$s" is a required.'), $field['name']);
405 continue;
406 }
407
408 if (!empty($field['regexmatch']))
409 {
410 if (!preg_match('#' . str_replace('#', '\#', $field['regexmatch']) . '#si', $inputdata["$fieldname"]))
411 {
412 $errorlist[] = sprintf(_('%1$s does not match the specified format'), $field['name']);
413 continue;
414 }
415 }
416
417 if (isset($inputdata["$fieldname"]))
418 {
419 if ($field['type'] == 'input_text')
420 {
421 if (empty($inputdata["$fieldname"]) AND $searchMode)
422 {
423 continue;
424 }
425 $bugapi->set($fieldname, $inputdata["$fieldname"]);
426 }
427 else
428 {
429 if ($inputdata["$fieldname"] == -1)
430 {
431 if (!$searchMode)
432 {
433 $bugapi->set($fieldname, '');
434 }
435 continue;
436 }
437
438 $temp = unserialize($field['selects']);
439 $bugapi->set($fieldname, trim($temp[ intval($inputdata["$fieldname"]) ]));;
440 }
441 }
442 }
443
444 if ($errorlist)
445 {
446 if ($errorbox)
447 {
448 foreach ($errorlist AS $err)
449 {
450 $msg->addError($err);
451 }
452 }
453 else
454 {
455 $msg->error($errorlist[0]);
456 }
457 }
458 }
459
460 // ####################### Start fetch_on_bits #######################
461 function fetch_on_bits($mask, $userinfo = null)
462 {
463 global $bugsys;
464
465 if ($userinfo == null)
466 {
467 $userinfo =& $bugsys->userinfo;
468 }
469
470 $onbits = array();
471
472 $usergroupid = $userinfo['usergroupid'];
473
474 if ($bugsys->datastore['usergroup']["$usergroupid"]['permissions'] & $bugsys->permissions["$mask"] AND is_array($bugsys->datastore['product']))
475 {
476 foreach ($bugsys->datastore['product'] AS $id => $product)
477 {
478 $onbits["$id"] = $id;
479 }
480 }
481
482 if (is_array($bugsys->datastore['permission']["$usergroupid"]))
483 {
484 foreach ($bugsys->datastore['permission']["$usergroupid"] AS $productid => $bit)
485 {
486 if ($bit & $bugsys->permissions["$mask"])
487 {
488 $onbits["$productid"] = $productid;
489 }
490 else
491 {
492 if ($onbits["$productid"])
493 {
494 unset($onbits["$productid"]);
495 }
496 }
497 }
498 }
499
500 if (sizeof($onbits) < 1)
501 {
502 $onbits = array(0);
503 }
504
505 return implode(',', $onbits);
506 }
507
508 // #################### Start isso_pre_parse_hook ####################
509 // the pre-parse hook for ISSO's template engine
510 function isso_pre_parse_hook($template)
511 {
512 $template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
513 return $template;
514 }
515
516 // ###################### Start fetch_help_link ######################
517 // returns a prepared link to insert into templates that opens up a
518 // help popup in the user-end
519 function fetch_help_link($topic)
520 {
521 global $bugsys;
522
523 if (isset($bugsys->datastore['help']["$topic"]))
524 {
525 eval('$temp = "' . $bugsys->template->fetch('help_link') . '";');
526 return $temp;
527 }
528 else
529 {
530 if ($bugsys->debug)
531 {
532 return "[[INVALID TOPIC: $topic]]";
533 }
534 // do we want this?
535 else if (null == 1)
536 {
537 return eval('$temp = "' . $bugsys->template->fetch('help_link') . '";');
538 }
539 }
540 }
541
542 // ###################################################################
543 /**
544 * Returns a user array of information that is specific to all visiting
545 * users (guests). This can then be passed to any function that requires
546 * user information.
547 *
548 * @access public
549 *
550 * @return array User information array
551 */
552 function fetch_guest_user()
553 {
554 global $bugsys;
555
556 return array(
557 'usergroupid' => 1,
558 'groupids' => array(),
559 'userid' => 0,
560 'email' => '',
561 'displayname' => '',
562 'showcolors' => 1,
563 'permissions' => $bugsys->datastore['usergroup'][1]['permissions'],
564 'displaytitle' => $bugsys->datastore['usergroup'][1]['displaytitle'],
565 'timezone' => $bugsys->options['defaulttimezone']
566 );
567 }
568
569 // ###################################################################
570 /**
571 * Does an exhaustive permissions check on the bug. It checks for hidden
572 * bug status and ability to view hidden bugs. This normally was done
573 * at the top of each page, but it got so big, it was moved to a function.
574 *
575 * @access public
576 *
577 * @param array Bug array
578 * @param array Alternate user array
579 *
580 * @return bool Does the user have permission
581 */
582 function check_bug_permissions($bug, $userinfo = null)
583 {
584 global $bugsys;
585 if ($userinfo == null)
586 {
587 $userinfo = $bugsys->userinfo;
588 }
589
590 $bugsys->debug("checking permissions for $userinfo[userid] on bug $bug[bugid]");
591
592 $bugsys->debug('*** START VERBOSE CHECK ***');
593
594 $bugsys->debug('* !can_perform(canviewbugs, $bug[product], $userinfo) = ' . (int)(!can_perform('canviewbugs', $bug['product'], $userinfo)));
595 $bugsys->debug('* $bug[hidden] = ' . (int)$bug['hidden']);
596 $bugsys->debug('* $userinfo[userid] (' . $userinfo['userid'] . ') == $bug[userid] (' . $bug['userid'] . ') = ' . (int)($userinfo['userid'] == $bug['userid']));
597 $bugsys->debug('* can_perform(canviewownhidden, $bug[product], $userinfo) = ' . (int)(!!can_perform('canviewownhidden', $bug['product'], $userinfo)));
598 $bugsys->debug('* can_perform(canviewhidden, $bug[product], $userinfo) = ' . (int)(!!can_perform('canviewhidden', $bug['product'], $userinfo)));
599 $bugsys->debug('* !$bug[hidden] = ' . (int)(!$bug['hidden']));
600
601 $bugsys->debug('*** END PERMISSIONS CHECK ***');
602
603 if
604 (
605 !can_perform('canviewbugs', $bug['product'], $userinfo)
606 OR
607 !(
608 (
609 $bug['hidden']
610 AND
611 (A
612 ($userinfo['userid'] == $bug['userid'] AND can_perform('canviewownhidden', $bug['product'], $userinfo))
613 OR
614 can_perform('canviewhidden', $bug['product'], $userinfo)
615 )
616 )
617 OR
618 !$bug['hidden']
619 )
620 )
621 {
622 $bugsys->debug('*** DONE WITH REAL CALLS ***');
623 return false;
624 }
625
626 $bugsys->debug('*** DONE WITH REAL CALLS ***');
627
628 return true;
629 }
630
631 // ###################################################################
632 /**
633 * Takes an array of bug information and returns another array with
634 * information that is suitable for display as all the IDs have been
635 * replaced by their string equivalents
636 *
637 * @param array Unprocessed bug data
638 * @param string Color to display if the user has opted to not show status colours
639 *
640 * @param array Bug array with data fit for display
641 */
642 function ProcessBugDataForDisplay($bug, $color = '')
643 {
644 global $bugsys;
645
646 $bug['hiddendisplay'] = ($bug['hidden'] AND (can_perform('canviewhidden', $bug['product']) OR (can_perform('canviewownhidden') AND $bug['userid'] == $bugsys->userinfo['userid'])));
647
648 $bug['bgcolor'] = ($bugsys->userinfo['showcolors'] ? $bugsys->datastore['status']["$bug[status]"]['color'] : $color);
649 $bug['product'] = $bugsys->datastore['product']["$bug[product]"]['title'];
650 $bug['version'] = $bugsys->datastore['version']["$bug[version]"]['version'];
651 $bug['component'] = $bugsys->datastore['component']["$bug[component]"]['title'];
652 $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
653 $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
654 $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
655 $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
656
657 $bug['lastposttime'] = ($bug['hiddendisplay'] ? $bug['hiddenlastposttime'] : $bug['lastposttime']);
658 $bug['lastpost'] = ($bug['hiddendisplay'] ? $bug['hiddenlastpostbyname'] : $bug['lastpostbyname']);
659
660 $bug['lastposttime'] = $bugsys->datef->format($bugsys->options['dateformat'], $bug['lastposttime']);
661
662 return $bug;
663 }
664
665 // ###################################################################
666 /**
667 * Loads the pagination module and sets all of the appropriate options
668 * for it
669 *
670 * @access public
671 */
672 function LoadPaginationFramework()
673 {
674 global $bugsys;
675
676 $bugsys->load('pagination', 'pagination', true);
677 $bugsys->pagination->setDefaultPerPage($bugsys->options['defaultpp']);
678 $bugsys->pagination->setMaxPerPage($bugsys->options['maxpp']);
679 $bugsys->pagination->setPageLinks($bugsys->options['pagelinks']);
680 $bugsys->pagination->setPageVar('p');
681 $bugsys->pagination->setPerPageVar('pp');
682 $bugsys->pagination->setBitProcessor('PageNavigatorBitCallback');
683 $bugsys->pagination->setNavigatorProcessor('PageNavigatorCallback');
684 $bugsys->pagination->processIncomingData();
685 }
686
687 // ###################################################################
688 /**
689 * Callback function for the Pagination->BitProcessor()
690 *
691 * @param string Base link
692 * @param bool Do not show this as a link
693 * @param integer Page number
694 * @param object Page navigator framework
695 *
696 * @return string Processed HTML
697 */
698 function PageNavigatorBitCallback($baselink, $nolink, $number, $paginator)
699 {
700 global $bugsys;
701 eval('$return = "' . $bugsys->template->fetch('pagenav_bit') . '";');
702 return $return;
703 }
704
705 // ###################################################################
706 /**
707 * Callback function for the Pagination->NavigatorProcessor()
708 *
709 * @param string Base URL
710 * @param integer Next page number
711 * @param integer Previous page number
712 * @param array Show information
713 * @param string Individual page bits
714 * @param object Page navigator framework
715 *
716 * @return string Processed HTML
717 */
718 function PageNavigatorCallback($baselink, $nextpage, $prevpage, $show, $pagebits, $paginator)
719 {
720 global $bugsys;
721 eval('$return = "' . $bugsys->template->fetch('pagenav') . '";');
722 return $return;
723 }
724
725 // ###################################################################
726 /**
727 * Determines the correct permissions of the user. This is especially
728 * important for working with multiple-usergroup permission schemes.
729 * If a user is assigned to more than one usergroup, the highest level
730 * will always override (so a YES will always override a NO); this is
731 * because permissions are calculated with bitwise OR.
732 *
733 * @param array The user array with usergroups already exploded
734 *
735 * @return integer Permissions value
736 */
737 function FetchUserPermissions(&$user)
738 {
739 global $bugsys;
740
741 $perms = (int)$bugsys->datastore['usergroup']["$user[usergroupid]"]['permissions'];
742 if (!is_array($user['groupids']))
743 {
744 $user['groupids'] = explode(',', $bugsys->userinfo['groupids']);
745 }
746 $user['groupids'] = $bugsys->funct->array_strip_empty($user['groupids']);
747
748 foreach ($user['groupids'] AS $group)
749 {
750 $perms |= (int)$bugsys->datastore['usergroup']["$group"]['permissions'];
751 }
752
753 return $perms;
754 }
755
756 /*=====================================================================*\
757 || ###################################################################
758 || # $HeadURL$
759 || # $Id$
760 || ###################################################################
761 \*=====================================================================*/
762 ?>