« Back to History
employee_portal.php
|
20260921_175631.php
Initial Domain Snapshot
Copy Code
<?php /* ========================================================= File: /erp/public/employee_portal.php Purpose: Role-wise Employee Portal (login stays on same page) ========================================================= */ error_reporting(E_ALL); ini_set('display_errors', 1); $BASE = dirname(__DIR__); // /erp require $BASE . '/core/db.php'; require_once $BASE . '/modules/auth/auth.php'; $pdo = $GLOBALS['pdo'] ?? $pdo ?? null; /* ---------------- URL MAP (edit if needed) ---------------- */ $URL_MAP = [ 'beam_entry' => '/erp/public/warper_beam_entry.php', 'show_patia' => '/erp/public/index.php?widget=patia', 'yarn_entry' => '/erp/public/index.php?page=yarn_entry', 'yarn_records' => '/erp/public/index.php?page=yarn_records', 'machine' => '/erp/public/index.php?page=machine', 'pissing_entry' => '/erp/public/index.php?page=pissing_entry', 'pissing_records' => '/erp/public/index.php?page=pissing_records', 'pasaria_entry' => '/erp/public/index.php?page=pasaria_entry', 'pasaria_records' => '/erp/public/index.php?page=pasaria_records', 'production_entry' => '/erp/public/index.php?page=production_entry', // common 'salary_report' => '/erp/public/index.php?report=salary', 'change_password' => '/erp/public/change_password.php', 'leave_request' => '/erp/public/leave_request.php', 'advance_request' => '/erp/public/advance_request.php', 'my_profile' => '/erp/public/profile.php', 'bank_details' => '/erp/public/bank_details.php', ]; /* ---------------- Labels ---------------- */ $LABELS_DEFAULT = [ 'beam_entry' => 'Beam Entry', 'show_patia' => 'Beam Card', 'yarn_entry' => 'Yarn Entry', 'yarn_records' => 'Entry Record', 'machine' => 'Machine', 'pissing_entry' => 'Pissing Entry', 'pissing_records' => 'Entry Record', 'pasaria_entry' => 'Pasaria Entry', 'pasaria_records' => 'Entry Record', 'production_entry' => 'Production Entry', 'salary_report' => 'Salary Report', 'change_password' => 'Change Password', 'leave_request' => 'Leave Request', 'advance_request' => 'Advance Request', 'my_profile' => 'Edit Profile', 'bank_details' => 'Add / Edit Bank Details', ]; /* ---------------- Small helpers ---------------- */ function table_exists(PDO $pdo, string $name): bool { try { $s=$pdo->query("SHOW TABLES LIKE ".$pdo->quote($name)); return (bool)$s->fetch(); } catch(Throwable $e){ return false; } } function col_exists(PDO $pdo, string $table, string $col): bool { try { $s=$pdo->prepare("SHOW COLUMNS FROM `$table` LIKE ?"); $s->execute([$col]); return (bool)$s->fetch(); } catch(Throwable $e){ return false; } } function get_company_setting(PDO $pdo, int $company_id, string $key, $default=null){ if (!table_exists($pdo,'company_settings')) return $default; try{ $s=$pdo->prepare("SELECT value FROM company_settings WHERE company_id=? AND `key`=? LIMIT 1"); $s->execute([$company_id,$key]); $row=$s->fetch(PDO::FETCH_ASSOC); if(!$row) return $default; $v=$row['value']; $vl=strtolower(trim((string)$v)); if (is_numeric($v)) return (int)$v; if (in_array($vl,['true','false','yes','no','on','off'],true)) return in_array($vl,['true','yes','on'],true); return $v; }catch(Throwable $e){ return $default; } } function pick_col(?array $row=null, array $candidates=[]){ if(!$row) return null; foreach($candidates as $c){ if(isset($row[$c]) && trim((string)$row[$c])!=='') return trim((string)$row[$c]); } return null; } function role_norm($r){ $k = mb_strtolower(trim((string)$r)); $map = [ 'warper'=>'Warper','karigar'=>'Karigar', 'rapier'=>'Rapier Karigar','rapier karigar'=>'Rapier Karigar','rapier-karigar'=>'Rapier Karigar', 'pissing'=>'Pissing','pasaria'=>'Pasaria', 'kandi'=>'Kandi','kandiya'=>'Kandi','kandhi'=>'Kandi','bobin'=>'Kandi','bobbin'=>'Kandi', 'folder'=>'Folder','foldr'=>'Folder','foldar'=>'Folder', 'owner'=>'Owner','admin'=>'Admin','manager'=>'Manager','developer'=>'Developer','employee'=>'Employee','user'=>'Employee' ]; return $map[$k] ?? (strlen($k)?ucwords($k):'Employee'); } /* ---------------- Logout ---------------- */ if (isset($_GET['logout'])) { auth_logout(); header("Location: ".$_SERVER['PHP_SELF']); exit; } /* ---------------- Build profile/role/menu ---------------- */ $u = auth_user(); if (!$u) { $next = '/erp/public/employee_portal.php'; header('Location: /erp/public/login.php?next=' . rawurlencode($next)); exit; } $profile = ['dp_url'=>null,'khata'=>'','loom_range'=>'','company_name'=>'Company Name']; $COMMON_ALWAYS = ['salary_report','change_password','leave_request','advance_request','my_profile','bank_details']; $DISPLAY_NAME = 'Employee'; $DISPLAY_ROLE = 'Employee'; $ROLE_2 = []; $labelOverrides = $LABELS_DEFAULT; if ($u) { $user_id = (int)$u['id']; $company_id = (int)$u['company_id']; if (table_exists($pdo,'companies')) { try { $st=$pdo->prepare("SELECT name FROM companies WHERE id=? LIMIT 1"); $st->execute([$company_id]); if($r=$st->fetch(PDO::FETCH_ASSOC)) $profile['company_name']=$r['name']; } catch(Throwable $e){} } $empRow = null; if (table_exists($pdo,'employees')) { try { $st=$pdo->prepare("SELECT * FROM employees WHERE user_id=? AND company_id=? LIMIT 1"); $st->execute([$user_id,$company_id]); $empRow=$st->fetch(PDO::FETCH_ASSOC) ?: null; } catch(Throwable $e){} } $DISPLAY_NAME = pick_col($empRow, ['name','emp_name','full_name','employee_name']) ?? ($u['name'] ?? 'Employee'); $ROLE = role_norm(pick_col($empRow, ['role','designation','post','job_role','dept_role','department','duty','category']) ?: ($u['role'] ?? 'Employee')); $DISPLAY_ROLE = $ROLE; try { if (table_exists($pdo,'profiles') && col_exists($pdo,'profiles','dp_file_id')) { $s=$pdo->prepare("SELECT dp_file_id FROM profiles WHERE user_id=? LIMIT 1"); $s->execute([$user_id]); if($r=$s->fetch(PDO::FETCH_ASSOC)){ $fid=(int)$r['dp_file_id']; if ($fid && table_exists($pdo,'files') && col_exists($pdo,'files','path')) { $f=$pdo->prepare("SELECT path FROM files WHERE id=? LIMIT 1"); $f->execute([$fid]); if($fr=$f->fetch(PDO::FETCH_ASSOC)) $profile['dp_url']='/'.$fr['path']; } } } elseif (col_exists($pdo,'users','dp_url')) { $s=$pdo->prepare("SELECT dp_url FROM users WHERE id=? LIMIT 1"); $s->execute([$user_id]); if($r=$s->fetch(PDO::FETCH_ASSOC)) $profile['dp_url']=$r['dp_url']; } if ($empRow) { $profile['khata'] = pick_col($empRow, ['khata_code','khata']) ?: ''; $lf=(int)($empRow['loom_from']??0); $lt=(int)($empRow['loom_to']??0); if ($lf && $lt) $profile['loom_range']=sprintf('Loom %02d – Loom %02d',$lf,$lt); } } catch(Throwable $e){} switch ($ROLE) { case 'Warper': $ROLE_2 = ['beam_entry','show_patia']; $labelOverrides['show_patia']='Beam Card'; break; case 'Folder': $ROLE_2 = ['production_entry','show_patia']; $labelOverrides['show_patia']='Patia'; break; case 'Kandi': $ROLE_2 = ['yarn_entry','yarn_records']; break; case 'Karigar': $ROLE_2 = ['show_patia','machine']; $labelOverrides['show_patia']='Patia'; break; case 'Rapier Karigar': $ROLE_2 = ['yarn_entry','yarn_records']; break; case 'Pissing': $ROLE_2 = ['pissing_entry','pissing_records']; break; case 'Pasaria': $ROLE_2 = ['pasaria_entry','pasaria_records']; break; default: $ROLE_2 = ['show_patia','machine']; $labelOverrides['show_patia']='Patia'; } $advEnabled = get_company_setting($pdo,$company_id,'enable_advance_request',true); if (!$advEnabled) $COMMON_ALWAYS = array_values(array_filter($COMMON_ALWAYS, fn($s)=>$s!=='advance_request')); } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> <title><?=htmlspecialchars($DISPLAY_ROLE)?> Portal • Mr. Manager</title> <style> :root{ --primary:#34A853; --bg:#F5FFF7; --accent:#A7D8DE; --text:#202124; } *{box-sizing:border-box} html,body{height:100%} body{margin:0;background:var(--bg);color:var(--text);font-family:ui-sans-serif,-apple-system,Segoe UI,Roboto,Arial,"Noto Sans","Helvetica Neue",sans-serif} .wrap{min-height:100vh;display:grid;place-items:center;padding:16px} .card{width:440px;max-width:100%;border-radius:24px;overflow:hidden;border:1px solid rgba(0,0,0,.06);box-shadow:0 10px 24px rgba(0,0,0,.08);background:#fff} .header{padding:22px 18px 18px;color:#fff;background:linear-gradient(165deg,var(--primary),var(--accent));text-align:center} .brandrow{display:flex;align-items:center;justify-content:space-between;font-size:13px;opacity:.9} .brand{font-weight:600}.company{background:rgba(255,255,255,.2);padding:4px 10px;border-radius:999px} .dp{margin:12px auto 8px;height:88px;width:88px;border-radius:999px;background:rgba(255,255,255,.92);display:grid;place-items:center;box-shadow:inset 0 0 0 2px rgba(255,255,255,.65);overflow:hidden} .dp img{width:100%;height:100%;object-fit:cover;display:block} .name{font-size:18px;font-weight:700}.sub{font-size:12px;opacity:.95} .section{padding:14px 16px 0;font-weight:700;color:#374151} .grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;padding:12px 16px 16px} @media (min-width:560px){.grid{grid-template-columns:repeat(3,minmax(0,1fr))}} .link{display:block;width:100%;text-decoration:none;color:#111;background:#fff;border:1px solid rgba(0,0,0,.06);border-radius:14px;padding:12px;box-shadow:0 2px 6px rgba(0,0,0,.05);transition:transform .15s ease,box-shadow .15s ease} .link:hover{box-shadow:0 6px 14px rgba(0,0,0,.08);transform:translateY(-1px)} .link .ico{display:grid;place-items:center;width:36px;height:36px;border-radius:10px;background:#F5FFF7;margin-bottom:8px;border:1px dashed rgba(0,0,0,.08)} .link .ttl{font-weight:600;font-size:14px;line-height:1.2;min-height:2.2em} .footer{display:flex;justify-content:flex-end;gap:8px;padding:12px 16px;border-top:1px solid rgba(0,0,0,.06);background:#fff} .btn{display:inline-block;padding:10px 12px;border-radius:12px;border:0;background:var(--primary);color:#fff;font-weight:600;text-align:center} .btn.outline{background:#fff;color:#374151;border:1px solid #d1d5db} .login-body{padding:22px}.title{text-align:center;color:#34A853;font-weight:800;font-size:20px;margin-bottom:4px} .small{text-align:center;color:#6b7280;font-size:12px;margin-bottom:6px}.field{margin-top:12px} .label{font-size:13px;color:#374151}.input{margin-top:6px;width:100%;border:1px solid #d1d5db;border-radius:12px;padding:10px 12px;font-size:14px} .row{display:flex;gap:8px}.err{margin-top:10px;background:#FEF2F2;color:#B91C1C;font-size:13px;border-radius:12px;padding:8px 12px} </style> </head> <body> <div class="wrap"> <div class="card"> <div class="header"> <div class="brandrow"> <div class="brand">Mr. Manager</div> <div class="company"><?=htmlspecialchars($profile['company_name'] ?: 'Company Name')?></div> </div> <div class="dp"> <?php if(!empty($profile['dp_url'])): ?> <img src="<?=htmlspecialchars($profile['dp_url'])?>" alt="DP"> <?php else: ?> <svg viewBox="0 0 100 100" width="88" height="88" aria-hidden="true"> <circle cx="50" cy="50" r="48" fill="#ffffff"/> <text x="50" y="58" text-anchor="middle" font-size="36" fill="#374151" font-family="Arial, sans-serif"> <?=htmlspecialchars(mb_strtoupper(mb_substr($DISPLAY_NAME??'U',0,1)))?> </text> </svg> <?php endif; ?> </div> <div class="name"> <?=htmlspecialchars($DISPLAY_NAME)?> — <span style="font-weight:700"><?=htmlspecialchars($DISPLAY_ROLE)?></span> </div> <?php if($profile['khata']): ?><div class="sub">Khata <?=htmlspecialchars($profile['khata'])?></div><?php endif; ?> <?php if($profile['loom_range']): ?><div class="sub"><?=htmlspecialchars($profile['loom_range'])?></div><?php endif; ?> </div> <?php $ICONS = [ 'beam_entry'=>'<svg viewBox="0 0 24 24" width="20" height="20"><path d="M4 12h16M12 4v16" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'show_patia'=>'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="3" y="4" width="18" height="14" rx="2" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M3 9h18" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'yarn_entry'=>'<svg viewBox="0 0 24 24" width="20" height="20"><path d="M4 6h16M4 12h16M4 18h16" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'yarn_records'=>'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="4" y="4" width="16" height="16" rx="2" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M8 10h8M8 14h6" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'machine'=>'<svg viewBox="0 0 24 24" width="20" height="20"><circle cx="7" cy="17" r="2" stroke="currentColor" fill="none" stroke-width="1.5"/><circle cx="17" cy="17" r="2" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M5 17H3v-4h14l4-6H9L7 9H3" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'pissing_entry'=>'<svg viewBox="0 0 24 24" width="20" height="20"><path d="M4 12h16M12 4v16" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'pissing_records'=>'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="4" y="4" width="16" height="16" rx="2" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M8 10h8M8 14h6" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'pasaria_entry'=>'<svg viewBox="0 0 24 24" width="20" height="20"><path d="M5 12h14M12 5l7 7-7 7" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'pasaria_records'=>'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="4" y="4" width="16" height="16" rx="2" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M8 10h8M8 14h6" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'production_entry'=>'<svg viewBox="0 0 24 24" width="20" height="20"><path d="M4 12h16M12 4v16" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'salary_report'=>'<svg viewBox="0 0 24 24" width="20" height="20"><path d="M3 3h18v18H3z" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M7 13l3 3 7-7" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'change_password'=>'<svg viewBox="0 0 24 24" width="20" height="20"><rect x="3" y="11" width="18" height="10" rx="2" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M7 11V7a5 5 0 0 1 10 0v4" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'leave_request'=>'<svg viewBox="0 0 24 24" width="20" height="20"><path d="M8 21h8M12 17V3" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M6 7l6-4 6 4" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'advance_request'=>'<svg viewBox="0 0 24 24" width="20" height="20"><circle cx="12" cy="12" r="9" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M8 12h8M12 8v8" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'my_profile'=>'<svg viewBox="0 0 24 24" width="20" height="20"><circle cx="12" cy="8" r="4" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M4 20a8 8 0 0 1 16 0" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', 'bank_details'=>'<svg viewBox="0 0 24 24" width="20" height="20"><path d="M3 10l9-6 9 6" stroke="currentColor" fill="none" stroke-width="1.5"/><path d="M4 10h16v8H4z" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>', ]; $menu_slugs = array_values(array_unique(array_merge($ROLE_2, $COMMON_ALWAYS))); ?> <div class="section">Quick Actions</div> <div class="grid"> <?php foreach($menu_slugs as $slug): $url = $URL_MAP[$slug] ?? '#'; $label = $labelOverrides[$slug] ?? ($LABELS_DEFAULT[$slug] ?? $slug); $ico = $ICONS[$slug] ?? '<svg viewBox="0 0 24 24" width="20" height="20"><circle cx="12" cy="12" r="9" stroke="currentColor" fill="none" stroke-width="1.5"/></svg>'; ?> <a class="link" href="<?=htmlspecialchars($url)?>"> <div class="ico"><?=$ico?></div> <div class="ttl"><?=htmlspecialchars($label)?></div> </a> <?php endforeach; ?> </div> <div class="footer"> <a class="btn" href="?logout=1">Logout</a> </div> </div> </div> </body> </html>