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

Revision 5280, 7.0 kB (checked in by p_lindheimer, 5 years ago)

added conferences_getdest() and conferences_getdestinfo() and feedback on destination usage

  • 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, $pin) {
11     $this->_meetmes[$room] = $pin;
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' => 'Conference Room '.$exten.': '.$thisexten['description'],
57                    'edit_url' => 'config.php?display=conferences&extdisplay='.urlencode($exten),
58                   );
59     }
60   } else {
61     return false;
62   }
63 }
64
65 /*  Generates dialplan for conferences
66   We call this with retrieve_conf
67 */
68 function conferences_get_config($engine) {
69   global $ext;  // is this the best way to pass this?
70   global $conferences_conf;
71   global $version;
72   switch($engine) {
73     case "asterisk":
74       $ext->addInclude('from-internal-additional','ext-meetme');
75       $contextname = 'ext-meetme';
76       if(is_array($conflist = conferences_list())) {
77        
78         // Start the conference
79         $ext->add($contextname, 'STARTMEETME', '', new ext_meetme('${MEETME_ROOMNUM}','${MEETME_OPTS}','${PIN}'));
80         $ext->add($contextname, 'STARTMEETME', '', new ext_hangup(''));
81        
82         // hangup for whole context
83         $ext->add($contextname, 'h', '', new ext_hangup(''));           
84        
85         foreach($conflist as $item) {
86           $room = conferences_get(ltrim($item['0']));
87          
88           $roomnum = ltrim($item['0']);
89           $roomoptions = $room['options'];
90           if (version_compare($version, "1.4",">=")) {
91             $roomoptions = str_replace('i','I',$roomoptions);
92           }
93           $roomuserpin = $room['userpin'];
94           $roomadminpin = $room['adminpin'];
95           $roomjoinmsg = (isset($room['joinmsg'])?$room['joinmsg']:'');
96          
97           // entry point
98           $ext->add($contextname, $roomnum, '', new ext_macro('user-callerid'));
99           $ext->add($contextname, $roomnum, '', new ext_setvar('MEETME_ROOMNUM',$roomnum));
100           $ext->add($contextname, $roomnum, '', new ext_gotoif('$["${DIALSTATUS}" = "ANSWER"]',($roomuserpin == '' && $roomadminpin == '' ? 'USER' : 'READPIN')));     
101           $ext->add($contextname, $roomnum, '', new ext_answer(''));
102           $ext->add($contextname, $roomnum, '', new ext_wait(1));
103          
104           // Deal with PINs -- if exist
105           if ($roomuserpin != '' || $roomadminpin != '') {
106             $ext->add($contextname, $roomnum, '', new ext_setvar('PINCOUNT','0'));
107             $ext->add($contextname, $roomnum, 'READPIN', new ext_read('PIN','enter-conf-pin-number'));
108            
109             // userpin -- must do always, otherwise if there is just an adminpin
110             // there would be no way to get to the conference !
111             $ext->add($contextname, $roomnum, '', new ext_gotoif('$[x${PIN} = x'.$roomuserpin.']','USER'));
112
113             // admin pin -- exists
114             if ($roomadminpin != '') {
115               $ext->add($contextname, $roomnum, '', new ext_gotoif('$[x${PIN} = x'.$roomadminpin.']','ADMIN'));
116             }
117
118             // pin invalid
119             $ext->add($contextname, $roomnum, '', new ext_setvar('PINCOUNT','$[${PINCOUNT}+1]'));
120             $ext->add($contextname, $roomnum, '', new ext_gotoif('$[${PINCOUNT}>3]', "h"));
121             $ext->add($contextname, $roomnum, '', new ext_playback('conf-invalidpin'));
122             $ext->add($contextname, $roomnum, '', new ext_goto('READPIN'));
123            
124             // admin mode -- only valid if there is an admin pin
125             if ($roomadminpin != '') {
126               $ext->add($contextname, $roomnum, 'ADMIN', new ext_setvar('MEETME_OPTS','aA'.$roomoptions));
127               if ($roomjoinmsg != '') {  // play joining message if one defined
128                 $ext->add($contextname, $roomnum, '', new ext_playback($roomjoinmsg));
129               }
130               $ext->add($contextname, $roomnum, '', new ext_goto('STARTMEETME,1'));             
131             }
132           }
133          
134           // user mode
135           $ext->add($contextname, $roomnum, 'USER', new ext_setvar('MEETME_OPTS',$roomoptions));
136           if ($roomjoinmsg != '') {  // play joining message if one defined
137             $ext->add($contextname, $roomnum, '', new ext_playback($roomjoinmsg));
138           }
139           $ext->add($contextname, $roomnum, '', new ext_goto('STARTMEETME,1'));
140          
141           // add meetme config
142           $conferences_conf->addMeetme($room['exten'],$room['userpin']);
143         }
144       }
145
146     break;
147   }
148 }
149
150 function conferences_check_extensions($exten=true) {
151   $extenlist = array();
152   if (is_array($exten) && empty($exten)) {
153     return $extenlist;
154   }
155   $sql = "SELECT exten, description FROM meetme ";
156   if (is_array($exten)) {
157     $sql .= "WHERE exten in ('".implode("','",$exten)."')";
158   }
159   $sql .= " ORDER BY exten";
160   $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
161
162   foreach ($results as $result) {
163     $thisexten = $result['exten'];
164     $extenlist[$thisexten]['description'] = _("Conference: ").$result['description'];
165     $extenlist[$thisexten]['status'] = 'INUSE';
166     $extenlist[$thisexten]['edit_url'] = 'config.php?display=conferences&extdisplay='.urlencode($thisexten);
167   }
168   return $extenlist;
169 }
170
171 //get the existing meetme extensions
172 function conferences_list() {
173   $results = sql("SELECT exten,description FROM meetme ORDER BY exten","getAll",DB_FETCHMODE_ASSOC);
174   foreach($results as $result){
175     // check to see if we are in-range for the current AMP User.
176     if (isset($result['exten']) && checkRange($result['exten'])){
177       // return this item's dialplan destination, and the description
178       $extens[] = array($result['exten'],$result['description']);
179     }
180   }
181   if (isset($extens)) {
182     return $extens;
183   } else {
184     return null;
185   }
186 }
187
188 function conferences_get($account){
189   //get all the variables for the meetme
190   $results = sql("SELECT exten,options,userpin,adminpin,description,joinmsg FROM meetme WHERE exten = '$account'","getRow",DB_FETCHMODE_ASSOC);
191   return $results;
192 }
193
194 function conferences_del($account){
195   $results = sql("DELETE FROM meetme WHERE exten = \"$account\"","query");
196 }
197
198 function conferences_add($account,$name,$userpin,$adminpin,$options,$joinmsg=null){
199   global $active_modules;
200   $results = sql("INSERT INTO meetme (exten,description,userpin,adminpin,options,joinmsg) values (\"$account\",\"$name\",\"$userpin\",\"$adminpin\",\"$options\",\"$joinmsg\")");
201 }
202 ?>
Note: See TracBrowser for help on using the browser.