menu from an array
// key vars are used when you need to get data out of the $label array
function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false)
{
global $bugsys;
// if we're not working on a boolean false, we use it for the value (allows -1 and 0)
if ($includenil !== false)
{
$opts[] = '' . $bugsys->lang->string('Not Selected') . ' ';
}
foreach ($array AS $value => $label)
{
$opts[] = '' . (($labelkey) ? $label["$labelkey"] : $label) . ' ';
}
return '' . implode("\n\t", $opts) . "\r ";
}
// ################### Start construct_user_display ##################
// $userinfo needs userid, email, displayname, and showemail
function construct_user_display($userinfo, $html = true)
{
global $bugsys;
if (!$userinfo['userid'])
{
$userinfo['displayname'] = $bugsys->lang->string('Guest');
$userinfo['showemail'] = false;
}
if ($html)
{
eval('$username = "' . $bugsys->template->fetch('username_display') . '";');
}
else
{
if ($userinfo['showemail'])
{
$username = sprintf($bugsys->lang->string('%1$s <%2$s>'), $userinfo['displayname'], $userinfo['email']);
}
else
{
$username = $userinfo['displayname'];
}
}
return $username;
}
// ######################## Start can_perform ########################
// short-hand for bitwise &
function can_perform($bitmask, $productid = 0)
{
global $bugsys, $_PERMISSION;
$userinfo = $bugsys->userinfo;
if (!isset($_PERMISSION["$bitmask"]))
{
trigger_error('Invalid bitmask "' . $bitmask . '" specified for can_perform() [includes/functions.php]', E_USER_WARNING);
}
if ($productid AND isset($bugsys->datastore['permission']["$userinfo[usergroupid]"]["$productid"]))
{
$inspecific = array('cansearch', 'canbeassignedto', 'canadminpanel', 'canadminbugs', 'canadminfields', 'canadminversions', 'canadminusers', 'canadmingroups', 'canadmintools');
if (!in_array($bitmask, $inspecific))
{
return ($bugsys->datastore['permission']["$userinfo[usergroupid]"]["$productid"] & $_PERMISSION["$bitmask"]);
}
}
return ($userinfo['permissions'] & $_PERMISSION["$bitmask"]);
}
// ################# Start construct_datastore_select ################
// loops through the specified datastore to create s
function construct_datastore_select($datastore, $labelname, $valuename, $selectedvalue = 0, $includeblank = false, $adminmode = false)
{
global $bugsys;
if ($adminmode)
{
global $admin;
}
$select = '';
if ($includeblank)
{
if ($adminmode)
{
$admin->list_item('', '', ((!$selectedvalue) ? true : false));
}
else
{
$label = '';
$value = '';
$selected = ((!$selectedvalue) ? true : false);
eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
}
}
foreach ($bugsys->datastore["$datastore"] AS $item)
{
$label = $item["$labelname"];
$value = $item["$valuename"];
$selected = (($value == $selectedvalue) ? true : false);
if ($adminmode)
{
$admin->list_item($label, $value, $selected);
}
else
{
eval('$select .= "' . $bugsys->template->fetch('selectoption') . '";');
}
}
if (!$adminmode)
{
return $select;
}
}
// ################## Start construct_custom_fields ##################
function construct_custom_fields($bug = array(), $ignore21mask = false, $nodefault = false)
{
global $bugsys;
static $fields;
if (!is_array($fields))
{
$fields = array();
$fields_fetch = $bugsys->db->query("
SELECT bugfield.*, permission.mask
FROM " . TABLE_PREFIX . "bugfield AS bugfield
LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
ON (bugfield.fieldid = permission.fieldid)
WHERE (permission.mask = 2 OR permission.mask = 1)
AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
);
while ($field = $bugsys->db->fetch_array($fields_fetch))
{
$fields["$field[fieldid]"] = $field;
}
}
$fieldvalues = $bugsys->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = " . intval($bug['bugid']));
$fieldbits = '';
foreach ($fields AS $field)
{
if ($nodefault)
{
$field['defaultvalue'] = '';
}
if (!is_null($bug["field$field[fieldid]"]))
{
$bugsys->debug("not null: $field[fieldid]");
$value = $bug["field$field[fieldid]"];
}
else
{
$value = $field['defaultvalue'];
}
if ($ignore21mask AND $field['mask'] != 0)
{
$field['mask'] = 2;
}
if ($field['mask'] == 2)
{
switch ($field['type'])
{
case 'input_text':
eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_text') . '";');
break;
case 'input_checkbox':
$selected = (($value) ? ' checked="checked"' : '');
eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_checkbox') . '";');
break;
case 'select_single':
$selects = unserialize($field['selects']);
$value = trim($value);
$options = '';
$id = -1;
$select = '';
if (!$field['usedefault'] AND !trim($value))
{
$selected = ' selected="selected"';
}
else
{
$selected = '';
}
eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
foreach ($selects AS $id => $select)
{
$selected = '';
$select = stripslashes(trim($select));
if ($select == $value)
{
$selected = ' selected="selected"';
}
else if ($field['usedefault'] AND $id == 0)
{
$selected = ' selected="selected"';
}
eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";');
}
eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";');
break;
}
}
else
{
$bugsys->debug('mask 1 processing');
if (is_null($fieldvalues["field$field[fieldid]"]))
{
$bugsys->debug("is null: $field[fieldid]");
if ($field['type'] == 'select_single')
{
if ($field['usedefault'])
{
$temp = unserialize($field['selects']);
$value = trim($temp[0]);
}
else
{
$value = $fieldvalues["field$field[fieldid]"];
}
}
else
{
$value = $field['defaultvalue'];
}
}
else
{
$value = $fieldvalues["field$field[fieldid]"];
}
if ($field['type'] == 'input_checkbox')
{
$value = (($value) ? 'True' : 'False');
}
$field['value'] = $value;
eval('$tempfield = "' . $bugsys->template->fetch('bugfield_static_text') . '";');
}
$fieldbits[] = $tempfield;
}
return $fieldbits;
}
// ################### Start process_custom_fields ###################
function process_custom_fields($bugid, $inputdata = array())
{
global $bugsys;
if (!$inputdata)
{
$inputdata =& $bugsys->in;
}
$fields = $bugsys->db->query("
SELECT bugfield.*
FROM " . TABLE_PREFIX . "bugfield AS bugfield
LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
ON (bugfield.fieldid = permission.fieldid)
WHERE permission.mask = 2
AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
);
while ($field = $bugsys->db->fetch_array($fields))
{
if ($field['type'] == 'input_checkbox')
{
$fieldbuild[] = 'field' . $field['fieldid'];
if (isset($inputdata["field$field[fieldid]"]))
{
$fieldvalue[] = 1;
}
else
{
$fieldvalue[] = 0;
}
continue;
}
if ($field['required'] AND empty($inputdata["field$field[fieldid]"]))
{
$errorlist[] = sprintf($bugsys->lang->string('The "%1$s" field is a required field.'), $field['name']);
continue;
}
if (isset($inputdata["field$field[fieldid]"]))
{
$fieldbuild[] = 'field' . $field['fieldid'];
if ($field['type'] == 'input_text')
{
$fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'";
}
else
{
if ($inputdata["field$field[fieldid]"] == -1)
{
$fieldvalue[] = "''";
continue;
}
$temp = unserialize($field['selects']);
$fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'";
}
}
}
if ($errorlist)
{
return $errorlist;
}
if (count($fieldbuild) < 1)
{
return;
}
$bugsys->db->query("REPLACE INTO " . TABLE_PREFIX . "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")");
}
// ####################### Start fetch_on_bits #######################
function fetch_on_bits($mask)
{
global $bugsys, $_PERMISSION;
$onbits = array();
$usergroupid = $bugsys->userinfo['usergroupid'];
if ($bugsys->datastore['usergroup']["$usergroupid"]['permissions'] & $_PERMISSION["$mask"])
{
foreach ($bugsys->datastore['product'] AS $id => $product)
{
if (!$product['componentmother'])
{
$onbits["$id"] = $id;
}
}
}
if (is_array($bugsys->datastore['permission']["$usergroupid"]))
{
foreach ($bugsys->datastore['permission']["$usergroupid"] AS $productid => $bit)
{
if ($bit & $_PERMISSION["$mask"])
{
$onbits["$productid"] = $productid;
}
else
{
if ($onbits["$productid"])
{
unset($onbits["$productid"]);
}
}
}
}
if (count($onbits) < 1)
{
$onbits = array(0);
}
return implode(',', $onbits);
}
// #################### Start isso_pre_parse_hook ####################
// the pre-parse hook for ISSO's template engine
function isso_pre_parse_hook($template)
{
$template = preg_replace('#\$help\[(.*)\]#', '" . fetch_help_link("\1") . "', $template);
return $template;
}
// ###################### Start fetch_help_link ######################
// returns a prepared link to insert into templates that opens up a
// help popup in the user-end
function fetch_help_link($topic)
{
global $bugsys;
if (isset($bugsys->datastore['help']["$topic"]))
{
eval('$temp = "' . $bugsys->template->fetch('help_link') . '";');
return $temp;
}
else
{
if ($bugsys->debug)
{
return "[[INVALID TOPIC: $topic]]";
}
// do we want this?
else if (null == 1)
{
return eval('$temp = "' . $bugsys->template->fetch('help_link') . '";');
}
}
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>