';
}
// handle view/edit/hall request (simple)
if(isset($_GET['dc_view_candidate'])){
$cid = intval($_GET['dc_view_candidate']);
$c = $wpdb->get_row( $wpdb->prepare("SELECT * FROM {$wpdb->prefix}dc_candidates WHERE id = %d AND school_id = %d", $cid, $school_id) );
if($c){
$output .= '
Candidate Preview
';
$output .= '
Name: '.esc_html($c->student_name).'
';
$output .= '
Father: '.esc_html($c->father_name).'
';
$output .= '
Mother: '.esc_html($c->mother_name).'
';
$output .= '
Mobile: '.esc_html($c->mobile).'
';
$output .= '
Level: '.esc_html($c->level).'
';
if(!empty($c->photo)){
$photo_url = plugins_url('uploads/'.$c->photo, DC_PLUGIN_DIR.'../');
// better to serve uploads via plugin uploads or server uploads — adjust path if needed
$output .= '
';
}
$output .= '';
} else {
$output .= '
Candidate not found or you do not have permission.
';
}
}
// Edit handling: redirect to edit form page or display inline form
if(isset($_GET['dc_edit_candidate'])){
$cid = intval($_GET['dc_edit_candidate']);
$c = $wpdb->get_row( $wpdb->prepare("SELECT * FROM {$wpdb->prefix}dc_candidates WHERE id = %d AND school_id = %d", $cid, $school_id) );
if($c){
// if POST update
if(isset($_POST['dc_update_candidate']) && intval($_POST['candidate_id']) == $cid){
$wpdb->update(
$wpdb->prefix.'dc_candidates',
array(
'student_name' => sanitize_text_field($_POST['student_name']),
'father_name' => sanitize_text_field($_POST['father_name']),
'mother_name' => sanitize_text_field($_POST['mother_name']),
'mobile' => sanitize_text_field($_POST['mobile']),
'district' => sanitize_text_field($_POST['district']),
'dob' => sanitize_text_field($_POST['dob']),
'gender' => sanitize_text_field($_POST['gender']),
'level' => sanitize_text_field($_POST['level'])
),
array('id' => $cid)
);
$output .= '
Candidate updated successfully.
';
// refresh candidate data
$c = $wpdb->get_row( $wpdb->prepare("SELECT * FROM {$wpdb->prefix}dc_candidates WHERE id = %d", $cid) );
}
// edit form
$output .= '
Edit Candidate
';
$output .= '';
} else {
$output .= '
Candidate not found or you do not have permission.