Пример #1
0
function getSpeedDial($card, &$dialnum)
{
    global $a2b;
    global $agi;
    // SPEED DIAL HANDLER
    if (($sp_prefix = getAGIconfig('speeddial_prefix', NULL)) != NULL) {
        if (strncmp($dialnum, $sp_prefix, strlen($sp_prefix)) == 0) {
            // translate the speed dial.
            $QRY = str_dbparams($a2b->DBHandle(), "SELECT phone, name FROM speeddials WHERE card_id = %#1 AND speeddial = %2", array($card['id'], substr($dialnum, strlen($sp_prefix))));
            $agi->conlog($QRY, 3);
            $res = $a2b->DBHandle()->Execute($QRY);
            // If the rate engine has anything to Notice/Warn, display that..
            if ($notice = $a2b->DBHandle()->NoticeMsg()) {
                $agi->verbose('DB:' . $notice, 2);
            }
            if (!$res) {
                $agi->verbose('Speed Dial: query error!', 2);
                $agi->conlog($a2b->DBHandle()->ErrorMsg(), 2);
                if (getAGIconfig('say_errors', true)) {
                    $agi->stream_file('allison2', '#');
                }
                break;
            } elseif ($res->EOF) {
                $agi->verbose('Speed Dial: no result.', 2);
            }
            $arr_speeddial = $res->fetchRow();
            $agi->conlog('Speed Dial : found ' . $arr_speeddial['phone'], 4);
            $dialnum = $arr_speeddial['phone'];
        }
    }
}
Пример #2
0
 /** Just saves the params and timestamp as an alarm_run row */
 public function Save($status = null)
 {
     $dbhandle = A2Billing::DBHandle();
     global $verbose;
     if ($status) {
         $this->ar_status = $status;
     }
     if (empty($this->ar_status)) {
         $this->ar_status = 1;
     }
     if ($this->ar_id) {
         // update a previous alarm_run record
         $qry = sql_dbparams($dbhandle, "UPDATE cc_alarm_run\n\t\t\t\tSET tmodify = now(), status = %#2, params = %!3\n\t\t\t\tWHERE id = %1;", array($this->ar_id, $this->ar_status, arr2url($this->ar_params)));
     } else {
         //no run record, insert
         $qry = str_dbparams($dbhandle, "INSERT INTO cc_alarm_run(alid,status,params)\n\t\t\t\tVALUES(%#1,%#2,%!3);", array($this->id, $this->ar_status, arr2url($this->ar_params)));
     }
     $res = $dbhandle->Execute($qry);
     if (!$res) {
         echo "Cannot mark alarm-run: ";
         echo $dbhandle->ErrorMsg() . "\n";
     } elseif ($dbhandle->Affected_Rows() < 1) {
         echo "Cannot update alarm run.\n";
     }
     if ($verbose > 1) {
         $str = $dbhandle->NoticeMsg();
         if ($str) {
             echo $str . "\n";
         }
     }
 }
Пример #3
0
 /** Inserts some provisioning group 
 	   \return the id of the inserted record
 	  */
 protected function getGroup2($confname, $name, $subname = NULL, $opts)
 {
     $qry = str_dbparams($this->dbhandle, 'INSERT INTO provision_group(categ,model,name, sub_name, options) ' . 'VALUES(%1,%2,%3,%!4,%#5) RETURNING id; ', array('spa-conf', $confname, $name, $subname, $opts));
     $res = $this->dbhandle->Execute($qry);
     if (!$res) {
         $this->out(LOG_ERR, $this->dbhandle->ErrorMsg());
         throw new Exception('Cannot insert into database.');
     } elseif ($res->EOF) {
         $this->out(LOG_ERR, "No rows inserted!");
     }
     $row = $res->fetchRow();
     return $row['id'];
 }
 public function buildSearchClause(&$dbhandle, &$form, $search_exprs)
 {
     $val = $this->buildValue($form->getpost_dirty($this->fieldname), $form);
     $mo_val = $form->getpost_dirty('use_' . $this->fieldname);
     if (empty($mo_val)) {
         $mo_val = 'no';
     }
     if (empty($this->fieldexpr)) {
         $fldex = $this->fieldname;
     } else {
         $fldex = $this->fieldexpr;
     }
     if ($this->case_sensitive) {
         $like = 'LIKE';
     } else {
         $like = 'ILIKE';
     }
     if ($val == null) {
         switch ($mo_val) {
             case 'no':
             default:
                 return null;
             case 'eq':
                 return "{$fldex} IS NULL";
             case 'st':
             case 'en':
                 return null;
         }
     } else {
         switch ($mo_val) {
             case 'eq':
                 if ($this->case_sensitive) {
                     return str_dbparams($dbhandle, "{$fldex} = %1", array($val));
                 } else {
                     return str_dbparams($dbhandle, "lower({$fldex}) = lower(%1)", array($val));
                 }
             case 'st':
                 return str_dbparams($dbhandle, "{$fldex} {$like} %1 || '%%'", array($val));
             case 'en':
                 return str_dbparams($dbhandle, "{$fldex} {$like} '%%' || %1", array($val));
             case 'ct':
                 return str_dbparams($dbhandle, "{$fldex} {$like} '%%' || %1 || '%%'", array($val));
             case 'no':
             default:
                 return null;
         }
     }
 }
Пример #5
0
function update_mailing(&$dbhandle, $id, $is_sent, $dbg)
{
    if ($is_sent) {
        $state = 3;
    } else {
        $state = 4;
    }
    $qry = str_dbparams($dbhandle, "UPDATE cc_mailings SET state = %#2 WHERE id = %1 ;", array($id, $state));
    $res = $dbhandle->Execute($qry);
    if ($dbg > 2) {
        echo "Update query: " . $qry . "\n";
    }
    if (!$res) {
        if ($dbg > 0) {
            echo "Query Failed: " . $dbhandle->ErrorMsg() . "\n";
        }
        return false;
    }
    return true;
}
Пример #6
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();
 }
Пример #7
0
 public function genContent(&$outstream)
 {
     fwrite($outstream, "; Generated content\n\n");
     while ($crd = $this->itemres->fetchRow()) {
         foreach ($this->grprows as $grp) {
             $line = '';
             $qry = str_dbparams($this->dbhandle, "SELECT * FROM provisions " . "WHERE grp_id = %#1 ORDER BY metric;", array($grp['id']));
             $this->out(LOG_DEBUG, "Query: {$qry}");
             $pres = $this->dbhandle->Execute($qry);
             if (!$pres) {
                 $this->out(LOG_ERR, $this->dbhandle->ErrorMsg());
                 throw new Exception("Cannot locate provision");
             } elseif ($itemres->EOF) {
                 $this->out(LOG_WARNING, 'No rows for cc_card');
                 continue;
             }
             // Write a header like [name] ..
             $line = '[';
             if (!empty($grp['sub_name'])) {
                 $line .= str_alparams($grp['sub_name'], $crd);
             } else {
                 $line .= $grp['name'];
             }
             $line .= "]\n";
             fwrite($outstream, $line);
             while ($row = $pres->fetchRow()) {
                 $line = '';
                 if (!empty($row['sub_name'])) {
                     $line = str_alparams($row['sub_name'], $crd);
                 } else {
                     $line = $row['name'];
                 }
                 $line .= '=';
                 $line .= str_alparams($row['valuef'], $crd);
                 $line .= "\n";
                 fwrite($outstream, $line);
             }
             fwrite($outstream, "\n");
         }
     }
 }
Пример #8
0
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;
}
Пример #9
0
#  Set the parameters: SQL Query, hostname, databasename, dbuser and password                                       #
#####################################################################################################################
$dumpfile = new iam_csvdump();
#  Call the CSV Dumping function and THAT'S IT!!!!  A file named dump.csv is sent to the user for download          #
#####################################################################################################################
if (strlen($id_tp) < 1) {
    echo gettext("ERROR CSV EXPORT");
} else {
    $log = new Logger();
    $DBHandle = DbConnect();
    $export_fields = array('dialprefix', 'destination', 'rateinitial');
    $sql_str = "ABORT;";
    switch ($export_style) {
        case 'peer-full-csv':
            array_push($export_fields, 'buyrate', 'buyrateinitblock', 'buyrateincrement', 'rateinitial', 'initblock', 'billingblock', 'connectcharge', 'disconnectcharge', 'stepchargea', 'chargea', 'timechargea', 'billingblocka', 'stepchargeb', 'chargeb', 'timechargeb', 'billingblockb', 'stepchargec', 'chargec', 'timechargec', 'billingblockc');
            $sql_str = str_dbparams($DBHandle, 'SELECT ' . implode(', ', $export_fields) . ' FROM cc_ratecard WHERE idtariffplan = %1;', array($id_tp));
            $log_str = "Ratecard #%0 exported in csv format, all fields in peer format";
            $myfileName = "Ratecard_" . $tp_id;
            $prolog = "# Export of tp #{$id_tp}\n";
            $prolog .= "#fields: " . implode(';', $export_fields) . "\n";
            break;
        default:
            echo "Wrong export style:" . $export_style . "\n<br>\n";
            die;
    }
    $myfileName .= date("Y-m-d");
    $log->insertLog($_SESSION["admin_id"], 2, "FILE EXPORTED", str_params($log_str, array($id_tp, $export_style)), '', $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI'], '');
    $dumpfile->sep = ';';
    $dumpfile->prolog = $prolog;
    $dumpfile->dump($sql_str, $myfileName, "csv", DBNAME, USER, PASS, HOST, DB_TYPE);
    DBDisconnect($DBHandle);
Пример #10
0
function gen_all_agents($dbh, $do_sip, $do_iax, &$err_msg)
{
    global $FG_DEBUG;
    global $A2B;
    $ita = new Table('cc_agent', 'id, login,name');
    if ($FG_DEBUG > 1) {
        $ita->debug_st = 1;
    }
    $list_agent = $ita->Get_list($dbh, 'active = true', null, null, null, null);
    if (!is_array($list_agent) || count($list_agent) == 0) {
        $err_msg .= str_params(_("<p style='color: red'>No active agents found!<br>%1</p>"), array($dbh->ErrorMsg()), 1);
        return false;
    }
    // These are put by default on a non-existing directory!
    // This is intentional, since those files contain SIP/IAX passwords.
    // they shouldn't be carelessly left in a world-readable dir.
    if (isset($A2B->config['webui']['buddy_sip_agent'])) {
        $buddy_sip = $A2B->config['webui']['buddy_sip_agent'];
    } else {
        $buddy_sip = "/tmp/a2billing/additional_sip.%1.conf";
    }
    if (isset($A2B->config['webui']['buddy_iax_agent'])) {
        $buddy_iax = $A2B->config['webui']['buddy_iax_agent'];
    } else {
        $buddy_iax = "/tmp/a2billing/additional_iax.%1.conf";
    }
    $succ = 0;
    foreach ($list_agent as $ag) {
        $hdr_lines = "; Configuration for " . $ag[2] . "\n";
        if ($do_sip) {
            $fname = str_params($buddy_sip, $ag);
            $qclause = str_dbparams($dbh, "name IN (SELECT callerid FROM cc_booth WHERE agentid = %1)", array($ag[0]));
            if (gen_userdata($dbh, $fname, 'cc_sip_buddies', $qclause, $err_msg, $hdr_lines)) {
                $succ++;
            }
        }
        if ($do_iax) {
            $fname = str_params($buddy_iax, $ag);
            $qclause = str_dbparams($dbh, "name IN (SELECT callerid FROM cc_booth WHERE agentid = %1)", array($ag[0]));
            if (gen_userdata($dbh, $fname, 'cc_iax_buddies', $qclause, $err_msg, $hdr_lines)) {
                $succ++;
            }
        }
    }
    $co = 0;
    if ($do_sip) {
        $co += count($list_agent);
    }
    if ($do_iax) {
        $co += count($list_agent);
    }
    $err_msg .= str_params(_("<p style='color: blue'>Agent config files: %#1 of %#2 files created.</p>"), array($succ, $co), 1);
    return true;
}
Пример #11
0
 function db_fetchone($qry, $parms = NULL)
 {
     if ($parms) {
         $res = $this->dbh->Execute(str_dbparams($this->dbh, $qry, $parms));
     } else {
         $res = $this->dbh->Execute($qry);
     }
     if (!$res) {
         $this->out(LOG_ERR, "Qry failed: {$qry} (" . implode(', ', $parms) . ')');
         $this->out(LOG_ERR, $this->dbh->ErrorMsg());
         throw new Exception("Query failed: {$qry}");
     }
     $row = $res->FetchRow();
     if (!$row) {
         throw new NoDataException("Query: \"{$qry}\": No results");
     }
     return $row;
 }
Пример #12
0
function formatDialstring_peer($dialn, &$route, &$card, $do_param = true)
{
    global $a2b;
    global $agi;
    $dbhandle = $a2b->DBHandle();
    if ($route['stripdigits'] > 0) {
        $dialnum = substr($route['dialstring'], $route['stripdigits']);
    } else {
        $dialnum = $route['dialstring'];
    }
    $bind_str = '%dialtech/%dialname';
    switch ($route['trunkfmt']) {
        case 4:
            $qry = str_dbparams($dbhandle, 'SELECT dialtech, dialname FROM cc_dialpeer_local_v ' . 'WHERE useralias = %1', array($dialnum));
            $bind_str = '%dialtech/%dialname';
            if (strlen($route['providertech'])) {
                $qry .= str_dbparams($dbhandle, ' AND dialtech = %1', array($route['providertech']));
            }
            // If the trunk specifies an "ip", aliases among the corresponding numplan will be queried
            // else, the numplan *must* be the same with that of the card.
            // It would be wrong not to specify a numplan, since aliases accross them are not unique!
            if (strlen($route['providerip'])) {
                $qry .= str_dbparams($dbhandle, ' AND numplan_name = %1', array($route['providerip']));
            } else {
                $qry .= str_dbparams($dbhandle, ' AND numplan = %#1', array($card['numplan']));
            }
            break;
        case 6:
            // hardcode search into same numplan!
            $qry = str_dbparams($dbhandle, 'SELECT * FROM cc_dialpeer_remote_v ' . 'WHERE useralias = %1 AND numplan = %#2', array($dialnum, $card['numplan']));
            $bind_str = $route['providertech'] . '/' . $route['providerip'];
            break;
        case 7:
        case 15:
            $dnum = explode('-', $dialnum);
            if ($dnum[0] == 'L') {
                $dnum[0] = $card['numplan'];
            }
            $qry = str_dbparams($dbhandle, 'SELECT dialtech, dialname FROM cc_dialpeer_local_v ' . 'WHERE useralias = %2 AND numplan = %#1 ', $dnum);
            if (strlen($route['providertech'])) {
                $qry .= str_dbparams($dbhandle, ' AND dialtech = %1', array($route['providertech']));
            }
            $bind_str = '%dialtech/%dialname';
            $agi->conlog("Query: {$qry}", 3);
            break;
        case 8:
            $dnum = explode('-', $dialnum);
            if ($dnum[0] == 'L') {
                $dnum[0] = $card['numplan'];
            }
            $qry = str_dbparams($dbhandle, 'SELECT * FROM cc_dialpeer_remote_v ' . 'WHERE useralias = %2 AND numplan = %#1', $dnum);
            $agi->conlog("Query: {$qry}", 3);
            $bind_str = $route['providertech'] . '/' . $route['providerip'];
            break;
    }
    $qry .= ';';
    //$agi->conlog("Find peer from ". $qry,4);
    if (!$bind_str) {
        return false;
    }
    $res = $dbhandle->Execute($qry);
    if (!$res) {
        $agi->verbose('Cannot dial peer: ' . $dbhandle->ErrorMsg());
        if (getAGIconfig('say_errors', true)) {
            $agi->stream_file('allison2', '#');
        }
        return false;
    }
    if ($res->EOF) {
        $agi->verbose("Peer dial: cannot find peer " . $dialnum, 2);
        //$agi-> stream_file("prepaid-dest-unreachable",'#');
        return null;
    }
    // Feature! If more than one registrations exist, call all of them in
    // parallel!
    $peer_rows = array();
    while ($row = $res->fetchRow()) {
        $peer_rows[] = str_alparams($bind_str, $row);
    }
    $str = '';
    if ($do_param) {
        if ($agi->astmajor == "1.6") {
            $str .= getAGIconfig('dialcommand_param', ',60,iL(%timeout)%param');
        } else {
            $str .= getAGIconfig('dialcommand_param', '|60|iL(%timeout)%param');
        }
        $str = str_alparams($str, array('dialnum' => $dialnum, 'dialnumber' => $dialn, 'dialstring' => $route['dialstring'], 'destination' => $route['destination'], 'trunkprefix' => $route['trunkprefix'], 'tech' => $route['providertech'], 'providerip' => $route['providerip'], 'prefix' => $route['prefix'], 'param' => $route['trunkparm'], 'cardnum' => $card['username'], 'stimeout' => $route['tmout'], 'timeout' => 1000 * $route['tmout']));
    }
    return implode('&', $peer_rows) . $str;
}
Пример #13
0
 public function buildSearchClause(&$dbhandle, $form, $search_exprs)
 {
     $val = $this->buildValue($form->getpost_dirty($this->fieldname), $form);
     if (empty($this->fieldexpr)) {
         $fldex = $this->fieldname;
     } else {
         $fldex = $this->fieldexpr;
     }
     if (is_array($search_exprs) && isset($search_exprs[$this->fieldname])) {
         $sex = $search_exprs[$this->fieldname];
     } else {
         $sex = '=';
     }
     //what's on *your* mind?
     if ($val == null) {
         switch ($sex) {
             // Assume NULL -> 0 ..
             case '<>':
             case '!=':
             case '>':
                 return $fldex . ' IS NOT NULL';
             case '<':
                 return 'false';
             case '>=':
                 return 'true';
             case '=':
             case '<=':
             default:
                 return $fldex . ' IS NULL';
         }
     } else {
         return str_dbparams($dbhandle, "{$fldex} {$sex} %1", array($val));
     }
 }
Пример #14
0
     }
     $played_nec = true;
     ReleaseCard($card);
     $card = null;
     continue;
 }
 $played_nec = false;
 $dialnum = getDialNumber($card, $num_try == 0);
 if ($dialnum === false) {
     $agi->stream_file('prepaid-invalid-digits', '#');
     continue;
 }
 $agi->conlog("Dial number: " . $dialnum, 4);
 // CHECK SPEEDDIAL
 getSpeedDial($card, $dialnum);
 $QRY = str_dbparams($a2b->DBHandle(), 'SELECT * FROM RateEngine3(%#1, %2, %#3, now(), %4);', array($card['tgid'], $dialnum, $card['numplan'], $card_money['base']));
 $agi->conlog($QRY, 3);
 $res = $a2b->DBHandle()->Execute($QRY);
 // If the rate engine has anything to Notice/Warn, display that..
 if ($notice = $a2b->DBHandle()->NoticeMsg()) {
     $agi->verbose('DB:' . $notice, 2);
 }
 if (!$res) {
     $agi->verbose('Rate engine: query error!', 2);
     $agi->conlog($a2b->DBHandle()->ErrorMsg(), 2);
     if (getAGIconfig('say_errors', true)) {
         $agi->stream_file('allison2', '#');
     }
     ReleaseCard($card);
     $card = null;
     break;
Пример #15
0
 public function buildUpdate(&$ins_arr, &$form)
 {
     if (!$this->does_edit) {
         return;
     }
     $ins_arr[] = str_dbparams($form->a2billing->DBHandle(), $this->fieldname . " = conv_currency_to( %1, %2)", array($this->buildValue($form->getpost_dirty($this->fieldname), $form), $form->a2billing->currency));
 }
Пример #16
0
 /** Allow special handling of other lines */
 protected function reg_special2($line2)
 {
     $tokens = array();
     if (preg_match('/\\[auto (.+)\\s*\\]/', $line2, $tokens) > 0) {
         $this->out(LOG_DEBUG, "Found auto header:" . $tokens[1]);
         $qry = str_dbparams($this->dbhandle, 'SELECT DISTINCT grp FROM cc_sysconf WHERE grp LIKE %1 ;', array($tokens[1] . '%'));
         $this->out(LOG_DEBUG, $qry);
         $rows = $this->dbhandle->GetAll($qry);
         if ($rows === false) {
             $this->out(LOG_ERR, $this->dbhandle->ErrorMsg());
             throw new Exception('Cannot query database');
         }
         for ($i = 1; $i < 100; $i++) {
             if (!in_array(array(grp => $tokens[1] . $i), $rows)) {
                 $this->cur_header = $tokens[1] . $i;
                 $this->out(LOG_DEBUG, "Will use " . $this->cur_header);
                 return true;
             }
         }
         $this->out(LOG_WARNING, "Cannot find useful group for " . $tokens[1] . "%x");
         $this->cur_header = false;
         //set it so that we skip the section!
         return true;
     }
     return false;
 }
Пример #17
0
    echo _("Pay back");
}
?>
 </p>
	<br><br><br>
<?php 
if (!isset($carry)) {
    $carry = 'f';
}
if (isset($sid)) {
    if ($pback == 0) {
        $sql_cmd = "SELECT format_currency(0 - pay_session( %1, %2, true, %3), %4, %5);";
    } else {
        $sql_cmd = "SELECT format_currency(pay_session( %1, %2, true, %3), %4, %5);";
    }
    $QUERY = str_dbparams($DBHandle, $sql_cmd, array($sid, $_SESSION['agent_id'], $carry, strtoupper(BASE_CURRENCY), $_SESSION['currency']));
    //echo htmlspecialchars($QUERY);
    $res = $DBHandle->query($QUERY);
} else {
    $res = false;
}
if ($res) {
    //echo gettype($res) . "<br>";
    $row = $res->fetchRow();
    //print_r($row);
    $sum = $row[0];
    ?>
	
	<p class="pay-message">
		<?php 
    if ($pback == 0) {
Пример #18
0
list($myyear, $mymonth) = split("-", $fromstatsmonth_sday);
$mymonth = $mymonth + 1;
if ($current_mymonth == 13) {
    $mymonth = 1;
    $myyear = $myyear + 1;
}
if (isset($choose_agent) && $choose_agent != '') {
    switch ($choose_agent) {
        case 'all':
            $tmp_agent_clause = 't1.username IN (SELECT cc_card.username FROM cc_card, cc_agent_cards WHERE cc_card.id = cc_agent_cards.card_id)';
            break;
        case 'no':
            $tmp_agent_clause = 't1.username NOT IN (SELECT cc_card.username FROM cc_card, cc_agent_cards WHERE cc_card.id = cc_agent_cards.card_id)';
            break;
        default:
            $tmp_agent_clause = str_dbparams($DBHandle, 't1.username IN (SELECT cc_card.username FROM cc_card, cc_agent_cards WHERE cc_card.id = cc_agent_cards.card_id AND cc_agent_cards.agentid = %1)', array((int) $choose_agent));
            break;
    }
}
for ($i = 0; $i < $months_compare + 1; $i++) {
    // creer un table legende
    $current_mymonth = $mymonth - $i;
    if ($current_mymonth <= 0) {
        $current_mymonth = $current_mymonth + 12;
        $minus_oneyar = 1;
    }
    $current_myyear = $myyear - $minus_oneyar;
    $current_mymonth2 = $mymonth - $i - 1;
    if ($current_mymonth2 <= 0) {
        $current_mymonth2 = $current_mymonth2 + 12;
        $minus_oneyar = 1;
Пример #19
0
/**
 *	Function refill_card_with_voucher
 **/
function getVoucher($card)
{
    global $a2b;
    global $agi;
    $dbhandle = $a2b->DBHandle();
    $agi->conlog('Voucher refill with card', 4);
    $vtimeout = getAGIconfig('voucher-timeoute', 8000);
    $vmaxlen = getAGIconfig('voucher-maxlen', 15);
    $vminlen = getAGIconfig('voucher-minlen', 5);
    $vprompt = getAGIconfig('voucher-prompt', 'prepaid-voucher_enter_number');
    $vprompt_nexist = getAGIconfig('voucher-prompt-nexist', 'prepaid-voucher_does_not_exist');
    $vprompt_refill = getAGIconfig('voucher-prompt-refill', 'prepaid-account_refill');
    $vprompt_no_entered = getAGIconfig('voucher-prompt-no-entered', 'prepaid-no-voucher-entered');
    $vprompt_invalid = getAGIconfig('voucher-prompt-invalid', 'prepaid-invalid-voucher');
    $agi->conlog('Voucher-ivr: asking for Voucher', 4);
    $res_dtmf = $agi->get_data($vprompt, $vtimeout, $vmaxlen);
    $agi->conlog('Voucher-ivr: result ' . print_r($res_dtmf, true), 3);
    if (!isset($res_dtmf['result'])) {
        $agi->conlog('No Voucher entered', 2);
        $agi->stream_file($vprompt_no_entered, '#');
        return null;
    }
    $vouchernum = $res_dtmf['result'];
    if (strlen($vouchernum) < $vminlen || strlen($vouchernum) > $vmaxlen) {
        $agi->conlog('Invalid Voucher', 2);
        $agi->stream_file($vprompt_invalid, '#');
        return null;
    }
    // CALL STORED PROCEDURE FOR VOUCHER
    $QRY = str_dbparams($a2b->DBHandle(), 'SELECT * FROM  card_use_voucher (%1, %2);', array($card['id'], $vouchernum));
    $agi->conlog($QRY, 3);
    $res = $a2b->DBHandle()->Execute($QRY);
    // If the rate engine has anything to Notice/Warn, display that..
    if ($notice = $a2b->DBHandle()->NoticeMsg()) {
        $agi->verbose('DB:' . $notice, 2);
    }
    if (!$res) {
        $emsg = $dbhandle->ErrorMsg();
        if (substr($emsg, 0, 23) == 'ERROR:  card_use_voucher') {
            $msga = explode('|', $emsg);
            $agi->verbose('Could not use voucher: ' . $msga[3]);
            //$agi->conlog("Message: " . print_r($msga,true),4);
            switch ($msga[1]) {
                case 'voucher-no-find':
                    //$agi->stream_file('prepaid-card-in-use','#');
                    break;
                case 'voucher-zero':
                case 'conv_currency-failed':
                case 'conv_currency-failed-zero':
                    //TODO
                    break;
                default:
                    $agi->conlog('Unknown result from card_use_voucher: ' . $msga[1], 3);
            }
        } else {
            $agi->verbose('Could not use voucher : ' . $emsg);
        }
        $agi->stream_file($vprompt_invalid, '#');
        return null;
    }
    if ($res->EOF) {
        $agi->verbose('No used voucher in card_use_voucher(), why?');
        return null;
    }
    $agi->conlog('Unknown result from card_use_voucher: ' . $msga[1], 3);
    $row = $res->fetchRow();
    if (empty($row['card_use_voucher'])) {
        $agi->verbose('Fail to fetch on voucher ! ');
        return false;
    }
    $agi->conlog('Voucher used. Amount of credit added : ' . $row['card_use_voucher'], 3);
    $agi->stream_file($vprompt_refill, '#');
    // TODO : play the Amount of credit added
    return true;
}
Пример #20
0
    public function genContent(&$outstream)
    {
        fwrite($outstream, "<flat-profile>\n");
        fwrite($outstream, "\t<!-- Generated content -->\n\n");
        $dbhandle = $this->dbhandle;
        $passed_gen = false;
        if ($this->args['firsttime']) {
            $ftc = '';
        } else {
            $ftc = ' AND (options & 02 = 0 )';
        }
        $unquery = "SELECT DISTINCT * FROM provision_group " . " WHERE categ = %2 " . " AND model = %1 AND options = 0";
        $numquery = "SELECT DISTINCT * FROM provision_group " . " WHERE categ = %2 " . " AND model = %1 AND options = 1";
        if (!$this->args['firsttime']) {
            $unquery .= ' AND ( mtime IS NULL OR %!3 IS NULL OR mtime > %!3 )';
            $numquery .= ' AND ( mtime IS NULL OR %!3 IS NULL OR mtime > %!3 )';
        }
        $unquery .= ';';
        $numquery .= ';';
        while ($cardrow = $this->cardres->fetchRow()) {
            // find the unnumbered parameters:
            if (!$passed_gen) {
                $qry = str_dbparams($dbhandle, $unquery, array($cardrow['devmodel'], $this->confname, $cardrow['provi_date']));
                $this->out(LOG_DEBUG, "Query: {$qry}");
                $gres = $dbhandle->Execute($qry);
                if (!$gres) {
                    $this->out(LOG_ERR, $this->dbhandle->ErrorMsg());
                    throw new Exception("Cannot locate provision");
                } elseif ($gres->EOF) {
                    $this->out(LOG_DEBUG, 'No rows for provision groups');
                } else {
                    while ($grprow = $gres->fetchRow()) {
                        $qry = str_dbparams($this->dbhandle, "SELECT * FROM provisions " . "WHERE grp_id = %#1 AND (options & 16 = 0) {$ftc} ORDER BY metric;", array($grprow['id']));
                        $this->out(LOG_DEBUG, "Query: {$qry}");
                        $pres = $this->dbhandle->Execute($qry);
                        if (!$pres) {
                            $this->out(LOG_ERR, $this->dbhandle->ErrorMsg());
                            throw new Exception("Cannot locate provision");
                        } elseif (!$itemres->EOF) {
                            if (!$grphead) {
                                fwrite($outstream, "\t<!-- " . $grprow['sub_name'] . " -->\n");
                            }
                            $this->genContentElems($outstream, $pres, $cardrow);
                            $passed_gen = true;
                            $grphead = true;
                        }
                    }
                }
            }
            // Query again for numbered groups:
            $qry = str_dbparams($dbhandle, $numquery, array($cardrow['devmodel'], $this->confname, $cardrow['provi_date']));
            $this->out(LOG_DEBUG, "Query: {$qry}");
            $gres = $dbhandle->Execute($qry);
            if (!$gres) {
                $this->out(LOG_ERR, $this->dbhandle->ErrorMsg());
                throw new Exception("Cannot locate provision");
            } elseif ($gres->EOF) {
                $this->out(LOG_DEBUG, 'No rows for provision groups');
            } else {
                while ($grprow = $gres->fetchRow()) {
                    $grphead = false;
                    if (empty($cardrow['provi_num'])) {
                        continue;
                    }
                    // And one for the numbered params
                    $qry = str_dbparams($this->dbhandle, "SELECT * FROM provisions " . "WHERE grp_id = %#1 {$ftc} ORDER BY metric;", array($grprow['id']));
                    $this->out(LOG_DEBUG, "Query: {$qry}");
                    $pres = $this->dbhandle->Execute($qry);
                    if (!$pres) {
                        $this->out(LOG_ERR, $this->dbhandle->ErrorMsg());
                        throw new Exception("Cannot locate provision");
                    } elseif (!$itemres->EOF) {
                        if (!$grphead) {
                            fwrite($outstream, "\t<!-- " . $grprow['sub_name'] . " -->\n");
                        }
                        $this->genContentElems($outstream, $pres, $cardrow, $cardrow['provi_num']);
                        $grphead = true;
                    }
                }
            }
        }
        fwrite($outstream, "\n</flat-profile>\n");
        $qry = str_dbparams($dbhandle, 'UPDATE cc_ast_users SET provi_date = now() ' . ' WHERE cc_ast_users.macaddr = %1
			  AND cc_ast_users.devsecret = %2
			  AND EXISTS (SELECT 1 FROM provision_group WHERE categ = %3 
			  		AND model = cc_ast_users.devmodel) ;', array($this->args['mac'], $this->args['sec'], $this->confname));
        $this->out(LOG_DEBUG, "Query: {$qry}");
        $res = $this->dbhandle->Execute($qry);
        if (!$res) {
            $this->out(LOG_ERR, $this->dbhandle->ErrorMsg());
            $this->out(LOG_ERR, "Cannot Update provisioned device.");
        }
    }
Пример #21
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();
Пример #22
0
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!";
    $PAGE_ELEMS[] = new ErrorElem(_("Cannot locate session!"));
} else {
    $sess_row = $sess_res->fetchRow();
}
Пример #23
0
function iterate_regstates()
{
    global $manager_connections;
    global $dbh;
    global $verbose;
    $qry = 'SELECT * FROM realtime16_sip_regstates WHERE sipiax = 5 AND reg_state >2 ;';
    if ($verbose > 2) {
        echo "Query: {$qry} \n";
    }
    $res = $dbh->Execute($qry);
    if (!$res) {
        echo $dbh->ErrorMsg() . "\n";
        return false;
    } elseif ($res->EOF) {
        if ($verbose > 1) {
            echo "No instances need update.\n";
        }
        return false;
    } else {
        while ($row = $res->fetchRow()) {
            if (empty($row['srvid']) || !isset($manager_connections[$row['srvid']])) {
                if ($verbose > 2) {
                    echo "Alterer entry belongs to other server.\n";
                }
                continue;
            }
            $nextstate = NULL;
            switch ($row['reg_state']) {
                case '3':
                    //new
                    if ($verbose > 2) {
                        echo "User " . $row['name'] . '@' . $row['regserver'] . " must be loaded\n";
                    }
                    $mr = $manager_connections[$row['srvid']]->Command('sip qualify peer ' . $row['name'] . ' load');
                    if (!$mr) {
                        if ($verbose > 1) {
                            echo "Command failed.\n";
                        }
                        break;
                    }
                    $nextstate = 1;
                    break;
                case '5':
                    // to prune
                    if ($verbose > 2) {
                        echo "User " . $row['defaultuser'] . '@' . $row['host'] . " must be pruned\n";
                    }
                    $mr = $manager_connections[$row['srvid']]->Command('sip registry prune ' . $row['defaultuser'] . '@' . $row['host']);
                    if (!$mr) {
                        if ($verbose > 1) {
                            echo "Command failed.\n";
                        }
                        break;
                    }
                    $nextstate = 2;
                    break;
                default:
                    if ($verbose > 1) {
                        echo "Unknown reg_state: " . $row['reg_state'] . "\n";
                    }
            }
            if ($nextstate !== NULL) {
                // Update state
                $upd_qry = str_dbparams($dbh, 'UPDATE cc_ast_instance SET reg_state = %#1 ' . 'WHERE userid = %#2 AND srvid = %#3 AND sipiax = %#4 ;', array($nextstate, $row['realtime_id'], $row['srvid'], $row['sipiax']));
                if ($verbose > 2) {
                    echo "Query: {$upd_qry} \n";
                }
                $ures = $dbh->Execute($upd_qry);
                if (!$ures) {
                    echo $dbh->ErrorMsg() . "\n";
                    break;
                }
            }
        }
        return true;
    }
}
Пример #24
0
}
if (!isset($form_action)) {
    $form_action = "list";
}
//ask-add
if (!isset($action)) {
    $action = $form_action;
}
if ($posted == 2) {
    if ($FG_DEBUG > 1) {
        echo "<br>posted!<br>";
    }
    $texts_list = $_POST['text'];
    if (is_array($texts_list)) {
        foreach ($texts_list as $txt_id => $txt_val) {
            $qry = str_dbparams($HD_Form->DBHandle, "UPDATE cc_texts SET txt = %2 WHERE id = %1 AND lang = %3;", array($txt_id, $txt_val, $filterlang));
            if ($FG_DEBUG > 1) {
                echo $qry . "<br>";
            }
            $res = $HD_Form->DBHandle->Query($qry);
            if (!$res && $FG_DEBUG) {
                echo "<br>Query failed: " . $HD_Form->DBHandle->ErrorMsg() . "<br>";
            }
        }
    } else {
        if ($FG_DEBUG > 1) {
            echo "Texts is not an array!<br>";
        }
    }
    $form_action = "list";
}
Пример #25
0
    public function Render(&$form)
    {
        $dbhandle = $form->a2billing->DBHandle();
        $fldIndex = array();
        ?>
<div class='impA-progress' name="<?php 
        echo $form->prefix;
        ?>
iprogress">
			<?php 
        echo _("Importing uploaded data...");
        ?>
			<span name="<?php 
        echo $form->prefix;
        ?>
icount"> </span>
		<div>
		
		<?php 
        // Construct, again, the list of fields
        foreach ($form->model as $key => $fld) {
            if ($fld->fieldname) {
                $fldIndex[$fld->fieldname] = $key;
            }
        }
        $fields2 = array();
        $returning = array();
        $fields = explode(',', $_SESSION[$form->prefix . 'importFields']);
        foreach ($fields as $fld) {
            $retk = null;
            $ext = false;
            //does it aggregate over CSV rows?
            $aggr = in_array($fld, $this->askImport->multiple);
            // does it belong to the primary INSERT or to
            // some subsequent?
            if ($form->model[$fldIndex[$fld]] instanceof RevRef) {
                $ext = true;
                $retk = $form->model[$fldIndex[$fld]]->localkey;
            }
            $fields2[] = array($fld, $fldIndex[$fld], $aggr, $ext, $retk);
        }
        unset($fields);
        if ($form->FG_DEBUG > 4) {
            echo nl2br(htmlspecialchars(print_r($fields2, true)));
            echo "<br>\n";
        }
        // Build primary INSERT
        $ins_keys = array();
        //$ins_values = array();
        $ins_qm = array();
        $ins_returning = array();
        // Find
        foreach ($this->askImport->common as $fld) {
            $ins_keys[] = $fld;
            $ins_qm[] = str_dbparams($dbhandle, "%!1", array($form->model[$fldIndex[$fld]]->buildValue($form->getpost_dirty($fld), $form)));
        }
        foreach ($fields2 as $fld) {
            if (!$fld[3]) {
                $ins_keys[] = $fld[0];
                $ins_qm[] = '?';
            } else {
                $ins_returning[] = $fld[4];
            }
        }
        $insert_pri = "INSERT INTO " . $form->model_table . "(" . implode(', ', $ins_keys) . ") VALUES(" . implode(',', $ins_qm) . ")";
        if (count($ins_returning)) {
            $insert_pri .= " RETURNING " . implode(', ', $ins_returning);
        }
        $insert_pri .= ";";
        if ($form->FG_DEBUG > 1) {
            echo "Insert query: " . htmlspecialchars($insert_pri) . "<br>\n";
        }
        $fp = fopen($this->movedFile, "r");
        if (!$fp) {
            ?>
<div class="error">
				<?php 
            echo _("Error: Cannot open uploaded file");
            ?>
			</div>
			<?php 
            return;
        }
        $nrows = 0;
        $nlines = 0;
        $delimiter = $this->askImport->delimiter;
        $multi_sep = $this->askImport->multi_sep;
        $last_a = null;
        $reted = null;
        // 		$last_b = null;
        //Everything must be in one transaction, to avoid partially imported
        //data
        $dbhandle->StartTrans();
        // The actual import loop!
        while (($larr = fgetcsv($fp, 4096, $delimiter)) !== false) {
            if ($larr === null) {
                continue;
            }
            if (count($larr) < count($fields2)) {
                if ($form->FG_DEBUG) {
                    echo "Less fields came!<br>\n";
                }
                if ($form->FG_DEBUG > 2) {
                    echo nl2br(print_r($larr, true) . "\n");
                }
                $dbhandle->FailTrans();
                break;
            }
            $nlines++;
            $arr_a = array();
            $arr_b = array();
            $arr_ext = array();
            //split the data into 2 arrays.
            foreach ($fields2 as $fld) {
                $val = $form->model[$fld[1]]->buildValue(current($larr), $form);
                if (!$fld[2]) {
                    $arr_a[] = $val;
                } else {
                    if (!$fld[3]) {
                        $arr_b[] = $val;
                    } else {
                        $arr_c[$fld[0]] = $val;
                    }
                }
                next($larr);
            }
            //If non-multiple data matches, we reuse the line
            if ($this->askImport->distinct && $arr_a == $last_a) {
            } else {
                if ($form->FG_DEBUG > 2 && $nrows < 100) {
                    echo "Data:" . htmlspecialchars(implode(', ', $arr_a)) . "<br>\n";
                }
                $res = $dbhandle->Execute($insert_pri, $arr_a);
                if (!$res) {
                    ?>
				<div class="error">
					<?php 
                    echo _("Database error, cannot import!");
                    ?>
				</div>
				<?php 
                    if ($form->FG_DEBUG) {
                        echo $dbhandle->ErrorMsg();
                        echo "<br>\n";
                    }
                    $dbhandle->FailTrans();
                    return;
                } elseif (count($ins_returning) && $res->EOF) {
                    ?>
				<div class="error">
					<?php 
                    echo _("Database error, rows not imported!");
                    ?>
				</div>
				<?php 
                    if ($form->FG_DEBUG) {
                        echo "No result from insert operation!";
                        echo "<br>\n";
                    }
                    $dbhandle->FailTrans();
                    return;
                } else {
                    $reted = $res->fetchRow();
                }
                if ($form->FG_DEBUG && !$res->EOF) {
                    echo "Second result after INSERT? weird..<br>\n";
                }
                if ($form->FG_DEBUG > 2 && $nlines < 10 && count($ins_returning)) {
                    echo "Returned: " . print_r($reted, true) . "<br>\n";
                }
                $last_a = $arr_a;
                $nrows++;
            }
            if (count($arr_c)) {
                foreach ($fields2 as $fld) {
                    if (!$fld[3]) {
                        continue;
                    }
                    $mfld =& $form->model[$fld[1]];
                    $cqry = "INSERT INTO {$mfld->reftable} ({$mfld->refid}, {$mfld->refname}) VALUES ";
                    $data = explode($multi_sep, $arr_c[$fld[0]]);
                    if (!count($data)) {
                        continue;
                    }
                    $cqry_val = array();
                    foreach ($data as $dat) {
                        $cqry_val[] = str_dbparams($dbhandle, "(%1, %2)", array($reted[$mfld->localkey], $dat));
                    }
                    $cqry .= implode(",\n", $cqry_val) . ";";
                    if ($form->FG_DEBUG > 2 && $nlines < 100) {
                        echo "Extra: " . htmlspecialchars($cqry) . "<br>\n";
                    }
                    $res = $dbhandle->Execute($cqry);
                    if (!$res) {
                        ?>
				<div class="error">
					<?php 
                        echo _("Database error, secondary rows not imported!");
                        ?>
				</div>
				<?php 
                        if ($form->FG_DEBUG) {
                            if ($form->FG_DEBUG > 2) {
                                echo "Query: " . htmlspecialchars($cqry) . "<br>\n";
                            }
                            echo $dbhandle->ErrorMsg();
                            echo "<br>\n";
                        }
                        $dbhandle->FailTrans();
                        return;
                    }
                }
            }
            if ($nlines % 1000 == 0) {
                // reset the timer and give us another 20sec
                set_time_limit(20);
                if ($form->FG_DEBUG > 1) {
                    echo "Rows found: {$nrows}<br>\n";
                }
                ?>
	<script language="JavaScript" type="text/javascript">
	document.getElementsByName("<?php 
                echo $form->prefix;
                ?>
icount")[0].innerHTML = "<?php 
                echo str_params(_("%1 lines processed: %2 rows"), array($nlines, $nrows), 1);
                ?>
";
	window.status = "<?php 
                echo str_params(_("%1 lines processed: %2 rows"), array($nlines, $nrows), 1);
                ?>
";
		</script>
				<?php 
                @ob_end_flush();
                // Make sure we flush the http data
            }
        }
        //while fgets
        if ($dbhandle->CompleteTrans()) {
            ?>
	<script language="JavaScript" type="text/javascript">
	document.getElementsByName("<?php 
            echo $form->prefix;
            ?>
icount")[0].innerHTML = "<?php 
            echo str_params(_("%1 lines processed: %2 rows"), array($nlines, $nrows), 1);
            ?>
";
	window.status = "<?php 
            echo str_params(_("%1 lines processed: %2 rows"), array($nlines, $nrows), 1);
            ?>
";
		</script>
		<?php 
        } else {
            echo _("Import of data aborted.");
            echo "<br>\n";
        }
        unset($_SESSION[$form->prefix . 'importFile']);
        unset($_SESSION[$form->prefix . 'importFields']);
        unset($_SESSION[$form->prefix . 'importRnd']);
        @unlink($this->movedFile);
    }
Пример #26
0
         $row = $result->FetchRow();
         array_push($new_cards, $row[0]);
     }
     if ($gtype == 'booth') {
         $BOOTH_QUERY = str_dbparams($HD_Form->DBHandle, "INSERT INTO cc_booth(agentid,  name, def_card_id, callerid)" . "SELECT %#1, 'Booth ' || useralias, %2, username " . "FROM cc_card WHERE id = %2 ;", array($choose_agent, $row[0]));
         $result = $HD_Form->DBHandle->Execute($BOOTH_QUERY);
         if ($HD_Form->FG_DEBUG > 2 || !$result) {
             echo "DB Err:" . $HD_Form->DBHandle->ErrorMsg() . "<br>\n";
         }
         if (!$result) {
             if ($HD_Form->FG_DEBUG > 0) {
                 echo "Cannot create booth!<br>\n";
             }
             break;
         }
         $SIP_QUERY = str_dbparams($HD_Form->DBHandle, "INSERT INTO cc_sip_buddies(" . "name, accountcode, regexten, callerid, username, secret, " . "type, allow, context, nat, amaflags, qualify, host, dtmfmode) " . " SELECT username, username, NULL, username, username, mkpasswd(8), " . $SIP_CONSTS . " FROM cc_card WHERE id = %#1;", array($row[0]));
         $result = $HD_Form->DBHandle->Execute($SIP_QUERY);
         if ($HD_Form->FG_DEBUG > 2 || !$result) {
             echo "DB Err:" . $HD_Form->DBHandle->ErrorMsg() . "<br>\n";
         }
         if (!$result) {
             if ($HD_Form->FG_DEBUG > 0) {
                 echo "Cannot create sip_buddy!<br>\n";
             }
             continue;
         }
         $_SESSION["is_sip_iax_change"] = 1;
         $_SESSION["is_sip_changed"] = 1;
     }
 }
 echo "New cards:";
Пример #27
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";
Пример #28
0
 public function PerformObjEdit(&$form)
 {
     $DBHandle = $form->a2billing->DBHandle();
     $oeaction = $form->getpost_single($this->fieldname . '_action');
     $oeid = $form->getpost_single($this->localkey);
     $dbg_elem = new DbgElem();
     if ($form->FG_DEBUG > 0) {
         $form->pre_elems[] =& $dbg_elem;
     }
     switch ($oeaction) {
         case 'add':
             $QUERY = str_dbparams($DBHandle, "INSERT INTO {$this->assoctable} ({$this->assocleft}, {$this->assocright}) VALUES(%1, %2);", array($oeid, $form->getpost_single($this->fieldname . '_add')));
             $dbg_elem->content .= "Query: " . htmlspecialchars($QUERY) . "\n";
             $res = $DBHandle->Execute($QUERY);
             if (!$res) {
                 $form->pre_elems[] = new ErrorElem(str_params(_("Cannot insert new %1"), array($this->fieldtitle), 1));
                 $dbg_elem->content .= "Query failed:" . $DBHandle->ErrorMsg() . "\n";
             } else {
                 $dbg_elem->content .= "Item added!";
             }
             break;
         case 'delete':
             $QUERY = str_dbparams($DBHandle, "DELETE FROM {$this->assoctable} WHERE {$this->assocleft} = %1 AND {$this->assocright} = %2;", array($oeid, $form->getpost_single($this->fieldname . '_del')));
             $dbg_elem->content .= "Query: " . htmlspecialchars($QUERY) . "\n";
             $res = $DBHandle->Execute($QUERY);
             if (!$res) {
                 $form->pre_elems[] = new ErrorElem(str_params(_("Cannot delete %1"), array($this->fieldtitle), 1));
                 $dbg_elem->content .= "Query failed: " . $DBHandle->ErrorMsg() . " \n";
             } else {
                 $dbg_elem->content .= "Item deleted!";
             }
             break;
         default:
             $dbg_elem->content .= "Unknown action {$oeaction}";
     }
     return 'ask-edit';
 }
Пример #29
0
 public function buildUpdate(&$upd_arr, &$form)
 {
     if (!$this->does_edit) {
         return;
     }
     $val = $form->getpost_dirty($this->fieldname);
     $val_old = $form->getpost_dirty($this->fieldname . '_old');
     if ($val != $val_old) {
         $upd_arr[] = str_dbparams($form->a2billing->DBHandle(), "{$this->fieldname} = %#1 + ({$this->fieldname} - %#2)", array($val, $val_old));
     }
 }
Пример #30
0
 public function listQueryClause(&$dbhandle, &$form)
 {
     return str_dbparams($dbhandle, "{$this->fieldname} = %1", array($this->fieldvalue));
 }