Skip to content

Commit 0c702ba

Browse files
author
vogelor
committed
Clients can now have client-templates (template custom coming soon)
1 parent 0920f0e commit 0c702ba

File tree

9 files changed

+117
-8
lines changed

9 files changed

+117
-8
lines changed

install/sql/ispconfig3.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ CREATE TABLE `client` (
9696
`password` varchar(255) default NULL,
9797
`language` varchar(255) NOT NULL default 'en',
9898
`usertheme` varchar(255) NOT NULL default 'default',
99+
`template_master` bigint(20) NOT NULL default '0',
100+
`template_additional` varchar(255) NOT NULL default '',
99101
PRIMARY KEY (`client_id`)
100102
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
101103

@@ -132,7 +134,12 @@ CREATE TABLE `client_template` (
132134
`limit_dns_zone` int(11) NOT NULL default '-1',
133135
`limit_dns_record` int(11) NOT NULL default '-1',
134136
`limit_database` int(11) NOT NULL default '-1',
135-
`limit_client` int(11) NOT NULL default '0',
137+
`limit_client` int(11) NOT NULL default '0',
138+
`sys_userid` int(11) NOT NULL default '0',
139+
`sys_groupid` int(11) NOT NULL default '0',
140+
`sys_perm_user` varchar(5) default NULL,
141+
`sys_perm_group` varchar(5) default NULL,
142+
`sys_perm_other` varchar(5) default NULL,
136143
PRIMARY KEY (`template_id`)
137144
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
138145

interface/web/client/client_edit.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
require_once('../../lib/config.inc.php');
4242
require_once('../../lib/app.inc.php');
43+
require_once('tools.inc.php');
4344

4445
//* Check permissions for module
4546
$app->auth->check_module_permissions('client');
@@ -83,8 +84,9 @@ function onAfterInsert() {
8384
$app->auth->add_group_to_user($_SESSION['s']['user']['userid'],$groupid);
8485
$app->db->query("UPDATE client SET parent_client_id = ".intval($_SESSION['s']['user']['client_id'])." WHERE client_id = ".$this->id);
8586
}
86-
87-
87+
88+
/* If there is a client-template, process it */
89+
applyClientTemplates($this->id);
8890
}
8991

9092

@@ -122,9 +124,10 @@ function onAfterUpdate() {
122124
$sql = "UPDATE sys_user SET modules = '$modules' WHERE client_id = $client_id";
123125
$app->db->query($sql);
124126
}
127+
/*
128+
* If there is a client-template, process it */
129+
applyClientTemplates($this->id);
125130
}
126-
127-
128131
}
129132

130133
$page = new page_action;

interface/web/client/client_template_del.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
//* Check permissions for module
4646
$app->auth->check_module_permissions('client');
47+
if(!$_SESSION["s"]["user"]["typ"] == 'admin') die('Client-Templates are only for Admins.');
4748

4849
$app->uses('tpl,tform');
4950
$app->load('tform_actions');

interface/web/client/client_template_edit.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040

4141
require_once('../../lib/config.inc.php');
4242
require_once('../../lib/app.inc.php');
43+
require_once('tools.inc.php');
4344

4445
//* Check permissions for module
4546
$app->auth->check_module_permissions('client');
46-
4747
if(!$_SESSION["s"]["user"]["typ"] == 'admin') die('Client-Templates are only for Admins.');
4848

4949
// Loading classes
@@ -52,6 +52,22 @@
5252

5353
class page_action extends tform_actions {
5454

55+
/*
56+
This function is called automatically right after
57+
the data was successful updated in the database.
58+
*/
59+
function onAfterUpdate() {
60+
global $app;
61+
62+
/*
63+
* the template has changed. apply the new data to all clients
64+
*/
65+
$sql = "SELECT client_id FROM client WHERE template_master = " . $this->id;
66+
$clients = $app->db->queryAllRecords($sql);
67+
foreach ($clients as $client){
68+
applyClientTemplates($client['client_id']);
69+
}
70+
}
5571
}
5672

5773
$page = new page_action;

interface/web/client/client_template_list.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
//* Check permissions for module
1616
$app->auth->check_module_permissions('client');
17-
1817
if(!$_SESSION["s"]["user"]["typ"] == 'admin') die('Client-Templates are only for Admins.');
1918

2019
$app->uses('listform_actions');

interface/web/client/form/client.tform.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@
297297
##################################
298298
# Begin Datatable fields
299299
##################################
300+
'template_master' => array (
301+
'datatype' => 'INTEGER',
302+
'formtype' => 'SELECT',
303+
'default' => '1',
304+
'datasource' => array ( 'type' => 'SQL',
305+
'querystring' => "SELECT template_id,template_name FROM client_template WHERE template_type ='m'",
306+
'keyfield'=> 'template_id',
307+
'valuefield'=> 'template_name'
308+
),
309+
'value' => array('0' => 'custom')
310+
),
300311
'default_mailserver' => array (
301312
'datatype' => 'INTEGER',
302313
'formtype' => 'SELECT',

interface/web/client/form/client_template.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
$form["db_history"] = "no";
4343
$form["tab_default"] = "template";
4444
$form["list_default"] = "client_template_list.php";
45-
$form["auth"] = 'no';
45+
$form["auth"] = 'yes';
4646

4747
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
4848
$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user

interface/web/client/templates/client_edit_limits.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ <h2><tmpl_var name="list_head_txt"></h2>
33
<div class="panel panel_client">
44

55
<div class="pnl_formsarea">
6+
<fieldset id="wf_area_client"><legend>Client-Template</legend>
7+
<span class="wf_oneField">
8+
<label for="template_master" class="wf_preField">{tmpl_var name='template_master_txt'}</label>
9+
<select id="template_master" name="template_master">{tmpl_var name='template_master'}</select>
10+
</span>
11+
</fieldset>
612
<fieldset id="wf_area_client"><legend>Limits</legend>
713
<span class="wf_oneField">
814
<label for="default_mailserver" class="wf_preField">{tmpl_var name='default_mailserver_txt'}</label>

interface/web/client/tools.inc.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/*
3+
Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
* Neither the name of ISPConfig nor the names of its contributors
15+
may be used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
function applyClientTemplates($clientId){
31+
global $app;
32+
/*
33+
* Get the master-template for the client
34+
*/
35+
$sql = "SELECT template_master FROM client WHERE client_id = " . intval($clientId);
36+
$record = $app->db->queryOneRecord($sql);
37+
$masterTemplateId = $record['template_master'];
38+
39+
/*
40+
* if the master-Template is custom there is NO changing
41+
*/
42+
if ($masterTemplateId > 0){
43+
$sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId);
44+
$limits = $app->db->queryOneRecord($sql);
45+
}
46+
47+
/*
48+
* TODO: Process the additional tempaltes here (add them to the limits
49+
* if != -1)
50+
* (like $limits['limit_database'] += $limitAdditional)
51+
*/
52+
53+
/*
54+
* Write all back to the database
55+
*/
56+
$update = '';
57+
foreach($limits as $k => $v){
58+
if (strpos($k, 'limit') !== false){
59+
if ($update != '') $update .= ', ';
60+
$update .= '`' . $k . "`='" . $v . "'";
61+
}
62+
}
63+
$sql = 'UPDATE client SET ' . $update . " WHERE client_id = " . intval($clientId);
64+
$app->db->query($sql);
65+
}
66+
?>

0 commit comments

Comments
 (0)