load->model('HmsAdmin_Model'); $this->load->model('classroom_model'); $this->nepaliDateObject = new NepaliDate(); //Load the required helpers here $this->load->helper('common_helper'); $this->nepali_current_date = cuurentNepaliDate($this->nepaliDateObject); } public function is_valid_admin_emailid($eid) { $this->form_validation->set_message('is_valid_admin_emailid', 'This Email Id does not exist. Please check again.'); if ($this->HmsAdmin_Model->check_is_emailid_valid($eid)) return true; else return false; } public function is_valid_admin_credentials() { $eid = $_POST['email']; $encrypt_password = md5($_POST['password']); $this->form_validation->set_message('is_valid_admin_credentials', 'Invalid password. Please check again.'); if ($this->HmsAdmin_Model->check_login_credentials($eid, $encrypt_password)) return true; else return false; } public function login() { $data['title'] = 'Admin Login'; $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_is_valid_admin_emailid'); $this->form_validation->set_rules('password', 'Password', 'required'); if (isset($_POST['password']) && $_POST['password'] != '') $this->form_validation->set_rules('password', 'Password', 'callback_is_valid_admin_credentials'); if ($this->form_validation->run() === FALSE) { $this->load->view('hms-admin/login', $data); //echo '
'; print_r($this->form_validation);exit; } else { $encrypt_password = md5($this->input->post('password')); $where = 'email="' . $this->input->post('email') . '" AND password="' . $encrypt_password . '"'; $loginData = $this->HmsAdmin_Model->get_admin_details($where); if (isset($loginData[0]) && !empty($loginData[0])) { if ($loginData[0]['status'] == 'Active') { if (isset($_POST['remember_me']) && $_POST['remember_me'] == 'on') { //set 0 instead of time to remove the cookie once the browser is closed setcookie("username", $_POST["email"], time() + 86400); //86400 seconds in a day setcookie("password", $_POST["password"], time() + 86400); setcookie("rem_me", 'On', time() + 86400); // test_view_array($_COOKIE); } else { if (isset($_COOKIE['username'])) { unset($_COOKIE['username']); setcookie('username', ''); } if (isset($_COOKIE['password'])) { unset($_COOKIE['password']); setcookie('password', ''); } if (isset($_COOKIE['rem_me'])) { unset($_COOKIE['rem_me']); setcookie('rem_me', ''); } } $lnData = array( 'hms_lin_id' => $loginData[0]['id'], 'hms_lin_name' => $loginData[0]['admin_name'], 'hms_lin_login' => true, ); $this->session->set_userdata('hmsAULoginData', $lnData); //Set Message $this->session->set_flashdata('success', 'Welcome To Admin Users Dashboard.'); $redirectToHere = 'dashboard'; $detailsHere = $this->HmsAdmin_Model->get_admin_details('', "SELECT admin_role_ids FROM hms_admin WHERE id = " . $loginData[0]['id']); if (isset($detailsHere[0]['admin_role_ids']) && $detailsHere[0]['admin_role_ids'] != '') { $permissionDetailsHere = $this->HmsAdmin_Model->get_hms_admin_role_permissions('', "SELECT menu_ids FROM hms_admin_role_permissions WHERE admin_role_ids IN(" . $detailsHere[0]['admin_role_ids'] . ")"); $menuIdsHere = explode(',', $permissionDetailsHere[0]['menu_ids']); if (!empty($menuIdsHere)) { $menuDetailsHere = $this->HmsAdmin_Model->get_admin_menu_details('', "SELECT page_link FROM hms_admin_menu WHERE id =" . $menuIdsHere[0]); if (isset($menuDetailsHere[0]['page_link']) && $menuDetailsHere[0]['page_link'] != '') $redirectToHere = $menuDetailsHere[0]['page_link']; } } //echo base_url().$redirectToHere;exit; redirect(base_url() . $redirectToHere); } else { $this->session->set_flashdata('danger', 'Your account is inactive. Please contact the administrator.'); $this->load->view('hms-admin/login', $data); } } else { $this->session->set_flashdata('danger', 'Login Credential in invalid!'); $this->load->view('hms-admin/login', $data); } } } /*----------------------------------- SATRT Of Logout --------------------------------------------------------*/ public function logout() { $this->common_logout(); //Set Message $this->session->set_flashdata('success', 'You are logged out successfully.'); redirect(base_url() . 'admin'); } public function common_logout() { $lnEuIdId = 0; // unset the loggout admin user data $this->session->unset_userdata('hmsAULoginData'); } public function ajaxLogout() { $this->common_logout(); echo 'Success'; exit; } /*----------------------------------- ENDDD Of Logout --------------------------------------------------------*/ /*----------------------------- START of Admin User Password Functionality -----------------------------*/ public function fp_check_is_emailid_valid($eid) { $this->form_validation->set_message('fp_check_is_emailid_valid', 'This Email Id does not exist. Please check again.'); if ($this->HmsAdmin_Model->check_is_emailid_valid($eid)) return true; else { return false; } } public function forgot_password() { if (!file_exists(APPPATH . 'views/hms-admin/forgot-password.php')) show_404(); $data['title'] = 'Forgot Password'; $this->form_validation->set_rules('email', 'email', 'required|valid_email|callback_fp_check_is_emailid_valid'); if ($this->form_validation->run() === FALSE) { $this->load->view('hms-admin/forgot-password', $data); } else { $where = 'email="' . $this->input->post('email') . '" '; $detailsHere = $this->HmsAdmin_Model->get_admin_details($where); $rpData['nameHere'] = ''; if (isset($detailsHere[0]['admin_name'])) $rpData['nameHere'] = $detailsHere[0]['admin_name']; $rpData['emailId'] = urlsafe_b64encode($this->input->post('email')); $emailContent = $this->load->view('hms-admin/emails/admin-user-forgot-password.php', $rpData, TRUE); $emailData['to'] = $this->input->post('email'); $emailData['subject'] = 'Blackboard Hostel - Admin User Password Recovery Mail'; $emailData['message'] = $emailContent; //echo $emailContent;exit; $result = ciSendEmail($emailData); $this->session->set_userdata('isForgotPasswordSuccess', 'Yes'); $this->load->view('hms-admin/forgot-password', $data); } } function reset_password($encodedEmailId) { if (isset($encodedEmailId) && $encodedEmailId != '') { $decodedEmailId = urlsafe_b64decode($encodedEmailId); $data['encodedEmailId'] = $encodedEmailId; $data['title'] = 'Reset Password'; $this->form_validation->set_rules('password', 'Enter New Password', 'trim|required'); $this->form_validation->set_rules('conf_password', 'Retype New Password', 'required|matches[password]'); if ($this->form_validation->run() === FALSE) { $this->load->view('hms-admin/reset-password', $data); } else { $where = 'email ="' . $decodedEmailId . '"'; $isValidUser = $this->HmsAdmin_Model->get_admin_details($where); if (!empty($isValidUser) && count($isValidUser) == 1) { $this->HmsAdmin_Model->reset_admin_password($isValidUser[0]['id'], $this->input->post('password')); //Set Message $this->session->set_userdata('isResetPasswordSuccess', 'Yes'); redirect('reset-password/' . $encodedEmailId); } else { $this->session->set_flashdata('danger', 'OOps. Something went wrong.'); redirect('reset-password/' . $encodedEmailId); } } } else { redirect(base_url() . "admin"); } } /*----------------------------- ENDDD of Admin User Password Functionality -----------------------------*/ /*----------------------------------- START Of Admin Roles --------------------------------------------------------*/ public function roles() { $data['title'] = 'Roles'; $sqlRole = 'SELECT r.*, rp.menu_ids FROM hms_admin_roles AS r, hms_admin_role_permissions AS rp WHERE r.id = rp.admin_role_ids'; $rolesList = $this->HmsAdmin_Model->get_hms_admin_roles('', $sqlRole); if (!empty($rolesList)) { foreach ($rolesList as $key => $role) { $rPs = ''; $sqlRolePermissions = 'SELECT menu_name FROM hms_admin_menu WHERE id IN(' . $role['menu_ids'] . ')'; $rolePermissions = $this->HmsAdmin_Model->get_hms_admin_roles('', $sqlRolePermissions); if (!empty($rolePermissions)) { foreach ($rolePermissions as $p) { if ($rPs == '') $rPs = $p['menu_name']; else $rPs .= ',' . $p['menu_name']; } } $rolesList[$key]['permissions'] = $rPs; } } $data['roleList'] = $rolesList; //echo ''; print_r($data['roleList']);exit; $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header', $data); $this->load->view('hms-admin/roles', $data); $this->load->view('hms-admin/common/footer'); } public function ajaxCheckIsRoleAlreadyExists() { $result = 'Insufficient Data'; if (isset($_POST['role_name']) && $_POST['role_name'] != '' && isset($_POST['id']) && $_POST['id'] != '') { if ($this->HmsAdmin_Model->check_role_exists($_POST['id'], $_POST['role_name'])) $result = 'Unique Role'; else $result = 'Duplicate Role'; } echo $result; exit; } public function add_edit_role($idVal) { $sql = "SELECT * FROM hms_admin_roles WHERE id = $idVal"; $details = $this->HmsAdmin_Model->get_hms_admin_roles("id = $idVal"); if (empty($details) && $idVal != 0) redirect(base_url() . 'roles'); $data['title'] = 'Add New Role'; if ($idVal > 0) $data['title'] = 'Update Role'; $data['details'] = $details; $data['idVal'] = $idVal; $data['menus'] = $this->HmsAdmin_Model->get_admin_menu_details('', 'SELECT id,menu_name FROM hms_admin_menu WHERE status="Active" AND parent_id=0'); $data['role_permissions'] = $this->HmsAdmin_Model->get_hms_admin_role_permissions('', "SELECT menu_ids FROM hms_admin_role_permissions WHERE admin_role_ids = $idVal"); if (count($_POST) > 0) { $permissions = ''; if (isset($_POST['role_permissions']) && !empty($_POST['role_permissions'])) { $permissions = implode(',', $_POST['role_permissions']); unset($_POST['role_permissions']); } $res = $this->HmsAdmin_Model->add_edit_admin_role($idVal, $_POST); if ($res) { if ($permissions != '') { if ($idVal == 0) { $rpData['admin_role_ids'] = $res; $rpData['menu_ids'] = $permissions; $this->HmsAdmin_Model->add_edit_admin_role_permissions(0, $rpData); } else { $getRPrid = $this->HmsAdmin_Model->get_hms_admin_role_permissions('', "SELECT id FROM hms_admin_role_permissions WHERE admin_role_ids = $idVal"); if (isset($getRPrid[0]['id'])) { $rpData['admin_role_ids'] = $idVal; $rpData['menu_ids'] = $permissions; $this->HmsAdmin_Model->add_edit_admin_role_permissions($getRPrid[0]['id'], $rpData); } } } $this->session->set_flashdata('success', str_replace('%s', 'new role', THE_ADD_SUCCESS_MSG)); if ($idVal > 0) $this->session->set_flashdata('success', str_replace('%s', 'role', THE_UPDATE_SUCCESS_MSG)); } redirect(base_url() . 'roles'); } $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header', $data); $this->load->view('hms-admin/add-edit-role', $data); } public function delete_role() { $roleId = $_POST['id']; $sql = "SELECT id FROM hms_admin WHERE admin_role_ids=" . $roleId; $result = $this->HmsAdmin_Model->get_admin_details('', $sql); //echo ''; print_r($result);exit; if (!empty($result)) echo 'Error'; else { $this->HmsAdmin_Model->delete_admin_role($roleId); echo 'Success'; } } /*----------------------------------- ENDDD Of Admin Roles --------------------------------------------------------*/ /*----------------------------------- START Of Admin Users --------------------------------------------------------*/ public function users() { $data['title'] = 'Users'; $sql = 'SELECT a.*, ar.role_name FROM hms_admin AS a, hms_admin_roles AS ar WHERE a.admin_role_ids = ar.id'; $data['userList'] = $this->HmsAdmin_Model->get_admin_details('', $sql); $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header', $data); $this->load->view('hms-admin/users', $data); } public function ajaxCheckIsUserEmailAlreadyExists() { $result = 'Insufficient Data'; if (isset($_POST['email']) && $_POST['email'] != '' && isset($_POST['id']) && $_POST['id'] != '') { if ($this->HmsAdmin_Model->check_emailid_exists($_POST['id'], $_POST['email'])) $result = 'Unique Email'; else $result = 'Duplicate Email'; } echo $result; exit; } public function add_edit_user($idVal) { $sql = "SELECT * FROM hms_admin WHERE id = $idVal"; $details = $this->HmsAdmin_Model->get_admin_details("id = $idVal"); if (empty($details) && $idVal != 0) redirect(base_url() . 'users'); $data['title'] = 'Add New User'; if ($idVal > 0) $data['title'] = 'Update User'; $data['details'] = $details; $data['idVal'] = $idVal; $data['roles'] = $this->HmsAdmin_Model->get_hms_admin_roles('', 'SELECT id,role_name FROM hms_admin_roles WHERE status="Active"'); if (count($_POST) > 0) { if (isset($_POST['password'])) $_POST['password'] = md5($_POST['password']); if (isset($_POST['confirm_password'])) unset($_POST['confirm_password']); $res = $this->HmsAdmin_Model->add_edit_admin_user($idVal, $_POST); $this->session->set_flashdata('success', str_replace('%s', 'new user', THE_ADD_SUCCESS_MSG)); if ($idVal > 0) $this->session->set_flashdata('success', str_replace('%s', 'user', THE_UPDATE_SUCCESS_MSG)); redirect(base_url() . 'users'); } $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header', $data); $this->load->view('hms-admin/add-edit-user', $data); } public function delete_user() { $userId = $_POST['id']; $result = $this->HmsAdmin_Model->delete_admin_user($userId); if ($result) echo 'Success'; else echo 'Error'; } /*----------------------------------- ENDDD Of Admin Users --------------------------------------------------------*/ /*############################################ ENDDD Of Coding By Nandini ############################################*/ // ================== Blocks Start - Afras khan - 02-12-2021 ================== public function blocks() { $sql = "SELECT b.id, b.block_name, (SELECT COUNT(*) from hms_floors f where f.block_id = b.id ) as floor_count, (SELECT COUNT(*) from hms_rooms where room_block_id = b.id) as room_count, (SELECT COUNT(*) from hms_beds where block_id = b.id ) as beds_count, (SELECT COUNT(*) from hms_students where block_id = b.id ) as student_count from hms_blocks b"; $data['blocks_data'] = $this->HmsAdmin_Model->get_table_info('hms_blocks', '', $sql); $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header'); $this->load->view('hms-admin/blocks'); $this->load->view('hms-admin/common/footer'); } public function delete_block($block_id) { $arr['block_id'] = $block_id; $check_if_student_assigned = $this->HmsAdmin_Model->get_table_info('hms_students', $arr); if (empty($check_if_student_assigned)) { $sql = $this->HmsAdmin_Model->deleteTable('hms_blocks', $block_id); if ($sql) { $floor_del_data['block_id'] = $block_id; $delete_floors = $this->HmsAdmin_Model->deleteTable('hms_floors', '', $floor_del_data); if ($delete_floors) { $this->session->set_flashdata('success', str_replace('%s', 'Block', THE_DELETE_SUCCESS_MSG)); redirect(base_url() . 'blocks'); } else { $this->session->set_flashdata('failed', str_replace('%s', 'Block', THE_DELETE_ERROR_MSG)); redirect(base_url() . 'blocks'); } } else { $this->session->set_flashdata('failed', str_replace('%s', 'Block', THE_DELETE_ERROR_MSG)); redirect(base_url() . 'blocks'); } } else { $this->session->set_flashdata('failed', 'Block cannot be deleted, as a student is been assigned to it'); redirect(base_url() . 'blocks'); } } public function ae_blocks($block_id) { if ($block_id == 0) { $block_name = $this->input->post('block_name'); $floor_names = $this->input->post('floor_names'); $insert_block_data = array( 'block_name' => $block_name, 'created' => $this->nepali_current_date ); $inserted_block_id = $this->HmsAdmin_Model->add_edit_table('hms_blocks', $block_id, $insert_block_data); if ($inserted_block_id) { $floors_insert_data = array(); foreach ($floor_names as $key => $value) { $floors_insert_data[$key]['block_id'] = $inserted_block_id; $floors_insert_data[$key]['floor_name'] = $value; $floors_insert_data[$key]['created'] = $this->nepali_current_date; } // test_view_array($floors_insert_data); $insert_floors = $this->HmsAdmin_Model->insert_batch_data('hms_floors', $floors_insert_data); if ($insert_floors) { $this->session->set_flashdata('success', str_replace('%s', 'Block and Floors', THE_ADD_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/blocks'); } else { $this->session->set_flashdata('failed', str_replace('%s', 'Floors', THE_ADD_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/blocks'); } } else { $this->session->set_flashdata('failed', str_replace('%s', 'Block', THE_ADD_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/blocks'); } // if ID is greater than 0 condition starts } else { $block_name = $this->input->post('block_edit_name'); $floor_names = $this->input->post('floor_edit_names'); $update_block_data = array( 'block_name' => $block_name, 'modified' => $this->nepali_current_date ); $update_block_name = $this->HmsAdmin_Model->add_edit_table('hms_blocks', $block_id, $update_block_data); if (!$update_block_name) { $this->session->set_flashdata('failed', str_replace('%s', 'Block', THE_UPDATE_ERROR_MSG)); redirect(base_url() . 'blocks'); } $sql = "Select id, floor_name from hms_floors where block_id = '$block_id'"; $get_old_floors = $this->HmsAdmin_Model->get_table_info('hms_floors', '', $sql); // test_view_array($get_old_floors); $count_of_exisiting_floors = count($get_old_floors); $floors_update_data = array(); $to_be_isnerted = array(); $to_be_count = 0; foreach ($floor_names as $key => $value) { if ($count_of_exisiting_floors > 0) { foreach ($get_old_floors as $index => $ele) { $floors_update_data[$key]['id'] = $get_old_floors[$key]['id']; $floors_update_data[$key]['floor_name'] = $value; $floors_update_data[$key]['modified'] = $this->nepali_current_date; } $count_of_exisiting_floors--; } else { $to_be_isnerted[$to_be_count]['block_id'] = $block_id; $to_be_isnerted[$to_be_count]['floor_name'] = $value; } } $update_floor_names = $this->HmsAdmin_Model->update_block_floors($block_id, $floors_update_data); if ($update_floor_names) { if (!empty($to_be_isnerted)) { $insert_floors = $this->HmsAdmin_Model->insert_batch_data('hms_floors', $to_be_isnerted); if ($insert_floors) { $this->session->set_flashdata('success', str_replace('%s', 'Block and Floors', THE_UPDATE_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/blocks'); } else { $this->session->set_flashdata('failed', 'Could not add new floors to the block, However old floors have been updated'); redirect(base_url() . 'HmsAdmin/blocks'); } } else { $this->session->set_flashdata('success', str_replace('%s', 'Block and Floors', THE_UPDATE_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/blocks'); } } else { $this->session->set_flashdata('failed', str_replace('%s', 'Floors', THE_UPDATE_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/blocks'); } } } public function ajax_validate_block_name() { $blockName = strtolower($this->input->post('value')); $id = $this->input->post('id'); $query = $this->HmsAdmin_Model->check_value_exists('hms_blocks', array('LOWER(block_name)' => $blockName), $id); if ($query) echo 'success'; else echo 'failed'; } public function ajax_get_block_floor_info() { $block_id = $this->input->post('id'); if (!$block_id) return false; $block_name = $this->db->query("SELECT * FROM hms_blocks WHERE id = '$block_id'")->row()->block_name; $data_floors['block_id'] = $block_id; $floors = $this->HmsAdmin_Model->get_table_info('hms_floors', $data_floors, '', 'ASC'); $floor_html = ''; foreach ($floors as $key => $value) { $floor_html .= ''; $floor_html .= ''; if ($key !== 0) { $floor_html .= ''; } else { $floor_html .= ''; } $floor_html .= ''; } $response['block_name'] = $block_name; $response['floors'] = $floor_html; $json = json_encode($response); echo $json; } public function ajax_delete_floors() { $floor_id = $this->input->post('id'); $arr['floor_id'] = $floor_id; $check_if_student_assigned = $this->HmsAdmin_Model->get_table_info('hms_students', $arr); if (!empty($check_if_student_assigned)) { echo false; exit; } $floor_del_data['id'] = $floor_id; $delete_floors = $this->HmsAdmin_Model->deleteTable('hms_floors', '', $floor_del_data); $this->HmsAdmin_Model->deleteTable('hms_rooms', '', array('room_floor_id' => $floor_id)); $this->HmsAdmin_Model->deleteTable('hms_beds', '', array(' floor_id' => $floor_id)); if ($delete_floors) echo true; else echo false; } // ================== Blocks End - Afras khan - 02-12-2021 ================== // ================== Floors - Afras khan - 02-12-2021 ================== public function floors() { $sql = "Select b.block_name, f.*, (SELECT COUNT(*) from hms_rooms where room_floor_id = f.id ) as room_count, (SELECT COUNT(*) from hms_beds where floor_id = f.id ) as beds_count,(SELECT COUNT(*) from hms_students where floor_id = f.id ) as student_count from hms_floors f inner join hms_blocks b on b.id = f.block_id"; $data['floors_data'] = $this->HmsAdmin_Model->get_table_info('hms_floors', '', $sql); $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header'); $this->load->view('hms-admin/floors'); $this->load->view('hms-admin/common/footer'); } public function delete_floors($floor_id) { $arr['floor_id'] = $floor_id; $check_if_student_assigned = $this->HmsAdmin_Model->get_table_info('hms_students', $arr); if (!empty($check_if_student_assigned)) { $this->session->set_flashdata('failed', 'Cannot delete floor as a student is been assigned to it'); redirect(base_url() . 'HmsAdmin/floors'); } $floor_del_data['id'] = $floor_id; $delete_floors = $this->HmsAdmin_Model->deleteTable('hms_floors', '', $floor_del_data); if ($delete_floors) { $room_del_data['room_floor_id'] = $floor_id; $delete_rooms = $this->HmsAdmin_Model->deleteTable('hms_rooms', '', $room_del_data); $this->HmsAdmin_Model->deleteTable('hms_beds', '', array('floor_id' => $floor_id)); $this->session->set_flashdata('success', str_replace('%s', 'Floors', THE_DELETE_SUCCESS_MSG)); redirect(base_url() . 'floors'); } else { $this->session->set_flashdata('failed', str_replace('%s', 'Floors', THE_DELETE_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/floors'); } } public function ae_rooms($floor_id) { $rooms = $this->input->post('room_names'); $block_id = $this->input->post('block_id'); $ac = $this->input->post('ac'); if (isset($_POST['room_id'])) { // UPDATE ROOMS TO FLOOR $room_id = $this->input->post('room_id'); $count_of_exisiting_rooms = count($room_id); $rooms_update_data = array(); $to_be_isnerted = array(); $to_be_count = 0; foreach ($rooms as $key => $value) { if ($count_of_exisiting_rooms > 0) { foreach ($room_id as $index => $ele) { $rooms_update_data[$key]['id'] = $room_id[$key]; $rooms_update_data[$key]['room_name'] = $value; $rooms_update_data[$key]['room_ac'] = $ac[$key]; $rooms_update_data[$key]['modified'] = $this->nepali_current_date; } $count_of_exisiting_rooms--; } else { $to_be_isnerted[$to_be_count]['room_block_id'] = $block_id; $to_be_isnerted[$to_be_count]['room_floor_id'] = $floor_id; $to_be_isnerted[$to_be_count]['room_ac'] = $ac[$key]; $to_be_isnerted[$to_be_count]['room_name'] = $value; $to_be_isnerted[$to_be_count]['created'] = $this->nepali_current_date; $to_be_count++; } } $update_floor_rooms = $this->HmsAdmin_Model->update_floor_rooms($floor_id, $rooms_update_data); if ($update_floor_rooms) { if (!empty($to_be_isnerted)) { $insert_rooms = $this->HmsAdmin_Model->insert_batch_data('hms_rooms', $to_be_isnerted); if ($insert_rooms) { $this->session->set_flashdata('success', str_replace('%s', 'Floors and Rooms', THE_UPDATE_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/floors'); } else { $this->session->set_flashdata('failed', 'Could not add new rooms to the floors, However old rooms have been updated'); redirect(base_url() . 'HmsAdmin/floors'); } } else { $this->session->set_flashdata('success', str_replace('%s', 'Floors and Rooms', THE_UPDATE_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/floors'); } } else { $this->session->set_flashdata('failed', str_replace('%s', 'Rooms', THE_UPDATE_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/floors'); } } else { // ADDING ROOMS TO FLOOR $input_arr = array(); foreach ($rooms as $key => $value) { $input_arr[$key]['room_block_id'] = $block_id; $input_arr[$key]['room_floor_id'] = $floor_id; $input_arr[$key]['room_name'] = $value; $input_arr[$key]['room_ac'] = $ac[$key]; $input_arr[$key]['created'] = $this->nepali_current_date; } $insert_room_query = $this->HmsAdmin_Model->insert_batch_data('hms_rooms', $input_arr); if ($insert_room_query) { $this->session->set_flashdata('success', str_replace('%s', 'Rooms', THE_ADD_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/floors'); } else { $this->session->set_flashdata('failed', str_replace('%s', 'Rooms', THE_ADD_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/floors'); } } } public function ajax_get_floor_rooms_info() { $floor_id = $this->input->post('id'); if (!$floor_id) return false; $rooms_query = "SELECT b.block_name,r.room_ac,r.room_block_id,f.floor_name,r.room_floor_id,r.id as room_id,r.room_name FROM hms_rooms r INNER JOIN hms_floors f on r.room_floor_id = f.id INNER JOIN hms_blocks b on b.id = f.block_id WHERE room_floor_id = '$floor_id'"; $rooms = $this->HmsAdmin_Model->get_table_info('hms_rooms', '', $rooms_query); $sql = "Select b.id as block_id,b.block_name, f.floor_name from hms_floors f inner join hms_blocks b on b.id = f.block_id WHERE f.id = '$floor_id'"; $block_name = $this->db->query($sql)->row()->block_name; $floor_name = $this->db->query($sql)->row()->floor_name; $block_id = $this->db->query($sql)->row()->block_id; $rooms_html = ''; if (empty($rooms)) { $rooms_html .= ''; } else { foreach ($rooms as $key => $value) { $checked = $value['room_ac'] == 'A/C' ? 'checked' : ''; $rooms_html .= ''; } } $response['block_name'] = $block_name; $response['floor_name'] = $floor_name; $response['rooms'] = $rooms_html; $json = json_encode($response); echo $json; } public function ajax_delete_rooms() { $room_id = $this->input->post('id'); $arr['room_id'] = $room_id; $check_if_student_assigned = $this->HmsAdmin_Model->get_table_info('hms_students', $arr); if (!empty($check_if_student_assigned)) { echo false; exit; } $room_del_data['id'] = $room_id; $delete_floors = $this->HmsAdmin_Model->deleteTable('hms_rooms', '', $room_del_data); $this->HmsAdmin_Model->deleteTable('hms_beds', '', array('room_id' => $room_id)); if ($delete_floors) echo true; else echo false; } // ================== Floors End - Afras khan - 02-12-2021 ================== // ================== Rooms - Afras khan - 06-12-2021 ================== public function rooms() { $sql = "Select b.block_name, f.floor_name, r.*, (SELECT COUNT(*) from hms_beds where room_id = r.id) as beds_count from hms_rooms r inner join hms_floors f on r.room_floor_id = f.id inner join hms_blocks b on b.id = r.room_block_id"; $data['rooms_data'] = $this->HmsAdmin_Model->get_table_info('hms_floors', '', $sql); // test_view_array($data['floors_data']); $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header'); $this->load->view('hms-admin/rooms'); $this->load->view('hms-admin/common/footer'); } public function ae_beds($room_id) { $sql = "Select * from hms_rooms where id = '$room_id'"; $block_id = $this->db->query($sql)->row()->room_block_id; $floor_id = $this->db->query($sql)->row()->room_floor_id; $bed_names = $this->input->post('bed_names'); if (isset($_POST['bedId'])) { // UPDATE ROOMS TO FLOOR $bed_id = $this->input->post('bedId'); $count_of_exisiting_beds = count($bed_id); $bed_update_data = array(); $to_be_isnerted = array(); $to_be_count = 0; foreach ($bed_names as $key => $value) { if ($count_of_exisiting_beds > 0) { foreach ($bed_id as $index => $ele) { $bed_update_data[$key]['id'] = $bed_id[$key]; $bed_update_data[$key]['room_name'] = $value; $bed_update_data[$key]['modified'] = $this->nepali_current_date; } $count_of_exisiting_beds--; } else { $to_be_isnerted[$to_be_count]['block_id'] = $block_id; $to_be_isnerted[$to_be_count]['floor_id'] = $floor_id; $to_be_isnerted[$to_be_count]['room_id'] = $room_id; $to_be_isnerted[$to_be_count]['bed_name'] = $value; $to_be_isnerted[$to_be_count]['created'] = $this->nepali_current_date; $to_be_count++; } } if (!empty($to_be_isnerted)) { $insert_beds = $this->HmsAdmin_Model->insert_batch_data('hms_beds', $to_be_isnerted); if ($insert_beds) { $this->session->set_flashdata('success', str_replace('%s', 'Beds', THE_UPDATE_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/rooms'); } else { $this->session->set_flashdata('failed', 'Could not add new beds to the room, However old beds have been not changed'); redirect(base_url() . 'HmsAdmin/rooms'); } } else { $this->session->set_flashdata('success', str_replace('%s', 'Beds', THE_UPDATE_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/rooms'); } } else { // ADD BEDS $insert_arr = array(); foreach ($bed_names as $key => $value) { $insert_arr[$key]['block_id'] = $block_id; $insert_arr[$key]['floor_id'] = $floor_id; $insert_arr[$key]['room_id'] = $room_id; $insert_arr[$key]['bed_name'] = $value; $insert_arr[$key]['created'] = $this->nepali_current_date; } $insert_room_query = $this->HmsAdmin_Model->insert_batch_data('hms_beds', $insert_arr); if ($insert_room_query) { $this->session->set_flashdata('success', str_replace('%s', 'Rooms', THE_ADD_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/rooms'); } else { $this->session->set_flashdata('failed', str_replace('%s', 'Rooms', THE_ADD_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/rooms'); } } } public function ajax_get_rooms_bed_info() { $room_id = $this->input->post('id'); if (!$room_id) return false; $beds_query = "Select * from hms_beds where room_id = '$room_id'"; $beds = $this->HmsAdmin_Model->get_table_info('hms_beds', '', $beds_query); $beds_html = ''; if (!empty($beds)) { foreach ($beds as $key => $value) { $beds_html .= ''; if ($key != 0) { $rooms_html .= ''; } else { $rooms_html .= ''; } $rooms_html .= ''; if ($key == 0) { $beds_html .= ''; } else { $beds_html .= ''; } $beds_html .= ''; } } echo $beds_html; } public function delete_room($roomid) { $arr['room_id'] = $roomid; $check_if_student_assigned = $this->HmsAdmin_Model->get_table_info('hms_students', $arr); if (!empty($check_if_student_assigned)) { $this->session->set_flashdata('failed', 'Cannot delete room as a student is been assigned to it'); redirect(base_url() . 'HmsAdmin/rooms'); } $room_del_data['id'] = $roomid; $delete_rooms = $this->HmsAdmin_Model->deleteTable('hms_rooms', '', $room_del_data); if ($delete_rooms) { $bed_del_data['room_id'] = $roomid; $delete_beds = $this->HmsAdmin_Model->deleteTable('hms_beds', '', $bed_del_data); $this->session->set_flashdata('success', str_replace('%s', 'Room', THE_DELETE_SUCCESS_MSG)); redirect(base_url() . 'rooms'); } else { $this->session->set_flashdata('failed', str_replace('%s', 'Room', THE_DELETE_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/rooms'); } } public function ajax_delete_row() { $id = $this->input->post('id'); $arr['room_id'] = $id; $check_if_student_assigned = $this->HmsAdmin_Model->get_table_info('hms_students', $arr); if (!empty($check_if_student_assigned)) { echo false; exit; } $table = $this->input->post('table'); $data['id'] = $id; $delete_data = $this->HmsAdmin_Model->deleteTable($table, '', $data); if ($delete_data) echo true; else echo false; } // ================== Rooms End - Afras khan - 06-12-2021 ================== // ================== Beds - Afras khan - 07-12-2021 ================== public function beds() { $sql = "Select hs.student_id,be.id, be.bed_name, be.bed_status, b.block_name, f.floor_name, r.room_name, r.room_ac from hms_beds be inner join hms_rooms r on be.room_id = r.id inner join hms_floors f on be.floor_id = f.id inner join hms_blocks b on b.id = be.block_id left join hms_students hs on be.id = hs.bed_id;"; $data['beds_data'] = $this->HmsAdmin_Model->get_table_info('hms_beds', '', $sql); // test_view_array($data['floors_data']); $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header'); $this->load->view('hms-admin/beds'); $this->load->view('hms-admin/common/footer'); } public function delete_beds($id) { $arr['bed_id'] = $id; $check_if_student_assigned = $this->HmsAdmin_Model->get_table_info('hms_students', $arr); if (!empty($check_if_student_assigned)) { $this->session->set_flashdata('failed', 'Cannot delete bed as a student is been assigned to it'); redirect(base_url() . 'HmsAdmin/beds'); } $del_data['id'] = $id; $delete_row = $this->HmsAdmin_Model->deleteTable('hms_beds', '', $del_data); if ($delete_row) { $this->session->set_flashdata('success', str_replace('%s', 'Beds', THE_DELETE_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/beds'); } else { $this->session->set_flashdata('failed', str_replace('%s', 'Beds', THE_DELETE_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/beds'); } } // ================== Beds End - Afras khan - 07-12-2021 ================== // ================== Students - Afras khan - 07-12-2021 ================== public function students() { $sql = "Select c.classroom_name as classroom_name, s.id,s.name,s.studentId,s.emergency_contact_number from students s inner join student_batch sb on s.id = sb.student_id inner join classroom c on sb.classroom_id = c.id WHERE s.hostel = 'yes'"; $data['students'] = $this->classroom_model->get_table_info('students', '', $sql); $hms_data = $this->HmsAdmin_Model->get_table_info('hms_students'); if (!empty($hms_data)) { foreach ($hms_data as $index => $ele) { $room_name = $this->db->get_where('hms_rooms', array('id' => $ele['room_id']))->row()->room_name; foreach ($data['students'] as $key => $value) { if ($value['id'] == $ele['student_id']) { $data['students'][$key]['room_name'] = $room_name; } } } } $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header'); $this->load->view('hms-admin/students'); $this->load->view('hms-admin/common/footer'); } public function ae_assign_student($student_id) { // Get Blocks $blocks_sql = "Select b.*, be.bed_status,be.bed_name from hms_blocks b inner join hms_beds be on b.id = be.block_id WHERE be.bed_status = 'vacant' group by b.block_name"; $data['blocks'] = $this->HmsAdmin_Model->get_table_info('hms_blocks', '', $blocks_sql); $data['student_id'] = $student_id; $stud['student_id'] = $student_id; if (empty($data['blocks'])) { $this->session->set_flashdata('failed', 'No Beds are available'); redirect(base_url() . 'HmsAdmin/students'); } $check_if_exists = $this->HmsAdmin_Model->get_table_info('hms_students', $stud); $data['status'] = $status = empty($check_if_exists) ? 'Insert' : 'Update'; $sql = "Select * from students_online_payments sop inner join course_fees cf on sop.course_fee_id = cf.id inner join fee_types ft on ft.id = cf.fees_type WHERE sop.student_id = $student_id AND cf.fees_type = 3"; $opted_hostel = $this->classroom_model->get_table_info_row('students_online_payments', '', $sql); if (!empty($opted_hostel)) { $data['option'] = 'Note : Student has opted for ' . $opted_hostel['fee_values'] . '.'; $option = $opted_hostel['fee_values']; $arr = explode(' and ', $option); list($data['room_tye'], $data['food_type']) = $arr; } else { $this->session->set_flashdata('failed', 'Student has not paid any amount'); redirect(base_url() . 'HmsAdmin/students'); } if (count($_POST) > 0) { $bed_id = $this->input->post('bed_id'); if ($status == 'Insert') { $clasDb = $this->load->database('classroom', TRUE); $student_name = $clasDb->get_where('students', array('id' => $student_id))->row()->name; $_POST['student_id'] = $student_id; $_POST['student_name'] = $student_name; $_POST['joined_date'] = $this->nepali_current_date; $insert_query = $this->HmsAdmin_Model->insert_data('hms_students', $_POST); if ($insert_query) { $update_arr['bed_status'] = 'occupied'; $update_arr['modified'] = $this->nepali_current_date; $update_bed = $this->HmsAdmin_Model->add_edit_table('hms_beds', $bed_id, $update_arr); if ($update_bed) { $this->session->set_flashdata('success', str_replace('%s', 'Student', THE_ADD_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/students'); } else { $this->session->set_flashdata('success', str_replace('%s', 'Student', THE_ADD_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/students'); } } else { $this->session->set_flashdata('failed', str_replace('%s', 'Student', THE_ADD_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/students'); } } else { $existing_bed_id = $this->db->get_where('hms_students', array('student_id' => $student_id))->row()->bed_id; $hms_stud = $this->input->post('hms_student_id'); unset($_POST['hms_student_id']); $_POST['modified'] = $this->nepali_current_date; $update_query = $this->HmsAdmin_Model->add_edit_table('hms_students', $hms_stud, $_POST); if ($update_query) { if ($existing_bed_id != $bed_id) { $update_exisiting = $this->HmsAdmin_Model->add_edit_table('hms_beds', $existing_bed_id, array('bed_status' => 'vacant')); $update_new = $this->HmsAdmin_Model->add_edit_table('hms_beds', $bed_id, array('bed_status' => 'occupied')); } $this->session->set_flashdata('success', str_replace('%s', 'Student', THE_UPDATE_SUCCESS_MSG)); redirect(base_url() . 'HmsAdmin/students'); } else { $this->session->set_flashdata('failed', str_replace('%s', 'Student', THE_UPDATE_ERROR_MSG)); redirect(base_url() . 'HmsAdmin/students'); } } } $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header'); $this->load->view('hms-admin/assign_students'); $this->load->view('hms-admin/common/footer'); } public function ajax_get_rows() { $id = $this->input->post('id'); $table = $this->input->post('table'); $column = $this->input->post('column'); $where[$column] = $id; if ($_POST['bed_clause'] != '') { $where['bed_status'] = 'vacant'; } $result = $this->HmsAdmin_Model->get_table_info($table, $where, '', 'ASC'); if (empty($result)) { echo false; } else { $json = json_encode($result); echo $json; } } public function ajax_get_rows_onready() { $student_id = $this->input->post('id'); $result = $this->HmsAdmin_Model->get_table_info_row('hms_students', array('student_id' => $student_id)); if (!empty($result)) { $data['hms_student_id'] = $result['id']; $data['block_name'] = $this->db->get_where('hms_blocks', array('id' => $result['block_id']))->row()->block_name; $block_id = $result['block_id']; $floor_id = $result['floor_id']; $room_id = $result['room_id']; $data['food_type'] = $result['food_type']; $data['floor_name'] = $this->db->get_where('hms_floors', array('id' => $result['floor_id']))->row()->floor_name; $data['room_name'] = $this->db->get_where('hms_rooms', array('id' => $result['room_id']))->row()->room_name; $data['bed_name'] = $this->db->get_where('hms_beds', array('room_id' => $result['room_id']))->row()->bed_name; // Floors $floors_sql = "Select f.* from hms_floors f inner join hms_beds be on be.block_id = $block_id WHERE f.block_id = $block_id AND be.bed_status = 'vacant' GROUP BY f.id"; $data['floor'] = $this->HmsAdmin_Model->get_table_info('hms_floors', '', $floors_sql); if (empty($data['floor'])) { echo false; exit; } // Rooms $rooms_sql = "Select f.* from hms_rooms f inner join hms_beds be on be.block_id = $block_id WHERE f.room_floor_id = $floor_id AND (f.room_block_id = $block_id AND be.bed_status = 'vacant') GROUP BY f.id"; $data['rooms'] = $this->HmsAdmin_Model->get_table_info('hms_rooms', '', $rooms_sql); if (empty($data['rooms'])) { echo false; exit; } // Beds $beds_sql = "Select * from hms_beds where block_id = $block_id AND floor_id = $floor_id AND room_id = $room_id"; $data['beds'] = $this->HmsAdmin_Model->get_table_info('hms_beds ', '', $beds_sql); if (empty($data['beds'])) { echo false; exit; } // Blocsk $blocks_sql = "Select f.* from hms_blocks f inner join hms_beds be on be.block_id = $block_id WHERE f.id = $block_id AND be.bed_status = 'vacant' GROUP BY f.id"; $data['blocks'] = $this->HmsAdmin_Model->get_table_info('hms_rooms', '', $blocks_sql); if (empty($data['blocks'])) { echo false; exit; } $json = json_encode($data); echo $json; } else { echo false; } } public function student_profile($student_id) { $arr['id'] = $student_id; $sql = "Select s.*, c.course_name from students s inner join course c on s.course = c.id WHERE s.id = $student_id"; // Personal Info $data['student'] = $student_info = $this->classroom_model->get_table_info_row('students', '', $sql); // Course Info $course_id = $student_info['course']; $studentbatch = $this->classroom_model->get_table_info_row('batch', array('id' => $student_info['batch_id'])); $section_name_sql = "Select s.section_name from section s inner join classroom c on s.id = c.section_id WHERE c.course_id = $course_id"; $section = $this->classroom_model->get_table_info_row('section', '', $section_name_sql); $data['student']['class'] = $student_info['course_name'] . ' - ' . $section['section_name']; $fromMonth = date("M", strtotime($studentbatch['b_from'])); $toMonth = date("M", strtotime($studentbatch['b_end'])); $fromYear = date("y", strtotime($studentbatch['b_from'])); $toYear = date("y", strtotime($studentbatch['b_end'])); $data['student']['startEndDate'] = $student_info['startEndDate'] = $fromMonth . ' ' . $fromYear . ' to ' . $toMonth . ' ' . $toYear; $subjects_sql = "Select s.id, s.subject_name from subject s inner join course_subjects cs on cs.subject_id = s.id WHERE cs.course_id = $course_id"; $data['student']['subjects'] = $this->classroom_model->get_table_info('subject', '', $subjects_sql); // Hostel Info $h_sql = "Select b.block_name,f.floor_name,r.room_name,r.room_ac,be.bed_name,s.food_type, s.joined_date from hms_students s inner join hms_blocks b on s.block_id = b.id inner join hms_floors f on s.floor_id = f.id inner join hms_rooms r on s.room_id = r.id inner join hms_beds be on s.bed_id = be.id WHERE s.student_id = $student_id"; $data['hostel'] = $this->HmsAdmin_Model->get_table_info_row('hms_students', '', $h_sql); // Payment Info $hostel_payment_sql = "Select sop.*, s.StudentId as student_code, pt.payment_type_name, cf.amount from students_online_payments sop inner join payment_types pt on pt.id = sop.installment_type_id inner join course_fees cf on cf.id = sop.course_fee_id inner join students s on sop.student_id = s.id inner join fee_types ft on ft.id = cf.fees_type WHERE sop.student_id = '$student_id' AND cf.course_id = s.course AND cf.batch_id = s.batch_id AND ft.feetype_name LIKE '%Hostel%' "; $data['payments'] = $this->classroom_model->get_table_info('students_online_payments', '', $hostel_payment_sql); if (!empty($data['payments'])) { $student_installments = json_decode($data['payments'][0]['payment_details']); $encryptedString = $data['payments'][0]['student_code'] . ',' . $data['payments'][0]['course_fee_id']; foreach ($student_installments as $key => $value) { if ($value->payment_status == 'no') { $encryptedString .= ',' . $value->feeamount . ',' . $value->install_sno; break; } } $data['encrypted'] = urlsafe_b64encode($encryptedString); // Studentid,Amount,CourseFee } // test_view_array($data['payments']); $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header'); $this->load->view('hms-admin/student-profile'); $this->load->view('hms-admin/common/footer'); } // ================== Students End - Afras khan - 07-12-2021 ================== // ================== Dashboard - Afras khan - 08-12-2021 ================== public function dashboard() { $data['student_count'] = $this->db->query("Select count(*) as count from hms_students")->row()->count; $data['staff_count'] = $this->db->query("Select count(*) as count from hms_admin")->row()->count; $data['room_count'] = $this->db->query("Select count(*) as count from hms_rooms")->row()->count; $data['bed_count'] = $this->db->query("Select count(*) as count from hms_beds")->row()->count; $sql = "Select be.id, be.bed_name, b.block_name, f.floor_name, r.room_name, r.room_ac from hms_beds be inner join hms_rooms r on be.room_id = r.id inner join hms_floors f on be.floor_id = f.id inner join hms_blocks b on b.id = be.block_id WHERE be.bed_status = 'vacant'"; $data['beds_data'] = $this->HmsAdmin_Model->get_table_info('hms_beds', '', $sql); $data['title'] = 'Dashboard'; $data['school_info'] = $this->classroom_model->get_logo_from_setting(); $this->load->view('hms-admin/common/left-menu', $data); $this->load->view('hms-admin/common/header', $data); $this->load->view('hms-admin/dashboard', $data); $this->load->view('hms-admin/common/footer'); } // ================== Dashboard End - Afras khan - 08-12-2021 ================== }