<?php

/**
 * @file
 * This file is the default customer invoice template for Ubercart.
 *
 * Available variables:
 * - $products: An array of product objects in the order, with the following
 *   members:
 *   - title: The product title.
 *   - model: The product SKU.
 *   - qty: The quantity ordered.
 *   - total_price: The formatted total price for the quantity ordered.
 *   - individual_price: If quantity is more than 1, the formatted product
 *     price of a single item.
 *   - details: Any extra details about the product, such as attributes.
 * - $line_items: An array of line item arrays attached to the order, each with
 *   the following keys:
 *   - line_item_id: The type of line item (subtotal, shipping, etc.).
 *   - title: The line item display title.
 *   - formatted_amount: The formatted amount of the line item.
 * - $shippable: TRUE if the order is shippable.
 *
 * Tokens: All site, store and order tokens are also available as
 * variables, such as $site_logo, $store_name and $order_first_name.
 *
 * Display options:
 * - $op: 'view', 'print', 'checkout-mail' or 'admin-mail', depending on
 *   which variant of the invoice is being rendered.
 * - $business_header: TRUE if the invoice header should be displayed.
 * - $shipping_method: TRUE if shipping information should be displayed.
 * - $help_text: TRUE if the store help message should be displayed.
 * - $email_text: TRUE if the "do not reply to this email" message should
 *   be displayed.
 * - $store_footer: TRUE if the store URL should be displayed.
 * - $thank_you_message: TRUE if the 'thank you for your order' message
 *   should be displayed.
 *
 * @see template_preprocess_uc_order()
 */
 // include drupal_realpath(file_build_uri('')).'/phpqrcode/qrlib.php';

?>
<table width="95%" border="0" cellspacing="0" cellpadding="1" align="center" bgcolor="#006699" style="font-family: verdana, arial, helvetica; font-size: small;">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="#FFFFFF" style="font-family: verdana, arial, helvetica; font-size: small;">
        <?php if ($business_header): ?>
        <tr valign="top">
          <td>
            <table width="100%" style="font-family: verdana, arial, helvetica; font-size: small;">
              <tr>
                <td>
                  <?php print $site_logo; ?>
                </td>
                <td width="98%">
                  <div style="padding-left: 1em;">
                  <span style="font-size: large;"><?php print $store_name; ?></span><br />
                  <?php print $site_slogan; ?>
                  </div>
                </td>
                <td nowrap="nowrap">
                  <?php print $store_address; ?><br /><?php print $store_phone; ?>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <?php endif; ?>

        <tr valign="top">
          <td>

            <?php if ($thank_you_message): ?>
            <p><b><?php print t('Thanks for your order, !order_first_name!', array('!order_first_name' => $order_first_name)); ?></b></p>

            <?php if (isset($order->data['new_user'])): ?>
            <p><b><?php print t('An account has been created for you with the following details:'); ?></b></p>
            <p><b><?php print t('Username:'); ?></b> <?php print $order_new_username; ?><br />
            <b><?php print t('Password:'); ?></b> <?php print $order_new_password; ?></p>
            <?php endif; ?>

            <p><b><?php print t('Want to manage your order online?'); ?></b><br />
            <?php print t('If you need to check the status of your order, please visit our home page at !store_link and click on "My account" in the menu or login with the following link:', array('!store_link' => $store_link)); ?>
            <br /><br /><?php print $site_login_link; ?></p>
            <?php endif; ?>

            <table cellpadding="4" cellspacing="0" border="0" width="100%" style="font-family: verdana, arial, helvetica; font-size: small;">
              <tr>
                <td colspan="2" bgcolor="#e1007a" style="color: white;">
                  <b><?php print t('Purchasing Information:'); ?></b>
                </td>
              </tr>
              <tr>
                <td nowrap="nowrap">
                  <b><?php print t('E-mail Address:'); ?></b>
                </td>
                <td width="98%">
                  <?php print $order_email; ?>
                </td>
              </tr>
              <tr>
                <td colspan="2">

                  <table width="100%" cellspacing="0" cellpadding="0" style="font-family: verdana, arial, helvetica; font-size: small;">
                    <tr>
                      <td valign="top" width="50%">
                        <b><?php print t('Billing Address:'); ?></b><br />
                        <?php print $order_billing_address; ?><br />
                        <br />
                        <b><?php print t('Billing Phone:'); ?></b><br />
                        <?php print $order_billing_phone; ?><br />
                      </td>
                      <?php if ($shippable): ?>
                      <td valign="top" width="50%">
                        <b><?php print t('Shipping Address:'); ?></b><br />
                        <?php print $order_shipping_address; ?><br />
                        <br />
                        <b><?php print t('Shipping Phone:'); ?></b><br />
                        <?php print $order_shipping_phone; ?><br />
                      </td>
                      <?php endif; ?>
                    </tr>
                  </table>

                </td>
              </tr>
              <tr>
                <td nowrap="nowrap">
                  <b><?php print t('Order Grand Total:'); ?></b>
                </td>
                <td width="98%">
                  <b><?php print $order_total; ?></b>
                </td>
              </tr>
              <tr>
                <td nowrap="nowrap">
                  <b><?php print t('Payment Method:'); ?></b>
                </td>
                <td width="98%">
                  <?php print $order_payment_method; ?>
                </td>
              </tr>

              <tr>
                <td colspan="2" bgcolor="#e1007a" style="color: white;">
                  <b><?php print t('Order Summary:'); ?></b>
                </td>
              </tr>

              <?php if ($shippable): ?>
              <tr>
                <td colspan="2" bgcolor="#EEEEEE">
                  <font color="#CC6600"><b><?php print t('Shipping Details:'); ?></b></font>
                </td>
              </tr>
              <?php endif; ?>

              <tr>
                <td colspan="2">

                  <table border="0" cellpadding="1" cellspacing="0" width="100%" style="font-family: verdana, arial, helvetica; font-size: small;">
                    <tr>
                      <td nowrap="nowrap">
                        <b><?php print t('Order #:'); ?></b>
                      </td>
                      <td width="98%">
                        <?php print $order_link; ?>
                      </td>
                    </tr>

                    <tr>
                      <td nowrap="nowrap">
                        <b><?php print t('Order Date: '); ?></b>
                      </td>
                      <td width="98%">
                        <?php print $order_created; ?>
                      </td>
                    </tr>

                    <?php if ($shipping_method && $shippable): ?>
                    <tr>
                      <td nowrap="nowrap">
                        <b><?php print t('Shipping Method:'); ?></b>
                      </td>
                      <td width="98%">
                        <?php print $order_shipping_method; ?>
                      </td>
                    </tr>
                    <?php endif; ?>

                    <tr>
                      <td nowrap="nowrap">
                        <?php print t('Products Subtotal:'); ?>&nbsp;
                      </td>
                      <td width="98%">
                        <?php print $order_subtotal; ?>
                      </td>
                    </tr>

                    <?php foreach ($line_items as $item): ?>
                    <?php if ($item['type'] == 'subtotal' || $item['type'] == 'total')  continue; ?>

                    <tr>
                      <td nowrap="nowrap">
                        <?php print $item['title']; ?>:
                      </td>
                      <td>
                        <?php print $item['formatted_amount']; ?>
                      </td>
                    </tr>

                    <?php endforeach; ?>

                    <tr>
                      <td>&nbsp;</td>
                      <td>------</td>
                    </tr>

                    <tr>
                      <td nowrap="nowrap">
                        <b><?php print t('Total for this Order:'); ?>&nbsp;</b>
                      </td>
                      <td>
                        <b><?php print $order_total; ?></b>
                      </td>
                    </tr>

                    <tr>
                      <td colspan="2">
                        <br /><br /><b><?php print t('Products on order:'); ?>&nbsp;</b>

                        <table width="100%" style="font-family: verdana, arial, helvetica; font-size: small;">

                          <?php foreach ($products as $product): ?>
                          <tr>
                            <td valign="top" nowrap="nowrap">
                              <b><?php print $product->qty; ?> x </b>
                            </td>
                            <td width="98%">
                              <b><?php print $product->title; ?> - <?php print $product->total_price; ?></b>
                              <?php print $product->individual_price; ?><br />
                              <?php print t('SKU'); ?>: <?php print $product->model; ?><br />
                              <?php print $product->details; ?>
                            </td>
                          </tr>
                          <?php endforeach; ?>
                        </table>

                      </td>
                    </tr>
                  </table>

                </td>
              </tr>

              <?php if ($help_text || $email_text || $store_footer): ?>
              <tr>
                <td colspan="2">
                  <hr noshade="noshade" size="1" /><br />

                  <?php if ($help_text): ?>
                  <p><b><?php print t('Where can I get help with reviewing my order?'); ?></b><br />
                  <?php print t('To learn more about managing your orders on !store_link, please visit our <a href="!store_help_url">help page</a>.', array('!store_link' => $store_link, '!store_help_url' => $store_help_url)); ?>
                  <br /></p>
                  <?php endif; ?>

                  <?php if ($email_text): ?>
                  <p><?php print t('Please note: This e-mail message is an automated notification. Please do not reply to this message.'); ?></p>

                  <p><?php print t('Thanks again for shopping with us.'); ?></p>
                  <?php endif; ?>

                  <?php if ($store_footer): ?>
                  <p><b><?php print $store_link; ?></b><br /><b><?php print $site_slogan; ?></b></p>
                  <?php endif; ?>
                </td>
              </tr>
              <?php endif; ?>

            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>



