From 0c702ba44e114965f8afe09dfbac126691420479 Mon Sep 17 00:00:00 2001
From: vogelor <vogelor@ispconfig3>
Date: Tue, 16 Dec 2008 05:15:31 -0500
Subject: [PATCH] Clients can now have client-templates (template custom coming soon)
---
interface/web/client/client_template_list.php | 1
interface/web/client/client_edit.php | 11 ++-
install/sql/ispconfig3.sql | 9 ++
interface/web/client/templates/client_edit_limits.htm | 6 ++
interface/web/client/tools.inc.php | 66 ++++++++++++++++++++++
interface/web/client/form/client.tform.php | 11 +++
interface/web/client/client_template_del.php | 1
interface/web/client/form/client_template.tform.php | 2
interface/web/client/client_template_edit.php | 18 +++++
9 files changed, 117 insertions(+), 8 deletions(-)
diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql
index be62ad2..736fb66 100644
--- a/install/sql/ispconfig3.sql
+++ b/install/sql/ispconfig3.sql
@@ -96,6 +96,8 @@
`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 @@
`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 23e445f..9200440 100644
--- a/interface/web/client/client_edit.php
+++ b/interface/web/client/client_edit.php
@@ -40,6 +40,7 @@
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 @@
$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 @@
$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 c4d3e90..0ad1749 100644
--- a/interface/web/client/client_template_del.php
+++ b/interface/web/client/client_template_del.php
@@ -44,6 +44,7 @@
//* 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 8a0705e..6ae4588 100644
--- a/interface/web/client/client_template_edit.php
+++ b/interface/web/client/client_template_edit.php
@@ -40,10 +40,10 @@
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 @@
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 85e3ee2..093de6e 100644
--- a/interface/web/client/client_template_list.php
+++ b/interface/web/client/client_template_list.php
@@ -14,7 +14,6 @@
//* 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 b1caeaa..c0e4571 100644
--- a/interface/web/client/form/client.tform.php
+++ b/interface/web/client/form/client.tform.php
@@ -297,6 +297,17 @@
##################################
# 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 59be804..71146bd 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_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 360311b..8792e00 100644
--- a/interface/web/client/templates/client_edit_limits.htm
+++ b/interface/web/client/templates/client_edit_limits.htm
@@ -3,6 +3,12 @@
<div class="panel panel_client">
<div class="pnl_formsarea">
+ <fieldset id="wf_area_client"><legend>Client-Template</legend>
+ <span class="wf_oneField">
+ <label for="template_master" class="wf_preField">{tmpl_var name='template_master_txt'}</label>
+ <select id="template_master" name="template_master">{tmpl_var name='template_master'}</select>
+ </span>
+ </fieldset>
<fieldset id="wf_area_client"><legend>Limits</legend>
<span class="wf_oneField">
<label for="default_mailserver" class="wf_preField">{tmpl_var name='default_mailserver_txt'}</label>
diff --git a/interface/web/client/tools.inc.php b/interface/web/client/tools.inc.php
new file mode 100644
index 0000000..d98392f
--- /dev/null
+++ b/interface/web/client/tools.inc.php
@@ -0,0 +1,66 @@
+<?php
+/*
+Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of ISPConfig nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+function applyClientTemplates($clientId){
+ global $app;
+ /*
+ * Get the master-template for the client
+ */
+ $sql = "SELECT template_master FROM client WHERE client_id = " . intval($clientId);
+ $record = $app->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);
+}
+?>
--
Gitblit v1.9.1