make this page look stuning : <?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: register.php");
exit;
}
?>
سیستم هدایت تحصیلی هوشمند
*{
font-family: 'Badkhate 2'
}
.Btn {
display: flex;
align-items: center;
justify-content: flex-start;
width: 45px;
height: 45px;
border: none;
border-radius: 50%;
cursor: pointer;
position: relative;
overflow: hidden;
transition-duration: 0.3s;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.199);
background-color: white;
}
/* plus sign */
.sign {
width: 100%;
transition-duration: 0.3s;
display: flex;
align-items: center;
justify-content: center;
}
.sign svg {
width: 17px;
}
.sign svg path {
fill: black;
}
/* text */
.text {
position: absolute;
right: 0%;
width: 0%;
opacity: 0;
color: white;
font-size: 1.2em;
font-weight: 600;
transition-duration: 0.3s;
}
/* hover effect on button width */
.Btn:hover {
background-color: black;
width: 125px;
border-radius: 40px;
transition-duration: 0.3s;
}
.Btn:hover .sign {
width: 30%;
transition-duration: 0.3s;
padding-left: 20px;
}
.Btn:hover .sign svg path {
fill: white;
}
/* hover effect button's text */
.Btn:hover .text {
opacity: 1;
width: 70%;
transition-duration: 0.3s;
padding-right: 10px;
}
/* button click effect*/
.Btn:active {
transform: translate(2px, 2px);
}
body {
font-family: 'Badkhate 2'
margin: 0;
padding: 0;
background-color: #f8f9fa;
}
/* Header Styles */
.dashboard-header {
background: linear-gradient(135deg, #4361ee 0%, #3a0ca3 100%);
color: white;
padding: 15px 30px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
position: sticky;
top: 0;
z-index: 1000;
}
.header-left {
display: flex;
align-items: center;
gap: 20px;
}
.header-right {
display: flex;
align-items: center;
gap: 15px;
}
.welcome-message {
font-size: 18px;
font-weight: 500;
}
.username {
font-weight: 700;
color: #f8f9fa;
}
/* Notification Badge (for future use) */
.notification-badge {
background-color: #f72585;
color: white;
border-radius: 50%;
width: 25px;
height: 25px;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
cursor: pointer;
}
/* Logout Button Styles */
.logout-btn {
display: flex;
align-items: center;
gap: 8px;
background: rgba(255,255,255,0.1);
border: none;
color: white;
padding: 8px 15px;
border-radius: 6px;
cursor: pointer;
transition: all 0.3s;
font-family: inherit;
font-size: 14px;
}
.logout-btn:hover {
background: rgba(255,255,255,0.2);
}
.logout-icon {
width: 16px;
height: 16px;
}
/* Main Content Area */
.dashboard-content {
padding: 30px;
max-width: 1200px;
margin: 0 auto;
}
خوش آمدید،
!
خارج شدن
صدور هدایت تحصیلی
مدرسه امام علی بن ابیطالب (ع) آبادان
فایل اکسل دانش آموزان را انتخاب کنید
پردازش اطلاعات
چاپ گزارشات
در حال پردازش اطلاعات...
فرم هدایت تحصیلی دانش آموزان
امیرارسلان ملکی
Show full message · 593 lines Assistant2025-05-04 15:57 UTC Copy response
Certainly! I've refined your PHP page with a modern, stunning design by improving layout, colors, typography, button effects, and responsiveness, while keeping your existing structure and RTL (فارسی) support intact. The design now uses a clean card layout, subtle gradients, and smooth interactive elements.
Enhanced version of your page
Show full message · 529 lines should i provide you the script file because after using this verson the students cards dont load
Assistant2025-05-04 15:59 UTC Copy response
Yes, please share your script.js file!
That way I can review how the Excel file is processed and how the student cards are generated and inserted into the page.
This will help me identify why the cards aren't loading or showing, and fix the integration with the improved design and HTML structure I provided.
Feel free to paste the entire script.js or relevant parts related to reading the file and rendering the report/cards.
here it is:
const fieldsOfStudy = {
"نظری": {
"ریاضی و فیزیک": {
'ریاضی': 14,
'علوم': 13,
'توضیحات': 'نمره ریاضی ≥ ۱۴ و علوم ≥ ۱۳'
},
"علوم تجربی": {
'ریاضی': 13,
'علوم': 14,
'توضیحات': 'نمره علوم ≥ ۱۴ و ریاضی ≥ ۱۳'
},
"علوم انسانی": {
'ادبیات فارسی': 14,
'مطالعات اجتماعی': 12,
'توضیحات': 'نمره ادبیات ≥ ۱۴ و مطالعات ≥ ۱۲'
},
"معارف اسلامی": {
'ادبیات فارسی': 14,
'معارف اسلامی': 14,
'توضیحات': 'نمره ادبیات و معارف ≥ ۱۴'
}
},
"فنی و حرفهای": {
"صنعت": {
'ریاضی': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره ریاضی ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"خدمات": {
'کار و فناوری': 12,
'فرهنگ و هنر': 12,
'توضیحات': 'نمره کاروفناوری ≥ ۱۲ و فرهنگ و هنر ≥ ۱۲'
},
"کشاورزی": {
'علوم': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره علوم ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"هنر": {
'فرهنگ و هنر': 12,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۲ و کاروفناوری ≥ ۱۲'
}
},
"کار و دانش": {
"صنعت": {
'ریاضی': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره ریاضی ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"خدمات": {
'فرهنگ و هنر': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"کشاورزی": {
'علوم': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره علوم ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"هنر": {
'فرهنگ و هنر': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۰ و کاروفناوری ≥ ۱۲'
}
}
};
function handleFile() {
const file = document.getElementById('excelFile').files[0];
if (!file) {
alert("لطفاً یک فایل اکسل انتخاب کنید");
return;
}
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
code Copy code
if (workbook.SheetNames.length === 0) {
alert("فایل انتخابی حاوی هیچ صفحهای نیست");
return;
}
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet, { defval: null });
if (jsonData.length === 0) {
alert("صفحه انتخابی حاوی دادهای نیست");
return;
}
const students = jsonData.map(row => processStudent(row));
const reportHTML = students.map(student => generatePrintForm(student)).join("");
document.getElementById("report").innerHTML = reportHTML;
document.getElementById("printBtn").style.display = "inline-block";
document.getElementById("report").scrollIntoView({ behavior: 'smooth' });
} catch (error) {
alert("خطا در پردازش فایل. لطفاً از صحت فرمت فایل اطمینان حاصل کنید.");
console.error("Error details:", error);
}
Show full message · 429 lines Assistant2025-05-04 15:59 UTC Copy response
Thanks for sharing your full script.js!
The logic of loading Excel, processing students, and generating the report looks solid. The likely issue with "student cards not showing" is a mismatch between your CSS classes or missing styles in the main HTML/CSS you have, or maybe missing animation classes (you use animate-fade-in, which is not defined unless in your CSS).
What to check/fix to get students rendered correctly:
Inject the correct CSS styles for .print-form & related classes
Your JS outputs the students inside:
html Copy code
<div class="print-form student-report"> ...student data... </div>
But your earlier CSS doesn't have .print-form or .student-report definitions, so the cards might be unstyled or invisible.
Add this CSS for your student report cards (add it into your <style> tag):
css Copy code
.print-form {
background: #fff;
border-radius: 1rem;
box-shadow: 0 10px 28px rgb(0 0 0 / 0.1);
margin-bottom: 2rem;
padding: 1.8rem 2rem;
direction: rtl;
color: #1e293b; /* dark slate color */
font-weight: 600;
font-size: 1rem;
line-height: 1.6;
transition: box-shadow 0.3s ease;
}
.print-form:hover {
box-shadow: 0 16px 40px rgb(0 0 0 / 0.15);
}
.info-row {
display: flex;
justify-content: space-between;
margin-bottom: 0.6rem;
}
.info-label {
font-weight: 700;
color: #4338ca; /* indigo */
}
/* Table Styles */
.field-table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
direction: rtl;
font-size: 0.95rem;
}
.field-table th, .field-table td {
border: 1px solid #ddd;
padding: 10px 14px;
text-align: center;
}
.field-table th {
background: #4338ca;
color: white;
font-weight: 700;
}
.eligible {
color: #059669; /* green */
font-weight: 700;
}
.ineligible {
color: #dc2626; /* red */
font-weight: 700;
}
/* Signature area, visible only on print */
.signature-area {
margin-top: 2rem;
display: flex;
justify-content: space-between;
gap: 2rem;
font-weight: 600;
font-size: 0.9rem;
}
.signature-line {
width: 150px;
height: 3px;
border-bottom: 2px solid #4338ca;
margin-bottom: 0.25rem;
}
/* Animation for fade-in, add if you like */
@keyframes fadeIn {
from {opacity: 0;transform: translateY(20px);}
to {opacity: 1;transform: translateY(0);}
}
.animate-fade-in {
animation: fadeIn 0.5s ease forwards;
}
just give me the whole code
Assistant2025-05-04 16:03 UTC Copy response
Certainly! Below is the full updated and integrated code combining your PHP, improved HTML structure, enhanced CSS (including the necessary styles for student cards), and the full script.js functionality.
This should produce a stunning interface with fully working student cards loading and rendering .
Show full message · 917 lines optimize this code and improve it:
const fieldsOfStudy = {
"نظری": {
"ریاضی و فیزیک": {
'ریاضی': 14,
'علوم': 13,
'توضیحات': 'نمره ریاضی ≥ ۱۴ و علوم ≥ ۱۳'
},
"علوم تجربی": {
'ریاضی': 13,
'علوم': 14,
'توضیحات': 'نمره علوم ≥ ۱۴ و ریاضی ≥ ۱۳'
},
"علوم انسانی": {
'ادبیات فارسی': 14,
'مطالعات اجتماعی': 12,
'توضیحات': 'نمره ادبیات ≥ ۱۴ و مطالعات ≥ ۱۲'
},
"معارف اسلامی": {
'ادبیات فارسی': 14,
'معارف اسلامی': 14,
'توضیحات': 'نمره ادبیات و معارف ≥ ۱۴'
}
},
"فنی و حرفهای": {
"صنعت": {
'ریاضی': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره ریاضی ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"خدمات": {
'کار و فناوری': 12,
'فرهنگ و هنر': 12,
'توضیحات': 'نمره کاروفناوری ≥ ۱۲ و فرهنگ و هنر ≥ ۱۲'
},
"کشاورزی": {
'علوم': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره علوم ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"هنر": {
'فرهنگ و هنر': 12,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۲ و کاروفناوری ≥ ۱۲'
}
},
"کار و دانش": {
"صنعت": {
'ریاضی': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره ریاضی ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"خدمات": {
'فرهنگ و هنر': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"کشاورزی": {
'علوم': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره علوم ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"هنر": {
'فرهنگ و هنر': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۰ و کاروفناوری ≥ ۱۲'
}
}
};
function handleFile() {
const file = document.getElementById('excelFile').files[0];
if (!file) {
alert("لطفاً یک فایل اکسل انتخاب کنید");
return;
}
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
code Copy code
if (workbook.SheetNames.length === 0) {
alert("فایل انتخابی حاوی هیچ صفحهای نیست");
return;
}
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet, { defval: null });
if (jsonData.length === 0) {
alert("صفحه انتخابی حاوی دادهای نیست");
return;
}
const students = jsonData.map(row => processStudent(row));
const reportHTML = students.map(student => generatePrintForm(student)).join("");
document.getElementById("report").innerHTML = reportHTML;
document.getElementById("printBtn").style.display = "inline-block";
document.getElementById("report").scrollIntoView({ behavior: 'smooth' });
} catch (error) {
alert("خطا در پردازش فایل. لطفاً از صحت فرمت فایل اطمینان حاصل کنید.");
console.error("Error details:", error);
}
Show full message · 429 lines Assistant2025-05-04 16:05 UTC Copy response
Here is an optimized and cleaner version of your code, with emphasis on:
Removing duplicate handleFile definition
Using async/await with a Promise-based FileReader wrapper
Better variable naming, early returns
Reusable utility functions
Using template literals cleanly and indenting generated HTML properly
Minor optimizations in logic and readability
Show full message · 343 lines improve this? <?php
h o s t = ′ l o c a l h o s t ′ ; host = 'localhost';
h os t = ′ l oc a l h os t ′ ; db = 'mydb1';
u s e r = ′ r o o t ′ ; user = 'root';
u ser = ′ r oo t ′ ; pass = '';
$charset = 'utf8mb4';
d s n = " m y s q l : h o s t = dsn = "mysql:host= d s n = " m y s q l : h os t = host;dbname=d b ; c h a r s e t = db;charset= d b ; c ha r se t = charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
p d o = n e w P D O ( pdo = new PDO( p d o = n e w P D O ( dsn, u s e r , user, u ser , pass, options);
} catch (\PDOException e) {
throw new \PDOException(e − > g e t M e s s a g e ( ) , ( i n t ) e->getMessage(), (int) e->getCode());
}
?>
Assistant2025-05-04 16:09 UTC Copy response
Certainly! Your PDO connection code is already quite solid and secure, following good practices such as:
Using UTF-8 charset (utf8mb4) for proper Unicode support,
Setting ERRMODE_EXCEPTION for proper error handling,
Disabling emulated prepares for security,
Setting default fetch mode to associative arrays.
Here are some improvements and enhancements you might consider:
1. Externalize configuration (optional but recommended)
Put database credentials and settings in a separate config file or environment variables for better security and flexibility.
2. Define a reusable function or class for connecting
If you’ll connect to the database multiple times or in multiple places, wrap this in a function or a class that handles the connection and errors gracefully.
3. Add a timezone and persistent connection (optional)
Depending on your app, you might want persistent connections for performance or explicitly set timezone.
4. Improved error handling
Instead of throwing the exception directly, you might want to log the error and display user-friendly message / halt execution gracefully.
5. Example improved and enhanced version:
what backend do you think i can add to this
Assistant2025-05-04 16:10 UTC Copy response
Your existing PHP + PDO backend is solid for many use cases, but depending on your needs — scalability, maintainability, advanced features, or developer familiarity — you might consider augmenting or migrating to one of several popular backend approaches.
Suggestions depending on your goals:
1. Keep PHP but adopt a modern PHP framework
If you want to stick with PHP for easier integration:
Laravel — a powerful, popular MVC framework with built-in ORM (Eloquent), routing, authentication, validation, queues, jobs, and more.
Symfony — enterprise-grade framework, flexible and modular, great for complex apps.
CodeIgniter / CakePHP / Slim — lighter or micro-framework alternatives.
Benefits:
You keep PHP, get structure, reduce boilerplate, and get large community support.
2. Node.js with Express (or NestJS)
If you want to modernize and move to JavaScript full-stack:
Express.js — minimal and flexible web framework for Node.js, great for REST APIs.
NestJS — built on top of Express or Fastify, uses TypeScript, and offers Angular-like modularity and dependency injection.
Benefits:
Same language front+backend, huge ecosystem, easy real-time (Socket.io) support, highly scalable.
3. Python backend
Django : batteries included—authentication, ORM, admin panel.
Flask or FastAPI : lightweight and highly customizable; FastAPI especially is modern, async-ready, and performant.
Benefits:
Good for rapid development, data-heavy apps, and AI/ML integrations.
4. Go (Golang) backend
Built for speed, concurrency, and simple deployment.
Frameworks like Gin or Echo streamline web app creation.
Great if you want a fast, compiled, and statically typed backend.
5. Java/Kotlin backend
Frameworks like Spring Boot make enterprise-grade web apps.
Suits large-scale or JVM-heavy ecosystems.
6. Serverless / BaaS options
Consider Firebase (Firestore + Cloud Functions), AWS Lambda with API Gateway, or Hasura GraphQL Engine over Postgres.
i meant what options should i add
Assistant2025-05-04 16:11 UTC Copy response
Ah, I see—you’re asking what backend features or capabilities you should add to your current PHP-based "سیستم هدایت تحصیلی هوشمند" to improve or expand it, not what technology stack to switch to.
Here are suggestions for backend features and options to add that will make your system more powerful, user-friendly, maintainable, and scalable:
1. User Authentication & Role Management
Implement secure login, registration, password hashing (e.g., password_hash in PHP), password resets.
Add roles like Admin, Counselor, Student, School Staff.
Role-based access control (RBAC) to restrict sensitive actions only to authorized users.
2. Data Validation and Sanitization
Validate all uploaded Excel files (file type, size limit).
Validate extracted data to ensure correctness (e.g., numeric grades within allowed ranges).
Sanitize all inputs to prevent SQL injection or XSS (already largely handled if using PDO correctly).
3. Database and Data Management
Store uploaded student data in database tables for persistence.
Maintain versioning: historical records of uploaded data for “audit trail”.
Provide CRUD operations for students, grades, and recommendations.
4. API Layer
Create RESTful or GraphQL APIs to decouple frontend and backend.
APIs can deliver student data, reports, and eligibility status in JSON format.
Makes future integration with mobile apps or third-party services easier.
5. Reporting & Exporting
Export reports as PDF or Excel for printing/sharing.
Generate summaries or dashboards for admins/counselors.
Visualize data (charts for average grades, eligibility distributions).
6. Notifications
Send email or SMS alerts to students and staff about uploaded data, changes, deadlines, or results.
Notification system for important events or system messages.
7. Logging & Audit
Log uploads, logins, and key actions for security and troubleshooting.
Track who uploaded or modified student data and when.
8. Error & Exception Handling
Gracefully handle errors and provide user-friendly messages.
when printing a student card doesnt fit in the printing page that is a4 please fix it : <?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: register.php");
exit;
}
?>
code Copy code
<!-- Upload Section -->
<section class="card no-print" aria-label="آپلود فایل اکسل">
<label for="excelFile" class="file-upload-label" aria-describedby="upload-instructions" tabindex="0">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<span id="upload-instructions">فایل اکسل دانش آموزان را انتخاب کنید</span>
<input type="file" id="excelFile" accept=".xlsx, .xls" aria-label="انتخاب فایل اکسل" />
</label>
<div class="action-buttons" role="group" aria-label="دکمههای عملیات فایل">
<button onclick="handleFile()" class="primary-button" id="processBtn" aria-live="polite" aria-busy="false">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
پردازش اطلاعات
</button>
<button onclick="window.print()" id="printBtn" class="secondary-button" style="display:none;">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true">
<polyline points="6 9 6 2 18 2 18 9"/>
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/>
<rect x="6" y="14" width="12" height="8"/>
</svg>
چاپ گزارشات
</button>
</div>
</section>
<!-- Loading -->
<div id="loadingIndicator" class="fixed z-50 flex hidden inset-0 flex-col items-center justify-center bg-white bg-opacity-95" role="alert" aria-live="assertive" aria-busy="true" aria-label="در حال پردازش اطلاعات">
<div class="loading-spinner"></div>
<p>در حال پردازش اطلاعات...</p>
</div>
<!-- Report container -->
<section id="report" class="report-container" aria-live="polite" aria-atomic="true" tabindex="0" aria-label="گزارش پردازش شده">
<!-- JS inserts student cards here -->
</section>
<!-- Print Header -->
<section class="print-only" style="display:none;">
<div class="print-header text-center py-5">
<div class="print-title">فرم هدایت تحصیلی دانش آموزان</div>
<div class="print-subtitle mt-2">امیرارسلان ملکی</div>
<div class="divider-indigo" style="margin: 12px auto 0;"></div>
</div>
</section>
Show full message · 882 lines Assistant2025-05-04 16:13 UTC Copy response
To ensure each student card fits nicely on a printed A4 page and does not get cut off or overflow, you need to:
Restrict the max height of each card for print,
Use page-break CSS properties correctly,
Adjust margins, paddings, and font sizes for print,
Possibly split multiple cards on one page if desired, or force one card per page.
Here's how you can improve your print styles:
Add / update CSS inside your @media print block:
css Copy code
@media print {
body {
background: white !important;
color: black !important;
margin: 0.5cm;
}
.no-print {
display: none !important;
}
.print-only {
display: block !important;
}
.print-header {
margin-bottom: 1rem;
font-weight: 700;
font-family: 'Badkhate 2', cursive;
}
.print-title {
font-size: 1.9rem;
color: black;
margin-bottom: 0.5rem;
}
.print-subtitle {
font-size: 1.25rem;
color: #444444;
}
.print-header .divider-indigo {
margin: 0.8rem auto;
background: #4338ca;
height: 3px;
width: 60px;
border-radius: 9999px;
}
#report {
box-shadow: none;
padding: 0;
font-size: 0.9rem;
line-height: 1.3;
letter-spacing: 0.02em;
}
.print-form {
page-break-inside: avoid; /* avoid splitting card */
/* Force one card per page */
page-break-after: always;
/* Optional: constrain card size */
max-height: 27cm; /* a bit less than A4 page height (29.7cm) */
box-shadow: none;
border-radius: 0;
padding: 1rem;
font-size: 0.95rem;
color: black;
}
.signature-area {
display: flex !important;
margin-top: 1.5rem;
font-weight: 600;
font-size: 0.9rem;
}
/* Reduce margins and padding inside cards */
.info-row {
margin-bottom: 0.3rem;
}
/* Smaller table font and spacing */
.field-table th,
.field-table td {
padding: 6px 8px;
font-size: 0.85rem;
}
/* Adjust headings */
h3 {
margin-top: 1rem;
margin-bottom: 0.5rem;
font-size: 1.1rem;
color: black;
}
}
the first page gets messed up a little bit
Assistant2025-05-04 16:16 UTC Copy response
That “first page messed up” issue is often caused by page breaks and margins colliding with sticky/fixed headers or other first-page elements. Since your page has a sticky header and a large branding section before the report container, the print layout may be disrupted on the first page.
To fix this, you can try:
1. Exclude header and introductory “branding” sections from printing (you already have .no-print on them?) to avoid collisions
Check the branding section — add .no-print class if missing, so it’s not printed , keeping your print clean:
html Copy code
<section class="card no-print" aria-label="اطلاعات مدرسه">
<!-- ... -->
</section>
2. Add top margin/padding to the first .print-form to prevent overlapping with printer margins
Add something like this to your @media print CSS:
css Copy code
@media print {
.print-form:first-child {
margin-top: 2cm; /* push it a bit down on first printed page */
}
}
Adjust 2cm to what fits your page printer margins.
3. Make sure no sticky or fixed elements appear when printing
Add this into your @media print:
css Copy code
@media print {
.dashboard-header,
.navbar,
header,
footer {
display: none !important;
}
}
This hides sticky elements (headers or navbars) during print that may overlap content.
4. Avoid using excessive negative margins or paddings on first page content that causes overflow or unexpected page jumps.
5. Optional — Add a page-break before the report container so it starts fresh on a new page
css Copy code
@media print {
#report {
break-before: page; /* modern */
page-break-before: always; /* fallback */
}
}
This forces the report section to start on a new printed page cleanly.
Putting it all together:
Add/Update in your CSS:
Copy first response
Not yet included in a published release.
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: register.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>سیستم هدایت تحصیلی هوشمند</title>
<!-- External Fonts & Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/font-store/badkhate2@latest/font.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<!-- Tailwind CSS CDN for utility first styles (optional but helpful) -->
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Use Badkhate 2 font throughout */
body, input, button, select, textarea {
font-family: 'Badkhate 2', cursive !important;
}
/* Reset and base */
body {
margin: 0;
background: linear-gradient(135deg, #e0e7ff, #a5b4fc);
color: #2c3e50;
min-height: 100vh;
direction: rtl;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* Header Styles */
.dashboard-header {
background: linear-gradient(135deg, #4f46e5, #4338ca);
color: white;
box-shadow: 0 4px 10px rgb(67 56 202 / 0.4);
position: sticky;
top: 0;
z-index: 1050;
padding: 0.875rem 2.5rem;
display: flex;
justify-content: space-between;
align-items: center;
font-weight: bold;
font-size: 1.125rem;
letter-spacing: 0.05em;
}
.dashboard-header .username {
color: #dcd6f7;
font-weight: 700;
transition: color 0.3s ease;
}
.dashboard-header .username:hover {
color: #c7d2fe;
}
/* Logout Button */
.logout-btn {
background: #6366f1;
border: none;
padding: 0.5rem 1.25rem;
border-radius: 9999px;
color: white;
font-weight: 600;
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.1s ease;
box-shadow: 0 8px 15px rgba(99, 102, 241, 0.3);
font-size: 0.9rem;
user-select: none;
}
.logout-btn:hover {
background-color: #4f46e5;
box-shadow: 0 12px 20px rgba(79, 70, 229, 0.5);
transform: translateY(-2px);
}
.logout-btn:active {
transform: translateY(0);
box-shadow: none;
}
.logout-btn svg {
width: 18px;
height: 18px;
fill: white;
}
/* Main Content Container */
.dashboard-content {
max-width: 900px;
margin: 40px auto 60px;
padding: 0 20px;
}
/* Card Style */
.card {
background: white;
border-radius: 1rem;
box-shadow: 0 8px 24px rgba(0,0,0,0.12);
padding: 2.8rem 2rem;
margin-bottom: 3rem;
text-align: center;
position: relative;
animation: fadeInUp 0.9s ease both;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(40px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Title Styling */
.school-branding h1 {
font-size: 2.5rem;
color: #4f46e5;
font-weight: 900;
letter-spacing: 0.06em;
margin-bottom: 0.6rem;
text-shadow: 2px 2px 6px rgb(79 70 229 / 0.25);
}
.school-info h2 {
font-size: 1.5rem;
font-weight: 600;
color: #374151;
}
.divider-indigo {
width: 70px;
height: 4px;
margin: 1rem auto 0;
background: linear-gradient(90deg, #6366f1, #4338ca);
border-radius: 99px;
filter: drop-shadow(0 0 3px rgba(67, 56, 202, 0.4));
}
/* Upload Input */
#excelFile {
display: none;
}
.file-upload-label {
cursor: pointer;
display: inline-block;
padding: 1.6rem 1rem;
border: 2px dashed #6366f1;
border-radius: 1rem;
width: 100%;
max-width: 400px;
margin: 0 auto 1.8rem;
transition: background-color 0.3s ease, border-color 0.3s ease;
color: #4f46e5;
user-select: none;
}
.file-upload-label:hover {
background-color: #f3f4f6; /* Tailwind slate-100 */
border-color: #4338ca;
}
.file-upload-label svg {
width: 72px;
height: 72px;
stroke: #4338ca;
margin-bottom: 0.6rem;
transition: stroke 0.3s ease;
}
.file-upload-label:hover svg {
stroke: #6366f1;
}
.file-upload-label span {
font-size: 1.2rem;
font-weight: 600;
letter-spacing: 0.02em;
color: #4b5563;
}
/* Buttons */
.action-buttons {
display: flex;
justify-content: center;
gap: 1.6rem;
flex-wrap: wrap;
}
button.primary-button {
background: linear-gradient(to left, #4f46e5, #4338ca);
box-shadow: 0 4px 15px rgb(67 56 202 / 0.4);
color: white;
font-weight: 700;
border-radius: 0.75rem;
padding: 0.85rem 2rem;
border: none;
cursor: pointer;
font-size: 1.1rem;
display: flex;
align-items: center;
gap: 0.6rem;
transition: transform 0.25s ease, box-shadow 0.25s ease;
user-select: none;
}
button.primary-button:hover {
transform: scale(1.06);
box-shadow: 0 8px 25px rgb(79 70 229 / 0.6);
}
button.primary-button svg {
height: 22px;
width: 22px;
stroke: white;
stroke-width: 2.5;
}
button.secondary-button {
background: white;
border: 2px solid #4f46e5;
padding: 0.85rem 2rem;
border-radius: 0.75rem;
font-weight: 700;
color: #4f46e5;
font-size: 1.1rem;
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
box-shadow: 0 4px 10px rgb(79 70 229 / 0.25);
transition: background-color 0.3s ease, color 0.3s ease;
user-select: none;
display: none; /* initially hidden */
}
button.secondary-button svg {
height: 20px;
width: 20px;
stroke: #4f46e5;
stroke-width: 2.2;
}
button.secondary-button:hover {
background-color: #4f46e5;
color: white;
box-shadow: 0 8px 20px rgb(67 56 202 / 0.5);
}
/* Loading Overlay */
#loadingIndicator {
position: fixed;
inset: 0;
background-color: rgba(255, 255, 255, 0.95);
z-index: 1500;
display: none;
flex-direction: column;
justify-content: center;
align-items: center;
}
.loading-spinner {
border: 5px solid #c7d2fe;
border-top: 5px solid #4338ca;
border-radius: 50%;
width: 72px;
height: 72px;
animation: spin 1.2s linear infinite;
margin-bottom: 1rem;
}
@keyframes spin {
to { transform: rotate(360deg);}
}
#loadingIndicator p {
font-size: 1.3rem;
font-weight: 600;
color: #4338ca;
font-family: 'Badkhate 2', cursive;
}
/* Report Container */
#report {
background: white;
border-radius: 1rem;
box-shadow: 0 4px 20px rgba(67, 56, 202, 0.2);
padding: 2rem;
min-height: 300px;
margin-top: 2rem;
overflow-x: auto;
font-size: 1rem;
color: #374151;
text-align: right;
font-weight: 500;
line-height: 1.5;
letter-spacing: 0.02em;
}
/* Print Styles */
@media print {
body {
background: white;
color: black;
}
.no-print {
display: none !important;
}
.print-only {
display: block !important;
}
.print-header {
margin-bottom: 1rem;
font-weight: 700;
font-family: 'Badkhate 2', cursive;
}
.print-title {
font-size: 1.9rem;
color: black;
margin-bottom: 0.5rem;
}
.print-subtitle {
font-size: 1.25rem;
color: #444444;
}
.print-header .divider-indigo {
margin: 0.8rem auto;
background: #4338ca;
height: 3px;
width: 60px;
border-radius: 9999px;
}
#report {
box-shadow: none;
padding: 0;
font-size: 0.95rem;
line-height: 1.4;
}
}
</style>
<!-- Scripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
</head>
<body>
<!-- Header/Nav -->
<header class="dashboard-header" role="banner">
<div class="welcome-message" aria-live="polite" aria-atomic="true">
خوش آمدید،
<span class="username"><?php echo htmlspecialchars($_SESSION['full_name']); ?></span>!
</div>
<div>
<a href="logout.php" class="logout-link" aria-label="خارج شدن از حساب کاربری">
<button type="button" class="logout-btn">
<svg viewBox="0 0 512 512" aria-hidden="true" focusable="false">
<path d="M377.9 105.9L500.7 228.7c7.2 7.2 11.3 17.1 11.3 27.3s-4.1 20.1-11.3 27.3L377.9 406.1c-6.4 6.4-15 9.9-24 9.9c-18.7 0-33.9-15.2-33.9-33.9l0-62.1-128 0c-17.7 0-32-14.3-32-32l0-64c0-17.7 14.3-32 32-32l128 0 0-62.1c0-18.7 15.2-33.9 33.9-33.9c9 0 17.6 3.6 24 9.9zM160 96L96 96c-17.7 0-32 14.3-32 32l0 256c0 17.7 14.3 32 32 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-64 0c-53 0-96-43-96-96L0 128C0 75 43 32 96 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32z"></path>
</svg>
خروج
</button>
</a>
</div>
</header>
<!-- Main Content -->
<main class="dashboard-content" role="main">
<!-- Branding Card -->
<section class="card no-print" aria-label="اطلاعات مدرسه">
<div class="school-branding">
<h1>صدور هدایت تحصیلی</h1>
<div class="school-info">
<h2>مدرسه امام علی بن ابیطالب (ع) آبادان</h2>
<div class="divider-indigo"></div>
</div>
</div>
</section>
<!-- Upload Section -->
<section class="card no-print" aria-label="آپلود فایل اکسل">
<label for="excelFile" class="file-upload-label" aria-describedby="upload-instructions" tabindex="0">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<span id="upload-instructions">فایل اکسل دانش آموزان را انتخاب کنید</span>
<input type="file" id="excelFile" accept=".xlsx, .xls" aria-label="انتخاب فایل اکسل" />
</label>
<!-- Action Buttons -->
<div class="action-buttons" role="group" aria-label="دکمههای عملیات فایل">
<button onclick="handleFile()" class="primary-button" id="processBtn" aria-live="polite" aria-busy="false">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
پردازش اطلاعات
</button>
<button onclick="window.print()" id="printBtn" class="secondary-button" style="display:none;">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true">
<polyline points="6 9 6 2 18 2 18 9"/>
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/>
<rect x="6" y="14" width="12" height="8"/>
</svg>
چاپ گزارشات
</button>
</div>
</section>
<!-- Loading Indicator -->
<div id="loadingIndicator" class="fixed z-50 flex hidden inset-0 flex-col items-center justify-center bg-white bg-opacity-95" role="alert" aria-live="assertive" aria-busy="true" aria-label="در حال پردازش اطلاعات">
<div class="loading-spinner"></div>
<p>در حال پردازش اطلاعات...</p>
</div>
<!-- Report Container -->
<section id="report" class="report-container" aria-live="polite" aria-atomic="true" tabindex="0" aria-label="گزارش پردازش شده">
<!-- Report content will be inserted dynamically by script.js -->
</section>
<!-- Print Header -->
<section class="print-only" style="display:none;">
<div class="print-header text-center py-5">
<div class="print-title">فرم هدایت تحصیلی دانش آموزان</div>
<div class="print-subtitle mt-2">امیرارسلان ملکی</div>
<div class="divider-indigo" style="margin: 12px auto 0;"></div>
</div>
</section>
</main>
<script src="script.js"></script>
<!-- Example JavaScript to handle showing loading, print button etc. -->
<script>
// Function to handle file input processing
function handleFile() {
const fileInput = document.getElementById('excelFile');
if (!fileInput.files.length) {
alert('لطفا ابتدا یک فایل اکسل انتخاب کنید.');
return;
}
// Show loading
const loadingIndicator = document.getElementById('loadingIndicator');
loadingIndicator.style.display = 'flex';
// Disable buttons while processing
document.getElementById('processBtn').setAttribute('aria-busy', 'true');
document.getElementById('processBtn').disabled = true;
// Simulate processing delay for demo purposes
setTimeout(() => {
// Hide loading
loadingIndicator.style.display = 'none';
// Enable buttons
document.getElementById('processBtn').setAttribute('aria-busy', 'false');
document.getElementById('processBtn').disabled = false;
// Show print button
const printBtn = document.getElementById('printBtn');
printBtn.style.display = 'inline-flex';
// Example: insert dummy report content
const report = document.getElementById('report');
report.innerHTML = `
<h3 style="font-weight:700; margin-bottom:1rem;">گزارش پردازش شده</h3>
<p>اطلاعات فایل اکسل با موفقیت بارگذاری و پردازش شد.</p>
<p>در این بخش می توانید جزییات گزارش خود را مشاهده کنید.</p>
`;
// Set focus to report for screen reader users
report.focus();
}, 2200);
}
// Optional: Allow label click & enter key to trigger file dialog
document.querySelector('.file-upload-label').addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
document.getElementById('excelFile').click();
}
});
</script>
</body>
</html>
Key improvements:
Typography: Larger, stylish headings with letter spacing and text shadows.
Color scheme: Beautiful indigo/purple gradients with subtle shadows and complementary background gradient.
Buttons: Modern gradient primary button with hover and active states, consistent with your existing color palette.
Upload box: Larger clickable area with dashed border, icon included, and smooth hover effect.
Loading indicator: Centered overlay with big spinner and clear text.
Report container: Clean white card with padding and soft shadows.
Accessibility: Proper aria-labels, button states, keyboard support, and focus management.
Print styles: Clear and minimalist print design.
Responsive & RTL: Works well on mobile, tablets, and desktop; fully supports right-to-left layout and Persian content.
How to use
Replace your current page content with the above.
Keep your server-side PHP as is.
Your existing script.js can be updated or kept — I added an inline demo of handleFile().
The <link> to Badkhate font loads your custom font.
The page is self-contained for a stunning UI out of the box.
If you want me to help integrating your existing external CSS or polish JavaScript functionality, feel free to ask!
reader.onerror = function() {
alert("خطا در خواندن فایل");
};
reader.readAsArrayBuffer(file);
}
function processStudent(row) {
const gradeFields = {
'ریاضی': ['ریاضی7', 'ریاضی8', 'ریاضی9'],
'علوم': ['علوم7', 'علوم8', 'علوم9'],
'ادبیات فارسی': ['ادبیات7', 'ادبیات8', 'ادبیات9'],
'مطالعات اجتماعی': ['مطالعات7', 'مطالعات8', 'مطالعات9'],
'عربی': ['عربی7', 'عربی8', 'عربی9'],
'معارف اسلامی': ['معارف7', 'معارف8', 'معارف9'],
'کار و فناوری': ['کاروفناوری7', 'کاروفناوری8', 'کاروفناوری9'],
'فرهنگ و هنر': ['فرهنگ و هنر7', 'فرهنگ و هنر8', 'فرهنگ و هنر9']
};
code Copy code
const grades = {};
const averages = {};
for (const [subject, fields] of Object.entries(gradeFields)) {
const gradeData = {
g7: parseFloat(row[fields[0]]) || 0,
g8: parseFloat(row[fields[1]]) || 0,
g9: parseFloat(row[fields[2]]) || 0
};
grades[subject] = gradeData;
// محاسبه میانگین وزنی با ضریب 1 برای هفتم و هشتم و 3 برای نهم
const weightedSum = (gradeData.g7 * 1) + (gradeData.g8 * 1) + (gradeData.g9 * 3);
const weight = 5; // مجموع ضرایب (1+1+3)
averages[subject] = (weightedSum / weight).toFixed(2);
}
const student = {
name: row['نام'] || 'نامشخص',
family: row['نام خانوادگی'] || 'نامشخص',
nationalCode: row['کدملی'] || 'نامشخص',
school: row['مدرسه'] || 'مدرسه امام علی بن ابیطالب (ع)',
grades,
averages,
strengths: [],
weaknesses: []
};
determineFieldAndBranch(student);
analyzeStudentPerformance(student);
return student;
function determineFieldAndBranch(student) {
const avg = student.averages;
const math = parseFloat(avg['ریاضی']);
const sci = parseFloat(avg['علوم']);
const per = parseFloat(avg['ادبیات فارسی']);
const art = parseFloat(avg['فرهنگ و هنر']);
const tech = parseFloat(avg['کار و فناوری']);
const rel = parseFloat(avg['معارف اسلامی']);
const soc = parseFloat(avg['مطالعات اجتماعی']);
code Copy code
// رشتههای نظری
if (math >= 14 && sci >= 13) {
student.branch = "نظری";
student.field = "ریاضی و فیزیک";
}
else if (sci >= 14 && math >= 13) {
student.branch = "نظری";
student.field = "علوم تجربی";
}
else if (per >= 14 && rel >= 14) {
student.branch = "نظری";
student.field = "معارف اسلامی";
}
else if (per >= 14 && soc >= 12) {
student.branch = "نظری";
student.field = "علوم انسانی";
}
// رشتههای فنی و حرفهای
else if (art >= 12 && tech >= 12) {
student.branch = "فنی و حرفهای";
student.field = "هنر";
}
else if (tech >= 12) {
if (math >= 10) {
student.branch = "فنی و حرفهای";
student.field = "صنعت";
}
else if (sci >= 10) {
student.branch = "فنی و حرفهای";
student.field = "کشاورزی";
}
else {
student.branch = "فنی و حرفهای";
student.field = "خدمات";
}
}
// رشتههای کار و دانش
else {
student.branch = "کار و دانش";
if (art >= 10) {
student.field = "هنر";
} else if (math >= 10) {
student.field = "صنعت";
} else if (sci >= 10) {
student.field = "کشاورزی";
} else {
student.field = "خدمات";
}
}
// محاسبه رشتههای مجاز با در نظر گرفتن میانگین وزنی
student.eligibleFields = {};
for (const branch in fieldsOfStudy) {
student.eligibleFields[branch] = {};
for (const field in fieldsOfStudy[branch]) {
const conditions = fieldsOfStudy[branch][field];
let isEligible = true;
for (const subject in conditions) {
if (subject !== 'توضیحات') {
const studentGrade = parseFloat(avg[subject]) || 0;
if (studentGrade < conditions[subject]) {
isEligible = false;
break;
}
}
}
student.eligibleFields[branch][field] = isEligible;
}
}
function analyzeStudentPerformance(student) {
const avg = student.averages;
code Copy code
// نقاط قوت (نمرات 14 و بالاتر)
if (parseFloat(avg['ریاضی']) >= 14) student.strengths.push('ریاضیات');
if (parseFloat(avg['علوم']) >= 14) student.strengths.push('علوم');
if (parseFloat(avg['ادبیات فارسی']) >= 14) student.strengths.push('ادبیات فارسی');
if (parseFloat(avg['فرهنگ و هنر']) >= 14) student.strengths.push('فرهنگ و هنر');
if (parseFloat(avg['کار و فناوری']) >= 14) student.strengths.push('کار و فناوری');
// نقاط ضعف (نمرات کمتر از 10)
if (parseFloat(avg['ریاضی']) < 10) student.weaknesses.push('ریاضیات');
if (parseFloat(avg['علوم']) < 10) student.weaknesses.push('علوم');
if (parseFloat(avg['ادبیات فارسی']) < 10) student.weaknesses.push('ادبیات فارسی');
if (parseFloat(avg['کار و فناوری']) < 10) student.weaknesses.push('کار و فناوری');
if (student.strengths.length === 0) {
student.strengths.push('نیاز به بررسی بیشتر توسط مشاور');
}
function generatePrintForm(student) {
return `
نام و نام خانوادگی:
s t u d e n t . n a m e {student.name} s t u d e n t . nam e {student.family}
کد ملی:
s t u d e n t . n a t i o n a l C o d e < / s p a n > < / d i v > < d i v c l a s s = " i n f o − r o w " > < s p a n c l a s s = " i n f o − l a b e l " > مدرسه : < / s p a n > < s p a n > {student.nationalCode}</span>
</div>
<div class="info-row">
<span class="info-label">مدرسه:</span>
<span> s t u d e n t . na t i o na l C o d e < / s p an >< / d i v >< d i v c l a ss = " in f o − {student.school}
شاخه پیشنهادی:
s t u d e n t . b r a n c h < / s t r o n g > < / s p a n > < / d i v > < d i v c l a s s = " i n f o − r o w " > < s p a n c l a s s = " i n f o − l a b e l " > رشتهپیشنهادی : < / s p a n > < s p a n > < s t r o n g > {student.branch}</strong></span>
</div>
<div class="info-row">
<span class="info-label">رشته پیشنهادی:</span>
<span><strong> s t u d {student.field}
code Copy code
<h3>وضعیت مجاز بودن رشتهها</h3>
<table class="field-table">
<thead>
<tr>
<th>شاخه</th>
<th>رشته</th>
<th>وضعیت</th>
<th>شرایط</th>
</tr>
</thead>
<tbody>
${Object.entries(student.eligibleFields).map(([branch, fields]) =>
Object.entries(fields).map(([field, isEligible]) => `
<tr>
<td>${branch}</td>
<td>${field}</td>
<td class="${isEligible ? 'eligible' : 'ineligible'}">${isEligible ? 'مجاز' : 'غیرمجاز'}</td>
<td>${fieldsOfStudy[branch][field]['توضیحات']}</td>
</tr>`
).join('')
).join('')}
</tbody>
</table>
<div style="margin-top: 20px;">
<div class="info-row">
<span class="info-label">نقاط قوت:</span>
<span>${student.strengths.join('، ')}</span>
</div>
<div class="info-row">
<span class="info-label">نقاط ضعف:</span>
<span>${student.weaknesses.join('، ')}</span>
</div>
</div>
<div class="signature-area print-only">
<div>
<div class="signature-line"></div>
<p>امضاء و مهر مشاور</p>
</div>
<div>
<div class="signature-line"></div>
<p>امضاء و مهر مدیر</p>
</div>
<div>
<p>تاریخ: ______________</p>
</div>
</div>
</div>`;
// Only adding the loading indicator functionality
async function handleFile() {
const loadingIndicator = document.getElementById('loadingIndicator');
const reportContainer = document.getElementById('report');
try {
// Show loading indicator
loadingIndicator.style.display = 'block';
reportContainer.innerHTML = '';
code Copy code
const file = document.getElementById('excelFile').files[0];
if (!file) {
throw new Error("لطفاً یک فایل اکسل انتخاب کنید");
}
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
if (workbook.SheetNames.length === 0) {
throw new Error("فایل انتخابی حاوی هیچ صفحهای نیست");
}
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet, { defval: null });
if (jsonData.length === 0) {
throw new Error("صفحه انتخابی حاوی دادهای نیست");
}
const students = jsonData.map(row => processStudent(row));
const reportHTML = students.map(student => generatePrintForm(student)).join("");
// Hide loading indicator and show results
loadingIndicator.style.display = 'none';
reportContainer.innerHTML = reportHTML;
document.getElementById("printBtn").style.display = "inline-block";
// Add animation to reports
document.querySelectorAll('.print-form').forEach((el, i) => {
el.classList.add('animate-fade-in');
el.style.animationDelay = `${i * 0.1}s`;
});
reportContainer.scrollIntoView({ behavior: 'smooth' });
} catch (error) {
loadingIndicator.style.display = 'none';
handleError(error);
}
};
reader.onerror = function() {
loadingIndicator.style.display = 'none';
throw new Error("خطا در خواندن فایل");
};
reader.readAsArrayBuffer(file);
} catch (error) {
loadingIndicator.style.display = 'none';
handleError(error);
}
}
function handleError(error) {
console.error("Error:", error);
alert(error.message || "خطایی رخ داده است. لطفاً دوباره تلاش کنید.");
}
Explanation:
This styles the .print-form "cards" with a white background, shadow, spacing, and RTL-friendly layout.
.info-row and .info-label provide styled labels and aligned info for student properties.
.field-table styles the eligibility table cleanly with green/red colors for eligible/non-eligible.
.signature-area is formatted nicely for print display.
Added a simple fade-in animation class used by your JS (.animate-fade-in).
Additional recommendations:
Make sure your main HTML <style> contains this CSS or link to a CSS file with similar styles.
If you want to keep your animations from animate.css, adjust your JS to use classes like animate__fadeInUp or just keep your .animate-fade-in as above.
Ensure the container #report has enough width and padding (which suggested HTML does).
How to integrate: Add the CSS snippet inside your <style> block right after your existing styles.
html Copy code
<style>
/* ... your existing styles ... */
/* Add this: */
.print-form {
/* styles here */
}
/* ... rest of CSS from above ... */
</style>
Why this fixes your issue Your current CSS has no styling for .print-form elements, so although your script inserts the student cards, they have no visual layout or may collapse to zero height.
If you want, I can prepare a full updated version of your HTML+CSS+JS snippet with all these fixes integrated and ready to copy-paste.
Let me know if you want me to do that — or if you have any other question!
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: register.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>سیستم هدایت تحصیلی هوشمند</title>
<!-- Fonts & Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/font-store/badkhate2@latest/font.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<!-- Tailwind CSS CDN for utility styles (optional, can remove if you prefer) -->
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Global font */
body, input, button, select, textarea {
font-family: 'Badkhate 2', cursive !important;
}
body {
margin: 0;
background: linear-gradient(135deg, #e0e7ff, #a5b4fc);
color: #2c3e50;
min-height: 100vh;
direction: rtl;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* Header */
.dashboard-header {
background: linear-gradient(135deg, #4f46e5, #4338ca);
color: white;
box-shadow: 0 4px 10px rgb(67 56 202 / 0.4);
position: sticky;
top: 0;
z-index: 1050;
padding: 0.875rem 2.5rem;
display: flex;
justify-content: space-between;
align-items: center;
font-weight: bold;
font-size: 1.125rem;
letter-spacing: 0.05em;
}
.dashboard-header .username {
color: #dcd6f7;
font-weight: 700;
transition: color 0.3s ease;
}
.dashboard-header .username:hover {
color: #c7d2fe;
}
/* Logout Button */
.logout-btn {
background: #6366f1;
border: none;
padding: 0.5rem 1.25rem;
border-radius: 9999px;
color: white;
font-weight: 600;
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.1s ease;
box-shadow: 0 8px 15px rgba(99, 102, 241, 0.3);
font-size: 0.9rem;
user-select: none;
}
.logout-btn:hover {
background-color: #4f46e5;
box-shadow: 0 12px 20px rgba(79, 70, 229, 0.5);
transform: translateY(-2px);
}
.logout-btn:active {
transform: translateY(0);
box-shadow: none;
}
.logout-btn svg {
width: 18px;
height: 18px;
fill: white;
}
/* Main content */
.dashboard-content {
max-width: 900px;
margin: 40px auto 60px;
padding: 0 20px;
}
/* Card Style */
.card {
background: white;
border-radius: 1rem;
box-shadow: 0 8px 24px rgba(0,0,0,0.12);
padding: 2.8rem 2rem;
margin-bottom: 3rem;
text-align: center;
position: relative;
animation: fadeInUp 0.9s ease both;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(40px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* School Branding */
.school-branding h1 {
font-size: 2.5rem;
color: #4f46e5;
font-weight: 900;
letter-spacing: 0.06em;
margin-bottom: 0.6rem;
text-shadow: 2px 2px 6px rgb(79 70 229 / 0.25);
}
.school-info h2 {
font-size: 1.5rem;
font-weight: 600;
color: #374151;
}
.divider-indigo {
width: 70px;
height: 4px;
margin: 1rem auto 0;
background: linear-gradient(90deg, #6366f1, #4338ca);
border-radius: 99px;
filter: drop-shadow(0 0 3px rgba(67, 56, 202, 0.4));
}
/* Upload Box */
#excelFile {
display: none;
}
.file-upload-label {
cursor: pointer;
display: inline-block;
padding: 1.6rem 1rem;
border: 2px dashed #6366f1;
border-radius: 1rem;
width: 100%;
max-width: 400px;
margin: 0 auto 1.8rem;
transition: background-color 0.3s ease, border-color 0.3s ease;
color: #4f46e5;
user-select: none;
}
.file-upload-label:hover {
background-color: #f3f4f6;
border-color: #4338ca;
}
.file-upload-label svg {
width: 72px;
height: 72px;
stroke: #4338ca;
margin-bottom: 0.6rem;
transition: stroke 0.3s ease;
}
.file-upload-label:hover svg {
stroke: #6366f1;
}
.file-upload-label span {
font-size: 1.2rem;
font-weight: 600;
letter-spacing: 0.02em;
color: #4b5563;
}
/* Buttons */
.action-buttons {
display: flex;
justify-content: center;
gap: 1.6rem;
flex-wrap: wrap;
}
button.primary-button {
background: linear-gradient(to left, #4f46e5, #4338ca);
box-shadow: 0 4px 15px rgb(67 56 202 / 0.4);
color: white;
font-weight: 700;
border-radius: 0.75rem;
padding: 0.85rem 2rem;
border: none;
cursor: pointer;
font-size: 1.1rem;
display: flex;
align-items: center;
gap: 0.6rem;
transition: transform 0.25s ease, box-shadow 0.25s ease;
user-select: none;
}
button.primary-button:hover {
transform: scale(1.06);
box-shadow: 0 8px 25px rgb(79 70 229 / 0.6);
}
button.primary-button svg {
height: 22px;
width: 22px;
stroke: white;
stroke-width: 2.5;
}
button.secondary-button {
background: white;
border: 2px solid #4f46e5;
padding: 0.85rem 2rem;
border-radius: 0.75rem;
font-weight: 700;
color: #4f46e5;
font-size: 1.1rem;
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
box-shadow: 0 4px 10px rgb(79 70 229 / 0.25);
transition: background-color 0.3s ease, color 0.3s ease;
user-select: none;
display: none; /* initially hidden */
}
button.secondary-button svg {
height: 20px;
width: 20px;
stroke: #4f46e5;
stroke-width: 2.2;
}
button.secondary-button:hover {
background-color: #4f46e5;
color: white;
box-shadow: 0 8px 20px rgb(67 56 202 / 0.5);
}
/* Loading Indicator */
#loadingIndicator {
position: fixed;
inset: 0;
background-color: rgba(255, 255, 255, 0.95);
z-index: 1500;
display: none;
flex-direction: column;
justify-content: center;
align-items: center;
}
.loading-spinner {
border: 5px solid #c7d2fe;
border-top: 5px solid #4338ca;
border-radius: 50%;
width: 72px;
height: 72px;
animation: spin 1.2s linear infinite;
margin-bottom: 1rem;
}
@keyframes spin {
to { transform: rotate(360deg);}
}
#loadingIndicator p {
font-size: 1.3rem;
font-weight: 600;
color: #4338ca;
font-family: 'Badkhate 2', cursive;
}
/* Report container */
#report {
background: white;
border-radius: 1rem;
box-shadow: 0 4px 20px rgba(67, 56, 202, 0.2);
padding: 2rem;
min-height: 300px;
margin-top: 2rem;
overflow-x: auto;
font-size: 1rem;
color: #374151;
text-align: right;
font-weight: 500;
line-height: 1.5;
letter-spacing: 0.02em;
}
/* ===================
Student cards styles
===================== */
.print-form {
background: #fff;
border-radius: 1rem;
box-shadow: 0 10px 28px rgb(0 0 0 / 0.1);
margin-bottom: 2rem;
padding: 1.8rem 2rem;
direction: rtl;
color: #1e293b;
font-weight: 600;
font-size: 1rem;
line-height: 1.6;
transition: box-shadow 0.3s ease;
}
.print-form:hover {
box-shadow: 0 16px 40px rgb(0 0 0 / 0.15);
}
.info-row {
display: flex;
justify-content: space-between;
margin-bottom: 0.6rem;
}
.info-label {
font-weight: 700;
color: #4338ca;
}
/* Table */
.field-table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
direction: rtl;
font-size: 0.95rem;
}
.field-table th, .field-table td {
border: 1px solid #ddd;
padding: 10px 14px;
text-align: center;
}
.field-table th {
background: #4338ca;
color: white;
font-weight: 700;
}
.eligible {
color: #059669;
font-weight: 700;
}
.ineligible {
color: #dc2626;
font-weight: 700;
}
/* Signature area */
.signature-area {
margin-top: 2rem;
display: flex;
justify-content: space-between;
gap: 2rem;
font-weight: 600;
font-size: 0.9rem;
}
.signature-line {
width: 150px;
height: 3px;
border-bottom: 2px solid #4338ca;
margin-bottom: 0.25rem;
}
/* Animations */
@keyframes fadeIn {
from {opacity: 0;transform: translateY(20px);}
to {opacity: 1;transform: translateY(0);}
}
.animate-fade-in {
animation: fadeIn 0.5s ease forwards;
}
/* Print styles */
@media print {
body {
background: white !important;
color: black !important;
}
.no-print {
display: none !important;
}
.print-only {
display: block !important;
}
.print-header {
margin-bottom: 1rem;
font-weight: 700;
font-family: 'Badkhate 2', cursive;
}
.print-title {
font-size: 1.9rem;
color: black;
margin-bottom: 0.5rem;
}
.print-subtitle {
font-size: 1.25rem;
color: #444444;
}
.print-header .divider-indigo {
margin: 0.8rem auto;
background: #4338ca;
height: 3px;
width: 60px;
border-radius: 9999px;
}
#report {
box-shadow: none;
padding: 0;
font-size: 0.95rem;
line-height: 1.4;
}
.signature-area {
display: flex !important;
}
}
</style>
<!-- XLSX library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
</head>
<body>
<!-- Header/Nav -->
<header class="dashboard-header" role="banner">
<div class="welcome-message" aria-live="polite" aria-atomic="true">
خوش آمدید،
<span class="username"><?php echo htmlspecialchars($_SESSION['full_name']); ?></span>!
</div>
<div>
<a href="logout.php" class="logout-link" aria-label="خارج شدن از حساب کاربری">
<button type="button" class="logout-btn">
<svg viewBox="0 0 512 512" aria-hidden="true" focusable="false">
<path d="M377.9 105.9L500.7 228.7c7.2 7.2 11.3 17.1 11.3 27.3s-4.1 20.1-11.3 27.3L377.9 406.1c-6.4 6.4-15 9.9-24 9.9c-18.7 0-33.9-15.2-33.9-33.9l0-62.1-128 0c-17.7 0-32-14.3-32-32l0-64c0-17.7 14.3-32 32-32l128 0 0-62.1c0-18.7 15.2-33.9 33.9-33.9c9 0 17.6 3.6 24 9.9zM160 96L96 96c-17.7 0-32 14.3-32 32l0 256c0 17.7 14.3 32 32 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-64 0c-53 0-96-43-96-96L0 128C0 75 43 32 96 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32z"></path>
</svg>
خروج
</button>
</a>
</div>
</header>
<!-- Main content -->
<main class="dashboard-content" role="main">
<!-- Branding Card -->
<section class="card no-print" aria-label="اطلاعات مدرسه">
<div class="school-branding">
<h1>صدور هدایت تحصیلی</h1>
<div class="school-info">
<h2>مدرسه امام علی بن ابیطالب (ع) آبادان</h2>
<div class="divider-indigo"></div>
</div>
</div>
</section>
<!-- Upload Section -->
<section class="card no-print" aria-label="آپلود فایل اکسل">
<label for="excelFile" class="file-upload-label" aria-describedby="upload-instructions" tabindex="0">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<span id="upload-instructions">فایل اکسل دانش آموزان را انتخاب کنید</span>
<input type="file" id="excelFile" accept=".xlsx, .xls" aria-label="انتخاب فایل اکسل" />
</label>
<div class="action-buttons" role="group" aria-label="دکمههای عملیات فایل">
<button onclick="handleFile()" class="primary-button" id="processBtn" aria-live="polite" aria-busy="false">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
پردازش اطلاعات
</button>
<button onclick="window.print()" id="printBtn" class="secondary-button" style="display:none;">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" aria-hidden="true">
<polyline points="6 9 6 2 18 2 18 9"/>
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/>
<rect x="6" y="14" width="12" height="8"/>
</svg>
چاپ گزارشات
</button>
</div>
</section>
<!-- Loading -->
<div id="loadingIndicator" class="fixed z-50 flex hidden inset-0 flex-col items-center justify-center bg-white bg-opacity-95" role="alert" aria-live="assertive" aria-busy="true" aria-label="در حال پردازش اطلاعات">
<div class="loading-spinner"></div>
<p>در حال پردازش اطلاعات...</p>
</div>
<!-- Report container -->
<section id="report" class="report-container" aria-live="polite" aria-atomic="true" tabindex="0" aria-label="گزارش پردازش شده">
<!-- JS inserts student cards here -->
</section>
<!-- Print Header -->
<section class="print-only" style="display:none;">
<div class="print-header text-center py-5">
<div class="print-title">فرم هدایت تحصیلی دانش آموزان</div>
<div class="print-subtitle mt-2">امیرارسلان ملکی</div>
<div class="divider-indigo" style="margin: 12px auto 0;"></div>
</div>
</section>
</main>
<script>
const fieldsOfStudy = {
"نظری": {
"ریاضی و فیزیک": {
'ریاضی': 14,
'علوم': 13,
'توضیحات': 'نمره ریاضی ≥ ۱۴ و علوم ≥ ۱۳'
},
"علوم تجربی": {
'ریاضی': 13,
'علوم': 14,
'توضیحات': 'نمره علوم ≥ ۱۴ و ریاضی ≥ ۱۳'
},
"علوم انسانی": {
'ادبیات فارسی': 14,
'مطالعات اجتماعی': 12,
'توضیحات': 'نمره ادبیات ≥ ۱۴ و مطالعات ≥ ۱۲'
},
"معارف اسلامی": {
'ادبیات فارسی': 14,
'معارف اسلامی': 14,
'توضیحات': 'نمره ادبیات و معارف ≥ ۱۴'
}
},
"فنی و حرفهای": {
"صنعت": {
'ریاضی': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره ریاضی ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"خدمات": {
'کار و فناوری': 12,
'فرهنگ و هنر': 12,
'توضیحات': 'نمره کاروفناوری ≥ ۱۲ و فرهنگ و هنر ≥ ۱۲'
},
"کشاورزی": {
'علوم': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره علوم ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"هنر": {
'فرهنگ و هنر': 12,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۲ و کاروفناوری ≥ ۱۲'
}
},
"کار و دانش": {
"صنعت": {
'ریاضی': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره ریاضی ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"خدمات": {
'فرهنگ و هنر': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"کشاورزی": {
'علوم': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره علوم ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"هنر": {
'فرهنگ و هنر': 10,
'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۰ و کاروفناوری ≥ ۱۲'
}
}
};
function handleFile() {
const loadingIndicator = document.getElementById('loadingIndicator');
const reportContainer = document.getElementById('report');
const processBtn = document.getElementById('processBtn');
const printBtn = document.getElementById('printBtn');
try {
loadingIndicator.style.display = 'flex';
reportContainer.innerHTML = '';
processBtn.setAttribute('aria-busy', 'true');
processBtn.disabled = true;
printBtn.style.display = 'none';
const file = document.getElementById('excelFile').files[0];
if (!file) throw new Error("لطفاً یک فایل اکسل انتخاب کنید");
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
if (workbook.SheetNames.length === 0) throw new Error("فایل انتخابی حاوی هیچ صفحهای نیست");
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet, { defval: null });
if (jsonData.length === 0) throw new Error("صفحه انتخابی حاوی دادهای نیست");
const students = jsonData.map(row => processStudent(row));
const reportHTML = students.map(student => generatePrintForm(student)).join("");
loadingIndicator.style.display = 'none';
reportContainer.innerHTML = reportHTML;
// Animate fade-in for each student card
document.querySelectorAll('.print-form').forEach((el, i) => {
el.classList.add('animate-fade-in');
el.style.animationDelay = `${i * 0.1}s`;
});
printBtn.style.display = 'inline-flex';
processBtn.setAttribute('aria-busy', 'false');
processBtn.disabled = false;
reportContainer.scrollIntoView({ behavior: 'smooth' });
} catch (error) {
loadingIndicator.style.display = 'none';
handleError(error);
}
};
reader.onerror = function() {
loadingIndicator.style.display = 'none';
handleError(new Error("خطا در خواندن فایل"));
};
reader.readAsArrayBuffer(file);
} catch (error) {
loadingIndicator.style.display = 'none';
handleError(error);
}
}
function handleError(error) {
console.error("Error:", error);
alert(error.message || "خطایی رخ داده است. لطفاً دوباره تلاش کنید.");
}
function processStudent(row) {
const gradeFields = {
'ریاضی': ['ریاضی7', 'ریاضی8', 'ریاضی9'],
'علوم': ['علوم7', 'علوم8', 'علوم9'],
'ادبیات فارسی': ['ادبیات7', 'ادبیات8', 'ادبیات9'],
'مطالعات اجتماعی': ['مطالعات7', 'مطالعات8', 'مطالعات9'],
'عربی': ['عربی7', 'عربی8', 'عربی9'],
'معارف اسلامی': ['معارف7', 'معارف8', 'معارف9'],
'کار و فناوری': ['کاروفناوری7', 'کاروفناوری8', 'کاروفناوری9'],
'فرهنگ و هنر': ['فرهنگ و هنر7', 'فرهنگ و هنر8', 'فرهنگ و هنر9']
};
const grades = {};
const averages = {};
for (const [subject, fields] of Object.entries(gradeFields)) {
const gradeData = {
g7: parseFloat(row[fields[0]]) || 0,
g8: parseFloat(row[fields[1]]) || 0,
g9: parseFloat(row[fields[2]]) || 0
};
grades[subject] = gradeData;
const weightedSum = (gradeData.g7 * 1) + (gradeData.g8 * 1) + (gradeData.g9 * 3);
const weight = 5;
averages[subject] = (weightedSum / weight).toFixed(2);
}
const student = {
name: row['نام'] || 'نامشخص',
family: row['نام خانوادگی'] || 'نامشخص',
nationalCode: row['کدملی'] || 'نامشخص',
school: row['مدرسه'] || 'مدرسه امام علی بن ابیطالب (ع)',
grades,
averages,
strengths: [],
weaknesses: []
};
determineFieldAndBranch(student);
analyzeStudentPerformance(student);
return student;
}
function determineFieldAndBranch(student) {
const avg = student.averages;
const math = parseFloat(avg['ریاضی']);
const sci = parseFloat(avg['علوم']);
const per = parseFloat(avg['ادبیات فارسی']);
const art = parseFloat(avg['فرهنگ و هنر']);
const tech = parseFloat(avg['کار و فناوری']);
const rel = parseFloat(avg['معارف اسلامی']);
const soc = parseFloat(avg['مطالعات اجتماعی']);
if (math >= 14 && sci >= 13) {
student.branch = "نظری";
student.field = "ریاضی و فیزیک";
}
else if (sci >= 14 && math >= 13) {
student.branch = "نظری";
student.field = "علوم تجربی";
}
else if (per >= 14 && rel >= 14) {
student.branch = "نظری";
student.field = "معارف اسلامی";
}
else if (per >= 14 && soc >= 12) {
student.branch = "نظری";
student.field = "علوم انسانی";
}
else if (art >= 12 && tech >= 12) {
student.branch = "فنی و حرفهای";
student.field = "هنر";
}
else if (tech >= 12) {
if (math >= 10) {
student.branch = "فنی و حرفهای";
student.field = "صنعت";
}
else if (sci >= 10) {
student.branch = "فنی و حرفهای";
student.field = "کشاورزی";
}
else {
student.branch = "فنی و حرفهای";
student.field = "خدمات";
}
}
else {
student.branch = "کار و دانش";
if (art >= 10) {
student.field = "هنر";
} else if (math >= 10) {
student.field = "صنعت";
} else if (sci >= 10) {
student.field = "کشاورزی";
} else {
student.field = "خدمات";
}
}
student.eligibleFields = {};
for (const branch in fieldsOfStudy) {
student.eligibleFields[branch] = {};
for (const field in fieldsOfStudy[branch]) {
const conditions = fieldsOfStudy[branch][field];
let isEligible = true;
for (const subject in conditions) {
if (subject !== 'توضیحات') {
const studentGrade = parseFloat(avg[subject]) || 0;
if (studentGrade < conditions[subject]) {
isEligible = false;
break;
}
}
}
student.eligibleFields[branch][field] = isEligible;
}
}
}
function analyzeStudentPerformance(student) {
const avg = student.averages;
if (parseFloat(avg['ریاضی']) >= 14) student.strengths.push('ریاضیات');
if (parseFloat(avg['علوم']) >= 14) student.strengths.push('علوم');
if (parseFloat(avg['ادبیات فارسی']) >= 14) student.strengths.push('ادبیات فارسی');
if (parseFloat(avg['فرهنگ و هنر']) >= 14) student.strengths.push('فرهنگ و هنر');
if (parseFloat(avg['کار و فناوری']) >= 14) student.strengths.push('کار و فناوری');
if (parseFloat(avg['ریاضی']) < 10) student.weaknesses.push('ریاضیات');
if (parseFloat(avg['علوم']) < 10) student.weaknesses.push('علوم');
if (parseFloat(avg['ادبیات فارسی']) < 10) student.weaknesses.push('ادبیات فارسی');
if (parseFloat(avg['کار و فناوری']) < 10) student.weaknesses.push('کار و فناوری');
if (student.strengths.length === 0) {
student.strengths.push('نیاز به بررسی بیشتر توسط مشاور');
}
}
function generatePrintForm(student) {
return `
<div class="print-form student-report" tabindex="0">
<div class="student-info">
<div class="info-row">
<span class="info-label">نام و نام خانوادگی:</span>
<span>${student.name} ${student.family}</span>
</div>
<div class="info-row">
<span class="info-label">کد ملی:</span>
<span>${student.nationalCode}</span>
</div>
<div class="info-row">
<span class="info-label">مدرسه:</span>
<span>${student.school}</span>
</div>
<div class="info-row">
<span class="info-label">شاخه پیشنهادی:</span>
<span><strong>${student.branch}</strong></span>
</div>
<div class="info-row">
<span class="info-label">رشته پیشنهادی:</span>
<span><strong>${student.field}</strong></span>
</div>
</div>
<h3 style="margin-top: 1rem; margin-bottom: 0.6rem; color: #4338ca;">وضعیت مجاز بودن رشتهها</h3>
<table class="field-table" role="table" aria-label="وضعیت مجاز بودن رشته ها">
<thead>
<tr>
<th>شاخه</th>
<th>رشته</th>
<th>وضعیت</th>
<th>شرایط</th>
</tr>
</thead>
<tbody>
${Object.entries(student.eligibleFields).map(([branch, fields]) =>
Object.entries(fields).map(([field, isEligible]) => `
<tr>
<td>${branch}</td>
<td>${field}</td>
<td class="${isEligible ? 'eligible' : 'ineligible'}">${isEligible ? 'مجاز' : 'غیرمجاز'}</td>
<td>${fieldsOfStudy[branch][field]['توضیحات']}</td>
</tr>`
).join('')
).join('')}
</tbody>
</table>
<div style="margin-top: 20px;">
<div class="info-row">
<span class="info-label">نقاط قوت:</span>
<span>${student.strengths.join('، ')}</span>
</div>
<div class="info-row">
<span class="info-label">نقاط ضعف:</span>
<span>${student.weaknesses.join('، ')}</span>
</div>
</div>
<div class="signature-area print-only" style="display:none;">
<div>
<div class="signature-line"></div>
<p>امضاء و مهر مشاور</p>
</div>
<div>
<div class="signature-line"></div>
<p>امضاء و مهر مدیر</p>
</div>
<div>
<p>تاریخ: ______________</p>
</div>
</div>
</div>`;
}
// Accessibility: allow label keyboard interaction
document.querySelector('.file-upload-label').addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
document.getElementById('excelFile').click();
}
});
</script>
</body>
</html>
What this includes:
Your PHP session check and user greeting.
Modern and clean UI with gradient backgrounds and card layout.
Fully styled student report cards with proper RTL support.
File upload with large clickable dashed box and icon.
Primary & secondary buttons with nice hover/focus effects.
Loading spinner overlay during file processing.
Student cards loaded dynamically with fade-in animation.
Accessibility improvements (aria attributes, keyboard support).
Print-friendly styles.
How it works:
Click “فایل اکسل دانش آموزان را انتخاب کنید” to pick an Excel file (.xlsx or .xls).
Click پردازش اطلاعات button to load & process the file.
After processing, it displays student info cards below with eligibility tables.
The چاپ گزارشات button appears for printing the report.
If there's any other feature or tweak you want, just ask!
reader.onerror = function() {
alert("خطا در خواندن فایل");
};
reader.readAsArrayBuffer(file);
}
function processStudent(row) {
const gradeFields = {
'ریاضی': ['ریاضی7', 'ریاضی8', 'ریاضی9'],
'علوم': ['علوم7', 'علوم8', 'علوم9'],
'ادبیات فارسی': ['ادبیات7', 'ادبیات8', 'ادبیات9'],
'مطالعات اجتماعی': ['مطالعات7', 'مطالعات8', 'مطالعات9'],
'عربی': ['عربی7', 'عربی8', 'عربی9'],
'معارف اسلامی': ['معارف7', 'معارف8', 'معارف9'],
'کار و فناوری': ['کاروفناوری7', 'کاروفناوری8', 'کاروفناوری9'],
'فرهنگ و هنر': ['فرهنگ و هنر7', 'فرهنگ و هنر8', 'فرهنگ و هنر9']
};
code Copy code
const grades = {};
const averages = {};
for (const [subject, fields] of Object.entries(gradeFields)) {
const gradeData = {
g7: parseFloat(row[fields[0]]) || 0,
g8: parseFloat(row[fields[1]]) || 0,
g9: parseFloat(row[fields[2]]) || 0
};
grades[subject] = gradeData;
// محاسبه میانگین وزنی با ضریب 1 برای هفتم و هشتم و 3 برای نهم
const weightedSum = (gradeData.g7 * 1) + (gradeData.g8 * 1) + (gradeData.g9 * 3);
const weight = 5; // مجموع ضرایب (1+1+3)
averages[subject] = (weightedSum / weight).toFixed(2);
}
const student = {
name: row['نام'] || 'نامشخص',
family: row['نام خانوادگی'] || 'نامشخص',
nationalCode: row['کدملی'] || 'نامشخص',
school: row['مدرسه'] || 'مدرسه امام علی بن ابیطالب (ع)',
grades,
averages,
strengths: [],
weaknesses: []
};
determineFieldAndBranch(student);
analyzeStudentPerformance(student);
return student;
function determineFieldAndBranch(student) {
const avg = student.averages;
const math = parseFloat(avg['ریاضی']);
const sci = parseFloat(avg['علوم']);
const per = parseFloat(avg['ادبیات فارسی']);
const art = parseFloat(avg['فرهنگ و هنر']);
const tech = parseFloat(avg['کار و فناوری']);
const rel = parseFloat(avg['معارف اسلامی']);
const soc = parseFloat(avg['مطالعات اجتماعی']);
code Copy code
// رشتههای نظری
if (math >= 14 && sci >= 13) {
student.branch = "نظری";
student.field = "ریاضی و فیزیک";
}
else if (sci >= 14 && math >= 13) {
student.branch = "نظری";
student.field = "علوم تجربی";
}
else if (per >= 14 && rel >= 14) {
student.branch = "نظری";
student.field = "معارف اسلامی";
}
else if (per >= 14 && soc >= 12) {
student.branch = "نظری";
student.field = "علوم انسانی";
}
// رشتههای فنی و حرفهای
else if (art >= 12 && tech >= 12) {
student.branch = "فنی و حرفهای";
student.field = "هنر";
}
else if (tech >= 12) {
if (math >= 10) {
student.branch = "فنی و حرفهای";
student.field = "صنعت";
}
else if (sci >= 10) {
student.branch = "فنی و حرفهای";
student.field = "کشاورزی";
}
else {
student.branch = "فنی و حرفهای";
student.field = "خدمات";
}
}
// رشتههای کار و دانش
else {
student.branch = "کار و دانش";
if (art >= 10) {
student.field = "هنر";
} else if (math >= 10) {
student.field = "صنعت";
} else if (sci >= 10) {
student.field = "کشاورزی";
} else {
student.field = "خدمات";
}
}
// محاسبه رشتههای مجاز با در نظر گرفتن میانگین وزنی
student.eligibleFields = {};
for (const branch in fieldsOfStudy) {
student.eligibleFields[branch] = {};
for (const field in fieldsOfStudy[branch]) {
const conditions = fieldsOfStudy[branch][field];
let isEligible = true;
for (const subject in conditions) {
if (subject !== 'توضیحات') {
const studentGrade = parseFloat(avg[subject]) || 0;
if (studentGrade < conditions[subject]) {
isEligible = false;
break;
}
}
}
student.eligibleFields[branch][field] = isEligible;
}
}
function analyzeStudentPerformance(student) {
const avg = student.averages;
code Copy code
// نقاط قوت (نمرات 14 و بالاتر)
if (parseFloat(avg['ریاضی']) >= 14) student.strengths.push('ریاضیات');
if (parseFloat(avg['علوم']) >= 14) student.strengths.push('علوم');
if (parseFloat(avg['ادبیات فارسی']) >= 14) student.strengths.push('ادبیات فارسی');
if (parseFloat(avg['فرهنگ و هنر']) >= 14) student.strengths.push('فرهنگ و هنر');
if (parseFloat(avg['کار و فناوری']) >= 14) student.strengths.push('کار و فناوری');
// نقاط ضعف (نمرات کمتر از 10)
if (parseFloat(avg['ریاضی']) < 10) student.weaknesses.push('ریاضیات');
if (parseFloat(avg['علوم']) < 10) student.weaknesses.push('علوم');
if (parseFloat(avg['ادبیات فارسی']) < 10) student.weaknesses.push('ادبیات فارسی');
if (parseFloat(avg['کار و فناوری']) < 10) student.weaknesses.push('کار و فناوری');
if (student.strengths.length === 0) {
student.strengths.push('نیاز به بررسی بیشتر توسط مشاور');
}
function generatePrintForm(student) {
return `
نام و نام خانوادگی:
s t u d e n t . n a m e {student.name} s t u d e n t . nam e {student.family}
کد ملی:
s t u d e n t . n a t i o n a l C o d e < / s p a n > < / d i v > < d i v c l a s s = " i n f o − r o w " > < s p a n c l a s s = " i n f o − l a b e l " > مدرسه : < / s p a n > < s p a n > {student.nationalCode}</span>
</div>
<div class="info-row">
<span class="info-label">مدرسه:</span>
<span> s t u d e n t . na t i o na l C o d e < / s p an >< / d i v >< d i v c l a ss = " in f o − {student.school}
شاخه پیشنهادی:
s t u d e n t . b r a n c h < / s t r o n g > < / s p a n > < / d i v > < d i v c l a s s = " i n f o − r o w " > < s p a n c l a s s = " i n f o − l a b e l " > رشتهپیشنهادی : < / s p a n > < s p a n > < s t r o n g > {student.branch}</strong></span>
</div>
<div class="info-row">
<span class="info-label">رشته پیشنهادی:</span>
<span><strong> s t u d {student.field}
code Copy code
<h3>وضعیت مجاز بودن رشتهها</h3>
<table class="field-table">
<thead>
<tr>
<th>شاخه</th>
<th>رشته</th>
<th>وضعیت</th>
<th>شرایط</th>
</tr>
</thead>
<tbody>
${Object.entries(student.eligibleFields).map(([branch, fields]) =>
Object.entries(fields).map(([field, isEligible]) => `
<tr>
<td>${branch}</td>
<td>${field}</td>
<td class="${isEligible ? 'eligible' : 'ineligible'}">${isEligible ? 'مجاز' : 'غیرمجاز'}</td>
<td>${fieldsOfStudy[branch][field]['توضیحات']}</td>
</tr>`
).join('')
).join('')}
</tbody>
</table>
<div style="margin-top: 20px;">
<div class="info-row">
<span class="info-label">نقاط قوت:</span>
<span>${student.strengths.join('، ')}</span>
</div>
<div class="info-row">
<span class="info-label">نقاط ضعف:</span>
<span>${student.weaknesses.join('، ')}</span>
</div>
</div>
<div class="signature-area print-only">
<div>
<div class="signature-line"></div>
<p>امضاء و مهر مشاور</p>
</div>
<div>
<div class="signature-line"></div>
<p>امضاء و مهر مدیر</p>
</div>
<div>
<p>تاریخ: ______________</p>
</div>
</div>
</div>`;
// Only adding the loading indicator functionality
async function handleFile() {
const loadingIndicator = document.getElementById('loadingIndicator');
const reportContainer = document.getElementById('report');
try {
// Show loading indicator
loadingIndicator.style.display = 'block';
reportContainer.innerHTML = '';
code Copy code
const file = document.getElementById('excelFile').files[0];
if (!file) {
throw new Error("لطفاً یک فایل اکسل انتخاب کنید");
}
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
if (workbook.SheetNames.length === 0) {
throw new Error("فایل انتخابی حاوی هیچ صفحهای نیست");
}
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet, { defval: null });
if (jsonData.length === 0) {
throw new Error("صفحه انتخابی حاوی دادهای نیست");
}
const students = jsonData.map(row => processStudent(row));
const reportHTML = students.map(student => generatePrintForm(student)).join("");
// Hide loading indicator and show results
loadingIndicator.style.display = 'none';
reportContainer.innerHTML = reportHTML;
document.getElementById("printBtn").style.display = "inline-block";
// Add animation to reports
document.querySelectorAll('.print-form').forEach((el, i) => {
el.classList.add('animate-fade-in');
el.style.animationDelay = `${i * 0.1}s`;
});
reportContainer.scrollIntoView({ behavior: 'smooth' });
} catch (error) {
loadingIndicator.style.display = 'none';
handleError(error);
}
};
reader.onerror = function() {
loadingIndicator.style.display = 'none';
throw new Error("خطا در خواندن فایل");
};
reader.readAsArrayBuffer(file);
} catch (error) {
loadingIndicator.style.display = 'none';
handleError(error);
}
}
function handleError(error) {
console.error("Error:", error);
alert(error.message || "خطایی رخ داده است. لطفاً دوباره تلاش کنید.");
}
const fieldsOfStudy = {
"نظری": {
"ریاضی و فیزیک": {
'ریاضی': 14, 'علوم': 13,
'توضیحات': 'نمره ریاضی ≥ ۱۴ و علوم ≥ ۱۳'
},
"علوم تجربی": {
'ریاضی': 13, 'علوم': 14,
'توضیحات': 'نمره علوم ≥ ۱۴ و ریاضی ≥ ۱۳'
},
"علوم انسانی": {
'ادبیات فارسی': 14, 'مطالعات اجتماعی': 12,
'توضیحات': 'نمره ادبیات ≥ ۱۴ و مطالعات ≥ ۱۲'
},
"معارف اسلامی": {
'ادبیات فارسی': 14, 'معارف اسلامی': 14,
'توضیحات': 'نمره ادبیات و معارف ≥ ۱۴'
}
},
"فنی و حرفهای": {
"صنعت": {
'ریاضی': 10, 'کار و فناوری': 12,
'توضیحات': 'نمره ریاضی ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"خدمات": {
'کار و فناوری': 12, 'فرهنگ و هنر': 12,
'توضیحات': 'نمره کاروفناوری ≥ ۱۲ و فرهنگ و هنر ≥ ۱۲'
},
"کشاورزی": {
'علوم': 10, 'کار و فناوری': 12,
'توضیحات': 'نمره علوم ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"هنر": {
'فرهنگ و هنر': 12, 'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۲ و کاروفناوری ≥ ۱۲'
}
},
"کار و دانش": {
"صنعت": {
'ریاضی': 10, 'کار و فناوری': 12,
'توضیحات': 'نمره ریاضی ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"خدمات": {
'فرهنگ و هنر': 10, 'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"کشاورزی": {
'علوم': 10, 'کار و فناوری': 12,
'توضیحات': 'نمره علوم ≥ ۱۰ و کاروفناوری ≥ ۱۲'
},
"هنر": {
'فرهنگ و هنر': 10, 'کار و فناوری': 12,
'توضیحات': 'نمره فرهنگ و هنر ≥ ۱۰ و کاروفناوری ≥ ۱۲'
}
}
};
const gradeFields = {
'ریاضی': ['ریاضی7', 'ریاضی8', 'ریاضی9'],
'علوم': ['علوم7', 'علوم8', 'علوم9'],
'ادبیات فارسی': ['ادبیات7', 'ادبیات8', 'ادبیات9'],
'مطالعات اجتماعی': ['مطالعات7', 'مطالعات8', 'مطالعات9'],
'عربی': ['عربی7', 'عربی8', 'عربی9'],
'معارف اسلامی': ['معارف7', 'معارف8', 'معارف9'],
'کار و فناوری': ['کاروفناوری7', 'کاروفناوری8', 'کاروفناوری9'],
'فرهنگ و هنر': ['فرهنگ و هنر7', 'فرهنگ و هنر8', 'فرهنگ و هنر9']
};
function readFileAsync(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = e => resolve(new Uint8Array(e.target.result));
reader.onerror = () => reject(new Error("خطا در خواندن فایل"));
reader.readAsArrayBuffer(file);
});
}
async function handleFile() {
const loadingIndicator = document.getElementById('loadingIndicator');
const reportContainer = document.getElementById('report');
const processBtn = document.getElementById('processBtn');
const printBtn = document.getElementById('printBtn');
try {
const fileInput = document.getElementById('excelFile');
const file = fileInput.files[0];
if (!file) {
alert("لطفاً یک فایل اکسل انتخاب کنید");
return;
}
loadingIndicator.style.display = 'flex';
reportContainer.innerHTML = "";
processBtn.disabled = true;
processBtn.setAttribute('aria-busy', 'true');
printBtn.style.display = "none";
const data = await readFileAsync(file);
const workbook = XLSX.read(data, { type: 'array' });
if (workbook.SheetNames.length === 0) {
throw new Error("فایل انتخابی حاوی هیچ صفحهای نیست");
}
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet, { defval: null });
if (jsonData.length === 0) {
throw new Error("صفحه انتخابی حاوی دادهای نیست");
}
const students = jsonData.map(processStudent);
reportContainer.innerHTML = students.map(generatePrintForm).join("");
// Animate cards
document.querySelectorAll('.print-form').forEach((el, i) => {
el.classList.add('animate-fade-in');
el.style.animationDelay = `${i * 0.1}s`;
});
loadingIndicator.style.display = 'none';
printBtn.style.display = "inline-block";
processBtn.disabled = false;
processBtn.setAttribute('aria-busy', 'false');
reportContainer.scrollIntoView({ behavior: 'smooth' });
} catch (error) {
loadingIndicator.style.display = 'none';
alert(error.message || "خطایی رخ داده است. لطفاً دوباره تلاش کنید.");
console.error(error);
processBtn.disabled = false;
processBtn.setAttribute('aria-busy', 'false');
}
}
function parseWeightedAverage(row, fields) {
const g7 = parseFloat(row[fields[0]]) || 0;
const g8 = parseFloat(row[fields[1]]) || 0;
const g9 = parseFloat(row[fields[2]]) || 0;
const totalWeight = 5; // 1+1+3
return ((g7 + g8 + g9*3) / totalWeight);
}
function processStudent(row) {
const averages = {};
const grades = {};
for (const [subject, fields] of Object.entries(gradeFields)) {
const avg = parseWeightedAverage(row, fields);
averages[subject] = avg.toFixed(2);
grades[subject] = fields.map(f => parseFloat(row[f]) || 0);
}
const student = {
name: row['نام'] || 'نامشخص',
family: row['نام خانوادگی'] || 'نامشخص',
nationalCode: row['کدملی'] || 'نامشخص',
school: row['مدرسه'] || 'مدرسه امام علی بن ابیطالب (ع)',
grades,
averages,
strengths: [],
weaknesses: []
};
assignBranchAndField(student);
analyzeStudentPerformance(student);
assignEligibility(student);
return student;
}
function assignBranchAndField(student) {
const avg = student.averages;
const math = parseFloat(avg['ریاضی']);
const sci = parseFloat(avg['علوم']);
const per = parseFloat(avg['ادبیات فارسی']);
const art = parseFloat(avg['فرهنگ و هنر']);
const tech = parseFloat(avg['کار و فناوری']);
const rel = parseFloat(avg['معارف اسلامی']);
const soc = parseFloat(avg['مطالعات اجتماعی']);
if (math >= 14 && sci >= 13) {
student.branch = "نظری";
student.field = "ریاضی و فیزیک";
} else if (sci >= 14 && math >= 13) {
student.branch = "نظری";
student.field = "علوم تجربی";
} else if (per >= 14 && rel >= 14) {
student.branch = "نظری";
student.field = "معارف اسلامی";
} else if (per >= 14 && soc >= 12) {
student.branch = "نظری";
student.field = "علوم انسانی";
} else if (art >= 12 && tech >= 12) {
student.branch = "فنی و حرفهای";
student.field = "هنر";
} else if (tech >= 12) {
if (math >= 10) {
student.branch = "فنی و حرفهای";
student.field = "صنعت";
} else if (sci >= 10) {
student.branch = "فنی و حرفهای";
student.field = "کشاورزی";
} else {
student.branch = "فنی و حرفهای";
student.field = "خدمات";
}
} else {
student.branch = "کار و دانش";
if (art >= 10) {
student.field = "هنر";
} else if (math >= 10) {
student.field = "صنعت";
} else if (sci >= 10) {
student.field = "کشاورزی";
} else {
student.field = "خدمات";
}
}
}
function assignEligibility(student) {
const avg = student.averages;
student.eligibleFields = {};
for (const [branch, fields] of Object.entries(fieldsOfStudy)) {
student.eligibleFields[branch] = {};
for (const [field, criteria] of Object.entries(fields)) {
const isEligible = Object.entries(criteria)
.filter(([key]) => key !== 'توضیحات')
.every(([subject, threshold]) => (parseFloat(avg[subject]) || 0) >= threshold);
student.eligibleFields[branch][field] = isEligible;
}
}
}
function analyzeStudentPerformance(student) {
const avg = student.averages;
const strengths = [];
const weaknesses = [];
const subjects = [
['ریاضی', 14],
['علوم', 14],
['ادبیات فارسی', 14],
['فرهنگ و هنر', 14],
['کار و فناوری', 14],
];
subjects.forEach(([subject, threshold]) => {
if (parseFloat(avg[subject]) >= threshold) strengths.push(subject);
});
const weakSubjects = ['ریاضی', 'علوم', 'ادبیات فارسی', 'کار و فناوری'];
weakSubjects.forEach(subject => {
if (parseFloat(avg[subject]) < 10) weaknesses.push(subject);
});
student.strengths = strengths.length ? strengths : ['نیاز به بررسی بیشتر توسط مشاور'];
student.weaknesses = weaknesses;
}
function generatePrintForm(student) {
const eligibleRows = Object.entries(student.eligibleFields)
.map(([branch, fields]) => Object.entries(fields)
.map(([field, isEligible]) => `
<tr>
<td>${branch}</td>
<td>${field}</td>
<td class="${isEligible ? 'eligible' : 'ineligible'}">${isEligible ? 'مجاز' : 'غیرمجاز'}</td>
<td>${fieldsOfStudy[branch][field]['توضیحات']}</td>
</tr>`)
.join(''))
.join('');
return `
<div class="print-form student-report">
<div class="student-info">
<div class="info-row"><span class="info-label">نام و نام خانوادگی:</span><span>${student.name} ${student.family}</span></div>
<div class="info-row"><span class="info-label">کد ملی:</span><span>${student.nationalCode}</span></div>
<div class="info-row"><span class="info-label">مدرسه:</span><span>${student.school}</span></div>
<div class="info-row"><span class="info-label">شاخه پیشنهادی:</span><span><strong>${student.branch}</strong></span></div>
<div class="info-row"><span class="info-label">رشته پیشنهادی:</span><span><strong>${student.field}</strong></span></div>
</div>
<h3>وضعیت مجاز بودن رشتهها</h3>
<table class="field-table" role="table" aria-label="وضعیت مجاز بودن رشته ها">
<thead>
<tr>
<th>شاخه</th>
<th>رشته</th>
<th>وضعیت</th>
<th>شرایط</th>
</tr>
</thead>
<tbody>
${eligibleRows}
</tbody>
</table>
<div style="margin-top: 20px;">
<div class="info-row"><span class="info-label">نقاط قوت:</span><span>${student.strengths.join('، ')}</span></div>
<div class="info-row"><span class="info-label">نقاط ضعف:</span><span>${student.weaknesses.join('، ')}</span></div>
</div>
<div class="signature-area print-only">
<div><div class="signature-line"></div><p>امضاء و مهر مشاور</p></div>
<div><div class="signature-line"></div><p>امضاء و مهر مدیر</p></div>
<div><p>تاریخ: ______________</p></div>
</div>
</div>`;
}
Summary of improvements:
Converted handleFile to async/await with readFileAsync helper for cleaner async handling.
Removed duplicate handleFile definitions.
Used .map and .every for eligibility checks, improving readability.
Reduced repeated parseFloat calls by storing averages centrally.
Grouped subject thresholds and logic in arrays to simplify strength/weakness assignment.
Simplified HTML generation with cleaner template literals.
Added appropriate roles and aria-labels in table for accessibility (optional but recommended).
Grouped constant objects outside functions for clarity.
Using early returns and clear error handling in handleFile.
This code is easier to maintain and understand and will behave equivalently.
Let me know if you'd like me to help integrate it into your full page!
e − > g e tM ess a g e ( ) , ( in t )
<?php
// db.php: Database connection wrapper
class Database {
private $host = 'localhost';
private $db = 'mydb1';
private $user = 'root';
private $pass = '';
private $charset = 'utf8mb4';
private $pdo;
private $error;
private $options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Throw exceptions on errors
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Fetch assoc arrays
PDO::ATTR_EMULATE_PREPARES => false, // Disable emulated prepares for security
PDO::ATTR_PERSISTENT => true // Use persistent connection (optional)
];
public function __construct() {
$dsn = "mysql:host={$this->host};dbname={$this->db};charset={$this->charset}";
try {
$this->pdo = new PDO($dsn, $this->user, $this->pass, $this->options);
// Optional: Set default timezone for DB connection if needed
$this->pdo->exec("SET time_zone = '+00:00';");
} catch (PDOException $e) {
$this->error = $e->getMessage();
// Log the error (to a file or error monitoring system)
error_log("Database Connection Error: " . $this->error);
// Optional: Display custom error or redirect
// die("Database connection failed. Please try again later.");
throw new Exception("Database connection failed.");
}
}
// Get PDO instance (for querying)
public function getConnection() {
return $this->pdo;
}
}
php Copy code
require_once 'db.php';
try {
$database = new Database();
$pdo = $database->getConnection();
// Example query:
$stmt = $pdo->query('SELECT * FROM users');
$users = $stmt->fetchAll();
} catch (Exception $e) {
// handle or display a user-friendly error message
echo "خطا در ارتباط با پایگاه داده";
// optionally log detailed error
}
Why this is better:
You encapsulate the connection and error handling in a class.
You can reuse the connection object easily.
Persistent connection option reduces connection overhead if your app needs it.
You store errors to logs, avoiding leaking sensitive info to users.
You separate config from business logic for cleaner maintainability.
Adding extra PDO options if needed is easy.
Alternatively, minimal improvement just to your snippet: php Copy code
<?php
$host = 'localhost';
$db = 'mydb1';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
try {
$pdo = new PDO($dsn, $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_PERSISTENT => true, // optional persistent connection
]);
// Optional: setting timezone on connection
$pdo->exec("SET time_zone = '+00:00';");
} catch (PDOException $e) {
error_log("DB connection failed: ".$e->getMessage());
// Show a generic message to user
die("ارتباط با پایگاه داده برقرار نشد. لطفاً مجدداً تلاش کنید.");
}
If you want, I can help with specific database abstraction layers, or adding prepared statement helpers, or more! Just let me know.
Reduces infrastructure management; auto-scales easily.
What fits best for your "هدایت تحصیلی هوشمند" system?
If you want stable, straightforward, and have PHP experience:
Laravel would be a natural next step. It provides polished ORM, validation, authentication, routing, API resources, and good integration with Vue/React if you want SPA frontend later.
If you want JavaScript end-to-end, and perhaps REST or GraphQL APIs:
Node.js with Express or NestJS is superb. NestJS especially helps build maintainable and scalable apps with TypeScript.
If you want fast API development and possibly integration with Python ML/analysis:
FastAPI (Python) would be excellent.
If startup speed and low maintenance are priorities, and your data is mostly CRUD + light logic:
Try serverless with Firebase or Hasura.
Additional tips:
Think about frontend as well. If you want reactive UI:
Use Vue.js (Laravel supports it well) or React/Angular.
Consider your deployment options and hosting budget.
For the database, MySQL is fine, but you might also explore PostgreSQL for advanced features.
Summary Backend Option When to Choose PHP + Laravel Stay with PHP, want modern framework & ecosystem Node.js + Express/Nest JS/TS full stack, scalable, real-time APIs Python + FastAPI/Django Rapid dev, async, data/AI heavy apps Go (Gin/Echo) High performance, concurrency heavy Serverless (Firebase) Quick dev, auto scalable, minimal backend management
If you want, I can help you scaffold any of these backends or suggest concrete next steps! What stack or features do you prefer?
Implement error logging to files or monitoring services.
9. File Storage & Management
Allow users to upload multiple Excel or other data files.
Store those files securely on the server or cloud storage with metadata.
Allow downloading previous uploads or backups.
10. Performance & Security
Rate-limit file uploads or API calls to avoid abuse.
Use HTTPS and secure cookies.
Implement CSRF protection for forms.
Cache heavy queries or reports to improve responsiveness.
11. Multi-language / Localization Support
Prepare the backend and frontend for additional languages if needed.
Use translation files or databases for UI strings.
12. Admin Panel
Build a backend admin dashboard for managing users, viewing uploads, approving/denying data.
Manage system configuration and settings.
13. Integration with External Systems
Single sign-on (SSO) with school authentication systems.
Integration with Learning Management Systems (LMS), government education portals or analytics software.
Prioritized roadmap example:
User Authentication + Role Management
Store Excel data in Database + CRUD interface
Error handling and validation
Reporting & export to PDF/Excel
Notifications (email/SMS)
Admin dashboard
API endpoints for future clients
Audit logs & usage analytics
Summary The most valuable next step depends on your users and goals, but typically:
Secure, role-based user login & data storage comes first.
Then solid data management + export/reporting.
Later, notifications, administration, and integration features.
If you want, I can help you write code for any of these features, or design the database schema and backend API endpoints. Just tell me what you want to tackle next!
Explanation:
page-break-inside: avoid prevents student cards from breaking mid-card.
page-break-after: always ensures that after each card, a page break happens, putting each student card on its own page.
max-height: 27cm makes the card height fit inside an A4 page vertically with some margin.
Font sizes, margins and paddings slightly reduced for print to use space efficiently.
Body margin for print ensures proper printer margins.
Removed box shadows and border radius for clean print output.
Optional: If you want multiple cards per page (e.g. 2 or 4 cards), remove page-break-after: always and arrange .print-form width: css Copy code
@media print {
#report {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.print-form {
flex: 0 0 48%; /* Two cards per page width */
box-sizing: border-box;
max-height: 13.5cm; /* half of A4 with margin */
page-break-inside: avoid;
page-break-after: auto;
}
}
How to apply:
Replace your existing @media print CSS block with the improved one above (or add the new rules).
Test print preview — each student card should perfectly fit inside an A4 page.
Adjust max-height values or font sizes as needed for your exact card content length.
If you want me to generate a complete updated page with these fixes integrated, please let me know.
@media print {
/* Hide sticky header */
.dashboard-header {
display: none !important;
}
/* Don't print branding and upload */
.no-print {
display: none !important;
}
/* Give some space at start of report */
.print-form:first-child {
margin-top: 2cm;
}
/* Start report on a fresh page */
#report {
break-before: page;
page-break-before: always;
}
/* Student cards print adjustments */
.print-form {
page-break-inside: avoid;
page-break-after: always;
max-height: 27cm;
padding: 1rem;
font-size: 0.95rem;
box-shadow: none;
border-radius: 0;
color: black;
}
/* Reduce info-row margin for print */
.info-row {
margin-bottom: 0.3rem;
}
/* Table adjustments */
.field-table th, .field-table td {
padding: 6px 8px;
font-size: 0.85rem;
}
/* Signature area */
.signature-area {
display: flex !important;
margin-top: 1.5rem;
font-weight: 600;
font-size: 0.9rem;
}
/* Body and report container */
body {
margin: 0.5cm;
background: white !important;
color: black !important;
}
#report {
box-shadow: none;
padding: 0;
font-size: 0.9rem;
line-height: 1.3;
}
}
Testing tips:
Use browser Print Preview mode.
Adjust the margin-top: 2cm; value for .print-form:first-child if needed.
Ensure the .no-print class is applied to the branding/upload sections.
Try toggling break-before / page-break-before to see if forcing new page helps.
If you want, I can generate your full updated page with these fixes integrated to minimize all first-page print conflicts.
Just say the word!
r o w " ><
s p an c l a ss =
" in f o −
l ab e l " >
مدرسه :<
/ s p an ><
s p an >
e
n
t
.
b
r
an
c
h
<
/ s t r o n g ><
/ s p an ><
/ d i v ><
d i v c l a ss =
" in f o −
r o w " ><
s p an c l a ss =
" in f o −
l ab e l " >
رشتهپیشنهادی :<
/ s p an ><
s p an ><
s t r o n g >
r o w " ><
s p an c l a ss =
" in f o −
l ab e l " >
مدرسه :<
/ s p an ><
s p an >
e
n
t
.
b
r
an
c
h
<
/ s t r o n g ><
/ s p an ><
/ d i v ><
d i v c l a ss =
" in f o −
r o w " ><
s p an c l a ss =
" in f o −
l ab e l " >
رشتهپیشنهادی :<
/ s p an ><
s p an ><
s t r o n g >