'state', 'source_table' => $store_table, 'source_field' => 'state_id', 'join_field' => 'state_id', ); $t=new Asharp_Template(); $t->set_file('the_page',$page->folder.'stockist/list.html'); $t->set_if('the_page','isAdmin',$perm->have_perm('admin')); # strip the blocks $vars = array( "FORMBLOCK", "ERRORBLOCK", "RESULTINTRO", "STORE", ); foreach ($vars as $var) { $t->set_block("the_page", $var, strtolower($var)); $var_backups[$var] = $t->get_var($var); $t->set_var($var, ""); } # show the form unless we have a submission if (count($_POST) == 0) { $block = "FORMBLOCK"; $t->set_var($block, $var_backups[$block]); $t->parse(strtolower($block), $block, true); } else { $res = postcode_search($db, $store_table, $joins, $num_results_to_show); # set the scalar vars from res foreach ($res as $key => $value) { if (!is_array($value)) { $t->set_var($key, htmlentities($value)); } } if (isset($res["error"])) { $block = "ERRORBLOCK"; $t->set_var($block, $var_backups[$block]); $t->set_var("error_msg", $res["error"]); $t->parse(strtolower($block), $block, true); } else { $block = "RESULTINTRO"; $t->set_var($block, $var_backups[$block]); $t->parse(strtolower($block), $block, true); $block = "STORE"; $t->set_var($block, $var_backups[$block]); $vars = array( "ADDRESS1_B", "ADDRESS2_B", "PHONE_B", ); foreach ($vars as $var) { $t->set_block("STORE", $var, strtolower($var)); $var_backups[$var] = $t->get_var($var); $t->set_var($var, ""); } # insert the stores from res foreach ($res["matches"] as $num => $entry) { foreach ($entry as $key => $value) { $t->set_var($key, htmlentities(" $value")); $t->set_var("var_with_leading_zero_$key", htmlentities(sprintf(" %04d", $value))); $varskey = strtoupper($key)."_B"; if (in_array($varskey, $vars)) { if ($value != "") { $t->set_var($varskey, $var_backups[$varskey]); $t->parse(strtolower($varskey), $varskey); } else { $t->set_var($varskey, ""); $t->parse(strtolower($varskey), $varskey); } } } $t->parse(strtolower($block), $block, true); } } } $t->set_var("num_results", $num_results_to_show); $t->parse("out", "the_page"); $page->add_content($t->get('out')); $page->show(); Asharp_close(); ?>