diff --git a/includes/helper-functions.php b/includes/helper-functions.php index 35ba3cf..b3c7eb0 100644 --- a/includes/helper-functions.php +++ b/includes/helper-functions.php @@ -1,21 +1,21 @@ 0) { // over a month old, just show date ("Month, Day Year") @@ -77,22 +77,22 @@ // seconds only $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':''); } - + // show relative date and add proper verbiage return $relative_date.' ago'; } - + } - + //this function accept 'YYYY-MM-DD HH:MM:SS' function short_relative_date($input_date) { - + $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); $year = substr($posted_date,0,4); - + if ($month == "02") { // february // check for leap year $leapYear = isLeapYear($year); @@ -101,14 +101,14 @@ } else { // not february // check to see if the month has 30/31 days in it - if ($month == "04" or - $month == "06" or - $month == "09" or + if ($month == "04" or + $month == "06" or + $month == "09" or $month == "11") $month_in_seconds = 2592000; // 30 day month else $month_in_seconds = 2678400; // 31 day month; } - + $in_seconds = strtotime(substr($posted_date,0,8).' '. substr($posted_date,8,2).':'. substr($posted_date,10,2).':'. @@ -125,10 +125,10 @@ $minutes = floor($diff/60); $diff -= $minutes*60; $seconds = $diff; - + $relative_date = ''; if ($months>0) { - + // over a month old if(!empty($input_date)){ if($year < date('Y')){ //over a year, show international date @@ -136,7 +136,7 @@ }else{ //less than a year return date('M j',strtotime($input_date)); } - + }else{ return ''; } @@ -160,17 +160,17 @@ // seconds only $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':''); } - + // show relative date and add proper verbiage return $relative_date.' ago'; } - + } - + function isLeapYear($year) { return $year % 4 == 0 && ($year % 400 == 0 || $year % 100 != 0); } - + //remove a folder and all it's content function full_rmdir($dirname){ if ($dirHandle = opendir($dirname)){ @@ -199,80 +199,80 @@ //show success or error messages function show_message(){ - + if(!empty($_SESSION['AP_ERROR'])){ if(!empty($_SESSION['AP_ERROR']['desc'])){ $error_desc = '

'.$_SESSION['AP_ERROR']['desc'].'

'; }else{ $error_desc = ''; } - + $ul_markup =<<
  • {$_SESSION['AP_ERROR']['title']}  

    {$error_desc} -
  • + EOT; echo $ul_markup; - + $_SESSION['AP_ERROR'] = array(); unset($_SESSION['AP_ERROR']); } - + if(!empty($_SESSION['AP_SUCCESS'])){ if(!empty($_SESSION['AP_SUCCESS']['desc'])){ $success_desc = '

    '.$_SESSION['AP_SUCCESS']['desc'].'

    '; }else{ $success_desc = ''; } - + $ul_markup =<<
  • {$_SESSION['AP_SUCCESS']['title']} 

    {$success_desc} -
  • + EOT; echo $ul_markup; - + $_SESSION['AP_SUCCESS'] = array(); unset($_SESSION['AP_SUCCESS']); } - + } - + //send notification email //$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){ - + $from_name = $email_param['from_name']; $from_email = $email_param['from_email']; $subject = $email_param['subject']; $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 $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 if($target_is_admin === false){ $options['strip_download_link'] = true; } - + $options['strip_checkbox_image'] = true; $options['machform_base_path'] = $email_param['machform_base_path']; //the path to machform $entry_details = get_entry_details($form_id,$entry_id,$options); - + //populate field values to template variables $i=0; foreach ($entry_details as $data){ $template_variables[$i] = '{element_'.$data['element_id'].'}'; $template_values[$i] = $data['value']; - + if($data['element_type'] == 'textarea'){ $template_values[$i] = nl2br($data['value']); }elseif ($data['element_type'] == 'file'){ @@ -284,25 +284,25 @@ EOT; }else{ $template_values[$i] = $data['value']; } - + $i++; } - + //get entry timestamp $query = "select date_created,ip_address from `ap_form_{$form_id}` where id='$entry_id'"; $result = do_query($query); $row = do_fetch_result($result); - + $date_created = $row['date_created']; $ip_address = $row['ip_address']; - + //get form name $query = "select form_name from `ap_forms` where form_id='$form_id'"; $result = do_query($query); $row = do_fetch_result($result); $form_name = $row['form_name']; - - + + $template_variables[$i] = '{date_created}'; $template_values[$i] = $date_created; $i++; @@ -317,58 +317,58 @@ EOT; $i++; $template_variables[$i] = '{form_id}'; $template_values[$i] = $form_id; - - + + //compose {entry_data} based on 'as_plain_text' preferences $email_body = ''; if(!$as_plain_text){ //compose html format $email_body = ''."\n"; - + $toggle = false; foreach ($entry_details as $data){ //0 should be displayed, empty string don't if((empty($data['value']) || $data['value'] == ' ') && $data['value'] !== 0 && $data['value'] !== '0'){ continue; - } - + } + if($toggle){ $toggle = false; $row_style = 'style="background-color:#F3F7FB"'; }else{ $toggle = true; $row_style = ''; - } - + } + if($data['element_type'] == 'textarea'){ $data['value'] = nl2br($data['value']); }elseif ($data['element_type'] == 'file'){ - + if($target_is_admin === false){ $data['value'] = strip_tags($data['value']); }else{ $data['value'] = strip_tags($data['value'],''); } } - + $email_body .= "\n"; $email_body .= ''."\n"; $email_body .= ''."\n"; - $email_body .= ''."\n"; - + $email_body .= ''."\n"; + $i++; } $email_body .= "
    '.$data['label'].' '.$data['value'].'
    \n"; }else{ - + //compose text format foreach ($entry_details as $data){ - + //0 should be displayed, empty string don't if((empty($data['value']) || $data['value'] == ' ') && $data['value'] !== 0 && $data['value'] !== '0'){ continue; } - + if($data['element_type'] == 'textarea'){ $email_body .= "{$data['label']}
    ".nl2br($data['value'])."

    \n"; }elseif ($data['element_type'] == 'checkbox' || $data['element_type'] == 'address'){ @@ -384,38 +384,38 @@ EOT; }else{ $email_body .= "{$data['label']} - {$data['value']}
    \n"; } - - + + } } - + $i = count($template_variables); $template_variables[$i] = '{entry_data}'; $template_values[$i] = $email_body; - + $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; $mail->Host = "127.0.0.1"; $mail->IsHTML(true); - $mail->Mailer = "mail"; + $mail->Mailer = "mail"; $mail->SMTPAuth = false; - + if(USE_SMTP === true){ $mail->Mailer = "smtp"; $mail->Host = SMTP_HOST; $mail->Port = SMTP_PORT; - + if(SMTP_AUTH === true){ - $mail->SMTPAuth = true; + $mail->SMTPAuth = true; $mail->Username = SMTP_USERNAME; $mail->Password = SMTP_PASSWORD; } - + if(SMTP_SECURE === true){ $mail->SMTPSecure = 'tls'; } } - + //parse from_name template if(!empty($from_name)){ $from_name = str_replace($template_variables,$template_values,$from_name); @@ -423,12 +423,12 @@ EOT; }elseif (NOTIFICATION_MAIL_FROM_NAME != ''){ $mail->FromName = utf8_encode(str_replace(' ','',str_replace($template_variables,$template_values,NOTIFICATION_MAIL_FROM_NAME))); }else{ - $mail->FromName = 'MachForm'; + $mail->FromName = ''; } - + //decode any html entity $mail->FromName = html_entity_decode($mail->FromName,ENT_QUOTES); - + //parse from_email_address template if(!empty($from_email)){ $from_email = str_replace($template_variables,$template_values,$from_email); @@ -439,7 +439,7 @@ EOT; $domain = str_replace('www.','',$_SERVER['SERVER_NAME']); $mail->From = "no-reply@{$domain}"; } - + //parse subject template if(!empty($subject)){ $subject = str_replace($template_variables,$template_values,$subject); @@ -455,24 +455,24 @@ EOT; } //decode any html entity $mail->Subject = html_entity_decode($mail->Subject,ENT_QUOTES); - - + + //parse content template $email_content = str_replace($template_variables,$template_values,$content); - + //add footer - $email_content .= "




    Powered by
    MachForm"; - + $email_content .= "




    "; + //enclose with container div $email_content = '
    '.$email_content.'
    '; - + $mail->Body = $email_content; - + //send email $to_emails = str_replace(' ','',str_replace($template_variables,$template_values,$to_emails)); $email_address = explode(',',$to_emails); - - $has_email = false; + + $has_email = false; foreach ($email_address as $email){ $email = trim($email); if(!empty($email)){ @@ -480,35 +480,35 @@ EOT; $has_email = true; } } - + if($has_email){ $send_status = $mail->Send(); $mail->ClearAddresses(); - + if($send_status !== true){ echo "Error sending email: ".$mail->ErrorInfo; } } } - + function get_ssl_suffix(){ if(!empty($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off')){ $ssl_suffix = 's'; }else{ $ssl_suffix = ''; } - + return $ssl_suffix; } - + function get_dirname($path){ $current_dir = dirname($path); - + if($current_dir == "/" || $current_dir == "\\"){ $current_dir = ''; } - + return $current_dir; } - + ?> \ No newline at end of file