agents.php 2.1 KB

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