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