| 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 |
?> |
| 12 |
<?php |
| 13 |
if (isset($_GET['tab']) && sanitize_text_field($_GET['tab']) == 'addteacher') { |
| 14 |
if ($current_user_role == 'administrator') { |
| 15 |
include_once(WPSP_PLUGIN_PATH . '/includes/wpsp-teacherForm.php'); |
| 16 |
} |
| 17 |
} else if (isset($_GET['id']) && is_numeric($_GET['id'])) { |
| 18 |
if ($current_user_role == 'administrator') { |
| 19 |
include_once(WPSP_PLUGIN_PATH . '/includes/wpsp-teacherProfile.php'); |
| 20 |
} |
| 21 |
} else { |
| 22 |
include_once(WPSP_PLUGIN_PATH . '/includes/wpsp-teacherList.php'); |
| 23 |
?> |
| 24 |
<?php do_action('wpsp_teacher_import_html'); ?> |
| 25 |
<?php |
| 26 |
} |
| 27 |
wpsp_body_end(); |
| 28 |
wpsp_footer(); |
| 29 |
} |
| 30 |
if ($current_user_role == 'parent' || $current_user_role == 'student') { |
| 31 |
wpsp_topbar(); |
| 32 |
wpsp_sidebar(); |
| 33 |
wpsp_body_start(); |
| 34 |
$ID = intval($current_user->ID); |
| 35 |
$teacher_table = $wpdb->prefix . "wpsp_teacher"; |
| 36 |
$class_table = $wpdb->prefix . "wpsp_class"; |
| 37 |
$subjects_table = $wpdb->prefix . "wpsp_subject"; |
| 38 |
$student_table = $wpdb->prefix . "wpsp_student"; |
| 39 |
$queryFiels = $current_user_role == 'student' ? 'wp_usr_id' : 'parent_wp_usr_id'; |
| 40 |
$classlist = array(); |
| 41 |
$classquery = ''; |
| 42 |
|
| 43 |
$ciid = sanitize_text_field(stripslashes($_GET['cid'])); |
| 44 |
$classID = esc_sql(base64_decode($ciid)); |
| 45 |
|
| 46 |
?> |
| 47 |
<div class="wpsp-card"> |
| 48 |
<div class="wpsp-card-head"> |
| 49 |
<h3 class="wpsp-card-title"><?php esc_html_e('Teachers Details', 'wpschoolpress'); ?> </h3> |
| 50 |
</div> |
| 51 |
<div class="wpsp-card-body"> |
| 52 |
<table id="teacher_table" class="wpsp-table"> |
| 53 |
<thead> |
| 54 |
<tr> |
| 55 |
<th class="nosort">#</th> |
| 56 |
<th><?php esc_html_e('Full Name', 'wpschoolpress'); ?></th> |
| 57 |
<th><?php esc_html_e('Incharge of Class', 'wpschoolpress'); ?></th> |
| 58 |
<th><?php esc_html_e('Subjects Handling', 'wpschoolpress'); ?></th> |
| 59 |
<th><?php esc_html_e('Phone', 'wpschoolpress'); ?></th> |
| 60 |
</tr> |
| 61 |
</thead> |
| 62 |
<tbody> |
| 63 |
<?php |
| 64 |
if (!empty($classID)) { |
| 65 |
|
| 66 |
// $classquery = 'AND c.cid=' . esc_sql($classID); |
| 67 |
|
| 68 |
// $sub_han = $wpdb->get_results("select sub_name, sub_teach_id, c.c_name from $subjects_table s, $class_table c where sub_teach_id > 0 AND c.cid = s.class_id $classquery order by c.cid"); |
| 69 |
|
| 70 |
$classquery = 'AND c.cid = %d'; |
| 71 |
|
| 72 |
$sub_han = $wpdb->get_results( |
| 73 |
$wpdb->prepare( |
| 74 |
"SELECT sub_name, sub_teach_id, c.c_name |
| 75 |
FROM $subjects_table s, $class_table c |
| 76 |
WHERE sub_teach_id > 0 |
| 77 |
AND c.cid = s.class_id |
| 78 |
$classquery |
| 79 |
ORDER BY c.cid", |
| 80 |
$classID |
| 81 |
) |
| 82 |
); |
| 83 |
|
| 84 |
if (!empty($sub_han)) { |
| 85 |
foreach ($sub_han as $subhan) { |
| 86 |
$sub_handling[$subhan->sub_teach_id][] = $subhan->sub_name . ' (' . $subhan->c_name . ')'; |
| 87 |
$teacher[] = $subhan->sub_teach_id; |
| 88 |
} |
| 89 |
} else { |
| 90 |
$teacher[] = '0'; |
| 91 |
} |
| 92 |
|
| 93 |
// $incharges = $wpdb->get_results("select c.c_name,c.teacher_id from $class_table c LEFT JOIN $teacher_table t ON t.wp_usr_id=c.teacher_id where c.teacher_id>0 $classquery"); |
| 94 |
|
| 95 |
$incharges = $wpdb->get_results( |
| 96 |
$wpdb->prepare( |
| 97 |
"SELECT c.c_name, c.teacher_id |
| 98 |
FROM $class_table c |
| 99 |
LEFT JOIN $teacher_table t ON t.wp_usr_id = c.teacher_id |
| 100 |
WHERE c.teacher_id > 0 |
| 101 |
$classquery", |
| 102 |
$classID |
| 103 |
) |
| 104 |
); |
| 105 |
|
| 106 |
foreach ($incharges as $incharge) { |
| 107 |
$cincharge[$incharge->teacher_id][] = $incharge->c_name; |
| 108 |
} |
| 109 |
// if (!empty($teacher) && !empty($classID)) { |
| 110 |
// $teacherQuery = ' WHERE wp_usr_id IN (' . implode(", ", $teacher) . ') '; |
| 111 |
// } |
| 112 |
// $teachers = $wpdb->get_results("select * from $teacher_table $teacherQuery order by tid DESC"); |
| 113 |
if (!empty($teacher) && !empty($classID)) { |
| 114 |
$teacherPlaceholders = implode(', ', array_fill(0, count($teacher), '%d')); |
| 115 |
$teacherQuery = ' WHERE wp_usr_id IN (' . $teacherPlaceholders . ')'; |
| 116 |
|
| 117 |
$teachers = $wpdb->get_results( |
| 118 |
$wpdb->prepare( |
| 119 |
"SELECT * FROM $teacher_table $teacherQuery ORDER BY tid DESC", |
| 120 |
$teacher |
| 121 |
) |
| 122 |
); |
| 123 |
} else { |
| 124 |
$teachers = $wpdb->get_results("SELECT * FROM $teacher_table ORDER BY tid DESC"); |
| 125 |
} |
| 126 |
|
| 127 |
$sno = 0; |
| 128 |
|
| 129 |
foreach ($teachers as $tinfo) { |
| 130 |
$loc_avatar = get_user_meta($tinfo->wp_usr_id, 'simple_local_avatar', true); |
| 131 |
$img_url = $loc_avatar ? sanitize_text_field($loc_avatar['full']) : WPSP_PLUGIN_URL . 'img/avatar.png'; |
| 132 |
$sno = $sno + 1; |
| 133 |
?> |
| 134 |
<tr> |
| 135 |
<td><?php echo esc_html($sno); ?></td> |
| 136 |
<td><?php echo esc_html($tinfo->first_name . " " . $tinfo->middle_name . " " . $tinfo->last_name); ?></td> |
| 137 |
<td><?php if (isset($cincharge[$tinfo->wp_usr_id])) { |
| 138 |
echo esc_html(implode(", ", $cincharge[$tinfo->wp_usr_id])); |
| 139 |
} else { |
| 140 |
echo '-'; |
| 141 |
} ?></td> |
| 142 |
<td><?php if (isset($sub_handling[$tinfo->wp_usr_id])) { |
| 143 |
echo esc_html(implode(", ", $sub_handling[$tinfo->wp_usr_id])); |
| 144 |
} else { |
| 145 |
echo '-'; |
| 146 |
} ?></td> |
| 147 |
<td><?php echo esc_html($tinfo->phone); ?></td> |
| 148 |
</tr> |
| 149 |
<?php } ?> |
| 150 |
<?php } ?> |
| 151 |
</tbody> |
| 152 |
<tfoot> |
| 153 |
<tr> |
| 154 |
<th>#</th> |
| 155 |
<th><?php esc_html_e('Full Name', 'wpschoolpress'); ?></th> |
| 156 |
<th><?php esc_html_e('Incharge of Class', 'wpschoolpress'); ?></th> |
| 157 |
<th><?php esc_html_e('Subjects Handling', 'wpschoolpress'); ?></th> |
| 158 |
<th><?php esc_html_e('Phone', 'wpschoolpress'); ?></th> |
| 159 |
</tr> |
| 160 |
</tfoot> |
| 161 |
</table> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
<?php |
| 165 |
wpsp_body_end(); |
| 166 |
wpsp_footer(); |
| 167 |
} ?> |
| 168 |
<div class="wpsp-popupMain" id="ViewModal"> |
| 169 |
<div class="wpsp-overlayer"></div> |
| 170 |
<div class="wpsp-popBody"> |
| 171 |
<div class="wpsp-popInner"> |
| 172 |
<a href="javascript:;" class="wpsp-closePopup"></a> |
| 173 |
<div id="ViewModalContent"> |
| 174 |
</div> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
</div> |
| 178 |
<?php |
| 179 |
} else { |
| 180 |
include_once(WPSP_PLUGIN_PATH . '/includes/wpsp-login.php'); |
| 181 |
} |
| 182 |
?> |