<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/

// ******************************************************************************************
// SKLADANIE ZAMOWIENIA
//******************************************************************************************
  //
  $temat = MakeUTF(EMAIL_TEXT_SUBJECT_TWO) . ' - ' . $oID;
  $owner = MakeUTF(STORE_NAME);
  $adresat = MakeUTF($order->customer['name']);

  // GENEROWANIE TRESCI MAILA
  if (EMAIL_USE_HTML == 'true') {
        $ArrayLNTargets = array("\r\n", "\n\r", "\n", "\r", "\t");
        //
        $email_order = '
        <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr><td align="left" style="font-family:Tahoma,Arial;font-size:16px;color:#4f7d13"><b>'.UHE_TEXT_DEAR.' '.$order->customer['name'].'</b></td></tr>
        <tr><td align="left" style="font-family:Tahoma,Arial;font-size:11px;color:#474747">'.EMAIL_WARNING.'</td></tr>
        </table>
        <table border="0" cellspacing="0" cellpadding="5" width="100%">
            <tr><td align="left" style="font-family:Tahoma,Arial;font-size:12px;color:#474747">'.
            UHE_TEXT_ORDER_NUMBER.' <b>'.$oID.'</b><br>'.
            //UHE_TEXT_INVOICE_URL.' <b>'.tep_href_link('account_history_info.php', 'order_id=' . $oID, 'SSL', false).'</b><br>'.
            UHE_TEXT_INVOICE_URL.' <b>'.tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $oID, 'SSL').'</b><br>'.
            UHE_TEXT_DATE_ORDERED.' <b>'.strftime(DATE_FORMAT_LONG).'</b></td></tr>';
            // komentarz do zamowienia
            if ($order->info['comments']) {
                $email_order .= '<tr><td align="left" style="font-family:Tahoma,Arial;font-size:12px;color:#474747">';
                $email_order .= '<br><b>'.UHE_TEXT_COMMENTS.'</b><br>'. str_replace($ArrayLNTargets, '<br>', tep_db_output($order->info['comments']));
                $email_order .= '</td></tr>';
            }
            $email_order .= '
            <tr><td align="left" style="font-family:Tahoma,Arial;font-size:12px;color:#474747"><br>'.UHE_TEXT_ORDER_CONTENTS.'</td></tr>
            <tr><td align="left">
                <table cellspacing="3" width="100%" cellpadding="2" style="border:1px;border-style:solid;border-color:#868785">
    				<tr>
    					<td align="left" style="background-color:#bbd1bc;font-family:Tahoma,Arial;font-size:12px;color:#474747">'.UHE_TEXT_PRODUCTS_ARTICLE.'</td>
    					<td align="center" style="background-color:#bbd1bc;font-family:Tahoma,Arial;font-size:12px;color:#474747">'.UHE_TEXT_PRODUCTS_MODEL.'</td>
    					<td align="center" style="background-color:#bbd1bc;font-family:Tahoma,Arial;font-size:12px;color:#474747">'.UHE_TEXT_PRODUCTS_PRICE.'</td>
    					<td align="center" style="background-color:#bbd1bc;font-family:Tahoma,Arial;font-size:12px;color:#474747">'.UHE_TEXT_PRODUCTS_QTY.'</td>
    					<td align="center" style="background-color:#bbd1bc;font-family:Tahoma,Arial;font-size:12px;color:#474747">'.UHE_TEXT_PRODUCTS_TOTAL.'</td>
    				</tr>'.$products_ordered_html.'
                </table>
            </td></tr>
        </table>';

        $email_order .= '
        <table border="0" cellspacing="0" cellpadding="5" width="100%">
            <tr><td align="left" style="font-family:Tahoma,Arial;font-size:12px;color:#474747">
                <table cellspacing="3" cellpadding="3" style="border:1px;border-style:solid;border-color:#868785">';
                	for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
                		$temp_title = trim(strip_tags($order->totals[$i]['title']));
                		if(substr($temp_title, -1) == ':'): $temp_title = substr($temp_title, 0, -1); endif;
                		$email_order .= '<tr><td align="left" style="background-color:#f0f0f0;font-family:Tahoma,Arial;font-size:12px;color:#474747">'.$temp_title .'</td><td align="right" style="background-color:#f0f0f0;font-family:Tahoma,Arial;font-size:12px;color:#474747"><b>' . strip_tags($order->totals[$i]['text']) . "</b></td></tr>";
                	}
                $email_order .= '</table>';
        $email_order .= '</td></tr></table>';

        $email_order .= '
        <table border="0" cellspacing="0" cellpadding="5" width="100%">
            <tr><td align="left" style="font-family:Tahoma,Arial;font-size:12px;color:#474747">';
            $email_order .= '<b>'.UHE_TEXT_PAYMENT_METHOD . ': </b>'. $order->info['payment_method'];
            $email_order .= '</td></tr></table>';

        $email_order .='<table border="0" cellspacing="0" cellpadding="5">
            <tr><td align="left">
                <table cellspacing="3" width="100%" cellpadding="5" style="border:1px;border-style:solid;border-color:#868785">
                    <tr>';
                        if ($order->content_type != 'virtual') {
                            $email_order .= '<td align="left" style="background-color:#bbd1bc;font-family:Tahoma,Arial;font-size:13px;color:#474747">'. UHE_TEXT_DELIVERY_ADDRESS .'</td>';
                        }
                        $email_order .= '<td align="left" style="background-color:#bbd1bc;font-family:Tahoma,Arial;font-size:13px;color:#474747">'. UHE_TEXT_BILLING_ADDRESS .'</td>
                    </tr>
                    <tr>';
                        if ($order->content_type != 'virtual') {
                            $email_order .= '<td align="left" style="background-color:#f0f0f0;font-family:Tahoma,Arial;font-size:13px;color:#474747">';
                        	$email_order .= $order->delivery['name'] . "<br>";
                    						if ($order->delivery['company']) {
                    		                  $email_order .= $order->delivery['company'] . "<br>";
                    	                    }
                    						if ($order->delivery['nip']) {
                    		                  $email_order .= $order->delivery['nip'] . "<br>";
                    	                    }
                    		$email_order .= $order->delivery['street_address'] . "<br>";
                    		                if ($order->delivery['suburb']) {
                    		                  $email_order .= $order->delivery['suburb'] . "<br>";
                    	                    }
                    		$email_order .= $order->customer['city'] . "<br>";
                    		                if ($order->delivery['state']) {
                    		                  $email_order .= $order->delivery['state'] . "<br>";
                    	                    }
                    		$email_order .= $order->customer['postcode'] . "<br>" .
                    						$order->delivery['country'];
                            $email_order .= '</td>';
                        }
                        $email_order .= '<td align="left" style="background-color:#f0f0f0;font-family:Tahoma,Arial;font-size:13px;color:#474747">';
                    	$email_order .= $order->billing['name'] . "<br>";
                						if ($order->billing['company']) {
                		                  $email_order .= $order->billing['company'] . "<br>";
                	                    }
                						if ($order->billing['nip']) {
                		                  $email_order .= $order->billing['nip'] . "<br>";
                	                    }
                		$email_order .= $order->billing['street_address'] . "<br>";
                		                if ($order->billing['suburb']) {
                		                  $email_order .= $order->billing['suburb'] . "<br>";
                	                    }
                		$email_order .= $order->customer['city'] . "<br>";
                		                if ($order->billing['state']) {
                		                  $email_order .= $order->billing['state'] . "<br>";
                	                    }
                		$email_order .= $order->customer['postcode'] . "<br>" .
                						$order->billing['country'];
                        $email_order .= '</td>
                    </tr>
                </table>
            </td></tr>
        </table>';
        $email_order = str_replace($ArrayLNTargets, '', $email_order);
        $email_order = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $email_order);
     } else {
       $email_order = STORE_NAME . "\n" .
                        EMAIL_SEPARATOR . "\n" .
                        EMAIL_TEXT_ORDER_NUMBER . ' ' . (int)$oID . "\n" .
                        EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . (int)$oID, 'SSL') . "\n" .
                        EMAIL_TEXT_DATE_MODIFIED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";

       $email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
                        EMAIL_SEPARATOR . "\n" .
                        $products_ordered .
                        EMAIL_SEPARATOR . "\n";

	   for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
        $email_order .= strip_tags($order->totals[$i]['title']) . ' ' . strip_tags($order->totals[$i]['text']) . "\n";
       }

	   if ($order->content_type != 'virtual') {
    	$email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" .
        	            EMAIL_SEPARATOR . "\n" .
						$order->delivery['name'] . "\n";
						if ($order->delivery['company']) {
		                  $email_order .= $order->delivery['company'] . "\n";
	                    }
						if ($order->delivery['nip']) {
		                  $email_order .= $order->delivery['nip'] . "\n";
	                    }
		$email_order .= $order->delivery['street_address'] . "\n";
		                if ($order->delivery['suburb']) {
		                  $email_order .= $order->delivery['suburb'] . "\n";
	                    }
		$email_order .= $order->customer['city'] . "\n";
		                if ($order->delivery['state']) {
		                  $email_order .= $order->delivery['state'] . "\n";
	                    }
		$email_order .= $order->customer['postcode'] . "\n" .
						$order->delivery['country'] . "\n";
	  }

    	$email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
        	            EMAIL_SEPARATOR . "\n" .
						$order->billing['name'] . "\n";
						if ($order->billing['company']) {
		                  $email_order .= $order->billing['company'] . "\n";
	                    }
						if ($order->billing['nip']) {
		                  $email_order .= $order->billing['nip'] . "\n";
	                    }
		$email_order .= $order->billing['street_address'] . "\n";
		                if ($order->billing['suburb']) {
		                  $email_order .= $order->billing['suburb'] . "\n";
	                    }
		$email_order .= $order->customer['city'] . "\n";
		                if ($order->billing['state']) {
		                  $email_order .= $order->billing['state'] . "\n";
	                    }
		$email_order .= $order->customer['postcode'] . "\n" .
						$order->billing['country'] . "\n\n";

	    $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
    	                EMAIL_SEPARATOR . "\n";
	    $email_order .= $order->info['payment_method'] . "\n\n";
        if (EMAIL_TEXT_FOOTER) {
            $email_order .= EMAIL_TEXT_FOOTER . "\n\n";
        }
  }
  tep_mail($adresat, $order->customer['email_address'], $temat, html_entity_decode($email_order), $owner, STORE_OWNER_EMAIL_ADDRESS);
  // wysylanie od innych administratorw kopii
  if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
    tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $temat, html_entity_decode($email_order), $owner, STORE_OWNER_EMAIL_ADDRESS);
  }
?>