| 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 |
$filename = ''; |
| 12 |
$header = 'Classes'; |
| 13 |
if( isset($_GET['tab'] ) && sanitize_text_field($_GET['tab']) == 'addclass' ) { |
| 14 |
if($current_user_role=='administrator'){ |
| 15 |
$header = $label = __( 'Add New Class', 'wpschoolpress'); |
| 16 |
$filename = WPSP_PLUGIN_PATH .'includes/wpsp-classForm.php'; |
| 17 |
} |
| 18 |
}elseif((isset($_GET['id']) && is_numeric($_GET['id']))) { |
| 19 |
if($current_user_role=='administrator'){ |
| 20 |
$header = $label = __( 'Update Class', 'wpschoolpress'); |
| 21 |
$filename = WPSP_PLUGIN_PATH .'includes/wpsp-classForm.php'; |
| 22 |
} |
| 23 |
} |
| 24 |
if( !empty( $filename) ) { |
| 25 |
include_once ( $filename ); |
| 26 |
} else { |
| 27 |
?> |
| 28 |
<div class="wpsp-card"> |
| 29 |
<div class="wpsp-card-head"> |
| 30 |
<h3 class="wpsp-card-title"><?php esc_html_e( 'Class List', 'wpschoolpress' )?></h3> |
| 31 |
</div> |
| 32 |
<div class="wpsp-card-body"> |
| 33 |
<table class="wpsp-table" id="class_table" cellspacing="0" width="100%" style="width:100%"> |
| 34 |
<thead> |
| 35 |
<tr> |
| 36 |
<th class="nosort">#</th> |
| 37 |
<th><?php esc_html_e( 'Class Number', 'wpschoolpress' ); ?></th> |
| 38 |
<th><?php esc_html_e( 'Class Name', 'wpschoolpress' ); ?></th> |
| 39 |
<th><?php esc_html_e( 'Teacher Incharge', 'wpschoolpress' ); ?></th> |
| 40 |
<th><?php esc_html_e( 'Number of Students', 'wpschoolpress' ); ?></th> |
| 41 |
<th><?php esc_html_e( 'Capacity', 'wpschoolpress' ); ?></th> |
| 42 |
<th><?php esc_html_e( 'Location', 'wpschoolpress' ); ?></th> |
| 43 |
<?php if( $current_user_role=='administrator' ) { ?> <th class="nosort" align="center"><?php esc_html_e( 'Action', 'wpschoolpress' ); ?></th> <?php } ?> |
| 44 |
</tr> |
| 45 |
</thead> |
| 46 |
<tbody> |
| 47 |
<?php |
| 48 |
$ctable=$wpdb->prefix."wpsp_class"; |
| 49 |
$stable=$wpdb->prefix."wpsp_student"; |
| 50 |
$wpsp_classes =$wpdb->get_results("select * from $ctable order by cid DESC"); |
| 51 |
$sno=1; |
| 52 |
$teacher_table= $wpdb->prefix."wpsp_teacher"; |
| 53 |
$teacher_data = $wpdb->get_results("select wp_usr_id,CONCAT_WS(' ', first_name, middle_name, last_name ) AS full_name from $teacher_table order by tid"); |
| 54 |
$teacherlist = array(); |
| 55 |
if( !empty( $teacher_data ) ) { |
| 56 |
foreach( $teacher_data as $value ) |
| 57 |
$teacherlist[$value->wp_usr_id] = $value->full_name; |
| 58 |
} |
| 59 |
foreach ($wpsp_classes as $wpsp_class) { |
| 60 |
$cid=intval($wpsp_class->cid); |
| 61 |
$studentlists = $wpdb->get_results("select class_id, sid from $stable"); |
| 62 |
$stl = []; |
| 63 |
foreach ($studentlists as $stu) { |
| 64 |
if(is_numeric($stu->class_id) ){ |
| 65 |
if($stu->class_id == $cid){ |
| 66 |
$stl[] = $stu->sid; |
| 67 |
} |
| 68 |
}else{ |
| 69 |
$class_id_array = unserialize( $stu->class_id ); |
| 70 |
if(!empty($class_id_array)){ |
| 71 |
if(in_array($cid, $class_id_array)){ |
| 72 |
$stl[] = $stu->sid; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
$class_students_count = count($stl); |
| 78 |
$teach_id= intval($wpsp_class->teacher_id); |
| 79 |
$teachername = ''; |
| 80 |
?> |
| 81 |
<tr id="<?php echo esc_attr($wpsp_class->cid);?>" class="pointer"> |
| 82 |
<td><?php echo esc_html($sno);?><td><?php echo esc_html($wpsp_class->c_numb);?> </td> |
| 83 |
<td><?php echo esc_html($wpsp_class->c_name);?></td> |
| 84 |
<td><?php echo isset( $teacherlist[$teach_id] ) ? esc_html($teacherlist[$teach_id]) : '';?></td> |
| 85 |
<td><?php echo esc_html($class_students_count);?></td> |
| 86 |
<td><?php echo esc_html($wpsp_class->c_capacity);?></td> |
| 87 |
<td><?php echo esc_html($wpsp_class->c_loc);?></td> |
| 88 |
<?php if( $current_user_role=='administrator' ) { ?> |
| 89 |
<td align="center"> |
| 90 |
<div class="wpsp-action-col"> |
| 91 |
<a href="<?php echo esc_url(wpsp_admin_url().'sch-class&id='.esc_attr($wpsp_class->cid)."&edit=true");?>" title="Edit"> |
| 92 |
<i class="icon dashicons dashicons-edit wpsp-edit-icon"></i></a> |
| 93 |
<a href="javascript:;" id="d_teacher" class="wpsp-popclick" data-pop="DeleteModal" title="Delete" data-id="<?php echo esc_attr($wpsp_class->cid);?>" > |
| 94 |
<i class="icon dashicons dashicons-trash wpsp-delete-icon" data-id="<?php echo esc_attr($wpsp_class->cid);?>"></i> |
| 95 |
</a> |
| 96 |
</div> |
| 97 |
</td> |
| 98 |
<?php } ?> |
| 99 |
</tr> |
| 100 |
<?php |
| 101 |
$sno++; |
| 102 |
} |
| 103 |
?> |
| 104 |
</tbody> |
| 105 |
</table> |
| 106 |
</div> |
| 107 |
</div> |
| 108 |
<?php } if( $current_user_role=='administrator' ) { ?> |
| 109 |
<?php } |
| 110 |
wpsp_body_end(); |
| 111 |
wpsp_footer(); |
| 112 |
}else if($current_user_role=='parent' || $current_user_role='student'){ |
| 113 |
wpsp_topbar(); |
| 114 |
wpsp_sidebar(); |
| 115 |
wpsp_body_start(); |
| 116 |
?> |
| 117 |
<div class="wpsp-row"> |
| 118 |
<div class="wpsp-col-md-12"> |
| 119 |
<div class="wpsp-card"> |
| 120 |
<div class="wpsp-card-head ui-sortable-handle"> |
| 121 |
<h3 class="wpsp-card-title"><?php esc_html_e( 'Classe Details', 'wpschoolpress' )?> </h3> |
| 122 |
</div> |
| 123 |
<div class="wpsp-card-body"> |
| 124 |
<table id="class_table" class="wpsp-table wpsp-table-bordered wpsp-table-striped" cellspacing="0" width="100%" style="width:100%"> |
| 125 |
<thead> |
| 126 |
<tr> |
| 127 |
<th class="nosort">#</th> |
| 128 |
<th><?php esc_html_e( 'Class Number', 'wpschoolpress' ); ?></th> |
| 129 |
<th><?php esc_html_e( 'Class Name', 'wpschoolpress' ); ?></th> |
| 130 |
<th><?php esc_html_e( 'Teacher Incharge', 'wpschoolpress' ); ?></th> |
| 131 |
<th><?php esc_html_e( 'Number of Students', 'wpschoolpress' ); ?></th> |
| 132 |
<th><?php esc_html_e( 'Location', 'wpschoolpress' ); ?></th> |
| 133 |
</tr> |
| 134 |
</thead> |
| 135 |
<tbody> |
| 136 |
<?php |
| 137 |
$ctable=$wpdb->prefix."wpsp_class"; |
| 138 |
$stable=$wpdb->prefix."wpsp_student"; |
| 139 |
$teacher_table= $wpdb->prefix."wpsp_teacher"; |
| 140 |
$teacher_data = $wpdb->get_results("select wp_usr_id,CONCAT_WS(' ', first_name, middle_name, last_name ) AS full_name from $teacher_table order by tid"); |
| 141 |
$teacherlist = array(); |
| 142 |
if( !empty( $teacher_data ) ) { |
| 143 |
foreach( $teacher_data as $value ) |
| 144 |
$teacherlist[$value->wp_usr_id] = $value->full_name; |
| 145 |
} |
| 146 |
if( $current_user_role=='student' ) { |
| 147 |
// $wpsp_classes =$wpdb->get_results("SELECT cls.* FROM $ctable cls, $stable st where st.wp_usr_id = '".esc_sql($current_user->ID)."' AND st.class_id=cls.cid"); |
| 148 |
// $wpsp_classes = $wpdb->get_results($wpdb->prepare("SELECT cls.* FROM $ctable cls, $stable st WHERE st.wp_usr_id = %d AND st.class_id=cls.cid",$current_user->ID)); |
| 149 |
$wpsp_classes = $wpdb->get_results($wpdb->prepare("SELECT cls.* FROM $ctable AS cls INNER JOIN $stable AS st ON st.class_id = cls.cid WHERE st.wp_usr_id = %d",$current_user->ID)); |
| 150 |
} else { |
| 151 |
// $wpsp_classes =$wpdb->get_results("SELECT DISTINCT cls.* FROM $ctable cls, $stable st where st.parent_wp_usr_id = '".esc_sql($current_user->ID)."' AND st.class_id=cls.cid"); |
| 152 |
$wpsp_classes = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT cls.* FROM $ctable AS cls INNER JOIN $stable AS st ON st.class_id = cls.cid WHERE st.parent_wp_usr_id = %d",$current_user->ID)); |
| 153 |
} |
| 154 |
$sno=1; |
| 155 |
foreach ($wpsp_classes as $wpsp_class){ |
| 156 |
$cid = intval($wpsp_class->cid); |
| 157 |
//$class_students_count = $wpdb->get_var( "SELECT COUNT(`wp_usr_id`) FROM $stable WHERE class_id = '".esc_sql($cid)."'" ); |
| 158 |
$class_students_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(`wp_usr_id`) FROM $stable WHERE class_id = %d",$cid)); |
| 159 |
$teach_id= intval($wpsp_class->teacher_id); |
| 160 |
$teacher=get_userdata($teach_id); |
| 161 |
?> |
| 162 |
<tr id="<?php echo esc_attr($wpsp_class->cid);?>" class="pointer"> |
| 163 |
<td><?php echo esc_html($sno);?><td><?php echo esc_html($wpsp_class->c_numb);?> </td> |
| 164 |
<td><?php echo esc_html($wpsp_class->c_name);?></td> |
| 165 |
<td><?php echo isset( $teacherlist[$teach_id] ) ? esc_html($teacherlist[$teach_id]) : '';?></td> |
| 166 |
<td><?php echo esc_html($class_students_count);?></td> |
| 167 |
<td><?php echo esc_html($wpsp_class->c_loc);?></td> |
| 168 |
</tr> |
| 169 |
<?php |
| 170 |
$sno++; |
| 171 |
} |
| 172 |
?> |
| 173 |
</tbody> |
| 174 |
</table> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
</div> |
| 178 |
</div> |
| 179 |
<?php |
| 180 |
wpsp_body_end(); |
| 181 |
wpsp_footer(); |
| 182 |
} |
| 183 |
}else{ |
| 184 |
include_once( WPSP_PLUGIN_PATH .'/includes/wpsp-login.php'); |
| 185 |
} |
| 186 |
?> |