copyright and version fixes
[civicrm-core.git] / CRM / Mailing / Form / Search.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
f6df2c32
DS
57 $statusVals = array('Scheduled', 'Complete', 'Running', 'Canceled');
58 foreach ($statusVals as $status) {
59 $this->addElement('checkbox', "mailing_status[$status]", NULL, $status);
6a488035 60 }
f6df2c32 61 $this->addElement('checkbox', 'status_unscheduled', NULL, 'Draft / Unscheduled');
8a4f27dc 62 $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE);
f6df2c32 63
6a488035
TO
64 if ($parent->_sms) {
65 $this->addElement('hidden', 'sms', $parent->_sms);
66 }
f5d7a1ab 67 $this->add('hidden', 'hidden_find_mailings', 1);
6a488035
TO
68
69 $this->addButtons(array(
70 array(
71 'type' => 'refresh',
72 'name' => ts('Search'),
73 'isDefault' => TRUE,
74 ),
75 ));
76 }
77
78 function setDefaultValues() {
6ff6d85a 79 $defaults = $statusVals = array();
cbb4cb7b
PJ
80 $parent = $this->controller->getParent();
81
f6df2c32
DS
82 if ($parent->get('unscheduled')) {
83 $defaults['status_unscheduled'] = 1;
84 }
f6df2c32
DS
85 if ($parent->get('scheduled')) {
86 $statusVals = array('Scheduled', 'Complete', 'Running', 'Canceled');
f6df2c32
DS
87 $defaults['is_archived'] = 0;
88 }
f6df2c32
DS
89 if ($parent->get('archived')) {
90 $defaults['is_archived'] = 1;
6a488035 91 }
6ff6d85a
DS
92 foreach ($statusVals as $status) {
93 $defaults['mailing_status'][$status] = 1;
94 }
6a488035 95
6a488035
TO
96 if ($parent->_sms) {
97 $defaults['sms'] = 1;
98 }
99 return $defaults;
100 }
101
102 function postProcess() {
103 $params = $this->controller->exportValues($this->_name);
104
105 CRM_Contact_BAO_Query::fixDateValues($params["mailing_relative"], $params['mailing_from'], $params['mailing_to']);
106
107 $parent = $this->controller->getParent();
108 if (!empty($params)) {
f6df2c32 109 $fields = array('mailing_name', 'mailing_from', 'mailing_to', 'sort_name',
f5d7a1ab 110 'campaign_id', 'mailing_status', 'sms', 'status_unscheduled', 'is_archived', 'hidden_find_mailings');
6a488035
TO
111 foreach ($fields as $field) {
112 if (isset($params[$field]) &&
113 !CRM_Utils_System::isNull($params[$field])
114 ) {
115 if (in_array($field, array(
116 'mailing_from', 'mailing_to')) && !$params["mailing_relative"]) {
117 $time = ($field == 'mailing_to') ? '235959' : NULL;
118 $parent->set($field, CRM_Utils_Date::processDate($params[$field], $time));
119 }
120 else {
121 $parent->set($field, $params[$field]);
122 }
123 }
124 else {
125 $parent->set($field, NULL);
126 }
127 }
128 }
129 }
130}
131