Page Multiple Tenants at Once
If you would require to page to all or to a certain number of tenants at once, you can create a very simple custom script. See our Custom Scripts page on Developer Resource Center.

2007-10-13

ScopServ Telephony 1.4.5, Asterisk 1.4.13 and Wanpipe 3.2.0
more...



ScopServ API

The ScopServ API lets you add and remove informations on it's own database, change fields value, view contents of differents sections and more. See all of its functions here!

Please note that some PHP programming knowledge are required.

Functions

Here's a full list of all available functions, in alphabetic order, that can be called from custom PHP script.


$telephony->convertExtensionToChannel ( string $extension [, string $tenant_name] )
Get the Channel for a specific Extension. If no Tenant Name is given and more than one extension exist on different Tenant, an array containing all possible channels will be returned as result.

$telephony->countExtensions ( string $type [, int $tenant_id] )
Count the number of items for a specific type/section. If a Tenant ID is given, only data from the given Tenant will be returned.

$telephony->deleteExtension ( int $ext_id )
Delete from database for the specified extension ID.

$telephony->deleteExtensions ( string $type )
Delete all items from database for the specified type/section.

$telephony->getExtension ( int $ext_id )
Get informations from database for the specified extension ID.

$telephony->getExtensions ( string $type [, int $tenant_id] )
Get all items from database for the specified type/section. If a Tenant ID is given, only data from the given Tenant will be returned.

$telephony->getLastChange ( time $timestamp )
Return all items that have been changed since the specified timestamp.

$telephony->getPhonesChannels ( )
List all channels for every extensions on the server.

$telephony->getTenants ( )
Get the list of all Tenants (ID and Name) that are configured.

$telephony->getValue ( int $ext_id, string $field )
Get a specific item key for a specific Extension ID.

$telephony->saveExtension ( array $info )
Save a new or modified item on the ScopServ database.

$telephony->setValue ( int $ext_id, string $field, string $value )
Set/Update the value of a key for a specific Extension ID.

$telephony->toggleEnable ( int $ext_id [, mixed $mode] )
Allow to Enable/Disable any items for a specified Extension ID. If no mode is specified, it will toggle the current value. Set to 'enable' if you want to enable it or any others values to disable.

Example #1

List all enabled Extensions (Phones) and display some informations (Extension, Full Name, Type and Tenant).


<?php

// No authentication mechanism
@define('AUTH_HANDLER'true);

// Define PHP include path
ini_set('include_path''/var/www/scopserv/framework');

// Define ScopServ Base directory
@define('TELEPHONY_BASE''/var/www/scopserv/telephony');

// Load ScopServ Telephony library
require_once TELEPHONY_BASE '/lib/base.php';

// Get the list of all Tenants
$tenants $telephony->getTenants();

// List all enabled Extensions (Phones) and display informations
$phones $telephony->getExtensions('phone');
foreach(
$phones as $id => $info) {
    
    
// If the item is not enable, continue to next
    
if (isset($info['ext_enable']) && !$info['ext_enable']) {
        continue;
    }
    
    
// Get Tenant Name
    
$tenant_id $info['tenant_id'];
    
$tenant    $tenants[$tenant_id];
    
    
// Get Extension Number
    
$extension $info['phone_extension'];
    
    
// Get Fullname
    
$fullname  $info['phone_fullname'];
    
    
// Get Phone Type
    
$type      $info['phone_type'];

    
// Channel
    
$channel   $telephony->convertExtensionToChannel($extension$tenant);
    
    
// Print Information about the Extensions
    
echo sprintf("%10s %30s %5s %20s %s\n"$extension$fullname$type$channel$tenant);
}


Example #2

Display informations about all configured Speeddial.


<?php

// No authentication mechanism
@define('AUTH_HANDLER'true);

// Define PHP include path
ini_set('include_path''/var/www/scopserv/framework');

// Define ScopServ Base directory
@define('TELEPHONY_BASE''/var/www/scopserv/telephony');

// Load ScopServ Telephony library
require_once TELEPHONY_BASE '/lib/base.php';

// Get the list of all Tenants
$tenants $telephony->getTenants();

// List all Speeddial (System)
$infos $telephony->getExtensions('speeddial');

// Sort data by Extension
Horde_Array::arraySort($infos'speeddial_ext');

// Loop through all items and 
foreach($infos as $id => $info) {
    
    
// Get Tenant Name
    
$tenant   $tenants[$info['tenant_id']];
    
    
// Get Speeddial Extension
    
$extension $info['speeddial_ext'];
    
    
// Get Destination Number
    
$number    $info['speeddial_number'];
    
    
// Print Information about the Speeddial
    
echo sprintf("%6s %15s %s\n"$extension$number$tenant);
}

Example #3

Import Speeddial from CSV file and check if item is already defined on the ScopServ database.


<?php

// No authentication mechanism
@define('AUTH_HANDLER'true);

// Define PHP include path
ini_set('include_path''/var/www/scopserv/framework');

// Define ScopServ Base directory
@define('TELEPHONY_BASE''/var/www/scopserv/telephony');

// Load ScopServ Telephony library
require_once TELEPHONY_BASE '/lib/base.php';

// List all Speeddial (System)
$infos $telephony->getExtensions('speeddial');

// Loop through all speeddial and add it to the $exists array
$exists = array();
foreach(
$infos as $id => $info) {
    
$exists[$info['speeddial_ext']] = $info['ext_id'];
}

// Open 'speeddial.csv' comma delimited file
$handle fopen('speeddial.csv'"r");
while ((
$data fgetcsv($handle1000',')) !== FALSE) {
    
    
// Get Speedial and Destination Number from CSV file
    
$ext    $data[0];
    
$number $data[1];
    
    
// Initialize the array
    
$info = array();
    
    
// Set the type to 'speeddial'
    
$info['type'] = 'speeddial';
    
    
// If the speeddial is already defined, set the Extension ID to update existing data
    
if (isset($exists[$ext])) {
    
$info['ext_id'] = $exists[$ext];
    }
    
    
// Set information for speeddial entry
    
$info['speeddial_ext']    = $ext;
    
$info['speeddial_number'] = $number;
    
    
// Save information on ScopServ database
    
$telephony->saveExtension($info);
}