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