home *** CD-ROM | disk | FTP | other *** search
/ grafika-wolowiec.cba.pl / grafika-wolowiec.cba.pl.tar / grafika-wolowiec.cba.pl / admin / orders.php < prev    next >
PHP Script  |  2014-01-24  |  12KB  |  292 lines

  1. <?php
  2. require_once("header.php");
  3.  
  4. /**
  5.  * Format a number to look like a currency
  6.  * @param  float $number The number
  7.  * @return strng         The formatted string
  8.  */
  9. function cnumber_format($number) {
  10.     global $imSettings;
  11.     return number_format($number, 2) . $imSettings['ecommerce']['database']['currency'];
  12. }
  13.  
  14. ?>
  15. <div id="imAdminPage" style="width: 80%;">
  16.     <div id="imBody">
  17.         <div class="imContent">
  18. <?php
  19. if (isset($imSettings['ecommerce']) && isset($imSettings['ecommerce']['database'])) {
  20.     $dbconf = getDbData($imSettings['ecommerce']['database']['id']);
  21.     $prefix = $imSettings['ecommerce']['database']['table'];
  22.     $pagination_length = 15;
  23.     $pagination_start = (isset($_GET['page']) ? $_GET['page'] * $pagination_length : 0);
  24.     $ecommerce = new ImCart();
  25.     if ($ecommerce->setDatabaseConnection($dbconf['host'], $dbconf['user'], $dbconf['password'], $dbconf['database'], $prefix)) {
  26.         if (isset($_GET['delete'])) {
  27.             $ecommerce->deleteOrderFromDb($_GET['delete']);
  28.         }
  29.         if (!isset($_GET['id'])) {
  30.  
  31.             /*
  32.             |-----------------------------
  33.             |    Show the summary table
  34.             |-----------------------------
  35.              */
  36.             
  37.             $result = $ecommerce->getOrders($pagination_start, $pagination_length, @$_GET['search']);
  38. ?>
  39.             <form action="orders.php" method="get" style="margin: 5px; float: right;">
  40.                 <input name="search" id="search" type="text" style="padding: 5px;" value="<?php echo @$_GET['search'] ?>"/>
  41.                 <input type="submit" value="<?php echo l10n('search_search') ?>">
  42.             </form>
  43.             <table class="border">
  44.                 <thead>
  45.                     <tr>
  46.                         <th style="width: 15%;"><?php echo l10n('cart_order_no') ?></th>
  47.                         <th><?php echo l10n('cart_date', 'Date') ?></th>
  48.                         <th><?php echo l10n('cart_total') ?></th>
  49.                         <th><?php echo l10n('cart_payment') ?></th>
  50.                         <th><?php echo l10n('cart_shipping') ?></th>
  51.                         <th></th>
  52.                     </tr>
  53.                 </thead>
  54.                 <tbody>
  55. <?php // Empty search! ?>
  56. <?php if (isset($_GET['search']) && !count($result['orders'])): ?>
  57.                     <tr>
  58.                         <td colspan="6" style="text-align: center;"><?php echo l10n('search_empty', 'Empty results') ?></td>
  59.                     </tr>
  60. <?php else:?>
  61. <?php // Orders ?>
  62. <?php foreach ($result['orders'] as $order): ?>
  63.                     <tr>
  64.                         <td style="text-align: center;"><a href="orders.php?id=<?php echo $order['id'] ?>"><?php echo $order['id'] ?></a></td>
  65.                         <td tyle="text-align: center;"><?php echo $order['ts'] ?></td>
  66.                         <td style="text-align: center;"><?php echo cnumber_format($order['vat_type'] != "excluded" ? $order['price_plus_vat'] : $order['price']) ?></td>
  67.                         <td><?php echo $order['payment_name'] . ($order['payment_price'] > 0 ? " (" . cnumber_format($order['vat_type'] != "excluded" ? $order['payment_price_plus_vat'] : $order['payment_price']) . ")" : "") ?></td>
  68.                         <td><?php echo $order['shipping_name'] . ($order['shipping_price'] > 0 ? " (" . cnumber_format($order['vat_type'] != "excluded" ? $order['shipping_price_plus_vat'] : $order['shipping_price']) . ")" : "") ?></td>
  69.                         <td><a href="?delete=<?php echo $order['id']?>" onclick="return confirm('<?php echo str_replace("'", "\\'", l10n('cart_delete_order_q', 'Are you sure?')) ?>')"><?php echo l10n('cart_delete_order', 'Delete') ?></a></td>
  70.                     </tr>
  71. <?php endforeach; ?>
  72. <?php endif; ?>
  73.                 </tbody>
  74.             </table>
  75. <?php // PAGINATION ?>
  76. <?php if ($result['paginationCount'] > $pagination_length): ?>
  77.             <div style="text-align: center; margin: 5px;">
  78.     <?php if (@$_GET['page'] != 0): ?>
  79.                 <a href="orders.php?page=0&search=<?php echo @$_GET['search'] ?>"><<</a>
  80.     <?php endif; ?>
  81.     <?php if (@$_GET['page'] - 2 >= 0): ?>
  82.                 <a href="orders.php?page=<?php echo @$_GET['page'] - 2 ?>&search=<?php echo @$_GET['search'] ?>"><</a>
  83.     <?php endif; ?>
  84.     <?php for ($i = max(@$_GET['page'] - 3, 0); $i < min($ordersCount/$pagination_length, max(@$_GET['page'] - 3, 0) + 6); $i++): ?>
  85.                 <a href="orders.php?page=<?php echo $i ?>&search=<?php echo @$_GET['search'] ?>"><?php echo $i + 1?></a>
  86.     <?php endfor; ?>
  87.     <?php if (@$_GET['page'] + 1 <= $ordersCount/$pagination_length - 2): ?>
  88.                 <a href="orders.php?page=<?php echo @$_GET['page'] + 1 ?>&search=<?php echo @$_GET['search'] ?>">></a>
  89.     <?php endif; ?>
  90.     <?php if (@$_GET['page'] != $ordersCount/$pagination_length - 1): ?>
  91.                 <a href="orders.php?page=<?php echo $ordersCount/$pagination_length - 1?>&search=<?php echo @$_GET['search'] ?>">>></a>
  92.             </div>
  93.     <?php endif; ?>
  94. <?php endif; ?>
  95. <?php
  96.         } else {
  97.  
  98.             /*
  99.             |-----------------------------
  100.             |    Show the order page
  101.             |-----------------------------
  102.              */
  103.             
  104.             $orderArray = $ecommerce->getOrder($_GET['id']);
  105.             if (count($orderArray)) {
  106.                 $order = $orderArray['order'];
  107. ?>
  108.             <h1><?php echo l10n('cart_order_no') . ": " . $order['id'] ?></h1>
  109.             <div class="personal-data" style="float: left;">
  110.                 <table style="width: 100%;">
  111.                     <thead>
  112.                         <tr>
  113.                             <th colspan="2">
  114.                                 <?php
  115.                                     if (count($orderArray['shipping']) === 0) {
  116.                                         echo l10n('cart_vat_address') . "/" . l10n('cart_shipping_address');
  117.                                     } else {
  118.                                         echo l10n('cart_vat_address');
  119.                                     }
  120.                                 ?>
  121.                             </th>
  122.                         </tr>
  123.                     </thead>
  124.                     <tbody>
  125. <?php foreach ($orderArray['invoice'] as $line): ?>
  126.                         <tr>
  127.                             <td style="font-weight: bold;"><?php echo $line['label'] . ":" ?></td>
  128.                             <td><?php echo $line['value'] ?></td>
  129.                         </tr>
  130. <?php endforeach; ?>
  131.                     </tbody>
  132.                 </table>
  133.             </div>
  134. <?php if (count($orderArray['shipping']) > 0): ?>
  135.             <div class="personal-data" style="float: right;">
  136.                 <table style="width: 100%;">
  137.                     <thead>
  138.                         <tr>
  139.                             <th colspan="2">
  140.                                 <?php echo l10n('cart_shipping_address') ?>    
  141.                             </th>
  142.                         </tr>
  143.                     </thead>
  144.                     <tbody>
  145. <?php foreach ($orderArray['shipping'] as $line): ?>
  146.                         <tr>
  147.                             <td style="font-weight: bold;"><?php echo $line['label'] . ":" ?></td>
  148.                             <td><?php echo $line['value'] ?></td>
  149.                         </tr>
  150. <?php endforeach; ?>
  151.                     </tbody>
  152.                 </table>
  153.             </div>
  154. <?php endif; // End shipping table ?>
  155.             <div style="clear:both;"></div>
  156.             <h2 style="margin-bottom: 5px; margin-top: 15px;"><?php echo l10n('cart_product_list') ?></h2>
  157.             <div style="margin: 0 5px 15px 5px;">
  158.                 <table class="border">
  159.                     <thead>
  160.                         <tr>
  161.                             <th><?php echo l10n('cart_descr') ?></th>
  162.                             <th><?php echo l10n('cart_price') ?></th>
  163.                             <th><?php echo l10n('cart_qty') ?></th>
  164.                             <?php if ($order['vat_type'] != "none"): ?>
  165.                             <th><?php echo l10n($order['vat_type'] == "excluded" ? 'cart_vat' : 'cart_vat_included') ?></th>
  166.                             <?php endif; ?>
  167.                             <th><?php echo l10n('cart_subtot') ?></th>
  168.                         </tr>
  169.                     </thead>
  170.                     <tbody>
  171. <?php foreach ($orderArray['products'] as $product): ?>
  172.                         <tr>
  173.                             <td>
  174.                                 <?php echo $product['name'] . ($product['option'] != "" ? " - " . $product['option'] . ($product['suboption'] != "" ? " - " . $product['suboption'] : "") : "") ?>
  175.                             </td>
  176.                             <td class="align-right"><?php echo cnumber_format($product['price'] / $product['quantity']) ?></td>
  177.                             <td class="align-right"><?php echo $product['quantity'] ?></td>
  178.                             <?php if ($order['vat_type'] != "none"): ?>
  179.                             <td class="align-right"><?php echo cnumber_format($product['vat']) ?></td>
  180.                             <?php endif; ?>
  181.                             <td class="align-right"><?php echo cnumber_format($order['vat_type'] == "excluded" ? $product['price'] : $product['price_plus_vat']) ?></td>
  182.                         </tr>
  183. <?php endforeach; ?>
  184.                         <tr>
  185.                             <td colspan="3" style="border: none;"></td>
  186.                         </tr>
  187.                         <!-- Shipping data -->
  188.                         <?php if ($order['shipping_name'] != "" || $order['shipping_price'] != 0): ?>
  189.                         <tr class="head">
  190.                             <th colspan="3"><?php echo l10n('cart_shipping') ?></th>
  191.                             <?php if ($order['vat_type'] != "none"): ?>
  192.                             <th><?php echo l10n($order['vat_type'] == "excluded" ? 'cart_vat' : 'cart_vat_included') ?></th>
  193.                             <?php endif; ?>
  194.                             <th><?php echo l10n('cart_price') ?></th>
  195.                         </tr>
  196.                         <tr>
  197.                             <td colspan="3"><?php echo $order['shipping_name'] ?></td>
  198.                             <?php if ($order['vat_type'] != "none"): ?>
  199.                             <td class="align-right"><?php echo cnumber_format($order['shipping_vat']) ?></td>
  200.                             <?php endif; ?>
  201.                             <td class="align-right"><?php echo cnumber_format($order['vat_type'] == "excluded" ? $order['shipping_price'] : $order['shipping_price_plus_vat']) ?></td>
  202.                         </tr>
  203.                         <tr>
  204.                             <td colspan="3" style="border: none;"></td>
  205.                         </tr>
  206.                         <?php endif; ?>                        
  207.                         <!-- Payment data -->
  208.                         <?php if ($order['payment_name'] != "" || $order['payment_price'] != 0): ?>
  209.                         <tr class="head">
  210.                             <th colspan="3"><?php echo l10n('cart_payment') ?></th>
  211.                             <?php if ($order['vat_type'] != "none"): ?>
  212.                             <th><?php echo l10n($order['vat_type'] == "excluded" ? 'cart_vat' : 'cart_vat_included') ?></th>
  213.                             <?php endif; ?>
  214.                             <th><?php echo l10n('cart_price') ?></th>
  215.                         </tr>
  216.                         <tr>
  217.                             <td colspan="3"><?php echo $order['payment_name'] ?></td>
  218.                             <?php if ($order['vat_type'] != "none"): ?>
  219.                             <td class="align-right"><?php echo cnumber_format($order['payment_vat']) ?></td>
  220.                             <?php endif; ?>
  221.                             <td class="align-right"><?php echo cnumber_format($order['vat_type'] == "excluded" ? $order['payment_price'] : $order['payment_price_plus_vat']) ?></td>
  222.                         </tr>
  223.                         <tr>
  224.                             <td colspan="3" style="border: none;"></td>
  225.                         </tr>
  226.                         <?php endif; ?>
  227.                         <!-- Coupon Code -->
  228.                         <?php if (isset($order['coupon']) && $order['coupon'] != ""): ?>
  229.                         <tr>
  230.                             <th colspan="3" style="border-left: none; border-bottom: none; border-top: none;"></th>
  231.                             <th class="head"><?php echo l10n('cart_coupon', "Coupon Code") ?></th>
  232.                             <td class="align-right"><?php echo $order['coupon'] ?></td>
  233.                         </tr>
  234.                         <?php endif; ?>
  235.                         <!-- Total Amounts -->
  236.                         <?php switch($order['vat_type']) {
  237.                             case "included": ?>
  238.                         <tr>
  239.                             <th colspan="3" style="border: none;"></th>
  240.                             <th class="head"><?php echo l10n('cart_total_vat') ?></th>
  241.                             <td class="align-right"><?php echo cnumber_format($order['price_plus_vat']) ?></td>
  242.                         </tr>
  243.                         <tr>
  244.                             <th colspan="3" style="border: none;"></th>
  245.                             <th class="head"><?php echo l10n('cart_vat_included') ?></th>
  246.                             <td class="align-right"><?php echo cnumber_format($order['vat']) ?></td>
  247.                         </tr>
  248.                         <?php
  249.                             break;
  250.                             case "excluded": ?>
  251.                         <tr>
  252.                             <th colspan="3" style="border: none;"></th>
  253.                             <th class="head"><?php echo l10n('cart_total') ?></th>
  254.                             <td class="align-right"><?php echo cnumber_format($order['price']) ?></td>
  255.                         </tr>
  256.                         <tr>
  257.                             <th colspan="3" style="border: none;"></th>
  258.                             <th class="head"><?php echo l10n('cart_vat') ?></th>
  259.                             <td class="align-right"><?php echo cnumber_format($order['vat']) ?></td>
  260.                         </tr>
  261.                         <tr>
  262.                             <th colspan="3" style="border: none;"></th>
  263.                             <th class="head"><?php echo l10n('cart_total_vat') ?></th>
  264.                             <td class="align-right"><?php echo cnumber_format($order['price_plus_vat']) ?></td>
  265.                         </tr>
  266.                         <?php
  267.                             break;
  268.                             case "none":?>
  269.                         <tr>
  270.                             <th colspan="2" style="border: none;"></th>
  271.                             <th class="head"><?php echo l10n('cart_total') ?></th>
  272.                             <td class="align-right"><?php echo cnumber_format($order['price_plus_vat']) ?></td>
  273.                         </tr>
  274.                         <? break; ?>
  275.                         <?php } ?>
  276.                     </tbody>
  277.                 </table>
  278.             </div>
  279.             <div style="padding: 5px; text-align: center;">
  280.                 <input type="button" onclick="location.href='<?php echo strpos($_SERVER['HTTP_REFERER'], basename($_SERVER['PHP_SELF'])) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF'] ?>';" value="<?php echo l10n('cart_goback', "Back") ?>" />
  281.             </div>
  282. <?php
  283.             }
  284.         }
  285.     }
  286. }
  287. ?>
  288.         </div>
  289.     </div>
  290. </div>
  291. <?php require_once("footer.php"); ?>
  292.