hjkhjkjhkhjkgjghjhgjhgjghjhghjghjhgjjnbvnvbnvk
bnmbnmbnhjkhjkhjkhjktyutyutyuytutyutyutyhgjgjghjgjghjguytutyry
/
home
/
wjcvelqp
/
public_html
/
vc
/
Upload FileeE
HOME
<?php declare(strict_types=1); require_once __DIR__ . '/includes/bootstrap.php'; /* |-------------------------------------------------------------------------- | VILLAGECONNECT NIGERIA — COMMUNITY DIRECTORY |-------------------------------------------------------------------------- | Features: | - Search approved communities | - Filter by state and LGA | - Dynamic state-to-LGA selection | - Submit missing communities | - Admin approval workflow |-------------------------------------------------------------------------- */ $q = clean_string($_GET['q'] ?? '', 120); $state_id = (int)($_GET['state_id'] ?? 0); $lga_id = (int)($_GET['lga_id'] ?? 0); $page = max(1, (int)($_GET['page'] ?? 1)); $states = []; $allLgas = []; $items = []; $total = 0; $p = paginate(0, 1); $error = ''; /* |-------------------------------------------------------------------------- | LOAD STATES AND LGAS |-------------------------------------------------------------------------- */ try { $states = db()->query( 'SELECT id, name FROM states ORDER BY name ASC' )->fetchAll(); $allLgas = db()->query( 'SELECT id, state_id, name FROM local_governments ORDER BY name ASC' )->fetchAll(); } catch (Throwable $e) { $error = 'Unable to load locations. Please try again later.'; } /* |-------------------------------------------------------------------------- | SEARCH AND FILTER COMMUNITIES |-------------------------------------------------------------------------- */ if ($error === '') { $conditions = ['c.is_approved = 1']; $params = []; if ($q !== '') { $conditions[] = 'c.name LIKE ?'; $params[] = '%' . $q . '%'; } if ($state_id > 0) { $conditions[] = 'c.state_id = ?'; $params[] = $state_id; } if ($lga_id > 0) { $conditions[] = 'c.lga_id = ?'; $params[] = $lga_id; } $where = implode(' AND ', $conditions); try { // Count matching communities. $countSql = " SELECT COUNT(*) FROM communities c WHERE {$where} "; $stmt = db()->prepare($countSql); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $p = paginate($total, $page); // Fetch communities. $sql = " SELECT c.*, s.name AS state_name, lg.name AS lga_name FROM communities c INNER JOIN states s ON s.id = c.state_id LEFT JOIN local_governments lg ON lg.id = c.lga_id WHERE {$where} ORDER BY c.name ASC LIMIT {$p['per_page']} OFFSET {$p['offset']} "; $stmt = db()->prepare($sql); $stmt->execute($params); $items = $stmt->fetchAll(); } catch (Throwable $e) { $error = 'Unable to retrieve communities. Please try again.'; } } /* |-------------------------------------------------------------------------- | SUBMIT A MISSING COMMUNITY |-------------------------------------------------------------------------- */ if (is_post() && isset($_POST['submit_village'])) { auth_require(); csrf_require(); $name = clean_string($_POST['name'] ?? '', 150); $sid = (int)($_POST['state_id'] ?? 0); $lid = (int)($_POST['lga_id'] ?? 0); $desc = clean_text($_POST['description'] ?? '', 2000); if ($name === '' || $sid < 1 || $lid < 1) { flash('error', 'Community name, state and LGA are required.'); } else { try { // Confirm that the selected state exists. $stateCheck = db()->prepare( 'SELECT id FROM states WHERE id = ? LIMIT 1' ); $stateCheck->execute([$sid]); if (!$stateCheck->fetch()) { flash('error', 'Please select a valid state.'); } else { // Confirm that the LGA belongs to the selected state. $lgaCheck = db()->prepare( 'SELECT id FROM local_governments WHERE id = ? AND state_id = ? LIMIT 1' ); $lgaCheck->execute([$lid, $sid]); if (!$lgaCheck->fetch()) { flash('error', 'The selected LGA does not belong to that state.'); } else { // Check whether the community is already registered. $duplicate = db()->prepare( 'SELECT id FROM communities WHERE state_id = ? AND lga_id = ? AND name = ? LIMIT 1' ); $duplicate->execute([$sid, $lid, $name]); if ($duplicate->fetch()) { flash('error', 'This community already exists in the directory.'); } else { /* * The database column is called notes, * not description. */ $insert = db()->prepare( "INSERT INTO village_submissions ( user_id, state_id, lga_id, name, notes, status, created_at ) VALUES (?, ?, ?, ?, ?, 'pending', NOW())" ); $insert->execute([ auth_id(), $sid, $lid, $name, $desc ]); flash( 'success', 'Your community has been submitted successfully. It will appear after administrator approval.' ); } } } } catch (Throwable $e) { flash('error', 'Something went wrong while submitting the community.'); } } redirect('communities.php'); } /* |-------------------------------------------------------------------------- | PAGE SETTINGS |-------------------------------------------------------------------------- */ $query = $_GET; unset($query['page']); $baseUrl = url('communities.php') . ($query ? '?' . http_build_query($query) : ''); $page_title = 'Communities — ' . VC_APP_NAME; $nav = 'communities'; include __DIR__ . '/includes/header.php'; ?> <div class="page"> <div class="container"> <div class="page-header"> <h1>Community Directory</h1> <p class="muted"> Discover communities, towns and villages across Nigeria. Search by name or narrow your results by state and LGA. </p> </div> <?php if ($error !== ''): ?> <div class="alert alert-error"> <?= e($error) ?> </div> <?php endif; ?> <!-- SEARCH AND FILTER --> <div class="detail"> <h2>Find a Community</h2> <form method="get" action="<?= e(url('communities.php')) ?>"> <div class="form-group"> <label for="searchCommunity"> Search Community </label> <input type="search" name="q" id="searchCommunity" placeholder="Enter community, town or village name" value="<?= e($q) ?>" > </div> <div class="form-group"> <label for="cState">State</label> <select name="state_id" id="cState" data-lga-target="cLga" > <option value="">All States</option> <?php foreach ($states as $s): ?> <option value="<?= (int)$s['id'] ?>" <?= $state_id === (int)$s['id'] ? 'selected' : '' ?> > <?= e($s['name']) ?> </option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label for="cLga">Local Government Area</label> <select name="lga_id" id="cLga" data-selected="<?= $lga_id ?>" > <option value="">All LGAs</option> <?php foreach ($allLgas as $lga): ?> <option value="<?= (int)$lga['id'] ?>" data-state="<?= (int)$lga['state_id'] ?>" <?= $lga_id === (int)$lga['id'] ? 'selected' : '' ?> > <?= e($lga['name']) ?> </option> <?php endforeach; ?> </select> </div> <button class="btn btn-primary" type="submit"> Search Communities </button> <a href="<?= e(url('communities.php')) ?>" class="btn" > Clear Filters </a> </form> </div> <!-- COMMUNITY RESULTS --> <div class="page-header" style="margin-top:30px"> <h2>Available Communities</h2> <p class="muted"> <?= number_format($total) ?> approved communities found. </p> </div> <?php if (empty($items)): ?> <div class="empty"> <h3>No communities found</h3> <p> We could not find a community matching your search. You can submit a missing community below. </p> </div> <?php else: ?> <div class="grid grid-2 grid-3"> <?php foreach ($items as $c): ?> <article class="card"> <div class="card-body"> <h3> <a href="<?= e(url( 'community-details.php?id=' . (int)$c['id'] )) ?>"> <?= e($c['name']) ?> </a> </h3> <div class="meta"> <?= e($c['lga_name'] ?? 'LGA not specified') ?>, <?= e($c['state_name']) ?> </div> </div> </article> <?php endforeach; ?> </div> <?= pagination_html($p, $baseUrl) ?> <?php endif; ?> <!-- SUBMIT A MISSING COMMUNITY --> <div class="detail" style="margin-top:35px"> <h2>Can't Find Your Community?</h2> <p class="muted"> Help us expand VillageConnect Nigeria by submitting your town, village or community. </p> <?php if (!auth_check()): ?> <p> Please <a href="<?= e(url('login.php')) ?>">log in</a> or <a href="<?= e(url('register.php')) ?>">create an account</a> before submitting a community. </p> <?php else: ?> <form method="post"> <?= csrf_field() ?> <div class="form-group"> <label for="subName"> Community / Village Name </label> <input type="text" name="name" id="subName" maxlength="150" placeholder="Enter your community name" required > </div> <div class="form-group"> <label for="subState">State</label> <select name="state_id" id="subState" data-lga-target="subLga" required > <option value="">Select State</option> <?php foreach ($states as $s): ?> <option value="<?= (int)$s['id'] ?>"> <?= e($s['name']) ?> </option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label for="subLga">Local Government Area</label> <select name="lga_id" id="subLga" required > <option value="">Select LGA</option> <?php foreach ($allLgas as $lga): ?> <option value="<?= (int)$lga['id'] ?>" data-state="<?= (int)$lga['state_id'] ?>" > <?= e($lga['name']) ?> </option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label for="subDescription"> Description (Optional) </label> <textarea name="description" id="subDescription" rows="4" maxlength="2000" placeholder="Tell us something about this community..." ></textarea> </div> <button class="btn btn-primary" type="submit" name="submit_village" value="1" > Submit Community for Review </button> </form> <?php endif; ?> </div> </div> </div> <!-- STATE AND LGA FILTER SCRIPT --> <script> document.addEventListener('DOMContentLoaded', function () { function setupLocationDropdown(stateSelect) { const targetId = stateSelect.dataset.lgaTarget; const lgaSelect = document.getElementById(targetId); if (!lgaSelect) { return; } const allOptions = Array.from( lgaSelect.querySelectorAll('option[data-state]') ); const selectedLga = lgaSelect.dataset.selected || ''; function updateLgas() { const selectedState = stateSelect.value; lgaSelect.innerHTML = ''; const firstOption = document.createElement('option'); firstOption.value = ''; firstOption.textContent = targetId === 'cLga' ? 'All LGAs' : 'Select LGA'; lgaSelect.appendChild(firstOption); allOptions.forEach(function (option) { if ( selectedState !== '' && option.dataset.state === selectedState ) { const newOption = option.cloneNode(true); if (newOption.value === selectedLga) { newOption.selected = true; } lgaSelect.appendChild(newOption); } }); } stateSelect.addEventListener('change', function () { lgaSelect.dataset.selected = ''; updateLgas(); }); updateLgas(); } document .querySelectorAll('select[data-lga-target]') .forEach(setupLocationDropdown); }); </script> <?php include __DIR__ . '/includes/footer.php'; ?>