Merge pull request #773 from norahmollo/master

CODE STYLE Formating gulliver/system
This commit is contained in:
ferOnti
2012-10-17 09:47:16 -07:00
2 changed files with 1124 additions and 1080 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,7 @@
<?php <?php
/** /**
* class.dbconnection.php * class.dbconnection.php
*
* @package gulliver.system * @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -13,11 +14,11 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
@@ -25,254 +26,270 @@
*/ */
/** /**
*
* @package gulliver.system * @package gulliver.system
*/ *
*/
require_once ("DB.php"); require_once ("DB.php");
define ( 'DB_ERROR_NO_SHOW_AND_CONTINUE', 0); define( 'DB_ERROR_NO_SHOW_AND_CONTINUE', 0 );
define ( 'DB_ERROR_SHOW_AND_STOP', 1); define( 'DB_ERROR_SHOW_AND_STOP', 1 );
define ( 'DB_ERROR_SHOW_AND_CONTINUE', 2); define( 'DB_ERROR_SHOW_AND_CONTINUE', 2 );
define ( 'DB_ERROR_SHOWALL_AND_STOP', 3); define( 'DB_ERROR_SHOWALL_AND_STOP', 3 );
define ( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4); define( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4 );
/** /**
* DBConnection class definition * DBConnection class definition
* It is useful to stablish a connection * It is useful to stablish a connection
*
* @package gulliver.system * @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team. * @copyright (C) 2002 by Colosa Development Team.
*/ */
class DBConnection class DBConnection
{ {
var $db; var $db;
var $db_error; var $db_error;
var $errorLevel; var $errorLevel;
var $type; var $type;
/***************************************************************** /**
/* Error types: * ***************************************************************
/* -1 Fatal error ( clase no instanced ) * /* Error types:
/* -2 Syntax error ( session missing, query malformed, etc ) * /* -1 Fatal error ( clase no instanced )
/* -3 warning ( when the engine build a dangerous query, i.e delete without where clause ) * /* -2 Syntax error ( session missing, query malformed, etc )
/* * /* -3 warning ( when the engine build a dangerous query, i.e delete without where clause )
/* Error level: * /*
/* 0 don't display any error information and continue. * /* Error level:
/* 1 display small box with error information and die. * /* 0 don't display any error information and continue.
/* 2 display small box with error information and continue * /* 1 display small box with error information and die.
/* 3 display complete error information and die. * /* 2 display small box with error information and continue
/* 4 display complete error information and continue. * /* 3 display complete error information and die.
/* * /* 4 display complete error information and continue.
/* Error Structure * /*
/* int error code * /* Error Structure
/* string error message * /* int error code
/* string error detailed message * /* string error message
/* * /* string error detailed message
/* In all cases, the error will be saved in the apache log file * /*
/* * /* In all cases, the error will be saved in the apache log file
/* */ * /*
* /*
*/
/** /**
* Starts DB connection with default values * Starts DB connection with default values
* @author Fernando Ontiveros Lira <fernando@colosa.com> *
* @access public * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @param const $strServer Host Name * @access public
* @param const $strUser User Name * @param const $strServer Host Name
* @param const $strPwd Password * @param const $strUser User Name
* @param const $strDB Database Name * @param const $strPwd Password
* @param string $type Connection Type * @param const $strDB Database Name
* @param integer $strPort Used Port * @param string $type Connection Type
* @param string $errorLevel Error values posibles are: * @param integer $strPort Used Port
* @return string * @param string $errorLevel Error values posibles are:
* * @return string
*/ *
function DBConnection( $strServer = DB_HOST, $strUser = DB_USER, $strPwd = DB_PASS, $strDB = DB_NAME , $type = DB_ADAPTER, $strPort = 0, $errorLevel = 2 ) */
{ function DBConnection ($strServer = DB_HOST, $strUser = DB_USER, $strPwd = DB_PASS, $strDB = DB_NAME, $type = DB_ADAPTER, $strPort = 0, $errorLevel = 2)
$this->errorLevel = $errorLevel; {
if ($type == null ) $type = 'mysql'; $this->errorLevel = $errorLevel;
$this->type = $type; if ($type == null)
//print "<hr>$type $strServer, $strUser, $strPwd, $strDB <hr>"; $type = 'mysql';
if ( $type == "mysql" ) $this->type = $type;
$dsn = "mysql://$strUser:$strPwd@$strServer/$strDB"; //print "<hr>$type $strServer, $strUser, $strPwd, $strDB <hr>";
if ( $type == "pgsql" ) { if ($type == "mysql")
//$dsn = "pgsql://postgres@$strServer/$strDB"; $dsn = "mysql://$strUser:$strPwd@$strServer/$strDB";
$prt = ( $strPort == 0 || $strPort == 5432 ? '' : ":$strPort" ); if ($type == "pgsql") {
$dsn = "pgsql://$strUser:$strPwd@$strServer$prt/$strDB"; //$dsn = "pgsql://postgres@$strServer/$strDB";
$prt = ($strPort == 0 || $strPort == 5432 ? '' : ":$strPort");
$dsn = "pgsql://$strUser:$strPwd@$strServer$prt/$strDB";
}
if ($type == "odbc")
$dsn = "odbc://$strUser:$strPwd@$strServer/$strDB";
if ($type == "mssql") {
$strServer = substr( $strServer, 0, strpos( $strServer, ':' ) );
$prt = ($strPort == 0 || $strPort == 1433 ? '' : ":$strPort");
$dsn = "mssql://$strUser:$strPwd@$strServer$prt/$strDB";
///--) $dsn = "mssql://$strUser:$strPwd@$strServer/$strDB";
}
if ($type == "oracle") {
$dsn = "oci8://$strUser:$strPwd@$strServer/$strDB";
}
$this->db_error = null;
if ($type === 'myxml') {
$this->db = XMLDB::connect( $strServer );
} else {
$this->db = DB::connect( $dsn );
}
if (DB::isError( $this->db )) {
$this->db_error = $this->db;
$this->db = null;
$this->logError( $this->db_error );
}
} }
if ( $type == "odbc" )
$dsn = "odbc://$strUser:$strPwd@$strServer/$strDB";
if ( $type == "mssql" ) {
$strServer = substr($strServer, 0, strpos($strServer,':'));
$prt = ( $strPort == 0 || $strPort == 1433 ? '' : ":$strPort" );
$dsn = "mssql://$strUser:$strPwd@$strServer$prt/$strDB";
///--) $dsn = "mssql://$strUser:$strPwd@$strServer/$strDB";
}
if ( $type == "oracle" ) {
$dsn = "oci8://$strUser:$strPwd@$strServer/$strDB";
}
$this->db_error = NULL;
if ( $type === 'myxml' ) {
$this->db = XMLDB::connect ( $strServer );
} else {
$this->db = DB::connect ( $dsn );
}
if ( DB::isError ($this->db) ) {
$this->db_error = $this->db;
$this->db = NULL;
$this->logError( $this->db_error );
}
}
/** /**
* Close Connection and Generate Log Message * Close Connection and Generate Log Message
* @author Fernando Ontiveros Lira <fernando@colosa.com> *
* @access public * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @return void * @access public
*/ * @return void
function Reset() */
{ function Reset ()
if ( $this->db ){ {
$this->db->disconnect(); if ($this->db) {
$this->db->disconnect();
}
$this->db = null;
} }
$this->db = NULL;
}
/** /**
* Disconnect from Data base * Disconnect from Data base
* @author Fernando Ontiveros Lira <fernando@colosa.com> *
* @access public * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @return void * @access public
*/ * @return void
function Free() */
{ function Free ()
$this->Reset(); {
} $this->Reset();
}
/** /**
* Close Connection * Close Connection
* @author Fernando Ontiveros Lira <fernando@colosa.com> *
* @access public * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @return void * @access public
*/ * @return void
function Close() */
{ function Close ()
$this->Reset(); {
} $this->Reset();
}
/** /**
* log Errors * log Errors
* @author Fernando Ontiveros Lira <fernando@colosa.com> *
* @access public * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @param db_error $obj * @access public
* @param string $errorLevel * @param db_error $obj
* @return void * @param string $errorLevel
*/ * @return void
function logError( $obj, $errorLevel = NULL ) */
{ function logError ($obj, $errorLevel = NULL)
global $_SESSION; {
global $_SERVER; global $_SESSION;
if ( is_null( $errorLevel ) ) global $_SERVER;
if ( isset ( $this->errorLevel) ) if (is_null( $errorLevel ))
$errorLevel = $this->errorLevel; if (isset( $this->errorLevel )) {
else $errorLevel = $this->errorLevel;
$errorLevel = DB_ERROR_SHOWALL_AND_STOP; //for fatal errors the default is 3, show detailed and die. } else {
if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOW_AND_CONTINUE || $errorLevel = DB_ERROR_SHOWALL_AND_STOP; //for fatal errors the default is 3, show detailed and die.
$errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE ) { }
print "<table border=1 style='font-family:Arial' cellspacing=1 cellpadding = 0 width=400 class= 'tableError' >";
print "<tr><td><b>" . $obj->code . ' '. $obj->message . "</b></td></tr>";
if ($errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE ) {
print "<tr><td>" . $obj->userinfo . "</td></tr>";
}
print "</table>";
}
if (defined('DB_ERROR_BACKTRACE') && DB_ERROR_BACKTRACE) {
print "<table border = 1 width=400 class= 'sendMsgRojo'><tr><td><textarea rows='12' cols='180' style='width:100%;font-family:courier;white-space:pre-line;overflow:auto;border:none;'>";
print((htmlentities(DBConnection::traceError())));
print "</textarea></td></tr></table>";
}
//G::setErrorHandler ( );
G::customErrorLog ('DB_Error', $obj->code . ' '. $obj->message .'-' . $obj->userinfo, '', '');
if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_STOP ) {
die; //stop
}
}
/** if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOW_AND_CONTINUE || $errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) {
* Get the trace of the current execution (debug_backtrace). print "<table border=1 style='font-family:Arial' cellspacing=1 cellpadding = 0 width=400 class= 'tableError' >";
* @author David Callizaya print "<tr><td><b>" . $obj->code . ' ' . $obj->message . "</b></td></tr>";
* @param string $tts if ($errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) {
* @param string $limit print "<tr><td>" . $obj->userinfo . "</td></tr>";
* @return string }
*/ print "</table>";
function traceError( $tts=2 , $limit=-1 ) }
{ if (defined( 'DB_ERROR_BACKTRACE' ) && DB_ERROR_BACKTRACE) {
$trace = debug_backtrace(); print "<table border = 1 width=400 class= 'sendMsgRojo'><tr><td><textarea rows='12' cols='180' style='width:100%;font-family:courier;white-space:pre-line;overflow:auto;border:none;'>";
$out=''; print ((htmlentities( DBConnection::traceError() ))) ;
foreach($trace as $step) { print "</textarea></td></tr></table>";
if ($tts>0) { }
$tts--; //G::setErrorHandler ( );
} else { G::customErrorLog( 'DB_Error', $obj->code . ' ' . $obj->message . '-' . $obj->userinfo, '', '' );
$out .= '['.basename($step['file']).': '.$step['line'].'] : ' . $step['function'] .'(' . if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_STOP) {
DBConnection::printArgs($step['args']). ")\n"; die(); //stop
$limit--; }
if ($limit===0)
return $out;
}
} }
return $out;
}
/** /**
* Print the arguments of a function * Get the trace of the current execution (debug_backtrace).
* @author David Callizaya *
* @param string $args * @author David Callizaya
* @return string * @param string $tts
*/ * @param string $limit
function printArgs( $args ) * @return string
{ */
$out = ''; function traceError ($tts = 2, $limit = -1)
if (is_array($args)){ {
foreach($args as $arg) { $trace = debug_backtrace();
if ($out!=='') $out = '';
$out .= ' ,'; foreach ($trace as $step) {
if (is_string($arg)) if ($tts > 0) {
$out .= "'".($arg)."'"; $tts --;
elseif (is_array($arg) ) } else {
$out .= print_r ( $arg ,1 ); $out .= '[' . basename( $step['file'] ) . ': ' . $step['line'] . '] : ' . $step['function'] . '(' . DBConnection::printArgs( $step['args'] ) . ")\n";
elseif (is_object($arg)) $limit --;
$out .= get_class($arg);// print_r ( $arg ,1 ); if ($limit === 0) {
elseif (!isset($arg)) return $out;
$out .= 'NULL'; }
else }
$out .= sprintf ( "%s" ,$arg ); }
} return $out;
} else { }
if (!isset($args))
$out = 'NULL'; /**
else * Print the arguments of a function
$out = print_r($args,1); *
* @author David Callizaya
* @param string $args
* @return string
*/
function printArgs ($args)
{
$out = '';
if (is_array( $args )) {
foreach ($args as $arg) {
if ($out !== '') {
$out .= ' ,';
}
if (is_string( $arg )) {
$out .= "'" . ($arg) . "'";
} elseif (is_array( $arg )) {
$out .= print_r( $arg, 1 );
} elseif (is_object( $arg )) {
$out .= get_class( $arg ); // print_r ( $arg ,1 );
} elseif (! isset( $arg )) {
$out .= 'NULL';
} else {
$out .= sprintf( "%s", $arg );
}
}
} else {
if (! isset( $args )) {
$out = 'NULL';
} else {
$out = print_r( $args, 1 );
}
}
return $out;
} }
return $out;
}
/** /**
* Gets last autoincrement value inserted * Gets last autoincrement value inserted
*
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public * @access public
* @return void * @return void
*/ */
function GetLastID() function GetLastID ()
{ {
if ( PEAR_DATABASE == "mysql" ){ if (PEAR_DATABASE == "mysql") {
return mysql_insert_id(); return mysql_insert_id();
} else {
$dberror = PEAR::raiseError( null, DB_ERROR_FEATURE_NOT_AVAILABLE, null, 'null', "getLastID with " . PEAR_DATABASE . ' database.', 'G_Error', true );
DBconnection::logError( $dberror, DB_ERROR_SHOWALL_AND_STOP ); //this error will stop the execution, until we add this feature!!
return $dberror;
}
return mysql_insert_id();
} }
else {
$dberror = PEAR::raiseError(null, DB_ERROR_FEATURE_NOT_AVAILABLE, null, 'null',
"getLastID with " . PEAR_DATABASE . ' database.',
'G_Error', true);
DBconnection::logError( $dberror, DB_ERROR_SHOWALL_AND_STOP ); //this error will stop the execution, until we add this feature!!
return $dberror;
}
return mysql_insert_id();
}
} }