Skip to content

Commit fedbcaf

Browse files
author
Till Brehm
committed
- Added Welcome email function for clients and resellers.
- Added email message templates.
1 parent c6e9894 commit fedbcaf

16 files changed

+684
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
ALTER TABLE `client` ADD `limit_domainmodule` INT NOT NULL DEFAULT '0';
22
ALTER TABLE `client_template` ADD `limit_domainmodule` INT NOT NULL DEFAULT '0';
3+
CREATE TABLE `client_message_template` (
4+
`client_message_template_id` bigint(20) NOT NULL AUTO_INCREMENT,
5+
`sys_userid` int(11) NOT NULL DEFAULT '0',
6+
`sys_groupid` int(11) NOT NULL DEFAULT '0',
7+
`sys_perm_user` varchar(5) DEFAULT NULL,
8+
`sys_perm_group` varchar(5) DEFAULT NULL,
9+
`sys_perm_other` varchar(5) DEFAULT NULL,
10+
`template_type` varchar(255) DEFAULT NULL,
11+
`template_name` varchar(255) DEFAULT NULL,
12+
`subject` varchar(255) DEFAULT NULL,
13+
`message` text,
14+
PRIMARY KEY (`client_message_template_id`)
15+
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

install/sql/ispconfig3.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,30 @@ CREATE TABLE `client_template_assigned` (
340340
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
341341
-- --------------------------------------------------------
342342

343+
--
344+
-- Table structure for table `invoice_message_template`
345+
--
346+
347+
CREATE TABLE `client_message_template` (
348+
`client_message_template_id` bigint(20) NOT NULL AUTO_INCREMENT,
349+
`sys_userid` int(11) NOT NULL DEFAULT '0',
350+
`sys_groupid` int(11) NOT NULL DEFAULT '0',
351+
`sys_perm_user` varchar(5) DEFAULT NULL,
352+
`sys_perm_group` varchar(5) DEFAULT NULL,
353+
`sys_perm_other` varchar(5) DEFAULT NULL,
354+
`template_type` varchar(255) DEFAULT NULL,
355+
`template_name` varchar(255) DEFAULT NULL,
356+
`subject` varchar(255) DEFAULT NULL,
357+
`message` text,
358+
PRIMARY KEY (`client_message_template_id`)
359+
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
360+
361+
--
362+
-- Dumping data for table `invoice_message_template`
363+
--
364+
365+
-- --------------------------------------------------------
366+
343367
--
344368
-- Table structure for table `country`
345369
--

interface/web/client/client_edit.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,48 @@ function onAfterInsert() {
334334
}
335335
}
336336
}
337+
338+
//* Send welcome email
339+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
340+
$sql = "SELECT * FROM client_message_template WHERE template_type = 'welcome' AND sys_groupid = ".$client_group_id;
341+
$email_template = $app->db->queryOneRecord($sql);
342+
$client = $app->tform->getDataRecord($this->id);
343+
344+
if(is_array($email_template) && $client['email'] != '') {
345+
//* Parse client details into message
346+
$message = $email_template['message'];
347+
$subject = $email_template['subject'];
348+
foreach($client as $key => $val) {
349+
switch ($key) {
350+
case 'password':
351+
$message = str_replace('{password}', $this->dataRecord['password'], $message);
352+
$subject = str_replace('{password}', $this->dataRecord['password'], $subject);
353+
break;
354+
case 'gender':
355+
$message = str_replace('{salutation}', $wb['gender_'.$val.'_txt'], $message);
356+
$subject = str_replace('{salutation}', $wb['gender_'.$val.'_txt'], $subject);
357+
break;
358+
default:
359+
$message = str_replace('{'.$key.'}', $val, $message);
360+
$subject = str_replace('{'.$key.'}', $val, $subject);
361+
}
362+
}
363+
364+
//* Get sender address
365+
if($app->auth->is_admin()) {
366+
$app->uses('getconf');
367+
$system_config = $app->getconf->get_global_config();
368+
$from = $system_config['admin_mail'];
369+
} else {
370+
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
371+
$reseller = $app->db->queryOneRecord("SELECT client.email FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = ".$client_group_id);
372+
$from = $reseller["email"];
373+
}
374+
375+
//* Send the email
376+
$app->functions->mail($client['email'], $subject, $message, $from);
377+
}
378+
337379

338380
parent::onAfterInsert();
339381
}

