123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- /*
- FusionPBX
- Version: MPL 1.1
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
- The Original Code is FusionPBX
- The Initial Developer of the Original Code is
- Mark J Crane <[email protected]>
- Portions created by the Initial Developer are Copyright (C) 2008-2023
- the Initial Developer. All Rights Reserved.
- Contributor(s):
- Mark J Crane <[email protected]>
- */
- //define the contacts class
- if (!class_exists('contacts')) {
- class contacts {
- const APP_NAME = "contacts";
- const APP_UUID = "04481e0e-a478-c559-adad-52bd4174574c";
- /**
- * declare private variables
- */
- private $app_name;
- private $app_uuid;
- private $permission_prefix;
- private $list_page;
- private $tables;
- private $uuid_prefix;
- /**
- * declare public variables
- */
- public $contact_uuid;
- /**
- * called when the object is created
- */
- public function __construct() {
- //assign private variables
- $this->app_name = self::APP_NAME;
- $this->app_uuid = self::APP_UUID;
- $this->permission_prefix = 'contact_';
- $this->list_page = 'contacts.php';
- $this->tables[] = 'contact_addresses';
- $this->tables[] = 'contact_attachments';
- $this->tables[] = 'contact_emails';
- $this->tables[] = 'contact_groups';
- $this->tables[] = 'contact_notes';
- $this->tables[] = 'contact_phones';
- $this->tables[] = 'contact_relations';
- $this->tables[] = 'contact_settings';
- $this->tables[] = 'contact_times';
- $this->tables[] = 'contact_urls';
- $this->tables[] = 'contact_users';
- $this->tables[] = 'contacts';
- $this->uuid_prefix = 'contact_';
- }
- /**
- * delete records
- */
- public function delete($records) {
- if (permission_exists($this->permission_prefix.'delete')) {
- //add multi-lingual support
- $language = new text;
- $text = $language->get();
- //validate the token
- $token = new token;
- if (!$token->validate($_SERVER['PHP_SELF'])) {
- message::add($text['message-invalid_token'],'negative');
- header('Location: '.$this->list_page);
- exit;
- }
- //delete multiple records
- if (is_array($records) && @sizeof($records) != 0) {
- //build the delete array
- foreach ($records as $x => $record) {
- if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
- if (is_array($this->tables) && @sizeof($this->tables) != 0) {
- foreach ($this->tables as $table) {
- $array[$table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
- $array[$table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
- }
- }
- }
- }
- //delete the checked rows
- if (is_array($array) && @sizeof($array) != 0) {
- //grant temp permissions
- $p = permissions::new();
- $database = new database;
- foreach ($this->tables as $table) {
- $p->add(database::singular($table).'_delete', 'temp');
- }
- //execute delete
- $database = new database;
- $database->app_name = $this->app_name;
- $database->app_uuid = $this->app_uuid;
- $database->delete($array);
- unset($array);
- //revoke temp permissions
- $database = new database;
- foreach ($this->tables as $table) {
- $p->delete(database::singular($table).'_delete', 'temp');
- }
- //set message
- message::add($text['message-delete']);
- }
- unset($records);
- }
- }
- }
- public function delete_properties($records) {
- //add multi-lingual support
- $language = new text;
- $text = $language->get();
- //validate the token
- $token = new token;
- if (!$token->validate($_SERVER['PHP_SELF'])) {
- message::add($text['message-invalid_token'],'negative');
- header('Location: '.$this->list_page);
- exit;
- }
- //delete multiple records
- if (is_array($records) && @sizeof($records) != 0) {
- //check permissions and build the delete array
- $x = 0;
- foreach ($records as $property_name => $properties) {
- $database = new database;
- if (permission_exists(database::singular($property_name).'_delete')) {
- if (is_array($properties) && @sizeof($properties) != 0) {
- foreach ($properties as $property) {
- if ($property['checked'] == 'true' && is_uuid($property['uuid'])) {
- $array[$property_name][$x][database::singular($property_name).'_uuid'] = $property['uuid'];
- $array[$property_name][$x]['contact_uuid'] = $this->contact_uuid;
- $array[$property_name][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
- $x++;
- }
- }
- }
- }
- }
- //delete the checked rows
- if (is_array($array) && @sizeof($array) != 0) {
- //execute delete
- $database = new database;
- $database->app_name = $this->app_name;
- $database->app_uuid = $this->app_uuid;
- $database->delete($array);
- unset($array);
- }
- unset($records);
- }
- }
- public function delete_users($records) {
- //assign private variables
- $this->permission_prefix = 'contact_user_';
- $this->table = 'contact_users';
- $this->uuid_prefix = 'contact_user_';
- if (permission_exists($this->permission_prefix.'delete')) {
- //add multi-lingual support
- $language = new text;
- $text = $language->get();
- //validate the token
- $token = new token;
- if (!$token->validate($_SERVER['PHP_SELF'])) {
- message::add($text['message-invalid_token'],'negative');
- header('Location: '.$this->list_page);
- exit;
- }
- //delete multiple records
- if (is_array($records) && @sizeof($records) != 0) {
- //filter out unchecked ivr menu options, build delete array
- $x = 0;
- foreach ($records as $record) {
- if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
- $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
- $array[$this->table][$x]['contact_uuid'] = $this->contact_uuid;
- $x++;
- }
- }
- //delete the checked rows
- if (is_array($array) && @sizeof($array) != 0) {
- //execute delete
- $database = new database;
- $database->app_name = $this->app_name;
- $database->app_uuid = $this->app_uuid;
- $database->delete($array);
- unset($array);
- }
- unset($records);
- }
- }
- }
- public function delete_groups($records) {
- //assign private variables
- $this->permission_prefix = 'contact_group_';
- $this->table = 'contact_groups';
- $this->uuid_prefix = 'contact_group_';
- if (permission_exists($this->permission_prefix.'delete')) {
- //add multi-lingual support
- $language = new text;
- $text = $language->get();
- //validate the token
- $token = new token;
- if (!$token->validate($_SERVER['PHP_SELF'])) {
- message::add($text['message-invalid_token'],'negative');
- header('Location: '.$this->list_page);
- exit;
- }
- //delete multiple records
- if (is_array($records) && @sizeof($records) != 0) {
- //filter out unchecked ivr menu options, build delete array
- $x = 0;
- foreach ($records as $record) {
- if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
- $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
- $array[$this->table][$x]['contact_uuid'] = $this->contact_uuid;
- $x++;
- }
- }
- //delete the checked rows
- if (is_array($array) && @sizeof($array) != 0) {
- //execute delete
- $database = new database;
- $database->app_name = $this->app_name;
- $database->app_uuid = $this->app_uuid;
- $database->delete($array);
- unset($array);
- }
- unset($records);
- }
- }
- } //method
- } //class
- }
- ?>
|