Skip to content

Commit 3e94c8b

Browse files
committed
hide client selector when domain module is enabled, auto get client from selected domain
1 parent 8537705 commit 3e94c8b

File tree

11 files changed

+240
-178
lines changed

11 files changed

+240
-178
lines changed

interface/lib/classes/tools_sites.inc.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ function checkDomainModuleDomain($domain_id) {
181181
return $domain['domain'];
182182
}
183183

184+
function getClientIdForDomain($domain_id) {
185+
global $app;
186+
187+
$sql = "SELECT sys_groupid FROM domain WHERE domain_id = " . $app->functions->intval($domain_id);
188+
if ($_SESSION["s"]["user"]["typ"] != 'admin') {
189+
$groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
190+
$sql .= " AND sys_groupid IN (".$groups.")";
191+
}
192+
$domain = $app->db->queryOneRecord($sql);
193+
if(!$domain || !$domain['sys_groupid']) return false;
194+
return $domain['sys_groupid'];
195+
}
196+
184197
}
185198

186199
?>

interface/web/dns/dns_slave_edit.php

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,30 @@ function onShowNew() {
7272
function onShowEnd() {
7373
global $app, $conf;
7474

75-
// If user is admin, we will allow him to select to whom this record belongs
76-
if($_SESSION["s"]["user"]["typ"] == 'admin') {
77-
// Getting Domains of the user
78-
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
79-
$clients = $app->db->queryAllRecords($sql);
80-
$client_select = '';
81-
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
82-
//$tmp_data_record = $app->tform->getDataRecord($this->id);
83-
if(is_array($clients)) {
84-
foreach( $clients as $client) {
85-
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
86-
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
75+
$app->uses('ini_parser,getconf');
76+
$settings = $app->getconf->get_global_config('domains');
77+
78+
/*
79+
* Now we have to check, if we should use the domain-module to select the domain
80+
* or not
81+
*/
82+
if ($settings['use_domain_module'] != 'y') {
83+
// If user is admin, we will allow him to select to whom this record belongs
84+
if($_SESSION["s"]["user"]["typ"] == 'admin') {
85+
// Getting Domains of the user
86+
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
87+
$clients = $app->db->queryAllRecords($sql);
88+
$client_select = '';
89+
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
90+
//$tmp_data_record = $app->tform->getDataRecord($this->id);
91+
if(is_array($clients)) {
92+
foreach( $clients as $client) {
93+
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
94+
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
95+
}
8796
}
88-
}
89-
$app->tpl->setVar("client_group_id", $client_select);
90-
} else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
97+
$app->tpl->setVar("client_group_id", $client_select);
98+
} else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
9199

92100
// Get the limits of the client
93101
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
@@ -108,14 +116,7 @@ function onShowEnd() {
108116
$app->tpl->setVar("client_group_id", $client_select);
109117

110118
}
111-
112-
/*
113-
* Now we have to check, if we should use the domain-module to select the domain
114-
* or not
115-
*/
116-
$app->uses('ini_parser,getconf');
117-
$settings = $app->getconf->get_global_config('domains');
118-
if ($settings['use_domain_module'] == 'y') {
119+
} else {
119120
/*
120121
* The domain-module is in use.
121122
*/
@@ -160,6 +161,9 @@ function onSubmit() {
160161
$app->uses('ini_parser,getconf');
161162
$settings = $app->getconf->get_global_config('domains');
162163
if ($settings['use_domain_module'] == 'y') {
164+
if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
165+
$this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['origin']);
166+
}
163167
$domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['origin']);
164168
if(!$domain_check) {
165169
// invalid domain selected

interface/web/dns/dns_soa_edit.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,30 @@ function onShowNew() {
8282
function onShowEnd() {
8383
global $app, $conf;
8484

85-
// If user is admin, we will allow him to select to whom this record belongs
86-
if($_SESSION["s"]["user"]["typ"] == 'admin') {
87-
// Getting Domains of the user
88-
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
89-
$clients = $app->db->queryAllRecords($sql);
90-
$client_select = '';
91-
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
92-
//$tmp_data_record = $app->tform->getDataRecord($this->id);
93-
if(is_array($clients)) {
94-
foreach( $clients as $client) {
95-
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
96-
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
85+
$app->uses('ini_parser,getconf');
86+
$settings = $app->getconf->get_global_config('domains');
87+
88+
/*
89+
* Now we have to check, if we should use the domain-module to select the domain
90+
* or not
91+
*/
92+
if ($settings['use_domain_module'] != 'y') {
93+
// If user is admin, we will allow him to select to whom this record belongs
94+
if($_SESSION["s"]["user"]["typ"] == 'admin') {
95+
// Getting Domains of the user
96+
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
97+
$clients = $app->db->queryAllRecords($sql);
98+
$client_select = '';
99+
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
100+
//$tmp_data_record = $app->tform->getDataRecord($this->id);
101+
if(is_array($clients)) {
102+
foreach( $clients as $client) {
103+
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
104+
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
105+
}
97106
}
98-
}
99-
$app->tpl->setVar("client_group_id", $client_select);
100-
} else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
107+
$app->tpl->setVar("client_group_id", $client_select);
108+
} else if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
101109

102110
// Get the limits of the client
103111
$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
@@ -118,7 +126,7 @@ function onShowEnd() {
118126
$app->tpl->setVar("client_group_id", $client_select);
119127

120128
}
121-
$app->tpl->setVar("client_group_id", $client_select);
129+
}
122130

123131
// }
124132

@@ -150,12 +158,6 @@ function onShowEnd() {
150158

151159
}
152160

153-
/*
154-
* Now we have to check, if we should use the domain-module to select the domain
155-
* or not
156-
*/
157-
$app->uses('ini_parser,getconf');
158-
$settings = $app->getconf->get_global_config('domains');
159161
if ($settings['use_domain_module'] == 'y') {
160162
/*
161163
* The domain-module is in use.
@@ -201,6 +203,9 @@ function onSubmit() {
201203
$app->uses('ini_parser,getconf');
202204
$settings = $app->getconf->get_global_config('domains');
203205
if ($settings['use_domain_module'] == 'y') {
206+
if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
207+
$this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['origin']);
208+
}
204209
$domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['origin']);
205210
if(!$domain_check) {
206211
// invalid domain selected

interface/web/dns/dns_wizard.php

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
unset($n);
7272
$app->tpl->setVar("template_id_option", $template_id_option);
7373

74+
$app->uses('ini_parser,getconf');
75+
$domains_settings = $app->getconf->get_global_config('domains');
76+
7477
// If the user is administrator
7578
if($_SESSION['s']['user']['typ'] == 'admin') {
7679

@@ -83,19 +86,21 @@
8386
}
8487
$app->tpl->setVar("server_id", $server_id_option);
8588

86-
// load the list of clients
87-
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
88-
$clients = $app->db->queryAllRecords($sql);
89-
$client_select = '';
90-
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
91-
if(is_array($clients)) {
92-
foreach( $clients as $client) {
93-
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':'';
94-
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
89+
if ($domains_settings['use_domain_module'] != 'y') {
90+
// load the list of clients
91+
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
92+
$clients = $app->db->queryAllRecords($sql);
93+
$client_select = '';
94+
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>";
95+
if(is_array($clients)) {
96+
foreach( $clients as $client) {
97+
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':'';
98+
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
99+
}
95100
}
96-
}
97101

98-
$app->tpl->setVar("client_group_id", $client_select);
102+
$app->tpl->setVar("client_group_id", $client_select);
103+
}
99104
}
100105

101106
if ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
@@ -105,19 +110,21 @@
105110
$client = $app->db->queryOneRecord("SELECT client.client_id, client.contact_name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname, sys_group.name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
106111

107112

108-
// load the list of clients
109-
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$app->functions->intval($client['client_id'])." ORDER BY client.company_name, client.contact_name, sys_group.name";
110-
$clients = $app->db->queryAllRecords($sql);
111-
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($client['client_id']));
112-
$client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>';
113-
if(is_array($clients)) {
114-
foreach( $clients as $client) {
115-
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':'';
116-
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
113+
if ($domains_settings['use_domain_module'] != 'y') {
114+
// load the list of clients
115+
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$app->functions->intval($client['client_id'])." ORDER BY client.company_name, client.contact_name, sys_group.name";
116+
$clients = $app->db->queryAllRecords($sql);
117+
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($client['client_id']));
118+
$client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>';
119+
if(is_array($clients)) {
120+
foreach( $clients as $client) {
121+
$selected = ($client["groupid"] == $sys_groupid)?'SELECTED':'';
122+
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
123+
}
117124
}
118-
}
119125

120-
$app->tpl->setVar("client_group_id", $client_select);
126+
$app->tpl->setVar("client_group_id", $client_select);
127+
}
121128
}
122129

123130
if($_SESSION["s"]["user"]["typ"] != 'admin')
@@ -162,9 +169,7 @@
162169
* Now we have to check, if we should use the domain-module to select the domain
163170
* or not
164171
*/
165-
$app->uses('ini_parser,getconf');
166-
$settings = $app->getconf->get_global_config('domains');
167-
if ($settings['use_domain_module'] == 'y') {
172+
if ($domains_settings['use_domain_module'] == 'y') {
168173
/*
169174
* The domain-module is in use.
170175
*/
@@ -215,7 +220,10 @@
215220
// apply filters
216221
if(isset($_POST['domain']) && $_POST['domain'] != ''){
217222
/* check if the domain module is used - and check if the selected domain can be used! */
218-
if ($settings['use_domain_module'] == 'y') {
223+
if ($domains_settings['use_domain_module'] == 'y') {
224+
if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
225+
$_POST['client_group_id'] = $app->tools_sites->getClientIdForDomain($_POST['domain']);
226+
}
219227
$domain_check = $app->tools_sites->checkDomainModuleDomain($_POST['domain']);
220228
if(!$domain_check) {
221229
// invalid domain selected

interface/web/dns/templates/dns_slave_edit.htm

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,24 @@ <h2><tmpl_var name="list_head_txt"></h2>
2020
</select>
2121
</tmpl_if>
2222
</div>
23-
<div class="ctrlHolder">
24-
<label for="client_group_id">{tmpl_var name='client_txt'}</label>
25-
<select name="client_group_id" id="client_group_id" class="selectInput">
26-
{tmpl_var name='client_group_id'}
27-
</select>
28-
</div>
23+
<tmpl_unless name="domain_option">
24+
<div class="ctrlHolder">
25+
<label for="client_group_id">{tmpl_var name='client_txt'}</label>
26+
<select name="client_group_id" id="client_group_id" class="selectInput">
27+
{tmpl_var name='client_group_id'}
28+
</select>
29+
</div>
30+
</tmpl_unless>
2931
</tmpl_if>
3032
<tmpl_if name="is_reseller">
31-
<div class="ctrlHolder">
32-
<label for="client_group_id">{tmpl_var name='client_txt'}</label>
33-
<select name="client_group_id" id="client_group_id" class="selectInput">
34-
{tmpl_var name='client_group_id'}
35-
</select>
36-
</div>
33+
<tmpl_unless name="domain_option">
34+
<div class="ctrlHolder">
35+
<label for="client_group_id">{tmpl_var name='client_txt'}</label>
36+
<select name="client_group_id" id="client_group_id" class="selectInput">
37+
{tmpl_var name='client_group_id'}
38+
</select>
39+
</div>
40+
</tmpl_unless>
3741
</tmpl_if>
3842
<div class="ctrlHolder">
3943
<label for="origin">{tmpl_var name='origin_txt'}</label>
@@ -100,4 +104,4 @@ <h2><tmpl_var name="list_head_txt"></h2>
100104
searchFieldWatermark: '',
101105
resultBoxPosition: 'e'
102106
});
103-
</script>
107+
</script>

interface/web/dns/templates/dns_soa_edit.htm

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ <h2><tmpl_var name="list_head_txt"></h2>
2020
</select>
2121
</tmpl_if>
2222
</div>
23-
<div class="ctrlHolder">
24-
<label for="client_group_id">{tmpl_var name='client_txt'}</label>
25-
<select name="client_group_id" id="client_group_id" class="selectInput">
26-
{tmpl_var name='client_group_id'}
27-
</select>
28-
</div>
23+
<tmpl_unless name="domain_option">
24+
<div class="ctrlHolder">
25+
<label for="client_group_id">{tmpl_var name='client_txt'}</label>
26+
<select name="client_group_id" id="client_group_id" class="selectInput">
27+
{tmpl_var name='client_group_id'}
28+
</select>
29+
</div>
30+
</tmpl_unless>
2931
<tmpl_else>
3032
<tmpl_if name="only_one_server">
3133
<input type="hidden" id="server_id" name="server_id" value="{tmpl_var name='server_id_value'}" />
@@ -47,12 +49,14 @@ <h2><tmpl_var name="list_head_txt"></h2>
4749
</tmpl_if>
4850
</tmpl_if>
4951
<tmpl_if name="is_reseller">
50-
<div class="ctrlHolder">
51-
<label for="client_group_id">{tmpl_var name='client_txt'}</label>
52-
<select name="client_group_id" id="client_group_id" class="selectInput">
53-
{tmpl_var name='client_group_id'}
54-
</select>
55-
</div>
52+
<tmpl_unless name="domain_option">
53+
<div class="ctrlHolder">
54+
<label for="client_group_id">{tmpl_var name='client_txt'}</label>
55+
<select name="client_group_id" id="client_group_id" class="selectInput">
56+
{tmpl_var name='client_group_id'}
57+
</select>
58+
</div>
59+
</tmpl_unless>
5660
</tmpl_if>
5761
<div class="ctrlHolder">
5862
<label for="origin">{tmpl_var name='origin_txt'}</label>
@@ -153,4 +157,4 @@ <h2><tmpl_var name="list_head_txt"></h2>
153157
searchFieldWatermark: '',
154158
resultBoxPosition: 'e'
155159
});
156-
</script>
160+
</script>

0 commit comments

Comments
 (0)