
<?php
include('dbconnection.php');
session_start();

if(!$_SESSION['emp_email'])  
{  
header("Location: login.php");//redirect to login page to secure the welcome page without login access.  
}  
?>
<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="format-detection" content="telephone=no">
	
	<!-- PAGE TITLE HERE -->
	<title>صفحه اصلی</title>
	
	<!-- FAVICONS ICON -->
	<link rel="shortcut icon" type="image/png" href="images/favicon.png">
	
	<link href="vendor/jquery-nice-select/css/nice-select.css" rel="stylesheet">
	<link rel="stylesheet" href="vendor/nouislider/nouislider.min.css">
	<!-- Style css -->
    <link href="css/style.css" rel="stylesheet">
	
	
</head>
<body>

    <!--*******************
        Preloader start
    ********************-->
    <div id="preloader">
        <div class="waviy">
		   <span style="--i:1">N</span>
		   <span style="--i:2">A</span>
		   <span style="--i:3">I</span>
		   <span style="--i:4">M</span>
		   <span style="--i:5">-</span>
		   <span style="--i:5">A</span>
		   <span style="--i:5">R</span>
		   <span style="--i:6">I</span>
           <span style="--i:6">A</span>
		   <span style="--i:7">-</span>
           <span style="--i:8">E</span>
		   <span style="--i:9">D</span>
           <span style="--i:10">U</span>
		</div>
    </div>
    <!--*******************
        Preloader end
    ********************-->

    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

        <!--**********************************
            Nav header start
        ***********************************-->
        <div class="nav-header">
            <a href="index.php" class="brand-logo">
			<img src="images/logo1.png" alt="" height="70" width="70">
            </a>
            <div class="nav-control">
                <div class="hamburger">
                    <span class="line"></span><span class="line"></span><span class="line"></span>
                </div>
            </div>
        </div>
        <!--**********************************
            Nav header end
        ***********************************-->
		
		<!--**********************************
            Chat box start
        ***********************************-->

		<!--**********************************
            Chat box End
        ***********************************-->
		
		<!--**********************************
            Header start
        ***********************************-->
        <div class="header">
            <div class="header-content">
                <nav class="navbar navbar-expand">
                    <div class="collapse navbar-collapse justify-content-between">
                        <div class="header-left">
							<div class="dashboard_bar">
							<h1>صفحه اصلی	</h1>
                            </div>
                        </div>
                        <ul class="navbar-nav header-right">
							<?php


// Get upcoming payment notifications
$sql = "
SELECT 
    payments.*, 
    student.s_name,
    (SELECT COUNT(*) 
     FROM payments AS p 
     WHERE p.end_date BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)) AS payment_count
FROM payments
INNER JOIN student ON payments.s_id = student.s_id
WHERE payments.end_date BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)
ORDER BY payments.end_date ASC
";

$result = $con->query($sql);
$notifications = [];
$payment_count = 0;

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $notifications[] = $row;
        $payment_count = $row['payment_count']; // Same for all rows, just use the last
    }
}
?>

						
                              <li class="nav-item dropdown notification_dropdown">
    <a class="nav-link ai-icon" href="javascript:void(0);" role="button" data-bs-toggle="dropdown">
        <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path fill-rule="evenodd" clip-rule="evenodd"
                d="M12.638 4.9936V2.3C12.638 1.5824 13.2484 1 14.0006 1C14.7513 1 15.3631 1.5824 15.3631 2.3V4.9936C17.3879 5.2718 19.2805 6.1688 20.7438 7.565C22.5329 9.2719 23.5384 11.5872 23.5384 14V18.8932L24.6408 20.9966C25.1681 22.0041 25.1122 23.2001 24.4909 24.1582C23.8709 25.1163 22.774 25.7 21.5941 25.7H15.3631C15.3631 26.4176 14.7513 27 14.0006 27C13.2484 27 12.638 26.4176 12.638 25.7H6.40705C5.22571 25.7 4.12888 25.1163 3.50892 24.1582C2.88759 23.2001 2.83172 22.0041 3.36039 20.9966L4.46268 18.8932V14C4.46268 11.5872 5.46691 9.2719 7.25594 7.565C8.72068 6.1688 10.6119 5.2718 12.638 4.9936ZM14.0006 7.5C12.1924 7.5 10.4607 8.1851 9.18259 9.4045C7.90452 10.6226 7.18779 12.2762 7.18779 14V19.2C7.18779 19.4015 7.13739 19.6004 7.04337 19.7811C7.04337 19.7811 6.43703 20.9381 5.79662 22.1588C5.69171 22.3603 5.70261 22.6008 5.82661 22.7919C5.9506 22.983 6.16996 23.1 6.40705 23.1H21.5941C21.8298 23.1 22.0492 22.983 22.1732 22.7919C22.2972 22.6008 22.3081 22.3603 22.2031 22.1588C21.5627 20.9381 20.9564 19.7811 20.9564 19.7811C20.8624 19.6004 20.8133 19.4015 20.8133 19.2V14C20.8133 12.2762 20.0953 10.6226 18.8172 9.4045C17.5391 8.1851 15.8073 7.5 14.0006 7.5Z"
                fill="#4f7086"></path>
        </svg>
        <span class="badge light text-white bg-primary rounded-circle">
            <?php echo $payment_count; ?>
        </span>
    </a>
    <div class="dropdown-menu dropdown-menu-end">
        <div id="dlab_W_Notification1" class="widget-media dlab-scroll p-3" style="height:380px;">
            <ul class="timeline">
                <?php if (count($notifications) > 0): ?>
                    <?php foreach ($notifications as $note): ?>
                        <li>
                            <div class="timeline-panel">
                                <div class="media me-2 bg-primary">
                                    <i class="fa fa-bell text-white"></i>
                                </div>
                                <div class="media-body">
                                    <h6 class="mb-1 text-primary"><?php echo htmlspecialchars($note['s_name']); ?></h6>
                                    <small class="d-block">تاریخ ختم <?php echo date("Y-m-d", strtotime($note['end_date'])); ?></small>
                                    
                                </div>
                            </div>
                        </li>
                    <?php endforeach; ?>
                <?php else: ?>
                    <li>
                        <div class="timeline-panel">
                            <div class="media-body text-center">
                                <small class="text-muted">No upcoming payments.</small>
                            </div>
                        </div>
                    </li>
                <?php endif; ?>
            </ul>
        </div>
    </div>
