Custom Contexts broken in FreePBX

Hi All.
I am using FreePBX which is in the latest Trixbox update I have just freshly installed.
I installed custom contexts as per the instructions on

When I installed the module thu the module admin, this all goes ok, but then when I add a custom context, submit it then click “apply changes” I get the following error. Has anyone else had this error? is there a fix? I see from the tricBox forum that atleast one other who has updated to Trixbox 2.4 also has this error.
Thanks, Jeremy

exit: 1

Checking for PEAR DB…OK
Checking for PEAR Console::Getopt…OK
Checking for /etc/amportal.conf …OK
Bootstrapping /etc/amportal.conf …OK
Parsing /etc/amportal.conf …OK
Parsing /etc/asterisk/asterisk.conf …OK
Connecting to database…OK
Connecting to Asterisk manager interface…OK
Added to globals: ASTETCDIR = /etc/asterisk
Added to globals: ASTMODDIR = /usr/lib/asterisk/modules
Added to globals: ASTVARLIBDIR = /var/lib/asterisk
Added to globals: ASTAGIDIR = /var/lib/asterisk/agi-bin
Added to globals: ASTSPOOLDIR = /var/spool/asterisk
Added to globals: ASTRUNDIR = /var/run/asterisk
Added to globals: ASTLOGDIR = /var/log/asterisk
Added to globals: CWINUSEBUSY = true
Added to globals: AMPMGRUSER = admin
Added to globals: AMPMGRPASS = amp111

Warning: array_keys(): The first argument should be an array in /var/www/html/admin/extensions.class.php on line 189

Warning: Invalid argument supplied for foreach() in /var/www/html/admin/extensions.class.php on line 189
Please update your modules and reload Asterisk by browsing to your server.

1 error(s) occured, you should view the notification log on the dashboard or main screen to check for more details.

there are a few other bugs, but this one crashes.
I must point out that I have not had time to upgrade the module properly, so as before - use at your own risk.
with that said…

the following line
						$sql = "INSERT INTO customcontexts_includes_list (context, include, description, sort) VALUES ('$section', '$include', '$include', $i)";
should be replaced with
						$sql = "INSERT IGNORE INTO customcontexts_includes_list (context, include, description, sort) VALUES ('$section', '$include', '$include', $i)";
/var/www/html/admin/modules/customcontexts/ line 53 of 1411

the module is in the contributed_modules directory on svn. (Which of course you have access to since you have dev access, plus I always give contributors access when modules get put there). You may want to go and update it, there is a publish script right there which you can use to build the tarball and all.

YAY !!! well that SQL script DID fix part of the problem, i.e. I can now save changes again :slight_smile:
Philippe, or anyone else for that matter, do you have a URL or something for the svn where I can get the script etc. you mention?

Thanks, Jeremy

there is a “contributed_modules” directory that is at the same level as “modules” and “freepbx” just browse over on the dev site into the repo and you should see it.

am I in the right place??

Just that I noticed that the files are 4mths old and when I check line 53 as above, its still the same as the old one.

Sorry :slight_smile:


yes you are in the right place. The “contributed_modules” repository are not maintained by the FreePBX team, they are put there as a service for those who want access to them. Until a module is adopted into the main stream release they will only be maintained to the extent that the original contributor chooses to do such, or if someone else wants to volunteer to do some work on them and contacts us about it. I created that repository and moved the module there originally as it had previously been nothing more than a tarball attached to a ticket.

oh I see…I miss inturprited what you meant…I thought the FIX was in this section :slight_smile:
I still get an error displayed at the top of my page “Warning: Invalid argument supplied for foreach() in /var/www/html/admin/modules/customcontexts/ on line 590” when I enter the custom contexts page, but if I ignore that, it still seems to work.


Ok, had a look at line 590, and figured the array being passed might be empty, so I have changed the code below, and it seems to solve the issue. Not sure what the flow on affect would be :-

(at line 590)

		   foreach ($timegroups as $val) 
		      $currentcomponent->addoptlistitem('includeyn', $val[0], $val[1]);


		if (!empty($timegroups))
		   foreach ($timegroups as $val) 
		      $currentcomponent->addoptlistitem('includeyn', $val[0], $val[1]);

I followed all of the instruction listed above and my custom context module appears to now be installed property and does not show any error

If naftali is too busy to maintain it in the contributed repository and someone out there feels comfortable enough to help out I’d be glad to give you svn write access to the contributed repository to do such.

When editing an extension, at bottom apears Warning: Invalid argument supplied for foreach() … at line 405. I make a change like for line 590 (added an if for empty), and now working the warning does not appear…

This would be near and dear to me as well (tieing * with a legacy system). Over at trixbox it wasn’t clear if this was an issue with freepbx or * 1.4. Before I get confused and lost I’m going to try the fixes seen here. I think this would be very useful to many and hope to see it as a core function or module.

this is not planned as standard because the way trunking/routing is going to be ripped out and replaced will completely break this module and the work involved to seamlessly move people to the new design, in addition to the fact that it may not be possible to completely migrate what they were doing, is not something that we are willing to invest in. As you can see, the current author has not had the resourced to even maintain this for the few issues that have come up here…

ok thanks. Does the functionality of controlling outbound trunks per extension as is often asked sound like something that could get into the new design? Not as an unmaintained module (thanks to the author anyway) like it is but as a core function for at least this feature? I’m trying to come up with a way to have SIP extensions get to the legacy via a specific FXO line so that the lego extension knows who is calling (lego won’t pass the * extension and only sees the line it came in on).

And thanks again for your help these last weeks. I’m online and functional with only a few kinks left to beat down.

edit-> you said it wouldn’t be standard, sorry.

yes - dial context will have abilities such as creating different route arrangements for different dial contexts.

excellent… Thanks, I know a lot of people will be very thankful for that one.
Now if I can get my local Bell and friends to bring back ISDN I’ll be a happy camper…

r5617, r5618 - I bumped it up to 0.3.4 with the above suggested fix

But what about jscoulter fix, of the 590 line?

how about someone step up to the plate and volunteer to maintain the module, as it seems like there is a small following.

There are plenty of other places in that code from the few minutes I looked at it that have similar bugs in them to line 590. The module is not in the main repository for a variety of reasons so it is not maintained by our development ‘staff’ of volunteers. However, being in the contributed modules directory, we are happy to give a reasonably responsible person write access to that area so that they can maintain this or other contributed modules located there.