<p>&nbsp</p>

<?php $ssb=1;


// connect database
$con = mysql_connect("localhost","kaligraf_bout_dd","X3MHG4hI4v");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}

mysql_select_db("kaligraf_bout_dd", $con);

$sql = 'select count(*) nbr from dd_tickets where order_id = ' .  $order->order_id;

$result = mysql_query($sql);

$row = mysql_fetch_array($result);

if($row["nbr"]>0)
{

?>


<table width="95%" border="0" cellspacing="0" cellpadding="1" align="center" bgcolor="#85b919" color="#FFFFFF" style="font-family: verdana, arial, helvetica; font-size: small; color: white; align: center;">
    <tr>
        <td align="center">
              <p><b>Liste des bons</b></p>
        </td>
    </tr>
    
    <tr>
    <td bgcolor="#FFFFFF" style="font-family: verdana, arial, helvetica; font-size: small; color: black">


<p>Ci-dessous une liste de bons cadeaux que vous avez commandé sur notre boutique en ligne. Si vous avez demandé a les recevoir par courrier, le bons cadeaux vous seront expédiés sous 48h au maximum. Vous les recevez rapidement dans votre boîte aux lettres. <br> 
En attendant, vous pouvez aussi imprimer les bons ci-dessous et vous présenter &agrave; l'espace Double-D&eacute;tente pour b&eacute;n&eacute;ficier dès maintenant de votre prestation.</p>
<p>N'oubliez pas de prendre rendez-vous, par téléphone au 01 39 73 33 32 ou à notre boutique au 59 bis rue de Pologne à St Germain en laye pour bénéficier de votre prestation.</p>

<p>Vos bons sont également disponibles sur le site boutique.double-detente.com à la rubrique <b>'Mon compte'</b> puis <b>'Mes bons de prestations'</b>. Vous y trouverez la liste de vos bons ainsi que leur historique d'utilisation.</p>
<p>Toute l'équipe de l'Espace Double-Détente vous remercie encore pour votre commande.</p>
<p>&nbsp</p>

</td> </tr>
</table>

<?php $ssb=1;


// connect database

$sql = 'select * from dd_tickets where order_id = ' .  $order->order_id;

$result = mysql_query($sql);

$i = 1;





while($row = mysql_fetch_array($result)) 
{

?>


<p><img src="http://boutique.double-detente.com/sites/boutique.double-detente.com/files/cut_here.png"> </p> <br/>


<table>
<table width="900px" border="0" cellspacing="0" cellpadding="1" align="center" bgcolor="#e1007a" style="font-family: verdana, arial, helvetica; font-size: medium;">
    <tr>
        <td colspan="2" bgcolor="#e1007a" align="center" style="color: white;">
           <p> <b>&nbsp;Bon cadeau num&eacute;ro <?php print $order->order_id; ?>-<?php print $ssb; ?> </p></b>
           <?php $ssb=$ssb + 1; ?>
        </td>
    </tr>

    <tr>
        <td>
            <table width="820px" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="#FFFFFF" style="font-family: verdana, arial, helvetica; font-size: small;">
            <?php if ($business_header): ?>
                <tr valign="top">
                    <td>
                        <table width="100%" style="font-family: verdana, arial, helvetica; font-size: small;">
                        <tr>
                            <td>
                                <img src="http://boutique.double-detente.com/sites/boutique.double-detente.com/files/espacedd-logo.png">
                                
                            </td>
                            <td nowrap="nowrap">
                                <?php print $store_address; ?><br /><?php print $store_phone; ?>
                            </td>
                        </tr>
                        </table>
                    </td>
                </tr>
            <?php endif; ?>
            </table>
        </td>
    </tr>
    
            

    <tr valign="top">
        <td>
            <table width="820px" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="#FFFFFF" style="font-family: verdana, arial, helvetica; font-size: medim;">
                <tr>
                <td width="100%">
                
           <p>
           
            <img alt="" src="http://boutique.double-detente.com/sites/boutique.double-detente.com/files/papillon_pm.png" style="float: left; margin-left: 15px; margin-right: 10px" />
                
                
           <b style="font-family: verdana, arial, helvetica; background-color: rgb(255, 255, 255); ">
           <br>Bon pour une prestation <?php echo '"'.utf8_encode($row["title"]) .'" de '. utf8_encode($row["duration"])  ; ?> &agrave; l'Espace Double-D&eacute;tente </b><br>
           <span style="font-size:11px;"><span style="font-family: verdana, arial, helvetica; white-space: nowrap; background-color: rgb(255, 255, 255);">
           (R&eacute;f&eacute;rence : <?php echo  utf8_encode($row["sku"]); ?>)</span></span><br></p>
           <p style="font-family: verdana, arial, helvetica; font-size: small; white-space:  background-color: rgb(255, 255, 255); "><span style="font-size:14px;">
           <i><?php echo utf8_encode($row['teaser']); ?> </i></span></p>
                
            
                
                
                </td>
                </tr>
            </table>    
            <table width="820px" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="#FFFFFF" style="font-family: verdana, arial, helvetica; font-size: small;">    
            <tr> 
            <td width="60%" align="center">
	        
	        <?php 
	
		      
	
				$qrfile = drupal_realpath(file_build_uri('')).'/phpqrcode/img/'.$row['code'] .'.png';
				$imgurl = 'http://boutique.double-detente.com/sites/boutique.double-detente.com/files/phpqrcode/img/'.$row['code'] .'.png';
				$qrurl = 'http://boutique.double-detente.com/user/ticket/view?in='.$row['code'];
				
		
				//watchdog('information', 'QR code calculation', $qrurl);
				//QRcode::png($qrurl, $qrfile, 'L', 4, 2);
	
				echo '<img src="'.$imgurl.'">';
	
			?>

	            
            </td>
            <td valign="top" width="40%">
                
                De la part de :<br />
                <b><?php print utf8_encode($row['FirstName']) . ' '. utf8_encode($row['LastName']); ?><br /></b>
                <a href="mailto:<?php print utf8_encode($row['email']); ?>"><?php print utf8_encode($row['email']); ?></a><br>
                <br />
                <br>
            </td>
            </tr>    
            <tr>
            <td colspan="2">
            <center>
            
            <span style="font-size:9px;"><span style="font-family: verdana, arial, helvetica;  background-color: rgb(255, 255, 255); color:#a9a9a9;">
            N'oubliez pas de prendre rendez-vous, par téléphone au 01 39 73 33 32 ou à notre boutique au 59 bis rue de Pologne à St Germain en laye pour bénéficier de votre prestation.</span>

            </center>
            </td>
            </tr>
        

</table>
<tr>
<td colspan="2" bgcolor="#e1007a" align="center" style="color: white; font-size: small;" >
<p><?php print $row['code']; ?><br>
Ce bon est valable jusqu'au <?php print date ("d/m/Y", $row['end']); ?> </p>
</tr> </td>
</table>
<p>&nbsp</p>
<?php 

} // while get row (boucle sur les tickets.
}// if nbr >0
mysql_close($con);
 ?>

