| 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 |
$current_user_Id = intval($current_user->ID); |
| 8 |
$subject_table = $wpdb->prefix."wpsp_subject"; |
| 9 |
if($current_user_role=='administrator' || $current_user_role=='teacher'){ |
| 10 |
wpsp_topbar(); |
| 11 |
wpsp_sidebar(); |
| 12 |
wpsp_body_start(); |
| 13 |
$filename = ''; |
| 14 |
$header ='Exams'; |
| 15 |
if( isset($_GET['tab'] ) && sanitize_text_field($_GET['tab']) == 'addexam' ) { |
| 16 |
if($current_user_role=='administrator'){ |
| 17 |
$header = $label = __( 'Add New Exam', 'wpschoolpress'); |
| 18 |
$filename = WPSP_PLUGIN_PATH .'includes/wpsp-examForm.php'; |
| 19 |
} |
| 20 |
}else if(( isset($_GET['id']) && intval($_GET['id']))) { |
| 21 |
if($current_user_role=='administrator'){ |
| 22 |
$header = $label = __( 'Update Exam', 'wpschoolpress'); |
| 23 |
$filename = WPSP_PLUGIN_PATH .'includes/wpsp-examForm.php'; |
| 24 |
} |
| 25 |
} |
| 26 |
$extable = $wpdb->prefix."wpsp_exam"; |
| 27 |
$ctable = $wpdb->prefix."wpsp_class"; |
| 28 |
$wpsp_exams = $wpdb->get_results( "select * from $extable"); |
| 29 |
$class_ID = 0; |
| 30 |
if( $current_user_role=='teacher' ) { |
| 31 |
$cuserId = intval($current_user->ID); |
| 32 |
/*$class_ID = $wpdb->get_results("SELECT DISTINCT c.cid,c.c_name,s.id FROM wp_wpsp_class c |
| 33 |
INNER JOIN wp_wpsp_subject s ON s.class_id= c.cid |
| 34 |
WHERE s.sub_teach_id ='".esc_sql($cuserId)."' || c.teacher_id = '".esc_sql($cuserId)."'"); */ |
| 35 |
$class_ID = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT c.cid,c.c_name,s.id FROM $ctable c |
| 36 |
INNER JOIN $subject_table s ON s.class_id= c.cid WHERE s.sub_teach_id = %d || c.teacher_id = %d",$cuserId,$cuserId)); |
| 37 |
$j=0; |
| 38 |
foreach( $class_ID as $class_IDa ) { |
| 39 |
$clsid[] = esc_sql($class_IDa->cid); |
| 40 |
$subid[] = esc_sql($class_IDa->id); |
| 41 |
} |
| 42 |
$msg = 'Please Ask Principal To Assign Class'; |
| 43 |
if( !empty( intval($class_ID )) ) { |
| 44 |
$clsid = array_map('intval', $clsid); // ensure all class IDs are integers |
| 45 |
$subid = array_map('intval', $subid); // ensure all subject IDs are integers |
| 46 |
$cls_placeholders = implode(',', array_fill(0, count($clsid), '%d')); |
| 47 |
$sub_placeholders = implode(',', array_fill(0, count($subid), '%d')); |
| 48 |
$query = $wpdb->prepare("SELECT * FROM $extable WHERE classid IN ($cls_placeholders) AND subject_id IN ($sub_placeholders)",...$clsid,...$subid); |
| 49 |
$wpsp_exams = $wpdb->get_results($query); |
| 50 |
// $wpsp_exams = $wpdb->get_results( "select * from $extable where classid IN (".implode(',',$clsid).") and subject_id IN (".implode(',',$subid).")"); |
| 51 |
} |
| 52 |
} |
| 53 |
if( !empty( $filename) ) { |
| 54 |
include_once ( $filename ); |
| 55 |
} else {?> |
| 56 |
<div class="wpsp-card"> |
| 57 |
<div class="wpsp-card-body"> |
| 58 |
<div class="subject-head"> |
| 59 |
<?php if( $current_user_role=='teacher' && empty( $class_ID ) ) { |
| 60 |
echo '<div class="alert alert-danger col-lg-2">'.esc_html($msg).'</div>'; |
| 61 |
} ?> |
| 62 |
</div> |
| 63 |
<table id="exam_class_table" class="wpsp-table" cellspacing="0" width="100%" style="width:100%"> |
| 64 |
<thead> |
| 65 |
<tr> |
| 66 |
<th class="nosort">#</th> |
| 67 |
<th><?php esc_html_e( 'Exam Name', 'wpschoolpress' );?></th> |
| 68 |
<th><?php esc_html_e( 'Class Name', 'wpschoolpress' );?></th> |
| 69 |
<th><?php esc_html_e( 'Subject Name', 'wpschoolpress' );?></th> |
| 70 |
<th><?php esc_html_e( 'Start Date', 'wpschoolpress' );?></th> |
| 71 |
<th><?php esc_html_e( 'End Date', 'wpschoolpress' );?></th> |
| 72 |
<?php if($current_user_role=='administrator'){?> |
| 73 |
<th class="nosort"><?php esc_html_e( 'Action', 'wpschoolpress' );?></th> |
| 74 |
<?php }?> |
| 75 |
</tr> |
| 76 |
</thead> |
| 77 |
<tbody> |
| 78 |
<?php |
| 79 |
$sno=1; |
| 80 |
foreach( $wpsp_exams as $wpsp_exam ) { |
| 81 |
$classname = $sublist = ''; |
| 82 |
$classid = isset($wpsp_exam->classid) ? intval($wpsp_exam->classid) : ''; |
| 83 |
if( !empty( intval($classid )) ) { |
| 84 |
$classname = $wpdb->get_var($wpdb->prepare("SELECT `c_name` FROM $ctable WHERE cid = %d",$classid)); |
| 85 |
} |
| 86 |
$sublist = '-'; |
| 87 |
if( !empty($wpsp_exam->subject_id) ) { |
| 88 |
$subject_list = array(); |
| 89 |
$slist = str_replace( 'All,', '',$wpsp_exam->subject_id); |
| 90 |
if( !empty( $slist ) ) { |
| 91 |
$subject_ids = explode(',', $slist); // "1,2,3" -> [1,2,3] |
| 92 |
$subject_ids = array_map('intval', $subject_ids); |
| 93 |
$placeholders = implode(',', array_fill(0, count($subject_ids), '%d')); |
| 94 |
$query = $wpdb->prepare("SELECT sub_name FROM $subject_table WHERE id IN ($placeholders)",...$subject_ids); |
| 95 |
$subjectlist = $wpdb->get_results($query, ARRAY_A); |
| 96 |
// $subjectlist = $wpdb->get_results("SELECT sub_name FROM $subject_table WHERE id IN($slist) ", ARRAY_A ); |
| 97 |
foreach( $subjectlist as $list ) { |
| 98 |
$subject_list[] = $list['sub_name']; |
| 99 |
} |
| 100 |
$sublist = implode(", ",$subject_list); |
| 101 |
} |
| 102 |
} |
| 103 |
?> |
| 104 |
<tr id="<?php echo esc_attr($wpsp_exam->eid);?>"> |
| 105 |
<td><?php echo esc_html($sno); ?> |
| 106 |
<td><?php echo esc_html($wpsp_exam->e_name);?></td> |
| 107 |
<td><?php echo esc_html($classname); ?></td> |
| 108 |
<td><?php echo esc_html($sublist); ?></td> |
| 109 |
<td><?php echo esc_html(wpsp_ViewDate($wpsp_exam->e_s_date),'wpschoolpress'); ?></td> |
| 110 |
<td><?php echo esc_html(wpsp_ViewDate($wpsp_exam->e_e_date),'wpschoolpress');?></td> |
| 111 |
<?php if($current_user_role=='administrator'){?> |
| 112 |
<td align="center"> |
| 113 |
<div class="wpsp-action-col"> |
| 114 |
<a href="<?php echo esc_url(wpsp_admin_url().'sch-exams&id='.intval($wpsp_exam->eid).'&edit=true');?>" title="Edit"><i class="icon dashicons dashicons-edit wpsp-edit-icon"></i></a> |
| 115 |
<a href="javascript:;" id="d_teacher" class="wpsp-popclick" data-pop="DeleteModal" title="Delete" data-id="<?php echo esc_attr($wpsp_exam->eid);?>" > |
| 116 |
<i class="icon dashicons dashicons-trash wpsp-delete-icon" data-id="<?php echo esc_attr($wpsp_exam->eid);?>"></i> |
| 117 |
</a> |
| 118 |
</div> |
| 119 |
</td> |
| 120 |
<?php } ?> |
| 121 |
</tr> |
| 122 |
<?php |
| 123 |
$sno++; |
| 124 |
} |
| 125 |
?> |
| 126 |
</tbody> |
| 127 |
<tfoot> |
| 128 |
<tr> |
| 129 |
<th class="nosort">#</th> |
| 130 |
<th><?php esc_html_e( 'Exam Name', 'wpschoolpress' );?></th> |
| 131 |
<th><?php esc_html_e( 'Class Name', 'wpschoolpress' );?></th> |
| 132 |
<th><?php esc_html_e( 'Subject Name', 'wpschoolpress' );?></th> |
| 133 |
<th><?php esc_html_e( 'Start Date', 'wpschoolpress' );?></th> |
| 134 |
<th><?php esc_html_e( 'End Date', 'wpschoolpress' );?></th> |
| 135 |
<?php if($current_user_role=='administrator'){?> |
| 136 |
<th class="nosort"><?php esc_html_e( 'Action', 'wpschoolpress' );?></th> |
| 137 |
<?php } ?> |
| 138 |
</tr> |
| 139 |
</tfoot> |
| 140 |
</table> |
| 141 |
</div> |
| 142 |
</div> |
| 143 |
<?php } |
| 144 |
if($current_user_role=='administrator'){?> |
| 145 |
<!--Info Modal--> |
| 146 |
<div class="modal fade" id="InfoModal" tabindex="-1" role="dialog" aria-labelledby="InfoModal" aria-hidden="true"> |
| 147 |
<div class="modal-dialog"> |
| 148 |
<div class="modal-content"> |
| 149 |
<div class="col-md-12"> |
| 150 |
<div class="box box-success"> |
| 151 |
<div class="box-header"> |
| 152 |
<p class="box-title" id="InfoModalTitle"></p> |
| 153 |
</div><!-- /.box-header --> |
| 154 |
<div id="InfoModalBody" class="box-body PTZero"> |
| 155 |
</div> |
| 156 |
</div> |
| 157 |
</div> |
| 158 |
</div> |
| 159 |
</div> |
| 160 |
</div><!-- /.modal --> |
| 161 |
<?php |
| 162 |
} |
| 163 |
wpsp_body_end(); |
| 164 |
wpsp_footer(); |
| 165 |
}else if( $current_user_role=='parent' || $current_user_role='student'){ |
| 166 |
wpsp_topbar(); |
| 167 |
wpsp_sidebar(); |
| 168 |
wpsp_body_start(); |
| 169 |
?> |
| 170 |
<div class="wpsp-card"> |
| 171 |
<div class="wpsp-card-head"> |
| 172 |
<h3 class="wpsp-card-title"><?php esc_html_e( 'Time Table', 'wpschoolpress' )?> </h3> |
| 173 |
</div> |
| 174 |
<div class="wpsp-card-body"> |
| 175 |
<table id="exam_class_table" class="wpsp-table" cellspacing="0" width="100%" style="width:100%"> |
| 176 |
<thead> |
| 177 |
<tr> |
| 178 |
<th class="nosort">#</th> |
| 179 |
<th><?php esc_html_e( 'Exam Name', 'wpschoolpress' );?></th> |
| 180 |
<th><?php esc_html_e( 'Class Name', 'wpschoolpress' );?></th> |
| 181 |
<th><?php esc_html_e( 'Subject Name', 'wpschoolpress' );?></th> |
| 182 |
<th><?php esc_html_e( 'Start Date', 'wpschoolpress' );?></th> |
| 183 |
<th><?php esc_html_e( 'End Date', 'wpschoolpress' );?></th> |
| 184 |
</tr> |
| 185 |
</thead> |
| 186 |
<tbody> |
| 187 |
<?php |
| 188 |
// $id = sanitize_text_field(stripslashes($_GET['cid'])); |
| 189 |
$class_id = base64_decode(sanitize_text_field($_GET['cid'])); |
| 190 |
$extable = $wpdb->prefix."wpsp_exam"; |
| 191 |
$studtable = $wpdb->prefix."wpsp_student"; |
| 192 |
$classtable = $wpdb->prefix."wpsp_class"; |
| 193 |
$wpsp_exams = []; |
| 194 |
if( $current_user_role=='parent' ) { |
| 195 |
// $wpsp_exams =$wpdb->get_results( "SELECT DISTINCT e.*,c.c_name FROM $studtable st, $extable e, $classtable c where st.parent_wp_usr_id='".esc_sql($current_user_Id)."' AND e.classid='".esc_sql($class_id)."' AND c.cid=".esc_sql($class_id).""); |
| 196 |
$wpsp_exams = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT e.*, c.c_name FROM $studtable st, $extable e, $classtable c |
| 197 |
WHERE st.parent_wp_usr_id = %d AND e.classid = %d AND c.cid = %d",$current_user_Id,$class_id,$class_id)); |
| 198 |
} else { |
| 199 |
// $wpsp_exams =$wpdb->get_results( "SELECT DISTINCT e.*,c.c_name FROM $studtable st, $extable e, $classtable c where |
| 200 |
// st.wp_usr_id='".esc_sql($current_user_Id)."' AND e.classid='".esc_sql($class_id)."' AND c.cid='".esc_sql($class_id)."'"); |
| 201 |
$wpsp_exams = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT e.*, c.c_name FROM $studtable st, $extable e, $classtable c |
| 202 |
WHERE st.wp_usr_id = %d AND e.classid = %d AND c.cid = %d",$current_user_Id,$class_id,$class_id)); |
| 203 |
} |
| 204 |
$sno=1; |
| 205 |
if(!empty($wpsp_exams)){ |
| 206 |
foreach ($wpsp_exams as $wpsp_exam){ |
| 207 |
$sublist = ''; |
| 208 |
if( !empty($wpsp_exam->subject_id) ) { |
| 209 |
$subject_list = array(); |
| 210 |
$subject_ids = explode(',', $wpsp_exam->subject_id); // "1,2,3" -> [1,2,3] |
| 211 |
$subject_ids = array_map('intval', $subject_ids); |
| 212 |
$placeholders = implode(',', array_fill(0, count($subject_ids), '%d')); |
| 213 |
// $subjectlist = $wpdb->get_results("SELECT sub_name FROM $subject_table WHERE id IN($wpsp_exam->subject_id)", ARRAY_A ); |
| 214 |
$query = $wpdb->prepare("SELECT sub_name FROM $subject_table WHERE id IN ($placeholders)",...$subject_ids); |
| 215 |
$subjectlist = $wpdb->get_results($query, ARRAY_A); |
| 216 |
foreach( $subjectlist as $list ) { |
| 217 |
$subject_list[] = $list['sub_name']; |
| 218 |
} |
| 219 |
$sublist = implode(", ",$subject_list); |
| 220 |
} |
| 221 |
?> |
| 222 |
<tr id="<?php echo esc_attr($wpsp_exam->eid);?>" class="pointer"> |
| 223 |
<td><?php echo esc_html($sno);?></td> |
| 224 |
<td><?php echo esc_html($wpsp_exam->e_name);?></td> |
| 225 |
<td><?php echo esc_html($wpsp_exam->c_name);?> </td> |
| 226 |
<td style="width: 580px;"><?php echo esc_html($sublist); ?> </td> |
| 227 |
<td><?php echo esc_html(wpsp_ViewDate($wpsp_exam->e_s_date),'wpschoolpress'); ?></td> |
| 228 |
<td><?php echo esc_html(wpsp_ViewDate($wpsp_exam->e_e_date),'wpschoolpress');?></td> |
| 229 |
</tr> |
| 230 |
<?php |
| 231 |
$sno++; |
| 232 |
} |
| 233 |
} |
| 234 |
?> |
| 235 |
</tbody> |
| 236 |
</table> |
| 237 |
</div> |
| 238 |
</div> |
| 239 |
<?php |
| 240 |
wpsp_body_end(); |
| 241 |
wpsp_footer(); |
| 242 |
} |
| 243 |
}else{ |
| 244 |
//Include Login Section |
| 245 |
include_once( WPSP_PLUGIN_PATH .'/includes/wpsp-login.php'); |
| 246 |
} |
| 247 |
?> |