Commit fedbcaf0 authored by Till Brehm's avatar Till Brehm
Browse files

- Added Welcome email function for clients and resellers.

- Added email message templates.
parent c6e98947
ALTER TABLE `client` ADD `limit_domainmodule` INT NOT NULL DEFAULT '0';
ALTER TABLE `client_template` ADD `limit_domainmodule` INT NOT NULL DEFAULT '0';
CREATE TABLE `client_message_template` (
`client_message_template_id` bigint(20) NOT NULL AUTO_INCREMENT,
`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,
`template_type` varchar(255) DEFAULT NULL,
`template_name` varchar(255) DEFAULT NULL,
`subject` varchar(255) DEFAULT NULL,
`message` text,
PRIMARY KEY (`client_message_template_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
\ No newline at end of file
......@@ -340,6 +340,30 @@ CREATE TABLE `client_template_assigned` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `invoice_message_template`
--
CREATE TABLE `client_message_template` (
`client_message_template_id` bigint(20) NOT NULL AUTO_INCREMENT,
`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,
`template_type` varchar(255) DEFAULT NULL,
`template_name` varchar(255) DEFAULT NULL,
`subject` varchar(255) DEFAULT NULL,
`message` text,
PRIMARY KEY (`client_message_template_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `invoice_message_template`
--
-- --------------------------------------------------------
--
-- Table structure for table `country`
--
......
......@@ -334,6 +334,48 @@ class page_action extends tform_actions {
}
}
}
//* Send welcome email
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$sql = "SELECT * FROM client_message_template WHERE template_type = 'welcome' AND sys_groupid = ".$client_group_id;
$email_template = $app->db->queryOneRecord($sql);
$client = $app->tform->getDataRecord($this->id);
if(is_array($email_template) && $client['email'] != '') {
//* Parse client details into message
$message = $email_template['message'];
$subject = $email_template['subject'];
foreach($client as $key => $val) {
switch ($key) {
case 'password':
$message = str_replace('{password}', $this->dataRecord['password'], $message);
$subject = str_replace('{password}', $this->dataRecord['password'], $subject);
break;
case 'gender':
$message = str_replace('{salutation}', $wb['gender_'.$val.'_txt'], $message);
$subject = str_replace('{salutation}', $wb['gender_'.$val.'_txt'], $subject);
break;
default:
$message = str_replace('{'.$key.'}', $val, $message);
$subject = str_replace('{'.$key.'}', $val, $subject);
}
}
//* Get sender address
if($app->auth->is_admin()) {
$app->uses('getconf');
$system_config = $app->getconf->get_global_config();
$from = $system_config['admin_mail'];
} else {
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$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);
$from = $reseller["email"];
}
//* Send the email
$app->functions->mail($client['email'], $subject, $message, $from);
}
parent::onAfterInsert();
}
......
......@@ -146,7 +146,7 @@ if($_SESSION["s"]["user"]["typ"] == 'admin'){
//message variables
$message_variables = '';
$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_%'";
$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_%'";
$field_names = $app->db->queryAllRecords($sql);
if(!empty($field_names) && is_array($field_names)){
foreach($field_names as $field_name){
......
<?php
/*
Form Definition
Tabledefinition
Datatypes:
- INTEGER (Forces the input to Int)
- DOUBLE
- CURRENCY (Formats the values to currency notation)
- VARCHAR (no format check, maxlength: 255)
- TEXT (no format check)
- DATE (Dateformat, automatic conversion to timestamps)
Formtype:
- TEXT (Textfield)
- TEXTAREA (Textarea)
- PASSWORD (Password textfield, input is not shown when edited)
- SELECT (Select option field)
- RADIO
- CHECKBOX
- CHECKBOXARRAY
- FILE
VALUE:
- Wert oder Array
Hint:
The ID field of the database table is not part of the datafield definition.
The ID field must be always auto incement (int or bigint).
*/
$form["title"] = "Email template";
$form["description"] = "";
$form["name"] = "client_message_template";
$form["action"] = "message_template_edit.php";
$form["db_table"] = "client_message_template";
$form["db_table_idx"] = "client_message_template_id";
$form["db_history"] = "no";
$form["tab_default"] = "template";
$form["list_default"] = "message_template_list.php";
$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
$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
$form["tabs"]['template'] = array (
'title' => "Settings",
'width' => 100,
'template' => "templates/message_template.htm",
'fields' => array (
//#################################
// Begin Datatable fields
//#################################
'template_type' => array (
'datatype' => 'VARCHAR',
'formtype' => 'SELECT',
'default' => '',
'value' => array('welcome' => 'Default welcome email', 'other' => 'Other')
),
'template_name' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'separator' => '',
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => ''
),
'subject' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'separator' => '',
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => ''
),
'message' => array (
'datatype' => 'TEXT',
'formtype' => 'TEXTAREA',
'default' => '',
'value' => '',
'separator' => '',
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => ''
),
//#################################
// END Datatable fields
//#################################
)
);
?>
<?php
$wb["template_type_txt"] = 'Email type';
$wb["template_name_txt"] = 'Template name';
$wb["subject_txt"] = 'Subject';
$wb["message_txt"] = 'Message';
$wb['Email template'] = 'Email template';
$wb['Settings'] = 'Setting';
$wb['variables_txt'] = 'Variables';
$wb['variables_description_txt'] = '(The username and password variables are only available in welcome emails.)';
$wb['duplicate_welcome_error'] = 'There can be only one default welcome email template. Please edit the existing template instead of adding a new one.';
?>
\ No newline at end of file
<?php
$wb["list_head_txt"] = 'Email templates';
$wb["template_type_txt"] = 'Message for';
$wb["template_name_txt"] = 'Template name';
?>
\ No newline at end of file
......@@ -65,6 +65,10 @@ $items[] = array( 'title' => "Limit-Templates",
'link' => 'client/client_template_list.php',
'html_id' => 'client_template_list');
$items[] = array( 'title' => "Email-Templates",
'target' => 'content',
'link' => 'client/message_template_list.php',
'html_id' => 'message_template_list');
$module["nav"][] = array( 'title' => 'Templates',
'open' => 1,
......
<?php
/*
Copyright (c) 2010, Till Brehm, projektfarm Gmbh
All rights reserved.
*/
/*
Datatypes:
- INTEGER
- DOUBLE
- CURRENCY
- VARCHAR
- TEXT
- DATE
*/
// Name of the list
$liste["name"] = "client_message_template";
// Database table
$liste["table"] = "client_message_template";
// Index index field of the database table
$liste["table_idx"] = "client_message_template_id";
// Search Field Prefix
$liste["search_prefix"] = "search_";
// Records per page
$liste["records_per_page"] = 15;
// Script File of the list
$liste["file"] = "message_template_list.php";
// Script file of the edit form
$liste["edit_file"] = "message_template_edit.php";
// Script File of the delete script
$liste["delete_file"] = "message_template_del.php";
// Paging Template
$liste["paging_tpl"] = "templates/paging.tpl.htm";
// Enable authe
$liste["auth"] = "yes";
/*****************************************************
* Suchfelder
*****************************************************/
$liste["item"][] = array( 'field' => "template_type",
'datatype' => "VARCHAR",
'formtype' => "SELECT",
'op' => "=",
'prefix' => "",
'suffix' => "",
'width' => "",
'value' => array('welcome' => 'Default welcome email', 'other' => 'Other'));
$liste["item"][] = array( 'field' => "template_name",
'datatype' => "VARCHAR",
'formtype' => "TEXT",
'op' => "like",
'prefix' => "%",
'suffix' => "%",
'width' => "",
'value' => "");
?>
<?php
/*
Copyright (c) 2014 Till Brehm, ISPConfig UG
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.
*/
/******************************************
* Begin Form configuration
******************************************/
$list_def_file = "list/message_template.list.php";
$tform_def_file = "form/message_template.tform.php";
/******************************************
* End Form configuration
******************************************/
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
//* Check permissions for module
$app->auth->check_module_permissions('client');
$app->uses('tpl,tform');
$app->load('tform_actions');
class page_action extends tform_actions {
}
$page = new page_action;
$page->onDelete()
?>
<?php
/*
Copyright (c) 2014 Till Brehm, ISPConfig UG
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.
*/
/******************************************
* Begin Form configuration
******************************************/
$tform_def_file = "form/message_template.tform.php";
/******************************************
* End Form configuration
******************************************/
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
//* Check permissions for module
$app->auth->check_module_permissions('client');
// Loading classes
$app->uses('tpl,tform,tform_actions');
$app->load('tform_actions');
class page_action extends tform_actions {
function onSubmit() {
global $app, $conf;
// Check for duplicates
if($this->dataRecord['template_type'] == 'welcome') {
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$sql = "SELECT count(client_message_template_id) as number FROM client_message_template WHERE template_type = 'welcome' AND sys_groupid = ".$client_group_id;
if($this->id > 0) {
$sql .= " AND client_message_template_id != ".$this->id;
}
$tmp = $app->db->queryOneRecord($sql);
if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng('duplicate_welcome_error');
}
parent::onSubmit();
}
function onShowEnd() {
global $app, $conf;
//message variables
$message_variables = '';
$sql = "SHOW COLUMNS FROM client WHERE Field NOT IN ('client_id', 'sys_userid', 'sys_groupid', 'sys_perm_user', 'sys_perm_group', 'sys_perm_other', '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_%'";
$field_names = $app->db->queryAllRecords($sql);
if(!empty($field_names) && is_array($field_names)){
foreach($field_names as $field_name){
if($field_name['Field'] != ''){
if($field_name['Field'] == 'gender'){
$message_variables .= '<a href="javascript:void(0);" class="addPlaceholder">{salutation}</a> ';
} else {
$message_variables .= '<a href="javascript:void(0);" class="addPlaceholder">{'.$field_name['Field'].'}</a> ';
}
}
}
}
$app->tpl->setVar('message_variables', trim($message_variables));
parent::onShowEnd();
}
}
$page = new page_action;
$page->onLoad();
?>
<?php
/*
Copyright (c) 2014 Till Brehm, ISPConfig UG
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.
*/
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
/******************************************
* Begin Form configuration
******************************************/
$list_def_file = "list/message_template.list.php";
/******************************************
* End Form configuration
******************************************/
//* Check permissions for module
$app->auth->check_module_permissions('client');
$app->uses('listform_actions');
//$app->listform_actions->SQLOrderBy = 'ORDER BY company_name, contact_name, client_id';
//$app->listform_actions->SQLExtWhere = "limit_client = 0";
$app->listform_actions->onLoad();
?>
......@@ -266,6 +266,47 @@ class page_action extends tform_actions {
}
}
//* Send welcome email
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$sql = "SELECT * FROM client_message_template WHERE template_type = 'welcome' AND sys_groupid = ".$client_group_id;
$email_template = $app->db->queryOneRecord($sql);
$client = $app->tform->getDataRecord($this->id);
if(is_array($email_template) && $client['email'] != '') {
//* Parse client details into message
$message = $email_template['message'];
$subject = $email_template['subject'];
foreach($client as $key => $val) {
switch ($key) {
case 'password':
$message = str_replace('{password}', $this->dataRecord['password'], $message);
$subject = str_replace('{password}', $this->dataRecord['password'], $subject);
break;
case 'gender':
$message = str_replace('{salutation}', $wb['gender_'.$val.'_txt'], $message);
$subject = str_replace('{salutation}', $wb['gender_'.$val.'_txt'], $subject);
break;
default:
$message = str_replace('{'.$key.'}', $val, $message);
$subject = str_replace('{'.$key.'}', $val, $subject);
}
}
//* Get sender address
if($app->auth->is_admin()) {
$app->uses('getconf');
$system_config = $app->getconf->get_global_config();
$from = $system_config['admin_mail'];
} else {
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$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);
$from = $reseller["email"];
}
//* Send the email
$app->functions->mail($client['email'], $subject, $message, $from);
}
parent::onAfterInsert();
}
......
<h2><tmpl_var name="list_head_txt"></h2>
<div class="panel panel_list_client_message_template">
<div class="pnl_toolsarea">
<fieldset><legend>{tmpl_var name="toolsarea_head_txt"}</legend>
<div class="buttons">
<button class="iconstxt icoAdd" type="button" onclick="loadContent('client/message_template_edit.php');">
<span>{tmpl_var name="add_new_record_txt"}</span>
</button>
</div>