?
Current Path : /home1/savoy/public_html/savoyglobal.net/cocorico/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/cocorico/application/models/mastermodel.php |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Mastermodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); } /* Common function starts here */ function authenticate($user_name, $password) { $data = array(); $ip = $this->input->post('ip'); $logintime = $today = date("Y-m-d H:i:s"); $password1 = md5($password); $query = $this->db->query("select * from user where user_name='$user_name' and password='$password1'"); $data['numrows'] = $query->num_rows(); if ($query->num_rows() > 0) { $lastid = $this->get_single_value('login_details', 'id', 'user_name', $user_name); $result = $query->row(); $data['user_id'] = $result->user_id; $data['employee_id'] = $result->employee_id; $data['user_name'] = $user_name; $data['clogintime'] = $logintime; $data['lastid'] = $lastid; $query1 = $this->db->query("select * from login_details where user_name='$user_name' and id>='$lastid'"); $data['attempt'] = ($query1->num_rows()) - 1; $tblValues = array('user_name' => $user_name, 'password' => $password1, 'login_time ' => $logintime, 'user_id ' => $result->user_id, 'ip_address ' => $ip, 'status ' => 'Success'); $this->db->insert('login_details', $tblValues); } else { $tblValues = array('user_name' => $user_name, 'password' => $password, 'login_time ' => $logintime, 'user_id ' => '', 'failing_time ' => $logintime, 'ip_address ' => $ip, 'status ' => 'failed'); $this->db->insert('login_details', $tblValues); } return $data; } function getSingleFieldValue($table, $field, $condition, $value) { //echo "select ". $field. " from ". $table . " where ". $condition . "='". $value ."'"; $data = $this->db->query("select " . $field . " from " . $table . " where " . $condition . "='" . $value . "'"); $result = $data->row(); if ($result) { return $result->$field; } else { return ""; } } function searchfeemaster($postdata, $pagenum) { $data = array(); $this->db->from('fee_master'); $count = $this->db->count_all_results(); $arr = $this->fpaginate->paginate($pagenum, $count); $data['startpage'] = $arr[0]; $data['endpage'] = $arr[1]; $start = $arr[2]; $perpage = $arr[3]; $data['count'] = $count; $this->db->select('fee_master_id,fee_master_name,fee_master_description,fee_master_target'); $this->db->from('fee_master'); $data['results'] = $this->db->get(); return $data; } function get_class_by_term($term) { $data = array(); $Q = $this->db->query("SELECT DISTINCT class_name_id from student_class where term_id=$term; "); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function check_deactivate($class_name, $student_id, $date, $deactivate = '') { $date = $this->mastermodel->convertdateformat($date); $where = "(activate_date > '$date' OR activate_date='0000-00-00')"; $this->db->from('student_deactivate'); $this->db->where('student_id', $student_id); $this->db->where('class_name_id', $class_name); $this->db->where('start_date <=', $date); $this->db->where($where); $this->db->where('activate_date !=', $date); // $this->db->where('activate !=', '1'); if ($deactivate != '') $this->db->where('deactivate_id !=', $deactivate); $count = $this->db->count_all_results(); return $count; // $Q = $this->db->get(); // $row = $Q->row(); // return $row; } function student_assessment_details($assessment_id) { $this->db->from('student_assessment_details'); $this->db->join('student', 'student.student_id=student_assessment_details.student_id'); $this->db->where('student_assessment_id', $assessment_id); return $this->db->get(); } function searchfeeparticulars($postdata, $pagenum) { $data = array(); $this->db->from('fee_particular'); $postdata = $_SESSION['searchdata']; if (!empty($postdata)) { $searchtext = $postdata['searchtext']; $searchfield = $postdata['searchvalue']; $this->db->like($searchfield, $searchtext); } $count = $this->db->count_all_results(); $arr = $this->fpaginate->paginate($pagenum, $count); $data['startpage'] = $arr[0]; $data['endpage'] = $arr[1]; $start = $arr[2]; $perpage = $arr[3]; $data['count'] = $count; if (!empty($postdata)) { $searchtext = $postdata['searchtext']; $searchfield = $postdata['searchvalue']; $this->db->like($searchfield, $searchtext); } $this->db->select('*'); $this->db->from('fee_particular'); $this->db->limit($perpage, $start); $data['results'] = $this->db->get(); return $data; } function getenumvalues($table, $column) { $sql = "SHOW COLUMNS FROM $table LIKE '$column'"; $result = mysql_query($sql); if ($result) { $enum = mysql_fetch_object($result); preg_match_all("/'([\w ]*)'/", $enum->Type, $values); $data['val'] = $values[1]; return $data; } else { die("Unable to fetch enum values: " . mysql_error()); } } function generate_random_string($length = 10) { $characters = 'abcdefghijklmnopqrstuvwxyz1234567890@#$%&^'; $random_string = ''; for ($i = 0; $i < $length; $i++) { $random_string .= $characters[rand(0, strlen($characters) - 1)]; } return date("Y-m-d-h-i-s") . $random_string; } function get_num_rows($table, $field = '', $id = '') { if ($field != '') $this->db->where($field, $id); $Q = $this->db->get($table); return $Q->num_rows(); } function getdistinctfield($field, $table, $sortfield = "") { $data = array(); $this->db->distinct(); $this->db->select($field); if (!empty($sortfield)) { $this->db->order_by($sortfield, "asc"); } $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function convdatformat($xdate) { $mydate = explode('-', $xdate); if (sizeof($mydate) > 2) return $mydate[2] . "-" . $mydate[1] . "-" . $mydate[0]; else if (sizeof($mydate) > 1) return $mydate[1] . "-" . $mydate[0]; else return $mydate[0]; } function number_rows($tabname, $field1 = '', $value1 = '', $field2 = '', $value2 = '', $field3 = '', $value3 = '', $primary_field = '') { $this->db->from($tabname); if ($primary_field != '') { $this->db->join('master', "master.master_id=$tabname.$primary_field"); } if ($field1 != '') $this->db->where($field1, $value1); if ($field2 != '') $this->db->where($field2, $value2); if ($field3 != '') $this->db->where($field3, $value3); $num = $this->db->count_all_results(); return $num; } function get_single_value($table, $field, $condition, $value) { $data = $this->db->query("select max(" . $field . ") as " . $field . " from " . $table . " where " . $condition . "='" . $value . "' and status='Success'"); $result = $data->row(); if ($result) { return $result->$field; } else { return ""; } } function get_no_rows($table, $field, $id, $cond1, $cond2) { $this->db->where($field, $id); $this->db->where($cond1, $cond2); $Q = $this->db->get($table); $num = $Q->num_rows(); return $num; } function get_master_code($table, $prefix_name, $field, $primary_field) { $Q = $this->db->get($table); $num = $Q->num_rows(); $prefix_values = $this->mastermodel->get_data_srow('prefix', $prefix_name, 'prefix_name'); $prefix_count = $prefix_values->prefix_digit; $prefix_code = $prefix_values->prefix; $num = $this->mastermodel->number_rows($table, '', '', '', '', '', '', $primary_field); $num++; do { $master_code = $prefix_code . str_pad($num, $prefix_count, "0", STR_PAD_LEFT); $num_rows_code = $this->mastermodel->number_rows($table, $field, $master_code); $num++; } while ($num_rows_code != 0); return $master_code; } function get_single_field_value($table, $field, $condition, $value) { $data = $this->db->query("select " . $field . " from " . $table . " where " . $condition . "='" . $value . "'"); $result = $data->row(); if ($result) { return $result->$field; } else { return ""; } } function get_single_field_value_two($table, $field, $condition, $value, $condition1, $value1) { $sql = "select " . $field . " from " . $table . " where " . $condition . "='" . $value . "' and " . $condition1 . "='" . $value1 . "'"; $data = $this->db->query($sql); $result = $data->row(); if ($result) { return $result->$field; } else { return ""; } } function get_single_joined_value($field, $table1, $table2, $field1, $field2, $condition, $value) { $data = $this->db->query("select $table1.$field from " . $table1 . " inner join " . $table2 . " on $table1.$field1=$table2.$field2 where " . $condition . "='" . $value . "'"); $result = $data->row(); if ($result) { return $result->$field; } else { return ""; } } function get_data_dual($table, $id, $field, $id1, $field1, $sortfield = "") { $data = array(); $this->db->where($field, $id); $this->db->where($field1, $id1); if (!empty($sortfield)) { $this->db->order_by($sortfield, 'asc'); } $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function check_fee_term($term, $session, $academic_year) { $data = array(); $this->db->select('*', FALSE); $this->db->from('fee_term'); $this->db->where('fee_term_term_id', $term); $this->db->where('fee_term_session', $session); $this->db->where('fee_term_academic_year_id', $academic_year); $Q = $this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function build_menu($moduleid = "") { $user_id = $_SESSION['user_id']; $data = array(); $Q = $this->db->query("select * from menu where parent_menu_id = 0 and active=1 and module_id = " . $moduleid . " order by sort"); $P = $this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['user_id'] . "'"); $result = $P->row(); $permission = explode(',', $result->user_modules); $edit_del_permission = explode(',', $result->modules_permission); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $check = $this->mastermodel->check_user_permission($row['menu_id'], $_SESSION['user_id'], '0'); if ($check) { $data[] = $row; } } } $Q->free_result(); return $data; } function get_sub_menu_child() { $user_id = $_SESSION['user_id']; $data = array(); $Q = $this->db->query("SELECT child.* FROM `menu` parent join menu as child on(parent.menu_id = child.parent_menu_id) where child.active=1 order by child.sort"); $P = $this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['user_id'] . "'"); $result = $P->row(); $permission = explode(',', $result->user_modules); $edit_del_permission = explode(',', $result->modules_permission); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $check = $this->mastermodel->check_user_permission($row['menu_id'], $_SESSION['user_id'], '0'); if ($check) { $data[] = $row; } } } $Q->free_result(); return $data; } function get_sub_menu_child_new($parent_id) { $user_id = $_SESSION['user_id']; $data = array(); $this->db->select('child.*') ->from('menu parent') ->join('menu child', 'parent.menu_id = child.parent_menu_id') ->where('child.parent_menu_id', $parent_id) ->where('child.active', '1') ->order_by('child.sort'); $Q = $this->db->get(); // $Q = $this->db->query("SELECT child.* FROM `menu` parent join menu as child on(parent.menu_id = child.parent_menu_id) where child.active=1 order by child.sort"); $this->db->select('user_modules,modules_permission') ->from('user') ->where('user_id', $_SESSION['user_id']); $permission = $this->db->get(); //$P = $this->db->query("select user_modules,modules_permission from user where user_id='" . $_SESSION['user_id'] . "'"); $result = $permission->row(); $permission = explode(',', $result->user_modules); $edit_del_permission = explode(',', $result->modules_permission); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $check = $this->mastermodel->check_user_permission($row['menu_id'], $_SESSION['user_id'], '0'); if ($check) { $data[] = $row; } } } $Q->free_result(); return $data; } function build_module() { $flag = 0; $homemodel = 0; $data = array(); $P = $this->db->query("select user_modules from user where user_id='" . $_SESSION['user_id'] . "'"); $result = $P->row(); $permission = explode(',', $result->user_modules); $Q = $this->db->query("select * from module where active = '1' order by sort"); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $R = $this->db->query("select * from menu where module_id='" . $row['module_id'] . "' and active = 1"); foreach ($R->result_array() as $menu) { $check = $this->mastermodel->check_user_permission($menu['menu_id'], $_SESSION['user_id'], '0'); if ($check) { $flag = 1; } } if ($homemodel == 0) { $data[] = $row; $homemodel = 1; } if ($flag == 1) { $data[] = $row; $flag = 0; } else { $flag = 0; } } } $Q->free_result(); return $data; } function chk_url_permission($menuid) { if (!isset($_SESSION['user_id'])) die(); $uid = $_SESSION['user_id']; $permission = $this->get_single_field_value('user', 'user_modules', 'user_id', $uid); $array = explode(',', $permission); if (in_array($menuid, $array)) { return true; } else { return false; } } function getdatas($table, $sortfield = "", $sort_order = "asc", $primary_field = '') { $data = array(); if (!empty($sortfield)) { $this->db->order_by($sortfield, $sort_order); } if (!empty($primary_field)) { $this->db->join('master', "master.master_id=$table.$primary_field"); } $Q = $this->db->get($table); // echo $this->db->last_query(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getLastPagination($table, $id, $field) { $data = array(); $this->db->query("SELECT * FROM $table ORDER BY nutrition_bottle $id DESC LIMIT 1"); $query = $this->db->get($table); $data = $query->row_array(); return $data; } function get_data($table, $id, $field, $sortfield = "", $primary_field = '') { $data = array(); $this->db->where($field, $id); if (!empty($sortfield)) { $this->db->order_by($sortfield, 'asc'); } if (!empty($primary_field)) { $this->db->join('master', "master.master_id=$table.$primary_field"); } $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_sibling_details($parent, $student) { $data = array(); $this->db->join('student', "student.student_id=parent_student.student_id"); $this->db->where('parent_id', $parent); $this->db->where('parent_student.student_id !=', $student); $Q = $this->db->get('parent_student'); // echo $this->db->last_query(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_data_joined($table1, $table2, $field1, $field2, $id = '', $field = '', $sortfield = "") { $data = array(); if ($id != '') $this->db->where($field, $id); $this->db->join($table2, "$table2.$field2=$table1.$field1"); if (!empty($sortfield)) { $this->db->order_by($sortfield, 'desc'); } $Q = $this->db->get($table1); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } // echo $this->db->last_query(); $Q->free_result(); return $data; } function get_data_srow($table, $id, $field, $isarray = FALSE) { $data = array(); $this->db->where($field, $id); $Q = $this->db->get($table); if ($isarray) $row = $Q->row_array(); else $row = $Q->row(); return $row; } function get_srow($table, $field) { $data = array(); $Q = $this->db->get($table); $row = $Q->row(); return $row; } function get_data_srow_joined($table1, $table2, $field1, $field2, $id, $field) { $this->db->join($table2, "$table2.$field2=$table1.$field1"); $this->db->where($field, $id); $Q = $this->db->get($table1); $row = $Q->row(); return $row; } function get_data_scoloumn($table, $id, $field, $coloumn, $sortfield = "") { $data = array(); $this->db->where($field, $id); if (!empty($sortfield)) { $this->db->order_by($sortfield, 'asc'); } $this->db->select($coloumn); $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getmoduledatamaster() { $data = array(); $res = $this->db->query("select module.module_name,module.module_title,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort, menu_icon from module join menu on module.module_id=menu.module_id where module.active = '1' and menu.active='1' order by module.sort, menu.sort"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function getmodules() { $data = array(); $res = $this->db->query("select * from module where module.active=1 and module.module_name != 'home' order by module.sort"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function getmenus($module_id) { $data = array(); $res = $this->db->query("select * from menu where menu.active=1 and menu.module_id='$module_id' order by parent_menu_id,menu.sort"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function getmoduledata() { $data = array(); $res = $this->db->query("select module.module_title,module.module_name,menu.caption,menu.target,menu.menu_id,menu.module_id,menu.sort from module join menu on module.module_id=menu.module_id where menu.active=1 and module.active=1 order by module.sort, menu.sort"); foreach ($res->result_array() as $row) { $data[] = $row; } return $data; } function replacemenu($menuid) { $uid = $_SESSION['user_id']; $permission = $this->get_single_field_value('user', 'user_modules', 'user_id', $uid); $array = explode(',', $permission); if (in_array($menuid, $array)) { return $menuid; } else { return false; } } function permissionList() { $permission = array(); $user_id = $_SESSION['user_id']; $P = $this->db->query("select user_modules from user where user_id='" . $user_id . "'"); $result = $P->row(); $permission = explode(',', $result->user_modules); return $permission; } function checkexistencearray($table, $field, $value) { $tbarr = explode('~', $table); $fdarr = explode('~', $field); for ($i = 0; $i < sizeof($tbarr); $i++) { $this->db->from($tbarr[$i]); $this->db->where($fdarr[$i], $value); $count = $this->db->count_all_results(); if ($count > 0) { return $count; break; } else { continue; } } } function checkexistence($table, $field, $value) { $this->db->from($table); $this->db->where($field, $value); $count = $this->db->count_all_results(); return $count; } function check_user_permission($menuid, $user_id, $check) { $this->db->select('user_modules,modules_permission'); $this->db->from('user'); $this->db->where('user_id', $user_id); $data = $this->db->get(); $result = $data->row(); $array_perm = explode(',', $result->modules_permission); $array_mod = explode(',', $result->user_modules); $found = array_search($menuid, $array_mod); $val = 0; if (isset($array_perm[$found])) $val = $array_perm[$found]; $a = decbin($val); $d = sprintf('%03u', $a); $ar = str_split($d); if ($ar[$check] == 1) { return true; } else { return false; } } function check_home_page($menuid, $user_id, $check) { $this->db->select('*'); $this->db->from('user'); $this->db->where('user_id', $user_id); $data = $this->db->get(); $result = $data->row(); $array_perm = explode(',', $result->modules_permission); $array_mod = explode(',', $result->user_modules); $array_home_page = explode(',', $result->home_page); $found = array_search($menuid, $array_mod); $val = 0; if (isset($array_perm[$found])) $val = $array_perm[$found]; $a = decbin($val); $d = sprintf('%03u', $a); $ar = str_split($d); if ($ar[$check] == 1 && (isset($array_home_page[$found]) && $array_home_page[$found] == 1)) { return true; } else { return false; } } function getreminder() { $data = array(); $tdate = date('Y-m-d'); $data = $this->db->query("select * from reminder join master on master_id=reminder_id where creator_id=" . $_SESSION['user_id'] . " and remind_before >= datediff(reminder_date,now()) and datediff(reminder_date,now())>=0"); return $data; } function add($postdata) { $data = array(); $data['resfunction'] = $postdata['resfunction']; $table = $postdata['tab_name']; unset($postdata['tab_name']); unset($postdata['resfunction']); $res = $this->db->insert($table, $postdata); $cnt = $this->db->insert_id(); if ($res > 0) { $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; } else { $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; } return $data; } function update($postdata) { $data = array(); $data['resfunction'] = $postdata['resfunction']; $table = $postdata['tab_name']; $field = $postdata['tab_field']; $id = $postdata['tab_id']; unset($postdata['resfunction']); unset($postdata['tab_name']); unset($postdata['tab_field']); unset($postdata['tab_id']); $this->db->where($field, $id); $res = $this->db->update($table, $postdata); if ($res > 0) { $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; } else { $data['res'] = 0; $data['msg'] = 'Error On updating Record'; } return $data; } function deletedata($table, $id, $field) { $data = array(); $this->db->trans_begin(); $this->db->delete($table, array($field => $id)); $this->db->trans_status(); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Unable to delete record because of associated data'; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Data Deleted Successfully'; } return $data; } function norecords($tabname) { $data = array(); $sql = "select MAX(id) as maxid from $tabname"; $res = mysql_query($sql); $row = mysql_fetch_array($res); $numcode = $row['maxid']; if ($numcode != '') { return $numcode; } else { return 0; } } function convertdateformat($date) { if ($date == "" || $date == "00-00-0000") { return ""; } else { $time = strtotime($date); return date('Y-m-d', $time); } } function convertdatenormalformat($date) { if ($date == "" || $date == "0000-00-00") { return ""; } else { $time = strtotime($date); return date('d-m-Y', $time); } } function insertmasterdata() { $time = date("Y-m-d H:i:s"); $tblValues = array('menu_id' => $_SESSION['current_mode'], 'creator_id' => $_SESSION['employee_id'], 'owner_id' => $_SESSION['employee_id'], 'created_time' => $time, 'ip_address' => $_SERVER['REMOTE_ADDR']); $this->db->insert('master', $tblValues); return mysql_insert_id(); } function updatemasterdata($id, $branch_id = '') { $time = date("Y-m-d H:i:s"); $tblValues = array('modifier_id' => $_SESSION['user_id'], 'modified_time' => $time, 'ip_address' => $_SERVER['REMOTE_ADDR']); $this->db->where('master_id', $id); $this->db->update('master', $tblValues); } /* Common function ends here */ /* Search function starts here */ function convert_number($number) { if (($number < 0) || ($number > 999999999)) { throw new Exception("Number is out of range"); } $Gn = floor($number / 1000000); /* Millions (giga) */ $number -= $Gn * 1000000; $kn = floor($number / 1000); /* Thousands (kilo) */ $number -= $kn * 1000; $Hn = floor($number / 100); /* Hundreds (hecto) */ $number -= $Hn * 100; $Dn = floor($number / 10); /* Tens (deca) */ $n = $number % 10; /* Ones */ $res = ""; if ($Gn) { $res .= $this->convert_number($Gn) . " Million"; } if ($kn) { $res .= (empty($res) ? "" : " ") . $this->convert_number($kn) . " Thousand"; } if ($Hn) { $res .= (empty($res) ? "" : " ") . $this->convert_number($Hn) . " Hundred"; } $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"); $tens = array("", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"); if ($Dn || $n) { if (!empty($res)) { $res .= " and "; } if ($Dn < 2) { $res .= $ones[$Dn * 10 + $n]; } else { $res .= $tens[$Dn]; if ($n) { $res .= " " . $ones[$n]; } } } if (empty($res)) { $res = "zero"; } return $res; } function getdistinctfield_condition($field, $table, $id, $value, $sortfield = "") { $data = array(); $this->db->distinct(); $this->db->select($field); $this->db->where($id, $value); if (!empty($sortfield)) { $this->db->order_by($sortfield, "asc"); } $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_employee_number() { $prefix = $this->mastermodel->get_single_field_value('prefix', 'prefix_code', 'prefix_name', 'Employee'); $prefix_no = $this->mastermodel->get_single_field_value('prefix', 'starting_no', 'prefix_name', 'Employee'); $this->db->from('employee'); $num = $this->db->count_all_results(); $num++; $num+=$prefix_no; do { $employee_number = $prefix . $num; $num_rows = $this->mastermodel->get_num_rows('employee', 'employee_no', $employee_number); $num++; } while ($num_rows != 0); return $employee_number; } function get_teacher_number() { $this->db->like('employee_no', 'TEA'); $this->db->from('employee'); $num = $this->db->count_all_results(); $num++; do { $teacher_number = 'TEA' . str_pad($num, 3, "0", STR_PAD_LEFT); ; $num_rows = $this->mastermodel->get_num_rows('employee', 'employee_no', $teacher_number); $num++; } while ($num_rows != 0); return $teacher_number; } function get_student_number() { $prefix = $this->mastermodel->get_single_field_value('prefix', 'prefix_code', 'prefix_name', 'Student'); $prefix_no = $this->mastermodel->get_single_field_value('prefix', 'starting_no', 'prefix_name', 'Student'); $this->db->from('student'); $num = $this->db->count_all_results(); $num++; $num+=$prefix_no; do { $student_number = $prefix . $num; ; $num_rows = $this->mastermodel->get_num_rows('student', 'reg_no', $student_number); $num++; } while ($num_rows != 0); return $student_number; } /* functions for course */ function search_fee_master($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('fee_master'); $this->db->where('active', 1); $this->db->order_by('fee_master_id', 'asc'); $data['results'] = $this->db->get(); return $data; } function search_session() { $data = array(); $this->db->select('*'); $this->db->from('session'); $this->db->order_by('session_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_session($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'session_name' => $postdata['session_name'], 'session_start' => $postdata['session_start_hr'] . ':' . $postdata['session_start_min'], 'session_end' => $postdata['session_end_hr'] . ':' . $postdata['session_end_min'] ); $this->db->insert('session', $tblValues); $data['resfunction'] = 'search_session'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_session($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'session_name' => $postdata['session_name'], 'session_start' => $postdata['session_start_hr'] . ':' . $postdata['session_start_min'], 'session_end' => $postdata['session_end_hr'] . ':' . $postdata['session_end_min'] ); $this->db->where('session_id', $postdata['tab_id']); $this->db->update('session', $tblValues); $data['resfunction'] = 'search_session'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_class_name() { $data = array(); $this->db->select('*'); $this->db->from('class_name'); $this->db->join('class_room', 'class_room.class_room_id = class_name.class_room_id'); $this->db->join('academic_year', 'academic_year_id = class_name_academic_year_id'); $this->db->order_by('class_name_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_class_name($postdata) { $data = array(); $this->db->trans_begin(); $days = ""; if (isset($postdata['class_days'])) { $days = implode(',', $postdata['class_days']); } $start_time = $postdata['start_time_hour'] . ":" . $postdata['start_time_minute']; $end_time = $postdata['end_time_hour'] . ":" . $postdata['end_time_minute']; if ($postdata['class_room_name'] != '') { $class_room_id = $this->mastermodel->get_single_field_value('class_room', 'class_room_id', 'class_room_name', $postdata['class_room_name']); if ($class_room_id == '') { $tblValues = array( 'class_room_name' => $postdata['class_room_name'], ); $this->db->insert('class_room', $tblValues); $class_room_id = mysql_insert_id(); } } $tblValues = array( 'class_name_code' => $postdata['class_name_code'], 'class_section' => $postdata['class_section'], 'class_room_id' => $class_room_id, 'class_name_academic_year_id' => $postdata['class_name_academic_year_id'], 'class_days' => $days, 'class_start_time' => $start_time, 'class_end_time' => $end_time, ); $this->db->insert('class_name', $tblValues); $class_id = mysql_insert_id(); $i = 1; while (isset($postdata['teacher' . $i]) && isset($postdata['teacher_wef_date' . $i])) { if ($postdata['teacher' . $i] != '') { $tbl1Values = array( 'class_name_id' => $class_id, 'teacher_id' => $postdata['teacher' . $i], 'wef_date' => $this->mastermodel->convertdateformat($postdata['teacher_wef_date' . $i]) ); $this->db->insert('class_teacher', $tbl1Values); } $i++; } $data['resfunction'] = 'search_class_name'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_class_name($postdata) { $data = array(); $this->db->trans_begin(); $days = ""; if (isset($postdata['class_days'])) { $days = implode(',', $postdata['class_days']); } $start_time = $postdata['start_time_hour'] . ":" . $postdata['start_time_minute']; $end_time = $postdata['end_time_hour'] . ":" . $postdata['end_time_minute']; if ($postdata['class_room_name'] != '') { $class_room_id = $this->mastermodel->get_single_field_value('class_room', 'class_room_id', 'class_room_name', $postdata['class_room_name']); if ($class_room_id == '') { $tblValues = array( 'class_room_name' => $postdata['class_room_name'], ); $this->db->insert('class_room', $tblValues); $class_room_id = mysql_insert_id(); } } $tblValues = array( 'class_name_code' => $postdata['class_name_code'], 'class_section' => $postdata['class_section'], 'class_room_id' => $class_room_id, 'class_name_academic_year_id' => $postdata['class_name_academic_year_id'], 'class_days' => $days, 'class_start_time' => $start_time, 'class_end_time' => $end_time, ); $this->db->where('class_name_id', $postdata['class_name_id']); $this->db->update('class_name', $tblValues); $this->db->where('class_name_id', $postdata['class_name_id']); $this->db->delete('class_teacher'); $i = 1; while (isset($postdata['teacher' . $i]) && isset($postdata['teacher_wef_date' . $i])) { if ($postdata['teacher' . $i] != '') { $tbl1Values = array( 'class_name_id' => $postdata['class_name_id'], 'teacher_id' => $postdata['teacher' . $i], 'wef_date' => $this->mastermodel->convertdateformat($postdata['teacher_wef_date' . $i]) ); $this->db->insert('class_teacher', $tbl1Values); } $i++; } $data['resfunction'] = 'search_class_name'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_class_room($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('class_room'); $this->db->order_by('class_room_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function convdatforsearch($xdate) { $mydate = explode('-', $xdate); if (sizeof($mydate) > 2) return $mydate[2] . "-" . $mydate[1] . "-" . $mydate[0]; else if (sizeof($mydate) > 1) return $mydate[1] . "-" . $mydate[0]; else return $mydate[0]; } function check_class_code($class_name_id, $class_room_id, $session, $term, $academic_year) { $data = array(); $this->db->select('*'); $this->db->from('class_name'); $this->db->where('class_room_id', $class_room_id); $this->db->where('class_session', $session); $this->db->where('class_term_id', $term); $this->db->where('class_name_academic_year_id', $academic_year); if ($class_name_id > 0) { $this->db->where('class_name_id !=', $class_name_id); } $Q = $this->db->get(); // echo $this->db->last_query(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } /* functions for exam */ function search_assessment_master($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('assessment_master'); $this->db->order_by('assessment_master_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_assessment_master($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'assessment_master_name' => $postdata['assessment_master_name'], 'class_name_id' => $postdata['class_name_id'], 'start_date' => $this->mastermodel->convertdateformat($postdata['start_date']), 'end_date' => $this->mastermodel->convertdateformat($postdata['end_date']) ); $this->db->insert('assessment_master', $tblValues); $data['resfunction'] = 'search_assessment_master'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_assessment_master($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'assessment_master_name' => $postdata['assessment_master_name'], 'start_date' => $this->mastermodel->convertdateformat($postdata['start_date']), 'end_date' => $this->mastermodel->convertdateformat($postdata['end_date']) ); $this->db->where('assessment_master_id', $postdata['assessment_master_id']); $this->db->update('assessment_master', $tblValues); $data['resfunction'] = 'search_assessment_master'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } /* functions for branch */ function search_branch($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('branch'); $this->db->order_by('branch_id', 'desc'); $data['results'] = $this->db->get(); return $data; } // /* functions for Center */ function search_nursery() { $data = array(); $this->db->select('*'); $this->db->from('nursery'); $data['results'] = $this->db->get(); return $data; } function update_nursery($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'nursery_name' => $postdata['nursery_name'], 'city' => $postdata['city'], 'country' => $postdata['country'], 'municipality' => $postdata['municipality'], 'address' => $postdata['address'], 'age_limit' => $postdata['age_limit'], 'curriculum' => $postdata['curriculum'], 'contact_no' => $postdata['contact_no'], 'email' => $postdata['email'], 'fax' => $postdata['fax'], 'po_code' => $postdata['po_code'], 'website' => $postdata['website'], 'theme' => $postdata['theme'] ); $this->db->where('nursery_id', $postdata['nursery_id']); $this->db->update('nursery', $tblValues); $data['resfunction'] = 'search_nursery'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } /* fucntions for term */ function search_term() { $data = array(); $this->db->select('*'); $this->db->from('term'); $this->db->order_by('term_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function fee_paid_details($class_id = "") { $data = array(); $this->db->select('*,SUM(IFNULL(amount_paid,0)) as fee_paid', false); $this->db->from('student_class'); $this->db->join('fee', 'fee.student_class_id=student_class.student_class_id', 'left'); $this->db->join('student', 'student.student_id=student_class.student_id'); $this->db->join('class_name', 'class_name.class_name_id=student_class.class_name_id', 'left'); $this->db->join('fee_paid_details', 'fee_paid_details.fee_id=fee.fee_id'); $this->db->order_by('fee.student_class_id', 'asc'); $this->db->group_by('fee.student_class_id'); if ($class_id != "") { $this->db->where('student_class.class_name_id', $class_id); } $Q = $this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[$row['student_class_id']] = $row; } } $Q->free_result(); return $data; } function leave_application_alert() { $data = array(); $interval = $this->mastermodel->get_single_field_value('alert_master', 'alert_master_days', 'alert_master_type', 'leave_application_alert'); $sql = "SELECT * FROM leave_application JOIN employee on leave_application.employee_id=employee.employee_id LEFT JOIN alert_close ON alert_close.master_id= leave_application.leave_application_id and alert_date=from_date where NOW() between DATE_SUB(DATE_FORMAT(from_date,'%Y-%m-%d') ,INTERVAL $interval DAY) and DATE_FORMAT(from_date,'%Y-%m-%d') and employee_reporting_to=" . $_SESSION['employee_id'] . " HAVING alert_close.id is null"; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function document_alert() { $data = array(); //$document = $this->mastermodel->get_single_field_value('alert_master', 'alert_master_days', 'alert_master_type', 'document_alert'); $sql = "SELECT *,DATE_SUB(concat( YEAR(NOW()) , '-', DATE_FORMAT(file_expiry_date,'%m-%d')) ,INTERVAL file_remind_before DAY) as alertdate from nursery_file LEFT JOIN alert_close ON alert_close.master_id= nursery_file.file_id and alert_date=file_expiry_date where NOW() between DATE_SUB(DATE_FORMAT(file_expiry_date,'%Y-%m-%d') ,INTERVAL file_remind_before DAY) and DATE_FORMAT(file_expiry_date,'%Y-%m-%d') HAVING alert_close.id is null "; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function fee_pending_alert($class_id = "") { $data = array(); $data['result_list'] = array(); $data['result_count'] = array(); $this->db->select('*,IF(payment_type="term",SUM(fee_amount),SUM(amount)) as fee', false); $this->db->from('student_class'); $this->db->join('student', 'student.student_id=student_class.student_id'); $this->db->join('class_name', 'class_name.class_name_id=student_class.class_name_id'); $this->db->join('student_class_fee', 'student_class_fee.student_class_id=student_class.student_class_id', 'left'); $this->db->join('student_monthly_fee', 'student_monthly_fee.student_class_fee_id=student_class_fee.student_class_fee_id', 'left'); $this->db->join('alert_close', 'alert_close.master_id=student_class.student_class_id AND ( year(now())=year(alert_date) AND month(now())=month(alert_date)) AND alert_date <= now() AND alert_type="fee_pending"', 'left'); // $this->db->where("student_monthly_fee.fee_wef_date<='", date('Y-m-d') ."'" , false); $this->db->order_by('student_class_fee.student_class_id,student_class_fee.student_class_fee_id', 'asc'); $this->db->group_by('student_class_fee.student_class_id,student_class_fee.student_class_fee_id'); if ($class_id != "") { $this->db->where('student_class.class_name_id', $class_id); } $this->db->having('alert_close.id is null'); $Q = $this->db->get(); // echo $this->db->last_query(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data['result'][$row['student_class_id']] = $row; if (isset($data['amount'][$row['student_class_id']])) { // var_dump($row); $data['amount'][$row['student_class_id']]+=$row['fee']; } else $data['amount'][$row['student_class_id']] = $row['fee']; } } $data['amount_paid'] = $this->fee_paid_details($class_id); // var_dump($data['result'][$row['student_class_id']]); if (isset($data['result'])) { foreach ($data['result'] as $value) { $paid = 0; if (isset($data['amount_paid'][$value['student_class_id']]['fee_paid'])) { // var_dump($data['amount_paid'][$value['student_class_id']]); $paid = $data['amount_paid'][$value['student_class_id']]['fee_paid']; if ($paid < $data['amount'][$value['student_class_id']]) { $data['result_list'][$value['student_class_id']] = $value; $data['result_list'][$value['student_class_id']]['fee_paid'] = $paid; $data['result_list'][$value['student_class_id']]['fee'] = $data['amount'][$value['student_class_id']]; if (isset($data['result_count'][$value['class_name_id']])) { $data['result_count'][$value['class_name_id']]+=1; } else { $data['result_count'][$value['class_name_id']] = 1; } } } } } $Q->free_result(); return $data; } function age_limit() { $data = array(); $age = $this->mastermodel->get_single_field_value('alert_master', 'alert_master_days', 'alert_master_type', 'age_limit_alerts'); $age_limit = $this->mastermodel->get_single_field_value('nursery', 'age_limit', 'nursery_id', '1'); $sql = "SELECT *,DATE_SUB(concat( YEAR(NOW()) , '-', DATE_FORMAT(dob,'%m-%d')) ,INTERVAL $age DAY) as alertdate from student where NOW() between DATE_SUB(concat( YEAR(NOW()) , '-', DATE_FORMAT(dob,'%m-%d')) ,INTERVAL $age DAY) and concat( YEAR(NOW()) , '-', DATE_FORMAT(dob,'%m-%d')) and student_id NOT IN (SELECT master_id from alert_close) "; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $student_age = $this->getAgeDetails($row['dob']); if ($student_age['age'] >= $age_limit || $student_age['age'] == ($age_limit-1)) { $data[] = $row; } } } $Q->free_result(); return $data; } function medical_expiry() { $data = array(); $medical = $this->mastermodel->get_single_field_value('alert_master', 'alert_master_days', 'alert_master_type', 'medical_test_expiry_alerts'); $sql = "SELECT *,DATE_SUB(concat( YEAR(NOW()) , '-', DATE_FORMAT(employee_medical_test_expiry_date,'%m-%d')) ,INTERVAL $medical DAY) as alertdate from employee LEFT JOIN alert_close ON alert_close.master_id= employee.employee_id and alert_date=employee_medical_test_expiry_date where NOW() between DATE_SUB(DATE_FORMAT(employee_medical_test_expiry_date,'%Y-%m-%d') ,INTERVAL $medical DAY) and DATE_FORMAT(employee_medical_test_expiry_date,'%Y-%m-%d') HAVING alert_close.id is null "; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function resident_expiry() { $data = array(); $resident = $this->mastermodel->get_single_field_value('alert_master', 'alert_master_days', 'alert_master_type', 'resident_visa_expiry_alerts'); $sql = "SELECT *,DATE_SUB(concat( YEAR(NOW()) , '-', DATE_FORMAT(employee_visa_expiry_date,'%m-%d')) ,INTERVAL $resident DAY) as alertdate from employee LEFT JOIN alert_close ON alert_close.master_id= employee.employee_id and alert_date=employee_visa_expiry_date where NOW() between DATE_SUB(concat( YEAR(NOW()) , '-', DATE_FORMAT(employee_visa_expiry_date,'%m-%d')) ,INTERVAL $resident DAY) and concat( YEAR(NOW()) , '-', DATE_FORMAT(employee_visa_expiry_date,'%m-%d')) HAVING alert_close.id is null "; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function labour_expiry() { $data = array(); $labour = $this->mastermodel->get_single_field_value('alert_master', 'alert_master_days', 'alert_master_type', 'labor_card_expiry_alerts'); $sql = "SELECT *,DATE_SUB(concat( YEAR(NOW()) , '-', DATE_FORMAT(employee_labour_card_expiry_date,'%m-%d')) , INTERVAL $labour DAY) as alertdate from employee LEFT JOIN alert_close ON alert_close.master_id= employee.employee_id and alert_date=employee_labour_card_expiry_date where NOW() between DATE_SUB(concat( YEAR(NOW()) , '-', DATE_FORMAT(employee_labour_card_expiry_date,'%m-%d')) , INTERVAL $labour DAY) and concat( YEAR(NOW()) , '-', DATE_FORMAT(employee_labour_card_expiry_date,'%m-%d')) HAVING alert_close.id is null"; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } // function alert_count() // { // $data = array(); // // // } function search_fee_particular() { $data = array(); $this->db->select('*'); $this->db->from('fee_particular'); $this->db->order_by('fee_particular_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function search_fee_term($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('fee_term'); $this->db->join('session', 'session.session_id=fee_term_session'); $this->db->join('term', 'term.term_id=fee_term_term_id'); $this->db->join('academic_year', 'academic_year.academic_year_id=fee_term.fee_term_academic_year_id'); $this->db->order_by('fee_term_id', 'desc'); $data['results'] = $this->db->get(); return $data; } /* fucntions for nationality */ function search_nationality() { $data = array(); $this->db->select('*'); $this->db->from('nationality'); $this->db->order_by('nationality_id', 'desc'); $data['results'] = $this->db->get(); return $data; } /* functions for academic year */ function search_academic_year() { $data = array(); $this->db->select('*'); $this->db->from('academic_year'); $this->db->order_by('academic_year_year', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_academic_year($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'academic_year_year' => $postdata['academic_year_year'], 'display_name' => $postdata['display_name'], 'academic_year_start_date' => $this->mastermodel->convertdateformat($postdata['academic_year_start_date']), 'academic_year_end_date' => $this->mastermodel->convertdateformat($postdata['academic_year_end_date']), ); $this->db->insert('academic_year', $tblValues); $academic_year_id = mysql_insert_id(); $i = 1; while (isset($postdata['term' . $i])) { if ($postdata['term' . $i] != '') { $term_id = $this->mastermodel->get_single_field_value('term', 'term_id', 'term_name', $postdata['term' . $i]); if ($term_id == '') { $tblValues = array( 'term_name' => $postdata['term' . $i], ); $this->db->insert('term', $tblValues); $term_id = mysql_insert_id(); } $tbl1Values = array( 'academic_year_id' => $academic_year_id, 'term_id' => $term_id, 'term_start_date' => $this->mastermodel->convertdateformat($postdata['term_start_date' . $i]), 'term_end_date' => $this->mastermodel->convertdateformat($postdata['term_end_date' . $i]) ); $this->db->insert('term_academic_details', $tbl1Values); } $i++; } $data['resfunction'] = 'search_academic_year'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_academic_year($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'display_name' => $postdata['display_name'], 'academic_year_start_date' => $this->mastermodel->convertdateformat($postdata['academic_year_start_date']), 'academic_year_end_date' => $this->mastermodel->convertdateformat($postdata['academic_year_end_date']), ); $this->db->where('academic_year_id', $postdata['academic_year_id']); $this->db->update('academic_year', $tblValues); $this->db->where('academic_year_id', $postdata['academic_year_id']); $this->db->delete('term_academic_details'); $i = 1; while (isset($postdata['term' . $i])) { if ($postdata['term' . $i] != '') { $term_id = $this->mastermodel->get_single_field_value('term', 'term_id', 'term_name', $postdata['term' . $i]); if ($term_id == '') { $tblValues = array( 'term_name' => $postdata['term' . $i], ); $this->db->insert('term', $tblValues); $term_id = mysql_insert_id(); } $tbl1Values = array( 'academic_year_id' => $postdata['academic_year_id'], 'term_id' => $term_id, 'term_start_date' => $this->mastermodel->convertdateformat($postdata['term_start_date' . $i]), 'term_end_date' => $this->mastermodel->convertdateformat($postdata['term_end_date' . $i]) ); $this->db->insert('term_academic_details', $tbl1Values); } $i++; } $data['resfunction'] = 'search_academic_year'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_effort_behavior() { $data = array(); $this->db->select('*'); $this->db->from('effort_behavior'); $this->db->order_by('effort_behavior_id', 'desc'); $data['results'] = $this->db->get(); return $data; } /* functions for subject */ function search_subject() { $data = array(); $this->db->select('*'); $this->db->from('subject'); $this->db->order_by('subject_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_subject($postdata) { $data = array(); $this->db->trans_begin(); $prefix = "SUB"; $prefix_no = "100"; $this->db->from('student'); $num = $this->db->count_all_results(); $num++; $num+=$prefix_no; do { $subject_code = $prefix . $num; $num_rows = $this->mastermodel->get_num_rows('subject', 'subject_code', $subject_code); $num++; } while ($num_rows != 0); $tblValues = array( 'subject_code' => $subject_code, 'subject_name' => $postdata['subject_name'] ); $this->db->insert('subject', $tblValues); $data['resfunction'] = 'search_subject'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_subject($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'subject_name' => $postdata['subject_name'], ); $this->db->where('subject_id', $postdata['subject_id']); $this->db->update('subject', $tblValues); $data['resfunction'] = 'search_subject'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_file_type($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('file_type'); $this->db->order_by('file_type_id', 'asc'); $data['results'] = $this->db->get(); return $data; } function insert_file_type($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'file_type' => $postdata['file_type'], ); $this->db->insert('file_type', $tblValues); $data['resfunction'] = 'search_file_type'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_fee_particular($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'fee_particular_name' => $postdata['fee_particular_name'], ); $this->db->where('fee_particular_id', $postdata['fee_particular_id']); $this->db->update('fee_particular', $tblValues); $data['resfunction'] = 'search_fee_particular'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function update_file_type($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'file_type' => $postdata['file_type'], ); $this->db->where('file_type_id', $postdata['file_type_id']); $this->db->update('file_type', $tblValues); $data['resfunction'] = 'search_file_type'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_no_sessions() { $data = array(); $this->db->select('*'); $this->db->from('no_sessions'); $this->db->order_by('no_sessions_id', 'asc'); $data['results'] = $this->db->get(); return $data; } function search_expense_type($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('expense_type'); $this->db->order_by('expense_type_id', 'asc'); $data['results'] = $this->db->get(); return $data; } function upload_file($postdata) { $this->db->trans_begin(); $tbl1Values = array('master_id' => $postdata['master_id'], 'file_type_id' => $postdata['file_type_id'], 'file_date' => date("Y-m-d"), 'file_location' => $postdata['file_location']); $this->db->insert('file', $tbl1Values); $this->db->trans_commit(); } function upload_nursery_file($postdata) { $this->db->trans_begin(); $tbl1Values = array( 'file_name' => $postdata["file_name"], 'file_location' => $postdata['file_location'], 'file_expiry_date' => $this->mastermodel->convertdateformat($postdata['file_expiry_date']), 'file_remind_before' => $postdata['file_remind_before']); $this->db->insert('nursery_file', $tbl1Values); $this->db->trans_commit(); } function get_data_dual_srow($table, $id1, $field1, $id2, $field2, $sortfield = "") { $data = array(); $this->db->where($field1, $id1); $this->db->where($field2, $id2); if (!empty($sortfield)) { $this->db->order_by($sortfield, 'asc'); } $Q = $this->db->get($table); $row = $Q->row(); return $row; } function get_alert_datas() { $data = array(); $sql = "SELECT `alert_master_name`,`alert`.`alert_master_id`,count(alert.alert_id) FROM `alert_master` JOIN alert on alert_master.alert_master_id=alert.alert_master_id JOIN master on master.master_id=alert.alert_record_id WHERE alert.alert_status=1 GROUP BY `alert_master`.`alert_master_id` "; $Q = $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function deletsub($id) { $this->db->where('id', $id); $this->db->delete('course_subject'); } function traceemployee($employee_id, $staff_list) { $employee_list = $this->mastermodel->get_data('employee', $employee_id, 'employee_reporting_to'); foreach ($employee_list as $list) { if ($list['employee_id'] != $employee_id) { $staff_list .= $list['employee_id'] . ','; $this->traceemployee($list['employee_id'], $staff_list); } } $return_list = substr($staff_list, 0, -1); return implode(',', array_unique(explode(',', $return_list))); } function get_account_settings($field, $table) { $data = array(); $this->db->select($field); $q = $this->db->get($table); if ($q->num_rows() > 0) $res = $q->row()->$field; else $res = 0; return $res; } function get_employee_not_user() { $data = array(); $this->db->where('`employee`.`employee_id` NOT IN (SELECT `employee_id` FROM `user`)', NULL, FALSE); $this->db->order_by('employee.employee_id', 'asc'); $Q = $this->db->get('employee'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_chart_account() { $data = array(); $this->db->select('*,finance_chart_master.chart_account_code as chart_account_code'); $this->db->from('finance_chart_master'); $this->db->join('finance_bank_account', 'finance_bank_account.chart_account_code=finance_chart_master.chart_account_code', 'left'); $this->db->having('bank_account_id is null'); $Q = $this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_student_account() { $data = array(); $this->db->select('*'); $this->db->from('finance_chart_master'); $this->db->join('student', 'student.reg_no=finance_chart_master.chart_account_code'); $this->db->order_by('student_id'); $Q = $this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getdistinct_rec_date() { $data = array(); $this->db->distinct(); $this->db->select('reconcile_date'); $this->db->join('master', 'master_id=journal_id'); $this->db->where('reconcile_date IS NOT NULL'); $this->db->order_by('reconcile_date', "asc"); $Q = $this->db->get('finance_journal'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_teacher_class($class_id, $date) { $this->db->where('class_name_id', $class_id); $this->db->where('wef_date <=', $this->mastermodel->convertdateformat($date)); $this->db->join('employee', 'employee.employee_id=class_teacher.teacher_id'); $this->db->order_by('wef_date', 'desc'); $this->db->limit('1'); $Q = $this->db->get('class_teacher'); return $Q->row(); } function insert_fee_term($postdata) { $data = array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tbl1Values = array( 'fee_term_id' => $masterid, 'fee_term_term_id' => $postdata['fee_term_term_id'], 'fee_term_session' => $postdata['fee_term_session'], 'fee_term_academic_year_id' => $postdata['fee_term_academic_year_id'], 'refund_bond_amount' => $postdata['refund_bond_amount'], 'fee_term_due_date' => $this->mastermodel->convertdateformat($postdata['fee_term_due_date']) ); $this->db->insert('fee_term', $tbl1Values); $i = 1; while (isset($postdata['fee_particular_id' . $i])) { $tbl1Values = array( 'fee_term_id' => $masterid, 'fee_particular_id' => $postdata['fee_particular_id' . $i], 'fee_term_amount' => $postdata['fee_term_amount' . $i], 'fee_month_amount' => $postdata['fee_month_amount' . $i], 'fee_term_no_of_days' => $postdata['fee_term_no_of_days' . $i] ); $this->db->insert('fee_term_details', $tbl1Values); $i++; } if (isset($postdata['month_date'])) { foreach ($postdata['month_date'] as $month_date) { $tbl1Values = array( 'fee_term_id' => $masterid, 'fee_term_monthly_due_date' => $month_date ); $this->db->insert('fee_term_due_date', $tbl1Values); } } $data['resfunction'] = 'search_fee_term'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->db->trans_commit(); $data['res'] = 1; return $data; } } function update_fee_terms($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'fee_term_session' => $postdata['fee_term_session'], 'refund_bond_amount' => $postdata['refund_bond_amount'], 'fee_term_due_date' => $this->mastermodel->convertdateformat($postdata['fee_term_due_date']) ); $this->db->where('fee_term_id', $postdata['fee_term_id']); $this->db->update('fee_term', $tblValues); $this->db->where('fee_term_id', $postdata['fee_term_id']); $this->db->delete('fee_term_details'); $this->db->where('fee_term_id', $postdata['fee_term_id']); $this->db->delete('fee_term_due_date'); $i = 1; while (isset($postdata['fee_particular_id' . $i])) { $tbl1Values = array( 'fee_term_id' => $postdata['fee_term_id'], 'fee_particular_id' => $postdata['fee_particular_id' . $i], 'fee_term_amount' => $postdata['fee_term_amount' . $i], 'fee_month_amount' => $postdata['fee_month_amount' . $i], 'fee_term_no_of_days' => $postdata['fee_term_no_of_days' . $i], ); $this->db->insert('fee_term_details', $tbl1Values); $i++; } if (isset($postdata['month_date'])) { foreach ($postdata['month_date'] as $month_date) { $tbl1Values = array( 'fee_term_id' => $postdata['fee_term_id'], 'fee_term_monthly_due_date' => $month_date ); $this->db->insert('fee_term_due_date', $tbl1Values); } } $data['resfunction'] = 'search_fee_term'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function set_academic_year_default($id) { $tblValues = array('current' => 1); $this->db->where('academic_year_id', $id); $this->db->update('academic_year', $tblValues); $sql = "UPDATE academic_year SET `current`=0 WHERE academic_year_id != $id ;"; $data = $this->db->query($sql); } function getAgeDetails($birthDate) { $data = array(); $birthDate = explode("-", $birthDate); $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[1], $birthDate[2], $birthDate[0]))) > date("md") ? ((date("Y") - $birthDate[0]) - 1) : (date("Y") - $birthDate[0])); $cur_month = date('m'); $dob_month = $birthDate[1]; $mo = 0; if ($cur_month > $dob_month) { $mo = $cur_month - $dob_month; } else if ($dob_month > $cur_month) { $mo = 12 - ($dob_month - $cur_month); } else if ($dob_month == $cur_month) { $age++; } if (date('d') < $birthDate[2]) $mo--; $data['age'] = $age; $data['month'] = $mo; $data['in_words'] = ($age != "" && $age > 0 ? $age . ($mo != "" && $mo > 0 ? "." . $mo : "") . " Yrs " : ($mo != "" && $mo > 0 ? "0." . $mo . " Yrs " : "") ); return $data; } function get_class_rollover($from_class_id) { $data = array(); $this->db->where('class_name.class_name_id != ', $from_class_id); $Q = $this->db->get('class_name'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function update_nursery_upload($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'file_name' => $postdata['file_name'], 'file_expiry_date' => $this->mastermodel->convertdateformat($postdata['file_expiry_date']), 'file_remind_before' => $postdata['file_remind_before'] ); $this->db->where('file_id', $postdata['file_id']); $this->db->update('nursery_file', $tblValues); if ($postdata['file_location'] != '') { $tblValues = array( 'file_location' => $postdata['file_location'], ); $this->db->where('file_id', $postdata['file_id']); $this->db->update('nursery_file', $tblValues); } $data['resfunction'] = 'search_nursery'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function session_name($name) { $data = array(); $this->db->select('*'); $this->db->from('session'); $this->db->where('session_name', $name); $count = $this->db->count_all_results(); if ($count > 0) { return $count; } } function get_my_alerts() { $data = array(); $this->db->where('alert_master_employee_id', $_SESSION['employee_id']); $this->db->join('alert_master_employee', "alert_master_employee.alert_master_id=alert_master.alert_master_id"); $this->db->order_by('alert_master.alert_master_id', 'asc'); $Q = $this->db->get('alert_master'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } }