<?php
function sendEmail($to, $subject, $message, $from='', $extra_headers, $is_html, $is_queued=0) {
global $custom_vars;
if ($from != '') {
$headers .= "From: " . $from;
}
if ($is_html == 1) {
if ($headers != '') {
$newline = "\n";
} else {
$newline = "";
}
$headers = $headers . $newline . "Content-type: text/html; charset=iso-8859-1";
}
if ($extra_headers != '') {
if ($headers != '') {
$newline = "\n";
} else {
$newline = "";
}
$headers = $headers . $newline . $extra_headers;
}
if ($custom_vars['email_use_queue'] == 1 && $is_queued == 0) {
if ($insert_query = mysql_query('
INSERT INTO ibd_email_queue
SET ibd_email_queue_to = "' . $to .'",
ibd_email_queue_date = "' . date('Y-m-d H:i:s') . '",
ibd_email_queue_subject = "' . magic_quote_alter($subject) . '",
ibd_email_queue_content = "' . magic_quote_alter($message) .'",
ibd_email_queue_is_html = "' . $is_html .'",
ibd_email_queue_headers = "' . magic_quote_alter($headers) . '"')) {
return true;
}
} else {
//echo 'To:' . $to . '<br>' . 'Subject:' . $subject . '<br>' . 'message:' . $message . '<br>' . 'headers:' . $headers . '<br>';
if (mail($to,$subject,$message,$headers)) {
return true;
} else {
return false;
}
}
}
function validateEmail($email) {
if (eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$', $email)) {
return false;
} else {
return true;
}
}
function textSettingInput($name,$size,$value,$prefix='',$appendix='',$max_length='') {
if ($max_length != '') {
$max_length = ' maxlength="' . $max_length . '" ';
}
if ($value == '0000-00-00 00:00:00') {
$value = '';
}
$value = htmlspecialchars($value);
if ($value != '') {
$value = 'value="' . $value . '"';
}
$input = $prefix . '<input type="text" name="' . $name . '"' . $max_length . ' size="' . $size . '" ' . $value . ' />' . $appendix;
return $input;
}
function passwordInput($name,$size,$value,$max_length='') {
if ($max_length != '') {
$max_length = ' maxlength="' . $max_length . '" ';
}
if ($value != '') {
$value = 'value="' . $value . '"';
}
$input = '<input type="password" name="' . $name . '"' . $max_length . ' size="' . $size . '" ' . $value . ' />';
return $input;
}
function textareaSettingInput($name,$value,$cols=50,$rows=3,$add_wysiwyg=0,$count='') {
if ($add_wysiwyg == 1) {
$class = ' convert_this="true" ';
}
if ($count != '') {
$count = ' onkeyup="countChars(\'' . $name . '\', \'' . $name . '_count_div\', ' . $count . ')" ';
$count_div = '<div id="' . $name . '_count_div"> </div>';
}
$input = '<textarea id="' . $name .'" ' .$class . $count . ' name="' . $name . '" cols="' . $cols . '" rows="' . $rows . '"/>' . htmlspecialchars($value) . '</textarea>' . $count_div;
return $input;
}
function selectInput($table,$value_column,$display_column,$selected_value,$add_blank = 0,$formatting='',$name='') {
if ($name == '') {
$name = $value_column;
}
$result = mysql_query('
SELECT *
FROM ' . $table);
while ($row = mysql_fetch_array($result)) {
if ($row[$value_column] == $selected_value) {
$selected = ' selected ';
} else {
$selected = '';
}
if ($formatting == 'price') {
$display = '$' . number_format($row[$display_column]);
} else {
$display = $row[$display_column];
}
$select_box .= '<option value="' . $row[$value_column] . '" ' . $selected . '>' . $display . '</option>';
}
if ($add_blank == 1) {
$select_box = '<option value=""></option>' . $select_box;
}
$select_box = '<select name="' . $name . '">' . $select_box . '</select>';
return $select_box;
}
function selectInputFromValues($name,$values,$selected_value,$add_blank = 0,$formatting='') {
$values = str_replace("\n",'',$values);
if (strpos($values,',')) {
$value_array = explode(',',$values);
} else {
$value_array[0] = $values;
}
$i = 0;
while ($value_array[$i] != '') {
if (strpos($value_array[$i],':')) {
$value_pair = explode(':',$value_array[$i]);
$value = trim($value_pair[0]);
$display = trim($value_pair[1]);
} else {
$value = trim($value_array[$i]);
$display = trim($value_array[$i]);
}
if ($value == $selected_value) {
$selected = ' selected ';
} else {
$selected = '';
}
if ($formatting == 'price') {
$display = '$' . number_format($display);
}
$select_box .= '<option value="' . $value . '" ' . $selected . '>' . $display . '</option>';
$i++;
}
if ($add_blank == 1) {
$select_box = '<option value=""></option>' . $select_box;
}
$select_box = '<select name="' . $name . '">' . $select_box . '</select>';
return $select_box;
}
function checkboxSettingInput($name,$value,$checked='') {
if ($value == 1) {
$checked = ' checked ';
}
$input = '<input type="checkbox" name="' . $name . '" value="1" ' . $checked . ' />';
return $input;
}
function sendQueuedMail() {
global $custom_vars;
if ($custom_vars['email_queue_use_cron'] != 1) {
$now = time();
$custom_time = strtotime($custom_vars['email_queue_date_last_reset_custom']);
$custom_duration = multiplyFromString($custom_vars['email_queue_custom_duration']);
$custom_count = $custom_vars['email_queue_custom_count'];
$day_count = $custom_vars['email_queue_24_hour_count'];
$elapsed = $now-$custom_time;
if ($elapsed > $custom_duration) {
// Reset Custom Timer
updateCustomSetting('email_queue_date_last_reset_custom',date('Y-m-d H:i:s'));
updateCustomSetting('email_queue_custom_count',0);
$custom_count = 0;
}
$day_time = strtotime($custom_vars['email_queue_date_last_reset_24_hour']);
$day_duration = 60;
$elapsed = $now-$day_time;
if ($elapsed > $day_duration) {
// Reset Day Timer
updateCustomSetting('email_queue_date_last_reset_24_hour',date('Y-m-d H:i:s'));
updateCustomSetting('email_queue_24_hour_count',0);
$day_count = 0;
}
if (($day_count < $custom_vars['email_queue_max_per_day']) && ($custom_count < $custom_vars['email_queue_custom_duration_max'])) {
$mail_result = mysql_query('
SELECT *
FROM ibd_email_queue
ORDER BY ibd_email_queue_id ASC
LIMIT 10');
while ($row = mysql_fetch_array($mail_result)) {
if (($day_count < $custom_vars['email_queue_max_per_day']) && ($custom_count < $custom_vars['email_queue_custom_duration_max'])) {
$to = $row['ibd_email_queue_to'];
$subject = $row['ibd_email_queue_subject'];
$message = $row['ibd_email_queue_content'];
$extra_headers = $row['ibd_email_queue_headers'];
$is_html = $row['ibd_email_queue_is_html'];
if (sendEmail($to, $subject, $message, $from, $extra_headers, $is_html, 1)) {
// Delete the e-mail in queue
$delete = mysql_query('
DELETE
FROM ibd_email_queue
WHERE ibd_email_queue_id = "' . $row['ibd_email_queue_id'] . '"');
$custom_count++;
$day_count++;
}
}
}
updateCustomSetting('email_queue_custom_count',$custom_count);
updateCustomSetting('email_queue_24_hour_count',$day_count);
}
}
}
if(!function_exists('str_split')){
function str_split($str,$length=1){
$cnt = strlen($str);
for ($i=0; $i<$cnt; $i+=$length) {
$array[]= substr($str,$i,$length);
}
return $array;
}
}
function checkValidChars($string,$valid_chars) {
$string_array = str_split($string);
$valid_chars_array = str_split($valid_chars);
$i = 0;
while ($string_array[$i] != '') {
if (!in_array($string_array[$i],$valid_chars_array)) {
return false;
}
$i++;
}
return true;
}
?>