/
Message.php
234 lines (194 loc) · 8.6 KB
/
Message.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Message extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('lib_auth');
if (!$this->lib_auth->is_logged_in())
{
redirect();
}
$this->load->library('lib_message');
}
public function index($filter = NULL) // list-unsubscribe, type
{
$local_view_data['list'] = $this->lib_message->get_list();
$view_data['is_logged_in'] = $this->lib_auth->is_logged_in();
$view_data['main_content'] = $this->load->view('message/list', $local_view_data, TRUE);
$this->load->view('base', $view_data);
// $this->load->library('lib_message');
// $local_view_data['list'] = $this->lib_message->get_list_transactional();
// $view_data['is_logged_in'] = $this->lib_auth->is_logged_in();
// $view_data['main_content'] = $this->load->view('message/list', $local_view_data, TRUE);
// $this->load->view('base', $view_data);
}
public function view($message_id = 0, $type = NULL)
{
$message = $this->lib_message->get($message_id);
if (empty($message)) show_404();
if ($type == 'html' OR $type == 'text' OR $type == 'html_input')
{
echo $message['body_'.$type]; die();
}
$local_view_data['message'] = $message;
$view_data['is_logged_in'] = $this->lib_auth->is_logged_in();
$view_data['main_content'] = $this->load->view('message/view', $local_view_data, TRUE);
$this->load->view('base', $view_data);
}
public function create($list)
{
$this->load->library('lib_list_unsubscribe');
$list_unsubscribe = $this->lib_list_unsubscribe->get_by_name($list);
if (empty($list_unsubscribe))
{
show_error('List: '.$list.' not found');
}
$local_view_data = [];
$local_view_data['list_unsubscribe'] = $list_unsubscribe;
$this->load->library('form_validation');
if ($this->form_validation->run())
{
if (is_null($message_id = $this->lib_message->create(
$this->form_validation->set_value('subject'),
$list_unsubscribe['list_id']
)))
{
show_error($this->lib_message->get_error_message());
}
else
{
redirect('message/edit/'.$message_id);
}
}
$view_data['is_logged_in'] = $this->lib_auth->is_logged_in();
$view_data['main_content'] = $this->load->view('message/create', $local_view_data, TRUE);
$this->load->view('base', $view_data);
}
public function edit($message_id = 0)
{
$message = $this->lib_message->get($message_id);
if (empty($message)) show_404();
$local_view_data = [];
$local_view_data['message'] = $message;
if ($message['archived'] != '1000-01-01 00:00:00')
{
show_error('The message is archived and can not be modified');
}
$this->load->library('form_validation');
if ($this->form_validation->run('message/edit'))
{
if (is_null($this->lib_message->update(
$message,
$this->form_validation->set_value('subject'),
$this->form_validation->set_value('body_html_input'),
$this->form_validation->set_value('reply_to_name'),
$this->form_validation->set_value('reply_to_email')
)))
{
show_error($this->lib_message->get_error_message());
}
else
{
$this->session->set_flashdata('alert', ['type' => 'success', 'message' => '<abbr class="text-nowrap pull-right" title="Patience Young Grasshopper http://emojicons.com/e/patience-young-grasshopper"> ┬─┬ ノ( ゜-゜ノ)</abbr>
<strong>Updated:</strong> Message is successfuly updated']);
redirect('message/view/'.$message_id);
}
}
$view_data['main_content'] = $this->load->view('message/edit', $local_view_data, TRUE);
$view_data['is_logged_in'] = $this->lib_auth->is_logged_in();
$this->load->view('base', $view_data);
}
public function publish($message_id = NULL)
{
$message = $this->lib_message->get($message_id);
if (empty($message)) show_404();
$local_view_data = [];
$local_view_data['message'] = $message;
if ($message['archived'] != '1000-01-01 00:00:00')
{
show_error('The message is archived and can not be modified');
}
$this->load->library('form_validation');
// if ($message['type'] == 'transactional')
// {
// $this->form_validation->set_data(['php_datetime_str' => 'now']);
// }
if ($this->form_validation->run('message/publish'))
{
if (is_null($this->lib_message->publish($message, $this->form_validation->set_value('php_datetime_str'))))
{
show_error($this->lib_message->get_error_message());
}
else
{
$this->session->set_flashdata('alert', ['type' => 'success', 'message' => '<abbr class="text-nowrap pull-right" title="Magical Table Flipping http://emojicons.com/e/magical-table-flipping"> (/¯◡ ‿ ◡)/¯ ~ ┻━┻</abbr>
<strong>Hooah</strong> /ˈhuːɑː/ Message was successfuly published']);
redirect('message/view/'.$message_id);
}
}
$view_data['main_content'] = $this->load->view('message/publish', $local_view_data, TRUE);
$view_data['is_logged_in'] = $this->lib_auth->is_logged_in();
$this->load->view('base', $view_data);
}
public function archive($message_id = NULL)
{
if (is_null($this->lib_message->archive($message_id)))
{
show_error($this->lib_message->get_error_message());
}
else
{
$this->session->set_flashdata('alert', ['type' => 'warning', 'message' => '<abbr class="text-nowrap pull-right" title="Flipping Tables http://emojicons.com/e/flipping-tables"> (╯°□°)╯︵ ┻━┻</abbr>
<strong>Archive</strong> Message has been archived']);
redirect('message/view/'.$message_id);
}
}
public function unarchive($message_id = NULL)
{
if (is_null($type = $this->lib_message->unarchive($message_id)))
{
show_error($this->lib_message->get_error_message());
}
else
{
if ($type == 'transactional')
{
$this->session->set_flashdata('alert', ['type' => 'success', 'message' => '<abbr class="text-nowrap pull-right" title="Magical Table Flipping http://emojicons.com/e/magical-table-flipping"> (/¯◡ ‿ ◡)/¯ ~ ┻━┻</abbr>
<strong>Hooah</strong> /ˈhuːɑː/ Message was successfuly published']);
}
else
{
$this->session->set_flashdata('alert', ['type' => 'info', 'message' => '<abbr class="text-nowrap pull-right" title="Patience Young Grasshopper http://emojicons.com/e/patience-young-grasshopper"> ┬─┬ ノ( ゜-゜ノ)</abbr>
<strong>Archive</strong> Message has been revert to draft']);
}
redirect('message/view/'.$message_id);
}
}
public function send_test($message_id = NULL)
{
$message = $this->lib_message->get($message_id);
if (empty($message)) show_404();
$local_view_data = [];
$local_view_data['message'] = $message;
$this->load->library('form_validation');
if ($this->form_validation->run('message/send_test'))
{
$to_email = $this->form_validation->set_value('email');
$this->load->library('lib_send_email');
if (is_null($this->lib_send_email->direct(
$to_email, $message['subject'], $message['body_html'], $message['body_text']
)))
{
show_error($this->lib_message->get_error_message());
}
else
{
$this->session->set_flashdata('alert', ['type' => 'info', 'message' => '<abbr class="text-nowrap pull-right" title="Glomp http://emojicons.com/e/glomp"> (づ ̄ ³ ̄)づ</abbr>
<strong>On its way!</strong> Check your inbox ('.$to_email.')']);
redirect('message/view/'.$message_id);
}
}
}
}