diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql index be62ad2db3e5515cf715b388be34f46dbcef0a90..736fb66ac8c201313dee190cf270a462c0e08b35 100644 --- a/install/sql/ispconfig3.sql +++ b/install/sql/ispconfig3.sql @@ -96,6 +96,8 @@ CREATE TABLE `client` ( `password` varchar(255) default NULL, `language` varchar(255) NOT NULL default 'en', `usertheme` varchar(255) NOT NULL default 'default', + `template_master` bigint(20) NOT NULL default '0', + `template_additional` varchar(255) NOT NULL default '', PRIMARY KEY (`client_id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 ; @@ -132,7 +134,12 @@ CREATE TABLE `client_template` ( `limit_dns_zone` int(11) NOT NULL default '-1', `limit_dns_record` int(11) NOT NULL default '-1', `limit_database` int(11) NOT NULL default '-1', - `limit_client` int(11) NOT NULL default '0', + `limit_client` int(11) NOT NULL default '0', + `sys_userid` int(11) NOT NULL default '0', + `sys_groupid` int(11) NOT NULL default '0', + `sys_perm_user` varchar(5) default NULL, + `sys_perm_group` varchar(5) default NULL, + `sys_perm_other` varchar(5) default NULL, PRIMARY KEY (`template_id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 ; diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php index 23e445fa4b91cfd85c557357cbba8fd4db2afce0..9200440348f5478668a9c54affefdd1882319caf 100644 --- a/interface/web/client/client_edit.php +++ b/interface/web/client/client_edit.php @@ -40,6 +40,7 @@ $tform_def_file = "form/client.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); +require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('client'); @@ -83,8 +84,9 @@ class page_action extends tform_actions { $app->auth->add_group_to_user($_SESSION['s']['user']['userid'],$groupid); $app->db->query("UPDATE client SET parent_client_id = ".intval($_SESSION['s']['user']['client_id'])." WHERE client_id = ".$this->id); } - - + + /* If there is a client-template, process it */ + applyClientTemplates($this->id); } @@ -122,9 +124,10 @@ class page_action extends tform_actions { $sql = "UPDATE sys_user SET modules = '$modules' WHERE client_id = $client_id"; $app->db->query($sql); } + /* + * If there is a client-template, process it */ + applyClientTemplates($this->id); } - - } $page = new page_action; diff --git a/interface/web/client/client_template_del.php b/interface/web/client/client_template_del.php index c4d3e90e1e950468e779207180d9f9dce29f81f1..0ad174909328be33d0ef34a647c49300690ca955 100644 --- a/interface/web/client/client_template_del.php +++ b/interface/web/client/client_template_del.php @@ -44,6 +44,7 @@ require_once('../../lib/app.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('client'); +if(!$_SESSION["s"]["user"]["typ"] == 'admin') die('Client-Templates are only for Admins.'); $app->uses('tpl,tform'); $app->load('tform_actions'); diff --git a/interface/web/client/client_template_edit.php b/interface/web/client/client_template_edit.php index 8a0705e0d6abe5e66d6c818d37502a71b2eac2d8..6ae45880c3f97c0cc94b7fdc3a4d84e091b85dbb 100644 --- a/interface/web/client/client_template_edit.php +++ b/interface/web/client/client_template_edit.php @@ -40,10 +40,10 @@ $tform_def_file = "form/client_template.tform.php"; require_once('../../lib/config.inc.php'); require_once('../../lib/app.inc.php'); +require_once('tools.inc.php'); //* Check permissions for module $app->auth->check_module_permissions('client'); - if(!$_SESSION["s"]["user"]["typ"] == 'admin') die('Client-Templates are only for Admins.'); // Loading classes @@ -52,6 +52,22 @@ $app->load('tform_actions'); class page_action extends tform_actions { + /* + This function is called automatically right after + the data was successful updated in the database. + */ + function onAfterUpdate() { + global $app; + + /* + * the template has changed. apply the new data to all clients + */ + $sql = "SELECT client_id FROM client WHERE template_master = " . $this->id; + $clients = $app->db->queryAllRecords($sql); + foreach ($clients as $client){ + applyClientTemplates($client['client_id']); + } + } } $page = new page_action; diff --git a/interface/web/client/client_template_list.php b/interface/web/client/client_template_list.php index 85e3ee2b2f22666720fbcf7b937b40321279ad23..093de6ea3e0a21ef01278fede6c4447334c81873 100644 --- a/interface/web/client/client_template_list.php +++ b/interface/web/client/client_template_list.php @@ -14,7 +14,6 @@ $list_def_file = "list/client_template.list.php"; //* Check permissions for module $app->auth->check_module_permissions('client'); - if(!$_SESSION["s"]["user"]["typ"] == 'admin') die('Client-Templates are only for Admins.'); $app->uses('listform_actions'); diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php index b1caeaadce7044aeca500bd3c03062d62433cf80..c0e4571d55cbb5ecd3158d9dca5c8e1c509186d2 100644 --- a/interface/web/client/form/client.tform.php +++ b/interface/web/client/form/client.tform.php @@ -297,6 +297,17 @@ $form["tabs"]['limits'] = array ( ################################## # Begin Datatable fields ################################## + 'template_master' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '1', + 'datasource' => array ( 'type' => 'SQL', + 'querystring' => "SELECT template_id,template_name FROM client_template WHERE template_type ='m'", + 'keyfield'=> 'template_id', + 'valuefield'=> 'template_name' + ), + 'value' => array('0' => 'custom') + ), 'default_mailserver' => array ( 'datatype' => 'INTEGER', 'formtype' => 'SELECT', diff --git a/interface/web/client/form/client_template.tform.php b/interface/web/client/form/client_template.tform.php index 59be8049f6f2c4008d194dd99d64f38b069f0deb..71146bd2d79a5074945c1b1554f721ef1f4cb327 100644 --- a/interface/web/client/form/client_template.tform.php +++ b/interface/web/client/form/client_template.tform.php @@ -42,7 +42,7 @@ $form["db_table_idx"] = "template_id"; $form["db_history"] = "no"; $form["tab_default"] = "template"; $form["list_default"] = "client_template_list.php"; -$form["auth"] = 'no'; +$form["auth"] = 'yes'; $form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user $form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user diff --git a/interface/web/client/templates/client_edit_limits.htm b/interface/web/client/templates/client_edit_limits.htm index 360311bee9f1367c0542eefeebf470cb2fdbf1ae..8792e00f1de84903ee4658d17938b63715d576b7 100644 --- a/interface/web/client/templates/client_edit_limits.htm +++ b/interface/web/client/templates/client_edit_limits.htm @@ -3,6 +3,12 @@
+
Client-Template + + + + +
Limits diff --git a/interface/web/client/tools.inc.php b/interface/web/client/tools.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..d98392fa45f9b7904a960c3223dab497f45f803b --- /dev/null +++ b/interface/web/client/tools.inc.php @@ -0,0 +1,66 @@ +db->queryOneRecord($sql); + $masterTemplateId = $record['template_master']; + + /* + * if the master-Template is custom there is NO changing + */ + if ($masterTemplateId > 0){ + $sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId); + $limits = $app->db->queryOneRecord($sql); + } + + /* + * TODO: Process the additional tempaltes here (add them to the limits + * if != -1) + * (like $limits['limit_database'] += $limitAdditional) + */ + + /* + * Write all back to the database + */ + $update = ''; + foreach($limits as $k => $v){ + if (strpos($k, 'limit') !== false){ + if ($update != '') $update .= ', '; + $update .= '`' . $k . "`='" . $v . "'"; + } + } + $sql = 'UPDATE client SET ' . $update . " WHERE client_id = " . intval($clientId); + $app->db->query($sql); +} +?>