Porting 2.11 version 'Wake Up Calls" module to V14

During reload.

Code is here: hotelwakeup/functions.inc.php at release/13.0 · FreePBX/hotelwakeup · GitHub

This is also where it calls the AGI that you said you couldn’t find.

Function is being called here hotelwakeup/functions.inc.php at 7ea43c7b67e3171769b052514438841d342216ce · FreePBX/hotelwakeup · GitHub

Thank you - working.

I had removed the two functions as I could not find references to it.:blush: (There was a sort of warning text that registered at the back of my mind but I ignored it)

Added the two functions and did a reload and all seems to be well.

I just need to do some tidying up and some thorough testing.

How do I package it all up to do a fresh install? Just a simple zip of the folder?

I want to uninstall it and test it starting from the install.

Yes that will work

Correction: Not quite working.

  1. Originally *67 (feature code for my module) did not work
  2. Added back the two missing functions - working.
  3. I then realized that the function contained a reference to:
    ext_AGI(‘wakeup’))
    and I did not have such a file in my agi-bin folder.
  4. Conclusion: that these files are global and my *67 was picking up the routine in hotelwakeup.
  5. Copied over the file to my module/agi-bin and called it wakeup67.
  6. Renamed all references there from hotelwakeup to wakeupalarm (some with a capital W)
  7. Changed my function to reference wakeup67.
  8. Did a reload.
  9. Not working
  10. Changed function back to point to ‘wakeup’, did a reload and it works again.

Any suggestions?

Why don’t you just do your work in the original module and contribute back?

Agis are copied to the agi-bin folder on reload from the agi folder in the module. If this wasn’t working then dialparties wouldn’t be copied and your system would not function.

I most certainly would like to contribute my module as a replacement for hotelwakeup.

I tried to use that as a base (twice) but wasted days on it. I just could not get to grips with trying to extend the pop-up forms to do what I wanted.

So I went for ringroups as the base it was more ‘traditional’.

The php code i’m using is based on that in hotelwakeup but significantly extended.

So once it is working I would be only too happy to hand it over for it to replace hotelwakeup.

It seems to be working as expected except for this feature code issue.

Further to your comments, I have found that the ‘wakeup67’ agi file is being copied and it in fact runs when *67 is dialed, but is dying at the last line below:

$restrict_mods = true;
include ‘/etc/freepbx.conf’;
set_time_limit(0);
error_reporting(0);
require_once “phpagi.php”;
$AGI = new AGI();
$AGI->answer();
$config = FreePBX::Wakeupalarms()->getConfig();

The function does exist inside functions.inc.php in </var/www/html/admin/modules/wakeupalarms>

