PluginProbe
School Management System – WPSchoolPress / 2.2.43
School Management System – WPSchoolPress v2.2.43
2.2.48 2.2.47 2.2.46 2.2.45 2.2.44 2.2.43 2.2.42 2.2.41 2.2.40 2.2.39 2.2.38 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 All 103 releases
wpschoolpress / pages / wpsp-attendance.php

wpsp-attendance.php in School Management System – WPSchoolPress 2.2.43, at pages/wpsp-attendance.php

422 lines 18.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined( 'ABSPATH' ) )exit('No Such File');
3 wpsp_header();
4 if( is_user_logged_in() ) {
5 global $current_user, $wpdb;
6 $current_user_role=$current_user->roles[0];
7 if($current_user_role=='administrator' || $current_user_role=='teacher'){
8 wpsp_topbar();
9 wpsp_sidebar();
10 wpsp_body_start();
11 ?>
12 <div class="wpsp-card">
13 <div class="wpsp-card-head">
14 <h3 class="wpsp-card-title"><?php echo esc_html(apply_filters( 'wpsp_student_attendance_heading_detail', 'Attendance Report' ),'wpschoolpress'); ?></h3>
15 <hr>
16 </div>
17 <div class="wpsp-card-body text-black">
18 <div class="wpsp-row">
19 <?php $item = esc_html(apply_filters( 'wpsp_student_attendance_title_item',"Attendance"),"wpschoolpress"); ?>
20 <div class="wpsp-col-lg-4 wpsp-col-md-4 wpsp-col-sm-12 wpsp-col-xs-12" id="AttendanceEnterForm">
21 <h3 class="wpsp-card-title"><?php esc_html_e( 'Attendance', 'wpschoolpress' ); ?></h3>
22 <div class="line_box">
23 <div class="wpsp-form-group">
24 <label for="Class">
25 <?php if( isset($item['classid'])){
26 esc_html($item['classid'],"wpschoolpress");
27 }else{
28 esc_html_e("Select Class","wpschoolpress");
29 }
30 ?>
31 </label>
32 <select name="classid" id="AttendanceClass" class="wpsp-form-control">
33 <option value=""><?php echo esc_html("Select Class", "wpschoolpress");?></option>
34 <?php
35 if(isset($_POST['classid']) && intval($_POST['classid'])!='')
36 $selid=intval($_POST['classid']);
37 else
38 if($current_user_role=='teacher'){
39 $current_user_id = esc_sql(get_current_user_id());
40 $selid=0;
41 $ctname=$wpdb->prefix.'wpsp_class';
42 // $clt=$wpdb->get_results("select `cid`,`c_name` from `$ctname` where teacher_id = '$current_user_id' ");
43 $clt = $wpdb->get_results($wpdb->prepare("SELECT `cid`,`c_name` FROM $ctname WHERE teacher_id = %d",$current_user_id));
44 foreach($clt as $cnm){?>
45 <option value="<?php echo esc_attr($cnm->cid);?>" <?php if($cnm->cid==$selid) echo esc_html("selected","wpschoolpress");?>><?php echo esc_html($cnm->c_name);?></option>
46 <?php }
47 } else {
48 $selid=0;
49 $ctname=$wpdb->prefix.'wpsp_class';
50 $clt=$wpdb->get_results("select `cid`,`c_name` from `$ctname`");
51 foreach($clt as $cnm){?>
52 <option value="<?php echo esc_attr($cnm->cid);?>" <?php if($cnm->cid==$selid) echo esc_html("selected","wpschoolpress");?>><?php echo esc_html($cnm->c_name);?></option>
53 <?php }
54 } ?>
55 </select>
56 <span class="clserror wpsp-text-red"><?php echo esc_html( 'Please select Class', 'wpschoolpress' ); ?></span>
57 </div>
58 <div class="wpsp-form-group">
59 <label for="date">
60 <?php if( isset($item['entry_date'])){
61 esc_html($item['entry_date'],"wpschoolpress");
62 }else{
63 esc_html_e('Date',"wpschoolpress");
64 }
65 ?>
66 </label>
67 <input type="text" class="wpsp-form-control select_date" id="AttendanceDate" value="<?php if(isset($_POST['entry_date'])) { echo esc_attr($_POST['entry_date']); } else { echo esc_attr(date('m/d/Y')); }?>" name="entry_date">
68 <span class="clsdate"><?php echo esc_html( 'Please select Date', 'wpschoolpress' ); ?></span>
69 </div>
70 <div class="wpsp-row wpsp-text-center">
71 <div class="wpsp-col-sm-12">
72 <div class="wpsp-form-group">
73 <button id="AttendanceEnter" name="attendance" class="wpsp-btn wpsp-btn-success"><?php echo esc_html( 'Add/Update', 'wpschoolpress' ); ?></button>
74 <button id="Attendanceview" name="attendanceview" class="wpsp-btn wpsp-btn-primary"><?php echo esc_html( 'View', 'wpschoolpress' ); ?></button>
75 </div>
76 </div>
77 </div>
78 <div class="wpsp-row">
79 <div class="wpsp-col-lg-12 wpsp-col-md-12 wpsp-col-sm-12 wpsp-form-group wpsp-text-red" id="wpsp-error-msg" style="margin-top:0px;">
80 </div>
81 </div>
82 </div>
83 </div>
84 <div class="wpsp-col-lg-6 wpsp-col-lg-offset-1 wpsp-col-md-5 wpsp-col-md-offset-1 wpsp-col-sm-12 wpsp-col-xs-12 AttendanceView">
85 <?php
86 $class_names = $c_stcount = $attendance = array();
87 $class_table = $wpdb->prefix."wpsp_class";
88 $student_table = $wpdb->prefix."wpsp_student";
89 $attendance_table = $wpdb->prefix."wpsp_attendance";
90 $class_info = $wpdb->get_results("select cid,c_name from $class_table");
91 $stl = array();
92 foreach($class_info as $cls){
93 $class_names[$cls->cid]=$cls->c_name;
94 $studentlists = $wpdb->get_results("select class_id, sid from $student_table");
95 foreach ($studentlists as $stu) {
96 if(is_numeric($stu->class_id) ){
97 if($stu->class_id == $cls->cid){
98 $stl[$cls->cid][$stu->sid] = $stu->sid;
99 }
100 }else{
101 $class_id_array = unserialize( $stu->class_id );
102 if(!empty($class_id_array)){
103 if(in_array($cls->cid, $class_id_array)){
104 $stl[$cls->cid][$stu->sid] = $stu->sid;
105 }
106 }
107 }
108 }
109 }
110 $newArr = array();
111 $newArr1 = array();
112 foreach ($stl as $key => $value) {
113 $newArr[] = count($value);
114 $newArr1[$key] = count($value);
115 }
116 $classwise_count = $wpdb->get_results("select class_id, count(*) as count from $student_table GROUP BY class_id",ARRAY_A);
117 foreach($classwise_count as $clwc){
118 $c_stcount[$clwc['class_id']] = $clwc['count'];
119 }
120 $date_today = date('Y-m-d');
121 // $attendance_info = $wpdb->get_results("select class_id, absents from $attendance_table where date='$date_today'");
122 $attendance_info = $wpdb->get_results($wpdb->prepare("SELECT class_id, absents FROM $attendance_table WHERE date = %s",$date_today));
123
124 foreach($attendance_info as $attend){
125 foreach($newArr1 as $key => $value){
126 if($key == $attend->class_id){
127 $absents = json_decode($attend->absents);
128 if(empty($absents)){}else {
129 $present = $value-count($absents);
130 }
131 $percent = round(($present*100)/$value);
132 $attendance[$attend->class_id] = array('present'=>$present,'percentage'=>$percent);
133 }
134 }
135 }
136 ?>
137 <div class="wpsp-col-sm-12">
138 <h3 class="wpsp-card-title"><?php esc_html_e( 'View Attendance Report', 'wpschoolpress' ); ?></h3>
139 <div class="line_box">
140 <div class="box-body">
141 <?php
142 $i=0;
143 foreach($class_names as $clid=>$cln){
144 $css_class='';
145 if(isset($attendance[$clid])){
146 if($attendance[$clid]['percentage']==100)
147 $css_class="wpsp-progress-bar-success";
148 else if($attendance[$clid]['percentage']<100 && $attendance[$clid]['percentage']>70)
149 $css_class="wpsp-progress-bar-warning";
150 else if($attendance[$clid]['percentage']<=70)
151 $css_class="wpsp-progress-bar-danger";
152 else
153 $css_class="wpsp-progress-bar-info";
154 }
155 ?>
156 <div class="wpsp-progress-group">
157 <span class="wpsp-progress-text"><?php echo esc_html($cln);?></span>
158 <span class="wpsp-progress-number"><?php if(isset($attendance[$clid])){ echo esc_html($attendance[$clid]['present']); }?>/<?php echo (isset($newArr[$i]))? esc_html($newArr[$i]):'0';?></span>
159 <div class="wpsp-progress sm">
160 <div class="wpsp-progress-bar <?php echo esc_attr($css_class);?>" style="width: <?php echo (isset($attendance[$clid])) ? esc_attr($attendance[$clid]['percentage']):'0'; ?>%">
161 </div>
162 </div>
163 </div>
164 <?php
165 $i++;
166 } ?>
167 </div>
168 </div>
169 </div>
170 </div>
171 </div>
172 <div class="modal modal-wide" id="AddModal" tabindex="-1" role="dialog" aria-labelledby="AddModal" aria-hidden="true">
173 <div class="modal-dialog">
174 <div class="modal-content" id="AddModalContent">
175 </div>
176 </div>
177 </div>
178 <?php do_action('wpshoolpress_after_attendance') ?>
179 </div>
180 </div>
181 <?php do_action('wpshoolpress_after_attendance');
182 wpsp_body_end();
183 wpsp_footer();
184 }else if($current_user_role=='parent'){
185 wpsp_topbar();
186 wpsp_sidebar();
187 wpsp_body_start();
188 $parent_id=intval($current_user->ID);
189 $student_table=$wpdb->prefix."wpsp_student";
190 $class_table=$wpdb->prefix."wpsp_class";
191 $att_table=$wpdb->prefix."wpsp_attendance";
192 // $students=$wpdb->get_results("select wp_usr_id, class_id, s_fname, s_mname, s_lname, sid from $student_table where parent_wp_usr_id='".esc_sql($parent_id)."'");
193
194 $students = $wpdb->get_results($wpdb->prepare("SELECT wp_usr_id, class_id, s_fname, s_mname, s_lname, sid FROM $student_table WHERE parent_wp_usr_id = %d",$parent_id));
195
196
197 $child=array();
198 foreach($students as $childinfo){
199 $child[]=array('student_id'=>$childinfo->wp_usr_id,'s_fname'=>$childinfo->s_fname,'class_id'=>$childinfo->class_id, 's_mname'=>$childinfo->s_mname, 's_lname'=>$childinfo->s_lname, 'sid'=>$childinfo->sid);
200 }
201 ?>
202 <div class="wpsp-card">
203 <div class="wpsp-card-body">
204 <div class="tabSec wpsp-nav-tabs-custom" id="verticalTab">
205 <div class="tabList">
206 <ul class="wpsp-resp-tabs-list">
207 <?php $i=0; foreach($child as $ch) {
208 if(base64_decode(sanitize_text_field($_GET['sid'])) == $ch['sid']){ ?>
209 <li class="wpsp-tabing <?php echo ($i==0)?'wpsp-resp-tab-active':''?>">
210 <?php echo esc_html($ch['s_fname'].' '.$ch['s_mname'].' '. $ch['s_lname']);?>
211 </li>
212 <?php }$i++;
213 } ?>
214 </ul>
215 </div>
216 <section class="content">
217 <?php
218 global $wpdb;
219 $id = sanitize_text_field($_GET['cid']);
220 $class_id = sanitize_text_field(base64_decode($id));
221 $stu_id = base64_decode(sanitize_text_field($_GET['sid']));
222 $st_id = esc_sql($stu_id);
223 $stl =[];
224 $att_table = $wpdb->prefix . "wpsp_attendance";
225 $st_table = $wpdb->prefix . "wpsp_student";
226 $class_table = $wpdb->prefix . "wpsp_class";
227 $st_wp_id = $wpdb->get_row($wpdb->prepare("select wp_usr_id from $st_table where sid = '%d'",$st_id));
228 $wp_usr_id = $st_wp_id->wp_usr_id;
229 $ser = '%' . $wp_usr_id . '%';
230 // $stinfo = $wpdb->get_row("select st.class_id, st.s_rollno, st.wp_usr_id, CONCAT_WS(' ', st.s_fname, st.s_mname, st.s_lname )
231 // AS full_name, c.c_name, c.c_sdate, c.c_edate from $st_table st LEFT JOIN $class_table c ON c.cid='".esc_sql($class_id)."' where st.sid='".esc_sql($st_id)."'");
232
233 $stinfo = $wpdb->get_row($wpdb->prepare("SELECT st.class_id, st.s_rollno, st.wp_usr_id, CONCAT_WS(' ', st.s_fname, st.s_mname, st.s_lname ) AS full_name, c.c_name, c.c_sdate, c.c_edate
234 FROM $st_table st LEFT JOIN $class_table c ON c.cid = %d WHERE st.sid = %d",$class_id,$st_id));
235
236 if(is_numeric($stinfo->class_id) ){
237 if($stinfo->class_id == $class_id){
238 $stl[] = $st->sid;
239 }
240 }else{
241 $class_id_array = unserialize($stinfo->class_id);
242 if(in_array($class_id, $class_id_array)){
243 $stl[] = $class_id;
244 }
245 }
246 // $att_info = $wpdb->get_row("select count(*) as count from $att_table WHERE absents LIKE ".esc_sql($ser)." AND class_id='$class_id'");
247 $att_info = $wpdb->get_row($wpdb->prepare("SELECT count(*) as count FROM $att_table WHERE absents LIKE %s and class_id=%d",$ser,$class_id));
248
249 $stinfo->c_edate = wpsp_ViewDate($stinfo->c_edate);
250 $stinfo->c_sdate = wpsp_ViewDate($stinfo->c_sdate);
251 $loc_avatar = get_user_meta($stinfo->wp_usr_id, 'simple_local_avatar', true);
252 $img_url = $loc_avatar ? $loc_avatar['full'] : WPSP_PLUGIN_URL . 'img/avatar.png';
253 $attendance_days = $wpdb->get_results(
254 $wpdb->prepare("SELECT * FROM $att_table WHERE class_id = %d", $class_id)
255 );
256 $present_days = 0;
257 $classid_array = unserialize($stinfo->class_id);
258 $classname_array = [];
259 foreach ($classid_array as $id ) {
260 // $clasname = $wpdb->get_var("SELECT c_name FROM $class_table where cid='".esc_sql($class_id)."'");
261 $clasname = $wpdb->get_var($wpdb->prepare("SELECT c_name FROM $class_table WHERE cid = %d", $class_id));
262 $classname_array[] = $clasname;
263 }
264 foreach($attendance_days as $days => $attendance){
265 if ($attendance->absents == 'Nil'){
266 $present_days++;
267 }else{
268 $absents = json_decode($attendance->absents, true);
269 if (array_search($stinfo->wp_usr_id, array_column($absents, 'sid')) !== False){
270 }else{
271 $present_days++;
272 }
273 }
274 }
275 $working_days = $present_days + $att_info->count;
276 $content = "<div class='wpsp-panel-body'>
277 <div class='wpsp-userpic'style='margin-top: 0;'>
278 <img src=".esc_url($img_url)." height='150px' width='150px' class='img img-circle'/>
279 </div>
280 <div class='wpsp-userDetails'>
281 <table class='wpsp-table'>
282 <tbody>
283 <tr>
284 <td colspan='2'><strong>Name: </strong>".esc_html($stinfo->full_name)."</td>
285 </tr>
286 <tr>
287 <td><strong>Class: </strong>".esc_html($stinfo->c_name)."</td>
288 <td><strong>Roll No. : </strong>".esc_html($stinfo->s_rollno)."</td>
289 </tr>
290 <tr>
291 <td><strong>Class Start: </strong> ".esc_html($stinfo->c_sdate)." </td>
292 <td><strong>Class End : </strong>".esc_html($stinfo->c_edate)."</td>
293 </tr>
294 <tr>
295 <td><strong>Number of Absent days: </strong>".esc_html($att_info->count)."</td>
296 <td><strong>Number of Present days: </strong>".esc_html($present_days)."</td>
297 </tr>
298 <tr>
299 <td colspan='2'><strong>Number of Attendance days: </strong>".esc_html($working_days)."</td>
300 </tr>
301 </tbody>
302 </table>
303 </div>
304 </div>";
305 $allowed_tags = wp_kses_allowed_html('post');
306 echo wp_kses(stripslashes_deep($content), $allowed_tags);
307 ?>
308 </section>
309 </div>
310 </div>
311 </div>
312 <?php
313 wpsp_body_end();
314 wpsp_footer();
315 }else if($current_user_role=='student'){
316 wpsp_topbar();
317 wpsp_sidebar();
318 wpsp_body_start();
319 $st_id=esc_sql($current_user->ID);
320 ?>
321 <div class="wpsp-card">
322 <div class="wpsp-card-body">
323 <section class="content">
324 <?php
325 global $wpdb;
326 $id = sanitize_text_field(stripslashes($_GET['cid']));
327 $class_id = esc_sql(base64_decode($id));
328 $stl =array();
329 $att_table = $wpdb->prefix . "wpsp_attendance";
330 $st_table = $wpdb->prefix . "wpsp_student";
331 $class_table = $wpdb->prefix . "wpsp_class";
332 $ser = '%' . $st_id . '%';
333 //$stinfo = $wpdb->get_row("select st.class_id, st.s_rollno , CONCAT_WS(' ', st.s_fname, st.s_mname, st.s_lname ) AS full_name, c.c_name, c.c_sdate, c.c_edate from $st_table
334 // st LEFT JOIN $class_table c ON c.cid='".esc_sql($class_id)."' where st.wp_usr_id='".esc_sql($st_id)."'");
335
336 $stinfo = $wpdb->get_row($wpdb->prepare("SELECT st.class_id, st.s_rollno, CONCAT_WS(' ', st.s_fname, st.s_mname, st.s_lname ) AS full_name, c.c_name, c.c_sdate, c.c_edate
337 FROM $st_table st LEFT JOIN $class_table c ON c.cid = %d WHERE st.wp_usr_id = %d",$class_id,$st_id));
338
339
340 if(is_numeric($stinfo->class_id) ){
341 if($stinfo->class_id == $class_id){
342 $stl[] = $st->sid;
343 }
344 }else{
345 $class_id_array = unserialize($stinfo->class_id);
346 if(in_array($class_id, $class_id_array)){
347 $stl[] = $class_id;
348 }
349 }
350 //$att_info = $wpdb->get_row("select count(*) as count from $att_table WHERE absents LIKE '$ser' AND class_id='$class_id'");
351 $att_info = $wpdb->get_row($wpdb->prepare("SELECT count(*) as count FROM $att_table WHERE absents LIKE %s and class_id=%d",$ser,$class_id));
352 $stinfo->c_edate = wpsp_ViewDate($stinfo->c_edate);
353 $stinfo->c_sdate = wpsp_ViewDate($stinfo->c_sdate);
354 $loc_avatar = get_user_meta($st_id, 'simple_local_avatar', true);
355 $img_url = $loc_avatar ? $loc_avatar['full'] : WPSP_PLUGIN_URL . 'img/avatar.png';
356 $attendance_days = $wpdb->get_results(
357 $wpdb->prepare("SELECT * FROM $att_table WHERE class_id = %d", $class_id)
358 );
359 $present_days = 0;
360 $classid_array = unserialize($stinfo->class_id);
361 $classname_array = array();
362 foreach ($classid_array as $id ) {
363 $clasname = $wpdb->get_var(
364 $wpdb->prepare("SELECT c_name FROM $class_table WHERE cid = %d", $class_id)
365 );
366 $classname_array[] = $clasname;
367 }
368 foreach($attendance_days as $days => $attendance){
369 if ($attendance->absents == 'Nil'){
370 $present_days++;
371 }else{
372 $absents = json_decode($attendance->absents, true);
373 if (array_search($st_id, array_column($absents, 'sid')) !== False){
374 }else{
375 $present_days++;
376 }
377 }
378 }
379 $working_days = $present_days + $att_info->count;
380 $content = "<div class='wpsp-panel-body'>
381 <div class='wpsp-userpic'style='margin-top: 0;'>
382 <img src=".esc_url($img_url)." height='150px' width='150px' class='img img-circle'/>
383 </div>
384 <div class='wpsp-userDetails'>
385 <table class='wpsp-table'>
386 <tbody>
387 <tr>
388 <td colspan='2'><strong>Name: </strong>".esc_html($stinfo->full_name)."</td>
389 </tr>
390 <tr>
391 <td><strong>Class: </strong>".esc_html($stinfo->c_name)."</td>
392 <td><strong>Roll No. : </strong>".esc_html($stinfo->s_rollno)."</td>
393 </tr>
394 <tr>
395 <td><strong>Class Start: </strong> ".esc_html($stinfo->c_sdate)." </td>
396 <td><strong>Class End : </strong>".esc_html($stinfo->c_edate)."</td>
397 </tr>
398 <tr>
399 <td><strong>Number of Absent days: </strong>".esc_html($att_info->count)."</td>
400 <td><strong>Number of Present days: </strong>".esc_html($present_days)."</td>
401 </tr>
402 <tr>
403 <td colspan='2'><strong>Number of Attendance days: </strong>".esc_html($working_days)."</td>
404 </tr>
405 </tbody>
406 </table>
407 </div>
408 </div>";
409 $allowed_tags = wp_kses_allowed_html('post');
410 echo wp_kses(stripslashes_deep($content), $allowed_tags);
411 ?>
412 </section>
413 </div>
414 </div>
415 <?php
416 wpsp_body_end();
417 wpsp_footer();
418 }
419 }else{
420 include_once( WPSP_PLUGIN_PATH .'/includes/wpsp-login.php');
421 }
422 ?>