Commit 0c702ba4 authored by vogelor's avatar vogelor

Clients can now have client-templates (template custom coming soon)

parent 0920f0e7
......@@ -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 ;
......
......@@ -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;
......
......@@ -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');
......
......@@ -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;
......
......@@ -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');
......
......@@ -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',
......
......@@ -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
......
......@@ -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>
......
<?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);
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment