Skip to content

Commit 12ae7f4

Browse files
author
vogelor
committed
It is now possible to add additional templates to the client (and delete them)
1 parent 88a927c commit 12ae7f4

File tree

8 files changed

+138
-26
lines changed

8 files changed

+138
-26
lines changed

interface/web/client/client_edit.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,39 @@
5050
$app->load('tform_actions');
5151

5252
class page_action extends tform_actions {
53-
53+
54+
55+
function onShowEnd() {
56+
57+
global $app;
58+
59+
$sql = "SELECT template_id,template_name FROM client_template WHERE template_type = 'a'";
60+
$tpls = $app->db->queryAllRecords($sql);
61+
$option = '';
62+
$tpl = array();
63+
foreach($tpls as $item){
64+
$option .= '<option value="' . $item['template_id'] . '|' . $item['template_name'] . '">' . $item['template_name'] . '</option>';
65+
$tpl[$item['template_id']] = $item['template_name'];
66+
}
67+
$app->tpl->setVar('tpl_add_select',$option);
68+
69+
$sql = "SELECT template_additional FROM client WHERE client_id = " . $this->id;
70+
$result = $app->db->queryOneRecord($sql);
71+
$tplAdd = explode("/", $result['template_additional']);
72+
$text = '';
73+
foreach($tplAdd as $item){
74+
if (trim($item) != ''){
75+
if ($text != '') $text .= '<br>';
76+
$text .= $tpl[$item];
77+
}
78+
}
79+
80+
$app->tpl->setVar('template_additional_list', $text);
81+
82+
parent::onShowEnd();
83+
84+
}
85+
5486
/*
5587
This function is called automatically right after
5688
the data was successful inserted in the database.
@@ -87,6 +119,8 @@ function onAfterInsert() {
87119

88120
/* If there is a client-template, process it */
89121
applyClientTemplates($this->id);
122+
123+
parent::onAfterInsert();
90124
}
91125

92126

@@ -127,6 +161,8 @@ function onAfterUpdate() {
127161
/*
128162
* If there is a client-template, process it */
129163
applyClientTemplates($this->id);
164+
165+
parent::onAfterUpdate();
130166
}
131167
}
132168

interface/web/client/client_template_edit.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ function onAfterUpdate() {
6262
/*
6363
* the template has changed. apply the new data to all clients
6464
*/
65-
$sql = "SELECT client_id FROM client WHERE template_master = " . $this->id;
65+
if ($this->dataRecord["template_type"] == 'm'){
66+
$sql = "SELECT client_id FROM client WHERE template_master = " . $this->id;
67+
} else {
68+
$sql = "SELECT client_id FROM client WHERE template_additional LIKE '%/" . $this->id . '/%"';
69+
}
6670
$clients = $app->db->queryAllRecords($sql);
67-
foreach ($clients as $client){
68-
applyClientTemplates($client['client_id']);
71+
if (is_array($clients)){
72+
foreach ($clients as $client){
73+
applyClientTemplates($client['client_id']);
74+
}
6975
}
7076
}
7177
}

