emailtemplates.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:19k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: emailtemplates.php,v $
- // | $Date: 2004/02/12 21:16:57 $
- // | $Revision: 1.23 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - E-mail template maintenance (administration interface)
- // +-------------------------------------------------------------+
- error_reporting(E_ALL & ~E_NOTICE);
- require_once('./global.php');
- //Nullify WTN-WDYL Team
- require_once(INCLUDE_PATH . 'functions/conditional_functions.php');
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "view_user";
- }
- // globalise variables
- $global = array (
- array('category'),
- array('id'),
- array('language')
- );
- rg($global);
- // set language to 1 if not using languages
- if (!$language) {
- $language = $settings[default_language];
- }
- /* email template categories:
- 1 - USER EMAILS
- 2 - TECH EMAILS
- */
- ########################################################################################
- ############################### VIEW TECH TEMPLATES ###############################
- ########################################################################################
- if ($_REQUEST['do'] == "view_tech") {
- admin_header('Email Templates', 'View Email Templates');
- /***************************************************
- DEFAULT TEMPLATES
- ***************************************************/
- // names of english templates
- $db->query("
- SELECT * FROM template_email
- WHERE category = 'Tech Emails'
- AND backup = 0
- ORDER by custom, displayorder
- ");
-
- while ($template = $db->row_array()) {
- if ($template[custom] == 1 AND !$y) {
- $table[] = table_midheader('Your Custom Templates');
- $y = true;
- }
-
- unset($word);
- if ($template[upgraded] == "1") {
- $word = "<font color="red">CHANGED</font>";
- } elseif ($template[changed] == 1) {
- $word = "<font color="orange">EDITED</font>";
- }
- $table[] = array(
- "<b>$template[name]</b> $word",
- $template[description],
- iff($template[changed] AND !$template[custom], jprompt('Are you sure you want to restore this template to its original?\nAll your modifications will be lost', "emailtemplates.php?do=restore&id=$template[id]", 'Restore Default')),
- "<a href="emailtemplates.php?do=edit&id=$template[id]">Edit</a>",
- iff($template[custom], jprompt('Confirm deletion of this template', "emailtemplates.php?do=delete&id=$template[id]", "Delete"))
- );
- }
-
- $columns = array('Name', 'Description', 'Restore Default', 'Edit', 'Delete');
- table_header("Default Templates");
- table_content($columns, $table, '', '', '', '', $width, $bottomline);
- table_footer();
- echo "<b>KEY:</b><ul>
- <li><font color="red">CHANGED</font> : The template has been upgraded since you last changed it. You should find the changes made or revert the template.</li>
- <li><font color="orange">EDITED</font> : You have made changes to this template.</li>
- </ul>
- ";
- }
- ########################################################################################
- ############################### VIEW USER TEMPLATES ###############################
- ########################################################################################
- if ($_REQUEST['do'] == "view_user") {
- admin_header('Email Templates', 'View User Templates');
- /***************************************************
- PICK LANGUAGE
- ***************************************************/
- /////////////// SELECT LANGUAGE ///////////////
- if ($settings[language_on] == "1") {
- $db->query("SELECT * FROM languages");
- while ($lang = $db->row_array()) {
- $languages[$lang[id]] = "$lang[name]";
- }
- $table[] = array(
- "<b>Currently viewing $languages[$language] templates:</b>",
- form_select('language', $languages, '', $language) . '<input type="submit" name="submit" value="Change">'
- );
-
- echo form_hidden('do', 'view_user');
- echo "<form action="emailtemplates.php" method="post">";
- table_nohead($table);
- unset($table);
- echo '<br />';
- }
- /***************************************************
- DEFAULT TEMPLATES
- ***************************************************/
- // details on current language
- $thislanguage = $db->query_return("SELECT * FROM languages WHERE id = $language");
-
- if ($thislanguage[custom] == "1") {
- $table = array('This language is a custom set of templates created by you. Changes made to these templates will have no corresponding updated icons that would appear on changes made to template sets downloaded with DeskPRO.');
- echo "<BR>";
- echo table_nohead($table);
- unset($table);
- echo "<br /><br />";
- }
- // names of english templates
- $db->query("
- SELECT name FROM template_email
- WHERE language = 1
- AND custom != 1
- AND category = 'User Emails'
- AND backup = 0
- ORDER by displayorder
- ");
- while ($result = $db->row_array()) {
- $engtemplates_cat[] = $result[name];
- }
- // get default templates
- $db->query("
- SELECT * FROM template_email
- WHERE language = '$language'
- AND category = 'User Emails'
- AND backup = 0
- ORDER by category, displayorder
- ");
-
- while ($template = $db->row_array()) {
- unset($word);
- $templates_temp[] = $template[name];
- if ($template[upgraded] == "1") {
- $word = "<font color="red">CHANGED</font>";
- } elseif ($template[changed] == 1) {
- $word = "<font color="orange">EDITED</font>";
- }
- // restore link
- $bit = jprompt('Are you sure you want to restore this template to its original?\nAll your modifications will be lost', "emailtemplates.php?do=restore&id=$template[id]", 'Restore Default');
-
- // set if we have a restore to default link
- if ($thislanguage[custom] != 1) {
- $table[] = array(
- "<b>$template[name]</b> $word",
- $template[description],
- iff($template[changed], $bit, ''),
- "<a href="emailtemplates.php?do=edit&id=$template[id]">Edit</a>"
- );
- } else {
- $table[] = array(
- "<b>$template[name]</b> $word",
- $template[description],
- "<a href="emailtemplates.php?do=edit&id=$template[id]">Edit</a>",
- );
- }
- }
- // extra rows for uncreated templates
- if ($thislanguage[custom] == "1") {
- if (is_array($templates_temp)) {
- $notemplate = array_diff($engtemplates_cat, $templates_temp);
- } else {
- $notemplate = $engtemplates_cat;
- }
- }
- if (count($notemplate) > 0) {
- $uncreated = 1;
- $table[] = table_midheader('These are standard templates that you have not created for the ' . $thislanguage[name] . ' language');
- foreach($notemplate AS $key => $var) {
- $table[] = array(
- "<b><I>$var</I></b>",
- '',
- '',
- "<a href="emailtemplates.php?name=$var&language=$language&do=newdefault">Create</a>"
- );
- }
- // add any empty columns needed
- foreach ($table AS $key => $var) {
- if (count($var) == 3) {
- $table[$key][] = '';
- }
- }
- }
- if ($settings[language_on] AND $uncreated) {
- $columns = array('Name', 'Description', 'Edit', 'Create');
- } elseif ($thislanguage[custom] == 1) {
- $columns = array('Name', 'Description', 'Edit');
- } else {
- $columns = array('Name', 'Description', 'Restore Default', 'Edit');
- }
- table_header("Default Templates");
- table_content($columns, $table, '', '', '', '', $width, $bottomline);
- table_footer();
- unset($templates_temp, $table, $bottomline, $columns, $uncreated, $notemplate);
- /***************************************************
- CUSTOM TEMPLATES
- ***************************************************/
- // get custom templates
- $db->query("SELECT * FROM template_email WHERE category = '$category' AND language = '$language' AND custom = 1");
- $count = $db->num_rows();
-
- while ($template = $db->row_array()) {
- $templates_temp[] = $template[name];
- // delete link (depends on language setting)
- if ($settings[language_on] == "1") {
- $bit = jprompt_multi('Are you sure you want to delete this custom template?', "Do you wish to delete this custom template for ALL languages?\nCancel will only delete the $languages[$language] template", "emailtemplates.php?do=delete_all&id=$template[id]", "emailtemplates.php?do=delete&id=$template[id]",'Delete');
- } else {
- $bit = jprompt('Are you sure you want to delete this template?', "emailtemplates.php?do=restore&id=$template[id]", 'Delete');
- }
- $table[] = array(
- "<b>$template[name]</b>",
- $template[description],
- $bit,
- "<a href="emailtemplates.php?do=editcustom&id=$template[id]">Edit</a>"
- );
-
- }
- // get sum of custom templates
- $db->query("SELECT DISTINCT name FROM template_email WHERE custom = 1 AND category = '$category'");
- while ($result = $db->row_array()) {
- $customtemplates[] = $result[name];
- }
- // extra rows for custom templates exisiting in other languages
- if (is_array($templates_temp)) {
- $notemplate = array_diff($customtemplates, $templates_temp);
- } else {
- $notemplate = $customtemplates;
- }
- if (count($notemplate) > 0) {
- $uncreated = 1;
- $table[] = table_midheader('These are custom templates that have been created for other languages but not for the ' . $thislanguage[name] . ' language');
- foreach($notemplate AS $key => $var) {
- $table[] = array("
- <b><I>$var</I></b>",
- '',
- '',
- '',
- "<a href="emailtemplates.php?do=newcustom&language=$language&name=$var">Create</a>"
- );
- }
- // add any empty columns needed
- foreach ($table AS $key => $var) {
- if (count($var) == 4) {
- $table[$key][] = '';
- }
- }
- }
- if ($uncreated) {
- $cols = array('Name', 'Description', 'Delete', 'Edit', 'Create');
- } else {
- $cols = array('Name', 'Description', 'Delete', 'Edit');
- }
- if (($count > 0) OR (count($notemplate) > 0)) {
- table_header("Custom Templates");
- table_content($cols, $table, '', '', '', '', $width, $bottomline);
- table_footer();
- }
- echo "<b>KEY:</b><ul>
- <li><font color="red">CHANGED</font> : The template has been upgraded since you last changed it. You should find the changes made or revert the template.</li>
- <li><font color="orange">EDITED</font> : You have made changes to this template.</li>
- </ul>
- ";
- }
- ############################### DELETE CUSTOM TEMPLATE ###############################
- if ($_REQUEST['do'] == 'delete') {
- $template = $db->query_return("SELECT * FROM template_email WHERE id = '$id'");
- if ($template[custom] != 1) {
- mistake('You can only delete custom templates');
- }
- $db->query("DELETE FROM template_email WHERE id = '$id'");
- if ($template['category'] == 'User Emails') {
- jump("emailtemplates.php?do=view_email", 'The email template has been deleted');
- } else {
- jump("emailtemplates.php?do=view_tech", 'The email template has been deleted');
- }
- }
- ############################### TRANSLATE (2) ###############################
- if ($_REQUEST['do'] == 'newdefault2') {
- $template = parse_conditionals($_REQUEST[template_unparsed]);
- $db->query(" INSERT INTO template_email SET
- name = '" . mysql_escape_string($_REQUEST['name']) . "',
- description = '" . mysql_escape_string($_REQUEST['description']) . "',
- template = '" . mysql_escape_string($template) . "',
- template_unparsed = '" . mysql_escape_string($_REQUEST['template_unparsed']) . "',
- category= 'User Emails',
- custom = '1',
- subject = '" . mysql_escape_string($_REQUEST['subject']) . "',
- language = '$_REQUEST[language]'
- ");
- jump("emailtemplates.php?do=view_user&language=$_REQUEST[language]", 'Template Translated');
- }
- ############################### TRANSLATE (1) ###############################
- if ($_REQUEST['do'] == 'newdefault') {
- // get the language details
- $db->query("SELECT * FROM languages");
- while ($language = $db->row_array()) {
- if ($language['id'] == $_REQUEST['language']) {
- $this_language = $language;
- }
- $lang[$language[id]] = $language[name];
- }
- $template = $db->query_return("SELECT * FROM template_email WHERE name = '" . addslashes($_REQUEST['name']) . "' AND backup AND language = '$settings[default_language]'");
- admin_header('Email Templates', 'Create Email Template',
- array('dir' => $this_language['direction'], 'lang' => $this_language['isocode'], 'charset' => $this_language['contenttype'])
- );
- $table[] = array('<b>Name</b>', '<input DISABLED value="' . $_REQUEST['name'] . '" size="40">' . form_hidden('name', $_REQUEST['name']));
- $table[] = array('<b>Category</b>', form_select('category', array('User Emails', 'Tech Emails'), '', '', 1));
- $table[] = array('<b>Language</b>', form_select('language', $lang, NULL, $_REQUEST['language'], NULL, NULL, NULL, NULL, NULL, NULL, 1));
- $table[] = array('<b>Description</b>', form_textarea('description', '60', '4', $template[description]));
- $table[] = array('<b>Subject</b>', form_input('subject', $template[subject], 80));
- $table[] = array('<b>Template</b>', form_textarea('template_unparsed', '100', '30', $template[template_unparsed]));
- table_header("Translate Template", 'emailtemplates.php', array('do' => 'newdefault2', 'language' => $_REQUEST[language]));
- table_content($columns, $table);
- table_footer('Create Template');
- unset($table);
- }
- ############################### CREATE A NEW TEMPLATE ###############################
- if ($_REQUEST['do'] == "add") {
- // get the language details
- $db->query("SELECT * FROM languages");
- while ($language = $db->row_array()) {
- if ($language['id'] == $_REQUEST['language']) {
- $this_language = $language;
- }
- $lang[$language[id]] = $language[name];
- }
- admin_header('Email Templates', 'Create Email Template',
- array('dir' => $this_language['direction'], 'lang' => $this_language['isocode'], 'charset' => $this_language['contenttype'])
- );
- $table[] = array('<b>Name</b>', form_input('name', '', 40));
- $table[] = array('<b>Category</b>', form_select('category', array('User Emails', 'Tech Emails'), '', '', 1));
- $table[] = array('<b>Language</b>', form_select('language', $lang, $_REQUEST[language]));
- $table[] = array('<b>Description</b>', form_textarea('description', '60', '4'));
- $table[] = array('<b>Subject</b>', form_input('subject', '', 80));
- $table[] = array('<b>Template</b>', form_textarea('template_unparsed', '100', '30', $template[template_unparsed]));
- table_header("Create Custom Template", 'emailtemplates.php', array('do' => 'add2'));
- table_content($columns, $table);
- table_footer('Create Template');
- unset($table);
- }
- ############################### CREATE A TEMPLATE (2) ###############################
- if ($_REQUEST['do'] == "add2") {
- $template = parse_conditionals($_REQUEST[template_unparsed]);
- $db->query(" INSERT INTO template_email SET
- name = '" . mysql_escape_string($_REQUEST['name']) . "',
- description = '" . mysql_escape_string($_REQUEST['description']) . "',
- template = '" . mysql_escape_string($template) . "',
- template_unparsed = '" . mysql_escape_string($_REQUEST['template_unparsed']) . "',
- category= '" . mysql_escape_string($_REQUEST['category']) . "',
- custom = '1',
- subject = '" . mysql_escape_string($_REQUEST['subject']) . "'" .
- iff($_REQUEST['category'] == 'User Emails', ", language = '$_REQUEST[language]'") .
- "");
- if ($_RESULT['category'] == 'User Emails') {
- jump("emailtemplates.php?do=view_user&language=$_REQUEST[language]", 'Template Created');
- } else {
- jump("emailtemplates.php?do=view_tech", 'Template Created');
- }
- }
- ############################### EDIT TEMPLATE ###############################
- if ($_REQUEST['do'] == "edit") {
- $template = $db->query_return("SELECT * FROM template_email WHERE id = '$id'");
- if ($template['language']) {
- // get the language details
- $db->query("SELECT * FROM languages");
- while ($language = $db->row_array()) {
- if ($language['id'] == $template['language']) {
- $this_language = $language;
- }
- $lang[$language[id]] = $language[name];
- }
- }
- admin_header('Email Templates', '',
- array('dir' => $this_language['direction'], 'lang' => $this_language['isocode'], 'charset' => $this_language['contenttype'])
- );
- $table[] = array('<b>Name</b>', form_input('name', $template['name'], 40));
- if ($template['category'] == 'User_Emails') {
- $table[] = array('<b>Language</b>', form_select('language', $lang, '', $template['language']));
- }
- $table[] = array('<b>Description</b>', form_textarea('description', '60', '4', $template[description]));
- $table[] = array('<b>Subject</b>', form_input('subject', $template['subject'], 80));
- $table[] = array('<b>Template</b>', form_textarea('template_unparsed', '100', '30', $template[template_unparsed]));
- table_header("Edit Template", 'emailtemplates.php', array('do' => 'edit2', 'id' => $template['id']));
- table_content($columns, $table);
- table_footer('Edit Template');
- unset($table);
- }
- ############################### EDIT TEMPLATE (2) ###############################
- if ($_REQUEST['do'] == "edit2") {
- $template = parse_conditionals($_REQUEST[template_unparsed]);
- $db->query(" UPDATE template_email SET
- name = '" . mysql_escape_string($_REQUEST['name']) . "',
- description = '" . mysql_escape_string($_REQUEST['description']) . "',
- template = '" . mysql_escape_string($template) . "',
- template_unparsed = '" . mysql_escape_string($_REQUEST['template_unparsed']) . "',
- changed = 1,
- subject = '" . mysql_escape_string($_REQUEST['subject']) . "',
- language = '$_REQUEST[language]'
- WHERE id = '$id'
- ");
-
- $template = $db->query_return("SELECT * FROM template_email WHERE id = '$id'");
- if ($template['category'] == 'User Emails') {
- jump("emailtemplates.php?do=view_user&language=$_REQUEST[language]", 'Template Updated');
- } else {
- jump("emailtemplates.php?do=view_tech&language=$_REQUEST[language]", 'Template Updated');
- }
- }
- ############################### RESTORE TEMPLATE (1) ###############################
- if ($_REQUEST['do'] == "restore") {
- $template = $db->query_return("SELECT * FROM template_email WHERE id = $id");
- if (!$db->num_rows()) {
- mistake('Template to restore not found.');
- }
- $template_backup = $db->query_return("
- SELECT * FROM template_email
- WHERE name = '$template[name]'
- AND language = '$template[language]'
- AND backup = 1
- ");
- if ($db->num_rows()) {
- $db->query("
- UPDATE template_email SET
- template = '" . mysql_escape_string($template_backup[template]) . "',
- subject = '" . mysql_escape_string($template_backup[subject]) . "',
- template_unparsed = '" . mysql_escape_string($template_backup[template_unparsed]) . "',
- upgraded = 0,
- changed = 0,
- backup = 0
- WHERE id = '$id'
- ");
- if ($template_backup['category'] == 'Tech Emails') {
- jump("emailtemplates.php?do=view_tech", "Template restored from backup");
- } else {
- jump("emailtemplates.php?language=$template[language]", "Template restored from backup");
- }
- } else {
- mistake('Backup template not found');
- }
- }