예제 #1
0
 /**
  * Register a subscription event.  Create a new contact if one does not
  * already exist.
  *
  * @param int $domain_id        The domain id of the new subscription
  * @param int $group_id         The group id to subscribe to
  * @param string $email         The email address of the (new) contact
  * @return int|null $se_id      The id of the subscription event, null on failure
  * @access public
  * @static
  */
 function &subscribe($domain_id, $group_id, $email)
 {
     /* First, find out if the contact already exists */
     $params = array('email' => $email, 'domain_id' => $domain_id);
     require_once 'CRM/Core/BAO/UFGroup.php';
     $contact_id = CRM_Core_BAO_UFGroup::findContact($params);
     CRM_Core_DAO::transaction('BEGIN');
     if (is_a($contact_id, CRM_Core_Error)) {
         require_once 'CRM/Core/BAO/LocationType.php';
         /* If the contact does not exist, create one. */
         $formatted = array('contact_type' => 'Individual');
         $value = array('email' => $email, 'location_type' => CRM_Core_BAO_LocationType::getDefaultID());
         _crm_add_formatted_param($value, $formatted);
         $contact =& crm_create_contact_formatted($formatted, CRM_IMPORT_PARSER_DUPLICATE_SKIP);
         if (is_a($contact, CRM_Core_Error)) {
             return null;
         }
         $contact_id = $contact->id;
     }
     require_once 'CRM/Core/BAO/Email.php';
     require_once 'CRM/Core/BAO/Location.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     /* Get the primary email id from the contact to use as a hash input */
     $dao =& new CRM_Core_DAO();
     $emailTable = CRM_Core_BAO_Email::getTableName();
     $locTable = CRM_Core_BAO_Location::getTableName();
     $contactTable = CRM_Contact_BAO_Contact::getTableName();
     $dao->query("SELECT {$emailTable}.id as email_id\n                    FROM {$emailTable}\n                    INNER JOIN {$locTable}\n                        ON  {$emailTable}.location_id = {$locTable}.id\n                    WHERE   {$emailTable}.is_primary = 1\n                    AND     {$locTable}.is_primary = 1\n                    AND     {$locTable}.entity_table = '{$contactTable}'\n                    AND     {$locTable}.entity_id = " . CRM_Utils_Type::escape($contact_id, 'Integer'));
     $dao->fetch();
     $se =& new CRM_Mailing_Event_BAO_Subscribe();
     $se->group_id = $group_id;
     $se->contact_id = $contact_id;
     $se->time_stamp = date('YmdHis');
     $se->hash = sha1("{$group_id}:{$contact_id}:{$dao->email_id}");
     $se->save();
     $contacts = array($contact_id);
     require_once 'CRM/Contact/BAO/GroupContact.php';
     CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email', 'Pending', $se->id);
     CRM_Core_DAO::transaction('COMMIT');
     return $se;
 }
