Move contacts from the app to core directory

This commit is contained in:
markjcrane
2024-11-16 21:06:29 -07:00
parent cbcc47d47b
commit 9b843bbff0
50 changed files with 0 additions and 0 deletions
@@ -0,0 +1,282 @@
<?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 <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2023
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
//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 = new permissions;
$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
}
?>
@@ -0,0 +1,42 @@
<?php
//contacts
$array['dashboard'][$x]['dashboard_uuid'] = '3b0cbb2f-733d-4646-8332-7d108808f2fd';
$array['dashboard'][$x]['dashboard_name'] = 'Contacts';
$array['dashboard'][$x]['dashboard_path'] = 'dashboard/icon';
$array['dashboard'][$x]['dashboard_icon'] = 'fa-regular fa-address-card';
$array['dashboard'][$x]['dashboard_url'] = '/app/contacts/contacts.php';
$array['dashboard'][$x]['dashboard_target'] = 'self';
$array['dashboard'][$x]['dashboard_width'] = '';
$array['dashboard'][$x]['dashboard_height'] = '';
$array['dashboard'][$x]['dashboard_content'] = '';
$array['dashboard'][$x]['dashboard_content_text_align'] = '';
$array['dashboard'][$x]['dashboard_content_details'] = '';
$array['dashboard'][$x]['dashboard_chart_type'] = '';
$array['dashboard'][$x]['dashboard_heading_text_color'] = '';
$array['dashboard'][$x]['dashboard_heading_text_color_hover'] = '';
$array['dashboard'][$x]['dashboard_heading_background_color'] = '';
$array['dashboard'][$x]['dashboard_heading_background_color_hover'] = '';
$array['dashboard'][$x]['dashboard_number_background_color'] = '';
$array['dashboard'][$x]['dashboard_number_text_color'] = '#0292FF';
$array['dashboard'][$x]['dashboard_number_text_color_hover'] = '';
$array['dashboard'][$x]['dashboard_background_color'] ='';
$array['dashboard'][$x]['dashboard_background_color_hover'] = '';
$array['dashboard'][$x]['dashboard_detail_background_color'] = '';
$array['dashboard'][$x]['dashboard_column_span'] = '1';
$array['dashboard'][$x]['dashboard_row_span'] = '1';
$array['dashboard'][$x]['dashboard_details_state'] = 'disabled';
$array['dashboard'][$x]['dashboard_order'] = '50';
$array['dashboard'][$x]['dashboard_enabled'] = 'true';
$array['dashboard'][$x]['dashboard_description'] = '';
$y = 0;
$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_group_uuid'] = 'ec16fd64-5333-4372-bb9c-21603358e283';
$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_uuid'] = '3b0cbb2f-733d-4646-8332-7d108808f2fd';
$array['dashboard'][$x]['dashboard_groups'][$y]['group_name'] = 'superadmin';
$y++;
$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_group_uuid'] = 'c46035ba-9d23-4e77-84a9-c8ffeea48415';
$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_uuid'] = '3b0cbb2f-733d-4646-8332-7d108808f2fd';
$array['dashboard'][$x]['dashboard_groups'][$y]['group_name'] = 'admin';
$y++;
?>
@@ -0,0 +1,116 @@
<?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 <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2013
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
if (!function_exists('google_get_contacts')) {
function google_get_contacts($token, $max_results = 50) {
//global $records;
global $groups;
//$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&oauth_token='.$_SESSION['contact_auth']['token']; // all contacts as xml
//$url = 'https://www.google.com/m8/feeds/contacts/default/full/78967d550d3fdd99?alt=json&v=3.0&oauth_token='.$_SESSION['contact_auth']['token']; // single contact
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$token; // all contacts as json
$xml_response = curl_file_get_contents($url);
$records = json_decode($xml_response, true);
//check for authentication errors (logged out of google account, or app access permission revoked, etc)
if ($records['error']['code']) {
header("Location: contact_auth.php?source=google&target=".substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"],'/')+1));
exit;
}
//create new array of contacts
foreach($records['feed']['entry'] as $contact['number'] => $contact) {
$contact_id = substr($contact['id']['$t'], strrpos($contact['id']['$t'], "/")+1);
$contacts[$contact_id]['etag'] = $contact['gd$etag'];
$contacts[$contact_id]['updated'] = $contact['updated']['$t'];
$contacts[$contact_id]['name_prefix'] = $contact['gd$name']['gd$namePrefix']['$t'];
$contacts[$contact_id]['name_given'] = $contact['gd$name']['gd$givenName']['$t'];
$contacts[$contact_id]['name_middle'] = $contact['gd$name']['gd$additionalName']['$t'];
$contacts[$contact_id]['name_family'] = $contact['gd$name']['gd$familyName']['$t'];
$contacts[$contact_id]['name_suffix'] = $contact['gd$name']['gd$nameSuffix']['$t'];
$contacts[$contact_id]['nickname'] = $contact['gContact$nickname']['$t'];
$contacts[$contact_id]['title'] = $contact['gd$organization'][0]['gd$orgTitle']['$t'];
$contacts[$contact_id]['organization'] = $contact['gd$organization'][0]['gd$orgName']['$t'];
foreach ($contact['gd$email'] as $contact_email['number'] => $contact_email) {
if ($contact_email['label']) {
$contact_email_label = $contact_email['label'];
}
else {
$contact_email_label = substr($contact_email['rel'], strpos($contact_email['rel'], "#")+1);
$contact_email_label = ucwords(str_replace("_", " ", $contact_email_label));
}
$contacts[$contact_id]['emails'][$contact_email['number']]['label'] = $contact_email_label;
$contacts[$contact_id]['emails'][$contact_email['number']]['address'] = $contact_email['address'];
$contacts[$contact_id]['emails'][$contact_email['number']]['primary'] = ($contact_email['primary']) ? 1 : 0;
}
foreach ($contact['gd$phoneNumber'] as $contact_phone['number'] => $contact_phone) {
if ($contact_phone['label']) {
$contact_phone_label = $contact_phone['label'];
}
else {
$contact_phone_label = substr($contact_phone['rel'], strpos($contact_phone['rel'], "#")+1);
$contact_phone_label = ucwords(str_replace("_", " ", $contact_phone_label));
}
$contacts[$contact_id]['numbers'][$contact_phone['number']]['label'] = $contact_phone_label;
$contacts[$contact_id]['numbers'][$contact_phone['number']]['number'] = preg_replace('{\D}', '', $contact_phone['$t']);
}
foreach ($contact['gContact$website'] as $contact_website['number'] => $contact_website) {
$contact_website_label = ($contact_website['label']) ? $contact_website['label'] : ucwords(str_replace("_", " ", $contact_website['rel']));
$contacts[$contact_id]['urls'][$contact_website['number']]['label'] = $contact_website_label;
$contacts[$contact_id]['urls'][$contact_website['number']]['url'] = $contact_website['href'];
}
foreach ($contact['gd$structuredPostalAddress'] as $contact_address['number'] => $contact_address) {
if ($contact_address['label']) {
$contact_address_label = $contact_address['label'];
}
else {
$contact_address_label = substr($contact_address['rel'], strpos($contact_address['rel'], "#")+1);
$contact_address_label = ucwords(str_replace("_", " ", $contact_address_label));
}
$contacts[$contact_id]['addresses'][$contact_address['number']]['label'] = $contact_address_label;
$contacts[$contact_id]['addresses'][$contact_address['number']]['street'] = $contact_address['gd$street']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['extended'] = $contact_address['gd$pobox']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['community'] = $contact_address['gd$neighborhood']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['locality'] = $contact_address['gd$city']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['region'] = $contact_address['gd$region']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['postal_code'] = $contact_address['gd$postcode']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['country'] = $contact_address['gd$country']['$t'];
}
foreach ($contact['gContact$groupMembershipInfo'] as $contact_group['number'] => $contact_group) {
$contact_group_id = substr($contact_group['href'], strrpos($contact_group['href'], "/")+1);
$contacts[$contact_id]['groups'][$contact_group_id] = $groups[$contact_group_id]['name'];
}
$contacts[$contact_id]['notes'] = $contact['content']['$t'];
}
//set account holder info
$_SESSION['contact_auth']['name'] = $records['feed']['author'][0]['name']['$t'];
$_SESSION['contact_auth']['email'] = $records['feed']['author'][0]['email']['$t'];
return $contacts;
}
}
?>
@@ -0,0 +1,54 @@
<?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 <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2013
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
function google_get_groups($token) {
// retrieve groups
$url = 'https://www.google.com/m8/feeds/groups/default/full?alt=json&v=3.0&oauth_token='.$token;
$xml_response = curl_file_get_contents($url);
$records = json_decode($xml_response, true);
//check for authentication errors
if ($records['error']['code']) {
header("Location: contact_auth.php?source=google&target=".substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"],'/')+1));
exit;
}
//create new array of groups
foreach($records['feed']['entry'] as $group['number'] => $group) {
$group_id = substr($group['id']['$t'], strrpos($group['id']['$t'], "/")+1);
$groups[$group_id]['name'] = ($group['gContact$systemGroup']['id']) ? $group['gContact$systemGroup']['id'] : $group['title']['$t'];
$groups[$group_id]['count'] = 0;
unset($group_id);
}
unset($group);
//set account holder info
$_SESSION['contact_auth']['name'] = $records['feed']['author'][0]['name']['$t'];
$_SESSION['contact_auth']['email'] = $records['feed']['author'][0]['email']['$t'];
return $groups;
}
?>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB