<?php /* **************************************************************************** *** *** *** ViArt Shop 4.0.5 *** *** File: shopping_cart.php *** *** Built: Fri Jan 28 01:45:24 2011 *** *** http://www.viart.com *** *** *** **************************************************************************** */ $eol = get_eol(); $sc_errors = ""; $sc_message = ""; $sc_item_id = ""; $cart = get_param("cart"); $cart_id = get_param("cart_id"); if ($cart) { $placed_ids = get_session("placed_ids"); if (!is_array($placed_ids)) { $placed_ids = array(); } $random_id = get_param("rnd"); //-- checking if such page has been already called if (!strlen($random_id) || !isset($placed_ids[$random_id])) { if ($cart != "SHIPPING") { // allow to add items for shipping calculations $placed_ids[$random_id] = $random_id; } switch (strtoupper($cart)) {
function va_mail($mail_to, $mail_subject, $mail_body, $mail_headers = "", $attachments = "") { global $settings; if (!strlen($mail_to)) { return false; } $mail_type = get_setting_value($mail_headers, "mail_type", 0); $mail_from = get_setting_value($mail_headers, "from", $settings["admin_email"]); $email_additional_headers = get_setting_value($settings, "email_additional_headers", ""); $email_additional_parameters = get_setting_value($settings, "email_additional_parameters", ""); $eol = get_eol(); // set additional mail headers $add_mail_headers = preg_split("/[\r\n]+/", $email_additional_headers, -1, PREG_SPLIT_NO_EMPTY); foreach ($add_mail_headers as $header) { $header = explode(":", $header); if (sizeof($header) == 2) { $mail_headers = array_merge(array(trim($header[0]) => trim($header[1])), $mail_headers); } } if (is_array($attachments) && sizeof($attachments) > 0) { $boundary = "--va_" . md5(va_timestamp()) . "_" . va_timestamp(); $mail_headers["Content-Type"] = "multipart/mixed; boundary=\"" . $boundary . "\""; if (isset($mail_headers["mail_type"])) { unset($mail_headers["mail_type"]); } $original_body = $mail_body; $mail_body = "This is a multi-part message in MIME format." . $eol . $eol; $mail_body .= "--" . $boundary . $eol; if ($mail_type) { $mail_body .= "Content-Type: text/html;" . $eol; } else { $mail_body .= "Content-Type: text/plain;" . $eol; } $mail_body .= "\tcharset=\"" . CHARSET . "\"" . $eol; $mail_body .= "Content-Transfer-Encoding: 7bit" . $eol; $mail_body .= $eol; $mail_body .= $original_body; $mail_body .= $eol . $eol; for ($at = 0; $at < sizeof($attachments); $at++) { $attachment_info = $attachments[$at]; if (!is_array($attachment_info)) { $filepath = $attachment_info; $attachment_info = array(basename($filepath), $filepath, ""); } elseif (sizeof($attachment_info) == 1) { $filepath = $attachment_info[0]; $attachment_info = array(basename($filepath), $filepath, ""); } $filename = $attachment_info[0]; if (!$filename) { $filename = basename($filepath); } if (!$filename) { $filename = "noname.txt"; } $filepath = $attachment_info[1]; $filetype = isset($attachment_info[2]) ? $attachment_info[2] : ""; if (preg_match("/^(http|https|ftp|ftps):\\/\\//", $filepath)) { $is_remote_file = true; } else { $is_remote_file = false; } $filebody = ""; if ($filetype == "pdf") { $filebody = $pdf->get_buffer(); } elseif ($filetype == "buffer") { $filebody = $filepath; } elseif ($filetype == "fp") { // read entire file from file pointer while (!feof($fp)) { $filebody .= fread($fp, 8192); } } elseif ($is_remote_file || @file_exists($filepath) && !@is_dir($filepath)) { // read entire file into filebody $fp = fopen($filepath, "rb"); while (!feof($fp)) { $filebody .= fread($fp, 8192); } fclose($fp); } if ($filebody) { $file_base64 = chunk_split(base64_encode($filebody)); $mail_body .= "--" . $boundary . $eol; if (preg_match("/\\.gif\$/", $filename)) { $mail_body .= "Content-Type: image/gif;" . $eol; } elseif (preg_match("/\\.pdf\$/", $filename)) { $mail_body .= "Content-Type: application/pdf;" . $eol; } else { $mail_body .= "Content-Type: application/octet-stream;" . $eol; } $mail_body .= "\tname=\"" . $filename . "\"" . $eol; $mail_body .= "Content-Transfer-Encoding: base64" . $eol; $mail_body .= "Content-Disposition: attachment;" . $eol; $mail_body .= "\tfilename=\"" . $filename . "\"" . $eol; $mail_body .= $eol; $mail_body .= $file_base64; $mail_body .= $eol . $eol; } } // end multipart message $mail_body .= "--" . $boundary . "--" . $eol; $mail_body .= $eol; } else { $mail_headers["mail_type"] = $mail_type; } $smtp_mail = get_setting_value($settings, "smtp_mail", 0); if ($smtp_mail) { $smtp_host = get_setting_value($settings, "smtp_host", "127.0.0.1"); $smtp_port = get_setting_value($settings, "smtp_port", 25); $smtp_timeout = get_setting_value($settings, "smtp_timeout", 30); $smtp_username = get_setting_value($settings, "smtp_username", ""); $smtp_password = get_setting_value($settings, "smtp_password", ""); $errors = ""; $socket = @fsockopen($smtp_host, $smtp_port, $errno, $error, $smtp_timeout); if (!$socket) { $errors = $error; return false; } // read server reply $response = smtp_check_response($socket, 220, $error); if ($error) { $errors = $error; return false; } $smtp_username = get_setting_value($settings, "smtp_username", ""); $smtp_password = get_setting_value($settings, "smtp_password", ""); if (strlen($smtp_username) && strlen($smtp_password)) { fputs($socket, "EHLO " . $smtp_host . "\r\n"); smtp_check_response($socket, "250", $error); $errors .= $error; fputs($socket, "AUTH LOGIN\r\n"); smtp_check_response($socket, "334", $error); $errors .= $error; fputs($socket, base64_encode($smtp_username) . "\r\n"); smtp_check_response($socket, "334", $error); $errors .= $error; fputs($socket, base64_encode($smtp_password) . "\r\n"); smtp_check_response($socket, "235", $error); $errors .= $error; } else { fputs($socket, "HELO " . $smtp_host . "\r\n"); smtp_check_response($socket, "250", $error); $errors .= $error; } if ($errors) { return false; } fputs($socket, "MAIL FROM: <" . $mail_from . ">\r\n"); smtp_check_response($socket, "250", $error); if ($error) { $errors = $error; return false; } if (!isset($mail_headers["to"])) { $mail_headers["to"] = $mail_to; } $header_names = array("to", "cc", "bcc"); for ($hf = 0; $hf < sizeof($header_names); $hf++) { $recipients_string = get_setting_value($mail_headers, $header_names[$hf], ""); $recipients_string = str_replace(";", ",", $recipients_string); if ($recipients_string) { $recipients_values = explode(",", $recipients_string); for ($i = 0; $i < sizeof($recipients_values); $i++) { $recipient_email = ""; $recipient_value = $recipients_values[$i]; if (preg_match("/<([^@]+@[^@]+(\\.[^@]+)*\\.[a-z]+)>/i", $recipient_value, $match)) { $recipient_email = $match[1]; } elseif (preg_match("/\\s*([^@]+@[^@]+(\\.[^@]+)*\\.[a-z]+)\\s*/i", $recipient_value, $match)) { $recipient_email = trim($match[1]); } if ($recipient_email) { fputs($socket, "RCPT TO: <" . $recipient_email . ">\r\n"); smtp_check_response($socket, "250", $error); $errors .= $error; } } } } if ($errors) { return false; } // Preparing for sending data fputs($socket, "DATA\r\n"); smtp_check_response($socket, "354", $error); if ($error) { $errors = $error; return false; } // Send subject fputs($socket, "Subject: " . $mail_subject . "\r\n"); // Add other headers $headers_string = email_headers_string($mail_headers, "\r\n"); fputs($socket, $headers_string . "\r\n\r\n"); // Send the mail body fputs($socket, $mail_body . "\r\n.\r\n"); smtp_check_response($socket, "250", $error); if ($error) { $errors = $error; return false; } fputs($socket, "QUIT\r\n"); fclose($socket); return true; } else { $headers_string = email_headers_string($mail_headers); $safe_mode = strtolower(ini_get("safe_mode")) == "on" || intval(ini_get("safe_mode")) == 1 ? true : false; if ($safe_mode) { return @mail($mail_to, $mail_subject, $mail_body, $headers_string); } else { return @mail($mail_to, $mail_subject, $mail_body, $headers_string, $email_additional_parameters); } } }