예제 #2
0
 /**
  * Get rows for the event browser
  *
  * @param int $mailing_id       ID of the mailing
  * @param int $job_id           optional ID of the job
  * @param int $offset           Offset
  * @param int $rowCount         Number of rows
  * @param array $sort           sort array
  * @return array                Result set
  * @access public
  * @static
  */
 function &getRows($mailing_id, $job_id = null, $offset = null, $rowCount = null, $sort = null)
 {
     $dao =& new CRM_Core_Dao();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $query = "\n            SELECT      {$contact}.display_name as display_name,\n                        {$contact}.id as contact_id,\n                        {$email}.email as email,\n                        {$job}.start_date as date\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     $query .= " ORDER BY {$contact}.sort_name, {$job}.start_date ";
     if ($offset) {
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
         $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
예제 #3
0
 /**
  * Get rows for the event browser
  *
  * @param int $mailing_id       ID of the mailing
  * @param int $job_id           optional ID of the job
  * @param boolean $is_distinct  Group by queue id?
  * @param int $offset           Offset
  * @param int $rowCount         Number of rows
  * @param array $sort           sort array
  *
  * @return array                Result set
  * @access public
  * @static
  */
 public static function &getRows($mailing_id, $job_id = NULL, $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL)
 {
     $dao = new CRM_Core_Dao();
     $bounce = self::getTableName();
     $bounceType = CRM_Mailing_DAO_BounceType::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_MailingJob::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $query = "\n            SELECT      {$contact}.display_name as display_name,\n                        {$contact}.id as contact_id,\n                        {$email}.email as email,\n                        {$bounce}.time_stamp as date,\n                        {$bounce}.bounce_reason as reason,\n                        {$bounceType}.name as bounce_type\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$bounce}\n                    ON  {$bounce}.event_queue_id = {$queue}.id\n            LEFT JOIN   {$bounceType}\n                    ON  {$bounce}.bounce_type_id = {$bounceType}.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n                    AND {$job}.is_test = 0\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     if ($is_distinct) {
         $query .= " GROUP BY {$queue}.id ";
     }
     $orderBy = "sort_name ASC, {$bounce}.time_stamp DESC";
     if ($sort) {
         if (is_string($sort)) {
             $sort = CRM_Utils_Type::escape($sort, 'String');
             $orderBy = $sort;
         } else {
             $orderBy = trim($sort->orderBy());
         }
     }
     $query .= " ORDER BY {$orderBy} ";
     if ($offset || $rowCount) {
         //Added "||$rowCount" to avoid displaying all records on first page
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
         $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'type' => empty($dao->bounce_type) ? ts('Unknown') : $dao->bounce_type, 'reason' => $dao->reason, 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
예제 #4
0
 /**
  * Send the mailing.
  *
  * @param object $mailer
  *   A Mail object to send the messages.
  *
  * @param array $testParams
  *
  * @return void
  */
 public function deliver(&$mailer, $testParams = NULL)
 {
     $mailing = new CRM_Mailing_BAO_Mailing();
     $mailing->id = $this->mailing_id;
     $mailing->find(TRUE);
     $mailing->free();
     $eq = new CRM_Mailing_Event_BAO_Queue();
     $eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
     $emailTable = CRM_Core_BAO_Email::getTableName();
     $phoneTable = CRM_Core_DAO_Phone::getTableName();
     $contactTable = CRM_Contact_BAO_Contact::getTableName();
     $edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
     $ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $query = "  SELECT      {$eqTable}.id,\n                                {$emailTable}.email as email,\n                                {$eqTable}.contact_id,\n                                {$eqTable}.hash,\n                                NULL as phone\n                    FROM        {$eqTable}\n                    INNER JOIN  {$emailTable}\n                            ON  {$eqTable}.email_id = {$emailTable}.id\n                    INNER JOIN  {$contactTable}\n                            ON  {$contactTable}.id = {$emailTable}.contact_id\n                    LEFT JOIN   {$edTable}\n                            ON  {$eqTable}.id = {$edTable}.event_queue_id\n                    LEFT JOIN   {$ebTable}\n                            ON  {$eqTable}.id = {$ebTable}.event_queue_id\n                    WHERE       {$eqTable}.job_id = " . $this->id . "\n                        AND     {$edTable}.id IS null\n                        AND     {$ebTable}.id IS null\n                        AND    {$contactTable}.is_opt_out = 0";
     if ($mailing->sms_provider_id) {
         $query = "\n                    SELECT      {$eqTable}.id,\n                                {$phoneTable}.phone as phone,\n                                {$eqTable}.contact_id,\n                                {$eqTable}.hash,\n                                NULL as email\n                    FROM        {$eqTable}\n                    INNER JOIN  {$phoneTable}\n                            ON  {$eqTable}.phone_id = {$phoneTable}.id\n                    INNER JOIN  {$contactTable}\n                            ON  {$contactTable}.id = {$phoneTable}.contact_id\n                    LEFT JOIN   {$edTable}\n                            ON  {$eqTable}.id = {$edTable}.event_queue_id\n                    LEFT JOIN   {$ebTable}\n                            ON  {$eqTable}.id = {$ebTable}.event_queue_id\n                    WHERE       {$eqTable}.job_id = " . $this->id . "\n                        AND     {$edTable}.id IS null\n                        AND     {$ebTable}.id IS null\n                        AND    ( {$contactTable}.is_opt_out = 0\n                        OR       {$contactTable}.do_not_sms = 0 )";
     }
     $eq->query($query);
     $config = NULL;
     if ($config == NULL) {
         $config = CRM_Core_Config::singleton();
     }
     $job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date);
     $fields = array();
     if (!empty($testParams)) {
         $mailing->subject = ts('[CiviMail Draft]') . ' ' . $mailing->subject;
     }
     CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
     // get and format attachments
     $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
     if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
         CRM_Core_Smarty::registerStringResource();
     }
     // CRM-12376
     // This handles the edge case scenario where all the mails
     // have been delivered in prior jobs
     $isDelivered = TRUE;
     // make sure that there's no more than $config->mailerBatchLimit mails processed in a run
     while ($eq->fetch()) {
         // if ( ( $mailsProcessed % 100 ) == 0 ) {
         // CRM_Utils_System::xMemory( "$mailsProcessed: " );
         // }
         if ($config->mailerBatchLimit > 0 && self::$mailsProcessed >= $config->mailerBatchLimit) {
             if (!empty($fields)) {
                 $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
             }
             $eq->free();
             return FALSE;
         }
         self::$mailsProcessed++;
         $fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email, 'phone' => $eq->phone);
         if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) {
             $isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
             if (!$isDelivered) {
                 $eq->free();
                 return $isDelivered;
             }
             $fields = array();
         }
     }
     $eq->free();
     if (!empty($fields)) {
         $isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
     }
     return $isDelivered;
 }
예제 #5
0
 /**
  * Returns array of contacts who are members of the specified group.
  *
  * @param CRM_Contact $group                A valid group object (passed by reference)
  * @param array       $returnProperties     Which properties
  *                    should be included in the returned Contact object(s). If NULL,
  *                    the default set of contact properties will be
  *                    included. group_contact properties (such as 'status',
  * '                  in_date', etc.) are included automatically.Note:Do not inclue
  *                    Id releted properties.  
  * @param text        $status               A valid status value ('Added', 'Pending', 'Removed').
  * @param text        $sort                 Associative array of
  *                    one or more "property_name"=>"sort direction"
  *                    pairs which will control order of Contact objects returned.
  * @param Int         $offset               Starting row index.
  * @param Int         $row_count            Maximum number of rows to returns.
  *
  *
  * @return            $contactArray         Array of contacts who are members of the specified group
  *
  * @access public
  */
 static function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null, $includeChildGroups = false)
 {
     $groupDAO =& new CRM_Contact_DAO_Group();
     $groupDAO->id = $group->id;
     if (!$groupDAO->find(true)) {
         return CRM_Core_Error::createError("Could not locate group with id: {$id}");
     }
     // make sure user has got permission to view this group
     require_once 'CRM/Contact/BAO/Group.php';
     if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
         return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
     }
     $query = '';
     if (empty($returnProperties)) {
         $query = "SELECT contact_a.id as contact_id,\n                      civicrm_email.email as email";
     } else {
         $query = "SELECT contact_a.id as contact_id , {$grpStatus} as status,";
         $query .= implode(',', $returnProperties);
     }
     $params = array();
     if ($includeChildGroups) {
         require_once 'CRM/Contact/BAO/GroupNesting.php';
         $groupIds = CRM_Contact_BAO_GroupNesting::getDescendentGroupIds(array($group->id));
     } else {
         $groupIds = array($group->id);
     }
     foreach ($groupIds as $groupId) {
         $params[] = array('group', 'IN', array($group->id => true), 0, 0);
     }
     require_once 'CRM/Core/BAO/Email.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $tables = array(CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true);
     $inner = array();
     $whereTables = array();
     $where = CRM_Contact_BAO_Query::getWhereClause($params, null, $tables, $whereTables);
     $permission = CRM_Core_Permission::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables);
     $from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
     $query .= " {$from} WHERE {$permission} AND {$where} ";
     if ($sort != null) {
         $order = array();
         foreach ($sort as $key => $direction) {
             $order[] = " {$key} {$direction} ";
         }
         $query .= " ORDER BY " . implode(',', $order);
     }
     if (!is_null($offset) && !is_null($row_count)) {
         $query .= " LIMIT {$offset}, {$row_count}";
     }
     $dao =& new CRM_Contact_DAO_Contact();
     $dao->query($query);
     // this is quite inefficient, we need to change the return
     // values in docs
     $contactArray = array();
     while ($dao->fetch()) {
         $contactArray[] = clone $dao;
     }
     return $contactArray;
 }
예제 #6
0
 /**
  * Get rows for the event browser
  *
  * @param int $mailing_id       ID of the mailing
  * @param int $job_id           optional ID of the job
  * @param boolean $is_distinct  Group by queue id?
  * @param int $offset           Offset
  * @param int $rowCount         Number of rows
  * @param array $sort           sort array
  * @return array                Result set
  * @access public
  * @static
  */
 function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null)
 {
     $dao =& new CRM_Core_Dao();
     $bounce = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $bounceType = CRM_Mailing_DAO_BounceType::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $query = "\n            SELECT      {$contact}.display_name as display_name,\n                        {$contact}.id as contact_id,\n                        {$email}.email as email,\n                        {$bounce}.time_stamp as date,\n                        {$bounce}.bounce_reason as reason,\n                        {$bounceType}.name as bounce_type\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$bounce}\n                    ON  {$bounce}.event_queue_id = {$queue}.id\n            LEFT JOIN   {$bounceType}\n                    ON  {$bounce}.bounce_type_id = {$bounceType}.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     if ($is_distinct) {
         $query .= " GROUP BY {$queue}.id ";
     }
     $query .= " ORDER BY {$contact}.sort_name, {$bounce}.time_stamp ";
     if ($offset) {
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
         $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'type' => empty($dao->bounce_type) ? ts('Unknown') : $dao->bounce_type, 'reason' => $dao->reason, 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
예제 #7
0
 /**
  * Get rows for the event browser
  *
  * @param int $mailing_id       ID of the mailing
  * @param int $job_id           optional ID of the job
  * @param boolean $is_distinct  Group by queue id?
  * @param int $offset           Offset
  * @param int $rowCount         Number of rows
  * @param array $sort           sort array
  * @return array                Result set
  * @access public
  * @static
  */
 public static function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null)
 {
     $dao =& new CRM_Core_Dao();
     $unsub = self::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $query = "\n            SELECT      {$contact}.display_name as display_name,\n                        {$contact}.id as contact_id,\n                        {$email}.email as email,\n                        {$unsub}.time_stamp as date,\n                        {$unsub}.org_unsubscribe as org_unsubscribe\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$unsub}\n                    ON  {$unsub}.event_queue_id = {$queue}.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n                    AND {$job}.is_test = 0\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     if ($is_distinct) {
         $query .= " GROUP BY {$queue}.id ";
     }
     $query .= " ORDER BY {$contact}.sort_name, {$unsub}.time_stamp DESC ";
     if ($offset) {
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
         $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'org' => $dao->org_unsubscribe ? ts('Yes') : ts('No'), 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
예제 #8
0
파일: Forward.php 프로젝트: bhirsch/voipdev
 /**
  * Get rows for the event browser
  *
  * @param int $mailing_id       ID of the mailing
  * @param int $job_id           optional ID of the job
  * @param boolean $is_distinct  Group by queue id?
  * @param int $offset           Offset
  * @param int $rowCount         Number of rows
  * @param array $sort           sort array
  * @return array                Result set
  * @access public
  * @static
  */
 public static function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null)
 {
     $dao =& new CRM_Core_Dao();
     $forward = self::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $query = "\n            SELECT      {$contact}.display_name as from_name,\n                        {$contact}.id as from_id,\n                        {$email}.email as from_email,\n                        dest_contact.id as dest_id,\n                        dest_email.email as dest_email,\n                        {$forward}.time_stamp as date\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$forward}\n                    ON  {$forward}.event_queue_id = {$queue}.id\n            INNER JOIN  {$queue} as dest_queue\n                    ON  {$forward}.dest_queue_id = dest_queue.id\n            INNER JOIN  {$contact} as dest_contact\n                    ON  dest_queue.contact_id = dest_contact.id\n            INNER JOIN  {$email} as dest_email\n                    ON  dest_queue.email_id = dest_email.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n                    AND {$job}.is_test = 0\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     if ($is_distinct) {
         $query .= " GROUP BY {$queue}.id ";
     }
     $query .= " ORDER BY {$contact}.sort_name, {$forward}.time_stamp DESC ";
     if ($offset || $rowCount) {
         //Added "||$rowCount" to avoid displaying all records on first page
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $from_url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->from_id}");
         $dest_url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->dest_id}");
         $results[] = array('from_name' => "<a href=\"{$from_url}\">{$dao->from_name}</a>", 'from_email' => $dao->from_email, 'dest_email' => "<a href=\"{$dest_url}\">{$dao->dest_email}</a>", 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
예제 #9
0
파일: Event.php 프로젝트: hguru/224Civi
 /**
  * returns the column headers as an array of tuples:
  * (name, sortName (key to the sort array))
  *
  * @param string $action the action being performed
  * @param enum   $output what should the result set include (web/email/csv)
  *
  * @return array the column headers that need to be displayed
  * @access public
  */
 function &getColumnHeaders($action = NULL, $output = NULL)
 {
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $job = CRM_Mailing_BAO_MailingJob::getTableName();
     if (!isset($this->_columnHeaders)) {
         $this->_columnHeaders = array(array('name' => ts('Contact'), 'sort' => $contact . '.sort_name', 'direction' => CRM_Utils_Sort::ASCENDING), array('name' => ts('Email Address'), 'sort' => $email . '.email', 'direction' => CRM_Utils_Sort::DONTCARE));
         switch ($this->_event_type) {
             case 'queue':
                 $dateSort = $job . '.start_date';
                 break;
             case 'delivered':
                 $dateSort = CRM_Mailing_Event_BAO_Delivered::getTableName() . '.time_stamp';
                 break;
             case 'opened':
                 $dateSort = CRM_Mailing_Event_BAO_Opened::getTableName() . '.time_stamp';
                 break;
             case 'bounce':
                 $dateSort = CRM_Mailing_Event_BAO_Bounce::getTableName() . '.time_stamp';
                 $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Bounce Type')), array('name' => ts('Bounce Reason'))));
                 break;
             case 'forward':
                 $dateSort = CRM_Mailing_Event_BAO_Forward::getTableName() . '.time_stamp';
                 $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Forwarded Email'))));
                 break;
             case 'reply':
                 $dateSort = CRM_Mailing_Event_BAO_Reply::getTableName() . '.time_stamp';
                 break;
             case 'unsubscribe':
                 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp';
                 $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Unsubscribe'))));
                 break;
             case 'optout':
                 $dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp';
                 $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Opt-Out'))));
                 break;
             case 'click':
                 $dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen::getTableName() . '.time_stamp';
                 $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('URL'))));
                 break;
             default:
                 return 0;
         }
         $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Date'), 'sort' => $dateSort, 'direction' => CRM_Utils_Sort::DESCENDING)));
     }
     return $this->_columnHeaders;
 }
