v_cdr_edit.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('cdr_csv_view')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. require_once "v_cdr_import.php";
  32. //action add or update
  33. if (isset($_REQUEST["id"])) {
  34. $action = "update";
  35. $cdr_id = check_str($_REQUEST["id"]);
  36. }
  37. else {
  38. $action = "add";
  39. }
  40. //POST to PHP variables
  41. if (count($_POST)>0) {
  42. $caller_id_name = check_str($_POST["caller_id_name"]);
  43. $caller_id_number = check_str($_POST["caller_id_number"]);
  44. $destination_number = check_str($_POST["destination_number"]);
  45. $context = check_str($_POST["context"]);
  46. $start_stamp = check_str($_POST["start_stamp"]);
  47. $answer_stamp = check_str($_POST["answer_stamp"]);
  48. $end_stamp = check_str($_POST["end_stamp"]);
  49. $duration = check_str($_POST["duration"]);
  50. $billsec = check_str($_POST["billsec"]);
  51. $hangup_cause = check_str($_POST["hangup_cause"]);
  52. $uuid = check_str($_POST["uuid"]);
  53. $bleg_uuid = check_str($_POST["bleg_uuid"]);
  54. $accountcode = check_str($_POST["accountcode"]);
  55. $read_codec = check_str($_POST["read_codec"]);
  56. $write_codec = check_str($_POST["write_codec"]);
  57. $remote_media_ip = check_str($_POST["remote_media_ip"]);
  58. $network_addr = check_str($_POST["network_addr"]);
  59. }
  60. /*
  61. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  62. $msg = '';
  63. ////recommend moving this to the config.php file
  64. $uploadtempdir = $_ENV["TEMP"]."\\";
  65. ini_set('upload_tmp_dir', $uploadtempdir);
  66. ////$imagedir = $_ENV["TEMP"]."\\";
  67. ////$filedir = $_ENV["TEMP"]."\\";
  68. if ($action == "update") {
  69. $cdr_id = check_str($_POST["cdr_id"]);
  70. }
  71. //check for all required data
  72. //if (strlen($caller_id_name) == 0) { $msg .= "Please provide: CID Name<br>\n"; }
  73. //if (strlen($caller_id_number) == 0) { $msg .= "Please provide: CID Number<br>\n"; }
  74. //if (strlen($destination_number) == 0) { $msg .= "Please provide: Destination<br>\n"; }
  75. //if (strlen($context) == 0) { $msg .= "Please provide: Context<br>\n"; }
  76. //if (strlen($start_stamp) == 0) { $msg .= "Please provide: Start<br>\n"; }
  77. //if (strlen($answer_stamp) == 0) { $msg .= "Please provide: Answer<br>\n"; }
  78. //if (strlen($end_stamp) == 0) { $msg .= "Please provide: End<br>\n"; }
  79. //if (strlen($duration) == 0) { $msg .= "Please provide: Duration<br>\n"; }
  80. //if (strlen($billsec) == 0) { $msg .= "Please provide: Bill Seconds<br>\n"; }
  81. //if (strlen($hangup_cause) == 0) { $msg .= "Please provide: Hangup Cause<br>\n"; }
  82. //if (strlen($uuid) == 0) { $msg .= "Please provide: UUID<br>\n"; }
  83. //if (strlen($bleg_uuid) == 0) { $msg .= "Please provide: Bleg UUID<br>\n"; }
  84. //if (strlen($accountcode) == 0) { $msg .= "Please provide: Account Code<br>\n"; }
  85. //if (strlen($read_codec) == 0) { $msg .= "Please provide: Read Codec<br>\n"; }
  86. //if (strlen($write_codec) == 0) { $msg .= "Please provide: Write Codec<br>\n"; }
  87. //if (strlen($remote_media_ip) == 0) { $msg .= "Please provide: Remote Media IP<br>\n"; }
  88. //if (strlen($network_addr) == 0) { $msg .= "Please provide: Network Addr<br>\n"; }
  89. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  90. require "resources/require.php";
  91. require_once "resources/header.php";
  92. require_once "resources/persist_form_var.php";
  93. echo "<div align='center'>\n";
  94. echo "<table><tr><td>\n";
  95. echo $msg."<br />";
  96. echo "</td></tr></table>\n";
  97. persistformvar($_POST);
  98. echo "</div>\n";
  99. require_once "resources/footer.php";
  100. return;
  101. }
  102. //add or update the database
  103. if ($_POST["persistformvar"] != "true") {
  104. if ($action == "add") {
  105. $sql = "insert into v_cdr ";
  106. $sql .= "(";
  107. $sql .= "domain_uuid, ";
  108. $sql .= "caller_id_name, ";
  109. $sql .= "caller_id_number, ";
  110. $sql .= "destination_number, ";
  111. $sql .= "context, ";
  112. $sql .= "start_stamp, ";
  113. $sql .= "answer_stamp, ";
  114. $sql .= "end_stamp, ";
  115. $sql .= "duration, ";
  116. $sql .= "billsec, ";
  117. $sql .= "hangup_cause, ";
  118. $sql .= "uuid, ";
  119. $sql .= "bleg_uuid, ";
  120. $sql .= "accountcode, ";
  121. $sql .= "read_codec, ";
  122. $sql .= "write_codec, ";
  123. $sql .= "remote_media_ip, ";
  124. $sql .= "network_addr ";
  125. $sql .= ")";
  126. $sql .= "values ";
  127. $sql .= "(";
  128. $sql .= "'$domain_uuid', ";
  129. $sql .= "'$caller_id_name', ";
  130. $sql .= "'$caller_id_number', ";
  131. $sql .= "'$destination_number', ";
  132. $sql .= "'$context', ";
  133. $sql .= "'$start_stamp', ";
  134. $sql .= "'$answer_stamp', ";
  135. $sql .= "'$end_stamp', ";
  136. $sql .= "'$duration', ";
  137. $sql .= "'$billsec', ";
  138. $sql .= "'$hangup_cause', ";
  139. $sql .= "'$uuid', ";
  140. $sql .= "'$bleg_uuid', ";
  141. $sql .= "'$accountcode', ";
  142. $sql .= "'$read_codec', ";
  143. $sql .= "'$write_codec', ";
  144. $sql .= "'$remote_media_ip', ";
  145. $sql .= "'$network_addr' ";
  146. $sql .= ")";
  147. $db->exec(check_sql($sql));
  148. unset($sql);
  149. require "resources/require.php";
  150. require_once "resources/header.php";
  151. echo "<meta http-equiv=\"refresh\" content=\"2;url=v_cdr.php\">\n";
  152. echo "<div align='center'>\n";
  153. echo "Add Complete\n";
  154. echo "</div>\n";
  155. require_once "resources/footer.php";
  156. return;
  157. } //if ($action == "add")
  158. if ($action == "update") {
  159. $sql = "update v_cdr set ";
  160. $sql .= "caller_id_name = '$caller_id_name', ";
  161. $sql .= "caller_id_number = '$caller_id_number', ";
  162. $sql .= "destination_number = '$destination_number', ";
  163. $sql .= "context = '$context', ";
  164. $sql .= "start_stamp = '$start_stamp', ";
  165. $sql .= "answer_stamp = '$answer_stamp', ";
  166. $sql .= "end_stamp = '$end_stamp', ";
  167. $sql .= "duration = '$duration', ";
  168. $sql .= "billsec = '$billsec', ";
  169. $sql .= "hangup_cause = '$hangup_cause', ";
  170. $sql .= "uuid = '$uuid', ";
  171. $sql .= "bleg_uuid = '$bleg_uuid', ";
  172. $sql .= "accountcode = '$accountcode', ";
  173. $sql .= "read_codec = '$read_codec', ";
  174. $sql .= "write_codec = '$write_codec', ";
  175. $sql .= "remote_media_ip = '$remote_media_ip', ";
  176. $sql .= "network_addr = '$network_addr' ";
  177. $sql .= "where domain_uuid = '$domain_uuid' ";
  178. $sql .= "and cdr_id = '$cdr_id' ";
  179. $db->exec(check_sql($sql));
  180. unset($sql);
  181. require "resources/require.php";
  182. require_once "resources/header.php";
  183. echo "<meta http-equiv=\"refresh\" content=\"2;url=v_cdr.php\">\n";
  184. echo "<div align='center'>\n";
  185. echo "Update Complete\n";
  186. echo "</div>\n";
  187. require_once "resources/footer.php";
  188. return;
  189. } //if ($action == "update")
  190. } //if ($_POST["persistformvar"] != "true") {
  191. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  192. */
  193. //pre-populate the form
  194. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  195. $cdr_id = $_GET["id"];
  196. $sql = "";
  197. $sql .= "select * from v_cdr ";
  198. if (!(if_group("admin") || if_group("superadmin"))) {
  199. if (trim($sql_where) == "where") { $sql_where = ""; }
  200. if (count($_SESSION['user']['extension']) > 0) {
  201. foreach ($_SESSION['user']['extension'] as &$row) {
  202. if ($row['user'] > 0) { $sql_where .= "or caller_id_number = '".$row['user']."' ". $sql_where_orig; } //source
  203. if ($row['user'] > 0) { $sql_where .= "or destination_number = '".$row['user']."' ".$sql_where_orig; } //destination
  204. if ($row['user'] > 0) { $sql_where .= "or destination_number = '*99".$row['user']."' ".$sql_where_orig; } //destination
  205. }
  206. }
  207. }
  208. else {
  209. $sql .= "where domain_uuid = '$domain_uuid' ";
  210. $sql .= "and cdr_id = '$cdr_id' ";
  211. }
  212. $sql_where = str_replace ("where or", "where", $sql_where);
  213. $sql_where = str_replace ("where and", "where", $sql_where);
  214. $sql .= $sql_where;
  215. $prep_statement = $db->prepare(check_sql($sql));
  216. $prep_statement->execute();
  217. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  218. foreach ($result as &$row) {
  219. $caller_id_name = $row["caller_id_name"];
  220. $caller_id_number = $row["caller_id_number"];
  221. $destination_number = $row["destination_number"];
  222. $context = $row["context"];
  223. $start_stamp = $row["start_stamp"];
  224. $answer_stamp = $row["answer_stamp"];
  225. $end_stamp = $row["end_stamp"];
  226. $duration = $row["duration"];
  227. $billsec = $row["billsec"];
  228. $hangup_cause = $row["hangup_cause"];
  229. $uuid = $row["uuid"];
  230. $bleg_uuid = $row["bleg_uuid"];
  231. $accountcode = $row["accountcode"];
  232. $read_codec = $row["read_codec"];
  233. $write_codec = $row["write_codec"];
  234. $remote_media_ip = $row["remote_media_ip"];
  235. $network_addr = $row["network_addr"];
  236. break; //limit to 1 row
  237. }
  238. unset ($prep_statement);
  239. }
  240. require "resources/require.php";
  241. require_once "resources/header.php";
  242. echo "<div align='center'>";
  243. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  244. echo "<tr class='border'>\n";
  245. echo " <td align=\"left\">\n";
  246. echo " <br>";
  247. echo "<form method='post' name='frm' action=''>\n";
  248. echo "<div align='center'>\n";
  249. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  250. echo "<tr>\n";
  251. if ($action == "add") {
  252. echo "<td align='left' width='30%' nowrap><b>Call Detail Records Add</b></td>\n";
  253. }
  254. if ($action == "update") {
  255. echo "<td align='left' width='30%' nowrap><b>Call Detail Records: Details</b></td>\n";
  256. }
  257. echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='v_cdr.php'\" value='Back'></td>\n";
  258. echo "</tr>\n";
  259. echo "<tr>\n";
  260. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  261. echo " CID Name:\n";
  262. echo "</td>\n";
  263. echo "<td class='vtable' align='left'>\n";
  264. echo " <input class='formfld' type='text' name='caller_id_name' maxlength='255' value=\"$caller_id_name\">\n";
  265. echo "<br />\n";
  266. echo "\n";
  267. echo "</td>\n";
  268. echo "</tr>\n";
  269. echo "<tr>\n";
  270. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  271. echo " CID Number:\n";
  272. echo "</td>\n";
  273. echo "<td class='vtable' align='left'>\n";
  274. echo " <input class='formfld' type='text' name='caller_id_number' maxlength='255' value=\"$caller_id_number\">\n";
  275. echo "<br />\n";
  276. echo "\n";
  277. echo "</td>\n";
  278. echo "</tr>\n";
  279. echo "<tr>\n";
  280. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  281. echo " Destination:\n";
  282. echo "</td>\n";
  283. echo "<td class='vtable' align='left'>\n";
  284. echo " <input class='formfld' type='text' name='destination_number' maxlength='255' value=\"$destination_number\">\n";
  285. echo "<br />\n";
  286. echo "\n";
  287. echo "</td>\n";
  288. echo "</tr>\n";
  289. echo "<tr>\n";
  290. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  291. echo " Context:\n";
  292. echo "</td>\n";
  293. echo "<td class='vtable' align='left'>\n";
  294. echo " <input class='formfld' type='text' name='context' maxlength='255' value=\"$context\">\n";
  295. echo "<br />\n";
  296. echo "\n";
  297. echo "</td>\n";
  298. echo "</tr>\n";
  299. echo "<tr>\n";
  300. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  301. echo " Start:\n";
  302. echo "</td>\n";
  303. echo "<td class='vtable' align='left'>\n";
  304. echo " <input class='formfld' type='text' name='start_stamp' maxlength='255' value=\"$start_stamp\">\n";
  305. echo "<br />\n";
  306. echo "\n";
  307. echo "</td>\n";
  308. echo "</tr>\n";
  309. echo "<tr>\n";
  310. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  311. echo " Answer:\n";
  312. echo "</td>\n";
  313. echo "<td class='vtable' align='left'>\n";
  314. echo " <input class='formfld' type='text' name='answer_stamp' maxlength='255' value=\"$answer_stamp\">\n";
  315. echo "<br />\n";
  316. echo "\n";
  317. echo "</td>\n";
  318. echo "</tr>\n";
  319. echo "<tr>\n";
  320. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  321. echo " End:\n";
  322. echo "</td>\n";
  323. echo "<td class='vtable' align='left'>\n";
  324. echo " <input class='formfld' type='text' name='end_stamp' maxlength='255' value=\"$end_stamp\">\n";
  325. echo "<br />\n";
  326. echo "\n";
  327. echo "</td>\n";
  328. echo "</tr>\n";
  329. echo "<tr>\n";
  330. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  331. echo " Duration:\n";
  332. echo "</td>\n";
  333. echo "<td class='vtable' align='left'>\n";
  334. echo " <input class='formfld' type='text' name='duration' maxlength='255' value=\"$duration\">\n";
  335. echo "<br />\n";
  336. echo "\n";
  337. echo "</td>\n";
  338. echo "</tr>\n";
  339. echo "<tr>\n";
  340. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  341. echo " Bill Seconds:\n";
  342. echo "</td>\n";
  343. echo "<td class='vtable' align='left'>\n";
  344. echo " <input class='formfld' type='text' name='billsec' maxlength='255' value=\"$billsec\">\n";
  345. echo "<br />\n";
  346. echo "\n";
  347. echo "</td>\n";
  348. echo "</tr>\n";
  349. echo "<tr>\n";
  350. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  351. echo " Hangup Cause:\n";
  352. echo "</td>\n";
  353. echo "<td class='vtable' align='left'>\n";
  354. echo " <input class='formfld' type='text' name='hangup_cause' maxlength='255' value=\"$hangup_cause\">\n";
  355. echo "<br />\n";
  356. echo "\n";
  357. echo "</td>\n";
  358. echo "</tr>\n";
  359. echo "<tr>\n";
  360. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  361. echo " UUID:\n";
  362. echo "</td>\n";
  363. echo "<td class='vtable' align='left'>\n";
  364. echo " <input class='formfld' type='text' name='uuid' maxlength='255' value=\"$uuid\">\n";
  365. echo "<br />\n";
  366. echo "\n";
  367. echo "</td>\n";
  368. echo "</tr>\n";
  369. echo "<tr>\n";
  370. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  371. echo " Bleg UUID:\n";
  372. echo "</td>\n";
  373. echo "<td class='vtable' align='left'>\n";
  374. echo " <input class='formfld' type='text' name='bleg_uuid' maxlength='255' value=\"$bleg_uuid\">\n";
  375. echo "<br />\n";
  376. echo "\n";
  377. echo "</td>\n";
  378. echo "</tr>\n";
  379. echo "<tr>\n";
  380. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  381. echo " Account Code:\n";
  382. echo "</td>\n";
  383. echo "<td class='vtable' align='left'>\n";
  384. echo " <input class='formfld' type='text' name='accountcode' maxlength='255' value=\"$accountcode\">\n";
  385. echo "<br />\n";
  386. echo "\n";
  387. echo "</td>\n";
  388. echo "</tr>\n";
  389. echo "<tr>\n";
  390. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  391. echo " Read Codec:\n";
  392. echo "</td>\n";
  393. echo "<td class='vtable' align='left'>\n";
  394. echo " <input class='formfld' type='text' name='read_codec' maxlength='255' value=\"$read_codec\">\n";
  395. echo "<br />\n";
  396. echo "\n";
  397. echo "</td>\n";
  398. echo "</tr>\n";
  399. echo "<tr>\n";
  400. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  401. echo " Write Codec:\n";
  402. echo "</td>\n";
  403. echo "<td class='vtable' align='left'>\n";
  404. echo " <input class='formfld' type='text' name='write_codec' maxlength='255' value=\"$write_codec\">\n";
  405. echo "<br />\n";
  406. echo "\n";
  407. echo "</td>\n";
  408. echo "</tr>\n";
  409. echo "<tr>\n";
  410. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  411. echo " Remote Media IP:\n";
  412. echo "</td>\n";
  413. echo "<td class='vtable' align='left'>\n";
  414. echo " <input class='formfld' type='text' name='remote_media_ip' maxlength='255' value=\"$remote_media_ip\">\n";
  415. echo "<br />\n";
  416. echo "\n";
  417. echo "</td>\n";
  418. echo "</tr>\n";
  419. echo "<tr>\n";
  420. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  421. echo " Network Addr:\n";
  422. echo "</td>\n";
  423. echo "<td class='vtable' align='left'>\n";
  424. echo " <input class='formfld' type='text' name='network_addr' maxlength='255' value=\"$network_addr\">\n";
  425. echo "<br />\n";
  426. echo "\n";
  427. echo "</td>\n";
  428. echo "</tr>\n";
  429. echo " <tr>\n";
  430. echo " <td colspan='2' align='right'>\n";
  431. if ($action == "update") {
  432. echo " <input type='hidden' name='cdr_id' value='$cdr_id'>\n";
  433. }
  434. //echo " <input type='submit' name='submit' class='btn' value='Save'>\n";
  435. echo " </td>\n";
  436. echo " </tr>";
  437. echo "</table>";
  438. echo "</form>";
  439. echo " </td>";
  440. echo " </tr>";
  441. echo "</table>";
  442. echo "</div>";
  443. require "resources/require.php";
  444. require_once "resources/footer.php";
  445. ?>