|
From: Benjamin C. <bc...@us...> - 2004-10-25 12:07:48
|
Update of /cvsroot/phpbt/phpbt/inc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28250/inc Modified Files: auth.php functions.php Added Files: is_a.php Log Message: Merging in htmltemplates branch to HEAD Index: auth.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/inc/auth.php,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- auth.php 7 Apr 2003 21:58:30 -0000 1.18 +++ auth.php 25 Oct 2004 12:07:00 -0000 1.19 @@ -2,7 +2,7 @@ // auth.php - Authentication and permission objects // ------------------------------------------------------------------------ -// Copyright (c) 2001, 2002 The phpBugTracker Group +// Copyright (c) 2001 - 2004 The phpBugTracker Group // ------------------------------------------------------------------------ // This file is part of phpBugTracker // @@ -10,194 +10,173 @@ // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // phpBugTracker is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with phpBugTracker; if not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // ------------------------------------------------------------------------ -// Based on and/or directly from PHPlib, which is +// Based on and/or directly from PHPlib, which is // Copyright (c) 1998-2000 NetUSE AG -- Boris Erdmann, Kristian Koehntopp class uauth { var $lifetime = 0; // In minutes -- 0 for no expiration until browser closed var $classname = 'uauth'; - + function uauth() { - global $HTTP_SESSION_VARS, $group_ids, $uname, $db_fields, $group, $perms, - $uid, $exp; - - if (!isset($HTTP_SESSION_VARS['group_ids'])) { - if (phpversion() <= '4.0.6') { - $group_ids = array(0); - $uname = ''; - $db_fields = array(); - $group = array(); - $perms = array(); - $uid = 0; - $exp = 0; - session_register(array('group_ids', 'uname', 'db_fields', 'group', - 'perms', 'uid', 'exp')); - } - $HTTP_SESSION_VARS['group_ids'] = array(0); + global $group_ids, $uname, $db_fields, $group, $perms, + $uid, $exp; + + if (!isset($_SESSION['group_ids'])) { + $_SESSION['group_ids'] = array(0); } - + if ($this->is_authenticated()) { - if ($HTTP_SESSION_VARS['uid']) { - $HTTP_SESSION_VARS['exp'] = time() + (60 * $this->lifetime); + if ($_SESSION['uid']) { + $_SESSION['exp'] = time() + (60 * $this->lifetime); } } } function is_authenticated() { - global $HTTP_SESSION_VARS; - - if (isset($HTTP_SESSION_VARS['uid']) && $HTTP_SESSION_VARS['uid'] && - ($this->lifetime <= 0 || time() < $HTTP_SESSION_VARS['exp'])) { - return $HTTP_SESSION_VARS['uid']; + + if (isset($_SESSION['uid']) && $_SESSION['uid'] && ($this->lifetime <= 0 || time() < $_SESSION['exp'])) { + return $_SESSION['uid']; } else { return false; } } - + function auth_validatelogin() { - global $_pv, $db, $select, $emailpass, $emailsuccess, $STRING, - $HTTP_SESSION_VARS, $uid; + global $db, $select, $emailpass, $emailsuccess, $uid; - extract($_pv); - if (!$username) return 0; - $HTTP_SESSION_VARS['uname'] = $username; - if (ENCRYPT_PASS) { - $password = md5($password); - } - $u = $db->getRow("select * from ".TBL_AUTH_USER." where login = '$username' and password = '$password' and active > 0"); - if (!$u or DB::isError($u)) { - return 0; - } else { - $HTTP_SESSION_VARS['db_fields'] = @unserialize($u['bug_list_fields']); - - // Grab group assignments and permissions based on groups - $rs = $db->query("select u.group_id, group_name from ".TBL_USER_GROUP. - " u, ".TBL_AUTH_GROUP." a where user_id = {$u['user_id']} ". - 'and u.group_id = a.group_id'); + extract($_POST); + if (!$username) return 0; + $_SESSION['uname'] = $username; + if (ENCRYPT_PASS) { + $password = md5($password); + } + $u = $db->getRow("select * from ".TBL_AUTH_USER." where login = '$username' and password = '$password' and active > 0"); + if (!$u or DB::isError($u)) { + return 0; + } else { + $_SESSION['db_fields'] = @unserialize($u['bug_list_fields']); + + // Grab group assignments and permissions based on groups + $rs = $db->query("select u.group_id, group_name from ".TBL_USER_GROUP." u, ".TBL_AUTH_GROUP." a where user_id = {$u['user_id']} and u.group_id = a.group_id"); while (list($groupid, $groupname) = $rs->fetchRow(DB_FETCHMODE_ORDERED)) { - $HTTP_SESSION_VARS['group_ids'][] = $groupid; - $HTTP_SESSION_VARS['group'][$groupname] = true; + $_SESSION['group_ids'][] = $groupid; + $_SESSION['group'][$groupname] = true; + } + $perms = $db->getCol("select perm_name from ".TBL_AUTH_PERM." ap, ".TBL_GROUP_PERM." gp where group_id in (".@join(',', $_SESSION['group_ids']).") and gp.perm_id = ap.perm_id"); + foreach ($perms as $perm) { + $_SESSION['perms'][$perm] = true; } - $perms = $db->getCol("select perm_name from ".TBL_AUTH_PERM." ap, ". - TBL_GROUP_PERM." gp where group_id in (". - delimit_list(',', $HTTP_SESSION_VARS['group_ids']).") and gp.perm_id = ap.perm_id"); - foreach ($perms as $perm) { - $HTTP_SESSION_VARS['perms'][$perm] = true; - } - $HTTP_SESSION_VARS['uid'] = $u['user_id']; - - return $u['user_id']; - } - } - + $_SESSION['uid'] = $u['user_id']; + + return $u['user_id']; + } + } + function unauth() { - global $HTTP_SESSION_VARS; - - $HTTP_SESSION_VARS['uid'] = 0; - $HTTP_SESSION_VARS['perms'] = array(); - $HTTP_SESSION_VARS['exp'] = 0; - $HTTP_SESSION_VARS['group'] = array(); - $HTTP_SESSION_VARS['group_ids'] = array(0); - $HTTP_SESSION_VARS['db_fields'] = array(); - } + + $_SESSION['uid'] = 0; + $_SESSION['perms'] = array(); + $_SESSION['exp'] = 0; + $_SESSION['group'] = array(); + $_SESSION['group_ids'] = array(0); + $_SESSION['db_fields'] = array(); + } } class uperm { - var $classname = 'uperm'; - var $permissions = array (); + var $classname = 'uperm'; + var $permissions = array (); + + function check($p) { + + if (!$this->have_perm($p)) { + if (!isset($_SESSION['perms']) ) { + $_SESSION['perms'] = ''; + } + $this->perm_invalid($_SESSION['perms'], $p); + exit(); + } + } - function check($p) { - global $HTTP_SESSION_VARS; + function check_proj($project_id) { + global $db; + + if ($this->have_perm_proj($project_id)) { + return true; + } else { + $this->perm_invalid($_SESSION['perms'], $p); + exit(); + } + } - if (!$this->have_perm($p)) { - if (!isset($HTTP_SESSION_VARS['perms']) ) { - $HTTP_SESSION_VARS['perms'] = ''; - } - $this->perm_invalid($HTTP_SESSION_VARS['perms'], $p); - exit(); - } - } - - function check_proj($project_id) { - global $db; - - if ($this->have_perm_proj($project_id)) { - return true; - } else { - $this->perm_invalid($HTTP_SESSION_VARS['perms'], $p); - exit(); - } - } - - function have_perm_proj($project_id) { - global $db; - - if ($this->have_perm('Admin')) { - return true; - } - - if ( $db->getCol('SELECT user_id FROM '.TBL_PROJECT_PERM.' WHERE user_id = '.$_SESSION['uid']." AND project_id = $project_id") ) { - return true; - } else { - return false; - } - } - - function check_auth($auth_var, $reqs) { - global $HTTP_SESSION_VARS; - - // Administrators always pass - if (@isset($HTTP_SESSION_VARS[$auth_var]['Admin'])) { - return true; - } - - if (is_array($reqs)) { - foreach ($reqs as $req) { - if (!@isset($HTTP_SESSION_VARS[$auth_var][$req])) { - return false; - } - } - } else { - if (!@isset($HTTP_SESSION_VARS[$auth_var][$reqs])) { - return false; - } - } - - // Didn't fail on any requirements? Then the user passes the check - return true; - } - - - function in_group($req_groups) { - return $this->check_auth('group', $req_groups); - } - - - function have_perm($req_perms) { - return $this->check_auth('perms', $req_perms); - } - - - function perm_invalid($actual_perms, $required_perms) { - global $t; - - $t->wrap('badperm.html'); - } + function have_perm_proj($project_id) { + global $db; + + if ($this->have_perm('Admin')) { + return true; + } + + if ( $db->getCol('SELECT user_id FROM '.TBL_PROJECT_PERM.' WHERE user_id = '.$_SESSION['uid']." AND project_id = $project_id") ) { + return true; + } else { + return false; + } + } + + function check_auth($auth_var, $reqs) { + + // Administrators always pass + if (@isset($_SESSION[$auth_var]['Admin'])) { + return true; + } + + if (is_array($reqs)) { + foreach ($reqs as $req) { + if (!@isset($_SESSION[$auth_var][$req])) { + return false; + } + } + } else { + if (!@isset($_SESSION[$auth_var][$reqs])) { + return false; + } + } + + // Didn't fail on any requirements? Then the user passes the check + return true; + } + + + function in_group($req_groups) { + return $this->check_auth('group', $req_groups); + } + + + function have_perm($req_perms) { + return $this->check_auth('perms', $req_perms); + } + + + function perm_invalid($actual_perms, $required_perms) { + global $t; + + $t->render('badperm.html', ''); + } function check_group($group) { global $t; - if (!$this->check_auth('group', $group)) { + if (!$this->check_auth('group', $group)) { $t->assign('group', $group); $t->wrap('badgroup.html'); exit(); Index: functions.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/inc/functions.php,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- functions.php 18 Mar 2004 22:48:32 -0000 1.46 +++ functions.php 25 Oct 2004 12:07:00 -0000 1.47 @@ -2,7 +2,7 @@ // functions.php - Set up global functions // ------------------------------------------------------------------------ -// Copyright (c) 2001, 2002 The phpBugTracker Group +// Copyright (c) 2001 - 2004 The phpBugTracker Group // ------------------------------------------------------------------------ // This file is part of phpBugTracker // @@ -22,37 +22,42 @@ // ------------------------------------------------------------------------ // $Id$ +// Set the domain if gettext is available +if (false && is_callable('gettext')) { + define('USE_GETTEXT', true); + setlocale(LC_ALL, LOCALE); + bindtextdomain('phpbt', './locale'); + textdomain('phpbt'); +} else { + define('USE_GETTEXT', false); +} + /// /// Show text to the browser - escape hatch function show_text($text, $iserror = false) { - global $t; + global $t; $t->assign(array( 'text' => $text, 'iserror' => $iserror )); - $t->wrap('error.html'); + $t->render('error.html', ''); } $select['priority'] = array( - 1 => '1 - Low', - 2 => '2', - 3 => '3 - Medium', - 4 => '4', - 5 => '5 - High' - ); + 1 => '1 - Low', + 2 => '2', + 3 => '3 - Medium', + 4 => '4', + 5 => '5 - High' + ); /// /// Build a select box with the item matching $value selected -function build_select($params) { - global $db, $select, $perm, $STRING, $restricted_projects, $QUERY; - - extract($params); - if (!isset($selected)) { - $selected = ''; - } +function build_select($box, $selected = '', $project = 0) { + global $db, $select, $perm, $restricted_projects, $QUERY; - // create hash to map tablenames + // create hash to map tablenames $cfgDatabase = array( 'group' => TBL_AUTH_GROUP, 'project' => TBL_PROJECT, @@ -63,240 +68,271 @@ 'version' => TBL_VERSION, 'database' => TBL_DATABASE, 'site' => TBL_SITE - ); + ); - $text = ''; + $text = ''; - if (isset($cfgDatabase[$box])) { + if (isset($cfgDatabase[$box])) { $querystart = "select {$box}_id, {$box}_name from $cfgDatabase[$box]"; $querymid = ' where sort_order > 0 order by sort_order'; $queries = array( - 'group' => $querystart.' where group_name <> \'User\' order by group_name', - 'severity' => $querystart.$querymid, - 'site' => $querystart.$querymid, - 'status' => $querystart.$querymid, - 'resolution' => $querystart.$querymid, - 'project' => $perm->have_perm('Admin') - ? $querystart." where ". - ($selected ? "(active > 0 or project_id in ($selected))" : 'active > 0'). - " order by {$box}_name" - : $querystart." where project_id not in ($restricted_projects)". - " and ". - ($selected ? " (active > 0 or project_id in ($selected))" : 'active > 0'). - " order by {$box}_name", - 'component' => $querystart." where project_id = $project and active = 1 order by {$box}_name", - 'version' => $querystart." where project_id = $project and active = 1 order by {$box}_id desc", - 'database' => $querystart.$querymid + 'group' => $querystart.' where group_name <> \'User\' order by group_name', + 'severity' => $querystart.$querymid, + 'site' => $querystart.$querymid, + 'status' => $querystart.$querymid, + 'resolution' => $querystart.$querymid, + 'project' => $perm->have_perm('Admin') + ? $querystart." where ". + ($selected ? "(active > 0 or project_id in ($selected))" : 'active > 0'). + " order by {$box}_name" + : $querystart." where project_id not in ($restricted_projects)". + " and ". + ($selected ? " (active > 0 or project_id in ($selected))" : 'active > 0'). + " order by {$box}_name", + 'component' => $querystart." where project_id = $project and active = 1 order by {$box}_name", + 'version' => $querystart." where project_id = $project and active = 1 order by {$box}_id desc", + 'database' => $querystart.$querymid ); - } + } - switch($box) { - case 'user_filter': - foreach ($STRING['user_filter'] as $k => $v) { - $text .= sprintf("<option value=\"%d\"%s>%s</option>", - $k, ($k == $selected ? ' selected' : ''), $v); - } - break; - case 'group': - if ($project) { // If we are building for project admin page - if (!count($selected) or (count($selected) && in_array(0, $selected))) { - $sel = ' selected'; - } else { - $sel = ''; - } - $text = "<option value=\"all\"$sel>All Groups</option>"; - } - $rs = $db->query($queries[$box]); - while ($rs->fetchInto($row)) { - if (count($selected) && in_array($row[$box.'_id'], $selected)) { - $sel = ' selected'; - } else { - $sel = ''; - } - $text .= '<option value="'. - $row[$box.'_id']."\"$sel>".$row[$box.'_name'].'</option>'; - } - break; - case 'database': $text = '<option value="0">None</option>'; - case 'severity': - case 'status': - case 'resolution': - case 'project': - case 'site': - case 'component': - case 'version': - $rs = $db->query($queries[$box]); - while ($rs->fetchInto($row)) { - if ($selected == $row[$box.'_id'] and $selected != '') { - $sel = ' selected'; - } else { - $sel = ''; - } - $text .= '<option value="'. - $row[$box.'_id']."\"$sel>".$row[$box.'_name'].'</option>'; - } - break; - case 'os': - $rs = $db->query("select {$box}_id, {$box}_name, regex from ".TBL_OS." where sort_order > 0 order by sort_order"); - while ($rs->fetchInto($row)) { - if ($selected == '' and isset($row['Regex']) and - preg_match($row['Regex'],$GLOBALS['HTTP_USER_AGENT'])) { - $sel = ' selected'; - } elseif ($selected == $row[$box.'_id']) { - $sel = ' selected'; - } else { - $sel = ''; - } - $text .= '<option value="'.$row[$box.'_id']."\"$sel>".$row[$box.'_name']."</option>"; - } - break; - case 'owner': - $rs = $db->query("select u.user_id, login from ".TBL_AUTH_USER." u, ".TBL_USER_GROUP." ug, ".TBL_AUTH_GROUP." g where u.active > 0 and u.user_id = ug.user_id and ug.group_id = g.group_id and g.assignable > 0 order by login"); - while ($rs->fetchInto($row)) { - // either singular matches, or array matches are acceptable - if (($selected == $row['user_id']) || in_array($row['user_id'], $selected)) { - $sel = ' selected'; - } else { - $sel = ''; - } - $text .= "<option value=\"{$row['user_id']}\"$sel>". - maskemail($row['login'])."</option>"; - } - break; - case 'bug_cc': - $rs = $db->query(sprintf($QUERY['functions-bug-cc'], $selected)); - while (list($uid, $user) = $rs->fetchRow(DB_FETCHMODE_ORDERED)) { - $text .= "<option value=\"$uid\">".maskemail($user).'</option>'; - } - // Pad the sucker - $text .= '<option value="" disabled>'; - for ($i = 0; $i < 30; $i++) { - $text .= ' '; - } - $text .= '</option>'; - break; - case 'LANGUAGE' : - $dir = opendir('languages'); - while (false !== ($file = readdir($dir))) { - if ($file != '.' && $file != '..' && $file != 'CVS' && substr($file, -3) == 'php') { - $filelist[] = str_replace('.php', '', $file); - } - } - closedir($dir); - sort($filelist); - foreach ($filelist as $file) { - if ($file == $selected) { - $sel = ' selected'; - } else { - $sel = ''; - } - $text .= "<option value=\"$file\"$sel>$file</option>"; - } - break; - case 'THEME' : - $dir = opendir('templates'); - while (false !== ($file = readdir($dir))) { - if ($file != '.' && $file != '..' && $file != 'CVS') { - $filelist[] = str_replace('.php', '', $file); - } - } - closedir($dir); - sort($filelist); - foreach ($filelist as $file) { - if ($file == $selected) { - $sel = ' selected'; - } else { - $sel = ''; - } - $text .= "<option value=\"$file\"$sel>$file</option>"; - } - break; - case 'STYLE' : - $dir = opendir('styles'); - while (false !== ($file = readdir($dir))) { - if ($file != '.' && $file != '..' && $file != 'CVS') { - $filelist[] = str_replace('.css', '', $file); - } - } - closedir($dir); - sort($filelist); - foreach ($filelist as $file) { - if ($file == $selected) { - $sel = ' selected'; - } else { - $sel = ''; - } - $text .= "<option value=\"$file\"$sel>$file</option>"; - } - break; - case 'BUG_UNCONFIRMED' : - case 'BUG_PROMOTED' : - case 'BUG_ASSIGNED' : - case 'BUG_REOPENED' : - case 'BUG_CLOSED' : - static $bug_status_list = array(); - - if (empty($bug_status_list)) { - $bug_status_list = $db->getAssoc("select status_id, status_name". - " from ".TBL_STATUS." order by status_name"); - } - foreach ($bug_status_list as $id => $name) { - $sel = $id == $selected ? ' selected' : ''; - $text .= "<option value=\"$id\"$sel>$name</option>"; - } - break; - case 'GROUP_ASSIGN_TO' : - static $group_list = array(); - - if (empty($group_list)) { - $group_list = $db->getAssoc("select group_id, group_name". - " from ".TBL_AUTH_GROUP." order by group_name"); - } - foreach ($group_list as $id => $name) { - $sel = $id == $selected ? ' selected' : ''; - $text .= "<option value=\"$id\"$sel>$name</option>"; - } - break; - default : - $deadarray = $select[$box]; - while(list($val,$item) = each($deadarray)) { - if ($selected == $val and $selected != '') { - $sel = ' selected'; - } else { - $sel = ''; - } - $text .= "<option value=\"$val\"$sel>$item</option>"; - } - break; - } - echo ($text); + switch($box) { + case 'user_filter': + $options = array( + 0 => translate("All Users"), + 1 => translate("Active Users"), + 2 => translate("Inactive Users")); + foreach ($options as $k => $v) { + $text .= sprintf("<option value=\"%d\"%s>%s</option>", + $k, ($k == $selected ? ' selected' : ''), $v); + } + break; + case 'group': + if ($project) { // If we are building for project admin page + if (!count($selected) or (count($selected) && in_array(0, $selected))) { + $sel = ' selected'; + } else { + $sel = ''; + } + $text = "<option value=\"all\"$sel>All Groups</option>"; + } + $rs = $db->query($queries[$box]); + while ($rs->fetchInto($row)) { + if (count($selected) && in_array($row[$box.'_id'], $selected)) { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= '<option value="'. + $row[$box.'_id']."\"$sel>".$row[$box.'_name'].'</option>'; + } + break; + case 'database': $text = '<option value="0">None</option>'; + case 'severity': + case 'status': + case 'resolution': + case 'project': + case 'site': + case 'component': + case 'version': + $rs = $db->query($queries[$box]); + while ($rs->fetchInto($row)) { + if ($selected == $row[$box.'_id'] and $selected != '') { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= '<option value="'. + $row[$box.'_id']."\"$sel>".$row[$box.'_name'].'</option>'; + } + break; + case 'os': + $rs = $db->query("select {$box}_id, {$box}_name, regex from ".TBL_OS." where sort_order > 0 order by sort_order"); + while ($rs->fetchInto($row)) { + if ($selected == '' and isset($row['Regex']) and + preg_match($row['Regex'],$GLOBALS['HTTP_USER_AGENT'])) { + $sel = ' selected'; + } elseif ($selected == $row[$box.'_id']) { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= '<option value="'.$row[$box.'_id']."\"$sel>".$row[$box.'_name']."</option>"; + } + break; + case 'owner': + // Added the DISTINCT SQL modifier so we don't get duplicated users in the list. (Because of being in multiple groups with assignable rights.) + $rs = $db->query("select DISTINCT u.user_id, login from ".TBL_AUTH_USER." u, ".TBL_USER_GROUP." ug, ".TBL_AUTH_GROUP." g where u.active > 0 and u.user_id = ug.user_id and ug.group_id = g.group_id and g.assignable > 0 order by login"); + while ($rs->fetchInto($row)) { + // either singular matches, or array matches are acceptable + if (($selected == $row['user_id']) || (is_array($selected) && in_array($row['user_id'], $selected))) { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= "<option value=\"{$row['user_id']}\"$sel>". + maskemail($row['login'])."</option>"; + } + break; + case 'reporter': + global $u; + $selected = $selected ? $selected : $u; + $rs = $db->query("select u.user_id, login from ".TBL_AUTH_USER." u where u.active > 0 order by login"); + while ($rs->fetchInto($row)) { + // either singular matches, or array matches are acceptable + if ($selected == $row['user_id']) { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= "<option value=\"{$row['user_id']}\"$sel>". + maskemail($row['login'])."</option>"; + } + break; + case 'bug_cc': + $rs = $db->query(sprintf($QUERY['functions-bug-cc'], $selected)); + while (list($uid, $user) = $rs->fetchRow(DB_FETCHMODE_ORDERED)) { + $text .= "<option value=\"$uid\">".maskemail($user).'</option>'; + } + // Pad the sucker + $text .= '<option value="" disabled>'; + for ($i = 0; $i < 30; $i++) { + $text .= ' '; + } + $text .= '</option>'; + break; + case 'LANGUAGE' : + $dir = opendir('languages'); + while (false !== ($file = readdir($dir))) { + if ($file != '.' && $file != '..' && $file != 'CVS' && substr($file, -3) == 'php') { + $filelist[] = str_replace('.php', '', $file); + } + } + closedir($dir); + sort($filelist); + foreach ($filelist as $file) { + if ($file == $selected) { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= "<option value=\"$file\"$sel>$file</option>"; + } + break; + case 'THEME' : + $dir = opendir('templates'); + while (false !== ($file = readdir($dir))) { + if ($file != '.' && $file != '..' && $file != 'CVS') { + $filelist[] = str_replace('.php', '', $file); + } + } + closedir($dir); + sort($filelist); + foreach ($filelist as $file) { + if ($file == $selected) { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= "<option value=\"$file\"$sel>$file</option>"; + } + break; + case 'STYLE' : + $dir = opendir('styles'); + while (false !== ($file = readdir($dir))) { + if ($file != '.' && $file != '..' && $file != 'CVS') { + $filelist[] = str_replace('.css', '', $file); + } + } + closedir($dir); + sort($filelist); + foreach ($filelist as $file) { + if ($file == $selected) { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= "<option value=\"$file\"$sel>$file</option>"; + } + break; + case 'BUG_UNCONFIRMED' : + case 'BUG_PROMOTED' : + case 'BUG_ASSIGNED' : + case 'BUG_REOPENED' : + case 'BUG_CLOSED' : + static $bug_status_list = array(); + + if (empty($bug_status_list)) { + $bug_status_list = $db->getAssoc("select status_id, status_name from ".TBL_STATUS." order by status_name"); + } + foreach ($bug_status_list as $id => $name) { + $sel = $id == $selected ? ' selected' : ''; + $text .= "<option value=\"$id\"$sel>$name</option>"; + } + break; + case 'GROUP_ASSIGN_TO' : + static $group_list = array(); + + if (empty($group_list)) { + $group_list = $db->getAssoc("select group_id, group_name from ".TBL_AUTH_GROUP." order by group_name"); + } + foreach ($group_list as $id => $name) { + $sel = $id == $selected ? ' selected' : ''; + $text .= "<option value=\"$id\"$sel>$name</option>"; + } + break; + default : + $deadarray = $select[$box]; + while(list($val,$item) = each($deadarray)) { + if ($selected == $val and $selected != '') { + $sel = ' selected'; + } else { + $sel = ''; + } + $text .= "<option value=\"$val\"$sel>$item</option>"; + } + break; + } + echo ($text); } /// +/// Return human-friendly text for a value +function lookup($var, $val) { + global $db; + + switch($var) { + case 'assigned_to' : + return maskemail($db->getOne("select login from ".TBL_AUTH_USER." where user_id = $val")); + break; + } +} + + +/// /// Divide the results of a database query into multiple pages function multipages($nr, $page, $urlstr) { - global $me, $selrange, $t, $u, $db, $perm; + global $me, $selrange, $t, $u, $db, $perm; - $pages = ''; - if (!$page) $page = 1; - if ($page == 'all') { - $selrange = $nr; - $llimit = 0; - $page = 0; - } else { - if ($perm->check_auth('group', 'Users')) - $selrange = $db->getOne('select def_results from '.TBL_USER_PREF.' where user_id = '.$u); - $llimit = ($page-1)*$selrange; - } - if ($nr) $npages = ceil($nr/$selrange); - else $npages = 0; - if ($npages == 1) $pages = 1; - else { - for ($i=1; $i<=$npages; $i++) { - $pages .= $i != $page ? " <a href='$me?page=$i&$urlstr'>$i</a> " : " $i "; - $pages .= $i != $npages ? '|' : ''; - } - } + $pages = ''; + if (!$page) $page = 1; + if ($page == 'all') { + $selrange = $nr; + $llimit = 0; + $page = 0; + } else { + if ($perm->check_auth('group', 'Users')) + $selrange = $db->getOne('select def_results from '.TBL_USER_PREF.' where user_id = '.$u); + $llimit = ($page-1)*$selrange; + } + if ($nr) $npages = ceil($nr/$selrange); + else $npages = 0; + if ($npages == 1) $pages = 1; + else { + for ($i=1; $i<=$npages; $i++) { + $pages .= $i != $page ? " <a href='$me?page=$i&$urlstr'>$i</a> " : " $i "; + $pages .= $i != $npages ? '|' : ''; + } + } $t->assign(array( 'pages' => $pages, 'first' => $llimit+1, @@ -304,21 +340,21 @@ 'total' => $nr )); - return array($selrange, $llimit); + return array($selrange, $llimit); } /// /// Sets variables in the templates for the column headers to sort database results function sorting_headers($url, $headers, $order, $sort, $urlstr = '') { - global $t; + global $t; - while(list($k, $v) = each($headers)) { + while(list($k, $v) = each($headers)) { $theader[$k]['url'] = "$url?order=$v&sort=". - ($order == $v ? ($sort == 'asc' ? 'desc' : 'asc') : 'asc'). - ($urlstr ? '&'.$urlstr : ''); - $theader[$k]['color'] = $order == $v ? '#bbbbbb' : '#eeeeee'; - $theader[$k]['class'] = $order == $v ? 'selected' : ''; - } + ($order == $v ? ($sort == 'asc' ? 'desc' : 'asc') : 'asc'). + ($urlstr ? '&'.$urlstr : ''); + $theader[$k]['color'] = $order == $v ? '#bbbbbb' : '#eeeeee'; + $theader[$k]['class'] = $order == $v ? 'selected' : ''; + } $t->assign('headers', $theader); } @@ -327,94 +363,91 @@ /// (From zend.com user Rival7) function genpassword($length){ - srand((double)microtime()*1000000); + srand((double)microtime()*1000000); - $vowels = array("a", "e", "i", "o", "u"); - $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl"); - $password = ''; + $vowels = array("a", "e", "i", "o", "u"); + $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl"); + $password = ''; - $num_vowels = count($vowels); - $num_cons = count($cons); + $num_vowels = count($vowels); + $num_cons = count($cons); - for($i = 0; $i < $length; $i++){ - $password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)]; - } + for($i = 0; $i < $length; $i++){ + $password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)]; + } - return substr($password, 0, $length); + return substr($password, 0, $length); } /// /// Wrap text - Picked up somewhere on the net - probably zend.com function textwrap($text, $wrap=72, $break="\n"){ - $len = strlen($text); - if ($len > $wrap) { - $h = ''; - $lastWhite = 0; - $lastChar = 0; - $lastBreak = 0; - while ($lastChar < $len) { - $char = substr($text, $lastChar, 1); - if (($lastChar - $lastBreak > $wrap) && ($lastWhite > $lastBreak)) { - $h .= substr($text, $lastBreak, ($lastWhite - $lastBreak)) . $break; - $lastChar = $lastWhite + 1; - $lastBreak = $lastChar; - } - /* You may wish to include other characters as valid whitespace... */ - if ($char == ' ' || $char == chr(13) || $char == chr(10)) - $lastWhite = $lastChar; - $lastChar = $lastChar + 1; - } - $h .= substr($text, $lastBreak); - } - else $h = $text; - return $h; + $len = strlen($text); + if ($len > $wrap) { + $h = ''; + $lastWhite = 0; + $lastChar = 0; + $lastBreak = 0; + while ($lastChar < $len) { + $char = substr($text, $lastChar, 1); + if (($lastChar - $lastBreak > $wrap) && ($lastWhite > $lastBreak)) { + $h .= substr($text, $lastBreak, ($lastWhite - $lastBreak)) . $break; + $lastChar = $lastWhite + 1; + $lastBreak = $lastChar; + } + /* You may wish to include other characters as valid whitespace... */ + if ($char == ' ' || $char == chr(13) || $char == chr(10)) + $lastWhite = $lastChar; + $lastChar = $lastChar + 1; + } + $h .= substr($text, $lastBreak); + } + else $h = $text; + return $h; } /// /// Return a delimited list if there is more than one element in $ary, otherwise /// return the lone element as the list function delimit_list($delimiter, $ary) { - if (isset($ary[1])) return join($delimiter, $ary); - elseif (isset($ary[0])) return ($ary[0]); - else return ''; + if (isset($ary[1])) return join($delimiter, $ary); + elseif (isset($ary[0])) return ($ary[0]); + else return ''; } /// /// Check the validity of an email address /// (From zend.com user russIndr) function bt_valid_email($email) { - return eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$', $email); + return eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$', $email); } /// /// If the constant is set do a little email masking to make harvesting a little harder function maskemail($email) { - global $_sv; - if (HIDE_EMAIL && empty($_sv['uid'])) { - return '******'; - } elseif (MASK_EMAIL) { - return str_replace('@', ' at ', str_replace('.', ' dot ', $email)); - } else { - return $email; - } + if (HIDE_EMAIL && empty($_SESSION['uid'])) { + return '******'; + } elseif (MASK_EMAIL) { + return str_replace('@', ' at ', str_replace('.', ' dot ', $email)); + } else { + return $email; + } } /// /// Build the javascript for the dynamic project -> component -> version select boxes -function build_project_js($params) { - global $db, $u, $perm, $_sv, $QUERY; +function build_project_js($no_all = false) { + global $db, $u, $perm, $QUERY; - extract($params); $js = ''; $js2 = ''; // Build the javascript-powered select boxes if ($perm->have_perm('Admin')) { - $rs = $db->query("select project_id, project_name from ".TBL_PROJECT. - " where active = 1 order by project_name"); + $rs = $db->query("select project_id, project_name from ".TBL_PROJECT." where active = 1 order by project_name"); } else { $rs = $db->query(sprintf($QUERY['functions-project-js'], - delimit_list(',', $_sv['group_ids']))); + @join(',', $_SESSION['group_ids']))); } while (list($pid, $pname) = $rs->fetchRow(DB_FETCHMODE_ORDERED)) { $pname = addslashes($pname); @@ -424,8 +457,7 @@ $js2 = "closedversions['$pname'] = new Array(". ((!isset($no_all) or !$no_all) ? "new Array('','All')," : "new Array(0, 'Choose One'),"); - $rs2 = $db->query("select version_name, version_id from ".TBL_VERSION. - " where project_id = $pid and active = 1"); + $rs2 = $db->query("select version_name, version_id from ".TBL_VERSION." where project_id = $pid and active = 1"); while (list($version,$vid) = $rs2->fetchRow(DB_FETCHMODE_ORDERED)) { $version = addslashes($version); $js .= "new Array($vid,'$version'),"; @@ -440,8 +472,7 @@ // Component array $js .= "components['$pname'] = new Array("; $js .= (!isset($no_all) || !$no_all) ? "new Array('','All')," : ''; - $rs2 = $db->query("select component_name, component_id from ".TBL_COMPONENT. - " where project_id = $pid and active = 1"); + $rs2 = $db->query("select component_name, component_id from ".TBL_COMPONENT." where project_id = $pid and active = 1"); while (list($comp,$cid) = $rs2->fetchRow(DB_FETCHMODE_ORDERED)) { $comp = addslashes($comp); $js .= "new Array($cid,'$comp'),"; @@ -465,8 +496,8 @@ case 'ibase' : $retstr = delimit_list(' || ', $pieces); break; case 'fbsql' : $retstr = 'CONCAT('. delimit_list(', ', $pieces).')'; break; default : $retstr = delimit_list(' + ', $pieces); break; - } - return $retstr; + } + return $retstr; } // Dump a var @@ -481,7 +512,15 @@ // Handle a database error function handle_db_error(&$obj) { - die($obj->message.'<br>'.$obj->userinfo); + if (!defined('RAWERROR')) { + define('RAWERROR', false); + } + if (!RAWERROR) { + show_text('A database error has occurred'); + } else { + show_text(htmlentities($obj->message).'<br>'.htmlentities($obj->userinfo)); + } + exit; } // Date() wrapper for smarty @@ -490,98 +529,110 @@ } /* quoted-printable encoder function - This encoding has all non-ascii (say >127, <32 and =61 chracters) - encoded as "=" and it's hexadecimal value. Special case is space - (32 decimal) at the end of line, which is converted to =20, other- - wise it's not converted and it's returned as space (32 decimal). */ + This encoding has all non-ascii (say >127, <32 and =61 chracters) + encoded as "=" and it's hexadecimal value. Special case is space + (32 decimal) at the end of line, which is converted to =20, other- + wise it's not converted and it's returned as space (32 decimal). */ function qp_enc($input, $line_max = 76) { - // Initialize variables - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); - $eol = "\n"; - $escape = "="; - $output = ""; - // Do "dos2unix" and split $input into $lines by end of line - $lines = split("\n", str_replace("\r\n", "\n", $input)); - // Loop throught $lines - while( list(, $line) = each($lines) ) { - // Trim each line from right side - $line = rtrim($line); - // Place line length to $linlen - $linlen = strlen($line); - // Initialize $newline - $newline = ""; - // Loop throught each line and process each character of the line - for($i = 0; $i < $linlen; $i++) { - // Place each character of $line to $c - $c = substr($line, $i, 1); - // Place decimal value of $c to $dec - $dec = ord($c); - // If $c equals to space (" ") and we are at the end of line place - // space (" ") to $c - if (($dec == 32) && ($i == ($linlen - 1))) { - $c = "=20"; - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { - // Or if $c is not printable character in ascii, convert the - // character to it's quoted-printable value - $h2 = floor($dec/16); $h1 = floor($dec%16); - $c = $escape.$hex["$h2"].$hex["$h1"]; - } - // If we are at the maximum line length, add whole line (converted) - // with end of line character to $output - if ( (strlen($newline) + strlen($c)) >= $line_max ) { - $output .= $newline.$escape.$eol; - // And initialize $newline as empty + // Initialize variables + $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); + $eol = "\n"; + $escape = "="; + $output = ""; + // Do "dos2unix" and split $input into $lines by end of line + $lines = split("\n", str_replace("\r\n", "\n", $input)); + // Loop throught $lines + while( list(, $line) = each($lines) ) { + // Trim each line from right side + $line = rtrim($line); + // Place line length to $linlen + $linlen = strlen($line); + // Initialize $newline $newline = ""; - } - // Add converted (or ascii) character to $newline - $newline .= $c; - } - // Add $newline with end of line character to output - $output .= $newline.$eol; - } - // Return trimmed output - return (trim($output)); + // Loop throught each line and process each character of the line + for($i = 0; $i < $linlen; $i++) { + // Place each character of $line to $c + $c = substr($line, $i, 1); + // Place decimal value of $c to $dec + $dec = ord($c); + // If $c equals to space (" ") and we are at the end of line place + // space (" ") to $c + if (($dec == 32) && ($i == ($linlen - 1))) { + $c = "=20"; + } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { + // Or if $c is not printable character in ascii, convert the + // character to it's quoted-printable value + $h2 = floor($dec/16); $h1 = floor($dec%16); + $c = $escape.$hex["$h2"].$hex["$h1"]; + } + // If we are at the maximum line length, add whole line (converted) + // with end of line character to $output + if ( (strlen($newline) + strlen($c)) >= $line_max ) { + $output .= $newline.$escape.$eol; + // And initialize $newline as empty + $newline = ""; + } + // Add converted (or ascii) character to $newline + $newline .= $c; + } + // Add $newline with end of line character to output + $output .= $newline.$eol; + } + // Return trimmed output + return (trim($output)); } // mailer with use of quoted-printable encoding (if configured so) function qp_mail($to, $subject = 'No subject', $body, $headers = '') { - global $STRING; + global $STRING; - if ($headers != '') { - $headers .= "\n"; - // There have to be no newline at the end of $headers - } + if ($headers != '') { + $headers .= "\n"; + // There have to be no newline at the end of $headers + } if (false/*HTML_EMAIL*/) { $headers .= "Content-Type: text/html; charset=\"".$STRING['lang_charset']."\"\r\nContent-Transfer-Encoding: "; } else { $headers .= "Content-Type: text/plain; charset=\"".$STRING['lang_charset']."\"\r\nContent-Transfer-Encoding: "; } - // If configured to send MIME encoded emails - if (SEND_MIME_EMAIL) { - $retval = mail ($to, $subject, qp_enc($body), $headers. - "quoted-printable\nMIME-Version: 1.0"); - } else { - $retval = mail ($to, $subject, $body, $headers. - "8bit"); - } + // If configured to send MIME encoded emails + if (SEND_MIME_EMAIL) { + $retval = mail ($to, $subject, qp_enc($body), $headers. + "quoted-printable\nMIME-Version: 1.0"); + } else { + $retval = mail ($to, $subject, $body, $headers. + "8bit"); + } + + // Returns true if mail is eccepted for delivery, otherwise return false + return ($retval); +} + +function translate($string, $plural = false) { + global $STRING; - // Returns true if mail is eccepted for delivery, otherwise return false - return ($retval); + if (USE_GETTEXT) { + return $plural ? ngettext($string) : gettext($string); + } else { + @include_once('languages/'.LANGUAGE.'.php'); + if (!empty($STRING[$string])) return $STRING[$string]; + else return $string; + } } // Generate a testable WHERE expression for closed bugs function in_closed($column) { global $db; - - $closed_statuses = array(); - + + $closed_statuses = array(0); + foreach($db->getAll('SELECT status_id FROM '.TBL_STATUS.' WHERE bug_open = 0') as $row) { $closed_statuses[] = (int)$row['status_id']; } - - return '('.$column.' = '.(count($closed_statuses) ? join(' OR '.$column.' = ', $closed_statuses) : '0').')'; + + return '('.$column.' in ('.(@join(', ', $closed_statuses)).'))'; } // Check whether or not a status-id means BUG_CLOSED @@ -594,4 +645,14 @@ return false; } } + +// Check to make sure a bug is numeric +function check_id($id) { + if (!is_numeric($id)) { + show_text("Invalid ID"); + exit; + } + return $id; +} + ?> |