EVOLUTION-NINJA
Edit File: New_Project.php
<?php namespace App\Controllers; use DateTime; use DateTimeZone; use App\Models\New_Model; use App\Models\Amcad_Home; use CodeIgniter\I18n\Time; use App\Models\Chapter_material; use App\Models\InstructorModel; use App\Models\Courses_Model; use App\Models\Faculty_Model; use App\Models\Training_Model; use App\Models\Subject_Model; use App\Models\Nparrots_Model; use App\Models\Topics_Model; use App\Models\Batch_Model; use ResponseTrait; use CodeIgniter\Controller; use CodeIgniter\Email\Email; use CodeIgniter\Config\Services; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; use PhpOffice\PhpSpreadsheet\IOFactory; use TCPDF\TCPDF; use Config\Database; class New_Project extends BaseController { public function __construct() { $nparrotsModel = new New_Model(); $this->db = \Config\Database::connect(); } public function cart_details() { $session = session(); $login_id = $session->get('user_login_id'); if ($login_id) { $course_id = $this->request->uri->getSegment(2); $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $table = 'courses'; $nparrotsModel = new Amcad_Home(); $data['result'] = $nparrotsModel->getWhereRow($table, $where); $where1 = ['enroll_status' => 'ENROLLED', 'delete_status' => 'ACTIVE']; $table1 = 'user_course_mapping'; $order_by = 'mapping_id'; $data['enrol_result'] = $nparrotsModel->getWhereOrderbyRow($table1, $where1, $order_by); return view('user/preplannedbatches', $data); } else { return redirect()->to('/'); } } public function getUserLoginId() { $session = session(); return $session->get('user_login_id'); } public function add_course_to_db_cart() { $course_id = $this->request->getPost('course_id'); $course_title = $this->request->getPost('course_title'); $course_price = $this->request->getPost('course_price'); $batch_ids = $this->request->getPost('batch_id'); $faculty_ids = $this->request->getPost('faculty_id'); $c_batch_ids = json_encode(explode(',', $this->request->getPost('cookie_batch_ids'))); $c_faculty_ids = json_encode(explode(',', $this->request->getPost('cookie_faculty_ids'))); $sub_domain_ids = json_encode(explode(',', $this->request->getPost('cookie_subdomain_ids'))); $from_time = json_encode(explode(',', $this->request->getPost('cookie_fromtime_ids'))); $to_time = json_encode(explode(',', $this->request->getPost('cookie_totime_ids'))); $session = json_encode(explode(',', $this->request->getPost('cookie_session_ids'))); $bid = (!empty($batch_ids)) ? $batch_ids[0] : null; $table = "batches"; $where = ['batch_id' => $bid]; $nparrotsModel = new New_Model(); $get_data = $nparrotsModel->get_where_row($where, $table); $table1 = "user_course_mapping"; $where1 = ['batch_ids' => json_encode($batch_ids)]; $get_data1 = $nparrotsModel->number_rows($table1, $where1); if (empty($batch_ids) && empty($faculty_ids)) { return $this->response->setJSON(['result' => 3, 'message' => "Choose batch or faculty"]); } elseif (!empty($batch_ids) && !empty($faculty_ids)) { return $this->response->setJSON(['result' => 3, 'message' => "Choose batch or faculty"]); } elseif (empty($get_data)) { $table = 'course_cart'; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $user_id = session()->get('user_login_id'); $data = [ 'user_id' => $user_id, 'course_id' => $course_id, 'course_price' => $course_price, 'batch_ids' => json_encode($batch_ids), 'faculty_ids' => json_encode($faculty_ids), 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; if (!empty($faculty_ids)) { $data['sub_domain_ids'] = $sub_domain_ids; $data['from_time'] = $from_time; $data['to_time'] = $to_time; $data['session_type'] = $session; } elseif (!empty($batch_ids)) { $data['sub_domain_ids'] = $sub_domain_ids; $data['from_time'] = $from_time; $data['faculty_ids'] = $c_faculty_ids; $data['session_type'] = $session; } $where = ['user_id' => $user_id, 'course_id' => $course_id, 'delete_status' => 'ACTIVE']; $all_data = $nparrotsModel->get_where_result($table, $where); $array = []; $array1 = []; $mapping_table = 'user_course_mapping'; $where1 = [ 'user_id' => $user_id, 'course_id' => $course_id, 'delete_status' => 'ACTIVE', 'enroll_status' => 'ENROLLED', 'payment_status' => 'PAID', ]; $all_data1 = $nparrotsModel->get_where_result($mapping_table, $where1); $all_data = $nparrotsModel->get_where_result($table, $where); $array1 = []; foreach ($all_data1 as $value) { array_push($array1, strtolower($value->course_id)); } foreach ($all_data as $value) { array_push($array, strtolower($value->course_id)); } if (in_array($course_id, $array)) { return $this->response->setJSON(['result' => 3, 'message' => "Course already exists in your cart"]); } elseif (in_array($course_id, $array1)) { return $this->response->setJSON(['result' => 3, 'message' => "You have enrolled in this course"]); } else { $result = $nparrotsModel->insert_val($data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => "Course added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong"]); } } } elseif ($get_data->batch_size != $get_data1) { $table = 'course_cart'; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $user_id = session()->get('user_login_id'); $data = [ 'user_id' => $user_id, 'course_id' => $course_id, 'course_price' => $course_price, 'batch_ids' => json_encode($batch_ids), 'faculty_ids' => json_encode($faculty_ids), 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; if (!empty($faculty_ids)) { $data['sub_domain_ids'] = $sub_domain_ids; $data['from_time'] = $from_time; $data['to_time'] = $to_time; $data['session_type'] = $session; } elseif (!empty($batch_ids)) { $data['sub_domain_ids'] = $sub_domain_ids; $data['from_time'] = $from_time; $data['faculty_ids'] = $c_faculty_ids; $data['session_type'] = $session; } $where = ['user_id' => $user_id, 'course_id' => $course_id, 'delete_status' => 'ACTIVE']; $all_data = $nparrotsModel->get_where_result($table, $where); $array = []; $array1 = []; $mapping_table = 'user_course_mapping'; $where1 = [ 'user_id' => $user_id, 'course_id' => $course_id, 'delete_status' => 'ACTIVE', 'enroll_status' => 'ENROLLED', 'payment_status' => 'PAID', ]; $all_data1 = $nparrotsModel->get_where_result($mapping_table, $where1); $array1 = []; foreach ($all_data1 as $value) { array_push($array1, strtolower($value->course_id)); } foreach ($all_data as $value) { array_push($array, strtolower($value->course_id)); } if (in_array($course_id, $array)) { return $this->response->setJSON(['result' => 3, 'message' => "Course already exists in your cart"]); } elseif (in_array($course_id, $array1)) { return $this->response->setJSON(['result' => 3, 'message' => "You have enrolled in this course"]); } else { return $this->response->setJSON(['result' => 1, 'message' => "Course added successfully"]); } } else { return $this->response->setJSON(['result' => 3, 'message' => "Batch size has been exceeded"]); } } public function get_all_domains() { $table = 'domains'; $where = ['delete_status' => 'ACTIVE', 'user_type_id' => '1']; $order_by = 'domain_name'; $nparrotsModel = new New_Model(); $result = $nparrotsModel->get_where_result_orderby_asc($table, $where, $order_by); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function category_wise_courses() { $domain_id = $this->request->getPost('domain_id'); $table = 'domains'; $where = ['domain_id' => $domain_id, 'delete_status' => 'ACTIVE']; $nparrotsModel = new New_Model(); $domain_name = $nparrotsModel->where($where)->first(); $result = $nparrotsModel->get_category_courses($domain_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result, 'domains' => $domain_name]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_all_subdomains() { $id = $this->request->getPost('id'); $table = 'sub_domains'; $where = ['domain_id' => $id, 'delete_status' => 'ACTIVE']; $order_by = 'sub_domain'; $nparrotsModel = new New_Model(); $result = $nparrotsModel->get_where_result_orderby_asc($table, $where, $order_by); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_subdomain_wise_courses() { $sub_domain_id = $this->request->getPost('sub_domain_id'); $nparrotsModel = new New_Model(); $result = $nparrotsModel->get_subdomain_wise_courses($sub_domain_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function check_dashboard_access() { $login_id = $this->request->getPost('user_login_id'); $table = 'login'; $where = ['login_id' => $login_id]; $nparrots_model = new Amcad_Home(); $result = $nparrots_model->get_where_row($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'data' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_all_subdomains_courses() { $id = $this->request->getPost('id'); $nparrotsModel = new New_Model(); $result = $this->$nparrotsModel->get_subdomain_courses($id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function subject_wise_courses($sub_domain_id) { $data['sub_domain_id'] = $sub_domain_id; return view('user/subject_wise_courses', $data); } public function about_us() { echo view('user/aboutus'); } public function courses() { echo view('user/courses'); } public function privacy() { $table = 'courselist'; $nparrotsModel = new New_Model(); $data['course'] = $nparrotsModel->fetchData($table); echo view('user/privacy', $data); } public function terms_condition() { $table = 'courselist'; $nparrotsModel = new New_Model(); $data['course'] = $nparrotsModel->fetchData($table); echo view('user/termsconditions', $data); } public function refund_cancellation_policy() { $table = 'courselist'; $nparrotsModel = new New_Model(); $data['course'] = $nparrotsModel->fetchData($table); echo view('user/refund_cancellation_policy', $data); } public function contact() { echo view('user/contact'); } public function faq() { $table = 'courselist'; $nparrotsModel = new New_Model(); $data['course'] = $nparrotsModel->fetchData($table); echo view('user/faq', $data); } public function career() { $table = 'courselist'; $nparrotsModel = new New_Model(); $data['course'] = $nparrotsModel->fetchData($table); echo view('user/career', $data); } public function become_affiliate() { echo view('user/becomeaffiliate'); } public function recorded_lessons() { echo view('user/recorded'); } public function webinars() { echo view('user/webinars'); } public function get_user_db_cart_details() { $session = session(); $user_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); $cartResult = $nparrotsModel->get_cart_data_from_db($user_id); $array = []; foreach ($cartResult as $value) { $data = [ 'course_id' => $value->course_id, 'course_image' => $value->course_image, 'course_title' => $value->course_title, 'course_price' => $value->course_price, ]; if ($value->batch_ids != 'null') { $batches = json_decode($value->batch_ids); $batches = implode(',', $batches); $sql1 = "SELECT A.*, B.username FROM batches A, login B WHERE B.login_id = A.faculty_id AND A.batch_id IN ($batches) AND A.delete_status = 'ACTIVE'"; $result1 = $this->db->query($sql1)->getResult(); $data['faculty_batch'] = $result1; $data['selected_type'] = 'batch'; } else { $faculties = json_decode($value->faculty_ids); $fromTimes = json_decode($value->from_time); $toTimes = json_decode($value->to_time); $sessionTypes = json_decode($value->session_type); $array1 = []; foreach ($faculties as $index => $facultyId) { $sql1 = "SELECT A.username FROM login A WHERE A.login_id = '$facultyId' AND A.delete_status = 'ACTIVE'"; $result1 = $this->db->query($sql1)->getRow(); if ($result1) { $data1 = [ 'username' => $result1->username, 'from_time' => $fromTimes[$index], 'to_time' => $toTimes[$index], 'course_type' => $sessionTypes[$index], ]; array_push($array1, $data1); } } $data['faculty_batch'] = $array1; $data['selected_type'] = 'faculty'; } array_push($array, $data); } if (!empty($array)) { return $this->response->setJSON(['result' => 1, 'cart_result' => $array]); } else { return $this->response->setJSON(['result' => 0]); } } public function index() { return view('user/index'); } public function search_all() { $search_value = $this->request->getPost('search_value'); $nparrotsModel = new New_Model(); $result = $nparrotsModel->search_all_1($search_value); if ($result) { return $this->response->setJSON(['result' => 1, 'search_result' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_searched_value_subdomain_id() { $search_bar = $this->request->getPost('search_bar'); $search_value = $this->request->getPost('search_value'); $nparrotsModel = new New_Model(); $result = $nparrotsModel->get_searched_value_subdomain_id($search_bar, $search_value); if ($result) { return $this->response->setJSON(['result' => 1, 'type' => $search_value, 'data' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function view_category_courses() { return view('user/category_wise_courses'); } public function get_all_domains_courses() { $nparrotsModel = new Amcad_Home(); $result = $nparrotsModel->get_domain_courses(); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_cart_count() { $user_id = session('user_login_id'); // Use session helper $where = ['user_id' => $user_id, 'delete_status' => 'ACTIVE']; $table = 'course_cart'; $nparrotsModel = new Amcad_Home(); // Instantiate your model class $result = $nparrotsModel->get_where_result($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'count' => count($result)]); } else { return $this->response->setJSON(['result' => 0]); } } public function jb_admin() { echo view('institutions/admin_form'); } public function instructor() { $nparrotsModel = new New_Model(); $domain_table = 'domains'; $where_domain = ['delete_status' => 'ACTIVE', 'user_type_id' => '1']; $order_by = 'domain_name'; $data['domain'] = $nparrotsModel->get_where_result_orderby_asc($domain_table, $where_domain, $order_by); return view('user/instructor', $data); } public function addRequestedCourse() { $loginId = session()->get('faculty_login_id'); $userTypeId = session()->get('faculty_user_type_id'); $facultyInstitutionId = session()->get('faculty_institution_id'); $loginTable = 'login'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $emailResult = $faculty_model->getWhereRow($loginTable, $where); $email = $emailResult->email; $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $domainId = $this->request->getPost('catagory'); $subDomainId = $this->request->getPost('sub_catagory'); $comments = $this->request->getPost('comments'); $batchSize = $this->request->getPost('batch_size'); $courseType = $this->request->getPost('course_type'); $availableType = ""; foreach ($courseType as $courses) { if ($courses == 'live') { $availableType = $this->request->getPost('available_type'); } } $i = 0; $j = 0; $k = 0; $l = 0; $timeCount = 0; $startTime = ''; $endTime = ''; if ($availableType != '') { if ($availableType == 'timings') { $startTime = $this->request->getPost('from_time'); $endTime = $this->request->getPost('to_time'); $repeatedTime = []; foreach ($startTime as $key => $value) { // Your existing code for handling timings // ... } } else { // Your existing code for handling other available types // ... } } else { // Your existing code for handling cases when availableType is empty // ... } if ($j >= 1) { $repeatedTimings = implode(', ', $repeatedTime); return json_encode(['result' => 0, 'message' => $repeatedTimings . ' Timings are already added to other course']); } elseif ($i >= 1) { return json_encode(['result' => 0, 'message' => 'Timings are duplicated']); } elseif ($k >= 1) { return json_encode(['result' => 0, 'message' => 'Timings are duplicated']); } elseif ($l == 1) { return json_encode(['result' => 0, 'message' => $cMessage]); } else { // Your existing code for handling other cases $notification = $emailResult->username . ', has requested for additional subjects ' . $subdomains; $notificationData = [ 'login_id' => $loginId, 'username' => $emailResult->username, 'notification' => $notification, 'view_status' => 'NOT_VIEWED', 'delete_status' => 'ACTIVE', 'category_type' => 'Course Request', 'created_by' => $loginId, 'created_at' => $createdAt, ]; if ($facultyInstitutionId == 0) { $notificationTable = 'notification'; $institutionId = '0'; } else { $notificationTable = 'admin_notifications'; $notificationData['institution_id'] = $facultyInstitutionId; } $notificationResult = $faculty_model->insert($notificationTable, $notificationData); return json_encode(['result' => 1, 'message' => 'Added Successfully']); } } public function admin_login() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $logged_in = $date->format('Y-m-d H:i:s'); $email = $this->request->getPost('email'); $password = md5($this->request->getPost('password')); // print_r($password);die(); $passwordd = $this->request->getPost('password'); $remember = $this->request->getPost('remember'); $nparrots_model = new Nparrots_Model(); $result = $nparrots_model->getWhereUser($email, $password); if ($remember == 1) { setcookie("email", $email, time() + (86400 * 30), "/"); setcookie("password", $passwordd, time() + (86400 * 30), "/"); } else { setcookie("email", "", time() + (86400 * 30), "/"); setcookie("password", "", time() + (86400 * 30), "/"); } if ($result !== null) { // Check if $result is not null $where_login = [ 'user_type_id' => $result->user_type_id, 'delete_status' => 'ACTIVE', ]; $data = ['last_logged_in' => $logged_in]; $login_table = 'login'; // Assuming you have a model called NparrotsModel for updating data $updateLoginTime = $nparrots_model->updateData2($where_login, $login_table, $data); // Set session data based on user type $sessionData = [ 'login_id' => $result->login_id, 'user_type_id' => $result->user_type_id, 'username' => $result->username, 'user_type' => $result->user_type, 'approval_status' => $result->approval_status, 'password' => $result->password, ]; if ($result->user_type_id == 1) { session()->set($sessionData); return json_encode(['result' => 1, 'message' => 'Login Successful']); } elseif ($result->user_type_id == 2) { $facultySessionData = [ 'faculty_login_id' => $result->login_id, 'faculty_user_type_id' => $result->user_type_id, 'faculty_username' => $result->username, 'faculty_user_type' => $result->user_type, 'faculty_approval_status' => $result->approval_status, ]; session()->set($facultySessionData); return json_encode(['result' => 2, 'message' => 'Login Successful']); } else { return json_encode(['result' => 4, 'message' => 'Wrong Login Credentials']); } } else { return json_encode(['result' => 4, 'message' => 'Wrong Login Credentials']); } } public function user_login() { $currentDateTime = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $logged_in = $currentDateTime->format('Y-m-d H:i:s'); $email = $this->request->getPost('email'); $password = md5($this->request->getPost('password')); // $password = $this->request->getPost('password'); $passwordd = $this->request->getPost('password'); $remember = $this->request->getPost('remember'); $table = 'login'; $where = [ 'email' => $email, 'password' => $password, 'user_type_id' => 3, 'delete_status' => 'ACTIVE', 'verified_status' => 'VERIFIED' ]; $nparrotsModel = new New_Model(); $result = $nparrotsModel->get_where_row($where, $table); // print_r($result);die(); if ($result) { $where_user = ['login_id' => $result->login_id, 'delete_status' => 'ACTIVE']; $login_status = ['login_status' => 'ONLINE']; $nparrotsModel->customUpdate($table, $login_status, $where_user); if ($remember == 'user') { setcookie("user_cookie_email", $email, time() + (86400 * 30), "/"); setcookie("user_cookie_password", $passwordd, time() + (86400 * 30), "/"); } else { setcookie("user_cookie_email", "", time() + (86400 * 30), "/"); setcookie("user_cookie_password", "", time() + (86400 * 30), "/"); } $where_login = [ 'login_id' => $result->login_id, 'delete_status' => 'ACTIVE' ]; $data = ['last_logged_in' => $logged_in]; $login_table = 'login'; $nparrotsModel->customUpdate($table, $data, $where_login); session()->set([ 'user_login_id' => $result->login_id, 'user_user_type_id' => $result->user_type_id, 'user_username' => $result->username, 'user_approval_status' => $result->approval_status, 'user_institution_id' => $result->institution_id, 'email'=>$result->email, ]); $url = $this->request->getPost('url_segment'); if (isset($_COOKIE['course_ids']) && $url == 'CoursesDetails') { $cart_table = 'course_cart'; $course_ids = $_COOKIE['course_ids']; $course_titles = $_COOKIE['course_titles']; $course_prices = $_COOKIE['course_prices']; $course_faculty = $_COOKIE['course_faculty']; $course_batch = $_COOKIE['course_batch']; $course_subdomain = $_COOKIE['course_subdomain']; $course_fromtime = $_COOKIE['course_fromtime']; $course_totime = $_COOKIE['course_totime']; $course_session = $_COOKIE['course_session']; $cart_data = [ 'user_id' => $result->login_id, 'course_id' => $course_ids, 'course_title' => $course_titles, 'course_price' => $course_prices, 'batch_ids' => $course_batch, 'faculty_ids' => $course_faculty, 'sub_domain_ids' => $course_subdomain, 'from_time' => $course_fromtime, 'to_time' => $course_totime, 'session_type' => $course_session, 'created_at' => $logged_in, 'created_by' => $result->login_id ]; $cart_table = 'course_cart'; $user_id = $result->login_id; $where = ['user_id' => $result->login_id, 'course_id' => $course_ids, 'delete_status' => 'ACTIVE']; $all_data = $nparrotsModel->get_where_result($cart_table, $where); $mapping_table = 'user_course_mapping'; $where1 = [ 'user_id' => $result->login_id, 'course_id' => $course_ids, 'delete_status' => 'ACTIVE', 'enroll_status' => 'ENROLLED', 'payment_status' => 'PAID' ]; $all_data1 = $nparrotsModel->get_where_result($mapping_table, $where1); if ($all_data) { return $this->response->setJSON(['result' => 6, 'message' => "Course already exists in your cart"]); } elseif ($all_data1) { return $this->response->setJSON(['result' => 6, 'message' => "You have enrolled in this course"]); } else { $result = $nparrotsModel->customInsert($cart_table, $cart_data); if ($result) { $this->response->setJSON(['result' => 5, 'message' => 'Login Successful']); helper('cookie'); delete_cookie("course_ids"); delete_cookie("course_titles"); delete_cookie("course_prices"); delete_cookie("course_faculty"); delete_cookie("course_batch"); delete_cookie("course_subdomain"); delete_cookie("course_fromtime"); delete_cookie("course_totime"); delete_cookie("course_session"); } } } else { return $this->response->setJSON(['result' => 3, 'message' => 'Login Successful.']); } } else { $table = 'login'; $where = [ 'email' => $email, 'user_type_id' => 3, 'delete_status' => 'ACTIVE' ]; $result = $nparrotsModel->get_where_row($where, $table); if (empty($result)) { return $this->response->setJSON(['result' => 7, 'message' => 'You are not registered yet to login.']); } else { if ($remember == 'user') { setcookie("user_cookie_email", $email, time() + (86400 * 30), "/"); setcookie("user_cookie_password", $passwordd, time() + (86400 * 30), "/"); } else { setcookie("user_cookie_email", "", time() + (86400 * 30), "/"); setcookie("user_cookie_password", "", time() + (86400 * 30), "/"); } return $this->response->setJSON(['result' => 4, 'message' => 'Wrong Login Credentials']); } } } public function user_logout() { $currentDateTime = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $logged_out = $currentDateTime->format('Y-m-d H:i:s'); $session = session(); $table = 'login'; $where_user = ['login_id' => $session->get('user_login_id'), 'delete_status' => 'ACTIVE']; $login_status = ['login_status' => 'OFFLINE', 'updated_at' => $logged_out]; $nparrotsModel = new New_Model(); $result = $nparrotsModel->UpdateData($where_user, $table, $login_status); $session->remove(['user_login_id', 'user_user_type_id', 'user_username', 'user_user_type']); return redirect()->to('/'); } public function user_registration() { $username = $this->request->getPost('username'); $email = $this->request->getPost('email'); $password = $this->request->getPost('password'); $phone_number = $this->request->getPost('phone_number'); $country_code = $this->request->getPost('country_code'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $login_table = 'login'; $current_time = time(); $time1 = md5($current_time); $string = substr($time1, 0, 6); $otp = strtoupper($string); $login_data = [ 'user_type_id' => '3', 'username' => $username, 'email' => $email, 'password' => md5($password), 'otp_code' => $otp, 'verified_status' => 'NOT_VERIFIED', 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $where_email = [ 'user_type_id' => '3', 'email' => $email, 'delete_status' => 'ACTIVE', 'verified_status' => 'VERIFIED', ]; $nparrots_model = new Amcad_Home(); $check_email = $nparrots_model->getWhereRow($login_table, $where_email); if ($check_email) { echo json_encode(['result' => 2, 'message' => "Email already exists"]); } else { $result = $nparrots_model->insertData2($login_table, $login_data); if ($result) { $user_table = 'user_registrations'; $user_data = [ 'login_id' => $result, 'country_code' => $country_code, 'phone_number' => $phone_number, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $user_result = $nparrots_model->insertData3($user_table, $user_data); $where_id = ['login_id' => $result]; $update_id = ['encrypted_login_id' => md5($result)]; $update = $nparrots_model->UpdateData15($login_table, $update_id, $where_id); $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($email); $emailService->setSubject('Amcad Registration – OTP for Email Verification'); $href = base_url(''); $content = ''; $content .= '<body style="background:#f3f3f3;">'; $content .= '<div style="width:100%;">'; $content .= '<div style="text-align: center;">'; $content .= '<div>'; $content .= '<img src="'.$href.'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $content .= '</div>'; $content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $content .= '<img src="'.$href.'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $content .= '</div>'; $content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $content .= '<h3 style="margin-top:10px;">Email Confirmation</h3>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$username.', Thanks for registering on Amcad. Please click on the below link for email verification and enter OTP to complete verification.</p>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">OTP : '.$otp.'</p>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">Your Login credentials are : '.$email.' and '.$password.'</p>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="'.$href.'user-verification/'.md5($result).'" style="color:#fff;padding:10px 30px;background:#a6d039;" style="color:#fff;padding:10px 30px;background:#a6d039;">Verify Your OTP</a></p>'; $content .= '</div>'; $content .= '</div>'; $content .= '</div>'; $content .= '</body>'; $emailService->setMessage($content); if ($emailService->send()) { echo json_encode(['result'=>1,'message'=>"To complete your registration please verify the link with OTP code sent to $email"]); } else { echo json_encode(['result' => 0, 'message' => "Something went wrong.. try again"]); } } } } public function user_verification() { echo view('user/user_verification'); } public function complete_user_verification() { $nparrotsModel = new Amcad_Home(); $otpCode = $this->request->getPost('otp_code'); $currentTime = Time::now('Asia/Kolkata'); $loginTable = 'login'; $where = ['otp_code' => $otpCode]; $checkOtp = $nparrotsModel->get_where_row11($loginTable, $where); if ($checkOtp) { if ($checkOtp->verified_status == 'VERIFIED') { return json_encode(['result' => 3, 'message' => 'OTP already verified']); } else { $whereId = ['otp_code' => $otpCode]; $updateData = ['verified_status' => 'VERIFIED', 'verified_at' => $currentTime->toDateTimeString()]; $result = $nparrotsModel->updateData22($whereId, $loginTable, $updateData); if ($result) { $session = session(); $session->set('user_login_id', $checkOtp->login_id); $session->set('user_user_type_id', $checkOtp->user_type_id); $session->set('user_username', $checkOtp->username); $session->set('user_approval_status', $checkOtp->approval_status); if ($checkOtp->user_type_id == 4 || $checkOtp->user_type_id == 2) { return json_encode(['result' => 1, 'message' => 'Registered Successfully. You will be notified by your password credentials and login link once admin approves your registration']); } else { return json_encode(['result' => 1, 'message' => 'Registered Successfully']); } } else { return json_encode(['result' => 2, 'message' => 'Something went wrong... try again']); } } } else { return json_encode(['result' => 0, 'message' => 'Wrong OTP']); } } public function check_registered_user_email() { $nparrots_model = new Amcad_Home(); $table = 'login'; $login_id = $this->request->getPost('login_id'); $result = $nparrots_model->get_user_signup_details($login_id); if ($result) { return $this->response->setJSON(['data' => $result, 'result' => 1]); } else { return $this->response->setJSON(['result' => 0, 'message' => $result]); } } public function admin_dashboard() { $session = session(); $login_id = $session->get('login_id'); if ($login_id) { $where_faculty = [ 'verified_status' => 'VERIFIED', 'delete_status' => 'ACTIVE', 'user_type_id' => 2, 'approval_status' => 'APPROVED', 'institution_id' => 0 ]; $nparrotsModel = new New_Model(); $data['users'] = count($nparrotsModel->get_user_registrations()); $data['faculty'] = count($nparrotsModel->get_where_result('login', $where_faculty)); $data['institutions'] = count($nparrotsModel->get_institutes_details()); return view('admin/admin_dashboard', $data); } else { return redirect()->to('/'); } } public function user_dashboard() { $login_id = session()->get('user_login_id'); if ($login_id) { return view('user/user_dashboard'); } else { return redirect()->to('/'); } } public function read_cart_data_from_db() { $user_id = session('user_login_id'); $nparrots_model = new Amcad_Home(); $cart_result = $nparrots_model->get_cart_data_from_db($user_id); if ($cart_result) { return $this->response->setJSON(['result' => 1, 'cart_result' => $cart_result]); } else { return $this->response->setJSON(['result' => 0]); } } public function user_added_courses() { $login_id = $this->request->getPost('login_id'); $nparrots_model = new Amcad_Home(); $result = $nparrots_model->user_added_courses($login_id); // print_r($login_id);die(); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_popular_course_on_clicks() { $nparrotsModel = new New_Model(); $result = $nparrotsModel->get_popular_course_on_clicks(); if ($result) { return $this->response->setJSON(['result' => 1, 'clicks_result' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function courses_details() { $nparrotsModel = new New_Model(); $course_id = $this->request->uri->getSegment(2); $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $table = 'courses'; $data['result'] = $nparrotsModel->get_where_row($where, $table); $where1 = ['enroll_status' => 'ENROLLED', 'delete_status' => 'ACTIVE']; $table1 = 'user_course_mapping'; $order_by = 'mapping_id'; $data['enrol_result'] = $nparrotsModel->get_where_orderby_row($table1, $where1, $order_by); $sub_domain_id = $data['result']->sub_domain_id; $data['instructor'] = $nparrotsModel->get_instructors_details($course_id); $data['batches'] = $nparrotsModel->get_batch_list($course_id); $data['feedbacks'] = $nparrotsModel->get_feedbacks_list($course_id); return view('user/courses_details', $data); } public function add_clicks() { $courseId = $this->request->getPost('course_id'); $whereCourse = ['course_id' => $courseId, 'delete_status' => 'ACTIVE']; $clicksTable = 'popular_course_clicks'; $nparrotsModel = new New_Model(); $clicksResult = $nparrotsModel->get_where_row($clicksTable, $whereCourse); if ($clicksResult) { $clicksData = ['clicks' => $clicksResult->clicks + 1]; $nparrotsModel->updateData($whereCourse, $clicksTable, $clicksData); } else { $clicksData = [ 'course_id' => $courseId, 'clicks' => 1, 'delete_status' => 'ACTIVE' ]; $this->db->table($clicksTable)->insert($clicksData); } } public function get_all_courses() { $nparrotsModel = new New_Model(); $result = $nparrotsModel->get_all_courses(); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function delete_course_from_cart() { $table = 'course_cart'; $session = session(); $user_id = $session->get('user_login_id'); $course_id = $this->request->getPost('course_id'); $where = ['course_id' => $course_id, 'user_id' => $user_id]; $data = ['delete_status' => 'INACTIVE']; $Model = new New_Model(); $deleteCart = $Model->deleteData($table, $where); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed']); } } public function complete_user_registration() { $course_id = $this->request->getPost('course_id'); $course_price = $this->request->getPost('course_price'); $full_name = $this->request->getPost('full_name'); $address = $this->request->getPost('address'); $qualification = $this->request->getPost('qualification'); $current_occupation = $this->request->getPost('current_occupation'); $present_location = $this->request->getPost('present_location'); $session_type = $this->request->getPost('session_type'); $duration = $this->request->getPost('duration'); $terms_and_conditions = $this->request->getPost('terms_and_conditions'); $nparrotsModel = new Amcad_Home(); $updated_at = date('Y-m-d H:i:s'); $login_id = session()->get('user_login_id'); $table = 'user_registrations'; $where = ['login_id' => $login_id]; $data = [ 'full_name' => $full_name, 'address' => $address, 'qualification' => $qualification, 'current_occupation' => $current_occupation, 'present_location' => $present_location, 'session_type' => $session_type, 'duration' => $duration, 'terms_and_conditions' => $terms_and_conditions, 'registration_status' => 'REGISTERED', 'updated_by' => $login_id, 'updated_at' => $updated_at ]; $result = $nparrotsModel->UpdateData($table, $data, $where); $login_table = 'login'; $login_data = ['username' => $full_name, 'updated_at' => $updated_at]; $resul1 = $nparrotsModel->UpdateData($login_table, $login_data, $where); session()->set('user_username', $full_name); if ($result) { $login_table = 'login'; $where_id = ['login_id' => $login_id]; $update_data = ['approval_status' => 'APPROVED']; $update_status = $nparrotsModel->UpdateData($login_table, $update_data, $where_id); $map_table = 'user_course_mapping'; $cart_table = 'course_cart'; $cart_data = $nparrotsModel->get_cart_data_from_db($login_id); $course_array = []; foreach ($cart_data as $val) { $where_course = ['user_id' => $login_id, 'course_id' => $val->course_id, 'delete_status' => 'ACTIVE']; $check_course = $nparrotsModel->getWhereRow($map_table, $where_course); $where = ['course_id' => $val->course_id]; $table = 'courses'; $course = $nparrotsModel->getWhereRow($table, $where); if ($check_course) { $update_data = [ 'user_id' => $login_id, 'course_id' => $val->course_id, 'course_price' => $val->course_price, 'batch_ids' => $val->batch_ids, 'faculty_ids' => $val->faculty_ids, 'sub_domain_ids' => $val->sub_domain_ids, 'from_time' => $val->from_time, 'to_time' => $val->to_time, 'session_type' => $val->session_type, 'updated_by' => $login_id, 'updated_at' => $updated_at ]; $where_course = ['user_id' => $login_id, 'course_id' => $val->course_id]; $update_map = $nparrotsModel->UpdateData($map_table, $update_data, $where_course); if ($update_map) { $where_cart = ['user_id' => $login_id, 'course_id' => $val->course_id]; } } else { $mapping_data = [ 'user_id' => $login_id, 'course_id' => $val->course_id, 'course_price' => $val->course_price, 'batch_ids' => $val->batch_ids, 'faculty_ids' => $val->faculty_ids, 'sub_domain_ids' => $val->sub_domain_ids, 'from_time' => $val->from_time, 'to_time' => $val->to_time, 'session_type' => $val->session_type, 'enroll_status' => 'ENROLLED', 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'created_at' => $updated_at ]; $insert_map = $nparrotsModel->insertData($map_table, $mapping_data); if ($insert_map) { $where_cart = ['user_id' => $login_id, 'course_id' => $val->course_id]; } } array_push($course_array, $course->course_title); } $course_title = implode(', ', $course_array); $table = 'login'; $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; $username = $nparrotsModel->getWhereRow($table, $where); $notification = $username->username . ', has registered for the course ' . $course_title; $notification_table = 'notification'; $notification_data = [ 'login_id' => $login_id, 'username' => $username->username, 'notification' => $notification, 'view_status' => 'NOT_VIEWED', 'delete_status' => 'ACTIVE', 'category_type' => 'User Registration', 'created_by' => $login_id, 'created_at' => $updated_at ]; $notification_result = $nparrotsModel->insertData($notification_table, $notification_data); if ($session_type == "live") { $from_time = $this->request->getPost('from_time'); $to_time = $this->request->getPost('to_time'); $timing_table = 'user_available_timings'; foreach ($from_time as $key => $value) { $timing_data = [ 'course_id' => $course_id, 'user_id' => $login_id, 'from_time' => $from_time[$key], 'to_time' => $to_time[$key], 'delete_status' => 'ACTIVE', 'created_at' => $updated_at ]; $time_result = $nparrotsModel->insertData($timing_table, $timing_data); } } return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update. Try again']); } } public function course_payment() { $user_id = session()->get('user_login_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $nparrotsModel = new New_Model(); // Adjust the model class name and namespace $cartTable = 'course_cart'; $whereUser = ['user_id' => $user_id]; $cartResult = $nparrotsModel->getWhereResult($cartTable, $whereUser); $table = 'user_course_mapping'; $paymentStatus = ['payment_status' => 'PAID', 'updated_at' => $updated_at]; if ($cartResult) { $courseContent = ''; $courseContent .= '<table class="table table-bordered list_table">'; $courseContent .= '<thead>'; $courseContent .= '<tr>'; $courseContent .= '<th scope="col">#</th>'; $courseContent .= '<th scope="col" style="width:150px">Course Name</th>'; $courseContent .= '<th scope="col" style="width:150px">Faculty/Batch</th>'; $courseContent .= '<th scope="col" style="width:150px">Session Type</th>'; $courseContent .= '<th scope="col" style="width:150px">Timings</th>'; $courseContent .= '</tr>'; $courseContent .= '</thead>'; $i = 0; foreach ($cartResult as $val) { $i = $i + 1; $whereUser = ['user_id' => $user_id, 'course_id' => $val->course_id, 'delete_status' => 'ACTIVE']; $result = $nparrotsModel->updateData($whereUser, $table, $paymentStatus); if ($nparrotsModel->affectedRows() > 0) { $batchFaculty = $nparrotsModel->getWhereRow($table, $whereUser); if ($batchFaculty->batch_ids == 'null') { $facultyIds = json_decode($batchFaculty->faculty_ids); $facultyIds = implode(',', $facultyIds); $loginTable = 'login'; $whereFaculty = ['login_id' => $facultyIds, 'delete_status' => 'ACTIVE']; $batchesFaculty = $nparrotsModel->getWhereRow($loginTable, $whereFaculty); $facBatch = $batchesFaculty->username; } else { $batch_ids = json_decode($batchFaculty->batch_ids); $batch_ids = implode(',', $batch_ids); $batchTable = 'batches'; $whereBatch = ['batch_id' => $batch_ids, 'delete_status' => 'ACTIVE']; $batchesFaculty = $nparrotsModel->getWhereRow($batchTable, $whereBatch); $facBatch = $batchesFaculty->batch_name; } $table = 'courses'; $where = ['course_id' => $val->course_id, 'delete_status' => 'ACTIVE']; $courseName = $nparrotsModel->getWhereRow($table, $where); $courseContent .= '<tbody id="course_tbody">'; $courseContent .= '<td>' . $i . '</td>'; $courseContent .= '<td>' . $courseName->course_title . '</td>'; $courseContent .= '<td>' . $facBatch . '</td>'; $courseContent .= '<td>' . implode(',', json_decode($batchFaculty->session_type)) . '</td>'; $sessionType = implode(',', json_decode($batchFaculty->from_time)); if ($batchFaculty->batch_ids == 'null') { if ($sessionType == 'Live' || $sessionType == 'Recorded' || $sessionType == 'Fullday') { $courseContent .= '<td></td>'; } else { $courseContent .= '<td>' . implode(',', json_decode($batchFaculty->from_time)) . ' - ' . implode(',', json_decode($batchFaculty->to_time)) . '</td>'; } } else { $courseContent .= '<td>' . implode(',', json_decode($batchFaculty->from_time)) . '</td>'; } $courseContent .= '</tbody>'; $whereUser = ['user_id' => $user_id, 'course_id' => $val->course_id]; $deleteCart = $nparrotsModel->deleteData($cartTable, $whereUser); } } $courseContent .= '</table>'; } return redirect()->to('/user-dashboard'); } public function added_course_details_review() { $session = \Config\Services::session(); $user_id = $session->get('user_login_id'); if ($user_id) { $mapping_id = $this->request->uri->getSegment(2); $mocktest_sl_no = $this->request->uri->getSegment(3); $mocktest_id = $this->request->uri->getSegment(4); $nparrots_model = new Amcad_Home(); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'delete_status' => 'ACTIVE']; $det = $nparrots_model->getWhereRow($table, $where); $sub_domain_ids = $det->sub_domain_ids; $table = 'question_mapping'; $where = ['mocktest_id' => $mocktest_id, 'user_id' => $user_id]; $mocktest_taken = $nparrots_model->numberRows($table, $where); $mocktests = $nparrots_model->get_where_mocktest_taken($mocktest_id, $user_id); $data['mocktests'] = $mocktests; $data['mocktests_taken'] = $mocktest_taken; $table = 'question_mapping'; $whereIn = ['user_id' => $user_id, 'test_type' => 'Final Test']; $data['check_attempt'] = $nparrots_model->get_where_in_result($user_id, $sub_domain_ids); $check_attempt = $nparrots_model->get_where_in_result($user_id, $sub_domain_ids); if ($check_attempt) { $data['finals'] = '1'; } else { $data['finals'] = '0'; } $data['mapping_subjects'] = $mapping = $nparrots_model->get_mapping_course_subjects($mapping_id); return view('user/user_course_details_review', $data); } else { return redirect()->to('/'); } } public function added_course_details() { $user_id = session()->get('user_login_id'); $user_institution_id = session()->get('user_institution_id'); if ($user_id) { $mapping_id = $this->request->uri->getSegment(2); $nparrots_model = new Amcad_Home(); $mapp_data = $nparrots_model->get_where_row_11('user_course_mapping', ['mapping_id' => $mapping_id]); if ($mapp_data && is_object($mapp_data)) { $data['course_details'] = $nparrots_model->get_user_course_details($user_id, $mapping_id); if (!empty($data['course_details']) && isset($data['course_details'][0][0]->sub_domain_id)) { $sub_domain_id = $data['course_details'][0][0]->sub_domain_id; $data['mapping_subjects'] = $nparrots_model->get_mapping_course_subjects($mapping_id); if (property_exists($mapp_data, 'course_id')) { $where_course = ['course_id' => $mapp_data->course_id]; $data['course_sub_domain'] = $nparrots_model->get_where_row('courses', $where_course); if ($mapp_data->batch_ids == 'null') { $faculty_ids = json_decode($mapp_data->faculty_ids); $data['faculties'] = $nparrots_model->get_faculties($faculty_ids); } else { $batch_ids = json_decode($mapp_data->batch_ids); $data['faculties'] = $nparrots_model->get_batch_faculties($batch_ids); } $data['mapping_id'] = $mapping_id; $note_table = 'notes'; $where_note = [ 'course_id' => $mapp_data->course_id, 'created_by' => $user_id, 'delete_status' => 'ACTIVE' ]; $data['notes'] = $nparrots_model->get_where_result5($note_table, $where_note); $get_sub_domains = $nparrots_model->get_where_row5('courses', $where_course); $sub_domain_id = json_decode($get_sub_domains->sub_domain_id); $data['analysis_details'] = $nparrots_model->get_user_analysis_details($user_id, $sub_domain_id); if (!empty($data['course_details'][0][0]->sub_domain_id)) { $data['performance'] = $nparrots_model->get_user_performance_details($user_id, $data['course_details'][0][0]->sub_domain_id); $data['progress'] = $nparrots_model->get_user_progress_details($user_id, $data['course_details'][0][0]->sub_domain_id); } $table_quest = "questions"; $where = ['status' => 'ACTIVE']; $data['questions'] = $nparrots_model->get_where_result_new($table_quest, $where); $data['course_data'] = $nparrots_model->single_course_details($mapping_id); $data['sub_domain_id'] = $data['course_details'][0][0]->sub_domain_id; $table = 'question_mapping'; $where = [ 'user_id' => $user_id, 'test_type' => 'Final Test', 'subject_id' => $data['course_details'][0][0]->sub_domain_id ]; $data['check_attempt'] = $nparrots_model->get_where_result($table, $where); $order_by = 'test_id'; $check_attempt = $nparrots_model->get_where_result4($table, $where, $order_by); $check_attempts = $nparrots_model->get_where_orderby_row($table, $where, $order_by); if ($check_attempts) { if ($check_attempts->final_result == 'PASS') { $data['finals'] = '1'; } else { $data['finals'] = '0'; } } else { $data['finals'] = '0'; } if ($check_attempt) { $test_id = $check_attempt[0]->test_id; $qid = json_decode($check_attempt[0]->question_id); $questions = count($qid); $data['finals_score'] = $nparrots_model->final_test_correct_answer($sub_domain_id, $user_id, $test_id); } else { $data['finals_score'] = 0; } $sub_domain_id = $data['course_details'][0][0]->sub_domain_id; if ($mapp_data->batch_ids == 'null') { $faculty_ids = json_decode($mapp_data->faculty_ids); $faculty = $faculty_ids; } else { $batch_ids = json_decode($mapp_data->batch_ids); $batch_faculty_id = $nparrots_model->get_batch_faculties_row($batch_ids); $faculty = $batch_faculty_id->faculty_id; } $data['mocktests'] = $nparrots_model->get_mocktests($user_id, $sub_domain_id, $faculty); $data['chapter'] = $nparrots_model->get_where_chapter_answered_details($user_id, $sub_domain_id, $faculty); // print_r($data['chapter']);die(); return view('user/user_course_details', $data); } else { // Handle the case where 'course_id' is not a property of $mapp_data // You might want to log an error, redirect, or handle it according to your logic. } } else { // Handle the case where $mapp_data is null or not an object // You might want to log an error, redirect, or handle it according to your logic. } } else { return redirect()->to('/'); } } } public function get_user_details() { $login_id = session()->get('user_login_id'); $table = 'login'; $where = ['login_id' => $login_id]; $model = new Amcad_Home(); $result = $model->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function check_course_type() { $table = 'user_course_mapping'; $mapping_id = $this->request->getPost('mapping_id'); $nparrots_model = new Amcad_Home(); $result = $nparrots_model->check_course_type($mapping_id); if ($result) { $type = json_decode($result->session_type); if (in_array('Live', $type)) { $course_type = "Live"; } else { $course_type = "Recorded"; } return $this->response->setJSON(['course_type' => $course_type, 'result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } public function check_user_session_status() { $session = session(); $login_id = $session->get('user_login_id'); $nparrots_model = new Amcad_Home(); $table = 'login'; $where = ['login_id' => $login_id]; $result = $nparrots_model->getWhereRow($table, $where); if ($result) { if ($result->delete_status == 'INACTIVE') { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } else { return $this->response->setJSON(['result' => 0]); } } public function edit_user_prifile() { $userId = session()->get('user_login_id'); if ($userId) { $registrationTable = 'user_registrations'; $where = ['login_id' => $userId, 'delete_status' => 'ACTIVE']; $nparrots_model = new Amcad_Home(); $data['user_details'] = $nparrots_model->get_user_details($userId); return view('user/user_profile', $data); } else { return redirect()->to('/'); } } public function edit_user_profile1() { $userId = session()->get('user_login_id'); if ($userId) { $registrationTable = 'user_registrations'; $where = ['login_id' => $userId, 'delete_status' => 'ACTIVE']; $nparrots_model = new Amcad_Home(); $data['user_details'] = $nparrots_model->get_user_details($userId); return view('user/user_profile1', $data); } else { return redirect()->to('/'); } } public function update_user_password() { $session = session(); $login_id = $session->get('user_login_id'); if ($login_id) { return view('user/update_user_password'); } else { return redirect()->to('/'); } } public function reset_password() { $encryptedId = $this->request->getPost('encrypted_id'); // print_r($encryptedId);die(); $password1 = $this->request->getPost('password1'); $password2 = $this->request->getPost('password2'); $date = Time::now('Asia/Kolkata'); $updatedAt = $date->format('Y-m-d H:i:s'); $nparrots_model = new Amcad_Home(); $table = 'login'; $where = ['encrypted_login_id' => $encryptedId]; $data = [ 'password' => md5($password2), 'updated_at' => $updatedAt ]; $typeResult = $nparrots_model->getWhereRow($table, $where); if ($typeResult->delete_status == 'INACTIVE') { return $this->response->setJSON(['result' => 0, 'message' => 'Your account is deleted']); } else { if ($password1 == $password2) { $result = $nparrots_model->UpdateData12($where, $table, $data); if ($nparrots_model->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully', 'data' => $typeResult]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update. Try again']); } } else { return $this->response->setJSON(['result' => 2, 'message' => "Password doesn't match"]); } } } public function reset_password_faculty() { $encryptedId = $this->request->getPost('encrypted_id'); // print_r($encryptedId);die(); $password1 = $this->request->getPost('password1'); $password2 = $this->request->getPost('password2'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedAt = $date->format('Y-m-d H:i:s'); $table = 'login'; // $where = ['encrypted_login_id' => $encryptedId, // 'user_type_id'=>2 // ]; $where = ['password' => md5($encryptedId), 'user_type_id'=>2 ]; $data = [ 'password' => md5($password2), 'updated_at' => $updatedAt ]; $nparrots_model = new Amcad_Home(); $typeResult = $nparrots_model->get_where_row($table, $where); if ($typeResult && $typeResult->delete_status == 'INACTIVE') { return json_encode(['result' => 0, 'message' => 'Your account is deleted']); } else { if ($password1 == $password2) { $result = $nparrots_model->UpdateData12($where, $table, $data); if ($nparrots_model->affectedRows() > 0) { return json_encode(['result' => 1, 'message' => 'Updated successfully', 'data' => $typeResult]); } else { return json_encode(['result' => 0, 'message' => 'Failed to update. Try again']); } } else { return json_encode(['result' => 2, 'message' => "Password doesn't match"]); } } } // public function reset_forgot_pswrd_faculty() // { // $encryptedId = $this->request->getPost('encrypted_id'); // $password1 = $this->request->getPost('password1'); // $password2 = $this->request->getPost('password2'); // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $updatedAt = $date->format('Y-m-d H:i:s'); // $table = 'login'; // $where = ['encrypted_login_id' => $encryptedId]; // $data = [ // 'password' => md5($password2), // 'updated_at' => $updatedAt // ]; // $nparrots_model = new Amcad_Home(); // $typeResult = $nparrots_model->get_where_row($table, $where); // if ($typeResult && $typeResult->delete_status == 'INACTIVE') { // return json_encode(['result' => 0, 'message' => 'Your account is deleted']); // } else { // if ($password1 == $password2) { // $result = $nparrots_model->UpdateData12($where, $table, $data); // if ($nparrots_model->affectedRows() > 0) { // return json_encode(['result' => 1, 'message' => 'Updated successfully', 'data' => $typeResult]); // } else { // return json_encode(['result' => 0, 'message' => 'Failed to update. Try again']); // } // } else { // return json_encode(['result' => 2, 'message' => "Password doesn't match"]); // } // } // } public function reset_forgot_pswrd_faculty() { $encryptedId = $this->request->getPost('encrypted_id'); $password1 = $this->request->getPost('password1'); $password2 = $this->request->getPost('password2'); // Step 1: Retrieve user information using the provided token $nparrots_model = new Amcad_Home(); $where = ['encrypted_login_id' => $encryptedId]; $user = $nparrots_model->get_where_row('login', $where); // Step 2: Verify the token against the user's information stored in the database if (!$user || $user->delete_status == 'INACTIVE') { return json_encode(['result' => 0, 'message' => 'Invalid or deleted account']); } // Check the token expiration if applicable (add your own logic) // $tokenExpirationTime = strtotime($user->token_created_at) + 3600; // Example: Token expires in 1 hour // if (time() > $tokenExpirationTime) { // return json_encode(['result' => 0, 'message' => 'Token expired']); // } // Step 3: Proceed with password update only if the token is valid if ($password1 == $password2) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedAt = $date->format('Y-m-d H:i:s'); $data = [ 'password' => md5($password2), 'updated_at' => $updatedAt ]; $result = $nparrots_model->UpdateData12($where, 'login', $data); if ($nparrots_model->affectedRows() > 0) { return json_encode(['result' => 1, 'message' => 'Updated successfully', 'data' => $user]); } else { return json_encode(['result' => 0, 'message' => 'Failed to update. Try again']); } } else { return json_encode(['result' => 2, 'message' => "Password doesn't match"]); } } public function reset_forgot_pswrd_user() { $encryptedId = $this->request->getPost('encrypted_id'); $password1 = $this->request->getPost('password1'); $password2 = $this->request->getPost('password2'); // Step 1: Retrieve user information using the provided token $nparrots_model = new Amcad_Home(); $where = ['encrypted_login_id' => $encryptedId]; $user = $nparrots_model->get_where_row('login', $where); // Step 2: Verify the token against the user's information stored in the database if (!$user || $user->delete_status == 'INACTIVE') { return json_encode(['result' => 0, 'message' => 'Invalid or deleted account']); } // Check the token expiration if applicable (add your own logic) // $tokenExpirationTime = strtotime($user->token_created_at) + 3600; // Example: Token expires in 1 hour // if (time() > $tokenExpirationTime) { // return json_encode(['result' => 0, 'message' => 'Token expired']); // } // Step 3: Proceed with password update only if the token is valid if ($password1 == $password2) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedAt = $date->format('Y-m-d H:i:s'); $data = [ 'password' => md5($password2), 'updated_at' => $updatedAt ]; $result = $nparrots_model->UpdateData12($where, 'login', $data); if ($nparrots_model->affectedRows() > 0) { return json_encode(['result' => 1, 'message' => 'Updated successfully', 'data' => $user]); } else { return json_encode(['result' => 0, 'message' => 'Failed to update. Try again']); } } else { return json_encode(['result' => 2, 'message' => "Password doesn't match"]); } } // public function update_user_profile() // { // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $email = $this->request->getPost('email'); // $login_id = $this->request->getPost('login_id'); // $user_name = $this->request->getPost('user_name'); // $phone_number = $this->request->getPost('phone_number'); // $address = $this->request->getPost('address'); // $qualification = $this->request->getPost('qualification'); // $occupation = $this->request->getPost('occupation'); // $location = $this->request->getPost('location'); // $image_files = ""; // if ($this->request->getFile('profile_pic')->isValid()) { // $profilePic = $this->request->getFile('profile_pic'); // // Ensure the file is moved successfully // if ($profilePic->move('public/course_images', time() . $profilePic->getName())) { // $image_files = $profilePic->getName(); // echo "File moved successfully: $image_files"; // } else { // return json_encode(['result' => 0, 'message' => 'Failed to upload profile picture']); // } // } // $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; // $loginTable = 'login'; // $nparrotsModel = new Amcad_Home(); // $loginResult = $nparrotsModel->getWhereRow1($loginTable, $where); // $registeredEmail = $loginResult->email; // if ($registeredEmail == $email) { // $loginTable = 'login'; // $loginData = ($image_files != '') // ? ['username' => $user_name, 'image' => $image_files, 'updated_at' => $created_at] // : ['username' => $user_name, 'updated_at' => $created_at]; // $nparrotsModel->updateData1($where, $loginTable, $loginData); // if ($nparrotsModel->affectedRows() > 0) { // $table = 'user_registrations'; // $data = [ // 'phone_number' => $phone_number, // 'full_name' => $user_name, // 'qualification' => $qualification, // 'current_occupation' => $occupation, // 'present_location' => $location, // 'address' => $address, // 'updated_at' => $created_at // ]; // $result = $nparrotsModel->updateData2($where, $table, $data); // if ($nparrotsModel->affectedRows() > 0) { // return json_encode(['result' => 1, 'message' => 'Updated Successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong..']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong..']); // } // } else { // $currentTime = time(); // $time1 = md5($currentTime); // $string = substr($time1, 0, 6); // $otp = strtoupper($string); // $data = ['verified_status' => 'NOT_VERIFIED']; // $nparrotsModel->updateData3($where, $loginTable, $data); // if ($nparrotsModel->affectedRows() > 0) { // $emailService = \Config\Services::email(); // $email_content = ''; // $href = base_url(''); // $email_content .= '<body style="background:#f3f3f3;">'; // $email_content .= '<div style="width:100%;">'; // $email_content .= '<div style="text-align: center;">'; // $email_content .= '<div>'; // $email_content .= '<img src="' . $href . 'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; // $email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; // $email_content .= '</div>'; // $email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; // $email_content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; // $email_content .= '</div>'; // $email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; // $email_content .= '<h3 style="margin-top:10px;">Email Confirmation</h3>'; // $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $user_name . ', Thanks for registering on Amcad. Please click on the below link for email verification and enter OTP to complete verification.</p>'; // $email_content .= '<p style="font-size:16px;padding-bottom:10px;">OTP : ' . $otp . '</p>'; // $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="' . $href . 'user-verification/' . md5($loginResult->login_id) . '" style="color:#fff;padding:10px 30px;background:#a6d039;">Verify Your OTP</a></p>'; // $email_content .= '</div>'; // $email_content .= '</div>'; // $email_content .= '</div>'; // $email_content .= '</body>'; // $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); // $emailService->setTo($email); // $emailService->setSubject('User Authentication'); // $emailService->setMessage($email_content); // if ($emailService->send()) { // $loginTable = 'login'; // if ($image_files != '') { // $loginData = [ // 'username' => $user_name, // 'updated_at' => $created_at, // 'image' => $image_files, // 'otp_code' => $otp, // 'email' => $email // ]; // } else { // $loginData = [ // 'username' => $user_name, // 'updated_at' => $created_at, // 'otp_code' => $otp, // 'email' => $email // ]; // } // $nparrotsModel->updateData4($where, $loginTable, $loginData); // if ($nparrotsModel->affectedRows() > 0) { // setcookie("user_cookie_email", "", time() + (86400 * 30), "/"); // setcookie("user_cookie_password", "", time() + (86400 * 30), "/"); // $table = 'user_registrations'; // $data = [ // 'phone_number' => $phone_number, // 'full_name' => $user_name, // 'qualification' => $qualification, // 'current_occupation' => $occupation, // 'present_location' => $location, // 'address' => $address, // 'updated_at' => $created_at // ]; // $result = $nparrotsModel->updateData2($where, $table, $data); // if ($nparrotsModel->affectedRows() > 0) { // return json_encode(['result' => 2, 'message' => 'Data updated successfully. Please verify the link with OTP code sent to your email id to complete Authentication']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong..']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong..']); // } // } // } // } // } public function update_user_profile() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $email = $this->request->getPost('email'); $login_id = $this->request->getPost('login_id'); $user_name = $this->request->getPost('user_name'); $phone_number = $this->request->getPost('phone_number'); $address = $this->request->getPost('address'); $qualification = $this->request->getPost('education'); $blood_group = $this->request->getPost('blood_group'); $dob = $this->request->getPost('dob'); // print_r($dob);die(); $age = $this->request->getPost('age'); // $location = $this->request->getPost('address'); $image_files = ""; if ($this->request->getFile('profile_pic')->isValid()) { $profilePic = $this->request->getFile('profile_pic'); // Ensure the file is moved successfully if ($profilePic->move('public/course_images', time() . $profilePic->getName())) { $image_files = $profilePic->getName(); } else { return json_encode(['result' => 0, 'message' => 'Failed to upload profile picture']); } } $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; $loginTable = 'login'; $nparrotsModel = new Amcad_Home(); $loginResult = $nparrotsModel->getWhereRow1($loginTable, $where); $registeredEmail = $loginResult->email; if ($registeredEmail == $email) { $loginData = ($image_files != '') ? ['username' => $user_name, 'image' => $image_files, 'updated_at' => $created_at] : ['username' => $user_name, 'updated_at' => $created_at]; $affected= $nparrotsModel->updateData1($where, $loginTable, $loginData); if ($nparrotsModel->affectedRows() > 0) { $table = 'user_registrations'; $data = [ 'phone_number' => $phone_number, 'full_name' => $user_name, 'qualification' => $qualification, 'age' => $age, 'dob' => $dob, 'address' => $address, 'blood_group'=>$blood_group, 'updated_at' => $created_at ]; $result = $nparrotsModel->updateData2($where, $table, $data); if ($nparrotsModel->affectedRows() > 0) { return json_encode(['result' => 1, 'message' => 'Updated Successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong..']); } } else { return json_encode(['result' => 0, 'message' => 'Something went wrong..']); } } else { return json_encode(['result' => 0, 'message' => 'Email does not match the registered email.']); } } public function online_class_User() { $nparrotsModel = new Amcad_Home(); $userId = session()->get('user_login_id'); $where = ['login_id' => $userId, 'delete_status' => 'ACTIVE']; $table = 'login'; $data['result'] = $nparrotsModel->getWhereRow($table, $where); return view('user/online_class_user', $data); } public function user_reports() { $session = session(); $loginId = $session->get('user_login_id'); if ($loginId) { $mapping_id = $this->request->uri->getSegment(2); $nparrotsModel = new Amcad_Home(); $table = 'user_course_mapping'; $whereDomain = ['mapping_id' => $mapping_id]; $mappData = $nparrotsModel->getWhereRow($table, $whereDomain); if ($mappData && property_exists($mappData, 'batch_ids')) { $batch_ids = json_decode($mappData->batch_ids); if ($batch_ids) { $table = 'batches'; $where = ['batch_id' => $batch_ids[0]]; $row = $nparrotsModel->getWhereRow($table, $where); $subDomainId = $row->sub_domain_id; $facultyId = $row->faculty_id; $data['course_details'] = $nparrotsModel->getUserCourseDetails($loginId, $mapping_id); $data['mapping_subjects'] = $nparrotsModel->getMappingCourseSubjects($mapping_id); $whereCourse = ['course_id' => $mappData->course_id]; $courseTable = 'courses'; $data['course_sub_domain'] = $nparrotsModel->getWhereRow($courseTable, $whereCourse); $tableData1 = "syllabus_chapter"; $whereData1 = ['sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE']; $tableData2 = "sub_domains"; $whereData2 = ['sub_domain_id' => $subDomainId]; $data['chapters'] = $nparrotsModel->get_where_result($tableData1, $whereData1); $table = 'faculty_mocktest_setting'; $where = ['created_by' => $facultyId, 'test_type' => 'Mock Test', 'sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE']; $data['mocktests'] = $nparrotsModel->get_where_result($table, $where); $data['subjects'] = $nparrotsModel->get_where_result($tableData2, $whereData2); return view('user/user_reports', $data); } else { $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id]; $res = $nparrotsModel->getWhereRow($table, $where); $facId = json_decode($res->faculty_ids); $facultyId = $facId[0]; $ids = json_decode($mappData->sub_domain_ids); $data['course_details'] = $nparrotsModel->getUserCourseDetails($loginId, $mapping_id); $data['mapping_subjects'] = $nparrotsModel->getMappingCourseSubjects($mapping_id); $whereCourse = ['course_id' => $mappData->course_id]; $courseTable = 'courses'; $data['course_sub_domain'] = $nparrotsModel->getWhereRow($courseTable, $whereCourse); $tableData1 = "syllabus_chapter"; $whereData1 = ['sub_domain_id' => $ids[0], 'delete_status' => 'ACTIVE']; $tableData2 = "sub_domains"; $whereData2 = ['sub_domain_id' => $ids[0]]; $data['chapters'] = $nparrotsModel->get_where_result($tableData1, $whereData1); $table = 'faculty_mocktest_setting'; $where = ['created_by' => $facultyId, 'test_type' => 'Mock Test', 'sub_domain_id' => $ids[0], 'delete_status' => 'ACTIVE']; $data['mocktests'] = $nparrotsModel->get_where_result($table, $where); $data['subjects'] = $nparrotsModel->get_where_result($tableData2, $whereData2); return view('user/user_reports', $data); } } else { } } else { return redirect()->to('admin'); } } public function view_reports_chapter() { $session = session(); $login_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $chapter_id = $this->request->getPost('chapter_id'); $table = "question_mapping"; $where = ['user_id' => $login_id, 'chapter_id' => $chapter_id]; $order_by = 'test_id'; $result = $nparrotsModel->getWhereResultOrderByAsc($table, $where, $order_by); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Report available']); } } else { return redirect()->to('/'); } } public function view_reports_subject() { $session = session(); $login_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mocktest_id = $this->request->getPost('mocktest_id'); $table = "question_mapping"; $where = [ 'user_id' => $login_id, 'mocktest_id' => $mocktest_id, 'chapter_id' => 0, 'test_type' => 'Mock Test' ]; $result = $nparrotsModel->get_where_result($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Report available']); } } else { return redirect()->to('admin'); } } // public function view_result_report() // { // $login_id = session('user_login_id'); // $nparrotsModel = new Courses_Model(); // if ($login_id) { // $test_id = $this->request->uri->getSegment(5); // $mapping_id = $this->request->uri->getSegment(3); // $table = 'user_course_mapping'; // $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // // print_r($res); // // die(); // // $course_id = $res->course_id; // if ($res && is_object($res)) { // Check if $res is an object // $course_id = $res->course_id; // $table = 'courses'; // $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // $course = $res->course_title; // $data['course_title'] = $course; // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id]; // $get_test_id = $nparrotsModel->getWhereRow($table, $where); // if ($get_test_id->chapter_id == "0") { // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => 'Mock Test']; // $get_test_ids = $nparrotsModel->getWhereRow($table, $where); // $test_id = $get_test_ids->test_id; // $chapter_id = $get_test_ids->chapter_id; // $mocktest_id = $get_test_ids->mocktest_id; // $sub_domain_id = $get_test_ids->subject_id; // $quest_id = $get_test_ids->question_id; // $faculty_id = $get_test_ids->faculty_id; // $det = $nparrotsModel->getWhereUserDetails($login_id); // $data['mapping_id'] = $mapping_id; // $question_table = 'questions'; // $where_sub_domain_id = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->getQuestionsForMocktestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id); // $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_sub_domain_id); // $data['total_questions'] = count($data['tot_questions']); // $table = "sub_domains"; // $where = ['sub_domain_id' => $sub_domain_id]; // $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); // $data['correct_answer'] = $nparrotsModel->subjectWiseCorrectAnswer($sub_domain_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); // $data['mocktest_id'] = $mocktest_id; // $table = 'question_mapping'; // $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; // $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); // $check_attempt = $nparrotsModel->get_where_result($table, $where); // if ($check_attempt) { // $data['finals'] = '1'; // } else { // $data['finals'] = '0'; // } // return view('user/user_subjectwise_report', $data); // } else { // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => '']; // $get_test_id = $nparrotsModel->getWhereRow($table, $where); // $test_id = $get_test_id->test_id; // $chapter_id = $get_test_id->chapter_id; // $mocktest_id = $get_test_id->mocktest_id; // $sub_domain_id = $get_test_id->subject_id; // $quest_id = $get_test_id->question_id; // $faculty_id = $get_test_id->faculty_id; // $table = "user_course_mapping"; // $where = ['user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $det = $nparrotsModel->getWhereLike($table, $where); // $data['mapping_id'] = $mapping_id; // $table = "syllabus_chapter"; // $where = ['chapter_id' => $chapter_id]; // $data['chapter_name'] = $nparrotsModel->getWhereRow($table, $where); // $table = "sub_domains"; // $where = ['sub_domain_id' => $sub_domain_id]; // $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); // $question_table = 'questions'; // $where_chapter = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->getQuestionsForPracticeReview($sub_domain_id, $quest_id, $test_id, $faculty_id); // $data['correct_answer'] = $nparrotsModel->correct_answer($chapter_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->incorrect_answer($chapter_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->not_attempted_answer($chapter_id, $login_id, $test_id); // $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_chapter); // $data['total_questions'] = count($data['tot_questions']); // $table = 'question_mapping'; // $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; // $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); // $check_attempt = $nparrotsModel->get_where_result($table, $where); // if ($check_attempt) { // $data['finals'] = '1'; // } else { // $data['finals'] = '0'; // } // return view('user/user_chapterwise_report', $data); // } // } else { // // Handle the case where $res is not an object (e.g., log an error, redirect, or display a message) // // Example: // echo "Error: Course not found for the given user and mapping ID."; // } // } // } // public function view_result_report() // { // $nparrotsModel = new Courses_Model(); // $login_id = session()->get('user_login_id'); // if ($login_id) { // $test_id = $this->request->uri->getSegment(5); // $mapping_id = $this->request->uri->getSegment(3); // $table = 'user_course_mapping'; // $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // $course_id = $res->course_id; // $table = 'courses'; // $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // $course = $res->course_title; // $data['course_title'] = $course; // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id]; // $get_test_id = $nparrotsModel->getWhereRow($table, $where); // if ($get_test_id->chapter_id == "0") { // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => 'Mock Test']; // $get_test_ids = $nparrotsModel->getWhereRow($table, $where); // $test_id = $get_test_ids->test_id; // $chapter_id = $get_test_ids->chapter_id; // $mocktest_id = $get_test_ids->mocktest_id; // $sub_domain_id = $get_test_ids->subject_id; // $quest_id = $get_test_ids->question_id; // $faculty_id = $get_test_ids->faculty_id; // $det = $nparrotsModel->getWhereUserDetails($login_id); // $data['mapping_id'] = $mapping_id; // $question_table = 'questions'; // $where_sub_domain_id = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->getQuestionsForMocktestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id); // $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_sub_domain_id); // $data['total_questions'] = count($data['tot_questions']); // $table = "sub_domains"; // $where = ['sub_domain_id' => $sub_domain_id]; // $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); // $data['correct_answer'] = $nparrotsModel->subjectWiseCorrectAnswer($sub_domain_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); // $data['mocktest_id'] = $mocktest_id; // $table = 'question_mapping'; // $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; // $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); // $check_attempt = $nparrotsModel->get_where_result($table, $where); // if ($check_attempt) { // $data['finals'] = '1'; // } else { // $data['finals'] = '0'; // } // return view('user/user_subjectwise_report', $data); // } else { // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => '']; // $get_test_id = $nparrotsModel->getWhereRow($table, $where); // $test_id = $get_test_id->test_id; // $chapter_id = $get_test_id->chapter_id; // $mocktest_id = $get_test_id->mocktest_id; // $sub_domain_id = $get_test_id->subject_id; // $quest_id = $get_test_id->question_id; // $faculty_id = $get_test_id->faculty_id; // $table = "user_course_mapping"; // $where = ['user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $det = $nparrotsModel->getWhereLike($table, $where); // $data['mapping_id'] = $mapping_id; // $table = "syllabus_chapter"; // $where = ['chapter_id' => $chapter_id]; // $data['chapter_name'] = $nparrotsModel->getWhereRow($table, $where); // $table = "sub_domains"; // $where = ['sub_domain_id' => $sub_domain_id]; // $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); // $question_table = 'questions'; // $where_chapter = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->getQuestionsForPracticeReview($sub_domain_id, $quest_id, $test_id, $faculty_id); // $data['correct_answer'] = $nparrotsModel->correct_answer($chapter_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->incorrect_answer($chapter_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->not_attempted_answer($chapter_id, $login_id, $test_id); // $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_chapter); // $data['total_questions'] = count($data['tot_questions']); // $table = 'question_mapping'; // $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; // $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); // $check_attempt = $nparrotsModel->get_where_result($table, $where); // if ($check_attempt) { // $data['finals'] = '1'; // } else { // $data['finals'] = '0'; // } // return view('user/user_chapterwise_report', $data); // } // } // } public function view_result_report() { $session = session(); $login_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $test_id = $this->request->uri->getSegment(4); $mapping_id = $this->request->uri->getSegment(2); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); // Check if a valid result is returned if ($res) { $course_id = $res->course_id; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); if ($res) { $course = $res->course_title; $data['course_title'] = $course; $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id]; $get_test_id = $nparrotsModel->getWhereRow($table, $where); if ($get_test_id->chapter_id == "0") { $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => 'Mock Test']; $get_test_ids = $nparrotsModel->getWhereRow($table, $where); $test_id = $get_test_ids->test_id; $chapter_id = $get_test_ids->chapter_id; $mocktest_id = $get_test_ids->mocktest_id; $sub_domain_id = $get_test_ids->subject_id; $quest_id = $get_test_ids->question_id; $faculty_id = $get_test_ids->faculty_id; $det = $nparrotsModel->getWhereUserDetails($login_id); $data['mapping_id'] = $mapping_id; $question_table = 'questions'; $where_sub_domain_id = ['status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->getQuestionsForMocktestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id); $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_sub_domain_id); $data['total_questions'] = count($data['tot_questions']); $table = "sub_domains"; $where = ['sub_domain_id' => $sub_domain_id]; $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); $data['correct_answer'] = $nparrotsModel->subjectWiseCorrectAnswer($sub_domain_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); $data['mocktest_id'] = $mocktest_id; $table = 'question_mapping'; $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); $check_attempt = $nparrotsModel->get_where_result($table, $where); if ($check_attempt) { $data['finals'] = '1'; } else { $data['finals'] = '0'; } return view('user/user_subjectwise_report', $data); } else { $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => '']; $get_test_id = $nparrotsModel->getWhereRow($table, $where); $test_id = $get_test_id->test_id; $chapter_id = $get_test_id->chapter_id; $mocktest_id = $get_test_id->mocktest_id; $sub_domain_id = $get_test_id->subject_id; $quest_id = $get_test_id->question_id; $faculty_id = $get_test_id->faculty_id; $table = "user_course_mapping"; $where = ['user_id' => $login_id, 'delete_status' => 'ACTIVE']; $det = $nparrotsModel->getWhereLike($table, $where); $data['mapping_id'] = $mapping_id; $table = "syllabus_chapter"; $where = ['chapter_id' => $chapter_id]; $data['chapter_name'] = $nparrotsModel->getWhereRow($table, $where); $table = "sub_domains"; $where = ['sub_domain_id' => $sub_domain_id]; $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); $question_table = 'questions'; $where_chapter = ['status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->getQuestionsForPracticeReview($sub_domain_id, $quest_id, $test_id, $faculty_id,$chapter_id); // $db = \Config\Database::connect(); // echo $db->getLastQuery(); // print_r($data['questions']); $data['correct_answer'] = $nparrotsModel->correct_answer($chapter_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->incorrect_answer($chapter_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->not_attempted_answer($chapter_id, $login_id, $test_id); $data['not_attempted_answer'] = 30-($data['correct_answer']+$data['incorrect_answer']); $data['tot_questions'] = $nparrotsModel->getWhereResult($question_table, $where_chapter); $data['total_questions'] = count($data['tot_questions']); $table = 'question_mapping'; $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; $data['check_attempt'] = $nparrotsModel->getWhereResult($table, $where); $check_attempt = $nparrotsModel->getWhereResult($table, $where); if ($check_attempt) { $data['finals'] = '1'; } else { $data['finals'] = '0'; } return view('user/user_chapterwise_report', $data); } } else { return redirect()->to('/'); } } } } public function check_approved_materials_for_mocktest() { $loginId = session()->get('user_login_id'); $nparrots_model = new Amcad_Home(); if ($loginId) { $subjectId = $this->request->getPost('subject_id'); $mapping_id = $this->request->getPost('mapping_id'); $table = 'user_course_mapping'; $where = ['user_id' => $loginId, 'mapping_id' => $mapping_id, 'delete_status' => 'ACTIVE']; $getFacultyId = $nparrots_model->getWhereRow($table, $where); $batchId = json_decode($getFacultyId->batch_ids); if ($batchId == "null") { $table = 'batches'; $getBatch = $nparrots_model->getWhereLikeBatch1($table, $batchId); $facId = $getBatch->faculty_id; $result = $nparrots_model->check_approved_materials_for_mocktest($mapping_id, $loginId, $subjectId, $facId); } else { $facultyId = json_decode($getFacultyId->faculty_ids); $result = $nparrots_model->check_approved_materials_for_mocktest($mapping_id, $loginId, $subjectId, $facultyId); } if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } } public function mocktest_practice() { $login_id = session('user_login_id'); $nparrots_model = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->uri->getSegment(2); $course_id = $this->request->uri->getSegment(3); $mocktest_id = $this->request->uri->getSegment(4); $table = 'subject_chapter_question_mapping'; $where_user = ['user_id' => $login_id, 'subject_id' => $course_id, 'chapter_id' => '0']; $data = ['user_id' => $login_id, 'selected_type' => 'subject_wise', 'subject_id' => $course_id, 'test_type' => 'Mock Test']; $result = $nparrots_model->InsertData($table, $data); $table_online_test = 'subject_chapter_question_mapping'; $where_user = ['user_id' => $login_id, 'subject_id' => $course_id, 'chapter_id' => '0']; $details = $nparrots_model->get_where_result($table_online_test, $where_user); foreach ($details as $det) { $selected_type = $det->selected_type; $chapter_id = $det->chapter_id; $subject_id = $det->subject_id; } $table_fac = 'faculty_mocktest_setting'; $where_fac = ['sub_domain_id' => $course_id, 'chapter' => '0', 'test_type' => 'Mock Test', 'mocktest_id' => $mocktest_id]; $order_by = "id"; $details_fac = $nparrots_model->getWhereOrderbyRow($table_fac, $where_fac, $order_by); $selected_type = $det->selected_type; if ($selected_type != 'subject_wise') { return json_encode(['result' => 0, 'message' => "Questions Not Added Yet!"]); } else { $table_sub = "sub_domains"; $where_sub = ['sub_domain_id' => $course_id]; $data['subject'] = $nparrots_model->getWhereRow($table_sub, $where_sub); $data['course_id'] = $course_id; $data['details'] = $nparrots_model->get_where_result($table_online_test, $where_user); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id]; $get_det = $nparrots_model->getWhereRow($table, $where); $batch_id = json_decode($get_det->batch_ids); $faculty_id = json_decode($get_det->faculty_ids); if ($batch_id != "") { $table = 'batches'; $get_batch = $nparrots_model->getWhereLikeBatch($table, $batch_id); $fac_id = $get_batch->faculty_id; $data['questions'] = $nparrots_model->getMockTestSubjectQuestions($subject_id, $fac_id, $mocktest_id); $table_fac = "faculty_mocktest_setting"; $where = ['test_type' => 'Mock Test', 'sub_domain_id' => $course_id, 'delete_status' => 'ACTIVE', 'chapter' => '0', 'created_by' => $fac_id, 'mocktest_id' => $mocktest_id]; $order_by = 'id'; $data['check'] = $nparrots_model->getWhereRowOrderby($table_fac, $where, $order_by); } else { $data['questions'] = $nparrots_model->getMockTestSubjectQuestions($subject_id, $faculty_id, $mocktest_id); $data['check'] = $nparrots_model->getWhereLikeFaculty($faculty_id, $course_id); } $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrots_model->getWhereRow($table, $where); $course_id = $res->course_id; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrots_model->getWhereRow($table, $where); $course = $res->course_title; $data['course_title'] = $course; return view('user/user_practice_welcome_page', $data); } } } public function view_reports_final() { $session = session(); $login_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $table = "question_mapping"; $where = ['user_id' => $login_id, 'chapter_id' => 0, 'test_type' => 'Final Test']; $order_by = 'test_id'; $result = $nparrotsModel->getWhereRowOrderby($table, $where, $order_by); if ($result) { return $this->response->setJSON(['result' => 1, 'data' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Report available']); } } else { return redirect()->to('/'); } } public function finaltest_result_report() { $nparrotsModel = new Courses_Model(); $login_id = session('user_login_id'); if ($login_id) { $test_id = $this->request->uri->getSegment(4); $mapping_id = $this->request->uri->getSegment(2); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); if ($res !== null) { $course_id = $res->course_id; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = $res->course_title; $data['course_title'] = $course; $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id]; $get_test_id = $nparrotsModel->getWhereRow($table, $where); if ($get_test_id->chapter_id == "0") { $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; $get_test_ids = $nparrotsModel->getWhereRow($table, $where); $test_id = $get_test_ids->test_id; $chapter_id = $get_test_ids->chapter_id; $mocktest_id = $get_test_ids->mocktest_id; $sub_domain_id = $get_test_ids->subject_id; $quest_id = $get_test_ids->question_id; $faculty_id = $get_test_ids->faculty_id; $det = $nparrotsModel->getWhereUserDetails($login_id); $data['mapping_id'] = $mapping_id; $question_table = 'questions'; $where_sub_domain_id = ['status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->getQuestionsForFinalTestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id); $data['tot_questions'] = $nparrotsModel->get_where_result1($question_table, $where_sub_domain_id); $data['total_questions'] = count($data['tot_questions']); $table = "sub_domains"; $where = ['sub_domain_id' => $sub_domain_id]; $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); $data['correct_answer'] = $nparrotsModel->subjectWiseCorrectAnswer($sub_domain_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); $data['mocktest_id'] = $mocktest_id; $table = 'question_mapping'; $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); $check_attempt = $nparrotsModel->get_where_result($table, $where); if ($check_attempt) { $data['finals'] = '1'; } else { $data['finals'] = '0'; } return view('user/finaltest_result_report', $data); } } else { // Handle the case when no matching record is found in 'user_course_mapping' // For example, you can redirect the user or show an error message } } } public function get_subject_wise_reportresult($testId) { $session = session(); $loginId = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($loginId) { $table = 'question_mapping'; $where = ['test_id' => $testId, 'user_id' => $loginId]; $getTestId = $nparrotsModel->getWhereRow($table, $where); if ($getTestId && is_object($getTestId)) { $subDomainId = $getTestId->subject_id; $correctAnswer = $nparrotsModel->subjectWiseCorrectAnswer($subDomainId, $loginId, $testId); $incorrectAnswer = $nparrotsModel->subjectWiseIncorrectAnswer($subDomainId, $loginId, $testId); $notAttemptedAnswer = $nparrotsModel->subjectWiseNotAttemptedAnswer($subDomainId, $loginId, $testId); $data = [ 'correct_answer' => $correctAnswer, 'incorrect_answer' => $incorrectAnswer, 'not_attempted_answer' => $notAttemptedAnswer, ]; return $this->response->setJSON(['data' => $data]); } } } public function get_finalsubject_chapter_wise_questions() { $qid = $this->request->getPost('question_id'); $nparrotsModel = new Amcad_Home(); $table = 'questions'; $where = ['qid' => $qid]; $getDet = $nparrotsModel->getWhereRow($table, $where); $userId = session('user_login_id'); $subdomainId = $this->request->getPost('sub_domain_id'); $whereQuest = ['user_id' => $userId, 'subject_id' => $subdomainId]; $mapTable = 'question_mapping'; $getTestId = $nparrotsModel->getWhereResult($mapTable, $whereQuest); $chapterId = 0; $testId = null; foreach ($getTestId as $value) { $testId = $value->test_id; } $correctAnswer = $nparrotsModel->getUserChapterAnswer($chapterId, $userId, $testId, $qid, $subdomainId); if ($getDet) { return json_encode(['result' => 1, 'details' => $getDet, 'user_answer' => $correctAnswer]); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong..!']); } } public function user_final_test() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->uri->getSegment(2); $course_id = $this->request->uri->getSegment(3); $table = 'subject_chapter_question_mapping'; $where_user = ['user_id' => $login_id, 'subject_id' => $course_id, 'chapter_id' => '0']; $data = ['user_id' => $login_id, 'selected_type' => 'final_test', 'subject_id' => $course_id, 'test_type' => 'Final Test']; $result = $nparrotsModel->InsertData($table, $data); $tableOnlineTest = 'subject_chapter_question_mapping'; $whereUser = ['user_id' => $login_id, 'subject_id' => $course_id, 'chapter_id' => '0']; $details = $nparrotsModel->get_where_result1($tableOnlineTest, $whereUser); $selectedType = null; $chapterId = null; $subjectId = null; foreach ($details as $det) { $selectedType = $det->selected_type; $chapterId = $det->chapter_id; $subjectId = $det->subject_id; } $tableFac = 'faculty_mocktest_setting'; $whereFac = ['sub_domain_id' => $course_id, 'chapter' => '0', 'test_type' => 'Final Test']; $orderBy = "id"; $detailsFac = $nparrotsModel->getWhereOrderbyRow($tableFac, $whereFac, $orderBy); if ($selectedType != 'final_test') { echo json_encode(['result' => 0, 'message' => "Questions Not Added Yet!"]); } else { $tableSub = "sub_domains"; $whereSub = ['sub_domain_id' => $course_id]; $data['subject'] = $nparrotsModel->getWhereRow($tableSub, $whereSub); $data['course_id'] = $course_id; $data['details'] = $nparrotsModel->getWhereResult($tableOnlineTest, $whereUser); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id]; $getDet = $nparrotsModel->getWhereRow($table, $where); $batchId = null; $facultyId = null; if ($getDet !== null && is_object($getDet)) { $batchId = json_decode($getDet->batch_ids); $facultyId = json_decode($getDet->faculty_ids); } if ($batchId !== null && $batchId != "") { $table = 'batches'; $getBatch = $nparrotsModel->getWhereLikeBatch1($table, $batchId); $facId = $getBatch->faculty_id; $data['questions'] = $nparrotsModel->getFinalTestQuestions($subjectId, $facId); $tableFac = "faculty_mocktest_setting"; $where = ['test_type' => 'Final Test', 'sub_domain_id' => $course_id, 'delete_status' => 'ACTIVE', 'chapter' => '0', 'created_by' => $facId]; $orderBy = 'id'; $data['check'] = $nparrotsModel->getWhereRowOrderby($tableFac, $where, $orderBy); } else { $data['questions'] = $nparrotsModel->getFinalTestQuestions($subjectId, $facultyId); $data['check'] = $nparrotsModel->getWhereLikeFacultyForFinals($facultyId, $course_id); } $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); // Check if $res is not null and contains the expected property if ($res !== null && property_exists($res, 'course_id')) { $courseId = $res->course_id; $table = 'courses'; $where = ['course_id' => $courseId, 'delete_status' => 'ACTIVE']; $course = $nparrotsModel->getWhereRow($table, $where); // Ensure $course is not null before accessing its properties if ($course !== null && property_exists($course, 'course_title')) { $data['course_title'] = $course->course_title; } else { // Handle the case where $course is null or doesn't contain the expected property // You may set a default value or show an error message $data['course_title'] = 'Default Course Title'; } } else { // Handle the case where $res is null or doesn't contain the expected property // You may set a default value or show an error message $data['course_title'] = 'Default Course Title'; } return view('user/finaltest', $data); } } } public function get_questions_for_final_test() { $loginId = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($loginId) { $mapping_id = $this->request->uri->getSegment(2); $subDomainId = $this->request->uri->getSegment(3); $table = 'subject_chapter_question_mapping'; $where = ['subject_id' => $subDomainId, 'test_type' => 'Final Test']; $getRes = $nparrotsModel->get_where_result($table, $where); foreach ($getRes as $result) { $subjectId = $result->subject_id; } $table = 'user_course_mapping'; $where = ['user_id' => $loginId, 'delete_status' => 'ACTIVE', 'mapping_id' => $mapping_id]; $det = $nparrotsModel->getWhereRow($table, $where); $batchId = json_decode($det->batch_ids); $facultyId = json_decode($det->faculty_ids); if ($batchId != "") { $table = 'batches'; $getBatch = $nparrotsModel->getWhereLikeBatch1($table, $batchId); $facId = $getBatch->faculty_id; } else { $facId = $facultyId[0]; } $questions = $nparrotsModel->getWhereFinalTestQuestions($mapping_id, $loginId, $subDomainId, $facId); $array1 = []; foreach ($questions as $question) { $qId = $question['question_id']; $qSubjectId = $question['sub_domain_id']; $materialId = $question['material_id']; array_push($array1, $qId); } $questionId = $array1; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answeredOn = $date->format('Y-m-d'); $insertTable = 'question_mapping'; $insertData = [ 'user_id' => $loginId, 'subject_id' => $qSubjectId, 'chapter_id' => 0, 'question_id' => json_encode($questionId), 'answered_on' => $answeredOn, 'test_type' => 'Final Test', 'faculty_id' => $facId, 'test_status' => 'ONGOING', 'material_id' => $materialId, ]; $nparrotsModel->InsertData($insertTable, $insertData); $resultTest = $nparrotsModel->get_last_row(); $testId = $resultTest->test_id; $subjectIds = $resultTest->subject_id; $data['questions'] = $nparrotsModel->getLeftSideFinalQuestions($mapping_id, $testId, $loginId, $subjectIds, $facId); foreach ($questions as $quests) { $subDomainId = $quests['sub_domain_id']; } $data['limitationQuestions'] = $nparrotsModel->finalTestLimitationQuestions($mapping_id, $testId, $loginId, $subjectIds); $data['markForLater'] = $nparrotsModel->finalTestMarkLater($subDomainId, $loginId, $testId); $table = "answered_questions"; $where = ['mark_for_later' => 'YES', 'test_type' => 'subject_wise', 'test_id' => $testId]; $data['markNumber'] = $nparrotsModel->getWhereResult($table, $where); $facTable = 'faculty_mocktest_setting'; $whereFac = ['test_type' => 'Final Test', 'sub_domain_id' => $subDomainId, 'chapter' => 0, 'delete_status' => 'ACTIVE']; $orderBy = 'id'; $data['totalSubjectWiseQuestions'] = $nparrotsModel->getWhereOrderbyRow($facTable, $whereFac, $orderBy); $tableSub = "sub_domains"; $whereSub = ['sub_domain_id' => $subDomainId]; $data['subject'] = $nparrotsModel->getWhereRow($tableSub, $whereSub); $tableOnlineTest = 'subject_chapter_question_mapping'; $whereUser = ['user_id' => $loginId, 'test_type' => 'Final Test']; $data['details'] = $nparrotsModel->get_where_result($tableOnlineTest, $whereUser); $details = $nparrotsModel->get_where_result($tableOnlineTest, $whereUser); foreach ($details as $det) { $selectedType = $det->selected_type; } $data['courseId'] = $subDomainId; $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $loginId, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $courseId = $res->course_id; $table = 'courses'; $where = ['course_id' => $courseId, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = $res->course_title; $data['courseTitle'] = $course; return view('user/user_final_test', $data); } } public function mark_as_later_finals() { $nparrotsModel = new Amcad_Home(); $loginId = session()->get('user_login_id'); $table = "answered_questions"; $qid = $this->request->getPost('qid'); $questionNumber = $this->request->getPost('question_number'); $resultTest = $nparrotsModel->get_last_row(); $testId = $resultTest->test_id; $where = [ 'test_id' => $testId, 'question_id' => $qid, 'test_type' => 'final_test', ]; $markResult = $nparrotsModel->getWhereRow($table, $where); if (empty($markResult)) { $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $answeredOn = $date->format('Y-m-d'); $resultTest = $nparrotsModel->get_last_row(); $testId = $resultTest->test_id; $subjectId = $resultTest->subject_id; $data = [ 'answered_by' => $loginId, 'mark_for_later' => 'YES', 'question_number' => $questionNumber, 'question_id' => $qid, 'answered_on' => $answeredOn, 'test_type' => 'final_test', 'test_id' => $testId, 'sub_domain_id' => $subjectId, 'chapter_id' => 0, ]; $insertResult = $nparrotsModel->InsertData($table, $data); $where = ['answer_id' => $insertResult]; $result = $nparrotsModel->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Marked for later', 'mark_data' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something wrong...']); } } else { $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $answeredOn = $date->format('Y-m-d'); $resultTest = $nparrotsModel->get_last_row(); $testId = $resultTest->test_id; $where = ['test_id' => $testId, 'question_id' => $qid, 'test_type' => 'final_test']; $data = [ 'answered_by' => $loginId, 'mark_for_later' => 'YES', 'question_number' => $questionNumber, 'question_id' => $qid, 'answered_on' => $answeredOn, 'test_type' => 'final_test', 'test_id' => $testId, ]; $updateResult = $nparrotsModel->UpdateData($table, $data, $where); $where = ['test_id' => $testId, 'question_id' => $qid, 'test_type' => 'final_test']; $result = $nparrotsModel->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Mark as later', 'mark_data' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong!']); } } } public function next_question_for_finals() { $loginId = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($loginId) { $table = "answered_questions"; $mapping_id = $this->request->getPost('mapping_id'); $qid = $this->request->getPost('qid'); $subDomainId = $this->request->getPost('cid'); $resultTest = $nparrotsModel->get_last_row(); $testId = $resultTest->test_id; $result = $nparrotsModel->nextQuestionForFinals($mapping_id, $qid, $subDomainId, $testId, $loginId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } } } public function previous_question_for_finals() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->getPost('mapping_id'); $qid = $this->request->getPost('qid'); $sub_domain_id = $this->request->getPost('cid'); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $result = $nparrotsModel->previousQuestionForFinals($mapping_id, $test_id, $qid, $sub_domain_id, $login_id); if ($result) { return json_encode(['result' => 1, 'message' => $result]); } else { return json_encode(['result' => 0, 'message' => 'No questions available']); } } } public function next_question() { // die(); $session = \Config\Services::session(); $login_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $table = "answered_questions"; $mapping_id = $this->request->getPost('mapping_id'); $qid = $this->request->getPost('qid'); $chapter_id = $this->request->getPost('cid'); $result_test = $nparrotsModel->get_test_id($chapter_id,$login_id); $test_id = $result_test->test_id; $sub_domain_id = $result_test->subject_id; $result = $nparrotsModel->next_question($mapping_id, $qid, $chapter_id, $sub_domain_id, $test_id, $login_id); // print_r($result); // $db = \Config\Database::connect(); // echo $db->getLastQuery(); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } } public function get_marked_chapter_questions() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $chapter_id = $result_test->chapter_id; $subject_id = $result_test->subject_id; $result = $nparrotsModel->get_marked_chapter_questions($login_id, $test_id, $subject_id, $chapter_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something wrong...']); } } public function previous_question() { $login_id = session()->get('user_login_id'); if ($login_id) { $mapping_id = $this->request->getPost('mapping_id'); $qid = $this->request->getPost('qid'); $cid = $this->request->getPost('cid'); $nparrotsModel = new Amcad_Home(); $result_test = $nparrotsModel->get_test_id($cid,$login_id); $test_id = $result_test->test_id; $sub_domain_id = $result_test->subject_id; $result = $nparrotsModel->previous_question($mapping_id, $test_id, $qid, $cid, $login_id, $sub_domain_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No questions available']); } } } public function mark_later_qus_chapter() { $session = session(); $login_id = $session->get('user_login_id'); if ($login_id) { $qid = $this->request->getPost('qid'); $cid = $this->request->getPost('cid'); $sub_domain_id = $this->request->getPost('sid'); $table = "questions"; $where = ['qid' => $qid, 'chapter_id' => $cid, 'sub_domain_id' => $sub_domain_id, 'status' => 'ACTIVE']; $nparrotsModel = new Amcad_Home(); $res = $nparrotsModel->getWhereRow($table, $where); if ($res) { $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $result = $nparrotsModel->mark_later_qus_chapter($test_id, $qid, $cid, $login_id, $sub_domain_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'No questions available']); } } } // public function insert_chapter_wise_answers() // { // $session = session(); // $login_id = $session->get('user_login_id'); // $nparrotsModel = new Amcad_Home(); // if ($login_id) { // $mvalue = $this->request->getPost('mvalue'); // $qid = $this->request->getPost('qid'); // $chapter_id = $this->request->getPost('cid'); // $table_question_mapping = 'question_mapping'; // $where_chapter = ['chapter_id' => $chapter_id]; // $order_by = 'test_id'; // $get_details = $nparrotsModel->getWhereRowOrderby4($table_question_mapping, $where_chapter, $order_by); // if (is_object($get_details) && property_exists($get_details, 'test_id')) { // $test_id = $get_details->test_id; // $sub_domain_id = $get_details->subject_id; // $result_test = $nparrotsModel->get_last_row(); // $test_id1 = $result_test->test_id; // // print_r($test_id);die(); // $table_mapping_sub_chapter = 'subject_chapter_question_mapping'; // $where_id = ['chapter_id' => $chapter_id]; // $get_det = $nparrotsModel->getWhereRow25($table_mapping_sub_chapter, $where_id); // $test_type = $get_det->selected_type; // $ans = $this->request->getPost('ans'); // $ans = empty($ans) ? "0" : $ans; // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $answered_on = $date->format('Y-m-d H:i:s'); // $table = "answered_questions"; // $where = [ // 'test_id' => $test_id1, // 'question_id' => $qid, // 'chapter_id' => $chapter_id, // 'test_type' => 'chapter_wise', // 'sub_domain_id' => $sub_domain_id // ]; // $order_by = 'test_id'; // $result = $nparrotsModel->getWhereRowOrderby($table, $where, $order_by); // if ($result !== null && is_object($result) && property_exists($result, 'mark_for_later')) { // // Access properties here // $test_id = $get_details->test_id; // $sub_domain_id = $get_details->subject_id; // if ($result->mark_for_later == "YES" && ($result->question_id == $qid) && ($result->test_type == "chapter_wise") && ($result->test_id == $test_id)) { // $where = [ // 'test_id' => $test_id, // 'question_id' => $qid, // 'test_type' => 'chapter_wise' // ]; // $data = [ // 'correct_answer' => $ans, // 'mark_for_later' => 'NO', // 'test_type' => $test_type, // 'chapter_id' => $chapter_id, // 'sub_domain_id' => $sub_domain_id // ]; // $nparrotsModel->UpdateData11($where, $table, $data); // } elseif ($result->mark_for_later == "NO" && ($result->question_id == $qid) && ($result->test_type == "chapter_wise") && ($result->test_id == $test_id)) { // $where = [ // 'test_id' => $test_id, // 'question_id' => $qid, // 'test_type' => 'chapter_wise' // ]; // $data = [ // 'correct_answer' => $ans, // 'mark_for_later' => 'NO', // 'test_type' => $test_type, // 'chapter_id' => $chapter_id, // 'sub_domain_id' => $sub_domain_id // ]; // $nparrotsModel->UpdateData11($where, $table, $data); // } elseif ($test_id1 != $test_id) { // $data = [ // 'question_id' => $qid, // 'answered_by' => $login_id, // 'test_type' => $test_type, // 'correct_answer' => $ans, // 'answered_on' => $answered_on, // 'chapter_id' => $chapter_id, // 'sub_domain_id' => $sub_domain_id, // 'test_id' => $test_id // ]; // $nparrotsModel->InsertData($table, $data); // } // } // } // } // } // public function insert_chapter_wise_answers() // { // $session = session(); // $login_id = $session->get('user_login_id'); // if (!$login_id) { // die("User not logged in"); // } // $nparrotsModel = new Amcad_Home(); // // Fetch POST values // $mvalue = $this->request->getPost('mvalue'); // $qid = $this->request->getPost('qid'); // $chapter_id = $this->request->getPost('cid'); // $ans = $this->request->getPost('ans'); // // Debug: Check if POST values are coming correctly // if (empty($qid) || empty($chapter_id)) { // die("Missing required parameters: " . print_r($_POST, true)); // } // // Fetch test details based on chapter_id // $table_question_mapping = 'question_mapping'; // $where_chapter = ['chapter_id' => $chapter_id,'user_id'=>$login_id]; // $order_by = 'test_id'; // $get_details = $nparrotsModel->getWhereRowOrderby4($table_question_mapping, $where_chapter, $order_by); // if (!is_object($get_details) || !property_exists($get_details, 'test_id')) { // die("Test details not found for chapter_id: " . $chapter_id); // } // $test_id = $get_details->test_id; // $sub_domain_id = $get_details->subject_id; // // Fetch last test row // $result_test = $nparrotsModel->get_last_row(); // if (!is_object($result_test) || !property_exists($result_test, 'test_id')) { // die("Last test record not found"); // } // $test_id1 = $result_test->test_id; // // print_r($test_id1);die(); // // Debug: Check test IDs // print_r([ // 'Fetched test_id' => $test_id, // 'Last test_id' => $test_id1 // ]); // // Fetch test type // $table_mapping_sub_chapter = 'subject_chapter_question_mapping'; // $where_id = ['chapter_id' => $chapter_id]; // $get_det = $nparrotsModel->getWhereRow25($table_mapping_sub_chapter, $where_id); // if (!is_object($get_det) || !property_exists($get_det, 'selected_type')) { // die("Test type not found for chapter_id: " . $chapter_id); // } // $test_type = $get_det->selected_type; // $ans = empty($ans) ? "0" : $ans; // // Define answered_on timestamp // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $answered_on = $date->format('Y-m-d H:i:s'); // // Check existing answer entry // $table = "answered_questions"; // $where = [ // 'test_id' => $test_id1, // 'question_id' => $qid, // 'chapter_id' => $chapter_id, // 'test_type' => 'chapter_wise', // 'sub_domain_id' => $sub_domain_id // ]; // $result = $nparrotsModel->getWhereRowOrderby($table, $where, 'test_id'); // // Debug: Print fetched existing answer entry // print_r(['Existing Answer Entry' => $result]); // if ($result !== null && is_object($result) && property_exists($result, 'mark_for_later')) { // // Access properties // if ($result->mark_for_later == "YES" && $result->question_id == $qid && $result->test_type == "chapter_wise" && $result->test_id == $test_id) { // $where = [ // 'test_id' => $test_id, // 'question_id' => $qid, // 'test_type' => 'chapter_wise' // ]; // $data = [ // 'correct_answer' => $ans, // 'mark_for_later' => 'NO', // 'test_type' => $test_type, // 'chapter_id' => $chapter_id, // 'sub_domain_id' => $sub_domain_id // ]; // // Debug: Print update data before updating // print_r(['Update Data (Mark for Later YES)' => $data]); // $nparrotsModel->UpdateData11($where, $table, $data); // } elseif ($result->mark_for_later == "NO" && $result->question_id == $qid && $result->test_type == "chapter_wise" && $result->test_id == $test_id) { // $where = [ // 'test_id' => $test_id, // 'question_id' => $qid, // 'test_type' => 'chapter_wise' // ]; // $data = [ // 'correct_answer' => $ans, // 'mark_for_later' => 'NO', // 'test_type' => $test_type, // 'chapter_id' => $chapter_id, // 'sub_domain_id' => $sub_domain_id // ]; // // Debug: Print update data before updating // print_r(['Update Data (Mark for Later NO)' => $data]); // $nparrotsModel->UpdateData11($where, $table, $data); // } // } elseif ($test_id) { // $data = [ // 'question_id' => $qid, // 'answered_by' => $login_id, // 'test_type' => $test_type, // 'correct_answer' => $ans, // 'answered_on' => $answered_on, // 'chapter_id' => $chapter_id, // 'sub_domain_id' => $sub_domain_id, // 'test_id' => $test_id // ]; // // Debug: Print final data before inserting // print_r(['Insert Data' => $data]); // $nparrotsModel->InsertData($table, $data); // // Check for database errors // $db = \Config\Database::connect(); // if ($db->error()) { // print_r(['DB Error' => $db->error()]); // die(); // } // return "Data inserted successfully!"; // } else { // die("Test IDs are the same, no insertion needed."); // } // } public function insert_chapter_wise_answers() { // die(); $session = session(); $login_id = $session->get('user_login_id'); if (!$login_id) { die("User not logged in"); } $nparrotsModel = new Amcad_Home(); // Fetch POST values $mvalue = $this->request->getPost('mvalue'); $qid = $this->request->getPost('qid'); $chapter_id = $this->request->getPost('cid'); $ans = $this->request->getPost('ans'); // Debug: Check if POST values are coming correctly if (empty($qid) || empty($chapter_id)) { die("Missing required parameters: " . print_r($_POST, true)); } // Fetch test details based on chapter_id $table_question_mapping = 'question_mapping'; $where_chapter = ['chapter_id' => $chapter_id,'user_id'=>$login_id]; $order_by = 'test_id'; $get_details = $nparrotsModel->getWhereRowOrderby4($table_question_mapping, $where_chapter, $order_by); if (!is_object($get_details) || !property_exists($get_details, 'test_id')) { die("Test details not found for chapter_id: " . $chapter_id); } $test_id = $get_details->test_id; $sub_domain_id = $get_details->subject_id; // $result_test = $nparrotsModel->get_last_row(); $result_test = $nparrotsModel->get_last_row1($test_id, $login_id); if (!is_object($result_test) || !property_exists($result_test, 'test_id')) { die("Last test record not found"); } // print_r($result_test);die(); $test_id1 = $result_test->test_id; // print_r($test_id1);die(); print_r([ 'Fetched test_id' => $test_id, 'Last test_id' => $test_id1 ]); // Fetch test type $table_mapping_sub_chapter = 'subject_chapter_question_mapping'; $where_id = ['chapter_id' => $chapter_id,"user_id"=>$login_id]; $get_det = $nparrotsModel->getWhereRow25($table_mapping_sub_chapter, $where_id); if (!is_object($get_det) || !property_exists($get_det, 'selected_type')) { die("Test type not found for chapter_id: " . $chapter_id); } $test_type = $get_det->selected_type; $ans = empty($ans) ? "0" : $ans; // Define answered_on timestamp $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d H:i:s'); // Check existing answer entry $table = "answered_questions"; $where = [ 'test_id' => $test_id1, 'question_id' => $qid, 'chapter_id' => $chapter_id, 'test_type' => 'chapter_wise', 'sub_domain_id' => $sub_domain_id ]; $result = $nparrotsModel->getWhereRowOrderby($table, $where, 'test_id'); // Debug: Print fetched existing answer entry print_r(['Existing Answer Entry' => $result]); if ($result !== null && is_object($result) && property_exists($result, 'mark_for_later')) { // Access properties if ($result->mark_for_later == "YES" && $result->question_id == $qid && $result->test_type == "chapter_wise" && $result->test_id == $test_id) { $where = [ 'test_id' => $test_id, 'question_id' => $qid, 'test_type' => 'chapter_wise' ]; $data = [ 'correct_answer' => $ans, 'mark_for_later' => 'NO', 'test_type' => $test_type, 'chapter_id' => $chapter_id, 'sub_domain_id' => $sub_domain_id ]; // Debug: Print update data before updating print_r(['Update Data (Mark for Later YES)' => $data]); //$nparrotsModel->UpdateData11($where, $table, $data); $nparrotsModel->UpdateData11( $table,$where, $data); } elseif ($result->mark_for_later == "NO" && $result->question_id == $qid && $result->test_type == "chapter_wise" && $result->test_id == $test_id) { $where = [ 'test_id' => $test_id, 'question_id' => $qid, 'test_type' => 'chapter_wise' ]; $data = [ 'correct_answer' => $ans, 'mark_for_later' => 'NO', 'test_type' => $test_type, 'chapter_id' => $chapter_id, 'sub_domain_id' => $sub_domain_id ]; // Debug: Print update data before updating print_r(['Update Data (Mark for Later NO)' => $data]); $nparrotsModel->UpdateData11($table,$where,$data); } } elseif ($test_id1) { $data = [ 'question_id' => $qid, 'answered_by' => $login_id, 'test_type' => $test_type, 'correct_answer' => $ans, 'answered_on' => $answered_on, 'chapter_id' => $chapter_id, 'sub_domain_id' => $sub_domain_id, 'test_id' => $test_id1 ]; // Debug: Print final data before inserting print_r(['Insert Data' => $data]); $nparrotsModel->InsertData($table, $data); // Check for database errors $db = \Config\Database::connect(); if ($db->error()) { print_r(['DB Error' => $db->error()]); die(); } return "Data inserted successfully!"; } else { die("Test IDs are the same, no insertion needed."); } } // public function insert_unattended_chapter_wise_answers() // { // $session = session(); // $loginId = $session->get('user_login_id'); // if ($loginId) { // $chapterId = $this->request->getPost('chapter_id'); // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $answeredOn = $date->format('Y-m-d H:i:s'); // $nparrotsModel = new Amcad_Home(); // $table = "question_mapping"; // $where = ['chapter_id' => $chapterId]; // $orderBy = 'test_id'; // $test = $nparrotsModel->getWhereRowOrderBy($table, $where, $orderBy); // $testId = $test->test_id; // $subDomainId = $test->subject_id; // $answerTable = 'answered_questions'; // $whereAnsweredQuestions = ['answered_by' => $loginId, 'test_id' => $testId]; // $getAnsweredQuestions = $nparrotsModel->getWhereResult15($answerTable, $whereAnsweredQuestions); // if (empty($getAnsweredQuestions)) { // $testId = $test->test_id; // $testQuestions = json_decode($test->question_id); // foreach ($testQuestions as $testQuests) { // $answerTable = 'answered_questions'; // $questions = $testQuests; // $data = [ // 'answered_by' => $loginId, // 'question_id' => $questions, // 'test_type' => 'chapter_wise', // 'correct_answer' => '0', // 'test_id' => $testId, // 'answered_on' => $answeredOn, // 'sub_domain_id' => $subDomainId, // 'chapter_id' => $chapterId // ]; // $result = $nparrotsModel->insertData23($answerTable,$data); // $table = 'question_mapping'; // $where = ['test_id' => $testId, 'test_status' => 'ONGOING']; // $data = ['test_status' => 'COMPLETED']; // // print_r($data);die(); // $res = $nparrotsModel->UpdateData2($where, $table, $data); // } // } else { // $whereQuests = ['chapter_id' => $chapterId, 'user_id' => $loginId, 'test_id' => $testId]; // $orderBy = 'test_id'; // $getQuestionsMapping = $nparrotsModel->getWhereRowOrderBy($table, $where, $orderBy); // $questionId = $getQuestionsMapping->question_id; // $questionIds = json_decode($getQuestionsMapping->question_id); // $getQuests = $nparrotsModel->getWhereQuestionsChapters($questionIds, $testId, $chapterId); // foreach ($getQuests as $unAnswered) { // $unansweredQuest = $unAnswered; // $answerTable = 'answered_questions'; // $data = [ // 'answered_by' => $loginId, // 'question_id' => $unansweredQuest, // 'test_type' => 'chapter_wise', // 'correct_answer' => '0', // 'test_id' => $testId, // 'answered_on' => $answeredOn, // 'sub_domain_id' => $subDomainId, // 'chapter_id' => $chapterId // ]; // $result = $nparrotsModel->insertData23($answerTable,$data); // $table = 'question_mapping'; // $where = ['test_id' => $testId, 'test_status' => 'ONGOING']; // $data = ['test_status' => 'COMPLETED']; // $res = $nparrotsModel->UpdateData2($where, $table, $data); // } // } // } // } public function insert_unattended_chapter_wise_answers() { $session = session(); $loginId = $session->get('user_login_id'); if ($loginId) { $chapterId = $this->request->getPost('chapter_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $answeredOn = $date->format('Y-m-d H:i:s'); $nparrotsModel = new Amcad_Home(); $table = "question_mapping"; $where = ['chapter_id' => $chapterId,"user_id"=>$loginId]; $orderBy = 'test_id'; $test = $nparrotsModel->getWhereRowOrderBy($table, $where, $orderBy); $testId = $test->test_id; $subDomainId = $test->subject_id; $answerTable = 'answered_questions'; $whereAnsweredQuestions = ['answered_by' => $loginId, 'test_id' => $testId]; $getAnsweredQuestions = $nparrotsModel->getWhereResult15($answerTable, $whereAnsweredQuestions); // print_r($getAnsweredQuestions); if (empty($getAnsweredQuestions)) { $testId = $test->test_id; $testQuestions = json_decode($test->question_id); foreach ($testQuestions as $testQuests) { $answerTable = 'answered_questions'; $questions = $testQuests; $data = [ 'answered_by' => $loginId, 'question_id' => $questions, 'test_type' => 'chapter_wise', 'correct_answer' => '0', 'test_id' => $testId, 'answered_on' => $answeredOn, 'sub_domain_id' => $subDomainId, 'chapter_id' => $chapterId ]; $result = $nparrotsModel->insertData23($answerTable,$data); } $table = 'question_mapping'; $where = ['test_id' => $testId, 'test_status' => 'ONGOING',"user_id"=>$loginId]; $data = ['test_status' => 'COMPLETED']; // print_r($data);die(); $res = $nparrotsModel->UpdateData2($table,$where,$data); } else { $whereQuests = ['chapter_id' => $chapterId, 'user_id' => $loginId, 'test_id' => $testId]; $orderBy = 'test_id'; $getQuestionsMapping = $nparrotsModel->getWhereRowOrderBy($table, $where, $orderBy); $questionId = $getQuestionsMapping->question_id; $questionIds = json_decode($getQuestionsMapping->question_id); $getQuests = $nparrotsModel->getWhereQuestionsChapters($questionIds, $testId, $chapterId,$loginId); foreach ($getQuests as $unAnswered) { $unansweredQuest = $unAnswered; $answerTable = 'answered_questions'; $data = [ 'answered_by' => $loginId, 'question_id' => $unansweredQuest, 'test_type' => 'chapter_wise', 'correct_answer' => '0', 'test_id' => $testId, 'answered_on' => $answeredOn, 'sub_domain_id' => $subDomainId, 'chapter_id' => $chapterId ]; $result = $nparrotsModel->insertData23($answerTable,$data); } $table = 'question_mapping'; $where = ['test_id' => $testId, 'test_status' => 'ONGOING',"user_id"=>$loginId]; $data = ['test_status' => 'COMPLETED']; $res = $nparrotsModel->UpdateData2($table,$where,$data); } } } // public function online_test_result_chapter_wise() // { // $login_id = session('user_login_id'); // $nparrotsModel = new Amcad_Home(); // if ($login_id) { // $mapping_id = $this->request->uri->getSegment(2); // $table = 'user_course_mapping'; // $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // $course_id = $res->course_id; // $table = 'courses'; // $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // $course = $res->course_title; // $data['course_title'] = $course; // $chapter_id = $this->request->uri->getSegment(3); // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $answered_on = $date->format('Y-m-d H:i:s'); // $table = "question_mapping"; // $where = ['chapter_id' => $chapter_id]; // $order_by = 'test_id'; // $test = $nparrotsModel->getWhereRowOrderBy($table, $where, $order_by); // $test_id = $test->test_id; // $sub_domain_id = $test->subject_id; // $chapter_id = $test->chapter_id; // $answer_table = 'answered_questions'; // $where_answered_questions = ['answered_by' => $login_id, 'test_id' => $test_id]; // $get_answered_questions = $nparrotsModel->get_where_result($answer_table, $where_answered_questions); // if (empty($get_answered_questions)) { // $test_id = $test->test_id; // $test_questions = json_decode($test->question_id); // foreach ($test_questions as $test_quests) { // $answer_table = 'answered_questions'; // $questions = $test_quests; // $data = [ // 'answered_by' => $login_id, // 'question_id' => $questions, // 'test_type' => 'chapter_wise', // 'correct_answer' => '0', // 'test_id' => $test_id, // 'answered_on' => $answered_on, // 'chapter_id' => $chapter_id, // 'sub_domain_id' => $sub_domain_id // ]; // $result = $this->db->table($answer_table)->insert($data); // $table = 'question_mapping'; // $where = ['test_id' => $test_id]; // $data = ['test_status' => 'COMPLETED', 'test_status' => 'ONGOING']; // $res = $nparrotsModel->UpdateData($where, $table, $data); // } // } else { // $where_quests = ['chapter_id' => $chapter_id, 'user_id' => $login_id, 'test_id' => $test_id]; // $order_by = 'test_id'; // $get_questions_mapping = $nparrotsModel->getWhereRowOrderBy($table, $where, $order_by); // $question_id = $get_questions_mapping->question_id; // $question_ids = json_decode($get_questions_mapping->question_id); // $get_quests = $nparrotsModel->get_where_questions_chapters($question_ids, $test_id, $chapter_id); // foreach ($get_quests as $un_answered) { // $unanswered_quest = $un_answered; // $answer_table = 'answered_questions'; // $data = [ // 'answered_by' => $login_id, // 'question_id' => $unanswered_quest, // 'test_type' => 'chapter_wise', // 'correct_answer' => '0', // 'test_id' => $test_id, // 'answered_on' => $answered_on, // 'chapter_id' => $chapter_id, // 'sub_domain_id' => $sub_domain_id // ]; // $result = $this->db->table($answer_table)->insert($data); // $table = 'question_mapping'; // $where = ['test_id' => $test_id]; // $data = ['test_status' => 'COMPLETED', 'test_status' => 'ONGOING']; // $res = $nparrotsModel->UpdateData($where, $table, $data); // } // } // $table = 'question_mapping'; // $where = ['chapter_id' => $chapter_id, 'user_id' => $login_id]; // $get_test_id = $nparrotsModel->get_where_result($table, $where); // foreach ($get_test_id as $value) { // $test_id = $value->test_id; // $quest_id = $value->question_id; // $faculty_id = $value->faculty_id; // } // $table = "syllabus_chapter"; // $where = ['chapter_id' => $chapter_id]; // $data['chapter_name'] = $nparrotsModel->getWhereRow($table, $where); // $question_table = 'questions'; // $where_chapter = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->getQuestionsForPracticeReview($sub_domain_id, $quest_id, $test_id, $faculty_id); // $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_chapter); // $data['total_questions'] = count($data['tot_questions']); // $data['correct_answer'] = $nparrotsModel->correct_answer($chapter_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->incorrect_answer($chapter_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->not_attempted_answer($chapter_id, $login_id, $test_id); // $where = ['mapping_id' => $mapping_id]; // $table = 'user_course_mapping'; // $det = $nparrotsModel->getWhereRow($table, $where); // $sub_domain_id = json_decode($det->sub_domain_ids); // $sub_domain_table = 'sub_domains'; // $where = ['sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE']; // $data['sub_domain'] = $nparrotsModel->get_where_in($sub_domain_table, $where); // $data['mapping_id'] = $mapping_id; // return view('user/online_test_result_chapter_wise', $data); // } // } public function online_test_result_chapter_wise() { $login_id = session('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->uri->getSegment(2); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); if ($res && is_object($res)) { $course_id = $res->course_id; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = $res->course_title; $data['course_title'] = $course; // $chapter_id = $this->request->uri->getSegment(4); $chapter_id = $this->request->uri->getSegment(3); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d H:i:s'); $table = "question_mapping"; $where = ['chapter_id' => $chapter_id,"user_id"=>$login_id]; $order_by = 'test_id'; $test = $nparrotsModel->getWhereRowOrderBy($table, $where, $order_by); $test_id = $test->test_id; $sub_domain_id = $test->subject_id; $chapter_id = $test->chapter_id; $answer_table = 'answered_questions'; $where_answered_questions = ['answered_by' => $login_id, 'test_id' => $test_id]; $get_answered_questions = $nparrotsModel->get_where_result24($answer_table, $where_answered_questions); if (empty($get_answered_questions)) { $test_id = $test->test_id; $test_questions = json_decode($test->question_id); foreach ($test_questions as $test_quests) { $answer_table = 'answered_questions'; $questions = $test_quests; $answer_data = [ 'answered_by' => $login_id, 'question_id' => $questions, 'test_type' => 'chapter_wise', 'correct_answer' => '0', 'test_id' => $test_id, 'answered_on' => $answered_on, 'chapter_id' => $chapter_id, 'sub_domain_id' => $sub_domain_id ]; $result = $nparrotsModel->insert11($answer_table,$answer_data); $table = 'question_mapping'; $where = ['test_id' => $test_id]; // $data = ['test_status' => 'COMPLETED', 'test_status' => 'ONGOING']; $data = ['test_status' => 'COMPLETED']; $res = $nparrotsModel->UpdateData($table,$where, $data); } } else { $where_quests = ['chapter_id' => $chapter_id, 'user_id' => $login_id, 'test_id' => $test_id]; $order_by = 'test_id'; $get_questions_mapping = $nparrotsModel->getWhereRowOrderBy($table, $where, $order_by); $question_id = $get_questions_mapping->question_id; $question_ids = json_decode($get_questions_mapping->question_id); $get_quests = $nparrotsModel->get_where_questions_chapters($question_ids, $test_id, $chapter_id); foreach ($get_quests as $un_answered) { $unanswered_quest = $un_answered; $answer_table = 'answered_questions'; $data = [ 'answered_by' => $login_id, 'question_id' => $unanswered_quest, 'test_type' => 'chapter_wise', 'correct_answer' => '0', 'test_id' => $test_id, 'answered_on' => $answered_on, 'chapter_id' => $chapter_id, 'sub_domain_id' => $sub_domain_id ]; // $result = $nparrotsModel->table($answer_table)->insert($data); $result = $nparrotsModel->insert_data($answer_table,$data); $table = 'question_mapping'; $where = ['test_id' => $test_id]; $data = ['test_status' => 'COMPLETED']; $res = $nparrotsModel->UpdateData11($table,$where,$data); } } $table = 'question_mapping'; $where = ['chapter_id' => $chapter_id, 'user_id' => $login_id]; $get_test_id = $nparrotsModel->get_where_result($table, $where); foreach ($get_test_id as $value) { $test_id = $value->test_id; $quest_id = $value->question_id; $faculty_id = $value->faculty_id; } $table = "syllabus_chapter"; $where = ['chapter_id' => $chapter_id]; $data['chapter_name'] = $nparrotsModel->getWhereRow($table, $where); $question_table = 'questions'; $where_chapter = ['status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->getQuestionsForPracticeReview($sub_domain_id, $quest_id, $test_id, $faculty_id,$chapter_id); $data['tot_questions'] = $nparrotsModel->get_where_result26($question_table, $where_chapter); $data['total_questions'] = count($data['tot_questions']); $data['correct_answer'] = $nparrotsModel->correct_answer($chapter_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->incorrect_answer($chapter_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->not_attempted_answer($chapter_id, $login_id, $test_id); // print_r($data['not_attempted_answer']);die(); $where = ['mapping_id' => $mapping_id]; $table = 'user_course_mapping'; $det = $nparrotsModel->getWhereRow($table, $where); $sub_domain_id = json_decode($det->sub_domain_ids); $sub_domain_table = 'sub_domains'; $where = ['sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE']; $data['sub_domain'] = $nparrotsModel->get_where_in1($sub_domain_table, $where); $data['mapping_id'] = $mapping_id; return view('user/online_test_result_chapter_wise', $data); } } } public function mark_later_qus_finals() { $loginId = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($loginId) { $qid = $this->request->getPost('qid'); $cid = $this->request->getPost('cid'); $table = 'questions'; $where = ['qid' => $qid, 'chapter_id' => $cid]; $rowData = $nparrotsModel->getWhereRow($table, $where); if ($rowData) { $resultTest = $nparrotsModel->get_last_row(); $testId = $resultTest->test_id; $subDomainId = $rowData->sub_domain_id; $result = $nparrotsModel->markLaterQusFinals($testId, $loginId, $qid, $subDomainId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No questions available']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'No questions available']); } } } public function insert_finals_answers() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mvalue = $this->request->getPost('mvalue'); $qid = $this->request->getPost('qid'); $sub_domain_id = $this->request->getPost('cid'); $table_question_mapping = 'question_mapping'; $where_sub_domain = ['subject_id' => $sub_domain_id, 'test_type' => 'Final Test']; $order_by = 'test_id'; $get_details = $nparrotsModel->getWhereRowOrderby1($table_question_mapping, $where_sub_domain, $order_by); // Check if $get_details is an object and has test_id property if (is_object($get_details) && property_exists($get_details, 'test_id')) { $test_id = $get_details->test_id; $result_test = $nparrotsModel->get_last_row(); $test_id1 = $result_test->test_id; $table_mapping_sub_chapter = 'subject_chapter_question_mapping'; $where_id = ['subject_id' => $sub_domain_id, 'test_type' => 'Final Test']; $get_det = $nparrotsModel->getWhereRow26($table_mapping_sub_chapter, $where_id); $test_type = $get_det->selected_type; $ans = $this->request->getPost('ans'); $ans = empty($ans) ? "0" : $ans; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d H:i:s'); $table = "answered_questions"; $where = ['question_id' => $qid, 'test_type' => 'final_test', 'sub_domain_id' => $sub_domain_id]; $order_by = 'test_id'; $mark_result = $nparrotsModel->getWhereRow($table, $where); $result = $nparrotsModel->getWhereRowOrderby($table, $where, $order_by); $res_test_id = is_object($result) ? $result->test_id : null; if ($result && $result->mark_for_later == "YES" && $result->question_id == $qid && $result->test_type == "final_test" && $result->test_id == $test_id1) { $table = "answered_questions"; $qid = $this->request->getPost('qid'); $sub_domain_id = $this->request->getPost('cid'); $ans = $this->request->getPost('ans'); $ans = empty($ans) ? 0 : $ans; $where = ['question_id' => $qid, 'test_type' => 'final_test']; $data = ['correct_answer' => $ans, 'mark_for_later' => 'NO', 'test_type' => $test_type, 'test_id' => $test_id, 'sub_domain_id' => $sub_domain_id]; $nparrotsModel->UpdateData123($where, $table, $data); } elseif ($result && $result->mark_for_later == "NO" && $result->question_id == $qid && $result->test_type == "final_test" && $result->test_id == $test_id1) { $qid = $this->request->getPost('qid'); $sub_domain_id = $this->request->getPost('cid'); $ans = $this->request->getPost('ans'); $ans = empty($ans) ? 0 : $ans; $where = ['question_id' => $qid, 'test_type' => 'final_test']; $data = ['correct_answer' => $ans, 'mark_for_later' => 'NO', 'test_type' => $test_type, 'test_id' => $test_id, 'sub_domain_id' => $sub_domain_id]; $nparrotsModel->UpdateData123($where, $table, $data); } elseif ($res_test_id != $test_id) { $data = [ 'question_id' => $qid, 'answered_by' => $login_id, 'test_type' => $test_type, 'correct_answer' => $ans, 'answered_on' => $answered_on, 'test_id' => $test_id, 'sub_domain_id' => $sub_domain_id ]; $nparrotsModel->InsertData($table, $data); } } else { // Handle the case where $get_details is not as expected // Log an error or perform necessary actions // Example: log_message('error', 'Unable to retrieve test_id from get_details'); } } } public function insert_unattended_finals_answers() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $subject_id = $this->request->getPost('subject_id'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d H:i:s'); $table = "question_mapping"; $where = ['subject_id' => $subject_id, 'test_type' => 'Final Test']; $order_by = 'test_id'; $test = $nparrotsModel->getWhereRowOrderby($table, $where, $order_by); if ($test) { $test_id = $test->test_id; $answer_table = 'answered_questions'; $where_answered_questions = ['answered_by' => $login_id, 'test_id' => $test_id]; $get_answered_questions = $nparrotsModel->get_where_result2($answer_table, $where_answered_questions); if (empty($get_answered_questions)) { $test_id = $test->test_id; $test_questions = json_decode($test->question_id); foreach ($test_questions as $test_quests) { $answer_table = 'answered_questions'; $questions = $test_quests; $data = [ 'answered_by' => $login_id, 'question_id' => $questions, 'test_type' => 'final_test', 'correct_answer' => '0', 'test_id' => $test_id, 'answered_on' => $answered_on, 'sub_domain_id' => $subject_id ]; $result = $nparrotsModel->insert_data($answer_table, $data); $table = 'question_mapping'; $where = ['test_id' => $test_id, 'test_status' => 'ONGOING']; $data = ['test_status' => 'COMPLETED']; $res = $nparrotsModel->UpdateData2($where, $table, $data); } } else { $where_quests = ['subject_id' => $subject_id, 'user_id' => $login_id, 'test_id' => $test_id]; $order_by = 'test_id'; $get_questions_mapping = $nparrotsModel->getWhereRowOrderby2($table, $where_quests, $order_by); $question_id = $get_questions_mapping->question_id; $question_ids = json_decode($get_questions_mapping->question_id); $get_quests = $nparrotsModel->getWhereQuestionsSubjects1($question_ids, $test_id, $subject_id); foreach ($get_quests as $un_answered) { $unanswered_quest = $un_answered; $answer_table = 'answered_questions'; $data = [ 'answered_by' => $login_id, 'question_id' => $unanswered_quest, 'test_type' => 'final_test', 'correct_answer' => '0', 'test_id' => $test_id, 'answered_on' => $answered_on, 'sub_domain_id' => $subject_id ]; $result = $nparrotsModel->insert_data($answer_table, $data); $table = 'question_mapping'; $where = ['test_id' => $test_id, 'test_status' => 'ONGOING']; $data = ['test_status' => 'COMPLETED']; $res = $nparrotsModel->UpdateData2($where, $table, $data); } } } } } public function get_marked_finaltest_questions() { $loginId = session()->get('user_login_id'); $table = "answered_questions"; $nparrotsModel = new Amcad_Home(); $resultTest = $nparrotsModel->get_last_row(); $testId = $resultTest->test_id; $chapterId = $resultTest->chapter_id; $subjectId = $resultTest->subject_id; $result = $nparrotsModel->getMarkedFinalTestQuestions($loginId, $testId, $subjectId, $chapterId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something wrong...']); } } // public function get_chapter_material() // { // $ids = explode(',', $this->request->getPost('id')); // $chapter_model = new chapter_material(); // $data = [ // 'topic_id' => $ids[0], // '$mapping_id' => $ids[1] // ]; // // $result = $chapter_model->get_chapter_material($topic_id, $mapping_id); // // if ($result) { // // return $this->response->setJSON(['result' => 1, $data] ); // // } else { // // return $this->response->setJSON(['result' => 0, 'message' => 'Materials not available for this topic']); // // } // if (count($ids) < 2) { // return $this->response->setJSON(['result' => 0, 'message' => 'Invalid input']); // } // $topic_id = $ids[0]; // $mapping_id = $ids[1]; // try { // $result = $chapter_model->get_chapter_material($topic_id, $mapping_id); // return $this->response->setJSON(['result' => 1, 'data' => $data]); // } catch (Exception $e) { // return $this->response->setJSON(['result' => 0, 'message' => 'Error retrieving chapter material']); // } // } // public function get_chapter_material() // { // $ids = explode(',', $this->request->getPost('id')); // $chapter_model = new chapter_material(); // $result = $chapter_model->get_chapter_material($ids[0], $ids[1]); // if ($result) { // return $this->response->setJSON(['result' => 1, 'topic_id' => $ids[0], 'mapping_id' => $ids[1]]); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Materials not available for this topic']); // } // } public function get_chapter_material() { $ids = explode(',', $this->request->getPost('id')); // print_r($ids);die(); // Check if both indices exist if (isset($ids[0]) && isset($ids[1])) { $chapter_model = new chapter_material(); $result = $chapter_model->get_chapter_material($ids[0], $ids[1]); if ($result) { return $this->response->setJSON(['result' => 1, 'topic_id' => $ids[0], 'mapping_id' => $ids[1]]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Materials not available for this topic']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid input format']); } } public function get_user_chapter_topics() { $nparrotsModel = new Amcad_Home(); $ids = explode(',', $this->request->getPost('id')); $chapter_id = $ids[0]; // $mapping_id = $ids[1]; // $chapter_id = $this->request->getPost('id'); $where = ['chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE']; $table = 'topics'; $result = $nparrotsModel->get_where_result($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function chapter_wise_materials() { $login_id = session('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $data['topic_id'] = $this->request->uri->getSegment(2); $mapping_id = $this->request->uri->getSegment(3); $data['chapter_result'] = $nparrotsModel->get_topic_name($data['topic_id']); $data['mapping_subjects'] = $nparrotsModel->get_mapping_course_subjects($mapping_id); return view('user/chapter_wise_materials', $data); } else { return redirect()->to('/'); } } public function chapter_wise_material_list() { $nparrotsModel = new Amcad_Home(); $topic_id = $this->request->getPost('topic_id'); $result = $nparrotsModel->chapter_wise_material_list($topic_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function feedback() { $loginId = session()->get('user_login_id'); if ($loginId) { $mapping_id = $this->request->uri->getSegment(2); $nparrotsModel = new Amcad_Home(); $table = 'user_course_mapping'; $whereDomain = ['mapping_id' => $mapping_id]; $mappData = $nparrotsModel->getWhereRow3($table, $whereDomain); if ($mappData && !empty($mappData->course_id)) { $whereCourse = ['course_id' => $mappData->course_id]; $courseTable = 'courses'; $data['course_sub_domain'] = $nparrotsModel->getWhereRow5($courseTable, $whereCourse); if ($mappData->batch_ids == 'null') { $facultyIds = json_decode($mappData->faculty_ids); $data['faculties'] = $nparrotsModel->getFaculties($facultyIds); } else { $batch_ids = json_decode($mappData->batch_ids); $data['faculties'] = $nparrotsModel->getBatchFaculties($batch_ids); } $courseTable = 'courses'; $whereCourse = ['course_id' => $mappData->course_id, 'delete_status' => 'ACTIVE']; $data['course'] = $nparrotsModel->getWhereRow5($courseTable, $whereCourse); $sessionType = json_decode($mappData->session_type); if (in_array('Live', $sessionType)) { return view('user/feedback', $data); } else { return view('user/recorded_feedback', $data); } } else { return redirect()->to('/'); } } else { return redirect()->to('/'); } } public function add_feedback() { $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $login_id = session()->get('user_login_id'); $institution_id = session()->get('user_institution_id'); $nparrotsModel = new Amcad_Home(); $course_id = $this->request->getPost('course_id'); $feedback = $this->request->getPost('feedback'); $faculty_id = $this->request->getPost('faculty_id'); $knowledge = $this->request->getPost('knowledge'); $questions_comments = $this->request->getPost('questions_comments'); $concept_ideas = $this->request->getPost('concept_ideas'); $learnt_things = $this->request->getPost('learnt_things'); $data = [ 'institution_id' => $institution_id, 'course_id' => $course_id, 'feedback' => $feedback, 'faculty_id' => $faculty_id, 'knowledge' => $knowledge, 'questions_comments' => $questions_comments, 'concept_ideas' => $concept_ideas, 'display_status' => 'DISPLAY', 'learnt_things' => $learnt_things, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'created_at' => $created_at, ]; $feedback_table = 'feedback'; $result = $nparrotsModel->insertDataf($feedback_table, $data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Added Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } // public function review_result_report() // { // $login_id = session()->get('user_login_id'); // $nparrotsModel = new Amcad_Home(); // if ($login_id) { // $test_id = $this->request->uri->getSegment(5); // $mapping_id = $this->request->uri->getSegment(3); // $table = 'user_course_mapping'; // $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // if ($res && is_object($res)) { // $course_id = $res->course_id; // $course_title = $res->course_title; // $data['course_title'] = $course_title; // $table = 'courses'; // $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // $course = $res->course_title; // $data['course_title'] = $course; // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id]; // $get_test_id = $nparrotsModel->getWhereRow($table, $where); // if ($get_test_id->chapter_id == "0") { // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => 'Mock Test']; // $get_test_ids = $nparrotsModel->getWhereRow($table, $where); // $test_id = $get_test_ids->test_id; // $chapter_id = $get_test_ids->chapter_id; // $mocktest_id = $get_test_ids->mocktest_id; // $sub_domain_id = $get_test_ids->subject_id; // $quest_id = $get_test_ids->question_id; // $faculty_id = $get_test_ids->faculty_id; // $det = $nparrotsModel->get_where_user_details($login_id); // $data['mapping_id'] = $mapping_id; // $question_table = 'questions'; // $where_sub_domain_id = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->getQuestionsForMocktestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id); // $data['tot_questions'] = $nparrotsModel->get_where_result20($question_table, $where_sub_domain_id); // $data['total_questions'] = count($data['tot_questions']); // $table = "sub_domains"; // $where = ['sub_domain_id' => $sub_domain_id]; // $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); // $data['correct_answer'] = $nparrotsModel->subjectWiseCorrectAnswer($sub_domain_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); // $data['mocktest_id'] = $mocktest_id; // $table = 'question_mapping'; // $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; // $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); // $check_attempt = $nparrotsModel->get_where_result($table, $where); // if ($check_attempt) { // $data['finals'] = '1'; // } else { // $data['finals'] = '0'; // } // return view('user/user_subjectwise_report', $data); // } else { // $table = 'question_mapping'; // $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => '']; // $get_test_id = $nparrotsModel->getWhereRow($table, $where); // $test_id = $get_test_id->test_id; // $chapter_id = $get_test_id->chapter_id; // $mocktest_id = $get_test_id->mocktest_id; // $sub_domain_id = $get_test_id->subject_id; // $quest_id = $get_test_id->question_id; // $faculty_id = $get_test_id->faculty_id; // $table = "user_course_mapping"; // $where = ['user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $det = $nparrotsModel->getWhereLike($table, $where); // $data['mapping_id'] = $mapping_id; // $table = "syllabus_chapter"; // $where = ['chapter_id' => $chapter_id]; // $data['chapter_name'] = $nparrotsModel->getWhereRow($table, $where); // $table = "sub_domains"; // $where = ['sub_domain_id' => $sub_domain_id]; // $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); // $question_table = 'questions'; // $where_chapter = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->get_questions_for_practice_review($sub_domain_id, $quest_id, $test_id, $faculty_id); // $data['correct_answer'] = $nparrotsModel->correct_answer($chapter_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->incorrect_answer($chapter_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->not_attempted_answer($chapter_id, $login_id, $test_id); // $data['tot_questions'] = $nparrotsModel->get_where_result21($question_table, $where_chapter); // $data['total_questions'] = count($data['tot_questions']); // return view('user/user_chapterwise_report', $data); // } // } else { // } // } // } public function review_result_report() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $test_id = $this->request->uri->getSegment(4); $mapping_id = $this->request->uri->getSegment(2); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); if ($res && is_object($res)) { $course_id = $res->course_id; $course_title = isset($res->course_title) ? $res->course_title : ''; // Check if property exists $data['course_title'] = $course_title; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = isset($res->course_title) ? $res->course_title : ''; // Check if property exists $data['course_title'] = $course; $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id]; $get_test_id = $nparrotsModel->getWhereRow($table, $where); if ($get_test_id->chapter_id == "0") { $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => 'Mock Test']; $get_test_ids = $nparrotsModel->getWhereRow($table, $where); $test_id = $get_test_ids->test_id; $chapter_id = $get_test_ids->chapter_id; $mocktest_id = $get_test_ids->mocktest_id; $sub_domain_id = $get_test_ids->subject_id; $quest_id = $get_test_ids->question_id; $faculty_id = $get_test_ids->faculty_id; $det = $nparrotsModel->get_where_user_details1($login_id); $data['mapping_id'] = $mapping_id; $question_table = 'questions'; $where_sub_domain_id = ['status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->getQuestionsForMocktestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id); $data['tot_questions'] = $nparrotsModel->get_where_result11($question_table, $where_sub_domain_id); $data['total_questions'] = count($data['tot_questions']); $table = "sub_domains"; $where = ['sub_domain_id' => $sub_domain_id]; $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); $data['correct_answer'] = $nparrotsModel->subjectWiseCorrectAnswer($sub_domain_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); $data['mocktest_id'] = $mocktest_id; $table = 'question_mapping'; $where = ['user_id' => $login_id, 'test_type' => 'Final Test', 'subject_id' => $sub_domain_id]; $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); $check_attempt = $nparrotsModel->get_where_result($table, $where); if ($check_attempt) { $data['finals'] = '1'; } else { $data['finals'] = '0'; } return view('user/user_subjectwise_report', $data); } else { $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id, 'test_type' => '']; $get_test_id = $nparrotsModel->getWhereRow($table, $where); $test_id = $get_test_id->test_id; $chapter_id = $get_test_id->chapter_id; $mocktest_id = $get_test_id->mocktest_id; $sub_domain_id = $get_test_id->subject_id; $quest_id = $get_test_id->question_id; $faculty_id = $get_test_id->faculty_id; $table = "user_course_mapping"; $where = ['user_id' => $login_id, 'delete_status' => 'ACTIVE']; $det = $nparrotsModel->getWhereLike($table, $where); $data['mapping_id'] = $mapping_id; $table = "syllabus_chapter"; $where = ['chapter_id' => $chapter_id]; $data['chapter_name'] = $nparrotsModel->getWhereRow($table, $where); $table = "sub_domains"; $where = ['sub_domain_id' => $sub_domain_id]; $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); $question_table = 'questions'; $where_chapter = ['status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->get_questions_for_practice_review($sub_domain_id, $quest_id, $test_id, $faculty_id); $data['correct_answer'] = $nparrotsModel->correct_answer($chapter_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->incorrect_answer($chapter_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->not_attempted_answer($chapter_id, $login_id, $test_id); $data['tot_questions'] = $nparrotsModel->get_where_result26($question_table, $where_chapter); $data['total_questions'] = count($data['tot_questions']); return view('user/user_chapterwise_report', $data); } } else { } } } public function get_subject_chapter_wise_questions() { $nparrotsModel = new Amcad_Home(); $qid = $this->request->getPost('question_id'); $table = 'questions'; $where = ['qid' => $qid]; $get_det = $nparrotsModel->get_where_row($table, $where); $user_id = session()->get('user_login_id'); $chapter_id = $this->request->getPost('chapter_id'); // print_r($chapter_id);die(); $subdomain_id = $get_det->sub_domain_id; $where_quest = ['chapter_id' => $chapter_id, 'user_id' => $user_id]; $map_table = 'question_mapping'; // $get_test_id = $nparrotsModel->get_where_result($map_table, $where_quest); $get_test_id = $nparrotsModel->get_test_id($chapter_id,$user_id); // $test_id = null; // foreach ($get_test_id as $value) { // $test_id = $value->test_id; // } $test_id = $get_test_id->test_id; $correct_answer = $nparrotsModel->getUserChapterAnswer($chapter_id, $user_id, $test_id, $qid, $subdomain_id); // $db = \Config\Database::connect(); // echo $db->getLastQuery(); if ($get_det) { return $this->response->setJSON(['result' => 1, 'details' => $get_det, 'user_answer' => $correct_answer]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..!']); } } public function get_questions_for_test_subject_wise() { $session = session(); $login_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->uri->getSegment(2); $sub_domain_id = $this->request->uri->getSegment(3); $mocktest_id = $this->request->uri->getSegment(4); $table = 'subject_chapter_question_mapping'; $where = ['subject_id' => $sub_domain_id]; $getRes = $nparrotsModel->getWhereRow($table, $where); $type = $getRes->selected_type; $user_id = $getRes->user_id; $table = 'user_course_mapping'; $where = ['user_id' => $login_id, 'delete_status' => 'ACTIVE']; $det = $nparrotsModel->getWhereInRow($login_id, $mapping_id); $batch_id = json_decode($det->batch_ids); $faculty_id = json_decode($det->faculty_ids); if ($batch_id != "") { $table = 'batches'; $getBatch = $nparrotsModel->getWhereLikeBatch($table, $batch_id); $fac_id = $getBatch->faculty_id; $faculty_ids = $getBatch->faculty_id; } else { $fac_id = $faculty_id; $faculty_ids = $fac_id[0]; } $chapter_id = $getRes->chapter_id; $subject_id = $getRes->subject_id; $questions = $nparrotsModel->get_where_domains_subject_wise_questions($mapping_id, $login_id, $chapter_id, $subject_id, $fac_id, $mocktest_id); $array1 = []; foreach ($questions as $question) { $q_id = $question['question_id']; $q_chapter_id = $question['chapter_id']; $material_id = $question['material_id']; array_push($array1, $q_id); } $question_id = $array1; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d'); $insertTable = 'question_mapping'; $insertData = [ 'user_id' => $login_id, 'subject_id' => $subject_id, 'chapter_id' => 0, 'question_id' => json_encode($question_id), 'answered_on' => $answered_on, 'test_type' => 'Mock Test', 'mocktest_id' => $mocktest_id, 'faculty_id' => $faculty_ids, 'test_status' => 'ONGOING', 'material_id' => $material_id ]; $nparrotsModel->InsertData($insertTable, $insertData); $resultTest = $nparrotsModel->get_last_row(); $test_id = $resultTest->test_id; $subject_ids = $resultTest->subject_id; $data['questions'] = $nparrotsModel->get_where_left_subject_questions($mapping_id, $test_id, $login_id, $subject_ids, $mocktest_id); foreach ($questions as $quests) { $sub_domain_id = $quests['sub_domain_id']; } $data['limitation_questions'] = $nparrotsModel->limitation_questions_subject_wise($mapping_id, $test_id, $login_id, $subject_ids, $mocktest_id); $data['mark_for_later'] = $nparrotsModel->mark_for_later_subject_wise($subject_id, $login_id, $test_id); $table = "answered_questions"; $where = ['mark_for_later' => 'YES', 'test_type' => 'subject_wise', 'test_id' => $test_id]; $data['mark_number'] = $nparrotsModel->get_where_result($table, $where); $facTable = 'faculty_mocktest_setting'; $whereFac = ['sub_domain_id' => $sub_domain_id, 'chapter' => 0, 'delete_status' => 'ACTIVE', 'mocktest_id' => $mocktest_id]; $orderBy = 'id'; $data['total_subject_wise_questions'] = $nparrotsModel->getWhereOrderbyRow($facTable, $whereFac, $orderBy); $tableSub = "sub_domains"; $whereSub = ['sub_domain_id' => $sub_domain_id]; $data['subject'] = $nparrotsModel->getWhereRow($tableSub, $whereSub); $tableOnlineTest = 'subject_chapter_question_mapping'; $whereUser = ['user_id' => $login_id]; $data['details'] = $nparrotsModel->get_where_result($tableOnlineTest, $whereUser); $details = $nparrotsModel->get_where_result($tableOnlineTest, $whereUser); foreach ($details as $det) { $selected_type = $det->selected_type; } $data['course_id'] = $sub_domain_id; $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course_id = $res->course_id; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = $res->course_title; $data['course_title'] = $course; return view('user/user_subject_wise_test', $data); } } public function get_course_name() { $mapping_id = $this->request->getPost('mapping_id'); $nparrotsModel = new Amcad_Home(); $result = $nparrotsModel->get_course_name($mapping_id); if ($result) { return $this->response->setJSON(['result' => 1, 'course_name' => $result->course_title]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Please add training plan before adding material']); } } public function check_approved_materials() { $loginId = session()->get('user_login_id'); // print_r($loginId);die(); if ($loginId) { $chapterId = $this->request->getPost('chapter_id'); $subjectId = $this->request->getPost('subject_id'); $mappingId = $this->request->getPost('mapping_id'); // print_r($mappingId);die(); $nparrotsModel = new Amcad_Home(); $table = 'user_course_mapping'; $where = ['user_id' => $loginId, 'mapping_id' => $mappingId, 'delete_status' => 'ACTIVE']; $getFacultyId = $nparrotsModel->getWhereRow($table, $where); // print_r($where);die(); if ($getFacultyId) { $batchId = isset($getFacultyId->batch_ids) ? json_decode($getFacultyId->batch_ids, true) : null; if ($batchId != null) { $table = 'batches'; $getBatch = $nparrotsModel->getWhereLikeBatch2($table, $batchId); if ($getBatch && isset($getBatch->faculty_id)) { $facId = $getBatch->faculty_id; $result = $nparrotsModel->check_approved_materials($mappingId, $loginId, $chapterId, $subjectId, $facId); } else { $result = false; } } else { $facultyId = isset($getFacultyId->faculty_ids) ? json_decode($getFacultyId->faculty_ids) : null; if ($facultyId != null) { $result = $nparrotsModel->check_approved_materials($mappingId, $loginId, $chapterId, $subjectId, $facultyId); } else { $result = false; } } if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } } } public function get_questions_for_test_chapter_wise() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->uri->getSegment(2); $chapter_id = $this->request->uri->getSegment(3); $course_id = $this->request->uri->getSegment(3); $mapping_data = $this->db->table('faculty_mocktest_setting') ->where([ 'chapter' => $chapter_id, 'live_status' => 0 ]) ->orderBy('id', 'DESC') ->get() ->getRow(); if ($mapping_data) { return redirect()->to('/'); } $mapping_data = $this->db->table('question_mapping') ->where([ 'chapter_id' => $chapter_id, 'user_id' => $login_id ]) ->orderBy('test_id', 'DESC') ->get() ->getRow(); if ($mapping_data) { return $this->response->setJSON(['result' => 0, 'message' => "You already attended the test. Unable to take test again"]); // redirect('/'); } $table = 'subject_chapter_question_mapping'; $where = ['chapter_id' => $chapter_id]; $get_res = $nparrotsModel->getWhereRow($table, $where); $type = $get_res->selected_type; if ($type == 'chapter_wise') { $user_id = $get_res->user_id; $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $det = $nparrotsModel->getWhereRow($table, $where); if ($det) { $batch_id = json_decode($det->batch_ids); $faculty_id = json_decode($det->faculty_ids); if ($batch_id != "") { $table = 'batches'; $get_batch = $nparrotsModel->getWhereLikeBatch($table, $batch_id); $fac_id = $get_batch->faculty_id; } else { $fac_id = $faculty_id; } $chapter_id = $get_res->chapter_id; $subject_id = $get_res->subject_id; $questions = $nparrotsModel->getWhereDomainsQuestions($mapping_id, $login_id, $chapter_id, $subject_id, $fac_id); $array1 = []; foreach ($questions as $question) { // Use a different variable name for the loop variable $q_id = $question['question_id']; $q_sub_domain_id = $question['sub_domain_id']; $q_faculty_id = $question['faculty_id']; $material_id = $question['material_id']; array_push($array1, $q_id); } $question_id = $array1; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d'); $insert_table = 'question_mapping'; $insert_data = [ 'user_id' => $login_id, 'subject_id' => $q_sub_domain_id, 'chapter_id' => $chapter_id, 'question_id' => json_encode($question_id), 'answered_on' => $answered_on, 'faculty_id' => $q_faculty_id, 'test_status' => 'ONGOING', 'material_id' => $material_id, ]; $nparrotsModel->InsertData6($insert_table, $insert_data); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $data['questions'] = $nparrotsModel->getWhereLeftChapterQuestions($mapping_id, $test_id, $login_id, $chapter_id, $q_sub_domain_id, $fac_id); foreach ($questions as $quests) { $sub_domain_id = $quests['sub_domain_id']; } $table_sub_domain = 'sub_domains'; $where_sub_domain = ['sub_domain_id' => $sub_domain_id]; $get_sub_domain = $nparrotsModel->getWhereRow10($table_sub_domain, $where_sub_domain); $data['sub_domain'] = $get_sub_domain->sub_domain; $sub_domain_table = 'syllabus_chapter'; $where_chapter = ['chapter_id' => $chapter_id]; $get_dets = $nparrotsModel->getWhereRow12($sub_domain_table, $where_chapter); $data['chapter_name'] = $get_dets->chapter_name; $data['limitation_questions'] = $nparrotsModel->limitationQuestions($mapping_id, $test_id, $login_id, $chapter_id, $sub_domain_id); $data['mark_for_later'] = $nparrotsModel->markForLaterChapterWise($chapter_id, $login_id, $test_id); $where_chapter_id = ['chapter_id' => $chapter_id]; $table = "answered_questions"; $where = ['mark_for_later' => 'YES', 'test_type' => 'chapter_wise', 'test_id' => $test_id]; $data['mark_number'] = $nparrotsModel->get_where_result($table, $where); $fac_table = 'faculty_mocktest_setting'; $where_fac = ['chapter' => $chapter_id, 'sub_domain_id' => $sub_domain_id, 'created_by' => $q_faculty_id]; $order_by = 'id'; $data['total_chapter_wise_questions'] = $nparrotsModel->getWhereOrderbyRow11($fac_table, $where_fac, $order_by); } $table = "syllabus_chapter"; $where = ['chapter_id' => $course_id]; $data['chapter'] = $nparrotsModel->getWhereRow($table, $where); $table_sub = "sub_domains"; $where_sub = ['sub_domain_id' => $course_id]; $data['subject'] = $nparrotsModel->getWhereRow13($table_sub, $where_sub); $table_online_test = 'subject_chapter_question_mapping'; $where_user = ['user_id' => $login_id]; $data['details'] = $nparrotsModel->get_where_result15($table_online_test, $where_user); $details = $nparrotsModel->get_where_result15($table_online_test, $where_user); foreach ($details as $det) { $selected_type = $det->selected_type; } if ($selected_type == 'subject_wise') { $table_question = "questions"; $where_question = ['sub_domain_id' => $course_id, 'status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->get_where_result16($table_question, $where_question); } else { $table_quest = "questions"; $where_quest = ['chapter_id' => $course_id]; $data['quest'] = $nparrotsModel->get_where_result17($table_quest, $where_quest); } $data['course_id'] = $course_id; $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); if ($res) { $course_id = $res->course_id; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = $res->course_title; $data['course_title'] = $course; return view('user/user_chapter_wise_test', $data); } } } } public function end_module() { $session = session(); $login_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->uri->getSegment(2); $sub_domain_id = $this->request->uri->getSegment(3); $chapter_id = $this->request->uri->getSegment(4); $table = 'syllabus_chapter'; $where = ['delete_status' => 'ACTIVE', 'chapter_id' => $chapter_id]; $data['chapter_id'] = $this->request->uri->getSegment(3); $data['chapter_name'] = $nparrotsModel->getWhereRow($table, $where); $data['mapping_subjects'] = $mapping = $nparrotsModel->get_mapping_course_subjects($mapping_id); $table = 'question_mapping'; $where = ['user_id' => $login_id, 'chapter_id' => $chapter_id, 'subject_id' => $sub_domain_id, 'test_type' => '']; $data['practices_count'] = $nparrotsModel->numberRows($table, $where); $table = 'question_mapping'; $where = ['user_id' => $login_id, 'subject_id' => $sub_domain_id, 'test_type' => 'Final Test']; $data['check_attempt'] = $nparrotsModel->get_where_result($table, $where); $check_attempt = $nparrotsModel->get_where_result($table, $where); if ($check_attempt) { $data['finals'] = '1'; } else { $data['finals'] = '0'; } return view('user/end_of_module', $data); } else { return redirect()->to('/'); } } public function subject_chapter_wise_questions() { $session = session(); $login_id = $session->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $table = 'subject_chapter_question_mapping'; $where_user = ['user_id' => $login_id]; $selected_type = $this->request->getPost('selected_type'); $subject = $this->request->getPost('subject'); $chapter = $this->request->getPost('chapter'); $data = [ 'user_id' => $login_id, 'selected_type' => 'chapter_wise', 'chapter_id' => $chapter, 'subject_id' => $subject ]; $result = $nparrotsModel->InsertData($table, $data); $where = ['mapping_id' => $result]; $get_det = $nparrotsModel->getWhereRow($table, $where); $mapping_data = $this->db->table('question_mapping') ->where([ 'chapter_id' => $chapter, 'subject_id' => $subject, 'user_id' => $login_id ]) ->orderBy('test_id', 'DESC') ->get() ->getRow(); if ($mapping_data) { return $this->response->setJSON(['result' => 0, 'message' => "You already attended the test. Unable to take test again"]); } // if ($login_id == 359 || $login_id == 415 || $login_id == 419 || $login_id == 417 || $login_id == 418 || $login_id == 407 ) { // if ( $login_id == 419 ) { // $get_det = $nparrotsModel->getWhereRow($table, $where); // } else { // $get_det = null; // } if ($get_det->selected_type == "chapter_wise") { $chapter_id = $get_det->chapter_id; $quest_table = 'questions'; $where_chapter_id = ['chapter_id' => $chapter_id]; $res = $nparrotsModel->get_where_result($quest_table, $where_chapter_id); $table = 'faculty_mocktest_setting'; $subject_id = $get_det->subject_id; $where = ['chapter' => $chapter_id, 'sub_domain_id' => $subject_id, 'delete_status' => 'ACTIVE','live_status'=>1,]; $details = $nparrotsModel->getWhereRow($table, $where); if (empty($res)) { return $this->response->setJSON(['result' => 0, 'message' => "Questions Not Added Yet!"]); } elseif (empty($details)) { return $this->response->setJSON(['result' => 0, 'message' => "Test Setting Not Yet Done!"]); } else { if ($result) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } } } } public function test_welcome_page() { $session = session(); $loginId = $session->get('user_login_id'); if ($loginId) { $mappingId = $this->request->uri->getSegment(2); $table = "user_course_mapping"; $where = ['mapping_id' => $mappingId]; $nparrotsModel = new Amcad_Home(); $batchIdss = $nparrotsModel->getWhereRow($table, $where); if ($batchIdss !== null) { $batchIds = json_decode($batchIdss->batch_ids); if (!empty($batchIds)) { $table1 = "batches"; $where1 = ['batch_id' => $batchIds[0]]; $result = $nparrotsModel->getWhereRoww($table1, $where1); if ($result) { $subDomainId = $result->sub_domain_id; $chapterIds = $this->request->uri->getSegment(4); $table = "syllabus_chapter"; $where = ['chapter_id' => $chapterIds]; $data['chapter'] = $nparrotsModel->getWhereRow($table, $where); $data['course_id'] = $chapterIds; $tableSub = "sub_domains"; $whereSub = ['sub_domain_id' => $subDomainId]; $data['subject'] = $nparrotsModel->getWhereRow12($tableSub, $whereSub); $table = 'subject_chapter_question_mapping'; $where = ['user_id' => $loginId, 'subject_id' => $subDomainId, 'chapter_id' => $chapterIds]; $data['details'] = $nparrotsModel->get_where_result($table, $where); $table = 'user_course_mapping'; $where = ['mapping_id' => $mappingId, 'delete_status' => 'ACTIVE']; $getDet = $nparrotsModel->getWhereLike($table, $where); $batchId = json_decode($getDet->batch_ids); if ($getDet->batch_ids != 'null') { $table = 'batches'; $getBatch = $nparrotsModel->getWhereLikeBatch($table, $batchId); $facId = $getBatch->faculty_id; $data['questions'] = $nparrotsModel->getMockTestQuestions($chapterIds, $subDomainId, $facId); $tableFac = "faculty_mocktest_setting"; $where = ['sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE', 'chapter' => $chapterIds, 'created_by' => $facId]; $orderBy = 'id'; $data['check'] = $nparrotsModel->getWhereRowOrderby($tableFac, $where, $orderBy); } } else { $facultyId = json_decode($getDet->faculty_ids); $data['questions'] = $nparrotsModel->getMockTestQuestions2($chapterIds, $subDomainId, $facultyId); $data['check'] = $nparrotsModel->getWhereLikeChapterFaculty1($chapterIds, $facultyId, $subDomainId); } } else { $table = "user_course_mapping"; $where = ['mapping_id' => $mappingId]; $res = $nparrotsModel->getWhereRow($table, $where); $subDomainId = $res->sub_domain_ids; $chapterIds = $this->request->uri->getSegment(4); $table = 'subject_chapter_question_mapping'; $where = ['user_id' => $loginId, 'chapter_id' => $chapterIds, 'test_type' => '']; $det = $nparrotsModel->getWhereInSubDomainId1($table, $where, $subDomainId); if (is_object($det)) { // Proceed with accessing properties $subjectId = $det->subject_id; $tableOnlineTest = 'subject_chapter_question_mapping'; $whereUser = ['user_id' => $loginId]; $details = $nparrotsModel->get_where_result1($tableOnlineTest, $whereUser); foreach ($details as $det) { $selectedType = $det->selected_type; $chapterId = $det->chapter_id; $subjectId = $det->subject_id; } $table = "syllabus_chapter"; $where = ['chapter_id' => $chapterIds]; $data['chapter'] = $nparrotsModel->getWhereRow($table, $where); $tableSub = "sub_domains"; $whereSub = ['sub_domain_id' => $subjectId]; $data['subject'] = $nparrotsModel->getWhereRow($tableSub, $whereSub); $data['course_id'] = $chapterIds; $data['details'] = $nparrotsModel->get_where_result($tableOnlineTest, $whereUser); $table = 'user_course_mapping'; $where = ['mapping_id' => $mappingId, 'delete_status' => 'ACTIVE']; $getDet = $nparrotsModel->getWhereRow($table, $where); if ($getDet->batch_ids != 'null') { $batchId = json_decode($getDet->batch_ids); $table = 'batches'; $getBatch = $nparrotsModel->getWhereLikeBatch($table, $batchId); $facId = $getBatch->faculty_id; $data['questions'] = $nparrotsModel->getMockTestQuestions($chapterIds, $subDomainId, $facId); $tableFac = "faculty_mocktest_setting"; $where = ['sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE', 'chapter' => $chapterIds, 'created_by' => $facId]; $orderBy = 'id'; $data['check'] = $nparrotsModel->getWhereRowOrderby($tableFac, $where, $orderBy); $tableFac = "questions"; $where = ['sub_domain_id' => $subDomainId, 'status' => 'ACTIVE', 'chapter' => $chapterIds, 'created_by' => $facId]; $data['question_count'] = $nparrotsModel->get_where_result($table, $where); } else { $facultyId = json_decode($getDet->faculty_ids); $data['questions'] = $nparrotsModel->getMockTestQuestions2($chapterIds, $subjectId, $facultyId); $tableFac = "questions"; $where = ['sub_domain_id' => $subDomainId, 'status' => 'ACTIVE', 'chapter' => $chapterIds, 'created_by' => $facultyId]; $data['question_count'] = $nparrotsModel->getWhereQuestionsCount($subjectId, $chapterIds, $facultyId); $data['check'] = $nparrotsModel->getWhereLikeChapterFaculty1($chapterIds, $facultyId, $subjectId); } } $table = 'user_course_mapping'; $where = ['mapping_id' => $mappingId, 'user_id' => $loginId, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $courseId = $res->course_id; $table = 'courses'; $where = ['course_id' => $courseId, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = $res->course_title; $data['course_title'] = $course; return view('user/user_welcome_page', $data); } } } } public function add_notes() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $session = session(); $loginId = $session->get('user_login_id'); // $mapping_id = $this->request->uri->getSegment(4); $mapping_id = $this->request->uri->getSegment(2); // print_r($mapping_id);die(); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'delete_status' => 'ACTIVE']; $nparrotsModel = new Amcad_Home(); $courseId = $nparrotsModel->getWhereRow($table, $where); // print_r($courseId);die(); $courseId =$courseId->course_id; $note = $this->request->getPost('note'); $data = [ 'course_id' => $courseId, 'notes' => $note, 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $createdAt ]; $noteTable = 'notes'; $result = $nparrotsModel->InsertData($noteTable, $data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Added Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } public function get_notes() { $id = $this->request->getPost('id'); $table = 'notes'; $where = ['id' => $id]; $nparrotsModel = new Amcad_Home(); $result = $nparrotsModel->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } public function update_notes() { $nparrotsModel = new Amcad_Home(); $notes_id = $this->request->getPost('notes_id'); $added_notes = $this->request->getPost('added_note'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $where = ['id' => $notes_id]; $table = 'notes'; $data = ['notes' => $added_notes, 'created_at' => $updated_at]; $result = $nparrotsModel->UpdateData($table, $data, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } public function delete_notes() { $nparrotsModel = new Amcad_Home(); $id = $this->request->getPost('id'); $where = ['id' => $id, 'delete_status' => 'ACTIVE']; $table = 'notes'; $data = ['delete_status' => 'INACTIVE']; $result = $nparrotsModel->UpdateData($table, $data, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } // public function add_faculty_registration() // { // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $full_name = $this->request->getPost('full_name'); // $email = $this->request->getPost('email'); // $phone = $this->request->getPost('phone'); // $qualification = $this->request->getPost('qualification'); // $experience = $this->request->getPost('experience'); // $category = $this->request->getPost('catagory'); // $current_work = $this->request->getPost('current_work'); // $teach_experience = $this->request->getPost('teach_experience'); // $location = $this->request->getPost('location'); // $batch_size = $this->request->getPost('batch_size'); // $sub_category = $this->request->getPost('sub_catagory'); // $instructorModel = new InstructorModel(); // if (!empty($sub_category)) { // $sub_catagories = json_encode($sub_category); // } else { // $sub_catagories = ""; // } // $course_type = $this->request->getPost('course_type'); // $available_type = ""; // if (is_array($course_type) && !empty($course_type)) { // foreach ($course_type as $course) { // if ($course == 'live') { // $available_type = $this->request->getPost('available_type'); // } // } // } // $i = 0; // $start_time = ''; // $end_time = ''; // if (!empty($available_type)) { // if ($available_type == 'timings') { // $start_time = $this->request->getPost('from_time'); // $end_time = $this->request->getPost('to_time'); // foreach ($start_time as $key => $value) { // foreach ($end_time as $keys => $value) { // $start_explode_colon = explode(':', $start_time[$key]); // $start_explode_space = explode(' ', $start_explode_colon[1]); // $end_totime_colon = explode(':', $end_time[$key]); // $end_totime_space = explode(' ', $end_totime_colon[1]); // $start_explode_colons = explode(':', $start_time[$keys]); // $start_explode_spaces = explode(' ', $start_explode_colons[1]); // $end_explode_colons = explode(':', $end_time[$keys]); // $end_explode_spaces = explode(' ', $end_explode_colons[1]); // $i = 0; // if ( // (($start_time[$key] == $start_time[$keys]) && ($end_time[$key] == $end_time[$keys])) || // ($start_time[$key] == $start_time[$keys]) // ) { // $i = $i + 1; // } // if ($start_explode_space[1] == $start_explode_spaces[1]) { // if ( // (($start_explode_colons[0] == $end_totime_colon[0]) && // ($start_explode_spaces[0] < $end_totime_space[0])) || // ($start_explode_colons[0] == $start_explode_colon[0]) // ) { // $i = $i + 1; // } // } // } // } // } // } // if ($i >= 1) { // return $this->response->setJSON(['result' => 0, 'message' => 'Timings are duplicated']); // } else { // $otp_code = strtoupper(substr(md5(time()), 0, 6)); // $login_data = [ // 'username' => !empty($full_name) ? $full_name : 'default_username', // 'user_type_id' => 2, // // 'encrypted_login_id' => $encrypted_Id, // 'otp_code' => $otp_code, // 'verified_status' => 'NOT_VERIFIED', // 'email' => !empty($email) ? $email : 'default_email@example.com', // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at, // ]; // $where_email = [ // 'user_type_id' => 2, // 'email' => !empty($email) ? $email : 'default_email@example.com', // 'delete_status' => 'ACTIVE', // 'verified_status' => 'VERIFIED', // ]; // $check_email = $instructorModel->getWhereRow('login', $where_email); // if ($check_email) { // return $this->response->setJSON(['result' => 2, 'message' => 'Email already exists']); // } else { // $res_file = $this->request->getFile('resume'); // if ($res_file && $res_file->isValid() && !$res_file->hasMoved()) { // $resume_size = $res_file->getSize(); // if ($resume_size <= 2000000) { // $resume = ""; // if ($res_file->getError() !== UPLOAD_ERR_OK) { // $target = 'faculty_resumes/'; // $resume_document = time() . $res_file->getClientName(); // $res_file->move(ROOTPATH . 'public/' . $target, $resume_document); // $resume = json_encode($resume_document); // } else { // $resume = ""; // } // } // $login_data['otp_code'] = $otp_code; // $login_result = $instructorModel->insert1('login', $login_data); // if ($login_result) { // if ($category == 'other') { // $other_category = $this->request->getPost('other_category'); // $domain_table = 'domains'; // $domain_data = [ // 'domain_name' => $other_category, // 'delete_status' => 'ACTIVE', // 'created_by' => $login_result, // 'user_type_id' => '2', // 'created_at' => $created_at, // ]; // $domain_result = $instructorModel->insert2($domain_table, $domain_data); // $category = $domain_result; // if ($domain_result) { // $sub_domain_table = 'sub_domains'; // $sub_array = []; // foreach ($sub_category as $sub) { // $sub_domain_data = [ // 'sub_domain' => $sub, // 'domain_id' => $domain_result, // 'delete_status' => 'ACTIVE', // 'created_by' => $login_result, // 'user_type_id' => '2', // 'created_at' => $created_at, // ]; // $sub_domain_result = $instructorModel->insert3($sub_domain_table, $sub_domain_data); // } // $where = ['domain_id' => $domain_result, 'delete_status' => 'ACTIVE']; // $enc_result = $instructorModel->getWhereResult($sub_domain_table, $where); // foreach ($enc_result as $res) { // array_push($sub_array, $res->sub_domain_id); // } // $sub_catagories = json_encode($sub_array); // } // } // $otherSub = ''; // if (is_array($sub_category)) { // foreach ($sub_category as $sub) { // if ($sub == 'Other') { // $otherSub = 'Other'; // } // } // if ($otherSub != '') { // $subArray = []; // $otherSubCategory = ''; // foreach ($sub_category as $sub) { // if ($sub == 'Other') { // $otherSubCategory = $this->request->getPost('other_sub_category'); // } else { // array_push($subArray, $sub); // } // } // if ($otherSubCategory != '') { // $subDomainResultArray = []; // $subDomainTable = 'sub_domains'; // $subDomainData = [ // 'sub_domain' => $otherSubCategory, // 'domain_id' => $category, // 'delete_status' => 'ACTIVE', // 'created_by' => $login_result, // 'created_at' => $created_at, // ]; // $subDomainResult = $instructorModel->insert4($subDomainTable, $subDomainData); // $where = ['sub_domain_id' => $subDomainResult, 'delete_status' => 'ACTIVE']; // $subResult = $instructorModel->getWhereResult('sub_domains', $where); // } // foreach ($subResult as $subRes) { // array_push($subArray, $subRes->sub_domain_id); // } // $sub_category = $subArray; // $sub_catagories = json_encode($sub_category); // } // } // $whereId = ['login_id' => $login_result]; // $updateId = ['encrypted_login_id' => md5($login_result)]; // $update = $instructorModel->update1($whereId, 'login', $updateId); // $emailService = \Config\Services::email(); // $emailService->setFrom("johncameron6677@gmail.com", "AMCAD"); // $emailService->setTo($email); // $emailService->setSubject('Amcad Registration – OTP for Email Verification'); // $href = base_url(); // $content = '<body style="background:#f3f3f3;">'; // $content .= '<div style="width:100%;">'; // $content .= '<div style="text-align: center;">'; // $content .= '<div>'; // $content .= '<img src="' . $href . 'assets/images/all_logo.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; // $content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; // $content .= '</div>'; // $content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; // $content .= '<img src="' . $href . 'assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; // $content .= '</div>'; // $content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; // $content .= '<h3 style="margin-top:10px;">Email Confirmation</h3>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $full_name . ', Thanks for registering on Nparrots. Please click on the below link for email verification and enter OTP to complete verification.</p>'; // // $content .= '<p style="font-size:16px;padding-bottom:10px;">OTP : '.$encrypted_Id.'</p>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;">OTP : ' . $otp_code . '</p>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="' . $href . 'faculty-verification/' . md5($login_result) . '" style="color:#fff;padding:10px 30px;background:#a6d039;" style="color:#fff;padding:10px 30px;background:#a6d039;">Verify Your OTP</a></p>'; // $content .= '</div>'; // $content .= '</div>'; // $content .= '</div>'; // $content .= '</body>'; // $emailService->setMessage($content); // if ($emailService->send()) { // $faculty_data = [ // 'login_id' => $login_result, // 'domain_id' => $category, // 'sub_domain_id' => $sub_catagories, // 'fullname' => $full_name, // 'email' => !empty($email) ? $email : 'default_email@example.com', // 'phone' => $phone, // 'qualification' => $qualification, // 'teaching_experience' => $experience, // 'current_working' => $current_work, // 'online_teaching_experience' => $teach_experience, // 'location' => $location, // 'resume' => $resume, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at, // ]; // $faculty_table = 'faculty_registration'; // $faculty_result = $instructorModel->insert5($faculty_table, $faculty_data); // if ($faculty_result) { // $mapping_table = 'faculty_subject_mapping'; // $mapping_data = [ // 'login_id' => $login_result, // 'faculty_reg_id' => $faculty_result, // 'domain_id' => $category, // 'sub_domain_id' => $sub_catagories, // 'batch_size' => $batch_size, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at, // 'added_from' => 'REGISTRATION', // 'approval_status' => 'NOT_APPROVED', // 'created_by' => $login_result // ]; // $mapping_result = $instructorModel->insert6($mapping_table, $mapping_data); // if ($mapping_result) { // $timing_table = 'faculty_available_timings'; // if ($available_type != '') { // if ($available_type == 'timings') { // foreach ($start_time as $key => $value) { // $timing_data = [ // 'faculty_id' => $login_result, // 'subject_id' => $sub_catagories, // 'course_type' => json_encode($course_type), // 'subject_mapping_id' => $mapping_result, // 'from_time' => $start_time[$key], // 'to_time' => $end_time[$key], // 'available_type' => $available_type, // 'delete_status' => 'ACTIVE', // 'approval_status' => 'NOT_APPROVED', // 'return_status' => 'NOT_RETURNED', // 'created_at' => $created_at, // ]; // $time_result = $instructorModel->insert7($timing_table, $timing_data); // } // } else { // $timing_data = [ // 'faculty_id' => $login_result, // 'subject_id' => $sub_catagories, // 'course_type' => json_encode($course_type), // 'subject_mapping_id' => $mapping_result, // 'from_time' => $start_time, // 'to_time' => $end_time, // 'available_type' => $available_type, // 'delete_status' => 'ACTIVE', // 'approval_status' => 'NOT_APPROVED', // 'return_status' => 'NOT_RETURNED', // 'created_at' => $created_at, // ]; // $time_result = $instructorModel->insert7($timing_table, $timing_data); // } // } else { // $timing_data = [ // 'faculty_id' => $login_result, // 'subject_id' => $sub_catagories, // 'course_type' => json_encode($course_type), // 'subject_mapping_id' => $mapping_result, // 'from_time' => $start_time, // 'to_time' => $end_time, // 'delete_status' => 'ACTIVE', // 'approval_status' => 'NOT_APPROVED', // 'return_status' => 'NOT_RETURNED', // 'created_at' => $created_at, // ]; // $time_result = $instructorModel->insert7($timing_table, $timing_data); // } // $notification = $full_name . ', has registered as faculty for subjects ' . $sub_catagories; // $notification_table = 'notification'; // $notification_data = [ // 'login_id' => $login_result, // 'username' => !empty($full_name) ? $full_name : 'default_username', // 'notification' => $notification, // 'view_status' => 'NOT_VIEWED', // 'delete_status' => 'ACTIVE', // 'category_type' => 'Faculty Registration', // 'created_by' => $login_result, // 'created_at' => $created_at, // ]; // $notification_result = $instructorModel->insert8($notification_table, $notification_data); // return $this->response->setJSON(['result' => 1, 'message' => 'Details added successfully. Please verify the link with OTP code sent to your email id to complete registration.']); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong1..']); // } // } // } else { // error_log('Email sending failed: ' . $emailService->printDebugger(['headers'])); // return $this->response->setJSON(['result' => 0, 'message' => 'Email could not be sent. Please try again later.']); // } // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong3..']); // } // } // } // } // } // public function add_faculty_registration() // { // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $full_name = $this->request->getPost('full_name'); // $email = $this->request->getPost('email'); // $phone = $this->request->getPost('phone'); // $qualification = $this->request->getPost('qualification'); // $experience = $this->request->getPost('experience'); // $category = $this->request->getPost('catagory'); // $current_work = $this->request->getPost('current_work'); // $teach_experience = $this->request->getPost('teach_experience'); // $location = $this->request->getPost('location'); // $batch_size = $this->request->getPost('batch_size'); // $sub_category = $this->request->getPost('sub_catagory'); // $instructorModel = new InstructorModel(); // if (!empty($sub_category)) { // $sub_catagories = json_encode($sub_category); // } else { // $sub_catagories = ""; // } // $course_type = $this->request->getPost('course_type'); // $available_type = ""; // if (is_array($course_type) && !empty($course_type)) { // foreach ($course_type as $course) { // if ($course == 'live') { // $available_type = $this->request->getPost('available_type'); // } // } // } // $i = 0; // $start_time = ''; // $end_time = ''; // if (!empty($available_type)) { // if ($available_type == 'timings') { // $start_time = $this->request->getPost('from_time'); // $end_time = $this->request->getPost('to_time'); // foreach ($start_time as $key => $value) { // foreach ($end_time as $keys => $value) { // $start_explode_colon = explode(':', $start_time[$key]); // $start_explode_space = explode(' ', $start_explode_colon[1]); // $end_totime_colon = explode(':', $end_time[$key]); // $end_totime_space = explode(' ', $end_totime_colon[1]); // $start_explode_colons = explode(':', $start_time[$keys]); // $start_explode_spaces = explode(' ', $start_explode_colons[1]); // $end_explode_colons = explode(':', $end_time[$keys]); // $end_explode_spaces = explode(' ', $end_explode_colons[1]); // $i = 0; // if ( // (($start_time[$key] == $start_time[$keys]) && ($end_time[$key] == $end_time[$keys])) || // ($start_time[$key] == $start_time[$keys]) // ) { // $i = $i + 1; // } // if ($start_explode_space[1] == $start_explode_spaces[1]) { // if ( // (($start_explode_colons[0] == $end_totime_colon[0]) && // ($start_explode_spaces[0] < $end_totime_space[0])) || // ($start_explode_colons[0] == $start_explode_colon[0]) // ) { // $i = $i + 1; // } // } // } // } // } // } // if ($i >= 1) { // return $this->response->setJSON(['result' => 0, 'message' => 'Timings are duplicated']); // } else { // $otp_code = strtoupper(substr(md5(time()), 0, 6)); // $login_data = [ // 'username' => !empty($full_name) ? $full_name : 'default_username', // 'user_type_id' => 2, // 'otp_code' => $otp_code, // 'verified_status' => 'NOT_VERIFIED', // 'email' => !empty($email) ? $email : 'default_email@example.com', // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at, // ]; // $where_email = [ // 'user_type_id' => 2, // 'email' => !empty($email) ? $email : 'default_email@example.com', // 'delete_status' => 'ACTIVE', // 'verified_status' => 'VERIFIED', // ]; // $check_email = $instructorModel->getWhereRow('login', $where_email); // if ($check_email) { // return $this->response->setJSON(['result' => 2, 'message' => 'Email already exists']); // } else { // $res_file = $this->request->getFile('resume'); // if ($res_file && $res_file->isValid() && !$res_file->hasMoved()) { // $resume_size = $res_file->getSize(); // if ($resume_size <= 2000000) { // $resume = ""; // if ($res_file->getError() !== UPLOAD_ERR_OK) { // $target = 'public/faculty_resumes/'; // $resume_document = time() . $res_file->getClientName(); // $res_file->move(ROOTPATH . 'public/' . $target, $resume_document); // $resume = json_encode($resume_document); // } else { // $resume = ""; // } // } // $login_data['otp_code'] = $otp_code; // $login_result = $instructorModel->insert1('login', $login_data); // if ($login_result) { // if ($category == 'other') { // $other_category = $this->request->getPost('other_category'); // $domain_table = 'domains'; // $domain_data = [ // 'domain_name' => $other_category, // 'delete_status' => 'ACTIVE', // 'created_by' => $login_result, // 'user_type_id' => '2', // 'created_at' => $created_at, // ]; // $domain_result = $instructorModel->insert2($domain_table, $domain_data); // $category = $domain_result; // if ($domain_result) { // $sub_domain_table = 'sub_domains'; // $sub_array = []; // foreach ($sub_category as $sub) { // $sub_domain_data = [ // 'sub_domain' => $sub, // 'domain_id' => $domain_result, // 'delete_status' => 'ACTIVE', // 'created_by' => $login_result, // 'user_type_id' => '2', // 'created_at' => $created_at, // ]; // $sub_domain_result = $instructorModel->insert3($sub_domain_table, $sub_domain_data); // } // $where = ['domain_id' => $domain_result, 'delete_status' => 'ACTIVE']; // $enc_result = $instructorModel->getWhereResult($sub_domain_table, $where); // foreach ($enc_result as $res) { // array_push($sub_array, $res->sub_domain_id); // } // $sub_catagories = json_encode($sub_array); // } // } // $otherSub = ''; // if (is_array($sub_category)) { // foreach ($sub_category as $sub) { // if ($sub == 'Other') { // $otherSub = 'Other'; // } // } // if ($otherSub != '') { // $subArray = []; // $otherSubCategory = ''; // foreach ($sub_category as $sub) { // if ($sub == 'Other') { // $otherSubCategory = $this->request->getPost('other_sub_category'); // } else { // array_push($subArray, $sub); // } // } // if ($otherSubCategory != '') { // $subDomainResultArray = []; // $subDomainTable = 'sub_domains'; // $subDomainData = [ // 'sub_domain' => $otherSubCategory, // 'domain_id' => $category, // 'delete_status' => 'ACTIVE', // 'created_by' => $login_result, // 'created_at' => $created_at, // ]; // $subDomainResult = $instructorModel->insert4($subDomainTable, $subDomainData); // $where = ['sub_domain_id' => $subDomainResult, 'delete_status' => 'ACTIVE']; // $subResult = $instructorModel->getWhereResult('sub_domains', $where); // } // foreach ($subResult as $subRes) { // array_push($subArray, $subRes->sub_domain_id); // } // $sub_category = $subArray; // $sub_catagories = json_encode($sub_category); // } // } // $whereId = ['login_id' => $login_result]; // $updateId = ['encrypted_login_id' => md5($login_result)]; // $update = $instructorModel->update1($whereId, 'login', $updateId); // $emailService = \Config\Services::email(); // $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); // $emailService->setTo($email); // $emailService->setSubject('Amcad Registration – OTP for Email Verification'); // $href = base_url(); // $content = '<body style="background:#f3f3f3;">'; // $content .= '<div style="width:100%;">'; // $content .= '<div style="text-align: center;">'; // $content .= '<div>'; // $content .= '<img src="' . $href . 'assets/website_assets/icons/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; // $content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; // $content .= '</div>'; // $content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; // $content .= '<img src="'.$href.'assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; // $content .= '</div>'; // $content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; // $content .= '<h3 style="margin-top:10px;">Email Confirmation</h3>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$full_name.', Thanks for registering on Amcad. Please click on the below link for email verification and enter OTP to complete verification.</p>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;">OTP : '.$otp_code.'</p>'; // // $content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="'.$href.'email_verification/'.md5($login_result).'" style="color:#fff;padding:10px 30px;background:#a6d039;" style="color:#fff;padding:10px 30px;background:#a6d039;">Verify Your OTP</a></p>'; // $content .= '</div>'; // $content .= '</div>'; // $content .= '</div>'; // $content .= '</body>'; // $emailService->setMessage($content); // if ($emailService->send()) { // $faculty_data = [ // 'login_id' => $login_result, // 'domain_id' => $category, // 'sub_domain_id' => $sub_catagories, // 'fullname' => $full_name, // 'email' => !empty($email) ? $email : 'default_email@example.com', // 'phone' => $phone, // 'qualification' => $qualification, // 'teaching_experience' => $experience, // 'current_working' => $current_work, // 'online_teaching_experience' => $teach_experience, // 'location' => $location, // 'resume' => $resume, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at, // ]; // $faculty_table = 'faculty_registration'; // $faculty_result = $instructorModel->insert5($faculty_table, $faculty_data); // if ($faculty_result) { // $mapping_table = 'faculty_subject_mapping'; // $mapping_data = [ // 'login_id' => $login_result, // 'faculty_reg_id' => $faculty_result, // 'domain_id' => $category, // 'sub_domain_id' => $sub_catagories, // 'batch_size' => $batch_size, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at, // 'added_from' => 'REGISTRATION', // 'approval_status' => 'NOT_APPROVED', // 'created_by' => $login_result // ]; // $mapping_result = $instructorModel->insert6($mapping_table, $mapping_data); // if ($mapping_result) { // $timing_table = 'faculty_available_timings'; // if ($available_type != '') { // if ($available_type == 'timings') { // foreach ($start_time as $key => $value) { // $timing_data = [ // 'faculty_id' => $login_result, // 'subject_id' => $sub_catagories, // 'course_type' => json_encode($course_type), // 'subject_mapping_id' => $mapping_result, // 'from_time' => $start_time[$key], // 'to_time' => $end_time[$key], // 'available_type' => $available_type, // 'delete_status' => 'ACTIVE', // 'approval_status' => 'NOT_APPROVED', // 'return_status' => 'NOT_RETURNED', // 'created_at' => $created_at, // ]; // $time_result = $instructorModel->insert7($timing_table, $timing_data); // } // } else { // $timing_data = [ // 'faculty_id' => $login_result, // 'subject_id' => $sub_catagories, // 'course_type' => json_encode($course_type), // 'subject_mapping_id' => $mapping_result, // 'from_time' => $start_time, // 'to_time' => $end_time, // 'available_type' => $available_type, // 'delete_status' => 'ACTIVE', // 'approval_status' => 'NOT_APPROVED', // 'return_status' => 'NOT_RETURNED', // 'created_at' => $created_at, // ]; // $time_result = $instructorModel->insert7($timing_table, $timing_data); // } // } else { // $timing_data = [ // 'faculty_id' => $login_result, // 'subject_id' => $sub_catagories, // 'course_type' => json_encode($course_type), // 'subject_mapping_id' => $mapping_result, // 'from_time' => $start_time, // 'to_time' => $end_time, // 'delete_status' => 'ACTIVE', // 'approval_status' => 'NOT_APPROVED', // 'return_status' => 'NOT_RETURNED', // 'created_at' => $created_at, // ]; // $time_result = $instructorModel->insert7($timing_table, $timing_data); // } // $notification = $full_name . ', has registered as faculty for subjects ' . $sub_catagories; // $notification_table = 'notification'; // $notification_data = [ // 'login_id' => $login_result, // 'username' => !empty($full_name) ? $full_name : 'default_username', // 'notification' => $notification, // 'view_status' => 'NOT_VIEWED', // 'delete_status' => 'ACTIVE', // 'category_type' => 'Faculty Registration', // 'created_by' => $login_result, // 'created_at' => $created_at, // ]; // $notification_result = $instructorModel->insert8($notification_table, $notification_data); // return $this->response->setJSON(['result' => 1, 'message' => 'Details added successfully. Please verify the link with OTP code sent to your email id to complete registration.']); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong1..']); // } // } // } else { // error_log('Email sending failed: ' . $emailService->printDebugger(['headers'])); // return $this->response->setJSON(['result' => 0, 'message' => 'Email could not be sent. Please try again later.']); // } // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong3..']); // } // } // } // } // } public function add_faculty_registration() { $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $full_name = $this->request->getPost('full_name'); $email = $this->request->getPost('email'); $phone = $this->request->getPost('phone'); $qualification = $this->request->getPost('qualification'); $experience = $this->request->getPost('experience'); $category = $this->request->getPost('catagory'); $current_work = $this->request->getPost('current_work'); $teach_experience = $this->request->getPost('teach_experience'); $location = $this->request->getPost('location'); $batch_size = $this->request->getPost('batch_size'); $sub_category = $this->request->getPost('sub_catagory'); $instructorModel = new InstructorModel(); if (!empty($sub_category)) { $sub_catagories = json_encode($sub_category); } else { $sub_catagories = ""; } $course_type = $this->request->getPost('course_type'); $available_type = ""; if (is_array($course_type) && !empty($course_type)) { foreach ($course_type as $course) { if ($course == 'live') { $available_type = $this->request->getPost('available_type'); } } } $i = 0; $start_time = ''; // Initialize the variable $end_time = ''; // Initialize the variable if (!empty($available_type)) { if ($available_type == 'timings') { $start_time = $this->request->getPost('from_time'); $end_time = $this->request->getPost('to_time'); for ($key = 0; $key < count($start_time); $key++) { for ($keys = $key + 1; $keys < count($start_time); $keys++) { $start1 = new DateTime($start_time[$key]); $end1 = new DateTime($end_time[$key]); $start2 = new DateTime($start_time[$keys]); $end2 = new DateTime($end_time[$keys]); if ( ($start1 == $start2 && $end1 == $end2) || ($start1 == $start2 && $end1 > $start2) || ($start1 < $start2 && $end1 > $start2) || ($start1 < $end2 && $end1 >= $end2) ) { $i++; } } } } } if ($i >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'Timings are duplicated']); } else { $otp_code = strtoupper(substr(md5(time()), 0, 6)); $login_data = [ 'username' => !empty($full_name) ? $full_name : 'default_username', 'user_type_id' => 2, 'otp_code' => $otp_code, 'verified_status' => 'NOT_VERIFIED', 'email' => !empty($email) ? $email : 'default_email@example.com', 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $where_email = [ 'user_type_id' => 2, 'email' => !empty($email) ? $email : 'default_email@example.com', 'delete_status' => 'ACTIVE', 'verified_status' => 'VERIFIED', ]; $check_email = $instructorModel->getWhereRow('login', $where_email); if ($check_email) { return $this->response->setJSON(['result' => 2, 'message' => 'Email already exists']); } else { $res_file = $this->request->getFile('resume'); if ($res_file && $res_file->isValid() && !$res_file->hasMoved()) { $resume_size = $res_file->getSize(); if ($resume_size <= 2000000) { $resume = ""; if ($res_file->getError() !== UPLOAD_ERR_OK) { $target = 'faculty_resumes/'; $resume_document = time() . $res_file->getClientName(); $res_file->move(ROOTPATH . 'public/' . $target, $resume_document); $resume = json_encode($resume_document); } else { $resume = ""; } } $login_data['otp_code'] = $otp_code; $login_result = $instructorModel->insert1('login', $login_data); if ($login_result) { if ($category == 'other') { $other_category = $this->request->getPost('other_category'); $domain_table = 'domains'; $domain_data = [ 'domain_name' => $other_category, 'delete_status' => 'ACTIVE', 'created_by' => $login_result, 'user_type_id' => '2', 'created_at' => $created_at, ]; $domain_result = $instructorModel->insert2($domain_table, $domain_data); $category = $domain_result; if ($domain_result) { $sub_domain_table = 'sub_domains'; $sub_array = []; foreach ($sub_category as $sub) { $sub_domain_data = [ 'sub_domain' => $sub, 'domain_id' => $domain_result, 'delete_status' => 'ACTIVE', 'created_by' => $login_result, 'user_type_id' => '2', 'created_at' => $created_at, ]; $sub_domain_result = $instructorModel->insert3($sub_domain_table, $sub_domain_data); } $where = ['domain_id' => $domain_result, 'delete_status' => 'ACTIVE']; $enc_result = $instructorModel->getWhereResult($sub_domain_table, $where); foreach ($enc_result as $res) { array_push($sub_array, $res->sub_domain_id); } $sub_catagories = json_encode($sub_array); } } $otherSub = ''; if (is_array($sub_category)) { foreach ($sub_category as $sub) { if ($sub == 'Other') { $otherSub = 'Other'; } } if ($otherSub != '') { $subArray = []; $otherSubCategory = ''; foreach ($sub_category as $sub) { if ($sub == 'Other') { $otherSubCategory = $this->request->getPost('other_sub_category'); } else { array_push($subArray, $sub); } } if ($otherSubCategory != '') { $subDomainResultArray = []; $subDomainTable = 'sub_domains'; $subDomainData = [ 'sub_domain' => $otherSubCategory, 'domain_id' => $category, 'delete_status' => 'ACTIVE', 'created_by' => $login_result, 'created_at' => $created_at, ]; $subDomainResult = $instructorModel->insert4($subDomainTable, $subDomainData); $where = ['sub_domain_id' => $subDomainResult, 'delete_status' => 'ACTIVE']; $subResult = $instructorModel->getWhereResult('sub_domains', $where); } foreach ($subResult as $subRes) { array_push($subArray, $subRes->sub_domain_id); } $sub_category = $subArray; $sub_catagories = json_encode($sub_category); } } $whereId = ['login_id' => $login_result]; $updateId = ['encrypted_login_id' => md5($login_result)]; $update = $instructorModel->update1($whereId, 'login', $updateId); $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($email); $emailService->setSubject('Amcad Registration – OTP for Email Verification'); $href = base_url(); $content = '<body style="background:#f3f3f3;">'; $content .= '<div style="width:100%;">'; $content .= '<div style="text-align: center;">'; $content .= '<div>'; $content .= '<img src="' . $href . 'public/assets/website_assets/icons/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $content .= '</div>'; $content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $content .= '<img src="'.$href.'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $content .= '</div>'; $content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $content .= '<h3 style="margin-top:10px;">Email Confirmation</h3>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$full_name.', Thanks for registering on Amcad. Please enter OTP to complete email verification.</p>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">OTP : '.$otp_code.'</p>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="'.$href.'email_verification/'.md5($login_result).'" style="color:#fff;padding:10px 30px;background:#a6d039;" style="color:#fff;padding:10px 30px;background:#a6d039;">Verify Your OTP</a></p>'; $content .= '</div>'; $content .= '</div>'; $content .= '</div>'; $content .= '</body>'; $emailService->setMessage($content); if ($emailService->send()) { $faculty_data = [ 'login_id' => $login_result, 'domain_id' => $category, 'sub_domain_id' => $sub_catagories, 'fullname' => $full_name, 'email' => !empty($email) ? $email : 'default_email@example.com', 'phone' => $phone, 'qualification' => $qualification, 'teaching_experience' => $experience, 'current_working' => $current_work, 'online_teaching_experience' => $teach_experience, 'location' => $location, 'resume' => $resume, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $faculty_table = 'faculty_registration'; $faculty_result = $instructorModel->insert5($faculty_table, $faculty_data); if ($faculty_result) { $mapping_table = 'faculty_subject_mapping'; $mapping_data = [ 'login_id' => $login_result, 'faculty_reg_id' => $faculty_result, 'domain_id' => $category, 'sub_domain_id' => $sub_catagories, 'batch_size' => $batch_size, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, 'added_from' => 'REGISTRATION', 'approval_status' => 'NOT_APPROVED', 'created_by' => $login_result ]; $mapping_result = $instructorModel->insert6($mapping_table, $mapping_data); if ($mapping_result) { $timing_table = 'faculty_available_timings'; if ($available_type != '') { if ($available_type == 'timings') { foreach ($start_time as $key => $value) { $timing_data = [ 'faculty_id' => $login_result, 'subject_id' => $sub_catagories, 'course_type' => json_encode($course_type), 'subject_mapping_id' => $mapping_result, 'from_time' => $start_time[$key], 'to_time' => $end_time[$key], 'available_type' => $available_type, 'delete_status' => 'ACTIVE', 'approval_status' => 'NOT_APPROVED', 'return_status' => 'NOT_RETURNED', 'created_at' => $created_at, ]; $time_result = $instructorModel->insert7($timing_table, $timing_data); } } else { $timing_data = [ 'faculty_id' => $login_result, 'subject_id' => $sub_catagories, 'course_type' => json_encode($course_type), 'subject_mapping_id' => $mapping_result, 'from_time' => $start_time, 'to_time' => $end_time, 'available_type' => $available_type, 'delete_status' => 'ACTIVE', 'approval_status' => 'NOT_APPROVED', 'return_status' => 'NOT_RETURNED', 'created_at' => $created_at, ]; $time_result = $instructorModel->insert7($timing_table, $timing_data); } } else { $timing_data = [ 'faculty_id' => $login_result, 'subject_id' => $sub_catagories, 'course_type' => json_encode($course_type), 'subject_mapping_id' => $mapping_result, 'from_time' => $start_time, 'to_time' => $end_time, 'delete_status' => 'ACTIVE', 'approval_status' => 'NOT_APPROVED', 'return_status' => 'NOT_RETURNED', 'created_at' => $created_at, ]; $time_result = $instructorModel->insert7($timing_table, $timing_data); } $notification = $full_name . ', has registered as faculty for subjects ' . $sub_catagories; $notification_table = 'notification'; $notification_data = [ 'login_id' => $login_result, 'username' => !empty($full_name) ? $full_name : 'default_username', 'notification' => $notification, 'view_status' => 'NOT_VIEWED', 'delete_status' => 'ACTIVE', 'category_type' => 'Faculty Registration', 'created_by' => $login_result, 'created_at' => $created_at, ]; $notification_result = $instructorModel->insert8($notification_table, $notification_data); return $this->response->setJSON(['result' => 1, 'message' => 'Details added successfully. Please verify the link with OTP code sent to your email id to complete registration.']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong1..']); } } } else { error_log('Email sending failed: ' . $emailService->printDebugger(['headers'])); return $this->response->setJSON(['result' => 0, 'message' => 'Email could not be sent. Please try again later.']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong3..']); } } } } } public function email_verification() { // $data['encrypted_id'] = $this->request->uri->getSegment(4); echo view('user/email_verification'); } public function complete_email_verification() { // $encryptedId = $this->request->getPost('encrypted_id'); $otpCode = $this->request->getPost('otp_code'); $nparrots_model = new InstructorModel(); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $loginTable = 'login'; $where = ['otp_code' => $otpCode]; $checkOtp = $nparrots_model->getWhereRow1($loginTable, $where); if ($checkOtp) { if ($checkOtp->verified_status == 'VERIFIED') { return $this->response->setJSON(['result' => 3, 'message' => 'OTP already verified']); } else { $whereId = ['otp_code' => $otpCode]; $updateData = ['verified_status' => 'VERIFIED', 'verified_at' => $createdAt]; $nparrots_model->update2($whereId, $loginTable, $updateData); if ($nparrots_model->affectedRows() > 0) { $resultMessage = ($checkOtp->user_type_id == 4 || $checkOtp->user_type_id == 2) ? ['result' => 1, 'message' => 'Updated Successfully'] : ['result' => 2, 'message' => 'Updated Successfully']; return $this->response->setJSON($resultMessage); } else { return $this->response->setJSON(['result' => 2, 'message' => 'Something went wrong... try again']); } } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Wrong OTP']); } } public function mark_as_later_chapter() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); $table = "answered_questions"; $qid = $this->request->getPost('qid'); $question_number = $this->request->getPost('question_number'); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $chapter_id = $result_test->chapter_id; $subject_id = $result_test->subject_id; $where = [ 'test_id' => $test_id, 'question_id' => $qid, 'test_type' => 'chapter_wise', ]; $markResult = $nparrotsModel->getWhereRow($table, $where); if (empty($markResult)) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d'); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $data = [ 'answered_by' => $login_id, 'mark_for_later' => 'YES', 'question_number' => $question_number, 'question_id' => $qid, 'answered_on' => $answered_on, 'test_type' => 'chapter_wise', 'test_id' => $test_id, 'chapter_id' => $chapter_id, 'sub_domain_id' => $subject_id, ]; $insertResult = $nparrotsModel->InsertData($table, $data); $where = ['answer_id' => $insertResult]; $result = $nparrotsModel->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Marked for later', 'mark_data' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong!']); } } else { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d'); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $where = [ 'test_id' => $test_id, 'question_id' => $qid, 'test_type' => 'chapter_wise', ]; $data = [ 'answered_by' => $login_id, 'mark_for_later' => 'YES', 'question_number' => $question_number, 'question_id' => $qid, 'answered_on' => $answered_on, 'test_type' => 'chapter_wise', 'test_id' => $test_id, ]; $updateResult = $nparrotsModel->UpdateData($where, $table, $data); $where = [ 'test_id' => $test_id, 'question_id' => $qid, 'test_type' => 'chapter_wise', ]; $result = $nparrotsModel->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Marked for later', 'mark_data' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong!']); } } } // public function get_sub_domain() // { // $request = service('request'); // $id = $request->getPost('domain_id'); // $subdomain_table = 'sub_domains'; // $where_subdomain = ['domain_id' => $id, 'delete_status' => 'ACTIVE']; // $order_by = 'sub_domain'; // $nparrotsModel = new Amcad_Home(); // $result = $nparrotsModel->getWhereResultOrderByAsc1($subdomain_table, $where_subdomain, $order_by); // if ($result) { // return $this->response->setJSON(['result' => 1, 'message' => $result]); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); // } // } public function get_sub_domain() { $batch_model = new Batch_Model(); $id = $this->request->getPost('domain_id'); $subdomainTable = 'sub_domains'; $whereSubDomain = ['domain_id' => $id, 'delete_status' => 'ACTIVE']; $orderBy = 'sub_domain'; $result = $batch_model->getWhereResultOrderByAsc($subdomainTable, $whereSubDomain, $orderBy); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function previous_question_subject_wise() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->getPost('mapping_id'); $qid = $this->request->getPost('qid'); $sub_domain_id = $this->request->getPost('cid'); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $result = $nparrotsModel->previous_question_subject_wise($mapping_id, $test_id, $qid, $sub_domain_id, $login_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No questions available']); } } } public function mark_later_qus_subject() { $session = session(); $login_id = $session->get('user_login_id'); if ($login_id) { $qid = $this->request->getPost('qid'); $sub_domain_id = $this->request->getPost('sid'); $table = 'questions'; $where = ['qid' => $qid, 'sub_domain_id' => $sub_domain_id, 'status' => 'ACTIVE']; $nparrotsModel = new Amcad_Home(); $res = $nparrotsModel->getWhereRow($table, $where); if ($res) { $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $result = $nparrotsModel->mark_later_qus_subject($test_id, $login_id, $qid, $sub_domain_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'No questions available']); } } } public function insert_subject_wise_answers() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mvalue = $this->request->getPost('mvalue'); $qid = $this->request->getPost('qid'); $sub_domain_id = $this->request->getPost('cid'); $table_question_mapping = 'question_mapping'; $where_sub_domain = ['subject_id' => $sub_domain_id, 'test_type' => 'Mock Test']; $order_by = 'test_id'; $get_details = $nparrotsModel->getWhereRowOrderBy1($table_question_mapping, $where_sub_domain, $order_by); $test_id = $get_details->test_id; $result_test = $nparrotsModel->get_last_row(); $test_id1 = $result_test->test_id; $table_mapping_sub_chapter = 'subject_chapter_question_mapping'; $where_id = ['subject_id' => $sub_domain_id, 'test_type' => 'Mock Test']; $get_det = $nparrotsModel->getWhereRow8($table_mapping_sub_chapter, $where_id); $test_type = $get_det->selected_type; $ans = $this->request->getPost('ans'); if (empty($ans)) { $ans = "0"; } else { $ans = $this->request->getPost('ans'); } $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d H:i:s'); $table = "answered_questions"; $where = ['test_id' => $test_id1, 'question_id' => $qid, 'test_type' => 'subject_wise']; $order_by = 'test_id'; $mark_result = $nparrotsModel->getWhereRow($table, $where); $result = $nparrotsModel->getWhereRowOrderBy($table, $where, $order_by); $res_test_id = null; // Declare $res_test_id outside the if block if (is_object($result) && property_exists($result, 'test_id')) { $res_test_id = $result->test_id; if (property_exists($result, 'mark_for_later')) { if ($result->mark_for_later == "YES" && ($result->question_id == $qid) && ($result->test_type == "subject_wise") && ($result->test_id == $test_id1)) { $where = ['test_id' => $test_id, 'question_id' => $qid, 'test_type' => 'subject_wise']; $data = ['correct_answer' => $ans, 'mark_for_later' => 'NO', 'test_type' => $test_type, 'test_id' => $test_id]; $nparrotsModel->UpdateData2($where, $table, $data); } else if ($result->mark_for_later == "NO" && ($result->question_id == $qid) && ($result->test_type == "subject_wise") && ($result->test_id == $test_id1)) { $where = ['test_id' => $test_id, 'question_id' => $qid, 'test_type' => 'subject_wise']; $data = ['correct_answer' => $ans, 'mark_for_later' => 'NO', 'test_type' => $test_type, 'test_id' => $test_id]; $nparrotsModel->UpdateData2($where, $table, $data); } } } else if ($res_test_id != $test_id) { $data = [ 'question_id' => $qid, 'answered_by' => $login_id, 'test_type' => $test_type, 'correct_answer' => $ans, 'answered_on' => $answered_on, 'test_id' => $test_id, 'sub_domain_id' => $sub_domain_id, ]; $nparrotsModel->InsertData($table, $data); } } } public function mark_as_later_subject() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); $table = "answered_questions"; $qid = $this->request->getPost('qid'); $question_number = $this->request->getPost('question_number'); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $where = [ 'test_id' => $test_id, 'question_id' => $qid, 'test_type' => 'subject_wise' ]; $markResult = $nparrotsModel->getWhereRow($table, $where); if (empty($markResult)) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d'); $data = [ 'answered_by' => $login_id, 'mark_for_later' => 'YES', 'question_number' => $this->request->getPost('question_number'), 'question_id' => $qid, 'answered_on' => $answered_on, 'test_type' => 'subject_wise', 'test_id' => $test_id, 'sub_domain_id' => $result_test->subject_id, 'chapter_id' => 0 ]; try { $insertResult = $nparrotsModel->insertData1($table, $data, 'special'); } catch (\Exception $e) { return $this->response->setJSON(['result' => 0, 'message' => $e->getMessage()]); } $where = ['answer_id' => $insertResult]; $result = $nparrotsModel->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Marked for later', 'mark_data' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something wrong...']); } } else { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d'); $data = [ 'answered_by' => $login_id, 'mark_for_later' => 'YES', 'question_number' => $question_number, 'question_id' => $qid, 'answered_on' => $answered_on, 'test_type' => 'subject_wise', 'test_id' => $test_id ]; $updateResult = $nparrotsModel->UpdateData2($where, $table, $data); $result = $nparrotsModel->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Mark as later', 'mark_data' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong!']); } } } public function next_question_subject_wise() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $table = "answered_questions"; $mapping_id = $this->request->getPost('mapping_id'); $qid = $this->request->getPost('qid'); $sub_domain_id = $this->request->getPost('cid'); $question_number = $this->request->getPost('question_number'); $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $result = $nparrotsModel->next_question_subject_wise($mapping_id, $qid, $sub_domain_id, $test_id, $login_id, $question_number); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } } } public function insert_unattended_subject_wise_answers() { $loginId = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($loginId) { $subjectId = $this->request->getPost('subject_id'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $answeredOn = $date->format('Y-m-d H:i:s'); $table = "question_mapping"; $where = ['subject_id' => $subjectId, 'test_type' => 'Mock Test']; $orderBy = 'test_id'; $test = $nparrotsModel->getWhereRowOrderBy($table, $where, $orderBy); if ($test && is_object($test)) { $testId = $test->test_id; $testQuestions = json_decode($test->question_id); foreach ($testQuestions as $testQuests) { $answerTable = 'answered_questions'; $questions = $testQuests; $data = [ 'answered_by' => $loginId, 'question_id' => $questions, 'test_type' => 'subject_wise', 'correct_answer' => '0', 'test_id' => $testId, 'answered_on' => $answeredOn, 'sub_domain_id' => $subjectId ]; $result = $nparrotsModel->insert_data($answerTable, $data); $table = 'question_mapping'; $where = ['test_id' => $testId, 'test_status' => 'ONGOING']; $data = ['test_status' => 'COMPLETED']; $res = $nparrotsModel->updateData2($where, $table, $data); } } else { echo json_encode(['result' => 0, 'message' => 'Test not found or is not an object']); return; } } else { echo json_encode(['result' => 0, 'message' => 'User not logged in']); return; } } public function online_test_result_subject_wise() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $mapping_id = $this->request->uri->getSegment(2); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course_id = $res->course_id; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = $res->course_title; $data['course_title'] = $course; $sub_domain_id = $this->request->uri->getSegment(3); $mocktest_id = $this->request->uri->getSegment(4); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $answered_on = $date->format('Y-m-d H:i:s'); $table = "question_mapping"; $where = ['subject_id' => $sub_domain_id, 'test_type' => 'Mock Test']; $order_by = 'test_id'; $test = $nparrotsModel->getWhereRowOrderBy($table, $where, $order_by); $test_id = $test->test_id; $answer_table = 'answered_questions'; $where_answered_questions = ['answered_by' => $login_id, 'test_id' => $test_id]; $get_answered_questions = $nparrotsModel->get_where_result25($answer_table, $where_answered_questions); if (empty($get_answered_questions)) { $test_id = $test->test_id; $test_questions = json_decode($test->question_id); foreach ($test_questions as $test_quests) { $answer_table = 'answered_questions'; $questions = $test_quests; $data = [ 'answered_by' => $login_id, 'question_id' => $questions, 'test_type' => 'subject_wise', 'correct_answer' => '0', 'test_id' => $test_id, 'answered_on' => $answered_on, 'sub_domain_id' => $sub_domain_id ]; $result = $this->db->table($answer_table)->insert($data); $table = 'question_mapping'; $where = ['test_id' => $test_id]; $data = ['test_status' => 'COMPLETED', 'test_status' => 'ONGOING']; $res = $nparrotsModel->UpdateData($where, $table, $data); } } else { $where_quests = ['subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_id' => $test_id]; $order_by = 'test_id'; $get_questions_mapping = $nparrotsModel->getWhereRowOrderBy($table, $where, $order_by); $question_id = $get_questions_mapping->question_id; $question_ids = json_decode($get_questions_mapping->question_id); $get_quests = $nparrotsModel->getWhereQuestionsSubjects($question_ids, $test_id, $sub_domain_id); foreach ($get_quests as $un_answered) { $unanswered_quest = $un_answered; $answer_table = 'answered_questions'; $data = [ 'answered_by' => $login_id, 'question_id' => $unanswered_quest, 'test_type' => 'subject_wise', 'correct_answer' => '0', 'test_id' => $test_id, 'answered_on' => $answered_on, 'sub_domain_id' => $sub_domain_id ]; $result = $this->db->table($answer_table)->insert($data); $table = 'question_mapping'; $where = ['test_id' => $test_id]; $data = ['test_status' => 'COMPLETED', 'test_status' => 'ONGOING']; $res = $nparrotsModel->UpdateData($where, $table, $data); } } $table = 'question_mapping'; $where = ['subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Mock Test']; $get_test_id = $nparrotsModel->get_where_result($table, $where); foreach ($get_test_id as $value) { $test_id = $value->test_id; $quest_id = $value->question_id; $faculty_id = $value->faculty_id; } $question_table = 'questions'; $where_sub_domain_id = ['status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->getQuestionsForMocktestReview($sub_domain_id, $quest_id, $test_id, $faculty_id, $mocktest_id); $data['tot_questions'] = $nparrotsModel->getWhereResult($question_table, $where_sub_domain_id); $data['total_questions'] = count($data['tot_questions']); $table = "sub_domains"; $where = ['sub_domain_id' => $sub_domain_id]; $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); $data['correct_answer'] = $nparrotsModel->subjectWiseCorrectAnswer($sub_domain_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); $where_course = ['course_id' => $sub_domain_id]; $course_table = 'courses'; $data['course_sub_domain'] = $nparrotsModel->getWhereRow($course_table, $where_course); $data['mapping_id'] = $mapping_id; $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course_id = $res->course_id; $table = 'courses'; $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->getWhereRow($table, $where); $course = $res->course_title; $data['course_title'] = $course; echo view('user/online_test_result_subject_wise', $data); } } public function get_chapter_wise_reportresult() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $test_id = $this->request->uri->getSegment(3); $table = 'question_mapping'; $where = ['test_id' => $test_id, 'user_id' => $login_id]; $get_test_id = $nparrotsModel->getWhereRow($table, $where); $chapter_id = $get_test_id->chapter_id; $sub_domain_id = $get_test_id->subject_id; $correct_answer = $nparrotsModel->correct_answer($chapter_id, $login_id, $test_id, $sub_domain_id); $data['correct_answer'] = $correct_answer; $incorrect_answer = $nparrotsModel->incorrect_answer($chapter_id, $login_id, $test_id, $sub_domain_id); $data['incorrect_answer'] = $incorrect_answer; $not_attempted_answer = $nparrotsModel->not_attempted_answer($chapter_id, $login_id, $test_id, $sub_domain_id); $data['not_attempted_answer'] = $not_attempted_answer; return json_encode(['data' => $data]); } } // public function final_test_result() // { // $login_id = session()->get('user_login_id'); // $nparrotsModel = new Amcad_Home(); // if ($login_id) { // $table = 'login'; // $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->get_where_row($table, $where); // $fullname = $res->username; // $email = $res->email; // $mapping_id = $this->request->uri->getSegment(2); // $table = 'user_course_mapping'; // $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->get_where_row($table, $where); // $course_id = $res->course_id; // $table = 'courses'; // $where = [ // 'course_id' => $course_id, 'delete_status' => 'ACTIVE' // ]; // $res = $nparrotsModel->get_where_row($table, $where); // $course = $res->course_title; // $data['course_title'] = $course; // $sub_domain_id = $this->request->uri->getSegment(3); // $table = 'question_mapping'; // $where = ['subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; // $get_test_id = $nparrotsModel->get_where_result($table, $where); // $quest_id = ''; // Initialize $quest_id outside the loop // $test_id = ''; // Initialize $test_id outside the loop // $faculty_id = ''; // Initialize $faculty_id outside the loop // $sub_domain_ids = ''; // Initialize $sub_domain_ids outside the loop // foreach ($get_test_id as $value) { // $test_id = $value->test_id; // $quest_id = $value->question_id; // $faculty_id = $value->faculty_id; // $sub_domain_ids = $value->subject_id; // } // $question_table = 'questions'; // $where_sub_domain_id = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->get_questions_for_finals_review1($sub_domain_id, $quest_id, $test_id, $faculty_id); // $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_sub_domain_id); // $data['total_questions'] = count($data['tot_questions']); // $table = "sub_domains"; // $where = ['sub_domain_id' => $sub_domain_id]; // $data['sub_domain'] = $nparrotsModel->get_where_row($table, $where); // $data['correct_answer'] = $nparrotsModel->subject_wise_correct_answer($sub_domain_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->subject_wise_incorrect_answer($sub_domain_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->subject_wise_not_attempted_answer($sub_domain_id, $login_id, $test_id); // $where_course = ['course_id' => $sub_domain_id]; // $course_table = 'courses'; // $data['course_sub_domain'] = $nparrotsModel->get_where_row($course_table, $where_course); // $data['mapping_id'] = $mapping_id; // $table = 'faculty_mocktest_setting'; // $where = ['sub_domain_id' => $sub_domain_ids, 'created_by' => $faculty_id, 'delete_status' => 'ACTIVE', 'test_type' => 'Final Test']; // $data['finals_result'] = $passing_marks = $nparrotsModel->get_where_row($table, $where); // $data['finals_score'] = $finals_score = $nparrotsModel->get_where_final_result_score($test_id, $login_id, $sub_domain_id); // // Your email content // // $content = view('emails/final_test_result', $data); // Assuming you have an email template // // Load Email library // $href = base_url(); // $content = ''; // $content .= '<body style="background:#f3f3f3;">'; // $content .= '<div style="width:100%;">'; // $content .= '<div style="text-align: center;">'; // $content .= '<div>'; // $content .= '<img src="' . $href . 'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; // $content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; // $content .= '</div>'; // $content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; // $content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; // $content .= '</div>'; // $content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; // $content .= '<h3 style="margin-top:10px;">Final Test Result</h3>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . esc($fullname) . ',</p>'; // Use esc() for security // if ($finals_score < $passing_marks->passing_criteria) { // $mapping_table = 'question_mapping'; // $where_user = ['test_id' => $test_id, 'subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; // $result_status = ['final_result' => 'FAIL']; // $status_result = $nparrotsModel->update_data2($where_user, $mapping_table, $result_status); // $content .= '<p style="font-size:16px;padding-bottom:10px;">Sorry! You have not passed the Final Test of the course ' . esc($course) . '.' . '</p>'; // } else { // $mapping_table = 'question_mapping'; // $where_user = ['test_id' => $test_id, 'subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; // $result_status = ['final_result' => 'PASS']; // $status_result = $nparrotsModel->update_data2($where_user, $mapping_table, $result_status); // $content .= '<p style="font-size:16px;padding-bottom:10px;">Congratulations! You have passed the Final Test of the course ' . esc($course) . ' scoring: ' . esc($finals_score) . '. Please find the certificate of your final test attached below.</br> Thank You.</p>'; // } // $content .= '</div>'; // $content .= '</div>'; // $content .= '</div>'; // $content .= '</body>'; // $emailService = \Config\Services::email(); // $emailService->setFrom('johncameron6677@gmail.com', 'Amcad'); // $emailService->setTo($email); // $emailService->setSubject('Final Test Result'); // $emailService->setMessage($content); // // Send email // $emailService->send(); // return view('user/final_test_result', $data); // } // } // public function final_test_result() // { // $login_id = session()->get('user_login_id'); // $nparrotsModel = new Amcad_Home(); // if ($login_id) { // $table = 'login'; // $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // $fullname = $res->username; // $email = $res->email; // $mapping_id = $this->request->uri->getSegment(2); // $table = 'user_course_mapping'; // $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; // $res = $nparrotsModel->getWhereRow($table, $where); // if ($res && is_object($res) && property_exists($res, 'course_title')) { // $course = $res->course_title; // $table = 'courses'; // $where = [ // 'course_id' => $course_id, 'delete_status' => 'ACTIVE' // ]; // $res = $nparrotsModel->getWhereRow($table, $where); // $course = $res->course_title; // $data['course_title'] = $course; // $sub_domain_id = $this->request->uri->getSegment(3); // $table = 'question_mapping'; // $where = ['subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; // $get_test_id = $nparrotsModel->get_where_result($table, $where); // foreach ($get_test_id as $value) { // $test_id = $value->test_id; // $quest_id = $value->question_id; // $faculty_id = $value->faculty_id; // $sub_domain_ids = $value->subject_id; // } // $question_table = 'questions'; // $where_sub_domain_id = ['status' => 'ACTIVE']; // $data['questions'] = $nparrotsModel->get_questions_for_finals_review($sub_domain_id, $quest_id, $test_id, $faculty_id); // $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_sub_domain_id); // $data['total_questions'] = count($data['tot_questions']); // $table = "sub_domains"; // $where = ['sub_domain_id' => $sub_domain_id]; // $data['sub_domain'] = $nparrotsModel->getWhereRow($table, $where); // $data['correct_answer'] = $nparrotsModel->subject_wise_correct_answer($sub_domain_id, $login_id, $test_id); // $data['incorrect_answer'] = $nparrotsModel->subject_wise_incorrect_answer($sub_domain_id, $login_id, $test_id); // $data['not_attempted_answer'] = $nparrotsModel->subject_wise_not_attempted_answer($sub_domain_id, $login_id, $test_id); // $where_course = ['course_id' => $sub_domain_id]; // $course_table = 'courses'; // $data['course_sub_domain'] = $nparrotsModel->getWhereRow($course_table, $where_course); // $data['mapping_id'] = $mapping_id; // $table = 'faculty_mocktest_setting'; // $where = ['sub_domain_id' => $sub_domain_ids, 'created_by' => $faculty_id, 'delete_status' => 'ACTIVE', 'test_type' => 'Final Test']; // $data['finals_result'] = $passing_marks = $nparrotsModel->getWhereRow($table, $where); // $data['finals_score'] = $finals_score = $nparrotsModel->get_where_final_result_score($test_id, $login_id, $sub_domain_id); // // Your email content // // $content = view('emails/final_test_result', $data); // Assuming you have an email template // // Load Email library // $href = base_url(); // $content = ''; // $content .= '<body style="background:#f3f3f3;">'; // $content .= '<div style="width:100%;">'; // $content .= '<div style="text-align: center;">'; // $content .= '<div>'; // $content .= '<img src="' . $href . 'public/assets/images/all_logo.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; // $content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; // $content .= '</div>'; // $content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; // $content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; // $content .= '</div>'; // $content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; // $content .= '<h3 style="margin-top:10px;">Final Test Result</h3>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . esc($fullname) . ',</p>'; // Use esc() for security // if ($finals_score < $passing_marks->passing_criteria) { // $mapping_table = 'question_mapping'; // $where_user = ['test_id' => $test_id, 'subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; // $result_status = ['final_result' => 'FAIL']; // $status_result = $nparrotsModel->update_data2($where_user, $mapping_table, $result_status); // $content .= '<p style="font-size:16px;padding-bottom:10px;">Sorry! You have not passed the Final Test of the course ' . esc($course) . '.' . '</p>'; // } else { // $mapping_table = 'question_mapping'; // $where_user = ['test_id' => $test_id, 'subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; // $result_status = ['final_result' => 'PASS']; // $status_result = $nparrotsModel->update_data2($where_user, $mapping_table, $result_status); // $content .= '<p style="font-size:16px;padding-bottom:10px;">Congratulations! You have passed the Final Test of the course ' . esc($course) . ' scoring: ' . esc($finals_score) . '. Please find the certificate of your final test attached below.</br> Thank You.</p>'; // } // $content .= '</div>'; // $content .= '</div>'; // $content .= '</div>'; // $content .= '</body>'; // $emailService = \Config\Services::email(); // $emailService->setFrom('johncameron6677@gmail.com', 'AMCAD'); // $emailService->setTo($email); // $emailService->setSubject('Final Test Result'); // $emailService->setMessage($content); // // Send email // $emailService->send(); // return view('user/final_test_result', $data); // } else { // // Handle the case where course information is not as expected // } // } // } public function final_test_result() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $table = 'login'; $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->get_where_row($table, $where); $fullname = $res->username; $email = $res->email; $mapping_id = $this->request->uri->getSegment(2); $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id, 'user_id' => $login_id, 'delete_status' => 'ACTIVE']; $res = $nparrotsModel->get_where_row($table, $where); $course_id = $res->course_id; $table = 'courses'; $where = [ 'course_id' => $course_id, 'delete_status' => 'ACTIVE' ]; $res = $nparrotsModel->get_where_row($table, $where); $course = $res->course_title; $data['course_title'] = $course; $sub_domain_id = $this->request->uri->getSegment(3); $table = 'question_mapping'; $where = ['subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; $get_test_id = $nparrotsModel->get_where_result($table, $where); foreach ($get_test_id as $value) { $test_id = $value->test_id; $quest_id = $value->question_id; $faculty_id = $value->faculty_id; $sub_domain_ids = $value->subject_id; } $question_table = 'questions'; $where_sub_domain_id = ['status' => 'ACTIVE']; $data['questions'] = $nparrotsModel->get_questions_for_finals_review($sub_domain_id, $quest_id, $test_id, $faculty_id); $data['tot_questions'] = $nparrotsModel->get_where_result($question_table, $where_sub_domain_id); $data['total_questions'] = count($data['tot_questions']); $table = "sub_domains"; $where = ['sub_domain_id' => $sub_domain_id]; $data['sub_domain'] = $nparrotsModel->get_where_row($table, $where); $data['correct_answer'] = $nparrotsModel->subject_wise_correct_answer($sub_domain_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->subject_wise_incorrect_answer($sub_domain_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->subject_wise_not_attempted_answer($sub_domain_id, $login_id, $test_id); $where_course = ['course_id' => $sub_domain_id]; $course_table = 'courses'; $data['course_sub_domain'] = $nparrotsModel->get_where_row($course_table, $where_course); $data['mapping_id'] = $mapping_id; $table = 'faculty_mocktest_setting'; $where = ['sub_domain_id' => $sub_domain_ids, 'created_by' => $faculty_id, 'delete_status' => 'ACTIVE', 'test_type' => 'Final Test']; $data['finals_result'] = $passing_marks = $nparrotsModel->get_where_row($table, $where); $data['finals_score'] = $finals_score = $nparrotsModel->get_where_final_result_score($test_id, $login_id, $sub_domain_id); // Your email content // $content = view('emails/final_test_result', $data); // Assuming you have an email template // Load Email library $href = base_url(); $content = ''; $content .= '<body style="background:#f3f3f3;">'; $content .= '<div style="width:100%;">'; $content .= '<div style="text-align: center;">'; $content .= '<div>'; $content .= '<img src="' . $href . 'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $content .= '</div>'; $content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $content .= '</div>'; $content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $content .= '<h3 style="margin-top:10px;">Final Test Result</h3>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . esc($fullname) . ',</p>'; // Use esc() for security if ($finals_score < $passing_marks->passing_criteria) { $mapping_table = 'question_mapping'; $where_user = ['test_id' => $test_id, 'subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; $result_status = ['final_result' => 'FAIL']; $status_result = $nparrotsModel->update_data2($where_user, $mapping_table, $result_status); $content .= '<p style="font-size:16px;padding-bottom:10px;">Sorry! You have not passed the Final Test of the course ' . esc($course) . '.' . '</p>'; } else { $mapping_table = 'question_mapping'; $where_user = ['test_id' => $test_id, 'subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Final Test']; $result_status = ['final_result' => 'PASS']; $status_result = $nparrotsModel->update_data2($where_user, $mapping_table, $result_status); $content .= '<p style="font-size:16px;padding-bottom:10px;">Congratulations! You have passed the Final Test of the course ' . esc($course) . ' scoring: ' . esc($finals_score) . '. Please find the certificate of your final test attached below.</br> Thank You.</p>'; } $content .= '</div>'; $content .= '</div>'; $content .= '</div>'; $content .= '</body>'; $emailService = \Config\Services::email(); $emailService->setFrom('johncameron6677@gmail.com', 'Amcad'); $emailService->setTo($email); $emailService->setSubject('Final Test Result'); $emailService->setMessage($content); // Send email $emailService->send(); return view('user/final_test_result', $data); } } public function get_marked_questions() { $loginId = session('user_login_id'); $table = "answered_questions"; $nparrotsModel = new Amcad_Home(); $resultTest = $nparrotsModel->get_last_row(); $testId = $resultTest->test_id; $subjectId = $resultTest->subject_id; $result = $nparrotsModel->getMarkedQuestions($loginId, $testId, $subjectId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something wrong...']); } } public function add_recorded_feedback() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $login_id = session()->get('user_login_id'); $institution_id = session()->get('user_institution_id'); $course_id = $this->request->getPost('course_id'); $feedback = $this->request->getPost('feedback'); $faculty_id = $this->request->getPost('faculty_id'); $objectives = $this->request->getPost('objectives'); $combination_of_training = $this->request->getPost('combination_of_training'); $program_duration = $this->request->getPost('program_duration'); $material_use = $this->request->getPost('material_use'); $learnt_things = $this->request->getPost('learnt_things'); $data = [ 'institution_id' => $institution_id, 'course_id' => $course_id, 'feedback' => $feedback, 'faculty_id' => $faculty_id, 'objectives' => $objectives, 'combination_of_training' => $combination_of_training, 'program_duration' => $program_duration, 'material_use' => $material_use, 'learnt_things' => $learnt_things, 'delete_status' => 'ACTIVE', 'faculty_id' => $faculty_id, 'created_by' => $login_id, 'created_at' => $created_at ]; $feedback_model = new Amcad_Home(); $feedback_table = 'feedback'; $result = $feedback_model->insert9($feedback_table, $data); if ($result) { return json_encode(['result' => 1, 'message' => 'Added Successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong..']); } } public function add_tocart_without_login_cookie() { $course_id = $this->request->getPost('course_id'); $course_title = $this->request->getPost('course_title'); $course_price = $this->request->getPost('course_price'); $batch_ids = $this->request->getPost('batch_id'); $faculty_ids = $this->request->getPost('faculty_id'); $subdomain_id = $this->request->getPost('subdomain_id'); $from_time = $this->request->getPost('from_time'); $to_time = $this->request->getPost('to_time'); $session_type = $this->request->getPost('session_type'); $form_faculty_ids = $this->request->getPost('form_faculty_ids'); $form_batch_ids = $this->request->getPost('form_batch_ids'); if ($form_batch_ids == null && $form_faculty_ids == null) { return $this->response->setJSON(['result' => 0, 'message' => 'Choose batch or faculty']); } elseif ($form_batch_ids != null && $form_faculty_ids != null) { return $this->response->setJSON(['result' => 0, 'message' => 'Choose batch or faculty']); } else { if ($form_batch_ids == null) { $batch_ids = 'null'; $faculty_ids = json_encode(explode(',', $this->request->getVar('faculty_id'))); $subdomain_id = json_encode(explode(',', $this->request->getVar('subdomain_id'))); $from_time = json_encode(explode(',', $this->request->getVar('from_time'))); $to_time = json_encode(explode(',', $this->request->getVar('to_time'))); $session_type = json_encode(explode(',', $this->request->getVar('session_type'))); } if ($form_faculty_ids == null) { $faculty_ids = json_encode(explode(',', $this->request->getVar('faculty_id'))); $batch_ids = json_encode(explode(',', $this->request->getVar('batch_id'))); $subdomain_id = json_encode(explode(',', $this->request->getVar('subdomain_id'))); $from_time = json_encode(explode(',', $this->request->getVar('from_time'))); $to_time = json_encode(explode(',', $this->request->getVar('to_time'))); $session_type = json_encode(explode(',', $this->request->getVar('session_type'))); } $cookies = [ 'course_ids' => $course_id, 'course_titles' => $course_title, 'course_prices' => $course_price, 'course_batch' => $batch_ids, 'course_faculty' => $faculty_ids, 'course_subdomain' => $subdomain_id, 'course_fromtime' => $from_time, 'course_totime' => $to_time, 'course_session' => $session_type, ]; foreach ($cookies as $key => $value) { $this->response->setCookie($key, $value, 86400 * 30); } return $this->response->setJSON([ 'result' => 2, 'course_ids' => json_encode($course_id), 'course_titles' => json_encode($course_title), 'course_prices' => json_encode($course_price), 'course_faculty' => json_encode($faculty_ids), 'course_batch' => json_encode($batch_ids), ]); } } public function get_subject_wise_result() { $login_id = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($login_id) { $sub_domain_id = $this->request->uri->getSegment(3); $table = 'question_mapping'; $where = ['subject_id' => $sub_domain_id, 'user_id' => $login_id, 'test_type' => 'Mock Test']; $get_test_id = $nparrotsModel->get_where_result($table, $where); $test_id = null; foreach ($get_test_id as $value) { $test_id = $value->test_id; } $correct_answer = $nparrotsModel->subject_wise_correct_answer($sub_domain_id, $login_id, $test_id); $data['correct_answer'] = $nparrotsModel->subject_wise_correct_answer($sub_domain_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->subject_wise_incorrect_answer($sub_domain_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); $incorrect_answer = $nparrotsModel->subjectWiseIncorrectAnswer($sub_domain_id, $login_id, $test_id); $not_attempted_answer = $nparrotsModel->subjectWiseNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); $data_1['correct_answer'] = $correct_answer; $data_1['incorrect_answer'] = $incorrect_answer; $data_1['not_attempted_answer'] = $not_attempted_answer; return $this->response->setJSON(['data' => $data_1]); } } public function get_subject_wise_questions() { $nparrotsModel = new Amcad_Home(); $qid = $this->request->getPost('question_id'); $table = 'questions'; $where = ['qid' => $qid]; $get_det = $nparrotsModel->getWhereRow($table, $where); $user_id = session()->get('user_login_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $map_table = 'question_mapping'; $result_test = $nparrotsModel->get_last_row(); $test_id = $result_test->test_id; $correct_answer = $nparrotsModel->getUserSubjectAnswer($user_id, $test_id, $qid, $sub_domain_id); if ($get_det) { return $this->response->setJSON(['result' => 1, 'details' => $get_det, 'user_answer' => $correct_answer]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..!']); } } public function get_final_test_result() { $nparrotsModel = new Amcad_Home(); $login_id = session()->get('user_login_id'); if ($login_id) { $sub_domain_id = $this->request->uri->getSegment(3); $table = 'question_mapping'; $where = ['subject_id' => $sub_domain_id, 'user_id' => $login_id]; $get_test_id = $nparrotsModel->get_where_result($table, $where); $test_id = null; foreach ($get_test_id as $value) { $test_id = $value->test_id; } $correct_answer = $nparrotsModel->final_test_correct_answer($sub_domain_id, $login_id, $test_id); $data['correct_answer'] = $nparrotsModel->final_test_correct_answer($sub_domain_id, $login_id, $test_id); $data['incorrect_answer'] = $nparrotsModel->finalTestIncorrectAnswer($sub_domain_id, $login_id, $test_id); $data['not_attempted_answer'] = $nparrotsModel->finalTestNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); $incorrect_answer = $nparrotsModel->finalTestIncorrectAnswer($sub_domain_id, $login_id, $test_id); $not_attempted_answer = $nparrotsModel->finalTestNotAttemptedAnswer($sub_domain_id, $login_id, $test_id); $data_1['correct_answer'] = $correct_answer; $data_1['incorrect_answer'] = $incorrect_answer; $data_1['not_attempted_answer'] = $not_attempted_answer; return $this->response->setJSON(['data' => $data_1]); } } public function download_certificate() { $loginId = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($loginId) { $mapping_id = $this->request->uri->getSegment(2); $table = 'user_course_mapping'; $whereDomain = ['mapping_id' => $mapping_id]; $mappData = $nparrotsModel->getWhereRow($table, $whereDomain); $batch_ids = json_decode($mappData->batch_ids); // print_r($batch_ids);die(); if ($batch_ids) { $table = "batches"; $where = ['batch_id' => $batch_ids[0]]; $row = $nparrotsModel->getWhereRow($table, $where); $subDomainId = $row->sub_domain_id; $facultyId = $row->faculty_id; $data['course_details'] = $courseDetails = $nparrotsModel->getUserCourseDetails($loginId, $mapping_id); $data['mapping_subjects'] = $mapping = $nparrotsModel->getMappingCourseSubjects($mapping_id); $whereCourse = ['course_id' => $mappData->course_id]; $courseTable = 'courses'; $data['course_sub_domain'] = $nparrotsModel->getWhereRow($courseTable, $whereCourse); $tableData1 = "syllabus_chapter"; $whereData1 = ['sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE']; $tableData2 = "sub_domains"; $whereData2 = ['sub_domain_id' => $subDomainId]; $data['chapters'] = $nparrotsModel->get_where_result($tableData1, $whereData1); $table = 'faculty_mocktest_setting'; $where = [ 'created_by' => $facultyId, 'test_type' => 'Mock Test', 'sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE' ]; $data['mocktests'] = $nparrotsModel->get_where_result($table, $where); $data['subjects'] = $nparrotsModel->get_where_result($tableData2, $whereData2); return view('user/download_certificate', $data); } else { $table = 'user_course_mapping'; $where = ['mapping_id' => $mapping_id]; $res = $nparrotsModel->getWhereRow($table, $where); $facId = json_decode($res->faculty_ids); $facultyId = $facId[0]; $ids = json_decode($mappData->sub_domain_ids); $data['course_details'] = $courseDetails = $nparrotsModel->getUserCourseDetails($loginId, $mapping_id); $data['mapping_subjects'] = $mapping = $nparrotsModel->getMappingCourseSubjects($mapping_id); $whereCourse = ['course_id' => $mappData->course_id]; $courseTable = 'courses'; $data['course_sub_domain'] = $nparrotsModel->getWhereRow($courseTable, $whereCourse); $tableData1 = "syllabus_chapter"; $whereData1 = ['sub_domain_id' => $ids[0], 'delete_status' => 'ACTIVE']; $tableData2 = "sub_domains"; $whereData2 = ['sub_domain_id' => $ids[0]]; $data['chapters'] = $nparrotsModel->get_where_result($tableData1, $whereData1); $table = 'faculty_mocktest_setting'; $where = [ 'created_by' => $facultyId, 'test_type' => 'Mock Test', 'sub_domain_id' => $ids[0], 'delete_status' => 'ACTIVE' ]; $data['mocktests'] = $nparrotsModel->get_where_result($table, $where); $data['subjects'] = $nparrotsModel->get_where_result($tableData2, $whereData2); // print_r($data['course_details']);die(); return view('user/download_certificate', $data); } } else { return redirect()->to('/'); } } public function payment() { $session = session(); $login_id = $session->get('user_login_id'); $sql = "SELECT * FROM login B, user_registrations C WHERE B.login_id = C.login_id AND B.login_id = $login_id"; $result = $this->db->query($sql); $data['result'] = $result->getRow(); $data['TXN_AMOUNT'] = $this->request->uri->getSegment(3); $data['ORDER_ID'] = $this->request->uri->getSegment(2); $data['MERCHANT_KEY'] = "qZwJyCXO"; $data['SALT'] = "QGfBaUODYg"; $data['PAYU_BASE_URL'] = "https://secure.payu.in"; return view('payuredirect/PayUMoney_form', $data); } public function failure() { return view('payuredirect/failure'); } // FACULTY public function faculty() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $logged_in = $date->format('Y-m-d H:i:s'); $session = session(); $nparrotsModel = new Amcad_Home(); if ($this->request->getCookie('login_status')) { $table = 'login'; $where_user = ['login_id' => $session->get('faculty_login_id'), 'delete_status' => 'ACTIVE']; $login_status = ['login_status' => 'OFFLINE', 'updated_at' => $logged_in]; $nparrotsModel->UpdateData($table, $login_status, $where_user); if ($this->db->affectedRows() > 0) { $session->remove(['faculty_login_id', 'faculty_user_type_id', 'faculty_username', 'faculty_user_type']); helper('cookie'); delete_cookie('login_status'); return redirect()->to('/faculty'); } } return view('faculty/faculty_login'); } public function faculty_login() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $logged_in = $date->format('Y-m-d H:i:s'); $email = $this->request->getPost('email'); $password = md5($this->request->getPost('password')); $passwordd = $this->request->getPost('password'); $remember = $this->request->getPost('remember'); $nparrotsModel = new Amcad_Home(); $result = $nparrotsModel->get_where_faculty($email, $password); if ($remember == 1) { setcookie("faculty_cookie_email", $email, time() + (86400 * 30), "/"); setcookie("faculty_cookie_password", $passwordd, time() + (86400 * 30), "/"); } else { setcookie("faculty_cookie_email", "", time() + (86400 * 30), "/"); setcookie("faculty_cookie_password", "", time() + (86400 * 30), "/"); } if ($result) { $login_condition = ' '; if (isset($_COOKIE['login_status'])) { $login_condition = $_COOKIE['login_status']; } if ($login_condition == ' ') { $table = 'login'; $where_user = ['login_id' => $result->login_id, 'delete_status' => 'ACTIVE']; $login_status = ['login_status' => 'OFFLINE', 'updated_at' => $logged_in]; $nparrotsModel->UpdateData5($where_user, $table, $login_status); if ($nparrotsModel->affectedRows() > 0) { $session = session(); $session->remove(['faculty_login_id', 'faculty_user_type_id', 'faculty_username', 'faculty_user_type', 'faculty_institution_id']); } } } if ($result) { $result =$nparrotsModel->get_where_faculty($email, $password); $login_table = 'login'; $where_user = ['login_id' => $result->login_id, 'delete_status' => 'ACTIVE']; $login_status = ['login_status' => 'ONLINE']; $nparrotsModel->UpdateData6($where_user, $login_table, $login_status); if ($result->verified_status == 'VERIFIED') { if ($result->return_status == 'NOT_RETURNED') { if ($result->approval_status == 'APPROVED') { $where_login = [ 'user_type_id' => $result->user_type_id, 'delete_status' => 'ACTIVE' ]; $data = ['last_logged_in' => $logged_in]; $login_table = 'login'; $update_logintime = $nparrotsModel->UpdateData7($where_login, $login_table, $data); if ($result->user_type_id == 2) { setcookie("login_status", 'LIVE', time() + (86400 * 30), "/"); $session = session(); $session->set(['faculty_login_id' => $result->login_id, 'faculty_user_type_id' => $result->faculty_user_type_id, 'faculty_username' => $result->username, 'faculty_full_name' => $result->fullname, 'faculty_user_type' => $result->user_type, 'faculty_approval_status' => $result->approval_status, 'faculty_institution_id' => $result->faculty_institution_id]); return $this->response->setJSON(['result' => 2, 'message' => 'Login Successful']); } else { return $this->response->setJSON(['result' => 4, 'message' => 'Wrong Login Credentials111111']); } } else { return $this->response->setJSON(['result' => 4, 'message' => 'Not approved by admin']); } } else { return $this->response->setJSON(['result' => 4, 'message' => 'Your Credentials are returned']); } } else { return $this->response->setJSON(['result' => 4, 'message' => 'Email Not Authenticated']); } } else { return $this->response->setJSON(['result' => 4, 'message' => 'Wrong Login Credentials']); } } public function faculty_dashboard() { $login_id = session('faculty_login_id'); $faculty_model = new Faculty_Model(); if ($login_id) { $data['feedback'] = count($faculty_model->get_faculty_feedback_list($login_id)); $data['enrolled_students'] = count($faculty_model->get_enrolled_students($login_id)); $table = 'batches'; $where = ['faculty_id' => $login_id, 'delete_status' => 'ACTIVE']; $data['batches'] = count($faculty_model->get_where_result($table, $where)); return view('faculty/faculty_dashboard', $data); } else { return redirect()->to('admin'); } } public function forgot_password() { $nparrotsModel = new Amcad_Home(); $email = $this->request->getPost('email'); $login_table = 'login'; $where_email = [ 'email' => $email, 'delete_status' => 'ACTIVE', 'verified_status' => 'VERIFIED', 'user_type_id' => 3, ]; $order_by = 'login_id'; $checkEmail = $nparrotsModel->getWhereOrderByRow2($login_table,$where_email,$order_by); if ($checkEmail) { if ($checkEmail->verified_status == "NOT_VERIFIED") { return json_encode(['result' => 2, 'message' => 'This email id not verified yet']); } else { $href = base_url(); $email_content = ''; $email_content .= '<body style="background:#f3f3f3;">'; $email_content .= '<div style="width:100%;">'; $email_content .= '<div style="text-align: center;">'; $email_content .= '<div>'; $email_content .= '<img src="'.$href.'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $email_content .= '</div>'; $email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $email_content .= '<img src="'.$href.'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $email_content .= '</div>'; $email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $email_content .= '<h3 style="margin-top:10px;">Reset Password</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$checkEmail->username.', </p>'; //$email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="'.$href.'update-password-user/'.$check_email->encrypted_login_id.'" style="color:#fff;padding:10px 30px;background:#a6d039;" style="color:#fff;padding:10px 30px;background:#a6d039;">Click here to update password</a></p>'; $email_content .= '<a href="' . site_url('reset_forgot_password_user?token='.$checkEmail->encrypted_login_id).'" style="background: #a6d039;padding: 10px 10px;color: white;letter-spacing: 1px;border-radius: 5px;text-decoration: none;">Click here to update password</a>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; // Send the email using your email library or service // Example using CodeIgniter 4 Email library: $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($checkEmail->email); $emailService->setSubject('Reset Password'); $emailService->setMessage($email_content); if ($emailService->send()) { return json_encode(['result' => 1, 'message' => 'Password reset link has been sent to your email id']); } else { return json_encode(['result' => 0, 'message' => 'Email could not be sent. Please try again later.']); } } } else { return json_encode(['result' => 0, 'message' => 'This email id does not exist or is not verified']); } } public function user_forget_passwrd() { return view('user/user_forget_pwd'); } public function faculty_forgot_password() { return view('faculty/faculty_forgot_password'); } public function faculty_forgot_pswd() { $email = $this->request->getPost('email'); $loginTable = 'login'; $whereEmail = [ 'email' => $email, 'delete_status' => 'ACTIVE', 'verified_status' => 'VERIFIED', 'user_type_id' => 2, ]; $orderBy = 'login_id'; $nparrotsModel = new Amcad_Home(); $checkEmail = $nparrotsModel->getWhereOrderByRow1($loginTable, $whereEmail, $orderBy); if ($checkEmail) { if ($checkEmail->verified_status == "NOT_VERIFIED") { return $this->response->setJSON([ 'result' => 2, 'message' => "This email id not verified yet", ]); } else { $href = base_url(); $emailContent = ''; $emailContent .= '<body style="background:#f3f3f3;">'; $emailContent .= '<div style="width:100%;">'; $emailContent .= '<div style="text-align: center;">'; $emailContent .= '<div>'; $emailContent .= '<img src="' . $href . 'public/assets/website_assets/icons/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $emailContent .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $emailContent .= '</div>'; $emailContent .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $emailContent .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px; margin-left: 30%;"/>'; $emailContent .= '</div>'; $emailContent .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $emailContent .= '<h3 style="margin-top:10px;">Reset Password</h3>'; $emailContent .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $checkEmail->username . ', </p>'; $emailContent .= '<a href="' . site_url('reset_forgot_password_faculty?token=' . $checkEmail->encrypted_login_id) . '" style="background: #a6d039; padding: 10px 10px; color: white; letter-spacing: 1px; border-radius: 5px; text-decoration: none;">Click here to update password</a>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</body>'; $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($email); $emailService->setSubject("Reset Password"); $emailService->setMessage($emailContent); if ($emailService->send()) { return $this->response->setJSON([ 'result' => 1, 'message' => "Password reset link has sent to your email id", ]); } else { return $this->response->setJSON([ 'result' => 0, 'message' => "Error sending email", ]); } } } else { return $this->response->setJSON([ 'result' => 0, 'message' => "This email id is not exists or not verified", ]); } } public function add_topics() { $loginId = session()->get('faculty_login_id'); $faculty_model = new Faculty_Model(); if ($loginId) { $table = 'faculty_registration'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $result = $faculty_model->getWhereRow($table, $where); $domainTable = 'domains'; $whereDomain = ['delete_status' => 'ACTIVE']; $orderBy = 'domain_name'; $data['domain'] = $faculty_model->getWhereResultOrderByAsc($domainTable, $whereDomain, $orderBy); // or use $data['domain'] = $faculty_model->getDomains($loginId); $data['login_id'] = session()->get('faculty_login_id'); $data['domain_id'] = $result->domain_id; return view('faculty/add_topics', $data); } else { return redirect()->to('/faculty'); } } // public function training_plan() // { // $loginId = session()->get('faculty_login_id'); // $faculty_model = new Faculty_Model(); // if ($loginId) { // $table = 'faculty_registration'; // $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; // $result = $faculty_model->getWhereRow($table, $where); // if ($result) { // // $subDomId = json_decode($result->sub_domain_id); // // $data['sub_domain'] = $faculty_model->getSubDomains($loginId); // $data['domain'] = $faculty_model->getDomains($loginId); // } else { // $data['sub_domain'] = ""; // } // return view('faculty/training_plan', $data); // } else { // return redirect()->to('admin'); // } // } public function training_plan() { $loginId = session()->get('faculty_login_id'); $training_model = new Training_Model(); if ($loginId) { $table = 'faculty_registration'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $result = $training_model->getWhereRow($table, $where); if ($result) { // $subDomId = json_decode($result->sub_domain_id); // $data['sub_domain'] = $this->nparrotsModel->getSubDomains($loginId); $data['domain'] = $training_model->getDomains($loginId); } else { $data['sub_domain'] = ""; } return view('faculty/training_plan', $data); } else { return redirect()->to('/admin'); } } public function mocktest_settings() { $loginId = session()->get('faculty_login_id'); $faculty_model = new Faculty_Model(); if ($loginId) { $table = 'faculty_registration'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $result = $faculty_model->getWhereRow($table, $where); if ($result) { $subDomId = json_decode($result->sub_domain_id); $data['domain'] = $faculty_model->getDomains($loginId); // $data['sub_domain'] = $faculty_model->getSubDomains($loginId); } else { $data['sub_domain'] = ""; } return view('faculty/mocktest_setting', $data); } else { return redirect()->to('/'); } } // public function faculty_batch() // { // $session = session(); // $login_id = $session->get('faculty_login_id'); // if ($login_id) { // $faculty_model = new Faculty_Model(); // $table = 'faculty_registration'; // $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; // $result = $faculty_model->getWhereRow($table, $where); // $institution_id = $result->institution_id; // if ($result) { // if ($institution_id != 0) { // $batch_table = 'batches'; // $where_batch = ['delete_status' => 'ACTIVE', 'institution_id' => $institution_id]; // $order_by_batch = 'batch_id'; // $batch = $faculty_model->getWhereOrderbyRow($batch_table, $where_batch, $order_by_batch); // if ($batch) { // $login_table = 'login'; // $where_login = ['delete_status' => 'ACTIVE', 'institution_id' => $institution_id]; // $inst = $faculty_model->getWhereRow($login_table, $where_login); // if ($inst->institution_id != 0) { // $login_table = 'login'; // $where_login = ['delete_status' => 'ACTIVE', 'login_id' => $institution_id]; // $institution = $faculty_model->getWhereRow($login_table, $where_login); // $institution_name = substr($institution->username, 0, 3); // $batch_name = substr($batch->batch_name, -4); // $batch_number = $batch_name + 1; // $data['batch'] = 'NP-' . $institution_name . '000' . $batch_number; // } else { // $institution_name = substr($inst->username, 0, 3); // $batch_name = substr($batch->batch_name, -4); // $batch_number = $batch_name + 1; // $data['batch'] = 'NP-' . $institution_name . '000' . $batch_number; // } // } else { // $login_table = 'login'; // $where_login = ['delete_status' => 'ACTIVE', 'institution_id' => $institution_id]; // $inst = $faculty_model->getWhereRow($login_table, $where_login); // $institution_name = substr($inst->username, 0, 3); // $batch_number = 1; // $data['batch'] = $institution_name . '000' . $batch_number; // } // } else { // $batch_table = 'batches'; // $where_batch = ['delete_status' => 'ACTIVE', 'institution_id' => '0']; // $order_by_batch = 'batch_id'; // $batch_res = $faculty_model->getWhereOrderbyRow($batch_table, $where_batch, $order_by_batch); // if ($batch_res) { // $batch_name = substr($batch_res->batch_name, -4); // $batch_number = $batch_name + 1; // $data['batch'] = 'NP000' . $batch_number; // } else { // $data['batch'] = 'NP0001'; // } // } // $sub_dom_id = json_decode($result->sub_domain_id); // $data['domain'] = $faculty_model->getDomains($login_id); // //$data['sub_domain'] = $faculty_model->get_sub_domains($login_id); // } else { // $data['sub_domain'] = ""; // } // $data['login_id'] = $login_id; // if ($institution_id == 0) { // return view('faculty/faculty_batch_form', $data); // } else { // $course_table = 'courses'; // $where_course = ['delete_status' => 'ACTIVE', 'created_by' => $institution_id]; // $order_by = 'course_title'; // $data['course'] = $faculty_model->getWhereResultOrderbyAsc($course_table, $where_course, $order_by); // return view('faculty/institution_faculty_batch_form', $data); // } // } else { // return redirect()->to('/'); // } // } public function faculty_batch() { $batch_model = new Batch_Model(); $loginId = session()->get('faculty_login_id'); if ($loginId) { $table = 'faculty_registration'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $result = $batch_model->getWhereRow($table, $where); $institutionId = $result->institution_id; if ($result) { if ($institutionId != 0) { $batchTable = 'batches'; $whereBatch = ['delete_status' => 'ACTIVE', 'institution_id' => $institutionId]; $orderByBatch = 'batch_id'; $batch = $batch_model->getWhereOrderByRow($batchTable, $whereBatch, $orderByBatch); if ($batch) { $loginTable = 'login'; $whereLogin = ['delete_status' => 'ACTIVE', 'institution_id' => $institutionId]; $inst = $batch_model->getWhereRow($loginTable, $whereLogin); if ($inst->institution_id != 0) { $loginTable = 'login'; $whereLogin = ['delete_status' => 'ACTIVE', 'login_id' => $institutionId]; $institution = $batch_model->getWhereRow($loginTable, $whereLogin); $institutionName = substr($institution->username, 0, 3); $batchName = substr($batch->batch_name, -4); $batchNumber = $batchName + 1; $data['batch'] = 'NP-' . $institutionName . '000' . $batchNumber; } else { $institutionName = substr($inst->username, 0, 3); $batchName = substr($batch->batch_name, -4); $batchNumber = $batchName + 1; $data['batch'] = 'NP-' . $institutionName . '000' . $batchNumber; } } else { $loginTable = 'login'; $whereLogin = ['delete_status' => 'ACTIVE', 'institution_id' => $institutionId]; $inst = $batch_model->getWhereRow($loginTable, $whereLogin); $institutionName = substr($inst->username, 0, 3); $batchNumber = 1; $data['batch'] = $institutionName . '000' . $batchNumber; } } else { $batchTable = 'batches'; $whereBatch = ['delete_status' => 'ACTIVE', 'institution_id' => '0']; $orderByBatch = 'batch_id'; $batchRes = $batch_model->getWhereOrderByRow($batchTable, $whereBatch, $orderByBatch); if ($batchRes) { $batchName = substr($batchRes->batch_name, -4); $batchNumber = $batchName + 1; $data['batch'] = 'NP000' . $batchNumber; } else { $data['batch'] = 'NP0001'; } } $subDomId = json_decode($result->sub_domain_id); $data['domain'] = $batch_model->getDomains($loginId); //$data['sub_domain'] = $this->nparrots_model->get_sub_domains($login_id); } else { $data['sub_domain'] = ""; } $data['login_id'] = $loginId; if ($institutionId == 0) { return view('faculty/faculty_batch_form', $data); } else { $courseTable = 'courses'; $whereCourse = ['delete_status' => 'ACTIVE', 'created_by' => $institutionId]; $orderBy = 'course_title'; $data['course'] = $batch_model->getWhereResultOrderByAsc($courseTable, $whereCourse, $orderBy); return view('faculty/institution_faculty_batch_form', $data); } } else { return redirect()->to('/'); } } public function enrolled_students() { $loginId = session()->get('faculty_login_id'); if ($loginId) { return view('faculty/enrolled_students'); } else { return redirect()->to('/faculty'); } } public function faculty_feedbacks() { $loginId = session()->get('faculty_login_id'); if ($loginId) { return view('faculty/faculty_feedbacks'); } else { return redirect()->to('admin'); } } public function request_course() { $loginId = session()->get('faculty_login_id'); $facultyInstitutionId = session()->get('faculty_institution_id'); $faculty_model = new Faculty_Model(); if ($facultyInstitutionId == 0) { $createdBy = 1; } else { $createdBy = $facultyInstitutionId; } if ($loginId) { $table = 'faculty_registration'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $result = $faculty_model->getWhereRow($table, $where); if ($result) { $domainTable = 'domains'; $whereDomain = ['delete_status' => 'ACTIVE', 'created_by' => $createdBy]; $orderBy = 'domain_name'; $data['domain'] = $faculty_model->getWhereResultOrderByAsc($domainTable, $whereDomain, $orderBy); // $data['login_id'] = session()->get('faculty_login_id'); $data['domain_id'] = $result->domain_id; } else { $data['domain'] = ""; $data['domain_id'] = ''; } return view('faculty/request_course', $data); } else { return redirect()->to('/'); } } public function online_class_faculty() { return view('faculty/online_class_faculty'); } public function add_chapter_topics() { $table = 'topics'; $sub_domain_id = $this->request->getPost('sub_domain_id'); $login_id = $this->request->getPost('login_id'); $user_type_id = $this->request->getPost('user_type_id'); $domain_id = $this->request->getPost('domain_id'); $chapter_id = $this->request->getPost('chapter'); $topics_model = new Topics_Model(); $where = [ 'delete_status' => 'ACTIVE', 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, ]; $topic_name = $this->request->getPost('topic_name'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $i = 0; $j = 0; $k = 0; foreach ($topic_name as $val) { $topic_table = 'topics'; $where = [ 'sub_domain_id' => $sub_domain_id, 'topic_name' => htmlspecialchars($val), 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'chapter_id' => $chapter_id, ]; $chapter_result = $topics_model->getWhereRow($topic_table, $where); if ($chapter_result) { $i = $i + 1; } } $count = count($topic_name) - 1; while ($j <= $count) { while ($count >= 0) { if ($count != $j) { if ($topic_name[$j] == $topic_name[$count]) { $k = $k + 1; } } $count = $count - 1; } $j = $j + 1; $count = count($topic_name) - 1; } if ($i >= 1) { return json_encode(['result' => 0, 'message' => 'Topic names already exist']); } elseif ($k >= 1) { return json_encode(['result' => 0, 'message' => 'Topic names are duplicated']); } else { foreach ($topic_name as $val) { $chapter_id = $this->request->getPost('chapter'); $data = [ 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'topic_name' => $val, 'chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, 'user_type_id' => $user_type_id, //'updated_by' => $login_id, 'created_by' => $login_id, ]; $result = $topics_model->insertData($table, $data); } if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } } public function get_topics_list() { $login_id = session('faculty_login_id'); $faculty_model = new Faculty_Model(); $result = $faculty_model->getFacultyTopicsList($login_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } public function delete_topics() { $topic_id = $this->request->getPost('topic_id'); $where = ['topic_id' => $topic_id]; $data = ['delete_status' => 'INACTIVE']; $table = 'topics'; $faculty_model = new Faculty_Model(); $result = $faculty_model->UpdateData($table, $data, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } public function edit_topics() { $faculty_model = new Faculty_Model(); $topic_id = $this->request->getPost('topic_id'); $where = ['topic_id' => $topic_id, 'delete_status' => 'ACTIVE']; $table = 'topics'; $result = $faculty_model->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } public function update_topics() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $login_id = $this->request->getPost('login_id'); $user_type_id = $this->request->getPost('user_type_id'); $topic_id = $this->request->getPost('topic_id'); $chapter_id = $this->request->getPost('chapter_id'); $domain_id = $this->request->getPost('domain_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $topic_name = $this->request->getPost('topic_name'); $faculty_model = new Faculty_Model(); $where = ['delete_status' => 'ACTIVE', 'sub_domain_id' => $sub_domain_id]; $table = 'topics'; $result = $faculty_model->get_Where_Result($table, $where); $i = 0; $j = 0; $k = 0; foreach ($topic_name as $val) { $topic_table = 'topics'; $where = [ 'sub_domain_id' => $sub_domain_id, 'topic_name' => htmlspecialchars($val), 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'chapter_id' => $chapter_id, ]; $chapter_result = $faculty_model->getWhereRow($topic_table, $where); if ($chapter_result && $chapter_result->topic_id != $topic_id) { $i = $i + 1; } } $count = count($topic_name) - 1; while ($j <= $count) { while ($count >= 0) { if ($count != $j) { if ($topic_name[$j] == $topic_name[$count]) { $k = $k + 1; } } $count = $count - 1; } $j = $j + 1; $count = count($topic_name) - 1; } if ($i > 0) { return $this->response->setJSON(['result' => 0, 'message' => 'Topic name already exists']); } elseif ($k >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'Topic names are duplicated']); } else { $table = 'topics'; $where = ['topic_id' => $topic_id]; $result = $faculty_model->deleteRecord($table, $where); foreach ($topic_name as $val) { $chapter_id = $this->request->getPost('chapter'); $data = [ 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'topic_name' => $val, 'chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, 'user_type_id' => $user_type_id, 'updated_at' => $created_at, 'updated_by' => $login_id, 'created_by' => $login_id, ]; $result = $faculty_model->insertData($table, $data); } if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } } public function get_categories_list() { $faculty_model = new Faculty_Model(); $login_id = session('login_id'); $table = 'domains'; $where = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; $order_by = 'domain_name'; $result = $faculty_model->getWhereResultOrderByAsc($table, $where, $order_by); if ($result) { return $this->response->setJSON(['categories_list' => $result, 'result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_topics_chapters() { $faculty_model = new Faculty_Model(); $login_id = session('faculty_login_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $result = $faculty_model->getTopicsChapters($sub_domain_id, $login_id); // print_r($result);die(); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_domain_subdomain() { $session = session(); $login_id = $session->get('faculty_login_id'); $domain_id = $this->request->getPost('domain_id'); $training_model = new Training_Model(); $result = $training_model->get_domain_subdomain($login_id, $domain_id); // print_r($result);die(); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_subject_chapters() { $faculty_model = new Faculty_Model(); $subDomainId = $this->request->getPost('sub_domain_id'); $table = 'syllabus_chapter'; $where = ['sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE']; $result = $faculty_model->get_where_result($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_chapterwise_topics() { $uri = service('uri'); $chapter_id = $uri->getSegment(2); $faculty_model = new Faculty_Model(); $result = $faculty_model->getChapterwiseTopics($chapter_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0]); } } // public function check_faculty_session_status() // { // $faculty_model = new Faculty_Model(); // $login_id = session('faculty_login_id'); // $table = 'login'; // $where = ['login_id' => $login_id]; // $result = $faculty_model->getWhereRow($table, $where); // if ($result) { // if ($result->delete_status == 'INACTIVE' || $result->return_status == 'RETURNED') { // return $this->response->setJSON(['result' => 1]); // } else { // return $this->response->setJSON(['result' => 0]); // } // } else { // return $this->response->setJSON(['result' => 0]); // } // } public function get_faculty_details() { $faculty_model = new Faculty_Model(); $login_id = session('faculty_login_id'); $table = 'login'; $where = ['login_id' => $login_id]; $result = $faculty_model->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function check_faculty_session_type() { $faculty_model = new Faculty_Model(); $faculty_id = $this->request->getPost('faculty_id'); $result = $faculty_model->checkFacultySessionType($faculty_id); if ($result) { $array = []; foreach ($result as $val) { $session = json_decode($val->course_type); foreach ($session as $value) { array_push($array, $value); } } $session_type = in_array('live', $array) ? 'Live' : 'Recorded'; return $this->response->setJSON(['result' => 1, 'message' => $session_type]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_session_list() { $training_model = new Training_Model(); $login_id = session('faculty_login_id'); $result = $training_model->getSessionList($login_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function add_materials_form() { $loginId = session('faculty_login_id'); if ($loginId) { $faculty_model = new Faculty_Model(); $table = 'faculty_registration'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $result = $faculty_model->getWhereRow($table, $where); if ($result) { $subDomId = json_decode($result->sub_domain_id); $data['domain'] = $faculty_model->getDomains($loginId); } else { $data['sub_domain'] = ""; } return view('faculty/materials', $data); } else { return redirect()->to('/faculty'); } } public function faculty_logout() { $date = Time::now('Asia/Kolkata'); $logged_in = $date->format('Y-m-d H:i:s'); $faculty_model = new Faculty_Model(); helper('cookie'); if (isset($_COOKIE['login_status'])) { $table = 'login'; $where_user = ['login_id' => session('faculty_login_id'), 'delete_status' => 'ACTIVE']; $login_status = ['login_status' => 'OFFLINE', 'updated_at' => $logged_in]; $faculty_model->UpdateData($table, $login_status, $where_user); if ($this->db->affectedRows() > 0) { session()->remove(['faculty_login_id', 'faculty_user_type_id', 'faculty_username', 'faculty_user_type']); delete_cookie('login_status'); return redirect()->to('/faculty'); } } } public function edit_faculty_profile() { $facultyId = session()->get('faculty_login_id'); if ($facultyId) { $instructorModel = new InstructorModel(); $data['faculty_details'] = $instructorModel->getFacultyDetails($facultyId); $data['sub_domain'] = $instructorModel->getSubFacultyDomains($facultyId); $timingTable = 'faculty_available_timings'; $whereTiming = ['faculty_id' => $facultyId, 'delete_status' => 'ACTIVE']; $data['timing_details'] = $instructorModel->getWhereResult($timingTable, $whereTiming); return view('faculty/faculty_profile', $data); } else { return redirect()->to('/faculty'); } } public function update_faculty_password() { $login_id = session('faculty_login_id'); if ($login_id) { return view('faculty/update_faculty_password'); } else { return redirect()->to('/faculty'); } } public function reset_forgot_password_faculty() { $token = $this->request->getGet('token'); // Validate $token and fetch user details based on the token if ($token) { return view('faculty/forgot_password_faculty', ['token' => $token]); } else { return redirect()->to('/faculty'); } } // public function reset_forgot_password_faculty() // { // $token = $this->request->getGet('token'); // // Validate $token and fetch user details based on the token // $isValidToken = $this->validateResetToken($token); // if ($isValidToken) { // return view('faculty/forgot_password_faculty', ['token' => $token]); // } else { // // Invalid token, redirect or show an error message // return redirect()->to('/faculty')->with('error', 'Invalid or expired token'); // } // } public function reset_forgot_password_user() { $token = $this->request->getGet('token'); // Validate $token and fetch user details based on the token if ($token) { return view('user/forgot_password_user', ['token' => $token]); } else { return redirect()->to('/'); } } public function add_training_plans() { $training_model = new Training_Model(); if ($this->request->getPost('chapter') !== "") { $login_id = session()->get('faculty_login_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $chapter_id = json_encode($this->request->getPost('chapter')); $domain_id = $this->request->getPost('domain_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $session_time = $this->request->getPost('session_time'); $data = [ 'sub_domain_id' => $sub_domain_id, 'domain_id' => $domain_id, 'chapter_ids' => $chapter_id, 'session_time' => $session_time, 'delete_status' => 'ACTIVE', 'approval_status' => 'NOT_APPROVED', 'created_at' => $created_at, 'created_by' => $login_id, ]; $table = 'training_plans'; $result = $training_model->insertData($table, $data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Added Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Please select chapter']); } } // public function get_training_plan_edit_chapters() // { // $training_model = new Training_Model(); // $login_id = session()->get('faculty_login_id'); // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $training_plan_id = $this->request->getPost('training_plan_id'); // $result = $training_model->getTrainingPlanEditChapters($sub_domain_id, $login_id, $training_plan_id); // if ($result) { // return $this->response->setJSON(['result' => 1, 'message' => $result]); // } else { // return $this->response->setJSON(['result' => 0]); // } // } public function get_training_plan_edit_chapters() { $sub_domain_id = $this->request->getPost('sub_domain_id'); $training_plan_id = $this->request->getPost('training_plan_id'); $login_id = session()->get('faculty_login_id'); $training_model = new Training_Model(); $data['message'] = $training_model->getTrainingPlanEditChapters($sub_domain_id, $login_id, $training_plan_id); $response = [ 'result' => (!empty($data['message'])) ? 1 : 0, 'message' => $data['message'] ?? [] ]; return $this->response->setJSON($response); } // public function get_training_plan_chapters() // { // $session = session(); // $login_id = $session->get('faculty_login_id'); // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $training_model = new Training_Model(); // $result = $training_model->get_training_plan_chapters($sub_domain_id, $login_id); // // if ($result) { // // return $this->response->setJSON(['result' => 1, 'message' => $result]); // // } else { // // return $this->response->setJSON(['result' => 0]); // // } // $response = [ // 'result' => 1, // 'message' => [ // ['chapter_id' => 1, 'chapter_name' => 'Chapter 1'], // ['chapter_id' => 2, 'chapter_name' => 'Chapter 2'], // // Add more chapters as needed // ], // ]; // return $this->response->setJSON($response); // } public function get_training_plan_chapters() { $training_model = new Training_Model(); $loginId = session()->get('faculty_login_id'); $subDomainId = $this->request->getPost('sub_domain_id'); $result = $training_model->get_training_plan_chapters($subDomainId, $loginId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function update_training_plan() { $training_model = new Training_Model(); if ($this->request->getPost('chapter') != "") { $loginId = session()->get('faculty_login_id'); // Updated this line $trainingPlanId = $this->request->getPost('training_plan_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updatedAt = $date->format('Y-m-d H:i:s'); $chapterId = json_encode($this->request->getPost('chapter')); $domainId = $this->request->getPost('domain_id'); $subDomainId = $this->request->getPost('sub_domain_id'); $sessionTime = $this->request->getPost('session_time'); $data = [ 'sub_domain_id' => $subDomainId, 'domain_id' => $domainId, 'chapter_ids' => $chapterId, 'session_time' => $sessionTime, 'updated_at' => $updatedAt, 'updated_by' => $loginId, ]; $table = 'training_plans'; $where = ['training_plan_id' => $trainingPlanId]; $result = $training_model->UpdateData($table, $data, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Please select chapter']); } } public function training_plan_domains() { $training_model = new Training_Model(); $session = \Config\Services::session(); $loginId = $session->get('faculty_login_id'); $result = $training_model->getDomains($loginId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function training_plan_details() { $training_model = new Training_Model(); $trainingPlanId = $this->request->getPost('training_plan_id'); $table = 'training_plans'; $where = ['training_plan_id' => $trainingPlanId, 'delete_status' => 'ACTIVE']; $result = $training_model->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function delete_training_plan() { $training_model = new Training_Model(); $trainingPlanId = $this->request->getPost('id'); $table = 'training_plans'; $where = ['training_plan_id' => $trainingPlanId]; $data = ['delete_status' => 'INACTIVE']; $result = $training_model->UpdateData($table, $data, $where); if ($training_model->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } public function chpater_wise_training_plans() { $training_model = new Training_Model(); $login_id = session()->get('faculty_login_id'); $sub_domain_id = $this->request->uri->getSegment(2); $result = $training_model->chapter_wise_training_plans($sub_domain_id, $login_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0]); } } protected $helpers = ['form', 'url']; public function updateFacultyProfile() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $facultyId = session()->get('faculty_login_id'); $userName = $this->request->getPost('name'); $email = $this->request->getPost('email'); $phoneNumber = $this->request->getPost('phone_number'); $qualification = $this->request->getPost('qualification'); $experience = $this->request->getPost('experience'); $currentWork = $this->request->getPost('current_work'); $teachExperience = $this->request->getPost('teach_experience'); $location = $this->request->getPost('location'); $where = ['login_id' => $facultyId, 'delete_status' => 'ACTIVE']; $table = 'login'; $loginModel = new \App\Models\YourModel(); // Replace YourModel with the actual model name $loginResult = $loginModel->getWhereRow($where); $registeredEmail = $loginResult->email; $imageFiles = ""; if ($this->request->getFile('profile_pic')->isValid()) { $profilePic = $this->request->getFile('profile_pic'); $imageFiles = time() . $profilePic->getName(); $profilePic->move('course_images/', $imageFiles); } if ($registeredEmail == $email) { $data = [ 'username' => $userName, 'updated_at' => $createdAt, 'email' => $email, 'image' => $imageFiles, ]; $result = $loginModel->update($where, $table, $data); if ($loginModel->affectedRows() > 0) { // Handle video and resume file uploads here // ... if ($loginModel->affectedRows() > 0) { // Handle video file upload $videoFile = $this->request->getFile('samplevideo'); if ($videoFile->isValid()) { $videoSize = $videoFile->getSize(); if ($videoSize <= 50000000) { $videoFileName = time() . $videoFile->getName(); $videoFile->move('demo_videos/', $videoFileName); $registrationData['demo'] = json_encode($videoFileName); } else { return json_encode(['result' => 0, 'message' => 'Video size must not exceed 50mb']); } } // Handle resume file upload $resumeFile = $this->request->getFile('resume'); if ($resumeFile->isValid()) { $resumeSize = $resumeFile->getSize(); if ($resumeSize <= 2000000) { $resumeFileName = time() . $resumeFile->getName(); $resumeFile->move('public/faculty_resumes/', $resumeFileName); $registrationData['resume'] = json_encode($resumeFileName); } else { return json_encode(['result' => 0, 'message' => 'Resume size must not exceed 2mb']); } } // Continue with the registration data update... $registrationTable = 'faculty_registration'; $registrationData['fullname'] = $userName; $registrationData['phone'] = $phoneNumber; $registrationData['qualification'] = $qualification; // ... (other fields) $loginModel->update($where, $registrationTable, $registrationData); if ($loginModel->affectedRows() > 0) { $loginTable = 'login'; $loginData = ['username' => $userName, 'updated_at' => $createdAt]; $loginModel->update($where, $loginTable, $loginData); return json_encode(['result' => 2, 'message' => 'Data updated successfully. Please verify the link with OTP code sent to your email id to complete Authentication']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong']); } } else { return json_encode(['result' => 0, 'message' => 'Something went wrong']); } } } } public function get_mocktest_settings_without_chapter_details() { $faculty_model = new Faculty_Model(); $loginId = session()->get('faculty_login_id'); $result = $faculty_model->getMocktestSettingsWithoutChapterDetails($loginId); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 1, 'message' => 'No Data Found']); } } public function delete_mocktest_setting() { $loginId = session()->get('faculty_login_id'); $id = $this->request->getPost('id'); $where = ['id' => $id]; $table = 'faculty_mocktest_setting'; $data = ['delete_status' => 'INACTIVE']; $faculty_model = new Faculty_Model(); $result = $faculty_model->UpdateData($table, $data, $where); if ($faculty_model->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted Successfully']); } else { return $this->response->setJSON(['result' => 1, 'message' => 'Something Went Wrong..']); } } public function edit_mocktest_settings() { $loginId = session()->get('faculty_login_id'); $id = $this->request->getPost('id'); $where = ['id' => $id, 'delete_status' => 'ACTIVE']; $table = 'faculty_mocktest_setting'; $faculty_model = new Faculty_Model(); $result = $faculty_model->getWhereRow($table, $where); if ($result) { return json_encode(['result' => 1, 'message' => $result]); } else { return json_encode(['result' => 0]); } } public function update_mocktest_settings() { $loginId = session()->get('faculty_login_id'); $testType = $this->request->getPost('edit_optradio4'); $id = $this->request->getPost('mocktest_setting_id'); $faculty_model = new Faculty_Model(); $date = Time::now('Asia/Kolkata'); if ($testType == 'mock_test') { $mocktestDomainId = $this->request->getPost('edit_mocktest_domain_id'); $mocktestSubDomainId = $this->request->getPost('edit_mocktest_sub_domain_id'); $mocktestAddTime = $this->request->getPost('edit_mocktest_add_time'); $mocktestNumberOfQuestions = $this->request->getPost('edit_mocktest_number_of_questions'); $mocktestQuestOrder = $this->request->getPost('edit_mocktest_question_order'); $tableQuestion = 'questions'; $where = [ 'sub_domain_id' => $mocktestSubDomainId, 'status' => 'ACTIVE', 'faculty_id' => $loginId, ]; $nQuestions = $faculty_model->getWhereResultNew($tableQuestion, $where); if ($mocktestNumberOfQuestions <= $nQuestions) { $table = 'faculty_mocktest_setting'; $data = [ 'test_type' => 'Mock Test', 'domain_id' => $mocktestDomainId, 'sub_domain_id' => $mocktestSubDomainId, 'total_time' => $mocktestAddTime, 'number_of_questions' => $mocktestNumberOfQuestions, 'question_order' => $mocktestQuestOrder, 'selected_type' => 'Subject', 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $date->toDateTimeString(), ]; $where = ['id' => $id]; $result = $faculty_model->UpdateData($table, $data, $where); if ($result) { return json_encode(['result' => 1, 'message' => 'Added successfully']); } else { return json_encode(['result' => 0, 'message' => 'Please Fill All the Fields']); } } else { return json_encode(['result' => 2, 'message' => 'Number of questions available is ' . $nQuestions]); } } elseif ($testType == 'practice_test') { $practiceDomainId = $this->request->getPost('edit_practice_domain_id'); $practiceSubDomainId = $this->request->getPost('edit_practice_sub_domain_id'); $practiceChapterName = $this->request->getPost('edit_practice_chapter_name'); $practiceAddTime = $this->request->getPost('edit_practice_add_time'); $practiceNumberOfQuestions = $this->request->getPost('edit_practice_number_of_questions'); $practiceQuestionOrder = $this->request->getPost('edit_practice_question_order'); $tableQuestion = 'questions'; $where = [ 'chapter_id' => $practiceChapterName, 'sub_domain_id' => $practiceSubDomainId, 'status' => 'ACTIVE', 'faculty_id' => $loginId, ]; $practiceNQuestions = $faculty_model->getWhereResultNew($tableQuestion, $where); if ($practiceNumberOfQuestions <= $practiceNQuestions) { $table = 'faculty_mocktest_setting'; $whereChapter = [ 'test_type' => 'Practice Test', 'domain_id' => $practiceDomainId, 'delete_status' => 'ACTIVE', 'sub_domain_id' => $practiceSubDomainId, 'chapter' => $practiceChapterName, 'created_by' => $loginId, ]; $detailsChapter = $faculty_model->getWhereRow($table, $whereChapter); if (!empty($detailsChapter)) { return json_encode(['result' => 0, 'message' => 'Details Already Added']); } else { $data = [ 'test_type' => 'Practice Test', 'domain_id' => $practiceDomainId, 'sub_domain_id' => $practiceSubDomainId, 'chapter' => $practiceChapterName, 'total_time' => $practiceAddTime, 'number_of_questions' => $practiceNumberOfQuestions, 'question_order' => $practiceQuestionOrder, 'selected_type' => 'Chapter', 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $date->toDateTimeString(), ]; $where = ['id' => $id]; $result = $faculty_model->UpdateData($table, $data, $where); if ($result) { return json_encode(['result' => 1, 'message' => 'Added successfully']); } else { return json_encode(['result' => 0, 'message' => 'Please Fill All the Fields']); } } } else { return json_encode(['result' => 2, 'message' => 'Number of questions available is ' . $practiceNQuestions]); } } else { $finalTestDomainId = $this->request->getPost('edit_final_test_domain_id'); $finalTestSubDomainId = $this->request->getPost('edit_final_test_sub_domain_id'); $finalTestPassingCriteria = $this->request->getPost('edit_final_test_passing_criteria'); $finalTestAddTime = $this->request->getPost('edit_final_test_add_time'); $finalTestNumberOfQuestions = $this->request->getPost('edit_final_test_number_of_questions'); $finalTestQuestOrder = $this->request->getPost('edit_final_test_question_order'); $tableQuestion = 'questions'; $where = [ 'sub_domain_id' => $finalTestSubDomainId, 'status' => 'ACTIVE', 'faculty_id' => $loginId, ]; $finalNQuestions = $faculty_model->getWhereResultNew($tableQuestion, $where); if ($finalTestNumberOfQuestions <= $finalNQuestions) { $table = 'faculty_mocktest_setting'; $whereFinals = [ 'test_type' => 'Final Test', 'domain_id' => $finalTestDomainId, 'delete_status' => 'ACTIVE', 'sub_domain_id' => $finalTestSubDomainId, 'created_by' => $loginId, ]; $detailsFinals = $faculty_model->getWhereRow($table, $whereFinals); if (!empty($detailsFinals)) { return json_encode(['result' => 0, 'message' => 'Details Already Added']); } else { $data = [ 'test_type' => 'Final Test', 'domain_id' => $finalTestDomainId, 'sub_domain_id' => $finalTestSubDomainId, 'chapter' => '0', 'passing_criteria' => $finalTestPassingCriteria, 'total_time' => $finalTestAddTime, 'number_of_questions' => $finalTestNumberOfQuestions, 'question_order' => $finalTestQuestOrder, 'selected_type' => 'Subject', 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $date->toDateTimeString(), ]; $where = ['id' => $id]; $result = $faculty_model->UpdateData($table, $data, $where); if ($result) { return json_encode(['result' => 1, 'message' => 'Added successfully']); } else { return json_encode(['result' => 0, 'message' => 'Please Fill All the Fields']); } } } else { return json_encode(['result' => 2, 'message' => 'Number of questions available is ' . $finalNQuestions]); } } } public function get_mocktest_settings_details($id) { $loginId = session()->get('faculty_login_id'); $faculty_model = new Faculty_Model(); $result = $faculty_model->getMocktestSettingsDetails($loginId, $id); if ($result) { return json_encode($result); } else { return json_encode(['result' => 1, 'message' => 'No Data Found']); } } public function add_mocktest_settings() { $loginId = session()->get('faculty_login_id'); $testType = $this->request->getPost('select_test_optradio'); $faculty_model = new Faculty_Model(); if ($testType == 'mock_test') { $mocktestDomainId = $this->request->getPost('mocktest_domain_id'); $mocktestSubDomainId = $this->request->getPost('mocktest_sub_domain_id'); $mocktestAddTime = $this->request->getPost('mocktest_add_time'); $mocktestNumberOfQuestions = $this->request->getPost('mocktest_number_of_questions'); $mocktestQuestOrder = $this->request->getPost('mocktest_question_order'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $tableQuestion = 'questions'; $chapter = "0"; $where = ['sub_domain_id' => $mocktestSubDomainId, 'status' => 'ACTIVE', 'faculty_id' => $loginId]; $nQuestions = $faculty_model->getWhereResultNew($tableQuestion, $where); if ($mocktestNumberOfQuestions <= $nQuestions) { $table = 'faculty_mocktest_setting'; $where = ['test_type' => 'Mock Test']; $orderBy = 'mocktest_id'; $checkMocktest = $faculty_model->getWhereOrderbyRow($table, $where, $orderBy); $checkedMocktestId = $checkMocktest->mocktest_id; if (empty($checkMocktest)) { $mocktestId = 1; } else { $mocktestId = $checkedMocktestId + 1; } $data = [ 'test_type' => 'Mock Test', 'mocktest_id' => $mocktestId, 'domain_id' => $mocktestDomainId, 'sub_domain_id' => $mocktestSubDomainId, 'total_time' => $mocktestAddTime, 'number_of_questions' => $mocktestNumberOfQuestions, 'question_order' => $mocktestQuestOrder, 'selected_type' => 'Subject', 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $createdAt, ]; $result = $faculty_model->insertData($table, $data); if ($result) { return json_encode(['result' => 1, 'message' => 'Added successfully']); } else { return json_encode(['result' => 0, 'message' => 'Please Fill All the Fields']); } } else { return json_encode(['result' => 2, 'message' => 'Number of questions available is ' . $nQuestions]); } } elseif ($testType == 'practice_test') { $practiceDomainId = $this->request->getPost('practice_domain_id'); $practiceSubDomainId = $this->request->getPost('practice_sub_domain_id'); $practiceChapterName = $this->request->getPost('practice_chapter_name'); $practiceAddTime = $this->request->getPost('practice_add_time'); $practiceNumberOfQuestions = $this->request->getPost('practice_number_of_questions'); $practiceQuestionOrder = $this->request->getPost('practice_question_order'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $table = 'faculty_mocktest_setting'; $tableQuestion = 'questions'; $where = [ 'chapter_id' => $practiceChapterName, 'sub_domain_id' => $practiceSubDomainId, 'status' => 'ACTIVE', 'faculty_id' => $loginId, ]; // print_r($where);die(); $practiceNQuestions = $faculty_model->getWhereResultNew($tableQuestion, $where); if ($practiceNumberOfQuestions <= $practiceNQuestions) { $table = 'faculty_mocktest_setting'; $whereChapter = [ 'test_type' => 'Practice Test', 'domain_id' => $practiceDomainId, 'delete_status' => 'ACTIVE', 'sub_domain_id' => $practiceSubDomainId, 'chapter' => $practiceChapterName, 'created_by' => $loginId, ]; $detailsChapter = $faculty_model->getWhereRow($table, $whereChapter); if (!empty($detailsChapter)) { return json_encode(['result' => 0, 'message' => 'Details Already Added']); } else { $data = [ 'test_type' => 'Practice Test', 'domain_id' => $practiceDomainId, 'sub_domain_id' => $practiceSubDomainId, 'chapter' => $practiceChapterName, 'total_time' => $practiceAddTime, 'number_of_questions' => $practiceNumberOfQuestions, 'question_order' => $practiceQuestionOrder, 'selected_type' => 'Chapter', 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $createdAt, ]; $result = $faculty_model->insertData($table, $data); if ($result) { return json_encode(['result' => 1, 'message' => 'Added successfully']); } else { return json_encode(['result' => 0, 'message' => 'Please Fill All the Fields']); } } } else { return json_encode(['result' => 2, 'message' => 'Number of questions available is ' . $practiceNQuestions]); } } else { $finalTestDomainId = $this->request->getPost('final_domain_id'); $finalTestSubDomainId = $this->request->getPost('final_sub_domain_id'); $finalTestPassingCriteria = $this->request->getPost('final_test_passing_criteria'); $finalTestAddTime = $this->request->getPost('final_test_add_time'); $finalTestNumberOfQuestions = $this->request->getPost('final_test_number_of_questions'); $finalTestQuestOrder = $this->request->getPost('final_test_question_order'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $table = 'faculty_mocktest_setting'; $tableQuestion = 'questions'; $where = [ 'sub_domain_id' => $finalTestSubDomainId, 'status' => 'ACTIVE', 'faculty_id' => $loginId, ]; $finalNQuestions = $faculty_model->getWhereResultNew($tableQuestion, $where); if ($finalTestNumberOfQuestions <= $finalNQuestions) { $table = 'faculty_mocktest_setting'; $whereFinals = [ 'test_type' => 'Final Test', 'domain_id' => $finalTestDomainId, 'delete_status' => 'ACTIVE', 'sub_domain_id' => $finalTestSubDomainId, 'created_by' => $loginId, ]; $detailsFinals = $faculty_model->getWhereRow($table, $whereFinals); if (!empty($detailsFinals)) { return json_encode(['result' => 0, 'message' => 'Details Already Added']); } else { $data = [ 'test_type' => 'Final Test', 'domain_id' => $finalTestDomainId, 'sub_domain_id' => $finalTestSubDomainId, 'chapter' => '0', 'passing_criteria' => $finalTestPassingCriteria, 'total_time' => $finalTestAddTime, 'number_of_questions' => $finalTestNumberOfQuestions, 'question_order' => $finalTestQuestOrder, 'selected_type' => 'Subject', 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $createdAt, ]; $result = $faculty_model->insertData($table, $data); if ($result) { return json_encode(['result' => 1, 'message' => 'Added successfully']); } else { return json_encode(['result' => 0, 'message' => 'Please Fill All the Fields']); } } } else { return json_encode(['result' => 2, 'message' => 'Number of questions available is ' . $finalNQuestions]); } } } public function get_faculty_batch_list() { $batch_model = new Batch_Model(); $loginId = session()->get('faculty_login_id'); if ($loginId) { $result = $batch_model->facultyBatchList($loginId); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } else { return redirect()->to('/'); } } public function get_domains() { $session = session(); $login_id = $session->get('institution_login_id'); $faculty_model = new Faculty_Model(); if ($login_id) { $id = $this->request->getPost('course_id'); $course_table = 'courses'; $where_course = ['course_id' => $id, 'delete_status' => 'ACTIVE', 'created_by' => $login_id]; $order_by = 'course_title'; $get_details = $faculty_model->getWhereRow1($course_table, $where_course); $domain_id = $get_details->domain_id; $domain_table = 'domains'; $where_domain = ['domain_id' => $domain_id, 'delete_status' => 'ACTIVE', 'created_by' => $login_id]; $order_by = 'domain_name'; $result = $faculty_model->get_where_result1($domain_table, $where_domain); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } else { return redirect()->to('/'); } } public function edit_faculty_batch() { $batch_model = new Batch_Model(); $loginId = session()->get('faculty_login_id'); if ($loginId) { $id = $this->request->uri->getSegment(2); $batchTable = 'batches'; $where = ['batch_id' => $id]; $getDet = $batch_model->getWhereRow($batchTable, $where); $batchDomainId = $getDet->domain_id; $batchSubDomainId = $getDet->sub_domain_id; $batchFacId = $getDet->faculty_id; $domainTable = 'domains'; $whereDomain = ['delete_status' => 'ACTIVE']; $orderByDomain = 'domain_name'; $data['domain'] = $batch_model->getDomains($loginId); $subDomainTable = 'sub_domains'; $whereSubDomain = ['domain_id' => $batchDomainId, 'delete_status' => 'ACTIVE']; $orderBySubDomain = 'domain_id'; $data['sub_domain'] = $batch_model->getWhereResultOrderByAsc($subDomainTable, $whereSubDomain, $orderBySubDomain); $data['faculty'] = $batch_model->getWhereFacultyList($batchDomainId, $batchSubDomainId); $table = 'faculty_available_timings'; $whereFacTimings = [ 'faculty_id' => $batchFacId, 'approval_status' => 'APPROVED', 'domain_id' => $batchDomainId, 'subject_id' => $batchSubDomainId, 'delete_status' => 'ACTIVE' ]; $data['fac_timings'] = $batch_model->getNotEnrolledFacTimings($batchFacId, $batchSubDomainId, $batchDomainId); $table = 'faculty_available_timings'; $whereFac = ['faculty_id' => $batchFacId, 'delete_status' => 'ACTIVE']; $result = $batch_model->get_where_result($table, $whereFac); $batchTable = 'batches'; $whereBatch = ['batch_id' => $id, 'delete_status' => 'ACTIVE']; $orderByBatch = 'batch_name'; $data['batch'] = $batch_model->getWhereResultOrderByAsc($batchTable, $whereBatch, $orderByBatch); $data['login_id'] = $loginId; $data['batch_id'] = $id; return view('faculty/edit_faculty_batch', $data); } else { return redirect()->to('/'); } } // public function get_not_enrolled_fac_timings() // { // $facId = $this->request->getPost('id'); // $subDomainId = $this->request->getPost('sub_domain_id'); // $domainId = $this->request->getPost('domain_id'); // $faculty_model = new Faculty_Model(); // $result = $faculty_model->getNotEnrolledFacTimings($facId, $subDomainId, $domainId); // if ($result) { // return $this->response->setJSON(['result' => 1, 'message' => $result]); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Timings Not Available For This Faculty!']); // } // } public function get_not_enrolled_fac_timings() { $batch_model = new Batch_Model(); $facId = $this->request->getPost('id'); $subDomainId = $this->request->getPost('sub_domain_id'); $domainId = $this->request->getPost('domain_id'); $result = $batch_model->getNotEnrolledFacTimings($facId, $subDomainId, $domainId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Timings Not Available For This Faculty!']); } } public function delete_batch() { $table = 'batches'; $batchId = $this->request->getPost('batch_id'); $faculty_model = new Faculty_Model(); $batchTable = 'user_course_mapping'; $whereBatchIds = [ 'enroll_status' => 'ENROLLED', 'payment_status' => 'PAID', 'delete_status' => 'ACTIVE' ]; $batchResult = $this->db->table('user_course_mapping') ->like('batch_ids', $batchId) ->where($whereBatchIds) ->get() ->getResult(); if ($batchResult) { return $this->response->setJSON(['result' => 2]); } else { $where = ['batch_id' => $batchId]; $data = ['delete_status' => 'INACTIVE']; $result = $faculty_model->UpdateData($table, $data, $where); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0]); } } } public function single_batch_details() { $table = 'batches'; $faculty_model = new Faculty_Model(); $batchId = $this->request->getPost('batch_id'); $result = $faculty_model->getWhereBatches($table, $batchId); if ($result) { return $this->response->setJSON(['batch_details' => $result, 'result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } // public function get_training_plan_duration() // { // $facultyId = $this->request->getPost('faculty_id'); // $subDomainId = $this->request->getPost('sub_domain_id'); // $domainId = $this->request->getPost('domain_id'); // $faculty_model = new Faculty_Model(); // $result = $faculty_model->getTrainingPlanDuration($facultyId, $subDomainId, $domainId); // if ($result) { // return $this->response->setJSON(['result' => 1, 'message' => $result]); // } else { // return $this->response->setJSON(['result' => 0]); // } // } public function get_training_plan_duration() { $batch_model = new Batch_Model(); $facultyId = $this->request->getPost('faculty_id'); $subDomainId = $this->request->getPost('sub_domain_id'); $domainId = $this->request->getPost('domain_id'); $result = $batch_model->getTrainingPlanDuration($facultyId, $subDomainId, $domainId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } // public function get_enrolled_students() // { // $loginId = session()->get('faculty_login_id'); // $faculty_model = new Faculty_Model(); // if ($loginId) { // $result = $faculty_model->get_enrolled_students($loginId); // if ($result) { // return $this->response->setJSON($result); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); // } // } else { // return redirect()->to('/faculty'); // } // } public function get_enrolled_students() { $faculty_model = new Faculty_Model(); $loginId = session()->get('faculty_login_id'); if ($loginId) { $result = $faculty_model->get_enrolled_students($loginId); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } else { return redirect()->to('/faculty'); } } public function get_faculty_feebbacks() { $loginId = session()->get('faculty_login_id'); $faculty_model = new Faculty_Model(); if ($loginId) { $table = 'feedback'; $result = $faculty_model->getFacultyFeedbackList($loginId); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } else { return redirect()->to('/'); } } public function view_faculty_feedback() { $loginId = session()->get('faculty_login_id'); $faculty_model = new Faculty_Model(); if ($loginId) { $feedbackId = $this->request->uri->getSegment(2); $data['feedback'] = $faculty_model->getWhereFeedback($feedbackId); $courseType = $faculty_model->checkFeedbackCourseType($feedbackId); if ($courseType && property_exists($courseType, 'session_type')) { $sessionType = json_decode($courseType->session_type); if (in_array('Live', $sessionType)) { $data['session_type'] = 'Live'; } else { $data['session_type'] = 'Recorded'; } } else { $data['session_type'] = 'Unknown'; } return view('faculty/faculty_feedback_details', $data); } else { return redirect()->to('/faculty'); } } public function get_sub_domain_registered_courses() { $faculty_model = new Faculty_Model(); $id = $this->request->getPost('domain_id'); $loginId = $this->request->getPost('login_id'); $facultyTable = 'faculty_subject_mapping'; $whereDomain = ['login_id' => $loginId, 'approval_status' => 'APPROVED', 'delete_status' => 'ACTIVE']; $getRes = $faculty_model->get_where_result($facultyTable, $whereDomain); $subdomainTable = 'sub_domains'; $domainArray = []; if ($getRes) { foreach ($getRes as $value) { $subDomainIds = json_decode($value->sub_domain_id); foreach ($subDomainIds as $ids) { array_push($domainArray, $ids); } } } $whereSubdomain = ['domain_id' => $id, 'delete_status' => 'ACTIVE']; $orderBy = 'sub_domain'; $result = $faculty_model->getWhereResultOrderByAsc($subdomainTable, $whereSubdomain, $orderBy); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result, 'sub_domains' => $domainArray]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data..']); } } public function get_requested_courses() { $faculty_model = new Faculty_Model(); $userTypeId = session()->get('faculty_user_type_id'); $loginId = session()->get('faculty_login_id'); $result = $faculty_model->getRequestFacultyList($userTypeId, $loginId); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 1, 'message' => 'No Data Found']); } } public function add_material() { $login_id = session()->get('faculty_login_id'); $faculty = session()->get('faculty_username'); $topic_id = $this->request->getPost('topic_id'); $chapter_id = $this->request->getPost('chapter'); $sub_domain_id = $this->request->getPost('sub_domain_id'); // echo "$chapter_id";die(); $table = 'subject_materials'; $where = ['delete_status' => 'ACTIVE']; $amcadModel = new Amcad_Home(); $all_materials = $amcadModel->getWhereResult1($table, $where); if ($all_materials) { $order_by = 'material_id'; $single_id = $amcadModel->getWhereOrderByRow($table, $where, $order_by); $array = []; foreach ($all_materials as $val) { array_push($array, preg_replace('/\D/', '', $val->material_count)); } $material_count = max($array); $material_count = $material_count + 1; $material_count = 'material_' . $material_count; } else { $material_count = 'material_1'; } $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); // print_r($sub_domain_id);die(); $domain_table = 'sub_domains'; $where_domain = ['sub_domain_id' => $sub_domain_id]; $subdomain = $amcadModel->getWhereRow15($domain_table, $where_domain); $login_table = 'login'; $where_id = ['login_id' => $login_id]; $faculty_res = $amcadModel->getWhereRow16($login_table, $where_id); helper('form', 'url'); $validation = \Config\Services::validation(); $vid_target = ""; $video_url = []; $img_target = ''; $img_url = []; $pdf_target = ''; $pdf_url = []; // if (!empty($_FILES['upvideo']['size'][0])) { // for ($i = 0; $i < count($_FILES['upvideo']['name']); $i++) { // $target1 = 'public/subject_videos/'; // $stamp = getdate(); // $target1 .= $stamp[0] . basename($_FILES['upvideo']['name'][$i]); // $target2 = $stamp[0] . basename($_FILES['upvideo']['name'][$i]); // $video_url[] = $target2; // move_uploaded_file($_FILES['upvideo']['tmp_name'][$i], $target1); // } // $vid_target = json_encode($video_url); // } if (!empty($_FILES['upvideo']['size'][0])) { for ($i = 0; $i < count($_FILES['upvideo']['name']); $i++) { $target1 = 'public/subject_videos/'; $stamp = time(); // Use timestamp $filename = $stamp . '_' . basename($_FILES['upvideo']['name'][$i]); $target1 .= $filename; $target2 = $filename; if (move_uploaded_file($_FILES['upvideo']['tmp_name'][$i], $target1)) { $video_url[] = $target2; } else { echo "Error uploading: " . $_FILES['upvideo']['name'][$i]; print_r($_FILES['upvideo']['error'][$i]); // Show upload error die(); } } $vid_target = json_encode($video_url); } if (!empty($_FILES['upimg']['size'][0])) { for ($i = 0; $i < count($_FILES['upimg']['name']); $i++) { $target1 = 'public/subject_images/'; $stamp = getdate(); $target1 .= $stamp[0] . basename($_FILES['upimg']['name'][$i]); $target2 = $stamp[0] . basename($_FILES['upimg']['name'][$i]); $img_url[] = $target2; move_uploaded_file($_FILES['upimg']['tmp_name'][$i], $target1); } $img_target = json_encode($img_url); } if (!empty($_FILES['uppdf']['size'][0])) { for ($i = 0; $i < count($_FILES['uppdf']['name']); $i++) { $target1 = 'public/subject_pdf/'; $stamp = getdate(); $target1 .= $stamp[0] . basename($_FILES['uppdf']['name'][$i]); $target2 = $stamp[0] . basename($_FILES['uppdf']['name'][$i]); $pdf_url[] = $target2; move_uploaded_file($_FILES['uppdf']['tmp_name'][$i], $target1); } $pdf_target = json_encode($pdf_url); } $data = [ 'material_count' => $material_count, 'chapter_id' => $this->request->getPost('chapter'), 'topic_id' => $this->request->getPost('topic_id'), 'sub_domain_id' => $this->request->getPost('sub_domain_id'), 'domain_id' => $this->request->getPost('domain_id'), 'video' => $vid_target, 'image' => $img_target, 'pdf' => $pdf_target, 'approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED', 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'created_at' => $created_at, ]; $result = $amcadModel->insert_data22($table, $data); // print_r($result);die(); if ($result) { // $where_material = ['chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE']; // $data = ['approval_status' => 'NOT_APROVED']; // $amcadModel->UpdateData20($where_material, $table, $data); $emailService = \Config\Services::email(); $href = base_url(''); $content = ''; $content .= '<body style="background:#f3f3f3;">'; $content .= '<div style="width:100%;">'; $content .= '<div style="text-align: center;">'; $content .= '<div>'; $content .= '<img src="' . $href . 'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $content .= '</div>'; $content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $content .= '</div>'; $content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $content .= '<h3 style="margin-top:10px;">Material Updates</h3>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello admin,</p>'; // $content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . $faculty_res->username . ' have added new material to ' . $subdomain->sub_domain . '</p>'; $content .= '</div>'; $content .= '</div>'; $content .= '</div>'; $content .= '</body>'; $emailService->setFrom($faculty_res->email, $faculty_res->username); $emailService->setTo('johncameron6677@gmail.com'); $emailService->setSubject('Material Updates'); $emailService->setMessage($content); if ($emailService->send()) { $notification = $faculty_res->username . ', has added new material to ' . (!empty($subdomain->sub_domain) ? $subdomain->sub_domain : '0'); $notification_data = [ 'login_id' => $login_id, 'username' => $faculty_res->username, 'notification' => $notification, 'view_status' => 'NOT_VIEWED', 'delete_status' => 'ACTIVE', 'category_type' => 'New Material', 'created_by' => $login_id, 'created_at' => $created_at, ]; if ($this->request->getPost('faculty_institution_id') == 0) { $notification_table = 'notification'; $institution_id = 0; } else { $notification_table = 'admin_notifications'; $institution_id = $this->request->getPost('faculty_institution_id'); $notification_data['institution_id'] = $institution_id; } $notification_result = $amcadModel->insert8($notification_table, $notification_data); return json_encode(['result' => 1, 'message' => 'Material added successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something Went Wrong..']); } } } public function get_material_details() { $subject_model = new Subject_Model(); $login_id = session()->get('faculty_login_id'); $result = $subject_model->get_material_details($login_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 1, 'message' => 'No Data Found']); } } public function get_topic_wise_materials($login_id, $sub_domain_id, $chapter_id) { $subject_model = new Subject_Model(); $result = $subject_model->get_topic_wise_materials($login_id, $sub_domain_id, $chapter_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } public function delete_subject_material() { $faculty_model = new Faculty_Model(); $login_id = session()->get('faculty_login_id'); $material_id = $this->request->getPost('material_id'); $created_by = $this->request->getPost('faculty_id'); $where = ['material_id' => $material_id, 'created_by' => $login_id]; $where_q = ['material_id' => $material_id]; $table = 'subject_materials'; $data = ['delete_status' => 'INACTIVE']; $table1 = 'questions'; $data1 = ['status' => 'INACTIVE']; $result = $faculty_model->UpdateData($table, $data, $where); if ($this->db->affectedRows() > 0) { $result1 = $faculty_model->UpdateData($table1, $data1, $where_q); return $this->response->setJSON(['result' => 1, 'message' => 'Deleted Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function single_material_details() { $faculty_model = new Faculty_Model(); $material_id = $this->request->getPost('material_id'); $where = ['material_id' => $material_id, 'delete_status' => 'ACTIVE']; $table = 'subject_materials'; $result = $faculty_model->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_faculty_domains() { $faculty_model = new Faculty_Model(); $login_id = session()->get('faculty_login_id'); $result = $faculty_model->getDomains($login_id); if ($result) { return $this->response->setJSON(['categories_list' => $result, 'result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } // public function update_material() // { // $faculty_model = new Faculty_Model(); // $this->load->library('image_lib'); // $chapter_id = $this->request->getPost('chapter_id'); // $login_id = $this->request->getPost('login_id'); // $material_id = $this->request->getPost('material_id'); // $domain_id = $this->request->getPost('domain_id'); // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $chapter_id = $this->request->getPost('chapter'); // $topic_id = $this->request->getPost('topic_id'); // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $table = 'subject_materials'; // $where = ['material_id' => $material_id, 'delete_status' => 'ACTIVE']; // $single_material = $faculty_model->getWhereRow($table, $where); // if ($_FILES['upvideo']['size'][0] == 0) { // $vid_target = $single_material->video; // } else { // $vid_target = ''; // $video_url = []; // if ($_FILES['upvideo']['size'][0] != 0) { // for ($i = 0; $i < count($_FILES['upvideo']['name']); $i++) { // $target1 = 'subject_videos/'; // $stamp = getdate(); // $target1 .= $stamp[0] . basename($_FILES['upvideo']['name'][$i]); // $target2 = $stamp[0] . basename($_FILES['upvideo']['name'][$i]); // $video_url[] = $target2; // move_uploaded_file($_FILES['upvideo']['tmp_name'][$i], $target1); // $config1['source_image'] = $target1; // $config1['maintain_ratio'] = TRUE; // $this->image_lib->initialize($config1); // $this->image_lib->resize(); // $this->image_lib->clear(); // } // $vid_target = json_encode($video_url); // } // } // $data = [ // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'chapter_id' => $chapter_id, // 'topic_id' => $topic_id, // 'video' => $vid_target, // // 'image' => $img_target, // // 'pdf' => $pdf_target, // 'updated_at' => $created_at, // 'updated_by' => $login_id // ]; // $update_data = ['approval_status' => 'NOT_APROVED']; // $where_chapter = ['chapter_id' => $chapter_id, 'created_by' => $login_id]; // $updateresult = $faculty_model->UpdateData($table, $update_data, $where_chapter); // $where = ['material_id' => $material_id]; // $result = $faculty_model->UpdateData($table, $data, $where); // if ($this->db->affected_rows() > 0) { // return $this->response->setJSON(['result' => 1, 'message' => 'Updated Successfully']); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); // } // } public function update_material() { $faculty_model = new Faculty_Model(); $chapter_id = $this->request->getPost('chapter_id'); $login_id = $this->request->getPost('login_id'); $material_id = $this->request->getPost('material_id'); $domain_id = $this->request->getPost('domain_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $chapter_id = $this->request->getPost('chapter'); $topic_id = $this->request->getPost('topic_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $table = 'subject_materials'; $where = ['material_id' => $material_id, 'delete_status' => 'ACTIVE']; $single_material = $faculty_model->getWhereRow($table, $where); if (!empty($_FILES['upvideo']) && $_FILES['upvideo']['size'][0] != 0) { $vid_target = ''; $video_url = []; for ($i = 0; $i < count($_FILES['upvideo']['name']); $i++) { $target1 = 'subject_videos/'; $stamp = getdate(); $target1 .= $stamp[0] . basename($_FILES['upvideo']['name'][$i]); $target2 = $stamp[0] . basename($_FILES['upvideo']['name'][$i]); $video_url[] = $target2; $file = $this->request->getFile('upvideo'); $file->move(ROOTPATH . 'public/' . $target1, true); $config1 = [ 'image' => ROOTPATH . 'public/' . $target1, 'maintainRatio' => true, 'width' => 100, // Set your desired width 'height' => 100, // Set your desired height ]; \Config\Services::image() ->withFile($config1['image']) ->fit($config1['width'], $config1['height'], 'center') ->save($config1['image']); } $vid_target = json_encode($video_url); } else { if (!empty($single_material) && is_object($single_material)) { $vid_target = $single_material->video; } else { $vid_target = ''; } } $data = [ 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'chapter_id' => $chapter_id, 'topic_id' => $topic_id, 'video' => $vid_target, 'updated_at' => $created_at, 'updated_by' => $login_id, ]; $update_data = ['approval_status' => 'NOT_APPROVED']; $where_chapter = ['chapter_id' => $chapter_id, 'created_by' => $login_id]; $updateresult = $faculty_model->UpdateData($table, $update_data, $where_chapter); $where = ['material_id' => $material_id]; $result = $faculty_model->UpdateData($table, $data, $where); // if ($this->db->affected_rows() > 0) { // return $this->response->setJSON(['result' => 1, 'message' => 'Updated Successfully']); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); // } if ($result) { $affectedRows = $this->db->affectedRows(); if ($affectedRows > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function get_chapter_topics() { $faculty_model = new Faculty_Model(); $login_id = $this->request->getPost('login_id'); $chapter_id = $this->request->getPost('chapter_id'); $table = 'topics'; $where = ['created_by' => $login_id, 'chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE']; $result = $faculty_model->get_chapter_topics($chapter_id, $login_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function add_question_bank() { $login_id = session('faculty_login_id'); $subject_model = new Subject_Model(); if ($login_id) { $data['number_rows'] = $subject_model->number_of_questions(); $material_id = $this->request->uri->getSegment(2); $data['result'] = $subject_model->get_where_domains_materials($material_id); $table = "subject_materials"; $where = ['material_id' => $material_id]; $material_date = $subject_model->getWhereRow($table, $where); $chapter_id = $material_date->chapter_id; $sub_id = $material_date->sub_domain_id; $data['questions'] = $subject_model->list_of_questions($chapter_id, $login_id, $sub_id); return view('faculty/faculty_add_questions', $data); } } public function number_of_questions() { $builder = $this->db->table('questions'); $builder->select('*'); $builder->where('status', 'ACTIVE'); $result = $builder->get(); return $result->getNumRows(); } public function questions_insert() { $faculty_model = new Faculty_Model(); $login_id = session()->get('faculty_login_id'); $material_id = $this->request->getPost('material_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $chapter_id = $this->request->getPost('chapter_id'); $questions = htmlspecialchars($this->request->getPost('questions')); $number_of_options = $this->request->getPost('optradio'); $ans1 = htmlspecialchars($this->request->getPost('ans1')); $ans2 = htmlspecialchars($this->request->getPost('ans2')); $ans3 = htmlspecialchars($this->request->getPost('ans3')); $ans4 = htmlspecialchars($this->request->getPost('ans4')); $ans = $this->request->getPost('ans'); $explanation = $this->request->getPost('explanation'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_on = $date->format('Y-m-d'); if (!empty($questions)) { $table = "questions"; $data = [ 'material_id' => $material_id, 'faculty_id' => $login_id, 'sub_domain_id' => $sub_domain_id, 'chapter_id' => $chapter_id, 'questions' => $questions, 'ans1' => $ans1, 'ans2' => $ans2, 'ans3' => $ans3, 'ans4' => $ans4, 'ans' => $ans, 'created_on' => $created_on, 'explanation' => $explanation, 'no_of_options' => $number_of_options, ]; $result = $faculty_model->insertData($table, $data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Add successfully']); } else { return $this->response->setJSON(['result' => 0]); } } else { return $this->response->setJSON(['result' => 2, 'message' => 'Please Enter Questions']); } } public function edit_faculty_add_questions() { $faculty_model = new Faculty_Model(); $qid = $this->request->getPost('qid'); $where = ['qid' => $qid, 'status' => 'ACTIVE']; $table = 'questions'; $result = $faculty_model->getWhereFacultyAddedQuestions($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function delete_faculty_add_questions() { $faculty_model = new Faculty_Model(); $login_id = session()->get('faculty_login_id'); $qid = $this->request->getPost('qid'); $where = ['qid' => $qid, 'status' => 'ACTIVE']; $table = 'questions'; $data = ['status' => 'INACTIVE']; $result = $faculty_model->UpdateData($table, $data, $where); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function edit_questions_insert() { $faculty_model = new Faculty_Model(); $loginId = session('faculty_login_id'); $qidEdit = $this->request->getPost('qid_edit'); $questionsEdit = htmlspecialchars($this->request->getPost('questions_edit')); $numberOfOptionsEdit = $this->request->getPost('edit_optradio'); $ans1Edit = htmlspecialchars($this->request->getPost('ans1_edit')); $ans2Edit = htmlspecialchars($this->request->getPost('ans2_edit')); $ans3Edit = htmlspecialchars($this->request->getPost('ans3_edit')); $ans4Edit = htmlspecialchars($this->request->getPost('ans4_edit')); $editAns = $this->request->getPost('edit_ans'); $explanationEdit = htmlspecialchars($this->request->getPost('explanation_edit')); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedOn = $date->format('Y-m-d'); if (!empty($questionsEdit)) { $table = "questions"; $data = [ 'questions' => $questionsEdit, 'ans1' => $ans1Edit, 'ans2' => $ans2Edit, 'ans3' => $numberOfOptionsEdit >= 3 ? $ans3Edit : '', 'ans4' => $numberOfOptionsEdit >= 4 ? $ans4Edit : '', 'ans' => $editAns, 'updated_on' => $updatedOn, 'explanation' => $explanationEdit, 'no_of_options' => $numberOfOptionsEdit, ]; $where = ['qid' => $qidEdit]; $result = $faculty_model->UpdateData($table, $data, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Update successfully']); } else { return $this->response->setJSON(['result' => 0]); } } else { return $this->response->setJSON(['result' => 2, 'message' => 'Please Enter Questions']); } } // public function imported() // { // $faculty_model = new Faculty_Model(); // date_default_timezone_set('Asia/Kolkata'); // if ($file = $this->request->getFile('file')) { // $fileName = $file->getName(); // $ext = pathinfo($fileName, PATHINFO_EXTENSION); // if ($ext == "xlsx") { // $loginId = session('faculty_login_id'); // $subDomainId = $this->request->getPost('sub_domain_id'); // $chapterId = $this->request->getPost('chapter_id'); // $materialId = $this->request->getPost('material_id'); // $fileTmpName = $file->getTempName(); // $inputFileName = $fileTmpName; // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $createdOn = $date->format('Y-m-d'); // try { // $spreadsheet = IOFactory::load($inputFileName); // } catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) { // die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); // } // $sheet = $spreadsheet->getActiveSheet(); // $highestRow = $sheet->getHighestRow(); // $highestColumn = $sheet->getHighestColumn(); // $table = "questions"; // $allDataInSheet = $sheet->toArray(null, true, true, true); // $arrayCount = count($allDataInSheet); // if ($arrayCount > 0) { // for ($i = 2; $i <= $arrayCount; $i++) { // $questions = htmlspecialchars(trim($allDataInSheet[$i]["A"])); // $numberOfOptions = trim($allDataInSheet[$i]["B"]); // $option1 = htmlspecialchars(trim($allDataInSheet[$i]["C"])); // $option2 = htmlspecialchars(trim($allDataInSheet[$i]["D"])); // $option3 = htmlspecialchars(trim($allDataInSheet[$i]["E"])); // $option4 = htmlspecialchars(trim($allDataInSheet[$i]["F"])); // $currentAnswer = trim($allDataInSheet[$i]["G"]); // $explanation = trim($allDataInSheet[$i]["H"]); // if ($questions != "") { // $data = [ // 'faculty_id' => $loginId, // 'material_id' => $materialId, // 'chapter_id' => $chapterId, // 'sub_domain_id' => $subDomainId, // 'questions' => $questions, // 'no_of_options' => $numberOfOptions, // 'ans1' => $this->getFormattedValue($option1), // 'ans2' => $this->getFormattedValue($option2), // 'ans3' => $numberOfOptions >= 3 ? $this->getFormattedValue($option3) : '', // 'ans4' => $numberOfOptions >= 4 ? $this->getFormattedValue($option4) : '', // 'ans' => $currentAnswer, // 'explanation' => $explanation, // 'created_on' => $createdOn, // ]; // $faculty_model->insertData($table, $data); // } // } // return json_encode(['result' => 1, 'message' => 'Excel Sheet Update Successfully']); // } // } else { // return json_encode(['result' => 2, 'message' => 'Uploaded file format is wrong']); // } // } // } // private function getFormattedValue($option) // { // switch ($option) { // case "1": // return 'TRUE'; // case "0": // case "": // return 'FALSE'; // case "TRUE": // return 'TRUE'; // case "FALSE": // return 'FALSE'; // default: // return $option; // } // } public function imported() { date_default_timezone_set('Asia/Kolkata'); $faculty_model = new Faculty_Model(); if ($file = $this->request->getFile('file')) { $fileExt = $file->getClientExtension(); if ($fileExt === 'xlsx') { $loginId = session('faculty_login_id'); $subDomainId = $this->request->getPost('sub_domain_id'); $chapterId = $this->request->getPost('chapter_id'); $materialId = $this->request->getPost('material_id'); $fileTempName = $file->getTempName(); $inputFileName = $fileTempName; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdOn = $date->format('Y-m-d'); try { $inputFileType = IOFactory::identify($inputFileName); $objReader = IOFactory::createReader($inputFileType); $spreadsheet = $objReader->load($inputFileName); } catch (\Exception $e) { die('Error loading file "' . $file->getName() . '": ' . $e->getMessage()); } $sheet = $spreadsheet->getActiveSheet(); $highestRow = $sheet->getHighestRow(); $table = "questions"; for ($i = 2; $i <= $highestRow; $i++) { $questions = htmlspecialchars(trim($sheet->getCell('A' . $i)->getValue())); $noOfOptions = trim($sheet->getCell('B' . $i)->getValue()); $option1 = htmlspecialchars(trim($sheet->getCell('C' . $i)->getValue())); $option2 = htmlspecialchars(trim($sheet->getCell('D' . $i)->getValue())); $option3 = htmlspecialchars(trim($sheet->getCell('E' . $i)->getValue())); $option4 = htmlspecialchars(trim($sheet->getCell('F' . $i)->getValue())); $currentAnswer = trim($sheet->getCell('G' . $i)->getValue()); $explanation = trim($sheet->getCell('H' . $i)->getValue()); if ($questions !== "") { // Process the data based on the number of options // (similar to your existing logic) // Example: if ($noOfOptions == "2") { // Process for 2 options // ... } elseif ($noOfOptions == "3") { if ($option1 == "1") { $val = 'TRUE'; } else if ($option1 == "0" || $option1 == "") { $val = 'FALSE'; } else if ($option1 == "TRUE") { $val = 'TRUE'; } else if ($option1 == "FALSE") { $val = 'FALSE'; } else { $val = $option1; } if ($option2 == "1") { $val2 = 'TRUE'; } else if ($option2 == "0" || $option2 == "") { $val2 = 'FALSE'; } else if ($option2 == "TRUE") { $val2 = 'TRUE'; } else if ($option2 == "FALSE") { $val2 = 'FALSE'; } else { $val2 = $option2; } $data = [ 'faculty_id' => $loginId, 'material_id' => $materialId, 'chapter_id' => $chapterId, 'sub_domain_id' => $subDomainId, 'questions' => $questions, 'no_of_options' => $noOfOptions, 'ans1' => $val, 'ans2' => $val2, 'ans3' => '', // Replace with your actual logic for ans3 'ans4' => '', // Replace with your actual logic for ans4 'ans' => $currentAnswer, 'explanation' => $explanation, 'created_on' => $createdOn, ]; $faculty_model->insertData($table, $data); } else if ($noOfOptions == "3") { if ($option1 == "1") { $val = 'TRUE'; } else if ($option1 == "0" || $option1 == "") { $val = 'FALSE'; } else if ($option1 == "TRUE") { $val = 'TRUE'; } else if ($option1 == "FALSE") { $val = 'FALSE'; } else { $val = $option1; } if ($option2 == "1") { $val2 = 'TRUE'; } else if ($option2 == "0" || $option2 == "") { $val2 = 'FALSE'; } else if ($option2 == "TRUE") { $val2 = 'TRUE'; } else if ($option2 == "FALSE") { $val2 = 'FALSE'; } else { $val2 = $option2; } if ($option3 == "1") { $val3 = 'TRUE'; } else if ($option3 == "0" || $option3 == "") { $val3 = 'FALSE'; } else if ($option3 == "TRUE") { $val3 = 'TRUE'; } else if ($option3 == "FALSE") { $val3 = 'FALSE'; } else { $val3 = $option3; } $data = [ 'faculty_id' => $loginId, 'material_id' => $materialId, 'chapter_id' => $chapterId, 'sub_domain_id' => $subDomainId, 'questions' => $questions, 'no_of_options' => $noOfOptions, 'ans1' => $val, 'ans2' => $val2, 'ans3' => $val3, 'ans4' => '', // Replace with your actual logic for ans4 'ans' => $currentAnswer, 'explanation' => $explanation, 'created_on' => $createdOn, ]; $faculty_model->insertData($table, $data); } else { if ($option1 == "1") { $val = 'TRUE'; } else if ($option1 == "0" || $option1 == "") { $val = 'FALSE'; } else if ($option1 == "TRUE") { $val = 'TRUE'; } else if ($option1 == "FALSE") { $val = 'FALSE'; } else { $val = $option1; } if ($option2 == "1") { $val2 = 'TRUE'; } else if ($option2 == "0" || $option2 == "") { $val2 = 'FALSE'; } else if ($option2 == "TRUE") { $val2 = 'TRUE'; } else if ($option2 == "FALSE") { $val2 = 'FALSE'; } else { $val2 = $option2; } if ($option3 == "1") { $val3 = 'TRUE'; } else if ($option3 == "0" || $option3 == "") { $val3 = 'FALSE'; } else if ($option3 == "TRUE") { $val3 = 'TRUE'; } else if ($option3 == "FALSE") { $val3 = 'FALSE'; } else { $val3 = $option3; } if ($option4 == "1") { $val4 = 'TRUE'; } else if ($option4 == "0" || $option4 == "") { $val4 = 'FALSE'; } else if ($option4 == "TRUE") { $val4 = 'TRUE'; } else if ($option4 == "FALSE") { $val4 = 'FALSE'; } else { $val4 = $option4; } // Insert data into the database $data = [ 'faculty_id' => $loginId, 'material_id' => $materialId, 'chapter_id' => $chapterId, 'sub_domain_id' => $subDomainId, 'questions' => $questions, 'no_of_options' => $noOfOptions, 'ans1' => $val, 'ans2' => $val2, 'ans3' => $val3, 'ans4' => $val4, 'ans' => $currentAnswer, 'explanation' => $explanation, 'created_on' => $createdOn, ]; $faculty_model->insertData($table, $data); } } } return json_encode(['result' => 1, 'message' => 'Excel Sheet Update Successfully']); } else { return json_encode(['result' => 2, 'message' => 'Uploaded file format is wrong']); } } } public function faculty_update_batch() { $loginId = session()->get('faculty_login_id'); $faculty_model = new Faculty_Model(); if ($loginId) { $batchId = $this->request->getPost('batch_id'); $date = Time::now('Asia/Kolkata'); $created_at = $date->toDateTimeString(); $domainId = $this->request->getPost('domain_id'); $subDomainId = $this->request->getPost('sub_domain_ids') !== "" ? $this->request->getPost('sub_domain_ids') : $this->request->getPost('sub_domain_id'); $availableTimings = $this->request->getPost('available_timings') !== "" ? $this->request->getPost('available_timings') : $this->request->getPost('available_timings'); $batchName = $this->request->getPost('batch_name'); $batchType = $this->request->getPost('batch_type'); $batchRangeSize = $this->request->getPost('batch_range_size'); if ($batchType == 'Fixed') { $batchSize = $this->request->getPost('batch_fixed_size'); } elseif ($batchType == 'Range') { $batchSize = $this->request->getPost('batch_range_size'); } $courseType = $this->request->getPost('course_type'); $batchFromDate = $this->request->getPost('batch_from_date'); $batchToDate = $this->request->getPost('batch_to_date'); $batchDuration = $this->request->getPost('batch_duration'); $batchTable = 'batches'; $userEnrolledTable = 'user_course_mapping'; $batchIds = json_encode($this->request->getPost('batch_id')); $where = ['batch_ids' => $batchIds, 'delete_status' => 'ACTIVE', 'enroll_status' => 'ENROLLED', 'payment_status' => 'PAID']; $checkEnrolled = $faculty_model->getWhereLike($userEnrolledTable, $where); if ($courseType == "Recorded") { $batchData = [ 'domain_id' => $domainId, 'sub_domain_id' => $subDomainId, 'faculty_id' => $loginId, 'from_time' => '', 'batch_name' => $batchName, 'batch_type' => $batchType, 'batch_size' => $batchSize, 'batch_from_date' => $batchFromDate, 'batch_to_date' => $batchToDate, 'batch_duration' => $batchDuration, 'course_type' => $courseType, 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $created_at ]; $whereId = ['batch_id' => $batchId, 'delete_status' => 'ACTIVE']; $result = $faculty_model->UpdateData($whereId, $batchTable, $batchData); if ($this->db->affectedRows() > 0) { $facultyRes = $faculty_model->getWhereRow('login', ['login_id' => $loginId]); $emailContent = view('emails/faculty_batch_edit', ['facultyRes' => $facultyRes, 'batchName' => $batchName]); $this->sendEmail($emailContent, 'Faculty Batch Edit Updates', ['sowmyayp@gmail.com']); return json_encode(['result' => 1, 'message' => 'Batch updated successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong. Try again']); } } elseif ($availableTimings == "" || $availableTimings == "0") { return json_encode(['result' => 0, 'message' => 'Details cannot be empty! Please fill all the details']); } else { $batchData = [ 'domain_id' => $domainId, 'sub_domain_id' => $subDomainId, 'faculty_id' => $loginId, 'from_time' => $availableTimings, 'batch_name' => $batchName, 'batch_type' => $batchType, 'batch_size' => $batchSize, 'batch_from_date' => $batchFromDate, 'batch_to_date' => $batchToDate, 'batch_duration' => $batchDuration, 'course_type' => $courseType, 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'created_at' => $created_at ]; $whereId = ['batch_id' => $batchId, 'delete_status' => 'ACTIVE']; $result = $faculty_model->UpdateData($whereId, $batchTable, $batchData); if ($this->db->affectedRows() > 0) { $facultyRes = $faculty_model->getWhereRow('login', ['login_id' => $loginId]); $emailContent = view('emails/faculty_batch_edit', ['facultyRes' => $facultyRes, 'batchName' => $batchName]); $this->sendEmail($emailContent, 'Faculty Batch Edit Updates', ['sowmyayp@gmail.com']); return json_encode(['result' => 1, 'message' => 'Batch updated successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong. Try again']); } } } else { return redirect()->to('/'); } } protected function sendEmail($content, $subject, $recipients) { $email = \Config\Services::email(); $email->initialize([ 'protocol' => 'smtp', 'SMTPHost' => 'smtp-relay.gmail.com', 'SMTPPort' => 587, 'SMTPUser' => 'healthcare@medusyspty.com', 'SMTPPass' => 'Password@1236', 'SMTPCrypto' => 'tls', 'mailType' => 'html', 'charset' => 'UTF-8', 'SMTPDebug' => 2, 'debugOutput' => 'html', ]); $email->setTo($recipients); $email->setSubject($subject); $email->setMessage($content); if (!$email->send()) { log_message('error', 'Email sending failed: ' . $email->printDebugger(['headers'])); return false; } return true; } public function faculty_material_details() { // $session = session(); // Access the session service // $loginId = $session->get('faculty_login_id'); // if ($loginId) { // $material_id = $this->request->uri->getSegment(2); // $subject_model = new Subject_Model(); // $data['result'] = $subject_model->getWhereMaterialDetails($material_id); // $data['chapter_result'] = $subject_model->getTopicName($data['result']['topic_id']); // return view('faculty/faculty_material_details', $data); // } else { // return redirect()->to('admin'); // } $session = session(); // Access the session service $loginId = $session->get('faculty_login_id'); if ($loginId) { $material_id = $this->request->uri->getSegment(2); $subject_model = new Subject_Model(); $data['result'] = $subject_model->getWhereMaterialDetails($material_id); // Check if $data['result'] is not null before accessing its properties if ($data['result']) { $data['chapter_result'] = $subject_model->getTopicName($data['result']->topic_id); } else { // Handle the case where $data['result'] is null or doesn't have the expected structure $data['chapter_result'] = null; } return view('faculty/faculty_material_details', $data); } else { return redirect()->to('admin'); } } public function download2() { $path = './app/sample_excel/questions.xlsx'; // Check if the file exists if (file_exists($path)) { $response = $this->response ->download($path, null, true) ->setFileName('questions.xlsx') ->setHeader('Cache-Control', 'public, max-age=0') ->setHeader('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT') ->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT') ->setHeader('Pragma', 'public'); return $response; } else { // Handle the case when the file doesn't exist return redirect()->to('add_question_bank'); } } // public function update_faculty_profile() // { // $faculty_model = new Faculty_Model(); // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $createdAt = $date->format('Y-m-d H:i:s'); // $facultyId = session()->get('faculty_login_id'); // $userName = $this->request->getPost('name'); // $email = $this->request->getPost('email'); // $phoneNumber = $this->request->getPost('phone_number'); // $qualification = $this->request->getPost('qualification'); // $experience = $this->request->getPost('experience'); // $current_work = $this->request->getPost('current_work'); // $teach_experience = $this->request->getPost('teach_experience'); // $location = $this->request->getPost('location'); // $where = ['login_id' => $facultyId, 'delete_status' => 'ACTIVE']; // $table = 'login'; // $loginResult = $faculty_model->get_where_row($table, $where); // if ($loginResult && is_object($loginResult)) { // $registeredEmail = $loginResult->email; // $imageFiles = ""; // $profilePic = $this->request->getFile('profile_pic'); // // Check if the file is present and is valid // if ($profilePic && $profilePic->isValid()) { // $target = 'writable/course_images/' . time() . $profilePic->getName(); // $profilePic->move($target); // $imageFiles = time() . $profilePic->getName(); // } // if ($registeredEmail == $email) { // if ($imageFiles !== '') { // $data = ['username' => $userName, 'updated_at' => $createdAt, 'email' => $email, 'image' => $imageFiles]; // } else { // $data = ['username' => $userName, 'updated_at' => $createdAt, 'email' => $email]; // } // $result = $faculty_model->update_data($where, $table, $data); // if ($faculty_model->affectedRows() > 0) { // $resumeFile = $this->request->getFile('resume'); // // Check if 'resume' file is valid before attempting to move it // if ($resumeFile && $resumeFile->isValid()) { // $resumeSize = $resumeFile->getSize(); // if ($resumeSize <= 2000000) { // $resumePath = './public/faculty_resumes/' . time() . $resumeFile->getName(); // $resumeFile->move(ROOTPATH . $resumePath); // $resumePath = json_encode($resumePath); // $registrationData = [ // 'resume' => $resumePath, // 'fullname' => $userName, // 'phone' => $phoneNumber, // 'qualification' => $qualification, // 'email' => $email, // 'location' => $location, // 'teaching_experience' => $experience, // 'current_working' => $current_work, // 'online_teaching_experience' => $teach_experience, // 'updated_at' => $createdAt // ]; // $registrationTable = 'faculty_registration'; // $faculty_model->UpdateData1($where, $registrationTable, $registrationData); // if ($faculty_model->affectedRows() > 0) { // $loginTable = 'login'; // $loginData = ['username' => $userName, 'email' => $email, 'updated_at' => $createdAt]; // $faculty_model->UpdateData2($where, $loginTable, $loginData); // return json_encode(['result' => 1, 'message' => 'Updated Successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Resume size exceeds limit']); // } // } else { // return json_encode(['result' => 0, 'message' => 'No valid file uploaded for resume']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong']); // } // } else { // // Rest of your code... // $whereLogin = ['delete_status' => 'ACTIVE', 'email' => $email, 'user_type_id' => 2, 'verified_status' => 'VERIFIED']; // $loginTable = 'login'; // $emailResult = $faculty_model->get_where_row1($loginTable, $whereLogin); // if ($emailResult && is_object($emailResult)) { // return json_encode(['result' => 0, 'message' => 'Email already exists']); // } else { // $currentTime = time(); // $time1 = md5($currentTime); // $string = substr($time1, 0, 6); // $otp = strtoupper($string); // if ($imageFiles !== '') { // $data = [ // 'new_email_status' => 'NOT_VERIFIED', // 'new_email' => $email, // 'updated_at' => $createdAt, // 'otp_code' => $otp, // 'image' => $imageFiles // ]; // } else { // $data = [ // 'new_email_status' => 'NOT_VERIFIED', // 'new_email' => $email, // 'updated_at' => $createdAt, // 'otp_code' => $otp // ]; // } // $result = $faculty_model->UpdateData3($where, $table, $data); // // $href = base_url(); // // $email_content = ''; // // $email_content .= '<body style="background:#f3f3f3;">'; // // $email_content .= '<div style="width:100%;">'; // // $email_content .= '<div style="text-align: center;">'; // // $email_content .= '<div>'; // // $email_content .= '<img src="'.$href.'assets/website_assets/icons/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; // // $email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; // // $email_content .= '</div>'; // // $email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; // // $email_content .= '<img src="'.$href.'assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; // // $email_content .= '</div>'; // // $email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; // // $email_content .= '<h3 style="margin-top:10px;">Email Confirmation</h3>'; // // $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$userName.',Please click on the below link for email verification and enter OTP to complete verification.</p>'; // // $email_content .= '<p style="font-size:16px;padding-bottom:10px;">OTP : '.$otp.'</p>'; // // $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="'.$href.'faculty-verification/'.md5($loginResult->login_id).'" style="color:#fff;padding:10px 30px;background:#a6d039;" style="color:#fff;padding:10px 30px;background:#a6d039;">Verify Your OTP</a></p>'; // // $email_content .= '</div>'; // // $email_content .= '</div>'; // // $email_content .= '</div>'; // // $email_content .= '</body>'; // // // $emailService = ... // Initialize your email service here // // $emailService = \Config\Services::email(); // // $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); // // $emailService->setTo($email); // // $emailService->setSubject('faculty Authentication'); // // $emailService->setMessage($email_content); // // if ($emailService->send()) { // $res_file = $this->request->getFile('resume'); // if ($res_file) { // $resume_size = $this->request->getFile('resume')->getSize(); // } else { // $resume_size = 0; // } // if ($resume_size <= 2000000) { // if ($this->request->getFile('resume')->getName() != '') { // $resume = ""; // if ($this->request->getFile('resume')->getName()) { // $path = $this->request->getFile('resume')->getName(); // $target = 'public/faculty_resumes/' . time() . $this->request->getFile('resume')->getName(); // $resume_document = time() . $this->request->getFile('resume')->getName(); // $this->request->getFile('resume')->move($target); // $resume = json_encode($resume_document); // } else { // $resume = ""; // } // $registration_data['resume'] = $resume; // } // $registration_table = 'faculty_registration'; // $registration_data['fullname'] = $userName; // $registration_data['phone'] = $phoneNumber; // $registration_data['qualification'] = $qualification; // $registration_data['location'] = $location; // $registration_data['teaching_experience'] = $experience; // $registration_data['current_working'] = $current_work; // $registration_data['online_teaching_experience'] = $teach_experience; // $registration_data['updated_at'] = $createdAt; // $faculty_model->UpdateData4($where, $registration_table, $registration_data); // $affectedRows = $faculty_model->affectedRows(); // if ($affectedRows > 0) { // $login_table = 'login'; // $login_data = ['username' => $userName, 'updated_at' => $createdAt]; // $faculty_model->UpdateData5($where, $login_table, $login_data); // } // } // } // if ($result) { // return json_encode(['result' => 1, 'message' => 'Email verification sent successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong']); // } // } // } // } //protected $helpers = ['form', 'url']; public function update_faculty_profile() { $faculty_model = new Faculty_Model(); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $facultyId = session()->get('faculty_login_id'); $userName = $this->request->getPost('name'); $email = $this->request->getPost('email'); $phoneNumber = $this->request->getPost('phone_number'); $qualification = $this->request->getPost('qualification'); $experience = $this->request->getPost('experience'); $currentWork = $this->request->getPost('current_work'); $teachExperience = $this->request->getPost('teach_experience'); $location = $this->request->getPost('location'); $where = ['login_id' => $facultyId, 'delete_status' => 'ACTIVE']; $table = 'login'; $loginResult = $faculty_model->getWhereRow($table, $where); $registeredEmail = $loginResult->email; $imageFiles = ""; $profilePic = $this->request->getFile('profile_pic'); if ($profilePic && $profilePic->isValid()) { $imageFiles = time() . $profilePic->getName(); $profilePic->move('public/course_images/', $imageFiles); } if ($registeredEmail == $email) { $data = [ 'username' => $userName, 'updated_at' => $createdAt, 'email' => $email, 'image' => $imageFiles, ]; $result = $faculty_model->update_data($where, $table, $data); if ($faculty_model->affectedRows() > 0) { // Handle video and resume file uploads here // ... if ($faculty_model->affectedRows() > 0) { // Handle video file upload // $videoFile = $this->request->getFile('samplevideo'); // if ($videoFile->isValid()) { // $videoSize = $videoFile->getSize(); // if ($videoSize <= 50000000) { // $videoFileName = time() . $videoFile->getName(); // $videoFile->move('demo_videos/', $videoFileName); // $registrationData['demo'] = json_encode($videoFileName); // } else { // return json_encode(['result' => 0, 'message' => 'Video size must not exceed 50mb']); // } // } // Handle resume file upload $resumeFile = $this->request->getFile('resume'); if ($resumeFile->isValid()) { $resumeSize = $resumeFile->getSize(); if ($resumeSize <= 2000000) { $resumeFileName = time() . $resumeFile->getName(); $resumeFile->move('public/faculty_resumes/', $resumeFileName); $registrationData['resume'] = json_encode($resumeFileName); } else { return json_encode(['result' => 0, 'message' => 'Resume size must not exceed 2mb']); } } // Continue with the registration data update... $registrationTable = 'faculty_registration'; $registrationData['fullname'] = $userName; $registrationData['phone'] = $phoneNumber; $registrationData['qualification'] = $qualification; // ... (other fields) $faculty_model->update_data($where, $registrationTable, $registrationData); if ($faculty_model->affectedRows() > 0) { $loginTable = 'login'; $loginData = ['username' => $userName, 'updated_at' => $createdAt]; $faculty_model->update_data($where, $loginTable, $loginData); return json_encode(['result' => 2, 'message' => 'Data updated successfully. Please verify the link with OTP code sent to your email id to complete Authentication']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong']); } } else { return json_encode(['result' => 0, 'message' => 'Something went wrong']); } } } } public function institute_faculty_verification() { $login_id = session()->get('institution_login_id'); if ($login_id) { return view('institutions/institution_faculty_verification'); } else { return redirect()->to('/'); } } public function faculty_verification() { $data['encrypted_id'] = $this->request->uri->getSegment(3); return view('faculty/faculty_verification',$data); } public function complete_faculty_verification() { $facultyModel = new Faculty_Model(); // Create an instance of your model // Get data from the request $encryptedId = $this->request->getPost('encrypted_id'); $otpCode = $this->request->getPost('otp_code'); // Get the current date and time $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); // Database table names $loginTable = 'login'; $regTable = 'faculty_registration'; // Check OTP $where = ['encrypted_login_id' => $encryptedId, 'otp_code' => $otpCode]; $checkOtp = $facultyModel->getWhereRow1($loginTable, $where); if ($checkOtp) { if (($checkOtp->verified_status == 'VERIFIED') && ($checkOtp->new_email == '')) { echo json_encode(['result' => 3, 'message' => 'OTP already verified']); } elseif ($checkOtp->new_email_status == 'VERIFIED') { echo json_encode(['result' => 3, 'message' => 'OTP already verified']); } elseif (($checkOtp->new_email_status == 'NOT_VERIFIED') && ($checkOtp->verified_status == 'VERIFIED')) { // Update login table $whereId = ['encrypted_login_id' => $encryptedId]; $updateData = [ 'new_email_status' => 'VERIFIED', 'verified_at' => $createdAt, 'email' => $checkOtp->new_email ]; $facultyModel->UpdateData6($whereId, $loginTable, $updateData); if ($facultyModel->affectedRows() > 0) { // Update faculty registration table $whereReg = ['login_id' => $checkOtp->login_id]; $updateData = ['email' => $checkOtp->new_email, 'updated_at' => $createdAt]; $facultyModel->UpdateData7($whereReg, $regTable, $updateData); if ($facultyModel->affectedRows() > 0) { echo json_encode(['result' => 5, 'message' => 'Verified successfully']); } else { echo json_encode(['result' => 2, 'message' => "Something went wrong.. try again"]); } } } else { // Update login table $whereId = ['encrypted_login_id' => $encryptedId]; $updateData = ['verified_status' => 'VERIFIED', 'verified_at' => $createdAt]; $facultyModel->UpdateData6($whereId, $loginTable, $updateData); if ($facultyModel->affectedRows() > 0) { // The rest of your code... $whereReg = ['login_id' => $checkOtp->login_id, 'delete_status' => 'ACTIVE']; $regResult = $facultyModel->getWhereRow2($regTable, $whereReg); $subCategory = json_decode($regResult->sub_domain_id); $subDomainArray = []; $subDomains = $facultyModel->approvedSubjects($subCategory); foreach ($subDomains as $values) { array_push($subDomainArray, $values->sub_domain); } $subDomains = implode(', ', $subDomainArray); // (Email sending and response) $href = base_url(''); $admin_email_content = ''; $admin_email_content .= '<body style="background:#f3f3f3;">'; $admin_email_content .= '<div style="width:100%;">'; $admin_email_content .= '<div style="text-align: center;">'; $admin_email_content .= '<div>'; $admin_email_content .= '<img src="'.$href.'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $admin_email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $admin_email_content .= '</div>'; $admin_email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $admin_email_content .= '<img src="'.$href.'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $admin_email_content .= '</div>'; $admin_email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $admin_email_content .= '<h3 style="margin-top:10px;">Faculty Registration</h3>'; $admin_email_content .= '<p style="font-size:16px;padding-bottom:10px;">'.$regResult->fullname.', has registered for Nparrots on subjects '.$subDomains.' . Click on the below link to login admin dashboard.</p>'; $admin_email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="'.$href.'admin" style="color:#fff;padding:10px 30px;background:#a6d039;">Click here to login</a></p>'; $admin_email_content .= '</div>'; $admin_email_content .= '</div>'; $admin_email_content .= '</div>'; $admin_email_content .= '</body>'; // (Email sending and response) $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($checkOtp->new_email); // Change to the appropriate email field $emailService->setSubject('faculty Authentication'); $emailService->setMessage($admin_email_content); if ($emailService->send()) { echo json_encode(['result' => 1, 'message' => 'You will be notified by your password credentials and login link once admin approves your registration']); } else { echo json_encode(['result' => 2, 'message' => 'Error sending email']); } } else { echo json_encode(['result' => 2, 'message' => "Something went wrong.. try again"]); } } } else { echo json_encode(['result' => 0, 'message' => 'Wrong OTP']); } } public function complete_institute_faculty_verification() { $encryptedId = $this->request->getPost('encrypted_id'); $otpCode = $this->request->getPost('otp_code'); $faculty_model = new Faculty_Model(); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $loginTable = 'login'; $where = ['encrypted_login_id' => $encryptedId, 'otp_code' => $otpCode]; $checkOtp = $faculty_model->getWhereRow($loginTable, $where); if ($checkOtp) { if (($checkOtp->verified_status == 'VERIFIED') && ($checkOtp->new_email == '')) { return json_encode(['result' => 3, 'message' => 'OTP already verified']); } elseif ($checkOtp->new_email_status == 'VERIFIED') { return json_encode(['result' => 3, 'message' => 'OTP already verified']); } elseif (($checkOtp->new_email_status == 'NOT_VERIFIED') && ($checkOtp->verified_status == 'VERIFIED')) { $whereId = ['encrypted_login_id' => $encryptedId]; $updateData = [ 'new_email_status' => 'VERIFIED', 'verified_at' => $createdAt, 'email' => $checkOtp->new_email ]; $result = $faculty_model->UpdateData($loginTable, $updateData, $whereId); if ($this->db->affectedRows() > 0) { $regTable = 'faculty_registration'; $whereReg = ['login_id' => $checkOtp->login_id]; $updateData = ['email' => $checkOtp->new_email, 'updated_at' => $createdAt]; $result = $faculty_model->UpdateData($regTable, $updateData, $whereReg); if ($this->db->affectedRows() > 0) { return json_encode(['result' => 5, 'message' => 'Verified successfully']); } else { return json_encode(['result' => 2, 'message' => 'Something went wrong.. try again']); } } } else { $whereId = ['encrypted_login_id' => $encryptedId]; $updateData = ['verified_status' => 'VERIFIED', 'verified_at' => $createdAt]; $result = $faculty_model->UpdateData($loginTable, $updateData, $whereId); if ($this->db->affectedRows() > 0) { $regTable = 'faculty_registration'; $whereReg = ['login_id' => $checkOtp->login_id, 'delete_status' => 'ACTIVE']; $regResult = $faculty_model->getWhereRow($regTable, $whereReg); $subCatagory = json_decode($regResult->sub_domain_id); $subDomainArray = []; $subDomains = $faculty_model->approvedSubjects($subCatagory); foreach ($subDomains as $values) { array_push($subDomainArray, $values->sub_domain); } $subDomains = implode(', ', $subDomainArray); $href = base_url(''); $adminEmailContent = ''; $adminEmailContent .= '<body style="background:#f3f3f3;">'; $adminEmailContent .= '<div style="width:100%;">'; $adminEmailContent .= '<div style="text-align: center;">'; $adminEmailContent .= '<div>'; $adminEmailContent .= '<img src="' . $href . 'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $adminEmailContent .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $adminEmailContent .= '</div>'; $adminEmailContent .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $adminEmailContent .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $adminEmailContent .= '</div>'; $adminEmailContent .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $adminEmailContent .= '<h3 style="margin-top:10px;">Faculty Registration</h3>'; $adminEmailContent .= '<p style="font-size:16px;padding-bottom:10px;">' . $regResult->fullname . ', has registered for Nparrots on subjects ' . $subDomains . ' . Click on the below link to login admin dashboard.</p>'; $adminEmailContent .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="' . $href . 'admin" style="color:#fff;padding:10px 30px;background:#a6d039;">Click here to login</a></p>'; $adminEmailContent .= '</div>'; $adminEmailContent .= '</div>'; $adminEmailContent .= '</div>'; $adminEmailContent .= '</body>'; $this->load->library('email'); $phpMailer = new PHPMailer(true); $phpMailer->isSMTP(); $phpMailer->Host = "smtp-relay.gmail.com"; $phpMailer->SMTPAuth = true; $phpMailer->Username = "healthcare@medusyspty.com"; $phpMailer->Password = "Password@1236"; $phpMailer->SMTPSecure = "tls"; $phpMailer->Port = 587; $phpMailer->isHTML(true); $phpMailer->CharSet = "UTF-8"; $phpMailer->setFrom("healthcare@medusyspty.com", "Nparrots"); $phpMailer->addAddress('sowmyayp@gmail.com'); $phpMailer->Subject = "Faculty Registration"; $phpMailer->Body = $adminEmailContent; $phpMailer->send(); return json_encode(['result' => 1, 'message' => 'You will be notified by your password credentials and login link once admin approved your registration']); } else { return json_encode(['result' => 2, 'message' => 'Something went wrong.. try again']); } } } else { return json_encode(['result' => 0, 'message' => 'Wrong OTP']); } } public function add_requested_course() { $login_id = session()->get('faculty_login_id'); $user_type_id = session()->get('faculty_user_type_id'); $faculty_institution_id = session()->get('faculty_institution_id'); $login_table = 'login'; $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; $nparrotsModel = new Amcad_Home(); $email_result =$nparrotsModel->get_where_row11($login_table, $where); $email = $email_result->email; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $domain_id = $this->request->getPost('catagory'); $sub_domain_id = $this->request->getPost('sub_catagory'); $comments = $this->request->getPost('comments'); $batch_size = $this->request->getPost('batch_size'); $course_type = $this->request->getPost('course_type'); $available_type = ""; foreach ($course_type as $courses) { if ($courses == 'live') { $available_type = $this->request->getPost('available_type'); } } $i = 0; $j = 0; $k = 0; $l = 0; $time_count = 0; $start_time = ''; $end_time = ''; if ($available_type != '') { if ($available_type == 'timings') { $start_time = $this->request->getPost('from_time'); $end_time = $this->request->getPost('to_time'); $repeated_time = []; foreach ($start_time as $key => $value) { foreach ($start_time as $keys => $value) { if ($key != $keys) { if ((($start_time[$key] == $start_time[$keys]) && ($end_time[$key] == $end_time[$keys])) || ($start_time[$key] == $start_time[$keys])) { $i = $i + 1; } } } $timings_table = 'faculty_available_timings'; $where_timing = ['faculty_id' => $login_id, 'delete_status' => 'ACTIVE', 'approval_status' => 'APPROVED']; $timing_result = $nparrotsModel->get_where_result3($timings_table, $where_timing); if ($timing_result) { foreach ($timing_result as $time) { if ($time->from_time != '') { $explode_colon = explode(':', $start_time[$key]); $explode_space = explode(' ', $explode_colon[1]); $end_explode_colon = explode(':', $end_time[$key]); $end_explode_space = explode(' ', $end_explode_colon[1]); $from_colon = explode(':', $time->from_time); $from_space = explode(' ', $from_colon[1]); $totime_colon = explode(':', $time->to_time); $totime_space = explode(' ', $totime_colon[1]); if ((($start_time[$key] == $time->from_time) && ($end_time[$key] == $time->to_time))) { $time_count = $time_count + 1; $j = $j + 1; } if ($end_explode_space[1] == $from_space[1]) { if ($totime_colon[0] == $explode_colon[0]) { if ((($explode_space[0] < $totime_space[0]) || ($from_colon[0] == $explode_colon[0]))) { $time_count = $time_count + 1; $j = $j + 1; } } if (($from_colon[0] == $explode_colon[0]) && ($totime_colon[0] == $end_explode_colon[0])) { $time_count = $time_count + 1; $j = $j + 1; } if ((($end_explode_space[0] > $from_space[0]) && ($end_explode_colon[0] < $totime_colon[0]) && ($end_explode_colon[0] == $from_colon[0]))) { $time_count = $time_count + 1; $j = $j + 1; } } } } } if ($time_count >= 1) { $rtime = $start_time[$key] . ' To ' . $end_time[$key]; array_push($repeated_time, $rtime); } $time_count = 0; } $k = 0; foreach ($start_time as $key => $value) { foreach ($start_time as $keys => $value) { if ($key != $keys) { $start_explode_colon = explode(':', $start_time[$key]); $start_explode_space = explode(' ', $start_explode_colon[1]); $end_totime_colon = explode(':', $end_time[$key]); $end_totime_space = explode(' ', $end_totime_colon[1]); $start_explode_colons = explode(':', $start_time[$keys]); $start_explode_spaces = explode(' ', $start_explode_colons[1]); $end_explode_colons = explode(':', $end_time[$keys]); $end_explode_spaces = explode(' ', $end_explode_colons[1]); if ($start_explode_space[1] == $start_explode_spaces[1]) { if ((($start_explode_colons[0] == $end_totime_colon[0]) && ($start_explode_spaces[0] < $end_totime_space[0])) || ($start_explode_colons[0] == $start_explode_colon[0])) { $k = $k + 1; } } } } } } else { $enc_course_type = json_encode($course_type); $timings_table = 'faculty_available_timings'; $where_timing = ['faculty_id' => $login_id, 'delete_status' => 'ACTIVE', 'return_status' => 'NOT_RETURNED', 'available_type' => $available_type]; $timing_result = $nparrotsModel->get_where_result($timings_table, $where_timing); if ($timing_result) { foreach ($timing_result as $res) { $c_type = json_decode($res->course_type); $c_result = array_intersect($c_type, $course_type); if ($c_result) { $l = 1; $cc_types = implode(', ', $c_result); if ($res->approval_status == 'NOT_APPROVED') { $c_message = $cc_types . ' course type for fullday is already requested'; } else { $c_message = $cc_types . ' course type for fullday is already added to other course'; } break; } } } } } else { $enc_course_type = json_encode($course_type); $timings_table = 'faculty_available_timings'; $where_timing = ['faculty_id' => $login_id, 'delete_status' => 'ACTIVE', 'return_status' => 'NOT_RETURNED', 'course_type' => $enc_course_type]; $timing_result = $nparrotsModel->get_where_result3($timings_table, $where_timing); if ($timing_result) { foreach ($timing_result as $available) { $sub_ids = json_decode($available->subject_id); $ct_result = array_intersect($sub_ids, $sub_domain_id); if ($ct_result) { $l = 1; if ($available->approval_status == 'NOT_APPROVED') { $c_message = ' course type Recorded is already requested'; } else { $c_message = 'course type Recorded is already added to other course'; } break; } } } } if ($j >= 1) { $repeated_timings = implode(', ', $repeated_time); return json_encode(['result' => 0, 'message' => $repeated_timings . ' Timings are already added to other course']); } else if ($i >= 1) { return json_encode(['result' => 0, 'message' => 'Timings are duplicated']); } else if ($k >= 1) { return json_encode(['result' => 0, 'message' => 'Timings are duplicated']); } else if ($l == 1) { return json_encode(['result' => 0, 'message' => $c_message]); } else { $sub_domain = json_encode($sub_domain_id); $reg_table = 'faculty_registration'; $where_reg = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; $fac_reg = $nparrotsModel->get_where_row8($reg_table, $where_reg); $faculty_reg_id = $fac_reg->faculty_reg_id; $mapping_table = 'faculty_subject_mapping'; $where_mapping = ['sub_domain_id' => $sub_domain]; $subdomain = $nparrotsModel->get_where_row6($mapping_table, $where_mapping); $where_domain = ['login_id' => $login_id, 'delete_status' => 'ACTIVE', 'approval_status' => 'APPROVED']; $subdomains_res = $nparrotsModel->get_where_result6($mapping_table, $where_domain); $subids = ' '; foreach ($subdomains_res as $sub) { $sub_domain_dec = json_decode($sub->sub_domain_id); foreach ($sub_domain_dec as $id) { if (in_array($id, $sub_domain_id)) { $subids = 'exist'; } } } $subdomains = $nparrotsModel->get_where_sub_domain($sub_domain_id, $domain_id); $table = 'faculty_subject_mapping'; $data = [ 'login_id' => $login_id, 'domain_id' => $domain_id, 'batch_size' => $batch_size, 'sub_domain_id' => $sub_domain, 'faculty_reg_id' => $faculty_reg_id, 'comments' => $comments, 'created_by' => $login_id, 'delete_status' => 'ACTIVE', 'approval_status' => 'NOT_APPROVED', 'mapping_institution_id' => $faculty_institution_id, 'added_from' =>'REQUEST', 'created_at' => $created_at, ]; $result = $nparrotsModel->insertData($table, $data); if ($result) { $timing_table = 'faculty_available_timings'; if ($available_type != '') { if ($available_type == 'timings') { foreach ($start_time as $key => $value) { $timing_data = [ 'faculty_id' => $login_id, 'subject_mapping_id' => $result, 'subject_id' => $sub_domain, 'course_type' => json_encode($course_type), 'from_time' => $start_time[$key], 'to_time' => $end_time[$key], 'available_type' => $available_type, 'delete_status' => 'ACTIVE', 'approval_status' => 'NOT_APPROVED', 'return_status' => 'NOT_RETURNED', 'mapping_institution_id' => $faculty_institution_id, 'created_at' => $created_at, ]; $time_result = $nparrotsModel->insertData3($timing_table, $timing_data); } } else { $timing_data = [ 'faculty_id' => $login_id, 'subject_mapping_id' => $result, 'subject_id' => $sub_domain, 'course_type' => json_encode($course_type), 'from_time' => $start_time, 'to_time' => $end_time, 'available_type' => $available_type, 'delete_status' => 'ACTIVE', 'approval_status' => 'NOT_APPROVED', 'return_status' => 'NOT_RETURNED', 'mapping_institution_id' => $faculty_institution_id, 'created_at' => $created_at, ]; $time_result = $nparrotsModel->insertData3($timing_table, $timing_data); } } else { $timing_data = [ 'faculty_id' => $login_id, 'subject_mapping_id' => $result, 'subject_id' => $sub_domain, 'course_type' => json_encode($course_type), 'from_time' => $start_time, 'to_time' => $end_time, 'delete_status' => 'ACTIVE', 'approval_status' => 'NOT_APPROVED', 'return_status' => 'NOT_RETURNED', 'mapping_institution_id' => $faculty_institution_id, 'created_at' => $created_at, ]; $time_result = $nparrotsModel->insertData3($timing_table, $timing_data); } $domain_table = 'faculty_subject_mapping'; $where_domain = ['sub_domain_id' => $sub_domain]; $subdomain = $nparrotsModel->get_where_row9($domain_table,$where_domain); try { $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($email); $emailService->setSubject("Requested Courses"); // Configure your email settings here $href = base_url(); $email_content = '<body style="background:#f3f3f3;">'; $email_content .= '<body style="background:#f3f3f3;">'; $email_content .= '<div style="width:100%;">'; $email_content .= '<div style="text-align: center;">'; $email_content .= '<div>'; $email_content .= '<img src="' . $href . 'public/assets/images/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $email_content .= '</div>'; $email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $email_content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $email_content .= '</div>'; $email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $email_content .= '<h3 style="margin-top:10px;">New Subject Request Details</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello admin, </p>'; if ($subids == ' ') { $email_content .= '<p style="font-size:16px;padding-bottom:10px;">This is ' . $email_result->username . ' and i would like to teach on additional subjects ' . $subdomains . '</p>'; } else { $email_content .= '<p style="font-size:16px;padding-bottom:10px;">This is ' . $email_result->username . ' and i would like to add additional timings for subjects ' . $subdomains . '</p>'; } $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . $subdomain->comments . '</p>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; $emailService->setMessage($email_content); if ($emailService->send()) { if ($subids == ' ') { $notification = $email_result->username . ', has requested for additional subjects ' . $subdomains; } else { $notification = $email_result->username . ', has requested for additional timings for subjects ' . $subdomains; } $notification_data = [ 'login_id' => $login_id, 'username' => $email_result->username, 'notification' => $notification, 'view_status' => 'NOT_VIEWED', 'delete_status' => 'ACTIVE', 'category_type' => 'Course Request', 'created_by' => $login_id, 'created_at' => $created_at ]; if ($faculty_institution_id == 0) { $notification_table = 'notification'; $institution_id = '0'; } else { $notification_table = 'admin_notifications'; $notification_data['institution_id'] = $faculty_institution_id; $nparrotsModel->insertData5($notification_table, $notification_data); } } } catch (\Exception $e) { log_message('error', 'Email sending failed: ' . $e->getMessage()); } return json_encode(['result' => 1, 'message' => 'Added Successfully']); } } } // public function faculty_add_batch() // { // $nparrotsModel = new Amcad_Home(); // $insitution_login_id = $this->request->getPost('login_id'); // if ($insitution_login_id == 0) { // $course_id = 0; // } else { // $course_id = $this->request->getPost('course_id'); // } // $login_id = $this->request->getPost('faculty_login_id'); // $table = 'faculty_registration'; // $where_fac = ['login_id' => $login_id]; // $get_fac = $nparrotsModel->getWhereRow($table, $where_fac); // $fac_name = $get_fac->fullname; // $domain_id = $this->request->getPost('domain_id'); // $table = 'domains'; // $where_domain = ['domain_id' => $domain_id]; // $details = $nparrotsModel->getWhereRow($table, $where_domain); // $domain_title = $details->domain_name; // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $table = 'sub_domains'; // $where_domain = ['domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id]; // $sub_domain_details = $nparrotsModel->getWhereRow($table, $where_domain); // $sub_domain_title = $sub_domain_details->sub_domain; // $table = 'courses'; // $where_domain = ['domain_id' => $domain_id]; // $course_details = $nparrotsModel->getWhereRow($table, $where_domain); // $course_title = ($course_details) ? $course_details->course_title : ''; // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $from_time = $this->request->getPost('from_time'); // $batch_name = $this->request->getPost('batch_name'); // $batch_type = $this->request->getPost('batch_type'); // $batch_range_size = $this->request->getPost('batch_range_size'); // if ($batch_type == 'Fixed') { // $batch_size = $this->request->getPost('batch_fixed_size'); // } elseif ($batch_type == 'Range') { // $batch_size = $this->request->getPost('batch_range_size'); // } // $course_type = $this->request->getPost('course_type'); // $batch_from_date = $this->request->getPost('batch_from_date'); // $batch_to_date = $this->request->getPost('batch_to_date'); // $batch_duration = $this->request->getPost('batch_duration'); // if ($batch_duration != "") { // $table = 'batches'; // $where = ['batch_name' => $batch_name, 'course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time]; // $result = $nparrotsModel->getWhereRow($table, $where); // if ($course_type == "" || $batch_size == "" || $batch_from_date == "" || $batch_to_date == "") { // echo json_encode(['result' => 0, 'message' => 'Please Fill All Fields']); // } elseif ($course_type == "Recorded") { // if (!$result) { // $where1 = ['course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time]; // $result1 = $nparrotsModel->getWhereRow($table, $where1); // if (!$result1) { // $batch_table = 'batches'; // $batch_data = [ // 'course_id' => $course_id, // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'faculty_id' => $login_id, // 'from_time' => $from_time, // 'batch_name' => $batch_name, // 'batch_type' => $batch_type, // 'batch_size' => $batch_size, // 'batch_from_date' => $batch_from_date, // 'batch_to_date' => $batch_to_date, // 'batch_duration' => $batch_duration, // 'course_type' => $course_type, // 'delete_status' => 'ACTIVE', // 'created_by' => $login_id, // 'institution_id' => $insitution_login_id, // 'created_at' => $created_at, // ]; // $result = $nparrotsModel->insert($batch_table, $batch_data); // if ($result) { // $this->load->library('email'); // $href = base_url(''); // $email_content = ''; // // ... (Email content creation) // // Example of sending email using CodeIgniter 4 // $email = \Config\Services::email(); // $email->setTo('recipient@example.com'); // $email->setSubject('Batch Created Successfully'); // $email->setMessage($email_content); // $email->send(); // echo json_encode(['result' => 1, 'message' => 'Batch Created Successfully']); // } else { // echo json_encode(['result' => 0, 'message' => 'Something went wrong']); // } // } else { // echo json_encode(['result' => 0, 'message' => 'Batch with Recorded Course Already Exist']); // } // } else { // echo json_encode(['result' => 0, 'message' => 'Batch Already Exist']); // } // } elseif ($course_type == "Upcoming") { // if (!$result) { // $batch_table = 'batches'; // $batch_data = [ // 'course_id' => $course_id, // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'faculty_id' => $login_id, // 'from_time' => $from_time, // 'batch_name' => $batch_name, // 'batch_type' => $batch_type, // 'batch_size' => $batch_size, // 'batch_from_date' => $batch_from_date, // 'batch_to_date' => $batch_to_date, // 'batch_duration' => $batch_duration, // 'course_type' => $course_type, // 'delete_status' => 'ACTIVE', // 'created_by' => $login_id, // 'institution_id' => $insitution_login_id, // 'created_at' => $created_at, // ]; // $result = $nparrotsModel->insert($batch_table, $batch_data); // if ($result) { // // Send Email // $emailContent = '<body style="background:#f3f3f3;">'; // // ... (Email content creation) // $email = \Config\Services::email(); // $email->setTo('recipient@example.com'); // $email->setSubject('Batch Created Successfully'); // $email->setMessage($emailContent); // $email->send(); // return json_encode(['result' => 1, 'message' => 'Batch Created Successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Batch with Recorded Course Already Exist']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Batch Already Exist']); // } // } elseif ($courseType == "Upcoming") { // if (!$result) { // $batchData = [ // 'course_id' => $courseId, // 'domain_id' => $domainId, // 'sub_domain_id' => $subDomainId, // 'faculty_id' => $loginId, // 'from_time' => $fromTime, // 'batch_name' => $batchName, // 'batch_type' => $batchType, // 'batch_size' => $batchSize, // 'batch_from_date' => $batchFromDate, // 'batch_to_date' => $batchToDate, // 'batch_duration' => $batchDuration, // 'course_type' => $courseType, // 'delete_status' => 'ACTIVE', // 'created_by' => $loginId, // 'institution_id' => $institutionLoginId, // 'created_at' => $created_at, // ]; // $result = $nparrotsModel->insert($batchTable, $batchData); // if ($result) { // // Send Email // $emailContent = '<body style="background:#f3f3f3;">'; // // ... (Email content creation) // $email = \Config\Services::email(); // $email->setTo('recipient@example.com'); // $email->setSubject('Batch Created Successfully'); // $email->setMessage($emailContent); // $email->send(); // return json_encode(['result' => 1, 'message' => 'Batch Created Successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong']); // } // } else { // return json_encode(['result' => 2, 'message' => 'Batch is already created']); // } // } else { // // return json_encode(['result' => 2, 'message' => 'Batch is already created']); // // } // // } else{ // if (!$result) { // $where1 = ['course_type' => $courseType, 'sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE', 'from_time' => $fromTime]; // $result1 = $nparrotsModel->getWhereRow($batchTable, $where1); // if (!$result1) { // $batchData = [ // 'course_id' => $courseId, // 'domain_id' => $domainId, // 'sub_domain_id' => $subDomainId, // // Add other batch data variables as needed // ]; // $result = $nparrotsModel->insert($batchTable, $batchData); // if ($result) { // // Email sending logic // // $this->email->initialize([...]); // Initialize email settings // $emailContent = '<body style="background:#f3f3f3;">'; // // Build email content // // ... // $this->email->setTo('sowmyayp@gmail.com'); // $this->email->setSubject('Faculty Batch'); // $this->email->setMessage($emailContent); // if ($this->email->send()) { // return json_encode(['result' => 1, 'message' => 'Batch added successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Email sending failed']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } else { // return json_encode(['result' => 2, 'message' => 'Batch is already created']); // } // } elseif ($institutionLoginId) { // // Repeat the same logic for institution_login_id block // } else { // return json_encode(['result' => 2, 'message' => 'Batch is already created']); // } // } // } public function faculty_add_batch() { $nparrotsModel = new Amcad_Home(); $insitution_login_id = $this->request->getPost('login_id'); if ($insitution_login_id == 0) { $course_id = 0; } else { $course_id = $this->request->getPost('course_id'); } $login_id = $this->request->getPost('faculty_login_id'); $table = 'faculty_registration'; $where_fac = ['login_id' => $login_id]; $get_fac = $nparrotsModel->getWhereRow($table, $where_fac); $fac_name = $get_fac->fullname; $domain_id = $this->request->getPost('domain_id'); $table = 'domains'; $where_domain = ['domain_id' => $domain_id]; $details = $nparrotsModel->getWhereRow($table, $where_domain); $domain_title = $details->domain_name; $sub_domain_id = $this->request->getPost('sub_domain_id'); $table = 'sub_domains'; $where_domain = ['domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id]; $sub_domain_details = $nparrotsModel->getWhereRow($table, $where_domain); $sub_domain_title = $sub_domain_details->sub_domain; $table = 'courses'; $where_domain = ['domain_id' => $domain_id]; $course_details = $nparrotsModel->getWhereRow($table, $where_domain); if ($course_details) { $course_title = $course_details->course_title; } else { $course_title = ''; } $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $from_time = $this->request->getPost('from_time'); $batch_name = $this->request->getPost('batch_name'); $batch_type = $this->request->getPost('batch_type'); $batch_range_size = $this->request->getPost('batch_range_size'); if ($batch_type == 'Fixed') { $batch_size = $this->request->getPost('batch_fixed_size'); } elseif ($batch_type == 'Range') { $batch_size = $this->request->getPost('batch_range_size'); } $course_type = $this->request->getPost('course_type'); $batch_from_date = $this->request->getPost('batch_from_date'); $batch_to_date = $this->request->getPost('batch_to_date'); $batch_duration = $this->request->getPost('batch_duration'); if ($batch_duration != "") { $table = 'batches'; $where = [ 'batch_name' => $batch_name, 'course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time ]; $result = $nparrotsModel->getWhereRow($table, $where); if (empty($course_type) || empty($batch_size) || empty($batch_from_date) || empty($batch_to_date)) { return json_encode(['result' => 0, 'message' => 'Please Fill All Fields']); } elseif ($course_type == "Recorded") { if (!$result) { $where1 = ['course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time]; $result1 = $nparrotsModel->getWhereRow($table, $where1); if (!$result1) { $batch_table = 'batches'; $batch_data = [ 'course_id' => $course_id, 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'faculty_id' => $login_id, 'from_time' => $from_time, 'batch_name' => $batch_name, 'batch_type' => $batch_type, 'batch_size' => $batch_size, 'batch_from_date' => $batch_from_date, 'batch_to_date' => $batch_to_date, 'batch_duration' => $batch_duration, 'course_type' => $course_type, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'institution_id' => $insitution_login_id, 'created_at' => $created_at, ]; $result = $nparrotsModel->insertData($batch_table, $batch_data); // $href = base_url(''); if ($result) { $href = base_url(''); // Send Email $email_content = ''; $email_content = '<body style="background:#f3f3f3;">'; $email_content .= '<div style="width:100%;">'; $email_content .= '<div style="text-align: center;">'; $email_content .= '<div>'; $email_content .= '<img src="' . $href . 'public/assets/website_assets/icons/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $email_content .= '</div>'; $email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $email_content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $email_content .= '</div>'; $email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $email_content .= '<h3 style="margin-top:10px;">Faculty Batch</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello admin,</p>'; if (!empty($course_title)) { $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . esc($fac_name) . ' has added a new batch - ' . esc($batch_name) . ' for the course ' . esc($course_title) . ' for recorded session from ' . esc($batch_from_date) . ' to ' . esc($batch_to_date) . ' of batch size ' . esc($batch_size) . '.</p>'; } else { $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . esc($fac_name) . ' has added a new batch - ' . esc($batch_name) . ' for the subject ' . esc($sub_domain_title) . ' for recorded session from ' . esc($batch_from_date) . ' to ' . esc($batch_to_date) . ' of batch size ' . esc($batch_size) . '.</p>'; } $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo('unknownjayblues@gmail.com'); $emailService->setSubject('Batch Created Successfully'); $emailService->setMessage($email_content); $emailService->send(); return json_encode(['result' => 1, 'message' => 'Batch added Successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); } } else { return json_encode(['result' => 2, 'message' => 'Batch is already created']); } } else if ($insitution_login_id) { $where1 = [ 'course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time ]; $result1 = $nparrotsModel->get_where_row($table, $where1); if (!$result1) { $batch_table = 'batches'; $batch_data = [ 'course_id' => $course_id, 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'faculty_id' => $login_id, 'from_time' => $from_time, 'batch_name' => $batch_name, 'batch_type' => $batch_type, 'batch_size' => $batch_size, 'batch_from_date' => $batch_from_date, 'batch_to_date' => $batch_to_date, 'batch_duration' => $batch_duration, 'course_type' => $course_type, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'institution_id' => $insitution_login_id, 'created_at' => $created_at, ]; $result = $nparrotsModel->insertData($batch_table, $batch_data); if ($result) { $href = base_url(''); // Send Email $email_content = ''; $email_content = '<body style="background:#f3f3f3;">'; $email_content .= '<div style="width:100%;">'; $email_content .= '<div style="text-align: center;">'; $email_content .= '<div>'; $email_content .= '<img src="' . $href . 'public/assets/website_assets/icons/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $email_content .= '</div>'; $email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $email_content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $email_content .= '</div>'; $email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $email_content .= '<h3 style="margin-top:10px;">Faculty Batch</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello admin,</p>'; if (!empty($course_title)) { $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . $fac_name . ' has added a new batch - ' . $batch_name . ' for the course ' . $course_title . ' for recorded session from ' . $batch_from_date . ' to ' . $batch_to_date . ' of batch size ' . $batch_size . '.</p>'; } else { $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . $fac_name . ' has added a new batch - ' . $batch_name . ' for the subject ' . $sub_domain_title . ' for recorded session from ' . $batch_from_date . ' to ' . $batch_to_date . ' of batch size ' . $batch_size . '.</p>'; } $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo('unknownjayblues@gmail.com'); $emailService->setSubject('Faculty Batch'); $emailService->setMessage($email_content); $emailService->send(); return json_encode(['result' => 1, 'message' => 'Batch added Successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); } } else { return json_encode(['result' => 2, 'message' => 'Batch is already created']); } } else { return json_encode(['result' => 2, 'message' => 'Batch Already Exist']); } } else { if (!$result) { $where1 = [ 'course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time ]; $result1 = $nparrotsModel->get_where_row($table, $where1); if (!$result) { $batch_table = 'batches'; $batch_data = [ 'course_id' => $course_id, 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'faculty_id' => $login_id, 'from_time' => $from_time, 'batch_name' => $batch_name, 'batch_type' => $batch_type, 'batch_size' => $batch_size, 'batch_from_date' => $batch_from_date, 'batch_to_date' => $batch_to_date, 'batch_duration' => $batch_duration, 'course_type' => $course_type, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'institution_id' => $insitution_login_id, 'created_at' => $created_at, ]; $result = $nparrotsModel->insertData($batch_table, $batch_data); if ($result) { $href = base_url(''); $email_content = (''); $email_content = '<body style="background:#f3f3f3;">'; $email_content .= '<div style="width:100%;">'; $email_content .= '<div style="text-align: center;">'; $email_content .= '<div>'; $email_content .= '<img src="' . $href . 'public/assets/website_assets/icons/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $email_content .= '</div>'; $email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $email_content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $email_content .= '</div>'; $email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $email_content .= '<h3 style="margin-top:10px;">Faculty Batch</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello admin,</p>'; if (!empty($course_title)) { $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . $fac_name . ' has added a new batch - ' . $batch_name . ' for the course ' . $course_title . ' at ' . $from_time . ' from ' . $batch_from_date . ' to ' . $batch_to_date . ' of batch size ' . $batch_size . '.</p>'; } else { $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . $fac_name . ' has added a new batch - ' . $batch_name . ' for the course ' . $sub_domain_title . ' at ' . $from_time . ' from ' . $batch_from_date . ' to ' . $batch_to_date . ' of batch size ' . $batch_size . '.</p>'; } $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo('unknownjayblues@gmail.com'); $emailService->setSubject('Faculty Batch'); $emailService->setMessage($email_content); $emailService->send(); return json_encode(['result' => 1, 'message' => 'Batch added Successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); } } else { return json_encode(['result' => 2, 'message' => 'Batch is already created']); } } else if ($insitution_login_id) { $where1 = [ 'course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time ]; $result1 = $nparrotsModel->get_where_row($table, $where1); if (!$result) { // $where1 = ['course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time]; // $result1 = $nparrotsModel->getWhereRow($batch_table, $where1); if (!$result1) { $batch_table = 'batches'; $batch_data = [ 'course_id' => $course_id, 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'faculty_id' => $login_id, 'from_time' => $from_time, 'batch_name' => $batch_name, 'batch_type' => $batch_type, 'batch_size' => $batch_size, 'batch_from_date' => $batch_from_date, 'batch_to_date' => $batch_to_date, 'batch_duration' => $batch_duration, 'course_type' => $course_type, 'delete_status' => 'ACTIVE', 'batch_approval_status' => 'APPROVED', 'created_by' => $login_id, 'institution_id' => $insitution_login_id, 'created_at' => $created_at, ]; $result = $nparrotsModel->insertData($batch_table, $batch_data); if ($result) { $href = base_url(''); $email_content = ''; $email_content = '<body style="background:#f3f3f3;">'; $email_content .= '<div style="width:100%;">'; $email_content .= '<div style="text-align: center;">'; $email_content .= '<div>'; $email_content .= '<img src="' . $href . 'public/assets/website_assets/icons/Logo_AMCAD.png" style="float:left;padding-left: 11px;padding-bottom: 10px;"/>'; $email_content .= '<p style="float:right;color:#000;padding-right:13px;padding-top:15px;">Bringing Affordable Learning Anywhere</p>'; $email_content .= '</div>'; $email_content .= '<div style="padding-top:2%;padding-bottom:2%;background:#a6d039;box-shadow: 2px 2px 5px #707070;clear: both;">'; $email_content .= '<img src="' . $href . 'public/assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; $email_content .= '</div>'; $email_content .= '<div style="background:#fff;padding-top:3%;padding-bottom:3%;padding-left:1%;padding-right:1%;box-shadow: 2px 2px 5px #707070;">'; $email_content .= '<h3 style="margin-top:10px;">Faculty Batch</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello admin,</p>'; if (!empty($course_title)) { $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . $fac_name . ' has added a new batch - ' . $batch_name . ' for the course ' . $course_title . ' at ' . $from_time . ' from ' . $batch_from_date . ' to ' . $batch_to_date . ' of batch size ' . $batch_size . '.</p>'; } else { $email_content .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;">' . $fac_name . ' has added a new batch - ' . $batch_name . ' for the course ' . $sub_domain_title . ' at ' . $from_time . ' from ' . $batch_from_date . ' to ' . $batch_to_date . ' of batch size ' . $batch_size . '.</p>'; } $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo('unknownjayblues@gmail.com'); $emailService->setSubject('Faculty Batch'); $emailService->setMessage($email_content); if ($emailService->send()) return $this->response->setJSON(['result' => 1, 'message' => 'Batch added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Email sending failed']); } } else { return $this->response->setJSON(['result' => 2, 'message' => 'Batch is already created']); } } else { return $this->response->setJSON(['result' => 2, 'message' => 'Batch is already created']); } } } } else { return $this->response->setJSON(['result' => 3, 'message' => 'Duration has not been added by Faculty']); } } public function get_chapter_wise_result() { $loginId = session()->get('user_login_id'); $nparrotsModel = new Amcad_Home(); if ($loginId) { $chapterId = $this->request->uri->getSegment(3); $table = 'question_mapping'; $where = ['chapter_id' => $chapterId, 'user_id' => $loginId]; $getTestId = $nparrotsModel->getWhereResult1($table, $where); $testId = null; foreach ($getTestId as $value) { $testId = $value->test_id; } $correctAnswer =$nparrotsModel->correctAnswer($chapterId, $loginId, $testId); $data['correct_answer'] = $correctAnswer; $data['incorrect_answer'] = $nparrotsModel->incorrectAnswer($chapterId, $loginId, $testId); $data['not_attempted_answer'] = $nparrotsModel->notAttemptedAnswer($chapterId, $loginId, $testId); $incorrectAnswer = $nparrotsModel->incorrectAnswer($chapterId, $loginId, $testId); $notAttemptedAnswer = $nparrotsModel->notAttemptedAnswer($chapterId, $loginId, $testId); $data1['correct_answer'] = $correctAnswer; $data1['incorrect_answer'] = $incorrectAnswer; $data1['not_attempted_answer'] = $notAttemptedAnswer; return json_encode(['data' => $data1]); } } public function go_live() { $id = $this->request->getPost('id'); $builder = $this->db->table('faculty_mocktest_setting'); $builder->where('id', $id); $update = $builder->update(['live_status' => 1]); if ($update) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } public function save_score(){ $loginId = session()->get('user_login_id'); $data = array( 'user_id' => $loginId, 'correct_answer' => $this->request->getPost('correct_answer'), 'incorrect_answer' => $this->request->getPost('incorrect_answer'), 'not_attempted_answer' => $this->request->getPost('not_attempted_answer'), 'mapping_id' => $this->request->getPost('mapping_id'), 'chapter_id' => $this->request->getPost('chapter_id'), ); $builder = $this->db->table('test_results'); $inserted = $builder->insert($data); if ($inserted) { return $this->response->setJSON([ 'status' => 'success', 'message' => 'Marks Stored Successfully' ]); } else { return $this->response->setJSON([ 'status' => 'error', 'message' => 'Failed to store marks' ]); } } }