Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $catnames = array("a1" => "A1's Products",
- "b1" => "b1's Products",
- "c1" => "c1's Products",
- "d1" => "d1's Products");
- if (isset($_GET['id'])) {
- $sql = "SELECT products.*, products_categories.parentcat FROM products LEFT JOIN products_categories ON products.category=products_categories.id WHERE products.id=?";
- $pV = $pdb->getRow($sql, array($_GET['id']));
- if (PEAR::isError($pV) || $pV == NULL)
- die("There was a problem retrieving the product from the database. Please try again later.");
- }
- if (isset($_GET['id']) && isset($_GET['region'])) {
- $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";
- $res =& $pdb->getCol($sql, 0, array($_GET['region'], $_GET['id']));
- if (PEAR::isError($res))
- die("Problem getting store list: " . $res->getMessage());
- $stores = $res;
- }
- else {
- $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");
- if (PEAR::isError($res))
- die("Problem when retrieving product list from the database, please try again later." . $res->getDebugInfo());
- $prods = array("a1" => array(),
- "b1" => array(),
- "c1" => array(),
- "d1" => array());
- foreach ($res as $r) {
- if ($r['parentcat'] == "kens")
- $r['name'] = ucwords(strtolower($r['catname'])) . " " . $r['name'];
- $prods[$r['parentcat']][] = $r;
- }
- $res =& $pdb->getCol("SELECT DISTINCT region FROM products_locations ORDER BY region ASC", 0);
- if (PEAR::isError($res))
- die("Problem getting region names. " . $res->getMessage());
- $regions = $res;
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <!-- some header stuff like jquery and custom js files -->
- <script type="text/javascript">
- <?php if (isset($prods)) {
- echo "var prods = {\n";
- foreach ($prods as $k => $pl) {
- echo "\"$k\": [";
- foreach ($pl as $p)
- echo "{\"id\":\"" . $p['id'] . "\", \"name\": \"" . $p['name'] . "\"},";
- echo "],";
- }
- echo "};";
- } ?>
- </script>
- <script type="text/javascript">
- $(document).ready(function(){
- $("select :first-child").each(function () {
- $(this).attr("selected", true);
- });
- $("#disabled").prepend('<option class="selectProd" value="0">Select a Product</option>');
- $([]).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');
- $('#disabled').attr('disabled', 'true');
- $('#disabled').css('opacity','0.5');
- var sel = $('select[name="products"]');
- $('select[name="cat"]').change(function(e) {
- sel.children('option').remove();
- if ($("select[name='cat']").attr("selectedIndex") == "0"){
- $("#overlay").show();
- $("#disabled").prepend('<option class="selectProd" value="0">Select a Product</option>');
- $('#disabled').css('opacity','0.5');
- $('#disabled').attr('disabled', 'true');
- } else{
- $('#disabled').removeAttr('disabled').css('opacity','1');
- $("#disabled").prepend("<option class='selectProd' value='0'>Select a Product</option>");
- }
- var k = $(this).attr('value');
- // the problem is with the for loop. I'm getting an error that says prod.id null or not an object.
- for (var i = 0; i < prods[k].length; i++){
- prod = prods[k][i];
- sel.append('<option value=\'' + prod.id + '\'>' + prod.name + '</option>');
- }
- });
- $('select[name="products"]').change(function(e) {
- if($("select[name='products']").val() == 0){
- $("#overlay").show();
- } else{
- $("#overlay").hide();
- }
- });
- $('area').click(function(e) {
- var id = $('select[name="products"]').attr('value');
- if (id == '') {
- window.alert("Please select a product/category!");
- } else {
- var url = '<?=$_SERVER['PHP_SELF']?>?id=' + id + '®ion=' + $(this).data('region');
- window.location = url;
- }
- e.preventDefault();
- });
- <?php if (isset($pV)) { ?>
- $('select[name="cat"]').change();
- $('select[name="products"]').val('<?=$pV['id']?>');
- <?php } ?>
- });
- </script>
- </head>
- <body>
- <!-- some more html code here -->
- <h3 style="color:#999900; padding-bottom:10px">STEP ONE </h3>
- <select name="cat" id="firstd" class="plain" style="width: 95%;">
- <option class="selectCat" id="ie99" value="Select a Category" selected>Select a Category</option>
- <?php foreach ($catnames as $k => $v) { ?>
- <option value="<?=$k?>"<?=(isset($pV['parentcat']) && $pV['parentcat'] == $k) ? " selected" : ""?>><?=$v?></option>
- <?php } ?>
- </select>
- <!-- some more html code here -->
- <h3 style="color:#999900; padding-bottom:10px">STEP TWO </h3>
- <select id="disabled" name="products" class="plain" style="width: 95%;">
- <option class="selectProd">Select a Product</option>
- </select>
- <!-- some more html code here -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement