exten => 23,1,Ringing()
exten => 23,n,Wait(1)
exten => 23,n,Answer
exten => 23,n,AGI(cidlookup.php,${CALLERID},green)
;you may want to use a Dial() command here or convert to a macro to use on every inbound call
exten => 23,n,Hangup()
|
--
-- Current Database: cidlookup
--
CREATE DATABASE IF NOT EXISTS cidlookup;
USE cidlookup;
--
-- Table structure for table cidnum
--
DROP TABLE IF EXISTS cidnum;
CREATE TABLE cidnum (
cidactive char(1) NOT NULL default 'A',
cidnum char(11) NOT NULL default '12223334444',
cidname char(16) NOT NULL default 'unknown',
cidcustid char(12) NOT NULL default 'unknown',
cidrepid char(6) NOT NULL default 'empty',
PRIMARY KEY (cidnum,cidname)
) ;
--
-- Table structure for table custlist
--
DROP TABLE IF EXISTS custlist;
CREATE TABLE custlist (
cuactive char(1) NOT NULL default 'A',
custid char(12) NOT NULL default 'unknown',
custconame char(16) NOT NULL default 'unknown',
custrepid char(6) NOT NULL default 'empty',
PRIMARY KEY (custid)
) ;
--
-- Table structure for table replist
--
DROP TABLE IF EXISTS replist;
CREATE TABLE replist (
repactive char(1) NOT NULL default 'A',
repid char(12) NOT NULL default 'unknown',
repfname char(16) NOT NULL default 'unknown',
replname char(16) NOT NULL default 'unknown',
reploginid char(16) NOT NULL default 'unknown',
PRIMARY KEY (repid)
) ;
|
#!/usr/local/bin/php -q
foreach($agi as $key=>$value)
{
$noop = 1;
fwrite(STDERR," -- $key = $value\n");
fflush(STDERR);
echo " -- $key = >$value<\n";
fputs($stdlog," -- $key = >$value<\n");
}
// indicate in the CLI> that we have launched the agi script
fputs($stdlog,"VERBOSE \"Here we go!\" 2\n");
echo "VERBOSE \"Here we go!\" 2\n";
read();
// any write/echo output from this script to the asterisk program must
// have a coresponding read or you will hang asterisk
write("Call from ".$agi['channel']." - Calling phone");
read();
fputs($stdlog,"Call from ".$agi['channel']." - Called channel\n");
fputs($stdlog,"Caller Number ".$agi['callerid']." - Caller Number\n");
fputs($stdlog,"Caller Name ".$agi['calleridname']." - Caller Name\n\n");
// this is what we expect for the caller id variables:
// agi_callerid: 18576870181
// agi_calleridname: JONES JACK J
// Note: some caller id strings have a comma after the last name so
// if you parse this aware the string format is not standard
// ok, lets get all the fields for this record
$query="SELECT * from cidnum where cidnum='" . $agi['callerid'] . "';";
fputs($stdlog,"query=$query<\n");
$Result = mysql_query($query,$conn);
$num_rows = mysql_num_rows($Result);
if ($terrno == 0)
{
// a successful query, log the error
$terrno = mysql_errno($conn);
$errno = sprintf("%s",$terrno);
fputs($stdlog," errno $errno\n");
} else {
// an unsuccessful query, log the failure so we can fix
// that at some point
$terrno = mysql_errno($conn);
$terror = mysql_error($conn);
$errno = sprintf("%s",$terrno);
$error = sprintf("%s",$terror);
fputs($stdlog," errno $errno\n");
fputs($stdlog," error $error\n");
}
// now, get the record details and place them into a web only variable
// indicated by a preceding w_
// this is used to distinquish a just retrieved database field from
// a webpage veriable on a refresh. we can tell if the webpage changed
// and an update must be performed on the database
// this would be used if the webpage had any editing capabilities
$Row = mysql_fetch_array($Result, MYSQL_ASSOC);
$w_cidnum = $Row["cidnum"];
$w_cidname = $Row["cidname"];
$w_cidcustid = $Row["cidcustid"];
$w_cidrepid = $Row["cidrepid"];
// check to make sure we only got one record
fputs($stdlog," num_rows=$num_rows\n");
if ($num_rows == 1)
{
fputs($stdlog,"PASS: cidnum [$w_cidnum] returned exactly $num_rows row<\n");
} else {
fputs($stdlog,"ERROR: cidnum [$w_cidnum] returned $num_rows rows<\n");
}
// ok, now get the assigned customer rep id for this customer
$query="SELECT * from replist where repid='" . $w_cidrepid . "';";
fputs($stdlog,"query=$query<\n");
$Result = mysql_query($query,$conn);
$num_rows = mysql_num_rows($Result);
// check to make sure we only got one record
if ($num_rows == 1)
{
fputs($stdlog,"PASS: reploginid [$w_reploginid] returned exactly $num_rows row<\n");
} else {
fputs($stdlog,"ERROR: reploginid [$w_reploginid] returned $num_rows rows<\n");
}
// get the record for our customer service rep
$Row = mysql_fetch_array($Result, MYSQL_ASSOC);
$w_repfname = $Row["repfname"];
$w_reploginid = $Row["reploginid"];
// log what we currently have to the logfile
fputs($stdlog,"cidnum=$w_cidnum<\n");
fputs($stdlog,"cidname=$w_cidname<\n");
fputs($stdlog,"cidcustid=$w_cidcustid<\n");
fputs($stdlog,"cidrepid=$w_cidrepid<\n");
fputs($stdlog,"reploginid=$w_reploginid<\n");
// close db connection
mysql_close($conn);
// at some point, we can figure out how to route to the reps,
// primary rep first (if currently logged in)
// secondary rep next or next rep logged in or place in the queue!
// now create the screen pop web page
// create the HTML ACTION parameters to put in the FORM ACTION= param
$ACTION_HOST = "192.168.15.81";
$ACTION_DIR = "pop9";
$ACTION_SCRIPT = "callpop4.php";
// create the POP_URL to send to the rep
// this is where the customer rep will point his/her browser
// it just happens to be on the same host
$POPHOST = "192.168.15.81";
$POP_DIR = "pop9/scrnpop";
// create the call alert (accept/reject) webpage to launch for this call
$WEB_DIR = "/var/www/html/";
$WEB_DIR .= $POP_DIR;
$now = date('Y-m-d-H-i-s.u');
// create the filename and add the date to the filename so we can keep a
// record of pops although that is overkill
$WEB_FILENAME = 'scrnpop_' . $now . "-" . $w_cidcustid . "-" . $w_reploginid . ".php";
$WEBPAGE = $WEB_DIR . "/" . $WEB_FILENAME;
fputs($stdlog,"WEB_DIR filename is >$WEB_DIR<\n");
fputs($stdlog,"WEB_FILENAME is >$WEB_FILENAME<\n");
fputs($stdlog,"WEBPAGE is >$WEBPAGE<\n");
// now create the actual URL
$POP_URL="http://" . $POPHOST . "/" . $POP_DIR . "/" . $WEB_FILENAME;
fputs($stdlog,"POP_URL created is >$POP_URL<\n");
fputs($stdlog,"\n");
fputs($stdlog,"=====================\n");
fputs($stdlog,"\n");
...
|