Database class integration.

This commit is contained in:
Nate 2019-07-29 09:26:52 -06:00
parent ccfce8ee1f
commit 12d7ceb397
5 changed files with 269 additions and 281 deletions

View File

@ -28,112 +28,106 @@
if ($domains_processed == 1) {
//add the access control list to the database
$sql = "select count(*) as num_rows from v_access_controls ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
//set the directory
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/acl.conf.xml";
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/acl.conf';
//load the xml and save it into an array
if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file);
}
elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents(xml_file_alt);
}
else {
$xml_string = "<configuration name=\"acl.conf\" description=\"Network Lists\">\n";
$xml_string .= " <network-lists>\n";
$xml_string .= " <list name=\"lan\" default=\"allow\">\n";
$xml_string .= " <node type=\"allow\" cidr=\"192.168.42.42/32\"/>\n";
$xml_string .= " </list>\n";
$xml_string .= " <list name=\"domains\" default=\"deny\">\n";
$xml_string .= " <node type=\"allow\" domain=\"".$_SESSION['domain_name']."\"/>\n";
$xml_string .= " </list>\n";
$xml_string .= " </network-lists>\n";
$xml_string .= "</configuration>\n";
}
$xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
$sql = "select count(*) from v_access_controls ";
$database = new database;
$num_rows = $database->select($sql, null, 'column');
if ($num_rows == 0) {
//set the directory
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/acl.conf.xml";
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/acl.conf';
//load the xml and save it into an array
if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file);
}
elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents(xml_file_alt);
}
else {
$xml_string = "<configuration name=\"acl.conf\" description=\"Network Lists\">\n";
$xml_string .= " <network-lists>\n";
$xml_string .= " <list name=\"lan\" default=\"allow\">\n";
$xml_string .= " <node type=\"allow\" cidr=\"192.168.42.42/32\"/>\n";
$xml_string .= " </list>\n";
$xml_string .= " <list name=\"domains\" default=\"deny\">\n";
$xml_string .= " <node type=\"allow\" domain=\"".$_SESSION['domain_name']."\"/>\n";
$xml_string .= " </list>\n";
$xml_string .= " </network-lists>\n";
$xml_string .= "</configuration>\n";
}
$xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
//process the array
foreach($conf_array['network-lists']['list'] as $list) {
//get the attributes
$access_control_name = $list['@attributes']['name'];
$access_control_default = $list['@attributes']['default'];
//process the array
foreach($conf_array['network-lists']['list'] as $list) {
//get the attributes
$access_control_name = $list['@attributes']['name'];
$access_control_default = $list['@attributes']['default'];
//insert the name, description
$access_control_uuid = uuid();
$sql = "insert into v_access_controls ";
$sql .= "(";
$sql .= "access_control_uuid, ";
$sql .= "access_control_name, ";
$sql .= "access_control_default ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$access_control_uuid."', ";
$sql .= "'".check_str($access_control_name)."', ";
$sql .= "'".check_str($access_control_default)."' ";
$sql .= ")";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
//insert the name, description
$access_control_uuid = uuid();
$array['access_controls'][0]['access_control_uuid'] = $access_control_uuid;
$array['access_controls'][0]['access_control_name'] = $access_control_name;
$array['access_controls'][0]['access_control_default'] = $access_control_default;
//normalize the array - needed because the array is inconsistent when there is only one row vs multiple
if (strlen($list['node']['@attributes']['type']) > 0) {
$list['node'][]['@attributes'] = $list['node']['@attributes'];
unset($list['node']['@attributes']);
}
$p = new permissions;
$p->add('access_control_add', 'temp');
//add the nodes
foreach ($list['node'] as $row) {
//get the name and value pair
$node_type = $row['@attributes']['type'];
$node_cidr = $row['@attributes']['cidr'];
$node_domain = $row['@attributes']['domain'];
$node_description = $row['@attributes']['description'];
//replace $${domain}
if (strlen($node_domain) > 0) {
$node_domain = str_replace("\$\${domain}", $domain_name, $node_domain);
}
//add the profile settings into the database
$access_control_node_uuid = uuid();
$sql = "insert into v_access_control_nodes ";
$sql .= "(";
$sql .= "access_control_node_uuid, ";
$sql .= "access_control_uuid, ";
$sql .= "node_type, ";
$sql .= "node_cidr, ";
$sql .= "node_domain, ";
$sql .= "node_description ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$access_control_node_uuid."', ";
$sql .= "'".$access_control_uuid."', ";
$sql .= "'".$node_type."', ";
$sql .= "'".$node_cidr."', ";
$sql .= "'".$node_domain."', ";
$sql .= "'".$node_description."' ";
$sql .= ")";
//echo $sql."\n";
$db->exec(check_sql($sql));
}
$database = new database;
$database->app_name = 'access_controls';
$database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
$database->save($array);
unset($array);
$p->delete('access_control_add', 'temp');
//normalize the array - needed because the array is inconsistent when there is only one row vs multiple
if (strlen($list['node']['@attributes']['type']) > 0) {
$list['node'][]['@attributes'] = $list['node']['@attributes'];
unset($list['node']['@attributes']);
}
unset($prep_statement);
//rename the file
if (file_exists($xml_dir.'/acl.conf.xml')) {
rename($xml_dir.'/acl.conf.xml', $xml_dir.'/acl.conf');
//add the nodes
foreach ($list['node'] as $row) {
//get the name and value pair
$node_type = $row['@attributes']['type'];
$node_cidr = $row['@attributes']['cidr'];
$node_domain = $row['@attributes']['domain'];
$node_description = $row['@attributes']['description'];
//replace $${domain}
if (strlen($node_domain) > 0) {
$node_domain = str_replace("\$\${domain}", $domain_name, $node_domain);
}
//add the profile settings into the database
$access_control_node_uuid = uuid();
$array['access_control_nodes'][0]['access_control_node_uuid'] = $access_control_node_uuid;
$array['access_control_nodes'][0]['access_control_uuid'] = $access_control_uuid;
$array['access_control_nodes'][0]['node_type'] = $node_type;
$array['access_control_nodes'][0]['node_cidr'] = $node_cidr;
$array['access_control_nodes'][0]['node_domain'] = $node_domain;
$array['access_control_nodes'][0]['node_description'] = $node_description;
$p = new permissions;
$p->add('access_control_node_add', 'temp');
$database = new database;
$database->app_name = 'access_controls';
$database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
$database->save($array);
unset($array);
$p->delete('access_control_node_add', 'temp');
}
}
}
unset($prep_statement);
//rename the file
if (file_exists($xml_dir.'/acl.conf.xml')) {
rename($xml_dir.'/acl.conf.xml', $xml_dir.'/acl.conf');
}
}
unset($sql, $num_rows);
}

