Skip to content

Commit 5192dbc

Browse files
author
Till Brehm
committed
Implemented: FS#926 - User assignment from a Reseller to a Reseller
1 parent e9b033f commit 5192dbc

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

interface/web/client/client_edit.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,24 @@ function onShowEnd() {
221221
}
222222
}
223223

224+
if($app->auth->is_admin()) {
225+
// Fill the client select field
226+
$sql = "SELECT client.client_id, 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 AND client.limit_client > 0 ORDER BY sys_group.name";
227+
$clients = $app->db->queryAllRecords($sql);
228+
$client_select = "<option value='0'>- ".$app->tform->lng('none_txt')." -</option>";
229+
//$tmp_data_record = $app->tform->getDataRecord($this->id);
230+
if(is_array($clients)) {
231+
$selected_client_id = 0; // needed to get list of PHP versions
232+
foreach($clients as $client) {
233+
if(is_array($this->dataRecord) && ($client["client_id"] == $this->dataRecord['parent_client_id']) && !$selected_client_id) $selected_client_id = $client["client_id"];
234+
$selected = @(is_array($this->dataRecord) && ($client["client_id"] == $this->dataRecord['parent_client_id']))?'SELECTED':'';
235+
if($selected == 'SELECTED') $selected_client_id = $client["client_id"];
236+
$client_select .= "<option value='$client[client_id]' $selected>$client[contactname]</option>\r\n";
237+
}
238+
}
239+
$app->tpl->setVar("parent_client_id", $client_select);
240+
}
241+
224242
parent::onShowEnd();
225243

226244
}
@@ -262,6 +280,14 @@ function onAfterInsert() {
262280
if($_SESSION['s']['user']['typ'] == 'user') {
263281
$app->auth->add_group_to_user($_SESSION['s']['user']['userid'], $groupid);
264282
$app->db->query("UPDATE client SET parent_client_id = ".$app->functions->intval($_SESSION['s']['user']['client_id'])." WHERE client_id = ".$this->id);
283+
} else {
284+
if($this->dataRecord['parent_client_id'] > 0) {
285+
//* get userid of the reseller and add it to the group of the client
286+
$tmp = $app->db->queryOneRecord("SELECT sys_user.userid FROM sys_user,sys_group WHERE sys_user.default_group = sys_group.groupid AND sys_group.client_id = ".$app->functions->intval($this->dataRecord['parent_client_id']));
287+
$app->auth->add_group_to_user($tmp['userid'], $groupid);
288+
$app->db->query("UPDATE client SET parent_client_id = ".$app->functions->intval($this->dataRecord['parent_client_id'])." WHERE client_id = ".$this->id);
289+
unset($tmp);
290+
}
265291
}
266292

267293
//* Set the default servers
@@ -448,7 +474,7 @@ function onAfterUpdate() {
448474
$app->db->query($sql);
449475
}
450476

451-
// reseller status changed
477+
//* reseller status changed
452478
if(isset($this->dataRecord["limit_client"]) && $this->dataRecord["limit_client"] != $this->oldDataRecord["limit_client"]) {
453479
$modules = $conf['interface_modules_enabled'];
454480
if($this->dataRecord["limit_client"] > 0) $modules .= ',client';
@@ -457,6 +483,34 @@ function onAfterUpdate() {
457483
$sql = "UPDATE sys_user SET modules = '$modules' WHERE client_id = $client_id";
458484
$app->db->query($sql);
459485
}
486+
487+
//* Client has been moved to another reseller
488+
if($_SESSION['s']['user']['typ'] == 'admin' && isset($this->dataRecord['parent_client_id']) && $this->dataRecord['parent_client_id'] != $this->oldDataRecord['parent_client_id']) {
489+
//* Get groupid of the client
490+
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".intval($this->id));
491+
$groupid = $tmp['groupid'];
492+
unset($tmp);
493+
494+
//* Remove sys_user of old reseller from client group
495+
if($this->oldDataRecord['parent_client_id'] > 0) {
496+
//* get userid of the old reseller remove it from the group of the client
497+
$tmp = $app->db->queryOneRecord("SELECT sys_user.userid FROM sys_user,sys_group WHERE sys_user.default_group = sys_group.groupid AND sys_group.client_id = ".$app->functions->intval($this->oldDataRecord['parent_client_id']));
498+
$app->auth->remove_group_from_user($tmp['userid'], $groupid);
499+
unset($tmp);
500+
}
501+
502+
//* Add sys_user of new reseller to client group
503+
if($this->dataRecord['parent_client_id'] > 0) {
504+
//* get userid of the reseller and add it to the group of the client
505+
$tmp = $app->db->queryOneRecord("SELECT sys_user.userid, sys_user.default_group FROM sys_user,sys_group WHERE sys_user.default_group = sys_group.groupid AND sys_group.client_id = ".$app->functions->intval($this->dataRecord['parent_client_id']));
506+
$app->auth->add_group_to_user($tmp['userid'], $groupid);
507+
$app->db->query("UPDATE client SET sys_userid = ".$app->functions->intval($tmp['userid']).", sys_groupid = ".$app->functions->intval($tmp['default_group']).", parent_client_id = ".$app->functions->intval($this->dataRecord['parent_client_id'])." WHERE client_id = ".$this->id);
508+
unset($tmp);
509+
} else {
510+
//* Client is not assigned to a reseller anymore, so we assign it to the admin
511+
$app->db->query("UPDATE client SET sys_userid = 1, sys_groupid = 1, parent_client_id = 0 WHERE client_id = ".$this->id);
512+
}
513+
}
460514

461515
if(isset($this->dataRecord['template_master'])) {
462516
$app->uses('client_templates');

interface/web/client/lib/lang/en_client.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,6 @@ $wb['gender_m_txt'] = 'Mr.';
154154
$wb['gender_f_txt'] = 'Ms.';
155155
$wb['added_by_txt'] = 'Added by';
156156
$wb['added_date_txt'] = 'Added date';
157+
$wb['parent_client_id_txt'] = 'Client of reseller';
158+
$wb['none_txt'] = 'none';
157159
?>

interface/web/client/templates/client_edit_limits.htm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ <h2><tmpl_var name="list_head_txt"></h2>
3737
<div class="ctrlHolder">
3838
&nbsp;
3939
</div>
40+
<tmpl_if name="is_admin">
41+
<div class="ctrlHolder">
42+
<label for="parent_client_id_id">{tmpl_var name='parent_client_id_txt'}</label>
43+
<select name="parent_client_id" id="parent_client_id" class="selectInput">
44+
{tmpl_var name='parent_client_id'}
45+
</select>
46+
</div>
47+
</tmpl_if>
4048
<div class="subsectiontoggle"><span class="showing"></span>{tmpl_var name='web_limits_txt'}<em class="showing"></em></div>
4149
<div>
4250
<div class="ctrlHolder">
@@ -313,7 +321,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
313321
.find('div.pnl_formsarea')
314322
.find('fieldset')
315323
.find('input,select,button')
316-
.not('#template_master,#template_additional,#default_mailserver,#default_webserver,#default_dbserver,#default_dnsserver,#default_slave_dnsserver,#customer_no_template,#customer_no_start,#customer_no_counter')
324+
.not('#template_master,#template_additional,#default_mailserver,#default_webserver,#default_dbserver,#default_dnsserver,#default_slave_dnsserver,#customer_no_template,#customer_no_start,#customer_no_counter,#parent_client_id')
317325
.click(function(e) {
318326
if(custom_template_selected()) return true;
319327
e.preventDefault();

0 commit comments

Comments
 (0)