BBnepal-Accounts/library/application/controllers/LmsAdmin.php

1301 lines
43 KiB
PHP
Raw Permalink Normal View History

2024-07-10 12:43:19 +00:00
<?php
defined('BASEPATH') or exit('No direct script access allowed');
use Nilambar\NepaliDate\NepaliDate;
require_once '../vendor/autoload.php';
class LmsAdmin extends CI_Controller
{
/*############################################ START Of Coding By Nandini ############################################*/
public function __construct()
{
parent::__construct();
//Load the required models here
$this->load->model('LmsAdmin_Model');
//Load the required helpers here
$this->load->helper('common_helper');
date_default_timezone_set('Asia/Kathmandu');
$this->nepaliDateObject = new NepaliDate();
$this->nepali_current_date = cuurentNepaliDate($this->nepaliDateObject);
//echo $this->nepali_current_date."<br>";
//exit;
}
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->LmsAdmin_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->LmsAdmin_Model->check_login_credentials($eid, $encrypt_password))
return true;
else
return false;
}
public function login()
{
$data['title'] = 'Admin Login';
$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('lms-admin/login', $data);
} else {
$encrypt_password = md5($this->input->post('password'));
$where = 'email="' . $this->input->post('email') . '" AND password="' . $encrypt_password . '"';
$loginData = $this->LmsAdmin_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);
} 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(
'lms_lin_id' => $loginData[0]['id'],
'lms_lin_name' => $loginData[0]['admin_name'],
'lms_lin_login' => true,
);
$this->session->set_userdata('lmsAULoginData', $lnData);
//Set Message
$this->session->set_flashdata('success', 'Welcome To Admin Users Dashboard.');
$redirectToHere = 'dashboard';
$detailsHere = $this->LmsAdmin_Model->get_admin_details('', "SELECT admin_role_ids FROM lms_admin WHERE id = " . $loginData[0]['id']);
if (isset($detailsHere[0]['admin_role_ids']) && $detailsHere[0]['admin_role_ids'] != '') {
$permissionDetailsHere = $this->LmsAdmin_Model->get_lms_admin_role_permissions('', "SELECT menu_ids FROM lms_admin_role_permissions WHERE admin_role_ids IN(" . $detailsHere[0]['admin_role_ids'] . ")");
$menuIdsHere = explode(',', $permissionDetailsHere[0]['menu_ids']);
if (!empty($menuIdsHere)) {
$menuDetailsHere = $this->LmsAdmin_Model->get_admin_menu_details('', "SELECT page_link FROM lms_admin_menu WHERE id =" . $menuIdsHere[0]);
if (isset($menuDetailsHere[0]['page_link']) && $menuDetailsHere[0]['page_link'] != '')
$redirectToHere = $menuDetailsHere[0]['page_link'];
}
}
redirect(base_url() . $redirectToHere);
} else {
$this->session->set_flashdata('danger', 'Your account is inactive. Please contact the administrator.');
$this->load->view('lms-admin/login', $data);
}
} else {
$this->session->set_flashdata('danger', 'Login Credential in invalid!');
$this->load->view('lms-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('lmsAULoginData');
}
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->LmsAdmin_Model->check_is_emailid_valid($eid))
return true;
else {
return false;
}
}
public function forgot_password()
{
if (!file_exists(APPPATH . 'views/lms-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('lms-admin/forgot-password', $data);
} else {
$where = 'email="' . $this->input->post('email') . '" ';
$detailsHere = $this->LmsAdmin_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('lms-admin/emails/admin-user-forgot-password.php', $rpData, TRUE);
$emailData['to'] = $this->input->post('email');
$emailData['subject'] = ' LMS - Admin User Password Recovery Mail';
$emailData['message'] = $emailContent;
//echo $emailContent;exit;
$result = ciSendEmail($emailData);
$this->session->set_userdata('isForgotPasswordSuccess', 'Yes');
$this->load->view('lms-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('lms-admin/reset-password', $data);
} else {
$where = 'email ="' . $decodedEmailId . '"';
$isValidUser = $this->LmsAdmin_Model->get_admin_details($where);
if (!empty($isValidUser) && count($isValidUser) == 1) {
$this->LmsAdmin_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 -----------------------------*/
public function dashboard()
{
$data['title'] = 'Dashboard';
$nepCurDate = $this->nepali_current_date;
$sql = "SELECT * FROM ((SELECT count(*) AS ttl_books FROM lms_books) AS ttl_books, (SELECT count(*) AS ttl_issed_book FROM lms_book_transactions WHERE returned_on_date IS NULL) AS ttl_ibooks, (SELECT count(*) AS ttl_late_fee FROM lms_book_transactions WHERE total_late_fee!='0') AS ttl_lfee, (SELECT count(*) AS ttl_damaged_book FROM lms_book_transactions WHERE is_damaged='Yes') AS ttl_damaged)";
$data['ttlData'] = $this->LmsAdmin_Model->get_lms_dashboard_records('', $sql);
//$where = "date(issued_date) >= ( CURDATE() - INTERVAL 7 DAY ) AND returned_on_date";
$todayDateObj = new DateTime($nepCurDate);
$todayIs = $todayDateObj->format('Y-m-d');
$intDay = date('Y-m-d', strtotime('-7 day', strtotime(date('Y-m-d'))));
$fromDayIs = convert_ADdate_to_BSdate($this->nepaliDateObject, $intDay, $character = '-');
$where = "issued_date>='" . $fromDayIs . "' AND issued_date<='" . $todayIs . "' AND returned_on_date IS NULL ";
$data['recentlyIssuedBook'] = $this->LmsAdmin_Model->getData('lms_book_transactions', $where);
$data['npCurrDate'] = $nepCurDate;
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/dashboard', $data);
}
/*----------------------------------- START Of Admin Roles --------------------------------------------------------*/
public function roles()
{
$data['title'] = 'Roles';
$sqlRole = 'SELECT r.*, rp.menu_ids FROM lms_admin_roles AS r, lms_admin_role_permissions AS rp WHERE r.id = rp.admin_role_ids';
$rolesList = $this->LmsAdmin_Model->get_lms_admin_roles('', $sqlRole);
if (!empty($rolesList)) {
foreach ($rolesList as $key => $role) {
$rPs = '';
$sqlRolePermissions = 'SELECT menu_name FROM lms_admin_menu WHERE id IN(' . $role['menu_ids'] . ')';
$rolePermissions = $this->LmsAdmin_Model->get_lms_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 '<pre>'; print_r($data['roleList']);exit;
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/roles', $data);
}
public function ajaxCheckIsRoleAlreadyExists()
{
$result = 'Insufficient Data';
if (isset($_POST['role_name']) && $_POST['role_name'] != '' && isset($_POST['id']) && $_POST['id'] != '') {
if ($this->LmsAdmin_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 lms_admin_roles WHERE id = $idVal";
$details = $this->LmsAdmin_Model->get_lms_admin_roles("id = $idVal");
if (empty($details) && $idVal != 0)
redirect(base_url() . 'roles');
if ($idVal == 0) {
$data['title'] = 'Add New Role';
$data['button'] = 'Save';
} else if ($idVal > 0) {
$data['title'] = 'Update Role';
$data['button'] = 'Update';
}
$data['details'] = $details;
$data['idVal'] = $idVal;
$data['menus'] = $this->LmsAdmin_Model->get_admin_menu_details('', 'SELECT id,menu_name FROM lms_admin_menu WHERE status="Active" AND parent_id=0');
$data['role_permissions'] = $this->LmsAdmin_Model->get_lms_admin_role_permissions('', "SELECT menu_ids FROM lms_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']);
}
if ($idVal == 0)
$_POST['created'] = $this->nepali_current_date;
else
$_POST['modified'] = $this->nepali_current_date;
//echo '<pre>'; print_r($_POST);exit;
$res = $this->LmsAdmin_Model->add_edit_admin_role($idVal, $_POST);
if ($res) {
if ($permissions != '') {
if ($idVal == 0) {
$rpData['admin_role_ids'] = $res;
$rpData['menu_ids'] = $permissions;
$rpData['created'] = $this->nepali_current_date;
$this->LmsAdmin_Model->add_edit_admin_role_permissions(0, $rpData);
} else {
$getRPrid = $this->LmsAdmin_Model->get_lms_admin_role_permissions('', "SELECT id FROM lms_admin_role_permissions WHERE admin_role_ids = $idVal");
if (isset($getRPrid[0]['id'])) {
$rpData['admin_role_ids'] = $idVal;
$rpData['menu_ids'] = $permissions;
$rpData['modified'] = $this->nepali_current_date;
$this->LmsAdmin_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');
}
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/add-edit-role', $data);
}
public function deleteRoleData()
{
$roleId = $_POST['id'];
$where = " admin_role_ids=" . $roleId;
$existsUser = $this->LmsAdmin_Model->getData('lms_admin', $where);
if ($existsUser) {
echo 0;
} else {
$dwhere = " id=" . $roleId;
$delete = $this->LmsAdmin_Model->deleteData('lms_admin_roles', $dwhere);
if ($delete) {
echo 1;
}
}
}
/*----------------------------------- ENDDD Of Admin Roles --------------------------------------------------------*/
/*----------------------------------- START Of Admin Users --------------------------------------------------------*/
public function users()
{
$data['title'] = 'Users';
$sql = 'SELECT a.*, ar.role_name FROM lms_admin AS a, lms_admin_roles AS ar WHERE a.admin_role_ids = ar.id';
$data['userList'] = $this->LmsAdmin_Model->get_admin_details('', $sql);
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/users', $data);
}
public function ajaxCheckIsUserEmailAlreadyExists()
{
$result = 'Insufficient Data';
if (isset($_POST['email']) && $_POST['email'] != '' && isset($_POST['id']) && $_POST['id'] != '') {
if ($this->LmsAdmin_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 lms_admin WHERE id = $idVal";
$details = $this->LmsAdmin_Model->get_admin_details("id = $idVal");
if (empty($details) && $idVal != 0)
redirect(base_url() . 'users');
if ($idVal == 0) {
$data['title'] = 'Add New User';
$data['button'] = 'Save';
} else if ($idVal > 0) {
$data['title'] = 'Update User';
$data['button'] = 'Update';
}
$data['details'] = $details;
$data['idVal'] = $idVal;
$data['roles'] = $this->LmsAdmin_Model->get_lms_admin_roles('', 'SELECT id,role_name FROM lms_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']);
if ($idVal == 0)
$_POST['created'] = $this->nepali_current_date;
else
$_POST['modified'] = $this->nepali_current_date;
$res = $this->LmsAdmin_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');
}
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/add-edit-user', $data);
}
public function deleteUserData()
{
$userId = $_POST['id'];
$dwhere = " id=" . $userId;
$delete = $this->LmsAdmin_Model->deleteData('lms_admin', $dwhere);
if ($delete) {
echo 1;
}
}
/*----------------------------------- ENDDD Of Admin Users --------------------------------------------------------*/
/*############################################ ENDDD Of Coding By Nandini ############################################*/
/*############################################ START Of Coding By Keerthi ############################################*/
//start book
public function ajaxGetBookLists()
{
if (isset($_POST['categoryId']) && $_POST['categoryId'] != '') {
$catArr['category_id'] = $_POST['categoryId'];
$returnData = $this->fecthBookLists($catArr);
echo $returnData;
exit;
}
}
public function books()
{
if (!file_exists(APPPATH . 'views/lms-admin/books.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Books';
$bookData = '';
$data['bookDetail'] = $this->fecthBookLists($bookData);
$where = " is_active='Y'";
$data['categoryData'] = $this->LmsAdmin_Model->getData('lms_categories', $where);
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/books', $data);
// $this->load->view('lms-admin/common/footer', $data);
} else {
LmsAdmin::logout();
}
}
public function fecthBookLists($bookData = array())
{
if (isset($bookData['category_id']) && !empty($bookData['category_id'])) {
$where = ' category_id=' . $bookData['category_id'];
} else {
$where = '';
}
$bookLists = $this->LmsAdmin_Model->getData('lms_books', $where);
$liData['bookDetail'] = $bookLists;
$returnPage = $this->load->view('lms-admin/books-reload', $liData, true);
return $returnPage;
}
public function add_edit_book($idVal = 0)
{
$page = 'add-edit-book';
if (!file_exists(APPPATH . 'views/lms-admin/' . $page . '.php')) {
show_404();
}
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['idVal'] = $idVal;
$data['title'] = 'Add New Book';
$data['button'] = 'Add Book';
$cwhere = " is_active='Y'";
$data['categoryData'] = $this->LmsAdmin_Model->getData('lms_categories', $cwhere);
$data['gSData'] = $this->LmsAdmin_Model->getGeneralSettingData('lms_general_settings');
if ($idVal > 0) {
$data['title'] = 'Edit Book';
$data['button'] = 'Update';
$where = 'id = ' . $idVal;
$data['details'] = $this->LmsAdmin_Model->getData('lms_books', $where);
}
if (count($_POST) > 0) {
$isbn = $_POST['isbn'];
$where = " isbn=" . "'$isbn'";
$existsISBN = $this->LmsAdmin_Model->getData('lms_books', $where);
if (isset($existsISBN) && ($idVal == 0)) {
echo 0;
} else {
if ($idVal > 0) {
$_POST['modified'] = $this->nepali_current_date;
$where = ['book_id' => $idVal, 'returned_on_date =' => NULL];
$ttlIssuedBook = $this->db->get_where('lms_book_transactions', $where)->result_array();
$ttl_issued_qty = count($ttlIssuedBook);
$existingBookQty = $this->db->get_where('lms_books', ['id' => $idVal])->row_array();
$qty = $existingBookQty['total_quantity'];
$remQty = $existingBookQty['remaining_quantity'];
$ttl = ($ttl_issued_qty) + ($remQty);
$ttl_qty = $_POST['total_quantity'];
if ($ttl_qty < $ttl) {
echo $ttl_issued_qty . '_' . $remQty;
} else {
if ($ttl_qty == $ttl) {
$ttlRemQty = $remQty;
$ttlBookQty = $qty;
} else {
$ttlBookQty = $ttl_qty;
$ttlRemQty = (($ttl_qty) - ($qty)) + ($remQty);
}
$insertUpdate = $this->LmsAdmin_Model->addEditBook($idVal, $this->input->post(), $ttlRemQty, $ttlBookQty);
if ($insertUpdate) {
echo 1;
}
}
} else {
$_POST['created'] = $this->nepali_current_date;
$insertUpdate = $this->LmsAdmin_Model->addEditBook($idVal, $this->input->post(), '', '');
if ($insertUpdate) {
echo 1;
}
}
}
} else {
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/add-edit-book', $data);
}
} else {
LmsAdmin::logout();
}
}
public function importBooks()
{
if (isset($_FILES["upload_file"]["name"])) {
$file = $_FILES["upload_file"]["tmp_name"];
$handle = fopen($file, "r");
$c = 0;
$dataArray = array();
while (($filesop = fgetcsv($handle, 1000, ",")) !== false) {
$category_id = $filesop[0];
$isbn = $filesop[1];
$title = $filesop[2];
$author = $filesop[3];
$publisher = $filesop[4];
$published_year = $filesop[5];
$price = $filesop[6];
$total_no_of_pages = $filesop[7];
$total_quantity = $filesop[8];
$remaining_quantity = $filesop[9];
$rack_no = $filesop[10];
$description = $filesop[11];
$can_be_issued_for = 0;
$fine_per_day = 0;
if ($c <> 0) {
$dataArray[] = array('category_id' => $category_id, 'isbn' => $isbn, 'title' => $title, 'author' => $author, 'publisher' => $publisher, 'published_year' => $published_year, 'price' => $price, 'total_no_of_pages' => $total_no_of_pages, 'total_quantity' => $total_quantity, 'remaining_quantity' => $remaining_quantity, 'rack_no' => $rack_no, 'description' => $description, 'can_be_issued_for' => $can_be_issued_for, 'fine_per_day' => $fine_per_day);
}
$c = $c + 1;
}
foreach ($dataArray as $data) {
$isbn = $data['isbn'];
$where = ' isbn=' . "'$isbn'";
$duplicate = $this->LmsAdmin_Model->getData('lms_books', $where);
if ($duplicate) {
$idVal = $duplicate['id'];
$_POST['modified'] = $this->nepali_current_date;
$insertUpdate = $this->LmsAdmin_Model->addEditBook($idVal, $data);
} else {
$idVal = 0;
$_POST['created'] = $this->nepali_current_date;
$insertUpdate = $this->LmsAdmin_Model->addEditBook($idVal, $data);
}
}
if ($insertUpdate) {
$this->session->set_flashdata('success', 'Book detail imported successfully.');
redirect(base_url() . 'books');
}
}
}
public function checkExistingBook()
{
$isbn = $_POST['isbn'];
$where = ' isbn=' . "'$isbn'";
$existingBook = $this->LmsAdmin_Model->getData('lms_books', $where);
if ($existingBook) {
$remQty = $existingBook['remaining_quantity'];
if ($remQty == 0) {
echo 0;
} else {
echo 1;
}
}
}
public function deleteBookData()
{
$book_id = $_POST['bookId'];
$where = " book_id=" . $book_id;
$checkExistsInIssued = $this->LmsAdmin_Model->getData('lms_book_transactions', $where);
if ($checkExistsInIssued) {
echo 0;
} else {
$dwhere = " id=" . $book_id;
$delete = $this->LmsAdmin_Model->deleteData('lms_books', $dwhere);
if ($delete) {
echo 1;
}
}
}
//end book
//start settings
public function generalSettings()
{
if (!file_exists(APPPATH . 'views/lms-admin/general-settings.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'General Settings';
$data['gSData'] = $this->LmsAdmin_Model->getGeneralSettingData('lms_general_settings');
if (count($_POST) > 0) {
$idVal = $_POST['id'];
if ($idVal == 0)
$_POST['created'] = $this->nepali_current_date;
else
$_POST['modified'] = $this->nepali_current_date;
$insertUpdate = $this->LmsAdmin_Model->addEditGeneralSettings($idVal, $this->input->post());
if ($insertUpdate) {
echo 1;
}
} else {
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/general-settings', $data);
}
} else {
LmsAdmin::logout();
}
}
public function getCategoryData()
{
if (!file_exists(APPPATH . 'views/lms-admin/category.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Categories';
$data['categoryData'] = $this->LmsAdmin_Model->getData('lms_categories', '');
if (count($_POST) > 0) {
$idVal = $_POST['id'];
$name = $_POST['name'];
$where = " name=" . "'$name'";
$exsistingCat = $this->LmsAdmin_Model->getData('lms_categories', $where);
if (($exsistingCat) && ($idVal == 0)) {
echo 0;
} else {
if ($idVal == 0)
$_POST['created'] = $this->nepali_current_date;
else
$_POST['modified'] = $this->nepali_current_date;
$insertUpdate = $this->LmsAdmin_Model->addEditCatgeoryData($idVal, $this->input->post());
if ($insertUpdate) {
echo 1;
}
}
} else {
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/category', $data);
}
} else {
LmsAdmin::logout();
}
}
public function deleteCategoryData()
{
$categoryId = $_POST['categoryId'];
$tableName = $_POST['tableName'];
$existingData = $this->db->get_where('lms_books', ['category_id' => $categoryId])->row();
if ($existingData) {
echo 0;
} else {
$where = ' id=' . $categoryId;
$delete = $this->LmsAdmin_Model->deleteData($tableName, $where);
if ($delete) {
echo 1;
}
}
}
public function getCategoryById()
{
$categoryId = $_POST['categoryId'];
$tableName = $_POST['tableName'];
$where = ' id=' . $categoryId;
$data = $this->LmsAdmin_Model->getData($tableName, $where);
if ($data['is_active'] == 'Y') {
$status = 'Active';
} elseif ($data['is_active'] == 'N') {
$status = 'Inactive';
}
$html = '<div class="form-group">
<label>Category Name</label>
<input type="text" class="form-control txtData" name="name" id="name" placeholder="Category Name" value="' . $data['name'] . '">
<p class="form_err" id="error-name"></p>
</div>
<div class="form-group">
<label>Status</label>
<select class="form-control txtData" name="is_active" id="is_active" style="padding:0;">
<option value="' . $data['is_active'] . '">' . $status . '</option>
<option value="Y">Active</option>
<option value="N">Inactive</option>
</select>
<p class="form_err" id="error-is_active"></p>
</div>';
echo $html;
}
//end settings
//start issued book
public function ajaxIssuedBookDetail()
{
if (isset($_POST['startdate']) && $_POST['startdate'] != '')
$reqArr['startdate'] = $_POST['startdate'];
if (isset($_POST['enddate']) && $_POST['enddate'] != '')
$reqArr['enddate'] = $_POST['enddate'];
if (isset($_POST['option']) && $_POST['option'] != '') {
$reqArr['option'] = $_POST['option'];
} else {
$reqArr['option'] = '';
}
$returnData = $this->fetchIssedBookData($reqArr);
echo $returnData;
exit;
}
public function issued_books()
{
if (!file_exists(APPPATH . 'views/lms-admin/issued-books.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Issued Books';
$options = '';
$startDate = '';
$endDate = '';
if (count($_POST) > 0) {
if (isset($_POST['startdate']) && $_POST['startdate'] != '') {
$iBookData['startdate'] = $_POST['startdate'];
$startDate = $_POST['startdate'];
}
if (isset($_POST['enddate']) && $_POST['enddate'] != '') {
$iBookData['enddate'] = $_POST['enddate'];
$endDate = $_POST['enddate'];
}
if (isset($_POST['option']) && $_POST['option'] != '') {
$iBookData['option'] = $_POST['option'];
$options = $_POST['option'];
}
}
$iBookData = '';
$data['issuedBookData'] = $this->fetchIssedBookData($iBookData);
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/issued-books', $data);
} else {
LmsAdmin::logout();
}
}
public function fetchIssedBookData($iBookData = array())
{
$todayDateObj = new DateTime($this->nepali_current_date);
$today = $todayDateObj->format('Y-m-d');
if (isset($iBookData['startdate']) && !empty($iBookData['startdate']) && isset($iBookData['enddate']) && !empty($iBookData['option']) && isset($iBookData['option']) && !empty($iBookData['enddate'])) {
$where = " DATE(issued_date) >= '" . $iBookData['startdate'] . "' AND DATE(issued_date) <= '" . $iBookData['enddate'] . "' AND DATE(return_date) < '" . $today . "'";
} elseif (isset($iBookData['startdate']) && !empty($iBookData['startdate']) && isset($iBookData['enddate']) && !empty($iBookData['enddate'])) {
$where = " DATE(issued_date) >= '" . $iBookData['startdate'] . "' AND DATE(issued_date) <= '" . $iBookData['enddate'] . "'";
} elseif (isset($iBookData['enddate']) && !empty($iBookData['enddate'])) {
$where = " DATE(issued_date) <= '" . $iBookData['enddate'] . "'";
} elseif (isset($iBookData['enddate']) && !empty($iBookData['enddate'])) {
$where = " DATE(issued_date) <= '" . $iBookData['enddate'] . "'";
} elseif (isset($iBookData['option ']) && !empty($iBookData['option '])) {
$where = " DATE(return_date) <= '" . $today . "'";
} else {
$where = "";
}
$issuedBookLists = $this->LmsAdmin_Model->get_issed_book_data('lms_book_transactions', $where);
$liData['issuedBookData'] = $issuedBookLists;
$liData['npCurrDate'] = $this->nepali_current_date;
$returnPage = $this->load->view('lms-admin/issued-books-reload', $liData, true);
return $returnPage;
}
public function add_edit_issue_book($idVal = 0)
{
$page = 'add-edit-issue-book';
if (!file_exists(APPPATH . 'views/lms-admin/' . $page . '.php')) {
show_404();
}
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['idVal'] = $idVal;
$data['title'] = 'Issue Book';
$data['button'] = 'Add Book';
$data['gSData'] = $this->LmsAdmin_Model->getGeneralSettingData('lms_general_settings');
if ($idVal > 0) {
$data['title'] = 'Edit Issue Book';
$data['button'] = 'Update Book';
}
if (count($_POST) > 0) {
if (isset($_POST['eu_unique_id']) && !empty($_POST['eu_unique_id'])) {
$ttl_rows = $_POST['ttlrows'];
$eu_id = $_POST['eu_unique_id'];
$idate = explode(',', $_POST['issueddate']);
$rdate = explode(',', $_POST['returndate']);
$bhealth = explode(',', $_POST['bookhealth']);
$isbn = $_POST['isbn'];
$title = $_POST['title'];
for ($i = 0; $i < count($isbn); $i++) {
$data = $this->db->get_where('lms_books', ['isbn' => $isbn[$i]])->row_array();
$bisbn[] = $isbn[$i];
$bid[] = $data['id'];
$euid[] = $eu_id;
$i_date[] = $idate[$i];
$r_date[] = $rdate[$i];
$b_health[] = $bhealth[$i];
}
$vals = array_count_values($bisbn);
$book_isbn = array();
foreach ($vals as $key => $val) {
$b_isbn = $key;
$b_ttlrows = $val;
$data = $this->db->get_where('lms_books', ['isbn' => $b_isbn])->row_array();
$ttlremqty = $data['remaining_quantity'];
if ($b_ttlrows > $ttlremqty) {
$book_isbn[] = 'The book ' . $b_isbn . ' is having remaining quantity ' . $ttlremqty . ' you can not issue more than that.';
}
}
if (!empty($book_isbn)) {
$message = implode(' , ', $book_isbn);
$this->session->set_flashdata('failure', $message);
redirect(base_url() . 'add-edit-issue-book/0');
} else {
$dataArray = array(
'book_id' => $bid,
'eu_unique_id' => $euid,
'issued_date' => $i_date,
'return_date' => $r_date,
'book_health' => $b_health,
'created_on' => $this->nepali_current_date,
'modified_on' => $this->nepali_current_date,
);
$insertUpdate = $this->LmsAdmin_Model->addEditissuedBookData($idVal, $dataArray);
if ($insertUpdate) {
$this->session->set_flashdata('success', 'The book has been issued successfully.');
redirect(base_url() . 'add-edit-issue-book/0');
}
}
} else {
$this->session->set_flashdata('failure', 'Please add book details to issue the book.');
redirect(base_url() . 'add-edit-issue-book/0');
}
} else {
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/' . $page, $data);
}
} else {
LmsAdmin::logout();
}
}
public function getDataById()
{
$id = $_POST['id'];
$tableName = $_POST['tableName'];
if ($tableName == 'lms_books') {
$where = ' isbn=' . "'$id'";
}
$data = $this->LmsAdmin_Model->getData($tableName, $where);
if ($tableName == 'lms_books') {
$catData = $this->db->get_where('lms_categories', ['id' => $data['category_id']])->row_array();
$cat_name = $catData['name'];
$issueData = $this->db->get('lms_general_settings')->row_array();
if ($data['can_be_issued_for'] == 0) {
$data['lending_days'] = $issueData['can_be_issued_for'];
} else {
$data['lending_days'] = $data['can_be_issued_for'];
}
$data['category_name'] = $cat_name;
}
print_r(json_encode($data));
}
public function getStudentDataById()
{
$stdIs = $_POST['id'];
$data = $this->LmsAdmin_Model->getStudentDataById($stdIs);
$cnt = 0;
$ttlBookCnt = 0;
if ($data) {
$eu_unique_id = $data['studentId'];
$where = ['eu_unique_id' => $eu_unique_id, 'returned_on_date=' => NULL];
$existingBookData = $this->db->get_where('lms_book_transactions', $where)->result_array();
$bookPerUserData = $this->LmsAdmin_Model->getGeneralSettingData('lms_general_settings');
$ttlBookCnt = $bookPerUserData['no_of_book_per_user'];
$cnt = count($existingBookData);
$data['ttl_issued_book_cnt'] = $ttlBookCnt;
$data['eu_issued_book_cnt'] = $cnt;
} else {
$data['ttl_issued_book_cnt'] = $ttlBookCnt;
$data['eu_issued_book_cnt'] = $cnt;
}
print_r(json_encode($data));
}
//end issued book
//start returned book
public function ajaxReturnedBookDetail()
{
if (isset($_POST['startdate']) && $_POST['startdate'] != '')
$reqArr['startdate'] = $_POST['startdate'];
if (isset($_POST['enddate']) && $_POST['enddate'] != '')
$reqArr['enddate'] = $_POST['enddate'];
if (isset($_POST['option']) && $_POST['option'] != '') {
$reqArr['option'] = $_POST['option'];
} else {
$reqArr['option'] = '';
}
$returnData = $this->fetchReturnedBookData($reqArr);
echo $returnData;
exit;
}
public function returned_books()
{
if (!file_exists(APPPATH . 'views/lms-admin/returned-books.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Returned Books';
$options = '';
$startDate = '';
$endDate = '';
if (count($_POST) > 0) {
if (isset($_POST['startdate']) && $_POST['startdate'] != '') {
$rBookData['startdate'] = $_POST['startdate'];
$startDate = $_POST['startdate'];
}
if (isset($_POST['enddate']) && $_POST['enddate'] != '') {
$rBookData['enddate'] = $_POST['enddate'];
$endDate = $_POST['enddate'];
}
if (
isset($_POST['option']) && $_POST['option'] != ''
) {
$rBookData['option'] = $_POST['option'];
$options = $_POST['option'];
}
}
$rBookData = '';
$data['returnedBookData'] = $this->fetchReturnedBookData($rBookData);
$this->load->view(
'lms-admin/common/left-menu',
$data
);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/returned-books', $data);
} else {
LmsAdmin::logout();
}
}
public function fetchReturnedBookData($rBookData = array())
{
$todayDateObj = new DateTime($this->nepali_current_date);
$today = $todayDateObj->format('Y-m-d');
if (isset($rBookData['startdate']) && !empty($rBookData['startdate']) && isset($rBookData['enddate']) && !empty($rBookData['option']) && isset($rBookData['option']) && !empty($rBookData['enddate'])) {
$where = " DATE(returned_on_date) >= '" . $rBookData['startdate'] . "' AND DATE(returned_on_date) <= '" . $rBookData['enddate'] . "' AND DATE(return_date) < '" . $today . "'";
} elseif (isset($rBookData['startdate']) && !empty($rBookData['startdate']) && isset($rBookData['enddate']) && !empty($rBookData['enddate'])) {
$where = " DATE(returned_on_date) >= '" . $rBookData['startdate'] . "' AND DATE(returned_on_date) <= '" . $rBookData['enddate'] . "'";
} elseif (isset($rBookData['enddate']) && !empty($rBookData['enddate'])) {
$where = " DATE(returned_on_date) <= '" . $rBookData['enddate'] . "'";
} elseif (isset($rBookData['enddate']) && !empty($rBookData['enddate'])) {
$where = " DATE(returned_on_date) <= '" . $rBookData['enddate'] . "'";
} elseif (isset($rBookData['option ']) && !empty($rBookData['option '])) {
$where = " DATE(returned_on_date) <= '" . $today . "'";
} else {
$where = " returned_on_date!=''";
}
//echo $where;
$returnedBookLists = $this->LmsAdmin_Model->get_returned_book_data('lms_book_transactions', $where);
$liData['returnedBookData'] = $returnedBookLists;
$returnPage = $this->load->view('lms-admin/returned-books-reload', $liData, true);
return $returnPage;
}
public function receive_book()
{
if (!file_exists(APPPATH . 'views/lms-admin/receive-book.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Receive Book';
if (count($_POST) > 0) {
$eu_id = $_POST['eu_unique_id'];
$euId = $this->LmsAdmin_Model->getStudentDataById($eu_id);
$where = " eu_unique_id=" . "'$eu_id'";
$existsUser = $this->LmsAdmin_Model->getData('lms_book_transactions', $where);
if (!$existsUser) {
echo 0;
} else {
echo $euId['id'];
}
} else {
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/receive-book', $data);
}
} else {
LmsAdmin::logout();
}
}
public function receive_book_detail($euId = '')
{
if (!file_exists(APPPATH . 'views/lms-admin/receive-book-detail.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Receive Book';
$data['userData'] = $this->LmsAdmin_Model->getStudentInfo($euId);
if ($data['userData']) {
$eu_unique_id = $data['userData']['studentId'];
$userWhere = " returned_on_date IS NULL AND eu_unique_id=" . "'$eu_unique_id'";
$data['bookDetail'] = $this->LmsAdmin_Model->getData('lms_book_transactions', $userWhere);
}
$data['gSData'] = $this->LmsAdmin_Model->getGeneralSettingData('lms_general_settings');
$data['npCurrDate'] = $this->nepali_current_date;
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/receive-book-detail', $data);
} else {
LmsAdmin::logout();
}
}
public function addComment()
{
if (isset($_POST['id']) && !empty($_POST['id'])) {
$idVal = $_POST['id'];
if (isset($_POST['is_damaged'])) {
$damaged = 'Yes';
} else {
$damaged = 'No';
}
$dam_comment = $_POST['damaged_comment'];
$dataArray = array(
'is_damaged' => $damaged,
'damaged_comment' => $dam_comment
);
$insertComment = $this->LmsAdmin_Model->addCommentData($idVal, $dataArray);
if ($insertComment) {
echo 1;
}
}
}
public function returnedBookData()
{
if (isset($_POST['returnedBook']) && !empty($_POST['returnedBook'])) {
$returnedId = $_POST['returnedBook'];
$update = $this->LmsAdmin_Model->addReturnedBook($returnedId);
echo $update;
//echo '<pre>';print_r($update);
/*if($update)
{
echo 1;
}*/
}
}
public function getCommentData()
{
$commentId = $_POST['CommentId'];
$table = $_POST['tableName'];
$where = ' id=' . $commentId;
$data = $this->LmsAdmin_Model->getData($table, $where);
$dataArray = array(
'comment' => $data['damaged_comment'],
'isDamaged' => $data['is_damaged']
);
print_r(json_encode($dataArray));
}
//end returned book
//start student
public function ajaxGetUserData()
{
if (isset($_POST['class']) && $_POST['class'] != '') {
$catArr['class'] = $_POST['class'];
$returnData = $this->fecthUserData($catArr);
echo $returnData;
exit;
}
}
public function students()
{
if (!file_exists(APPPATH . 'views/lms-admin/students.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Students';
$userData = '';
$data['studentData'] = $this->fecthUserData($userData);
// $distinct = $this->db->distinct();
// $data['classData'] = $this->LmsAdmin_Model->get_user_data('lms_end_users', '', $distinct);
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/students', $data);
} else {
LmsAdmin::logout();
}
}
public function fecthUserData($userData = array())
{
// if(isset($userData['class']) && !empty($userData['class'])){
// $class = $userData['class'];
// $where = " unq_id LIKE '%ECS%' AND class_name="."'$class'";
// }else{
// $where = " unq_id LIKE '%ECS%'";
// }
$userLists = $this->LmsAdmin_Model->get_user_data('students');
$liData['studentData'] = $userLists;
$returnPage = $this->load->view('lms-admin/students-reload', $liData, true);
return $returnPage;
}
public function students_info($stdId = '')
{
if (!file_exists(APPPATH . 'views/lms-admin/students-info.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Student Info';
$where = " id=" . $stdId;
$data['studentInfo'] = $this->LmsAdmin_Model->getStudentInfo($stdId);
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/students-info', $data);
} else {
LmsAdmin::logout();
}
}
//end student
//start damaged book
public function damaged_books()
{
if (!file_exists(APPPATH . 'views/lms-admin/damaged-books.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Damaged Books';
$where = " is_damaged=" . "'Yes'";
$data['damagedBookData'] = $this->LmsAdmin_Model->getData('lms_book_transactions', $where);
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/damaged-books', $data);
} else {
LmsAdmin::logout();
}
}
public function damaged_books_details($dBId = '')
{
if (!file_exists(APPPATH . 'views/lms-admin/damaged-books-details.php'))
show_404();
if ($_SESSION['lmsAULoginData']['lms_lin_login'] == 1) {
$data['title'] = 'Damaged Books';
$where = " book_id=" . $dBId;
$data['damagedBookDetail'] = $this->LmsAdmin_Model->getData('lms_book_transactions', $where);
$data['bookData'] = $this->db->get_where('lms_books', ['id' => $dBId])->row_array();
$this->load->view('lms-admin/common/left-menu', $data);
$this->load->view('lms-admin/common/header', $data);
$this->load->view('lms-admin/damaged-books-details', $data);
} else {
LmsAdmin::logout();
}
}
//end damaged book
/*############################################ ENDDD Of Coding By Keerthi ############################################*/
}