コード例 #1
0
ファイル: Unsubscribe.php プロジェクト: ksecor/civicrm
 /**
  * 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;
 }
コード例 #2
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;
 }
コード例 #3
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;
 }
コード例 #4
0
 /**
  * Get the rows for a browse operation
  *
  * @param int $offset       The row number to start from
  * @param int $rowCount     The nmber of rows to return
  * @param string $sort      The sql string that describes the sort order
  * 
  * @return array            The rows
  * @access public
  */
 function &getRows($offset, $rowCount, $sort)
 {
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $session =& CRM_Core_Session::singleton();
     $domain_id = $session->get('domainID');
     $query = "\n            SELECT      {$mailing}.id,\n                        {$mailing}.name, \n                        {$job}.status, \n                        MIN({$job}.scheduled_date) as scheduled_date, \n                        MIN({$job}.start_date) as start_date,\n                        MAX({$job}.end_date) as end_date\n            FROM        {$mailing}\n            INNER JOIN  {$job}\n                    ON  {$job}.mailing_id = {$mailing}.id\n            WHERE       {$mailing}.domain_id = {$domain_id}\n            GROUP BY    {$mailing}.id\n            ORDER BY    {$mailing}.id, {$job}.end_date";
     if ($rowCount) {
         $query .= " LIMIT {$offset}, {$rowCount} ";
     }
     $this->query($query);
     $rows = array();
     while ($this->fetch()) {
         $rows[] = array('id' => $this->id, 'name' => $this->name, 'status' => CRM_Mailing_BAO_Job::status($this->status), 'scheduled' => CRM_Utils_Date::customFormat($this->scheduled_date), 'scheduled_iso' => $this->scheduled_date, 'start' => CRM_Utils_Date::customFormat($this->start_date), 'end' => CRM_Utils_Date::customFormat($this->end_date));
     }
     return $rows;
 }
コード例 #5
0
 /**
  * Replace the list of recipients on a given mailing.
  *
  * @param int $mailingId
  * @param string $type
  *   'include' or 'exclude'.
  * @param string $entity
  *   'groups' or 'mailings'.
  * @param array <int> $entityIds
  * @throws CiviCRM_API3_Exception
  */
 public static function replaceGroups($mailingId, $type, $entity, $entityIds)
 {
     $values = array();
     foreach ($entityIds as $entityId) {
         $values[] = array('entity_id' => $entityId);
     }
     civicrm_api3('mailing_group', 'replace', array('mailing_id' => $mailingId, 'group_type' => $type, 'entity_table' => $entity == 'groups' ? CRM_Contact_BAO_Group::getTableName() : CRM_Mailing_BAO_Mailing::getTableName(), 'values' => $values));
 }
コード例 #6
0
 public function postProcess()
 {
     $values = $this->controller->exportValues($this->_name);
     //build hidden smart group. when user want to send  mailing
     //through search contact-> more action -> send Mailing. CRM-3711
     $groups = array();
     if ($this->_searchBasedMailing && $this->_contactIds) {
         $session = CRM_Core_Session::singleton();
         if ($this->_resultSelectOption == 'ts_sel') {
             // create a static grp if only a subset of result set was selected:
             $randID = md5(time());
             $grpTitle = "Hidden Group {$randID}";
             $grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title');
             if (!$grpID) {
                 $groupParams = array('title' => $grpTitle, 'is_active' => 1, 'is_hidden' => 1, 'group_type' => array('2' => 1));
                 $group = CRM_Contact_BAO_Group::create($groupParams);
                 $grpID = $group->id;
                 CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id);
                 $newGroupTitle = "Hidden Group {$grpID}";
                 $groupParams = array('id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle);
                 $group = CRM_Contact_BAO_Group::create($groupParams);
             }
             // note at this point its a static group
             $smartGroupId = $grpID;
         } else {
             //get the hidden smart group id.
             $ssId = $this->get('ssID');
             $hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $this->get('formValues'), 'saved_search_id' => $ssId, 'search_custom_id' => $this->get('customSearchID'), 'search_context' => $this->get('context'));
             list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
             //set the saved search id.
             if (!$ssId) {
                 if ($savedSearchId) {
                     $this->set('ssID', $savedSearchId);
                 } else {
                     CRM_Core_Error::fatal();
                 }
             }
         }
         //get the base group for this mailing, CRM-3711
         $groups['base'] = array($values['baseGroup']);
         $values['includeGroups'][] = $smartGroupId;
     }
     foreach (array('name', 'group_id', 'search_id', 'search_args', 'campaign_id', 'dedupe_email') as $n) {
         if (CRM_Utils_Array::value($n, $values)) {
             $params[$n] = $values[$n];
         }
     }
     $qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit');
     $this->set('name', $params['name']);
     $inGroups = $values['includeGroups'];
     $outGroups = $values['excludeGroups'];
     $inMailings = $values['includeMailings'];
     $outMailings = $values['excludeMailings'];
     if (is_array($inGroups)) {
         foreach ($inGroups as $key => $id) {
             if ($id) {
                 $groups['include'][] = $id;
             }
         }
     }
     if (is_array($outGroups)) {
         foreach ($outGroups as $key => $id) {
             if ($id) {
                 $groups['exclude'][] = $id;
             }
         }
     }
     $mailings = array();
     if (is_array($inMailings)) {
         foreach ($inMailings as $key => $id) {
             if ($id) {
                 $mailings['include'][] = $id;
             }
         }
     }
     if (is_array($outMailings)) {
         foreach ($outMailings as $key => $id) {
             if ($id) {
                 $mailings['exclude'][] = $id;
             }
         }
     }
     $session = CRM_Core_Session::singleton();
     $params['groups'] = $groups;
     $params['mailings'] = $mailings;
     if ($this->get('mailing_id')) {
         $ids = array();
         // don't create a new mailing if already exists
         $ids['mailing_id'] = $this->get('mailing_id');
         $groupTableName = CRM_Contact_BAO_Group::getTableName();
         $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
         // delete previous includes/excludes, if mailing already existed
         foreach (array('groups', 'mailings') as $entity) {
             $mg = new CRM_Mailing_DAO_Group();
             $mg->mailing_id = $ids['mailing_id'];
             $mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
             $mg->find();
             while ($mg->fetch()) {
                 $mg->delete();
             }
         }
     } else {
         // new mailing, so lets set the created_id
         $session = CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
     $this->set('mailing_id', $mailing->id);
     $dedupeEmail = FALSE;
     if (isset($params['dedupe_email'])) {
         $dedupeEmail = $params['dedupe_email'];
     }
     // also compute the recipients and store them in the mailing recipients table
     CRM_Mailing_BAO_Mailing::getRecipients($mailing->id, $mailing->id, NULL, NULL, TRUE, $dedupeEmail);
     $count = CRM_Mailing_BAO_Recipients::mailingSize($mailing->id);
     $this->set('count', $count);
     $this->assign('count', $count);
     $this->set('groups', $groups);
     $this->set('mailings', $mailings);
     if ($qf_Group_submit) {
         //when user perform mailing from search context
         //redirect it to search result CRM-3711.
         $ssID = $this->get('ssID');
         $context = $this->get('context');
         if ($ssID && $this->_searchBasedMailing) {
             if ($this->_action == CRM_Core_Action::BASIC) {
                 $fragment = 'search';
             } elseif ($this->_action == CRM_Core_Action::PROFILE) {
                 $fragment = 'search/builder';
             } elseif ($this->_action == CRM_Core_Action::ADVANCED) {
                 $fragment = 'search/advanced';
             } else {
                 $fragment = 'search/custom';
             }
             $context = $this->get('context');
             if (!CRM_Contact_Form_Search::isSearchContext($context)) {
                 $context = 'search';
             }
             $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
             if (CRM_Utils_Rule::qfKey($qfKey)) {
                 $urlParams .= "&qfKey={$qfKey}";
             }
             $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
             CRM_Core_Session::setStatus($status);
             //replace user context to search.
             $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
             return $this->controller->setDestination($url);
         } else {
             $status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it.");
             CRM_Core_Session::setStatus($status);
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             return $this->controller->setDestination($url);
         }
     }
 }
コード例 #7
0
ファイル: Queue.php プロジェクト: bhirsch/voipdrupal-4.7-1.0
 /**
  * Get the mailing object for this queue event instance
  * 
  * @param
  * @return object           Mailing BAO
  * @access public
  */
 function &getMailing()
 {
     $mailing =& new CRM_Mailing_BAO_Mailing();
     $jobs = CRM_Mailing_BAO_Job::getTableName();
     $mailings = CRM_Mailing_BAO_Mailing::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $mailing->query("\n                SELECT      {$mailings}.*\n                FROM        {$mailings}\n                INNER JOIN  {$jobs}\n                        ON  {$jobs}.mailing_id = {$mailings}.id\n                INNER JOIN  {$queue}\n                        ON  {$queue}.job_id = {$jobs}.id\n                WHERE       {$queue}.id = {$this->id}");
     $mailing->fetch();
     return $mailing;
 }
コード例 #8
0
ファイル: Browse.php プロジェクト: rajeshrhino/civicrm-core
 /**
  * Returns total number of rows for the query.
  *
  * @param
  *
  * @return int
  *   Total number of rows
  */
 public function getTotalCount($action)
 {
     $job = CRM_Mailing_BAO_MailingJob::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL();
     //get the where clause.
     $params = array();
     $whereClause = "{$mailingACL} AND " . $this->whereClause($params);
     // CRM-11919 added addition ON clauses to mailing_job to match getRows
     $query = "\n   SELECT  COUNT( DISTINCT {$mailing}.id ) as count\n     FROM  {$mailing}\nLEFT JOIN  {$job} ON ( {$mailing}.id = {$job}.mailing_id AND civicrm_mailing_job.is_test = 0 AND civicrm_mailing_job.parent_id IS NULL )\nLEFT JOIN  civicrm_contact createdContact   ON ( {$mailing}.created_id   = createdContact.id )\nLEFT JOIN  civicrm_contact scheduledContact ON ( {$mailing}.scheduled_id = scheduledContact.id )\n    WHERE  {$whereClause}";
     return CRM_Core_DAO::singleValueQuery($query, $params);
 }
コード例 #9
0
 /**
  * Resubscribe a contact to the groups, he/she was unsubscribed from.
  *
  * @param int $job_id       The job ID
  * @param int $queue_id     The Queue Event ID of the recipient
  * @param string $hash      The hash
  * @return array|null $groups    Array of all groups to which the contact was added, or null if the queue event could not be found.
  * @access public
  * @static
  */
 public static function &resub_to_mailing($job_id, $queue_id, $hash)
 {
     /* First make sure there's a matching queue event */
     $q =& CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
     $success = null;
     if (!$q) {
         return $success;
     }
     // check if this queue_id was actually unsubscribed
     $ue = new CRM_Mailing_Event_BAO_Unsubscribe();
     $ue->event_queue_id = $queue_id;
     $ue->org_unsubscribe = 0;
     if (!$ue->find(true)) {
         return $success;
     }
     $contact_id = $q->contact_id;
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $do = new CRM_Core_DAO();
     $mg = CRM_Mailing_DAO_Group::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $group = CRM_Contact_BAO_Group::getTableName();
     $gc = CRM_Contact_BAO_GroupContact::getTableName();
     $do->query("\n            SELECT      {$mg}.entity_table as entity_table,\n                        {$mg}.entity_id as entity_id\n            FROM        {$mg}\n            INNER JOIN  {$job}\n                ON      {$job}.mailing_id = {$mg}.mailing_id\n            WHERE       {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer') . "\n                AND     {$mg}.group_type = 'Include'");
     /* Make a list of groups and a list of prior mailings that received 
      * this mailing */
     $groups = array();
     $mailings = array();
     while ($do->fetch()) {
         if ($do->entity_table == $group) {
             $groups[$do->entity_id] = null;
         } else {
             if ($do->entity_table == $mailing) {
                 $mailings[] = $do->entity_id;
             }
         }
     }
     /* As long as we have prior mailings, find their groups and add to the
      * list */
     while (!empty($mailings)) {
         $do->query("\n                SELECT      {$mg}.entity_table as entity_table,\n                            {$mg}.entity_id as entity_id\n                FROM        {$mg}\n                WHERE       {$mg}.mailing_id IN (" . implode(', ', $mailings) . ")\n                    AND     {$mg}.group_type = 'Include'");
         $mailings = array();
         while ($do->fetch()) {
             if ($do->entity_table == $group) {
                 $groups[$do->entity_id] = true;
             } else {
                 if ($do->entity_table == $mailing) {
                     $mailings[] = $do->entity_id;
                 }
             }
         }
     }
     /* Now we have a complete list of recipient groups.  Filter out all
      * those except smart groups and those that the contact belongs to */
     $do->query("\n            SELECT      {$group}.id as group_id,\n                        {$group}.title as title\n            FROM        {$group}\n            LEFT JOIN   {$gc}\n                ON      {$gc}.group_id = {$group}.id\n            WHERE       {$group}.id IN (" . implode(', ', array_keys($groups)) . ")\n                AND     ({$group}.saved_search_id is not null\n                            OR  ({$gc}.contact_id = {$contact_id}\n                                AND {$gc}.status = 'Removed')\n                        )");
     while ($do->fetch()) {
         $groups[$do->group_id] = $do->title;
     }
     $contacts = array($contact_id);
     foreach ($groups as $group_id => $group_name) {
         $notadded = 0;
         if ($group_name) {
             list($total, $added, $notadded) = CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email');
         }
         if ($notadded) {
             unset($groups[$group_id]);
         }
     }
     // remove entry from Unsubscribe table.
     $ue = new CRM_Mailing_Event_BAO_Unsubscribe();
     $ue->event_queue_id = $queue_id;
     $ue->org_resubscribe = 0;
     if ($ue->find(true)) {
         $ue->delete();
     }
     $transaction->commit();
     return $groups;
 }
コード例 #10
0
 /**
  * Resubscribe a contact to the groups, he/she was unsubscribed from.
  *
  * @param int $job_id
  *   The job ID.
  * @param int $queue_id
  *   The Queue Event ID of the recipient.
  * @param string $hash
  *   The hash.
  *
  * @return array|null
  *   $groups    Array of all groups to which the contact was added, or null if the queue event could not be found.
  */
 public static function &resub_to_mailing($job_id, $queue_id, $hash)
 {
     // First make sure there's a matching queue event.
     $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
     $success = NULL;
     if (!$q) {
         return $success;
     }
     // check if this queue_id was actually unsubscribed
     $ue = new CRM_Mailing_Event_BAO_Unsubscribe();
     $ue->event_queue_id = $queue_id;
     $ue->org_unsubscribe = 0;
     if (!$ue->find(TRUE)) {
         return $success;
     }
     $contact_id = $q->contact_id;
     $transaction = new CRM_Core_Transaction();
     $do = new CRM_Core_DAO();
     $mg = CRM_Mailing_DAO_MailingGroup::getTableName();
     $job = CRM_Mailing_BAO_MailingJob::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $group = CRM_Contact_BAO_Group::getTableName();
     $gc = CRM_Contact_BAO_GroupContact::getTableName();
     // We Need the mailing Id for the hook...
     $do->query("SELECT {$job}.mailing_id as mailing_id\n                     FROM   {$job}\n                     WHERE {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'));
     $do->fetch();
     $mailing_id = $do->mailing_id;
     $do->query("\n            SELECT      {$mg}.entity_table as entity_table,\n                        {$mg}.entity_id as entity_id\n            FROM        {$mg}\n            INNER JOIN  {$job}\n                ON      {$job}.mailing_id = {$mg}.mailing_id\n            INNER JOIN  {$group}\n                ON      {$mg}.entity_id = {$group}.id\n            WHERE       {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer') . "\n                AND     {$mg}.group_type IN ( 'Include', 'Base' )\n                AND     {$group}.is_hidden = 0");
     // Make a list of groups and a list of prior mailings that received
     // this mailing.
     $groups = array();
     $mailings = array();
     while ($do->fetch()) {
         if ($do->entity_table == $group) {
             $groups[$do->entity_id] = NULL;
         } elseif ($do->entity_table == $mailing) {
             $mailings[] = $do->entity_id;
         }
     }
     // As long as we have prior mailings, find their groups and add to the
     // list.
     while (!empty($mailings)) {
         $do->query("\n                SELECT      {$mg}.entity_table as entity_table,\n                            {$mg}.entity_id as entity_id\n                FROM        {$mg}\n                WHERE       {$mg}.mailing_id IN (" . implode(', ', $mailings) . ")\n                    AND     {$mg}.group_type = 'Include'");
         $mailings = array();
         while ($do->fetch()) {
             if ($do->entity_table == $group) {
                 $groups[$do->entity_id] = TRUE;
             } elseif ($do->entity_table == $mailing) {
                 $mailings[] = $do->entity_id;
             }
         }
     }
     $group_ids = array_keys($groups);
     $base_groups = NULL;
     CRM_Utils_Hook::unsubscribeGroups('resubscribe', $mailing_id, $contact_id, $group_ids, $base_groups);
     // Now we have a complete list of recipient groups.  Filter out all
     // those except smart groups and those that the contact belongs to.
     $do->query("\n            SELECT      {$group}.id as group_id,\n                        {$group}.title as title\n            FROM        {$group}\n            LEFT JOIN   {$gc}\n                ON      {$gc}.group_id = {$group}.id\n            WHERE       {$group}.id IN (" . implode(', ', $group_ids) . ")\n                AND     ({$group}.saved_search_id is not null\n                            OR  ({$gc}.contact_id = {$contact_id}\n                                AND {$gc}.status = 'Removed')\n                        )");
     while ($do->fetch()) {
         $groups[$do->group_id] = $do->title;
     }
     $contacts = array($contact_id);
     foreach ($groups as $group_id => $group_name) {
         $notadded = 0;
         if ($group_name) {
             list($total, $added, $notadded) = CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email');
         }
         if ($notadded) {
             unset($groups[$group_id]);
         }
     }
     // remove entry from Unsubscribe table.
     $ue = new CRM_Mailing_Event_BAO_Unsubscribe();
     $ue->event_queue_id = $queue_id;
     $ue->org_resubscribe = 0;
     if ($ue->find(TRUE)) {
         $ue->delete();
     }
     $transaction->commit();
     return $groups;
 }
コード例 #11
0
ファイル: Event.php プロジェクト: bhirsch/voipdev
 /**
  * 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)
 {
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     require_once 'CRM/Mailing/BAO/Job.php';
     $job = CRM_Mailing_BAO_Job::getTableName();
     if (!isset($this->_columnHeaders)) {
         $this->_columnHeaders = array(array('name' => ts('Contact')), array('name' => ts('Email Address')));
         if ($this->_event_type == 'bounce') {
             $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Bounce Type')), array('name' => ts('Bounce Reason'))));
         } elseif ($this->_event_type == 'unsubscribe') {
             $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Opt-Out'))));
         } elseif ($this->_event_type == 'click') {
             $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('URL'))));
         } elseif ($this->_event_type == 'forward') {
             $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Forwarded Email'))));
         }
         $this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Date'))));
     }
     return $this->_columnHeaders;
 }
コード例 #12
0
 /**
  * Construct a new mailing object, along with job and mailing_group
  * objects, from the form values of the create mailing wizard.
  *
  * @params array $params        Form values
  *
  * @return object $mailing      The new mailing object
  * @access public
  * @static
  */
 public static function create(&$params, &$ids)
 {
     $transaction = new CRM_Core_Transaction();
     $mailing = self::add($params, $ids);
     if (is_a($mailing, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $mailing;
     }
     $groupTableName = CRM_Contact_BAO_Group::getTableName();
     $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
     /* Create the mailing group record */
     $mg = new CRM_Mailing_DAO_Group();
     foreach (array('groups', 'mailings') as $entity) {
         foreach (array('include', 'exclude', 'base') as $type) {
             if (isset($params[$entity]) && CRM_Utils_Array::value($type, $params[$entity]) && is_array($params[$entity][$type])) {
                 foreach ($params[$entity][$type] as $entityId) {
                     $mg->reset();
                     $mg->mailing_id = $mailing->id;
                     $mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
                     $mg->entity_id = $entityId;
                     $mg->group_type = $type;
                     $mg->save();
                 }
             }
         }
     }
     if (!empty($params['search_id']) && !empty($params['group_id'])) {
         $mg->reset();
         $mg->mailing_id = $mailing->id;
         $mg->entity_table = $groupTableName;
         $mg->entity_id = $params['group_id'];
         $mg->search_id = $params['search_id'];
         $mg->search_args = $params['search_args'];
         $mg->group_type = 'Include';
         $mg->save();
     }
     // check and attach and files as needed
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_mailing', $mailing->id);
     $transaction->commit();
     return $mailing;
 }
コード例 #13
0
ファイル: Mailing.php プロジェクト: konadave/civicrm-core
 /**
  * Whitelist of possible values for the entity_table field
  * @return array
  */
 public static function mailingGroupEntityTables()
 {
     $tables = array(CRM_Contact_BAO_Group::getTableName(), CRM_Mailing_BAO_Mailing::getTableName());
     // Identical keys & values
     return array_combine($tables, $tables);
 }
コード例 #14
0
ファイル: Browse.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**
  * Returns total number of rows for the query.
  *
  * @param 
  * @return int Total number of rows 
  * @access public
  */
 function getTotalCount($action)
 {
     require_once 'CRM/Mailing/BAO/Job.php';
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $job = CRM_Mailing_BAO_Job::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $mailingACL = CRM_Mailing_BAO_Mailing::mailingACL();
     //get the where clause.
     $params = array();
     $whereClause = "{$mailingACL} AND " . $this->whereClause($params);
     $query = "\n   SELECT  COUNT( DISTINCT {$mailing}.id ) as count\n     FROM  {$mailing}\nLEFT JOIN  {$job} ON ( {$mailing}.id = {$job}.mailing_id) \nLEFT JOIN  civicrm_contact createdContact   ON ( {$mailing}.created_id   = createdContact.id )\nLEFT JOIN  civicrm_contact scheduledContact ON ( {$mailing}.scheduled_id = scheduledContact.id ) \n    WHERE  {$whereClause}";
     return CRM_Core_DAO::singleValueQuery($query, $params);
 }
コード例 #15
0
ファイル: Bounce.php プロジェクト: bhirsch/voipdrupal-4.7-1.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;
 }
コード例 #16
0
 /**
  * Construct a new mailing object, along with job and mailing_group
  * objects, from the form values of the create mailing wizard.
  *
  * @params array $params        Form values
  *
  * @return object $mailing      The new mailing object
  * @access public
  * @static
  */
 public static function create(&$params, $ids = array())
 {
     // CRM-12430
     // Do the below only for an insert
     // for an update, we should not set the defaults
     if (!isset($ids['id']) && !isset($ids['mailing_id'])) {
         // Retrieve domain email and name for default sender
         $domain = civicrm_api('Domain', 'getsingle', array('version' => 3, 'current_domain' => 1, 'sequential' => 1));
         if (isset($domain['from_email'])) {
             $domain_email = $domain['from_email'];
             $domain_name = $domain['from_name'];
         } else {
             $domain_email = '*****@*****.**';
             $domain_name = 'EXAMPLE.ORG';
         }
         if (!isset($params['created_id'])) {
             $session =& CRM_Core_Session::singleton();
             $params['created_id'] = $session->get('userID');
         }
         $defaults = array('override_verp' => TRUE, 'forward_replies' => FALSE, 'open_tracking' => TRUE, 'url_tracking' => TRUE, 'visibility' => 'User and User Admin Only', 'replyto_email' => $domain_email, 'header_id' => CRM_Mailing_PseudoConstant::defaultComponent('header_id', ''), 'footer_id' => CRM_Mailing_PseudoConstant::defaultComponent('footer_id', ''), 'from_email' => $domain_email, 'from_name' => $domain_name, 'msg_template_id' => NULL, 'created_id' => $params['created_id'], 'approver_id' => NULL, 'auto_responder' => 0, 'created_date' => date('YmdHis'), 'scheduled_date' => NULL, 'approval_date' => NULL);
         // Get the default from email address, if not provided.
         if (empty($defaults['from_email'])) {
             $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
             foreach ($defaultAddress as $id => $value) {
                 if (preg_match('/"(.*)" <(.*)>/', $value, $match)) {
                     $defaults['from_email'] = $match[2];
                     $defaults['from_name'] = $match[1];
                 }
             }
         }
         $params = array_merge($defaults, $params);
     }
     /**
      * Could check and warn for the following cases:
      *
      * - groups OR mailings should be populated.
      * - body html OR body text should be populated.
      */
     $transaction = new CRM_Core_Transaction();
     $mailing = self::add($params, $ids);
     if (is_a($mailing, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $mailing;
     }
     $groupTableName = CRM_Contact_BAO_Group::getTableName();
     $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
     /* Create the mailing group record */
     $mg = new CRM_Mailing_DAO_MailingGroup();
     foreach (array('groups', 'mailings') as $entity) {
         foreach (array('include', 'exclude', 'base') as $type) {
             if (isset($params[$entity]) && CRM_Utils_Array::value($type, $params[$entity]) && is_array($params[$entity][$type])) {
                 foreach ($params[$entity][$type] as $entityId) {
                     $mg->reset();
                     $mg->mailing_id = $mailing->id;
                     $mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
                     $mg->entity_id = $entityId;
                     $mg->group_type = $type;
                     $mg->save();
                 }
             }
         }
     }
     if (!empty($params['search_id']) && !empty($params['group_id'])) {
         $mg->reset();
         $mg->mailing_id = $mailing->id;
         $mg->entity_table = $groupTableName;
         $mg->entity_id = $params['group_id'];
         $mg->search_id = $params['search_id'];
         $mg->search_args = $params['search_args'];
         $mg->group_type = 'Include';
         $mg->save();
     }
     // check and attach and files as needed
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_mailing', $mailing->id);
     $transaction->commit();
     /**
      * create parent job if not yet created
      * condition on the existence of a scheduled date
      */
     if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null') {
         $job = new CRM_Mailing_BAO_MailingJob();
         $job->mailing_id = $mailing->id;
         $job->status = 'Scheduled';
         $job->is_test = 0;
         if (!$job->find(TRUE)) {
             $job->scheduled_date = $params['scheduled_date'];
             $job->save();
         }
         // Populate the recipients.
         $mailing->getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, FALSE);
     }
     return $mailing;
 }
コード例 #17
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;
 }
コード例 #18
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;
 }
コード例 #19
0
ファイル: Group.php プロジェクト: hampelm/Ginsberg-CiviDemo
 public function postProcess()
 {
     $values = $this->controller->exportValues($this->_name);
     //build hidden smart group. when user want to send  mailing
     //through search contact-> more action -> send Mailing. CRM-3711
     $groups = array();
     if ($this->_searchBasedMailing && $this->_contactIds) {
         //get the hidden smart group id.
         $ssId = $this->get('ssID');
         $session = CRM_Core_Session::singleton();
         $hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $this->get('formValues'), 'saved_search_id' => $ssId, 'search_custom_id' => $this->get('customSearchID'), 'search_context' => $this->get('context'));
         require_once 'CRM/Contact/BAO/Group.php';
         list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
         //set the saved search id.
         if (!$ssId) {
             if ($savedSearchId) {
                 $this->set('ssID', $savedSearchId);
             } else {
                 CRM_Core_Error::fatal();
             }
         }
         //get the base group for this mailing, CRM-3711
         $groups['base'] = array($values['baseGroup']);
         $values['includeGroups'][] = $smartGroupId;
     }
     foreach (array('name', 'group_id', 'search_id', 'search_args') as $n) {
         if (CRM_Utils_Array::value($n, $values)) {
             $params[$n] = $values[$n];
         }
     }
     $qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit');
     $this->set('name', $params['name']);
     $inGroups = $values['includeGroups'];
     $outGroups = $values['excludeGroups'];
     $inMailings = $values['includeMailings'];
     $outMailings = $values['excludeMailings'];
     if (is_array($inGroups)) {
         foreach ($inGroups as $key => $id) {
             if ($id) {
                 $groups['include'][] = $id;
             }
         }
     }
     if (is_array($outGroups)) {
         foreach ($outGroups as $key => $id) {
             if ($id) {
                 $groups['exclude'][] = $id;
             }
         }
     }
     $mailings = array();
     if (is_array($inMailings)) {
         foreach ($inMailings as $key => $id) {
             if ($id) {
                 $mailings['include'][] = $id;
             }
         }
     }
     if (is_array($outMailings)) {
         foreach ($outMailings as $key => $id) {
             if ($id) {
                 $mailings['exclude'][] = $id;
             }
         }
     }
     $session = CRM_Core_Session::singleton();
     $params['groups'] = $groups;
     $params['mailings'] = $mailings;
     if ($this->get('mailing_id')) {
         $ids = array();
         // don't create a new mailing if already exists
         $ids['mailing_id'] = $this->get('mailing_id');
         $groupTableName = CRM_Contact_BAO_Group::getTableName();
         $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
         // delete previous includes/excludes, if mailing already existed
         require_once 'CRM/Contact/DAO/Group.php';
         foreach (array('groups', 'mailings') as $entity) {
             $mg = new CRM_Mailing_DAO_Group();
             $mg->mailing_id = $ids['mailing_id'];
             $mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
             $mg->find();
             while ($mg->fetch()) {
                 $mg->delete();
             }
         }
     } else {
         // new mailing, so lets set the created_id
         $session = CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
     $this->set('mailing_id', $mailing->id);
     $count = CRM_Mailing_BAO_Mailing::getRecipientsCount(true, false, $mailing->id);
     $this->set('count', $count);
     $this->assign('count', $count);
     $this->set('groups', $groups);
     $this->set('mailings', $mailings);
     if ($qf_Group_submit) {
         //when user perform mailing from search context
         //redirect it to search result CRM-3711.
         $ssID = $this->get('ssID');
         $context = $this->get('context');
         if ($ssID && $this->_searchBasedMailing) {
             if ($this->_action == CRM_Core_Action::BASIC) {
                 $fragment = 'search';
             } else {
                 if ($this->_action == CRM_Core_Action::PROFILE) {
                     $fragment = 'search/builder';
                 } else {
                     if ($this->_action == CRM_Core_Action::ADVANCED) {
                         $fragment = 'search/advanced';
                     } else {
                         $fragment = 'search/custom';
                     }
                 }
             }
             $context = $this->get('context');
             if (!CRM_Contact_Form_Search::isSearchContext($context)) {
                 $context = 'search';
             }
             $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
             if (CRM_Utils_Rule::qfKey($qfKey)) {
                 $urlParams .= "&qfKey={$qfKey}";
             }
             $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
             CRM_Core_Session::setStatus($status);
             //replace user context to search.
             $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
             CRM_Utils_System::redirect($url);
         } else {
             $status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it.");
             CRM_Core_Session::setStatus($status);
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             CRM_Utils_System::redirect($url);
         }
     }
 }
コード例 #20
0
ファイル: Browse.php プロジェクト: bhirsch/voipdev
 /**
  * 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)
 {
     require_once 'CRM/Mailing/BAO/Mailing.php';
     require_once 'CRM/Mailing/BAO/Job.php';
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     if (!isset(self::$_columnHeaders)) {
         self::$_columnHeaders = array(array('name' => ts('Mailing Name'), 'sort' => 'name', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Status'), 'sort' => 'status', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Created By'), 'sort' => 'created_by', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Sent By'), 'sort' => 'scheduled_by', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Scheduled'), 'sort' => 'scheduled_date', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Started'), 'sort' => 'start_date', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Completed'), 'sort' => 'end_date', 'direction' => CRM_Utils_Sort::DESCENDING));
         if ($output != CRM_Core_Selector_Controller::EXPORT) {
             self::$_columnHeaders[] = array('name' => ts('Action'));
         }
     }
     return self::$_columnHeaders;
 }
コード例 #21
0
ファイル: Group.php プロジェクト: sarehag/civicrm-core
 public function postProcess()
 {
     $values = $this->controller->exportValues($this->_name);
     $groups = array();
     foreach (array('name', 'group_id', 'is_sms') as $n) {
         if (!empty($values[$n])) {
             $params[$n] = $values[$n];
         }
     }
     $qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit');
     $this->set('name', $params['name']);
     $inGroups = $values['includeGroups'];
     $outGroups = $values['excludeGroups'];
     $inMailings = $values['includeMailings'];
     $outMailings = $values['excludeMailings'];
     if (is_array($inGroups)) {
         foreach ($inGroups as $key => $id) {
             if ($id) {
                 $groups['include'][] = $id;
             }
         }
     }
     if (is_array($outGroups)) {
         foreach ($outGroups as $key => $id) {
             if ($id) {
                 $groups['exclude'][] = $id;
             }
         }
     }
     $mailings = array();
     if (is_array($inMailings)) {
         foreach ($inMailings as $key => $id) {
             if ($id) {
                 $mailings['include'][] = $id;
             }
         }
     }
     if (is_array($outMailings)) {
         foreach ($outMailings as $key => $id) {
             if ($id) {
                 $mailings['exclude'][] = $id;
             }
         }
     }
     $session = CRM_Core_Session::singleton();
     $params['groups'] = $groups;
     $params['mailings'] = $mailings;
     $ids = array();
     if ($this->get('mailing_id')) {
         // don't create a new mass sms if already exists
         $ids['mailing_id'] = $this->get('mailing_id');
         $groupTableName = CRM_Contact_BAO_Group::getTableName();
         $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName();
         // delete previous includes/excludes, if mailing already existed
         foreach (array('groups', 'mailings') as $entity) {
             $mg = new CRM_Mailing_DAO_MailingGroup();
             $mg->mailing_id = $ids['mailing_id'];
             $mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName;
             $mg->find();
             while ($mg->fetch()) {
                 $mg->delete();
             }
         }
     } else {
         // new mailing, so lets set the created_id
         $session = CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
     $this->set('mailing_id', $mailing->id);
     // also compute the recipients and store them in the mailing recipients table
     CRM_Mailing_BAO_Mailing::getRecipients($mailing->id, $mailing->id, TRUE, FALSE, 'sms');
     $count = CRM_Mailing_BAO_Recipients::mailingSize($mailing->id);
     $this->set('count', $count);
     $this->assign('count', $count);
     $this->set('groups', $groups);
     $this->set('mailings', $mailings);
     if ($qf_Group_submit) {
         $status = ts("Your Mass SMS has been saved.");
         CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
         $url = CRM_Utils_System::url('civicrm/mailing', 'reset=1&sms=1');
         return $this->controller->setDestination($url);
     }
 }
コード例 #22
0
ファイル: Browse.php プロジェクト: bhirsch/voipdrupal-4.7-1.0
 /**
  * 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)
 {
     require_once 'CRM/Mailing/BAO/Mailing.php';
     require_once 'CRM/Mailing/BAO/Job.php';
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     if (!isset($GLOBALS['_CRM_MAILING_SELECTOR_BROWSE']['_columnHeaders'])) {
         $GLOBALS['_CRM_MAILING_SELECTOR_BROWSE']['_columnHeaders'] = array(array('name' => ts('Mailing Name')), array('name' => ts('Status')), array('name' => ts('Scheduled Date')), array('name' => ts('Start Date')), array('name' => ts('Completed Date')));
         if ($output != CRM_CORE_SELECTOR_CONTROLLER_EXPORT) {
             $GLOBALS['_CRM_MAILING_SELECTOR_BROWSE']['_columnHeaders'][] = array('name' => ts('Action'));
         }
     }
     return $GLOBALS['_CRM_MAILING_SELECTOR_BROWSE']['_columnHeaders'];
 }