Merge pull request #4981 from totten/master-cbf2
[civicrm-core.git] / CRM / Contact / Form / Task / Unhold.php
CommitLineData
6a488035 1<?php
86538308
EM
2
3/**
4 * Class CRM_Contact_Form_Task_Unhold
5 */
6a488035
TO
6class CRM_Contact_Form_Task_Unhold extends CRM_Contact_Form_Task {
7
8 /**
100fef9d 9 * Set variables up before form is built
6a488035
TO
10 *
11 * @return void
6a488035 12 */
00be9182 13 public function preProcess() {
6a488035
TO
14 parent::preProcess();
15 }
16
00be9182 17 public function buildQuickForm() {
6a488035
TO
18 $this->addDefaultButtons(ts('Unhold Email'), 'done');
19 }
20
21 public function postProcess() {
22 // Query to unhold emails of selected contacts
23 $num = count($this->_contactIds);
24 if ($num >= 1) {
25 $queryString = "
8ef12e64 26UPDATE civicrm_email SET on_hold = 0, hold_date = null
6a488035
TO
27WHERE on_hold = 1 AND hold_date is not null AND contact_id in (" . implode(",", $this->_contactIds) . ")";
28 CRM_Core_DAO::executeQuery($queryString);
29 $sql = "SELECT ROW_COUNT( )";
30 $result = CRM_Core_DAO::singleValueQuery($sql);
31 if ($result) {
353ffa53
TO
32 CRM_Core_Session::setStatus(ts('%count email was found on hold and updated.', array(
33 'count' => $result,
795492f3 34 'plural' => '%count emails were found on hold and updated.',
353ffa53 35 )), ts('Emails Restored'), 'success');
6a488035
TO
36 }
37 else {
353ffa53
TO
38 CRM_Core_Session::setStatus(ts('The selected contact does not have an email on hold.', array(
39 'count' => $result,
795492f3 40 'plural' => 'None of the selected contacts have an email on hold.',
353ffa53 41 )), ts('No Emails to Restore'), 'info');
6a488035
TO
42 }
43 }
44 else {
45 CRM_Core_Session::setStatus(ts('Please select one or more contact for this action'), ts('No Contacts Selected'), 'error');
46 }
47 }
96025800 48
6a488035 49}