2017-12-17 09:50:46 +01:00
|
|
|
<?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 <markjcrane@fusionpbx.com>
|
2018-04-03 09:18:32 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2018
|
2017-12-17 09:50:46 +01:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//includes
|
|
|
|
|
require_once "root.php";
|
|
|
|
|
require_once "resources/require.php";
|
2020-01-06 20:18:33 +01:00
|
|
|
require_once "resources/check_auth.php";
|
2017-12-17 09:50:46 +01:00
|
|
|
|
|
|
|
|
//check permissions
|
|
|
|
|
if (permission_exists('email_template_add') || permission_exists('email_template_edit')) {
|
|
|
|
|
//access granted
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add multi-lingual support
|
|
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
|
|
|
|
|
|
|
|
|
//action add or update
|
2019-08-06 16:23:30 +02:00
|
|
|
if (is_uuid($_REQUEST["id"])) {
|
2017-12-17 09:50:46 +01:00
|
|
|
$action = "update";
|
2019-08-06 16:23:30 +02:00
|
|
|
$email_template_uuid = $_REQUEST["id"];
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$action = "add";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get http post variables and set them to php variables
|
|
|
|
|
if (is_array($_POST)) {
|
2019-08-06 16:23:30 +02:00
|
|
|
$domain_uuid = $_POST["domain_uuid"];
|
|
|
|
|
$template_language = $_POST["template_language"];
|
|
|
|
|
$template_category = $_POST["template_category"];
|
|
|
|
|
$template_subcategory = $_POST["template_subcategory"];
|
|
|
|
|
$template_subject = $_POST["template_subject"];
|
|
|
|
|
$template_body = $_POST["template_body"];
|
|
|
|
|
$template_type = $_POST["template_type"];
|
|
|
|
|
$template_enabled = $_POST["template_enabled"];
|
|
|
|
|
$template_description = $_POST["template_description"];
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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") {
|
2019-08-06 16:23:30 +02:00
|
|
|
$email_template_uuid = $_POST["email_template_uuid"];
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-18 07:00:34 +02:00
|
|
|
//validate the token
|
|
|
|
|
$token = new token;
|
|
|
|
|
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
|
|
|
|
message::add($text['message-invalid_token'],'negative');
|
|
|
|
|
header('Location: email_templates.php');
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-17 09:50:46 +01:00
|
|
|
//check for all required data
|
|
|
|
|
$msg = '';
|
|
|
|
|
if (strlen($template_language) == 0) { $msg .= $text['message-required']." ".$text['label-template_language']."<br>\n"; }
|
|
|
|
|
if (strlen($template_category) == 0) { $msg .= $text['message-required']." ".$text['label-template_category']."<br>\n"; }
|
|
|
|
|
//if (strlen($template_subcategory) == 0) { $msg .= $text['message-required']." ".$text['label-template_subcategory']."<br>\n"; }
|
|
|
|
|
if (strlen($template_subject) == 0) { $msg .= $text['message-required']." ".$text['label-template_subject']."<br>\n"; }
|
|
|
|
|
if (strlen($template_body) == 0) { $msg .= $text['message-required']." ".$text['label-template_body']."<br>\n"; }
|
|
|
|
|
//if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."<br>\n"; }
|
2018-04-03 09:18:32 +02:00
|
|
|
//if (strlen($template_type) == 0) { $msg .= $text['message-required']." ".$text['label-template_type']."<br>\n"; }
|
2017-12-17 09:50:46 +01:00
|
|
|
if (strlen($template_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-template_enabled']."<br>\n"; }
|
|
|
|
|
//if (strlen($template_description) == 0) { $msg .= $text['message-required']." ".$text['label-template_description']."<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 email_template_uuid
|
2019-08-06 16:23:30 +02:00
|
|
|
if (!is_uuid($_POST["email_template_uuid"])) {
|
2017-12-17 09:50:46 +01:00
|
|
|
$email_template_uuid = uuid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//prepare the array
|
2019-09-18 08:11:36 +02:00
|
|
|
$array['email_templates'][0]['domain_uuid'] = $domain_uuid;
|
|
|
|
|
$array['email_templates'][0]['email_template_uuid'] = $email_template_uuid;
|
|
|
|
|
$array['email_templates'][0]['template_language'] = $template_language;
|
|
|
|
|
$array['email_templates'][0]['template_category'] = $template_category;
|
|
|
|
|
$array['email_templates'][0]['template_subcategory'] = $template_subcategory;
|
|
|
|
|
$array['email_templates'][0]['template_subject'] = $template_subject;
|
|
|
|
|
$array['email_templates'][0]['template_body'] = $template_body;
|
|
|
|
|
$array['email_templates'][0]['template_type'] = $template_type;
|
|
|
|
|
$array['email_templates'][0]['template_enabled'] = $template_enabled;
|
|
|
|
|
$array['email_templates'][0]['template_description'] = $template_description;
|
2017-12-17 09:50:46 +01:00
|
|
|
|
|
|
|
|
//save to the data
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->app_name = 'email_templates';
|
2019-08-06 16:23:30 +02:00
|
|
|
$database->app_uuid = '8173e738-2523-46d5-8943-13883befd2fd';
|
2017-12-17 09:50:46 +01:00
|
|
|
if (strlen($email_template_uuid) > 0) {
|
|
|
|
|
$database->uuid($email_template_uuid);
|
|
|
|
|
}
|
|
|
|
|
$database->save($array);
|
|
|
|
|
$message = $database->message;
|
|
|
|
|
|
|
|
|
|
//redirect the user
|
|
|
|
|
if (isset($action)) {
|
|
|
|
|
if ($action == "add") {
|
2019-08-06 16:23:30 +02:00
|
|
|
message::add($text['message-add']);
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
|
|
|
|
if ($action == "update") {
|
2019-08-06 16:23:30 +02:00
|
|
|
message::add($text['message-update']);
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
2018-06-30 19:18:13 +02:00
|
|
|
header('Location: email_template_edit.php?id='.escape($email_template_uuid));
|
2019-08-06 16:23:30 +02:00
|
|
|
exit;
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
2019-08-06 16:23:30 +02:00
|
|
|
}
|
2017-12-17 09:50:46 +01:00
|
|
|
|
|
|
|
|
//pre-populate the form
|
|
|
|
|
if (is_array($_GET) && $_POST["persistformvar"] != "true") {
|
2019-08-06 16:23:30 +02:00
|
|
|
$email_template_uuid = $_GET["id"];
|
2017-12-17 09:50:46 +01:00
|
|
|
$sql = "select * from v_email_templates ";
|
2019-08-06 16:23:30 +02:00
|
|
|
$sql .= "where email_template_uuid = :email_template_uuid ";
|
|
|
|
|
//$sql .= "and domain_uuid = :domain_uuid ";
|
|
|
|
|
$parameters['email_template_uuid'] = $email_template_uuid;
|
|
|
|
|
//$parameters['domain_uuid'] = $domain_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$row = $database->select($sql, $parameters, 'row');
|
|
|
|
|
if (is_array($row) && @sizeof($row) != 0) {
|
2017-12-17 09:50:46 +01:00
|
|
|
$domain_uuid = $row["domain_uuid"];
|
|
|
|
|
$template_language = $row["template_language"];
|
|
|
|
|
$template_category = $row["template_category"];
|
|
|
|
|
$template_subcategory = $row["template_subcategory"];
|
|
|
|
|
$template_subject = $row["template_subject"];
|
|
|
|
|
$template_body = $row["template_body"];
|
2018-04-03 09:18:32 +02:00
|
|
|
$template_type = $row["template_type"];
|
2017-12-17 09:50:46 +01:00
|
|
|
$template_enabled = $row["template_enabled"];
|
|
|
|
|
$template_description = $row["template_description"];
|
|
|
|
|
}
|
2019-08-06 16:23:30 +02:00
|
|
|
unset($sql, $parameters, $row);
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-18 07:00:34 +02:00
|
|
|
//create token
|
|
|
|
|
$object = new token;
|
|
|
|
|
$token = $object->create($_SERVER['PHP_SELF']);
|
|
|
|
|
|
2017-12-17 09:50:46 +01:00
|
|
|
//show the header
|
2020-01-06 20:18:33 +01:00
|
|
|
$document['title'] = $text['title-email_template'];
|
2017-12-17 09:50:46 +01:00
|
|
|
require_once "resources/header.php";
|
|
|
|
|
|
|
|
|
|
//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-email_template']."</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='email_templates.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='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-template_language']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
2018-06-30 19:18:13 +02:00
|
|
|
echo " <input class='formfld' type='text' name='template_language' maxlength='255' value=\"".escape($template_language)."\">\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-template_language']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-template_category']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
2018-06-30 19:18:13 +02:00
|
|
|
echo " <input class='formfld' type='text' name='template_category' maxlength='255' value=\"".escape($template_category)."\">\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-template_category']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-template_subcategory']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
2018-06-30 19:18:13 +02:00
|
|
|
echo " <input class='formfld' type='text' name='template_subcategory' maxlength='255' value=\"".escape($template_subcategory)."\">\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-template_subcategory']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-template_subject']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
2018-06-30 19:18:13 +02:00
|
|
|
echo " <input class='formfld' type='text' name='template_subject' maxlength='255' value=\"".escape($template_subject)."\">\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-template_subject']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-template_body']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
2019-08-27 03:35:06 +02:00
|
|
|
echo " <textarea class='formfld' name='template_body' style='min-width: 100%; height: 350px; font-family: monospace;'>".$template_body."</textarea>\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-template_body']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-domain']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
|
|
|
|
echo " <select class='formfld' name='domain_uuid'>\n";
|
2019-08-06 16:23:30 +02:00
|
|
|
if (!is_uuid($domain_uuid)) {
|
2017-12-17 09:50:46 +01:00
|
|
|
echo " <option value='' selected='selected'>".$text['label-global']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo " <option value=''>".$text['label-global']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
foreach ($_SESSION['domains'] as $row) {
|
|
|
|
|
if ($row['domain_uuid'] == $domain_uuid) {
|
2018-06-30 19:18:13 +02:00
|
|
|
echo " <option value='".escape($row['domain_uuid'])."' selected='selected'>".escape($row['domain_name'])."</option>\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-06-30 19:18:13 +02:00
|
|
|
echo " <option value='".escape($row['domain_uuid'])."'>".escape($row['domain_name'])."</option>\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
echo " </select>\n";
|
|
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-domain_uuid']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
2018-04-03 09:18:32 +02:00
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-template_type']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
2018-06-30 19:18:13 +02:00
|
|
|
echo " <input class='formfld' type='text' name='template_type' maxlength='255' value=\"".escape($template_type)."\">\n";
|
2018-04-03 09:18:32 +02:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-template_type']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
2017-12-17 09:50:46 +01:00
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-template_enabled']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
|
|
|
|
echo " <select class='formfld' name='template_enabled'>\n";
|
|
|
|
|
if ($template_enabled == "true") {
|
|
|
|
|
echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo " <option value='true'>".$text['label-true']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
if ($template_enabled == "false") {
|
|
|
|
|
echo " <option value='false' selected='selected'>".$text['label-false']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo " <option value='false'>".$text['label-false']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
echo " </select>\n";
|
|
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-template_enabled']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
|
|
|
|
|
echo " ".$text['label-template_description']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' style='position: relative;' align='left'>\n";
|
2018-06-30 19:18:13 +02:00
|
|
|
echo " <input class='formfld' type='text' name='template_description' maxlength='255' value=\"".escape($template_description)."\">\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-template_description']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo " <tr>\n";
|
|
|
|
|
echo " <td colspan='2' align='right'>\n";
|
|
|
|
|
if ($action == "update") {
|
2019-09-18 07:00:34 +02:00
|
|
|
echo " <input type='hidden' name='email_template_uuid' value='".escape($email_template_uuid)."'>\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
}
|
2019-09-18 07:00:34 +02:00
|
|
|
echo " <input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
|
|
|
|
|
echo " <input type='submit' class='btn' value='".$text['button-save']."'>\n";
|
2017-12-17 09:50:46 +01:00
|
|
|
echo " </td>\n";
|
|
|
|
|
echo " </tr>";
|
|
|
|
|
echo "</table>";
|
|
|
|
|
echo "</form>";
|
|
|
|
|
echo "<br /><br />";
|
|
|
|
|
|
|
|
|
|
//include the footer
|
|
|
|
|
require_once "resources/footer.php";
|
|
|
|
|
|
|
|
|
|
?>
|