Advertisement
Guest User

Untitled

a guest
Nov 7th, 2008
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.59 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Class Postpaidmodel
  4.  * handles controller Class Post paid requests dealing with user table in DB
  5.  *
  6.  *
  7.  * @package     EasyHotspot
  8.  * @subpackage  Models
  9.  * @category    Post Paid
  10.  * @author      Rafeequl Rahman Awan
  11.  * @copyright   Copyright (c) 2008, easyhotspot.sf.net
  12.  * @license     http://www.gnu.org/licenses/gpl.html
  13.  * @link        http://easyhotspot.sourceforge.net
  14.  * @version     1.0
  15.  */
  16.  
  17. class Postpaidmodel extends model {
  18.     function Postpaidmodel(){
  19.         parent::Model();
  20.        
  21.         //tables
  22.         $this->_table= 'postpaid_account';
  23.         $this->_table_account_list= 'postpaid_account_list';
  24.         $this->_table_account_bill= 'postpaid_account_bill';
  25.         $this->_table_radcheck = 'radcheck';
  26.         $this->_table_radreply = 'radreply';
  27.         $this->_table_radacct = 'radacct';
  28.         $this->_table_postplan = 'postplan';
  29.        
  30.     }
  31.    
  32.     function getAccount($fields = null, $where = null, $limit = null, $order = null){
  33.        
  34.         ($fields != null) ? $this->db->select($fields) :'';
  35.        
  36.         ($where != null) ? $this->db->where($where) :'';
  37.        
  38.         ($limit != null) ? $this->db->limit($limit['start'],$limit['end']) :'';
  39.  
  40.         ($order != null) ? $this->db->order_by($order['field'],$order['dir']) : $this->db->order_by('id','desc');
  41.        
  42.         return $this->db->get($this->_table);
  43.     }
  44.    
  45.     function getAccountList($fields = null, $where = null, $limit = null, $order = null){
  46.        
  47.         ($fields != null) ? $this->db->select($fields) :'';
  48.        
  49.         ($where != null) ? $this->db->where($where) :'';
  50.        
  51.         ($limit != null) ? $this->db->limit($limit['start'],$limit['end']) :'';
  52.        
  53.         ($order != null) ? $this->db->order_by($order['field'],$order['dir']) : $this->db->order_by('id','desc');
  54.        
  55.         return $this->db->get($this->_table_account_list);
  56.    
  57.     }
  58.    
  59.     function getAccountUsage($fields = null, $where = null, $limit = null){
  60.        
  61.         ($fields != null) ? $this->db->select($fields) :'';
  62.        
  63.         ($where != null) ? $this->db->where($where) :'';
  64.        
  65.         ($limit != null) ? $this->db->limit($limit['start'],$limit['end']) :'';
  66.        
  67.         return $this->db->get($this->_table_account_bill);
  68.    
  69.     }
  70.    
  71.     function addAccount(){
  72.        
  73.         //data for radcheck table
  74.         $radcheck_value = array();
  75.         $radcheck_value['username'] = $_POST['username'];
  76.         $radcheck_value['value'] = $_POST['password'];
  77.         $radcheck_value['attribute'] = 'User-Password';
  78.         $radcheck_value['op'] = ':=';
  79.        
  80.         $simultaneous['username'] = $_POST['username'];
  81.         $simultaneous['attribute'] = 'Simultaneous-Use';
  82.         $simultaneous['op'] = ':=';
  83.         $simultaneous['value'] = '1';
  84.                
  85.         $this->db->trans_start();
  86.         $this->db->insert($this->_table,$_POST); //insert into postpaid account table
  87.         $this->db->insert($this->_table_radcheck,$radcheck_value);      //insert into radcheck account table
  88.         $this->db->insert($this->_table_radcheck,$simultaneous);
  89.         $this->db->trans_complete();
  90.        
  91.     }
  92.    
  93.     function deleteAccount(){
  94.         $this->db->trans_start();
  95.            
  96.         $this->db->where('username',$this->uri->segment(3));
  97.         $this->db->delete($this->_table); //delete from postpaid_account table
  98.        
  99.         $this->db->where('username',$this->uri->segment(3));
  100.         $this->db->delete($this->_table_radcheck);      //delete from radcheck account table
  101.        
  102.         $this->db->where('username',$this->uri->segment(3));
  103.         $this->db->delete($this->_table_radacct); //delete from radacct table
  104.            
  105.         $this->db->trans_complete();
  106.     }
  107.    
  108.     function editAccount(){
  109.         $tbl_postpaid_account = array ('bill_by' => $_POST['bill_by'], //fields on postpaid_account table
  110.                         'password' => $_POST['password'] );
  111.                        
  112.         $tbl_radcheck = array('value' => $_POST['password']); //field on radcheck table
  113.                        
  114.         $this->db->trans_start();
  115.            
  116.         $this->db->where('username',$_POST['username']);
  117.         $this->db->update($this->_table,$tbl_postpaid_account);
  118.        
  119.         $this->db->where('username',$_POST['username']);
  120.         $this->db->update($this->_table_radcheck,$tbl_radcheck);
  121.        
  122.         $this->db->trans_complete();
  123.     }
  124.    
  125.     function searchAccount($limit = null){
  126.        
  127.         //search by username or realname
  128.         $this->db->like('username',$this->db_session->userdata('search'));
  129.         $this->db->orlike('realname',$this->db_session->userdata('search'));
  130.        
  131.         //limit
  132.         ($limit !=null ) ? $this->db->limit($limit['start'],$limit['end']) :'';
  133.        
  134.         return $this->db->get($this->_table_account_list);
  135.        
  136.     }
  137.    
  138.     function getAccountStatistic(){
  139.         //account created
  140.         $accounts = $this->postpaidmodel->getAccountList();
  141.         $data['created'] = $accounts->num_rows();
  142.        
  143.         //account used
  144.         $account_used = $this->db->query('select*from postpaid_account_list where time_used is not NULL');
  145.         $data['used'] = $account_used->num_rows();
  146.        
  147.         //bill by
  148.        
  149.         return $data;
  150.     }
  151.    
  152.  
  153.        
  154.    
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement