template_restore_default.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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-2010
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require_once "includes/config.php";
  23. require_once "includes/checkauth.php";
  24. if (ifgroup("superadmin")) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. return;
  30. }
  31. //remove the old menu
  32. $sql = "delete from v_templates ";
  33. $sql .= "where domain_uuid = '$domain_uuid' and templatename = 'default' ";
  34. $sql .= "or domain_uuid = '$domain_uuid' and templatename = 'horizontal' ";
  35. //echo $sql;
  36. $db->exec(check_sql($sql));
  37. //load the default database into a sqlite memory database
  38. $filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/includes/install/sql/sqlite.sql';
  39. $file_contents = file_get_contents($filename);
  40. unset($filename);
  41. try {
  42. //$db_default = new PDO('sqlite:'.$dbfilepath.'/'.$dbfilename); //sqlite 3
  43. $db_default = new PDO('sqlite::memory:'); //sqlite 3
  44. //$db_default->beginTransaction();
  45. }
  46. catch (PDOException $error) {
  47. print "error: " . $error->getMessage() . "<br/>";
  48. die();
  49. }
  50. //replace \r\n with \n then explode on \n
  51. $file_contents = str_replace("\r\n", "\n", $file_contents);
  52. //loop line by line through all the lines of sql code
  53. $stringarray = explode("\n", $file_contents);
  54. $x = 0;
  55. foreach($stringarray as $sql) {
  56. try {
  57. $db_default->query($sql);
  58. }
  59. catch (PDOException $error) {
  60. echo "error: " . $error->getMessage() . " sql: $sql<br/>";
  61. //die();
  62. }
  63. $x++;
  64. }
  65. unset ($file_contents, $sql);
  66. //$db_default->commit();
  67. //load the default menu into an array
  68. $sql = "";
  69. $sql .= "select * from v_templates ";
  70. $sql .= "where domain_uuid = '$domain_uuid' ";
  71. $prepstatement = $db_default->prepare(check_sql($sql));
  72. $prepstatement->execute();
  73. $menu_array = $prepstatement->fetchAll();
  74. //use the menu array to restore the default menu
  75. foreach ($menu_array as &$row) {
  76. $templateid = $row["templateid"];
  77. $templatelanguage = $row["templatelanguage"];
  78. $templatename = $row["templatename"];
  79. $templatedesc = $row["templatedesc"];
  80. $template = $row["template"];
  81. $templatemenutype = $row["templatemenutype"];
  82. $templatemenucss = $row["templatemenucss"];
  83. $template_default = $row["template_default"];
  84. //insert the defaul menu into the database
  85. $sql = "insert into v_templates ";
  86. $sql .= "(";
  87. $sql .= "domain_uuid, ";
  88. $sql .= "templateid, ";
  89. $sql .= "templatelanguage, ";
  90. $sql .= "templatename, ";
  91. $sql .= "templatedesc, ";
  92. $sql .= "template, ";
  93. $sql .= "templatemenutype, ";
  94. $sql .= "templatemenucss, ";
  95. $sql .= "template_default ";
  96. $sql .= ")";
  97. $sql .= "values ";
  98. $sql .= "(";
  99. $sql .= "'$domain_uuid', ";
  100. $sql .= "'$templateid', ";
  101. $sql .= "'$templatelanguage', ";
  102. $sql .= "'$templatename', ";
  103. $sql .= "'$templatedesc', ";
  104. $sql .= "'$template', ";
  105. $sql .= "'$templatemenutype', ";
  106. $sql .= "'$templatemenucss', ";
  107. $sql .= "'$template_default' ";
  108. $sql .= ")";
  109. $db->exec(check_sql($sql));
  110. unset($sql);
  111. }
  112. //restore the default theme files
  113. //place holder
  114. require_once "includes/header.php";
  115. echo "<meta http-equiv=\"refresh\" content=\"2;url=templates.php\">\n";
  116. echo "<div align='center'>\n";
  117. echo "Restore Complete\n";
  118. echo "</div>\n";
  119. require_once "includes/footer.php";
  120. return;
  121. ?>