From 0c702ba44e114965f8afe09dfbac126691420479 Mon Sep 17 00:00:00 2001 From: vogelor Date: Tue, 16 Dec 2008 10:15:31 +0000 Subject: [PATCH] Clients can now have client-templates (template custom coming soon) --- install/sql/ispconfig3.sql | 9 ++- interface/web/client/client_edit.php | 11 ++-- interface/web/client/client_template_del.php | 1 + interface/web/client/client_template_edit.php | 18 ++++- interface/web/client/client_template_list.php | 1 - interface/web/client/form/client.tform.php | 11 ++++ .../web/client/form/client_template.tform.php | 2 +- .../client/templates/client_edit_limits.htm | 6 ++ interface/web/client/tools.inc.php | 66 +++++++++++++++++++ 9 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 interface/web/client/tools.inc.php diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql index be62ad2db..736fb66ac 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 23e445fa4..920044034 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 c4d3e90e1..0ad174909 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 8a0705e0d..6ae45880c 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 85e3ee2b2..093de6ea3 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 b1caeaadc..c0e4571d5 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 59be8049f..71146bd2d 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 360311bee..8792e00f1 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 000000000..d98392fa4 --- /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); +} +?> -- GitLab