</li>

                          
				<!---
					
				----->


                        </ul>
                    </div>
				</nav>
			</div>
		</div>
        <!--**********************************
            Header end ti-comment-alt
        ***********************************-->

        <!--**********************************
            Sidebar start
        ***********************************-->
		<div class="dlabnav">
            <div class="dlabnav-scroll">
				<ul class="metismenu" id="menu">
					<li class="dropdown header-profile">
						<a class="nav-link" href="javascript:void(0);" role="button" data-bs-toggle="dropdown">
							<img src="images/profile/profile.png" width="20" alt="">
							<div class="header-info ms-3">
								<span class="font-w600 "><?php echo $_SESSION['emp_name']; ?></span>
								<small class="text-end font-w400"><?php echo $_SESSION['emp_email']; ?></small>
							</div>
						</a>
						<div class="dropdown-menu dropdown-menu-end">
							<a href="app-profile.php" class="dropdown-item ai-icon">
								<svg id="icon-user1" xmlns="http://www.w3.org/2000/svg" class="text-primary" width="18" height="18" viewbox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>
								<span class="ms-2">پروفایل</span>
							</a>
							<a href="logout.php" class="dropdown-item ai-icon">
								<svg id="icon-logout" xmlns="http://www.w3.org/2000/svg" class="text-danger" width="18" height="18" viewbox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line></svg>
								<span class="ms-2">خروج از سیتم </span>
							</a>
							
						</div>
					</li>
              
					<li><a class="ai-icon" href="index.php" aria-expanded="false" style='font-size:20px;font-weight: bold;'>
						<i class="flaticon-025-dashboard"></i>
						<span class="nav-text">صفحه اصلی</span>
					</a>
				
				</li>
                    <li><a class="has-arrow ai-icon" href="javascript:void()" aria-expanded="false" style='font-size:20px;font-weight: bold;'>
						<i class="icon-user"></i>
							<span class="nav-text">لیست محصلین</span>
							
						</a>
                        <ul aria-expanded="false">
                            <li><a href="add_student.php" style='font-size:20px;font-weight: bold;'>اضافه محصل</a></li>
							<li><a href="view_student.php" style='font-size:20px;font-weight: bold;'>مشاهده محصل</a></li>
							<li><a href="view_all_student.php" style='font-size:20px;font-weight: bold;'>مشاهده محصلین</a></li>
							
                        </ul>
                    </li>
                  

  
                    <li><a class="has-arrow ai-icon" href="javascript:void()" aria-expanded="false">
							<i class="fa fa-book"></i>
							<span class="nav-text" style='font-size:20px;font-weight: bold;'>بخش صنف</span>
						</a>
                        <ul aria-expanded="false">
							<li><a href="add_course.php" style='font-size:20px;font-weight: bold;'>اضافه صنف جدید </a></li>
							<li><a href="view_course.php" style='font-size:20px;font-weight: bold;'>مشاهده صنوف</a></li>

                        </ul>
                    </li>
					<li><a class="has-arrow ai-icon" href="javascript:void()" aria-expanded="false" style='font-size:20px;font-weight: bold;'>
						<i class="icon-user"></i>
							<span class="nav-text">بخش اساتید</span>
							
						</a>
                        <ul aria-expanded="false">
                            <li><a href="view_teacher.php" style='font-size:20px;font-weight: bold;'>مشاهده</a></li>
							
							
                        </ul>
                    </li>
					<li><a  class="has-arrow ai-icon" aria-expanded="false">
							<i class="fa fa-file-invoice-dollar"></i>
							<span class="nav-text" style='font-size:20px;font-weight: bold;'>بخش پول صیف</span>
						</a>
						<ul aria-expanded="false">
                            
                            <li><a href="view_cash_point_details.php" style='font-size:20px;font-weight: bold;'>راپور صیف</a></li>
							<li><a href="add_view_expenses.php" style='font-size:20px;font-weight: bold;'>اضافه و مشاهده مصارف</a></li>
							
							
                        </ul>
					</li>

					<li><a  class="has-arrow ai-icon" aria-expanded="false">
							<i class="fa fa-calendar"></i>
							<span class="nav-text" style='font-size:20px;font-weight: bold;'>مشاهده راپور ها</span>
						</a>
						<ul aria-expanded="false">
                            
                            <li><a href="cash_point_report.php" style='font-size:20px;font-weight: bold;'>راپور صیف</a></li>
							<li><a href="student_report.php" style='font-size:20px;font-weight: bold;'>راپور محصلین</a></li>

							
                        </ul>
					</li>

                </ul>
			<div class="copyright">
					<p><strong>Student MIS Admin Dashboard</strong> © 2025 All Rights Reserved</p>
					<p class="fs-12">Made with <span class="heart"></span> by Dynamic & Cryptic</p>
				</div>
			</div>
        </div>
        <!--**********************************
            Sidebar end
        ***********************************-->
		
		<!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">
            <!-- row -->
			<div class="container-fluid">
				<div class="row invoice-card-row">
				<div class="col-xl-3 col-xxl-6 col-lg-6 col-sm-6">
						<div class="widget-stat card bg-primary">
							<div class="card-body  p-4">
								<div class="media">
									<span class="me-3">
										<i class="la la-users"></i>
									</span>
									<div class="media-body text-white">
										<p class="mb-1">مجموع محصل</p>
										<h3 class="text-white"><?php
										
										$q2="SELECT count(s_id) AS total FROM student";
										$r=$con->query($q2);
										while($row=$r->fetch_array(MYSQLI_ASSOC))
										{
							
											echo $row["total"];
										}
										
										?></h3>	
									</div>
									<div class="media-body text-white">
										<p class="mb-1">مجموع صنوف</p>
										<h3 class="text-white"><?php
										
										$q2="SELECT count(c_id) AS total FROM course_type";
										$r=$con->query($q2);
										while($row=$r->fetch_array(MYSQLI_ASSOC))
										{
							
											echo $row["total"];
										}
										
										?></h3>	
									</div>
								</div>
							</div>
						</div>
                    </div>
				
					
				
				
				<div class="col-xl-3 col-xxl-6 col-lg-6 col-sm-6">
						<div class="widget-stat card bg-danger ">
							<div class="card-body p-4">
								<div class="media">
									<span class="me-3">
										<i class="la la-dollar"></i>
									</span>
									<div class="media-body text-white">
										<p class="mb-1">مجموعه فیس</p>
										<h3 class="text-white"><?php
										
										$q2="SELECT sum(received_amount) AS total FROM loan";
										$r=$con->query($q2);
										while($row=$r->fetch_array(MYSQLI_ASSOC))
										{
							
											echo $row["total"];
										}
										
										?></h3>
										
									</div>
										<div class="media-body text-white">
										<p class="mb-1">مجموعه قرض</p>
										<h3 class="text-white"><?php
										
										$q2="SELECT sum(borrow_amount) AS total FROM loan";
										$r=$con->query($q2);
										while($row=$r->fetch_array(MYSQLI_ASSOC))
										{
							
											echo $row["total"];
										}
										
										?></h3>
										
									</div>
								</div>
							</div>
						</div>
                    </div>


