From 12ae7f4b1e0544a02a299ec5ef7ac998c8c800d0 Mon Sep 17 00:00:00 2001
From: vogelor <vogelor@ispconfig3>
Date: Tue, 16 Dec 2008 10:47:28 -0500
Subject: [PATCH] It is now possible to add additional templates to the client (and delete them)
---
interface/web/client/client_edit.php | 38 ++++++++++++
interface/web/client/templates/client_edit_limits.htm | 11 +++
interface/web/client/tools.inc.php | 28 ++++++++-
interface/web/client/form/client.tform.php | 4 +
interface/web/themes/default/css/screen/content_ispc.css | 1
interface/web/client/form/client_template.tform.php | 38 ++++++------
interface/web/client/client_template_edit.php | 12 +++-
interface/web/js/scrigo.js.php | 32 ++++++++++
8 files changed, 138 insertions(+), 26 deletions(-)
diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php
index 9200440..a35b663 100644
--- a/interface/web/client/client_edit.php
+++ b/interface/web/client/client_edit.php
@@ -50,7 +50,39 @@
$app->load('tform_actions');
class page_action extends tform_actions {
-
+
+
+ function onShowEnd() {
+
+ global $app;
+
+ $sql = "SELECT template_id,template_name FROM client_template WHERE template_type = 'a'";
+ $tpls = $app->db->queryAllRecords($sql);
+ $option = '';
+ $tpl = array();
+ foreach($tpls as $item){
+ $option .= '<option value="' . $item['template_id'] . '|' . $item['template_name'] . '">' . $item['template_name'] . '</option>';
+ $tpl[$item['template_id']] = $item['template_name'];
+ }
+ $app->tpl->setVar('tpl_add_select',$option);
+
+ $sql = "SELECT template_additional FROM client WHERE client_id = " . $this->id;
+ $result = $app->db->queryOneRecord($sql);
+ $tplAdd = explode("/", $result['template_additional']);
+ $text = '';
+ foreach($tplAdd as $item){
+ if (trim($item) != ''){
+ if ($text != '') $text .= '<br>';
+ $text .= $tpl[$item];
+ }
+ }
+
+ $app->tpl->setVar('template_additional_list', $text);
+
+ parent::onShowEnd();
+
+ }
+
/*
This function is called automatically right after
the data was successful inserted in the database.
@@ -87,6 +119,8 @@
/* If there is a client-template, process it */
applyClientTemplates($this->id);
+
+ parent::onAfterInsert();
}
@@ -127,6 +161,8 @@
/*
* If there is a client-template, process it */
applyClientTemplates($this->id);
+
+ parent::onAfterUpdate();
}
}
diff --git a/interface/web/client/client_template_edit.php b/interface/web/client/client_template_edit.php
index 6ae4588..7368063 100644
--- a/interface/web/client/client_template_edit.php
+++ b/interface/web/client/client_template_edit.php
@@ -62,10 +62,16 @@
/*
* the template has changed. apply the new data to all clients
*/
- $sql = "SELECT client_id FROM client WHERE template_master = " . $this->id;
+ if ($this->dataRecord["template_type"] == 'm'){
+ $sql = "SELECT client_id FROM client WHERE template_master = " . $this->id;
+ } else {
+ $sql = "SELECT client_id FROM client WHERE template_additional LIKE '%/" . $this->id . '/%"';
+ }
$clients = $app->db->queryAllRecords($sql);
- foreach ($clients as $client){
- applyClientTemplates($client['client_id']);
+ if (is_array($clients)){
+ foreach ($clients as $client){
+ applyClientTemplates($client['client_id']);
+ }
}
}
}
diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php
index c0e4571..8be3de8 100644
--- a/interface/web/client/form/client.tform.php
+++ b/interface/web/client/form/client.tform.php
@@ -308,6 +308,10 @@
),
'value' => array('0' => 'custom')
),
+ 'template_additional' => array (
+ 'datatype' => 'VARCHAR',
+ 'formtype' => 'TEXT',
+ ),
'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 71146bd..f732faf 100644
--- a/interface/web/client/form/client_template.tform.php
+++ b/interface/web/client/form/client_template.tform.php
@@ -107,7 +107,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_maildomain_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -121,7 +121,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_mailbox_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -135,7 +135,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_mailalias_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -149,7 +149,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_mailforward_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -163,7 +163,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_mailcatchall_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -191,7 +191,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_mailfilter_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -205,7 +205,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_mailfetchmail_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -219,7 +219,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_mailquota_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -233,7 +233,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_spamfilter_wblist_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -247,7 +247,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_spamfilter_user_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -261,7 +261,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_spamfilter_policy_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -275,7 +275,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_web_domain_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -289,7 +289,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_web_aliasdomain_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -303,7 +303,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_web_subdomain_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -317,7 +317,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_ftp_user_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -331,7 +331,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_shell_user_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -345,7 +345,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_dns_zone_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -359,7 +359,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_dns_record_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
@@ -387,7 +387,7 @@
'validators' => array ( 0 => array ( 'type' => 'ISINT',
'errmsg'=> 'limit_database_error_notint'),
),
- 'default' => '-1',
+ 'default' => '0',
'value' => '',
'separator' => '',
'width' => '10',
diff --git a/interface/web/client/templates/client_edit_limits.htm b/interface/web/client/templates/client_edit_limits.htm
index 8792e00..5e4232b 100644
--- a/interface/web/client/templates/client_edit_limits.htm
+++ b/interface/web/client/templates/client_edit_limits.htm
@@ -9,6 +9,17 @@
<select id="template_master" name="template_master">{tmpl_var name='template_master'}</select>
</span>
</fieldset>
+ <fieldset id="wf_area_client"><legend>Additional-Templates</legend>
+ <span class="wf_oneField">
+ <select id="tpl_add_select" name="tpl_add_select">{tmpl_var name='tpl_add_select'}</select>
+ </span>
+ <span id="template_additional_list">{tmpl_var name='template_additional_list'}</span>
+ <input type="hidden" id="template_additional" name="template_additional" value="{tmpl_var name='template_additional'}">
+ <div class="wf_actions buttons">
+ <button class="positive iconstxt icoAdd" type="button" value="Add additional template" onClick="addAdditionalTemplate();"><span>Add additional template</span></button>
+ <button class="negative iconstxt icoDelete" type="button" value="Delete additional template" onClick="delAdditionalTemplate();"><span>Delete additional template</span></button>
+ </div>
+ </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
index d98392f..9cbf8eb 100644
--- a/interface/web/client/tools.inc.php
+++ b/interface/web/client/tools.inc.php
@@ -32,9 +32,10 @@
/*
* Get the master-template for the client
*/
- $sql = "SELECT template_master FROM client WHERE client_id = " . intval($clientId);
+ $sql = "SELECT template_master, template_additional FROM client WHERE client_id = " . intval($clientId);
$record = $app->db->queryOneRecord($sql);
$masterTemplateId = $record['template_master'];
+ $additionalTemplateStr = $record['template_additional'];
/*
* if the master-Template is custom there is NO changing
@@ -42,13 +43,34 @@
if ($masterTemplateId > 0){
$sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId);
$limits = $app->db->queryOneRecord($sql);
+ } else {
+ $limits = $this->dataRecord;
}
/*
- * TODO: Process the additional tempaltes here (add them to the limits
+ * Process the additional tempaltes here (add them to the limits
* if != -1)
- * (like $limits['limit_database'] += $limitAdditional)
*/
+ $addTpl = explode('/', $additionalTemplateStr);
+ foreach ($addTpl as $item){
+ if (trim($item) != ''){
+ $sql = "SELECT * FROM client_template WHERE template_id = " . intval($item);
+ $addLimits = $app->db->queryOneRecord($sql);
+ /* maybe the template is deleted in the meantime */
+ if (is_array($addLimits)){
+ foreach($addLimits as $k => $v){
+ if ($limits[$k] > -1){
+ if ($v == -1) {
+ $limits[$k] = -1;
+ }
+ else {
+ $limits[$k] += $v;
+ }
+ }
+ }
+ }
+ }
+ }
/*
* Write all back to the database
diff --git a/interface/web/js/scrigo.js.php b/interface/web/js/scrigo.js.php
index 519f767..8831141 100644
--- a/interface/web/js/scrigo.js.php
+++ b/interface/web/js/scrigo.js.php
@@ -408,3 +408,35 @@
}
return false;
}
+
+function addAdditionalTemplate(){
+ var tpl_add = document.getElementById('template_additional').value;
+ var tpl_list = document.getElementById('template_additional_list').innerHTML;
+ var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
+ var addTplId = addTemplate[0];
+ var addTplText = addTemplate[1];
+ var newVal = tpl_add + '/' + addTplId + '/';
+ newVal = newVal.replace('//', '/');
+ var newList = tpl_list + '<br>' + addTplText;
+ newList = newList.replace('<br><br>', '<br>');
+ document.getElementById('template_additional').value = newVal;
+ document.getElementById('template_additional_list').innerHTML = newList;
+ alert('additional template ' + addTplText + ' added to customer');
+}
+
+function delAdditionalTemplate(){
+ var tpl_add = document.getElementById('template_additional').value;
+ var tpl_list = document.getElementById('template_additional_list').innerHTML;
+ var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
+ var addTplId = addTemplate[0];
+ var addTplText = addTemplate[1];
+ var newVal = tpl_add;
+ newVal = newVal.replace(addTplId, '');
+ newVal = newVal.replace('//', '/');
+ var newList = tpl_list.replace(addTplText, '');
+ newList = newList.replace('<br><br>', '<br>');
+ document.getElementById('template_additional').value = newVal;
+ document.getElementById('template_additional_list').innerHTML = newList;
+ alert('additional template ' + addTplText + ' deleted from customer');
+}
+
diff --git a/interface/web/themes/default/css/screen/content_ispc.css b/interface/web/themes/default/css/screen/content_ispc.css
index 2936f56..b07974e 100644
--- a/interface/web/themes/default/css/screen/content_ispc.css
+++ b/interface/web/themes/default/css/screen/content_ispc.css
@@ -287,6 +287,7 @@
.iconstxt.icoNegative { background-image: url("../../icons/x16/cross_circle_frame.png"); }
.iconstxt.icoAdd { background-image: url(../../icons/x16/plus_circle_frame.png); }
.iconstxt.icoKey { background-image: url("../../icons/x16/key.png"); }
+ .iconstxt.icoDelete { background-image: url("../../icons/x16/minus_circle_frame.png"); }
/* Button with icon and without text */
.icons16 span { display: none; }
--
Gitblit v1.9.1