File: /srv/www/rectt-csmcri.res.in/admin_html/view_primary.php
<?php
// session_start();
require_once dirname(__DIR__) . '/public_html/sites/config/config.php';
if (!isset($_SESSION['admin_logged_in']) || !in_array($_SESSION['admin_role'], ['superadmin', 'manager', 'reviewer'])) {
header("Location: admin_dashboard.php");
// echo $_SESSION['admin_role'];
exit;
}
// 1) basic session checks
if (
empty($_SESSION['admin_id']) || empty($_SESSION['session_token'])
) {
header("Location: admin_login.php");
exit;
}
// 2) pull the token (and role) from the database
$stmt = $conn->prepare("SELECT session_token FROM admin_users WHERE id = ?");
$stmt->bind_param("i", $_SESSION['admin_id']);
$stmt->execute();
$result = $stmt->get_result()->fetch_assoc();
$stmt->close();
// 3) if the DB token is gone or doesn’t match the session’s, force logout
if (
! $result || $result['session_token'] !== $_SESSION['session_token']
) {
session_unset();
session_destroy();
header("Location: admin_login.php?error=" . urlencode("Your session has expired."));
exit;
}
// Fetch and render Primary Details for a user with Bootstrap styling
function getPrimaryDetailsHtml_BS($user_id)
{
global $conn;
// Fetch primary details
$stmt = $conn->prepare("SELECT * FROM primary_details WHERE user_id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$res = $stmt->get_result();
$d = $res->fetch_assoc();
// Fetch relatives if needed
$relatives = [];
if ($d && strtolower($d['relative_in_csir']) == 'yes') {
$stmt2 = $conn->prepare("SELECT * FROM relatives WHERE user_id = ?");
$stmt2->bind_param("i", $user_id);
$stmt2->execute();
$relatives = $stmt2->get_result()->fetch_all(MYSQLI_ASSOC);
}
// Helper functions
$fieldval = function ($val) {
return $val ? htmlspecialchars($val) : '<em class="text-muted">-</em>';
};
$yesno = function ($v) {
return (strtolower($v) === 'yes') ? 'Yes' : 'No';
};
$addr_line = function ($h, $city, $dist, $state, $pin) {
$addr = trim($h);
if ($city) $addr .= ', ' . $city;
if ($dist && stripos($addr, $dist) === false) $addr .= ', ' . $dist;
if ($state && stripos($addr, $state) === false) $addr .= ', ' . $state;
if ($pin) $addr .= ', ' . $pin;
return $addr;
};
ob_start();
?>
<div class="container my-4">
<div class="card shadow-sm mb-4 max-card-width">
<div class="card shadow-sm">
<div class="card-body">
<h4 class="card-title mb-4 text-primary">Primary Details</h4>
<?php if ($d): ?>
<div class="section-title">Personal Information</div>
<table class="table table-bordered mb-4">
<tbody>
<tr>
<th>Name as per 10<sup>th</sup> certificate</th>
<td><?= $fieldval($d['ssc_name']) ?></td>
</tr>
<tr>
<th>Name Ever Changed</th>
<td><?= $yesno($d['has_name_changed']) ?></td>
</tr>
<?php if (strtolower($d['has_name_changed']) === 'yes'): ?>
<tr>
<th>New Name</th>
<td><?= $fieldval($d['new_name']) ?></td>
</tr>
<?php endif; ?>
<tr>
<th>Father's Name</th>
<td><?= $fieldval($d['father_name']) ?></td>
</tr>
<tr>
<th>Mother's Name</th>
<td><?= $fieldval($d['mother_name']) ?></td>
</tr>
<tr>
<th>Date of Birth</th>
<td><?= $d['dob'] ? date('d-m-Y', strtotime($d['dob'])) : '<em class="text-muted">-</em>' ?></td>
</tr>
<tr>
<th>Age</th>
<td>
<?php
if ($d['dob']) {
$from = new DateTime($d['dob']);
$to = new DateTime('today');
$diff = $from->diff($to);
echo "{$diff->y} years {$diff->m} months {$diff->d} days";
} else {
echo '<em class="text-muted">-</em>';
}
?>
</td>
</tr>
<tr>
<th>Place of Birth</th>
<td><?= $fieldval($d['place_ob']) ?></td>
</tr>
<tr>
<th>Gender</th>
<td><?= $fieldval($d['gender']) ?></td>
</tr>
<tr>
<th>Religion</th>
<td><?= $fieldval($d['religion']) ?></td>
</tr>
<tr>
<th>Citizenship</th>
<td><?= $fieldval($d['citizenship']) ?></td>
</tr>
</tbody>
</table>
<div class="section-title">Disability & Reservation</div>
<table class="table table-bordered mb-4">
<tbody>
<tr>
<th>Are you Physically Disabled (>=40%)</th>
<td><?= $yesno($d['disability']) ?></td>
</tr>
<tr>
<th>
a) Hard of hearing<br>
b) Locomotor disability<br>
c) Multiple disabilities
</th>
<td>
a) <?= $yesno($d['disability_hearing']) ?><br>
b) <?= $yesno($d['disability_walking']) ?><br>
c) <?= $yesno($d['disability_multiple']) ?>
</td>
</tr>
<tr>
<th>Category</th>
<td><?= $fieldval($d['category']) ?></td>
</tr>
</tbody>
</table>
<div class="section-title">Service & Employment</div>
<table class="table table-bordered mb-4">
<tbody>
<tr>
<th>Are you Ex-Servicemen</th>
<td><?= $yesno($d['ex_servicemen']) ?></td>
</tr>
<tr>
<th>Length of service in Armed Forces</th>
<td>
<?php
if (strtolower($d['ex_servicemen']) === 'yes') {
echo ($d['service_years'] ?? '0') . ' Years, ' . ($d['service_months'] ?? '0') . ' Months, ' . ($d['service_days'] ?? '0') . ' Days';
} else {
echo '<em class="text-muted">-</em>';
}
?>
</td>
</tr>
<tr>
<th>Are you permanent Govt/Autonomous/Semi Govt/PSU employee?</th>
<td><?= $yesno($d['gov_employee']) ?></td>
</tr>
<tr>
<th>Org. & Post (if yes)</th>
<td><?= (strtolower($d['gov_employee']) === 'yes') ? $fieldval($d['gov_organization'] . ', ' . $d['gov_post']) : '<em class="text-muted">-</em>'; ?></td>
</tr>
<tr>
<th>Are you CSIR Employee?</th>
<td><?= $yesno($d['csir_employee']) ?></td>
</tr>
<tr>
<th>Institute / lab & Designation</th>
<td><?= (strtolower($d['csir_employee']) === 'yes') ? $fieldval($d['csir_lab'] . ', ' . $d['csir_designation']) : '<em class="text-muted">-</em>'; ?></td>
</tr>
</tbody>
</table>
<div class="section-title">Marital & Contact Details</div>
<table class="table table-bordered mb-4">
<tbody>
<tr>
<th>Marital Status</th>
<td><?= $fieldval($d['marital_status']) ?></td>
</tr>
<tr>
<th>Are you staying abroad?</th>
<td><?= $yesno($d['staying_abroad']) ?></td>
</tr>
<tr>
<th>Address for Correspondence</th>
<td><?= $fieldval($addr_line($d['corr_house'], $d['corr_city'], $d['corr_district'], $d['corr_state'], $d['corr_pincode'])) ?></td>
</tr>
<tr>
<th>Permanent Address</th>
<td><?= $fieldval($addr_line($d['perm_house'], $d['perm_city'], $d['perm_district'], $d['perm_state'], $d['perm_pincode'])) ?></td>
</tr>
<tr>
<th>Email</th>
<td><?= $fieldval($d['email']) ?></td>
</tr>
<tr>
<th>Secondary Email</th>
<td><?= $fieldval($d['secondary_email']) ?></td>
</tr>
<tr>
<th>Mobile</th>
<td><?= $fieldval($d['mobile']) ?></td>
</tr>
<tr>
<th>Alternate Mobile</th>
<td><?= $fieldval($d['alt_mobile']) ?></td>
</tr>
</tbody>
</table>
<div class="section-title">Relatives in CSIR</div>
<table class="table table-bordered mb-4">
<tbody>
<tr>
<th>Any relative in CSIR?</th>
<td><?= $yesno($d['relative_in_csir']) ?></td>
</tr>
</tbody>
</table>
<?php if (count($relatives) > 0): ?>
<div class="mb-3">
<table class="table table-bordered table-sm">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Post</th>
<th>Lab/Institute</th>
<th>Relationship</th>
</tr>
</thead>
<tbody>
<?php foreach ($relatives as $rel): ?>
<tr>
<td><?= $fieldval($rel['relative_name']) ?></td>
<td><?= $fieldval($rel['post']) ?></td>
<td><?= $fieldval($rel['lab_institute']) ?></td>
<td><?= $fieldval($rel['relationship']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<?php else: ?>
<div class="alert alert-danger text-center">No data found.</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
// $data = getPrimaryDetailsHtml_BS(15);
// Example: Output for testing (remove/comment this in production)
// echo $data;
?>