2004-12-12 03:51:51 +00:00
< ? php
/*************************************************/
/* Main Include Library for Application Database */
/*************************************************/
2004-03-15 16:22:00 +00:00
2004-12-23 01:09:20 +00:00
// get modules
2005-01-15 06:02:01 +00:00
ini_set ( " memory_limit " , " 64M " );
2006-11-25 17:24:44 +00:00
require_once ( BASE . " include/config.php " );
2005-02-07 23:56:32 +00:00
require ( BASE . " include/util.php " );
require ( BASE . " include/user.php " );
require ( BASE . " include/session.php " );
require ( BASE . " include/menu.php " );
require ( BASE . " include/html.php " );
2006-07-19 16:37:54 +00:00
require ( BASE . " include/error_log.php " );
2006-07-17 20:56:07 +00:00
require ( BASE . " include/query.php " );
2007-07-23 19:56:43 +00:00
require ( BASE . " include/table.php " );
2007-03-13 21:03:08 +00:00
require_once ( BASE . " include/objectManager.php " );
2004-03-15 16:22:00 +00:00
2006-06-26 00:44:44 +00:00
/* if magic quotes are enabled make sure the user disables them */
/* otherwise they will see all kinds of odd effects that are difficult */
/* to track down */
if ( get_magic_quotes_gpc ())
{
2008-02-23 12:06:24 +11:00
echo " <b>Please disable the magic quotes GPC PHP setting. See <a href= \" http://us2.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc \" > this page</a> for more information</b><br><br> " ;
echo " AppDB php code assumes magic quotes are disabled.<br><br> " ;
echo " Magic quotes are a bad idea for a few reasons.<br><br> " ;
2006-06-26 00:44:44 +00:00
echo " First is that php calls <b>addslashes()</b> on all \$ _POST, \$ _REQUEST and cookie variables " ;
echo " if magic quotes is enabled. " ;
2008-02-23 12:06:24 +11:00
echo " Ooooooh you say.<br> " ;
echo " <i> \" Aren't magic quotes a convienent way to protect my php code from sql injection attacks? \" </i><br><br> " ;
2007-08-03 23:27:25 +00:00
echo " No! <b>addslashes()</b> isn't adequate. You should use <b>query_escape_string()</b> or some other function " ;
2006-06-26 00:44:44 +00:00
echo " that will handle multi-byte characters. See <a href= \" http://shiflett.org/archive/184 \" >this article</a> " ;
2008-02-23 12:06:24 +11:00
echo " for a way to exploit <b>addslash()</b>ed parameters.<br><br> " ;
2007-08-03 23:27:25 +00:00
echo " A second reason is that with magic quotes enabled, due to the use of <b>query_escape_string()</b> to " ;
2006-06-26 00:44:44 +00:00
echo " protect from sql injection attacks we'll end up with variables that have been addslash()ed and " ;
2007-08-03 23:27:25 +00:00
echo " <b>query_escape_string()</b>ed. So you end up having to call stripslashes() on EVERY variable. " ;
2006-06-26 00:44:44 +00:00
exit ;
}
2006-07-07 02:36:34 +00:00
/**
* rename $_REQUEST variables to preserve backwards compatibility
* with bugzilla links and urls in emails and on google from before our
* mass rename of GPC variables to use our coding standard prefixing
*
* NOTE : we may be able to remove these backwareds compatibility changes
* in a few years , check in mid 2007 to see how many old
* links are still poping up in google then
*/
if ( isset ( $_REQUEST [ 'versionId' ]))
{
$_REQUEST [ 'iVersionId' ] = $_REQUEST [ 'versionId' ];
unset ( $_REQUEST [ 'versionId' ]);
}
if ( isset ( $_REQUEST [ 'appId' ]))
{
$_REQUEST [ 'iAppId' ] = $_REQUEST [ 'appId' ];
unset ( $_REQUEST [ 'appId' ]);
}
2006-07-08 19:05:28 +00:00
if ( isset ( $_REQUEST [ 'bug_id' ]))
2006-07-07 02:36:34 +00:00
{
2006-07-08 19:05:28 +00:00
$_REQUEST [ 'iBugId' ] = $_REQUEST [ 'bug_id' ];
unset ( $_REQUEST [ 'bug_id' ]);
2006-07-07 02:36:34 +00:00
}
if ( isset ( $_REQUEST [ 'catId' ]))
{
$_REQUEST [ 'iCatId' ] = $_REQUEST [ 'catId' ];
unset ( $_REQUEST [ 'catId' ]);
}
if ( isset ( $_REQUEST [ 'sub' ]))
{
$_REQUEST [ 'sSub' ] = $_REQUEST [ 'sub' ];
unset ( $_REQUEST [ 'sub' ]);
}
if ( isset ( $_REQUEST [ 'topic' ]))
{
$_REQUEST [ 'sTopic' ] = $_REQUEST [ 'topic' ];
unset ( $_REQUEST [ 'topic' ]);
}
2006-07-07 15:39:41 +00:00
if ( isset ( $_REQUEST [ 'mode' ]))
{
$_REQUEST [ 'sMode' ] = $_REQUEST [ 'mode' ];
unset ( $_REQUEST [ 'mode' ]);
}
2006-07-07 02:36:34 +00:00
/* End backwards compatibility code */
2004-03-15 16:22:00 +00:00
// create arrays
$sidebar_func_list = array ();
$help_list = array ();
function apidb_help_add ( $desc , $id )
{
global $help_list ;
$help_list [] = array ( $desc , $id );
}
2004-12-23 01:09:20 +00:00
// return url with docroot prepended
2004-03-15 16:22:00 +00:00
function apidb_url ( $path )
{
2004-12-23 01:09:20 +00:00
return BASE . $path ;
2004-03-15 16:22:00 +00:00
}
2004-12-23 01:09:20 +00:00
// return FULL url with docroot prepended
2004-03-15 16:22:00 +00:00
function apidb_fullurl ( $path = " " )
{
2004-12-23 01:09:20 +00:00
return BASE . $path ;
2004-03-15 16:22:00 +00:00
}
2005-07-27 02:10:56 +00:00
function appdb_fullpath ( $path )
2004-03-15 16:22:00 +00:00
{
2005-07-27 02:10:56 +00:00
/* IE : we know this file is in / yyy / xxx / include , we want to get the / yyy / xxx
/* so we call dirname on this file path twice */
$fullpath = dirname ( dirname ( __FILE__ )) . " // " . $path ;
/* get rid of potential double slashes due to string concat */
return str_replace ( " // " , " / " , $fullpath );
2004-03-15 16:22:00 +00:00
}
/*
* output the common apidb header
*/
function apidb_header ( $title = 0 )
{
2005-01-30 23:12:48 +00:00
$realname = $_SESSION [ 'current' ] -> sRealname ;
2004-03-15 16:22:00 +00:00
// Set Page Title
$page_title = $title ;
if ( $title )
2004-12-12 03:51:51 +00:00
$title = " - $title " ;
2004-03-15 16:22:00 +00:00
2007-05-26 04:05:20 +00:00
// grab the starting time
global $sPageGeneratingStartTime ;
$sPageGeneratingStartTime = microtime ();
$aStartarray = explode ( " " , $sPageGeneratingStartTime );
$sPageGeneratingStartTime = $aStartarray [ 1 ] + $aStartarray [ 0 ];
2004-03-15 16:22:00 +00:00
// Display Header
2005-02-07 23:56:32 +00:00
include ( BASE . " include/header.php " );
2004-03-15 16:22:00 +00:00
// Display Sidebar
apidb_sidebar ();
// Display Status Messages
dumpmsgbuffer ();
}
/*
* output the common apidb footer
*/
function apidb_footer ()
{
2007-05-26 04:05:20 +00:00
// grab the end of the page generating time
global $sPageGeneratingStartTime ;
$sPageGeneratingEndTime = microtime ();
$aEndarray = explode ( " " , $sPageGeneratingEndTime );
$sPageGeneratingEndTime = $aEndarray [ 1 ] + $aEndarray [ 0 ];
$sTotaltime = $sPageGeneratingEndTime - $sPageGeneratingStartTime ;
$sTotaltime = round ( $sTotaltime , 5 );
echo " <center>Page loaded in <b> $sTotaltime </b> seconds.</center> " ;
2004-03-15 16:22:00 +00:00
// Display Footer
2004-12-10 01:07:45 +00:00
if ( ! isset ( $header_disabled ))
2008-12-05 16:44:29 -06:00
include ( BASE . " include/ " . " footer.php " );
2004-03-15 16:22:00 +00:00
}
/*
* output the sidebar , calls all functions registered with apidb_sidebar_add
*/
function apidb_sidebar ()
{
global $sidebar_func_list ;
2008-12-05 16:44:29 -06:00
echo '
< div id = " sidebar " >
< ul >
' ;
2004-03-15 16:22:00 +00:00
//TURN on GLOBAL ADMIN MENU
2005-01-30 23:12:48 +00:00
if ( $_SESSION [ 'current' ] -> hasPriv ( " admin " ))
2004-03-15 16:22:00 +00:00
{
2005-02-07 23:56:32 +00:00
include ( BASE . " include/sidebar_admin.php " );
2004-12-12 03:51:51 +00:00
apidb_sidebar_add ( " global_admin_menu " );
2005-08-05 22:07:41 +00:00
} else if ( $_SESSION [ 'current' ] -> isMaintainer ()) /* if the user maintains anything, add their menus */
{
include ( BASE . " include/sidebar_maintainer_admin.php " );
apidb_sidebar_add ( " global_maintainer_admin_menu " );
2004-03-15 16:22:00 +00:00
}
// Login Menu
2005-02-07 23:56:32 +00:00
include ( BASE . " include/sidebar_login.php " );
2004-03-15 16:22:00 +00:00
apidb_sidebar_add ( " global_sidebar_login " );
// Main Menu
2005-02-07 23:56:32 +00:00
include ( BASE . " include/sidebar.php " );
2004-03-15 16:22:00 +00:00
apidb_sidebar_add ( " global_sidebar_menu " );
//LOOP and display menus
for ( $i = 0 ; $i < sizeof ( $sidebar_func_list ); $i ++ )
{
2004-12-12 03:51:51 +00:00
$func = $sidebar_func_list [ $i ];
$func ();
2004-03-15 16:22:00 +00:00
}
2008-12-05 16:44:29 -06:00
echo '
</ ul >
</ div >
' ;
2004-03-15 16:22:00 +00:00
}
2004-12-12 03:51:51 +00:00
/**
* register a sidebar menu function
2004-03-15 16:22:00 +00:00
* the supplied function is called when the sidebar is built
*/
function apidb_sidebar_add ( $funcname )
{
global $sidebar_func_list ;
array_unshift ( $sidebar_func_list , $funcname );
}
function apidb_image ( $name )
{
2004-12-23 01:09:20 +00:00
return BASE . " images/ $name " ;
2004-03-15 16:22:00 +00:00
}
2005-07-10 02:22:21 +00:00
/**
* format a date as required for HTTP by RFC 2068 sec 3.3 . 1
*/
function fHttpDate ( $iDate ) {
return gmdate ( " D, d M Y H:i:s " , $iDate ) . " GMT " ;
}
/**
* parse all the date formats required by HTTP 1.1 into PHP time values
*/
function pHttpDate ( $sDate ) {
$iDate = strtotime ( $sDate );
if ( $iDate != - 1 ) return $iDate ;
/* the RFC also requires asctime() format... */
$aTs = strptime ( $sDate , " %a %b %e %H:%M:%S %Y " );
$iDate = gmmktime ( $aTs [ 2 ], $aTs [ 1 ], $aTs [ 0 ], $aTs [ 4 ], $aTs [ 3 ], $aTs [ 5 ], 0 );
return $iDate ;
}
2004-03-15 16:22:00 +00:00
2004-12-12 03:51:51 +00:00
/**
2004-03-15 16:22:00 +00:00
* msgs will be displayed on the Next page view of the same user
*/
2007-08-03 23:27:25 +00:00
function addmsg ( $shText , $color = " black " )
2004-03-15 16:22:00 +00:00
{
2008-02-08 13:15:54 -06:00
$GLOBALS [ 'session' ] -> addmsg ( $shText , $color );
2004-03-15 16:22:00 +00:00
}
2007-07-30 01:56:39 +00:00
function purgeSessionMessages ()
{
2008-02-08 13:15:54 -06:00
$GLOBALS [ 'session' ] -> purgemsg ();
2007-07-30 01:56:39 +00:00
}
2004-03-15 16:22:00 +00:00
2004-12-12 03:51:51 +00:00
/**
2004-03-15 16:22:00 +00:00
* output msg_buffer and clear it .
*/
function dumpmsgbuffer ()
{
2008-02-08 13:15:54 -06:00
$GLOBALS [ 'session' ] -> dumpmsgbuffer ();
2008-02-08 13:18:29 -06:00
if ( is_array ( $GLOBALS [ 'session' ] -> msg ) and count ( $GLOBALS [ 'session' ] -> msg ) > 0 )
2004-12-12 03:51:51 +00:00
{
2008-02-08 13:18:29 -06:00
echo html_frame_start ( " " , " 300 " , " " , 5 );
foreach ( $GLOBALS [ 'session' ] -> msg as $msg )
{
if ( $msg [ 'color' ] == " red " )
$msg [ 'color' ] = " { $msg [ 'color' ] } ;text-decoration:blink " ;
2009-04-05 20:19:50 +02:00
echo " <div align= \" center \" class= \" session_note \" style= \" font-color: { $msg [ 'color' ] } ; \" > { $msg [ 'msg' ] } </div> " ;
2008-02-08 13:18:29 -06:00
}
echo html_frame_end ( " " );
echo " <br> \n " ;
2004-12-12 03:51:51 +00:00
}
2004-03-15 16:22:00 +00:00
}
2004-12-23 01:08:21 +00:00
2005-01-12 16:22:55 +00:00
/**
2005-01-30 23:12:48 +00:00
* Init Session ( stores user info in session )
2004-12-13 03:50:02 +00:00
*/
$session = new session ( " whq_appdb " );
$session -> register ( " current " );
2007-01-04 02:35:01 +00:00
if ( ! isset ( $_SESSION [ 'current' ]))
{
$_SESSION [ 'current' ] = new User ();
}
2005-01-30 23:12:48 +00:00
2004-12-18 01:56:08 +00:00
// if we are debugging we need to see all errors
2005-01-30 23:12:48 +00:00
if ( $_SESSION [ 'current' ] -> showDebuggingInfos ()) error_reporting ( E_ALL ^ E_NOTICE );
2007-01-06 05:03:58 +00:00
// include filter.php to filter all REQUEST input
require ( BASE . " include/filter.php " );
2004-03-15 16:22:00 +00:00
?>