Commit | Line | Data |
---|---|---|
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 | */ | |
35 | class CRM_Mailing_Form_ForwardMailing extends CRM_Core_Form { | |
36 | function preProcess() { | |
37 | $job_id = CRM_Utils_Request::retrieve('jid', 'Positive', | |
38 | $this, NULL | |
39 | ); | |
40 | $queue_id = CRM_Utils_Request::retrieve('qid', 'Positive', | |
41 | $this, NULL | |
42 | ); | |
43 | $hash = CRM_Utils_Request::retrieve('h', 'String', | |
44 | $this, NULL | |
45 | ); | |
46 | ||
47 | $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash); | |
48 | ||
49 | if ($q == NULL) { | |
50 | ||
51 | /** ERROR **/ | |
52 | CRM_Core_Error::fatal(ts('Invalid form parameters.')); | |
53 | CRM_Core_Error::statusBounce(ts('Invalid form parameters.')); | |
54 | } | |
55 | $mailing = &$q->getMailing(); | |
56 | ||
57 | if ($hash) { | |
58 | $emailId = CRM_Core_DAO::getfieldValue('CRM_Mailing_Event_DAO_Queue', $hash, 'email_id', 'hash'); | |
59 | $this->_fromEmail = $fromEmail = CRM_Core_DAO::getfieldValue('CRM_Core_DAO_Email', $emailId, 'email'); | |
60 | $this->assign('fromEmail', $fromEmail); | |
61 | } | |
62 | ||
63 | /* Show the subject instead of the name here, since it's being | |
64 | * displayed to external contacts/users */ | |
65 | ||
66 | CRM_Utils_System::setTitle(ts('Forward Mailing: %1', array(1 => $mailing->subject))); | |
67 | ||
68 | $this->set('queue_id', $queue_id); | |
69 | $this->set('job_id', $job_id); | |
70 | $this->set('hash', $hash); | |
71 | } | |
72 | ||
73 | /** | |
74 | * Function to actually build the form | |
75 | * | |
76 | * @return None | |
77 | * @access public | |
78 | */ | |
79 | public function buildQuickForm() { | |
80 | for ($i = 0; $i < 5; $i++) { | |
81 | $this->add('text', "email_$i", ts('Email %1', array(1 => $i + 1))); | |
82 | $this->addRule("email_$i", ts('Email is not valid.'), 'email'); | |
83 | } | |
84 | ||
85 | //insert message Text by selecting "Select Template option" | |
86 | $this->add('textarea', 'forward_comment', ts('Comment'), array('cols' => '80', 'rows' => '8')); | |
87 | $this->addWysiwyg('html_comment', | |
88 | ts('HTML Message'), | |
89 | array('cols' => '80', 'rows' => '8') | |
90 | ); | |
91 | ||
92 | $this->addButtons(array( | |
93 | array( | |
94 | 'type' => 'next', | |
95 | 'name' => ts('Forward'), | |
96 | 'isDefault' => TRUE, | |
97 | ), | |
98 | array( | |
99 | 'type' => 'cancel', | |
100 | 'name' => ts('Cancel'), | |
101 | ), | |
102 | )); | |
103 | } | |
104 | ||
105 | /** | |
106 | * Form submission of new/edit contact is processed. | |
107 | * | |
108 | * @access public | |
109 | * | |
110 | * @return None | |
111 | */ | |
112 | public function postProcess() { | |
113 | $queue_id = $this->get('queue_id'); | |
114 | $job_id = $this->get('job_id'); | |
115 | $hash = $this->get('hash'); | |
116 | $timeStamp = date('YmdHis'); | |
117 | ||
118 | $formValues = $this->controller->exportValues($this->_name); | |
119 | $params = array(); | |
120 | $params['body_text'] = $formValues['forward_comment']; | |
121 | $html_comment = $formValues['html_comment']; | |
122 | $params['body_html'] = str_replace('%7B', '{', str_replace('%7D', '}', $html_comment)); | |
123 | ||
124 | $emails = array(); | |
125 | for ($i = 0; $i < 5; $i++) { | |
126 | $email = $this->controller->exportValue($this->_name, "email_$i"); | |
127 | if (!empty($email)) { | |
128 | $emails[] = $email; | |
129 | } | |
130 | } | |
131 | ||
132 | $forwarded = NULL; | |
133 | foreach ($emails as $email) { | |
134 | $params = array( | |
135 | 'version' => 3, | |
136 | 'job_id' => $job_id, | |
137 | 'event_queue_id' => $queue_id, | |
138 | 'hash' => $hash, | |
139 | 'email' => $email, | |
140 | 'time_stamp' => $timeStamp, | |
141 | 'fromEmail' => $this->_fromEmail, | |
142 | 'params' => $params, | |
143 | ); | |
144 | $result = civicrm_api('Mailing', 'event_forward', $params); | |
145 | if (!civicrm_error($result)) { | |
146 | $forwarded++; | |
147 | } | |
148 | } | |
149 | ||
150 | $status = ts('Mailing is not forwarded to the given email address.', array('count' => count($emails), 'plural' => 'Mailing is not forwarded to the given email addresses.')); | |
151 | if ($forwarded) { | |
152 | $status = ts('Mailing is forwarded successfully to %count email address.', array('count' => $forwarded, 'plural' => 'Mailing is forwarded successfully to %count email addresses.')); | |
153 | } | |
154 | ||
155 | CRM_Utils_System::setUFMessage($status); | |
156 | ||
157 | // always redirect to front page of url | |
158 | $session = CRM_Core_Session::singleton(); | |
159 | $config = CRM_Core_Config::singleton(); | |
160 | $session->pushUserContext($config->userFrameworkBaseURL); | |
161 | } | |
162 | } | |
163 |