root/trunk/gui/client/mail_autoresponder_edit.php

Revision 1412, 5.1 kB (checked in by scitech, 32 minutes ago)

Fixed #1518: Virtual mail problem. Add support for alias subdomain mail (part I)

Line 
1 <?php
2 /**
3  * ispCP ω (OMEGA) a Virtual Hosting Control System
4  *
5  * @copyright     2001-2006 by moleSoftware GmbH
6  * @copyright     2006-2008 by ispCP | http://isp-control.net
7  * @version     SVN: $Id$
8  * @link         http://isp-control.net
9  * @author         ispCP Team
10  *
11  * @license
12  *   This program is free software; you can redistribute it and/or modify it under
13  *   the terms of the MPL General Public License as published by the Free Software
14  *   Foundation; either version 1.1 of the License, or (at your option) any later
15  *   version.
16  *   You should have received a copy of the MPL Mozilla Public License along with
17  *   this program; if not, write to the Open Source Initiative (OSI)
18  *   http://opensource.org | osi@opensource.org
19  */
20
21 require '../include/ispcp-lib.php';
22
23 check_login(__FILE__);
24
25 $tpl = new pTemplate();
26 $tpl->define_dynamic('page', Config::get('CLIENT_TEMPLATE_PATH') . '/mail_autoresponder_enable.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('logged_from', 'page');
29
30 // page functions.
31
32 function check_email_user(&$sql) {
33     $dmn_name = $_SESSION['user_logged'];
34     $mail_id = $_GET['id'];
35
36     $query = <<<SQL_QUERY
37         select
38           t1.*,
39           t2.domain_id,
40           t2.domain_name
41         from
42           mail_users as t1,
43           domain as t2
44         where
45           t1.mail_id = ?
46         and
47           t2.domain_id = t1.domain_id
48         and
49           t2.domain_name = ?
50 SQL_QUERY;
51
52     $rs = exec_query($sql, $query, array($mail_id, $dmn_name));
53
54     if ($rs->RecordCount() == 0) {
55         set_page_message(tr('User does not exist or you do not have permission to access this interface!'));
56         header('Location: mail_accounts.php');
57         die();
58     }
59 }
60
61 function gen_page_dynamic_data(&$tpl, &$sql, $mail_id, $read_from_db) {
62     // Get Message
63     if ($read_from_db) {
64         $query = <<<SQL_QUERY
65             SELECT
66                 mail_auto_respond_text, mail_acc
67             FROM
68                 mail_users
69             WHERE
70                 mail_id = ?
71 SQL_QUERY;
72         $rs = exec_query($sql, $query, array($mail_id));
73         $mail_name = $rs->fields['mail_acc'];
74
75         $tpl->assign('ARSP_MESSAGE', $rs->fields['mail_auto_respond_text']);
76         return;
77     } else {
78         $arsp_message = clean_input($_POST['arsp_message']);
79     }
80
81     $item_change_status = Config::get('ITEM_CHANGE_STATUS');
82     check_for_lock_file();
83
84     if (isset($_POST['uaction']) && $_POST['uaction'] === 'enable_arsp') {
85         if (empty($_POST['arsp_message'])) {
86             $tpl->assign('ARSP_MESSAGE', '');
87             set_page_message(tr('Please type your mail autorespond message!'));
88             return;
89         }
90
91         $query = <<<SQL_QUERY
92             UPDATE
93                 `mail_users`
94             SET
95                 `status` = ?,
96                 `mail_auto_respond_text` = ?
97             WHERE
98                 `mail_id` = ?
99 SQL_QUERY;
100
101         $rs = exec_query($sql, $query, array($item_change_status, $arsp_message, $mail_id));
102
103         send_request();
104         $query = "
105             SELECT
106                 `mail_type`,
107                 IF(`mail_type` like 'normal_%',t2.`domain_name`,
108                     IF(`mail_type` like 'alias_%',t3.`alias_name`,
109                         IF(`mail_type` like 'subdom_%',CONCAT(t4.`subdomain_name`,'.',t6.`domain_name`),CONCAT(t5.`subdomain_alias_name`,'.',t7.`alias_name`))
110                     )
111                 ) AS mailbox
112             FROM
113                 `mail_users` as t1
114             left join (domain as t2) on (t1.domain_id=t2.domain_id)
115             left join (domain_aliasses as t3) on (sub_id=alias_id)
116             left join (subdomain as t4) on (sub_id=subdomain_id)
117             left join (subdomain_alias as t5) on (sub_id=subdomain_alias_id)
118             left join (domain as t6) on (t4.domain_id=t6.domain_id)
119             left join (domain_aliasses as t7) on (t5.alias_id=t7.alias_id)
120             WHERE
121                 `mail_id` = ?
122         ";
123
124         $rs = exec_query($sql, $query, array($mail_id));
125         $mail_name = $rs->fields['mailbox'];
126         write_log($_SESSION['user_logged'] . ": changes mail autoresponder: " . $mail_name);
127         set_page_message(tr('Mail account scheduler for modification!'));
128         header("Location: mail_accounts.php");
129         exit(0);
130     } else {
131         $tpl->assign('ARSP_MESSAGE', '');
132     }
133 }
134
135 // common page data.
136
137 if (isset($_GET['id'])) {
138     $mail_id = $_GET['id'];
139 } else if (isset($_POST['id'])) {
140     $mail_id = $_POST['id'];
141 } else {
142     header("Location: mail_accounts.php");
143     exit(0);
144 }
145
146 if (isset($_SESSION['email_support']) && $_SESSION['email_support'] == "no") {
147     header("Location: index.php");
148 }
149
150 $theme_color = Config::get('USER_INITIAL_THEME');
151
152 $tpl->assign(
153     array(
154         'TR_CLIENT_ENABLE_AUTORESPOND_PAGE_TITLE'    => tr('ispCP - Client/Enable Mail Auto Responder'),
155         'THEME_COLOR_PATH'                            => "../themes/$theme_color",
156         'THEME_CHARSET'                                => tr('encoding'),
157         'ISP_LOGO'                                    => get_logo($_SESSION['user_id'])
158     )
159 );
160
161 // dynamic page data.
162
163 check_email_user($sql);
164 gen_page_dynamic_data($tpl, $sql, $mail_id, !isset($_POST['uaction']));
165
166 // static page messages.
167
168 gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_email_accounts.tpl');
169 gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_email_accounts.tpl');
170
171 gen_logged_from($tpl);
172
173 check_permissions($tpl);
174
175 $tpl->assign(
176     array(
177         'TR_ENABLE_MAIL_AUTORESPONDER'    => tr('Edit mail auto responder'),
178         'TR_ARSP_MESSAGE'                => tr('Your message'),
179         'TR_ENABLE'                        => tr('Save'),
180         'TR_CANCEL'                        => tr('Cancel'),
181         'ID'                            => $mail_id
182     )
183 );
184 gen_page_message($tpl);
185
186 $tpl->parse('PAGE', 'page');
187 $tpl->prnt();
188
189 if (Config::get('DUMP_GUI_DEBUG'))
190     dump_gui_debug();
191
192 unset_messages();
193
194 ?>
Note: See TracBrowser for help on using the browser.