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

View File

@@ -1,11 +1,13 @@
<?php <?php
/** /**
* class.dbrecordset.php * class.dbrecordset.php
* @package gulliver.system *
* * @package gulliver.system
*
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
* DBRecordset class definition * 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 * 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 * @package gulliver.system
* *
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
@@ -34,118 +37,116 @@
*/ */
class DBRecordSet class DBRecordSet
{ {
var $result = null; var $result = null;
/** /**
* Starts connection to Database using default values * Starts connection to Database using default values
* *
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public * @access public
* @param string $intResult Database recordset default value = false * @param string $intResult Database recordset default value = false
* @return void * @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
*/ */
/*if (is_array ($res) ) function DBRecordSet ($intResult = null)
foreach ($res as $key => $val) {
$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*/ $res[$key] = stripslashes ($val); remove the slashes*/
return $res; return $res;
} }
/** /**
* Function ReadAbsolute * Function ReadAbsolute
* @author David S. Callizaya S. <davidsantos@colosa.com> *
* @access public * @author David S. Callizaya S. <davidsantos@colosa.com>
* @return string * @access public
*/ * @return string
function ReadAbsolute() */
{ function ReadAbsolute ()
$res = $this->result->fetchRow(DB_FETCHMODE_ORDERED); {
//for Pgsql databases, $res = $this->result->fetchRow( DB_FETCHMODE_ORDERED );
//if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); } //for Pgsql databases,
return $res; //if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); }
} return $res;
} }
}

View File