예제 #10
0
 /**
  * Returns array of contacts who are members of the specified group.
  *
  * @param CRM_Contact $group                A valid group object (passed by reference)
  * @param array       $returnProperties     Which properties
  *                    should be included in the returned Contact object(s). If NULL,
  *                    the default set of contact properties will be
  *                    included. group_contact properties (such as 'status',
  * '                  in_date', etc.) are included automatically.Note:Do not inclue
  *                    Id releted properties.  
  * @param text        $status               A valid status value ('Added', 'Pending', 'Removed').
  * @param text        $sort                 Associative array of
  *                    one or more "property_name"=>"sort direction"
  *                    pairs which will control order of Contact objects returned.
  * @param Int         $offset               Starting row index.
  * @param Int         $row_count            Maximum number of rows to returns.
  *
  *
  * @return            $contactArray         Array of contacts who are members of the specified group
  *
  * @access public
  */
 function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null)
 {
     $query = "SELECT * FROM civicrm_group WHERE id = " . CRM_Utils_Type::escape($group->id, 'Integer');
     $groupDAO =& new CRM_Contact_DAO_Group();
     $groupDAO->id = $group->id;
     if (!$groupDAO->find(true)) {
         return CRM_Core_Error::createError("Could not locate group with id: {$id}");
     }
     // make sure user has got permission to view this group
     if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
         return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
     }
     $query = '';
     if (empty($returnProperties)) {
         $query = "SELECT civicrm_contact.id as contact_id,\n                      civicrm_email.email as email";
         //$query = "SELECT *,civicrm_contact.id as contact_id, (talk to lobo before re-enabling this)
         //civicrm_email.email as email";
     } else {
         $query = "SELECT civicrm_contact.id as contact_id ,";
         $query .= implode(',', $returnProperties);
     }
     $fv = array('group' => array($group->id => true));
     if ($status) {
         $fv['group_contact_status'] = array($status => true);
     } else {
         $fv['group_contact_status'] = array('Added' => true, 'Removed' => true, 'Pending' => true);
     }
     $tables = array(CRM_Contact_BAO_GroupContact::getTableName() => true, CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true, CRM_Contact_BAO_Group::getTableName() => true);
     $inner = array();
     $whereTables = array();
     $where = CRM_Contact_BAO_Query::getWhereClause($fv, null, $tables, $whereTables);
     $permission = CRM_Core_Permission::whereClause(CRM_CORE_PERMISSION_VIEW, $tables, $whereTables);
     $from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
     $query .= " {$from} WHERE {$permission} AND {$where} ";
     if ($sort != null) {
         $order = array();
         foreach ($sort as $key => $direction) {
             $order[] = " {$key} {$direction} ";
         }
         $query .= " ORDER BY " . implode(',', $order);
     }
     if ($offset != null && $row_count != null) {
         $query .= " LIMIT {$offset}, {$row_count}";
     }
     // CRM_Core_Error::debug( 'q', $query );
     $dao =& new CRM_Contact_DAO_Contact();
     $dao->query($query);
     // this is quite inefficient, we need to change the return
     // values in docs
     $contactArray = array();
     while ($dao->fetch()) {
         $contactArray[] = clone $dao;
     }
     return $contactArray;
 }
