-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_edit.php
349 lines (312 loc) · 13.7 KB
/
message_edit.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <[email protected]>
Portions created by the Initial Developer are Copyright (C) 2018 - 2019
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <[email protected]>
*/
//includes
require_once "root.php";
require_once "resources/require.php";
//check permissions
require_once "resources/check_auth.php";
if (permission_exists('message_add') || permission_exists('message_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//action add or update
if (is_uuid($_REQUEST["id"])) {
$action = "update";
$message_uuid = $_REQUEST["id"];
}
else {
$action = "add";
}
//get http post variables and set them to php variables
if (is_array($_POST)) {
$message_uuid = $_POST["message_uuid"];
//$user_uuid = $_POST["user_uuid"];
$message_type = $_POST["message_type"];
$message_direction = $_POST["message_direction"];
$message_date = $_POST["message_date"];
$message_from = $_POST["message_from"];
$message_to = $_POST["message_to"];
$message_text = $_POST["message_text"];
$message_media_type = $_POST["message_media_type"];
$message_media_url = $_POST["message_media_url"];
$message_media_content = $_POST["message_media_content"];
$message_json = $_POST["message_json"];
}
//process the user data and save it to the database
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//get the uuid from the POST
if ($action == "update") {
$message_uuid = $_POST["message_uuid"];
}
//check for all required data
$msg = '';
//if (strlen($user_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-user_uuid']."<br>\n"; }
if (strlen($message_type) == 0) { $msg .= $text['message-required']." ".$text['label-message_type']."<br>\n"; }
if (strlen($message_direction) == 0) { $msg .= $text['message-required']." ".$text['label-message_direction']."<br>\n"; }
if (strlen($message_date) == 0) { $msg .= $text['message-required']." ".$text['label-message_date']."<br>\n"; }
if (strlen($message_from) == 0) { $msg .= $text['message-required']." ".$text['label-message_from']."<br>\n"; }
if (strlen($message_to) == 0) { $msg .= $text['message-required']." ".$text['label-message_to']."<br>\n"; }
//if (strlen($message_text) == 0) { $msg .= $text['message-required']." ".$text['label-message_text']."<br>\n"; }
//if (strlen($message_media_type) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_type']."<br>\n"; }
//if (strlen($message_media_url) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_url']."<br>\n"; }
//if (strlen($message_media_content) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_content']."<br>\n"; }
//if (strlen($message_json) == 0) { $msg .= $text['message-required']." ".$text['label-message_json']."<br>\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\n";
require_once "resources/footer.php";
return;
}
//add the message_uuid
if (!is_uuid($_POST["message_uuid"])) {
$message_uuid = uuid();
}
//prepare the array
$array['messages'][0]['domain_uuid'] = $_SESSION["domain_uuid"];;
$array['messages'][0]['user_uuid'] = $user_uuid;
$array['messages'][0]['message_uuid'] = $message_uuid;
$array['messages'][0]['message_type'] = $message_type;
$array['messages'][0]['message_direction'] = $message_direction;
$array['messages'][0]['message_date'] = $message_date;
$array['messages'][0]['message_from'] = $message_from;
$array['messages'][0]['message_to'] = $message_to;
$array['messages'][0]['message_text'] = $message_text;
$array['messages'][0]['message_uuid'] = $message_uuid;
//save to the data
$database = new database;
$database->app_name = 'messages';
$database->app_uuid = '4a20815d-042c-47c8-85df-085333e79b87';
$database->save($array);
//redirect the user
if (isset($action)) {
if ($action == "add") {
message::add($text['message-add']);
}
if ($action == "update") {
message::add($text['message-update']);
}
header('Location: message_edit.php?id='.$message_uuid);
exit;
}
}
//pre-populate the form
if (is_array($_GET) && $_POST["persistformvar"] != "true") {
$message_uuid = $_GET["id"];
$sql = "select * from v_messages ";
$sql .= "where message_uuid = :message_uuid ";
$parameters['message_uuid'] = $message_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$user_uuid = $row["user_uuid"];
$message_type = $row["message_type"];
$message_direction = $row["message_direction"];
$message_date = $row["message_date"];
$message_from = $row["message_from"];
$message_to = $row["message_to"];
$message_text = $row["message_text"];
$message_media_type = $row["message_media_type"];
$message_media_url = $row["message_media_url"];
$message_media_content = $row["message_media_content"];
$message_json = $row["message_json"];
}
unset($sql, $parameters);
}
//show the header
require_once "resources/header.php";
//get the users
$sql = "select user_uuid, username from v_users ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and user_enabled = 'true' ";
$sql .= "order by username asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$users = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//show the content
echo "<form name='frm' id='frm' method='post' action=''>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-message']."</b><br><br></td>\n";
echo "<td width='70%' align='right' valign='top'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='messages_log.php'\" value='".$text['button-back']."'>";
echo " <input type='submit' class='btn' value='".$text['button-save']."'>";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-username']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='user_uuid'>\n";
foreach($users as $row) {
echo " <option value='".escape($row['user_uuid'])."' ".($row['user_uuid'] == $user_uuid ? "selected='selected'" : null).">".escape($row['username'])."</option>\n";
}
echo " </select>\n";
echo "<br />\n";
echo $text['description-username']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_type']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='message_type'>\n";
echo " <option value='sms' ".($message_type == 'sms' ? "selected='selected'" : null).">".$text['label-sms']."</option>\n";
echo " <option value='mms' ".($message_type == 'mms' ? "selected='selected'" : null).">".$text['label-mms']."</option>\n";
echo " <option value='chat' ".($message_type == 'chat' ? "selected='selected'" : null).">".$text['label-chat']."</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-message_type']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_direction']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='message_direction'>\n";
echo " <option value='inbound' ".($message_direction == 'inbound' ? "selected='selected'" : null).">".$text['label-inbound']."</option>\n";
echo " <option value='outbound' ".($message_direction == 'outbound' ? "selected='selected'" : null).">".$text['label-outbound']."</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-message_direction']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_date']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_date' maxlength='255' value=\"".escape($message_date)."\">\n";
echo "<br />\n";
echo $text['description-message_date']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_from']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_from' maxlength='255' value=\"".escape($message_from)."\">\n";
echo "<br />\n";
echo $text['description-message_from']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_to']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_to' maxlength='255' value=\"".escape($message_to)."\">\n";
echo "<br />\n";
echo $text['description-message_to']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_text']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_text' maxlength='255' value=\"".escape($message_text)."\">\n";
echo "<br />\n";
echo $text['description-message_text']."\n";
echo "</td>\n";
echo "</tr>\n";
if (strlen($message_media_type) > 0) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " \n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
$image_source = 'data: '.mime_content_type($message_media_type).';base64,'.$message_media_content;
echo "<img src='".$image_source."' width='100%'>";
echo "<br />\n";
echo "</td>\n";
echo "</tr>\n";
}
if ($_GET['debug'] == 'true') {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_media_type']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_media_type' maxlength='255' value=\"".escape($message_media_type)."\">\n";
echo "<br />\n";
echo $text['description-message_media_type']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_media_url']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_media_url' maxlength='255' value=\"".escape($message_media_url)."\">\n";
echo "<br />\n";
echo $text['description-message_media_url']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_media_content']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_media_content' maxlength='255' value=\"".escape($message_media_content)."\">\n";
echo "<br />\n";
echo $text['description-message_media_content']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_json']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_json' maxlength='255' value=\"".escape($message_json)."\">\n";
echo "<br />\n";
echo $text['description-message_json']."\n";
echo "</td>\n";
echo "</tr>\n";
}
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
echo " <input type='hidden' name='message_uuid' value='".escape($message_uuid)."'>\n";
echo " <input type='submit' class='btn' value='".$text['button-save']."'>\n";
echo " </td>\n";
echo " </tr>";
echo "</table>";
echo "</form>";
echo "<br /><br />";
//include the footer
require_once "resources/footer.php";
?>