install_prereq: Download latest Jansson.
[asterisk/asterisk.git] / contrib / scripts / agents.php
1 <?php 
2
3 ob_implicit_flush(false);
4
5 $username = "drmac";
6 $secret   = "secret";
7
8 $socket = fsockopen("127.0.0.1","5038", $errornum, $errorstr);
9
10 $agents = array();
11 $curr_agent = "";
12 $better_status = array( 'AGENT_UNKNOWN'         => 'Unknown',
13                         'AGENT_IDLE'            => 'Idle',
14                         'AGENT_ONCALL'          => 'On Call',
15                         'AGENT_LOGGEDOFF'       => 'Not Logged In' );
16
17 if(!$socket) {
18         print "Couldn't open socket. Error #" . $errornum . ": " . $errorstr;
19 } else {
20         fputs($socket, "Action: Login\r\n");
21         fputs($socket, "UserName: $username\r\n");
22         fputs($socket, "Secret: $secret\r\n\r\n");
23         fputs($socket, "Action: Agents\r\n\r\n");
24         fputs($socket, "Action: Logoff\r\n\r\n");
25
26         while(!feof($socket)) {
27                 $info = fscanf($socket, "%s\t%s\r\n");
28                 switch($info[0]) {
29                         case "Agent:":
30                                 $curr_agent = $info[1];
31                                 $agents[$curr_agent] = array();
32                                 break;
33                         case "Name:":
34                                 $agents[$curr_agent]['Name'] = $info[1];
35                                 break;
36                         case "Status:":
37                                 $agents[$curr_agent]['Status'] = $better_status[$info[1]];
38                                 break;
39                         case "LoggedInChan:":
40                                 $agents[$curr_agent]['LoggedInChan'] = $info[1];
41                                 break;
42                         case "LoggedInTime:":
43                                 if($info[1] != "0") {
44                                         $agents[$curr_agent]['LoggedInTime'] = date("D, M d Y g:ia", $info[1]);
45                                 } else {
46                                         $agents[$curr_agent]['LoggedInTime'] = "n/a";
47                                 }
48                                 break;
49                         case "TalkingTo:":
50                                 $agents[$curr_agent]['TalkingTo'] = $info[1];
51                                 break;
52                         default:
53                                 break;
54                 }
55         }
56         fclose($socket);
57
58         print "<html><head><title>Agents Status</title></head>\n<body>\n";
59         print "<table width=\"800px\" border=\"1\">\n";
60         print "  <tr><th>Agent #</th><th>Agent Name</th><th>Agent Location</th><th>Agent Status</th><th>Agent Talking To</th><th>Agent Login Time</th></tr>\n";
61
62         foreach( $agents as $agent=>$curr ) {
63                 print "  <tr>\n    <td>" . $agent . "</td>\n";
64                 print "    <td>" . $curr['Name'] . "</td>\n";
65                 print "    <td>" . $curr['LoggedInChan'] . "</td>\n";
66                 print "    <td>" . $curr['Status'] . "</td>\n";
67                 print "    <td>" . $curr['TalkingTo'] . "</td>\n";
68                 print "    <td>" . $curr['LoggedInTime'] . "</td>\n  </tr>\n";
69         }
70
71         print "</table>\n</body>\n</html>\n";
72 }
73 ?>