contacts.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //define the contacts class
  22. if (!class_exists('contacts')) {
  23. class contacts {
  24. const APP_NAME = "contacts";
  25. const APP_UUID = "04481e0e-a478-c559-adad-52bd4174574c";
  26. /**
  27. * declare private variables
  28. */
  29. private $app_name;
  30. private $app_uuid;
  31. private $permission_prefix;
  32. private $list_page;
  33. private $tables;
  34. private $uuid_prefix;
  35. /**
  36. * declare public variables
  37. */
  38. public $contact_uuid;
  39. /**
  40. * called when the object is created
  41. */
  42. public function __construct() {
  43. //assign private variables
  44. $this->app_name = self::APP_NAME;
  45. $this->app_uuid = self::APP_UUID;
  46. $this->permission_prefix = 'contact_';
  47. $this->list_page = 'contacts.php';
  48. $this->tables[] = 'contact_addresses';
  49. $this->tables[] = 'contact_attachments';
  50. $this->tables[] = 'contact_emails';
  51. $this->tables[] = 'contact_groups';
  52. $this->tables[] = 'contact_notes';
  53. $this->tables[] = 'contact_phones';
  54. $this->tables[] = 'contact_relations';
  55. $this->tables[] = 'contact_settings';
  56. $this->tables[] = 'contact_times';
  57. $this->tables[] = 'contact_urls';
  58. $this->tables[] = 'contact_users';
  59. $this->tables[] = 'contacts';
  60. $this->uuid_prefix = 'contact_';
  61. }
  62. /**
  63. * delete records
  64. */
  65. public function delete($records) {
  66. if (permission_exists($this->permission_prefix.'delete')) {
  67. //add multi-lingual support
  68. $language = new text;
  69. $text = $language->get();
  70. //validate the token
  71. $token = new token;
  72. if (!$token->validate($_SERVER['PHP_SELF'])) {
  73. message::add($text['message-invalid_token'],'negative');
  74. header('Location: '.$this->list_page);
  75. exit;
  76. }
  77. //delete multiple records
  78. if (is_array($records) && @sizeof($records) != 0) {
  79. //build the delete array
  80. foreach ($records as $x => $record) {
  81. if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
  82. if (is_array($this->tables) && @sizeof($this->tables) != 0) {
  83. foreach ($this->tables as $table) {
  84. $array[$table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
  85. $array[$table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
  86. }
  87. }
  88. }
  89. }
  90. //delete the checked rows
  91. if (is_array($array) && @sizeof($array) != 0) {
  92. //grant temp permissions
  93. $p = permissions::new();
  94. $database = new database;
  95. foreach ($this->tables as $table) {
  96. $p->add(database::singular($table).'_delete', 'temp');
  97. }
  98. //execute delete
  99. $database = new database;
  100. $database->app_name = $this->app_name;
  101. $database->app_uuid = $this->app_uuid;
  102. $database->delete($array);
  103. unset($array);
  104. //revoke temp permissions
  105. $database = new database;
  106. foreach ($this->tables as $table) {
  107. $p->delete(database::singular($table).'_delete', 'temp');
  108. }
  109. //set message
  110. message::add($text['message-delete']);
  111. }
  112. unset($records);
  113. }
  114. }
  115. }
  116. public function delete_properties($records) {
  117. //add multi-lingual support
  118. $language = new text;
  119. $text = $language->get();
  120. //validate the token
  121. $token = new token;
  122. if (!$token->validate($_SERVER['PHP_SELF'])) {
  123. message::add($text['message-invalid_token'],'negative');
  124. header('Location: '.$this->list_page);
  125. exit;
  126. }
  127. //delete multiple records
  128. if (is_array($records) && @sizeof($records) != 0) {
  129. //check permissions and build the delete array
  130. $x = 0;
  131. foreach ($records as $property_name => $properties) {
  132. $database = new database;
  133. if (permission_exists(database::singular($property_name).'_delete')) {
  134. if (is_array($properties) && @sizeof($properties) != 0) {
  135. foreach ($properties as $property) {
  136. if ($property['checked'] == 'true' && is_uuid($property['uuid'])) {
  137. $array[$property_name][$x][database::singular($property_name).'_uuid'] = $property['uuid'];
  138. $array[$property_name][$x]['contact_uuid'] = $this->contact_uuid;
  139. $array[$property_name][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
  140. $x++;
  141. }
  142. }
  143. }
  144. }
  145. }
  146. //delete the checked rows
  147. if (is_array($array) && @sizeof($array) != 0) {
  148. //execute delete
  149. $database = new database;
  150. $database->app_name = $this->app_name;
  151. $database->app_uuid = $this->app_uuid;
  152. $database->delete($array);
  153. unset($array);
  154. }
  155. unset($records);
  156. }
  157. }
  158. public function delete_users($records) {
  159. //assign private variables
  160. $this->permission_prefix = 'contact_user_';
  161. $this->table = 'contact_users';
  162. $this->uuid_prefix = 'contact_user_';
  163. if (permission_exists($this->permission_prefix.'delete')) {
  164. //add multi-lingual support
  165. $language = new text;
  166. $text = $language->get();
  167. //validate the token
  168. $token = new token;
  169. if (!$token->validate($_SERVER['PHP_SELF'])) {
  170. message::add($text['message-invalid_token'],'negative');
  171. header('Location: '.$this->list_page);
  172. exit;
  173. }
  174. //delete multiple records
  175. if (is_array($records) && @sizeof($records) != 0) {
  176. //filter out unchecked ivr menu options, build delete array
  177. $x = 0;
  178. foreach ($records as $record) {
  179. if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
  180. $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
  181. $array[$this->table][$x]['contact_uuid'] = $this->contact_uuid;
  182. $x++;
  183. }
  184. }
  185. //delete the checked rows
  186. if (is_array($array) && @sizeof($array) != 0) {
  187. //execute delete
  188. $database = new database;
  189. $database->app_name = $this->app_name;
  190. $database->app_uuid = $this->app_uuid;
  191. $database->delete($array);
  192. unset($array);
  193. }
  194. unset($records);
  195. }
  196. }
  197. }
  198. public function delete_groups($records) {
  199. //assign private variables
  200. $this->permission_prefix = 'contact_group_';
  201. $this->table = 'contact_groups';
  202. $this->uuid_prefix = 'contact_group_';
  203. if (permission_exists($this->permission_prefix.'delete')) {
  204. //add multi-lingual support
  205. $language = new text;
  206. $text = $language->get();
  207. //validate the token
  208. $token = new token;
  209. if (!$token->validate($_SERVER['PHP_SELF'])) {
  210. message::add($text['message-invalid_token'],'negative');
  211. header('Location: '.$this->list_page);
  212. exit;
  213. }
  214. //delete multiple records
  215. if (is_array($records) && @sizeof($records) != 0) {
  216. //filter out unchecked ivr menu options, build delete array
  217. $x = 0;
  218. foreach ($records as $record) {
  219. if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
  220. $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
  221. $array[$this->table][$x]['contact_uuid'] = $this->contact_uuid;
  222. $x++;
  223. }
  224. }
  225. //delete the checked rows
  226. if (is_array($array) && @sizeof($array) != 0) {
  227. //execute delete
  228. $database = new database;
  229. $database->app_name = $this->app_name;
  230. $database->app_uuid = $this->app_uuid;
  231. $database->delete($array);
  232. unset($array);
  233. }
  234. unset($records);
  235. }
  236. }
  237. } //method
  238. } //class
  239. }
  240. ?>