--- nfo/site/htdocs/inc/common/common.php.inc 2004/08/30 04:19:20 1.3 +++ nfo/site/htdocs/inc/common/common.php.inc 2004/09/03 22:44:57 1.8 @@ -4,7 +4,7 @@ --- Setup and common functions include file. -------------------------------------------------------------------------------- --- rabit, 04:31 24.08.2004 ---- $Id: common.php.inc,v 1.3 2004/08/30 04:19:20 rabit Exp $ +--- $Id: common.php.inc,v 1.8 2004/09/03 22:44:57 joko Exp $ ------------------------------------------------------------------------------*/ //------------------------------------------------------------------------------ @@ -24,7 +24,7 @@ } // The starting entry in the benchmark steps list: -common_benchmark_addstep('COMMON: start'); +common_benchmark_addstep('common: start'); //---------------------------------------------------------- //- Developer host setups: @@ -59,11 +59,19 @@ unset($hostsetups); +common_benchmark_addstep('common: host setup'); + //---------------------------------------------------------- //- Site variable setups: +// Paths: $common['site']['docroot'] = $_SERVER['DOCUMENT_ROOT'] . $common['hostsetup']['urlrel']; $common['site']['incroot'] = $common['site']['docroot'] . 'inc/'; +$common['site']['libroot'] = $common['site']['docroot'] . 'libs/'; + +// URLs: +$common['site']['url'] = 'http://' . $_SERVER['HTTP_HOST'] . $common['hostsetup']['urlrel']; +$common['site']['gfxurl'] = $common['site']['url'] . 'gfx/'; //---------------------------------------------------------- //- Page variable setups: @@ -71,64 +79,75 @@ $common['page']['filename'] = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/') + 1); $common['page']['url'] = $_SERVER['PHP_SELF']; -common_benchmark_addstep('COMMON: setup'); +common_benchmark_addstep('common: site/page setup'); //------------------------------------------------------------------------------ //- Includes: //common_include('cfg/cfg.php.inc'); -//common_benchmark_addstep('COMMON: CFG included'); +//common_benchmark_addstep('common: CFG included'); -common_include('xmlcp/xmlcp.php.inc'); -common_benchmark_addstep('COMMON: XMLCP included'); +include($common['site']['incroot'] . 'xmlcp/xmlcp.php.inc'); +common_benchmark_addstep('common: XMLCP included'); -common_include('cms/cms.php.inc'); -common_benchmark_addstep('COMMON: CMS included'); +include($common['site']['incroot'] . 'cms/cms.php.inc'); +common_benchmark_addstep('common: CMS included'); //------------------------------------------------------------------------------ //- MySQL connection: -$common['dbc']['dbconnected'] = common_dbc_connectdb(); - -common_benchmark_addstep('COMMON: connect database'); +common_dbc_connectdb(); +common_benchmark_addstep('common: connect database'); //------------------------------------------------------------------------------ //- Session setup: -// Neither proxies, nor the clients are allowed to cache session data: -session_cache_limiter('nocache'); +if ($common['client']['session_enabled']) { -// This is neccessary to make the $_SESSION global available: -session_start(); + // Neither proxies, nor the clients are allowed to cache session data: + session_cache_limiter('nocache'); + + // This is neccessary to make the $_SESSION global available: + session_start(); + +} -common_benchmark_addstep('COMMON: session init'); +common_benchmark_addstep('common: session init'); if(!isset($_SESSION['common_sessiondata'])) { // The session variable isn't set, create it: - common_benchmark_addstep('COMMON: New session: start'); + common_benchmark_addstep('common: New session: start'); $common_sessiondata = array( 'birthtime' => time(), 'firstrequest' => 1, // Mark the very first page request. + // Empty user data sub array: + 'userdata' => array( + 'name' => '', + 'password' => '', + 'authorised' => false, + ), + + // Content related additional data: 'additionaldata' => array() ); - common_benchmark_addstep('COMMON: New session: create session'); + common_benchmark_addstep('common: New session: create session'); // Protocol the visitors hit and store the columns insertion ID: $common_sessiondata['hit_id'] = common_protocolhit(); - common_benchmark_addstep('COMMON: New session: protocol hit'); + common_benchmark_addstep('common: New session: protocol hit'); // Store a reference to the session data array: $_SESSION['common_sessiondata'] = &$common_sessiondata; - common_benchmark_addstep('COMMON: New session: store session/end'); + common_benchmark_addstep('common: New session: store session/end'); } else { @@ -142,15 +161,74 @@ $sql = "UPDATE hits SET requestcount=requestcount+1 WHERE id='" . $common_sessiondata['hit_id'] . "';"; - mysql_query($sql); + common_dbc_query($sql); - common_benchmark_addstep('COMMON: session/hit data updated'); + common_benchmark_addstep('common: session/hit data updated'); } //------------------------------------------------------------------------------ +//- URL parameter flags and variables: + +if(isset($_GET['devstate'])) $common_sessiondata['userdata']['devstate'] = $_GET['devstate']; + +if(isset($common_sessiondata['userdata']['devstate'])) $common['hostsetup']['devstate'] = $common_sessiondata['userdata']['devstate']; + +//------------------------------------------------------------------------------ //- Functions: +function common_checkauthorisation() { + +global $common_sessiondata; + + $username = $common_sessiondata['userdata']['name']; + $password = $common_sessiondata['userdata']['password']; + + if((strlen($username) < 2) || (strlen($password) < 2)) return false; + + $sql = "SELECT id, rights, logincount, lastlogin FROM users WHERE name='$username' AND password='$password';"; + + $res = common_dbc_query($sql); + + if(!$res) return false; + + if(!($row = mysql_fetch_row($res))) return false; + + // Congratulations - authorisation suxxessful! + + $logintime = time(); + + $userid = $row[0]; + $rights = $row[1]; + $logincount = $row[2] + 1; + $lastlogin = $row[3]; + + $common_sessiondata['userdata']['authorised'] = true; + + $common_sessiondata['userdata']['id'] = $userid; + $common_sessiondata['userdata']['lastlogin'] = $lastlogin; + $common_sessiondata['userdata']['rights'] = $rights; + + // Break if the user already has authorised in this session: + if(isset($common_sessiondata['userdata']['logintime'])) return false; + + $common_sessiondata['userdata']['logincount'] = $logincount; + $common_sessiondata['userdata']['logintime'] = $logintime; + +// print_r($common_sessiondata['userdata']); + + $sql = "UPDATE users SET logincount='$logincount', lastlogin=FROM_UNIXTIME('$logintime') WHERE id='$userid';"; + + $res = common_dbc_query($sql); + + if(!$res) return false; + + return true; + +} + +//------------------------------------------------------------------------------ + function common_protocolhit() { global $common, $common_sessiondata; @@ -160,12 +238,11 @@ $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); $sessionid = session_id(); $unixtime = $common_sessiondata['birthtime']; - $timestamp = date('YmdHis', $common_sessiondata['birthtime']); $useragent = $_SERVER['HTTP_USER_AGENT']; - $sql = "INSERT INTO hits (id, timestamp, address, entryurl, referer, sessionid, useragent, requestcount) VALUES (DEFAULT, FROM_UNIXTIME('$unixtime'), '$address', '$entryurl', '$referer', '$sessionid', '$useragent', '1');"; + $sql = "INSERT INTO hits (id, timestamp, address, entryurl, referer, sessionid, useragent, requestcount) VALUES (NULL, FROM_UNIXTIME('$unixtime'), '$address', '$entryurl', '$referer', '$sessionid', '$useragent', '1');"; - $res = mysql_query($sql); + $res = common_dbc_query($sql); if(!$res) return false; @@ -174,7 +251,6 @@ } //---------------------------------------------------------- - //- Database functions: function common_dbc_connect() { @@ -216,328 +292,51 @@ function common_dbc_connectdb() { - return (common_dbc_connect() && common_dbc_selectdb()); - -} - -//---------------------------------------------------------- - -//- File functions: - -function common_include($filename) { - global $common; - return include($common['site']['incroot'] . $filename); - -} - -//---------------------------------------------------------- - -//- XMLCP setup: - -xmlcp_registertagcallbacks('b', 'common_cb_xmlcp_start_bold', 'common_cb_xmlcp_end_bold'); -xmlcp_registertagcallbacks('h', 'common_cb_xmlcp_start_headline', 'common_cb_xmlcp_end_headline'); -xmlcp_registertagcallbacks('p', 'common_cb_xmlcp_start_paragraph', 'common_cb_xmlcp_end_paragraph'); -xmlcp_registertagcallbacks('page', 'common_cb_xmlcp_start_page', 'common_cb_xmlcp_end_page'); - -function common_cb_xmlcp_end_bold($h_parser, $tagname) { - -global $xmlcp_cdata; - - $xmlcp_cdata .= ''; - -} - -function common_cb_xmlcp_start_bold($h_parser, $tagname, $attribs) { - -global $xmlcp_cdata; - - $xmlcp_cdata .= ''; - -} - -function common_cb_xmlcp_end_page($h_parser, $tagname) { + $common['dbc']['dbconnected'] = (common_dbc_connect() && common_dbc_selectdb()); -} - -function common_cb_xmlcp_start_page($h_parser, $tagname, $attribs) { + return $common['dbc']['dbconnected']; } -function common_cb_xmlcp_end_headline($h_parser, $tagname) { - -global $xmlcp_cdata; - - common_headline(trim($xmlcp_cdata)); - - $xmlcp_cdata = ''; - -} - -function common_cb_xmlcp_start_headline($h_parser, $tagname, $attribs) { - -global $xmlcp_cdata; - - $xmlcp_cdata = ''; - -} - -function common_cb_xmlcp_end_paragraph($h_parser, $tagname) { - -global $xmlcp_cdata; - - common_paragraph(trim($xmlcp_cdata)); - - $xmlcp_cdata = ''; - -} - -function common_cb_xmlcp_start_paragraph($h_parser, $tagname, $attribs) { - -global $xmlcp_cdata; - - $xmlcp_cdata = ''; - -} - -//---------------------------------------------------------- - -//- ML functions: - -function common_codeparagraph($contents) { - - echo '
-
-' . $contents . '
-
-
-Page execution time: ' . round($timediff * 100000) / 100 . ' ms.
- |
-- | -
-• ' . $title . '
-' . ($additionalcontents ? $additionalcontents . '
-' : '') . '
-' . $contents . ' -
- -'; - +//- Utility functions: +function common_get_baseurl() { + $baseurl = "http://" . $_SERVER['SERVER_NAME'] . "" . $_SERVER['SCRIPT_NAME'] . "/"; + return $baseurl; } //------------------------------------------------------------------------------ -common_benchmark_addstep('COMMON: end'); +common_benchmark_addstep('common: end'); //------------------------------------------------------------------------------