Toll Allow

voipBull

Active Member
Dec 3, 2023
123
25
28
Hello community,

Is there a way to pre-populate a drop-down list of 'Tollallow' options, instead of the default free-form text field for Tollallow?

I was looking through the code in `extension_edit.php` and found the below piece of code. By the looks of it, it does look for an array type session variable 'toll allow' that will present the data into a drop-down list.

Code:
if (permission_exists('extension_toll')) {
        echo "<tr>\n";
        echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
        echo "    ".$text['label-toll_allow']."\n";
        echo "</td>\n";
        echo "<td class='vtable' align='left'>\n";
        if (!empty($_SESSION['toll allow']['name']) && is_array($_SESSION['toll allow']['name'])) {
            echo "    <select class='formfld' name='toll_allow' id='toll_allow'>\n";
            echo "        <option value=''></option>\n";
            foreach ($_SESSION['toll allow']['name'] as $name) {
                if ($name == $toll_allow) {
                    echo "        <option value='".escape($name)."' selected='selected'>".escape($name)."</option>\n";
                }
                else {
                    echo "        <option value='".escape($name)."'>".escape($name)."</option>\n";
                }
            }
            echo "    </select>\n";
        }
        else {
            echo "    <input class='formfld' type='text' name='toll_allow' maxlength='255' value=\"".escape($toll_allow ?? '')."\">\n";
        }
        echo "<br />\n";
        echo $text['description-toll_allow']."\n";
        echo "</td>\n";
        echo "</tr>\n";
    }

I couldn't find where this 'toll allow' session variable is being set. Anyone has any idea? or is this just legacy code that is not in use anymore.

Thanks
 
A session variable for `toll allow` is not set. You can add print_r or var_dump debugging code to extension_edit.php to verify this. The FusionPBX code for toll allow has been written to allow any text in this field and the code as it is written allows for you to add a session variable to the page to turn the toll allow into a set drop-down list with
PHP:
$_SESSION['toll allow']['name'] = ['voipBull', 'local', 'longdistance', 'international'];

1745960860567.png

But this method of code insertion will be in conflict with running code updates, and other issues of global session variables. If you want toll allow to be populated from a default setting or domain setting then you would need to add a small amount of code in a couple of locations on the page and rewrite the toll allow section to pull from default settings or domain settings variables.

There are other ways in which you may populate session variable. Each method, including default settings/domain settings, you will need to think through all scenarios to allow for the level of flexibility required.
 
Thanks @whut thats definitely one way to do it. But as you said, it complicates future updates and upgrades. What I’m really thinking about is how tollallow could evolve into a lightweight, pluggable application that offers granular yet intuitive control over call restrictions for all types of extensions that have the ability to dial PSTN destinations. Right now, it's just a string-matching mechanism, and when setting up new extensions, you have to remember and manually input the correct tollallow strings that were used for outbound routes.
Instead tollallow could function more like a call permissions manager where groups could be predefined (like "US", "Canada", "International"....) along with the country codes/NPA's that are allowed to dial with that group, and then can be made available to be selected when creating new extensions of any type, eliminating guesswork and reducing human error. This would simplify call permissions management and enhance overall control across the system.
 
I believe country code and area code inclusion would require unnecessary overhead to maintain tables with this data and would require a lot of development to organize. This data changes more often than we would expect. Another downfall with this would be when new country and area codes are introduced or they are rearranged this will negatively impact your ability to make calls. It is legally imperative that emergency dialing is not blocked in anyway.

I would suggest to keep it more simple with a small modification of the toll allow field to be

- if session variables set - use dropdown (leave as it is now)
- ADD else if default setting / domain setting / extension setting toll allow array is enabled - use the array in a dropdown
- else - use textbox (leave as it is now)

Focusing on North America as the example I would imagine the entries coulb be something like
0. extension to extension dialing only (local / internal)
1. country / north america including emergency services
2. international

With each "level up in allowance" to allow it's level of dialing + the levels below.

This method allows for existing toll allow configurations to not be broken and does not focus the functionality too narrowly for one region/country. This method also reduces misspelling of toll allow values.

The great value of FusionPBX is that it is so powerful and flexible. The downside of FusionPBX is that it is so powerful and flexible. powerful and flexibility != simplicity.
 
A session variable for `toll allow` is not set. You can add print_r or var_dump debugging code to extension_edit.php to verify this. The FusionPBX code for toll allow has been written to allow any text in this field and the code as it is written allows for you to add a session variable to the page to turn the toll allow into a set drop-down list with
PHP:
$_SESSION['toll allow']['name'] = ['voipBull', 'local', 'longdistance', 'international'];

View attachment 4600
The code change isn't needed.

Toll Allow was built for default settings and domain settings using type array.

Category: toll allow
Subcategory: name
Type: array
Value: international

Add more default settings to increase the list.
 
Thank you @markjcrane I gave it a try, but it doesn’t quite work as expected out of the box. When adding or saving a new default setting with the category set as 'toll allow', the space gets stripped and it’s saved as 'tollallow'. This causes it not to match with the session variable $_SESSION['toll allow']['name'] that extension_edit.php looks for. It starts working once I update lines 1910 and 1913 to reference $_SESSION['tollallow']['name'] instead.
After making that change and adding a few entries via the default settings to build a list, I noticed another limitation. the toll allow field only supports selecting a single value from the dropdown, but in most setups its usually required to allow assigning multiple toll allow strings per extension. I think replacing the dropdown with a multi-select checkbox interface would be a better fit for this use case.
 
@voipBull Thanks for reporting that. I tested it and duplicated the issue you reported. And then added a spaced in the regular expression so it would allow the space. If you update your system it should work now.
 
Would it be better to update the session variable to toll_allow so the default settings will all be consistent with all default setting categories that are more than 1 word?

eg:
default_setting_category
call_block
call_center
call_flow
call_recordings
conference_center
fax_queue
follow_me
ivr_menu
operator_panel
ring_group
time_conditions
 
@markjcrane Thank you. Just tried it again. Yes, it works (partially), but a few things to note here.

1. After adding the new category 'toll allow', use the search dropdown on the default settings page and select 'Toll allow'. Nothing shows up. But 'Toll allow' is there when you're using either 'All', 'Custom' or 'Category...' on the default settings search dropdown.
2. Toll allow dropdown is not showing on other pages, like Outbound routes, Fax server, Call Broadcast, Ring Groups etc. Looks like the code for these pages doesn't even look for the tollallow session variable array.
3. There is usually a need to assign/select multiple tollallow strings per extension to give them access to specific outbound routes, which is not possible with this current dropdown method for the tollallow field. Like I mentioned earlier, would replacing the dropdown with a multi-select checkbox be a better fit here?