?
Current Path : /home1/savoy/public_html/savoyglobal.net/simsdemo/school/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/simsdemo/school/application/models/mastermodel.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?> <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ class Mastermodel extends Model { function Mastermodel() { parent::Model(); } function getdatas($table,$sortfield="") { $data = array(); 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 getdatas_undeleted($table,$field,$sortfield="") { $data = array(); $ayear = $this->mastermodel->getsinglefieldvalue('academicyear','ayear','current','1'); if(!empty ($sortfield)) { $this->db->order_by($sortfield, "asc"); } $this->db->join('master','masterid='.$field); $this->db->where('deleted',0); $this->db->where('ayear',$ayear); $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_data($table,$id,$field,$sortfield="") { $data = array(); $this->db->where($field,$id); 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_joined_info($table,$field,$table2,$field2,$order_field="",$where_id="",$where_field="",$where_id2="",$where_field2="") { $data = array(); $this->db->join($table2,"$table.$field=$table2.$field2"); if($where_field!="") $this->db->where($where_field,$where_id); if($where_field2!="") $this->db->where($where_field2,$where_id2); if($order_field != "") $this->db->order_by($order_field,'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_joined_single_info($table,$field,$table2,$field2,$where_field="",$where_id="") { $this->db->join($table2,"$table.$field2=$table2.$field2"); if($where_field!="") $this->db->where("$table.$where_field",$where_id); $Q= $this->db->get($table); $row=$Q->row(); return $row; } function get_data_tab($tabid='') { $flag=0; $homemodel=0; $data = array(); $P=$this->db->query("select modules from user inner join user_profiles on user_profiles.profile_id = user.profile_id where user_id='" . $_SESSION['userid'] ."'"); $result= $P->row(); $permission=explode(',',$result->modules); $sql="select * from tab where invisible = 0"; if($tabid!="") { $sql.=" and tab_id = $tabid"; } $sql.=" order by sort"; $Q= $this->db->query($sql); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $R = $this->db->query("select * from module where tab_id = '".$row['tab_id']."' and invisible=0"); foreach($R->result_array() as $module) { $check=$this->mastermodel->check_user_permission($module['module_id'],$_SESSION['userid'],'0'); if($check) { $flag=1; } } // if($flag==1) { $data[]=$row; $flag=0; } else { $flag=0; } } } $Q->free_result(); return $data; } function get_data_module($tabid) { $data = array(); $sql="select * from module where invisible = 0 and tab_id = $tabid order by sort"; $Q= $this->db->query($sql); $P=$this->db->query("select modules,permissions from user inner join user_profiles on user_profiles.profile_id = user.profile_id where user_id='" . $_SESSION['userid'] ."'"); $result= $P->row(); $permission=explode(',',$result->modules); $edit_del_permission=explode(',',$result->permissions); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $check=$this->mastermodel->check_user_permission($row['module_id'],$_SESSION['userid'],'0'); if($check) { $data[]=$row; } } } $Q->free_result(); return $data; } function count_all($table) { return $this->db->count_all($table); } function getmoduledata($moduleid="") { $data=array(); $sql="select tab.tab_name,tab.tab_caption,module.target,module.module_name,module.module_caption,module.module_id,tab.tab_id,module.sort from tab join module on tab.tab_id=module.tab_id where tab.invisible = 0 and module.invisible = 0 "; if($moduleid!="") $sql.="and module.module_id = '$moduleid'"; $sql.=" order by tab.sort, module.sort"; //echo $sql; $res=$this->db->query($sql); foreach ($res->result_array() as $row) { $check=$this->mastermodel->check_user_permission($row['module_id'],$_SESSION['userid'],'0'); if($check) { $data[]=$row; } } return $data; } function getsinglefieldvalue($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 getmaxvalue($table,$field,$condition,$value) { //echo "select max(". $field. ") as ".$field." from ". $table . " where ". $condition . "='". $value ."' and status='Success'"; $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 authenticate($username,$password) { $ip=$this->input->post('ip'); $uid= $this->getsinglefieldvalue('user','user_id','username',$username); if($uid=="") { $uid='NULL'; } $logintime=$today = date("Y-m-d H:i:s"); $passwordmd5=md5($password); $query= $this->db->query("select * from user where username='$username' and password='$passwordmd5'"); $data['numrows']=$query->num_rows(); if($query->num_rows()>0) { $lastid= $this->getmaxvalue('login_details','id','username',$username); $clogintime= $this->getmaxvalue('login_details','login_time','username',$username); $result= $query->row(); $data['userid']= $result->user_id; $data['username']=$username; $data['clogintime']=$logintime; $data['lastid']=$lastid; $data['linked_record']=$result->linkedto_id; $query1= $this->db->query("select * from login_details where username='$username' and id>='$lastid'"); $data['attempt']=($query1->num_rows())-1; $tblValues=array('username'=>$username,'password'=>$passwordmd5,'login_time '=>$logintime,'userid '=>$uid,'ip_address '=>$ip,'status '=>'Success'); $this->db->insert('login_details', $tblValues); $data['profile_type']=$this->getsinglefieldvalue('user_profiles', 'profile_user_type', 'profile_id', $result->profile_id); return $data; } else { $tblValues=array('username'=>$username,'password'=>$password,'login_time '=>$logintime,'userid '=>$uid,'failing_time '=>$logintime,'ip_address '=>$ip,'status '=>'failed'); $datas=$this->db->insert('login_details', $tblValues); } } function view($table,$page="",$per_page="") { if($page) { $start = ($page-1)*$per_page; } else { $start=0; } $this->db->limit($per_page,$start); $data['results']=$this->db->get($table); return $data['results']; } function insertmasterdata($ayear="") { $time= date("Y-m-d H:i:s"); $ip=$_SERVER['REMOTE_ADDR']; if($ayear=="") $ayear = $this->mastermodel->getsinglefieldvalue('academicyear','ayear','current','1'); $query="insert into master (creator_id,created_time,deleted,ip,module_id,ayear) values ('".$_SESSION['userid']."','$time','0','$ip','".$_SESSION['current_mode']."','$ayear')"; $this->db->query($query); return mysql_insert_id(); } function updatemasterdata($id) { $time= date("Y-m-d H:i:s"); $ip=$_SERVER['REMOTE_ADDR']; $tblValues=array('modifier_id'=>$_SESSION['userid'], 'modified_time'=>$time, 'ip'=>$ip ); $this->db->where('masterid',$id); $this->db->update('master', $tblValues); } function deletemaster($id) { $time= date("Y-m-d H:i:s"); $ip=$_SERVER['REMOTE_ADDR']; $tblValues=array('modifier_id'=>$_SESSION['userid'], 'modified_time'=>$time, 'deleted'=>'1', 'ip'=>$ip ); $this->db->where('masterid',$id); return $this->db->update('master', $tblValues); } function delete($id,$table,$field) { $this->db->where($field,$id); return $this->db->delete($table); } function get_data_srow($table,$id,$field,$sortfield="") { $data = array(); $this->db->where($field,$id); if(!empty($sortfield)) { $this->db->order_by($sortfield,'asc'); } $Q= $this->db->get($table); $row=$Q->row(); return $row; } function checkexistence($table,$field,$value) { $this->db->from($table); $this->db->where($field, $value); $count= $this->db->count_all_results(); return $count; } 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 checkexistenceedit($table,$field,$value,$masterid,$masterfield) { $this->db->from($table); $this->db->where($field, $value); $this->db->where($masterfield.' !=', $masterid); $count= $this->db->count_all_results(); return $count; } function check_user_permission($module_id,$userid,$check) { $this->db->select('modules,permissions'); $this->db->from('user_profiles'); $this->db->join('user','user.profile_id=user_profiles.profile_id'); $this->db->where('user_id', $userid); $data=$this->db->get(); $result= $data->row(); $array_perm=explode(',',$result->permissions); $array_mod=explode(',',$result->modules); $found=array_search($module_id,$array_mod); $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 deletedataperm($id,$table,$field) { if($table=='tc') { $student_id=$this->getsinglefieldvalue('tc', 'student_id', 'tc_id', $id); $tbl1Values=array( 'tc'=>'0', ); $this->db->where('student_id', $student_id); $this->db->update('student', $tbl1Values); } $this->db->where($field,$id); $res= $this->db->delete($table); return $res; } function check_dual($table,$field1,$field2,$value1,$value2) { $this->db->from($table); $this->db->where($field1,$value1); $this->db->where($field2,$value2); $count= $this->db->count_all_results(); return $count; } function convertdateformat($date) { $time = strtotime( $date ); return date( 'Y-m-d', $time ); } function convertdatenormalformat($date) { $time = strtotime( $date ); return date( 'd-m-Y', $time ); } function shownoticeboard() { $data=array(); $today=date("Y-m-d"); $this->db->select('noticeboard.id,noticeboard.title,noticeboard.note,noticeboard.posted_date'); $this->db->from('noticeboard'); $this->db->join('master','master.masterid=noticeboard.id'); $this->db->where('deleted','0'); $this->db->where('from_date <=',$today); $this->db->like('permission',$_SESSION['profile_type']); $this->db->where('to_date >=',$today); $data=$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 get_student_class($classlevel_id) { $data = array(); $ayear = $this->mastermodel->getsinglefieldvalue('academicyear','ayear','current','1'); $this->db->join('master',"master.masterid=student.student_id"); $this->db->where('ayear',$ayear); $this->db->where('tc','0'); $this->db->where('deleted','0'); $this->db->where('classlevel_id',$classlevel_id); $this->db->order_by('first_name','asc'); $Q= $this->db->get('student'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_max_row($table,$field,$append,$primaryfield) { $num_rows=$this->mastermodel->number_rows($table,'1',$primaryfield); if($num_rows==0) $num_rows++; do { $record_no = $append.str_pad($num_rows, 3, "0", STR_PAD_LEFT); $num_rows_record_no = $this->mastermodel->number_rows($table,'','',$field,$record_no); $num_rows++; }while($num_rows_record_no!=0); return $record_no; } function number_rows($tabname,$master='',$primaryfield='',$field1='',$value1='',$field2='',$value2='',$field3='',$value3='') { $data = array(); $this->db->from($tabname); if($master==1) $this->db->join("master","$tabname.$primaryfield=master.masterid"); if($field1 !='') $this->db->where($field1,$value1); if($field2 !='') $this->db->where($field2,$value2); if($field3 !='') $this->db->where($field3,$value3); if($master==1) $this->db->where('deleted','0'); return $this->db->count_all_results(); } function uploadfile($postdata) { $this->db->trans_begin(); $tbl1Values=array('file_name'=>$postdata['file_name'], 'record_id'=>$postdata['masterid'], 'file_location'=>$postdata['file_location']); $this->db->insert('files', $tbl1Values); $this->db->trans_commit(); } function getstudents($class_type) { $data = array(); $this->db->join('classlevel','classlevel.classlevel_id=student.classlevel_id'); $this->db->join('master','master.masterid=student.student_id'); if($class_type!="2") $this->db->where('classlevel.kg',$class_type); $this->db->where('student.tc','0'); $this->db->where('master.deleted','0'); $this->db->order_by('reg_no', "asc"); $Q = $this->db->get('student'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getparentf() { $data = array(); $this->db->join('master','master.masterid=parent.parent_id'); $this->db->where('master.deleted','0'); $this->db->where('relationship_type','father'); $Q = $this->db->get('parent'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getparentm() { $data = array(); $this->db->join('master','master.masterid=parent.parent_id'); $this->db->where('master.deleted','0'); $this->db->where('relationship_type','mother'); $Q = $this->db->get('parent'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getteacher() { $data = array(); $this->db->join('master','master.masterid=teacher.teacher_id'); $this->db->where('master.deleted','0'); $Q = $this->db->get('teacher'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getstaff() { $data = array(); $this->db->join('master','master.masterid=staff.staff_id'); $this->db->where('master.deleted','0'); $Q = $this->db->get('staff'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getsubject() { $data = array(); $Q = $this->db->get('subject'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getstudent() { $data = array(); $this->db->join('classlevel','classlevel.classlevel_id=student.classlevel_id'); $this->db->join('master','master.masterid=student.student_id'); $this->db->where('student.tc','0'); $this->db->where('master.deleted','0'); $this->db->order_by('reg_no', "asc"); $Q = $this->db->get('student'); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function reset_user_password_request() { $this->db->query("update forgot_password set status = '". $_POST['status'] ."' where forgot_password_id=". $_POST['forgot_password_id']); $password=md5($_POST['password']); $tbl2Values=array('password'=>$password); $this->db->where('username', $_POST['username']); $this->db->update('user', $tbl2Values); } function insertpassword($password) { $password=md5($password); $tbl2Values=array('password'=>$password); $this->db->where('user_id', $_SESSION['userid']); $this->db->update('user', $tbl2Values); } }