Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.78 KB | None | 0 0
  1. <?php
  2.  
  3. function do_html_header($title = '')
  4. {
  5.   // print an HTML header
  6.  
  7.   // declare the session variables we want access to inside the function  
  8.   if(!$_SESSION['items']) $_SESSION['items'] = '0';
  9.   if(!$_SESSION['total_price']) $_SESSION['total_price'] = '0.00';
  10. ?>
  11.   <html>
  12.   <head>
  13.     <title><?php echo $title; ?></title>
  14.     <link rel="stylesheet" type="text/css" href="styling.css" />   
  15.   </head>
  16.   <body>
  17.   <table width='100%' border=0 cellspacing = 0 bgcolor='#848484'>
  18.   <tr>
  19.   <td rowspan = 2>
  20.   <a href = 'index.php'><img src='images/logo.gif' alt='Logo Failed to load, sorry.' border=0
  21.        align='left' valign='bottom' height = 55 width = 325></a>
  22.   </td>
  23.   <td align = 'right' valign = 'bottom'>
  24.   <?php if(isset($_SESSION['admin_user']))
  25.        echo '&nbsp;';
  26.      else
  27.        echo 'Total Items = '.$_SESSION['items'];
  28.   ?>
  29.   </td>
  30.   <td align = 'right' rowspan = 2 width = 135>
  31.   <?php if(isset($_SESSION['admin_user']))
  32.        display_button('logout.php', 'log-out', 'Log Out');
  33.      else
  34.        display_button('show_cart.php', 'view-cart', 'View Your Shopping Cart');
  35.   ?>
  36.   </tr>
  37.   <tr>
  38.   <td align = right valign = top>
  39.   <?php if(isset($_SESSION['admin_user']))
  40.        echo '&nbsp;';
  41.      else
  42.        echo 'Cart Total = &pound'.number_format($_SESSION['total_price'],2);
  43.   ?>
  44.   </td>
  45.   </tr>
  46.   </table>
  47. <?php
  48.   if($title)
  49.     do_html_heading($title);
  50. }
  51.  
  52. function do_html_footer()
  53. {
  54.   // print an HTML footer
  55. ?>
  56.   </body>
  57.   </html>
  58. <?php
  59. }
  60.  
  61. function do_html_heading($heading)
  62. {
  63.   // print heading
  64. ?>
  65.   <h2><?php echo $heading; ?></h2>
  66. <?php
  67. }
  68.  
  69. function do_html_URL($url, $name)
  70. {
  71.   // output URL as link and br
  72. ?>
  73.   <a href="<?php echo $url; ?>"><?php echo $name; ?></a><br />
  74. <?php
  75. }
  76.  
  77. function display_categories($cat_array)
  78. {
  79.   if (!is_array($cat_array))
  80.   {
  81.      echo 'No categories currently available<br />';
  82.      return;
  83.   }
  84.   echo '<ul>';
  85.   foreach ($cat_array as $row)
  86.   {
  87.     $url = 'show_cat.php?categoryID='.($row['categoryID']);
  88.     $title = $row['category_name'];
  89.     echo '<li>';
  90.     do_html_url($url, $title);
  91.     echo '</li>';
  92.   }    
  93.   echo '</ul>';
  94.   echo '<hr />';
  95. }
  96.  
  97. function display_products($product_array)
  98. {
  99.   //display all products in the array passed in
  100.   if (!is_array($product_array))
  101.   {
  102.      echo '<br />No products currently available in this category<br />';
  103.   }
  104.   else
  105.   {
  106.     //create table
  107.     echo '<table width = \"100%\" border = 0>';
  108.    
  109.     //create a table row for each product    
  110.     foreach ($product_array as $row)
  111.     {
  112.       $url = 'show_product.php?productID='.($row['productID']);
  113.       echo '<tr><td style=\'width:30%\'>';
  114.       if (@file_exists('images/'.$row['image_url']))
  115.       {
  116.         $title = '<img src=\'images/'.($row['image_url']).'\' border=0 style=\'height:30%\' />';
  117.         do_html_url($url, $title);
  118.       }
  119.       else
  120.       {
  121.         echo '&nbsp;';
  122.       }
  123.       echo '</td><td>';
  124.       $name =  $row['name'].' '.$row['storage_space'].'GB';
  125.       do_html_url($url, $name);
  126.       echo '</td></tr>';
  127.     }
  128.     echo '</table>';
  129.   }
  130.   echo '<hr />';
  131. }
  132.  
  133. function display_product_details($product)
  134. {
  135.   // display all details about this product
  136.   if (is_array($product))
  137.   {
  138.     echo '<table><tr>';
  139.     //display the picture if there is one
  140.     if (@file_exists('images/'.($product['image_url'])))
  141.     {
  142.       $size = GetImageSize('images/'.$product['image_url']);
  143.       if($size[0]>0 && $size[1]>0)
  144.         echo '<td><img src=\'images/'.$product['image_url'].'\' border=0 style=\'width:40%\'></td>';
  145.     }
  146.     echo '<td><ul>';
  147.     echo '</li><li><b>Product Name:</b> ';
  148.     echo $product['name'];
  149.     echo '<li><b>Storage Space:</b> ';
  150.     echo $product['storage_space'].'GB';
  151.     echo '</li><li><b>Our Price:</b> ';
  152.     echo number_format($product['price'], 2);
  153.     echo '</li><li><b>Description:</b> ';
  154.     echo $product['description'];
  155.     echo '</li></ul></td></tr></table>';
  156.   }
  157.   else
  158.     echo 'The details of this product cannot be displayed at this time.';
  159.   echo '<hr />';
  160. }
  161.  
  162. function display_checkout_form()
  163. {
  164.   //display the form that asks for name and address
  165. ?>
  166.   <br />
  167.   <table border = 0 width = '100%' cellspacing = 0>
  168.   <form action = 'purchase.php' method = 'post'>
  169.   <tr><th colspan = 2 bgcolor='#848484'>Your Details</th></tr>
  170.   <tr>
  171.     <td>Name</td>
  172.     <td><input type = 'text' name = 'name' value = "" maxlength = 40 size = 40></td>
  173.   </tr>
  174.   <tr>
  175.     <td>Address</td>
  176.     <td><input type = 'text' name = 'address' value = "" maxlength = 40 size = 40></td>
  177.   </tr>
  178.   <tr>
  179.     <td>City</td>
  180.     <td><input type = 'text' name = 'city' value = "" maxlength = 20 size = 40></td>
  181.   </tr>
  182.   <tr>
  183.     <td>County</td>
  184.     <td><input type = 'text' name = 'county' value = "" maxlength = 20 size = 40></td>
  185.   </tr>
  186.   <tr>
  187.     <td>Postcode</td>
  188.     <td><input type = 'text' name = 'post_code' value = "" maxlength = 10 size = 40></td>
  189.   </tr>
  190.   <tr>
  191.     <td>Country</td>
  192.     <td><input type = 'text' name = 'country' value = "" maxlength = 20 size = 40></td>
  193.   </tr>
  194.   <tr><th colspan = 2 bgcolor='#848484'>Shipping Address (leave blank if as above)</th></tr>
  195.   <tr>
  196.     <td>Name</td>
  197.     <td><input type = 'text' name = 'ship_name' value = "" maxlength = 40 size = 40></td>
  198.   </tr>
  199.   <tr>
  200.     <td>Address</td>
  201.     <td><input type = 'text' name = 'ship_address' value = "" maxlength = 40 size = 40></td>
  202.   </tr>
  203.   <tr>
  204.     <td>City</td>
  205.     <td><input type = 'text' name = 'ship_city' value = "" maxlength = 20 size = 40></td>
  206.   </tr>
  207.   <tr>
  208.     <td>County</td>
  209.     <td><input type = 'text' name = 'ship_county' value = "" maxlength = 20 size = 40></td>
  210.   </tr>
  211.   <tr>
  212.     <td>Postcode</td>
  213.     <td><input type = 'text' name = 'ship_postcode' value = "" maxlength = 10 size = 40></td>
  214.   </tr>
  215.   <tr>
  216.     <td>Country</td>
  217.     <td><input type = 'text' name = 'ship_country' value = "" maxlength = 20 size = 40></td>
  218.   </tr>
  219.   <tr>
  220.     <td colspan = 2 align = 'center'>
  221.       <b>Please press Purchase to confirm your purchase,
  222.          or Continue Shopping to add or remove items</b>
  223.      <?php display_form_button('purchase', 'Purchase These Items'); ?>
  224.     </td>
  225.   </tr>
  226.   </form>
  227.   </table><hr />
  228. <?php
  229. }
  230.  
  231. function display_shipping($shipping)
  232. {
  233.   // display table row with shipping cost and total price including shipping
  234. ?>
  235.   <table border = 0 width = '100%' cellspacing = 0>
  236.   <tr><td align = 'left'>Shipping</td>
  237.       <td align = 'right'> <?php echo number_format($shipping, 2); ?></td></tr>
  238.   <tr><th bgcolor='#848484' align = 'left'>TOTAL INCLUDING SHIPPING</th>
  239.       <th bgcolor='#848484' align = 'right'>$<?php echo number_format($shipping+$_SESSION['total_price'], 2); ?></th>
  240.   </tr>
  241.   </table><br />
  242. <?php
  243. }
  244.  
  245. function display_card_form($name)
  246. {
  247.   //display form asking for credit card details
  248. ?>
  249.   <table border = 0 width = '100%' cellspacing = 0>
  250.   <form action = 'process.php' method = 'post'>
  251.   <tr><th colspan = 2 bgcolor="#848484">Credit Card Details</th></tr>
  252.   <tr>
  253.     <td>Type</td>
  254.     <td><select name = 'card_type'><option>VISA<option>MasterCard<option>American Express</select></td>
  255.   </tr>
  256.   <tr>
  257.     <td>Number</td>
  258.     <td><input type = 'text' name = 'card_number' value = "" maxlength = 16 size = 40></td>
  259.   </tr>
  260.   <tr>
  261.     <td>AMEX code (if required)</td>
  262.     <td><input type = 'text' name = 'amex_code' value = "" maxlength = 4 size = 4></td>
  263.   </tr>
  264.   <tr>
  265.     <td>Expiry Date</td>
  266.     <td>Month <select name = 'card_month'><option>01<option>02<option>03<option>04<option>05<option>06<option>07<option>08<option>09<option>10<option>11<option>12</select>
  267.     Year <select name = 'card_year'><option>00<option>01<option>02<option>03<option>04<option>05<option>06<option>07<option>08<option>09<option>10</select></td>
  268.   </tr>
  269.   <tr>
  270.     <td>Name on Card</td>
  271.     <td><input type = 'text' name = 'card_name' value = "<?php echo $name; ?>" maxlength = 40 size = 40></td>
  272.   </tr>
  273.   <tr>
  274.     <td colspan = 2 align = 'center'>
  275.       <b>Please press Purchase to confirm your purchase,
  276.          or Continue Shopping to add or remove items</b>
  277.      <?php display_form_button('purchase', 'Purchase These Items'); ?>
  278.     </td>
  279.   </tr>
  280.   </table>
  281. <?php
  282. }
  283.  
  284.  
  285.  
  286. function display_cart($cart, $change = true, $images = 1)
  287. {
  288.   // display items in shopping cart
  289.   // optionally allow changes (true or false)
  290.   // optionally include images (1 - yes, 0 - no)
  291.  
  292.    echo '<table border = 0 width = "100%" cellspacing = 0>
  293.        <form action = "show_cart.php" method = "post">
  294.        <tr><th colspan = '. (1+$images) .' bgcolor="#848484">Item</th>
  295.        <th bgcolor="#848484">Price</th><th bgcolor="#848484">Quantity</th>
  296.        <th bgcolor="#848484">Total</th></tr>';
  297.  
  298.   //display each item as a table row
  299.   foreach ($cart as $productID => $qty)
  300.   {
  301.     $product = get_product_details($productID);
  302.     echo '<tr>';
  303.     if($images ==true)
  304.     {
  305.       echo '<td align = left>';
  306.       if (file_exists("images/".$image_url))
  307.       {
  308.          $size = GetImageSize('images/'.$image_url);  
  309.          if($size[0]>0 && $size[1]>0)
  310.          {
  311.            echo '<img src="images/'.$image_url.'\" border=0 ';
  312.            echo 'width = \'200px\' />';
  313.          }
  314.       }
  315.       else
  316.          echo '&nbsp;';
  317.       echo '</td>';
  318.     }
  319.     echo '<td align = "left">';
  320.     echo '<a href = "show_product.php?productID='.$productID.'">'.$product['name'].' '.$product['storage_space'].'GB';
  321.     echo '</td><td align = "center">&pound'.number_format($product['price'], 2);
  322.     echo '</td><td align = "center">';
  323.     // if we allow changes, quantities are in text boxes
  324.     if ($change == true)
  325.       echo "<input type = 'text' name = \"".$productID."\" value = \"".$qty."\" size = 3>";
  326.     else
  327.       echo $qty;
  328.     echo '</td><td align = "center">&pound'.number_format($product['price']*$qty,2)."</td></tr>\n";
  329.   }
  330.   // display total row
  331.   echo "<tr>
  332.          <th colspan = ". (2+$images) ." bgcolor=\"#848484\">&nbsp;</td>
  333.          <th align = \"center\" bgcolor=\"#848484\">
  334.              ".$_SESSION['items']."
  335.          </th>
  336.          <th align = \"center\" bgcolor=\"#848484\">
  337.              &pound".number_format($_SESSION['total_price'], 2).
  338.           '</th>
  339.        </tr>';
  340.   // display save change button
  341.   if($change == true)
  342.   {
  343.     echo '<tr>
  344.            <td colspan = '. (2+$images) .'>&nbsp;</td>
  345.            <td align = "center">
  346.              <input type = "hidden" name = "save" value = true>  
  347.              <input type = "image" src = "images/save-changes.gif"
  348.                     border = 0 alt = "Save Changes">
  349.            </td>
  350.            <td>&nbsp;</td>
  351.        </tr>';
  352.   }
  353.   echo '</form></table>';
  354. }
  355.  
  356. function display_login_form()
  357. {
  358.   // dispaly form asking for name and password
  359. ?>
  360.   <form method='post' action="admin.php">
  361.  <table bgcolor='#848484'>
  362.    <tr>
  363.      <td>Username:</td>
  364.      <td><input type='text' name='username'></td></tr>
  365.    <tr>
  366.      <td>Password:</td>
  367.      <td><input type='password' name='passwd'></td></tr>
  368.    <tr>
  369.      <td colspan=2 align='center'>
  370.      <input type='submit' value="Log in"></td></tr>
  371.    <tr>
  372.  </table></form>
  373. <?php
  374. }
  375.  
  376. function display_admin_menu()
  377. {
  378. ?>
  379. <br />
  380. <a href="index.php">Go to main site</a><br />
  381. <a href="insert_category_form.php">Add a new category</a><br />
  382. <a href="insert_product_form.php">Add a new product</a><br />
  383. <a href="change_password_form.php">Change admin password</a><br />
  384. <?php
  385.  
  386. }
  387.  
  388. function display_button($target, $image, $alt)
  389. {
  390.   echo "<center><a href=\"$target\"><img src=\"images/$image".".gif\"
  391.           alt=\"$alt\" border=0 height = 50 width = 135></a></center>";
  392. }
  393.  
  394. function display_form_button($image, $alt)
  395. {
  396.   echo "<center><input type = image src=\"images/$image".".gif\"
  397.           alt=\"$alt\" border=0 height = 50 width = 135></center>";
  398. }
  399.  
  400. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement