|
From: Benjamin C. <bc...@us...> - 2002-01-23 14:22:09
|
Update of /cvsroot/phpbt/phpbt
In directory usw-pr-cvs1:/tmp/cvs-serv31784
Modified Files:
include.php
Log Message:
Moved support functions from include.php to inc/functions.php
Index: include.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/include.php,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- include.php 2002/01/16 09:43:17 1.90
+++ include.php 2002/01/23 14:22:06 1.91
@@ -1,6 +1,6 @@
<?php
-// include.php - Set up global variables and functions
+// include.php - Set up global variables
// ------------------------------------------------------------------------
// Copyright (c) 2001 The phpBugTracker Group
// ------------------------------------------------------------------------
@@ -43,6 +43,9 @@
exit();
}
+// Grab the global functions
+include (INSTALL_PATH.'/'.INCLUDE_PATH.'inc/functions.php');
+
class dbclass extends DB_Sql {
var $classname = 'dbclass';
var $Host = DB_HOST;
@@ -134,8 +137,8 @@
$me2 = $HTTP_SERVER_VARS['REQUEST_URI'];
$selrange = 30;
$now = time();
-$_gv = &$HTTP_GET_VARS;
-$_pv = &$HTTP_POST_VARS;
+$_gv =& $HTTP_GET_VARS;
+$_pv =& $HTTP_POST_VARS;
$all_db_fields = array(
'bug_id' => 'ID',
@@ -217,288 +220,9 @@
'error' => '',
'loginerror' => '',
'template_path' => INCLUDE_PATH.'templates/'.THEME));
-
-// End classes -- Begin helper functions
-
-///
-/// Show text to the browser - escape hatch
-function show_text($text, $iserror = false) {
- global $t;
-
- $t->set_file('content','error.html');
- if (!$iserror) $t->set_var('text',$text);
- else $t->set_var('text',"<font color=red>$text</font>");
-}
-
-$select['priority'] = array(
- 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($box, $value = '', $project = 0) {
- global $q, $select, $perm, $auth;
-
- //create hash to map tablenames
- $cfgDatabase = array(
- 'group' => TBL_AUTH_GROUP,
- 'project' => TBL_PROJECT,
- 'component' => TBL_COMPONENT,
- 'status' => TBL_STATUS,
- 'resolution' => TBL_RESOLUTION,
- 'severity' => TBL_SEVERITY,
- 'version' => TBL_VERSION
- );
-
- $text = '';
- if (isset($cfgDatabase[$box])) {
- $querystart = "select {$box}_id, {$box}_name from $cfgDatabase[$box]";
- $queries = array(
- 'group' => $querystart.' where group_name <> \'User\' order by group_name',
- 'severity' => $querystart.' where sort_order > 0 order by sort_order',
- 'status' => $querystart.' where sort_order > 0 order by sort_order',
- 'resolution' => $querystart.' where sort_order > 0 order by sort_order',
- 'project' => $perm->have_perm('Admin')
- ? $querystart." where active > 0 order by {$box}_name"
- : "select p.{$box}_id, {$box}_name from $cfgDatabase[$box] p left join ".
- TBL_PROJECT_GROUP.' pg using(project_id) where active > 0
- and (pg.project_id is null or pg.group_id in ('.
- delimit_list(',', $auth->auth['group_ids']).')) group by
- p.project_id, p.project_name order by project_name',
- 'component' => $querystart." where project_id = $project order by {$box}_name",
- 'version' => $querystart." where project_id = $project order by {$box}_id desc"
- );
- }
-
- switch($box) {
- case 'group' :
- if ($project) { // If we are building for project admin page
- if (!count($value) or (count($value) && in_array(0, $value))) {
- $sel = ' selected';
- } else {
- $sel = '';
- }
- $text = "<option value=\"all\"$sel>All Groups</option>";
- }
- $q->query($queries[$box]);
- while ($row = $q->grab()) {
- if (count($value) && in_array($row[$box.'_id'], $value)) $sel = ' selected';
- else $sel = '';
- $text .= '<option value="'.
- $row[$box.'_id']."\"$sel>".$row[$box.'_name'].'</option>';
- }
- break;
- case 'severity' :
- case 'status' :
- case 'resolution' :
- case 'project' :
- case 'component' :
- case 'version' :
- $q->query($queries[$box]);
- while ($row = $q->grab()) {
- if ($value == $row[$box.'_id'] and $value != '') $sel = ' selected';
- else $sel = '';
- $text .= '<option value="'.
- $row[$box.'_id']."\"$sel>".$row[$box.'_name'].'</option>';
- }
- break;
- case 'os' :
- $q->query("select {$box}_id, {$box}_name, regex from ".TBL_OS." order by sort_order");
- while ($row = $q->grab()) {
- if ($value == '' and isset($row['Regex']) and
- preg_match($row['Regex'],$GLOBALS['HTTP_USER_AGENT'])) $sel = ' selected';
- elseif ($value == $row[$box.'_id']) $sel = ' selected';
- else $sel = '';
- $text .= '<option value="'.
- $row[$box.'_id']."\"$sel>".$row[$box.'_name']."</option>";
- }
- break;
- case 'owner' :
- $q->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 group_name = 'Developer' order by login");
- while ($row = $q->grab()) {
- if ($value == $row['user_id']) $sel = ' selected';
- else $sel = '';
- $text .= "<option value=\"{$row['user_id']}\"$sel>{$row['login']}</option>";
- }
- break;
- case 'bug_cc' :
- $q->query('select b.user_id, login from '.TBL_BUG_CC.' b left join '.
- TBL_AUTH_USER." using(user_id) where bug_id = $value");
- while (list($uid, $user) = $q->grab()) {
- $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(INSTALL_PATH.'/'.INCLUDE_PATH.'languages');
- while (false !== ($file = readdir($dir))) {
- if ($file != '.' && $file != '..' && $file != 'CVS') {
- $file = str_replace('.php', '', $file);
- if ($file == $value) {
- $sel = ' selected';
- } else {
- $sel = '';
- }
- $text .= "<option value=\"$file\"$sel>$file</option>";
- }
- }
- break;
- case 'THEME' :
- $dir = opendir(INSTALL_PATH.'/'.INCLUDE_PATH.'templates');
- while (false !== ($file = readdir($dir))) {
- if ($file != '.' && $file != '..' && $file != 'CVS') {
- $file = str_replace('.php', '', $file);
- if ($file == $value) {
- $sel = ' selected';
- } else {
- $sel = '';
- }
- $text .= "<option value=\"$file\"$sel>$file</option>";
- }
- }
- break;
- default :
- $deadarray = $select[$box];
- while(list($val,$item) = each($deadarray)) {
- if ($value == $val and $value != '') $sel = ' selected';
- else $sel = '';
- $text .= "<option value=\"$val\"$sel>$item</option>";
- }
- break;
- }
- return $text;
-}
-
-///
-/// Divide the results of a database query into multiple pages
-function multipages($nr, $page, $urlstr) {
- global $me, $selrange;
-
- $pages = '';
- if (!$page) $page = 1;
- if ($page == 'all') {
- $selrange = $nr;
- $llimit = 0;
- $page = 0;
- } else {
- #$selrange = 60;
- $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 ? '|' : '';
- }
- }
- return array($selrange, $llimit, $npages, $pages);
-}
-
-///
-/// Sets variables in the templates for the column headers to sort database results
-function sorting_headers($url, $headers, $order, $sort, $urlstr = '') {
- global $t;
-
- while(list($k, $v) = each($headers)) {
- $t->set_var($k.'url', "$url?order=$v&sort=".
- ($order == $v ? ($sort == 'asc' ? 'desc' : 'asc') : 'asc').
- ($urlstr ? '&'.$urlstr : ''));
- $t->set_var($k.'color', $order == $v ? '#bbbbbb' : '#eeeeee');
- $t->set_var($k.'class', $order == $v ? 'head-selected' : 'head');
- }
-}
-
-///
-/// Generates a somewhat random pronounceable password $length letters long
-/// (From zend.com user Rival7)
-function genpassword($length){
-
- 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 = '';
-
- $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)];
- }
-
- 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;
-}
-
-///
-/// 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 '';
-}
-
-///
-/// Check the validity of an email address
-/// (From zend.com user russIndr)
-function valid_email($email) {
- return eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $email);
-}
-
-///
-/// If the constant is set do a little email masking to make harvesting a little harder
-function maskemail($email) {
- global $auth;
-
- if (HIDE_EMAIL && empty($auth->auth['uid'])) {
- return '******';
- } elseif (MASK_EMAIL) {
- return str_replace('@', ' at ', str_replace('.', ' dot ', $email));
- } else {
- return $email;
- }
-}
+// End classes -- Begin page
-// Begin every page with a page_open
if (!defined('NO_AUTH')) {
session_start();
$_sv =& $HTTP_SESSION_VARS;
@@ -533,4 +257,4 @@
$op = isset($_gv['op']) ? $_gv['op'] : (isset($_pv['op']) ? $_pv['op'] : '');
-?>
\ No newline at end of file
+?>
|