From 78e54e1909506cb6606354a4b6e9120f7c4475b7 Mon Sep 17 00:00:00 2001 From: Robin Date: Sat, 15 May 2010 22:29:14 +0200 Subject: [PATCH] fixes in log and ocs --- inc/lib_base.php | 25 ++++++++++++++++++++++++- inc/lib_config.php | 4 +++- inc/lib_log.php | 9 ++------- inc/lib_ocs.php | 17 +++++------------ ocs/v1.php | 1 + 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/inc/lib_base.php b/inc/lib_base.php index 6eef3affd4..303809bdd6 100755 --- a/inc/lib_base.php +++ b/inc/lib_base.php @@ -423,7 +423,6 @@ class OC_DB { static function numrows($result) { $result->numRows(); } - /** * Returning number of affected rows * @@ -433,6 +432,30 @@ class OC_DB { self::$DBConnection->affectedRows(); } + /** + * get a field from the resultset + * + * @param resultset $result + * @param int $i + * @param int $field + * @return unknown + */ + static function result($result, $i, $field) { + $tmp=$result->fetchRow(MDB2_FETCHMODE_ASSOC,$i); + $tmp=$tmp[$field]; + return($tmp); + } + + /** + * get data-array from resultset + * + * @param resultset $result + * @return data + */ + static function fetch_assoc($result){ + return $result->fetchRow(MDB2_FETCHMODE_ASSOC); + } + /** * Freeing resultset (performance) * diff --git a/inc/lib_config.php b/inc/lib_config.php index a6567bc829..986d12f4dc 100755 --- a/inc/lib_config.php +++ b/inc/lib_config.php @@ -292,10 +292,12 @@ class OC_CONFIG{ ); CREATE TABLE 'log' ( + `id` INTEGER ASC DEFAULT '' NOT NULL, 'timestamp' int(11) NOT NULL, 'user' varchar(250) NOT NULL, 'type' int(11) NOT NULL, - 'message' varchar(250) NOT NULL + 'message' varchar(250) NOT NULL, + PRIMARY KEY ('id') ); diff --git a/inc/lib_log.php b/inc/lib_log.php index 2a8a91be40..5e47c4ee16 100755 --- a/inc/lib_log.php +++ b/inc/lib_log.php @@ -61,11 +61,8 @@ class OC_LOG { global $CONFIG_DATEFORMAT; echo('
'); - $result = OC_DB::query('select timestamp,user,type,message from log order by timestamp desc limit 20'); - $count=OC_DB::numrows($result); - for ($i=0; $i < $count;$i++) { - - $entry=OC_DB::fetch_assoc($result); + $result = OC_DB::select('select timestamp,user,type,message from log order by timestamp desc limit 20'); + foreach($result as $entry){ echo(''); echo(''); echo(''); @@ -74,8 +71,6 @@ class OC_LOG { echo(''); } echo('
'.date($CONFIG_DATEFORMAT,$entry['timestamp']).''.OC_LOG::$TYPE[$entry['type']].'
'); - OC_DB::free_result($result); - } } diff --git a/inc/lib_ocs.php b/inc/lib_ocs.php index 97c412c419..b36c4937e0 100755 --- a/inc/lib_ocs.php +++ b/inc/lib_ocs.php @@ -166,9 +166,6 @@ class OC_OCS { * @return username string */ private static function checkpassword($forceuser=true) { - global $CONFIG_ADMINLOGIN; - global $CONFIG_ADMINPASSWORD; - //valid user account ? if(isset($_SERVER['PHP_AUTH_USER'])) $authuser=$_SERVER['PHP_AUTH_USER']; else $authuser=''; if(isset($_SERVER['PHP_AUTH_PW'])) $authpw=$_SERVER['PHP_AUTH_PW']; else $authpw=''; @@ -182,7 +179,7 @@ class OC_OCS { $identifieduser=''; } }else{ - if(($authuser<>$CONFIG_ADMINLOGIN) or ($authpw<>$CONFIG_ADMINPASSWORD)) { + if(!OC_USER::login($authuser,$authpw)){ if($forceuser){ header('WWW-Authenticate: Basic realm="your valid user account or api key"'); header('HTTP/1.0 401 Unauthorized'); @@ -351,11 +348,8 @@ class OC_OCS { * @return string xml/json */ private static function personcheck($format,$login,$passwd) { - global $CONFIG_ADMINLOGIN; - global $CONFIG_ADMINPASSWORD; - if($login<>''){ - if(($login==$CONFIG_ADMINLOGIN) and ($passwd==$CONFIG_ADMINPASSWORD)) { + if(OC_USER::login($login,$passwd)){ $xml['person']['personid']=$login; echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'person','check',2)); }else{ @@ -386,13 +380,12 @@ class OC_OCS { $totalcount=$entry['co']; OC_DB::free_result($result); - $result = OC_DB::query('select id,timestamp,user,type,message from log order by timestamp desc limit '.($page*$pagesize).','.$pagesize); - $itemscount=OC_DB::numrows($result); + $result = OC_DB::select('select id,timestamp,user,type,message from log order by timestamp desc limit '.($page*$pagesize).','.$pagesize); + $itemscount=count($result); $url='http://'.substr($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'],0,-11).''; $xml=array(); - for ($i=0; $i < $itemscount;$i++) { - $log=OC_DB::fetch_assoc($result); + foreach($result as $i=>$log) { $xml[$i]['id']=$log['id']; $xml[$i]['personid']=$log['user']; $xml[$i]['firstname']=$log['user']; diff --git a/ocs/v1.php b/ocs/v1.php index 14d56bbec6..2419658ff1 100755 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -22,6 +22,7 @@ */ require_once('../inc/lib_base.php'); +ob_clean(); OC_OCS::handle(); ?>