diff --git a/gulliver/system/class.database_mssql.php b/gulliver/system/class.database_mssql.php index 1d6076d6e..b5e83acb4 100755 --- a/gulliver/system/class.database_mssql.php +++ b/gulliver/system/class.database_mssql.php @@ -1,173 +1,173 @@ -. - * - * 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( 'database_base' ); - -class database extends database_base -{ - public $iFetchType = MSSQL_ASSOC; - - public function __construct ($sType = DB_ADAPTER, $sServer = DB_HOST, $sUser = DB_USER, $sPass = DB_PASS, $sDataBase = DB_NAME) - { - $this->sType = $sType; - $this->sServer = $sServer; - $this->sUser = $sUser; - $this->sPass = $sPass; - $this->sDataBase = $sDataBase; - $this->oConnection = @mssql_connect( $sServer, $sUser, $sPass ) || null; - $this->sQuoteCharacter = ' '; - $this->nullString = 'NULL'; - $this->sQuoteCharacterBegin = '['; - $this->sQuoteCharacterEnd = ']'; - } - - public function generateCreateTableSQL ($sTable, $aColumns) - { - $sKeys = ''; - $sSQL = 'CREATE TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '('; - - foreach ($aColumns as $sColumnName => $aParameters) { - if ($sColumnName != 'INDEXES') { - - if ($sColumnName != '' && isset( $aParameters['Type'] ) && $aParameters['Type'] != '') { - $sSQL .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ' ' . $aParameters['Type']; - - if (isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') { - $sSQL .= ' NULL'; - } else { - $sSQL .= ' NOT NULL'; - } - if (isset( $aParameters['Key'] ) && $aParameters['Key'] == 'PRI') { - $sKeys .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ','; - } - - if (isset( $aParameters['Default'] ) && $aParameters['Default'] != '') { - $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; - } - - $sSQL .= ','; - } - } - } - $sSQL = substr( $sSQL, 0, - 1 ); - if ($sKeys != '') { - $sSQL .= ',PRIMARY KEY(' . substr( $sKeys, 0, - 1 ) . ')'; - } - $sSQL .= ')' . $this->sEndLine; - - return $sSQL; - } - - public function generateDropTableSQL ($sTable) - { - return 'DROP TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine; - } - - public function generateDropColumnSQL ($sTable, $sColumn) - { +. + * + * 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( 'database_base' ); + +class database extends database_base +{ + public $iFetchType = MSSQL_ASSOC; + + public function __construct ($sType = DB_ADAPTER, $sServer = DB_HOST, $sUser = DB_USER, $sPass = DB_PASS, $sDataBase = DB_NAME) + { + $this->sType = $sType; + $this->sServer = $sServer; + $this->sUser = $sUser; + $this->sPass = $sPass; + $this->sDataBase = $sDataBase; + $this->oConnection = @mssql_connect( $sServer, $sUser, $sPass ) || null; + $this->sQuoteCharacter = ' '; + $this->nullString = 'NULL'; + $this->sQuoteCharacterBegin = '['; + $this->sQuoteCharacterEnd = ']'; + } + + public function generateCreateTableSQL ($sTable, $aColumns) + { + $sKeys = ''; + $sSQL = 'CREATE TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '('; + + foreach ($aColumns as $sColumnName => $aParameters) { + if ($sColumnName != 'INDEXES') { + + if ($sColumnName != '' && isset( $aParameters['Type'] ) && $aParameters['Type'] != '') { + $sSQL .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ' ' . $aParameters['Type']; + + if (isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') { + $sSQL .= ' NULL'; + } else { + $sSQL .= ' NOT NULL'; + } + if (isset( $aParameters['Key'] ) && $aParameters['Key'] == 'PRI') { + $sKeys .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ','; + } + + if (isset( $aParameters['Default'] ) && $aParameters['Default'] != '') { + $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } + + $sSQL .= ','; + } + } + } + $sSQL = substr( $sSQL, 0, - 1 ); + if ($sKeys != '') { + $sSQL .= ',PRIMARY KEY(' . substr( $sKeys, 0, - 1 ) . ')'; + } + $sSQL .= ')' . $this->sEndLine; + + return $sSQL; + } + + public function generateDropTableSQL ($sTable) + { + return 'DROP TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine; + } + + public function generateDropColumnSQL ($sTable, $sColumn) + { // SQL Server first should remove the restriction before the Elimination of the field - $oConstraint = $this->dropFieldConstraint( $sTable, $sColumn ); - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine; - return $sSQL; - } - - public function generateAddColumnSQL ($sTable, $sColumn, $aParameters) - { - if (isset( $aParameters['Type'] ) && isset( $aParameters['Null'] )) { - $sDefault = ""; - $sType = $aParameters['Type']; - $sDataType = $aParameters['Type']; - if (! in_array( $sDataType, array ("TEXT","DATE" - ) )) { - $sType = substr( $sType, 0, strpos( $sType, '(' ) ); - } - switch ($sType) { - case 'VARCHAR': - case 'TEXT': - $sDefault = " DEFAULT '' "; - break; - case 'DATE': - $sDataType = " CHAR(19) "; + $oConstraint = $this->dropFieldConstraint( $sTable, $sColumn ); + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine; + return $sSQL; + } + + public function generateAddColumnSQL ($sTable, $sColumn, $aParameters) + { + if (isset( $aParameters['Type'] ) && isset( $aParameters['Null'] )) { + $sDefault = ""; + $sType = $aParameters['Type']; + $sDataType = $aParameters['Type']; + if (! in_array( $sDataType, array ("TEXT","DATE" + ) )) { + $sType = substr( $sType, 0, strpos( $sType, '(' ) ); + } + switch ($sType) { + case 'VARCHAR': + case 'TEXT': + $sDefault = " DEFAULT '' "; + break; + case 'DATE': + $sDataType = " CHAR(19) "; $sDefault = " DEFAULT '0000-00-00' "; // The date data type to use char (19) - break; - case 'INT': - case 'FLOAT': - $sDataType = $sType; - $sDefault = " DEFAULT 0 "; - break; - } - $sSQL = "ALTER TABLE " . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " ADD " . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . " " . $aParameters['Type']; - if ($aParameters['Null'] == 'YES') { - $sSQL .= " NULL"; - } else { - $sSQL .= " NOT NULL " . $sDefault; - - } - } + break; + case 'INT': + case 'FLOAT': + $sDataType = $sType; + $sDefault = " DEFAULT 0 "; + break; + } + $sSQL = "ALTER TABLE " . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " ADD " . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . " " . $aParameters['Type']; + if ($aParameters['Null'] == 'YES') { + $sSQL .= " NULL"; + } else { + $sSQL .= " NOT NULL " . $sDefault; + + } + } /*if ($aParameters['Key'] == 'PRI') { - $sKeys .= 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . - ' ADD PRIMARY KEY (' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ')' . $this->sEndLine; - }*/ - if (isset( $aParameters['AI'] )) { - if ($aParameters['AI'] == 1) { - $sSQL .= ' AUTO_INCREMENT'; - } else { - if ($aParameters['Default'] != '') { - $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; - } - } - } else { - if (isset( $aParameters['Default'] ) && $aParameters['Default'] != '') { - $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; - } - } - $sSQL .= $this->sEndLine; - return $sSQL; - } - - public function generateChangeColumnSQL ($sTable, $sColumn, $aParameters, $sColumnNewName = '') - { - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter . ' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter; - if (isset( $aParameters['Type'] )) { - $sSQL .= ' ' . $aParameters['Type']; - } - if (isset( $aParameters['Null'] )) { - if ($aParameters['Null'] == 'YES') { - $sSQL .= ' NULL'; - } else { - $sSQL .= ' NOT NULL'; - } - } + $sKeys .= 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . + ' ADD PRIMARY KEY (' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ')' . $this->sEndLine; + }*/ + if (isset( $aParameters['AI'] )) { + if ($aParameters['AI'] == 1) { + $sSQL .= ' AUTO_INCREMENT'; + } else { + if ($aParameters['Default'] != '') { + $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } + } + } else { + if (isset( $aParameters['Default'] ) && $aParameters['Default'] != '') { + $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } + } + $sSQL .= $this->sEndLine; + return $sSQL; + } + + public function generateChangeColumnSQL ($sTable, $sColumn, $aParameters, $sColumnNewName = '') + { + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter . ' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter; + if (isset( $aParameters['Type'] )) { + $sSQL .= ' ' . $aParameters['Type']; + } + if (isset( $aParameters['Null'] )) { + if ($aParameters['Null'] == 'YES') { + $sSQL .= ' NULL'; + } else { + $sSQL .= ' NOT NULL'; + } + } //if (isset($aParameters['AI'])) { // if ($aParameters['AI'] == 1) { // $sSQL .= ' AUTO_INCREMENT'; @@ -181,413 +181,420 @@ class database extends database_base // } //} //else { - if (isset( $aParameters['Default'] )) { - if (trim( $aParameters['Default'] == '' ) && $aParameters['Type'] == 'datetime') { + if (isset( $aParameters['Default'] )) { + if (trim( $aParameters['Default'] == '' ) && $aParameters['Type'] == 'datetime') { //do nothing - } else - $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } else { + $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } //} - } - if (! isset( $aParameters['Default'] ) && isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') { - $sSQL .= " DEFAULT NULL "; - } + } + if (! isset( $aParameters['Default'] ) && isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') { + $sSQL .= " DEFAULT NULL "; + } //} - $sSQL .= $this->sEndLine; - return $sSQL; - } - - public function generateGetPrimaryKeysSQL ($sTable) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' WHERE Seq_in_index = 1' . $this->sEndLine; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * Get primary key - * - * @param eter string $sTable - * @return string $sPrimaryKey - */ - public function getPrimaryKey ($sTable) - { - try { - $sSQL = " SELECT c.COLUMN_NAME " . " FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk , " . " INFORMATION_SCHEMA.KEY_COLUMN_USAGE c " . " WHERE pk.TABLE_NAME = '" . trim( $sTable ) . "' " . " AND CONSTRAINT_TYPE = 'PRIMARY KEY' " . " AND c.TABLE_NAME = pk.TABLE_NAME " . " AND c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME "; - $oPrimaryKey = $this->executeQuery( $sSQL ); - $aPrimaryKey = mssql_fetch_array( $oPrimaryKey ); - mssql_free_result( $oPrimaryKey ); - return $aPrimaryKey[0]; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * Get Field Constraint - * - * @param eter string $sTable - * @param eter string $sField - * @return string $sFieldConstraint - */ - public function getFieldConstraint ($sTable, $sField) - { - try { - $sSQL = " select a.name " . " from sysobjects a " . " inner join syscolumns b on a.id = b.cdefault " . " where a.xtype = 'D' " . " and a.parent_obj = (select id from sysobjects where xtype = 'U' and name = '" . trim( $sTable ) . "') " . " and b.name = '" . trim( $sField ) . "' "; - - $oFieldConstraint = $this->executeQuery( $sSQL ); - $aFieldConstraint = mssql_fetch_array( $oFieldConstraint ); - mssql_free_result( $oFieldConstraint ); - return $aFieldConstraint[0]; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * drop Field Constraint - * - * @param eter string $sTable - * @param eter string $sField - * @return object $oFieldConstraint - */ - public function dropFieldConstraint ($sTable, $sField) - { - try { - $sConstraint = $this->getFieldConstraint( $sTable, $sField ); - $sSQL = "ALTER TABLE " . $sTable . " DROP CONSTRAINT " . $sConstraint . $this->sEndLine; - $oFieldConstraint = $this->executeQuery( $sSQL ); - return $oFieldConstraint; - } catch (Exception $oException) { - throw $oException; - } - } - - public function generateDropPrimaryKeysSQL ($sTable) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - $sPrimayKey = $this->getPrimaryKey( $sTable ); - - return ' ALTER TABLE ' . $sTable . ' DROP CONSTRAINT ' . $sPrimayKey . $this->sEndLine; - } catch (Exception $oException) { - throw $oException; - } - } - - public function generateAddPrimaryKeysSQL ($sTable, $aPrimaryKeys) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD PRIMARY KEY ('; - foreach ($aPrimaryKeys as $sKey) { - $sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ','; - } - $sSQL = substr( $sSQL, 0, - 1 ) . ')' . $this->sEndLine; - return $sSQL; - } catch (Exception $oException) { - throw $oException; - } - } - - public function generateDropKeySQL ($sTable, $sIndexName) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - if ($sIndexName == '') { - throw new Exception( 'The column name cannot be empty!' ); - } - return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP INDEX ' . $this->sQuoteCharacter . $sIndexName . $this->sQuoteCharacter . $this->sEndLine; - } catch (Exception $oException) { - throw $oException; - } - } - - public function generateAddKeysSQL ($sTable, $indexName, $aKeys) - { - try { - $indexType = 'INDEX'; - if ($indexName == 'primaryKey' || $indexName == 'PRIMARY') { - $indexType = 'PRIMARY'; - $indexName = 'KEY'; - } - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD ' . $indexType . ' ' . $indexName . ' ('; - foreach ($aKeys as $sKey) { - $sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ', '; - } - $sSQL = substr( $sSQL, 0, - 2 ); - $sSQL .= ')' . $this->sEndLine; - return $sSQL; - } catch (Exception $oException) { - throw $oException; - } - } - - public function generateShowTablesSQL () - { - return 'SHOW TABLES' . $this->sEndLine; - } - - public function generateShowTablesLikeSQL ($sTable) - { - return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine; - } - - public function generateDescTableSQL ($sTable) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - return 'DESC ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine; - } catch (Exception $oException) { - throw $oException; - } - } - - public function generateTableIndexSQL ($sTable) - { - return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " " . $this->sEndLine; + $sSQL .= $this->sEndLine; + return $sSQL; + } + + public function generateGetPrimaryKeysSQL ($sTable) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' WHERE Seq_in_index = 1' . $this->sEndLine; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * Get primary key + * + * @param eter string $sTable + * @return string $sPrimaryKey + */ + public function getPrimaryKey ($sTable) + { + try { + $sSQL = " SELECT c.COLUMN_NAME " . " FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk , " . " INFORMATION_SCHEMA.KEY_COLUMN_USAGE c " . " WHERE pk.TABLE_NAME = '" . trim( $sTable ) . "' " . " AND CONSTRAINT_TYPE = 'PRIMARY KEY' " . " AND c.TABLE_NAME = pk.TABLE_NAME " . " AND c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME "; + $oPrimaryKey = $this->executeQuery( $sSQL ); + $aPrimaryKey = mssql_fetch_array( $oPrimaryKey ); + mssql_free_result( $oPrimaryKey ); + return $aPrimaryKey[0]; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * Get Field Constraint + * + * @param eter string $sTable + * @param eter string $sField + * @return string $sFieldConstraint + */ + public function getFieldConstraint ($sTable, $sField) + { + try { + $sSQL = " select a.name " . " from sysobjects a " . " inner join syscolumns b on a.id = b.cdefault " . " where a.xtype = 'D' " . " and a.parent_obj = (select id from sysobjects where xtype = 'U' and name = '" . trim( $sTable ) . "') " . " and b.name = '" . trim( $sField ) . "' "; + + $oFieldConstraint = $this->executeQuery( $sSQL ); + $aFieldConstraint = mssql_fetch_array( $oFieldConstraint ); + mssql_free_result( $oFieldConstraint ); + return $aFieldConstraint[0]; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * drop Field Constraint + * + * @param eter string $sTable + * @param eter string $sField + * @return object $oFieldConstraint + */ + public function dropFieldConstraint ($sTable, $sField) + { + try { + $sConstraint = $this->getFieldConstraint( $sTable, $sField ); + $sSQL = "ALTER TABLE " . $sTable . " DROP CONSTRAINT " . $sConstraint . $this->sEndLine; + $oFieldConstraint = $this->executeQuery( $sSQL ); + return $oFieldConstraint; + } catch (Exception $oException) { + throw $oException; + } + } + + public function generateDropPrimaryKeysSQL ($sTable) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + $sPrimayKey = $this->getPrimaryKey( $sTable ); + + return ' ALTER TABLE ' . $sTable . ' DROP CONSTRAINT ' . $sPrimayKey . $this->sEndLine; + } catch (Exception $oException) { + throw $oException; + } + } + + public function generateAddPrimaryKeysSQL ($sTable, $aPrimaryKeys) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD PRIMARY KEY ('; + foreach ($aPrimaryKeys as $sKey) { + $sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ','; + } + $sSQL = substr( $sSQL, 0, - 1 ) . ')' . $this->sEndLine; + return $sSQL; + } catch (Exception $oException) { + throw $oException; + } + } + + public function generateDropKeySQL ($sTable, $sIndexName) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + if ($sIndexName == '') { + throw new Exception( 'The column name cannot be empty!' ); + } + return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP INDEX ' . $this->sQuoteCharacter . $sIndexName . $this->sQuoteCharacter . $this->sEndLine; + } catch (Exception $oException) { + throw $oException; + } + } + + public function generateAddKeysSQL ($sTable, $indexName, $aKeys) + { + try { + $indexType = 'INDEX'; + if ($indexName == 'primaryKey' || $indexName == 'PRIMARY') { + $indexType = 'PRIMARY'; + $indexName = 'KEY'; + } + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD ' . $indexType . ' ' . $indexName . ' ('; + foreach ($aKeys as $sKey) { + $sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ', '; + } + $sSQL = substr( $sSQL, 0, - 2 ); + $sSQL .= ')' . $this->sEndLine; + return $sSQL; + } catch (Exception $oException) { + throw $oException; + } + } + + public function generateShowTablesSQL () + { + return 'SHOW TABLES' . $this->sEndLine; + } + + public function generateShowTablesLikeSQL ($sTable) + { + return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine; + } + + public function generateDescTableSQL ($sTable) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + return 'DESC ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine; + } catch (Exception $oException) { + throw $oException; + } + } + + public function generateTableIndexSQL ($sTable) + { + return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " " . $this->sEndLine; //return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " WHERE Key_name <> 'PRIMARY'" . $this->sEndLine; - } - - public function isConnected () - { - if (! $this->oConnection) - return false; - return $this->executeQuery( 'USE ' . $this->sDataBase ); - } - - public function logQuery ($sQuery) - { - try { - $found = false; - if (substr( $sQuery, 0, 6 ) == 'SELECT') - $found = true; - if (substr( $sQuery, 0, 4 ) == 'SHOW') - $found = true; - if (substr( $sQuery, 0, 4 ) == 'DESC') - $found = true; - if (substr( $sQuery, 0, 4 ) == 'USE ') - $found = true; - if (! $found) { - $logFile = PATH_DATA . 'log' . PATH_SEP . 'query.log'; - $fp = fopen( $logFile, 'a+' ); - fwrite( $fp, date( "Y-m-d H:i:s" ) . " " . $this->sDataBase . " " . $sQuery . "\n" ); - fclose( $fp ); - } - } catch (Exception $oException) { - } - } - - public function executeQuery ($sQuery) - { - $this->logQuery( $sQuery ); - - try { - if ($this->oConnection) { - @mssql_select_db( $this->sDataBase ); - - return @mssql_query( $sQuery ); - } else { - throw new Exception( 'invalid connection to database ' . $this->sDataBase ); - } - } catch (Exception $oException) { - $this->logQuery( $oException->getMessage() ); - throw $oException; - } - } - - public function countResults ($oDataset) - { - return @mssql_num_rows( $oDataset ); - } - - public function getRegistry ($oDataset) - { - return @mssql_fetch_array( $oDataset, $this->iFetchType ); - } - - public function close () - { - @mssql_close( $this->oConnection ); - } - - public function generateInsertSQL ($table, $data) - { - $fields = array (); - $values = array (); - foreach ($data as $field) { - $fields[] = $field['field']; - if (! is_null( $field['value'] )) { - switch ($field['type']) { - case 'text': - case 'date': - $values[] = "'" . addslashes( $field['value'] ) . "'"; - break; - case 'int': - default: - $values[] = addslashes( $field['value'] ); - break; - } - } else { - $values[] = $this->nullString; - } - } - $fields = array_map( array ($this,'putQuotes' - ), $fields ); - $sql = sprintf( "INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $values ) ); - return $sql; - } - - public function generateUpdateSQL ($table, $keys, $data) - { - $fields = array (); - $where = array (); - foreach ($data as $field) { - if (! is_null( $field['value'] )) { - switch ($field['type']) { - case 'text': - case 'date': - $fields[] = $this->putQuotes( $field['field'] ) . " = '" . addslashes( $field['value'] ) . "'"; - break; - case 'int': - default: - $fields[] = $this->putQuotes( $field['field'] ) . " = " . addslashes( $field['value'] ); - break; - } - } else { - $values[] = $this->nullString; - } - if (in_array( $field['field'], $keys )) { - $where[] = $fields[count( $fields ) - 1]; - } - } - $sql = sprintf( "UPDATE %s SET %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $where ) ); - return $sql; - } - - public function generateDeleteSQL ($table, $keys, $data) - { - $fields = array (); - $where = array (); - foreach ($data as $field) { - if (in_array( $field['field'], $keys )) { - if (! is_null( $field['value'] )) { - switch ($field['type']) { - case 'text': - case 'date': - $where[] = $this->putQuotes( $field['field'] ) . " = '" . addslashes( $field['value'] ) . "'"; - break; - case 'int': - default: - $where[] = $this->putQuotes( $field['field'] ) . " = " . addslashes( $field['value'] ); - break; - } - } else { - $values[] = $this->nullString; - } - } - } - $sql = sprintf( "DELETE FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) ); - return $sql; - } - - public function generateSelectSQL ($table, $keys, $data) - { - $fields = array (); - $where = array (); - foreach ($data as $field) { - if (in_array( $field['field'], $keys )) { - if (! is_null( $field['value'] )) { - switch ($field['type']) { - case 'text': - case 'date': - $where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'"; - break; - case 'int': - default: - $where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] ); - break; - } - } else { - $values[] = $this->nullString; - } - } - } - $sql = sprintf( "SELECT * FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) ); - return $sql; - } - - private function putQuotes ($element) - { - return $this->sQuoteCharacterBegin . $element . $this->sQuoteCharacterEnd; - } - - /*=================================================================================================*/ - /** - * concatString - * Generates a string equivalent to the chosen database. - * - * author Hector Cortez - * date 2010-08-04 - * - * @return string $sConcat - */ - function concatString() - { - $nums = func_num_args(); - $vars = func_get_args(); - $sConcat = ""; - for ($i = 0; $i < $nums; $i ++) { - if (isset( $vars[$i] )) { - $sConcat .= $vars[$i]; - if (($i + 1) < $nums) - $sConcat .= " + "; - } - } - return $sConcat; - } - + } + + public function isConnected () + { + if (! $this->oConnection) { + return false; + } + return $this->executeQuery( 'USE ' . $this->sDataBase ); + } + + public function logQuery ($sQuery) + { + try { + $found = false; + if (substr( $sQuery, 0, 6 ) == 'SELECT') { + $found = true; + } + if (substr( $sQuery, 0, 4 ) == 'SHOW') { + $found = true; + } + if (substr( $sQuery, 0, 4 ) == 'DESC') { + $found = true; + } + if (substr( $sQuery, 0, 4 ) == 'USE ') { + $found = true; + } + if (! $found) { + $logFile = PATH_DATA . 'log' . PATH_SEP . 'query.log'; + $fp = fopen( $logFile, 'a+' ); + fwrite( $fp, date( "Y-m-d H:i:s" ) . " " . $this->sDataBase . " " . $sQuery . "\n" ); + fclose( $fp ); + } + } catch (Exception $oException) { + } + } + + public function executeQuery ($sQuery) + { + $this->logQuery( $sQuery ); + + try { + if ($this->oConnection) { + @mssql_select_db( $this->sDataBase ); + + return @mssql_query( $sQuery ); + } else { + throw new Exception( 'invalid connection to database ' . $this->sDataBase ); + } + } catch (Exception $oException) { + $this->logQuery( $oException->getMessage() ); + throw $oException; + } + } + + public function countResults ($oDataset) + { + return @mssql_num_rows( $oDataset ); + } + + public function getRegistry ($oDataset) + { + return @mssql_fetch_array( $oDataset, $this->iFetchType ); + } + + public function close () + { + @mssql_close( $this->oConnection ); + } + + public function generateInsertSQL ($table, $data) + { + $fields = array (); + $values = array (); + foreach ($data as $field) { + $fields[] = $field['field']; + if (! is_null( $field['value'] )) { + switch ($field['type']) { + case 'text': + case 'date': + $values[] = "'" . addslashes( $field['value'] ) . "'"; + break; + case 'int': + default: + $values[] = addslashes( $field['value'] ); + break; + } + } else { + $values[] = $this->nullString; + } + } + $fields = array_map( array ($this,'putQuotes' + ), $fields ); + $sql = sprintf( "INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $values ) ); + return $sql; + } + + public function generateUpdateSQL ($table, $keys, $data) + { + $fields = array (); + $where = array (); + foreach ($data as $field) { + if (! is_null( $field['value'] )) { + switch ($field['type']) { + case 'text': + case 'date': + $fields[] = $this->putQuotes( $field['field'] ) . " = '" . addslashes( $field['value'] ) . "'"; + break; + case 'int': + default: + $fields[] = $this->putQuotes( $field['field'] ) . " = " . addslashes( $field['value'] ); + break; + } + } else { + $values[] = $this->nullString; + } + if (in_array( $field['field'], $keys )) { + $where[] = $fields[count( $fields ) - 1]; + } + } + $sql = sprintf( "UPDATE %s SET %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $where ) ); + return $sql; + } + + public function generateDeleteSQL ($table, $keys, $data) + { + $fields = array (); + $where = array (); + foreach ($data as $field) { + if (in_array( $field['field'], $keys )) { + if (! is_null( $field['value'] )) { + switch ($field['type']) { + case 'text': + case 'date': + $where[] = $this->putQuotes( $field['field'] ) . " = '" . addslashes( $field['value'] ) . "'"; + break; + case 'int': + default: + $where[] = $this->putQuotes( $field['field'] ) . " = " . addslashes( $field['value'] ); + break; + } + } else { + $values[] = $this->nullString; + } + } + } + $sql = sprintf( "DELETE FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) ); + return $sql; + } + + public function generateSelectSQL ($table, $keys, $data) + { + $fields = array (); + $where = array (); + foreach ($data as $field) { + if (in_array( $field['field'], $keys )) { + if (! is_null( $field['value'] )) { + switch ($field['type']) { + case 'text': + case 'date': + $where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'"; + break; + case 'int': + default: + $where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] ); + break; + } + } else { + $values[] = $this->nullString; + } + } + } + $sql = sprintf( "SELECT * FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) ); + return $sql; + } + + private function putQuotes ($element) + { + return $this->sQuoteCharacterBegin . $element . $this->sQuoteCharacterEnd; + } + + /*=================================================================================================*/ + /** + * concatString + * Generates a string equivalent to the chosen database. + * + * author Hector Cortez + * date 2010-08-04 + * + * @return string $sConcat + */ + public function concatString () + { + $nums = func_num_args(); + $vars = func_get_args(); + $sConcat = ""; + for ($i = 0; $i < $nums; $i ++) { + if (isset( $vars[$i] )) { + $sConcat .= $vars[$i]; + if (($i + 1) < $nums) { + $sConcat .= " + "; + } + } + } + return $sConcat; + } + /* - * query functions for class class.case.php - * - */ - /** - * concatString - * Generates a string equivalent to the case when - * - * @author Hector Cortez - * date 2010-08-04 - * - * @return string $sCompare - */ - function getCaseWhen($compareValue, $trueResult, $falseResult) - { - $sCompare = " CASE WHEN " . $compareValue . " THEN " . $trueResult . " ELSE " . $falseResult . " END "; - return $sCompare; - } - - /** - * Generates a string equivalent to create table ObjectPermission - * - * class.case.php - * function verifyTable() - * - * @return string $sql - */ - function createTableObjectPermission() - { + * query functions for class class.case.php + * + */ + /** + * concatString + * Generates a string equivalent to the case when + * + * @author Hector Cortez + * date 2010-08-04 + * + * @return string $sCompare + */ + public function getCaseWhen ($compareValue, $trueResult, $falseResult) + { + $sCompare = " CASE WHEN " . $compareValue . " THEN " . $trueResult . " ELSE " . $falseResult . " END "; + return $sCompare; + } + + /** + * Generates a string equivalent to create table ObjectPermission + * + * class.case.php + * function verifyTable() + * + * @return string $sql + */ + public function createTableObjectPermission () + { $sql = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='OBJECT_PERMISSION' AND xtype='U') CREATE TABLE OBJECT_PERMISSION ( OP_UID varchar(32) NOT NULL, @@ -600,28 +607,28 @@ class database extends database_base OP_OBJ_TYPE varchar(15) NOT NULL default 'ANY', OP_OBJ_UID varchar(32) NOT NULL, OP_ACTION varchar(10) NOT NULL default 'VIEW', - CONSTRAINT PK_PRO_UID PRIMARY KEY CLUSTERED (PRO_UID, TAS_UID,USR_UID, OP_TASK_SOURCE, OP_OBJ_UID) )"; - return $sql; - } - + CONSTRAINT PK_PRO_UID PRIMARY KEY CLUSTERED (PRO_UID, TAS_UID,USR_UID, OP_TASK_SOURCE, OP_OBJ_UID) )"; + return $sql; + } + /* - * query functions for class class.report.php - * - */ - /** - * Generates a string query - * - * class.report.php - * function generatedReport4() - * - * @return string $sql - */ - function getSelectReport4() - { - - $sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] "; - $sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME "; - + * query functions for class class.report.php + * + */ + /** + * Generates a string query + * + * class.report.php + * function generatedReport4() + * + * @return string $sql + */ + public function getSelectReport4 () + { + + $sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] "; + $sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME "; + $sql = "SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES, MIN(AD.DEL_DURATION) AS MIN, MAX(AD.DEL_DURATION) AS MAX, @@ -631,25 +638,25 @@ class database extends database_base LEFT JOIN APP_DELEGATION AS AD ON(A.APP_UID = AD.APP_UID AND AD.DEL_INDEX=1) LEFT JOIN USERS AS U ON(U.USR_UID = A.APP_INIT_USER) WHERE A.APP_UID<>'' - GROUP BY " . $sqlGroupBy; - - return $sql; - - } - - /** - * Generates a string query - * - * class.report.php - * function generatedReport4_filter() - * - * @return string $sql - */ - function getSelectReport4Filter($var) - { - $sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] "; - $sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME "; - + GROUP BY " . $sqlGroupBy; + + return $sql; + + } + + /** + * Generates a string query + * + * class.report.php + * function generatedReport4_filter() + * + * @return string $sql + */ + public function getSelectReport4Filter ($var) + { + $sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] "; + $sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME "; + $sql = " SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES, MIN(AD.DEL_DURATION) AS MIN, MAX(AD.DEL_DURATION) AS MAX, @@ -659,26 +666,26 @@ class database extends database_base LEFT JOIN APP_DELEGATION AS AD ON(A.APP_UID = AD.APP_UID AND AD.DEL_INDEX=1) LEFT JOIN USERS AS U ON(U.USR_UID = A.APP_INIT_USER) " . $var . " - GROUP BY " . $sqlGroupBy; - - return $sql; - - } - - /** - * Generates a string query - * - * class.report.php - * function generatedReport5() - * - * @return string $sql - */ - function getSelectReport5() - { - - $sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] "; - $sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME "; - + GROUP BY " . $sqlGroupBy; + + return $sql; + + } + + /** + * Generates a string query + * + * class.report.php + * function generatedReport5() + * + * @return string $sql + */ + public function getSelectReport5 () + { + + $sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] "; + $sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME "; + $sql = " SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES, MIN(AD.DEL_DURATION) AS MIN, MAX(AD.DEL_DURATION) AS MAX, @@ -688,26 +695,26 @@ class database extends database_base LEFT JOIN PROCESS AS P ON (P.PRO_UID = AD.PRO_UID) LEFT JOIN USERS AS U ON(U.USR_UID = AD.USR_UID) WHERE AD.APP_UID<>'' AND AD.DEL_FINISH_DATE IS NULL - GROUP BY " . $sqlGroupBy; - - return $sql; - - } - - /** - * Generates a string query - * - * class.report.php - * function generatedReport5_filter() - * - * @return string $sql - */ - function getSelectReport5Filter($var) - { - - $sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] "; - $sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME "; - + GROUP BY " . $sqlGroupBy; + + return $sql; + + } + + /** + * Generates a string query + * + * class.report.php + * function generatedReport5_filter() + * + * @return string $sql + */ + public function getSelectReport5Filter ($var) + { + + $sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] "; + $sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME "; + $sql = "SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES, MIN(AD.DEL_DURATION) AS MIN, MAX(AD.DEL_DURATION) AS MAX, @@ -717,45 +724,46 @@ class database extends database_base LEFT JOIN PROCESS AS P ON (P.PRO_UID = AD.PRO_UID) LEFT JOIN USERS AS U ON(U.USR_UID = AD.USR_UID) " . $var . " - GROUP BY " . $sqlGroupBy; - - return $sql; - } - + GROUP BY " . $sqlGroupBy; + + return $sql; + } + /* - * query functions for class class.net.php - * - */ - function getServerVersion($driver, $dbIP, $dbPort, $dbUser, $dbPasswd, $dbSourcename) - { - - if (strlen( trim( $dbIP ) ) <= 0) - $dbIP = DB_HOST; - if ($link = @mssql_connect( $dbIP, $dbUser, $dbPasswd )) { - @mssql_select_db( DB_NAME, $link ); - $oResult = @mssql_query( "select substring(@@version, 21, 6) + ' (' + CAST(SERVERPROPERTY ('productlevel') as varchar(10)) + ') ' + CAST(SERVERPROPERTY('productversion') AS VARCHAR(15)) + ' ' + CAST(SERVERPROPERTY ('edition') AS VARCHAR(25)) as version; ", $link ); - $aResult = @mssql_fetch_array( $oResult ); - @mssql_free_result( $oResult ); - $v = $aResult[0]; - } else { - throw new Exception( @mssql_error( $link ) ); - } - return (isset( $v )) ? $v : 'none'; - - } - + * query functions for class class.net.php + * + */ + public function getServerVersion ($driver, $dbIP, $dbPort, $dbUser, $dbPasswd, $dbSourcename) + { + + if (strlen( trim( $dbIP ) ) <= 0) { + $dbIP = DB_HOST; + } + if ($link = @mssql_connect( $dbIP, $dbUser, $dbPasswd )) { + @mssql_select_db( DB_NAME, $link ); + $oResult = @mssql_query( "select substring(@@version, 21, 6) + ' (' + CAST(SERVERPROPERTY ('productlevel') as varchar(10)) + ') ' + CAST(SERVERPROPERTY('productversion') AS VARCHAR(15)) + ' ' + CAST(SERVERPROPERTY ('edition') AS VARCHAR(25)) as version; ", $link ); + $aResult = @mssql_fetch_array( $oResult ); + @mssql_free_result( $oResult ); + $v = $aResult[0]; + } else { + throw new Exception( @mssql_error( $link ) ); + } + return (isset( $v )) ? $v : 'none'; + + } + /* - * query functions for class class.net.php - * - */ - function getDropTable($sTableName) - { - $sql = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='" . $sTableName . "' AND xtype='U') " . "DROP TABLE ['" . $sTableName . "']"; - return $sql; - } - - function getTableDescription($sTableName) - { + * query functions for class class.net.php + * + */ + public function getDropTable ($sTableName) + { + $sql = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='" . $sTableName . "' AND xtype='U') " . "DROP TABLE ['" . $sTableName . "']"; + return $sql; + } + + public function getTableDescription ($sTableName) + { $sql = " select column_name as Field, data_type + ' ' + (case data_type @@ -772,56 +780,56 @@ class database extends database_base when 'No' then 'NO' else 'YES' END) AS AsNull, COLUMN_DEFAULT as [Default] FROM information_schema.columns - WHERE table_name = '" . trim( $sTableName ) . "'" . " Order by Ordinal_Position asc "; - return $sql; - } - - function getFieldNull() - { - $fieldName = "AsNull"; - return $fieldName; - } - - function getValidate($validate) - { - $oValidate = true; - return $oValidate; - } - - /** - * Determines whether a table exists - * It is part of class.reportTables.php - */ - function reportTableExist() - { - $bExists = true; - $oConnection = mssql_connect( DB_HOST, DB_USER, DB_PASS ); - mssql_select_db( DB_NAME ); - $oDataset = mssql_query( 'SELECT COUNT(*) FROM REPORT_TABLE' ) || ($bExists = false); - - return $bExists; - } - - /** - * It is part of class.pagedTable.php - */ - function getLimitRenderTable($nCurrentPage, $nRowsPerPage) - { - $sql = ""; - return $sql; - } - - /** - * Determining the existence of a table - */ - function tableExists($table, $db) - { - $sql = "SELECT * FROM sysobjects WHERE name='" . $table . "' AND type='u'"; - $bExists = true; - $oConnection = mssql_connect( DB_HOST, DB_USER, DB_PASS ); - mssql_select_db( DB_NAME ); - $oDataset = mssql_query( $sql ) || ($bExists = false); - return $bExists; - } -} - + WHERE table_name = '" . trim( $sTableName ) . "'" . " Order by Ordinal_Position asc "; + return $sql; + } + + public function getFieldNull () + { + $fieldName = "AsNull"; + return $fieldName; + } + + public function getValidate ($validate) + { + $oValidate = true; + return $oValidate; + } + + /** + * Determines whether a table exists + * It is part of class.reportTables.php + */ + public function reportTableExist () + { + $bExists = true; + $oConnection = mssql_connect( DB_HOST, DB_USER, DB_PASS ); + mssql_select_db( DB_NAME ); + $oDataset = mssql_query( 'SELECT COUNT(*) FROM REPORT_TABLE' ) || ($bExists = false); + + return $bExists; + } + + /** + * It is part of class.pagedTable.php + */ + public function getLimitRenderTable ($nCurrentPage, $nRowsPerPage) + { + $sql = ""; + return $sql; + } + + /** + * Determining the existence of a table + */ + public function tableExists ($table, $db) + { + $sql = "SELECT * FROM sysobjects WHERE name='" . $table . "' AND type='u'"; + $bExists = true; + $oConnection = mssql_connect( DB_HOST, DB_USER, DB_PASS ); + mssql_select_db( DB_NAME ); + $oDataset = mssql_query( $sql ) || ($bExists = false); + return $bExists; + } +} + diff --git a/gulliver/system/class.database_mysql.php b/gulliver/system/class.database_mysql.php index 75fd83e8c..fe551636f 100755 --- a/gulliver/system/class.database_mysql.php +++ b/gulliver/system/class.database_mysql.php @@ -1,193 +1,193 @@ -. - * - * 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( 'database_base' ); - -class database extends database_base -{ - - public $iFetchType = MYSQL_ASSOC; - - /** - * class database constructor - * - * @param $sType adapter type - * @param $sServer server - * @param $sUser db user - * @param $sPass db user password - * @param $sDataBase Database name - */ - public function __construct ($sType = DB_ADAPTER, $sServer = DB_HOST, $sUser = DB_USER, $sPass = DB_PASS, $sDataBase = DB_NAME) - { - $this->sType = $sType; - $this->sServer = $sServer; - $this->sUser = $sUser; - $this->sPass = $sPass; - $this->sDataBase = $sDataBase; - $this->oConnection = @mysql_connect( $sServer, $sUser, $sPass ) || null; - $this->sQuoteCharacter = '`'; - $this->nullString = 'null'; - } - - /** - * generate the sql sentence to create a table - * - * @param $sTable table name - * @param $aColumns array of columns - * @return $sSql the sql sentence - */ - public function generateCreateTableSQL ($sTable, $aColumns) - { - $sKeys = ''; - $sSQL = 'CREATE TABLE IF NOT EXISTS ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '('; - - foreach ($aColumns as $sColumnName => $aParameters) { - if ($sColumnName != 'INDEXES') { - - if ($sColumnName != '' && isset( $aParameters['Type'] ) && $aParameters['Type'] != '') { - $sSQL .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ' ' . $aParameters['Type']; - - if (isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') { - $sSQL .= ' NULL'; - } else { - $sSQL .= ' NOT NULL'; - } - if (isset( $aParameters['Key'] ) && $aParameters['Key'] == 'PRI') { - $sKeys .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ','; - } - - if (isset( $aParameters['Default'] ) && $aParameters['Default'] != '') { - $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; - } - - $sSQL .= ','; - } - } - } - $sSQL = substr( $sSQL, 0, - 1 ); - if ($sKeys != '') { - $sSQL .= ',PRIMARY KEY(' . substr( $sKeys, 0, - 1 ) . ')'; - } - $sSQL .= ')' . $this->sEndLine; - - return $sSQL; - } - - /** - * generate a drop table sentence - * - * @param $sTable table name - * @return sql sentence string - */ - public function generateDropTableSQL ($sTable) - { - return 'DROP TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine; - } - - /** - * generate drop column sentence - * - * @param $sTable table name - * @param $sColumn column name - * @return $sSql sql sentence - */ - public function generateDropColumnSQL ($sTable, $sColumn) - { - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine; - return $sSQL; - } - - /** - * generate an add column sentence - * - * @param $sTable table name - * @param $sColumn column name - * @param $aParameters parameters of field like typo or if it can be null - * @return $sSql sql sentence - */ - public function generateAddColumnSQL ($sTable, $sColumn, $aParameters) - { - if (isset( $aParameters['Type'] ) && isset( $aParameters['Null'] )) { - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ' ' . $aParameters['Type']; - if ($aParameters['Null'] == 'YES') { - $sSQL .= ' NULL'; - } else { - $sSQL .= ' NOT NULL'; - } - } +. + * + * 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( 'database_base' ); + +class database extends database_base +{ + + public $iFetchType = MYSQL_ASSOC; + + /** + * class database constructor + * + * @param $sType adapter type + * @param $sServer server + * @param $sUser db user + * @param $sPass db user password + * @param $sDataBase Database name + */ + public function __construct ($sType = DB_ADAPTER, $sServer = DB_HOST, $sUser = DB_USER, $sPass = DB_PASS, $sDataBase = DB_NAME) + { + $this->sType = $sType; + $this->sServer = $sServer; + $this->sUser = $sUser; + $this->sPass = $sPass; + $this->sDataBase = $sDataBase; + $this->oConnection = @mysql_connect( $sServer, $sUser, $sPass ) || null; + $this->sQuoteCharacter = '`'; + $this->nullString = 'null'; + } + + /** + * generate the sql sentence to create a table + * + * @param $sTable table name + * @param $aColumns array of columns + * @return $sSql the sql sentence + */ + public function generateCreateTableSQL ($sTable, $aColumns) + { + $sKeys = ''; + $sSQL = 'CREATE TABLE IF NOT EXISTS ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '('; + + foreach ($aColumns as $sColumnName => $aParameters) { + if ($sColumnName != 'INDEXES') { + + if ($sColumnName != '' && isset( $aParameters['Type'] ) && $aParameters['Type'] != '') { + $sSQL .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ' ' . $aParameters['Type']; + + if (isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') { + $sSQL .= ' NULL'; + } else { + $sSQL .= ' NOT NULL'; + } + if (isset( $aParameters['Key'] ) && $aParameters['Key'] == 'PRI') { + $sKeys .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ','; + } + + if (isset( $aParameters['Default'] ) && $aParameters['Default'] != '') { + $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } + + $sSQL .= ','; + } + } + } + $sSQL = substr( $sSQL, 0, - 1 ); + if ($sKeys != '') { + $sSQL .= ',PRIMARY KEY(' . substr( $sKeys, 0, - 1 ) . ')'; + } + $sSQL .= ')' . $this->sEndLine; + + return $sSQL; + } + + /** + * generate a drop table sentence + * + * @param $sTable table name + * @return sql sentence string + */ + public function generateDropTableSQL ($sTable) + { + return 'DROP TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine; + } + + /** + * generate drop column sentence + * + * @param $sTable table name + * @param $sColumn column name + * @return $sSql sql sentence + */ + public function generateDropColumnSQL ($sTable, $sColumn) + { + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine; + return $sSQL; + } + + /** + * generate an add column sentence + * + * @param $sTable table name + * @param $sColumn column name + * @param $aParameters parameters of field like typo or if it can be null + * @return $sSql sql sentence + */ + public function generateAddColumnSQL ($sTable, $sColumn, $aParameters) + { + if (isset( $aParameters['Type'] ) && isset( $aParameters['Null'] )) { + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ' ' . $aParameters['Type']; + if ($aParameters['Null'] == 'YES') { + $sSQL .= ' NULL'; + } else { + $sSQL .= ' NOT NULL'; + } + } /*if ($aParameters['Key'] == 'PRI') { - $sKeys .= 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . + $sKeys .= 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD PRIMARY KEY (' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ')' . $this->sEndLine; - }*/ - if (isset( $aParameters['AI'] )) { - if ($aParameters['AI'] == 1) { - $sSQL .= ' AUTO_INCREMENT'; - } else { - if ($aParameters['Default'] != '') { - $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; - } - } - } else { - if (isset( $aParameters['Default'] )) { - $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; - } - } - $sSQL .= $this->sEndLine; - return $sSQL; - } - - /** - * generate a change column sentence - * - * @param $sTable table name - * @param $sColumn column name - * @param $aParameters parameters of field like typo or if it can be null - * @param $sColumnNewName column new name - * @return $sSql sql sentence - */ - public function generateChangeColumnSQL ($sTable, $sColumn, $aParameters, $sColumnNewName = '') - { - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter . ' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter; - if (isset( $aParameters['Type'] )) { - $sSQL .= ' ' . $aParameters['Type']; - } - if (isset( $aParameters['Null'] )) { - if ($aParameters['Null'] == 'YES') { - $sSQL .= ' NULL'; - } else { - $sSQL .= ' NOT NULL'; - } - } + }*/ + if (isset( $aParameters['AI'] )) { + if ($aParameters['AI'] == 1) { + $sSQL .= ' AUTO_INCREMENT'; + } else { + if ($aParameters['Default'] != '') { + $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } + } + } else { + if (isset( $aParameters['Default'] )) { + $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } + } + $sSQL .= $this->sEndLine; + return $sSQL; + } + + /** + * generate a change column sentence + * + * @param $sTable table name + * @param $sColumn column name + * @param $aParameters parameters of field like typo or if it can be null + * @param $sColumnNewName column new name + * @return $sSql sql sentence + */ + public function generateChangeColumnSQL ($sTable, $sColumn, $aParameters, $sColumnNewName = '') + { + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter . ' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter; + if (isset( $aParameters['Type'] )) { + $sSQL .= ' ' . $aParameters['Type']; + } + if (isset( $aParameters['Null'] )) { + if ($aParameters['Null'] == 'YES') { + $sSQL .= ' NULL'; + } else { + $sSQL .= ' NOT NULL'; + } + } //if (isset($aParameters['AI'])) { // if ($aParameters['AI'] == 1) { // $sSQL .= ' AUTO_INCREMENT'; @@ -201,454 +201,463 @@ class database extends database_base // } //} //else { - if (isset( $aParameters['Default'] )) { - if (trim( $aParameters['Default'] ) == '' && $aParameters['Type'] == 'datetime') { + if (isset( $aParameters['Default'] )) { + if (trim( $aParameters['Default'] ) == '' && $aParameters['Type'] == 'datetime') { //do nothing - } else - $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } else { + $sSQL .= " DEFAULT '" . $aParameters['Default'] . "'"; + } //} - } - if (! isset( $aParameters['Default'] ) && isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') { - $sSQL .= " DEFAULT NULL "; - } + } + if (! isset( $aParameters['Default'] ) && isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') { + $sSQL .= " DEFAULT NULL "; + } //} - $sSQL .= $this->sEndLine; - return $sSQL; - } - - /** - * Generate and get the primary key in a sentence - * - * @param $sTable table name - * @return $sSql sql sentence - */ - public function generateGetPrimaryKeysSQL ($sTable) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' WHERE Seq_in_index = 1' . $this->sEndLine; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * generate a sentence to drop the primary key - * - * @param $sTable table name - * @return sql sentence - */ - public function generateDropPrimaryKeysSQL ($sTable) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP PRIMARY KEY' . $this->sEndLine; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * generate a sentence to add multiple primary keys - * - * @param $sTable table name - * @param $aPrimaryKeys array of primary keys - * @return sql sentence - */ - public function generateAddPrimaryKeysSQL ($sTable, $aPrimaryKeys) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD PRIMARY KEY ('; - foreach ($aPrimaryKeys as $sKey) { - $sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ','; - } - $sSQL = substr( $sSQL, 0, - 1 ) . ')' . $this->sEndLine; - return $sSQL; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * generate a sentence to drop an index - * - * @param $sTable table name - * @param $sIndexName index name - * @return sql sentence - */ - public function generateDropKeySQL ($sTable, $sIndexName) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - if ($sIndexName == '') { - throw new Exception( 'The column name cannot be empty!' ); - } - return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP INDEX ' . $this->sQuoteCharacter . $sIndexName . $this->sQuoteCharacter . $this->sEndLine; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * generate a sentence to add indexes or primary keys - * - * @param $sTable table name - * @param $indexName index name - * @param $aKeys array of keys - * @return sql sentence - */ - - public function generateAddKeysSQL ($sTable, $indexName, $aKeys) - { - try { - $indexType = 'INDEX'; - if ($indexName == 'primaryKey' || $indexName == 'PRIMARY') { - $indexType = 'PRIMARY'; - $indexName = 'KEY'; - } - $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD ' . $indexType . ' ' . $indexName . ' ('; - foreach ($aKeys as $sKey) { - $sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ', '; - } - $sSQL = substr( $sSQL, 0, - 2 ); - $sSQL .= ')' . $this->sEndLine; - return $sSQL; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * generate a sentence to show the tables - * - * @return sql sentence - */ - public function generateShowTablesSQL () - { - return 'SHOW TABLES' . $this->sEndLine; - } - - /** - * generate a sentence to show the tables with a like sentence - * - * @return sql sentence - */ - public function generateShowTablesLikeSQL ($sTable) - { - return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine; - } - - /** - * generate a sentence to show the tables with a like sentence - * - * @param $sTable table name - * @return sql sentence - */ - public function generateDescTableSQL ($sTable) - { - try { - if ($sTable == '') { - throw new Exception( 'The table name cannot be empty!' ); - } - return 'DESC ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine; - } catch (Exception $oException) { - throw $oException; - } - } - - /** - * generate a sentence to show some table indexes - * - * @param $sTable table name - * @return sql sentence - */ - public function generateTableIndexSQL ($sTable) - { - return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " " . $this->sEndLine; + $sSQL .= $this->sEndLine; + return $sSQL; + } + + /** + * Generate and get the primary key in a sentence + * + * @param $sTable table name + * @return $sSql sql sentence + */ + public function generateGetPrimaryKeysSQL ($sTable) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' WHERE Seq_in_index = 1' . $this->sEndLine; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * generate a sentence to drop the primary key + * + * @param $sTable table name + * @return sql sentence + */ + public function generateDropPrimaryKeysSQL ($sTable) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP PRIMARY KEY' . $this->sEndLine; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * generate a sentence to add multiple primary keys + * + * @param $sTable table name + * @param $aPrimaryKeys array of primary keys + * @return sql sentence + */ + public function generateAddPrimaryKeysSQL ($sTable, $aPrimaryKeys) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD PRIMARY KEY ('; + foreach ($aPrimaryKeys as $sKey) { + $sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ','; + } + $sSQL = substr( $sSQL, 0, - 1 ) . ')' . $this->sEndLine; + return $sSQL; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * generate a sentence to drop an index + * + * @param $sTable table name + * @param $sIndexName index name + * @return sql sentence + */ + public function generateDropKeySQL ($sTable, $sIndexName) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + if ($sIndexName == '') { + throw new Exception( 'The column name cannot be empty!' ); + } + return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP INDEX ' . $this->sQuoteCharacter . $sIndexName . $this->sQuoteCharacter . $this->sEndLine; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * generate a sentence to add indexes or primary keys + * + * @param $sTable table name + * @param $indexName index name + * @param $aKeys array of keys + * @return sql sentence + */ + + public function generateAddKeysSQL ($sTable, $indexName, $aKeys) + { + try { + $indexType = 'INDEX'; + if ($indexName == 'primaryKey' || $indexName == 'PRIMARY') { + $indexType = 'PRIMARY'; + $indexName = 'KEY'; + } + $sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD ' . $indexType . ' ' . $indexName . ' ('; + foreach ($aKeys as $sKey) { + $sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ', '; + } + $sSQL = substr( $sSQL, 0, - 2 ); + $sSQL .= ')' . $this->sEndLine; + return $sSQL; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * generate a sentence to show the tables + * + * @return sql sentence + */ + public function generateShowTablesSQL () + { + return 'SHOW TABLES' . $this->sEndLine; + } + + /** + * generate a sentence to show the tables with a like sentence + * + * @return sql sentence + */ + public function generateShowTablesLikeSQL ($sTable) + { + return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine; + } + + /** + * generate a sentence to show the tables with a like sentence + * + * @param $sTable table name + * @return sql sentence + */ + public function generateDescTableSQL ($sTable) + { + try { + if ($sTable == '') { + throw new Exception( 'The table name cannot be empty!' ); + } + return 'DESC ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine; + } catch (Exception $oException) { + throw $oException; + } + } + + /** + * generate a sentence to show some table indexes + * + * @param $sTable table name + * @return sql sentence + */ + public function generateTableIndexSQL ($sTable) + { + return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " " . $this->sEndLine; //return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " WHERE Key_name <> 'PRIMARY'" . $this->sEndLine; - } - - /** - * execute a sentence to check if there is connection - * - * @return void - */ - public function isConnected () - { - if (! $this->oConnection) - return false; - return $this->executeQuery( 'USE ' . $this->sDataBase ); - } - - /** - * generate a sentence to show the tables with a like sentence - * - * @param $sQuery sql query string - * @return void - */ - public function logQuery ($sQuery) - { - try { - $found = false; - if (substr( $sQuery, 0, 6 ) == 'SELECT') - $found = true; - if (substr( $sQuery, 0, 4 ) == 'SHOW') - $found = true; - if (substr( $sQuery, 0, 4 ) == 'DESC') - $found = true; - if (substr( $sQuery, 0, 4 ) == 'USE ') - $found = true; - if (! $found) { - $logDir = PATH_DATA . 'log'; - if (! file_exists( $logDir )) - if (! mkdir( $logDir )) - return; - $logFile = "$logDir/query.log"; - $fp = fopen( $logFile, 'a+' ); - if ($fp !== false) { - fwrite( $fp, date( "Y-m-d H:i:s" ) . " " . $this->sDataBase . " " . $sQuery . "\n" ); - fclose( $fp ); - } - } - } catch (Exception $oException) { - } - } - - /** - * execute a sql query - * - * @param $sQuery table name - * @return void - */ - public function executeQuery ($sQuery) - { - $this->logQuery( $sQuery ); - - try { - if ($this->oConnection) { - @mysql_select_db( $this->sDataBase ); - - return @mysql_query( $sQuery ); - } else { - throw new Exception( 'invalid connection to database ' . $this->sDataBase ); - } - } catch (Exception $oException) { - $this->logQuery( $oException->getMessage() ); - throw $oException; - } - } - - /** - * count the rows of a dataset - * - * @param $oDataset - * @return the number of rows - */ - public function countResults ($oDataset) - { - return @mysql_num_rows( $oDataset ); - } - - /** - * count an array of the registry from a dataset - * - * @param $oDataset - * @return the registry - */ - public function getRegistry ($oDataset) - { - return @mysql_fetch_array( $oDataset, $this->iFetchType ); - } - - /** - * close the current connection - * - * @return void - */ - public function close () - { - @mysql_close( $this->oConnection ); - } - - public function generateInsertSQL ($table, $data) - { - $fields = array (); - $values = array (); - foreach ($data as $field) { - $fields[] = $field['field']; - if (! is_null( $field['value'] )) { - switch ($field['type']) { - case 'text': - case 'date': - $values[] = "'" . mysql_real_escape_string( $field['value'] ) . "'"; - break; - case 'int': - default: - $values[] = mysql_real_escape_string( $field['value'] ); - break; - } - } else { - $values[] = $this->nullString; - } - } - $fields = array_map( array ($this,'putQuotes' - ), $fields ); - $sql = sprintf( "INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $values ) ); - return $sql; - } - - public function generateUpdateSQL ($table, $keys, $data) - { - $fields = array (); - $where = array (); - foreach ($data as $field) { - if (! is_null( $field['value'] )) { - switch ($field['type']) { - case 'text': - case 'date': - $fields[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'"; - break; - case 'int': - default: - $fields[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] ); - break; - } - } else { - $values[] = $this->nullString; - } - if (in_array( $field['field'], $keys )) { - $where[] = $fields[count( $fields ) - 1]; - } - } - $sql = sprintf( "UPDATE %s SET %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $where ) ); - return $sql; - } - - public function generateDeleteSQL ($table, $keys, $data) - { - $fields = array (); - $where = array (); - foreach ($data as $field) { - if (in_array( $field['field'], $keys )) { - if (! is_null( $field['value'] )) { - switch ($field['type']) { - case 'text': - case 'date': - $where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'"; - break; - case 'int': - default: - $where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] ); - break; - } - } else { - $values[] = $this->nullString; - } - } - } - $sql = sprintf( "DELETE FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) ); - return $sql; - } - - public function generateSelectSQL ($table, $keys, $data) - { - $fields = array (); - $where = array (); - foreach ($data as $field) { - if (in_array( $field['field'], $keys )) { - if (! is_null( $field['value'] )) { - switch ($field['type']) { - case 'text': - case 'date': - $where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'"; - break; - case 'int': - default: - $where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] ); - break; - } - } else { - $values[] = $this->nullString; - } - } - } - $sql = sprintf( "SELECT * FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) ); - return $sql; - } - - private function putQuotes ($element) - { - return $this->sQuoteCharacter . $element . $this->sQuoteCharacter; - } - - /*=================================================================================================*/ - /** - * concatString - * Generates a string equivalent to the chosen database. - * - * author Hector Cortez - * date 2010-08-04 - * - * @return string $sConcat - */ - function concatString () - { - $nums = func_num_args(); - $vars = func_get_args(); - - $sConcat = " CONCAT("; - for ($i = 0; $i < $nums; $i ++) { - if (isset( $vars[$i] )) { - $sConcat .= $vars[$i]; - if (($i + 1) < $nums) - $sConcat .= ", "; - } - } - $sConcat .= ")"; - - return $sConcat; - - } - + } + + /** + * execute a sentence to check if there is connection + * + * @return void + */ + public function isConnected () + { + if (! $this->oConnection) { + return false; + } + return $this->executeQuery( 'USE ' . $this->sDataBase ); + } + + /** + * generate a sentence to show the tables with a like sentence + * + * @param $sQuery sql query string + * @return void + */ + public function logQuery ($sQuery) + { + try { + $found = false; + if (substr( $sQuery, 0, 6 ) == 'SELECT') { + $found = true; + } + if (substr( $sQuery, 0, 4 ) == 'SHOW') { + $found = true; + } + if (substr( $sQuery, 0, 4 ) == 'DESC') { + $found = true; + } + if (substr( $sQuery, 0, 4 ) == 'USE ') { + $found = true; + } + if (! $found) { + $logDir = PATH_DATA . 'log'; + if (! file_exists( $logDir )) { + if (! mkdir( $logDir )) { + return; + } + } + $logFile = "$logDir/query.log"; + $fp = fopen( $logFile, 'a+' ); + if ($fp !== false) { + fwrite( $fp, date( "Y-m-d H:i:s" ) . " " . $this->sDataBase . " " . $sQuery . "\n" ); + fclose( $fp ); + } + } + } catch (Exception $oException) { + } + } + + /** + * execute a sql query + * + * @param $sQuery table name + * @return void + */ + public function executeQuery ($sQuery) + { + $this->logQuery( $sQuery ); + + try { + if ($this->oConnection) { + @mysql_select_db( $this->sDataBase ); + + return @mysql_query( $sQuery ); + } else { + throw new Exception( 'invalid connection to database ' . $this->sDataBase ); + } + } catch (Exception $oException) { + $this->logQuery( $oException->getMessage() ); + throw $oException; + } + } + + /** + * count the rows of a dataset + * + * @param $oDataset + * @return the number of rows + */ + public function countResults ($oDataset) + { + return @mysql_num_rows( $oDataset ); + } + + /** + * count an array of the registry from a dataset + * + * @param $oDataset + * @return the registry + */ + public function getRegistry ($oDataset) + { + return @mysql_fetch_array( $oDataset, $this->iFetchType ); + } + + /** + * close the current connection + * + * @return void + */ + public function close () + { + @mysql_close( $this->oConnection ); + } + + public function generateInsertSQL ($table, $data) + { + $fields = array (); + $values = array (); + foreach ($data as $field) { + $fields[] = $field['field']; + if (! is_null( $field['value'] )) { + switch ($field['type']) { + case 'text': + case 'date': + $values[] = "'" . mysql_real_escape_string( $field['value'] ) . "'"; + break; + case 'int': + default: + $values[] = mysql_real_escape_string( $field['value'] ); + break; + } + } else { + $values[] = $this->nullString; + } + } + $fields = array_map( array ($this,'putQuotes' + ), $fields ); + $sql = sprintf( "INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $values ) ); + return $sql; + } + + public function generateUpdateSQL ($table, $keys, $data) + { + $fields = array (); + $where = array (); + foreach ($data as $field) { + if (! is_null( $field['value'] )) { + switch ($field['type']) { + case 'text': + case 'date': + $fields[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'"; + break; + case 'int': + default: + $fields[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] ); + break; + } + } else { + $values[] = $this->nullString; + } + if (in_array( $field['field'], $keys )) { + $where[] = $fields[count( $fields ) - 1]; + } + } + $sql = sprintf( "UPDATE %s SET %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $where ) ); + return $sql; + } + + public function generateDeleteSQL ($table, $keys, $data) + { + $fields = array (); + $where = array (); + foreach ($data as $field) { + if (in_array( $field['field'], $keys )) { + if (! is_null( $field['value'] )) { + switch ($field['type']) { + case 'text': + case 'date': + $where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'"; + break; + case 'int': + default: + $where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] ); + break; + } + } else { + $values[] = $this->nullString; + } + } + } + $sql = sprintf( "DELETE FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) ); + return $sql; + } + + public function generateSelectSQL ($table, $keys, $data) + { + $fields = array (); + $where = array (); + foreach ($data as $field) { + if (in_array( $field['field'], $keys )) { + if (! is_null( $field['value'] )) { + switch ($field['type']) { + case 'text': + case 'date': + $where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'"; + break; + case 'int': + default: + $where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] ); + break; + } + } else { + $values[] = $this->nullString; + } + } + } + $sql = sprintf( "SELECT * FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) ); + return $sql; + } + + private function putQuotes ($element) + { + return $this->sQuoteCharacter . $element . $this->sQuoteCharacter; + } + + /*=================================================================================================*/ + /** + * concatString + * Generates a string equivalent to the chosen database. + * + * author Hector Cortez + * date 2010-08-04 + * + * @return string $sConcat + */ + public function concatString () + { + $nums = func_num_args(); + $vars = func_get_args(); + + $sConcat = " CONCAT("; + for ($i = 0; $i < $nums; $i ++) { + if (isset( $vars[$i] )) { + $sConcat .= $vars[$i]; + if (($i + 1) < $nums) { + $sConcat .= ", "; + } + } + } + $sConcat .= ")"; + + return $sConcat; + + } + /* - * query functions for class class.case.php - * - */ - /** - * concatString - * Generates a string equivalent to the case when - * - * author Hector Cortez - * date 2010-08-04 - * - * @return string $sCompare - */ - function getCaseWhen ($compareValue, $trueResult, $falseResult) - { - $sCompare = "IF(" . $compareValue . ", " . $trueResult . ", " . $falseResult . ") "; - return $sCompare; - - } - - /** - * Generates a string equivalent to create table ObjectPermission - * - * class.case.php - * function verifyTable() - * - * @return string $sql - */ - function createTableObjectPermission () - { + * query functions for class class.case.php + * + */ + /** + * concatString + * Generates a string equivalent to the case when + * + * author Hector Cortez + * date 2010-08-04 + * + * @return string $sCompare + */ + public function getCaseWhen ($compareValue, $trueResult, $falseResult) + { + $sCompare = "IF(" . $compareValue . ", " . $trueResult . ", " . $falseResult . ") "; + return $sCompare; + + } + + /** + * Generates a string equivalent to create table ObjectPermission + * + * class.case.php + * function verifyTable() + * + * @return string $sql + */ + public function createTableObjectPermission () + { $sql = "CREATE TABLE IF NOT EXISTS `OBJECT_PERMISSION` ( `OP_UID` varchar(32) NOT NULL, `PRO_UID` varchar(32) NOT NULL, @@ -661,28 +670,28 @@ class database extends database_base `OP_OBJ_UID` varchar(32) NOT NULL, `OP_ACTION` varchar(10) NOT NULL default 'VIEW', KEY `PRO_UID` (`PRO_UID`,`TAS_UID`,`USR_UID`,`OP_TASK_SOURCE`,`OP_OBJ_UID`) - )ENGINE=MyISAM DEFAULT CHARSET=latin1;"; - return $sql; - } - + )ENGINE=MyISAM DEFAULT CHARSET=latin1;"; + return $sql; + } + /* - * query functions for class class.report.php - * - */ - /** - * Generates a string query - * - * class.report.php - * function generatedReport4() - * - * @return string $sql - */ - function getSelectReport4 () - { - - $sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER "; - $sqlGroupBy = " USER "; - + * query functions for class class.report.php + * + */ + /** + * Generates a string query + * + * class.report.php + * function generatedReport4() + * + * @return string $sql + */ + public function getSelectReport4 () + { + + $sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER "; + $sqlGroupBy = " USER "; + $sql = "SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES, MIN(AD.DEL_DURATION) AS MIN, MAX(AD.DEL_DURATION) AS MAX, @@ -692,25 +701,25 @@ class database extends database_base LEFT JOIN APP_DELEGATION AS AD ON(A.APP_UID = AD.APP_UID AND AD.DEL_INDEX=1) LEFT JOIN USERS AS U ON(U.USR_UID = A.APP_INIT_USER) WHERE A.APP_UID<>'' - GROUP BY " . $sqlGroupBy; - - return $sql; - - } - - /** - * Generates a string query - * - * class.report.php - * function generatedReport4_filter() - * - * @return string $sql - */ - function getSelectReport4Filter ($var) - { - $sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER "; - $sqlGroupBy = " USER "; - + GROUP BY " . $sqlGroupBy; + + return $sql; + + } + + /** + * Generates a string query + * + * class.report.php + * function generatedReport4_filter() + * + * @return string $sql + */ + public function getSelectReport4Filter ($var) + { + $sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER "; + $sqlGroupBy = " USER "; + $sql = " SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES, MIN(AD.DEL_DURATION) AS MIN, MAX(AD.DEL_DURATION) AS MAX, @@ -720,25 +729,25 @@ class database extends database_base LEFT JOIN APP_DELEGATION AS AD ON(A.APP_UID = AD.APP_UID AND AD.DEL_INDEX=1) LEFT JOIN USERS AS U ON(U.USR_UID = A.APP_INIT_USER) " . $var . " - GROUP BY " . $sqlGroupBy; - - return $sql; - - } - - /** - * Generates a string query - * - * class.report.php - * function generatedReport5() - * - * @return string $sql - */ - function getSelectReport5 () - { - $sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER "; - $sqlGroupBy = " USER "; - + GROUP BY " . $sqlGroupBy; + + return $sql; + + } + + /** + * Generates a string query + * + * class.report.php + * function generatedReport5() + * + * @return string $sql + */ + public function getSelectReport5 () + { + $sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER "; + $sqlGroupBy = " USER "; + $sql = " SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES, MIN(AD.DEL_DURATION) AS MIN, MAX(AD.DEL_DURATION) AS MAX, @@ -748,26 +757,26 @@ class database extends database_base LEFT JOIN PROCESS AS P ON (P.PRO_UID = AD.PRO_UID) LEFT JOIN USERS AS U ON(U.USR_UID = AD.USR_UID) WHERE AD.APP_UID<>'' AND AD.DEL_FINISH_DATE IS NULL - GROUP BY " . $sqlGroupBy; - - return $sql; - - } - - /** - * Generates a string query - * - * class.report.php - * function generatedReport5_filter() - * - * @return string $sql - */ - function getSelectReport5Filter ($var) - { - - $sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER "; - $sqlGroupBy = " USER "; - + GROUP BY " . $sqlGroupBy; + + return $sql; + + } + + /** + * Generates a string query + * + * class.report.php + * function generatedReport5_filter() + * + * @return string $sql + */ + public function getSelectReport5Filter ($var) + { + + $sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER "; + $sqlGroupBy = " USER "; + $sql = "SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES, MIN(AD.DEL_DURATION) AS MIN, MAX(AD.DEL_DURATION) AS MAX, @@ -777,105 +786,106 @@ class database extends database_base LEFT JOIN PROCESS AS P ON (P.PRO_UID = AD.PRO_UID) LEFT JOIN USERS AS U ON(U.USR_UID = AD.USR_UID) " . $var . " - GROUP BY " . $sqlGroupBy; - - return $sql; - } - + GROUP BY " . $sqlGroupBy; + + return $sql; + } + /* - * query functions for class class.net.php - * - */ - function getServerVersion ($driver, $dbIP, $dbPort, $dbUser, $dbPasswd, $dbSourcename) - { - - if ($link = @mysql_connect( $dbIP, $dbUser, $dbPasswd )) { - $v = @mysql_get_server_info(); - } else { - throw new Exception( @mysql_error( $link ) ); - } - return (isset( $v )) ? $v : 'none'; - - } - + * query functions for class class.net.php + * + */ + public function getServerVersion ($driver, $dbIP, $dbPort, $dbUser, $dbPasswd, $dbSourcename) + { + + if ($link = @mysql_connect( $dbIP, $dbUser, $dbPasswd )) { + $v = @mysql_get_server_info(); + } else { + throw new Exception( @mysql_error( $link ) ); + } + return (isset( $v )) ? $v : 'none'; + + } + /* - * query functions for class class.net.php, class.reportTables.php - * - */ - function getDropTable ($sTableName) - { - $sql = 'DROP TABLE IF EXISTS `' . $sTableName . '`'; - return $sql; - } - - function getTableDescription ($sTableName) - { - $sql = "DESC " . $sTableName; - return $sql; - } - - function getFieldNull () - { - $fieldName = "Null"; - return $fieldName; - } - - function getValidate ($validate) - { - $oValidate = $validate; - return $oValidate; - } - - /** - * Determines whether a table exists - * It is part of class.reportTables.php - */ - function reportTableExist () - { - $bExists = true; - $oConnection = mysql_connect( DB_HOST, DB_USER, DB_PASS ); - mysql_select_db( DB_NAME ); - $oDataset = mysql_query( 'SELECT COUNT(*) FROM REPORT_TABLE' ) || ($bExists = false); - - return $bExists; - } - - /** - * It is part of class.pagedTable.php - */ - function getLimitRenderTable ($nCurrentPage, $nRowsPerPage) - { - $sql = ' LIMIT ' . (($nCurrentPage - 1) * $nRowsPerPage) . ', ' . $nRowsPerPage; - return $sql; - } - - /** - * Determining the existence of a table - */ - function tableExists ($tableName, $database) - { - @mysql_select_db( $database ); - $tables = array (); - $tablesResult = mysql_query( "SHOW TABLES FROM $database;" ); - while ($row = @mysql_fetch_row( $tablesResult )) - $tables[] = $row[0]; - if (in_array( $tableName, $tables )) { - return TRUE; - } - return FALSE; - } - + * query functions for class class.net.php, class.reportTables.php + * + */ + public function getDropTable ($sTableName) + { + $sql = 'DROP TABLE IF EXISTS `' . $sTableName . '`'; + return $sql; + } + + public function getTableDescription ($sTableName) + { + $sql = "DESC " . $sTableName; + return $sql; + } + + public function getFieldNull () + { + $fieldName = "Null"; + return $fieldName; + } + + public function getValidate ($validate) + { + $oValidate = $validate; + return $oValidate; + } + + /** + * Determines whether a table exists + * It is part of class.reportTables.php + */ + public function reportTableExist () + { + $bExists = true; + $oConnection = mysql_connect( DB_HOST, DB_USER, DB_PASS ); + mysql_select_db( DB_NAME ); + $oDataset = mysql_query( 'SELECT COUNT(*) FROM REPORT_TABLE' ) || ($bExists = false); + + return $bExists; + } + + /** + * It is part of class.pagedTable.php + */ + public function getLimitRenderTable ($nCurrentPage, $nRowsPerPage) + { + $sql = ' LIMIT ' . (($nCurrentPage - 1) * $nRowsPerPage) . ', ' . $nRowsPerPage; + return $sql; + } + + /** + * Determining the existence of a table + */ + public function tableExists ($tableName, $database) + { + @mysql_select_db( $database ); + $tables = array (); + $tablesResult = mysql_query( "SHOW TABLES FROM $database;" ); + while ($row = @mysql_fetch_row( $tablesResult )) { + $tables[] = $row[0]; + } + if (in_array( $tableName, $tables )) { + return true; + } + return false; + } + /* * Determining the existence of a table (Depricated) - */ + */ // function tableExists ($table, $db) { - // $tables = mysql_list_tables ($db); - // while (list ($temp) = @mysql_fetch_array ($tables)) { - // if ($temp == $table) { - // return TRUE; - // } - // } - // return FALSE; - // } -} - + // $tables = mysql_list_tables ($db); + // while (list ($temp) = @mysql_fetch_array ($tables)) { + // if ($temp == $table) { + // return TRUE; + // } + // } + // return FALSE; + // } +} + diff --git a/workflow/engine/classes/class.cli.php b/workflow/engine/classes/class.cli.php index 0ab097300..29cc9b454 100755 --- a/workflow/engine/classes/class.cli.php +++ b/workflow/engine/classes/class.cli.php @@ -34,7 +34,7 @@ class CLI { public static $tasks = array (); - public static $currentTask = NULL; + public static $currentTask = null; /** * Adds a new task defined by it's name. @@ -46,7 +46,7 @@ class CLI public static function taskName ($name) { self::$currentTask = $name; - self::$tasks[$name] = array ('name' => $name,'description' => NULL,'args' => array (),'function' => NULL,'opt' => array ('short' => '','long' => array (),'descriptions' => array () + self::$tasks[$name] = array ('name' => $name,'description' => null,'args' => array (),'function' => null,'opt' => array ('short' => '','long' => array (),'descriptions' => array () ) ); } @@ -61,7 +61,7 @@ class CLI */ public static function taskDescription ($description) { - assert( self::$currentTask !== NULL ); + assert( self::$currentTask !== null ); self::$tasks[self::$currentTask]["description"] = $description; } @@ -76,7 +76,7 @@ class CLI */ public static function taskArg ($name, $optional = true, $multiple = false) { - assert( self::$currentTask !== NULL ); + assert( self::$currentTask !== null ); self::$tasks[self::$currentTask]["args"][$name] = array ('optional' => $optional,'multiple' => $multiple ); } @@ -87,14 +87,16 @@ class CLI * @param string $short short options * @param array $long long options */ - public static function taskOpt ($name, $description, $short, $long = NULL) + public static function taskOpt ($name, $description, $short, $long = null) { - assert( self::$currentTask !== NULL ); + assert( self::$currentTask !== null ); $opts = self::$tasks[self::$currentTask]["opt"]; - if ($short) + if ($short) { $opts['short'] .= $short; - if ($long) + } + if ($long) { $opts['long'][] = $long; + } $opts['descriptions'][$name] = array ('short' => $short,'long' => $long,'description' => $description ); self::$tasks[self::$currentTask]["opt"] = $opts; @@ -107,7 +109,7 @@ class CLI */ public static function taskRun ($function) { - assert( self::$currentTask !== NULL ); + assert( self::$currentTask !== null ); self::$tasks[self::$currentTask]["function"] = $function; } @@ -117,14 +119,15 @@ class CLI * @param array $args if defined, the task name should be argument 0 * @param array $opts options as returned by getopt */ - public static function help ($args, $opts = NULL) + public static function help ($args, $opts = null) { global $argv; $scriptName = $argv[0]; - if (is_array( $args )) + if (is_array( $args )) { $taskName = $args[0]; - else + } else { $taskName = $args; + } if (! $taskName) { echo "usage: $scriptName [options] [args]\n"; @@ -142,10 +145,12 @@ class CLI $valid_args = array (); foreach (self::$tasks[$taskName]['args'] as $arg => $data) { $arg = strtoupper( $arg ); - if ($data['multiple']) + if ($data['multiple']) { $arg = "$arg..."; - if ($data['optional']) + } + if ($data['optional']) { $arg = "[$arg]"; + } $valid_args[] = $arg; } $valid_args = join( " ", $valid_args ); @@ -162,10 +167,12 @@ EOT; $valid_options = array (); foreach (self::$tasks[$taskName]['opt']['descriptions'] as $opt => $data) { $optString = array (); - if ($data['short']) + if ($data['short']) { $optString[] = "-{$data['short']}"; - if ($data['long']) + } + if ($data['long']) { $optString[] = "--{$data['long']}"; + } $valid_options[] = " " . join( ", ", $optString ) . "\n\t" . wordwrap( $data['description'], 70, "\n\t" ); } $valid_options = join( "\n", $valid_options ); @@ -194,14 +201,15 @@ EOT; $args = $argv; $cliname = array_shift( $args ); $taskName = array_shift( $args ); - while ($taskName{0} == '-') + while ($taskName{0} == '-') { $taskName = array_shift( $args ); + } if (! $taskName) { echo self::error( "Specify a task from the list below." ) . "\n\n"; - self::help( NULL, NULL ); + self::help( null, null ); return; } - $taskData = NULL; + $taskData = null; foreach (self::$tasks as $name => $data) { if (strcasecmp( $name, $taskName ) === 0) { $taskData = $data; @@ -210,7 +218,7 @@ EOT; } if (! $taskData) { echo self::error( "Command not found: '$taskName'" ) . "\n\n"; - self::help( NULL, NULL ); + self::help( null, null ); return; } G::LoadThirdParty( 'pear/Console', 'Getopt' ); @@ -238,12 +246,15 @@ EOT; self::help( $taskName ); return; } - if (strpos( $optName, '--' ) === 0) + if (strpos( $optName, '--' ) === 0) { $optName = substr( $optName, 2 ); - if (! array_key_exists( $optName, $validOpts )) + } + if (! array_key_exists( $optName, $validOpts )) { throw new Exception( "option not found: $optName" ); - if (array_key_exists( $validOpts[$optName], $taskOpts )) + } + if (array_key_exists( $validOpts[$optName], $taskOpts )) { throw new Exception( "'$optName' specified more then once" ); + } $taskOpts[$validOpts[$optName]] = $optArg; } } catch (Exception $e) { @@ -323,18 +334,18 @@ EOT; * @param string $message the message to display * @param string $filename the log file to write messages */ - public static function logging ($message, $filename = NULL) + public static function logging ($message, $filename = null) { - static $log_file = NULL; + static $log_file = null; if (isset( $filename )) { $log_file = fopen( $filename, "a" ); fwrite( $log_file, " -- " . date( "c" ) . " " . $message . " --\n" ); } else { - if (isset( $log_file )) + if (isset( $log_file )) { fwrite( $log_file, $message ); + } echo $message; } } } -?> \ No newline at end of file diff --git a/workflow/engine/classes/class.pluginRegistry.php b/workflow/engine/classes/class.pluginRegistry.php index dcb7de10c..e5facf576 100755 --- a/workflow/engine/classes/class.pluginRegistry.php +++ b/workflow/engine/classes/class.pluginRegistry.php @@ -1,407 +1,407 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - */ - -/** - * - * @package workflow.engine.classes - */ - -class pluginDetail -{ - public $sNamespace; - public $sClassName; - public $sFriendlyName = null; - public $sDescription = null; - public $sSetupPage = null; - public $sFilename; - public $sPluginFolder = ''; - public $sCompanyLogo = ''; - public $iVersion = 0; - public $enabled = false; - public $aWorkspaces = null; - public $bPrivate = false; - - /** - * This function is the constructor of the pluginDetail class - * - * @param string $sNamespace - * @param string $sClassName - * @param string $sFilename - * @param string $sFriendlyName - * @param string $sPluginFolder - * @param string $sDescription - * @param string $sSetupPage - * @param integer $iVersion - * @return void - */ - public function __construct ($sNamespace, $sClassName, $sFilename, $sFriendlyName = '', $sPluginFolder = '', $sDescription = '', $sSetupPage = '', $iVersion = 0) - { - $this->sNamespace = $sNamespace; - $this->sClassName = $sClassName; - $this->sFriendlyName = $sFriendlyName; - $this->sDescription = $sDescription; - $this->sSetupPage = $sSetupPage; - $this->iVersion = $iVersion; - $this->sFilename = $sFilename; - if ($sPluginFolder == '') { - $this->sPluginFolder = $sNamespace; - } else { - $this->sPluginFolder = $sPluginFolder; - } - } -} - -/** - * - * @package workflow.engine.classes - */ - -class PMPluginRegistry -{ - private $_aPluginDetails = array (); - private $_aPlugins = array (); - private $_aMenus = array (); - private $_aFolders = array (); - private $_aTriggers = array (); - private $_aDashlets = array (); - private $_aReports = array (); - private $_aPmFunctions = array (); - private $_aRedirectLogin = array (); - private $_aSteps = array (); - private $_aCSSStyleSheets = array (); - private $_aToolbarFiles = array (); - private $_aCaseSchedulerPlugin = array (); - private $_aTaskExtendedProperties = array (); - private $_aDashboardPages = array (); - - /** - * Registry a plugin javascript to include with js core at same runtime - */ - private $_aJavascripts = array (); - - /** - * Contains all rest services classes from plugins - */ - private $_restServices = array (); - - private static $instance = null; - - /** - * This function is the constructor of the PMPluginRegistry class - * param - * - * @return void - */ - public function __construct () - { - } - - /** - * This function is instancing to this class - * param - * - * @return object - */ - function &getSingleton () - { - if (self::$instance == null) { - self::$instance = new PMPluginRegistry(); - } - return self::$instance; - } - - /** - * This function generates a storable representation of a value - * param - * - * @return void - */ - public function serializeInstance () - { - return serialize( self::$instance ); - } - - /** - * This function takes a single serialized variable and converts it back a code - * - * @param string $serialized - * @return void - */ - public function unSerializeInstance ($serialized) - { - if (self::$instance == null) { - self::$instance = new PMPluginRegistry(); - } - - $instance = unserialize( $serialized ); - self::$instance = $instance; - } - - /** - * Save the current instance to the plugin singleton - */ - public function save () - { - file_put_contents( PATH_DATA_SITE . 'plugin.singleton', $this->serializeInstance() ); - } - - /** - * Register the plugin in the singleton - * - * @param unknown_type $sClassName - * @param unknown_type $sNamespace - * @param unknown_type $sFilename - */ - public function registerPlugin ($sNamespace, $sFilename = null) - { +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + */ + +/** + * + * @package workflow.engine.classes + */ + +class pluginDetail +{ + public $sNamespace; + public $sClassName; + public $sFriendlyName = null; + public $sDescription = null; + public $sSetupPage = null; + public $sFilename; + public $sPluginFolder = ''; + public $sCompanyLogo = ''; + public $iVersion = 0; + public $enabled = false; + public $aWorkspaces = null; + public $bPrivate = false; + + /** + * This function is the constructor of the pluginDetail class + * + * @param string $sNamespace + * @param string $sClassName + * @param string $sFilename + * @param string $sFriendlyName + * @param string $sPluginFolder + * @param string $sDescription + * @param string $sSetupPage + * @param integer $iVersion + * @return void + */ + public function __construct ($sNamespace, $sClassName, $sFilename, $sFriendlyName = '', $sPluginFolder = '', $sDescription = '', $sSetupPage = '', $iVersion = 0) + { + $this->sNamespace = $sNamespace; + $this->sClassName = $sClassName; + $this->sFriendlyName = $sFriendlyName; + $this->sDescription = $sDescription; + $this->sSetupPage = $sSetupPage; + $this->iVersion = $iVersion; + $this->sFilename = $sFilename; + if ($sPluginFolder == '') { + $this->sPluginFolder = $sNamespace; + } else { + $this->sPluginFolder = $sPluginFolder; + } + } +} + +/** + * + * @package workflow.engine.classes + */ + +class PMPluginRegistry +{ + private $_aPluginDetails = array (); + private $_aPlugins = array (); + private $_aMenus = array (); + private $_aFolders = array (); + private $_aTriggers = array (); + private $_aDashlets = array (); + private $_aReports = array (); + private $_aPmFunctions = array (); + private $_aRedirectLogin = array (); + private $_aSteps = array (); + private $_aCSSStyleSheets = array (); + private $_aToolbarFiles = array (); + private $_aCaseSchedulerPlugin = array (); + private $_aTaskExtendedProperties = array (); + private $_aDashboardPages = array (); + + /** + * Registry a plugin javascript to include with js core at same runtime + */ + private $_aJavascripts = array (); + + /** + * Contains all rest services classes from plugins + */ + private $_restServices = array (); + + private static $instance = null; + + /** + * This function is the constructor of the PMPluginRegistry class + * param + * + * @return void + */ + public function __construct () + { + } + + /** + * This function is instancing to this class + * param + * + * @return object + */ + public function &getSingleton () + { + if (self::$instance == null) { + self::$instance = new PMPluginRegistry(); + } + return self::$instance; + } + + /** + * This function generates a storable representation of a value + * param + * + * @return void + */ + public function serializeInstance () + { + return serialize( self::$instance ); + } + + /** + * This function takes a single serialized variable and converts it back a code + * + * @param string $serialized + * @return void + */ + public function unSerializeInstance ($serialized) + { + if (self::$instance == null) { + self::$instance = new PMPluginRegistry(); + } + + $instance = unserialize( $serialized ); + self::$instance = $instance; + } + + /** + * Save the current instance to the plugin singleton + */ + public function save () + { + file_put_contents( PATH_DATA_SITE . 'plugin.singleton', $this->serializeInstance() ); + } + + /** + * Register the plugin in the singleton + * + * @param unknown_type $sClassName + * @param unknown_type $sNamespace + * @param unknown_type $sFilename + */ + public function registerPlugin ($sNamespace, $sFilename = null) + { //require_once ($sFilename); - - - $sClassName = $sNamespace . "plugin"; - $plugin = new $sClassName( $sNamespace, $sFilename ); - - if (isset( $this->_aPluginDetails[$sNamespace] )) { - $this->_aPluginDetails[$sNamespace]->iVersion = $plugin->iVersion; - - return; - } - - $detail = new pluginDetail( $sNamespace, $sClassName, $sFilename, $plugin->sFriendlyName, $plugin->sPluginFolder, $plugin->sDescription, $plugin->sSetupPage, $plugin->iVersion ); - - if (isset( $plugin->aWorkspaces )) { - $detail->aWorkspaces = $plugin->aWorkspaces; - } - - if (isset( $plugin->bPrivate )) { - $detail->bPrivate = $plugin->bPrivate; - } - + + + $sClassName = $sNamespace . "plugin"; + $plugin = new $sClassName( $sNamespace, $sFilename ); + + if (isset( $this->_aPluginDetails[$sNamespace] )) { + $this->_aPluginDetails[$sNamespace]->iVersion = $plugin->iVersion; + + return; + } + + $detail = new pluginDetail( $sNamespace, $sClassName, $sFilename, $plugin->sFriendlyName, $plugin->sPluginFolder, $plugin->sDescription, $plugin->sSetupPage, $plugin->iVersion ); + + if (isset( $plugin->aWorkspaces )) { + $detail->aWorkspaces = $plugin->aWorkspaces; + } + + if (isset( $plugin->bPrivate )) { + $detail->bPrivate = $plugin->bPrivate; + } + //if (isset($this->_aPluginDetails[$sNamespace])){ // $detail->enabled = $this->_aPluginDetails[$sNamespace]->enabled; //} - - - $this->_aPluginDetails[$sNamespace] = $detail; - } - - /** - * get the plugin details, by filename - * - * @param unknown_type $sFilename - */ - public function getPluginDetails ($sFilename) - { - foreach ($this->_aPluginDetails as $key => $row) { - if ($sFilename == baseName( $row->sFilename )) { - return $row; - } - } - return null; - } - - /** - * Enable the plugin in the singleton - * - * @param unknown_type $sNamespace - */ - public function enablePlugin ($sNamespace) - { - foreach ($this->_aPluginDetails as $namespace => $detail) { - if ($sNamespace == $namespace) { - $this->registerFolder( $sNamespace, $sNamespace, $detail->sPluginFolder ); + + + $this->_aPluginDetails[$sNamespace] = $detail; + } + + /** + * get the plugin details, by filename + * + * @param unknown_type $sFilename + */ + public function getPluginDetails ($sFilename) + { + foreach ($this->_aPluginDetails as $key => $row) { + if ($sFilename == baseName( $row->sFilename )) { + return $row; + } + } + return null; + } + + /** + * Enable the plugin in the singleton + * + * @param unknown_type $sNamespace + */ + public function enablePlugin ($sNamespace) + { + foreach ($this->_aPluginDetails as $namespace => $detail) { + if ($sNamespace == $namespace) { + $this->registerFolder( $sNamespace, $sNamespace, $detail->sPluginFolder ); //register the default directory, later we can have more - $this->_aPluginDetails[$sNamespace]->enabled = true; - $oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); - $this->_aPlugins[$detail->sNamespace] = $oPlugin; - if (method_exists( $oPlugin, 'enable' )) { - $oPlugin->enable(); - } - return true; - } - } - throw new Exception( "Unable to enable plugin '$sNamespace' (plugin not found)" ); - } - - /** - * disable the plugin in the singleton - * - * @param unknown_type $sNamespace - */ - public function disablePlugin ($sNamespace, $eventPlugin = 1) - { - $sw = false; - - foreach ($this->_aPluginDetails as $namespace => $detail) { - if ($namespace == $sNamespace) { - unset( $this->_aPluginDetails[$sNamespace] ); - - if ($eventPlugin == 1) { - $plugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); - $this->_aPlugins[$detail->sNamespace] = $plugin; - if (method_exists( $plugin, "disable" )) { - $plugin->disable(); - } - } - - $sw = true; - } - } - - if (! $sw) { - throw new Exception( "Unable to disable plugin '$sNamespace' (plugin not found)" ); - } - - foreach ($this->_aMenus as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aMenus[$key] ); - } - } - foreach ($this->_aFolders as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aFolders[$key] ); - } - } - foreach ($this->_aTriggers as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aTriggers[$key] ); - } - } - foreach ($this->_aDashlets as $key => $detail) { - if ($detail == $sNamespace) { - unset( $this->_aDashlets[$key] ); - } - } - foreach ($this->_aReports as $key => $detail) { - if ($detail == $sNamespace) { - unset( $this->_aReports[$key] ); - } - } - foreach ($this->_aPmFunctions as $key => $detail) { - if ($detail == $sNamespace) { - unset( $this->_aPmFunctions[$key] ); - } - } - foreach ($this->_aRedirectLogin as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aRedirectLogin[$key] ); - } - } - foreach ($this->_aSteps as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aSteps[$key] ); - } - } - foreach ($this->_aToolbarFiles as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aToolbarFiles[$key] ); - } - } - foreach ($this->_aCSSStyleSheets as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aCSSStyleSheets[$key] ); - } - } - foreach ($this->_aCaseSchedulerPlugin as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aCaseSchedulerPlugin[$key] ); - } - } - foreach ($this->_aTaskExtendedProperties as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aTaskExtendedProperties[$key] ); - } - } - foreach ($this->_aDashboardPages as $key => $detail) { - if ($detail->sNamespace == $sNamespace) { - unset( $this->_aDashboardPages[$key] ); - } - } - + $this->_aPluginDetails[$sNamespace]->enabled = true; + $oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); + $this->_aPlugins[$detail->sNamespace] = $oPlugin; + if (method_exists( $oPlugin, 'enable' )) { + $oPlugin->enable(); + } + return true; + } + } + throw new Exception( "Unable to enable plugin '$sNamespace' (plugin not found)" ); + } + + /** + * disable the plugin in the singleton + * + * @param unknown_type $sNamespace + */ + public function disablePlugin ($sNamespace, $eventPlugin = 1) + { + $sw = false; + + foreach ($this->_aPluginDetails as $namespace => $detail) { + if ($namespace == $sNamespace) { + unset( $this->_aPluginDetails[$sNamespace] ); + + if ($eventPlugin == 1) { + $plugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); + $this->_aPlugins[$detail->sNamespace] = $plugin; + if (method_exists( $plugin, "disable" )) { + $plugin->disable(); + } + } + + $sw = true; + } + } + + if (! $sw) { + throw new Exception( "Unable to disable plugin '$sNamespace' (plugin not found)" ); + } + + foreach ($this->_aMenus as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aMenus[$key] ); + } + } + foreach ($this->_aFolders as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aFolders[$key] ); + } + } + foreach ($this->_aTriggers as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aTriggers[$key] ); + } + } + foreach ($this->_aDashlets as $key => $detail) { + if ($detail == $sNamespace) { + unset( $this->_aDashlets[$key] ); + } + } + foreach ($this->_aReports as $key => $detail) { + if ($detail == $sNamespace) { + unset( $this->_aReports[$key] ); + } + } + foreach ($this->_aPmFunctions as $key => $detail) { + if ($detail == $sNamespace) { + unset( $this->_aPmFunctions[$key] ); + } + } + foreach ($this->_aRedirectLogin as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aRedirectLogin[$key] ); + } + } + foreach ($this->_aSteps as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aSteps[$key] ); + } + } + foreach ($this->_aToolbarFiles as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aToolbarFiles[$key] ); + } + } + foreach ($this->_aCSSStyleSheets as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aCSSStyleSheets[$key] ); + } + } + foreach ($this->_aCaseSchedulerPlugin as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aCaseSchedulerPlugin[$key] ); + } + } + foreach ($this->_aTaskExtendedProperties as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aTaskExtendedProperties[$key] ); + } + } + foreach ($this->_aDashboardPages as $key => $detail) { + if ($detail->sNamespace == $sNamespace) { + unset( $this->_aDashboardPages[$key] ); + } + } + //unregistering javascripts from this plugin - $this->unregisterJavascripts( $sNamespace ); + $this->unregisterJavascripts( $sNamespace ); //unregistering rest services from this plugin - $this->unregisterRestService( $sNamespace ); - } - - /** - * get status plugin in the singleton - * - * @param unknown_type $sNamespace - */ - public function getStatusPlugin ($sNamespace) - { - foreach ($this->_aPluginDetails as $namespace => $detail) { - if ($sNamespace == $namespace) { - if ($this->_aPluginDetails[$sNamespace]->enabled) { - return 'enabled'; - } else { - return 'disabled'; - } - } - } - return 0; - } - - /** - * Install a plugin archive. - * If pluginName is specified, the archive will - * only be installed if it contains this plugin. - * - * @return bool true if enabled, false otherwise - */ - public function installPluginArchive ($filename, $pluginName) - { - G::LoadThirdParty( "pear/Archive", "Tar" ); - $tar = new Archive_Tar( $filename ); - $files = $tar->listContent(); - $plugins = array (); - $namePlugin = array (); - foreach ($files as $f) { + $this->unregisterRestService( $sNamespace ); + } + + /** + * get status plugin in the singleton + * + * @param unknown_type $sNamespace + */ + public function getStatusPlugin ($sNamespace) + { + foreach ($this->_aPluginDetails as $namespace => $detail) { + if ($sNamespace == $namespace) { + if ($this->_aPluginDetails[$sNamespace]->enabled) { + return 'enabled'; + } else { + return 'disabled'; + } + } + } + return 0; + } + + /** + * Install a plugin archive. + * If pluginName is specified, the archive will + * only be installed if it contains this plugin. + * + * @return bool true if enabled, false otherwise + */ + public function installPluginArchive ($filename, $pluginName) + { + G::LoadThirdParty( "pear/Archive", "Tar" ); + $tar = new Archive_Tar( $filename ); + $files = $tar->listContent(); + $plugins = array (); + $namePlugin = array (); + foreach ($files as $f) { //if (preg_match("/^([\w\.]*).ini$/", $f["filename"], $matches)) { - if (preg_match( "/^(.*pluginConfig)\.ini$/", $f["filename"], $matches )) { - $plugins[] = $matches[1]; - } - if (preg_match( "/^.*($pluginName)\.php$/", $f["filename"], $matches )) { - $namePlugin[] = $matches[1]; - } - } - - if (count( $plugins ) > 1) { - throw new Exception( "Multiple plugins in one archive are not supported currently" ); - } - + if (preg_match( "/^(.*pluginConfig)\.ini$/", $f["filename"], $matches )) { + $plugins[] = $matches[1]; + } + if (preg_match( "/^.*($pluginName)\.php$/", $f["filename"], $matches )) { + $namePlugin[] = $matches[1]; + } + } + + if (count( $plugins ) > 1) { + throw new Exception( "Multiple plugins in one archive are not supported currently" ); + } + //if (isset($pluginName) && !in_array($pluginName, $plugins)) { - if (isset( $pluginName ) && ! in_array( $pluginName, $namePlugin )) { - throw new Exception( "Plugin '$pluginName' not found in archive" ); - } - + if (isset( $pluginName ) && ! in_array( $pluginName, $namePlugin )) { + throw new Exception( "Plugin '$pluginName' not found in archive" ); + } + //$pluginName = $plugins[0]; - $pluginFile = "$pluginName.php"; - + $pluginFile = "$pluginName.php"; + /* $oldPluginStatus = $this->getStatusPlugin($pluginFile); @@ -412,8 +412,8 @@ class PMPluginRegistry $oldDetails = NULL; $oldVersion = NULL; } - */ - + */ + //$pluginIni = $tar->extractInString("$pluginName.ini"); //$pluginConfig = parse_ini_string($pluginIni); /* @@ -434,612 +434,614 @@ class PMPluginRegistry if ($fVersionOld > $fVersionNew) { throw new Exception('A recent version of this plugin was already installed.'); } - */ - - $res = $tar->extract( PATH_PLUGINS ); - - if (! file_exists( PATH_PLUGINS . $pluginFile )) { - throw (new Exception( "File \"$pluginFile\" doesn't exist" )); - } - - require_once (PATH_PLUGINS . $pluginFile); - $details = $this->getPluginDetails( $pluginFile ); - - $this->installPlugin( $details->sNamespace ); - $this->setupPlugins(); - - $this->enablePlugin( $details->sNamespace ); - $this->save(); - } - - public function uninstallPlugin ($sNamespace) - { - $pluginFile = $sNamespace . ".php"; - - if (! file_exists( PATH_PLUGINS . $pluginFile )) { - throw (new Exception( "File \"$pluginFile\" doesn't exist" )); - } - + */ + + $res = $tar->extract( PATH_PLUGINS ); + + if (! file_exists( PATH_PLUGINS . $pluginFile )) { + throw (new Exception( "File \"$pluginFile\" doesn't exist" )); + } + + require_once (PATH_PLUGINS . $pluginFile); + $details = $this->getPluginDetails( $pluginFile ); + + $this->installPlugin( $details->sNamespace ); + $this->setupPlugins(); + + $this->enablePlugin( $details->sNamespace ); + $this->save(); + } + + public function uninstallPlugin ($sNamespace) + { + $pluginFile = $sNamespace . ".php"; + + if (! file_exists( PATH_PLUGINS . $pluginFile )) { + throw (new Exception( "File \"$pluginFile\" doesn't exist" )); + } + /////// - require_once (PATH_PLUGINS . $pluginFile); - - foreach ($this->_aPluginDetails as $namespace => $detail) { - if ($namespace == $sNamespace) { - $this->enablePlugin( $detail->sNamespace ); - $this->disablePlugin( $detail->sNamespace ); - + require_once (PATH_PLUGINS . $pluginFile); + + foreach ($this->_aPluginDetails as $namespace => $detail) { + if ($namespace == $sNamespace) { + $this->enablePlugin( $detail->sNamespace ); + $this->disablePlugin( $detail->sNamespace ); + /////// - $plugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); - $this->_aPlugins[$detail->sNamespace] = $plugin; - - if (method_exists( $plugin, "uninstall" )) { - $plugin->uninstall(); - } - + $plugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); + $this->_aPlugins[$detail->sNamespace] = $plugin; + + if (method_exists( $plugin, "uninstall" )) { + $plugin->uninstall(); + } + /////// - $this->save(); + $this->save(); /////// - $pluginDir = PATH_PLUGINS . $detail->sPluginFolder; - - if (isset( $detail->sFilename ) && ! empty( $detail->sFilename ) && file_exists( $detail->sFilename )) { - unlink( $detail->sFilename ); - } - - if (isset( $detail->sPluginFolder ) && ! empty( $detail->sPluginFolder ) && file_exists( $pluginDir )) { - G::rm_dir( $pluginDir ); - } - + $pluginDir = PATH_PLUGINS . $detail->sPluginFolder; + + if (isset( $detail->sFilename ) && ! empty( $detail->sFilename ) && file_exists( $detail->sFilename )) { + unlink( $detail->sFilename ); + } + + if (isset( $detail->sPluginFolder ) && ! empty( $detail->sPluginFolder ) && file_exists( $pluginDir )) { + G::rm_dir( $pluginDir ); + } + /////// - $this->uninstallPluginWorkspaces( array ($sNamespace) ); + $this->uninstallPluginWorkspaces( array ($sNamespace + ) ); /////// - break; - } - } - } - - public function uninstallPluginWorkspaces ($arrayPlugin) - { - G::LoadClass( "system" ); - G::LoadClass( "wsTools" ); - - $workspace = System::listWorkspaces(); - - foreach ($workspace as $indexWS => $ws) { - $wsPathDataSite = PATH_DATA . "sites" . PATH_SEP . $ws->name . PATH_SEP; - - if (file_exists( $wsPathDataSite . "plugin.singleton" )) { + break; + } + } + } + + public function uninstallPluginWorkspaces ($arrayPlugin) + { + G::LoadClass( "system" ); + G::LoadClass( "wsTools" ); + + $workspace = System::listWorkspaces(); + + foreach ($workspace as $indexWS => $ws) { + $wsPathDataSite = PATH_DATA . "sites" . PATH_SEP . $ws->name . PATH_SEP; + + if (file_exists( $wsPathDataSite . "plugin.singleton" )) { //G::LoadClass("plugin"); //Here we are loading all plug-ins registered //The singleton has a list of enabled plug-ins - - $pluginRegistry = &PMPluginRegistry::getSingleton(); - $pluginRegistry->unSerializeInstance( file_get_contents( $wsPathDataSite . "plugin.singleton" ) ); - + + + $pluginRegistry = &PMPluginRegistry::getSingleton(); + $pluginRegistry->unSerializeInstance( file_get_contents( $wsPathDataSite . "plugin.singleton" ) ); + /////// - $attributes = $pluginRegistry->getAttributes(); - - foreach ($arrayPlugin as $index => $value) { - if (isset( $attributes["_aPluginDetails"][$value] )) { - $pluginRegistry->disablePlugin( $value, 0 ); - } - } - + $attributes = $pluginRegistry->getAttributes(); + + foreach ($arrayPlugin as $index => $value) { + if (isset( $attributes["_aPluginDetails"][$value] )) { + $pluginRegistry->disablePlugin( $value, 0 ); + } + } + /////// - file_put_contents( $wsPathDataSite . "plugin.singleton", $pluginRegistry->serializeInstance() ); - } - } - } - - /** - * install the plugin - * - * @param unknown_type $sNamespace - */ - public function installPlugin ($sNamespace) - { - try { - foreach ($this->_aPluginDetails as $namespace => $detail) { - if ($sNamespace == $namespace) { - $oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); - $this->_aPlugins[$detail->sNamespace] = $oPlugin; - $oPlugin->install(); - } - } - } catch (Exception $e) { - global $G_PUBLISH; - $aMessage['MESSAGE'] = $e->getMessage(); - $G_PUBLISH = new Publisher(); - $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage ); - G::RenderPage( 'publish' ); - die(); - } - - } - - /** - * Register a menu in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sMenuId - * @param unknown_type $sFilename - */ - public function registerMenu ($sNamespace, $sMenuId, $sFilename) - { - $found = false; - foreach ($this->_aMenus as $row => $detail) { - if ($sMenuId == $detail->sMenuId && $sNamespace == $detail->sNamespace) { - $found = true; - } - } - if (! $found) { - $menuDetail = new menuDetail( $sNamespace, $sMenuId, $sFilename ); - $this->_aMenus[] = $menuDetail; - } - } - - /** - * Register a dashlet class in the singleton - * - * @param unknown_type $className - */ - public function registerDashlets ($namespace) - { - $found = false; - foreach ($this->_aDashlets as $row => $detail) { - if ($namespace == $detail) { - $found = true; - } - } - if (! $found) { - $this->_aDashlets[] = $namespace; - } - } - - /** - * Register a stylesheet in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sPage - */ - public function registerCss ($sNamespace, $sCssFile) - { - $found = false; - foreach ($this->_aCSSStyleSheets as $row => $detail) { - if ($sCssFile == $detail->sCssFile && $sNamespace == $detail->sNamespace) { - $detail->sCssFile = $sCssFile; - $found = true; - } - } - if (! $found) { - $cssFile = new cssFile( $sNamespace, $sCssFile ); - $this->_aCSSStyleSheets[] = $cssFile; - } - } - - /** - * return all css - * - * @return array - */ - public function getRegisteredCss () - { - return $this->_aCSSStyleSheets; - } - - /** - * Register a plugin javascript to run with core js script at same runtime - * - * @param string $sNamespace - * @param string $coreJsFile - * @param array/string $pluginJsFile - */ - public function registerJavascript ($sNamespace, $sCoreJsFile, $pluginJsFile) - { - - foreach ($this->_aJavascripts as $i => $js) { - if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { - if (is_string( $pluginJsFile )) { - if (! in_array( $pluginJsFile, $this->_aJavascripts[$i]->pluginJsFile )) { - $this->_aJavascripts[$i]->pluginJsFile[] = $pluginJsFile; - } - } elseif (is_array( $pluginJsFile )) { - $this->_aJavascripts[$i]->pluginJsFile = array_unique( array_merge( $pluginJsFile, $this->_aJavascripts[$i]->pluginJsFile ) ); - } else { - throw new Exception( 'Invalid third param, $pluginJsFile should be a string or array - ' . gettype( $pluginJsFile ) . ' given.' ); - } - return $this->_aJavascripts[$i]; - } - } - - $js = new StdClass(); - $js->sNamespace = $sNamespace; - $js->sCoreJsFile = $sCoreJsFile; - $js->pluginJsFile = Array (); - - if (is_string( $pluginJsFile )) { - $js->pluginJsFile[] = $pluginJsFile; - } elseif (is_array( $pluginJsFile )) { - $js->pluginJsFile = array_merge( $js->pluginJsFile, $pluginJsFile ); - } else { - throw new Exception( 'Invalid third param, $pluginJsFile should be a string or array - ' . gettype( $pluginJsFile ) . ' given.' ); - } - - $this->_aJavascripts[] = $js; - } - - /** - * return all plugin javascripts - * - * @return array - */ - public function getRegisteredJavascript () - { - return $this->_aJavascripts; - } - - /** - * return all plugin javascripts given a core js file, from all namespaces or a single namespace - * - * @param string $sCoreJsFile - * @param string $sNamespace - * @return array - */ - public function getRegisteredJavascriptBy ($sCoreJsFile, $sNamespace = '') - { - $scripts = array (); - - if ($sNamespace == '') { - foreach ($this->_aJavascripts as $i => $js) { - if ($sCoreJsFile == $js->sCoreJsFile) { - $scripts = array_merge( $scripts, $this->_aJavascripts[$i]->pluginJsFile ); - } - } - } else { - foreach ($this->_aJavascripts as $i => $js) { - if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { - $scripts = array_merge( $scripts, $this->_aJavascripts[$i]->pluginJsFile ); - } - } - } - return $scripts; - } - - /** - * unregister all javascripts from a namespace or a js core file given - * - * @param string $sNamespace - * @param string $sCoreJsFile - * @return array - */ - public function unregisterJavascripts ($sNamespace, $sCoreJsFile = '') - { - if ($sCoreJsFile == '') { + file_put_contents( $wsPathDataSite . "plugin.singleton", $pluginRegistry->serializeInstance() ); + } + } + } + + /** + * install the plugin + * + * @param unknown_type $sNamespace + */ + public function installPlugin ($sNamespace) + { + try { + foreach ($this->_aPluginDetails as $namespace => $detail) { + if ($sNamespace == $namespace) { + $oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); + $this->_aPlugins[$detail->sNamespace] = $oPlugin; + $oPlugin->install(); + } + } + } catch (Exception $e) { + global $G_PUBLISH; + $aMessage['MESSAGE'] = $e->getMessage(); + $G_PUBLISH = new Publisher(); + $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage ); + G::RenderPage( 'publish' ); + die(); + } + + } + + /** + * Register a menu in the singleton + * + * @param unknown_type $sNamespace + * @param unknown_type $sMenuId + * @param unknown_type $sFilename + */ + public function registerMenu ($sNamespace, $sMenuId, $sFilename) + { + $found = false; + foreach ($this->_aMenus as $row => $detail) { + if ($sMenuId == $detail->sMenuId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + if (! $found) { + $menuDetail = new menuDetail( $sNamespace, $sMenuId, $sFilename ); + $this->_aMenus[] = $menuDetail; + } + } + + /** + * Register a dashlet class in the singleton + * + * @param unknown_type $className + */ + public function registerDashlets ($namespace) + { + $found = false; + foreach ($this->_aDashlets as $row => $detail) { + if ($namespace == $detail) { + $found = true; + } + } + if (! $found) { + $this->_aDashlets[] = $namespace; + } + } + + /** + * Register a stylesheet in the singleton + * + * @param unknown_type $sNamespace + * @param unknown_type $sPage + */ + public function registerCss ($sNamespace, $sCssFile) + { + $found = false; + foreach ($this->_aCSSStyleSheets as $row => $detail) { + if ($sCssFile == $detail->sCssFile && $sNamespace == $detail->sNamespace) { + $detail->sCssFile = $sCssFile; + $found = true; + } + } + if (! $found) { + $cssFile = new cssFile( $sNamespace, $sCssFile ); + $this->_aCSSStyleSheets[] = $cssFile; + } + } + + /** + * return all css + * + * @return array + */ + public function getRegisteredCss () + { + return $this->_aCSSStyleSheets; + } + + /** + * Register a plugin javascript to run with core js script at same runtime + * + * @param string $sNamespace + * @param string $coreJsFile + * @param array/string $pluginJsFile + */ + public function registerJavascript ($sNamespace, $sCoreJsFile, $pluginJsFile) + { + + foreach ($this->_aJavascripts as $i => $js) { + if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { + if (is_string( $pluginJsFile )) { + if (! in_array( $pluginJsFile, $this->_aJavascripts[$i]->pluginJsFile )) { + $this->_aJavascripts[$i]->pluginJsFile[] = $pluginJsFile; + } + } elseif (is_array( $pluginJsFile )) { + $this->_aJavascripts[$i]->pluginJsFile = array_unique( array_merge( $pluginJsFile, $this->_aJavascripts[$i]->pluginJsFile ) ); + } else { + throw new Exception( 'Invalid third param, $pluginJsFile should be a string or array - ' . gettype( $pluginJsFile ) . ' given.' ); + } + return $this->_aJavascripts[$i]; + } + } + + $js = new StdClass(); + $js->sNamespace = $sNamespace; + $js->sCoreJsFile = $sCoreJsFile; + $js->pluginJsFile = Array (); + + if (is_string( $pluginJsFile )) { + $js->pluginJsFile[] = $pluginJsFile; + } elseif (is_array( $pluginJsFile )) { + $js->pluginJsFile = array_merge( $js->pluginJsFile, $pluginJsFile ); + } else { + throw new Exception( 'Invalid third param, $pluginJsFile should be a string or array - ' . gettype( $pluginJsFile ) . ' given.' ); + } + + $this->_aJavascripts[] = $js; + } + + /** + * return all plugin javascripts + * + * @return array + */ + public function getRegisteredJavascript () + { + return $this->_aJavascripts; + } + + /** + * return all plugin javascripts given a core js file, from all namespaces or a single namespace + * + * @param string $sCoreJsFile + * @param string $sNamespace + * @return array + */ + public function getRegisteredJavascriptBy ($sCoreJsFile, $sNamespace = '') + { + $scripts = array (); + + if ($sNamespace == '') { + foreach ($this->_aJavascripts as $i => $js) { + if ($sCoreJsFile == $js->sCoreJsFile) { + $scripts = array_merge( $scripts, $this->_aJavascripts[$i]->pluginJsFile ); + } + } + } else { + foreach ($this->_aJavascripts as $i => $js) { + if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { + $scripts = array_merge( $scripts, $this->_aJavascripts[$i]->pluginJsFile ); + } + } + } + return $scripts; + } + + /** + * unregister all javascripts from a namespace or a js core file given + * + * @param string $sNamespace + * @param string $sCoreJsFile + * @return array + */ + public function unregisterJavascripts ($sNamespace, $sCoreJsFile = '') + { + if ($sCoreJsFile == '') { // if $sCoreJsFile=='' unregister all js from this namespace - foreach ($this->_aJavascripts as $i => $js) { - if ($sNamespace == $js->sNamespace) { - unset( $this->_aJavascripts[$i] ); - } - } + foreach ($this->_aJavascripts as $i => $js) { + if ($sNamespace == $js->sNamespace) { + unset( $this->_aJavascripts[$i] ); + } + } // Re-index when all js were unregistered - $this->_aJavascripts = array_values( $this->_aJavascripts ); - } else { - foreach ($this->_aJavascripts as $i => $js) { - if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { - unset( $this->_aJavascripts[$i] ); + $this->_aJavascripts = array_values( $this->_aJavascripts ); + } else { + foreach ($this->_aJavascripts as $i => $js) { + if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { + unset( $this->_aJavascripts[$i] ); // Re-index for each js that was unregistered - $this->_aJavascripts = array_values( $this->_aJavascripts ); - } - } - } - } - - /** - * Register a reports class in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sMenuId - * @param unknown_type $sFilename - */ - public function registerReport ($sNamespace) - { - $found = false; - foreach ($this->_aReports as $row => $detail) { - if ($sNamespace == $detail) { - $found = true; - } - } - if (! $found) { - $this->_aReports[] = $sNamespace; - } - } - - /** - * Register a PmFunction class in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sMenuId - * @param unknown_type $sFilename - */ - public function registerPmFunction ($sNamespace) - { - $found = false; - foreach ($this->_aPmFunctions as $row => $detail) { - if ($sNamespace == $detail) { - $found = true; - } - } - if (! $found) { - $this->_aPmFunctions[] = $sNamespace; - } - } - - /** - * Register a redirectLogin class in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sRole - * @param unknown_type $sPath - */ - public function registerRedirectLogin ($sNamespace, $sRole, $sPathMethod) - { - $found = false; - foreach ($this->_aRedirectLogin as $row => $detail) { - if (($sNamespace == $detail->sNamespace) && ($sRole == $detail->sRoleCode)) { + $this->_aJavascripts = array_values( $this->_aJavascripts ); + } + } + } + } + + /** + * Register a reports class in the singleton + * + * @param unknown_type $sNamespace + * @param unknown_type $sMenuId + * @param unknown_type $sFilename + */ + public function registerReport ($sNamespace) + { + $found = false; + foreach ($this->_aReports as $row => $detail) { + if ($sNamespace == $detail) { + $found = true; + } + } + if (! $found) { + $this->_aReports[] = $sNamespace; + } + } + + /** + * Register a PmFunction class in the singleton + * + * @param unknown_type $sNamespace + * @param unknown_type $sMenuId + * @param unknown_type $sFilename + */ + public function registerPmFunction ($sNamespace) + { + $found = false; + foreach ($this->_aPmFunctions as $row => $detail) { + if ($sNamespace == $detail) { + $found = true; + } + } + if (! $found) { + $this->_aPmFunctions[] = $sNamespace; + } + } + + /** + * Register a redirectLogin class in the singleton + * + * @param unknown_type $sNamespace + * @param unknown_type $sRole + * @param unknown_type $sPath + */ + public function registerRedirectLogin ($sNamespace, $sRole, $sPathMethod) + { + $found = false; + foreach ($this->_aRedirectLogin as $row => $detail) { + if (($sNamespace == $detail->sNamespace) && ($sRole == $detail->sRoleCode)) { //Filters based on Workspace and Role Code - $found = true; - } - } - if (! $found) { - $this->_aRedirectLogin[] = new redirectDetail( $sNamespace, $sRole, $sPathMethod ); - } - } - - /** - * Register a folder for methods - * - * @param unknown_type $sFolderName - */ - public function registerFolder ($sNamespace, $sFolderId, $sFolderName) - { - $found = false; - foreach ($this->_aFolders as $row => $detail) { - if ($sFolderId == $detail->sFolderId && $sNamespace == $detail->sNamespace) { - $found = true; - } - } - - if (! $found) { - $this->_aFolders[] = new folderDetail( $sNamespace, $sFolderId, $sFolderName ); - } - } - - /** - * Register a step for process - * - * @param unknown_type $sFolderName - */ - public function registerStep ($sNamespace, $sStepId, $sStepName, $sStepTitle, $setupStepPage = '') - { - $found = false; - foreach ($this->_aSteps as $row => $detail) { - if ($sStepId == $detail->sStepId && $sNamespace == $detail->sNamespace) { - $found = true; - } - } - - if (! $found) { - $this->_aSteps[] = new stepDetail( $sNamespace, $sStepId, $sStepName, $sStepTitle, $setupStepPage ); - } - } - - /** - * return true if the $sFolderName is registered in the singleton - * - * @param unknown_type $sFolderName - */ - public function isRegisteredFolder ($sFolderName) - { - foreach ($this->_aFolders as $row => $folder) { - if ($sFolderName == $folder->sFolderName && is_dir( PATH_PLUGINS . $folder->sFolderName )) { - return true; - } elseif ($sFolderName == $folder->sFolderName && is_dir( PATH_PLUGINS . $folder->sNamespace . PATH_SEP . $folder->sFolderName )) { - return $folder->sNamespace; - } - } - return false; - } - - /** - * return all menus related to a menuId - * - * @param unknown_type $menuId - */ - public function getMenus ($menuId) - { - foreach ($this->_aMenus as $row => $detail) { - if ($menuId == $detail->sMenuId && file_exists( $detail->sFilename )) { - include ($detail->sFilename); - } - } - } - - /** - * return all dashlets classes registered - * - * @return array - */ - public function getDashlets () - { - return $this->_aDashlets; - } - - /** - * this function returns all reports registered - * - * @return array - */ - public function getReports () - { - return $this->_aReports; - $report = array (); - foreach ($this->_aReports as $row => $detail) { - $sClassName = str_replace( 'plugin', 'class', $this->_aPluginDetails[$detail]->sClassName ); - $report[] = $sClassName; - } - return $report; - } - - /** - * This function returns all pmFunctions registered - * @ array - */ - public function getPmFunctions () - { - return $this->_aPmFunctions; - $pmf = array (); - foreach ($this->_aPmFunctions as $row => $detail) { - $sClassName = str_replace( 'plugin', 'class', $this->_aPluginDetails[$detail]->sClassName ); - $pmf[] = $sClassName; - } - return $pmf; - } - - /** - * This function returns all steps registered - * - * @return string - */ - public function getSteps () - { - return $this->_aSteps; - } - - /** - * This function returns all redirect registered - * - * @return string - */ - public function getRedirectLogins () - { - return $this->_aRedirectLogin; - } - - /** - * execute all triggers related to a triggerId - * - * @param unknown_type $menuId - * @return object - */ - public function executeTriggers ($triggerId, $oData) - { - foreach ($this->_aTriggers as $row => $detail) { - if ($triggerId == $detail->sTriggerId) { + $found = true; + } + } + if (! $found) { + $this->_aRedirectLogin[] = new redirectDetail( $sNamespace, $sRole, $sPathMethod ); + } + } + + /** + * Register a folder for methods + * + * @param unknown_type $sFolderName + */ + public function registerFolder ($sNamespace, $sFolderId, $sFolderName) + { + $found = false; + foreach ($this->_aFolders as $row => $detail) { + if ($sFolderId == $detail->sFolderId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + + if (! $found) { + $this->_aFolders[] = new folderDetail( $sNamespace, $sFolderId, $sFolderName ); + } + } + + /** + * Register a step for process + * + * @param unknown_type $sFolderName + */ + public function registerStep ($sNamespace, $sStepId, $sStepName, $sStepTitle, $setupStepPage = '') + { + $found = false; + foreach ($this->_aSteps as $row => $detail) { + if ($sStepId == $detail->sStepId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + + if (! $found) { + $this->_aSteps[] = new stepDetail( $sNamespace, $sStepId, $sStepName, $sStepTitle, $setupStepPage ); + } + } + + /** + * return true if the $sFolderName is registered in the singleton + * + * @param unknown_type $sFolderName + */ + public function isRegisteredFolder ($sFolderName) + { + foreach ($this->_aFolders as $row => $folder) { + if ($sFolderName == $folder->sFolderName && is_dir( PATH_PLUGINS . $folder->sFolderName )) { + return true; + } elseif ($sFolderName == $folder->sFolderName && is_dir( PATH_PLUGINS . $folder->sNamespace . PATH_SEP . $folder->sFolderName )) { + return $folder->sNamespace; + } + } + return false; + } + + /** + * return all menus related to a menuId + * + * @param unknown_type $menuId + */ + public function getMenus ($menuId) + { + foreach ($this->_aMenus as $row => $detail) { + if ($menuId == $detail->sMenuId && file_exists( $detail->sFilename )) { + include ($detail->sFilename); + } + } + } + + /** + * return all dashlets classes registered + * + * @return array + */ + public function getDashlets () + { + return $this->_aDashlets; + } + + /** + * this function returns all reports registered + * + * @return array + */ + public function getReports () + { + return $this->_aReports; + $report = array (); + foreach ($this->_aReports as $row => $detail) { + $sClassName = str_replace( 'plugin', 'class', $this->_aPluginDetails[$detail]->sClassName ); + $report[] = $sClassName; + } + return $report; + } + + /** + * This function returns all pmFunctions registered + * @ array + */ + public function getPmFunctions () + { + return $this->_aPmFunctions; + $pmf = array (); + foreach ($this->_aPmFunctions as $row => $detail) { + $sClassName = str_replace( 'plugin', 'class', $this->_aPluginDetails[$detail]->sClassName ); + $pmf[] = $sClassName; + } + return $pmf; + } + + /** + * This function returns all steps registered + * + * @return string + */ + public function getSteps () + { + return $this->_aSteps; + } + + /** + * This function returns all redirect registered + * + * @return string + */ + public function getRedirectLogins () + { + return $this->_aRedirectLogin; + } + + /** + * execute all triggers related to a triggerId + * + * @param unknown_type $menuId + * @return object + */ + public function executeTriggers ($triggerId, $oData) + { + foreach ($this->_aTriggers as $row => $detail) { + if ($triggerId == $detail->sTriggerId) { //review all folders registered for this namespace - $found = false; - $classFile = ''; - - foreach ($this->_aFolders as $row => $folder) { - $fname = PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; - if ($detail->sNamespace == $folder->sNamespace && file_exists( $fname )) { - $found = true; - $classFile = $fname; - } - } - if ($found) { - require_once ($classFile); - $sClassName = substr( $this->_aPluginDetails[$detail->sNamespace]->sClassName, 0, 1 ) . str_replace( 'plugin', 'class', substr( $this->_aPluginDetails[$detail->sNamespace]->sClassName, 1 ) ); - $obj = new $sClassName(); - $methodName = $detail->sTriggerName; - $response = $obj->{$methodName}( $oData ); - if (PEAR::isError( $response )) { - print $response->getMessage(); - return; - } - return $response; - } else { - print "error in call method " . $detail->sTriggerName; - } - } - } - } - - /** - * verify if exists triggers related to a triggerId - * - * @param unknown_type $triggerId - */ - public function existsTrigger ($triggerId) - { - $found = false; - foreach ($this->_aTriggers as $row => $detail) { - if ($triggerId == $detail->sTriggerId) { + $found = false; + $classFile = ''; + + foreach ($this->_aFolders as $row => $folder) { + $fname = PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; + if ($detail->sNamespace == $folder->sNamespace && file_exists( $fname )) { + $found = true; + $classFile = $fname; + } + } + if ($found) { + require_once ($classFile); + $sClassName = substr( $this->_aPluginDetails[$detail->sNamespace]->sClassName, 0, 1 ) . str_replace( 'plugin', 'class', substr( $this->_aPluginDetails[$detail->sNamespace]->sClassName, 1 ) ); + $obj = new $sClassName(); + $methodName = $detail->sTriggerName; + $response = $obj->{$methodName}( $oData ); + if (PEAR::isError( $response )) { + print $response->getMessage(); + return; + } + return $response; + } else { + print "error in call method " . $detail->sTriggerName; + } + } + } + } + + /** + * verify if exists triggers related to a triggerId + * + * @param unknown_type $triggerId + */ + public function existsTrigger ($triggerId) + { + $found = false; + foreach ($this->_aTriggers as $row => $detail) { + if ($triggerId == $detail->sTriggerId) { //review all folders registered for this namespace - foreach ($this->_aFolders as $row => $folder) { - $fname = PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; - if ($detail->sNamespace == $folder->sNamespace && file_exists( $fname )) { - $found = true; - } - } - } - } - return $found; - } - - /** - * Return info related to a triggerId - * - * @param unknown_type $triggerId - * @return object - */ - public function getTriggerInfo ($triggerId) - { - $found = null; - foreach ($this->_aTriggers as $row => $detail) { - if ($triggerId == $detail->sTriggerId) { + foreach ($this->_aFolders as $row => $folder) { + $fname = PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; + if ($detail->sNamespace == $folder->sNamespace && file_exists( $fname )) { + $found = true; + } + } + } + } + return $found; + } + + /** + * Return info related to a triggerId + * + * @param unknown_type $triggerId + * @return object + */ + public function getTriggerInfo ($triggerId) + { + $found = null; + foreach ($this->_aTriggers as $row => $detail) { + if ($triggerId == $detail->sTriggerId) { //review all folders registered for this namespace - foreach ($this->_aFolders as $row => $folder) { - $fname = PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; - if ($detail->sNamespace == $folder->sNamespace && file_exists( $fname )) { - $found = $detail; - } - } - } - } - return $found; - } - - /** - * Register a trigger in the Singleton - * - * @param unknown_type $sTriggerId - * @param unknown_type $sMethodFunction - * @return void - */ - public function registerTrigger ($sNamespace, $sTriggerId, $sTriggerName) - { - $found = false; - foreach ($this->_aTriggers as $row => $detail) { - if ($sTriggerId == $detail->sTriggerId && $sNamespace == $detail->sNamespace) { - $found = true; - } - } - if (! $found) { - $triggerDetail = new triggerDetail( $sNamespace, $sTriggerId, $sTriggerName ); - $this->_aTriggers[] = $triggerDetail; - } - } - - /** - * get plugin - * - * @param unknown_type $sNamespace - * @return void - */ - public function &getPlugin ($sNamespace) - { - if (array_key_exists( $sNamespace, $this->_aPlugins )) { - return $this->_aPlugins[$sNamespace]; - } + foreach ($this->_aFolders as $row => $folder) { + $fname = PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; + if ($detail->sNamespace == $folder->sNamespace && file_exists( $fname )) { + $found = $detail; + } + } + } + } + return $found; + } + + /** + * Register a trigger in the Singleton + * + * @param unknown_type $sTriggerId + * @param unknown_type $sMethodFunction + * @return void + */ + public function registerTrigger ($sNamespace, $sTriggerId, $sTriggerName) + { + $found = false; + foreach ($this->_aTriggers as $row => $detail) { + if ($sTriggerId == $detail->sTriggerId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + if (! $found) { + $triggerDetail = new triggerDetail( $sNamespace, $sTriggerId, $sTriggerName ); + $this->_aTriggers[] = $triggerDetail; + } + } + + /** + * get plugin + * + * @param unknown_type $sNamespace + * @return void + */ + public function &getPlugin ($sNamespace) + { + if (array_key_exists( $sNamespace, $this->_aPlugins )) { + return $this->_aPlugins[$sNamespace]; + } /* $aDetails = KTUtil::arrayGet($this->_aPluginDetails, $sNamespace); if (empty($aDetails)) { @@ -1053,372 +1055,374 @@ class PMPluginRegistry $oPlugin =& new $sClassName($sFilename); $this->_aPlugins[$sNamespace] =& $oPlugin; return $oPlugin; - */ - } - - /** - * set company logo - * - * @param unknown_type $sNamespace - * @param unknown_type $filename - * @return void - */ - public function setCompanyLogo ($sNamespace, $filename) - { - $found = false; - foreach ($this->_aPluginDetails as $row => $detail) { - if ($sNamespace == $detail->sNamespace) { - $this->_aPluginDetails[$sNamespace]->sCompanyLogo = $filename; - } - } - } - - /** - * get company logo - * - * @param unknown_type $default - * @return void - */ - public function getCompanyLogo ($default) - { - $sCompanyLogo = $default; - foreach ($this->_aPluginDetails as $row => $detail) { - if (trim( $detail->sCompanyLogo ) != '') { - $sCompanyLogo = $detail->sCompanyLogo; - } - } - return $sCompanyLogo; - } - - /** - * get setup Plugins - * - * @param unknown_type $default - * @return void - */ - public function setupPlugins () - { - try { - $iPlugins = 0; - G::LoadClass( 'serverConfiguration' ); - $oServerConf = & serverConf::getSingleton(); - $oServerConf->addPlugin( SYS_SYS, $this->_aPluginDetails ); - foreach ($this->_aPluginDetails as $namespace => $detail) { - if (isset( $detail->enabled ) && $detail->enabled) { - if (! empty( $detail->sFilename ) && file_exists( $detail->sFilename )) { - if (strpos( $detail->sFilename, PATH_SEP ) !== false) { - $aux = explode( PATH_SEP, $detail->sFilename ); - } else { - $aux = explode( chr( 92 ), $detail->sFilename ); - } - $sFilename = PATH_PLUGINS . $aux[count( $aux ) - 1]; - if (! file_exists( $sFilename )) { - continue; - } - require_once $sFilename; - if (class_exists( $detail->sClassName )) { - $oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); - $this->_aPlugins[$detail->sNamespace] = $oPlugin; - $iPlugins ++; - $oPlugin->setup(); - } - } - } - } - $this->eevalidate(); - return $iPlugins; - } catch (Exception $e) { - global $G_PUBLISH; - $aMessage['MESSAGE'] = $e->getMessage(); - $G_PUBLISH = new Publisher(); - $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage ); - G::RenderPage( 'publish' ); - die(); - } - - } - - /** - * this function execute a Method - * - * @param string $sNamespace - * @param string $methodName - * @param object $oData - * @return object - */ - public function executeMethod ($sNamespace, $methodName, $oData) - { - $response = null; - try { - $details = $this->_aPluginDetails[$sNamespace]; - $pluginFolder = $details->sPluginFolder; - $className = $details->sClassName; - $classFile = PATH_PLUGINS . $pluginFolder . PATH_SEP . 'class.' . $pluginFolder . '.php'; - if (file_exists( $classFile )) { - $sClassName = substr_replace( $className, "class", - 6, 6 ); + */ + } + + /** + * set company logo + * + * @param unknown_type $sNamespace + * @param unknown_type $filename + * @return void + */ + public function setCompanyLogo ($sNamespace, $filename) + { + $found = false; + foreach ($this->_aPluginDetails as $row => $detail) { + if ($sNamespace == $detail->sNamespace) { + $this->_aPluginDetails[$sNamespace]->sCompanyLogo = $filename; + } + } + } + + /** + * get company logo + * + * @param unknown_type $default + * @return void + */ + public function getCompanyLogo ($default) + { + $sCompanyLogo = $default; + foreach ($this->_aPluginDetails as $row => $detail) { + if (trim( $detail->sCompanyLogo ) != '') { + $sCompanyLogo = $detail->sCompanyLogo; + } + } + return $sCompanyLogo; + } + + /** + * get setup Plugins + * + * @param unknown_type $default + * @return void + */ + public function setupPlugins () + { + try { + $iPlugins = 0; + G::LoadClass( 'serverConfiguration' ); + $oServerConf = & serverConf::getSingleton(); + $oServerConf->addPlugin( SYS_SYS, $this->_aPluginDetails ); + foreach ($this->_aPluginDetails as $namespace => $detail) { + if (isset( $detail->enabled ) && $detail->enabled) { + if (! empty( $detail->sFilename ) && file_exists( $detail->sFilename )) { + if (strpos( $detail->sFilename, PATH_SEP ) !== false) { + $aux = explode( PATH_SEP, $detail->sFilename ); + } else { + $aux = explode( chr( 92 ), $detail->sFilename ); + } + $sFilename = PATH_PLUGINS . $aux[count( $aux ) - 1]; + if (! file_exists( $sFilename )) { + continue; + } + require_once $sFilename; + if (class_exists( $detail->sClassName )) { + $oPlugin = new $detail->sClassName( $detail->sNamespace, $detail->sFilename ); + $this->_aPlugins[$detail->sNamespace] = $oPlugin; + $iPlugins ++; + $oPlugin->setup(); + } + } + } + } + $this->eevalidate(); + return $iPlugins; + } catch (Exception $e) { + global $G_PUBLISH; + $aMessage['MESSAGE'] = $e->getMessage(); + $G_PUBLISH = new Publisher(); + $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage ); + G::RenderPage( 'publish' ); + die(); + } + + } + + /** + * this function execute a Method + * + * @param string $sNamespace + * @param string $methodName + * @param object $oData + * @return object + */ + public function executeMethod ($sNamespace, $methodName, $oData) + { + $response = null; + try { + $details = $this->_aPluginDetails[$sNamespace]; + $pluginFolder = $details->sPluginFolder; + $className = $details->sClassName; + $classFile = PATH_PLUGINS . $pluginFolder . PATH_SEP . 'class.' . $pluginFolder . '.php'; + if (file_exists( $classFile )) { + $sClassName = substr_replace( $className, "class", - 6, 6 ); //$sClassName = str_replace ( 'plugin', 'class', $className ); - if (! class_exists( $sClassName )) { - require_once $classFile; - } - $obj = new $sClassName(); - if (! in_array( $methodName, get_class_methods( $obj ) )) { - throw (new Exception( "The method '$methodName' doesn't exist in class '$sClassName' " )); - } - $obj->sNamespace = $details->sNamespace; - $obj->sClassName = $details->sClassName; - $obj->sFilename = $details->sFilename; - $obj->iVersion = $details->iVersion; - $obj->sFriendlyName = $details->sFriendlyName; - $obj->sPluginFolder = $details->sPluginFolder; - $response = $obj->{$methodName}( $oData ); - } - return $response; - } catch (Exception $e) { - throw ($e); - } - } - - /** - * this function gets Fields For Page on Setup - * - * @param string $sNamespace - * @return object - */ - public function getFieldsForPageSetup ($sNamespace) - { - $oData = null; - return $this->executeMethod( $sNamespace, 'getFieldsForPageSetup', $oData ); - } - /** - * this function updates Fields For Page on Setup - * - * @param string $sNamespace - * @return void - */ - public function updateFieldsForPageSetup ($sNamespace, $oData) - { - if (! isset( $this->_aPluginDetails[$sNamespace] )) { - throw (new Exception( "The namespace '$sNamespace' doesn't exist in plugins folder." )); - } - - return $this->executeMethod( $sNamespace, 'updateFieldsForPageSetup', $oData ); - } - - public function eevalidate () - { - $fileL = PATH_DATA_SITE . 'license.dat'; - $fileS = PATH_DATA . 'license.dat'; - if ((file_exists( $fileL )) || (file_exists( $fileS ))) { + if (! class_exists( $sClassName )) { + require_once $classFile; + } + $obj = new $sClassName(); + if (! in_array( $methodName, get_class_methods( $obj ) )) { + throw (new Exception( "The method '$methodName' doesn't exist in class '$sClassName' " )); + } + $obj->sNamespace = $details->sNamespace; + $obj->sClassName = $details->sClassName; + $obj->sFilename = $details->sFilename; + $obj->iVersion = $details->iVersion; + $obj->sFriendlyName = $details->sFriendlyName; + $obj->sPluginFolder = $details->sPluginFolder; + $response = $obj->{$methodName}( $oData ); + } + return $response; + } catch (Exception $e) { + throw ($e); + } + } + + /** + * this function gets Fields For Page on Setup + * + * @param string $sNamespace + * @return object + */ + public function getFieldsForPageSetup ($sNamespace) + { + $oData = null; + return $this->executeMethod( $sNamespace, 'getFieldsForPageSetup', $oData ); + } + + /** + * this function updates Fields For Page on Setup + * + * @param string $sNamespace + * @return void + */ + public function updateFieldsForPageSetup ($sNamespace, $oData) + { + if (! isset( $this->_aPluginDetails[$sNamespace] )) { + throw (new Exception( "The namespace '$sNamespace' doesn't exist in plugins folder." )); + } + + return $this->executeMethod( $sNamespace, 'updateFieldsForPageSetup', $oData ); + } + + public function eevalidate () + { + $fileL = PATH_DATA_SITE . 'license.dat'; + $fileS = PATH_DATA . 'license.dat'; + if ((file_exists( $fileL )) || (file_exists( $fileS ))) { //Found a License - if (class_exists( 'pmLicenseManager' )) { - $sSerializedFile = PATH_DATA_SITE . 'lmn.singleton'; - $pmLicenseManagerO = & pmLicenseManager::getSingleton(); - if (file_exists( $sSerializedFile )) { - $pmLicenseManagerO->unSerializeInstance( file_get_contents( $sSerializedFile ) ); - } - } - } - } - - /** - * Register a toolbar for dynaform editor in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sToolbarId - * @param unknown_type $sFilename - */ - public function registerToolbarFile ($sNamespace, $sToolbarId, $sFilename) - { - $found = false; - foreach ($this->_aToolbarFiles as $row => $detail) { - if ($sToolbarId == $detail->sToolbarId && $sNamespace == $detail->sNamespace) { - $found = true; - } - } - if (! $found) { - $toolbarDetail = new toolbarDetail( $sNamespace, $sToolbarId, $sFilename ); - $this->_aToolbarFiles[] = $toolbarDetail; - } - } - - /** - * return all toolbar files related to a sToolbarId - * - * @param unknown_type $sToolbarId (NORMAL, GRID) - */ - public function getToolbarOptions ($sToolbarId) - { - foreach ($this->_aToolbarFiles as $row => $detail) { - if ($sToolbarId == $detail->sToolbarId && file_exists( $detail->sFilename )) { - include ($detail->sFilename); - } - } - } - - /** - * Register a Case Scheduler Plugin - */ - public function registerCaseSchedulerPlugin ($sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields) - { - $found = false; - foreach ($this->_aCaseSchedulerPlugin as $row => $detail) - if ($sActionId == $detail->sActionId && $sNamespace == $detail->sNamespace) { - $found = true; - } - - if (! $found) { - $this->_aCaseSchedulerPlugin[] = new caseSchedulerPlugin( $sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields ); - } - } - - /** - * This function returns all Case Scheduler Plugins registered - * - * @return string - */ - public function getCaseSchedulerPlugins () - { - return $this->_aCaseSchedulerPlugin; - } - - /** - * Register a Task Extended property page in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sPage - */ - - public function registerTaskExtendedProperty ($sNamespace, $sPage, $sName, $sIcon) - { - $found = false; - foreach ($this->_aTaskExtendedProperties as $row => $detail) { - if ($sPage == $detail->sPage && $sNamespace == $detail->sNamespace) { - $detail->sName = $sName; - $detail->sIcon = $sIcon; - $found = true; - } - } - if (! $found) { - $taskExtendedProperty = new taskExtendedProperty( $sNamespace, $sPage, $sName, $sIcon ); - $this->_aTaskExtendedProperties[] = $taskExtendedProperty; - } - } - - /** - * Register a dashboard page for cases in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sPage - * @param unknown_type $sName - * @param unknown_type $sIcon - */ - public function registerDashboardPage ($sNamespace, $sPage, $sName, $sIcon) - { - foreach ($this->_aDashboardPages as $row => $detail) { - if ($sPage == $detail->sPage && $sNamespace == $detail->sNamespace) { - $detail->sName = $sName; - $detail->sIcon = $sIcon; - $found = true; - } - } - if (! $found) { - $dashboardPage = new dashboardPage( $sNamespace, $sPage, $sName, $sIcon ); - $this->_aDashboardPages[] = $dashboardPage; - } - } - - /** - * Register a rest service class from a plugin to be served by processmaker - * - * @param string $sNamespace The namespace for the plugin - * @param string $classname The service (api) class name - * @param string $path (optional) the class file path, if it is not set the system will try resolve the - * file path from its classname. - */ - public function registerRestService ($sNamespace, $classname, $path = '') - { - $restService = new StdClass(); - $restService->sNamespace = $sNamespace; - $restService->classname = $classname; - - if (empty( $path )) { - $path = PATH_PLUGINS . $restService->sNamespace . "/services/rest/$classname.php"; - - if (! file_exists( $path )) { - $path = PATH_PLUGINS . $restService->sNamespace . "/services/rest/crud/$classname.php"; - } - } - - if (! file_exists( $path )) { - return false; - } - - $restService->path = $path; - $this->_restServices[] = $restService; - - return true; - } - - /** - * Unregister a rest service class of a plugin - * - * @param string $sNamespace The namespace for the plugin - */ - public function unregisterRestService ($sNamespace) - { - foreach ($this->_restServices as $i => $service) { - if ($sNamespace == $service->sNamespace) { - unset( $this->_restServices[$i] ); - } - } + if (class_exists( 'pmLicenseManager' )) { + $sSerializedFile = PATH_DATA_SITE . 'lmn.singleton'; + $pmLicenseManagerO = & pmLicenseManager::getSingleton(); + if (file_exists( $sSerializedFile )) { + $pmLicenseManagerO->unSerializeInstance( file_get_contents( $sSerializedFile ) ); + } + } + } + } + + /** + * Register a toolbar for dynaform editor in the singleton + * + * @param unknown_type $sNamespace + * @param unknown_type $sToolbarId + * @param unknown_type $sFilename + */ + public function registerToolbarFile ($sNamespace, $sToolbarId, $sFilename) + { + $found = false; + foreach ($this->_aToolbarFiles as $row => $detail) { + if ($sToolbarId == $detail->sToolbarId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + if (! $found) { + $toolbarDetail = new toolbarDetail( $sNamespace, $sToolbarId, $sFilename ); + $this->_aToolbarFiles[] = $toolbarDetail; + } + } + + /** + * return all toolbar files related to a sToolbarId + * + * @param unknown_type $sToolbarId (NORMAL, GRID) + */ + public function getToolbarOptions ($sToolbarId) + { + foreach ($this->_aToolbarFiles as $row => $detail) { + if ($sToolbarId == $detail->sToolbarId && file_exists( $detail->sFilename )) { + include ($detail->sFilename); + } + } + } + + /** + * Register a Case Scheduler Plugin + */ + public function registerCaseSchedulerPlugin ($sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields) + { + $found = false; + foreach ($this->_aCaseSchedulerPlugin as $row => $detail) { + if ($sActionId == $detail->sActionId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + + if (! $found) { + $this->_aCaseSchedulerPlugin[] = new caseSchedulerPlugin( $sNamespace, $sActionId, $sActionForm, $sActionSave, $sActionExecute, $sActionGetFields ); + } + } + + /** + * This function returns all Case Scheduler Plugins registered + * + * @return string + */ + public function getCaseSchedulerPlugins () + { + return $this->_aCaseSchedulerPlugin; + } + + /** + * Register a Task Extended property page in the singleton + * + * @param unknown_type $sNamespace + * @param unknown_type $sPage + */ + + public function registerTaskExtendedProperty ($sNamespace, $sPage, $sName, $sIcon) + { + $found = false; + foreach ($this->_aTaskExtendedProperties as $row => $detail) { + if ($sPage == $detail->sPage && $sNamespace == $detail->sNamespace) { + $detail->sName = $sName; + $detail->sIcon = $sIcon; + $found = true; + } + } + if (! $found) { + $taskExtendedProperty = new taskExtendedProperty( $sNamespace, $sPage, $sName, $sIcon ); + $this->_aTaskExtendedProperties[] = $taskExtendedProperty; + } + } + + /** + * Register a dashboard page for cases in the singleton + * + * @param unknown_type $sNamespace + * @param unknown_type $sPage + * @param unknown_type $sName + * @param unknown_type $sIcon + */ + public function registerDashboardPage ($sNamespace, $sPage, $sName, $sIcon) + { + foreach ($this->_aDashboardPages as $row => $detail) { + if ($sPage == $detail->sPage && $sNamespace == $detail->sNamespace) { + $detail->sName = $sName; + $detail->sIcon = $sIcon; + $found = true; + } + } + if (! $found) { + $dashboardPage = new dashboardPage( $sNamespace, $sPage, $sName, $sIcon ); + $this->_aDashboardPages[] = $dashboardPage; + } + } + + /** + * Register a rest service class from a plugin to be served by processmaker + * + * @param string $sNamespace The namespace for the plugin + * @param string $classname The service (api) class name + * @param string $path (optional) the class file path, if it is not set the system will try resolve the + * file path from its classname. + */ + public function registerRestService ($sNamespace, $classname, $path = '') + { + $restService = new StdClass(); + $restService->sNamespace = $sNamespace; + $restService->classname = $classname; + + if (empty( $path )) { + $path = PATH_PLUGINS . $restService->sNamespace . "/services/rest/$classname.php"; + + if (! file_exists( $path )) { + $path = PATH_PLUGINS . $restService->sNamespace . "/services/rest/crud/$classname.php"; + } + } + + if (! file_exists( $path )) { + return false; + } + + $restService->path = $path; + $this->_restServices[] = $restService; + + return true; + } + + /** + * Unregister a rest service class of a plugin + * + * @param string $sNamespace The namespace for the plugin + */ + public function unregisterRestService ($sNamespace) + { + foreach ($this->_restServices as $i => $service) { + if ($sNamespace == $service->sNamespace) { + unset( $this->_restServices[$i] ); + } + } // Re-index when all js were unregistered - $this->_restServices = array_values( $this->_restServices ); - } - - public function getRegisteredRestServices () - { - return $this->_restServices; - } - - public function getRegisteredRestClassFiles () - { - $restClassFiles = array (); - - foreach ($this->_restServices as $restService) { - $restClassFiles[] = $restService->path; - } - - return $restClassFiles; - } - - /** - * return all dashboard pages - * - * @return array - */ - public function getDashboardPages () - { - return $this->_aDashboardPages; - } - - /** - * return all tasl extended properties - * - * @return array - */ - public function getTaskExtendedProperties () - { - return $this->_aTaskExtendedProperties; - } - - public function registerDashboard () - { + $this->_restServices = array_values( $this->_restServices ); + } + + public function getRegisteredRestServices () + { + return $this->_restServices; + } + + public function getRegisteredRestClassFiles () + { + $restClassFiles = array (); + + foreach ($this->_restServices as $restService) { + $restClassFiles[] = $restService->path; + } + + return $restClassFiles; + } + + /** + * return all dashboard pages + * + * @return array + */ + public function getDashboardPages () + { + return $this->_aDashboardPages; + } + + /** + * return all tasl extended properties + * + * @return array + */ + public function getTaskExtendedProperties () + { + return $this->_aTaskExtendedProperties; + } + + public function registerDashboard () + { // Dummy function for backwards compatibility - } - - public function getAttributes () - { - return get_object_vars( $this ); - } -} - + } + + public function getAttributes () + { + return get_object_vars( $this ); + } +} + diff --git a/workflow/engine/classes/entities/FacetGroup.php b/workflow/engine/classes/entities/FacetGroup.php index 4e3302d8d..a1b8f0803 100644 --- a/workflow/engine/classes/entities/FacetGroup.php +++ b/workflow/engine/classes/entities/FacetGroup.php @@ -6,46 +6,44 @@ require_once ('Base.php'); * * @property $facetGroupName: The name of the facet (field name in solr index) * @property $facetGroupPrintName: The print name of the facet (Human readable - * description) + * description) * @property $facetGroupType: The type of facet group, field, daterange, filter, - * range + * range * @property $facetGroupId: An identifier to find group information * @property $facetItems: array of facet items * @author dev-HebertSaak - * + * */ class Entity_FacetGroup extends Entity_Base { - public $facetGroupName = ''; - public $facetGroupPrintName = ''; - public $facetGroupType = ''; // field, daterange, query - public $facetGroupId = ''; - public $facetItems = array (); - - private function __construct() - { - } - - static function createEmpty() - { - $obj = new Entity_FacetGroup (); - return $obj; - } - - static function createForInsert($data) - { - $obj = new Entity_FacetGroup (); - - $obj->initializeObject ($data); - - $requiredFields = array ( - "facetGroupName", - "facetItems" - ); - - $obj->validateRequiredFields ($requiredFields); - - return $obj; - } + public $facetGroupName = ''; + public $facetGroupPrintName = ''; + public $facetGroupType = ''; // field, daterange, query + public $facetGroupId = ''; + public $facetItems = array (); + + private function __construct () + { + } + + static function createEmpty () + { + $obj = new Entity_FacetGroup(); + return $obj; + } + + static function createForInsert ($data) + { + $obj = new Entity_FacetGroup(); + + $obj->initializeObject( $data ); + + $requiredFields = array ("facetGroupName","facetItems" + ); + + $obj->validateRequiredFields( $requiredFields ); + + return $obj; + } +} -} \ No newline at end of file diff --git a/workflow/engine/classes/entities/SolrUpdateDocument.php b/workflow/engine/classes/entities/SolrUpdateDocument.php index 6ce732516..7ca92231d 100644 --- a/workflow/engine/classes/entities/SolrUpdateDocument.php +++ b/workflow/engine/classes/entities/SolrUpdateDocument.php @@ -3,33 +3,31 @@ require_once ('Base.php'); class Entity_SolrUpdateDocument extends Entity_Base { - var $workspace = ''; - var $document = ''; - - private function __construct() - { - } - - static function createEmpty() - { - $obj = new Entity_SolrUpdateDocument (); - return $obj; - } - - static function createForRequest($data) - { - $obj = new Entity_SolrUpdateDocument (); - - $obj->initializeObject ($data); - - $requiredFields = array ( - "workspace", - "document" - ); - - $obj->validateRequiredFields ($requiredFields); - - return $obj; - } + var $workspace = ''; + var $document = ''; + + private function __construct () + { + } + + static function createEmpty () + { + $obj = new Entity_SolrUpdateDocument(); + return $obj; + } + + static function createForRequest ($data) + { + $obj = new Entity_SolrUpdateDocument(); + + $obj->initializeObject( $data ); + + $requiredFields = array ("workspace","document" + ); + + $obj->validateRequiredFields( $requiredFields ); + + return $obj; + } +} -} \ No newline at end of file diff --git a/workflow/engine/classes/triggers/class.pmTalendFunctions.php b/workflow/engine/classes/triggers/class.pmTalendFunctions.php index 87c2d4f2c..edbb13644 100755 --- a/workflow/engine/classes/triggers/class.pmTalendFunctions.php +++ b/workflow/engine/classes/triggers/class.pmTalendFunctions.php @@ -1,4 +1,5 @@ 1)); +function executeTalendWebservice ($wsdl, $message, $params = array()) +{ + $client = new SoapClient( $wsdl, array ('trace' => 1 + ) ); - //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($client, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($client, CURLOPT_PROXYPORT, $sysConf['proxy_port']); + //Apply proxy settings + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $client, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $client, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $client, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $client, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); } - if ($sysConf['proxy_user'] != '') { - curl_setopt($client, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); + + $params[0] = ""; + foreach ($params as $paramO) { + $params[] = "--context_param" . $paramO[0] . "=" . $paramO[1]; } - curl_setopt($client, CURLOPT_HTTPHEADER, array('Expect:')); - } + $result = $client->__SoapCall( 'runJob', array ($params + ) ); - $params[0]=""; - foreach($params as $paramO){ - $params[]="--context_param".$paramO[0]."=".$paramO[1]; - } - $result = $client->__SoapCall('runJob', array($params)); + /* + $params[1]="--context_param nb_line=".@=Quantity; - /* - $params[1]="--context_param nb_line=".@=Quantity; + $result = $client->__SoapCall('runJob', array($params)); + foreach ($result->item as $keyItem => $item){ + $gridRow=$keyItem+1; + @=USERSINFO[$gridRow]['NAME']=$item->item[1]; + @=USERSINFO[$gridRow]['LASTNAME']=$item->item[2]; + @=USERSINFO[$gridRow]['DATE']=$item->item[0]; + @=USERSINFO[$gridRow]['STREET']=$item->item[3]; + @=USERSINFO[$gridRow]['CITY']=$item->item[4]; + @=USERSINFO[$gridRow]['STATE']=$item->item[5]; + @=USERSINFO[$gridRow]['STATEID']=$item->item[6]; - $result = $client->__SoapCall('runJob', array($params)); - foreach ($result->item as $keyItem => $item){ - $gridRow=$keyItem+1; - @=USERSINFO[$gridRow]['NAME']=$item->item[1]; - @=USERSINFO[$gridRow]['LASTNAME']=$item->item[2]; - @=USERSINFO[$gridRow]['DATE']=$item->item[0]; - @=USERSINFO[$gridRow]['STREET']=$item->item[3]; - @=USERSINFO[$gridRow]['CITY']=$item->item[4]; - @=USERSINFO[$gridRow]['STATE']=$item->item[5]; - @=USERSINFO[$gridRow]['STATEID']=$item->item[6]; + } + */ + G::SendMessageText( "Information from Talend ETL webservice
" . $wsdl . "
", "INFO" ); +} - } - */ - G::SendMessageText( "Information from Talend ETL webservice
".$wsdl."
", "INFO"); -} \ No newline at end of file diff --git a/workflow/engine/methods/appFolder/appFolderList.php b/workflow/engine/methods/appFolder/appFolderList.php index 0aec98a26..7e9605ba4 100755 --- a/workflow/engine/methods/appFolder/appFolderList.php +++ b/workflow/engine/methods/appFolder/appFolderList.php @@ -1,59 +1,56 @@ $sw) { + if ($sw == "true") { + $keyDocArray = explode( "_", $keyDoc ); + $aFields = array ('APP_DOC_UID' => $keyDocArray[0],'DOC_VERSION' => $keyDocArray[1],'FOLDER_UID' => $folderUid + ); + $oAppDocument->update( $aFields ); + } } } - foreach($filesArray as $keyDoc => $sw){ - if($sw=="true"){ - $keyDocArray=explode("_",$keyDoc); - $aFields = array('APP_DOC_UID' => $keyDocArray[0], - 'DOC_VERSION' => $keyDocArray[1], - 'FOLDER_UID' => $folderUid); - $oAppDocument->update($aFields); - } - } - } -//$rootFolder='5320083284b210ceb511e43070218744'; -$rootFolder='0'; -//$rootFolder='4977070264b54bf093aef68069996372'; + //$rootFolder='5320083284b210ceb511e43070218744'; + $rootFolder = '0'; + //$rootFolder='4977070264b54bf093aef68069996372'; - $G_PUBLISH->AddContent('view', 'appFolder/appFolderTree' ); - $G_PUBLISH->AddContent('smarty', 'appFolder/appFolderFileList', '', '', array()); - G::RenderPage( "publish-treeview" , 'blank'); + $G_PUBLISH->AddContent( 'view', 'appFolder/appFolderTree' ); + $G_PUBLISH->AddContent( 'smarty', 'appFolder/appFolderFileList', '', '', array () ); + G::RenderPage( "publish-treeview", 'blank' ); - } - catch ( Exception $e ) { - $G_PUBLISH = new Publisher; +} catch (Exception $e) { + $G_PUBLISH = new Publisher(); $aMessage['MESSAGE'] = $e->getMessage(); - $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage ); + $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage ); G::RenderPage( 'publish', 'blank' ); - } - ?> +} +?> \ No newline at end of file + diff --git a/workflow/engine/methods/processes/processes_Ajax.php b/workflow/engine/methods/processes/processes_Ajax.php index 14de2abf4..c1c111878 100755 --- a/workflow/engine/methods/processes/processes_Ajax.php +++ b/workflow/engine/methods/processes/processes_Ajax.php @@ -29,13 +29,13 @@ try { G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels'); G::header('location: ../login/login'); die; - break; - case -1: + break; + case -1: G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels'); G::header('location: ../login/login'); die; - break; - }*/ + break; + }*/ $oJSON = new Services_JSON(); if (isset( $_REQUEST['data'] )) { $oData = $oJSON->decode( stripslashes( $_REQUEST['data'] ) ); @@ -97,7 +97,6 @@ try { unlink( PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "public" . PATH_SEP . $form['PRO_UID'] . PATH_SEP . str_replace( ".php", "Post", $form['FILENAME'] ) . ".php" ); $oProcessMap->webEntry( $_REQUEST['PRO_UID'] ); break; - case 'webEntry_new': $oProcessMap->webEntry_new( $oData->PRO_UID ); break; @@ -125,11 +124,9 @@ try { case 'webEntry': $oProcessMap->webEntry( $oData->pro_uid ); break; - case 'webEntry_Val_Assig': include (PATH_METHODS . 'processes/webEntry_Val_Assig.php'); break; - case 'saveTitlePosition': $sOutput = $oProcessMap->saveTitlePosition( $oData->pro_uid, $oData->position->x, $oData->position->y ); break; @@ -149,15 +146,12 @@ try { case 'users': $oProcessMap->users( $oData->pro_uid, $oData->tas_uid ); break; - case 'users_adhoc': $oProcessMap->users_adhoc( $oData->pro_uid, $oData->tas_uid ); break; - case 'addTask': $sOutput = $oProcessMap->addTask( $oData->uid, $oData->position->x, $oData->position->y ); break; - case 'addSubProcess': $sOutput = $oProcessMap->addSubProcess( $oData->uid, $oData->position->x, $oData->position->y ); break; @@ -427,16 +421,15 @@ try { $oJSON = new Services_JSON(); echo $oJSON->encode( $oResponse ); break; - case 'editFile': //echo $_REQUEST['filename']; global $G_PUBLISH; $G_PUBLISH = new Publisher(); ///-- $sDirectory = PATH_DATA_MAILTEMPLATES . $_REQUEST['pro_uid'] . PATH_SEP . $_REQUEST['filename']; $sDir = ""; - if (isset( $_SESSION['PFMDirectory'] )) + if (isset( $_SESSION['PFMDirectory'] )) { $sDir = $_SESSION['PFMDirectory']; - + } switch ($sDir) { case 'mailTemplates': $sDirectory = PATH_DATA_MAILTEMPLATES . $_REQUEST['pro_uid'] . PATH_SEP . $_REQUEST['filename']; @@ -457,17 +450,17 @@ try { $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'processes/processes_FileEdit', '', $aData ); G::RenderPage( 'publish', 'raw' ); /*}else{ echo 'krlos'; - $aMessage['MESSAGE'] = G::loadTranslation( 'HTML_FILES' ); - $G_PUBLISH->AddContent ( 'xmlform', 'xmlform', 'login/showMessage', '',$aMessage ); - }*/ - + $aMessage['MESSAGE'] = G::loadTranslation( 'HTML_FILES' ); + $G_PUBLISH->AddContent ( 'xmlform', 'xmlform', 'login/showMessage', '',$aMessage ); + }*/ break; case 'saveFile': global $G_PUBLISH; $G_PUBLISH = new Publisher(); $sDir = ""; - if (isset( $_REQUEST['MAIN_DIRECTORY'] )) + if (isset( $_REQUEST['MAIN_DIRECTORY'] )) { $sDir = $_REQUEST['MAIN_DIRECTORY']; + } switch ($sDir) { case 'mailTemplates': @@ -493,26 +486,25 @@ try { $oProcessMap->eventsList( $oData->pro_uid, $oData->type ); break; /* - case 'saveFile': - global $G_PUBLISH; - $G_PUBLISH = new Publisher(); - $sDirectory = PATH_DATA_MAILTEMPLATES . $_REQUEST['pro_uid'] . PATH_SEP . $_REQUEST['filename']; + case 'saveFile': + global $G_PUBLISH; + $G_PUBLISH = new Publisher(); + $sDirectory = PATH_DATA_MAILTEMPLATES . $_REQUEST['pro_uid'] . PATH_SEP . $_REQUEST['filename']; - $fp = fopen($sDirectory, 'w'); - $content = stripslashes($_REQUEST['fcontent']); - $content = str_replace("@amp@", "&", $content); - fwrite($fp, $content); - fclose($fp); - echo 'saved: '. $sDirectory; - break; -*/ + $fp = fopen($sDirectory, 'w'); + $content = stripslashes($_REQUEST['fcontent']); + $content = str_replace("@amp@", "&", $content); + fwrite($fp, $content); + fclose($fp); + echo 'saved: '. $sDirectory; + break; + */ case 'emptyFileOptions': global $G_PUBLISH; $G_PUBLISH = new Publisher(); $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'processes/processes_FileEditCreateEmpty', '' ); G::RenderPage( 'publish', 'raw' ); break; - case "taskCases": require_once 'classes/model/AppDelegation.php'; $criteria = new Criteria( 'workflow' );