예제 #11
0
 /**
  * Send the mailing
  *
  * @param object $mailer        A Mail object to send the messages
  * @return void
  * @access public
  */
 function deliver(&$mailer)
 {
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $mailing =& new CRM_Mailing_BAO_Mailing();
     $mailing->id = $this->mailing_id;
     $mailing->find(true);
     $eq =& new CRM_Mailing_Event_BAO_Queue();
     $eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
     $emailTable = CRM_Core_BAO_Email::getTableName();
     $contactTable = CRM_Contact_BAO_Contact::getTableName();
     $edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
     $ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $query = "  SELECT      {$eqTable}.id,\n                                {$emailTable}.email as email,\n                                {$eqTable}.contact_id,\n                                {$eqTable}.hash\n                    FROM        {$eqTable}\n                    INNER JOIN  {$emailTable}\n                            ON  {$eqTable}.email_id = {$emailTable}.id\n                    LEFT JOIN   {$edTable}\n                            ON  {$eqTable}.id = {$edTable}.event_queue_id\n                    LEFT JOIN   {$ebTable}\n                            ON  {$eqTable}.id = {$ebTable}.event_queue_id\n                    WHERE       {$eqTable}.job_id = " . $this->id . "\n                        AND     {$edTable}.id IS null\n                        AND     {$ebTable}.id IS null";
     $eq->query($query);
     while ($eq->fetch()) {
         /* Compose the mailing */
         $recipient = null;
         $message = $mailing->compose($this->id, $eq->id, $eq->hash, $eq->contact_id, $eq->email, $recipient);
         /* Send the mailing */
         $body = $message->get();
         $headers = $message->headers();
         /* TODO: when we separate the content generator from the delivery
          * engine, maybe we should dump the messages into a table */
         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
         $result = $mailer->send($recipient, $headers, $body);
         CRM_Core_Error::setCallback();
         $params = array('event_queue_id' => $eq->id, 'job_id' => $this->id, 'hash' => $eq->hash);
         if (is_a($result, PEAR_Error)) {
             /* Register the bounce event */
             require_once 'CRM/Mailing/BAO/BouncePattern.php';
             require_once 'CRM/Mailing/Event/BAO/Bounce.php';
             $params = array_merge($params, CRM_Mailing_BAO_BouncePattern::match($result->getMessage()));
             CRM_Mailing_Event_BAO_Bounce::create($params);
         } else {
             /* Register the delivery event */
             CRM_Mailing_Event_BAO_Delivered::create($params);
         }
     }
 }
