v_fifo_agent_login.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 "includes/require.php";
  23. require_once "includes/checkauth.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. //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. //POST to PHP variables
  40. if (count($_POST)>0) {
  41. //$fifo_name = check_str($_POST["fifo_name"]);
  42. $fifo_agent_profile_id = check_str($_POST["fifo_agent_profile_id"]);
  43. $agent_username = $_SESSION["username"];
  44. $agent_contact_number = check_str($_POST["agent_contact_number"]);
  45. }
  46. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  47. $msg = '';
  48. ////recommend moving this to the config.php file
  49. $uploadtempdir = $_ENV["TEMP"]."\\";
  50. ini_set('upload_tmp_dir', $uploadtempdir);
  51. ////$imagedir = $_ENV["TEMP"]."\\";
  52. ////$filedir = $_ENV["TEMP"]."\\";
  53. if ($action == "update") {
  54. $fifo_agent_id = check_str($_POST["fifo_agent_id"]);
  55. }
  56. //check for all required data
  57. if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
  58. if (strlen($fifo_agent_profile_id) == 0) { $msg .= "Please provide: profile<br>\n"; }
  59. //if (strlen($fifo_name) == 0) { $msg .= "Please provide: Queue Name<br>\n"; }
  60. //if (strlen($agent_username) == 0) { $msg .= "Please provide: Username<br>\n"; }
  61. //if (strlen($agent_priority) == 0) { $msg .= "Please provide: Agent Priority<br>\n"; }
  62. if (strlen($agent_contact_number) == 0) { $msg .= "Please provide: Contact Number<br>\n"; }
  63. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  64. require_once "includes/header.php";
  65. require_once "includes/persistformvar.php";
  66. echo "<div align='center'>\n";
  67. echo "<table><tr><td>\n";
  68. echo $msg."<br />";
  69. echo "</td></tr></table>\n";
  70. persistformvar($_POST);
  71. echo "</div>\n";
  72. require_once "includes/footer.php";
  73. return;
  74. }
  75. //add or update the database
  76. if ($_POST["persistformvar"] != "true") {
  77. if ($action == "add") {
  78. $fifo_agent_profile_member_id = $_GET["id"];
  79. $sql = "";
  80. $sql .= "select * from v_fifo_agent_profile_members ";
  81. $sql .= "where domain_uuid = '$domain_uuid' ";
  82. $sql .= "and fifo_agent_profile_id = '$fifo_agent_profile_id' ";
  83. $sql .= "and agent_username = '$agent_username' ";
  84. $prep_statement = $db->prepare(check_sql($sql));
  85. $prep_statement->execute();
  86. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  87. foreach ($result as &$row) {
  88. $fifo_agent_profile_member_id = $row["fifo_agent_profile_member_id"];
  89. $fifo_agent_profile_id = $row["fifo_agent_profile_id"];
  90. $fifo_name = $row["fifo_name"];
  91. $agent_priority = $row["agent_priority"];
  92. $agent_status = '2'; //available
  93. $agent_last_call = 0;
  94. $sql = "insert into v_fifo_agents ";
  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_status_epoch, ";
  102. $sql .= "agent_last_call, ";
  103. $sql .= "agent_contact_number ";
  104. $sql .= ")";
  105. $sql .= "values ";
  106. $sql .= "(";
  107. $sql .= "'$domain_uuid', ";
  108. $sql .= "'$fifo_name', ";
  109. $sql .= "'$agent_username', ";
  110. $sql .= "'$agent_priority', ";
  111. $sql .= "'$agent_status', ";
  112. $sql .= "'".time()."', ";
  113. $sql .= "'$agent_last_call', ";
  114. $sql .= "'$agent_contact_number' ";
  115. $sql .= ")";
  116. $db->exec(check_sql($sql));
  117. unset($sql);
  118. //agent status log login
  119. $agent_status = '1'; //login
  120. $sql = "insert into v_fifo_agent_status_logs ";
  121. $sql .= "(";
  122. $sql .= "domain_uuid, ";
  123. $sql .= "username, ";
  124. $sql .= "agent_status, ";
  125. $sql .= "add_date ";
  126. $sql .= ")";
  127. $sql .= "values ";
  128. $sql .= "(";
  129. $sql .= "'$domain_uuid', ";
  130. $sql .= "'".$_SESSION["username"]."', ";
  131. $sql .= "'$agent_status', ";
  132. $sql .= "now() ";
  133. $sql .= ")";
  134. $db->exec(check_sql($sql));
  135. unset($sql);
  136. }
  137. unset ($prep_statement);
  138. require_once "includes/header.php";
  139. echo "<meta http-equiv=\"refresh\" content=\"2;url=v_fifo_agent_edit.php\">\n";
  140. echo "<div align='center'>\n";
  141. echo "Login Complete\n";
  142. echo "</div>\n";
  143. require_once "includes/footer.php";
  144. return;
  145. } //if ($action == "add")
  146. /*
  147. if ($action == "update") {
  148. $sql = "update v_fifo_agents set ";
  149. $sql .= "domain_uuid = '$domain_uuid', ";
  150. $sql .= "fifo_name = '$fifo_name', ";
  151. $sql .= "agent_username = '$agent_username', ";
  152. $sql .= "agent_priority = '$agent_priority', ";
  153. $sql .= "agent_contact_number = '$agent_contact_number' ";
  154. $sql .= "where fifo_agent_id = '$fifo_agent_id'";
  155. $db->exec(check_sql($sql));
  156. unset($sql);
  157. require_once "includes/header.php";
  158. echo "<meta http-equiv=\"refresh\" content=\"2;url=v_fifo_agents.php\">\n";
  159. echo "<div align='center'>\n";
  160. echo "Update Complete\n";
  161. echo "</div>\n";
  162. require_once "includes/footer.php";
  163. return;
  164. } //if ($action == "update")
  165. */
  166. } //if ($_POST["persistformvar"] != "true")
  167. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  168. //pre-populate the form
  169. /*
  170. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  171. $fifo_agent_id = $_GET["id"];
  172. $sql = "";
  173. $sql .= "select * from v_fifo_agents ";
  174. $sql .= "where fifo_agent_id = '$fifo_agent_id' ";
  175. $prep_statement = $db->prepare(check_sql($sql));
  176. $prep_statement->execute();
  177. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  178. foreach ($result as &$row) {
  179. $domain_uuid = $row["domain_uuid"];
  180. $fifo_name = $row["fifo_name"];
  181. $agent_username = $row["agent_username"];
  182. $agent_priority = $row["agent_priority"];
  183. $agent_contact_number = $row["agent_contact_number"];
  184. break; //limit to 1 row
  185. }
  186. unset ($prep_statement);
  187. }
  188. */
  189. //begin the content
  190. require_once "includes/header.php";
  191. echo "<div align='center'>";
  192. echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
  193. echo "<tr class='border'>\n";
  194. echo " <td align=\"left\">\n";
  195. echo " <br>";
  196. echo "<form method='post' name='frm' action=''>\n";
  197. echo "<div align='center'>\n";
  198. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  199. echo "<tr>\n";
  200. if ($action == "add") {
  201. echo "<td align='left' width='30%' nowrap><b>Agent Login</b></td>\n";
  202. }
  203. //if ($action == "update") {
  204. // echo "<td align='left' width='30%' nowrap><b>Agent Login</b></td>\n";
  205. //}
  206. 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";
  207. echo "</tr>\n";
  208. echo "<tr>\n";
  209. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  210. echo " Profile Name:\n";
  211. echo "</td>\n";
  212. echo "<td class='vtable' align='left'>\n";
  213. $sql = "";
  214. $sql .= "select * from v_fifo_agent_profiles ";
  215. $sql .= "where domain_uuid = '$domain_uuid' ";
  216. //$sql .= "and fifo_agent_profile_id = '$fifo_agent_profile_id' ";
  217. $prep_statement = $db->prepare(check_sql($sql));
  218. $prep_statement->execute();
  219. $x = 0;
  220. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  221. echo "<select name=\"fifo_agent_profile_id\" class='formfld'>\n";
  222. echo "<option value=\"\"></option>\n";
  223. foreach ($result as &$row) {
  224. $domain_uuid = $row["domain_uuid"];
  225. $profile_name = $row["profile_name"];
  226. $profile_desc = $row["profile_desc"];
  227. if ($row["fifo_agent_profile_id"] == $fifo_agent_profile_id) {
  228. echo " <option value='".$row["fifo_agent_profile_id"]."' selected='selected'>".$row["profile_name"]."</option>\n";
  229. }
  230. else {
  231. echo " <option value='".$row["fifo_agent_profile_id"]."'>".$row["profile_name"]."</option>\n";
  232. }
  233. }
  234. echo "</select>\n";
  235. unset ($prep_statement);
  236. echo "<tr>\n";
  237. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  238. echo " Contact Number:\n";
  239. echo "</td>\n";
  240. echo "<td class='vtable' align='left'>\n";
  241. echo " <input class='formfld' type='text' name='agent_contact_number' maxlength='255' value=\"$agent_contact_number\">\n";
  242. echo "<br />\n";
  243. echo "Enter the agent contact number.\n";
  244. echo "</td>\n";
  245. echo "</tr>\n";
  246. echo " <tr>\n";
  247. echo " <td colspan='2' align='right'>\n";
  248. //if ($action == "update") {
  249. // echo " <input type='hidden' name='fifo_agent_id' value='$fifo_agent_id'>\n";
  250. //}
  251. echo " <input type='submit' name='submit' class='btn' value='Login'>\n";
  252. echo " </td>\n";
  253. echo " </tr>";
  254. echo "</table>";
  255. echo "</form>";
  256. echo " </td>";
  257. echo " </tr>";
  258. echo "</table>";
  259. echo "</div>";
  260. require_once "includes/footer.php";
  261. ?>