query("SELECT *,r.id as marksheet_id FROM results as r,students as s where r.roll_no = '".$_POST['roll_no']."' and r.status = 1 AND s.enrollment_no = r.enrollment_no"); $return = ['status' => false,'html' => '']; if($num = $result->num_rows) { if($num == 0){ $return['html'] = '
Result Not Found.
'; } else if($num == 1){ $return['status'] = true; $return['html'] = 'single hai'; $return['marksheet_url'] = marksheet_url($result->fetch_assoc()['marksheet_id']); } else{ $return['status'] = true; $return['html'] = '

Marksheet List

'; while($row = $result->fetch_assoc()){ $return['html'] .= ''; } $return['html'] .= '
MarksheetAction
'.$row['duration'].' '.ucfirst($row['duration_type']).' Result View
'; } } else $return['html'] = '
Result Not Found
'; echo json_encode($return); break; case 'useItems': $page_id =$post['page_id']; $type = $post['type']; $chk = $con->query("SELECT * FROM `web_schema` WHERE `page_id` = '".$post['page_id']."' AND `type` = '".$post['type']."' "); if($chk->num_rows){ $con->query("DELETE FROM `web_schema` WHERE `page_id` = '$page_id' AND `type` = '$type'"); }else{ $query = $con->query("INSERT INTO `web_schema` (`type`, `page_id`) VALUES ('$type','$page_id')"); if(!$query){ print_r($con->error);exit; } } echo 1; break; case 'extra_setting': unset($post['status']); unset($post['type']); $query = false; $hasFile = false; if(!empty($_FILES)){ foreach($_FILES as $key => $file){ if($file['error'] == 0 && !empty($file['name']) && $file['size'] > 0){ $logo = photo_upload($key, 'files'); if($logo['status'] == 1 && !empty($logo['file_name'])){ $val = $logo['file_name']; $hasFile = true; $chk = $con->query("SELECT * FROM `setting` WHERE `type` = '$key' ")->num_rows; if($chk){ $query = $con->query("UPDATE `setting` SET `value`= '$val' WHERE `type` = '$key' "); }else{ $query = $con->query("INSERT INTO `setting`(`type`, `value`) VALUES ('$key','$val')"); } } } } } foreach($post as $key => $val){ if(!empty($key) && $key != 'type'){ $chk = $con->query("SELECT * FROM `setting` WHERE `type` = '$key' ")->num_rows; if($chk){ $query = $con->query("UPDATE `setting` SET `value`= '$val' WHERE `type` = '$key' "); }else{ $query = $con->query("INSERT INTO `setting`(`type`, `value`) VALUES ('$key','$val')"); } } } if($query){ $res = 'Successfully Saved'; }else{ $res = 'Something went wrong'; } echo json_encode($res); break; case 'Add_Menu': $chk = $con->query("SELECT * FROM menu where name = '".$post['name']."'"); if(!($chk->num_rows)) { $con->query("INSERT INTO `menu` (`id`, `timestamp`, `name`) VALUES (NULL, CURRENT_TIMESTAMP, '".$post['name']."')"); echo '1'; } else { echo '0'; } break; case 'deleteRow': $id = $post['id']; $table = $post['table']; $query = $con->query("DELETE FROM $table WHERE `id` = '$id'"); if($query){ $res = 'Successfully Deleted'; }else{ $res = 'Something went wrong'; } echo json_encode($res); break; case 'change_seq_of_sliders': $return['status'] = true; foreach($post['order'] as $k => $id) $con->query("UPDATE `gallery_category` SET `seq` = ($k+1) WHERE `gallery_category`.`id` = '".$id."'"); $return['text'] = 'Order successfully Change.'; $return['class_name'] = 'success'; echo json_encode($return); break; case 'change_seq_of_gallery': $return['status'] = true; foreach($post['order'] as $k => $id) $con->query("UPDATE `gallery` SET `seq` = ($k+1) WHERE `gallery`.`id` = '".$id."'"); $return['text'] = 'Order successfully Change.'; $return['class_name'] = 'success'; echo json_encode($return); break; case 'Check_Login': $post = $_POST; if ($_SESSION['digit'] == $post['digit']) { $username = mysqli_real_escape_string($con, $post['username']); $password = mysqli_real_escape_string($con, $post['password']); $stmt = $con->prepare("SELECT id, type FROM login WHERE username = ? AND password = ?"); $stmt->bind_param("ss", $username, md5($password)); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows > 0) { $stmt->bind_result($id, $type); $stmt->fetch(); $rand = rand(111111, 999999); $_SESSION['admin']['id'] = $id; $_SESSION['admin']['session_id'] = $rand; $_SESSION['admin']['login'] = true; $_SESSION['admin']['type'] = $type; $con->query("INSERT INTO `check_session` (`id`, `timestamp`, `user_id`, `session_id`) VALUES (NULL, CURRENT_TIMESTAMP, '$id', '$rand')"); session_regenerate_id(true); echo json_encode(1); } else { echo json_encode(0); } $stmt->close(); } else { echo json_encode(2); } break; case 'get_city': $state_id = mysqli_real_escape_string($con, $post['state_id']); $get = $con->query("SELECT * FROM city where state_id = '$state_id' ORDER BY city_name ASC"); if($get->num_rows > 0) { echo ''; while($g = $get->fetch_assoc()) { echo ''; } } else { echo ''; } break; case 'get_city2': $state_id = mysqli_real_escape_string($con, $post['state_id']); $get = $con->query("SELECT * FROM city where state_id = '$state_id' ORDER BY city_name ASC"); if($get->num_rows > 0) { echo ''; while($g = $get->fetch_assoc()) { echo ''; } } else { echo ''; } break; case 'get_subjects': echo ''; $i=1; $get = $con->query("SELECT * FROM subjects where course_id = '".$post['course_id']."' ORDER BY is_optional ASC, subject_name ASC"); if($get->num_rows > 0) { while($g = $get->fetch_assoc()) { $type_badge = $g['is_optional'] ? 'Optional' : 'Compulsory'; echo ' '; } } else { echo ''; } echo '
# Subject Name Marks Type Edit Remove
Max Min
'.$i++.' '.ucwords($g['subject_name']).' '.$g['max_marks'].' '.$g['min_marks'].' '.$type_badge.'
No subjects found
'; break; case 'update_subject': $is_optional = isset($_POST['is_optional']) ? 1 : 0; $con->query("UPDATE `subjects` SET `max_marks` = '".$_POST['max_marks']."', min_marks = '".$_POST['min_marks']."', subject_name = '".$_POST['subject_name']."', code = '".$_POST['code']."', is_optional = '$is_optional' WHERE `subjects`.`id` = '".$_POST['id']."'"); echo 1; break; // ============================================= // FIXED: subjects case for create_result.php // ============================================= case 'subjects': header('Content-Type: application/json'); $course_id = mysqli_real_escape_string($con, $post['course_id'] ?? ''); $duration_type = mysqli_real_escape_string($con, $post['duration_type'] ?? ''); $duration = mysqli_real_escape_string($con, $post['duration'] ?? ''); $enrollment_no = mysqli_real_escape_string($con, $post['enrollment_no'] ?? ''); // Debug log error_log("Subjects Request - Course: $course_id, Duration: $duration, Type: $duration_type"); // Get subjects for this course (without duration filter first to check) $get = $con->query("SELECT * FROM subjects WHERE course_id = '$course_id' ORDER BY is_optional ASC, subject_name ASC"); // If no subjects found with course_id only, try with duration filter if(!$get || $get->num_rows == 0) { $get = $con->query("SELECT * FROM subjects WHERE course_id = '$course_id' AND duration = '$duration' AND duration_type = '$duration_type' ORDER BY is_optional ASC, subject_name ASC"); } if($get && $get->num_rows > 0) { $html = '
'; $html .= '
'; $html .= '
'; $html .= '

Subject Marks Entry

'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $i = 1; while($subject = $get->fetch_assoc()) { $type_badge = $subject['is_optional'] ? 'Optional' : 'Compulsory'; $type_class = $subject['is_optional'] ? 'warning' : 'info'; $max_marks = $subject['max_marks'] ? $subject['max_marks'] : 100; $min_marks = $subject['min_marks'] ? $subject['min_marks'] : 33; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $i++; } $html .= ''; $html .= '
S.No.Subject NameCodeTypeMax MarksMin MarksObtained Marks
' . $i . ''; $html .= '' . htmlspecialchars($subject['subject_name']) . ''; $html .= ''; $html .= '' . ($subject['code'] ? htmlspecialchars($subject['code']) : 'N/A') . '' . $type_badge . '' . $max_marks . '' . $min_marks . ''; $html .= ''; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; echo json_encode([ 'html' => $html, 'success' => true, 'count' => $get->num_rows ]); } else { // No subjects found $html = '
'; $html .= '
'; $html .= ' '; $html .= 'No subjects found for this course and duration.'; $html .= '
Course ID: ' . $course_id . ', Duration: ' . $duration . ' ' . $duration_type . ''; $html .= '
Please add subjects for this course first.'; $html .= '
'; $html .= '
'; echo json_encode([ 'html' => $html, 'success' => false, 'error' => 'No subjects found', 'course_id' => $course_id, 'duration' => $duration, 'duration_type' => $duration_type ]); } break; case 'fetch_student_details': $enrollmentNo = $_POST['enrollment_no']; $studentDetails = fetchStudentDetails($enrollmentNo); echo $studentDetails; break; // ============================================= // FIXED: get_roll case - Complete rewrite // ============================================= case 'get_roll': header('Content-Type: application/json'); $enrollment_no = mysqli_real_escape_string($con, $post['enrollment_no'] ?? ''); if(empty($enrollment_no)) { echo json_encode(['success' => false, 'error' => 'No enrollment number provided']); exit; } // First try: Get student details from students table with course info $student_query = $con->query(" SELECT s.*, c.course_name, c.id as course_id, c.duration as course_duration, c.duration_type as course_duration_type FROM students s LEFT JOIN courses c ON s.course_id = c.id WHERE s.enrollment_no = '$enrollment_no' AND s.status = '1' "); if($student_query && $student_query->num_rows > 0) { $stu = $student_query->fetch_assoc(); // Count existing results for this student $result_count = $con->query("SELECT COUNT(*) as total FROM results WHERE enrollment_no = '$enrollment_no'"); $count = $result_count->fetch_assoc(); $response = array( 'success' => true, 'roll' => $stu['roll_no'] ?? '', 'roll_no' => $stu['roll_no'] ?? '', 'course_id' => $stu['course_id'] ?? '', 'course_name' => $stu['course_name'] ?? 'Not Assigned', 'duration' => $stu['course_duration'] ?? $stu['duration'] ?? 1, 'duration_type' => $stu['course_duration_type'] ?? $stu['duration_type'] ?? 'year', 'result' => $count['total'] ?? 0, 'student_name' => $stu['name'] ?? $stu['student_name'] ?? '' ); echo json_encode($response); exit; } // Second try: Get from admit_card table $admit_query = $con->query(" SELECT a.*, c.course_name, c.id as course_id, c.duration, c.duration_type FROM admit_card a LEFT JOIN courses c ON a.course_id = c.id WHERE a.enrollment_no = '$enrollment_no' LIMIT 1 "); if($admit_query && $admit_query->num_rows > 0) { $adm = $admit_query->fetch_assoc(); $result_count = $con->query("SELECT COUNT(*) as total FROM results WHERE enrollment_no = '$enrollment_no'"); $count = $result_count->fetch_assoc(); $response = array( 'success' => true, 'roll' => $adm['roll_no'] ?? '', 'roll_no' => $adm['roll_no'] ?? '', 'course_id' => $adm['course_id'] ?? '', 'course_name' => $adm['course_name'] ?? 'Not Assigned', 'duration' => $adm['duration'] ?? 1, 'duration_type' => $adm['duration_type'] ?? 'year', 'result' => $count['total'] ?? 0, 'student_name' => '' ); echo json_encode($response); exit; } // Third try: Get from certificate_requests or any other table that has enrollment $cert_query = $con->query(" SELECT * FROM certificate_requests WHERE enrollment_no = '$enrollment_no' LIMIT 1 "); if($cert_query && $cert_query->num_rows > 0) { $cert = $cert_query->fetch_assoc(); $response = array( 'success' => true, 'roll' => $cert['roll_no'] ?? '', 'roll_no' => $cert['roll_no'] ?? '', 'course_id' => $cert['course_id'] ?? '', 'course_name' => 'From Certificate', 'duration' => $cert['duration'] ?? 1, 'duration_type' => $cert['duration_type'] ?? 'year', 'result' => 0, 'student_name' => $cert['student_name'] ?? '' ); echo json_encode($response); exit; } // Student not found anywhere echo json_encode([ 'success' => false, 'error' => 'Student not found or inactive. Enrollment: ' . $enrollment_no, 'roll' => '', 'roll_no' => '', 'course_id' => '', 'course_name' => '', 'duration' => 1, 'duration_type' => 'year', 'result' => 0 ]); break; case 'course_fee': $get = $con->query("SELECT * FROM courses where id = '".$post['course_id']."'")->fetch_assoc(); echo $get['fee']; break; case 'get-admit-details': $get = $con->query("SELECT * FROM admit_card WHERE id = '".$post['id']."'"); echo json_encode($get->fetch_assoc()); break; case 'update-admit-card-details': $con->query("UPDATE `admit_card` SET exam_center = '".$post['exam_center']."', exam_date = '".$post['exam_date']."', exam_time = '".$post['exam_time']."', session = '".$post['session']."', exam_held = '".$post['exam_held']."', year = '".$post['year']."' WHERE `admit_card`.`id` = '".$post['id']."'"); echo json_encode(['status' => true]); break; case 'get_courses': $get = $con->query("SELECT * FROM students where enrollment_no = '".$post['enrollment_no']."'")->fetch_assoc(); $c = $con->query("SELECT * FROM courses where id = '".$get['course_id']."'")->fetch_assoc(); $option = ''; $message = ' '; if($c['duration_type'] == 'month'){ $checkAdmit = $con->query("SELECT * FROM admit_card WHERE enrollment_no = '".$post['enrollment_no']."' and course_id = '".$get['course_id']."' and duration = '".$c['duration']."' and duration_type = '".$c['duration_type']."' "); $option .= ''; if($checkAdmit->num_rows) $message = '
'.$c['duration'].' '.ucfirst($c['duration_type']).' admit card created..
'; } else{ $selectedSet = false; for($i = 1; $i <= $c['duration']; $i++){ $checkAdmit = $con->query("SELECT * FROM admit_card WHERE enrollment_no = '".$post['enrollment_no']."' and course_id = '".$get['course_id']."' and duration = '".$i."' and duration_type = '".$c['duration_type']."' "); if($checkAdmit->num_rows) $option .= ''; else{ if (!$selectedSet) { $option .= ''; $selectedSet = true; } else { $option .= ''; } } if($checkAdmit->num_rows) $message .= '
'.$i.' '.ucfirst($c['duration_type']).' admit card created..
'; } } echo json_encode([ 'course_id' => $c['id'], 'course_name' => $c['course_name'], 'message' => $message, 'option' => $option ]); break; case 'get-subject-list': $course_id = $_POST['course_id']; $duration = $_POST['duration']; $duration_type = $_POST['duration_type']; $getSubjects = $con->query("SELECT * FROM subjects WHERE course_id = '$course_id' and duration = '$duration' and duration_type = '$duration_type' ORDER BY is_optional ASC, subject_name ASC"); $html = '
'; if($getSubjects->num_rows){ $html .= ''; $date = date('Y-m-d'); while($sub = $getSubjects->fetch_assoc()){ $date = date('Y-m-d',strtotime($date." +1 day")); $type_badge = $sub['is_optional'] ? 'Optional' : 'Compulsory'; $html .= ''; } $html .= '
Code Subject Name Type Date Start Time End Time
'.$sub['code'].' '.$sub['subject_name'].' '.$type_badge.'
'; } else $html .= '
Subjects are not found of this course..
'; $html .= '
'; echo json_encode(['html' => $html]); break; case 'contact_us': $state_id = mysqli_real_escape_string($con, $_POST['state']); $city_id = mysqli_real_escape_string($con, $_POST['city']); if(!is_numeric($city_id) && !empty($city_id)) { $checkCity = $con->query("SELECT id FROM city WHERE city_name = '$city_id' AND state_id = '$state_id'"); if($checkCity->num_rows > 0) { $cityData = $checkCity->fetch_assoc(); $city_id = $cityData['id']; } else { $con->query("INSERT INTO city (state_id, city_name) VALUES ('$state_id', '$city_id')"); $city_id = $con->insert_id; } } $get = $con->query("INSERT INTO `contact_query` (`id`, `timestamp`, `name`, `mobile`, `email`, `state_id`,`city_id`) VALUES (NULL, current_timestamp(),'".$_POST['name']."', '".$_POST['mobile']."', '".$_POST['email']."', '$state_id','$city_id') "); echo json_encode(['status' => $get ? true : false, 'message' => $get ? 'Query submitted successfully' : 'Error submitting query']); break; } /** * Photo upload function */ function photo_upload($file, $path) { $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", strtolower($_FILES[$file]["name"])); $extension = end($temp); $return = array('status' => 0); if ((($_FILES[$file]["type"] == "image/gif") || ($_FILES[$file]["type"] == "image/jpeg") || ($_FILES[$file]["type"] == "image/jpg") || ($_FILES[$file]["type"] == "image/pjpeg") || ($_FILES[$file]["type"] == "image/x-png") || ($_FILES[$file]["type"] == "image/png")) && in_array($extension, $allowedExts)) { if ($_FILES[$file]["error"] > 0) { $return['error'] = 'Error Code: ' . $_FILES[$file]["error"]; } { $newfilename = time() . '_' . rand(1000, 9999) . '.' . $extension; $aa = 'product__' . $newfilename; $a = '../uploads/' . $path . '/' . $aa; if (move_uploaded_file($_FILES[$file]["tmp_name"], $a)) { $return['file_name'] = $aa; $return['status'] = 1; } else { $return['error'] = 'Failed to move uploaded file. Check folder permissions.'; } } } else { $return['error'] = 'Invalid file type. Allowed: ' . implode(', ', $allowedExts); } return $return; } ?>