File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/modules/access_control/models/Access_model.php
Back
<?php Class Access_model extends CI_Model{ function save_json($jsonArray, $ip) { $all_id = $this->get_all_Id(); $exist_id = array_column($all_id, 'devID'); foreach ($jsonArray as $input){ $input->ip = $ip; if(in_array($input->devID, $exist_id)){ $this->updateAccess((array)$input); } else $this->insertAccess((array)$input); } return true; } function get_devices() { return $this->db->get('ac_devices')->result_array(); } function get_devices_RSSI($id) { $this->db->order_by('event_time','DESC'); $this->db->where('event_type','RSSI'); $this->db->where('cardReaderID',$id); return $this->db->get('ac_log')->row_array(); } function get_by_venues($venues) { $array = array(); foreach($venues as $venue){ array_push($array, $venue['id']); } $this->db->select('venue_id,id,devID,state,lastUpdate,receiver'); $this->db->where_in('venue_id', $array); return $this->db->get('ac_devices')->result_array(); } function get_all_Id() { $this->db->select('devID'); return $this->db->get('ac_devices')->result_array(); } function updateAccess($input) { $data = array( "lastUpdate" => date('Y-m-d H:i:s', strtotime($input['lastUpdate'])) , "state" => $input['state'], "rssi" => $input['rssi'] ); $this->db->where('devID',$input['devID']); $this->db->update('ac_devices ',$data); return true; } function getUser_cards() { $this->db->select('users.*,at_user_card.card'); $this->db->where('at_user_card.active',1); $this->db->from('users'); $this->db->join('at_user_card','at_user_card.uid = users.id','left'); return $this->db->get()->result_array(); } function getUser_card($id) { $this->db->select('at_user_card.card'); $this->db->from('users'); $this->db->join('at_user_card','at_user_card.uid = users.id','left'); $this->db->where('users.id ='.$id); return $this->db->get()->row_array(); } function insertAccess($input) { if(strtotime($input['lastUpdate'])>time()) { $input['lastUpdate'] = date('Y-m-d H:i:s', strtotime($input['lastUpdate'])); } else { $input['lastUpdate'] = date('Y-m-d H:i:s', strtotime($input['lastUpdate'] . "+8hours")); } $this->db->insert('ac_devices ',$input); return true; } function updateUser_card($data) { $exist = $this->db->get_where('at_user_card','uid='.$data['uid'])->row_array(); if(empty($exist)){ $this->db->insert('at_user_card',$data); } else { $this->db->where('uid',$data['uid']); $this->db->update('at_user_card',array('card'=>$data['card'])); } return $data['card']; } function getCard_reader($card_number = 0) { return $this->db->get_where('at_user_card',array('card' => $card_number ))->row_array(); } function clearLog() { return $this->db->delete('ac_log',array('event_time <'=>date('Y-m-d',strtotime('1 days ago')))); } function importCard_Reader($data) { foreach($data as $key => $value) { if($key!=0) { $user=$this->db->get_where('users',array('username' => $value[0] ))->row_array(); if(!empty($user['id'])) { $exist=$this->db->get_where('at_user_card',array('uid' => $user['id'] ))->row_array(); if(!empty($exist)) { $this->db->where('id',$exist['id'])->update('at_user_card',['active'=>0]); } $newdata=array("uid"=>$user['id'],"card"=>$value[1],'active'=>1); $this->db->insert('at_user_card',$newdata); } unset($newdata); } } return true; } function recordDT($start,$end) { $this->db->select('ac_record.*, venues.title'); $this->db->from('ac_record'); $this->db->join('ac_devices','ac_record.devID=ac_devices.devID'); if($start!='' && $end !='') { $this->db->where('ac_record.cardTime >=',$start); $this->db->where('ac_record.cardTime <=',$end); } $db = $this->db->join('venues','ac_devices.venue_id=venues.id'); $this->datatable->get($db,$_POST); // echo $this->db->last_query(); } }
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.28 |
proxy
|
phpinfo
|
Settings