Portions created by the Initial Developer are Copyright (C) 2018-2025 the Initial Developer. All Rights Reserved. */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (!(permission_exists('email_template_add') || permission_exists('email_template_edit'))) { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //action add or update if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $action = "update"; $email_template_uuid = $_REQUEST["id"]; } else { $action = "add"; } //set the defaults $template_language = ''; $template_category = ''; $template_subcategory = ''; $template_subject = ''; $template_body = ''; $template_type = ''; $template_description = ''; //get http post variables and set them to php variables if (!empty($_POST)) { $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"]; } //process the user data and save it to the database if (!empty($_POST) && empty($_POST["persistformvar"])) { //get the uuid from the POST if ($action == "update") { $email_template_uuid = $_POST["email_template_uuid"]; } //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; } //check for all required data $msg = ''; if (empty($template_language)) { $msg .= $text['message-required']." ".$text['label-template_language']."
\n"; } if (empty($template_category)) { $msg .= $text['message-required']." ".$text['label-template_category']."
\n"; } //if (empty($template_subcategory)) { $msg .= $text['message-required']." ".$text['label-template_subcategory']."
\n"; } if (empty($template_subject)) { $msg .= $text['message-required']." ".$text['label-template_subject']."
\n"; } if (empty($template_body)) { $msg .= $text['message-required']." ".$text['label-template_body']."
\n"; } //if (empty($domain_uuid)) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; } //if (empty($template_type)) { $msg .= $text['message-required']." ".$text['label-template_type']."
\n"; } //if (empty($template_description)) { $msg .= $text['message-required']." ".$text['label-template_description']."
\n"; } if (!empty($msg) && empty($_POST["persistformvar"])) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //add the email_template_uuid if (empty($_POST["email_template_uuid"]) || !is_uuid($_POST["email_template_uuid"])) { $email_template_uuid = uuid(); } //prepare the array $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; //save to the data if (!empty($email_template_uuid)) { $database->uuid($email_template_uuid); } $database->save($array); //$message = $database->message; //redirect the user if (isset($action)) { if ($action == "add") { message::add($text['message-add']); } if ($action == "update") { message::add($text['message-update']); } header('Location: email_template_edit.php?id='.escape($email_template_uuid)); exit; } } //pre-populate the form if (count($_GET)>0 && empty($_POST["persistformvar"])) { $email_template_uuid = $_GET["id"]; $sql = "select "; $sql .= "email_template_uuid, "; $sql .= "domain_uuid, "; $sql .= "template_language, "; $sql .= "template_category, "; $sql .= "template_subcategory, "; $sql .= "template_subject, "; $sql .= "template_body, "; $sql .= "template_type, "; $sql .= "template_enabled, "; $sql .= "template_description "; $sql .= "from v_email_templates "; $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; $row = $database->select($sql, $parameters, 'row'); if (!empty($row)) { $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"]; $template_type = $row["template_type"]; $template_enabled = $row["template_enabled"]; $template_description = $row["template_description"]; } unset($sql, $parameters, $row); } //load editor preferences/defaults $setting_size = !empty($settings->get('editor', 'font_size')) ? $settings->get('editor', 'font_size') : '12px'; $setting_theme = !empty($settings->get('editor', 'theme')) ? $settings->get('editor', 'theme') : 'cobalt'; $setting_invisibles = $settings->get('editor', 'invisibles', 'false'); $setting_indenting = $settings->get('editor', 'indent_guides', 'false'); $setting_numbering = $settings->get('editor', 'line_numbers', 'true'); //set the defaults $template_enabled = $template_enabled ?? true; //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-email_template']; require_once "resources/header.php"; echo "\n"; echo "\n"; //show the content echo "
\n"; echo "
\n"; echo "
".$text['title-email_template']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'email_templates.php']); echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','onclick'=>"set_value(); $('#frm').submit();"]); echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-template_language']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-template_language']."\n"; echo "
\n"; echo " ".$text['label-template_category']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-template_category']."\n"; echo "
\n"; echo " ".$text['label-template_subcategory']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-template_subcategory']."\n"; echo "
\n"; echo " ".$text['label-template_subject']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-template_subject']."\n"; echo "
\n"; echo " ".$text['label-template_body']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " \n"; echo " \n"; $themes['Light']['chrome']= 'Chrome'; $themes['Light']['clouds']= 'Clouds'; $themes['Light']['crimson_editor']= 'Crimson Editor'; $themes['Light']['dawn']= 'Dawn'; $themes['Light']['dreamweaver']= 'Dreamweaver'; $themes['Light']['eclipse']= 'Eclipse'; $themes['Light']['github']= 'GitHub'; $themes['Light']['iplastic']= 'IPlastic'; $themes['Light']['solarized_light']= 'Solarized Light'; $themes['Light']['textmate']= 'TextMate'; $themes['Light']['tomorrow']= 'Tomorrow'; $themes['Light']['xcode']= 'XCode'; $themes['Light']['kuroir']= 'Kuroir'; $themes['Light']['katzenmilch']= 'KatzenMilch'; $themes['Light']['sqlserver']= 'SQL Server'; $themes['Dark']['ambiance']= 'Ambiance'; $themes['Dark']['chaos']= 'Chaos'; $themes['Dark']['clouds_midnight']= 'Clouds Midnight'; $themes['Dark']['cobalt']= 'Cobalt'; $themes['Dark']['idle_fingers']= 'idle Fingers'; $themes['Dark']['kr_theme']= 'krTheme'; $themes['Dark']['merbivore']= 'Merbivore'; $themes['Dark']['merbivore_soft']= 'Merbivore Soft'; $themes['Dark']['mono_industrial']= 'Mono Industrial'; $themes['Dark']['monokai']= 'Monokai'; $themes['Dark']['pastel_on_dark']= 'Pastel on dark'; $themes['Dark']['solarized_dark']= 'Solarized Dark'; $themes['Dark']['terminal']= 'Terminal'; $themes['Dark']['tomorrow_night']= 'Tomorrow Night'; $themes['Dark']['tomorrow_night_blue']= 'Tomorrow Night Blue'; $themes['Dark']['tomorrow_night_bright']= 'Tomorrow Night Bright'; $themes['Dark']['tomorrow_night_eighties']= 'Tomorrow Night 80s'; $themes['Dark']['twilight']= 'Twilight'; $themes['Dark']['vibrant_ink']= 'Vibrant Ink'; echo " \n"; echo "
\n"; echo "
\n"; echo $text['description-template_body']."\n"; echo "
\n"; echo " ".$text['label-domain']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo !empty($text['description-domain_uuid'])."\n"; echo "
\n"; echo " ".$text['label-template_type']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-template_type']."\n"; echo "
\n"; echo " ".$text['label-template_enabled']."\n"; echo "\n"; if ($input_toggle_style_switch) { echo " \n"; } echo " \n"; if ($input_toggle_style_switch) { echo " \n"; echo " \n"; } echo "
\n"; echo $text['description-template_enabled']."\n"; echo "
\n"; echo " ".$text['label-template_description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-template_description']."\n"; echo "
"; echo "
"; echo "

"; if ($action == "update") { echo "\n"; } echo "\n"; echo "
"; echo "\n"; echo "\n"; //include the footer require_once "resources/footer.php"; ?>