<?php 

function eedu_portal_dashboard_cb() {
	$post = new post;
	$user_meta = $_GET;
	$term = get_option("current_academic_term");
	$current_session = get_option("current_academic_session");
	$time = time();
	do_action("msg_announcement", $user_meta);
	?>
	<link rel="stylesheet" type="text/css" href="contents/plugins/eedu_portal/css/dashboard.css">
	<div class="row mb-5">
		<div class="col-md-6 col-lg-4">
			<div class="profile-nav mb-4">
				<div class="card-container">
					<span class="pro">PRO</span>
					<img class="round" src="<?php echo get_user_image($user_meta['id']); ?>" alt="user" />
					<h3><?php echo get_fullname($user_meta); ?></h3>
					<h6><?php echo get_role_name($user_meta['role']); ?></h6>
					<p>STUDENT/STAFF ID: <?php echo strtoupper($user_meta['username']) ?></p>
					<div class="buttons">
						<a href="notifications" class="btn primary">
							Messages
						</a>
						<a href="<?php echo ($user_meta['role'] == 'student') ? 'student-profile' : 'profile'; ?>" class="btn primary ghost">
							Profile
						</a>
					</div>
					<div class="skills">
						<h6>Meta</h6>
						<ul>
							<?php if (isset($user_meta['class'])): ?>
								<li><?php echo get_class_name($user_meta['class'], $user_meta['category']) ?></li>
								<li><?php echo get_fullname(get_form_teacher($user_meta['class'], $user_meta['category'])) ?> <small>(<?php echo get_option('pref_name_for_form_teacher') ?>)</small></li>
							<?php endif ?>
							<li><?php echo get_term_name($term) ?></li>
							<li><?php echo get_session_name($current_session) ?> Session</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<div class="col-md-6 col-lg-8">
			<link rel='stylesheet' href='https://fonts.googleapis.com/icon?family=Material+Icons'>
			<div class="dashboard-buttons mb-4">
			    <div class="row portfolio">
			    <?php if (current_user_can("gradebook")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="gradebook">
				        <img src="contents/plugins/eedu_portal/images/noun_Grading Homework_23471.png">
				        <h3>GradeBook</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("broadsheet")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="broadsheet">
				        <img src="contents/plugins/eedu_portal/images/noun_Newspaper_80055.png">
				        <h3>BroadSheet</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("mock_exam_gradebook")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="mock-exam-gradebook">
				        <img src="contents/plugins/eedu_portal/images/noun_Grading Homework_23471mock.png">
				        <h3>Mock Exam GradeBook</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("mock_exam_broadsheet")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="mock-exam-broadsheet">
				        <img src="contents/plugins/eedu_portal/images/noun_Reading_19820.png">
				        <h3>Mock Exam BroadSheet</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("master_sheet")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="master-sheet">
				        <img src="contents/plugins/eedu_portal/images/annual-broadsheet.png">
				        <h3>Annual BroadSheet</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("print_results")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="print-results">
				        <img src="contents/plugins/eedu_portal/images/noun_financial data_319017.png">
				        <h3>Print Results</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("cp_classwork_stream")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="cp-classwork-stream">
				        <img src="contents/plugins/eedu_portal/images/noun_Stream_2146848.png">
				        <h3>Classwork Streams</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("see_curriculum")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="lesson-notes">
				        <img src="contents/plugins/eedu_portal/images/noun_e-learning_985266.png">
				        <h3>Lesson Notes</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("cp_all_available_quiz")): 
			    	$subjects = get_class_courses($user_meta['class'] ?? NULL, $user_meta['category'] ?? NULL, false, false);
    				$subjects = array_keys($subjects);
			    	$quiz = $post->get_post_by_meta_data(['type' => 'cp_quiz', 'class' => $user_meta['class'] ?? NULL, 'course' => $subjects, 'term' => $term, 'from' => $time, 'to' => $time, 'status' => 'published'], ['from' => "<", 'to' => ">="], false, 0, 0, 'post_id', 'DESC');
			    	$count = $quiz ? _count($quiz) : 0;
			    	?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="cp-all-available-quiz">
				        <span class="dashboard-badge bg-red"><?php echo $count; ?></span>
				        <img src="contents/plugins/eedu_portal/images/noun_online quiz_3006362.png">
				        <h3>Quiz & Test</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("academic_session")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="academic-session?id=<?php echo $current_session; ?>">
				        <img src="contents/plugins/eedu_portal/images/noun_online session_3485331.png">
				        <h3>Term Info</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("attendance_report")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="attendance-report">
				        <img src="contents/plugins/eedu_portal/images/noun_report_149914.png">
				        <h3>Attendance Report</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("mark_attendance")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="mark-attendance">
				        <img src="contents/plugins/eedu_portal/images/noun_Mark_1745727.png">
				        <h3>Mark Attendance</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("users")): 
			    	$session = Session::getInstance();
			    	if(!isset($session->students)) {
			    		$user = new user;
			    		$students = $user->get_user_by_meta_data(['role' => 'student', 'status' => 'active'], "LIKE", false, 0, 0, 'user_id', 'ASC', "user_id");
			    		$session->students = _count($students);
			    	}
			    	
			    	?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="users">
				        <span class="dashboard-badge bg-green"><?php echo $session->students ?></span>
				        <img src="contents/plugins/eedu_portal/images/noun_users_216107.png">
				        <h3>People & Users</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("add_student")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="add-student">
				        <img src="contents/plugins/eedu_portal/images/noun_add student_2960708.png">
				        <h3>Add Student</h3>
			        </a>
			      </div>

			    <?php endif ?>

			    <?php if (current_user_can("my_invoices") && current_user_can("student_only")): ?>
			    
			      <div class="grid">
			        <a class="grid-content text-center" href="my-invoices">
				        <img src="contents/plugins/eedu_portal/images/noun_invoice_180791.png">
				        <h3>My Invoices</h3>
			        </a>
			      </div>

			    <?php endif ?>
			   		
			    </div>
			</div>
		</div>
	</div>
	<?php
}