예제 #12
0
 /**
  * Get rows for the event browser.
  *
  * @param int $mailing_id
  *   ID of the mailing.
  * @param int $job_id
  *   Optional ID of the job.
  * @param bool $is_distinct
  *   Group by queue id?.
  * @param int $offset
  *   Offset.
  * @param int $rowCount
  *   Number of rows.
  * @param array $sort
  *   Sort array.
  *
  * @param null $org_unsubscribe
  * @return array
  *   Result set
  */
 public static function &getRows($mailing_id, $job_id = NULL, $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL, $org_unsubscribe = NULL)
 {
     $dao = new CRM_Core_Dao();
     $unsub = self::$_tableName;
     $queueObject = new CRM_Mailing_Event_BAO_Queue();
     $queue = $queueObject->getTableName();
     $mailingObject = new CRM_Mailing_BAO_Mailing();
     $mailing = $mailingObject->getTableName();
     $jobObject = new CRM_Mailing_BAO_MailingJob();
     $job = $jobObject->getTableName();
     $contactObject = new CRM_Contact_BAO_Contact();
     $contact = $contactObject->getTableName();
     $emailObject = new CRM_Core_BAO_Email();
     $email = $emailObject->getTableName();
     $query = "\n            SELECT      {$contact}.display_name as display_name,\n                        {$contact}.id as contact_id,\n                        {$email}.email as email,\n                        {$unsub}.time_stamp as date,\n                        {$unsub}.org_unsubscribe as org_unsubscribe\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$unsub}\n                    ON  {$unsub}.event_queue_id = {$queue}.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n                    AND {$job}.is_test = 0\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     if ($org_unsubscribe !== NULL) {
         $query .= " AND {$unsub}.org_unsubscribe = " . ($org_unsubscribe ? 0 : 1);
     }
     if ($is_distinct) {
         $query .= " GROUP BY {$queue}.id ";
     }
     $orderBy = "sort_name ASC, {$unsub}.time_stamp DESC";
     if ($sort) {
         if (is_string($sort)) {
             $sort = CRM_Utils_Type::escape($sort, 'String');
             $orderBy = $sort;
         } else {
             $orderBy = trim($sort->orderBy());
         }
     }
     $query .= " ORDER BY {$orderBy} ";
     if ($offset || $rowCount) {
         //Added "||$rowCount" to avoid displaying all records on first page
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
         $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'unsubOrOptout' => ts('Yes'), 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
예제 #13
0
파일: Job.php 프로젝트: bhirsch/voipdev
 /**
  * Send the mailing
  *
  * @param object $mailer        A Mail object to send the messages
  * @return void
  * @access public
  */
 public function deliver(&$mailer, $testParams = null)
 {
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $mailing =& new CRM_Mailing_BAO_Mailing();
     $mailing->id = $this->mailing_id;
     $mailing->find(true);
     $eq =& new CRM_Mailing_Event_BAO_Queue();
     $eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
     $emailTable = CRM_Core_BAO_Email::getTableName();
     $contactTable = CRM_Contact_BAO_Contact::getTableName();
     $edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
     $ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $query = "  SELECT      {$eqTable}.id,\n                                {$emailTable}.email as email,\n                                {$eqTable}.contact_id,\n                                {$eqTable}.hash\n                    FROM        {$eqTable}\n                    INNER JOIN  {$emailTable}\n                            ON  {$eqTable}.email_id = {$emailTable}.id\n                    LEFT JOIN   {$edTable}\n                            ON  {$eqTable}.id = {$edTable}.event_queue_id\n                    LEFT JOIN   {$ebTable}\n                            ON  {$eqTable}.id = {$ebTable}.event_queue_id\n                    WHERE       {$eqTable}.job_id = " . $this->id . "\n                        AND     {$edTable}.id IS null\n                        AND     {$ebTable}.id IS null";
     $eq->query($query);
     static $config = null;
     $mailsProcessed = 0;
     if ($config == null) {
         $config =& CRM_Core_Config::singleton();
     }
     $job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date);
     $fields = array();
     if (!empty($testParams)) {
         $mailing->from_name = ts('CiviCRM Test Mailer (%1)', array(1 => $mailing->from_name));
         $mailing->subject = ts('Test Mailing:') . ' ' . $mailing->subject;
     }
     CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
     // get and format attachments
     require_once 'CRM/Core/BAO/File.php';
     $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
     if (defined('CIVICRM_MAIL_SMARTY')) {
         require_once 'CRM/Core/Smarty/resources/String.php';
         civicrm_smarty_register_string_resource();
     }
     // make sure that there's no more than $config->mailerBatchLimit mails processed in a run
     while ($eq->fetch()) {
         // if ( ( $mailsProcessed % 100 ) == 0 ) {
         // CRM_Utils_System::xMemory( "$mailsProcessed: " );
         // }
         if ($config->mailerBatchLimit > 0 && $mailsProcessed >= $config->mailerBatchLimit) {
             $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
             return false;
         }
         $mailsProcessed++;
         $fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email);
         if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) {
             $isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
             if (!$isDelivered) {
                 return $isDelivered;
             }
             $fields = array();
         }
     }
     $isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
     return $isDelivered;
 }
