CODE STYLE, gulliver/system/...

FILES:
class.dbMaintenance.php
class.dbconnection.php
class.dbrecordset.php
class.dbsession.php
class.dbtable.php
class.httpProxyController.php
class.i18n_po.php
class.mailer.php
class.menu.php
class.objectTemplate.php
class.testTools.php
class.tree.php
class.unitTest.php
class.webResource.php
class.xmlDocument.php
class.xmlformExtension.php
This commit is contained in:
jennylee
2012-10-18 10:54:46 -04:00
parent 37bb8a1f5f
commit e456979aa3
16 changed files with 3515 additions and 3358 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,295 +1,298 @@
<?php
/**
* class.dbconnection.php
*
* @package gulliver.system
*
* 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
* 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
* 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/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
/**
*
* @package gulliver.system
*
*/
require_once ("DB.php");
define( 'DB_ERROR_NO_SHOW_AND_CONTINUE', 0 );
define( 'DB_ERROR_SHOW_AND_STOP', 1 );
define( 'DB_ERROR_SHOW_AND_CONTINUE', 2 );
define( 'DB_ERROR_SHOWALL_AND_STOP', 3 );
define( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4 );
/**
* DBConnection class definition
* It is useful to stablish a connection
*
* @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team.
*/
class DBConnection
{
var $db;
var $db_error;
var $errorLevel;
var $type;
/**
* ***************************************************************
* /* Error types:
* /* -1 Fatal error ( clase no instanced )
* /* -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.
* /* 1 display small box with error information and die.
* /* 2 display small box with error information and continue
* /* 3 display complete error information and die.
* /* 4 display complete error information and continue.
* /*
* /* Error Structure
* /* int error code
* /* string error message
* /* string error detailed message
* /*
* /* In all cases, the error will be saved in the apache log file
* /*
* /*
*/
/**
* Starts DB connection with default values
*
* @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
* @param string $type Connection Type
* @param integer $strPort Used Port
* @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)
{
$this->errorLevel = $errorLevel;
if ($type == null)
$type = 'mysql';
$this->type = $type;
<?php
/**
* class.dbconnection.php
*
* @package gulliver.system
*
* 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
* 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
* 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/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
/**
*
* @package gulliver.system
*
*/
require_once ("DB.php");
define( 'DB_ERROR_NO_SHOW_AND_CONTINUE', 0 );
define( 'DB_ERROR_SHOW_AND_STOP', 1 );
define( 'DB_ERROR_SHOW_AND_CONTINUE', 2 );
define( 'DB_ERROR_SHOWALL_AND_STOP', 3 );
define( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4 );
/**
* DBConnection class definition
* It is useful to stablish a connection
*
* @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team.
*/
class DBConnection
{
var $db;
var $db_error;
var $errorLevel;
var $type;
/**
* ***************************************************************
* /* Error types:
* /* -1 Fatal error ( clase no instanced )
* /* -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.
* /* 1 display small box with error information and die.
* /* 2 display small box with error information and continue
* /* 3 display complete error information and die.
* /* 4 display complete error information and continue.
* /*
* /* Error Structure
* /* int error code
* /* string error message
* /* string error detailed message
* /*
* /* In all cases, the error will be saved in the apache log file
* /*
* /*
*/
/**
* Starts DB connection with default values
*
* @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
* @param string $type Connection Type
* @param integer $strPort Used Port
* @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)
{
$this->errorLevel = $errorLevel;
if ($type == null) {
$type = 'mysql';
}
$this->type = $type;
//print "<hr>$type $strServer, $strUser, $strPwd, $strDB <hr>";
if ($type == "mysql")
$dsn = "mysql://$strUser:$strPwd@$strServer/$strDB";
if ($type == "pgsql") {
if ($type == "mysql") {
$dsn = "mysql://$strUser:$strPwd@$strServer/$strDB";
}
if ($type == "pgsql") {
//$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";
$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 );
}
}
/**
* Close Connection and Generate Log Message
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return void
*/
function Reset ()
{
if ($this->db) {
$this->db->disconnect();
}
$this->db = null;
}
/**
* Disconnect from Data base
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return void
*/
function Free ()
{
$this->Reset();
}
/**
* Close Connection
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return void
*/
function Close ()
{
$this->Reset();
}
/**
* log Errors
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param db_error $obj
* @param string $errorLevel
* @return void
*/
function logError ($obj, $errorLevel = NULL)
{
global $_SESSION;
global $_SERVER;
if (is_null( $errorLevel ))
if (isset( $this->errorLevel )) {
$errorLevel = $this->errorLevel;
} else {
$errorLevel = DB_ERROR_SHOWALL_AND_STOP; //for fatal errors the default is 3, show detailed and die.
}
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) {
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>";
}
}
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
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return void
*/
function Reset ()
{
if ($this->db) {
$this->db->disconnect();
}
$this->db = null;
}
/**
* Disconnect from Data base
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return void
*/
function Free ()
{
$this->Reset();
}
/**
* Close Connection
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return void
*/
function Close ()
{
$this->Reset();
}
/**
* log Errors
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param db_error $obj
* @param string $errorLevel
* @return void
*/
function logError ($obj, $errorLevel = null)
{
global $_SESSION;
global $_SERVER;
if (is_null( $errorLevel ))
if (isset( $this->errorLevel )) {
$errorLevel = $this->errorLevel;
} else {
$errorLevel = DB_ERROR_SHOWALL_AND_STOP; //for fatal errors the default is 3, show detailed and die.
}
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) {
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) {
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
}
}
/**
* Get the trace of the current execution (debug_backtrace).
*
* @author David Callizaya
* @param string $tts
* @param string $limit
* @return string
*/
function traceError ($tts = 2, $limit = -1)
{
$trace = debug_backtrace();
$out = '';
foreach ($trace as $step) {
if ($tts > 0) {
$tts --;
} else {
$out .= '[' . basename( $step['file'] ) . ': ' . $step['line'] . '] : ' . $step['function'] . '(' . DBConnection::printArgs( $step['args'] ) . ")\n";
$limit --;
if ($limit === 0) {
return $out;
}
}
}
return $out;
}
/**
* Print the arguments of a function
*
* @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 )) {
}
}
/**
* Get the trace of the current execution (debug_backtrace).
*
* @author David Callizaya
* @param string $tts
* @param string $limit
* @return string
*/
function traceError ($tts = 2, $limit = -1)
{
$trace = debug_backtrace();
$out = '';
foreach ($trace as $step) {
if ($tts > 0) {
$tts --;
} else {
$out .= '[' . basename( $step['file'] ) . ': ' . $step['line'] . '] : ' . $step['function'] . '(' . DBConnection::printArgs( $step['args'] ) . ")\n";
$limit --;
if ($limit === 0) {
return $out;
}
}
}
return $out;
}
/**
* Print the arguments of a function
*
* @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;
}
/**
* 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 );
} elseif (! isset( $arg )) {
$out .= 'NULL';
} else {
$out .= sprintf( "%s", $arg );
}
}
} else {
if (! isset( $args )) {
$out = 'NULL';
} else {
$out = print_r( $args, 1 );
}
}
return $out;
}
/**
* 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();
}
}
return $dberror;
}
return mysql_insert_id();
}
}

View File

@@ -1,11 +1,13 @@
<?php
/**
* class.dbrecordset.php
* @package gulliver.system
*
*
* @package gulliver.system
*
* 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
* published by the Free Software Foundation, either version 3 of the
@@ -13,20 +15,21 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
*
* 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.,
* 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.
*
*
*/
/**
/**
* DBRecordset class definition
* Provides access to a generalized table it assumes that the dbconnection object is already initialized for the table should be also provided in order to provide
*
* @package gulliver.system
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
@@ -34,118 +37,116 @@
*/
class DBRecordSet
{
var $result = null;
var $result = null;
/**
* Starts connection to Database using default values
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $intResult Database recordset default value = false
* @return void
*/
function DBRecordSet( $intResult = null )
{
$this->SetTo( $intResult );
}
/**
* Set conecction to Database
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $intResult connection string default value = false
* @return void
*/
function SetTo( $intResult = null )
{
if ( $intResult === null ) {
$dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null',
"You tried to call to a DBRecordset with an invalid result recordset.",
'G_Error', true);
DBconnection::logError( $dberror );
}
if ( $intResult ) {
$this->result = $intResult;
}
}
/**
* Function Free
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function Free()
{
if ( $this->result === null ) {
$dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null',
"You tried to call to a DBRecordset with an invalid result recordset.",
'G_Error', true);
DBconnection::logError( $dberror );
}
$this->result->free();
return;
}
/**
* Function Count
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function Count()
{
if ( $this->result === null ) {
$dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null',
"You tried to call to a DBRecordset with an invalid result recordset.",
'G_Error', true);
DBconnection::logError( $dberror );
}
return $this->result->numRows();
}
/**
* Function Read
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function Read()
{
if ( $this->result === null ) {
$dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null',
"You tried to call to a DBRecordset with an invalid result recordset.",
'G_Error', true);
DBconnection::logError( $dberror );
}
$res = $this->result->fetchRow(DB_FETCHMODE_ASSOC);
//for Pgsql databases,
//if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); }
/* Comment Code: This block is not required now because
* of the the use of the G::sqlEscape() instead of addslashes
* funcion over each field in DBTable.
* @author David Callizaya
/**
* Starts connection to Database using default values
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $intResult Database recordset default value = false
* @return void
*/
/*if (is_array ($res) )
foreach ($res as $key => $val)
function DBRecordSet ($intResult = null)
{
$this->SetTo( $intResult );
}
/**
* Set conecction to Database
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $intResult connection string default value = false
* @return void
*/
function SetTo ($intResult = null)
{
if ($intResult === null) {
$dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', "You tried to call to a DBRecordset with an invalid result recordset.", 'G_Error', true );
DBconnection::logError( $dberror );
}
if ($intResult) {
$this->result = $intResult;
}
}
/**
* Function Free
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function Free ()
{
if ($this->result === null) {
$dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', "You tried to call to a DBRecordset with an invalid result recordset.", 'G_Error', true );
DBconnection::logError( $dberror );
}
$this->result->free();
return;
}
/**
* Function Count
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function Count ()
{
if ($this->result === null) {
$dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', "You tried to call to a DBRecordset with an invalid result recordset.", 'G_Error', true );
DBconnection::logError( $dberror );
}
return $this->result->numRows();
}
/**
* Function Read
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function Read ()
{
if ($this->result === null) {
$dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', "You tried to call to a DBRecordset with an invalid result recordset.", 'G_Error', true );
DBconnection::logError( $dberror );
}
$res = $this->result->fetchRow( DB_FETCHMODE_ASSOC );
//for Pgsql databases,
//if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); }
/* Comment Code: This block is not required now because
* of the the use of the G::sqlEscape() instead of addslashes
* funcion over each field in DBTable.
* @author David Callizaya
*/
/*if (is_array ($res) )
foreach ($res as $key => $val)
$res[$key] = stripslashes ($val); remove the slashes*/
return $res;
}
/**
* Function ReadAbsolute
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function ReadAbsolute()
{
$res = $this->result->fetchRow(DB_FETCHMODE_ORDERED);
//for Pgsql databases,
//if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); }
return $res;
}
}
return $res;
}
/**
* Function ReadAbsolute
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function ReadAbsolute ()
{
$res = $this->result->fetchRow( DB_FETCHMODE_ORDERED );
//for Pgsql databases,
//if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); }
return $res;
}
}

View File

@@ -1,11 +1,13 @@
<?php
/**
* class.dbsession.php
* @package gulliver.system
*
*
* @package gulliver.system
*
* 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
* published by the Free Software Foundation, either version 3 of the
@@ -13,20 +15,21 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
*
* 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.,
* 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.
*
*
*/
/**
/**
* DBSession class definition
* It is useful to stablish a database connection using an specific database
*
* @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team.
@@ -34,146 +37,151 @@
*/
class DBSession
{
var $dbc = NULL;
var $dbname = '';
var $result = false;
var $dbc = null;
var $dbname = '';
var $result = false;
/**
* Starts a session using a connection with an specific database
* @author Fernando Ontiveros Lira <fernando@colosa.com>
*
* @access public
* @param object $objConnection
* @param string $strDBName
* @return void
*
*/
function DBSession( $objConnection = NULL, $strDBName = '' )
{
if ($strDBName!='') $strDBName = $objConnection->db->_db;
$this->setTo( $objConnection, $strDBName );
}
/**
* It's like a constructor
* @author Fernando Ontiveros Lira <fernando@colosa.com>
*
* @access public
* @param object $objConnection
* @param string $strDBName
* @return void
*
*/
function setTo( $objConnection = NULL, $strDBName = DB_NAME )
{
if ( $objConnection != NULL )
/**
* Starts a session using a connection with an specific database
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
*
* @access public
* @param object $objConnection
* @param string $strDBName
* @return void
*
*/
function DBSession ($objConnection = null, $strDBName = '')
{
$this->Free();
$this->dbc = $objConnection;
$this->dbname = $strDBName;
//enable utf8 in mysql databases
if ( $this->dbc->db->phptype == 'mysql' ) { //utf-8
$this->dbc->db->query ( "SET NAMES 'utf8'; " );
}
}
}
/**
* UseDB stablish a database for the connection
* @author Fernando Ontiveros Lira <fernando@colosa.com>
*
* @access public
* @param string $strDBName
* @return void
*
*/
function UseDB( $strDBName = DB_NAME )
{
$this->dbname = $strDBName;
}
/**
* Function Execute, to execute a query and send back the recordset.
* @access public
* @parameter string strQuery
* @parameter string debug
* @parameter string error
* @return string
*/
function Execute( $strQuery = '', $debug = false, $errorLevel = null )
{
//BUG::traceRoute();
if ($this->dbc == NULL ) {
$dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null',
'You have tried to call a DBSession function without create an instance of DBConnection',
'G_Error', true);
DBconnection::logError( $dberror, $errorLevel );
return $dberror;
};
if ( $errorLevel === null ) $errorLevel = $this->dbc->errorLevel;
$this->Free( true );
if( $debug ) {
print( $strQuery . "<br>\n" );
}
$this->result = $this->dbc->db->query ( $strQuery );
if (DB::isError ($this->result)) {
$this->dbc->logError( $this->result, $errorLevel );
return $this->result;
}
$dset = new DBRecordSet( $this->result );
return $dset;
}
/**
* Function Query, just to execute the query.
* @access public
* @parameter string strQuery
* @parameter string debug
* @parameter string error
* @return string
*/
/* function deprecated... by Onti, 30th july 2007
function Query( $strQuery = '', $debug = false, $error = '' )
{
if ( $error == '' && defined('ERROR_STATE') ) {
$error = ERROR_STATE;
if ($strDBName != '') {
$strDBName = $objConnection->db->_db;
}
$this->setTo( $objConnection, $strDBName );
}
if ( !defined('ERROR_STATE') ) $error = 4;
/**
* It's like a constructor
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
*
* @access public
* @param object $objConnection
* @param string $strDBName
* @return void
*
*/
function setTo ($objConnection = null, $strDBName = DB_NAME)
{
if ($objConnection != null) {
$this->Free();
$this->dbc = $objConnection;
$this->dbname = $strDBName;
if( $debug ) {
print( $strQuery . "<br>\n" );
//enable utf8 in mysql databases
if ($this->dbc->db->phptype == 'mysql') { //utf-8
$this->dbc->db->query( "SET NAMES 'utf8'; " );
}
}
}
$this->Free( true );
$this->result = $this->dbc->db->query ( $strQuery );
if (DB::isError ($this->result)) {
$this->dbc->ShowLogError( $this->result->getMessage() , $this->result->userinfo, $error);
die;
/**
* UseDB stablish a database for the connection
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
*
* @access public
* @param string $strDBName
* @return void
*
*/
function UseDB ($strDBName = DB_NAME)
{
$this->dbname = $strDBName;
}
return;
}
*/
/**
* Function Free
* @access public
* @parameter string debug
* @return string
*/
function Free( $debug = false )
{
if ( is_resource($this->result) )
$this->result->Free();
return;
}
/**
* Function Execute, to execute a query and send back the recordset.
*
* @access public
* @param eter string strQuery
* @param eter string debug
* @param eter string error
* @return string
*/
function Execute ($strQuery = '', $debug = false, $errorLevel = null)
{
//BUG::traceRoute();
if ($this->dbc == null) {
$dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', 'You have tried to call a DBSession function without create an instance of DBConnection', 'G_Error', true );
DBconnection::logError( $dberror, $errorLevel );
return $dberror;
}
;
if ($errorLevel === null) {
$errorLevel = $this->dbc->errorLevel;
}
$this->Free( true );
if ($debug) {
print ($strQuery . "<br>\n") ;
}
$this->result = $this->dbc->db->query( $strQuery );
if (DB::isError( $this->result )) {
$this->dbc->logError( $this->result, $errorLevel );
return $this->result;
}
$dset = new DBRecordSet( $this->result );
return $dset;
}
/**
* Function Query, just to execute the query.
*
* @access public
* @param eter string strQuery
* @param eter string debug
* @param eter string error
* @return string
*/
/* function deprecated... by Onti, 30th july 2007
function Query( $strQuery = '', $debug = false, $error = '' )
{
if ( $error == '' && defined('ERROR_STATE') ) {
$error = ERROR_STATE;
}
if ( !defined('ERROR_STATE') ) $error = 4;
if( $debug ) {
print( $strQuery . "<br>\n" );
}
$this->Free( true );
$this->result = $this->dbc->db->query ( $strQuery );
if (DB::isError ($this->result)) {
$this->dbc->ShowLogError( $this->result->getMessage() , $this->result->userinfo, $error);
die;
}
return;
}
*/
/**
* Function Free
*
* @access public
* @param eter string debug
* @return string
*/
function Free ($debug = false)
{
if (is_resource( $this->result )) {
$this->result->Free();
}
return;
}
}

