| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
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/ezcontentclass.php' ); 28 include_once ( 'kernel/classes/ezcontentclassattribute.php' ); 29 include_once ( 'kernel/classes/ezcontentclassclassgroup.php' ); 30 include_once ( 'lib/ezutils/classes/ezhttptool.php' ); 31 include_once ( 'lib/ezutils/classes/ezhttppersistence.php' ); 32 33 34 $Module =& $Params['Module']; 35 $ClassID = $Params['ClassID']; 36 $GroupID = $Params['GroupID']; 37 $GroupName = $Params['GroupName']; 38 $EditLanguage = $Params['Language']; 39 $FromLanguage = false; 40 $ClassVersion = null; 41 42 switch ( $Params['FunctionName'] ) 43 { 44 case 'edit': 45 { 46 } break; 47 default: 48 { 49 eZDebug::writeError( 'Undefined function: ' . $params['Function'] ); 50 $Module->setExitStatus( EZ_MODULE_STATUS_FAILED ); 51 return; 52 }; 53 } 54 55 $http =& eZHttpTool::instance(); 56 if ( $http->hasPostVariable( 'CancelConflictButton' ) ) 57 { 58 $Module->redirectToView( 'grouplist' ); 59 } 60 61 if ( $http->hasPostVariable( 'EditLanguage' ) ) 62 { 63 $EditLanguage = $http->postVariable( 'EditLanguage' ); 64 } 65 66 if ( is_numeric( $ClassID ) ) 67 { 68 $class = eZContentClass::fetch( $ClassID, true, EZ_CLASS_VERSION_STATUS_TEMPORARY ); 69 70 // If temporary version does not exist fetch the current and add temperory class to corresponding group 71 if ( !is_object( $class ) or $class->attribute( 'id' ) == null ) 72 { 73 $class = eZContentClass::fetch( $ClassID, true, EZ_CLASS_VERSION_STATUS_DEFINED ); 74 if( is_null( $class ) ) // Class does not exist 75 { 76 return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' ); 77 } 78 $classGroups= eZContentClassClassGroup::fetchGroupList( $ClassID, EZ_CLASS_VERSION_STATUS_DEFINED ); 79 foreach ( $classGroups as $classGroup ) 80 { 81 $groupID = $classGroup->attribute( 'group_id' ); 82 $groupName = $classGroup->attribute( 'group_name' ); 83 $ingroup = eZContentClassClassGroup::create( $ClassID, EZ_CLASS_VERSION_STATUS_TEMPORARY, $groupID, $groupName ); 84 $ingroup->store(); 85 } 86 } 87 else 88 { 89 include_once ( 'lib/ezlocale/classes/ezdatetime.php' ); 90 $user =& eZUser::currentUser(); 91 $contentIni =& eZIni::instance( 'content.ini' ); 92 $timeOut = $contentIni->variable( 'ClassSettings', 'DraftTimeout' ); 93 94 if ( $class->attribute( 'modifier_id' ) != $user->attribute( 'contentobject_id' ) && 95 $class->attribute( 'modified' ) + $timeOut > time() ) 96 { 97 include_once ( 'kernel/common/template.php' ); 98 $tpl =& templateInit(); 99 100 $res =& eZTemplateDesignResource::instance(); 101 $res->setKeys( array( array( 'class', $class->attribute( 'id' ) ) ) ); // Class ID 102 $tpl->setVariable( 'class', $class ); 103 $tpl->setVariable( 'lock_timeout', $timeOut ); 104 105 $Result = array(); 106 $Result['content'] =& $tpl->fetch( 'design:class/edit_denied.tpl' ); 107 $Result['path'] = array( array( 'url' => '/class/grouplist/', 108 'text' => ezi18n( 'kernel/class', 'Class list' ) ) ); 109 return $Result; 110 } 111 } 112 } 113 else 114 { 115 include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 116 117 if ( !$EditLanguage ) 118 $EditLanguage = eZContentClass::defaultLanguage(); 119 120 $user =& eZUser::currentUser(); 121 $user_id = $user->attribute( 'contentobject_id' ); 122 $class = eZContentClass::create( $user_id, array(), $EditLanguage ); 123 $class->setName( ezi18n( 'kernel/class/edit', 'New Class' ), $EditLanguage ); 124 $class->store(); 125 $editLanguageID = eZContentLanguage::idByLocale( $EditLanguage ); 126 $class->setAlwaysAvailableLanguageID( $editLanguageID ); 127 $ClassID = $class->attribute( 'id' ); 128 $ClassVersion = $class->attribute( 'version' ); 129 $ingroup = eZContentClassClassGroup::create( $ClassID, $ClassVersion, $GroupID, $GroupName ); 130 $ingroup->store(); 131 $Module->redirectTo( $Module->functionURI( 'edit' ) . '/' . $ClassID . '/(language)/' . $EditLanguage ); 132 return; 133 } 134 135 136 $contentClassHasInput = true; 137 if ( $http->hasPostVariable( 'ContentClassHasInput' ) ) 138 $contentClassHasInput = $http->postVariable( 'ContentClassHasInput' ); 139 140 // Find out the group where class is created or edited from. 141 if ( $http->hasSessionVariable( 'FromGroupID' ) ) 142 { 143 $fromGroupID = $http->sessionVariable( 'FromGroupID' ); 144 } 145 else 146 { 147 $fromGroupID = false; 148 } 149 $ClassID = $class->attribute( 'id' ); 150 $ClassVersion = $class->attribute( 'version' ); 151 152 $validation = array( 'processed' => false, 153 'groups' => array(), 154 'attributes' => array(), 155 'class_errors' => array() ); 156 $unvalidatedAttributes = array(); 157 158 if ( $http->hasPostVariable( 'DiscardButton' ) ) 159 { 160 eZSessionDestroy( $http->sessionVariable( 'CanStoreTicket' ) ); 161 $http->removeSessionVariable( 'CanStoreTicket' ); 162 $class->setVersion( EZ_CLASS_VERSION_STATUS_TEMPORARY ); 163 $class->remove( true, EZ_CLASS_VERSION_STATUS_TEMPORARY ); 164 eZContentClassClassGroup::removeClassMembers( $ClassID, EZ_CLASS_VERSION_STATUS_TEMPORARY ); 165 if ( $fromGroupID === false ) 166 { 167 $Module->redirectToView( 'grouplist' ); 168 } 169 else 170 { 171 $Module->redirectTo( $Module->functionURI( 'classlist' ) . '/' . $fromGroupID . '/' ); 172 } 173 return; 174 } 175 if ( $http->hasPostVariable( 'AddGroupButton' ) && $http->hasPostVariable( 'ContentClass_group' ) ) 176 { 177 include_once ( "kernel/class/ezclassfunctions.php" ); 178 eZClassFunctions::addGroup( $ClassID, $ClassVersion, $http->postVariable( 'ContentClass_group' ) ); 179 } 180 if ( $http->hasPostVariable( 'RemoveGroupButton' ) && $http->hasPostVariable( 'group_id_checked' ) ) 181 { 182 include_once ( "kernel/class/ezclassfunctions.php" ); 183 if ( !eZClassFunctions::removeGroup( $ClassID, $ClassVersion, $http->postVariable( 'group_id_checked' ) ) ) 184 { 185 $validation['groups'][] = array( 'text' => ezi18n( 'kernel/class', 'You have to have at least one group that the class belongs to!' ) ); 186 $validation['processed'] = true; 187 } 188 } 189 190 // Fetch attributes and definitions 191 $attributes =& $class->fetchAttributes(); 192 193 if ( $http->hasPostVariable( 'SelectLanguageButton' ) && $http->hasPostVariable( 'EditLanguage' ) ) 194 { 195 $EditLanguage = $http->postVariable( 'EditLanguage' ); 196 197 $FromLanguage = 'None'; 198 if ( $http->hasPostVariable( 'FromLanguage' ) ) 199 $FromLanguage = $http->postVariable( 'FromLanguage' ); 200 201 foreach ( array_keys( $attributes ) as $key ) 202 { 203 $name = ''; 204 if ( $FromLanguage != 'None' ) 205 { 206 $name = $attributes[$key]->name( $FromLanguage ); 207 } 208 $attributes[$key]->setName( $name, $EditLanguage ); 209 } 210 211 $name = ''; 212 if ( $FromLanguage != 'None' ) 213 { 214 $name = $class->name( $FromLanguage ); 215 } 216 217 $class->setName( $name, $EditLanguage ); 218 } 219 220 // No language was specified in the URL, we need to figure out 221 // the language to use. 222 if ( !$EditLanguage ) 223 { 224 // Check number of languages 225 include_once ( 'kernel/classes/ezcontentlanguage.php' ); 226 $languages = eZContentLanguage::fetchList(); 227 // If there is only one language we choose it for the user. 228 if ( count( $languages ) == 1 ) 229 { 230 $EditLanguage = array_shift( $languages ); 231 } 232 else 233 { 234 $canCreateLanguages = $class->attribute( 'can_create_languages' ); 235 if ( count( $canCreateLanguages ) == 0) 236 { 237 $EditLanguage = $class->attribute( 'top_priority_language_locale' ); 238 } 239 else 240 { 241 include_once ( 'kernel/common/template.php' ); 242 243 $tpl =& templateInit(); 244 245 $res =& eZTemplateDesignResource::instance(); 246 $res->setKeys( array( array( 'class', $class->attribute( 'id' ) ) ) ); // Class ID 247 248 $tpl->setVariable( 'module', $Module ); 249 $tpl->setVariable( 'class', $class ); 250 251 $Result = array(); 252 $Result['content'] =& $tpl->fetch( 'design:class/select_language.tpl' ); 253 $Result['path'] = array( array( 'url' => '/class/edit/', 254 'text' => ezi18n( 'kernel/class', 'Class edit' ) ) ); 255 return $Result; 256 } 257 } 258 } 259 260 include_once ( 'kernel/classes/ezdatatype.php' ); 261 eZDataType::loadAndRegisterAllTypes(); 262 $datatypes = eZDataType::registeredDataTypes(); 263 264 $customAction = false; 265 $customActionAttributeID = null; 266 // Check for custom actions 267 if ( $http->hasPostVariable( 'CustomActionButton' ) ) 268 { 269 $customActionArray = $http->postVariable( 'CustomActionButton' ); 270 $customActionString = key( $customActionArray ); 271 272 $customActionAttributeID = preg_match( "#^([0-9]+)_(.*)$#", $customActionString, $matchArray ); 273 274 $customActionAttributeID = $matchArray[1]; 275 $customAction = $matchArray[2]; 276 } 277 278 279 // Validate input 280 $storeActions = array( 'MoveUp', 281 'MoveDown', 282 'StoreButton', 283 'ApplyButton', 284 'NewButton', 285 'CustomActionButton'); 286 $validationRequired = false; 287 foreach( $storeActions as $storeAction ) 288 { 289 if ( $http->hasPostVariable( $storeAction ) ) 290 { 291 $validationRequired = true; 292 break; 293 } 294 } 295 296 include_once ( 'lib/ezutils/classes/ezinputvalidator.php' ); 297 $canStore = true; 298 $requireFixup = false; 299 if ( $contentClassHasInput ) 300 { 301 if ( $validationRequired ) 302 { 303 foreach ( array_keys( $attributes ) as $key ) 304 { 305 $attribute =& $attributes[$key]; 306 $dataType = $attribute->dataType(); 307 $status = $dataType->validateClassAttributeHTTPInput( $http, 'ContentClass', $attribute ); 308 if ( $status == EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE ) 309 $requireFixup = true; 310 else if ( $status == EZ_INPUT_VALIDATOR_STATE_INVALID ) 311 { 312 $canStore = false; 313 $attributeName = $dataType->attribute( 'information' ); 314 $attributeName = $attributeName['name']; 315 $unvalidatedAttributes[] = array( 'id' => $attribute->attribute( 'id' ), 316 'identifier' => $attribute->attribute( 'identifier' ) ? $attribute->attribute( 'identifier' ) : $attribute->attribute( 'name' ), 317 'name' => $attributeName ); 318 } 319 } 320 $validation['processed'] = true; 321 $validation['attributes'] = $unvalidatedAttributes; 322 $requireVariable = 'ContentAttribute_is_required_checked'; 323 $searchableVariable = 'ContentAttribute_is_searchable_checked'; 324 $informationCollectorVariable = 'ContentAttribute_is_information_collector_checked'; 325 $canTranslateVariable = 'ContentAttribute_can_translate_checked'; 326 $requireCheckedArray = array(); 327 $searchableCheckedArray = array(); 328 $informationCollectorCheckedArray = array(); 329 $canTranslateCheckedArray = array(); 330 if ( $http->hasPostVariable( $requireVariable ) ) 331 $requireCheckedArray = $http->postVariable( $requireVariable ); 332 if ( $http->hasPostVariable( $searchableVariable ) ) 333 $searchableCheckedArray = $http->postVariable( $searchableVariable ); 334 if ( $http->hasPostVariable( $informationCollectorVariable ) ) 335 $informationCollectorCheckedArray = $http->postVariable( $informationCollectorVariable ); 336 if ( $http->hasPostVariable( $canTranslateVariable ) ) 337 $canTranslateCheckedArray = $http->postVariable( $canTranslateVariable ); 338 339 if ( $http->hasPostVariable( 'ContentAttribute_priority' ) ) 340 $placementArray = $http->postVariable( 'ContentAttribute_priority' ); 341 342 foreach ( array_keys( $attributes ) as $key ) 343 { 344 $attribute =& $attributes[$key]; 345 $attributeID = $attribute->attribute( 'id' ); 346 $attribute->setAttribute( 'is_required', in_array( $attributeID, $requireCheckedArray ) ); 347 $attribute->setAttribute( 'is_searchable', in_array( $attributeID, $searchableCheckedArray ) ); 348 $attribute->setAttribute( 'is_information_collector', in_array( $attributeID, $informationCollectorCheckedArray ) ); 349 // Set can_translate to 0 if user has clicked Disable translation in GUI 350 $attribute->setAttribute( 'can_translate', !in_array( $attributeID, $canTranslateCheckedArray ) ); 351 352 $placement = (int) $placementArray[$key]; 353 if ( $attribute->attribute( 'placement' ) != $placement ) 354 $attribute->setAttribute( 'placement', $placement ); 355 } 356 } 357 } 358 359 // Fixup input 360 if ( $requireFixup ) 361 { 362 foreach( array_keys( $attributes ) as $key ) 363 { 364 $attribute =& $attributes[$key]; 365 $dataType = $attribute->dataType(); 366 $status = $dataType->fixupClassAttributeHTTPInput( $http, 'ContentClass', $attribute ); 367 } 368 } 369 370 $cur_datatype = 'ezstring'; 371 // Apply HTTP POST variables 372 if ( $contentClassHasInput ) 373 { 374 eZHTTPPersistence::fetch( 'ContentAttribute', eZContentClassAttribute::definition(), $attributes, $http, true ); 375 if ( $http->hasPostVariable( 'ContentAttribute_name' ) ) 376 { 377 $attributeNames = $http->postVariable( 'ContentAttribute_name' ); 378 foreach( array_keys( $attributes ) as $key ) 379 { 380 if ( isset( $attributeNames[$key] ) ) 381 { 382 $attributes[$key]->setName( $attributeNames[$key], $EditLanguage ); 383 } 384 } 385 } 386 387 eZHTTPPersistence::fetch( 'ContentClass', eZContentClass::definition(), $class, $http, false ); 388 if ( $http->hasPostVariable( 'ContentClass_name' ) ) 389 { 390 $class->setName( $http->postVariable( 'ContentClass_name' ), $EditLanguage ); 391 } 392 393 if ( $http->hasVariable( 'ContentClass_is_container_exists' ) ) 394 { 395 if ( $http->hasVariable( 'ContentClass_is_container_checked' ) ) 396 { 397 $class->setAttribute( "is_container", 1 ); 398 } 399 else 400 { 401 $class->setAttribute( "is_container", 0 ); 402 } 403 } 404 405 if ( $http->hasVariable( 'ContentClass_always_available_exists' ) ) 406 { 407 if ( $http->hasVariable( 'ContentClass_always_available' ) ) 408 { 409 $class->setAttribute( 'always_available', 1 ); 410 } 411 else 412 { 413 $class->setAttribute( 'always_available', 0 ); 414 } 415 } 416 417 if ( $http->hasVariable( 'ContentClass_default_sorting_exists' ) ) 418 { 419 if ( $http->hasVariable( 'ContentClass_default_sorting_field' ) ) 420 { 421 $sortingField = $http->variable( 'ContentClass_default_sorting_field' ); 422 $class->setAttribute( 'sort_field', $sortingField ); 423 } 424 if ( $http->hasVariable( 'ContentClass_default_sorting_order' ) ) 425 { 426 $sortingOrder = $http->variable( 'ContentClass_default_sorting_order' ); 427 $class->setAttribute( 'sort_order', $sortingOrder ); 428 } 429 } 430 431 if ( $http->hasPostVariable( 'DataTypeString' ) ) 432 $cur_datatype = $http->postVariable( 'DataTypeString' ); 433 } 434 435 $class->setAttribute( 'version', EZ_CLASS_VERSION_STATUS_TEMPORARY ); 436 $class->NameList->setHasDirtyData(); 437 438 include_once ( 'lib/ezi18n/classes/ezchartransform.php' ); 439 $trans =& eZCharTransform::instance(); 440 441 // Fixed identifiers to only contain a-z0-9_ 442 foreach( array_keys( $attributes ) as $key ) 443 { 444 $attribute =& $attributes[$key]; 445 $attribute->setAttribute( 'version', EZ_CLASS_VERSION_STATUS_TEMPORARY ); 446 $identifier = $attribute->attribute( 'identifier' ); 447 if ( $identifier == '' ) 448 $identifier = $attribute->attribute( 'name' ); 449 450 $identifier = $trans->transformByGroup( $identifier, 'identifier' ); 451 $attribute->setAttribute( 'identifier', $identifier ); 452 if ( $dataType = $attribute->dataType() ) 453 { 454 $dataType->initializeClassAttribute( $attribute ); 455 } 456 } 457 458 // Fixed class identifier to only contain a-z0-9_ 459 $identifier = $class->attribute( 'identifier' ); 460 if ( $identifier == '' ) 461 $identifier = $class->attribute( 'name' ); 462 $identifier = $trans->transformByGroup( $identifier, 'identifier' ); 463 $class->setAttribute( 'identifier', $identifier ); 464 465 // Run custom actions if any 466 if ( $customAction ) 467 { 468 foreach( array_keys( $attributes ) as $key ) 469 { 470 $attribute =& $attributes[$key]; 471 if ( $customActionAttributeID == $attribute->attribute( 'id' ) ) 472 { 473 $attribute->customHTTPAction( $Module, $http, $customAction ); 474 } 475 } 476 } 477 // Set new modification date 478 $date_time = time(); 479 $class->setAttribute( 'modified', $date_time ); 480 include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 481 $user =& eZUser::currentUser(); 482 $user_id = $user->attribute( 'contentobject_id' ); 483 $class->setAttribute( 'modifier_id', $user_id ); 484 485 // Remove attributes which are to be deleted 486 if ( $http->hasPostVariable( 'RemoveButton' ) ) 487 { 488 $validation['processed'] = true; 489 if ( eZHttpPersistence::splitSelected( 'ContentAttribute', $attributes, 490 $http, 'id', 491 $keepers, $rejects ) ) 492 { 493 $attributes = $keepers; 494 foreach ( $rejects as $reject ) 495 { 496 $dataType = $reject->dataType(); 497 if ( $dataType->isClassAttributeRemovable( $reject ) ) 498 { 499 $reject->remove(); 500 } 501 else 502 { 503 $removeInfo = $dataType->classAttributeRemovableInformation( $reject ); 504 if ( $removeInfo !== false ) 505 { 506 $validation['attributes'] = array( array( 'id' => $reject->attribute( 'id' ), 507 'identifier' => $reject->attribute( 'identifier' ), 508 'reason' => $removeInfo ) ); 509 } 510 } 511 } 512 } 513 } 514 515 // Fetch HTTP input 516 $datatypeValidation = array(); 517 if ( $contentClassHasInput ) 518 { 519 foreach( array_keys( $attributes ) as $key ) 520 { 521 $attribute =& $attributes[$key]; 522 if ( $dataType = $attribute->dataType() ) 523 { 524 $dataType->fetchClassAttributeHTTPInput( $http, 'ContentClass', $attribute ); 525 } 526 else 527 { 528 $datatypeValidation['processed'] = 1; 529 $datatypeValidation['attributes'][] = 530 array( 'reason' => array( 'text' => ezi18n( 'kernel/class', 'Could not load datatype: ' ). 531 $attribute->attribute( 'data_type_string' )."\n". 532 ezi18n( 'kernel/class', 'Editing this content class may cause data corruption in your system.' ).'<br>'. 533 ezi18n( 'kernel/class', 'Press "Cancel" to safely exit this operation.').'<br>'. 534 ezi18n( 'kernel/class', 'Please contact your eZ publish administrator to solve this problem.').'<br>' ), 535 'item' => $attribute->attribute( 'data_type_string' ), 536 'identifier' => $attribute->attribute( 'data_type_string' ), 537 'id' => $key ); 538 } 539 } 540 } 541 542 if ( $validationRequired ) 543 { 544 // check for duplicate attribute identifiers in the input 545 if ( count( $attributes ) > 1 ) 546 { 547 for( $attrIndex = 0; $attrIndex < count( $attributes ) - 1; $attrIndex++ ) 548 { 549 $classAttribute = $attributes[$attrIndex]; 550 $identifier = $classAttribute->attribute( 'identifier' ); 551 $placement = $classAttribute->attribute( 'placement' ); 552 for ( $attrIndex2 = $attrIndex + 1; $attrIndex2 < count( $attributes ); $attrIndex2++ ) 553 { 554 $classAttribute2 = $attributes[$attrIndex2]; 555 $identifier2 = $classAttribute2->attribute( 'identifier' ); 556 $placement2 = $classAttribute2->attribute( 'placement' ); 557 if ( $placement == $placement2 ) 558 { 559 $validation['attributes'][] = array( 'identifier' => $identifier2, 560 'name' => $classAttribute2->attribute( 'name' ), 561 'id' => $classAttribute2->attribute( 'id' ), 562 'reason' => array ( 'text' => ezi18n( 'kernel/class', 'duplicate attribute placement' ) ) ); 563 $canStore = false; 564 break; 565 } 566 567 if ( $identifier == $identifier2 ) 568 { 569 $validation['attributes'][] = array( 'identifier' => $identifier, 570 'name' => $classAttribute->attribute( 'name' ), 571 'id' => $classAttribute->attribute( 'id' ), 572 'reason' => array ( 'text' => ezi18n( 'kernel/class', 'duplicate attribute identifier' ) ) ); 573 $canStore = false; 574 break; 575 } 576 } 577 } 578 } 579 } 580 581 // Store version 0 and discard version 1 582 if ( $http->hasPostVariable( 'StoreButton' ) && $canStore ) 583 { 584 585 $id = $class->attribute( 'id' ); 586 $oldClassAttributes = $class->fetchAttributes( $id, true, EZ_CLASS_VERSION_STATUS_DEFINED ); 587 $newClassAttributes = $class->fetchAttributes( ); 588 589 // validate class name and identifier; check presence of class attributes 590 // FIXME: object pattern name is never validated 591 592 $basicClassPropertiesValid = true; 593 { 594 $className =& $class->attribute( 'name' ); 595 $classIdentifier =& $class->attribute( 'identifier' ); 596 $classID =& $class->attribute( 'id' ); 597 598 // validate class name 599 if( trim( $className ) == '' ) 600 { 601 $validation['class_errors'][] = array( 'text' => ezi18n( 'kernel/class', 'The class should have nonempty \'Name\' attribute.' ) ); 602 $basicClassPropertiesValid = false; 603 } 604 605 // check presence of attributes 606 $newClassAttributes = $class->fetchAttributes( ); 607 if ( count( $newClassAttributes ) == 0 ) 608 { 609 $validation['class_errors'][] = array( 'text' => ezi18n( 'kernel/class', 'The class should have at least one attribute.' ) ); 610 $basicClassPropertiesValid = false; 611 } 612 613 // validate class identifier 614 615 $db =& eZDB::instance(); 616 $classCount = $db->arrayQuery( "SELECT COUNT(*) AS count FROM ezcontentclass WHERE identifier='$classIdentifier' AND version=" . EZ_CLASS_VERSION_STATUS_DEFINED . " AND id <> $classID" ); 617 if ( $classCount[0]['count'] > 0 ) 618 { 619 $validation['class_errors'][] = array( 'text' => ezi18n( 'kernel/class', 'There is a class already having the same identifier.' ) ); 620 $basicClassPropertiesValid = false; 621 } 622 unset( $classList ); 623 unset( $db ); 624 } 625 626 if ( !$basicClassPropertiesValid ) 627 { 628 $canStore = false; 629 $validation['processed'] = false; 630 } 631 else 632 { 633 $firstStoreAttempt =& eZSessionRead( $http->sessionVariable( 'CanStoreTicket' ) ); 634 if ( !$firstStoreAttempt ) 635 { 636 return $Module->redirectToView( 'view', array( $ClassID ), array( 'Language' => $EditLanguage ) ); 637 } 638 eZSessionDestroy( $http->sessionVariable( 'CanStoreTicket' ) ); 639 640 // Class cleanup, update existing class objects according to new changes 641 include_once ( 'kernel/classes/ezcontentobject.php' ); 642 643 $db =& eZDB::instance(); 644 $db->begin(); 645 646 $objects = null; 647 $objectCount = eZContentObject::fetchSameClassListCount( $ClassID ); 648 if ( $objectCount > 0 ) 649 { 650 // Delete object attributes which have been removed. 651 foreach ( $oldClassAttributes as $oldClassAttribute ) 652 { 653 $attributeExist = false; 654 $oldClassAttributeID = $oldClassAttribute->attribute( 'id' ); 655 foreach ( $newClassAttributes as $newClassAttribute ) 656 { 657 $newClassAttributeID = $newClassAttribute->attribute( 'id' ); 658 if ( $oldClassAttributeID == $newClassAttributeID ) 659 $attributeExist = true; 660 } 661 if ( !$attributeExist ) 662 { 663 $objectAttributes = eZContentObjectAttribute::fetchSameClassAttributeIDList( $oldClassAttributeID ); 664 foreach ( $objectAttributes as $objectAttribute ) 665 { 666 $objectAttributeID = $objectAttribute->attribute( 'id' ); 667 $objectAttribute->remove( $objectAttributeID ); 668 } 669 } 670 } 671 $class->storeDefined( $attributes ); 672 673 // Add object attributes which have been added. 674 foreach ( $newClassAttributes as $newClassAttribute ) 675 { 676 $attributeExist = false; 677 $newClassAttributeID = $newClassAttribute->attribute( 'id' ); 678 foreach ( $oldClassAttributes as $oldClassAttribute ) 679 { 680 $oldClassAttributeID = $oldClassAttribute->attribute( 'id' ); 681 if ( $oldClassAttributeID == $newClassAttributeID ) 682 $attributeExist = true; 683 } 684 if ( !$attributeExist ) 685 { 686 if ( $objects == null ) 687 { 688 $objects = eZContentObject::fetchSameClassList( $ClassID ); 689 } 690 foreach ( $objects as $object ) 691 { 692 $contentobjectID = $object->attribute( 'id' ); 693 $objectVersions =& $object->versions(); 694 foreach ( $objectVersions as $objectVersion ) 695 { 696 $translations = $objectVersion->translations( false ); 697 $version = $objectVersion->attribute( 'version' ); 698 foreach ( $translations as $translation ) 699 { 700 $objectAttribute = eZContentObjectAttribute::create( $newClassAttributeID, $contentobjectID, $version ); 701 $objectAttribute->setAttribute( 'language_code', $translation ); 702 $objectAttribute->initialize(); 703 $objectAttribute->store(); 704 $objectAttribute->postInitialize(); 705 } 706 } 707 } 708 } 709 } 710 } 711 else 712 { 713 $class->storeDefined( $attributes ); 714 } 715 716 $db->commit(); 717 718 $http->removeSessionVariable( 'CanStoreTicket' ); 719 return $Module->redirectToView( 'view', array( $ClassID ), array( 'Language' => $EditLanguage ) ); 720 } 721 } 722 723 // Store changes 724 if ( $canStore ) 725 $class->store( $attributes ); 726 727 if ( $http->hasPostVariable( 'NewButton' ) ) 728 { 729 $new_attribute = eZContentClassAttribute::create( $ClassID, $cur_datatype, array(), $EditLanguage ); 730 $attrcnt = count( $attributes ) + 1; 731 $new_attribute->setName( ezi18n( 'kernel/class/edit', 'new attribute' ) . $attrcnt, $EditLanguage ); 732 $dataType = $new_attribute->dataType(); 733 $dataType->initializeClassAttribute( $new_attribute ); 734 $new_attribute->store(); 735 $attributes[] =& $new_attribute; 736 } 737 else if ( $http->hasPostVariable( 'MoveUp' ) ) 738 { 739 $attribute =& eZContentClassAttribute::fetch( $http->postVariable( 'MoveUp' ), true, EZ_CLASS_VERSION_STATUS_TEMPORARY, 740 array( 'contentclass_id', 'version', 'placement' ) ); 741 $attribute->move( false ); 742 $Module->redirectTo( $Module->functionURI( 'edit' ) . '/' . $ClassID . '/(language)/' . $EditLanguage ); 743 return; 744 } 745 else if ( $http->hasPostVariable( 'MoveDown' ) ) 746 { 747 $attribute =& eZContentClassAttribute::fetch( $http->postVariable( 'MoveDown' ), true, EZ_CLASS_VERSION_STATUS_TEMPORARY, 748 array( 'contentclass_id', 'version', 'placement' ) ); 749 $attribute->move( true ); 750 $Module->redirectTo( $Module->functionURI( 'edit' ) . '/' . $ClassID . '/(language)/' . $EditLanguage ); 751 return; 752 } 753 754 $Module->setTitle( 'Edit class ' . $class->attribute( 'name' ) ); 755 if ( !$http->hasSessionVariable( 'CanStoreTicket' ) ) 756 { 757 $http->setSessionVariable( 'CanStoreTicket', md5( (string)rand() ) ); 758 eZSessionWrite( $http->sessionVariable( 'CanStoreTicket' ), 1 ); 759 } 760 761 // Fetch updated attributes 762 $attributes = $class->fetchAttributes(); 763 $validation = array_merge( $validation, $datatypeValidation ); 764 765 // Template handling 766 include_once ( 'kernel/common/template.php' ); 767 $tpl =& templateInit(); 768 $res =& eZTemplateDesignResource::instance(); 769 $res->setKeys( array( array( 'class', $class->attribute( 'id' ) ) ) ); // Class ID 770 $tpl->setVariable( 'http', $http ); 771 $tpl->setVariable( 'validation', $validation ); 772 $tpl->setVariable( 'can_store', $canStore ); 773 $tpl->setVariable( 'require_fixup', $requireFixup ); 774 $tpl->setVariable( 'module', $Module ); 775 $tpl->setVariable( 'class', $class ); 776 $tpl->setVariable( 'attributes', $attributes ); 777 $tpl->setVariable( 'datatypes', $datatypes ); 778 $tpl->setVariable( 'datatype', $cur_datatype ); 779 $tpl->setVariable( 'language_code', $EditLanguage ); 780 781 $Result = array(); 782 $Result['content'] =& $tpl->fetch( 'design:class/edit.tpl' ); 783 $Result['path'] = array( array( 'url' => '/class/edit/', 784 'text' => ezi18n( 'kernel/class', 'Class edit' ) ) ); 785 786 ?>
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 |