Quitar "Powered by..." de los emails.

git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_FormulariosCalidad/trunk@21 e2c41b2c-0c6f-0149-8b81-50b1a9191bb3
This commit is contained in:
David Arranz 2011-04-11 18:28:54 +00:00
parent 8b11d513ad
commit 4827746562

View File

@ -1,21 +1,21 @@
<?php <?php
/****************************************************************************** /******************************************************************************
MachForm MachForm
Copyright 2007 Appnitro Software. This code cannot be redistributed without Copyright 2007 Appnitro Software. This code cannot be redistributed without
permission from http://www.appnitro.com/ permission from http://www.appnitro.com/
More info at: http://www.appnitro.com/ More info at: http://www.appnitro.com/
******************************************************************************/ ******************************************************************************/
//this function accept 'YYYY-MM-DD HH:MM:SS' //this function accept 'YYYY-MM-DD HH:MM:SS'
function relative_date($input_date) { function relative_date($input_date) {
$tz = 0; // change this if your web server and weblog are in different timezones $tz = 0; // change this if your web server and weblog are in different timezones
$posted_date = str_replace(array('-',' ',':'),'',$input_date); $posted_date = str_replace(array('-',' ',':'),'',$input_date);
$month = substr($posted_date,4,2); $month = substr($posted_date,4,2);
if ($month == "02") { // february if ($month == "02") { // february
// check for leap year // check for leap year
$leapYear = isLeapYear(substr($posted_date,0,4)); $leapYear = isLeapYear(substr($posted_date,0,4));
@ -24,14 +24,14 @@
} }
else { // not february else { // not february
// check to see if the month has 30/31 days in it // check to see if the month has 30/31 days in it
if ($month == "04" or if ($month == "04" or
$month == "06" or $month == "06" or
$month == "09" or $month == "09" or
$month == "11") $month == "11")
$month_in_seconds = 2592000; // 30 day month $month_in_seconds = 2592000; // 30 day month
else $month_in_seconds = 2678400; // 31 day month; else $month_in_seconds = 2678400; // 31 day month;
} }
$in_seconds = strtotime(substr($posted_date,0,8).' '. $in_seconds = strtotime(substr($posted_date,0,8).' '.
substr($posted_date,8,2).':'. substr($posted_date,8,2).':'.
substr($posted_date,10,2).':'. substr($posted_date,10,2).':'.
@ -48,7 +48,7 @@
$minutes = floor($diff/60); $minutes = floor($diff/60);
$diff -= $minutes*60; $diff -= $minutes*60;
$seconds = $diff; $seconds = $diff;
$relative_date = ''; $relative_date = '';
if ($months>0) { if ($months>0) {
// over a month old, just show date ("Month, Day Year") // over a month old, just show date ("Month, Day Year")
@ -77,22 +77,22 @@
// seconds only // seconds only
$relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':''); $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':'');
} }
// show relative date and add proper verbiage // show relative date and add proper verbiage
return $relative_date.' ago'; return $relative_date.' ago';
} }
} }
//this function accept 'YYYY-MM-DD HH:MM:SS' //this function accept 'YYYY-MM-DD HH:MM:SS'
function short_relative_date($input_date) { function short_relative_date($input_date) {
$tz = 0; // change this if your web server and weblog are in different timezones $tz = 0; // change this if your web server and weblog are in different timezones
$posted_date = str_replace(array('-',' ',':'),'',$input_date); $posted_date = str_replace(array('-',' ',':'),'',$input_date);
$month = substr($posted_date,4,2); $month = substr($posted_date,4,2);
$year = substr($posted_date,0,4); $year = substr($posted_date,0,4);
if ($month == "02") { // february if ($month == "02") { // february
// check for leap year // check for leap year
$leapYear = isLeapYear($year); $leapYear = isLeapYear($year);
@ -101,14 +101,14 @@
} }
else { // not february else { // not february
// check to see if the month has 30/31 days in it // check to see if the month has 30/31 days in it
if ($month == "04" or if ($month == "04" or
$month == "06" or $month == "06" or
$month == "09" or $month == "09" or
$month == "11") $month == "11")
$month_in_seconds = 2592000; // 30 day month $month_in_seconds = 2592000; // 30 day month
else $month_in_seconds = 2678400; // 31 day month; else $month_in_seconds = 2678400; // 31 day month;
} }
$in_seconds = strtotime(substr($posted_date,0,8).' '. $in_seconds = strtotime(substr($posted_date,0,8).' '.
substr($posted_date,8,2).':'. substr($posted_date,8,2).':'.
substr($posted_date,10,2).':'. substr($posted_date,10,2).':'.
@ -125,10 +125,10 @@
$minutes = floor($diff/60); $minutes = floor($diff/60);
$diff -= $minutes*60; $diff -= $minutes*60;
$seconds = $diff; $seconds = $diff;
$relative_date = ''; $relative_date = '';
if ($months>0) { if ($months>0) {
// over a month old // over a month old
if(!empty($input_date)){ if(!empty($input_date)){
if($year < date('Y')){ //over a year, show international date if($year < date('Y')){ //over a year, show international date
@ -136,7 +136,7 @@
}else{ //less than a year }else{ //less than a year
return date('M j',strtotime($input_date)); return date('M j',strtotime($input_date));
} }
}else{ }else{
return ''; return '';
} }
@ -160,17 +160,17 @@
// seconds only // seconds only
$relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':''); $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':'');
} }
// show relative date and add proper verbiage // show relative date and add proper verbiage
return $relative_date.' ago'; return $relative_date.' ago';
} }
} }
function isLeapYear($year) { function isLeapYear($year) {
return $year % 4 == 0 && ($year % 400 == 0 || $year % 100 != 0); return $year % 4 == 0 && ($year % 400 == 0 || $year % 100 != 0);
} }
//remove a folder and all it's content //remove a folder and all it's content
function full_rmdir($dirname){ function full_rmdir($dirname){
if ($dirHandle = opendir($dirname)){ if ($dirHandle = opendir($dirname)){
@ -199,80 +199,80 @@
//show success or error messages //show success or error messages
function show_message(){ function show_message(){
if(!empty($_SESSION['AP_ERROR'])){ if(!empty($_SESSION['AP_ERROR'])){
if(!empty($_SESSION['AP_ERROR']['desc'])){ if(!empty($_SESSION['AP_ERROR']['desc'])){
$error_desc = '<p id="error_message_desc"><b>'.$_SESSION['AP_ERROR']['desc'].'</b></p>'; $error_desc = '<p id="error_message_desc"><b>'.$_SESSION['AP_ERROR']['desc'].'</b></p>';
}else{ }else{
$error_desc = ''; $error_desc = '';
} }
$ul_markup =<<<EOT $ul_markup =<<<EOT
<ul class="global_message"> <ul class="global_message">
<li id="error_message"> <li id="error_message">
<h3 id="error_message_title">{$_SESSION['AP_ERROR']['title']} &nbsp;<img src="images/icons/stop.gif" align="top" style="padding-top: 2px"/></h3> <h3 id="error_message_title">{$_SESSION['AP_ERROR']['title']} &nbsp;<img src="images/icons/stop.gif" align="top" style="padding-top: 2px"/></h3>
{$error_desc} {$error_desc}
</li> </li>
</ul> </ul>
EOT; EOT;
echo $ul_markup; echo $ul_markup;
$_SESSION['AP_ERROR'] = array(); $_SESSION['AP_ERROR'] = array();
unset($_SESSION['AP_ERROR']); unset($_SESSION['AP_ERROR']);
} }
if(!empty($_SESSION['AP_SUCCESS'])){ if(!empty($_SESSION['AP_SUCCESS'])){
if(!empty($_SESSION['AP_SUCCESS']['desc'])){ if(!empty($_SESSION['AP_SUCCESS']['desc'])){
$success_desc = '<p id="success_message_desc"><b>'.$_SESSION['AP_SUCCESS']['desc'].'</b></p>'; $success_desc = '<p id="success_message_desc"><b>'.$_SESSION['AP_SUCCESS']['desc'].'</b></p>';
}else{ }else{
$success_desc = ''; $success_desc = '';
} }
$ul_markup =<<<EOT $ul_markup =<<<EOT
<ul class="global_message"> <ul class="global_message">
<li id="success_message"> <li id="success_message">
<h3 id="success_message_title"><span>{$_SESSION['AP_SUCCESS']['title']}&nbsp;<img src="images/icons/checkbox.gif" align="absmiddle" /></span></h3> <h3 id="success_message_title"><span>{$_SESSION['AP_SUCCESS']['title']}&nbsp;<img src="images/icons/checkbox.gif" align="absmiddle" /></span></h3>
{$success_desc} {$success_desc}
</li> </li>
</ul> </ul>
EOT; EOT;
echo $ul_markup; echo $ul_markup;
$_SESSION['AP_SUCCESS'] = array(); $_SESSION['AP_SUCCESS'] = array();
unset($_SESSION['AP_SUCCESS']); unset($_SESSION['AP_SUCCESS']);
} }
} }
//send notification email //send notification email
//$to_emails is a comma separated list of email address or {element_x} field //$to_emails is a comma separated list of email address or {element_x} field
function send_notification($form_id,$entry_id,$to_emails,$email_param){ function send_notification($form_id,$entry_id,$to_emails,$email_param){
$from_name = $email_param['from_name']; $from_name = $email_param['from_name'];
$from_email = $email_param['from_email']; $from_email = $email_param['from_email'];
$subject = $email_param['subject']; $subject = $email_param['subject'];
$content = nl2br($email_param['content']); $content = nl2br($email_param['content']);
$as_plain_text = $email_param['as_plain_text']; //if set to 'true' the email content will be a simple plain text $as_plain_text = $email_param['as_plain_text']; //if set to 'true' the email content will be a simple plain text
$target_is_admin = $email_param['target_is_admin']; //if set to 'false', the download link for uploaded file will be removed $target_is_admin = $email_param['target_is_admin']; //if set to 'false', the download link for uploaded file will be removed
//get data for the particular entry id //get data for the particular entry id
if($target_is_admin === false){ if($target_is_admin === false){
$options['strip_download_link'] = true; $options['strip_download_link'] = true;
} }
$options['strip_checkbox_image'] = true; $options['strip_checkbox_image'] = true;
$options['machform_base_path'] = $email_param['machform_base_path']; //the path to machform $options['machform_base_path'] = $email_param['machform_base_path']; //the path to machform
$entry_details = get_entry_details($form_id,$entry_id,$options); $entry_details = get_entry_details($form_id,$entry_id,$options);
//populate field values to template variables //populate field values to template variables
$i=0; $i=0;
foreach ($entry_details as $data){ foreach ($entry_details as $data){
$template_variables[$i] = '{element_'.$data['element_id'].'}'; $template_variables[$i] = '{element_'.$data['element_id'].'}';
$template_values[$i] = $data['value']; $template_values[$i] = $data['value'];
if($data['element_type'] == 'textarea'){ if($data['element_type'] == 'textarea'){
$template_values[$i] = nl2br($data['value']); $template_values[$i] = nl2br($data['value']);
}elseif ($data['element_type'] == 'file'){ }elseif ($data['element_type'] == 'file'){
@ -284,25 +284,25 @@ EOT;
}else{ }else{
$template_values[$i] = $data['value']; $template_values[$i] = $data['value'];
} }
$i++; $i++;
} }
//get entry timestamp //get entry timestamp
$query = "select date_created,ip_address from `ap_form_{$form_id}` where id='$entry_id'"; $query = "select date_created,ip_address from `ap_form_{$form_id}` where id='$entry_id'";
$result = do_query($query); $result = do_query($query);
$row = do_fetch_result($result); $row = do_fetch_result($result);
$date_created = $row['date_created']; $date_created = $row['date_created'];
$ip_address = $row['ip_address']; $ip_address = $row['ip_address'];
//get form name //get form name
$query = "select form_name from `ap_forms` where form_id='$form_id'"; $query = "select form_name from `ap_forms` where form_id='$form_id'";
$result = do_query($query); $result = do_query($query);
$row = do_fetch_result($result); $row = do_fetch_result($result);
$form_name = $row['form_name']; $form_name = $row['form_name'];
$template_variables[$i] = '{date_created}'; $template_variables[$i] = '{date_created}';
$template_values[$i] = $date_created; $template_values[$i] = $date_created;
$i++; $i++;
@ -317,58 +317,58 @@ EOT;
$i++; $i++;
$template_variables[$i] = '{form_id}'; $template_variables[$i] = '{form_id}';
$template_values[$i] = $form_id; $template_values[$i] = $form_id;
//compose {entry_data} based on 'as_plain_text' preferences //compose {entry_data} based on 'as_plain_text' preferences
$email_body = ''; $email_body = '';
if(!$as_plain_text){ if(!$as_plain_text){
//compose html format //compose html format
$email_body = '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-family:Lucida Grande,Tahoma,Arial,Verdana,sans-serif;font-size:12px;text-align:left">'."\n"; $email_body = '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-family:Lucida Grande,Tahoma,Arial,Verdana,sans-serif;font-size:12px;text-align:left">'."\n";
$toggle = false; $toggle = false;
foreach ($entry_details as $data){ foreach ($entry_details as $data){
//0 should be displayed, empty string don't //0 should be displayed, empty string don't
if((empty($data['value']) || $data['value'] == '&nbsp;') && $data['value'] !== 0 && $data['value'] !== '0'){ if((empty($data['value']) || $data['value'] == '&nbsp;') && $data['value'] !== 0 && $data['value'] !== '0'){
continue; continue;
} }
if($toggle){ if($toggle){
$toggle = false; $toggle = false;
$row_style = 'style="background-color:#F3F7FB"'; $row_style = 'style="background-color:#F3F7FB"';
}else{ }else{
$toggle = true; $toggle = true;
$row_style = ''; $row_style = '';
} }
if($data['element_type'] == 'textarea'){ if($data['element_type'] == 'textarea'){
$data['value'] = nl2br($data['value']); $data['value'] = nl2br($data['value']);
}elseif ($data['element_type'] == 'file'){ }elseif ($data['element_type'] == 'file'){
if($target_is_admin === false){ if($target_is_admin === false){
$data['value'] = strip_tags($data['value']); $data['value'] = strip_tags($data['value']);
}else{ }else{
$data['value'] = strip_tags($data['value'],'<a>'); $data['value'] = strip_tags($data['value'],'<a>');
} }
} }
$email_body .= "<tr {$row_style}>\n"; $email_body .= "<tr {$row_style}>\n";
$email_body .= '<td width="40%" style="border-bottom:1px solid #DEDEDE;padding:5px 10px;"><strong>'.$data['label'].'</strong> </td>'."\n"; $email_body .= '<td width="40%" style="border-bottom:1px solid #DEDEDE;padding:5px 10px;"><strong>'.$data['label'].'</strong> </td>'."\n";
$email_body .= '<td width="60%" style="border-bottom:1px solid #DEDEDE;padding:5px 10px;">'.$data['value'].'</td>'."\n"; $email_body .= '<td width="60%" style="border-bottom:1px solid #DEDEDE;padding:5px 10px;">'.$data['value'].'</td>'."\n";
$email_body .= '</tr>'."\n"; $email_body .= '</tr>'."\n";
$i++; $i++;
} }
$email_body .= "</table>\n"; $email_body .= "</table>\n";
}else{ }else{
//compose text format //compose text format
foreach ($entry_details as $data){ foreach ($entry_details as $data){
//0 should be displayed, empty string don't //0 should be displayed, empty string don't
if((empty($data['value']) || $data['value'] == '&nbsp;') && $data['value'] !== 0 && $data['value'] !== '0'){ if((empty($data['value']) || $data['value'] == '&nbsp;') && $data['value'] !== 0 && $data['value'] !== '0'){
continue; continue;
} }
if($data['element_type'] == 'textarea'){ if($data['element_type'] == 'textarea'){
$email_body .= "<b>{$data['label']}</b> <br />".nl2br($data['value'])."<br /><br />\n"; $email_body .= "<b>{$data['label']}</b> <br />".nl2br($data['value'])."<br /><br />\n";
}elseif ($data['element_type'] == 'checkbox' || $data['element_type'] == 'address'){ }elseif ($data['element_type'] == 'checkbox' || $data['element_type'] == 'address'){
@ -384,38 +384,38 @@ EOT;
}else{ }else{
$email_body .= "<b>{$data['label']}</b> - {$data['value']} <br />\n"; $email_body .= "<b>{$data['label']}</b> - {$data['value']} <br />\n";
} }
} }
} }
$i = count($template_variables); $i = count($template_variables);
$template_variables[$i] = '{entry_data}'; $template_variables[$i] = '{entry_data}';
$template_values[$i] = $email_body; $template_values[$i] = $email_body;
$mail = new PHPMailer(); $mail = new PHPMailer();
$mail->CharSet = 'UTF-8'; $mail->CharSet = 'UTF-8';
$mail->Host = "127.0.0.1"; $mail->Host = "127.0.0.1";
$mail->IsHTML(true); $mail->IsHTML(true);
$mail->Mailer = "mail"; $mail->Mailer = "mail";
$mail->SMTPAuth = false; $mail->SMTPAuth = false;
if(USE_SMTP === true){ if(USE_SMTP === true){
$mail->Mailer = "smtp"; $mail->Mailer = "smtp";
$mail->Host = SMTP_HOST; $mail->Host = SMTP_HOST;
$mail->Port = SMTP_PORT; $mail->Port = SMTP_PORT;
if(SMTP_AUTH === true){ if(SMTP_AUTH === true){
$mail->SMTPAuth = true; $mail->SMTPAuth = true;
$mail->Username = SMTP_USERNAME; $mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD; $mail->Password = SMTP_PASSWORD;
} }
if(SMTP_SECURE === true){ if(SMTP_SECURE === true){
$mail->SMTPSecure = 'tls'; $mail->SMTPSecure = 'tls';
} }
} }
//parse from_name template //parse from_name template
if(!empty($from_name)){ if(!empty($from_name)){
$from_name = str_replace($template_variables,$template_values,$from_name); $from_name = str_replace($template_variables,$template_values,$from_name);
@ -423,12 +423,12 @@ EOT;
}elseif (NOTIFICATION_MAIL_FROM_NAME != ''){ }elseif (NOTIFICATION_MAIL_FROM_NAME != ''){
$mail->FromName = utf8_encode(str_replace('&nbsp','',str_replace($template_variables,$template_values,NOTIFICATION_MAIL_FROM_NAME))); $mail->FromName = utf8_encode(str_replace('&nbsp','',str_replace($template_variables,$template_values,NOTIFICATION_MAIL_FROM_NAME)));
}else{ }else{
$mail->FromName = 'MachForm'; $mail->FromName = '';
} }
//decode any html entity //decode any html entity
$mail->FromName = html_entity_decode($mail->FromName,ENT_QUOTES); $mail->FromName = html_entity_decode($mail->FromName,ENT_QUOTES);
//parse from_email_address template //parse from_email_address template
if(!empty($from_email)){ if(!empty($from_email)){
$from_email = str_replace($template_variables,$template_values,$from_email); $from_email = str_replace($template_variables,$template_values,$from_email);
@ -439,7 +439,7 @@ EOT;
$domain = str_replace('www.','',$_SERVER['SERVER_NAME']); $domain = str_replace('www.','',$_SERVER['SERVER_NAME']);
$mail->From = "no-reply@{$domain}"; $mail->From = "no-reply@{$domain}";
} }
//parse subject template //parse subject template
if(!empty($subject)){ if(!empty($subject)){
$subject = str_replace($template_variables,$template_values,$subject); $subject = str_replace($template_variables,$template_values,$subject);
@ -455,24 +455,24 @@ EOT;
} }
//decode any html entity //decode any html entity
$mail->Subject = html_entity_decode($mail->Subject,ENT_QUOTES); $mail->Subject = html_entity_decode($mail->Subject,ENT_QUOTES);
//parse content template //parse content template
$email_content = str_replace($template_variables,$template_values,$content); $email_content = str_replace($template_variables,$template_values,$content);
//add footer //add footer
$email_content .= "<br /><br /><br /><br /><br /><b style=\"font-family:Lucida Grande,Tahoma,Arial,Verdana,sans-serif;font-size:12px\">Powered by <a href=\"http://www.appnitro.com\">MachForm</a></b>"; $email_content .= "<br /><br /><br /><br /><br /><b style=\"font-family:Lucida Grande,Tahoma,Arial,Verdana,sans-serif;font-size:12px\"></b>";
//enclose with container div //enclose with container div
$email_content = '<div style="font-family:Lucida Grande,Tahoma,Arial,Verdana,sans-serif;font-size:12px">'.$email_content.'</div>'; $email_content = '<div style="font-family:Lucida Grande,Tahoma,Arial,Verdana,sans-serif;font-size:12px">'.$email_content.'</div>';
$mail->Body = $email_content; $mail->Body = $email_content;
//send email //send email
$to_emails = str_replace('&nbsp;','',str_replace($template_variables,$template_values,$to_emails)); $to_emails = str_replace('&nbsp;','',str_replace($template_variables,$template_values,$to_emails));
$email_address = explode(',',$to_emails); $email_address = explode(',',$to_emails);
$has_email = false; $has_email = false;
foreach ($email_address as $email){ foreach ($email_address as $email){
$email = trim($email); $email = trim($email);
if(!empty($email)){ if(!empty($email)){
@ -480,35 +480,35 @@ EOT;
$has_email = true; $has_email = true;
} }
} }
if($has_email){ if($has_email){
$send_status = $mail->Send(); $send_status = $mail->Send();
$mail->ClearAddresses(); $mail->ClearAddresses();
if($send_status !== true){ if($send_status !== true){
echo "Error sending email: ".$mail->ErrorInfo; echo "Error sending email: ".$mail->ErrorInfo;
} }
} }
} }
function get_ssl_suffix(){ function get_ssl_suffix(){
if(!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')){ if(!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')){
$ssl_suffix = 's'; $ssl_suffix = 's';
}else{ }else{
$ssl_suffix = ''; $ssl_suffix = '';
} }
return $ssl_suffix; return $ssl_suffix;
} }
function get_dirname($path){ function get_dirname($path){
$current_dir = dirname($path); $current_dir = dirname($path);
if($current_dir == "/" || $current_dir == "\\"){ if($current_dir == "/" || $current_dir == "\\"){
$current_dir = ''; $current_dir = '';
} }
return $current_dir; return $current_dir;
} }
?> ?>