[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/com_vtiger_workflow/tasks/ -> VTSendNotificationTask.inc (source)

   1  <?php
   2  /*+**********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ************************************************************************************/
  10  
  11  require_once ('modules/com_vtiger_workflow/tasks/VTEmailTask.inc');
  12  
  13  class VTSendNotificationTask extends VTEmailTask {
  14  
  15  	public function doTask($entity) {
  16          global $adb, $current_user;
  17          $util = new VTWorkflowUtils();
  18          $admin = $util->adminUser();
  19          $module = $entity->getModuleName();
  20  
  21          $taskContents = Zend_Json::decode($this->getContents($entity));
  22          $fromEmail    = $taskContents['fromEmail'];
  23          $fromName    = $taskContents['fromName'];
  24          $toEmail    = $taskContents['toEmail'];
  25          $cc            = $taskContents['ccEmail'];
  26          $bcc        = $taskContents['bccEmail'];
  27          $subject    = $taskContents['subject'];
  28          $content    = $taskContents['content'];
  29  
  30          //Storing the details of emails
  31          $entityIdDetails = vtws_getIdComponents($entity->getId());
  32          $entityId = $entityIdDetails[1];
  33          $moduleName = 'Emails';
  34          $userId = $current_user->id;
  35          $emailFocus = CRMEntity::getInstance($moduleName);
  36          $dateTime = new DateTimeField(null);
  37          $emailFieldValues = array(
  38                  'assigned_user_id' => $userId,
  39                  'subject' => $subject,
  40                  'description' => $content,
  41                  'from_email' => $fromEmail,
  42                  'saved_toid' => $toEmail,
  43                  'ccmail' => $cc,
  44                  'bccmail' => $bcc,
  45                  'parent_id' => $entityId."@$userId|",
  46                  'email_flag' => 'SENT',
  47                  'activitytype' => $moduleName,
  48                  'date_start' => date($dateTime->getDisplayDate($current_user)),
  49                  'time_start' => date($dateTime->getDisplayTime($current_user)),
  50                  'mode' => '',
  51                  'id' => ''
  52          );
  53          $emailFocus->column_fields = $emailFieldValues;
  54          $emailFocus->save($moduleName);
  55  
  56          //Including email tracking details
  57          global $site_URL, $application_unique_key;
  58          $emailId = $emailFocus->id;
  59          $trackURL = "$site_URL/modules/Emails/TrackAccess.php?record=$entityId&mailid=$emailId&app_key=$application_unique_key";
  60          $content = "<img src='$trackURL' alt='' width='1' height='1'>$content";
  61  
  62          if (stripos($content, '<img src="cid:logo" />')) {
  63              $logo = 1;
  64          }
  65  
  66          $status = send_mail($module, $toEmail, $fromName, $fromEmail, $subject, $content, $cc, $bcc, '', '', $logo);
  67  
  68          if(!empty($emailId)) {
  69              $emailFocus->setEmailAccessCountValue($emailId);
  70          }
  71          if(!$status) {
  72              //If mail is not sent then removing the details about email
  73              $emailFocus->trash($moduleName, $emailId);
  74          }
  75  
  76          $util->revertUser();
  77      }
  78  
  79      /**
  80       * Function to get contents of this task
  81       * @param <Object> $entity
  82       * @return <Array> contents
  83       */
  84  	public function getContents($entity, $entityCache=false) {
  85          if (!$this->contents) {
  86              $util = new VTWorkflowUtils();
  87              $admin = $util->adminUser();
  88              $entityCache = new VTEntityCache($admin);
  89  
  90              $entityOwnerId = $entity->get('assigned_user_id');
  91              $entityId = $entity->getId();
  92              $entity = $entityCache->forId($entityId);
  93  
  94              list($referenceEntityId, $ownerId) = vtws_getIdComponents($entityOwnerId);
  95  
  96              $referenceEntity = $entityCache->forId($entityOwnerId);
  97              if($referenceEntity->getModuleName() === 'Groups') {
  98                  require_once ('include/utils/GetGroupUsers.php');
  99  
 100                  $groupModel = new GetGroupUsers();
 101                  $groupModel->getAllUsersInGroup($ownerId);
 102                  $usersList = $groupModel->group_users;
 103                  if ($usersList) {
 104                      $ownerId = $usersList[0];
 105                  }
 106              }
 107              if ($ownerId) {
 108                  $ownerFocus = CRMEntity::getInstance('Users');
 109                  $ownerFocus->retrieve_entity_info($ownerId, 'Users');
 110  
 111                  $dateTime = new DateTimeField($entity->get('date_start') .' '. $entity->get('time_start'));
 112                  $entity->set('date_start', $dateTime->getDisplayDate($ownerFocus));
 113                  $entity->set('time_start', $dateTime->getDisplayTime($ownerFocus));
 114  
 115                  $dateTime = new DateTimeField($entity->get('due_date') .' '. $entity->get('time_end'));
 116                  $entity->set('due_date', $dateTime->getDisplayDate($ownerFocus));
 117                  $entity->set('time_end', $dateTime->getDisplayTime($ownerFocus));
 118              }
 119              $entityCache->cache[$entityId] = $entity;
 120              $this->contents = parent::getContents($entity, $entityCache);
 121              $util->revertUser();
 122          }
 123          return $this->contents;
 124      }
 125  }
 126  
 127  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1