root/trunk/gui/client/mail_catchall.php

Revision 1412, 8.8 kB (checked in by scitech, 41 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_catchall.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('logged_from', 'page');
29 $tpl->define_dynamic('catchall_message', 'page');
30 $tpl->define_dynamic('catchall_item', 'page');
31
32
33 // page functions.
34
35 function gen_user_mail_action($mail_id, $mail_status) {
36     if ($mail_status === Config::get('ITEM_OK_STATUS')) {
37         return array(tr('Delete'), "mail_delete.php?id=$mail_id", "mail_edit.php?id=$mail_id");
38     } else {
39         return array(tr('N/A'), '#', '#');
40     }
41 }
42
43 function gen_user_catchall_action($mail_id, $mail_status) {
44     if ($mail_status === Config::get('ITEM_ADD_STATUS')) {
45         return array(tr('N/A'), '#');//Addition in progress
46     } else if ($mail_status === Config::get('ITEM_OK_STATUS')) {
47         return array(tr('Delete CatchAll'), "mail_catchall_delete.php?id=$mail_id");
48     } else if ($mail_status === Config::get('ITEM_CHANGE_STATUS')) {
49         return array(tr('N/A'), '#');
50     } else if ($mail_status === Config::get('ITEM_DELETE_STATUS')) {
51         return array(tr('N/A'), '#');
52     } else {
53         return null;
54     }
55 }
56
57 function gen_catchall_item(&$tpl, $action, $dmn_id, $dmn_name, $mail_id, $mail_acc, $mail_status, $ca_type) {
58     $show_dmn_name = decode_idna($dmn_name);
59
60     if ($action === 'create') {
61         $tpl->assign(
62             array(
63                 'CATCHALL_DOMAIN'            => $show_dmn_name,
64                 'CATCHALL_ACC'                => tr('None'),
65                 'CATCHALL_STATUS'            => tr('N/A'),
66                 'CATCHALL_ACTION'            => tr('Create catch all'),
67                 'CATCHALL_ACTION_SCRIPT'    => "mail_catchall_add.php?id=$dmn_id;$ca_type"
68                 )
69             );
70     } else {
71         list($catchall_action, $catchall_action_script) = gen_user_catchall_action($mail_id, $mail_status);
72
73         $show_dmn_name = decode_idna($dmn_name);
74         $show_mail_acc = decode_idna($mail_acc);
75
76         $tpl->assign(
77             array(
78                 'CATCHALL_DOMAIN' => $show_dmn_name,
79                 'CATCHALL_ACC' => $show_mail_acc,
80                 'CATCHALL_STATUS' => translate_dmn_status($mail_status),
81                 'CATCHALL_ACTION' => $catchall_action,
82                 'CATCHALL_ACTION_SCRIPT' => $catchall_action_script
83             )
84         );
85     }
86 }
87
88 function gen_page_catchall_list(&$tpl, &$sql, $dmn_id, $dmn_name) {
89     global $counter;
90
91     $tpl->assign('CATCHALL_MESSAGE', '');
92
93         $query = "
94             select
95                 mail_id, mail_acc, status
96             from
97                 mail_users
98             where
99                 domain_id = '$dmn_id'
100               and
101                 sub_id = 0
102               and
103                 mail_type = 'normal_catchall'
104         ";
105
106         $rs = execute_query($sql, $query);
107
108         if ($rs->RecordCount() == 0) {
109             gen_catchall_item($tpl, 'create', $dmn_id, $dmn_name, '', '', '', 'normal');
110         } else {
111             gen_catchall_item($tpl,
112                 'delete',
113                 $dmn_id,
114                 $dmn_name,
115                 $rs->fields['mail_id'],
116                 $rs->fields['mail_acc'],
117                 $rs->fields['status'], 'normal');
118         }
119         $tpl->assign(
120             array(
121                 'ITEM_CLASS' => 'content',
122             )
123         );
124
125         $tpl->parse('CATCHALL_ITEM', 'catchall_item');
126
127         $query = "
128             select
129                 alias_id, alias_name
130             from
131                 domain_aliasses
132             where
133                 domain_id = '$dmn_id'
134               and
135                 alias_status = 'ok'
136         ";
137
138         $rs = execute_query($sql, $query);
139
140         while (!$rs->EOF) {
141             if ($counter % 2 == 0) {
142                 $tpl->assign('ITEM_CLASS', 'content2');
143             } else {
144                 $tpl->assign('ITEM_CLASS', 'content');
145             }
146
147             $als_id = $rs->fields['alias_id'];
148
149             $als_name = $rs->fields['alias_name'];
150
151             $query = "
152                 select
153                     mail_id, mail_acc, status
154                 from
155                     mail_users
156                 where
157                     domain_id = '$dmn_id'
158                   and
159                     sub_id = '$als_id'
160                   and
161                     mail_type = 'alias_catchall'
162             ";
163
164             $rs_als = execute_query($sql, $query);
165
166             if ($rs_als->RecordCount() == 0) {
167                 gen_catchall_item($tpl, 'create', $als_id, $als_name, '', '', '', 'alias');
168             } else {
169                 gen_catchall_item(
170                     $tpl,
171                     'delete',
172                     $als_id,
173                     $als_name,
174                     $rs_als->fields['mail_id'],
175                     $rs_als->fields['mail_acc'],
176                     $rs_als->fields['status'], 'alias'
177                 );
178             }
179
180             $tpl->parse('CATCHALL_ITEM', '.catchall_item');
181
182             $rs->MoveNext();
183             $counter ++;
184         }
185
186         $query = "
187             select
188                 a.subdomain_alias_id, CONCAT(a.subdomain_alias_name,'.',b.alias_name) as subdomain_name
189             from
190                 subdomain_alias as a, domain_aliasses as b
191             where
192                 b.alias_id IN (SELECT `alias_id` FROM `domain_aliasses` WHERE `domain_id`='$dmn_id')
193             and
194                    a.alias_id = b.alias_id
195             and
196                 a.subdomain_alias_status = 'ok'
197         ";
198
199         $rs = execute_query($sql, $query);
200
201         while (!$rs->EOF) {
202             if ($counter % 2 == 0) {
203                 $tpl->assign('ITEM_CLASS', 'content2');
204             } else {
205                 $tpl->assign('ITEM_CLASS', 'content');
206             }
207
208             $als_id = $rs->fields['subdomain_alias_id'];
209
210             $als_name = $rs->fields['subdomain_name'];
211
212             $query = "
213                 select
214                     mail_id, mail_acc, status
215                 from
216                     mail_users
217                 where
218                     domain_id = '$dmn_id'
219                   and
220                     sub_id = '$als_id'
221                   and
222                     mail_type = 'alssub_catchall'
223             ";
224
225             $rs_als = execute_query($sql, $query);
226
227             if ($rs_als->RecordCount() == 0) {
228                 gen_catchall_item($tpl, 'create', $als_id, $als_name, '', '', '', 'alssub');
229             } else {
230                 gen_catchall_item(
231                     $tpl,
232                     'delete',
233                     $als_id,
234                     $als_name,
235                     $rs_als->fields['mail_id'],
236                     $rs_als->fields['mail_acc'],
237                     $rs_als->fields['status'], 'alssub'
238                 );
239             }
240
241             $tpl->parse('CATCHALL_ITEM', '.catchall_item');
242
243             $rs->MoveNext();
244             $counter ++;
245         }
246
247         $query = "
248             select
249                 a.subdomain_id, CONCAT(a.subdomain_name,'.',b.domain_name) as subdomain_name
250             from
251                 subdomain as a, domain as b
252             where
253                 a.domain_id = '$dmn_id'
254             and
255                    a.domain_id = b.domain_id
256             and
257                 a.subdomain_status = 'ok'
258         ";
259
260         $rs = execute_query($sql, $query);
261
262         while (!$rs->EOF) {
263             if ($counter % 2 == 0) {
264                 $tpl->assign('ITEM_CLASS', 'content2');
265             } else {
266                 $tpl->assign('ITEM_CLASS', 'content');
267             }
268
269             $als_id = $rs->fields['subdomain_id'];
270
271             $als_name = $rs->fields['subdomain_name'];
272
273             $query = "
274                 select
275                     mail_id, mail_acc, status
276                 from
277                     mail_users
278                 where
279                     domain_id = '$dmn_id'
280                   and
281                     sub_id = '$als_id'
282                   and
283                     mail_type = 'subdom_catchall'
284             ";
285
286             $rs_als = execute_query($sql, $query);
287
288             if ($rs_als->RecordCount() == 0) {
289                 gen_catchall_item($tpl, 'create', $als_id, $als_name, '', '', '', 'subdom');
290             } else {
291                 gen_catchall_item($tpl,
292                     'delete',
293                     $als_id,
294                     $als_name,
295                     $rs_als->fields['mail_id'],
296                     $rs_als->fields['mail_acc'],
297                     $rs_als->fields['status'], 'subdom');
298             }
299
300             $tpl->parse('CATCHALL_ITEM', '.catchall_item');
301
302             $rs->MoveNext();
303             $counter ++;
304         }
305 }
306
307 function gen_page_lists(&$tpl, &$sql, $user_id)
308 {
309     list($dmn_id,
310         $dmn_name,
311         $dmn_gid,
312         $dmn_uid,
313         $dmn_created_id,
314         $dmn_created,
315         $dmn_last_modified,
316         $dmn_mailacc_limit,
317         $dmn_ftpacc_limit,
318         $dmn_traff_limit,
319         $dmn_sqld_limit,
320         $dmn_sqlu_limit,
321         $dmn_status,
322         $dmn_als_limit,
323         $dmn_subd_limit,
324         $dmn_ip_id,
325         $dmn_disk_limit,
326         $dmn_disk_usage,
327         $dmn_php,
328         $dmn_cgi) = get_domain_default_props($sql, $user_id);
329
330     gen_page_catchall_list($tpl, $sql, $dmn_id, $dmn_name);
331     // gen_page_ftp_list($tpl, $sql, $dmn_id, $dmn_name);
332 }
333
334 // common page data.
335
336 $theme_color = Config::get('USER_INITIAL_THEME');
337
338 $tpl->assign(
339     array(
340         'TR_CLIENT_MANAGE_USERS_PAGE_TITLE'    => tr('ispCP - Client/Manage Users'),
341         'THEME_COLOR_PATH'                    => "../themes/$theme_color",
342         'THEME_CHARSET'                        => tr('encoding'),
343         'ISP_LOGO'                            => get_logo($_SESSION['user_id'])
344     )
345 );
346
347 // dynamic page data.
348
349 if (isset($_SESSION['email_support']) && $_SESSION['email_support'] == "no") {
350     $tpl->assign('NO_MAILS', '');
351 }
352
353 gen_page_lists($tpl, $sql, $_SESSION['user_id']);
354
355 // static page messages.
356
357 gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_email_accounts.tpl');
358 gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_email_accounts.tpl');
359
360 gen_logged_from($tpl);
361 check_permissions($tpl);
362
363 $tpl->assign(
364     array(
365         'TR_STATUS'                    => tr('Status'),
366         'TR_ACTION'                    => tr('Action'),
367         'TR_CATCHALL_MAIL_USERS'    => tr('Catch all account'),
368         'TR_DOMAIN'                    => tr('Domain'),
369         'TR_CATCHALL'                => tr('Catch all'),
370         'TR_MESSAGE_DELETE'            => tr('Are you sure you want to delete %s?', true, '%s')
371     )
372 );
373
374 gen_page_message($tpl);
375
376 $tpl->parse('PAGE', 'page');
377 $tpl->prnt();
378
379 if (Config::get('DUMP_GUI_DEBUG')) dump_gui_debug();
380
381 unset_messages();
382
383 ?>
384
Note: See TracBrowser for help on using the browser.