root/trunk/gui/client/domains_manage.php

Revision 1387, 8.5 kB (checked in by scitech, 1 month ago)

Subdomain with existing mountpoint not possible

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') . '/domains_manage.tpl');
27 $tpl->define_dynamic('page_message', 'page');
28 $tpl->define_dynamic('logged_from', 'page');
29 $tpl->define_dynamic('als_message', 'page');
30 $tpl->define_dynamic('als_list', 'page');
31 $tpl->define_dynamic('als_item', 'als_list');
32 $tpl->define_dynamic('sub_message', 'page');
33 $tpl->define_dynamic('sub_list', 'page');
34 $tpl->define_dynamic('sub_item', 'sub_list');
35
36 // page functions.
37
38 function gen_user_sub_action($sub_id, $sub_status) {
39     if ($sub_status === Config::get('ITEM_OK_STATUS')) {
40         return array(tr('Delete'), "subdomain_delete.php?id=$sub_id");
41     } else {
42         return array(tr('N/A'), '#');
43     }
44 }
45
46 function gen_user_alssub_action($sub_id, $sub_status) {
47     if ($sub_status === Config::get('ITEM_OK_STATUS')) {
48         return array(tr('Delete'), "alssub_delete.php?id=$sub_id");
49     } else {
50         return array(tr('N/A'), '#');
51     }
52 }
53
54 function gen_user_sub_list(&$tpl, &$sql, $user_id) {
55     $domain_id = get_user_domain_id($sql, $user_id);
56
57     $query = <<<SQL_QUERY
58         SELECT
59             subdomain_id, subdomain_name, subdomain_mount, subdomain_status, domain_name
60         FROM
61             subdomain join domain
62         ON
63             subdomain.domain_id = domain.domain_id
64         WHERE
65             subdomain.domain_id = ?
66         ORDER BY
67             subdomain_name
68 SQL_QUERY;
69             
70   $query2 = <<<SQL_QUERY
71         SELECT
72             subdomain_alias_id, subdomain_alias_name, subdomain_alias_mount, subdomain_alias_status, alias_name
73         FROM
74             subdomain_alias join domain_aliasses
75         ON
76             subdomain_alias.alias_id = domain_aliasses.alias_id
77         WHERE
78             domain_id = ?
79         ORDER BY
80             subdomain_alias_name
81 SQL_QUERY;
82
83     $rs = exec_query($sql, $query, array($domain_id));
84     $rs2 = exec_query($sql, $query2, array($domain_id));
85
86     if ( ( $rs->RecordCount() + $rs2->RecordCount() ) == 0) {
87         $tpl->assign(array('SUB_MSG' => tr('Subdomain list is empty!'), 'SUB_LIST' => ''));
88         $tpl->parse('SUB_MESSAGE', 'sub_message');
89     } else {
90         $counter = 0;
91         while (!$rs->EOF) {
92             if ($counter % 2 == 0) {
93                 $tpl->assign('ITEM_CLASS', 'content');
94             } else {
95                 $tpl->assign('ITEM_CLASS', 'content2');
96             }
97
98             list($sub_action, $sub_action_script) = gen_user_sub_action($rs->fields['subdomain_id'], $rs->fields['subdomain_status']);
99             $sbd_name = decode_idna($rs->fields['subdomain_name']);
100             $tpl->assign(
101                         array(
102                             'SUB_NAME' => $sbd_name,
103                             'SUB_ALIAS_NAME'    =>    $rs->fields['domain_name'],
104                             'SUB_MOUNT' => $rs->fields['subdomain_mount'],
105                             'SUB_STATUS' => translate_dmn_status($rs->fields['subdomain_status']),
106                             'SUB_ACTION' => $sub_action,
107                             'SUB_ACTION_SCRIPT' => $sub_action_script
108                         )
109                     );
110             $tpl->parse('SUB_ITEM', '.sub_item');
111             $rs->MoveNext();
112             $counter++;
113         }
114         while (!$rs2->EOF) {
115             if ($counter % 2 == 0) {
116                 $tpl->assign('ITEM_CLASS', 'content');
117             } else {
118                 $tpl->assign('ITEM_CLASS', 'content2');
119             }
120
121             list($sub_action, $sub_action_script) = gen_user_alssub_action($rs2->fields['subdomain_alias_id'], $rs2->fields['subdomain_alias_status']);
122             $sbd_name = decode_idna($rs2->fields['subdomain_alias_name']);
123             $tpl->assign(
124                         array(
125                             'SUB_NAME' => $sbd_name,
126                             'SUB_ALIAS_NAME'    =>    $rs2->fields['alias_name'],
127                             'SUB_MOUNT' => $rs2->fields['subdomain_alias_mount'],
128                             'SUB_STATUS' => translate_dmn_status($rs2->fields['subdomain_alias_status']),
129                             'SUB_ACTION' => $sub_action,
130                             'SUB_ACTION_SCRIPT' => $sub_action_script
131                         )
132                     );
133             $tpl->parse('SUB_ITEM', '.sub_item');
134             $rs2->MoveNext();
135             $counter++;
136         }
137         
138         $tpl->parse('SUB_LIST', 'sub_list');
139       $tpl->assign('SUB_MESSAGE', '');       
140     }
141 }
142
143 function gen_user_als_action($als_id, $als_status) {
144     if ($als_status === Config::get('ITEM_OK_STATUS')) {
145         return array(tr('Delete'), "alias_delete.php?id=$als_id");
146     } else if ($als_status === Config::get('ITEM_ORDERED_STATUS')) {
147         return array(tr('Delete order'), "alias_order_delete.php?del_id=$als_id");
148     } else {
149         return array(tr('N/A'), '#');
150     }
151 }
152
153 function gen_user_als_forward($als_id, $als_status, $url_forward) {
154     if ($url_forward === 'no') {
155         if ($als_status === 'ok') {
156             return array("-", "alias_edit.php?edit_id=" . $als_id, tr("Edit"));
157         } else if ($als_status === 'ordered') {
158             return array("-", "#", tr("N/A"));
159         } else {
160             return array(tr("N/A"), "#", tr("N/A"));
161         }
162     } else {
163         if ($als_status === 'ok') {
164             return array($url_forward, "alias_edit.php?edit_id=" . $als_id, tr("Edit"));
165         } else if ($als_status === 'ordered') {
166             return array($url_forward, "#", tr("N/A"));
167         } else {
168             return array(tr("N/A"), "#", tr("N/A"));
169         }
170     }
171 }
172
173 function gen_user_als_list(&$tpl, &$sql, $user_id) {
174     $domain_id = get_user_domain_id($sql, $user_id);
175
176     $query = <<<SQL_QUERY
177         SELECT
178             alias_id, alias_name, alias_status, alias_mount, alias_ip_id, url_forward
179         FROM
180             domain_aliasses
181         WHERE
182             domain_id = ?
183         ORDER BY
184             alias_mount,
185             alias_name
186 SQL_QUERY;
187
188     $rs = exec_query($sql, $query, array($domain_id));
189
190     if ($rs->RecordCount() == 0) {
191         $tpl->assign(array('ALS_MSG' => tr('Alias list is empty!'), 'ALS_LIST' => ''));
192         $tpl->parse('ALS_MESSAGE', 'als_message');
193     } else {
194         $counter = 0;
195         while (!$rs->EOF) {
196             if ($counter % 2 == 0) {
197                 $tpl->assign('ITEM_CLASS', 'content');
198             } else {
199                 $tpl->assign('ITEM_CLASS', 'content2');
200             }
201             list($als_action, $als_action_script) = gen_user_als_action($rs->fields['alias_id'], $rs->fields['alias_status']);
202             list($als_forward, $alias_edit_link, $als_edit) = gen_user_als_forward($rs->fields['alias_id'], $rs->fields['alias_status'], $rs->fields['url_forward']);
203
204             $alias_name = decode_idna($rs->fields['alias_name']);
205             $als_forward = decode_idna($als_forward);
206             $tpl->assign(
207                         array(
208                             'ALS_NAME' => $alias_name,
209                             'ALS_MOUNT' => $rs->fields['alias_mount'],
210                             'ALS_STATUS' => translate_dmn_status($rs->fields['alias_status']),
211                             'ALS_FORWARD' => $als_forward,
212                             'ALS_EDIT_LINK' => $alias_edit_link,
213                             'ALS_EDIT' => $als_edit,
214                             'ALS_ACTION' => $als_action,
215                             'ALS_ACTION_SCRIPT' => $als_action_script
216                         )
217                     );
218             $tpl->parse('ALS_ITEM', '.als_item');
219             $rs->MoveNext();
220             $counter ++;
221         }
222
223         $tpl->parse('ALS_LIST', 'als_list');
224         $tpl->assign('ALS_MESSAGE', '');
225     }
226 }
227
228 // common page data.
229
230 $theme_color = Config::get('USER_INITIAL_THEME');
231
232 $tpl->assign(array('TR_CLIENT_MANAGE_DOMAINS_PAGE_TITLE' => tr('ispCP - Client/Manage Domains'),
233         'THEME_COLOR_PATH' => "../themes/$theme_color",
234         'THEME_CHARSET' => tr('encoding'),
235         'ISP_LOGO' => get_logo($_SESSION['user_id'])));
236
237 // dynamic page data.
238
239 gen_user_sub_list($tpl, $sql, $_SESSION['user_id']);
240 gen_user_als_list($tpl, $sql, $_SESSION['user_id']);
241
242 // static page messages.
243
244 gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_manage_domains.tpl');
245 gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_manage_domains.tpl');
246
247 gen_logged_from($tpl);
248
249 check_permissions($tpl);
250
251 $tpl->assign(
252         array(
253             'TR_MANAGE_DOMAINS' => tr('Manage domains'),
254             'TR_DOMAIN_ALIASES' => tr('Domain aliases'),
255             'TR_ALS_NAME' => tr('Name'),
256             'TR_ALS_MOUNT' => tr('Mount point'),
257             'TR_ALS_FORWARD' => tr('Forward'),
258             'TR_ALS_STATUS' => tr('Status'),
259             'TR_ALS_ACTION' => tr('Action'),
260             'TR_SUBDOMAINS' => tr('Subdomains'),
261             'TR_SUB_NAME' => tr('Name'),
262             'TR_SUB_MOUNT' => tr('Mount point'),
263             'TR_SUB_STATUS' => tr('Status'),
264             'TR_SUB_ACTION' => tr('Actions'),
265             'TR_MESSAGE_DELETE' => tr('Are you sure you want to delete %s?', true, '%s')
266         )
267     );
268
269 gen_page_message($tpl);
270 $tpl->parse('PAGE', 'page');
271 $tpl->prnt();
272
273 if (Config::get('DUMP_GUI_DEBUG'))
274     dump_gui_debug();
275
276 unset_messages();
277
278 ?>
279
Note: See TracBrowser for help on using the browser.