databases.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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) 2020-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //define the databases class
  22. if (!class_exists('databases')) {
  23. class databases {
  24. /**
  25. * declare private variables
  26. */
  27. private $app_name;
  28. private $app_uuid;
  29. private $permission_prefix;
  30. private $list_page;
  31. private $table;
  32. private $uuid_prefix;
  33. /**
  34. * called when the object is created
  35. */
  36. public function __construct() {
  37. //assign private variables
  38. $this->app_name = 'databases';
  39. $this->app_uuid = '8d229b6d-1383-fcec-74c6-4ce1682479e2';
  40. $this->permission_prefix = 'database_';
  41. $this->list_page = 'databases.php';
  42. $this->table = 'databases';
  43. $this->uuid_prefix = 'database_';
  44. }
  45. /**
  46. * delete records
  47. */
  48. public function delete($records) {
  49. if (permission_exists($this->permission_prefix.'delete')) {
  50. //add multi-lingual support
  51. $language = new text;
  52. $text = $language->get();
  53. //validate the token
  54. $token = new token;
  55. if (!$token->validate($_SERVER['PHP_SELF'])) {
  56. message::add($text['message-invalid_token'],'negative');
  57. header('Location: '.$this->list_page);
  58. exit;
  59. }
  60. //delete multiple records
  61. if (is_array($records) && @sizeof($records) != 0) {
  62. //build the delete array
  63. foreach ($records as $x => $record) {
  64. if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
  65. $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
  66. }
  67. }
  68. //delete the checked rows
  69. if (is_array($array) && @sizeof($array) != 0) {
  70. //execute delete
  71. $database = new database;
  72. $database->app_name = $this->app_name;
  73. $database->app_uuid = $this->app_uuid;
  74. $database->delete($array);
  75. unset($array);
  76. //set message
  77. message::add($text['message-delete']);
  78. }
  79. unset($records);
  80. }
  81. }
  82. }
  83. /**
  84. * copy records
  85. */
  86. public function copy($records) {
  87. if (permission_exists($this->permission_prefix.'add')) {
  88. //add multi-lingual support
  89. $language = new text;
  90. $text = $language->get();
  91. //validate the token
  92. $token = new token;
  93. if (!$token->validate($_SERVER['PHP_SELF'])) {
  94. message::add($text['message-invalid_token'],'negative');
  95. header('Location: '.$this->list_page);
  96. exit;
  97. }
  98. //copy the checked records
  99. if (is_array($records) && @sizeof($records) != 0) {
  100. //get checked records
  101. foreach ($records as $x => $record) {
  102. if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
  103. $uuids[] = "'".$record['uuid']."'";
  104. }
  105. }
  106. //create insert array from existing data
  107. if (is_array($uuids) && @sizeof($uuids) != 0) {
  108. $sql = "select * from v_".$this->table." ";
  109. $sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
  110. $database = new database;
  111. $rows = $database->select($sql, $parameters ?? null, 'all');
  112. if (is_array($rows) && @sizeof($rows) != 0) {
  113. foreach ($rows as $x => $row) {
  114. //copy data
  115. $array[$this->table][$x] = $row;
  116. //overwrite
  117. $array[$this->table][$x][$this->uuid_prefix.'uuid'] = uuid();
  118. $array[$this->table][$x]['database_description'] = trim($row['database_description'].' ('.$text['label-copy'].')');
  119. }
  120. }
  121. unset($sql, $parameters, $rows, $row);
  122. }
  123. //save the changes and set the message
  124. if (is_array($array) && @sizeof($array) != 0) {
  125. //save the array
  126. $database = new database;
  127. $database->app_name = $this->app_name;
  128. $database->app_uuid = $this->app_uuid;
  129. $database->save($array);
  130. unset($array);
  131. //set message
  132. message::add($text['message-copy']);
  133. }
  134. unset($records);
  135. }
  136. }
  137. }
  138. }
  139. }
  140. ?>