class.a2billing.php

来自「asterisk用 的voip记费软件」· PHP 代码 · 共 1,467 行 · 第 1/5 页

PHP
1,467
字号
<?php/*************************************************************************** * * Class.A2Billing.php : PHP A2Billing Functions for A2Billing * Written for PHP 4.x & PHP 5.X versions. * * A2Billing -- Asterisk billing solution. * Copyright (C) 2004, 2007 Belaid Arezqui <areski _atl_ gmail com> * * See http://www.asterisk2billing.org for more information about * the A2Billing project.  * Please submit bug reports, patches, etc to <areski _atl_ gmail com> * * This software is released under the terms of the GNU Lesser General Public License v2.1 * A copy of which is available from http://www.gnu.org/copyleft/lesser.html * ****************************************************************************/define('AST_CONFIG_DIR', '/etc/asterisk/'); define('DEFAULT_A2BILLING_CONFIG', AST_CONFIG_DIR . '/a2billing.conf');// DEFINE STATUS FOR DEBUGdefine ('VERBOSE',			1);define ('WRITELOG',			2);			// 1 << 1class A2Billing {			/**    * Config variables    *    * @var array    * @access public    */	var $config;		/**    * Config AGI variables	* Create for coding readability facilities    *    * @var array    * @access public    */	var $agiconfig;		/**    * IDConfig variables    *    * @var interger    * @access public    */	var $idconfig=1;			/**    * cardnumber & CallerID variables    *    * @var string    * @access public    */	var $cardnumber;	var $CallerID;			/**    * Buffer variables    *    * @var string    * @access public    */	var $BUFFER;			/**    * DBHandle variables    *    * @var object    * @access public    */		var $DBHandle;			/**    * instance_table variables    *    * @var object    * @access public    */		var $instance_table;		/**    * store the file name to store the logs    *    * @var string    * @access public    */	var $log_file = '';			/**    * request AGI variables    *    * @var string    * @access public    */		var $channel;	var $uniqueid;	var $accountcode;	var $dnid;				// from apply_rules, if a prefix is removed we keep it to track exactly what the user introduce		var $countrycode;	var $subcode;	var $myprefix;	var $ipaddress;	var $rate;	var $destination;	var $sip_iax_buddy;		var $credit;	var $tariff;	var $active;	var $hostname='';	var $currency='usd';            	var $timeout;	var $newdestination;	var $tech;	var $prefix;	var $username;		var $typepaid = 0; 	var $removeinterprefix = 1; 	var $redial;	var $nbused = 0;		var $enableexpire;	var $expirationdate;	var $expiredays;	var $firstusedate;	var $creationdate;			var $languageselected;			var $cardholder_lastname;	var $cardholder_firstname;	var $cardholder_email;	var $cardholder_uipass;	var $id_campaign;	var $id_card;	var $useralias;		// Flag to know that we ask for an othercardnumber when for instance we doesnt have enough credit to make a call	var $ask_other_cardnumber=0;		var $ivr_voucher;	var $vouchernumber;	var $add_credit;		var $cardnumber_range;		// Define if we have changed the status of the card	var $set_inuse = 0;		/**	* CC_TESTING variables 	* for developer purpose, will replace some get_data inputs in order to test the application from shell	*	* @var interger	* @access public	*/		var $CC_TESTING;			/* CONSTRUCTOR */	function A2Billing() {     				//$this -> DBHandle = $DBHandle;			}			/* Init */		function Reinit () {  		$this -> countrycode='';		$this -> subcode='';		$this -> myprefix='';		$this -> ipaddress='';		$this -> rate='';		$this -> destination='';		$this -> sip_iax_buddy='';	}			/* 	 * Debug	 *	 * usage : $A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, $buffer_debug);	 */	function debug( $debug, $agi, $file, $line, $buffer_debug){				$file = basename($file);				// RUN VERBOSE ON CLI		if ($debug & VERBOSE){			if ($this->agiconfig['debug']>=1)   $agi->verbose('file:'.$file.' - line:'.$line.' - '.$buffer_debug);		}				// RIGHT DEBUG IN LOG FILE		if ($debug & WRITELOG){			$this -> write_log($buffer_debug, 1, "[file:$file - line:$line]:");		}	}		/* 	 * Write log into file 	 */	function write_log($output, $tobuffer = 1, $line_file_info = ''){		//$tobuffer = 0;				if (strlen($this->log_file) > 1){						$string_log = "[".date("d/m/Y H:i:s")."]:".$line_file_info."[CallerID:".$this->CallerID."]:[CN:".$this->cardnumber."]:[$output]\n";			if ($this->CC_TESTING) echo $string_log;						$this -> BUFFER .= $string_log;							if (!$tobuffer || $this->CC_TESTING){				error_log ($this -> BUFFER, 3, $this->log_file);				$this-> BUFFER = '';			}		}	}		/* set the DB handler */ 	function set_dbhandler ($DBHandle){		$this->DBHandle	= $DBHandle;	}		function set_instance_table ($instance_table){		$this->instance_table	= $instance_table;	}	function load_conf( &$agi, $config=NULL, $webui=0, $idconfig=1, $optconfig=array())    {	  		$this -> idconfig = $idconfig;		// load config		if(!is_null($config) && file_exists($config))			$this->config = parse_ini_file($config, true);		elseif(file_exists(DEFAULT_A2BILLING_CONFIG)){			$this->config = parse_ini_file(DEFAULT_A2BILLING_CONFIG, true);				}	  	  		// If optconfig is specified, stuff vals and vars into 'a2billing' config array.		foreach($optconfig as $var=>$val)			$this->config["agi-conf$idconfig"][$var] = $val;				// add default values to config for uninitialized values        				//Card Number Length Code		$card_length_range = isset($this->config['global']['interval_len_cardnumber'])?$this->config['global']['interval_len_cardnumber']:null;		$this -> cardnumber_range = $this -> splitable_data ($card_length_range);				if(is_array($this -> cardnumber_range) && ($this -> cardnumber_range[0] >= 4))		{			define ("CARDNUMBER_LENGTH_MIN", $this -> cardnumber_range[0]);			define ("CARDNUMBER_LENGTH_MAX", $this -> cardnumber_range[count($this -> cardnumber_range)-1]);			define ("LEN_CARDNUMBER", CARDNUMBER_LENGTH_MIN);		}		else		{			echo gettext("Invalid card number lenght defined in configuration.");			exit;		}		if(!isset($this->config['global']['len_aliasnumber']))		$this->config['global']['len_aliasnumber'] = 15;		if(!isset($this->config['global']['len_voucher']))			$this->config['global']['len_voucher'] = 15;		if(!isset($this->config['global']['base_currency'])) 		$this->config['global']['base_currency'] = 'usd';		if(!isset($this->config['global']['didbilling_daytopay'])) 	$this->config['global']['didbilling_daytopay'] = 5;		if(!isset($this->config['global']['admin_email'])) 			$this->config['global']['admin_email'] = 'root@localhost';				// conf for the database connection		if(!isset($this->config['database']['hostname']))	$this->config['database']['hostname'] = 'localhost';		if(!isset($this->config['database']['port']))		$this->config['database']['port'] = '5432';		if(!isset($this->config['database']['user']))		$this->config['database']['user'] = 'postgres';		if(!isset($this->config['database']['password']))	$this->config['database']['password'] = '';

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?