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
00038
00039
00040
00041
00042
00043 include_once( "kernel/classes/ezworkflowtype.php" );
00044 include_once( 'kernel/classes/collaborationhandlers/ezapprove/ezapprovecollaborationhandler.php' );
00045
00046 define( "EZ_WORKFLOW_TYPE_APPROVE_ID", "ezapprove" );
00047
00048 define( "EZ_APPROVE_COLLABORATION_NOT_CREATED", 0 );
00049 define( "EZ_APPROVE_COLLABORATION_CREATED", 1 );
00050
00051 define( 'EZ_APPROVE_VERSION_OPTION_FIRST_ONLY', 1 );
00052 define( 'EZ_APPROVE_VERSION_OPTION_EXCEPT_FIRST', 2 );
00053 define( 'EZ_APPROVE_VERSION_OPTION_ALL', EZ_APPROVE_VERSION_OPTION_FIRST_ONLY | EZ_APPROVE_VERSION_OPTION_EXCEPT_FIRST );
00054
00055 class eZApproveType extends eZWorkflowEventType
00056 {
00057 function eZApproveType()
00058 {
00059 $this->eZWorkflowEventType( EZ_WORKFLOW_TYPE_APPROVE_ID, ezi18n( 'kernel/workflow/event', "Approve" ) );
00060 $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'before' ) ) ) );
00061 }
00062
00063 function &attributeDecoder( &$event, $attr )
00064 {
00065 switch ( $attr )
00066 {
00067 case 'selected_sections':
00068 {
00069 $attributeValue = trim( $event->attribute( 'data_text1' ) );
00070 $returnValue = empty( $attributeValue ) ? array( -1 ) : explode( ',', $attributeValue );
00071 }break;
00072
00073 case 'approve_users':
00074 {
00075 $attributeValue = trim( $event->attribute( 'data_text3' ) );
00076 $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue );
00077 }break;
00078
00079 case 'approve_groups':
00080 {
00081 $attributeValue = trim( $event->attribute( 'data_text4' ) );
00082 $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue );
00083 }break;
00084
00085 case 'selected_usergroups':
00086 {
00087 $attributeValue = trim( $event->attribute( 'data_text2' ) );
00088 $returnValue = empty( $attributeValue ) ? array() : explode( ',', $attributeValue );
00089 }break;
00090
00091 case 'language_list':
00092 {
00093 $returnValue = array();
00094 $attributeValue = $event->attribute( 'data_int2' );
00095 if ( $attributeValue != 0 )
00096 {
00097 include_once( 'kernel/classes/ezcontentlanguage.php' );
00098 $languages = eZContentLanguage::languagesByMask( $attributeValue );
00099 foreach ( $languages as $language )
00100 {
00101 $returnValue[$language->attribute( 'id' )] = $language->attribute( 'name' );
00102 }
00103 }
00104 }break;
00105
00106 case 'version_option':
00107 {
00108 $returnValue = EZ_APPROVE_VERSION_OPTION_ALL & $event->attribute( 'data_int3' );
00109 }break;
00110
00111 default:
00112 $returnValue = null;
00113 }
00114 return $returnValue;
00115 }
00116
00117 function typeFunctionalAttributes( )
00118 {
00119 return array( 'selected_sections',
00120 'approve_users',
00121 'approve_groups',
00122 'selected_usergroups',
00123 'language_list',
00124 'version_option' );
00125 }
00126
00127 function attributes()
00128 {
00129 return array_merge( array( 'sections',
00130 'languages',
00131 'users',
00132 'usergroups' ),
00133 eZWorkflowEventType::attributes() );
00134
00135 }
00136
00137 function hasAttribute( $attr )
00138 {
00139 return in_array( $attr, $this->attributes() );
00140 }
00141
00142 function &attribute( $attr )
00143 {
00144 switch( $attr )
00145 {
00146 case 'sections':
00147 {
00148 include_once( 'kernel/classes/ezsection.php' );
00149 $sections = eZSection::fetchList( false );
00150 foreach ( array_keys( $sections ) as $key )
00151 {
00152 $section =& $sections[$key];
00153 $section['Name'] = $section['name'];
00154 $section['value'] = $section['id'];
00155 }
00156 return $sections;
00157 }break;
00158 case 'languages':
00159 {
00160 include_once( 'kernel/classes/ezcontentlanguage.php' );
00161 $languages = eZContentLanguage::fetchList();
00162 return $languages;
00163 }break;
00164 }
00165 $eventValue =& eZWorkflowEventType::attribute( $attr );
00166 return $eventValue;
00167 }
00168
00169 function execute( &$process, &$event )
00170 {
00171 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $process, 'eZApproveType::execute' );
00172 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'eZApproveType::execute' );
00173 $parameters = $process->attribute( 'parameter_list' );
00174 $versionID = $parameters['version'];
00175 $objectID = $parameters['object_id'];
00176 $object = eZContentObject::fetch( $objectID );
00177
00178 if ( !$object )
00179 {
00180 eZDebugSetting::writeError( 'kernel-workflow-approve', "No object with ID $objectID", 'eZApproveType::execute' );
00181 return EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED;
00182 }
00183
00184 $version = $object->version( $versionID );
00185
00186 if ( !$version )
00187 {
00188 eZDebugSetting::writeError( 'kernel-workflow-approve', "No version $versionID for object with ID $objectID", 'eZApproveType::execute' );
00189 return EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED;
00190 }
00191
00192
00193 $version_option = $event->attribute( 'version_option' );
00194 if ( ( $version_option == EZ_APPROVE_VERSION_OPTION_FIRST_ONLY and $parameters['version'] > 1 ) or
00195 ( $version_option == EZ_APPROVE_VERSION_OPTION_EXCEPT_FIRST and $parameters['version'] == 1 ) )
00196 {
00197 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00198 }
00199
00200
00201
00202
00203
00204
00205 if ( $process->attribute( 'user_id' ) == 0 )
00206 {
00207 $user =& eZUser::currentUser();
00208 $process->setAttribute( 'user_id', $user->id() );
00209 }
00210 else
00211 {
00212 $user =& eZUser::instance( $process->attribute( 'user_id' ) );
00213 }
00214
00215 $userGroups = array_merge( $user->attribute( 'groups' ), $user->attribute( 'contentobject_id' ) );
00216 $workflowSections = explode( ',', $event->attribute( 'data_text1' ) );
00217 $workflowGroups = explode( ',', $event->attribute( 'data_text2' ) );
00218 $editors = explode( ',', $event->attribute( 'data_text3' ) );
00219 $approveGroups = explode( ',', $event->attribute( 'data_text4' ) );
00220 $languageMask = $event->attribute( 'data_int2' );
00221
00222 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $user, 'eZApproveType::execute::user' );
00223 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $userGroups, 'eZApproveType::execute::userGroups' );
00224 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $editors, 'eZApproveType::execute::editor' );
00225 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowSections, 'eZApproveType::execute::workflowSections' );
00226 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowGroups, 'eZApproveType::execute::workflowGroups' );
00227 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $languageMask, 'eZApproveType::execute::languageMask' );
00228 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $object->attribute( 'section_id'), 'eZApproveType::execute::section_id' );
00229
00230 $section = $object->attribute( 'section_id' );
00231 $correctSection = false;
00232
00233 if ( !in_array( $section, $workflowSections ) && !in_array( -1, $workflowSections ) )
00234 {
00235 $assignedNodes = $object->attribute( 'assigned_nodes' );
00236 if ( $assignedNodes )
00237 {
00238 foreach( $assignedNodes as $assignedNode )
00239 {
00240 $parent =& $assignedNode->attribute( 'parent' );
00241 $parentObject =& $parent->object();
00242 $section = $parentObject->attribute( 'section_id');
00243
00244 if ( in_array( $section, $workflowSections ) )
00245 {
00246 $correctSection = true;
00247 break;
00248 }
00249 }
00250 }
00251 }
00252 else
00253 $correctSection = true;
00254
00255 $inExcludeGroups = count( array_intersect( $userGroups, $workflowGroups ) ) != 0;
00256
00257 $userIsEditor = ( in_array( $user->id(), $editors ) ||
00258 count( array_intersect( $userGroups, $approveGroups ) ) != 0 );
00259
00260
00261 $hasLanguageMatch = true;
00262 if ( $languageMask != 0 )
00263 {
00264
00265
00266
00267 $languageID = (int)$version->attribute( 'initial_language_id' );
00268 $hasLanguageMatch = (bool)( $languageMask & $languageID );
00269 }
00270
00271 if ( $hasLanguageMatch and
00272 !$userIsEditor and
00273 !$inExcludeGroups and
00274 $correctSection )
00275 {
00276
00277
00278 $ini =& eZINI::instance();
00279 $userClassIDArray = array( $ini->variable( 'UserSettings', 'UserClassID' ) );
00280 $approveUserIDArray = array();
00281 foreach( $approveGroups as $approveUserGroupID )
00282 {
00283 if ( $approveUserGroupID != false )
00284 {
00285 $approveUserGroup =& eZContentObject::fetch( $approveUserGroupID );
00286 if ( isset( $approveUserGroup ) )
00287 foreach( $approveUserGroup->attribute( 'assigned_nodes' ) as $assignedNode )
00288 {
00289 $userNodeArray =& $assignedNode->subTree( array( 'ClassFilterType' => 'include',
00290 'ClassFilterArray' => $userClassIDArray,
00291 'Limitation' => array() ) );
00292 foreach( $userNodeArray as $userNode )
00293 {
00294 $approveUserIDArray[] = $userNode->attribute( 'contentobject_id' );
00295 }
00296 }
00297 }
00298 }
00299 $approveUserIDArray = array_merge( $approveUserIDArray, $editors );
00300 $approveUserIDArray = array_unique( $approveUserIDArray );
00301
00302 $collaborationID = false;
00303 $db = & eZDb::instance();
00304 $taskResult = $db->arrayQuery( 'select workflow_process_id, collaboration_id from ezapprove_items where workflow_process_id = ' . $process->attribute( 'id' ) );
00305 if ( count( $taskResult ) > 0 )
00306 $collaborationID = $taskResult[0]['collaboration_id'];
00307
00308 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $collaborationID, 'approve collaborationID' );
00309 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $process->attribute( 'event_state'), 'approve $process->attribute( \'event_state\')' );
00310 if ( $collaborationID === false )
00311 {
00312 $this->createApproveCollaboration( $process, $event, $user->id(), $object->attribute( 'id' ), $versionID, $approveUserIDArray );
00313 $this->setInformation( "We are going to create approval" );
00314 $process->setAttribute( 'event_state', EZ_APPROVE_COLLABORATION_CREATED );
00315 $process->store();
00316 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $this, 'approve execute' );
00317 return EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT;
00318 }
00319 else if ( $process->attribute( 'event_state') == EZ_APPROVE_COLLABORATION_NOT_CREATED )
00320 {
00321 eZApproveCollaborationHandler::activateApproval( $collaborationID );
00322 $process->setAttribute( 'event_state', EZ_APPROVE_COLLABORATION_CREATED );
00323 $process->store();
00324 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $this, 'approve re-execute' );
00325 return EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT;
00326 }
00327 else
00328 {
00329 $this->setInformation( "we are checking approval now" );
00330 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'check approval' );
00331 return $this->checkApproveCollaboration( $process, $event );
00332 }
00333 }
00334 else
00335 {
00336 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowSections , "we are not going to create approval " . $object->attribute( 'section_id') );
00337 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $userGroups, "we are not going to create approval" );
00338 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $workflowGroups, "we are not going to create approval" );
00339 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $user->id(), "we are not going to create approval " );
00340 return EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00341 }
00342 }
00343
00344 function initializeEvent( &$event )
00345 {
00346 }
00347
00348 function validateUserIDList( $userIDList, &$reason )
00349 {
00350 $returnState = EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00351 foreach ( $userIDList as $userID )
00352 {
00353 if ( !is_numeric( $userID ) or
00354 !eZUser::isUserObject( eZContentObject::fetch( $userID ) ) )
00355 {
00356 $returnState = EZ_INPUT_VALIDATOR_STATE_INVALID;
00357 $reason[ 'list' ][] = $userID;
00358 }
00359 }
00360 $reason[ 'text' ] = "Some of passed user IDs are not valid, must be IDs of existing users only.";
00361 return $returnState;
00362 }
00363
00364 function validateGroupIDList( $userGroupIDList, &$reason )
00365 {
00366 $returnState = EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00367 $groupClassNames = eZUser::fetchUserGroupClassNames();
00368 if ( count( $groupClassNames ) > 0 )
00369 {
00370 foreach( $userGroupIDList as $userGroupID )
00371 {
00372 if ( !is_numeric( $userGroupID ) or
00373 !is_object( $userGroup =& eZContentObject::fetch( $userGroupID ) ) or
00374 !in_array( $userGroup->attribute( 'class_identifier' ), $groupClassNames ) )
00375 {
00376 $returnState = EZ_INPUT_VALIDATOR_STATE_INVALID;
00377 $reason[ 'list' ][] = $userGroupID;
00378 }
00379 }
00380 $reason[ 'text' ] = "Some of passed user-group IDs are not valid, must be IDs of existing user groups only.";
00381 }
00382 else
00383 {
00384 $returnState = EZ_INPUT_VALIDATOR_STATE_INVALID;
00385 $reason[ 'text' ] = "There is no one user-group classes among the user accounts, please choose standalone users.";
00386 }
00387 return $returnState;
00388 }
00389
00390 function validateHTTPInput( &$http, $base, &$workflowEvent, &$validation )
00391 {
00392 $returnState = EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00393 $reason = array();
00394
00395 if ( !$http->hasSessionVariable( 'BrowseParameters' ) )
00396 {
00397
00398 $approversIDs = array_unique( $this->attributeDecoder( $workflowEvent, 'approve_users' ) );
00399 if ( is_array( $approversIDs ) and
00400 count( $approversIDs ) > 0 )
00401 {
00402 $returnState = eZApproveType::validateUserIDList( $approversIDs, $reason );
00403 }
00404 else
00405 $returnState = false;
00406
00407 if ( $returnState != EZ_INPUT_VALIDATOR_STATE_INVALID )
00408 {
00409
00410 $userGroupIDList = array_unique( $this->attributeDecoder( $workflowEvent, 'approve_groups' ) );
00411 if ( is_array( $userGroupIDList ) and
00412 count( $userGroupIDList ) > 0 )
00413 {
00414 $returnState = eZApproveType::validateGroupIDList( $userGroupIDList, $reason );
00415 }
00416 else if ( $returnState === false )
00417 {
00418
00419 $returnState = EZ_INPUT_VALIDATOR_STATE_INVALID;
00420 $reason[ 'text' ] = "There must be passed at least one valid user or user group who approves content for the event.";
00421 }
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433 if ( $returnState != EZ_INPUT_VALIDATOR_STATE_INVALID )
00434 {
00435 $userGroupIDList = array_unique( $this->attributeDecoder( $workflowEvent, 'selected_usergroups' ) );
00436 if ( is_array( $userGroupIDList ) and
00437 count( $userGroupIDList ) > 0 )
00438 {
00439 $returnState = eZApproveType::validateGroupIDList( $userGroupIDList, $reason );
00440 }
00441 }
00442 }
00443 }
00444 else
00445 {
00446 $browseParameters =& $http->sessionVariable( 'BrowseParameters' );
00447 if ( isset( $browseParameters['custom_action_data'] ) )
00448 {
00449 $customData = $browseParameters['custom_action_data'];
00450 if ( isset( $customData['event_id'] ) and
00451 $customData['event_id'] == $workflowEvent->attribute( 'id' ) )
00452 {
00453 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) and
00454 $http->hasPostVariable( 'SelectedObjectIDArray' ) )
00455 {
00456 $objectIDArray = $http->postVariable( 'SelectedObjectIDArray' );
00457 if ( is_array( $objectIDArray ) and
00458 count( $objectIDArray ) > 0 )
00459 {
00460 switch( $customData['browse_action'] )
00461 {
00462 case "AddApproveUsers":
00463 {
00464 $returnState = eZApproveType::validateUserIDList( $objectIDArray, $reason );
00465 } break;
00466 case 'AddApproveGroups':
00467 case 'AddExcludeUser':
00468 {
00469 $returnState = eZApproveType::validateGroupIDList( $objectIDArray, $reason );
00470 } break;
00471 case 'AddExcludedGroups':
00472 {
00473
00474
00475 } break;
00476 }
00477 }
00478 }
00479 }
00480 }
00481 }
00482
00483 if ( $returnState == EZ_INPUT_VALIDATOR_STATE_INVALID )
00484 {
00485 $validation[ 'processed' ] = true;
00486 $validation[ 'events' ][] = array( 'id' => $workflowEvent->attribute( 'id' ),
00487 'placement' => $workflowEvent->attribute( 'placement' ),
00488 'workflow_type' => &$this,
00489 'reason' => $reason );
00490 }
00491 return $returnState;
00492 }
00493
00494
00495 function fetchHTTPInput( &$http, $base, &$event )
00496 {
00497 $sectionsVar = $base . "_event_ezapprove_section_" . $event->attribute( "id" );
00498 if ( $http->hasPostVariable( $sectionsVar ) )
00499 {
00500 $sectionsArray = $http->postVariable( $sectionsVar );
00501 if ( in_array( '-1', $sectionsArray ) )
00502 {
00503 $sectionsArray = array( -1 );
00504 }
00505 $sectionsString = implode( ',', $sectionsArray );
00506 $event->setAttribute( "data_text1", $sectionsString );
00507 }
00508
00509 $languageVar = $base . "_event_ezapprove_languages_" . $event->attribute( "id" );
00510 if ( $http->hasPostVariable( $languageVar ) )
00511 {
00512 $languageArray = $http->postVariable( $languageVar );
00513 if ( in_array( '-1', $languageArray ) )
00514 {
00515 $languageArray = array();
00516 }
00517 $languageMask = 0;
00518 foreach ( $languageArray as $languageID )
00519 {
00520 $languageMask |= $languageID;
00521 }
00522 $event->setAttribute( "data_int2", $languageMask );
00523 }
00524
00525 $versionOptionVar = $base . "_event_ezapprove_version_option_" . $event->attribute( "id" );
00526 if ( $http->hasPostVariable( $versionOptionVar ) )
00527 {
00528 $versionOptionArray = $http->postVariable( $versionOptionVar );
00529 $versionOption = 0;
00530 if ( is_array( $versionOptionArray ) )
00531 {
00532 foreach ( $versionOptionArray as $vv )
00533 {
00534 $versionOption = $versionOption | $vv;
00535 }
00536 }
00537 $versionOption = $versionOption & EZ_APPROVE_VERSION_OPTION_ALL;
00538 $event->setAttribute( 'data_int3', $versionOption );
00539 }
00540
00541 if ( $http->hasSessionVariable( 'BrowseParameters' ) )
00542 {
00543 $browseParameters = $http->sessionVariable( 'BrowseParameters' );
00544 if ( isset( $browseParameters['custom_action_data'] ) )
00545 {
00546 $customData = $browseParameters['custom_action_data'];
00547 if ( isset( $customData['event_id'] ) &&
00548 $customData['event_id'] == $event->attribute( 'id' ) )
00549 {
00550 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) and
00551 $http->hasPostVariable( 'SelectedObjectIDArray' ) )
00552 {
00553 $objectIDArray = $http->postVariable( 'SelectedObjectIDArray' );
00554 if ( is_array( $objectIDArray ) and
00555 count( $objectIDArray ) > 0 )
00556 {
00557
00558 switch( $customData['browse_action'] )
00559 {
00560 case 'AddApproveUsers':
00561 {
00562 foreach( $objectIDArray as $key => $userID )
00563 {
00564 if ( !eZUser::isUserObject( eZContentObject::fetch( $userID ) ) )
00565 {
00566 unset( $objectIDArray[$key] );
00567 }
00568 }
00569 $event->setAttribute( 'data_text3', implode( ',',
00570 array_unique( array_merge( $this->attributeDecoder( $event, 'approve_users' ),
00571 $objectIDArray ) ) ) );
00572 } break;
00573
00574 case 'AddApproveGroups':
00575 {
00576 $event->setAttribute( 'data_text4', implode( ',',
00577 array_unique( array_merge( $this->attributeDecoder( $event, 'approve_groups' ),
00578 $objectIDArray ) ) ) );
00579 } break;
00580
00581 case 'AddExcludeUser':
00582 {
00583 $event->setAttribute( 'data_text2', implode( ',',
00584 array_unique( array_merge( $this->attributeDecoder( $event, 'selected_usergroups' ),
00585 $objectIDArray ) ) ) );
00586 } break;
00587
00588 case 'AddExcludedGroups':
00589 {
00590
00591
00592 } break;
00593 }
00594 }
00595 $http->removeSessionVariable( 'BrowseParameters' );
00596 }
00597 }
00598 }
00599 }
00600 }
00601
00602 function createApproveCollaboration( &$process, &$event, $userID, $contentobjectID, $contentobjectVersion, $editors )
00603 {
00604 if ( $editors === null )
00605 return false;
00606 $authorID = $userID;
00607 $collaborationItem = eZApproveCollaborationHandler::createApproval( $contentobjectID, $contentobjectVersion,
00608 $authorID, $editors );
00609 $db = & eZDb::instance();
00610 $db->query( 'INSERT INTO ezapprove_items( workflow_process_id, collaboration_id )
00611 VALUES(' . $process->attribute( 'id' ) . ',' . $collaborationItem->attribute( 'id' ) . ' ) ' );
00612 }
00613
00614
00615
00616
00617 function customWorkflowEventHTTPAction( &$http, $action, &$workflowEvent )
00618 {
00619 $eventID = $workflowEvent->attribute( "id" );
00620 $module =& $GLOBALS['eZRequestedModule'];
00621
00622 include_once( 'kernel/classes/ezcontentclass.php' );
00623
00624 switch ( $action )
00625 {
00626 case 'AddApproveUsers' :
00627 {
00628 $userClassNames = eZUser::fetchUserClassNames();
00629 if ( count( $userClassNames ) > 0 )
00630 {
00631 include_once( 'kernel/classes/ezcontentbrowse.php' );
00632 eZContentBrowse::browse( array( 'action_name' => 'SelectMultipleUsers',
00633 'from_page' => '/workflow/edit/' . $workflowEvent->attribute( 'workflow_id' ),
00634 'custom_action_data' => array( 'event_id' => $eventID,
00635 'browse_action' => $action ),
00636 'class_array' => $userClassNames ),
00637 $module );
00638 }
00639 } break;
00640
00641 case 'RemoveApproveUsers' :
00642 {
00643 if ( $http->hasPostVariable( 'DeleteApproveUserIDArray_' . $eventID ) )
00644 {
00645 $workflowEvent->setAttribute( 'data_text3', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'approve_users' ),
00646 $http->postVariable( 'DeleteApproveUserIDArray_' . $eventID ) ) ) );
00647 }
00648 } break;
00649
00650 case 'AddApproveGroups' :
00651 case 'AddExcludeUser' :
00652 {
00653 $groupClassNames = eZUser::fetchUserGroupClassNames();
00654 if ( count( $groupClassNames ) > 0 )
00655 {
00656 include_once( 'kernel/classes/ezcontentbrowse.php' );
00657 eZContentBrowse::browse( array( 'action_name' => 'SelectMultipleUsers',
00658 'from_page' => '/workflow/edit/' . $workflowEvent->attribute( 'workflow_id' ),
00659 'custom_action_data' => array( 'event_id' => $eventID,
00660 'browse_action' => $action ),
00661 'class_array' => $groupClassNames ),
00662 $module );
00663 }
00664 } break;
00665
00666 case 'RemoveApproveGroups' :
00667 {
00668 if ( $http->hasPostVariable( 'DeleteApproveGroupIDArray_' . $eventID ) )
00669 {
00670 $workflowEvent->setAttribute( 'data_text4', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'approve_groups' ),
00671 $http->postVariable( 'DeleteApproveGroupIDArray_' . $eventID ) ) ) );
00672 }
00673 } break;
00674
00675 case 'RemoveExcludeUser' :
00676 {
00677 if ( $http->hasPostVariable( 'DeleteExcludeUserIDArray_' . $eventID ) )
00678 {
00679 $workflowEvent->setAttribute( 'data_text2', implode( ',', array_diff( $this->attributeDecoder( $workflowEvent, 'selected_usergroups' ),
00680 $http->postVariable( 'DeleteExcludeUserIDArray_' . $eventID ) ) ) );
00681 }
00682 } break;
00683
00684 case 'AddExcludedGroups' :
00685 {
00686
00687
00688 } break;
00689
00690 case 'RemoveExcludedGroups' :
00691 {
00692
00693
00694 } break;
00695 }
00696 }
00697
00698
00699
00700
00701 function cleanupAfterRemoving( $attr = array() )
00702 {
00703 foreach ( array_keys( $attr ) as $attrKey )
00704 {
00705 switch ( $attrKey )
00706 {
00707 case 'DeleteContentObject':
00708 {
00709 $contentObjectID = (int)$attr[ $attrKey ];
00710 $db = & eZDb::instance();
00711
00712 $db->query( 'UPDATE ezworkflow_event
00713 SET data_int1 = \'0\'
00714 WHERE data_int1 = \'' . $contentObjectID . '\'' );
00715
00716 $excludedGroupsID = $db->arrayQuery( 'SELECT data_text2, id
00717 FROM ezworkflow_event
00718 WHERE data_text2 like \'%' . $contentObjectID . '%\'' );
00719 if ( count( $excludedGroupsID ) > 0 )
00720 {
00721 foreach ( $excludedGroupsID as $groupID )
00722 {
00723
00724 $IDArray = split( ',', $groupID[ 'data_text2' ] );
00725
00726 $newIDArray = array_filter( $IDArray, create_function( '$v', 'return ( $v != ' . $contentObjectID .' );' ) );
00727 $newValues = implode( ',', $newIDArray );
00728 $db->query( 'UPDATE ezworkflow_event
00729 SET data_text2 = \''. $newValues .'\'
00730 WHERE id = ' . $groupID[ 'id' ] );
00731 }
00732 }
00733 } break;
00734 }
00735 }
00736 }
00737
00738 function checkApproveCollaboration( &$process, &$event )
00739 {
00740 $db = & eZDb::instance();
00741 $taskResult = $db->arrayQuery( 'select workflow_process_id, collaboration_id from ezapprove_items where workflow_process_id = ' . $process->attribute( 'id' ) );
00742 $collaborationID = $taskResult[0]['collaboration_id'];
00743 $collaborationItem = eZCollaborationItem::fetch( $collaborationID );
00744 $contentObjectVersion = eZApproveCollaborationHandler::contentObjectVersion( $collaborationItem );
00745 $approvalStatus = eZApproveCollaborationHandler::checkApproval( $collaborationID );
00746 if ( $approvalStatus == EZ_COLLABORATION_APPROVE_STATUS_WAITING )
00747 {
00748 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval still waiting' );
00749 return EZ_WORKFLOW_TYPE_STATUS_DEFERRED_TO_CRON_REPEAT;
00750 }
00751 else if ( $approvalStatus == EZ_COLLABORATION_APPROVE_STATUS_ACCEPTED )
00752 {
00753 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval was accepted' );
00754 $status = EZ_WORKFLOW_TYPE_STATUS_ACCEPTED;
00755 }
00756 else if ( $approvalStatus == EZ_COLLABORATION_APPROVE_STATUS_DENIED or
00757 $approvalStatus == EZ_COLLABORATION_APPROVE_STATUS_DEFERRED )
00758 {
00759 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, 'approval was denied' );
00760 $contentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
00761 $status = EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED;
00762 }
00763 else
00764 {
00765 eZDebugSetting::writeDebug( 'kernel-workflow-approve', $event, "approval unknown status '$approvalStatus'" );
00766 $contentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_REJECTED );
00767 $status = EZ_WORKFLOW_TYPE_STATUS_WORKFLOW_CANCELLED;
00768 }
00769 $contentObjectVersion->sync();
00770 if ( $approvalStatus != EZ_COLLABORATION_APPROVE_STATUS_DEFERRED )
00771 $db->query( 'DELETE FROM ezapprove_items WHERE workflow_process_id = ' . $process->attribute( 'id' ) );
00772 return $status;
00773 }
00774 }
00775
00776 eZWorkflowEventType::registerType( EZ_WORKFLOW_TYPE_APPROVE_ID, "ezapprovetype" );
00777
00778 ?>