예제 #14
0
 /**
  * Get rows for the event browser
  *
  * @param int $mailing_id       ID of the mailing
  * @param int $job_id           optional ID of the job
  * @param int $offset           Offset
  * @param int $rowCount         Number of rows
  * @param array $sort           sort array
  * @return array                Result set
  * @access public
  * @static
  */
 public static function &getRows($mailing_id, $job_id = null, $offset = null, $rowCount = null, $sort = null)
 {
     $dao = new CRM_Core_Dao();
     $queue = self::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $orderBy = "sort_name ASC, {$job}.start_date DESC";
     if ($sort) {
         if (is_string($sort)) {
             $orderBy = $sort;
         } else {
             $orderBy = trim($sort->orderBy());
         }
     }
     $query = "\n            SELECT      {$contact}.display_name as display_name,\n                        {$contact}.id as contact_id,\n                        {$email}.email as email,\n                        {$job}.start_date as date\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n                    AND {$job}.is_test = 0\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     $query .= " ORDER BY {$orderBy} ";
     if ($offset || $rowCount) {
         //Added "||$rowCount" to avoid displaying all records on first page
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
         $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
예제 #15
0
 /**
  * Generate an event queue for a retry job (ie the contacts who bounced)
  *
  * @param int $job_id       The job marked retry
  * @return object           A DAO loaded with email_id/contact_id results
  * @access public
  */
 function retryRecipients($job_id)
 {
     $eq =& new CRM_Mailing_Event_BAO_Queue();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $bounce = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $delivered = CRM_Mailing_Event_BAO_Delivered::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $query = "SELECT             {$queue}.email_id as email_id, \n                                    {$queue}.contact_id as contact_id\n                FROM                {$queue}\n                INNER JOIN          {$job}\n                        ON          {$queue}.job_id = {$job}.id\n                INNER JOIN          {$bounce}\n                        ON          {$bounce}.event_queue_id = {$queue}.id\n                INNER JOIN          {$contact}\n                        ON          {$queue}.contact_id = {$contact}.id\n                INNER JOIN          {$email}\n                        ON          {$queue}.email_id = {$email}.id\n                LEFT JOIN           {$queue} as queue_d\n                        ON          queue_d.contact_id = {$queue}.contact_id\n                LEFT JOIN           {$delivered}\n                        ON          {$delivered}.event_queue_id = queue_d.id\n                LEFT JOIN           {$bounce} as bounce_d\n                        ON          bounce_d.event_queue_id = queue_d.id\n                WHERE               \n                                    {$job}.mailing_id = {$this->id}\n                    AND             {$job}.id <> {$job_id}\n                    AND             {$contact}.do_not_email = 0\n                    AND             {$contact}.is_opt_out = 0\n                    AND             {$email}.on_hold = 0\n                    AND             bounce_d.id IS NOT NULL\n                GROUP BY            {$queue}.email_id";
     $eq->query($query);
     return $eq;
     //         $results = array();
     //         while ($eq->fetch()) {
     //             $results[] = array(
     //                 'email_id' => $eq->email_id,
     //                 'contact_id' => $eq->contact_id,
     //             );
     //         }
     //         return $results;
 }