View File

@@ -1,6 +1,8 @@
<?php
/**
* class.dbtable.php
*
* @package gulliver.system
*
* ProcessMaker Open Source Edition
@@ -13,11 +15,11 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
* 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.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
@@ -29,6 +31,7 @@
* This class provides acces to a generalized table
* it assumes that the dbconnection object is already initialized, the table name, as well as the primary keys
* for the table should be also provided in order to provide the class a way to generate an UPDATE query properly.
*
* @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team.
@@ -36,393 +39,391 @@
*/
class DBTable
{
var $_dbc;
var $_dbses;
var $_dset;
var $table_name;
var $table_keys;
var $Fields = null;
var $is_new;
var $errorLevel;
var $debug = false;
var $_dbc;
var $_dbses;
var $_dset;
var $table_name;
var $table_keys;
var $Fields = null;
var $is_new;
var $errorLevel;
var $debug = false;
/**
* Initiate a database conecction using default values
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param object $objConnection conecction string
* @return void
*/
function dBTable( $objConnection = NULL, $strTable = "", $arrKeys = array( 'UID' ) )
{
$this->_dbc = NULL;
$this->_dbses = NULL;
$this->SetTo( $objConnection, $strTable, $arrKeys );
}
/**
* Initiate a database conecction using default values
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param object $objDBConnection conecction string
* @param string $strTable Table name defaultvalue=''
* @param array $arrKeys table keys defaultvalue=UID
* @return void
*/
function setTo( $objDBConnection, $strTable = "", $arrKeys = array( 'UID' ) )
{
$this->_dbc = $objDBConnection;
if( $this->_dbc != NULL && strcasecmp( get_class( $objDBConnection ) , 'dbconnection' ) == 0 )
/**
* Initiate a database conecction using default values
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param object $objConnection conecction string
* @return void
*/
function dBTable ($objConnection = null, $strTable = "", $arrKeys = array( 'UID' ))
{
$this->_dbses = new DBSession( $this->_dbc );
$this->_dbses->UseDB( DB_NAME );
$this->_dbc = null;
$this->_dbses = null;
$this->SetTo( $objConnection, $strTable, $arrKeys );
}
else {
$dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null',
"You tried to call to a DBTable function without create an instance of DBConnection",
'G_Error', true);
//DBconnection::logError( $dberror );
return $dberror;
}
$this->is_new = true;
$this->Fields = NULL;
$this->table_name = $strTable;
if ( is_array ( $arrKeys ) )
$this->table_keys = $arrKeys;
else
$this->table_keys = array ( 0 => $arrKeys );
$this->errorLevel = $this->_dbc->errorLevel;
}
/**
* Loads full description of a referenced table in Fields
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return void
*/
function loadEmpty()
{
$stQry = "DESCRIBE `" . $this->table_name. "`";
$dset = $this->_dbses->execute( $stQry );
//$dset = new DBRecordSet( $this->_dbses->Result );
$nlim = $dset->Count();
$this->Fields = NULL;
for( $ncount = 0; $ncount < $nlim; $ncount++ )
/**
* Initiate a database conecction using default values
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param object $objDBConnection conecction string
* @param string $strTable Table name defaultvalue=''
* @param array $arrKeys table keys defaultvalue=UID
* @return void
*/
function setTo ($objDBConnection, $strTable = "", $arrKeys = array( 'UID' ))
{
$data = $dset->Read();
$fname = $data['Field'];
$fval = "";
$ftypearr = explode($data['Type'], '(' );
$ftype = $ftypearr[0];
if( $data['Key'] == 'PRI' )
{
if( is_array($this->table_keys) )
{
$this->table_keys[count( $this->table_keys ) - 1] = $fname;
$this->_dbc = $objDBConnection;
if ($this->_dbc != null && strcasecmp( get_class( $objDBConnection ), 'dbconnection' ) == 0) {
$this->_dbses = new DBSession( $this->_dbc );
$this->_dbses->UseDB( DB_NAME );
} else {
$dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', "You tried to call to a DBTable function without create an instance of DBConnection", 'G_Error', true );
//DBconnection::logError( $dberror );
return $dberror;
}
else
{
$this->table_keys[0] = $fname;
$this->is_new = true;
$this->Fields = null;
$this->table_name = $strTable;
if (is_array( $arrKeys )) {
$this->table_keys = $arrKeys;
} else {
$this->table_keys = array (0 => $arrKeys
);
}
}
switch( $ftype )
{
case 'int':
case 'smallint':
case 'tinyint':
case 'decimal':
case 'numeric':
case 'double':
case 'float':
$fval = 0;
break;
}
$this->Fields[ $fname ] = $fval;
$this->Fields[ $ncount ] = &$this->Fields[ $fname ];
}
}
/**
* Return specified field on the referenced table
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strWhere string which contains conditions
* @return strint
*/
function loadWhere( $strWhere )
{
$this->Fields = NULL;
$stQry = "SELECT * FROM `" . $this->table_name . "`";
if( $strWhere != "" ) $stQry .= " WHERE " . $strWhere;
$this->_dset = $this->_dbses->Execute ( $stQry , $this->debug, $this->errorLevel);
if (DB::isError ($this->_dset)) {
return $this->_dset;
$this->errorLevel = $this->_dbc->errorLevel;
}
if( $this->_dset->Count() > 0 ){
$this->Fields = $this->_dset->Read();
$this->is_new = false;
}
else
/**
* Loads full description of a referenced table in Fields
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return void
*/
function loadEmpty ()
{
$this->Fields = NULL;
$this->is_new = true;
}
$stQry = "DESCRIBE `" . $this->table_name . "`";
$dset = $this->_dbses->execute( $stQry );
//$dset = new DBRecordSet( $this->_dbses->Result );
$nlim = $dset->Count();
$this->Fields = null;
for ($ncount = 0; $ncount < $nlim; $ncount ++) {
$data = $dset->Read();
$fname = $data['Field'];
$fval = "";
$ftypearr = explode( $data['Type'], '(' );
$ftype = $ftypearr[0];
return $this->Fields;
}
/**
* Return all fields on the referenced table
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param array array of arguments key values
* @return void
*/
function load()
{
// bug::traceRoute();
$ncount = 0;
$stWhere = "";
$arrKeys = func_get_args();
if ( isset($arrKeys[0]) && is_array ($arrKeys[0] ) ) {
foreach ($this->table_keys as $key=>$val) {
if( $stWhere == "" ){
$stWhere .= " $val = '" . $arrKeys[0][ $val ] . "' ";
}else
$stWhere .= " AND $val = '" . $arrKeys[0][ $val ] . "' ";
}
}
else {
foreach( $arrKeys as $val )
{
if( $stWhere == "" )
{
$stWhere .= $this->table_keys[$ncount] . "='" . $val . "'";
}
else
{
$stWhere .= " AND " . $this->table_keys[$ncount] . "='" . $val . "'";
}
$ncount++;
}
}
return $this->LoadWhere( $stWhere );
}
/**
* Function nextvalPGSql
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @parameter string seq
* @return string
*/
function nextvalPGSql( $seq )
{
$stQry = " Select NEXTVAL( '$seq' ) ";
$dset = $this->_dbses->Execute( $stQry );
$row = $dset->Read();
if ( is_array ($row) ) {
return $row['NEXTVAL'];
}
die ("Sequence '$seq' is not exist!!");
return -1;
}
/**
* Insert a new row
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function insert () {
$strFields = "";
$strValues = "";
if( defined('DB_ADAPTER'))
$DBEngine = DB_ADAPTER;
else
$DBEngine = 'mysql';
foreach( $this->Fields as $field => $val ) {
$strFields .= $field . ",";
$iskey = false;
if ( isset ( $this->table_keys ) && is_array ( $this->table_keys ) )
$iskey = in_array( $field, $this->table_keys ) && strtoupper(substr(trim($val),0,7) ) == "NEXTVAL";
$dbcType = isset ( $this->_dbc->type ) ? $this->_dbc->type : $DBEngine;
// Commented by new format of textarea in javascript
if( ! $iskey )
$val = "'" . $val . "'";
///-- $val = "'" . G::sqlEscape( $val , $dbcType ) . "'";
$strValues .= $val .", ";
}
$strFields = substr( $strFields , 0, strlen($strFields)-1 );
$strValues = substr( $strValues , 0, strlen($strValues)-1 );
$stQry = "INSERT INTO `" . $this->table_name . "` ( " . $strFields . " ) values ( " . $strValues . " ) ";
$result = $this->_dbses->Execute( $stQry , $this->debug);
return $result;
}
/**
* Update an existing row
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function update()
{
$stQry = "";
$stWhere = '';
$remainKeys = array();
if(defined('DB_ADAPTER'))
$DBEngine = DB_ADAPTER;
else
$DBEngine = 'mysql';
foreach ( $this->table_keys as $k => $v ) $remainKeys[ $v ] = false;
foreach( $this->Fields as $field => $val )
{
$iskey = false;
$iskey = in_array( $field, $this->table_keys );
if( $iskey == false ) {
$stQry .= $field . "='" . $val . "', ";
// Commented by new format of textarea in javascript
///-- $stQry .= $field . "='" . G::sqlEscape ( $val, isset( $this->_dbc->type) ? $this->_dbc->type : $DBEngine ) . "', ";
}
else {
if( $stWhere == "" ) {
$stWhere .= $field . "='" . G::sqlEscape ( $val, isset( $this->_dbc->type) ? $this->_dbc->type : $DBEngine ) . "'";
}
else {
$stWhere .= " AND " . $field . "='" . G::sqlEscape ( $val, isset( $this->_dbc->type) ? $this->_dbc->type : $DBEngine ) . "'";
}
$remainKeys[ $field ] = true;
}
}
foreach( $remainKeys as $field => $bool )
if ( $bool == false) {
if( $stWhere != "" ) $stWhere = " AND ";
$stWhere .= $field . "= ''";
$remainKeys[ $field ] = true;
}
$stQry = trim( $stQry );
$stQry = substr( $stQry , 0, strlen($stQry)-1 ); //to remove the last comma ,
if (!$stQry) return;
$stQry = "UPDATE `" . $this->table_name . "` SET " . $stQry;
$stWhere = trim( $stWhere );
if( $stWhere != "" ) $stQry .= " WHERE " . $stWhere;
$result = false;
$result = $this->_dbses->execute( $stQry , $this->debug, $this->errorLevel );
$this->is_new = false;
return $result;
}
/**
* Save a register in a table
*
* depending of value of "is_new" inserts or update is do it
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function save()
{
if ( $this->is_new == true )
return $this->Insert();
else
return $this->Update();
}
/**
* Delete an existing row
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function delete()
{
$stQry = "delete from `" . $this->table_name . "` ";
$stWhere = '';
$remainKeys = array();
if(defined('DB_ADAPTER'))
$DBEngine = DB_ADAPTER;
else
$DBEngine = 'mysql';
foreach ( $this->table_keys as $k => $v ) $remainKeys[ $v ] = false;
if ( is_array ( $this->Fields ) ) {
foreach( $this->Fields as $field => $val )
{
$iskey = false;
$iskey = in_array( $field, $this->table_keys );
if( $iskey == true ) {
if( $stWhere == "" ) {
$stWhere .= $field . "='" . G::sqlEscape ( $val, isset( $this->_dbc->type) ? $this->_dbc->type : $DBEngine ) . "'";
if ($data['Key'] == 'PRI') {
if (is_array( $this->table_keys )) {
$this->table_keys[count( $this->table_keys ) - 1] = $fname;
} else {
$this->table_keys[0] = $fname;
}
}
else {
$stWhere .= " AND " . $field . "='" . G::sqlEscape ( $val, isset( $this->_dbc->type) ? $this->_dbc->type : $DBEngine ) . "'";
switch ($ftype) {
case 'int':
case 'smallint':
case 'tinyint':
case 'decimal':
case 'numeric':
case 'double':
case 'float':
$fval = 0;
break;
}
$remainKeys[ $field ] = true;
}
}
$this->Fields[$fname] = $fval;
$this->Fields[$ncount] = &$this->Fields[$fname];
}
}
foreach( $remainKeys as $field => $bool )
if ( $bool == false) {
if( $stWhere != "" ) $stWhere .= " AND ";
$stWhere .= $field . "= ''";
$remainKeys[ $field ] = true;
}
$stQry = trim( $stQry );
$stWhere = trim( $stWhere );
if ( $stWhere == '' ) {
$dberror = PEAR::raiseError(null, G_ERROR_WARNING_MESSAGE, null, 'null',
"You tried to call delete method without WHERE clause, if you want to delete all records use dbsession",
'G_Error', true);
DBconnection::logError( $dberror, $this->errorLevel );
return $dberror;
/**
* Return specified field on the referenced table
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strWhere string which contains conditions
* @return strint
*/
function loadWhere ($strWhere)
{
$this->Fields = null;
$stQry = "SELECT * FROM `" . $this->table_name . "`";
if ($strWhere != "") {
$stQry .= " WHERE " . $strWhere;
}
$this->_dset = $this->_dbses->Execute( $stQry, $this->debug, $this->errorLevel );
if (DB::isError( $this->_dset )) {
return $this->_dset;
}
if ($this->_dset->Count() > 0) {
$this->Fields = $this->_dset->Read();
$this->is_new = false;
} else {
$this->Fields = null;
$this->is_new = true;
}
return $this->Fields;
}
$stQry .= " WHERE " . $stWhere;
$result = $this->_dbses->execute( $stQry , $this->debug, $this->errorLevel );
$this->is_new = false;
return $result;
}
/**
* Return all fields on the referenced table
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param array array of arguments key values
* @return void
*/
function load ()
{
// bug::traceRoute();
$ncount = 0;
$stWhere = "";
$arrKeys = func_get_args();
if (isset( $arrKeys[0] ) && is_array( $arrKeys[0] )) {
foreach ($this->table_keys as $key => $val) {
if ($stWhere == "") {
$stWhere .= " $val = '" . $arrKeys[0][$val] . "' ";
} else {
$stWhere .= " AND $val = '" . $arrKeys[0][$val] . "' ";
}
}
} else {
foreach ($arrKeys as $val) {
if ($stWhere == "") {
$stWhere .= $this->table_keys[$ncount] . "='" . $val . "'";
} else {
$stWhere .= " AND " . $this->table_keys[$ncount] . "='" . $val . "'";
}
$ncount ++;
}
}
return $this->LoadWhere( $stWhere );
}
/**
* Move to next record in a recordset
*
* Move to next record in a recordset, this is useful where the load method have a recordset with many rows
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function next()
{
$this->Fields = $this->_dset->read ();
}
/**
* Function nextvalPGSql
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string seq
* @return string
*/
function nextvalPGSql ($seq)
{
$stQry = " Select NEXTVAL( '$seq' ) ";
$dset = $this->_dbses->Execute( $stQry );
$row = $dset->Read();
if (is_array( $row )) {
return $row['NEXTVAL'];
}
die( "Sequence '$seq' is not exist!!" );
return - 1;
}
/**
* Insert a new row
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*
*/
function insert ()
{
$strFields = "";
$strValues = "";
if (defined( 'DB_ADAPTER' )) {
$DBEngine = DB_ADAPTER;
} else {
$DBEngine = 'mysql';
}
foreach ($this->Fields as $field => $val) {
$strFields .= $field . ",";
$iskey = false;
if (isset( $this->table_keys ) && is_array( $this->table_keys )) {
$iskey = in_array( $field, $this->table_keys ) && strtoupper( substr( trim( $val ), 0, 7 ) ) == "NEXTVAL";
}
$dbcType = isset( $this->_dbc->type ) ? $this->_dbc->type : $DBEngine;
// Commented by new format of textarea in javascript
if (! $iskey) {
$val = "'" . $val . "'";
}
///-- $val = "'" . G::sqlEscape( $val , $dbcType ) . "'";
$strValues .= $val . ", ";
}
$strFields = substr( $strFields, 0, strlen( $strFields ) - 1 );
$strValues = substr( $strValues, 0, strlen( $strValues ) - 1 );
$stQry = "INSERT INTO `" . $this->table_name . "` ( " . $strFields . " ) values ( " . $strValues . " ) ";
$result = $this->_dbses->Execute( $stQry, $this->debug );
return $result;
}
/**
* Update an existing row
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function update ()
{
$stQry = "";
$stWhere = '';
$remainKeys = array ();
if (defined( 'DB_ADAPTER' )) {
$DBEngine = DB_ADAPTER;
} else {
$DBEngine = 'mysql';
}
foreach ($this->table_keys as $k => $v) {
$remainKeys[$v] = false;
}
foreach ($this->Fields as $field => $val) {
$iskey = false;
$iskey = in_array( $field, $this->table_keys );
if ($iskey == false) {
$stQry .= $field . "='" . $val . "', ";
// Commented by new format of textarea in javascript
///-- $stQry .= $field . "='" . G::sqlEscape ( $val, isset( $this->_dbc->type) ? $this->_dbc->type : $DBEngine ) . "', ";
} else {
if ($stWhere == "") {
$stWhere .= $field . "='" . G::sqlEscape( $val, isset( $this->_dbc->type ) ? $this->_dbc->type : $DBEngine ) . "'";
} else {
$stWhere .= " AND " . $field . "='" . G::sqlEscape( $val, isset( $this->_dbc->type ) ? $this->_dbc->type : $DBEngine ) . "'";
}
$remainKeys[$field] = true;
}
}
foreach ($remainKeys as $field => $bool)
if ($bool == false) {
if ($stWhere != "") {
$stWhere = " AND ";
}
$stWhere .= $field . "= ''";
$remainKeys[$field] = true;
}
$stQry = trim( $stQry );
$stQry = substr( $stQry, 0, strlen( $stQry ) - 1 ); //to remove the last comma ,
if (! $stQry) {
return;
}
$stQry = "UPDATE `" . $this->table_name . "` SET " . $stQry;
$stWhere = trim( $stWhere );
if ($stWhere != "") {
$stQry .= " WHERE " . $stWhere;
}
$result = false;
$result = $this->_dbses->execute( $stQry, $this->debug, $this->errorLevel );
$this->is_new = false;
return $result;
}
/**
* Save a register in a table
*
* depending of value of "is_new" inserts or update is do it
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function save ()
{
if ($this->is_new == true) {
return $this->Insert();
} else {
return $this->Update();
}
}
/**
* Delete an existing row
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function delete ()
{
$stQry = "delete from `" . $this->table_name . "` ";
$stWhere = '';
$remainKeys = array ();
if (defined( 'DB_ADAPTER' )) {
$DBEngine = DB_ADAPTER;
} else {
$DBEngine = 'mysql';
}
foreach ($this->table_keys as $k => $v) {
$remainKeys[$v] = false;
}
if (is_array( $this->Fields )) {
foreach ($this->Fields as $field => $val) {
$iskey = false;
$iskey = in_array( $field, $this->table_keys );
if ($iskey == true) {
if ($stWhere == "") {
$stWhere .= $field . "='" . G::sqlEscape( $val, isset( $this->_dbc->type ) ? $this->_dbc->type : $DBEngine ) . "'";
} else {
$stWhere .= " AND " . $field . "='" . G::sqlEscape( $val, isset( $this->_dbc->type ) ? $this->_dbc->type : $DBEngine ) . "'";
}
$remainKeys[$field] = true;
}
}
}
foreach ($remainKeys as $field => $bool)
if ($bool == false) {
if ($stWhere != "") {
$stWhere .= " AND ";
}
$stWhere .= $field . "= ''";
$remainKeys[$field] = true;
}
$stQry = trim( $stQry );
$stWhere = trim( $stWhere );
if ($stWhere == '') {
$dberror = PEAR::raiseError( null, G_ERROR_WARNING_MESSAGE, null, 'null', "You tried to call delete method without WHERE clause, if you want to delete all records use dbsession", 'G_Error', true );
DBconnection::logError( $dberror, $this->errorLevel );
return $dberror;
}
$stQry .= " WHERE " . $stWhere;
$result = $this->_dbses->execute( $stQry, $this->debug, $this->errorLevel );
$this->is_new = false;
return $result;
}
/**
* Move to next record in a recordset
*
* Move to next record in a recordset, this is useful where the load method have a recordset with many rows
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return boolean
*/
function next ()
{
$this->Fields = $this->_dset->read();
}
}

View File

@@ -1,46 +1,53 @@
<?php
/**
* HttpProxyController
*
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
* @package gulliver.system
* @access private
*/
class HttpProxyController {
class HttpProxyController
{
/**
*
* @var array - private array to store proxy data
*/
private $__data__ = array();
private $__data__ = array ();
/**
* @var object - private object to store the http request data
*
* @var object - private object to store the http request data
*/
private $__request__;
public $jsonResponse = true;
private $sendResponse = true;
/**
* Magic setter method
*
*
* @param string $name
* @param string $value
*/
public function __set($name, $value) {
public function __set ($name, $value)
{
//echo "Setting '$name' to '$value'\n";
$this->__data__[$name] = $value;
}
/**
* Magic getter method
*
*
* @param string $name
* @return string or NULL if the internal var doesn't exist
*/
public function __get($name) {
public function __get ($name)
{
//echo "Getting '$name'\n";
if (array_key_exists($name, $this->__data__)) {
if (array_key_exists( $name, $this->__data__ )) {
return $this->__data__[$name];
}
@@ -55,89 +62,102 @@ class HttpProxyController {
/**
* Magic isset method
*
*
* @param string $name
*/
public function __isset($name) {
public function __isset ($name)
{
//echo "Is '$name' set?\n";
return isset($this->__data__[$name]);
return isset( $this->__data__[$name] );
}
/**
* Magic unset method
*
*
* @param string $name
*/
public function __unset($name) {
public function __unset ($name)
{
//echo "Unsetting '$name'\n";
unset($this->__data__[$name]);
unset( $this->__data__[$name] );
}
/**
* call to execute a internal proxy method and handle its exceptions
*
*
* @param string $name
*/
public function call($name)
public function call ($name)
{
try {
$result = $this->$name($this->__request__);
$result = $this->$name( $this->__request__ );
if (!$this->jsonResponse) {
if (! $this->jsonResponse) {
return null;
}
if( ! $result )
$result = $this->__data__;
if (! $result) {
$result = $this->__data__;
}
} catch (Exception $e) {
$result->success = false;
$result->message = $result->msg = $e->getMessage();
switch(get_class($e)) {
case 'Exception': $error = "SYSTEM ERROR"; break;
case 'PMException': $error = "PROCESSMAKER ERROR"; break;
case 'PropelException': $error = "DATABASE ERROR"; break;
case 'UserException': $error = "USER ERROR"; break;
switch (get_class( $e )) {
case 'Exception':
$error = "SYSTEM ERROR";
break;
case 'PMException':
$error = "PROCESSMAKER ERROR";
break;
case 'PropelException':
$error = "DATABASE ERROR";
break;
case 'UserException':
$error = "USER ERROR";
break;
}
$result->error = $e->getMessage();
$result->exception->class = get_class($e);
$result->exception->class = get_class( $e );
$result->exception->code = $e->getCode();
$result->exception->trace = $e->getTraceAsString();
}
if ($this->sendResponse) {
print G::json_encode($result);
print G::json_encode( $result );
}
}
/**
* Set the http request data
*
*
* @param array $data
*/
public function setHttpRequestData($data)
public function setHttpRequestData ($data)
{
if( is_array($data) ) {
while( $var = each($data) )
$this->__request__->$var['key'] = $var['value'];
} else
if (is_array( $data )) {
while ($var = each( $data )) {
$this->__request__->$var['key'] = $var['value'];
}
} else {
$this->__request__ = $data;
}
}
public function setJsonResponse($bool)
public function setJsonResponse ($bool)
{
$this->jsonResponse = $bool;
}
/**
* Send response to client
*
*
* @param boolean $val
*/
public function setSendResponse($val)
public function setSendResponse ($val)
{
$this->sendResponse = $val;
}
}

View File

@@ -1,7 +1,9 @@
<?php
/**
* class.dbtable.php
* @package gulliver.system
*
* @package gulliver.system
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc.
@@ -13,375 +15,395 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
* 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.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
/**
* i18n_PO
/**
* i18n_PO
* This class build biggers PO files without size limit and this not use much memory that the allowed
*
*
* @package gulliver.system
* @author Erik Amaru Ortiz <erik@colosa.com>
* date Aug 31th, 2010
* @copyright (C) 2002 by Colosa Development Team.
*/
class i18n_PO
{
private $_file = NULL;
private $_string = '';
private $_meta;
private $_fp;
private $_fileComments;
protected $_editingHeader;
protected $_fileLine;
protected $flagEndHeaders;
protected $flagError;
protected $flagInit;
protected $lineNumber;
public $translatorComments;
public $extractedComments;
public $references;
public $flags;
public $previousUntranslatedStrings;
function __construct($file)
{
$this->file = $file;
}
function buildInit()
{
$this->_fp = fopen($this->file, 'w');
if ( ! is_resource($this->_fp) ) {
throw new Exception('Could\'t open ' . $this->file . ' file');
}
// lock PO file exclusively
if ( ! flock($this->_fp, LOCK_EX) ) {
fclose($this->_fp);
return FALSE;
}
$this->_meta = 'msgid ""';
$this->_writeLine($this->_meta);
$this->_meta = 'msgstr ""';
$this->_writeLine($this->_meta);
$this->_editingHeader = TRUE;
}
private $_file = null;
private $_string = '';
private $_meta;
private $_fp;
private $_fileComments;
function readInit(){
$this->_fp = fopen($this->file, 'r');
if ( ! is_resource($this->_fp) ) {
throw new Exception('Could\'t open ' . $this->file . ' file');
}
//skipping comments
$this->skipCommets();
//deaing headers
$this->readHeaders();
$this->translatorComments = Array();
$this->extractedComments = Array();
$this->references = Array();
$this->flags = Array();
$this->previousUntranslatedStrings = Array();
}
protected $_editingHeader;
protected $_fileLine;
function addHeader($id, $value)
{
if( $this->_editingHeader ) {
$meta = '"'.trim($id).': '.trim($value).'\n"';
$this->_writeLine($meta);
}
}
function addTranslatorComment($str)
{
$this->headerStroke();
$comment = '# ' . trim($str);
$this->_writeLine($comment);
}
function addExtractedComment($str)
{
$this->headerStroke();
$comment = '#. ' . trim($str);
$this->_writeLine($comment);
}
function addReference($str)
{
$this->headerStroke();
$reference = '#: ' . trim($str);
$this->_writeLine($reference);
}
function addFlag($str)
{
$this->headerStroke();
$flag = '#, ' . trim($str);
$this->_writeLine($flag);
}
function addPreviousUntranslatedString($str)
{
$this->headerStroke();
$str = '#| ' . trim($str);
$this->_writeLine($str);
}
function addTranslation($msgid, $msgstr)
{
$this->headerStroke();
$this->_writeLine('msgid "' . $this->prepare($msgid, true) . '"');
$this->_writeLine('msgstr "' . $this->prepare($msgstr, true) . '"');
$this->_writeLine('');
}
function _writeLine($str)
{
$this->_write($str . "\n");
}
function _write($str)
{
fwrite($this->_fp, $str);
}
function prepare($string, $reverse = false)
{
//$string = str_replace('\"', '"', $string);
//$string = stripslashes($string);
if ($reverse) {
$smap = array('"', "\n", "\t", "\r");
$rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r');
return (string) str_replace($smap, $rmap, $string);
} else {
$string = preg_replace('/"\s+"/', '', $string);
$smap = array('\\n', '\\r', '\\t', '\"');
$rmap = array("\n", "\r", "\t", '"');
return (string) str_replace($smap, $rmap, $string);
}
}
function headerStroke()
{
if( $this->_editingHeader ) {
$this->_editingHeader = FALSE;
$this->_writeLine('');;
}
}
/** read funtions **/
private function skipCommets(){
$this->_fileComments = '';
do {
$lastPos = ftell($this->_fp);
$line = fgets($this->_fp);
$this->_fileComments .= $line;
} while( (substr($line, 0, 1) == '#' || trim($line) == '') && ! feof($this->_fp) );
fseek($this->_fp, $lastPos);
}
protected $flagEndHeaders;
protected $flagError;
protected $flagInit;
protected $lineNumber;
private function readHeaders()
{
$this->flagEndHeaders = false;
$this->flagError = false;
$this->flagInit = true;
$this->lineNumber = 0;
$errMsg = '';
while( ! $this->flagError && ! $this->flagEndHeaders ) {
if( $this->flagInit ) { //in first instance
$this->flagInit = false; //unset init flag
public $translatorComments;
public $extractedComments;
public $references;
public $flags;
public $previousUntranslatedStrings;
//read the first and second line of the file
$firstLine = fgets($this->_fp);
$secondLine = fgets($this->_fp);
function __construct ($file)
{
$this->file = $file;
}
//verifying the file head
if( strpos($firstLine, 'msgid ""') === false || strpos($secondLine, 'msgstr ""') === false ){
$this->flagError = true;
$errMsg = 'Misplace for firts msgid "" and msgstr "" in the header';
function buildInit ()
{
$this->_fp = fopen( $this->file, 'w' );
if (! is_resource( $this->_fp )) {
throw new Exception( 'Could\'t open ' . $this->file . ' file' );
}
continue;
}
//getting the new line
$this->_fileLine = trim(fgets($this->_fp));
//set line number
$this->lineNumber++;
//verifying that is not end of file and applying a restriction for to read just the twenty firsts lines
if( trim($this->_fileLine) == '' || ! $this->_fileLine || $this->lineNumber >= 20 ) {
$this->flagEndHeaders = true; // set ending to read the headers
continue;
}
//verify if has a valid mask header line
preg_match('/^"([a-z0-9\._-]+)\s*:\s*([\W\w]+)\\\n"$/i', $this->_fileLine, $match);
// lock PO file exclusively
if (! flock( $this->_fp, LOCK_EX )) {
fclose( $this->_fp );
return false;
}
//for a valid header line the $match size should three
if( sizeof($match) == 3 ) {
$key = trim($match[1]); //getting the key of the header
$value = trim($match[2]); //getting the value of the header
$this->_meta[$key] = $value; //setting a new header
} else {
$this->flagEndHeaders = true; //otherwise set the ending to read the headers
break;
}
}//end looking for headeers
//verifying the headers data
if( ! isset($this->_meta['X-Poedit-Language']) ) {
$this->flagError = true;
$errMsg = "X-Poedit-Language meta doesn't exist";
} else if ( $this->_meta['X-Poedit-Language'] == '' ) {
$this->flagError = true;
$errMsg = "X-Poedit-Language meta is empty";
$this->_meta = 'msgid ""';
$this->_writeLine( $this->_meta );
$this->_meta = 'msgstr ""';
$this->_writeLine( $this->_meta );
$this->_editingHeader = true;
}
//if the country is not present in metadata
if( ! isset($this->_meta['X-Poedit-Country']) ) {
$this->_meta['X-Poedit-Country'] = '.';
} else if( $this->_meta['X-Poedit-Country'] == '' ) {
$this->_meta['X-Poedit-Country'] = '.';
function readInit ()
{
$this->_fp = fopen( $this->file, 'r' );
if (! is_resource( $this->_fp )) {
throw new Exception( 'Could\'t open ' . $this->file . ' file' );
}
//skipping comments
$this->skipCommets();
//deaing headers
$this->readHeaders();
$this->translatorComments = Array ();
$this->extractedComments = Array ();
$this->references = Array ();
$this->flags = Array ();
$this->previousUntranslatedStrings = Array ();
}
//thowing the exception if is necesary
if( $this->flagError ){
throw new Exception("This file is not a valid PO file. ($errMsg)");
function addHeader ($id, $value)
{
if ($this->_editingHeader) {
$meta = '"' . trim( $id ) . ': ' . trim( $value ) . '\n"';
$this->_writeLine( $meta );
}
}
}
function getHeaders() {
return $this->_meta;
}
public function getTranslation(){
$flagReadingComments = true;
$this->translatorComments = Array();
$this->extractedComments = Array();
$this->references = Array();
$this->flags = Array();
//getting the new line
while( $flagReadingComments && ! $this->flagError ) {
$this->_fileLine = trim(fgets($this->_fp));
//set line number
$this->lineNumber++;
if( ! $this->_fileLine )
return false;
$prefix = substr($this->_fileLine, 0, 2);
switch($prefix) {
case '# ':
$lineItem = str_replace('# ', '', $this->_fileLine);
$this->translatorComments[] = $lineItem;
break;
case '#.':
if( substr_count($this->_fileLine, '#. ') == 0 )
$this->flagError = true;
else {
$lineItem = str_replace('#. ', '', $this->_fileLine);
$this->extractedComments[] = $lineItem;
}
break;
case '#:':
if( substr_count($this->_fileLine, '#: ') == 0 )
$this->flagError = true;
else {
$lineItem = str_replace('#: ', '', $this->_fileLine);
$this->references[] = $lineItem;
}
break;
case '#,':
if( substr_count($this->_fileLine, '#, ') == 0 )
$this->flagError = true;
else {
$lineItem = str_replace('#, ', '', $this->_fileLine);
$this->flags[] = $lineItem;
}
break;
case '#|':
if( substr_count($this->_fileLine, '#| ') == 0 )
$this->flagError = true;
else {
$lineItem = str_replace('#| ', '', $this->_fileLine);
$this->previousUntranslatedStrings[] = $lineItem;
}
break;
default:
$flagReadingComments = false;
}
function addTranslatorComment ($str)
{
$this->headerStroke();
$comment = '# ' . trim( $str );
$this->_writeLine( $comment );
}
if( ! $this->_fileLine )
return false;
//Getting the msgid
preg_match('/\s*msgid\s*"(.*)"\s*/s', $this->_fileLine, $match);
if( sizeof($match) != 2 )
throw new Exception('Invalid PO file format1');
$msgid = '';
do {
//g::pr($match);
$msgid .= $match[1];
$this->_fileLine = trim(fgets($this->_fp));
preg_match('/^"(.*)"\s*/s', $this->_fileLine, $match);
} while ( sizeof($match) == 2 );
//Getting the msgstr
preg_match('/\s*msgstr\s*"(.*)"\s*/s', $this->_fileLine, $match);
if( sizeof($match) != 2 )
throw new Exception('Invalid PO file format2');
function addExtractedComment ($str)
{
$this->headerStroke();
$comment = '#. ' . trim( $str );
$this->_writeLine( $comment );
}
$msgstr = '';
do {
//g::pr($match);
$msgstr .= $match[1] . "\n";
$this->_fileLine = trim(fgets($this->_fp));
preg_match('/^"(.*)"\s*/s', $this->_fileLine, $match);
} while ( sizeof($match) == 2 );
/*g::pr($this->translatorComments);
g::pr($this->references);
g::pr($match);
die;*/
return Array('msgid'=>trim($msgid), 'msgstr'=>trim($msgstr));
}
//garbage
function __destruct()
{
if ( $this->_fp )
fclose($this->_fp);
}
function addReference ($str)
{
$this->headerStroke();
$reference = '#: ' . trim( $str );
$this->_writeLine( $reference );
}
function addFlag ($str)
{
$this->headerStroke();
$flag = '#, ' . trim( $str );
$this->_writeLine( $flag );
}
function addPreviousUntranslatedString ($str)
{
$this->headerStroke();
$str = '#| ' . trim( $str );
$this->_writeLine( $str );
}
function addTranslation ($msgid, $msgstr)
{
$this->headerStroke();
$this->_writeLine( 'msgid "' . $this->prepare( $msgid, true ) . '"' );
$this->_writeLine( 'msgstr "' . $this->prepare( $msgstr, true ) . '"' );
$this->_writeLine( '' );
}
function _writeLine ($str)
{
$this->_write( $str . "\n" );
}
function _write ($str)
{
fwrite( $this->_fp, $str );
}
function prepare ($string, $reverse = false)
{
//$string = str_replace('\"', '"', $string);
//$string = stripslashes($string);
if ($reverse) {
$smap = array ('"',"\n","\t","\r"
);
$rmap = array ('\"','\\n"' . "\n" . '"','\\t','\\r'
);
return (string) str_replace( $smap, $rmap, $string );
} else {
$string = preg_replace( '/"\s+"/', '', $string );
$smap = array ('\\n','\\r','\\t','\"'
);
$rmap = array ("\n","\r","\t",'"'
);
return (string) str_replace( $smap, $rmap, $string );
}
}
function headerStroke ()
{
if ($this->_editingHeader) {
$this->_editingHeader = false;
$this->_writeLine( '' );
;
}
}
/**
* read funtions *
*/
private function skipCommets ()
{
$this->_fileComments = '';
do {
$lastPos = ftell( $this->_fp );
$line = fgets( $this->_fp );
$this->_fileComments .= $line;
} while ((substr( $line, 0, 1 ) == '#' || trim( $line ) == '') && ! feof( $this->_fp ));
fseek( $this->_fp, $lastPos );
}
private function readHeaders ()
{
$this->flagEndHeaders = false;
$this->flagError = false;
$this->flagInit = true;
$this->lineNumber = 0;
$errMsg = '';
while (! $this->flagError && ! $this->flagEndHeaders) {
if ($this->flagInit) { //in first instance
$this->flagInit = false; //unset init flag
//read the first and second line of the file
$firstLine = fgets( $this->_fp );
$secondLine = fgets( $this->_fp );
//verifying the file head
if (strpos( $firstLine, 'msgid ""' ) === false || strpos( $secondLine, 'msgstr ""' ) === false) {
$this->flagError = true;
$errMsg = 'Misplace for firts msgid "" and msgstr "" in the header';
}
continue;
}
//getting the new line
$this->_fileLine = trim( fgets( $this->_fp ) );
//set line number
$this->lineNumber ++;
//verifying that is not end of file and applying a restriction for to read just the twenty firsts lines
if (trim( $this->_fileLine ) == '' || ! $this->_fileLine || $this->lineNumber >= 20) {
$this->flagEndHeaders = true; // set ending to read the headers
continue;
}
//verify if has a valid mask header line
preg_match( '/^"([a-z0-9\._-]+)\s*:\s*([\W\w]+)\\\n"$/i', $this->_fileLine, $match );
//for a valid header line the $match size should three
if (sizeof( $match ) == 3) {
$key = trim( $match[1] ); //getting the key of the header
$value = trim( $match[2] ); //getting the value of the header
$this->_meta[$key] = $value; //setting a new header
} else {
$this->flagEndHeaders = true; //otherwise set the ending to read the headers
break;
}
} //end looking for headeers
//verifying the headers data
if (! isset( $this->_meta['X-Poedit-Language'] )) {
$this->flagError = true;
$errMsg = "X-Poedit-Language meta doesn't exist";
} else if ($this->_meta['X-Poedit-Language'] == '') {
$this->flagError = true;
$errMsg = "X-Poedit-Language meta is empty";
}
//if the country is not present in metadata
if (! isset( $this->_meta['X-Poedit-Country'] )) {
$this->_meta['X-Poedit-Country'] = '.';
} else if ($this->_meta['X-Poedit-Country'] == '') {
$this->_meta['X-Poedit-Country'] = '.';
}
//thowing the exception if is necesary
if ($this->flagError) {
throw new Exception( "This file is not a valid PO file. ($errMsg)" );
}
}
function getHeaders ()
{
return $this->_meta;
}
public function getTranslation ()
{
$flagReadingComments = true;
$this->translatorComments = Array ();
$this->extractedComments = Array ();
$this->references = Array ();
$this->flags = Array ();
//getting the new line
while ($flagReadingComments && ! $this->flagError) {
$this->_fileLine = trim( fgets( $this->_fp ) );
//set line number
$this->lineNumber ++;
if (! $this->_fileLine) {
return false;
}
$prefix = substr( $this->_fileLine, 0, 2 );
switch ($prefix) {
case '# ':
$lineItem = str_replace( '# ', '', $this->_fileLine );
$this->translatorComments[] = $lineItem;
break;
case '#.':
if (substr_count( $this->_fileLine, '#. ' ) == 0) {
$this->flagError = true;
} else {
$lineItem = str_replace( '#. ', '', $this->_fileLine );
$this->extractedComments[] = $lineItem;
}
break;
case '#:':
if (substr_count( $this->_fileLine, '#: ' ) == 0) {
$this->flagError = true;
} else {
$lineItem = str_replace( '#: ', '', $this->_fileLine );
$this->references[] = $lineItem;
}
break;
case '#,':
if (substr_count( $this->_fileLine, '#, ' ) == 0) {
$this->flagError = true;
} else {
$lineItem = str_replace( '#, ', '', $this->_fileLine );
$this->flags[] = $lineItem;
}
break;
case '#|':
if (substr_count( $this->_fileLine, '#| ' ) == 0) {
$this->flagError = true;
} else {
$lineItem = str_replace( '#| ', '', $this->_fileLine );
$this->previousUntranslatedStrings[] = $lineItem;
}
break;
default:
$flagReadingComments = false;
}
}
if (! $this->_fileLine) {
return false;
}
//Getting the msgid
preg_match( '/\s*msgid\s*"(.*)"\s*/s', $this->_fileLine, $match );
if (sizeof( $match ) != 2) {
throw new Exception( 'Invalid PO file format1' );
}
$msgid = '';
do {
//g::pr($match);
$msgid .= $match[1];
$this->_fileLine = trim( fgets( $this->_fp ) );
preg_match( '/^"(.*)"\s*/s', $this->_fileLine, $match );
} while (sizeof( $match ) == 2);
//Getting the msgstr
preg_match( '/\s*msgstr\s*"(.*)"\s*/s', $this->_fileLine, $match );
if (sizeof( $match ) != 2) {
throw new Exception( 'Invalid PO file format2' );
}
$msgstr = '';
do {
//g::pr($match);
$msgstr .= $match[1] . "\n";
$this->_fileLine = trim( fgets( $this->_fp ) );
preg_match( '/^"(.*)"\s*/s', $this->_fileLine, $match );
} while (sizeof( $match ) == 2);
/*g::pr($this->translatorComments);
g::pr($this->references);
g::pr($match);
die;*/
return Array ('msgid' => trim( $msgid ),'msgstr' => trim( $msgstr )
);
}
//garbage
function __destruct ()
{
if ($this->_fp) {
fclose( $this->_fp );
}
}
}

View File

@@ -1,11 +1,12 @@
<?php
/**
* class.mailer.php
* @package gulliver.system
*
* @package gulliver.system
*
* 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
* published by the Free Software Foundation, either version 3 of the
@@ -13,17 +14,17 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
*
* 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.,
* 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.
*
*
*/
G::LoadThirdParty('phpmailer','class.phpmailer');
G::LoadThirdParty( 'phpmailer', 'class.phpmailer' );
/* Send emails using the class "PHPMailer"
* Email server configuration constants:
* MAIL_MAILER mail/smtp
@@ -39,237 +40,276 @@ G::LoadThirdParty('phpmailer','class.phpmailer');
* @author David Callizaya <davidsantos@colosa.com>
*/
/**
/**
*
* @package gulliver.system
**/
*
*/
class mailer
{
/**
* instanceMailer
*
* @return object(PHPMailer) $mailer
*/
function instanceMailer()
{
$mailer = new PHPMailer;
$mailer->PluginDir=PATH_THIRDPARTY.'phpmailer/';
//DEFAULT CONFIGURATION
$mailer->Mailer = 'mail';
$mailer->Host = "";
$mailer->SMTPAuth = false;
$mailer->Username = "";
$mailer->Password = "";
$mailer->Timeout = 30;
$mailer->CharSet = 'utf-8';
$mailer->Encoding='base64';
if (defined('MAIL_MAILER')) $mailer->Mailer = MAIL_MAILER;
if (defined('MAIL_HOST')) $mailer->Host = MAIL_HOST;
if (defined('MAIL_SMTPAUTH')) $mailer->SMTPAuth = MAIL_SMTPAUTH;
if (defined('MAIL_USERNAME')) $mailer->Username = MAIL_USERNAME;
if (defined('MAIL_PASSWORD')) $mailer->Password = MAIL_PASSWORD;
if (defined('MAIL_TIMEOUT')) $mailer->Timeout = MAIL_TIMEOUT;
if (defined('MAIL_CHARSET')) $mailer->CharSet = MAIL_CHARSET;
if (defined('MAIL_ENCODING')) $mailer->Encoding= MAIL_ENCODING;
return $mailer;
}
/* ARPA INTERNET TEXT MESSAGES
* Returns an array with the "name" and "email" of an ARPA type
* email $address.
* @author David Callizaya
*/
function arpaEMAIL($address)
{
$arpa = array();
preg_match("/([^<>]*)(?:\<([^<>]*)\>)?/",$address,$matches);
$isEmail = preg_match("/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i",$matches[1]);
$arpa['email'] = ((isset($matches[2]))&&($matches[2]!=''))?$matches[2]:(($isEmail)?$matches[1]:'');
$arpa['name'] = ($isEmail)?'':$matches[1];
return $arpa;
}
/**
* sendTemplate
*
* @param string $from default value empty
* @param string $target default value default value empty
* @param string $cc default value default value empty
* @param string $bcc default value default value empty
* @param string $subject default value empty
* @param array $Fields
* @param string $templateFile default value "empty.html"
* @param array $attachs
* @param boolean $plainText default value false
* @param boolean $returnContent default value false
*
* @return object $content or $result
*/
function sendTemplate( $from = "", $target = "", $cc = "", $bcc="" ,$subject = "", $Fields = array(), $templateFile = "empty.html", $attachs=array(), $plainText=false, $returnContent = false )
{
// Read the content of the TemplateFile
$fp = fopen(PATH_HTMLMAIL . $templateFile,"r");
$content = fread($fp,filesize(PATH_HTMLMAIL . $templateFile));
fclose($fp);
//Replace the @@Fields with the $Fields array.
$content = mailer::replaceFields($Fields,$content);
//Compatibility with class.Application
if ($attachs==='FALSE')
return $content;
//Create the alternative body (text only)
//$h2t =& new html2text($content);
$text = '';//$h2t->get_text();
//Prepate el phpmailer
$mailer = mailer::instanceMailer();
$arpa = mailer::arpaEMAIL($from);
$mailer->From = $arpa['email']==''?$mailer->defaultEMail:$arpa['email'];
$mailer->FromName = $arpa['name'];
$arpa = mailer::arpaEMAIL($target);
$mailer->AddAddress($arpa['email'],$arpa['name']);
$mailer->AddCC($cc);
$mailer->AddBCC($bcc);
$mailer->Subject = $subject;
if ($plainText)
$content = $text;
if ($content==='')
$content='empty';
$mailer->Body = $content;
//$mailer->AltBody = $text;
$mailer->isHTML(!$plainText);
//Attach the required files
if (is_array($attachs))
if (sizeof($attachs)>0)
foreach($attachs as $aFile)
$mailer->AddAttachment($aFile,basename($aFile));
//Send the e-mail.
for($r=1;$r<=4;$r++) {
$result = $mailer->Send();
if ($result) break;
/**
* instanceMailer
*
* @return object(PHPMailer) $mailer
*/
function instanceMailer ()
{
$mailer = new PHPMailer();
$mailer->PluginDir = PATH_THIRDPARTY . 'phpmailer/';
//DEFAULT CONFIGURATION
$mailer->Mailer = 'mail';
$mailer->Host = "";
$mailer->SMTPAuth = false;
$mailer->Username = "";
$mailer->Password = "";
$mailer->Timeout = 30;
$mailer->CharSet = 'utf-8';
$mailer->Encoding = 'base64';
if (defined( 'MAIL_MAILER' )) {
$mailer->Mailer = MAIL_MAILER;
}
if (defined( 'MAIL_HOST' )) {
$mailer->Host = MAIL_HOST;
}
if (defined( 'MAIL_SMTPAUTH' )) {
$mailer->SMTPAuth = MAIL_SMTPAUTH;
}
if (defined( 'MAIL_USERNAME' )) {
$mailer->Username = MAIL_USERNAME;
}
if (defined( 'MAIL_PASSWORD' )) {
$mailer->Password = MAIL_PASSWORD;
}
if (defined( 'MAIL_TIMEOUT' )) {
$mailer->Timeout = MAIL_TIMEOUT;
}
if (defined( 'MAIL_CHARSET' )) {
$mailer->CharSet = MAIL_CHARSET;
}
if (defined( 'MAIL_ENCODING' )) {
$mailer->Encoding = MAIL_ENCODING;
}
return $mailer;
}
//unset($h2t);
if ($result && $returnContent) return $content;
return $result;
}
/**
* sendHtml
*
* @param string $from default value empty
* @param string $target default value empty
* @param string $cc default value empty
* @param string $bcc default value empty
* @param string $subject default value empty
* @param array $Fields
* @param string $content default value empty
* @param array $attachs default value empty
* @param string $plainText default false
* @param boolean $returnContent default value false
*
* @return object $result
*/
function sendHtml( $from = "", $target = "", $cc = "", $bcc="" ,$subject = "", $Fields = array(), $content = "", $attachs=array(), $plainText=false, $returnContent = false )
{
//Replace the @@Fields with the $Fields array.
$content = mailer::replaceFields($Fields,$content);
//Create the alternative body (text only)
//$h2t =& new html2text($content);
$text = '';//$h2t->get_text();
//Prepate el phpmailer
$mailer = mailer::instanceMailer();
$arpa = mailer::arpaEMAIL($from);
$mailer->From = $arpa['email']==''?$mailer->defaultEMail:$arpa['email'];
$mailer->FromName = $arpa['name'];
$arpa = mailer::arpaEMAIL($target);
$mailer->AddAddress($arpa['email'],$arpa['name']);
$mailer->AddCC($cc);
$mailer->AddBCC($bcc);
$mailer->Subject = $subject;
if ($plainText) $content = $text;
if ($content==='') $content='empty';
$mailer->Body = $content;
//$mailer->AltBody = $text;
$mailer->isHTML(!$plainText);
//Attach the required files
if (is_array($attachs))
if (sizeof($attachs)>0)
foreach($attachs as $aFile)
$mailer->AddAttachment($aFile,basename($aFile));
//Send the e-mail.
for($r=1;$r<=4;$r++) {
$result=$mailer->Send();
if ($result) break;
}
//unset($h2t);
if ($result && $returnContent) return $content;
return $result;
}
/**
* sendText
*
* @param string $from default value empty
* @param string $target default value empty
* @param string $cc default value empty
* @param string $bcc default value empty
* @param string $subject default value empty
* @param string $content default value empty
* @param array $attachs
*
* @return object $result
*/
function sendText( $from = "", $target = "", $cc = "", $bcc="" ,$subject = "", $content = "", $attachs=array())
{
//Prepate el phpmailer
$mailer = mailer::instanceMailer();
$arpa = mailer::arpaEMAIL($from);
$mailer->From = $arpa['email']==''?$mailer->defaultEMail:$arpa['email'];
$mailer->FromName = $arpa['name'];
$arpa = mailer::arpaEMAIL($target);
$mailer->AddAddress($arpa['email'],$arpa['name']);
$mailer->AddCC($cc);
$mailer->AddBCC($bcc);
$mailer->Subject = $subject;
if ($content==='') $content='empty';
$mailer->Body = $content;
$mailer->AltBody = $content;
$mailer->isHTML(false);
//Attach the required files
if (sizeof($attachs)>0)
foreach($attachs as $aFile)
$mailer->AddAttachment($aFile,basename($aFile));
//Send the e-mail.
for($r=1;$r<=4;$r++) {
$result=$mailer->Send();
if ($result) break;
}
return $result;
}
/**
* replaceFields
*
* @param array $Fields
* @param string $content default value string empty
*
* @return none
*/
function replaceFields($Fields = array(), $content = "")
{
return G::replaceDataField( $content , $Fields );
}
/**
* html2text
*
* empty
* @return none
*/
function html2text()
{
//$h2t =& new html2text($content);
//return $h2t->get_text();
}
/* ARPA INTERNET TEXT MESSAGES
* Returns an array with the "name" and "email" of an ARPA type
* email $address.
* @author David Callizaya
*/
function arpaEMAIL ($address)
{
$arpa = array ();
preg_match( "/([^<>]*)(?:\<([^<>]*)\>)?/", $address, $matches );
$isEmail = preg_match( "/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i", $matches[1] );
$arpa['email'] = ((isset( $matches[2] )) && ($matches[2] != '')) ? $matches[2] : (($isEmail) ? $matches[1] : '');
$arpa['name'] = ($isEmail) ? '' : $matches[1];
return $arpa;
}
/**
* sendTemplate
*
* @param string $from default value empty
* @param string $target default value default value empty
* @param string $cc default value default value empty
* @param string $bcc default value default value empty
* @param string $subject default value empty
* @param array $Fields
* @param string $templateFile default value "empty.html"
* @param array $attachs
* @param boolean $plainText default value false
* @param boolean $returnContent default value false
*
* @return object $content or $result
*/
function sendTemplate ($from = "", $target = "", $cc = "", $bcc = "", $subject = "", $Fields = array(), $templateFile = "empty.html", $attachs = array(), $plainText = false, $returnContent = false)
{
// Read the content of the TemplateFile
$fp = fopen( PATH_HTMLMAIL . $templateFile, "r" );
$content = fread( $fp, filesize( PATH_HTMLMAIL . $templateFile ) );
fclose( $fp );
//Replace the @@Fields with the $Fields array.
$content = mailer::replaceFields( $Fields, $content );
//Compatibility with class.Application
if ($attachs === 'FALSE') {
return $content;
}
//Create the alternative body (text only)
//$h2t =& new html2text($content);
$text = ''; //$h2t->get_text();
//Prepate el phpmailer
$mailer = mailer::instanceMailer();
$arpa = mailer::arpaEMAIL( $from );
$mailer->From = $arpa['email'] == '' ? $mailer->defaultEMail : $arpa['email'];
$mailer->FromName = $arpa['name'];
$arpa = mailer::arpaEMAIL( $target );
$mailer->AddAddress( $arpa['email'], $arpa['name'] );
$mailer->AddCC( $cc );
$mailer->AddBCC( $bcc );
$mailer->Subject = $subject;
if ($plainText) {
$content = $text;
}
if ($content === '') {
$content = 'empty';
}
$mailer->Body = $content;
//$mailer->AltBody = $text;
$mailer->isHTML( ! $plainText );
//Attach the required files
if (is_array( $attachs ))
if (sizeof( $attachs ) > 0)
foreach ($attachs as $aFile)
$mailer->AddAttachment( $aFile, basename( $aFile ) );
//Send the e-mail.
for ($r = 1; $r <= 4; $r ++) {
$result = $mailer->Send();
if ($result) {
break;
}
}
//unset($h2t);
if ($result && $returnContent) {
return $content;
}
return $result;
}
/**
* sendHtml
*
* @param string $from default value empty
* @param string $target default value empty
* @param string $cc default value empty
* @param string $bcc default value empty
* @param string $subject default value empty
* @param array $Fields
* @param string $content default value empty
* @param array $attachs default value empty
* @param string $plainText default false
* @param boolean $returnContent default value false
*
* @return object $result
*/
function sendHtml ($from = "", $target = "", $cc = "", $bcc = "", $subject = "", $Fields = array(), $content = "", $attachs = array(), $plainText = false, $returnContent = false)
{
//Replace the @@Fields with the $Fields array.
$content = mailer::replaceFields( $Fields, $content );
//Create the alternative body (text only)
//$h2t =& new html2text($content);
$text = ''; //$h2t->get_text();
//Prepate el phpmailer
$mailer = mailer::instanceMailer();
$arpa = mailer::arpaEMAIL( $from );
$mailer->From = $arpa['email'] == '' ? $mailer->defaultEMail : $arpa['email'];
$mailer->FromName = $arpa['name'];
$arpa = mailer::arpaEMAIL( $target );
$mailer->AddAddress( $arpa['email'], $arpa['name'] );
$mailer->AddCC( $cc );
$mailer->AddBCC( $bcc );
$mailer->Subject = $subject;
if ($plainText) {
$content = $text;
}
if ($content === '') {
$content = 'empty';
}
$mailer->Body = $content;
//$mailer->AltBody = $text;
$mailer->isHTML( ! $plainText );
//Attach the required files
if (is_array( $attachs ))
if (sizeof( $attachs ) > 0)
foreach ($attachs as $aFile)
$mailer->AddAttachment( $aFile, basename( $aFile ) );
//Send the e-mail.
for ($r = 1; $r <= 4; $r ++) {
$result = $mailer->Send();
if ($result) {
break;
}
}
//unset($h2t);
if ($result && $returnContent) {
return $content;
}
return $result;
}
/**
* sendText
*
* @param string $from default value empty
* @param string $target default value empty
* @param string $cc default value empty
* @param string $bcc default value empty
* @param string $subject default value empty
* @param string $content default value empty
* @param array $attachs
*
* @return object $result
*/
function sendText ($from = "", $target = "", $cc = "", $bcc = "", $subject = "", $content = "", $attachs = array())
{
//Prepate el phpmailer
$mailer = mailer::instanceMailer();
$arpa = mailer::arpaEMAIL( $from );
$mailer->From = $arpa['email'] == '' ? $mailer->defaultEMail : $arpa['email'];
$mailer->FromName = $arpa['name'];
$arpa = mailer::arpaEMAIL( $target );
$mailer->AddAddress( $arpa['email'], $arpa['name'] );
$mailer->AddCC( $cc );
$mailer->AddBCC( $bcc );
$mailer->Subject = $subject;
if ($content === '') {
$content = 'empty';
}
$mailer->Body = $content;
$mailer->AltBody = $content;
$mailer->isHTML( false );
//Attach the required files
if (sizeof( $attachs ) > 0) {
foreach ($attachs as $aFile) {
$mailer->AddAttachment( $aFile, basename( $aFile ) );
}
}
//Send the e-mail.
for ($r = 1; $r <= 4; $r ++) {
$result = $mailer->Send();
if ($result) {
break;
}
}
return $result;
}
/**
* replaceFields
*
* @param array $Fields
* @param string $content default value string empty
*
* @return none
*/
function replaceFields ($Fields = array(), $content = "")
{
return G::replaceDataField( $content, $Fields );
}
/**
* html2text
*
* empty
*
* @return none
*/
function html2text ()
{
//$h2t =& new html2text($content);
//return $h2t->get_text();
}
}
?>

View File

@@ -1,7 +1,9 @@
<?php
/**
* class.menu.php
* @package gulliver.system
*
* @package gulliver.system
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc.
@@ -13,23 +15,27 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
* 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.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
/**
*
* @package gulliver.system
*/
*
*/
/**
*
*
* Menu class definition
* Render Menus
*
* @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team.
@@ -37,343 +43,342 @@
*/
class Menu
{
var $Id = NULL;
var $Options = NULL;
var $Labels = NULL;
var $Icons = NULL;
var $JS = NULL;
var $Types = NULL;
var $Class = "mnu";
var $Classes = NULL;
var $Enabled = NULL;
var $optionOn = -1;
var $id_optionOn = "";
var $ElementClass = NULL;
var $Id = null;
var $Options = null;
var $Labels = null;
var $Icons = null;
var $JS = null;
var $Types = null;
var $Class = "mnu";
var $Classes = null;
var $Enabled = null;
var $optionOn = - 1;
var $id_optionOn = "";
var $ElementClass = null;
/**
* Set menu style
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param $strClass name of style class default value 'mnu'
* @return void
*/
function SetClass( $strClass = "mnu" )
{
$this->Class = "mnu";
}
/**
* Load menu options
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param $strMenuName name of menu
* @return void
*/
function Load( $strMenuName )
{
global $G_TMP_MENU;
$G_TMP_MENU = NULL;
$G_TMP_MENU = new Menu;
$fMenu = G::ExpandPath( "menus" ) . $strMenuName . ".php";
//if the menu file doesn't exists, then try with the plugins folders
if ( !is_file( $fMenu) ) {
$aux = explode ( PATH_SEP, $strMenuName );
if ( count($aux) == 2 ) {
$oPluginRegistry =& PMPluginRegistry::getSingleton();
if ( $oPluginRegistry->isRegisteredFolder($aux[0]) )
$fMenu = PATH_PLUGINS . $aux[0] . PATH_SEP . $aux[1] . ".php";
}
}
if( !is_file( $fMenu ) )
return;
include( $fMenu );
//this line will add options to current menu.
$oPluginRegistry =& PMPluginRegistry::getSingleton();
$oPluginRegistry->getMenus ( $strMenuName );
//?
$c = 0;
for ($i = 0; $i < count ($G_TMP_MENU->Options) ; $i++)
if ($G_TMP_MENU->Enabled[$i] == 1) {
$this->Options[$c] = $G_TMP_MENU->Options[$i];
$this->Labels [$c] = $G_TMP_MENU->Labels[$i];
$this->Icons [$c] = $G_TMP_MENU->Icons[$i];
$this->JS [$c] = $G_TMP_MENU->JS[$i];
$this->Types [$c] = $G_TMP_MENU->Types[$i];
$this->Enabled[$c] = $G_TMP_MENU->Enabled[$i];
$this->Id [$c] = $G_TMP_MENU->Id[$i];
$this->Classes[$c] = $G_TMP_MENU->Classes[$i];
$this->ElementClass[$c] = $G_TMP_MENU->ElementClass[$i];
$c ++;
} else {
if ($i == $this->optionOn) $this->optionOn = -1;
elseif ($i < $this->optionOn) $this->optionOn--;
elseif ($this->optionOn > 0) $this->optionOn--;//added this line
}
$G_TMP_MENU = NULL;
}
/**
* Load menu options
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return int
*/
function OptionCount()
{
$result = 0;
if( is_array( $this->Options ) )
/**
* Set menu style
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param $strClass name of style class default value 'mnu'
* @return void
*/
function SetClass ($strClass = "mnu")
{
$result = count( $this->Options );
$this->Class = "mnu";
}
return $result;
}
/**
* Add an option to menu
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strLabel label to show
* @param string $strURL link
* @param string $strType type, defualt value ='plugins'
* @return void
*/
function AddOption( $strLabel, $strURL, $strType = "plugins" )
{
$pos = $this->OptionCount();
$this->Options[$pos] = $strURL;
$this->Labels[$pos] = $strLabel;
$this->Types[$pos] = $strType;
$this->Enabled[$pos] = 1;
$this->Id[$pos] = $pos;
unset( $pos );
}
/**
* Add an option to menu by id
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strId menu id
* @param string $strLabel label to show
* @param string $strURL link
* @param string $strType type, defualt value ='plugins'
* @return void
*/
function AddIdOption( $strId, $strLabel, $strURL, $strType = "plugins" )
{
$pos = $this->OptionCount();
$this->Options[$pos] = $strURL;
$this->Labels[$pos] = $strLabel;
$this->Types[$pos] = $strType;
$this->Enabled[$pos] = 1;
if (is_array ($strId)) {
$this->Id[$pos] = $strId[0];
$this->Classes[$pos] = $strId[1];
}
else
$this->Id[$pos] = $strId;
unset( $pos );
}
/**
* Add an option to menu
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strURL link
* @param string $strType type, defualt value ='plugins'
* @return void
*/
function AddRawOption( $strURL = "", $strType = "plugins" )
{
$pos = $this->OptionCount();
$this->Options[$pos] = $strURL;
$this->Labels[$pos] = "";
$this->Types[$pos] = $strType;
$this->Enabled[$pos] = 1;
$this->Id[$pos] = $pos;
unset( $pos );
}
/**
* Add an option to menu by id
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strId menu id
* @param string $strLabel label to show
* @param string $strURL link
* @param string $strType type, defualt value ='plugins'
* @param string $elementClass default value =''
* @return void
*/
function AddIdRawOption( $strId, $strURL = "", $label = "", $icon = "",$js = "", $strType = "plugins",$elementClass = '' )
{
$pos = $this->OptionCount();
$this->Options[$pos] = $strURL;
$this->Labels[$pos] = $label;
$this->Icons[$pos] = $icon;
$this->JS[$pos] = $js;
$this->Types[$pos] = $strType;
$this->Enabled[$pos] = 1;
$this->ElementClass[$pos] = $elementClass;
if (is_array ($strId)) {
$this->Id[$pos] = $strId[0];
$this->Classes[$pos] = $strId[1];
}
else
$this->Id[$pos] = $strId;
unset( $pos );
}
/**
* Disable an menu option by menu's position
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $intPos menu option's position
* @return void
*/
function DisableOptionPos( $intPos )
{
$this->Enabled[$intPos] = 0;
}
/**
* Disable an menu's option by id
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $id menu's id
* @return void
*/
function DisableOptionId ( $id )
{
if ( array_search ($id, $this->Id) )
$this->Enabled[ array_search ($id, $this->Id) ] = 0;
}
/**
* Render an menu's option
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $intPos menu option's position
* @return void
*/
function RenderOption( $intPos )
{
if ( $this->Enabled[$intPos] != 1)
return;
$classname = $this->Class . "Link";
if ( $this->Classes[$intPos] != "" ) $classname = $this->Classes[$intPos];
$target = $this->Options[$intPos];
if( $this->Types[$intPos] != "absolute" )
/**
* Load menu options
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param $strMenuName name of menu
* @return void
*/
function Load ($strMenuName)
{
if (defined('ENABLE_ENCRYPT')) {
global $G_TMP_MENU;
$G_TMP_MENU = null;
$G_TMP_MENU = new Menu();
$fMenu = G::ExpandPath( "menus" ) . $strMenuName . ".php";
$target = "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target;
}
else
if (defined('SYS_SYS'))
$target = "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target;
else
$target = "/sys/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target;
//if the menu file doesn't exists, then try with the plugins folders
if (! is_file( $fMenu )) {
$aux = explode( PATH_SEP, $strMenuName );
if (count( $aux ) == 2) {
$oPluginRegistry = & PMPluginRegistry::getSingleton();
if ($oPluginRegistry->isRegisteredFolder( $aux[0] )) {
$fMenu = PATH_PLUGINS . $aux[0] . PATH_SEP . $aux[1] . ".php";
}
}
}
if (! is_file( $fMenu )) {
return;
}
include ($fMenu);
//this line will add options to current menu.
$oPluginRegistry = & PMPluginRegistry::getSingleton();
$oPluginRegistry->getMenus( $strMenuName );
//?
$c = 0;
for ($i = 0; $i < count( $G_TMP_MENU->Options ); $i ++)
if ($G_TMP_MENU->Enabled[$i] == 1) {
$this->Options[$c] = $G_TMP_MENU->Options[$i];
$this->Labels[$c] = $G_TMP_MENU->Labels[$i];
$this->Icons[$c] = $G_TMP_MENU->Icons[$i];
$this->JS[$c] = $G_TMP_MENU->JS[$i];
$this->Types[$c] = $G_TMP_MENU->Types[$i];
$this->Enabled[$c] = $G_TMP_MENU->Enabled[$i];
$this->Id[$c] = $G_TMP_MENU->Id[$i];
$this->Classes[$c] = $G_TMP_MENU->Classes[$i];
$this->ElementClass[$c] = $G_TMP_MENU->ElementClass[$i];
$c ++;
} else {
if ($i == $this->optionOn)
$this->optionOn = - 1;
elseif ($i < $this->optionOn)
$this->optionOn --;
elseif ($this->optionOn > 0)
$this->optionOn --; //added this line
}
$G_TMP_MENU = null;
}
$label = $this->Labels[$intPos];
$result = "<a href=\"$target\"";
$result .= " class=\"$classname\">";
$result .= htmlentities( $label , ENT_NOQUOTES , 'utf-8');
$result .= "</a>";
print( $result );
}
/**
* to make an array for template
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $G_MAIN_MENU
* @param string $classOn
* @param string $classOff
* @param string $G_MENU_SELECTED
* @param string $G_ID_MENU_SELECTED
* @return array
*/
function generateArrayForTemplate($G_MAIN_MENU,$classOn,$classOff,$G_MENU_SELECTED, $G_ID_MENU_SELECTED ) {
$menus = array();
if ($G_MAIN_MENU == null) {
return $menus;
}
$this->Load ($G_MAIN_MENU);
$this->optionOn = $G_MENU_SELECTED;
$this->id_optionOn = $G_ID_MENU_SELECTED;
//$this->Class = $G_MENU_CLASS;
if (is_array($this->Options))
/**
* Load menu options
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return int
*/
function OptionCount ()
{
for ($ncount = 0; $ncount < $this->OptionCount(); $ncount++)
{
$target = $this->Options[$ncount];
//$aux = $this->Icons[$ncount];
$aux = $this->JS[$ncount];
if ($this->Types[$ncount] == 'absolute') {
//$target = G::encryptLink(str_replace('sys' . SYS_TEMP, SYS_TEMP, $this->Options[$ncount]));
$target = $this->Options[$ncount];
$result = 0;
if (is_array( $this->Options )) {
$result = count( $this->Options );
}
if ($this->Types[$ncount] != 'absolute') {
if (defined('SYS_SYS')) {
$target = '/sys' . SYS_TEMP . G::encryptLink('/' . SYS_LANG . '/' . SYS_SKIN . '/' . $this->Options[$ncount]);
}
else {
$target = '/sys/' . G::encryptLink(SYS_LANG . '/' . SYS_SKIN . '/' . $this->Options[$ncount]);
}
}
$label = $this->Labels[$ncount];
if ($this->id_optionOn != '') {
$onMenu = ($this->Id[$ncount] == $this->id_optionOn ? true : false);
}
else {
$onMenu = ($ncount == $this->optionOn ? true : false);
}
$classname = ($onMenu ? $classOn : $classOff);
$imageLeft = ($onMenu ? "<img src=\"/images/bulletSubMenu.jpg\" />" : '');
$onclick = '';
if ($this->JS[$ncount] !== '' ) {
$onclick = " onclick=\"" . $this->JS[$ncount] . "\"";
}
$icon = '';
if ($this->Icons[$ncount] !== '' ) {
$icon = " <a href=\"#\" onclick=\"" . $this->JS[$ncount] . "\" class=\"$classname\">" .
"<img src=\"". $this->Icons[$ncount] . "\" border=\"0\"/></a>";
$icon = $this->Icons[$ncount];
}
if ( $this->Classes[$ncount] != '') {
$classname = $this->Classes[$ncount];
$target = "#";
}
$idName=$this->Id[$ncount];
$elementclass = '';
if($this->ElementClass[$ncount] != ''){
$elementclass = 'class="'.$this->ElementClass[$ncount].'"';
}
$menus[] = array ( 'id' => $ncount, 'target' => $target, 'label' => $label, 'onMenu' => $onMenu, 'classname' => $classname,
'imageLeft' => $imageLeft, 'onclick' => $onclick,
'icon' => $icon, 'aux' => $aux,'idName' => $idName,'elementclass'=>$elementclass);
}
return $result;
}
return $menus;
}
}
/**
* Add an option to menu
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strLabel label to show
* @param string $strURL link
* @param string $strType type, defualt value ='plugins'
* @return void
*/
function AddOption ($strLabel, $strURL, $strType = "plugins")
{
$pos = $this->OptionCount();
$this->Options[$pos] = $strURL;
$this->Labels[$pos] = $strLabel;
$this->Types[$pos] = $strType;
$this->Enabled[$pos] = 1;
$this->Id[$pos] = $pos;
unset( $pos );
}
/**
* Add an option to menu by id
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strId menu id
* @param string $strLabel label to show
* @param string $strURL link
* @param string $strType type, defualt value ='plugins'
* @return void
*/
function AddIdOption ($strId, $strLabel, $strURL, $strType = "plugins")
{
$pos = $this->OptionCount();
$this->Options[$pos] = $strURL;
$this->Labels[$pos] = $strLabel;
$this->Types[$pos] = $strType;
$this->Enabled[$pos] = 1;
if (is_array( $strId )) {
$this->Id[$pos] = $strId[0];
$this->Classes[$pos] = $strId[1];
} else {
$this->Id[$pos] = $strId;
}
unset( $pos );
}
/**
* Add an option to menu
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strURL link
* @param string $strType type, defualt value ='plugins'
* @return void
*/
function AddRawOption ($strURL = "", $strType = "plugins")
{
$pos = $this->OptionCount();
$this->Options[$pos] = $strURL;
$this->Labels[$pos] = "";
$this->Types[$pos] = $strType;
$this->Enabled[$pos] = 1;
$this->Id[$pos] = $pos;
unset( $pos );
}
/**
* Add an option to menu by id
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strId menu id
* @param string $strLabel label to show
* @param string $strURL link
* @param string $strType type, defualt value ='plugins'
* @param string $elementClass default value =''
* @return void
*/
function AddIdRawOption ($strId, $strURL = "", $label = "", $icon = "", $js = "", $strType = "plugins", $elementClass = '')
{
$pos = $this->OptionCount();
$this->Options[$pos] = $strURL;
$this->Labels[$pos] = $label;
$this->Icons[$pos] = $icon;
$this->JS[$pos] = $js;
$this->Types[$pos] = $strType;
$this->Enabled[$pos] = 1;
$this->ElementClass[$pos] = $elementClass;
if (is_array( $strId )) {
$this->Id[$pos] = $strId[0];
$this->Classes[$pos] = $strId[1];
} else {
$this->Id[$pos] = $strId;
}
unset( $pos );
}
/**
* Disable an menu option by menu's position
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $intPos menu option's position
* @return void
*/
function DisableOptionPos ($intPos)
{
$this->Enabled[$intPos] = 0;
}
/**
* Disable an menu's option by id
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $id menu's id
* @return void
*/
function DisableOptionId ($id)
{
if (array_search( $id, $this->Id )) {
$this->Enabled[array_search( $id, $this->Id )] = 0;
}
}
/**
* Render an menu's option
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $intPos menu option's position
* @return void
*/
function RenderOption ($intPos)
{
if ($this->Enabled[$intPos] != 1) {
return;
}
$classname = $this->Class . "Link";
if ($this->Classes[$intPos] != "") {
$classname = $this->Classes[$intPos];
}
$target = $this->Options[$intPos];
if ($this->Types[$intPos] != "absolute") {
if (defined( 'ENABLE_ENCRYPT' )) {
$target = "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target;
} else if (defined( 'SYS_SYS' )) {
$target = "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target;
} else {
$target = "/sys/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target;
}
}
$label = $this->Labels[$intPos];
$result = "<a href=\"$target\"";
$result .= " class=\"$classname\">";
$result .= htmlentities( $label, ENT_NOQUOTES, 'utf-8' );
$result .= "</a>";
print ($result) ;
}
/**
* to make an array for template
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $G_MAIN_MENU
* @param string $classOn
* @param string $classOff
* @param string $G_MENU_SELECTED
* @param string $G_ID_MENU_SELECTED
* @return array
*/
function generateArrayForTemplate ($G_MAIN_MENU, $classOn, $classOff, $G_MENU_SELECTED, $G_ID_MENU_SELECTED)
{
$menus = array ();
if ($G_MAIN_MENU == null) {
return $menus;
}
$this->Load( $G_MAIN_MENU );
$this->optionOn = $G_MENU_SELECTED;
$this->id_optionOn = $G_ID_MENU_SELECTED;
//$this->Class = $G_MENU_CLASS;
if (is_array( $this->Options )) {
for ($ncount = 0; $ncount < $this->OptionCount(); $ncount ++) {
$target = $this->Options[$ncount];
//$aux = $this->Icons[$ncount];
$aux = $this->JS[$ncount];
if ($this->Types[$ncount] == 'absolute') {
//$target = G::encryptLink(str_replace('sys' . SYS_TEMP, SYS_TEMP, $this->Options[$ncount]));
$target = $this->Options[$ncount];
}
if ($this->Types[$ncount] != 'absolute') {
if (defined( 'SYS_SYS' )) {
$target = '/sys' . SYS_TEMP . G::encryptLink( '/' . SYS_LANG . '/' . SYS_SKIN . '/' . $this->Options[$ncount] );
} else {
$target = '/sys/' . G::encryptLink( SYS_LANG . '/' . SYS_SKIN . '/' . $this->Options[$ncount] );
}
}
$label = $this->Labels[$ncount];
if ($this->id_optionOn != '') {
$onMenu = ($this->Id[$ncount] == $this->id_optionOn ? true : false);
} else {
$onMenu = ($ncount == $this->optionOn ? true : false);
}
$classname = ($onMenu ? $classOn : $classOff);
$imageLeft = ($onMenu ? "<img src=\"/images/bulletSubMenu.jpg\" />" : '');
$onclick = '';
if ($this->JS[$ncount] !== '') {
$onclick = " onclick=\"" . $this->JS[$ncount] . "\"";
}
$icon = '';
if ($this->Icons[$ncount] !== '') {
$icon = " <a href=\"#\" onclick=\"" . $this->JS[$ncount] . "\" class=\"$classname\">" . "<img src=\"" . $this->Icons[$ncount] . "\" border=\"0\"/></a>";
$icon = $this->Icons[$ncount];
}
if ($this->Classes[$ncount] != '') {
$classname = $this->Classes[$ncount];
$target = "#";
}
$idName = $this->Id[$ncount];
$elementclass = '';
if ($this->ElementClass[$ncount] != '') {
$elementclass = 'class="' . $this->ElementClass[$ncount] . '"';
}
$menus[] = array ('id' => $ncount,'target' => $target,'label' => $label,'onMenu' => $onMenu,'classname' => $classname,'imageLeft' => $imageLeft,'onclick' => $onclick,'icon' => $icon,'aux' => $aux,'idName' => $idName,'elementclass' => $elementclass
);
}
}
return $menus;
}
}

View File

@@ -1,11 +1,13 @@
<?php
/**
* class.objectTemplate.php
* @package gulliver.system
*
* @package gulliver.system
*
* 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
* published by the Free Software Foundation, either version 3 of the
@@ -13,51 +15,56 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
*
* 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.,
* 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.
*
*
*/
/**
* Class objectTemplate
*
* @package gulliver.system
* @access public
*/
class objectTemplate extends smarty
class objectTemplate extends smarty
{
/**
* Function objectTemplate
* @access public
* @param object $templateFile
* @return void
*/
function objectTemplate( $templateFile )
{
$this->template_dir = PATH_TPL;
$this->compile_dir = PATH_SMARTY_C;
$this->cache_dir = PATH_SMARTY_CACHE;
$this->config_dir = PATH_THIRDPARTY . 'smarty/configs';
$this->caching = false;
$this->templateFile = $templateFile;
}
/**
* Function printObject
* @access public
* @param object $object
* @return string
*/
function printObject($object)
{
$this->assign($object);
return $this->fetch($this->templateFile);
}
}
/**
* Function objectTemplate
*
* @access public
* @param object $templateFile
* @return void
*/
function objectTemplate ($templateFile)
{
$this->template_dir = PATH_TPL;
$this->compile_dir = PATH_SMARTY_C;
$this->cache_dir = PATH_SMARTY_CACHE;
$this->config_dir = PATH_THIRDPARTY . 'smarty/configs';
$this->caching = false;
$this->templateFile = $templateFile;
}
/**
* Function printObject
*
* @access public
* @param object $object
* @return string
*/
function printObject ($object)
{
$this->assign( $object );
return $this->fetch( $this->templateFile );
}
}

View File

@@ -1,12 +1,13 @@
<?php
/**
* class.testTools.php
* @package gulliver.system
*
* @package gulliver.system
*
* 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
* published by the Free Software Foundation, either version 3 of the
@@ -14,173 +15,185 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
*
* 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.,
* 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.
*
*
*/
/**
/**
*
* @package gulliver.system
**/
G::LoadSystem ( 'ymlDomain');
G::LoadSystem ( 'ymlTestCases');
G::LoadSystem ( 'unitTest');
*
*/
G::LoadSystem( 'ymlDomain' );
G::LoadSystem( 'ymlTestCases' );
G::LoadSystem( 'unitTest' );
class testTools
{
/**
* importDB
*
* @param string $host
* @param string $user
* @param string $password
* @param string $database
* @param string $importFile
*
* @return none
*/
function importDB( $host, $user, $password, $database, $importFile )
{
exec("mysql -h " . $host . " --user=" . $user . " --password=" . $password . " $database < $importFile");
}
/**
* importLocalDB
*
* @param string $importFile
*
* @return none
*/
function importLocalDB( $importFile )
{
self::importDB( DB_HOST, DB_USER, DB_PASS, DB_NAME, $importFile );
}
/**
* callMethod
*
* @param string $methodFile
* @param string $GET
* @param string $POST
* @param string $SESSION
*
* @return none
*/
function callMethod( $methodFile, $GET, $POST, $SESSION )
{
//TODO $_SERVER
self::arrayDelete($_GET);
self::arrayDelete($_POST);
self::arrayDelete($_SESSION);
self::arrayAppend($_GET,$GET);
self::arrayAppend($_POST,$POST);
self::arrayAppend($_SESSION,$SESSION);
include( PATH_CORE . 'methods/' . $methodFile );
}
/**
* importDB
*
* @param string $host
* @param string $user
* @param string $password
* @param string $database
* @param string $importFile
*
* @return none
*/
function importDB ($host, $user, $password, $database, $importFile)
{
exec( "mysql -h " . $host . " --user=" . $user . " --password=" . $password . " $database < $importFile" );
}
/**
* arrayAppend
*
* @param string &$to
* @param string $appendFrom
*
* @return boolean true
*/
function arrayAppend( &$to , $appendFrom )
{
foreach($appendFrom as $appendItem) $to[]=$appendItem;
return true;
}
/**
* arrayDelete
*
* @param array &$array
*
* @return boolean true
*/
function arrayDelete( &$array )
{
foreach($array as $key => $value) unset($array[$key]);
return true;
}
/**
* replaceVariables
*
* @param string $Fields
* @param array $ExternalVariables
*
* @return array $Fields
*/
//@@
function replaceVariables( $Fields, $ExternalVariables = array() )
{
//TODO: Verify dependencies between fields
foreach($Fields as $key => $field) {
if (is_string($field)) {
$mergedValues = G::array_merges( $Fields, $ExternalVariables );
$Fields[$key] = G::ReplaceDataField( $field, $mergedValues );
}
/**
* importLocalDB
*
* @param string $importFile
*
* @return none
*/
function importLocalDB ($importFile)
{
self::importDB( DB_HOST, DB_USER, DB_PASS, DB_NAME, $importFile );
}
return $Fields;
}
// EXTRA TOOLS
/**
* findValue
*
* @param string $value
* @param object &$obj
*
* @return (boolean | string) ((true | false) | $value)
*/
function findValue( $value, &$obj )
{
if (is_array($obj)) {
foreach($obj as $key => $val ) {
if ($res=self::findValue( $value , $obj[$key] )) {
if ($res==true) return $key;
else return $key . '.' . $res;
/**
* callMethod
*
* @param string $methodFile
* @param string $GET
* @param string $POST
* @param string $SESSION
*
* @return none
*/
function callMethod ($methodFile, $GET, $POST, $SESSION)
{
//TODO $_SERVER
self::arrayDelete( $_GET );
self::arrayDelete( $_POST );
self::arrayDelete( $_SESSION );
self::arrayAppend( $_GET, $GET );
self::arrayAppend( $_POST, $POST );
self::arrayAppend( $_SESSION, $SESSION );
include (PATH_CORE . 'methods/' . $methodFile);
}
/**
* arrayAppend
*
* @param string &$to
* @param string $appendFrom
*
* @return boolean true
*/
function arrayAppend (&$to, $appendFrom)
{
foreach ($appendFrom as $appendItem) {
$to[] = $appendItem;
}
}
return false;
return true;
}
elseif (is_object($obj)) {
foreach($obj as $key => $val ) {
if ($res=self::findValue( $value , $obj->$key )) {
if ($res==true)
return $key;
else
return $key . '.' . $res;
/**
* arrayDelete
*
* @param array &$array
*
* @return boolean true
*/
function arrayDelete (&$array)
{
foreach ($array as $key => $value) {
unset( $array[$key] );
}
}
return false;
return true;
}
else {
return $obj==$value;
/**
* replaceVariables
*
* @param string $Fields
* @param array $ExternalVariables
*
* @return array $Fields
*/
//@@
function replaceVariables ($Fields, $ExternalVariables = array())
{
//TODO: Verify dependencies between fields
foreach ($Fields as $key => $field) {
if (is_string( $field )) {
$mergedValues = G::array_merges( $Fields, $ExternalVariables );
$Fields[$key] = G::ReplaceDataField( $field, $mergedValues );
}
}
return $Fields;
}
// EXTRA TOOLS
/**
* findValue
*
* @param string $value
* @param object &$obj
*
* @return (boolean | string) ((true | false) | $value)
*/
function findValue ($value, &$obj)
{
if (is_array( $obj )) {
foreach ($obj as $key => $val) {
if ($res = self::findValue( $value, $obj[$key] )) {
if ($res == true) {
return $key;
} else {
return $key . '.' . $res;
}
}
}
return false;
} elseif (is_object( $obj )) {
foreach ($obj as $key => $val) {
if ($res = self::findValue( $value, $obj->$key )) {
if ($res == true) {
return $key;
} else {
return $key . '.' . $res;
}
}
}
return false;
} else {
return $obj == $value;
}
}
}
}
/* Some extra global functions */
/**
* domain
*
* @param string $location *
* @param string $location *
* @return object $result
*/
*/
function domain($location)
function domain ($location)
{
global $testDomain;
$result = $testDomain->get($location);
if (count($result)==0) trigger_error("'$location' is an empty domain.", E_USER_WARNING);
return $result;
global $testDomain;
$result = $testDomain->get( $location );
if (count( $result ) == 0) {
trigger_error( "'$location' is an empty domain.", E_USER_WARNING );
}
return $result;
}

View File

@@ -1,153 +1,160 @@
<?php
/**
* class.tree.php
* @package gulliver.system
*
* @package gulliver.system
*
* 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
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*<2A>
* <EFBFBD>
* This program is distributed in the hope that it will be useful,
* 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.
*
*
* 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.,
* 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.
*
*
*/
/**
/**
*
* @package gulliver.system
*/
G::LoadSystem('objectTemplate');
class Tree extends Xml_Node {
var $template = 'tree.html';
var $nodeType = 'base';
var $nodeClass = 'treeNode';
G::LoadSystem( 'objectTemplate' );
class Tree extends Xml_Node
{
var $template = 'tree.html';
var $nodeType = 'base';
var $nodeClass = 'treeNode';
var $contentClass = 'treeContent';
var $width = '100%';
var $width = '100%';
var $contentWidth = '360';
var $contracted = false;
var $showSign = true;
var $isChild = false;
var $plus = "<span style='position:absolute; width:16px;height:22px;cursor:pointer;'onclick='tree.expand(this.parentNode);'>&nbsp;</span>";
var $minus = "<span style='position:absolute; width:16px;height:22px;cursor:pointer' onclick='tree.contract(this.parentNode);'>&nbsp;</span>";
var $point = "<span style='position:absolute; width:5px;height:10px;cursor:pointer;' onclick='tree.select(this.parentNode);'>&nbsp;</span>";
var $contracted = false;
var $showSign = true;
var $isChild = false;
var $plus = "<span style='position:absolute; width:16px;height:22px;cursor:pointer;'onclick='tree.expand(this.parentNode);'>&nbsp;</span>";
var $minus = "<span style='position:absolute; width:16px;height:22px;cursor:pointer' onclick='tree.contract(this.parentNode);'>&nbsp;</span>";
var $point = "<span style='position:absolute; width:5px;height:10px;cursor:pointer;' onclick='tree.select(this.parentNode);'>&nbsp;</span>";
/**
* Tree
*
* @param array $xmlnode default value NULL
* @param array $xmlnode default value NULL
*
* @return none
*/
function Tree( $xmlnode = NULL )
*/
function Tree ($xmlnode = null)
{
if (!isset($xmlnode))
return;
if (isset($xmlnode->attributes['nodeType']))
$this->nodeType=$xmlnode->attributes['nodeType'];
foreach($xmlnode as $key => $value) {
if ($key==='children') {
foreach( $xmlnode->children as $key => $value ) {
$this->children[ $key ] = new Tree( $value->toTree());
}
} elseif ($key==='attributes') {
foreach( $xmlnode->attributes as $key => $value ) {
$this->{$key} = $value;
}
if (! isset( $xmlnode )) {
return;
}
else {
$this->{$key} = $value;
if (isset( $xmlnode->attributes['nodeType'] )) {
$this->nodeType = $xmlnode->attributes['nodeType'];
}
foreach ($xmlnode as $key => $value) {
if ($key === 'children') {
foreach ($xmlnode->children as $key => $value) {
$this->children[$key] = new Tree( $value->toTree() );
}
} elseif ($key === 'attributes') {
foreach ($xmlnode->attributes as $key => $value) {
$this->{$key} = $value;
}
} else {
$this->{$key} = $value;
}
}
}
}
/**
* &addChild
*
* @param string $name
* @param string $label
* @param array $attributes
* @param string $name
* @param string $label
* @param array $attributes
*
* @return object(Tree) $newNode
*/
*/
function &addChild( $name, $label, $attributes = array() )
function &addChild ($name, $label, $attributes = array())
{
$newNode = new Tree(new Xml_Node($name, 'open', $label, $attributes));
$this->children[] =& $newNode;
return $newNode;
$newNode = new Tree( new Xml_Node( $name, 'open', $label, $attributes ) );
$this->children[] = & $newNode;
return $newNode;
}
/**
* printPlus
*
* @return string '<span>...</span>'
*/
function printPlus()
*/
function printPlus ()
{
$plus = 'none';
$minus = 'none';
$point = 'none';
if ($this->showSign) {
if ((sizeof($this->children)>0) && ($this->contracted)) {
$plus = '';
} elseif ((sizeof($this->children)>0) && (!$this->contracted)) {
$minus = '';
} else {
$point = '';
$plus = 'none';
$minus = 'none';
$point = 'none';
if ($this->showSign) {
if ((sizeof( $this->children ) > 0) && ($this->contracted)) {
$plus = '';
} elseif ((sizeof( $this->children ) > 0) && (! $this->contracted)) {
$minus = '';
} else {
$point = '';
}
}
}
return "<span class='treePlus' name='plus' style='display:$plus;'>{$this->plus}</span>".
"<span class='treeMinus' name='minus' style='display:$minus'>{$this->minus}</span>".
"<span class='treePointer' name='point' style='display:$point'>{$this->point}</span>";
return "<span class='treePlus' name='plus' style='display:$plus;'>{$this->plus}</span>" . "<span class='treeMinus' name='minus' style='display:$minus'>{$this->minus}</span>" . "<span class='treePointer' name='point' style='display:$point'>{$this->point}</span>";
}
/**
* printLabel
*
* @return $this->value
*/
function printLabel()
*/
function printLabel ()
{
return $this->value;
return $this->value;
}
/**
* printContent
*
* @return string $html
*/
function printContent()
*/
function printContent ()
{
$html = '';
$row = 0;
foreach($this->children as $child) {
if ($row)
$child->nodeClass = 'treeNodeAlternate';
$html .= $child->render();
$row = ($row + 1) % 2;
}
return $html;
$html = '';
$row = 0;
foreach ($this->children as $child) {
if ($row) {
$child->nodeClass = 'treeNodeAlternate';
}
$html .= $child->render();
$row = ($row + 1) % 2;
}
return $html;
}
/**
* render
*
* @return $obj->printObject( array( 'node' => &$this ) )
*/
function render() {
$obj = new objectTemplate( $this->template );
return $obj->printObject( array( 'node' => &$this ) );
*/
function render ()
{
$obj = new objectTemplate( $this->template );
return $obj->printObject( array ('node' => &$this
) );
}
}
}

View File

@@ -1,12 +1,14 @@
<?php
/**
* class.unitTest.php
* @package gulliver.system
*
* @package gulliver.system
*
* 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
* published by the Free Software Foundation, either version 3 of the
@@ -14,59 +16,64 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
*
* 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.,
* 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.
*
*
*/
/**
* @package gulliver.system
*/
/**
*
* @package gulliver.system
*/
class unitTest
{
var $dbc;
var $times;
var $yml;
var $domain;
var $testLime;
function unitTest( $ymlFile, &$testLime, &$testDomain )
{
if (!isset($testDomain)) $testDomain = new ymlDomain();
$this->domain =& $testDomain;
$this->testLime =& $testLime;
$this->yml = new ymlTestCases( $ymlFile, $this->domain, $this->testLime );
}
//Load a Test (group of unitary tests) defined in the Yml file.
function load( $testName, $fields=array() )
{
$this->yml->load( $testName, $fields );
}
//Run one single unit test from the loaded Test
function runSingle( $fields=array() )
{
return $this->yml->runSingle( $this, $fields );
}
//Run a group of unit tests from the loaded Test
function runMultiple( $fields=array(), $count = -1, $start=0)
{
return $this->yml->runMultiple( $this, $fields, $count, $start );
}
//Run all the unit tests from the loaded Test
function runAll( $fields=array())
{
return $this->yml->runMultiple( $this, $fields, -1, 0 );
}
//A sample of "Function" to run a unit test.
function sampleTestFunction( $testCase , &$Fields )
{
$result = ($Fields['APP_UID']!='')?"OK":"FALSE";
return $result;
}
var $dbc;
var $times;
var $yml;
var $domain;
var $testLime;
function unitTest ($ymlFile, &$testLime, &$testDomain)
{
if (! isset( $testDomain )) {
$testDomain = new ymlDomain();
}
$this->domain = & $testDomain;
$this->testLime = & $testLime;
$this->yml = new ymlTestCases( $ymlFile, $this->domain, $this->testLime );
}
//Load a Test (group of unitary tests) defined in the Yml file.
function load ($testName, $fields = array())
{
$this->yml->load( $testName, $fields );
}
//Run one single unit test from the loaded Test
function runSingle ($fields = array())
{
return $this->yml->runSingle( $this, $fields );
}
//Run a group of unit tests from the loaded Test
function runMultiple ($fields = array(), $count = -1, $start = 0)
{
return $this->yml->runMultiple( $this, $fields, $count, $start );
}
//Run all the unit tests from the loaded Test
function runAll ($fields = array())
{
return $this->yml->runMultiple( $this, $fields, - 1, 0 );
}
//A sample of "Function" to run a unit test.
function sampleTestFunction ($testCase, &$Fields)
{
$result = ($Fields['APP_UID'] != '') ? "OK" : "FALSE";
return $result;
}
}

View File

@@ -1,11 +1,13 @@
<?php
/**
* class.webResource.php
* @package gulliver.system
*
* @package gulliver.system
*
* 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
* published by the Free Software Foundation, either version 3 of the
@@ -13,15 +15,15 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
*
* 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.,
* 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.
*
*
*/
/* Web Resource (v1.0 PHP4)
* This class permit create PHP/Javascript classes accesible by
@@ -29,103 +31,101 @@
* _Function = don't encode
* JS_function = javascript function.
* @example: h2b2x/territoriesAjax.php
* @dependencies: grest.js *
* @dependencies: grest.js *
*/
/**
/**
*
* @package gulliver.system
*/
class WebResource
{
var $_uri;
var $_uri;
/**
* WebResource
*
* @param string $uri
* @param string $post
*
* @return none
*/
function WebResource($uri, $post)
{
$this->_uri=$uri;
if (isset($post['function'])&&$post['function']!='') {
/*Call a function*/
header('Content-Type: text/json');
//$parameters=G::json_decode((urldecode($post['parameters']))); //for %AC
$parameters=G::json_decode(($post['parameters']));
$paramsRef=array();
foreach($parameters as $key => $value)
{
if (is_string($key)) $paramsRef[]="\$parameters['".addcslashes($key,'\\\'')."']";
else $paramsRef[]='$parameters['.$key.']';
}
$res=eval('return ($this->'.$post['function'].'('.implode(',',$paramsRef).'));');
$res=G::json_encode($res);
print($res);
/**
* WebResource
*
* @param string $uri
* @param string $post
*
* @return none
*/
function WebResource ($uri, $post)
{
$this->_uri = $uri;
if (isset( $post['function'] ) && $post['function'] != '') {
/*Call a function*/
header( 'Content-Type: text/json' );
//$parameters=G::json_decode((urldecode($post['parameters']))); //for %AC
$parameters = G::json_decode( ($post['parameters']) );
$paramsRef = array ();
foreach ($parameters as $key => $value) {
if (is_string( $key )) {
$paramsRef[] = "\$parameters['" . addcslashes( $key, '\\\'' ) . "']";
} else {
$paramsRef[] = '$parameters[' . $key . ']';
}
}
$res = eval( 'return ($this->' . $post['function'] . '(' . implode( ',', $paramsRef ) . '));' );
$res = G::json_encode( $res );
print ($res) ;
} else {
/*Print class definition*/
$this->_encode();
}
}
else {
/*Print class definition*/
$this->_encode();
/**
* _encode
*
* @return none
*/
function _encode ()
{
header( 'Content-Type: text/json' );
$methods = get_class_methods( get_class( $this ) );
print ('{') ;
$first = true;
foreach ($methods as $method) {
//To avoid PHP version incompatibilities, put the $method name in lowercase
$method = strtolower( $method );
if ((substr( $method, 0, 1 ) === '_') || (strcasecmp( $method, 'WebResource' ) == 0) || (strcasecmp( $method, get_class( $this ) ) == 0)) {
} elseif (strcasecmp( substr( $method, 0, 3 ), 'js_' ) == 0) {
if (! $first) {
print (',') ;
}
$this->{$method}();
$first = false;
} else {
if (! $first) {
print (',') ;
}
print ($method . ':function(){return __wrCall("' . addslashes( $this->_uri ) . '","' . $method . '",arguments);}') ;
$first = false;
}
}
print ('}') ;
}
}
/**
* _encode
*
* @return none
*/
function _encode()
{
header('Content-Type: text/json');
$methods=get_class_methods(get_class($this));
print('{');
$first = true;
foreach($methods as $method) {
//To avoid PHP version incompatibilities, put the $method name in lowercase
$method=strtolower($method);
if ((substr($method,0,1)==='_')||
(strcasecmp($method,'WebResource')==0)||
(strcasecmp($method,get_class($this))==0)
)
{
}
elseif (strcasecmp(substr($method,0,3),'js_')==0)
{
if (!$first) print(',');
$this->{$method}();
$first=false;
}
else
{
if (!$first) print(',');
print(
$method.
':function(){return __wrCall("'.
addslashes($this->_uri).
'","'.$method.'",arguments);}'
);
$first=false;
}
}
print('}');
}
}
/* end class WebResource */
if (!function_exists('json_encode')) {
G::LoadThirdParty('pear/json','class.json');
function json_encode(&$value) {
$json= new Services_JSON;
return $json->encode($value);
}
if (! function_exists( 'json_encode' )) {
G::LoadThirdParty( 'pear/json', 'class.json' );
function json_encode (&$value)
{
$json = new Services_JSON();
return $json->encode( $value );
}
}
if (!function_exists('json_decode')) {
G::LoadThirdParty('pear/json','class.json');
function json_decode(&$value) {
$json= new Services_JSON;
return $json->decode($value);
}
if (! function_exists( 'json_decode' )) {
G::LoadThirdParty( 'pear/json', 'class.json' );
function json_decode (&$value)
{
$json = new Services_JSON();
return $json->decode( $value );
}
}

View File

@@ -1,7 +1,9 @@
<?php
/**
* class.xmlDocument.php
* @package gulliver.system
*
* @package gulliver.system
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc.
@@ -13,11 +15,11 @@
*
* This program is distributed in the hope that it will be useful,
* 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.
*
* 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.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
@@ -25,340 +27,355 @@
*/
/**
* Class Xml_Node
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @package gulliver.system
* @access public
*/
class Xml_Node
{
var $name = '';
var $type = '';
var $value = ''; //maybe not necesary
var $attributes = array();
var $children = array();
/**
* Function Xml_Node
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @parameter string name
* @parameter string type
* @parameter string value
* @parameter string attributes
* @return string
*/
function Xml_Node($name, $type, $value, $attributes = array() )
{
$this->name = $name;
$this->type = $type;
$this->value = $value;
$this->attributes = $attributes;
}
/**
* Function addAttribute
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @parameter string name
* @parameter string value
* @return string
*/
function addAttribute( $name, $value )
{
$this->attributes[$name] = $value;
return true;
}
/**
* Function addChildNode
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @parameter string childNode
* @return string
*/
function addChildNode( $childNode )
{
if (is_object($childNode) && strcasecmp( get_class($childNode), 'Xml_Node' ) == 0 ) {
$this->type = 'open';
$childNode->parent = &$this;
$this->children[] = &$childNode;
return true;
}
else {
return false;
}
}
/**
* Function toTree
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function toTree()
{
$arr = new Xml_Node( $this->name, $this->type, $this->value, $this->attributes );
unset( $arr->parent );
foreach($this->children as $k => $v) {
unset($v->parent);
$arr->children[$k]=$v->toTree();
}
return $arr;
}
function toArray( $obj = NULL ) {
$arr = array();
if ( !isset($obj) ) $obj = $this->toTree();
foreach($obj as $att => $val ) {
if (is_array($val) || is_object($val) ) {
$arr[$att] = Xml_Node::toArray($val);
} else {
$arr[$att] = $val;
}
}
return $arr;
}
/**
* Function &findNode
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @parameter string xpath
* @return string
*/
function &findNode( $xpath )
{
$n = NULL;
$p = explode('/', $xpath);
if ( $p[0] === '') {
return $this;
}
elseif ( substr($p[0],0 , 1) === '@') {
$p[0] = substr($p[0], 1 );
if ( isset($this->attributes[$p[0]])) return $this->attributes[$p[0]];
}
elseif ($p[0] === '..' ) {
array_shift($p);
$n = & $this->parent->findNode ( implode('/',$p) );
if (isset($n) ) return $n;
}
else {
foreach( $this->children as $k => $v) {
if ( ($v->type!=='cdata')&&($v->name===$p[0])) {
if (sizeof($p)>1) {
array_shift($p);
$n=& $this->children[$k]->findNode(implode('/',$p));
if (isset($n)) return $n;
}
else {
return $this->children[$k];
}
}
}
}
return $n;
}
/**
* Function getXML
* Returns a string of the node in XML notation.
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @parameter string xpath
* @return string
*/
function getXML()
{
switch($this->type)
var $name = '';
var $type = '';
var $value = ''; //maybe not necesary
var $attributes = array ();
var $children = array ();
/**
* Function Xml_Node
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string name
* @param eter string type
* @param eter string value
* @param eter string attributes
* @return string
*/
function Xml_Node ($name, $type, $value, $attributes = array())
{
case 'open':
$xml = '<'.$this->name;
foreach( $this->attributes as $attib => $value ) {
$value = htmlspecialchars( $value, ENT_QUOTES, 'utf-8' );
/*if(($attib == "hint")||($attib == "defaultvalue")){
$value = str_replace("&", "&amp;", $value);
$value = str_replace("'", "\'", $value);
$value = str_replace(">", "&gt;", $value);
$value = str_replace("<", "&lt;", $value);
}
//else{
$value = htmlentities( $value, ENT_QUOTES, 'utf-8' );
//}
*/
$xml .= ' ' . $attib . '="' . $value . '"';
//check if the htmlentities result value is the euro symbol and
//replaced by their numeric character representation
if (strpos($xml, '&euro;') !== false) {
$xml = str_replace('&euro;', '&#8364;', $xml);
}
}
$xml .= '>'.$this->getCDATAValue();
foreach( $this->children as $child )
$xml .= $child->getXML();
$xml .= '</'.$this->name.'>';
break;
case 'close':
$xml = '</'.$this->name.'>';
break;
case 'cdata':
$xml = $this->getCDATAValue();
break;
case 'complete':
$xml = '<'.$this->name;
foreach( $this->attributes as $attib => $value ) {
$xml .= ' ' . $attib . '="' . htmlentities($value, ENT_QUOTES, 'utf-8' ) . '"';
//check if the htmlentities result value is the euro symbol and
//replaced by their numeric character representation
if (strpos($xml, '&euro;') !== false) {
$xml = str_replace('&euro;', '&#8364;', $xml);
}
}
if ($this->value!=='') {
$xml .= '>'.$this->getCDATAValue();
$xml .= '</'.$this->name.'>';
} else {
$xml .= '/>';
}
break;
$this->name = $name;
$this->type = $type;
$this->value = $value;
$this->attributes = $attributes;
}
/**
* Function addAttribute
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string name
* @param eter string value
* @return string
*/
function addAttribute ($name, $value)
{
$this->attributes[$name] = $value;
return true;
}
/**
* Function addChildNode
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string childNode
* @return string
*/
function addChildNode ($childNode)
{
if (is_object( $childNode ) && strcasecmp( get_class( $childNode ), 'Xml_Node' ) == 0) {
$this->type = 'open';
$childNode->parent = &$this;
$this->children[] = &$childNode;
return true;
} else {
return false;
}
}
/**
* Function toTree
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function toTree ()
{
$arr = new Xml_Node( $this->name, $this->type, $this->value, $this->attributes );
unset( $arr->parent );
foreach ($this->children as $k => $v) {
unset( $v->parent );
$arr->children[$k] = $v->toTree();
}
return $arr;
}
function toArray ($obj = null)
{
$arr = array ();
if (! isset( $obj )) {
$obj = $this->toTree();
}
foreach ($obj as $att => $val) {
if (is_array( $val ) || is_object( $val )) {
$arr[$att] = Xml_Node::toArray( $val );
} else {
$arr[$att] = $val;
}
}
return $arr;
}
/**
* Function &findNode
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string xpath
* @return string
*/
function &findNode ($xpath)
{
$n = null;
$p = explode( '/', $xpath );
if ($p[0] === '') {
return $this;
} elseif (substr( $p[0], 0, 1 ) === '@') {
$p[0] = substr( $p[0], 1 );
if (isset( $this->attributes[$p[0]] )) {
return $this->attributes[$p[0]];
}
} elseif ($p[0] === '..') {
array_shift( $p );
$n = & $this->parent->findNode( implode( '/', $p ) );
if (isset( $n )) {
return $n;
}
} else {
foreach ($this->children as $k => $v) {
if (($v->type !== 'cdata') && ($v->name === $p[0])) {
if (sizeof( $p ) > 1) {
array_shift( $p );
$n = & $this->children[$k]->findNode( implode( '/', $p ) );
if (isset( $n )) {
return $n;
}
} else {
return $this->children[$k];
}
}
}
}
return $n;
}
/**
* Function getXML
* Returns a string of the node in XML notation.
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string xpath
* @return string
*/
function getXML ()
{
switch ($this->type) {
case 'open':
$xml = '<' . $this->name;
foreach ($this->attributes as $attib => $value) {
$value = htmlspecialchars( $value, ENT_QUOTES, 'utf-8' );
/*if(($attib == "hint")||($attib == "defaultvalue")){
$value = str_replace("&", "&amp;", $value);
$value = str_replace("'", "\'", $value);
$value = str_replace(">", "&gt;", $value);
$value = str_replace("<", "&lt;", $value);
}
//else{
$value = htmlentities( $value, ENT_QUOTES, 'utf-8' );
//}
*/
$xml .= ' ' . $attib . '="' . $value . '"';
//check if the htmlentities result value is the euro symbol and
//replaced by their numeric character representation
if (strpos( $xml, '&euro;' ) !== false) {
$xml = str_replace( '&euro;', '&#8364;', $xml );
}
}
$xml .= '>' . $this->getCDATAValue();
foreach ($this->children as $child) {
$xml .= $child->getXML();
}
$xml .= '</' . $this->name . '>';
break;
case 'close':
$xml = '</' . $this->name . '>';
break;
case 'cdata':
$xml = $this->getCDATAValue();
break;
case 'complete':
$xml = '<' . $this->name;
foreach ($this->attributes as $attib => $value) {
$xml .= ' ' . $attib . '="' . htmlentities( $value, ENT_QUOTES, 'utf-8' ) . '"';
//check if the htmlentities result value is the euro symbol and
//replaced by their numeric character representation
if (strpos( $xml, '&euro;' ) !== false) {
$xml = str_replace( '&euro;', '&#8364;', $xml );
}
}
if ($this->value !== '') {
$xml .= '>' . $this->getCDATAValue();
$xml .= '</' . $this->name . '>';
} else {
$xml .= '/>';
}
break;
}
return $xml;
}
function getCDATAValue ()
{
$cdata = htmlentities( $this->value, ENT_QUOTES, 'utf-8' );
if ($this->value === $cdata) {
return $this->value;
} else {
return '<![CDATA[' . $this->value . ']]>';
}
}
return $xml;
}
function getCDATAValue()
{
$cdata = htmlentities( $this->value, ENT_QUOTES, 'utf-8' );
if ($this->value === $cdata)
return $this->value;
else
return '<![CDATA[' . $this->value . ']]>';
}
}
/**
* Class Xml_document
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @package gulliver.system
* @access public
*/
class Xml_document extends Xml_Node
{
var $currentNode;
/**
* Function Xml_document
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function Xml_document()
{
$this->currentNode = &$this;
}
/**
* Function parseXmlFile
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @parameter string filename
* @parameter string content
* @return string
*/
function parseXmlFile($filename,$content="")
{ //$content is a new variable, if it has any value then use it instead of the file content.
if($content==""){
if ( !file_exists ($filename) ) {
throw ( new Exception ( "failed to open Xmlform File : No such file or directory in $filename " ) );
}
$data = implode( '', file( $filename) );
}else{
$data = $content;
}
$parser = xml_parser_create( 'utf-8' );
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
xml_parse_into_struct($parser, $data, $values, $tags);
if (xml_get_error_code($parser)!== 0) {
$msg = sprintf( "XML error in <b>%s</b>: %s at line %d", $filename , xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser));
trigger_error ( $msg );
}
xml_parser_free( $parser );
var $currentNode;
$this->name = '#document';
$this->type = 'open';
$this->currentNode = &$this;
$m = &$this;
foreach($values as $k => $v)
/**
* Function Xml_document
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
function Xml_document ()
{
switch ($v['type'])
{
case 'open':
$this->currentNode->addChildNode ( new Xml_Node ($v['tag'],
$v['type'], isset($v['value'])?$v['value'] : '',
isset($v['attributes']) ? $v['attributes']:array()));
$this->currentNode = &$this->findNode($v['tag']);
break;
case 'close':
$this->currentNode=& $this->findNode('..');
break;
case 'cdata':
$this->currentNode->addChildNode(new Xml_Node('',
$v['type'], isset($v['value'])?$v['value']:''));
break;
case 'complete':
$this->currentNode->addChildNode( new Xml_Node($v['tag'],
$v['type'], isset($v['value'])?$v['value']:'',
isset($v['attributes'])?$v['attributes']:array()));
break;
}
$this->currentNode = &$this;
}
return true;
}
/**
* Function &findNode
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @parameter string xpath
* @return string
*/
function &findNode( $xpath )
{
if ( substr( $xpath, 0, 1 ) == '/' ) {
return parent::findNode( substr( $xpath,1) );
}
else {
if ( isset($this->currentNode) ){
if ( $this->currentNode->name === $this->name)
return parent::findNode( $xpath );
else
return $this->currentNode->findNode($xpath);
}
else {
return $null;
}
}
} //function findNode
/**
* Function getXML
*
* @access public
* @return string $xml
*/
function getXML()
{
$xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$xml .= $this->children[0]->getXML();
return $xml;
}
/**
* Function save
*
* @access public
* @return void
*/
function save ( $filename )
{
$xml = $this->getXML();
$fp = fopen( $filename , 'w' );
fwrite( $fp , $xml );
fclose( $fp );/**/
}
/**
* Function parseXmlFile
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string filename
* @param eter string content
* @return string
*/
function parseXmlFile ($filename, $content = "")
{ //$content is a new variable, if it has any value then use it instead of the file content.
if ($content == "") {
if (! file_exists( $filename )) {
throw (new Exception( "failed to open Xmlform File : No such file or directory in $filename " ));
}
$data = implode( '', file( $filename ) );
} else {
$data = $content;
}
$parser = xml_parser_create( 'utf-8' );
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 0 );
xml_parse_into_struct( $parser, $data, $values, $tags );
if (xml_get_error_code( $parser ) !== 0) {
$msg = sprintf( "XML error in <b>%s</b>: %s at line %d", $filename, xml_error_string( xml_get_error_code( $parser ) ), xml_get_current_line_number( $parser ) );
trigger_error( $msg );
}
xml_parser_free( $parser );
$this->name = '#document';
$this->type = 'open';
$this->currentNode = &$this;
$m = &$this;
foreach ($values as $k => $v) {
switch ($v['type']) {
case 'open':
$this->currentNode->addChildNode( new Xml_Node( $v['tag'], $v['type'], isset( $v['value'] ) ? $v['value'] : '', isset( $v['attributes'] ) ? $v['attributes'] : array () ) );
$this->currentNode = &$this->findNode( $v['tag'] );
break;
case 'close':
$this->currentNode = & $this->findNode( '..' );
break;
case 'cdata':
$this->currentNode->addChildNode( new Xml_Node( '', $v['type'], isset( $v['value'] ) ? $v['value'] : '' ) );
break;
case 'complete':
$this->currentNode->addChildNode( new Xml_Node( $v['tag'], $v['type'], isset( $v['value'] ) ? $v['value'] : '', isset( $v['attributes'] ) ? $v['attributes'] : array () ) );
break;
}
}
return true;
}
/**
* Function &findNode
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string xpath
* @return string
*/
function &findNode ($xpath)
{
if (substr( $xpath, 0, 1 ) == '/') {
return parent::findNode( substr( $xpath, 1 ) );
} else {
if (isset( $this->currentNode )) {
if ($this->currentNode->name === $this->name) {
return parent::findNode( $xpath );
} else {
return $this->currentNode->findNode( $xpath );
}
} else {
return $null;
}
}
} //function findNode
/**
* Function getXML
*
* @access public
* @return string $xml
*/
function getXML ()
{
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$xml .= $this->children[0]->getXML();
return $xml;
}
/**
* Function save
*
* @access public
* @return void
*/
function save ($filename)
{
$xml = $this->getXML();
$fp = fopen( $filename, 'w' );
fwrite( $fp, $xml );
fclose( $fp );
}
}

View File

@@ -1,157 +1,161 @@
<?php
/**
* class.xmlformExtension.php
* @package gulliver.system
*
* 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
* 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
* 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/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
/**
* @package gulliver.system
*/
class XmlForm_Field_Label extends XmlForm_Field
{
var $withoutValue = true;
var $align = 'left';
}
/**
* Special class for pagedTable
* condition: PHP expression whose result defines whether to "mark"
* the following columns (that is if true)
* @package gulliver.system
*/
class XmlForm_Field_cellMark extends XmlForm_Field
{
/* Defines the style of the next tds
<?php
/**
* class.xmlformExtension.php
*
* @package gulliver.system
*
* 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
* 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
* 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/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
/**
*
* @package gulliver.system
*/
class XmlForm_Field_Label extends XmlForm_Field
{
var $withoutValue = true;
var $align = 'left';
}
/**
* Special class for pagedTable
* condition: PHP expression whose result defines whether to "mark"
* the following columns (that is if true)
*
* @package gulliver.system
*/
class XmlForm_Field_cellMark extends XmlForm_Field
{
/* Defines the style of the next tds
of the pagedTable.
*/
var $showInTable = "0";
var $style = "";
var $styleAlt = "";
var $className = "";
var $classNameAlt = "";
var $condition = 'false';
/**
* tdStyle
*
* @param string $values
* @param string $owner
*
* @return string $value
*/
function tdStyle( $values , $owner )
{
$value = G::replaceDataField( $this->condition, $owner->values );
$value = @eval('return ('.$value.');');
$row=$values['row__'];
$style=((($row % 2)==0) && ($this->styleAlt!=0)) ?
$this->styleAlt : $this->style;
return ($value)?$style:'';
}
/**
* tdClass
*
* @param string $values
* @param string $owner
*
* @return $value
*/
function tdClass( $values, $owner )
{
$value = G::replaceDataField( $this->condition, $owner->values );
$value = @eval('return ('.$value.');');
$row=$values['row__'];
$style=(($row % 2)==0) ?
$this->classNameAlt : $this->className;
return ($value)?$style:'';
}
*/
var $showInTable = "0";
var $style = "";
var $styleAlt = "";
var $className = "";
var $classNameAlt = "";
var $condition = 'false';
/**
* tdStyle
*
* @param string $values
* @param string $owner
*
* @return string $value
*/
function tdStyle ($values, $owner)
{
$value = G::replaceDataField( $this->condition, $owner->values );
$value = @eval( 'return (' . $value . ');' );
$row = $values['row__'];
$style = ((($row % 2) == 0) && ($this->styleAlt != 0)) ? $this->styleAlt : $this->style;
return ($value) ? $style : '';
}
/**
* tdClass
*
* @param string $values
* @param string $owner
*
* @return $value
*/
function tdClass ($values, $owner)
{
$value = G::replaceDataField( $this->condition, $owner->values );
$value = @eval( 'return (' . $value . ');' );
$row = $values['row__'];
$style = (($row % 2) == 0) ? $this->classNameAlt : $this->className;
return ($value) ? $style : '';
}
}
/**
* XmlForm_Field_DVEditor
*
* extends XmlForm_Field
*
* @package gulliver.system
*
*/
class XmlForm_Field_DVEditor extends XmlForm_Field
{
var $toolbarSet = 'toolbar2lines.html';
var $width = '90%';
var $height = '200';
/**
* render
*
* @param string $value
* @param string $owner default value NULL
*
* @return string '<div> ... </div>'
*/
function render ($value, $owner = null)
{
return '<div style="width:' . htmlentities( $this->width, ENT_QUOTES, 'utf-8' ) . ';height:' . htmlentities( $this->height, ENT_QUOTES, 'utf-8' ) . '"><input id="form[' . $this->name . ']" name="form[' . $this->name . ']" type="hidden" value="' . htmlentities( $value, ENT_QUOTES, 'UTF-8' ) . '"/></div>';
}
/**
* attachEvents
*
* @param string $element
*
* @return $html
*/
function attachEvents ($element)
{
$html = 'var _editor' . $this->name . '=new DVEditor(getField("form[' . $this->name . ']").parentNode,getField("form[' . $this->name . ']").value)';
return $html;
}
}
/**
* Special field: Add a search box (fast search) for the related pagedTable
*
* The PAGED_TABLE_ID reserved field must be defined in the xml.
* Use PAGED_TABLE_FAST_SEARCH reserved field, it contains the saved value for each table.
* example:
* Ex1.
* <PAGED_TABLE_ID type="private"/>
* <PAGED_TABLE_FAST_SEARCH type="FastSearch">
* <en>Search</en>
* </PAGED_TABLE_FAST_SEARCH>
* Ex2 (Using type="text").
* <PAGED_TABLE_ID type="private"/>
* <PAGED_TABLE_FAST_SEARCH type="text" colAlign="right" colWidth="180" onkeypress="if (event.keyCode===13)@#PAGED_TABLE_ID.doFastSearch(this.value);if (event.keyCode===13)return false;">
* <en>Search</en>
* </PAGED_TABLE_FAST_SEARCH>
*
* @package gulliver.system
*/
class XmlForm_Field_FastSearch extends XmlForm_Field_Text
{
var $onkeypress = "if (event.keyCode===13)@#PAGED_TABLE_ID.doFastSearch(this.value);if (event.keyCode===13)return false;";
var $colAlign = "right";
var $colWidth = "180";
var $label = "@G::LoadTranslation(ID_SEARCH)";
}
/**
* XmlForm_Field_DVEditor
*
* extends XmlForm_Field
* @package gulliver.system
*
*/
class XmlForm_Field_DVEditor extends XmlForm_Field
{
var $toolbarSet = 'toolbar2lines.html';
var $width = '90%';
var $height = '200' ;
/**
* render
*
* @param string $value
* @param string $owner default value NULL
*
* @return string '<div> ... </div>'
*/
function render( $value, $owner = NULL )
{
return '<div style="width:'.htmlentities($this->width,ENT_QUOTES,'utf-8').';height:'.htmlentities($this->height,ENT_QUOTES,'utf-8').'"><input id="form['.$this->name.']" name="form['.$this->name.']" type="hidden" value="'.htmlentities($value,ENT_QUOTES,'UTF-8').'"/></div>';
}
/**
* attachEvents
*
* @param string $element
*
* @return $html
*/
function attachEvents($element)
{
$html = 'var _editor'.$this->name.'=new DVEditor(getField("form['.$this->name.']").parentNode,getField("form['.$this->name.']").value)';
return $html;
}
}
/**
* Special field: Add a search box (fast search) for the related pagedTable
*
* The PAGED_TABLE_ID reserved field must be defined in the xml.
* Use PAGED_TABLE_FAST_SEARCH reserved field, it contains the saved value for each table.
* example:
* Ex1.
* <PAGED_TABLE_ID type="private"/>
* <PAGED_TABLE_FAST_SEARCH type="FastSearch">
* <en>Search</en>
* </PAGED_TABLE_FAST_SEARCH>
* Ex2 (Using type="text").
* <PAGED_TABLE_ID type="private"/>
* <PAGED_TABLE_FAST_SEARCH type="text" colAlign="right" colWidth="180" onkeypress="if (event.keyCode===13)@#PAGED_TABLE_ID.doFastSearch(this.value);if (event.keyCode===13)return false;">
* <en>Search</en>
* </PAGED_TABLE_FAST_SEARCH>
* @package gulliver.system
*/
class XmlForm_Field_FastSearch extends XmlForm_Field_Text
{
var $onkeypress = "if (event.keyCode===13)@#PAGED_TABLE_ID.doFastSearch(this.value);if (event.keyCode===13)return false;";
var $colAlign = "right";
var $colWidth = "180";
var $label = "@G::LoadTranslation(ID_SEARCH)";
}