root/tags/omega-1.0.0-rc3/gui/reseller/domain_alias.php

Revision 880, 10.8 KB (checked in by raphael, 15 months ago)

Fixed #7: no user set to run awstats cronjobs
Fixed #796: let aliases share the same mount point with a subdomain
Fixed some issues with email forwarders (see #555)
Reduced number of entries in admin's log
Fixed #152: Add webmaster@… and postmaster@…

Line 
1<?php
2/**
3 * ispCP ω (OMEGA) a Virtual Hosting Control System
4 *
5 * @copyright     2001-2006 by moleSoftware GmbH
6 * @copyright     2006-2007 by ispCP | http://isp-control.net
7 * @version     SVN: $ID$
8 * @link         http://isp-control.net
9 * @author         ispCP Team (2007)
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
21require '../include/ispcp-lib.php';
22
23check_login(__FILE__);
24
25$tpl = new pTemplate();
26
27$tpl->define_dynamic('page', $cfg['RESELLER_TEMPLATE_PATH'] . '/domain_alias.tpl');
28$tpl->define_dynamic('page_message', 'page');
29$tpl->define_dynamic('logged_from', 'page');
30$tpl->define_dynamic('table_list', 'page');
31$tpl->define_dynamic('table_item', 'table_list');
32$tpl->define_dynamic('scroll_prev', 'page');
33$tpl->define_dynamic('scroll_next_gray', 'page');
34$tpl->define_dynamic('scroll_next', 'page');
35
36$theme_color = $cfg['USER_INITIAL_THEME'];
37
38$tpl->assign(
39        array(
40            'TR_ALIAS_PAGE_TITLE' => tr('ispCP - Manage Domain/Alias'),
41            'THEME_COLOR_PATH' => "../themes/$theme_color",
42            'THEME_CHARSET' => tr('encoding'),
43            'ISPCP_LICENSE' => $cfg['ISPCP_LICENSE'],
44            'ISP_LOGO' => get_logo($_SESSION['user_id']),
45        )
46    );
47
48/*
49 *
50 * static page messages.
51 *
52 */
53
54gen_reseller_mainmenu($tpl, $cfg['RESELLER_TEMPLATE_PATH'] . '/main_menu_manage_users.tpl');
55gen_reseller_menu($tpl, $cfg['RESELLER_TEMPLATE_PATH'] . '/menu_manage_users.tpl');
56
57gen_logged_from($tpl);
58
59$err_txt = "_off_";
60
61generate_als_list($tpl, $_SESSION['user_id'], $err_txt);
62
63generate_als_messages($tpl, $err_txt);
64
65$tpl->assign(
66        array(
67            'TR_MANAGE_ALIAS' => tr('Manage alias'),
68            'TR_NAME' => tr('Name'),
69            'TR_REAL_DOMAIN' => tr('Real domain'),
70            'TR_FORWARD' => tr('Forward'),
71            'TR_STATUS' => tr('Status'),
72            'TR_ACTION' => tr('Action'),
73            'TR_ADD_ALIAS' => tr('Add alias'),
74            'TR_MESSAGE_DELETE' => tr('Are you sure you want to delete'),
75        )
76    );
77
78$tpl->parse('PAGE', 'page');
79
80$tpl->prnt();
81
82if ($cfg['DUMP_GUI_DEBUG'])
83    dump_gui_debug();
84
85unset_messages();
86
87// Function declaration
88
89// Generate domain alias list
90function generate_als_list(&$tpl, $reseller_id, &$als_err) {
91    global $sql, $cfg;
92
93    $have_aliases = '_no_';
94
95    $start_index = 0;
96
97    $rows_per_page = $cfg['DOMAIN_ROWS_PER_PAGE'];
98
99    $current_psi = 0;
100    $_SESSION['search_for'] = '';
101    $search_common = '';
102    $search_for = '';
103
104    if (isset($_GET['psi'])) {
105        $start_index = $_GET['psi'];
106        $current_psi = $_GET['psi'];
107    }
108
109    if (isset($_POST['uaction']) && !empty($_POST['uaction'])) {
110        $_SESSION['search_for'] = trim(clean_input($_POST['search_for']));
111
112        $_SESSION['search_common'] = $_POST['search_common'];
113
114        $search_for = $_SESSION['search_for'];
115
116        $search_common = $_SESSION['search_common'];
117    } else {
118        if (isset($_SESSION['search_for']) && !isset($_GET['psi'])) {
119            unset($_SESSION['search_for']);
120
121            unset($_SESSION['search_common']);
122        }
123    }
124    $tpl->assign(
125                array(
126                    'PSI' => $current_psi,
127                    'SEARCH_FOR' => stripslashes($search_for),
128                    'TR_SEARCH' => tr('Search'),
129                    'M_ALIAS_NAME' => tr('Alias name'),
130                    'M_ACCOUNT_NAME' => tr('Account name'),
131                )
132        );
133
134    if (isset($_SESSION['search_for']) && $_SESSION['search_for'] != '') {
135        if (isset($search_common) && $search_common == 'alias_name') {
136            $query = <<<SQL_QUERY
137        SELECT
138            t1.*,
139            t2.domain_id,
140            t2.domain_name,
141            t2.domain_created_id
142        FROM
143            domain_aliasses AS t1,
144            domain AS t2
145        WHERE
146            alias_name RLIKE '$search_for'
147          AND
148            t2.domain_created_id = ?
149          AND
150            t1.domain_id = t2.domain_id
151        ORDER BY
152            t1.alias_name ASC
153        LIMIT
154            $start_index, $rows_per_page
155SQL_QUERY;
156            // count query
157            $count_query = <<<SQL_QUERY
158        SELECT
159            COUNT(alias_id) AS cnt
160        FROM
161               domain_aliasses AS t1,
162            domain AS t2
163        WHERE
164            t2.domain_created_id = ?
165          AND
166            alias_name RLIKE '$search_for'
167          AND
168            t1.domain_id = t2.domain_id
169SQL_QUERY;
170        } else {
171            $query = <<<SQL_QUERY
172        SELECT
173            t1.*,
174            t2.domain_id,
175            t2.domain_name,
176            t2.domain_created_id
177        FROM
178            domain_aliasses AS t1,
179            domain AS t2
180        WHERE
181            t2.domain_name RLIKE '$search_for'
182          AND
183            t1.domain_id = t2.domain_id
184          AND
185            t2.domain_created_id = ?
186        ORDER BY
187            t1.alias_name ASC
188        LIMIT
189            $start_index, $rows_per_page
190SQL_QUERY;
191            // count query
192            $count_query = <<<SQL_QUERY
193        SELECT
194            COUNT(alias_id) AS cnt
195        FROM
196            domain_aliasses AS t1,
197            domain AS t2
198        WHERE
199            t2.domain_created_id = ?
200          AND
201            t2.domain_name RLIKE '$search_for'
202          AND
203            t1.domain_id = t2.domain_id
204SQL_QUERY;
205        }
206    } else {
207        $query = <<<SQL_QUERY
208        SELECT
209             t1.*,
210             t2.domain_id,
211             t2.domain_name,
212             t2.domain_created_id
213        FROM
214            domain_aliasses AS t1,
215            domain AS t2
216        WHERE
217            t1.domain_id = t2.domain_id
218          AND
219            t2.domain_created_id = ?
220        ORDER BY
221            t1.alias_name ASC
222        LIMIT
223            $start_index, $rows_per_page
224SQL_QUERY;
225        // count query
226        $count_query = <<<SQL_QUERY
227        SELECT
228            COUNT(alias_id) AS cnt
229        FROM
230            domain_aliasses AS t1,
231            domain AS t2
232        WHERE
233            t1.domain_id = t2.domain_id
234          AND
235            t2.domain_created_id = ?
236SQL_QUERY;
237    }
238    // lets count
239    $rs = exec_query($sql, $count_query, array($reseller_id));
240    $records_count = $rs->fields['cnt'];
241    // Get all alias records
242    $rs = exec_query($sql, $query, array($reseller_id));
243
244    if ($records_count == 0) {
245        $tpl->assign(
246                    array(
247                        'TABLE_LIST' => '',
248                        'USERS_LIST' => '',
249                        'SCROLL_PREV' => '',
250                        'SCROLL_NEXT' => '',
251                    )
252            );
253
254        if (isset($_SESSION['search_for'])) {
255            $als_err = tr('Not found user records matching the search criteria!');
256        } else {
257            $als_err = tr('You have no alias records.');
258        }
259        return;
260    } else {
261        $prev_si = $start_index - $rows_per_page;
262
263        if ($start_index == 0) {
264            $tpl->assign('SCROLL_PREV', '');
265        } else {
266            $tpl->assign(
267                    array(
268                        'SCROLL_PREV_GRAY' => '',
269                        'PREV_PSI' => $prev_si
270                    )
271                );
272        }
273
274        $next_si = $start_index + $rows_per_page;
275
276        if ($next_si + 1 > $records_count) {
277            $tpl->assign('SCROLL_NEXT', '');
278        } else {
279            $tpl->assign(
280                    array(
281                        'SCROLL_NEXT_GRAY' => '',
282                        'NEXT_PSI' => $next_si
283                    )
284                );
285        }
286    }
287
288    $i = 1;
289
290    while (!$rs->EOF) {
291        $als_id = $rs->fields['alias_id'];
292        $domain_id = $rs->fields['domain_id'];
293        $als_name = $rs->fields['alias_name'];
294        $als_mount_point = $rs->fields['alias_mount'];
295        $als_status = $rs->fields['alias_status'];
296        $als_ip_id = $rs->fields['alias_ip_id'];
297        $als_fwd = $rs->fields['url_forward'];
298        $show_als_fwd = ($als_fwd == 'no') ? "-" : $als_fwd;
299
300        $domain_name = decode_idna($rs->fields['domain_name']);
301
302        if ($als_mount_point == '') $als_mount_point = "/";
303
304        $query = "select ip_number, ip_domain from server_ips where ip_id = ?";
305
306        $alsip_r = exec_query($sql, $query, array($als_ip_id));
307        $alsip_d = $alsip_r->FetchRow();
308
309        $als_ip = $alsip_d['ip_number'];
310        $als_ip_name = $alsip_d['ip_domain'];
311
312        if ($i % 2 == 0) {
313            $page_cont = 'content';
314        } else {
315            $page_cont = 'content2';
316        }
317
318        if ($als_status === $cfg['ITEM_OK_STATUS']) {
319            $delete_link = "delete_domainalias.php?del_id=" . $als_id;
320            $edit_link = "edit_alias.php?edit_id=" . $als_id;
321            $action_text = tr("Delete");
322            $edit_text = tr("Edit");
323        } else if ($als_status === $cfg['ITEM_ORDERED_STATUS']){
324            $delete_link = "domainaliasorder.php?action=delete&del_id=".$als_id;
325            $edit_link = "domainaliasorder.php?action=activate&act_id=".$als_id;
326            $action_text = tr("Delete order");
327            $edit_text = tr("Activate");
328        } else {
329            $delete_link = "#";
330            $edit_link = "#";
331            $action_text = tr('N/A');
332            $edit_text = tr('N/A');
333        }
334        $als_status = translate_dmn_status($als_status);
335        $als_name = decode_idna($als_name);
336        $show_als_fwd = decode_idna($show_als_fwd);
337
338        if (isset($_SESSION['search_common']) && $_SESSION['search_common'] === 'account_name') {
339            $domain_name_selected = "";
340            $account_name_selected = "selected";
341        } else {
342            $domain_name_selected = "selected";
343            $account_name_selected = "";
344        }
345
346        $tpl->assign(
347                    array(
348                        'NAME' => $als_name,
349                        'ALIAS_IP' => "$als_ip ($als_ip_name)",
350                        'REAL_DOMAIN' => $domain_name,
351                        'REAL_DOMAIN_MOUNT' => $als_mount_point,
352                        'FORWARD' => $show_als_fwd,
353                        'STATUS' => $als_status,
354                        'ID' => $als_id,
355                        'DELETE' => $action_text,
356                        'CONTENT' => $page_cont,
357                        'DELETE_LINK' => $delete_link,
358                        'EDIT_LINK' => $edit_link,
359                        'EDIT' => $edit_text,
360                        'M_DOMAIN_NAME_SELECTED' => $domain_name_selected,
361                        'M_ACCOUN_NAME_SELECTED' => $account_name_selected,
362                    )
363            );
364
365        $i++;
366        $tpl->parse('TABLE_ITEM', '.table_item');
367        $rs->MoveNext();
368    }
369} // End of generate_als_list()
370
371function generate_als_messages(&$tpl, $als_err) {
372    if ($als_err != '_off_') {
373        $tpl->assign(
374            array('MESSAGE' => $als_err)
375            );
376        $tpl->parse('PAGE_MESSAGE', 'page_message');
377        return;
378    } else if (isset($_SESSION["dahavemail"])) {
379        $tpl->assign('MESSAGE', tr('Domain alias you are trying to remove has email accounts !<br>First remove them!'));
380        unset($_SESSION['dahavemail']);
381    } else if (isset($_SESSION["dahaveftp"])) {
382        $tpl->assign('MESSAGE', tr('Domain alias you are trying to remove has FTP accounts!<br>First remove them!'));
383        unset($_SESSION['dahavemail']);
384    } else if (isset($_SESSION["aldel"])) {
385        if ('_yes_' === $_SESSION['aldel'])
386            $tpl->assign('MESSAGE', tr('Domain alias added for termination!'));
387        else
388            $tpl->assign('MESSAGE', tr('Domain alias not added for termination!'));
389
390        unset($_SESSION['aldel']);
391    } else if (isset($_SESSION['aladd'])) {
392        if ('_yes_' === $_SESSION['aladd'])
393            $tpl->assign('MESSAGE', tr('Domain alias added!'));
394        else
395            $tpl->assign('MESSAGE', tr('Domain alias not added!'));
396
397        unset($_SESSION['aladd']);
398    } else if (isset($_SESSION['aledit'])) {
399        if ('_yes_' === $_SESSION['aledit'])
400            $tpl->assign('MESSAGE', tr('Domain alias modified!'));
401        else
402            $tpl->assign('MESSAGE', tr('Domain alias not modified!'));
403
404        unset($_SESSION['aledit']);
405    } else if(isset($_SESSION['orderaldel'])){
406        if('_no_' === $_SESSION['orderaldel']) {
407            $tpl -> assign('MESSAGE', tr('Ordered domain alias not deleted!'));
408        }
409        unset($_SESSION['orderaldel']);
410    } else if(isset($_SESSION['orderalact'])){
411        if('_yes_' === $_SESSION['orderalact'])
412            $tpl -> assign('MESSAGE', tr('Ordered domain alias activated!'));
413        else
414            $tpl -> assign('MESSAGE', tr('Ordered domain alias not activated!'));
415
416        unset($_SESSION['orderalact']);
417    } else {
418        $tpl->assign('MESSAGE', '');
419        $tpl->assign('PAGE_MESSAGE', "");
420    }
421} // End of generate_als_messages()
422
423?>
Note: See TracBrowser for help on using the browser.