View File

@ -33,24 +33,36 @@ if ($domains_processed == 1) {
$sql .= "from v_call_center_tiers as t, v_domains as d ";
$sql .= "where t.domain_uuid = d.domain_uuid ";
$sql .= "and (t.call_center_queue_uuid is null or t.call_center_agent_uuid is null) ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$tiers = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($tiers as &$row) {
if ($row['call_center_queue_uuid'] == null && $row['queue_uuid'] != null) {
$sql = "update v_call_center_tiers set call_center_queue_uuid = '".$row['queue_uuid']."' ";
$sql .= "where call_center_tier_uuid = '".$row['call_center_tier_uuid']."' ";
$db->exec(check_sql($sql));
unset($sql);
$database = new database;
$tiers = $database->select($sql, null, 'all');
if (is_array($tiers) && @sizeof($tiers) != 0) {
foreach ($tiers as $index => &$row) {
if ($row['call_center_queue_uuid'] == null && $row['queue_uuid'] != null) {
$array['call_center_tiers'][$index]['call_center_queue_uuid'] = $row['queue_uuid'];
}
if ($row['call_center_agent_uuid'] == null && $row['agent_uuid'] != null) {
$array['call_center_tiers'][$index]['call_center_agent_uuid'] = $row['agent_uuid'];
}
if (is_array($array['call_center_tiers'][$index]) && @sizeof($array['call_center_tiers'][$index]) != 0) {
$array['call_center_tiers'][$index]['call_center_tier_uuid'] = $row['call_center_tier_uuid'];
}
}
if ($row['call_center_agent_uuid'] == null && $row['agent_uuid'] != null) {
$sql = "update v_call_center_tiers set call_center_agent_uuid = '".$row['agent_uuid']."' ";
$sql .= "where call_center_tier_uuid = '".$row['call_center_tier_uuid']."' ";
$db->exec(check_sql($sql));
unset($sql);
if (is_array($array) && @sizeof($array) != 0) {
$p = new permissions;
$p->add('call_center_tier_edit', 'temp');
$database = new database;
$database->app_name = 'call_centers';
$database->app_uuid = '95788e50-9500-079e-2807-fd530b0ea370';
$database->save($array);
$response = $database->message;
unset($array);
$p->delete('call_center_tier_edit', 'temp');
}
}
unset($sql);
}

View File

@ -27,104 +27,94 @@
if ($domains_processed == 1) {
//add the conference controls list to the database
$sql = "select count(*) as num_rows from v_conference_controls; ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
$sql = "select count(*) from v_conference_controls; ";
$database = new database;
$num_rows = $database->select($sql, null, 'column');
if ($num_rows == 0) {
//set the directory
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/conference.conf";
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/conference.conf';
//set the directory
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/conference.conf";
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/conference.conf';
//rename the file
if (file_exists($xml_dir.'/conference.conf.xml.noload')) {
rename($xml_dir.'/conference.conf.xml.noload', $xml_dir.'/conference.conf');
}
//rename the file
if (file_exists($xml_dir.'/conference.conf.xml.noload')) {
rename($xml_dir.'/conference.conf.xml.noload', $xml_dir.'/conference.conf');
}
//load the xml and save it into an array
if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file);
}
elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents($xml_file_alt);
}
$xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
//load the xml and save it into an array
if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file);
}
elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents($xml_file_alt);
}
$xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
//process the array
foreach ($conf_array['caller-controls']['group'] as $row) {
//process the array
foreach ($conf_array['caller-controls']['group'] as $row) {
//get the data from the array
$control_name = $row['@attributes']['name'];
//echo $profile_name."<br />\n";
//get the data from the array
$control_name = $row['@attributes']['name'];
//echo $profile_name."<br />\n";
//insert the data into the database
$conference_control_uuid = uuid();
$sql = "insert into v_conference_controls ";
$sql .= "(";
//$sql .= "domain_uuid, ";
$sql .= "conference_control_uuid, ";
$sql .= "control_name, ";
$sql .= "control_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
//$sql .= "'".$domain_uuid."', ";
$sql .= "'".$conference_control_uuid."', ";
$sql .= "'".check_str($control_name)."', ";
$sql .= "'true' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
//insert the data into the database
$conference_control_uuid = uuid();
$array['conference_controls'][0]['conference_control_uuid'] = $conference_control_uuid;
$array['conference_controls'][0]['control_name'] = $control_name;
$array['conference_controls'][0]['control_enabled'] = 'true';
//insert the profile params
foreach ($row['control'] as $p) {
$p = new permissions;
$p->add('conference_control_add', 'temp');
//get the name
//print_r($p);
$control_action = $p['@attributes']['action'];
$control_digits = $p['@attributes']['digits'];
$control_data = $p['@attributes']['data'];
$control_enabled = 'true';
$database = new database;
$database->app_name = 'conference_controls';
$database->app_uuid = 'e1ad84a2-79e1-450c-a5b1-7507a043e048';
$database->save($array);
unset($array);
//add the coference profile params
$conference_control_detail_uuid = uuid();
$sql = "insert into v_conference_control_details ";
$sql .= "(";
$sql .= "conference_control_uuid, ";
$sql .= "conference_control_detail_uuid, ";
$sql .= "control_digits, ";
$sql .= "control_action, ";
if (strlen($control_data) > 0) {
$sql .= "control_data, ";
}
$sql .= "control_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$conference_control_uuid."', ";
$sql .= "'".$conference_control_detail_uuid."', ";
$sql .= "'".$control_digits."', ";
$sql .= "'".$control_action."', ";
if (strlen($control_data) > 0) {
$sql .= "'".$control_data."', ";
}
$sql .= "'".$control_enabled."' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
}
$p->delete('conference_control_add', 'temp');
}
//insert the profile params
foreach ($row['control'] as $p) {
} //if num_rows
} //if prep_statement
//get the name
//print_r($p);
$control_action = $p['@attributes']['action'];
$control_digits = $p['@attributes']['digits'];
$control_data = $p['@attributes']['data'];
$control_enabled = 'true';
//add the coference profile params
$conference_control_detail_uuid = uuid();
$array['conference_contro_details'][0]['conference_control_uuid'] = $conference_control_uuid;
$array['conference_contro_details'][0]['conference_control_detail_uuid'] = $conference_control_detail_uuid;
$array['conference_contro_details'][0]['control_digits'] = $control_digits;
$array['conference_contro_details'][0]['control_action'] = $control_action;
if (strlen($control_data) > 0) {
$array['conference_contro_details'][0]['control_data'] = $control_data;
}
$array['conference_contro_details'][0]['control_enabled'] = $control_enabled;
$p = new permissions;
$p->add('conference_contro_detail_add', 'temp');
$database = new database;
$database->app_name = 'conference_controls';
$database->app_uuid = 'e1ad84a2-79e1-450c-a5b1-7507a043e048';
$database->save($array);
unset($array);
$p->delete('conference_contro_detail_add', 'temp');
}
}
}
unset($sql, $num_rows);
}

