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