Merge pull request #4955 from atif-shaikh/master-cleanup
[civicrm-core.git] / CRM / Mailing / Form / Search.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35class CRM_Mailing_Form_Search extends CRM_Core_Form {
36
37 public function preProcess() {
38 parent::preProcess();
39 }
40
41 public function buildQuickForm() {
42 $parent = $this->controller->getParent();
43 $nameTextLabel = ($parent->_sms) ? ts('SMS Name') : ts('Mailing Name');
44
45 $this->add('text', 'mailing_name', $nameTextLabel,
46 CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'title')
47 );
48
bc3f7f04 49 CRM_Core_Form_Date::buildDateRange($this, 'mailing', 1, '_from', '_to', ts('From'), FALSE);
6a488035
TO
50
51 $this->add('text', 'sort_name', ts('Created or Sent by'),
52 CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
53 );
54
55 CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this);
56
d4ad3b22 57 // CRM-15434 - Fix mailing search by status in non-English languages
7236e25f 58 $statusVals = CRM_Core_SelectValues::getMailingJobStatus();
d4ad3b22 59 foreach ($statusVals as $statusId => $statusName) {
60 $this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName);
6a488035 61 }
7ccbe556 62 $this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled'));
8a4f27dc 63 $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE);
f6df2c32 64
6a488035
TO
65 if ($parent->_sms) {
66 $this->addElement('hidden', 'sms', $parent->_sms);
67 }
f5d7a1ab 68 $this->add('hidden', 'hidden_find_mailings', 1);
6a488035
TO
69
70 $this->addButtons(array(
353ffa53
TO
71 array(
72 'type' => 'refresh',
73 'name' => ts('Search'),
74 'isDefault' => TRUE,
75 ),
76 ));
6a488035
TO
77 }
78
e0ef6999
EM
79 /**
80 * @return array
81 */
00be9182 82 public function setDefaultValues() {
6ff6d85a 83 $defaults = $statusVals = array();
cbb4cb7b
PJ
84 $parent = $this->controller->getParent();
85
f6df2c32
DS
86 if ($parent->get('unscheduled')) {
87 $defaults['status_unscheduled'] = 1;
88 }
f6df2c32
DS
89 if ($parent->get('scheduled')) {
90 $statusVals = array('Scheduled', 'Complete', 'Running', 'Canceled');
f6df2c32
DS
91 $defaults['is_archived'] = 0;
92 }
f6df2c32
DS
93 if ($parent->get('archived')) {
94 $defaults['is_archived'] = 1;
6a488035 95 }
6ff6d85a
DS
96 foreach ($statusVals as $status) {
97 $defaults['mailing_status'][$status] = 1;
98 }
6a488035 99
6a488035
TO
100 if ($parent->_sms) {
101 $defaults['sms'] = 1;
102 }
103 return $defaults;
104 }
105
00be9182 106 public function postProcess() {
6a488035
TO
107 $params = $this->controller->exportValues($this->_name);
108
109 CRM_Contact_BAO_Query::fixDateValues($params["mailing_relative"], $params['mailing_from'], $params['mailing_to']);
110
111 $parent = $this->controller->getParent();
112 if (!empty($params)) {
353ffa53
TO
113 $fields = array(
114 'mailing_name',
115 'mailing_from',
116 'mailing_to',
117 'sort_name',
118 'campaign_id',
119 'mailing_status',
120 'sms',
121 'status_unscheduled',
122 'is_archived',
795492f3 123 'hidden_find_mailings',
353ffa53 124 );
6a488035
TO
125 foreach ($fields as $field) {
126 if (isset($params[$field]) &&
127 !CRM_Utils_System::isNull($params[$field])
128 ) {
129 if (in_array($field, array(
353ffa53 130 'mailing_from',
795492f3 131 'mailing_to',
353ffa53
TO
132 )) && !$params["mailing_relative"]
133 ) {
6a488035
TO
134 $time = ($field == 'mailing_to') ? '235959' : NULL;
135 $parent->set($field, CRM_Utils_Date::processDate($params[$field], $time));
136 }
137 else {
138 $parent->set($field, $params[$field]);
139 }
140 }
141 else {
142 $parent->set($field, NULL);
143 }
144 }
145 }
146 }
147}