<?php if (isset($_SESSION['emp_type']) && $_SESSION['emp_type'] == 'admin'): ?>
	<div class="col-xl-3 col-xxl-6 col-lg-6 col-sm-6">
		<div class="widget-stat card bg-danger ">
			<div class="card-body p-4">
				<div class="media">
					<span class="me-3">
						<i class="la la-dollar"></i>
					</span>
					<div class="media-body text-white">
						<p class="mb-1">عاید خالص</p>
						<h3 class="text-white">
							<?php
							$net_profit = "SELECT (SELECT SUM(received_amount) FROM loan) - (SELECT SUM(ex_amount) FROM expenses) AS net_prof";
							$net_revenue = $con->query($net_profit);
							while($row = $net_revenue->fetch_array(MYSQLI_ASSOC)) {
								echo $row["net_prof"];
							}
							?>
						</h3>
					</div>
					<div class="media-body text-white">
						<p class="mb-1">جمله مصارف</p>
						<h3 class="text-white">
							<?php
							$q2 = "SELECT SUM(ex_amount) AS total FROM expenses";
							$r = $con->query($q2);
							while($row = $r->fetch_array(MYSQLI_ASSOC)) {
								echo $row["total"];
							}
							?>
						</h3>
					</div>
				</div>
			</div>
		</div>
	</div>
<?php endif; ?>

			
				
				
				
				

									</div>
								</div>
							</div>
							
				
						
						</div>
					</div>
				</div>
            </div>
        </div>
        <!--**********************************
            Content body end
        ***********************************-->
		
		
		
        <!--**********************************
            Footer start
        ***********************************-->
        <div class="footer">
		   <div class="copyright">
                <p>Copyright © Designed &amp; Developed by <a href="https://dynamic-cryptic.com/" target="_blank">Dynamic & Cryptic</a> 2025</p>
            </div>
          
        </div>
        <!--**********************************
            Footer end
        ***********************************-->

		


	</div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <!--**********************************
        Scripts
    ***********************************-->
    <!-- Required vendors -->
    <script src="vendor/global/global.min.js"></script>
	<script src="vendor/chart.js/Chart.bundle.min.js"></script>
	<script src="vendor/jquery-nice-select/js/jquery.nice-select.min.js"></script>
	
	<!-- Apex Chart -->
	<script src="vendor/apexchart/apexchart.js"></script>
	<script src="vendor/nouislider/nouislider.min.js"></script>
	<script src="vendor/wnumb/wNumb.js"></script>
	
	<!-- Dashboard 1 -->
	<script src="js/dashboard/dashboard-1.js"></script>

    <script src="js/custom.min.js"></script>
	<script src="js/dlabnav-init.js"></script>
	<script src="js/demo.js"></script>
    <script src="js/styleSwitcher.js"></script>
	
</body>
</html>