From 12ae7f4b1e0544a02a299ec5ef7ac998c8c800d0 Mon Sep 17 00:00:00 2001 From: vogelor Date: Tue, 16 Dec 2008 15:47:28 +0000 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/client_template_edit.php | 12 ++++-- interface/web/client/form/client.tform.php | 4 ++ .../web/client/form/client_template.tform.php | 38 +++++++++---------- .../client/templates/client_edit_limits.htm | 11 ++++++ interface/web/client/tools.inc.php | 28 ++++++++++++-- interface/web/js/scrigo.js.php | 32 ++++++++++++++++ .../default/css/screen/content_ispc.css | 1 + 8 files changed, 138 insertions(+), 26 deletions(-) diff --git a/interface/web/client/client_edit.php b/interface/web/client/client_edit.php index 920044034..a35b6639a 100644 --- a/interface/web/client/client_edit.php +++ b/interface/web/client/client_edit.php @@ -50,7 +50,39 @@ $app->uses('tpl,tform,tform_actions'); $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 .= ''; + $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 .= '
'; + $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 @@ class page_action extends tform_actions { /* If there is a client-template, process it */ applyClientTemplates($this->id); + + parent::onAfterInsert(); } @@ -127,6 +161,8 @@ class page_action extends tform_actions { /* * 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 6ae45880c..7368063ec 100644 --- a/interface/web/client/client_template_edit.php +++ b/interface/web/client/client_template_edit.php @@ -62,10 +62,16 @@ class page_action extends tform_actions { /* * 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 c0e4571d5..8be3de8a2 100644 --- a/interface/web/client/form/client.tform.php +++ b/interface/web/client/form/client.tform.php @@ -308,6 +308,10 @@ $form["tabs"]['limits'] = array ( ), '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 71146bd2d..f732faf57 100644 --- a/interface/web/client/form/client_template.tform.php +++ b/interface/web/client/form/client_template.tform.php @@ -107,7 +107,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_maildomain_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -121,7 +121,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_mailbox_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -135,7 +135,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_mailalias_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -149,7 +149,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_mailforward_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -163,7 +163,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_mailcatchall_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -191,7 +191,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_mailfilter_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -205,7 +205,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_mailfetchmail_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -219,7 +219,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_mailquota_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -233,7 +233,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_spamfilter_wblist_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -247,7 +247,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_spamfilter_user_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -261,7 +261,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_spamfilter_policy_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -275,7 +275,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_web_domain_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -289,7 +289,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_web_aliasdomain_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -303,7 +303,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_web_subdomain_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -317,7 +317,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_ftp_user_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -331,7 +331,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_shell_user_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -345,7 +345,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_dns_zone_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -359,7 +359,7 @@ $form["tabs"]['limits'] = array ( 'validators' => array ( 0 => array ( 'type' => 'ISINT', 'errmsg'=> 'limit_dns_record_error_notint'), ), - 'default' => '-1', + 'default' => '0', 'value' => '', 'separator' => '', 'width' => '10', @@ -387,7 +387,7 @@ $form["tabs"]['limits'] = array ( '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 8792e00f1..5e4232b9a 100644 --- a/interface/web/client/templates/client_edit_limits.htm +++ b/interface/web/client/templates/client_edit_limits.htm @@ -9,6 +9,17 @@ +
Additional-Templates + + + + {tmpl_var name='template_additional_list'} + +
+ + +
+
Limits diff --git a/interface/web/client/tools.inc.php b/interface/web/client/tools.inc.php index d98392fa4..9cbf8eb1d 100644 --- a/interface/web/client/tools.inc.php +++ b/interface/web/client/tools.inc.php @@ -32,9 +32,10 @@ function applyClientTemplates($clientId){ /* * 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 @@ function applyClientTemplates($clientId){ 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 519f767e0..8831141ea 100644 --- a/interface/web/js/scrigo.js.php +++ b/interface/web/js/scrigo.js.php @@ -408,3 +408,35 @@ function pass_contains(pass, check) { } 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 + '
' + addTplText; + newList = newList.replace('

', '
'); + 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('

', '
'); + 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 2936f56e2..b07974e91 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; } -- GitLab