GetAssoc("SELECT county_id, county_name_$lang FROM counties ORDER BY county_name_$lang"); $tpl->assign('counties', $counties); $resources = $db->GetAssoc("SELECT resource_id, resource_name_$lang FROM resource_types ORDER BY " . get_resource_order($lang)); $tpl->assign('resources', $resources); $tpl->display("resources_county_form_$lang.tpl"); } // Select language if (!isset($lang)) { $lang = 'en'; } // Initialize classes $tpl =& get_tpl(); $db =& get_db(); if (count($_GET) == 0) { // User did not submit the form display_form($db, $tpl); } else { // Display search results // Build query $params = array(); $conds = array(); $level1_column = "county_name_$lang"; $level2_column = "resource_name_$lang"; if ($_GET['resource'] != '') { $conds[] = 'cs.resource_id = ?'; $params[] = $_GET['resource']; $level1_column = "resource_name_$lang"; $level2_column = "county_name_$lang"; } if ($_GET['county'] != '') { $conds[] = 'cs.county_id = ?'; $params[] = $_GET['county']; $level1_column = "county_name_$lang"; $level2_column = "resource_name_$lang"; } $sql_where = ''; if (count($conds) > 0) { $sql_where = 'WHERE ' . implode(' AND ', $conds); } $sql = "SELECT cs.*, c.county_name_en, c.county_name_sp, cs.webinfo, rt.resource_name_en, rt.resource_name_sp FROM county_services AS cs INNER JOIN counties AS c ON cs.county_id = c.county_id INNER JOIN resource_types AS rt ON cs.resource_id = rt.resource_id $sql_where ORDER BY c.county_name_$lang, " . get_resource_order($lang) . ", cs.resource_en"; $resources = $db->GetAll($sql, $params); // Group resources by $level1_column $nested_resources = array(); foreach ($resources as $resource) { $level1_value = $resource[$level1_column]; if (!array_key_exists($level1_value, $nested_resources)) { $nested_resources[$level1_value] = array(); } $nested_resources[$level1_value][] = $resource; } $tpl->assign('nested_resources', $nested_resources); $tpl->assign('level2_column', $level2_column); $tpl->assign('county_id', $_GET['county']); $tpl->assign('resource_id', $_GET['resource']); $tpl->display("resources_county_$lang.tpl"); } ?>