Advertisement
Guest User

Untitled

a guest
Feb 24th, 2012
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. <?php
  2. $catnames = array("a1" => "A1's Products",
  3. "b1" => "b1's Products",
  4. "c1" => "c1's Products",
  5. "d1" => "d1's Products");
  6.  
  7. if (isset($_GET['id'])) {
  8. $sql = "SELECT products.*, products_categories.parentcat FROM products LEFT JOIN products_categories ON products.category=products_categories.id WHERE products.id=?";
  9. $pV = $pdb->getRow($sql, array($_GET['id']));
  10. if (PEAR::isError($pV) || $pV == NULL)
  11. die("There was a problem retrieving the product from the database. Please try again later.");
  12. }
  13.  
  14. if (isset($_GET['id']) && isset($_GET['region'])) {
  15. $sql = "SELECT DISTINCT products_locations.store FROM products_locations WHERE region=? AND upc IN (SELECT products_sizes.upc FROM products_sizes LEFT JOIN products ON products_sizes.pid=products.id WHERE products.id=?) ORDER BY products_locations.store ASC";
  16. $res =& $pdb->getCol($sql, 0, array($_GET['region'], $_GET['id']));
  17. if (PEAR::isError($res))
  18. die("Problem getting store list: " . $res->getMessage());
  19. $stores = $res;
  20. }
  21. else {
  22. $res =& $pdb->getAll("SELECT products.*, products_categories.parentcat as parentcat, products_categories.name AS catname FROM products LEFT JOIN products_categories ON products.category=products_categories.id ORDER BY products_categories.weight ASC, products.weight ASC");
  23. if (PEAR::isError($res))
  24. die("Problem when retrieving product list from the database, please try again later." . $res->getDebugInfo());
  25. $prods = array("a1" => array(),
  26. "b1" => array(),
  27. "c1" => array(),
  28. "d1" => array());
  29. foreach ($res as $r) {
  30. if ($r['parentcat'] == "kens")
  31. $r['name'] = ucwords(strtolower($r['catname'])) . " " . $r['name'];
  32. $prods[$r['parentcat']][] = $r;
  33. }
  34. $res =& $pdb->getCol("SELECT DISTINCT region FROM products_locations ORDER BY region ASC", 0);
  35. if (PEAR::isError($res))
  36. die("Problem getting region names. " . $res->getMessage());
  37. $regions = $res;
  38. }
  39. ?>
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  41. <html>
  42. <head>
  43. <!-- some header stuff like jquery and custom js files -->
  44. <script type="text/javascript">
  45. <?php if (isset($prods)) {
  46. echo "var prods = {\n";
  47. foreach ($prods as $k => $pl) {
  48. echo "\"$k\": [";
  49. foreach ($pl as $p)
  50. echo "{\"id\":\"" . $p['id'] . "\", \"name\": \"" . $p['name'] . "\"},";
  51. echo "],";
  52. }
  53. echo "};";
  54. } ?>
  55.  
  56. </script>
  57. <script type="text/javascript">
  58. $(document).ready(function(){
  59. $("select :first-child").each(function () {
  60. $(this).attr("selected", true);
  61. });
  62. $("#disabled").prepend('<option class="selectProd" value="0">Select a Product</option>');
  63. $([]).preload(['img/btn_buy_on.gif', 'img/btn_find_another_on.gif']); MM_preloadImages('img/map_central.png','img/map_pac-northwest.png','img/map_mid-central.png','img/map_mid-atlantic.png','img/map-northeast.png','img/map_north-midwest.png','img/map_california-nevada.png','img/map-southwest.png','img/map_southeast.png');
  64. $('#disabled').attr('disabled', 'true');
  65. $('#disabled').css('opacity','0.5');
  66. var sel = $('select[name="products"]');
  67. $('select[name="cat"]').change(function(e) {
  68. sel.children('option').remove();
  69. if ($("select[name='cat']").attr("selectedIndex") == "0"){
  70. $("#overlay").show();
  71. $("#disabled").prepend('<option class="selectProd" value="0">Select a Product</option>');
  72. $('#disabled').css('opacity','0.5');
  73. $('#disabled').attr('disabled', 'true');
  74. } else{
  75. $('#disabled').removeAttr('disabled').css('opacity','1');
  76. $("#disabled").prepend("<option class='selectProd' value='0'>Select a Product</option>");
  77. }
  78. var k = $(this).attr('value');
  79.  
  80. // the problem is with the for loop. I'm getting an error that says prod.id null or not an object.
  81. for (var i = 0; i < prods[k].length; i++){
  82. prod = prods[k][i];
  83. sel.append('<option value=\'' + prod.id + '\'>' + prod.name + '</option>');
  84. }
  85. });
  86.  
  87. $('select[name="products"]').change(function(e) {
  88. if($("select[name='products']").val() == 0){
  89. $("#overlay").show();
  90. } else{
  91. $("#overlay").hide();
  92. }
  93. });
  94.  
  95. $('area').click(function(e) {
  96. var id = $('select[name="products"]').attr('value');
  97. if (id == '') {
  98. window.alert("Please select a product/category!");
  99. } else {
  100. var url = '<?=$_SERVER['PHP_SELF']?>?id=' + id + '&region=' + $(this).data('region');
  101. window.location = url;
  102. }
  103. e.preventDefault();
  104. });
  105. <?php if (isset($pV)) { ?>
  106. $('select[name="cat"]').change();
  107. $('select[name="products"]').val('<?=$pV['id']?>');
  108. <?php } ?>
  109. });
  110. </script>
  111. </head>
  112. <body>
  113. <!-- some more html code here -->
  114. <h3 style="color:#999900; padding-bottom:10px">STEP ONE&nbsp;&nbsp;&nbsp;</h3>
  115. <select name="cat" id="firstd" class="plain" style="width: 95%;">
  116. <option class="selectCat" id="ie99" value="Select a Category" selected>Select a Category</option>
  117. <?php foreach ($catnames as $k => $v) { ?>
  118. <option value="<?=$k?>"<?=(isset($pV['parentcat']) && $pV['parentcat'] == $k) ? " selected" : ""?>><?=$v?></option>
  119. <?php } ?>
  120. </select>
  121. <!-- some more html code here -->
  122. <h3 style="color:#999900; padding-bottom:10px">STEP TWO&nbsp;&nbsp;&nbsp;</h3>
  123. <select id="disabled" name="products" class="plain" style="width: 95%;">
  124. <option class="selectProd">Select a Product</option>
  125. </select>
  126. <!-- some more html code here -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement