root/modules/branches/2.10/conferences/functions.inc.php

Revision 12324, 10.7 kB (checked in by p_lindheimer, 2 years ago)

initial checkin of recordings infrastructure change. Probably breaks seeing the old recordings in ARI but it's a start. Also no migration code, the recording file is expecting there to be a new field in the CDR database which will need to be addressed by migration code. For testing this can simply be added. The field is: recordingfile and is a VARCHAR 255

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2
3 // extend extensions class.
4 // This example is about as simple as it gets
5 class conferences_conf {
6     // return the filename to write
7     function get_filename() {
8         return "meetme_additional.conf";
9     }
10     function addMeetme($room, $userpin, $adminpin='') {
11         $this->_meetmes[$room] = $userpin.($adminpin != '' ? ','.$adminpin : '');
12     }
13     // return the output that goes in the file
14     function generateConf() {
15         $output = "";
16         if (isset($this->_meetmes) && is_array($this->_meetmes)) {
17             foreach (array_keys($this->_meetmes) as $meetme) {
18                 $output .= 'conf => '.$meetme.",".$this->_meetmes[$meetme]."\n";
19             }
20         }
21         return $output;
22     }
23 }
24
25 // returns a associative arrays with keys 'destination' and 'description'
26 function conferences_destinations() {
27     //get the list of meetmes
28     $results = conferences_list();
29
30     // return an associative array with destination and description
31     if (isset($results)) {
32         foreach($results as $result){
33             $extens[] = array('destination' => 'ext-meetme,'.$result['0'].',1', 'description' => $result['1']." <".$result['0'].">");
34         }
35         return $extens;
36     } else {
37         return null;
38     }
39 }
40
41 function conferences_getdest($exten) {
42     return array('ext-meetme,'.$exten.',1');
43 }
44
45 function conferences_getdestinfo($dest) {
46     global $active_modules;
47
48     if (substr(trim($dest),0,11) == 'ext-meetme,') {
49         $exten = explode(',',$dest);
50         $exten = $exten[1];
51         $thisexten = conferences_get($exten);
52         if (empty($thisexten)) {
53             return array();
54         } else {
55             //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
56             return array('description' => sprintf(_("Conference Room %s : %s"),$exten,$thisexten['description']),
57                          'edit_url' => 'config.php?display=conferences&extdisplay='.urlencode($exten),
58                     );
59         }
60     } else {
61         return false;
62     }
63 }
64
65 function conferences_recordings_usage($recording_id) {
66     global $active_modules;
67
68     $results = sql("SELECT `exten`, `description` FROM `meetme` WHERE `joinmsg_id` = '$recording_id'","getAll",DB_FETCHMODE_ASSOC);
69     if (empty($results)) {
70         return array();
71     } else {
72         foreach ($results as $result) {
73             $usage_arr[] = array(
74                 'url_query' => 'config.php?display=conferences&extdisplay='.urlencode($result['exten']),
75                 'description' => sprintf(_("Conference: %s"),$result['description']),
76             );
77         }
78         return $usage_arr;
79     }
80 }
81
82 /*     Generates dialplan for conferences
83     We call this with retrieve_conf
84 */
85 function conferences_get_config($engine) {
86     global $ext// is this the best way to pass this?
87     global $conferences_conf;
88     global $version;
89     global $amp_conf;
90     global $astman;
91     
92     $ast_ge_162 = version_compare($version, '1.6.2', 'ge');
93     // Default to conference meetme
94     $confapp = 'ext_meetme';
95     if ($ast_ge_162 && $amp_conf['AMPENGINE'] == 'asterisk' && isset($astman) && $astman->connected()) {
96         //check for meetme application and fallback to confbridge if possible
97         $app = $astman->send_request('Command', array('Command' => 'module show like meetme'));
98         if (preg_match('/[1-9] modules loaded/', $app['data'])){
99             $confapp='ext_meetme';
100         } else {
101             $app = $astman->send_request('Command', array('Command' => 'module show like confbridge'));
102             if (preg_match('/[1-9] modules loaded/', $app['data'])){               
103                 $confapp='ext_confbridge';
104             }
105         }
106     }
107     
108     switch($engine) {
109         case "asterisk":
110             $ext->addInclude('from-internal-additional','ext-meetme');
111             $contextname = 'ext-meetme';
112             if(is_array($conflist = conferences_list())) {
113
114                 $ast_ge_14 = version_compare($version, "1.4","ge");
115                 
116                 // Start the conference
117                 if ($ast_ge_14) {
118                     $ext->add($contextname, 'STARTMEETME', '', new ext_execif('$["${MEETME_MUSIC}" != ""]','Set','CHANNEL(musicclass)=${MEETME_MUSIC}'));
119                 } else {
120                     $ext->add($contextname, 'STARTMEETME', '', new ext_execif('$["${MEETME_MUSIC}" != ""]','SetMusicOnHold','${MEETME_MUSIC}'));
121                 }
122                 $ext->add($contextname, 'STARTMEETME', '', new ext_setvar('GROUP(meetme)','${MEETME_ROOMNUM}'));
123                 $ext->add($contextname, 'STARTMEETME', '', new ext_gotoif('$[${MAX_PARTICIPANTS} > 0 && ${GROUP_COUNT(${MEETME_ROOMNUM}@meetme)}>${MAX_PARTICIPANTS}]','MEETMEFULL,1'));
124                 if ($confapp != 'ext_confbridge') {
125                     $ext->add($contextname, 'STARTMEETME', '', new ext_meetme('${MEETME_ROOMNUM}','${MEETME_OPTS}','${PIN}'));
126                 } else {
127                     $ext->add($contextname, 'STARTMEETME', '', new ext_confbridge('${MEETME_ROOMNUM}','${MEETME_OPTS}','${PIN}'));
128                 }
129                 $ext->add($contextname, 'STARTMEETME', '', new ext_hangup(''));
130
131                 //meetme full
132                 $ext->add($contextname, 'MEETMEFULL', '', new ext_playback('im-sorry&conf-full&goodbye'));
133                 $ext->add($contextname, 'MEETMEFULL', '', new ext_hangup(''));
134                 
135                 // hangup for whole context
136                 $ext->add($contextname, 'h', '', new ext_hangup(''));
137                 
138                 foreach($conflist as $item) {
139                     $room = conferences_get(ltrim($item['0']));
140                     
141                     $roomnum = ltrim($item['0']);
142                     $roomoptions = $room['options'];
143                     if ($ast_ge_14) {
144                         $roomoptions = str_replace('i','I',$roomoptions);
145                     }
146                     if (!$ast_ge_14) {
147                         $roomoptions = str_replace('o','',$roomoptions);
148                         $roomoptions = str_replace('T','',$roomoptions);
149                     }
150                     $roomuserpin = $room['userpin'];
151                     $roomadminpin = $room['adminpin'];
152                     $roomusers = $room['users'];
153                     if(isset($room['music']) && $room['music'] !='' && $room['music']!='inherit') {
154                         $music = $room['music'];
155                     } else {
156                         $music='${MOHCLASS}'; // inherit channel moh class
157                     }
158                     if (isset($room['joinmsg_id']) && $room['joinmsg_id'] != '') {
159                         $roomjoinmsg = recordings_get_file($room['joinmsg_id']);
160                     } else {
161                         $roomjoinmsg = '';
162                     }
163                     
164                     // Add optional hint
165                     if ($amp_conf['USEDEVSTATE']) {
166                         $ext->addHint($contextname, $roomnum, "MeetMe:".$roomnum);
167                     }
168                     // entry point
169                     $ext->add($contextname, $roomnum, '', new ext_macro('user-callerid'));
170                     $ext->add($contextname, $roomnum, '', new ext_setvar('MEETME_ROOMNUM',$roomnum));
171                     $ext->add($contextname, $roomnum, '', new ext_setvar('MAX_PARTICIPANTS', $roomusers));
172                     $ext->add($contextname, $roomnum, '', new ext_setvar('MEETME_MUSIC',$music));
173           $ext->add($contextname, $roomnum, '', new ext_gosub('1','s','sub-record-check',"conf,$roomnum," . (strstr($room['options'],'r') !== false ? 'always' : 'never')));
174                     $ext->add($contextname, $roomnum, '', new ext_gotoif('$["${DIALSTATUS}" = "ANSWER"]',($roomuserpin == '' && $roomadminpin == '' ? 'USER' : 'READPIN')));   
175                     $ext->add($contextname, $roomnum, '', new ext_answer(''));
176                     $ext->add($contextname, $roomnum, '', new ext_wait(1));
177                     
178                     // Deal with PINs -- if exist
179                     if ($roomuserpin != '' || $roomadminpin != '') {
180                         $ext->add($contextname, $roomnum, '', new ext_setvar('PINCOUNT','0'));
181                         $ext->add($contextname, $roomnum, 'READPIN', new ext_read('PIN','enter-conf-pin-number'));
182                         
183                         // userpin -- must do always, otherwise if there is just an adminpin
184                         // there would be no way to get to the conference !
185                         $ext->add($contextname, $roomnum, '', new ext_gotoif('$[x${PIN} = x'.$roomuserpin.']','USER'));
186
187                         // admin pin -- exists
188                         if ($roomadminpin != '') {
189                             $ext->add($contextname, $roomnum, '', new ext_gotoif('$[x${PIN} = x'.$roomadminpin.']','ADMIN'));
190                         }
191
192                         // pin invalid
193                         $ext->add($contextname, $roomnum, '', new ext_setvar('PINCOUNT','$[${PINCOUNT}+1]'));
194                         $ext->add($contextname, $roomnum, '', new ext_gotoif('$[${PINCOUNT}>3]', "h"));
195                         $ext->add($contextname, $roomnum, '', new ext_playback('conf-invalidpin'));
196                         $ext->add($contextname, $roomnum, '', new ext_goto('READPIN'));
197                         
198                         // admin mode -- only valid if there is an admin pin
199                         if ($roomadminpin != '') {
200                             $ext->add($contextname, $roomnum, 'ADMIN', new ext_setvar('MEETME_OPTS','aA'.str_replace('m','',$roomoptions)));
201                             if ($roomjoinmsg != '') {  // play joining message if one defined
202                                 $ext->add($contextname, $roomnum, '', new ext_playback($roomjoinmsg));
203                             }
204                             $ext->add($contextname, $roomnum, '', new ext_goto('STARTMEETME,1'));                           
205                         }
206                     }
207                     
208                     // user mode
209                     $ext->add($contextname, $roomnum, 'USER', new ext_setvar('MEETME_OPTS',$roomoptions));
210                     if ($roomjoinmsg != '') {  // play joining message if one defined
211                         $ext->add($contextname, $roomnum, '', new ext_playback($roomjoinmsg));
212                     }
213                     $ext->add($contextname, $roomnum, '', new ext_goto('STARTMEETME,1'));
214                     
215                     // add meetme config
216                     $conferences_conf->addMeetme($room['exten'],$room['userpin'],$room['adminpin']);
217                 }
218             }
219
220         break;
221     }
222 }
223
224 function conferences_check_extensions($exten=true) {
225     $extenlist = array();
226     if (is_array($exten) && empty($exten)) {
227         return $extenlist;
228     }
229     $sql = "SELECT exten, description FROM meetme ";
230     if (is_array($exten)) {
231         $sql .= "WHERE exten in ('".implode("','",$exten)."')";
232     }
233     $sql .= " ORDER BY exten";
234     $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
235
236     foreach ($results as $result) {
237         $thisexten = $result['exten'];
238         $extenlist[$thisexten]['description'] = _("Conference: ").$result['description'];
239         $extenlist[$thisexten]['status'] = 'INUSE';
240         $extenlist[$thisexten]['edit_url'] = 'config.php?display=conferences&extdisplay='.urlencode($thisexten);
241     }
242     return $extenlist;
243 }
244
245 //get the existing meetme extensions
246 function conferences_list() {
247     $results = sql("SELECT exten,description FROM meetme ORDER BY exten","getAll",DB_FETCHMODE_ASSOC);
248     foreach($results as $result){
249         // check to see if we are in-range for the current AMP User.
250         if (isset($result['exten']) && checkRange($result['exten'])){
251             // return this item's dialplan destination, and the description
252             $extens[] = array($result['exten'],$result['description']);
253         }
254     }
255     if (isset($extens)) {
256         return $extens;
257     } else {
258         return null;
259     }
260 }
261
262 function conferences_get($account){
263   global $db;
264     //get all the variables for the meetme
265     $results = sql("SELECT exten,options,userpin,adminpin,description,joinmsg_id,music,users FROM meetme WHERE exten = '".$db->escapeSimple($account)."'","getRow",DB_FETCHMODE_ASSOC);
266     return $results;
267 }
268
269 function conferences_del($account){
270     global $db;
271     $results = sql("DELETE FROM meetme WHERE exten = '".$db->escapeSimple($account)."'","query");
272 }
273
274 function conferences_add($account,$name,$userpin,$adminpin,$options,$joinmsg_id=null,$music='',$users=0){
275     global $active_modules;
276     global $db;
277     $account    = $db->escapeSimple($account);
278     $name       = $db->escapeSimple($name);
279     $userpin    = $db->escapeSimple($userpin);
280     $adminpin   = $db->escapeSimple($adminpin);
281     $options    = $db->escapeSimple($options);
282     $joinmsg_id = $db->escapeSimple($joinmsg_id);
283     $music      = $db->escapeSimple($music);
284     $users      = $db->escapeSimple($users);
285     $results = sql("INSERT INTO meetme (exten,description,userpin,adminpin,options,joinmsg_id,music,users) values (\"$account\",\"$name\",\"$userpin\",\"$adminpin\",\"$options\",\"$joinmsg_id\",\"$music\",\"$users\")");
286 }
287 ?>
288
Note: See TracBrowser for help on using the browser.