View File

@ -27,96 +27,88 @@
if ($domains_processed == 1) {
//add the music_on_hold list to the database
$sql = "select count(*) as num_rows from v_conference_profiles; ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
$sql = "select count(*) from v_conference_profiles; ";
$database = new database;
$num_rows = $database->select($sql, null, 'column');
if ($num_rows == 0) {
//set the directory
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/conference.conf";
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/conference.conf';
//set the directory
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/conference.conf";
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/conference.conf';
//rename the file
if (file_exists($xml_dir.'/conference.conf.xml.noload')) {
rename($xml_dir.'/conference.conf.xml.noload', $xml_dir.'/conference.conf');
}
//rename the file
if (file_exists($xml_dir.'/conference.conf.xml.noload')) {
rename($xml_dir.'/conference.conf.xml.noload', $xml_dir.'/conference.conf');
}
//load the xml and save it into an array
if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file);
}
elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents($xml_file_alt);
}
$xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
//load the xml and save it into an array
if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file);
}
elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents($xml_file_alt);
}
$xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
//process the array
foreach ($conf_array['profiles']['profile'] as $row) {
//process the array
foreach ($conf_array['profiles']['profile'] as $row) {
//get the data from the array
$profile_name = $row['@attributes']['name'];
//echo $profile_name."<br />\n";
//get the data from the array
$profile_name = $row['@attributes']['name'];
//echo $profile_name."<br />\n";
//insert the data into the database
$conference_profile_uuid = uuid();
$sql = "insert into v_conference_profiles ";
$sql .= "(";
//$sql .= "domain_uuid, ";
$sql .= "conference_profile_uuid, ";
$sql .= "profile_name, ";
$sql .= "profile_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
//$sql .= "'".$domain_uuid."', ";
$sql .= "'".$conference_profile_uuid."', ";
$sql .= "'".check_str($profile_name)."', ";
$sql .= "'true' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
//insert the data into the database
$conference_profile_uuid = uuid();
$array['conference_profiles'][0]['conference_profile_uuid'] = $conference_profile_uuid;
$array['conference_profiles'][0]['profile_name'] = $profile_name;
$array['conference_profiles'][0]['profile_enabled'] = 'true';
//insert the profile params
foreach ($row['param'] as $p) {
//get the name
//print_r($p);
$profile_param_name = $p['@attributes']['name'];
$profile_param_value = $p['@attributes']['value'];
$profile_param_enabled = 'true';
$p = new permissions;
$p->add('conference_profile_add', 'temp');
//add the coference profile params
$conference_profile_param_uuid = uuid();
$sql = "insert into v_conference_profile_params ";
$sql .= "(";
$sql .= "conference_profile_uuid, ";
$sql .= "conference_profile_param_uuid, ";
$sql .= "profile_param_name, ";
$sql .= "profile_param_value, ";
$sql .= "profile_param_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$conference_profile_uuid."', ";
$sql .= "'".$conference_profile_param_uuid."', ";
$sql .= "'".$profile_param_name."', ";
$sql .= "'".$profile_param_value."', ";
$sql .= "'".$profile_param_enabled."' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
}
$database = new database;
$database->app_name = 'conference_profiles';
$database->app_uuid = 'c33e2c2a-847f-44c1-8c0d-310df5d65ba9';
$database->save($array);
unset($array);
}
$p->delete('conference_profile_add', 'temp');
} //if num_rows
} //if prep_statement
//insert the profile params
foreach ($row['param'] as $p) {
//get the name
//print_r($p);
$profile_param_name = $p['@attributes']['name'];
$profile_param_value = $p['@attributes']['value'];
$profile_param_enabled = 'true';
//add the coference profile params
$conference_profile_param_uuid = uuid();
$array['conference_profile_params'][0]['conference_profile_uuid'] = $conference_profile_uuid;
$array['conference_profile_params'][0]['conference_profile_param_uuid'] = $conference_profile_param_uuid;
$array['conference_profile_params'][0]['profile_param_name'] = $profile_param_name;
$array['conference_profile_params'][0]['profile_param_value'] = $profile_param_value;
$array['conference_profile_params'][0]['profile_param_enabled'] = $profile_param_enabled;
$p = new permissions;
$p->add('conference_profile_param_add', 'temp');
$database = new database;
$database->app_name = 'conference_profiles';
$database->app_uuid = 'c33e2c2a-847f-44c1-8c0d-310df5d65ba9';
$database->save($array);
unset($array);
$p->delete('conference_profile_param_add', 'temp');
}
}
}
unset($sql, $num_rows);
}

View File

@ -5,8 +5,8 @@ if ($domains_processed == 1) {
$sql = "update v_dialplan_details ";
$sql .= "set dialplan_detail_data = replace(dialplan_detail_data, '-','@') ";
$sql .= "where dialplan_detail_type = 'conference' and dialplan_detail_data like '%-%';";
//echo $sql."\n";
$db->exec($sql);
$database = new database;
$database->execute($sql);
unset($sql);
}