EVOLUTION-NINJA
Edit File: Home.php
<?php namespace App\Controllers; use CodeIgniter\Controller; use CodeIgniter\API\ResponseTrait; use App\Models\Admin\Nparrots_Model; use App\Models\Admin\Course_Model; use App\Models\Admin\coursemodel1; use App\Models\Admin\Master_Model; use App\Models\Admin\Syllabus_Model; use App\Models\Syllabus_Chapter; use App\Models\Admin\Faculty_Model; use App\Models\Admin\Batch_Model; use App\Models\Admin\Content_Model; use App\Models\Admin\Content_Model_1; use App\Models\Admin\Enrolled_Model; use App\Models\Admin\Feedback_Model; use App\Models\Admin\Notification_Model; use App\Models\Admin\contents12; use App\Models\Admin\addnewcoursemodel; use App\Models\Admin\InstitutionModel; use CodeIgniter\HTTP\ResponseInterface; use App\Models\Protection_model; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use CodeIgniter\Database\ConnectionInterface; use Intervention\Image\ImageManagerStatic as Image; use DateTime; use DateTimeZone; use CodeIgniter\I18n\Time; use CodeIgniter\Email\Email; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\Services; use App\Models\TestResultModel; class Home extends Controller { use ResponseTrait; protected $db; protected $imageLib; public function __construct() { $this->db = \Config\Database::connect(); // Initialize the database connection $this->imageLib = service('image_lib'); } public function admin() { return view('admin/login'); } public function test_uploads() { return view('faculty/test_uploads'); } public function test_result_page() { $model = new TestResultModel(); $data['results'] = $model->getResults(); return view('faculty/test_result', $data); } 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')); $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 admin_dashboard() { $session = session(); // Load the session service $login_id = $session->get('login_id'); if ($login_id) { // Initialize the model $nparrots_model = new Nparrots_Model(); $whereFaculty = [ 'verified_status' => 'VERIFIED', 'delete_status' => 'ACTIVE', 'user_type_id' => 2, 'approval_status' => 'APPROVED', 'institution_id' => 0 ]; $data['users'] = count($nparrots_model->getUserRegistrations()); $data['faculty'] = count($nparrots_model->getWhereResult('login', $whereFaculty)); $data['institutions'] = count($nparrots_model->getInstitutesDetails()); return view('admin/admin_dashboard', $data); } else { return redirect()->to('/admin'); } } public function user_dashboard() { $session = session(); // Load the session service $login_id = $session->get('user_login_id'); if ($login_id) { return view('user/user_dashboard'); } else { return redirect()->to('admin'); } } public function test_result() { $session = session(); $login_id = $session->get('user_login_id'); if ($login_id) { return view('user/user_dashboard'); } else { return redirect()->to('admin'); } } public function getNotifications() { $table = 'notification'; $nparrots_model = new Nparrots_Model(); $where = ['delete_status' => 'ACTIVE', 'view_status' => 'NOT_VIEWED']; $count = $nparrots_model->getWhereResult($table, $where); $whereActive = ['delete_status' => 'ACTIVE']; $orderBy = 'created_at'; $notification = $nparrots_model->getWhereResultOrderBy($table, $whereActive, $orderBy); if ($notification) { $response = [ 'result' => 1, 'count' => count($count), 'notification' => $notification ]; } else { $response = ['result' => 0]; } return $this->response->setJSON($response); // Return a JSON response } public function loadTabContent($tabName) { // Call the model to retrieve tab content data $nparrots_model = new Nparrots_Model(); $tabContent = $nparrots_model->getTabContent($tabName); // Return the tab content as JSON header('Content-Type: application/json'); echo json_encode($tabContent); } public function viewAllNotifications() { $nodification_model = new Notification_Model(); $table = 'notification'; $where = ['delete_status' => 'ACTIVE']; $orderBy = 'created_at'; $data['notification'] = $nodification_model->getWhereResultOrderBy($table, $where, $orderBy); // $data['comments'] = $comments; return view('admin/notifications', $data); } public function viewAllAdminNotifications() { $session = session(); $institution_id = $session->get('institution_login_id'); $nodification_model = new Notification_Model(); $table = 'admin_notifications'; $where = ['delete_status' => 'ACTIVE', 'institution_id' => $institution_id]; $orderBy = 'created_at'; $data['notification'] = $nodification_model->getWhereResultOrderBy($table, $where, $orderBy); return view('institutions/admin_notifications', $data); } public function deleteNotification() { $notificationId = $this->request->getPost('notification_id'); $nodification_model = new Notification_Model(); $result = $nodification_model->deleteNotification($notificationId); if ($result) { return $this->response->setJSON(['success' => true]); } else { return $this->response->setJSON(['success' => false]); } } public function changeNotificationStatus() { $table = 'notification'; $where = ['delete_status' => 'ACTIVE', 'view_status' => 'NOT_VIEWED']; $data = ['view_status' => 'VIEWED']; // Load the model $nodification_model = new Notification_Model(); $result = $nodification_model->updateData($table, $data, $where); $whereActive = ['delete_status' => 'ACTIVE']; $orderBy = 'created_at'; $notification = $nodification_model->getWhereResultOrderBy($table, $whereActive, $orderBy); if ($result) { return $this->response->setJSON(['result' => 1, 'notification' => $notification, 'count' => 0]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_admin_details() { $loginId = session()->get('login_id'); $nparrots_model = new Nparrots_Model(); if ($loginId) { $table = 'login'; $where = ['login_id' => $loginId]; $result = $nparrots_model->getWhereRow($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } else { return $this->response->setJSON(['result' => 0]); } } public function single_course_details() { $courseModel = new Course_Model(); $table = 'courses'; $course_id = $this->request->getPost('course_id'); $where = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; $result = $courseModel->getCourseRow($course_id); $timings = $courseModel->get_where_courses_timings($course_id); if ($result) { return $this->response->setJSON(['course_details' => $result, 'result' => 1, 'timings' => $timings]); } else { return $this->response->setJSON(['result' => 0]); } } public function admin_profile() { $session = \Config\Services::session(); $login_id = $session->get('login_id'); if ($login_id) { $nparrots_model = new Nparrots_Model(); $table = 'login'; $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; $data['admin_details'] = $nparrots_model->getWhereRow($table, $where); // Pass the session data to the view return view('admin/admin_profile', [ 'login_id' => $login_id, // Pass login_id directly 'admin_details' => $data['admin_details'], // Pass admin_details ]); } else { return redirect()->to('/admin'); } } public function update_admin_profile() { $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'); $name = $this->request->getPost('name'); $email = $this->request->getPost('email'); $model = new Nparrots_Model(); $where = ['delete_status' => 'ACTIVE', 'login_id' => $login_id]; $table = 'login'; $login_res = $model->getWhereRow($table, $where); $image_files = ""; if ($this->request->getFile('profile_pic')) { $profilePic = $this->request->getFile('profile_pic'); // Check if the file is valid if ($profilePic->isValid()) { $newName = $profilePic->getRandomName(); $profilePic->move('./public/course_images', $newName); $image_files = $newName; } } if (!empty($image_files)) { $data = ['username' => $name, 'email' => $email, 'image' => $image_files, 'updated_at' => $created_at]; } else { $data = ['username' => $name, 'email' => $email, 'updated_at' => $created_at]; } $where = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; $table = 'login'; if (isset($login_res) && is_object($login_res) && isset($login_res->email)) { if ($login_res->email == $email) { $result = $model->updateData($where, $table, $data); if ($model->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } // Handle the case where login_res is not set } } public function admin_logout() { // Load the session service $session = session(); // Unset session data $session->remove('login_id'); $session->remove('user_type_id'); $session->remove('username'); $session->remove('user_type'); // Redirect to the admin page return redirect()->to('/admin'); } public function update_password() { helper('uri'); $encrypted_id = $this->request->uri->getSegment(2); $data['encrypted_id'] = $encrypted_id; return view('user/update', $data); } public function update_password1() { // helper('uri'); // $encrypted_id = $this->request->uri->getSegment(2); // $data['encrypted_id'] = $encrypted_id; return view('user/update1'); } public function reset_password() { $session = session(); // Check if the email exists in the session $email = $session->get('email'); // print_r($email);die(); $old_password = md5($this->request->getPost('oldPassword')); // $old_password = $this->request->getPost('oldPassword'); // print_r($old_password);die(); $password1 = $this->request->getPost('password1'); $password2 = $this->request->getPost('password2'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $table = 'login'; // $where = ['encrypted_login_id' => $encrypted_id]; $where = ['password' => $old_password, 'email'=>$email, ]; $data = [ 'password' => md5($password2), // 'password' => $password2, 'updated_at' => $updated_at ]; $nparrots_model = new Nparrots_Model(); $type_result = $nparrots_model->getWhereRow($table, $where); if ($type_result !== null) { if ($type_result->delete_status == 'INACTIVE') { return $this->response->setJSON(['result' => 0, 'message' => "Your account is deleted"]); } else { if ($password1 == $password2) { $nparrots_model->updateData($where, $table, $data); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Updated successfully", 'data' => $type_result]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Failed to update. Try again"]); } } else { // return $this->response->setJSON(['result' => 2, 'message' => "New and Confirm Password doesn't match"]); return $this->response->setJSON(['result' => 2, 'message' => "New password and Confirm Password Must Be Same"]); } } } else { return $this->response->setJSON(['result' => 0, 'message' => "Please Enter Old Password Correctly"]); // Handle the case where no user was found } } public function add_course_to_users_form() { $login_id = session('institution_login_id'); if ($login_id) { $user_id = $this->request->uri->getSegment(2); $table = 'user_course_mapping'; $where = ['user_id' => $user_id, 'delete_status' => 'ACTIVE', 'payment_status' => 'PAID']; $nparrots_model = new Nparrots_Model(); $prev_domains = $nparrots_model->getWhereResult($table, $where); $array = []; if ($prev_domains) { foreach ($prev_domains as $val) { $ids = json_decode($val->sub_domain_ids); foreach ($ids as $val_1) { array_push($array, $val_1); } } } $data['prev_domains'] = $array; $table = 'sub_domains'; $where = ['created_by' => $login_id, 'user_type_id' => '4', 'delete_status' => 'ACTIVE']; $data['subdomains'] = $nparrots_model->getUserSubdomains($array); $table = 'centers'; $where = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; $order_by = 'center'; $data['centers'] = $nparrots_model->getWhereResultOrderByAsc($table, $where, $order_by); $login_table = 'login'; $where_user = ['login_id' => $user_id]; $data['user_result'] = $nparrots_model->getWhereRow($login_table, $where_user); return view('institutions/add_course_to_users', $data); } else { return redirect()->to('/institution-login'); } } public function add_new_course_admin() { $session = session(); // Load the session service $login_id = $session->get('login_id'); // Retrieve the 'login_id' from the session $user_type_id = $session->get('user_type_id'); // Retrieve the 'user_type_id' from the session if ($login_id) { $nparrots_model = new Nparrots_Model(); $table = 'domains'; $where = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; $order_by = 'domain_name'; $data['categories'] = $nparrots_model->getWhereResultOrderByAsc($table, $where, $order_by); return view('admin/add_new_course_admin', $data); // Load the view with data } else { return redirect()->to('/admin'); // Redirect to the home page } } public function categories() { $session = session(); $login_id = $session->get('login_id'); if ($login_id) { return view('admin/categories'); } else { return redirect()->to('/admin'); } } public function subCategories() { $login_id = session()->get('login_id'); if ($login_id) { $table = 'domains'; $where = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; $orderBy = 'domain_name'; $content_model = new Content_Model(); $data['categories'] = $content_model->getWhereResultOrderByAsc($table, $where, $orderBy); return view('admin/sub_categories', $data); } else { return redirect()->to('/admin'); } } public function syllabus() { $login_id = session('login_id'); if ($login_id) { $nparrots_model = new Nparrots_Model(); $data['sub_domain'] = $nparrots_model->getSubCategoriesList(); return view('admin/syllabus', $data); } else { return redirect()->to('/admin'); } } public function add_admin_topics() { $nparrots_model = new Nparrots_Model(); $loginId = session()->get('login_id'); if ($loginId) { $table = 'faculty_registration'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $result = $nparrots_model->getWhereRow($table, $where); $domainTable = 'domains'; $whereDomain = ['delete_status' => 'ACTIVE', 'created_by' => $loginId]; $orderBy = 'domain_name'; $data['domain'] = $nparrots_model->getWhereResultOrderByAsc($domainTable, $whereDomain, $orderBy); // Make sure to use the correct method name // Load the view return view('admin/add_topics', $data); } else { return redirect()->to('admin'); } } public function course() { $session = session(); $login_id = $session->get('login_id'); $user_type_id = $session->get('user_type_id'); if ($login_id) { $nparrots_model = new Nparrots_Model(); // Replace with your actual model class $domain_table = 'domains'; $where_domain = [ 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'user_type_id' => $user_type_id, ]; $order_by = 'domain_name'; $data['domain'] = $nparrots_model->getWhereResultOrderByAsc($domain_table, $where_domain, $order_by); return view('admin/course_form', $data); } else { return redirect()->to('/admin'); } } public function course_list() { $session = session(); $login_id = $session->get('login_id'); if ($login_id) { return view('admin/course_list'); } else { return redirect()->to('/admin'); } } public function get_all_course_list() { $courseModel = new Course_Model(); // Load your model $result = $courseModel->get_all_course_list(); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0]); } } public function faculty_list() { $login_id = session()->get('login_id'); if ($login_id) { return view('admin/faculty_list'); // Load the view } else { return redirect()->to('/admin'); // Redirect to the home page } } public function enrolledUsersList() { $loginId = session()->get('login_id'); if ($loginId) { return view('admin/enrolled_users_list'); } else { return redirect()->to('/admin'); } } public function add_material_form() { $nparrots_model = new Nparrots_Model(); $loginId = session()->get('login_id'); // Use session() helper to get session data if ($loginId) { $domainTable = 'domains'; $whereDomain = ['delete_status' => 'ACTIVE', 'created_by' => $loginId]; $orderBy = 'domain_name'; $data['domains'] = $nparrots_model->getWhereResultOrderByAsc($domainTable, $whereDomain, $orderBy); echo view('admin/materials', $data); } else { return redirect()->to('/admin'); } } public function adminMaterialList() { $loginId = session()->get('login_id'); // Use session() helper to get session data if ($loginId) { $domain = []; // Define the $domain variable as an empty array or fetch the data from your model $sub_domain = []; // Define the $sub_domain variable as an empty array or fetch the data from your model $data = [ 'domain' => $domain, 'sub_domain' => $sub_domain, ]; return view('admin/admin_material_list', $data); } else { return redirect()->to('/admin'); } } public function material_list() { $login_id = session()->get('login_id'); // CodeIgniter 4 session access if ($login_id) { return view('admin/material_list'); // CodeIgniter 4 view function } else { return redirect()->to('/admin'); // CodeIgniter 4 redirect function } } // public function batch() // { // $session = \Config\Services::session(); // $login_id = $session->get('login_id'); // if ($login_id) { // $nparrots_model = new Nparrots_Model(); // $domainTable = 'domains'; // $whereDomain = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; // $orderBy = 'domain_name'; // $data['domain'] = $nparrots_model->getWhereResultOrderByAsc($domainTable, $whereDomain, $orderBy); // $batchTable = 'batches'; // $whereBatch = ['delete_status' => 'ACTIVE']; // $orderByBatch = 'batch_id'; // $data['batch'] = $nparrots_model->getWhereOrderbyRow($batchTable, $whereBatch, $orderByBatch); // $batchTable = 'batches'; // $whereBatch = ['delete_status' => 'ACTIVE', 'institution_id' => '0']; // $orderByBatch = 'batch_id'; // $batchRes = $nparrots_model->getWhereOrderbyRow($batchTable, $whereBatch, $orderByBatch); // if ($batchRes) { // $batchName = substr($batchRes->batch_name, -4); // $batchNumber = $batchName + 1; // $data['batch_id'] = 'NP000' . $batchNumber; // } else { // $data['batch_id'] = 'NP0001'; // } // echo view('admin/batch_form', $data); // } else { // return redirect()->to('/admin'); // } // } public function batch() { $login_id = session()->get('login_id'); if ($login_id) { $model = new Batch_Model(); $DomainTable = 'domains'; $whereDomain = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; $orderByDomain = 'domain_name'; $data['domain'] = $model->getWhereResultOrderbyAsc($DomainTable, $whereDomain, $orderByDomain); $BatchTable = 'batches'; $whereBatch = ['delete_status' => 'ACTIVE']; $orderByBatch = 'batch_id'; $data['batch'] = $model->getWhereOrderbyRow($BatchTable, $whereBatch, $orderByBatch); $BatchTable = 'batches'; $whereBatchInstitution = ['delete_status' => 'ACTIVE', 'institution_id' => '0']; $orderByBatchInstitution = 'batch_id'; $batchRes = $model->getWhereOrderbyRow($BatchTable, $whereBatchInstitution, $orderByBatchInstitution); if ($batchRes) { $batchName = substr($batchRes->batch_name, -4); $batchNumber = $batchName + 1; $data['batch_id'] = 'NP000' . $batchNumber; } else { $data['batch_id'] = 'NP0001'; } return view('admin/batch_form', $data); } else { return redirect()->to('/admin'); } } public function batch_list() { $login_id = session()->get('login_id'); // Use session() to access sessions if ($login_id) { return view('admin/batch_list'); // Use 'return' instead of 'load->view' } else { return redirect()->to('/admin'); } } public function faculty_added_batch_list() { // Get the session service $session = \Config\Services::session(); // Retrieve the 'login_id' from the session $login_id = $session->get('login_id'); if ($login_id) { return view('admin/faculty_added_batches'); } else { return redirect()->to('/admin'); } } public function editBatch() { $login_id = session('login_id'); if ($login_id) { $id = $this->request->uri->getSegment(2); $batch_table = 'batches'; $where = ['batch_id' => $id]; $model = new Nparrots_Model(); $get_det = $model->getWhereRow($batch_table, $where); $batch_domain_id = $get_det->domain_id; $batch_sub_domain_id = $get_det->sub_domain_id; $batch_fac_id = $get_det->faculty_id; $domain_table = 'domains'; $where_domain = ['delete_status' => 'ACTIVE']; $order_by = 'domain_name'; $data['domain'] = $model->getWhereResultOrderByAsc($domain_table, $where_domain, $order_by); $sub_domain_table = 'sub_domains'; $where_sub_domain = ['domain_id' => $batch_domain_id, 'delete_status' => 'ACTIVE']; $order_by = 'domain_id'; $data['sub_domain'] = $model->getWhereResultOrderByAsc($sub_domain_table, $where_sub_domain, $order_by); $facultymodel = new Faculty_Model(); $data['faculty'] = $facultymodel->getWhereAllFacultyList($batch_domain_id, $batch_sub_domain_id); $table = 'faculty_available_timings'; $where = ['faculty_id' => $batch_fac_id, 'delete_status' => 'ACTIVE']; $result = $model->getWhereResult($table, $where); $batch_table = 'batches'; $where_batch = ['batch_id' => $id, 'delete_status' => 'ACTIVE']; $order_by_batch = 'batch_name'; $data['batch'] = $model->getWhereResultOrderByAsc($batch_table, $where_batch, $order_by_batch); return view('admin/edit_batch', $data); } else { return redirect()->to('/admin'); } } public function delete_batch() { $table = 'batches'; $batch_id = $this->request->getVar('batch_id'); $model = new Batch_Model(); $batch_table = 'user_course_mapping'; $where_batch_ids = [ 'enroll_status' => 'ENROLLED', 'payment_status' => 'PAID', 'delete_status' => 'ACTIVE', ]; $builder = $this->db->table('user_course_mapping'); $builder->where($where_batch_ids); $builder->like('batch_ids', '%' . $batch_id . '%', 'both'); // Adjust this line $batch_result = $builder->get()->getResult(); if ($batch_result) { return $this->response->setJSON(['result' => 2]); } else { $where = ['batch_id' => $batch_id]; $data = ['delete_status' => 'INACTIVE']; $model->updateData($where, $table, $data); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0]); } } } // public function institution_registration() // { // $login_id = session()->get('login_id'); // if ($login_id) { // return view('admin/institutions_list'); // } else { // return redirect()->to('/admin'); // } // } public function feedback_list() { $session = session(); $loginId = $session->get('login_id'); if ($loginId) { return view('admin/feedback_list'); } else { return redirect()->to('/admin'); } } public function get_feedback_list() { $feedback_model = new Feedback_Model(); $result = $feedback_model->getFeedbackList(); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } public function view_feedback() { $session = session(); $login_id = $session->get('login_id'); if ($login_id) { $feedback_id = $this->request->uri->getSegment(2); $model = new Feedback_Model(); $data['feedback'] = $model->getWhereFeedback($feedback_id); $course_type = $model->checkFeedbackCourseType($feedback_id); if ($course_type) { if (property_exists($course_type, 'session_type')) { $session_type = json_decode($course_type->session_type); if ($session_type !== null) { if (in_array('Live', $session_type)) { $data['session_type'] = 'Live'; } else { $data['session_type'] = 'Recorded'; } } else { // Handle JSON decoding error. $data['session_type'] = 'Unknown'; } } else { // Handle the case where 'session_type' property doesn't exist in $course_type. $data['session_type'] = 'Not Available'; } } else { // Handle the case where $course_type is null or not found. $data['session_type'] = 'Data Not Found'; } return view('admin/feedback_details', $data); } else { // Handle the "else" condition to redirect to the feedback_details page. return redirect()->to('/admin/feedback_details'); // Adjust the URL as needed. } } public function delete_feedback() { $request = service('request'); // Assuming you are using the model 'Feedback_Model' $model = new Feedback_Model(); $feedback_id = $request->getPost('id'); $where = ['feedback_id' => $feedback_id]; $table = 'feedback'; $data = ['delete_status' => 'INACTIVE']; try { // Perform the deletion $result = $model->updateData($where, $table, $data); // Check if the deletion was successful if ($result) { // Deletion was successful $message = 'Feedback has been deleted.'; } else { // Deletion was not successful $message = 'Failed to delete feedback.'; } // Return a response with the message return $this->response->setJSON(['message' => $message]); } catch (\Exception $e) { log_message('error', 'Database error: ' . $e->getMessage()); // Handle the error gracefully or return an appropriate error response. } } public function get_sub_domain_courses() { // Get the request data $request = $this->request->getPost(); $nparrots_model = new Nparrots_Model(); $table = 'courses'; $domainId = $this->request->getPost('domain_id'); $createdBy = session()->get('login_id'); $where = ['domain_id' => $domainId, 'created_by' => $createdBy, 'delete_status' => 'ACTIVE']; $orderBy = 'course_id'; $result = $nparrots_model->getWhereResultOrderBy($table, $where, $orderBy); // Construct the response $response = [ 'result' => 1, // You can check if the query was successful or not 'data' => $result, // Use the result of your query here ]; return $this->response->setJSON($response); } public function add_domain() { $request = 'request'(); $response = 'response'(); { $request = service('request'); $response = service('response'); $sylubus_Model = new Syllabus_Model(); $domainName = ucfirst($request->getPost('domain_name')); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $table = 'domains'; $loginId = $request->getPost('login_id'); $userTypeId = $request->getPost('user_type_id'); $where = ['delete_status' => 'ACTIVE', 'created_by' => $loginId]; $categories = $sylubus_Model->get_where_result($table, $where); $array = []; $exists = []; $data = [ 'domain_name' => $domainName, 'delete_status' => 'ACTIVE', 'created_by' => $loginId, 'user_type_id' => $userTypeId, 'created_at' => $createdAt, ]; foreach ($categories as $category) { $array[] = strtolower($category->domain_name); } if (in_array(strtolower($domainName), $array)) { return $response->setJSON([ 'result' => 2, 'message' => 'Category already exists', ]); } else { $result = $sylubus_Model->set($data)->insert_data($table, $data); if ($result) { return $response->setJSON([ 'result' => 1, 'message' => 'Category added successfully', ]); } else { return $response->setJSON([ 'result' => 0, 'message' => 'Something went wrong.. try again', ]); } } } } public function get_sub_domain() { $id = $this->request->getPost('domain_id'); $subdomainTable = 'sub_domains'; $whereSubdomain = ['domain_id' => $id, 'delete_status' => 'ACTIVE']; $orderBy = 'sub_domain'; $nparrotsModel = new Master_Model(); $result = $nparrotsModel->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 get_subject_wise_syllabus_list($sub_domain_id) { $Model = new Nparrots_Model(); $result = $Model->getSubjectWiseSyllabusList($sub_domain_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0]); } } public function update_domain() { $domain_id = $this->request->getPost('domain_id'); $domain_name = $this->request->getPost('domain_name'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updated_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'); $courseModel = new Course_Model(); $table = 'domains'; $where_domain = ['domain_id' => $domain_id]; $domain_data = $courseModel->getWhereRow($table, $where_domain); $where_dom = $domain_data->domain_name; $where = ['delete_status' => 'ACTIVE', 'domain_name !=' => $where_dom]; $domains = $courseModel->getWhereResult($table, $where); $array = []; foreach ($domains as $value) { array_push($array, strtolower($value->domain_name)); } if (in_array(strtolower($domain_name), $array)) { return $this->response->setJSON(['result' => 2, 'message' => "Category already exists"]); } else { $where_id = ['domain_id' => $domain_id]; $data = [ 'domain_name' => ucfirst($domain_name), 'updated_by' => $login_id, 'updated_at' => $updated_at, ]; $result = $courseModel->update_Data($where_id, $table, $data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => "Updated successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Failed to update. Try again"]); } } } public function delete_domain() { $table = 'domains'; // $domain_id = $this->request->getPost('domain_id'); $domain_id = $this->request->getPost('domain_id'); $where = ['domain_id' => $domain_id]; $data = ['delete_status' => 'INACTIVE']; $courseModel = new Course_Model(); $result = $courseModel->updateData($where, $table, $data); if ($courseModel->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0]); } } public function add_sub_domain() { $nparrotsModel = new Master_Model(); // Instantiate your model $domain_id = $this->request->getPost('domain_id'); $sub_domain = ucfirst($this->request->getPost('sub_domain')); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $table = 'sub_domains'; $login_id = $this->request->getPost('login_id'); $user_type_id = $this->request->getPost('user_type_id'); $where = ['domain_id' => $domain_id, 'delete_status' => 'ACTIVE', 'created_by' => $login_id]; $categories = $nparrotsModel->getWhereResult($table, $where); $array = []; foreach ($categories as $value) { array_push($array, strtolower($value->sub_domain)); } if (in_array(strtolower($sub_domain), $array)) { return $this->response->setJSON(['result' => 2, 'message' => 'Sub Category already exists']); } else { $data = [ 'domain_id' => $domain_id, 'sub_domain' => $sub_domain, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'user_type_id' => $user_type_id, 'created_at' => $created_at ]; $result = $nparrotsModel->insertData($table, $data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Sub Category added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong.. try again']); } } } public function getSubCategoriesList() { $nparrotsModel = new Master_Model(); // Instantiate your model $result = $nparrotsModel->getSubCategoriesList(); $response = []; if ($result) { $response['sub_categories_list'] = $result; $response['result'] = 1; } else { $response['result'] = 0; } return $this->response->setJSON($response); } public function update_sub_domain() { $nparrotsModel = new Master_Model(); $subDomainId = $this->request->getPost('sub_domain_id'); $subDomain = $this->request->getPost('sub_domain'); $domainId = $this->request->getPost('domain_id'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedAt = $date->format('Y-m-d H:i:s'); $loginId = $this->request->getPost('login_id'); $table = 'sub_domains'; $whereDomain = ['sub_domain_id' => $subDomainId]; $domainData = $nparrotsModel->getWhere_Row($table, $whereDomain); // Check if the new subdomain already exists $whereSubdomain = ['sub_domain' => $subDomain, 'delete_status' => 'ACTIVE']; $existingSubdomain = $nparrotsModel->getWhere_Roww($table, $whereSubdomain); if ($existingSubdomain && $existingSubdomain->sub_domain_id != $subDomainId) { return $this->response->setJSON(['result' => 2, 'message' => 'Subdomain already exists']); } // Update the subdomain $where = ['sub_domain_id' => $subDomainId]; $data = [ 'domain_id' => $domainId, 'sub_domain' => $subDomain, 'updated_by' => $loginId, 'updated_at' => $updatedAt, ]; $result = $nparrotsModel->update_Data($where, $table, $data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { // Log or print an error message for debugging error_log("Update failed: " . $nparrotsModel->getErrorMessage()); // Replace with your error handling method return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update. Try again']); } } public function delete_sub_domain() { $nparrotsModel = new Master_Model(); $table = 'sub_domains'; $subDomainId = $this->request->getPost('sub_domain_id'); $where = ['sub_domain_id' => $subDomainId]; $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]); } } public function add_syllabus() { $nparrotsModel = new Master_Model(); $login_id = $this->request->getPost('login_id'); $user_type_id = $this->request->getPost('user_type_id'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $sub_category = $this->request->getPost('sub_category'); $chapter_name = $this->request->getPost('chapter_name'); $syllabus_data = [ 'sub_domain_id' => $sub_category, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'user_type_id' => $user_type_id, 'created_at' => $created_at ]; $table = 'syllabus'; $i = 0; $j = 0; $k = 0; foreach ($chapter_name as $chapters) { $chapter_table = 'syllabus_chapter'; $where = [ 'sub_domain_id' => $sub_category, 'chapter_name' => $chapters, 'delete_status' => 'ACTIVE', 'created_by' => $login_id ]; $chapter_result = $nparrotsModel->getWhereRow($chapter_table, $where); if ($chapter_result) { $i = $i + 1; } } $count = count($chapter_name) - 1; while ($j <= $count) { $countCopy = $count; while ($countCopy >= 0) { if ($countCopy != $j) { if ($chapter_name[$j] == $chapter_name[$countCopy]) { $k = $k + 1; } } $countCopy = $countCopy - 1; } $j = $j + 1; } if ($i > 0) { return $this->response->setJSON(['result' => 0, 'message' => 'Chapter name already exists']); } else if ($k >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'Chapter names are duplicated']); } else { $result = $nparrotsModel->insertData($table, $syllabus_data, true); if ($result) { foreach ($chapter_name as $key => $value) { $chapter_data = [ 'syllabus_id' => $result, 'sub_domain_id' => $sub_category, 'chapter_name' => $chapter_name[$key], 'created_by' => $login_id, 'user_type_id' => $user_type_id, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $chapter_table = 'syllabus_chapter'; $chapter_result = $nparrotsModel->insertData($chapter_table, $chapter_data); if (!$chapter_result) { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong while inserting chapters...']); } } return $this->response->setJSON(['result' => 1, 'message' => 'Added Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong while inserting syllabus...']); } } } public function get_syllabus_list() { $sylubus_Model = new Syllabus_Model(); $data = $sylubus_Model->get_syllabus_list(); // Implement this method in your model return $this->response->setJSON($data); } public function edit_syllabus_details() { $chapter_id = $this->request->getPost('id'); $nparrotsModel = new Master_Model(); $where = [ 'chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE', 'approval_status' => 'APPROVED' ]; $table = 'subject_materials'; $material = $nparrotsModel->getWhereRow($table, $where); $j = 0; if ($material) { $j = $j + 1; } $where_training = ['delete_status' => 'ACTIVE']; $training_table = 'training_plans'; $training_plans = $nparrotsModel->getWhereResult($training_table, $where_training); $i = 0; foreach ($training_plans as $plan) { $chapter_ids = json_decode($plan->chapter_ids); foreach ($chapter_ids as $id) { if ($id == $chapter_id) { $i = $i + 1; } } } if ($j >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'You cannot edit, material is added to this syllabus']); } elseif ($i >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'You cannot edit, training plan is added to this syllabus']); } else { $result = $nparrotsModel->getSyllabusDetails($chapter_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong...']); } } } public function edit_faculty_details() { $chapter_id = $this->request->getPost('id'); $nparrotsModel = new Master_Model(); $where = [ 'chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE', 'approval_status' => 'APPROVED' ]; $table = 'subject_materials'; $material = $nparrotsModel->getWhereRow($table, $where); $j = 0; if ($material) { $j = $j + 1; } $where_training = ['delete_status' => 'ACTIVE']; $training_table = 'training_plans'; $training_plans = $nparrotsModel->getWhereResult($training_table, $where_training); $i = 0; foreach ($training_plans as $plan) { $chapter_ids = json_decode($plan->chapter_ids); foreach ($chapter_ids as $id) { if ($id == $chapter_id) { $i = $i + 1; } } } if ($j >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'You cannot edit, material is added to this syllabus']); } elseif ($i >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'You cannot edit, training plan is added to this syllabus']); } else { $result = $nparrotsModel->getSyllabusDetails($chapter_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong...']); } } } public function update_syllabus() { $login_id = $this->request->getPost('login_id'); $nparrotsModel = new Master_Model(); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $syllabus_id = $this->request->getPost('syllabus_id'); $chapter_id = $this->request->getPost('chapter_id'); $chapter_name = $this->request->getPost('chapter_name'); $sub_category = $this->request->getPost('sub_category'); if (!empty($chapter_name)) { $i = 0; $j = 0; $k = 0; foreach ($chapter_name as $chapters) { $chapter_table = 'syllabus_chapter'; $where = [ 'sub_domain_id' => $sub_category, 'chapter_name' => $chapters, 'delete_status' => 'ACTIVE', 'chapter_id !=' => $chapter_id, ]; $chapter_result = $nparrotsModel->getWhereRow($chapter_table, $where); if ($chapter_result) { if ($syllabus_id != $chapter_result->syllabus_id) { $i = $i + 1; } } } $count = count($chapter_name) - 1; while ($j <= $count) { while ($count >= 0) { if ($count != $j) { if ($chapter_name[$j] == $chapter_name[$count]) { $k = $k + 1; } } $count = $count - 1; } $j = $j + 1; } if ($i > 0) { return $this->response->setJSON(['result' => 0, 'message' => 'Chapter name already exists']); } elseif ($k >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'Chapter names are duplicated']); } else { $where = ['chapter_id' => $chapter_id]; $chapter_table = 'syllabus_chapter'; $delete_chapter = $nparrotsModel->deleteRecord($chapter_table, $where); if ($delete_chapter) { foreach ($chapter_name as $key => $value) { $chapter_data = [ 'syllabus_id' => $syllabus_id, 'sub_domain_id' => $sub_category, 'chapter_name' => $chapter_name[$key], 'updated_by' => $login_id, 'updated_at' => $updated_at, 'created_at' => $updated_at, 'created_by' => $login_id, ]; $chapter_result = $nparrotsModel->insertData($chapter_table, $chapter_data); } if ($chapter_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' => 'Something went wrong...']); } } } else { return $this->response->setJSON(['result' => 2, 'message' => 'Please enter the chapter name']); } } public function check_subcategory_course_exists() { $sub_domain_id = $this->request->getPost('sub_domain_id'); $login_id = session()->get('login_id'); $user_type_id = session()->get('user_type_id'); $courseTable = 'courses'; $whereDomain = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; $nparrotsModel = new Master_Model(); $result = $nparrotsModel->getWhereResult($courseTable, $whereDomain); $array = []; if ($result) { foreach ($result as $val) { $subDomainArray = json_decode($val->sub_domain_id); // Check if $subDomainArray is valid and iterable if (is_array($subDomainArray)) { foreach ($subDomainArray as $val_1) { $array[] = $val_1; } } } if (in_array($sub_domain_id, $array)) { return json_encode(['result' => 1, 'message' => 'Course has been added to this category. You cannot delete this category']); } else { return json_encode(['result' => 0, 'message' => '']); } } else { return json_encode(['result' => 0, 'message' => 'No results found']); // Handle no results as needed } } public function getDomainSubdomainAdmin() { $login_id = session('login_id'); // Access session data using the session() function. $domain_id = $this->request->getPost('domain_id'); $nparrotsModel = new Master_Model(); $where_domain = ['delete_status' => 'ACTIVE', 'domain_id' => $domain_id]; $order_by = 'sub_domain'; $domain_table = 'sub_domains'; // Use the Query Builder to fetch data. $result = $nparrotsModel->get_Where_Result_OrderByAsc($domain_table, $where_domain, $order_by); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_topics_chapters() { $session = session(); $login_id = $session->get('faculty_login_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $Model = new Master_Model(); // Adjust the model namespace and name accordingly $result = $Model->getTopicsChapters($sub_domain_id, $login_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function getTopicsListAdmin() { $session = session(); $login_id = $session->get('login_id'); $nparrotsModel = new Master_Model(); // Adjust the model namespace and name accordingly $result = $nparrotsModel->getTopicsListAdmin($login_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } public function getAdminChapterWiseTopics() { $login_id = session()->get('login_id'); $chapter_id = $this->request->uri->getSegment(2); $table = 'topics'; // Replace with your actual table name $where = ['chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE', 'created_by' => $login_id]; // print_r($where); $Model = new Nparrots_Model(); $result = $Model->getWhereResult($table, $where); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } public function editTopics() { $topic_id = $this->request->getPost('topic_id'); $where = ['topic_id' => $topic_id, 'delete_status' => 'ACTIVE']; $table = 'topics'; // Load the model using CodeIgniter 4's model() method $Model = new Nparrots_Model(); $result = $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 updateTopics() { $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'); $model = new Nparrots_Model(); $where = array('delete_status' => 'ACTIVE', 'sub_domain_id' => 344); $table = 'topics'; $result = $model->getWhereResult($table, $where); $i = 0; $j = 0; $k = 0; if (is_array($topic_name) && !empty($topic_name)) { foreach ($topic_name as $val) { $topic_table = 'topics'; $where = array('sub_domain_id' => $sub_domain_id, 'topic_name' => htmlspecialchars($val), 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'chapter_id' => $chapter_id); $chapter_result = $model->getWhereRow($topic_table, $where); if ($chapter_result) { if ($chapter_result->topic_id != $topic_id) { $i = $i + 1; } } } } if (is_array($topic_name)) { $count = count($topic_name) - 1; $j = 0; $k = 0; while ($j <= $count) { $countCopy = $count; // Make a copy of $count to use inside the inner loop while ($countCopy >= 0) { if ($countCopy !== $j) { if ($topic_name[$j] === $topic_name[$countCopy]) { $k++; } } $countCopy--; } $j++; } // Now $k contains the count of duplicate values in the array. } else { // Handle the case where $topic_name is not an array } if ($i > 0) { echo json_encode(array('result' => 0, 'message' => 'Topic name already exists')); } else if ($k >= 1) { echo json_encode(array('result' => 0, 'message' => 'Topic names are duplicated')); } else { $table = 'topics'; $where = array('topic_id' => $topic_id); $result = $model->deleteData($table, $where); if (is_array($topic_name)) { foreach ($topic_name as $val) { $chapter_id = $this->request->getPost('chapter'); $data = array( 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'topic_name' => $val, // Define $val within this loop '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 = $model->insertData($table, $data); } if ($result) { echo json_encode(array('result' => 1, 'message' => 'Updated successfully')); } else { echo json_encode(array('result' => 0, 'message' => 'Something went wrong..')); } } } } public function deleteTopics() { $topic_id = $this->request->getPost('topic_id'); $where = ['topic_id' => $topic_id]; $data = ['delete_status' => 'INACTIVE']; $table = 'topics'; // Load the model (assuming Nparrots_Model is your model class) $model = new Nparrots_Model(); $result = $model->updateData($where, $table, $data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } public function addChapterTopics() { helper('date'); $Model = new Master_Model(); // Adjust the model namespace and name accordingly $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'); $where = ['delete_status' => 'ACTIVE', 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id]; // $timezone = 'Asia/Kolkata'; // $date = date('Y-m-d H:i:s', $timezone); // $topic_name = $this->request->getPost('topic_name'); // // $created_at = $date->format('Y-m-d H:i:s'); // $created_at = $date; $timezone = 'Asia/Kolkata'; $datetime = new \DateTime('now', new \DateTimeZone($timezone)); // Create a DateTime object with the specified timezone $date = $datetime->format('Y-m-d H:i:s'); // Format the DateTime object $topic_name = $this->request->getPost('topic_name'); $created_at = $date; if (!is_array($topic_name)) { return $this->response->setJSON(['result' => 0, 'message' => 'Topic names should be provided as an array']); } $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 = $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 $this->response->setJSON(['result' => 0, 'message' => 'Topic names already exist']); } elseif ($k >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'Topic names are duplicated']); } else { $data = []; 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, 'created_by' => $login_id ]; } $result = $Model->insertData($table, $data); // Use insertBatch to insert multiple records if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong...']); } } } //add course // public function add_new_course_admin() // { // $session = session(); // Load the session service // $login_id = $session->get('login_id'); // Retrieve the 'login_id' from the session // $user_type_id = $session->get('user_type_id'); // Retrieve the 'user_type_id' from the session // if ($login_id) { // $nparrotsModel = new Master_Model(); // Load your model, replace with the actual model name // $table = 'domains'; // $where = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; // $order_by = 'domain_name'; // $data['categories'] = $nparrotsModel->getWhereResultOrderByAsc($table, $where, $order_by); // return view('admin/add_new_course_admin', $data); // Load the view with data // } else { // return redirect()->to('/'); // Redirect to the home page // } // } // public function get_sub_domain_courses() // { // // Get the request data // $request = $this->request->getPost(); // $Model = new Master_Model(); // $table = 'courses'; // $domainId = $this->request->getPost('domain_id'); // $createdBy = session()->get('login_id'); // $where = ['domain_id' => $domainId, 'created_by' => $createdBy, 'delete_status' => 'ACTIVE']; // $orderBy = 'course_id'; // $result = $Model->getWhereResultOrderBy($table, $where, $orderBy); // // Construct the response // $response = [ // 'result' => 1, // You can check if the query was successful or not // 'data' => $result, // Use the result of your query here // ]; // return $this->response->setJSON($response); // } public function check_category_course_existes() { // Define table names $domainTable = 'domains'; $courseTable = 'courses'; // Get domain_id from POST data and login_id from session $domain_id = $this->request->getPost('domain_id'); $login_id = session()->get('login_id'); // Define the conditions for checking if a course exists in the specified category $where_domain = [ 'domain_id' => $domain_id, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, ]; // Load your model $nparrotsModel = new Master_Model(); // Adjust the model name // Call the model method to check if a course exists in the category $result = $nparrotsModel->getWhereResult($courseTable, $where_domain); // Prepare and return the response as JSON if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Course has been added to this category. You cannot delete this category.']); } else { return $this->response->setJSON(['result' => 0, 'message' => '']); } } public function add_new_course() { $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'); $global_variable = $this->request->getPost('global_variable'); $domain_id = $this->request->getPost('domain_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); if ($sub_domain_id !== null) { // Proceed with the rest of your code $syllabus_table = 'syllabus'; $syllabus_data = [ 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'user_type_id' => $user_type_id, 'created_at' => $created_at, ]; $where_id = ['sub_domain_id' => $sub_domain_id]; $nparrotsModel = new addnewcoursemodel(); $syllabus = $nparrotsModel->getWhereRow($syllabus_table, $where_id); // Set $syllabus to null if there is no match. if (!$syllabus) { $syllabus = null; } else { $syllabus_result = $nparrotsModel->insertData($syllabus_table, $syllabus_data); if ($syllabus_result) { $chapter_table = 'syllabus_chapter'; $topic_table = 'topics'; for ($i = 0; $i <= $global_variable; $i++) { $chapter = $this->request->getPost('chapter_name' . $i); foreach ($chapter as $key => $val) { $chapter_data = [ 'syllabus_id' => $syllabus_result, 'sub_domain_id' => $sub_domain_id, 'chapter_name' => $val, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, 'created_by' => $login_id, 'user_type_id' => $user_type_id, ]; $chapter_result = $nparrotsModel->insert_data($chapter_table, $chapter_data); if ($chapter_result) { $topics = $this->request->getPost('topic' . $i); foreach ($topics as $key1 => $value1) { $topic_data = [ 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'chapter_id' => $chapter_result, 'topic_name' => $value1, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, 'created_by' => $login_id, 'user_type_id' => $user_type_id, ]; $topic_result = $nparrotsModel->insert_course($topic_table, $topic_data); } } } } } echo json_encode(['result' => 1, 'message' => "Syllabus added successfully"]); } } } public function faculty_details() { $session = session(); $login_id = $session->get('login_id'); if ($login_id) { $faculty_model = new Faculty_Model(); // Replace with your actual model class $result = $faculty_model->getFacultiesDetails(); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } else { return redirect()->to('/admin'); } } // public function delete_faculty_details() // { // $faculty_model= new Faculty_Model(); // $id = $this->request->getPost('id'); // $result = $faculty_model->deleteFaculty($id); // if ($result) { // // Send a success response // return $this->response->setJSON(['result' => 1]); // } else { // // Send an error response // return $this->response->setJSON(['result' => 0]); // } // } public function delete_faculty_details() { $id = $this->request->getPost('id'); $table = 'login'; $where = ['login_id' => $id]; $data = ['delete_status' => 'INACTIVE']; $faculty_model = new Faculty_Model(); $result = $faculty_model->updateData($where, $table, $data); if ($result) { $facultyTable = 'faculty_registration'; $facultyResult = $faculty_model->updateData($where, $facultyTable, $data); if ($facultyResult) { $timingsTable = 'faculty_available_timings'; $whereTiming = ['faculty_id' => $id]; $facultyResult = $faculty_model->updateData($whereTiming, $timingsTable, $data); $subjectTable = 'faculty_subject_mapping'; $whereFaculty = ['login_id' => $id]; $deleteResult = $faculty_model->updateData($whereFaculty, $subjectTable, $data); $emailResult = $faculty_model->getWhereRow($table, $where); // $email = $emailResult->email; // $fullName = $emailResult->username; if ($emailResult !== null) { $email = $emailResult->email; $fullName = $emailResult->username; if ($faculty_model->affectedRows() > 0) { $href = base_url(); // $href = 'http://localhost/np/'; $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/images/all_logo.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;"/>'; $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;">Account Information</h3>'; $emailContent .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $fullName . ', Your account has been deleted.</p>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</body>'; $email = new Email(); $email->setFrom('healthcare@medusyspty.com', 'Nparrots'); $email->setTo($emailResult->email); $email->setSubject('Faculty Account Deactivate'); $email->setMessage($emailContent); $email->send(); } else { // Handle the case when no matching record is found, e.g., return an error message return $this->response->setJSON(['result' => 0, 'error' => 'No matching record found']); } return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } else { return $this->response->setJSON(['result' => 0]); } } else { return $this->response->setJSON(['result' => 0]); } } // public function approve_faculty_subjects() // { // $mappingId = $this->request->getPost('mapping_id'); // $loginId = $this->request->getPost('id'); // $faculty_model = new Faculty_Model(); // Replace with your actual model class // $result = $faculty_model->getApprovalSubjects($mappingId, $loginId); // if ($result) { // return $this->response->setJSON(['result' => 1, 'message' => $result]); // } else { // return $this->response->setJSON(['result' => 0]); // } // } public function approve_faculty_subjects() { $mappingId = $this->request->getPost('mapping_id'); $loginId = $this->request->getPost('id'); $facultyModel = new Faculty_Model(); $result = $facultyModel->getApprovalSubjects($mappingId, $loginId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function approve_faculty() { $nparrotsModel = new Master_Model(); $loginId = session()->get('login_id'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedAt = $date->format('Y-m-d H:i:s'); $id = $this->request->getPost('id'); $userTypeId = $this->request->getPost('user_type_id'); $mappingId = $this->request->getPost('mapping_id'); $where = ['login_id' => $id, 'delete_status' => 'ACTIVE']; $table = 'login'; $emailResult = $nparrotsModel->getWhereRow($table, $where); if ($emailResult->approval_status == 'NOT_APPROVED' && $emailResult->return_status == 'NOT_RETURNED') { $emailSubject = 'Faculty Password'; $emailTitle = 'Password Information'; } elseif ($emailResult->approval_status == 'APPROVED' && $emailResult->return_status == 'RETURNED') { $emailSubject = 'Faculty Approval'; $emailTitle = 'Faculty Approval'; } else { $emailSubject = 'Faculty Password'; $emailTitle = 'Password Information'; } $whereSubject = ['mapping_id' => $mappingId]; $subjectTable = 'faculty_subject_mapping'; $data = ['approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; $subjectsApprove = $nparrotsModel->UpdateData($subjectTable, $data, $whereSubject); if ($this->db->affectedRows() > 0) { $where = ['login_id' => $id, 'delete_status' => 'ACTIVE']; $table = 'login'; $returnStatus = $nparrotsModel->UpdateData($table, $data, $where); $emailResult = $nparrotsModel->getWhereRow($table, $where); $email = $emailResult->email; $userName = $emailResult->username; $subDomainId = $this->request->getPost('sub_domain_id'); $subDomain = $nparrotsModel->approvedSubjects($subDomainId); $subArray = []; foreach ($subDomain as $value) { array_push($subArray, $value->sub_domain); } $subDomains = implode(',', $subArray); $whereSubId = ['mapping_id' => $mappingId]; $subIdData = ['sub_domain_id' => json_encode($subDomainId), 'updated_at' => $updatedAt]; $updateSubId = $nparrotsModel->UpdateData($subjectTable, $subIdData, $whereSubId); if ($this->db->affectedRows() > 0) { $timingsTable = 'faculty_available_timings'; $availableType = $this->request->getPost('available_type'); if ($availableType == 'timings') { $timeIds = $this->request->getPost('course_type'); foreach ($timeIds as $timeId) { $whereTimings = ['time_id' => $timeId]; $timingData = ['subject_id' => json_encode($subDomainId), 'approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; $nparrotsModel->UpdateData($timingsTable, $timingData, $whereTimings); } } else { $courseType = $this->request->getPost('course_type'); $timeIds = $this->request->getPost('time_id'); foreach ($timeIds as $timeId) { $whereTimings = ['time_id' => $timeId]; $timingData = ['subject_id' => json_encode($subDomainId), 'approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; $nparrotsModel->UpdateData($timingsTable, $timingData, $whereTimings); } } $currentTime = time(); $time1 = md5($currentTime); $string = substr($time1, 0, 10); $password = strtoupper($string); $passwordData = ['password' => md5($password)]; if ($emailResult->password == "") { $passwordResult = $nparrotsModel->UpdateData($table, $passwordData, $where); $emailContents = '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $userName . ', Your Registration for subjects ' . $subDomains . ' has been Approved and your password is ' . $password . '</p>'; } else { $emailContents = '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $userName . ', Your Registration for subjects ' . $subDomains . ' has been Approved </p>'; } $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($email); $emailService->setSubject($emailSubject); $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/images/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;"/>'; $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;">' . $emailTitle . '</h3>'; $emailContent .= $emailContents; $emailContent .= '<p style="font-size:16px;padding-bottom:10px;text-align:center;padding-top:20px;"><a href="' . $href . 'faculty' . '" style="color:#fff;padding:10px 30px;background:#a6d039;" style="color:#fff;padding:10px 30px;background:#a6d039;">Click here to login to AMCAD</a></p>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</body>'; $emailService->setMessage($emailContent); if ($emailService->send()) { return $this->response->setJSON(['result' => 1, 'message' => 'Approved Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Error sending email']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function add_returned_comment() { $login_id = session('login_id'); $mapping_id = $this->request->getPost('mapping_id'); if ($login_id) { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $faculty_id = $this->request->getPost('faculty_id'); $comment = $this->request->getPost('comment'); $feedback_model = new Feedback_Model(); $where = ['login_id' => $faculty_id, 'delete_status' => 'ACTIVE']; $login_table = 'login'; $comment_data = ['return_status' => 'RETURNED']; $result = $feedback_model->updateData1($where, $login_table, $comment_data); $where_mapping = ['mapping_id' => $mapping_id]; $mapping_table = 'faculty_subject_mapping'; $mapping_data = ['approval_status' => 'NOT_APPROVED', 'return_status' => 'RETURNED']; $update_approve = $feedback_model->updateData2($where_mapping, $mapping_table, $mapping_data); $email_result = $feedback_model->getWhereRow1($login_table, $where); if ($email_result !== null) { $email = $email_result->email; $full_name = $email_result->username; 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;">Email Confirmation</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $email_result->username . '</p>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">' . $comment . '</p>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; // Example using CodeIgniter 4 Email library: $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($email_result->email); $emailService->setSubject('Faculty Return'); $emailService->setMessage($email_content); if ($emailService->send()) { $comment_table = 'returned_faculty_comments'; $comment_data = [ 'faculty_id' => $faculty_id, 'comment' => $comment, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, 'created_by' => $login_id ]; $comment_result = $feedback_model->insertData1($comment_table, $comment_data); if ($comment_result) { return $this->response->setJSON(['result' => 1, 'message' => 'Returned Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => "Email sending failed"]); } } } else { return redirect()->to('/admin'); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'No email result found']); // Handle the case where no result was found } } public function view_faculty_details($id) { $session = session(); $login_id = $session->get('login_id'); if ($login_id) { $faculty_model = new Faculty_Model(); $data['faculty_details'] = $faculty_model->getFacultyDetails($id); $data['sub_domain'] = $faculty_model->getSubDomains($id); $timingTable = 'faculty_available_timings'; $whereTiming = ['faculty_id' => $id, 'delete_status' => 'ACTIVE']; $data['timing_details'] = $faculty_model->getWhereResult($timingTable, $whereTiming); return view('admin/faculty_details', $data); } else { return redirect()->to('/admin'); } } public function request_details() { $user_type_id = session()->get('user_type_id'); $login_id = session()->get('login_id'); $faculty_model = new Faculty_Model(); // Replace with your actual model class $result = $faculty_model->getRequestList($user_type_id, $login_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function check_material_exist() { $mappingId = $this->request->getPost('id'); $loginId = $this->request->getPost('login_id'); $facultyModel = new Faculty_Model(); $table = 'faculty_subject_mapping'; $where = ['mapping_id' => $mappingId, 'delete_status' => 'ACTIVE']; $result = $facultyModel->getWhereRow($table, $where); if ($result && $result->approval_status === 'APPROVED') { $subdomainResult = $facultyModel->getSubjects($mappingId); $i = 0; foreach ($subdomainResult as $value) { $table = 'subject_materials'; $where = ['sub_domain_id' => $value->sub_domain_id, 'created_by' => $loginId]; $materialResult = $facultyModel->getWhereRow($table, $where); if ($materialResult) { $i++; } } if ($i >= 1) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } return $this->response->setJSON(['result' => 0]); } public function delete_request() { $facultyModel = new Faculty_Model(); $mappingId = $this->request->getPost('id'); $subdomainResult = $facultyModel->getSubjects($mappingId); $table = 'faculty_subject_mapping'; $where = ['mapping_id' => $mappingId, 'delete_status' => 'ACTIVE']; $data = ['delete_status' => 'INACTIVE']; $facultyModel->updateData($where, $table, $data); $db = db_connect(); // Get the database connection $email = \Config\Services::email(); $email->setTo('recipient@example.com'); if ($db->affectedRows() > 0) { $whereRequest = ['mapping_id' => $mappingId, 'delete_status' => 'INACTIVE']; $mappingResult = $facultyModel->getWhereRow($table, $whereRequest); $subDomainIds = json_decode($mappingResult->sub_domain_id); $whereTimings = ['faculty_id' => $mappingResult->login_id, 'subject_mapping_id' => $mappingResult->mapping_id]; $timingsTable = 'faculty_available_timings'; $facultyModel->updateData($whereTimings, $timingsTable, $data); foreach ($subDomainIds as $value) { $trainingTable = 'training_plans'; $trainingData = ['delete_status' => 'INACTIVE']; $whereTraining = ['sub_domain_id' => $value]; $facultyModel->updateData($whereTraining, $trainingTable, $trainingData); } $subArray = []; foreach ($subdomainResult as $val) { array_push($subArray, $val->sub_domain); } $subDomains = implode(', ', $subArray); $facultyTable = 'faculty_registration'; $whereFaculty = ['login_id' => $mappingResult->login_id]; $emailResult = $facultyModel->getWhereRow($facultyTable, $whereFaculty); $email = $emailResult->email; $fullName = $emailResult->fullname; $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/images/all_logo.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;"/>'; $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;">Request Information</h3>'; $emailContent .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $fullName . ', Your requests for subjects ' . $subDomains . ' has been deleted.</p>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</body>'; $email = \Config\Services::email(); $email->setTo('recipient@example.com'); $email->setSubject("Delete Request"); $email->setMessage($emailContent); if ($email->send()) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Email sending failed']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Update failed']); } } public function approve_request() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedAt = $date->format('Y-m-d H:i:s'); $loginId = $this->request->getPost('id'); $mappingId = $this->request->getPost('mapping_id'); $whereAddSub = ['mapping_id' => $mappingId, 'delete_status' => 'ACTIVE']; $tableAddSub = 'faculty_subject_mapping'; $data = ['approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; $faculty_model = new Faculty_Model(); // Replace with your actual model class $result = $faculty_model->updateData($whereAddSub, $tableAddSub, $data); if ($result) { $table = 'login'; $where = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; $emailResult = $faculty_model->getWhereRow($table, $where); if ($emailResult !== null) { $email = $emailResult->email; $userName = $emailResult->username; $subDomainId = $this->request->getPost('sub_domain_id'); $subDomain = $faculty_model->approvedSubjects($subDomainId); $subArray = []; foreach ($subDomain as $value) { array_push($subArray, $value->sub_domain); } $subDomains = implode(', ', $subArray); $whereSubId = ['mapping_id' => $mappingId]; $subIdData = ['sub_domain_id' => json_encode($subDomainId), 'updated_at' => $updatedAt]; $updateSubId = $faculty_model->updateData($whereSubId, $tableAddSub, $subIdData); if ($updateSubId) { $timingsTable = 'faculty_available_timings'; $availableType = $this->request->getPost('available_type'); if ($availableType == 'timings') { $timeIds = $this->request->getPost('course_type'); foreach ($timeIds as $timeId) { $whereTimings = ['time_id' => $timeId]; $timingData = ['subject_id' => json_encode($subDomainId), 'approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; $faculty_model->updateData($whereTimings, $timingsTable, $timingData); } } else { $timeIds = $this->request->getPost('time_id'); foreach ($timeIds as $timeId) { $whereTimings = ['time_id' => $timeId]; $timingData = ['subject_id' => json_encode($subDomainId), 'approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; $faculty_model->updateData($whereTimings, $timingsTable, $timingData); } } $whereRequest = ['mapping_id' => $mappingId, 'delete_status' => 'ACTIVE']; $requestTable = 'faculty_subject_mapping'; $mappingResult = $faculty_model->getWhereRow($requestTable, $whereRequest); $subDomainIds = json_decode($mappingResult->sub_domain_id); foreach ($subDomainIds as $value) { $trainingTable = 'training_plans'; $trainingData = ['return_status' => 'NOT_RETURNED']; $whereTraining = ['sub_domain_id' => $value]; $faculty_model->updateData($whereTraining, $trainingTable, $trainingData); } $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/images/all_logo.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;"/>'; $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;">Request Subject Approval</h3>'; $emailContent .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $userName . ', Your Request for teaching additional subjects ' . $subDomains . ' has been approved.</p>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</body>'; $phpMailer = new PHPMailer(true); try { $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($email); $phpMailer->Subject = "Subject Approval"; $phpMailer->Body = $emailContent; $phpMailer->send(); return $this->response->setJSON(['result' => 1, 'message' => 'Approved Successfully']); } catch (Exception $e) { return $this->response->setJSON(['result' => 0, 'error' => $e->getMessage()]); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'No matching record found for the specified faculty']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function returned_request_comment() { $loginId = session()->get('login_id'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $facultyId = $this->request->getPost('faculty_id'); $mappingId = $this->request->getPost('mapping_id'); $comment = $this->request->getPost('comment'); $whereRequest = ['mapping_id' => $mappingId, 'delete_status' => 'ACTIVE']; $requestTable = 'faculty_subject_mapping'; $commentData = ['return_status' => 'RETURNED', 'approval_status' => 'NOT_APPROVED']; $faculty_model = new Faculty_Model(); // Replace with your actual model class $result = $faculty_model->updateData($whereRequest, $requestTable, $commentData); if ($result) { $where = ['login_id' => $facultyId, 'delete_status' => 'ACTIVE']; $loginTable = 'login'; $emailResult = $faculty_model->getWhereRow($loginTable, $where); if ($emailResult !== null) { $email = $emailResult->email; $mappingResult = $faculty_model->getWhereRow($requestTable, $whereRequest); $subDomainIds = json_decode($mappingResult->sub_domain_id); $timingsTable = 'faculty_available_timings'; $whereTiming = ['faculty_id' => $facultyId, 'subject_mapping_id' => $mappingResult->mapping_id]; $faculty_model->updateData($whereTiming, $timingsTable, $commentData); foreach ($subDomainIds as $value) { $trainingTable = 'training_plans'; $trainingData = ['return_status' => 'RETURNED']; $whereTraining = ['sub_domain_id' => $value]; $faculty_model->updateData($whereTraining, $trainingTable, $trainingData); } $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/images/all_logo.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;"/>'; $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;">Request Subject Return</h3>'; $emailContent .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $emailResult->username . '</p>'; $emailContent .= '<p style="font-size:16px;padding-bottom:10px;">' . $comment . '</p>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</div>'; $emailContent .= '</body>'; $phpMailer = new PHPMailer(true); try { $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($email); $phpMailer->Subject = "Returning Subject Request"; $phpMailer->Body = $emailContent; $phpMailer->send(); $commentTable = 'returned_request_comments'; $commentData = [ 'faculty_id' => $facultyId, 'comment' => $comment, 'delete_status' => 'ACTIVE', 'created_at' => $createdAt, 'created_by' => $loginId, ]; $commentResult = $faculty_model->insertData($commentTable, $commentData); if ($commentResult) { return $this->response->setJSON(['result' => 1, 'message' => 'Returned Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } catch (\Exception $e) { return $this->response->setJSON(['result' => 0, 'message' => 'Email sending failed']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'No matching record found for the specified faculty']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function enrolledCourseDetails() { $userId = $this->request->getPost('user_id'); $faculty_model = new Faculty_Model(); // Replace with your actual model class $result = $faculty_model->getWhereEnrolledUsersSubdomains($userId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } // public function get_faculty() // { // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $domain_id = $this->request->getPost('domain_id'); // // Load the NparrotsModel // $faculty_model = new Faculty_Model(); // Replace with your actual model class // // Call the model method to retrieve faculty data // $result = $faculty_model->getWhereAllFacultyList($domain_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..']); // } // } // public function get_faculty() // { // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $domain_id = $this->request->getPost('domain_id'); // // Load the necessary model (assuming Faculty_Model exists) // $model = new Faculty_Model(); // $result = $model->getWhereAllFacultyList($domain_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..']); // } // } public function get_faculty() { $model = new Faculty_Model(); $sub_domain_id = $this->request->getPost('sub_domain_id'); $domain_id = $this->request->getPost('domain_id'); // Assuming that $this->nparrots_model is an instance of your model class $result = $model->getWhereAllFacultyList($domain_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..']); } } // public function get_not_enrolled_fac_timings() // { // $fac_id = $this->request->getPost('id'); // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $domain_id = $this->request->getPost('domain_id'); // $faculty_model = new Faculty_Model(); // Replace with your actual model class // $modelResult = $faculty_model->getNotEnrolledFacTimings($fac_id, $sub_domain_id, $domain_id); // if ($modelResult) { // // The model function returned a result // return $this->response->setJSON(['result' => 1, 'message' => $modelResult]); // } else { // // The model function did not return any result // return $this->response->setJSON(['result' => 0, 'message' => 'Timings Not Available For This Faculty!']); // } // } 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() // { // $fac_id = $this->request->getPost('id'); // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $domain_id = $this->request->getPost('domain_id'); // // Load your model through the model class // $Model = new Faculty_Model(); // $tableName = 'user_course_mapping'; // $result = $Model->getNotEnrolledFacTimings($fac_id, $sub_domain_id, $domain_id, $tableName); // 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_training_plan_duration() { $faculty_id = $this->request->getPost('faculty_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $domain_id = $this->request->getPost('domain_id'); $faculty_model = new Faculty_Model(); // Replace with your actual model class $result = $faculty_model->getTrainingPlanDuration($faculty_id, $sub_domain_id, $domain_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_all_batch_list() { $faculty_model = new Faculty_Model(); $result = $faculty_model->get_all_batch_list(); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0]); } } public function edit_batch() { $session = session(); $login_id = $session->get('login_id'); if ($login_id) { $id = $this->request->uri->getSegment(2); $batch_table = 'batches'; $where = ['batch_id' => $id]; $faculty_model = new Faculty_Model(); // Replace with your actual model class $get_det = $faculty_model->getWhereRow($batch_table, $where); $batch_domain_id = $get_det->domain_id; $batch_sub_domain_id = $get_det->sub_domain_id; $batch_fac_id = $get_det->faculty_id; $faculty_model = new Faculty_Model(); // Replace with your actual model class $data['domain'] = $faculty_model->where('delete_status', 'ACTIVE')->orderBy('domain_name')->findAll(); $faculty_model = new Faculty_Model(); // Replace with your actual model class $data['sub_domain'] = $faculty_model->where('domain_id', $batch_domain_id)->where('delete_status', 'ACTIVE')->orderBy('domain_id')->findAll(); $faculty_model = new Faculty_Model(); // Replace with your actual model class $data['faculty'] = $faculty_model->getWhereFacultyList($batch_domain_id, $batch_sub_domain_id); $faculty_model = new Faculty_Model(); // Replace with your actual model class $result = $faculty_model->where('faculty_id', $batch_fac_id)->where('delete_status', 'ACTIVE')->findAll(); $faculty_model = new Faculty_Model(); // Replace with your actual model class $data['batch'] = $faculty_model->where('batch_id', $id)->where('delete_status', 'ACTIVE')->orderBy('batch_name')->findAll(); return view('admin/edit_faculty_added_batch_list', $data); } else { return redirect()->to('/admin'); } } public function get_categories_list() { // Load the session library (if not autoloaded) $session = session(); $login_id = $session->get('login_id'); $table = 'domains'; $where = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; $orderBy = 'domain_name'; // Load the model (replace 'YourModel' with your actual model name) $content_model = new Content_Model(); $result = $content_model->getWhereResultOrderBy($table, $where, $orderBy); if ($result) { return json_encode(['categories_list' => $result, 'result' => 1]); } else { return json_encode(['result' => 0]); } } public function delete_course() { $table = 'courses'; $course_id = $this->request->getPost('course_id'); $where = ['course_id' => $course_id]; $data = ['delete_status' => 'INACTIVE']; $courseModel = new Course_Model(); $result = $courseModel->updateData($where, $table, $data); if ($courseModel->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0]); } } public function edit_course() { $session = session(); $login_id = $session->get('login_id'); if ($login_id) { $courseModel = new Course_Model(); // Adjust the model name as per your actual model $domain_table = 'domains'; $where_domain = ['delete_status' => 'ACTIVE']; $order_by = 'domain_name'; $data['domain'] = $courseModel->getWhereResultOrderByAsc($domain_table, $where_domain, $order_by); return view('admin/edit_course', $data); } else { return redirect()->to('/admin'); } } public function get_enrolled_users_details() { $loginId = session()->get('login_id'); $enrolled_model = new Enrolled_Model; if ($loginId) { $result = $enrolled_model->getEnrolledUsersDetails(); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 1, 'message' => 'No Data Found']); } } else { return redirect()->to('/admin'); } } public function delete_enrolled_user() { $userId = $this->request->getPost('id'); $whereLogin = ['login_id' => $userId, 'delete_status' => 'ACTIVE']; $loginTable = 'login'; $enrolled_model = new Enrolled_Model(); $emailResult = $enrolled_model->getWhereRow($loginTable, $whereLogin); if ($emailResult) { $email = $emailResult->email; $fullName = $emailResult->username; $data = ['delete_status' => 'INACTIVE']; $deleteLogin = $enrolled_model->updateData($whereLogin, $loginTable, $data); if ($this->db->affectedRows() > 0) { $registrationTable = 'user_registrations'; $deleteRegistration = $enrolled_model->updateData($whereLogin, $registrationTable, $data); if ($this->db->affectedRows() > 0) { $whereCourse = ['user_id' => $userId, 'delete_status' => 'ACTIVE']; $courseTable = 'user_course_mapping'; $deleteCourse = $enrolled_model->updateData($whereCourse, $courseTable, $data); $timingTable = 'user_available_timings'; $deleteTimings = $enrolled_model->updateData($whereCourse, $timingTable, $data); $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/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;">Account Information</h3>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $fullName . ', Your account has been deleted.</p>'; $content .= '</div>'; $content .= '</div>'; $content .= '</div>'; $content .= '</body>'; $emailService->setMessage($content); try { $emailService->send(); } catch (\Exception $e) { // Handle email sending error here } return $this->response->setJSON(['result' => 1, 'message' => 'Deleted Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'User not found']); } } public function approve_feedback() { $feedback_id = $this->request->getPost('id'); $where = ['feedback_id' => $feedback_id, 'delete_status' => 'ACTIVE']; $table = 'feedback'; $data = ['display_status' => 'DISPLAY']; $feedback_model = new Feedback_Model(); if ($feedback_model->updateData($where, $data)) { return $this->response->setJSON(['result' => 1, 'message' => 'Approved Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } public function return_feedback() { $feedback_id = $this->request->getPost('id'); $where = ['feedback_id' => $feedback_id, 'delete_status' => 'ACTIVE']; $table = 'feedback'; $data = ['display_status' => 'NOT_DISPLAY']; $feedback_model = new Feedback_Model(); if ($feedback_model->updateData($where, $data)) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } use ResponseTrait; public function get_domain_subdomain_admin() { $login_id = session()->get('login_id'); // Updated session access method // Retrieve the 'domain_id' from POST data $domain_id = $this->request->getPost('domain_id'); $where_domain = ['delete_status' => 'ACTIVE', 'domain_id' => $domain_id]; $orderBy = 'sub_domain'; $domain_table = 'sub_domains'; // Replace with your table name // Load the model (replace 'NparrotsModel' with your actual model name) $nparrots_model = new Nparrots_Model(); $result = $nparrots_model->getWhereResultOrderByAsc($domain_table, $where_domain, $orderBy); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function check_user_course_exists() { // Retrieve the 'course_id' from POST data $course_id = $this->request->getPost('course_id'); // Define the table name $course_table = 'user_course_mapping'; // Define the criteria for the where clause $where_domain = [ 'course_id' => $course_id, 'delete_status' => 'ACTIVE', 'payment_status' => 'PAID' ]; // Load the model (replace 'NparrotsModel' with your actual model name) $nparrots_model = new Nparrots_Model(); // Check if a record with the given criteria exists $result = $nparrots_model->getWhereResult($course_table, $where_domain); if ($result) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0, 'message' => '']); } } use ResponseTrait; public function get_all_faculty_added_batches() { $batch_model = new Batch_Model(); // Replace with your actual model class $result = $batch_model->get_all_faculty_added_batches(); if ($result) { return $this->respond($result, 200); // Respond with JSON data } else { return $this->fail(['result' => 0], 404); // Respond with a JSON error message and status code } } public function course_image_crop() { $data = $this->request->getPost('image'); list($type, $data) = explode(';', $data); list(, $data) = explode(',', $data); $data = base64_decode($data); $imageName = time().'course_image.png'; file_put_contents('public/course_images/'.$imageName, $data); echo json_encode(array('result'=>1,'message'=>$imageName)); } public function get_subject_chapters() { $subDomainId = $this->request->getPost('sub_domain_id'); $table = 'syllabus_chapter'; $where = ['sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE']; $content_model = new Content_Model(); $result = $content_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_notifications() { $nparrots_model = new Nparrots_Model(); $table = 'notification'; $where = ['delete_status' => 'ACTIVE', 'view_status' => 'NOT_VIEWED']; $count = $nparrots_model->getWhereResult($table, $where); $whereActive = ['delete_status' => 'ACTIVE']; $orderBy = 'created_at'; $notification = $nparrots_model->getWhereResultOrderBy($table, $whereActive, $orderBy); if ($notification) { return $this->response->setJSON(['result' => 1, 'count' => $count, 'notification' => $notification]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_chapter_topics() { $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' ]; $Content_Model1 = new Content_Model_1(); // Instantiate the model // Assuming you have a method called getChapterTopics in your model $result = $Content_Model1->getChapterTopics($chapter_id, $login_id); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_material_list_admin() { $loginId = session()->get('login_id'); $content_model = new Content_Model(); $result = $content_model->get_material_list_admin($loginId); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 1, 'message' => 'No Data Found']); } } public function add_course() { $coursemodel = new coursemodel1(); $login_id = $this->request->getPost('login_id'); $user_type_id = $this->request->getPost('user_type_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $domain_id = $this->request->getPost('domain_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $course_title = $this->request->getPost('course_title'); $language = $this->request->getPost('language'); $course_price = $this->request->getPost('course_price'); $description = $this->request->getPost('content'); $curriculum = $this->request->getPost('content1'); $instructor = $this->request->getPost('content2'); $duration = $this->request->getPost('duration'); $from_time = $this->request->getPost('from_time'); $to_time = $this->request->getPost('to_time'); if ($user_type_id == 4) { $partner_id = $this->request->getPost('partner_id'); $funder_id = $this->request->getPost('funder_id'); $cer_partner_id = $this->request->getPost('cer_partner_id'); } else { $partner_id = '0'; $funder_id = '0'; $cer_partner_id = '0'; } $available_type = ""; $course_type = $this->request->getPost('course_type'); if (is_array($course_type)) { foreach ($course_type as $courses) { if ($courses == 'live') { $available_type = $this->request->getPost('available_type'); } } $i = 0; if ($available_type == 'timings') { $i = 0; if ($from_time != '') { foreach ($from_time as $key => $value) { foreach ($from_time as $keys => $value) { if ($key != $keys) { $start_explode_colon = explode(':', $from_time[$key]); $start_explode_space = explode(' ', $start_explode_colon[1]); $end_totime_colon = explode(':', $to_time[$key]); $end_totime_space = explode(' ', $end_totime_colon[1]); $start_explode_colons = explode(':', $from_time[$keys]); $start_explode_spaces = explode(' ', $start_explode_colons[1]); $end_explode_colons = explode(':', $to_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])) { $i = $i + 1; } } } } } } } if (!$duration) { $duration = ''; } $video_files = ""; if ($this->request->getFile('course_demo_video')->isValid()) { $video_size = $this->request->getFile('course_demo_video')->getSize(); $video_document = $this->request->getFile('course_demo_video'); $target = 'course_videos/'; $target .= time() . $video_document->getClientName(); try { $video_document->move(WRITEPATH . 'uploads/' . $target); $video_files = $target; } catch (\CodeIgniter\HTTP\Exceptions\HTTPException $e) { return json_encode(array('result' => 0, 'message' => 'Error moving the video file: ' . $e->getMessage())); } } else { $video_files = ""; $video_size = 0; } $this->image = \Config\Services::image(); $course_image = ''; if ($this->request->getFile('course_image')->isValid()) { $courseImageDocument = $this->request->getFile('course_image'); $course_image = time() . $courseImageDocument->getClientName(); try { $courseImageDocument->move(WRITEPATH . 'uploads/course_images', $course_image); } catch (\CodeIgniter\HTTP\Exceptions\HTTPException $e) { return json_encode(array('result' => 0, 'message' => 'Error moving the course image: ' . $e->getMessage())); } } $course_cropped_image = $this->request->getPost('course_cropped_image'); if (($course_image != "") && ($course_cropped_image != "")) { $course_cropped_image = $this->request->getPost('course_cropped_image'); if ($course_image) { $course_image = $course_cropped_image; } } if ($i > 0) { return json_encode(array('result' => 0, 'message' => 'Timings are duplicated')); } elseif ($video_size > 50000000) { return json_encode(array('result' => 0, 'message' => 'Video size must not exceed above 50MB')); } else { $course_table = 'courses'; $course_data = [ 'domain_id' => $domain_id, 'sub_domain_id' => json_encode($sub_domain_id), 'course_title' => $course_title, 'course_image' => $course_image, 'course_demo_video' => $video_files, 'language' => $language, 'course_price' => $course_price, 'duration' => $duration, 'course_type' => json_encode($course_type), 'description' => $description, 'curriculam' => $curriculum, 'instructor' => $instructor, 'partner_id' => $partner_id, 'funder_id' => $funder_id, 'cer_partner_id' => $cer_partner_id, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'user_type_id' => $user_type_id, 'created_at' => $created_at ]; $where_course = array('delete_status' => 'ACTIVE', 'created_by' => $login_id); $check_course = $coursemodel->get_where_result($course_table, $where_course); $sub_id_count = 0; $course_title_count = 0; foreach ($check_course as $course) { if ($course->course_title == $course_title) { $course_title_count = 1; } } if ($course_title_count) { return json_encode(array('result' => 0, 'message' => 'Course title already exists')); } else { $result = $coursemodel->insert_data($course_table, $course_data); if ($result) { if ($available_type != "") { if ($available_type == "timings") { if ($from_time != '') { foreach ($from_time as $key => $value) { $course_timings = array( 'course_id' => $result, 'course_type' => json_encode($course_type), 'available_type' => $available_type, 'from_time' => $from_time[$key], 'to_time' => $to_time[$key], 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'created_at' => $created_at ); $timing_table = 'course_available_timings'; $time_result = $coursemodel->insert_data($timing_table, $course_timings); } if ($time_result) { return json_encode(array('result' => 1, 'message' => 'Course added successfully')); } } else { return json_encode(array('result' => 0, 'message' => 'Please add timings')); } } else if ($available_type == "full_day") { $course_timings = array( 'course_id' => $result, 'course_type' => json_encode($course_type), 'available_type' => $available_type, 'delete_status' => 'ACTIVE', 'created_by' => $login_id, 'created_at' => $created_at ); $timing_table = 'course_available_timings'; $time_result = $coursemodel->insert_data($timing_table, $course_timings); if ($time_result) { return json_encode(array('result' => 1, 'message' => 'Course added successfully')); } } else { return json_encode(array('result' => 0, 'message' => 'Please select available type')); } } else { return json_encode(array('result' => 1, 'message' => 'Course added successfully')); } } else { return json_encode(array('result' => 0, 'message' => "Something went wrong. Try again")); } } } } } // public function add_material_admin() // { // $session = \Config\Services::session(); // $login_id = $session->get('login_id'); // $topic_id = $this->request->getPost('topic_id'); // // Check if $topic_id is empty or null, and set a default value // if ($topic_id === null || $topic_id === '') { // // Handle the case where 'topic_id' is null or empty // // For example, set a default value or show an error message // $topic_id = 0; // You can set any default value you prefer // } // $table = 'subject_materials'; // $where = ['delete_status' => 'ACTIVE']; // $model = new contents12(); // Instantiate your model // $all_materials = $model->get_where_result($table, $where); // if ($all_materials) { // $order_by = 'material_id'; // $single_id = $model->get_where_orderby_row($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'); // $sub_domain_id = $this->request->getPost('sub_domain_id'); // // Check if $sub_domain_id is empty or null, and set a default value // if ($sub_domain_id === null || $sub_domain_id === '') { // // Handle the case where 'sub_domain_id' is null or empty // // For example, set a default value or show an error message // $sub_domain_id = 0; // You can set any default value you prefer // } // $chapter_id = $this->request->getPost('chapter'); // // Check if $chapter_id is empty or null, and set a default value // if ($chapter_id === null || $chapter_id === '') { // // Handle the case where 'chapter_id' is null or empty // // For example, set a default value or show an error message // $chapter_id = 0; // You can set any default value you prefer // } // // Check if domain_id is empty or null, and set a default value // $domain_id = $this->request->getPost('domain_id'); // if ($domain_id === null || $domain_id === '') { // // Handle the case where 'domain_id' is null or empty // // For example, set a default value or show an error message // $domain_id = 0; // You can set any default value you prefer // } // $domain_table = 'sub_domains'; // $where_domain = ['sub_domain_id' => $sub_domain_id]; // $subdomain = $model->get_where_row($domain_table, $where_domain); // $login_table = 'login'; // $where_id = ['login_id' => $login_id]; // $faculty_res = $model->get_whererow($login_table, $where_id); // // Load the Image service // $image = \Config\Services::image(); // // Define the configuration for resizing // $config = [ // 'image' => 'public/course_images/.jpg', // Replace with the path to your image // 'width' => 251, // Desired width for the resized image // 'height' => 166, // Desired height for the resized image // ]; // // Resize and save the image // if ($image->withFile($config['image'])->resize($config['width'], $config['height'])->save()) { // echo "Image was resized and saved successfully."; // } else { // echo "There was an error in resizing the image."; // } // // $vid_target = ""; // // $video_url = []; // $img_target = ''; // $img_url = []; // $pdf_target = ''; // $pdf_url = []; // // Ensure that $login_id is not null or empty before using it as 'created_by' // if ($login_id === null || $login_id === '') { // // Handle the case where 'login_id' is null or empty // // For example, set a default value or show an error message // $login_id = 0; // You can set any default value you prefer // } // $data = [ // 'material_count' => $material_count, // 'chapter_id' => $chapter_id, // 'topic_id' => $topic_id, // 'sub_domain_id' => $sub_domain_id, // 'domain_id' => $domain_id, // 'image' => $img_target, // 'pdf' => $pdf_target, // 'approval_status' => 'APPROVED', // 'return_status' => 'NOT_RETURNED', // 'delete_status' => 'ACTIVE', // 'created_by' => $login_id, // 'created_at' => $created_at, // ]; // // Rest of your code... // $result = $model->insert_data($table, $data); // if ($result) { // return json_encode(['result' => 1, 'message' => 'Material added successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something Went Wrong..']); // } // } public function add_material_admin() { $login_id = session()->get('login_id'); $topic_id = $this->request->getPost('topic_id'); $table = 'subject_materials'; $where = ['delete_status' => 'ACTIVE']; $model = new contents12(); $all_materials = $model->get_where_result($table, $where); if ($all_materials) { $order_by = 'material_id'; $single_id = $model->get_where_orderby_row($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'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $chapter_id = $this->request->getPost('chapter'); $domain_table = 'sub_domains'; $where_domain = ['sub_domain_id' => $sub_domain_id]; $subdomain = $model->get_where_row($domain_table, $where_domain); $login_table = 'login'; $where_id = ['login_id' => $login_id]; $faculty_res = $model->get_where_row($login_table, $where_id); // Load and configure the image library $imageLib = service('image'); $vid_target = ''; $video_url = []; $img_target = ''; $img_url = []; $pdf_target = ''; $pdf_url = []; // Handle video uploads if ($this->request->getFiles() && isset($this->request->getFiles()['upvideo'])) { $uploadedFile = $this->request->getFiles()['upvideo']; // Process each video file $target1 = 'subject_videos/'; $stamp = time(); $target1 .= $stamp . $uploadedFile->getClientName(); $target2 = $stamp . $uploadedFile->getClientName(); $video_url[] = $target2; $uploadedFile->move($target1); $vid_target = json_encode($video_url); } // Handle image uploads if ($this->request->getFiles() && isset($this->request->getFiles()['upimg'])) { foreach ($this->request->getFiles()['upimg'] as $file) { // Process each image file $target1 = 'subject_images/'; $stamp = time(); $target1 .= $stamp . $file->getClientName(); $target2 = $stamp . $file->getClientName(); $img_url[] = $target2; } $img_target = json_encode($img_url); } // Handle PDF uploads // if ($this->request->getFiles() && isset($this->request->getFiles()['uppdf'])) { // foreach ($this->request->getFiles()['uppdf'] as $file) { // // Process each PDF file // $target1 = 'subject_pdf/'; // $stamp = time(); // $target1 .= $stamp . $file->getClientName(); // $target2 = $stamp . $file->getClientName(); // $pdf_url[] = $target2; // $file->move($target1); // } // $pdf_target = json_encode($pdf_url); // } // $chapter_id = $this->request->getPost('chapter_id'); // $chapter_id = $chapter_id ? $chapter_id : 'default_value'; // Replace 'default_value' with the appropriate default. if ($this->request->getFiles() && isset($this->request->getFiles()['uppdf'])) { $pdf_url = []; // Ensure array is initialized foreach ($this->request->getFiles()['uppdf'] as $file) { if ($file->isValid() && !$file->hasMoved()) { $target1 = 'subject_pdf/'; $stamp = time(); $target2 = $stamp . $file->getClientName(); // Move the file to the correct directory if ($file->move($target1, $target2)) { $pdf_url[] = $target2; // Store only the filename } else { echo "Error moving file: " . $file->getClientName(); } } else { echo "File upload error: " . $file->getErrorString(); } } // Encode only if files were successfully uploaded $pdf_target = !empty($pdf_url) ? json_encode($pdf_url) : null; } // Ensure chapter_id is assigned correctly $chapter_id = $this->request->getPost('chapter_id') ?: 'default_value'; // Prepare data for insertion $data = [ 'material_count' => $material_count, 'chapter_id' => $chapter_id, 'topic_id' => $topic_id, // Corrected variable name 'sub_domain_id' => $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 ]; // Insert data into the database $result = $model->insert_data($table, $data); // Return JSON response based on the result if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Material added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } // public function get_admin_added_contents() // { // $login_id = session()->get('login_id'); // $content_model = new Content_Model(); // $result = $content_model->get_material_details($login_id); // if ($result) { // return $this->respond($result, 200); // } else { // return $this->respond(['result' => 1, 'message' => 'No Data Found'], 200); // } // } public function get_admin_added_contents() { $session = session(); $login_id = $session->get('login_id'); $content_model = new Content_Model(); $result = $content_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 enrolled_users_details($userId) { $session = session(); $loginId = $session->get('login_id'); if ($loginId) { $enrolledModel = new Enrolled_Model(); $data['user_id'] = $userId; $data['result'] = $enrolledModel->getWhereEnrolledUsersDetails($data['user_id']); return view('admin/enrolled_users_details', $data); } else { return redirect()->to('admin'); } } public function enrolled_course_details() { $userId = $this->request->getPost('user_id'); $enrolledModel = new Enrolled_Model(); $result = $enrolledModel->getWhereEnrolledUsersSubdomains($userId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function get_where_subject_syllabus() { $subDomainId = $this->request->getPost('sub_domain_id'); $loginId = $this->request->getPost('login_id'); $model = new Nparrots_Model(); $result = $model->getWhereTrainingPlans($subDomainId, $loginId); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function return_training_plan() { $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $model = new Nparrots_Model(); $login_id = session()->get('login_id'); $training_plan_id = $this->request->getPost('training_plan_id'); $comment = $this->request->getPost('return_comment'); $table = 'training_plans'; $where = ['training_plan_id' => $training_plan_id]; $data = ['approval_status' => 'NOT_APPROVED', 'return_status' => 'RETURNED']; $result = $model->updateData($where, $table, $data); if ($result > 0) { $trainingPlansBuilder = $model->db->table($table . ' A'); $trainingPlansBuilder->select('*'); $trainingPlansBuilder->where('A.delete_status', 'ACTIVE'); $trainingPlanId = $this->request->getPost('training_plan_id'); $trainingQuery = $trainingPlansBuilder->get(); $trainingResult = $trainingQuery->getRow(); if ($trainingResult) { $chapterIds = json_decode($trainingResult->chapter_ids); $chapterArray = []; foreach ($chapterIds as $val) { $syllabusChapterBuilder = $model->db->table($table . ' B'); $syllabusChapterBuilder->select('*'); $syllabusChapterBuilder->where('B.delete_status', 'ACTIVE'); // The rest of your code for processing syllabus chapters // ... } $emailResult = $model->getFacultySessionDetails($training_plan_id); $chapters = $emailResult['chapters']; $email = $emailResult['email']; $username = $emailResult['username']; $href = base_url(); // Continue with your email sending logic // ... return $this->response->setJSON(['result' => 1, 'message' => 'Approved successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No training plan found']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Update failed']); } } public function approve_training_plan() { $training_plan_id = $this->request->getPost('training_plan_id'); $table = 'training_plans'; $where = ['training_plan_id' => $training_plan_id]; $data = ['approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; $model = new Nparrots_Model(); $result = $model->updateData($where, $table, $data); if ($result) { $affectedRows = $model->db->affectedRows(); if ($affectedRows > 0) { $emailResult = $model->getFacultySessionDetails($training_plan_id); $chapters = $emailResult['chapters']; $email = $emailResult['email']; $username = $emailResult['username']; $emailService = \Config\Services::email(); $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;">Session Approval</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$username.', Your Session for the chapters '.$chapters.' has been Approved </p>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; $emailService->setMessage($email_content); // Set the recipient's email address $emailService->setTo($email); // Set the email subject and content $emailService->setSubject("Session Approval"); $emailService->setMessage($email_content); // Send the email if ($emailService->send()) { return $this->response->setJSON(['result' => 1, 'message' => 'Approved successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Email sending failed']); } } return $this->response->setJSON(['result' => 1, 'message' => 'No records updated']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong..']); } } public function getMaterialDetailsAdmin($login_id = null, $sub_domain_id = null) { // Get the login_id and sub_domain_id from the route parameters $login_id = $login_id ?? $this->request->uri->getSegment(3); $sub_domain_id = $sub_domain_id ?? $this->request->uri->getSegment(4); // Load the model $Model = new Nparrots_Model(); // Call the model method to get material details $result = $Model->getMaterialDetailsAdmin($sub_domain_id, $login_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 1, 'message' => 'No Data Found']); } } public function getTopicMaterialDetailsAdmin() { $login_id = $this->request->uri->getSegment(2); $sub_domain_id = $this->request->uri->getSegment(3); $chapter_id = $this->request->uri->getSegment(4); $model = new Nparrots_Model(); // Replace with your model's namespace // Define conditions as an array $conditions = [ 'login_id' => $login_id, 'sub_domain_id' => $sub_domain_id, 'chapter_id' => $chapter_id, ]; // Get the result from the model method with conditions $result = $model->getTopicMaterialDetailsAdmin($sub_domain_id, $login_id, $chapter_id); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function getTopicWiseMaterials() { $loginId = $this->request->uri->getSegment(3); $subDomainId = $this->request->uri->getSegment(4); $chapterId = $this->request->uri->getSegment(5); $Model = new Nparrots_Model(); $result = $Model->getTopicWiseMaterials($loginId, $subDomainId, $chapterId); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } } // public function update_course() // { // $model = new Nparrots_Model(); // $login_id = $this->request->getVar('login_id'); // $user_type_id = $this->request->getVar('user_type_id'); // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $course_id = $this->request->getVar('course_id'); // $domain_id = $this->request->getVar('domain_id'); // $sub_domain_id = $this->request->getVar('sub_domain_id'); // $course_title = $this->request->getVar('course_title'); // $language = $this->request->getVar('language'); // $course_price = $this->request->getVar('course_price'); // $course_type = $this->request->getVar('course_type'); // $description = $this->request->getVar('content'); // $curriculum = $this->request->getVar('content1'); // $instructor = $this->request->getVar('content2'); // if ($user_type_id == 4) { // $partner_id = $this->request->getVar('partner_id'); // $funder_id = $this->request->getVar('funder_id'); // $cer_partner_id = $this->request->getVar('cer_partner_id'); // } else { // $partner_id = '0'; // $funder_id = '0'; // $cer_partner_id = '0'; // } // $duration = $this->request->getVar('duration'); // if (!$duration) { // $duration = ''; // } // $from_time = $this->request->getVar('from_time'); // $to_time = $this->request->getVar('to_time'); // $available_type = ''; // $course_type = $this->request->getVar('course_type'); // Make sure to fetch course_type // $available_type = ''; // if (is_array($course_type)) { // foreach ($course_type as $courses) { // if ($courses == 'live') { // $available_type = $this->request->getVar('available_type'); // if ($available_type == '') { // $available_type = 'none'; // } // } // } // } // $i = 0; // if ($available_type == 'timings') { // $i = 0; // if ($from_time != '') { // foreach ($from_time as $key => $value) { // foreach ($from_time as $keys => $value) { // if ($key != $keys) { // $start_explode_colon = explode(':', $from_time[$key]); // $start_explode_space = explode(' ', $start_explode_colon[1]); // $end_totime_colon = explode(':', $to_time[$key]); // $end_totime_space = explode(' ', $end_totime_colon[1]); // $start_explode_colons = explode(':', $from_time[$keys]); // $start_explode_spaces = explode(' ', $start_explode_colons[1]); // $end_explode_colons = explode(':', $to_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]) // ) { // $i = $i + 1; // } // } // } // } // } // } // } // $course_table = 'courses'; // $where_course = ['course_id' => $course_id]; // $course_result = $model->getWhereRow($course_table, $where_course); // $course_image = ''; // $courseImage = $this->request->getFile('course_image'); // if ($courseImage !== null) { // if ($courseImage->isValid() && !$courseImage->hasMoved()) { // $image = time() . $courseImage->getClientName(); // $courseImage->move('writable/course_images', $image); // $image = \Config\Services::image(); // Create an instance of the Image service // $config = [ // 'image' => 'writable/course_images/.jpg', // Replace with the path to your image // 'width' => 251, // Desired width for the resized image // 'height' => 166, // Desired height for the resized image // ]; // $image->initialize($config); // Initialize the Image service with your configuration // if ($image->withFile($config['image'])->resize($config['width'], $config['height'])->save()) { // echo "Image was resized and saved successfully."; // } else { // echo "There was an error in resizing the image."; // } // } // } // $course_cropped_image = $this->request->getVar('course_cropped_image'); // if ($course_image != '' && $course_cropped_image != '') { // $course_cropped_image = $this->request->getVar('course_cropped_image'); // if ($course_image) { // $course_image = $course_cropped_image; // } // } // if ($course_image == '') { // if ($course_result) { // $course_image = $course_result->course_image; // } else { // // Handle the case where $course_result is not a valid object // // You can set a default value or display an error message. // // For example: $course_image = 'default_image.jpg'; // } // } // if ($i > 0) { // echo json_encode(['result' => 0, 'message' => 'Timings are duplicated']); // // } elseif ($video_size > 50000000) { // // echo json_encode(['result' => 0, 'message' => 'Video size must not exceed above 50MB']); // } else { // $where_course = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; // $check_course = $model->getWhereResult($course_table, $where_course); // $sub_id_count = 0; // $course_title_count = 0; // foreach ($check_course as $course) { // if ($course->course_title == $course_title) { // if ($course->course_id != $course_id) { // $course_title_count = 1; // } // } // } // if ($course_title_count) { // echo json_encode(['result' => 0, 'message' => 'Course title already exists']); // } else { // $course_data = [ // 'domain_id' => $domain_id, // 'sub_domain_id' => json_encode($sub_domain_id), // 'course_title' => $course_title, // 'course_image' => $course_image, // // 'course_demo_video' => $video_files, // 'language' => $language, // 'course_price' => $course_price, // 'duration' => $duration, // 'course_type' => json_encode($course_type), // 'description' => $description, // 'curriculum' => $curriculum, // 'instructor' => $instructor, // 'partner_id' => $partner_id, // 'funder_id' => $funder_id, // 'cer_partner_id' => $cer_partner_id, // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // // Define $where_id with the desired condition // $where_id = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // // Other variable assignments // $course_data = [ // 'funder_id' => $funder_id, // 'cer_partner_id' => $cer_partner_id, // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $tableName = 'courses'; // Replace 'your_table_name' with the actual table name // // Call the updateCourse method with the defined variables // $model->updateCourse($tableName, $where_id, $course_data); // // echo json_encode(['result' => 1, 'message' => 'Course updated successfully']); // return $this->response->setJSON(['result' => 1, 'message' => 'Course updated successfully']); // $timings_table = 'course_available_timings'; // // $timings_table = 'your_timings_table'; // Replace with the actual table name // $where_timings = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $model->deleteTimings($timings_table, $where_timings); // if ($available_type != '') { // if ($available_type == 'timings') { // if ($from_time != '') { // foreach ($from_time as $key => $value) { // $course_timings = [ // 'course_id' => $course_id, // 'course_type' => json_encode($course_type), // 'available_type' => $available_type, // 'from_time' => $from_time[$key], // 'to_time' => $to_time[$key], // 'delete_status' => 'ACTIVE', // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $timing_table = 'course_available_timings'; // $model->insertTimings($timing_table, $course_timings); // } // echo json_encode(['result' => 1, 'message' => 'Course updated successfully']); // } else { // echo json_encode(['result' => 0, 'message' => 'Please add timings']); // } // } elseif ($available_type == 'full_day') { // $course_timings = [ // 'course_id' => $course_id, // 'course_type' => json_encode($course_type), // 'available_type' => $available_type, // 'delete_status' => 'ACTIVE', // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $timing_table = 'course_available_timings'; // $model->insertTimings($timing_table, $course_timings); // $time_result = time(); // Get the current timestamp // if (isset($time_result)) { // echo json_encode(['result' => 1, 'message' => 'Course updated successfully']); // } else { // echo json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } // } // } // } // } // public function update_course() // { // $model = new Nparrots_Model(); // $login_id = $this->request->getPost('login_id'); // $user_type_id = $this->request->getPost('user_type_id'); // $date = new Time('now', 'Asia/Kolkata'); // $created_at = $date->format('Y-m-d H:i:s'); // $course_id = $this->request->getPost('course_id'); // $domain_id = $this->request->getPost('domain_id'); // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $course_title = $this->request->getPost('course_title'); // $language = $this->request->getPost('language'); // $course_price = $this->request->getPost('course_price'); // $course_type = $this->request->getPost('course_type'); // $description = $this->request->getPost('content'); // $curriculum = $this->request->getPost('content1'); // $instructor = $this->request->getPost('content2'); // if ($user_type_id == 4) { // $partner_id = $this->request->getPost('partner_id'); // $funder_id = $this->request->getPost('funder_id'); // $cer_partner_id = $this->request->getPost('cer_partner_id'); // } else { // $partner_id = '0'; // $funder_id = '0'; // $cer_partner_id = '0'; // } // $duration = $this->request->getPost('duration'); // if (!$duration) { // $duration = ''; // } // $from_time = $this->request->getPost('from_time'); // $to_time = $this->request->getPost('to_time'); // $available_type = ""; // foreach ($course_type as $courses) { // if ($courses == 'live') { // $available_type = $this->request->getPost('available_type'); // if ($available_type == "") { // $available_type = "none"; // } // } // } // $i = 0; // if ($available_type == 'timings') { // $i = 0; // if ($from_time != '') { // foreach ($from_time as $key => $value) { // foreach ($from_time as $keys => $value) { // if ($key != $keys) { // $start_explode_colon = explode(':', $from_time[$key]); // $start_explode_space = explode(' ', $start_explode_colon[1]); // $end_totime_colon = explode(':', $to_time[$key]); // $end_totime_space = explode(' ', $end_totime_colon[1]); // $start_explode_colons = explode(':', $from_time[$keys]); // $start_explode_spaces = explode(' ', $start_explode_colons[1]); // $end_explode_colons = explode(':', $to_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])) { // $i = $i + 1; // } // } // } // } // } // } // } // $course_table = 'courses'; // $where_course = ['course_id' => $course_id]; // $course_result = $model->getWhereRow($course_table,$where_course); // $video_files = ""; // if ($this->request->getFile('course_demo_video')->isValid()) { // $video_size = $this->request->getFile('course_demo_video')->getSize(); // $video_document = $this->request->getFile('course_demo_video'); // $video_files = $video_document->getRandomName(); // $video_document->move('writable/uploads/course_videos', $video_files); // } else { // $video_size = 0; // $video_files = $course_result->course_demo_video; // } // $course_image = ""; // if ($this->request->getFile('course_image')->isValid()) { // $course_image = $this->request->getFile('course_image'); // $course_image->move('writable/uploads/course_images'); // } // $course_cropped_image = $this->request->getPost('course_cropped_image'); // if (($course_image != "") && ($course_cropped_image != "")) { // $course_cropped_image = $this->request->getPost('course_cropped_image'); // if ($course_image) { // $course_image = $course_cropped_image; // } // } // if ($course_image == '') { // $course_image = $course_result->course_image; // } // if ($i > 0) { // echo json_encode(['result' => 0, 'message' => 'Timings are duplicated']); // } elseif ($video_size > 50000000) { // echo json_encode(['result' => 0, 'message' => 'Video size must not exceed above 50MB']); // } else { // $where_course = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; // $check_course = $model->getWhere($where_course)->getResult(); // $sub_id_count = 0; // $course_title_count = 0; // foreach ($check_course as $course) { // if ($course->course_title == $course_title) { // if ($course->course_id != $course_id) { // $course_title_count = 1; // } // } // } // if ($course_title_count) { // echo json_encode(['result' => 0, 'message' => 'Course title already exists']); // } else { // $course_data = [ // 'domain_id' => $domain_id, // 'sub_domain_id' => json_encode($sub_domain_id), // 'course_title' => $course_title, // 'course_image' => $course_image, // 'course_demo_video' => $video_files, // 'language' => $language, // 'course_price' => $course_price, // 'duration' => $duration, // 'course_type' => json_encode($course_type), // 'description' => $description, // 'curriculum' => $curriculum, // 'instructor' => $instructor, // 'partner_id' => $partner_id, // 'funder_id' => $funder_id, // 'cer_partner_id' => $cer_partner_id, // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $where_id = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $result = $model->update($where_id, $course_table, $course_data); // if ($this->db->affectedRows() > 0) { // $timings_table = 'course_available_timings'; // $where_timings = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $time_result = $model->delete($timings_table, $where_timings); // if ($available_type != "") { // if ($available_type == "timings") { // if ($from_time != '') { // foreach ($from_time as $key => $value) { // $course_timings = [ // 'course_id' => $course_id, // 'course_type' => json_encode($course_type), // 'available_type' => $available_type, // 'from_time' => $from_time[$key], // 'to_time' => $to_time[$key], // 'delete_status' => 'ACTIVE', // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $timing_table = 'course_available_timings'; // $time_result = $model->insert($timing_table, $course_timings); // } // if ($time_result) { // echo json_encode(['result' => 1, 'message' => "Course updated successfully"]); // } else { // echo json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } else { // echo json_encode(['result' => 0, 'message' => 'Please add timings']); // } // } elseif ($available_type == "full_day") { // $course_timings = [ // 'course_id' => $course_id, // 'course_type' => json_encode($course_type), // 'available_type' => $available_type, // 'delete_status' => 'ACTIVE', // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $timing_table = 'course_available_timings'; // $time_result = $model->insert($timing_table, $course_timings); // if ($time_result) { // echo json_encode(['result' => 1, 'message' => 'Course updated successfully']); // } else { // echo json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } else { // echo json_encode(['result' => 0, 'message' => 'Please select available type']); // } // } else { // echo json_encode(['result' => 1, 'message' => 'Course updated successfully']); // } // } else { // echo json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } // } // } // public function update_course() // { // $model = new Nparrots_Model(); // $login_id = $this->request->getPost('login_id'); // $user_type_id = $this->request->getPost('user_type_id'); // $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $course_id = $this->request->getPost('course_id'); // $domain_id = $this->request->getPost('domain_id'); // $sub_domain_id = $this->request->getPost('sub_domain_id'); // $course_title = $this->request->getPost('course_title'); // $language = $this->request->getPost('language'); // $course_price = $this->request->getPost('course_price'); // $course_type = $this->request->getPost('course_type'); // $description = $this->request->getPost('content'); // $curriculum = $this->request->getPost('content1'); // $instructor = $this->request->getPost('content2'); // if ($user_type_id == 4) { // $partner_id = $this->request->getPost('partner_id'); // $funder_id = $this->request->getPost('funder_id'); // $cer_partner_id = $this->request->getPost('cer_partner_id'); // } else { // $partner_id = '0'; // $funder_id = '0'; // $cer_partner_id = '0'; // } // $duration = $this->request->getPost('duration'); // if (!$duration) { // $duration = ''; // } // $from_time = $this->request->getPost('from_time'); // $to_time = $this->request->getPost('to_time'); // $available_type = ""; // foreach ($course_type as $courses) { // if ($courses == 'live') { // $available_type = $this->request->getPost('available_type'); // if ($available_type == "") { // $available_type = "none"; // } // } // } // $i = 0; // if ($available_type == 'timings') { // $i = 0; // if ($from_time != '') { // foreach ($from_time as $key => $value) { // foreach ($from_time as $keys => $value) { // if ($key != $keys) { // $start_explode_colon = explode(':', $from_time[$key]); // $start_explode_space = explode(' ', $start_explode_colon[1]); // $end_totime_colon = explode(':', $to_time[$key]); // $end_totime_space = explode(' ', $end_totime_colon[1]); // $start_explode_colons = explode(':', $from_time[$keys]); // $start_explode_spaces = explode(' ', $start_explode_colons[1]); // $end_explode_colons = explode(':', $to_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])) { // $i = $i + 1; // } // } // } // } // } // } // } // $course_table = 'courses'; // $where_course = ['course_id'=>$course_id]; // $course_result = $model->getWhereRow($course_table,$where_course); // $video_files = ""; // if (!empty($course_result) && $this->request->getFile('course_demo_video')->getName()) { // $video_size = $this->request->getFile('course_demo_video')->getSize(); // $video_document = $this->request->getFile('course_demo_video'); // $video_files = $video_document->getRandomName(); // $video_document->move('course_videos', $video_files); // } else { // $video_size = 0; // $video_files = !empty($course_result) ? $course_result->course_demo_video : ""; // } // $imageLib = \Config\Services::image(); // // $course_image = ""; // // if ($this->request->getFile('course_image')->getName()) { // // $course_image_file = $this->request->getFile('course_image'); // // $course_image = $course_image_file->getRandomName(); // // $course_image_file->move('course_images', $course_image); // // // Resize image // // $config['image_library'] = 'gd2'; // // $config['source_image'] = 'course_images/' . $course_image; // // $config['create_thumb'] = FALSE; // // $config['maintain_ratio'] = TRUE; // // $config['width'] = 251; // // $config['height'] = 166; // // $this->image_lib->initialize($config); // // $this->image_lib->resize(); // // } // $course_image = ""; // if ($_FILES['course_image']['name']) { // $target = 'course_images/'; // $target .= time() . $_FILES['course_image']['name']; // $course_image = time() . $_FILES['course_image']['name']; // $image = $target; // move_uploaded_file($_FILES['course_image']['tmp_name'], $target); // // Use the image_lib service for resizing // $config['source_image'] = $target; // $config['maintain_ratio'] = TRUE; // $config['width'] = 251; // $config['height'] = 166; // $imageLib->initialize($config); // $imageLib->resize(); // } // $course_cropped_image = $this->request->getPost('course_cropped_image'); // if (($course_image != "") && ($course_cropped_image != "")) { // $course_cropped_image = $this->request->getPost('course_cropped_image'); // if ($course_image) { // $course_image = $course_cropped_image; // } // } // if ($course_image == '') { // $course_image = $course_result->course_image; // } // if ($i > 0) { // return json_encode(['result' => 0, 'message' => 'Timings are duplicated']); // } elseif ($video_size > 50000000) { // return json_encode(['result' => 0, 'message' => 'Video size must not exceed above 50MB']); // } else { // $where_course = ['delete_status' => 'ACTIVE', 'created_by' => $login_id]; // $check_course = $model->get_where_result($course_table, $where_course); // $sub_id_count = 0; // $course_title_count = 0; // foreach ($check_course as $course) { // if ($course->course_title == $course_title) { // if ($course->course_id != $course_id) { // $course_title_count = 1; // } // } // } // if ($course_title_count) { // return json_encode(['result' => 0, 'message' => 'Course title already exists']); // } else { // $course_data = [ // 'domain_id' => $domain_id, // 'sub_domain_id' => json_encode($sub_domain_id), // 'course_title' => $course_title, // 'course_image' => $course_image, // 'course_demo_video' => $video_files, // 'language' => $language, // 'course_price' => $course_price, // 'duration' => $duration, // 'course_type' => json_encode($course_type), // 'description' => $description, // 'curriculum' => $curriculum, // 'instructor' => $instructor, // 'partner_id' => $partner_id, // 'funder_id' => $funder_id, // 'cer_partner_id' => $cer_partner_id, // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $where_id = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $result = $model->updateData($where_id,$course_table,$course_data); // if ($this->db->affectedRows() > 0) { // $timings_table = 'course_available_timings'; // $where_timings = ['course_id' => $course_id, 'delete_status' => 'ACTIVE']; // $time_result = $model->deleteData($timings_table, $where_timings); // if ($available_type != "") { // if ($available_type == "timings") { // if ($from_time != '') { // foreach ($from_time as $key => $value) { // $course_timings = [ // 'course_id' => $course_id, // 'course_type' => json_encode($course_type), // 'available_type' => $available_type, // 'from_time' => $from_time[$key], // 'to_time' => $to_time[$key], // 'delete_status' => 'ACTIVE', // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $timing_table = 'course_available_timings'; // $time_result = $model->insertData($timing_table, $course_timings); // } // if ($time_result) { // return json_encode(['result' => 1, 'message' => 'Course updated successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Please add timings']); // } // } elseif ($available_type == "full_day") { // $course_timings = [ // 'course_id' => $course_id, // 'course_type' => json_encode($course_type), // 'available_type' => $available_type, // 'delete_status' => 'ACTIVE', // 'updated_by' => $login_id, // 'updated_at' => $created_at, // ]; // $timing_table = 'course_available_timings'; // $time_result = $model->insertData($timing_table, $course_timings); // if ($time_result) { // return json_encode(['result' => 1, 'message' => 'Course updated successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Please select available type']); // } // } else { // return json_encode(['result' => 1, 'message' => 'Course updated successfully']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } // } // } public function update_course() { $model = new Nparrots_Model(); $loginId = $this->request->getPost('login_id'); $userTypeId = $this->request->getPost('user_type_id'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createdAt = $date->format('Y-m-d H:i:s'); $courseId = $this->request->getPost('course_id'); $domainId = $this->request->getPost('domain_id'); $subDomainId = $this->request->getPost('sub_domain_id'); $courseTitle = $this->request->getPost('course_title'); $language = $this->request->getPost('language'); $coursePrice = $this->request->getPost('course_price'); $courseType = $this->request->getPost('course_type'); $description = $this->request->getPost('content'); $curriculum = $this->request->getPost('content1'); $instructor = $this->request->getPost('content2'); if ($userTypeId == 4) { $partnerId = $this->request->getPost('partner_id'); $funderId = $this->request->getPost('funder_id'); $cerPartnerId = $this->request->getPost('cer_partner_id'); } else { $partnerId = '0'; $funderId = '0'; $cerPartnerId = '0'; } $duration = $this->request->getPost('duration'); if (!$duration) { $duration = ''; } $fromTime = $this->request->getPost('from_time'); $toTime = $this->request->getPost('to_time'); $availableType = ""; if (is_array($courseType)) { foreach ($courseType as $courses) { if ($courses == 'live') { $availableType = $this->request->getPost('available_type'); if ($availableType == "") { $availableType = "none"; } } } } $i = 0; if ($availableType == 'timings') { $i = 0; if ($fromTime != '') { foreach ($fromTime as $key => $value) { foreach ($fromTime as $keys => $value) { if ($key != $keys) { $startExplodeColon = explode(':', $fromTime[$key]); $startExplodeSpace = explode(' ', $startExplodeColon[1]); $endToTimeColon = explode(':', $toTime[$key]); $endToTimeSpace = explode(' ', $endToTimeColon[1]); $startExplodeColons = explode(':', $fromTime[$keys]); $startExplodeSpaces = explode(' ', $startExplodeColons[1]); $endExplodeColons = explode(':', $toTime[$keys]); $endExplodeSpaces = explode(' ', $endExplodeColons[1]); if ($startExplodeSpace[1] == $startExplodeSpaces[1]) { if (($startExplodeColons[0] == $endToTimeColon[0] && $startExplodeSpaces[0] < $endToTimeSpace[0]) || $startExplodeColons[0] == $startExplodeColon[0]) { $i = $i + 1; } } } } } } } $courseTable = 'courses'; $whereCourse = ['course_id' => $courseId]; $courseResult = $model->getWhereRow($courseTable, $whereCourse); $videoFiles = ""; $courseDemoVideo = $this->request->getFile('course_demo_video'); if ($courseDemoVideo && $courseDemoVideo->getName()) { $videoSize = $courseDemoVideo->getSize(); $videoDocument = time() . $courseDemoVideo->getName(); $videoFiles = $videoDocument; $videoPath = 'course_videos/' . $videoDocument; $courseDemoVideo->move($videoPath); } else { $videoSize = 0; if ($courseResult && property_exists($courseResult, 'course_demo_video')) { $videoFiles = $courseResult->course_demo_video; } else { // Handle the case where $courseResult is null or does not have 'course_demo_video' // You might want to set a default value or log an error message. } } $courseImage = ""; $courseImageFile = $this->request->getFile('course_image'); if ($courseImageFile && $courseImageFile->getName()) { $courseImage = time() . $courseImageFile->getName(); $target = 'course_images/' . $courseImage; $image = $target; $courseImageFile->move($target); // Assuming you have the image_lib library loaded $config['source_image'] = $target; $config['maintain_ratio'] = TRUE; $config['width'] = 251; $this->image_lib->initialize($config); $this->image_lib->resize(); } $courseCroppedImage = $this->request->getPost('course_cropped_image'); if (($courseImage == "") && ($courseCroppedImage != "")) { $courseImage = $courseCroppedImage; } if ($courseImage == '') { // Check if $courseResult is not null and contains the property 'course_image' if ($courseResult && property_exists($courseResult, 'course_image')) { $courseImage = $courseResult->course_image; } else { // Handle the case where $courseResult is null or does not have 'course_image' // You might want to set a default value or log an error message. } } if ($i > 0) { return json_encode(['result' => 0, 'message' => 'Timings are duplicated']); } elseif ($videoSize > 50000000) { return json_encode(['result' => 0, 'message' => 'Video size must not exceed above 50MB']); } else { $whereCourse = ['delete_status' => 'ACTIVE', 'created_by' => $loginId]; $checkCourse = $model->getWhereResult($courseTable, $whereCourse); $subIdCount = 0; $courseTitleCount = 0; foreach ($checkCourse as $course) { if ($course->course_title == $courseTitle) { if ($course->course_id != $courseId) { $courseTitleCount = 1; } } } if ($courseTitleCount) { return json_encode(['result' => 0, 'message' => 'Course title already exists']); } else { $courseData = [ 'domain_id' => $domainId, 'sub_domain_id' => json_encode($subDomainId), 'course_title' => $courseTitle, 'course_image' => $courseImage, 'course_demo_video' => $videoFiles, 'language' => $language, 'course_price' => $coursePrice, 'duration' => $duration, 'course_type' => json_encode($courseType), 'description' => $description, // 'curriculum' => $curriculum, 'curriculam' => $curriculum, 'instructor' => $instructor, 'partner_id' => $partnerId, 'funder_id' => $funderId, 'cer_partner_id' => $cerPartnerId, 'updated_by' => $loginId, 'updated_at' => $createdAt ]; $whereId = ['course_id' => $courseId, 'delete_status' => 'ACTIVE']; $result = $model->updateData($whereId, $courseTable, $courseData); if ($this->db->affectedRows() > 0) { $timingsTable = 'course_available_timings'; $whereTimings = ['course_id' => $courseId, 'delete_status' => 'ACTIVE']; $timeResult = $model->deleteData($timingsTable, $whereTimings); if ($availableType != "") { if ($availableType == "timings") { if ($fromTime != '') { foreach ($fromTime as $key => $value) { $courseTimings = [ 'course_id' => $courseId, 'course_type' => json_encode($courseType), 'available_type' => $availableType, 'from_time' => $fromTime[$key], 'to_time' => $toTime[$key], 'delete_status' => 'ACTIVE', 'updated_by' => $loginId, 'updated_at' => $createdAt ]; $timingTable = 'course_available_timings'; $timeResult = $model->insertData($timingTable, $courseTimings); } if ($timeResult) { return json_encode(['result' => 1, 'message' => 'Course updated successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); } } else { return json_encode(['result' => 0, 'message' => 'Please add timings']); } } elseif ($availableType == "full_day") { $courseTimings = [ 'course_id' => $courseId, 'course_type' => json_encode($courseType), 'available_type' => $availableType, 'delete_status' => 'ACTIVE', 'updated_by' => $loginId, 'updated_at' => $createdAt ]; $timingTable = 'course_available_timings'; $timeResult = $model->insertData($timingTable, $courseTimings); if ($timeResult) { return json_encode(['result' => 1, 'message' => 'Course updated successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); } } else { return json_encode(['result' => 0, 'message' => 'Please select available type']); } } else { return json_encode(['result' => 1, 'message' => 'Course updated successfully']); } } else { return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); } } } } public function question_details() { $request = service('request'); $facultyId = $request->getPost('id'); $chapterId = $request->getPost('chapter_id'); $Model = new Nparrots_Model(); // Replace with the actual model you're using. $result = $Model->getQuestionDetails($facultyId, $chapterId); if ($result) { return $this->response->setJSON(['result' => 1, 'data_result' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } // public function institution_registrations() // { // $login_id = session()->get('login_id'); // if ($login_id) { // return view('admin/institution_registration'); // } else { // return redirect()->to('/admin'); // } // } // public function institution() // { // $model = new InstitutionModel(); // $institution = $model->first(); // if ($institution) { // // If registered, show details // $data['details'] = $institution; // return view('admin/institution_view_1', $data); // // return view('admin/view_institution', $data); // } else { // // If not registered, show registration form // return view('admin/institution_registration'); // } // } //Prakrauthi public function institution() { $institutionModel = new InstitutionModel(); // Check if there is any data in the database $existingData = $institutionModel->first(); if ($existingData) { // Data exists, show details return redirect()->to('show_details/' . $existingData['id']); } else { // No data exists, show registration page return view('admin/institution_registration'); } } public function institution_registration() { $institutionModel = new InstitutionModel(); $institutionData = [ 'institution_name' => $this->request->getPost('institution_name'), 'address' => $this->request->getPost('address'), 'email' => $this->request->getPost('email'), 'inst_phone' => $this->request->getPost('inst_phone'), 'contact_person_details' => $this->request->getPost('contact_person_details'), ]; if (empty($institutionData['institution_name']) || empty($institutionData['email'])) { $response = ['success' => false, 'message' => 'Please fill out required fields.']; } else { $insert_id = $institutionModel->insert($institutionData); if ($insert_id) { $response = ['success' => true, 'id' => $insert_id]; } else { $dbError = $institutionModel->errors(); $dbErrorString = print_r($dbError, true); $response = ['success' => false, 'message' => 'Institution registration failed to be created. Database Error: ' . $dbErrorString]; } } // Return JSON response return $this->response->setJSON($response); } public function show_details($institutionId) { $institutionModel = new InstitutionModel(); $institutionDetails = $institutionModel->find($institutionId); if ($institutionDetails) { return view('admin/institutions_details', [ 'success' => true, 'id' => $institutionId, 'details' => $institutionDetails, ]); } else { return view('admin/institutions_details', [ 'success' => false, 'message' => 'Institution not found.', ]); } } public function edit($id) { $institutionModel = new InstitutionModel(); $details = $institutionModel->getInstitutionById($id); // Load the edit view with the institution details return view('admin/institution_registration', ['id' => $id, 'details' => $details]); } public function update($id) { $institutionModel = new InstitutionModel(); // Assuming you are using CodeIgniter's request class to get post data $postData = $this->request->getPost(); // Validate and update the institution details in the database $updateResult = $institutionModel->updateInstitution($id, $postData); if ($updateResult) { // Successful update, redirect to the details page with a success message return redirect()->to(base_url('institution/details/' . $id))->with('success', true); } else { // Update failed, redirect back to the edit page with an error message return redirect()->to(base_url('edit/' . $id))->with('error', 'Update failed. Please try again.'); } } // public function institution_registration1() // { // $institutionModel = new InstitutionModel(); // $institutionData = [ // 'institution_name' => $this->request->getPost('institution_name'), // 'address' => $this->request->getPost('address'), // 'email' => $this->request->getPost('email'), // 'inst_phone' => $this->request->getPost('phone'), // 'contact_person_details' => $this->request->getPost('contact_person_details'), // ]; // if ($institutionModel->insert($institutionData)) { // return json_encode(['success' => true, 'message' => 'Institution registration successfully created.']); // } else { // return json_encode(['success' => false, 'message' => 'Institution registration failed to be created.']); // } // } // public function institution_registration_submit() // { // $institutionModel = new InstitutionModel(); // $institutionData = [ // 'institution_name' => $this->request->getPost('institution_name'), // 'address' => $this->request->getPost('address'), // 'email' => $this->request->getPost('email'), // 'inst_phone' => $this->request->getPost('phone'), // 'contact_person_details' => $this->request->getPost('contact_person_details'), // ]; // // Add validation here, for example, check if required fields are not empty // if (empty($institutionData['institution_name']) || empty($institutionData['email'])) { // $response = ['success' => false, 'message' => 'Please fill out required fields.']; // } else { // $insert_id = $institutionModel->insert($institutionData); // if ($insert_id) { // $response = ['success' => true, 'message' => 'Institution registration successfully created.', 'id' => $insert_id]; // } else { // $response = ['success' => false, 'message' => 'Institution registration failed to be created.']; // } // } // return $this->response->setJSON($response); // Send the response as JSON // } // public function view() // { // $institution_name = isset($_GET['institution_name']) ? $_GET['institution_name'] : ''; // $address = isset($_GET['address']) ? $_GET['address'] : ''; // $email = isset($_GET['email']) ? $_GET['email'] : ''; // $phone = isset($_GET['phone']) ? $_GET['phone'] : ''; // $contact_person_details = isset($_GET['contact_person_details']) ? $_GET['contact_person_details'] : ''; // // // Now you can use these variables as needed without causing "Undefined index" errors // // // ... // return view('admin/view_institution', [ // 'institution_name' => $institution_name, // 'address' => $address, // 'email' => $email, // 'phone' => $phone, // 'contact_person_details' => $contact_person_details, // ]); // } // public function edit() // { // return view('admin/edit_institution'); // } // public function update_institution() // { // $institutionModel = new InstitutionModel(); // $institutionData = [ // 'institution_name' => $this->request->getPost('institution_name'), // 'address' => $this->request->getPost('address'), // 'email' => $this->request->getPost('email'), // 'inst_phone' => $this->request->getPost('phone'), // 'contact_person_details' => $this->request->getPost('contact_person_details'), // ]; // // Add validation here, for example, check if required fields are not empty // if (empty($institutionData['institution_name']) || empty($institutionData['email'])) { // $response = ['success' => false, 'message' => 'Please fill out required fields.']; // } else { // $id = $this->request->getPost('institution_id'); // Get the ID of the institution to update // if ($institutionModel->update($id, $institutionData)) { // $response = ['success' => true, 'message' => 'Institution information updated successfully.']; // // return redirect()->to('admin/update_institution'); // Redirect to the specified page // } else { // $response = ['success' => false, 'message' => 'Failed to update institution information.']; // } // } // return $this->response->setJSON($response); // } // public function upd() // { // $institution_name = isset($_GET['institution_name']) ? $_GET['institution_name'] : ''; // $address = isset($_GET['address']) ? $_GET['address'] : ''; // $email = isset($_GET['email']) ? $_GET['email'] : ''; // $phone = isset($_GET['phone']) ? $_GET['phone'] : ''; // $contact_person_details = isset($_GET['contact_person_details']) ? $_GET['contact_person_details'] : ''; // return view('admin/update_institution', [ // 'institution_name' => $institution_name, // 'address' => $address, // 'email' => $email, // 'phone' => $phone, // 'contact_person_details' => $contact_person_details, // ]); // } // public function returned_material_comment() // { // $login_id = session()->get('login_id'); // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $chapter_id = $this->request->getPost('faculty_id'); // $faculty_id = $this->request->getPost('faculty_ids'); // $comment = $this->request->getPost('comment'); // $where_material = [ // 'chapter_id' => $chapter_id, // 'created_by' => $faculty_id, // 'delete_status' => 'ACTIVE' // ]; // $material_table = 'subject_materials'; // $comment_data = ['approval_status' => 'NOT_APROVED', 'return_status' => 'RETURNED']; // $model = new Nparrots_Model(); // Replace with your actual model. // $result = $model->updateData($where_material, $material_table, $comment_data); // $where = ['login_id' => $faculty_id, 'delete_status' => 'ACTIVE']; // $login_table = 'login'; // $email_result = $model->getWhereRow($login_table, $where); // if ($email_result) { // $email = $email_result->email; // if ($result) { // $href = base_url(''); // $email_content = ''; // $email_content .= '<body style="background:#f3f3f3;">'; // // ... Rest of your email content ... // require_once ROOTPATH . '/email/PHPMailerAutoload.php'; // $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($email); // $phpMailer->Subject = "Return Material"; // $phpMailer->Body = $email_content; // $phpMailer->send(); // $comment_table = 'returned_material_comments'; // $comment_data = [ // 'faculty_id' => $faculty_id, // 'comment' => $comment, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at, // 'created_by' => $login_id // ]; // $comment_result = $model->insertData($comment_table, $comment_data); // if ($comment_result) { // return $this->response->setJSON(['result' => 1, 'message' => 'Returned Successfully']); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); // } // } // } // } public function returned_material_comment() { $model = new Nparrots_Model(); $login_id = session()->get('login_id'); $date = new Time('now', 'Asia/Kolkata'); $created_at = $date->format('Y-m-d H:i:s'); $chapter_id = $this->request->getPost('faculty_id'); $faculty_id = $this->request->getPost('faculty_ids'); $comment = $this->request->getPost('comment'); $where_material = ['chapter_id' => $chapter_id, 'created_by' => $faculty_id, 'delete_status' => 'ACTIVE']; $material_table = 'subject_materials'; $comment_data = ['approval_status' => 'NOT_APPROVED', 'return_status' => 'RETURNED']; $result = $model->updateData($where_material, $material_table, $comment_data); $where = ['login_id' => $faculty_id, 'delete_status' => 'ACTIVE']; $login_table = 'login'; $email_result = $model->getWhereRow($login_table, $where); $email = $email_result->email; // print_r($email); // die(); if ($result) { $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;">Return Material</h3>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$email_result->username.',</p>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">'.$comment.'</p>'; $content .= '</div>'; $content .= '</div>'; $content .= '</div>'; $content .= '</body>'; $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "AMCAD"); $emailService->setTo($email); $emailService->setSubject('Return Material'); $emailService->setMessage($content); try { $emailService->send(); $comment_table = 'returned_material_comments'; $comment_data = [ 'faculty_id' => $faculty_id, 'comment' => $comment, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, 'created_by' => $login_id, ]; $comment_result = $model->insertData($comment_table, $comment_data); if ($comment_result) { return $this->response->setJSON(['result' => 1, 'message' => 'Returned Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } catch (\Exception $e) { return $this->response->setJSON(['result' => 0, 'message' => 'Error sending email: ' . $e->getMessage()]); } } } // public function approveMaterials() // { // $loginId = $this->request->getPost('faculty_id'); // $chapterId = $this->request->getPost('id'); // $table = 'subject_materials'; // $where = ['chapter_id' => $chapterId, 'delete_status' => 'ACTIVE', 'created_by' => $loginId]; // $Model = new Nparrots_Model(); // $data = ['approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; // $result = $Model->updateData($where, $table, $data); // $createdBy = $Model->getWhereRow($table, $where); // $loginTable = 'login'; // $whereLogin = ['login_id' => $loginId, 'delete_status' => 'ACTIVE']; // $emailResult = $Model->getWhereRow($loginTable, $whereLogin); // if ($emailResult) { // $email = $emailResult->email; // $userName = $emailResult->username; // } else { // // Handle the case where no record is found. // $email = "No email found"; // You can set a default value // $userName = "No username found"; // Set a default value or show an error message. // } // $subTable = 'sub_domains'; // $whereSub = ['delete_status' => 'ACTIVE']; // if ($createdBy && property_exists($createdBy, 'sub_domain_id')) { // $whereSub['sub_domain_id'] = $createdBy->sub_domain_id; // $subject = $Model->getWhereRow($subTable, $whereSub); // if ($subject) { // $subjectName = $subject->sub_domain; // } else { // // Handle the case where no subject record is found. // $subjectName = "No subject found"; // Set a default value or show an error message. // } // } else { // // Handle the case where no 'sub_domain_id' property is found in $createdBy. // $subjectName = "No subject found"; // Set a default value or show an error message. // } // if ($result) { // $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 . 'assets/images/all_logo.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 . 'assets/images/email.png" style="display:block;margin:auto;width:100px;"/>'; // $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;">Material Approval Information</h3>'; // $emailContent .= '<p style="font-size:16px;padding-bottom:10px;">Hello ' . $userName . ', Your Material has been Approved for ' . $subjectName . '. </p>'; // $emailContent .= '</div>'; // $emailContent .= '</div>'; // $emailContent .= '</div>'; // $emailContent .= '</body>'; // $email = \Config\Services::email(); // $email->initialize([ // 'protocol' => 'smtp', // 'SMTPHost' => 'your_smtp_host', // 'SMTPUser' => 'your_smtp_username', // 'SMTPPass' => 'your_smtp_password', // 'SMTPPort' => 587, // 'SMTPCrypto' => 'tls', // 'CRLF' => "\r\n", // 'newline' => "\r\n" // ]); // $email->setFrom('healthcare@medusyspty.com', 'Nparrots'); // // Change the variable name to something other than $email to avoid the conflict // $recipientEmail = 'recipient@example.com'; // $email->setTo($recipientEmail); // $email->setSubject('Material Approval'); // $email->setMessage($emailContent); // if ($email->send()) { // return $this->response->setJSON(['result' => 1, 'message' => 'Approved Successfully']); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); // } // } // } public function approve_materials() { $Model = new Nparrots_Model(); $login_id = $this->request->getPost('faculty_id'); $chapter_id = $this->request->getPost('id'); $table = 'subject_materials'; $where = ['chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE', 'created_by' => $login_id]; $data = ['approval_status' => 'APPROVED', 'return_status' => 'NOT_RETURNED']; $result = $Model->updateData($where, $table, $data); $created_by = $Model->getWhereRow($table, $where); $login_table = 'login'; $where_login = ['login_id' => $login_id, 'delete_status' => 'ACTIVE']; $email_result = $Model->getWhereRow($login_table, $where_login); $email = $email_result->email; $user_name = $email_result->username; $sub_table = 'sub_domains'; $where_sub = ['sub_domain_id' => $created_by->sub_domain_id, 'delete_status' => 'ACTIVE']; $subject = $Model->getWhereRow($sub_table, $where_sub); $subject_name = $subject->sub_domain; if ($result) { $emailService = \Config\Services::email(); $emailService->setFrom("johncameron6677@gmail.com", "Amcad"); $emailService->setTo($email); $emailService->setSubject('Material Approval'); $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;">Material Approval Information</h3>'; $email_content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$user_name.', Your Material has been Approved for '.$subject_name.'. </p>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</div>'; $email_content .= '</body>'; $emailService->setMessage($email_content); // Email configuration // $emailConfig = [ // 'protocol' => 'smtp', // 'SMTPHost' => 'smtp-relay.gmail.com', // 'SMTPPort' => 587, // 'SMTPUser' => 'healthcare@medusyspty.com', // 'SMTPPass' => 'Password@1236', // 'SMTPCrypto' => 'tls', // 'mailType' => 'html', // 'charset' => 'UTF-8', // 'newline' => "\r\n", // ]; // Load email library // $email = \Config\Services::email(); // $email->initialize($emailConfig); // Set email content // $email->setFrom('healthcare@medusyspty.com', 'Nparrots'); // $email->setTo($email); // $email->setSubject('Material Approval'); // $email->setMessage($email_content); // Send email $emailService->send(); return $this->response->setJSON(['result' => 1, 'message' => 'Approved Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function getNotEnrolledFacTimings() { $fac_id = $this->request->getPost('id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $domain_id = $this->request->getPost('domain_id'); $nparrotsModel = new Nparrots_Model(); $result = $nparrotsModel->getNotEnrolledFacTimings($fac_id, $sub_domain_id, $domain_id); 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 update_batch() // { // $batch_id = $this->request->getPost('batch_id'); // $login_id = session()->get('login_id'); // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $domain_id = $this->request->getPost('domain_id'); // if ($this->request->getPost('sub_domain_ids') != "") { // $sub_domain_id = $this->request->getPost('sub_domain_ids'); // } else { // $sub_domain_id = $this->request->getPost('sub_domain_id'); // } // if ($this->request->getPost('faculty_id') != "") { // $faculty_id = $this->request->getPost('faculty_id'); // } else { // $faculty_id = $this->request->getPost('faculty_names'); // } // if ($this->request->getPost('from_time') != "") { // $from_time = $this->request->getPost('from_time'); // } else { // $from_time = $this->request->getPost('time_list'); // } // $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'); // $batch_size = $this->request->getPost('batch_size'); // Replace with the actual name of your input field // $batchTable = 'batches'; // Replace with the actual table name // $where = [ // 'course_type' => $course_type, // 'sub_domain_id' => $sub_domain_id, // 'delete_status' => 'ACTIVE', // 'from_time' => $from_time, // 'batch_size' => $batch_size, // 'batch_type' => $batch_type // ]; // $whereData = [ // 'course_type' => $course_type, // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'delete_status' => 'ACTIVE', // 'from_time' => $from_time, // 'batch_size' => $batch_size, // 'batch_type' => $batch_type, // 'batch_id' => $batch_id, // 'faculty_id' => $faculty_id, // 'batch_from_date' => $batch_from_date, // 'batch_to_date' => $batch_to_date, // 'batch_duration' => $batch_duration // ]; // $nparrotsModel = new Nparrots_Model(); // Replace with the actual model name // $resultData = $nparrotsModel->getWhereRow($batchTable, $whereData); // $result = $nparrotsModel->getWhereRow($batchTable, $where); // if (!$result) { // if ($course_type == "Recorded") { // if ($batch_size != '') { // $batchData = [ // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'faculty_id' => $faculty_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, // 'created_at' => $created_at // ]; // $whereId = ['batch_id' => $batch_id, 'delete_status' => 'ACTIVE']; // $result = $nparrotsModel->updateData($whereId, $batchTable, $batchData); // if ($result->resultID->numRows > 0) { // return json_encode(['result' => 1, 'message' => 'Batch updated successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong... try again']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Details cannot be empty! Please fill all the details']); // } // } elseif ($faculty_id == "" || $faculty_id == "0" || $from_time == "" || $from_time == "0" || $batch_size == "") { // return json_encode(['result' => 0, 'message' => 'Details cannot be empty! Please fill all the details']); // } else { // $batchData = [ // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'faculty_id' => $faculty_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, // 'created_at' => $created_at // ]; // $whereId = ['batch_id' => $batch_id, 'delete_status' => 'ACTIVE']; // $result = $nparrotsModel->updateData($whereId, $batchTable, $batchData); // if ($result->resultID->numRows > 0) { // return json_encode(['result' => 1, 'message' => 'Batch updated successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong... try again']); // } // } // } elseif ($resultData) { // return json_encode(['result' => 1, 'message' => 'Batch updated successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Batch already created!']); // } // } // public function update_batch() // { // $nparrotsModel = new Nparrots_Model(); // $batch_id = $this->request->getPost('batch_id'); // $login_id = session('login_id'); // $date = new Time('now', 'Asia/Kolkata'); // $created_at = $date->format('Y-m-d H:i:s'); // $domain_id = $this->request->getPost('domain_id'); // $sub_domain_id = $this->request->getPost('sub_domain_ids') != "" ? $this->request->getPost('sub_domain_ids') : $this->request->getPost('sub_domain_id'); // $faculty_id = $this->request->getPost('faculty_id') != "" ? $this->request->getPost('faculty_id') : $this->request->getPost('faculty_names'); // $from_time = $this->request->getPost('from_time') != "" ? $this->request->getPost('from_time') : $this->request->getPost('time_list'); // $batch_name = $this->request->getPost('batch_name'); // $batch_type = $this->request->getPost('batch_type'); // $batch_range_size = $this->request->getPost('batch_range_size'); // $batch_size = ($batch_type == 'Fixed') ? $this->request->getPost('batch_fixed_size') : $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'); // $batch_table = 'batches'; // $where = [ // 'course_type' => $course_type, // 'sub_domain_id' => $sub_domain_id, // 'delete_status' => 'ACTIVE', // 'from_time' => $from_time, // 'batch_size' => $batch_size, // 'batch_type' => $batch_type, // ]; // $where_data = [ // 'course_type' => $course_type, // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'delete_status' => 'ACTIVE', // 'from_time' => $from_time, // 'batch_size' => $batch_size, // 'batch_type' => $batch_type, // 'batch_id' => $batch_id, // 'faculty_id' => $faculty_id, // 'batch_from_date' => $batch_from_date, // 'batch_to_date' => $batch_to_date, // 'batch_duration' => $batch_duration, // ]; // $result_data = $nparrotsModel->getWhereRow($batch_table, $where_data); // $result = $nparrotsModel->getWhereRow($batch_table, $where); // if (!$result) { // if ($course_type == "Recorded") { // if ($batch_size != '') { // $batch_data = [ // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'faculty_id' => $faculty_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, // 'created_at' => $created_at, // ]; // $where_id = ['batch_id' => $batch_id, 'delete_status' => 'ACTIVE']; // $result = $nparrotsModel->updateData($where_id, $batch_table, $batch_data); // if ($this->db->affectedRows() > 0) { // return json_encode(['result' => 1, 'message' => 'Batch updated successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } else { // return json_encode(['result' => 0, 'message' => 'Details Cannot be empty! Please Fill All the Details']); // } // } else if ($faculty_id == "" || $faculty_id == "0" || $from_time == "" || $from_time == "0" || $batch_size == "") { // return json_encode(['result' => 0, 'message' => 'Details Cannot be empty! Please Fill All the Details']); // } else { // $batch_data = [ // 'domain_id' => $domain_id, // 'sub_domain_id' => $sub_domain_id, // 'faculty_id' => $faculty_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, // 'created_at' => $created_at, // ]; // $where_id = ['batch_id' => $batch_id, 'delete_status' => 'ACTIVE']; // $result = $nparrotsModel->updateData($where_id, $batch_table, $batch_data); // if ($this->db->affectedRows() > 0) { // return json_encode(['result' => 1, 'message' => 'Batch updated successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Something went wrong.. try again']); // } // } // } else if ($result_data) { // return json_encode(['result' => 1, 'message' => 'Batch updated successfully']); // } else { // return json_encode(['result' => 0, 'message' => 'Batch already created!']); // } // } public function update_batch() { $model = new Batch_Model(); $batch_id = $this->request->getPost('batch_id'); $login_id = session()->get('login_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $domain_id = $this->request->getPost('domain_id'); if ($this->request->getPost('sub_domain_ids') != "") { $sub_domain_id = $this->request->getPost('sub_domain_ids'); } else { $sub_domain_id = $this->request->getPost('sub_domain_id'); } if ($this->request->getPost('faculty_id') != "") { $faculty_id = $this->request->getPost('faculty_id'); } else { $faculty_id = $this->request->getPost('faculty_names'); } if ($this->request->getPost('from_time') != "") { $from_time = $this->request->getPost('from_time'); } else { $from_time = $this->request->getPost('time_list'); } $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'); $batch_table = 'batches'; $where = [ 'course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time, 'batch_size' => $batch_size, 'batch_type' => $batch_type ]; $where_data = [ 'course_type' => $course_type, 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time, 'batch_size' => $batch_size, 'batch_type' => $batch_type, 'batch_id' => $batch_id, 'faculty_id' => $faculty_id, 'batch_from_date' => $batch_from_date, 'batch_to_date' => $batch_to_date, 'batch_duration' => $batch_duration ]; $result_data = $model->getWhereRow($batch_table, $where_data); $result = $model->getWhereRow($batch_table, $where); if (!$result) { if ($course_type == "Recorded") { if ($batch_size != '') { $batch_data = [ 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'faculty_id' => $faculty_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, 'created_at' => $created_at ]; $where_id = ['batch_id' => $batch_id, 'delete_status' => 'ACTIVE']; $result = $model->updateData($where_id, $batch_table, $batch_data); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Batch updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong.. try again']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Details cannot be empty! Please fill in all the details']); } } elseif ($faculty_id == "" || $faculty_id == "0" || $from_time == "" || $from_time == "0" || $batch_size == "") { return $this->response->setJSON(['result' => 0, 'message' => 'Details cannot be empty! Please fill in all the details']); } else { $batch_data = [ 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'faculty_id' => $faculty_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, 'created_at' => $created_at ]; $where_id = ['batch_id' => $batch_id, 'delete_status' => 'ACTIVE']; $result = $model->updateData($where_id, $batch_table, $batch_data); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Batch updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong.. try again']); } } } elseif ($result_data) { return $this->response->setJSON(['result' => 1, 'message' => 'Batch updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Batch already created!']); } } public function deleteSyllabus() { $chapterId = $this->request->getPost('id'); $data = ['delete_status' => 'INACTIVE']; $where = ['chapter_id' => $chapterId]; $topicsTable = 'topics'; $Model = new Nparrots_Model(); $Model->updateData($where, $topicsTable, $data); $syllabusChapterTable = 'syllabus_chapter'; $Model->updateData($where, $syllabusChapterTable, $data); if ($Model->affectedRows() > 0) { $where = ['chapter_id' => $chapterId, 'delete_status' => 'ACTIVE']; $subjectMaterialsTable = 'subject_materials'; $Model->updateData($where, $subjectMaterialsTable, $data); return json_encode(['result' => 1, 'message' => 'Deleted Successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something went wrong...']); } } public function check_material_training() { $chapter_id = $this->request->getPost('id'); $where = [ 'chapter_id' => $chapter_id, 'delete_status' => 'ACTIVE', 'approval_status' => 'APPROVED' ]; $table = 'subject_materials'; // Load the model (assuming you have a model called NparrotsModel) $model = new Nparrots_Model(); $material = $model->getWhereRow($table, $where); $j = 0; if ($material) { $j = $j + 1; } $where_training = [ 'delete_status' => 'ACTIVE', 'approval_status' => 'APPROVED' ]; $training_table = 'training_plans'; $training_plans = $model->getWhereResult($training_table, $where_training); $i = 0; foreach ($training_plans as $plan) { $chapter_ids = json_decode($plan->chapter_ids); foreach ($chapter_ids as $id) { if ($id == $chapter_id) { $i = $i + 1; } } } if ($j >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'You cannot delete, material is added to this chapter']); } elseif ($i >= 1) { return $this->response->setJSON(['result' => 0, 'message' => 'You cannot delete, training plan is added to this chapter']); } else { return $this->response->setJSON(['result' => 1]); } } public function checkTestStatus() { $material_id = $this->request->getVar('material_id'); $faculty_id = $this->request->getVar('faculty_id'); $sub_domain_id = $this->request->getVar('sub_domain_id'); // Assuming you have loaded the database library, you can use the following to query the database. $db = db_connect(); $table = 'user_course_mapping'; $where = [ 'enroll_status' => 'ENROLLED', 'payment_status' => 'PAID', ]; // Check if faculty_id is not null before using it in the like condition. if ($faculty_id !== null) { $where['faculty_ids'] = $faculty_id; $query = $db->table($table) ->where($where) ->like('sub_domain_ids') ->get(); } else { $query = $db->table($table) ->where($where) ->like('sub_domain_ids') ->get(); } $result = $query->getResult(); $table = 'question_mapping'; $where = ['material_id' => $material_id]; $res = $db->table($table)->where($where)->get()->getRow(); if ($result) { return $this->response->setJSON(['result' => 2]); } elseif ($res) { $test_status = $res->test_status; if ($test_status == 'ONGOING') { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 3]); } } else { return $this->response->setJSON(['result' => 3]); } } public function deleteSubjectMaterial() { $loginId = session()->get('faculty_login_id'); $materialId = $this->request->getPost('material_id'); $createdBy = $this->request->getPost('faculty_id'); $where = ['material_id' => $materialId, 'created_by' => $loginId]; $whereQ = ['material_id' => $materialId]; $table = 'subject_materials'; $data = ['delete_status' => 'INACTIVE']; $table1 = 'questions'; $data1 = ['status' => 'INACTIVE']; $Model = new Nparrots_Model(); // Assuming you have a model named NparrotsModel $result = $Model->updateData($where, $table, $data); if ($Model->db->affectedRows() > 0) { $result1 = $Model->updateData($whereQ, $table1, $data1); return json_encode(['result' => 1, 'message' => 'Deleted Successfully']); } else { return json_encode(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function getWhereMaterialDetailsAdmin() { $material_id = $this->request->getPost('material_id'); $model = new Nparrots_Model(); // Replace with your model's namespace $result = $model->getWhereMaterialDetailsAdmin($material_id); if ($result) { $created_at = date('d-m-Y H:i:s', strtotime($result->created_at)); return $this->response->setJSON(['result' => 1, 'message' => $result, 'created_at' => $created_at]); } else { return $this->response->setJSON(['result' => 0]); } } public function singleBatchDetails() { $table = 'batches'; $model = new Nparrots_Model(); $batchId = $this->request->getPost('batch_id'); // Change to request object for CodeIgniter 4 $result = $model->getWhereBatches($batchId); if ($result) { return $this->response->setJSON(['batch_details' => $result, 'result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } // UPDATE CONTROLLER public function approve_faculty_batch() { $model = new Batch_Model(); $facultyId = $this->request->getPost('faculty_id'); $batchId = $this->request->getPost('id'); $table = 'batches'; $where = ['batch_id' => $batchId, 'delete_status' => 'ACTIVE', 'faculty_id' => $facultyId]; $data = ['batch_approval_status' => 'APPROVED']; $result = $model->updateData($where, $table, $data); $createdBy = $model->getWhereRow($table, $where); $loginTable = 'login'; $whereLogin = ['login_id' => $facultyId, 'delete_status' => 'ACTIVE']; $emailResult = $model->getWhereRow($loginTable, $whereLogin); $email = $emailResult->email; $userName = $emailResult->username; $subTable = 'batches'; $whereSub = ['faculty_id' => $createdBy->faculty_id, 'delete_status' => 'ACTIVE']; $subject = $model->getWhereRow($subTable, $whereSub); $subDomainId = $subject->sub_domain_id; $batchTime = $subject->from_time; $batchFromDate = $subject->batch_from_date; $batchToDate = $subject->batch_to_date; $batchSize = $subject->batch_size; $subTable = 'sub_domains'; $whereSub = ['sub_domain_id' => $subDomainId, 'delete_status' => 'ACTIVE']; $subject = $model->getWhereRow($subTable, $whereSub); $subjectName = $subject->sub_domain; if ($result) { //$email = service('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;">Faculty Batch Approval</h3>'; $content .= '<p style="font-size:16px;padding-bottom:10px;">Hello '.$userName.', Your Batch has been Approved for the subject '.$subjectName.' for timings '.$batchTime.' from '.$batchFromDate.' till '.$batchToDate.' of batch size '.$batchSize.'. </p>'; $content .= '</div>'; $content .= '</div>'; $content .= '</div>'; $content .= '</body>'; $emailService = \Config\Services::email(); $emailService->setMessage($content); $emailService->setTo($email); $emailService->setSubject("Faculty Batch Approval"); $emailService->send(); return $this->response->setJSON(['result' => 1, 'message' => 'Approved Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } public function add_batch() { $model = new Batch_Model(); $login_id = session()->get('login_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $domain_id = $this->request->getPost('domain_id'); $sub_domain_id = $this->request->getPost('sub_domain_id'); $faculty_id = $this->request->getPost('faculty_id'); $batch_name = $this->request->getPost('batch_name'); $batch_type = $this->request->getPost('batch_type'); if ($batch_type == 'Fixed') { $batch_size = $this->request->getPost('batch_fixed_size'); } elseif ($batch_type == 'Range') { $batch_size = $this->request->getPost('batch_range_size'); } $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'); $course_type = $this->request->getPost('course_type'); if ($course_type == 'Live') { $from_time = $this->request->getPost('from_time'); if ($domain_id == '' || $sub_domain_id == '' || $faculty_id == '' || $batch_type == '' || $batch_size == '' || $batch_size == '0' || $batch_from_date == '' || $batch_to_date == '' || $from_time == '') { return $this->response->setJSON(['result' => 0, 'message' => 'Please fill all details!']); } else { $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 = $model->getWhereRow($table, $where); if (!$result) { $where1 = [ 'course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', 'from_time' => $from_time, ]; $result1 = $model->getWhereRow($table, $where1); if (!$result1) { $batch_table = 'batches'; $batch_data = [ 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'faculty_id' => $faculty_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, 'created_at' => $created_at, ]; $result = $model->insertData($batch_table, $batch_data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Batch added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong.. try again']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Batch already created']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Batch already created']); } } } else { $from_time = ''; if ($domain_id == '' || $sub_domain_id == '' || $faculty_id == '' || $batch_type == '' || $batch_size == '' || $batch_size == '0' || $batch_from_date == '' || $batch_to_date == '') { return $this->response->setJSON(['result' => 0, 'message' => 'Please fill all details!']); } else { $table = 'batches'; $where = [ 'course_type' => $course_type, 'sub_domain_id' => $sub_domain_id, 'delete_status' => 'ACTIVE', ]; $result = $model->getWhereRow($table, $where); if (!$result) { $where1 = [ 'batch_name' => $batch_name, 'delete_status' => 'ACTIVE', ]; $result1 = $model->getWhereRow($table, $where1); if (!$result1) { $batch_table = 'batches'; $batch_data = [ 'domain_id' => $domain_id, 'sub_domain_id' => $sub_domain_id, 'faculty_id' => $faculty_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, 'created_at' => $created_at, ]; $result = $model->insertData($batch_table, $batch_data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Batch added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong.. try again']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Batch already created']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Batch already created']); } } } } }