[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Created on: <21-Nov-2002 18:27:06 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/ezinformationcollection.php' );
  28  include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
  29  include_once ( "lib/ezdb/classes/ezdb.php" );
  30  include_once ( 'lib/ezutils/classes/ezmail.php' );
  31  include_once ( 'lib/ezutils/classes/ezmailtransport.php' );
  32  include_once ( 'kernel/common/template.php' );
  33  
  34  $Module =& $Params['Module'];
  35  $http =& eZHTTPTool::instance();
  36  
  37  if ( $Module->isCurrentAction( 'CollectInformation' ) )
  38  {
  39      $ObjectID = $Module->actionParameter( 'ContentObjectID' );
  40      $NodeID = $Module->actionParameter( 'ContentNodeID' );
  41      $ViewMode = 'full';
  42      if ( $Module->hasActionParameter( 'ViewMode' ) )
  43          $ViewMode = $Module->actionParameter( 'ViewMode' );
  44  
  45      $object =& eZContentObject::fetch( $ObjectID );
  46      if ( !$object )
  47          return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
  48      if ( !$object->attribute( 'can_read' ) )
  49          return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
  50      $version =& $object->currentVersion();
  51      $contentObjectAttributes =& $version->contentObjectAttributes();
  52  
  53      $user =& eZUser::currentUser();
  54      $isLoggedIn = $user->attribute( 'is_logged_in' );
  55      $allowAnonymous = true;
  56      if ( !$isLoggedIn )
  57      {
  58          $allowAnonymous = eZInformationCollection::allowAnonymous( $object );
  59      }
  60  
  61      $newCollection = false;
  62      $collection = false;
  63      $userDataHandling = eZInformationCollection::userDataHandling( $object );
  64      if ( $userDataHandling == 'unique' or
  65           $userDataHandling == 'overwrite'  )
  66          $collection = eZInformationCollection::fetchByUserIdentifier( eZInformationCollection::currentUserIdentifier(), $object->attribute( 'id' ) );
  67      if ( ( !$isLoggedIn and
  68             !$allowAnonymous ) or
  69           ( $userDataHandling == 'unique' and
  70             $collection ) )
  71      {
  72          $tpl =& templateInit();
  73  
  74          $attributeHideList = eZInformationCollection::attributeHideList();
  75          $informationCollectionTemplate = eZInformationCollection::templateForObject( $object );
  76  
  77          $node = eZContentObjectTreeNode::fetch( $NodeID );
  78  
  79          $collectionID = false;
  80          if ( $collection )
  81              $collectionID = $collection->attribute( 'id' );
  82  
  83          $tpl->setVariable( 'node_id', $node->attribute( 'node_id' ) );
  84          $tpl->setVariable( 'collection_id', $collectionID );
  85          $tpl->setVariable( 'collection', $collection );
  86          $tpl->setVariable( 'node', $node );
  87          $tpl->setVariable( 'object', $object );
  88          $tpl->setVariable( 'attribute_hide_list', $attributeHideList );
  89          $tpl->setVariable( 'error', true );
  90          $tpl->setVariable( 'error_existing_data', ( $userDataHandling == 'unique' and $collection ) );
  91          $tpl->setVariable( 'error_anonymous_user', ( !$isLoggedIn and !$allowAnonymous ) );
  92  
  93          $section = eZSection::fetch( $object->attribute( 'section_id' ) );
  94          if ( $section )
  95              $navigationPartIdentifier = $section->attribute( 'navigation_part_identifier' );
  96  
  97          $res =& eZTemplateDesignResource::instance();
  98          $res->setKeys( array( array( 'object', $object->attribute( 'id' ) ),
  99                                array( 'node', $node->attribute( 'node_id' ) ),
 100                                array( 'parent_node', $node->attribute( 'parent_node_id' ) ),
 101                                array( 'class', $object->attribute( 'contentclass_id' ) ),
 102                                array( 'class_identifier', $object->attribute( 'class_identifier' ) ),
 103                                array( 'navigation_part_identifier', $navigationPartIdentifier ),
 104                                array( 'depth', $node->attribute( 'depth' ) ),
 105                                array( 'url_alias', $node->attribute( 'url_alias' ) )
 106                                ) );
 107  
 108          $Result['content'] =& $tpl->fetch( 'design:content/collectedinfo/' . $informationCollectionTemplate . '.tpl' );
 109  
 110          $title = $object->attribute( 'name' );
 111          if ( $tpl->hasVariable( 'title' ) )
 112              $title = $tpl->variable( 'title' );
 113  
 114          // create path
 115          $parents =& $node->attribute( 'path' );
 116  
 117          $path = array();
 118          $titlePath = array();
 119          foreach ( $parents as $parent )
 120          {
 121              $path[] = array( 'text' => $parent->attribute( 'name' ),
 122                               'url' => '/content/view/full/' . $parent->attribute( 'node_id' ),
 123                               'url_alias' => $parent->attribute( 'url_alias' ),
 124                               'node_id' => $parent->attribute( 'node_id' )
 125                               );
 126          }
 127          $path[] = array( 'text' => $object->attribute( 'name' ),
 128                           'url' => '/content/view/full/' . $node->attribute( 'node_id' ),
 129                           'url_alias' => $node->attribute( 'url_alias' ),
 130                           'node_id' => $node->attribute( 'node_id' ) );
 131  
 132          array_shift( $parents );
 133          foreach ( $parents as $parent )
 134          {
 135              $titlePath[] = array( 'text' => $parent->attribute( 'name' ),
 136                                    'url' => '/content/view/full/' . $parent->attribute( 'node_id' ),
 137                                    'url_alias' => $parent->attribute( 'url_alias' ),
 138                                    'node_id' => $parent->attribute( 'node_id' )
 139                                    );
 140          }
 141          $titlePath[] = array( 'text' => $title,
 142                                'url' => '/content/view/full/' . $node->attribute( 'node_id' ),
 143                                'url_alias' => $node->attribute( 'url_alias' ),
 144                                'node_id' => $node->attribute( 'node_id' ) );
 145  
 146          $Result['path'] =& $path;
 147          $Result['title_path'] =& $titlePath;
 148  
 149          return $Result;
 150      }
 151      if ( !$collection )
 152      {
 153          $collection = eZInformationCollection::create( $ObjectID, eZInformationCollection::currentUserIdentifier() );
 154          $collection->store();
 155          $newCollection = true;
 156      }
 157      else
 158          $collection->setAttribute( 'modified', time() );
 159  
 160  
 161      // Check every attribute if it's supposed to collect information
 162      $attributeDataBaseName = 'ContentObjectAttribute';
 163      $unvalidatedAttributes = array();
 164      $canCollect = true;
 165      $requireFixup = false;
 166      foreach ( array_keys( $contentObjectAttributes ) as $key )
 167      {
 168          $contentObjectAttribute = $contentObjectAttributes[$key];
 169          $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
 170  
 171          if ( $contentClassAttribute->attribute( 'is_information_collector' ) )
 172          {
 173              $inputParameters = null;
 174              $status = $contentObjectAttribute->validateInformation( $http, $attributeDataBaseName, $inputParameters );
 175              if ( $status == EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE )
 176                  $requireFixup = true;
 177              else if ( $status == EZ_INPUT_VALIDATOR_STATE_INVALID )
 178              {
 179                  $canCollect = false;
 180                  $description = $contentObjectAttribute->attribute( 'validation_error' );
 181                  $hasValidationError = $contentObjectAttribute->attribute( 'has_validation_error' );
 182                  if ( $hasValidationError )
 183                  {
 184                      if ( !$description )
 185                          $description = false;
 186                      $validationName = $contentClassAttribute->attribute( 'name' );
 187                      $unvalidatedAttributes[] = array( 'id' => $contentObjectAttribute->attribute( 'id' ),
 188                                                        'identifier' => $contentClassAttribute->attribute( 'identifier' ),
 189                                                        'name' => $validationName,
 190                                                        'description' => $description );
 191                  }
 192              }
 193              else if ( $status == EZ_INPUT_VALIDATOR_STATE_ACCEPTED )
 194              {
 195              }
 196          }
 197      }
 198      $collectionAttributes = array();
 199  
 200      $db =& eZDB::instance();
 201      $db->begin();
 202  
 203      foreach ( array_keys( $contentObjectAttributes ) as $key )
 204      {
 205          $contentObjectAttribute = $contentObjectAttributes[$key];
 206          $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
 207  
 208          if ( $contentClassAttribute->attribute( 'is_information_collector' ) )
 209          {
 210              // Collect the information for the current attribute
 211              if ( $newCollection )
 212                  $collectionAttribute = eZInformationCollectionAttribute::create( $collection->attribute( 'id' ) );
 213              else
 214                  $collectionAttribute = eZInformationCollectionAttribute::fetchByObjectAttributeID( $collection->attribute( 'id' ), $contentObjectAttribute->attribute( 'id' ) );
 215              if ( $collectionAttribute and $contentObjectAttribute->collectInformation( $collection, $collectionAttribute, $http, "ContentObjectAttribute" ) )
 216              {
 217                  if ( $canCollect )
 218                  {
 219                      $collectionAttribute->store();
 220                  }
 221              }
 222              else
 223              {
 224              }
 225              $collectionAttributes[$contentObjectAttribute->attribute( 'id' )] = $collectionAttribute;
 226          }
 227      }
 228      $db->commit();
 229  
 230      if ( $canCollect )
 231      {
 232          $collection->sync();
 233  
 234          $sendEmail = eZInformationCollection::sendOutEmail( $object );
 235          $redirectToNodeID = false;
 236  
 237          if ( $sendEmail )
 238          {
 239              $tpl =& templateInit();
 240  
 241              $attributeHideList = eZInformationCollection::attributeHideList();
 242              $informationCollectionTemplate = eZInformationCollection::templateForObject( $object );
 243  
 244              $node = eZContentObjectTreeNode::fetch( $NodeID );
 245  
 246              $section = eZSection::fetch( $object->attribute( 'section_id' ) );
 247              if ( $section )
 248                  $navigationPartIdentifier = $section->attribute( 'navigation_part_identifier' );
 249  
 250              $res =& eZTemplateDesignResource::instance();
 251              $res->setKeys( array( array( 'object', $object->attribute( 'id' ) ),
 252                                    array( 'node', $node->attribute( 'node_id' ) ),
 253                                    array( 'parent_node', $node->attribute( 'parent_node_id' ) ),
 254                                    array( 'class', $object->attribute( 'contentclass_id' ) ),
 255                                    array( 'class_identifier', $object->attribute( 'class_identifier' ) ),
 256                                    array( 'navigation_part_identifier', $navigationPartIdentifier ),
 257                                    array( 'depth', $node->attribute( 'depth' ) ),
 258                                    array( 'url_alias', $node->attribute( 'url_alias' ) )
 259                                    ) );
 260  
 261              $tpl->setVariable( 'node_id', $node->attribute( 'node_id' ) );
 262              $tpl->setVariable( 'collection_id', $collection->attribute( 'id' ) );
 263              $tpl->setVariable( 'collection', $collection );
 264              $tpl->setVariable( 'node', $node );
 265              $tpl->setVariable( 'object', $object );
 266              $tpl->setVariable( 'attribute_hide_list', $attributeHideList );
 267  
 268              $tpl->setVariable( 'collection', $collection );
 269              $tpl->setVariable( 'object', $object );
 270              $templateResult =& $tpl->fetch( 'design:content/collectedinfomail/' . $informationCollectionTemplate . '.tpl' );
 271  
 272              $subject =& $tpl->variable( 'subject' );
 273              $receiver =& $tpl->variable( 'email_receiver' );
 274              $ccReceivers =& $tpl->variable( 'email_cc_receivers' );
 275              $bccReceivers =& $tpl->variable( 'email_bcc_receivers' );
 276              $sender =& $tpl->variable( 'email_sender' );
 277              $redirectToNodeID =& $tpl->variable( 'redirect_to_node_id' );
 278  
 279              $ini =& eZINI::instance();
 280              $mail = new eZMail();
 281  
 282              if ( !$mail->validate( $receiver ) )
 283              {
 284                  $receiver = $ini->variable( "InformationCollectionSettings", "EmailReceiver" );
 285                  if ( !$receiver )
 286                      $receiver = $ini->variable( "MailSettings", "AdminEmail" );
 287              }
 288              $mail->setReceiver( $receiver );
 289  
 290              if ( !$mail->validate( $sender ) )
 291              {
 292                  $sender = $ini->variable( "MailSettings", "EmailSender" );
 293              }
 294              $mail->setSender( $sender );
 295              $mail->setReplyTo( $sender );
 296  
 297              // Handle CC recipients
 298              if ( $ccReceivers )
 299              {
 300                  if ( !is_array( $ccReceivers ) )
 301                      $ccReceivers = array( $ccReceivers );
 302                  foreach ( $ccReceivers as $ccReceiver )
 303                  {
 304                      if ( $mail->validate( $ccReceiver ) )
 305                          $mail->addCc( $ccReceiver );
 306                  }
 307              }
 308  
 309              // Handle BCC recipients
 310              if ( $bccReceivers )
 311              {
 312                  if ( !is_array( $bccReceivers ) )
 313                      $bccReceivers = array( $bccReceivers );
 314  
 315                  foreach ( $bccReceivers as $bccReceiver )
 316                  {
 317                      if ( $mail->validate( $bccReceiver ) )
 318                          $mail->addBcc( $bccReceiver );
 319                  }
 320              }
 321  
 322              $mail->setSubject( $subject );
 323              $mail->setBody( $templateResult );
 324              $mailResult = eZMailTransport::send( $mail );
 325          }
 326  
 327          $icMap = array();
 328          if ( eZHTTPTool::hasSessionVariable( 'InformationCollectionMap' ) )
 329              $icMap = eZHTTPTool::sessionVariable( 'InformationCollectionMap' );
 330          $icMap[$object->attribute( 'id' )] = $collection->attribute( 'id' );
 331          eZHTTPTool::setSessionVariable( 'InformationCollectionMap', $icMap );
 332  
 333          if ( is_numeric( $redirectToNodeID ) )
 334          {
 335              $Module->redirectToView( 'view', array( 'full', $redirectToNodeID ) );
 336          }
 337          else
 338          {
 339              $display = eZInformationCollection::displayHandling( $object );
 340              if ( $display == 'node' )
 341              {
 342                  $Module->redirectToView( 'view', array( $ViewMode, $NodeID ) );
 343              }
 344              else if ( $display == 'redirect' )
 345              {
 346                  $redirectURL = eZInformationCollection::redirectURL( $object );
 347                  $Module->redirectTo( $redirectURL );
 348              }
 349              else
 350              {
 351                  $Module->redirectToView( 'collectedinfo', array( $NodeID ) );
 352              }
 353          }
 354      }
 355      else
 356      {
 357          $collection->remove();
 358  
 359          return $Module->run( 'view', array( $ViewMode, $NodeID ),
 360                               array( 'ViewCache' => false,
 361                                      'AttributeValidation' => array( 'processed' => true,
 362                                                                      'attributes' => $unvalidatedAttributes ),
 363                                      'CollectionAttributes' => $collectionAttributes ) );
 364      }
 365  
 366      return EZ_MODULE_HOOK_STATUS_CANCEL_RUN;
 367  }
 368  
 369  ?>


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