예제 #1
0
 function init($sA2Billing = null)
 {
     if ($sA2Billing) {
         $this->a2billing =& $sA2Billing;
     } else {
         $this->a2billing =& A2Billing::instance();
     }
     if (isset($GLOBALS['FG_DEBUG'])) {
         $this->FG_DEBUG = $GLOBALS['FG_DEBUG'];
     }
     // Fill a local array with dirty versions of data..
     if (!$this->prefix) {
         $this->_dirty_vars = array_merge($_GET, $_POST);
     } else {
         $tmp_arr = array_merge($_GET, $_POST);
         $tlen = strlen($this->prefix);
         $this->_dirty_vars = array();
         // Find vars matching prefix and strip that!
         foreach ($tmp_arr as $key => $data) {
             if (strncmp($this->prefix, $key, $tlen) == 0) {
                 $this->_dirty_vars[substr($key, $tlen)] = $data;
             }
         }
     }
     // set action, for a start:
     $this->action = $this->getpost_single('action');
     if ($this->action == null) {
         $this->action = $this->action_ask;
     }
 }
예제 #2
0
 /** Returns the static config's instance.
 	   Of course, it will create one when called for the first time.
 	*/
 public static function &instance()
 {
     if (!self::$the_instance) {
         self::$the_instance = new self();
         self::$the_instance->load_config();
     }
     return self::$the_instance;
 }
예제 #3
0
 function insertLog($userID, $logLevel, $actionPerformed, $description, $tableName, $ipAddress, $pageName, $data = '')
 {
     $DB_Handle = A2Billing::DBHandle();
     $pageName = basename($pageName);
     $pageArray = explode('?', $pageName);
     $pageName = array_shift($pageArray);
     $res = $DB_Handle->Execute("INSERT INTO cc_system_log (iduser, loglevel, action, description, tablename, pagename, ipaddress, data) " . " VALUES(?,?,?,?,?,?,?,?);", array($userID, $logLevel, $actionPerformed, $description, $tableName, $pageName, $ipAddress, $data));
     if (!$res) {
         @syslog(LOG_WARNING, "Cannot log: " . $DB_Handle->ErrorMsg());
     }
 }
예제 #4
0
파일: login.php 프로젝트: sayemk/a2billing
function login($user, $pass)
{
    global $FG_DEBUG;
    $DBHandle = A2Billing::DBHandle();
    $user = trim($user);
    $pass = trim($pass);
    if (strlen($user) == 0 || strlen($user) >= 50 || strlen($pass) == 0 || strlen($pass) >= 50) {
        return false;
    }
    $nameclause = "";
    if (DynConf::GetCfg(CUSTOMER_CFG, 'username_login', true)) {
        $nameclause = "username = %1";
    }
    if (DynConf::GetCfg(CUSTOMER_CFG, 'useralias_login', false)) {
        if (!empty($nameclause)) {
            $nameclause .= ' OR ';
        }
        $nameclause .= "useralias = %1";
    }
    if (DynConf::GetCfg(CUSTOMER_CFG, 'email_login', false)) {
        if (!empty($nameclause)) {
            $nameclause .= ' OR ';
        }
        $nameclause .= "email = %1";
    }
    if (($cgrp = DynConf::GetCfg(CUSTOMER_CFG, 'cardgroup_only', null)) != null) {
        $group_clause = ' AND grp = %#3';
    }
    $QUERY = str_dbparams($DBHandle, "SELECT id, username, status, currency, grp, language\n\t\t FROM cc_card WHERE ({$nameclause}) AND userpass = %2 {$group_clause} ;", array($user, $pass, $cgrp));
    $res = $DBHandle->Execute($QUERY);
    if (!$res) {
        $errstr = $DBHandle->ErrorMsg();
        if ($FG_DEBUG) {
            echo $errstr . "<br>\n";
        }
        return 4;
    }
    if ($res->EOF) {
        // no such user!
        if ($FG_DEBUG > 1) {
            echo "Query: {$QUERY} <br>";
        }
        return 1;
    }
    $row = $res->fetchRow();
    if ($row['status'] != 1) {
        return 0 - intval($row['status']);
    }
    //     if( ACTIVATEDBYUSER==1 && $row [0][7] != "t" && $row [0][7] != "1" ) {
    // 		return -2;
    // 	}
    return $row;
}
예제 #5
0
 function init($sA2Billing = null, $stdActions = true)
 {
     if (!$this->rights_checked) {
         error_log("Attempt to use Callshop w/o rights!");
         die;
     }
     if ($sA2Billing) {
         $this->a2billing =& $sA2Billing;
     } else {
         $this->a2billing =& A2Billing::instance();
     }
     if (isset($GLOBALS['FG_DEBUG'])) {
         $this->FG_DEBUG = $GLOBALS['FG_DEBUG'];
     }
 }
예제 #6
0
 public function sendMail($templ, $tomail, $locale, $params)
 {
     global $verbose;
     $dbhandle = A2Billing::DBHandle();
     if ($verbose > 2) {
         echo "Sending {$templ} mail to {$tomail}\n";
     }
     $res = $dbhandle->Execute("SELECT create_mail(?, ?, ?, ?);", array($templ, $tomail, $locale, arr2url($params)));
     if (!$res) {
         echo "Cannot mark mail: ";
         echo $dbhandle->ErrorMsg() . "\n";
     } elseif ($res->EOF) {
         echo "Cannot send mail, no template?\n";
     }
     $this->mail_flag = true;
 }
