| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) |
| 3 |
exit; |
| 4 |
|
| 5 |
$skip_hours = False; |
| 6 |
if ('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['noh']) && $_POST['noh'] != '') { |
| 7 |
$tt_table = $wpdb->prefix . "wpsp_timetable"; |
| 8 |
$wh_table = $wpdb->prefix . "wpsp_workinghours"; |
| 9 |
$wpsp_class_id = intval($_POST['wpsp_class_name']); |
| 10 |
$noh = intval($_POST['noh']); |
| 11 |
$sess_template = sanitize_text_field($_POST['sessions_template']); |
| 12 |
$sql_query = $wpdb->prepare("SELECT heading FROM $tt_table WHERE class_id = %d AND heading != %s",$wpsp_class_id,''); |
| 13 |
|
| 14 |
// Get the row using the prepared query. |
| 15 |
$check_tt = $wpdb->get_row($sql_query, ARRAY_N); |
| 16 |
//$check_tt = $wpdb->get_row("Select heading from $tt_table where class_id='".esc_sql($wpsp_class_id)."' and heading!=''", ARRAY_N); |
| 17 |
if (!empty($check_tt)) { |
| 18 |
$_POST['sessions_template'] = 'available'; |
| 19 |
$skip_hours = TRUE; |
| 20 |
} else { |
| 21 |
$sessions = $wpdb->get_results("SELECT * from $wh_table"); |
| 22 |
if (empty($sessions)) { |
| 23 |
echo "<div class='wpsp-text-red'>No Working Hours added. Please add at <a href='".esc_url(admin_url('admin.php?page=sch-settings&sc=WrkHours'))."'>Settings</a></div>"; |
| 24 |
return false; |
| 25 |
} |
| 26 |
?> |
| 27 |
<div class="box box-info"> |
| 28 |
<div class="box-header"> |
| 29 |
<h3 class="box-title"><?php esc_html_e( 'Select time for Sessions', 'wpschoolpress' ); ?></h3> |
| 30 |
</div> |
| 31 |
<div class="box-body"> |
| 32 |
<form name="" method="post" class="wpsp-form-horizontal"> |
| 33 |
<input type="hidden" name="wpsp_class_name" value="<?php echo esc_attr($wpsp_class_id);?>"> |
| 34 |
<input type="hidden" name="sessions_template" value="<?php echo esc_attr($sess_template);?>"> <?php |
| 35 |
for ($i = 1; $i <= $noh; $i++) { |
| 36 |
?> <div class="wpsp-row"> |
| 37 |
<div class="wpsp-col-md-4"> |
| 38 |
<div class="wpsp-form-group"> |
| 39 |
<label class="wpsp-label"><?php echo esc_html( 'Session', 'wpschoolpress' ); ?><?php echo esc_html($i);?> </label> |
| 40 |
<select name="session[]" class="wpsp-form-control"> |
| 41 |
<?php |
| 42 |
foreach ($sessions as $ses) {?> <option value="<?php echo esc_attr($ses->id);?>"><?php echo esc_html($ses->begintime);?>-<?php echo esc_html($ses->endtime);?></option> <?php |
| 43 |
}?> |
| 44 |
</select> |
| 45 |
</div> |
| 46 |
</div> |
| 47 |
</div> <?php } ?> |
| 48 |
<div class="wpsp-col-md-12"> |
| 49 |
<div class="wpsp-form-group"> |
| 50 |
<input type="submit" name="last-step" value="submit" class="wpsp-btn wpsp-btn-primary"> |
| 51 |
</div> |
| 52 |
</div> |
| 53 |
</form> |
| 54 |
</div> |
| 55 |
</div> <?php |
| 56 |
} |
| 57 |
} |
| 58 |
if (($skip_hours === TRUE) || ('POST' == $_SERVER['REQUEST_METHOD'] && sanitize_text_field($_POST['sessions_template']) == 'available' && sanitize_text_field($_POST['template_class']) != '') || ('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['last-step']) && sanitize_text_field($_POST['last-step']) == 'submit')) { |
| 59 |
$session = sanitize_price_array($_POST['session']); |
| 60 |
$tt_table = $wpdb->prefix . "wpsp_timetable"; |
| 61 |
$subject_table = $wpdb->prefix . "wpsp_subject"; |
| 62 |
$h_table = $wpdb->prefix . "wpsp_workinghours"; |
| 63 |
$class_id = sanitize_text_field($_POST['wpsp_class_name']); |
| 64 |
$sess_template = sanitize_text_field($_POST['sessions_template']); |
| 65 |
?> <div class="wpsp-card"> |
| 66 |
<div class="wpsp-card-head"> |
| 67 |
<h3 class="wpsp-card-title"><?php esc_html_e( 'Drag and Drop Subjects', 'wpschoolpress' ); ?> </h3> |
| 68 |
</div> |
| 69 |
<div class="wpsp-card-body"> <?php |
| 70 |
if ($sess_template == 'new') { |
| 71 |
$session = sanitize_price_array($_POST['session']); |
| 72 |
} else if ($sess_template == 'available' || $skip_hours === TRUE) { |
| 73 |
if ($skip_hours == TRUE) { |
| 74 |
$template_class_id = $class_id; |
| 75 |
} else { |
| 76 |
$template_class_id = sanitize_text_field($_POST['template_class']); |
| 77 |
|
| 78 |
} |
| 79 |
$check_tt = $wpdb->get_row($wpdb->prepare("SELECT heading FROM $tt_table WHERE class_id = %d AND heading != %s",$wpsp_class_id,'')); |
| 80 |
if (!empty($check_tt)) { |
| 81 |
$get_sessions = unserialize($check_tt->heading); |
| 82 |
foreach ($get_sessions as $sesio) { |
| 83 |
$session[] = $sesio; |
| 84 |
} |
| 85 |
$error = 0; |
| 86 |
} else { |
| 87 |
$error = 1; |
| 88 |
echo "<div class='wpsp-text-red'>Can't fetch template from the selected class</div>"; |
| 89 |
} |
| 90 |
} |
| 91 |
if (count($session) > 0) { |
| 92 |
//$chck_hd = $wpdb->get_row("SELECT * from $tt_table where class_id='".esc_sql($class_id)."' and time_id='0' and day='0' and heading!=''"); |
| 93 |
$chck_hd = $wpdb->get_row($wpdb->prepare("SELECT * FROM $tt_table WHERE class_id = %d and time_id='%s' and day='%s' AND heading != %s",$wpsp_class_id,'0','0','')); |
| 94 |
if (empty($chck_hd)) { |
| 95 |
$ins = $wpdb->insert($tt_table, array( |
| 96 |
'class_id' => $class_id, |
| 97 |
'heading' => serialize($session) |
| 98 |
)); |
| 99 |
} else { |
| 100 |
// echo "<span class='red'>*Sessions already available in order to edit session delete and regenerate timetable.</span>"; |
| 101 |
} |
| 102 |
$error = 0; |
| 103 |
} else { |
| 104 |
$error = 1; |
| 105 |
echo "<div class='wpsp-text-red'>No Sessions Retrieved</div>"; |
| 106 |
} |
| 107 |
$wpsp_hours_table = $wpdb->prefix . "wpsp_workinghours"; |
| 108 |
$wpsp_subjects_table = $wpdb->prefix . "wpsp_subject"; |
| 109 |
//$clt = $wpdb->get_results("SELECT * FROM $wpsp_subjects_table WHERE class_id='".esc_sql($class_id)."' or class_id=0 order by class_id desc"); |
| 110 |
$clt = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpsp_subjects_table WHERE class_id = %d or class_id = %d order by class_id desc",$class_id,0)); |
| 111 |
if (count($clt) == 0) { |
| 112 |
$error = 1; |
| 113 |
echo "<div class='wpsp-text-red'>No Subjects retrieved, Check you have subject for this class at <a href='" . esc_url(admin_url('admin.php?page=sch-subject')) . "'>Subjects</a></div>"; |
| 114 |
} |
| 115 |
if ($error == 0) { |
| 116 |
$timetable = array(); |
| 117 |
//$tt_days = $wpdb->get_results("select * from $tt_table where class_id='".esc_sql($class_id)."' and time_id !='0' ", ARRAY_A); |
| 118 |
$tt_query = $wpdb->prepare("SELECT * FROM $tt_table WHERE class_id = %d or time_id = %s",$class_id,'0'); |
| 119 |
$tt_days = $wpdb->get_results($tt_query, ARRAY_A); |
| 120 |
foreach ($tt_days as $ttd) { |
| 121 |
$timetable[$ttd['day']][$ttd['time_id']] = $ttd['subject_id']; |
| 122 |
} |
| 123 |
?> <div class="wpsp-row"> |
| 124 |
<div class="wpsp-col-md-12"> |
| 125 |
<div class="wpsp-form-group"> |
| 126 |
<label class="wpsp-labelMain"> <?php echo esc_html("Class", "wpschoolpress");?>: <?php |
| 127 |
echo esc_html(wpsp_GetClassName(sanitize_text_field($_POST['wpsp_class_name'])),'wpschoolpress'); |
| 128 |
?> </label> |
| 129 |
</div> |
| 130 |
</div> |
| 131 |
</div> |
| 132 |
<!-- <div class="wpsp-table-responsive"> |
| 133 |
<table align="center" class="wpsp-table" cellspacing="0" width="100%" style="width:100%"> |
| 134 |
<tbody> |
| 135 |
<tr> --> <?php |
| 136 |
foreach ($clt as $id) { |
| 137 |
wp_nonce_field( 'TimeTableRegister', 'wps_timetable_nonce', '', true ); |
| 138 |
/*echo '<td class="removesubject"><div class="item" id="' . $id->id . '" style="width:90px">' . $id->sub_name . '</div> </td>';*/ |
| 139 |
echo '<div class="removesubject"><div class="item" id="' . esc_attr($id->id) . '" style="width:auto; color:#5cb85c; font-weight:500;">' . esc_html($id->sub_name) . '</div> </div>'; |
| 140 |
} |
| 141 |
?> |
| 142 |
<!-- </tr> |
| 143 |
</tbody> |
| 144 |
</table> |
| 145 |
</div> --> |
| 146 |
<!-- <div class="wpsp-bg-yellow text-right" id="ajax_response_exist" style="background-color: #f39c12 !important;width: auto;float: right;text-align: center;"> |
| 147 |
</div> --> |
| 148 |
<div class="right wpsp-table-responsive" id="TimetableContainer"> |
| 149 |
<table class="wpsp-table wpsp-table-bordered" cellspacing="0" width="100%" style="width:100%"> |
| 150 |
<thead> |
| 151 |
<tr> |
| 152 |
<th> <?php echo esc_html("Week", "wpschoolpress");?> |
| 153 |
<!--<select class="daytype"> |
| 154 |
<option value="0">Days |
| 155 |
</option> |
| 156 |
<option value="1"> --> |
| 157 |
<!-- </option> |
| 158 |
</select> --> |
| 159 |
</th> <?php //print_r($session); |
| 160 |
foreach ($session as $sess) { |
| 161 |
?> <th> <?php |
| 162 |
//$ses_info = $wpdb->get_row("Select * from $wpsp_hours_table where id='$sess'"); |
| 163 |
$ses_info = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpsp_hours_table WHERE id = %s",$sess)); |
| 164 |
echo esc_html($ses_info->begintime . " to " . $ses_info->endtime); |
| 165 |
?> </th> <?php |
| 166 |
} |
| 167 |
?> |
| 168 |
</tr> |
| 169 |
</thead> |
| 170 |
<tbody> |
| 171 |
<?php |
| 172 |
$dayname = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); |
| 173 |
$leave_table=$wpdb->prefix."wpsp_leavedays";/* Sat-sun Off */ |
| 174 |
// $check = $wpdb->get_row("select description from $leave_table where class_id='".esc_sql($class_id)."'"); |
| 175 |
$check = $wpdb->get_row($wpdb->prepare("SELECT description FROM $leave_table WHERE class_id = %d",$class_id)); |
| 176 |
$wd = explode(',', $check->description); |
| 177 |
for ($j = 1; $j <= 7; $j++) { |
| 178 |
/* Sat-sun Off */ |
| 179 |
if (!empty($check)) { |
| 180 |
if ($wd[0] == $dayname[$j-1]) { |
| 181 |
continue; |
| 182 |
} |
| 183 |
if (isset($wd[1])) { |
| 184 |
if ($wd[1] == $dayname[$j-1]) { |
| 185 |
continue; |
| 186 |
} |
| 187 |
} |
| 188 |
}/* Sat-sun Off */ |
| 189 |
?> |
| 190 |
<tr id="<?php echo esc_html($j);?>"> |
| 191 |
<td> |
| 192 |
<!-- span class="dayval">Day <?php echo esc_html($j);?></span> --> |
| 193 |
<span class="daynam"> <?php echo esc_html($dayname[$j - 1]);?></span> |
| 194 |
</td> <?php |
| 195 |
foreach ($session as $key => $ses) { |
| 196 |
$ses = esc_sql($ses); |
| 197 |
// $hour_det = $wpdb->get_row("Select * from $wpsp_hours_table where id='$ses'"); |
| 198 |
$hour_det = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpsp_hours_table WHERE id = %s",$ses)); |
| 199 |
if ($hour_det->type == "1") { |
| 200 |
$td_class = "drop"; |
| 201 |
} else { |
| 202 |
$td_class = "break"; |
| 203 |
/* $sub_name='<div class="item1 assigned wpsp-assigned-item <?php echo $key; ?> <?php echo $ses; ?> <?php echo $j;?>">Break |
| 204 |
</div>'; */ |
| 205 |
|
| 206 |
} $sub_id = ''; $sub_name = ''; |
| 207 |
if (isset($timetable[$j][$ses])) $sub_id = $timetable[$j][$ses]; |
| 208 |
if ($sub_id > 0) { |
| 209 |
//$sub_name_f = $wpdb->get_row("SELECT sub_name from $subject_table where id='".esc_sql($sub_id)."'"); |
| 210 |
$sub_name_f = $wpdb->get_row($wpdb->prepare("SELECT sub_name FROM $subject_table WHERE id = %d",$sub_id)); |
| 211 |
$sub_name = $sub_name_f->sub_name; } |
| 212 |
if ($sub_name != '') { |
| 213 |
$sub_name='<div class="item1 assigned wpsp-assigned-item">'. esc_html($sub_name).'</div>'; } else { $sub_name = $sub_name; } |
| 214 |
if($td_class == "break"){ |
| 215 |
// $sub_name_f1 = $wpdb->get_row("SELECT id from $subject_table where sub_name='Break'"); |
| 216 |
$sub_name_f1 = $wpdb->get_row($wpdb->prepare("SELECT id FROM $subject_table WHERE sub_name = %s",'Break')); |
| 217 |
$time_table = $wpdb->prefix . "wpsp_timetable"; |
| 218 |
$time_table_data = array( 'class_id' => $class_id, 'time_id' => $ses, 'subject_id' => $sub_name_f1->id, 'session_id' => $key, 'day' => $j ); |
| 219 |
$ins = $wpdb->insert($time_table, $time_table_data); } ?> <td class="<?php echo esc_attr($td_class); ?>" tid="<?php echo esc_attr($ses); ?>" data-sessionid="<?php echo esc_attr($key); ?>"><?php if($td_class == "break"){ echo esc_html("Break","wpschoolpress");} else {echo wp_kses_post($sub_name); }?></td> <?php |
| 220 |
} |
| 221 |
?> </tr> <?php |
| 222 |
} |
| 223 |
?> </tbody> |
| 224 |
</table> |
| 225 |
<div class="wpsp-form-group"> |
| 226 |
<div class="wpsp-col-md-offset-10"> |
| 227 |
<input type="hidden" name="class_id" id="class_id" value="<?php echo esc_attr($class_id);?>"> |
| 228 |
<div id="ajax_response"> |
| 229 |
</div> |
| 230 |
</div> |
| 231 |
</div> |
| 232 |
<div class="wpsp-col-md-12 wpsp-col-lg-12"> |
| 233 |
<span class="pull-right"> |
| 234 |
<a href="javascript:;" class="wpsp-btn wpsp-btn-danger" id="deleteTimetable" data-id="<?php echo esc_attr($class_id);?>"><?php echo esc_html("Delete", "wpschoolpress");?></a> |
| 235 |
</span> |
| 236 |
</div> |
| 237 |
</div> <?php |
| 238 |
} |
| 239 |
?> |
| 240 |
</div> |
| 241 |
</div> <?php } |
| 242 |
if ('POST' != $_SERVER['REQUEST_METHOD']) { |
| 243 |
$tt_table = $wpdb->prefix . "wpsp_timetable"; |
| 244 |
$class_table = $wpdb->prefix . "wpsp_class"; |
| 245 |
$classQuery = $wpdb->prepare("select cid,c_name from $class_table Order By cid ASC"); |
| 246 |
$msg = esc_html("Please Add Class Before Adding Subjects", "wpschoolpress"); |
| 247 |
if ($current_usr_rle == 'teacher') { |
| 248 |
$cuserId = esc_sql($current_user->ID); |
| 249 |
$classQuery = $wpdb->prepare("select cid,c_name from $class_table where teacher_id='%d'",$cuserId); |
| 250 |
} |
| 251 |
$classes = $wpdb->get_results($classQuery); |
| 252 |
$class_names = array(); |
| 253 |
foreach ($classes as $cnames) { |
| 254 |
$class_names[$cnames->cid] = $cnames->c_name; |
| 255 |
} |
| 256 |
?> <div class="wpsp-card"> |
| 257 |
<div class="wpsp-card-head"> |
| 258 |
<h3 class="wpsp-card-title"><?php echo esc_html("Add New Timetable","wpschoolpress"); ?> </h3> |
| 259 |
</div> |
| 260 |
<div class="wpsp-card-body"> |
| 261 |
<form class="wpsp-form-horizontal" id="timetable_form" action="" method="post"> |
| 262 |
<?php wp_nonce_field( 'TimeTableRegister', 'wps_timetable_nonce', '', true ); ?> |
| 263 |
<div class="wpsp-row"> <?php |
| 264 |
$item = apply_filters( 'wpsp_timetable_title_item',esc_html("Class Name","wpschoolpress")); |
| 265 |
$is_required_item = apply_filters('wpsp_timetable_is_required',array()); |
| 266 |
?> <div class="wpsp-col-lg-3 wpsp-col-md-4 wpsp-col-sm-4 wpsp-col-xs-12"> |
| 267 |
<div class="wpsp-form-group"> |
| 268 |
<label class="wpsp-label"><?php esc_html_e("Select Class","wpschoolpress"); |
| 269 |
/*Check Required Field*/ |
| 270 |
if(isset($is_required_item['wpsp_class_name'])){ |
| 271 |
$is_required = esc_html($is_required_item['wpsp_class_name'],"wpschoolpress"); |
| 272 |
}else{ |
| 273 |
$is_required = true; |
| 274 |
} |
| 275 |
?> <span class="wpsp-required"><?php echo esc_html(($is_required))?"*":""; ?></span> |
| 276 |
</label> |
| 277 |
<select name="wpsp_class_name" data-is_required="<?php echo esc_attr($is_required); ?>" id="wpsp_class_name" class="wpsp-form-control"> |
| 278 |
<option value=""><?php echo esc_html("Select Class","wpschoolpress");?> </option> <?php |
| 279 |
foreach ($class_names as $cl_id => $cl_name) { |
| 280 |
?> <option value="<?php echo esc_attr($cl_id);?>"><?php echo esc_html($cl_name);?></option> <?php |
| 281 |
} |
| 282 |
?> |
| 283 |
</select> |
| 284 |
</div> |
| 285 |
</div> |
| 286 |
<div class="wpsp-col-lg-3 wpsp-col-md-4 wpsp-col-sm-4 wpsp-col-xs-12"> |
| 287 |
<div class="wpsp-form-group"> |
| 288 |
<label class="wpsp-label"><?php esc_html_e("Choose Session Template","wpschoolpress"); |
| 289 |
/*Check Required Field*/ |
| 290 |
if(isset($is_required_item['sessions_template'])){ |
| 291 |
$is_required = esc_html($is_required_item['sessions_template'],"wpschoolpress"); |
| 292 |
}else{ |
| 293 |
$is_required = true; |
| 294 |
} |
| 295 |
?> <span class="wpsp-required"><?php echo esc_html(($is_required))?"*":""; ?></span> |
| 296 |
</label> |
| 297 |
<select name="sessions_template" id="sessions_template" class="wpsp-form-control"> |
| 298 |
<option value="available"><?php echo esc_html("Available Templates","wpschoolpress");?> </option> |
| 299 |
<option value="new" selected><?php echo esc_html("New Template","wpschoolpress");?> </option> |
| 300 |
</select> |
| 301 |
</div> |
| 302 |
</div> |
| 303 |
<div class="wpsp-col-lg-3 wpsp-col-md-4 wpsp-col-sm-4 wpsp-col-xs-12" id="enter_sessions"> |
| 304 |
<div class="wpsp-form-group"> |
| 305 |
<label class="wpsp-label"><?php esc_html_e("Enter No.of Sessions","wpschoolpress"); |
| 306 |
/*Check Required Field*/ |
| 307 |
if(isset($is_required_item['noh'])){ |
| 308 |
$is_required = esc_html($is_required_item['noh'],"wpschoolpress"); |
| 309 |
}else{ |
| 310 |
$is_required = true; |
| 311 |
} |
| 312 |
?> <span class="wpsp-required"><?php echo esc_html(($is_required))?"*":""; ?></span> |
| 313 |
</label> |
| 314 |
<input type="text" data-is_required="<?php echo esc_attr($is_required); ?>" name="noh" class="wpsp-form-control"> |
| 315 |
<p style="margin-top:6px;"> |
| 316 |
<?php $url = plugins_url( 'img/svg/info-icon.svg', dirname(__FILE__) );?> |
| 317 |
<img src="<?php echo esc_url($url);?>" width="12" height="12"> <?php echo esc_html("Include breaks & lunch E.g 8 + 3 = 11 Sessions","wpschoolpress");?> |
| 318 |
</p> |
| 319 |
</div> |
| 320 |
</div> <?php |
| 321 |
// $avail_sess = $wpdb->get_results("SELECT t.class_id from $tt_table t, $class_table c where heading!='' and day=0 and c.cid=t.class_id"); |
| 322 |
$avail_sess = $wpdb->get_results($wpdb->prepare("SELECT t.class_id FROM $tt_table t $class_table c WHERE heading!= %s and day = %d and c.cid=t.class_id",'',0)); |
| 323 |
?> <div class="wpsp-col-lg-3 wpsp-col-md-4 wpsp-col-sm-4 wpsp-col-xs-12" id="select_template" style="display:none"> |
| 324 |
<div class="wpsp-form-group"> |
| 325 |
<label class="wpsp-label"><?php esc_html_e("Select Class","wpschoolpress");?> |
| 326 |
<?php echo esc_html("Select Sesssion","wpschoolpress");?> <span class="wpsp-required"> * </span> |
| 327 |
</label> |
| 328 |
<select name="template_class" id="template_class" class="wpsp-form-control"> <?php |
| 329 |
if (count($avail_sess) > 0) { |
| 330 |
foreach ($avail_sess as $avail_clid) { |
| 331 |
$class_id = $avail_clid->class_id; |
| 332 |
echo "<option value='" . esc_attr($class_id) . "'>" . esc_html($class_names[$class_id]) . "</option>"; |
| 333 |
} |
| 334 |
} else { |
| 335 |
"<option value=''>No Template Available</option>"; |
| 336 |
} |
| 337 |
?> </select> |
| 338 |
</div> |
| 339 |
</div> |
| 340 |
<div class="wpsp-col-xs-12"> |
| 341 |
<input type="submit" Value="Generate" name="stepone" class="wpsp-btn wpsp-btn-success"> |
| 342 |
</div> |
| 343 |
</div> |
| 344 |
</form> |
| 345 |
</div> |
| 346 |
</div> <?php |
| 347 |
} |
| 348 |
?> |