diff --git a/gulliver/system/class.dbMaintenance.php b/gulliver/system/class.dbMaintenance.php index bc3065123..0d68da8ec 100755 --- a/gulliver/system/class.dbMaintenance.php +++ b/gulliver/system/class.dbMaintenance.php @@ -1,7 +1,9 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -25,609 +27,617 @@ */ /** - * + * + * * Database Maintenance class - * + * * author Erik A. Ortiz * date May 17th, 2010 * * @package gulliver.system */ -class DataBaseMaintenance +class DataBaseMaintenance { - private $host; - private $user; - private $passwd; - - private $link; - private $dbName; - public $result; - protected $tmpDir; - protected $outfile; - protected $infile; + private $host; + private $user; + private $passwd; -/** - * __construct - * - * @param string $host is null - * @param string $user is null - * @param string $passwd is null - * - * @return none - */ - public function __construct($host = null, $user = null, $passwd = null) - { - $this->tmpDir = './'; - $this->link = null; - $this->dbName = null; - - if( isset($host) && isset($user) && isset($passwd) ) { - $this->host = $host; - $this->user = $user; - $this->passwd = $passwd; - } - } - -/** - * setUser - * - * @param string $user - * - * @return none - */ - public function setUser($user) - { - $this->user = $user; - } + private $link; + private $dbName; + public $result; + protected $tmpDir; + protected $outfile; + protected $infile; -/** - * setPasswd - * - * @param string $passwd - * - * @return none - */ - public function setPasswd($passwd) - { - $this->passwd = $passwd; - } - -/** - * setHost - * - * @param string $host - * - * @return none - */ - public function setHost($host) - { - $this->host = $host; - } - -/** - * setTempDir - * - * @param string $tmpDir - * - * @return none - */ - public function setTempDir($tmpDir) - { - $this->tmpDir = $tmpDir; - if (!file_exists($tmpDir)) - mkdir($this->tmpDir); - } - -/** - * getTempDir - * - * @return $this->tmpDir - */ - public function getTempDir() - { - return $this->tmpDir; - } - -/** - * status - * - * @return $this->link - */ - public function status() - { - return $$this->link; - } - - -/** - * connect - * - * @param string $dbname is null - * - * @return none - */ - public function connect($dbname = null) - { - if( $this->link != null ) { - mysql_close($this->link); - $this->link = null; - } - if( isset($dbname) ) { - $this->dbName = $dbname; - } - - $this->link = mysql_connect($this->host, $this->user, $this->passwd); - @mysql_query("SET NAMES 'utf8';"); - if( ! $this->link ) { - throw new Exception("Couldn't connect to host {$this->host} with user {$this->user}"); - } - - if( $this->dbName != null ) { - $this->selectDataBase($this->dbName); - } - } + /** + * __construct + * + * @param string $host is null + * @param string $user is null + * @param string $passwd is null + * + * @return none + */ + public function __construct ($host = null, $user = null, $passwd = null) + { + $this->tmpDir = './'; + $this->link = null; + $this->dbName = null; -/** - * setDbName - * - * @param string $dbname is null - * - * @return none - */ - public function setDbName($dbname) - { - $this->dbName = $dbname; - } - -/** - * selectDataBase - * - * @param string $dbname - * - * @return none - */ - public function selectDataBase($dbname) - { - $this->setDbName($dbname); - If( ! @mysql_select_db($this->dbName, $this->link) ) { - throw new Exception("Couldn't select database $dbname"); - } - } - -/** - * query - * - * @param string $sql - * - * @return $aRows - */ - public function query($sql) - { - $this->result = @mysql_query($sql); - if($this->result){ - $aRows = Array(); - while( $aRow = @mysql_fetch_assoc($this->result) ) { - array_push($aRows, $aRow); - } - return $aRows; - } else { - return false; - } - } - -/** - * error - * - * @return @mysql_error() - */ - public function error() - { - return @mysql_error($this->link); - } - -/** - * getTablesList - * - * @return $aRows - */ - public function getTablesList() - { - $this->result = @mysql_query("SHOW TABLES;"); - $aRows = Array (); - while( $aRow = mysql_fetch_row($this->result) ) { - array_push($aRows, $aRow[0]); - } - return $aRows; - } - -/** - * dumpData - * - * @param string $table - * - * @return boolean true or false - */ - function dumpData($table) - { - $this->outfile = $this->tmpDir . $table . '.dump'; - - //if the file exists delete it - if( is_file($this->outfile) ) { - @unlink($this->outfile); - } - - $sql = "SELECT * INTO OUTFILE '{$this->outfile}' FIELDS TERMINATED BY '\t|\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\t\t\r\r\n' FROM $table"; - // The mysql_escape_string function has been DEPRECATED as of PHP 5.3.0. - // Commented that is not assigned to a variable. - // mysql_escape_string("';"); - if( ! @mysql_query($sql) ) { - echo mysql_error() . "\n"; - return false; - } - return true; - } - -/** - * restoreData - * - * @param string $backupFile - * - * @return boolean true or false - */ - function restoreData($backupFile) - { - $tableName = str_replace('.dump', '', basename($backupFile)); - $sql = "LOAD DATA INFILE '$backupFile' INTO TABLE $tableName FIELDS TERMINATED BY '\t|\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\t\t\r\r\n'"; - if( ! @mysql_query($sql) ) { - print mysql_error() . "\n"; - return false; - } - return true; - } - -/** - * backupData - * - * @return boolean true or false - */ - function backupData() - { - $aTables = $this->getTablesList(); - foreach( $aTables as $table ) { - if( $this->dumpData($table) !== false ) { - printf("%20s %s %s\n", 'Dump of table:', $table, " in file {$this->outfile}"); - } else { - return false; - } - } - return true; - } - -/** - * backupSqlData - * - * @return boolean true or false - */ - function backupSqlData() - { - $aTables = $this->getTablesList(); - foreach( $aTables as $table ) { - $fsize = $this->dumpSqlInserts($table); - $file = basename($this->outfile); - - } - - return true; - } - -/** - * restoreAllData - * - * @param string $type default value null - * - * @return none - */ - function restoreAllData($type = null) - { - - $aTables = $this->getTablesList(); - - foreach( $aTables as $table ) { - if( isset($type) && $type == 'sql' ) { - $this->infile = $this->tmpDir . $table . ".sql"; - if( is_file($this->infile) ) { - $queries = $this->restoreFromSql($this->infile, true); - if (!isset($queries)) - $queries = "unknown"; - printf("%-59s%20s", "Restored table $table", "$queries queries\n"); + if (isset( $host ) && isset( $user ) && isset( $passwd )) { + $this->host = $host; + $this->user = $user; + $this->passwd = $passwd; } - } else { - $this->infile = $this->tmpDir . $table . ".dump"; - if( is_file($this->infile) ) { - $this->restoreData($this->infile); - printf("%20s %s %s\n", 'Restoring data from ', $this->infile, " in table $table"); + } + + /** + * setUser + * + * @param string $user + * + * @return none + */ + public function setUser ($user) + { + $this->user = $user; + } + + /** + * setPasswd + * + * @param string $passwd + * + * @return none + */ + public function setPasswd ($passwd) + { + $this->passwd = $passwd; + } + + /** + * setHost + * + * @param string $host + * + * @return none + */ + public function setHost ($host) + { + $this->host = $host; + } + + /** + * setTempDir + * + * @param string $tmpDir + * + * @return none + */ + public function setTempDir ($tmpDir) + { + $this->tmpDir = $tmpDir; + if (! file_exists( $tmpDir )) { + mkdir( $this->tmpDir ); } - } } - } - -/** - * createDb - * - * @param string $dbname - * @param string $drop default value false - * - * @return none - */ - function createDb($dbname, $drop = false) - { - if( $drop ) { - $sql = "DROP DATABASE IF EXISTS $dbname;"; - if( ! @mysql_query($sql) ) { - throw new Exception(mysql_error()); - } + + /** + * getTempDir + * + * @return $this->tmpDir + */ + public function getTempDir () + { + return $this->tmpDir; } - $sql = "CREATE DATABASE IF NOT EXISTS $dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"; - if( ! @mysql_query($sql) ) { - throw new Exception(mysql_error()); + + /** + * status + * + * @return $this->link + */ + public function status () + { + return $$this->link; } - } - -/** - * restoreFromSql2 - * - * @param string $sqlfile - * - * @return none - */ - function restoreFromSql2($sqlfile) - { - - ini_set('memory_limit', '512M'); - if( ! is_file($sqlfile) ) { - throw new Exception("the $sqlfile doesn't exist!"); - } - $query = file_get_contents($sqlfile); - $mysqli = new mysqli($this->host, $this->user, $this->passwd, $this->dbName); - - /* check connection */ - if( mysqli_connect_errno() ) { - printf("Connect failed: %s\n", mysqli_connect_error()); - exit(); - } - - /* execute multi query */ - if( $mysqli->multi_query($query) ) { - do { - /* store first result set */ - if( $result = $mysqli->store_result() ) { - while( $row = $result->fetch_row() ) { - } - $result->free(); + + /** + * connect + * + * @param string $dbname is null + * + * @return none + */ + public function connect ($dbname = null) + { + if ($this->link != null) { + mysql_close( $this->link ); + $this->link = null; } - - } while( $mysqli->next_result() ); - } - - /* close connection */ - $mysqli->close(); - } - - function lockTables() { - $aTables = $this->getTablesList(); - if (empty($aTables)) - return false; - printf("%-70s", "LOCK TABLES"); - if( @mysql_query("LOCK TABLES ".implode(" READ, ", $aTables)." READ; ") ) { - echo " [OK]\n"; - return true; - } else { - echo "[FAILED]\n".mysql_error()."\n"; - return false; - } - } - - function unlockTables() { - printf("%-70s", "UNLOCK TABLES"); - if( @mysql_query("UNLOCK TABLES;") ) - echo " [OK]\n"; - else - echo "[FAILED]\n".mysql_error()."\n"; - } - -/** - * dumpSqlInserts - * - * @param string $table - * - * @return integer $bytesSaved; - */ - function dumpSqlInserts($table) - { - - $bytesSaved = 0; - $result = @mysql_query("SELECT * FROM `$table`"); - - $num_rows = mysql_num_rows($result); - $num_fields = mysql_num_fields($result); - - $data = ""; - for( $i = 0; $i < $num_rows; $i ++ ) { - - $row = mysql_fetch_object($result); - $data .= "INSERT INTO `$table` VALUES ("; - - for( $x = 0; $x < $num_fields; $x ++ ) { - $field_name = mysql_field_name($result, $x); - - $data .= ($row->$field_name === null) ? 'NULL' : "'" . mysql_real_escape_string($row->$field_name) . "'"; - $data .= ($x < ($num_fields - 1)) ? ", " : false; - } - - $data .= ");\n"; - } - - printf("%-59s%20s", "Dump of table $table", strlen($data) . " Bytes Saved\n"); - return $data; - } - -/** - * backupDataBaseSchema - * - * @param string $outfile - * - * @return none - */ - function backupDataBase($outfile) - { - $aTables = $this->getTablesList(); - $ws = explode('_', $this->dbName); - $ws = isset($ws[1]) ? $ws[1] : $this->dbName; - $schema = "\n"; - $schema .= " -- Processmaker Data Base Maintenance Tool\n"; - $schema .= " --\n"; - $schema .= " -- Workspace: " . $ws . "\n"; - $schema .= " -- Data Base: " . $this->dbName . "\n"; - $schema .= " -- Tables: " . (count($aTables)) . "\n"; - $schema .= " -- Date: " . (date('l jS \of F Y h:i:s A')) . "\n"; - $schema .= " --\n\n"; - - $file = fopen($outfile, "w+"); - - fwrite($file, $schema); - - foreach( $aTables as $table ) { - $tableSchema = "\nDROP TABLE IF EXISTS `$table`;\n\n"; - $tableSchema .= $this->getSchemaFromTable($table); - $data = $this->dumpSqlInserts($table); - fwrite($file, $tableSchema); - fwrite($file, $data); - } - - fclose($file); - } - -/** - * restoreFromSql - * - * @param string $sqlfile - * - * @return boolean false or true - */ - function restoreFromSql($sqlfile, $type='file') - { - ini_set('memory_limit', '64M'); - if( $type == 'file' && !is_file($sqlfile) ) { - throw new Exception("the $sqlfile doesn't exist!"); - } - - $metaFile = str_replace('.sql', '.meta', $sqlfile); - - $queries = 0; - - if( is_file($metaFile) ) { - echo "Using $metaFile as metadata.\n"; - $fp = fopen($sqlfile, 'rb'); - $fpmd = fopen($metaFile, 'r'); - while( $offset = fgets($fpmd, 1024) ) { - $buffer = intval($offset); //reading the size of $oData - $query = fread($fp, $buffer); //reading string $oData - $queries += 1; - - if( ! @mysql_query($query) ) { - echo mysql_error() . "\n"; - echo "==>" . $query . "<==\n"; + if (isset( $dbname )) { + $this->dbName = $dbname; } - } - - } else { - $queries = NULL; - try{ - $mysqli = new mysqli($this->host, $this->user, $this->passwd, $this->dbName); - /* check connection */ - if( mysqli_connect_errno() ) { - printf("Connect failed: %s\n", mysqli_connect_error()); - exit(); + + $this->link = mysql_connect( $this->host, $this->user, $this->passwd ); + @mysql_query( "SET NAMES 'utf8';" ); + if (! $this->link) { + throw new Exception( "Couldn't connect to host {$this->host} with user {$this->user}" ); } - if($type == 'file'){ - $query = file_get_contents($sqlfile); - } else if($type == 'string'){ - $query = $sqlfile; + + if ($this->dbName != null) { + $this->selectDataBase( $this->dbName ); + } + } + + /** + * setDbName + * + * @param string $dbname is null + * + * @return none + */ + public function setDbName ($dbname) + { + $this->dbName = $dbname; + } + + /** + * selectDataBase + * + * @param string $dbname + * + * @return none + */ + public function selectDataBase ($dbname) + { + $this->setDbName( $dbname ); + if (! @mysql_select_db( $this->dbName, $this->link )) { + throw new Exception( "Couldn't select database $dbname" ); + } + } + + /** + * query + * + * @param string $sql + * + * @return $aRows + */ + public function query ($sql) + { + $this->result = @mysql_query( $sql ); + if ($this->result) { + $aRows = Array (); + while ($aRow = @mysql_fetch_assoc( $this->result )) { + array_push( $aRows, $aRow ); + } + return $aRows; } else { - return false; + return false; } - - if( trim($query) == "" ) - return false; - + } + + /** + * error + * + * @return @mysql_error() + */ + public function error () + { + return @mysql_error( $this->link ); + } + + /** + * getTablesList + * + * @return $aRows + */ + public function getTablesList () + { + $this->result = @mysql_query( "SHOW TABLES;" ); + $aRows = Array (); + while ($aRow = mysql_fetch_row( $this->result )) { + array_push( $aRows, $aRow[0] ); + } + return $aRows; + } + + /** + * dumpData + * + * @param string $table + * + * @return boolean true or false + */ + function dumpData ($table) + { + $this->outfile = $this->tmpDir . $table . '.dump'; + + //if the file exists delete it + if (is_file( $this->outfile )) { + @unlink( $this->outfile ); + } + + $sql = "SELECT * INTO OUTFILE '{$this->outfile}' FIELDS TERMINATED BY '\t|\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\t\t\r\r\n' FROM $table"; + // The mysql_escape_string function has been DEPRECATED as of PHP 5.3.0. + // Commented that is not assigned to a variable. + // mysql_escape_string("';"); + if (! @mysql_query( $sql )) { + echo mysql_error() . "\n"; + return false; + } + return true; + } + + /** + * restoreData + * + * @param string $backupFile + * + * @return boolean true or false + */ + function restoreData ($backupFile) + { + $tableName = str_replace( '.dump', '', basename( $backupFile ) ); + $sql = "LOAD DATA INFILE '$backupFile' INTO TABLE $tableName FIELDS TERMINATED BY '\t|\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\t\t\r\r\n'"; + if (! @mysql_query( $sql )) { + print mysql_error() . "\n"; + return false; + } + return true; + } + + /** + * backupData + * + * @return boolean true or false + */ + function backupData () + { + $aTables = $this->getTablesList(); + foreach ($aTables as $table) { + if ($this->dumpData( $table ) !== false) { + printf( "%20s %s %s\n", 'Dump of table:', $table, " in file {$this->outfile}" ); + } else { + return false; + } + } + return true; + } + + /** + * backupSqlData + * + * @return boolean true or false + */ + function backupSqlData () + { + $aTables = $this->getTablesList(); + foreach ($aTables as $table) { + $fsize = $this->dumpSqlInserts( $table ); + $file = basename( $this->outfile ); + + } + + return true; + } + + /** + * restoreAllData + * + * @param string $type default value null + * + * @return none + */ + function restoreAllData ($type = null) + { + + $aTables = $this->getTablesList(); + + foreach ($aTables as $table) { + if (isset( $type ) && $type == 'sql') { + $this->infile = $this->tmpDir . $table . ".sql"; + if (is_file( $this->infile )) { + $queries = $this->restoreFromSql( $this->infile, true ); + if (! isset( $queries )) { + $queries = "unknown"; + } + printf( "%-59s%20s", "Restored table $table", "$queries queries\n" ); + } + } else { + $this->infile = $this->tmpDir . $table . ".dump"; + if (is_file( $this->infile )) { + $this->restoreData( $this->infile ); + printf( "%20s %s %s\n", 'Restoring data from ', $this->infile, " in table $table" ); + } + } + } + } + + /** + * createDb + * + * @param string $dbname + * @param string $drop default value false + * + * @return none + */ + function createDb ($dbname, $drop = false) + { + if ($drop) { + $sql = "DROP DATABASE IF EXISTS $dbname;"; + if (! @mysql_query( $sql )) { + throw new Exception( mysql_error() ); + } + } + $sql = "CREATE DATABASE IF NOT EXISTS $dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"; + if (! @mysql_query( $sql )) { + throw new Exception( mysql_error() ); + } + } + + /** + * restoreFromSql2 + * + * @param string $sqlfile + * + * @return none + */ + function restoreFromSql2 ($sqlfile) + { + + ini_set( 'memory_limit', '512M' ); + if (! is_file( $sqlfile )) { + throw new Exception( "the $sqlfile doesn't exist!" ); + } + $query = file_get_contents( $sqlfile ); + $mysqli = new mysqli( $this->host, $this->user, $this->passwd, $this->dbName ); + + /* check connection */ + if (mysqli_connect_errno()) { + printf( "Connect failed: %s\n", mysqli_connect_error() ); + exit(); + } + /* execute multi query */ - if( $mysqli->multi_query($query) ) { - do { - /* store first result set */ - if( $result = $mysqli->store_result() ) { - while( $row = $result->fetch_row() ) { - //printf("%s\n", $row[0]); - } - $result->free(); - } - /* print divider */ - if( $mysqli->more_results() ) { - //printf("-----------------\n"); - } - } while( $mysqli->next_result() ); - } else throw new Exception(mysqli_error($mysqli)); - + if ($mysqli->multi_query( $query )) { + do { + /* store first result set */ + if ($result = $mysqli->store_result()) { + while ($row = $result->fetch_row()) { + } + $result->free(); + } + + } while ($mysqli->next_result()); + } + /* close connection */ $mysqli->close(); - } catch(Exception $e){ - echo $query; - echo $e->getMessage(); - } } - return $queries; - } - -/** - * getSchemaFromTable - * - * @param string $tablename - * - * @return string $tableSchema - */ - function getSchemaFromTable($tablename) - { - //$tableSchema = "/* Structure for table `$tablename` */\n"; - //$tableSchema .= "DROP TABLE IF EXISTS `$tablename`;\n\n"; - $tableSchema = ""; - $sql = "show create table `$tablename`; "; - $result = @mysql_query($sql); - if( $result ) { - if( $row = mysql_fetch_assoc($result) ) { - $tableSchema .= $row['Create Table'] . ";\n\n"; - } - mysql_free_result($result); - } else - echo mysql_error(); - - return $tableSchema; - } - -/** - * removeCommentsIntoString - * - * @param string $str - * - * @return string $str - */ - function removeCommentsIntoString($str) - { - $str = preg_replace('/\/\*[\w\W]*\*\//', '', $str); - $str = preg_replace("/--[\w\W]*\\n/", '', $str); - $str = preg_replace("/\/\/[\w\W]*\\n/", '', $str); - $str = preg_replace("/\#[\w\W]*\\n/", '', $str); - return $str; - } + + function lockTables () + { + $aTables = $this->getTablesList(); + if (empty( $aTables )) + return false; + printf( "%-70s", "LOCK TABLES" ); + if (@mysql_query( "LOCK TABLES " . implode( " READ, ", $aTables ) . " READ; " )) { + echo " [OK]\n"; + return true; + } else { + echo "[FAILED]\n" . mysql_error() . "\n"; + return false; + } + } + + function unlockTables () + { + printf( "%-70s", "UNLOCK TABLES" ); + if (@mysql_query( "UNLOCK TABLES;" )) { + echo " [OK]\n"; + } else { + echo "[FAILED]\n" . mysql_error() . "\n"; + } + } + + /** + * dumpSqlInserts + * + * @param string $table + * + * @return integer $bytesSaved; + */ + function dumpSqlInserts ($table) + { + + $bytesSaved = 0; + $result = @mysql_query( "SELECT * FROM `$table`" ); + + $num_rows = mysql_num_rows( $result ); + $num_fields = mysql_num_fields( $result ); + + $data = ""; + for ($i = 0; $i < $num_rows; $i ++) { + + $row = mysql_fetch_object( $result ); + $data .= "INSERT INTO `$table` VALUES ("; + + for ($x = 0; $x < $num_fields; $x ++) { + $field_name = mysql_field_name( $result, $x ); + + $data .= ($row->$field_name === null) ? 'NULL' : "'" . mysql_real_escape_string( $row->$field_name ) . "'"; + $data .= ($x < ($num_fields - 1)) ? ", " : false; + } + + $data .= ");\n"; + } + + printf( "%-59s%20s", "Dump of table $table", strlen( $data ) . " Bytes Saved\n" ); + return $data; + } + + /** + * backupDataBaseSchema + * + * @param string $outfile + * + * @return none + */ + function backupDataBase ($outfile) + { + $aTables = $this->getTablesList(); + $ws = explode( '_', $this->dbName ); + $ws = isset( $ws[1] ) ? $ws[1] : $this->dbName; + $schema = "\n"; + $schema .= " -- Processmaker Data Base Maintenance Tool\n"; + $schema .= " --\n"; + $schema .= " -- Workspace: " . $ws . "\n"; + $schema .= " -- Data Base: " . $this->dbName . "\n"; + $schema .= " -- Tables: " . (count( $aTables )) . "\n"; + $schema .= " -- Date: " . (date( 'l jS \of F Y h:i:s A' )) . "\n"; + $schema .= " --\n\n"; + + $file = fopen( $outfile, "w+" ); + + fwrite( $file, $schema ); + + foreach ($aTables as $table) { + $tableSchema = "\nDROP TABLE IF EXISTS `$table`;\n\n"; + $tableSchema .= $this->getSchemaFromTable( $table ); + $data = $this->dumpSqlInserts( $table ); + fwrite( $file, $tableSchema ); + fwrite( $file, $data ); + } + + fclose( $file ); + } + + /** + * restoreFromSql + * + * @param string $sqlfile + * + * @return boolean false or true + */ + function restoreFromSql ($sqlfile, $type = 'file') + { + ini_set( 'memory_limit', '64M' ); + if ($type == 'file' && ! is_file( $sqlfile )) { + throw new Exception( "the $sqlfile doesn't exist!" ); + } + + $metaFile = str_replace( '.sql', '.meta', $sqlfile ); + + $queries = 0; + + if (is_file( $metaFile )) { + echo "Using $metaFile as metadata.\n"; + $fp = fopen( $sqlfile, 'rb' ); + $fpmd = fopen( $metaFile, 'r' ); + while ($offset = fgets( $fpmd, 1024 )) { + $buffer = intval( $offset ); //reading the size of $oData + $query = fread( $fp, $buffer ); //reading string $oData + $queries += 1; + + if (! @mysql_query( $query )) { + echo mysql_error() . "\n"; + echo "==>" . $query . "<==\n"; + } + } + + } else { + $queries = null; + try { + $mysqli = new mysqli( $this->host, $this->user, $this->passwd, $this->dbName ); + /* check connection */ + if (mysqli_connect_errno()) { + printf( "Connect failed: %s\n", mysqli_connect_error() ); + exit(); + } + if ($type == 'file') { + $query = file_get_contents( $sqlfile ); + } else if ($type == 'string') { + $query = $sqlfile; + } else { + return false; + } + + if (trim( $query ) == "") { + return false; + } + + /* execute multi query */ + if ($mysqli->multi_query( $query )) { + do { + /* store first result set */ + if ($result = $mysqli->store_result()) { + while ($row = $result->fetch_row()) { + //printf("%s\n", $row[0]); + } + $result->free(); + } + /* print divider */ + if ($mysqli->more_results()) { + //printf("-----------------\n"); + } + } while ($mysqli->next_result()); + } else { + throw new Exception( mysqli_error( $mysqli ) ); + } + + /* close connection */ + $mysqli->close(); + } catch (Exception $e) { + echo $query; + echo $e->getMessage(); + } + } + return $queries; + } + + /** + * getSchemaFromTable + * + * @param string $tablename + * + * @return string $tableSchema + */ + function getSchemaFromTable ($tablename) + { + //$tableSchema = "/* Structure for table `$tablename` */\n"; + //$tableSchema .= "DROP TABLE IF EXISTS `$tablename`;\n\n"; + $tableSchema = ""; + $sql = "show create table `$tablename`; "; + $result = @mysql_query( $sql ); + if ($result) { + if ($row = mysql_fetch_assoc( $result )) { + $tableSchema .= $row['Create Table'] . ";\n\n"; + } + mysql_free_result( $result ); + } else { + echo mysql_error(); + } + return $tableSchema; + } + + /** + * removeCommentsIntoString + * + * @param string $str + * + * @return string $str + */ + function removeCommentsIntoString ($str) + { + $str = preg_replace( '/\/\*[\w\W]*\*\//', '', $str ); + $str = preg_replace( "/--[\w\W]*\\n/", '', $str ); + $str = preg_replace( "/\/\/[\w\W]*\\n/", '', $str ); + $str = preg_replace( "/\#[\w\W]*\\n/", '', $str ); + return $str; + } } /* @@ -649,11 +659,3 @@ $o2->restoreFromSql('/home/erik/backs/schema_os.sql'); $o2->restoreAllData('sql'); */ - - - - - - - - diff --git a/gulliver/system/class.dbconnection.php b/gulliver/system/class.dbconnection.php index 50b374f93..68fc68894 100755 --- a/gulliver/system/class.dbconnection.php +++ b/gulliver/system/class.dbconnection.php @@ -1,295 +1,298 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ - -/** - * - * @package gulliver.system - * - */ - -require_once ("DB.php"); - -define( 'DB_ERROR_NO_SHOW_AND_CONTINUE', 0 ); -define( 'DB_ERROR_SHOW_AND_STOP', 1 ); -define( 'DB_ERROR_SHOW_AND_CONTINUE', 2 ); -define( 'DB_ERROR_SHOWALL_AND_STOP', 3 ); -define( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4 ); - -/** - * DBConnection class definition - * It is useful to stablish a connection - * - * @package gulliver.system - * @author Fernando Ontiveros Lira - * @copyright (C) 2002 by Colosa Development Team. - */ -class DBConnection -{ - var $db; - var $db_error; - var $errorLevel; - var $type; - - /** - * *************************************************************** - * /* Error types: - * /* -1 Fatal error ( clase no instanced ) - * /* -2 Syntax error ( session missing, query malformed, etc ) - * /* -3 warning ( when the engine build a dangerous query, i.e delete without where clause ) - * /* - * /* Error level: - * /* 0 don't display any error information and continue. - * /* 1 display small box with error information and die. - * /* 2 display small box with error information and continue - * /* 3 display complete error information and die. - * /* 4 display complete error information and continue. - * /* - * /* Error Structure - * /* int error code - * /* string error message - * /* string error detailed message - * /* - * /* In all cases, the error will be saved in the apache log file - * /* - * /* - */ - - /** - * Starts DB connection with default values - * - * @author Fernando Ontiveros Lira - * @access public - * @param const $strServer Host Name - * @param const $strUser User Name - * @param const $strPwd Password - * @param const $strDB Database Name - * @param string $type Connection Type - * @param integer $strPort Used Port - * @param string $errorLevel Error values posibles are: - * @return string - * - */ - function DBConnection ($strServer = DB_HOST, $strUser = DB_USER, $strPwd = DB_PASS, $strDB = DB_NAME, $type = DB_ADAPTER, $strPort = 0, $errorLevel = 2) - { - $this->errorLevel = $errorLevel; - if ($type == null) - $type = 'mysql'; - $this->type = $type; +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + +/** + * + * @package gulliver.system + * + */ + +require_once ("DB.php"); + +define( 'DB_ERROR_NO_SHOW_AND_CONTINUE', 0 ); +define( 'DB_ERROR_SHOW_AND_STOP', 1 ); +define( 'DB_ERROR_SHOW_AND_CONTINUE', 2 ); +define( 'DB_ERROR_SHOWALL_AND_STOP', 3 ); +define( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4 ); + +/** + * DBConnection class definition + * It is useful to stablish a connection + * + * @package gulliver.system + * @author Fernando Ontiveros Lira + * @copyright (C) 2002 by Colosa Development Team. + */ +class DBConnection +{ + var $db; + var $db_error; + var $errorLevel; + var $type; + + /** + * *************************************************************** + * /* Error types: + * /* -1 Fatal error ( clase no instanced ) + * /* -2 Syntax error ( session missing, query malformed, etc ) + * /* -3 warning ( when the engine build a dangerous query, i.e delete without where clause ) + * /* + * /* Error level: + * /* 0 don't display any error information and continue. + * /* 1 display small box with error information and die. + * /* 2 display small box with error information and continue + * /* 3 display complete error information and die. + * /* 4 display complete error information and continue. + * /* + * /* Error Structure + * /* int error code + * /* string error message + * /* string error detailed message + * /* + * /* In all cases, the error will be saved in the apache log file + * /* + * /* + */ + + /** + * Starts DB connection with default values + * + * @author Fernando Ontiveros Lira + * @access public + * @param const $strServer Host Name + * @param const $strUser User Name + * @param const $strPwd Password + * @param const $strDB Database Name + * @param string $type Connection Type + * @param integer $strPort Used Port + * @param string $errorLevel Error values posibles are: + * @return string + * + */ + function DBConnection ($strServer = DB_HOST, $strUser = DB_USER, $strPwd = DB_PASS, $strDB = DB_NAME, $type = DB_ADAPTER, $strPort = 0, $errorLevel = 2) + { + $this->errorLevel = $errorLevel; + if ($type == null) { + $type = 'mysql'; + } + $this->type = $type; //print "
$type $strServer, $strUser, $strPwd, $strDB
"; - if ($type == "mysql") - $dsn = "mysql://$strUser:$strPwd@$strServer/$strDB"; - if ($type == "pgsql") { + if ($type == "mysql") { + $dsn = "mysql://$strUser:$strPwd@$strServer/$strDB"; + } + if ($type == "pgsql") { //$dsn = "pgsql://postgres@$strServer/$strDB"; - $prt = ($strPort == 0 || $strPort == 5432 ? '' : ":$strPort"); - $dsn = "pgsql://$strUser:$strPwd@$strServer$prt/$strDB"; - } - if ($type == "odbc") - $dsn = "odbc://$strUser:$strPwd@$strServer/$strDB"; - if ($type == "mssql") { - $strServer = substr( $strServer, 0, strpos( $strServer, ':' ) ); - $prt = ($strPort == 0 || $strPort == 1433 ? '' : ":$strPort"); - $dsn = "mssql://$strUser:$strPwd@$strServer$prt/$strDB"; + $prt = ($strPort == 0 || $strPort == 5432 ? '' : ":$strPort"); + $dsn = "pgsql://$strUser:$strPwd@$strServer$prt/$strDB"; + } + if ($type == "odbc") { + $dsn = "odbc://$strUser:$strPwd@$strServer/$strDB"; + } + if ($type == "mssql") { + $strServer = substr( $strServer, 0, strpos( $strServer, ':' ) ); + $prt = ($strPort == 0 || $strPort == 1433 ? '' : ":$strPort"); + $dsn = "mssql://$strUser:$strPwd@$strServer$prt/$strDB"; ///--) $dsn = "mssql://$strUser:$strPwd@$strServer/$strDB"; - } - if ($type == "oracle") { - $dsn = "oci8://$strUser:$strPwd@$strServer/$strDB"; - } - $this->db_error = null; - if ($type === 'myxml') { - $this->db = XMLDB::connect( $strServer ); - } else { - $this->db = DB::connect( $dsn ); - } - if (DB::isError( $this->db )) { - $this->db_error = $this->db; - $this->db = null; - $this->logError( $this->db_error ); - } - } - - /** - * Close Connection and Generate Log Message - * - * @author Fernando Ontiveros Lira - * @access public - * @return void - */ - function Reset () - { - if ($this->db) { - $this->db->disconnect(); - } - $this->db = null; - } - - /** - * Disconnect from Data base - * - * @author Fernando Ontiveros Lira - * @access public - * @return void - */ - function Free () - { - $this->Reset(); - } - - /** - * Close Connection - * - * @author Fernando Ontiveros Lira - * @access public - * @return void - */ - function Close () - { - $this->Reset(); - } - - /** - * log Errors - * - * @author Fernando Ontiveros Lira - * @access public - * @param db_error $obj - * @param string $errorLevel - * @return void - */ - function logError ($obj, $errorLevel = NULL) - { - global $_SESSION; - global $_SERVER; - if (is_null( $errorLevel )) - if (isset( $this->errorLevel )) { - $errorLevel = $this->errorLevel; - } else { - $errorLevel = DB_ERROR_SHOWALL_AND_STOP; //for fatal errors the default is 3, show detailed and die. - } - - if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOW_AND_CONTINUE || $errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) { - print ""; - print ""; - if ($errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) { - print ""; - } - print "
" . $obj->code . ' ' . $obj->message . "
" . $obj->userinfo . "
"; - } - if (defined( 'DB_ERROR_BACKTRACE' ) && DB_ERROR_BACKTRACE) { - print "
"; - } + } + if ($type == "oracle") { + $dsn = "oci8://$strUser:$strPwd@$strServer/$strDB"; + } + $this->db_error = null; + if ($type === 'myxml') { + $this->db = XMLDB::connect( $strServer ); + } else { + $this->db = DB::connect( $dsn ); + } + if (DB::isError( $this->db )) { + $this->db_error = $this->db; + $this->db = null; + $this->logError( $this->db_error ); + } + } + + /** + * Close Connection and Generate Log Message + * + * @author Fernando Ontiveros Lira + * @access public + * @return void + */ + function Reset () + { + if ($this->db) { + $this->db->disconnect(); + } + $this->db = null; + } + + /** + * Disconnect from Data base + * + * @author Fernando Ontiveros Lira + * @access public + * @return void + */ + function Free () + { + $this->Reset(); + } + + /** + * Close Connection + * + * @author Fernando Ontiveros Lira + * @access public + * @return void + */ + function Close () + { + $this->Reset(); + } + + /** + * log Errors + * + * @author Fernando Ontiveros Lira + * @access public + * @param db_error $obj + * @param string $errorLevel + * @return void + */ + function logError ($obj, $errorLevel = null) + { + global $_SESSION; + global $_SERVER; + if (is_null( $errorLevel )) + if (isset( $this->errorLevel )) { + $errorLevel = $this->errorLevel; + } else { + $errorLevel = DB_ERROR_SHOWALL_AND_STOP; //for fatal errors the default is 3, show detailed and die. + } + + if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOW_AND_CONTINUE || $errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) { + print ""; + print ""; + if ($errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) { + print ""; + } + print "
" . $obj->code . ' ' . $obj->message . "
" . $obj->userinfo . "
"; + } + if (defined( 'DB_ERROR_BACKTRACE' ) && DB_ERROR_BACKTRACE) { + print "
"; + } //G::setErrorHandler ( ); - G::customErrorLog( 'DB_Error', $obj->code . ' ' . $obj->message . '-' . $obj->userinfo, '', '' ); - if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_STOP) { + G::customErrorLog( 'DB_Error', $obj->code . ' ' . $obj->message . '-' . $obj->userinfo, '', '' ); + if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_STOP) { die(); //stop - } - } - - /** - * Get the trace of the current execution (debug_backtrace). - * - * @author David Callizaya - * @param string $tts - * @param string $limit - * @return string - */ - function traceError ($tts = 2, $limit = -1) - { - $trace = debug_backtrace(); - $out = ''; - foreach ($trace as $step) { - if ($tts > 0) { - $tts --; - } else { - $out .= '[' . basename( $step['file'] ) . ': ' . $step['line'] . '] : ' . $step['function'] . '(' . DBConnection::printArgs( $step['args'] ) . ")\n"; - $limit --; - if ($limit === 0) { - return $out; - } - } - } - return $out; - } - - /** - * Print the arguments of a function - * - * @author David Callizaya - * @param string $args - * @return string - */ - function printArgs ($args) - { - $out = ''; - if (is_array( $args )) { - foreach ($args as $arg) { - if ($out !== '') { - $out .= ' ,'; - } - if (is_string( $arg )) { - $out .= "'" . ($arg) . "'"; - } elseif (is_array( $arg )) { - $out .= print_r( $arg, 1 ); - } elseif (is_object( $arg )) { + } + } + + /** + * Get the trace of the current execution (debug_backtrace). + * + * @author David Callizaya + * @param string $tts + * @param string $limit + * @return string + */ + function traceError ($tts = 2, $limit = -1) + { + $trace = debug_backtrace(); + $out = ''; + foreach ($trace as $step) { + if ($tts > 0) { + $tts --; + } else { + $out .= '[' . basename( $step['file'] ) . ': ' . $step['line'] . '] : ' . $step['function'] . '(' . DBConnection::printArgs( $step['args'] ) . ")\n"; + $limit --; + if ($limit === 0) { + return $out; + } + } + } + return $out; + } + + /** + * Print the arguments of a function + * + * @author David Callizaya + * @param string $args + * @return string + */ + function printArgs ($args) + { + $out = ''; + if (is_array( $args )) { + foreach ($args as $arg) { + if ($out !== '') { + $out .= ' ,'; + } + if (is_string( $arg )) { + $out .= "'" . ($arg) . "'"; + } elseif (is_array( $arg )) { + $out .= print_r( $arg, 1 ); + } elseif (is_object( $arg )) { $out .= get_class( $arg ); // print_r ( $arg ,1 ); - } elseif (! isset( $arg )) { - $out .= 'NULL'; - } else { - $out .= sprintf( "%s", $arg ); - } - } - } else { - if (! isset( $args )) { - $out = 'NULL'; - } else { - $out = print_r( $args, 1 ); - } - } - return $out; - } - - /** - * Gets last autoincrement value inserted - * - * @author Fernando Ontiveros Lira - * @access public - * @return void - */ - function GetLastID () - { - if (PEAR_DATABASE == "mysql") { - return mysql_insert_id(); - } else { - $dberror = PEAR::raiseError( null, DB_ERROR_FEATURE_NOT_AVAILABLE, null, 'null', "getLastID with " . PEAR_DATABASE . ' database.', 'G_Error', true ); + } elseif (! isset( $arg )) { + $out .= 'NULL'; + } else { + $out .= sprintf( "%s", $arg ); + } + } + } else { + if (! isset( $args )) { + $out = 'NULL'; + } else { + $out = print_r( $args, 1 ); + } + } + return $out; + } + + /** + * Gets last autoincrement value inserted + * + * @author Fernando Ontiveros Lira + * @access public + * @return void + */ + function GetLastID () + { + if (PEAR_DATABASE == "mysql") { + return mysql_insert_id(); + } else { + $dberror = PEAR::raiseError( null, DB_ERROR_FEATURE_NOT_AVAILABLE, null, 'null', "getLastID with " . PEAR_DATABASE . ' database.', 'G_Error', true ); DBconnection::logError( $dberror, DB_ERROR_SHOWALL_AND_STOP ); //this error will stop the execution, until we add this feature!! - return $dberror; - } - return mysql_insert_id(); - } -} - + return $dberror; + } + return mysql_insert_id(); + } +} + diff --git a/gulliver/system/class.dbrecordset.php b/gulliver/system/class.dbrecordset.php index 7cf4ac14f..54a2d459a 100755 --- a/gulliver/system/class.dbrecordset.php +++ b/gulliver/system/class.dbrecordset.php @@ -1,11 +1,13 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ - /** +/** * DBRecordset class definition * Provides access to a generalized table it assumes that the dbconnection object is already initialized for the table should be also provided in order to provide + * * @package gulliver.system * * @author Fernando Ontiveros Lira @@ -34,118 +37,116 @@ */ class DBRecordSet { - var $result = null; + var $result = null; - /** - * Starts connection to Database using default values - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $intResult Database recordset default value = false - * @return void - */ - function DBRecordSet( $intResult = null ) - { - $this->SetTo( $intResult ); - } - - /** - * Set conecction to Database - * - * @author Fernando Ontiveros Lira - * @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. - * @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. - * @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. - * @access public - * @return string - */ - function Read() - { - if ( $this->result === null ) { - $dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', - "You tried to call to a DBRecordset with an invalid result recordset.", - 'G_Error', true); - DBconnection::logError( $dberror ); - } - $res = $this->result->fetchRow(DB_FETCHMODE_ASSOC); - //for Pgsql databases, - //if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); } - - /* Comment Code: This block is not required now because - * of the the use of the G::sqlEscape() instead of addslashes - * funcion over each field in DBTable. - * @author David Callizaya + /** + * Starts connection to Database using default values + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $intResult Database recordset default value = false + * @return void */ - /*if (is_array ($res) ) - foreach ($res as $key => $val) + function DBRecordSet ($intResult = null) + { + $this->SetTo( $intResult ); + } + + /** + * Set conecction to Database + * + * @author Fernando Ontiveros Lira + * @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. + * @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. + * @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. + * @access public + * @return string + */ + function Read () + { + if ($this->result === null) { + $dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', "You tried to call to a DBRecordset with an invalid result recordset.", 'G_Error', true ); + DBconnection::logError( $dberror ); + } + $res = $this->result->fetchRow( DB_FETCHMODE_ASSOC ); + //for Pgsql databases, + //if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); } + + + /* Comment Code: This block is not required now because + * of the the use of the G::sqlEscape() instead of addslashes + * funcion over each field in DBTable. + * @author David Callizaya + */ + /*if (is_array ($res) ) + foreach ($res as $key => $val) $res[$key] = stripslashes ($val); remove the slashes*/ - - return $res; - } - - /** - * Function ReadAbsolute - * @author David S. Callizaya S. - * @access public - * @return string - */ - function ReadAbsolute() - { - $res = $this->result->fetchRow(DB_FETCHMODE_ORDERED); - //for Pgsql databases, - //if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); } - return $res; - } -} \ No newline at end of file + + return $res; + } + + /** + * Function ReadAbsolute + * + * @author David S. Callizaya S. + * @access public + * @return string + */ + function ReadAbsolute () + { + $res = $this->result->fetchRow( DB_FETCHMODE_ORDERED ); + //for Pgsql databases, + //if ( PEAR_DATABASE == "pgsql" && is_array ( $res ) ) { $res = array_change_key_case( $res, CASE_UPPER); } + return $res; + } +} + diff --git a/gulliver/system/class.dbsession.php b/gulliver/system/class.dbsession.php index 04b67f9d7..34d1ef1e8 100755 --- a/gulliver/system/class.dbsession.php +++ b/gulliver/system/class.dbsession.php @@ -1,11 +1,13 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ - /** +/** * DBSession class definition * It is useful to stablish a database connection using an specific database + * * @package gulliver.system * @author Fernando Ontiveros Lira * @copyright (C) 2002 by Colosa Development Team. @@ -34,146 +37,151 @@ */ class DBSession { - var $dbc = NULL; - var $dbname = ''; - var $result = false; + var $dbc = null; + var $dbname = ''; + var $result = false; - /** - * Starts a session using a connection with an specific database - * @author Fernando Ontiveros Lira - * - * @access public - * @param object $objConnection - * @param string $strDBName - * @return void - * - */ - function DBSession( $objConnection = NULL, $strDBName = '' ) - { - if ($strDBName!='') $strDBName = $objConnection->db->_db; - $this->setTo( $objConnection, $strDBName ); - } - - - /** - * It's like a constructor - * @author Fernando Ontiveros Lira - * - * @access public - * @param object $objConnection - * @param string $strDBName - * @return void - * - */ - function setTo( $objConnection = NULL, $strDBName = DB_NAME ) - { - if ( $objConnection != NULL ) + /** + * Starts a session using a connection with an specific database + * + * @author Fernando Ontiveros Lira + * + * @access public + * @param object $objConnection + * @param string $strDBName + * @return void + * + */ + function DBSession ($objConnection = null, $strDBName = '') { - $this->Free(); - $this->dbc = $objConnection; - $this->dbname = $strDBName; - - //enable utf8 in mysql databases - if ( $this->dbc->db->phptype == 'mysql' ) { //utf-8 - $this->dbc->db->query ( "SET NAMES 'utf8'; " ); - } - } - } - - - /** - * UseDB stablish a database for the connection - * @author Fernando Ontiveros Lira - * - * @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 . "
\n" ); - } - $this->result = $this->dbc->db->query ( $strQuery ); - if (DB::isError ($this->result)) { - $this->dbc->logError( $this->result, $errorLevel ); - return $this->result; - } - $dset = new DBRecordSet( $this->result ); - return $dset; - } - - /** - * Function Query, just to execute the query. - * @access public - * @parameter string strQuery - * @parameter string debug - * @parameter string error - * @return string - */ -/* function deprecated... by Onti, 30th july 2007 - function Query( $strQuery = '', $debug = false, $error = '' ) - { - if ( $error == '' && defined('ERROR_STATE') ) { - $error = ERROR_STATE; + if ($strDBName != '') { + $strDBName = $objConnection->db->_db; + } + $this->setTo( $objConnection, $strDBName ); } - if ( !defined('ERROR_STATE') ) $error = 4; + /** + * It's like a constructor + * + * @author Fernando Ontiveros Lira + * + * @access public + * @param object $objConnection + * @param string $strDBName + * @return void + * + */ + function setTo ($objConnection = null, $strDBName = DB_NAME) + { + if ($objConnection != null) { + $this->Free(); + $this->dbc = $objConnection; + $this->dbname = $strDBName; - if( $debug ) { - print( $strQuery . "
\n" ); + //enable utf8 in mysql databases + if ($this->dbc->db->phptype == 'mysql') { //utf-8 + $this->dbc->db->query( "SET NAMES 'utf8'; " ); + } + } } - - $this->Free( true ); - $this->result = $this->dbc->db->query ( $strQuery ); - - if (DB::isError ($this->result)) { - $this->dbc->ShowLogError( $this->result->getMessage() , $this->result->userinfo, $error); - die; + /** + * UseDB stablish a database for the connection + * + * @author Fernando Ontiveros Lira + * + * @access public + * @param string $strDBName + * @return void + * + */ + function UseDB ($strDBName = DB_NAME) + { + $this->dbname = $strDBName; } - return; - } - */ - - /** - * Function Free - * @access public - * @parameter string debug - * @return string - */ - function Free( $debug = false ) - { - if ( is_resource($this->result) ) - $this->result->Free(); - return; - } + /** + * Function Execute, to execute a query and send back the recordset. + * + * @access public + * @param eter string strQuery + * @param eter string debug + * @param eter string error + * @return string + */ + function Execute ($strQuery = '', $debug = false, $errorLevel = null) + { + //BUG::traceRoute(); + if ($this->dbc == null) { + $dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', 'You have tried to call a DBSession function without create an instance of DBConnection', 'G_Error', true ); + DBconnection::logError( $dberror, $errorLevel ); + return $dberror; + } + ; + + if ($errorLevel === null) { + $errorLevel = $this->dbc->errorLevel; + } + $this->Free( true ); + + if ($debug) { + print ($strQuery . "
\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 . "
\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; + } } diff --git a/gulliver/system/class.dbtable.php b/gulliver/system/class.dbtable.php index 272013480..38a63dcd2 100755 --- a/gulliver/system/class.dbtable.php +++ b/gulliver/system/class.dbtable.php @@ -1,6 +1,8 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -29,6 +31,7 @@ * This class provides acces to a generalized table * it assumes that the dbconnection object is already initialized, the table name, as well as the primary keys * for the table should be also provided in order to provide the class a way to generate an UPDATE query properly. + * * @package gulliver.system * @author Fernando Ontiveros Lira * @copyright (C) 2002 by Colosa Development Team. @@ -36,393 +39,391 @@ */ class DBTable { - var $_dbc; - var $_dbses; - var $_dset; - var $table_name; - var $table_keys; - var $Fields = null; - var $is_new; - var $errorLevel; - var $debug = false; + var $_dbc; + var $_dbses; + var $_dset; + var $table_name; + var $table_keys; + var $Fields = null; + var $is_new; + var $errorLevel; + var $debug = false; -/** - * Initiate a database conecction using default values - * - * @author Fernando Ontiveros Lira - * @access public - * @param object $objConnection conecction string - * @return void - */ - function dBTable( $objConnection = NULL, $strTable = "", $arrKeys = array( 'UID' ) ) - { - $this->_dbc = NULL; - $this->_dbses = NULL; - $this->SetTo( $objConnection, $strTable, $arrKeys ); - } - - - /** - * Initiate a database conecction using default values - * - * @author Fernando Ontiveros Lira - * @access public - * @param object $objDBConnection conecction string - * @param string $strTable Table name defaultvalue='' - * @param array $arrKeys table keys defaultvalue=UID - * @return void - */ - function setTo( $objDBConnection, $strTable = "", $arrKeys = array( 'UID' ) ) - { - - $this->_dbc = $objDBConnection; - if( $this->_dbc != NULL && strcasecmp( get_class( $objDBConnection ) , 'dbconnection' ) == 0 ) + /** + * Initiate a database conecction using default values + * + * @author Fernando Ontiveros Lira + * @access public + * @param object $objConnection conecction string + * @return void + */ + function dBTable ($objConnection = null, $strTable = "", $arrKeys = array( 'UID' )) { - $this->_dbses = new DBSession( $this->_dbc ); - $this->_dbses->UseDB( DB_NAME ); + $this->_dbc = null; + $this->_dbses = null; + $this->SetTo( $objConnection, $strTable, $arrKeys ); } - else { - $dberror = PEAR::raiseError(null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', - "You tried to call to a DBTable function without create an instance of DBConnection", - 'G_Error', true); - //DBconnection::logError( $dberror ); - return $dberror; - } - $this->is_new = true; - $this->Fields = NULL; - $this->table_name = $strTable; - if ( is_array ( $arrKeys ) ) - $this->table_keys = $arrKeys; - else - $this->table_keys = array ( 0 => $arrKeys ); - $this->errorLevel = $this->_dbc->errorLevel; - } -/** - * Loads full description of a referenced table in Fields - * - * @author Fernando Ontiveros Lira - * @access public - * @return void - */ - function loadEmpty() - { - $stQry = "DESCRIBE `" . $this->table_name. "`"; - $dset = $this->_dbses->execute( $stQry ); - //$dset = new DBRecordSet( $this->_dbses->Result ); - $nlim = $dset->Count(); - $this->Fields = NULL; - for( $ncount = 0; $ncount < $nlim; $ncount++ ) + /** + * Initiate a database conecction using default values + * + * @author Fernando Ontiveros Lira + * @access public + * @param object $objDBConnection conecction string + * @param string $strTable Table name defaultvalue='' + * @param array $arrKeys table keys defaultvalue=UID + * @return void + */ + function setTo ($objDBConnection, $strTable = "", $arrKeys = array( 'UID' )) { - $data = $dset->Read(); - $fname = $data['Field']; - $fval = ""; - $ftypearr = explode($data['Type'], '(' ); - $ftype = $ftypearr[0]; - if( $data['Key'] == 'PRI' ) - { - if( is_array($this->table_keys) ) - { - $this->table_keys[count( $this->table_keys ) - 1] = $fname; + $this->_dbc = $objDBConnection; + if ($this->_dbc != null && strcasecmp( get_class( $objDBConnection ), 'dbconnection' ) == 0) { + $this->_dbses = new DBSession( $this->_dbc ); + $this->_dbses->UseDB( DB_NAME ); + } else { + $dberror = PEAR::raiseError( null, DB_ERROR_OBJECT_NOT_DEFINED, null, 'null', "You tried to call to a DBTable function without create an instance of DBConnection", 'G_Error', true ); + //DBconnection::logError( $dberror ); + return $dberror; } - else - { - $this->table_keys[0] = $fname; + $this->is_new = true; + $this->Fields = null; + $this->table_name = $strTable; + if (is_array( $arrKeys )) { + $this->table_keys = $arrKeys; + } else { + $this->table_keys = array (0 => $arrKeys + ); } - } - - switch( $ftype ) - { - case 'int': - case 'smallint': - case 'tinyint': - case 'decimal': - case 'numeric': - case 'double': - case 'float': - $fval = 0; - break; - } - - $this->Fields[ $fname ] = $fval; - $this->Fields[ $ncount ] = &$this->Fields[ $fname ]; - } - } - -/** - * Return specified field on the referenced table - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $strWhere string which contains conditions - * @return strint - */ - function loadWhere( $strWhere ) - { - $this->Fields = NULL; - - $stQry = "SELECT * FROM `" . $this->table_name . "`"; - if( $strWhere != "" ) $stQry .= " WHERE " . $strWhere; - - $this->_dset = $this->_dbses->Execute ( $stQry , $this->debug, $this->errorLevel); - if (DB::isError ($this->_dset)) { - return $this->_dset; + $this->errorLevel = $this->_dbc->errorLevel; } - if( $this->_dset->Count() > 0 ){ - $this->Fields = $this->_dset->Read(); - $this->is_new = false; - } - else + /** + * Loads full description of a referenced table in Fields + * + * @author Fernando Ontiveros Lira + * @access public + * @return void + */ + function loadEmpty () { - $this->Fields = NULL; - $this->is_new = true; - } + $stQry = "DESCRIBE `" . $this->table_name . "`"; + $dset = $this->_dbses->execute( $stQry ); + //$dset = new DBRecordSet( $this->_dbses->Result ); + $nlim = $dset->Count(); + $this->Fields = null; + for ($ncount = 0; $ncount < $nlim; $ncount ++) { + $data = $dset->Read(); + $fname = $data['Field']; + $fval = ""; + $ftypearr = explode( $data['Type'], '(' ); + $ftype = $ftypearr[0]; - return $this->Fields; - } - -/** - * Return all fields on the referenced table - * - * @author Fernando Ontiveros Lira - * @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. - * @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 - * @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 - * @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 - * @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 - * @access public - * @return boolean - */ - function delete() - { - $stQry = "delete from `" . $this->table_name . "` "; - - $stWhere = ''; - $remainKeys = array(); - if(defined('DB_ADAPTER')) - $DBEngine = DB_ADAPTER; - else - $DBEngine = 'mysql'; - foreach ( $this->table_keys as $k => $v ) $remainKeys[ $v ] = false; - - if ( is_array ( $this->Fields ) ) { - foreach( $this->Fields as $field => $val ) - { - $iskey = false; - $iskey = in_array( $field, $this->table_keys ); - if( $iskey == true ) { - if( $stWhere == "" ) { - $stWhere .= $field . "='" . G::sqlEscape ( $val, isset( $this->_dbc->type) ? $this->_dbc->type : $DBEngine ) . "'"; + if ($data['Key'] == 'PRI') { + if (is_array( $this->table_keys )) { + $this->table_keys[count( $this->table_keys ) - 1] = $fname; + } else { + $this->table_keys[0] = $fname; + } } - else { - $stWhere .= " AND " . $field . "='" . G::sqlEscape ( $val, isset( $this->_dbc->type) ? $this->_dbc->type : $DBEngine ) . "'"; + + switch ($ftype) { + case 'int': + case 'smallint': + case 'tinyint': + case 'decimal': + case 'numeric': + case 'double': + case 'float': + $fval = 0; + break; } - $remainKeys[ $field ] = true; - } - } + + $this->Fields[$fname] = $fval; + $this->Fields[$ncount] = &$this->Fields[$fname]; + } } - foreach( $remainKeys as $field => $bool ) - if ( $bool == false) { - if( $stWhere != "" ) $stWhere .= " AND "; - $stWhere .= $field . "= ''"; - $remainKeys[ $field ] = true; - } - $stQry = trim( $stQry ); - $stWhere = trim( $stWhere ); - if ( $stWhere == '' ) { - $dberror = PEAR::raiseError(null, G_ERROR_WARNING_MESSAGE, null, 'null', - "You tried to call delete method without WHERE clause, if you want to delete all records use dbsession", - 'G_Error', true); - DBconnection::logError( $dberror, $this->errorLevel ); - return $dberror; + /** + * Return specified field on the referenced table + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $strWhere string which contains conditions + * @return strint + */ + function loadWhere ($strWhere) + { + $this->Fields = null; + + $stQry = "SELECT * FROM `" . $this->table_name . "`"; + if ($strWhere != "") { + $stQry .= " WHERE " . $strWhere; + } + $this->_dset = $this->_dbses->Execute( $stQry, $this->debug, $this->errorLevel ); + if (DB::isError( $this->_dset )) { + return $this->_dset; + } + + if ($this->_dset->Count() > 0) { + $this->Fields = $this->_dset->Read(); + $this->is_new = false; + } else { + $this->Fields = null; + $this->is_new = true; + } + + return $this->Fields; } - $stQry .= " WHERE " . $stWhere; - $result = $this->_dbses->execute( $stQry , $this->debug, $this->errorLevel ); - $this->is_new = false; - return $result; - } + /** + * Return all fields on the referenced table + * + * @author Fernando Ontiveros Lira + * @access public + * @param array array of arguments key values + * @return void + */ + function load () + { + // bug::traceRoute(); + $ncount = 0; + $stWhere = ""; + $arrKeys = func_get_args(); + if (isset( $arrKeys[0] ) && is_array( $arrKeys[0] )) { + foreach ($this->table_keys as $key => $val) { + if ($stWhere == "") { + $stWhere .= " $val = '" . $arrKeys[0][$val] . "' "; + } else { + $stWhere .= " AND $val = '" . $arrKeys[0][$val] . "' "; + } + } + } else { + foreach ($arrKeys as $val) { + if ($stWhere == "") { + $stWhere .= $this->table_keys[$ncount] . "='" . $val . "'"; + } else { + $stWhere .= " AND " . $this->table_keys[$ncount] . "='" . $val . "'"; + } + $ncount ++; + } + } + return $this->LoadWhere( $stWhere ); + } - /** - * Move to next record in a recordset - * - * Move to next record in a recordset, this is useful where the load method have a recordset with many rows - * - * @author Fernando Ontiveros Lira - * @access public - * @return boolean - */ - function next() - { - $this->Fields = $this->_dset->read (); - } + /** + * Function nextvalPGSql + * + * @author David S. Callizaya S. + * @access public + * @param eter string seq + * @return string + */ + function nextvalPGSql ($seq) + { + $stQry = " Select NEXTVAL( '$seq' ) "; + $dset = $this->_dbses->Execute( $stQry ); + $row = $dset->Read(); + if (is_array( $row )) { + return $row['NEXTVAL']; + } + die( "Sequence '$seq' is not exist!!" ); + return - 1; + } + + /** + * Insert a new row + * + * @author Fernando Ontiveros Lira + * @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 + * @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 + * @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 + * @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 + * @access public + * @return boolean + */ + function next () + { + $this->Fields = $this->_dset->read(); + } } + diff --git a/gulliver/system/class.httpProxyController.php b/gulliver/system/class.httpProxyController.php index 33cc5ab4c..3d319d4c7 100755 --- a/gulliver/system/class.httpProxyController.php +++ b/gulliver/system/class.httpProxyController.php @@ -1,46 +1,53 @@ * @package gulliver.system * @access private */ -class HttpProxyController { - - +class HttpProxyController +{ + /** + * * @var array - private array to store proxy data */ - private $__data__ = array(); - + private $__data__ = array (); + /** - * @var object - private object to store the http request data + * + * @var object - private object to store the http request data */ private $__request__; public $jsonResponse = true; - + private $sendResponse = true; + /** * Magic setter method - * + * * @param string $name * @param string $value */ - public function __set($name, $value) { + public function __set ($name, $value) + { //echo "Setting '$name' to '$value'\n"; $this->__data__[$name] = $value; } /** * Magic getter method - * + * * @param string $name * @return string or NULL if the internal var doesn't exist */ - public function __get($name) { + public function __get ($name) + { //echo "Getting '$name'\n"; - if (array_key_exists($name, $this->__data__)) { + if (array_key_exists( $name, $this->__data__ )) { return $this->__data__[$name]; } @@ -55,89 +62,102 @@ class HttpProxyController { /** * Magic isset method - * + * * @param string $name */ - public function __isset($name) { + public function __isset ($name) + { //echo "Is '$name' set?\n"; - return isset($this->__data__[$name]); + return isset( $this->__data__[$name] ); } - /** * Magic unset method - * + * * @param string $name */ - public function __unset($name) { + public function __unset ($name) + { //echo "Unsetting '$name'\n"; - unset($this->__data__[$name]); + unset( $this->__data__[$name] ); } - + /** * call to execute a internal proxy method and handle its exceptions - * + * * @param string $name */ - public function call($name) + public function call ($name) { try { - $result = $this->$name($this->__request__); + $result = $this->$name( $this->__request__ ); - if (!$this->jsonResponse) { + if (! $this->jsonResponse) { return null; } - - if( ! $result ) - $result = $this->__data__; - + + if (! $result) { + $result = $this->__data__; + } + } catch (Exception $e) { $result->success = false; $result->message = $result->msg = $e->getMessage(); - switch(get_class($e)) { - case 'Exception': $error = "SYSTEM ERROR"; break; - case 'PMException': $error = "PROCESSMAKER ERROR"; break; - case 'PropelException': $error = "DATABASE ERROR"; break; - case 'UserException': $error = "USER ERROR"; break; + switch (get_class( $e )) { + case 'Exception': + $error = "SYSTEM ERROR"; + break; + case 'PMException': + $error = "PROCESSMAKER ERROR"; + break; + case 'PropelException': + $error = "DATABASE ERROR"; + break; + case 'UserException': + $error = "USER ERROR"; + break; } $result->error = $e->getMessage(); - - $result->exception->class = get_class($e); + + $result->exception->class = get_class( $e ); $result->exception->code = $e->getCode(); $result->exception->trace = $e->getTraceAsString(); } if ($this->sendResponse) { - print G::json_encode($result); + print G::json_encode( $result ); } } - + /** * Set the http request data - * + * * @param array $data */ - public function setHttpRequestData($data) + public function setHttpRequestData ($data) { - if( is_array($data) ) { - while( $var = each($data) ) - $this->__request__->$var['key'] = $var['value']; - } else + if (is_array( $data )) { + while ($var = each( $data )) { + $this->__request__->$var['key'] = $var['value']; + } + } else { $this->__request__ = $data; + } } - public function setJsonResponse($bool) + public function setJsonResponse ($bool) { $this->jsonResponse = $bool; } /** * Send response to client - * + * * @param boolean $val */ - public function setSendResponse($val) + public function setSendResponse ($val) { $this->sendResponse = $val; } } + diff --git a/gulliver/system/class.i18n_po.php b/gulliver/system/class.i18n_po.php index 225bdc79c..8309f0b92 100755 --- a/gulliver/system/class.i18n_po.php +++ b/gulliver/system/class.i18n_po.php @@ -1,7 +1,9 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. * */ - - /** - * i18n_PO + +/** + * i18n_PO * This class build biggers PO files without size limit and this not use much memory that the allowed - * + * * @package gulliver.system * @author Erik Amaru Ortiz * date Aug 31th, 2010 * @copyright (C) 2002 by Colosa Development Team. */ - + class i18n_PO { - private $_file = NULL; - private $_string = ''; - private $_meta; - private $_fp; - private $_fileComments; - - protected $_editingHeader; - protected $_fileLine; - - protected $flagEndHeaders; - protected $flagError; - protected $flagInit; - protected $lineNumber; - - public $translatorComments; - public $extractedComments; - public $references; - public $flags; - public $previousUntranslatedStrings; - - function __construct($file) - { - $this->file = $file; - } - - function buildInit() - { - $this->_fp = fopen($this->file, 'w'); - - if ( ! is_resource($this->_fp) ) { - throw new Exception('Could\'t open ' . $this->file . ' file'); - } - - // lock PO file exclusively - if ( ! flock($this->_fp, LOCK_EX) ) { - fclose($this->_fp); - return FALSE; - } - - $this->_meta = 'msgid ""'; - $this->_writeLine($this->_meta); - $this->_meta = 'msgstr ""'; - $this->_writeLine($this->_meta); - - $this->_editingHeader = TRUE; - } + private $_file = null; + private $_string = ''; + private $_meta; + private $_fp; + private $_fileComments; - function readInit(){ - $this->_fp = fopen($this->file, 'r'); - - if ( ! is_resource($this->_fp) ) { - throw new Exception('Could\'t open ' . $this->file . ' file'); - } - //skipping comments - $this->skipCommets(); - //deaing headers - $this->readHeaders(); - - $this->translatorComments = Array(); - $this->extractedComments = Array(); - $this->references = Array(); - $this->flags = Array(); - $this->previousUntranslatedStrings = Array(); - } + protected $_editingHeader; + protected $_fileLine; - function addHeader($id, $value) - { - if( $this->_editingHeader ) { - $meta = '"'.trim($id).': '.trim($value).'\n"'; - $this->_writeLine($meta); - } - } - - function addTranslatorComment($str) - { - $this->headerStroke(); - $comment = '# ' . trim($str); - $this->_writeLine($comment); - } - - function addExtractedComment($str) - { - $this->headerStroke(); - $comment = '#. ' . trim($str); - $this->_writeLine($comment); - } - - function addReference($str) - { - $this->headerStroke(); - $reference = '#: ' . trim($str); - $this->_writeLine($reference); - } - - function addFlag($str) - { - $this->headerStroke(); - $flag = '#, ' . trim($str); - $this->_writeLine($flag); - } - - function addPreviousUntranslatedString($str) - { - $this->headerStroke(); - $str = '#| ' . trim($str); - $this->_writeLine($str); - } - - function addTranslation($msgid, $msgstr) - { - $this->headerStroke(); - $this->_writeLine('msgid "' . $this->prepare($msgid, true) . '"'); - $this->_writeLine('msgstr "' . $this->prepare($msgstr, true) . '"'); - $this->_writeLine(''); - } - - function _writeLine($str) - { - $this->_write($str . "\n"); - } - - function _write($str) - { - fwrite($this->_fp, $str); - } - - function prepare($string, $reverse = false) - { - //$string = str_replace('\"', '"', $string); - //$string = stripslashes($string); - - if ($reverse) { - $smap = array('"', "\n", "\t", "\r"); - $rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r'); - return (string) str_replace($smap, $rmap, $string); - } else { - $string = preg_replace('/"\s+"/', '', $string); - $smap = array('\\n', '\\r', '\\t', '\"'); - $rmap = array("\n", "\r", "\t", '"'); - return (string) str_replace($smap, $rmap, $string); - } - } - - function headerStroke() - { - if( $this->_editingHeader ) { - $this->_editingHeader = FALSE; - $this->_writeLine('');; - } - } - - /** read funtions **/ - private function skipCommets(){ - $this->_fileComments = ''; - do { - $lastPos = ftell($this->_fp); - $line = fgets($this->_fp); - $this->_fileComments .= $line; - } while( (substr($line, 0, 1) == '#' || trim($line) == '') && ! feof($this->_fp) ); - - fseek($this->_fp, $lastPos); - } + protected $flagEndHeaders; + protected $flagError; + protected $flagInit; + protected $lineNumber; - private function readHeaders() - { - $this->flagEndHeaders = false; - $this->flagError = false; - $this->flagInit = true; - $this->lineNumber = 0; - $errMsg = ''; - - while( ! $this->flagError && ! $this->flagEndHeaders ) { - - if( $this->flagInit ) { //in first instance - $this->flagInit = false; //unset init flag + public $translatorComments; + public $extractedComments; + public $references; + public $flags; + public $previousUntranslatedStrings; - //read the first and second line of the file - $firstLine = fgets($this->_fp); - $secondLine = fgets($this->_fp); + function __construct ($file) + { + $this->file = $file; + } - //verifying the file head - if( strpos($firstLine, 'msgid ""') === false || strpos($secondLine, 'msgstr ""') === false ){ - $this->flagError = true; - $errMsg = 'Misplace for firts msgid "" and msgstr "" in the header'; + function buildInit () + { + $this->_fp = fopen( $this->file, 'w' ); + + if (! is_resource( $this->_fp )) { + throw new Exception( 'Could\'t open ' . $this->file . ' file' ); } - continue; - } - - //getting the new line - $this->_fileLine = trim(fgets($this->_fp)); - //set line number - $this->lineNumber++; - //verifying that is not end of file and applying a restriction for to read just the twenty firsts lines - if( trim($this->_fileLine) == '' || ! $this->_fileLine || $this->lineNumber >= 20 ) { - $this->flagEndHeaders = true; // set ending to read the headers - continue; - } - //verify if has a valid mask header line - preg_match('/^"([a-z0-9\._-]+)\s*:\s*([\W\w]+)\\\n"$/i', $this->_fileLine, $match); + // lock PO file exclusively + if (! flock( $this->_fp, LOCK_EX )) { + fclose( $this->_fp ); + return false; + } - //for a valid header line the $match size should three - if( sizeof($match) == 3 ) { - $key = trim($match[1]); //getting the key of the header - $value = trim($match[2]); //getting the value of the header - $this->_meta[$key] = $value; //setting a new header - } else { - $this->flagEndHeaders = true; //otherwise set the ending to read the headers - break; - } - }//end looking for headeers - - //verifying the headers data - if( ! isset($this->_meta['X-Poedit-Language']) ) { - $this->flagError = true; - $errMsg = "X-Poedit-Language meta doesn't exist"; - } else if ( $this->_meta['X-Poedit-Language'] == '' ) { - $this->flagError = true; - $errMsg = "X-Poedit-Language meta is empty"; + $this->_meta = 'msgid ""'; + $this->_writeLine( $this->_meta ); + $this->_meta = 'msgstr ""'; + $this->_writeLine( $this->_meta ); + + $this->_editingHeader = true; } - //if the country is not present in metadata - if( ! isset($this->_meta['X-Poedit-Country']) ) { - $this->_meta['X-Poedit-Country'] = '.'; - } else if( $this->_meta['X-Poedit-Country'] == '' ) { - $this->_meta['X-Poedit-Country'] = '.'; + function readInit () + { + $this->_fp = fopen( $this->file, 'r' ); + + if (! is_resource( $this->_fp )) { + throw new Exception( 'Could\'t open ' . $this->file . ' file' ); + } + //skipping comments + $this->skipCommets(); + //deaing headers + $this->readHeaders(); + + $this->translatorComments = Array (); + $this->extractedComments = Array (); + $this->references = Array (); + $this->flags = Array (); + $this->previousUntranslatedStrings = Array (); } - - //thowing the exception if is necesary - if( $this->flagError ){ - throw new Exception("This file is not a valid PO file. ($errMsg)"); + + function addHeader ($id, $value) + { + if ($this->_editingHeader) { + $meta = '"' . trim( $id ) . ': ' . trim( $value ) . '\n"'; + $this->_writeLine( $meta ); + } } - } - function getHeaders() { - return $this->_meta; - } - - public function getTranslation(){ - - $flagReadingComments = true; - $this->translatorComments = Array(); - $this->extractedComments = Array(); - $this->references = Array(); - $this->flags = Array(); - - //getting the new line - while( $flagReadingComments && ! $this->flagError ) { - - $this->_fileLine = trim(fgets($this->_fp)); - //set line number - $this->lineNumber++; - - if( ! $this->_fileLine ) - return false; - - $prefix = substr($this->_fileLine, 0, 2); - - switch($prefix) { - case '# ': - $lineItem = str_replace('# ', '', $this->_fileLine); - $this->translatorComments[] = $lineItem; - break; - case '#.': - if( substr_count($this->_fileLine, '#. ') == 0 ) - $this->flagError = true; - else { - $lineItem = str_replace('#. ', '', $this->_fileLine); - $this->extractedComments[] = $lineItem; - } - break; - case '#:': - if( substr_count($this->_fileLine, '#: ') == 0 ) - $this->flagError = true; - else { - $lineItem = str_replace('#: ', '', $this->_fileLine); - $this->references[] = $lineItem; - } - break; - case '#,': - if( substr_count($this->_fileLine, '#, ') == 0 ) - $this->flagError = true; - else { - $lineItem = str_replace('#, ', '', $this->_fileLine); - $this->flags[] = $lineItem; - } - break; - case '#|': - if( substr_count($this->_fileLine, '#| ') == 0 ) - $this->flagError = true; - else { - $lineItem = str_replace('#| ', '', $this->_fileLine); - $this->previousUntranslatedStrings[] = $lineItem; - } - break; - default: - $flagReadingComments = false; - } + function addTranslatorComment ($str) + { + $this->headerStroke(); + $comment = '# ' . trim( $str ); + $this->_writeLine( $comment ); } - - if( ! $this->_fileLine ) - return false; - - //Getting the msgid - preg_match('/\s*msgid\s*"(.*)"\s*/s', $this->_fileLine, $match); - - if( sizeof($match) != 2 ) - throw new Exception('Invalid PO file format1'); - $msgid = ''; - - do { - //g::pr($match); - $msgid .= $match[1]; - $this->_fileLine = trim(fgets($this->_fp)); - preg_match('/^"(.*)"\s*/s', $this->_fileLine, $match); - } while ( sizeof($match) == 2 ); - - //Getting the msgstr - preg_match('/\s*msgstr\s*"(.*)"\s*/s', $this->_fileLine, $match); - - if( sizeof($match) != 2 ) - throw new Exception('Invalid PO file format2'); + function addExtractedComment ($str) + { + $this->headerStroke(); + $comment = '#. ' . trim( $str ); + $this->_writeLine( $comment ); + } - $msgstr = ''; - - do { - //g::pr($match); - $msgstr .= $match[1] . "\n"; - $this->_fileLine = trim(fgets($this->_fp)); - preg_match('/^"(.*)"\s*/s', $this->_fileLine, $match); - } while ( sizeof($match) == 2 ); - - - /*g::pr($this->translatorComments); - g::pr($this->references); - g::pr($match); - die;*/ - - return Array('msgid'=>trim($msgid), 'msgstr'=>trim($msgstr)); - } - - //garbage - function __destruct() - { - if ( $this->_fp ) - fclose($this->_fp); - } + function addReference ($str) + { + $this->headerStroke(); + $reference = '#: ' . trim( $str ); + $this->_writeLine( $reference ); + } + + function addFlag ($str) + { + $this->headerStroke(); + $flag = '#, ' . trim( $str ); + $this->_writeLine( $flag ); + } + + function addPreviousUntranslatedString ($str) + { + $this->headerStroke(); + $str = '#| ' . trim( $str ); + $this->_writeLine( $str ); + } + + function addTranslation ($msgid, $msgstr) + { + $this->headerStroke(); + $this->_writeLine( 'msgid "' . $this->prepare( $msgid, true ) . '"' ); + $this->_writeLine( 'msgstr "' . $this->prepare( $msgstr, true ) . '"' ); + $this->_writeLine( '' ); + } + + function _writeLine ($str) + { + $this->_write( $str . "\n" ); + } + + function _write ($str) + { + fwrite( $this->_fp, $str ); + } + + function prepare ($string, $reverse = false) + { + //$string = str_replace('\"', '"', $string); + //$string = stripslashes($string); + + + if ($reverse) { + $smap = array ('"',"\n","\t","\r" + ); + $rmap = array ('\"','\\n"' . "\n" . '"','\\t','\\r' + ); + return (string) str_replace( $smap, $rmap, $string ); + } else { + $string = preg_replace( '/"\s+"/', '', $string ); + $smap = array ('\\n','\\r','\\t','\"' + ); + $rmap = array ("\n","\r","\t",'"' + ); + return (string) str_replace( $smap, $rmap, $string ); + } + } + + function headerStroke () + { + if ($this->_editingHeader) { + $this->_editingHeader = false; + $this->_writeLine( '' ); + ; + } + } + + /** + * read funtions * + */ + private function skipCommets () + { + $this->_fileComments = ''; + do { + $lastPos = ftell( $this->_fp ); + $line = fgets( $this->_fp ); + $this->_fileComments .= $line; + } while ((substr( $line, 0, 1 ) == '#' || trim( $line ) == '') && ! feof( $this->_fp )); + + fseek( $this->_fp, $lastPos ); + } + + private function readHeaders () + { + $this->flagEndHeaders = false; + $this->flagError = false; + $this->flagInit = true; + $this->lineNumber = 0; + $errMsg = ''; + + while (! $this->flagError && ! $this->flagEndHeaders) { + + if ($this->flagInit) { //in first instance + $this->flagInit = false; //unset init flag + + + //read the first and second line of the file + $firstLine = fgets( $this->_fp ); + $secondLine = fgets( $this->_fp ); + + //verifying the file head + if (strpos( $firstLine, 'msgid ""' ) === false || strpos( $secondLine, 'msgstr ""' ) === false) { + $this->flagError = true; + $errMsg = 'Misplace for firts msgid "" and msgstr "" in the header'; + } + continue; + } + + //getting the new line + $this->_fileLine = trim( fgets( $this->_fp ) ); + //set line number + $this->lineNumber ++; + + //verifying that is not end of file and applying a restriction for to read just the twenty firsts lines + if (trim( $this->_fileLine ) == '' || ! $this->_fileLine || $this->lineNumber >= 20) { + $this->flagEndHeaders = true; // set ending to read the headers + continue; + } + //verify if has a valid mask header line + preg_match( '/^"([a-z0-9\._-]+)\s*:\s*([\W\w]+)\\\n"$/i', $this->_fileLine, $match ); + + //for a valid header line the $match size should three + if (sizeof( $match ) == 3) { + $key = trim( $match[1] ); //getting the key of the header + $value = trim( $match[2] ); //getting the value of the header + $this->_meta[$key] = $value; //setting a new header + } else { + $this->flagEndHeaders = true; //otherwise set the ending to read the headers + break; + } + } //end looking for headeers + + + //verifying the headers data + if (! isset( $this->_meta['X-Poedit-Language'] )) { + $this->flagError = true; + $errMsg = "X-Poedit-Language meta doesn't exist"; + } else if ($this->_meta['X-Poedit-Language'] == '') { + $this->flagError = true; + $errMsg = "X-Poedit-Language meta is empty"; + } + + //if the country is not present in metadata + if (! isset( $this->_meta['X-Poedit-Country'] )) { + $this->_meta['X-Poedit-Country'] = '.'; + } else if ($this->_meta['X-Poedit-Country'] == '') { + $this->_meta['X-Poedit-Country'] = '.'; + } + + //thowing the exception if is necesary + if ($this->flagError) { + throw new Exception( "This file is not a valid PO file. ($errMsg)" ); + } + } + + function getHeaders () + { + return $this->_meta; + } + + public function getTranslation () + { + + $flagReadingComments = true; + $this->translatorComments = Array (); + $this->extractedComments = Array (); + $this->references = Array (); + $this->flags = Array (); + + //getting the new line + while ($flagReadingComments && ! $this->flagError) { + + $this->_fileLine = trim( fgets( $this->_fp ) ); + //set line number + $this->lineNumber ++; + + if (! $this->_fileLine) { + return false; + } + + $prefix = substr( $this->_fileLine, 0, 2 ); + + switch ($prefix) { + case '# ': + $lineItem = str_replace( '# ', '', $this->_fileLine ); + $this->translatorComments[] = $lineItem; + break; + case '#.': + if (substr_count( $this->_fileLine, '#. ' ) == 0) { + $this->flagError = true; + } else { + $lineItem = str_replace( '#. ', '', $this->_fileLine ); + $this->extractedComments[] = $lineItem; + } + break; + case '#:': + if (substr_count( $this->_fileLine, '#: ' ) == 0) { + $this->flagError = true; + } else { + $lineItem = str_replace( '#: ', '', $this->_fileLine ); + $this->references[] = $lineItem; + } + break; + case '#,': + if (substr_count( $this->_fileLine, '#, ' ) == 0) { + $this->flagError = true; + } else { + $lineItem = str_replace( '#, ', '', $this->_fileLine ); + $this->flags[] = $lineItem; + } + break; + case '#|': + if (substr_count( $this->_fileLine, '#| ' ) == 0) { + $this->flagError = true; + } else { + $lineItem = str_replace( '#| ', '', $this->_fileLine ); + $this->previousUntranslatedStrings[] = $lineItem; + } + break; + default: + $flagReadingComments = false; + } + } + + if (! $this->_fileLine) { + return false; + } + + //Getting the msgid + preg_match( '/\s*msgid\s*"(.*)"\s*/s', $this->_fileLine, $match ); + + if (sizeof( $match ) != 2) { + throw new Exception( 'Invalid PO file format1' ); + } + + $msgid = ''; + + do { + //g::pr($match); + $msgid .= $match[1]; + $this->_fileLine = trim( fgets( $this->_fp ) ); + preg_match( '/^"(.*)"\s*/s', $this->_fileLine, $match ); + } while (sizeof( $match ) == 2); + + //Getting the msgstr + preg_match( '/\s*msgstr\s*"(.*)"\s*/s', $this->_fileLine, $match ); + + if (sizeof( $match ) != 2) { + throw new Exception( 'Invalid PO file format2' ); + } + + $msgstr = ''; + + do { + //g::pr($match); + $msgstr .= $match[1] . "\n"; + $this->_fileLine = trim( fgets( $this->_fp ) ); + preg_match( '/^"(.*)"\s*/s', $this->_fileLine, $match ); + } while (sizeof( $match ) == 2); + + /*g::pr($this->translatorComments); + g::pr($this->references); + g::pr($match); + die;*/ + + return Array ('msgid' => trim( $msgid ),'msgstr' => trim( $msgstr ) + ); + } + + //garbage + function __destruct () + { + if ($this->_fp) { + fclose( $this->_fp ); + } + } } + diff --git a/gulliver/system/class.mailer.php b/gulliver/system/class.mailer.php index 85fcff041..c2685a5ae 100755 --- a/gulliver/system/class.mailer.php +++ b/gulliver/system/class.mailer.php @@ -1,11 +1,12 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ -G::LoadThirdParty('phpmailer','class.phpmailer'); +G::LoadThirdParty( 'phpmailer', 'class.phpmailer' ); /* Send emails using the class "PHPMailer" * Email server configuration constants: * MAIL_MAILER mail/smtp @@ -39,237 +40,276 @@ G::LoadThirdParty('phpmailer','class.phpmailer'); * @author David Callizaya */ - - /** +/** + * * @package gulliver.system - **/ + * + */ class mailer { - - /** - * instanceMailer - * - * @return object(PHPMailer) $mailer - */ - function instanceMailer() - { - $mailer = new PHPMailer; - $mailer->PluginDir=PATH_THIRDPARTY.'phpmailer/'; - //DEFAULT CONFIGURATION - $mailer->Mailer = 'mail'; - $mailer->Host = ""; - $mailer->SMTPAuth = false; - $mailer->Username = ""; - $mailer->Password = ""; - $mailer->Timeout = 30; - $mailer->CharSet = 'utf-8'; - $mailer->Encoding='base64'; - if (defined('MAIL_MAILER')) $mailer->Mailer = MAIL_MAILER; - if (defined('MAIL_HOST')) $mailer->Host = MAIL_HOST; - if (defined('MAIL_SMTPAUTH')) $mailer->SMTPAuth = MAIL_SMTPAUTH; - if (defined('MAIL_USERNAME')) $mailer->Username = MAIL_USERNAME; - if (defined('MAIL_PASSWORD')) $mailer->Password = MAIL_PASSWORD; - if (defined('MAIL_TIMEOUT')) $mailer->Timeout = MAIL_TIMEOUT; - if (defined('MAIL_CHARSET')) $mailer->CharSet = MAIL_CHARSET; - if (defined('MAIL_ENCODING')) $mailer->Encoding= MAIL_ENCODING; - return $mailer; - } - - /* ARPA INTERNET TEXT MESSAGES - * Returns an array with the "name" and "email" of an ARPA type - * email $address. - * @author David Callizaya - */ - function arpaEMAIL($address) - { - $arpa = array(); - preg_match("/([^<>]*)(?:\<([^<>]*)\>)?/",$address,$matches); - $isEmail = preg_match("/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i",$matches[1]); - $arpa['email'] = ((isset($matches[2]))&&($matches[2]!=''))?$matches[2]:(($isEmail)?$matches[1]:''); - $arpa['name'] = ($isEmail)?'':$matches[1]; - return $arpa; - } - /** - * sendTemplate - * - * @param string $from default value empty - * @param string $target default value default value empty - * @param string $cc default value default value empty - * @param string $bcc default value default value empty - * @param string $subject default value empty - * @param array $Fields - * @param string $templateFile default value "empty.html" - * @param array $attachs - * @param boolean $plainText default value false - * @param boolean $returnContent default value false - * - * @return object $content or $result - */ - function sendTemplate( $from = "", $target = "", $cc = "", $bcc="" ,$subject = "", $Fields = array(), $templateFile = "empty.html", $attachs=array(), $plainText=false, $returnContent = false ) - { - // Read the content of the TemplateFile - $fp = fopen(PATH_HTMLMAIL . $templateFile,"r"); - $content = fread($fp,filesize(PATH_HTMLMAIL . $templateFile)); - fclose($fp); - //Replace the @@Fields with the $Fields array. - $content = mailer::replaceFields($Fields,$content); - //Compatibility with class.Application - if ($attachs==='FALSE') - return $content; - //Create the alternative body (text only) - //$h2t =& new html2text($content); - $text = '';//$h2t->get_text(); - //Prepate el phpmailer - $mailer = mailer::instanceMailer(); - $arpa = mailer::arpaEMAIL($from); - $mailer->From = $arpa['email']==''?$mailer->defaultEMail:$arpa['email']; - $mailer->FromName = $arpa['name']; - $arpa = mailer::arpaEMAIL($target); - $mailer->AddAddress($arpa['email'],$arpa['name']); - $mailer->AddCC($cc); - $mailer->AddBCC($bcc); - $mailer->Subject = $subject; - if ($plainText) - $content = $text; - if ($content==='') - $content='empty'; - $mailer->Body = $content; - //$mailer->AltBody = $text; - $mailer->isHTML(!$plainText); - //Attach the required files - if (is_array($attachs)) - if (sizeof($attachs)>0) - foreach($attachs as $aFile) - $mailer->AddAttachment($aFile,basename($aFile)); - //Send the e-mail. - for($r=1;$r<=4;$r++) { - $result = $mailer->Send(); - if ($result) break; + /** + * instanceMailer + * + * @return object(PHPMailer) $mailer + */ + function instanceMailer () + { + $mailer = new PHPMailer(); + $mailer->PluginDir = PATH_THIRDPARTY . 'phpmailer/'; + //DEFAULT CONFIGURATION + $mailer->Mailer = 'mail'; + $mailer->Host = ""; + $mailer->SMTPAuth = false; + $mailer->Username = ""; + $mailer->Password = ""; + $mailer->Timeout = 30; + $mailer->CharSet = 'utf-8'; + $mailer->Encoding = 'base64'; + if (defined( 'MAIL_MAILER' )) { + $mailer->Mailer = MAIL_MAILER; + } + if (defined( 'MAIL_HOST' )) { + $mailer->Host = MAIL_HOST; + } + if (defined( 'MAIL_SMTPAUTH' )) { + $mailer->SMTPAuth = MAIL_SMTPAUTH; + } + if (defined( 'MAIL_USERNAME' )) { + $mailer->Username = MAIL_USERNAME; + } + if (defined( 'MAIL_PASSWORD' )) { + $mailer->Password = MAIL_PASSWORD; + } + if (defined( 'MAIL_TIMEOUT' )) { + $mailer->Timeout = MAIL_TIMEOUT; + } + if (defined( 'MAIL_CHARSET' )) { + $mailer->CharSet = MAIL_CHARSET; + } + if (defined( 'MAIL_ENCODING' )) { + $mailer->Encoding = MAIL_ENCODING; + } + return $mailer; } - //unset($h2t); - if ($result && $returnContent) return $content; - return $result; - } - - /** - * sendHtml - * - * @param string $from default value empty - * @param string $target default value empty - * @param string $cc default value empty - * @param string $bcc default value empty - * @param string $subject default value empty - * @param array $Fields - * @param string $content default value empty - * @param array $attachs default value empty - * @param string $plainText default false - * @param boolean $returnContent default value false - * - * @return object $result - */ - function sendHtml( $from = "", $target = "", $cc = "", $bcc="" ,$subject = "", $Fields = array(), $content = "", $attachs=array(), $plainText=false, $returnContent = false ) - { - //Replace the @@Fields with the $Fields array. - $content = mailer::replaceFields($Fields,$content); - //Create the alternative body (text only) - //$h2t =& new html2text($content); - $text = '';//$h2t->get_text(); - //Prepate el phpmailer - $mailer = mailer::instanceMailer(); - $arpa = mailer::arpaEMAIL($from); - $mailer->From = $arpa['email']==''?$mailer->defaultEMail:$arpa['email']; - $mailer->FromName = $arpa['name']; - $arpa = mailer::arpaEMAIL($target); - $mailer->AddAddress($arpa['email'],$arpa['name']); - $mailer->AddCC($cc); - $mailer->AddBCC($bcc); - $mailer->Subject = $subject; - if ($plainText) $content = $text; - if ($content==='') $content='empty'; - $mailer->Body = $content; - //$mailer->AltBody = $text; - $mailer->isHTML(!$plainText); - //Attach the required files - if (is_array($attachs)) - if (sizeof($attachs)>0) - foreach($attachs as $aFile) - $mailer->AddAttachment($aFile,basename($aFile)); - //Send the e-mail. - for($r=1;$r<=4;$r++) { - $result=$mailer->Send(); - if ($result) break; - } - //unset($h2t); - if ($result && $returnContent) return $content; - return $result; - } - - /** - * sendText - * - * @param string $from default value empty - * @param string $target default value empty - * @param string $cc default value empty - * @param string $bcc default value empty - * @param string $subject default value empty - * @param string $content default value empty - * @param array $attachs - * - * @return object $result - */ - function sendText( $from = "", $target = "", $cc = "", $bcc="" ,$subject = "", $content = "", $attachs=array()) - { - //Prepate el phpmailer - $mailer = mailer::instanceMailer(); - $arpa = mailer::arpaEMAIL($from); - $mailer->From = $arpa['email']==''?$mailer->defaultEMail:$arpa['email']; - $mailer->FromName = $arpa['name']; - $arpa = mailer::arpaEMAIL($target); - $mailer->AddAddress($arpa['email'],$arpa['name']); - $mailer->AddCC($cc); - $mailer->AddBCC($bcc); - $mailer->Subject = $subject; - if ($content==='') $content='empty'; - $mailer->Body = $content; - $mailer->AltBody = $content; - $mailer->isHTML(false); - //Attach the required files - if (sizeof($attachs)>0) - foreach($attachs as $aFile) - $mailer->AddAttachment($aFile,basename($aFile)); - //Send the e-mail. - for($r=1;$r<=4;$r++) { - $result=$mailer->Send(); - if ($result) break; - } - return $result; - } - /** - * replaceFields - * - * @param array $Fields - * @param string $content default value string empty - * - * @return none - */ - function replaceFields($Fields = array(), $content = "") - { - return G::replaceDataField( $content , $Fields ); - } - - /** - * html2text - * - * empty - * @return none - */ - function html2text() - { - //$h2t =& new html2text($content); - //return $h2t->get_text(); - } + /* ARPA INTERNET TEXT MESSAGES + * Returns an array with the "name" and "email" of an ARPA type + * email $address. + * @author David Callizaya + */ + function arpaEMAIL ($address) + { + $arpa = array (); + preg_match( "/([^<>]*)(?:\<([^<>]*)\>)?/", $address, $matches ); + $isEmail = preg_match( "/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i", $matches[1] ); + $arpa['email'] = ((isset( $matches[2] )) && ($matches[2] != '')) ? $matches[2] : (($isEmail) ? $matches[1] : ''); + $arpa['name'] = ($isEmail) ? '' : $matches[1]; + return $arpa; + } + + /** + * sendTemplate + * + * @param string $from default value empty + * @param string $target default value default value empty + * @param string $cc default value default value empty + * @param string $bcc default value default value empty + * @param string $subject default value empty + * @param array $Fields + * @param string $templateFile default value "empty.html" + * @param array $attachs + * @param boolean $plainText default value false + * @param boolean $returnContent default value false + * + * @return object $content or $result + */ + function sendTemplate ($from = "", $target = "", $cc = "", $bcc = "", $subject = "", $Fields = array(), $templateFile = "empty.html", $attachs = array(), $plainText = false, $returnContent = false) + { + // Read the content of the TemplateFile + $fp = fopen( PATH_HTMLMAIL . $templateFile, "r" ); + $content = fread( $fp, filesize( PATH_HTMLMAIL . $templateFile ) ); + fclose( $fp ); + //Replace the @@Fields with the $Fields array. + $content = mailer::replaceFields( $Fields, $content ); + //Compatibility with class.Application + if ($attachs === 'FALSE') { + return $content; + } + //Create the alternative body (text only) + //$h2t =& new html2text($content); + $text = ''; //$h2t->get_text(); + //Prepate el phpmailer + $mailer = mailer::instanceMailer(); + $arpa = mailer::arpaEMAIL( $from ); + $mailer->From = $arpa['email'] == '' ? $mailer->defaultEMail : $arpa['email']; + $mailer->FromName = $arpa['name']; + $arpa = mailer::arpaEMAIL( $target ); + $mailer->AddAddress( $arpa['email'], $arpa['name'] ); + $mailer->AddCC( $cc ); + $mailer->AddBCC( $bcc ); + $mailer->Subject = $subject; + if ($plainText) { + $content = $text; + } + if ($content === '') { + $content = 'empty'; + } + $mailer->Body = $content; + //$mailer->AltBody = $text; + $mailer->isHTML( ! $plainText ); + //Attach the required files + if (is_array( $attachs )) + if (sizeof( $attachs ) > 0) + foreach ($attachs as $aFile) + $mailer->AddAttachment( $aFile, basename( $aFile ) ); + //Send the e-mail. + for ($r = 1; $r <= 4; $r ++) { + $result = $mailer->Send(); + if ($result) { + break; + } + } + //unset($h2t); + if ($result && $returnContent) { + return $content; + } + return $result; + } + + /** + * sendHtml + * + * @param string $from default value empty + * @param string $target default value empty + * @param string $cc default value empty + * @param string $bcc default value empty + * @param string $subject default value empty + * @param array $Fields + * @param string $content default value empty + * @param array $attachs default value empty + * @param string $plainText default false + * @param boolean $returnContent default value false + * + * @return object $result + */ + function sendHtml ($from = "", $target = "", $cc = "", $bcc = "", $subject = "", $Fields = array(), $content = "", $attachs = array(), $plainText = false, $returnContent = false) + { + //Replace the @@Fields with the $Fields array. + $content = mailer::replaceFields( $Fields, $content ); + //Create the alternative body (text only) + //$h2t =& new html2text($content); + $text = ''; //$h2t->get_text(); + //Prepate el phpmailer + $mailer = mailer::instanceMailer(); + $arpa = mailer::arpaEMAIL( $from ); + $mailer->From = $arpa['email'] == '' ? $mailer->defaultEMail : $arpa['email']; + $mailer->FromName = $arpa['name']; + $arpa = mailer::arpaEMAIL( $target ); + $mailer->AddAddress( $arpa['email'], $arpa['name'] ); + $mailer->AddCC( $cc ); + $mailer->AddBCC( $bcc ); + $mailer->Subject = $subject; + if ($plainText) { + $content = $text; + } + if ($content === '') { + $content = 'empty'; + } + $mailer->Body = $content; + //$mailer->AltBody = $text; + $mailer->isHTML( ! $plainText ); + //Attach the required files + if (is_array( $attachs )) + if (sizeof( $attachs ) > 0) + foreach ($attachs as $aFile) + $mailer->AddAttachment( $aFile, basename( $aFile ) ); + //Send the e-mail. + for ($r = 1; $r <= 4; $r ++) { + $result = $mailer->Send(); + if ($result) { + break; + } + } + //unset($h2t); + if ($result && $returnContent) { + return $content; + } + return $result; + } + + /** + * sendText + * + * @param string $from default value empty + * @param string $target default value empty + * @param string $cc default value empty + * @param string $bcc default value empty + * @param string $subject default value empty + * @param string $content default value empty + * @param array $attachs + * + * @return object $result + */ + function sendText ($from = "", $target = "", $cc = "", $bcc = "", $subject = "", $content = "", $attachs = array()) + { + //Prepate el phpmailer + $mailer = mailer::instanceMailer(); + $arpa = mailer::arpaEMAIL( $from ); + $mailer->From = $arpa['email'] == '' ? $mailer->defaultEMail : $arpa['email']; + $mailer->FromName = $arpa['name']; + $arpa = mailer::arpaEMAIL( $target ); + $mailer->AddAddress( $arpa['email'], $arpa['name'] ); + $mailer->AddCC( $cc ); + $mailer->AddBCC( $bcc ); + $mailer->Subject = $subject; + if ($content === '') { + $content = 'empty'; + } + $mailer->Body = $content; + $mailer->AltBody = $content; + $mailer->isHTML( false ); + //Attach the required files + if (sizeof( $attachs ) > 0) { + foreach ($attachs as $aFile) { + $mailer->AddAttachment( $aFile, basename( $aFile ) ); + } + } + //Send the e-mail. + for ($r = 1; $r <= 4; $r ++) { + $result = $mailer->Send(); + if ($result) { + break; + } + } + return $result; + } + + /** + * replaceFields + * + * @param array $Fields + * @param string $content default value string empty + * + * @return none + */ + function replaceFields ($Fields = array(), $content = "") + { + return G::replaceDataField( $content, $Fields ); + } + + /** + * html2text + * + * empty + * + * @return none + */ + function html2text () + { + //$h2t =& new html2text($content); + //return $h2t->get_text(); + } } -?> \ No newline at end of file + diff --git a/gulliver/system/class.menu.php b/gulliver/system/class.menu.php index 328b38642..a17bd5479 100755 --- a/gulliver/system/class.menu.php +++ b/gulliver/system/class.menu.php @@ -1,7 +1,9 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. * */ /** + * * @package gulliver.system -*/ + * + */ /** + * * * Menu class definition * Render Menus + * * @package gulliver.system * @author Fernando Ontiveros Lira * @copyright (C) 2002 by Colosa Development Team. @@ -37,343 +43,342 @@ */ class Menu { - var $Id = NULL; - var $Options = NULL; - var $Labels = NULL; - var $Icons = NULL; - var $JS = NULL; - var $Types = NULL; - var $Class = "mnu"; - var $Classes = NULL; - var $Enabled = NULL; - var $optionOn = -1; - var $id_optionOn = ""; - var $ElementClass = NULL; + var $Id = null; + var $Options = null; + var $Labels = null; + var $Icons = null; + var $JS = null; + var $Types = null; + var $Class = "mnu"; + var $Classes = null; + var $Enabled = null; + var $optionOn = - 1; + var $id_optionOn = ""; + var $ElementClass = null; - /** - * Set menu style - * - * @author Fernando Ontiveros Lira - * @access public - * @param $strClass name of style class default value 'mnu' - * @return void - */ - function SetClass( $strClass = "mnu" ) - { - $this->Class = "mnu"; - } - - /** - * Load menu options - * - * @author Fernando Ontiveros Lira - * @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 - * @access public - * @return int - */ - function OptionCount() - { - $result = 0; - if( is_array( $this->Options ) ) + /** + * Set menu style + * + * @author Fernando Ontiveros Lira + * @access public + * @param $strClass name of style class default value 'mnu' + * @return void + */ + function SetClass ($strClass = "mnu") { - $result = count( $this->Options ); + $this->Class = "mnu"; } - return $result; - } - /** - * Add an option to menu - * - * @author Fernando Ontiveros Lira - * @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 - * @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 - * @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 - * @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 - * @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 - * @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 - * @access public - * @param string $intPos menu option's position - * @return void - */ - function RenderOption( $intPos ) - { - if ( $this->Enabled[$intPos] != 1) - return; - - $classname = $this->Class . "Link"; - if ( $this->Classes[$intPos] != "" ) $classname = $this->Classes[$intPos]; - $target = $this->Options[$intPos]; - if( $this->Types[$intPos] != "absolute" ) + /** + * Load menu options + * + * @author Fernando Ontiveros Lira + * @access public + * @param $strMenuName name of menu + * @return void + */ + function Load ($strMenuName) { - if (defined('ENABLE_ENCRYPT')) { + global $G_TMP_MENU; + $G_TMP_MENU = null; + $G_TMP_MENU = new Menu(); + $fMenu = G::ExpandPath( "menus" ) . $strMenuName . ".php"; - $target = "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target; - } - else - if (defined('SYS_SYS')) - $target = "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target; - else - $target = "/sys/" . SYS_LANG . "/" . SYS_SKIN . "/" . $target; + //if the menu file doesn't exists, then try with the plugins folders + if (! is_file( $fMenu )) { + $aux = explode( PATH_SEP, $strMenuName ); + if (count( $aux ) == 2) { + $oPluginRegistry = & PMPluginRegistry::getSingleton(); + if ($oPluginRegistry->isRegisteredFolder( $aux[0] )) { + $fMenu = PATH_PLUGINS . $aux[0] . PATH_SEP . $aux[1] . ".php"; + } + } + } + + if (! is_file( $fMenu )) { + return; + } + include ($fMenu); + //this line will add options to current menu. + $oPluginRegistry = & PMPluginRegistry::getSingleton(); + $oPluginRegistry->getMenus( $strMenuName ); + + //? + $c = 0; + for ($i = 0; $i < count( $G_TMP_MENU->Options ); $i ++) + if ($G_TMP_MENU->Enabled[$i] == 1) { + $this->Options[$c] = $G_TMP_MENU->Options[$i]; + $this->Labels[$c] = $G_TMP_MENU->Labels[$i]; + $this->Icons[$c] = $G_TMP_MENU->Icons[$i]; + $this->JS[$c] = $G_TMP_MENU->JS[$i]; + $this->Types[$c] = $G_TMP_MENU->Types[$i]; + $this->Enabled[$c] = $G_TMP_MENU->Enabled[$i]; + $this->Id[$c] = $G_TMP_MENU->Id[$i]; + $this->Classes[$c] = $G_TMP_MENU->Classes[$i]; + $this->ElementClass[$c] = $G_TMP_MENU->ElementClass[$i]; + $c ++; + } else { + if ($i == $this->optionOn) + $this->optionOn = - 1; + elseif ($i < $this->optionOn) + $this->optionOn --; + elseif ($this->optionOn > 0) + $this->optionOn --; //added this line + } + $G_TMP_MENU = null; } - $label = $this->Labels[$intPos]; - $result = ""; - $result .= htmlentities( $label , ENT_NOQUOTES , 'utf-8'); - $result .= ""; - print( $result ); - } - - /** - * to make an array for template - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $G_MAIN_MENU - * @param string $classOn - * @param string $classOff - * @param string $G_MENU_SELECTED - * @param string $G_ID_MENU_SELECTED - * @return array - */ - function generateArrayForTemplate($G_MAIN_MENU,$classOn,$classOff,$G_MENU_SELECTED, $G_ID_MENU_SELECTED ) { - $menus = array(); - if ($G_MAIN_MENU == null) { - return $menus; - } - $this->Load ($G_MAIN_MENU); - $this->optionOn = $G_MENU_SELECTED; - $this->id_optionOn = $G_ID_MENU_SELECTED; - //$this->Class = $G_MENU_CLASS; - if (is_array($this->Options)) + /** + * Load menu options + * + * @author Fernando Ontiveros Lira + * @access public + * @return int + */ + function OptionCount () { - for ($ncount = 0; $ncount < $this->OptionCount(); $ncount++) - { - $target = $this->Options[$ncount]; - - //$aux = $this->Icons[$ncount]; - $aux = $this->JS[$ncount]; - if ($this->Types[$ncount] == 'absolute') { - //$target = G::encryptLink(str_replace('sys' . SYS_TEMP, SYS_TEMP, $this->Options[$ncount])); - $target = $this->Options[$ncount]; + $result = 0; + if (is_array( $this->Options )) { + $result = count( $this->Options ); } - if ($this->Types[$ncount] != 'absolute') { - if (defined('SYS_SYS')) { - $target = '/sys' . SYS_TEMP . G::encryptLink('/' . SYS_LANG . '/' . SYS_SKIN . '/' . $this->Options[$ncount]); - } - else { - $target = '/sys/' . G::encryptLink(SYS_LANG . '/' . SYS_SKIN . '/' . $this->Options[$ncount]); - } - } - $label = $this->Labels[$ncount]; - if ($this->id_optionOn != '') { - $onMenu = ($this->Id[$ncount] == $this->id_optionOn ? true : false); - } - else { - $onMenu = ($ncount == $this->optionOn ? true : false); - } - $classname = ($onMenu ? $classOn : $classOff); - $imageLeft = ($onMenu ? "" : ''); - $onclick = ''; - if ($this->JS[$ncount] !== '' ) { - $onclick = " onclick=\"" . $this->JS[$ncount] . "\""; - } - $icon = ''; - if ($this->Icons[$ncount] !== '' ) { - $icon = " JS[$ncount] . "\" class=\"$classname\">" . - "Icons[$ncount] . "\" border=\"0\"/>"; - $icon = $this->Icons[$ncount]; - } - if ( $this->Classes[$ncount] != '') { - $classname = $this->Classes[$ncount]; - $target = "#"; - } - $idName=$this->Id[$ncount]; - - $elementclass = ''; - if($this->ElementClass[$ncount] != ''){ - $elementclass = 'class="'.$this->ElementClass[$ncount].'"'; - } - - $menus[] = array ( 'id' => $ncount, 'target' => $target, 'label' => $label, 'onMenu' => $onMenu, 'classname' => $classname, - 'imageLeft' => $imageLeft, 'onclick' => $onclick, - 'icon' => $icon, 'aux' => $aux,'idName' => $idName,'elementclass'=>$elementclass); - } + return $result; } - return $menus; - } -} \ No newline at end of file + + /** + * Add an option to menu + * + * @author Fernando Ontiveros Lira + * @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 + * @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 + * @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 + * @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 + * @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 + * @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 + * @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 = ""; + $result .= htmlentities( $label, ENT_NOQUOTES, 'utf-8' ); + $result .= ""; + print ($result) ; + + } + + /** + * to make an array for template + * + * @author Fernando Ontiveros Lira + * @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 ? "" : ''); + $onclick = ''; + if ($this->JS[$ncount] !== '') { + $onclick = " onclick=\"" . $this->JS[$ncount] . "\""; + } + $icon = ''; + if ($this->Icons[$ncount] !== '') { + $icon = " JS[$ncount] . "\" class=\"$classname\">" . "Icons[$ncount] . "\" border=\"0\"/>"; + $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; + } +} + diff --git a/gulliver/system/class.objectTemplate.php b/gulliver/system/class.objectTemplate.php index e5dc3cc79..0c673932a 100755 --- a/gulliver/system/class.objectTemplate.php +++ b/gulliver/system/class.objectTemplate.php @@ -1,11 +1,13 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ - + /** * Class objectTemplate + * * @package gulliver.system * @access public */ -class objectTemplate extends smarty +class objectTemplate extends smarty { - /** - * Function objectTemplate - * @access public - * @param object $templateFile - * @return void - */ - function objectTemplate( $templateFile ) - { - $this->template_dir = PATH_TPL; - $this->compile_dir = PATH_SMARTY_C; - $this->cache_dir = PATH_SMARTY_CACHE; - $this->config_dir = PATH_THIRDPARTY . 'smarty/configs'; - $this->caching = false; - $this->templateFile = $templateFile; - } - - /** - * Function printObject - * @access public - * @param object $object - * @return string - */ - function printObject($object) - { - $this->assign($object); - return $this->fetch($this->templateFile); - } -} \ No newline at end of file + /** + * Function objectTemplate + * + * @access public + * @param object $templateFile + * @return void + */ + + function objectTemplate ($templateFile) + { + $this->template_dir = PATH_TPL; + $this->compile_dir = PATH_SMARTY_C; + $this->cache_dir = PATH_SMARTY_CACHE; + $this->config_dir = PATH_THIRDPARTY . 'smarty/configs'; + $this->caching = false; + $this->templateFile = $templateFile; + } + + /** + * Function printObject + * + * @access public + * @param object $object + * @return string + */ + function printObject ($object) + { + $this->assign( $object ); + return $this->fetch( $this->templateFile ); + } +} + diff --git a/gulliver/system/class.testTools.php b/gulliver/system/class.testTools.php index f37c0b469..ff9611fb4 100755 --- a/gulliver/system/class.testTools.php +++ b/gulliver/system/class.testTools.php @@ -1,12 +1,13 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ - /** +/** + * * @package gulliver.system - **/ -G::LoadSystem ( 'ymlDomain'); -G::LoadSystem ( 'ymlTestCases'); -G::LoadSystem ( 'unitTest'); + * + */ +G::LoadSystem( 'ymlDomain' ); +G::LoadSystem( 'ymlTestCases' ); +G::LoadSystem( 'unitTest' ); + class testTools { - - /** - * importDB - * - * @param string $host - * @param string $user - * @param string $password - * @param string $database - * @param string $importFile - * - * @return none - */ - function importDB( $host, $user, $password, $database, $importFile ) - { - exec("mysql -h " . $host . " --user=" . $user . " --password=" . $password . " $database < $importFile"); - } - - /** - * importLocalDB - * - * @param string $importFile - * - * @return none - */ - function importLocalDB( $importFile ) - { - self::importDB( DB_HOST, DB_USER, DB_PASS, DB_NAME, $importFile ); - } - /** - * callMethod - * - * @param string $methodFile - * @param string $GET - * @param string $POST - * @param string $SESSION - * - * @return none - */ - function callMethod( $methodFile, $GET, $POST, $SESSION ) - { - //TODO $_SERVER - self::arrayDelete($_GET); - self::arrayDelete($_POST); - self::arrayDelete($_SESSION); - self::arrayAppend($_GET,$GET); - self::arrayAppend($_POST,$POST); - self::arrayAppend($_SESSION,$SESSION); - include( PATH_CORE . 'methods/' . $methodFile ); - } + /** + * importDB + * + * @param string $host + * @param string $user + * @param string $password + * @param string $database + * @param string $importFile + * + * @return none + */ + function importDB ($host, $user, $password, $database, $importFile) + { + exec( "mysql -h " . $host . " --user=" . $user . " --password=" . $password . " $database < $importFile" ); + } - /** - * arrayAppend - * - * @param string &$to - * @param string $appendFrom - * - * @return boolean true - */ - function arrayAppend( &$to , $appendFrom ) - { - foreach($appendFrom as $appendItem) $to[]=$appendItem; - return true; - } - - /** - * arrayDelete - * - * @param array &$array - * - * @return boolean true - */ - function arrayDelete( &$array ) - { - foreach($array as $key => $value) unset($array[$key]); - return true; - } - - /** - * replaceVariables - * - * @param string $Fields - * @param array $ExternalVariables - * - * @return array $Fields - */ - //@@ - function replaceVariables( $Fields, $ExternalVariables = array() ) - { - //TODO: Verify dependencies between fields - foreach($Fields as $key => $field) { - if (is_string($field)) { - $mergedValues = G::array_merges( $Fields, $ExternalVariables ); - $Fields[$key] = G::ReplaceDataField( $field, $mergedValues ); - } + /** + * importLocalDB + * + * @param string $importFile + * + * @return none + */ + function importLocalDB ($importFile) + { + self::importDB( DB_HOST, DB_USER, DB_PASS, DB_NAME, $importFile ); } - return $Fields; - } - - // EXTRA TOOLS - /** - * findValue - * - * @param string $value - * @param object &$obj - * - * @return (boolean | string) ((true | false) | $value) - */ - function findValue( $value, &$obj ) - { - if (is_array($obj)) { - foreach($obj as $key => $val ) { - if ($res=self::findValue( $value , $obj[$key] )) { - if ($res==true) return $key; - else return $key . '.' . $res; + + /** + * callMethod + * + * @param string $methodFile + * @param string $GET + * @param string $POST + * @param string $SESSION + * + * @return none + */ + function callMethod ($methodFile, $GET, $POST, $SESSION) + { + //TODO $_SERVER + self::arrayDelete( $_GET ); + self::arrayDelete( $_POST ); + self::arrayDelete( $_SESSION ); + self::arrayAppend( $_GET, $GET ); + self::arrayAppend( $_POST, $POST ); + self::arrayAppend( $_SESSION, $SESSION ); + include (PATH_CORE . 'methods/' . $methodFile); + } + + /** + * arrayAppend + * + * @param string &$to + * @param string $appendFrom + * + * @return boolean true + */ + function arrayAppend (&$to, $appendFrom) + { + foreach ($appendFrom as $appendItem) { + $to[] = $appendItem; } - } - return false; + return true; } - elseif (is_object($obj)) { - foreach($obj as $key => $val ) { - if ($res=self::findValue( $value , $obj->$key )) { - if ($res==true) - return $key; - else - return $key . '.' . $res; + + /** + * arrayDelete + * + * @param array &$array + * + * @return boolean true + */ + function arrayDelete (&$array) + { + foreach ($array as $key => $value) { + unset( $array[$key] ); } - } - return false; + return true; } - else { - return $obj==$value; + + /** + * replaceVariables + * + * @param string $Fields + * @param array $ExternalVariables + * + * @return array $Fields + */ + //@@ + function replaceVariables ($Fields, $ExternalVariables = array()) + { + //TODO: Verify dependencies between fields + foreach ($Fields as $key => $field) { + if (is_string( $field )) { + $mergedValues = G::array_merges( $Fields, $ExternalVariables ); + $Fields[$key] = G::ReplaceDataField( $field, $mergedValues ); + } + } + return $Fields; + } + + // EXTRA TOOLS + /** + * findValue + * + * @param string $value + * @param object &$obj + * + * @return (boolean | string) ((true | false) | $value) + */ + function findValue ($value, &$obj) + { + if (is_array( $obj )) { + foreach ($obj as $key => $val) { + if ($res = self::findValue( $value, $obj[$key] )) { + if ($res == true) { + return $key; + } else { + return $key . '.' . $res; + } + } + } + return false; + } elseif (is_object( $obj )) { + foreach ($obj as $key => $val) { + if ($res = self::findValue( $value, $obj->$key )) { + if ($res == true) { + return $key; + } else { + return $key . '.' . $res; + } + } + } + return false; + } else { + return $obj == $value; + } } - } } /* Some extra global functions */ /** * domain * - * @param string $location * + * @param string $location * * @return object $result - */ + */ -function domain($location) +function domain ($location) { - global $testDomain; - $result = $testDomain->get($location); - if (count($result)==0) trigger_error("'$location' is an empty domain.", E_USER_WARNING); - return $result; + global $testDomain; + $result = $testDomain->get( $location ); + if (count( $result ) == 0) { + trigger_error( "'$location' is an empty domain.", E_USER_WARNING ); + } + return $result; } + diff --git a/gulliver/system/class.tree.php b/gulliver/system/class.tree.php index 5c9179df8..cc64b3d9c 100755 --- a/gulliver/system/class.tree.php +++ b/gulliver/system/class.tree.php @@ -1,153 +1,160 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ - /** +/** + * * @package gulliver.system */ - G::LoadSystem('objectTemplate'); - class Tree extends Xml_Node { - var $template = 'tree.html'; - var $nodeType = 'base'; - var $nodeClass = 'treeNode'; +G::LoadSystem( 'objectTemplate' ); + +class Tree extends Xml_Node +{ + var $template = 'tree.html'; + var $nodeType = 'base'; + var $nodeClass = 'treeNode'; var $contentClass = 'treeContent'; - var $width = '100%'; + var $width = '100%'; var $contentWidth = '360'; - var $contracted = false; - var $showSign = true; - var $isChild = false; - var $plus = " "; - var $minus = " "; - var $point = " "; + var $contracted = false; + var $showSign = true; + var $isChild = false; + var $plus = " "; + var $minus = " "; + var $point = " "; /** * Tree * - * @param array $xmlnode default value NULL + * @param array $xmlnode default value NULL * * @return none - */ - function Tree( $xmlnode = NULL ) + */ + function Tree ($xmlnode = null) { - if (!isset($xmlnode)) - return; - if (isset($xmlnode->attributes['nodeType'])) - $this->nodeType=$xmlnode->attributes['nodeType']; - foreach($xmlnode as $key => $value) { - if ($key==='children') { - foreach( $xmlnode->children as $key => $value ) { - $this->children[ $key ] = new Tree( $value->toTree()); - } - } elseif ($key==='attributes') { - foreach( $xmlnode->attributes as $key => $value ) { - $this->{$key} = $value; - } + if (! isset( $xmlnode )) { + return; } - else { - $this->{$key} = $value; + if (isset( $xmlnode->attributes['nodeType'] )) { + $this->nodeType = $xmlnode->attributes['nodeType']; + } + foreach ($xmlnode as $key => $value) { + if ($key === 'children') { + foreach ($xmlnode->children as $key => $value) { + $this->children[$key] = new Tree( $value->toTree() ); + } + } elseif ($key === 'attributes') { + foreach ($xmlnode->attributes as $key => $value) { + $this->{$key} = $value; + } + } else { + $this->{$key} = $value; + } } - } } - + /** * &addChild * - * @param string $name - * @param string $label - * @param array $attributes + * @param string $name + * @param string $label + * @param array $attributes * * @return object(Tree) $newNode - */ + */ - function &addChild( $name, $label, $attributes = array() ) + function &addChild ($name, $label, $attributes = array()) { - $newNode = new Tree(new Xml_Node($name, 'open', $label, $attributes)); - $this->children[] =& $newNode; - return $newNode; + $newNode = new Tree( new Xml_Node( $name, 'open', $label, $attributes ) ); + $this->children[] = & $newNode; + return $newNode; } /** * printPlus * * @return string '...' - */ - function printPlus() + */ + function printPlus () { - $plus = 'none'; - $minus = 'none'; - $point = 'none'; - if ($this->showSign) { - if ((sizeof($this->children)>0) && ($this->contracted)) { - $plus = ''; - } elseif ((sizeof($this->children)>0) && (!$this->contracted)) { - $minus = ''; - } else { - $point = ''; + $plus = 'none'; + $minus = 'none'; + $point = 'none'; + if ($this->showSign) { + if ((sizeof( $this->children ) > 0) && ($this->contracted)) { + $plus = ''; + } elseif ((sizeof( $this->children ) > 0) && (! $this->contracted)) { + $minus = ''; + } else { + $point = ''; + } } - } - return "{$this->plus}". - "{$this->minus}". - "{$this->point}"; + return "{$this->plus}" . "{$this->minus}" . "{$this->point}"; } - + /** * printLabel * * @return $this->value - */ - function printLabel() + */ + function printLabel () { - return $this->value; + return $this->value; } - + /** * printContent * * @return string $html - */ - function printContent() + */ + function printContent () { - $html = ''; - $row = 0; - foreach($this->children as $child) { - if ($row) - $child->nodeClass = 'treeNodeAlternate'; - $html .= $child->render(); - $row = ($row + 1) % 2; - } - return $html; + $html = ''; + $row = 0; + foreach ($this->children as $child) { + if ($row) { + $child->nodeClass = 'treeNodeAlternate'; + } + $html .= $child->render(); + $row = ($row + 1) % 2; + } + return $html; } - + /** * render + * * @return $obj->printObject( array( 'node' => &$this ) ) - */ - function render() { - $obj = new objectTemplate( $this->template ); - return $obj->printObject( array( 'node' => &$this ) ); + */ + function render () + { + $obj = new objectTemplate( $this->template ); + return $obj->printObject( array ('node' => &$this + ) ); } - } +} diff --git a/gulliver/system/class.unitTest.php b/gulliver/system/class.unitTest.php index 327d44e4f..1ce24c473 100755 --- a/gulliver/system/class.unitTest.php +++ b/gulliver/system/class.unitTest.php @@ -1,12 +1,14 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ - /** - * @package gulliver.system - */ +/** + * + * @package gulliver.system + */ class unitTest { - var $dbc; - var $times; - var $yml; - var $domain; - var $testLime; - function unitTest( $ymlFile, &$testLime, &$testDomain ) - { - if (!isset($testDomain)) $testDomain = new ymlDomain(); - $this->domain =& $testDomain; - $this->testLime =& $testLime; - $this->yml = new ymlTestCases( $ymlFile, $this->domain, $this->testLime ); - } - //Load a Test (group of unitary tests) defined in the Yml file. - function load( $testName, $fields=array() ) - { - $this->yml->load( $testName, $fields ); - } - //Run one single unit test from the loaded Test - function runSingle( $fields=array() ) - { - return $this->yml->runSingle( $this, $fields ); - } - //Run a group of unit tests from the loaded Test - function runMultiple( $fields=array(), $count = -1, $start=0) - { - return $this->yml->runMultiple( $this, $fields, $count, $start ); - } - //Run all the unit tests from the loaded Test - function runAll( $fields=array()) - { - return $this->yml->runMultiple( $this, $fields, -1, 0 ); - } - //A sample of "Function" to run a unit test. - function sampleTestFunction( $testCase , &$Fields ) - { - $result = ($Fields['APP_UID']!='')?"OK":"FALSE"; - return $result; - } + var $dbc; + var $times; + var $yml; + var $domain; + var $testLime; + + function unitTest ($ymlFile, &$testLime, &$testDomain) + { + if (! isset( $testDomain )) { + $testDomain = new ymlDomain(); + } + $this->domain = & $testDomain; + $this->testLime = & $testLime; + $this->yml = new ymlTestCases( $ymlFile, $this->domain, $this->testLime ); + } + //Load a Test (group of unitary tests) defined in the Yml file. + function load ($testName, $fields = array()) + { + $this->yml->load( $testName, $fields ); + } + //Run one single unit test from the loaded Test + function runSingle ($fields = array()) + { + return $this->yml->runSingle( $this, $fields ); + } + //Run a group of unit tests from the loaded Test + function runMultiple ($fields = array(), $count = -1, $start = 0) + { + return $this->yml->runMultiple( $this, $fields, $count, $start ); + } + //Run all the unit tests from the loaded Test + function runAll ($fields = array()) + { + return $this->yml->runMultiple( $this, $fields, - 1, 0 ); + } + //A sample of "Function" to run a unit test. + function sampleTestFunction ($testCase, &$Fields) + { + $result = ($Fields['APP_UID'] != '') ? "OK" : "FALSE"; + return $result; + } } + diff --git a/gulliver/system/class.webResource.php b/gulliver/system/class.webResource.php index 36a10e042..a64d3596d 100755 --- a/gulliver/system/class.webResource.php +++ b/gulliver/system/class.webResource.php @@ -1,11 +1,13 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ /* Web Resource (v1.0 PHP4) * This class permit create PHP/Javascript classes accesible by @@ -29,103 +31,101 @@ * _Function = don't encode * JS_function = javascript function. * @example: h2b2x/territoriesAjax.php - * @dependencies: grest.js * + * @dependencies: grest.js * */ - /** +/** + * * @package gulliver.system */ class WebResource { - var $_uri; + var $_uri; - /** - * WebResource - * - * @param string $uri - * @param string $post - * - * @return none - */ - function WebResource($uri, $post) - { - $this->_uri=$uri; - if (isset($post['function'])&&$post['function']!='') { - /*Call a function*/ - header('Content-Type: text/json'); - //$parameters=G::json_decode((urldecode($post['parameters']))); //for %AC - $parameters=G::json_decode(($post['parameters'])); - $paramsRef=array(); - foreach($parameters as $key => $value) - { - if (is_string($key)) $paramsRef[]="\$parameters['".addcslashes($key,'\\\'')."']"; - else $paramsRef[]='$parameters['.$key.']'; - } - $res=eval('return ($this->'.$post['function'].'('.implode(',',$paramsRef).'));'); - $res=G::json_encode($res); - print($res); + /** + * WebResource + * + * @param string $uri + * @param string $post + * + * @return none + */ + function WebResource ($uri, $post) + { + $this->_uri = $uri; + if (isset( $post['function'] ) && $post['function'] != '') { + /*Call a function*/ + header( 'Content-Type: text/json' ); + //$parameters=G::json_decode((urldecode($post['parameters']))); //for %AC + $parameters = G::json_decode( ($post['parameters']) ); + $paramsRef = array (); + foreach ($parameters as $key => $value) { + if (is_string( $key )) { + $paramsRef[] = "\$parameters['" . addcslashes( $key, '\\\'' ) . "']"; + } else { + $paramsRef[] = '$parameters[' . $key . ']'; + } + } + $res = eval( 'return ($this->' . $post['function'] . '(' . implode( ',', $paramsRef ) . '));' ); + $res = G::json_encode( $res ); + print ($res) ; + } else { + /*Print class definition*/ + $this->_encode(); + } } - else { - /*Print class definition*/ - $this->_encode(); + + /** + * _encode + * + * @return none + */ + function _encode () + { + header( 'Content-Type: text/json' ); + $methods = get_class_methods( get_class( $this ) ); + print ('{') ; + $first = true; + foreach ($methods as $method) { + //To avoid PHP version incompatibilities, put the $method name in lowercase + $method = strtolower( $method ); + if ((substr( $method, 0, 1 ) === '_') || (strcasecmp( $method, 'WebResource' ) == 0) || (strcasecmp( $method, get_class( $this ) ) == 0)) { + } elseif (strcasecmp( substr( $method, 0, 3 ), 'js_' ) == 0) { + if (! $first) { + print (',') ; + } + $this->{$method}(); + $first = false; + } else { + if (! $first) { + print (',') ; + } + print ($method . ':function(){return __wrCall("' . addslashes( $this->_uri ) . '","' . $method . '",arguments);}') ; + $first = false; + } + } + print ('}') ; } - } - - /** - * _encode - * - * @return none - */ - function _encode() - { - header('Content-Type: text/json'); - $methods=get_class_methods(get_class($this)); - print('{'); - $first = true; - foreach($methods as $method) { - //To avoid PHP version incompatibilities, put the $method name in lowercase - $method=strtolower($method); - if ((substr($method,0,1)==='_')|| - (strcasecmp($method,'WebResource')==0)|| - (strcasecmp($method,get_class($this))==0) - ) - { - } - elseif (strcasecmp(substr($method,0,3),'js_')==0) - { - if (!$first) print(','); - $this->{$method}(); - $first=false; - } - else - { - if (!$first) print(','); - print( - $method. - ':function(){return __wrCall("'. - addslashes($this->_uri). - '","'.$method.'",arguments);}' - ); - $first=false; - } - } - print('}'); - } } /* end class WebResource */ -if (!function_exists('json_encode')) { - G::LoadThirdParty('pear/json','class.json'); - function json_encode(&$value) { - $json= new Services_JSON; - return $json->encode($value); - } +if (! function_exists( 'json_encode' )) { + G::LoadThirdParty( 'pear/json', 'class.json' ); + + function json_encode (&$value) + { + $json = new Services_JSON(); + return $json->encode( $value ); + } } -if (!function_exists('json_decode')) { - G::LoadThirdParty('pear/json','class.json'); - function json_decode(&$value) { - $json= new Services_JSON; - return $json->decode($value); - } +if (! function_exists( 'json_decode' )) { + G::LoadThirdParty( 'pear/json', 'class.json' ); + + function json_decode (&$value) + { + $json = new Services_JSON(); + return $json->decode( $value ); + } } + diff --git a/gulliver/system/class.xmlDocument.php b/gulliver/system/class.xmlDocument.php index 4b39c99db..e4c7f6ecc 100755 --- a/gulliver/system/class.xmlDocument.php +++ b/gulliver/system/class.xmlDocument.php @@ -1,7 +1,9 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -25,340 +27,355 @@ */ /** * Class Xml_Node + * * @author David S. Callizaya S. * @package gulliver.system * @access public */ class Xml_Node { - var $name = ''; - var $type = ''; - var $value = ''; //maybe not necesary - var $attributes = array(); - var $children = array(); - /** - * Function Xml_Node - * @author David S. Callizaya S. - * @access public - * @parameter string name - * @parameter string type - * @parameter string value - * @parameter string attributes - * @return string - */ - function Xml_Node($name, $type, $value, $attributes = array() ) - { - $this->name = $name; - $this->type = $type; - $this->value = $value; - $this->attributes = $attributes; - } - /** - * Function addAttribute - * @author David S. Callizaya S. - * @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. - * @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. - * @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. - * @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. - * @access public - * @parameter string xpath - * @return string - */ - function getXML() - { - switch($this->type) + var $name = ''; + var $type = ''; + var $value = ''; //maybe not necesary + var $attributes = array (); + var $children = array (); + + /** + * Function Xml_Node + * + * @author David S. Callizaya S. + * @access public + * @param eter string name + * @param eter string type + * @param eter string value + * @param eter string attributes + * @return string + */ + function Xml_Node ($name, $type, $value, $attributes = array()) { - case 'open': - $xml = '<'.$this->name; - foreach( $this->attributes as $attib => $value ) { - $value = htmlspecialchars( $value, ENT_QUOTES, 'utf-8' ); - /*if(($attib == "hint")||($attib == "defaultvalue")){ - $value = str_replace("&", "&", $value); - $value = str_replace("'", "\'", $value); - $value = str_replace(">", ">", $value); - $value = str_replace("<", "<", $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, '€') !== false) { - $xml = str_replace('€', '€', $xml); - } - } - $xml .= '>'.$this->getCDATAValue(); - foreach( $this->children as $child ) - $xml .= $child->getXML(); - $xml .= 'name.'>'; - break; - - case 'close': - $xml = '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, '€') !== false) { - $xml = str_replace('€', '€', $xml); - } - } - if ($this->value!=='') { - $xml .= '>'.$this->getCDATAValue(); - $xml .= 'name.'>'; - } else { - $xml .= '/>'; - } - break; + $this->name = $name; + $this->type = $type; + $this->value = $value; + $this->attributes = $attributes; + } + + /** + * Function addAttribute + * + * @author David S. Callizaya S. + * @access public + * @param eter string name + * @param eter string value + * @return string + */ + function addAttribute ($name, $value) + { + $this->attributes[$name] = $value; + return true; + } + + /** + * Function addChildNode + * + * @author David S. Callizaya S. + * @access public + * @param eter string childNode + * @return string + */ + function addChildNode ($childNode) + { + if (is_object( $childNode ) && strcasecmp( get_class( $childNode ), 'Xml_Node' ) == 0) { + $this->type = 'open'; + $childNode->parent = &$this; + $this->children[] = &$childNode; + return true; + } else { + return false; + } + } + + /** + * Function toTree + * + * @author David S. Callizaya S. + * @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. + * @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. + * @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("&", "&", $value); + $value = str_replace("'", "\'", $value); + $value = str_replace(">", ">", $value); + $value = str_replace("<", "<", $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, '€' ) !== false) { + $xml = str_replace( '€', '€', $xml ); + } + } + $xml .= '>' . $this->getCDATAValue(); + foreach ($this->children as $child) { + $xml .= $child->getXML(); + } + $xml .= 'name . '>'; + break; + case 'close': + $xml = '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, '€' ) !== false) { + $xml = str_replace( '€', '€', $xml ); + } + } + if ($this->value !== '') { + $xml .= '>' . $this->getCDATAValue(); + $xml .= '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 'value . ']]>'; + } } - return $xml; - } - function getCDATAValue() - { - $cdata = htmlentities( $this->value, ENT_QUOTES, 'utf-8' ); - if ($this->value === $cdata) - return $this->value; - else - return 'value . ']]>'; - } } + /** * Class Xml_document + * * @author David S. Callizaya S. * @package gulliver.system * @access public */ class Xml_document extends Xml_Node { - var $currentNode; - /** - * Function Xml_document - * @author David S. Callizaya S. - * @access public - * @return string - */ - function Xml_document() - { - $this->currentNode = &$this; - } - /** - * Function parseXmlFile - * @author David S. Callizaya S. - * @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 %s: %s at line %d", $filename , xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); - trigger_error ( $msg ); - } - xml_parser_free( $parser ); + var $currentNode; - $this->name = '#document'; - $this->type = 'open'; - $this->currentNode = &$this; - $m = &$this; - foreach($values as $k => $v) + /** + * Function Xml_document + * + * @author David S. Callizaya S. + * @access public + * @return string + */ + function Xml_document () { - switch ($v['type']) - { - case 'open': - $this->currentNode->addChildNode ( new Xml_Node ($v['tag'], - $v['type'], isset($v['value'])?$v['value'] : '', - isset($v['attributes']) ? $v['attributes']:array())); - $this->currentNode = &$this->findNode($v['tag']); - break; - - case 'close': - $this->currentNode=& $this->findNode('..'); - break; - - case 'cdata': - $this->currentNode->addChildNode(new Xml_Node('', - $v['type'], isset($v['value'])?$v['value']:'')); - break; - - case 'complete': - $this->currentNode->addChildNode( new Xml_Node($v['tag'], - $v['type'], isset($v['value'])?$v['value']:'', - isset($v['attributes'])?$v['attributes']:array())); - break; - } + $this->currentNode = &$this; } - return true; - } - /** - * Function &findNode - * @author David S. Callizaya S. - * @access public - * @parameter string xpath - * @return string - */ - function &findNode( $xpath ) - { - if ( substr( $xpath, 0, 1 ) == '/' ) { - return parent::findNode( substr( $xpath,1) ); - } - else { - if ( isset($this->currentNode) ){ - if ( $this->currentNode->name === $this->name) - return parent::findNode( $xpath ); - else - return $this->currentNode->findNode($xpath); - } - else { - return $null; - } - } - } //function findNode - /** - * Function getXML - * - * @access public - * @return string $xml - */ - function getXML() - { - $xml = ''."\n"; - $xml .= $this->children[0]->getXML(); - return $xml; - } - /** - * Function save - * - * @access public - * @return void - */ - function save ( $filename ) - { - $xml = $this->getXML(); - $fp = fopen( $filename , 'w' ); - fwrite( $fp , $xml ); - fclose( $fp );/**/ - } + /** + * Function parseXmlFile + * + * @author David S. Callizaya S. + * @access public + * @param eter string filename + * @param eter string content + * @return string + */ + function parseXmlFile ($filename, $content = "") + { //$content is a new variable, if it has any value then use it instead of the file content. + if ($content == "") { + if (! file_exists( $filename )) { + throw (new Exception( "failed to open Xmlform File : No such file or directory in $filename " )); + } + $data = implode( '', file( $filename ) ); + } else { + $data = $content; + } + + $parser = xml_parser_create( 'utf-8' ); + xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); + xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 0 ); + xml_parse_into_struct( $parser, $data, $values, $tags ); + if (xml_get_error_code( $parser ) !== 0) { + $msg = sprintf( "XML error in %s: %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. + * @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 = '' . "\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 ); + } } + diff --git a/gulliver/system/class.xmlformExtension.php b/gulliver/system/class.xmlformExtension.php index e3111bd3e..c431c05b5 100755 --- a/gulliver/system/class.xmlformExtension.php +++ b/gulliver/system/class.xmlformExtension.php @@ -1,157 +1,161 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ - - /** - * @package gulliver.system - */ - -class XmlForm_Field_Label extends XmlForm_Field -{ - var $withoutValue = true; - var $align = 'left'; -} - -/** - * Special class for pagedTable - * condition: PHP expression whose result defines whether to "mark" - * the following columns (that is if true) - * @package gulliver.system - */ -class XmlForm_Field_cellMark extends XmlForm_Field -{ - /* Defines the style of the next tds +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + +/** + * + * @package gulliver.system + */ + +class XmlForm_Field_Label extends XmlForm_Field +{ + var $withoutValue = true; + var $align = 'left'; +} + +/** + * Special class for pagedTable + * condition: PHP expression whose result defines whether to "mark" + * the following columns (that is if true) + * + * @package gulliver.system + */ +class XmlForm_Field_cellMark extends XmlForm_Field +{ + /* Defines the style of the next tds of the pagedTable. - */ - var $showInTable = "0"; - var $style = ""; - var $styleAlt = ""; - var $className = ""; - var $classNameAlt = ""; - var $condition = 'false'; - - /** - * tdStyle - * - * @param string $values - * @param string $owner - * - * @return string $value - */ - function tdStyle( $values , $owner ) - { - $value = G::replaceDataField( $this->condition, $owner->values ); - $value = @eval('return ('.$value.');'); - $row=$values['row__']; - $style=((($row % 2)==0) && ($this->styleAlt!=0)) ? - $this->styleAlt : $this->style; - return ($value)?$style:''; - } - - /** - * tdClass - * - * @param string $values - * @param string $owner - * - * @return $value - */ - function tdClass( $values, $owner ) - { - $value = G::replaceDataField( $this->condition, $owner->values ); - $value = @eval('return ('.$value.');'); - $row=$values['row__']; - $style=(($row % 2)==0) ? - $this->classNameAlt : $this->className; - return ($value)?$style:''; - } + */ + var $showInTable = "0"; + var $style = ""; + var $styleAlt = ""; + var $className = ""; + var $classNameAlt = ""; + var $condition = 'false'; + + /** + * tdStyle + * + * @param string $values + * @param string $owner + * + * @return string $value + */ + function tdStyle ($values, $owner) + { + $value = G::replaceDataField( $this->condition, $owner->values ); + $value = @eval( 'return (' . $value . ');' ); + $row = $values['row__']; + $style = ((($row % 2) == 0) && ($this->styleAlt != 0)) ? $this->styleAlt : $this->style; + return ($value) ? $style : ''; + } + + /** + * tdClass + * + * @param string $values + * @param string $owner + * + * @return $value + */ + function tdClass ($values, $owner) + { + $value = G::replaceDataField( $this->condition, $owner->values ); + $value = @eval( 'return (' . $value . ');' ); + $row = $values['row__']; + $style = (($row % 2) == 0) ? $this->classNameAlt : $this->className; + return ($value) ? $style : ''; + } +} + +/** + * XmlForm_Field_DVEditor + * + * extends XmlForm_Field + * + * @package gulliver.system + * + */ +class XmlForm_Field_DVEditor extends XmlForm_Field +{ + var $toolbarSet = 'toolbar2lines.html'; + var $width = '90%'; + var $height = '200'; + + /** + * render + * + * @param string $value + * @param string $owner default value NULL + * + * @return string '
...
' + */ + function render ($value, $owner = null) + { + return '
'; + } + + /** + * 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. + * + * + * Search + * + * Ex2 (Using type="text"). + * + * + * 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 '
...
' - */ - function render( $value, $owner = NULL ) - { - return '
'; - } - - /** - * 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. - * - * - * Search - * - * Ex2 (Using type="text"). - * - * - * 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)"; -} +