Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Class Postpaidmodel
- * handles controller Class Post paid requests dealing with user table in DB
- *
- *
- * @package EasyHotspot
- * @subpackage Models
- * @category Post Paid
- * @author Rafeequl Rahman Awan
- * @copyright Copyright (c) 2008, easyhotspot.sf.net
- * @license http://www.gnu.org/licenses/gpl.html
- * @link http://easyhotspot.sourceforge.net
- * @version 1.0
- */
- class Postpaidmodel extends model {
- function Postpaidmodel(){
- parent::Model();
- //tables
- $this->_table= 'postpaid_account';
- $this->_table_account_list= 'postpaid_account_list';
- $this->_table_account_bill= 'postpaid_account_bill';
- $this->_table_radcheck = 'radcheck';
- $this->_table_radreply = 'radreply';
- $this->_table_radacct = 'radacct';
- $this->_table_postplan = 'postplan';
- }
- function getAccount($fields = null, $where = null, $limit = null, $order = null){
- ($fields != null) ? $this->db->select($fields) :'';
- ($where != null) ? $this->db->where($where) :'';
- ($limit != null) ? $this->db->limit($limit['start'],$limit['end']) :'';
- ($order != null) ? $this->db->order_by($order['field'],$order['dir']) : $this->db->order_by('id','desc');
- return $this->db->get($this->_table);
- }
- function getAccountList($fields = null, $where = null, $limit = null, $order = null){
- ($fields != null) ? $this->db->select($fields) :'';
- ($where != null) ? $this->db->where($where) :'';
- ($limit != null) ? $this->db->limit($limit['start'],$limit['end']) :'';
- ($order != null) ? $this->db->order_by($order['field'],$order['dir']) : $this->db->order_by('id','desc');
- return $this->db->get($this->_table_account_list);
- }
- function getAccountUsage($fields = null, $where = null, $limit = null){
- ($fields != null) ? $this->db->select($fields) :'';
- ($where != null) ? $this->db->where($where) :'';
- ($limit != null) ? $this->db->limit($limit['start'],$limit['end']) :'';
- return $this->db->get($this->_table_account_bill);
- }
- function addAccount(){
- //data for radcheck table
- $radcheck_value = array();
- $radcheck_value['username'] = $_POST['username'];
- $radcheck_value['value'] = $_POST['password'];
- $radcheck_value['attribute'] = 'User-Password';
- $radcheck_value['op'] = ':=';
- $simultaneous['username'] = $_POST['username'];
- $simultaneous['attribute'] = 'Simultaneous-Use';
- $simultaneous['op'] = ':=';
- $simultaneous['value'] = '1';
- $this->db->trans_start();
- $this->db->insert($this->_table,$_POST); //insert into postpaid account table
- $this->db->insert($this->_table_radcheck,$radcheck_value); //insert into radcheck account table
- $this->db->insert($this->_table_radcheck,$simultaneous);
- $this->db->trans_complete();
- }
- function deleteAccount(){
- $this->db->trans_start();
- $this->db->where('username',$this->uri->segment(3));
- $this->db->delete($this->_table); //delete from postpaid_account table
- $this->db->where('username',$this->uri->segment(3));
- $this->db->delete($this->_table_radcheck); //delete from radcheck account table
- $this->db->where('username',$this->uri->segment(3));
- $this->db->delete($this->_table_radacct); //delete from radacct table
- $this->db->trans_complete();
- }
- function editAccount(){
- $tbl_postpaid_account = array ('bill_by' => $_POST['bill_by'], //fields on postpaid_account table
- 'password' => $_POST['password'] );
- $tbl_radcheck = array('value' => $_POST['password']); //field on radcheck table
- $this->db->trans_start();
- $this->db->where('username',$_POST['username']);
- $this->db->update($this->_table,$tbl_postpaid_account);
- $this->db->where('username',$_POST['username']);
- $this->db->update($this->_table_radcheck,$tbl_radcheck);
- $this->db->trans_complete();
- }
- function searchAccount($limit = null){
- //search by username or realname
- $this->db->like('username',$this->db_session->userdata('search'));
- $this->db->orlike('realname',$this->db_session->userdata('search'));
- //limit
- ($limit !=null ) ? $this->db->limit($limit['start'],$limit['end']) :'';
- return $this->db->get($this->_table_account_list);
- }
- function getAccountStatistic(){
- //account created
- $accounts = $this->postpaidmodel->getAccountList();
- $data['created'] = $accounts->num_rows();
- //account used
- $account_used = $this->db->query('select*from postpaid_account_list where time_used is not NULL');
- $data['used'] = $account_used->num_rows();
- //bill by
- return $data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement