| 1 |
<?php /* $Id */ |
|---|
| 2 |
|
|---|
| 3 |
// returns a associative arrays with keys 'destination' and 'description' |
|---|
| 4 |
function callback_destinations() { |
|---|
| 5 |
//get the list of meetmes |
|---|
| 6 |
$results = callback_list(); |
|---|
| 7 |
|
|---|
| 8 |
// return an associative array with destination and description |
|---|
| 9 |
if (isset($results)) { |
|---|
| 10 |
foreach($results as $result){ |
|---|
| 11 |
$extens[] = array('destination' => 'callback,'.$result['callback_id'].',1', 'description' => $result['description']); |
|---|
| 12 |
} |
|---|
| 13 |
return $extens; |
|---|
| 14 |
} else { |
|---|
| 15 |
return null; |
|---|
| 16 |
} |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
/* Generates dialplan for callback |
|---|
| 20 |
We call this with retrieve_conf |
|---|
| 21 |
*/ |
|---|
| 22 |
function callback_get_config($engine) { |
|---|
| 23 |
global $ext; // is this the best way to pass this? |
|---|
| 24 |
global $asterisk_conf; |
|---|
| 25 |
switch($engine) { |
|---|
| 26 |
case "asterisk": |
|---|
| 27 |
$timelist = callback_list(); |
|---|
| 28 |
if(is_array($timelist)) { |
|---|
| 29 |
foreach($timelist as $item) { |
|---|
| 30 |
//$thisitem = callback_get(ltrim($item['callback_id'])); |
|---|
| 31 |
// add dialplan |
|---|
| 32 |
|
|---|
| 33 |
// use callbacknum if avail, otherwise use cidnum |
|---|
| 34 |
$callback_num = (empty($item['callbacknum']) ? '${CALLERID(number)}' : $item['callbacknum']); |
|---|
| 35 |
$ext->add('callback', $item['callback_id'], '', new ext_setvar("CALL",$callback_num)); |
|---|
| 36 |
|
|---|
| 37 |
//substitute commas with periods to keep asterisk dialplan variables happy |
|---|
| 38 |
$callback_destination = str_replace(",",".",$item['destination']); |
|---|
| 39 |
$ext->add('callback', $item['callback_id'], '', new ext_setvar("DESTINATION",$callback_destination)); |
|---|
| 40 |
|
|---|
| 41 |
// set sleep time |
|---|
| 42 |
$sleep = (empty($item['sleep']) ? '0' : $item['sleep']); |
|---|
| 43 |
$ext->add('callback', $item['callback_id'], '', new ext_setvar("SLEEP",$sleep)); |
|---|
| 44 |
|
|---|
| 45 |
// kick off the callback script - run in background (&) so we can hangup |
|---|
| 46 |
$ext->add('callback', $item['callback_id'], '', new ext_system((empty($asterisk_conf['astvarlib']) ? '/var/lib/asterisk' : $asterisk_conf['astvarlib']).'/bin/callback ${CALL} ${DESTINATION} ${SLEEP} &')); |
|---|
| 47 |
|
|---|
| 48 |
//hangup |
|---|
| 49 |
$ext->add('callback', $item['callback_id'], '', new ext_hangup('')); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
} |
|---|
| 53 |
break; |
|---|
| 54 |
} |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
//get the existing meetme extensions |
|---|
| 58 |
function callback_list() { |
|---|
| 59 |
$results = sql("SELECT * FROM callback","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 60 |
if(is_array($results)){ |
|---|
| 61 |
foreach($results as $result){ |
|---|
| 62 |
// check to see if we have a dept match for the current AMP User. |
|---|
| 63 |
if (checkDept($result['deptname'])){ |
|---|
| 64 |
// return this item's dialplan destination, and the description |
|---|
| 65 |
$allowed[] = $result; |
|---|
| 66 |
} |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
if (isset($allowed)) { |
|---|
| 70 |
return $allowed; |
|---|
| 71 |
} else { |
|---|
| 72 |
return null; |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
function callback_get($id){ |
|---|
| 77 |
//get all the variables for the meetme |
|---|
| 78 |
$results = sql("SELECT * FROM callback WHERE callback_id = '$id'","getRow",DB_FETCHMODE_ASSOC); |
|---|
| 79 |
return $results; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
function callback_del($id){ |
|---|
| 83 |
$results = sql("DELETE FROM callback WHERE callback_id = '$id'","query"); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
function callback_add($post){ |
|---|
| 87 |
if(!callback_chk($post)) |
|---|
| 88 |
return false; |
|---|
| 89 |
extract($post); |
|---|
| 90 |
if(empty($description)) $description = ${$goto0.'0'}; |
|---|
| 91 |
$results = sql("INSERT INTO callback (description,callbacknum,destination,deptname,sleep) values (\"$description\",\"$callbacknum\",\"${$goto0.'0'}\",\"$deptname\",\"$sleep\")"); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
function callback_edit($id,$post){ |
|---|
| 95 |
if(!callback_chk($post)) |
|---|
| 96 |
return false; |
|---|
| 97 |
extract($post); |
|---|
| 98 |
if(empty($description)) $description = ${$goto0.'0'}; |
|---|
| 99 |
$results = sql("UPDATE callback SET description = \"$description\", callbacknum = \"$callbacknum\", destination = \"${$goto0.'0'}\", deptname = \"$deptname\", sleep = \"$sleep\" WHERE callback_id = \"$id\""); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
// ensures post vars is valid |
|---|
| 103 |
function callback_chk($post){ |
|---|
| 104 |
return true; |
|---|
| 105 |
} |
|---|
| 106 |
?> |
|---|