| 1 |
<?php |
| 2 |
if ( !defined( 'ABSPATH' ) ) { exit; } |
| 3 |
$skip_hours=False; |
| 4 |
if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['noh']) && $_POST['noh'] != ''){ |
| 5 |
$tt_table=$wpdb->prefix . "wpsp_timetable"; |
| 6 |
$wh_table = $wpdb->prefix . "wpsp_workinghours"; |
| 7 |
$wpsp_class_id = sanitize_text_field($_POST['wpsp_class_name']); |
| 8 |
$noh = sanitize_text_field($_POST['noh']); |
| 9 |
$sess_template = sanitize_text_field($_POST['sessions_template']); |
| 10 |
// $check_tt = $wpdb->get_row("Select heading from $tt_table where class_id='".esc_sql($wpsp_class_id)."' and heading!=''"); |
| 11 |
$check_tt = $wpdb->get_row($wpdb->prepare("SELECT heading FROM $tt_table WHERE class_id = %d and heading!= %s",$wpsp_class_id,'')); |
| 12 |
if (count($check_tt) > 0) { |
| 13 |
$_POST['sessions_template']='available'; |
| 14 |
$skip_hours=TRUE; |
| 15 |
}else{ |
| 16 |
$sessions = $wpdb->get_results("SELECT * from $wh_table"); |
| 17 |
if(empty($sessions)){ |
| 18 |
echo "<div class='wpsp-text-red'>No Working Hours added. Please add at <a href='".esc_url('sch-settings/?sc=WrkHours')."'>Settings</a></div>"; |
| 19 |
return false; |
| 20 |
}?> |
| 21 |
<div class="wpsp-card"> |
| 22 |
<div class="wpsp-card-head"> |
| 23 |
<h3 class="wpsp-card-title"><?php echo esc_html("Select time for Sessions","wpschoolpress");?> </h3> |
| 24 |
</div> |
| 25 |
<div class="wpsp-card-body"> |
| 26 |
<form name="gen_table" method="post" class="wpsp-form-horizontal"> |
| 27 |
<input type="hidden" name="wpsp_class_name" value="<?php echo esc_attr($wpsp_class_id); ?>"> |
| 28 |
<input type="hidden" name="sessions_template" value="<?php echo esc_attr($sess_template); ?>"> |
| 29 |
<?php for($i = 1; $i <= $noh; $i++) { ?> |
| 30 |
<div class="wpsp-form-group"> |
| 31 |
<label class="wpsp-label"><?php echo esc_html("Session","wpschoolpress");?><?php echo esc_html($i); ?></label> |
| 32 |
<div class="wpsp-col-md-4"> |
| 33 |
<select name="session[]" class="wpsp-form-control"> |
| 34 |
<?php |
| 35 |
foreach ($sessions as $ses) { ?> |
| 36 |
<option value="<?php echo esc_attr($ses->id); ?>"><?php echo esc_html($ses->begintime); ?>-<?php echo esc_html($ses->endtime); ?></option> |
| 37 |
<?php } ?> |
| 38 |
</select> |
| 39 |
</div> |
| 40 |
</div> |
| 41 |
<?php } ?> |
| 42 |
<div class="wpsp-form-group"> |
| 43 |
<div class="wpsp-col-md-offset-4"> |
| 44 |
<input type="submit" name="last-step" value="submit" class="wpsp-btn wpsp-btn-primary"> |
| 45 |
</div> |
| 46 |
</div> |
| 47 |
</form> |
| 48 |
</div> |
| 49 |
</div> |
| 50 |
<?php } |
| 51 |
} |
| 52 |
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')){ |
| 53 |
$tt_table = $wpdb->prefix . "wpsp_timetable"; |
| 54 |
$subject_table = $wpdb->prefix . "wpsp_subject"; |
| 55 |
$h_table = $wpdb->prefix . "wpsp_workinghours"; |
| 56 |
$class_id = sanitize_text_field($_POST['wpsp_class_name']); |
| 57 |
$sess_template = sanitize_text_field($_POST['sessions_template']); ?> |
| 58 |
<div class="wpsp-card"> |
| 59 |
<div class="wpsp-card-head"> |
| 60 |
<h3 class="wpsp-card-title"><?php esc_html_e("Drag and Drop Subjects","wpschoolpress");?></h3> |
| 61 |
</div> |
| 62 |
<div class="wpsp-card-body"> |
| 63 |
<?php |
| 64 |
if ($sess_template == 'new'){ |
| 65 |
$session = sanitize_text_field($_POST['session']); |
| 66 |
}else if ($sess_template == 'available' || $skip_hours===TRUE){ |
| 67 |
if($skip_hours==TRUE){ |
| 68 |
$template_class_id=$class_id; |
| 69 |
}else{ |
| 70 |
$template_class_id = sanitize_text_field($_POST['template_class']); |
| 71 |
} |
| 72 |
// $check_tt = $wpdb->get_row("Select heading from $tt_table where class_id='".esc_sql($template_class_id)."' and heading!=''"); |
| 73 |
$check_tt = $wpdb->get_row($wpdb->prepare("SELECT heading FROM $tt_table WHERE class_id = %d and heading!= %s",$template_class_id,'')); |
| 74 |
if (count($check_tt) > 0) { |
| 75 |
$get_sessions = unserialize($check_tt->heading); |
| 76 |
foreach ($get_sessions as $sesio){ |
| 77 |
$session[] = $sesio; |
| 78 |
} |
| 79 |
}else{ |
| 80 |
$error = 1; |
| 81 |
echo "<div class='wpsp-text-red'>Can't fetch template from the selected class</div>"; |
| 82 |
} |
| 83 |
} |
| 84 |
if (count($session) > 0) { |
| 85 |
// $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!=''"); |
| 86 |
$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",$class_id,'0','0','')); |
| 87 |
if(count($chck_hd) == null){ |
| 88 |
$ins = $wpdb->insert($tt_table, array('class_id' => $class_id,'heading' => serialize($session))); |
| 89 |
}else{ |
| 90 |
echo "<span class='red'>*Sessions already available in order to edit session delete and regenerate timetable.</span>"; |
| 91 |
} |
| 92 |
}else{ |
| 93 |
$error = 1; |
| 94 |
echo "<div class='wpsp-text-red'>No Sessions Retrieved</div>"; } |
| 95 |
$wpsp_hours_table = $wpdb->prefix . "wpsp_workinghours"; |
| 96 |
$wpsp_subjects_table = $wpdb->prefix . "wpsp_subject"; |
| 97 |
// $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"); |
| 98 |
$clt = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpsp_subjects_table WHERE class_id = %d or class_id=%d order by class_id desc",$class_id,0)); |
| 99 |
if(count($clt)==0) { |
| 100 |
$error = 1; |
| 101 |
echo "<div class='wpsp-text-red'>No Subjects retrieved, Check you have subject for this class at <a href='".esc_url(site_url())."/sch-subject'>Subjects</a></div>"; |
| 102 |
} |
| 103 |
if ($error == 0) { |
| 104 |
$timetable=array(); |
| 105 |
//$tt_days=$wpdb->get_results("select * from $tt_table where class_id='".esc_sql($class_id)."' and time_id !='0' ",ARRAY_A); |
| 106 |
$tt_query = $wpdb->prepare("SELECT * FROM $tt_table WHERE class_id = %d and time_id != '%s' order by class_id desc",$class_id,0); |
| 107 |
$tt_days = $wpdb->get_results($tt_query,$ARRAY_A); |
| 108 |
foreach($tt_days as $ttd){ |
| 109 |
$timetable[$ttd['day']][$ttd['time_id']]=$ttd['subject_id']; |
| 110 |
} ?> |
| 111 |
<div class="wpsp-col-md-6 text-blue"><?php esc_html_e("Class","wpschoolpress");?> :<span class="text-black"> <?php echo esc_html(wpsp_GetClassName(sanitize_text_field($_POST['wpsp_class_name'])),'wpschoolpress'); ?></span></div> |
| 112 |
<div style="width: 100%;"> |
| 113 |
</div> |
| 114 |
<div class="bg-yellow text-right" id="ajax_response_exist" style="background-color: #f39c12 !important;width: auto;float: right;text-align: center;"></div> |
| 115 |
<div class="right wpsp-table-responsive" id="TimetableContainer"> |
| 116 |
<table class="wpsp-table table-bordered"> |
| 117 |
<thead> |
| 118 |
<tr> |
| 119 |
<th> |
| 120 |
<select class="daytype"> |
| 121 |
<option value="0"><?php echo esc_html("Days","wpschoolpress");?></option> |
| 122 |
<option value="1"><?php echo esc_html("Week","wpschoolpress");?></option> |
| 123 |
</select> |
| 124 |
</th> |
| 125 |
<?php |
| 126 |
foreach ($session as $sess) { ?> |
| 127 |
<th> |
| 128 |
<?php $sess = esc_sql($sess); |
| 129 |
// $ses_info = $wpdb->get_row("Select * from $wpsp_hours_table where id='$sess'"); |
| 130 |
$ses_info = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpsp_hours_table WHERE ID = %s",$sess)); |
| 131 |
echo esc_html($ses_info->begintime . " to " . $ses_info->endtime) ?> |
| 132 |
</th> |
| 133 |
<?php }?> |
| 134 |
</tr> |
| 135 |
</thead> |
| 136 |
<tbody> |
| 137 |
<?php |
| 138 |
$dayname = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); |
| 139 |
for ($j = 1; $j <= 7; $j++) {?> |
| 140 |
<tr id="<?php echo esc_attr($j); ?>"> |
| 141 |
<td><span class="dayval"><?php echo esc_html("Day","wpschoolpress");?><?php echo esc_html($j); ?></span> |
| 142 |
<span class="daynam" style="display:none"> |
| 143 |
<?php echo esc_html($dayname[$j - 1]); ?></span> |
| 144 |
</td> |
| 145 |
<?php |
| 146 |
foreach ($session as $ses) { |
| 147 |
$ses = esc_sql($ses); |
| 148 |
// $hour_det = $wpdb->get_row("Select * from $wpsp_hours_table where id='$ses'"); |
| 149 |
$hour_det = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpsp_hours_table WHERE ID = %s",$ses)); |
| 150 |
if ($hour_det->type == "1") { |
| 151 |
$td_class = "drop"; |
| 152 |
}else { |
| 153 |
$td_class = "break"; } |
| 154 |
$sub_id=''; |
| 155 |
$sub_name=''; |
| 156 |
if(isset($timetable[$j][$ses])) |
| 157 |
$sub_id=$timetable[$j][$ses]; |
| 158 |
if($sub_id >0){ |
| 159 |
// $sub_name_f = $wpdb->get_row("SELECT sub_name from $subject_table where id='$sub_id'"); |
| 160 |
$sub_name_f = $wpdb->get_row($wpdb->prepare("SELECT sub_name FROM $subject_table WHERE id = %s",$sub_id)); |
| 161 |
$sub_name = $sub_name_f->sub_name; |
| 162 |
} |
| 163 |
if($sub_name!=''){ |
| 164 |
$sub_name='<div class="item assigned">'. esc_html($sub_name).'</div>'; }else{ $sub_name=''; } ?> |
| 165 |
<td class="<?php echo esc_attr($td_class); ?>" tid="<?php echo esc_attr($ses); ?>"> |
| 166 |
<?php echo esc_html($sub_name); ?> </td> |
| 167 |
<?php } ?> |
| 168 |
</tr> |
| 169 |
<?php } ?> |
| 170 |
</tbody> |
| 171 |
</table> |
| 172 |
<div class="wpsp-form-group"> |
| 173 |
<div class="wpsp-col-md-offset-10"> |
| 174 |
<input type="hidden" name="class_id" id="class_id" value="<?php echo esc_attr($class_id); ?>"> |
| 175 |
<div class="bg-green" id="ajax_response"></div> |
| 176 |
</div> |
| 177 |
</div> |
| 178 |
<div class="wpsp-col-md-12 wpsp-col-lg-12"> |
| 179 |
<span class="pull-right"><a href="javascript:;" id="deleteTimetable" data-id="<?php echo esc_attr($class_id); ?>"><?php echo esc_html("Delete","wpschoolpress");?></a></span> |
| 180 |
</div> |
| 181 |
</div> |
| 182 |
<?php } ?> |
| 183 |
</div> |
| 184 |
</div> |
| 185 |
<?php } |
| 186 |
if( 'POST' != $_SERVER['REQUEST_METHOD'] ) { |
| 187 |
$tt_table = $wpdb->prefix . "wpsp_timetable"; |
| 188 |
$class_table = $wpdb->prefix . "wpsp_class";?> |
| 189 |
<div class="box box-info"> |
| 190 |
<div class="box-header"> |
| 191 |
<h3 class="box-title"><?php esc_html_e("New Timetable","wpschoolpress");?></h3> |
| 192 |
</div> |
| 193 |
<div class="box-body"> |
| 194 |
<form class="wpsp-form-horizontal" id="timetable_form" action="" method="post"> |
| 195 |
<div class="wpsp-form-group"> |
| 196 |
<label class="wpsp-col-sm-4 wpsp-label"><?php esc_html_e("Select Class","wpschoolpress");?><span class="wpsp-required">*</span> </label> |
| 197 |
<div class="wpsp-col-md-4"> |
| 198 |
<select name="wpsp_class_name" id="wpsp_class_name" class="wpsp-form-control"> |
| 199 |
<option value=""><?php esc_html_e("Select Class","wpschoolpress");?></option> |
| 200 |
<?php |
| 201 |
foreach ($class_names as $cl_id=>$cl_name) {?> |
| 202 |
<option value="<?php echo esc_attr($cl_id); ?>"><?php echo esc_html($cl_name); ?></option> |
| 203 |
<?php |
| 204 |
} |
| 205 |
?> |
| 206 |
</select> |
| 207 |
</div> |
| 208 |
</div> |
| 209 |
<div class="wpsp-form-group"> |
| 210 |
<label class="wpsp-label "><?php esc_html_e("Choose Session Template","wpschoolpress");?> <span class="wpsp-required">*</span></label> |
| 211 |
<div class="wpsp-col-md-4"> |
| 212 |
<select name="sessions_template" id="sessions_template" class="wpsp-form-control"> |
| 213 |
<option value="available"><?php esc_html_e("Available Templates","wpschoolpress");?></option> |
| 214 |
<option value="new" selected><?php esc_html_e("New Template","wpschoolpress");?></option> |
| 215 |
</select> |
| 216 |
</div> |
| 217 |
</div> |
| 218 |
<?php //$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"); |
| 219 |
$avail_sess = $wpdb->get_results($wpdb->prepare("SELECT t.class_id from $tt_table t, $class_table c WHERE heading!= %s and day = %d c.cid=t.class_id",$sub_id,0)); |
| 220 |
?> |
| 221 |
<div class="wpsp-form-group" id="select_template" style="display:none"> |
| 222 |
<label class="wpsp-col-md-4 wpsp-label "><?php esc_html_e("Select Session","wpschoolpress");?><span class="wpsp-required">*</span></label> |
| 223 |
<div class="wpsp-col-md-3"> |
| 224 |
<select name="template_class" id="template_class" class="wpsp-form-control"> |
| 225 |
<?php |
| 226 |
if (count($avail_sess) > 0) { |
| 227 |
foreach ($avail_sess as $avail_clid) { |
| 228 |
$class_id = $avail_clid->class_id; |
| 229 |
echo "<option value='" . esc_attr($class_id) . "'>" . esc_html($class_names[$class_id]) . "</option>"; |
| 230 |
} |
| 231 |
} |
| 232 |
else { |
| 233 |
echo "<option value=''>No Template Available</option>"; |
| 234 |
}?> |
| 235 |
</select> |
| 236 |
</div> |
| 237 |
</div> |
| 238 |
<div class="wpsp-form-group" id="enter_sessions"> |
| 239 |
<label class="wpsp-col-md-4 wpsp-label"><?php esc_html_e("Enter No.of Sessions","wpschoolpress");?> |
| 240 |
<span class="wpsp-required">*</span> </label> |
| 241 |
<div class="wpsp-col-md-3"> |
| 242 |
<input type="text" name="noh" class="wpsp-form-control"> |
| 243 |
</div> |
| 244 |
<div class="wpsp-col-md-3"> |
| 245 |
<span class="text-muted"><?php esc_html_e("Include breaks and lunch <br> E.g 8 + 3 = 11 Sessions","wpschoolpress");?></span> |
| 246 |
</div> |
| 247 |
</div> |
| 248 |
<div class="wpsp-col-md-4 wpsp-col-md-offset-4"> |
| 249 |
<input type="submit" Value="Generate" name="stepone" class="wpsp-btn wpsp-btn-primary"> |
| 250 |
</div> |
| 251 |
</form> |
| 252 |
</div> |
| 253 |
</div> |
| 254 |
<?php }?> |