Required custom select fields will no longer show the empty option. This is only...
[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 $options = '';
294
295 // this overrides $field['usedefault'] because required fields will no longer have
296 // blank values as options
297 // TODO document above comment in the ACP
298 if (!$field['required'])
299 {
300 $tpl = new BSTemplate('bugfield_select_single_option');
301 $tpl->vars = array(
302 'id' => -1,
303 'select' => '',
304 'selected' => ((!$field['usedefault'] && !trim($value)) ? ' selected="selected"' : '')
305 );
306 $options = $tpl->evaluate()->getTemplate();
307 }
308
309 foreach ($selects as $id => $select)
310 {
311 $tpl = new BSTemplate('bugfield_select_single_option');
312 $tpl->vars = array(
313 'id' => $id,
314 'select' => stripslashes(trim($select)),
315 'selected' => (($select == $value || ($field['usedefault'] && $id == 0)) ? ' selected="selected"' : '')
316 );
317 $options .= $tpl->evaluate()->getTemplate();
318 }
319
320 $tpl = new BSTemplate('bugfield_select_single');
321 $tpl->vars = array(
322 'field' => $field,
323 'options' => $options
324 );
325 $tempfield = $tpl->evaluate()->getTemplate();
326 break;
327 }
328 }
329 else
330 {
331 BSApp::debug('mask 1 processing');
332 if (is_null($bug["custom$field[fieldid]"]))
333 {
334 BSApp::debug("is null: $field[fieldid]");
335 if ($field['type'] == 'select_single')
336 {
337 if ($field['usedefault'])
338 {
339 $temp = unserialize($field['selects']);
340 $value = trim($temp[0]);
341 }
342 else
343 {
344 $value = $bug["custom$field[fieldid]"];
345 }
346 }
347 else
348 {
349 $value = $field['defaultvalue'];
350 }
351 }
352 else
353 {
354 $value = $bug["custom$field[fieldid]"];
355 }
356
357 if ($field['type'] == 'input_checkbox')
358 {
359 $value = ($value ? 'True' : 'False');
360 }
361 $field['value'] = $value;
362
363 $tpl = new BSTemplate('bugfield_static_text');
364 $tpl->vars = array('field' => $field);
365 $tempfield = $tpl->evaluate()->getTemplate();
366 }
367 $fieldbits[] = $tempfield;
368 }
369
370 return $fieldbits;
371 }
372
373 // ###################################################################
374 /**
375 * This takes the bug API object and input data and then sanitizes, verifies,
376 * and processes the data for custom fields. If there are any errors,
377 * they are passed to the message reporter.
378 *
379 * @param object A BugAPI object
380 * @param object MessageReporter object
381 * @param bool If there are errors, add them to an errorbox format? If not, then display-on-encounter
382 * @param bool Search mode: don't change certain fields when they're 0 or empty
383 *
384 * @return mixed NULL if an ID is passed, string if bugid is NULL
385 */
386 function process_custom_fields(&$bugapi, &$msg, $errorbox = false, $searchMode = false)
387 {
388 if (!$inputdata)
389 {
390 $inputdata = &BSApp::$input->in;
391 }
392
393 $fields = BSApp::$db->query("
394 SELECT bugfield.*, MAX(permission.mask) AS mask
395 FROM " . TABLE_PREFIX . "bugfield AS bugfield
396 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
397 ON (bugfield.fieldid = permission.fieldid)
398 WHERE permission.mask = 2
399 AND permission.usergroupid IN (" . bugdar::$userinfo['usergroupid'] . (sizeof(bugdar::$userinfo['groupids']) != 0 ? ',' . implode(',', bugdar::$userinfo['groupids']) : '') . ")
400 GROUP BY (bugfield.fieldid)
401 ");
402 foreach ($fields as $field)
403 {
404 $fieldname = "custom$field[fieldid]";
405
406 if ($field['type'] == 'input_checkbox')
407 {
408 if ($searchMode AND intval($inputdata["$fieldname"]) == 0)
409 {
410 continue;
411 }
412 $bugapi->set($fieldname, intval($inputdata["$fieldname"]));
413 continue;
414 }
415 else if ($field['type'] == 'select_single')
416 {
417 $temp = unserialize($field['selects']);
418 $inputdata[$fieldname] = $temp[intval($inputdata["$fieldname"])] . ''; // make it a string so isset() doesn't catch
419 }
420
421 // field data wasn't passed, so skip it
422 if (!isset($inputdata["$fieldname"]))
423 {
424 continue;
425 }
426
427 if ($field['required'] AND empty($inputdata["$fieldname"]) AND !$searchMode)
428 {
429 $errorlist[] = sprintf(T('The field "%1$s" is a required.'), $field['name']);
430 continue;
431 }
432
433 if (!empty($field['regexmatch']))
434 {
435 if (!preg_match('#' . str_replace('#', '\#', $field['regexmatch']) . '#si', $inputdata["$fieldname"]))
436 {
437 $errorlist[] = sprintf(T('%1$s does not match the specified format'), $field['name']);
438 continue;
439 }
440 }
441
442 if (isset($inputdata["$fieldname"]))
443 {
444 if ($field['type'] == 'input_text')
445 {
446 if (empty($inputdata["$fieldname"]) AND $searchMode)
447 {
448 continue;
449 }
450 $bugapi->set($fieldname, $inputdata["$fieldname"]);
451 }
452 else
453 {
454 if (empty($inputdata["$fieldname"]))
455 {
456 if (!$searchMode)
457 {
458 $bugapi->set($fieldname, '');
459 }
460 continue;
461 }
462
463 $bugapi->set($fieldname, trim($inputdata["$fieldname"]));
464 }
465 }
466 }
467
468 if ($errorlist)
469 {
470 if ($errorbox)
471 {
472 foreach ($errorlist AS $err)
473 {
474 $msg->addError($err);
475 }
476 }
477 else
478 {
479 $msg->error($errorlist[0]);
480 }
481 }
482 }
483
484 // ####################### Start fetch_on_bits #######################
485 function fetch_on_bits($mask, $userinfo = null)
486 {
487 if ($userinfo == null)
488 {
489 $userinfo =& bugdar::$userinfo;
490 }
491
492 $onbits = array();
493
494 $usergroupid = $userinfo['usergroupid'];
495 FetchUserPermissions($userinfo); // get the groups
496 $groups = $userinfo['groupids'];
497 $groups[] = $usergroupid;
498
499 // product-inspecific work
500 if (is_array(bugdar::$datastore['product']))
501 {
502 foreach ($groups AS $groupid)
503 {
504 // we only need to do this so long as there's no onbits array because this isn't product specific
505 if (sizeof($onbits) == 0 AND bugdar::$datastore['usergroup']["$groupid"]['permissions'] & bugdar::$permissions["$mask"])
506 {
507 foreach (bugdar::$datastore['product'] AS $id => $product)
508 {
509 $onbits["$id"] = $id;
510 }
511 }
512 }
513 }
514
515 // bits set explicitly by products
516 $explicit = array();
517
518 // product specific work
519 foreach ($groups AS $groupid)
520 {
521 if (is_array(bugdar::$datastore['permission']["$groupid"]))
522 {
523 foreach (bugdar::$datastore['permission']["$groupid"] AS $productid => $bit)
524 {
525 if ($bit & bugdar::$permissions["$mask"])
526 {
527 $explicit["$productid"] = $productid;
528 $onbits["$productid"] = $productid;
529 }
530 else
531 {
532 // only unset if the bit was set in the first place by blanket and not product-specific permissions
533 // if it was set by product permissions then the highest level takes precedence
534 if ($onbits["$productid"] AND !isset($explicit["$productid"]))
535 {
536 unset($onbits["$productid"]);
537 }
538 }
539 }
540 }
541 }
542
543 // SQL queries would become very unhappy if we didn't do this
544 if (sizeof($onbits) < 1)
545 {
546 $onbits = array(0);
547 }
548
549 return implode(',', $onbits);
550 }
551
552 /**
553 * Pre-parse hook for BSTemplate class. This merely substitutes help links
554 *
555 * @param string Template
556 * @return string
557 */
558 function isso_pre_parse_hook($template)
559 {
560 $template = preg_replace('#\$help\[(.*)\]#', '<?php echo fetch_help_link("\1") ?>', $template);
561 return $template;
562 }
563
564 /**
565 * Returns the HTML used to generate a help link for a given topic
566 *
567 * @param string Topic name
568 * @return string
569 */
570 function fetch_help_link($topic)
571 {
572 $tpl = new BSTemplate('help_link');
573 $tpl->vars = array('topic' => $topic);
574
575 if (isset(bugdar::$datastore['help']["$topic"]))
576 {
577 return $tpl->evaluate()->getTemplate();
578 }
579 else
580 {
581 if (BSApp::get_debug())
582 {
583 return "[[INVALID TOPIC: $topic]]";
584 }
585 // do we want this?
586 else if (null == 1)
587 {
588 return $tpl->evaluate()->getTemplate();
589 }
590 }
591 }
592
593 // ###################################################################
594 /**
595 * Returns a user array of information that is specific to all visiting
596 * users (guests). This can then be passed to any function that requires
597 * user information.
598 *
599 * @access public
600 *
601 * @return array User information array
602 */
603 function fetch_guest_user()
604 {
605 return array(
606 'usergroupid' => 1,
607 'groupids' => array(),
608 'userid' => 0,
609 'email' => '',
610 'displayname' => '',
611 'showcolors' => 1,
612 'permissions' => bugdar::$datastore['usergroup'][1]['permissions'],
613 'displaytitle' => bugdar::$datastore['usergroup'][1]['displaytitle'],
614 'timezone' => bugdar::$options['defaulttimezone']
615 );
616 }
617
618 // ###################################################################
619 /**
620 * Does an exhaustive permissions check on the bug. It checks for hidden
621 * bug status and ability to view hidden bugs. This normally was done
622 * at the top of each page, but it got so big, it was moved to a function.
623 *
624 * @access public
625 *
626 * @param array Bug array
627 * @param array Alternate user array
628 *
629 * @return bool Does the user have permission
630 */
631 function check_bug_permissions($bug, $userinfo = null)
632 {
633 if ($userinfo == null)
634 {
635 $userinfo = bugdar::$userinfo;
636 }
637
638 BSApp::debug("checking permissions for $userinfo[userid] on bug $bug[bugid]");
639
640 BSApp::debug('*** START VERBOSE CHECK ***');
641
642 BSApp::debug('* !can_perform(canviewbugs, $bug[product], $userinfo) = ' . (int)(!can_perform('canviewbugs', $bug['product'], $userinfo)));
643 BSApp::debug('* $bug[hidden] = ' . (int)$bug['hidden']);
644 BSApp::debug('* $userinfo[userid] (' . $userinfo['userid'] . ') == $bug[userid] (' . $bug['userid'] . ') = ' . (int)($userinfo['userid'] == $bug['userid']));
645 BSApp::debug('* can_perform(canviewownhidden, $bug[product], $userinfo) = ' . (int)(!!can_perform('canviewownhidden', $bug['product'], $userinfo)));
646 BSApp::debug('* can_perform(canviewhidden, $bug[product], $userinfo) = ' . (int)(!!can_perform('canviewhidden', $bug['product'], $userinfo)));
647 BSApp::debug('* !$bug[hidden] = ' . (int)(!$bug['hidden']));
648
649 BSApp::debug('*** END PERMISSIONS CHECK ***');
650
651 if
652 (
653 !can_perform('canviewbugs', $bug['product'], $userinfo)
654 OR
655 !(
656 (
657 $bug['hidden']
658 AND
659 (
660 ($userinfo['userid'] == $bug['userid'] AND can_perform('canviewownhidden', $bug['product'], $userinfo))
661 OR
662 can_perform('canviewhidden', $bug['product'], $userinfo)
663 )
664 )
665 OR
666 !$bug['hidden']
667 )
668 )
669 {
670 BSApp::debug('*** DONE WITH REAL CALLS ***');
671 return false;
672 }
673
674 BSApp::debug('*** DONE WITH REAL CALLS ***');
675
676 return true;
677 }
678
679 // ###################################################################
680 /**
681 * Takes an array of bug information and returns another array with
682 * information that is suitable for display as all the IDs have been
683 * replaced by their string equivalents
684 *
685 * @param array Unprocessed bug data
686 * @param string Color to display if the user has opted to not show status colours
687 *
688 * @param array Bug array with data fit for display
689 */
690 function ProcessBugDataForDisplay($bug, $color = '')
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 $perms = (int)bugdar::$datastore['usergroup']["$user[usergroupid]"]['permissions'];
727 if (!is_array($user['groupids']))
728 {
729 $user['groupids'] = explode(',', bugdar::$userinfo['groupids']);
730 }
731 $user['groupids'] = BSFunctions::array_strip_empty($user['groupids']);
732
733 foreach ($user['groupids'] AS $group)
734 {
735 $perms |= (int)bugdar::$datastore['usergroup']["$group"]['permissions'];
736 }
737
738 return $perms;
739 }
740
741 // ###################################################################
742 /**
743 * Fetches the path for an email template, given the name of the
744 * template and the locale to use
745 *
746 * @param string The template name
747 * @param string Language locale code
748 *
749 * @return string Template path
750 */
751 function FetchEmailPath($name, $locale)
752 {
753 return '../locale/' . $locale . '/emails/' . $name;
754 }
755
756 ?>