AGI – IVR – Time Clock



AGI Script

#!/usr/bin/perl

use Asterisk::AGI;
use DBI;

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();
my $callerid = $input{''''callerid''''};

############# Time Clock Questions ################

my $empid = $AGI->get_data(''''employee'''',-1,5); # Asks for Employee ID
$AGI->stream_file(entered);
$AGI->say_digits($empid);

my $optemp = $AGI->get_data(''''correct'''',-1,1); # Asks if what was
entered is correct otherwise ask question again

if ($optemp != 1) {
employeeid ();
}

my $strid = $AGI->get_data(''''store'''',-1,5); # Asks for Store ID
$AGI->stream_file(entered);
$AGI->say_digits($strid);

my $optstr = $AGI->get_data(''''correct'''',-1,1); # Asks if what
was entered is correct otherwise ask question again

if ($optstr != 1) {
storeid ();
}

my $stat = $AGI->get_data(''''status'''',-1,1); #Asks - Login or Logout

if ($stat == 1) {
$AGI->stream_file(login);
}else{
$AGI->stream_file(logout);
}

my $optstat = $AGI->get_data(''''correct'''',-1,1); # Asks if what
was entered is correct otherwise ask question again

if ($optstat != 1) {
status ();
}

 

############# Database Connection ###########################

my $dbh = DBI->connect("DBI:mysql:database=service;host=localhost",
"username", "password",
{''''RaiseError'''' => 1});

$query = "INSERT INTO <a id="_GPLITA_1" title="Powered by Text-Enhance" href="http://shishir.com.np/blog/?q=node/5#">auto</a> (Callerid, Date, Time, Empid, Strid, Status)
VALUES (''''$callerid'''', sysdate(), sysdate(), ''''$empid'''', ''''$strid'''',
''''$stat'''')";

$sth = $dbh-&gt;prepare($query);
$sth-&gt;execute();

$sth-&gt;finish();

$dbh-&gt;disconnect;

$AGI-&gt;stream_file(beep);

####### Sub Routines ############

sub employeeid {

my $empid = $AGI-&gt;get_data(''''employee'''',-1,5);
$AGI-&gt;stream_file(entered);
$AGI-&gt;say_digits($empid);

my $optemp = $AGI-&gt;get_data(''''correct'''',-1,1);

}

sub storeid {

my $strid = $AGI-&gt;get_data(''''store'''',-1,5);
$AGI-&gt;stream_file(entered);
$AGI-&gt;say_digits($strid);

my $optstr = $AGI-&gt;get_data(''''correct'''',-1,1);

}

sub status {

my $stat = $AGI-&gt;get_data(''''status'''',-1,1);

if ($stat == 1) {
$AGI-&gt;stream_file(login);
}else{
$AGI-&gt;stream_file(logout);
}

my $optstat = $AGI-&gt;get_data(''''correct'''',-1,1);

------------------------------------------------------------------------------
Page to view data that was entered........

There is 3 Tables involved...

1. Data that is entered by user
2. Employeed Name -&gt; Employee ID
3. Store Named -&gt; Store ID

---------------------------------------------------------------------------------

Service <a id="_GPLITA_0" title="Powered by Text-Enhance" href="http://shishir.com.np/blog/?q=node/5#">Express</a> Time Clock

Service Express Time
Clock

Caller ID
Store Name
Employee Name
Date
Time
Login / Logout

&lt;?
$hostName = "localhost";
$userName = "username";
$password = "password";
$dbName = "service";

// make connection to database
mysql_connect($hostName, $userName, $password) or die("Unable to connect
to host $hostName");

mysql_select_db($dbName) or die("Unable to select database $dbName");

//$query = "SELECT * from auto ORDER BY Date, Time";

$query = "select
auto.Callerid,store.name,emp.employee,auto.Date,auto.Time,auto.Status
from auto,store,emp
where auto.Strid=store.store_id and auto.Empid=emp.id
ORDER BY Date, Time";

$result = mysql_query($query);

$number = mysql_numrows($result);

print "There are $number records in the Database:";

for ($i=0; $i&lt;$number; $i++) {
$v_callid = mysql_result($result, $i, "CallerID");
$v_store = mysql_result($result, $i, "name");
$v_emp = mysql_result($result, $i, "employee");
$v_date = mysql_result($result, $i, "Date");
$v_time = mysql_result($result, $i, "Time");
$v_stat = mysql_result($result, $i, "Status");

if ($v_stat == ''''1'''') {
$v_stat_chgn = "Login";
}else{
$v_stat_chgn = "Logout";
}

// print "$v_callid, $v_date, $v_time, $v_empid, $v_strid,
$v_stat, $v_stat_chgn";
echo "";
echo "$v_callid";
echo "$v_store";
echo "$v_emp";
echo "$v_date";
echo "$v_time";
echo "$v_stat_chgn";
echo "";
}

mysql_close();

?&gt;

, , ,

Comments are closed.