root/modules/branches/2.7/outroutemsg/functions.inc.php

Revision 8643, 6.2 kB (checked in by mickecarlsson, 3 years ago)

Re #3805 add possibility to change message to be played for different type of trunk failures, missing files

Line 
1 <?php /* $Id: function.inc.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             /* here we add macro-outisbusy with the following actions:
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_gotoif('$["${EMERGENCYROUTE}" = "YES"]', 'emergency,1'));
41         $ext->add($contextname, $exten, '', new ext_gotoif('$["${INTRACOMPANYROUTE}" = "YES"]', 'intracompany,1'));
42
43         switch ($outroutemsg_ids['default_msg_id']) {
44             case DEFAULT_MSG:
45                 $ext->add($contextname, $exten, '', new ext_playback("all-circuits-busy-now&pls-try-call-later, noanswer"));
46                 break;
47             case CONGESTION_TONE:
48                 $ext->add($contextname, $exten, '', new ext_playtones("congestion"));
49                 break;
50             default:
51                 $message = recordings_get_file($outroutemsg_ids['default_msg_id']);
52                 $message = ($message != "") ? $message : "all-circuits-busy-now&pls-try-call-later";
53                 $ext->add($contextname, $exten, '', new ext_playback("$message, noanswer"));
54         }
55         $ext->add($contextname, $exten, '', new ext_congestion());
56         $ext->add($contextname, $exten, '', new ext_hangup());
57
58         $exten = 'intracompany';
59         switch ($outroutemsg_ids['intracompany_msg_id']) {
60             case DEFAULT_MSG:
61                 $ext->add($contextname, $exten, '', new ext_playback("all-circuits-busy-now&pls-try-call-later, noanswer"));
62                 break;
63             case CONGESTION_TONE:
64                 $ext->add($contextname, $exten, '', new ext_playtones("congestion"));
65                 break;
66             default:
67                 $message = recordings_get_file($outroutemsg_ids['intracompany_msg_id']);
68                 $message = ($message != "") ? $message : "all-circuits-busy-now&pls-try-call-later";
69                 $ext->add($contextname, $exten, '', new ext_playback("$message, noanswer"));
70         }
71         $ext->add($contextname, $exten, '', new ext_congestion());
72         $ext->add($contextname, $exten, '', new ext_hangup());
73
74         $exten = 'emergency';
75         switch ($outroutemsg_ids['emergency_msg_id']) {
76             case DEFAULT_MSG:
77                 $ext->add($contextname, $exten, '', new ext_playback("all-circuits-busy-now&pls-try-call-later"));
78                 break;
79             case CONGESTION_TONE:
80                 $ext->add($contextname, $exten, '', new ext_playtones("congestion"));
81                 break;
82             default:
83                 $message = recordings_get_file($outroutemsg_ids['emergency_msg_id']);
84                 $message = ($message != "") ? $message : "all-circuits-busy-now&pls-try-call-later";
85                 $ext->add($contextname, $exten, '', new ext_playback("$message"));
86         }
87         $ext->add($contextname, $exten, '', new ext_congestion());
88         $ext->add($contextname, $exten, '', new ext_hangup());
89     }
90 }
91
92 function outroutemsg_add($default_msg_id, $intracompany_msg_id, $emergency_msg_id, $no_answer_msg_id, $invalidnmbr_msg_id, $unalloc_msg_id) {
93     global $db;
94
95     $default_msg_id      = $db->escapeSimple($default_msg_id);
96     $intracompany_msg_id = $db->escapeSimple($intracompany_msg_id);
97     $emergency_msg_id    = $db->escapeSimple($emergency_msg_id);
98     $no_answer_msg_id    = $db->escapeSimple($no_answer_msg_id);
99     $invalidnmbr_msg_id  = $db->escapeSimple($invalidnmbr_msg_id);
100     $unalloc_msg_id      = $db->escapeSimple($unalloc_msg_id);
101     
102     // in future will do in a outroutemsg_del but not needed for now
103     //
104     $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')";
105     $result = $db->query($sql);
106     if(DB::IsError($result)) {
107         die_freepbx($result->getMessage().$sql);
108     }
109
110     $insert_fields =array(
111         array('default_msg_id', "$default_msg_id"),
112         array('intracompany_msg_id', "$intracompany_msg_id"),
113         array('emergency_msg_id', "$emergency_msg_id"),
114         array('no_answer_msg_id', "$no_answer_msg_id"),
115         array('invalidnmbr_msg_id', "$invalidnmbr_msg_id"),
116         array('unalloc_msg_id', "$unalloc_msg_id"),
117         );
118
119     $compiled = $db->prepare('INSERT INTO outroutemsg (keyword, data) values (?,?)');
120     $result = $db->executeMultiple($compiled,$insert_fields);
121     if(DB::IsError($result)) {
122         die_freepbx($result->getDebugInfo()."<br><br>".'error adding to outroutemsg table');
123     }
124 }
125
126 function outroutemsg_get() {
127     global $db;
128     $sql = "SELECT keyword, data FROM outroutemsg";
129     $results = $db->getAssoc($sql);
130     if(DB::IsError($results)) {
131         $results = array();
132     }
133     $results['default_msg_id']      = isset($results['default_msg_id'])      ? $results['default_msg_id']      : DEFAULT_MSG;
134     $results['intracompany_msg_id'] = isset($results['intracompany_msg_id']) ? $results['intracompany_msg_id'] : DEFAULT_MSG;
135     $results['emergency_msg_id']    = isset($results['emergency_msg_id'])    ? $results['emergency_msg_id']    : DEFAULT_MSG;
136     $results['no_answer_msg_id']    = isset($results['no_answer_msg_id'])    ? $results['no_answer_msg_id']    : DEFAULT_MSG;
137     $results['invalidnmbr_msg_id']  = isset($results['invalidnmbr_msg_id'])  ? $results['invalidnmbr_msg_id']  : DEFAULT_MSG;
138     $results['unalloc_msg_id']      = isset($results['unalloc_msg_id'])      ? $results['unalloc_msg_id']      : DEFAULT_MSG;
139     return $results;
140 }
141
142 function outroutemsg_recordings_usage($recording_id) {
143     global $active_modules;
144
145     $my_id = sql("SELECT `data` FROM `outroutemsg` WHERE `data` = '$recording_id'","getOne");
146     if (!isset($my_id) || $my_id == '') {
147         return array();
148     } else {
149         $type = isset($active_modules['outroutemsg']['type'])?$active_modules['outroutemsg']['type']:'tool';
150         $usage_arr[] = array(
151             'url_query' => 'config.php?type='.$type.'&display=outroutemsg',
152             'description' => _("Route Congestion Messages"),
153         );
154         return $usage_arr;
155     }
156 }
157
158 ?>
159
Note: See TracBrowser for help on using the browser.