function wakeupalarms_getConfig() {
$dbh = \FreePBX::Database();

A debug line at the front of that function does not get executed so the call is failing.

If I copy that function to the agi file and call it locally it all works.

There is a later reference in the file to an other module function and it now fails there.

Seems like the module is not properly registered. My module.xml file listing is below

<module>
<rawname>wakeupalarms</rawname>
<repo>local</repo>
<name>Wakeup Alarms</name>
<version>14.0.0.1</version>
<publisher>Les Desser</publisher>
<license>GPLv3+</license>
<licenselink>http://www.gnu.org/licenses/gpl-3.0.txt</licenselink>
<category>Applications</category>
<description>
	Allows the creation of future wakeup alarm calls. Calls can be one-off or repeating. The details are stored in the database.
</description>
<changelog>
	*14.0.0.1*  Initial clone and update: Based on Wakeupalarms to incorporate v14 design
</changelog>
<depends>
	<version>13.0.1</version>
</depends>
<menuitems>
	<wakeupalarms>Wakeup Alarms</wakeupalarms>
</menuitems>
<popovers>
	<wakeupalarms>
		<display>wakeupalarms</display>
		<view>form</view>
	</wakeupalarms>
</popovers>
<supported>
	<version>14.0</version>
</supported>
<location/>
<md5sum/>

“getConfig” wouldn’t exist inside of there because you are calling it as a class reference. It would be in Wakeupalarms.class.php under /var/www/html/admin/modules/wakeupalarms

The name of this function is “wakeupalarms_getConfig” It’s a procedural function so you need to call it like “wakeupalarms_getConfig()” so.

FreePBX::Wakeupalarms()->getConfig(); is not equal to wakeupalarms_getConfig()

Ops! I moved some functions from the class file to functions as, again, I found no relevant references to them.

This ‘class’ methodology is all new to me.

Thank you.

I have hit an other issue - probably due to ignorance. I would be grateful for some suggestions as to what could be going wrong.

In the original Hotewakeup module there is an agi script wakeupconfirm.php.

There is the following line in there:

FreePBX::Hotelwakeup()->addWakeup($number,$time_wakeup,$lang);

which I understand as referencing function addWakeup in the hotelwakeup class file Hotelwakeup.class.php.

It works.

I have an identical line in my equivalent wakeconfirmalarm.php agi script in module wakeupalarms

FreePBX::Wakeupalarms()->addWakeup($number,$time_wakeup,$lang);

with the addWakeup function in my wakeupalarms class file Wakeupalarms.class.php

public function addWakeup($destination, $time, $lang) {

The function does not execute. I have a debug line as the first line in the function and it is not executed.

What could be the cause?

Is there a log file which may show up some error when the call is executed?

The agi script does not actually crash as a debug line after the call to the addWakeup function does run.

We would be unable to tell you without seeing your code in full. You should search out ‘how to debug in PHP’ on the internet.

Thank you for the prompt response.

I take the point and will follow it up.

Maybe you could just answer the question: Is there anything special that needs to be done in the agi script to enable it to ‘find’ the class function?

My script is built on the original with minor changes but I may have inadvertently removed a line.

Also, I’m not far from finishing this module. How do I go about sharing with others to review and test?

I can’t answer this blindly… Show us your AGI in full and then I can.

Found that Ctrl+Shift+C does it

#!/usr/bin/env php
<?php
//	License for all code of this FreePBX module can be found in the license file inside the module directory
//	Copyright 2013 Schmooze Com Inc.
//

// Bootstrap FreePBX but don't include any modules (so you won't get anything
// from the functions.inc.php files of all the modules.)
//
# Called from a call file when an alarm goes off
	$restrict_mods = true;
	include '/etc/freepbx.conf';
	set_time_limit(0);
	error_reporting(0);

// Connect to AGI:
//
	require_once "phpagi.php";
	$AGI = new AGI();
	$AGI->answer();
	$lang = $AGI->request['agi_language'];
	if($lang == 'ja') sim_playback($AGI, "this-is-yr-wakeup-call");
	else sim_playback($AGI, "hello&this-is-yr-wakeup-call");
	$time_wakeup = time();
// Default back to English if channel doesn't match other languages
	if($lang == 'ja') $digit = sim_background($AGI, "wakeup-menu","1234",1);
	else $digit = sim_background($AGI, "to-cancel-wakeup&press-1&to-snooze-for&digits/5&minutes&press-2&to-snooze-for&digits/10&minutes&press-3&to-snooze-for&digits/15&minutes&press-4","1234",1);
# Get Extension number
	$number = $AGI->request['agi_extension'];
	switch($digit) {
		case 1:
		  # Requested to delete alarm. Do nothing as Astrisk deletes it anyway
			if($lang == 'ja') sim_playback($AGI, "wakeup-call-cancelled");
			else sim_playback($AGI, "wakeup-call-cancelled");
		break;
		case 2:
		  # Snooze 5 mins - create a new call file
			$time_wakeup += 300;
		  # Create file immediately - must not be after sim_playback as the code seems to stop if the user hangs up
			FreePBX::Wakeupalarms()->addWakeup($number,$time_wakeup,$lang);
			if($lang == 'ja') sim_playback($AGI, "5-minutes-from-now&rqsted-wakeup-for");
			else sim_playback($AGI, "rqsted-wakeup-for&digits/5&minutes&vm-from&now");
			$AGI->hangup();
		break;
		case 3:
		  # Snooze 10 mins
			$time_wakeup += 600;
			FreePBX::Wakeupalarms()->addWakeup($number,$time_wakeup,$lang);
			if($lang == 'ja') sim_playback($AGI, "10-minutes-from-now&rqsted-wakeup-for");
			else sim_playback($AGI, "rqsted-wakeup-for&digits/10&minutes&vm-from&now");
			$AGI->hangup();
		break;
		case 4:
		  # Snooze 15 mins
			$time_wakeup += 900;
			FreePBX::Wakeupalarms()->addWakeup($number,$time_wakeup,$lang);
			if($lang == 'ja') sim_playback($AGI, "15-minutes-from-now&rqsted-wakeup-for");
			else sim_playback($AGI, "rqsted-wakeup-for&digits/15&minutes&vm-from&now");
			$AGI->hangup();
		break;
	}
sim_playback($AGI, "goodbye");
$AGI->hangup();

/**
 * Simulate playback functionality like the dialplan
 * @param  object $AGI  The AGI Object
 * @param  string $file Audio files combined by/with '&'
 */
#============================================================================
function writelog($log) {
	$NowTime = new DateTime();
	$logfile = "/var/www/html/admin/modules/wakeupalarms/debug.log";
	$x=file_put_contents($logfile, $NowTime->format('Y-m-d H:i:s')." UT: ".$log."\n", FILE_APPEND);
##	echo $NowTime->format('Y-m-d H:i:s')." UT: ".$log."\n";
}
#============================================================================
function sim_playback($AGI, $file) {
	$files = explode('&',$file);
	foreach($files as $f) {
		$AGI->stream_file($f);
	}
}

/**
 * Simulate background playback with added functionality
 * @param  object  $AGI      The AGI Object
 * @param  string  $file     Audio files combined by/with '&'
 * @param  string  $digits   Allowed digits (if we are prompting for them)
 * @param  string  $length   Length of allowed digits (if we are prompting for them)
 * @param  string  $escape   Escape character to exit
 * @param  integer $timeout  Timeout
 * @param  integer $maxLoops Max timeout loops
 * @param  integer $loops    Total loops
 */
function sim_background($AGI, $file,$digits='',$length='1',$escape='#',$timeout=15000, $maxLoops=1, $loops=0) {
	$files = explode('&',$file);
	$number = '';
	$lang = $AGI->request['agi_language'];
	foreach($files as $f) {
		$ret = $AGI->stream_file($f,$digits);
		if($ret['code'] == 200 && $ret['result'] != 0) {
			$number .= chr($ret['result']);
		}
		if(strlen($number) >= $length) {
			break;
		}
	}
	if(trim($digits) != '' && strlen($number) < $length) {
		while(strlen($number) < $length && $loops < $maxLoops) {
			$ret = $AGI->wait_for_digit($timeout);
			if($loops > 0) {
				sim_playback($AGI, "please-try-again");
			}
			if($ret['code'] == 200 && $ret['result'] == 0) {
				if($lang == 'ja') {
					sim_playback($AGI, "you-entered-bad-digits");
				} else {
					sim_playback($AGI, "you-entered&bad&digits");
				}
			} elseif($ret['code'] == 200) {
				$digit = chr($ret['result']);
				if($digit == $escape) {
					break;
				}
				if(strpos($digits,$digit) !== false) {
					$number .= $digit;
					continue; //dont count loops as we are good
				} else {
					if($lang == 'ja') {
						sim_playback($AGI,"you-entered-bad-digits");
					} else {
						sim_playback($AGI,"you-entered&bad&digits");
					}
				}
			} else {
				sim_playback($AGI,"an-error-has-occurred");
			}
			$loops++;
		}
	}
	$number = trim($number);
	return $number;
}

I don’t think there is anything wrong with the above.

I have replaced it with the original from Hotelwakeup and only changed the three lines referencing the original class reference to Wakeupalarms.

I have checked the other agi script (triggered by *67) and that also has the same problem.

For some reason the agi scripts are not finding the Wakeupalarms class.

Andrew: Don’t bother checking this any further at the moment.

I want to do a thorough check as I am getting some inconsistent results.

The problem turned out to be my debug fn did not work when called from an agi script.

I have put my wakeupalarms module on to Github and an install zip file is available for install at github download.

I’m keen for people to try it and provide feedback. Any way to publicize it?

I guess I’m just curious what your reservations are putting the code back into hotel wakeup itself?

None whatsoever - just the reverse. That is where it belongs.

It is a major change and I don’t know how these things are done. I don’t want to mess up the usage of existing users without first trying it (though I suspect there are few users, based on the number of serious bugs in the original).

Tell me what to do and I’m happy to do it. Or better still take the source and put it where it belongs.

I just noticed I still have some ring-group files in there - I will remove them.

Update: Checking further I see these files were not there in my original. I have re-installed wakeupalarms from the new install file and they have somehow re-appeared.

Also, the i18n folder is from ring-groups. I will replace it with the original from hotelwakeup.