lib_cdr.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /*
  22. if ($db_type == "sqlite") {
  23. try {
  24. if (strlen($dbfilename) == 0) {
  25. //if (strlen($_SERVER["SERVER_NAME"]) == 0) { $_SERVER["SERVER_NAME"] = "http://localhost"; }
  26. $server_name = $_SERVER["SERVER_NAME"];
  27. $server_name = str_replace ("www.", "", $server_name);
  28. $server_name = str_replace ("example.net", "example.com", $server_name);
  29. //$server_name = str_replace (".", "_", $server_name);
  30. $dbfilenameshort = $server_name;
  31. $dbfilename = $server_name.'.db';
  32. }
  33. else {
  34. $dbfilenameshort = $dbfilename;
  35. }
  36. $db_file_path = str_replace("\\", "/", $db_file_path);
  37. if (file_exists($db_file_path.'/'.$dbfilename)) {
  38. //echo "main file exists<br>";
  39. }
  40. else { //file doese not exist
  41. //--- begin: create the sqlite db file -----------------------------------------
  42. $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
  43. $file_contents = file_get_contents($filename);
  44. //echo "<pre>\n";
  45. //echo $file_contents;
  46. //echo "</pre>\n";
  47. //exit;
  48. //replace \r\n with \n then explode on \n
  49. $file_contents = str_replace("\r\n", "\n", $file_contents);
  50. //loop line by line through all the lines of sql code
  51. $stringarray = explode("\n", $file_contents);
  52. $x = 0;
  53. foreach($stringarray as $sql) {
  54. //create the call detail records database
  55. if (strtolower(substr($sql, 0, 18)) == "create table v_cdr") {
  56. try {
  57. $dbcdr = new PDO('sqlite:'.$db_file_path.'/'.$dbfilenameshort.'.cdr.db'); //sqlite 3
  58. $dbcdr->query($sql);
  59. unset($dbcdr);
  60. }
  61. catch (PDOException $error) {
  62. print "error: " . $error->getMessage() . "<br/>";
  63. die();
  64. }
  65. }
  66. $x++;
  67. }
  68. unset ($file_contents, $sql);
  69. //--- end: create the sqlite db -----------------------------------------
  70. if (is_writable($db_file_path.'/'.$dbfilename)) { //is writable
  71. //use database in current location
  72. }
  73. else { //not writable
  74. echo "The database ".$db_file_path."/".$dbfilename." is not writeable2.";
  75. exit;
  76. }
  77. }
  78. unset($db);
  79. //$db = new PDO('sqlite::memory:'); //sqlite 3
  80. $db = new PDO('sqlite:'.$db_file_path.'/'.$dbfilenameshort.'.cdr.db'); //sqlite 3
  81. }
  82. catch (PDOException $error) {
  83. print "error: " . $error->getMessage() . "<br/>";
  84. die();
  85. }
  86. }
  87. */
  88. ?>