email.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:9k
- <?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: email.php,v $
- // | $Date: 2004/02/11 01:28:14 $
- // | $Revision: 1.28 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - E-mail gateway settings and account maintenance
- // | (administration interface)
- // +-------------------------------------------------------------+
- error_reporting(E_ALL & ~E_NOTICE);
- require_once('./global.php');
- //Nullify WTN-WDYL Team
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "list";
- }
- // globalise variables
- $global = array (
- array('id', 'number')
- );
- rg($global);
- include('./settings_include.php');
- ############################### UPDATE THE SETTINGS ###############################
- if ($_REQUEST['do'] == "update") {
- if ($_REQUEST[settings][use_email] == 1) {
- $db->query("SELECT id FROM gateway_accounts");
- if ($db->num_rows() < 1) {
- mistake("You can not enable the email gateway until you have created a gateway <a href="email.php?do=add">account</a>");
- unset($_REQUEST[settings][use_email]);
- }
- }
- update_settings();
- $_REQUEST['do'] = "list";
- }
- ############################### DISPLAY SETTINGS ###############################
- if ($_REQUEST['do'] == "list") {
- admin_header('Email Gateway', 'View Settings');
- show_settings('email.php', array('Gateway Autoresponder Settings', 'Email Gateway', 'Tech Email Gateway'), false);
- }
- ############################### CREATE ACCOUNT ###############################
- if ($_REQUEST['do'] == "add2") {
- // we need an email address at least
- if (!validate_email($_REQUEST['email'])) {
-
- alert('You must enter a valid email address');
- $repeat = 1;
- $_REQUEST['do'] = 'add';
-
- } else {
-
- // make account default if it is the first one
- $db->query("SELECT id FROM gateway_accounts");
- if (!$db->num_rows()) {
- $_REQUEST['is_default'] = 1;
- update_settings('new_gateway', $_REQUEST['email']);
- }
- // only want one default accounts
- if ($_REQUEST['is_default'] == 1) {
- $db->query("UPDATE gateway_accounts SET is_default = 0");
- }
-
- $db->query("INSERT INTO gateway_accounts SET
- category = '" . mysql_escape_string($_REQUEST[category]) . "',
- priority = '" . mysql_escape_string($_REQUEST[priority]) . "',
- email = '" . mysql_escape_string($_REQUEST[email]) . "',
- tech = '" . mysql_escape_string($_REQUEST[tech]) . "',
- auto_new = '" . mysql_escape_string($_REQUEST[auto_new]) . "',
- auto_reply = '" . mysql_escape_string($_REQUEST[auto_reply]) . "',
- is_default = '" . mysql_escape_string($_REQUEST[is_default]) . "'
- ");
-
- $id = $db->last_id();
-
- jump("email.php?do=edit&id=$id", 'Gateway account created');
- }
- }
- ############################### EDIT ACCOUNT (2) ###############################
- if ($_REQUEST['do'] == "edit2") {
- // we need an email address at least
- if (!validate_email($_REQUEST['email'])) {
-
- alert('You must enter a valid email address');
- $repeat = 1;
- $_REQUEST['do'] = 'edit';
-
- } else {
- // make account default if there is no other default
- $db->query("SELECT id FROM gateway_accounts WHERE id != '$id' AND is_default = 1");
- if (!$db->num_rows()) {
- $_REQUEST['is_default'] = 1;
- update_settings('new_gateway', $_REQUEST['email']);
- }
-
- // only want one default accounts
- if ($_REQUEST['is_default']) {
- $db->query("UPDATE gateway_accounts SET is_default = 0 WHERE id != '$id'");
- }
-
- $db->query("
- UPDATE gateway_accounts SET
- category = '" . mysql_escape_string($_REQUEST[category]) . "',
- priority = '" . mysql_escape_string($_REQUEST[priority]) . "',
- email = '" . mysql_escape_string($_REQUEST[email]) . "',
- tech = '" . mysql_escape_string($_REQUEST[tech]) . "',
- auto_new = '" . mysql_escape_string($_REQUEST[auto_new]) . "',
- auto_reply = '" . mysql_escape_string($_REQUEST[auto_reply]) . "',
- is_default = '" . mysql_escape_string($_REQUEST[is_default]) . "'
- WHERE id = '$id'
- ");
-
- jump('email.php?do=view', 'Gateway account updated');
- }
- }
- ############################### DELETE ACCOUNT ###############################
- if ($_REQUEST['do'] == "delete") {
- $result = $db->query_return("SELECT is_default FROM gateway_accounts WHERE id = '$id'");
- if ($result['is_default'] == 1) {
- mistake('You can not delete the default gateway account');
- } else {
- $db->query("DELETE FROM gateway_accounts WHERE id = '$id'");
- $_REQUEST['do'] = "view";
- }
- }
- ############################### LIST ACCOUNTS ###############################
- if ($_REQUEST['do'] == "view") {
-
- admin_header('Email Gateway', 'List Accounts');
- $db->query("SELECT * FROM gateway_accounts");
- while ($result = $db->row_array()) {
- $g[$result[id]] = $result[email];
- }
- $db->query("SELECT gateway_accounts.*, ticket_cat.name AS category, ticket_pri.name AS priority, tech.username AS tech
- FROM gateway_accounts
- LEFT JOIN ticket_cat ON (gateway_accounts.category = ticket_cat.id)
- LEFT JOIN ticket_pri ON (gateway_accounts.priority = ticket_pri.id)
- LEFT JOIN tech ON (gateway_accounts.tech = tech.id)
- ORDER BY is_default DESC
- ");
-
- while ($gateway = $db->row_array()) {
- if ($gateway[is_default]) {
- $table[] = table_midheader('The Default Account');
- } else {
- if (!$x) {
- $table[] = table_midheader('Your Accounts');
- $x = 1;
- }
- }
- $table[] = array(
- $gateway[email],
- ifynb($gateway[is_default]),
- $gateway[category],
- iff($gateway[priority]),
- iff($gateway[tech]),
- ifynb($gateway[auto_new]),
- ifynb($gateway[auto_reply]),
- iff($gateway[is_default], 'n/a', "<a href="email.php?do=delete&id=$gateway[id]">delete</a>"),
- "<a href="email.php?do=edit&id=$gateway[id]">edit</a>"
- );
- }
- $cols = array('Email Address', 'Default', 'Category', 'Priority', 'Technician', 'Auto New', 'Auto Reply', 'Delete', 'Edit');
- table_header("Gateway Accounts");
- table_content($cols, $table);
- table_footer();
- // if email gateway is set to Off we should alert the user to turn it on
- if (!$settings['use_email']) {
- echo table_border("Currently the email interface is turned off. If you wish to use it, you should activate it <a href="./email.php">here</a>");
- }
- }
- ############################### CREATE / VIEW ACCOUNT ###############################
- if ($_REQUEST['do'] == "add" OR $_REQUEST['do'] == "edit") {
- if ($repeat) {
- $gateway = $_REQUEST;
- }
- if ($_REQUEST['do'] == "add") {
- admin_header('Email Gateway', 'Add Account');
- } else {
- admin_header('Email Gateway', 'Edit Account');
- $gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE id = $id");
- if (!$db->num_rows()) {
- mistake('The specified gateway account is not defined.');
- }
- }
- $categories[0] = '--- None ---';
- // get category data
- $db->query("SELECT * from ticket_cat");
- while ($cat = $db->row_array()) {
- $categories[$cat[id]] = $cat[name];
- }
-
- $priority[0] = '--- None ---';
- // get priority data
- $db->query("SELECT * from ticket_pri ORDER by pri_order");
- while ($pri = $db->row_array()) {
- $priority[$pri[id]] = $pri[name];
- }
-
- $tech[0] = '--- None ---';
- // get technician data
- $db->query("SELECT id, username from tech");
- while ($tech_name = $db->row_array()) {
- $tech[$tech_name[id]] = $tech_name[username];
- }
- $bit = form_input('email', $gateway[email]);
- $table[] = array('<b>Email</b><br />The email address for this account', $bit);
- $bit = form_radio_yn('is_default', NULL, $gateway['is_default']);
- $table[] = array('<b>Default Account</b><br />Set this account as default', $bit);
- $bit = form_select(category, $categories, '', $gateway[category]);
- $table[] = array('<b>Category</b><br />Category to associate emails with', $bit);
- $bit = form_select('priority', $priority, '', $gateway[priority]);
- $table[] = array('<b>Priority</b><br />Priority to associate emails with', $bit);
- $bit = form_select('tech', $tech,'', $gateway[technician]);
- $table[] = array('<b>Tech Name</b><br />Associate email with a specific user?', $bit);
- $bit = form_radio_yn('auto_new', '', $gateway[auto_new]);
- $table[] = array('<b>New Ticket Autoresponder</b><br />Send new ticket autoresponder messages?', $bit);
- $bit = form_radio_yn('auto_reply', '', $gateway[auto_reply]);
- $table[] = array('<b>New Reply Autoresponder</b><br />Send new reply autoresponder messages?', $bit);
- if ($_REQUEST['do'] == 'add') {
- table_header('Create Gateway Account', 'email.php', array('do' => 'add2'));
- table_content('', $table);
- table_footer('Create Account');
- } else {
- table_header('Update Gateway Account', 'email.php', array('do' => 'edit2', 'id' => $gateway['id']));
- table_content('', $table);
- table_footer('Update Account');
- }
- }
- ?>