Advertisement
Guest User

Untitled

a guest
Nov 7th, 2008
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.85 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Class Billingplanmodel
  4.  * handles controller Class Billing Plan requests dealing with user table in DB
  5.  *
  6.  *
  7.  * @package     EasyHotspot
  8.  * @subpackage  Models
  9.  * @category    Billing Plan
  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.  
  18. class Billingplanmodel extends model {
  19.    
  20.     function Billingplanmodel(){
  21.         parent::Model();
  22.        
  23.         //table name
  24.         $this->_table='billingplan';
  25.         $this->_table_radgroupreply = 'radgroupreply';
  26.         $this->_table_radgroupcheck = 'radgroupcheck';
  27.     }
  28.    
  29.      /**
  30.      * Retrieves all records and all fields (or those passed in the $fields string)
  31.      * from the table billing_plan. It is possible (optional) to pass the wonted fields,
  32.      * the query limit, and the query WHERE clause.
  33.      *
  34.      * @param string of fields wanted $fields
  35.      * @param array $limit
  36.      * @param string $where
  37.      * @return query string
  38.      */
  39.     function getBillingPlan($fields = null, $limit = null, $where = null){
  40.        
  41.         ($fields != null) ? $this->db->select($fields) :'';
  42.        
  43.         ($where != null) ? $this->db->where($where) :'';
  44.        
  45.         ($limit !=null ) ? $this->db->limit($limit['start'],$limit['end']) :'';
  46.        
  47.         //return the query string
  48.         return $this->db->get($this->_table);
  49.        
  50.     }
  51.    
  52.     /**
  53.      * Add new billing plan
  54.      *
  55.      */
  56.     function addBillingPlan(){
  57.         //insert into Billing Plan table
  58.         $this->db->insert($this->_table,$_POST);
  59.        
  60.         //properties
  61.         $data['groupname'] = $_POST['name'];
  62.        
  63.         //insert into radgroupreply table
  64.         //max download speed
  65.         if($_POST['bw_download'] != '') {
  66.             $data['attribute']='WISPr-Bandwidth-Max-Down';
  67.             $data['op']=':=';
  68.             $data['value'] = $_POST['bw_download']*1000;
  69.            
  70.             $this->db->insert($this->_table_radgroupreply,$data);
  71.         }
  72.        
  73.         //max upload speed
  74.         if($_POST['bw_upload'] != '') {
  75.             $data['attribute']='WISPr-Bandwidth-Max-Up';
  76.             $data['op']=':=';
  77.             $data['value'] = $_POST['bw_upload']*1000;
  78.            
  79.             $this->db->insert($this->_table_radgroupreply,$data);
  80.         }
  81.        
  82.         //maximum time
  83.         if($_POST['type']=='time'){
  84.             $data['attribute']='Max-All-Session';
  85.             $data['op']=':=';
  86.             $data['value'] = $_POST['amount']*60;
  87.            
  88.             $this->db->insert($this->_table_radgroupcheck,$data);
  89.         }
  90.        
  91.         //maximum packets being transfered
  92.         if($_POST['type']=='packet'){
  93.             $data['attribute']='Max-All-MB';
  94.             $data['op']=':=';
  95.             $data['value'] = $_POST['amount']*1024*1024;
  96.            
  97.             $this->db->insert($this->_table_radgroupcheck,$data);
  98.         }
  99.        
  100.         //Idle-Timeout
  101.         if($_POST['IdleTimeout']){
  102.             $data['attribute'] = 'Idle-Timeout';
  103.             $data['op'] = ':=';
  104.             $data['value'] = $_POST['IdleTimeout']*60;
  105.            
  106.             $this->db->insert($this->_table_radgroupreply,$data);
  107.         }
  108.        
  109.         //Simultaneous-Use
  110.        
  111.             $data['attribute'] = 'Simultaneous-Use';
  112.             $data['op'] = ':=';
  113.             $data['value'] = '1';
  114.             $this->db->insert($this->_table_radgroupcheck,$data);
  115.        
  116.     }
  117.    
  118.     /**
  119.      * Delete billing plan, defined by id on $this->uri->segment()
  120.      *
  121.      */
  122.     function deleteBillingPlan(){
  123.        
  124.         $this->db->query('delete billingplan,usergroup,voucher,radcheck,radgroupreply,radgroupcheck from billingplan left join usergroup on billingplan.name=usergroup.groupname left join voucher on billingplan.name = voucher.billingplan left join radcheck on voucher.username = radcheck.username left join radgroupreply on radgroupreply.groupname = billingplan.name left join radgroupcheck on radgroupcheck.groupname = billingplan.name where billingplan.name =\''.$this->uri->segment(5).'\'');      
  125.  
  126.     }
  127.    
  128.     function getBillingPlanStat(){
  129.    
  130.         return $this->db->query('select b.name as billingplan, if(count(u.groupname) is not null, count(u.groupname),0)as qty from billingplan b left join usergroup u on b.name=u.groupname group by b.name;');
  131.     }
  132. }
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement