Merge pull request #8634 from konadave/CRM-19007-master
[civicrm-core.git] / CRM / Mailing / Form / Search.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2016
32 */
33 class CRM_Mailing_Form_Search extends CRM_Core_Form {
34
35 public function preProcess() {
36 parent::preProcess();
37 }
38
39 public function buildQuickForm() {
40 $parent = $this->controller->getParent();
41 $nameTextLabel = ($parent->_sms) ? ts('SMS Name') : ts('Mailing Name');
42
43 $this->add('text', 'mailing_name', $nameTextLabel,
44 CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'title')
45 );
46
47 CRM_Core_Form_Date::buildDateRange($this, 'mailing', 1, '_from', '_to', ts('From'), FALSE);
48
49 $this->add('text', 'sort_name', ts('Created or Sent by'),
50 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
51 );
52
53 CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this);
54
55 // CRM-15434 - Fix mailing search by status in non-English languages
56 $statusVals = CRM_Core_SelectValues::getMailingJobStatus();
57 foreach ($statusVals as $statusId => $statusName) {
58 $this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName);
59 }
60 $this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled'));
61 $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE);
62
63 if ($parent->_sms) {
64 $this->addElement('hidden', 'sms', $parent->_sms);
65 }
66 $this->add('hidden', 'hidden_find_mailings', 1);
67
68 $this->addButtons(array(
69 array(
70 'type' => 'refresh',
71 'name' => ts('Search'),
72 'isDefault' => TRUE,
73 ),
74 ));
75 }
76
77 /**
78 * @return array
79 */
80 public function setDefaultValues() {
81 $defaults = $statusVals = array();
82 $parent = $this->controller->getParent();
83
84 if ($parent->get('unscheduled')) {
85 $defaults['status_unscheduled'] = 1;
86 }
87 if ($parent->get('scheduled')) {
88 $statusVals = array('Scheduled', 'Complete', 'Running', 'Canceled');
89 $defaults['is_archived'] = 0;
90 }
91 if ($parent->get('archived')) {
92 $defaults['is_archived'] = 1;
93 }
94 foreach ($statusVals as $status) {
95 $defaults['mailing_status'][$status] = 1;
96 }
97
98 if ($parent->_sms) {
99 $defaults['sms'] = 1;
100 }
101 return $defaults;
102 }
103
104 public function postProcess() {
105 $params = $this->controller->exportValues($this->_name);
106
107 CRM_Contact_BAO_Query::fixDateValues($params["mailing_relative"], $params['mailing_from'], $params['mailing_to']);
108
109 $parent = $this->controller->getParent();
110 if (!empty($params)) {
111 $fields = array(
112 'mailing_name',
113 'mailing_from',
114 'mailing_to',
115 'sort_name',
116 'campaign_id',
117 'mailing_status',
118 'sms',
119 'status_unscheduled',
120 'is_archived',
121 'hidden_find_mailings',
122 );
123 foreach ($fields as $field) {
124 if (isset($params[$field]) &&
125 !CRM_Utils_System::isNull($params[$field])
126 ) {
127 if (in_array($field, array(
128 'mailing_from',
129 'mailing_to',
130 )) && !$params["mailing_relative"]
131 ) {
132 $time = ($field == 'mailing_to') ? '235959' : NULL;
133 $parent->set($field, CRM_Utils_Date::processDate($params[$field], $time));
134 }
135 else {
136 $parent->set($field, $params[$field]);
137 }
138 }
139 else {
140 $parent->set($field, NULL);
141 }
142 }
143 }
144 }
145
146 }