| 1 |
<?php |
| 2 |
if (!defined( 'ABSPATH' ) )exit('No Such File'); |
| 3 |
wpsp_header(); |
| 4 |
if( is_user_logged_in() ) { |
| 5 |
global $current_user, $wp_roles, $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 |
$class_table=$wpdb->prefix."wpsp_class"; |
| 12 |
$leave_table=$wpdb->prefix."wpsp_leavedays"; |
| 13 |
$current_user_id = get_current_user_id(); |
| 14 |
if ($current_user_role == 'administrator') { |
| 15 |
$class_r=$wpdb->get_results("select cid,c_name,c_sdate,c_edate from $class_table"); |
| 16 |
} |
| 17 |
if ($current_user_role == 'teacher') { |
| 18 |
// $class_r=$wpdb->get_results("select cid,c_name,c_sdate,c_edate from $class_table where teacher_id = '".esc_sql($current_user_id)."'"); |
| 19 |
$class_r = $wpdb->get_results($wpdb->prepare("SELECT cid,c_name,c_sdate,c_edate FROM $class_table WHERE teacher_id = %d",$current_user_id)); |
| 20 |
} |
| 21 |
$classes=array(); |
| 22 |
foreach($class_r as $classinfo){ |
| 23 |
$classes[$classinfo->cid]=array('c_name'=>$classinfo->c_name,'c_sdate'=>$classinfo->c_sdate,'c_edate'=>$classinfo->c_edate); |
| 24 |
} |
| 25 |
?> |
| 26 |
<div class="wpsp-card"> |
| 27 |
<div class="wpsp-card-head"> |
| 28 |
<h3 class="wpsp-card-title"><?php echo esc_html(apply_filters( 'wpsp_leaveclendar_heading_item', 'Generate Leave days for a class'), 'wpschoolpress'); ?></h3> |
| 29 |
</div> |
| 30 |
<?php if ($current_user_role == 'administrator') { ?> |
| 31 |
<div class="wpsp-card-body" id="addLeaveDaysBody"> |
| 32 |
<div class="wpsp-row"> |
| 33 |
<?php |
| 34 |
if(isset($_POST['submit']) && sanitize_text_field($_POST['submit'])=='Save Dates'){ |
| 35 |
$class_id = sanitize_text_field($_POST['ClassID']); |
| 36 |
if (!isset($_POST['wps_addleaves_nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['wps_addleaves_nonce']) , 'WPSLeave')){ |
| 37 |
echo esc_html("Unauthorized Submission!!", "wpschoolpress"); |
| 38 |
// wp_die(); |
| 39 |
}else{ |
| 40 |
if( $class_id!='' ) |
| 41 |
//$check = $wpdb->get_row("select * from $leave_table where class_id='".esc_sql($class_id)."'"); |
| 42 |
$check = $wpdb->get_row($wpdb->prepare("SELECT * FROM $leave_table WHERE class_id = %d",$class_id)); |
| 43 |
if(!is_numeric($class_id)){ |
| 44 |
echo "<div class='wpsp-col-md-12 wpsp-text-red off-dates wpsp-form-group'>Select class to generate weekly off dates</div>"; |
| 45 |
}else if(!empty($check)){ |
| 46 |
echo "<div class='wpsp-col-md-12 wpsp-text-red off-dates wpsp-form-group'>Dates were already generated for <span class='wpsp-text-blue'>".esc_html($classes[$class_id]['c_name'])."</span> please delete or use add option to add leave dates</div>"; |
| 47 |
}else if(sanitize_text_field($_POST['from'])=='' || sanitize_text_field($_POST['to'])=='') { |
| 48 |
echo "<div class='wpsp-col-md-12 wpsp-text-red off-dates wpsp-form-group'>Enter valid <span class='wpsp-text-blue'> school year</span> dates before trying!</div>"; |
| 49 |
}else{ |
| 50 |
$strDateFrom=date('Y-m-d',strtotime($_POST['from'])); |
| 51 |
$strDateTo=date('Y-m-d',strtotime($_POST['to'])); |
| 52 |
// $check_class=$wpdb->get_row("select c_sdate,c_edate from $class_table where cid='".esc_sql($class_id)."'"); |
| 53 |
$check_class = $wpdb->get_row($wpdb->prepare("SELECT c_sdate,c_edate FROM $class_table WHERE cid = %d",$class_id)); |
| 54 |
if($check_class->c_sdate =='' || $check_class->c_sdate ==NULL){ |
| 55 |
$wpdb->update($class_table,array('c_sdate'=>$strDateFrom),array('cid'=>$class_id)); |
| 56 |
} |
| 57 |
if($check_class->c_edate =='' || $check_class->c_edate ==NULL){ |
| 58 |
$wpdb->update($class_table,array('c_edate'=>$strDateTo),array('cid'=>$class_id)); |
| 59 |
} |
| 60 |
if(sanitize_text_field($_POST['weeklyoff'])=='0'){ |
| 61 |
$weeklyoff=array('Saturday','Sunday'); |
| 62 |
}else{ |
| 63 |
$weeklyoff=array(sanitize_text_field($_POST['weeklyoff'])); |
| 64 |
} |
| 65 |
$leave_dates=wpsp_leaveDates($strDateFrom,$strDateTo,$weeklyoff); |
| 66 |
if(isset($weeklyoff[1])){ //Sat-sun Off |
| 67 |
$des = $weeklyoff[0].','.$weeklyoff[1]; |
| 68 |
}else{ |
| 69 |
$des = $weeklyoff[0]; |
| 70 |
} |
| 71 |
foreach($leave_dates as $ldate){ |
| 72 |
$leave_table_data = array('class_id'=>intval($_POST['ClassID']),'leave_date'=>$ldate,'description'=>$des); |
| 73 |
$dt_ins=$wpdb->insert($leave_table,$leave_table_data); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
?> |
| 79 |
</div> |
| 80 |
<div class="wpsp-row"> |
| 81 |
<?php if ($current_user_role == 'administrator'){?> |
| 82 |
<div class="wpsp-col-md-6"> |
| 83 |
<form action="" name="leaveDaysForm" id="leaveDaysForm" method="post"> |
| 84 |
<?php wp_nonce_field( 'WPSLeave', 'wps_addleaves_nonce', '', true ); ?> |
| 85 |
<?php do_action("wpsp_before_leavecalendar"); |
| 86 |
$item = apply_filters( 'wpsp_leaveclendar_title_item',array()); |
| 87 |
?> |
| 88 |
<div class="wpsp-form-group"> |
| 89 |
<label class="wpsp-label"><?php esc_html_e("Class","wpschoolpress"); ?><span class="wpsp-required">*</span></label> |
| 90 |
<select name="ClassID" id="ClassID" class="wpsp-form-control"> |
| 91 |
<option value=""><?php esc_html_e( 'Select Class', 'wpschoolpress' );?></option> |
| 92 |
<?php foreach($classes as $cid=>$cname){ ?> |
| 93 |
<option value="<?php echo esc_attr($cid);?>"><?php echo esc_html($cname['c_name']);?></option> |
| 94 |
<?php } ?> |
| 95 |
</select> |
| 96 |
</div> |
| 97 |
<div class="wpsp-display-none"> |
| 98 |
<div class="wpsp-row"> |
| 99 |
<div class="wpsp-col-md-6"> |
| 100 |
<div class="wpsp-form-group"> |
| 101 |
<label class="wpsp-label"><?php esc_html_e("Start Date","wpschoolpress"); ?><span class="wpsp-required">*</span></label> |
| 102 |
<input type="text" name="from" id="CSDate" class="wpsp-form-control select_date"> |
| 103 |
</div> |
| 104 |
</div> |
| 105 |
<div class="wpsp-col-md-6"> |
| 106 |
<div class="wpsp-form-group"> |
| 107 |
<label class="wpsp-label"><?php esc_html_e("End Date","wpschoolpress"); ?><span class="wpsp-required">*</span></label> |
| 108 |
<input type="text" name="to" id="CEDate" class="wpsp-form-control select_date"> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
</div> |
| 112 |
</div> |
| 113 |
<div class="clearfix"></div> |
| 114 |
<div class="wpsp-form-group"> |
| 115 |
<label class="wpsp-label"><?php esc_html_e("Weekly off ","wpschoolpress"); ?><span class="wpsp-required">*</span></label> |
| 116 |
<select name="weeklyoff" class="wpsp-form-control"> |
| 117 |
<option value=""><?php esc_html_e( 'Select Day', 'wpschoolpress' );?></option> |
| 118 |
<option value="0"><?php esc_html_e( 'All Saturday and Sunday', 'wpschoolpress' );?></option> |
| 119 |
<option value="Monday"><?php esc_html_e( 'Monday', 'wpschoolpress' );?></option> |
| 120 |
<option value="Tuesday"><?php esc_html_e( 'Tuesday', 'wpschoolpress' );?></option> |
| 121 |
<option value="Wednesday"><?php esc_html_e( 'Wednesday', 'wpschoolpress' );?></option> |
| 122 |
<option value="Thursday"><?php esc_html_e( 'Thursday', 'wpschoolpress' );?></option> |
| 123 |
<option value="Friday"><?php esc_html_e( 'Friday', 'wpschoolpress' );?></option> |
| 124 |
<option value="Saturday"><?php esc_html_e( 'Saturday', 'wpschoolpress' );?></option> |
| 125 |
<option value="Sunday"><?php esc_html_e( 'Sunday', 'wpschoolpress' );?></option> |
| 126 |
</select> |
| 127 |
</div> |
| 128 |
<div class="clearfix"></div> |
| 129 |
<div class="wpsp-form-group MTTen"> |
| 130 |
<input type="submit" name="submit" class="wpsp-btn wpsp-btn-primary" value="Save Dates"> |
| 131 |
</div> |
| 132 |
</form> |
| 133 |
</div> |
| 134 |
<div class="wpsp-col-md-6"> |
| 135 |
<ul class="wpsp-ulli-list"> |
| 136 |
<li><?php esc_html_e( 'Use this form only once for a class to generate all weekly off dates', 'wpschoolpress' );?></li> |
| 137 |
<li><?php esc_html_e( 'All these dates are excluded for attendance calculation', 'wpschoolpress' );?></li> |
| 138 |
<li><?php esc_html_e( 'You can delete any date if you have a school on that date', 'wpschoolpress' );?></li> |
| 139 |
<li><?php esc_html_e( 'This is for attendance calculation purpose only', 'wpschoolpress' );?></li> |
| 140 |
</ul> |
| 141 |
</div> |
| 142 |
<?php } ?> |
| 143 |
</div> |
| 144 |
</div> |
| 145 |
<?php |
| 146 |
} |
| 147 |
$leaves=$wpdb->get_results("select class_id,description,count(*) as numleaves from $leave_table group by class_id"); |
| 148 |
?> |
| 149 |
<div class="wpsp-card"> |
| 150 |
<div class="wpsp-card-body"> |
| 151 |
<table class="wpsp-table" id="wpsp_leave_days" cellspacing="0" width="100%" style="width:100%"> |
| 152 |
<thead> |
| 153 |
<tr> |
| 154 |
<th><?php esc_html_e( 'Class', 'wpschoolpress' );?></th> |
| 155 |
<th><?php esc_html_e( 'School Year', 'wpschoolpress' );?></th> |
| 156 |
<th><?php esc_html_e( 'Number of leave days', 'wpschoolpress' );?></th> |
| 157 |
<?php if ($current_user_role == 'administrator'){?> |
| 158 |
<th align="center" class="nosort"><?php esc_html_e( 'Action', 'wpschoolpress' );?></th> |
| 159 |
<?php }?> |
| 160 |
</tr> |
| 161 |
</thead> |
| 162 |
<tbody> |
| 163 |
<?php foreach($leaves as $leave){ |
| 164 |
if($classes[$leave->class_id]['c_name'] == ""){ }else{ ?> |
| 165 |
<tr> |
| 166 |
<td><?php echo esc_html($classes[$leave->class_id]['c_name']);?></td> |
| 167 |
<td> |
| 168 |
<?php |
| 169 |
echo esc_html(wpsp_ViewDate($classes[$leave->class_id]['c_sdate'])).' to '.esc_html(wpsp_ViewDate($classes[$leave->class_id]['c_edate'])); |
| 170 |
?> |
| 171 |
</td> |
| 172 |
<td><?php echo esc_html($leave->numleaves);?></td> |
| 173 |
<?php if ($current_user_role == 'administrator'){?> |
| 174 |
<td align="center"> |
| 175 |
<div class="wpsp-action-col"> |
| 176 |
<a href="javascript:;" class="leaveView wpsp-popclick" title="View" data-pop="ViewModal" data-id="<?php echo esc_attr(intval($leave->class_id));?>"> |
| 177 |
<i class="icon wpsp-view wpsp-view-icon"></i></a> |
| 178 |
<?php $nonce = wp_create_nonce( 'WPSAddLeaves'); ?> |
| 179 |
<a href="javascript:;" data-non ="<?php echo esc_attr( $nonce ); ?>" title="Add" class="leaveAdd wpsp-popclick" data-pop="ViewModal" data-id="<?php echo esc_attr(intval($leave->class_id));?>"> |
| 180 |
<i class="icon fa fa-plus-circle btn btn-primary gap-bottom-small"></i></a> |
| 181 |
<a href="javascript:;" id="d_teacher" class="wpsp-popclick" data-pop="DeleteModal" title="Delete" data-id="<?php echo esc_attr($leave->class_id);?>" > |
| 182 |
<i class="icon wpsp-trash wpsp-delete-icon" data-id="<?php echo esc_attr(intval($leave->class_id));?>"></i> |
| 183 |
</a> |
| 184 |
</div> |
| 185 |
</td> |
| 186 |
<?php }?> |
| 187 |
</tr> |
| 188 |
<?php } } ?> |
| 189 |
</tbody> |
| 190 |
<tfoot> |
| 191 |
<tr> |
| 192 |
<th><?php esc_html_e( 'Class', 'wpschoolpress' );?></th> |
| 193 |
<th><?php esc_html_e( 'School Year', 'wpschoolpress' );?></th> |
| 194 |
<th><?php esc_html_e( 'Number of leave days', 'wpschoolpress' );?></th> |
| 195 |
<?php if ($current_user_role == 'administrator'){?><th class="nosort"><?php esc_html_e( 'Action', 'wpschoolpress' );?></th><?php }?> |
| 196 |
</tr> |
| 197 |
</tfoot> |
| 198 |
</table> |
| 199 |
</div> |
| 200 |
</div> |
| 201 |
</div> |
| 202 |
<div class="wpsp-popupMain" id="ViewModal"> |
| 203 |
<div class="wpsp-overlayer"></div> |
| 204 |
<div class="wpsp-popBody"> |
| 205 |
<div class="wpsp-popInner"> |
| 206 |
<a href="javascript:;" class="wpsp-closePopup"></a> |
| 207 |
<div id="ViewModalContent" class="wpsp-text-left"></div> |
| 208 |
</div> |
| 209 |
</div> |
| 210 |
</div> |
| 211 |
<?php |
| 212 |
wpsp_body_end(); |
| 213 |
wpsp_footer(); |
| 214 |
}else if($current_user_role == 'parent' || $current_user_role == 'student'){ |
| 215 |
wpsp_topbar(); |
| 216 |
wpsp_sidebar(); |
| 217 |
wpsp_body_start(); |
| 218 |
$current_user_id = get_current_user_id(); |
| 219 |
$Student_table=$wpdb->prefix."wpsp_student"; |
| 220 |
if($current_user_role == 'student'){ |
| 221 |
$examinfo=$wpdb->get_row("select class_id from $Student_table where wp_usr_id = '".esc_sql($current_user_id)."'"); |
| 222 |
// $examinfo = $wpdb->get_row($wpdb->prepare("SELECT class_id FROM $Student_table WHERE wp_usr_id = %d",$current_user_id)); |
| 223 |
$class_id = base64_decode(sanitize_text_field($_GET['cid'])); |
| 224 |
} else { |
| 225 |
// $examinfo=$wpdb->get_row("select class_id from $Student_table where parent_wp_usr_id = '".esc_sql($current_user_id)."'") |
| 226 |
$examinfo = $wpdb->get_row($wpdb->prepare("SELECT class_id FROM $Student_table WHERE parent_wp_usr_id = %d",$current_user_id));; |
| 227 |
$class_id = base64_decode(sanitize_text_field($_GET['cid'])); |
| 228 |
} |
| 229 |
$class_table=$wpdb->prefix."wpsp_class"; |
| 230 |
$leave_table=$wpdb->prefix."wpsp_leavedays"; |
| 231 |
//$class_r=$wpdb->get_results("select cid,c_name,c_sdate,c_edate from $class_table where cid = '".esc_sql($class_id)."'"); |
| 232 |
$class_r = $wpdb->get_results($wpdb->prepare("SELECT cid,c_name,c_sdate,c_edate FROM $class_table WHERE cid = %d",$class_id)); |
| 233 |
$classes=array(); |
| 234 |
foreach($class_r as $classinfo){ |
| 235 |
$classes[ $classinfo->cid]=array('c_name'=>$classinfo->c_name,'c_sdate'=>$classinfo->c_sdate,'c_edate'=>$classinfo->c_edate); |
| 236 |
} |
| 237 |
$leaves=$wpdb->get_results("select class_id,description,count(*) as numleaves from $leave_table WHERE class_id = '".esc_sql($class_id)."' group by class_id"); |
| 238 |
// $leaves = $wpdb->get_results($wpdb->prepare("SELECT class_id,description,count(*) as numleaves FROM $leave_table WHERE class_id = %d group by class_id",$class_id)); |
| 239 |
?> |
| 240 |
<div class="wpsp-card"> |
| 241 |
<div class="wpsp-card-head" > |
| 242 |
<h3 class="wpsp-card-title"><?php esc_html_e( 'Leave Calender', 'wpschoolpress' );?></h3> |
| 243 |
</div> |
| 244 |
<div class="wpsp-card-body"> |
| 245 |
<table class="wpsp-table" id="wpsp_leave_days"> |
| 246 |
<thead> |
| 247 |
<tr> |
| 248 |
<th><?php esc_html_e( 'Class', 'wpschoolpress' );?></th> |
| 249 |
<th><?php esc_html_e( 'School Yea', 'wpschoolpress' );?>r</th> |
| 250 |
<th><?php esc_html_e( 'Number of leave days', 'wpschoolpress' );?></th> |
| 251 |
<th align="center" class="nosort"><?php esc_html_e( 'Action', 'wpschoolpress' );?></th> |
| 252 |
</tr> |
| 253 |
</thead> |
| 254 |
<tbody> |
| 255 |
<?php foreach($leaves as $leave){ ?> |
| 256 |
<tr> |
| 257 |
<td><?php echo esc_html($classes[$leave->class_id]['c_name']);?></td> |
| 258 |
<td> |
| 259 |
<?php echo esc_html(wpsp_ViewDate($classes[$leave->class_id]['c_sdate'])).' to '.esc_html(wpsp_ViewDate($classes[$leave->class_id]['c_edate'])); ?> |
| 260 |
</td> |
| 261 |
<td><?php echo esc_html($leave->numleaves);?></td> |
| 262 |
<td align="center"> |
| 263 |
<div class="wpsp-action-col minWidthAuto"> |
| 264 |
<span><a href="javascript:;" class="leaveView wpsp-popclick" data-pop="ViewModal" data-id="<?php echo esc_attr(intval($leave->class_id));?>"><i class="icon wpsp-view wpsp-view-icon"></i></a></span> |
| 265 |
</div> |
| 266 |
</td> |
| 267 |
</tr> |
| 268 |
<?php } ?> |
| 269 |
</tbody> |
| 270 |
</table> |
| 271 |
</div> |
| 272 |
</div> |
| 273 |
<!-- Modal popup of leave view --> |
| 274 |
<div class="wpsp-popupMain" id="ViewModal"> |
| 275 |
<div class="wpsp-overlayer"></div> |
| 276 |
<div class="wpsp-popBody"> |
| 277 |
<div class="wpsp-popInner"> |
| 278 |
<a href="javascript:;" class="wpsp-closePopup"></a> |
| 279 |
<div id="ViewModalContent"> |
| 280 |
<div class="wpsp-panel-body"> |
| 281 |
<h3 id="leaveModalHeader" class="wpsp-card-title"> |
| 282 |
</div> |
| 283 |
<div id="leaveModalBody" class="modal-body"> |
| 284 |
</div> |
| 285 |
</div> |
| 286 |
</div> |
| 287 |
</div> |
| 288 |
</div> |
| 289 |
</div> |
| 290 |
<!-- END Modal popup of leave view --> |
| 291 |
<div class="wpsp-wrapper"> |
| 292 |
<div class="wpsp-container"> |
| 293 |
<?php |
| 294 |
wpsp_body_end(); |
| 295 |
wpsp_footer(); |
| 296 |
?> |
| 297 |
</div> |
| 298 |
</div> |
| 299 |
<?php } |
| 300 |
}else{ |
| 301 |
include_once( WPSP_PLUGIN_PATH .'/includes/wpsp-login.php'); |
| 302 |
} |
| 303 |
?> |