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