v_fifo_agents_edit.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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("admin") || if_group("superadmin")) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //action add or update
  32. if (isset($_REQUEST["id"])) {
  33. $action = "update";
  34. $fifo_agent_id = check_str($_REQUEST["id"]);
  35. }
  36. else {
  37. $action = "add";
  38. }
  39. //get http post variables and set them to php variables
  40. if (count($_POST)>0) {
  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_last_uuid = check_str($_POST["agent_last_uuid"]);
  47. $agent_contact_number = check_str($_POST["agent_contact_number"]);
  48. }
  49. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  50. $msg = '';
  51. ////recommend moving this to the config.php file
  52. $uploadtempdir = $_ENV["TEMP"]."\\";
  53. ini_set('upload_tmp_dir', $uploadtempdir);
  54. ////$imagedir = $_ENV["TEMP"]."\\";
  55. ////$filedir = $_ENV["TEMP"]."\\";
  56. if ($action == "update") {
  57. $fifo_agent_id = check_str($_POST["fifo_agent_id"]);
  58. }
  59. //check for all required data
  60. if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
  61. if (strlen($fifo_name) == 0) { $msg .= "Please provide: Queue Name<br>\n"; }
  62. if (strlen($agent_username) == 0) { $msg .= "Please provide: Username<br>\n"; }
  63. if (strlen($agent_priority) == 0) { $msg .= "Please provide: Agent Priority<br>\n"; }
  64. if (strlen($agent_status) == 0) { $msg .= "Please provide: Status<br>\n"; }
  65. //if (strlen($agent_last_call) == 0) { $msg .= "Please provide: Last Call<br>\n"; }
  66. //if (strlen($agent_last_uuid) == 0) { $msg .= "Please provide: Last UUID<br>\n"; }
  67. //if (strlen($agent_contact_number) == 0) { $msg .= "Please provide: Contact Number<br>\n"; }
  68. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  69. require_once "resources/header.php";
  70. require_once "resources/persist_form_var.php";
  71. echo "<div align='center'>\n";
  72. echo "<table><tr><td>\n";
  73. echo $msg."<br />";
  74. echo "</td></tr></table>\n";
  75. persistformvar($_POST);
  76. echo "</div>\n";
  77. require_once "resources/footer.php";
  78. return;
  79. }
  80. //Add or update the database
  81. if ($_POST["persistformvar"] != "true") {
  82. if ($action == "add") {
  83. $sql = "insert into v_fifo_agents ";
  84. $sql .= "(";
  85. $sql .= "domain_uuid, ";
  86. $sql .= "fifo_name, ";
  87. $sql .= "agent_username, ";
  88. $sql .= "agent_priority, ";
  89. $sql .= "agent_status, ";
  90. $sql .= "agent_last_call, ";
  91. $sql .= "agent_last_uuid, ";
  92. $sql .= "agent_contact_number ";
  93. $sql .= ")";
  94. $sql .= "values ";
  95. $sql .= "(";
  96. $sql .= "'$domain_uuid', ";
  97. $sql .= "'$fifo_name', ";
  98. $sql .= "'$agent_username', ";
  99. $sql .= "'$agent_priority', ";
  100. $sql .= "'$agent_status', ";
  101. $sql .= "'$agent_last_call', ";
  102. $sql .= "'$agent_last_uuid', ";
  103. $sql .= "'$agent_contact_number' ";
  104. $sql .= ")";
  105. $db->exec(check_sql($sql));
  106. unset($sql);
  107. require_once "resources/header.php";
  108. echo "<meta http-equiv=\"refresh\" content=\"2;url=v_fifo_agents.php\">\n";
  109. echo "<div align='center'>\n";
  110. echo "Add Complete\n";
  111. echo "</div>\n";
  112. require_once "resources/footer.php";
  113. return;
  114. } //if ($action == "add")
  115. if ($action == "update") {
  116. $sql = "update v_fifo_agents set ";
  117. $sql .= "domain_uuid = '$domain_uuid', ";
  118. $sql .= "fifo_name = '$fifo_name', ";
  119. $sql .= "agent_username = '$agent_username', ";
  120. $sql .= "agent_priority = '$agent_priority', ";
  121. $sql .= "agent_status = '$agent_status', ";
  122. $sql .= "agent_status_epoch = ".time()." ";
  123. $sql .= "agent_last_call = '$agent_last_call', ";
  124. $sql .= "agent_last_uuid = '$agent_last_uuid', ";
  125. $sql .= "agent_contact_number = '$agent_contact_number' ";
  126. $sql .= "where fifo_agent_id = '$fifo_agent_id'";
  127. $db->exec(check_sql($sql));
  128. unset($sql);
  129. require_once "resources/header.php";
  130. echo "<meta http-equiv=\"refresh\" content=\"2;url=v_fifo_agents.php\">\n";
  131. echo "<div align='center'>\n";
  132. echo "Update Complete\n";
  133. echo "</div>\n";
  134. require_once "resources/footer.php";
  135. return;
  136. } //if ($action == "update")
  137. } //if ($_POST["persistformvar"] != "true")
  138. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  139. //pre-populate the form
  140. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  141. $fifo_agent_id = $_GET["id"];
  142. $sql = "";
  143. $sql .= "select * from v_fifo_agents ";
  144. $sql .= "where fifo_agent_id = '$fifo_agent_id' ";
  145. $prep_statement = $db->prepare(check_sql($sql));
  146. $prep_statement->execute();
  147. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  148. foreach ($result as &$row) {
  149. $fifo_name = $row["fifo_name"];
  150. $agent_username = $row["agent_username"];
  151. $agent_priority = $row["agent_priority"];
  152. $agent_status = $row["agent_status"];
  153. $agent_last_call = $row["agent_last_call"];
  154. $agent_last_uuid = $row["agent_last_uuid"];
  155. $agent_contact_number = $row["agent_contact_number"];
  156. break; //limit to 1 row
  157. }
  158. unset ($prep_statement);
  159. }
  160. //send the content to the browser
  161. require_once "resources/header.php";
  162. echo "<div align='center'>";
  163. echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
  164. echo "<tr class='border'>\n";
  165. echo " <td align=\"left\">\n";
  166. echo " <br>";
  167. echo "<form method='post' name='frm' action=''>\n";
  168. echo "<div align='center'>\n";
  169. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  170. echo "<tr>\n";
  171. if ($action == "add") {
  172. echo "<td align='left' width='30%' nowrap='nowrap' align='left'><b>Agent Login</b></td>\n";
  173. }
  174. if ($action == "update") {
  175. echo "<td align='left' width='30%' nowrap='nowrap' align='left'><b>Fifo Agent Edit</b></td>\n";
  176. }
  177. echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='v_fifo_agents.php'\" value='Back'></td>\n";
  178. echo "</tr>\n";
  179. echo "<tr>\n";
  180. echo "<td colspan='2' align='left'>\n";
  181. echo "List the agents assigned to a Queue.<br /><br />\n";
  182. echo "</td>\n";
  183. echo "</tr>\n";
  184. echo "<tr>\n";
  185. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  186. echo " Queue Name:\n";
  187. echo "</td>\n";
  188. echo "<td class='vtable' align='left'>\n";
  189. //echo " <input class='formfld' type='text' name='fifo_name' maxlength='255' value=\"$fifo_name\">\n";
  190. //generate the fifo name select list
  191. $sql = "";
  192. $sql .= "select * from v_dialplan_details ";
  193. $sql .= "where domain_uuid = '$domain_uuid' ";
  194. $prep_statement = $db->prepare(check_sql($sql));
  195. $prep_statement->execute();
  196. $x = 0;
  197. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  198. echo "<select name=\"fifo_name\" class='formfld'>\n";
  199. echo "<option value=\"\"></option>\n";
  200. foreach ($result as &$row) {
  201. if ($row["dialplan_detail_type"] == "fifo") {
  202. //if (strpos($row["dialplan_detail_data"], '@${domain_name} in') !== false) {
  203. //echo "rtrim(".$row["dialplan_detail_data"].", ' in') == ".$fifo_name."<br />";
  204. if (rtrim($row["dialplan_detail_data"], " in") == $fifo_name) {
  205. echo " <option value='".rtrim($row["dialplan_detail_data"], " in")."' selected='selected'>".rtrim($row["dialplan_detail_data"], " in")."</option>\n";
  206. }
  207. else {
  208. echo " <option value='".rtrim($row["dialplan_detail_data"], " in")."'>".rtrim($row["dialplan_detail_data"], " in")."</option>\n";
  209. }
  210. //}
  211. }
  212. }
  213. echo "</select>\n";
  214. unset ($prep_statement);
  215. echo "<br />\n";
  216. echo "Select the queue name.\n";
  217. echo "</td>\n";
  218. echo "</tr>\n";
  219. echo "<tr>\n";
  220. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  221. echo " Username:\n";
  222. echo "</td>\n";
  223. echo "<td class='vtable' align='left'>\n";
  224. //echo " <input class='formfld' type='text' name='agent_username' maxlength='255' value=\"$agent_username\">\n";
  225. //generate the user list
  226. $sql = "SELECT * FROM v_users ";
  227. $sql .= "where domain_uuid = '$domain_uuid' ";
  228. $sql .= "and user_enabled = 'true' ";
  229. $prep_statement = $db->prepare(check_sql($sql));
  230. $prep_statement->execute();
  231. echo "<select name=\"agent_username\" class='formfld'>\n";
  232. echo "<option value=\"\"></option>\n";
  233. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  234. foreach($result as $field) {
  235. if ($agent_username == $field[username]) {
  236. echo "<option value='".$field[username]."' selected='selected'>".$field[username]."</option>\n";
  237. }
  238. else {
  239. echo "<option value='".$field[username]."'>".$field[username]."</option>\n";
  240. }
  241. }
  242. echo "</select>";
  243. unset($sql, $result);
  244. echo "<br />\n";
  245. echo "Select the username.\n";
  246. echo "</td>\n";
  247. echo "</tr>\n";
  248. echo "<tr>\n";
  249. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  250. echo " Agent Priority:\n";
  251. echo "</td>\n";
  252. echo "<td class='vtable' align='left'>\n";
  253. echo " <select class='formfld' name='agent_priority'>\n";
  254. echo " <option value=''></option>\n";
  255. if ($agent_priority == "0") {
  256. echo " <option value='0' SELECTED >0</option>\n";
  257. }
  258. else {
  259. echo " <option value='0'>0</option>\n";
  260. }
  261. if ($agent_priority == "1") {
  262. echo " <option value='1' SELECTED >1</option>\n";
  263. }
  264. else {
  265. echo " <option value='1'>1</option>\n";
  266. }
  267. if ($agent_priority == "2") {
  268. echo " <option value='2' SELECTED >2</option>\n";
  269. }
  270. else {
  271. echo " <option value='2'>2</option>\n";
  272. }
  273. if ($agent_priority == "3") {
  274. echo " <option value='3' SELECTED >3</option>\n";
  275. }
  276. else {
  277. echo " <option value='3'>3</option>\n";
  278. }
  279. if ($agent_priority == "4") {
  280. echo " <option value='4' SELECTED >4</option>\n";
  281. }
  282. else {
  283. echo " <option value='4'>4</option>\n";
  284. }
  285. if ($agent_priority == "5") {
  286. echo " <option value='5' SELECTED >5</option>\n";
  287. }
  288. else {
  289. echo " <option value='5'>5</option>\n";
  290. }
  291. if ($agent_priority == "6") {
  292. echo " <option value='6' SELECTED >6</option>\n";
  293. }
  294. else {
  295. echo " <option value='6'>6</option>\n";
  296. }
  297. if ($agent_priority == "7") {
  298. echo " <option value='7' SELECTED >7</option>\n";
  299. }
  300. else {
  301. echo " <option value='7'>7</option>\n";
  302. }
  303. if ($agent_priority == "8") {
  304. echo " <option value='8' SELECTED >8</option>\n";
  305. }
  306. else {
  307. echo " <option value='8'>8</option>\n";
  308. }
  309. if ($agent_priority == "9") {
  310. echo " <option value='9' SELECTED >9</option>\n";
  311. }
  312. else {
  313. echo " <option value='9'>9</option>\n";
  314. }
  315. echo " </select>\n";
  316. echo "<br />\n";
  317. echo "Select a priority.\n";
  318. echo "</td>\n";
  319. echo "</tr>\n";
  320. echo "<tr>\n";
  321. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  322. echo " Status:\n";
  323. echo "</td>\n";
  324. echo "<td class='vtable' align='left'>\n";
  325. //generate the agent status select list
  326. $sql = "SELECT var_name, var_value FROM v_vars ";
  327. $sql .= "where domain_uuid = '$domain_uuid' ";
  328. $sql .= "and var_cat = 'Queues Agent Status' ";
  329. $prep_statement = $db->prepare(check_sql($sql));
  330. $prep_statement->execute();
  331. echo "<select name=\"agent_status\" class='formfld'>\n";
  332. echo "<option value=\"\"></option>\n";
  333. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  334. foreach($result as $field) {
  335. if ($field[var_value] == $agent_status) {
  336. echo "<option value='".$field[var_value]."' selected='selected'>".$field[var_name]."</option>\n";
  337. }
  338. else {
  339. echo "<option value='".$field[var_value]."'>".$field[var_name]."</option>\n";
  340. }
  341. }
  342. echo "</select>";
  343. /*
  344. foreach($result as $field) {
  345. $_SESSION["array_agent_status"][$field[var_value]] = $field[var_name];
  346. }
  347. $x=1;
  348. foreach($_SESSION["array_agent_status"] as $value) {
  349. echo "$x $value<br />\n";
  350. $x++;
  351. }
  352. */
  353. if (!is_array($_SESSION["array_agent_status"])) {
  354. echo "not an array";
  355. foreach($result as $field) {
  356. $_SESSION["array_agent_status"][$field[var_value]] = $field[var_name];
  357. }
  358. }
  359. else {
  360. //echo "is an array";
  361. //unset($_SESSION["array_agent_status"]);
  362. }
  363. unset($sql, $result);
  364. /*
  365. echo " <select class='formfld' name='agent_status'>\n";
  366. echo " <option value=''></option>\n";
  367. if ($agent_status == "busy") {
  368. echo " <option value='busy' SELECTED >busy</option>\n";
  369. }
  370. else {
  371. echo " <option value='busy'>busy</option>\n";
  372. }
  373. if ($agent_status == "break") {
  374. echo " <option value='break' SELECTED >break</option>\n";
  375. }
  376. else {
  377. echo " <option value='break'>break</option>\n";
  378. }
  379. if ($agent_status == "waiting") {
  380. echo " <option value='waiting' SELECTED >waiting</option>\n";
  381. }
  382. else {
  383. echo " <option value='waiting'>waiting</option>\n";
  384. }
  385. echo " </select>\n";
  386. */
  387. echo "<br />\n";
  388. echo "Enter the status of the Agent.\n";
  389. echo "</td>\n";
  390. echo "</tr>\n";
  391. echo "<tr>\n";
  392. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  393. echo " Last Call:\n";
  394. echo "</td>\n";
  395. echo "<td class='vtable' align='left'>\n";
  396. echo " <input class='formfld' type='text' name='agent_last_call' maxlength='255' value='$agent_last_call'>\n";
  397. echo "<br />\n";
  398. echo "\n";
  399. echo "</td>\n";
  400. echo "</tr>\n";
  401. echo "<tr>\n";
  402. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  403. echo " Last UUID:\n";
  404. echo "</td>\n";
  405. echo "<td class='vtable' align='left'>\n";
  406. echo " <input class='formfld' type='text' name='agent_last_uuid' maxlength='255' value=\"$agent_last_uuid\">\n";
  407. echo "<br />\n";
  408. echo "Enter the UUID for the last call.\n";
  409. echo "</td>\n";
  410. echo "</tr>\n";
  411. echo "<tr>\n";
  412. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  413. echo " Contact Number:\n";
  414. echo "</td>\n";
  415. echo "<td class='vtable' align='left'>\n";
  416. echo " <input class='formfld' type='text' name='agent_contact_number' maxlength='255' value='$agent_contact_number'>\n";
  417. echo "<br />\n";
  418. echo "Enter the agent contact number.\n";
  419. echo "</td>\n";
  420. echo "</tr>\n";
  421. echo " <tr>\n";
  422. echo " <td colspan='2' align='right'>\n";
  423. if ($action == "update") {
  424. echo " <input type='hidden' name='fifo_agent_id' value='$fifo_agent_id'>\n";
  425. }
  426. echo " <input type='submit' name='submit' class='btn' value='Save'>\n";
  427. echo " </td>\n";
  428. echo " </tr>";
  429. echo "</table>";
  430. echo "</form>";
  431. echo " </td>";
  432. echo " </tr>";
  433. echo "</table>";
  434. echo "</div>";
  435. require_once "resources/footer.php";
  436. ?>