[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/content/ -> removeeditversion.php (source)

   1  <?php
   2  //
   3  //
   4  // Created on: <10-Dec-2002 16:02:26 wy>
   5  //
   6  // SOFTWARE NAME: eZ publish
   7  // SOFTWARE RELEASE: 3.9.0
   8  // BUILD VERSION: 17785
   9  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  10  // SOFTWARE LICENSE: GNU General Public License v2.0
  11  // NOTICE: >
  12  //   This program is free software; you can redistribute it and/or
  13  //   modify it under the terms of version 2.0  of the GNU General
  14  //   Public License as published by the Free Software Foundation.
  15  //
  16  //   This program is distributed in the hope that it will be useful,
  17  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  //   GNU General Public License for more details.
  20  //
  21  //   You should have received a copy of version 2.0 of the GNU General
  22  //   Public License along with this program; if not, write to the Free
  23  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24  //   MA 02110-1301, USA.
  25  //
  26  //
  27  
  28  /*! \file removeobject.php
  29  */
  30  include_once ( "kernel/classes/ezcontentobject.php" );
  31  include_once ( "lib/ezutils/classes/ezhttppersistence.php" );
  32  include_once ( "lib/ezdb/classes/ezdb.php" );
  33  $Module =& $Params["Module"];
  34  $http =& eZHTTPTool::instance();
  35  $objectID = (int) $http->sessionVariable( "DiscardObjectID" );
  36  $version = (int) $http->sessionVariable( "DiscardObjectVersion" );
  37  $editLanguage = $http->sessionVariable( "DiscardObjectLanguage" );
  38  
  39  $isConfirmed = false;
  40  if ( $http->hasPostVariable( "ConfirmButton" ) )
  41      $isConfirmed = true;
  42  
  43  if ( $http->hasSessionVariable( "DiscardConfirm" ) )
  44  {
  45      $discardConfirm = $http->sessionVariable( "DiscardConfirm" );
  46      if ( !$discardConfirm )
  47          $isConfirmed = true;
  48  }
  49  
  50  if ( $isConfirmed )
  51  {
  52      $object =& eZContentObject::fetch( $objectID );
  53      if ( $object === null )
  54          return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
  55  
  56      $versionObject =& $object->version( $version );
  57      if ( is_object( $versionObject ) and $versionObject->attribute('status') != EZ_VERSION_STATUS_PUBLISHED )
  58      {
  59          if ( !$object->attribute( 'can_edit' ) )
  60          {
  61              // Check if it is a first created version of an object.
  62              // If so, then edit is allowed if we have an access to the 'create' function.
  63              if ( $object->attribute( 'current_version' ) == 1 && !$object->attribute( 'status' ) )
  64              {
  65                  $mainNode = eZNodeAssignment::fetchForObject( $object->attribute( 'id' ), 1 );
  66                  $parentObj = $mainNode[0]->attribute( 'parent_contentobject' );
  67                  $allowEdit = $parentObj->checkAccess( 'create', $object->attribute( 'contentclass_id' ), $parentObj->attribute( 'contentclass_id' ) );
  68              }
  69              else
  70                  $allowEdit = false;
  71  
  72              if ( !$allowEdit )
  73                  return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel', array( 'AccessList' => $object->accessList( 'edit' ) ) );
  74          }
  75  
  76          $db =& eZDB::instance();
  77          $db->begin();
  78  
  79          $contentObjectAttributes =& $versionObject->contentObjectAttributes( $editLanguage );
  80          foreach ( $contentObjectAttributes as $contentObjectAttribute )
  81          {
  82              $objectAttributeID = $contentObjectAttribute->attribute( 'id' );
  83              $contentObjectAttribute->remove( $objectAttributeID, $version );
  84          }
  85          $versionCount= $object->getVersionCount();
  86          if ( $versionCount == 1 )
  87          {
  88              $nodeID = $versionObject->attribute( 'main_parent_node_id' );
  89              $object->purge();
  90          }
  91          else
  92          {
  93              $nodeID = $object->attribute( 'main_node_id' );
  94              $versionObject->remove();
  95          }
  96  
  97          $db->query( "DELETE FROM ezcontentobject_link
  98                       WHERE from_contentobject_id=$objectID AND from_contentobject_version=$version" );
  99          $db->query( "DELETE FROM eznode_assignment
 100                       WHERE contentobject_id=$objectID AND contentobject_version=$version" );
 101  
 102          $db->commit();
 103      }
 104      $hasRedirected = false;
 105      if ( $http->hasSessionVariable( 'RedirectIfDiscarded' ) )
 106      {
 107          $Module->redirectTo( $http->sessionVariable( 'RedirectIfDiscarded' ) );
 108          $http->removeSessionVariable( 'RedirectIfDiscarded' );
 109          $http->removeSessionVariable( 'ParentObject' );
 110          $http->removeSessionVariable( 'NewObjectID' );
 111          $hasRedirected = true;
 112      }
 113      if ( $http->hasSessionVariable( 'ParentObject' ) && $http->sessionVariable( 'NewObjectID' ) == $objectID )
 114      {
 115          $parentArray = $http->sessionVariable( 'ParentObject' );
 116          $parentURL = $Module->redirectionURI( 'content', 'edit', $parentArray );
 117          $http->removeSessionVariable( 'ParentObject' );
 118          $http->removeSessionVariable( 'NewObjectID' );
 119          $Module->redirectTo( $parentURL );
 120          $hasRedirected = true;
 121      }
 122  
 123      if ( $hasRedirected == false )
 124      {
 125          if ( $nodeID != null )
 126              return $Module->redirectTo( '/content/view/full/' . $nodeID .'/' );
 127  
 128          include_once ( 'kernel/classes/ezredirectmanager.php' );
 129          return eZRedirectManager::redirectTo( $Module, '/', true, array( 'content/edit' ) );
 130      }
 131  }
 132  
 133  if ( $http->hasPostVariable( "CancelButton" ) )
 134  {
 135      $Module->redirectTo( '/content/edit/' . $objectID . '/' . $version . '/' );
 136  }
 137  
 138  $Module->setTitle( "Remove Editing Version" );
 139  
 140  include_once ( "kernel/common/template.php" );
 141  $tpl =& templateInit();
 142  $tpl->setVariable( "Module", $Module );
 143  $tpl->setVariable( "object_id", $objectID );
 144  $tpl->setVariable( "object_version", $version );
 145  $tpl->setVariable( "object_language", $editLanguage );
 146  $Result = array();
 147  $Result['content'] =& $tpl->fetch( "design:content/removeeditversion.tpl" );
 148  $Result['path'] = array( array( 'url' => '/content/removeeditversion/',
 149                                  'text' => ezi18n( 'kernel/content', 'Remove editing version' ) ) );
 150  ?>


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