Skip to content

Commit

Permalink
Create database object if not set. (#6492)
Browse files Browse the repository at this point in the history
* Create database object if not set.
  • Loading branch information
markjcrane committed Nov 8, 2022
1 parent 4a1913b commit 88bc541
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 40 deletions.
8 changes: 5 additions & 3 deletions app/call_centers/resources/dashboard/call_center_agents.php
Expand Up @@ -49,6 +49,11 @@
$order_by = $_GET["order_by"];
$order = $_GET["order"];

//connect to the database
if (!isset($database)) {
$database = new database;
}

//setup the event socket connection
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);

Expand All @@ -62,7 +67,6 @@
$array['call_center_agents'][0]['call_center_agent_uuid'] = $row['id'];
$array['call_center_agents'][0]['domain_uuid'] = $_SESSION['user']['domain_uuid'];
$array['call_center_agents'][0]['agent_status'] = $row['agent_status'];
$database = new database;
$database->app_name = 'call_centers_dashboard';
$database->app_uuid = '95788e50-9500-079e-2807-fd530b0ea370';
$database->save($array);
Expand Down Expand Up @@ -103,7 +107,6 @@
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "order by queue_extension asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$call_center_queues = $database->select($sql, $parameters, 'all');
$num_rows = !is_array($call_center_queues) ? 0 : @sizeof($call_center_queues);
unset($sql, $parameters);
Expand All @@ -114,7 +117,6 @@
$sql .= "and domain_uuid = :domain_uuid";
$parameters['user_uuid'] = $_SESSION['user_uuid'];
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$agents = $database->select($sql, $parameters, 'all');
if (count($agents) > 0) {
$agent = $agents[0];
Expand Down
12 changes: 7 additions & 5 deletions app/call_forward/resources/classes/call_forward.php
Expand Up @@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2010 - 2016
Copyright (C) 2010 - 2022
All Rights Reserved.
Contributor(s):
Expand All @@ -44,13 +44,15 @@ class call_forward {
public $outbound_caller_id_number;

public function set() {
//create the database connection
$database = new database;

//determine whether to update the dial string
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and extension_uuid = :extension_uuid ";
$parameters['domain_uuid'] = $this->domain_uuid;
$parameters['extension_uuid'] = $this->extension_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$this->extension = $row["extension"];
Expand All @@ -77,7 +79,6 @@ public function set() {
$p->add('extension_add', 'temp');

//execute update
$database = new database;
$database->app_name = 'calls';
$database->app_uuid = '19806921-e8ed-dcff-b325-dd3e5da4959d';
$database->save($array);
Expand Down Expand Up @@ -112,6 +113,9 @@ public function set() {
*/
public function toggle($records) {

//create the database connection
$database = new database;

//assign private variables
$this->app_name = 'calls';
$this->app_uuid = '19806921-e8ed-dcff-b325-dd3e5da4959d';
Expand Down Expand Up @@ -156,7 +160,6 @@ public function toggle($records) {
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
Expand Down Expand Up @@ -216,7 +219,6 @@ public function toggle($records) {
$p->add('extension_edit', 'temp');

//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
Expand Down
14 changes: 5 additions & 9 deletions app/devices/resources/dashboard/device_keys.php
Expand Up @@ -34,6 +34,11 @@
$language = new text;
$text = $language->get($_SESSION['domain']['language']['code'], 'app/devices');

//connect to the database
if (!isset($database)) {
$database = new database;
}

//get the vendor functions
$sql = "select v.name as vendor_name, f.name, f.value ";
$sql .= "from v_device_vendors as v, v_device_vendor_functions as f ";
Expand All @@ -57,7 +62,6 @@
$sql .= "and v.enabled = 'true' ";
$sql .= "and f.enabled = 'true' ";
$sql .= "order by v.name asc, f.name asc ";
$database = new database;
$vendor_functions = $database->select($sql, (is_array($parameters) ? $parameters : null), 'all');
unset($sql, $sql_where_or, $parameters);

Expand All @@ -79,7 +83,6 @@
$sql = "select device_uuid, device_profile_uuid from v_devices ";
$sql .= "where device_user_uuid = :device_user_uuid ";
$parameters['device_user_uuid'] = $_SESSION['user_uuid'];
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$device_uuid = $row['device_uuid'];
Expand All @@ -92,7 +95,6 @@
$sql = "select * from v_device_keys ";
$sql .= "where device_profile_uuid = :device_profile_uuid ";
$parameters['device_profile_uuid'] = $device_profile_uuid;
$database = new database;
$device_profile_keys = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
}
Expand All @@ -102,7 +104,6 @@
$sql = "select * from v_device_keys ";
$sql .= "where device_uuid = :device_uuid ";
$parameters['device_uuid'] = $device_uuid;
$database = new database;
$device_keys = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
}
Expand Down Expand Up @@ -219,7 +220,6 @@
$sql = "select device_uuid from v_devices ";
$sql .= "where device_user_uuid = :device_user_uuid ";
$parameters['device_user_uuid'] = $_SESSION['user_uuid'];
$database = new database;
$device_uuid = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
}
Expand Down Expand Up @@ -268,7 +268,6 @@
$p->add('device_key_edit', 'temp');

//save the changes
$database = new database;
$database->app_name = 'devices';
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
$database->save($array);
Expand Down Expand Up @@ -305,7 +304,6 @@
$sql = "select device_uuid, device_profile_uuid from v_devices ";
$sql .= "where device_user_uuid = :device_user_uuid ";
$parameters['device_user_uuid'] = $_SESSION['user_uuid'];
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$device_uuid = $row['device_uuid'];
Expand All @@ -318,7 +316,6 @@
$sql = "select * from v_device_lines ";
$sql .= "where device_uuid = :device_uuid ";
$parameters['device_uuid'] = $device_uuid;
$database = new database;
$device_lines = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
}
Expand Down Expand Up @@ -358,7 +355,6 @@
if (is_uuid($device_profile_uuid)) {
$parameters['device_profile_uuid'] = $device_profile_uuid;
}
$database = new database;
$keys = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
}
Expand Down
7 changes: 5 additions & 2 deletions app/domain_limits/resources/dashboard/domain_limits.php
Expand Up @@ -21,6 +21,11 @@
$language = new text;
$text = $language->get($_SESSION['domain']['language']['code'], 'core/user_settings');

//connect to the database
if (!isset($database)) {
$database = new database;
}

//domain limits
if (is_array($_SESSION['limit']) && sizeof($_SESSION['limit']) > 0) {
echo "<div class='hud_box'>\n";
Expand All @@ -33,7 +38,6 @@
$sql = "select count(extension_uuid) from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$extension_total = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);

Expand All @@ -45,7 +49,6 @@
$sql = "select count(destination_uuid) from v_destinations ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$destination_total = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);

Expand Down
9 changes: 6 additions & 3 deletions app/extensions/resources/dashboard/caller_id.php
Expand Up @@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2017 - 2021
Portions created by the Initial Developer are Copyright (C) 2017 - 2022
the Initial Developer. All Rights Reserved.
Contributor(s):
Expand All @@ -39,6 +39,11 @@
$language = new text;
$text = $language->get($_SESSION['domain']['language']['code'], 'app/extensions');

//connect to the database
if (!isset($database)) {
$database = new database;
}

//add or update the database
if (is_array($_POST['extensions']) && @sizeof($_POST['extensions']) != 0) {

Expand Down Expand Up @@ -89,7 +94,6 @@
$p->add("extension_edit", "temp");

//save to the data
$database = new database;
$database->app_name = 'extensions';
$database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
$database->save($array);
Expand Down Expand Up @@ -136,7 +140,6 @@
$sql .= "and destination_type = 'inbound' ";
$sql .= "order by destination_caller_id_name asc, destination_caller_id_number asc";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$destinations = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);

Expand Down
10 changes: 6 additions & 4 deletions app/ring_groups/resources/dashboard/ring_group_forward.php
Expand Up @@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2013-2021
Portions created by the Initial Developer are Copyright (C) 2013-2022
the Initial Developer. All Rights Reserved.
Contributor(s):
Expand Down Expand Up @@ -51,6 +51,11 @@
$order_by = $_GET["order_by"];
$order = $_GET["order"];

//connect to the database
if (!isset($database)) {
$database = new database;
}

//find the path
switch ($_SERVER['REQUEST_URI']) {
case PROJECT_PATH."/core/dashboard/index.php":
Expand Down Expand Up @@ -91,7 +96,6 @@
$p = new permissions;
$p->add('ring_group_edit', 'temp');

$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
$database->save($array);
Expand Down Expand Up @@ -125,7 +129,6 @@
$parameters['domain_uuid'] = $domain_uuid;
$parameters['user_uuid'] = $_SESSION['user']['user_uuid'];
}
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
unset($parameters);

Expand Down Expand Up @@ -158,7 +161,6 @@
}
$sql .= order_by($order_by, $order, 'ring_group_extension', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$result = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);

Expand Down
16 changes: 5 additions & 11 deletions app/system/resources/dashboard/system_counts.php
Expand Up @@ -13,6 +13,11 @@
exit;
}

//connect to the database
if (!isset($database)) {
$database = new database;
}

//add multi-lingual support
$language = new text;
$text = $language->get($_SESSION['domain']['language']['code'], 'core/user_settings');
Expand All @@ -34,7 +39,6 @@
$stats['domain']['devices']['total'] = 0;
$stats['domain']['devices']['disabled'] = 0;
$sql = "select domain_uuid, device_enabled from v_devices";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['devices']['total'] = sizeof($result);
Expand All @@ -56,7 +60,6 @@
$stats['domain']['extensions']['total'] = 0;
$stats['domain']['extensions']['disabled'] = 0;
$sql = "select domain_uuid, enabled from v_extensions";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['extensions']['total'] = sizeof($result);
Expand All @@ -78,7 +81,6 @@
$stats['domain']['gateways']['total'] = 0;
$stats['domain']['gateways']['disabled'] = 0;
$sql = "select domain_uuid, enabled from v_gateways";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['gateways']['total'] = sizeof($result);
Expand All @@ -100,7 +102,6 @@
$stats['domain']['users']['total'] = 0;
$stats['domain']['users']['disabled'] = 0;
$sql = "select domain_uuid, user_enabled from v_users";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['users']['total'] = sizeof($result);
Expand All @@ -122,7 +123,6 @@
$stats['domain']['destinations']['total'] = 0;
$stats['domain']['destinations']['disabled'] = 0;
$sql = "select domain_uuid, destination_enabled from v_destinations";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['destinations']['total'] = sizeof($result);
Expand All @@ -144,7 +144,6 @@
$stats['domain']['call_center_queues']['total'] = 0;
$stats['domain']['call_center_queues']['disabled'] = 0;
$sql = "select domain_uuid from v_call_center_queues";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['call_center_queues']['total'] = sizeof($result);
Expand All @@ -166,7 +165,6 @@
$stats['domain']['ivr_menus']['total'] = 0;
$stats['domain']['ivr_menus']['disabled'] = 0;
$sql = "select domain_uuid, ivr_menu_enabled from v_ivr_menus";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['ivr_menus']['total'] = sizeof($result);
Expand All @@ -188,7 +186,6 @@
$stats['domain']['ring_groups']['total'] = 0;
$stats['domain']['ring_groups']['disabled'] = 0;
$sql = "select domain_uuid, ring_group_enabled from v_ring_groups";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['ring_groups']['total'] = sizeof($result);
Expand All @@ -210,7 +207,6 @@
$stats['domain']['voicemails']['total'] = 0;
$stats['domain']['voicemails']['disabled'] = 0;
$sql = "select domain_uuid, voicemail_enabled from v_voicemails";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['voicemails']['total'] = sizeof($result);
Expand All @@ -232,7 +228,6 @@
$stats['domain']['messages']['total'] = 0;
$stats['domain']['messages']['new'] = 0;
$sql = "select domain_uuid, message_status from v_voicemail_messages";
$database = new database;
$result = $database->select($sql, null, 'all');
if (is_array($result) && sizeof($result) != 0) {
$stats['system']['messages']['total'] = sizeof($result);
Expand All @@ -256,7 +251,6 @@
$sql = "select ";
$sql .= "(select count(*) from v_domains where domain_enabled = 'true') as active, ";
$sql .= "(select count(*) from v_domains where domain_enabled = 'false') as inactive; ";
$database = new database;
$row = $database->select($sql, null, 'row');
$domain_active = $row['active'];
$domain_inactive = $row['inactive'];
Expand Down
2 changes: 1 addition & 1 deletion app/system/resources/dashboard/system_status.php
Expand Up @@ -194,7 +194,7 @@
}
}
if ($sql != '') {
$database = new database;
if (!isset($database)) { $database = new database; }
$connections = $database->select($sql, null, 'column');
unset($sql);
}
Expand Down

0 comments on commit 88bc541

Please sign in to comment.