interface/web/client/form/client.tform.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@
308308
),
309309
'value' => array('0' => 'custom')
310310
),
311+
'template_additional' => array (
312+
'datatype' => 'VARCHAR',
313+
'formtype' => 'TEXT',
314+
),
311315
'default_mailserver' => array (
312316
'datatype' => 'INTEGER',
313317
'formtype' => 'SELECT',

interface/web/client/form/client_template.tform.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
'validators' => array ( 0 => array ( 'type' => 'ISINT',
108108
'errmsg'=> 'limit_maildomain_error_notint'),
109109
),
110-
'default' => '-1',
110+
'default' => '0',
111111
'value' => '',
112112
'separator' => '',
113113
'width' => '10',
@@ -121,7 +121,7 @@
121121
'validators' => array ( 0 => array ( 'type' => 'ISINT',
122122
'errmsg'=> 'limit_mailbox_error_notint'),
123123
),
124-
'default' => '-1',
124+
'default' => '0',
125125
'value' => '',
126126
'separator' => '',
127127
'width' => '10',
@@ -135,7 +135,7 @@
135135
'validators' => array ( 0 => array ( 'type' => 'ISINT',
136136
'errmsg'=> 'limit_mailalias_error_notint'),
137137
),
138-
'default' => '-1',
138+
'default' => '0',
139139
'value' => '',
140140
'separator' => '',
141141
'width' => '10',
@@ -149,7 +149,7 @@
149149
'validators' => array ( 0 => array ( 'type' => 'ISINT',
150150
'errmsg'=> 'limit_mailforward_error_notint'),
151151
),
152-
'default' => '-1',
152+
'default' => '0',
153153
'value' => '',
154154
'separator' => '',
155155
'width' => '10',
@@ -163,7 +163,7 @@
163163
'validators' => array ( 0 => array ( 'type' => 'ISINT',
164164
'errmsg'=> 'limit_mailcatchall_error_notint'),
165165
),
166-
'default' => '-1',
166+
'default' => '0',
167167
'value' => '',
168168
'separator' => '',
169169
'width' => '10',
@@ -191,7 +191,7 @@
191191
'validators' => array ( 0 => array ( 'type' => 'ISINT',
192192
'errmsg'=> 'limit_mailfilter_error_notint'),
193193
),
194-
'default' => '-1',
194+
'default' => '0',
195195
'value' => '',
196196
'separator' => '',
197197
'width' => '10',
@@ -205,7 +205,7 @@
205205
'validators' => array ( 0 => array ( 'type' => 'ISINT',
206206
'errmsg'=> 'limit_mailfetchmail_error_notint'),
207207
),
208-
'default' => '-1',
208+
'default' => '0',
209209
'value' => '',
210210
'separator' => '',
211211
'width' => '10',
@@ -219,7 +219,7 @@
219219
'validators' => array ( 0 => array ( 'type' => 'ISINT',
220220
'errmsg'=> 'limit_mailquota_error_notint'),
221221
),
222-
'default' => '-1',
222+
'default' => '0',
223223
'value' => '',
224224
'separator' => '',
225225
'width' => '10',
@@ -233,7 +233,7 @@
233233
'validators' => array ( 0 => array ( 'type' => 'ISINT',
234234
'errmsg'=> 'limit_spamfilter_wblist_error_notint'),
235235
),
236-
'default' => '-1',
236+
'default' => '0',
237237
'value' => '',
238238
'separator' => '',
239239
'width' => '10',
@@ -247,7 +247,7 @@
247247
'validators' => array ( 0 => array ( 'type' => 'ISINT',
248248
'errmsg'=> 'limit_spamfilter_user_error_notint'),
249249
),
250-
'default' => '-1',
250+
'default' => '0',
251251
'value' => '',
252252
'separator' => '',
253253
'width' => '10',
@@ -261,7 +261,7 @@
261261
'validators' => array ( 0 => array ( 'type' => 'ISINT',
262262
'errmsg'=> 'limit_spamfilter_policy_error_notint'),
263263
),
264-
'default' => '-1',
264+
'default' => '0',
265265
'value' => '',
266266
'separator' => '',
267267
'width' => '10',
@@ -275,7 +275,7 @@
275275
'validators' => array ( 0 => array ( 'type' => 'ISINT',
276276
'errmsg'=> 'limit_web_domain_error_notint'),
277277
),
278-
'default' => '-1',
278+
'default' => '0',
279279
'value' => '',
280280
'separator' => '',
281281
'width' => '10',
@@ -289,7 +289,7 @@
289289
'validators' => array ( 0 => array ( 'type' => 'ISINT',
290290
'errmsg'=> 'limit_web_aliasdomain_error_notint'),
291291
),
292-
'default' => '-1',
292+
'default' => '0',
293293
'value' => '',
294294
'separator' => '',
295295
'width' => '10',
@@ -303,7 +303,7 @@
303303
'validators' => array ( 0 => array ( 'type' => 'ISINT',
304304
'errmsg'=> 'limit_web_subdomain_error_notint'),
305305
),
306-
'default' => '-1',
306+
'default' => '0',
307307
'value' => '',
308308
'separator' => '',
309309
'width' => '10',
@@ -317,7 +317,7 @@
317317
'validators' => array ( 0 => array ( 'type' => 'ISINT',
318318
'errmsg'=> 'limit_ftp_user_error_notint'),
319319
),
320-
'default' => '-1',
320+
'default' => '0',
321321
'value' => '',
322322
'separator' => '',
323323
'width' => '10',
@@ -331,7 +331,7 @@
331331
'validators' => array ( 0 => array ( 'type' => 'ISINT',
332332
'errmsg'=> 'limit_shell_user_error_notint'),
333333
),
334-
'default' => '-1',
334+
'default' => '0',
335335
'value' => '',
336336
'separator' => '',
337337
'width' => '10',
@@ -345,7 +345,7 @@
345345
'validators' => array ( 0 => array ( 'type' => 'ISINT',
346346
'errmsg'=> 'limit_dns_zone_error_notint'),
347347
),
348-
'default' => '-1',
348+
'default' => '0',
349349
'value' => '',
350350
'separator' => '',
351351
'width' => '10',
@@ -359,7 +359,7 @@
359359
'validators' => array ( 0 => array ( 'type' => 'ISINT',
360360
'errmsg'=> 'limit_dns_record_error_notint'),
361361
),
362-
'default' => '-1',
362+
'default' => '0',
363363
'value' => '',
364364
'separator' => '',
365365
'width' => '10',
@@ -387,7 +387,7 @@
387387
'validators' => array ( 0 => array ( 'type' => 'ISINT',
388388
'errmsg'=> 'limit_database_error_notint'),
389389
),
390-
'default' => '-1',
390+
'default' => '0',
391391
'value' => '',
392392
'separator' => '',
393393
'width' => '10',

interface/web/client/templates/client_edit_limits.htm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ <h2><tmpl_var name="list_head_txt"></h2>
99
<select id="template_master" name="template_master">{tmpl_var name='template_master'}</select>
1010
</span>
1111
</fieldset>
12+
<fieldset id="wf_area_client"><legend>Additional-Templates</legend>
13+
<span class="wf_oneField">
14+
<select id="tpl_add_select" name="tpl_add_select">{tmpl_var name='tpl_add_select'}</select>
15+
</span>
16+
<span id="template_additional_list">{tmpl_var name='template_additional_list'}</span>
17+
<input type="hidden" id="template_additional" name="template_additional" value="{tmpl_var name='template_additional'}">
18+
<div class="wf_actions buttons">
19+
<button class="positive iconstxt icoAdd" type="button" value="Add additional template" onClick="addAdditionalTemplate();"><span>Add additional template</span></button>
20+
<button class="negative iconstxt icoDelete" type="button" value="Delete additional template" onClick="delAdditionalTemplate();"><span>Delete additional template</span></button>
21+
</div>
22+
</fieldset>
1223
<fieldset id="wf_area_client"><legend>Limits</legend>
1324
<span class="wf_oneField">
1425
<label for="default_mailserver" class="wf_preField">{tmpl_var name='default_mailserver_txt'}</label>

interface/web/client/tools.inc.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,45 @@ function applyClientTemplates($clientId){
3232
/*
3333
* Get the master-template for the client
3434
*/
35-
$sql = "SELECT template_master FROM client WHERE client_id = " . intval($clientId);
35+
$sql = "SELECT template_master, template_additional FROM client WHERE client_id = " . intval($clientId);
3636
$record = $app->db->queryOneRecord($sql);
3737
$masterTemplateId = $record['template_master'];
38+
$additionalTemplateStr = $record['template_additional'];
3839

3940
/*
4041
* if the master-Template is custom there is NO changing
4142
*/
4243
if ($masterTemplateId > 0){
4344
$sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId);
4445
$limits = $app->db->queryOneRecord($sql);
46+
} else {
47+
$limits = $this->dataRecord;
4548
}
4649

4750
/*
48-
* TODO: Process the additional tempaltes here (add them to the limits
51+
* Process the additional tempaltes here (add them to the limits
4952
* if != -1)
50-
* (like $limits['limit_database'] += $limitAdditional)
5153
*/
54+
$addTpl = explode('/', $additionalTemplateStr);
55+
foreach ($addTpl as $item){
56+
if (trim($item) != ''){
57+
$sql = "SELECT * FROM client_template WHERE template_id = " . intval($item);
58+
$addLimits = $app->db->queryOneRecord($sql);
59+
/* maybe the template is deleted in the meantime */
60+
if (is_array($addLimits)){
61+
foreach($addLimits as $k => $v){
62+
if ($limits[$k] > -1){
63+
if ($v == -1) {
64+
$limits[$k] = -1;
65+
}
66+
else {
67+
$limits[$k] += $v;
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
5274

5375
/*
5476
* Write all back to the database

interface/web/js/scrigo.js.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,35 @@ function pass_contains(pass, check) {
408408
}
409409
return false;
410410
}
411+
412+
function addAdditionalTemplate(){
413+
var tpl_add = document.getElementById('template_additional').value;
414+
var tpl_list = document.getElementById('template_additional_list').innerHTML;
415+
var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
416+
var addTplId = addTemplate[0];
417+
var addTplText = addTemplate[1];
418+
var newVal = tpl_add + '/' + addTplId + '/';
419+
newVal = newVal.replace('//', '/');
420+
var newList = tpl_list + '<br>' + addTplText;
421+
newList = newList.replace('<br><br>', '<br>');
422+
document.getElementById('template_additional').value = newVal;
423+
document.getElementById('template_additional_list').innerHTML = newList;
424+
alert('additional template ' + addTplText + ' added to customer');
425+
}
426+
427+
function delAdditionalTemplate(){
428+
var tpl_add = document.getElementById('template_additional').value;
429+
var tpl_list = document.getElementById('template_additional_list').innerHTML;
430+
var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
431+
var addTplId = addTemplate[0];
432+
var addTplText = addTemplate[1];
433+
var newVal = tpl_add;
434+
newVal = newVal.replace(addTplId, '');
435+
newVal = newVal.replace('//', '/');
436+
var newList = tpl_list.replace(addTplText, '');
437+
newList = newList.replace('<br><br>', '<br>');
438+
document.getElementById('template_additional').value = newVal;
439+
document.getElementById('template_additional_list').innerHTML = newList;
440+
alert('additional template ' + addTplText + ' deleted from customer');
441+
}
442+

interface/web/themes/default/css/screen/content_ispc.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
.iconstxt.icoNegative { background-image: url("../../icons/x16/cross_circle_frame.png"); }
288288
.iconstxt.icoAdd { background-image: url(../../icons/x16/plus_circle_frame.png); }
289289
.iconstxt.icoKey { background-image: url("../../icons/x16/key.png"); }
290+
.iconstxt.icoDelete { background-image: url("../../icons/x16/minus_circle_frame.png"); }
290291

291292
/* Button with icon and without text */
292293
.icons16 span { display: none; }

0 commit comments

Comments
 (0)