Index: sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-db2.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-db2.inc.php	(revision 34)
+++ sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-db2.inc.php	(revision 8222)
@@ -1,5 +1,5 @@
 <?php
 /* 
-V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
@@ -59,5 +59,5 @@
 	function perf_db2(&$conn)
 	{
-		$this->conn =& $conn;
+		$this->conn = $conn;
 	}
 	
Index: sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-informix.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-informix.inc.php	(revision 34)
+++ sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-informix.inc.php	(revision 8222)
@@ -1,5 +1,5 @@
 <?php
 /* 
-V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
@@ -64,5 +64,5 @@
 	function perf_informix(&$conn)
 	{
-		$this->conn =& $conn;
+		$this->conn = $conn;
 	}
 
Index: sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mssql.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mssql.inc.php	(revision 34)
+++ sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mssql.inc.php	(revision 8222)
@@ -2,5 +2,5 @@
 
 /* 
-V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
@@ -72,5 +72,5 @@
 			//$this->explain = false;
 		}
-		$this->conn =& $conn;
+		$this->conn = $conn;
 	}
 	
@@ -97,8 +97,8 @@
 		$save = $ADODB_FETCH_MODE;
 		$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-		$rs =& $this->conn->Execute($sql);
+		$rs = $this->conn->Execute($sql);
 		//adodb_printr($rs);
 		$ADODB_FETCH_MODE = $save;
-		if ($rs) {
+		if ($rs && !$rs->EOF) {
 			$rs->MoveNext();
 			$s .= '<table bgcolor=white border=0 cellpadding="1" callspacing=0><tr><td nowrap align=center> Rows<td nowrap align=center> IO<td nowrap align=center> CPU<td align=left> &nbsp; &nbsp; Plan</tr>';
Index: sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-oci8.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-oci8.inc.php	(revision 34)
+++ sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-oci8.inc.php	(revision 8222)
@@ -1,5 +1,5 @@
 <?php
 /* 
-V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
@@ -16,5 +16,8 @@
 if (!defined('ADODB_DIR')) die();
 
+
 class perf_oci8 extends ADODB_perf{
+
+	var $noShowIxora = 15; // if the sql for suspicious sql is taking too long, then disable ixora
 	
 	var $tablesSQL = "select segment_name as \"tablename\", sum(bytes)/1024 as \"size_in_k\",tablespace_name as \"tablespace\",count(*) \"extents\" from sys.user_extents 
@@ -22,4 +25,5 @@
 	 
 	var $version;
+	
 	var $createTableSQL = "CREATE TABLE adodb_logsql (
 		  created date NOT NULL,
@@ -69,4 +73,5 @@
 	
 	'Data Cache',
+	
 		'data cache buffers' => array( 'DATAC',
 		"select a.value/b.value  from v\$parameter a, v\$parameter b 
@@ -76,6 +81,22 @@
 			"select value from v\$parameter where name='db_block_size'",
 			'' ),			
+	
 	'Memory Pools',
-		'data cache size' => array('DATAC',
+		'Mem Max Target (11g+)' => array( 'DATAC',
+		"select value from v\$parameter where name = 'memory_max_target'",
+			'The memory_max_size is the maximum value to which memory_target can be set.' ),
+	'Memory target (11g+)' => array( 'DATAC',
+		"select value from v\$parameter where name = 'memory_target'",
+			'If memory_target is defined then SGA and PGA targets are consolidated into one memory_target.' ),
+		'SGA Max Size' => array( 'DATAC',
+		"select nvl(value,0)/1024.0/1024 || 'M' from v\$parameter where name = 'sga_max_size'",
+			'The sga_max_size is the maximum value to which sga_target can be set.' ),
+	'SGA target' => array( 'DATAC',
+		"select nvl(value,0)/1024.0/1024 || 'M'  from v\$parameter where name = 'sga_target'",
+			'If sga_target is defined then data cache, shared, java and large pool size can be 0. This is because all these pools are consolidated into one sga_target.' ),
+	'PGA aggr target' => array( 'DATAC',
+		"select nvl(value,0)/1024.0/1024 || 'M' from v\$parameter where name = 'pga_aggregate_target'",
+			'If pga_aggregate_target is defined then this is the maximum memory that can be allocated for cursor operations such as sorts, group by, joins, merges. When in doubt, set it to 20% of sga_target.' ),
+	'data cache size' => array('DATAC',
 			"select value from v\$parameter where name = 'db_cache_size'",
 			'db_cache_size' ),
@@ -90,8 +111,5 @@
 			'this pool is for large mem allocations (not because it is larger than shared pool), for MTS sessions, parallel queries, io buffers (large_pool_size) ' ),
 
-		'pga buffer size' => array('CACHE',			
-			"select value from v\$parameter where name='pga_aggregate_target'",
-			'program global area is private memory for sorting, and hash and bitmap merges - since oracle 9i (pga_aggregate_target)' ),
-
+		'dynamic memory usage' => array('CACHE', "select '-' from dual", '=DynMemoryUsage'),
 		
 		'Connections',
@@ -110,5 +128,5 @@
 		'Percentage of data cache actually in use - should be over 85%'),
 		
-				'shared pool utilization ratio' => array('RATIOU', 
+		'shared pool utilization ratio' => array('RATIOU', 
 		'select round((sga.bytes/case when p.value=0 then sga.bytes else to_number(p.value) end)*100,2)
 		from v$sgastat sga, v$parameter p
@@ -126,6 +144,6 @@
 			'max in-mem sort_area_size (per query), uses memory in pga' ),
 
-		'pga usage at peak' => array('RATIOU',
-		'=PGA','Mb utilization at peak transactions (requires Oracle 9i+)'),
+		/*'pga usage at peak' => array('RATIOU',
+		'=PGA','Mb utilization at peak transactions (requires Oracle 9i+)'),*/
 	'Transactions',
 		'rollback segments' => array('ROLLBACK',
@@ -157,5 +175,23 @@
 			"select value from v\$parameter where name = 'optimizer_index_cost_adj'",
 			'=WarnPageCost'),
