FreePBX | Register | Issues | Wiki | Portal | Support

[HOW TO] Relatively simple interface to TimeTrex for FreePBX/PIAF users

(Jerry) #41

Thanks for replying so quickly. I read the thread a few times and checked and confirmed all users a few times. I moved all permissions to this user as well.

I tried a new user, logged in and changed the password and tried the original admin user that was created in the initial setup.

If you are available, I will pay for your time to help me directly if thats something you can do.

(Dave Burgess) #42

This rings a bell. In TimeTrex, you have to log in as the Time Accounting user and set the password. The password you use there has to match the Admin user in FreePBX and in TimeTrex.

(Jerry) #43

Sorry if this is a simple question but I am not sure of the answer. What is the “Time Accounting” user?

I dont have such a user and cant find it anywhere. I searched on google as well for “Timetrex Time Accouting User” and couldnt find anything.

Just to clarify, both of the administrators, the original one created and the new one i created both have all permissions added from the permissions tab.

Edit -
Sorry for all the questions, just scratching my head on this one and cant figure it out

(Dave Burgess) #44

You have to add an administrator that you want to use for the Time Accounting stuff in FreePBX. This (with whatever name you want to use) is your Time Accounting user in TimeTrex. Once you get logged in on that user in TimeTrex (the first time) you will be forced to reset the password on that user.

After you get that squared away, you need to set this user information in the AGI script so that your user can log into TimeTrex and get this going. For completeness I also add the user as an Admin user in FreePBX and give them the same credentials.

To - one last time - you need to set the Username for the TimeTrex script in TimeTrex (as an admin), in the script itself (TIMETREX_USER), and in the Administrators list in FreePBX.

Remember, you have to log into TimeTrex as the user in order to verify the user and make it so that the user can interact with TimeTrex.

(Jerry) #45

Thanks for the detailed reply.

I already tried all the steps that you mentioned and created the users as an asterisk manager and freepbx admin user. Both of those users with full freepbx and asterisk manager rights and permissions. I created the user in the ampusrs and usermanager. I tried both and individually with the same results.

The original timetrex user I am able to login directly to timetrex and the added user I logged in with as well and changed the password to the new password I am using everywhere. To make it easier for testing, both of these users have the same password but just a different username.

I just tried it again after you posted your steps to confirm everything :frowning:

I am using Freepbx 14 if it helps.

When I tried by dialing into the script it also fails. Just wanted to point that out as well.

edit - I will add my code in one moment

#!/usr/bin/php -q
$type_id[10] = 'Regular';
$type_id[20] = 'Lunch';
$type_id[30] = 'Break';
$type_id[40] = '';
$status_id[0] = 'Auto';
$status_id[10] = 'In';
$status_id[20] = 'Out';
$status_id[30] = 'Absent';


 Global variables - modify these defaults to suit your system.
$TIMETREX_HOST = "x.x.x.x";
$TIMETREX_URL = 'http://x.x.x.x/timetrex/api/soap/api.php';
$TIMETREX_USERNAME = 'timetrexadmin';
$TIMETREX_PASSWORD = 'password';

These following will be replaced when the AGI is executed by Asterisk. 
All of the following are actually information entries from TimeTrex (users) or are stored as
part of the punch.

$ASTERISK = 500;                # A Asterisk extension/TimeTrex special user
$EXTENSION = 500;            # Default phone extension (in case AGI below fails)
$EMPLOYEE = 1000;           # Default User Number (should be fake)
$EMP_PASS = 1000;           # Default Connect Password (bad passcode)

$EMPLOYEE = $argv[1];
$EMP_PASS = $argv[2];
$ASTERISK = $argv[3];
$EXTENSION = $_ENV{"_agi_extension"}; 

  $api_session = new TimeTrexClientAPI();
   echo "Login Failed! \n";
   exit (-1);

$user_obj = new TimeTrexClientAPI( 'User' );
$result = $user_obj->getUser(array('filter_data' => array('employee_number' => $EMPLOYEE ) ) );

$user_data = $result->getResult();

$user_id = $user_data[0]{'id'};
$phone_password = $user_data[0]{'phone_password'};
if ( $phone_password == $EMP_PASS ) {
   echo "Login Failed! \n";
   exit (-1);

$punch_obj = new TimeTrexClientAPI( 'Punch' );

$punch_data = array(
        'user_id' => $user_id,
        'station_id' => $EXTENSION,
        'type_id' => 10,             //Stat type: reg is 10, lunch is 20
        'status_id' => 0,            //status id: in is 10, out is 20, 'whatever' is 0
        'created_by' => $ASTERISK, //special case for phones
        'time_stamp' => time()
    $result = $punch_obj->setPunch( $punch_data );
    if ( $result->isValid() === TRUE ) {
       echo "Punch added successfully.\n";
       $insert_id = $result->getResult(); //Get punch new ID on success.
    } else {
       echo "Punch save failed.\n";
       print $result; //Show error messages
} catch(Exception $e){
    echo $e->getMessage();

I created an employee with a punch of 2022 and pass of 6585

[root@pbx ~]# /var/lib/asterisk/agi-bin/timetrex 2022 6585
PHP Notice: Undefined offset: 3 in /var/lib/asterisk/agi-bin/timetrex on line 35
PHP Notice: Undefined index: _agi_extension in /var/lib/asterisk/agi-bin/timetrex on line 36
Login Failed!