00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 include_once( "kernel/classes/ezworkflow.php" );
00038 include_once( "kernel/common/i18n.php" );
00039 include_once( "lib/ezutils/classes/ezdebug.php" );
00040
00041 define( "EZ_WORKFLOW_TYPE_STATUS_NONE", 0 );
00042 define( "EZ_WORKFLOW_TYPE_STATUS_ACCEPTED", 1 );
00043 define( "EZ_WORKFLOW_TYPE_STATUS_REJECTED", 2 );
00044 define( "EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON", 3 );
00045 define( "EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT", 4 );
00046 define( "EZ_WORKFLOW_TYPE_STATUS_RUN_SUB_EVENT", 5 );
00047 define( "EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED", 6 );
00048 define( "EZ_WORKFLOW_TYPE_STATUS_FETCH_TEMPLATE", 7 );
00049 define( "EZ_WORKFLOW_TYPE_STATUS_FETCH_TEMPLATE_REPEAT", 8 );
00050 define( "EZ_WORKFLOW_TYPE_STATUS_REDIRECT", 10 );
00051 define( "EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_DONE", 9 );
00052 define( "EZ_WORKFLOW_TYPE_STATUS_REDIRECT_REPEAT", 11 );
00053 define( "EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_RESET", 12 );
00054
00055 class eZWorkflowType
00056 {
00057 function eZWorkflowType( $group, $type,
00058 $groupName, $name )
00059 {
00060 $this->Group = $group;
00061 $this->Type = $type;
00062 $this->TypeString = $group . "_" . $type;
00063 $this->GroupName = $groupName;
00064 $this->Name = $name;
00065 $this->Information = "";
00066 $this->ActivationDate = false;
00067 $this->Attributes = array();
00068 $this->Attributes["group"] =& $this->Group;
00069 $this->Attributes["type"] =& $this->Type;
00070 $this->Attributes["type_string"] =& $this->TypeString;
00071 $this->Attributes["group_name"] =& $this->GroupName;
00072 $this->Attributes["name"] =& $this->Name;
00073 $this->Attributes["information"] =& $this->Information;
00074 $this->Attributes["activation_date"] =& $this->ActivationDate;
00075 }
00076
00077 function statusName( $status )
00078 {
00079 include_once( 'kernel/workflow/ezworkflowfunctioncollection.php' );
00080 $statusNames = eZWorkflowFunctionCollection::fetchWorkflowTypeStatuses();
00081 if ( isset( $statusNames[$status] ) )
00082 return $statusNames[$status];
00083 return false;
00084 }
00085
00086 function &createType( $typeString )
00087 {
00088 $types =& $GLOBALS["eZWorkflowTypes"];
00089 $def = null;
00090 if ( !isset( $types[$typeString] ) )
00091 {
00092 $result = eZWorkflowType::loadAndRegisterType( $typeString );
00093 if ( $result === false )
00094 return $def;
00095 }
00096
00097 if ( isset( $types[$typeString] ) )
00098 {
00099 $type_def =& $types[$typeString];
00100 $class_name = $type_def["class_name"];
00101
00102 $def =& $GLOBALS["eZWorkflowTypeObjects"][$typeString];
00103 if ( get_class( $def ) != $class_name )
00104 {
00105 if ( class_exists( $class_name ) )
00106 $def = new $class_name();
00107 else
00108 eZDebug::writeError( "Undefined event type class: $class_name", "eZWorkflowType::createType" );
00109 }
00110 }
00111 else
00112 eZDebug::writeError( "Undefined type: $typeString", "eZWorkflowType::createType" );
00113 return $def;
00114 }
00115
00116 function &fetchRegisteredTypes()
00117 {
00118 eZWorkflowType::loadAndRegisterAllTypes();
00119 $definition_objects =& $GLOBALS["eZWorkflowTypeObjects"];
00120 $types =& $GLOBALS["eZWorkflowTypes"];
00121 if ( is_array( $types ) )
00122 {
00123 foreach ( $types as $typeString => $type_def )
00124 {
00125 $class_name = $type_def["class_name"];
00126 $def =& $definition_objects[$typeString];
00127 if ( get_class( $def ) != $class_name )
00128 {
00129 if ( class_exists( $class_name ) )
00130 $def = new $class_name();
00131 else
00132 eZDebug::writeError( "Undefined event type class: $class_name", "eZWorkflowType::fetchRegisteredTypes" );
00133 }
00134 }
00135 }
00136 return $definition_objects;
00137 }
00138
00139 function allowedTypes()
00140 {
00141 $allowedTypes =& $GLOBALS["eZWorkflowAllowedTypes"];
00142 if ( !is_array( $allowedTypes ) )
00143 {
00144 $wfINI =& eZINI::instance( 'workflow.ini' );
00145 $eventTypes = $wfINI->variable( "EventSettings", "AvailableEventTypes" );
00146
00147
00148 $allowedTypes = array_unique( $eventTypes );
00149 }
00150 return $allowedTypes;
00151 }
00152
00153 function loadAndRegisterAllTypes()
00154 {
00155 $allowedTypes = eZWorkflowType::allowedTypes();
00156 foreach( $allowedTypes as $type )
00157 {
00158 eZWorkflowType::loadAndRegisterType( $type );
00159 }
00160 }
00161
00162 function registerType( $group, $type, $class_name )
00163 {
00164 $typeString = $group . "_" . $type;
00165 $types =& $GLOBALS["eZWorkflowTypes"];
00166 if ( !is_array( $types ) )
00167 $types = array();
00168 if ( isset( $types[$typeString] ) )
00169 {
00170 eZDebug::writeError( "Type already registered: $typeString", "eZWorkflowType::registerType" );
00171 }
00172 else
00173 {
00174 $types[$typeString] = array( "class_name" => $class_name );
00175 }
00176 }
00177
00178 function loadAndRegisterType( $typeString )
00179 {
00180 $typeElements = explode( "_", $typeString );
00181 if ( count( $typeElements ) < 2 )
00182 {
00183 eZDebug::writeError( "Workflow type not found: $typeString", "eZWorkflowType::loadAndRegisterType" );
00184 return false;
00185 }
00186
00187 $types =& $GLOBALS["eZWorkflowTypes"];
00188 if ( isset( $types[ $typeString ] ) and
00189 isset( $types[ $typeString ][ 'class_name' ] ) and
00190 class_exists( $types[ $typeString ][ 'class_name' ] ) )
00191 {
00192 return true;
00193 }
00194
00195 $group = $typeElements[0];
00196 $type = $typeElements[1];
00197
00198 include_once( 'lib/ezutils/classes/ezextension.php' );
00199 $baseDirectory = eZExtension::baseDirectory();
00200 $wfINI =& eZINI::instance( 'workflow.ini' );
00201 $repositoryDirectories = $wfINI->variable( 'EventSettings', 'RepositoryDirectories' );
00202 $extensionDirectories = $wfINI->variable( 'EventSettings', 'ExtensionDirectories' );
00203 foreach ( $extensionDirectories as $extensionDirectory )
00204 {
00205 $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/eventtypes';
00206 if ( file_exists( $extensionPath ) )
00207 $repositoryDirectories[] = $extensionPath;
00208 }
00209
00210 foreach ( $repositoryDirectories as $repositoryDirectory )
00211 {
00212 $includeFile = "$repositoryDirectory/$group/$type/" . $type . "type.php";
00213 if ( file_exists( $includeFile ) )
00214 {
00215 include_once( $includeFile );
00216 return true;
00217 }
00218 }
00219
00220 eZDebug::writeError( "Workflow type not found: $typeString, searched in these directories: " . implode( ', ', $repositoryDirectories ), "eZWorkflowType::loadAndRegisterType" );
00221 return false;
00222 }
00223
00224
00225 function attributes()
00226 {
00227 return array_merge( array( 'description',
00228 'allowed_triggers' ),
00229 array_keys( $this->Attributes ) );
00230 }
00231
00232 function hasAttribute( $attr )
00233 {
00234 return in_array( $attr, $this->attributes() );
00235 }
00236
00237 function &attribute( $attr )
00238 {
00239 switch( $attr )
00240 {
00241 case 'description':
00242 {
00243 return $this->eventDescription();
00244 } break;
00245
00246 case 'allowed_triggers':
00247 {
00248 return $this->TriggerTypes;
00249 } break;
00250
00251 default:
00252 {
00253 if ( isset( $this->Attributes[$attr] ) )
00254 return $this->Attributes[$attr];
00255 } break;
00256 }
00257 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZWorkflowType::attribute' );
00258 $retValue = null;
00259 return $retValue;
00260 }
00261
00262 function setAttribute( $attr, $value )
00263 {
00264 if ( array_key_exists( $attr, $this->Attributes ) )
00265 $this->Attributes[$attr] = $value;
00266 }
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 function setTriggerTypes( $allowedTypes )
00277 {
00278 $this->TriggerTypes = $allowedTypes;
00279 }
00280
00281 function &eventDescription()
00282 {
00283 return $this->Attributes["name"];
00284 }
00285
00286 function execute( &$process, &$event )
00287 {
00288 return EZ_WORKFLOW_TYPE_STATUS_NONE;
00289 }
00290
00291 function initializeEvent( &$event )
00292 {
00293 }
00294
00295 function validateHTTPInput( &$http, $base, &$event, &$validation )
00296 {
00297 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00298 }
00299
00300 function fixupHTTPInput( &$http, $base, &$event )
00301 {
00302 return true;
00303 }
00304
00305 function fetchHTTPInput( &$http, $base, &$event )
00306 {
00307 }
00308
00309 function setActivationDate( $date )
00310 {
00311 $this->ActivationDate = $date;
00312 }
00313
00314 function setInformation( $inf )
00315 {
00316 $this->Information = $inf;
00317 }
00318
00319 function needCleanup()
00320 {
00321 return false;
00322 }
00323
00324 function cleanupAfterRemoving( $attr = array() )
00325 {
00326 }
00327
00328 function cleanup( &$process, &$event )
00329 {
00330 }
00331
00332 function &attributeDecoder( &$event, $attr )
00333 {
00334 $retValue = null;
00335 return $retValue;
00336 }
00337
00338 function typeFunctionalAttributes( )
00339 {
00340 return array();
00341 }
00342
00343 function customWorkflowEventHTTPAction( &$http, $action, &$workflowEvent )
00344 {
00345 }
00346
00347 function &workflowEventContent()
00348 {
00349 $retValue = "";
00350 return $retValue;
00351 }
00352 function storeEventData( &$event, $version )
00353 {
00354 }
00355 function storeDefinedEventData( $event )
00356 {
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 function isAllowed( $moduleName, $functionName, $connectType )
00368 {
00369 if ( isset( $this->TriggerTypes['*'] ) )
00370 {
00371 return true;
00372 }
00373 else if ( isset( $this->TriggerTypes[$moduleName] ) )
00374 {
00375 if ( isset( $this->TriggerTypes[$moduleName][$functionName] ) )
00376 {
00377 if ( in_array( $connectType, $this->TriggerTypes[$moduleName][$functionName] ) )
00378 {
00379 return true;
00380 }
00381 }
00382 }
00383
00384 return false;
00385 }
00386
00387
00388 var $Group;
00389 var $Type;
00390 var $TypeString;
00391 var $GroupName;
00392 var $Name;
00393 var $ActivationDate;
00394 var $Information;
00395 var $TriggerTypes = array( '*' => true );
00396 }
00397
00398 class eZWorkflowEventType extends eZWorkflowType
00399 {
00400 function eZWorkflowEventType( $typeString, $name )
00401 {
00402 $this->eZWorkflowType( "event", $typeString, ezi18n( 'kernel/workflow/event', "Event" ), $name );
00403 }
00404
00405 function registerType( $typeString, $class_name )
00406 {
00407 eZWorkflowType::registerType( "event", $typeString, $class_name );
00408 }
00409 }
00410
00411 class eZWorkflowGroupType extends eZWorkflowType
00412 {
00413 function eZWorkflowGroupType( $typeString, $name )
00414 {
00415 $this->eZWorkflowType( "group", $typeString, ezi18n( 'kernel/workflow/group', "Group" ), $name );
00416 }
00417
00418 function registerType( $typeString, $class_name )
00419 {
00420 eZWorkflowType::registerType( "group", $typeString, $class_name );
00421 }
00422 }
00423
00424 ?>