| 1 |
<?php |
|---|
| 2 |
//Copyright (C) 2009 Philippe Lindheimer |
|---|
| 3 |
//Copyright (C) 2009 Bandwidth.com |
|---|
| 4 |
//Copyright (C) 2010 Mikael Carlsson |
|---|
| 5 |
// |
|---|
| 6 |
//This program is free software; you can redistribute it and/or |
|---|
| 7 |
//modify it under the terms of the GNU General Public License |
|---|
| 8 |
//as published by the Free Software Foundation version 2 |
|---|
| 9 |
//of the License. |
|---|
| 10 |
// |
|---|
| 11 |
//This program is distributed in the hope that it will be useful, |
|---|
| 12 |
//but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 |
//GNU General Public License for more details. |
|---|
| 15 |
|
|---|
| 16 |
define ('DEFAULT_MSG', -1); |
|---|
| 17 |
define ('CONGESTION_TONE', -2); |
|---|
| 18 |
|
|---|
| 19 |
function outroutemsg_get_config($engine) { |
|---|
| 20 |
global $db; |
|---|
| 21 |
global $ext; |
|---|
| 22 |
global $version; |
|---|
| 23 |
|
|---|
| 24 |
switch($engine) { |
|---|
| 25 |
case "asterisk": |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
* if ( EMERGENCYROUTE=YES ): |
|---|
| 29 |
* choose Emergency Message over everything else, ANSWER CALL |
|---|
| 30 |
* if ( INTRACOMPANYROUTE=YES ): |
|---|
| 31 |
* choose Intracompany Message over default |
|---|
| 32 |
* Use default |
|---|
| 33 |
*/ |
|---|
| 34 |
|
|---|
| 35 |
$contextname = 'macro-outisbusy'; |
|---|
| 36 |
|
|---|
| 37 |
$outroutemsg_ids = outroutemsg_get(); |
|---|
| 38 |
$exten = 's'; |
|---|
| 39 |
|
|---|
| 40 |
$ext->add($contextname, $exten, '', new ext_progress()); |
|---|
| 41 |
$ext->add($contextname, $exten, '', new ext_gotoif('$["${EMERGENCYROUTE}" = "YES"]', 'emergency,1')); |
|---|
| 42 |
$ext->add($contextname, $exten, '', new ext_gotoif('$["${INTRACOMPANYROUTE}" = "YES"]', 'intracompany,1')); |
|---|
| 43 |
|
|---|
| 44 |
switch ($outroutemsg_ids['default_msg_id']) { |
|---|
| 45 |
case DEFAULT_MSG: |
|---|
| 46 |
$ext->add($contextname, $exten, '', new ext_playback("all-circuits-busy-now&pls-try-call-later, noanswer")); |
|---|
| 47 |
break; |
|---|
| 48 |
case CONGESTION_TONE: |
|---|
| 49 |
$ext->add($contextname, $exten, '', new ext_playtones("congestion")); |
|---|
| 50 |
break; |
|---|
| 51 |
default: |
|---|
| 52 |
$message = recordings_get_file($outroutemsg_ids['default_msg_id']); |
|---|
| 53 |
$message = ($message != "") ? $message : "all-circuits-busy-now&pls-try-call-later"; |
|---|
| 54 |
$ext->add($contextname, $exten, '', new ext_playback("$message, noanswer")); |
|---|
| 55 |
} |
|---|
| 56 |
$ext->add($contextname, $exten, '', new ext_congestion()); |
|---|
| 57 |
$ext->add($contextname, $exten, '', new ext_hangup()); |
|---|
| 58 |
|
|---|
| 59 |
$exten = 'intracompany'; |
|---|
| 60 |
switch ($outroutemsg_ids['intracompany_msg_id']) { |
|---|
| 61 |
case DEFAULT_MSG: |
|---|
| 62 |
$ext->add($contextname, $exten, '', new ext_playback("all-circuits-busy-now&pls-try-call-later, noanswer")); |
|---|
| 63 |
break; |
|---|
| 64 |
case CONGESTION_TONE: |
|---|
| 65 |
$ext->add($contextname, $exten, '', new ext_playtones("congestion")); |
|---|
| 66 |
break; |
|---|
| 67 |
default: |
|---|
| 68 |
$message = recordings_get_file($outroutemsg_ids['intracompany_msg_id']); |
|---|
| 69 |
$message = ($message != "") ? $message : "all-circuits-busy-now&pls-try-call-later"; |
|---|
| 70 |
$ext->add($contextname, $exten, '', new ext_playback("$message, noanswer")); |
|---|
| 71 |
} |
|---|
| 72 |
$ext->add($contextname, $exten, '', new ext_congestion()); |
|---|
| 73 |
$ext->add($contextname, $exten, '', new ext_hangup()); |
|---|
| 74 |
|
|---|
| 75 |
$exten = 'emergency'; |
|---|
| 76 |
switch ($outroutemsg_ids['emergency_msg_id']) { |
|---|
| 77 |
case DEFAULT_MSG: |
|---|
| 78 |
$ext->add($contextname, $exten, '', new ext_playback("all-circuits-busy-now&pls-try-call-later")); |
|---|
| 79 |
break; |
|---|
| 80 |
case CONGESTION_TONE: |
|---|
| 81 |
$ext->add($contextname, $exten, '', new ext_playtones("congestion")); |
|---|
| 82 |
break; |
|---|
| 83 |
default: |
|---|
| 84 |
$message = recordings_get_file($outroutemsg_ids['emergency_msg_id']); |
|---|
| 85 |
$message = ($message != "") ? $message : "all-circuits-busy-now&pls-try-call-later"; |
|---|
| 86 |
$ext->add($contextname, $exten, '', new ext_playback("$message")); |
|---|
| 87 |
} |
|---|
| 88 |
$ext->add($contextname, $exten, '', new ext_congestion()); |
|---|
| 89 |
$ext->add($contextname, $exten, '', new ext_hangup()); |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
function outroutemsg_add($default_msg_id, $intracompany_msg_id, $emergency_msg_id, $no_answer_msg_id, $invalidnmbr_msg_id, $unalloc_msg_id) { |
|---|
| 94 |
global $db; |
|---|
| 95 |
|
|---|
| 96 |
$default_msg_id = $db->escapeSimple($default_msg_id); |
|---|
| 97 |
$intracompany_msg_id = $db->escapeSimple($intracompany_msg_id); |
|---|
| 98 |
$emergency_msg_id = $db->escapeSimple($emergency_msg_id); |
|---|
| 99 |
$no_answer_msg_id = $db->escapeSimple($no_answer_msg_id); |
|---|
| 100 |
$invalidnmbr_msg_id = $db->escapeSimple($invalidnmbr_msg_id); |
|---|
| 101 |
$unalloc_msg_id = $db->escapeSimple($unalloc_msg_id); |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
// |
|---|
| 105 |
$sql = "DELETE FROM outroutemsg WHERE `keyword` IN ('default_msg_id', 'intracompany_msg_id', 'emergency_msg_id', 'no_answer_msg_id', 'invalidnmbr_msg_id', 'unalloc_msg_id')"; |
|---|
| 106 |
$result = $db->query($sql); |
|---|
| 107 |
if(DB::IsError($result)) { |
|---|
| 108 |
die_freepbx($result->getMessage().$sql); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
$insert_fields =array( |
|---|
| 112 |
array('default_msg_id', "$default_msg_id"), |
|---|
| 113 |
array('intracompany_msg_id', "$intracompany_msg_id"), |
|---|
| 114 |
array('emergency_msg_id', "$emergency_msg_id"), |
|---|
| 115 |
array('no_answer_msg_id', "$no_answer_msg_id"), |
|---|
| 116 |
array('invalidnmbr_msg_id', "$invalidnmbr_msg_id"), |
|---|
| 117 |
array('unalloc_msg_id', "$unalloc_msg_id"), |
|---|
| 118 |
); |
|---|
| 119 |
|
|---|
| 120 |
$compiled = $db->prepare('INSERT INTO outroutemsg (keyword, data) values (?,?)'); |
|---|
| 121 |
$result = $db->executeMultiple($compiled,$insert_fields); |
|---|
| 122 |
if(DB::IsError($result)) { |
|---|
| 123 |
die_freepbx($result->getDebugInfo()."<br><br>".'error adding to outroutemsg table'); |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
function outroutemsg_get() { |
|---|
| 128 |
global $db; |
|---|
| 129 |
$sql = "SELECT keyword, data FROM outroutemsg"; |
|---|
| 130 |
$results = $db->getAssoc($sql); |
|---|
| 131 |
if(DB::IsError($results)) { |
|---|
| 132 |
$results = array(); |
|---|
| 133 |
} |
|---|
| 134 |
$results['default_msg_id'] = isset($results['default_msg_id']) ? $results['default_msg_id'] : DEFAULT_MSG; |
|---|
| 135 |
$results['intracompany_msg_id'] = isset($results['intracompany_msg_id']) ? $results['intracompany_msg_id'] : DEFAULT_MSG; |
|---|
| 136 |
$results['emergency_msg_id'] = isset($results['emergency_msg_id']) ? $results['emergency_msg_id'] : DEFAULT_MSG; |
|---|
| 137 |
$results['no_answer_msg_id'] = isset($results['no_answer_msg_id']) ? $results['no_answer_msg_id'] : DEFAULT_MSG; |
|---|
| 138 |
$results['invalidnmbr_msg_id'] = isset($results['invalidnmbr_msg_id']) ? $results['invalidnmbr_msg_id'] : DEFAULT_MSG; |
|---|
| 139 |
$results['unalloc_msg_id'] = isset($results['unalloc_msg_id']) ? $results['unalloc_msg_id'] : DEFAULT_MSG; |
|---|
| 140 |
return $results; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
function outroutemsg_recordings_usage($recording_id) { |
|---|
| 144 |
global $active_modules; |
|---|
| 145 |
|
|---|
| 146 |
$my_id = sql("SELECT `data` FROM `outroutemsg` WHERE `data` = '$recording_id'","getOne"); |
|---|
| 147 |
if (!isset($my_id) || $my_id == '') { |
|---|
| 148 |
return array(); |
|---|
| 149 |
} else { |
|---|
| 150 |
$type = isset($active_modules['outroutemsg']['type'])?$active_modules['outroutemsg']['type']:'tool'; |
|---|
| 151 |
$usage_arr[] = array( |
|---|
| 152 |
'url_query' => 'config.php?type='.$type.'&display=outroutemsg', |
|---|
| 153 |
'description' => _("Route Congestion Messages"), |
|---|
| 154 |
); |
|---|
| 155 |
return $usage_arr; |
|---|
| 156 |
} |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
?> |
|---|
| 160 |
|
|---|