mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Create more documentation (#7627)
* Documentation, format class, no modification.
This commit is contained in:
@@ -54,6 +54,13 @@
|
||||
}
|
||||
|
||||
//define the functions
|
||||
/**
|
||||
* Converts an array to a CSV string.
|
||||
*
|
||||
* @param array &$array The input array. It should be a multidimensional array where the first level keys are column headers and the second level arrays are rows.
|
||||
*
|
||||
* @return string|null The CSV string representation of the input array, or null if the input array is empty.
|
||||
*/
|
||||
function array2csv(array &$array) {
|
||||
if (count($array) == 0) {
|
||||
return null;
|
||||
@@ -69,7 +76,14 @@
|
||||
}
|
||||
|
||||
//send download headers
|
||||
function download_send_headers($filename) {
|
||||
/**
|
||||
* Sends HTTP headers to force a file download.
|
||||
*
|
||||
* @param string $filename The name of the file to be downloaded, excluding the path.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function download_send_headers($filename) {
|
||||
// disable caching
|
||||
$now = gmdate("D, d M Y H:i:s");
|
||||
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
|
||||
|
||||
@@ -40,6 +40,16 @@
|
||||
|
||||
//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduce the functionality but requires PHP 5.1.0 or higher
|
||||
if (!function_exists('str_getcsv')) {
|
||||
/**
|
||||
* Parse a CSV string into an array.
|
||||
*
|
||||
* @param string $input The CSV data to parse.
|
||||
* @param string $delimiter The field delimiter (default: ",").
|
||||
* @param string $enclosure The field enclosure character (default: """).
|
||||
* @param string $escape The escape character (default: "\"").
|
||||
*
|
||||
* @return array An array containing the parsed CSV fields.
|
||||
*/
|
||||
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
|
||||
$fp = fopen("php://memory", 'r+');
|
||||
fputs($fp, $input);
|
||||
@@ -212,6 +222,14 @@
|
||||
}
|
||||
|
||||
//get the parent table
|
||||
/**
|
||||
* Retrieve the parent table for a given table in a schema.
|
||||
*
|
||||
* @param array $schema The database schema to search in.
|
||||
* @param string $table_name The name of the table for which to find the parent.
|
||||
*
|
||||
* @return mixed The name of the parent table, or NULL if not found.
|
||||
*/
|
||||
function get_parent($schema,$table_name) {
|
||||
foreach ($schema as $row) {
|
||||
if ($row['table'] == $table_name) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* access controls class
|
||||
*/
|
||||
class access_controls {
|
||||
class access_controls {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -13,24 +13,30 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -60,7 +66,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or multiple records from the access controls table.
|
||||
*
|
||||
* @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) {
|
||||
|
||||
@@ -123,6 +135,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one or more access control nodes.
|
||||
*
|
||||
* @param array $records Array of records to delete, where each record is an associative array containing the
|
||||
* 'uuid' and 'checked' keys.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_nodes($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -177,7 +197,12 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copy access controls and their nodes.
|
||||
*
|
||||
* @param array $records An array of records to copy. Each record should contain a 'checked' key with value 'true'
|
||||
* and a 'uuid' key with the UUID of the access control or node to copy.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function copy($records) {
|
||||
|
||||
@@ -223,7 +248,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -289,4 +314,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +35,29 @@ class caller_context_filter implements filter {
|
||||
|
||||
private $domains;
|
||||
|
||||
/**
|
||||
* Initializes the object with an array of domain names.
|
||||
*
|
||||
* @param array $domain_names Array of domain names to initialize the object with.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $domain_names) {
|
||||
foreach ($domain_names as $name) {
|
||||
$this->domains[$name] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes this method as a callable.
|
||||
*
|
||||
* @param string $key The event key, which is used for validation and filtering.
|
||||
* @param mixed $value The value associated with the event key, used to determine
|
||||
* whether the filter chain should drop the payload.
|
||||
*
|
||||
* @return bool|null Returns true if the key is not 'caller_context' or the value exists in the domains,
|
||||
* otherwise returns null to drop the payload.
|
||||
*/
|
||||
public function __invoke(string $key, $value): ?bool {
|
||||
// return true when not on the event key caller_context to validate
|
||||
if ($key !== 'caller_context') {
|
||||
|
||||
@@ -35,10 +35,28 @@ class event_filter implements filter {
|
||||
|
||||
private $event_names;
|
||||
|
||||
/**
|
||||
* Initializes the object with the event names to filter on.
|
||||
*
|
||||
* @param array $event_names Array of event names to initialize the object with
|
||||
*/
|
||||
public function __construct(array $event_names) {
|
||||
$this->add_event_names($event_names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes this method to filter events.
|
||||
*
|
||||
* @param string $key The key name that will be used for filtering, currently only
|
||||
* supports the "event_name" key.
|
||||
* @param mixed $value The value associated with the provided key.
|
||||
*
|
||||
* @return bool|null Returns true if the invocation is valid and the event name
|
||||
* filter has not been applied yet. If the invocation has an "event_name"
|
||||
* key and its corresponding value, this method will return a boolean
|
||||
* indicating whether the event name already exists in the list of allowed
|
||||
* names or not. Otherwise returns null.
|
||||
*/
|
||||
public function __invoke(string $key, $value): ?bool {
|
||||
if ($key !== 'event_name') {
|
||||
return true;
|
||||
@@ -69,17 +87,20 @@ class event_filter implements filter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an event with the given name is present in the filters.
|
||||
*
|
||||
* @param string $name The name of the event to check for.
|
||||
*
|
||||
* @return bool|null True if the event is found, otherwise null. Returns null
|
||||
* when the event is not allowed due to permissions constraints.
|
||||
*/
|
||||
public function has_event_name(string $name): ?bool {
|
||||
if (isset($this->event_names[$name]))
|
||||
if (isset($this->event_names[$name])) {
|
||||
return true;
|
||||
//
|
||||
// If the event name is not allowed by the permissions given in
|
||||
// this object, then the entire event must be dropped. I could
|
||||
// not figure out a better way to do this except to throw an
|
||||
// exception so that the caller can drop the message.
|
||||
//
|
||||
// TODO: Find another way not so expensive to reject the payload
|
||||
//
|
||||
}
|
||||
|
||||
//reject the payload
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,23 @@ class event_key_filter implements filter {
|
||||
|
||||
private $filters;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the object with specified filters.
|
||||
*
|
||||
* @param array $filters Optional array of initial filters to be applied.
|
||||
*/
|
||||
public function __construct(array $filters = []) {
|
||||
$this->add_filters($filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a filter check with the given key and value.
|
||||
*
|
||||
* @param string $key The key of the filter to check
|
||||
* @param mixed $value The value associated with the filter key
|
||||
*
|
||||
* @return bool|null True if the filter exists, false otherwise
|
||||
*/
|
||||
public function __invoke(string $key, $value): ?bool {
|
||||
return $this->has_filter_key($key);
|
||||
}
|
||||
@@ -84,6 +97,13 @@ class event_key_filter implements filter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a filter key exists.
|
||||
*
|
||||
* @param string $key The filter key to check for existence.
|
||||
*
|
||||
* @return bool True if the filter key exists, false otherwise.
|
||||
*/
|
||||
public function has_filter_key(string $key): bool {
|
||||
return isset($this->filters[$key]);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ class event_message implements filterable_payload {
|
||||
* @var array
|
||||
*/
|
||||
private $event;
|
||||
|
||||
/**
|
||||
* Body of the SIP MESSAGE used in SMS
|
||||
* @var string
|
||||
*/
|
||||
private $body;
|
||||
|
||||
/**
|
||||
@@ -102,6 +107,11 @@ class event_message implements filterable_payload {
|
||||
return $this->event[$name] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array representation of this object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __toArray(): array {
|
||||
$array = [];
|
||||
foreach ($this->event as $key => $value) {
|
||||
@@ -110,10 +120,22 @@ class event_message implements filterable_payload {
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the current object into an array representation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function to_array(): array {
|
||||
return $this->__toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a filter to the event collection.
|
||||
*
|
||||
* @param filter $filter The filter function to apply
|
||||
*
|
||||
* @return self This object for method chaining
|
||||
*/
|
||||
public function apply_filter(filter $filter) {
|
||||
foreach ($this->event as $key => $value) {
|
||||
$result = ($filter)($key, $value);
|
||||
@@ -126,6 +148,16 @@ class event_message implements filterable_payload {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an active calls JSON string and return a list of event messages.
|
||||
*
|
||||
* This method expects a JSON string where each row represents an active call, and returns
|
||||
* a list of event_message objects populated with the relevant details for each call.
|
||||
*
|
||||
* @param string $json_string The JSON string to parse.
|
||||
*
|
||||
* @return array A list of event_message objects.
|
||||
*/
|
||||
public static function parse_active_calls($json_string): array {
|
||||
$calls = [];
|
||||
$json_array = json_decode($json_string, true);
|
||||
@@ -181,6 +213,15 @@ class event_message implements filterable_payload {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance from a switch event.
|
||||
*
|
||||
* @param array|string $raw_event The raw event data.
|
||||
* @param filter|null $filter Optional filter to be applied on the created object.
|
||||
* @param int $flags Flags controlling the creation process (see EVENT_SWAP_API and EVENT_USE_SUBCLASS).
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_switch_event($raw_event, filter $filter = null, $flags = 3): self {
|
||||
|
||||
// Set the options from the flags passed
|
||||
@@ -264,6 +305,14 @@ class event_message implements filterable_payload {
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the event object to an array representation.
|
||||
*
|
||||
* This method iterates over the event properties and includes them in the returned array.
|
||||
* If the body is not null, it will be included as a separate key-value pair in the resulting array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function event_to_array(): array {
|
||||
$array = [];
|
||||
foreach ($this->event as $key => $value) {
|
||||
@@ -275,15 +324,39 @@ class event_message implements filterable_payload {
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator for this object.
|
||||
*
|
||||
* This method allows iteration over the event data as a Traversable object.
|
||||
*
|
||||
* @return \Traversable
|
||||
*/
|
||||
public function getIterator(): \Traversable {
|
||||
yield from $this->event_to_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a specific event key exists in this object.
|
||||
*
|
||||
* @param mixed $offset The key of the event to check for existence
|
||||
*
|
||||
* @return bool True if the event key exists, false otherwise
|
||||
*/
|
||||
public function offsetExists(mixed $offset): bool {
|
||||
self::sanitize_event_key($offset);
|
||||
return isset($this->event[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value associated with the given key from this event object.
|
||||
*
|
||||
* If the key is 'body', returns the event body. Otherwise, returns the value
|
||||
* stored in the 'event' array for the given key.
|
||||
*
|
||||
* @param mixed $offset The key to retrieve the value for.
|
||||
*
|
||||
* @return mixed The value associated with the given key.
|
||||
*/
|
||||
public function offsetGet(mixed $offset): mixed {
|
||||
self::sanitize_event_key($offset);
|
||||
if ($offset === self::BODY_ARRAY_KEY) {
|
||||
@@ -292,6 +365,16 @@ class event_message implements filterable_payload {
|
||||
return $this->event[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for a given offset in this object.
|
||||
*
|
||||
* @param mixed $offset The key or index to set the value for. If it is
|
||||
* {@link self::BODY_ARRAY_KEY}, this method will replace the
|
||||
* entire body of the event with the provided value.
|
||||
* @param mixed $value The new value to be associated with the offset.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet(mixed $offset, mixed $value): void {
|
||||
self::sanitize_event_key($offset);
|
||||
if ($offset === self::BODY_ARRAY_KEY) {
|
||||
@@ -301,6 +384,15 @@ class event_message implements filterable_payload {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets a property from the event array.
|
||||
*
|
||||
* This method first sanitizes the provided offset using the sanitize_event_key method to prevent potential security vulnerabilities.
|
||||
* If the sanitized offset is equal to the BODY_ARRAY_KEY, it sets the body property of this object to null.
|
||||
* Otherwise, it removes the specified key from the event array.
|
||||
*
|
||||
* @param mixed $offset The index or key to be unset from the event array.
|
||||
*/
|
||||
public function offsetUnset(mixed $offset): void {
|
||||
self::sanitize_event_key($offset);
|
||||
if ($offset === self::BODY_ARRAY_KEY) {
|
||||
|
||||
@@ -35,6 +35,11 @@ class extension_filter {
|
||||
|
||||
private $extensions;
|
||||
|
||||
/**
|
||||
* Initializes the class with an array of extensions for fast lookup.
|
||||
*
|
||||
* @param array $extensions An optional array of extension configurations. Defaults to [].
|
||||
*/
|
||||
public function __construct(array $extensions = []) {
|
||||
//organize the extensions in a way we can use isset for fast lookup
|
||||
foreach ($extensions as $extension) {
|
||||
@@ -43,6 +48,14 @@ class extension_filter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes this instance with a key-value pair for fast lookup.
|
||||
*
|
||||
* @param string $key The presence ID key to look up in the extensions array.
|
||||
* @param mixed $value The value associated with the key, which is used as an index in the extensions array.
|
||||
*
|
||||
* @return bool|null True if no match was found or the key is not 'channel_presence_id', null otherwise when dropping a message.
|
||||
*/
|
||||
public function __invoke(string $key, $value): ?bool {
|
||||
//only match on channel_presence_id key
|
||||
if ($key === 'channel_presence_id' && !isset($this->extensions[$value])) {
|
||||
|
||||
@@ -1,124 +1,138 @@
|
||||
<?php
|
||||
|
||||
class azure{
|
||||
class azure {
|
||||
|
||||
public static $formats = array (
|
||||
/**
|
||||
* Array of available speech formats.
|
||||
*
|
||||
* This array contains a list of voice names and their corresponding languages
|
||||
* and genders. The keys are the voice names, and the values are arrays containing
|
||||
* the language code and gender.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $formats = [
|
||||
'English-Zira' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'en-US',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)',
|
||||
],
|
||||
'English-Jessa' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'en-US',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)',
|
||||
],
|
||||
'English-Benjamin' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'en-US',
|
||||
'gender' => 'Male',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, BenjaminRUS)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-US, BenjaminRUS)',
|
||||
],
|
||||
'British-Susan' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'en-GB',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, Susan, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, Susan, Apollo)',
|
||||
],
|
||||
'British-Hazel' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'en-GB',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, HazelRUS)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, HazelRUS)',
|
||||
],
|
||||
'British-George' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'en-GB',
|
||||
'gender' => 'Male',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, George, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-GB, George, Apollo)',
|
||||
],
|
||||
'Australian-Catherine' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'en-AU',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-AU, Catherine)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (en-AU, Catherine)',
|
||||
],
|
||||
'Spanish-Helena' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'es-ES',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, HelenaRUS)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, HelenaRUS)',
|
||||
],
|
||||
'Spanish-Laura' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'es-ES',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, Laura, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, Laura, Apollo)',
|
||||
],
|
||||
'Spanish-Pablo' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'es-ES',
|
||||
'gender' => 'Male',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, Pablo, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (es-ES, Pablo, Apollo)',
|
||||
],
|
||||
'French-Julie' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'fr-FR',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, Julie, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, Julie, Apollo)',
|
||||
],
|
||||
'French-Hortense' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'fr-FR',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, HortenseRUS)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, HortenseRUS)',
|
||||
],
|
||||
'French-Paul' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'fr-FR',
|
||||
'gender' => 'Male',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, Paul, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (fr-FR, Paul, Apollo)',
|
||||
],
|
||||
'German-Hedda' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'de-DE',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (de-DE, Hedda)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (de-DE, Hedda)',
|
||||
],
|
||||
'Russian-Irina' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'ru-RU',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (ru-RU, Irina, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (ru-RU, Irina, Apollo)',
|
||||
],
|
||||
'Russian-Pavel' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'ru-RU',
|
||||
'gender' => 'Male',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (ru-RU, Pavel, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (ru-RU, Pavel, Apollo)',
|
||||
],
|
||||
'Chinese-Huihui' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'zh-CN',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, HuihuiRUS)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, HuihuiRUS)',
|
||||
],
|
||||
'Chinese-Yaoyao' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'zh-CN',
|
||||
'gender' => 'Female',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, Yaoyao, Apollo)'
|
||||
),
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, Yaoyao, Apollo)',
|
||||
],
|
||||
'Chinese-Kangkang' =>
|
||||
array (
|
||||
[
|
||||
'lang' => 'zh-CN',
|
||||
'gender' => 'Male',
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, Kangkang, Apollo)'
|
||||
)
|
||||
);
|
||||
'name' => 'Microsoft Server Speech Text to Speech Voice (zh-CN, Kangkang, Apollo)',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Initializes the object with provided setting array.
|
||||
*
|
||||
* @param array $setting_array An optional array of setting values. Defaults to an empty array.
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
$domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
|
||||
@@ -130,34 +144,58 @@ class azure{
|
||||
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]);
|
||||
}
|
||||
|
||||
private static function getTokenUrl(){
|
||||
/**
|
||||
* Returns the URL for obtaining a token from Microsoft Cognitive Services.
|
||||
*
|
||||
* @return string The URL for issuing a token
|
||||
*/
|
||||
private static function getTokenUrl() {
|
||||
return "https://api.cognitive.microsoft.com/sts/v1.0/issueToken";
|
||||
}
|
||||
|
||||
private static function getApiUrl(){
|
||||
/**
|
||||
* Returns the URL for interacting with Microsoft Bing Speech API.
|
||||
*
|
||||
* @return string The URL for making requests to the Bing Speech API
|
||||
*/
|
||||
private static function getApiUrl() {
|
||||
return "https://speech.platform.bing.com/synthesize";
|
||||
}
|
||||
|
||||
private static function getSubscriptionKey(settings $settings){
|
||||
/**
|
||||
* Returns the subscription key from Azure settings.
|
||||
*
|
||||
* @param settings $settings The settings object containing Azure configuration
|
||||
*
|
||||
* @return string The subscription key for Azure services
|
||||
*/
|
||||
private static function getSubscriptionKey(settings $settings) {
|
||||
return $settings->get('azure', 'key');
|
||||
}
|
||||
|
||||
private static function _getToken(settings $settings){
|
||||
/**
|
||||
* Obtains a token from Microsoft Cognitive Services.
|
||||
*
|
||||
* @param settings $settings Settings object containing subscription key and other parameters.
|
||||
*
|
||||
* @return string The response from the server, which is expected to be an XML token.
|
||||
*/
|
||||
private static function _getToken(settings $settings) {
|
||||
$url = self::getTokenUrl();
|
||||
$subscriptionKey = self::getSubscriptionKey($settings);
|
||||
|
||||
$headers = array();
|
||||
$headers[] = 'Ocp-Apim-Subscription-Key: '. $subscriptionKey;
|
||||
$headers = [];
|
||||
$headers[] = 'Ocp-Apim-Subscription-Key: ' . $subscriptionKey;
|
||||
$headers[] = 'Content-Length: 0';
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt ( $ch, CURLOPT_URL, $url );
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
//curl_setopt($ch, CURLOPT_SSLVERSION, 1);
|
||||
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 60 );
|
||||
curl_setopt ( $ch, CURLOPT_TIMEOUT, 300 );
|
||||
curl_setopt ( $ch, CURLOPT_VERBOSE, false);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
//curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
|
||||
|
||||
@@ -167,7 +205,16 @@ class azure{
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function synthesize(settings $settings, $data, $format_key){
|
||||
/**
|
||||
* Synthesizes the given data into a WAV audio file using Microsoft Cognitive Services.
|
||||
*
|
||||
* @param object $settings Settings for the API call
|
||||
* @param string $data The text to be synthesized
|
||||
* @param string $format_key The key of the format in self::$formats
|
||||
*
|
||||
* @return string The path to the generated WAV file
|
||||
*/
|
||||
public static function synthesize(settings $settings, $data, $format_key) {
|
||||
|
||||
$lang = self::$formats[$format_key]['lang'];
|
||||
$gender = self::$formats[$format_key]['gender'];
|
||||
@@ -176,32 +223,32 @@ class azure{
|
||||
|
||||
$url = self::getApiUrl();
|
||||
|
||||
$headers = array();
|
||||
$headers[] = 'Authorization: Bearer '. $token;
|
||||
$headers = [];
|
||||
$headers[] = 'Authorization: Bearer ' . $token;
|
||||
$headers[] = 'Content-Type: application/ssml+xml';
|
||||
$headers[] = 'X-Microsoft-OutputFormat: riff-16khz-16bit-mono-pcm';
|
||||
$headers[] = 'User-Agent: TTS';
|
||||
|
||||
$xml_post_string = "<speak version='1.0' xml:lang='".$lang."'>
|
||||
<voice xml:lang='".$lang."' xml:gender='".$gender."' name='".$name."'>";
|
||||
$xml_post_string = "<speak version='1.0' xml:lang='" . $lang . "'>
|
||||
<voice xml:lang='" . $lang . "' xml:gender='" . $gender . "' name='" . $name . "'>";
|
||||
$xml_post_string .= $data;
|
||||
$xml_post_string .= "</voice>
|
||||
</speak>";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt ( $ch, CURLOPT_URL, $url );
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
//curl_setopt($ch, CURLOPT_SSLVERSION, 1);
|
||||
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 60 );
|
||||
curl_setopt ( $ch, CURLOPT_TIMEOUT, 300 );
|
||||
curl_setopt ( $ch, CURLOPT_VERBOSE, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$filename = "tts_".time().".wav";
|
||||
file_put_contents("/var/www/html/fusionpbx/app/voiplyrecording/tts_record/".$filename, $response);
|
||||
$filename = "tts_" . time() . ".wav";
|
||||
file_put_contents("/var/www/html/fusionpbx/app/voiplyrecording/tts_record/" . $filename, $response);
|
||||
|
||||
curl_close($ch);
|
||||
return $filename;
|
||||
|
||||
@@ -66,7 +66,9 @@
|
||||
private $domain_name;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
* Initializes the object with domain and user UUIDs, domain name, and database objects.
|
||||
*
|
||||
* @param array $setting_array An optional array containing settings for this object. Defaults to an empty array.
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -83,7 +85,10 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the call activity
|
||||
* Handles the call activity by retrieving extensions and their user status,
|
||||
* sending a command to retrieve active calls, and building a response array.
|
||||
*
|
||||
* @return mixed The response array containing extension details and active call information.
|
||||
*/
|
||||
public function call_activity() {
|
||||
|
||||
|
||||
@@ -68,7 +68,9 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with settings and default values.
|
||||
*
|
||||
* @param array $setting_array Associative array of setting keys to their respective values (optional)
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -92,7 +94,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or multiple records from the access controls table.
|
||||
*
|
||||
* @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')) {
|
||||
@@ -141,7 +149,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of the specified 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
@@ -212,7 +226,12 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
|
||||
@@ -456,6 +456,17 @@ if (permission_exists('call_block_all') || permission_exists('call_block_ring_gr
|
||||
echo " ".$text['label-action']."\n";
|
||||
echo "</td>\n";
|
||||
echo "<td class='vtable' align='left'>\n";
|
||||
/**
|
||||
* Select a call block action.
|
||||
*
|
||||
* This function generates an HTML select element for selecting a call block
|
||||
* action. It includes options for rejecting, busy, holding, and other actions,
|
||||
* as well as options for extensions, IVRs, ring groups, and voicemail.
|
||||
*
|
||||
* @param bool $label Whether to include the label option or not.
|
||||
*
|
||||
* @return void The function does not return any value.
|
||||
*/
|
||||
function call_block_action_select($label = false) {
|
||||
global $select_margin, $text, $call_block_app, $call_block_data, $extensions, $ivrs, $voicemails, $ring_groups;
|
||||
echo "<select class='formfld' style='".$select_margin."' name='call_block_action'>\n";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* call block class
|
||||
*/
|
||||
class call_block {
|
||||
class call_block {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -13,30 +13,38 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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 name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -60,7 +68,12 @@
|
||||
public $call_block_data;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -79,14 +92,20 @@
|
||||
$this->table = 'call_block';
|
||||
$this->uuid_prefix = 'call_block_';
|
||||
$this->toggle_field = 'call_block_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -95,8 +114,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -104,22 +123,22 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//filter out unchecked, build where clause for below
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary call block details
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, call_block_number from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, call_block_number from v_" . $this->table . " ";
|
||||
$sql .= "where ( ";
|
||||
$sql .= " domain_uuid = :domain_uuid ";
|
||||
if (permission_exists('call_block_domain')) {
|
||||
$sql .= " or domain_uuid is null ";
|
||||
}
|
||||
$sql .= ") ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -133,7 +152,7 @@
|
||||
//build the delete array
|
||||
$x = 0;
|
||||
foreach ($call_block_numbers as $call_block_uuid => $call_block_number) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $call_block_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $call_block_uuid;
|
||||
if (!permission_exists('call_block_domain')) {
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
@@ -150,7 +169,7 @@
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
foreach ($call_block_numbers as $call_block_number) {
|
||||
$cache->delete("app:call_block:".$this->domain_name.":".$call_block_number);
|
||||
$cache->delete("app:call_block:" . $this->domain_name . ":" . $call_block_number);
|
||||
}
|
||||
|
||||
//set message
|
||||
@@ -162,10 +181,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -174,8 +199,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -185,13 +210,13 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, call_block_number from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, call_block_number from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -206,7 +231,7 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -222,7 +247,7 @@
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
foreach ($call_block_numbers as $call_block_number) {
|
||||
$cache->delete("app:call_block:".$this->domain_name.":".$call_block_number);
|
||||
$cache->delete("app:call_block:" . $this->domain_name . ":" . $call_block_number);
|
||||
}
|
||||
|
||||
//set message
|
||||
@@ -235,10 +260,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -247,8 +278,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -258,22 +289,22 @@
|
||||
//get checked records
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create insert array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $x => $row) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -284,8 +315,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = uuid();
|
||||
$array[$this->table][$x]['call_block_description'] = trim($row['call_block_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = uuid();
|
||||
$array[$this->table][$x]['call_block_description'] = trim($row['call_block_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -311,10 +342,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* add records
|
||||
* Adds one or more 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 add($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -323,8 +360,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -334,14 +371,14 @@
|
||||
//filter checked records
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get the caller id info from call detail records
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select caller_id_name, caller_id_number, caller_destination from v_xml_cdr ";
|
||||
$sql .= "where xml_cdr_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "where xml_cdr_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
@@ -386,15 +423,13 @@
|
||||
foreach ($rows as $x => $row) {
|
||||
|
||||
//remove e.164 and country code
|
||||
if (substr($row["caller_id_number"],0,1) == "+") {
|
||||
if (substr($row["caller_id_number"], 0, 1) == "+") {
|
||||
//format e.164
|
||||
$call_block_number = str_replace("+".trim($country_code), "", trim($row["caller_id_number"]));
|
||||
}
|
||||
elseif (!empty($row["caller_id_number"])) {
|
||||
$call_block_number = str_replace("+" . trim($country_code), "", trim($row["caller_id_number"]));
|
||||
} elseif (!empty($row["caller_id_number"])) {
|
||||
//remove the country code if its the first in the string
|
||||
$call_block_number = ltrim(trim($row["caller_id_number"]), $country_code ?? '');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$call_block_number = '';
|
||||
}
|
||||
|
||||
@@ -421,8 +456,7 @@
|
||||
$array['call_block'][$x]['call_block_enabled'] = true;
|
||||
$array['call_block'][$x]['date_added'] = time();
|
||||
$x++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (is_array($user_extensions)) {
|
||||
foreach ($user_extensions as $field) {
|
||||
if (is_uuid($field['extension_uuid'])) {
|
||||
@@ -459,7 +493,7 @@
|
||||
//ensure call block is enabled in the dialplan (build update array)
|
||||
$sql = "select dialplan_uuid from v_dialplans ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and app_uuid = '".self::app_uuid."' ";
|
||||
$sql .= "and app_uuid = '" . self::app_uuid . "' ";
|
||||
$sql .= "and dialplan_enabled <> true ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters);
|
||||
@@ -494,4 +528,4 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -61,7 +61,15 @@
|
||||
$broadcast_toll_allow = '';
|
||||
|
||||
//function to Upload CSV/TXT file
|
||||
function upload_file($sql, $broadcast_phone_numbers) {
|
||||
/**
|
||||
* Uploads a file and prepares the SQL query for broadcasting phone numbers.
|
||||
*
|
||||
* @param string $sql The initial SQL query.
|
||||
* @param mixed $broadcast_phone_numbers The phone numbers to broadcast, or an empty value if not applicable.
|
||||
*
|
||||
* @return array An array containing the result code ('code') and the prepared SQL query ('sql').
|
||||
*/
|
||||
function upload_file($sql, $broadcast_phone_numbers) {
|
||||
$upload_csv = $sql = '';
|
||||
if (isset($_FILES['broadcast_phone_numbers_file']) && !empty($_FILES['broadcast_phone_numbers_file']) && $_FILES['broadcast_phone_numbers_file']['size'] > 0) {
|
||||
$filename=$_FILES["broadcast_phone_numbers_file"]["tmp_name"];
|
||||
|
||||
@@ -46,6 +46,17 @@
|
||||
ini_set('max_execution_time',3600);
|
||||
|
||||
//define the asynchronous command function
|
||||
/**
|
||||
* Asynchronously executes a command.
|
||||
*
|
||||
* This method runs the given $cmd as an asynchronous process. On Windows, it uses
|
||||
* proc_open to create a new process with pipes for stdin, stdout, and stderr. On
|
||||
* Posix systems (e.g., Linux, macOS), it uses exec to run the command in the background.
|
||||
*
|
||||
* @param string $cmd The command to execute asynchronously.
|
||||
*
|
||||
* @return int|bool The return value of proc_close() on Windows or false on failure; null if not executed successfully.
|
||||
*/
|
||||
function cmd_async($cmd) {
|
||||
//windows
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
/**
|
||||
* call broadcast class
|
||||
*/
|
||||
class call_broadcast {
|
||||
class call_broadcast {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -38,18 +38,23 @@
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
*
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -63,7 +68,11 @@
|
||||
private $uuid_prefix;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with the provided settings.
|
||||
*
|
||||
* @param array $setting_array An optional array of settings, defaulting to an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -81,10 +90,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -93,8 +108,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -102,9 +117,9 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//build the delete array
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $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][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
}
|
||||
@@ -125,10 +140,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -137,8 +158,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -146,17 +167,17 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create insert array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -166,8 +187,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = uuid();
|
||||
$array[$this->table][$x]['broadcast_description'] = trim($row['broadcast_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = uuid();
|
||||
$array[$this->table][$x]['broadcast_description'] = trim($row['broadcast_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -192,4 +213,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,15 @@
|
||||
}
|
||||
|
||||
//convert the string to a named array
|
||||
/**
|
||||
* Converts a string into a named array based on the specified delimiter.
|
||||
*
|
||||
* @param string $tmp_str The input string to be converted.
|
||||
* @param string $tmp_delimiter The delimiter used to split the string and field values.
|
||||
*
|
||||
* @return array A 2D array where each inner array represents a row in the original string,
|
||||
* with keys corresponding to the field names from the first line of the string.
|
||||
*/
|
||||
function str_to_named_array($tmp_str, $tmp_delimiter) {
|
||||
$tmp_array = explode ("\n", $tmp_str);
|
||||
$result = array();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* cache class provides an abstracted cache
|
||||
*/
|
||||
//define the call center class
|
||||
class call_center {
|
||||
class call_center {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -37,7 +37,9 @@
|
||||
const app_uuid = '95788e50-9500-079e-2807-fd530b0ea370';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
@@ -57,18 +59,23 @@
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
*
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -82,7 +89,11 @@
|
||||
private $uuid_prefix;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
* Initializes the object with provided settings.
|
||||
*
|
||||
* @param array $setting_array Optional array containing domain and user UUIDs, and database instance.
|
||||
* If not provided, default values from session will be used.
|
||||
* Database instance will be created if it is not set in the array.
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -95,9 +106,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a dialplan for call center
|
||||
* @var string $domain_uuid the multi-tenant id
|
||||
* @var string $value string to be cached
|
||||
* Saves or updates the dial plan.
|
||||
*
|
||||
* This method first checks if a previous dial plan exists. If it does, it is deleted.
|
||||
* Then, a new dial plan array is built with the necessary settings and conditions.
|
||||
* The new dial plan is then saved to the database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dialplan() {
|
||||
|
||||
@@ -155,7 +170,7 @@
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "^".$this->destination_number."\$";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "^" . $this->destination_number . "\$";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_break"] = "";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
|
||||
@@ -179,7 +194,7 @@
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "effective_caller_id_name=".$this->queue_cid_prefix."#\${caller_id_name}";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "effective_caller_id_name=" . $this->queue_cid_prefix . "#\${caller_id_name}";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
|
||||
$y++;
|
||||
@@ -199,7 +214,7 @@
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "playback";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "".$this->queue_greeting;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "" . $this->queue_greeting;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
|
||||
$y++;
|
||||
@@ -209,7 +224,7 @@
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "cc_exit_keys=".$this->queue_cc_exit_keys;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "cc_exit_keys=" . $this->queue_cc_exit_keys;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
|
||||
$y++;
|
||||
@@ -218,17 +233,17 @@
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "callcenter";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $this->queue_name.'@'.$this->domain_name;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $this->queue_name . '@' . $this->domain_name;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
|
||||
$y++;
|
||||
|
||||
if (!empty($this->queue_timeout_action)) {
|
||||
$action_array = explode(":",$this->queue_timeout_action);
|
||||
$action_array = explode(":", $this->queue_timeout_action);
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $action_array[0];
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = substr($this->queue_timeout_action, strlen($action_array[0])+1, strlen($this->queue_timeout_action));
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = substr($this->queue_timeout_action, strlen($action_array[0]) + 1, strlen($this->queue_timeout_action));
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10;
|
||||
$y++;
|
||||
@@ -280,7 +295,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//return the dialplan_uuid
|
||||
return $dialplan_response;
|
||||
@@ -288,7 +303,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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_queues($records) {
|
||||
|
||||
@@ -298,7 +319,7 @@
|
||||
$this->table = 'call_center_queues';
|
||||
$this->uuid_prefix = 'call_center_queue_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -307,8 +328,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -324,9 +345,9 @@
|
||||
|
||||
//get necessary details
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid, queue_name, queue_extension from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, dialplan_uuid, queue_name, queue_extension from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in ('".implode("','", $uuids)."') ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in ('" . implode("','", $uuids) . "') ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -342,16 +363,16 @@
|
||||
//build the delete array
|
||||
$x = 0;
|
||||
foreach ($call_center_queues as $call_center_queue_uuid => $call_center_queue) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $call_center_queue_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $call_center_queue_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $call_center_queue['dialplan_uuid'];
|
||||
$array['dialplans'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['dialplan_details'][$x]['dialplan_uuid'] = $call_center_queue['dialplan_uuid'];
|
||||
$array['dialplan_details'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['call_center_tiers'][$x][$this->uuid_prefix.'uuid'] = $call_center_queue_uuid;
|
||||
$array['call_center_tiers'][$x][$this->uuid_prefix . 'uuid'] = $call_center_queue_uuid;
|
||||
$array['call_center_tiers'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$x++;
|
||||
$array['call_center_tiers'][$x]['queue_name'] = $call_center_queue['queue_extension']."@".$this->domain_name;
|
||||
$array['call_center_tiers'][$x]['queue_name'] = $call_center_queue['queue_extension'] . "@" . $this->domain_name;
|
||||
$array['call_center_tiers'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -365,7 +386,7 @@
|
||||
//delete the queue in the switch
|
||||
if ($esl->is_connected()) {
|
||||
foreach ($uuids as $uuid) {
|
||||
$cmd = "callcenter_config queue unload ".$call_center_queues[$uuid]['queue_extension']."@".$this->domain_name;
|
||||
$cmd = "callcenter_config queue unload " . $call_center_queues[$uuid]['queue_extension'] . "@" . $this->domain_name;
|
||||
$response = event_socket::api($cmd);
|
||||
}
|
||||
}
|
||||
@@ -387,7 +408,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
remove_config_from_cache('configuration:callcenter.conf');
|
||||
|
||||
//clear the destinations session array
|
||||
@@ -409,6 +430,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple call center agents.
|
||||
*
|
||||
* @param array $records A list of records to delete, where each record is an associative array containing a 'uuid'
|
||||
* key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_agents($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -417,7 +446,7 @@
|
||||
$this->table = 'call_center_agents';
|
||||
$this->uuid_prefix = 'call_center_agent_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -426,8 +455,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -444,7 +473,7 @@
|
||||
//build the delete array
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
foreach ($uuids as $x => $uuid) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['call_center_tiers'][$x]['call_center_agent_uuid'] = $uuid;
|
||||
$array['call_center_tiers'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -487,9 +516,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy_queues($records) {
|
||||
|
||||
@@ -499,7 +533,7 @@
|
||||
$this->table = 'call_center_queues';
|
||||
$this->uuid_prefix = 'call_center_queue_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -508,8 +542,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -527,8 +561,8 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in ('".implode("','", $uuids)."') ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in ('" . implode("','", $uuids) . "') ";
|
||||
$rows = $this->database->select($sql, null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
$y = 0;
|
||||
@@ -537,7 +571,7 @@
|
||||
$new_dialplan_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -548,9 +582,9 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_call_center_queue_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $new_call_center_queue_uuid;
|
||||
$array[$this->table][$x]['dialplan_uuid'] = $new_dialplan_uuid;
|
||||
$array[$this->table][$x]['queue_description'] = trim($row['queue_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x]['queue_description'] = trim($row['queue_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//call center tiers sub table
|
||||
$sql_2 = "select * from v_call_center_tiers where call_center_queue_uuid = :call_center_queue_uuid";
|
||||
@@ -578,7 +612,7 @@
|
||||
if (is_array($dialplan) && @sizeof($dialplan) != 0) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($dialplan as $key => $value) {
|
||||
foreach ($dialplan as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$dialplan[$key] = $value;
|
||||
@@ -594,7 +628,7 @@
|
||||
$dialplan_xml = str_replace($row['call_center_queue_uuid'], $new_call_center_queue_uuid, $dialplan_xml); //replace source call_center_queue_uuid with new
|
||||
$dialplan_xml = str_replace($dialplan['dialplan_uuid'], $new_dialplan_uuid, $dialplan_xml); //replace source dialplan_uuid with new
|
||||
$array['dialplans'][$x]['dialplan_xml'] = $dialplan_xml;
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'].' ('.$text['label-copy'].')');
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
unset($sql_3, $parameters_3, $dialplan);
|
||||
@@ -624,7 +658,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//set message
|
||||
message::add($text['message-copy']);
|
||||
@@ -636,7 +670,7 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
/*
|
||||
$o = new call_center;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the call_flows class
|
||||
class call_flows {
|
||||
class call_flows {
|
||||
|
||||
/**
|
||||
* declare public variables
|
||||
@@ -40,30 +40,38 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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 name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -78,7 +86,11 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* 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
|
||||
@@ -94,14 +106,20 @@
|
||||
$this->list_page = 'call_flows.php';
|
||||
$this->table = 'call_flows';
|
||||
$this->uuid_prefix = 'call_flow_';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or multiple records from the access controls table.
|
||||
*
|
||||
* @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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -110,8 +128,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -121,15 +139,15 @@
|
||||
//filter out unchecked call flows, build where clause for below
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary call flow details
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid, call_flow_context from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, dialplan_uuid, call_flow_context from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -144,7 +162,7 @@
|
||||
//build the delete array
|
||||
$x = 0;
|
||||
foreach ($call_flows as $call_flow_uuid => $call_flow) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $call_flow_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $call_flow_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $call_flow['dialplan_uuid'];
|
||||
$array['dialplans'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -177,7 +195,7 @@
|
||||
$call_flow_contexts = array_unique($call_flow_contexts);
|
||||
$cache = new cache;
|
||||
foreach ($call_flow_contexts as $call_flow_context) {
|
||||
$cache->delete("dialplan:".$call_flow_context);
|
||||
$cache->delete("dialplan:" . $call_flow_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,10 +213,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
@@ -206,8 +230,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -215,17 +239,17 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($uuids)) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, ";
|
||||
$sql .= "dialplan_uuid, call_flow_feature_code, call_flow_context from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, ";
|
||||
$sql .= "dialplan_uuid, call_flow_feature_code, call_flow_context from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (!empty($rows)) {
|
||||
@@ -241,8 +265,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($call_flows as $uuid => $call_flow) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($call_flows as $uuid => $call_flow) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $call_flow['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
if ($this->toggle_field == 'call_flow_enabled') {
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $call_flow['dialplan_uuid'];
|
||||
@@ -274,7 +298,7 @@
|
||||
$call_flow_contexts = array_unique($call_flow_contexts);
|
||||
$cache = new cache;
|
||||
foreach ($call_flow_contexts as $call_flow_context) {
|
||||
$cache->delete("dialplan:".$call_flow_context);
|
||||
$cache->delete("dialplan:" . $call_flow_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,23 +314,22 @@
|
||||
|
||||
//toggle the presence
|
||||
if ($this->toggle_field != 'call_flow_enabled') {
|
||||
foreach($call_flows as $uuid => $row) {
|
||||
foreach ($call_flows as $uuid => $row) {
|
||||
//prepare the event
|
||||
$cmd = "sendevent PRESENCE_IN\n";
|
||||
$cmd .= "proto: flow\n";
|
||||
$cmd .= "login: ".$row['call_flow_feature_code']."@".$this->domain_name."\n";
|
||||
$cmd .= "from: ".$row['call_flow_feature_code']."@".$this->domain_name."\n";
|
||||
$cmd .= "login: " . $row['call_flow_feature_code'] . "@" . $this->domain_name . "\n";
|
||||
$cmd .= "from: " . $row['call_flow_feature_code'] . "@" . $this->domain_name . "\n";
|
||||
$cmd .= "status: Active (1 waiting)\n";
|
||||
$cmd .= "rpid: unknown\n";
|
||||
$cmd .= "event_type: presence\n";
|
||||
$cmd .= "alt_event_type: dialog\n";
|
||||
$cmd .= "event_count: 1\n";
|
||||
$cmd .= "unique-id: ".uuid()."\n";
|
||||
$cmd .= "unique-id: " . uuid() . "\n";
|
||||
$cmd .= "Presence-Call-Direction: outbound\n";
|
||||
if ($call_flow['state'] == 'true') {
|
||||
$cmd .= "answer-state: confirmed\n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$cmd .= "answer-state: terminated\n";
|
||||
}
|
||||
|
||||
@@ -322,10 +345,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -334,8 +363,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -343,9 +372,9 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,9 +382,9 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -364,7 +393,7 @@
|
||||
$new_dialplan_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -375,9 +404,9 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_call_flow_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $new_call_flow_uuid;
|
||||
$array[$this->table][$x]['dialplan_uuid'] = $new_dialplan_uuid;
|
||||
$array[$this->table][$x]['call_flow_description'] = trim($row['call_flow_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x]['call_flow_description'] = trim($row['call_flow_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//call flow dialplan record
|
||||
$sql_2 = "select * from v_dialplans where dialplan_uuid = :dialplan_uuid";
|
||||
@@ -386,7 +415,7 @@
|
||||
if (is_array($dialplan) && @sizeof($dialplan) != 0) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($dialplan as $key => $value) {
|
||||
foreach ($dialplan as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$dialplan[$key] = $value;
|
||||
@@ -402,7 +431,7 @@
|
||||
$dialplan_xml = str_replace($row['call_flow_uuid'], $new_call_flow_uuid, $dialplan_xml); //replace source call_flow_uuid with new
|
||||
$dialplan_xml = str_replace($dialplan['dialplan_uuid'], $new_dialplan_uuid, $dialplan_xml); //replace source dialplan_uuid with new
|
||||
$array['dialplans'][$x]['dialplan_xml'] = $dialplan_xml;
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'].' ('.$text['label-copy'].')');
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
unset($sql_2, $parameters_2, $dialplan);
|
||||
@@ -437,7 +466,7 @@
|
||||
$call_flow_contexts = array_unique($call_flow_contexts);
|
||||
$cache = new cache;
|
||||
foreach ($call_flow_contexts as $call_flow_context) {
|
||||
$cache->delete("dialplan:".$call_flow_context);
|
||||
$cache->delete("dialplan:" . $call_flow_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,4 +480,4 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -49,6 +49,15 @@
|
||||
$text = $language->get();
|
||||
|
||||
//define the destination_select function
|
||||
/**
|
||||
* Displays a select input element with options for destinations.
|
||||
*
|
||||
* @param string $select_name The name attribute of the select input element.
|
||||
* @param int $select_value The value to be selected in the select input element.
|
||||
* @param int $select_default The default value if select_value is empty.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function destination_select($select_name, $select_value, $select_default) {
|
||||
if (empty($select_value)) { $select_value = $select_default; }
|
||||
echo " <select class='formfld' style='width: 55px;' name='$select_name'>\n";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
//define the call_forward class
|
||||
class call_forward {
|
||||
class call_forward {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -38,13 +38,17 @@
|
||||
const app_uuid = '19806921-e8ed-dcff-b325-dd3e5da4959d';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
|
||||
* in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $domain_name;
|
||||
@@ -62,18 +66,22 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
@@ -88,7 +96,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -105,6 +118,11 @@
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extension with the provided values.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set() {
|
||||
|
||||
//determine whether to update the dial string
|
||||
@@ -146,15 +164,20 @@
|
||||
|
||||
//delete extension from the cache
|
||||
$cache = new cache;
|
||||
$cache->delete(gethostname().":directory:" . $this->extension . "@" . $this->domain_name);
|
||||
$cache->delete(gethostname() . ":directory:" . $this->extension . "@" . $this->domain_name);
|
||||
if (!empty($this->number_alias)) {
|
||||
$cache->delete(gethostname().":directory:" . $this->number_alias . "@" . $this->domain_name);
|
||||
$cache->delete(gethostname() . ":directory:" . $this->number_alias . "@" . $this->domain_name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle an array of call_forward records
|
||||
* @param array $records array of records to toggle
|
||||
* Toggles the state of one or more 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 toggle(array $records) {
|
||||
|
||||
@@ -293,9 +316,9 @@
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
foreach ($extensions as $uuid => $extension) {
|
||||
$cache->delete(gethostname().":directory:" . $extension['extension'] . "@" . $_SESSION['domain_name']);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension['extension'] . "@" . $_SESSION['domain_name']);
|
||||
if ($extension['number_alias'] != '') {
|
||||
$cache->delete(gethostname().":directory:" . $extension['number_alias'] . "@" . $_SESSION['domain_name']);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension['number_alias'] . "@" . $_SESSION['domain_name']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,6 +329,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/**
|
||||
* call_recordings class
|
||||
*/
|
||||
class call_recordings {
|
||||
class call_recordings {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -37,36 +37,46 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Username 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 $username;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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 name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -82,7 +92,12 @@
|
||||
public $binary;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -102,10 +117,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -114,8 +135,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -134,8 +155,8 @@
|
||||
$field = $this->database->select($sql, $parameters, 'row');
|
||||
if (is_array($field) && @sizeof($field) != 0) {
|
||||
//delete the file on the file system
|
||||
if (file_exists($field['call_recording_path'].'/'.$field['call_recording_name'])) {
|
||||
unlink($field['call_recording_path'].'/'.$field['call_recording_name']);
|
||||
if (file_exists($field['call_recording_path'] . '/' . $field['call_recording_name'])) {
|
||||
unlink($field['call_recording_path'] . '/' . $field['call_recording_name']);
|
||||
}
|
||||
|
||||
//build call recording delete array
|
||||
@@ -178,10 +199,14 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* transcribe call recordings
|
||||
* Transcribes multiple call recordings.
|
||||
*
|
||||
* @param array $records An array of records to transcribe.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function transcribe($records) {
|
||||
if (permission_exists($this->name.'_view')) {
|
||||
if (permission_exists($this->name . '_view')) {
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
@@ -189,8 +214,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -219,7 +244,7 @@
|
||||
if (
|
||||
is_array($field) &&
|
||||
@sizeof($field) != 0 &&
|
||||
file_exists($field['call_recording_path'].'/'.$field['call_recording_name'])
|
||||
file_exists($field['call_recording_path'] . '/' . $field['call_recording_name'])
|
||||
) {
|
||||
//audio to text - get the transcription from the audio file
|
||||
$transcribe->audio_path = $field['call_recording_path'];
|
||||
@@ -267,7 +292,11 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* download the recordings
|
||||
* Downloads one or multiple call recordings.
|
||||
*
|
||||
* @param array $records An optional array of recording UUIDs to download. If null, the method will attempt to download a single recording based on the current object's recording_uuid property.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function download($records = null) {
|
||||
if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) {
|
||||
@@ -280,8 +309,7 @@
|
||||
//set the time zone
|
||||
if (!empty($time_zone)) {
|
||||
$time_zone = $time_zone;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$time_zone = date_default_timezone_get();
|
||||
}
|
||||
|
||||
@@ -337,14 +365,14 @@
|
||||
$call_recording_time_formatted = $row['call_recording_time_formatted'];
|
||||
$call_recording_base64 = $row['call_recording_base64'];
|
||||
if (!empty($storage_type) && $storage_type == 'base64' && !empty($row['call_recording_base64'])) {
|
||||
file_put_contents($call_recording_path.'/'.$call_recording_name, base64_decode($row['call_recording_base64']));
|
||||
file_put_contents($call_recording_path . '/' . $call_recording_name, base64_decode($row['call_recording_base64']));
|
||||
}
|
||||
}
|
||||
unset($sql, $parameters, $row);
|
||||
}
|
||||
|
||||
//build full path
|
||||
$full_recording_path = $call_recording_path.'/'.$call_recording_name;
|
||||
$full_recording_path = $call_recording_path . '/' . $call_recording_name;
|
||||
|
||||
//created custom name
|
||||
$call_recording_name_download = $call_recording_name;
|
||||
@@ -372,21 +400,26 @@
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Type: application/download");
|
||||
header("Content-Description: File Transfer");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$file_ext = pathinfo($call_recording_name, PATHINFO_EXTENSION);
|
||||
switch ($file_ext) {
|
||||
case "wav" : header("Content-Type: audio/x-wav"); break;
|
||||
case "mp3" : header("Content-Type: audio/mpeg"); break;
|
||||
case "ogg" : header("Content-Type: audio/ogg"); break;
|
||||
case "wav" :
|
||||
header("Content-Type: audio/x-wav");
|
||||
break;
|
||||
case "mp3" :
|
||||
header("Content-Type: audio/mpeg");
|
||||
break;
|
||||
case "ogg" :
|
||||
header("Content-Type: audio/ogg");
|
||||
break;
|
||||
}
|
||||
}
|
||||
$call_recording_name_download = preg_replace('#[^a-zA-Z0-9_\-\.]#', '', $call_recording_name_download);
|
||||
header('Content-Disposition: attachment; filename="'.$call_recording_name_download.'"');
|
||||
header('Content-Disposition: attachment; filename="' . $call_recording_name_download . '"');
|
||||
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
||||
if ($this->binary) {
|
||||
header("Content-Length: ".filesize($full_recording_path));
|
||||
header("Content-Length: " . filesize($full_recording_path));
|
||||
}
|
||||
ob_clean();
|
||||
|
||||
@@ -412,8 +445,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -451,7 +484,7 @@
|
||||
$sql .= ", call_recording_base64 ";
|
||||
}
|
||||
$sql .= "from view_call_recordings ";
|
||||
$sql .= "where call_recording_uuid in ('".implode("','", $uuids)."') ";
|
||||
$sql .= "where call_recording_uuid in ('" . implode("','", $uuids) . "') ";
|
||||
$parameters['time_zone'] = $time_zone;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (!empty($rows) && is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -473,13 +506,13 @@
|
||||
$call_recording_date_formatted = $row['call_recording_date_formatted'];
|
||||
$call_recording_time_formatted = $row['call_recording_time_formatted'];
|
||||
if (!empty($storage_type) && $storage_type == 'base64' && !empty($row['call_recording_base64'])) {
|
||||
file_put_contents($call_recording_path.'/'.$call_recording_name, base64_decode($row['call_recording_base64']));
|
||||
file_put_contents($call_recording_path . '/' . $call_recording_name, base64_decode($row['call_recording_base64']));
|
||||
}
|
||||
|
||||
if (file_exists($call_recording_path.'/'.$call_recording_name)) {
|
||||
if (file_exists($call_recording_path . '/' . $call_recording_name)) {
|
||||
//add the original file to the array - use original file name
|
||||
if (empty($record_name)) {
|
||||
$full_recording_paths[] = $call_recording_path.'/'.$call_recording_name;
|
||||
$full_recording_paths[] = $call_recording_path . '/' . $call_recording_name;
|
||||
}
|
||||
|
||||
//created the custom name using the record_name as a template
|
||||
@@ -498,11 +531,11 @@
|
||||
$call_recording_name_download = str_replace('${time}', $call_recording_time, $call_recording_name_download);
|
||||
|
||||
//create a symbolic link with custom name
|
||||
$command = 'ln -s '.$call_recording_path.'/'.$call_recording_name.' '.$call_recording_path.'/'.$call_recording_name_download;
|
||||
$command = 'ln -s ' . $call_recording_path . '/' . $call_recording_name . ' ' . $call_recording_path . '/' . $call_recording_name_download;
|
||||
system($command);
|
||||
|
||||
//build the array for all the call recording with the new file name
|
||||
$full_recording_paths[] = $call_recording_path.'/'.$call_recording_name_download;
|
||||
$full_recording_paths[] = $call_recording_path . '/' . $call_recording_name_download;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,7 +551,7 @@
|
||||
header('Content-Disposition: attachment; filename="call_recordings.zip"');
|
||||
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
||||
passthru("zip -qj - ".implode(' ', $full_recording_paths));
|
||||
passthru("zip -qj - " . implode(' ', $full_recording_paths));
|
||||
}
|
||||
|
||||
//if base64, remove temp recording file
|
||||
@@ -566,7 +599,7 @@
|
||||
* (mediatype = mimetype)
|
||||
* as well as a boundry header to indicate the various chunks of data.
|
||||
*/
|
||||
header("Accept-Ranges: 0-".$length);
|
||||
header("Accept-Ranges: 0-" . $length);
|
||||
// header('Accept-Ranges: bytes');
|
||||
// multipart/byteranges
|
||||
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
|
||||
@@ -575,7 +608,7 @@
|
||||
$c_start = $start;
|
||||
$c_end = $end;
|
||||
// Extract the range string
|
||||
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
// Make sure the client hasn't sent us a multibyte range
|
||||
if (strpos($range, ',') !== false) {
|
||||
// (?) Shoud this be issued here, or should the first
|
||||
@@ -592,8 +625,7 @@
|
||||
if ($range[0] == '-') {
|
||||
// The n-number of the last bytes is requested
|
||||
$c_start = $size - substr($range, 1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$range = explode('-', $range);
|
||||
$c_start = $range[0];
|
||||
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
|
||||
@@ -623,7 +655,7 @@
|
||||
|
||||
// Start buffered download
|
||||
$buffer = 1024 * 8;
|
||||
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
|
||||
while (!feof($fp) && ($p = ftell($fp)) <= $end) {
|
||||
if ($p + $buffer > $end) {
|
||||
// In case we're only outputtin a chunk, make sure we don't
|
||||
// read past the length
|
||||
@@ -639,7 +671,9 @@
|
||||
|
||||
/**
|
||||
* Called by the maintenance service to clean out old call recordings
|
||||
*
|
||||
* @param settings $settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function filesystem_maintenance(settings $settings): void {
|
||||
@@ -688,12 +722,11 @@
|
||||
//file is not older - do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//report the retention days is not set correctly
|
||||
maintenance_service::log_write(self::class, "Retention days not set or not a valid number", $domain_uuid, maintenance_service::LOG_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -110,7 +110,14 @@
|
||||
//set the default
|
||||
if (empty($profile)) { $profile = "default"; }
|
||||
|
||||
//define fucntion get_conference_pin - used to find a unique pin number
|
||||
/**
|
||||
* Generates a unique pin number for a conference room.
|
||||
*
|
||||
* @param int $length The length of the pin number to be generated.
|
||||
* @param string $conference_room_uuid The UUID of the conference room.
|
||||
*
|
||||
* @return string A unique pin number if available, or generates another one recursively until an available one is found.
|
||||
*/
|
||||
function get_conference_pin($length, $conference_room_uuid) {
|
||||
//set the variable as global
|
||||
global $database;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
//define the blf_notify class
|
||||
class call_center_notify {
|
||||
class call_center_notify {
|
||||
|
||||
public $debug;
|
||||
public $domain_name;
|
||||
@@ -35,6 +35,16 @@
|
||||
public $agent_uuid;
|
||||
|
||||
//feature_event method
|
||||
|
||||
/**
|
||||
* Sends a presence notification to the call center.
|
||||
*
|
||||
* This method creates an event socket connection and sends a PRESENCE_IN event
|
||||
* if the connection is established. The event contains information about the agent's
|
||||
* presence, including their name, domain, unique ID, and answer state.
|
||||
*
|
||||
* @return boolean True if the event was successfully sent, false otherwise.
|
||||
*/
|
||||
public function send_call_center_notify() {
|
||||
|
||||
$esl = event_socket::create();
|
||||
@@ -46,15 +56,15 @@
|
||||
$event .= "alt_event_type: dialog\n";
|
||||
$event .= "Presence-Call-Direction: outbound\n";
|
||||
$event .= "state: Active (1 waiting)\n";
|
||||
$event .= "from: agent+".$this->agent_name."@".$this->domain_name."\n";
|
||||
$event .= "login: agent+".$this->agent_name."@".$this->domain_name."\n";
|
||||
$event .= "unique-id: ".$this->agent_uuid."\n";
|
||||
$event .= "answer-state: ".$this->answer_state."\n";
|
||||
$event .= "from: agent+" . $this->agent_name . "@" . $this->domain_name . "\n";
|
||||
$event .= "login: agent+" . $this->agent_name . "@" . $this->domain_name . "\n";
|
||||
$event .= "unique-id: " . $this->agent_uuid . "\n";
|
||||
$event .= "answer-state: " . $this->answer_state . "\n";
|
||||
$esl->request('api ' . $event);
|
||||
//echo $event."<br />";
|
||||
}
|
||||
} //function
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
?>
|
||||
|
||||
@@ -26,7 +26,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
*/
|
||||
|
||||
//define the conference centers class
|
||||
class conference_centers {
|
||||
class conference_centers {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,7 +35,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
const app_uuid = '8d083f5a-f726-42a8-9ffa-8d28f848f10e';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
@@ -55,30 +57,38 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Username 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 $username;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -94,7 +104,12 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
private $fields;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -108,7 +123,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
|
||||
/**
|
||||
* count the conference rooms
|
||||
* Retrieves the count of conference rooms.
|
||||
*
|
||||
* @return array|false An array containing a single column named "column" with the room count.
|
||||
*/
|
||||
public function room_count() {
|
||||
//get the room count
|
||||
@@ -140,7 +157,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
|
||||
/**
|
||||
* get the list of conference rooms
|
||||
* Retrieves a list of conference rooms based on filtering and sorting criteria.
|
||||
*
|
||||
* @return array|null A multidimensional array containing information about each room, or null if no rooms are found.
|
||||
*/
|
||||
public function rooms() {
|
||||
//get variables used to control the order
|
||||
@@ -192,7 +211,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
$sql .= "lower(r.account_code) like :search or ";
|
||||
$sql .= "lower(r.description) like :search ";
|
||||
$sql .= ") ";
|
||||
$parameters['search'] = '%'.strtolower($this->search).'%';
|
||||
$parameters['search'] = '%' . strtolower($this->search) . '%';
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
if (isset($this->created_by)) {
|
||||
@@ -201,8 +220,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
if (empty($this->order_by)) {
|
||||
$sql .= "order by r.description, r.conference_room_uuid asc ";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sql .= "order by $order_by $order ";
|
||||
}
|
||||
$sql .= "limit :rows_per_page offset :offset ";
|
||||
@@ -213,9 +231,11 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
|
||||
if (!empty($conference_rooms)) {
|
||||
$x = 0;
|
||||
foreach($conference_rooms as $row) {
|
||||
foreach ($conference_rooms as $row) {
|
||||
//increment the array index
|
||||
if (isset($previous) && $row["conference_room_uuid"] != $previous) { $x++; }
|
||||
if (isset($previous) && $row["conference_room_uuid"] != $previous) {
|
||||
$x++;
|
||||
}
|
||||
//build the array
|
||||
$result[$x]["domain_uuid"] = $row["domain_uuid"];
|
||||
$result[$x]["conference_room_uuid"] = $row["conference_room_uuid"];
|
||||
@@ -248,7 +268,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
|
||||
/**
|
||||
* download the recordings
|
||||
* Downloads a call recording based on the provided ID.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function download() {
|
||||
if (permission_exists('conference_session_play') || permission_exists('call_recording_play') || permission_exists('call_recording_download')) {
|
||||
@@ -275,37 +297,35 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
|
||||
//set the path for the directory
|
||||
$default_path = $this->settings->get('switch', 'call_recordings')."/".$this->domain_name;
|
||||
$default_path = $this->settings->get('switch', 'call_recordings') . "/" . $this->domain_name;
|
||||
|
||||
//get the file path and name
|
||||
$record_path = dirname($recording);
|
||||
$record_name = basename($recording);
|
||||
|
||||
//download the file
|
||||
if (file_exists($record_path.'/'.$record_name.'.wav')) {
|
||||
$record_name = $record_name.'.wav';
|
||||
}
|
||||
else {
|
||||
if (file_exists($record_path.'/'.$record_name.'.mp3')) {
|
||||
$record_name = $record_name.'.mp3';
|
||||
if (file_exists($record_path . '/' . $record_name . '.wav')) {
|
||||
$record_name = $record_name . '.wav';
|
||||
} else {
|
||||
if (file_exists($record_path . '/' . $record_name . '.mp3')) {
|
||||
$record_name = $record_name . '.mp3';
|
||||
}
|
||||
}
|
||||
|
||||
//download the file
|
||||
if (file_exists($record_path.'/'.$record_name)) {
|
||||
if (file_exists($record_path . '/' . $record_name)) {
|
||||
//content-range
|
||||
//if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
// range_download($full_recording_path);
|
||||
//}
|
||||
ob_clean();
|
||||
$fd = fopen($record_path.'/'.$record_name, "rb");
|
||||
$fd = fopen($record_path . '/' . $record_name, "rb");
|
||||
if ($_GET['t'] == "bin") {
|
||||
header("Content-Type: application/force-download");
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Type: application/download");
|
||||
header("Content-Description: File Transfer");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$file_ext = substr($record_name, -3);
|
||||
if ($file_ext == "wav") {
|
||||
header("Content-Type: audio/x-wav");
|
||||
@@ -314,7 +334,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
header("Content-Type: audio/mpeg");
|
||||
}
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.$record_name.'"');
|
||||
header('Content-Disposition: attachment; filename="' . $record_name . '"');
|
||||
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
||||
// header("Content-Length: ".filesize($full_recording_path));
|
||||
@@ -330,7 +350,12 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
} //end download method
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes multiple conference center records.
|
||||
*
|
||||
* @param array $records An array of records to delete, where each record is an associative array containing the UUID of
|
||||
* the conference center and a 'checked' key indicating whether the record should be deleted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_conference_centers($records) {
|
||||
|
||||
@@ -340,7 +365,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
$this->table = 'conference_centers';
|
||||
$this->uuid_prefix = 'conference_center_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -349,8 +374,8 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -371,7 +396,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
unset($sql, $parameters);
|
||||
|
||||
//create array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['dialplan_details'][$x]['dialplan_uuid'] = $dialplan_uuid;
|
||||
$array['dialplan_details'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -398,7 +423,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//clear the destinations session array
|
||||
if (isset($_SESSION['destinations']['array'])) {
|
||||
@@ -416,6 +441,13 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple conference rooms.
|
||||
*
|
||||
* @param array $records An array containing the IDs of the records to be deleted. The ID is represented as 'uuid'.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_conference_rooms($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -424,7 +456,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
$this->table = 'conference_rooms';
|
||||
$this->uuid_prefix = 'conference_room_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -433,8 +465,8 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -446,7 +478,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
|
||||
//create array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['conference_room_users'][$x]['conference_room_uuid'] = $record['uuid'];
|
||||
$array['conference_room_users'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -477,15 +509,23 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple conference sessions.
|
||||
*
|
||||
* @param array $records An array of records to delete, where each record is an associative array with a 'uuid' key and a 'checked' key.
|
||||
* The 'uuid' value must be a valid UUID, and the 'checked' value should be set to 'true' for the session to be deleted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_conference_sessions($records) {
|
||||
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'conference_session_';
|
||||
$this->list_page = 'conference_sessions.php?id='.$this->conference_room_uuid;
|
||||
$this->list_page = 'conference_sessions.php?id=' . $this->conference_room_uuid;
|
||||
$this->table = 'conference_sessions';
|
||||
$this->uuid_prefix = 'conference_session_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -494,8 +534,8 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -507,9 +547,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
|
||||
//create array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['conference_session_details'][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array['conference_session_details'][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array['conference_session_details'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
}
|
||||
@@ -539,7 +579,12 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of multiple conference centers.
|
||||
*
|
||||
* @param array $records An array of records to toggle, where each record is an associative array with a 'uuid' key and a 'checked' key.
|
||||
* The 'uuid' value must be a valid UUID, and the 'checked' value should be set to 'true' for the center to be toggled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function toggle_conference_centers($records) {
|
||||
|
||||
@@ -549,9 +594,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
$this->table = 'conference_centers';
|
||||
$this->uuid_prefix = 'conference_center_';
|
||||
$this->toggle_field = 'conference_center_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -560,8 +605,8 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -569,15 +614,15 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
if (!empty($records)) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids)) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, dialplan_uuid from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, dialplan_uuid from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (!empty($rows)) {
|
||||
@@ -591,8 +636,8 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($conference_centers as $uuid => $conference_center) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($conference_centers as $uuid => $conference_center) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $conference_center['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $conference_center['dialplan_uuid'];
|
||||
$array['dialplans'][$x]['dialplan_enabled'] = $conference_center['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
@@ -619,7 +664,7 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//clear the destinations session array
|
||||
if (isset($_SESSION['destinations']['array'])) {
|
||||
@@ -636,6 +681,14 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the state of multiple conference rooms.
|
||||
*
|
||||
* @param array $records An array of records to toggle, where each record is an associative array with a 'uuid' key and a 'checked' key.
|
||||
* The 'uuid' value must be a valid UUID, and the 'checked' value should be set to 'true' for the room to be toggled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function toggle_conference_rooms($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -643,9 +696,9 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
$this->list_page = 'conference_rooms.php';
|
||||
$this->table = 'conference_rooms';
|
||||
$this->uuid_prefix = 'conference_room_';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -654,8 +707,8 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -663,24 +716,24 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
if (!empty($records)) {
|
||||
|
||||
//validate submitted toggle field
|
||||
if (!in_array($this->toggle_field, ['record','wait_mod','announce_name','announce_count','announce_recording','mute','sounds','enabled'])) {
|
||||
header('Location: '.$this->list_page);
|
||||
if (!in_array($this->toggle_field, ['record', 'wait_mod', 'announce_name', 'announce_count', 'announce_recording', 'mute', 'sounds', 'enabled'])) {
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[$x] = "'".$record['uuid']."'";
|
||||
$uuids[$x] = "'" . $record['uuid'] . "'";
|
||||
if (($this->toggle_field == 'record' || $this->toggle_field == 'enabled') && !empty($record['meeting_uuid']) && is_uuid($record['meeting_uuid'])) {
|
||||
$meeting_uuid[$record['uuid']] = $record['meeting_uuid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($uuids)) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (!empty($rows)) {
|
||||
@@ -694,29 +747,29 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
/*
|
||||
/*
|
||||
//if toggling to true, start recording
|
||||
if ($this->toggle_field == 'record' && is_uuid($meeting_uuid[$uuid]) && $state == $this->toggle_values[1]) {
|
||||
//prepare the values and commands
|
||||
$default_language = 'en';
|
||||
$default_dialect = 'us';
|
||||
$default_voice = 'callie';
|
||||
// $recording_dir = $this->settings->get('switch', 'recordings').'/'.$this->domain_name.'/archive/'.date("Y").'/'.date("M").'/'.date("d");
|
||||
// $switch_cmd_record = "conference ".$meeting_uuid[$uuid]."@".$this->domain_name." record ".$recording_dir.'/'.$meeting_uuid[$uuid].'.wav';
|
||||
// $recording_dir = $this->settings->get('switch', 'recordings').'/'.$this->domain_name.'/archive/'.date("Y").'/'.date("M").'/'.date("d");
|
||||
// $switch_cmd_record = "conference ".$meeting_uuid[$uuid]."@".$this->domain_name." record ".$recording_dir.'/'.$meeting_uuid[$uuid].'.wav';
|
||||
$switch_cmd_notice = "conference ".$meeting_uuid[$uuid]."@".$this->domain_name." play ".$this->settings->get('switch', 'sounds')."/".$default_language."/".$default_dialect."/".$default_voice."/ivr/ivr-recording_started.wav";
|
||||
//execute api commands
|
||||
// if (!file_exists($recording_dir.'/'.$meeting_uuid[$uuid].'.wav')) {
|
||||
// if (!file_exists($recording_dir.'/'.$meeting_uuid[$uuid].'.wav')) {
|
||||
$esl = event_socket::create();
|
||||
if ($esl->is_connected()) {
|
||||
// $switch_result = event_socket::api($switch_cmd_record);
|
||||
// $switch_result = event_socket::api($switch_cmd_record);
|
||||
$switch_result = event_socket::api($switch_cmd_notice);
|
||||
}
|
||||
// }
|
||||
// }
|
||||
}
|
||||
*/
|
||||
*/
|
||||
$x++;
|
||||
}
|
||||
|
||||
@@ -815,19 +868,17 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
} //class
|
||||
|
||||
} //class
|
||||
|
||||
//example conference center
|
||||
/*
|
||||
$conference_center = new conference_centers;
|
||||
$conference_center->domain_uuid = $this->domain_uuid;
|
||||
$conference_center->rows_per_page = 150;
|
||||
$conference_center->offset = 0;
|
||||
$conference_center->created_by = uuid;
|
||||
$conference_center->order_by = $order_by;
|
||||
$conference_center->order = $order;
|
||||
$result = $conference_center->rooms();
|
||||
print_r($result);
|
||||
*/
|
||||
/*
|
||||
$conference_center = new conference_centers;
|
||||
$conference_center->domain_uuid = $this->domain_uuid;
|
||||
$conference_center->rows_per_page = 150;
|
||||
$conference_center->offset = 0;
|
||||
$conference_center->created_by = uuid;
|
||||
$conference_center->order_by = $order_by;
|
||||
$conference_center->order = $order;
|
||||
$result = $conference_center->rooms();
|
||||
print_r($result);
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/**
|
||||
* conference_controls class
|
||||
*/
|
||||
class conference_controls {
|
||||
class conference_controls {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -53,7 +53,12 @@
|
||||
public $conference_control_uuid;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set objects
|
||||
@@ -61,7 +66,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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) {
|
||||
|
||||
@@ -70,7 +81,7 @@
|
||||
$this->table = 'conference_controls';
|
||||
$this->location = 'conference_controls.php';
|
||||
|
||||
if (permission_exists($this->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -79,8 +90,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -91,8 +102,8 @@
|
||||
foreach ($records as $record) {
|
||||
//add to the array
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array['conference_control_details'][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
$array['conference_control_details'][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
}
|
||||
|
||||
//increment the id
|
||||
@@ -121,14 +132,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes conference control details.
|
||||
*
|
||||
* @param array $records An array of records to delete, where each record contains a 'checked' key with value 'true'.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_details($records) {
|
||||
|
||||
//assign the variables
|
||||
$this->name = 'conference_control_detail';
|
||||
$this->table = 'conference_control_details';
|
||||
$this->location = 'conference_control_edit.php?id='.$this->conference_control_uuid;
|
||||
$this->location = 'conference_control_edit.php?id=' . $this->conference_control_uuid;
|
||||
|
||||
if (permission_exists($this->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -137,8 +155,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate('/app/conference_controls/conference_control_details.php')) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -151,7 +169,7 @@
|
||||
foreach ($records as $record) {
|
||||
//add to the array
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
}
|
||||
|
||||
//increment the id
|
||||
@@ -174,7 +192,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle a field between two values
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
|
||||
@@ -182,10 +206,10 @@
|
||||
$this->name = 'conference_control';
|
||||
$this->table = 'conference_controls';
|
||||
$this->toggle_field = 'control_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->location = 'conference_controls.php';
|
||||
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -194,8 +218,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -204,12 +228,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -223,7 +247,7 @@
|
||||
$x = 0;
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -245,16 +269,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the state of one or more 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 toggle_details($records) {
|
||||
|
||||
//assign the variables
|
||||
$this->name = 'conference_control_detail';
|
||||
$this->table = 'conference_control_details';
|
||||
$this->toggle_field = 'control_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->location = 'conference_control_edit.php?id='.$this->conference_control_uuid;
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->location = 'conference_control_edit.php?id=' . $this->conference_control_uuid;
|
||||
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -263,8 +296,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate('/app/conference_controls/conference_control_details.php')) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -273,12 +306,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -293,7 +326,7 @@
|
||||
if (!empty($states) && is_array($states) && @sizeof($states) != 0) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -317,7 +350,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy rows from the database
|
||||
* Copies one or more 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 copy($records) {
|
||||
|
||||
@@ -327,7 +366,7 @@
|
||||
$this->description_field = 'control_description';
|
||||
$this->location = 'conference_controls.php';
|
||||
|
||||
if (permission_exists($this->name.'_add')) {
|
||||
if (permission_exists($this->name . '_add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -336,8 +375,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -347,7 +386,7 @@
|
||||
//get checked records
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,8 +394,8 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
$y = 0;
|
||||
@@ -364,7 +403,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -375,8 +414,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//add copy to the description
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field] ?? '').' ('.$text['label-copy'].')';
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field] ?? '') . ' (' . $text['label-copy'] . ')';
|
||||
|
||||
//details sub table
|
||||
$sql_2 = "select * from v_conference_control_details where conference_control_uuid = :conference_control_uuid";
|
||||
@@ -386,7 +425,7 @@
|
||||
foreach ($rows_2 as $row_2) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -405,7 +444,8 @@
|
||||
|
||||
}
|
||||
}
|
||||
unset($sql_2, $parameters_2, $rows_2, $row_2); }
|
||||
unset($sql_2, $parameters_2, $rows_2, $row_2);
|
||||
}
|
||||
}
|
||||
unset($sql, $parameters, $rows, $row);
|
||||
}
|
||||
@@ -424,4 +464,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/**
|
||||
* conference_profiles class
|
||||
*/
|
||||
class conference_profiles {
|
||||
class conference_profiles {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -53,7 +53,12 @@
|
||||
public $conference_profile_uuid;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set objects
|
||||
@@ -61,7 +66,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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) {
|
||||
|
||||
@@ -70,7 +81,7 @@
|
||||
$this->table = 'conference_profiles';
|
||||
$this->location = 'conference_profiles.php';
|
||||
|
||||
if (permission_exists($this->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -79,8 +90,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -91,8 +102,8 @@
|
||||
foreach ($records as $record) {
|
||||
//add to the array
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array['conference_profile_params'][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
$array['conference_profile_params'][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
}
|
||||
|
||||
//increment the id
|
||||
@@ -121,14 +132,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple parameters from the conference profile.
|
||||
*
|
||||
* @param array $records An array of records to delete, where each record contains a 'checked' key with value 'true' and an 'uuid' key containing the UUID of the parameter to be deleted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_params($records) {
|
||||
|
||||
//assign the variables
|
||||
$this->name = 'conference_profile_param';
|
||||
$this->table = 'conference_profile_params';
|
||||
$this->location = 'conference_profile_edit.php?id='.$this->conference_profile_uuid;
|
||||
$this->location = 'conference_profile_edit.php?id=' . $this->conference_profile_uuid;
|
||||
|
||||
if (permission_exists($this->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -137,8 +155,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate('/app/conference_profiles/conference_profile_params.php')) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -149,7 +167,7 @@
|
||||
foreach ($records as $record) {
|
||||
//add to the array
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
}
|
||||
|
||||
//increment the id
|
||||
@@ -171,7 +189,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle a field between two values
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
|
||||
@@ -179,10 +203,10 @@
|
||||
$this->name = 'conference_profile';
|
||||
$this->table = 'conference_profiles';
|
||||
$this->toggle_field = 'profile_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->location = 'conference_profiles.php';
|
||||
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -191,22 +215,22 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
//toggle the checked records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
//get current toggle state
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -218,9 +242,9 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -241,16 +265,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the enabled state of multiple parameters in a conference profile.
|
||||
*
|
||||
* @param array $records An array of records to toggle, where each record contains a 'checked' key with value 'true' and an 'uuid' key containing the UUID of the parameter to be toggled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function toggle_params($records) {
|
||||
|
||||
//assign the variables
|
||||
$this->name = 'conference_profile_param';
|
||||
$this->table = 'conference_profile_params';
|
||||
$this->toggle_field = 'profile_param_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->location = 'conference_profile_edit.php?id='.$this->conference_profile_uuid;
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->location = 'conference_profile_edit.php?id=' . $this->conference_profile_uuid;
|
||||
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -259,8 +290,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate('/app/conference_profiles/conference_profile_params.php')) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -269,12 +300,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -289,7 +320,7 @@
|
||||
if (!empty($states) && is_array($states) && @sizeof($states) != 0) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -312,7 +343,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy rows from the database
|
||||
* Copies one or more 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 copy($records) {
|
||||
|
||||
@@ -322,7 +359,7 @@
|
||||
$this->description_field = 'profile_description';
|
||||
$this->location = 'conference_profiles.php';
|
||||
|
||||
if (permission_exists($this->name.'_add')) {
|
||||
if (permission_exists($this->name . '_add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -331,8 +368,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -340,9 +377,9 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,8 +387,8 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
$y = 0;
|
||||
@@ -359,7 +396,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -370,8 +407,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//add copy to the description
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field] ?? '').' ('.$text['label-copy'].')';
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field] ?? '') . ' (' . $text['label-copy'] . ')';
|
||||
|
||||
//params sub table
|
||||
$sql_2 = "select * from v_conference_profile_params where conference_profile_uuid = :conference_profile_uuid";
|
||||
@@ -381,7 +418,7 @@
|
||||
foreach ($rows_2 as $row_2) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -428,4 +465,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the conferences class
|
||||
class conferences {
|
||||
class conferences {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,24 +35,31 @@
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
*
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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 name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -68,7 +75,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -85,14 +97,20 @@
|
||||
$this->table = 'conferences';
|
||||
$this->uuid_prefix = 'conference_';
|
||||
$this->toggle_field = 'conference_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -101,8 +119,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -123,7 +141,7 @@
|
||||
unset($sql, $parameters);
|
||||
|
||||
//build array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['conference_users'][$x]['conference_uuid'] = $record['uuid'];
|
||||
$array['conference_users'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -158,7 +176,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//clear the destinations session array
|
||||
if (isset($_SESSION['destinations']['array'])) {
|
||||
@@ -175,10 +193,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -187,8 +211,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -196,15 +220,15 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, dialplan_uuid from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, dialplan_uuid from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -218,8 +242,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($conferences as $uuid => $conference) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($conferences as $uuid => $conference) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $conference['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $conference['dialplan_uuid'];
|
||||
$array['dialplans'][$x]['dialplan_enabled'] = $conference['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
@@ -246,7 +270,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//clear the destinations session array
|
||||
if (isset($_SESSION['destinations']['array'])) {
|
||||
@@ -263,10 +287,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -275,8 +305,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -284,17 +314,17 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create insert array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -304,7 +334,7 @@
|
||||
$new_dialplan_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -315,9 +345,9 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_conference_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $new_conference_uuid;
|
||||
$array[$this->table][$x]['dialplan_uuid'] = $new_dialplan_uuid;
|
||||
$array[$this->table][$x]['conference_description'] = trim($row['conference_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x]['conference_description'] = trim($row['conference_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//conference users sub table
|
||||
$sql_2 = "select * from v_conference_users ";
|
||||
@@ -330,7 +360,7 @@
|
||||
foreach ($conference_users as $conference_user) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($conference_user as $key => $value) {
|
||||
foreach ($conference_user as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$conference_user[$key] = $value;
|
||||
@@ -358,7 +388,7 @@
|
||||
if (is_array($dialplan) && @sizeof($dialplan) != 0) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($dialplan as $key => $value) {
|
||||
foreach ($dialplan as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$dialplan[$key] = $value;
|
||||
@@ -374,7 +404,7 @@
|
||||
$dialplan_xml = str_replace($row['conference_uuid'], $new_conference_uuid, $dialplan_xml); //replace source conference_uuid with new
|
||||
$dialplan_xml = str_replace($dialplan['dialplan_uuid'], $new_dialplan_uuid, $dialplan_xml); //replace source dialplan_uuid with new
|
||||
$array['dialplans'][$x]['dialplan_xml'] = $dialplan_xml;
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'].' ('.$text['label-copy'].')');
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
unset($sql_3, $parameters_3, $dialplan);
|
||||
@@ -405,7 +435,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//set message
|
||||
message::add($text['message-copy']);
|
||||
@@ -417,4 +447,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +143,13 @@
|
||||
}
|
||||
|
||||
//define an alternative kick all
|
||||
/**
|
||||
* Ends a conference by killing all its members and destroying the session.
|
||||
*
|
||||
* @param string $name The name of the conference to end.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function conference_end($name) {
|
||||
$switch_cmd = "conference '".$name."' xml_list";
|
||||
$xml_str = trim(event_socket::api($switch_cmd));
|
||||
|
||||
@@ -236,6 +236,20 @@
|
||||
|
||||
//define the array _difference function
|
||||
//this adds old and new values to the array
|
||||
/**
|
||||
* Calculates the difference between two arrays.
|
||||
*
|
||||
* This function recursively iterates through both input arrays, comparing each key-value pair. If a value in $array2 is not present in $array1,
|
||||
* it is marked as 'new' in the returned array. If a value in $array1 is not present in $array2, it is also included in the returned array with a marker
|
||||
* indicating its origin.
|
||||
*
|
||||
* The function handles nested arrays by recursively calling itself for matching keys.
|
||||
*
|
||||
* @param mixed[] $array1 The first input array to compare.
|
||||
* @param mixed[] $array2 The second input array to compare.
|
||||
*
|
||||
* @return mixed[] An array containing the differences between the two input arrays, with added markers indicating origin.
|
||||
*/
|
||||
function array_difference($array1, $array2) {
|
||||
$array = array();
|
||||
if (is_array($array1)) {
|
||||
|
||||
@@ -36,7 +36,9 @@ class database_transactions {
|
||||
/**
|
||||
* Removes old entries for in the database database_transactions table
|
||||
* see {@link https://github.com/fusionpbx/fusionpbx-app-maintenance/} FusionPBX Maintenance App
|
||||
*
|
||||
* @param settings $settings Settings object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function database_maintenance(settings $settings): void {
|
||||
|
||||
@@ -73,6 +73,17 @@
|
||||
$available_columns[] = 'destination_order';
|
||||
|
||||
//define the functions
|
||||
/**
|
||||
* Converts an associative or numerical array into a CSV string.
|
||||
*
|
||||
* This function takes an array and returns its contents as a properly formatted
|
||||
* CSV string. If the input array is empty, it will return null.
|
||||
*
|
||||
* @param array $array The array to be converted into a CSV string.
|
||||
* It can be either an associative or numerical array.
|
||||
*
|
||||
* @return string A CSV string representation of the input array, or null if the array is empty.
|
||||
*/
|
||||
function array2csv(array &$array) {
|
||||
if (count($array) == 0) {
|
||||
return null;
|
||||
@@ -87,6 +98,17 @@
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends HTTP headers for a file download.
|
||||
*
|
||||
* This function sends the necessary HTTP headers to force the browser to download
|
||||
* a file instead of displaying it in the browser. The filename specified should be
|
||||
* a path to the file on the server, not a URL.
|
||||
*
|
||||
* @param string $filename The name and path to the file that will be downloaded by the client.
|
||||
*
|
||||
* @return void This function does not return anything.
|
||||
*/
|
||||
function download_send_headers($filename) {
|
||||
// disable caching
|
||||
$now = gmdate("D, d M Y H:i:s");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
//get the http get values and set them as php variables
|
||||
$action = $_POST["action"] ?? null;
|
||||
$from_row = $_POST["from_row"] ?? null;
|
||||
@@ -132,6 +120,14 @@
|
||||
}
|
||||
|
||||
//get the parent table
|
||||
/**
|
||||
* Retrieves the parent table of a given table in a database schema.
|
||||
*
|
||||
* @param array $schema Database schema containing table information
|
||||
* @param string $table_name Name of the table for which to retrieve the parent
|
||||
*
|
||||
* @return mixed Parent table name, or null if no matching table is found
|
||||
*/
|
||||
function get_parent($schema,$table_name) {
|
||||
foreach ($schema as $row) {
|
||||
if ($row['table'] == $table_name) {
|
||||
|
||||
@@ -79,6 +79,14 @@
|
||||
$destination_array = $destination->all('dialplan');
|
||||
|
||||
//function to return the action names in the order defined
|
||||
/**
|
||||
* Returns a list of actions based on the provided destination array and actions.
|
||||
*
|
||||
* @param array $destination_array The array containing the data to process.
|
||||
* @param array $destination_actions The array of actions to apply to the destination array.
|
||||
*
|
||||
* @return array A list of actions resulting from the processing of the destination array and actions.
|
||||
*/
|
||||
function action_name($destination_array, $destination_actions) {
|
||||
global $settings;
|
||||
$actions = [];
|
||||
@@ -175,8 +183,8 @@
|
||||
$page = $_GET['page'];
|
||||
}
|
||||
if (!isset($page)) { $page = 0; $_GET['page'] = 0; }
|
||||
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
|
||||
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
|
||||
[$paging_controls, $rows_per_page] = paging($num_rows, $param, $rows_per_page);
|
||||
[$paging_controls_mini, $rows_per_page] = paging($num_rows, $param, $rows_per_page, true);
|
||||
$offset = $rows_per_page * $page;
|
||||
|
||||
//get the list
|
||||
|
||||
@@ -51,6 +51,21 @@
|
||||
$label_required = $text['label-required'];
|
||||
|
||||
//define the functions
|
||||
/**
|
||||
* Converts a multi-dimensional array to CSV format.
|
||||
*
|
||||
* This function assumes that the input array is a collection of devices,
|
||||
* where each device has an array of columns. The function will take all
|
||||
* column headers from all devices and use them as the header row in the
|
||||
* generated CSV file.
|
||||
*
|
||||
* If any duplicate column headers are found, they will be removed by
|
||||
* truncating at the pipe character (|).
|
||||
*
|
||||
* @param array &$array A multi-dimensional array of device data.
|
||||
*
|
||||
* @return string The CSV formatted data as a string. Returns null if the input array is empty.
|
||||
*/
|
||||
function array2csv(array &$array) {
|
||||
if (count($array) == 0) {
|
||||
return null;
|
||||
@@ -86,6 +101,15 @@
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends HTTP headers to force a file download.
|
||||
*
|
||||
* This function sets various HTTP headers to instruct the browser to download the file instead of displaying it in the browser window.
|
||||
*
|
||||
* @param string $filename The filename to use for the downloaded file.
|
||||
*
|
||||
* @return void No return value. This function only sends HTTP headers and does not generate any output.
|
||||
*/
|
||||
function download_send_headers($filename) {
|
||||
// disable caching
|
||||
$now = gmdate("D, d M Y H:i:s");
|
||||
|
||||
@@ -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);
|
||||
fclose($fp);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
//set the max php execution time
|
||||
ini_set('max_execution_time',7200);
|
||||
|
||||
@@ -225,7 +213,15 @@
|
||||
}
|
||||
|
||||
//get the parent table
|
||||
function get_parent($schema,$table_name) {
|
||||
/**
|
||||
* Retrieves the parent table name for a given table in the schema.
|
||||
*
|
||||
* @param array $schema An associative array of schema definitions
|
||||
* @param string $table_name The name of the table to retrieve the parent for
|
||||
*
|
||||
* @return string|null The parent table name if found, otherwise null
|
||||
*/
|
||||
function get_parent($schema, $table_name) {
|
||||
foreach ($schema as $row) {
|
||||
if ($row['table'] == $table_name) {
|
||||
return $row['parent'];
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the device class
|
||||
class device {
|
||||
class device {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -34,7 +34,9 @@
|
||||
const app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
@@ -49,30 +51,38 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Username 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 $username;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -89,12 +99,12 @@
|
||||
private $tables;
|
||||
|
||||
/**
|
||||
* Create a settings object using key/value pairs in the $setting_array.
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* Valid values are: database.
|
||||
* @param array setting_array
|
||||
* @depends database::new()
|
||||
* @access public
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -107,13 +117,25 @@
|
||||
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the domain UUID.
|
||||
*
|
||||
* @return string The domain UUID.
|
||||
*/
|
||||
public function get_domain_uuid() {
|
||||
return $this->domain_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the device vendor from a given MAC address.
|
||||
*
|
||||
* @param string $mac The MAC address to retrieve the vendor for.
|
||||
*
|
||||
* @return string The device vendor, or an empty string if the MAC address is invalid.
|
||||
*/
|
||||
public static function get_vendor($mac) {
|
||||
//return if the mac address is empty
|
||||
if(empty($mac)) {
|
||||
if (empty($mac)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -379,7 +401,14 @@
|
||||
return $device_vendor;
|
||||
}
|
||||
|
||||
public static function get_vendor_by_agent($agent){
|
||||
/**
|
||||
* Returns the vendor of a given user agent string.
|
||||
*
|
||||
* @param string $agent The user agent string to determine the vendor from.
|
||||
*
|
||||
* @return string The identified vendor, or an empty string if no match is found.
|
||||
*/
|
||||
public static function get_vendor_by_agent($agent) {
|
||||
if ($agent) {
|
||||
//set the user agent string to lower case
|
||||
$agent = strtolower($agent);
|
||||
@@ -453,6 +482,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the directory where FusionPBX templates are stored.
|
||||
*
|
||||
* This method checks various locations on different operating systems to find the default template directory.
|
||||
* If a domain name subdirectory exists in the selected template directory, it will be used instead.
|
||||
*
|
||||
* @return string The path to the template directory.
|
||||
*/
|
||||
public function get_template_dir() {
|
||||
//set the default template directory
|
||||
if (PHP_OS == "Linux") {
|
||||
@@ -460,51 +497,43 @@
|
||||
if (empty($this->template_dir)) {
|
||||
if (file_exists('/usr/share/fusionpbx/templates/provision')) {
|
||||
$this->template_dir = '/usr/share/fusionpbx/templates/provision';
|
||||
}
|
||||
elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
|
||||
} elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
|
||||
$this->template_dir = '/etc/fusionpbx/resources/templates/provision';
|
||||
}
|
||||
else {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
} else {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (PHP_OS == "FreeBSD") {
|
||||
} elseif (PHP_OS == "FreeBSD") {
|
||||
//if the FreeBSD port is installed use the following paths by default.
|
||||
if (empty($this->template_dir)) {
|
||||
if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
|
||||
$this->template_dir = '/usr/local/share/fusionpbx/templates/provision';
|
||||
}
|
||||
elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
|
||||
} elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
|
||||
$this->template_dir = '/usr/local/etc/fusionpbx/resources/templates/provision';
|
||||
}
|
||||
else {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
} else {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (PHP_OS == "NetBSD") {
|
||||
} elseif (PHP_OS == "NetBSD") {
|
||||
//set the default template_dir
|
||||
if (empty($this->template_dir)) {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
elseif (PHP_OS == "OpenBSD") {
|
||||
} elseif (PHP_OS == "OpenBSD") {
|
||||
//set the default template_dir
|
||||
if (empty($this->template_dir)) {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//set the default template_dir
|
||||
if (empty($this->template_dir)) {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
|
||||
//check to see if the domain name sub directory exists
|
||||
if (is_dir($this->template_dir."/".$this->domain_name)) {
|
||||
$this->template_dir = $this->template_dir."/".$this->domain_name;
|
||||
if (is_dir($this->template_dir . "/" . $this->domain_name)) {
|
||||
$this->template_dir = $this->template_dir . "/" . $this->domain_name;
|
||||
}
|
||||
|
||||
//return the template directory
|
||||
@@ -512,7 +541,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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) {
|
||||
|
||||
@@ -522,7 +557,7 @@
|
||||
$this->table = 'devices';
|
||||
$this->uuid_prefix = 'device_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -531,8 +566,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -547,7 +582,7 @@
|
||||
$this->database->execute($sql, $parameters);
|
||||
unset($sql, $parameters);
|
||||
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array['device_settings'][$x]['device_uuid'] = $record['uuid'];
|
||||
$array['device_lines'][$x]['device_uuid'] = $record['uuid'];
|
||||
$array['device_keys'][$x]['device_uuid'] = $record['uuid'];
|
||||
@@ -588,13 +623,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one or more device lines from the database.
|
||||
*
|
||||
* @param array $records A list of records to be deleted, where each record is an associative array containing
|
||||
* 'uuid' and optionally 'device_uuid'.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_lines($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'device_line_';
|
||||
$this->table = 'device_lines';
|
||||
$this->uuid_prefix = 'device_line_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -603,8 +646,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -615,7 +658,7 @@
|
||||
$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][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['device_uuid'] = $this->device_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -632,13 +675,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple device key records.
|
||||
*
|
||||
* @param array $records An array of device key records to delete, where each record is an associative array
|
||||
* containing the uuid and checked status.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_keys($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'device_key_';
|
||||
$this->table = 'device_keys';
|
||||
$this->uuid_prefix = 'device_key_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -647,8 +698,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -659,7 +710,7 @@
|
||||
$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][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['device_uuid'] = $this->device_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -676,13 +727,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple device settings records.
|
||||
*
|
||||
* This method checks if the user has permission to delete device settings and validates the token.
|
||||
* It then filters out unchecked device settings, builds a delete array, and executes the deletion.
|
||||
*
|
||||
* @param array $records An array of device setting records to be deleted, where each record contains 'uuid' and
|
||||
* 'checked' keys.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_settings($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'device_setting_';
|
||||
$this->table = 'device_settings';
|
||||
$this->uuid_prefix = 'device_setting_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -691,8 +753,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -703,7 +765,7 @@
|
||||
$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][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['device_uuid'] = $this->device_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -720,6 +782,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the specified vendors.
|
||||
*
|
||||
* @param array $records The list of vendor records to delete, where each record is an associative array containing
|
||||
* the vendor's UUID and a 'checked' flag indicating whether the vendor should be deleted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_vendors($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -730,7 +800,7 @@
|
||||
$this->tables[] = 'device_vendor_function_groups';
|
||||
$this->uuid_prefix = 'device_vendor_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -739,8 +809,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -751,7 +821,7 @@
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
foreach ($this->tables as $table) {
|
||||
$array[$table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -781,6 +851,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes vendor functions based on the provided records.
|
||||
*
|
||||
* @param array $records An array of records containing information about the rows to delete,
|
||||
* where each record is an associative array with 'checked' and 'uuid' keys.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_vendor_functions($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -790,7 +868,7 @@
|
||||
$this->tables[] = 'device_vendor_function_groups';
|
||||
$this->uuid_prefix = 'device_vendor_function_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -799,8 +877,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate('/app/devices/device_vendor_functions.php')) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page.'?id='.$this->device_vendor_uuid);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page . '?id=' . $this->device_vendor_uuid);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -811,7 +889,7 @@
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
foreach ($this->tables as $table) {
|
||||
$array[$table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -839,6 +917,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple device profiles.
|
||||
*
|
||||
* @param array $records The list of records to delete, where each record is an associative array containing the
|
||||
* UUID and a 'checked' key indicating whether the profile should be deleted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_profiles($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -849,7 +935,7 @@
|
||||
$this->tables[] = 'device_profile_settings';
|
||||
$this->uuid_prefix = 'device_profile_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -858,8 +944,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -870,7 +956,7 @@
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
foreach ($this->tables as $table) {
|
||||
$array[$table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -900,15 +986,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple records from the device profile keys table.
|
||||
*
|
||||
* @param array $records The list of records to delete, where each record is an associative array containing 'uuid'
|
||||
* and/or 'checked' key(s).
|
||||
*
|
||||
* @return bool True if all records were successfully deleted, false otherwise.
|
||||
*/
|
||||
public function delete_profile_keys($records) {
|
||||
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'device_profile_key_';
|
||||
$this->list_page = 'device_profile_edit.php?id='.$this->device_profile_uuid;
|
||||
$this->list_page = 'device_profile_edit.php?id=' . $this->device_profile_uuid;
|
||||
$this->table = 'device_profile_keys';
|
||||
$this->uuid_prefix = 'device_profile_key_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -917,8 +1011,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -928,50 +1022,7 @@
|
||||
//build the delete array
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
}
|
||||
}
|
||||
|
||||
//execute delete
|
||||
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
}
|
||||
unset($records);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_profile_settings($records) {
|
||||
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'device_profile_setting_';
|
||||
$this->list_page = 'device_profile_edit.php?id='.$this->device_profile_uuid;
|
||||
$this->table = 'device_profile_settings';
|
||||
$this->uuid_prefix = 'device_profile_setting_';
|
||||
|
||||
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'])) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -987,7 +1038,61 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Deletes multiple profile settings.
|
||||
*
|
||||
* @param array $records An array of profile settings to delete, with each setting's 'uuid' key as the identifier.
|
||||
*/
|
||||
public function delete_profile_settings($records) {
|
||||
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'device_profile_setting_';
|
||||
$this->list_page = 'device_profile_edit.php?id=' . $this->device_profile_uuid;
|
||||
$this->table = 'device_profile_settings';
|
||||
$this->uuid_prefix = 'device_profile_setting_';
|
||||
|
||||
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'])) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
}
|
||||
}
|
||||
|
||||
//execute delete
|
||||
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
}
|
||||
unset($records);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
|
||||
@@ -997,9 +1102,9 @@
|
||||
$this->table = 'devices';
|
||||
$this->uuid_prefix = 'device_';
|
||||
$this->toggle_field = 'device_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1008,8 +1113,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1019,13 +1124,13 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -1039,7 +1144,7 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -1068,6 +1173,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the enabled state of one or more vendors.
|
||||
*
|
||||
* @param array $records An array of records containing vendor information, where each record
|
||||
* has a 'checked' property indicating whether to toggle the vendor's state.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function toggle_vendors($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -1076,9 +1189,9 @@
|
||||
$this->table = 'device_vendors';
|
||||
$this->uuid_prefix = 'device_vendor_';
|
||||
$this->toggle_field = 'enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1087,8 +1200,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1098,12 +1211,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -1116,7 +1229,7 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -1138,6 +1251,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the enabled state of one or more vendor functions.
|
||||
*
|
||||
* @param array $records An array of records containing vendor function information, where each record has a 'checked' property indicating whether to toggle the function's state.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function toggle_vendor_functions($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -1146,9 +1266,9 @@
|
||||
$this->table = 'device_vendor_functions';
|
||||
$this->uuid_prefix = 'device_vendor_function_';
|
||||
$this->toggle_field = 'enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1157,8 +1277,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate('/app/devices/device_vendor_functions.php')) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page.'?id='.$this->device_vendor_uuid);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page . '?id=' . $this->device_vendor_uuid);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1168,12 +1288,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -1186,7 +1306,7 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -1208,6 +1328,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the state of checked device profiles.
|
||||
*
|
||||
* @param array $records An array containing the records to toggle, where each record is an associative array
|
||||
* with a 'checked' key indicating whether the profile should be toggled, and a 'uuid'
|
||||
* key containing the UUID of the profile.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function toggle_profiles($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -1216,9 +1345,9 @@
|
||||
$this->table = 'device_profiles';
|
||||
$this->uuid_prefix = 'device_profile_';
|
||||
$this->toggle_field = 'device_profile_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1227,8 +1356,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1238,12 +1367,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -1257,7 +1386,7 @@
|
||||
$x = 0;
|
||||
if (!empty($states) && is_array($states) && @sizeof($states) != 0) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -1281,7 +1410,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copy the specified device profiles.
|
||||
*
|
||||
* @param array $records An array containing the records to copy, where each record is an associative array
|
||||
* with a 'checked' key indicating whether the profile should be copied, and a 'uuid'
|
||||
* key containing the UUID of the profile.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function copy_profiles($records) {
|
||||
|
||||
@@ -1291,7 +1426,7 @@
|
||||
$this->table = 'device_profiles';
|
||||
$this->uuid_prefix = 'device_profile_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1300,8 +1435,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1311,15 +1446,15 @@
|
||||
//get checked records
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create insert array from existing data
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -1328,7 +1463,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -1339,8 +1474,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['device_profile_description'] = trim($row['device_profile_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['device_profile_description'] = trim($row['device_profile_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//keys sub table
|
||||
$sql_2 = "select * from v_device_profile_keys ";
|
||||
@@ -1359,7 +1494,7 @@
|
||||
foreach ($rows_2 as $row_2) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -1388,7 +1523,7 @@
|
||||
foreach ($rows_3 as $row_3) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_3 as $key => $value) {
|
||||
foreach ($row_3 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_3[$key] = $value;
|
||||
@@ -1442,6 +1577,5 @@
|
||||
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
?>
|
||||
|
||||
@@ -44,8 +44,10 @@
|
||||
//declared functions
|
||||
/**
|
||||
* Checks if a dialplan detail record is marked for deletion
|
||||
*
|
||||
* @param string $uuid UUID of the dialplan detail record
|
||||
* @param array $deleted_details array of dialplan detail records marked for deletion
|
||||
*
|
||||
* @return bool Returns true if user has permission and dialplan detail is marked for deletion
|
||||
*/
|
||||
function marked_for_deletion(string $uuid, array $deleted_details): bool {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the dialplan class
|
||||
class dialplan {
|
||||
class dialplan {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -34,7 +34,9 @@
|
||||
const app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
@@ -81,18 +83,22 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
@@ -106,7 +112,14 @@
|
||||
private $toggle_field;
|
||||
private $toggle_values;
|
||||
|
||||
//class constructor
|
||||
/**
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
|
||||
@@ -125,10 +138,14 @@
|
||||
$this->table = 'dialplans';
|
||||
$this->uuid_prefix = 'dialplan_';
|
||||
$this->toggle_field = 'dialplan_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a specific dialplan exists in the database.
|
||||
*
|
||||
* @return bool True if the dialplan exists, False otherwise
|
||||
*/
|
||||
public function dialplan_exists() {
|
||||
$sql = "select count(*) from v_dialplans ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null)";
|
||||
@@ -139,6 +156,14 @@
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports dialplans from XML files for the specified domains.
|
||||
*
|
||||
* @param array $domains An array of domain data, where each domain is an associative array containing 'domain_uuid' and
|
||||
* other relevant information.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function import($domains) {
|
||||
//set the row id
|
||||
$x = 0;
|
||||
@@ -228,7 +253,7 @@
|
||||
|
||||
//determine if the dialplan already exists
|
||||
$app_uuid_exists = false;
|
||||
foreach($app_uuids as $row) {
|
||||
foreach ($app_uuids as $row) {
|
||||
if ($dialplan['@attributes']['app_uuid'] == $row['app_uuid']) {
|
||||
$app_uuid_exists = true;
|
||||
}
|
||||
@@ -240,8 +265,7 @@
|
||||
//dialplan global
|
||||
if (isset($dialplan['@attributes']['global']) && $dialplan['@attributes']['global'] == "true") {
|
||||
$dialplan_global = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$dialplan_global = false;
|
||||
}
|
||||
|
||||
@@ -252,8 +276,7 @@
|
||||
//set the domain_uuid
|
||||
if ($dialplan_global) {
|
||||
$domain_uuid = null;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$domain_uuid = $domain['domain_uuid'];
|
||||
}
|
||||
|
||||
@@ -275,8 +298,7 @@
|
||||
$array['dialplans'][$x]['dialplan_order'] = $dialplan['@attributes']['order'];
|
||||
if (!empty($dialplan['@attributes']['enabled'])) {
|
||||
$array['dialplans'][$x]['dialplan_enabled'] = $dialplan['@attributes']['enabled'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$array['dialplans'][$x]['dialplan_enabled'] = true;
|
||||
}
|
||||
$array['dialplans'][$x]['dialplan_description'] = $dialplan['@attributes']['description'] ?? null;
|
||||
@@ -300,8 +322,7 @@
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
|
||||
if (isset($row['@attributes']['enabled'])) {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = $row['@attributes']['enabled'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = true;
|
||||
}
|
||||
$y++;
|
||||
@@ -333,15 +354,13 @@
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row2['@attributes']['data'] ?? null;
|
||||
if (!empty($row2['@attributes']['inline'])) {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = $row2['@attributes']['inline'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = null;
|
||||
}
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
|
||||
if (isset($row2['@attributes']['enabled'])) {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = $row2['@attributes']['enabled'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = true;
|
||||
}
|
||||
$y++;
|
||||
@@ -360,15 +379,13 @@
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row2['@attributes']['data'];
|
||||
if (!empty($row2['@attributes']['inline'])) {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = $row2['@attributes']['inline'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = null;
|
||||
}
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
|
||||
if (isset($row2['@attributes']['enabled'])) {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = $row2['@attributes']['enabled'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_enabled'] = true;
|
||||
}
|
||||
$y++;
|
||||
@@ -377,8 +394,7 @@
|
||||
$order = $order + 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$condition_self_closing_tag = true;
|
||||
}
|
||||
|
||||
@@ -431,6 +447,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the outbound routes for a given destination number.
|
||||
*
|
||||
* @param string $destination_number The destination number to retrieve the outbound routes for.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function outbound_routes($destination_number) {
|
||||
|
||||
//normalize the destination number
|
||||
@@ -464,15 +487,19 @@
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$dialplans = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
unset($sql, $parameters);
|
||||
$x = 0; $y = 0;
|
||||
$x = 0;
|
||||
$y = 0;
|
||||
if (!empty($dialplans)) {
|
||||
foreach ($dialplans as $row) {
|
||||
//if the previous dialplan uuid has not been set then set it
|
||||
if (!isset($previous_dialplan_uuid)) { $previous_dialplan_uuid = $row['dialplan_uuid']; }
|
||||
if (!isset($previous_dialplan_uuid)) {
|
||||
$previous_dialplan_uuid = $row['dialplan_uuid'];
|
||||
}
|
||||
|
||||
//increment dialplan ordinal number
|
||||
if ($previous_dialplan_uuid != $row['dialplan_uuid']) {
|
||||
$x++; $y = 0;
|
||||
$x++;
|
||||
$y = 0;
|
||||
}
|
||||
|
||||
//build the array
|
||||
@@ -509,12 +536,11 @@
|
||||
if ($field['dialplan_detail_tag'] == "condition") {
|
||||
if ($field['dialplan_detail_type'] == "destination_number") {
|
||||
$dialplan_detail_data = $field['dialplan_detail_data'];
|
||||
$pattern = '/'.$dialplan_detail_data.'/';
|
||||
$pattern = '/' . $dialplan_detail_data . '/';
|
||||
preg_match($pattern, $destination_number, $matches, PREG_OFFSET_CAPTURE);
|
||||
if (count($matches) == 0) {
|
||||
$regex_match = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$regex_match = true;
|
||||
$regex_match_1 = $matches[1][0];
|
||||
$regex_match_2 = $matches[2][0];
|
||||
@@ -527,7 +553,7 @@
|
||||
if ($field['dialplan_detail_type'] == "set" && $field['dialplan_detail_tag'] == "action") {
|
||||
//only set variables with values not variables
|
||||
if (strpos($field['dialplan_detail_data'], '$') === false) {
|
||||
$this->variables .= $field['dialplan_detail_data'].",";
|
||||
$this->variables .= $field['dialplan_detail_data'] . ",";
|
||||
}
|
||||
}
|
||||
//process the $x detail data variables
|
||||
@@ -546,12 +572,19 @@
|
||||
} //function
|
||||
|
||||
//combines array dialplans and dialplan details arrays to match results from the database
|
||||
/**
|
||||
* Prepares an array of dialplan details from the provided database array.
|
||||
*
|
||||
* @param array $database_array An array containing database connections and dialplan data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepare_details($database_array) {
|
||||
$array = [];
|
||||
$id = 0;
|
||||
foreach($database_array['dialplans'] as $row) {
|
||||
foreach ($database_array['dialplans'] as $row) {
|
||||
if (!empty($row['dialplan_details'])) {
|
||||
foreach($row['dialplan_details'] as $detail) {
|
||||
foreach ($row['dialplan_details'] as $detail) {
|
||||
if ($detail['dialplan_detail_enabled'] == 'true') {
|
||||
$array[$id]['domain_uuid'] = $row['domain_uuid'];
|
||||
$array[$id]['dialplan_uuid'] = $row['dialplan_uuid'];
|
||||
@@ -585,6 +618,12 @@
|
||||
}
|
||||
|
||||
//reads dialplan details from the database to build the xml
|
||||
|
||||
/**
|
||||
* Generates XML representation of dialplans.
|
||||
*
|
||||
* @return string XML string representing the dialplans.
|
||||
*/
|
||||
public function xml() {
|
||||
|
||||
//set the xml array and then concatenate the array to a string
|
||||
@@ -608,13 +647,11 @@
|
||||
if (is_uuid($this->uuid)) {
|
||||
$sql .= "where dialplan_uuid = :dialplan_uuid ";
|
||||
$parameters['dialplan_uuid'] = $this->uuid;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!empty($this->context)) {
|
||||
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
|
||||
$sql .= "where dialplan_context = :dialplan_context ";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sql .= "where (dialplan_context = :dialplan_context or dialplan_context = '\${domain_name}' or dialplan_context = 'global') ";
|
||||
}
|
||||
$sql .= "and dialplan_enabled = true ";
|
||||
@@ -645,7 +682,7 @@
|
||||
$sql = "select * from v_domains ";
|
||||
$result = $this->database->select($sql, null, 'all');
|
||||
if (!empty($result)) {
|
||||
foreach($result as $row) {
|
||||
foreach ($result as $row) {
|
||||
$domains[$row['domain_uuid']] = $row['domain_name'];
|
||||
}
|
||||
}
|
||||
@@ -667,8 +704,7 @@
|
||||
if (isset($this->context)) {
|
||||
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
|
||||
$sql .= "and p.dialplan_context = :dialplan_context \n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sql .= "and (p.dialplan_context = :dialplan_context or p.dialplan_context = '\${domain_name}' or dialplan_context = 'global') \n";
|
||||
}
|
||||
$parameters['dialplan_context'] = $this->context;
|
||||
@@ -758,18 +794,15 @@
|
||||
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
|
||||
$condition_attribute = "";
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
else if (!empty($condition) && substr($condition, -1) == ">") {
|
||||
$xml .= " ".$condition;
|
||||
} elseif (!empty($condition) && substr($condition, -1) == ">") {
|
||||
$xml .= " " . $condition;
|
||||
$condition = "";
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
else if (!empty($condition)) {
|
||||
$xml .= " ".$condition . "/>";
|
||||
} elseif (!empty($condition)) {
|
||||
$xml .= " " . $condition . "/>";
|
||||
$condition = "";
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
else if ($condition_tag_status != "closed") {
|
||||
} elseif ($condition_tag_status != "closed") {
|
||||
$xml .= " </condition>\n";
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
@@ -805,41 +838,29 @@
|
||||
//determine the type of condition
|
||||
if ($dialplan_detail_type == "hour") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "minute") {
|
||||
} elseif ($dialplan_detail_type == "minute") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "minute-of-day") {
|
||||
} elseif ($dialplan_detail_type == "minute-of-day") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "mday") {
|
||||
} elseif ($dialplan_detail_type == "mday") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "mweek") {
|
||||
} elseif ($dialplan_detail_type == "mweek") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "mon") {
|
||||
} elseif ($dialplan_detail_type == "mon") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "time-of-day") {
|
||||
} elseif ($dialplan_detail_type == "time-of-day") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "yday") {
|
||||
} elseif ($dialplan_detail_type == "yday") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "year") {
|
||||
} elseif ($dialplan_detail_type == "year") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "wday") {
|
||||
} elseif ($dialplan_detail_type == "wday") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "week") {
|
||||
} elseif ($dialplan_detail_type == "week") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else if ($dialplan_detail_type == "date-time") {
|
||||
} elseif ($dialplan_detail_type == "date-time") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$condition_type = 'default';
|
||||
}
|
||||
|
||||
@@ -849,13 +870,11 @@
|
||||
$xml .= $condition . "\n";
|
||||
$condition = '';
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
else if (!empty($condition)) {
|
||||
} elseif (!empty($condition)) {
|
||||
$xml .= $condition . "/>\n";
|
||||
$condition = '';
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
else if (!empty($condition_attribute) && $condition_tag_status == "open") {
|
||||
} elseif (!empty($condition_attribute) && $condition_tag_status == "open") {
|
||||
// previous condition(s) must have been of type time
|
||||
// do not finalize if new condition is also of type time
|
||||
if ($condition_type != 'time') {
|
||||
@@ -882,25 +901,20 @@
|
||||
//condition tag but leave off the ending
|
||||
if ($condition_type == "default") {
|
||||
if (isset($dialplan_detail_type) && $dialplan_detail_tag == 'condition' && $dialplan_detail_type == 'regex') {
|
||||
$condition = " <condition regex=\"" . $dialplan_detail_data . "\"" . $condition_break.">";
|
||||
}
|
||||
elseif (isset($dialplan_detail_type) && $dialplan_detail_tag == 'regex') {
|
||||
$condition = " <condition regex=\"" . $dialplan_detail_data . "\"" . $condition_break . ">";
|
||||
} elseif (isset($dialplan_detail_type) && $dialplan_detail_tag == 'regex') {
|
||||
$condition = " <regex field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break . "/>";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$condition = " <condition field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break;
|
||||
}
|
||||
}
|
||||
else if ($condition_type == "time") {
|
||||
} elseif ($condition_type == "time") {
|
||||
if ($condition_attribute) {
|
||||
$condition_attribute = $condition_attribute . $dialplan_detail_type . "=\"" . $dialplan_detail_data . "\" ";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$condition_attribute = $dialplan_detail_type . "=\"" . $dialplan_detail_data . "\" ";
|
||||
}
|
||||
$condition = ""; //prevents a duplicate time condition
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$condition = " <condition field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break;
|
||||
}
|
||||
$condition_tag_status = "open";
|
||||
@@ -911,12 +925,10 @@
|
||||
if ($condition_attribute && (!empty($condition_attribute))) {
|
||||
$xml .= " <condition " . $condition_attribute . $condition_break . ">\n";
|
||||
$condition_attribute = "";
|
||||
}
|
||||
else if (!empty($condition) && !empty($condition_tag_status) && substr($condition, -1) == ">") {
|
||||
} elseif (!empty($condition) && !empty($condition_tag_status) && substr($condition, -1) == ">") {
|
||||
$xml .= $condition . "\n";
|
||||
$condition = "";
|
||||
}
|
||||
else if (!empty($condition) && !empty($condition_tag_status)) {
|
||||
} elseif (!empty($condition) && !empty($condition_tag_status)) {
|
||||
$xml .= $condition . ">\n";
|
||||
$condition = "";
|
||||
}
|
||||
@@ -976,14 +988,11 @@
|
||||
if ($condition_tag_status == "open") {
|
||||
if ($condition_attribute && (!empty($condition_attribute))) {
|
||||
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
|
||||
}
|
||||
else if (!empty($condition) && substr($condition, -1) == ">") {
|
||||
} elseif (!empty($condition) && substr($condition, -1) == ">") {
|
||||
$xml .= $condition . "\n";
|
||||
}
|
||||
else if (!empty($condition)) {
|
||||
} elseif (!empty($condition)) {
|
||||
$xml .= $condition . "/>\n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$xml .= " </condition>\n";
|
||||
}
|
||||
}
|
||||
@@ -1032,6 +1041,14 @@
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the object with default settings and updates the database.
|
||||
*
|
||||
* This method processes XML files, imports domains, and updates dialplan orders in the database.
|
||||
* It also adds XML for each dialplan where the dialplan XML is empty.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function defaults() {
|
||||
|
||||
//get the array of xml files and then process thm
|
||||
@@ -1044,8 +1061,7 @@
|
||||
$name_array = explode('_', basename($xml_file));
|
||||
if (is_numeric($name_array[0])) {
|
||||
$dialplan_order = $name_array[0];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$dialplan_order = 0;
|
||||
}
|
||||
|
||||
@@ -1079,11 +1095,17 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1092,8 +1114,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1105,7 +1127,7 @@
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
|
||||
//build delete array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array['dialplan_details'][$x]['dialplan_uuid'] = $record['uuid'];
|
||||
|
||||
//get the dialplan context
|
||||
@@ -1138,7 +1160,7 @@
|
||||
$dialplan_contexts = array_unique($dialplan_contexts, SORT_STRING);
|
||||
$cache = new cache;
|
||||
foreach ($dialplan_contexts as $dialplan_context) {
|
||||
$cache->delete("dialplan:".$dialplan_context);
|
||||
$cache->delete("dialplan:" . $dialplan_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1148,7 +1170,7 @@
|
||||
}
|
||||
|
||||
//set message
|
||||
message::add($text['message-delete'].': '.@sizeof($array[$this->table]));
|
||||
message::add($text['message-delete'] . ': ' . @sizeof($array[$this->table]));
|
||||
|
||||
}
|
||||
unset($records, $array);
|
||||
@@ -1157,13 +1179,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple records from the dialplan details table.
|
||||
*
|
||||
* @param array $records An array of record IDs to delete, each containing a 'checked' and 'uuid' key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_details($records) {
|
||||
//set private variables
|
||||
$this->table = 'dialplan_details';
|
||||
$this->uuid_prefix = 'dialplan_detail_';
|
||||
|
||||
//check the delete permission
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1172,8 +1201,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1185,7 +1214,7 @@
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
|
||||
//build delete array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['dialplan_uuid'] = $this->dialplan_uuid;
|
||||
|
||||
//get the dialplan context
|
||||
@@ -1216,7 +1245,7 @@
|
||||
$dialplan_contexts = array_unique($dialplan_contexts, SORT_STRING);
|
||||
$cache = new cache;
|
||||
foreach ($dialplan_contexts as $dialplan_context) {
|
||||
$cache->delete("dialplan:".$dialplan_context);
|
||||
$cache->delete("dialplan:" . $dialplan_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1228,11 +1257,17 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1241,8 +1276,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1250,14 +1285,14 @@
|
||||
if (!empty($records)) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids)) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, dialplan_context from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, dialplan_context from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
if (!permission_exists('dialplan_all')) {
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -1274,8 +1309,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -1299,7 +1334,7 @@
|
||||
$dialplan_contexts = array_unique($dialplan_contexts, SORT_STRING);
|
||||
$cache = new cache;
|
||||
foreach ($dialplan_contexts as $dialplan_context) {
|
||||
$cache->delete("dialplan:".$dialplan_context);
|
||||
$cache->delete("dialplan:" . $dialplan_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1318,12 +1353,18 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
|
||||
//determine app and permission prefix
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1332,8 +1373,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1341,9 +1382,9 @@
|
||||
if (!empty($records)) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1351,8 +1392,8 @@
|
||||
if (!empty($uuids)) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (!empty($rows)) {
|
||||
$y = 0;
|
||||
@@ -1361,7 +1402,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -1375,19 +1416,24 @@
|
||||
//except for inbound and outbound routes, fifo, time conditions
|
||||
$app_uuid = $row['app_uuid'];
|
||||
switch ($app_uuid) {
|
||||
case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": break;
|
||||
case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": break;
|
||||
case "16589224-c876-aeb3-f59f-523a1c0801f7": break;
|
||||
case "4b821450-926b-175a-af93-a03c441818b1": break;
|
||||
default: $app_uuid = uuid();
|
||||
case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4":
|
||||
break;
|
||||
case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3":
|
||||
break;
|
||||
case "16589224-c876-aeb3-f59f-523a1c0801f7":
|
||||
break;
|
||||
case "4b821450-926b-175a-af93-a03c441818b1":
|
||||
break;
|
||||
default:
|
||||
$app_uuid = uuid();
|
||||
}
|
||||
|
||||
//dialplan copy should have a unique app_uuid
|
||||
$array[$this->table][$x]['app_uuid'] = $app_uuid;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['dialplan_description'] = trim($row['dialplan_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['dialplan_description'] = trim($row['dialplan_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//details sub table
|
||||
$sql_2 = "select * from v_dialplan_details where dialplan_uuid = :dialplan_uuid";
|
||||
@@ -1397,7 +1443,7 @@
|
||||
foreach ($rows_2 as $row_2) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -1444,7 +1490,7 @@
|
||||
$dialplan_contexts = array_unique($dialplan_contexts, SORT_STRING);
|
||||
$cache = new cache;
|
||||
foreach ($dialplan_contexts as $dialplan_context) {
|
||||
$cache->delete("dialplan:".$dialplan_context);
|
||||
$cache->delete("dialplan:" . $dialplan_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1458,5 +1504,4 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* email_queue class
|
||||
*/
|
||||
class email_queue {
|
||||
class email_queue {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -13,24 +13,30 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -45,7 +51,12 @@
|
||||
private $location;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -60,15 +71,21 @@
|
||||
$this->name = 'email_queue';
|
||||
$this->table = 'email_queue';
|
||||
$this->toggle_field = '';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->location = 'email_queue.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -77,8 +94,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -89,8 +106,8 @@
|
||||
foreach ($records as $record) {
|
||||
//add to the array
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array['email_queue_attachments'][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
$array['email_queue_attachments'][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
//$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
|
||||
@@ -113,10 +130,19 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* resend emails in the queue
|
||||
* Resend multiple records.
|
||||
*
|
||||
* This method will resend the specified records if the permission to edit exists.
|
||||
* It first checks if the token is valid, then it iterates over the records and
|
||||
* updates their status to 'waiting' and resets the retry count. Finally, it saves
|
||||
* the changes to the database.
|
||||
*
|
||||
* @param array $records The records to resend.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resend($records) {
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -125,8 +151,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -137,7 +163,7 @@
|
||||
foreach ($records as $record) {
|
||||
//add to the array
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['email_status'] = 'waiting';
|
||||
$array[$this->table][$x]['email_retry_count'] = null;
|
||||
}
|
||||
@@ -162,10 +188,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle a field between two values
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -174,22 +206,22 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
//toggle the checked records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
//get current toggle state
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
@@ -203,9 +235,9 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -228,10 +260,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy rows from the database
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->name.'_add')) {
|
||||
if (permission_exists($this->name . '_add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -240,8 +278,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -249,16 +287,16 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create the array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
@@ -269,7 +307,7 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//add copy to the description
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = uuid();
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = uuid();
|
||||
|
||||
//increment the id
|
||||
$x++;
|
||||
@@ -293,4 +331,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/**
|
||||
* event_guard_logs class
|
||||
*/
|
||||
class event_guard {
|
||||
class event_guard {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -37,24 +37,30 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -69,7 +75,12 @@
|
||||
private $location;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -83,15 +94,21 @@
|
||||
$this->name = 'event_guard_log';
|
||||
$this->table = 'event_guard_logs';
|
||||
$this->toggle_field = '';
|
||||
$this->toggle_values = ['block','pending'];
|
||||
$this->toggle_values = ['block', 'pending'];
|
||||
$this->location = 'event_guard_logs.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -100,8 +117,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -134,10 +151,14 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* update rows from the database change status to pending
|
||||
* Unblocks multiple records.
|
||||
*
|
||||
* @param array $records An array of records to unblock, each containing 'event_guard_log_uuid' and 'checked' keys.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unblock($records) {
|
||||
if (permission_exists($this->name.'_unblock')) {
|
||||
if (permission_exists($this->name . '_unblock')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -146,8 +167,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -191,10 +212,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle a field between two values
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -203,22 +230,22 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
//toggle the checked records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
//get current toggle state
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['event_guard_log_uuid'])) {
|
||||
$uuids[] = "'".$record['event_guard_log_uuid']."'";
|
||||
$uuids[] = "'" . $record['event_guard_log_uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -230,9 +257,9 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -255,10 +282,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy rows from the database
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->name.'_add')) {
|
||||
if (permission_exists($this->name . '_add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -267,8 +300,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -276,22 +309,22 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['event_guard_log_uuid'])) {
|
||||
$uuids[] = "'".$record['event_guard_log_uuid']."'";
|
||||
$uuids[] = "'" . $record['event_guard_log_uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create the array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where event_guard_log_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where event_guard_log_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
$x = 0;
|
||||
foreach ($rows as $row) {
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -326,4 +359,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,13 @@
|
||||
echo "pid_file: ".$pid_file."\n";
|
||||
|
||||
//function to check if the process exists
|
||||
/**
|
||||
* Checks if a process exists.
|
||||
*
|
||||
* @param string $file Path to the file containing the process ID (PID)
|
||||
*
|
||||
* @return bool True if the process exists, false otherwise
|
||||
*/
|
||||
function process_exists($file) {
|
||||
|
||||
//set the default exists to false
|
||||
@@ -373,6 +380,13 @@
|
||||
}
|
||||
|
||||
//run command and capture standard output
|
||||
/**
|
||||
* Execute a shell command and capture its output.
|
||||
*
|
||||
* @param string $command The shell command to execute
|
||||
*
|
||||
* @return string The output of the executed command
|
||||
*/
|
||||
function shell($command) {
|
||||
ob_start();
|
||||
$result = system($command);
|
||||
@@ -381,6 +395,15 @@
|
||||
}
|
||||
|
||||
//block an ip address
|
||||
/**
|
||||
* Execute a block command for iptables or pf based on the firewall type.
|
||||
*
|
||||
* @param string $ip_address The IP address to block
|
||||
* @param string $filter The filter name for iptables or pf
|
||||
* @param array $event The event data containing 'to-user' and 'to-host'
|
||||
*
|
||||
* @return boolean True if the block command was executed successfully, false otherwise
|
||||
*/
|
||||
function block($ip_address, $filter, $event) {
|
||||
//define the global variables
|
||||
global $database, $debug, $firewall_path, $firewall_name;
|
||||
@@ -434,6 +457,14 @@
|
||||
}
|
||||
|
||||
//unblock the ip address
|
||||
/**
|
||||
* Unblock a specified IP address from a firewall.
|
||||
*
|
||||
* @param string $ip_address The IP address to unblock.
|
||||
* @param string $filter The filter name used in the firewall configuration.
|
||||
*
|
||||
* @return bool True if the IP address was successfully unblocked, false otherwise.
|
||||
*/
|
||||
function unblock($ip_address, $filter) {
|
||||
//define the global variables
|
||||
global $debug, $firewall_path, $firewall_name;
|
||||
@@ -470,6 +501,13 @@
|
||||
}
|
||||
|
||||
//is the ip address blocked
|
||||
/**
|
||||
* Check if an IP address is blocked in the configured firewall.
|
||||
*
|
||||
* @param string $ip_address The IP address to check
|
||||
*
|
||||
* @return bool True if the address is blocked, False otherwise
|
||||
*/
|
||||
function is_blocked($ip_address) {
|
||||
//define the global variables
|
||||
global $firewall_path, $firewall_name;
|
||||
@@ -502,6 +540,17 @@
|
||||
}
|
||||
|
||||
//determine if the IP address has been allowed by the access control list node cidr
|
||||
/**
|
||||
* Determine if access is allowed for a given IP address.
|
||||
*
|
||||
* This method checks the cache, user logs, event guard logs, access controls,
|
||||
* and registration to determine if access should be granted. If no valid reason
|
||||
* is found to deny access, it will be automatically allowed.
|
||||
*
|
||||
* @param string $ip_address The IP address to check for access.
|
||||
*
|
||||
* @return boolean True if access is allowed, false otherwise.
|
||||
*/
|
||||
function access_allowed($ip_address) {
|
||||
//define global variables
|
||||
global $debug;
|
||||
@@ -586,6 +635,13 @@
|
||||
}
|
||||
|
||||
//is the ip address registered
|
||||
/**
|
||||
* Checks if the given IP address is registered on the network.
|
||||
*
|
||||
* @param string $ip_address The IP address to check for registration.
|
||||
*
|
||||
* @return bool True if the IP address is registered, false otherwise.
|
||||
*/
|
||||
function is_registered($ip_address) {
|
||||
//invalid ip address
|
||||
if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
|
||||
@@ -609,6 +665,13 @@
|
||||
}
|
||||
|
||||
//determine if the IP address has been allowed by the access control list node cidr
|
||||
/**
|
||||
* Checks if the given IP address is authorized by any access control node.
|
||||
*
|
||||
* @param string $ip_address The IP address to check for authorization.
|
||||
*
|
||||
* @return bool True if the IP address is authorized, false otherwise.
|
||||
*/
|
||||
function access_control_allowed($ip_address) {
|
||||
|
||||
global $database;
|
||||
@@ -653,6 +716,13 @@
|
||||
}
|
||||
|
||||
//determine if the IP address has been allowed by a successful authentication
|
||||
/**
|
||||
* Determines if a user's IP address is allowed based on their login history.
|
||||
*
|
||||
* @param string $ip_address The IP address to check for access.
|
||||
*
|
||||
* @return bool True if the IP address is allowed, false otherwise.
|
||||
*/
|
||||
function user_log_allowed($ip_address) {
|
||||
|
||||
global $database, $debug;
|
||||
@@ -689,6 +759,13 @@
|
||||
}
|
||||
|
||||
//determine if the IP address has been unblocked in the event guard log
|
||||
/**
|
||||
* Determines if an IP address is allowed based on event guard logs.
|
||||
*
|
||||
* @param string $ip_address The IP address to check for access.
|
||||
*
|
||||
* @return bool True if the IP address is allowed, false otherwise.
|
||||
*/
|
||||
function event_guard_log_allowed($ip_address) {
|
||||
|
||||
global $database, $debug;
|
||||
@@ -724,6 +801,13 @@
|
||||
}
|
||||
|
||||
//check if the iptables chain exists
|
||||
/**
|
||||
* Determines if a pf table exists in the firewall configuration.
|
||||
*
|
||||
* @param string $table The name of the pf table to check for existence.
|
||||
*
|
||||
* @return bool True if the pf table exists, false otherwise.
|
||||
*/
|
||||
function pf_table_exists($table) {
|
||||
//define the global variables
|
||||
global $firewall_path, $firewall_name;
|
||||
@@ -741,6 +825,13 @@
|
||||
}
|
||||
|
||||
//add IP table chains
|
||||
/**
|
||||
* Adds a new IPtables chain and inserts it into the INPUT table.
|
||||
*
|
||||
* @param string $chain The name of the IPtables chain to add.
|
||||
*
|
||||
* @return bool True if the chain was successfully added, false otherwise.
|
||||
*/
|
||||
function iptables_chain_add($chain) {
|
||||
//define the global variables
|
||||
global $firewall_path;
|
||||
@@ -769,6 +860,13 @@
|
||||
}
|
||||
|
||||
//check if the iptables chain exists
|
||||
/**
|
||||
* Determines if a specified iptables chain exists.
|
||||
*
|
||||
* @param string $chain The name of the iptables chain to check for existence.
|
||||
*
|
||||
* @return bool True if the iptables chain exists, false otherwise.
|
||||
*/
|
||||
function iptables_chain_exists($chain) {
|
||||
//define the global variables
|
||||
global $firewall_path;
|
||||
@@ -784,5 +882,3 @@
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/**
|
||||
* extension_settings class
|
||||
*/
|
||||
class extension_settings {
|
||||
class extension_settings {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -42,24 +42,30 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -75,7 +81,12 @@
|
||||
private $location;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -89,17 +100,23 @@
|
||||
$this->name = 'extension_setting';
|
||||
$this->table = 'extension_settings';
|
||||
$this->toggle_field = 'extension_setting_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->description_field = 'extension_setting_description';
|
||||
$this->location = 'extension_settings.php';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -108,8 +125,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -120,13 +137,13 @@
|
||||
foreach ($records as $record) {
|
||||
//add to the array
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
|
||||
if (empty($this->extension_uuid)) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle, extension_uuid ";
|
||||
$sql .= "from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in :uuid ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle, extension_uuid ";
|
||||
$sql .= "from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in :uuid ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$parameters['uuid'] = $record['uuid'];
|
||||
@@ -155,8 +172,8 @@
|
||||
$parameters['extension_uuid'] = $this->extension_uuid;
|
||||
$extension = $this->database->select($sql, $parameters, 'row');
|
||||
$cache = new cache;
|
||||
$cache->delete(gethostname().":directory:".$extension["extension"]."@".$extension["user_context"]);
|
||||
$cache->delete(gethostname().":directory:".$extension["number_alias"]."@".$extension["user_context"]);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension["extension"] . "@" . $extension["user_context"]);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension["number_alias"] . "@" . $extension["user_context"]);
|
||||
}
|
||||
|
||||
//set message
|
||||
@@ -168,10 +185,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle a field between two values
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -180,8 +203,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -190,12 +213,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle, extension_uuid from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle, extension_uuid from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
@@ -210,9 +233,9 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -232,8 +255,8 @@
|
||||
$parameters['extension_uuid'] = $this->extension_uuid;
|
||||
$extension = $this->database->select($sql, $parameters, 'row');
|
||||
$cache = new cache;
|
||||
$cache->delete(gethostname().":directory:".$extension["extension"]."@".$extension["user_context"]);
|
||||
$cache->delete(gethostname().":directory:".$extension["number_alias"]."@".$extension["user_context"]);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension["extension"] . "@" . $extension["user_context"]);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension["number_alias"] . "@" . $extension["user_context"]);
|
||||
|
||||
//set message
|
||||
message::add($text['message-toggle']);
|
||||
@@ -244,10 +267,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy rows from the database
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->name.'_add')) {
|
||||
if (permission_exists($this->name . '_add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -256,8 +285,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -267,21 +296,21 @@
|
||||
//get checked records
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create the array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $x => $row) {
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -292,9 +321,9 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = uuid();
|
||||
$array[$this->table][$x][$this->name.'_enabled'] = $row['extension_setting_enabled'] === true ? 'true' : 'false';
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field] ?? '').' ('.$text['label-copy'].')';
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = uuid();
|
||||
$array[$this->table][$x][$this->name . '_enabled'] = $row['extension_setting_enabled'] === true ? 'true' : 'false';
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field] ?? '') . ' (' . $text['label-copy'] . ')';
|
||||
|
||||
}
|
||||
}
|
||||
@@ -315,4 +344,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,13 @@
|
||||
$available_columns[] = 'forward_user_not_registered_enabled';
|
||||
|
||||
//define the functions
|
||||
/**
|
||||
* Converts a multi-dimensional array into a CSV string.
|
||||
*
|
||||
* @param array &$array The input array to be converted. It is expected that all rows of the array have the same number of columns.
|
||||
*
|
||||
* @return string|null The CSV string representation of the input array, or null if the input array is empty.
|
||||
*/
|
||||
function array2csv(array &$array) {
|
||||
if (count($array) == 0) {
|
||||
return null;
|
||||
@@ -107,6 +114,11 @@
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the headers for a file download.
|
||||
*
|
||||
* @param string $filename The name of the file to be downloaded.
|
||||
*/
|
||||
function download_send_headers($filename) {
|
||||
// disable caching
|
||||
$now = gmdate("D, d M Y H:i:s");
|
||||
|
||||
@@ -50,6 +50,16 @@
|
||||
$page = isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? $_REQUEST['page'] : 0;
|
||||
|
||||
//return the first item if data type = array, returns value if data type = text
|
||||
/**
|
||||
* Returns the first item of a given value.
|
||||
*
|
||||
* If the value is an array, returns the first element of the array.
|
||||
* Otherwise, returns the value as is.
|
||||
*
|
||||
* @param mixed $value The value to retrieve the first item from.
|
||||
*
|
||||
* @return mixed The first item of the value.
|
||||
*/
|
||||
function get_first_item($value) {
|
||||
return is_array($value) ? $value[0] : $value;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
fclose($fp);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
//get the http get values and set them as php variables
|
||||
$action = $_POST["action"] ?? null;
|
||||
$from_row = $_POST["from_row"] ?? null;
|
||||
@@ -224,6 +212,14 @@
|
||||
}
|
||||
|
||||
//get the parent table
|
||||
/**
|
||||
* Retrieves the parent table name for a given table in the database schema.
|
||||
*
|
||||
* @param array $schema The database schema, where each element is an associative array containing 'table' and 'parent' keys.
|
||||
* @param string $table_name The name of the table for which to retrieve the parent table name.
|
||||
*
|
||||
* @return mixed|null The parent table name if found, otherwise null.
|
||||
*/
|
||||
function get_parent($schema,$table_name) {
|
||||
foreach ($schema as $row) {
|
||||
if ($row['table'] == $table_name) {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the directory class
|
||||
class extension {
|
||||
class extension {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -34,13 +34,17 @@
|
||||
const app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
|
||||
* in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $domain_name;
|
||||
@@ -91,18 +95,22 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
@@ -118,7 +126,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -136,9 +149,17 @@
|
||||
$this->table = 'extensions';
|
||||
$this->uuid_prefix = 'extension_';
|
||||
$this->toggle_field = 'enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an extension exists for a given domain UUID.
|
||||
*
|
||||
* @param string $domain_uuid The unique identifier of the domain.
|
||||
* @param string $extension The name or alias of the extension to check.
|
||||
*
|
||||
* @return bool True if the extension exists, false otherwise.
|
||||
*/
|
||||
public function exists($domain_uuid, $extension) {
|
||||
$sql = "select count(*) from v_extensions ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
@@ -150,23 +171,38 @@
|
||||
$parameters['domain_uuid'] = $domain_uuid;
|
||||
$parameters['extension'] = $extension;
|
||||
return $this->database->select($sql, $parameters, 'column') != 0 ? true : false;
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the domain UUID associated with this object.
|
||||
*
|
||||
* @return string The domain UUID as a string.
|
||||
*/
|
||||
public function get_domain_uuid() {
|
||||
return $this->domain_uuid;
|
||||
}
|
||||
|
||||
public function set_domain_uuid($domain_uuid){
|
||||
/**
|
||||
* Sets the domain UUID for the current session.
|
||||
*
|
||||
* @param string $domain_uuid The UUID of the domain to be set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_domain_uuid($domain_uuid) {
|
||||
$this->domain_uuid = $domain_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates or inserts the voicemail settings in the database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function voicemail() {
|
||||
//determine the voicemail_id
|
||||
if (is_numeric($this->number_alias)) {
|
||||
$this->voicemail_id = $this->number_alias;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->voicemail_id = $this->extension;
|
||||
}
|
||||
|
||||
@@ -185,8 +221,7 @@
|
||||
//grant temporary permissions
|
||||
$p = permissions::new();
|
||||
$p->add('voicemail_edit', 'temp');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//build insert array
|
||||
$array['voicemails'][0]['voicemail_uuid'] = uuid();
|
||||
$array['voicemails'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -216,6 +251,11 @@
|
||||
unset($voicemail_uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates XML files for extensions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function xml() {
|
||||
if (!empty($this->settings->get('switch', 'extensions'))) {
|
||||
//declare global variables
|
||||
@@ -226,8 +266,8 @@
|
||||
$user_context = $domain_name;
|
||||
|
||||
//delete all old extensions to prepare for new ones
|
||||
$dialplan_list = glob($this->settings->get('switch', 'extensions')."/".$user_context."/v_*.xml");
|
||||
foreach($dialplan_list as $name => $value) {
|
||||
$dialplan_list = glob($this->settings->get('switch', 'extensions') . "/" . $user_context . "/v_*.xml");
|
||||
foreach ($dialplan_list as $name => $value) {
|
||||
unlink($value);
|
||||
}
|
||||
|
||||
@@ -252,9 +292,8 @@
|
||||
if (!empty($tmp_call_group)) {
|
||||
if (empty($call_group_array[$tmp_call_group])) {
|
||||
$call_group_array[$tmp_call_group] = $row['extension'];
|
||||
}
|
||||
else {
|
||||
$call_group_array[$tmp_call_group] = $call_group_array[$tmp_call_group].','.$row['extension'];
|
||||
} else {
|
||||
$call_group_array[$tmp_call_group] = $call_group_array[$tmp_call_group] . ',' . $row['extension'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,15 +314,14 @@
|
||||
if (empty($dial_string)) {
|
||||
if (!empty($this->settings->get('domain', 'dial_string'))) {
|
||||
$dial_string = $this->settings->get('domain', 'dial_string');
|
||||
}
|
||||
else {
|
||||
$dial_string = "{sip_invite_domain=\${domain_name},leg_timeout=".$call_timeout.",presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}";
|
||||
} else {
|
||||
$dial_string = "{sip_invite_domain=\${domain_name},leg_timeout=" . $call_timeout . ",presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}";
|
||||
}
|
||||
}
|
||||
|
||||
//set the password hashes
|
||||
$a1_hash = md5($extension.":".$domain_name.":".$password);
|
||||
$vm_a1_hash = md5($extension.":".$domain_name.":".$voicemail_password);
|
||||
$a1_hash = md5($extension . ":" . $domain_name . ":" . $password);
|
||||
$vm_a1_hash = md5($extension . ":" . $domain_name . ":" . $voicemail_password);
|
||||
|
||||
$xml = "<include>\n";
|
||||
$cidr = '';
|
||||
@@ -292,9 +330,9 @@
|
||||
}
|
||||
$number_alias = '';
|
||||
if (!empty($row['number_alias'])) {
|
||||
$number_alias = " number-alias=\"".$row['number_alias']."\"";
|
||||
$number_alias = " number-alias=\"" . $row['number_alias'] . "\"";
|
||||
}
|
||||
$xml .= " <user id=\"".$row['extension']."\"".$cidr."".$number_alias.">\n";
|
||||
$xml .= " <user id=\"" . $row['extension'] . "\"" . $cidr . "" . $number_alias . ">\n";
|
||||
$xml .= " <params>\n";
|
||||
//$xml .= " <param name=\"a1-hash\" value=\"" . $a1_hash . "\"/>\n";
|
||||
$xml .= " <param name=\"password\" value=\"" . $row['password'] . "\"/>\n";
|
||||
@@ -366,8 +404,7 @@
|
||||
}
|
||||
if (!empty($switch_account_code)) {
|
||||
$xml .= " <variable name=\"accountcode\" value=\"" . $switch_account_code . "\"/>\n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$xml .= " <variable name=\"accountcode\" value=\"" . $row['accountcode'] . "\"/>\n";
|
||||
}
|
||||
$xml .= " <variable name=\"user_context\" value=\"" . $row['user_context'] . "\"/>\n";
|
||||
@@ -397,8 +434,7 @@
|
||||
}
|
||||
if (!empty($row['limit_max'])) {
|
||||
$xml .= " <variable name=\"limit_max\" value=\"" . $row['limit_max'] . "\"/>\n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$xml .= " <variable name=\"limit_max\" value=\"5\"/>\n";
|
||||
}
|
||||
if (!empty($row['limit_destination'])) {
|
||||
@@ -458,11 +494,11 @@
|
||||
$xml .= " </variables>\n";
|
||||
$xml .= " </user>\n";
|
||||
|
||||
if (!is_readable($this->settings->get('switch', 'extensions')."/".$row['user_context'])) {
|
||||
mkdir($this->settings->get('switch', 'extensions')."/".$row['user_context'], 0770, false);
|
||||
if (!is_readable($this->settings->get('switch', 'extensions') . "/" . $row['user_context'])) {
|
||||
mkdir($this->settings->get('switch', 'extensions') . "/" . $row['user_context'], 0770, false);
|
||||
}
|
||||
if (!empty($extension)) {
|
||||
$fout = fopen($this->settings->get('switch', 'extensions')."/".$row['user_context']."/v_".$extension.".xml","w");
|
||||
$fout = fopen($this->settings->get('switch', 'extensions') . "/" . $row['user_context'] . "/v_" . $extension . ".xml", "w");
|
||||
}
|
||||
$xml .= "</include>\n";
|
||||
fwrite($fout, $xml);
|
||||
@@ -502,9 +538,8 @@
|
||||
$xml .= " <!--the domain or ip (the right hand side of the @ in the addr-->\n";
|
||||
if ($user_context == "default") {
|
||||
$xml .= " <domain name=\"\$\${domain}\">\n";
|
||||
}
|
||||
else {
|
||||
$xml .= " <domain name=\"".$user_context."\">\n";
|
||||
} else {
|
||||
$xml .= " <domain name=\"" . $user_context . "\">\n";
|
||||
}
|
||||
$xml .= " <params>\n";
|
||||
//$xml .= " <param name=\"dial-string\" value=\"{sip_invite_domain=\${domain_name},presence_id=\${dialed_user}@\${dialed_domain}}\${sofia_contact(\${dialed_user}@\${dialed_domain})}\"/>\n";
|
||||
@@ -519,9 +554,9 @@
|
||||
$xml .= " </variables>\n";
|
||||
$xml .= "\n";
|
||||
$xml .= " <groups>\n";
|
||||
$xml .= " <group name=\"".$user_context."\">\n";
|
||||
$xml .= " <group name=\"" . $user_context . "\">\n";
|
||||
$xml .= " <users>\n";
|
||||
$xml .= " <X-PRE-PROCESS cmd=\"include\" data=\"".$user_context."/*.xml\"/>\n";
|
||||
$xml .= " <X-PRE-PROCESS cmd=\"include\" data=\"" . $user_context . "/*.xml\"/>\n";
|
||||
$xml .= " </users>\n";
|
||||
$xml .= " </group>\n";
|
||||
$xml .= "\n";
|
||||
@@ -557,7 +592,7 @@
|
||||
|
||||
//write the xml file
|
||||
if (is_readable($extension_dir) && !empty($extension_dir)) {
|
||||
$fout = fopen($extension_dir."/".$user_context.".xml","w");
|
||||
$fout = fopen($extension_dir . "/" . $user_context . ".xml", "w");
|
||||
fwrite($fout, $xml);
|
||||
unset($xml);
|
||||
fclose($fout);
|
||||
@@ -569,10 +604,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -581,8 +622,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -607,7 +648,7 @@
|
||||
$extensions[$x] = $row;
|
||||
|
||||
//build delete array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array['extension_users'][$x]['extension_uuid'] = $record['uuid'];
|
||||
|
||||
//include follow me destinations, if exists
|
||||
@@ -617,7 +658,7 @@
|
||||
}
|
||||
|
||||
//include ring group destinations, if exists
|
||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/ring_groups/app_config.php")) {
|
||||
if (file_exists($_SERVER["PROJECT_ROOT"] . "/app/ring_groups/app_config.php")) {
|
||||
$array['ring_group_destinations'][$x]['destination_number'] = $extensions[$x]['extension'];
|
||||
$array['ring_group_destinations'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
if (is_numeric($extensions[$x]['number_alias'])) {
|
||||
@@ -628,15 +669,19 @@
|
||||
}
|
||||
|
||||
//include extension settings, if exists
|
||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/extension_settings/app_config.php")) {
|
||||
if (file_exists($_SERVER["PROJECT_ROOT"] . "/app/extension_settings/app_config.php")) {
|
||||
$array['extension_settings'][$x]['extension_uuid'] = $record['uuid'];
|
||||
$array['extension_settings'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
|
||||
//create array of voicemail ids
|
||||
if ($this->delete_voicemail && permission_exists('voicemail_delete')) {
|
||||
if (is_numeric($extensions[$x]['extension'])) { $voicemail_ids[] = $extensions[$x]['extension']; }
|
||||
if (is_numeric($extensions[$x]['number_alias'])) { $voicemail_ids[] = $extensions[$x]['number_alias']; }
|
||||
if (is_numeric($extensions[$x]['extension'])) {
|
||||
$voicemail_ids[] = $extensions[$x]['extension'];
|
||||
}
|
||||
if (is_numeric($extensions[$x]['number_alias'])) {
|
||||
$voicemail_ids[] = $extensions[$x]['number_alias'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -658,7 +703,7 @@
|
||||
//retrieve voicemail uuids
|
||||
$sql = "select voicemail_uuid as uuid from v_voicemails ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and voicemail_id in ('".implode("','", $voicemail_ids)."') ";
|
||||
$sql .= "and voicemail_id in ('" . implode("','", $voicemail_ids) . "') ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -697,9 +742,9 @@
|
||||
//clear the cache
|
||||
foreach ($extensions as $x => $extension) {
|
||||
$cache = new cache;
|
||||
$cache->delete(gethostname().":directory:".$extension['extension']."@".$extension['user_context']);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension['extension'] . "@" . $extension['user_context']);
|
||||
if (permission_exists('number_alias') && !empty($extension['number_alias'])) {
|
||||
$cache->delete(gethostname().":directory:".$extension['number_alias']."@".$extension['user_context']);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension['number_alias'] . "@" . $extension['user_context']);
|
||||
}
|
||||
}
|
||||
unset($extensions);
|
||||
@@ -724,10 +769,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'enabled')) {
|
||||
if (permission_exists($this->permission_prefix . 'enabled')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -736,8 +787,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -745,15 +796,15 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, extension, number_alias, user_context from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, extension, number_alias, user_context from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -770,8 +821,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($extensions as $uuid => $extension) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($extensions as $uuid => $extension) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $extension['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -798,7 +849,7 @@
|
||||
|
||||
//write the provision files
|
||||
if (!empty($this->settings->get('provision', 'path'))) {
|
||||
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) {
|
||||
if (is_dir($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/app/provision')) {
|
||||
$prov = new provision;
|
||||
$prov->domain_uuid = $this->domain_uuid;
|
||||
$response = $prov->write();
|
||||
@@ -808,9 +859,9 @@
|
||||
//clear the cache
|
||||
foreach ($extensions as $uuid => $extension) {
|
||||
$cache = new cache;
|
||||
$cache->delete(gethostname().":directory:".$extension['extension']."@".$extension['user_context']);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension['extension'] . "@" . $extension['user_context']);
|
||||
if (permission_exists('number_alias') && !empty($extension['number_alias'])) {
|
||||
$cache->delete(gethostname().":directory:".$extension['number_alias']."@".$extension['user_context']);
|
||||
$cache->delete(gethostname() . ":directory:" . $extension['number_alias'] . "@" . $extension['user_context']);
|
||||
}
|
||||
}
|
||||
unset($extensions);
|
||||
@@ -830,4 +881,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,13 @@ $sql .= "and fax_email_outbound_subject_tag is not null ";
|
||||
$result = $database->select($sql, null, 'all');
|
||||
unset($sql);
|
||||
|
||||
/**
|
||||
* Converts an array to a map where each unique value in the array is mapped to true.
|
||||
*
|
||||
* @param array &$arr The input array
|
||||
*
|
||||
* @return array|false A map where each unique value in the array is mapped to true, or false if the input array is empty.
|
||||
*/
|
||||
function arr_to_map(&$arr){
|
||||
if (!empty($arr)){
|
||||
$map = Array();
|
||||
|
||||
@@ -127,6 +127,13 @@
|
||||
|
||||
//define function correct_path
|
||||
if (!function_exists('correct_path')) {
|
||||
/**
|
||||
* Corrects a file path to match the current operating system's conventions.
|
||||
*
|
||||
* @param string $p The file path to correct
|
||||
*
|
||||
* @return string The corrected file path
|
||||
*/
|
||||
function correct_path($p) {
|
||||
global $IS_WINDOWS;
|
||||
if ($IS_WINDOWS) {
|
||||
@@ -138,6 +145,17 @@ if (!function_exists('correct_path')) {
|
||||
|
||||
//define function gs_cmd
|
||||
if (!function_exists('gs_cmd')) {
|
||||
/**
|
||||
* Generates a command to execute Ghostscript.
|
||||
*
|
||||
* The command is constructed based on the value of $IS_WINDOWS, which indicates
|
||||
* whether the script is running under Windows. If it is, the command includes
|
||||
* the 'gswin32c' executable, otherwise it uses 'gs'.
|
||||
*
|
||||
* @param string $args Command line arguments to be passed to Ghostscript.
|
||||
*
|
||||
* @return string The constructed command as a string.
|
||||
*/
|
||||
function gs_cmd($args) {
|
||||
global $IS_WINDOWS;
|
||||
if ($IS_WINDOWS) {
|
||||
@@ -149,7 +167,17 @@ if (!function_exists('gs_cmd')) {
|
||||
|
||||
//define function fax_split dtmf
|
||||
if (!function_exists('fax_split_dtmf')) {
|
||||
function fax_split_dtmf(&$fax_number, &$fax_dtmf){
|
||||
/**
|
||||
* Splits a fax number string into its numeric and DTMF (Dual-Tone Multi-Frequency) parts.
|
||||
*
|
||||
* If the input fax number is in the format '12345678 (DTMF_digits)', this function
|
||||
* extracts the numeric part and stores it in $fax_number, while storing the DTMF digits
|
||||
* in $fax_dtmf.
|
||||
*
|
||||
* @param string &$fax_number The fax number to be split. Modified to contain only the numeric part.
|
||||
* @param string &$fax_dtmf The extracted DTMF digits from the input fax number.
|
||||
*/
|
||||
function fax_split_dtmf(&$fax_number, &$fax_dtmf) {
|
||||
$tmp = array();
|
||||
$fax_dtmf = '';
|
||||
if (preg_match('/^\s*(.*?)\s*\((.*)\)\s*$/', $fax_number, $tmp)){
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the fax class
|
||||
class fax {
|
||||
class fax {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -34,7 +34,9 @@
|
||||
const app_uuid = '24108154-4ac3-1db6-1551-4731703a4440';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
@@ -56,24 +58,30 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -90,7 +98,12 @@
|
||||
private $forward_prefix;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -104,9 +117,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a dialplan for call center
|
||||
* @var string $domain_uuid the multi-tenant id
|
||||
* @var string $value string to be cached
|
||||
* Processes and saves a dial plan for faxing.
|
||||
*
|
||||
* This method normalizes fax forward numbers, sets the forward prefix,
|
||||
* builds an XML dial plan, and saves it to the database. It also clears
|
||||
* any existing cache and removes temporary permissions after saving.
|
||||
*
|
||||
* @return mixed|null The UUID of the saved dialplan or null if not saved.
|
||||
*/
|
||||
public function dialplan() {
|
||||
|
||||
@@ -131,14 +148,13 @@
|
||||
if (strripos($this->fax_forward_number, '$1') === false) {
|
||||
$this->forward_prefix = ''; //not found
|
||||
} else {
|
||||
$this->forward_prefix = $this->forward_prefix.$this->fax_forward_number.'#'; //found
|
||||
$this->forward_prefix = $this->forward_prefix . $this->fax_forward_number . '#'; //found
|
||||
}
|
||||
|
||||
//set the dialplan_uuid
|
||||
if (empty($this->dialplan_uuid)) {
|
||||
$this->dialplan_uuid = uuid();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//build previous details delete array
|
||||
$array['dialplan_details'][0]['dialplan_uuid'] = $this->dialplan_uuid;
|
||||
$array['dialplan_details'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -162,31 +178,29 @@
|
||||
|
||||
//set the last fax
|
||||
if (!empty($this->settings->get('fax', 'last_fax'))) {
|
||||
$last_fax = "last_fax=".xml::sanitize($this->settings->get('fax', 'last_fax'));
|
||||
}
|
||||
else {
|
||||
$last_fax = "last_fax=" . xml::sanitize($this->settings->get('fax', 'last_fax'));
|
||||
} else {
|
||||
$last_fax = "last_fax=\${caller_id_number}-\${strftime(%Y-%m-%d-%H-%M-%S)}";
|
||||
}
|
||||
|
||||
//set the rx_fax
|
||||
$rxfax_data = $this->settings->get('switch', 'storage').'/fax/'.$this->domain_name.'/'.xml::sanitize($this->fax_extension).'/inbox/'.xml::sanitize($this->forward_prefix).'${last_fax}.tif';
|
||||
$rxfax_data = $this->settings->get('switch', 'storage') . '/fax/' . $this->domain_name . '/' . xml::sanitize($this->fax_extension) . '/inbox/' . xml::sanitize($this->forward_prefix) . '${last_fax}.tif';
|
||||
|
||||
//build the xml dialplan
|
||||
$dialplan_xml = "<extension name=\"".xml::sanitize($fax_name)."\" continue=\"false\" uuid=\"".xml::sanitize($this->dialplan_uuid)."\">\n";
|
||||
$dialplan_xml .= " <condition field=\"destination_number\" expression=\"^".xml::sanitize($this->destination_number)."$\">\n";
|
||||
$dialplan_xml = "<extension name=\"" . xml::sanitize($fax_name) . "\" continue=\"false\" uuid=\"" . xml::sanitize($this->dialplan_uuid) . "\">\n";
|
||||
$dialplan_xml .= " <condition field=\"destination_number\" expression=\"^" . xml::sanitize($this->destination_number) . "$\">\n";
|
||||
$dialplan_xml .= " <action application=\"answer\" data=\"\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"fax_uuid=".xml::sanitize($this->fax_uuid)."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"fax_uuid=" . xml::sanitize($this->fax_uuid) . "\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"api_hangup_hook=lua app/fax/resources/scripts/hangup_rx.lua\"/>\n";
|
||||
foreach($_SESSION['fax']['variable'] as $data) {
|
||||
if (substr($data,0,8) == "inbound:") {
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"".xml::sanitize(substr($data,8,strlen($data)))."\"/>\n";
|
||||
}
|
||||
elseif (substr($data,0,9) == "outbound:") {}
|
||||
else {
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"".xml::sanitize($data)."\"/>\n";
|
||||
foreach ($_SESSION['fax']['variable'] as $data) {
|
||||
if (substr($data, 0, 8) == "inbound:") {
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"" . xml::sanitize(substr($data, 8, strlen($data))) . "\"/>\n";
|
||||
} elseif (substr($data, 0, 9) == "outbound:") {
|
||||
} else {
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"" . xml::sanitize($data) . "\"/>\n";
|
||||
}
|
||||
}
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"".$last_fax."\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"set\" data=\"" . $last_fax . "\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"rxfax\" data=\"$rxfax_data\"/>\n";
|
||||
$dialplan_xml .= " <action application=\"hangup\" data=\"\"/>\n";
|
||||
$dialplan_xml .= " </condition>\n";
|
||||
@@ -230,7 +244,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//return the dialplan_uuid
|
||||
return $dialplan_response ?? null;
|
||||
@@ -238,7 +252,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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) {
|
||||
|
||||
@@ -248,7 +268,7 @@
|
||||
$this->table = 'fax';
|
||||
$this->uuid_prefix = 'fax_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -257,8 +277,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -268,15 +288,15 @@
|
||||
//filter out unchecked fax extensions, build where clause for below
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary fax details
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, dialplan_uuid from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -291,13 +311,17 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select fax_file_uuid as uuid, fax_mode, fax_file_path, fax_file_type from v_fax_files ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
if ($row['fax_mode'] == 'rx') { $fax_files[$row['uuid']]['folder'] = 'inbox'; }
|
||||
if ($row['fax_mode'] == 'tx') { $fax_files[$row['uuid']]['folder'] = 'sent'; }
|
||||
if ($row['fax_mode'] == 'rx') {
|
||||
$fax_files[$row['uuid']]['folder'] = 'inbox';
|
||||
}
|
||||
if ($row['fax_mode'] == 'tx') {
|
||||
$fax_files[$row['uuid']]['folder'] = 'sent';
|
||||
}
|
||||
$fax_files[$row['uuid']]['path'] = $row['fax_file_path'];
|
||||
$fax_files[$row['uuid']]['type'] = $row['fax_file_type'];
|
||||
}
|
||||
@@ -309,7 +333,7 @@
|
||||
if (!empty($fax_files) && is_array($fax_files) && @sizeof($fax_files) != 0) {
|
||||
foreach ($fax_files as $fax_file_uuid => $fax_file) {
|
||||
if (substr_count($fax_file['path'], '/temp/') > 0) {
|
||||
$fax_file['path'] = str_replace('/temp/', '/'.$fax_file['type'].'/', $fax_file['path']);
|
||||
$fax_file['path'] = str_replace('/temp/', '/' . $fax_file['type'] . '/', $fax_file['path']);
|
||||
}
|
||||
if (file_exists($fax_file['path'])) {
|
||||
@unlink($fax_file['path']);
|
||||
@@ -319,8 +343,7 @@
|
||||
if (file_exists($fax_file['path'])) {
|
||||
@unlink($fax_file['path']);
|
||||
}
|
||||
}
|
||||
else if ($fax_file['type'] == 'pdf') {
|
||||
} elseif ($fax_file['type'] == 'pdf') {
|
||||
$fax_file['path'] = str_replace('.pdf', '.tif', $fax_file['path']);
|
||||
if (file_exists($fax_file['path'])) {
|
||||
@unlink($fax_file['path']);
|
||||
@@ -333,13 +356,13 @@
|
||||
$x = 0;
|
||||
if (!empty($faxes) && is_array($faxes) && @sizeof($faxes) != 0) {
|
||||
foreach ($faxes as $fax_uuid => $fax) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $fax_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $fax_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['fax_users'][$x][$this->uuid_prefix.'uuid'] = $fax_uuid;
|
||||
$array['fax_users'][$x][$this->uuid_prefix . 'uuid'] = $fax_uuid;
|
||||
$array['fax_users'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['fax_files'][$x][$this->uuid_prefix.'uuid'] = $fax_uuid;
|
||||
$array['fax_files'][$x][$this->uuid_prefix . 'uuid'] = $fax_uuid;
|
||||
$array['fax_files'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['fax_logs'][$x][$this->uuid_prefix.'uuid'] = $fax_uuid;
|
||||
$array['fax_logs'][$x][$this->uuid_prefix . 'uuid'] = $fax_uuid;
|
||||
$array['fax_logs'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $fax['dialplan_uuid'];
|
||||
$array['dialplans'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -378,7 +401,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//clear the destinations session array
|
||||
if (isset($_SESSION['destinations']['array'])) {
|
||||
@@ -393,15 +416,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple fax files.
|
||||
*
|
||||
* @param array $records An array of records to delete, where each record is an associative array containing the 'checked' and 'uuid' keys.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_files($records) {
|
||||
|
||||
//set private variables
|
||||
$this->permission_prefix = 'fax_file_';
|
||||
$this->list_page = 'fax_files.php?id='.urlencode($this->fax_uuid).'&box='.urlencode($this->box);
|
||||
$this->list_page = 'fax_files.php?id=' . urlencode($this->fax_uuid) . '&box=' . urlencode($this->box);
|
||||
$this->table = 'fax_files';
|
||||
$this->uuid_prefix = 'fax_file_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -410,8 +440,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -421,21 +451,25 @@
|
||||
//filter out unchecked fax files, build where clause for below
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary fax file details
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, fax_mode, fax_file_path, fax_file_type from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, fax_mode, fax_file_path, fax_file_type from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
if ($row['fax_mode'] == 'rx') { $fax_files[$row['uuid']]['folder'] = 'inbox'; }
|
||||
if ($row['fax_mode'] == 'tx') { $fax_files[$row['uuid']]['folder'] = 'sent'; }
|
||||
if ($row['fax_mode'] == 'rx') {
|
||||
$fax_files[$row['uuid']]['folder'] = 'inbox';
|
||||
}
|
||||
if ($row['fax_mode'] == 'tx') {
|
||||
$fax_files[$row['uuid']]['folder'] = 'sent';
|
||||
}
|
||||
$fax_files[$row['uuid']]['path'] = $row['fax_file_path'];
|
||||
$fax_files[$row['uuid']]['type'] = $row['fax_file_type'];
|
||||
}
|
||||
@@ -447,7 +481,7 @@
|
||||
if (is_array($fax_files) && @sizeof($fax_files) != 0) {
|
||||
foreach ($fax_files as $fax_file_uuid => $fax_file) {
|
||||
if (substr_count($fax_file['path'], '/temp/') > 0) {
|
||||
$fax_file['path'] = str_replace('/temp/', '/'.$fax_file['type'].'/', $fax_file['path']);
|
||||
$fax_file['path'] = str_replace('/temp/', '/' . $fax_file['type'] . '/', $fax_file['path']);
|
||||
}
|
||||
if (file_exists($fax_file['path'])) {
|
||||
@unlink($fax_file['path']);
|
||||
@@ -457,8 +491,7 @@
|
||||
if (file_exists($fax_file['path'])) {
|
||||
@unlink($fax_file['path']);
|
||||
}
|
||||
}
|
||||
else if ($fax_file['type'] == 'pdf') {
|
||||
} elseif ($fax_file['type'] == 'pdf') {
|
||||
$fax_file['path'] = str_replace('.pdf', '.tif', $fax_file['path']);
|
||||
if (file_exists($fax_file['path'])) {
|
||||
@unlink($fax_file['path']);
|
||||
@@ -470,7 +503,7 @@
|
||||
//build the delete array
|
||||
$x = 0;
|
||||
foreach ($fax_files as $fax_file_uuid => $fax_file) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $fax_file_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $fax_file_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -490,15 +523,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple fax log records based on user input.
|
||||
*
|
||||
* @param array $records An array of record data, where each record is an associative array containing
|
||||
* information about the log entry to delete. Each array should have a 'checked'
|
||||
* key with a value of either true or false indicating whether the log entry
|
||||
* should be deleted, and a 'uuid' key containing the UUID of the log entry.
|
||||
*
|
||||
* @return void No return value; method only deletes records if permission is granted.
|
||||
*/
|
||||
public function delete_logs($records) {
|
||||
|
||||
//set private variables
|
||||
$this->permission_prefix = 'fax_log_';
|
||||
$this->list_page = 'fax_logs.php?id='.urlencode($this->fax_uuid);
|
||||
$this->list_page = 'fax_logs.php?id=' . urlencode($this->fax_uuid);
|
||||
$this->table = 'fax_logs';
|
||||
$this->uuid_prefix = 'fax_log_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -507,8 +550,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -518,7 +561,7 @@
|
||||
//filter out unchecked fax logs, build the delete array
|
||||
foreach ($records as $x => $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][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
}
|
||||
@@ -539,7 +582,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
|
||||
@@ -549,7 +598,7 @@
|
||||
$this->table = 'fax';
|
||||
$this->uuid_prefix = 'fax_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'copy')) {
|
||||
if (permission_exists($this->permission_prefix . 'copy')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -558,8 +607,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -567,9 +616,9 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,9 +626,9 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -589,7 +638,7 @@
|
||||
$new_dialplan_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -600,12 +649,12 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_fax_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $new_fax_uuid;
|
||||
$array[$this->table][$x]['dialplan_uuid'] = $new_dialplan_uuid;
|
||||
if ($row['fax_forward_number'] == '') {
|
||||
unset($array[$this->table][$x]['fax_forward_number']);
|
||||
}
|
||||
$array[$this->table][$x]['fax_description'] = trim($row['fax_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x]['fax_description'] = trim($row['fax_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//fax users sub table
|
||||
$sql_2 = "select e.* from v_fax_users as e, v_users as u ";
|
||||
@@ -619,7 +668,7 @@
|
||||
foreach ($rows_2 as $row_2) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -647,7 +696,7 @@
|
||||
if (is_array($dialplan) && @sizeof($dialplan) != 0) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($dialplan as $key => $value) {
|
||||
foreach ($dialplan as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$dialplan[$key] = $value;
|
||||
@@ -663,7 +712,7 @@
|
||||
$dialplan_xml = str_replace($row['fax_uuid'], $new_fax_uuid, $dialplan_xml); //replace source fax_uuid with new
|
||||
$dialplan_xml = str_replace($dialplan['dialplan_uuid'], $new_dialplan_uuid, $dialplan_xml); //replace source dialplan_uuid with new
|
||||
$array['dialplans'][$x]['dialplan_xml'] = $dialplan_xml;
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'].' ('.$text['label-copy'].')');
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
unset($sql_3, $parameters_3, $dialplan);
|
||||
@@ -695,7 +744,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//set message
|
||||
message::add($text['message-copy']);
|
||||
@@ -708,7 +757,13 @@
|
||||
} //method
|
||||
|
||||
/**
|
||||
* toggle read/unread
|
||||
* Toggles the read state of multiple fax file records based on user input.
|
||||
*
|
||||
* @param array $records An array of record data, where each record is an associative array containing information about the log entry to toggle.
|
||||
* Each array should have a 'checked' key with a value of either true or false indicating whether the log entry
|
||||
* should be toggled, and a 'uuid' key containing the UUID of the log entry.
|
||||
*
|
||||
* @return int The number of fax files toggled (0 if none were toggled).
|
||||
*/
|
||||
public function fax_file_toggle($records) {
|
||||
|
||||
@@ -722,8 +777,8 @@
|
||||
if (empty($this->download) || $this->download == false) {
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: fax_files.php?order_by='.urlencode($this->order_by).'&order='.urlencode($this->order).'&id='.urlencode($this->fax_uuid).'&box='.urlencode($this->box));
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: fax_files.php?order_by=' . urlencode($this->order_by) . '&order=' . urlencode($this->order) . '&id=' . urlencode($this->fax_uuid) . '&box=' . urlencode($this->box));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -771,7 +826,7 @@
|
||||
|
||||
}
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
/*
|
||||
$o = new fax;
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Recursively converts an object or array to a multi-dimensional array.
|
||||
*
|
||||
* @param mixed $obj The object or array to be converted. If the value is neither an object nor an array, it will be returned as is.
|
||||
*
|
||||
* @return array A multi-dimensional array representation of the input object or array.
|
||||
*/
|
||||
function object_to_array($obj) {
|
||||
if (!is_object($obj) && !is_array($obj)) { return $obj; }
|
||||
if (is_object($obj)) { $obj = get_object_vars($obj); }
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Parse attachments from a given email message.
|
||||
*
|
||||
* @param imap connection object $connection The IMAP connection to use for fetching the email message.
|
||||
* @param int $message_number The number of the email message to parse attachments from.
|
||||
* @param string $option Optional flag to pass to the imap_fetchstructure function.
|
||||
*
|
||||
* @return array An array of attachment details, where each element is an associative array containing
|
||||
* 'filename', 'name', and 'attachment' keys. The return value will be a reindexed array,
|
||||
* with keys starting from 0.
|
||||
*/
|
||||
function parse_attachments($connection, $message_number, $option = '') {
|
||||
$attachments = array();
|
||||
$structure = imap_fetchstructure($connection, $message_number, $option);
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Parse a message from the email connection.
|
||||
*
|
||||
* @param resource $connection IMAP connection to the mailbox
|
||||
* @param int $message_number The message number of the message to parse
|
||||
* @param string|null $option Optional argument for imap_fetchstructure()
|
||||
* @param string $to_charset Charset to decode messages into, default is 'UTF-8'
|
||||
*
|
||||
* @return array An array containing two keys: 'messages' and 'attachments'. Each key contains an array of parsed messages or attachments.
|
||||
*/
|
||||
function parse_message($connection, $message_number, $option = null, $to_charset = 'UTF-8') {
|
||||
$result = Array('messages'=>Array(),'attachments'=>Array());
|
||||
$structure = imap_fetchstructure($connection, $message_number, $option);
|
||||
@@ -33,6 +43,18 @@ function parse_message($connection, $message_number, $option = null, $to_charset
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the text part of a message from the email connection.
|
||||
*
|
||||
* @param resource $connection IMAP connection to the mailbox
|
||||
* @param array &$part The text part of the message, retrieved using imap_fetchstructure()
|
||||
* @param int $message_number The message number of the message to parse
|
||||
* @param int $id Unique identifier for this part of the message
|
||||
* @param string|null $option Optional argument for imap_fetchbody()
|
||||
* @param string $to_charset Charset to decode messages into, default is 'UTF-8'
|
||||
*
|
||||
* @return array An array containing three keys: 'data', 'type', and 'size'. The 'data' key contains the decoded message text.
|
||||
*/
|
||||
function parse_message_decode_text($connection, &$part, $message_number, $id, $option, $to_charset){
|
||||
$msg = parse_message_fetch_body($connection, $part, $message_number, $id, $option);
|
||||
|
||||
@@ -63,6 +85,17 @@ function parse_message_decode_text($connection, &$part, $message_number, $id, $o
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an attachment from the email connection.
|
||||
*
|
||||
* @param resource $connection IMAP connection to the mailbox
|
||||
* @param object &$part The email part to parse
|
||||
* @param int $message_number The message number of the message containing the attachment
|
||||
* @param string $id The internal ID of the attachment in the message
|
||||
* @param string|null $option Optional argument for imap_fetchbody()
|
||||
*
|
||||
* @return array|false An array containing information about the parsed attachment, or false if no valid filename is found.
|
||||
*/
|
||||
function parse_message_decode_attach($connection, &$part, $message_number, $id, $option){
|
||||
$filename = false;
|
||||
|
||||
@@ -99,6 +132,17 @@ function parse_message_decode_attach($connection, &$part, $message_number, $id,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves and decodes the body of a message from an email server.
|
||||
*
|
||||
* @param resource $connection IMAP connection to the email server
|
||||
* @param object & $part Part of the email being processed
|
||||
* @param int $message_number The number of the message to retrieve
|
||||
* @param string $id Unique identifier for the part
|
||||
* @param int $option Option flag (default value is not documented)
|
||||
*
|
||||
* @return string The decoded body of the message
|
||||
*/
|
||||
function parse_message_fetch_body($connection, &$part, $message_number, $id, $option){
|
||||
$body = imap_fetchbody($connection, $message_number, $id, $option);
|
||||
if($part->encoding == ENCBASE64){
|
||||
@@ -110,6 +154,13 @@ function parse_message_fetch_body($connection, &$part, $message_number, $id, $op
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type and subtype of a message part.
|
||||
*
|
||||
* @param object $part Message part object containing type and subtype information.
|
||||
*
|
||||
* @return string Type and subtype of the message part, separated by a slash. (e.g., "message/plain")
|
||||
*/
|
||||
function parse_message_get_type(&$part){
|
||||
$types = Array(
|
||||
TYPEMESSAGE => 'message',
|
||||
@@ -126,6 +177,17 @@ function parse_message_get_type(&$part){
|
||||
return $types[$part->type] . '/' . strtolower($part->subtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively flattens a hierarchical message structure into a single-level array.
|
||||
*
|
||||
* @param object $structure Message structure containing nested parts and subparts.
|
||||
* @param array &$result Resulting flattened array of message parts.
|
||||
* @param string $prefix Prefix for each part in the result array (optional).
|
||||
* @param int $index Index of the current part (used for generating prefixes, optional).
|
||||
* @param bool $fullPrefix Whether to include the index in the prefix or not (optional).
|
||||
*
|
||||
* @return array Flattened message structure.
|
||||
*/
|
||||
function parse_message_flatten(&$structure, &$result = array(), $prefix = '', $index = 1, $fullPrefix = true) {
|
||||
foreach ($structure as $part) {
|
||||
if(isset($part->parts)) {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/**
|
||||
* fax_queue class
|
||||
*/
|
||||
class fax_queue {
|
||||
class fax_queue {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -37,12 +37,15 @@
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
*
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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;
|
||||
@@ -57,7 +60,12 @@
|
||||
private $location;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -70,15 +78,21 @@
|
||||
$this->name = 'fax_queue';
|
||||
$this->table = 'fax_queue';
|
||||
$this->toggle_field = '';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->location = 'fax_queue.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -87,8 +101,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -122,10 +136,14 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* resend selected faxes in the fax queue
|
||||
* Resend multiple faxes.
|
||||
*
|
||||
* @param array $records Array of records to resend, where each record contains a 'checked' and 'fax_queue_uuid' key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resend($records) {
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -134,8 +152,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -146,7 +164,7 @@
|
||||
foreach ($records as $record) {
|
||||
//add to the array
|
||||
if ($record['checked'] == 'true' && is_uuid($record['fax_queue_uuid'])) {
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $record['fax_queue_uuid'];
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $record['fax_queue_uuid'];
|
||||
$array[$this->table][$x]['fax_status'] = 'waiting';
|
||||
$array[$this->table][$x]['fax_retry_date'] = null;
|
||||
$array[$this->table][$x]['fax_notify_date'] = null;
|
||||
@@ -174,10 +192,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle a field between two values
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -186,22 +210,22 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
//toggle the checked records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
//get current toggle state
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['fax_queue_uuid'])) {
|
||||
$uuids[] = "'".$record['fax_queue_uuid']."'";
|
||||
$uuids[] = "'" . $record['fax_queue_uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
@@ -215,9 +239,9 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -240,10 +264,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy rows from the database
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->name.'_add')) {
|
||||
if (permission_exists($this->name . '_add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -252,8 +282,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -261,16 +291,16 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['fax_queue_uuid'])) {
|
||||
$uuids[] = "'".$record['fax_queue_uuid']."'";
|
||||
$uuids[] = "'" . $record['fax_queue_uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create the array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where fax_queue_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where fax_queue_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
@@ -278,7 +308,7 @@
|
||||
$x = 0;
|
||||
foreach ($rows as $row) {
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -289,7 +319,7 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//add copy to the description
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = uuid();
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = uuid();
|
||||
|
||||
//increment the id
|
||||
$x++;
|
||||
@@ -315,14 +345,16 @@
|
||||
|
||||
/**
|
||||
* Removes records from the v_fax_files and v_fax_logs tables. Called by the maintenance application.
|
||||
*
|
||||
* @param settings $settings Settings object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function database_maintenance(settings $settings): void {
|
||||
$database = $settings->database();
|
||||
$domains = maintenance_service::get_domains($database);
|
||||
foreach ($domains as $domain_uuid => $domain_name) {
|
||||
$domain_settings = new settings(['database'=>$database, 'domain_uuid'=>$domain_uuid]);
|
||||
$domain_settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]);
|
||||
$retention_days = $domain_settings->get('fax_queue', 'database_retention_days', '');
|
||||
//delete from v_fax_queue where fax_status = 'sent' and fax_date < NOW() - INTERVAL '$days_keep_fax_queue days'
|
||||
if (!empty($retention_days) && is_numeric($retention_days)) {
|
||||
@@ -339,4 +371,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,13 @@
|
||||
//echo "pid_file: ".$pid_file."\n";
|
||||
|
||||
//function to check if the process exists
|
||||
/**
|
||||
* Checks if a process is running.
|
||||
*
|
||||
* @param string $file The path to the file containing the process ID, or false for no check.
|
||||
*
|
||||
* @return bool True if the process is running, false otherwise.
|
||||
*/
|
||||
function process_exists($file = false) {
|
||||
|
||||
//set the default exists to false
|
||||
|
||||
@@ -40,7 +40,17 @@
|
||||
|
||||
//extract dtmf from the fax number
|
||||
if (!function_exists('fax_split_dtmf')) {
|
||||
function fax_split_dtmf(&$fax_number, &$fax_dtmf){
|
||||
/**
|
||||
* Splits the fax number and DTMF tone string.
|
||||
*
|
||||
* This function takes a fax number with an optional DTMF tone string as input,
|
||||
* extracts the fax number and the DTMF tone string, and stores them separately in
|
||||
* the provided references.
|
||||
*
|
||||
* @param string &$fax_number The fax number to split. May contain an embedded DTMF tone string.
|
||||
* @param string &$fax_dtmf The extracted DTMF tone string.
|
||||
*/
|
||||
function fax_split_dtmf(&$fax_number, &$fax_dtmf) {
|
||||
$tmp = array();
|
||||
$fax_dtmf = '';
|
||||
if (preg_match('/^\s*(.*?)\s*\((.*)\)\s*$/', $fax_number, $tmp)){
|
||||
@@ -62,6 +72,16 @@
|
||||
}
|
||||
|
||||
//shutdown call back function
|
||||
/**
|
||||
* Performs a clean shutdown of the system.
|
||||
*
|
||||
* This function prepares for graceful termination by updating the fax queue status
|
||||
* and removing the pid file. It is intended to be called when the application needs
|
||||
* to shut down cleanly.
|
||||
*
|
||||
* @return void
|
||||
* @see \register_shutdown_function()
|
||||
*/
|
||||
function shutdown() {
|
||||
//add global variables
|
||||
global $database, $fax_queue_uuid;
|
||||
@@ -89,6 +109,16 @@
|
||||
//echo "pid_file: ".$pid_file."\n";
|
||||
|
||||
//function to check if the process exists
|
||||
/**
|
||||
* Checks if a process exists.
|
||||
*
|
||||
* This function checks the existence of a file containing a valid process ID,
|
||||
* then verifies that the corresponding process is running using the `ps` command.
|
||||
*
|
||||
* @param string $file The path to the file containing the process ID. Defaults to an empty string, which means the function will return false.
|
||||
*
|
||||
* @return bool True if the process exists and is running, false otherwise.
|
||||
*/
|
||||
function process_exists($file = '') {
|
||||
//check if the file exists return false if not found
|
||||
if (!file_exists($file)) {
|
||||
@@ -112,6 +142,15 @@
|
||||
}
|
||||
|
||||
//remove single quote
|
||||
/**
|
||||
* Escapes single quotes in a string.
|
||||
*
|
||||
* This function removes all occurrences of single quotes from the input value.
|
||||
*
|
||||
* @param string $value The value to remove single quotes from. May be empty.
|
||||
*
|
||||
* @return boolean|string True if the value was not empty, otherwise false.
|
||||
*/
|
||||
function escape_quote($value) {
|
||||
if (!empty($value)) {
|
||||
return str_replace("'", "", $value);
|
||||
|
||||
@@ -37,6 +37,16 @@
|
||||
//echo "pid_file: ".$pid_file."\n";
|
||||
|
||||
//function to check if the process exists
|
||||
/**
|
||||
* Checks if a process exists.
|
||||
*
|
||||
* This function checks if a process with the specified PID file exists, and returns true if it does,
|
||||
* or false otherwise. If no PID file is provided, the function defaults to returning false.
|
||||
*
|
||||
* @param string|false $file The path to the PID file of the process to check for, or false to default to not checking any process.
|
||||
*
|
||||
* @return bool True if a process with the specified PID exists, false otherwise.
|
||||
*/
|
||||
function process_exists($file = false) {
|
||||
|
||||
//set the default exists to false
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* fifo class
|
||||
*/
|
||||
class fifo {
|
||||
class fifo {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -13,12 +13,15 @@
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
*
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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;
|
||||
@@ -35,7 +38,12 @@
|
||||
private $uuid_prefix;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -49,26 +57,22 @@
|
||||
$this->table = 'fifo';
|
||||
$this->uuid_prefix = 'fifo_';
|
||||
$this->toggle_field = 'fifo_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->description_field = 'fifo_description';
|
||||
$this->location = 'fifo.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -77,8 +81,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -89,15 +93,15 @@
|
||||
$uuids = [];
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary fifo queue details
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, dialplan_uuid from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -112,7 +116,7 @@
|
||||
$x = 0;
|
||||
foreach ($fifos as $fifo_uuid => $fifo) {
|
||||
//add to the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $fifo_uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $fifo_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['fifo_members'][$x]['fifo_uuid'] = $fifo_uuid;
|
||||
$array['fifo_members'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
@@ -147,10 +151,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle a field between two values
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -159,8 +169,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -169,12 +179,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
@@ -190,7 +200,7 @@
|
||||
$x = 0;
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -213,10 +223,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy rows from the database
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->name.'_add')) {
|
||||
if (permission_exists($this->name . '_add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -225,8 +241,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -234,16 +250,16 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create the array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
@@ -255,8 +271,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//add copy to the description
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = uuid();
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field]).' ('.$text['label-copy'].')';
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = uuid();
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field]) . ' (' . $text['label-copy'] . ')';
|
||||
|
||||
//increment the id
|
||||
$x++;
|
||||
@@ -288,4 +304,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,18 @@
|
||||
|
||||
//gateway status function
|
||||
if (!function_exists('switch_gateway_status')) {
|
||||
/**
|
||||
* Switches the status of a gateway.
|
||||
*
|
||||
* This function sends an API request to retrieve the status of a gateway.
|
||||
* If the first request fails, it attempts to send the same request with the
|
||||
* gateway UUID in uppercase.
|
||||
*
|
||||
* @param string $gateway_uuid The unique identifier of the gateway.
|
||||
* @param string $result_type The type of response expected (default: 'xml').
|
||||
*
|
||||
* @return string The status of the gateway, or an error message if the request fails.
|
||||
*/
|
||||
function switch_gateway_status($gateway_uuid, $result_type = 'xml') {
|
||||
global $esl;
|
||||
if ($esl->is_connected()) {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the gateways class
|
||||
class gateways {
|
||||
class gateways {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,24 +35,30 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -68,7 +74,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -85,14 +96,22 @@
|
||||
$this->table = 'gateways';
|
||||
$this->uuid_prefix = 'gateway_';
|
||||
$this->toggle_field = 'enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* start gateways
|
||||
* Starts the checked gateways.
|
||||
*
|
||||
* This method checks for permission to edit and validates the token. It then
|
||||
* filters out unchecked gateways and retrieves their details from the database.
|
||||
* If necessary, it creates an event socket connection and starts the gateways.
|
||||
*
|
||||
* @param array $records A list of gateway records.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function start($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -101,8 +120,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -110,21 +129,20 @@
|
||||
if (!empty($records) && is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//filter out unchecked gateways, build where clause for below
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary gateway details
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, gateway, profile, enabled from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, gateway, profile, enabled from v_" . $this->table . " ";
|
||||
if (permission_exists('gateway_all')) {
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
}
|
||||
else {
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
} else {
|
||||
$sql .= "where (domain_uuid = :domain_uuid) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
@@ -148,7 +166,7 @@
|
||||
//start gateways
|
||||
foreach ($gateways as $gateway_uuid => $gateway) {
|
||||
if ($gateway['enabled'] == 'true') {
|
||||
$cmd = 'sofia profile '.$gateway['profile'].' startgw '.$gateway_uuid;
|
||||
$cmd = 'sofia profile ' . $gateway['profile'] . ' startgw ' . $gateway_uuid;
|
||||
$responses[$gateway_uuid]['gateway'] = $gateway['name'];
|
||||
$responses[$gateway_uuid]['message'] = trim(event_socket::api($cmd));
|
||||
}
|
||||
@@ -164,7 +182,7 @@
|
||||
if (!empty($responses) && is_array($responses) && @sizeof($responses) != 0) {
|
||||
$message = $text['message-gateway_started'];
|
||||
foreach ($responses as $response) {
|
||||
$message .= "<br><strong>".$response['gateway']."</strong>: ".$response['message'];
|
||||
$message .= "<br><strong>" . $response['gateway'] . "</strong>: " . $response['message'];
|
||||
}
|
||||
message::add($message, 'positive', 7000);
|
||||
}
|
||||
@@ -176,10 +194,18 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* stop gateways
|
||||
* Stops the checked gateways.
|
||||
*
|
||||
* This method checks for permission to edit and validates the token. It then
|
||||
* filters out unchecked gateways and retrieves their details from the database.
|
||||
* If necessary, it creates an event socket connection and stops the gateways.
|
||||
*
|
||||
* @param array $records A list of gateway records.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function stop($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -188,8 +214,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -197,21 +223,20 @@
|
||||
if (!empty($records) && is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//filter out unchecked gateways, build where clause for below
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary gateway details
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, gateway, profile, enabled from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, gateway, profile, enabled from v_" . $this->table . " ";
|
||||
if (permission_exists('gateway_all')) {
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
}
|
||||
else {
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
} else {
|
||||
$sql .= "where (domain_uuid = :domain_uuid) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
@@ -232,7 +257,7 @@
|
||||
//stop gateways
|
||||
foreach ($gateways as $gateway_uuid => $gateway) {
|
||||
if ($gateway['enabled'] == 'true') {
|
||||
$cmd = 'sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid;
|
||||
$cmd = 'sofia profile ' . $gateway['profile'] . ' killgw ' . $gateway_uuid;
|
||||
$responses[$gateway_uuid]['gateway'] = $gateway['name'];
|
||||
$responses[$gateway_uuid]['message'] = trim(event_socket::api($cmd));
|
||||
}
|
||||
@@ -241,7 +266,7 @@
|
||||
if (!empty($responses) && is_array($responses) && @sizeof($responses) != 0) {
|
||||
$message = $text['message-gateway_stopped'];
|
||||
foreach ($responses as $response) {
|
||||
$message .= "<br><strong>".$response['gateway']."</strong>: ".$response['message'];
|
||||
$message .= "<br><strong>" . $response['gateway'] . "</strong>: " . $response['message'];
|
||||
}
|
||||
message::add($message, 'positive', 7000);
|
||||
}
|
||||
@@ -253,10 +278,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -265,8 +296,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -276,19 +307,18 @@
|
||||
//filter out unchecked gateways, build where clause for below
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary gateway details
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, gateway, profile from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, gateway, profile from v_" . $this->table . " ";
|
||||
if (permission_exists('gateway_all')) {
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
}
|
||||
else {
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
} else {
|
||||
$sql .= "where (domain_uuid = :domain_uuid) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
@@ -313,7 +343,7 @@
|
||||
|
||||
//remove the xml file (if any)
|
||||
if (!empty($this->settings->get('switch', 'sip_profiles'))) {
|
||||
$gateway_xml_file = $this->settings->get('switch', 'sip_profiles')."/".$gateway['profile']."/v_".$gateway_uuid.".xml";
|
||||
$gateway_xml_file = $this->settings->get('switch', 'sip_profiles') . "/" . $gateway['profile'] . "/v_" . $gateway_uuid . ".xml";
|
||||
if (file_exists($gateway_xml_file)) {
|
||||
unlink($gateway_xml_file);
|
||||
}
|
||||
@@ -321,13 +351,13 @@
|
||||
|
||||
//send the api command to stop the gateway
|
||||
if ($esl->is_connected()) {
|
||||
$cmd = 'sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid;
|
||||
$cmd = 'sofia profile ' . $gateway['profile'] . ' killgw ' . $gateway_uuid;
|
||||
$response = event_socket::api($cmd);
|
||||
unset($cmd);
|
||||
}
|
||||
|
||||
//build delete array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $gateway_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $gateway_uuid;
|
||||
$x++;
|
||||
|
||||
}
|
||||
@@ -345,7 +375,7 @@
|
||||
//clear the cache
|
||||
|
||||
$cache = new cache;
|
||||
$cache->delete(gethostname().":configuration:sofia.conf");
|
||||
$cache->delete(gethostname() . ":configuration:sofia.conf");
|
||||
|
||||
//rescan the sip profile to look for new or stopped gateways
|
||||
$esl = event_socket::create();
|
||||
@@ -375,10 +405,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -387,8 +423,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -396,19 +432,18 @@
|
||||
if (!empty($records) && is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as state, gateway, profile from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as state, gateway, profile from v_" . $this->table . " ";
|
||||
if (permission_exists('gateway_all')) {
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
}
|
||||
else {
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
} else {
|
||||
$sql .= "where (domain_uuid = :domain_uuid) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
@@ -424,8 +459,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($gateways as $uuid => $gateway) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($gateways as $uuid => $gateway) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $gateway['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -442,13 +477,12 @@
|
||||
foreach ($gateways as $gateway_uuid => $gateway) {
|
||||
if ($gateway['state'] == 'true') {
|
||||
$_SESSION['gateways'][$gateway_uuid] = $gateway['name'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
unset($_SESSION['gateways'][$gateway_uuid]);
|
||||
|
||||
//remove the xml file (if any)
|
||||
if (!empty($this->settings->get('switch', 'sip_profiles'))) {
|
||||
$gateway_xml_file = $this->settings->get('switch', 'sip_profiles')."/".$gateway['profile']."/v_".$gateway_uuid.".xml";
|
||||
$gateway_xml_file = $this->settings->get('switch', 'sip_profiles') . "/" . $gateway['profile'] . "/v_" . $gateway_uuid . ".xml";
|
||||
if (file_exists($gateway_xml_file)) {
|
||||
unlink($gateway_xml_file);
|
||||
}
|
||||
@@ -461,7 +495,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete(gethostname().":configuration:sofia.conf");
|
||||
$cache->delete(gethostname() . ":configuration:sofia.conf");
|
||||
|
||||
//create the event socket connection
|
||||
$esl = event_socket::create();
|
||||
@@ -494,10 +528,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -506,8 +546,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -517,19 +557,18 @@
|
||||
//get checked records
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create insert array from existing data
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
if (permission_exists('gateway_all')) {
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
}
|
||||
else {
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
} else {
|
||||
$sql .= "where (domain_uuid = :domain_uuid) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
@@ -538,7 +577,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -549,8 +588,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['description'] = trim($row['description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['description'] = trim($row['description'] . ' (' . $text['label-copy'] . ')');
|
||||
unset($array[$this->table][$x]['channels']);
|
||||
|
||||
//defaults
|
||||
@@ -590,7 +629,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete(gethostname().":configuration:sofia.conf");
|
||||
$cache->delete(gethostname() . ":configuration:sofia.conf");
|
||||
|
||||
//set message
|
||||
message::add($text['message-copy']);
|
||||
@@ -602,4 +641,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the ivr_menu class
|
||||
class ivr_menu {
|
||||
class ivr_menu {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -34,37 +34,45 @@
|
||||
const app_uuid = 'a5788e9b-58bc-bd1b-df59-fff5d51253ab';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
|
||||
/**
|
||||
* declare ivr menu primary uuid key
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ivr_menu_uuid;
|
||||
|
||||
/**
|
||||
* declare order_by variables
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $order_by;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -80,7 +88,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -94,6 +107,11 @@
|
||||
$this->list_page = 'ivr_menus.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds records in the v_ivr_menus table.
|
||||
*
|
||||
* @return array An array of menu items or an empty array if no records are found.
|
||||
*/
|
||||
public function find() {
|
||||
$sql = "select * from v_ivr_menus ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
@@ -109,7 +127,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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) {
|
||||
//assign private variables
|
||||
@@ -118,7 +142,7 @@
|
||||
$this->uuid_prefix = 'ivr_menu_';
|
||||
|
||||
//return if permission does not exist
|
||||
if (!permission_exists($this->permission_prefix.'delete')) {
|
||||
if (!permission_exists($this->permission_prefix . 'delete')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -129,8 +153,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -140,15 +164,15 @@
|
||||
//filter out unchecked ivr menus, build where clause for below
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary ivr menu details
|
||||
if (!empty($uuids)) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid, ivr_menu_context from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, dialplan_uuid, ivr_menu_context from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -163,7 +187,7 @@
|
||||
//build the delete array
|
||||
$x = 0;
|
||||
foreach ($ivr_menus as $ivr_menu_uuid => $ivr_menu) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $ivr_menu_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $ivr_menu_uuid;
|
||||
$array['ivr_menu_options'][$x]['ivr_menu_uuid'] = $ivr_menu_uuid;
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $ivr_menu['dialplan_uuid'];
|
||||
$x++;
|
||||
@@ -190,7 +214,7 @@
|
||||
$ivr_menu_contexts = array_unique($ivr_menu_contexts);
|
||||
$cache = new cache;
|
||||
foreach ($ivr_menu_contexts as $ivr_menu_context) {
|
||||
$cache->delete("dialplan:".$ivr_menu_context);
|
||||
$cache->delete("dialplan:" . $ivr_menu_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +231,13 @@
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one or more ivr menu options.
|
||||
*
|
||||
* @param array $records An associative array containing the uuids and checked status of the records to delete.
|
||||
*
|
||||
* @return bool True if the operation was successful, false otherwise.
|
||||
*/
|
||||
public function delete_options($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'ivr_menu_option_';
|
||||
@@ -214,7 +245,7 @@
|
||||
$this->uuid_prefix = 'ivr_menu_option_';
|
||||
|
||||
//return if permission does not exist
|
||||
if (!permission_exists($this->permission_prefix.'delete')) {
|
||||
if (!permission_exists($this->permission_prefix . 'delete')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -225,8 +256,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -237,7 +268,7 @@
|
||||
$x = 0;
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['ivr_menu_uuid'] = $this->ivr_menu_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -264,7 +295,7 @@
|
||||
//clear the cache
|
||||
if (!empty($ivr_menu_context)) {
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$ivr_menu_context);
|
||||
$cache->delete("dialplan:" . $ivr_menu_context);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -273,7 +304,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
//assign private variables
|
||||
@@ -281,10 +318,10 @@
|
||||
$this->table = 'ivr_menus';
|
||||
$this->uuid_prefix = 'ivr_menu_';
|
||||
$this->toggle_field = 'ivr_menu_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
|
||||
//return if permission does not exist
|
||||
if (!permission_exists($this->permission_prefix.'edit')) {
|
||||
if (!permission_exists($this->permission_prefix . 'edit')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -295,8 +332,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -304,15 +341,15 @@
|
||||
if (!empty($records)) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids)) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, dialplan_uuid from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, dialplan_uuid from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -327,7 +364,7 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($ivr_menus as $uuid => $ivr_menu) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $ivr_menu['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $ivr_menu['dialplan_uuid'];
|
||||
$array['dialplans'][$x]['dialplan_enabled'] = $ivr_menu['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
@@ -350,9 +387,9 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
foreach ($ivr_menus as $ivr_menu_uuid => $ivr_menu) {
|
||||
$cache->delete("configuration:ivr.conf:".$ivr_menu_uuid);
|
||||
$cache->delete("configuration:ivr.conf:" . $ivr_menu_uuid);
|
||||
}
|
||||
|
||||
//clear the destinations session array
|
||||
@@ -369,7 +406,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
//assign private variables
|
||||
@@ -378,7 +421,7 @@
|
||||
$this->uuid_prefix = 'ivr_menu_';
|
||||
|
||||
//return if permission does not exist
|
||||
if (!permission_exists($this->permission_prefix.'add')) {
|
||||
if (!permission_exists($this->permission_prefix . 'add')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -389,8 +432,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -398,9 +441,9 @@
|
||||
if (!empty($records)) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,9 +451,9 @@
|
||||
if (!empty($uuids)) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (!empty($rows)) {
|
||||
@@ -420,7 +463,7 @@
|
||||
$new_dialplan_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -431,9 +474,9 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_ivr_menu_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $new_ivr_menu_uuid;
|
||||
$array[$this->table][$x]['dialplan_uuid'] = $new_dialplan_uuid;
|
||||
$array[$this->table][$x]['ivr_menu_description'] = trim($row['ivr_menu_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x]['ivr_menu_description'] = trim($row['ivr_menu_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//ivr menu options sub table
|
||||
$sql_2 = "select * from v_ivr_menu_options where ivr_menu_uuid = :ivr_menu_uuid";
|
||||
@@ -442,7 +485,7 @@
|
||||
if (!empty($rows_2)) {
|
||||
foreach ($rows_2 as $row_2) {
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -469,7 +512,7 @@
|
||||
$dialplan = $this->database->select($sql_3, $parameters_3, 'row');
|
||||
if (!empty($dialplan)) {
|
||||
//convert boolean values to a string
|
||||
foreach($dialplan as $key => $value) {
|
||||
foreach ($dialplan as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$dialplan[$key] = $value;
|
||||
@@ -485,7 +528,7 @@
|
||||
$dialplan_xml = str_replace($row['ivr_menu_uuid'], $new_ivr_menu_uuid, $dialplan_xml); //replace source ivr_menu_uuid with new
|
||||
$dialplan_xml = str_replace($dialplan['dialplan_uuid'], $new_dialplan_uuid, $dialplan_xml); //replace source dialplan_uuid with new
|
||||
$array['dialplans'][$z]['dialplan_xml'] = $dialplan_xml;
|
||||
$array['dialplans'][$z]['dialplan_description'] = trim($dialplan['dialplan_description'].' ('.$text['label-copy'].')');
|
||||
$array['dialplans'][$z]['dialplan_description'] = trim($dialplan['dialplan_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//increment
|
||||
$z++;
|
||||
@@ -516,7 +559,7 @@
|
||||
|
||||
//clear the cache
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$this->domain_name);
|
||||
$cache->delete("dialplan:" . $this->domain_name);
|
||||
|
||||
//set message
|
||||
message::add($text['message-copy']);
|
||||
@@ -527,4 +570,4 @@
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,16 @@
|
||||
*/
|
||||
|
||||
if (!function_exists('save_ivr_menu_xml')) {
|
||||
/**
|
||||
* Saves IVR menu XML configuration files.
|
||||
*
|
||||
* This function deletes all existing dialplan .xml files in the ivr_menus directory,
|
||||
* then creates new IVR menu XML files based on the database records for the current domain.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function save_ivr_menu_xml() {
|
||||
global $domain_uuid;
|
||||
global $domain_uuid, $settings;
|
||||
|
||||
//prepare for dialplan .xml files to be written. delete all dialplan files that are prefixed with dialplan_ and have a file extension of .xml
|
||||
if (count($_SESSION["domains"]) > 1) {
|
||||
|
||||
@@ -167,6 +167,11 @@
|
||||
|
||||
echo "<div class='card'>\n";
|
||||
echo "<table class='list'>\n";
|
||||
/**
|
||||
* Writes the header for a list of modules.
|
||||
*
|
||||
* @param string $modifier The modifier to use in the checkbox ID and other attributes.
|
||||
*/
|
||||
function write_header($modifier) {
|
||||
global $text, $modules, $list_row_edit_button;
|
||||
$modifier = str_replace('/', '', $modifier);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the modules class
|
||||
class modules {
|
||||
class modules {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -43,24 +43,30 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -77,7 +83,12 @@
|
||||
private $active_modules;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -95,7 +106,7 @@
|
||||
$this->table = 'modules';
|
||||
$this->uuid_prefix = 'module_';
|
||||
$this->toggle_field = 'module_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
|
||||
//get the list of active modules
|
||||
$json = $this->esl->request("api show modules as json");
|
||||
@@ -103,7 +114,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* get the additional information about a specific module
|
||||
* Get additional information about a specific module
|
||||
*
|
||||
* Retrieves and formats information about a module.
|
||||
*
|
||||
* @param string $name The name of the module to retrieve information for.
|
||||
*
|
||||
* @return array An array containing the formatted module information.
|
||||
*/
|
||||
public function info($name) {
|
||||
$module_label = substr($name, 4);
|
||||
@@ -768,6 +785,14 @@
|
||||
}
|
||||
|
||||
//check to see if the module exists in the array
|
||||
|
||||
/**
|
||||
* Check if a module exists in the collection of modules.
|
||||
*
|
||||
* @param string $name The name of the module to check for existence.
|
||||
*
|
||||
* @return bool True if the module exists, false otherwise.
|
||||
*/
|
||||
public function exists($name) {
|
||||
//set the default
|
||||
$result = false;
|
||||
@@ -782,7 +807,13 @@
|
||||
return $result;
|
||||
}
|
||||
|
||||
//check the status of the module
|
||||
/**
|
||||
* Check the status of the module
|
||||
*
|
||||
* @param string $name Module name to check for activity
|
||||
*
|
||||
* @return bool True if the module is active, false otherwise
|
||||
*/
|
||||
public function active($name) {
|
||||
foreach ($this->active_modules['rows'] as $row) {
|
||||
if ($row['ikey'] === $name) {
|
||||
@@ -792,15 +823,28 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
//get the list of modules
|
||||
/**
|
||||
* Sets a list of modules in the object property modules.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function get_modules() {
|
||||
$sql = "select * from v_modules ";
|
||||
$sql .= "order by module_category, module_label";
|
||||
$this->modules = $this->database->select($sql, null, 'all');
|
||||
unset($sql);
|
||||
}
|
||||
|
||||
//add missing modules for more module info see http://wiki.freeswitch.com/wiki/Modules
|
||||
|
||||
/**
|
||||
* Synchronize modules with the database.
|
||||
*
|
||||
* Scans the module directory for new or updated modules and inserts them into
|
||||
* the database. If a module is found, it is added to the database with its label,
|
||||
* name, description, category, order, enabled status, and default enabled status.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function synch() {
|
||||
if (false !== ($handle = opendir($this->dir ?? ''))) {
|
||||
$modules_new = '';
|
||||
@@ -821,7 +865,7 @@
|
||||
//get the module array
|
||||
$mod = $this->info($name);
|
||||
//append the module label
|
||||
$modules_new .= "<li>".$mod['module_label']."</li>\n";
|
||||
$modules_new .= "<li>" . $mod['module_label'] . "</li>\n";
|
||||
//set the order
|
||||
$order = $mod['module_order'];
|
||||
//build insert array
|
||||
@@ -862,6 +906,11 @@
|
||||
}
|
||||
|
||||
//save the modules.conf.xml file
|
||||
|
||||
/**
|
||||
* Composes the XML configuration for modules and saves it to modules.conf.xml file in the switch/autoload_configs
|
||||
* directory configured in the global default settings.
|
||||
*/
|
||||
function xml() {
|
||||
//set the globals
|
||||
global $config, $domain_uuid;
|
||||
@@ -880,10 +929,10 @@
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as $row) {
|
||||
if ($prev_module_cat != $row['module_category']) {
|
||||
$xml .= "\n <!-- ".$row['module_category']." -->\n";
|
||||
$xml .= "\n <!-- " . $row['module_category'] . " -->\n";
|
||||
}
|
||||
if ($row['module_enabled']){
|
||||
$xml .= " <load module=\"".$row['module_name']."\"/>\n";
|
||||
if ($row['module_enabled']) {
|
||||
$xml .= " <load module=\"" . $row['module_name'] . "\"/>\n";
|
||||
}
|
||||
$prev_module_cat = $row['module_category'];
|
||||
}
|
||||
@@ -894,8 +943,8 @@
|
||||
$xml .= " </modules>\n";
|
||||
$xml .= "</configuration>";
|
||||
|
||||
if (!empty($this->settings->get('switch', 'conf')) && is_writable($this->settings->get('switch', 'conf').'/autoload_configs/modules.conf.xml')) {
|
||||
$fout = fopen($this->settings->get('switch', 'conf')."/autoload_configs/modules.conf.xml","w");
|
||||
if (!empty($this->settings->get('switch', 'conf')) && is_writable($this->settings->get('switch', 'conf') . '/autoload_configs/modules.conf.xml')) {
|
||||
$fout = fopen($this->settings->get('switch', 'conf') . "/autoload_configs/modules.conf.xml", "w");
|
||||
fwrite($fout, $xml);
|
||||
unset($xml);
|
||||
fclose($fout);
|
||||
@@ -906,24 +955,35 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* start modules
|
||||
* Initiates the starting process.
|
||||
*
|
||||
* @param mixed[] $records Data required for the starting process
|
||||
*
|
||||
* @see modules::control()
|
||||
*/
|
||||
public function start($records) {
|
||||
$this->control('start', $records);
|
||||
}
|
||||
|
||||
/**
|
||||
* stop modules
|
||||
* Stops a module from the switch.
|
||||
*
|
||||
* @param mixed[] $records Data required for the termination process
|
||||
*
|
||||
* @see modules::control()
|
||||
*/
|
||||
public function stop($records) {
|
||||
$this->control('stop', $records);
|
||||
}
|
||||
|
||||
/**
|
||||
* control (load/unload) modules
|
||||
* Performs the specified control action on the checked modules.
|
||||
*
|
||||
* @param string $action The type of control to be performed ('start' or 'stop')
|
||||
* @param mixed[] $records An array of records containing information about the modules to be controlled
|
||||
*/
|
||||
private function control($action, $records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//set local variables
|
||||
switch ($action) {
|
||||
@@ -946,8 +1006,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -957,14 +1017,14 @@
|
||||
//filter out unchecked modules, build where clause for below
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get module details
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, module_name as module, module_enabled as enabled from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, module_name as module, module_enabled as enabled from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -984,9 +1044,8 @@
|
||||
foreach ($modules as $module_uuid => $module) {
|
||||
if ($module['enabled'] == 'true') {
|
||||
$responses[$module_uuid]['module'] = $module['name'];
|
||||
$responses[$module_uuid]['message'] = trim(event_socket::api($action.' '.$module['name']));
|
||||
}
|
||||
else {
|
||||
$responses[$module_uuid]['message'] = trim(event_socket::api($action . ' ' . $module['name']));
|
||||
} else {
|
||||
$responses[$module_uuid]['module'] = $module['name'];
|
||||
$responses[$module_uuid]['message'] = $text['label-disabled'];
|
||||
}
|
||||
@@ -996,7 +1055,7 @@
|
||||
$message = $text[$response_message];
|
||||
if (is_array($responses) && @sizeof($responses) != 0) {
|
||||
foreach ($responses as $response) {
|
||||
$message .= "<br><strong>".$response['module']."</strong>: ".$response['message'];
|
||||
$message .= "<br><strong>" . $response['module'] . "</strong>: " . $response['message'];
|
||||
}
|
||||
}
|
||||
message::add($message, 'positive', 7000);
|
||||
@@ -1008,10 +1067,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete modules
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1020,8 +1085,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1031,14 +1096,14 @@
|
||||
//filter out unchecked modules, build where clause for below
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get module details
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, module_name as module from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, module_name as module from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -1052,7 +1117,7 @@
|
||||
if (is_array($modules) && @sizeof($modules) != 0) {
|
||||
$x = 0;
|
||||
foreach ($modules as $module_uuid => $module) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $module_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $module_uuid;
|
||||
$x++;
|
||||
}
|
||||
}
|
||||
@@ -1068,7 +1133,7 @@
|
||||
foreach ($modules as $module_uuid => $module) {
|
||||
if ($this->active($module['name'])) {
|
||||
$responses[$module_uuid]['module'] = $module['name'];
|
||||
$responses[$module_uuid]['message'] = trim(event_socket::api('unload '.$module['name']));
|
||||
$responses[$module_uuid]['message'] = trim(event_socket::api('unload ' . $module['name']));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1084,7 +1149,7 @@
|
||||
$message = $text['message-delete'];
|
||||
if (!empty($responses) && is_array($responses) && @sizeof($responses) != 0) {
|
||||
foreach ($responses as $response) {
|
||||
$message .= "<br><strong>".$response['module']."</strong>: ".$response['message'];
|
||||
$message .= "<br><strong>" . $response['module'] . "</strong>: " . $response['message'];
|
||||
}
|
||||
}
|
||||
message::add($message, 'positive', 7000);
|
||||
@@ -1096,10 +1161,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -1108,8 +1179,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1119,12 +1190,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as state, module_name as name from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as state, module_name as name from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -1138,8 +1209,8 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
if (is_array($modules) && @sizeof($modules) != 0) {
|
||||
foreach($modules as $uuid => $module) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($modules as $uuid => $module) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $module['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -1160,7 +1231,7 @@
|
||||
if ($esl->is_connected()) {
|
||||
foreach ($modules as $module_uuid => $module) {
|
||||
if ($this->active($module['name'])) {
|
||||
$cmd = 'unload '.$module['name'];
|
||||
$cmd = 'unload ' . $module['name'];
|
||||
$responses[$module_uuid]['module'] = $module['name'];
|
||||
$responses[$module_uuid]['message'] = trim(event_socket::api($cmd));
|
||||
}
|
||||
@@ -1174,7 +1245,7 @@
|
||||
$message = $text['message-toggle'];
|
||||
if (!empty($responses) && is_array($responses) && @sizeof($responses) != 0) {
|
||||
foreach ($responses as $response) {
|
||||
$message .= "<br><strong>".$response['module']."</strong>: ".$response['message'];
|
||||
$message .= "<br><strong>" . $response['module'] . "</strong>: " . $response['message'];
|
||||
}
|
||||
}
|
||||
message::add($message, 'positive', 7000);
|
||||
@@ -1186,8 +1257,7 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
/*
|
||||
$mod = new modules;
|
||||
|
||||
@@ -612,6 +612,16 @@
|
||||
require_once "resources/footer.php";
|
||||
|
||||
//define the download function (helps safari play audio sources)
|
||||
/**
|
||||
* Downloads a file in chunks as requested by the client.
|
||||
*
|
||||
* This function is used to handle byte-range requests, allowing clients
|
||||
* to request specific parts of the file.
|
||||
*
|
||||
* @param string $file The path to the file being downloaded.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function range_download($file) {
|
||||
$fp = @fopen($file, 'rb');
|
||||
|
||||
@@ -640,7 +650,7 @@
|
||||
$c_start = $start;
|
||||
$c_end = $end;
|
||||
// Extract the range string
|
||||
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
// Make sure the client hasn't sent us a multibyte range
|
||||
if (strpos($range, ',') !== false) {
|
||||
// (?) Shoud this be issued here, or should the first
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
//define the switch_music_on_hold class
|
||||
class switch_music_on_hold {
|
||||
class switch_music_on_hold {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -37,36 +37,46 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $this->settings_array associative array or set in the session global array
|
||||
* User UUID set in the constructor. This can be passed in through the $this->settings_array associative array or
|
||||
* set in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $user_uuid;
|
||||
|
||||
/**
|
||||
* Username set in the constructor. This can be passed in through the $this->settings_array associative array or set in the session global array
|
||||
* Username set in the constructor. This can be passed in through the $this->settings_array associative array or
|
||||
* set in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $this->settings_array associative array or set in the session global array
|
||||
* Domain UUID set in the constructor. This can be passed in through the $this->settings_array associative array or
|
||||
* set in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $domain_uuid;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $this->settings_array associative array or set in the session global array
|
||||
* Domain name set in the constructor. This can be passed in through the $this->settings_array associative array or
|
||||
* set in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $domain_name;
|
||||
@@ -83,7 +93,12 @@
|
||||
private $uuid_prefix;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -101,47 +116,56 @@
|
||||
$this->uuid_prefix = 'music_on_hold_';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a HTML select element.
|
||||
*
|
||||
* @param string $name The name of the select field.
|
||||
* @param string $selected The currently selected value.
|
||||
* @param array $options Additional options to include in the select.
|
||||
*
|
||||
* @return string A HTML select element as a string.
|
||||
*/
|
||||
public function select($name, $selected, $options) {
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//start the select
|
||||
$select = "<select class='formfld' name='".$name."' id='".$name."' style='width: auto;'>\n";
|
||||
$select = "<select class='formfld' name='" . $name . "' id='" . $name . "' style='width: auto;'>\n";
|
||||
|
||||
//music on hold
|
||||
$music_list = $this->get();
|
||||
if (count($music_list) > 0) {
|
||||
$select .= " <option value=''>\n";
|
||||
$select .= " <optgroup label='".$text['label-music_on_hold']."'>\n";
|
||||
$select .= " <optgroup label='" . $text['label-music_on_hold'] . "'>\n";
|
||||
$previous_name = '';
|
||||
foreach($music_list as $row) {
|
||||
foreach ($music_list as $row) {
|
||||
if ($previous_name != $row['music_on_hold_name']) {
|
||||
$name = '';
|
||||
if (!empty($row['domain_uuid'])) {
|
||||
$name = $row['domain_name'].'/';
|
||||
$name = $row['domain_name'] . '/';
|
||||
}
|
||||
$name .= $row['music_on_hold_name'];
|
||||
$select .= " <option value='local_stream://".$name."' ".(($selected == "local_stream://".$name) ? 'selected="selected"' : null).">".$row['music_on_hold_name']."</option>\n";
|
||||
$select .= " <option value='local_stream://" . $name . "' " . (($selected == "local_stream://" . $name) ? 'selected="selected"' : null) . ">" . $row['music_on_hold_name'] . "</option>\n";
|
||||
}
|
||||
$previous_name = $row['music_on_hold_name'];
|
||||
}
|
||||
$select .= " </optgroup>\n";
|
||||
}
|
||||
//recordings
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"].'/app/recordings')) {
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"] . '/app/recordings')) {
|
||||
$recordings_c = new switch_recordings;
|
||||
$recordings = $recordings_c->list_recordings();
|
||||
if (is_array($recordings) && sizeof($recordings) > 0) {
|
||||
$select .= " <optgroup label='".$text['label-recordings']."'>";
|
||||
foreach($recordings as $recording_value => $recording_name){
|
||||
$select .= " <option value='".$recording_value."' ".(($selected == $recording_value) ? 'selected="selected"' : null).">".$recording_name."</option>\n";
|
||||
$select .= " <optgroup label='" . $text['label-recordings'] . "'>";
|
||||
foreach ($recordings as $recording_value => $recording_name) {
|
||||
$select .= " <option value='" . $recording_value . "' " . (($selected == $recording_value) ? 'selected="selected"' : null) . ">" . $recording_name . "</option>\n";
|
||||
}
|
||||
$select .= " </optgroup>\n";
|
||||
}
|
||||
}
|
||||
//streams
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"].'/app/streams')) {
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"] . '/app/streams')) {
|
||||
$sql = "select * from v_streams ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and stream_enabled = 'true' ";
|
||||
@@ -149,17 +173,17 @@
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$streams = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($streams) && @sizeof($streams) != 0) {
|
||||
$select .= " <optgroup label='".$text['label-streams']."'>";
|
||||
foreach($streams as $row){
|
||||
$select .= " <option value='".$row['stream_location']."' ".(($selected == $row['stream_location']) ? 'selected="selected"' : null).">".$row['stream_name']."</option>\n";
|
||||
$select .= " <optgroup label='" . $text['label-streams'] . "'>";
|
||||
foreach ($streams as $row) {
|
||||
$select .= " <option value='" . $row['stream_location'] . "' " . (($selected == $row['stream_location']) ? 'selected="selected"' : null) . ">" . $row['stream_name'] . "</option>\n";
|
||||
}
|
||||
$select .= " </optgroup>\n";
|
||||
}
|
||||
unset($sql, $parameters, $streams, $row);
|
||||
}
|
||||
//add additional options
|
||||
$select .= " <optgroup label='".$text['label-others']."'>";
|
||||
$select .= " <option value='silence' ".($selected == "silence" ? 'selected="selected"' : null).">".$text['label-none']."</option>\n";
|
||||
$select .= " <optgroup label='" . $text['label-others'] . "'>";
|
||||
$select .= " <option value='silence' " . ($selected == "silence" ? 'selected="selected"' : null) . ">" . $text['label-none'] . "</option>\n";
|
||||
if (is_array($options) && sizeof($options) > 0) {
|
||||
$select .= $options;
|
||||
}
|
||||
@@ -169,6 +193,11 @@
|
||||
return $select;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves moh records and builds an array.
|
||||
*
|
||||
* @return array|false An array of moh records.
|
||||
*/
|
||||
public function get() {
|
||||
//get moh records, build array
|
||||
$sql = "select ";
|
||||
@@ -182,6 +211,9 @@
|
||||
return $this->database->select($sql, $parameters, 'all');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the module and establishes a connection to the Event Socket.
|
||||
*/
|
||||
public function reload() {
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -192,7 +224,7 @@
|
||||
|
||||
//if the handle still does not exist show an error message
|
||||
if (!$esl->is_connected()) {
|
||||
$msg = "<div align='center'>".$text['message-event-socket']."<br /></div>";
|
||||
$msg = "<div align='center'>" . $text['message-event-socket'] . "<br /></div>";
|
||||
}
|
||||
|
||||
//send the api command to check if the module exists
|
||||
@@ -203,17 +235,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the music on hold configuration.
|
||||
*
|
||||
* This method retrieves the contents of the template, replaces variables,
|
||||
* and writes the updated XML config file to disk. The XML is then reloaded.
|
||||
*/
|
||||
public function save() {
|
||||
//get the contents of the template
|
||||
if (file_exists('/usr/share/examples/fusionpbx')) {
|
||||
$file_contents = file_get_contents("/usr/share/examples/fusionpbx/resources/templates/conf/autoload_configs/local_stream.conf.xml");
|
||||
}
|
||||
else {
|
||||
$file_contents = file_get_contents($_SERVER["PROJECT_ROOT"]."/app/switch/resources/conf/autoload_configs/local_stream.conf.xml");
|
||||
} else {
|
||||
$file_contents = file_get_contents($_SERVER["PROJECT_ROOT"] . "/app/switch/resources/conf/autoload_configs/local_stream.conf.xml");
|
||||
}
|
||||
//check where the default music is stored
|
||||
$default_moh_prefix = 'music/default';
|
||||
if(file_exists($this->settings->get('switch', 'sounds').'/music/8000')) {
|
||||
if (file_exists($this->settings->get('switch', 'sounds') . '/music/8000')) {
|
||||
$default_moh_prefix = 'music';
|
||||
}
|
||||
//replace the variables
|
||||
@@ -221,7 +258,7 @@
|
||||
$file_contents = preg_replace("/[\t ]*(?:<!--)?{v_moh_categories}(?:-->)?/", $this->xml, $file_contents);
|
||||
|
||||
//write the XML config file
|
||||
$fout = fopen($this->settings->get('switch', 'conf')."/autoload_configs/local_stream.conf.xml","w");
|
||||
$fout = fopen($this->settings->get('switch', 'conf') . "/autoload_configs/local_stream.conf.xml", "w");
|
||||
fwrite($fout, $file_contents);
|
||||
fclose($fout);
|
||||
|
||||
@@ -230,7 +267,10 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* read the music files to add the music on hold into the database
|
||||
* Imports music on hold records.
|
||||
*
|
||||
* Retrieves domain and music on hold data, builds an array of sound files,
|
||||
* and saves the data to the database.
|
||||
*/
|
||||
public function import() {
|
||||
//get the domains
|
||||
@@ -245,14 +285,14 @@
|
||||
unset($sql);
|
||||
|
||||
//build an array of the sound files
|
||||
$music_directory = $this->settings->get('switch', 'sounds').'/music';
|
||||
$music_directory = $this->settings->get('switch', 'sounds') . '/music';
|
||||
if (file_exists($music_directory)) {
|
||||
$files = array_merge(glob($music_directory.'/*/*/*.wav'), glob($music_directory.'/*/*/*/*.wav'));
|
||||
$files = array_merge(glob($music_directory . '/*/*/*.wav'), glob($music_directory . '/*/*/*/*.wav'));
|
||||
}
|
||||
|
||||
//build a new file array
|
||||
foreach($files as $file) {
|
||||
$path = substr($file, strlen($music_directory.'/'));
|
||||
foreach ($files as $file) {
|
||||
$path = substr($file, strlen($music_directory . '/'));
|
||||
$path = str_replace("\\", "/", $path);
|
||||
$path_array = explode("/", $path);
|
||||
$file_array[$path_array[0]][$path_array[1]][$path_array[2]] = dirname($file);
|
||||
@@ -263,12 +303,12 @@
|
||||
|
||||
//prepare the data
|
||||
$i = 0;
|
||||
foreach($file_array as $domain_name => $a1) {
|
||||
foreach($a1 as $category_name => $a2) {
|
||||
foreach($a2 as $sample_rate => $file_path) {
|
||||
foreach ($file_array as $domain_name => $a1) {
|
||||
foreach ($a1 as $category_name => $a2) {
|
||||
foreach ($a2 as $sample_rate => $file_path) {
|
||||
//echo "domain_name ".$domain_name."<br />\n";
|
||||
//echo "category_name ".$category_name."<br />\n";
|
||||
foreach($domains as $field) {
|
||||
foreach ($domains as $field) {
|
||||
if ($field['domain_name'] === $domain_name) {
|
||||
$domain_uuid = $field['domain_uuid'];
|
||||
//echo "domain_uuid ".$domain_uuid."<br />\n";
|
||||
@@ -311,10 +351,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records/files
|
||||
* Deletes one or more records/files.
|
||||
*
|
||||
* @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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -323,8 +369,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -352,8 +398,8 @@
|
||||
|
||||
//get music on hold details
|
||||
$sql = "select * from v_music_on_hold ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid ".(!permission_exists('music_on_hold_domain') ? "": "or domain_uuid is null ").") ";
|
||||
$sql .= "and music_on_hold_uuid in ('".implode("','", array_keys($moh))."') ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid " . (!permission_exists('music_on_hold_domain') ? "" : "or domain_uuid is null ") . ") ";
|
||||
$sql .= "and music_on_hold_uuid in ('" . implode("','", array_keys($moh)) . "') ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -385,7 +431,7 @@
|
||||
if (!empty($row['delete']) && $row['delete'] == true) {
|
||||
|
||||
//build delete array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $music_on_hold_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $music_on_hold_uuid;
|
||||
if (!permission_exists('music_on_hold_domain')) {
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
@@ -436,10 +482,9 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
|
||||
} //class
|
||||
|
||||
//build and save the XML
|
||||
//$moh = new switch_music_on_hold;
|
||||
//$moh->xml();
|
||||
//$moh->save();
|
||||
//$moh = new switch_music_on_hold;
|
||||
//$moh->xml();
|
||||
//$moh->save();
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the number translations class
|
||||
class number_translations {
|
||||
class number_translations {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -52,9 +52,13 @@
|
||||
private $xml;
|
||||
private $display_type;
|
||||
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set objects
|
||||
@@ -66,11 +70,15 @@
|
||||
$this->table = 'number_translations';
|
||||
$this->uuid_prefix = 'number_translation_';
|
||||
$this->toggle_field = 'number_translation_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the number translation already exists
|
||||
* Checks if a given name exists as a number translation.
|
||||
*
|
||||
* @param string $name The name to check for existence.
|
||||
*
|
||||
* @return bool True if the number translation exists, false otherwise.
|
||||
*/
|
||||
public function number_translation_exists($name) {
|
||||
$sql = "select count(*) from v_number_translations ";
|
||||
@@ -80,7 +88,9 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Import the number translation rules from the resources directory
|
||||
* Imports a number translation from either XML or JSON format.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function import() {
|
||||
//get the xml from the number templates
|
||||
@@ -91,12 +101,10 @@
|
||||
$json = json_encode($xml);
|
||||
//convert to an array
|
||||
$number_translation = json_decode($json, true);
|
||||
}
|
||||
else if (!empty($this->json)) {
|
||||
} elseif (!empty($this->json)) {
|
||||
//convert to an array
|
||||
$number_translation = json_decode($this->json, true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Exception("require either json or xml to import");
|
||||
}
|
||||
//check if the number_translation exists
|
||||
@@ -133,10 +141,9 @@
|
||||
unset($array);
|
||||
if (!empty($this->display_type) && $this->display_type == "text") {
|
||||
if ($this->database->message['code'] != '200') {
|
||||
echo "number_translation:".$number_translation['@attributes']['name'].": failed: ".$this->database->message['message']."\n";
|
||||
}
|
||||
else {
|
||||
echo "number_translation:".$number_translation['@attributes']['name'].": added with ".(($order/5)-1)." entries\n";
|
||||
echo "number_translation:" . $number_translation['@attributes']['name'] . ": failed: " . $this->database->message['message'] . "\n";
|
||||
} else {
|
||||
echo "number_translation:" . $number_translation['@attributes']['name'] . ": added with " . (($order / 5) - 1) . " entries\n";
|
||||
}
|
||||
}
|
||||
//revoke temporary permissions
|
||||
@@ -147,10 +154,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -159,8 +172,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -170,8 +183,8 @@
|
||||
//build the delete array
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array['number_translation_details'][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array['number_translation_details'][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +210,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple records from the number_translation_details table.
|
||||
*
|
||||
* @param array $records An array of records to be deleted, where each record is an associative array containing 'checked' and 'uuid' keys.
|
||||
* The 'checked' key should contain a boolean value indicating whether the record should be deleted,
|
||||
* while the 'uuid' key contains the unique identifier of the record.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_details($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -204,7 +226,7 @@
|
||||
$this->table = 'number_translation_details';
|
||||
$this->uuid_prefix = 'number_translation_detail_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -213,8 +235,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -224,7 +246,7 @@
|
||||
//build the delete array
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['number_translation_uuid'] = $this->number_translation_uuid;
|
||||
}
|
||||
}
|
||||
@@ -243,10 +265,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -255,8 +283,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -264,14 +292,14 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -283,8 +311,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -307,10 +335,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -319,8 +353,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -328,9 +362,9 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,8 +372,8 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
$y = 0;
|
||||
@@ -347,7 +381,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -358,8 +392,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['number_translation_description'] = trim($row['number_translation_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['number_translation_description'] = trim($row['number_translation_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//nodes sub table
|
||||
$sql_2 = "select * from v_number_translation_details where number_translation_uuid = :number_translation_uuid";
|
||||
@@ -368,7 +402,7 @@
|
||||
if (is_array($rows_2) && @sizeof($rows_2) != 0) {
|
||||
foreach ($rows_2 as $row_2) {
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -418,7 +452,7 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
/*
|
||||
$obj = new number_translations;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the phrases class
|
||||
class phrases {
|
||||
class phrases {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -40,12 +40,15 @@
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
*
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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;
|
||||
@@ -61,7 +64,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -76,14 +84,20 @@
|
||||
$this->table = 'phrases';
|
||||
$this->uuid_prefix = 'phrase_';
|
||||
$this->toggle_field = 'phrase_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -92,8 +106,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -103,15 +117,15 @@
|
||||
//filter out unchecked phrases, build where clause for below
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get phrase languages
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, phrase_language as lang from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, phrase_language as lang from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -126,9 +140,9 @@
|
||||
if (is_array($phrase_languages) && @sizeof($phrase_languages) != 0) {
|
||||
$x = 0;
|
||||
foreach ($phrase_languages as $phrase_uuid => $phrase_language) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $phrase_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $phrase_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['phrase_details'][$x][$this->uuid_prefix.'uuid'] = $phrase_uuid;
|
||||
$array['phrase_details'][$x][$this->uuid_prefix . 'uuid'] = $phrase_uuid;
|
||||
$array['phrase_details'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -152,7 +166,7 @@
|
||||
$phrase_languages = array_unique($phrase_languages);
|
||||
$cache = new cache;
|
||||
foreach ($phrase_languages as $phrase_language) {
|
||||
$cache->delete("languages:".$phrase_language);
|
||||
$cache->delete("languages:" . $phrase_language);
|
||||
}
|
||||
|
||||
//clear the destinations session array
|
||||
@@ -168,14 +182,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete multiple details records.
|
||||
*
|
||||
* @param array $records An array of record IDs to delete, where each ID is an associative array containing
|
||||
* the 'uuid' and optionally a 'checked' field. The 'checked' field should be set to true if the record
|
||||
* should be deleted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_details($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'phrase_';
|
||||
$this->list_page = 'phrase_edit.php?id='.$this->phrase_uuid;
|
||||
$this->list_page = 'phrase_edit.php?id=' . $this->phrase_uuid;
|
||||
$this->table = 'phrase_details';
|
||||
$this->uuid_prefix = 'phrase_detail_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -184,8 +207,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -195,7 +218,7 @@
|
||||
//filter out unchecked phrases, build the delete array
|
||||
foreach ($records as $x => $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][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['phrase_uuid'] = $this->phrase_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
@@ -229,7 +252,7 @@
|
||||
//clear the cache
|
||||
if ($phrase_language != '') {
|
||||
$cache = new cache;
|
||||
$cache->delete("languages:".$phrase_language);
|
||||
$cache->delete("languages:" . $phrase_language);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -239,10 +262,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -251,8 +280,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -262,13 +291,13 @@
|
||||
//get current toggle state and language
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, phrase_language as lang from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, phrase_language as lang from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -282,8 +311,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -301,7 +330,7 @@
|
||||
$phrase_languages = array_unique($phrase_languages);
|
||||
$cache = new cache;
|
||||
foreach ($phrase_languages as $phrase_language) {
|
||||
$cache->delete("languages:".$phrase_language);
|
||||
$cache->delete("languages:" . $phrase_language);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,10 +349,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -332,8 +367,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -343,7 +378,7 @@
|
||||
//get checked records
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,9 +386,9 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -362,7 +397,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -373,8 +408,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['phrase_description'] = trim($row['phrase_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['phrase_description'] = trim($row['phrase_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//details sub table
|
||||
$sql_2 = "select * from v_phrase_details where phrase_uuid = :phrase_uuid";
|
||||
@@ -384,7 +419,7 @@
|
||||
foreach ($rows_2 as $row_2) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -434,7 +469,7 @@
|
||||
$phrase_languages = array_unique($phrase_languages);
|
||||
$cache = new cache;
|
||||
foreach ($phrase_languages as $phrase_language) {
|
||||
$cache->delete("languages:".$phrase_language);
|
||||
$cache->delete("languages:" . $phrase_language);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,4 +483,4 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -51,6 +51,13 @@
|
||||
$available_columns[] = 'description';
|
||||
|
||||
//define the functions
|
||||
/**
|
||||
* Converts a multi-dimensional PHP array into a CSV string.
|
||||
*
|
||||
* @param array &$array The input data to be converted. It is expected to have at least one row and one column.
|
||||
*
|
||||
* @return string|null The CSV representation of the input data, or null if the input array is empty.
|
||||
*/
|
||||
function array2csv(array &$array) {
|
||||
if (count($array) == 0) {
|
||||
return null;
|
||||
@@ -65,6 +72,13 @@
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends HTTP headers for a file download.
|
||||
*
|
||||
* @param string $filename The name of the file to be downloaded.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function download_send_headers($filename) {
|
||||
// disable caching
|
||||
$now = gmdate("D, d M Y H:i:s");
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the pin numbers class
|
||||
class pin_numbers {
|
||||
class pin_numbers {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,18 +35,22 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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;
|
||||
@@ -62,7 +66,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -77,14 +86,20 @@
|
||||
$this->table = 'pin_numbers';
|
||||
$this->uuid_prefix = 'pin_number_';
|
||||
$this->toggle_field = 'enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -93,8 +108,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -104,7 +119,7 @@
|
||||
//build the delete array
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
}
|
||||
@@ -125,10 +140,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -137,8 +158,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -146,15 +167,15 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -167,8 +188,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -191,10 +212,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -203,8 +230,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -212,24 +239,24 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create insert array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $x => $row) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -240,8 +267,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = uuid();
|
||||
$array[$this->table][$x]['description'] = trim($row['description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = uuid();
|
||||
$array[$this->table][$x]['description'] = trim($row['description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -266,4 +293,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,13 @@
|
||||
}
|
||||
|
||||
//send http error
|
||||
/**
|
||||
* Displays a custom HTTP error page with the specified error code and message.
|
||||
*
|
||||
* @param int $error The HTTP error code (e.g., 400, 401, etc.)
|
||||
*
|
||||
* @return void The script exits after displaying the error page
|
||||
*/
|
||||
function http_error($error) {
|
||||
//$error_int_val = intval($error);
|
||||
$http_errors = [
|
||||
@@ -272,6 +279,13 @@
|
||||
if (!empty($provision["http_auth_username"]) && empty($provision["http_auth_type"])) { $provision["http_auth_type"] = "digest"; }
|
||||
if (!empty($provision["http_auth_username"]) && $provision["http_auth_type"] === "digest" && !empty($provision["http_auth_enabled"]) && $provision["http_auth_enabled"]) {
|
||||
//function to parse the http auth header
|
||||
/**
|
||||
* Parses the specified HTTP Digest authentication text and extracts relevant data.
|
||||
*
|
||||
* @param string $txt The HTTP Digest authentication text to parse
|
||||
*
|
||||
* @return array|false An array of extracted data if successful, or false if data is incomplete
|
||||
*/
|
||||
function http_digest_parse($txt) {
|
||||
//protect against missing data
|
||||
$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
|
||||
@@ -286,6 +300,13 @@
|
||||
}
|
||||
|
||||
//function to request digest authentication
|
||||
/**
|
||||
* Sends an HTTP Digest authentication request with the specified realm.
|
||||
*
|
||||
* @param string $realm The name of the protected resource's realm
|
||||
*
|
||||
* @return void The script exits after sending the authentication request
|
||||
*/
|
||||
function http_digest_request($realm) {
|
||||
header('HTTP/1.1 401 Authorization Required');
|
||||
header('WWW-Authenticate: Digest realm="'.$realm.'", qop="auth", nonce="'.uniqid().'", opaque="'.md5($realm).'"');
|
||||
@@ -447,8 +468,8 @@
|
||||
$file_size = strlen($file_contents);
|
||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
$ranges = $_SERVER['HTTP_RANGE'];
|
||||
list($unit, $range) = explode('=', $ranges, 2);
|
||||
list($start, $end) = explode('-', $range, 2);
|
||||
[$unit, $range] = explode('=', $ranges, 2);
|
||||
[$start, $end] = explode('-', $range, 2);
|
||||
|
||||
$start = empty($start) ? 0 : (int)$start;
|
||||
$end = empty($end) ? $file_size - 1 : min((int)$end, $file_size - 1);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
//define the provision class
|
||||
class provision {
|
||||
class provision {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,13 +35,17 @@
|
||||
const app_uuid = 'abf28ead-92ef-3de6-ebbb-023fbc2b6dd3';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set
|
||||
* in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $domain_name;
|
||||
@@ -56,24 +60,33 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -94,45 +107,37 @@
|
||||
if (empty($this->template_dir)) {
|
||||
if (file_exists('/usr/share/fusionpbx/templates/provision')) {
|
||||
$this->template_dir = '/usr/share/fusionpbx/templates/provision';
|
||||
}
|
||||
elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
|
||||
} elseif (file_exists('/etc/fusionpbx/resources/templates/provision')) {
|
||||
$this->template_dir = '/etc/fusionpbx/resources/templates/provision';
|
||||
}
|
||||
else {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
} else {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (PHP_OS == "FreeBSD") {
|
||||
} elseif (PHP_OS == "FreeBSD") {
|
||||
//if the FreeBSD port is installed use the following paths by default.
|
||||
if (empty($this->template_dir)) {
|
||||
if (file_exists('/usr/local/share/fusionpbx/templates/provision')) {
|
||||
$this->template_dir = '/usr/local/share/fusionpbx/templates/provision';
|
||||
}
|
||||
elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
|
||||
} elseif (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) {
|
||||
$this->template_dir = '/usr/local/etc/fusionpbx/resources/templates/provision';
|
||||
}
|
||||
else {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
} else {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (PHP_OS == "NetBSD") {
|
||||
} elseif (PHP_OS == "NetBSD") {
|
||||
//set the default template_dir
|
||||
if (empty($this->template_dir)) {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
else if (PHP_OS == "OpenBSD") {
|
||||
} elseif (PHP_OS == "OpenBSD") {
|
||||
//set the default template_dir
|
||||
if (empty($this->template_dir)) {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//set the default template_dir
|
||||
if (empty($this->template_dir)) {
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
|
||||
$this->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/resources/templates/provision';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,13 +148,23 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* get the domain uuid
|
||||
* Retrieves the domain UUID associated with the object instance.
|
||||
*
|
||||
* @return string The domain UUID of the current domain.
|
||||
*/
|
||||
public function get_domain_uuid() {
|
||||
return $this->domain_uuid;
|
||||
}
|
||||
|
||||
//define the function which checks to see if the device address exists in devices
|
||||
|
||||
/**
|
||||
* Checks if a device exists in the database.
|
||||
*
|
||||
* @param string $device_address The MAC address of the device to check for existence.
|
||||
*
|
||||
* @return bool True if the device is found in the database, false otherwise.
|
||||
*/
|
||||
private function device_exists($device_address) {
|
||||
//normalize the device address
|
||||
$device_address = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $device_address));
|
||||
@@ -161,14 +176,21 @@
|
||||
$num_rows = $this->database->select($sql, $parameters, 'column');
|
||||
if ($num_rows > 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
unset($sql, $parameters, $num_rows);
|
||||
}
|
||||
|
||||
//set the device address in the correct format for the specific vendor
|
||||
|
||||
/**
|
||||
* Formats the device address according to the vendor.
|
||||
*
|
||||
* @param string $device_address The IP address or hostname of the device.
|
||||
* @param string $vendor The vendor of the device, e.g. "cisco", "linksys", etc.
|
||||
*
|
||||
* @return string The formatted device address.
|
||||
*/
|
||||
public function format_address($device_address, $vendor) {
|
||||
switch (strtolower($vendor)) {
|
||||
case "algo":
|
||||
@@ -199,6 +221,14 @@
|
||||
}
|
||||
|
||||
//send http error
|
||||
|
||||
/**
|
||||
* Handles HTTP errors and displays a 404 Not Found page if the error code is '404'.
|
||||
*
|
||||
* @param string $error The HTTP error code.
|
||||
*
|
||||
* @return void Exits the script with an HTTP status code of 404 if the error code is '404', otherwise continues execution.
|
||||
*/
|
||||
private function http_error($error) {
|
||||
if ($error === "404") {
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
@@ -214,15 +244,34 @@
|
||||
}
|
||||
|
||||
//define a function to check if a contact exists in the contacts array
|
||||
|
||||
/**
|
||||
* Checks if a contact exists in the given array of contacts.
|
||||
*
|
||||
* @param array $contacts The array of contacts to search in.
|
||||
* @param string $uuid The unique identifier (UUID) of the contact to look for.
|
||||
*
|
||||
* @return bool True if the contact exists, false otherwise.
|
||||
*/
|
||||
private function contact_exists($contacts, $uuid) {
|
||||
if (is_array($contacts[$uuid])) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends contacts from the database to the given array of contacts.
|
||||
*
|
||||
* @param array $contacts The array of contacts to append to.
|
||||
* @param string $line The current line being processed (used for phone numbers).
|
||||
* @param string $domain_uuid The UUID of the domain to filter by.
|
||||
* @param string $device_user_uuid The UUID of the device user to filter by.
|
||||
* @param string $category The category of contacts to append (one of 'groups', 'users', or 'all').
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function contact_append(&$contacts, &$line, $domain_uuid, $device_user_uuid, $category) {
|
||||
|
||||
$sql = "select c.contact_uuid, c.contact_organization, c.contact_name_given, c.contact_name_family, ";
|
||||
@@ -259,7 +308,7 @@
|
||||
$phone_label = strtolower($row['phone_label'] ?? '');
|
||||
$contact_category = strtolower($row['contact_category'] ?? '');
|
||||
|
||||
$contact = array();
|
||||
$contact = [];
|
||||
$contacts[] = &$contact;
|
||||
$contact['category'] = ($category == 'all') ? 'groups' : $category;
|
||||
$contact['contact_uuid'] = $row['contact_uuid'];
|
||||
@@ -269,7 +318,7 @@
|
||||
$contact['contact_name_given'] = $row['contact_name_given'];
|
||||
$contact['contact_name_family'] = $row['contact_name_family'];
|
||||
|
||||
$contact['numbers'] = array();
|
||||
$contact['numbers'] = [];
|
||||
$numbers = &$contact['numbers'];
|
||||
|
||||
if (($row['phone_primary'] == '1') || (!isset($contact['phone_number']))) {
|
||||
@@ -293,6 +342,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the provision page for a device.
|
||||
*
|
||||
* This method checks if the device address exists in the database, and if so,
|
||||
* it retrieves the corresponding device information and template. If not, it
|
||||
* attempts to assign a default template based on the user agent.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render() {
|
||||
|
||||
//debug
|
||||
@@ -318,7 +376,7 @@
|
||||
//}
|
||||
|
||||
//remove ../ and slashes in the file name
|
||||
$search = array('..', '/', '\\', '/./', '//');
|
||||
$search = ['..', '/', '\\', '/./', '//'];
|
||||
$file = str_replace($search, "", $file);
|
||||
|
||||
//get the domain_name
|
||||
@@ -356,11 +414,10 @@
|
||||
|
||||
//checks either device enabled
|
||||
if ($row['device_enabled'] === false) {
|
||||
syslog(LOG_WARNING, '['.$_SERVER['REMOTE_ADDR']."] provision attempted but the device is not enabled for ".escape($device_address));
|
||||
if ($this->settings->get('provision','debug', false)) {
|
||||
syslog(LOG_WARNING, '[' . $_SERVER['REMOTE_ADDR'] . "] provision attempted but the device is not enabled for " . escape($device_address));
|
||||
if ($this->settings->get('provision', 'debug', false)) {
|
||||
echo "<br/>device disabled<br/>";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->http_error('404');
|
||||
}
|
||||
exit;
|
||||
@@ -419,8 +476,7 @@
|
||||
}
|
||||
unset($sql, $row, $parameters);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//use the user_agent to pre-assign a template for 1-hit provisioning. Enter the a unique string to match in the user agent, and the template it should match.
|
||||
$templates['Linksys/SPA-2102'] = 'linksys/spa2102';
|
||||
$templates['Linksys/SPA-3102'] = 'linksys/spa3102';
|
||||
@@ -542,8 +598,8 @@
|
||||
$templates['Flyingvoice FIP16'] = 'flyingvoice/fip16';
|
||||
$templates['Flyingvoice FIP16PLUS'] = 'flyingvoice/fip16plus';
|
||||
|
||||
foreach ($templates as $key=>$value) {
|
||||
if(stripos($_SERVER['HTTP_USER_AGENT'],$key)!== false) {
|
||||
foreach ($templates as $key => $value) {
|
||||
if (stripos($_SERVER['HTTP_USER_AGENT'], $key) !== false) {
|
||||
$device_template = $value;
|
||||
break;
|
||||
}
|
||||
@@ -551,7 +607,7 @@
|
||||
unset($templates);
|
||||
|
||||
//device address does not exist in the table so add it
|
||||
if ($this->settings->get('provision','auto_insert_enabled',false)) {
|
||||
if ($this->settings->get('provision', 'auto_insert_enabled', false)) {
|
||||
|
||||
//get a new primary key
|
||||
$device_uuid = uuid();
|
||||
@@ -641,7 +697,7 @@
|
||||
$parameters['device_profile_uuid'] = $device_profile_uuid;
|
||||
$device_profile_settings = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($device_profile_settings) && sizeof($device_profile_settings) != 0) {
|
||||
foreach($device_profile_settings as $row) {
|
||||
foreach ($device_profile_settings as $row) {
|
||||
$key = $row['profile_setting_name'];
|
||||
$value = $row['profile_setting_value'];
|
||||
$provision[$key] = $value;
|
||||
@@ -658,7 +714,7 @@
|
||||
$parameters['device_uuid'] = $device_uuid;
|
||||
$device_settings = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($device_settings) && sizeof($device_settings) != 0) {
|
||||
foreach($device_settings as $row) {
|
||||
foreach ($device_settings as $row) {
|
||||
$key = $row['device_setting_subcategory'];
|
||||
$value = $row['device_setting_value'];
|
||||
$provision[$key] = $value;
|
||||
@@ -673,14 +729,14 @@
|
||||
}
|
||||
|
||||
//if the domain name directory exists then only use templates from it
|
||||
if (is_dir($template_dir.'/'.$domain_name)) {
|
||||
$device_template = $domain_name.'/'.$device_template;
|
||||
if (is_dir($template_dir . '/' . $domain_name)) {
|
||||
$device_template = $domain_name . '/' . $device_template;
|
||||
}
|
||||
|
||||
//initialize a template object
|
||||
$view = new template();
|
||||
$view->engine = $this->settings->get('provision', 'template_engine', 'smarty');
|
||||
$view->template_dir = $template_dir ."/".$device_template."/";
|
||||
$view->template_dir = $template_dir . "/" . $device_template . "/";
|
||||
$view->cache_dir = sys_get_temp_dir();
|
||||
$view->init();
|
||||
|
||||
@@ -700,7 +756,7 @@
|
||||
$sql .= "order by extension asc ";
|
||||
$parameters['domain_uuid'] = $domain_uuid;
|
||||
$extensions = $this->database->select($sql, $parameters, 'all');
|
||||
foreach($extensions as $row) {
|
||||
foreach ($extensions as $row) {
|
||||
$extension_labels[$row['extension']]['caller_id_name'] = $row['effective_caller_id_name'];
|
||||
}
|
||||
unset($sql, $parameters);
|
||||
@@ -733,10 +789,9 @@
|
||||
$sql .= "profile_key_icon as device_key_icon ";
|
||||
$sql .= "from v_device_profile_keys ";
|
||||
$sql .= "where device_profile_uuid = :device_profile_uuid ";
|
||||
if (strtolower($device_vendor) == 'escene'){
|
||||
if (strtolower($device_vendor) == 'escene') {
|
||||
$sql .= "and (lower(profile_key_vendor) = 'escene' or lower(profile_key_vendor) = 'escene programmable' or profile_key_vendor is null) ";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sql .= "and (lower(profile_key_vendor) = :device_vendor or profile_key_vendor is null) ";
|
||||
$parameters['device_vendor'] = $device_vendor;
|
||||
}
|
||||
@@ -750,8 +805,7 @@
|
||||
$sql .= "else 100 end, ";
|
||||
if ($GLOBALS['db_type'] == "mysql") {
|
||||
$sql .= "profile_key_id asc ";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sql .= "cast(profile_key_id as numeric) asc ";
|
||||
}
|
||||
$parameters['device_profile_uuid'] = $device_profile_uuid;
|
||||
@@ -759,7 +813,7 @@
|
||||
|
||||
//add the profile keys to the device keys array
|
||||
if (is_array($keys) && sizeof($keys) != 0) {
|
||||
foreach($keys as $row) {
|
||||
foreach ($keys as $row) {
|
||||
//set the variables
|
||||
$id = $row['device_key_id'];
|
||||
$category = $row['device_key_category'];
|
||||
@@ -786,10 +840,9 @@
|
||||
//get the device keys
|
||||
$sql = "select * from v_device_keys ";
|
||||
$sql .= "where device_uuid = :device_uuid ";
|
||||
if (strtolower($device_vendor) == 'escene'){
|
||||
if (strtolower($device_vendor) == 'escene') {
|
||||
$sql .= "and (lower(device_key_vendor) = 'escene' or lower(device_key_vendor) = 'escene programmable' or device_key_vendor is null) ";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sql .= "and (lower(device_key_vendor) = :device_vendor or device_key_vendor is null) ";
|
||||
$parameters['device_vendor'] = $device_vendor;
|
||||
}
|
||||
@@ -803,8 +856,7 @@
|
||||
$sql .= "else 100 end, ";
|
||||
if ($GLOBALS['db_type'] == "mysql") {
|
||||
$sql .= "device_key_id asc ";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sql .= "cast(device_key_id as numeric) asc ";
|
||||
}
|
||||
$parameters['device_uuid'] = $device_uuid;
|
||||
@@ -812,7 +864,7 @@
|
||||
|
||||
//override profile keys with the device keys
|
||||
if (is_array($keys)) {
|
||||
foreach($keys as $row) {
|
||||
foreach ($keys as $row) {
|
||||
//set the variables
|
||||
$id = $row['device_key_id'];
|
||||
$category = $row['device_key_category'];
|
||||
@@ -836,7 +888,7 @@
|
||||
|
||||
//replace the ${caller_id_name} with the extensions caller id name
|
||||
if (is_array($device_keys)) {
|
||||
foreach($device_keys as $row) {
|
||||
foreach ($device_keys as $row) {
|
||||
//set the variables
|
||||
$id = $row['device_key_id'];
|
||||
$category = $row['device_key_category'];
|
||||
@@ -844,8 +896,8 @@
|
||||
//build the device keys array
|
||||
if (in_array($device_key_vendor, ['cisco', 'spa']) && $row['device_key_type'] == 'disabled') {
|
||||
$device_key_array = explode(';', $row['device_key_value']);
|
||||
foreach($device_key_array as $sub_row) {
|
||||
list($key, $value) = explode('=', $sub_row);
|
||||
foreach ($device_key_array as $sub_row) {
|
||||
[$key, $value] = explode('=', $sub_row);
|
||||
if ($key == 'sub') {
|
||||
$extension = explode('@', $value)[0]; //remove the @PROXY
|
||||
$caller_id_name = $extension_labels[$extension]['caller_id_name'];
|
||||
@@ -868,7 +920,7 @@
|
||||
|
||||
//set the variables
|
||||
if (is_array($device_lines) && sizeof($device_lines) != 0) {
|
||||
foreach($device_lines as $row) {
|
||||
foreach ($device_lines as $row) {
|
||||
//set the variables
|
||||
$line_number = $row['line_number'];
|
||||
$register_expires = $row['register_expires'];
|
||||
@@ -876,7 +928,9 @@
|
||||
$sip_port = $row['sip_port'] ?? '5060';
|
||||
|
||||
//set defaults
|
||||
if (empty($register_expires)) { $register_expires = "120"; }
|
||||
if (empty($register_expires)) {
|
||||
$register_expires = "120";
|
||||
}
|
||||
|
||||
//convert seconds to minutes for grandstream
|
||||
if ($device_vendor == 'grandstream') {
|
||||
@@ -917,18 +971,18 @@
|
||||
}
|
||||
|
||||
//assign the variables with the line number as part of the name
|
||||
$view->assign("server_address_".$line_number, $row["server_address"]);
|
||||
$view->assign("outbound_proxy_".$line_number, $row["outbound_proxy_primary"]);
|
||||
$view->assign("outbound_proxy_primary_".$line_number, $row["outbound_proxy_primary"]);
|
||||
$view->assign("outbound_proxy_secondary_".$line_number, $row["outbound_proxy_secondary"]);
|
||||
$view->assign("display_name_".$line_number, $row["display_name"]);
|
||||
$view->assign("auth_id_".$line_number, $row["auth_id"]);
|
||||
$view->assign("user_id_".$line_number, $row["user_id"]);
|
||||
$view->assign("user_password_".$line_number, $row["password"]);
|
||||
$view->assign("sip_transport_".$line_number, $sip_transport);
|
||||
$view->assign("sip_port_".$line_number, $sip_port);
|
||||
$view->assign("register_expires_".$line_number, $register_expires);
|
||||
$view->assign("shared_line_".$line_number, $row["shared_line"]);
|
||||
$view->assign("server_address_" . $line_number, $row["server_address"]);
|
||||
$view->assign("outbound_proxy_" . $line_number, $row["outbound_proxy_primary"]);
|
||||
$view->assign("outbound_proxy_primary_" . $line_number, $row["outbound_proxy_primary"]);
|
||||
$view->assign("outbound_proxy_secondary_" . $line_number, $row["outbound_proxy_secondary"]);
|
||||
$view->assign("display_name_" . $line_number, $row["display_name"]);
|
||||
$view->assign("auth_id_" . $line_number, $row["auth_id"]);
|
||||
$view->assign("user_id_" . $line_number, $row["user_id"]);
|
||||
$view->assign("user_password_" . $line_number, $row["password"]);
|
||||
$view->assign("sip_transport_" . $line_number, $sip_transport);
|
||||
$view->assign("sip_port_" . $line_number, $sip_port);
|
||||
$view->assign("register_expires_" . $line_number, $register_expires);
|
||||
$view->assign("shared_line_" . $line_number, $row["shared_line"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -940,25 +994,24 @@
|
||||
|
||||
//get the list of contact directly assigned to the user
|
||||
if (is_uuid($domain_uuid)) {
|
||||
if ($this->settings->get('contact','permissions',false)) {
|
||||
if ($this->settings->get('contact', 'permissions', false)) {
|
||||
//get the contacts assigned to the groups and add to the contacts array
|
||||
if (is_uuid($device_user_uuid) && $this->settings->get('contact','contact_groups', false)) {
|
||||
if (is_uuid($device_user_uuid) && $this->settings->get('contact', 'contact_groups', false)) {
|
||||
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, 'groups');
|
||||
}
|
||||
|
||||
//get the contacts assigned to the user and add to the contacts array
|
||||
if (is_uuid($device_user_uuid) && $this->settings->get('contact','contact_users', false)) {
|
||||
if (is_uuid($device_user_uuid) && $this->settings->get('contact', 'contact_users', false)) {
|
||||
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, 'users');
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//show all contacts for the domain
|
||||
$this->contact_append($contacts, $line, $domain_uuid, null, 'all');
|
||||
}
|
||||
}
|
||||
|
||||
//get the extensions and add them to the contacts array
|
||||
if (is_uuid($device_uuid) && is_uuid($domain_uuid) && $this->settings->get('provision','contact_extensions',false)) {
|
||||
if (is_uuid($device_uuid) && is_uuid($domain_uuid) && $this->settings->get('provision', 'contact_extensions', false)) {
|
||||
|
||||
//get contacts from the database
|
||||
$sql = "select extension_uuid as contact_uuid, directory_first_name, directory_last_name, ";
|
||||
@@ -987,8 +1040,7 @@
|
||||
//get the phone_extension
|
||||
if (is_numeric($row['extension'])) {
|
||||
$phone_extension = $row['extension'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$phone_extension = $row['number_alias'];
|
||||
}
|
||||
//save the contact array values
|
||||
@@ -1039,17 +1091,17 @@
|
||||
$variable_names[] = 'description';
|
||||
|
||||
//add location and description to the lines array
|
||||
foreach($lines as $id => $row) {
|
||||
foreach ($lines as $id => $row) {
|
||||
$lines[$id]['location'] = $device_location;
|
||||
$lines[$id]['description'] = $device_description;
|
||||
}
|
||||
|
||||
//update the device keys by replacing variables with their values
|
||||
if (!empty($device_keys['line']) && is_array($device_keys)) {
|
||||
$types = array("line", "memory", "expansion", "programmable");
|
||||
$types = ["line", "memory", "expansion", "programmable"];
|
||||
foreach ($types as $type) {
|
||||
if (!empty($device_keys[$type]) && is_array($device_keys[$type])) {
|
||||
foreach($device_keys[$type] as $row) {
|
||||
foreach ($device_keys[$type] as $row) {
|
||||
//get the variables
|
||||
$device_key_line = $row['device_key_line'];
|
||||
$device_key_id = $row['device_key_id'];
|
||||
@@ -1059,18 +1111,18 @@
|
||||
$device_key_icon = $row['device_key_icon'];
|
||||
|
||||
//replace the variables
|
||||
foreach($variable_names as $name) {
|
||||
foreach ($variable_names as $name) {
|
||||
if (!empty($row['device_key_value'])) {
|
||||
$device_key_value = str_replace("\${".$name."}", $lines[$device_key_line][$name], $device_key_value);
|
||||
$device_key_value = str_replace("\${" . $name . "}", $lines[$device_key_line][$name], $device_key_value);
|
||||
}
|
||||
if (!empty($row['device_key_extension'])) {
|
||||
$device_key_extension = str_replace("\${".$name."}", $lines[$device_key_line][$name], $device_key_extension);
|
||||
$device_key_extension = str_replace("\${" . $name . "}", $lines[$device_key_line][$name], $device_key_extension);
|
||||
}
|
||||
if (!empty($row['device_key_label'])) {
|
||||
$device_key_label = str_replace("\${".$name."}", $lines[$device_key_line][$name], $device_key_label);
|
||||
$device_key_label = str_replace("\${" . $name . "}", $lines[$device_key_line][$name], $device_key_label);
|
||||
}
|
||||
if (!empty($row['device_key_icon'])) {
|
||||
$device_key_icon = str_replace("\${".$name."}", $lines[$device_key_line][$name], $device_key_icon);
|
||||
$device_key_icon = str_replace("\${" . $name . "}", $lines[$device_key_line][$name], $device_key_icon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1090,10 +1142,10 @@
|
||||
}
|
||||
|
||||
//set the variables
|
||||
$types = array("line", "memory", "expansion", "programmable");
|
||||
$types = ["line", "memory", "expansion", "programmable"];
|
||||
foreach ($types as $type) {
|
||||
if (!empty($device_keys[$type]) && is_array($device_keys[$type])) {
|
||||
foreach($device_keys[$type] as $row) {
|
||||
foreach ($device_keys[$type] as $row) {
|
||||
//set the variables
|
||||
$device_key_category = $row['device_key_category'];
|
||||
$device_key_id = $row['device_key_id']; //1
|
||||
@@ -1114,61 +1166,118 @@
|
||||
if ($device_vendor == "grandstream") {
|
||||
if ($device_key_category == "line") {
|
||||
switch ($device_key_type) {
|
||||
case "line": $device_key_type = "0"; break;
|
||||
case "shared line": $device_key_type = "1"; break;
|
||||
case "speed dial": $device_key_type = "10"; break;
|
||||
case "blf": $device_key_type = "11"; break;
|
||||
case "presence watcher": $device_key_type = "12"; break;
|
||||
case "eventlist blf": $device_key_type = "13"; break;
|
||||
case "speed dial active": $device_key_type = "14"; break;
|
||||
case "dial dtmf": $device_key_type = "15"; break;
|
||||
case "voicemail": $device_key_type = "16"; break;
|
||||
case "call return": $device_key_type = "17"; break;
|
||||
case "transfer": $device_key_type = "18"; break;
|
||||
case "call park": $device_key_type = "19"; break;
|
||||
case "monitored call park": $device_key_type = "26"; break;
|
||||
case "intercom": $device_key_type = "20"; break;
|
||||
case "ldap search": $device_key_type = "21"; break;
|
||||
case "phonebook": $device_key_type = "30"; break;
|
||||
case "line":
|
||||
$device_key_type = "0";
|
||||
break;
|
||||
case "shared line":
|
||||
$device_key_type = "1";
|
||||
break;
|
||||
case "speed dial":
|
||||
$device_key_type = "10";
|
||||
break;
|
||||
case "blf":
|
||||
$device_key_type = "11";
|
||||
break;
|
||||
case "presence watcher":
|
||||
$device_key_type = "12";
|
||||
break;
|
||||
case "eventlist blf":
|
||||
$device_key_type = "13";
|
||||
break;
|
||||
case "speed dial active":
|
||||
$device_key_type = "14";
|
||||
break;
|
||||
case "dial dtmf":
|
||||
$device_key_type = "15";
|
||||
break;
|
||||
case "voicemail":
|
||||
$device_key_type = "16";
|
||||
break;
|
||||
case "call return":
|
||||
$device_key_type = "17";
|
||||
break;
|
||||
case "transfer":
|
||||
$device_key_type = "18";
|
||||
break;
|
||||
case "call park":
|
||||
$device_key_type = "19";
|
||||
break;
|
||||
case "monitored call park":
|
||||
$device_key_type = "26";
|
||||
break;
|
||||
case "intercom":
|
||||
$device_key_type = "20";
|
||||
break;
|
||||
case "ldap search":
|
||||
$device_key_type = "21";
|
||||
break;
|
||||
case "phonebook":
|
||||
$device_key_type = "30";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($device_key_category == "memory" || $device_key_category == "expansion") {
|
||||
switch ($device_key_type) {
|
||||
case "speed dial": $device_key_type = "0"; break;
|
||||
case "blf": $device_key_type = "1"; break;
|
||||
case "presence watcher": $device_key_type = "2"; break;
|
||||
case "eventlist blf": $device_key_type = "3"; break;
|
||||
case "speed dial active": $device_key_type = "4"; break;
|
||||
case "dial dtmf": $device_key_type = "5"; break;
|
||||
case "voicemail": $device_key_type = "6"; break;
|
||||
case "call return": $device_key_type = "7"; break;
|
||||
case "transfer": $device_key_type = "8"; break;
|
||||
case "call park": $device_key_type = "9"; break;
|
||||
case "monitored call park": $device_key_type = "16"; break;
|
||||
case "intercom": $device_key_type = "10"; break;
|
||||
case "ldap search": $device_key_type = "11"; break;
|
||||
case "speed dial":
|
||||
$device_key_type = "0";
|
||||
break;
|
||||
case "blf":
|
||||
$device_key_type = "1";
|
||||
break;
|
||||
case "presence watcher":
|
||||
$device_key_type = "2";
|
||||
break;
|
||||
case "eventlist blf":
|
||||
$device_key_type = "3";
|
||||
break;
|
||||
case "speed dial active":
|
||||
$device_key_type = "4";
|
||||
break;
|
||||
case "dial dtmf":
|
||||
$device_key_type = "5";
|
||||
break;
|
||||
case "voicemail":
|
||||
$device_key_type = "6";
|
||||
break;
|
||||
case "call return":
|
||||
$device_key_type = "7";
|
||||
break;
|
||||
case "transfer":
|
||||
$device_key_type = "8";
|
||||
break;
|
||||
case "call park":
|
||||
$device_key_type = "9";
|
||||
break;
|
||||
case "monitored call park":
|
||||
$device_key_type = "16";
|
||||
break;
|
||||
case "intercom":
|
||||
$device_key_type = "10";
|
||||
break;
|
||||
case "ldap search":
|
||||
$device_key_type = "11";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//assign the variables
|
||||
if (empty($device_key_category)) {
|
||||
$view->assign("key_id_".$device_key_id, $device_key_id);
|
||||
$view->assign("key_type_".$device_key_id, $device_key_type);
|
||||
$view->assign("key_line_".$device_key_id, $device_key_line);
|
||||
$view->assign("key_value_".$device_key_id, $device_key_value);
|
||||
$view->assign("key_extension_".$device_key_id, $device_key_extension);
|
||||
$view->assign("key_label_".$device_key_id, $device_key_label);
|
||||
$view->assign("key_icon_".$device_key_id, $device_key_icon);
|
||||
}
|
||||
else {
|
||||
$view->assign($device_key_category."_key_id_".$device_key_id, $device_key_id);
|
||||
$view->assign($device_key_category."_key_type_".$device_key_id, $device_key_type);
|
||||
$view->assign($device_key_category."_key_line_".$device_key_id, $device_key_line);
|
||||
$view->assign($device_key_category."_key_value_".$device_key_id, $device_key_value);
|
||||
$view->assign($device_key_category."_key_extension_".$device_key_id, $device_key_extension);
|
||||
$view->assign($device_key_category."_key_label_".$device_key_id, $device_key_label);
|
||||
$view->assign($device_key_category."_key_icon_".$device_key_id, $device_key_icon);
|
||||
$view->assign("key_id_" . $device_key_id, $device_key_id);
|
||||
$view->assign("key_type_" . $device_key_id, $device_key_type);
|
||||
$view->assign("key_line_" . $device_key_id, $device_key_line);
|
||||
$view->assign("key_value_" . $device_key_id, $device_key_value);
|
||||
$view->assign("key_extension_" . $device_key_id, $device_key_extension);
|
||||
$view->assign("key_label_" . $device_key_id, $device_key_label);
|
||||
$view->assign("key_icon_" . $device_key_id, $device_key_icon);
|
||||
} else {
|
||||
$view->assign($device_key_category . "_key_id_" . $device_key_id, $device_key_id);
|
||||
$view->assign($device_key_category . "_key_type_" . $device_key_id, $device_key_type);
|
||||
$view->assign($device_key_category . "_key_line_" . $device_key_id, $device_key_line);
|
||||
$view->assign($device_key_category . "_key_value_" . $device_key_id, $device_key_value);
|
||||
$view->assign($device_key_category . "_key_extension_" . $device_key_id, $device_key_extension);
|
||||
$view->assign($device_key_category . "_key_label_" . $device_key_id, $device_key_label);
|
||||
$view->assign($device_key_category . "_key_icon_" . $device_key_id, $device_key_icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1178,7 +1287,7 @@
|
||||
$device_address = $this->format_address($device_address, $device_vendor);
|
||||
|
||||
//set date/time for versioning provisioning templates
|
||||
$time = date($this->settings->get('provision','version_format', "dmyHi"));
|
||||
$time = date($this->settings->get('provision', 'version_format', "dmyHi"));
|
||||
|
||||
//replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number
|
||||
$view->assign("device_address", $device_address);
|
||||
@@ -1205,16 +1314,16 @@
|
||||
$sql = "select contact_uuid from v_users where user_uuid = :device_user_uuid ";
|
||||
$parameters['device_user_uuid'] = $device_user_uuid;
|
||||
$contact_uuid = $this->database->select($sql, $parameters, 'column');
|
||||
$view->assign("ldap_username", "uid=" . $contact_uuid . "," . $this->settings->get('provision','grandstream_ldap_user_base', ''));
|
||||
$view->assign("ldap_password",md5($laddr_salt.$device_user_uuid));
|
||||
$view->assign("ldap_username", "uid=" . $contact_uuid . "," . $this->settings->get('provision', 'grandstream_ldap_user_base', ''));
|
||||
$view->assign("ldap_password", md5($laddr_salt . $device_user_uuid));
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
//get the time zone
|
||||
$time_zone = $this->settings->get('domain','time_zone', 'UTC');
|
||||
$time_zone = $this->settings->get('domain', 'time_zone', 'UTC');
|
||||
|
||||
//auto calculate the daylight savings settings
|
||||
if ($this->settings->get('provision','daylight_savings_auto', true)) {
|
||||
if ($this->settings->get('provision', 'daylight_savings_auto', true)) {
|
||||
//initialize the variables
|
||||
$daylight_savings_start = null;
|
||||
$daylight_savings_end = null;
|
||||
@@ -1223,8 +1332,8 @@
|
||||
date_default_timezone_set($time_zone);
|
||||
$current_year = date('Y');
|
||||
$tz = new DateTimeZone($time_zone);
|
||||
$start_of_year = new DateTime($current_year.'-01-01 00:00:00', $tz);
|
||||
$end_of_year = new DateTime($current_year.'-12-31 23:59:59', $tz);
|
||||
$start_of_year = new DateTime($current_year . '-01-01 00:00:00', $tz);
|
||||
$end_of_year = new DateTime($current_year . '-12-31 23:59:59', $tz);
|
||||
$transitions = $tz->getTransitions($start_of_year->getTimestamp(), $end_of_year->getTimestamp());
|
||||
|
||||
//add the daylight savings to the provision array
|
||||
@@ -1274,15 +1383,15 @@
|
||||
|
||||
//set daylight savings settings time for yealink
|
||||
if (!isset($provision["yealink_time_zone_start_time"])) {
|
||||
$provision["yealink_time_zone_start_time"] = $provision["daylight_savings_start_month"]."/".$provision["daylight_savings_start_day"]."/".$provision["daylight_savings_start_time"];
|
||||
$provision["yealink_time_zone_start_time"] = $provision["daylight_savings_start_month"] . "/" . $provision["daylight_savings_start_day"] . "/" . $provision["daylight_savings_start_time"];
|
||||
}
|
||||
if (!isset($provision["yealink_time_zone_end_time"])) {
|
||||
$provision["yealink_time_zone_end_time"] = $provision["daylight_savings_stop_month"]."/".$provision["daylight_savings_stop_day"]."/".$provision["daylight_savings_stop_time"];
|
||||
$provision["yealink_time_zone_end_time"] = $provision["daylight_savings_stop_month"] . "/" . $provision["daylight_savings_stop_day"] . "/" . $provision["daylight_savings_stop_time"];
|
||||
}
|
||||
|
||||
//replace the dynamic provision variables that are defined in default, domain, and device settings
|
||||
if (is_array($provision)) {
|
||||
foreach($provision as $key=>$val) {
|
||||
foreach ($provision as $key => $val) {
|
||||
if (!empty($val) && is_string($val) && strpos($val, '{$domain_name}') !== false) {
|
||||
$val = str_replace('{$domain_name}', $domain_name, $val);
|
||||
}
|
||||
@@ -1295,31 +1404,25 @@
|
||||
|
||||
//if $file is not provided then look for a default file that exists
|
||||
if (empty($file)) {
|
||||
if (file_exists($template_dir."/".$device_template ."/{\$address}")) {
|
||||
if (file_exists($template_dir . "/" . $device_template . "/{\$address}")) {
|
||||
$file = "{\$address}";
|
||||
}
|
||||
elseif (file_exists($template_dir."/".$device_template ."/{\$address}.xml")) {
|
||||
} elseif (file_exists($template_dir . "/" . $device_template . "/{\$address}.xml")) {
|
||||
$file = "{\$address}.xml";
|
||||
}
|
||||
elseif (file_exists($template_dir."/".$device_template ."/{\$mac}")) {
|
||||
} elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}")) {
|
||||
$file = "{\$mac}";
|
||||
}
|
||||
elseif (file_exists($template_dir."/".$device_template ."/{\$mac}.xml")) {
|
||||
} elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}.xml")) {
|
||||
$file = "{\$mac}.xml";
|
||||
}
|
||||
elseif (file_exists($template_dir."/".$device_template ."/{\$mac}.cfg")) {
|
||||
} elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}.cfg")) {
|
||||
$file = "{\$mac}.cfg";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->http_error('404');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//make sure the file exists
|
||||
if (!file_exists($template_dir."/".$device_template ."/".$file)) {
|
||||
if (!file_exists($template_dir . "/" . $device_template . "/" . $file)) {
|
||||
$this->http_error('404');
|
||||
if ($this->settings->get('provision','debug',false)) {
|
||||
if ($this->settings->get('provision', 'debug', false)) {
|
||||
echo ":$template_dir/$device_template/$file<br/>";
|
||||
echo "template_dir: $template_dir<br/>";
|
||||
echo "device_template: $device_template<br/>";
|
||||
@@ -1333,10 +1436,10 @@
|
||||
$file_contents = $view->render($file);
|
||||
|
||||
//log file for testing
|
||||
if ($this->settings->get('provision','debug',false)) {
|
||||
if ($this->settings->get('provision', 'debug', false)) {
|
||||
$tmp_file = "/tmp/provisioning_log.txt";
|
||||
$fh = fopen($tmp_file, 'w') or die("can't open file");
|
||||
$tmp_string = $device_address."\n";
|
||||
$tmp_string = $device_address . "\n";
|
||||
fwrite($fh, $tmp_string);
|
||||
fclose($fh);
|
||||
}
|
||||
@@ -1348,6 +1451,15 @@
|
||||
|
||||
} //end render function
|
||||
|
||||
/**
|
||||
* Writes configuration files for devices based on the provided provision template.
|
||||
*
|
||||
* This method iterates over a list of devices in the database, retrieves their configuration
|
||||
* from the provision array, and writes the corresponding files to disk. If a device is
|
||||
* disabled, any existing files with a MAC address placeholder are removed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function write() {
|
||||
//build the provision array
|
||||
$provision = $this->settings->get('provision', null, []);
|
||||
@@ -1401,7 +1513,7 @@
|
||||
clearstatcache();
|
||||
|
||||
//loop through the provision template directory
|
||||
$dir_array = array();
|
||||
$dir_array = [];
|
||||
if (!empty($device_template)) {
|
||||
$template_path = path_join($this->template_dir, $device_template);
|
||||
$dir_list = opendir($template_path);
|
||||
@@ -1412,7 +1524,9 @@
|
||||
substr($file, -4) == ".svn" || substr($file, -4) == ".git";
|
||||
if (!$ignore) {
|
||||
$dir_array[] = path_join($template_path, $file);
|
||||
if ($x > 1000) { break; };
|
||||
if ($x > 1000) {
|
||||
break;
|
||||
};
|
||||
$x++;
|
||||
}
|
||||
}
|
||||
@@ -1458,13 +1572,12 @@
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
$fh = fopen($dest_path,"w") or die("Unable to write to $directory for provisioning. Make sure the path exists and permissons are set correctly.");
|
||||
$fh = fopen($dest_path, "w") or die("Unable to write to $directory for provisioning. Make sure the path exists and permissons are set correctly.");
|
||||
fwrite($fh, $file_contents);
|
||||
fclose($fh);
|
||||
}
|
||||
else { // device disabled
|
||||
} else { // device disabled
|
||||
//remove only files with `{$mac}` name
|
||||
if (strpos($template_path, '{$mac}') !== false){
|
||||
if (strpos($template_path, '{$mac}') !== false) {
|
||||
unlink($dest_path);
|
||||
}
|
||||
}
|
||||
@@ -1483,6 +1596,6 @@
|
||||
}
|
||||
} //end write function
|
||||
|
||||
} //end provision class
|
||||
} //end provision class
|
||||
|
||||
?>
|
||||
|
||||
@@ -328,8 +328,8 @@
|
||||
}
|
||||
$param .= "&order_by=".$order_by."&order=".$order;
|
||||
$page = isset($_GET['page']) ? $_GET['page'] : 0;
|
||||
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
|
||||
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
|
||||
[$paging_controls, $rows_per_page] = paging($num_rows, $param, $rows_per_page);
|
||||
[$paging_controls_mini, $rows_per_page] = paging($num_rows, $param, $rows_per_page, true);
|
||||
$offset = $rows_per_page * $page;
|
||||
|
||||
//set the time zone
|
||||
@@ -622,6 +622,13 @@
|
||||
require_once "resources/footer.php";
|
||||
|
||||
//define the download function (helps safari play audio sources)
|
||||
/**
|
||||
* Downloads a file in range mode, allowing the client to request specific byte ranges.
|
||||
*
|
||||
* @param string $file Path to the file being downloaded
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function range_download($file) {
|
||||
$fp = @fopen($file, 'rb');
|
||||
|
||||
@@ -650,7 +657,7 @@
|
||||
$c_start = $start;
|
||||
$c_end = $end;
|
||||
// Extract the range string
|
||||
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
// Make sure the client hasn't sent us a multibyte range
|
||||
if (strpos($range, ',') !== false) {
|
||||
// (?) Shoud this be issued here, or should the first
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
//define the switch_recordings class
|
||||
class switch_recordings {
|
||||
class switch_recordings {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,31 +35,39 @@
|
||||
const app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -75,7 +83,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -95,7 +108,14 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* list recordings
|
||||
* Retrieves a list of recordings.
|
||||
*
|
||||
* This method queries the database for recordings associated with the current domain UUID
|
||||
* and populates an array with the recording filenames. The array keys are constructed using
|
||||
* the directory path specified in the 'switch' settings, relative to the domain name.
|
||||
*
|
||||
* @return array|false An array of recording filenames where the keys represent the file paths on disk,
|
||||
* or false if no recordings were found.
|
||||
*/
|
||||
public function list_recordings() {
|
||||
$sql = "select recording_uuid, recording_filename ";
|
||||
@@ -104,12 +124,11 @@
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$result = $this->database->select($sql, $parameters, 'all');
|
||||
if (!empty($result)) {
|
||||
$switch_recordings_domain_dir = $this->settings->get('switch', 'recordings').'/'.$this->domain_name;
|
||||
$switch_recordings_domain_dir = $this->settings->get('switch', 'recordings') . '/' . $this->domain_name;
|
||||
foreach ($result as $row) {
|
||||
$recordings[$switch_recordings_domain_dir."/".$row['recording_filename']] = $row['recording_filename'];
|
||||
$recordings[$switch_recordings_domain_dir . "/" . $row['recording_filename']] = $row['recording_filename'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$recordings = false;
|
||||
}
|
||||
unset($sql, $parameters, $result, $row);
|
||||
@@ -117,10 +136,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -129,8 +154,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -151,7 +176,7 @@
|
||||
unset($sql, $parameters);
|
||||
|
||||
//build delete array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
}
|
||||
@@ -165,10 +190,10 @@
|
||||
|
||||
//delete recording files
|
||||
if (is_array($filenames) && @sizeof($filenames) != 0) {
|
||||
$switch_recordings_domain_dir = $this->settings->get('switch', 'recordings')."/".$this->domain_name;
|
||||
$switch_recordings_domain_dir = $this->settings->get('switch', 'recordings') . "/" . $this->domain_name;
|
||||
foreach ($filenames as $filename) {
|
||||
if (!empty($filename) && file_exists($switch_recordings_domain_dir."/".$filename)) {
|
||||
@unlink($switch_recordings_domain_dir."/".$filename);
|
||||
if (!empty($filename) && file_exists($switch_recordings_domain_dir . "/" . $filename)) {
|
||||
@unlink($switch_recordings_domain_dir . "/" . $filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,4 +211,4 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
|
||||
class registrations {
|
||||
class registrations {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -34,30 +34,37 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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 name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be an event_socket object and cannot be null.
|
||||
*
|
||||
* @var event_socket Event Socket Connection Object
|
||||
*/
|
||||
private $event_socket;
|
||||
@@ -70,7 +77,12 @@
|
||||
public $show;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -94,7 +106,11 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* get the registrations
|
||||
* Retrieves the registration list for a given SIP profile.
|
||||
*
|
||||
* @param string|null $profile The name of the SIP profile to retrieve. Defaults to 'all'.
|
||||
*
|
||||
* @return array|null The registration list, or null if no profiles are found.
|
||||
*/
|
||||
public function get($profile = 'all') {
|
||||
|
||||
@@ -139,17 +155,19 @@
|
||||
$field = $sip_profiles[$i++];
|
||||
|
||||
//get sofia status profile information including registrations
|
||||
$cmd = "api sofia xmlstatus profile '".$field['sip_profile_name']."' reg";
|
||||
$cmd = "api sofia xmlstatus profile '" . $field['sip_profile_name'] . "' reg";
|
||||
$xml_response = trim($event_socket->request($cmd));
|
||||
|
||||
//show an error message
|
||||
if ($xml_response == "Invalid Profile!") {
|
||||
//show the error message
|
||||
$xml_response = "<error_msg>".escape($text['label-message'])."</error_msg>";
|
||||
$xml_response = "<error_msg>" . escape($text['label-message']) . "</error_msg>";
|
||||
}
|
||||
|
||||
//sanitize the XML
|
||||
if (function_exists('iconv')) { $xml_response = iconv("utf-8", "utf-8//IGNORE", $xml_response); }
|
||||
if (function_exists('iconv')) {
|
||||
$xml_response = iconv("utf-8", "utf-8//IGNORE", $xml_response);
|
||||
}
|
||||
$xml_response = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/u', '', $xml_response);
|
||||
$xml_response = str_replace("<profile-info>", "<profile_info>", $xml_response);
|
||||
$xml_response = str_replace("</profile-info>", "</profile_info>", $xml_response);
|
||||
@@ -158,11 +176,10 @@
|
||||
if (strlen($xml_response) > 101) {
|
||||
try {
|
||||
$xml = new SimpleXMLElement($xml_response);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
echo basename(__FILE__)."<br />\n";
|
||||
echo "line: ".__line__."<br />\n";
|
||||
echo "error: ".$e->getMessage()."<br />\n";
|
||||
} catch (Exception $e) {
|
||||
echo basename(__FILE__) . "<br />\n";
|
||||
echo "line: " . __line__ . "<br />\n";
|
||||
echo "error: " . $e->getMessage() . "<br />\n";
|
||||
//echo $xml_response;
|
||||
exit;
|
||||
}
|
||||
@@ -202,8 +219,7 @@
|
||||
//get network-ip to url or blank
|
||||
if (isset($row['network-ip'])) {
|
||||
$registrations[$id]['network-ip'] = $row['network-ip'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$registrations[$id]['network-ip'] = '';
|
||||
}
|
||||
|
||||
@@ -214,34 +230,30 @@
|
||||
$lan_ip = $call_id_array[1];
|
||||
if (!empty($agent) && (false !== stripos($agent, 'grandstream') || false !== stripos($agent, 'ooma'))) {
|
||||
$lan_ip = str_ireplace(
|
||||
array('A','B','C','D','E','F','G','H','I','J'),
|
||||
array('0','1','2','3','4','5','6','7','8','9'),
|
||||
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
|
||||
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
|
||||
$lan_ip);
|
||||
}
|
||||
elseif (!empty($agent) && 1 === preg_match('/\ACL750A/', $agent)) {
|
||||
} elseif (!empty($agent) && 1 === preg_match('/\ACL750A/', $agent)) {
|
||||
//required for GIGASET Sculpture CL750A puts _ in it's lan ip account
|
||||
$lan_ip = preg_replace('/_/', '.', $lan_ip);
|
||||
}
|
||||
$registrations[$id]['lan-ip'] = $lan_ip;
|
||||
}
|
||||
else if (preg_match('/real=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $row['contact'] ?? '', $ip_match)) {
|
||||
} elseif (preg_match('/real=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $row['contact'] ?? '', $ip_match)) {
|
||||
//get ip address for snom phones
|
||||
$lan_ip = str_replace('real=', '', $ip_match[0]);
|
||||
$registrations[$id]['lan-ip'] = $lan_ip;
|
||||
}
|
||||
else if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $row['contact'] ?? '', $ip_match)) {
|
||||
} elseif (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $row['contact'] ?? '', $ip_match)) {
|
||||
$lan_ip = preg_replace('/_/', '.', $ip_match[0]);
|
||||
$registrations[$id]['lan-ip'] = $lan_ip;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$registrations[$id]['lan-ip'] = '';
|
||||
}
|
||||
|
||||
//remove unrelated domains
|
||||
if (!permission_exists('registration_all') || $this->show != 'all') {
|
||||
if ($registrations[$id]['sip-auth-realm'] == $this->domain_name) {}
|
||||
else if ($user_array[1] == $this->domain_name) {}
|
||||
else {
|
||||
if ($registrations[$id]['sip-auth-realm'] == $this->domain_name) {
|
||||
} elseif ($user_array[1] == $this->domain_name) {
|
||||
} else {
|
||||
unset($registrations[$id]);
|
||||
}
|
||||
}
|
||||
@@ -260,7 +272,11 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* get the registration count
|
||||
* Retrieves the registration count for a given SIP profile.
|
||||
*
|
||||
* @param string|null $profile The name of the SIP profile to retrieve. Defaults to 'all'.
|
||||
*
|
||||
* @return int The registration count, or 0 if no profiles are found.
|
||||
*/
|
||||
public function count($profile = 'all') {
|
||||
|
||||
@@ -276,31 +292,50 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister registrations
|
||||
* Unregisters a list of registrations from a given SIP profile or all profiles if no profile is specified.
|
||||
*
|
||||
* @param array $registrations The list of registrations to unregister, keyed by SIP URI.
|
||||
*
|
||||
* @return void This method does not return any value.
|
||||
*/
|
||||
public function unregister($registrations) {
|
||||
$this->switch_api('unregister', $registrations);
|
||||
}
|
||||
|
||||
/**
|
||||
* provision registrations
|
||||
* Provision a set of SIP registrations.
|
||||
*
|
||||
* @param array $registrations The list of registrations to provision.
|
||||
*
|
||||
* @returnvoid This method does not return any value.
|
||||
*/
|
||||
public function provision($registrations) {
|
||||
$this->switch_api('provision', $registrations);
|
||||
}
|
||||
|
||||
/**
|
||||
* reboot registrations
|
||||
* Initiates a system reboot with the specified registrations.
|
||||
*
|
||||
* @param array $registrations The list of registrations to persist before rebooting.
|
||||
*
|
||||
* @return void This method does not return any value.
|
||||
*/
|
||||
public function reboot($registrations) {
|
||||
$this->switch_api('reboot', $registrations);
|
||||
}
|
||||
|
||||
/**
|
||||
* switch api calls
|
||||
* Processes API commands for a list of registered devices.
|
||||
*
|
||||
* This will cause execution to exit.
|
||||
*
|
||||
* @param string $action The action to perform (unregister, provision, reboot).
|
||||
* @param array $records The list of registered devices.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function switch_api($action, $records) {
|
||||
if (permission_exists($this->permission_prefix.'domain') || permission_exists($this->permission_prefix.'all') || if_group('superadmin')) {
|
||||
if (permission_exists($this->permission_prefix . 'domain') || permission_exists($this->permission_prefix . 'all') || if_group('superadmin')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -309,14 +344,14 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
//filter out unchecked registrations
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if ($record['checked'] == 'true' && !empty($record['user']) && !empty($record['profile'])) {
|
||||
$registrations[] = $record;
|
||||
}
|
||||
@@ -348,9 +383,8 @@
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
header('Location: '.$this->list_page);
|
||||
} else {
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -373,23 +407,23 @@
|
||||
if (!empty($profile) && $user) {
|
||||
switch ($action) {
|
||||
case 'unregister':
|
||||
$command = "sofia profile ".$profile." flush_inbound_reg ".$user." reboot";
|
||||
$command = "sofia profile " . $profile . " flush_inbound_reg " . $user . " reboot";
|
||||
$response_message = $text['message-registrations_unregistered'];
|
||||
break;
|
||||
case 'provision':
|
||||
if ($vendor && $host) {
|
||||
$command = "lua app.lua event_notify ".$profile." check_sync ".$user." ".$vendor." ".$host;
|
||||
$command = "lua app.lua event_notify " . $profile . " check_sync " . $user . " " . $vendor . " " . $host;
|
||||
$response_message = $text['message-registrations_provisioned'];
|
||||
}
|
||||
break;
|
||||
case 'reboot':
|
||||
if ($vendor && $host) {
|
||||
$command = "lua app.lua event_notify ".$profile." reboot ".$user." ".$vendor." ".$host;
|
||||
$command = "lua app.lua event_notify " . $profile . " reboot " . $user . " " . $vendor . " " . $host;
|
||||
$response_message = $text['message-registrations_rebooted'];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
header('Location: '.$this->list_page);
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -408,23 +442,21 @@
|
||||
$message = '';
|
||||
foreach ($response_api as $registration_user => $response) {
|
||||
if (is_array($response['command'])) {
|
||||
foreach($response['command'] as $command) {
|
||||
foreach ($response['command'] as $command) {
|
||||
$command = trim($command ?? '');
|
||||
if ($command !== '-ERR no reply') {
|
||||
$message .= "<br>\n<strong>".escape($registration_user)."</strong>: ".escape($response_message);
|
||||
$message .= "<br>\n<strong>" . escape($registration_user) . "</strong>: " . escape($response_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!empty($response['command']) && $response['command'] !== '-ERR no reply') {
|
||||
$message .= "<br>\n<strong>".escape($registration_user)."</strong>: ".escape($response_message);
|
||||
$message .= "<br>\n<strong>" . escape($registration_user) . "</strong>: " . escape($response_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
message::add($message, 'positive', '7000');
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message::add($text['error-event-socket'], 'negative', 5000);
|
||||
}
|
||||
|
||||
@@ -433,4 +465,4 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the ring groups class
|
||||
class ring_groups {
|
||||
class ring_groups {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,30 +35,37 @@
|
||||
|
||||
/**
|
||||
* Ring group primary key
|
||||
*
|
||||
* @var uuid
|
||||
*/
|
||||
public $ring_group_uuid;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -74,7 +81,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -90,14 +102,20 @@
|
||||
$this->table = 'ring_groups';
|
||||
$this->uuid_prefix = 'ring_group_';
|
||||
$this->toggle_field = 'ring_group_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -106,8 +124,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -117,15 +135,15 @@
|
||||
//filter out unchecked ring groups, build where clause for below
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary ring group details
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid, ring_group_context from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, dialplan_uuid, ring_group_context from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -140,11 +158,11 @@
|
||||
//build the delete array
|
||||
$x = 0;
|
||||
foreach ($ring_groups as $ring_group_uuid => $ring_group) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $ring_group_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $ring_group_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['ring_group_users'][$x][$this->uuid_prefix.'uuid'] = $ring_group_uuid;
|
||||
$array['ring_group_users'][$x][$this->uuid_prefix . 'uuid'] = $ring_group_uuid;
|
||||
$array['ring_group_users'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['ring_group_destinations'][$x][$this->uuid_prefix.'uuid'] = $ring_group_uuid;
|
||||
$array['ring_group_destinations'][$x][$this->uuid_prefix . 'uuid'] = $ring_group_uuid;
|
||||
$array['ring_group_destinations'][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $ring_group['dialplan_uuid'];
|
||||
$array['dialplan_details'][$x]['dialplan_uuid'] = $ring_group['dialplan_uuid'];
|
||||
@@ -179,7 +197,7 @@
|
||||
$ring_group_contexts = array_unique($ring_group_contexts);
|
||||
$cache = new cache;
|
||||
foreach ($ring_group_contexts as $ring_group_context) {
|
||||
$cache->delete("dialplan:".$ring_group_context);
|
||||
$cache->delete("dialplan:" . $ring_group_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +214,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple destination records from the database.
|
||||
*
|
||||
* @param array $records An array of destination records to delete, where each record contains 'uuid' and 'checked' keys.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_destinations($records) {
|
||||
|
||||
//assign private variables
|
||||
@@ -203,7 +228,7 @@
|
||||
$this->table = 'ring_group_destinations';
|
||||
$this->uuid_prefix = 'ring_group_destination_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -212,8 +237,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('L$ring_group_uuidocation: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('L$ring_group_uuidocation: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -242,7 +267,7 @@
|
||||
if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$x = 0;
|
||||
foreach ($uuids as $uuid) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -261,7 +286,7 @@
|
||||
//clear the cache
|
||||
if ($ring_group_context) {
|
||||
$cache = new cache;
|
||||
$cache->delete("dialplan:".$ring_group_context);
|
||||
$cache->delete("dialplan:" . $ring_group_context);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -271,10 +296,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -283,8 +314,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -294,13 +325,13 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, dialplan_uuid, ring_group_context from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, dialplan_uuid, ring_group_context from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -316,7 +347,7 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($ring_groups as $uuid => $ring_group) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $ring_group['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $ring_group['dialplan_uuid'];
|
||||
$array['dialplans'][$x]['dialplan_enabled'] = $ring_group['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
@@ -346,7 +377,7 @@
|
||||
$ring_group_contexts = array_unique($ring_group_contexts);
|
||||
$cache = new cache;
|
||||
foreach ($ring_group_contexts as $ring_group_context) {
|
||||
$cache->delete("dialplan:".$ring_group_context);
|
||||
$cache->delete("dialplan:" . $ring_group_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,10 +396,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -377,8 +414,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -388,7 +425,7 @@
|
||||
//get checked records
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,9 +433,9 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -408,7 +445,7 @@
|
||||
$new_dialplan_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -419,9 +456,9 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_ring_group_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $new_ring_group_uuid;
|
||||
$array[$this->table][$x]['dialplan_uuid'] = $new_dialplan_uuid;
|
||||
$array[$this->table][$x]['ring_group_description'] = trim($row['ring_group_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x]['ring_group_description'] = trim($row['ring_group_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//users sub table
|
||||
$sql_2 = "select * from v_ring_group_users where ring_group_uuid = :ring_group_uuid";
|
||||
@@ -431,7 +468,7 @@
|
||||
foreach ($rows_2 as $row_2) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -460,7 +497,7 @@
|
||||
foreach ($rows_3 as $row_3) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_3 as $key => $value) {
|
||||
foreach ($row_3 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_3[$key] = $value;
|
||||
@@ -488,7 +525,7 @@
|
||||
if (is_array($dialplan) && @sizeof($dialplan) != 0) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($dialplan as $key => $value) {
|
||||
foreach ($dialplan as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$dialplan[$key] = $value;
|
||||
@@ -504,7 +541,7 @@
|
||||
$dialplan_xml = str_replace($row['ring_group_uuid'], $new_ring_group_uuid, $dialplan_xml); //replace source ring_group_uuid with new
|
||||
$dialplan_xml = str_replace($dialplan['dialplan_uuid'], $new_dialplan_uuid, $dialplan_xml); //replace source dialplan_uuid with new
|
||||
$array['dialplans'][$x]['dialplan_xml'] = $dialplan_xml;
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'].' ('.$text['label-copy'].')');
|
||||
$array['dialplans'][$x]['dialplan_description'] = trim($dialplan['dialplan_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
unset($sql_4, $parameters_4, $dialplan);
|
||||
@@ -543,7 +580,7 @@
|
||||
$ring_group_contexts = array_unique($ring_group_contexts);
|
||||
$cache = new cache;
|
||||
foreach ($ring_group_contexts as $ring_group_context) {
|
||||
$cache->delete("dialplan:".$ring_group_context);
|
||||
$cache->delete("dialplan:" . $ring_group_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,4 +594,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the sip profiles class
|
||||
class sip_profiles {
|
||||
class sip_profiles {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,24 +35,30 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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;
|
||||
@@ -73,7 +79,12 @@
|
||||
public $sip_profile_uuid;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -90,14 +101,20 @@
|
||||
$this->table = 'sip_profiles';
|
||||
$this->uuid_prefix = 'sip_profile_';
|
||||
$this->toggle_field = 'sip_profile_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -106,8 +123,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -117,13 +134,13 @@
|
||||
//filter out unchecked sip profiles, build where clause for below
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary sip profile details
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, sip_profile_name, sip_profile_hostname from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, sip_profile_name, sip_profile_hostname from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -136,9 +153,9 @@
|
||||
//build the delete array
|
||||
$x = 0;
|
||||
foreach ($sip_profiles as $sip_profile_uuid => $sip_profile) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $sip_profile_uuid;
|
||||
$array['sip_profile_domains'][$x][$this->uuid_prefix.'uuid'] = $sip_profile_uuid;
|
||||
$array['sip_profile_settings'][$x][$this->uuid_prefix.'uuid'] = $sip_profile_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $sip_profile_uuid;
|
||||
$array['sip_profile_domains'][$x][$this->uuid_prefix . 'uuid'] = $sip_profile_uuid;
|
||||
$array['sip_profile_settings'][$x][$this->uuid_prefix . 'uuid'] = $sip_profile_uuid;
|
||||
$x++;
|
||||
}
|
||||
|
||||
@@ -161,8 +178,8 @@
|
||||
//delete the xml sip profile and directory
|
||||
$switch_conf_dir = $this->settings->get('switch', 'conf');
|
||||
foreach ($sip_profiles as $sip_profile_uuid => $sip_profile) {
|
||||
@unlink($switch_conf_dir."/sip_profiles/".$sip_profile['name'].".xml");
|
||||
@unlink($switch_conf_dir."/sip_profiles/".$sip_profile['name']);
|
||||
@unlink($switch_conf_dir . "/sip_profiles/" . $sip_profile['name'] . ".xml");
|
||||
@unlink($switch_conf_dir . "/sip_profiles/" . $sip_profile['name']);
|
||||
}
|
||||
|
||||
//save the sip profile xml
|
||||
@@ -176,8 +193,7 @@
|
||||
foreach ($sip_profiles as $sip_profile_uuid => $sip_profile) {
|
||||
if ($sip_profile['hostname'] != '') {
|
||||
$hostnames[] = $sip_profile['hostname'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$empty_hostname = true;
|
||||
}
|
||||
}
|
||||
@@ -190,7 +206,7 @@
|
||||
$hostnames = array_unique($hostnames);
|
||||
$cache = new cache;
|
||||
foreach ($hostnames as $hostname) {
|
||||
$cache->delete($hostname.":configuration:sofia.conf");
|
||||
$cache->delete($hostname . ":configuration:sofia.conf");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,14 +218,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes specified domains from the system.
|
||||
*
|
||||
* @param array $records An array of records to be deleted, each containing 'checked' and 'uuid' keys.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_domains($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'sip_profile_domain_';
|
||||
$this->list_page = 'sip_profile_edit.php?id='.$this->sip_profile_uuid;
|
||||
$this->list_page = 'sip_profile_edit.php?id=' . $this->sip_profile_uuid;
|
||||
$this->table = 'sip_profile_domains';
|
||||
$this->uuid_prefix = 'sip_profile_domain_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'delete')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -218,8 +241,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -229,7 +252,7 @@
|
||||
//filter out unchecked sip profiles, build the delete array
|
||||
foreach ($records as $x => $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][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['sip_profile_uuid'] = $this->sip_profile_uuid;
|
||||
}
|
||||
}
|
||||
@@ -264,78 +287,7 @@
|
||||
//clear the cache
|
||||
if (!empty($sip_profile_hostname)) {
|
||||
$cache = new cache;
|
||||
$cache->delete($sip_profile_hostname.":configuration:sofia.conf");
|
||||
}
|
||||
|
||||
}
|
||||
unset($records);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_settings($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'sip_profile_setting_';
|
||||
$this->list_page = 'sip_profile_edit.php?id='.$this->sip_profile_uuid;
|
||||
$this->table = 'sip_profile_settings';
|
||||
$this->uuid_prefix = 'sip_profile_setting_';
|
||||
|
||||
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 (!empty($records) && @sizeof($records) != 0) {
|
||||
|
||||
//filter out unchecked sip profiles, build the delete array
|
||||
foreach ($records as $x => $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]['sip_profile_uuid'] = $this->sip_profile_uuid;
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary sip profile details
|
||||
if (!empty($this->sip_profile_uuid) && is_uuid($this->sip_profile_uuid)) {
|
||||
$sql = "select sip_profile_hostname from v_sip_profiles ";
|
||||
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
|
||||
$parameters['sip_profile_uuid'] = $this->sip_profile_uuid;
|
||||
$sip_profile_hostname = $this->database->select($sql, $parameters, 'column');
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
//delete the checked rows
|
||||
if (!empty($array) && @sizeof($array) != 0) {
|
||||
|
||||
//execute delete
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//save the sip profile xml
|
||||
save_sip_profile_xml();
|
||||
|
||||
//apply settings reminder
|
||||
$_SESSION["reload_xml"] = true;
|
||||
|
||||
//get system hostname if necessary
|
||||
if (empty($sip_profile_hostname)) {
|
||||
$sip_profile_hostname = gethostname();
|
||||
}
|
||||
|
||||
//clear the cache
|
||||
if (!empty($sip_profile_hostname)) {
|
||||
$cache = new cache;
|
||||
$cache->delete($sip_profile_hostname.":configuration:sofia.conf");
|
||||
$cache->delete($sip_profile_hostname . ":configuration:sofia.conf");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -345,10 +297,21 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Deletes settings for one or more sip profiles.
|
||||
*
|
||||
* @param array $records An associative array containing the records to delete, where each record is an associative array
|
||||
* with 'uuid' and optionally 'checked' keys. Defaults to an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
public function delete_settings($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'sip_profile_setting_';
|
||||
$this->list_page = 'sip_profile_edit.php?id=' . $this->sip_profile_uuid;
|
||||
$this->table = 'sip_profile_settings';
|
||||
$this->uuid_prefix = 'sip_profile_setting_';
|
||||
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -357,8 +320,82 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
//delete multiple records
|
||||
if (!empty($records) && @sizeof($records) != 0) {
|
||||
|
||||
//filter out unchecked sip profiles, build the delete array
|
||||
foreach ($records as $x => $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]['sip_profile_uuid'] = $this->sip_profile_uuid;
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary sip profile details
|
||||
if (!empty($this->sip_profile_uuid) && is_uuid($this->sip_profile_uuid)) {
|
||||
$sql = "select sip_profile_hostname from v_sip_profiles ";
|
||||
$sql .= "where sip_profile_uuid = :sip_profile_uuid ";
|
||||
$parameters['sip_profile_uuid'] = $this->sip_profile_uuid;
|
||||
$sip_profile_hostname = $this->database->select($sql, $parameters, 'column');
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
//delete the checked rows
|
||||
if (!empty($array) && @sizeof($array) != 0) {
|
||||
|
||||
//execute delete
|
||||
$this->database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//save the sip profile xml
|
||||
save_sip_profile_xml();
|
||||
|
||||
//apply settings reminder
|
||||
$_SESSION["reload_xml"] = true;
|
||||
|
||||
//get system hostname if necessary
|
||||
if (empty($sip_profile_hostname)) {
|
||||
$sip_profile_hostname = gethostname();
|
||||
}
|
||||
|
||||
//clear the cache
|
||||
if (!empty($sip_profile_hostname)) {
|
||||
$cache = new cache;
|
||||
$cache->delete($sip_profile_hostname . ":configuration:sofia.conf");
|
||||
}
|
||||
|
||||
}
|
||||
unset($records);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
@@ -368,12 +405,12 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, sip_profile_hostname from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, sip_profile_hostname from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -387,7 +424,7 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($sip_profiles as $uuid => $sip_profile) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $sip_profile['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -405,8 +442,7 @@
|
||||
foreach ($sip_profiles as $sip_profile_uuid => $sip_profile) {
|
||||
if ($sip_profile['hostname'] != '') {
|
||||
$hostnames[] = $sip_profile['hostname'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$empty_hostname = true;
|
||||
}
|
||||
}
|
||||
@@ -422,7 +458,7 @@
|
||||
$hostnames = array_unique($hostnames);
|
||||
$cache = new cache;
|
||||
foreach ($hostnames as $hostname) {
|
||||
$cache->delete($hostname.":configuration:sofia.conf");
|
||||
$cache->delete($hostname . ":configuration:sofia.conf");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,4 +477,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,14 @@
|
||||
}
|
||||
|
||||
//sort the array
|
||||
/**
|
||||
* Compares two XML elements based on their names and sorts them in a natural order.
|
||||
*
|
||||
* @param object $a The first XML element to compare.
|
||||
* @param object $b The second XML element to compare.
|
||||
*
|
||||
* @return int A negative integer, zero, or a positive integer if $a's name is less than, equal to, or greater than $b's name respectively.
|
||||
*/
|
||||
function sort_xml($a, $b) {
|
||||
return strnatcmp($a->name, $b->name);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/**
|
||||
* sofia_global_settings class
|
||||
*/
|
||||
class sofia_global_settings {
|
||||
class sofia_global_settings {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -48,7 +48,12 @@
|
||||
private $location;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set objects
|
||||
@@ -58,16 +63,22 @@
|
||||
$this->name = 'sofia_global_setting';
|
||||
$this->table = 'sofia_global_settings';
|
||||
$this->toggle_field = 'global_setting_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
$this->description_field = 'global_setting_description';
|
||||
$this->location = 'sofia_global_settings.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* delete rows from the database
|
||||
* Deletes one or more 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->name.'_delete')) {
|
||||
if (permission_exists($this->name . '_delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -76,8 +87,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -110,10 +121,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle a field between two values
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->name.'_edit')) {
|
||||
if (permission_exists($this->name . '_edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -122,22 +139,22 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
//toggle the checked records
|
||||
if (!empty($records) && @sizeof($records) != 0) {
|
||||
//get current toggle state
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) {
|
||||
$uuids[] = "'".$record['sofia_global_setting_uuid']."'";
|
||||
$uuids[] = "'" . $record['sofia_global_setting_uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (!empty($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->name . "_uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->name . "_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, null, 'all');
|
||||
if (!empty($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -149,9 +166,9 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
foreach ($states as $uuid => $state) {
|
||||
//create the array
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
|
||||
//increment the id
|
||||
@@ -174,10 +191,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy rows from the database
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->name.'_add')) {
|
||||
if (permission_exists($this->name . '_add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -186,8 +209,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->location);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->location);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -195,16 +218,16 @@
|
||||
if (!empty($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $record) {
|
||||
foreach ($records as $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['sofia_global_setting_uuid'])) {
|
||||
$uuids[] = "'".$record['sofia_global_setting_uuid']."'";
|
||||
$uuids[] = "'" . $record['sofia_global_setting_uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create the array from existing data
|
||||
if (!empty($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where sofia_global_setting_uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where sofia_global_setting_uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, null, 'all');
|
||||
if (!empty($rows) && @sizeof($rows) != 0) {
|
||||
$x = 0;
|
||||
@@ -213,9 +236,9 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//add copy to the description
|
||||
$array[$this->table][$x][$this->name.'_uuid'] = uuid();
|
||||
$array[$this->table][$x][$this->name . '_uuid'] = uuid();
|
||||
$array[$this->table][$x]['global_setting_enabled'] = $row['global_setting_enabled'] === true ? 'true' : 'false';
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field] ?? '').trim(' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->description_field] = trim($row[$this->description_field] ?? '') . trim(' (' . $text['label-copy'] . ')');
|
||||
|
||||
//increment the id
|
||||
$x++;
|
||||
@@ -239,4 +262,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the streams class
|
||||
class streams {
|
||||
class streams {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,36 +35,46 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Username 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 $username;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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 name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -80,7 +90,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -95,14 +110,20 @@
|
||||
$this->table = 'streams';
|
||||
$this->uuid_prefix = 'stream_';
|
||||
$this->toggle_field = 'stream_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -111,8 +132,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -122,7 +143,7 @@
|
||||
//build the delete array
|
||||
foreach ($records as $x => $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][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,10 +163,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -154,8 +181,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -165,13 +192,13 @@
|
||||
//get current toggle state
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -185,7 +212,7 @@
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -208,10 +235,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -220,8 +253,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -231,22 +264,22 @@
|
||||
//get checked records
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//create insert array from existing data
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $x => $row) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -257,8 +290,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = uuid();
|
||||
$array[$this->table][$x]['stream_description'] = trim($row['stream_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = uuid();
|
||||
$array[$this->table][$x]['stream_description'] = trim($row['stream_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -283,4 +316,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,14 @@
|
||||
/**
|
||||
* presence class
|
||||
*/
|
||||
class presence {
|
||||
class presence {
|
||||
|
||||
/**
|
||||
* active presence
|
||||
* @var string $presence_id
|
||||
* Check if presence is active
|
||||
*
|
||||
* @param string $presence_id Presence ID to check for activity
|
||||
*
|
||||
* @return bool True if presence is active, False otherwise
|
||||
*/
|
||||
public function active($presence_id) {
|
||||
$json = event_socket::api('show calls as json');
|
||||
@@ -54,7 +57,14 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* show presence
|
||||
* Retrieves and processes data from the event socket API.
|
||||
*
|
||||
* This method sends a 'show calls as json' request to the event socket API,
|
||||
* decodes the response, and returns an array containing presence information
|
||||
* for each user. The array is indexed by the index of the row in the original
|
||||
* JSON response, with keys for presence_id, presence_user, and domain_name.
|
||||
*
|
||||
* @return array An array of arrays containing presence information.
|
||||
*/
|
||||
public function show() {
|
||||
$array = [];
|
||||
@@ -79,11 +89,11 @@
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//examples
|
||||
/*
|
||||
//check if presence is active
|
||||
/*
|
||||
//check if presence is active
|
||||
$presence_id = '103@'.$_SESSION['domain_name'];
|
||||
$presence = new presence;
|
||||
$result = $presence->active($presence_id);
|
||||
@@ -94,7 +104,7 @@
|
||||
else {
|
||||
echo "active: false\n";
|
||||
}
|
||||
//show active the presence
|
||||
//show active the presence
|
||||
$presence = new presence;
|
||||
$array = $presence->show();
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
Matthew Vale <github@mafoo.org>
|
||||
*/
|
||||
|
||||
class ringbacks {
|
||||
class ringbacks {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -34,7 +34,9 @@
|
||||
const app_uuid = 'b63db353-e1c6-4401-8f10-101a6ee73b74';
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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
|
||||
*/
|
||||
public $domain_uuid;
|
||||
@@ -46,30 +48,38 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Username 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 $username;
|
||||
|
||||
/**
|
||||
* Domain name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -84,7 +94,12 @@
|
||||
private $streams;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -108,10 +123,9 @@
|
||||
if (!empty($ringtones)) {
|
||||
foreach ($ringtones as $ringtone) {
|
||||
$ringtone = $ringtone['var_name'];
|
||||
if (isset($text['label-'.$ringtone])) {
|
||||
$label = $text['label-'.$ringtone];
|
||||
}
|
||||
else {
|
||||
if (isset($text['label-' . $ringtone])) {
|
||||
$label = $text['label-' . $ringtone];
|
||||
} else {
|
||||
$label = $ringtone;
|
||||
}
|
||||
$ringtones_list[$ringtone] = $label;
|
||||
@@ -141,16 +155,16 @@
|
||||
$this->tones_list = $tones->tones_list();
|
||||
|
||||
//get music on hold and recordings
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"].'/app/music_on_hold')) {
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"] . '/app/music_on_hold')) {
|
||||
$music = new switch_music_on_hold;
|
||||
$this->music_list = $music->get();
|
||||
}
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"].'/app/recordings')) {
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"] . '/app/recordings')) {
|
||||
$recordings = new switch_recordings;
|
||||
$this->recordings_list = $recordings->list_recordings();
|
||||
}
|
||||
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"].'/app/streams')) {
|
||||
if (is_dir($_SERVER["PROJECT_ROOT"] . '/app/streams')) {
|
||||
$sql = "select * from v_streams ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and stream_enabled = 'true' ";
|
||||
@@ -162,37 +176,44 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given value is valid.
|
||||
*
|
||||
* @param mixed $value The value to check for validity
|
||||
*
|
||||
* @return bool True if the value is valid, false otherwise
|
||||
*/
|
||||
public function valid($value) {
|
||||
foreach($this->ringtones_list as $ringtone_value => $ringtone_name) {
|
||||
if ($value == "\${".$ringtone_value."}") {
|
||||
foreach ($this->ringtones_list as $ringtone_value => $ringtone_name) {
|
||||
if ($value == "\${" . $ringtone_value . "}") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->tones_list as $tone_value => $tone_name) {
|
||||
if ($value == "\${".$tone_value."}") {
|
||||
foreach ($this->tones_list as $tone_value => $tone_name) {
|
||||
if ($value == "\${" . $tone_value . "}") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->music_list as $row) {
|
||||
foreach ($this->music_list as $row) {
|
||||
$name = '';
|
||||
if (!empty($row['domain_uuid'])) {
|
||||
$name = $row['domain_name'].'/';
|
||||
$name = $row['domain_name'] . '/';
|
||||
}
|
||||
$name .= $row['music_on_hold_name'];
|
||||
if ($value == "local_stream://".$name) {
|
||||
if ($value == "local_stream://" . $name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->recordings_list as $recording_value => $recording_name) {
|
||||
foreach ($this->recordings_list as $recording_value => $recording_name) {
|
||||
if ($value == $recording_value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->streams as $row) {
|
||||
foreach ($this->streams as $row) {
|
||||
if ($value == $row['stream_location']) {
|
||||
return true;
|
||||
}
|
||||
@@ -201,27 +222,35 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a HTML <select> element based on given name and selected value.
|
||||
*
|
||||
* @param string $name The name of the select element
|
||||
* @param mixed $selected The currently selected value for the select element
|
||||
*
|
||||
* @return string A fully formed HTML <select> element with options populated from various lists (music, recordings, streams, ringtones, tones)
|
||||
*/
|
||||
public function select($name, $selected) {
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//start the select
|
||||
$select = "<select class='formfld' name='".$name."' id='".$name."' style='width: auto;'>\n";
|
||||
$select = "<select class='formfld' name='" . $name . "' id='" . $name . "' style='width: auto;'>\n";
|
||||
$select .= " <option value=''></option>\n";
|
||||
|
||||
//music list
|
||||
if (!empty($this->music_list)) {
|
||||
$select .= " <optgroup label='".$text['label-music_on_hold']."'>\n";
|
||||
$select .= " <optgroup label='" . $text['label-music_on_hold'] . "'>\n";
|
||||
$previous_name = '';
|
||||
foreach ($this->music_list as $row) {
|
||||
if ($previous_name != $row['music_on_hold_name']) {
|
||||
$name = '';
|
||||
if (!empty($row['domain_uuid'])) {
|
||||
$name = $row['domain_name'].'/';
|
||||
$name = $row['domain_name'] . '/';
|
||||
}
|
||||
$name .= $row['music_on_hold_name'];
|
||||
$select .= " <option value='local_stream://".$name."' ".(($selected == "local_stream://".$name) ? 'selected="selected"' : null).">".$row['music_on_hold_name']."</option>\n";
|
||||
$select .= " <option value='local_stream://" . $name . "' " . (($selected == "local_stream://" . $name) ? 'selected="selected"' : null) . ">" . $row['music_on_hold_name'] . "</option>\n";
|
||||
}
|
||||
$previous_name = $row['music_on_hold_name'];
|
||||
}
|
||||
@@ -230,18 +259,18 @@
|
||||
|
||||
//recordings
|
||||
if (!empty($this->recordings_list)) {
|
||||
$select .= " <optgroup label='".$text['label-recordings']."'>";
|
||||
$select .= " <optgroup label='" . $text['label-recordings'] . "'>";
|
||||
foreach ($this->recordings_list as $recording_value => $recording_name) {
|
||||
$select .= " <option value='".$recording_value."' ".(($selected == $recording_value) ? 'selected="selected"' : null).">".$recording_name."</option>\n";
|
||||
$select .= " <option value='" . $recording_value . "' " . (($selected == $recording_value) ? 'selected="selected"' : null) . ">" . $recording_name . "</option>\n";
|
||||
}
|
||||
$select .= " </optgroup>\n";
|
||||
}
|
||||
|
||||
//streams
|
||||
if (!empty($this->streams)) {
|
||||
$select .= " <optgroup label='".$text['label-streams']."'>";
|
||||
$select .= " <optgroup label='" . $text['label-streams'] . "'>";
|
||||
foreach ($this->streams as $row) {
|
||||
$select .= " <option value='".$row['stream_location']."' ".(($selected == $row['stream_location']) ? 'selected="selected"' : null).">".$row['stream_name']."</option>\n";
|
||||
$select .= " <option value='" . $row['stream_location'] . "' " . (($selected == $row['stream_location']) ? 'selected="selected"' : null) . ">" . $row['stream_name'] . "</option>\n";
|
||||
}
|
||||
$select .= " </optgroup>\n";
|
||||
}
|
||||
@@ -249,12 +278,12 @@
|
||||
//ringtones
|
||||
if (!empty($this->ringtones_list)) {
|
||||
$selected_ringtone = $selected;
|
||||
$selected_ringtone = preg_replace('/\A\${/',"",$selected_ringtone ?? '');
|
||||
$selected_ringtone = preg_replace('/}\z/',"",$selected_ringtone);
|
||||
$select .= " <optgroup label='".$text['label-ringtones']."'>";
|
||||
$selected_ringtone = preg_replace('/\A\${/', "", $selected_ringtone ?? '');
|
||||
$selected_ringtone = preg_replace('/}\z/', "", $selected_ringtone);
|
||||
$select .= " <optgroup label='" . $text['label-ringtones'] . "'>";
|
||||
//$select .= " <option value='default_ringtones'".(($selected == "default_ringback") ? ' selected="selected"' : '').">".$text['label-default']." (".$this->default_ringtone_label.")</option>\n";
|
||||
foreach ($this->ringtones_list as $ringtone_value => $ringtone_name) {
|
||||
$select .= " <option value='\${".$ringtone_value."}'".(($selected_ringtone == $ringtone_value) ? ' selected="selected"' : null).">".$ringtone_name."</option>\n";
|
||||
$select .= " <option value='\${" . $ringtone_value . "}'" . (($selected_ringtone == $ringtone_value) ? ' selected="selected"' : null) . ">" . $ringtone_name . "</option>\n";
|
||||
}
|
||||
//add silence option
|
||||
$select .= " <option value='silence'>Silence</option>\n";
|
||||
@@ -265,11 +294,11 @@
|
||||
//tones
|
||||
if (!empty($this->tones_list)) {
|
||||
$selected_tone = $selected;
|
||||
$selected_tone = preg_replace('/\A\${/',"",$selected_tone ?? '');
|
||||
$selected_tone = preg_replace('/}\z/',"",$selected_tone);
|
||||
$select .= " <optgroup label='".$text['label-tones']."'>";
|
||||
foreach($this->tones_list as $tone_value => $tone_name) {
|
||||
$select .= " <option value='\${".$tone_value."}'".(($selected_tone == $tone_value) ? ' selected="selected"' : null).">".$tone_name."</option>\n";
|
||||
$selected_tone = preg_replace('/\A\${/', "", $selected_tone ?? '');
|
||||
$selected_tone = preg_replace('/}\z/', "", $selected_tone);
|
||||
$select .= " <optgroup label='" . $text['label-tones'] . "'>";
|
||||
foreach ($this->tones_list as $tone_value => $tone_name) {
|
||||
$select .= " <option value='\${" . $tone_value . "}'" . (($selected_tone == $tone_value) ? ' selected="selected"' : null) . ">" . $tone_name . "</option>\n";
|
||||
}
|
||||
$select .= " </optgroup>\n";
|
||||
unset($selected_tone);
|
||||
@@ -279,4 +308,4 @@
|
||||
$select .= "</select>\n";
|
||||
return $select;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,17 @@
|
||||
/**
|
||||
* switch class provides methods for copying switch_files
|
||||
*/
|
||||
class switch_files {
|
||||
class switch_files {
|
||||
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set objects
|
||||
@@ -40,12 +45,20 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Corrects the path for specifically for windows
|
||||
* Converts the given path to a platform-agnostic format.
|
||||
*
|
||||
* @param string $path The path to be converted.
|
||||
*
|
||||
* @return string The converted path. If running on Windows, backslashes are replaced with forward slashes.
|
||||
*/
|
||||
private function correct_path($path) {
|
||||
global $IS_WINDOWS;
|
||||
if ($IS_WINDOWS == null) {
|
||||
if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; }
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
$IS_WINDOWS = true;
|
||||
} else {
|
||||
$IS_WINDOWS = false;
|
||||
}
|
||||
}
|
||||
if ($IS_WINDOWS) {
|
||||
return str_replace('\\', '/', $path);
|
||||
@@ -55,31 +68,31 @@
|
||||
|
||||
/**
|
||||
* Copy the switch scripts to the switch directory
|
||||
*
|
||||
* The function attempts to find the source and destination directories by checking various system locations. If
|
||||
* neither is found, it throws an exception.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function copy_scripts() {
|
||||
|
||||
//get the source directory
|
||||
if (file_exists('/usr/share/examples/fusionpbx/scripts')) {
|
||||
$source_directory = '/usr/share/examples/fusionpbx/scripts';
|
||||
}
|
||||
elseif (file_exists('/usr/local/www/fusionpbx/app/switch/resources/scripts')) {
|
||||
} elseif (file_exists('/usr/local/www/fusionpbx/app/switch/resources/scripts')) {
|
||||
$source_directory = '/usr/local/www/fusionpbx/app/switch/resources/scripts';
|
||||
}
|
||||
elseif (file_exists('/var/www/fusionpbx/app/switch/resources/scripts')) {
|
||||
} elseif (file_exists('/var/www/fusionpbx/app/switch/resources/scripts')) {
|
||||
$source_directory = '/var/www/fusionpbx/app/switch/resources/scripts';
|
||||
}
|
||||
else {
|
||||
$source_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/switch/resources/scripts';
|
||||
} else {
|
||||
$source_directory = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/app/switch/resources/scripts';
|
||||
}
|
||||
|
||||
//get the destination directory
|
||||
if (file_exists($this->config->get('switch.scripts.dir'))) {
|
||||
$destination_directory = $this->config->get('switch.scripts.dir');
|
||||
}
|
||||
elseif (file_exists('/etc/freeswitch/scripts')) {
|
||||
} elseif (file_exists('/etc/freeswitch/scripts')) {
|
||||
$destination_directory = '/etc/freeswitch/scripts';
|
||||
}
|
||||
elseif (file_exists('/usr/local/freeswitch/scripts')) {
|
||||
} elseif (file_exists('/usr/local/freeswitch/scripts')) {
|
||||
$destination_directory = '/usr/local/freeswitch/scripts';
|
||||
}
|
||||
|
||||
@@ -90,13 +103,12 @@
|
||||
unset($source_directory);
|
||||
|
||||
//copy the app/*/resource/install/scripts
|
||||
$app_scripts = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'app/*/resource/scripts');
|
||||
$app_scripts = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . 'app/*/resource/scripts');
|
||||
foreach ($app_scripts as $app_script) {
|
||||
recursive_copy($app_script, $destination_directory);
|
||||
}
|
||||
unset($app_scripts);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Exception("Cannot read from '$source_directory' to get the scripts");
|
||||
}
|
||||
chmod($destination_directory, 0775);
|
||||
@@ -104,34 +116,30 @@
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy the switch languages to the switch directory
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function copy_languages() {
|
||||
|
||||
//get the source directory
|
||||
if (file_exists('/usr/share/examples/freeswitch/conf/languages')) {
|
||||
$source_directory = '/usr/share/examples/fusionpbx/conf/languages';
|
||||
}
|
||||
elseif (file_exists('/usr/local/www/fusionpbx/app/switch/resources/conf/languages')) {
|
||||
} elseif (file_exists('/usr/local/www/fusionpbx/app/switch/resources/conf/languages')) {
|
||||
$source_directory = '/usr/local/www/fusionpbx/app/switch/resources/conf/languages';
|
||||
}
|
||||
elseif (file_exists('/var/www/fusionpbx/app/switch/resources/conf/languages')) {
|
||||
} elseif (file_exists('/var/www/fusionpbx/app/switch/resources/conf/languages')) {
|
||||
$source_directory = '/var/www/fusionpbx/app/switch/resources/conf/languages';
|
||||
}
|
||||
else {
|
||||
$source_directory = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/switch/resources/conf/languages';
|
||||
} else {
|
||||
$source_directory = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/app/switch/resources/conf/languages';
|
||||
}
|
||||
|
||||
//get the destination directory
|
||||
if (file_exists($this->config->get('switch.conf.dir').'/languages')) {
|
||||
$destination_directory = $this->config->get('switch.conf.dir').'/languages';
|
||||
}
|
||||
elseif (file_exists('/etc/freeswitch/languages')) {
|
||||
if (file_exists($this->config->get('switch.conf.dir') . '/languages')) {
|
||||
$destination_directory = $this->config->get('switch.conf.dir') . '/languages';
|
||||
} elseif (file_exists('/etc/freeswitch/languages')) {
|
||||
$destination_directory = '/usr/local/share/freeswitch/languages';
|
||||
}
|
||||
elseif (file_exists('/usr/local/freeswitch/conf/languages')) {
|
||||
} elseif (file_exists('/usr/local/freeswitch/conf/languages')) {
|
||||
$destination_directory = '/usr/local/freeswitch/conf/languages';
|
||||
}
|
||||
|
||||
@@ -140,8 +148,7 @@
|
||||
//copy the main languages
|
||||
recursive_copy($source_directory, $destination_directory);
|
||||
unset($source_directory);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Exception("Cannot read from '$source_directory' to get the scripts");
|
||||
}
|
||||
chmod($destination_directory, 0775);
|
||||
@@ -149,7 +156,7 @@
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//example use
|
||||
|
||||
@@ -95,6 +95,13 @@
|
||||
}
|
||||
|
||||
//define the download function (helps safari play audio sources)
|
||||
/**
|
||||
* Downloads a specified range of bytes from the given file.
|
||||
*
|
||||
* @param string $file The path to the file to download.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function range_download($file) {
|
||||
$fp = @fopen($file, 'rb');
|
||||
|
||||
@@ -123,7 +130,7 @@
|
||||
$c_start = $start;
|
||||
$c_end = $end;
|
||||
// Extract the range string
|
||||
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
// Make sure the client hasn't sent us a multibyte range
|
||||
if (strpos($range, ',') !== false) {
|
||||
// (?) Shoud this be issued here, or should the first
|
||||
|
||||
@@ -31,6 +31,11 @@
|
||||
*/
|
||||
class bsd_system_information extends system_information {
|
||||
|
||||
/**
|
||||
* Returns the number of CPU cores available on the system.
|
||||
*
|
||||
* @return int The number of CPU cores.
|
||||
*/
|
||||
public function get_cpu_cores(): int {
|
||||
$result = shell_exec("dmesg | grep -i --max-count 1 CPUs | sed 's/[^0-9]*//g'");
|
||||
$cpu_cores = trim($result);
|
||||
@@ -38,6 +43,12 @@ class bsd_system_information extends system_information {
|
||||
}
|
||||
|
||||
//get the CPU details
|
||||
|
||||
/**
|
||||
* Returns the current CPU usage percentage.
|
||||
*
|
||||
* @return float The current CPU usage percentage.
|
||||
*/
|
||||
public function get_cpu_percent(): float {
|
||||
$result = shell_exec('ps -A -o pcpu');
|
||||
$percent_cpu = 0;
|
||||
@@ -49,10 +60,20 @@ class bsd_system_information extends system_information {
|
||||
return $percent_cpu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the system uptime in seconds.
|
||||
*
|
||||
* @return string The system uptime in seconds.
|
||||
*/
|
||||
public function get_uptime() {
|
||||
return shell_exec('uptime');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current CPU usage percentage per core.
|
||||
*
|
||||
* @return array An associative array where keys are core indices and values are their respective CPU usage percentages.
|
||||
*/
|
||||
public function get_cpu_percent_per_core(): array {
|
||||
static $last = [];
|
||||
$results = [];
|
||||
@@ -94,11 +115,11 @@ class bsd_system_information extends system_information {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current network speed for a given interface.
|
||||
*
|
||||
* @staticvar array $last
|
||||
* @param string $interface
|
||||
* @return array
|
||||
* @depends FreeBSD Version 12
|
||||
* @param string $interface The network interface to query (default: 'em0')
|
||||
*
|
||||
* @return array An array containing the current receive and transmit speeds in bytes per second.
|
||||
*/
|
||||
public function get_network_speed(string $interface = 'em0'): array {
|
||||
static $last = [];
|
||||
|
||||
@@ -31,6 +31,13 @@
|
||||
*/
|
||||
class linux_system_information extends system_information {
|
||||
|
||||
/**
|
||||
* Returns the number of CPU cores available on the system.
|
||||
*
|
||||
* This method executes a shell command to parse the /proc/cpuinfo file and counts the number of processor entries found.
|
||||
*
|
||||
* @return int The total number of CPU cores
|
||||
*/
|
||||
public function get_cpu_cores(): int {
|
||||
$result = @trim(shell_exec("grep -P '^processor' /proc/cpuinfo"));
|
||||
$cpu_cores = count(explode("\n", $result));
|
||||
@@ -38,6 +45,16 @@ class linux_system_information extends system_information {
|
||||
}
|
||||
|
||||
//get the CPU details
|
||||
|
||||
/**
|
||||
* Returns the current CPU usage as a percentage.
|
||||
*
|
||||
* This method reads the CPU statistics from /proc/stat and calculates
|
||||
* the CPU usage by comparing the total and idle time of each core.
|
||||
* The result is rounded to two decimal places.
|
||||
*
|
||||
* @return float The current CPU usage in percent.
|
||||
*/
|
||||
public function get_cpu_percent(): float {
|
||||
$stat1 = file_get_contents('/proc/stat');
|
||||
usleep(500000);
|
||||
@@ -73,10 +90,27 @@ class linux_system_information extends system_information {
|
||||
return round($percent_cpu / $core_count, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current system uptime as reported by the 'uptime' command.
|
||||
*
|
||||
* This method executes the 'uptime' command and returns its output.
|
||||
*
|
||||
* @return string The current system uptime.
|
||||
*/
|
||||
public function get_uptime() {
|
||||
return shell_exec('uptime');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current CPU usage as a percentage per core.
|
||||
*
|
||||
* This method reads the CPU statistics from /proc/stat and calculates
|
||||
* the CPU usage by comparing the total and idle time of each core.
|
||||
* The result is rounded to two decimal places.
|
||||
*
|
||||
* @return array An array where the keys are the core numbers (starting at 0)
|
||||
* and the values are the current CPU usage for each core in percent.
|
||||
*/
|
||||
public function get_cpu_percent_per_core(): array {
|
||||
static $last = [];
|
||||
|
||||
@@ -107,6 +141,16 @@ class linux_system_information extends system_information {
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current network speed for the specified interface.
|
||||
*
|
||||
* This method reads the network statistics from /proc/net/dev and calculates
|
||||
* the network speed by comparing the received and transmitted bytes between two measurements.
|
||||
*
|
||||
* @param string $interface The network interface to read stats from. Defaults to 'eth0'.
|
||||
*
|
||||
* @return array An array containing the current receive (rx_bps) and transmit (tx_bps) speeds in bits per second.
|
||||
*/
|
||||
public function get_network_speed(string $interface = 'eth0'): array {
|
||||
static $last = [];
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ class session {
|
||||
|
||||
/**
|
||||
* Removes old php session files. Called by the maintenance application.
|
||||
*
|
||||
* @param settings $settings A settings object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function filesystem_maintenance(settings $settings): void {
|
||||
|
||||
@@ -38,6 +38,11 @@ class system_dashboard_service extends base_websocket_system_service {
|
||||
private $network_status_refresh_interval;
|
||||
private $network_interface;
|
||||
|
||||
/**
|
||||
* Reloads settings from database, config file and websocket server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function reload_settings(): void {
|
||||
static::set_system_information();
|
||||
|
||||
@@ -64,8 +69,12 @@ class system_dashboard_service extends base_websocket_system_service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes once
|
||||
* @return void
|
||||
* Registers topics for broadcasting system information.
|
||||
*
|
||||
* This method is responsible for setting up the system information object,
|
||||
* registering callback functions for cpu and network status requests, and
|
||||
* configuring timer callbacks to refresh these statuses at regular intervals.
|
||||
* It is only called once during initial startup.
|
||||
*/
|
||||
protected function register_topics(): void {
|
||||
|
||||
@@ -90,6 +99,17 @@ class system_dashboard_service extends base_websocket_system_service {
|
||||
$this->info("Broadcasting Network Status every {$this->network_status_refresh_interval}s");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the network status request.
|
||||
*
|
||||
* This method retrieves the current network interface and speeds, constructs a response message,
|
||||
* logs the request for debugging purposes, and attempts to send the broadcast. If the Websocket server
|
||||
* is disconnected, it waits until reconnection before attempting to send again.
|
||||
*
|
||||
* @param string|null $message The original message that triggered this response (optional).
|
||||
*
|
||||
* @return int The refresh interval for network status in seconds.
|
||||
*/
|
||||
public function on_network_status($message = null): int {
|
||||
// Get RX (receive) and TX (transmit) bps
|
||||
$network_rates = self::$system_information->get_network_speed($this->network_interface);
|
||||
@@ -134,6 +154,15 @@ class system_dashboard_service extends base_websocket_system_service {
|
||||
return $this->network_status_refresh_interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the selection of a network interface from a message.
|
||||
*
|
||||
* This method checks if the message is an instance of WebSocketMessage and if it contains
|
||||
* a 'network_interface' payload. If both conditions are true, it sets the network interface
|
||||
* property to the value of the payload.
|
||||
*
|
||||
* @param websocket_message|null $message The message containing the selected network interface.
|
||||
*/
|
||||
public function on_network_interface_select($message = null): void {
|
||||
if ($message !== null && $message instanceof websocket_message) {
|
||||
$payload = $message->payload();
|
||||
@@ -143,6 +172,17 @@ class system_dashboard_service extends base_websocket_system_service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles cpu status requests.
|
||||
*
|
||||
* This method is called to respond to incoming requests for the current CPU usage,
|
||||
* both total and per-core. It prepares a response message with the requested data
|
||||
* and sends it to all connected clients.
|
||||
*
|
||||
* @param null|websocket_message $message The request message, if responding to a specific request.
|
||||
*
|
||||
* @return int The interval at which this method should be called again to refresh the cpu status.
|
||||
*/
|
||||
public function on_cpu_status($message = null): int {
|
||||
// Get total and per-core CPU usage
|
||||
$cpu_percent_total = self::$system_information->get_cpu_percent();
|
||||
@@ -192,10 +232,27 @@ class system_dashboard_service extends base_websocket_system_service {
|
||||
return $this->cpu_status_refresh_interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the service name for system information.
|
||||
*
|
||||
* This method provides a unique identifier for the dashboard system information service.
|
||||
*
|
||||
* @return string The service name as a string, in this case "dashboard.system.information".
|
||||
*/
|
||||
public static function get_service_name(): string {
|
||||
return "dashboard.system.information";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a filter chain for broadcasting system information.
|
||||
*
|
||||
* This method generates a filter based on the subscriber's permissions,
|
||||
* allowing them to receive only relevant system view information.
|
||||
*
|
||||
* @param subscriber $subscriber The subscriber object with permission data.
|
||||
*
|
||||
* @return ?filter A filter chain that matches the subscriber's permissions, or null if no match is found.
|
||||
*/
|
||||
public static function create_filter_chain_for(subscriber $subscriber): ?filter {
|
||||
// Get the subscriber permissions
|
||||
$permissions = $subscriber->get_permissions();
|
||||
@@ -216,6 +273,15 @@ class system_dashboard_service extends base_websocket_system_service {
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the system information object.
|
||||
*
|
||||
* This method creates a new instance of `SystemInformation` and stores it in
|
||||
* the class's static property `$system_information`. It is typically called once
|
||||
* during initial startup to establish the system information source.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function set_system_information(): void {
|
||||
self::$system_information = system_information::new();
|
||||
}
|
||||
|
||||
@@ -37,10 +37,20 @@ abstract class system_information {
|
||||
abstract public function get_cpu_percent_per_core(): array;
|
||||
abstract public function get_network_speed(string $interface = 'eth0'): array;
|
||||
|
||||
/**
|
||||
* Returns the system load average.
|
||||
*
|
||||
* @return array Three most recent one-minute load averages.
|
||||
*/
|
||||
public function get_load_average() {
|
||||
return sys_getloadavg();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a system information object based on the underlying operating system.
|
||||
*
|
||||
* @return ?system_information The system information object for the current OS, or null if not supported.
|
||||
*/
|
||||
public static function new(): ?system_information {
|
||||
if (stristr(PHP_OS, 'BSD')) {
|
||||
return new bsd_system_information();
|
||||
|
||||
@@ -38,6 +38,13 @@
|
||||
|
||||
//function to parse a FusionPBX service from a .service file
|
||||
if (!function_exists('get_classname')) {
|
||||
/**
|
||||
* Retrieves the name of a PHP class from an ExecStart directive in a service file.
|
||||
*
|
||||
* @param string $file Path to the service file.
|
||||
*
|
||||
* @return string The name of the PHP class, or empty string if not found.
|
||||
*/
|
||||
function get_classname(string $file) {
|
||||
if (!file_exists($file)) {
|
||||
return '';
|
||||
@@ -55,6 +62,14 @@
|
||||
|
||||
//function to check for running process: returns [running, pid, etime]
|
||||
if (!function_exists('is_running')) {
|
||||
/**
|
||||
* Checks if a process with the given name is currently running.
|
||||
*
|
||||
* @param string $name The name of the process to check for.
|
||||
*
|
||||
* @return array An array containing information about the process's status,
|
||||
* including whether it's running, its PID, and how long it's been running.
|
||||
*/
|
||||
function is_running(string $name) {
|
||||
$name = escapeshellarg($name);
|
||||
$pid = trim(shell_exec("ps -aux | grep $name | grep -v grep | awk '{print \$2}' | head -n 1") ?? '');
|
||||
@@ -68,6 +83,21 @@
|
||||
|
||||
//function to format etime into friendly display
|
||||
if (!function_exists('format_etime')) {
|
||||
/**
|
||||
* Formats a time duration string into a human-readable format.
|
||||
*
|
||||
* The input string can be in one of the following formats:
|
||||
* - dd-hh:mm:ss
|
||||
* - hh:mm:ss
|
||||
* - mm:ss
|
||||
* - seconds (no units)
|
||||
*
|
||||
* If the input string is empty or invalid, an empty string will be returned.
|
||||
*
|
||||
* @param string $etime Time duration string to format.
|
||||
*
|
||||
* @return string Formatted time duration string in human-readable format.
|
||||
*/
|
||||
function format_etime($etime) {
|
||||
// Format: [[dd-]hh:]mm:ss
|
||||
if (empty($etime)) return '-';
|
||||
|
||||
@@ -83,6 +83,14 @@
|
||||
//
|
||||
|
||||
//system information
|
||||
/**
|
||||
* Retrieves system information.
|
||||
*
|
||||
* @return array An array containing various system information such as PHP and switch versions,
|
||||
* git repository details, operating system name, version, uptime, kernel, and type,
|
||||
* memory usage, CPU usage, and disk space. The keys of the returned array are
|
||||
* 'version', 'git', 'path', 'switch', 'php', 'os', 'mem', and 'cpu'.
|
||||
*/
|
||||
function system_information(): array {
|
||||
global $database, $db_type;
|
||||
$system_information = [];
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the time conditions class
|
||||
class time_conditions {
|
||||
class time_conditions {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,36 +35,46 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_uuid;
|
||||
|
||||
/**
|
||||
* Username set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Username 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 $username;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* 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 name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -80,6 +90,14 @@
|
||||
private $toggle_values;
|
||||
private $dialplan_global;
|
||||
|
||||
/**
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
|
||||
@@ -96,14 +114,20 @@
|
||||
$this->table = 'dialplans';
|
||||
$this->uuid_prefix = 'dialplan_';
|
||||
$this->toggle_field = 'dialplan_enabled';
|
||||
$this->toggle_values = ['true','false'];
|
||||
$this->toggle_values = ['true', 'false'];
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -112,8 +136,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -125,7 +149,7 @@
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
|
||||
//build delete array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $record['uuid'];
|
||||
$array['dialplan_details'][$x]['dialplan_uuid'] = $record['uuid'];
|
||||
|
||||
//get the dialplan context
|
||||
@@ -158,7 +182,7 @@
|
||||
$dialplan_contexts = array_unique($dialplan_contexts, SORT_STRING);
|
||||
$cache = new cache;
|
||||
foreach ($dialplan_contexts as $dialplan_context) {
|
||||
$cache->delete("dialplan:".$dialplan_context);
|
||||
$cache->delete("dialplan:" . $dialplan_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +192,7 @@
|
||||
}
|
||||
|
||||
//set message
|
||||
message::add($text['message-delete'].': '.@sizeof($array[$this->table]));
|
||||
message::add($text['message-delete'] . ': ' . @sizeof($array[$this->table]));
|
||||
|
||||
}
|
||||
unset($records, $array);
|
||||
@@ -178,10 +202,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
if (permission_exists($this->permission_prefix . 'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -190,8 +220,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -199,15 +229,15 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get current toggle state
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, dialplan_context from v_".$this->table." ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, " . $this->toggle_field . " as toggle, dialplan_context from v_" . $this->table . " ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql .= "and " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$rows = $this->database->select($sql, $parameters, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
@@ -221,8 +251,8 @@
|
||||
|
||||
//build update array
|
||||
$x = 0;
|
||||
foreach($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
|
||||
foreach ($states as $uuid => $state) {
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $uuid;
|
||||
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
|
||||
$x++;
|
||||
}
|
||||
@@ -247,7 +277,7 @@
|
||||
$dialplan_contexts = array_unique($dialplan_contexts, SORT_STRING);
|
||||
$cache = new cache;
|
||||
foreach ($dialplan_contexts as $dialplan_context) {
|
||||
$cache->delete("dialplan:".$dialplan_context);
|
||||
$cache->delete("dialplan:" . $dialplan_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,10 +296,16 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
if (permission_exists($this->permission_prefix . 'add')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -278,8 +314,8 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -287,9 +323,9 @@
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//get checked records
|
||||
foreach($records as $x => $record) {
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,8 +333,8 @@
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
|
||||
//primary table
|
||||
$sql = "select * from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select * from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
$y = 0;
|
||||
@@ -306,7 +342,7 @@
|
||||
$primary_uuid = uuid();
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row as $key => $value) {
|
||||
foreach ($row as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row[$key] = $value;
|
||||
@@ -317,8 +353,8 @@
|
||||
$array[$this->table][$x] = $row;
|
||||
|
||||
//overwrite
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['dialplan_description'] = trim($row['dialplan_description'].' ('.$text['label-copy'].')');
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $primary_uuid;
|
||||
$array[$this->table][$x]['dialplan_description'] = trim($row['dialplan_description'] . ' (' . $text['label-copy'] . ')');
|
||||
|
||||
//details sub table
|
||||
$sql_2 = "select * from v_dialplan_details where dialplan_uuid = :dialplan_uuid";
|
||||
@@ -328,7 +364,7 @@
|
||||
foreach ($rows_2 as $row_2) {
|
||||
|
||||
//convert boolean values to a string
|
||||
foreach($row_2 as $key => $value) {
|
||||
foreach ($row_2 as $key => $value) {
|
||||
if (gettype($value) == 'boolean') {
|
||||
$value = $value ? 'true' : 'false';
|
||||
$row_2[$key] = $value;
|
||||
@@ -377,7 +413,7 @@
|
||||
$dialplan_contexts = array_unique($dialplan_contexts, SORT_STRING);
|
||||
$cache = new cache;
|
||||
foreach ($dialplan_contexts as $dialplan_context) {
|
||||
$cache->delete("dialplan:".$dialplan_context);
|
||||
$cache->delete("dialplan:" . $dialplan_context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,5 +427,4 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -990,6 +990,13 @@ echo " ".$text['description-extension']."<br />\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
/**
|
||||
* Adds a custom condition to the given group.
|
||||
*
|
||||
* @param object $destination The destination object being processed.
|
||||
* @param int $group_id The ID of the group to which the condition is being added.
|
||||
* @param string $dialplan_action The dialplan action for the group (optional).
|
||||
*/
|
||||
function add_custom_condition($destination, $group_id, $dialplan_action = '') {
|
||||
global $text, $v_link_label_add;
|
||||
echo "<tr>\n";
|
||||
|
||||
@@ -46,7 +46,12 @@
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set objects
|
||||
@@ -62,7 +67,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
@@ -111,7 +122,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
* Toggles the state of one or more 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 toggle($records) {
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
@@ -181,7 +198,13 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* copy records
|
||||
* Copies one or more 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 copy($records) {
|
||||
if (permission_exists($this->permission_prefix.'add')) {
|
||||
|
||||
@@ -105,8 +105,8 @@
|
||||
$param = $search ? "&search=".$search : null;
|
||||
$param = $order_by ? "&order_by=".$order_by."&order=".$order : null;
|
||||
$page = empty($_GET['page']) ? $page = 0 : $page = $_GET['page'];
|
||||
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
|
||||
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
|
||||
[$paging_controls, $rows_per_page] = paging($num_rows, $param, $rows_per_page);
|
||||
[$paging_controls_mini, $rows_per_page] = paging($num_rows, $param, $rows_per_page, true);
|
||||
$offset = $rows_per_page * $page;
|
||||
|
||||
//get the list
|
||||
@@ -191,6 +191,13 @@
|
||||
|
||||
echo "<div class='card'>\n";
|
||||
echo "<table class='list'>\n";
|
||||
/**
|
||||
* Writes the header for a list of variables.
|
||||
*
|
||||
* @param string $modifier The modifier to be used in the header, with slashes and extra spaces removed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function write_header($modifier) {
|
||||
global $text, $order_by, $order, $vars, $list_row_edit_button;
|
||||
$modifier = str_replace('/', '', $modifier);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
//define the voicemail greetings class
|
||||
class voicemail_greetings {
|
||||
class voicemail_greetings {
|
||||
|
||||
/**
|
||||
* declare constant variables
|
||||
@@ -35,30 +35,38 @@
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User 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 $user_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
|
||||
* 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 name set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain name 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_name;
|
||||
@@ -77,7 +85,12 @@
|
||||
public $voicemail_id;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
* Initializes the object with setting array.
|
||||
*
|
||||
* @param array $setting_array An array containing settings for domain, user, and database connections. Defaults to
|
||||
* an empty array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
@@ -92,20 +105,25 @@
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'voicemail_greeting_';
|
||||
if (is_numeric($this->voicemail_id)) {
|
||||
$this->list_page = 'voicemail_greetings.php?id='.urlencode($this->voicemail_id).'&back='.urlencode(PROJECT_PATH.'/app/voicemail/voicemails.php');
|
||||
}
|
||||
else {
|
||||
$this->list_page = PROJECT_PATH.'/app/voicemails/voicemails.php';
|
||||
$this->list_page = 'voicemail_greetings.php?id=' . urlencode($this->voicemail_id) . '&back=' . urlencode(PROJECT_PATH . '/app/voicemail/voicemails.php');
|
||||
} else {
|
||||
$this->list_page = PROJECT_PATH . '/app/voicemails/voicemails.php';
|
||||
}
|
||||
$this->table = 'voicemail_greetings';
|
||||
$this->uuid_prefix = 'voicemail_greeting_';
|
||||
}
|
||||
|
||||
/**
|
||||
* delete records
|
||||
* Deletes one or more 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')) {
|
||||
if (permission_exists($this->permission_prefix . 'delete')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
@@ -114,14 +132,14 @@
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
message::add($text['message-invalid_token'], 'negative');
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
//check voicemail id
|
||||
if (!is_numeric($this->voicemail_id)) {
|
||||
header('Location: '.$this->list_page);
|
||||
header('Location: ' . $this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -131,14 +149,14 @@
|
||||
//filter out unchecked records
|
||||
foreach ($records as $x => $record) {
|
||||
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$uuids[] = "'".$record['uuid']."'";
|
||||
$uuids[] = "'" . $record['uuid'] . "'";
|
||||
}
|
||||
}
|
||||
|
||||
//get necessary greeting details
|
||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||
$sql = "select ".$this->uuid_prefix."uuid as uuid, greeting_filename, greeting_id from v_".$this->table." ";
|
||||
$sql .= "where ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
|
||||
$sql = "select " . $this->uuid_prefix . "uuid as uuid, greeting_filename, greeting_id from v_" . $this->table . " ";
|
||||
$sql .= "where " . $this->uuid_prefix . "uuid in (" . implode(', ', $uuids) . ") ";
|
||||
$rows = $this->database->select($sql, $parameters ?? null, 'all');
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
@@ -150,16 +168,16 @@
|
||||
}
|
||||
|
||||
//set the greeting directory
|
||||
$greeting_directory = $this->settings->get('switch', 'storage').'/voicemail/default/'.$this->domain_name.'/'.$this->voicemail_id;
|
||||
$greeting_directory = $this->settings->get('switch', 'storage') . '/voicemail/default/' . $this->domain_name . '/' . $this->voicemail_id;
|
||||
|
||||
//loop through greetings
|
||||
if (is_array($greeting_filenames) && @sizeof($greeting_filenames) != 0) {
|
||||
$x = 0;
|
||||
foreach ($greeting_filenames as $voicemail_greeting_uuid => $greeting_filename) {
|
||||
//delete the recording file
|
||||
@unlink($greeting_directory.'/'.$greeting_filename);
|
||||
@unlink($greeting_directory . '/' . $greeting_filename);
|
||||
//build the delete array
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $voicemail_greeting_uuid;
|
||||
$array[$this->table][$x][$this->uuid_prefix . 'uuid'] = $voicemail_greeting_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $this->domain_uuid;
|
||||
$x++;
|
||||
}
|
||||
@@ -196,4 +214,4 @@
|
||||
}
|
||||
} //method
|
||||
|
||||
} //class
|
||||
} //class
|
||||
|
||||
@@ -62,6 +62,13 @@
|
||||
}
|
||||
|
||||
//used (above) to search the array to determine if an extension is assigned to the user
|
||||
/**
|
||||
* Checks if the given extension number is assigned to the user.
|
||||
*
|
||||
* @param string $number The extension number to check.
|
||||
*
|
||||
* @return bool True if the extension number is assigned, False otherwise.
|
||||
*/
|
||||
function extension_assigned($number) {
|
||||
foreach ($_SESSION['user']['extension'] as $row) {
|
||||
if ((is_numeric($row['number_alias']) && $row['number_alias'] == $number) || $row['user'] == $number) {
|
||||
@@ -506,6 +513,11 @@
|
||||
require_once "resources/footer.php";
|
||||
|
||||
//define the download function (helps safari play audio sources)
|
||||
/**
|
||||
* Handles a range download request for the given file.
|
||||
*
|
||||
* @param string $file The path to the file being downloaded.
|
||||
*/
|
||||
function range_download($file) {
|
||||
$fp = @fopen($file, 'rb');
|
||||
|
||||
@@ -534,7 +546,7 @@
|
||||
$c_start = $start;
|
||||
$c_end = $end;
|
||||
// Extract the range string
|
||||
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
[, $range] = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
||||
// Make sure the client hasn't sent us a multibyte range
|
||||
if (strpos($range, ',') !== false) {
|
||||
// (?) Shoud this be issued here, or should the first
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -61,6 +61,13 @@
|
||||
$available_columns[] = 'voicemail_tutorial';
|
||||
|
||||
//define the functions
|
||||
/**
|
||||
* Converts a 2D array into a CSV string.
|
||||
*
|
||||
* @param array &$array The input array to convert. Each inner array represents a row in the CSV output.
|
||||
*
|
||||
* @return string|null The CSV data as a string, or null if the input array is empty.
|
||||
*/
|
||||
function array2csv(array &$array) {
|
||||
if (count($array) == 0) {
|
||||
return null;
|
||||
@@ -75,6 +82,13 @@
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends HTTP headers to initiate a file download.
|
||||
*
|
||||
* @param string $filename The name of the file to be downloaded.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function download_send_headers($filename) {
|
||||
// disable caching
|
||||
$now = gmdate("D, d M Y H:i:s");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -230,7 +218,15 @@
|
||||
}
|
||||
|
||||
//get the parent table
|
||||
function get_parent($schema,$table_name) {
|
||||
/**
|
||||
* Retrieves the parent table for a given table name from a schema.
|
||||
*
|
||||
* @param array $schema A multidimensional array representing the schema of tables.
|
||||
* @param string $table_name The name of the table to retrieve the parent for.
|
||||
*
|
||||
* @return string|null The name of the parent table, or null if not found in the schema.
|
||||
*/
|
||||
function get_parent($schema, $table_name) {
|
||||
foreach ($schema as $row) {
|
||||
if ($row['table'] == $table_name) {
|
||||
return $row['parent'];
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user