From e21cbdbaa6da384c168d48339e6d68ec59d423c5 Mon Sep 17 00:00:00 2001 From: norahmollo Date: Fri, 19 Oct 2012 21:30:26 +0000 Subject: [PATCH] CODE STYLE Format Change format --- .../classes/class.multipleFilesBackup.php | 445 ++- .../engine/classes/class.pluginRegistry.php | 2754 +++++++++-------- workflow/engine/classes/model/AppNotes.php | 522 ++-- .../engine/classes/model/FieldCondition.php | 692 ++--- workflow/engine/classes/model/Gateway.php | 351 +-- workflow/engine/classes/model/ReportVar.php | 316 +- workflow/engine/classes/model/SubProcess.php | 319 +- .../classes/model/SwimlanesElements.php | 463 ++- workflow/engine/classes/model/TaskUser.php | 396 +-- .../classes/triggers/api/class.zimbraApi.php | 2313 +++++++------- 10 files changed, 4295 insertions(+), 4276 deletions(-) diff --git a/workflow/engine/classes/class.multipleFilesBackup.php b/workflow/engine/classes/class.multipleFilesBackup.php index a3f2be169..ce5da7952 100644 --- a/workflow/engine/classes/class.multipleFilesBackup.php +++ b/workflow/engine/classes/class.multipleFilesBackup.php @@ -1,227 +1,218 @@ -filename = $filename; - } - if(!empty($size) && (int)$size > 0){ - $this->fileSize = $size; - } - } - /* Gets workspace information enough to make its backup. - * @workspace contains the workspace to be add to the commpression process. - */ - public function addToBackup($workspace) - { - //verifing if workspace exists. - if (!$workspace->workspaceExists()) { - echo "Workspace {$workspace->name} not found\n"; - return false; - } - //create destination path - if (!file_exists(PATH_DATA . "upgrade/")){ - mkdir(PATH_DATA . "upgrade/"); - } - $tempDirectory = PATH_DATA . "upgrade/" . basename(tempnam(__FILE__, '')); - mkdir($tempDirectory); - $metadata = $workspace->getMetadata(); - CLI::logging("Temporing up database...\n"); - $metadata["databases"] = $workspace->exportDatabase($tempDirectory); - $metadata["directories"] = array("{$workspace->name}.files"); - $metadata["version"] = 1; - $metaFilename = "$tempDirectory/{$workspace->name}.meta"; - if (!file_put_contents($metaFilename, - str_replace(array(",", "{", "}"), array(",\n ", "{\n ", "\n}\n"), - G::json_encode($metadata)))) { - CLI::logging("Could not create backup metadata"); - } - CLI::logging("Adding database to backup...\n"); - $this->addDirToBackup($tempDirectory); - CLI::logging("Adding files to backup...\n"); - $this->addDirToBackup($workspace->path); - $this->tempDirectories[] = $tempDirectory; - } - - /* Add a directory containing Db files or info files to be commpressed - * @directory the name and path of the directory to be add to the commpression process. - */ - private function addDirToBackup($directory) - { - if(!empty($directory)){ - $this->dir_to_compress .= $directory . " "; - } - } - - /* Commpress the DB and files into a single or several files with numerical series extentions - */ - public function letsBackup() - { - // creating command - $CommpressCommand = "tar czv "; - $CommpressCommand .= $this->dir_to_compress; - $CommpressCommand .= "| split -b "; - $CommpressCommand .= $this->fileSize; - $CommpressCommand .= "m -d - "; - $CommpressCommand .= $this->filename . "."; - //executing command to create the files - echo exec($CommpressCommand); - //Remove leftovers dirs. - foreach($this->tempDirectories as $tempDirectory) - { - CLI::logging("Deleting: ".$tempDirectory."\n"); - G::rm_dir($tempDirectory); - } - } - /* Restore from file(s) commpressed by letsBackup function, into a temporary directory - * @ filename got the name and path of the compressed file(s), if there are many files with file extention as a numerical series, the extention should be discriminated. - * @ srcWorkspace contains the workspace to be restored. - * @ dstWorkspace contains the workspace to be overwriting. - * @ overwrite got the option true if the workspace will be overwrite. - */ - static public function letsRestore($filename, $srcWorkspace, $dstWorkspace = NULL, $overwrite = true) - { - // Needed info: - // TEMPDIR /shared/workflow_data/upgrade/ - // BACKUPS /shared/workflow_data/backups/ - - // Creating command cat myfiles_split.tgz_* | tar xz - $DecommpressCommand = "cat " . $filename . ".* "; - $DecommpressCommand .= " | tar xzv"; - - $tempDirectory = PATH_DATA . "upgrade/" . basename(tempnam(__FILE__, '')); - $parentDirectory = PATH_DATA . "upgrade"; - if (is_writable($parentDirectory)) { - mkdir($tempDirectory); - } else { - throw new Exception("Could not create directory:" . $parentDirectory); - } - //Extract all backup files, including database scripts and workspace files - CLI::logging("Restoring into ".$tempDirectory."\n"); - chdir($tempDirectory); - echo exec($DecommpressCommand); - CLI::logging("\nUncompressed into: ".$tempDirectory."\n"); - - //Search for metafiles in the new standard (the old standard would contain meta files. - $metaFiles = glob($tempDirectory . "/*.meta"); - if (empty($metaFiles)) { - $metaFiles = glob($tempDirectory . "/*.txt"); - if (!empty($metaFiles)){ - return workspaceTools::restoreLegacy($tempDirectory); - } - else{ - throw new Exception("No metadata found in backup"); - } - } - else { - CLI::logging("Found " . count($metaFiles) . " workspaces in backup:\n"); - foreach ($metaFiles as $metafile){ - CLI::logging("-> " . basename($metafile) . "\n"); - } - } - if (count($metaFiles) > 1 && (!isset($srcWorkspace))){ - throw new Exception("Multiple workspaces in backup but no workspace specified to restore"); - } - if (isset($srcWorkspace) && !in_array("$srcWorkspace.meta", array_map(basename, $metaFiles))){ - throw new Exception("Workspace $srcWorkspace not found in backup"); - } - foreach ($metaFiles as $metaFile) { - $metadata = G::json_decode(file_get_contents($metaFile)); - if ($metadata->version != 1){ - throw new Exception("Backup version {$metadata->version} not supported"); - } - $backupWorkspace = $metadata->WORKSPACE_NAME; - if (isset($dstWorkspace)) { - $workspaceName = $dstWorkspace; - $createWorkspace = true; - } - else { - $workspaceName = $metadata->WORKSPACE_NAME; - $createWorkspace = false; - } - if (isset($srcWorkspace) && strcmp($metadata->WORKSPACE_NAME, $srcWorkspace) != 0) { - CLI::logging(CLI::warning("> Workspace $backupWorkspace found, but not restoring.") . "\n"); - continue; - } - else { - CLI::logging("> Restoring " . CLI::info($backupWorkspace) . " to " . CLI::info($workspaceName) . "\n"); - } - $workspace = new workspaceTools($workspaceName); - if ($workspace->workspaceExists()){ - if ($overwrite){ - CLI::logging(CLI::warning("> Workspace $workspaceName already exist, overwriting!") . "\n"); - } - else{ - throw new Exception("Destination workspace already exist (use -o to overwrite)"); - } - } - if (file_exists($workspace->path)) { - G::rm_dir($workspace->path); - } - foreach ($metadata->directories as $dir) { - CLI::logging("+> Restoring directory '$dir'\n"); - if (!rename("$tempDirectory/$dir", $workspace->path)) { - throw new Exception("There was an error copying the backup files ($tempDirectory/$dir) to the workspace directory {$workspace->path}."); - } - } - - CLI::logging("> Changing file permissions\n"); - $shared_stat = stat(PATH_DATA); - if ($shared_stat !== false){ - workspaceTools::dirPerms($workspace->path, $shared_stat['uid'], $shared_stat['gid'], $shared_stat['mode']); - } - else{ - CLI::logging(CLI::error ("Could not get the shared folder permissions, not changing workspace permissions") . "\n"); - } - - list($dbHost, $dbUser, $dbPass) = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH)); - - CLI::logging("> Connecting to system database in '$dbHost'\n"); - $link = mysql_connect($dbHost, $dbUser, $dbPass); - @mysql_query("SET NAMES 'utf8';"); - if (!$link){ - throw new Exception('Could not connect to system database: ' . mysql_error()); - } - - $newDBNames = $workspace->resetDBInfo($dbHost, $createWorkspace); - - foreach ($metadata->databases as $db) { - $dbName = $newDBNames[$db->name]; - CLI::logging("+> Restoring database {$db->name} to $dbName\n"); - $workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql"); - $workspace->createDBUser($dbName, $db->pass, "localhost", $dbName); - $workspace->createDBUser($dbName, $db->pass, "%", $dbName); - } - $workspace->upgradeCacheView(false); - mysql_close($link); - - } - CLI::logging("Removing temporary files\n"); - G::rm_dir($tempDirectory); - CLI::logging(CLI::info("Done restoring") . "\n"); - } -} - -?> +filename = $filename; + } + if (! empty( $size ) && (int) $size > 0) { + $this->fileSize = $size; + } + } + + /* Gets workspace information enough to make its backup. + * @workspace contains the workspace to be add to the commpression process. + */ + public function addToBackup ($workspace) + { + //verifing if workspace exists. + if (! $workspace->workspaceExists()) { + echo "Workspace {$workspace->name} not found\n"; + return false; + } + //create destination path + if (! file_exists( PATH_DATA . "upgrade/" )) { + mkdir( PATH_DATA . "upgrade/" ); + } + $tempDirectory = PATH_DATA . "upgrade/" . basename( tempnam( __FILE__, '' ) ); + mkdir( $tempDirectory ); + $metadata = $workspace->getMetadata(); + CLI::logging( "Temporing up database...\n" ); + $metadata["databases"] = $workspace->exportDatabase( $tempDirectory ); + $metadata["directories"] = array ("{$workspace->name}.files"); + $metadata["version"] = 1; + $metaFilename = "$tempDirectory/{$workspace->name}.meta"; + if (! file_put_contents( $metaFilename, str_replace( array (",","{","}"), array (",\n ","{\n ","\n}\n"), G::json_encode( $metadata ) ) )) { + CLI::logging( "Could not create backup metadata" ); + } + CLI::logging( "Adding database to backup...\n" ); + $this->addDirToBackup( $tempDirectory ); + CLI::logging( "Adding files to backup...\n" ); + $this->addDirToBackup( $workspace->path ); + $this->tempDirectories[] = $tempDirectory; + } + + /* Add a directory containing Db files or info files to be commpressed + * @directory the name and path of the directory to be add to the commpression process. + */ + private function addDirToBackup ($directory) + { + if (! empty( $directory )) { + $this->dir_to_compress .= $directory . " "; + } + } + + // Commpress the DB and files into a single or several files with numerical series extentions + + public function letsBackup () + { + // creating command + $CommpressCommand = "tar czv "; + $CommpressCommand .= $this->dir_to_compress; + $CommpressCommand .= "| split -b "; + $CommpressCommand .= $this->fileSize; + $CommpressCommand .= "m -d - "; + $CommpressCommand .= $this->filename . "."; + //executing command to create the files + echo exec( $CommpressCommand ); + //Remove leftovers dirs. + foreach ($this->tempDirectories as $tempDirectory) { + CLI::logging( "Deleting: " . $tempDirectory . "\n" ); + G::rm_dir( $tempDirectory ); + } + } + /* Restore from file(s) commpressed by letsBackup function, into a temporary directory + * @ filename got the name and path of the compressed file(s), if there are many files with file extention as a numerical series, the extention should be discriminated. + * @ srcWorkspace contains the workspace to be restored. + * @ dstWorkspace contains the workspace to be overwriting. + * @ overwrite got the option true if the workspace will be overwrite. + */ + static public function letsRestore ($filename, $srcWorkspace, $dstWorkspace = null, $overwrite = true) + { + // Needed info: + // TEMPDIR /shared/workflow_data/upgrade/ + // BACKUPS /shared/workflow_data/backups/ + // Creating command cat myfiles_split.tgz_* | tar xz + $DecommpressCommand = "cat " . $filename . ".* "; + $DecommpressCommand .= " | tar xzv"; + + $tempDirectory = PATH_DATA . "upgrade/" . basename( tempnam( __FILE__, '' ) ); + $parentDirectory = PATH_DATA . "upgrade"; + if (is_writable( $parentDirectory )) { + mkdir( $tempDirectory ); + } else { + throw new Exception( "Could not create directory:" . $parentDirectory ); + } + //Extract all backup files, including database scripts and workspace files + CLI::logging( "Restoring into " . $tempDirectory . "\n" ); + chdir( $tempDirectory ); + echo exec( $DecommpressCommand ); + CLI::logging( "\nUncompressed into: " . $tempDirectory . "\n" ); + + //Search for metafiles in the new standard (the old standard would contain meta files. + $metaFiles = glob( $tempDirectory . "/*.meta" ); + if (empty( $metaFiles )) { + $metaFiles = glob( $tempDirectory . "/*.txt" ); + if (! empty( $metaFiles )) { + return workspaceTools::restoreLegacy( $tempDirectory ); + } else { + throw new Exception( "No metadata found in backup" ); + } + } else { + CLI::logging( "Found " . count( $metaFiles ) . " workspaces in backup:\n" ); + foreach ($metaFiles as $metafile) { + CLI::logging( "-> " . basename( $metafile ) . "\n" ); + } + } + if (count( $metaFiles ) > 1 && (! isset( $srcWorkspace ))) { + throw new Exception( "Multiple workspaces in backup but no workspace specified to restore" ); + } + if (isset( $srcWorkspace ) && ! in_array( "$srcWorkspace.meta", array_map( basename, $metaFiles ) )) { + throw new Exception( "Workspace $srcWorkspace not found in backup" ); + } + foreach ($metaFiles as $metaFile) { + $metadata = G::json_decode( file_get_contents( $metaFile ) ); + if ($metadata->version != 1) { + throw new Exception( "Backup version {$metadata->version} not supported" ); + } + $backupWorkspace = $metadata->WORKSPACE_NAME; + if (isset( $dstWorkspace )) { + $workspaceName = $dstWorkspace; + $createWorkspace = true; + } else { + $workspaceName = $metadata->WORKSPACE_NAME; + $createWorkspace = false; + } + if (isset( $srcWorkspace ) && strcmp( $metadata->WORKSPACE_NAME, $srcWorkspace ) != 0) { + CLI::logging( CLI::warning( "> Workspace $backupWorkspace found, but not restoring." ) . "\n" ); + continue; + } else { + CLI::logging( "> Restoring " . CLI::info( $backupWorkspace ) . " to " . CLI::info( $workspaceName ) . "\n" ); + } + $workspace = new workspaceTools( $workspaceName ); + if ($workspace->workspaceExists()) { + if ($overwrite) { + CLI::logging( CLI::warning( "> Workspace $workspaceName already exist, overwriting!" ) . "\n" ); + } else { + throw new Exception( "Destination workspace already exist (use -o to overwrite)" ); + } + } + if (file_exists( $workspace->path )) { + G::rm_dir( $workspace->path ); + } + foreach ($metadata->directories as $dir) { + CLI::logging( "+> Restoring directory '$dir'\n" ); + if (! rename( "$tempDirectory/$dir", $workspace->path )) { + throw new Exception( "There was an error copying the backup files ($tempDirectory/$dir) to the workspace directory {$workspace->path}." ); + } + } + + CLI::logging( "> Changing file permissions\n" ); + $shared_stat = stat( PATH_DATA ); + if ($shared_stat !== false) { + workspaceTools::dirPerms( $workspace->path, $shared_stat['uid'], $shared_stat['gid'], $shared_stat['mode'] ); + } else { + CLI::logging( CLI::error( "Could not get the shared folder permissions, not changing workspace permissions" ) . "\n" ); + } + + list ($dbHost, $dbUser, $dbPass) = @explode( SYSTEM_HASH, G::decrypt( HASH_INSTALLATION, SYSTEM_HASH ) ); + + CLI::logging( "> Connecting to system database in '$dbHost'\n" ); + $link = mysql_connect( $dbHost, $dbUser, $dbPass ); + @mysql_query( "SET NAMES 'utf8';" ); + if (! $link) { + throw new Exception( 'Could not connect to system database: ' . mysql_error() ); + } + + $newDBNames = $workspace->resetDBInfo( $dbHost, $createWorkspace ); + + foreach ($metadata->databases as $db) { + $dbName = $newDBNames[$db->name]; + CLI::logging( "+> Restoring database {$db->name} to $dbName\n" ); + $workspace->executeSQLScript( $dbName, "$tempDirectory/{$db->name}.sql" ); + $workspace->createDBUser( $dbName, $db->pass, "localhost", $dbName ); + $workspace->createDBUser( $dbName, $db->pass, "%", $dbName ); + } + $workspace->upgradeCacheView( false ); + mysql_close( $link ); + + } + CLI::logging( "Removing temporary files\n" ); + G::rm_dir( $tempDirectory ); + CLI::logging( CLI::info( "Done restoring" ) . "\n" ); + } +} + diff --git a/workflow/engine/classes/class.pluginRegistry.php b/workflow/engine/classes/class.pluginRegistry.php index 2686ed41d..dcb7de10c 100755 --- a/workflow/engine/classes/class.pluginRegistry.php +++ b/workflow/engine/classes/class.pluginRegistry.php @@ -1,1408 +1,1424 @@ -. - * - * 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 -{ - var $sNamespace; - var $sClassName; - var $sFriendlyName = null; - var $sDescription = null; - var $sSetupPage = null; - var $sFilename; - var $sPluginFolder = ''; - var $sCompanyLogo = ''; - var $iVersion = 0; - var $enabled = false; - var $aWorkspaces = null; - var $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 - */ - 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 - */ - function serializeInstance () - { - return serialize( self::$instance ); - } - - /** - * This function takes a single serialized variable and converts it back a code - * - * @param string $serialized - * @return void - */ - 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 - */ - 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 + */ + 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 - */ - 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 - */ - 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 - */ - 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] = $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] ); + } + } + //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 - */ - 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 - */ - 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); - - if ($pluginStatus != 0) { - $oldDetails = $this->getPluginDetails($pluginFile); - $oldVersion = $oldDetails->iVersion; - } else { - $oldDetails = NULL; - $oldVersion = NULL; - } - */ + $oldPluginStatus = $this->getStatusPlugin($pluginFile); + if ($pluginStatus != 0) { + $oldDetails = $this->getPluginDetails($pluginFile); + $oldVersion = $oldDetails->iVersion; + } else { + $oldDetails = NULL; + $oldVersion = NULL; + } + */ + //$pluginIni = $tar->extractInString("$pluginName.ini"); //$pluginConfig = parse_ini_string($pluginIni); - - /* - if (!empty($oClass->aDependences)) { - foreach ($oClass->aDependences as $aDependence) { - if (file_exists(PATH_PLUGINS . $aDependence['sClassName'] . '.php')) { - require_once PATH_PLUGINS . $aDependence['sClassName'] . '.php'; - if (!$oPluginRegistry->getPluginDetails($aDependence['sClassName'] . '.php')) { - throw new Exception('This plugin needs "' . $aDependence['sClassName'] . '" plugin'); + if (!empty($oClass->aDependences)) { + foreach ($oClass->aDependences as $aDependence) { + if (file_exists(PATH_PLUGINS . $aDependence['sClassName'] . '.php')) { + require_once PATH_PLUGINS . $aDependence['sClassName'] . '.php'; + if (!$oPluginRegistry->getPluginDetails($aDependence['sClassName'] . '.php')) { + throw new Exception('This plugin needs "' . $aDependence['sClassName'] . '" plugin'); + } + } + else { + throw new Exception('This plugin needs "' . $aDependence['sClassName'] . '" plugin'); + } } } - else { - throw new Exception('This plugin needs "' . $aDependence['sClassName'] . '" plugin'); + unset($oClass); + if ($fVersionOld > $fVersionNew) { + throw new Exception('A recent version of this plugin was already installed.'); } - } - } - unset($oClass); - 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(); - } - - 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; - } - } - } - - 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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; - } - } else if (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; - } else if (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 - */ - 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 - */ - 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 - */ - 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] ); - } - } + 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] ); + } + } // 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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 - */ - function getDashlets () - { - return $this->_aDashlets; - } - - /** - * this function returns all reports registered - * - * @return array - */ - 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 - */ - 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 - */ - function getSteps () - { - return $this->_aSteps; - } - - /** - * This function returns all redirect registered - * - * @return string - */ - function getRedirectLogins () - { - return $this->_aRedirectLogin; - } - - /** - * execute all triggers related to a triggerId - * - * @param unknown_type $menuId - * @return object - */ - function executeTriggers ($triggerId, $oData) - { - foreach ($this->_aTriggers as $row => $detail) { - if ($triggerId == $detail->sTriggerId) { - + $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) { //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 - */ - 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 - */ - 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 - */ - 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 - */ - 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)) { - return null; - } - $sFilename = $aDetails[2]; - if (!empty($sFilename)) { - require_once($sFilename); - } - $sClassName = $aDetails[0]; - $oPlugin =& new $sClassName($sFilename); - $this->_aPlugins[$sNamespace] =& $oPlugin; - return $oPlugin; - */ - } - - /** - * set company logo - * - * @param unknown_type $sNamespace - * @param unknown_type $filename - * @return void - */ - function setCompanyLogo ($sNamespace, $filename) - { - $found = false; - foreach ($this->_aPluginDetails as $row => $detail) { - if ($sNamespace == $detail->sNamespace) - $this->_aPluginDetails[$sNamespace]->sCompanyLogo = $filename; + $aDetails = KTUtil::arrayGet($this->_aPluginDetails, $sNamespace); + if (empty($aDetails)) { + return null; } - } - - /** - * get company logo - * - * @param unknown_type $default - * @return void - */ - function getCompanyLogo ($default) - { - $sCompanyLogo = $default; - foreach ($this->_aPluginDetails as $row => $detail) { - if (trim( $detail->sCompanyLogo ) != '') - $sCompanyLogo = $detail->sCompanyLogo; + $sFilename = $aDetails[2]; + if (!empty($sFilename)) { + require_once($sFilename); } - return $sCompanyLogo; - } - - /** - * get setup Plugins - * - * @param unknown_type $default - * @return void - */ - 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 - */ - 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 = $aDetails[0]; + $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 ); //$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 - */ - function getFieldsForPageSetup ($sNamespace) - { - $oData = NULL; - return $this->executeMethod( $sNamespace, 'getFieldsForPageSetup', $oData ); - } - - /** - * this function updates Fields For Page on Setup - * - * @param string $sNamespace - * @return void - */ - 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 ); - } - - 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 - */ - 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) - */ - 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 - */ - 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 - */ - function getCaseSchedulerPlugins () - { - return $this->_aCaseSchedulerPlugin; - } - - /** - * Register a Task Extended property page in the singleton - * - * @param unknown_type $sNamespace - * @param unknown_type $sPage - */ - - 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 - */ - 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( $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] ); + } + } // 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 - */ - function getDashboardPages () - { - return $this->_aDashboardPages; - } - - /** - * return all tasl extended properties - * - * @return array - */ - function getTaskExtendedProperties () - { - return $this->_aTaskExtendedProperties; - } - - 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 - } - - function getAttributes () - { - return get_object_vars( $this ); - } -} + } + + public function getAttributes () + { + return get_object_vars( $this ); + } +} + diff --git a/workflow/engine/classes/model/AppNotes.php b/workflow/engine/classes/model/AppNotes.php index 2341f0081..2edfbf31b 100755 --- a/workflow/engine/classes/model/AppNotes.php +++ b/workflow/engine/classes/model/AppNotes.php @@ -1,277 +1,251 @@ -clearSelectColumns(); + + $Criteria->addSelectColumn( AppNotesPeer::APP_UID ); + $Criteria->addSelectColumn( AppNotesPeer::USR_UID ); + $Criteria->addSelectColumn( AppNotesPeer::NOTE_DATE ); + $Criteria->addSelectColumn( AppNotesPeer::NOTE_CONTENT ); + $Criteria->addSelectColumn( AppNotesPeer::NOTE_TYPE ); + $Criteria->addSelectColumn( AppNotesPeer::NOTE_AVAILABILITY ); + $Criteria->addSelectColumn( AppNotesPeer::NOTE_ORIGIN_OBJ ); + $Criteria->addSelectColumn( AppNotesPeer::NOTE_AFFECTED_OBJ1 ); + $Criteria->addSelectColumn( AppNotesPeer::NOTE_AFFECTED_OBJ2 ); + $Criteria->addSelectColumn( AppNotesPeer::NOTE_RECIPIENTS ); + $Criteria->addSelectColumn( UsersPeer::USR_USERNAME ); + $Criteria->addSelectColumn( UsersPeer::USR_FIRSTNAME ); + $Criteria->addSelectColumn( UsersPeer::USR_LASTNAME ); + $Criteria->addSelectColumn( UsersPeer::USR_EMAIL ); + + $Criteria->addJoin( AppNotesPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN ); + + $Criteria->add( appNotesPeer::APP_UID, $appUid, CRITERIA::EQUAL ); + + if ($usrUid != '') { + $Criteria->add( appNotesPeer::USR_UID, $usrUid, CRITERIA::EQUAL ); + } + + $Criteria->addDescendingOrderByColumn( AppNotesPeer::NOTE_DATE ); + + $response = array (); + $totalCount = AppNotesPeer::doCount( $Criteria ); + $response['totalCount'] = $totalCount; + $response['notes'] = array (); + + if ($start != '') { + $Criteria->setLimit( $limit ); + $Criteria->setOffset( $start ); + } + + $oDataset = appNotesPeer::doSelectRS( $Criteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + + while ($aRow = $oDataset->getRow()) { + $aRow['NOTE_CONTENT'] = stripslashes( $aRow['NOTE_CONTENT'] ); + $response['notes'][] = $aRow; + $oDataset->next(); + } + + $result['criteria'] = $Criteria; + $result['array'] = $response; + + return $result; + } + + public function postNewNote ($appUid, $usrUid, $noteContent, $notify = true, $noteAvalibility = "PUBLIC", $noteRecipients = "", $noteType = "USER", $noteDate = "now") + { + $this->setAppUid( $appUid ); + $this->setUsrUid( $usrUid ); + $this->setNoteDate( $noteDate ); + $this->setNoteContent( $noteContent ); + $this->setNoteType( $noteType ); + $this->setNoteAvailability( $noteAvalibility ); + $this->setNoteOriginObj( '' ); + $this->setNoteAffectedObj1( '' ); + $this->setNoteAffectedObj2( '' ); + $this->setNoteRecipients( $noteRecipients ); + + if ($this->validate()) { + // we save it, since we get no validation errors, or do whatever else you like. + $res = $this->save(); + $msg = ''; + } else { + // Something went wrong. We can now get the validationFailures and handle them. + $msg = ''; + $validationFailuresArray = $this->getValidationFailures(); + foreach ($validationFailuresArray as $objValidationFailure) { + $msg .= $objValidationFailure->getMessage() . "
"; + } + //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg ); + } + if ($msg != "") { + $response['success'] = 'failure'; + $response['message'] = $msg; + } else { + $response['success'] = 'success'; + $response['message'] = 'Saved...'; + } + + if ($notify) { + if ($noteRecipients == "") { + $noteRecipientsA = array (); + G::LoadClass( 'case' ); + $oCase = new Cases(); + $p = $oCase->getUsersParticipatedInCase( $appUid ); + foreach ($p['array'] as $key => $userParticipated) { + $noteRecipientsA[] = $key; + } + $noteRecipients = implode( ",", $noteRecipientsA ); + } + + $this->sendNoteNotification( $appUid, $usrUid, $noteContent, $noteRecipients ); + } + + return $response; + } + + public function sendNoteNotification ($appUid, $usrUid, $noteContent, $noteRecipients, $sFrom = "") + { + try { + require_once ('classes/model/Configuration.php'); + $oConfiguration = new Configuration(); + $sDelimiter = DBAdapter::getStringDelimiter(); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ConfigurationPeer::CFG_UID, 'Emails' ); + $oCriteria->add( ConfigurationPeer::OBJ_UID, '' ); + $oCriteria->add( ConfigurationPeer::PRO_UID, '' ); + $oCriteria->add( ConfigurationPeer::USR_UID, '' ); + $oCriteria->add( ConfigurationPeer::APP_UID, '' ); + if (ConfigurationPeer::doCount( $oCriteria ) == 0) { + $oConfiguration->create( array ('CFG_UID' => 'Emails','OBJ_UID' => '','CFG_VALUE' => '','PRO_UID' => '','USR_UID' => '','APP_UID' => '') ); + $aConfiguration = array (); + } else { + $aConfiguration = $oConfiguration->load( 'Emails', '', '', '', '' ); + if ($aConfiguration['CFG_VALUE'] != '') { + $aConfiguration = unserialize( $aConfiguration['CFG_VALUE'] ); + $passwd = $aConfiguration['MESS_PASSWORD']; + $passwdDec = G::decrypt( $passwd, 'EMAILENCRYPT' ); + $auxPass = explode( 'hash:', $passwdDec ); + if (count( $auxPass ) > 1) { + if (count( $auxPass ) == 2) { + $passwd = $auxPass[1]; + } else { + array_shift( $auxPass ); + $passwd = implode( '', $auxPass ); + } + } + $aConfiguration['MESS_PASSWORD'] = $passwd; + } else { + $aConfiguration = array (); + } + } + + if (! isset( $aConfiguration['MESS_ENABLED'] ) || $aConfiguration['MESS_ENABLED'] != '1') { + return false; + } + + $oUser = new Users(); + $aUser = $oUser->load( $usrUid ); + $authorName = ((($aUser['USR_FIRSTNAME'] != '') || ($aUser['USR_LASTNAME'] != '')) ? $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'] . ' ' : '') . '<' . $aUser['USR_EMAIL'] . '>'; + + G::LoadClass( 'case' ); + $oCase = new Cases(); + $aFields = $oCase->loadCase( $appUid ); + $configNoteNotification['subject'] = G::LoadTranslation( 'ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION' ) . " @#APP_TITLE "; + $configNoteNotification['body'] = G::LoadTranslation( 'ID_CASE' ) . ": @#APP_TITLE
" . G::LoadTranslation( 'ID_AUTHOR' ) . ": $authorName

$noteContent"; + + if ($sFrom == '') { + $sFrom = '"ProcessMaker"'; + } + + $hasEmailFrom = preg_match( '/(.+)@(.+)\.(.+)/', $sFrom, $match ); + + if (! $hasEmailFrom || strpos( $sFrom, $aConfiguration['MESS_ACCOUNT'] ) === false) { + if (($aConfiguration['MESS_ENGINE'] != 'MAIL') && ($aConfiguration['MESS_ACCOUNT'] != '')) { + $sFrom .= ' <' . $aConfiguration['MESS_ACCOUNT'] . '>'; + } else { + if (($aConfiguration['MESS_ENGINE'] == 'MAIL')) { + $sFrom .= ' '; + } else { + if ($aConfiguration['MESS_SERVER'] != '') { + if (($sAux = @gethostbyaddr( $aConfiguration['MESS_SERVER'] ))) { + $sFrom .= ' '; + } else { + $sFrom .= ' '; + } + } else { + $sFrom .= ' '; + } + } + } + } + + $sSubject = G::replaceDataField( $configNoteNotification['subject'], $aFields ); + + //erik: new behaviour for messages + //G::loadClass('configuration'); + //$oConf = new Configurations; + //$oConf->loadConfig($x, 'TAS_EXTRA_PROPERTIES', $aTaskInfo['TAS_UID'], '', ''); + //$conf = $oConf->aConfig; + /* + if( isset($conf['TAS_DEF_MESSAGE_TYPE']) && isset($conf['TAS_DEF_MESSAGE_TEMPLATE']) + && $conf['TAS_DEF_MESSAGE_TYPE'] == 'template' && $conf['TAS_DEF_MESSAGE_TEMPLATE'] != '') { -require_once 'classes/model/om/BaseAppNotes.php'; + $pathEmail = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $aTaskInfo['PRO_UID'] . PATH_SEP; + $fileTemplate = $pathEmail . $conf['TAS_DEF_MESSAGE_TEMPLATE']; -/** - * Skeleton subclass for representing a row from the 'APP_NOTES' table. - * - * - * - * You should add additional methods to this class to meet the - * application requirements. This class will only be generated as - * long as it does not already exist in the output directory. - * - * @package classes.model - */ -class AppNotes extends BaseAppNotes { - - function getNotesList($appUid, $usrUid='', $start='', $limit='') - { - require_once ("classes/model/Users.php"); - - G::LoadClass('ArrayPeer'); - - $Criteria = new Criteria('workflow'); - $Criteria->clearSelectColumns(); - - $Criteria->addSelectColumn(AppNotesPeer::APP_UID); - $Criteria->addSelectColumn(AppNotesPeer::USR_UID); - $Criteria->addSelectColumn(AppNotesPeer::NOTE_DATE); - $Criteria->addSelectColumn(AppNotesPeer::NOTE_CONTENT); - $Criteria->addSelectColumn(AppNotesPeer::NOTE_TYPE); - $Criteria->addSelectColumn(AppNotesPeer::NOTE_AVAILABILITY); - $Criteria->addSelectColumn(AppNotesPeer::NOTE_ORIGIN_OBJ); - $Criteria->addSelectColumn(AppNotesPeer::NOTE_AFFECTED_OBJ1); - $Criteria->addSelectColumn(AppNotesPeer::NOTE_AFFECTED_OBJ2); - $Criteria->addSelectColumn(AppNotesPeer::NOTE_RECIPIENTS); - $Criteria->addSelectColumn(UsersPeer::USR_USERNAME); - $Criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME); - $Criteria->addSelectColumn(UsersPeer::USR_LASTNAME); - $Criteria->addSelectColumn(UsersPeer::USR_EMAIL); - - $Criteria->addJoin(AppNotesPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN); - - $Criteria->add(appNotesPeer::APP_UID, $appUid, CRITERIA::EQUAL); - - if ($usrUid != '') { - $Criteria->add(appNotesPeer::USR_UID, $usrUid, CRITERIA::EQUAL); - } - - $Criteria->addDescendingOrderByColumn(AppNotesPeer::NOTE_DATE); - - $response = array(); - $totalCount = AppNotesPeer::doCount($Criteria); - $response['totalCount'] = $totalCount; - $response['notes'] = array(); - - if ($start != '') { - $Criteria->setLimit($limit); - $Criteria->setOffset($start); - } - - $oDataset = appNotesPeer::doSelectRS($Criteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - - while ($aRow = $oDataset->getRow()) { - $aRow['NOTE_CONTENT'] = stripslashes($aRow['NOTE_CONTENT']); - $response['notes'][] = $aRow; - $oDataset->next(); - } - - $result['criteria'] = $Criteria; - $result['array'] = $response; - - return $result; - } - - - function postNewNote($appUid, $usrUid, $noteContent, $notify=true, $noteAvalibility="PUBLIC", $noteRecipients="", $noteType="USER", $noteDate="now") { - - $this->setAppUid($appUid); - $this->setUsrUid($usrUid); - $this->setNoteDate($noteDate); - $this->setNoteContent($noteContent); - $this->setNoteType($noteType); - $this->setNoteAvailability($noteAvalibility); - $this->setNoteOriginObj(''); - $this->setNoteAffectedObj1(''); - $this->setNoteAffectedObj2(''); - $this->setNoteRecipients($noteRecipients); - - if ($this->validate()) { - // we save it, since we get no validation errors, or do whatever else you like. - $res = $this->save(); - $msg = ''; - } else { - // Something went wrong. We can now get the validationFailures and handle them. - $msg = ''; - $validationFailuresArray = $this->getValidationFailures(); - foreach ($validationFailuresArray as $objValidationFailure) { - $msg .= $objValidationFailure->getMessage() . "
"; - } - //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg ); - } - if ($msg != "") { - $response['success'] = 'failure'; - $response['message'] = $msg; - } else { - $response['success'] = 'success'; - $response['message'] = 'Saved...'; - } - - if ($notify) { - if ($noteRecipients == "") { - $noteRecipientsA = array(); - G::LoadClass('case'); - $oCase = new Cases (); - - $p = $oCase->getUsersParticipatedInCase($appUid); - foreach($p['array'] as $key => $userParticipated){ - $noteRecipientsA[]=$key; - } - $noteRecipients = implode(",", $noteRecipientsA); - } - - $this->sendNoteNotification($appUid, $usrUid, $noteContent, $noteRecipients); - } - - return $response; - } - - public function sendNoteNotification($appUid, $usrUid, $noteContent, $noteRecipients, $sFrom="") { - try { - require_once ('classes/model/Configuration.php'); - $oConfiguration = new Configuration(); - $sDelimiter = DBAdapter::getStringDelimiter(); - $oCriteria = new Criteria('workflow'); - $oCriteria->add(ConfigurationPeer::CFG_UID, 'Emails'); - $oCriteria->add(ConfigurationPeer::OBJ_UID, ''); - $oCriteria->add(ConfigurationPeer::PRO_UID, ''); - $oCriteria->add(ConfigurationPeer::USR_UID, ''); - $oCriteria->add(ConfigurationPeer::APP_UID, ''); - if (ConfigurationPeer::doCount($oCriteria) == 0) { - $oConfiguration->create(array('CFG_UID' => 'Emails', 'OBJ_UID' => '', 'CFG_VALUE' => '', 'PRO_UID' => '', 'USR_UID' => '', 'APP_UID' => '')); - $aConfiguration = array(); - } else { - $aConfiguration = $oConfiguration->load('Emails', '', '', '', ''); - if ($aConfiguration['CFG_VALUE'] != '') { - $aConfiguration = unserialize($aConfiguration['CFG_VALUE']); - $passwd = $aConfiguration['MESS_PASSWORD']; - $passwdDec = G::decrypt($passwd,'EMAILENCRYPT'); - $auxPass = explode('hash:', $passwdDec); - if (count($auxPass) > 1) { - if (count($auxPass) == 2) { - $passwd = $auxPass[1]; - } else { - array_shift($auxPass); - $passwd = implode('', $auxPass); - } - } - $aConfiguration['MESS_PASSWORD'] = $passwd; - } else { - $aConfiguration = array(); - } - } - - if (!isset($aConfiguration['MESS_ENABLED']) || $aConfiguration['MESS_ENABLED'] != '1') { - return false; - } - - $oUser = new Users(); - $aUser = $oUser->load($usrUid); - $authorName = ((($aUser['USR_FIRSTNAME'] != '') || ($aUser['USR_LASTNAME'] != '')) ? $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'] . ' ' : '') . '<' . $aUser['USR_EMAIL'] . '>'; - - G::LoadClass('case'); - $oCase = new Cases (); - $aFields = $oCase->loadCase( $appUid ); - $configNoteNotification['subject']= G::LoadTranslation('ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION')." @#APP_TITLE "; - $configNoteNotification['body'] = G::LoadTranslation('ID_CASE') . ": @#APP_TITLE
" . G::LoadTranslation('ID_AUTHOR').": $authorName

$noteContent"; - - if ($sFrom == '') { - $sFrom = '"ProcessMaker"'; - } - - $hasEmailFrom = preg_match('/(.+)@(.+)\.(.+)/', $sFrom, $match); - - if (!$hasEmailFrom || strpos($sFrom, $aConfiguration['MESS_ACCOUNT']) === false) { - if (($aConfiguration['MESS_ENGINE'] != 'MAIL') && ($aConfiguration['MESS_ACCOUNT'] != '')) { - $sFrom .= ' <' . $aConfiguration['MESS_ACCOUNT'] . '>'; - } else { - if (($aConfiguration['MESS_ENGINE'] == 'MAIL')) { - $sFrom .= ' '; - } else { - if ($aConfiguration['MESS_SERVER'] != '') { - if (($sAux = @gethostbyaddr($aConfiguration['MESS_SERVER']))) { - $sFrom .= ' '; - } else { - $sFrom .= ' '; - } - } else { - $sFrom .= ' '; + if ( ! file_exists ( $fileTemplate ) ) { + throw new Exception("Template file '$fileTemplate' does not exist."); } - } - } - } - - $sSubject = G::replaceDataField($configNoteNotification['subject'], $aFields); - - - //erik: new behaviour for messages - //G::loadClass('configuration'); - //$oConf = new Configurations; - //$oConf->loadConfig($x, 'TAS_EXTRA_PROPERTIES', $aTaskInfo['TAS_UID'], '', ''); - //$conf = $oConf->aConfig; -/* - if( isset($conf['TAS_DEF_MESSAGE_TYPE']) && isset($conf['TAS_DEF_MESSAGE_TEMPLATE']) - && $conf['TAS_DEF_MESSAGE_TYPE'] == 'template' && $conf['TAS_DEF_MESSAGE_TEMPLATE'] != '') { - - $pathEmail = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $aTaskInfo['PRO_UID'] . PATH_SEP; - $fileTemplate = $pathEmail . $conf['TAS_DEF_MESSAGE_TEMPLATE']; - - if ( ! file_exists ( $fileTemplate ) ) { - throw new Exception("Template file '$fileTemplate' does not exist."); - } - - $sBody = G::replaceDataField(file_get_contents($fileTemplate), $aFields); - } else {*/ - $sBody = nl2br(G::replaceDataField($configNoteNotification['body'], $aFields)); - /*}*/ - - G::LoadClass('spool'); - $oUser = new Users(); - - $recipientsArray=explode(",",$noteRecipients); - - foreach($recipientsArray as $recipientUid){ - - $aUser = $oUser->load($recipientUid); - - $sTo = ((($aUser['USR_FIRSTNAME'] != '') || ($aUser['USR_LASTNAME'] != '')) ? $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'] . ' ' : '') . '<' . $aUser['USR_EMAIL'] . '>'; - - $oSpool = new spoolRun(); - $oSpool->setConfig(array('MESS_ENGINE' => $aConfiguration['MESS_ENGINE'], - 'MESS_SERVER' => $aConfiguration['MESS_SERVER'], - 'MESS_PORT' => $aConfiguration['MESS_PORT'], - 'MESS_ACCOUNT' => $aConfiguration['MESS_ACCOUNT'], - 'MESS_PASSWORD' => $aConfiguration['MESS_PASSWORD'], - 'SMTPAuth' => $aConfiguration['MESS_RAUTH'] == '1' ? true : false, - 'SMTPSecure' => isset($aConfiguration['SMTPSecure']) ? $aConfiguration['SMTPSecure'] : '' - )); - $oSpool->create(array('msg_uid' => '', - 'app_uid' => $appUid, - 'del_index' => 1, - 'app_msg_type' => 'DERIVATION', - 'app_msg_subject' => $sSubject, - 'app_msg_from' => $sFrom, - 'app_msg_to' => $sTo, - 'app_msg_body' => $sBody, - 'app_msg_cc' => '', - 'app_msg_bcc' => '', - 'app_msg_attach' => '', - 'app_msg_template' => '', - 'app_msg_status' => 'pending' - )); - if (($aConfiguration['MESS_BACKGROUND'] == '') || ($aConfiguration['MESS_TRY_SEND_INMEDIATLY'] == '1')) { - $oSpool->sendMail(); - } - - } - - //Send derivation notification - End - - } catch (Exception $oException) { - throw $oException; - } - } -} + $sBody = G::replaceDataField(file_get_contents($fileTemplate), $aFields); + } else {*/ + $sBody = nl2br( G::replaceDataField( $configNoteNotification['body'], $aFields ) ); + /*}*/ + G::LoadClass( 'spool' ); + $oUser = new Users(); + $recipientsArray = explode( ",", $noteRecipients ); + + foreach ($recipientsArray as $recipientUid) { + + $aUser = $oUser->load( $recipientUid ); + + $sTo = ((($aUser['USR_FIRSTNAME'] != '') || ($aUser['USR_LASTNAME'] != '')) ? $aUser['USR_FIRSTNAME'] . ' ' . $aUser['USR_LASTNAME'] . ' ' : '') . '<' . $aUser['USR_EMAIL'] . '>'; + $oSpool = new spoolRun(); + $oSpool->setConfig( array ('MESS_ENGINE' => $aConfiguration['MESS_ENGINE'],'MESS_SERVER' => $aConfiguration['MESS_SERVER'],'MESS_PORT' => $aConfiguration['MESS_PORT'],'MESS_ACCOUNT' => $aConfiguration['MESS_ACCOUNT'],'MESS_PASSWORD' => $aConfiguration['MESS_PASSWORD'],'SMTPAuth' => $aConfiguration['MESS_RAUTH'] == '1' ? true : false,'SMTPSecure' => isset( $aConfiguration['SMTPSecure'] ) ? $aConfiguration['SMTPSecure'] : '') ); + $oSpool->create( array ('msg_uid' => '','app_uid' => $appUid,'del_index' => 1,'app_msg_type' => 'DERIVATION','app_msg_subject' => $sSubject,'app_msg_from' => $sFrom,'app_msg_to' => $sTo,'app_msg_body' => $sBody,'app_msg_cc' => '','app_msg_bcc' => '','app_msg_attach' => '','app_msg_template' => '','app_msg_status' => 'pending') ); + if (($aConfiguration['MESS_BACKGROUND'] == '') || ($aConfiguration['MESS_TRY_SEND_INMEDIATLY'] == '1')) { + $oSpool->sendMail(); + } + + } + //Send derivation notification - End + } catch (Exception $oException) { + throw $oException; + } + } +} + diff --git a/workflow/engine/classes/model/FieldCondition.php b/workflow/engine/classes/model/FieldCondition.php index db73c7ef9..3d263775f 100755 --- a/workflow/engine/classes/model/FieldCondition.php +++ b/workflow/engine/classes/model/FieldCondition.php @@ -1,349 +1,351 @@ - - */ - public function get( $UID ) { - - $obj = FieldConditionPeer::retrieveByPk($UID); - if( !isset($obj) ) { - throw new Exception("the record with UID: $UID doesn't exits!"); - } + + */ + public function get ($UID) + { + + $obj = FieldConditionPeer::retrieveByPk( $UID ); + if (! isset( $obj )) { + throw new Exception( "the record with UID: $UID doesn't exits!" ); + } //TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM - return $obj->toArray(BasePeer::TYPE_FIELDNAME); - } - - /** - * Quick get all records into a criteria object - * - * @author Erik A. Ortiz - */ - public function getAllCriteriaByDynUid( $DYN_UID, $filter='all' ) { - $oCriteria = new Criteria('workflow'); - $oCriteria->addSelectColumn(FieldConditionPeer::FCD_UID); - $oCriteria->addSelectColumn(FieldConditionPeer::FCD_FUNCTION); - $oCriteria->addSelectColumn(FieldConditionPeer::FCD_FIELDS); - $oCriteria->addSelectColumn(FieldConditionPeer::FCD_CONDITION); - $oCriteria->addSelectColumn(FieldConditionPeer::FCD_EVENTS); - $oCriteria->addSelectColumn(FieldConditionPeer::FCD_EVENT_OWNERS); - $oCriteria->addSelectColumn(FieldConditionPeer::FCD_STATUS); - $oCriteria->addSelectColumn(FieldConditionPeer::FCD_DYN_UID); - - $oCriteria->add(FieldConditionPeer::FCD_DYN_UID, $DYN_UID); - switch( $filter ) { - case 'active': - $oCriteria->add(FieldConditionPeer::FCD_STATUS, '1', Criteria::EQUAL); - break; - } - - return $oCriteria; - } - - /** - * Quick get all records into a associative array - * - * @author Erik A. Ortiz - */ - public function getAllByDynUid( $DYN_UID, $filter='all' ) { - $aRows = Array(); - - $oCriteria = $this->getAllCriteriaByDynUid($DYN_UID, $filter); - - $oDataset = FieldConditionPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - - while( $aRow = $oDataset->getRow() ) { - $aRows[] = $aRow; - $oDataset->next(); - } - - return $aRows; - } - - /** - * Quick save a record - * - * @author Erik A. Ortiz - */ - public function quickSave($aData) { - $con = Propel::getConnection(FieldConditionPeer::DATABASE_NAME); - try { - $obj = null; - - if( isset($aData['FCD_UID']) && trim($aData['FCD_UID']) != '' ) { - $obj = FieldConditionPeer::retrieveByPk($aData['FCD_UID']); - } else { - $aData['FCD_UID'] = G::generateUniqueID(); - } - - if (!is_object($obj)) { - $obj = new FieldCondition(); - } - - $obj->fromArray($aData, BasePeer::TYPE_FIELDNAME); - - if ($obj->validate()) { - $result = $obj->save(); - $con->commit(); - return $result; - } else { - $e = new Exception("Failed Validation in class " . get_class($this) . "."); - $e->aValidationFailures = $obj->getValidationFailures(); - throw ($e); - } - - } catch (exception $e) { - $con->rollback(); - throw ($e); - } - } - - function getConditionScript($DYN_UID) { - require_once 'classes/model/Dynaform.php'; - G::LoadSystem('dynaformhandler'); - - $oDynaform = DynaformPeer::retrieveByPk($DYN_UID); - $PRO_UID = $oDynaform->getProUid(); - - $this->oDynaformHandler = new dynaFormHandler(PATH_DYNAFORM . "$PRO_UID/$DYN_UID" . '.xml'); - $aDynaformFields = $this->oDynaformHandler->getFieldNames(); - for ( $i = 0; $i < count($aDynaformFields); $i++ ) { - $aDynaformFields[$i] = "'$aDynaformFields[$i]'"; - } - - $sDynaformFieldsAsStrings = implode(',', $aDynaformFields); - - $aRows = $this->getAllByDynUid($DYN_UID, 'active'); - $sCode = ''; - - if( sizeof($aRows) != 0 ) { - - foreach ( $aRows as $aRow ) { - $hashCond = md5($aRow['FCD_UID']); - $sCondition = $this->parseCondition($aRow['FCD_CONDITION']); - $sCondition = addslashes($sCondition); - - $sCode .= "function __condition__$hashCond() { "; - $sCode .= "if( eval(\"{$sCondition}\") ) { "; - - $aFields = explode(',', $aRow['FCD_FIELDS']); - - switch( $aRow['FCD_FUNCTION'] ) { - case 'show': - foreach ( $aFields as $aField ) { - $sCode .= "showRowById('$aField');"; - } - break; - - case 'showOnly': - $sCode .= "hideRowsById(Array($sDynaformFieldsAsStrings));"; - foreach ( $aFields as $aField ) { - $sCode .= "showRowById('$aField');"; - } - break; - - case 'showAll': - $sCode .= "showRowsById(Array($sDynaformFieldsAsStrings));"; - break; - - case 'hide': - foreach ( $aFields as $aField ) { - $sCode .= "hideRowById('$aField');"; - } - break; - - case 'hideOnly': - $sCode .= "showRowsById(Array($sDynaformFieldsAsStrings));"; - foreach ( $aFields as $aField ) { - $sCode .= "hideRowById('$aField');"; - } - break; - - case 'hideAll': - $aDynaFields = array(); - $aEventOwner = explode(',', $aRow['FCD_EVENT_OWNERS'] ); - foreach($aDynaformFields as $sDynaformFields){ - if(! in_array(str_replace("'", "", $sDynaformFields), $aEventOwner) ) { - $aDynaFields[] = $sDynaformFields; - } - } - $sDynaformFieldsAsStrings = implode(',', $aDynaFields); - $sCode .= "hideRowsById(Array($sDynaformFieldsAsStrings));"; - - break; - } - $sCode .= " } "; - $sCode .= "} "; - $aFieldOwners = explode(',', $aRow['FCD_EVENT_OWNERS']); - $aEvents = explode(',', $aRow['FCD_EVENTS']); - if( in_array('onchange', $aEvents) ) { - foreach ( $aFieldOwners as $aField ) { - + return $obj->toArray( BasePeer::TYPE_FIELDNAME ); + } + + /** + * Quick get all records into a criteria object + * + * @author Erik A. Ortiz + */ + public function getAllCriteriaByDynUid ($DYN_UID, $filter = 'all') + { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( FieldConditionPeer::FCD_UID ); + $oCriteria->addSelectColumn( FieldConditionPeer::FCD_FUNCTION ); + $oCriteria->addSelectColumn( FieldConditionPeer::FCD_FIELDS ); + $oCriteria->addSelectColumn( FieldConditionPeer::FCD_CONDITION ); + $oCriteria->addSelectColumn( FieldConditionPeer::FCD_EVENTS ); + $oCriteria->addSelectColumn( FieldConditionPeer::FCD_EVENT_OWNERS ); + $oCriteria->addSelectColumn( FieldConditionPeer::FCD_STATUS ); + $oCriteria->addSelectColumn( FieldConditionPeer::FCD_DYN_UID ); + + $oCriteria->add( FieldConditionPeer::FCD_DYN_UID, $DYN_UID ); + switch ($filter) { + case 'active': + $oCriteria->add( FieldConditionPeer::FCD_STATUS, '1', Criteria::EQUAL ); + break; + } + + return $oCriteria; + } + + /** + * Quick get all records into a associative array + * + * @author Erik A. Ortiz + */ + public function getAllByDynUid ($DYN_UID, $filter = 'all') + { + $aRows = Array (); + + $oCriteria = $this->getAllCriteriaByDynUid( $DYN_UID, $filter ); + + $oDataset = FieldConditionPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + + while ($aRow = $oDataset->getRow()) { + $aRows[] = $aRow; + $oDataset->next(); + } + + return $aRows; + } + + /** + * Quick save a record + * + * @author Erik A. Ortiz + */ + public function quickSave ($aData) + { + $con = Propel::getConnection( FieldConditionPeer::DATABASE_NAME ); + try { + $obj = null; + + if (isset( $aData['FCD_UID'] ) && trim( $aData['FCD_UID'] ) != '') { + $obj = FieldConditionPeer::retrieveByPk( $aData['FCD_UID'] ); + } else { + $aData['FCD_UID'] = G::generateUniqueID(); + } + + if (! is_object( $obj )) { + $obj = new FieldCondition(); + } + + $obj->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + + if ($obj->validate()) { + $result = $obj->save(); + $con->commit(); + return $result; + } else { + $e = new Exception( "Failed Validation in class " . get_class( $this ) . "." ); + $e->aValidationFailures = $obj->getValidationFailures(); + throw ($e); + } + + } catch (exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function getConditionScript ($DYN_UID) + { + require_once 'classes/model/Dynaform.php'; + G::LoadSystem( 'dynaformhandler' ); + + $oDynaform = DynaformPeer::retrieveByPk( $DYN_UID ); + $PRO_UID = $oDynaform->getProUid(); + + $this->oDynaformHandler = new dynaFormHandler( PATH_DYNAFORM . "$PRO_UID/$DYN_UID" . '.xml' ); + $aDynaformFields = $this->oDynaformHandler->getFieldNames(); + for ($i = 0; $i < count( $aDynaformFields ); $i ++) { + $aDynaformFields[$i] = "'$aDynaformFields[$i]'"; + } + + $sDynaformFieldsAsStrings = implode( ',', $aDynaformFields ); + + $aRows = $this->getAllByDynUid( $DYN_UID, 'active' ); + $sCode = ''; + + if (sizeof( $aRows ) != 0) { + foreach ($aRows as $aRow) { + $hashCond = md5( $aRow['FCD_UID'] ); + $sCondition = $this->parseCondition( $aRow['FCD_CONDITION'] ); + $sCondition = addslashes( $sCondition ); + + $sCode .= "function __condition__$hashCond() { "; + $sCode .= "if( eval(\"{$sCondition}\") ) { "; + + $aFields = explode( ',', $aRow['FCD_FIELDS'] ); + + switch ($aRow['FCD_FUNCTION']) { + case 'show': + foreach ($aFields as $aField) { + $sCode .= "showRowById('$aField');"; + } + break; + case 'showOnly': + $sCode .= "hideRowsById(Array($sDynaformFieldsAsStrings));"; + foreach ($aFields as $aField) { + $sCode .= "showRowById('$aField');"; + } + break; + case 'showAll': + $sCode .= "showRowsById(Array($sDynaformFieldsAsStrings));"; + break; + case 'hide': + foreach ($aFields as $aField) { + $sCode .= "hideRowById('$aField');"; + } + break; + case 'hideOnly': + $sCode .= "showRowsById(Array($sDynaformFieldsAsStrings));"; + foreach ($aFields as $aField) { + $sCode .= "hideRowById('$aField');"; + } + break; + case 'hideAll': + $aDynaFields = array (); + $aEventOwner = explode( ',', $aRow['FCD_EVENT_OWNERS'] ); + foreach ($aDynaformFields as $sDynaformFields) { + if (! in_array( str_replace( "'", "", $sDynaformFields ), $aEventOwner )) { + $aDynaFields[] = $sDynaformFields; + } + } + $sDynaformFieldsAsStrings = implode( ',', $aDynaFields ); + $sCode .= "hideRowsById(Array($sDynaformFieldsAsStrings));"; + break; + } + $sCode .= " } "; + $sCode .= "} "; + $aFieldOwners = explode( ',', $aRow['FCD_EVENT_OWNERS'] ); + $aEvents = explode( ',', $aRow['FCD_EVENTS'] ); + if (in_array( 'onchange', $aEvents )) { + foreach ($aFieldOwners as $aField) { + //verify the field type - $node = $this->oDynaformHandler->getNode($aField); - $nodeType = $node->getAttribute('type'); - - switch($nodeType){ - case 'checkbox': - $sJSEvent = 'click'; - break; - case 'text': - case 'textarea': - case 'currency': - case 'percentage': - $sJSEvent = 'blur'; - break; - - default: - $sJSEvent = 'change'; - break; - } - $sCode .= "leimnud.event.add(getField('$aField'), '$sJSEvent', function() {"; - $sCode .= " __condition__$hashCond(); "; - $sCode .= "}.extend(getField('$aField')));"; - } - - } - if( in_array('onload', $aEvents) ) { - foreach ( $aFieldOwners as $aField ) { - $sCode .= " __condition__$hashCond(); "; - } - } - } - - - return $sCode; - } else { - return NULL; - } - } - - function parseCondition($sCondition) { - preg_match_all('/@#[a-zA-Z0-9_.]+/', $sCondition, $result); - if ( sizeof($result[0]) > 0 ) { - foreach( $result[0] as $fname ) { - preg_match_all('/(@#[a-zA-Z0-9_]+)\.([@#[a-zA-Z0-9_]+)/', $fname, $result2); - if( isset($result2[2][0]) && $result2[1][0]){ - $sCondition = str_replace($fname, "getField('".str_replace('@#', '', $result2[1][0])."').".$result2[2][0], $sCondition); - } else { - $field = str_replace('@#', '', $fname); - $node = $this->oDynaformHandler->getNode($field); - if(isset($node)) { - $nodeType = $node->getAttribute('type'); - switch($nodeType){ - case 'checkbox': - $sAtt = 'checked'; - break; - default: - $sAtt = 'value'; - } - } else { - $sAtt = 'value'; - } - $sCondition = str_replace($fname, "getField('".$field."').$sAtt", $sCondition); - } - } - } - return $sCondition; - } - - public function create($aData) { - $oConnection = Propel::getConnection(FieldConditionPeer::DATABASE_NAME); - try { + $node = $this->oDynaformHandler->getNode( $aField ); + $nodeType = $node->getAttribute( 'type' ); + + switch ($nodeType) { + case 'checkbox': + $sJSEvent = 'click'; + break; + case 'text': + case 'textarea': + case 'currency': + case 'percentage': + $sJSEvent = 'blur'; + break; + default: + $sJSEvent = 'change'; + break; + } + $sCode .= "leimnud.event.add(getField('$aField'), '$sJSEvent', function() {"; + $sCode .= " __condition__$hashCond(); "; + $sCode .= "}.extend(getField('$aField')));"; + } + + } + if (in_array( 'onload', $aEvents )) { + foreach ($aFieldOwners as $aField) { + $sCode .= " __condition__$hashCond(); "; + } + } + } + + return $sCode; + } else { + return null; + } + } + + public function parseCondition ($sCondition) + { + preg_match_all( '/@#[a-zA-Z0-9_.]+/', $sCondition, $result ); + if (sizeof( $result[0] ) > 0) { + foreach ($result[0] as $fname) { + preg_match_all( '/(@#[a-zA-Z0-9_]+)\.([@#[a-zA-Z0-9_]+)/', $fname, $result2 ); + if (isset( $result2[2][0] ) && $result2[1][0]) { + $sCondition = str_replace( $fname, "getField('" . str_replace( '@#', '', $result2[1][0] ) . "')." . $result2[2][0], $sCondition ); + } else { + $field = str_replace( '@#', '', $fname ); + $node = $this->oDynaformHandler->getNode( $field ); + if (isset( $node )) { + $nodeType = $node->getAttribute( 'type' ); + switch ($nodeType) { + case 'checkbox': + $sAtt = 'checked'; + break; + default: + $sAtt = 'value'; + } + } else { + $sAtt = 'value'; + } + $sCondition = str_replace( $fname, "getField('" . $field . "').$sAtt", $sCondition ); + } + } + } + return $sCondition; + } + public function create ($aData) + { + $oConnection = Propel::getConnection( FieldConditionPeer::DATABASE_NAME ); + try { // $aData['FCD_UID'] = ''; - if ( isset ( $aData['FCD_UID'] ) && $aData['FCD_UID']== '' ) - unset ( $aData['FCD_UID'] ); - if ( !isset ( $aData['FCD_UID'] ) ) - $aData['FCD_UID'] = G::generateUniqueID(); - - $oFieldCondition = new FieldCondition(); - $oFieldCondition->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oFieldCondition->validate()) { - $oConnection->begin(); - $iResult = $oFieldCondition->save(); - $oConnection->commit(); - return true; - } else { - $sMessage = ''; - $aValidationFailures = $oFieldCondition->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - - public function remove($sUID) { - $oConnection = Propel::getConnection(FieldConditionPeer::DATABASE_NAME); - try { - $oConnection->begin(); - $this->setFcdUid($sUID); - $iResult = $this->delete(); - $oConnection->commit(); - return $iResult; - } catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - function fieldConditionExists ( $sUid, $aDynaform ) { - try { - $found = false; - $obj = FieldConditionPeer::retrieveByPk( $sUid ); - if( isset($obj) ) { - $aFields = $obj->toArray(BasePeer::TYPE_FIELDNAME); - foreach($aDynaform as $key => $row){ - if($row['DYN_UID'] == $aFields['FCD_DYN_UID']) - $found = true; - } - } + if (isset( $aData['FCD_UID'] ) && $aData['FCD_UID'] == '') { + unset( $aData['FCD_UID'] ); + } + if (! isset( $aData['FCD_UID'] )) { + $aData['FCD_UID'] = G::generateUniqueID(); + } + $oFieldCondition = new FieldCondition(); + $oFieldCondition->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oFieldCondition->validate()) { + $oConnection->begin(); + $iResult = $oFieldCondition->save(); + $oConnection->commit(); + return true; + } else { + $sMessage = ''; + $aValidationFailures = $oFieldCondition->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public function remove ($sUID) + { + $oConnection = Propel::getConnection( FieldConditionPeer::DATABASE_NAME ); + try { + $oConnection->begin(); + $this->setFcdUid( $sUID ); + $iResult = $this->delete(); + $oConnection->commit(); + return $iResult; + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public function fieldConditionExists ($sUid, $aDynaform) + { + try { + $found = false; + $obj = FieldConditionPeer::retrieveByPk( $sUid ); + if (isset( $obj )) { + $aFields = $obj->toArray( BasePeer::TYPE_FIELDNAME ); + foreach ($aDynaform as $key => $row) { + if ($row['DYN_UID'] == $aFields['FCD_DYN_UID']) { + $found = true; + } + } + } // return( get_class($obj) == 'FieldCondition') ; - return($found); - } - catch (Exception $oError) { - throw($oError); - } - } - - function Exists ( $sUid ) { - try { - $obj = FieldConditionPeer::retrieveByPk( $sUid ); - return(is_object($obj) && get_class($obj) == 'FieldCondition') ; - } - catch (Exception $oError) { - throw($oError); - } - } - -} // FieldCondition + return ($found); + } catch (Exception $oError) { + throw ($oError); + } + } + + public function Exists ($sUid) + { + try { + $obj = FieldConditionPeer::retrieveByPk( $sUid ); + return (is_object( $obj ) && get_class( $obj ) == 'FieldCondition'); + } catch (Exception $oError) { + throw ($oError); + } + } +} +// FieldCondition + diff --git a/workflow/engine/classes/model/Gateway.php b/workflow/engine/classes/model/Gateway.php index b7f77bce9..ade82613b 100755 --- a/workflow/engine/classes/model/Gateway.php +++ b/workflow/engine/classes/model/Gateway.php @@ -1,185 +1,166 @@ -fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oGateway->validate()) { - $oConnection->begin(); - $iResult = $oGateway->save(); - $oConnection->commit(); - return $sGatewayUID; - } - else { - $sMessage = ''; - $aValidationFailures = $oGateway->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - public function load($GatewayUid) - { - try { - $oRow = GatewayPeer::retrieveByPK( $GatewayUid ); - if (!is_null($oRow)) - { - $aFields = $oRow->toArray(BasePeer::TYPE_FIELDNAME); - $this->fromArray($aFields,BasePeer::TYPE_FIELDNAME); - $this->setNew(false); - return $aFields; - } - else { - throw(new Exception( "The row '" . $GatewayUid . "' in table Gateway doesn't exist!" )); - } - } - catch (Exception $oError) { - throw($oError); - } - } - - public function update($fields) - { - $con = Propel::getConnection(GatewayPeer::DATABASE_NAME); - try - { - $con->begin(); - $this->load($fields['GAT_UID']); - $this->fromArray($fields,BasePeer::TYPE_FIELDNAME); - if($this->validate()) - { - $result=$this->save(); - $con->commit(); - return $result; - } - else - { - $con->rollback(); - throw(new Exception("Failed Validation in class ".get_class($this).".")); - } - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - - public function remove($GatewayUid) - { - $oConnection = Propel::getConnection(GatewayPeer::DATABASE_NAME); - try { - $oGateWay = GatewayPeer::retrieveByPK($GatewayUid); - if (!is_null($oGateWay)) - { - $oConnection->begin(); - $iResult = $oGateWay->delete(); - $oConnection->commit(); - //return $iResult; - return true; - } - else { - throw(new Exception('This row does not exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * verify if Gateway row specified in [GatUid] exists. - * - * @param string $sProUid the uid of the Prolication - */ - - function gatewayExists ( $GatUid ) { - $con = Propel::getConnection(GatewayPeer::DATABASE_NAME); - try { - $oPro = GatewayPeer::retrieveByPk( $GatUid ); - if ( is_object($oPro) && get_class ($oPro) == 'Gateway' ) { - return true; - } - else { - return false; - } - } - catch (Exception $oError) { - throw($oError); - } - } - - /** - * create a new Gateway - * - * @param array $aData with new values - * @return void - */ - function createRow($aData) - { - $con = Propel::getConnection(GatewayPeer::DATABASE_NAME); - try - { - $con->begin(); - - $this->fromArray($aData,BasePeer::TYPE_FIELDNAME); - if($this->validate()) - { - $this->setGatUid((isset($aData['GAT_UID']) ? $aData['GAT_UID']: '')); - $this->setProUid((isset($aData['PRO_UID']) ? $aData['PRO_UID']: '')); - $this->setTasUid((isset($aData['TAS_UID']) ? $aData['TAS_UID']: '')); - $this->setGatNextTask((isset($aData['GAT_NEXT_TASK']) ? $aData['GAT_NEXT_TASK']: '')); - $this->setGatX((isset($aData['GAT_X']) ? $aData['GAT_X']: '')); - $this->setGatY((isset($aData['GAT_Y']) ? $aData['GAT_Y']: '')); - $this->save(); - $con->commit(); - return; - } - else - { - $con->rollback(); - $e=new Exception("Failed Validation in class ".get_class($this)."."); - $e->aValidationFailures=$this->getValidationFailures(); - throw($e); - } - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - -} // Gateway +fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oGateway->validate()) { + $oConnection->begin(); + $iResult = $oGateway->save(); + $oConnection->commit(); + return $sGatewayUID; + } else { + $sMessage = ''; + $aValidationFailures = $oGateway->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public function load ($GatewayUid) + { + try { + $oRow = GatewayPeer::retrieveByPK( $GatewayUid ); + if (! is_null( $oRow )) { + $aFields = $oRow->toArray( BasePeer::TYPE_FIELDNAME ); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + $this->setNew( false ); + return $aFields; + } else { + throw (new Exception( "The row '" . $GatewayUid . "' in table Gateway doesn't exist!" )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + public function update ($fields) + { + $con = Propel::getConnection( GatewayPeer::DATABASE_NAME ); + try { + $con->begin(); + $this->load( $fields['GAT_UID'] ); + $this->fromArray( $fields, BasePeer::TYPE_FIELDNAME ); + if ($this->validate()) { + $result = $this->save(); + $con->commit(); + return $result; + } else { + $con->rollback(); + throw (new Exception( "Failed Validation in class " . get_class( $this ) . "." )); + } + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function remove ($GatewayUid) + { + $oConnection = Propel::getConnection( GatewayPeer::DATABASE_NAME ); + try { + $oGateWay = GatewayPeer::retrieveByPK( $GatewayUid ); + if (! is_null( $oGateWay )) { + $oConnection->begin(); + $iResult = $oGateWay->delete(); + $oConnection->commit(); + //return $iResult; + return true; + } else { + throw (new Exception( 'This row does not exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * verify if Gateway row specified in [GatUid] exists. + * + * @param string $sProUid the uid of the Prolication + */ + + public function gatewayExists ($GatUid) + { + $con = Propel::getConnection( GatewayPeer::DATABASE_NAME ); + try { + $oPro = GatewayPeer::retrieveByPk( $GatUid ); + if (is_object( $oPro ) && get_class( $oPro ) == 'Gateway') { + return true; + } else { + return false; + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * create a new Gateway + * + * @param array $aData with new values + * @return void + */ + public function createRow ($aData) + { + $con = Propel::getConnection( GatewayPeer::DATABASE_NAME ); + try { + $con->begin(); + + $this->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($this->validate()) { + $this->setGatUid( (isset( $aData['GAT_UID'] ) ? $aData['GAT_UID'] : '') ); + $this->setProUid( (isset( $aData['PRO_UID'] ) ? $aData['PRO_UID'] : '') ); + $this->setTasUid( (isset( $aData['TAS_UID'] ) ? $aData['TAS_UID'] : '') ); + $this->setGatNextTask( (isset( $aData['GAT_NEXT_TASK'] ) ? $aData['GAT_NEXT_TASK'] : '') ); + $this->setGatX( (isset( $aData['GAT_X'] ) ? $aData['GAT_X'] : '') ); + $this->setGatY( (isset( $aData['GAT_Y'] ) ? $aData['GAT_Y'] : '') ); + $this->save(); + $con->commit(); + return; + } else { + $con->rollback(); + $e = new Exception( "Failed Validation in class " . get_class( $this ) . "." ); + $e->aValidationFailures = $this->getValidationFailures(); + throw ($e); + } + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } +} +// Gateway + diff --git a/workflow/engine/classes/model/ReportVar.php b/workflow/engine/classes/model/ReportVar.php index fe39cc5d8..33d949153 100755 --- a/workflow/engine/classes/model/ReportVar.php +++ b/workflow/engine/classes/model/ReportVar.php @@ -1,162 +1,160 @@ -toArray(BasePeer::TYPE_FIELDNAME); - $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME); - return $aFields; - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - throw($oError); - } - } - - /** - * Create the report var registry - * @param array $aData - * @return string - **/ - public function create($aData) - { - $oConnection = Propel::getConnection(ReportVarPeer::DATABASE_NAME); - try { - if ( isset ( $aData['REP_VAR_UID'] ) && $aData['REP_VAR_UID']== '' ) - unset ( $aData['REP_VAR_UID'] ); - if ( !isset ( $aData['REP_VAR_UID'] ) ) - $aData['REP_VAR_UID'] = G::generateUniqueID(); - $oReportVar = new ReportVar(); - $oReportVar->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oReportVar->validate()) { - $oConnection->begin(); - $iResult = $oReportVar->save(); - $oConnection->commit(); - return $aData['REP_VAR_UID']; - } - else { - $sMessage = ''; - $aValidationFailures = $oReportVar->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Update the report var registry - * @param array $aData - * @return string - **/ - public function update($aData) - { - $oConnection = Propel::getConnection(ReportVarPeer::DATABASE_NAME); - try { - $oReportVar = ReportVarPeer::retrieveByPK($aData['REP_VAR_UID']); - if (!is_null($oReportVar)) - { - $oReportVar->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oReportVar->validate()) { - $oConnection->begin(); - $iResult = $oReportVar->save(); - $oConnection->commit(); - return $iResult; - } - else { - $sMessage = ''; - $aValidationFailures = $oReportVar->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be updated!
'.$sMessage)); - } - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Remove the report var registry - * @param array $aData - * @return string - **/ - public function remove($sRepVarUid) - { - $oConnection = Propel::getConnection(ReportVarPeer::DATABASE_NAME); - try { - $oReportVar = ReportVarPeer::retrieveByPK($sRepVarUid); - if (!is_null($oReportVar)) - { - $oConnection->begin(); - $iResult = $oReportVar->delete(); - $oConnection->commit(); - return $iResult; - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - function reportVarExists ( $sRepVarUid ) { - $con = Propel::getConnection(ReportVarPeer::DATABASE_NAME); - try { - $oRepVarUid = ReportVarPeer::retrieveByPk( $sRepVarUid ); - if (is_object($oRepVarUid) && get_class ($oRepVarUid) == 'ReportVar' ) { - return true; - } - else { - return false; - } - } - catch (Exception $oError) { - throw($oError); - } - } -} // ReportVar + */ + public function load ($sRepVarUid) + { + try { + $oReportVar = ReportVarPeer::retrieveByPK( $sRepVarUid ); + if (! is_null( $oReportVar )) { + $aFields = $oReportVar->toArray( BasePeer::TYPE_FIELDNAME ); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + return $aFields; + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create the report var registry + * + * @param array $aData + * @return string + * + */ + public function create ($aData) + { + $oConnection = Propel::getConnection( ReportVarPeer::DATABASE_NAME ); + try { + if (isset( $aData['REP_VAR_UID'] ) && $aData['REP_VAR_UID'] == '') { + unset( $aData['REP_VAR_UID'] ); + } + if (! isset( $aData['REP_VAR_UID'] )) { + $aData['REP_VAR_UID'] = G::generateUniqueID(); + } + $oReportVar = new ReportVar(); + $oReportVar->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oReportVar->validate()) { + $oConnection->begin(); + $iResult = $oReportVar->save(); + $oConnection->commit(); + return $aData['REP_VAR_UID']; + } else { + $sMessage = ''; + $aValidationFailures = $oReportVar->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Update the report var registry + * + * @param array $aData + * @return string + * + */ + public function update ($aData) + { + $oConnection = Propel::getConnection( ReportVarPeer::DATABASE_NAME ); + try { + $oReportVar = ReportVarPeer::retrieveByPK( $aData['REP_VAR_UID'] ); + if (! is_null( $oReportVar )) { + $oReportVar->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oReportVar->validate()) { + $oConnection->begin(); + $iResult = $oReportVar->save(); + $oConnection->commit(); + return $iResult; + } else { + $sMessage = ''; + $aValidationFailures = $oReportVar->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be updated!
' . $sMessage )); + } + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Remove the report var registry + * + * @param array $aData + * @return string + * + */ + public function remove ($sRepVarUid) + { + $oConnection = Propel::getConnection( ReportVarPeer::DATABASE_NAME ); + try { + $oReportVar = ReportVarPeer::retrieveByPK( $sRepVarUid ); + if (! is_null( $oReportVar )) { + $oConnection->begin(); + $iResult = $oReportVar->delete(); + $oConnection->commit(); + return $iResult; + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public function reportVarExists ($sRepVarUid) + { + $con = Propel::getConnection( ReportVarPeer::DATABASE_NAME ); + try { + $oRepVarUid = ReportVarPeer::retrieveByPk( $sRepVarUid ); + if (is_object( $oRepVarUid ) && get_class( $oRepVarUid ) == 'ReportVar') { + return true; + } else { + return false; + } + } catch (Exception $oError) { + throw ($oError); + } + } +} +// ReportVar + diff --git a/workflow/engine/classes/model/SubProcess.php b/workflow/engine/classes/model/SubProcess.php index 7369bdda2..231313486 100755 --- a/workflow/engine/classes/model/SubProcess.php +++ b/workflow/engine/classes/model/SubProcess.php @@ -1,166 +1,153 @@ -toArray(BasePeer::TYPE_FIELDNAME); - $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME); - $this->setNew(false); - return $aFields; - } - else { - throw( new Exception( "The row '$SP_UID' in table SubProcess doesn't exist!" )); - } - } - catch (Exception $oError) { - throw($oError); - } - } - - public function create($aData) - { - $con = Propel::getConnection(SubProcessPeer::DATABASE_NAME); - try - { - $con->begin(); - if ( isset ( $aData['SP_UID'] ) && $aData['SP_UID']== '' ) - unset ( $aData['SP_UID'] ); - if ( !isset ( $aData['SP_UID'] ) ) - $this->setSpUid(G::generateUniqueID()); - else - $this->setSpUid($aData['SP_UID'] ); - - $this->setProUid($aData['PRO_UID']); - - $this->setTasUid($aData['TAS_UID']); - - $this->setProParent($aData['PRO_PARENT']); - - $this->setTasParent($aData['TAS_PARENT']); - - $this->setSpType($aData['SP_TYPE']); - - $this->setSpSynchronous($aData['SP_SYNCHRONOUS']); - - $this->setSpSynchronousType($aData['SP_SYNCHRONOUS_TYPE']); - - $this->setSpSynchronousWait($aData['SP_SYNCHRONOUS_WAIT']); - - $this->setSpVariablesOut($aData['SP_VARIABLES_OUT']); - - $this->setSpVariablesIn($aData['SP_VARIABLES_IN']); - - $this->setSpGridIn($aData['SP_GRID_IN']); - - if($this->validate()) - { - $result=$this->save(); - $con->commit(); - return $result; - } - else - { - $con->rollback(); - throw(new Exception("Failed Validation in class ".get_class($this).".")); - } - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - public function update($fields) - { - $con = Propel::getConnection(SubProcessPeer::DATABASE_NAME); - try - { - $con->begin(); - $this->load($fields['SP_UID']); - $this->fromArray($fields,BasePeer::TYPE_FIELDNAME); - if($this->validate()) - { - $result=$this->save(); - $con->commit(); - return $result; - } - else - { - $con->rollback(); - $validationE=new Exception("Failed Validation in class ".get_class($this)."."); - $validationE->aValidationFailures = $this->getValidationFailures(); - throw($validationE); - } - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - public function remove($SP_UID) - { - $con = Propel::getConnection(SubProcessPeer::DATABASE_NAME); - try - { - $con->begin(); - $oRepTab = SubProcessPeer::retrieveByPK( $SP_UID ); - if (!is_null($oRepTab)) { - $result = $oRepTab->delete(); - $con->commit(); - } - return $result; - } - catch(Exception $e) - { - $con->rollback(); - throw($e); - } - } - - /** - * verify if Trigger row specified in [sUid] exists. - * - * @param string $sUid the uid of the Prolication - */ - - function subProcessExists ( $sUid ) { - $con = Propel::getConnection(SubProcessPeer::DATABASE_NAME); - try { - $oObj = SubProcessPeer::retrieveByPk( $sUid ); - if (is_object($oObj) && get_class ($oObj) == 'SubProcess' ) { - return true; - } - else { - return false; - } - } - catch (Exception $oError) { - throw($oError); - } - } - -} // SubProcess +toArray( BasePeer::TYPE_FIELDNAME ); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + $this->setNew( false ); + return $aFields; + } else { + throw (new Exception( "The row '$SP_UID' in table SubProcess doesn't exist!" )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + public function create ($aData) + { + $con = Propel::getConnection( SubProcessPeer::DATABASE_NAME ); + try { + $con->begin(); + if (isset( $aData['SP_UID'] ) && $aData['SP_UID'] == '') { + unset( $aData['SP_UID'] ); + } + if (! isset( $aData['SP_UID'] )) { + $this->setSpUid( G::generateUniqueID() ); + } else { + $this->setSpUid( $aData['SP_UID'] ); + } + + $this->setProUid( $aData['PRO_UID'] ); + + $this->setTasUid( $aData['TAS_UID'] ); + + $this->setProParent( $aData['PRO_PARENT'] ); + + $this->setTasParent( $aData['TAS_PARENT'] ); + + $this->setSpType( $aData['SP_TYPE'] ); + + $this->setSpSynchronous( $aData['SP_SYNCHRONOUS'] ); + + $this->setSpSynchronousType( $aData['SP_SYNCHRONOUS_TYPE'] ); + + $this->setSpSynchronousWait( $aData['SP_SYNCHRONOUS_WAIT'] ); + + $this->setSpVariablesOut( $aData['SP_VARIABLES_OUT'] ); + + $this->setSpVariablesIn( $aData['SP_VARIABLES_IN'] ); + + $this->setSpGridIn( $aData['SP_GRID_IN'] ); + + if ($this->validate()) { + $result = $this->save(); + $con->commit(); + return $result; + } else { + $con->rollback(); + throw (new Exception( "Failed Validation in class " . get_class( $this ) . "." )); + } + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function update ($fields) + { + $con = Propel::getConnection( SubProcessPeer::DATABASE_NAME ); + try { + $con->begin(); + $this->load( $fields['SP_UID'] ); + $this->fromArray( $fields, BasePeer::TYPE_FIELDNAME ); + if ($this->validate()) { + $result = $this->save(); + $con->commit(); + return $result; + } else { + $con->rollback(); + $validationE = new Exception( "Failed Validation in class " . get_class( $this ) . "." ); + $validationE->aValidationFailures = $this->getValidationFailures(); + throw ($validationE); + } + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + public function remove ($SP_UID) + { + $con = Propel::getConnection( SubProcessPeer::DATABASE_NAME ); + try { + $con->begin(); + $oRepTab = SubProcessPeer::retrieveByPK( $SP_UID ); + if (! is_null( $oRepTab )) { + $result = $oRepTab->delete(); + $con->commit(); + } + return $result; + } catch (Exception $e) { + $con->rollback(); + throw ($e); + } + } + + /** + * verify if Trigger row specified in [sUid] exists. + * + * @param string $sUid the uid of the Prolication + */ + + public function subProcessExists ($sUid) + { + $con = Propel::getConnection( SubProcessPeer::DATABASE_NAME ); + try { + $oObj = SubProcessPeer::retrieveByPk( $sUid ); + if (is_object( $oObj ) && get_class( $oObj ) == 'SubProcess') { + return true; + } else { + return false; + } + } catch (Exception $oError) { + throw ($oError); + } + } +} +// SubProcess + diff --git a/workflow/engine/classes/model/SwimlanesElements.php b/workflow/engine/classes/model/SwimlanesElements.php index fb9b46b87..13c63d2a2 100755 --- a/workflow/engine/classes/model/SwimlanesElements.php +++ b/workflow/engine/classes/model/SwimlanesElements.php @@ -1,237 +1,232 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ - -require_once 'classes/model/om/BaseSwimlanesElements.php'; -require_once 'classes/model/Content.php'; - -/** - * Skeleton subclass for representing a row from the 'SWIMLANES_ELEMENTS' table. - * - * - * - * You should add additional methods to this class to meet the - * application requirements. This class will only be generated as - * long as it does not already exist in the input directory. - * - * @package workflow.engine.classes.model - */ -class SwimlanesElements extends BaseSwimlanesElements { - - /** - * This value goes in the content table - * @var string - */ - protected $swi_text = ''; - - /* +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + +require_once 'classes/model/om/BaseSwimlanesElements.php'; +require_once 'classes/model/Content.php'; + +/** + * Skeleton subclass for representing a row from the 'SWIMLANES_ELEMENTS' table. + * + * + * + * You should add additional methods to this class to meet the + * application requirements. This class will only be generated as + * long as it does not already exist in the input directory. + * + * @package workflow.engine.classes.model + */ +class SwimlanesElements extends BaseSwimlanesElements +{ + + /** + * This value goes in the content table + * + * @var string + */ + protected $swi_text = ''; + + /* * Load the application document registry * @param string $sAppDocUid * @return variant - */ - public function load($sSwiEleUid) - { - try { - $oSwimlanesElements = SwimlanesElementsPeer::retrieveByPK($sSwiEleUid); - if (!is_null($oSwimlanesElements)) - { - $aFields = $oSwimlanesElements->toArray(BasePeer::TYPE_FIELDNAME); - $aFields['SWI_TEXT'] = $oSwimlanesElements->getSwiEleText(); - $this->fromArray($aFields, BasePeer::TYPE_FIELDNAME); - return $aFields; - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - throw($oError); - } - } - - /** - * Create the application document registry - * @param array $aData - * @return string - **/ - public function create($aData) - { - $oConnection = Propel::getConnection(SwimlanesElementsPeer::DATABASE_NAME); - try { - $aData['SWI_UID'] = G::generateUniqueID(); - $oSwimlanesElements = new SwimlanesElements(); - $oSwimlanesElements->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oSwimlanesElements->validate()) { - $oConnection->begin(); - if (isset($aData['SWI_TEXT'])) { - $oSwimlanesElements->setSwiEleText($aData['SWI_TEXT']); - } - $iResult = $oSwimlanesElements->save(); - $oConnection->commit(); - return $aData['SWI_UID']; - } - else { - $sMessage = ''; - $aValidationFailures = $oSwimlanesElements->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Update the application document registry - * @param array $aData - * @return string - **/ - public function update($aData) - { - $oConnection = Propel::getConnection(SwimlanesElementsPeer::DATABASE_NAME); - try { - $oSwimlanesElements = SwimlanesElementsPeer::retrieveByPK($aData['SWI_UID']); - if (!is_null($oSwimlanesElements)) - { - $oSwimlanesElements->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oSwimlanesElements->validate()) { - $oConnection->begin(); - if (isset($aData['SWI_TEXT'])) - { - $oSwimlanesElements->setSwiEleText($aData['SWI_TEXT']); - } - $iResult = $oSwimlanesElements->save(); - $oConnection->commit(); - return $iResult; - } - else { - $sMessage = ''; - $aValidationFailures = $oSwimlanesElements->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be updated!
'.$sMessage)); - } - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Remove the application document registry - * @param array $aData - * @return string - **/ - public function remove($sSwiEleUid) - { - $oConnection = Propel::getConnection(SwimlanesElementsPeer::DATABASE_NAME); - try { - $oSwimlanesElements = SwimlanesElementsPeer::retrieveByPK($sSwiEleUid); - if (!is_null($oSwimlanesElements)) - { - $oConnection->begin(); - Content::removeContent('SWI_TEXT', '', $oSwimlanesElements->getSwiUid()); - $iResult = $oSwimlanesElements->delete(); - $oConnection->commit(); - return $iResult; - } - else { - throw(new Exception('This row doesn\'t exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - -function swimlanesElementsExists ( $sSwiEleUid ) { - $con = Propel::getConnection(SwimlanesElementsPeer::DATABASE_NAME); - try { - $oSwiEleUid = SwimlanesElementsPeer::retrieveByPk( $sSwiEleUid ); - if (is_object($oSwiEleUid) && get_class ($oSwiEleUid) == 'SwimlanesElements' ) { - return true; - } - else { - return false; - } - } - catch (Exception $oError) { - throw($oError); - } - } - - /** - * Get the [swi_text] column value. - * @return string - */ - public function getSwiEleText() - { - if ($this->swi_text == '') { - try { - $this->swi_text = Content::load('SWI_TEXT', '', $this->getSwiUid(), (defined('SYS_LANG') ? SYS_LANG : 'en')); - } - catch (Exception $oError) { - throw($oError); - } - } - return $this->swi_text; - } - - /** - * Set the [swi_text] column value. - * - * @param string $sValue new value - * @return void - */ - public function setSwiEleText($sValue) - { - if ($sValue !== null && !is_string($sValue)) { - $sValue = (string)$sValue; - } - if ($this->swi_text !== $sValue || $sValue === '') { - try { - $this->swi_text = $sValue; - - $iResult = Content::addContent('SWI_TEXT', '', $this->getSwiUid(), (defined('SYS_LANG') ? SYS_LANG : 'en'), $this->swi_text); - } - catch (Exception $oError) { - $this->swi_text = ''; - throw($oError); - } - } - } - -} // SwimlanesElements \ No newline at end of file + */ + public function load ($sSwiEleUid) + { + try { + $oSwimlanesElements = SwimlanesElementsPeer::retrieveByPK( $sSwiEleUid ); + if (! is_null( $oSwimlanesElements )) { + $aFields = $oSwimlanesElements->toArray( BasePeer::TYPE_FIELDNAME ); + $aFields['SWI_TEXT'] = $oSwimlanesElements->getSwiEleText(); + $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME ); + return $aFields; + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create the application document registry + * + * @param array $aData + * @return string + * + */ + public function create ($aData) + { + $oConnection = Propel::getConnection( SwimlanesElementsPeer::DATABASE_NAME ); + try { + $aData['SWI_UID'] = G::generateUniqueID(); + $oSwimlanesElements = new SwimlanesElements(); + $oSwimlanesElements->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oSwimlanesElements->validate()) { + $oConnection->begin(); + if (isset( $aData['SWI_TEXT'] )) { + $oSwimlanesElements->setSwiEleText( $aData['SWI_TEXT'] ); + } + $iResult = $oSwimlanesElements->save(); + $oConnection->commit(); + return $aData['SWI_UID']; + } else { + $sMessage = ''; + $aValidationFailures = $oSwimlanesElements->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Update the application document registry + * + * @param array $aData + * @return string + * + */ + public function update ($aData) + { + $oConnection = Propel::getConnection( SwimlanesElementsPeer::DATABASE_NAME ); + try { + $oSwimlanesElements = SwimlanesElementsPeer::retrieveByPK( $aData['SWI_UID'] ); + if (! is_null( $oSwimlanesElements )) { + $oSwimlanesElements->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oSwimlanesElements->validate()) { + $oConnection->begin(); + if (isset( $aData['SWI_TEXT'] )) { + $oSwimlanesElements->setSwiEleText( $aData['SWI_TEXT'] ); + } + $iResult = $oSwimlanesElements->save(); + $oConnection->commit(); + return $iResult; + } else { + $sMessage = ''; + $aValidationFailures = $oSwimlanesElements->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be updated!
' . $sMessage )); + } + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Remove the application document registry + * + * @param array $aData + * @return string + * + */ + public function remove ($sSwiEleUid) + { + $oConnection = Propel::getConnection( SwimlanesElementsPeer::DATABASE_NAME ); + try { + $oSwimlanesElements = SwimlanesElementsPeer::retrieveByPK( $sSwiEleUid ); + if (! is_null( $oSwimlanesElements )) { + $oConnection->begin(); + Content::removeContent( 'SWI_TEXT', '', $oSwimlanesElements->getSwiUid() ); + $iResult = $oSwimlanesElements->delete(); + $oConnection->commit(); + return $iResult; + } else { + throw (new Exception( 'This row doesn\'t exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public function swimlanesElementsExists ($sSwiEleUid) + { + $con = Propel::getConnection( SwimlanesElementsPeer::DATABASE_NAME ); + try { + $oSwiEleUid = SwimlanesElementsPeer::retrieveByPk( $sSwiEleUid ); + if (is_object( $oSwiEleUid ) && get_class( $oSwiEleUid ) == 'SwimlanesElements') { + return true; + } else { + return false; + } + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Get the [swi_text] column value. + * + * @return string + */ + public function getSwiEleText () + { + if ($this->swi_text == '') { + try { + $this->swi_text = Content::load( 'SWI_TEXT', '', $this->getSwiUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en') ); + } catch (Exception $oError) { + throw ($oError); + } + } + return $this->swi_text; + } + + /** + * Set the [swi_text] column value. + * + * @param string $sValue new value + * @return void + */ + public function setSwiEleText ($sValue) + { + if ($sValue !== null && ! is_string( $sValue )) { + $sValue = (string) $sValue; + } + if ($this->swi_text !== $sValue || $sValue === '') { + try { + $this->swi_text = $sValue; + + $iResult = Content::addContent( 'SWI_TEXT', '', $this->getSwiUid(), (defined( 'SYS_LANG' ) ? SYS_LANG : 'en'), $this->swi_text ); + } catch (Exception $oError) { + $this->swi_text = ''; + throw ($oError); + } + } + } +} +// SwimlanesElements + diff --git a/workflow/engine/classes/model/TaskUser.php b/workflow/engine/classes/model/TaskUser.php index 7b19d9c22..8abf9da8e 100755 --- a/workflow/engine/classes/model/TaskUser.php +++ b/workflow/engine/classes/model/TaskUser.php @@ -1,198 +1,198 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ - -require_once 'classes/model/om/BaseTaskUser.php'; -require_once 'classes/model/Content.php'; - -/** - * Skeleton subclass for representing a row from the 'GROUP_USER' table. - * - * - * - * You should add additional methods to this class to meet the - * application requirements. This class will only be generated as - * long as it does not already exist in the input directory. - * - * @package workflow.engine.classes.model - */ -class TaskUser extends BaseTaskUser { - - /** - * Create the application document registry - * @param array $aData - * @return string - **/ - public function create($aData) - { - $oConnection = Propel::getConnection(TaskUserPeer::DATABASE_NAME); - try { - $taskUser = TaskUserPeer::retrieveByPK($aData['TAS_UID'], $aData['USR_UID'], $aData['TU_TYPE'], $aData['TU_RELATION']); - - if( is_object($taskUser) ) - return -1; - - $oTaskUser = new TaskUser(); - $oTaskUser->fromArray($aData, BasePeer::TYPE_FIELDNAME); - if ($oTaskUser->validate()) { - $oConnection->begin(); - $iResult = $oTaskUser->save(); - $oConnection->commit(); - return $iResult; - } - else { - $sMessage = ''; - $aValidationFailures = $oTaskUser->getValidationFailures(); - foreach($aValidationFailures as $oValidationFailure) { - $sMessage .= $oValidationFailure->getMessage() . '
'; - } - throw(new Exception('The registry cannot be created!
'.$sMessage)); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - /** - * Remove the application document registry - * @param string $sTasUid - * @param string $sUserUid - * @return string - **/ - public function remove($sTasUid, $sUserUid, $iType, $iRelation) - { - $oConnection = Propel::getConnection(TaskUserPeer::DATABASE_NAME); - try { - $oTaskUser = TaskUserPeer::retrieveByPK($sTasUid, $sUserUid, $iType, $iRelation); - if (!is_null($oTaskUser)) - { - $oConnection->begin(); - $iResult = $oTaskUser->delete(); - $oConnection->commit(); - return $iResult; - } - else { - throw(new Exception('This row does not exist!')); - } - } - catch (Exception $oError) { - $oConnection->rollback(); - throw($oError); - } - } - - function TaskUserExists ($sTasUid, $sUserUid, $iType, $iRelation) { - $con = Propel::getConnection(TaskUserPeer::DATABASE_NAME); - try { - $oTaskUser = TaskUserPeer::retrieveByPk($sTasUid, $sUserUid, $iType, $iRelation); - if ( is_object($oTaskUser) && get_class ($oTaskUser) == 'TaskUser' ) { - return true; - } - else { - return false; - } - } - catch (Exception $oError) { - throw($oError); - } - } - - function getCountAllTaksByGroups(){ - $oCriteria = new Criteria('workflow'); - $oCriteria->addAsColumn('GRP_UID', TaskUserPeer::USR_UID); - $oCriteria->addSelectColumn('COUNT(*) AS CNT'); - $oCriteria->add(TaskUserPeer::TU_TYPE,1); - $oCriteria->add(TaskUserPeer::TU_RELATION,2); - $oCriteria->addGroupByColumn(TaskUserPeer::USR_UID); - $oDataset = TaskUserPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode (ResultSet::FETCHMODE_ASSOC); - $aRows = Array(); - while ($oDataset->next()){ - $row = $oDataset->getRow(); - $aRows[$row['GRP_UID']] = $row['CNT']; - } - return $aRows; - } - - //erik: new functions - function getUsersTask($TAS_UID, $TU_TYPE=1){ - - require_once 'classes/model/Users.php'; - - $groupsTask = array(); - $usersTask = array(); - - //getting task's users - $criteria = new Criteria('workflow'); - $criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME); - $criteria->addSelectColumn(UsersPeer::USR_LASTNAME); - $criteria->addSelectColumn(UsersPeer::USR_USERNAME); - $criteria->addSelectColumn(TaskUserPeer::TAS_UID); - $criteria->addSelectColumn(TaskUserPeer::USR_UID); - $criteria->addSelectColumn(TaskUserPeer::TU_TYPE); - $criteria->addSelectColumn(TaskUserPeer::TU_RELATION); - $criteria->addJoin(TaskUserPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN); - $criteria->add(TaskUserPeer::TAS_UID, $TAS_UID); - $criteria->add(TaskUserPeer::TU_TYPE, $TU_TYPE); - $criteria->add(TaskUserPeer::TU_RELATION, 1); - - $dataset = TaskUserPeer::doSelectRS($criteria); - $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - - while ($dataset->next()) - $usersTask[] = $dataset->getRow(); - - //getting task's groups - $delimiter = DBAdapter::getStringDelimiter (); - $criteria = new Criteria('workflow'); - $criteria->addAsColumn('GRP_TITLE', 'CONTENT.CON_VALUE'); - $criteria->addSelectColumn(TaskUserPeer::TAS_UID); - $criteria->addSelectColumn(TaskUserPeer::USR_UID); - $criteria->addSelectColumn(TaskUserPeer::TU_TYPE); - $criteria->addSelectColumn(TaskUserPeer::TU_RELATION); - $aConditions[] = array(TaskUserPeer::USR_UID, 'CONTENT.CON_ID'); - $aConditions[] = array('CONTENT.CON_CATEGORY', $delimiter . 'GRP_TITLE' . $delimiter); - $aConditions[] = array('CONTENT.CON_LANG', $delimiter . SYS_LANG . $delimiter); - $criteria->addJoinMC($aConditions, Criteria::LEFT_JOIN); - $criteria->add(TaskUserPeer::TAS_UID, $TAS_UID); - $criteria->add(TaskUserPeer::TU_TYPE, $TU_TYPE); - $criteria->add(TaskUserPeer::TU_RELATION, 2); - $dataset = TaskUserPeer::doSelectRS($criteria); - - $dataset = TaskUserPeer::doSelectRS($criteria); - $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - - while( $dataset->next() ) - $usersTask[] = $dataset->getRow(); - - $result->data = $usersTask; - $result->totalCount = sizeof($usersTask); - - return $result; - } - -} // TaskUser \ No newline at end of file +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ + +require_once 'classes/model/om/BaseTaskUser.php'; +require_once 'classes/model/Content.php'; + +/** + * Skeleton subclass for representing a row from the 'GROUP_USER' table. + * + * + * + * You should add additional methods to this class to meet the + * application requirements. This class will only be generated as + * long as it does not already exist in the input directory. + * + * @package workflow.engine.classes.model + */ +class TaskUser extends BaseTaskUser +{ + + /** + * Create the application document registry + * + * @param array $aData + * @return string + * + */ + public function create ($aData) + { + $oConnection = Propel::getConnection( TaskUserPeer::DATABASE_NAME ); + try { + $taskUser = TaskUserPeer::retrieveByPK( $aData['TAS_UID'], $aData['USR_UID'], $aData['TU_TYPE'], $aData['TU_RELATION'] ); + + if (is_object( $taskUser )) { + return - 1; + } + $oTaskUser = new TaskUser(); + $oTaskUser->fromArray( $aData, BasePeer::TYPE_FIELDNAME ); + if ($oTaskUser->validate()) { + $oConnection->begin(); + $iResult = $oTaskUser->save(); + $oConnection->commit(); + return $iResult; + } else { + $sMessage = ''; + $aValidationFailures = $oTaskUser->getValidationFailures(); + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception( 'The registry cannot be created!
' . $sMessage )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + /** + * Remove the application document registry + * + * @param string $sTasUid + * @param string $sUserUid + * @return string + * + */ + public function remove ($sTasUid, $sUserUid, $iType, $iRelation) + { + $oConnection = Propel::getConnection( TaskUserPeer::DATABASE_NAME ); + try { + $oTaskUser = TaskUserPeer::retrieveByPK( $sTasUid, $sUserUid, $iType, $iRelation ); + if (! is_null( $oTaskUser )) { + $oConnection->begin(); + $iResult = $oTaskUser->delete(); + $oConnection->commit(); + return $iResult; + } else { + throw (new Exception( 'This row does not exist!' )); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public function TaskUserExists ($sTasUid, $sUserUid, $iType, $iRelation) + { + $con = Propel::getConnection( TaskUserPeer::DATABASE_NAME ); + try { + $oTaskUser = TaskUserPeer::retrieveByPk( $sTasUid, $sUserUid, $iType, $iRelation ); + if (is_object( $oTaskUser ) && get_class( $oTaskUser ) == 'TaskUser') { + return true; + } else { + return false; + } + } catch (Exception $oError) { + throw ($oError); + } + } + + public function getCountAllTaksByGroups () + { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addAsColumn( 'GRP_UID', TaskUserPeer::USR_UID ); + $oCriteria->addSelectColumn( 'COUNT(*) AS CNT' ); + $oCriteria->add( TaskUserPeer::TU_TYPE, 1 ); + $oCriteria->add( TaskUserPeer::TU_RELATION, 2 ); + $oCriteria->addGroupByColumn( TaskUserPeer::USR_UID ); + $oDataset = TaskUserPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $aRows = Array (); + while ($oDataset->next()) { + $row = $oDataset->getRow(); + $aRows[$row['GRP_UID']] = $row['CNT']; + } + return $aRows; + } + //erik: new functions + public function getUsersTask ($TAS_UID, $TU_TYPE = 1) + { + require_once 'classes/model/Users.php'; + + $groupsTask = array (); + $usersTask = array (); + + //getting task's users + $criteria = new Criteria( 'workflow' ); + $criteria->addSelectColumn( UsersPeer::USR_FIRSTNAME ); + $criteria->addSelectColumn( UsersPeer::USR_LASTNAME ); + $criteria->addSelectColumn( UsersPeer::USR_USERNAME ); + $criteria->addSelectColumn( TaskUserPeer::TAS_UID ); + $criteria->addSelectColumn( TaskUserPeer::USR_UID ); + $criteria->addSelectColumn( TaskUserPeer::TU_TYPE ); + $criteria->addSelectColumn( TaskUserPeer::TU_RELATION ); + $criteria->addJoin( TaskUserPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN ); + $criteria->add( TaskUserPeer::TAS_UID, $TAS_UID ); + $criteria->add( TaskUserPeer::TU_TYPE, $TU_TYPE ); + $criteria->add( TaskUserPeer::TU_RELATION, 1 ); + + $dataset = TaskUserPeer::doSelectRS( $criteria ); + $dataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + + while ($dataset->next()) { + $usersTask[] = $dataset->getRow(); + } + //getting task's groups + $delimiter = DBAdapter::getStringDelimiter(); + $criteria = new Criteria( 'workflow' ); + $criteria->addAsColumn( 'GRP_TITLE', 'CONTENT.CON_VALUE' ); + $criteria->addSelectColumn( TaskUserPeer::TAS_UID ); + $criteria->addSelectColumn( TaskUserPeer::USR_UID ); + $criteria->addSelectColumn( TaskUserPeer::TU_TYPE ); + $criteria->addSelectColumn( TaskUserPeer::TU_RELATION ); + $aConditions[] = array (TaskUserPeer::USR_UID,'CONTENT.CON_ID'); + $aConditions[] = array ('CONTENT.CON_CATEGORY',$delimiter . 'GRP_TITLE' . $delimiter); + $aConditions[] = array ('CONTENT.CON_LANG',$delimiter . SYS_LANG . $delimiter); + $criteria->addJoinMC( $aConditions, Criteria::LEFT_JOIN ); + $criteria->add( TaskUserPeer::TAS_UID, $TAS_UID ); + $criteria->add( TaskUserPeer::TU_TYPE, $TU_TYPE ); + $criteria->add( TaskUserPeer::TU_RELATION, 2 ); + $dataset = TaskUserPeer::doSelectRS( $criteria ); + $dataset = TaskUserPeer::doSelectRS( $criteria ); + $dataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + + while ($dataset->next()) { + $usersTask[] = $dataset->getRow(); + } + $result->data = $usersTask; + $result->totalCount = sizeof( $usersTask ); + + return $result; + } +} +// TaskUser + diff --git a/workflow/engine/classes/triggers/api/class.zimbraApi.php b/workflow/engine/classes/triggers/api/class.zimbraApi.php index 9c80cb328..f226df271 100644 --- a/workflow/engine/classes/triggers/api/class.zimbraApi.php +++ b/workflow/engine/classes/triggers/api/class.zimbraApi.php @@ -1,363 +1,375 @@ - - * @GPL 2007, Plymouth State University, ITS - */ -class Zimbra { - - public $debug = false; - public $error; + + * @GPL 2007, Plymouth State University, ITS + */ +class Zimbra +{ + + public $debug = false; + public $error; protected $_connected = false; // boolean to determine if the connect function has been called protected static $_num_soap_calls = 0; // the number of times a SOAP call has been made protected $_preAuthKey; // key for doing pre-authentication - protected $_lcached_assets = array(); // an array to hold assets that have been cached + protected $_lcached_assets = array (); // an array to hold assets that have been cached protected $_preauth_expiration = 0; // 0 indicates using the default preauth expiration as defined on the server protected $_dev; // boolean indicating whether this is development or not protected $_protocol; // which protocol to use when building the URL - protected $_server1;// = 'ip-10-73-18-235.ec2.internal'; // hostname of zimbra server + protected $_server1; // = 'ip-10-73-18-235.ec2.internal'; // hostname of zimbra server protected $_server; // displayname of zimbra server - protected $_path = '/service/soap'; - protected $_timestamp; - protected $_account_info; + protected $_path = '/service/soap'; + protected $_timestamp; + protected $_account_info; protected $_admin = false; // operating as an admin - protected $_curl; + protected $_curl; protected $_auth_token; // used for repeat calls to zimbra through soap protected $_session_id; // used for repeat calls to zimbra through soap - protected $_idm; // IDMObject + protected $_idm; // IDMObject protected $_username; // the user we are operating as - - /** - * __construct - * - * constructor sets up connectivity to servers - * - * @since version 1.0 - * @acess public - * @param string $username username - * @param string $which defaults to prod - */ - - public function __construct($username, $serverUrl, $preAuthKey, $which = 'prod') { - if ($which == 'dev') { - $which = 'zimbra_dev'; - $this->_dev = true; - } else { - $which = 'zimbra'; - } - - $this->_preAuthKey = $preAuthKey; + + + /** + * __construct + * + * constructor sets up connectivity to servers + * + * @since version 1.0 + * @acess public + * @param string $username username + * @param string $which defaults to prod + */ + + public function __construct ($username, $serverUrl, $preAuthKey, $which = 'prod') + { + if ($which == 'dev') { + $which = 'zimbra_dev'; + $this->_dev = true; + } else { + $which = 'zimbra'; + } + + $this->_preAuthKey = $preAuthKey; $this->_protocol = "http://"; // could also be http:// $this->_server = $serverUrl; //'zimbra.hostname.edu'; $this->_server1 = $serverUrl; //'zimbra.hostname.edu'; - $this->_username = $username; - $this->_timestamp = time() . '000'; - } - + $this->_username = $username; + $this->_timestamp = time() . '000'; + } + // end __construct - - /** - * sso - * - * sso to Zimbra - * - * @since version 1.0 - * @access public - * @param string $options options for sso - * @return boolean - */ - public function sso($options='') { - if ($this->_username) { - setcookie('ZM_SKIN', 'plymouth', time() + 60 * 60 * 24 * 30, '/', '.plymouth.edu'); - - $pre_auth = $this->getPreAuth($this->_username); + + + /** + * sso + * + * sso to Zimbra + * + * @since version 1.0 + * @access public + * @param string $options options for sso + * @return boolean + */ + public function sso ($options = '') + { + if ($this->_username) { + setcookie( 'ZM_SKIN', 'plymouth', time() + 60 * 60 * 24 * 30, '/', '.plymouth.edu' ); + + $pre_auth = $this->getPreAuth( $this->_username ); $url = $this->_protocol . '/service/preauth?account=' . $this->_username . '@' . $this->_server . '&expires=' . $this->_preauth_expiration . '×tamp=' . $this->_timestamp . '&preauth=' . $pre_auth; //.'&'.$options; - header("Location: $url"); - exit; - } else { - return false; - } - } - + header( "Location: $url" ); + exit(); + } else { + return false; + } + } + // end sso - - /** - * createAccount - * @param string $name account name - * @param string $password password - * @return string account id - */ - function createAccount($name, $password) { - $option_string = ''; - - try { - - + + + /** + * createAccount + * + * @param string $name account name + * @param string $password password + * @return string account id + */ + function createAccount ($name, $password) + { + $option_string = ''; + + try { + $soap = ' ' . $name . '@' . $this->_server1 . ' ' . $password . '' . $option_string . ' - '; - - - $response = $this->soapRequest($soap); - } catch (SoapFault $exception) { - print_exception($exception); - } - - return $result['SOAP:ENVELOPE']['SOAP:BODY']['CREATEACCOUNTRESPONSE']['ACCOUNT']['ID']; - } - - /** - * getPreAuth - * - * get the preauth key needed for single-sign on - * - * @since version1.0 - * @access public - * @param string $username username - * @return string preauthentication key in hmacsha1 format - */ - private function getPreAuth($username) { - $account_identifier = $username . '@' . $this->_server1; - $by_value = 'name'; - $expires = $this->_preauth_expiration; - $timestamp = $this->_timestamp; - - $string = $account_identifier . '|' . $by_value . '|' . $expires . '|' . $timestamp; - - return $this->hmacsha1($this->_preAuthKey, $string); - } - + '; + + $response = $this->soapRequest( $soap ); + } catch (SoapFault $exception) { + print_exception( $exception ); + } + + return $result['SOAP:ENVELOPE']['SOAP:BODY']['CREATEACCOUNTRESPONSE']['ACCOUNT']['ID']; + } + + /** + * getPreAuth + * + * get the preauth key needed for single-sign on + * + * @since version1.0 + * @access public + * @param string $username username + * @return string preauthentication key in hmacsha1 format + */ + private function getPreAuth ($username) + { + $account_identifier = $username . '@' . $this->_server1; + $by_value = 'name'; + $expires = $this->_preauth_expiration; + $timestamp = $this->_timestamp; + + $string = $account_identifier . '|' . $by_value . '|' . $expires . '|' . $timestamp; + + return $this->hmacsha1( $this->_preAuthKey, $string ); + } + // end getPreAuth - - /** - * hmacsha1 - * - * generate an HMAC using SHA1, required for preauth - * - * @since version 1.0 - * @access public - * @param int $key encryption key - * @param string $data data to encrypt - * @return string converted to hmac sha1 format - */ - private function hmacsha1($key, $data) { - $blocksize = 64; - $hashfunc = 'sha1'; - if (strlen($key) > $blocksize) - $key = pack('H*', $hashfunc($key)); - $key = str_pad($key, $blocksize, chr(0x00)); - $ipad = str_repeat(chr(0x36), $blocksize); - $opad = str_repeat(chr(0x5c), $blocksize); - $hmac = pack( - 'H*', $hashfunc( - ($key ^ $opad) . pack( - 'H*', $hashfunc( - ($key ^ $ipad) . $data - ) - ) - ) - ); - return bin2hex($hmac); - } - + + + /** + * hmacsha1 + * + * generate an HMAC using SHA1, required for preauth + * + * @since version 1.0 + * @access public + * @param int $key encryption key + * @param string $data data to encrypt + * @return string converted to hmac sha1 format + */ + private function hmacsha1 ($key, $data) + { + $blocksize = 64; + $hashfunc = 'sha1'; + if (strlen( $key ) > $blocksize) { + $key = pack( 'H*', $hashfunc( $key ) ); + } + $key = str_pad( $key, $blocksize, chr( 0x00 ) ); + $ipad = str_repeat( chr( 0x36 ), $blocksize ); + $opad = str_repeat( chr( 0x5c ), $blocksize ); + $hmac = pack( 'H*', $hashfunc( ($key ^ $opad) . pack( 'H*', $hashfunc( ($key ^ $ipad) . $data ) ) ) ); + return bin2hex( $hmac ); + } + // end hmacsha1 - - /** - * connect - * - * connect to the Zimbra SOAP service - * - * @since version 1.0 - * @access public - * @return array associative array of account information - */ - public function connect() { - if ($this->_connected) { - return $this->_account_info; - } - $completeurl = $this->_protocol . $this->_server . $this->_path; - $this->_curl = curl_init(); - curl_setopt($this->_curl, CURLOPT_URL, $this->_protocol . $this->_server . $this->_path); - curl_setopt($this->_curl, CURLOPT_POST, true); - curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($this->_curl, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($this->_curl, CURLOPT_SSL_VERIFYHOST, false); - + + + /** + * connect + * + * connect to the Zimbra SOAP service + * + * @since version 1.0 + * @access public + * @return array associative array of account information + */ + public function connect () + { + if ($this->_connected) { + return $this->_account_info; + } + $completeurl = $this->_protocol . $this->_server . $this->_path; + $this->_curl = curl_init(); + curl_setopt( $this->_curl, CURLOPT_URL, $this->_protocol . $this->_server . $this->_path ); + curl_setopt( $this->_curl, CURLOPT_POST, true ); + curl_setopt( $this->_curl, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $this->_curl, CURLOPT_SSL_VERIFYPEER, false ); + curl_setopt( $this->_curl, CURLOPT_SSL_VERIFYHOST, false ); + //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt($this->_curl, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '')); - if ($sysConf['proxy_port'] != '') { - curl_setopt($this->_curl, CURLOPT_PROXYPORT, $sysConf['proxy_port']); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt($this->_curl, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); - } - curl_setopt($this->_curl, CURLOPT_HTTPHEADER, array('Expect:')); - } - - $preauth = $this->getPreAuth($this->_username); - $header = ''; - - if ($this->_admin) { + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $this->_curl, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $this->_curl, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $this->_curl, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $this->_curl, CURLOPT_HTTPHEADER, array ('Expect:') ); + } + + $preauth = $this->getPreAuth( $this->_username ); + $header = ''; + + if ($this->_admin) { $body = ' ' . $this->_admin_username . ' ' . $this->_admin_password . ' - '; - } else { + '; + } else { $body = ' ' . $this->_username . '@' . $this->_server1 . ' ' . $preauth . ' - '; - } - - $response = $this->soapRequest($body, $header, true); - if ($response) { - $tmp = $this->makeXMLTree($response); - $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; - - $this->session_id = $this->extractSessionID($response); - $this->auth_token = $this->extractAuthToken($response); - - $this->_connected = true; - + '; + } + + $response = $this->soapRequest( $body, $header, true ); + if ($response) { + $tmp = $this->makeXMLTree( $response ); + $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; + + $this->session_id = $this->extractSessionID( $response ); + $this->auth_token = $this->extractAuthToken( $response ); + + $this->_connected = true; + //return $this->_account_info; - return $this->_connected; - } else { - $this->_connected = false; - return false; - } - } - + return $this->_connected; + } else { + $this->_connected = false; + return false; + } + } + // end connect - - /** - * administerUser - * - * set the user you are administering (experimental) - * - * @since version 1.0 - * @access public - * @param string $username username to administer - * @return boolean - */ - public function administerUser($username) { - if (!$this->_admin) { - return false; - } - - $this->_username = $username; - + + + /** + * administerUser + * + * set the user you are administering (experimental) + * + * @since version 1.0 + * @access public + * @param string $username username to administer + * @return boolean + */ + public function administerUser ($username) + { + if (! $this->_admin) { + return false; + } + + $this->_username = $username; + $body = ' ' . $this->_username . '@' . $this->_server . ' - '; - $response = $this->soapRequest($body, $header); - if ($response) { - $tmp = $this->makeXMLTree($response); - $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; - - $this->session_id = $this->extractSessionID($response); - $this->auth_token = $this->extractAuthToken($response); - - return true; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $body, $header ); + if ($response) { + $tmp = $this->makeXMLTree( $response ); + $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; + + $this->session_id = $this->extractSessionID( $response ); + $this->auth_token = $this->extractAuthToken( $response ); + + return true; + } else { + return false; + } + } + // end administerUser - - /** - * getInfo - * - * generic function to get information on mailbox, preferences, attributes, properties, and more! - * - * @since version 1.0 - * @access public - * @param string $options options for info retrieval, defaults to null - * @return array information - */ - public function getInfo($options='') { + + + /** + * getInfo + * + * generic function to get information on mailbox, preferences, attributes, properties, and more! + * + * @since version 1.0 + * @access public + * @param string $options options for info retrieval, defaults to null + * @return array information + */ + public function getInfo ($options = '') + { // valid sections: mbox,prefs,attrs,zimlets,props,idents,sigs,dsrcs,children - $option_string = $this->buildOptionString($options); - - $soap = ''; - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - return $array['soap:Envelope'][0]['soap:Body'][0]['GetInfoResponse'][0]; - } else { - return false; - } - } - + $option_string = $this->buildOptionString( $options ); + + $soap = ''; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['GetInfoResponse'][0]; + } else { + return false; + } + } + // end getInfo - - /** - * getMessages - * - * get the messages in folder, deafults to inbox - * - * @since version 1.0 - * @access public - * @param string $search folder to retrieve from, defaults to in:inbox - * @param array $options options to apply to retrieval - * @return array array of messages - */ - public function getMessages($search='in:inbox', $options=array('limit' => 5, 'fetch' => 'none')) { - $option_string = $this->buildOptionString($options); - + + + /** + * getMessages + * + * get the messages in folder, deafults to inbox + * + * @since version 1.0 + * @access public + * @param string $search folder to retrieve from, defaults to in:inbox + * @param array $options options to apply to retrieval + * @return array array of messages + */ + public function getMessages ($search = 'in:inbox', $options = array('limit' => 5, 'fetch' => 'none')) + { + $option_string = $this->buildOptionString( $options ); + $soap = ' ' . $search . ' - '; - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + // end getMessages - - /** - * getContacts - * - * get the Contacts in folder, deafults to inbox - * - * @since version 1.0 - * @access public - * @param string $search folder to retrieve from, defaults to in:inbox - * @param array $options options to apply to retrieval - * @return array array of messages - */ - public function getContacts($search='in:contacts', $options=array('limit' => 5, 'fetch' => 'none')) { - $option_string = $this->buildOptionString($options); - + + + /** + * getContacts + * + * get the Contacts in folder, deafults to inbox + * + * @since version 1.0 + * @access public + * @param string $search folder to retrieve from, defaults to in:inbox + * @param array $options options to apply to retrieval + * @return array array of messages + */ + public function getContacts ($search = 'in:contacts', $options = array('limit' => 5, 'fetch' => 'none')) + { + $option_string = $this->buildOptionString( $options ); + $soap = ' ' . $search . ' - '; - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + // end getContacts - - + + /* getAppointments * * get the Appointments in folder @@ -367,25 +379,27 @@ class Zimbra { * @param string $search folder to retrieve from * @param array $options options to apply to retrieval * @return array array of messages - */ - - public function getAppointments($search='in:calendar', $options=array('limit' => 50, 'fetch' => 'none')) { - $option_string = $this->buildOptionString($options); - + */ + + public function getAppointments ($search = 'in:calendar', $options = array('limit' => 50, 'fetch' => 'none')) + { + $option_string = $this->buildOptionString( $options ); + $soap = ' ' . $search . ' - '; - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + // end getAppointments - + + /* getTasks * * get the Tasks in folder @@ -395,618 +409,661 @@ class Zimbra { * @param string $search folder to retrieve from * @param array $options options to apply to retrieval * @return array array of messages - */ - - public function getTasks($search='in:tasks', $options=array('limit' => 50, 'fetch' => 'none')) { - $option_string = $this->buildOptionString($options); - + */ + + public function getTasks ($search = 'in:tasks', $options = array('limit' => 50, 'fetch' => 'none')) + { + $option_string = $this->buildOptionString( $options ); + $soap = ' ' . $search . ' - '; - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + // end getTasks - - /** - * getMessageContent - * - * get the content from a message - * - * @since version 1.0 - * @access public - * @param int $id id number of message to retrieve content of - * @return array associative array with message content, valid for tasks, calendar entries, and email messages. - */ - public function getMessageContent($id) { + + + /** + * getMessageContent + * + * get the content from a message + * + * @since version 1.0 + * @access public + * @param int $id id number of message to retrieve content of + * @return array associative array with message content, valid for tasks, calendar entries, and email messages. + */ + public function getMessageContent ($id) + { $soap = ' * - '; - $response = $this->soapRequest($soap); - - if ($response) { - $array = $this->makeXMLTree($response); - $temp = $array['soap:Envelope'][0]['soap:Body'][0]['GetMsgResponse'][0]['m'][0]; - - $message = $temp['inv'][0]['comp'][0]; - + '; + $response = $this->soapRequest( $soap ); + + if ($response) { + $array = $this->makeXMLTree( $response ); + $temp = $array['soap:Envelope'][0]['soap:Body'][0]['GetMsgResponse'][0]['m'][0]; + + $message = $temp['inv'][0]['comp'][0]; + // content with no attachment - $message['content'] = $temp['mp'][0]['mp'][1]['content'][0]; - + $message['content'] = $temp['mp'][0]['mp'][1]['content'][0]; + // content with attachment - $message['content'] .= $temp['mp'][0]['mp'][0]['mp'][1]['content'][0]; - - return $message; - } else { - return false; - } - } - - /** - * getSubscribedCalendars - * - * get the calendars the user is subscribed to - * - * @since version 1.0 - * @access public - * @return array $subscribed - */ - public function getSubscribedCalendars() { - $subscribed = array(); - if (is_array($this->_account_info['link_attribute_name'])) { - foreach ($this->_account_info['link_attribute_name'] as $i => $name) { - if ($this->_account_info['link_attribute_view'][$i] == 'appointment') - $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; - } - } - return $subscribed; - } - + $message['content'] .= $temp['mp'][0]['mp'][0]['mp'][1]['content'][0]; + + return $message; + } else { + return false; + } + } + + /** + * getSubscribedCalendars + * + * get the calendars the user is subscribed to + * + * @since version 1.0 + * @access public + * @return array $subscribed + */ + public function getSubscribedCalendars () + { + $subscribed = array (); + if (is_array( $this->_account_info['link_attribute_name'] )) { + foreach ($this->_account_info['link_attribute_name'] as $i => $name) { + if ($this->_account_info['link_attribute_view'][$i] == 'appointment') { + $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; + } + } + } + return $subscribed; + } + // end getSubscribedCalendars - - /** - * getSubscribedTaskLists - * - * get the task lists the user is subscribed to - * - * @since version 1.0 - * @access public - * @return array $subscribed or false - */ - public function getSubscribedTaskLists() { - $subscribed = array(); - if (is_array($this->_account_info['link_attribute_name'])) { - foreach ($this->_account_info['link_attribute_name'] as $i => $name) { - if ($this->_account_info['link_attribute_view'][$i] == 'task') - $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; - } - } - return $subscribed; - } - + + + /** + * getSubscribedTaskLists + * + * get the task lists the user is subscribed to + * + * @since version 1.0 + * @access public + * @return array $subscribed or false + */ + public function getSubscribedTaskLists () + { + $subscribed = array (); + if (is_array( $this->_account_info['link_attribute_name'] )) { + foreach ($this->_account_info['link_attribute_name'] as $i => $name) { + if ($this->_account_info['link_attribute_view'][$i] == 'task') { + $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; + } + } + } + return $subscribed; + } + // end getSubscribedCalendars - - /** - * getFolder - * - * get a folder (experimental) - * - * @since version 1.0 - * @access public - * @param string $folder_options options for folder retrieval - * @return array $folder or false - */ - public function getFolder($folderName, $folder_options='') { - + + + /** + * getFolder + * + * get a folder (experimental) + * + * @since version 1.0 + * @access public + * @param string $folder_options options for folder retrieval + * @return array $folder or false + */ + public function getFolder ($folderName, $folder_options = '') + { + //$folder_option_string = $this->buildOptionString($folder_options); - + + $soap = ' - '; - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - - $folder = (is_array($array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0])) ? $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0] : $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]; - - $folder['u'] = (!isset($folder['u'])) ? $folder['folder_attribute_u'][0] : $folder['u']; - $folder['n'] = (!isset($folder['n'])) ? $folder['folder_attribute_n'][0] : $folder['n']; - - return $folder; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + + $folder = (is_array( $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0] )) ? $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0] : $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]; + + $folder['u'] = (! isset( $folder['u'] )) ? $folder['folder_attribute_u'][0] : $folder['u']; + $folder['n'] = (! isset( $folder['n'] )) ? $folder['folder_attribute_n'][0] : $folder['n']; + + return $folder; + } else { + return false; + } + } + // end getFolder - - /** - * getPrefrences - * - * get preferences - * - * @since version 1.0 - * @access public - * @example example XML: [ ] - * @return array $prefs or false - */ - public function getPreferences() { - $soap = ''; - $response = $this->soapRequest($soap); - if ($response) { - $prefs = array(); - $array = $this->makeXMLTree($response); - foreach ($array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref'] as $k => $value) { - $prefs[$array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref_attribute_name'][$k]] = $value; - } - return $prefs; - } else { - return false; - } - } - + + + /** + * getPrefrences + * + * get preferences + * + * @since version 1.0 + * @access public + * @example example XML: [ ] + * @return array $prefs or false + */ + public function getPreferences () + { + $soap = ''; + $response = $this->soapRequest( $soap ); + if ($response) { + $prefs = array (); + $array = $this->makeXMLTree( $response ); + foreach ($array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref'] as $k => $value) { + $prefs[$array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref_attribute_name'][$k]] = $value; + } + return $prefs; + } else { + return false; + } + } + // end getPreferences - - /** - * setPrefrences - * - * modify preferences - * - * @since version 1.0 - * @access public - * @param string $options options to set the prefrences - * @example example XML: [{value}...]+ - * @return boolean - */ - public function setPreferences($options='') { - $option_string = ''; - foreach ($options as $name => $value) { - $option_string .= '' . $value . ''; - } - + + + /** + * setPrefrences + * + * modify preferences + * + * @since version 1.0 + * @access public + * @param string $options options to set the prefrences + * @example example XML: [{value}...]+ + * @return boolean + */ + public function setPreferences ($options = '') + { + $option_string = ''; + foreach ($options as $name => $value) { + $option_string .= '' . $value . ''; + } + $soap = ' ' . $option_string . ' - '; - $response = $this->soapRequest($soap); - if ($response) { - return true; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + return true; + } else { + return false; + } + } + // end setPreferences - - /** - * emailChannel - * - * build the email channel - * - * @since version 1.0 - * @access public - */ - public function emailChannel() { - require_once 'xtemplate.php'; - $tpl = new XTemplate('/web/pscpages/webapp/portal/channel/email/templates/index.tpl'); - - $tpl->parse('main.transition'); - - $total_messages = 0; - $unread_messages = 0; - - $messages = $this->getMessages('in:inbox'); - if (is_array($messages)) { - $more = $messages['more']; - foreach ($messages['m'] as $message) { - $clean_message = array(); - - $clean_message['subject'] = (isset($message['su'][0]) && $message['su'][0] != '') ? htmlentities($message['su'][0]) : '[None]'; - $clean_message['subject'] = (strlen($clean_message['subject']) > 20) ? substr($clean_message['subject'], 0, 17) . '...' : $clean_message['subject']; - - $clean_message['body_fragment'] = $message['fr'][0]; - $clean_message['from_email'] = $message['e_attribute_a'][0]; - $clean_message['from'] = ($message['e_attribute_p'][0]) ? htmlspecialchars($message['e_attribute_p'][0]) : $clean_message['from_email']; - $clean_message['size'] = $this->makeBytesPretty($message['s'], 40 * 1024 * 1024); - $clean_message['date'] = date('n/j/y', ($message['d'] / 1000)); - $clean_message['id'] = $message['id']; - $clean_message['url'] = 'http://go.plymouth.edu/mymail/msg/' . $clean_message['id']; - - $clean_message['attachment'] = false; - $clean_message['status'] = 'read'; - $clean_message['deleted'] = false; - $clean_message['flagged'] = false; - if (isset($message['f'])) { - $clean_message['attachment'] = (strpos($message['f'], 'a') !== false) ? true : false; - $clean_message['status'] = (strpos($message['f'], 'u') !== false) ? 'unread' : 'read'; - ; - $clean_message['deleted'] = (strpos($message['f'], '2') !== false) ? true : false; - $clean_message['flagged'] = (strpos($message['f'], 'f') !== false) ? true : false; - } - - $tpl->assign('message', $clean_message); - $tpl->parse('main.message'); - } - $inbox = $this->getFolder(array('l' => 2)); - - $total_messages = (int) $inbox['n']; - $unread_messages = (int) $inbox['u']; - } - - $tpl->assign('total_messages', $total_messages); - $tpl->assign('unread_messages', $unread_messages); - - $info = $this->getInfo(array('sections' => 'mbox')); - if (is_array($info['attrs'][0]['attr_attribute_name'])) { - $quota = $info['attrs'][0]['attr'][array_search('zimbraMailQuota', $info['attrs'][0]['attr_attribute_name'])]; - $size_text = $this->makeBytesPretty($info['used'][0], ($quota * 0.75)) . ' out of ' . $this->makeBytesPretty($quota); - $tpl->assign('size', $size_text); - } - + + + /** + * emailChannel + * + * build the email channel + * + * @since version 1.0 + * @access public + */ + public function emailChannel () + { + require_once 'xtemplate.php'; + $tpl = new XTemplate( '/web/pscpages/webapp/portal/channel/email/templates/index.tpl' ); + + $tpl->parse( 'main.transition' ); + + $total_messages = 0; + $unread_messages = 0; + + $messages = $this->getMessages( 'in:inbox' ); + if (is_array( $messages )) { + $more = $messages['more']; + foreach ($messages['m'] as $message) { + $clean_message = array (); + + $clean_message['subject'] = (isset( $message['su'][0] ) && $message['su'][0] != '') ? htmlentities( $message['su'][0] ) : '[None]'; + $clean_message['subject'] = (strlen( $clean_message['subject'] ) > 20) ? substr( $clean_message['subject'], 0, 17 ) . '...' : $clean_message['subject']; + + $clean_message['body_fragment'] = $message['fr'][0]; + $clean_message['from_email'] = $message['e_attribute_a'][0]; + $clean_message['from'] = ($message['e_attribute_p'][0]) ? htmlspecialchars( $message['e_attribute_p'][0] ) : $clean_message['from_email']; + $clean_message['size'] = $this->makeBytesPretty( $message['s'], 40 * 1024 * 1024 ); + $clean_message['date'] = date( 'n/j/y', ($message['d'] / 1000) ); + $clean_message['id'] = $message['id']; + $clean_message['url'] = 'http://go.plymouth.edu/mymail/msg/' . $clean_message['id']; + + $clean_message['attachment'] = false; + $clean_message['status'] = 'read'; + $clean_message['deleted'] = false; + $clean_message['flagged'] = false; + if (isset( $message['f'] )) { + $clean_message['attachment'] = (strpos( $message['f'], 'a' ) !== false) ? true : false; + $clean_message['status'] = (strpos( $message['f'], 'u' ) !== false) ? 'unread' : 'read'; + ; + $clean_message['deleted'] = (strpos( $message['f'], '2' ) !== false) ? true : false; + $clean_message['flagged'] = (strpos( $message['f'], 'f' ) !== false) ? true : false; + } + + $tpl->assign( 'message', $clean_message ); + $tpl->parse( 'main.message' ); + } + $inbox = $this->getFolder( array ('l' => 2 + ) ); + + $total_messages = (int) $inbox['n']; + $unread_messages = (int) $inbox['u']; + } + + $tpl->assign( 'total_messages', $total_messages ); + $tpl->assign( 'unread_messages', $unread_messages ); + + $info = $this->getInfo( array ('sections' => 'mbox') ); + if (is_array( $info['attrs'][0]['attr_attribute_name'] )) { + $quota = $info['attrs'][0]['attr'][array_search( 'zimbraMailQuota', $info['attrs'][0]['attr_attribute_name'] )]; + $size_text = $this->makeBytesPretty( $info['used'][0], ($quota * 0.75) ) . ' out of ' . $this->makeBytesPretty( $quota ); + $tpl->assign( 'size', $size_text ); + } + /* include_once 'portal_functions.php'; $roles = getRoles($this->_username); if(in_array('faculty', $roles) || in_array('employee', $roles)) { $tpl->parse('main.away_message'); - } */ - - $tpl->parse('main'); - $tpl->out('main'); - } - + } */ + + $tpl->parse( 'main' ); + $tpl->out( 'main' ); + } + // end emailChannel - - /** - * builOptionString - * - * make an option string that will be placed as attributes inside an XML tag - * - * @since version 1.0 - * @access public - * @param array $options array of options to be parsed into a string - * @return string $options_string - */ - protected function buildOptionString($options) { - $options_string = ''; - foreach ($options as $k => $v) { - $options_string .= ' ' . $k . '="' . $v . '"'; - } - return $options_string; - } - + + + /** + * builOptionString + * + * make an option string that will be placed as attributes inside an XML tag + * + * @since version 1.0 + * @access public + * @param array $options array of options to be parsed into a string + * @return string $options_string + */ + protected function buildOptionString ($options) + { + $options_string = ''; + foreach ($options as $k => $v) { + $options_string .= ' ' . $k . '="' . $v . '"'; + } + return $options_string; + } + // end buildOptionString - - /** - * extractAuthToken - * - * get the Auth Token out of the XML - * - * @since version 1.0 - * @access public - * @param string $xml xml to have the auth token pulled from - * @return string $auth_token - */ - private function extractAuthToken($xml) { - $auth_token = strstr($xml, ""); - $auth_token = substr($auth_token, 1, strpos($auth_token, "<") - 1); - return $auth_token; - } - - /** - * extractSessionID - * - * get the Session ID out of the XML - * - * @since version 1.0 - * @access public - * @param string $xml xml to have the session id pulled from - * @return int $session_id - */ - private function extractSessionID($xml) { - + + + /** + * extractAuthToken + * + * get the Auth Token out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the auth token pulled from + * @return string $auth_token + */ + private function extractAuthToken ($xml) + { + $auth_token = strstr( $xml, "" ); + $auth_token = substr( $auth_token, 1, strpos( $auth_token, "<" ) - 1 ); + return $auth_token; + } + + /** + * extractSessionID + * + * get the Session ID out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the session id pulled from + * @return int $session_id + */ + private function extractSessionID ($xml) + { + //for testing purpose we are extracting lifetime instead of sessionid //$session_id = strstr($xml, ""); - $session_id = substr($session_id, 1, strpos($session_id, "<") - 1); - return $session_id; - } - + $session_id = strstr( $xml, "" ); + $session_id = substr( $session_id, 1, strpos( $session_id, "<" ) - 1 ); + return $session_id; + } + // end extractSessionID - - /** - * extractErrorCode - * - * get the error code out of the XML - * - * @since version 1.0 - * @access public - * @param string $xml xml to have the error code pulled from - * @return int $session_id - */ - private function extractErrorCode($xml) { - $session_id = strstr($xml, ""); - $session_id = substr($session_id, 1, strpos($session_id, "<") - 1); - return $session_id; - } - + + + /** + * extractErrorCode + * + * get the error code out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the error code pulled from + * @return int $session_id + */ + private function extractErrorCode ($xml) + { + $session_id = strstr( $xml, "" ); + $session_id = substr( $session_id, 1, strpos( $session_id, "<" ) - 1 ); + return $session_id; + } + // end extractErrorCode - - /** - * makeBytesPretty - * - * turns byte numbers into a more readable format with KB or MB - * - * @since version 1.0 - * @access public - * @param int $bytes bytes to be worked with - * @param boolean $redlevel - * @return int $size - */ - private function makeBytesPretty($bytes, $redlevel=false) { - if ($bytes < 1024) - $size = $bytes . ' B'; - elseif ($bytes < 1024 * 1024) - $size = round($bytes / 1024, 1) . ' KB'; - else - $size = round(($bytes / 1024) / 1024, 1) . ' MB'; - - if ($redlevel && $bytes > $redlevel) { - $size = '' . $size . ''; - } - - return $size; - } - + + + /** + * makeBytesPretty + * + * turns byte numbers into a more readable format with KB or MB + * + * @since version 1.0 + * @access public + * @param int $bytes bytes to be worked with + * @param boolean $redlevel + * @return int $size + */ + private function makeBytesPretty ($bytes, $redlevel = false) + { + if ($bytes < 1024) { + $size = $bytes . ' B'; + } elseif ($bytes < 1024 * 1024) { + $size = round( $bytes / 1024, 1 ) . ' KB'; + } else { + $size = round( ($bytes / 1024) / 1024, 1 ) . ' MB'; + } + if ($redlevel && $bytes > $redlevel) { + $size = '' . $size . ''; + } + + return $size; + } + // end makeBytesPretty - - /** - * message - * - * if debug is on, show a message - * - * @since version 1.0 - * @access public - * @param string $message message for debug - */ - protected function message($message) { - if ($this->debug) { - echo $message; - } - } - + + + /** + * message + * + * if debug is on, show a message + * + * @since version 1.0 + * @access public + * @param string $message message for debug + */ + protected function message ($message) + { + if ($this->debug) { + echo $message; + } + } + // end message - - /** - * soapRequest - * - * make a SOAP request to Zimbra server, returns the XML - * - * @since version 1.0 - * @access public - * @param string $body body of page - * @param boolean $header - * @param boolean $footer - * @return string $response - */ - protected function soapRequest($body, $header=false, $connecting=false) { - if (!$connecting && !$this->_connected) { - throw new Exception('zimbra.class: soapRequest called without a connection to Zimbra server'); - } - - if ($header == false) { + + + /** + * soapRequest + * + * make a SOAP request to Zimbra server, returns the XML + * + * @since version 1.0 + * @access public + * @param string $body body of page + * @param boolean $header + * @param boolean $footer + * @return string $response + */ + protected function soapRequest ($body, $header = false, $connecting = false) + { + if (! $connecting && ! $this->_connected) { + throw new Exception( 'zimbra.class: soapRequest called without a connection to Zimbra server' ); + } + + if ($header == false) { $header = ' ' . $this->auth_token . ' ' . $this->session_id . ' - '; - } - + '; + } + $soap_message = ' ' . $header . ' ' . $body . ' - '; - $this->message('SOAP message:'); - - curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $soap_message); - - if (!($response = curl_exec($this->_curl))) { - $this->error = 'ERROR: curl_exec - (' . curl_errno($this->_curl) . ') ' . curl_error($this->_curl); - return false; - } elseif (strpos($response, '') !== false) { - $error_code = $this->extractErrorCode($response); - $this->error = 'ERROR: ' . $error_code . ':'; - $this->message($this->error); - $aError = array('error' => $error_code); - return $aError; + '; + $this->message( 'SOAP message:' ); + + curl_setopt( $this->_curl, CURLOPT_POSTFIELDS, $soap_message ); + + if (! ($response = curl_exec( $this->_curl ))) { + $this->error = 'ERROR: curl_exec - (' . curl_errno( $this->_curl ) . ') ' . curl_error( $this->_curl ); + return false; + } elseif (strpos( $response, '' ) !== false) { + $error_code = $this->extractErrorCode( $response ); + $this->error = 'ERROR: ' . $error_code . ':'; + $this->message( $this->error ); + $aError = array ('error' => $error_code + ); + return $aError; //return false; - } - $this->message('SOAP response:

'); - - $this->_num_soap_calls++; - return $response; - } - + } + $this->message( 'SOAP response:

' ); + + $this->_num_soap_calls ++; + return $response; + } + // end soapRequest - - /** - * getNumSOAPCalls - * - * get the number of SOAP calls that have been made. This is for debugging and performancing - * - * @since version 1.0 - * @access public - * @return int $this->_num_soap_calls - */ - public function getNumSOAPCalls() { - return $this->_num_soap_calls; - } - + + + /** + * getNumSOAPCalls + * + * get the number of SOAP calls that have been made. This is for debugging and performancing + * + * @since version 1.0 + * @access public + * @return int $this->_num_soap_calls + */ + public function getNumSOAPCalls () + { + return $this->_num_soap_calls; + } + // end getNumSOAPCalls - - /** - * makeXMLTree - * - * turns XML into an array - * - * @since version 1.0 - * @access public - * @param string $data data to be built into an array - * @return array $ret - */ - protected function makeXMLTree($data) { + + + /** + * makeXMLTree + * + * turns XML into an array + * + * @since version 1.0 + * @access public + * @param string $data data to be built into an array + * @return array $ret + */ + protected function makeXMLTree ($data) + { // create parser - $parser = xml_parser_create(); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); - xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); - xml_parse_into_struct($parser, $data, $values, $tags); - xml_parser_free($parser); - + $parser = xml_parser_create(); + xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); + xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 ); + xml_parse_into_struct( $parser, $data, $values, $tags ); + xml_parser_free( $parser ); + // we store our path here - $hash_stack = array(); - + $hash_stack = array (); + // this is our target - $ret = array(); - foreach ($values as $key => $val) { - - switch ($val['type']) { - case 'open': - array_push($hash_stack, $val['tag']); - if (isset($val['attributes'])) - $ret = $this->composeArray($ret, $hash_stack, $val['attributes']); - else - $ret = $this->composeArray($ret, $hash_stack); - break; - - case 'close': - array_pop($hash_stack); - break; - - case 'complete': - array_push($hash_stack, $val['tag']); - $ret = $this->composeArray($ret, $hash_stack, $val['value']); - array_pop($hash_stack); - + $ret = array (); + foreach ($values as $key => $val) { + + switch ($val['type']) { + case 'open': + array_push( $hash_stack, $val['tag'] ); + if (isset( $val['attributes'] )) + $ret = $this->composeArray( $ret, $hash_stack, $val['attributes'] ); + else + $ret = $this->composeArray( $ret, $hash_stack ); + break; + + case 'close': + array_pop( $hash_stack ); + break; + + case 'complete': + array_push( $hash_stack, $val['tag'] ); + $ret = $this->composeArray( $ret, $hash_stack, $val['value'] ); + array_pop( $hash_stack ); + // handle attributes - if (isset($val['attributes'])) { - foreach ($val['attributes'] as $a_k => $a_v) { - $hash_stack[] = $val['tag'] . '_attribute_' . $a_k; - $ret = $this->composeArray($ret, $hash_stack, $a_v); - array_pop($hash_stack); - } - } - - break; - } - } - - return $ret; - } - + if (isset( $val['attributes'] )) { + foreach ($val['attributes'] as $a_k => $a_v) { + $hash_stack[] = $val['tag'] . '_attribute_' . $a_k; + $ret = $this->composeArray( $ret, $hash_stack, $a_v ); + array_pop( $hash_stack ); + } + } + + break; + } + } + + return $ret; + } + // end makeXMLTree - - /** - * &composeArray - * - * function used exclusively by makeXMLTree to help turn XML into an array - * - * @since version 1.0 - * @access public - * @param array $array - * @param array $elements - * @param array $value - * @return array $array - */ - private function &composeArray($array, $elements, $value=array()) { - global $XML_LIST_ELEMENTS; - + + + /** + * &composeArray + * + * function used exclusively by makeXMLTree to help turn XML into an array + * + * @since version 1.0 + * @access public + * @param array $array + * @param array $elements + * @param array $value + * @return array $array + */ + private function &composeArray ($array, $elements, $value = array()) + { + global $XML_LIST_ELEMENTS; + // get current element - $element = array_shift($elements); - + $element = array_shift( $elements ); + // does the current element refer to a list - if (sizeof($elements) > 0) { - $array[$element][sizeof($array[$element]) - 1] = &$this->composeArray($array[$element][sizeof($array[$element]) - 1], $elements, $value); + if (sizeof( $elements ) > 0) { + $array[$element][sizeof( $array[$element] ) - 1] = &$this->composeArray( $array[$element][sizeof( $array[$element] ) - 1], $elements, $value ); } else { // if (is_array($value)) - $array[$element][sizeof($array[$element])] = $value; - } - - return $array; - } - - // end composeArray - - /** - * noop - * - * keeps users session alive - * - * @since version 1.0 - * @access public - * @return string xml response from the noop - */ - public function noop() { - return $this->soapRequest(''); - } - - /** - * addAppointments - * - * add appointments in a calendar - * - * @since version 1.0 - * @access public - * @param - * @return - */ - public function addAppointment($serializeOp1) { - $unserializeOp1 = unserialize($serializeOp1); - - $username = $unserializeOp1['username']; - $subject = $unserializeOp1['subject']; - $appointmentName = $unserializeOp1['appointmentName']; - $friendlyName = $unserializeOp1['friendlyName']; - $userEmail = $unserializeOp1['userEmail']; - $domainName = $unserializeOp1['domainName']; - $schedule = $unserializeOp1['schedule']; - $cutype = $unserializeOp1['cutype']; - $allDay = $unserializeOp1['allDay']; - $isOrg = $unserializeOp1['isOrg']; - $rsvp = $unserializeOp1['rsvp']; - $atFriendlyName = $unserializeOp1['atFriendlyName']; - $role = $unserializeOp1['role']; - $location = $unserializeOp1['location']; - $ptst = $unserializeOp1['ptst']; - - $dateFormat=$allDay=="1"?"Ymd":"Ymd\THis"; - $startDate = date($dateFormat,strtotime($unserializeOp1['startDate'])); - $endDate = date($dateFormat,strtotime($unserializeOp1['endDate'])); - $timeZone = $allDay=="1"?"":$unserializeOp1['tz']; - - $explodeEmail = explode(';', $userEmail); - $explodeFriendlyName = explode(';', $atFriendlyName); - $countExplodeEmail = count($explodeEmail); - + $array[$element][sizeof( $array[$element] )] = $value; + } + + return $array; + } + + // end composeArray + + + /** + * noop + * + * keeps users session alive + * + * @since version 1.0 + * @access public + * @return string xml response from the noop + */ + public function noop () + { + return $this->soapRequest( '' ); + } + + /** + * addAppointments + * + * add appointments in a calendar + * + * @since version 1.0 + * @access public + * @param + * + * @return + * + */ + public function addAppointment ($serializeOp1) + { + $unserializeOp1 = unserialize( $serializeOp1 ); + + $username = $unserializeOp1['username']; + $subject = $unserializeOp1['subject']; + $appointmentName = $unserializeOp1['appointmentName']; + $friendlyName = $unserializeOp1['friendlyName']; + $userEmail = $unserializeOp1['userEmail']; + $domainName = $unserializeOp1['domainName']; + $schedule = $unserializeOp1['schedule']; + $cutype = $unserializeOp1['cutype']; + $allDay = $unserializeOp1['allDay']; + $isOrg = $unserializeOp1['isOrg']; + $rsvp = $unserializeOp1['rsvp']; + $atFriendlyName = $unserializeOp1['atFriendlyName']; + $role = $unserializeOp1['role']; + $location = $unserializeOp1['location']; + $ptst = $unserializeOp1['ptst']; + + $dateFormat = $allDay == "1" ? "Ymd" : "Ymd\THis"; + $startDate = date( $dateFormat, strtotime( $unserializeOp1['startDate'] ) ); + $endDate = date( $dateFormat, strtotime( $unserializeOp1['endDate'] ) ); + $timeZone = $allDay == "1" ? "" : $unserializeOp1['tz']; + + $explodeEmail = explode( ';', $userEmail ); + $explodeFriendlyName = explode( ';', $atFriendlyName ); + $countExplodeEmail = count( $explodeEmail ); + $soap = ' - ' . $subject . ''; - for ($i = 0; $i < $countExplodeEmail; $i++) { - $soap.= ''; - } - $soap.=' + ' . $subject . ''; + for ($i = 0; $i < $countExplodeEmail; $i ++) { + $soap .= ''; + } + $soap .= ' - '; - for ($i = 0; $i < $countExplodeEmail; $i++) { - $soap.=''; - } - $soap.= ' + '; + for ($i = 0; $i < $countExplodeEmail; $i ++) { + $soap .= ''; + } + $soap .= ' @@ -1016,46 +1073,47 @@ class Zimbra { - '; -//G::pr($soap);die; - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - - return $array['soap:Envelope'][0]['soap:Body'][0]['CreateAppointmentResponse']; - } else { - return false; - } - } - + '; + //G::pr($soap);die; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateAppointmentResponse']; + } else { + return false; + } + } + // end addAppointments - - /** - * addTask - * - * add Task in a Task Tab - * - * @since version 1.0 - * @access public - * @param array $options array of options to apply to retrieval from calendar - * @return array associative array of appointments - */ - public function addTask($serializeOp1) { - $unserializeOp1 = unserialize($serializeOp1); - - $subject = $unserializeOp1['subject']; - $taskName = $unserializeOp1['taskName']; - $friendlyName = $unserializeOp1['friendlyName']; - $userEmail = $unserializeOp1['userEmail']; - $priority = $unserializeOp1['priority']; - $allDay = $unserializeOp1['allDay']; - $class = $unserializeOp1['class']; - $location = $unserializeOp1['location']; - $dueDate = date("Ymd",strtotime($unserializeOp1['dueDate'])); - $status = $unserializeOp1['status']; - $percent = $unserializeOp1['percent']; - - + + + /** + * addTask + * + * add Task in a Task Tab + * + * @since version 1.0 + * @access public + * @param array $options array of options to apply to retrieval from calendar + * @return array associative array of appointments + */ + public function addTask ($serializeOp1) + { + $unserializeOp1 = unserialize( $serializeOp1 ); + + $subject = $unserializeOp1['subject']; + $taskName = $unserializeOp1['taskName']; + $friendlyName = $unserializeOp1['friendlyName']; + $userEmail = $unserializeOp1['userEmail']; + $priority = $unserializeOp1['priority']; + $allDay = $unserializeOp1['allDay']; + $class = $unserializeOp1['class']; + $location = $unserializeOp1['location']; + $dueDate = date( "Ymd", strtotime( $unserializeOp1['dueDate'] ) ); + $status = $unserializeOp1['status']; + $percent = $unserializeOp1['percent']; + $soap = ' ' . $subject . ' @@ -1077,40 +1135,44 @@ class Zimbra { - '; - $response = $this->soapRequest($soap); - - if ($response) { - $array = $this->makeXMLTree($response); - + '; + $response = $this->soapRequest( $soap ); + + if ($response) { + $array = $this->makeXMLTree( $response ); + //return $array['soap:Envelope'][0]['soap:Body'][0]['BatchResponse'][0]['CreateTaskRequest'][0]['appt']; - return $array['soap:Envelope'][0]['soap:Body'][0]['CreateTaskResponse']; - } else { - return false; - } - } - + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateTaskResponse']; + } else { + return false; + } + } + // end addTask - - /** - * addContacts - * - * add contact in a AddressBook - * - * @since version 1.0 - * @access public - * @param - * @return - */ - public function addContacts($serializeOp1) { - $unserializeOp1 = unserialize($serializeOp1); - - $firstName = $unserializeOp1['firstName']; - $lastName = $unserializeOp1['lastName']; - $email = $unserializeOp1['email']; - $otherData = $unserializeOp1['otherData']; - $otherDataValue = $unserializeOp1['otherDataValue']; - + + + /** + * addContacts + * + * add contact in a AddressBook + * + * @since version 1.0 + * @access public + * @param + * + * @return + * + */ + public function addContacts ($serializeOp1) + { + $unserializeOp1 = unserialize( $serializeOp1 ); + + $firstName = $unserializeOp1['firstName']; + $lastName = $unserializeOp1['lastName']; + $email = $unserializeOp1['email']; + $otherData = $unserializeOp1['otherData']; + $otherDataValue = $unserializeOp1['otherDataValue']; + $soap = ' ' . $firstName . ' @@ -1118,179 +1180,192 @@ class Zimbra { ' . $email . ' ' . $otherDataValue . ' - '; - - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - - return $array['soap:Envelope'][0]['soap:Body'][0]['CreateContactResponse']; - } else { - return false; - } - } - + '; + + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateContactResponse']; + } else { + return false; + } + } + // end addContacts - /** - * addFolder - * - * add Folder in a BriefCase - * - * @since version 1.0 - * @access public - * @param - * @return - */ - - public function addFolder($serializeOp1) { - $unserializeOp1 = unserialize($serializeOp1); - - $folderName = $unserializeOp1['folderName']; - $folderColor = $unserializeOp1['color']; - + /** + * addFolder + * + * add Folder in a BriefCase + * + * @since version 1.0 + * @access public + * @param + * + * @return + * + */ + + public function addFolder ($serializeOp1) + { + $unserializeOp1 = unserialize( $serializeOp1 ); + + $folderName = $unserializeOp1['folderName']; + $folderColor = $unserializeOp1['color']; + $soap = ' - '; - - $response = $this->soapRequest($soap); - if ($response) { - $array = $this->makeXMLTree($response); - - return $array['soap:Envelope'][0]['soap:Body'][0]['CreateFolderResponse']; - } else { - return false; - } - } - + '; + + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateFolderResponse']; + } else { + return false; + } + } + // end addFolder - /** - * uploadDocument - * - * add Folder in a BriefCase - * - * @since version 1.0 - * @access public - * @param - * @return - */ - - public function upload($folderId, $UploadId, $fileVersion='', $docId='') { - if ($fileVersion == '' && $docId == '') { + /** + * uploadDocument + * + * add Folder in a BriefCase + * + * @since version 1.0 + * @access public + * @param + * + * @return + * + */ + + public function upload ($folderId, $UploadId, $fileVersion = '', $docId = '') + { + if ($fileVersion == '' && $docId == '') { $soap = ' - '; - } else { + '; + } else { $soap = ' - '; - } - - $response = $this->soapRequest($soap); - if (is_array($response)) { - if (isset($response['error'])) { - return $response; - } - } else { - $array = $this->makeXMLTree($response); - - return $array['soap:Envelope'][0]['soap:Body'][0]['SaveDocumentResponse']; - } - } - + '; + } + + $response = $this->soapRequest( $soap ); + if (is_array( $response )) { + if (isset( $response['error'] )) { + return $response; + } + } else { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['SaveDocumentResponse']; + } + } + // end uploadDocument - - /** - * getDocId - * - * Get ID of File in Zimbra. - * - * @since version 1.0 - * @access public - * @param - * @return - */ - public function getDocId($folderId, $fileName) { + + + /** + * getDocId + * + * Get ID of File in Zimbra. + * + * @since version 1.0 + * @access public + * @param + * + * @return + * + */ + public function getDocId ($folderId, $fileName) + { $soap = ' - '; - - $response = $this->soapRequest($soap); - if (is_array($response)) { - if ($response['error']) { - return false; - } - } else { - $array = $this->makeXMLTree($response); - - return $array['soap:Envelope'][0]['soap:Body'][0]['GetItemResponse'][0]; - } - } - + '; + + $response = $this->soapRequest( $soap ); + if (is_array( $response )) { + if ($response['error']) { + return false; + } + } else { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['GetItemResponse'][0]; + } + } + // end getDocId -} - +} + // end Zimbra class // annoying sorting functions for getTasks... // I don't know how to make usort calls to internal OO functions // if someone knows how, please fix this :) - -/** - * zimbra_startSort - * - * sort of zimbra elements - * - * @since version 1.0 - * @access public - * @param array $task_a - * @param array $task_b - * @return int (($task_a['dueDate']-$task_a['dur']) < ($task_b['dueDate']-$task_b['dur'])) ? -1 : 1 - */ -function zimbra_startSort($task_a, $task_b) { - if (($task_a['dueDate'] - $task_a['dur']) == ($task_b['dueDate'] - $task_b['dur'])) { - return ($task_a['name'] < $task_b['name']) ? -1 : 1; - } - return (($task_a['dueDate'] - $task_a['dur']) < ($task_b['dueDate'] - $task_b['dur'])) ? -1 : 1; -} - -/** - * zimbra_dueSort - * - * sort by dueDate - * - * @since version 1.0 - * @access public - * @param array $task_a - * @param array $task_b - * @return int ($task_a['dueDate'] < $task_b['dueDate']) ? -1 : 1 - */ -function zimbra_dueSort($task_a, $task_b) { - if ($task_a['dueDate'] == $task_b['dueDate']) { - return ($task_a['name'] < $task_b['name']) ? -1 : 1; - } - return ($task_a['dueDate'] < $task_b['dueDate']) ? -1 : 1; -} - -/** - * zimbra_nameSort - * - * sort by name - * - * @since version 1.0 - * @access public - * @param array $task_a - * @param array $task_b - * @return int ($task_a['name'] < $task_b['name']) ? -1 : 1 - */ -function zimbra_nameSort($task_a, $task_b) { - if ($task_a['name'] == $task_b['name']) { - return 0; - } - return ($task_a['name'] < $task_b['name']) ? -1 : 1; -} - -?> \ No newline at end of file + + +/** + * zimbra_startSort + * + * sort of zimbra elements + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int (($task_a['dueDate']-$task_a['dur']) < ($task_b['dueDate']-$task_b['dur'])) ? -1 : 1 + */ +function zimbra_startSort ($task_a, $task_b) +{ + if (($task_a['dueDate'] - $task_a['dur']) == ($task_b['dueDate'] - $task_b['dur'])) { + return ($task_a['name'] < $task_b['name']) ? - 1 : 1; + } + return (($task_a['dueDate'] - $task_a['dur']) < ($task_b['dueDate'] - $task_b['dur'])) ? - 1 : 1; +} + +/** + * zimbra_dueSort + * + * sort by dueDate + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int ($task_a['dueDate'] < $task_b['dueDate']) ? -1 : 1 + */ +function zimbra_dueSort ($task_a, $task_b) +{ + if ($task_a['dueDate'] == $task_b['dueDate']) { + return ($task_a['name'] < $task_b['name']) ? - 1 : 1; + } + return ($task_a['dueDate'] < $task_b['dueDate']) ? - 1 : 1; +} + +/** + * zimbra_nameSort + * + * sort by name + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int ($task_a['name'] < $task_b['name']) ? -1 : 1 + */ +function zimbra_nameSort ($task_a, $task_b) +{ + if ($task_a['name'] == $task_b['name']) { + return 0; + } + return ($task_a['name'] < $task_b['name']) ? - 1 : 1; +} +