interface/web/client/client_message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146

147147
//message variables
148148
$message_variables = '';
149-
$sql = "SHOW COLUMNS FROM client WHERE Field NOT IN ('client_id', 'sys_userid', 'sys_groupid', 'sys_perm_user', 'sys_perm_group', 'sys_perm_other', 'password', 'parent_client_id', 'id_rsa', 'ssh_rsa', 'created_at', 'default_mailserver', 'default_webserver', 'web_php_options', 'ssh_chroot', 'default_dnsserver', 'default_dbserver', 'template_master', 'template_additional') AND Field NOT LIKE 'limit_%'";
149+
$sql = "SHOW COLUMNS FROM client WHERE Field NOT IN ('client_id', 'sys_userid', 'sys_groupid', 'sys_perm_user', 'sys_perm_group', 'sys_perm_other', 'password', 'parent_client_id', 'id_rsa', 'ssh_rsa', 'created_at', 'default_mailserver', 'default_webserver', 'web_php_options', 'ssh_chroot', 'default_dnsserver', 'default_dbserver', 'template_master', 'template_additional', 'force_suexec', 'default_slave_dnsserver', 'usertheme', 'locked', 'canceled', 'can_use_api', 'tmp_data', 'customer_no_template', 'customer_no_start', 'customer_no_counter', 'added_date', 'added_by') AND Field NOT LIKE 'limit_%'";
150150
$field_names = $app->db->queryAllRecords($sql);
151151
if(!empty($field_names) && is_array($field_names)){
152152
foreach($field_names as $field_name){
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
/*
4+
Form Definition
5+
6+
Tabledefinition
7+
8+
Datatypes:
9+
- INTEGER (Forces the input to Int)
10+
- DOUBLE
11+
- CURRENCY (Formats the values to currency notation)
12+
- VARCHAR (no format check, maxlength: 255)
13+
- TEXT (no format check)
14+
- DATE (Dateformat, automatic conversion to timestamps)
15+
16+
Formtype:
17+
- TEXT (Textfield)
18+
- TEXTAREA (Textarea)
19+
- PASSWORD (Password textfield, input is not shown when edited)
20+
- SELECT (Select option field)
21+
- RADIO
22+
- CHECKBOX
23+
- CHECKBOXARRAY
24+
- FILE
25+
26+
VALUE:
27+
- Wert oder Array
28+
29+
Hint:
30+
The ID field of the database table is not part of the datafield definition.
31+
The ID field must be always auto incement (int or bigint).
32+
33+
34+
*/
35+
36+
$form["title"] = "Email template";
37+
$form["description"] = "";
38+
$form["name"] = "client_message_template";
39+
$form["action"] = "message_template_edit.php";
40+
$form["db_table"] = "client_message_template";
41+
$form["db_table_idx"] = "client_message_template_id";
42+
$form["db_history"] = "no";
43+
$form["tab_default"] = "template";
44+
$form["list_default"] = "message_template_list.php";
45+
$form["auth"] = 'yes';
46+
47+
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
48+
$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user
49+
$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
50+
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
51+
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
52+
53+
$form["tabs"]['template'] = array (
54+
'title' => "Settings",
55+
'width' => 100,
56+
'template' => "templates/message_template.htm",
57+
'fields' => array (
58+
//#################################
59+
// Begin Datatable fields
60+
//#################################
61+
'template_type' => array (
62+
'datatype' => 'VARCHAR',
63+
'formtype' => 'SELECT',
64+
'default' => '',
65+
'value' => array('welcome' => 'Default welcome email', 'other' => 'Other')
66+
),
67+
'template_name' => array (
68+
'datatype' => 'VARCHAR',
69+
'formtype' => 'TEXT',
70+
'default' => '',
71+
'value' => '',
72+
'separator' => '',
73+
'width' => '30',
74+
'maxlength' => '255',
75+
'rows' => '',
76+
'cols' => ''
77+
),
78+
'subject' => array (
79+
'datatype' => 'VARCHAR',
80+
'formtype' => 'TEXT',
81+
'default' => '',
82+
'value' => '',
83+
'separator' => '',
84+
'width' => '30',
85+
'maxlength' => '255',
86+
'rows' => '',
87+
'cols' => ''
88+
),
89+
'message' => array (
90+
'datatype' => 'TEXT',
91+
'formtype' => 'TEXTAREA',
92+
'default' => '',
93+
'value' => '',
94+
'separator' => '',
95+
'width' => '30',
96+
'maxlength' => '255',
97+
'rows' => '',
98+
'cols' => ''
99+
),
100+
//#################################
101+
// END Datatable fields
102+
//#################################
103+
)
104+
);
105+
106+
107+
108+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
$wb["template_type_txt"] = 'Email type';
3+
$wb["template_name_txt"] = 'Template name';
4+
$wb["subject_txt"] = 'Subject';
5+
$wb["message_txt"] = 'Message';
6+
$wb['Email template'] = 'Email template';
7+
$wb['Settings'] = 'Setting';
8+
$wb['variables_txt'] = 'Variables';
9+
$wb['variables_description_txt'] = '(The username and password variables are only available in welcome emails.)';
10+
$wb['duplicate_welcome_error'] = 'There can be only one default welcome email template. Please edit the existing template instead of adding a new one.';
11+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
$wb["list_head_txt"] = 'Email templates';
3+
$wb["template_type_txt"] = 'Message for';
4+
$wb["template_name_txt"] = 'Template name';
5+
?>

interface/web/client/lib/module.conf.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
'link' => 'client/client_template_list.php',
6666
'html_id' => 'client_template_list');
6767

68+
$items[] = array( 'title' => "Email-Templates",
69+
'target' => 'content',
70+
'link' => 'client/message_template_list.php',
71+
'html_id' => 'message_template_list');
6872

6973
$module["nav"][] = array( 'title' => 'Templates',
7074
'open' => 1,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2010, Till Brehm, projektfarm Gmbh
5+
All rights reserved.
6+
*/
7+
8+
/*
9+
Datatypes:
10+
- INTEGER
11+
- DOUBLE
12+
- CURRENCY
13+
- VARCHAR
14+
- TEXT
15+
- DATE
16+
*/
17+
18+
19+
20+
// Name of the list
21+
$liste["name"] = "client_message_template";
22+
23+
// Database table
24+
$liste["table"] = "client_message_template";
25+
26+
// Index index field of the database table
27+
$liste["table_idx"] = "client_message_template_id";
28+
29+
// Search Field Prefix
30+
$liste["search_prefix"] = "search_";
31+
32+
// Records per page
33+
$liste["records_per_page"] = 15;
34+
35+
// Script File of the list
36+
$liste["file"] = "message_template_list.php";
37+
38+
// Script file of the edit form
39+
$liste["edit_file"] = "message_template_edit.php";
40+
41+
// Script File of the delete script
42+
$liste["delete_file"] = "message_template_del.php";
43+
44+
// Paging Template
45+
$liste["paging_tpl"] = "templates/paging.tpl.htm";
46+
47+
// Enable authe
48+
$liste["auth"] = "yes";
49+
50+
51+
/*****************************************************
52+
* Suchfelder
53+
*****************************************************/
54+
55+
$liste["item"][] = array( 'field' => "template_type",
56+
'datatype' => "VARCHAR",
57+
'formtype' => "SELECT",
58+
'op' => "=",
59+
'prefix' => "",
60+
'suffix' => "",
61+
'width' => "",
62+
'value' => array('welcome' => 'Default welcome email', 'other' => 'Other'));
63+
64+
$liste["item"][] = array( 'field' => "template_name",
65+
'datatype' => "VARCHAR",
66+
'formtype' => "TEXT",
67+
'op' => "like",
68+
'prefix' => "%",
69+
'suffix' => "%",
70+
'width' => "",
71+
'value' => "");
72+
73+
74+
75+
76+
77+
?>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2014 Till Brehm, ISPConfig UG
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
/******************************************
32+
* Begin Form configuration
33+
******************************************/
34+
35+
$list_def_file = "list/message_template.list.php";
36+
$tform_def_file = "form/message_template.tform.php";
37+
38+
/******************************************
39+
* End Form configuration
40+
******************************************/
41+
42+
require_once '../../lib/config.inc.php';
43+
require_once '../../lib/app.inc.php';
44+
45+
//* Check permissions for module
46+
$app->auth->check_module_permissions('client');
47+
48+
$app->uses('tpl,tform');
49+
$app->load('tform_actions');
50+
51+
class page_action extends tform_actions {
52+
53+
}
54+
55+
$page = new page_action;
56+
$page->onDelete()
57+
58+
?>

0 commit comments

Comments
 (0)