[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Created on: <22-Apr-2002 15:41:30 bf> 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/ezcontentclass.php' ); 28 include_once ( 'kernel/classes/ezcontentclassattribute.php' ); 29 30 include_once ( 'kernel/classes/ezcontentobject.php' ); 31 include_once ( 'kernel/classes/ezcontentobjectversion.php' ); 32 include_once ( 'kernel/classes/ezcontentobjectattribute.php' ); 33 34 include_once ( 'kernel/common/template.php' ); 35 include_once ( "lib/ezutils/classes/ezini.php" ); 36 include_once ( "lib/ezdb/classes/ezdb.php" ); 37 38 include_once ( 'lib/ezutils/classes/ezdebug.php' ); 39 40 $tpl =& templateInit(); 41 $http =& eZHTTPTool::instance(); 42 43 $ObjectID = $Params['ObjectID']; 44 $EditVersion = $Params['EditVersion']; 45 46 $Offset = $Params['Offset']; 47 $viewParameters = array( 'offset' => $Offset ); 48 49 if ( $http->hasPostVariable( 'BackButton' ) ) 50 { 51 $userRedirectURI = ''; 52 if ( $http->hasPostVariable( 'RedirectURI' ) ) 53 { 54 $redurectURI = $http->postVariable( 'RedirectURI' ); 55 $http->removeSessionVariable( 'LastAccessesVersionURI' ); 56 return $Module->redirectTo( $redurectURI ); 57 } 58 if ( $http->hasSessionVariable( "LastAccessesURI" ) ) 59 $userRedirectURI = $http->sessionVariable( "LastAccessesURI" ); 60 return $Module->redirectTo( $userRedirectURI ); 61 } 62 63 $object =& eZContentObject::fetch( $ObjectID ); 64 $editWarning = false; 65 66 $canEdit = false; 67 $canRemove = false; 68 69 if ( $object === null ) 70 return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' ); 71 72 if ( !$object->attribute( 'can_read' ) ) 73 return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' ); 74 75 if ( $object->attribute( 'can_edit' ) ) 76 $canEdit = true; 77 78 $canRemove = true; 79 80 $http =& eZHTTPTool::instance(); 81 82 if ( $http->hasSessionVariable( 'ExcessVersionHistoryLimit' ) ) 83 { 84 $excessLimit = $http->sessionVariable( 'ExcessVersionHistoryLimit' ); 85 if ( $excessLimit ) 86 $editWarning = 3; 87 $http->removeSessionVariable( 'ExcessVersionHistoryLimit' ); 88 } 89 90 if ( $http->hasPostVariable( 'RemoveButton' ) ) 91 { 92 if ( !$canEdit ) 93 return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' ); 94 if ( $http->hasPostVariable( 'DeleteIDArray' ) ) 95 { 96 $db =& eZDB::instance(); 97 $db->begin(); 98 99 $deleteIDArray = $http->postVariable( 'DeleteIDArray' ); 100 $versionArray = array(); 101 foreach ( $deleteIDArray as $deleteID ) 102 { 103 $version = eZContentObjectVersion::fetch( $deleteID ); 104 $versionArray[] = $version->attribute( 'version' ); 105 if ( $version != null ) 106 { 107 if ( $version->attribute( 'can_remove' ) ) 108 { 109 $version->remove(); 110 } 111 } 112 } 113 $db->commit(); 114 } 115 } 116 117 $user =& eZUser::currentUser(); 118 119 if ( $Module->isCurrentAction( 'Edit' ) ) 120 { 121 if ( !$canEdit ) 122 return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' ); 123 124 $versionID = false; 125 126 if ( is_array( $Module->actionParameter( 'VersionKeyArray' ) ) ) 127 { 128 $versionID = array_keys( $Module->actionParameter( 'VersionKeyArray' ) ); 129 $versionID = $versionID[0]; 130 } 131 else if ( $Module->hasActionParameter( 'VersionID' ) ) 132 $versionID = $Module->actionParameter( 'VersionID' ); 133 $version =& $object->version( $versionID ); 134 if ( !$version ) 135 $versionID = false; 136 137 if ( $versionID !== false and 138 !in_array( $version->attribute( 'status' ), array( EZ_VERSION_STATUS_DRAFT, EZ_VERSION_STATUS_INTERNAL_DRAFT ) ) ) 139 { 140 $editWarning = 1; 141 $EditVersion = $versionID; 142 } 143 else if ( $versionID !== false and 144 $version->attribute( 'creator_id' ) != $user->attribute( 'contentobject_id' ) ) 145 { 146 $editWarning = 2; 147 $EditVersion = $versionID; 148 } 149 else 150 { 151 return $Module->redirectToView( 'edit', array( $ObjectID, $versionID, $version->initialLanguageCode() ) ); 152 } 153 } 154 155 $versions =& $object->versions(); 156 157 if ( $Module->isCurrentAction( 'CopyVersion' ) ) 158 { 159 if ( !$canEdit ) 160 { 161 return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' ); 162 } 163 164 if ( is_array( $Module->actionParameter( 'VersionKeyArray' ) ) ) 165 { 166 $versionID = array_keys( $Module->actionParameter( 'VersionKeyArray' ) ); 167 $versionID = $versionID[0]; 168 } 169 else 170 { 171 $versionID = $Module->actionParameter( 'VersionID' ); 172 } 173 174 $languages = $Module->actionParameter( 'LanguageArray' ); 175 if ( $languages && array_key_exists( $versionID, $languages ) ) 176 { 177 $language = $languages[$versionID]; 178 } 179 else 180 { 181 $language = false; 182 } 183 184 if ( !$object->checkAccess( 'edit', false, false, false, $language ) ) 185 { 186 return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' ); 187 } 188 189 $contentINI =& eZINI::instance( 'content.ini' ); 190 $versionlimit = $contentINI->variable( 'VersionManagement', 'DefaultVersionHistoryLimit' ); 191 192 $limitList = $contentINI->variable( 'VersionManagement', 'VersionHistoryClass' ); 193 194 $classID = $object->attribute( 'contentclass_id' ); 195 foreach ( array_keys ( $limitList ) as $key ) 196 { 197 if ( $classID == $key ) 198 $versionlimit =& $limitList[$key]; 199 } 200 if ( $versionlimit < 2 ) 201 $versionlimit = 2; 202 203 $versionCount = $object->getVersionCount(); 204 if ( $versionCount < $versionlimit ) 205 { 206 $db =& eZDB::instance(); 207 $db->begin(); 208 foreach ( array_keys( $versions ) as $versionKey ) 209 { 210 $version =& $versions[$versionKey]; 211 if ( $version->attribute( 'version' ) == $versionID ) 212 { 213 $newVersionID = $object->copyRevertTo( $versionID, $language ); 214 215 if ( !$http->hasPostVariable( 'DoNotEditAfterCopy' ) ) 216 { 217 break; 218 } 219 } 220 } 221 $db->commit(); 222 223 if ( !$http->hasPostVariable( 'DoNotEditAfterCopy' ) ) 224 { 225 return $Module->redirectToView( 'edit', array( $ObjectID, $newVersionID, $language ) ); 226 } 227 } 228 else 229 { 230 $params = array( 'conditions'=> array( 'status' => 3 ) ); 231 $versions =& $object->versions( true, $params ); 232 if ( count( $versions ) > 0 ) 233 { 234 $modified = $versions[0]->attribute( 'modified' ); 235 $removeVersion =& $versions[0]; 236 foreach ( array_keys( $versions ) as $versionKey ) 237 { 238 $version =& $versions[$versionKey]; 239 $currentModified = $version->attribute( 'modified' ); 240 if ( $currentModified < $modified ) 241 { 242 $modified = $currentModified; 243 $removeVersion = $version; 244 } 245 } 246 247 $db =& eZDB::instance(); 248 $db->begin(); 249 $removeVersion->remove(); 250 251 $versions =& $object->versions(); 252 foreach ( array_keys( $versions ) as $versionKey ) 253 { 254 $version =& $versions[$versionKey]; 255 if ( $version->attribute( 'version' ) == $versionID ) 256 { 257 $newVersionID = $object->copyRevertTo( $versionID ); 258 259 if ( !$http->hasPostVariable( 'DoNotEditAfterCopy' ) ) 260 { 261 break; 262 } 263 } 264 } 265 $db->commit(); 266 267 if ( !$http->hasPostVariable( 'DoNotEditAfterCopy' ) ) 268 { 269 return $Module->redirectToView( 'edit', array( $ObjectID, $newVersionID, $version->initialLanguageCode() ) ); 270 } 271 } 272 else 273 { 274 $http->setSessionVariable( 'ExcessVersionHistoryLimit', true ); 275 $currentVersion = $object->attribute( 'current_version' ); 276 $Module->redirectToView( 'versions', array( $ObjectID, $currentVersion ) ); 277 return EZ_MODULE_HOOK_STATUS_CANCEL_RUN; 278 } 279 } 280 } 281 282 $res =& eZTemplateDesignResource::instance(); 283 $res->setKeys( array( array( 'object', $object->attribute( 'id' ) ), // Object ID 284 array( 'class', $object->attribute( 'contentclass_id' ) ), // Class ID 285 array( 'class_identifier', $object->attribute( 'class_identifier' ) ), // Class identifier 286 array( 'section_id', $object->attribute( 'section_id' ) ) // Section ID 287 ) ); // Section ID, 0 so far 288 289 include_once ( 'kernel/classes/ezsection.php' ); 290 eZSection::setGlobalID( $object->attribute( 'section_id' ) ); 291 $versionArray =( isset( $versionArray ) and is_array( $versionArray ) ) ? array_unique( $versionArray ) : array(); 292 $LastAccessesVersionURI = $http->hasSessionVariable( 'LastAccessesVersionURI' ) ? $http->sessionVariable( 'LastAccessesVersionURI' ) : null; 293 $explodedURI = $LastAccessesVersionURI ? explode ( '/', $LastAccessesVersionURI ) : null; 294 if ( $LastAccessesVersionURI and is_array( $versionArray ) and !in_array( $explodedURI[3], $versionArray ) ) 295 $tpl->setVariable( 'redirect_uri', $http->sessionVariable( 'LastAccessesVersionURI' ) ); 296 297 $tpl->setVariable( 'view_parameters', $viewParameters ); 298 $tpl->setVariable( 'object', $object ); 299 $tpl->setVariable( 'edit_version', $EditVersion ); 300 $tpl->setVariable( 'versions', $versions ); 301 $tpl->setVariable( 'edit_warning', $editWarning ); 302 $tpl->setVariable( 'can_edit', $canEdit ); 303 //$tpl->setVariable( 'can_remove', $canRemove ); 304 $tpl->setVariable( 'user_id', $user->attribute( 'contentobject_id' ) ); 305 306 eZDebug::writeNotice( 'The versions view has been deprecated, please use the /content/history/ view instead' ); 307 308 $Result = array(); 309 $Result['content'] =& $tpl->fetch( 'design:content/versions.tpl' ); 310 $Result['path'] = array( array( 'text' => ezi18n( 'kernel/content', 'Versions' ), 311 'url' => false ) ); 312 313 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |