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