@@ -1,11 +1,13 @@
<?php <?php
/** /**
* class.dbsession.php * class.dbsession.php
* @package gulliver.system *
* * @package gulliver.system
*
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
* DBSession class definition * DBSession class definition
* It is useful to stablish a database connection using an specific database * It is useful to stablish a database connection using an specific database
*
* @package gulliver.system * @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team. * @copyright (C) 2002 by Colosa Development Team.
@@ -34,146 +37,151 @@
*/ */
class DBSession class DBSession
{ {
var $dbc = NULL; var $dbc = null;
var $dbname = ''; var $dbname = '';
var $result = false; var $result = false;
/** /**
* Starts a session using a connection with an specific database * Starts a session using a connection with an specific database
* @author Fernando Ontiveros Lira <fernando@colosa.com> *
* * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public *
* @param object $objConnection * @access public
* @param string $strDBName * @param object $objConnection
* @return void * @param string $strDBName
* * @return void
*/ *
function DBSession( $objConnection = NULL, $strDBName = '' ) */
{ 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 )
{ {
$this->Free(); if ($strDBName != '') {
$this->dbc = $objConnection; $strDBName = $objConnection->db->_db;
$this->dbname = $strDBName; }
$this->setTo( $objConnection, $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 ( !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 ) { //enable utf8 in mysql databases
print( $strQuery . "<br>\n" ); 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 ); /**
* UseDB stablish a database for the connection
if (DB::isError ($this->result)) { *
$this->dbc->ShowLogError( $this->result->getMessage() , $this->result->userinfo, $error); * @author Fernando Ontiveros Lira <fernando@colosa.com>
die; *
* @access public
* @param string $strDBName
* @return void
*
*/
function UseDB ($strDBName = DB_NAME)
{
$this->dbname = $strDBName;
} }
return;
} /**
*/ * Function Execute, to execute a query and send back the recordset.
*
/** * @access public
* Function Free * @param eter string strQuery
* @access public * @param eter string debug
* @parameter string debug * @param eter string error
* @return string * @return string
*/ */
function Free( $debug = false ) function Execute ($strQuery = '', $debug = false, $errorLevel = null)
{ {
if ( is_resource($this->result) ) //BUG::traceRoute();
$this->result->Free(); if ($this->dbc == null) {
return; $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 <?php
/** /**
* class.dbtable.php * class.dbtable.php
*
* @package gulliver.system * @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -13,11 +15,11 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
@@ -29,6 +31,7 @@
* This class provides acces to a generalized table * 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 * 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. * for the table should be also provided in order to provide the class a way to generate an UPDATE query properly.
*
* @package gulliver.system * @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team. * @copyright (C) 2002 by Colosa Development Team.
@@ -36,393 +39,391 @@
*/ */
class DBTable class DBTable
{ {
var $_dbc; var $_dbc;
var $_dbses; var $_dbses;
var $_dset; var $_dset;
var $table_name; var $table_name;
var $table_keys; var $table_keys;
var $Fields = null; var $Fields = null;
var $is_new; var $is_new;
var $errorLevel; var $errorLevel;
var $debug = false; var $debug = false;
/** /**
* Initiate a database conecction using default values * Initiate a database conecction using default values
* *
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public * @access public
* @param object $objConnection conecction string * @param object $objConnection conecction string
* @return void * @return void
*/ */
function dBTable( $objConnection = NULL, $strTable = "", $arrKeys = array( 'UID' ) ) 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 )
{ {
$this->_dbses = new DBSession( $this->_dbc ); $this->_dbc = null;
$this->_dbses->UseDB( DB_NAME ); $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 * Initiate a database conecction using default values
* *
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public * @access public
* @return void * @param object $objDBConnection conecction string
*/ * @param string $strTable Table name defaultvalue=''
function loadEmpty() * @param array $arrKeys table keys defaultvalue=UID
{ * @return void
$stQry = "DESCRIBE `" . $this->table_name. "`"; */
$dset = $this->_dbses->execute( $stQry ); function setTo ($objDBConnection, $strTable = "", $arrKeys = array( 'UID' ))
//$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];
if( $data['Key'] == 'PRI' ) $this->_dbc = $objDBConnection;
{ if ($this->_dbc != null && strcasecmp( get_class( $objDBConnection ), 'dbconnection' ) == 0) {
if( is_array($this->table_keys) ) $this->_dbses = new DBSession( $this->_dbc );
{ $this->_dbses->UseDB( DB_NAME );
$this->table_keys[count( $this->table_keys ) - 1] = $fname; } 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->is_new = true;
{ $this->Fields = null;
$this->table_keys[0] = $fname; $this->table_name = $strTable;
if (is_array( $arrKeys )) {
$this->table_keys = $arrKeys;
} else {
$this->table_keys = array (0 => $arrKeys
);
} }
} $this->errorLevel = $this->_dbc->errorLevel;
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;
} }
if( $this->_dset->Count() > 0 ){ /**
$this->Fields = $this->_dset->Read(); * Loads full description of a referenced table in Fields
$this->is_new = false; *
} * @author Fernando Ontiveros Lira <fernando@colosa.com>
else * @access public
* @return void
*/
function loadEmpty ()
{ {
$this->Fields = NULL; $stQry = "DESCRIBE `" . $this->table_name . "`";
$this->is_new = true; $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; if ($data['Key'] == 'PRI') {
} if (is_array( $this->table_keys )) {
$this->table_keys[count( $this->table_keys ) - 1] = $fname;
/** } else {
* Return all fields on the referenced table $this->table_keys[0] = $fname;
* }
* @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 ) . "'";
} }
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 ); * Return specified field on the referenced table
if ( $stWhere == '' ) { *
$dberror = PEAR::raiseError(null, G_ERROR_WARNING_MESSAGE, null, 'null', * @author Fernando Ontiveros Lira <fernando@colosa.com>
"You tried to call delete method without WHERE clause, if you want to delete all records use dbsession", * @access public
'G_Error', true); * @param string $strWhere string which contains conditions
DBconnection::logError( $dberror, $this->errorLevel ); * @return strint
return $dberror; */
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 all fields on the referenced table
return $result; *
} * @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 * Function nextvalPGSql
* *
* Move to next record in a recordset, this is useful where the load method have a recordset with many rows * @author David S. Callizaya S. <davidsantos@colosa.com>
* * @access public
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @param eter string seq
* @access public * @return string
* @return boolean */
*/ function nextvalPGSql ($seq)
function next() {
{ $stQry = " Select NEXTVAL( '$seq' ) ";
$this->Fields = $this->_dset->read (); $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 <?php
/** /**
* HttpProxyController * HttpProxyController
*
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com> * @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
* @package gulliver.system * @package gulliver.system
* @access private * @access private
*/ */
class HttpProxyController { class HttpProxyController
{
/** /**
*
* @var array - private array to store proxy data * @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__; private $__request__;
public $jsonResponse = true; public $jsonResponse = true;
private $sendResponse = true; private $sendResponse = true;
/** /**
* Magic setter method * Magic setter method
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
*/ */
public function __set($name, $value) { public function __set ($name, $value)
{
//echo "Setting '$name' to '$value'\n"; //echo "Setting '$name' to '$value'\n";
$this->__data__[$name] = $value; $this->__data__[$name] = $value;
} }
/** /**
* Magic getter method * Magic getter method
* *
* @param string $name * @param string $name
* @return string or NULL if the internal var doesn't exist * @return string or NULL if the internal var doesn't exist
*/ */
public function __get($name) { public function __get ($name)
{
//echo "Getting '$name'\n"; //echo "Getting '$name'\n";
if (array_key_exists($name, $this->__data__)) { if (array_key_exists( $name, $this->__data__ )) {
return $this->__data__[$name]; return $this->__data__[$name];
} }
@@ -55,89 +62,102 @@ class HttpProxyController {
/** /**
* Magic isset method * Magic isset method
* *
* @param string $name * @param string $name
*/ */
public function __isset($name) { public function __isset ($name)
{
//echo "Is '$name' set?\n"; //echo "Is '$name' set?\n";
return isset($this->__data__[$name]); return isset( $this->__data__[$name] );
} }
/** /**
* Magic unset method * Magic unset method
* *
* @param string $name * @param string $name
*/ */
public function __unset($name) { public function __unset ($name)
{
//echo "Unsetting '$name'\n"; //echo "Unsetting '$name'\n";
unset($this->__data__[$name]); unset( $this->__data__[$name] );
} }
/** /**
* call to execute a internal proxy method and handle its exceptions * call to execute a internal proxy method and handle its exceptions
* *
* @param string $name * @param string $name
*/ */
public function call($name) public function call ($name)
{ {
try { try {
$result = $this->$name($this->__request__); $result = $this->$name( $this->__request__ );
if (!$this->jsonResponse) { if (! $this->jsonResponse) {
return null; return null;
} }
if( ! $result ) if (! $result) {
$result = $this->__data__; $result = $this->__data__;
}
} catch (Exception $e) { } catch (Exception $e) {
$result->success = false; $result->success = false;
$result->message = $result->msg = $e->getMessage(); $result->message = $result->msg = $e->getMessage();
switch(get_class($e)) { switch (get_class( $e )) {
case 'Exception': $error = "SYSTEM ERROR"; break; case 'Exception':
case 'PMException': $error = "PROCESSMAKER ERROR"; break; $error = "SYSTEM ERROR";
case 'PropelException': $error = "DATABASE ERROR"; break; break;
case 'UserException': $error = "USER 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->error = $e->getMessage();
$result->exception->class = get_class($e); $result->exception->class = get_class( $e );
$result->exception->code = $e->getCode(); $result->exception->code = $e->getCode();
$result->exception->trace = $e->getTraceAsString(); $result->exception->trace = $e->getTraceAsString();
} }
if ($this->sendResponse) { if ($this->sendResponse) {
print G::json_encode($result); print G::json_encode( $result );
} }
} }
/** /**
* Set the http request data * Set the http request data
* *
* @param array $data * @param array $data
*/ */
public function setHttpRequestData($data) public function setHttpRequestData ($data)
{ {
if( is_array($data) ) { if (is_array( $data )) {
while( $var = each($data) ) while ($var = each( $data )) {
$this->__request__->$var['key'] = $var['value']; $this->__request__->$var['key'] = $var['value'];
} else }
} else {
$this->__request__ = $data; $this->__request__ = $data;
}
} }
public function setJsonResponse($bool) public function setJsonResponse ($bool)
{ {
$this->jsonResponse = $bool; $this->jsonResponse = $bool;
} }
/** /**
* Send response to client * Send response to client
* *
* @param boolean $val * @param boolean $val
*/ */
public function setSendResponse($val) public function setSendResponse ($val)
{ {
$this->sendResponse = $val; $this->sendResponse = $val;
} }
} }

View File

@@ -1,7 +1,9 @@
<?php <?php
/** /**
* class.dbtable.php * class.dbtable.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
@@ -13,375 +15,395 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
* i18n_PO * i18n_PO
* This class build biggers PO files without size limit and this not use much memory that the allowed * This class build biggers PO files without size limit and this not use much memory that the allowed
* *
* @package gulliver.system * @package gulliver.system
* @author Erik Amaru Ortiz <erik@colosa.com> * @author Erik Amaru Ortiz <erik@colosa.com>
* date Aug 31th, 2010 * date Aug 31th, 2010
* @copyright (C) 2002 by Colosa Development Team. * @copyright (C) 2002 by Colosa Development Team.
*/ */
class i18n_PO class i18n_PO
{ {
private $_file = NULL; private $_file = null;
private $_string = ''; private $_string = '';
private $_meta; private $_meta;
private $_fp; private $_fp;
private $_fileComments; 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;
}
function readInit(){ protected $_editingHeader;
$this->_fp = fopen($this->file, 'r'); protected $_fileLine;
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();
}
function addHeader($id, $value) protected $flagEndHeaders;
{ protected $flagError;
if( $this->_editingHeader ) { protected $flagInit;
$meta = '"'.trim($id).': '.trim($value).'\n"'; protected $lineNumber;
$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);
}
private function readHeaders() public $translatorComments;
{ public $extractedComments;
$this->flagEndHeaders = false; public $references;
$this->flagError = false; public $flags;
$this->flagInit = true; public $previousUntranslatedStrings;
$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 function __construct ($file)
$firstLine = fgets($this->_fp); {
$secondLine = fgets($this->_fp); $this->file = $file;
}
//verifying the file head function buildInit ()
if( strpos($firstLine, 'msgid ""') === false || strpos($secondLine, 'msgstr ""') === false ){ {
$this->flagError = true; $this->_fp = fopen( $this->file, 'w' );
$errMsg = 'Misplace for firts msgid "" and msgstr "" in the header';
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 // lock PO file exclusively
if( trim($this->_fileLine) == '' || ! $this->_fileLine || $this->lineNumber >= 20 ) { if (! flock( $this->_fp, LOCK_EX )) {
$this->flagEndHeaders = true; // set ending to read the headers fclose( $this->_fp );
continue; return false;
} }
//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 $this->_meta = 'msgid ""';
if( sizeof($match) == 3 ) { $this->_writeLine( $this->_meta );
$key = trim($match[1]); //getting the key of the header $this->_meta = 'msgstr ""';
$value = trim($match[2]); //getting the value of the header $this->_writeLine( $this->_meta );
$this->_meta[$key] = $value; //setting a new header
} else { $this->_editingHeader = true;
$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 function readInit ()
if( ! isset($this->_meta['X-Poedit-Country']) ) { {
$this->_meta['X-Poedit-Country'] = '.'; $this->_fp = fopen( $this->file, 'r' );
} else if( $this->_meta['X-Poedit-Country'] == '' ) {
$this->_meta['X-Poedit-Country'] = '.'; 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 function addHeader ($id, $value)
if( $this->flagError ){ {
throw new Exception("This file is not a valid PO file. ($errMsg)"); if ($this->_editingHeader) {
$meta = '"' . trim( $id ) . ': ' . trim( $value ) . '\n"';
$this->_writeLine( $meta );
}
} }
}
function getHeaders() { function addTranslatorComment ($str)
return $this->_meta; {
} $this->headerStroke();
$comment = '# ' . trim( $str );
public function getTranslation(){ $this->_writeLine( $comment );
$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 = ''; function addExtractedComment ($str)
{
do { $this->headerStroke();
//g::pr($match); $comment = '#. ' . trim( $str );
$msgid .= $match[1]; $this->_writeLine( $comment );
$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 = ''; function addReference ($str)
{
do { $this->headerStroke();
//g::pr($match); $reference = '#: ' . trim( $str );
$msgstr .= $match[1] . "\n"; $this->_writeLine( $reference );
$this->_fileLine = trim(fgets($this->_fp)); }
preg_match('/^"(.*)"\s*/s', $this->_fileLine, $match);
} while ( sizeof($match) == 2 ); function addFlag ($str)
{
$this->headerStroke();
/*g::pr($this->translatorComments); $flag = '#, ' . trim( $str );
g::pr($this->references); $this->_writeLine( $flag );
g::pr($match); }
die;*/
function addPreviousUntranslatedString ($str)
return Array('msgid'=>trim($msgid), 'msgstr'=>trim($msgstr)); {
} $this->headerStroke();
$str = '#| ' . trim( $str );
//garbage $this->_writeLine( $str );
function __destruct() }
{
if ( $this->_fp ) function addTranslation ($msgid, $msgstr)
fclose($this->_fp); {
} $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 <?php
/** /**
* class.mailer.php * class.mailer.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
G::LoadThirdParty('phpmailer','class.phpmailer'); G::LoadThirdParty( 'phpmailer', 'class.phpmailer' );
/* Send emails using the class "PHPMailer" /* Send emails using the class "PHPMailer"
* Email server configuration constants: * Email server configuration constants:
* MAIL_MAILER mail/smtp * MAIL_MAILER mail/smtp
@@ -39,237 +40,276 @@ G::LoadThirdParty('phpmailer','class.phpmailer');
* @author David Callizaya <davidsantos@colosa.com> * @author David Callizaya <davidsantos@colosa.com>
*/ */
/**
/** *
* @package gulliver.system * @package gulliver.system
**/ *
*/
class mailer 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 * instanceMailer
* *
* @param string $from default value empty * @return object(PHPMailer) $mailer
* @param string $target default value default value empty */
* @param string $cc default value default value empty function instanceMailer ()
* @param string $bcc default value default value empty {
* @param string $subject default value empty $mailer = new PHPMailer();
* @param array $Fields $mailer->PluginDir = PATH_THIRDPARTY . 'phpmailer/';
* @param string $templateFile default value "empty.html" //DEFAULT CONFIGURATION
* @param array $attachs $mailer->Mailer = 'mail';
* @param boolean $plainText default value false $mailer->Host = "";
* @param boolean $returnContent default value false $mailer->SMTPAuth = false;
* $mailer->Username = "";
* @return object $content or $result $mailer->Password = "";
*/ $mailer->Timeout = 30;
function sendTemplate( $from = "", $target = "", $cc = "", $bcc="" ,$subject = "", $Fields = array(), $templateFile = "empty.html", $attachs=array(), $plainText=false, $returnContent = false ) $mailer->CharSet = 'utf-8';
{ $mailer->Encoding = 'base64';
// Read the content of the TemplateFile if (defined( 'MAIL_MAILER' )) {
$fp = fopen(PATH_HTMLMAIL . $templateFile,"r"); $mailer->Mailer = MAIL_MAILER;
$content = fread($fp,filesize(PATH_HTMLMAIL . $templateFile)); }
fclose($fp); if (defined( 'MAIL_HOST' )) {
//Replace the @@Fields with the $Fields array. $mailer->Host = MAIL_HOST;
$content = mailer::replaceFields($Fields,$content); }
//Compatibility with class.Application if (defined( 'MAIL_SMTPAUTH' )) {
if ($attachs==='FALSE') $mailer->SMTPAuth = MAIL_SMTPAUTH;
return $content; }
//Create the alternative body (text only) if (defined( 'MAIL_USERNAME' )) {
//$h2t =& new html2text($content); $mailer->Username = MAIL_USERNAME;
$text = '';//$h2t->get_text(); }
//Prepate el phpmailer if (defined( 'MAIL_PASSWORD' )) {
$mailer = mailer::instanceMailer(); $mailer->Password = MAIL_PASSWORD;
$arpa = mailer::arpaEMAIL($from); }
$mailer->From = $arpa['email']==''?$mailer->defaultEMail:$arpa['email']; if (defined( 'MAIL_TIMEOUT' )) {
$mailer->FromName = $arpa['name']; $mailer->Timeout = MAIL_TIMEOUT;
$arpa = mailer::arpaEMAIL($target); }
$mailer->AddAddress($arpa['email'],$arpa['name']); if (defined( 'MAIL_CHARSET' )) {
$mailer->AddCC($cc); $mailer->CharSet = MAIL_CHARSET;
$mailer->AddBCC($bcc); }
$mailer->Subject = $subject; if (defined( 'MAIL_ENCODING' )) {
if ($plainText) $mailer->Encoding = MAIL_ENCODING;
$content = $text; }
if ($content==='') return $mailer;
$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;
}
/** /* ARPA INTERNET TEXT MESSAGES
* replaceFields * Returns an array with the "name" and "email" of an ARPA type
* * email $address.
* @param array $Fields * @author David Callizaya
* @param string $content default value string empty */
* function arpaEMAIL ($address)
* @return none {
*/ $arpa = array ();
function replaceFields($Fields = array(), $content = "") preg_match( "/([^<>]*)(?:\<([^<>]*)\>)?/", $address, $matches );
{ $isEmail = preg_match( "/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i", $matches[1] );
return G::replaceDataField( $content , $Fields ); $arpa['email'] = ((isset( $matches[2] )) && ($matches[2] != '')) ? $matches[2] : (($isEmail) ? $matches[1] : '');
} $arpa['name'] = ($isEmail) ? '' : $matches[1];
return $arpa;
/** }
* html2text
* /**
* empty * sendTemplate
* @return none *
*/ * @param string $from default value empty
function html2text() * @param string $target default value default value empty
{ * @param string $cc default value default value empty
//$h2t =& new html2text($content); * @param string $bcc default value default value empty
//return $h2t->get_text(); * @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 <?php
/** /**
* class.menu.php * class.menu.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
@@ -13,23 +15,27 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
*
* @package gulliver.system * @package gulliver.system
*/ *
*/
/** /**
*
* *
* Menu class definition * Menu class definition
* Render Menus * Render Menus
*
* @package gulliver.system * @package gulliver.system
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @copyright (C) 2002 by Colosa Development Team. * @copyright (C) 2002 by Colosa Development Team.
@@ -37,343 +43,342 @@
*/ */
class Menu class Menu
{ {
var $Id = NULL; var $Id = null;
var $Options = NULL; var $Options = null;
var $Labels = NULL; var $Labels = null;
var $Icons = NULL; var $Icons = null;
var $JS = NULL; var $JS = null;
var $Types = NULL; var $Types = null;
var $Class = "mnu"; var $Class = "mnu";
var $Classes = NULL; var $Classes = null;
var $Enabled = NULL; var $Enabled = null;
var $optionOn = -1; var $optionOn = - 1;
var $id_optionOn = ""; var $id_optionOn = "";
var $ElementClass = NULL; var $ElementClass = null;
/** /**
* Set menu style * Set menu style
* *
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public * @access public
* @param $strClass name of style class default value 'mnu' * @param $strClass name of style class default value 'mnu'
* @return void * @return void
*/ */
function SetClass( $strClass = "mnu" ) 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 ) )
{ {
$result = count( $this->Options ); $this->Class = "mnu";
} }
return $result;
}
/** /**
* Add an option to menu * Load menu options
* *
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public * @access public
* @param string $strLabel label to show * @param $strMenuName name of menu
* @param string $strURL link * @return void
* @param string $strType type, defualt value ='plugins' */
* @return void function Load ($strMenuName)
*/
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')) { 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; //if the menu file doesn't exists, then try with the plugins folders
} if (! is_file( $fMenu )) {
else $aux = explode( PATH_SEP, $strMenuName );
if (defined('SYS_SYS')) if (count( $aux ) == 2) {
$target = "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target; $oPluginRegistry = & PMPluginRegistry::getSingleton();
else if ($oPluginRegistry->isRegisteredFolder( $aux[0] )) {
$target = "/sys/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target; $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 );
} /**
* Load menu options
/** *
* to make an array for template * @author Fernando Ontiveros Lira <fernando@colosa.com>
* * @access public
* @author Fernando Ontiveros Lira <fernando@colosa.com> * @return int
* @access public */
* @param string $G_MAIN_MENU function OptionCount ()
* @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++) $result = 0;
{ if (is_array( $this->Options )) {
$target = $this->Options[$ncount]; $result = count( $this->Options );
//$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') { return $result;
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;
} /**
} * 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 <?php
/** /**
* class.objectTemplate.php * class.objectTemplate.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
* Class objectTemplate * Class objectTemplate
*
* @package gulliver.system * @package gulliver.system
* @access public * @access public
*/ */
class objectTemplate extends smarty class objectTemplate extends smarty
{ {
/**
* Function objectTemplate
* @access public
* @param object $templateFile
* @return void
*/
function objectTemplate( $templateFile ) /**
{ * Function objectTemplate
$this->template_dir = PATH_TPL; *
$this->compile_dir = PATH_SMARTY_C; * @access public
$this->cache_dir = PATH_SMARTY_CACHE; * @param object $templateFile
$this->config_dir = PATH_THIRDPARTY . 'smarty/configs'; * @return void
$this->caching = false; */
$this->templateFile = $templateFile;
} function objectTemplate ($templateFile)
{
/** $this->template_dir = PATH_TPL;
* Function printObject $this->compile_dir = PATH_SMARTY_C;
* @access public $this->cache_dir = PATH_SMARTY_CACHE;
* @param object $object $this->config_dir = PATH_THIRDPARTY . 'smarty/configs';
* @return string $this->caching = false;
*/ $this->templateFile = $templateFile;
function printObject($object) }
{
$this->assign($object); /**
return $this->fetch($this->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 <?php
/** /**
* class.testTools.php * class.testTools.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
*
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
*
* @package gulliver.system * @package gulliver.system
**/ *
G::LoadSystem ( 'ymlDomain'); */
G::LoadSystem ( 'ymlTestCases'); G::LoadSystem( 'ymlDomain' );
G::LoadSystem ( 'unitTest'); G::LoadSystem( 'ymlTestCases' );
G::LoadSystem( 'unitTest' );
class testTools 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 * importDB
* *
* @param string $methodFile * @param string $host
* @param string $GET * @param string $user
* @param string $POST * @param string $password
* @param string $SESSION * @param string $database
* * @param string $importFile
* @return none *
*/ * @return none
function callMethod( $methodFile, $GET, $POST, $SESSION ) */
{ function importDB ($host, $user, $password, $database, $importFile)
//TODO $_SERVER {
self::arrayDelete($_GET); exec( "mysql -h " . $host . " --user=" . $user . " --password=" . $password . " $database < $importFile" );
self::arrayDelete($_POST); }
self::arrayDelete($_SESSION);
self::arrayAppend($_GET,$GET);
self::arrayAppend($_POST,$POST);
self::arrayAppend($_SESSION,$SESSION);
include( PATH_CORE . 'methods/' . $methodFile );
}
/** /**
* arrayAppend * importLocalDB
* *
* @param string &$to * @param string $importFile
* @param string $appendFrom *
* * @return none
* @return boolean true */
*/ function importLocalDB ($importFile)
function arrayAppend( &$to , $appendFrom ) {
{ self::importDB( DB_HOST, DB_USER, DB_PASS, DB_NAME, $importFile );
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 );
}
} }
return $Fields;
} /**
* callMethod
// EXTRA TOOLS *
/** * @param string $methodFile
* findValue * @param string $GET
* * @param string $POST
* @param string $value * @param string $SESSION
* @param object &$obj *
* * @return none
* @return (boolean | string) ((true | false) | $value) */
*/ function callMethod ($methodFile, $GET, $POST, $SESSION)
function findValue( $value, &$obj ) {
{ //TODO $_SERVER
if (is_array($obj)) { self::arrayDelete( $_GET );
foreach($obj as $key => $val ) { self::arrayDelete( $_POST );
if ($res=self::findValue( $value , $obj[$key] )) { self::arrayDelete( $_SESSION );
if ($res==true) return $key; self::arrayAppend( $_GET, $GET );
else return $key . '.' . $res; 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 true;
return false;
} }
elseif (is_object($obj)) {
foreach($obj as $key => $val ) { /**
if ($res=self::findValue( $value , $obj->$key )) { * arrayDelete
if ($res==true) *
return $key; * @param array &$array
else *
return $key . '.' . $res; * @return boolean true
*/
function arrayDelete (&$array)
{
foreach ($array as $key => $value) {
unset( $array[$key] );
} }
} return true;
return false;
} }
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 */ /* Some extra global functions */
/** /**
* domain * domain
* *
* @param string $location * * @param string $location *
* @return object $result * @return object $result
*/ */
function domain($location) function domain ($location)
{ {
global $testDomain; global $testDomain;
$result = $testDomain->get($location); $result = $testDomain->get( $location );
if (count($result)==0) trigger_error("'$location' is an empty domain.", E_USER_WARNING); if (count( $result ) == 0) {
return $result; trigger_error( "'$location' is an empty domain.", E_USER_WARNING );
}
return $result;
} }

View File

@@ -1,153 +1,160 @@
<?php <?php
/** /**
* class.tree.php * class.tree.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
*
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
*<2A> * <EFBFBD>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
*
* @package gulliver.system * @package gulliver.system
*/ */
G::LoadSystem('objectTemplate'); G::LoadSystem( 'objectTemplate' );
class Tree extends Xml_Node {
var $template = 'tree.html'; class Tree extends Xml_Node
var $nodeType = 'base'; {
var $nodeClass = 'treeNode'; var $template = 'tree.html';
var $nodeType = 'base';
var $nodeClass = 'treeNode';
var $contentClass = 'treeContent'; var $contentClass = 'treeContent';
var $width = '100%'; var $width = '100%';
var $contentWidth = '360'; var $contentWidth = '360';
var $contracted = false; var $contracted = false;
var $showSign = true; var $showSign = true;
var $isChild = false; var $isChild = false;
var $plus = "<span style='position:absolute; width:16px;height:22px;cursor:pointer;'onclick='tree.expand(this.parentNode);'>&nbsp;</span>"; 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 $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 $point = "<span style='position:absolute; width:5px;height:10px;cursor:pointer;' onclick='tree.select(this.parentNode);'>&nbsp;</span>";
/** /**
* Tree * Tree
* *
* @param array $xmlnode default value NULL * @param array $xmlnode default value NULL
* *
* @return none * @return none
*/ */
function Tree( $xmlnode = NULL ) function Tree ($xmlnode = null)
{ {
if (!isset($xmlnode)) if (! isset( $xmlnode )) {
return; 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;
}
} }
else { if (isset( $xmlnode->attributes['nodeType'] )) {
$this->{$key} = $value; $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 * &addChild
* *
* @param string $name * @param string $name
* @param string $label * @param string $label
* @param array $attributes * @param array $attributes
* *
* @return object(Tree) $newNode * @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)); $newNode = new Tree( new Xml_Node( $name, 'open', $label, $attributes ) );
$this->children[] =& $newNode; $this->children[] = & $newNode;
return $newNode; return $newNode;
} }
/** /**
* printPlus * printPlus
* *
* @return string '<span>...</span>' * @return string '<span>...</span>'
*/ */
function printPlus() function printPlus ()
{ {
$plus = 'none'; $plus = 'none';
$minus = 'none'; $minus = 'none';
$point = 'none'; $point = 'none';
if ($this->showSign) { if ($this->showSign) {
if ((sizeof($this->children)>0) && ($this->contracted)) { if ((sizeof( $this->children ) > 0) && ($this->contracted)) {
$plus = ''; $plus = '';
} elseif ((sizeof($this->children)>0) && (!$this->contracted)) { } elseif ((sizeof( $this->children ) > 0) && (! $this->contracted)) {
$minus = ''; $minus = '';
} else { } else {
$point = ''; $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 * printLabel
* *
* @return $this->value * @return $this->value
*/ */
function printLabel() function printLabel ()
{ {
return $this->value; return $this->value;
} }
/** /**
* printContent * printContent
* *
* @return string $html * @return string $html
*/ */
function printContent() function printContent ()
{ {
$html = ''; $html = '';
$row = 0; $row = 0;
foreach($this->children as $child) { foreach ($this->children as $child) {
if ($row) if ($row) {
$child->nodeClass = 'treeNodeAlternate'; $child->nodeClass = 'treeNodeAlternate';
$html .= $child->render(); }
$row = ($row + 1) % 2; $html .= $child->render();
} $row = ($row + 1) % 2;
return $html; }
return $html;
} }
/** /**
* render * render
*
* @return $obj->printObject( array( 'node' => &$this ) ) * @return $obj->printObject( array( 'node' => &$this ) )
*/ */
function render() { function render ()
$obj = new objectTemplate( $this->template ); {
return $obj->printObject( array( 'node' => &$this ) ); $obj = new objectTemplate( $this->template );
return $obj->printObject( array ('node' => &$this
) );
} }
} }

View File

@@ -1,12 +1,14 @@
<?php <?php
/** /**
* class.unitTest.php * class.unitTest.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
*
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
* @package gulliver.system *
*/ * @package gulliver.system
*/
class unitTest class unitTest
{ {
var $dbc; var $dbc;
var $times; var $times;
var $yml; var $yml;
var $domain; var $domain;
var $testLime; var $testLime;
function unitTest( $ymlFile, &$testLime, &$testDomain )
{ function unitTest ($ymlFile, &$testLime, &$testDomain)
if (!isset($testDomain)) $testDomain = new ymlDomain(); {
$this->domain =& $testDomain; if (! isset( $testDomain )) {
$this->testLime =& $testLime; $testDomain = new ymlDomain();
$this->yml = new ymlTestCases( $ymlFile, $this->domain, $this->testLime ); }
} $this->domain = & $testDomain;
//Load a Test (group of unitary tests) defined in the Yml file. $this->testLime = & $testLime;
function load( $testName, $fields=array() ) $this->yml = new ymlTestCases( $ymlFile, $this->domain, $this->testLime );
{ }
$this->yml->load( $testName, $fields ); //Load a Test (group of unitary tests) defined in the Yml file.
} function load ($testName, $fields = array())
//Run one single unit test from the loaded Test {
function runSingle( $fields=array() ) $this->yml->load( $testName, $fields );
{ }
return $this->yml->runSingle( $this, $fields ); //Run one single unit test from the loaded Test
} function runSingle ($fields = array())
//Run a group of unit tests from the loaded Test {
function runMultiple( $fields=array(), $count = -1, $start=0) return $this->yml->runSingle( $this, $fields );
{ }
return $this->yml->runMultiple( $this, $fields, $count, $start ); //Run a group of unit tests from the loaded Test
} function runMultiple ($fields = array(), $count = -1, $start = 0)
//Run all the unit tests from the loaded Test {
function runAll( $fields=array()) return $this->yml->runMultiple( $this, $fields, $count, $start );
{ }
return $this->yml->runMultiple( $this, $fields, -1, 0 ); //Run all the unit tests from the loaded Test
} function runAll ($fields = array())
//A sample of "Function" to run a unit test. {
function sampleTestFunction( $testCase , &$Fields ) return $this->yml->runMultiple( $this, $fields, - 1, 0 );
{ }
$result = ($Fields['APP_UID']!='')?"OK":"FALSE"; //A sample of "Function" to run a unit test.
return $result; function sampleTestFunction ($testCase, &$Fields)
} {
$result = ($Fields['APP_UID'] != '') ? "OK" : "FALSE";
return $result;
}
} }

View File

@@ -1,11 +1,13 @@
<?php <?php
/** /**
* class.webResource.php * class.webResource.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/* Web Resource (v1.0 PHP4) /* Web Resource (v1.0 PHP4)
* This class permit create PHP/Javascript classes accesible by * This class permit create PHP/Javascript classes accesible by
@@ -29,103 +31,101 @@
* _Function = don't encode * _Function = don't encode
* JS_function = javascript function. * JS_function = javascript function.
* @example: h2b2x/territoriesAjax.php * @example: h2b2x/territoriesAjax.php
* @dependencies: grest.js * * @dependencies: grest.js *
*/ */
/** /**
*
* @package gulliver.system * @package gulliver.system
*/ */
class WebResource class WebResource
{ {
var $_uri; var $_uri;
/** /**
* WebResource * WebResource
* *
* @param string $uri * @param string $uri
* @param string $post * @param string $post
* *
* @return none * @return none
*/ */
function WebResource($uri, $post) function WebResource ($uri, $post)
{ {
$this->_uri=$uri; $this->_uri = $uri;
if (isset($post['function'])&&$post['function']!='') { if (isset( $post['function'] ) && $post['function'] != '') {
/*Call a function*/ /*Call a function*/
header('Content-Type: text/json'); header( 'Content-Type: text/json' );
//$parameters=G::json_decode((urldecode($post['parameters']))); //for %AC //$parameters=G::json_decode((urldecode($post['parameters']))); //for %AC
$parameters=G::json_decode(($post['parameters'])); $parameters = G::json_decode( ($post['parameters']) );
$paramsRef=array(); $paramsRef = array ();
foreach($parameters as $key => $value) foreach ($parameters as $key => $value) {
{ if (is_string( $key )) {
if (is_string($key)) $paramsRef[]="\$parameters['".addcslashes($key,'\\\'')."']"; $paramsRef[] = "\$parameters['" . addcslashes( $key, '\\\'' ) . "']";
else $paramsRef[]='$parameters['.$key.']'; } else {
} $paramsRef[] = '$parameters[' . $key . ']';
$res=eval('return ($this->'.$post['function'].'('.implode(',',$paramsRef).'));'); }
$res=G::json_encode($res); }
print($res); $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 */ /* end class WebResource */
if (!function_exists('json_encode')) { if (! function_exists( 'json_encode' )) {
G::LoadThirdParty('pear/json','class.json'); G::LoadThirdParty( 'pear/json', 'class.json' );
function json_encode(&$value) {
$json= new Services_JSON; function json_encode (&$value)
return $json->encode($value); {
} $json = new Services_JSON();
return $json->encode( $value );
}
} }
if (!function_exists('json_decode')) { if (! function_exists( 'json_decode' )) {
G::LoadThirdParty('pear/json','class.json'); G::LoadThirdParty( 'pear/json', 'class.json' );
function json_decode(&$value) {
$json= new Services_JSON; function json_decode (&$value)
return $json->decode($value); {
} $json = new Services_JSON();
return $json->decode( $value );
}
} }

View File

@@ -1,7 +1,9 @@
<?php <?php
/** /**
* class.xmlDocument.php * class.xmlDocument.php
* @package gulliver.system *
* @package gulliver.system
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
@@ -13,11 +15,11 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
@@ -25,340 +27,355 @@
*/ */
/** /**
* Class Xml_Node * Class Xml_Node
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @package gulliver.system * @package gulliver.system
* @access public * @access public
*/ */
class Xml_Node class Xml_Node
{ {
var $name = ''; var $name = '';
var $type = ''; var $type = '';
var $value = ''; //maybe not necesary var $value = ''; //maybe not necesary
var $attributes = array(); var $attributes = array ();
var $children = array(); var $children = array ();
/**
* Function Xml_Node /**
* @author David S. Callizaya S. <davidsantos@colosa.com> * Function Xml_Node
* @access public *
* @parameter string name * @author David S. Callizaya S. <davidsantos@colosa.com>
* @parameter string type * @access public
* @parameter string value * @param eter string name
* @parameter string attributes * @param eter string type
* @return string * @param eter string value
*/ * @param eter string attributes
function Xml_Node($name, $type, $value, $attributes = array() ) * @return string
{ */
$this->name = $name; function Xml_Node ($name, $type, $value, $attributes = array())
$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)
{ {
case 'open': $this->name = $name;
$xml = '<'.$this->name; $this->type = $type;
foreach( $this->attributes as $attib => $value ) { $this->value = $value;
$value = htmlspecialchars( $value, ENT_QUOTES, 'utf-8' ); $this->attributes = $attributes;
/*if(($attib == "hint")||($attib == "defaultvalue")){ }
$value = str_replace("&", "&amp;", $value);
$value = str_replace("'", "\'", $value); /**
$value = str_replace(">", "&gt;", $value); * Function addAttribute
$value = str_replace("<", "&lt;", $value); *
} * @author David S. Callizaya S. <davidsantos@colosa.com>
//else{ * @access public
$value = htmlentities( $value, ENT_QUOTES, 'utf-8' ); * @param eter string name
//} * @param eter string value
*/ * @return string
$xml .= ' ' . $attib . '="' . $value . '"'; */
//check if the htmlentities result value is the euro symbol and function addAttribute ($name, $value)
//replaced by their numeric character representation {
if (strpos($xml, '&euro;') !== false) { $this->attributes[$name] = $value;
$xml = str_replace('&euro;', '&#8364;', $xml); return true;
} }
}
$xml .= '>'.$this->getCDATAValue(); /**
foreach( $this->children as $child ) * Function addChildNode
$xml .= $child->getXML(); *
$xml .= '</'.$this->name.'>'; * @author David S. Callizaya S. <davidsantos@colosa.com>
break; * @access public
* @param eter string childNode
case 'close': * @return string
$xml = '</'.$this->name.'>'; */
break; function addChildNode ($childNode)
{
case 'cdata': if (is_object( $childNode ) && strcasecmp( get_class( $childNode ), 'Xml_Node' ) == 0) {
$xml = $this->getCDATAValue(); $this->type = 'open';
break; $childNode->parent = &$this;
$this->children[] = &$childNode;
case 'complete': return true;
} else {
$xml = '<'.$this->name; return false;
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) { * Function toTree
$xml = str_replace('&euro;', '&#8364;', $xml); *
} * @author David S. Callizaya S. <davidsantos@colosa.com>
} * @access public
if ($this->value!=='') { * @return string
$xml .= '>'.$this->getCDATAValue(); */
$xml .= '</'.$this->name.'>'; function toTree ()
} else { {
$xml .= '/>'; $arr = new Xml_Node( $this->name, $this->type, $this->value, $this->attributes );
} unset( $arr->parent );
break; 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 * Class Xml_document
*
* @author David S. Callizaya S. <davidsantos@colosa.com> * @author David S. Callizaya S. <davidsantos@colosa.com>
* @package gulliver.system * @package gulliver.system
* @access public * @access public
*/ */
class Xml_document extends Xml_Node class Xml_document extends Xml_Node
{ {
var $currentNode; 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 );
$this->name = '#document'; /**
$this->type = 'open'; * Function Xml_document
$this->currentNode = &$this; *
$m = &$this; * @author David S. Callizaya S. <davidsantos@colosa.com>
foreach($values as $k => $v) * @access public
* @return string
*/
function Xml_document ()
{ {
switch ($v['type']) $this->currentNode = &$this;
{
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
* @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 * Function parseXmlFile
* *
* @access public * @author David S. Callizaya S. <davidsantos@colosa.com>
* @return string $xml * @access public
*/ * @param eter string filename
function getXML() * @param eter string content
{ * @return string
$xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n"; */
$xml .= $this->children[0]->getXML(); function parseXmlFile ($filename, $content = "")
return $xml; { //$content is a new variable, if it has any value then use it instead of the file content.
} if ($content == "") {
/** if (! file_exists( $filename )) {
* Function save throw (new Exception( "failed to open Xmlform File : No such file or directory in $filename " ));
* }
* @access public $data = implode( '', file( $filename ) );
* @return void } else {
*/ $data = $content;
function save ( $filename ) }
{
$xml = $this->getXML(); $parser = xml_parser_create( 'utf-8' );
$fp = fopen( $filename , 'w' ); xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
fwrite( $fp , $xml ); xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 0 );
fclose( $fp );/**/ 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 <?php
/**
* class.xmlformExtension.php /**
* @package gulliver.system * class.xmlformExtension.php
* *
* ProcessMaker Open Source Edition * @package gulliver.system
* Copyright (C) 2004 - 2011 Colosa Inc. *
* * ProcessMaker Open Source Edition
* This program is free software: you can redistribute it and/or modify * Copyright (C) 2004 - 2011 Colosa Inc.
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the * This program is free software: you can redistribute it and/or modify
* License, or (at your option) any later version. * it under the terms of the GNU Affero General Public License as
* * published by the Free Software Foundation, either version 3 of the
* This program is distributed in the hope that it will be useful, * License, or (at your option) any later version.
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * This program is distributed in the hope that it will be useful,
* GNU Affero General Public License for more details. * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* You should have received a copy of the GNU Affero General Public License * GNU Affero General Public License for more details.
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* * You should have received a copy of the GNU Affero General Public License
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * along with this program. If not, see <http://www.gnu.org/licenses/>.
* Coral Gables, FL, 33134, USA, or email info@colosa.com. *
* * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
*/ * Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
/** */
* @package gulliver.system
*/ /**
*
class XmlForm_Field_Label extends XmlForm_Field * @package gulliver.system
{ */
var $withoutValue = true;
var $align = 'left'; 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 * Special class for pagedTable
*/ * condition: PHP expression whose result defines whether to "mark"
class XmlForm_Field_cellMark extends XmlForm_Field * the following columns (that is if true)
{ *
/* Defines the style of the next tds * @package gulliver.system
*/
class XmlForm_Field_cellMark extends XmlForm_Field
{
/* Defines the style of the next tds
of the pagedTable. of the pagedTable.
*/ */
var $showInTable = "0"; var $showInTable = "0";
var $style = ""; var $style = "";
var $styleAlt = ""; var $styleAlt = "";
var $className = ""; var $className = "";
var $classNameAlt = ""; var $classNameAlt = "";
var $condition = 'false'; var $condition = 'false';
/** /**
* tdStyle * tdStyle
* *
* @param string $values * @param string $values
* @param string $owner * @param string $owner
* *
* @return string $value * @return string $value
*/ */
function tdStyle( $values , $owner ) function tdStyle ($values, $owner)
{ {
$value = G::replaceDataField( $this->condition, $owner->values ); $value = G::replaceDataField( $this->condition, $owner->values );
$value = @eval('return ('.$value.');'); $value = @eval( 'return (' . $value . ');' );
$row=$values['row__']; $row = $values['row__'];
$style=((($row % 2)==0) && ($this->styleAlt!=0)) ? $style = ((($row % 2) == 0) && ($this->styleAlt != 0)) ? $this->styleAlt : $this->style;
$this->styleAlt : $this->style; return ($value) ? $style : '';
return ($value)?$style:''; }
}
/**
/** * tdClass
* tdClass *
* * @param string $values
* @param string $values * @param string $owner
* @param string $owner *
* * @return $value
* @return $value */
*/ function tdClass ($values, $owner)
function tdClass( $values, $owner ) {
{ $value = G::replaceDataField( $this->condition, $owner->values );
$value = G::replaceDataField( $this->condition, $owner->values ); $value = @eval( 'return (' . $value . ');' );
$value = @eval('return ('.$value.');'); $row = $values['row__'];
$row=$values['row__']; $style = (($row % 2) == 0) ? $this->classNameAlt : $this->className;
$style=(($row % 2)==0) ? return ($value) ? $style : '';
$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)";
}