Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
6a488035 TO |
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 | ||
bc3f7f04 | 47 | CRM_Core_Form_Date::buildDateRange($this, 'mailing', 1, '_from', '_to', ts('From'), FALSE); |
6a488035 TO |
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 | ||
d4ad3b22 | 55 | // CRM-15434 - Fix mailing search by status in non-English languages |
7236e25f | 56 | $statusVals = CRM_Core_SelectValues::getMailingJobStatus(); |
d4ad3b22 | 57 | foreach ($statusVals as $statusId => $statusName) { |
58 | $this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName); | |
6a488035 | 59 | } |
7ccbe556 | 60 | $this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled')); |
8a4f27dc | 61 | $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE); |
f6df2c32 | 62 | |
c00b95ef ML |
63 | // Search by language, if multi-lingual |
64 | $enabledLanguages = CRM_Core_I18n::languages(TRUE); | |
65 | ||
66 | if (count($enabledLanguages) > 1) { | |
349218d7 | 67 | $this->addElement('select', 'language', ts('Language'), array('' => ts('- all languages -')) + $enabledLanguages, array('class' => 'crm-select2')); |
c00b95ef ML |
68 | } |
69 | ||
6a488035 TO |
70 | if ($parent->_sms) { |
71 | $this->addElement('hidden', 'sms', $parent->_sms); | |
72 | } | |
f5d7a1ab | 73 | $this->add('hidden', 'hidden_find_mailings', 1); |
6a488035 TO |
74 | |
75 | $this->addButtons(array( | |
353ffa53 TO |
76 | array( |
77 | 'type' => 'refresh', | |
78 | 'name' => ts('Search'), | |
79 | 'isDefault' => TRUE, | |
80 | ), | |
81 | )); | |
6a488035 TO |
82 | } |
83 | ||
e0ef6999 EM |
84 | /** |
85 | * @return array | |
86 | */ | |
00be9182 | 87 | public function setDefaultValues() { |
6ff6d85a | 88 | $defaults = $statusVals = array(); |
cbb4cb7b PJ |
89 | $parent = $this->controller->getParent(); |
90 | ||
f6df2c32 DS |
91 | if ($parent->get('unscheduled')) { |
92 | $defaults['status_unscheduled'] = 1; | |
93 | } | |
f6df2c32 DS |
94 | if ($parent->get('scheduled')) { |
95 | $statusVals = array('Scheduled', 'Complete', 'Running', 'Canceled'); | |
f6df2c32 DS |
96 | $defaults['is_archived'] = 0; |
97 | } | |
f6df2c32 DS |
98 | if ($parent->get('archived')) { |
99 | $defaults['is_archived'] = 1; | |
6a488035 | 100 | } |
6ff6d85a DS |
101 | foreach ($statusVals as $status) { |
102 | $defaults['mailing_status'][$status] = 1; | |
103 | } | |
6a488035 | 104 | |
6a488035 TO |
105 | if ($parent->_sms) { |
106 | $defaults['sms'] = 1; | |
107 | } | |
108 | return $defaults; | |
109 | } | |
110 | ||
00be9182 | 111 | public function postProcess() { |
6a488035 TO |
112 | $params = $this->controller->exportValues($this->_name); |
113 | ||
114 | CRM_Contact_BAO_Query::fixDateValues($params["mailing_relative"], $params['mailing_from'], $params['mailing_to']); | |
115 | ||
116 | $parent = $this->controller->getParent(); | |
117 | if (!empty($params)) { | |
353ffa53 TO |
118 | $fields = array( |
119 | 'mailing_name', | |
120 | 'mailing_from', | |
121 | 'mailing_to', | |
122 | 'sort_name', | |
123 | 'campaign_id', | |
124 | 'mailing_status', | |
125 | 'sms', | |
126 | 'status_unscheduled', | |
127 | 'is_archived', | |
c00b95ef | 128 | 'language', |
795492f3 | 129 | 'hidden_find_mailings', |
353ffa53 | 130 | ); |
6a488035 TO |
131 | foreach ($fields as $field) { |
132 | if (isset($params[$field]) && | |
133 | !CRM_Utils_System::isNull($params[$field]) | |
134 | ) { | |
135 | if (in_array($field, array( | |
353ffa53 | 136 | 'mailing_from', |
795492f3 | 137 | 'mailing_to', |
353ffa53 TO |
138 | )) && !$params["mailing_relative"] |
139 | ) { | |
6a488035 TO |
140 | $time = ($field == 'mailing_to') ? '235959' : NULL; |
141 | $parent->set($field, CRM_Utils_Date::processDate($params[$field], $time)); | |
142 | } | |
143 | else { | |
144 | $parent->set($field, $params[$field]); | |
145 | } | |
146 | } | |
147 | else { | |
148 | $parent->set($field, NULL); | |
149 | } | |
150 | } | |
151 | } | |
152 | } | |
96025800 | 153 | |
6a488035 | 154 | } |