예제 #7
0
function UseLanguage()
{
    global $language_list;
    global $FG_DEBUG;
    if (isset($_GET['language'])) {
        if ($FG_DEBUG > 0) {
            echo "<!-- lang explicitly set to " . $_GET['language'] . "-->\n";
        }
        $_SESSION["language"] = $_GET['language'];
    } elseif (!isset($_SESSION["language"])) {
        // we have to find a lang to use..
        if (isset($_SESSION["lang_db"])) {
            foreach ($language_list as $lang) {
                if ($lang['abbrev'] == $_SESSION["lang_db"]) {
                    $_SESSION["language"] = $lang['cname'];
                }
            }
            if ($FG_DEBUG > 0) {
                trigger_error("Lang Selected by db: " . $_SESSION["language"], E_USER_NOTICE);
            }
        } else {
            $_SESSION["language"] = 'english';
        }
    }
    define("LANGUAGE", $_SESSION["language"]);
    //include (FSROOT."lib/languages/".LANGUAGE.".php");
    //define ("LANGUAGE_DIR",FSROOT."lib/languages/".LANGUAGE."/");
    $lang_abbr = SetLocalLanguage($_SESSION["language"]);
    if ($FG_DEBUG > 5) {
        trigger_error("lang abbr: {$lang_abbr}", E_USER_NOTICE);
    }
    if (isset($_SESSION['agent_id']) && $_SESSION['cus_rights'] != 0 && isset($_SESSION["lang_db"]) && $_SESSION["lang_db"] != $lang_abbr) {
        $DBconn_tmp = A2Billing::DBHandle();
        $QUERY = "UPDATE cc_agent SET language = " . $DBconn_tmp->Quote($lang_abbr) . ", locale = " . $DBconn_tmp->Quote(getenv("LANG")) . " WHERE id = " . $DBconn_tmp->Quote($_SESSION['agent_id']) . ';';
        $res = $DBconn_tmp->query($QUERY);
        $_SESSION["lang_db"] = $lang_abbr;
        //echo $QUERY;
        if (!$res) {
            trigger_error("Set language to db failed:" . $DBconn_tmp->ErrorMsg(), E_USER_WARNING);
        }
        //DbDisconnect($DBconn_tmp);
    }
}
예제 #8
0
 function ProcessAlarm(AlmInstance $inst)
 {
     $dbhandle = A2Billing::DBHandle();
     global $verbose;
     if ($inst->ar_id) {
         // we cannot handle previous instances
         return;
     }
     $margin = $inst->alm_params['margin'];
     if (!isset($margin)) {
         $margin = 0.0;
     }
     $qry = str_dbparams($dbhandle, "SELECT cc_agent.id, credit, name, locale, email, climit, cc_alarm_run.id AS ar_id,\n\t\t\t\tcc_alarm_run.status AS ar_status\n\t\t\tFROM cc_agent LEFT JOIN cc_alarm_run ON ( cc_alarm_run.dataid = cc_agent.id\n\t\t\t\tAND cc_alarm_run.alid = %#1) \n\t\t\tWHERE (climit + credit ) < %#2 ;", array($inst->id, $margin));
     if ($verbose > 2) {
         echo "Query: " . $qry . "\n";
     }
     $res = $dbhandle->Execute($qry);
     if (!$res) {
         echo $dbhandle->ErrorMsg() . "\n";
     } else {
         if ($res->EOF) {
             if ($verbose > 2) {
                 echo "All agents have credit.\n";
             }
             $inst->Save(1);
             return;
         }
     }
     $neg_agents = array();
     while ($row = $res->fetchRow()) {
         if ($verbose > 2) {
             echo "Agent " . $row['name'] . " is low on credit.\n";
         }
         if (!empty($row['email'])) {
             $this->sendMail('agent-low-credit', $row['email'], $row['locale'], array(credit => $row['credit'], climit => $row['climit']));
         }
         $neg_agents[] = $row['name'] . ": " . $row['credit'] . "/" . $row['climit'];
     }
     $this->sendSysMail('sys-agent-low-credit', $inst, array(low_agents => implode("\n", $neg_agents)));
     $inst->Save();
 }
예제 #9
0
	    case 'did': 			$mode = 'did'; break;
	    case 'callback':			$mode = 'callback'; break;
	    case 'cid-callback':		$mode = 'cid-callback'; break;
	    case 'cid-prompt-callback': 	$mode = 'cid-prompt-callback'; break;
	    case 'all-callback':		$mode = 'all-callback'; break;
	    case 'voucher':			$mode = 'voucher'; break;
	    case 'campaign-callback':		$mode = 'campaign-callback'; break;
	    case 'conference-moderator':	$mode = 'conference-moderator'; break;
	    case 'conference-member':		$mode = 'conference-member'; break;
	    case 'auto-did-callback-cid':	$mode = 'auto'; break;
	    case 'auto':			$mode = 'auto'; break;
	    default:				$mode = 'standard'; break;
	}
} else $mode = 'standard';

$A2B = new A2Billing();
$A2B -> load_conf($agi, NULL, 0, $idconfig, $optconfig);
$A2B -> mode = $mode;
$A2B -> G_startime = $G_startime;


$A2B -> debug( INFO, $agi, __FILE__, __LINE__, "IDCONFIG : $idconfig");
$A2B -> debug( INFO, $agi, __FILE__, __LINE__, "MODE : $mode");


// get the area code for the cid-callback, all-callback and cid-prompt-callback
if ($argc > 3 && strlen($argv[3]) > 0) {
	$caller_areacode = $argv[3];
} else $caller_areacode = "";

if ($argc > 4 && strlen($argv[4]) > 0) {
예제 #10
0
		$ast -> disconnect();
		if ($res !== false) return $res;
		else return -2; // not enough free trunk for make call
	    }
	    else return -3; // not have enough credit to call you back
	}
	else return -1; // no route to call back your phonenumber
    }
    else return -1; // ERROR MESSAGE IS CONFIGURE BY THE callingcard_ivr_authenticate_light
}


$FG_DEBUG = 0;
$verbose_level = 1;

$A2B = new A2Billing();
$A2B->load_conf($agi);

if (!defined('PID'))
    define("PID", $A2B->config["daemon-info"]['pidfile']);

// CHECK IF THE DAEMON IS ALREADY RUNNING
if (ProcessHandler :: isActive())
    die("Already running!");
else
    ProcessHandler :: activate();

write_log(LOGFILE_API_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[#### CALLBACK BEGIN ####]");

if (!$A2B->DbConnect()) {
    echo "[Cannot connect to the database]\n";
예제 #11
0
 public function detailQueryField(&$dbhandle)
 {
     if ($this->fieldexpr) {
         $fld = $this->fieldexpr;
     } else {
         $fld = $this->fieldname;
     }
     return "format_currency2({$fld}, '" . A2Billing::instance()->currency . "') AS " . $this->fieldname;
 }
예제 #12
0
<?php

/** Booths xml code:
    Copyright (C) 2006-2008 P. Christeas <*****@*****.**>
    */
// We must tell the mod_php to send the correct header..
header('Content-type: text/xml');
require "lib/defines.php";
require "lib/module.access.php";
require "lib/common/BoothsXML.inc.php";
require "lib/common/Misc.inc.php";
if (!has_rights(ACX_AGENTS)) {
    header("HTTP/1.0 401 Unauthorized");
    $dom = messageDom(_("Unauthorized: please log in again."), "msg_errror");
    echo $dom->saveXML();
    exit;
}
$aclause = '';
if (!empty($_GET['aid'])) {
    $aclause = str_dbparams(A2Billing::DBHandle(), 'agentid = %#1', array($_GET['aid']));
}
$dom = BoothsDom($_GET['action'], $_GET['actb'], $aclause);
// Let ONLY this line produce any output!
echo $dom->saveXML();
예제 #13
0
// $res= fopen($files[0],'r');
// if (!$res){
// 	echo "Could not open ".$files[0]." .\n";
// 	exit(2);
// }
define('DEBUG_CONF', 1);
$host = A2Billing::instance()->set_def_conf($manager_section, 'host', 'localhost');
$uname = A2Billing::instance()->set_def_conf($manager_section, 'username', 'a2billing');
$password = A2Billing::instance()->set_def_conf($manager_section, 'secret', '');
if ($verbose > 2) {
    echo "Starting manager-eventd.\n";
}
$num_tries = 0;
while ($num_tries < 10) {
    $num_tries++;
    $dbh = A2Billing::DBHandle();
    if (!$dbh) {
        echo "Cannot connect to database, exiting..";
        break;
    }
    $as = new AGI_AsteriskManager();
    if ($verbose < 2) {
        $as->nolog = true;
    } else {
        if ($verbose > 3) {
            $as->debug = true;
        }
    }
    // && CONNECTING  connect($server=NULL, $username=NULL, $secret=NULL)
    $res = $as->connect($host, $uname, $password);
    if (!$res) {
if (!defined('PID')) {
    define("PID", "/var/run/a2billing/a2billing_batch_autodialer_pid.php");
}
// CHECK IF THE CRONT PROCESS IS ALREADY RUNNING
$pH = new ProcessHandler();
if ($pH->isActive()) {
    die;
    // Already running!
} else {
    $pH->activate();
}
$verbose_level = 1;
// time to wait between every send in callback queue
$timing = 6;
$group = 20;
$A2B = new A2Billing();
$A2B->load_conf($agi, NULL, 0, $idconfig);
write_log(LOGFILE_CRONT_BATCH_PROCESS, basename(__FILE__) . ' line:' . __LINE__ . "[#### BATCH BEGIN ####]");
if (!$A2B->DbConnect()) {
    echo "[Cannot connect to the database]\n";
    write_log(LOGFILE_CRONT_BATCH_PROCESS, basename(__FILE__) . ' line:' . __LINE__ . "[Cannot connect to the database]");
    exit;
}
if ($A2B->config["database"]['dbtype'] == "postgres") {
    $UNIX_TIMESTAMP = "date_part('epoch',";
} else {
    $UNIX_TIMESTAMP = "UNIX_TIMESTAMP(";
}
$tab_day = array(1 => 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
$num_day = date('N');
$name_day = $tab_day[$num_day];
예제 #15
0
function BoothsDom($action, $actb, $agent_clause = 'AND false')
{
    global $FG_DEBUG;
    $dbhandle =& A2Billing::instance()->DBHandle();
    // Prepare the XML DOM structure
    $dom = new DOMDocument("1.0", "utf-8");
    // $_SESSION["pr_login"];
    $dom_root = $dom->createElement("root");
    $dom->appendChild($dom_root);
    $dom_message = $dom->createElement("message");
    $dom_root->appendChild($dom_message);
    if (!empty($agent_clause)) {
        $aclause = ' AND ' . $agent_clause;
    } else {
        $aclause = '';
    }
    $booth_states = array();
    $booth_states[0] = array(_("N/A"), _("Not available, no cards configured."));
    $booth_states[1] = array(_("Empty"), _("No customer attached."));
    $booth_states[2] = array(_("Idle"), _("Customer attached, inactive"));
    $booth_states[3] = array(_("Ready"), _("Waiting for calls"));
    $booth_states[4] = array(_("Active"), _("Calls made, charged"));
    $booth_states[5] = array(_("Disabled"), _("Disabled by the agent"));
    $booth_states[6] = array(_("Stopped"), _("Calls made, charged, stopped"));
    // Perform the SQL query
    $message = '';
    if (!empty($action)) {
        /* Here we handle all actions to the booths!
         */
        $get_booth = -1;
        if (!empty($actb)) {
            $get_booth = (int) $actb;
            switch ($action) {
                case 'disable':
                    $message = _("Booth disabled");
                    break;
                case 'stop':
                    //$DBHandle->debug = true;
                    $res = $dbhandle->Execute("UPDATE cc_booth_v SET state = 2 WHERE id = ? {$aclause};", array($get_booth));
                    if ($res) {
                        $message = _("Booth stopped");
                    } else {
                        $message = _("Action failed:");
                        //if ($FG_DEBUG)
                        $message .= $dbhandle->ErrorMsg();
                    }
                    break;
                case 'start':
                    $res = $dbhandle->Execute("UPDATE cc_booth_v SET state = 3 WHERE id = ? {$aclause};", array($get_booth));
                    if ($res && $dbhandle->Affected_Rows()) {
                        $message = _("Booth started");
                    } else {
                        $message = _("Action failed:");
                        $message = $message . $dbhandle->ErrorMsg();
                        $message_class = "msg_error";
                    }
                    break;
                case 'load_def':
                    $res = $dbhandle->Execute("UPDATE cc_booth SET cur_card_id = def_card_id WHERE id = ? {$aclause};", array($get_booth));
                    if ($res && $dbhandle->Affected_Rows()) {
                        $message = _("Booth started");
                    } else {
                        $message = _("Action failed:");
                        $message = $message . $dbhandle->ErrorMsg();
                        $message_class = "msg_error";
                    }
                    break;
                case 'load_reg':
                    $res = $dbhandle->Execute("UPDATE cc_booth SET cur_card_id = ? WHERE id = ? {$aclause};", array($_GET['card'], $get_booth));
                    if ($res && $dbhandle->Affected_Rows()) {
                        $message = _("Booth started");
                    } else {
                        $message = _("Action failed:");
                        $message .= $dbhandle->ErrorMsg();
                        // $message .= "<br>Query: " . $query;
                        $message_class = "msg_error";
                    }
                    break;
                case 'refill':
                    $rf = (double) $_GET['sum'];
                    if ($rf <= 0.0 || $rf > 50.0) {
                        $message = _("Invalid sum for refill");
                        $message_class = "msg_error";
                    } else {
                        $get_booth = (int) $actb;
                        $query = "INSERT INTO cc_agentrefill(agentid, boothid, credit, pay_type) " . "SELECT agentid, cc_booth.id, conv_currency_from(?,  cc_agent.currency), " . "(SELECT id FROM cc_paytypes WHERE preset = 'prepay') " . "FROM cc_booth, cc_agent WHERE cc_booth.id = ? AND cc_agent.id = cc_booth.agentid {$aclause};";
                        $res = $dbhandle->Execute($query, array($rf, $get_booth));
                        if ($res && $dbhandle->Affected_Rows()) {
                            $message = _("Credit added to booth");
                            $message_class = "msg_success";
                        } else {
                            $message = _("Refill failed: do you have enough credit?");
                            if ($FG_DEBUG) {
                                $message .= "<br>" . $dbhandle->ErrorMsg();
                            }
                            if ($FG_DEBUG > 2) {
                                $message .= " <br>QUERY= " . $query;
                            }
                            $message_class = "msg_error";
                        }
                    }
                    break;
                case 'empty':
                    $res = $dbhandle->Execute("UPDATE cc_booth SET cur_card_id = NULL WHERE id = ? {$aclause};", array($get_booth));
                    if ($res && $dbhandle->Affected_Rows()) {
                        $message = _("Booth emptied");
                    } else {
                        $message = _("Action failed:");
                        $message .= $DBHandle->ErrorMsg();
                        //$message .= "<br>Query: " . $query;
                        $message_class = "msg_error";
                    }
                    break;
                default:
                    $message = "Unknown request";
                    $message_class = "msg_error";
            }
        } else {
            switch ($action) {
                default:
                    $message = "Incorrect request";
            }
        }
    }
    $QUERY = "SELECT id, name, state, secs, format_currency(COALESCE(credit,0), currency) AS credit, in_now ";
    $QUERY .= " FROM cc_booth_v WHERE def_card_id IS NOT NULL {$aclause} ORDER BY id;";
    $res = $dbhandle->query($QUERY);
    // 	$dom_message->appendChild($dom->createTextNode($QUERY));
    // 	$dom_message->setAttribute("class","msg_errror");
    if (!$res) {
        $message = _("Database query failed!");
        if ($FG_DEBUG) {
            $message .= $dbhandle->ErrorMsg();
        }
        if ($FG_DEBUG > 2) {
            $message .= '<br>' . htmlspecialchars($QUERY);
        }
        $dom_message->appendChild($dom->createTextNode($message));
        $dom_message->setAttribute("class", "msg_errror");
    } elseif ($res->EOF) {
        $message = _("Database query failed!");
        if ($FG_DEBUG) {
            $message .= "No rows returned!";
        }
        $dom_message->appendChild($dom->createTextNode($message));
        $dom_message->setAttribute("class", "msg_errror");
    } else {
        $dom_message->appendChild($dom->createTextNode($message));
        if (isset($message_class)) {
            $dom_message->setAttribute("class", $message_class);
        }
        // 		if (!isset($currencies_list[strtoupper($customer_info [14])][2]) || !is_numeric($currencies_list[strtoupper($customer_info [14])][2])) $mycur = 1;
        // 		else $mycur = $currencies_list[strtoupper($customer_info [14])][2];
        $buttons = array();
        $buttons['sta'] = false;
        $buttons['stp'] = false;
        $buttons['pay'] = false;
        $buttons['en'] = false;
        $buttons['dis'] = false;
        $buttons['unl'] = false;
        $buttons['ld'] = false;
        $buttons['lr'] = false;
        $buttons['emp'] = false;
        $buttons['ln'] = false;
        $num = $res->numRows();
        for ($i = 0; $i < $num; $i++) {
            $row = $res->fetchRow();
            $dom_booth = $dom->createElement("booth");
            $dom_root->appendChild($dom_booth);
            $dom_booth->setAttribute("id", "booth_" . $row['id']);
            $tmp = $dom->createElement("name");
            $name = $row['name'];
            if (!empty($row['in_now'])) {
                $name .= ' (' . $row['in_now'] . ')';
            }
            $tmp->appendChild($dom->createTextNode($name));
            $dom_booth->appendChild($tmp);
            $tmp = $dom->createElement("status");
            $row_state = $row['state'];
            if ($row_state < 0 || $row_state > 6) {
                $row_state = 0;
            }
            $tmp->appendChild($dom->createTextNode($booth_states[$row_state][0]));
            //$tmp->setAttribute("alt",$booth_states[$row_state][1]);
            $tmp->setAttribute("class", "state" . $row_state);
            $dom_booth->appendChild($tmp);
            $tmp = $dom->createElement("mins");
            $tmp->appendChild($dom->createTextNode(fmt_minutes($row['secs'])));
            $dom_booth->appendChild($tmp);
            $tmp = $dom->createElement("credit");
            $tmp->appendChild($dom->createTextNode($row['credit']));
            $dom_booth->appendChild($tmp);
            // switch off all buttons
            foreach ($buttons as &$bu) {
                $bu = false;
            }
            $td_refill = false;
            // select the ones that will be visible
            switch ($row_state) {
                case 0:
                    break;
                case 1:
                    $buttons["ld"] = true;
                    $buttons["lr"] = true;
                    //$buttons["ln"]=true;
                    //$buttons["dis"]=true;
                    break;
                case 2:
                    $buttons["sta"] = true;
                    $buttons["emp"] = true;
                    //$buttons["lr"]=true;
                    //$buttons["ld"]=true;
                    $td_refill = true;
                    break;
                case 3:
                    $buttons["stp"] = true;
                    $buttons['emp'] = true;
                    $td_refill = true;
                    break;
                case 4:
                    $buttons["pay"] = true;
                    $buttons["stp"] = true;
                    break;
                case 5:
                    $buttons["en"] = true;
                    break;
                case 6:
                    $buttons["pay"] = true;
                    $buttons["sta"] = true;
                    $td_refill = true;
            }
            foreach ($buttons as $key => $bu) {
                $tmp = $dom->createElement("button_" . $key);
                $tmp->setAttribute("display", $bu ? "inline" : "none");
                $dom_booth->appendChild($tmp);
            }
            $tmp = $dom->createElement("refill");
            $tmp->setAttribute("display", $td_refill ? "inline" : "none");
            $dom_booth->appendChild($tmp);
        }
    }
    return $dom;
}
예제 #16
0
if (isset($_SESSION['startTime'])) {
    $timeDiff = time() - $_SESSION['startTime'];
    //destroy session
    if ($timeDiff > 3600) {
        // 60 minutes
        //echo "You've been logged in too long. ($timeDiff)";
        $_SESSION = array();
        session_destroy();
        setcookie('PHPSESSID', '', time() - 3600, '/', '', 0, 0);
    }
} else {
    $_SESSION['startTime'] = time();
}
$G_instance_Query_trace = Query_trace::getInstance();
// A2B INSTANCE
$A2B = new A2Billing();
// The system will not log for Public/index.php and signup/index.php
if (isset($_SERVER['REQUEST_URI'])) {
    $URI = $_SERVER['REQUEST_URI'];
} else {
    $URI = '';
}
// Enable UI Logger
define("ENABLE_LOG", 1);
include FSROOT . "lib/Class.Logger.php";
$log = new Logger();
// LOAD THE CONFIGURATION
if (stripos($URI, "Public/index.php") === FALSE) {
    $res_load_conf = $A2B->load_conf($agi, A2B_CONFIG_DIR . "a2billing.conf", 1);
    if (!$res_load_conf) {
        exit;
예제 #17
0
// require_once (DIR_COMMON."Form/Class.SqlRefField.inc.php");
require_once DIR_COMMON . "Form/Class.TimeField.inc.php";
require_once DIR_COMMON . "Form/Class.ClauseField.inc.php";
require_once DIR_COMMON . "Form/Class.ListSumView.inc.php";
require_once DIR_COMMON . "Form/Class.SumMultiView.inc.php";
require_once DIR_COMMON . "Class.SqlActionElem.inc.php";
require_once DIR_COMMON . "SessionInvoice.inc.php";
$menu_section = 'menu_payments';
//HelpElem::DoHelp(gettext("Agents, callshops. <br>List or manipulate agents, which can deliver cards to customers."));
$sess_row = false;
$dbg_elem = new DbgElem();
$dbhandle = A2Billing::DBHandle();
if ($FG_DEBUG > 0) {
    $PAGE_ELEMS[] =& $dbg_elem;
}
$sessqry = "SELECT is_open, sid, booth, card, is_inuse, credit, " . " ( duration >= interval '1 day') AS has_days, " . str_dbparams($dbhandle, " format_currency(credit,%1) AS credit_fmt ", array(A2Billing::instance()->currency)) . " FROM cc_shopsession_status_v " . " WHERE agentid = " . $_SESSION['agent_id'];
if (isset($_GET['booth'])) {
    $sessqry .= str_dbparams($dbhandle, ' AND booth = %#1 ', array($_GET['booth']));
} elseif (isset($_GET['sid'])) {
    $sessqry .= str_dbparams($dbhandle, ' AND sid = %#1 ', array($_GET['sid']));
}
$sessqry .= ' ORDER BY sid DESC LIMIT 1;';
if ($FG_DEBUG > 2) {
    $dbg_elem->content .= "Query: " . $sessqry . "\n";
}
$sess_res = $dbhandle->Execute($sessqry);
if (!$sess_res) {
    $dbg_elem->content .= $dbhandle->ErrorMsg();
    $PAGE_ELEMS[] = new ErrorElem(_("Cannot locate session!"));
} elseif ($sess_res->EOF) {
    $dbg_elem->content .= "No data found!";
예제 #18
0
 function init($sA2Billing = null, $stdActions = true)
 {
     if (!$this->rights_checked) {
         error_log("Attempt to use FormHandler w/o rights!");
         die;
     }
     if ($sA2Billing) {
         $this->a2billing =& $sA2Billing;
     } else {
         $this->a2billing =& A2Billing::instance();
     }
     if (isset($GLOBALS['FG_DEBUG'])) {
         $this->FG_DEBUG = $GLOBALS['FG_DEBUG'];
     }
     // Fill a local array with dirty versions of data..
     if (!$this->prefix) {
         $this->_dirty_vars = array_merge($_GET, $_POST);
     } else {
         $tmp_arr = array_merge($_GET, $_POST);
         $tlen = strlen($this->prefix);
         $this->_dirty_vars = array();
         // Find vars matching prefix and strip that!
         foreach ($tmp_arr as $key => $data) {
             if (strncmp($this->prefix, $key, $tlen) == 0) {
                 $this->_dirty_vars[substr($key, $tlen)] = $data;
             }
         }
     }
     // set action, for a start:
     $this->action = $this->getpost_single('action');
     if ($this->action == null) {
         $this->action = 'list';
     }
     if ($this->order = $this->getpost_single('order')) {
         $this->addFollowParam('order', $this->order);
     } else {
         $this->order = $this->default_order;
     }
     if ($this->sens = $this->getpost_single('sens')) {
         $this->addFollowParam('sens', $this->sens);
     } else {
         $this->sens = $this->default_sens;
     }
     if ($this->cpage = $this->getpost_single('cpage')) {
         $this->addFollowParam('cpage', $this->cpage);
     }
     if ($this->ndisp = $this->getpost_single('ndisp')) {
         $this->addFollowParam('ndisp', $this->ndisp);
     } else {
         $this->ndisp = 30;
     }
     if ($stdActions) {
         $this->views['idle'] = new IdleView();
         $this->views['list'] = new ListView();
         if (!session_readonly()) {
             $this->views['edit'] = new EditView();
             $this->views['add'] = new AddView();
             $this->views['delete'] = new DeleteView();
             $this->views['object-edit'] = new ObjEditView();
         }
         $this->views['ask-add'] = new AskAddView();
         $this->views['ask-add2'] = new AskAdd2View();
         $this->views['ask-edit2'] = new AskEdit2View();
         $this->views['ask-edit'] = new AskEditView();
         $this->views['ask-del'] = new AskDelView();
         $this->views['details'] = new DetailsView();
         if ($this->FG_DEBUG) {
             $this->views['dump-form'] = new DbgDumpView();
         }
     }
 }
// Create AGI instance
$agi = new AGI();
if ($argc > 1 && is_numeric($argv[1]) && $argv[1] >= 0) {
    $idconfig = $argv[1];
} else {
    $idconfig = 1;
}
if ($dynamic_idconfig = intval($agi->get_variable("IDCONF", true))) {
    $idconfig = $dynamic_idconfig;
}
if ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'saydid') {
    $mode = 'saydid';
} else {
    $mode = 'standard';
}
$A2B = new A2Billing();
$A2B->load_conf($agi, NULL, 0, $idconfig);
$A2B->agiconfig['verbosity_level'] = 4;
$A2B->agiconfig['logging_level'] = 0;
$A2B->debug(INFO, $agi, __FILE__, __LINE__, "START MORNITORING");
define("DB_TYPE", isset($A2B->config["database"]['dbtype']) ? $A2B->config["database"]['dbtype'] : null);
define("SMTP_SERVER", isset($A2B->config['global']['smtp_server']) ? $A2B->config['global']['smtp_server'] : null);
define("SMTP_HOST", isset($A2B->config['global']['smtp_host']) ? $A2B->config['global']['smtp_host'] : null);
define("SMTP_USERNAME", isset($A2B->config['global']['smtp_username']) ? $A2B->config['global']['smtp_username'] : null);
define("SMTP_PASSWORD", isset($A2B->config['global']['smtp_password']) ? $A2B->config['global']['smtp_password'] : null);
// Print header
$A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "AGI Request:\n" . print_r($agi->request, true));
/* GET THE AGI PARAMETER */
$A2B->get_agi_request_parameter($agi);
if (!$A2B->DbConnect()) {
    $agi->stream_file('prepaid-final', '#');
예제 #20
0
* @package    MytoPg
* @author     Steve Dommett <*****@*****.**>
* @copyright  2009 Steve Dommett <*****@*****.**> and A2Billing
* @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
* @version    CVS: $Id:$
* @since      File available since Release 1.4
*
*/
include_once dirname(__FILE__) . "/lib/Class.Table.php";
include dirname(__FILE__) . "/lib/Class.A2Billing.php";
include dirname(__FILE__) . "/lib/Misc.php";
include dirname(__FILE__) . "/lib/interface/constants.php";
$instance_table = new Table();
$idconfig = 1;
$mode = 'standard';
$A2B = new A2Billing();
$A2B->load_conf($agi, NULL, 0, $idconfig);
$A2B->mode = $mode;
$global_instance_table = new Table();
$A2B->set_instance_table($global_instance_table);
$instance_table = new Table();
if (!$A2B->DbConnect()) {
    exit;
}
define("WRITELOG_QUERY", true);
$instance_table = new Table();
$A2B->set_instance_table($instance_table);
$table = new Table();
//$table -> debug_st = 1;
$mytopg = new MytoPg(0);
// debug level
예제 #21
0
 public function Init(array $args)
 {
     $this->args = $args;
     $this->dbhandle = A2Billing::DBHandle();
 }
예제 #22
0
    if (!empty($cli_args['verbose']) || !empty($cli_args['v'])) {
        $verbose = 2;
    } else {
        if (!empty($cli_args['silent']) || !empty($cli_args['q'])) {
            $verbose = 0;
        }
    }
}
// print_r ($cli_args);
// echo "verbose = $verbose - startdate=$startdate\n ";
if (!empty($cli_args['config'])) {
    define('DEFAULT_A2BILLING_CONFIG', $cli_args['config']);
}
// Get the periods
$proc_periods = $cli_args['input'];
$A2B = A2Billing::instance();
$dbhandle = $A2B->DBHandle();
$back_days = 15;
$amount_cdr = 100;
$cdr_per_day = intval($amount_cdr / $back_days);
$cardid = 3;
$destination = 'Italy';
$calledstation = '397821933244';
for ($i = 1; $i <= $back_days; $i++) {
    echo "Day : {$i}...\n";
    for ($j = 1; $j <= $cdr_per_day; $j++) {
        $maxhour = sprintf("%02d", rand(0, 23));
        $minhour = sprintf("%02d", rand(0, 23));
        if ($maxhour < $minhour) {
            $temp = $maxhour;
            $maxhour = $minhour;
	month	 		1-12 (or names, see below)
	day of week	 	0-7 (0 or 7 is Sun, or use names)

	
****************************************************************************/
set_time_limit(0);
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
include_once dirname(__FILE__) . "/../Class.Table.php";
include dirname(__FILE__) . "/../Class.A2Billing.php";
write_log(LOGFILE_CRONT_ARCHIVE_DATA, basename(__FILE__) . ' line:' . __LINE__ . "[#### ARCHIVING DATA BEGIN ####]");
if (!$A2B->DbConnect()) {
    echo "[Cannot connect to the database]\n";
    write_log(LOGFILE_CRONT_ARCHIVE_DATA, basename(__FILE__) . ' line:' . __LINE__ . "[Cannot connect to the database]");
    exit;
}
$A2B = new A2Billing();
$A2B->load_conf($agi, NULL, 0, $idconfig);
$instance_table = new Table();
$from_month = $A2B->config["backup"]['archive_data_x_month'];
if ($A2B->config["database"]['dbtype'] == "postgres") {
    $condition = "CURRENT_TIMESTAMP - interval '{$from_month} months' > starttime";
} else {
    $condition = "DATE_SUB(NOW(),INTERVAL {$from_month} MONTH) > starttime";
}
$value = "SELECT sessionid,uniqueid,username,nasipaddress,starttime,stoptime,sessiontime,calledstation,startdelay,stopdelay,terminatecause,usertariff,calledprovider,calledcountry,calledsub,calledrate,sessionbill,destination,id_tariffgroup,id_tariffplan,id_ratecard,id_trunk,sipiax,src,id_did,buyrate,buycost,id_card_package_offer,real_sessiontime FROM cc_call where {$condition}";
$func_fields = "sessionid,uniqueid,username,nasipaddress,starttime,stoptime,sessiontime,calledstation,startdelay,stopdelay,terminatecause,usertariff,calledprovider,calledcountry,calledsub,calledrate,sessionbill,destination,id_tariffgroup,id_tariffplan,id_ratecard,id_trunk,sipiax,src,id_did,buyrate,buycost,id_card_package_offer,real_sessiontime";
$func_table = 'cc_call_archive';
$id_name = "";
$subquery = true;
$result = $instance_table->Add_table($A2B->DBHandle, $value, $func_fields, $func_table, $id_name, $subquery);
$fun_table = "cc_call";
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
include dirname(__FILE__) . "/lib/admin.defines.php";
include dirname(__FILE__) . "/lib/ProcessHandler.php";
if (!defined('PID')) {
    define("PID", "/var/run/a2billing/currencies_update_yahoo_pid.php");
}
// CHECK IF THE CRONT PROCESS IS ALREADY RUNNING
$prcHandler = new ProcessHandler();
if ($prcHandler->isActive()) {
    die;
    // Already running!
} else {
    $prcHandler->activate();
}
$FG_DEBUG = 0;
$A2B = new A2Billing();
$A2B->load_conf($agi, DEFAULT_A2BILLING_CONFIG, 1);
// DEFINE FOR THE DATABASE CONNECTION
define("BASE_CURRENCY", strtoupper($A2B->config["global"]['base_currency']));
$A2B->load_conf($agi, NULL, 0, $idconfig);
write_log(LOGFILE_CRONT_CURRENCY_UPDATE, basename(__FILE__) . ' line:' . __LINE__ . "[#### START CURRENCY UPDATE ####]");
if (!$A2B->DbConnect()) {
    echo "[Cannot connect to the database]\n";
    write_log(LOGFILE_CRONT_CURRENCY_UPDATE, basename(__FILE__) . ' line:' . __LINE__ . "[Cannot connect to the database]");
    exit;
}
$instance_table = new Table();
$A2B->set_instance_table($instance_table);
$return = currencies_update_yahoo($A2B->DBHandle, $A2B->instance_table);
write_log(LOGFILE_CRONT_CURRENCY_UPDATE, basename(__FILE__) . ' line:' . __LINE__ . $return, 0);
die;
예제 #25
0
$tmp->Form->model[] = new TextField(_("Destination"), 'destination');
$tmp->Form->model[] = new SecondsField(_("Duration"), 'sessiontime');
end($tmp->Form->model)->fieldacr = _("Dur");
//$tmp->Form->model[] = new PKeyFieldTxt(_("ID"),'id');
$tmp->Form->model[] = new MoneyField(_("Bill"), 'sessionbill');
//one non-summed group
$tmp->Form->views['list']->sums[] = array('fns' => array('starttime' => true, 'calledstation' => true, 'destination' => true, 'sessiontime' => true, 'sessionbill' => true), 'order' => 'starttime');
//Per day/destination
$tmp->Form->views['list']->sums[] = array('title' => _("Sum per destination"), 'fns' => array('starttime' => false, 'destination' => true, 'sessiontime' => 'SUM', 'sessionbill' => 'SUM'), 'order' => 'sessiontime', 'sens' => 'DESC');
$tmp->Form->views['list']->sums[] = array('title' => _("Total"), 'fns' => array('calledstation' => 'COUNT', 'sessiontime' => 'SUM', 'sessionbill' => 'SUM'));
$hform = new FormHandler('cc_card');
$hform->checkRights(ACX_INVOICING);
$hform->init(null, false);
$hform->setAction('details');
$hform->views['details'] = new DetailsView();
$hform->model[] = new FreeClauseField(str_dbparams(A2Billing::DBHandle(), 'id = (SELECT cardid FROM cc_invoices WHERE id = %#1)', array($dform->getpost_dirty('id'))));
//$hform->model[] = new PKeyField(_("ID"),'id');
$hform->model[] = new TextField(_("Local number"), 'useralias');
$hform->model[] = new TextFieldN(_("First name"), 'firstname');
$hform->model[] = new TextFieldN(_("Last name"), 'lastname');
$hform->model[] = new TextAreaField(_("Address"), 'address');
$hform->model[] = new TextFieldN(_("City"), 'city');
$hform->model[] = new TextFieldN(_("State"), 'state');
$hform->model[] = new TextFieldN(_("Country"), 'country');
$hform->model[] = new TextFieldN(_("Zipcode"), 'zipcode');
//$hform->model[] = new TextFieldN(_("Phone"),'phone');
$hform->model[] = new TextFieldN(_("Fax"), 'fax');
$PAGE_ELEMS[] =& $hform;
$PAGE_ELEMS[] =& $dform;
if (isset($_GET['printable']) && $_GET['printable']) {
    require "PP_print.inc.php";
예제 #26
0
function Send_Mails($dbg = 1, $dry = false)
{
    $dbhandle = A2Billing::DBHandle();
    if ($dbg > 2) {
        echo "Mailer: start\n";
    }
    $sqlTimeFmt = _("YYYY-MM-DD HH24:MI:SS TZ");
    // TODO: not only select, but lock mails in 'sending' state.
    $qry = "SELECT cc_mailings.id AS id, mtype, fromname, fromemail, subject, \n\t\tmessage, defargs, tomail, args, to_char(tstamp,'{$sqlTimeFmt}') AS mdate\n\t\tFROM cc_templatemail, cc_mailings\n\t\tWHERE cc_mailings.tmail_id = cc_templatemail.id\n\t\tAND (state = 1 OR state = 5);";
    $res = $dbhandle->Execute($qry);
    if (!$res) {
        if ($dbg > 0) {
            echo "Query Failed: " . $dbhandle->ErrorMsg() . "\n";
        }
        return false;
    } elseif ($res->EOF) {
        if ($dbg > 2) {
            echo "No mails need to be sent.\n";
        }
        return true;
    }
    try {
        while ($row = $res->fetchRow()) {
            if ($dbg > 2) {
                echo "Sending " . $row['mtype'] . " to " . $row['tomail'] . "\n";
            }
            if (empty($row['tomail'])) {
                if ($dbg > 2) {
                    echo "No recepient specified!\n";
                }
                continue;
            }
            $mai = new Mailer();
            $mai->setTo('', $row['tomail']);
            $mai->setFrom($row['fromname'], $row['fromemail']);
            // Format parameters
            $defargs = array();
            parse_str($row['defargs'], $defargs);
            $defargs['mdate'] = $row['mdate'];
            $toargs = array();
            parse_str($row['args'], $toargs);
            $args = array_merge($defargs, $toargs);
            if ($dbg > 2) {
                echo "Arguments:";
                print_r($args);
                echo "\n";
            }
            $mai->setSubject(str_alparams($row['subject'], $args), "UTF-8");
            $mai->body = new Mailer_TextBody(str_alparams($row['message'], $args));
            if ($dry) {
                $mai->PrintMail();
                continue;
            }
            try {
                if ($dbg > 2) {
                    echo "Sending mail..";
                }
                $mai->SendMail();
                if ($dbg > 2) {
                    echo " done.\n";
                }
                update_mailing($dbhandle, $row['id'], true, $dbg);
            } catch (Exception $ex) {
                if ($dbg > 2) {
                    echo " failed.\n";
                }
                update_mailing($dbhandle, $row['id'], false, $dbg);
                throw $ex;
            }
        }
    } catch (Exception $ex) {
        if ($dbg > 1) {
            echo "Exception: " . $ex->getMessage();
        }
    }
    return true;
}
include dirname(__FILE__) . "/lib/admin.defines.php";
include dirname(__FILE__) . "/lib/ProcessHandler.php";
if (!defined('PID')) {
    define("PID", "/var/run/a2billing/a2billing_subscription_fee_pid.php");
}
// CHECK IF THE CRONT PROCESS IS ALREADY RUNNING
$pH = new ProcessHandler();
if ($pH->isActive()) {
    die;
    // Already running!
} else {
    $pH->activate();
}
$verbose_level = 1;
$groupcard = 5000;
$A2B = new A2Billing();
$A2B->load_conf($agi, NULL, 0, $idconfig);
write_log(LOGFILE_CRONT_SUBSCRIPTIONFEE, basename(__FILE__) . ' line:' . __LINE__ . "[#### BATCH BEGIN ####]");
if (!$A2B->DbConnect()) {
    echo "[Cannot connect to the database]\n";
    write_log(LOGFILE_CRONT_SUBSCRIPTIONFEE, basename(__FILE__) . ' line:' . __LINE__ . "[Cannot connect to the database]");
    exit;
}
$instance_table = new Table();
/*
    Pay_Status :
        0 : First USE
        1 : Billed
        2 : Paid
        3 : UnPaid
*/
예제 #28
0
 public function SpaXmlProvi()
 {
     $this->dbhandle = A2Billing::DbHandle();
 }
예제 #29
0
파일: login.php 프로젝트: sayemk/a2billing
}
if (!session_is_registered('pr_login') || !session_is_registered('pr_password') || !session_is_registered('cus_rights') || isset($_POST["done"]) && $_POST["done"] == "submit_log") {
    if (!isset($_SERVER['HTTPS'])) {
        header("HTTP/1.0 401 Unauthorized");
        header("Location: index.php?error=1");
        trigger_error("Unauthorized! no ssl!", E_USER_ERROR);
        die;
    }
    if (!isset($unsafe_base)) {
        $unsafe_base = ".";
    }
    if ($FG_DEBUG == 1) {
        echo "<br>0. HERE WE ARE";
    }
    if ($_POST["done"] == "submit_log") {
        $DBHandle = A2Billing::DBHandle();
        if ($FG_DEBUG == 1) {
            echo "<br>1. " . $_POST["pr_login"] . $_POST["pr_password"];
        }
        $_POST["pr_login"] = access_sanitize_data($_POST["pr_login"]);
        $_POST["pr_password"] = access_sanitize_data($_POST["pr_password"]);
        $return = login($_POST["pr_login"], $_POST["pr_password"]);
        if ($FG_DEBUG == 1) {
            print_r($return);
        }
        if ($FG_DEBUG == 1) {
            echo "==>" . $return[1];
        }
        if (!is_array($return)) {
            sleep(2);
            header("HTTP/1.0 401 Unauthorized");
예제 #30
0
} else {
    $mode = 'standard';
}
// get the area code for the cid-callback, all-callback and cid-prompt-callback
if ($argc > 3 && strlen($argv[3]) > 0) {
    $caller_areacode = $argv[3];
}
if ($argc > 4 && strlen($argv[4]) > 0) {
    $groupid = $argv[4];
    $A2B->group_mode = true;
    $A2B->group_id = $groupid;
}
if ($argc > 5 && strlen($argv[5]) > 0) {
    $cid_1st_leg_tariff_id = $argv[5];
}
$A2B = new A2Billing();
$A2B->load_conf($agi, NULL, 0, $idconfig, $optconfig);
$A2B->mode = $mode;
$A2B->G_startime = $G_startime;
$A2B->debug(INFO, $agi, __FILE__, __LINE__, "IDCONFIG : {$idconfig}");
$A2B->debug(INFO, $agi, __FILE__, __LINE__, "MODE : {$mode}");
$A2B->CC_TESTING = isset($A2B->agiconfig['debugshell']) && $A2B->agiconfig['debugshell'];
//$A2B->CC_TESTING = true;
define("DB_TYPE", isset($A2B->config["database"]['dbtype']) ? $A2B->config["database"]['dbtype'] : null);
define("SMTP_SERVER", isset($A2B->config['global']['smtp_server']) ? $A2B->config['global']['smtp_server'] : null);
define("SMTP_HOST", isset($A2B->config['global']['smtp_host']) ? $A2B->config['global']['smtp_host'] : null);
define("SMTP_USERNAME", isset($A2B->config['global']['smtp_username']) ? $A2B->config['global']['smtp_username'] : null);
define("SMTP_PASSWORD", isset($A2B->config['global']['smtp_password']) ? $A2B->config['global']['smtp_password'] : null);
// Print header
$A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "AGI Request:\n" . print_r($agi->request, true));
$A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[INFO : {$agi_version}]");