v_fifo_agent_edit.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Copyright (C) 2010
  17. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. require_once "root.php";
  22. require_once "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (if_group("agent") || if_group("admin") || if_group("superadmin")) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //save the uuid to a variable from the http GET
  32. $uuid = check_str($_GET["uuid"]);
  33. //POST to PHP variables
  34. if (count($_POST)>0) {
  35. //$domain_uuid = check_str($_POST["domain_uuid"]);
  36. $resolution_code = check_str($_POST["resolution_code"]);
  37. $transaction_id = check_str($_POST["transaction_id"]);
  38. $action_item = check_str($_POST["action_item"]);
  39. $uuid = check_str($_POST["uuid"]);
  40. $notes = check_str($_POST["notes"]);
  41. //$fifo_name = check_str($_POST["fifo_name"]);
  42. //$agent_username = check_str($_POST["agent_username"]);
  43. //$agent_priority = check_str($_POST["agent_priority"]);
  44. $agent_status = check_str($_POST["agent_status"]);
  45. //$agent_last_call = check_str($_POST["agent_last_call"]);
  46. //$agent_contact_number = check_str($_POST["agent_contact_number"]);
  47. }
  48. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  49. $msg = '';
  50. //check for all required data
  51. if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
  52. //if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
  53. //if (strlen($resolution_code) == 0) { $msg .= "Please provide: Resolution Code<br>\n"; }
  54. //if (strlen($transaction_id) == 0) { $msg .= "Please provide: Transaction ID<br>\n"; }
  55. //if (strlen($action_item) == 0) { $msg .= "Please provide: Action Item<br>\n"; }
  56. //if (strlen($uuid) == 0) { $msg .= "Please provide: UUID<br>\n"; }
  57. //if (strlen($notes) == 0) { $msg .= "Please provide: Notes<br>\n"; }
  58. //if (strlen($fifo_name) == 0) { $msg .= "Please provide: Queue Name<br>\n"; }
  59. //if (strlen($agent_username) == 0) { $msg .= "Please provide: Username<br>\n"; }
  60. //if (strlen($agent_priority) == 0) { $msg .= "Please provide: Agent Priority<br>\n"; }
  61. if (strlen($agent_status) == 0) { $msg .= "Please provide: Status<br>\n"; }
  62. //if (strlen($agent_last_call) == 0) { $msg .= "Please provide: Last Call<br>\n"; }
  63. //if (strlen($agent_contact_number) == 0) { $msg .= "Please provide: Contact Number<br>\n"; }
  64. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  65. require_once "resources/header.php";
  66. require_once "resources/persist_form_var.php";
  67. echo "<div align='center'>\n";
  68. echo "<table><tr><td>\n";
  69. echo $msg."<br />";
  70. echo "</td></tr></table>\n";
  71. persistformvar($_POST);
  72. echo "</div>\n";
  73. require_once "resources/footer.php";
  74. return;
  75. }
  76. //update the database
  77. if ($_POST["persistformvar"] != "true") {
  78. //do not insert {uuid} into the database
  79. if ($uuid == "{uuid}") { $uuid = ''; }
  80. //add to the agent call logs
  81. if (strlen($uuid) > 0) {
  82. $sql = "insert into v_fifo_agent_call_logs ";
  83. $sql .= "(";
  84. $sql .= "domain_uuid, ";
  85. $sql .= "resolution_code, ";
  86. $sql .= "transaction_id, ";
  87. $sql .= "action_item, ";
  88. $sql .= "uuid, ";
  89. $sql .= "notes, ";
  90. $sql .= "add_user, ";
  91. $sql .= "add_date ";
  92. $sql .= ")";
  93. $sql .= "values ";
  94. $sql .= "(";
  95. $sql .= "'$domain_uuid', ";
  96. $sql .= "'$resolution_code', ";
  97. $sql .= "'$transaction_id', ";
  98. $sql .= "'$action_item', ";
  99. $sql .= "'$uuid', ";
  100. $sql .= "'$notes', ";
  101. $sql .= "'".$_SESSION["username"]."', ";
  102. $sql .= "now() ";
  103. $sql .= ")";
  104. $db->exec(check_sql($sql));
  105. unset($sql);
  106. }
  107. //update the status
  108. $sql = "update v_fifo_agents set ";
  109. $sql .= "domain_uuid = '$domain_uuid', ";
  110. //$sql .= "fifo_name = '$fifo_name', ";
  111. //$sql .= "agent_username = '$agent_username', ";
  112. //$sql .= "agent_priority = '$agent_priority', ";
  113. $sql .= "agent_status = '$agent_status', ";
  114. $sql .= "agent_status_epoch = ".time()." ";
  115. //$sql .= "agent_last_call = '$agent_last_call', ";
  116. //$sql .= "agent_contact_number = '$agent_contact_number' ";
  117. $sql .= " where agent_username = '".$_SESSION["username"]."' ";
  118. $db->exec(check_sql($sql));
  119. unset($sql);
  120. //agent status log
  121. if (strlen($agent_status) > 0) {
  122. $sql = "insert into v_fifo_agent_status_logs ";
  123. $sql .= "(";
  124. $sql .= "domain_uuid, ";
  125. $sql .= "username, ";
  126. $sql .= "agent_status, ";
  127. $sql .= "uuid, ";
  128. $sql .= "add_date ";
  129. $sql .= ")";
  130. $sql .= "values ";
  131. $sql .= "(";
  132. $sql .= "'$domain_uuid', ";
  133. $sql .= "'".$_SESSION["username"]."', ";
  134. $sql .= "'$agent_status', ";
  135. $sql .= "'$uuid', ";
  136. $sql .= "now() ";
  137. $sql .= ")";
  138. $db->exec(check_sql($sql));
  139. unset($sql);
  140. }
  141. require_once "resources/header.php";
  142. echo "<meta http-equiv=\"refresh\" content=\"2;url=v_fifo_agent_edit.php\">\n";
  143. echo "<div align='center'>\n";
  144. echo "Update Complete\n";
  145. echo "</div>\n";
  146. require_once "resources/footer.php";
  147. return;
  148. } //if ($_POST["persistformvar"] != "true") {
  149. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  150. //pre-populate the form
  151. if ($_POST["persistformvar"] != "true") {
  152. $login_status = false;
  153. $sql = "";
  154. $sql .= "select * from v_fifo_agents ";
  155. $sql .= " where agent_username = '".$_SESSION["username"]."' ";
  156. $prep_statement = $db->prepare(check_sql($sql));
  157. $prep_statement->execute();
  158. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  159. foreach ($result as &$row) {
  160. $domain_uuid = $row["domain_uuid"];
  161. //$fifo_name = $row["fifo_name"];
  162. //$agent_username = $row["agent_username"];
  163. //$agent_priority = $row["agent_priority"];
  164. $agent_status = $row["agent_status"];
  165. $agent_last_call = $row["agent_last_call"];
  166. $agent_last_uuid = $row["agent_last_uuid"];
  167. //$agent_contact_number = $row["agent_contact_number"];
  168. $login_status = true;
  169. break; //limit to 1 row
  170. }
  171. unset ($prep_statement);
  172. }
  173. //format the last call time
  174. if ($agent_last_call == 0) {
  175. $agent_last_call_desc = '';
  176. }
  177. else {
  178. $agent_last_call_desc = date("g:i:s a j M Y",$agent_last_call);
  179. }
  180. //show the content
  181. require_once "resources/header.php";
  182. //if the agent_status is available and the uuid has been supplied then refrsh the page
  183. //until the status changes or until a time out has been reached
  184. if ($agent_status == '2' && strlen($uuid) > 0 && $uuid != "{uuid}") {
  185. if (count($_GET["refresh"]) < 10) {
  186. if (substr($_SERVER["SERVER_PROTOCOL"], 0,5) == "HTTP/") {
  187. $meta_refresh_url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]."&refresh[]=".count($_SERVER["refresh"]);
  188. }
  189. else {
  190. $meta_refresh_url = "https://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]."&refresh[]=".count($_SERVER["refresh"]);
  191. }
  192. echo "<meta http-equiv=\"refresh\" content=\"1;URL=".$meta_refresh_url."\">\n";
  193. }
  194. }
  195. echo "<div align='center'>";
  196. echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
  197. echo "<tr class='border'>\n";
  198. echo " <td align=\"left\">\n";
  199. //echo " <br>";
  200. echo "<form method='post' name='frm' action=''>\n";
  201. echo "<div align='center'>\n";
  202. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  203. echo "<tr>\n";
  204. echo "<td align='left' width='30%' nowrap='nowrap' align='left'><b>Agent</b></td>\n";
  205. echo "<td width='70%' align='right'>\n";
  206. if (!$login_status) {
  207. echo " <input type='button' class='btn' name='' alt='login' onclick=\"window.location='v_fifo_agent_login.php'\" value='Login'>\n";
  208. }
  209. if ($login_status) {
  210. echo " <input type='button' class='btn' name='' alt='logout' onclick=\"window.location='v_fifo_agent_logout.php'\" value='Logout'>\n";
  211. }
  212. //echo " <input type='button' class='btn' name='' alt='back' onclick=\"window.location='v_fifo_agents.php'\" value='Back'>\n";
  213. echo "</td>\n";
  214. echo "</tr>\n";
  215. echo "<tr>\n";
  216. echo "<td align='left' colspan='2'>\n";
  217. echo "Enables the agent to set their status.<br /><br />\n";
  218. echo "</td>\n";
  219. echo "</tr>\n";
  220. echo "<tr>\n";
  221. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  222. echo " <strong>Username:</strong>\n";
  223. echo "</td>\n";
  224. echo "<td class='vtable' align='left'>\n";
  225. echo " <strong>".$_SESSION["username"]."</strong>";
  226. echo "<br />\n";
  227. echo "\n";
  228. echo "</td>\n";
  229. echo "</tr>\n";
  230. //echo "<tr>\n";
  231. //echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  232. //echo " <strong>Last Call:</strong>\n";
  233. //echo "</td>\n";
  234. //echo "<td class='vtable' align='left'>\n";
  235. //echo $agent_last_call_desc;
  236. //echo " <input class='formfld' type='text' name='agent_last_call' maxlength='255' value='$agent_last_call'>\n";
  237. //echo "<br />\n";
  238. //echo "\n";
  239. //echo "</td>\n";
  240. //echo "</tr>\n";
  241. if ($login_status) {
  242. echo "<tr>\n";
  243. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  244. echo " Status:\n";
  245. echo "</td>\n";
  246. echo "<td class='vtable' align='left'>\n";
  247. //generate the agent status select list
  248. $sql = "SELECT var_name, var_value FROM v_vars ";
  249. $sql .= "where domain_uuid = '$domain_uuid' ";
  250. $sql .= "and var_cat = 'Queues Agent Status' ";
  251. $sql .= "and var_name not like 'system%' ";
  252. $prep_statement = $db->prepare(check_sql($sql));
  253. $prep_statement->execute();
  254. echo "<select name=\"agent_status\" class='formfld'>\n";
  255. echo "<option value=\"\"></option>\n";
  256. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  257. foreach($result as $field) {
  258. if ($field[var_value] == $agent_status) {
  259. echo "<option value='".$field[var_value]."' selected='selected'>".$field[var_name]."</option>\n";
  260. }
  261. else {
  262. echo "<option value='".$field[var_value]."'>".$field[var_name]."</option>\n";
  263. }
  264. }
  265. echo "</select>";
  266. $_SESSION["array_agent_status"] = "";
  267. if (!is_array($_SESSION["array_agent_status"])) {
  268. foreach($result as $field) {
  269. $_SESSION["array_agent_status"][$field[var_value]] = $field[var_name];
  270. }
  271. }
  272. /*
  273. foreach($result as $field) {
  274. $_SESSION["array_agent_status"][$field[var_value]] = $field[var_name];
  275. }
  276. $x=1;
  277. foreach($_SESSION["array_agent_status"] as $value) {
  278. echo "$x $value<br />\n";
  279. $x++;
  280. }
  281. */
  282. unset($sql, $result);
  283. echo "<br />\n";
  284. echo "Enter the status of the Agent.\n";
  285. echo "</td>\n";
  286. echo "</tr>\n";
  287. echo "<tr>\n";
  288. echo "<td class='' valign='top' align='left' nowrap>\n";
  289. echo " &nbsp;\n";
  290. echo "</td>\n";
  291. echo "<td class='' align='left'>\n";
  292. echo "<br />\n";
  293. echo "</td>\n";
  294. echo "</tr>\n";
  295. }
  296. /*
  297. echo "<tr>\n";
  298. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  299. echo " Contact Number:\n";
  300. echo "</td>\n";
  301. echo "<td class='vtable' align='left'>\n";
  302. echo $agent_contact_number;
  303. //echo " <input class='formfld' type='text' name='agent_contact_number' maxlength='255' value='$agent_contact_number'>\n";
  304. echo "<br />\n";
  305. //echo "Enter the agent contact number.\n";
  306. echo "</td>\n";
  307. echo "</tr>\n";
  308. */
  309. if ($login_status && $agent_status == '9') {
  310. echo "<tr>\n";
  311. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  312. echo " Resolution Code:\n";
  313. echo "</td>\n";
  314. echo "<td class='vtable' align='left'>\n";
  315. echo " <input class='formfld' type='text' name='resolution_code' maxlength='255' value=\"$resolution_code\">\n";
  316. echo "<br />\n";
  317. echo "Enter the resolution code.\n";
  318. echo "</td>\n";
  319. echo "</tr>\n";
  320. echo "<tr>\n";
  321. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  322. echo " Transaction ID:\n";
  323. echo "</td>\n";
  324. echo "<td class='vtable' align='left'>\n";
  325. echo " <input class='formfld' type='text' name='transaction_id' maxlength='255' value=\"$transaction_id\">\n";
  326. echo "<br />\n";
  327. echo "Enter the Transaction ID.\n";
  328. echo "</td>\n";
  329. echo "</tr>\n";
  330. echo "<tr>\n";
  331. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  332. echo " Action Item:\n";
  333. echo "</td>\n";
  334. echo "<td class='vtable' align='left'>\n";
  335. echo " <input class='formfld' type='text' name='action_item' maxlength='255' value=\"$action_item\">\n";
  336. echo "<br />\n";
  337. echo "Enter the Action Item.\n";
  338. echo "</td>\n";
  339. echo "</tr>\n";
  340. echo "<tr>\n";
  341. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  342. echo " Notes:\n";
  343. echo "</td>\n";
  344. echo "<td class='vtable' align='left'>\n";
  345. echo " <textarea class='formfld' name='notes' rows='4'>$notes</textarea>\n";
  346. echo "<br />\n";
  347. echo "Enter the notes.\n";
  348. echo "</td>\n";
  349. echo "</tr>\n";
  350. }
  351. if ($login_status) {
  352. echo " <tr>\n";
  353. echo " <td colspan='2' align='right'>\n";
  354. if (strlen($uuid) == 0) {
  355. $uuid = $agent_last_uuid;
  356. }
  357. echo " <input type='hidden' name='uuid' value=\"$uuid\">\n";
  358. echo " <input type='submit' name='submit' class='btn' value='Save'>\n";
  359. echo " </td>\n";
  360. echo " </tr>";
  361. }
  362. echo "</table>";
  363. echo "</form>";
  364. echo " </td>";
  365. echo " </tr>";
  366. echo "</table>";
  367. echo "</div>";
  368. require_once "resources/footer.php";
  369. ?>