[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/workflow/ -> edit.php (source)

   1  <?php
   2  //
   3  // Created on: <16-Apr-2002 11:00:12 amos>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  include_once ( "kernel/classes/ezworkflow.php" );
  28  include_once ( "kernel/classes/ezworkflowgrouplink.php" );
  29  include_once ( "kernel/classes/ezworkflowevent.php" );
  30  include_once ( "kernel/classes/ezworkflowtype.php" );
  31  include_once ( "lib/ezutils/classes/ezhttptool.php" );
  32  include_once ( "lib/ezutils/classes/ezhttppersistence.php" );
  33  
  34  $Module =& $Params["Module"];
  35  
  36  $WorkflowID = ( isset( $Params["WorkflowID"] ) ) ? $Params["WorkflowID"] : false;
  37  
  38  switch ( $Params["FunctionName"] )
  39  {
  40  case "up":
  41  case "down":
  42      {
  43          if ( $WorkflowID !== false )
  44          {
  45              if ( isset( $Params["EventID"] ) )
  46              {
  47                  $event = eZWorkflowEvent::fetch( $Params["EventID"], true, 1,
  48                                                   array( "workflow_id", "version", "placement" ) );
  49                  $event->move( $Params["FunctionName"] == "up" ? false : true );
  50                  $Module->redirectTo( $Module->functionURI( 'edit' ) . '/' . $WorkflowID );
  51                  return;
  52              }
  53              else
  54              {
  55                  eZDebug::writeError( "Missing parameter EventID for function: " . $params["Function"] );
  56                  $Module->setExitStatus( EZ_MODULE_STATUS_FAILED );
  57                  return;
  58              }
  59          }
  60          else
  61          {
  62              eZDebug::writeError( "Missing parameter WorkfowID for function: " . $params["Function"] );
  63              $Module->setExitStatus( EZ_MODULE_STATUS_FAILED );
  64              return;
  65          }
  66      } break;
  67  case "edit":
  68      {
  69      } break;
  70  default:
  71      {
  72          eZDebug::writeError( "Undefined function: " . $params["Function"] );
  73          $Module->setExitStatus( EZ_MODULE_STATUS_FAILED );
  74          return;
  75      }
  76  }
  77  
  78  $GroupID = ( isset( $Params["GroupID"] ) ) ? $Params["GroupID"] : false;
  79  $GroupName = ( isset( $Params["GroupName"] ) ) ? $Params["GroupName"] : false;
  80  
  81  if ( is_numeric( $WorkflowID ) )
  82  {
  83      // try to fetch temporary version of workflow
  84      $workflow = eZWorkflow::fetch( $WorkflowID, true, 1 );
  85  
  86      // If temporary version does not exist fetch the current
  87      if ( !is_object( $workflow ) )
  88      {
  89          $workflow = eZWorkflow::fetch( $WorkflowID, true, 0 );
  90          if ( is_object( $workflow ) )
  91          {
  92              $workflowGroups = eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 0, true );
  93  
  94              $db =& eZDB::instance();
  95              $db->begin();
  96              foreach ( $workflowGroups as $workflowGroup )
  97              {
  98                  $groupID = $workflowGroup->attribute( "group_id" );
  99                  $groupName = $workflowGroup->attribute( "group_name" );
 100                  $ingroup = eZWorkflowGroupLink::create( $WorkflowID, 1, $groupID, $groupName );
 101                  $ingroup->store();
 102              }
 103              $db->commit();
 104          }
 105          else
 106          {
 107              eZDebug::writeError( "Cannot fetch workflow with WorkfowID = " . $WorkflowID );
 108              $Module->setExitStatus( EZ_MODULE_STATUS_FAILED );
 109              return;
 110          }
 111      }
 112  }
 113  else
 114  {
 115      // if WorkflowID was not given then create new workflow
 116      include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" );
 117      $user =& eZUser::currentUser();
 118      $user_id = $user->attribute( "contentobject_id" );
 119      $workflow = eZWorkflow::create( $user_id );
 120      $workflowCount = eZWorkflow::fetchListCount();
 121      ++$workflowCount;
 122      $workflow->setAttribute( "name", ezi18n( 'kernel/workflow/edit', "New Workflow" ) . "$workflowCount" );
 123  
 124      $db =& eZDB::instance();
 125      $db->begin();
 126      $workflow->store();
 127      $WorkflowID = $workflow->attribute( "id" );
 128      $WorkflowVersion = $workflow->attribute( "version" );
 129      $ingroup = eZWorkflowGroupLink::create( $WorkflowID, $WorkflowVersion, $GroupID, $GroupName );
 130      $ingroup->store();
 131      $db->commit();
 132      return $Module->redirectTo( $Module->functionURI( 'edit' ) . '/' . $WorkflowID . '/' . $GroupID );
 133  }
 134  
 135  $http =& eZHttpTool::instance();
 136  $WorkflowVersion = $workflow->attribute( "version" );
 137  
 138  if ( $http->hasPostVariable( "DiscardButton" ) )
 139  {
 140      $workflow->setVersion( 1 );
 141  
 142      $db =& eZDB::instance();
 143      $db->begin();
 144      $workflow->remove( true );
 145      eZWorkflowGroupLink::removeWorkflowMembers( $WorkflowID, $WorkflowVersion );
 146      $db->commit();
 147  
 148      $workflowGroups= eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 0, true );
 149      $groupID = false;
 150      if ( count( $workflowGroups ) > 0 )
 151          $groupID = $workflowGroups[0]->attribute( 'group_id' );
 152      if ( !$groupID )
 153          $groupID = $GroupID;
 154      if ( $groupID )
 155          return $Module->redirectToView( 'workflowlist', array( $groupID ) );
 156      else
 157          return $Module->redirectToView( 'grouplist' );
 158  }
 159  
 160  $validation = array( 'processed' => false,
 161                       'groups' => array(),
 162                       'attributes' => array(),
 163                       'events' => array() );
 164  
 165  if ( $http->hasPostVariable( "AddGroupButton" ) && $http->hasPostVariable( "Workflow_group") )
 166  {
 167      include_once ( "kernel/workflow/ezworkflowfunctions.php" );
 168  
 169      $selectedGroup = $http->postVariable( "Workflow_group" );
 170      eZWorkflowFunctions::addGroup( $WorkflowID, $WorkflowVersion, $selectedGroup );
 171  }
 172  
 173  if ( $http->hasPostVariable( "DeleteGroupButton" ) && $http->hasPostVariable( "group_id_checked" ) )
 174  {
 175      include_once ( "kernel/workflow/ezworkflowfunctions.php" );
 176  
 177      $selectedGroup = $http->postVariable( "group_id_checked" );
 178      if ( !eZWorkflowFunctions::removeGroup( $WorkflowID, $WorkflowVersion, $selectedGroup ) )
 179      {
 180          $validation['groups'][] = array( 'text' => ezi18n( 'kernel/workflow', 'You have to have at least one group that the workflow belongs to!' ) );
 181          $validation['processed'] = true;
 182      }
 183  }
 184  
 185  // Fetch events and types
 186  $event_list =& $workflow->fetchEvents();
 187  $type_list =& eZWorkflowType::fetchRegisteredTypes();
 188  
 189  if ( $http->hasPostVariable( "DeleteButton" ) )
 190  {
 191      $db =& eZDB::instance();
 192      $db->begin();
 193  
 194      if ( eZHttpPersistence::splitSelected( "WorkflowEvent", $event_list,
 195                                             $http, "id",
 196                                             $keepers, $rejects ) )
 197      {
 198          $event_list = $keepers;
 199  
 200          foreach ( $rejects as $reject )
 201          {
 202              $reject->remove();
 203          }
 204      }
 205      $db->commit();
 206  
 207      $event_list =& $workflow->fetchEvents();
 208  }
 209  
 210  // Validate input
 211  include_once ( "lib/ezutils/classes/ezinputvalidator.php" );
 212  $canStore = true;
 213  $requireFixup = false;
 214  foreach( array_keys( $event_list ) as $key )
 215  {
 216      $event =& $event_list[$key];
 217      $eventType =& $event->eventType();
 218      $status = $eventType->validateHTTPInput( $http, "WorkflowEvent", $event, $validation );
 219  
 220      if ( $status == EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE )
 221          $requireFixup = true;
 222      else if ( $status == EZ_INPUT_VALIDATOR_STATE_INVALID )
 223          $canStore = false;
 224  }
 225  
 226  // Fixup input
 227  if ( $requireFixup )
 228  {
 229      foreach( array_keys( $event_list ) as $key )
 230      {
 231          $event =& $event_list[$key];
 232          $eventType =& $event->eventType();
 233          $status = $eventType->fixupHTTPInput( $http, "WorkflowEvent", $event );
 234      }
 235  }
 236  
 237  $cur_type = 0;
 238  // Apply HTTP POST variables
 239  eZHttpPersistence::fetch( "WorkflowEvent", eZWorkflowEvent::definition(),
 240                            $event_list, $http, true );
 241  eZHttpPersistence::fetch( "Workflow", eZWorkflow::definition(),
 242                            $workflow, $http, false );
 243  if ( $http->hasPostVariable( "WorkflowTypeString" ) )
 244      $cur_type = $http->postVariable( "WorkflowTypeString" );
 245  
 246  // set temporary version to edited workflow
 247  $workflow->setVersion( 1, $event_list );
 248  
 249  // Set new modification date
 250  $date_time = time();
 251  $workflow->setAttribute( "modified", $date_time );
 252  include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" );
 253  $user =& eZUser::currentUser();
 254  $user_id = $user->attribute( "contentobject_id" );
 255  $workflow->setAttribute( "modifier_id", $user_id );
 256  
 257  
 258  /********** Custom Action Code Start ***************/
 259  $customAction = false;
 260  $customActionAttributeID = null;
 261  // Check for custom actions
 262  if ( $http->hasPostVariable( "CustomActionButton" ) )
 263  {
 264      $customActionArray = $http->postVariable( "CustomActionButton" );
 265      $customActionString = key( $customActionArray );
 266  
 267      $customActionAttributeID = preg_match( "#^([0-9]+)_(.*)$#", $customActionString, $matchArray );
 268      $customActionAttributeID = $matchArray[1];
 269      $customAction = $matchArray[2];
 270  }
 271  /********** Custom Action Code End ***************/
 272  
 273  
 274  // Fetch HTTP input
 275  foreach( array_keys( $event_list ) as $key )
 276  {
 277      $event =& $event_list[$key];
 278      $eventType =& $event->eventType();
 279      $eventType->fetchHTTPInput( $http, "WorkflowEvent", $event );
 280      if ( $customActionAttributeID == $event->attribute( "id" ) )
 281      {
 282          $event->customHTTPAction( $http, $customAction );
 283      }
 284  }
 285  
 286  if ( $http->hasPostVariable( "StoreButton" ) and $canStore )
 287  {
 288      // Discard existing events, workflow version 1 and store version 0
 289      $db =& eZDB::instance();
 290      $db->begin();
 291  
 292      $workflow->store( $event_list ); // store changes.
 293  
 294      // Remove old version 0 first
 295      eZWorkflowGroupLink::removeWorkflowMembers( $WorkflowID, 0 );
 296  
 297      $workflowgroups = eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 1 );
 298      for ( $i=0;$i<count(  $workflowgroups );$i++ )
 299      {
 300          $workflowgroup =& $workflowgroups[$i];
 301          $workflowgroup->setAttribute("workflow_version", 0 );
 302          $workflowgroup->store();
 303      }
 304      // Remove version 1
 305      eZWorkflowGroupLink::removeWorkflowMembers( $WorkflowID, 1 );
 306  
 307      eZWorkflow::removeEvents( false, $WorkflowID, 0 );
 308      $workflow->remove( true );
 309      $workflow->setVersion( 0, $event_list );
 310      $workflow->adjustEventPlacements( $event_list );
 311      $workflow->store( $event_list );
 312      $workflow->cleanupWorkFlowProcess();
 313  
 314      $db->commit();
 315  
 316      $workflowGroups= eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 0, true );
 317      $groupID = false;
 318      if ( count( $workflowGroups ) > 0 )
 319          $groupID = $workflowGroups[0]->attribute( 'group_id' );
 320      if ( $groupID )
 321          return $Module->redirectToView( 'workflowlist', array( $groupID ) );
 322      else
 323          return $Module->redirectToView( 'grouplist' );
 324  }
 325  // Remove events which are to be deleted
 326  else if ( $http->hasPostVariable( "DeleteButton" ) )
 327  {
 328      if ( $canStore )
 329          $workflow->store( $event_list );
 330  }
 331  // Add new workflow event
 332  else if ( $http->hasPostVariable( "NewButton" ) )
 333  {
 334      $new_event = eZWorkflowEvent::create( $WorkflowID, $cur_type );
 335      $new_event_type =& $new_event->eventType();
 336      $db =& eZDB::instance();
 337      $db->begin();
 338  
 339      if ($canStore)
 340          $workflow->store( $event_list );
 341  
 342      $new_event_type->initializeEvent( $new_event );
 343      $new_event->store();
 344  
 345      $db->commit();
 346      $event_list[] =& $new_event;
 347  }
 348  else if ( $canStore )
 349  {
 350      $workflow->store( $event_list );
 351  }
 352  
 353  $Module->setTitle( ezi18n( 'kernel/workflow', 'Edit workflow' ) . ' ' . $workflow->attribute( "name" ) );
 354  
 355  // Template handling
 356  include_once ( "kernel/common/template.php" );
 357  $tpl =& templateInit();
 358  
 359  $res =& eZTemplateDesignResource::instance();
 360  
 361  $res->setKeys( array( array( "workflow", $workflow->attribute( "id" ) ) ) );
 362  
 363  if ( isset( $GLOBALS['eZWaitUntilDateSelectedClass'] ) )
 364      $tpl->setVariable( "selectedClass", $GLOBALS['eZWaitUntilDateSelectedClass'] );
 365  
 366  $tpl->setVariable( "http", $http );
 367  $tpl->setVariable( "can_store", $canStore );
 368  $tpl->setVariable( "require_fixup", $requireFixup );
 369  $tpl->setVariable( "module", $Module );
 370  $tpl->setVariable( "workflow", $workflow );
 371  $tpl->setVariable( "event_list", $event_list );
 372  $tpl->setVariable( "workflow_type_list", $type_list );
 373  $tpl->setVariable( "workflow_type", $cur_type );
 374  $tpl->setVariable( 'validation', $validation );
 375  if ( isset( $GroupID ) )
 376  {
 377      $tpl->setVariable( "group_id", $GroupID );
 378  }
 379  
 380  $Result = array();
 381  $Result['content'] =& $tpl->fetch( "design:workflow/edit.tpl" );
 382  $Result['path'] = array( array( 'text' => ezi18n( 'kernel/workflow', 'Workflow' ),
 383                                  'url' => false ),
 384                           array( 'text' => ezi18n( 'kernel/workflow', 'Edit' ),
 385                                  'url' => false ) );
 386  
 387  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7