Merge pull request #199 from mkoch227/attachments-in-emails
Attachments in emails
This commit is contained in:
commit
dbc351f09c
@ -197,7 +197,7 @@ if ($hesk_settings['attachments']['use'] && !empty($attachments))
|
||||
foreach ($attachments as $myatt)
|
||||
{
|
||||
hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` (`ticket_id`,`saved_name`,`real_name`,`size`) VALUES ('".hesk_dbEscape($trackingID)."','".hesk_dbEscape($myatt['saved_name'])."','".hesk_dbEscape($myatt['real_name'])."','".intval($myatt['size'])."')");
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] . '#' . $myatt['saved_name'] .',';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2094,6 +2094,28 @@ if ( defined('HESK_DEMO') )
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email_attachments" class="col-sm-4 col-xs-12 control-label">
|
||||
<?php echo $hesklang['email_attachments']; ?>
|
||||
<i class="fa fa-question-circle settingsquestionmark" data-toggle="htmlpopover"
|
||||
title="<?php echo $hesklang['email_attachments']; ?>"
|
||||
data-content="<?php echo $hesklang['email_attachments_help']; ?>"></i>
|
||||
</label>
|
||||
<div class="col-sm-8 col-xs-12">
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="email_attachments" value="0" <?php echo $modsForHesk_settings['attachments'] == 0 ? 'checked' : ''; ?>>
|
||||
<?php echo $hesklang['show_attachments_as_links']; ?>
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="email_attachments" value="1" <?php echo $modsForHesk_settings['attachments'] == 1 ? 'checked' : ''; ?>>
|
||||
<?php echo $hesklang['attach_directly_to_email']; ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="use_bootstrap_theme" class="col-sm-4 col-xs-12 control-label">
|
||||
<?php echo $hesklang['use_bootstrap_theme']; ?>
|
||||
|
@ -621,6 +621,7 @@ $set['customer-email-verification-required'] = empty($_POST['email-verification'
|
||||
$set['html_emails'] = empty($_POST['html_emails']) ? 0 : 1;
|
||||
$set['use_bootstrap_theme'] = empty($_POST['use_bootstrap_theme']) ? 0 : 1;
|
||||
$set['new_kb_article_visibility'] = hesk_checkMinMax( intval( hesk_POST('new_kb_article_visibility') ) , 0, 2, 2);
|
||||
$set['mfh_attachments'] = empty($_POST['email_attachments']) ? 0 : 1;
|
||||
|
||||
if ($set['customer-email-verification-required'])
|
||||
{
|
||||
@ -677,7 +678,10 @@ $modsForHesk_settings[\'mailgun_domain\'] = \''.$set['mailgun_domain'].'\';
|
||||
$modsForHesk_settings[\'use_bootstrap_theme\'] = '.$set['use_bootstrap_theme'].';
|
||||
|
||||
//-- Default value for new Knowledgebase article: 0 = Published, 1 = Private, 2 = Draft
|
||||
$modsForHesk_settings[\'new_kb_article_visibility\'] = '.$set['new_kb_article_visibility'].';';
|
||||
$modsForHesk_settings[\'new_kb_article_visibility\'] = '.$set['new_kb_article_visibility'].';
|
||||
|
||||
//-- Setting for adding attachments to email messages. Either 0 for default-HESK behavior, or 1 to send as attachments
|
||||
$modsForHesk_settings[\'attachments\'] = '.$set['mfh_attachments'].';';
|
||||
|
||||
// Write the file
|
||||
if ( ! file_put_contents(HESK_PATH . 'modsForHesk_settings.inc.php', $modsForHesk_file_content) )
|
||||
|
@ -401,7 +401,7 @@ if (isset($_POST['notemsg']) && hesk_token_check('POST'))
|
||||
foreach ($attachments as $myatt)
|
||||
{
|
||||
hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` (`ticket_id`,`saved_name`,`real_name`,`size`,`type`) VALUES ('".hesk_dbEscape($trackingID)."','".hesk_dbEscape($myatt['saved_name'])."','".hesk_dbEscape($myatt['real_name'])."','".intval($myatt['size'])."', '1')");
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] . '#' . $myatt['saved_name'] .',';
|
||||
}
|
||||
}
|
||||
|
||||
@ -568,15 +568,18 @@ if (isset($_GET['delatt']) && hesk_token_check())
|
||||
$revision = sprintf($hesklang['thist12'],hesk_date(),$att['real_name'],$_SESSION['name'].' ('.$_SESSION['user'].')');
|
||||
if ($reply)
|
||||
{
|
||||
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."replies` SET `attachments`=REPLACE(`attachments`,'".hesk_dbEscape($att_id.'#'.$att['real_name'].'#'.$att['saved_name']).",','') WHERE `id`='".intval($reply)."' LIMIT 1");
|
||||
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."replies` SET `attachments`=REPLACE(`attachments`,'".hesk_dbEscape($att_id.'#'.$att['real_name']).",','') WHERE `id`='".intval($reply)."' LIMIT 1");
|
||||
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `history`=CONCAT(`history`,'".hesk_dbEscape($revision)."') WHERE `id`='".intval($ticket['id'])."' LIMIT 1");
|
||||
}
|
||||
elseif ($note)
|
||||
{
|
||||
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."notes` SET `attachments`=REPLACE(`attachments`,'".hesk_dbEscape($att_id.'#'.$att['real_name'].'#'.$att['saved_name']).",','') WHERE `id`={$note} LIMIT 1");
|
||||
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."notes` SET `attachments`=REPLACE(`attachments`,'".hesk_dbEscape($att_id.'#'.$att['real_name']).",','') WHERE `id`={$note} LIMIT 1");
|
||||
}
|
||||
else
|
||||
{
|
||||
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `attachments`=REPLACE(`attachments`,'".hesk_dbEscape($att_id.'#'.$att['real_name'].'#'.$att['saved_name']).",','') WHERE `id`='".intval($ticket['id'])."' LIMIT 1");
|
||||
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `attachments`=REPLACE(`attachments`,'".hesk_dbEscape($att_id.'#'.$att['real_name']).",',''), `history`=CONCAT(`history`,'".hesk_dbEscape($revision)."') WHERE `id`='".intval($ticket['id'])."' LIMIT 1");
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ function hesk_validEmails()
|
||||
|
||||
function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
{
|
||||
global $hesk_settings, $hesklang, $modsForHesk_settings;
|
||||
global $hesk_settings, $hesklang, $modsForHesk_settings, $ticket;
|
||||
|
||||
// Demo mode
|
||||
if ( defined('HESK_DEMO') )
|
||||
@ -399,6 +399,11 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
{
|
||||
$postfields['html'] = $htmlMessage;
|
||||
}
|
||||
if ($modsForHesk_settings['attachments'] && $hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments']))
|
||||
{
|
||||
$postfields = processDirectAttachments('mailgun', $postfields);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
@ -411,17 +416,16 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
}
|
||||
|
||||
$boundary = sha1(uniqid());
|
||||
//Prepare the message for HTML or non-html
|
||||
if ($modsForHesk_settings['html_emails'])
|
||||
{
|
||||
$plaintextMessage = $message;
|
||||
$message = "--".$boundary."\n";
|
||||
$message .= "Content-Type: text/plain; charset=".$hesklang['ENCODING']."\n\n";
|
||||
$message .= $plaintextMessage."\n\n";
|
||||
//Prepare the message for HTML or non-html
|
||||
if ($modsForHesk_settings['html_emails'])
|
||||
{
|
||||
$message .= "--".$boundary."\n";
|
||||
$message .= "Content-Type: text/html; charset=".$hesklang['ENCODING']."\n\n";
|
||||
$message .= $htmlMessage."\n\n";
|
||||
$message .= "--".$boundary."--";
|
||||
}
|
||||
|
||||
// Use PHP's mail function
|
||||
@ -429,10 +433,7 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
{
|
||||
// Set additional headers
|
||||
$headers = '';
|
||||
if ($modsForHesk_settings['html_emails'])
|
||||
{
|
||||
$headers .= "MIME-Version: 1.0\n";
|
||||
}
|
||||
$headers .= "From: $hesk_settings[from_header]\n";
|
||||
if (count($cc) > 0)
|
||||
{
|
||||
@ -445,11 +446,17 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
$headers.= "Reply-To: $hesk_settings[from_header]\n";
|
||||
$headers.= "Return-Path: $hesk_settings[webmaster_mail]\n";
|
||||
$headers.= "Date: " . date(DATE_RFC2822) . "\n";
|
||||
if ($modsForHesk_settings['html_emails'])
|
||||
{
|
||||
$headers.= "Content-Type: multipart/alternative;boundary=".$boundary;
|
||||
|
||||
// Add attachments if necessary
|
||||
if ($modsForHesk_settings['attachments'] && $hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments']))
|
||||
{
|
||||
$message .= processDirectAttachments('phpmail', NULL, $boundary);
|
||||
}
|
||||
|
||||
//-- Close the email
|
||||
$message .= "--".$boundary."--";
|
||||
|
||||
// Send using PHP mail() function
|
||||
ob_start();
|
||||
mail($to,$subject,$message,$headers);
|
||||
@ -484,14 +491,9 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
"Subject: " . $subject,
|
||||
"Date: " . date(DATE_RFC2822)
|
||||
);
|
||||
if ($modsForHesk_settings['html_emails'])
|
||||
{
|
||||
array_push($headersArray,"MIME-Version: 1.0");
|
||||
array_push($headersArray,"Content-Type: multipart/alternative;boundary=".$boundary);
|
||||
} else
|
||||
{
|
||||
array_push($headersArray,"Content-Type: text/plain; charset=" . $hesklang['ENCODING']);
|
||||
}
|
||||
|
||||
if (count($cc) > 0)
|
||||
{
|
||||
array_push($headersArray,"Cc: ".implode(',',$cc));
|
||||
@ -501,7 +503,14 @@ function hesk_mail($to,$subject,$message,$htmlMessage,$cc=array(),$bcc=array())
|
||||
array_push($headersArray,"Bcc: ".implode(',',$bcc));
|
||||
}
|
||||
|
||||
// Add attachments if necessary
|
||||
if ($modsForHesk_settings['attachments'] && $hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments']))
|
||||
{
|
||||
$message .= processDirectAttachments('smtp', NULL, $boundary);
|
||||
}
|
||||
|
||||
//-- Close the email
|
||||
$message .= "--".$boundary."--";
|
||||
if ( ! $smtp->SendMessage($hesk_settings['noreply_mail'], $to_arr, $headersArray, $message))
|
||||
{
|
||||
// Suppress errors unless we are in debug mode
|
||||
@ -676,7 +685,7 @@ function hesk_getEmailMessage($eml_file, $ticket, $is_admin=0, $is_ticket=1, $ju
|
||||
|
||||
function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message, $isForHtml = 0)
|
||||
{
|
||||
global $hesk_settings, $hesklang;
|
||||
global $hesk_settings, $hesklang, $modsForHesk_settings;
|
||||
|
||||
/* Return just the message without any processing? */
|
||||
if ($just_message)
|
||||
@ -795,17 +804,31 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
|
||||
$msg = str_replace('%%MESSAGE%%',$ticket['message'],$msg);
|
||||
}
|
||||
|
||||
// Add direct links to any attachments at the bottom of the email message
|
||||
// Add direct links to any attachments at the bottom of the email message OR add them as attachments, depending on the settings
|
||||
// if ($modsForHesk_settings['attachments'] == 'inline' (other is 'attachment') {...}
|
||||
if ($hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments']) )
|
||||
{
|
||||
if (!$modsForHesk_settings['attachments']) {
|
||||
if ($isForHtml) {
|
||||
$msg .= "<br><br><br>" . $hesklang['fatt'];
|
||||
} else {
|
||||
$msg .= "\n\n\n" . $hesklang['fatt'];
|
||||
}
|
||||
|
||||
$att = explode(',', substr($ticket['attachments'], 0, -1));
|
||||
foreach ($att as $myatt)
|
||||
{
|
||||
list($att_id, $att_name) = explode('#', $myatt);
|
||||
$msg .= "\n\n" . $att_name . "\n" . $hesk_settings['hesk_url'] . '/download_attachment.php?att_id='.$att_id.'&track='.$ticket['trackid'].$hesk_settings['e_param'];
|
||||
list($att_id, $att_name, $saved_name) = explode('#', $myatt);
|
||||
if ($isForHtml) {
|
||||
$msg .= "<br><br>" . $att_name . "<br>";
|
||||
} else {
|
||||
$msg .= "\n\n" . $att_name . "\n";
|
||||
}
|
||||
$msg .= $hesk_settings['hesk_url'] . '/download_attachment.php?att_id='.$att_id.'&track='.$ticket['trackid'].$hesk_settings['e_param'];
|
||||
}
|
||||
}
|
||||
|
||||
// If attachments setting is set to 1, we'll add the attachments separately later; otherwise we'll duplicate the number of attachments.
|
||||
}
|
||||
|
||||
// For customer notifications: if we allow email piping/pop 3 fetching and
|
||||
@ -818,3 +841,34 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
// $postfields is only required for mailgun.
|
||||
// $boundary is only required for PHP/SMTP
|
||||
function processDirectAttachments($emailMethod, $postfields = NULL, $boundary = '') {
|
||||
global $hesk_settings, $ticket;
|
||||
|
||||
$att = explode(',', substr($ticket['attachments'], 0, -1));
|
||||
// if using mailgun, add each attachment to the array
|
||||
if ($emailMethod == 'mailgun') {
|
||||
$i = 0;
|
||||
foreach ($att as $myatt) {
|
||||
list($att_id, $att_name, $saved_name) = explode('#', $myatt);
|
||||
$postfields['attachment['.$i.']'] = '@'.HESK_PATH.$hesk_settings['attach_dir'].'/'.$saved_name;
|
||||
$i++;
|
||||
}
|
||||
return $postfields;
|
||||
} else {
|
||||
$attachments = '';
|
||||
foreach ($att as $myatt) {
|
||||
list($att_id, $att_name, $saved_name) = explode('#', $myatt);
|
||||
$attachments .= "\n\n" . "--".$boundary."\n";
|
||||
$attachments .= "Content-Type: application/octet-stream; name=\"".$att_name."\" \n";
|
||||
$attachments .= "Content-Disposition: attachment\n";
|
||||
$attachments .= "Content-Transfer-Encoding: base64\n\n";
|
||||
$attachmentBinary = file_get_contents(HESK_PATH.$hesk_settings['attach_dir'].'/'.$saved_name);
|
||||
$attcontents = chunk_split(base64_encode($attachmentBinary));
|
||||
$attachments .= $attcontents."\n\n";
|
||||
}
|
||||
return $attachments;
|
||||
}
|
||||
}
|
||||
|
@ -411,4 +411,20 @@ function execute220Scripts() {
|
||||
executeQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."statuses` SET `Closable` = 'yes'");
|
||||
executeQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."settings` SET `Value` = '2.2.0' WHERE `Key` = 'modsForHeskVersion'");
|
||||
}
|
||||
|
||||
function execute220FileUpdate() {
|
||||
//-- Add the new attachment property to modsForHesk_settings.inc.php
|
||||
$file = file_get_contents(HESK_PATH . 'modsForHesk_settings.inc.php');
|
||||
|
||||
//-- Only add the additional settings if they aren't already there.
|
||||
if (strpos($file, '$modsForHesk_settings[\'attachments\']') === false)
|
||||
{
|
||||
$file .= '
|
||||
|
||||
//-- Setting for adding attachments to email messages. Either 0 for default-HESK behavior, or 1 to send as attachments
|
||||
$modsForHesk_settings[\'attachments\'] = 0;';
|
||||
}
|
||||
|
||||
return file_put_contents(HESK_PATH.'modsForHesk_settings.inc.php', $file);
|
||||
}
|
||||
// END Version 2.2.0
|
@ -61,6 +61,11 @@ $hesklang['no_title_case'] = 'No';
|
||||
$hesklang['autoclose_ticket_status'] = 'When a ticket is closed automatically, change the status to';
|
||||
$hesklang['recent_tickets'] = 'Recent tickets';
|
||||
$hesklang['current_status_colon'] = 'Current status: %s'; // %s: status name (i.e. "Resolved", "New", etc.)
|
||||
$hesklang['email_attachments'] = 'Email attachments';
|
||||
$hesklang['email_attachments_help'] = '<b>Show attachments as links:</b> Links to attachments will be appended at the end of the email.
|
||||
<br><br><b>Attach directly to email:</b> Attachments will be embedded directly into emails.';
|
||||
$hesklang['show_attachments_as_links'] = 'Show attachments as links';
|
||||
$hesklang['attach_directly_to_email'] = 'Attach directly to email';
|
||||
|
||||
// ADDED OR MODIFIED IN Mods for HESK 2.1.1
|
||||
$hesklang['new_article_default_type'] = 'Default Type for New Articles';
|
||||
|
@ -38,3 +38,6 @@ $modsForHesk_settings['use_bootstrap_theme'] = 1;
|
||||
|
||||
//-- Default value for new Knowledgebase article: 0 = Published, 1 = Private, 2 = Draft
|
||||
$modsForHesk_settings['new_kb_article_visibility'] = 0;
|
||||
|
||||
//-- Setting for adding attachments to email messages. Either 0 for default-HESK behavior, or 1 to send as attachments
|
||||
$modsForHesk_settings['attachments'] = 0;
|
@ -187,7 +187,7 @@ if ($hesk_settings['attachments']['use'] && !empty($attachments))
|
||||
foreach ($attachments as $myatt)
|
||||
{
|
||||
hesk_dbQuery("INSERT INTO `".hesk_dbEscape($hesk_settings['db_pfix'])."attachments` (`ticket_id`,`saved_name`,`real_name`,`size`) VALUES ('{$trackingID}','".hesk_dbEscape($myatt['saved_name'])."','".hesk_dbEscape($myatt['real_name'])."','".intval($myatt['size'])."')");
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] .',';
|
||||
$myattachments .= hesk_dbInsertID() . '#' . $myatt['real_name'] . '#' . $myatt['saved_name'] .',';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user