-		
+	'Waits',
+		'Recent wait events' => array('WAITS','select \'Top 5 events\' from dual','=TopRecentWaits'),
+//		'Historical wait SQL' => array('WAITS','select \'Last 2 days\' from dual','=TopHistoricalWaits'), -- requires AWR license
+	'Backup',
+		'Achivelog Mode' => array('BACKUP', 'select log_mode from v$database', '=LogMode'),
+	
+		'DBID' => array('BACKUP','select dbid from v$database','Primary key of database, used for recovery with an RMAN Recovery Catalog'),
+		'Archive Log Dest' => array('BACKUP', "SELECT NVL(v1.value,v2.value) 
+FROM v\$parameter v1, v\$parameter v2 WHERE v1.name='log_archive_dest' AND v2.name='log_archive_dest_10'", ''),
+	
+		'Flashback Area' => array('BACKUP', "select nvl(value,'Flashback Area not used') from v\$parameter where name=lower('DB_RECOVERY_FILE_DEST')", 'Flashback area is a folder where all backup data and logs can be stored and managed by Oracle. If Error: message displayed, then it is not in use.'),
+	
+		'Flashback Usage' => array('BACKUP', "select nvl('-','Flashback Area not used') from v\$parameter where name=lower('DB_RECOVERY_FILE_DEST')", '=FlashUsage', 'Flashback area usage.'),
+		
+		'Control File Keep Time' => array('BACKUP', "select value from v\$parameter where name='control_file_record_keep_time'",'No of days to keep RMAN info in control file.  Recommended set to x2 or x3 times the frequency of your full backup.'),
+		'Recent RMAN Jobs' => array('BACKUP', "select '-' from dual", "=RMAN"),
+		
+		//		'Control File Keep Time' => array('BACKUP', "select value from v\$parameter where name='control_file_record_keep_time'",'No of days to keep RMAN info in control file. I recommend it be set to x2 or x3 times the frequency of your full backup.'),
+      'Storage', 'Tablespaces' => array('TABLESPACE', "select '-' from dual", "=TableSpace"),
 		false
 		
@@ -165,52 +201,175 @@
 	function perf_oci8(&$conn)
 	{
+	global $gSQLBlockRows;
+	
+		$gSQLBlockRows = 1000;
 		$savelog = $conn->LogSQL(false);	
 		$this->version = $conn->ServerInfo();
 		$conn->LogSQL($savelog);	
-		$this->conn =& $conn;
-	}
-	
+		$this->conn = $conn;
+	}
+	
+	function LogMode()
+	{
+		$mode = $this->conn->GetOne("select log_mode from v\$database");
+		
+		if ($mode == 'ARCHIVELOG') return 'To turn off archivelog:<br>
+	<pre><font size=-2>
+        SQLPLUS> connect sys as sysdba;
+        SQLPLUS> shutdown immediate;
+
+        SQLPLUS> startup mount exclusive;
+        SQLPLUS> alter database noarchivelog;
+        SQLPLUS> alter database open;
+</font></pre>';
+		
+		return 'To turn on archivelog:<br>
+	<pre><font size=-2>
+        SQLPLUS> connect sys as sysdba;
+        SQLPLUS> shutdown immediate;
+
+        SQLPLUS> startup mount exclusive;
+        SQLPLUS> alter database archivelog;
+        SQLPLUS> archive log start;
+        SQLPLUS> alter database open;
+</font></pre>';
+	}
+	
+	function TopRecentWaits()
+	{
+		
+		$rs = $this->conn->Execute("select * from (   
+		select event, round(100*time_waited/(select sum(time_waited) from v\$system_event where wait_class <> 'Idle'),1) \"% Wait\",
+    total_waits,time_waited, average_wait,wait_class from v\$system_event where wait_class <> 'Idle' order by 2 desc
+	) where rownum <=5");
+		
+		$ret = rs2html($rs,false,false,false,false);		
+		return "&nbsp;<p>".$ret."&nbsp;</p>";
+		
+	}
+	
+	function TopHistoricalWaits()
+	{
+		$days = 2;
+		
+		$rs = $this->conn->Execute("select * from (   SELECT
+         b.wait_class,B.NAME,
+        round(sum(wait_time+TIME_WAITED)/1000000) waitsecs,
+        parsing_schema_name,
+        C.SQL_TEXT, a.sql_id
+FROM    V\$ACTIVE_SESSION_HISTORY A
+        join V\$EVENT_NAME B  on  A.EVENT# = B.EVENT#
+       join V\$SQLAREA C  on  A.SQL_ID = C.SQL_ID
+WHERE   A.SAMPLE_TIME BETWEEN sysdate-$days and sysdate
+       and parsing_schema_name not in ('SYS','SYSMAN','DBSNMP','SYSTEM')
+GROUP BY b.wait_class,parsing_schema_name,C.SQL_TEXT, B.NAME,A.sql_id
+order by 3 desc) where rownum <=10");
+		
+		$ret = rs2html($rs,false,false,false,false);		
+		return "&nbsp;<p>".$ret."&nbsp;</p>";
+		
+	}
+	
+	function TableSpace()
+	{
+
+		$rs = $this->conn->Execute(
+	"select tablespace_name,round(sum(bytes)/1024/1024) as Used_MB,round(sum(maxbytes)/1024/1024) as Max_MB, round(sum(bytes)/sum(maxbytes),4) * 100 as PCT 
+	from dba_data_files
+   group by tablespace_name order by 2 desc");
+		
+		$ret = "<p><b>Tablespace</b>".rs2html($rs,false,false,false,false);
+
+		$rs = $this->conn->Execute("select * from dba_data_files order by tablespace_name, 1");
+		$ret .= "<p><b>Datafile</b>".rs2html($rs,false,false,false,false);
+		
+		return "&nbsp;<p>".$ret."&nbsp;</p>";
+	}
+	
+	function RMAN()
+	{
+		$rs = $this->conn->Execute("select * from (select start_time, end_time, operation, status, mbytes_processed, output_device_type  
+			from V\$RMAN_STATUS order by start_time desc) where rownum <=10");
+		
+		$ret = rs2html($rs,false,false,false,false);		
+		return "&nbsp;<p>".$ret."&nbsp;</p>";
+		
+	}
+
+	function DynMemoryUsage()
+	{
+		if (@$this->version['version'] >= 11) {
+			$rs = $this->conn->Execute("select component, current_size/1024./1024 as \"CurrSize (M)\" from  V\$MEMORY_DYNAMIC_COMPONENTS");
+
+		} else
+			$rs = $this->conn->Execute("select name, round(bytes/1024./1024,2) as \"CurrSize (M)\" from  V\$sgainfo");
+
+			
+		$ret = rs2html($rs,false,false,false,false);		
+		return "&nbsp;<p>".$ret."&nbsp;</p>";
+	}
+
+	function FlashUsage()
+	{
+        $rs = $this->conn->Execute("select * from  V\$FLASH_RECOVERY_AREA_USAGE");
+		$ret = rs2html($rs,false,false,false,false);		
+		return "&nbsp;<p>".$ret."&nbsp;</p>";
+	}
+
 	function WarnPageCost($val)
 	{
-		if ($val == 100) $s = '<font color=red><b>Too High</b>. </font>';
+		if ($val == 100 && $this->version['version'] < 10) $s = '<font color=red><b>Too High</b>. </font>';
 		else $s = '';
 		
 		return $s.'Recommended is 20-50 for TP, and 50 for data warehouses. Default is 100. See <a href=http://www.dba-oracle.com/oracle_tips_cost_adj.htm>optimizer_index_cost_adj</a>. ';
 	}
-	
+
 	function WarnIndexCost($val)
 	{
-		if ($val == 0) $s = '<font color=red><b>Too Low</b>. </font>';
+		if ($val == 0 && $this->version['version'] < 10) $s = '<font color=red><b>Too Low</b>. </font>';
 		else $s = '';
 		
 		return $s.'Percentage of indexed data blocks expected in the cache.
-			Recommended is 20 (fast disk array) to 50 (slower hard disks). Default is 0.
+			Recommended is 20 (fast disk array) to 30 (slower hard disks). Default is 0.
 			 See <a href=http://www.dba-oracle.com/oracle_tips_cbo_part1.htm>optimizer_index_caching</a>.';
 		}
 	
 	function PGA()
-	{
-		if ($this->version['version'] < 9) return 'Oracle 9i or later required';
-		
-		$rs = $this->conn->Execute("select a.mb,a.targ as pga_size_pct,a.pct from 
-	   (select round(pga_target_for_estimate/1024.0/1024.0,0) Mb,
-	   	   pga_target_factor targ,estd_pga_cache_hit_percentage pct,rownum as r 
-	   	   from v\$pga_target_advice) a left join
-	   (select round(pga_target_for_estimate/1024.0/1024.0,0) Mb,
-	   	   pga_target_factor targ,estd_pga_cache_hit_percentage pct,rownum as r 
-	   	   from v\$pga_target_advice) b on 
-	  a.r = b.r+1 where 
-  		b.pct < 100");
-		if (!$rs) return "Only in 9i or later";
-		$rs->Close();
-		if ($rs->EOF) return "PGA could be too big";
-		
-		return reset($rs->fields);
-	}
-	
+	{	
+		
+		//if ($this->version['version'] < 9) return 'Oracle 9i or later required';
+	}
+
+	function PGA_Advice()
+	{
+		$t = "<h3>PGA Advice Estimate</h3>";
+		if ($this->version['version'] < 9) return $t.'Oracle 9i or later required';
+		
+		$rs = $this->conn->Execute('select a.MB,
+			case when a.targ = 1 then \'<<= Current \' 
+			when a.targ < 1  or a.pct <= b.pct then null 
+			else 
+			\'- BETTER than Current by \'||round(a.pct/b.pct*100-100,2)||\'%\' end as "Percent Improved",
+	a.targ as  "PGA Size Factor",a.pct "% Perf"
+	from 
+       (select round(pga_target_for_estimate/1024.0/1024.0,0) MB,
+              pga_target_factor targ,estd_pga_cache_hit_percentage pct,rownum as r 
+              from v$pga_target_advice) a left join
+       (select round(pga_target_for_estimate/1024.0/1024.0,0) MB,
+              pga_target_factor targ,estd_pga_cache_hit_percentage pct,rownum as r 
+              from v$pga_target_advice) b on 
+      a.r = b.r+1 where 
+          b.pct < 100');
+		if (!$rs) return $t."Only in 9i or later";
+	//	$rs->Close();
+		if ($rs->EOF) return $t."PGA could be too big";
+		
+		return $t.rs2html($rs,false,false,true,false);
+	}
+
 	function Explain($sql,$partial=false) 
 	{
 		$savelog = $this->conn->LogSQL(false);
-		$rs =& $this->conn->SelectLimit("select ID FROM PLAN_TABLE");
+		$rs = $this->conn->SelectLimit("select ID FROM PLAN_TABLE");
 		if (!$rs) {
 			echo "<p><b>Missing PLAN_TABLE</b></p>
@@ -251,5 +410,5 @@
 		if ($partial) {
 			$sqlq = $this->conn->qstr($sql.'%');
-			$arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like $sqlq");
+			$arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
 			if ($arr) {
 				foreach($arr as $row) {
@@ -265,5 +424,5 @@
 		$id = "ADODB ".microtime();
 
-		$rs =& $this->conn->Execute("EXPLAIN PLAN SET STATEMENT_ID='$id' FOR $sql");
+		$rs = $this->conn->Execute("EXPLAIN PLAN SET STATEMENT_ID='$id' FOR $sql");
 		$m = $this->conn->ErrorMsg();
 		if ($m) {
@@ -273,5 +432,5 @@
 			return $s;
 		}
-		$rs =& $this->conn->Execute("
+		$rs = $this->conn->Execute("
 		select 
   '<pre>'||lpad('--', (level-1)*2,'-') || trim(operation) || ' ' || trim(options)||'</pre>'  as Operation, 
@@ -287,20 +446,22 @@
 		return $s;
 	}
-	
-	
+
 	function CheckMemory()
 	{
 		if ($this->version['version'] < 9) return 'Oracle 9i or later required';
 		
-		 $rs =& $this->conn->Execute("
-select  a.size_for_estimate as cache_mb_estimate,
-	case when a.size_factor=1 then 
-   		'&lt;&lt;= current'
-	 when a.estd_physical_read_factor-b.estd_physical_read_factor > 0 and a.estd_physical_read_factor<1 then
-		'- BETTER - '
-	else ' ' end as currsize, 
-   a.estd_physical_read_factor-b.estd_physical_read_factor as best_when_0
-   from (select size_for_estimate,size_factor,estd_physical_read_factor,rownum  r from v\$db_cache_advice) a , 
-   (select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$db_cache_advice) b where a.r = b.r-1");
+		 $rs = $this->conn->Execute("
+select  a.name Buffer_Pool, b.size_for_estimate as cache_mb_estimate, 
+	case when b.size_factor=1 then 
+   		'&lt;&lt;= Current'
+	 when a.estd_physical_read_factor-b.estd_physical_read_factor > 0.001 and b.estd_physical_read_factor<1 then
+		'- BETTER than current by ' || round((1-b.estd_physical_read_factor)/b.estd_physical_read_factor*100,2) || '%'
+	else ' ' end as RATING, 
+   b.estd_physical_read_factor \"Phys. Reads Factor\",
+   round((a.estd_physical_read_factor-b.estd_physical_read_factor)/b.estd_physical_read_factor*100,2) as \"% Improve\"
+   from (select size_for_estimate,size_factor,estd_physical_read_factor,rownum  r,name from v\$db_cache_advice order by name,1) a , 
+   (select size_for_estimate,size_factor,estd_physical_read_factor,rownum r,name from v\$db_cache_advice order by name,1) b 
+   where a.r = b.r-1 and a.name = b.name
+  ");
 		if (!$rs) return false;
 		
@@ -308,14 +469,14 @@
 		The v$db_cache_advice utility show the marginal changes in physical data block reads for different sizes of db_cache_size
 		*/
-		$s = "<h3>Data Cache Estimate</h3>";
+		$s = "<h3>Data Cache Advice Estimate</h3>";
 		if ($rs->EOF) {
 			$s .= "<p>Cache that is 50% of current size is still too big</p>";
 		} else {
-			$s .= "Ideal size of Data Cache is when \"best_when_0\" changes from a positive number and becomes zero.";
+			$s .= "Ideal size of Data Cache is when %BETTER gets close to zero.";
 			$s .= rs2html($rs,false,false,false,false);
 		}
-		return $s;
-	}
-	
+		return $s.$this->PGA_Advice();
+	}
+
 	/*
 		Generate html for suspicious/expensive sql
@@ -413,5 +574,9 @@
 		
 		$s = '';
+		$timer = time();
 		$s .= $this->_SuspiciousSQL($numsql);
+		$timer = time() - $timer;
+		
+		if ($timer > $this->noShowIxora) return $s;
 		$s .= '<p>';
 		
@@ -421,5 +586,5 @@
 		
 		$savelog = $this->conn->LogSQL(false);
-		$rs =& $this->conn->SelectLimit($sql);
+		$rs = $this->conn->SelectLimit($sql);
 		$this->conn->LogSQL($savelog);
 		
@@ -485,5 +650,9 @@
 		
 		$s = '';		
+		$timer = time();
 		$s .= $this->_ExpensiveSQL($numsql);
+		$timer = time() - $timer;
+		if ($timer > $this->noShowIxora) return $s;
+		
 		$s .= '<p>';
 		$save = $ADODB_CACHE_MODE;
@@ -492,5 +661,5 @@
 		
 		$savelog = $this->conn->LogSQL(false);
-		$rs =& $this->conn->Execute($sql);
+		$rs = $this->conn->Execute($sql);
 		$this->conn->LogSQL($savelog);
 		
@@ -506,4 +675,28 @@
 	}
 	
+	function clearsql() 
+	{
+		$perf_table = adodb_perf::table();
+	// using the naive "delete from $perf_table where created<".$this->conn->sysTimeStamp will cause the table to lock, possibly
+	// for a long time
+		$sql = 
+"DECLARE cnt pls_integer;
+BEGIN
+	cnt := 0;
+	FOR rec IN (SELECT ROWID AS rr FROM $perf_table WHERE created<SYSDATE) 
+	LOOP
+	  cnt := cnt + 1;
+	  DELETE FROM $perf_table WHERE ROWID=rec.rr;
+	  IF cnt = 1000 THEN
+	  	COMMIT;
+		cnt := 0;
+	  END IF;
+	END LOOP;
+	commit;
+END;";
+
+		$ok = $this->conn->Execute($sql);
+	}
+	
 }
 ?>
Index: sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mysql.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mysql.inc.php	(revision 34)
+++ sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mysql.inc.php	(revision 8222)
@@ -1,5 +1,5 @@
 <?php
 /* 
-V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
@@ -84,5 +84,5 @@
 	function perf_mysql(&$conn)
 	{
-		$this->conn =& $conn;
+		$this->conn = $conn;
 	}
 	
@@ -252,5 +252,5 @@
 		if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
 		
-		$rs = $this->conn->Execute('show innodb status');
+		$rs = $this->conn->Execute('show engine innodb status');
 		
 		if (isset($savem)) $this->conn->SetFetchMode($savem);
Index: sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mssqlnative.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mssqlnative.inc.php	(revision 8222)
+++ sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-mssqlnative.inc.php	(revision 8222)
@@ -0,0 +1,164 @@
+<?php
+
+/* 
+V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
+  Released under both BSD license and Lesser GPL library license. 
+  Whenever there is any discrepancy between the two licenses, 
+  the BSD license will take precedence. See License.txt. 
+  Set tabs to 4 for best viewing.
+  
+  Latest version is available at http://adodb.sourceforge.net
+  
+  Library for basic performance monitoring and tuning 
+  
+*/
+
+// security - hide paths
+if (!defined('ADODB_DIR')) die();
+
+/*
+	MSSQL has moved most performance info to Performance Monitor
+*/
+class perf_mssqlnative extends adodb_perf{
+	var $sql1 = 'cast(sql1 as text)';
+	var $createTableSQL = "CREATE TABLE adodb_logsql (
+		  created datetime NOT NULL,
+		  sql0 varchar(250) NOT NULL,
+		  sql1 varchar(4000) NOT NULL,
+		  params varchar(3000) NOT NULL,
+		  tracer varchar(500) NOT NULL,
+		  timer decimal(16,6) NOT NULL
+		)";
+		
+	var $settings = array(
+	'Ratios',
+		'data cache hit ratio' => array('RATIO',
+			"select round((a.cntr_value*100.0)/b.cntr_value,2) from master.dbo.sysperfinfo a, master.dbo.sysperfinfo b where a.counter_name = 'Buffer cache hit ratio' and b.counter_name='Buffer cache hit ratio base'",
+			'=WarnCacheRatio'),
+		'prepared sql hit ratio' => array('RATIO',
+			array('dbcc cachestats','Prepared',1,100),
+			''),
+		'adhoc sql hit ratio' => array('RATIO',
+			array('dbcc cachestats','Adhoc',1,100),
+			''),
+	'IO',
+		'data reads' => array('IO',
+		"select cntr_value from master.dbo.sysperfinfo where counter_name = 'Page reads/sec'"),
+		'data writes' => array('IO',
+		"select cntr_value from master.dbo.sysperfinfo where counter_name = 'Page writes/sec'"),
+			
+	'Data Cache',
+		'data cache size' => array('DATAC',
+		"select cntr_value*8192 from master.dbo.sysperfinfo where counter_name = 'Total Pages' and object_name='SQLServer:Buffer Manager'",
+			'' ),
+		'data cache blocksize' => array('DATAC',
+			"select 8192",'page size'),
+	'Connections',
+		'current connections' => array('SESS',
+			'=sp_who',
+			''),
+		'max connections' => array('SESS',
+			"SELECT @@MAX_CONNECTIONS",
+			''),
+
+		false
+	);
+	
+	
+	function perf_mssqlnative(&$conn)
+	{
+		if ($conn->dataProvider == 'odbc') {
+			$this->sql1 = 'sql1';
+			//$this->explain = false;
+		}
+		$this->conn =& $conn;
+	}
+	
+	function Explain($sql,$partial=false)
+	{
+		
+		$save = $this->conn->LogSQL(false);
+		if ($partial) {
+			$sqlq = $this->conn->qstr($sql.'%');
+			$arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
+			if ($arr) {
+				foreach($arr as $row) {
+					$sql = reset($row);
+					if (crc32($sql) == $partial) break;
+				}
+			}
+		}
+		
+		$s = '<p><b>Explain</b>: '.htmlspecialchars($sql).'</p>';
+		$this->conn->Execute("SET SHOWPLAN_ALL ON;");
+		$sql = str_replace('?',"''",$sql);
+		global $ADODB_FETCH_MODE;
+		
+		$save = $ADODB_FETCH_MODE;
+		$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+		$rs =& $this->conn->Execute($sql);
+		//adodb_printr($rs);
+		$ADODB_FETCH_MODE = $save;
+		if ($rs) {
+			$rs->MoveNext();
+			$s .= '<table bgcolor=white border=0 cellpadding="1" callspacing=0><tr><td nowrap align=center> Rows<td nowrap align=center> IO<td nowrap align=center> CPU<td align=left> &nbsp; &nbsp; Plan</tr>';
+			while (!$rs->EOF) {
+				$s .= '<tr><td>'.round($rs->fields[8],1).'<td>'.round($rs->fields[9],3).'<td align=right>'.round($rs->fields[10],3).'<td nowrap><pre>'.htmlspecialchars($rs->fields[0])."</td></pre></tr>\n"; ## NOTE CORRUPT </td></pre> tag is intentional!!!!
+				$rs->MoveNext();
+			}
+			$s .= '</table>';
+			
+			$rs->NextRecordSet();
+		}
+		
+		$this->conn->Execute("SET SHOWPLAN_ALL OFF;");
+		$this->conn->LogSQL($save);
+		$s .= $this->Tracer($sql);
+		return $s;
+	}
+	
+	function Tables()
+	{
+	global $ADODB_FETCH_MODE;
+	
+		$save = $ADODB_FETCH_MODE;
+		$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+		//$this->conn->debug=1;
+		$s = '<table border=1 bgcolor=white><tr><td><b>tablename</b></td><td><b>size_in_k</b></td><td><b>index size</b></td><td><b>reserved size</b></td></tr>';
+		$rs1 = $this->conn->Execute("select distinct name from sysobjects where xtype='U'");
+		if ($rs1) {
+			while (!$rs1->EOF) {
+				$tab = $rs1->fields[0];
+				$tabq = $this->conn->qstr($tab);
+				$rs2 = $this->conn->Execute("sp_spaceused $tabq");
+				if ($rs2) {
+					$s .= '<tr><td>'.$tab.'</td><td align=right>'.$rs2->fields[3].'</td><td align=right>'.$rs2->fields[4].'</td><td align=right>'.$rs2->fields[2].'</td></tr>';
+					$rs2->Close();
+				}
+				$rs1->MoveNext();
+			}
+			$rs1->Close();
+		}
+		$ADODB_FETCH_MODE = $save;
+		return $s.'</table>';
+	}
+	
+	function sp_who()
+	{
+		$arr = $this->conn->GetArray('sp_who');
+		return sizeof($arr);
+	}
+	
+	function HealthCheck($cli=false)
+	{
+		
+		$this->conn->Execute('dbcc traceon(3604)');
+		$html =  adodb_perf::HealthCheck($cli);
+		$this->conn->Execute('dbcc traceoff(3604)');
+		return $html;
+	}
+	
+	
+}
+
+?>
Index: sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-postgres.inc.php
===================================================================
--- sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-postgres.inc.php	(revision 34)
+++ sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/perf/perf-postgres.inc.php	(revision 8222)
@@ -2,5 +2,5 @@
 
 /* 
-V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
   Released under both BSD license and Lesser GPL library license. 
   Whenever there is any discrepancy between the two licenses, 
@@ -90,5 +90,34 @@
 	function perf_postgres(&$conn)
 	{
-		$this->conn =& $conn;
+		$this->conn = $conn;
+	}
+	
+	var $optimizeTableLow  = 'VACUUM %s'; 
+	var $optimizeTableHigh = 'VACUUM ANALYZE %s';
+
+/**
+ * @see adodb_perf#optimizeTable
+ */
+
+	function optimizeTable($table, $mode = ADODB_OPT_LOW) 
+	{
+	    if(! is_string($table)) return false;
+	    
+	    $conn = $this->conn;
+	    if (! $conn) return false;
+	    
+	    $sql = '';
+	    switch($mode) {
+	        case ADODB_OPT_LOW : $sql = $this->optimizeTableLow;  break;
+	        case ADODB_OPT_HIGH: $sql = $this->optimizeTableHigh; break;
+	        default            : 
+	        {
+	            ADOConnection::outp(sprintf("<p>%s: '%s' using of undefined mode '%s'</p>", __CLASS__, 'optimizeTable', $mode));
+	            return false;
+	        }
+	    }
+	    $sql = sprintf($sql, $table);
+	    
+	    return $conn->Execute($sql) !== false;  
 	}
 	
