diff --git a/app/sip_profiles/app_defaults.php b/app/sip_profiles/app_defaults.php index 0da9ff7d9f..64afcdd581 100644 --- a/app/sip_profiles/app_defaults.php +++ b/app/sip_profiles/app_defaults.php @@ -28,36 +28,37 @@ if ($domains_processed == 1) { //add the sip profiles to the database - $sql = "select count(*) as num_rows from v_sip_profiles "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles')) { - $sip_profile_dir = '/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload'; - } - elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles')) { - $sip_profile_dir = '/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload'; - } - else { - $sip_profile_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/sip_profiles/*.xml.noload'; - } - $db->beginTransaction(); - $xml_files = glob($sip_profile_dir); - foreach ($xml_files as &$xml_file) { - //load the sip profile xml and save it into an array - $sip_profile_xml = file_get_contents($xml_file); - $xml = simplexml_load_string($sip_profile_xml); - $json = json_encode($xml); - $sip_profile = json_decode($json, true); - $sip_profile_name = $sip_profile['@attributes']['name']; - $sip_profile_enabled = $sip_profile['@attributes']['enabled']; - //echo "sip profile name: ".$sip_profile_name."\n"; + $sql = "select count(*) from v_sip_profiles "; + $database = new database; + $num_rows = $database->select($sql, null, 'column'); + unset($sql); - if ($sip_profile_name != "{v_sip_profile_name}") { - //prepare the description - switch ($sip_profile_name) { + if ($num_rows == 0) { + if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles')) { + $sip_profile_dir = '/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload'; + } + elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles')) { + $sip_profile_dir = '/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload'; + } + else { + $sip_profile_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/sip_profiles/*.xml.noload'; + } + + $xml_files = glob($sip_profile_dir); + foreach ($xml_files as $x => &$xml_file) { + //load the sip profile xml and save it into an array + $sip_profile_xml = file_get_contents($xml_file); + $xml = simplexml_load_string($sip_profile_xml); + $json = json_encode($xml); + $sip_profile = json_decode($json, true); + $sip_profile_name = $sip_profile['@attributes']['name']; + $sip_profile_enabled = $sip_profile['@attributes']['enabled']; + //echo "sip profile name: ".$sip_profile_name."\n"; + + if ($sip_profile_name != "{v_sip_profile_name}") { + + //prepare the description + switch ($sip_profile_name) { case "internal": $sip_profile_description = "The Internal profile by default requires registration which is used by the endpoints. "; $sip_profile_description .= "By default the Internal profile binds to port 5060. "; @@ -78,184 +79,151 @@ break; default: $sip_profile_description = ''; - } + } //add the sip profile if it is not false if ($sip_profile_enabled != "false") { - //insert the sip profile name, description - $sip_profile_uuid = uuid(); - $sql = "insert into v_sip_profiles"; - $sql .= "("; - $sql .= "sip_profile_uuid, "; - $sql .= "sip_profile_name, "; - $sql .= "sip_profile_description "; - $sql .= ") "; - $sql .= "values "; - $sql .= "( "; - $sql .= "'".check_str($sip_profile_uuid)."', "; - $sql .= "'".check_str($sip_profile_name)."', "; - $sql .= "'".check_str($sip_profile_description)."' "; - $sql .= ")"; - //echo $sql."\n\n"; - $db->exec(check_sql($sql)); - unset($sql); - //get the domain, alias and parse values and set as variables - $sip_profile_domain_name = $sip_profile['domains']['domain']['@attributes']['name']; - $sip_profile_domain_alias = $sip_profile['domains']['domain']['@attributes']['alias']; - $sip_profile_domain_parse = $sip_profile['domains']['domain']['@attributes']['parse']; + //add profile name and description + $sip_profile_uuid = uuid(); + $array['sip_profiles'][$x]['sip_profile_uuid'] = $sip_profile_uuid; + $array['sip_profiles'][$x]['sip_profile_name'] = $sip_profile_name; + $array['sip_profiles'][$x]['sip_profile_description'] = $sip_profile_description; //add the sip profile domains name, alias and parse - $sip_profile_domain_uuid = uuid(); - $sql = "insert into v_sip_profile_domains"; - $sql .= "("; - $sql .= "sip_profile_domain_uuid, "; - $sql .= "sip_profile_uuid, "; - $sql .= "sip_profile_domain_name, "; - $sql .= "sip_profile_domain_alias, "; - $sql .= "sip_profile_domain_parse "; - $sql .= ") "; - $sql .= "values "; - $sql .= "( "; - $sql .= "'".$sip_profile_domain_uuid."', "; - $sql .= "'".$sip_profile_uuid."', "; - $sql .= "'".check_str($sip_profile_domain_name)."', "; - $sql .= "'".check_str($sip_profile_domain_alias)."', "; - $sql .= "'".check_str($sip_profile_domain_parse)."' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); + $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_domain_uuid'] = $sip_profile_domain_uuid; + $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_uuid'] = $sip_profile_uuid; + $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_domain_name'] = $sip_profile['domains']['domain']['@attributes']['name']; + $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_domain_alias'] = $sip_profile['domains']['domain']['@attributes']['alias']; + $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_domain_parse'] = $sip_profile['domains']['domain']['@attributes']['parse']; - //add the sip profile settings - foreach ($sip_profile['settings']['param'] as $row) { - //get the name and value pair - $sip_profile_setting_name = $row['@attributes']['name']; - $sip_profile_setting_value = $row['@attributes']['value']; - $sip_profile_setting_enabled = $row['@attributes']['enabled']; - if ($sip_profile_setting_enabled != "false") { $sip_profile_setting_enabled = "true"; } - //echo "name: $name value: $value\n"; - //add the profile settings into the database - $sip_profile_setting_uuid = uuid(); - $sql = "insert into v_sip_profile_settings "; - $sql .= "("; - $sql .= "sip_profile_setting_uuid, "; - $sql .= "sip_profile_uuid, "; - $sql .= "sip_profile_setting_name, "; - $sql .= "sip_profile_setting_value, "; - $sql .= "sip_profile_setting_enabled "; - $sql .= ") "; - $sql .= "values "; - $sql .= "( "; - $sql .= "'".check_str($sip_profile_setting_uuid)."', "; - $sql .= "'".check_str($sip_profile_uuid)."', "; - $sql .= "'".check_str($sip_profile_setting_name)."', "; - $sql .= "'".check_str($sip_profile_setting_value)."', "; - $sql .= "'".$sip_profile_setting_enabled."' "; - $sql .= ")"; - //echo $sql."\n\n"; - $db->exec(check_sql($sql)); + //add the profile settings + foreach ($sip_profile['settings']['param'] as $y => $row) { + $sip_profile_setting_uuid = uuid(); + $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_setting_uuid'] = $sip_profile_setting_uuid; + $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_uuid'] = $sip_profile_uuid; + $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_setting_name'] = $row['@attributes']['name']; + $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_setting_value'] = $row['@attributes']['value']; + $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_setting_enabled'] = $row['@attributes']['enabled'] != 'false' ? 'true' : $row['@attributes']['enabled']; } - } - } - } - $db->commit(); - //save the sip profile xml + } + + } + } + + //execute inserts + if (is_array($array) && @sizeof($array) != 0) { + //grant temporary permissions + $p = new permissions; + $p->add('sip_profile_add', 'temp'); + $p->add('sip_profile_domain_add', 'temp'); + $p->add('sip_profile_setting_add', 'temp'); + + //execute insert + $database = new database; + $database->app_name = 'sip_profiles'; + $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470'; + $database->save($array); + unset($array); + + //revoke temporary permissions + $p->delete('sip_profile_add', 'temp'); + $p->delete('sip_profile_domain_add', 'temp'); + $p->delete('sip_profile_setting_add', 'temp'); + } + + //save the sip profile xml save_sip_profile_xml(); - //apply settings reminder + //apply settings reminder $_SESSION["reload_xml"] = true; - } - unset($prep_statement); } + //upgrade - add missing sip profiles domain settings - $sql = "select count(*) as num_rows from v_sip_profile_domains "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles')) { - $sip_profile_dir = '/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload'; - } - elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles')) { - $sip_profile_dir = '/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload'; - } - else { - $sip_profile_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/sip_profiles/*.xml.noload'; - } - $db->beginTransaction(); - $xml_files = glob($sip_profile_dir); - foreach ($xml_files as &$xml_file) { - //load the sip profile xml and save it into an array - $sip_profile_xml = file_get_contents($xml_file); - $xml = simplexml_load_string($sip_profile_xml); - $json = json_encode($xml); - $sip_profile = json_decode($json, true); - $sip_profile_name = $sip_profile['@attributes']['name']; - $sip_profile_enabled = $sip_profile['@attributes']['enabled']; - //echo "sip profile name: ".$sip_profile_name."\n"; + $sql = "select count(*) from v_sip_profile_domains "; + $database = new database; + $num_rows = $database->select($sql, null, 'column'); + unset($sql); - //get the domain, alias and parse values and set as variables - $sip_profile_domain_name = $sip_profile['domains']['domain']['@attributes']['name']; - $sip_profile_domain_alias = $sip_profile['domains']['domain']['@attributes']['alias']; - $sip_profile_domain_parse = $sip_profile['domains']['domain']['@attributes']['parse']; + if ($num_rows == 0) { + if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles')) { + $sip_profile_dir = '/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload'; + } + elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles')) { + $sip_profile_dir = '/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload'; + } + else { + $sip_profile_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/sip_profiles/*.xml.noload'; + } - //get the sip_profile_uuid using the sip profile name - $sql = "select sip_profile_uuid from v_sip_profiles "; - $sql .= "where sip_profile_name = '$sip_profile_name' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $sip_profile_uuid = $result[0]["sip_profile_uuid"]; - unset ($prep_statement); + $xml_files = glob($sip_profile_dir); + foreach ($xml_files as $x => &$xml_file) { + //load the sip profile xml and save it into an array + $sip_profile_xml = file_get_contents($xml_file); + $xml = simplexml_load_string($sip_profile_xml); + $json = json_encode($xml); + $sip_profile = json_decode($json, true); + $sip_profile_name = $sip_profile['@attributes']['name']; + $sip_profile_enabled = $sip_profile['@attributes']['enabled']; - //add the sip profile domains name, alias and parse - if ($sip_profile_uuid) { - $sip_profile_domain_uuid = uuid(); - $sql = "insert into v_sip_profile_domains"; - $sql .= "("; - $sql .= "sip_profile_domain_uuid, "; - $sql .= "sip_profile_uuid, "; - $sql .= "sip_profile_domain_name, "; - $sql .= "sip_profile_domain_alias, "; - $sql .= "sip_profile_domain_parse "; - $sql .= ") "; - $sql .= "values "; - $sql .= "( "; - $sql .= "'".$sip_profile_domain_uuid."', "; - $sql .= "'".$sip_profile_uuid."', "; - $sql .= "'".check_str($sip_profile_domain_name)."', "; - $sql .= "'".check_str($sip_profile_domain_alias)."', "; - $sql .= "'".check_str($sip_profile_domain_parse)."' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - } - - //unset the sip_profile_uuid - unset($sip_profile_uuid); + //get the sip_profile_uuid using the sip profile name + $sql = "select sip_profile_uuid from v_sip_profiles "; + $sql .= "where sip_profile_name = :sip_profile_name "; + $parameters['sip_profile_name'] = $sip_profile_name; + $database = new database; + $sip_profile_uuid = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + + //add the sip profile domains name, alias and parse + if (is_uuid($sip_profile_uuid)) { + $sip_profile_domain_uuid = uuid(); + $array['sip_profile_domains'][$x]['sip_profile_domain_uuid'] = $sip_profile_domain_uuid; + $array['sip_profile_domains'][$x]['sip_profile_uuid'] = $sip_profile_uuid; + $array['sip_profile_domains'][$x]['sip_profile_domain_name'] = $sip_profile['domains']['domain']['@attributes']['name']; + $array['sip_profile_domains'][$x]['sip_profile_domain_alias'] = $sip_profile['domains']['domain']['@attributes']['alias']; + $array['sip_profile_domains'][$x]['sip_profile_domain_parse'] = $sip_profile['domains']['domain']['@attributes']['parse']; + } + + //unset the sip_profile_uuid + unset($sip_profile_uuid); + } + + //execute inserts + if (is_array($array) && @sizeof($array) != 0) { + //grant temporary permissions + $p = new permissions; + $p->add('sip_profile_domain_add', 'temp'); + + //execute insert + $database = new database; + $database->app_name = 'sip_profiles'; + $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470'; + $database->save($array); + unset($array); + + //revoke temporary permissions + $p->delete('sip_profile_domain_add', 'temp'); } - $db->commit(); - //save the sip profile xml + //save the sip profile xml save_sip_profile_xml(); - //apply settings reminder + //apply settings reminder $_SESSION["reload_xml"] = true; - } - unset($prep_statement); } + + + //if empty, set enabled to true + $sql = "update v_sip_profiles set "; + $sql .= "sip_profile_enabled = 'true' "; + $sql .= "where sip_profile_enabled is null "; + $sql .= "or sip_profile_enabled = '' "; + $database = new database; + $database->execute($sql); + unset($sql); + } -//if empty, set sip_profile_enabled = true - if ($domains_processed == 1) { - $sql = "update v_sip_profiles set "; - $sql .= "sip_profile_enabled = 'true' "; - $sql .= "where sip_profile_enabled is null "; - $sql .= "or sip_profile_enabled = '' "; - $db->exec(check_sql($sql)); - unset($sql); - } -?> +?> \ No newline at end of file diff --git a/app/sip_profiles/app_languages.php b/app/sip_profiles/app_languages.php index 3dd6bdd32d..2a93cfc9da 100644 --- a/app/sip_profiles/app_languages.php +++ b/app/sip_profiles/app_languages.php @@ -361,6 +361,26 @@ $text['label-sip_profile_settings']['ru-ru'] = "Настройки"; $text['label-sip_profile_settings']['sv-se'] = "Inställningar"; $text['label-sip_profile_settings']['uk-ua'] = "Параметри"; +$text['label-new_sip_profile_name']['en-us'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['ar-eg'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['de-at'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['de-ch'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['de-de'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['es-cl'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['es-mx'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['fr-ca'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['fr-fr'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['he-il'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['it-it'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['nl-nl'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['pl-pl'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['pt-br'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['pt-pt'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['ro-ro'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['ru-ru'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['sv-se'] = "Enter new SIP Profile Name"; +$text['label-new_sip_profile_name']['uk-ua'] = "Enter new SIP Profile Name"; + $text['header-sip_profiles']['en-us'] = "SIP Profiles"; $text['header-sip_profiles']['ar-eg'] = ""; $text['header-sip_profiles']['de-at'] = "SIP Profile"; //copied from de-de diff --git a/app/sip_profiles/sip_profile_copy.php b/app/sip_profiles/sip_profile_copy.php index 7307a058ca..d1f8dad4c1 100644 --- a/app/sip_profiles/sip_profile_copy.php +++ b/app/sip_profiles/sip_profile_copy.php @@ -47,122 +47,83 @@ $text = $language->get(); //set the http get/post variable(s) to a php variable - if (isset($_REQUEST["id"])) { - $sip_profile_uuid = check_str($_REQUEST["id"]); - $sip_profile_name = check_str($_REQUEST["name"]); - } + $sip_profile_uuid = $_REQUEST["id"]; + $sip_profile_name = $_REQUEST["name"]; -//get the sip profile data - if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { - $sql = "select * from v_sip_profiles "; - $sql .= "where sip_profile_uuid = '$sip_profile_uuid' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(); - foreach ($result as &$row) { - $sip_profile_description = $row["sip_profile_description"]; +if (is_uuid($sip_profile_uuid) && $sip_profile_name != '') { + + //get the sip profile data + if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { + $sql = "select sip_profile_description from v_sip_profiles "; + $sql .= "where sip_profile_uuid = :sip_profile_uuid "; + $parameters['sip_profile_uuid'] = $sip_profile_uuid; + $database = new database; + $sip_profile_description = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); } - unset ($prep_statement); - } -//copy the v_sip_profiles - $sip_profile_uuid_new = uuid(); - $sip_profile_enabled = 'true'; - $sql = "insert into v_sip_profiles "; - $sql .= "("; - $sql .= "sip_profile_uuid, "; - $sql .= "sip_profile_name, "; - $sql .= "sip_profile_enabled, "; - $sql .= "sip_profile_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'".$sip_profile_uuid_new."', "; - $sql .= "'".$sip_profile_name."', "; - $sql .= "'".$sip_profile_enabled."', "; - $sql .= "'".$sip_profile_description."' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); + //copy the sip profile + $sip_profile_uuid_new = uuid(); + $array['sip_profiles'][0]['sip_profile_uuid'] = $sip_profile_uuid_new; + $array['sip_profiles'][0]['sip_profile_name'] = $sip_profile_name; + $array['sip_profiles'][0]['sip_profile_enabled'] = 'true'; + $array['sip_profiles'][0]['sip_profile_description'] = $sip_profile_description; -//get the the sip profile settings - $sql = "select * from v_sip_profile_domains "; - $sql .= "where sip_profile_uuid = '$sip_profile_uuid' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(); - foreach ($result as &$row) { - $sip_profile_domain_name = $row["sip_profile_domain_name"]; - $sip_profile_domain_alias = $row["sip_profile_domain_alias"]; - $sip_profile_domain_parse = $row["sip_profile_domain_parse"]; + //get the the sip profile settings + $sql = "select * from v_sip_profile_domains "; + $sql .= "where sip_profile_uuid = :sip_profile_uuid "; + $parameters['sip_profile_uuid'] = $sip_profile_uuid; + $database = new database; + $result = $database->select($sql, $parameters, 'all'); + if (is_array($result) && @sizeof($result) != 0) { + foreach ($result as $x => &$row) { + $array['sip_profile_domains'][$x]['sip_profile_domain_uuid'] = uuid(); + $array['sip_profile_domains'][$x]['sip_profile_uuid'] = $sip_profile_uuid_new; + $array['sip_profile_domains'][$x]['sip_profile_domain_name'] = $row["sip_profile_domain_name"]; + $array['sip_profile_domains'][$x]['sip_profile_domain_alias'] = $row["sip_profile_domain_alias"]; + $array['sip_profile_domains'][$x]['sip_profile_domain_parse'] = $row["sip_profile_domain_parse"]; + } + } + unset($sql, $parameters, $result, $row); - //add the sip profile setting - $sql = "insert into v_sip_profile_domains "; - $sql .= "("; - $sql .= "sip_profile_domain_uuid, "; - $sql .= "sip_profile_uuid, "; - $sql .= "sip_profile_domain_name, "; - $sql .= "sip_profile_domain_alias, "; - $sql .= "sip_profile_domain_parse "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'$sip_profile_uuid_new', "; - $sql .= "'$sip_profile_domain_name', "; - $sql .= "'$sip_profile_domain_alias', "; - $sql .= "'$sip_profile_domain_parse' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - } - unset ($prep_statement); + //get the the sip profile settings + $sql = "select * from v_sip_profile_settings "; + $sql .= "where sip_profile_uuid = :sip_profile_uuid "; + $parameters['sip_profile_uuid'] = $sip_profile_uuid; + $database = new database; + $result = $database->select($sql, $parameters, 'all'); + if (is_array($result) && @sizeof($result) != 0) { + foreach ($result as $x => &$row) { + $array['sip_profile_settings'][$x]['sip_profile_setting_uuid'] = uuid(); + $array['sip_profile_settings'][$x]['sip_profile_uuid'] = $sip_profile_uuid_new; + $array['sip_profile_settings'][$x]['sip_profile_setting_name'] = $row["sip_profile_setting_name"]; + $array['sip_profile_settings'][$x]['sip_profile_setting_value'] = $row["sip_profile_setting_value"]; + $array['sip_profile_settings'][$x]['sip_profile_setting_enabled'] = $row["sip_profile_setting_enabled"]; + $array['sip_profile_settings'][$x]['sip_profile_setting_description'] = $row["sip_profile_setting_description"]; + } + } + unset($sql, $parameters, $result, $row); -//get the the sip profile settings - $sql = "select * from v_sip_profile_settings "; - $sql .= "where sip_profile_uuid = '$sip_profile_uuid' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(); - foreach ($result as &$row) { - $sip_profile_setting_name = $row["sip_profile_setting_name"]; - $sip_profile_setting_value = $row["sip_profile_setting_value"]; - $sip_profile_setting_enabled = $row["sip_profile_setting_enabled"]; - $sip_profile_setting_description = $row["sip_profile_setting_description"]; + //execute insert + $database = new database; + $database->app_name = 'sip_profiles'; + $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470'; + $database->save($array); + unset($array); - //add the sip profile setting - $sql = "insert into v_sip_profile_settings "; - $sql .= "("; - $sql .= "sip_profile_setting_uuid, "; - $sql .= "sip_profile_uuid, "; - $sql .= "sip_profile_setting_name, "; - $sql .= "sip_profile_setting_value, "; - $sql .= "sip_profile_setting_enabled, "; - $sql .= "sip_profile_setting_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'$sip_profile_uuid_new', "; - $sql .= "'$sip_profile_setting_name', "; - $sql .= "'$sip_profile_setting_value', "; - $sql .= "'$sip_profile_setting_enabled', "; - $sql .= "'$sip_profile_setting_description' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - } - unset ($prep_statement); + //save the sip profile xml + save_sip_profile_xml(); -//save the sip profile xml - save_sip_profile_xml(); + //apply settings reminder + $_SESSION["reload_xml"] = true; -//apply settings reminder - $_SESSION["reload_xml"] = true; + //set message + message::add($text['message-copy']); + +} //redirect the user - message::add($text['message-copy']); - header("Location: ".PROJECT_PATH."/app/sip_profiles/sip_profiles.php"); - return; + header("Location: sip_profiles.php"); + exit; -?> +?> \ No newline at end of file diff --git a/app/sip_profiles/sip_profile_delete.php b/app/sip_profiles/sip_profile_delete.php index a9b9602b75..60da4e0148 100644 --- a/app/sip_profiles/sip_profile_delete.php +++ b/app/sip_profiles/sip_profile_delete.php @@ -43,46 +43,39 @@ $text = $language->get(); //get the id - if (count($_GET) > 0) { - $id = check_str($_GET["id"]); - } + $sip_profile_uuid = $_GET["id"]; //delete the records - if (strlen($id) > 0) { + if (is_uuid($sip_profile_uuid)) { //get the details of the sip profile $sql = "select * from v_sip_profiles "; - $sql .= "where sip_profile_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(); - foreach ($result as &$row) { + $sql .= "where sip_profile_uuid = :sip_profile_uuid "; + $parameters['sip_profile_uuid'] = $sip_profile_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (is_array($array) && @sizeof($array) != 0) { $sip_profile_name = $row["sip_profile_name"]; $sip_profile_hostname = $row["sip_profile_hostname"]; $sip_profile_description = $row["sip_profile_description"]; } - unset ($prep_statement); + unset($sql, $parameters, $row); //delete the sip profile domains - $sql = "delete from v_sip_profile_domains "; - $sql .= "where sip_profile_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - unset($sql); + $array['sip_profile_domains'][0]['sip_profile_uuid'] = $sip_profile_uuid; //delete the sip profile settings - $sql = "delete from v_sip_profile_settings "; - $sql .= "where sip_profile_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - unset($sql); + $array['sip_profile_settings'][0]['sip_profile_uuid'] = $sip_profile_uuid; //delete the sip profile - $sql = "delete from v_sip_profiles "; - $sql .= "where sip_profile_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - unset($sql); + $array['sip_profiles'][0]['sip_profile_uuid'] = $sip_profile_uuid; + + //execute delete + $database = new database; + $database->app_name = 'sip_profiles'; + $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470'; + $database->delete($array); + unset($array); //delete the xml sip profile and directory unlink($_SESSION['switch']['conf']['dir']."/sip_profiles/".$sip_profile_name.".xml"); @@ -106,11 +99,14 @@ //clear the cache $cache = new cache; $cache->delete("configuration:sofia.conf:".$sip_profile_name); + + //set message + message::add($text['message-delete']); + } //redirect the browser - message::add($text['message-delete']); header("Location: sip_profiles.php"); - return; + exit; -?> +?> \ No newline at end of file diff --git a/app/sip_profiles/sip_profile_domain_delete.php b/app/sip_profiles/sip_profile_domain_delete.php index 2f8255df29..d025e49183 100644 --- a/app/sip_profiles/sip_profile_domain_delete.php +++ b/app/sip_profiles/sip_profile_domain_delete.php @@ -42,35 +42,40 @@ $language = new text; $text = $language->get(); -//delete the data - if (is_uuid($_GET["id"])) { +//get the id + $sip_profile_domain_uuid = $_GET["id"]; - //get the id - $id = $_GET["id"]; +//delete the data + if (is_uuid($sip_profile_domain_uuid)) { //get the details of the sip profile - $sql = "select * from v_sip_profile_domains "; - $sql .= "where sip_profile_domain_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(); - if (is_array($result)) { - foreach ($result as &$row) { - $sip_profile_uuid = $row["sip_profile_uuid"]; - } - } - unset ($prep_statement); + $sql = "select sip_profile_uuid "; + $sql .= "from v_sip_profile_domains "; + $sql .= "where sip_profile_domain_uuid = :sip_profile_domain_uuid "; + $parameters['sip_profile_domain_uuid'] = $sip_profile_domain_uuid; + $database = new database; + $sip_profile_uuid = $database->select($sql, $parameters, 'column'); - //delete sip_profile_domain - $sql = "delete from v_sip_profile_domains "; - $sql .= "where sip_profile_domain_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - unset($sql); + //build array + $array['sip_profile_domains'][0]['sip_profile_domain_uuid'] = $sip_profile_domain_uuid; + + //execute delete + $database = new database; + $database->app_name = 'sip_profiles'; + $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470'; + $database->delete($array); + unset($array); + + //set message + message::add($text['message-delete']); + + //redirect the user + header('Location: sip_profile_edit.php?id='.$sip_profile_uuid); + exit; } -//redirect the user - message::add($text['message-delete']); - header('Location: sip_profile_edit.php?id='.$sip_profile_uuid); +//default redirect + header('Location: sip_profiles.php'); + exit; -?> +?> \ No newline at end of file diff --git a/app/sip_profiles/sip_profile_edit.php b/app/sip_profiles/sip_profile_edit.php index 42b96e02ec..fe61e7e1fb 100644 --- a/app/sip_profiles/sip_profile_edit.php +++ b/app/sip_profiles/sip_profile_edit.php @@ -43,9 +43,9 @@ $text = $language->get(); //action add or update - if (isset($_REQUEST["id"])) { + if (is_uuid($_REQUEST["id"])) { $action = "update"; - $sip_profile_uuid = check_str($_REQUEST["id"]); + $sip_profile_uuid = $_REQUEST["id"]; } else { $action = "add"; @@ -53,11 +53,11 @@ //get http post variables and set them to php variables if (is_array($_POST)) { - $sip_profile_uuid = check_str($_POST["sip_profile_uuid"]); - $sip_profile_name = check_str($_POST["sip_profile_name"]); - $sip_profile_hostname = check_str($_POST["sip_profile_hostname"]); - $sip_profile_enabled = check_str($_POST["sip_profile_enabled"]); - $sip_profile_description = check_str($_POST["sip_profile_description"]); + $sip_profile_uuid = $_POST["sip_profile_uuid"]; + $sip_profile_name = $_POST["sip_profile_name"]; + $sip_profile_hostname = $_POST["sip_profile_hostname"]; + $sip_profile_enabled = $_POST["sip_profile_enabled"]; + $sip_profile_description = $_POST["sip_profile_description"]; } //process the user data and save it to the database @@ -65,12 +65,12 @@ //get the uuid from the POST if ($action == "update") { - $sip_profile_uuid = check_str($_POST["sip_profile_uuid"]); + $sip_profile_uuid = $_POST["sip_profile_uuid"]; } //check for all required data $msg = ''; - if (strlen($sip_profile_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_uuid']."
\n"; } + //if (strlen($sip_profile_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_uuid']."
\n"; } if (strlen($sip_profile_name) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_name']."
\n"; } //if (strlen($sip_profile_hostname) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_hostname']."
\n"; } if (strlen($sip_profile_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_enabled']."
\n"; } @@ -88,72 +88,74 @@ return; } - //cleanup the array - $x = 0; - foreach ($_POST["sip_profile_domains"] as $row) { - //unset the empty row - if (strlen($_POST["sip_profile_domains"][$x]["sip_profile_domain_name"]) == 0) { - unset($_POST["sip_profile_domains"][$x]); - } - if (strlen($_POST["sip_profile_domains"][$x]["sip_profile_domain_alias"]) == 0) { - unset($_POST["sip_profile_domains"][$x]); - } - if (strlen($_POST["sip_profile_domains"][$x]["sip_profile_domain_parse"]) == 0) { - unset($_POST["sip_profile_domains"][$x]); - } - //increment the row - $x++; - } - - //cleanup the array - $x = 0; - foreach ($_POST["sip_profile_settings"] as $row) { - //unset the empty row - if (strlen($_POST["sip_profile_settings"][$x]["sip_profile_setting_name"]) == 0) { - unset($_POST["sip_profile_settings"][$x]); - } - //if (strlen($_POST["sip_profile_settings"][$x]["sip_profile_setting_value"]) == 0) { - // unset($_POST["sip_profile_settings"][$x]); - //} - if (strlen($_POST["sip_profile_settings"][$x]["sip_profile_setting_enabled"]) == 0) { - unset($_POST["sip_profile_settings"][$x]); - } - //increment the row - $x++; - } - //add the sip_profile_uuid - if (strlen($_POST["sip_profile_uuid"]) == 0) { + if (!is_uuid($_POST["sip_profile_uuid"])) { $sip_profile_uuid = uuid(); $_POST["sip_profile_uuid"] = $sip_profile_uuid; } + //cleanup the array + foreach ($_POST["sip_profile_domains"] as $index => $row) { + //populate sip profile uuid + if (!is_uuid($row['sip_profile_uuid'])) { + $_POST["sip_profile_domains"][$index]['sip_profile_uuid'] = $sip_profile_uuid; + } + //unset the empty row + if (strlen($row["sip_profile_domain_name"]) == 0) { + unset($_POST["sip_profile_domains"][$index]); + } + if (strlen($row["sip_profile_domain_alias"]) == 0) { + unset($_POST["sip_profile_domains"][$index]); + } + if (strlen($row["sip_profile_domain_parse"]) == 0) { + unset($_POST["sip_profile_domains"][$index]); + } + } + + //cleanup the array + foreach ($_POST["sip_profile_settings"] as $index => $row) { + //populate sip profile uuid + if (!is_uuid($row['sip_profile_uuid'])) { + $_POST["sip_profile_settings"][$index]['sip_profile_uuid'] = $sip_profile_uuid; + } + //unset the empty row + if (strlen($row["sip_profile_setting_name"]) == 0) { + unset($_POST["sip_profile_settings"][$index]); + } + //if (strlen($row["sip_profile_setting_value"]) == 0) { + // unset($_POST["sip_profile_settings"][$index]); + //} + if (strlen($row["sip_profile_setting_enabled"]) == 0) { + unset($_POST["sip_profile_settings"][$index]); + } + } + //prepare the array $array['sip_profiles'][] = $_POST; + //grant temporary permissions + $p = new permissions; + $p->add('sip_profile_domain_add', 'temp'); + $p->add('sip_profile_setting_add', 'temp'); + //save to the data $database = new database; $database->app_name = 'sip_profiles'; - $database->app_uuid = null; - if (strlen($sip_profile_uuid) > 0) { - $database->uuid($sip_profile_uuid); - } + $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470'; $database->save($array); $message = $database->message; - //debug info - //echo "
";
-			//print_r($message);
-			//echo "
"; - //exit; - - //get the hostname + //get the hostname $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $switch_cmd = "switchname"; $sip_profile_hostname = event_socket_request($fp, 'api '.$switch_cmd); } + //revoke temporary permissions + $p->delete('sip_profile_domain_add', 'temp'); + $p->delete('sip_profile_setting_add', 'temp'); + //clear the cache $cache = new cache; $cache->delete("configuration:sofia.conf:".$sip_profile_hostname); @@ -165,44 +167,41 @@ $_SESSION["reload_xml"] = true; //redirect the user - if (isset($action)) { - if ($action == "add") { - message::add($text['message-add']); - } - if ($action == "update") { - message::add($text['message-update']); - } - header('Location: sip_profile_edit.php?id='.escape($sip_profile_uuid)); - return; + if ($action == "add") { + message::add($text['message-add']); } - } //(is_array($_POST) && strlen($_POST["persistformvar"]) == 0) + if ($action == "update") { + message::add($text['message-update']); + } + header('Location: sip_profile_edit.php?id='.escape($sip_profile_uuid)); + exit; + } //pre-populate the form if (is_array($_GET) && $_POST["persistformvar"] != "true") { - $sip_profile_uuid = check_str($_GET["id"]); + $sip_profile_uuid = $_GET["id"]; $sql = "select * from v_sip_profiles "; - $sql .= "where sip_profile_uuid = '$sip_profile_uuid' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($sip_profiles as $key => $row) { $sip_profiles[$key] = array_map("escape", $row); } - foreach ($sip_profiles as $row) { + $sql .= "where sip_profile_uuid = :sip_profile_uuid "; + $parameters['sip_profile_uuid'] = $sip_profile_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (is_array($row) && @sizeof($row) != 0) { $sip_profile_name = $row["sip_profile_name"]; $sip_profile_hostname = $row["sip_profile_hostname"]; $sip_profile_enabled = $row["sip_profile_enabled"]; $sip_profile_description = $row["sip_profile_description"]; } - unset ($prep_statement); + unset($sql, $parameters, $row); } //get the child data $sql = "select * from v_sip_profile_settings "; - $sql .= "where sip_profile_uuid = '".$sip_profile_uuid."' "; + $sql .= "where sip_profile_uuid = :sip_profile_uuid "; $sql .= "order by sip_profile_setting_name "; - $prep_statement = $db->prepare($sql); - $prep_statement->execute(); - $sip_profile_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($sip_profile_settings as $key => $row) { $sip_profile_settings[$key] = array_map("escape", $row); } + $parameters['sip_profile_uuid'] = $sip_profile_uuid; + $database = new database; + $sip_profile_settings = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); //add an empty row $x = count($sip_profile_settings); @@ -215,11 +214,11 @@ //get the child data $sql = "select * from v_sip_profile_domains "; - $sql .= "where sip_profile_uuid = '".$sip_profile_uuid."' "; - $prep_statement = $db->prepare($sql); - $prep_statement->execute(); - $sip_profile_domains = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($sip_profile_domains as $key => $row) { $sip_profile_domains[$key] = array_map("escape", $row); } + $sql .= "where sip_profile_uuid = :sip_profile_uuid "; + $parameters['sip_profile_uuid'] = $sip_profile_uuid; + $database = new database; + $sip_profile_domains = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); //add an empty row $x = count($sip_profile_domains); @@ -251,7 +250,12 @@ echo "".$text['title-sip_profile']."

\n"; echo "\n"; echo " "; - echo " \n"; + if (permission_exists('dialplan_add') + || permission_exists('inbound_route_add') + || permission_exists('outbound_route_add') + || permission_exists('time_condition_add')) { + echo " \n"; + } echo " "; echo "\n"; echo "\n"; @@ -261,7 +265,7 @@ echo " ".$text['label-sip_profile_name']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-sip_profile_name']."\n"; echo "\n"; @@ -279,16 +283,16 @@ echo " ".$text['label-sip_profile_domain_parse']."\n"; echo " \n"; $x = 0; - foreach($sip_profile_domains as $row) { + foreach ($sip_profile_domains as $row) { echo " \n"; - if (strlen($row["sip_profile_domain_uuid"]) > 0) { + if (is_uuid($row["sip_profile_domain_uuid"])) { $sip_profile_domain_uuid = $row["sip_profile_domain_uuid"]; } - if (strlen($row["sip_profile_uuid"]) > 0) { + if (is_uuid($row["sip_profile_uuid"])) { $sip_profile_uuid = $row["sip_profile_uuid"]; } echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo "   \n"; echo " \n"; @@ -332,10 +336,18 @@ echo " \n"; echo " \n"; if (strlen($row["sip_profile_domain_name"]) > 0) { - echo " \n"; + echo " \n"; } echo " \n"; echo " \n"; + //convert last empty labels to form elements + if ($row["sip_profile_domain_name"] == '' && $row["sip_profile_domain_alias"] == '' && $row["sip_profile_domain_parse"] == '') { + echo "\n"; + } $x++; } echo " \n"; @@ -355,18 +367,17 @@ echo " ".$text['label-sip_profile_setting_description']."\n"; echo " \n"; $x = 0; - foreach($sip_profile_settings as $row) { + foreach ($sip_profile_settings as $row) { echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo "   \n"; - echo " \n"; + echo " \n"; echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; echo " \n"; echo " \n"; @@ -396,6 +407,16 @@ } echo " \n"; echo " \n"; + //convert last empty labels to form elements + if ($row["sip_profile_setting_name"] == '' && $row["sip_profile_setting_value"] == '' && $row["sip_profile_setting_enabled"] == '' && $row["sip_profile_setting_description"] == '') { + echo "\n"; + } + $x++; $x++; } echo " \n"; @@ -419,7 +440,6 @@ echo "\n"; echo "\n"; echo " \n"; } + echo "
\n"; echo " \n"; echo " \n"; echo " "; @@ -464,4 +485,4 @@ //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/sip_profiles/sip_profile_setting_delete.php b/app/sip_profiles/sip_profile_setting_delete.php index 3803b1610f..a10b34053e 100644 --- a/app/sip_profiles/sip_profile_setting_delete.php +++ b/app/sip_profiles/sip_profile_setting_delete.php @@ -38,29 +38,32 @@ else { $language = new text; $text = $language->get(); -if (count($_GET)>0) { - $id = check_str($_GET["id"]); - $sip_profile_uuid = check_str($_GET["sip_profile_uuid"]); -} - -if (strlen($id)>0) { - //delete the sip profile setting - $sql = "delete from v_sip_profile_settings "; - $sql .= "where sip_profile_setting_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - unset($sql); +//get ids + $sip_profile_setting_uuid = $_GET["id"]; + $sip_profile_uuid = $_GET["sip_profile_uuid"]; +if (is_uuid($sip_profile_setting_uuid) && is_uuid($sip_profile_uuid)) { + //build array + $array['sip_profile_settings'][0]['sip_profile_setting_uuid'] = $sip_profile_setting_uuid; + //execute delete + $database = new database; + $database->app_name = 'sip_profiles'; + $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470'; + $database->delete($array); + unset($array); //save the sip profile xml save_sip_profile_xml(); - //apply settings reminder $_SESSION["reload_xml"] = true; + //set message + message::add($text['message-delete']); + //redirect + header("Location: sip_profile_edit.php?id=".$sip_profile_uuid); + exit; } -//redirect the browser - message::add($text['message-delete']); - header("Location: sip_profile_edit.php?id=".$sip_profile_uuid); - return; +//default redirect + header("Location: sip_profiles.php"); + exit; ?> \ No newline at end of file diff --git a/app/sip_profiles/sip_profiles.php b/app/sip_profiles/sip_profiles.php index 629f047d79..5a1e0c318b 100644 --- a/app/sip_profiles/sip_profiles.php +++ b/app/sip_profiles/sip_profiles.php @@ -43,16 +43,17 @@ $text = $language->get(); //get variables used to control the order - $order_by = check_str($_GET["order_by"]); - $order = check_str($_GET["order"]); + $order_by = $_GET["order_by"]; + $order = $_GET["order"]; //add the search term - $search = strtolower(check_str($_GET["search"])); + $search = strtolower($_GET["search"]); if (strlen($search) > 0) { - $sql_search = "and ("; - $sql_search .= "lower(sip_profile_name) like '%".$search."%' "; - $sql_search .= "or lower(sip_profile_hostname) like '%".$search."%' "; + $sql_search = "where ("; + $sql_search .= "lower(sip_profile_name) like :search "; + $sql_search .= "or lower(sip_profile_hostname) like :search "; $sql_search .= ") "; + $parameters['search'] = '%'.$search.'%'; } //additional includes @@ -60,21 +61,9 @@ require_once "resources/paging.php"; //prepare to page the results - $sql = "select count(sip_profile_uuid) as num_rows from v_sip_profiles "; - $sql .= "where 1 = 1 "; - $sql .= $sql_search; - if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } - $prep_statement = $db->prepare($sql); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] > 0) { - $num_rows = $row['num_rows']; - } - else { - $num_rows = '0'; - } - } + $sql = "select count(*) from v_sip_profiles "; + $database = new database; + $num_rows = $database->select($sql, null, 'column'); //prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; @@ -85,16 +74,13 @@ $offset = $rows_per_page * $page; //get the list - $sql = "select * from v_sip_profiles "; - $sql .= "where 1 = 1 "; + $sql = str_replace('count(*)', '*', $sql); $sql .= $sql_search; - if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } - $sql .= "limit $rows_per_page offset $offset "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($sip_profiles as $key => $row) { $sip_profiles[$key] = array_map("escape", $row); } - unset ($prep_statement, $sql); + $sql .= order_by($order_by, $order); + $sql .= limit_offset($rows_per_page, $offset); + $database = new database; + $sip_profiles = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); //escape the search $search = escape($search); @@ -139,28 +125,28 @@ echo "\n"; if (is_array($sip_profiles)) { - foreach($sip_profiles as $row) { + foreach ($sip_profiles as $row) { if (permission_exists('sip_profile_edit')) { - $tr_link = "href='sip_profile_edit.php?id=".$row['sip_profile_uuid']."'"; + $tr_link = "href='sip_profile_edit.php?id=".escape($row['sip_profile_uuid'])."'"; } echo "\n"; - echo " ".$row['sip_profile_name']." \n"; - echo " ".$row['sip_profile_hostname']." \n"; - echo " ".$row['sip_profile_enabled']." \n"; - echo " ".$row['sip_profile_description']." \n"; + echo " ".escape($row['sip_profile_name'])." \n"; + echo " ".escape($row['sip_profile_hostname'])." \n"; + echo " ".escape($row['sip_profile_enabled'])." \n"; + echo " ".escape($row['sip_profile_description'])." \n"; echo " "; if (permission_exists('sip_profile_edit')) { - echo "$v_link_label_edit"; + echo "$v_link_label_edit"; } if (permission_exists('sip_profile_delete')) { - echo "$v_link_label_delete"; + echo "$v_link_label_delete"; } echo " \n"; echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } - } //end foreach - unset($sql, $sip_profiles); - } //end if results + $c = $c ? 0 : 1; + } + } + unset($sip_profiles, $row); echo "\n"; echo "\n"; @@ -186,4 +172,4 @@ //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file