mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Documentation, format class, no modification. (#7628)
This commit is contained in:
@@ -38,18 +38,6 @@
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher
|
||||
if (!function_exists('str_getcsv')) {
|
||||
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
|
||||
$fp = fopen("php://memory", 'r+');
|
||||
fputs($fp, $input);
|
||||
rewind($fp);
|
||||
$data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0
|
||||
fclose($fp);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
//set the max php execution time
|
||||
ini_set('max_execution_time', 7200);
|
||||
|
||||
@@ -252,6 +240,14 @@
|
||||
}
|
||||
|
||||
//get the parent table
|
||||
/**
|
||||
* Retrieves the parent table name from a given schema based on the provided table name.
|
||||
*
|
||||
* @param array $schema A list of tables and their properties in the database schema.
|
||||
* @param string $table_name The name of the table for which to retrieve the parent.
|
||||
*
|
||||
* @return string|null The parent table name, or null if no match is found.
|
||||
*/
|
||||
function get_parent($schema,$table_name) {
|
||||
foreach ($schema as $row) {
|
||||
if ($row['table'] == $table_name) {
|
||||
|
||||
@@ -581,6 +581,13 @@ require_once "resources/footer.php";
|
||||
|
||||
|
||||
// used above
|
||||
/**
|
||||
* Retrieves the contents of a URL using cURL.
|
||||
*
|
||||
* @param string $url The URL to retrieve.
|
||||
*
|
||||
* @return string The contents of the retrieved URL, or FALSE if an error occurred.
|
||||
*/
|
||||
function curl_file_get_contents($url) {
|
||||
$curl = curl_init();
|
||||
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
|
||||
|
||||
@@ -25,262 +25,304 @@
|
||||
*/
|
||||
|
||||
//define the contacts class
|
||||
class contacts {
|
||||
class contacts {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
*/
|
||||
const app_name = 'contacts';
|
||||
const app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
|
||||
/**
|
||||
* declare constant variables
|
||||
*/
|
||||
const app_name = 'contacts';
|
||||
const app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
*
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Settings object set in the constructor. Must be a settings object and cannot be null.
|
||||
* @var settings Settings Object
|
||||
*/
|
||||
private $settings;
|
||||
/**
|
||||
* Settings object set in the constructor. Must be a settings object and cannot be null.
|
||||
*
|
||||
* @var settings Settings Object
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* @var string
|
||||
*/
|
||||
private $domain_uuid;
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
|
||||
* in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $domain_uuid;
|
||||
|
||||
/**
|
||||
* declare private variables
|
||||
*/
|
||||
private $permission_prefix;
|
||||
private $list_page;
|
||||
private $tables;
|
||||
private $table;
|
||||
private $uuid_prefix;
|
||||
/**
|
||||
* declare private variables
|
||||
*/
|
||||
private $permission_prefix;
|
||||
private $list_page;
|
||||
private $tables;
|
||||
private $table;
|
||||
private $uuid_prefix;
|
||||
|
||||
/**
|
||||
* declare public variables
|
||||
*/
|
||||
public $contact_uuid;
|
||||
/**
|
||||
* declare public variables
|
||||
*/
|
||||
public $contact_uuid;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
|
||||
|
||||
//set objects
|
||||
$this->database = $setting_array['database'] ?? database::new();
|
||||
/**
|
||||
* Constructor for the class.
|
||||
*
|
||||
* This method initializes the object with setting_array and session data.
|
||||
*
|
||||
* @param array $setting_array An optional array of settings to override default values. Defaults to [].
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
|
||||
|
||||
//assign private variables
|
||||
$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_';
|
||||
}
|
||||
//set objects
|
||||
$this->database = $setting_array['database'] ?? database::new();
|
||||
|
||||
/**
|
||||
* delete records
|
||||
*/
|
||||
public function delete($records) {
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
//assign private variables
|
||||
$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_';
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
/**
|
||||
* Deletes one or multiple records.
|
||||
*
|
||||
* @param array $records An array of record IDs to delete, where each ID is an associative array
|
||||
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
|
||||
* whether the corresponding checkbox was checked for deletion.
|
||||
*
|
||||
* @return void No return value; this method modifies the database state and sets a message.
|
||||
*/
|
||||
public function delete($records) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//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'] = $this->domain_uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//delete the checked rows
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
|
||||
//grant temp permissions
|
||||
$p = permissions::new();
|
||||
foreach ($this->tables as $table) {
|
||||
$p->add(database::singular($table).'_delete', 'temp');
|
||||
}
|
||||
|
||||
//execute delete
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temp permissions
|
||||
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();
|
||||
$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;
|
||||
}
|
||||
$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) {
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//check permissions and build the delete array
|
||||
$x = 0;
|
||||
foreach ($records as $property_name => $properties) {
|
||||
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'] = $this->domain_uuid;
|
||||
$x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//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'] = $this->domain_uuid;
|
||||
}
|
||||
}
|
||||
|
||||
//delete the checked rows
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
//execute delete
|
||||
$this->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_';
|
||||
//delete the checked rows
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
|
||||
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;
|
||||
//grant temp permissions
|
||||
$p = permissions::new();
|
||||
foreach ($this->tables as $table) {
|
||||
$p->add(database::singular($table) . '_delete', 'temp');
|
||||
}
|
||||
|
||||
//delete multiple records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
//execute delete
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//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
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
}
|
||||
unset($records);
|
||||
//revoke temp permissions
|
||||
foreach ($this->tables as $table) {
|
||||
$p->delete(database::singular($table) . '_delete', 'temp');
|
||||
}
|
||||
|
||||
//set message
|
||||
message::add($text['message-delete']);
|
||||
}
|
||||
unset($records);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_groups($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'contact_group_';
|
||||
$this->table = 'contact_groups';
|
||||
$this->uuid_prefix = 'contact_group_';
|
||||
/**
|
||||
* Deletes one or multiple records.
|
||||
*
|
||||
* @param array $records An array of record IDs to delete, where each ID is an associative array
|
||||
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
|
||||
* whether the corresponding checkbox was checked for deletion.
|
||||
*
|
||||
* @return void No return value; this method modifies the database state and sets a message.
|
||||
*/
|
||||
public function delete_properties($records) {
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
//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;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
//delete multiple records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//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++;
|
||||
}
|
||||
//check permissions and build the delete array
|
||||
$x = 0;
|
||||
foreach ($records as $property_name => $properties) {
|
||||
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'] = $this->domain_uuid;
|
||||
$x++;
|
||||
}
|
||||
|
||||
//delete the checked rows
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
//execute delete
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
}
|
||||
unset($records);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
//delete the checked rows
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
//execute delete
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
}
|
||||
unset($records);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one or multiple records.
|
||||
*
|
||||
* @param array $records An array of record IDs to delete, where each ID is an associative array
|
||||
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
|
||||
* whether the corresponding checkbox was checked for deletion.
|
||||
*
|
||||
* @return void No return value; this method modifies the database state and sets a message.
|
||||
*/
|
||||
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
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
}
|
||||
unset($records);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one or multiple records.
|
||||
*
|
||||
* @param array $records An array of record IDs to delete, where each ID is an associative array
|
||||
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
|
||||
* whether the corresponding checkbox was checked for deletion.
|
||||
*
|
||||
* @return void No return value; this method modifies the database state and sets a message.
|
||||
*/
|
||||
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
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
}
|
||||
unset($records);
|
||||
}
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
|
||||
Reference in New Issue
Block a user