root/modules/branches/2.8/findmefollow/functions.inc.php

Revision 9524, 25.4 kB (checked in by mbrevda, 3 years ago)

rename INTENDEDUSER to EXTTOCALL; used to trac the orignaly intended user

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php /* $Id: functions.inc.php 175 2006-10-03 19:12:39Z plindheimer $ */
2
3 /*  Generates dialplan for findmefollow
4   We call this with retrieve_conf
5 */
6 function findmefollow_get_config($engine) {
7   global $ext;  // is this the best way to pass this?
8   global $amp_conf;
9   switch($engine) {
10     case "asterisk":
11       if ($amp_conf['USEDEVSTATE']) {
12         $ext->addGlobal('FMDEVSTATE','TRUE');
13       }
14
15       $fcc = new featurecode('findmefollow', 'fmf_toggle');
16       $fmf_code = $fcc->getCodeActive();
17       unset($fcc);
18
19       if ($fmf_code != '') {
20         findmefollow_fmf_toggle($fmf_code);
21       }
22
23       $ext->addInclude('from-internal-additional','ext-findmefollow');
24       $ext->addInclude('from-internal-additional','fmgrps');
25       $contextname = 'ext-findmefollow';
26
27       // Before creating all the contexts, let's make a list of hints if needed
28       //
29       if ($amp_conf['USEDEVSTATE'] && $fmf_code != '') {
30         $device_list = core_devices_list("all", false, true);
31         foreach ($device_list as $device) {
32           $ext->add($contextname, $fmf_code.$device['id'], '', new ext_goto("1",$fmf_code,"app-fmf-toggle"));
33           $ext->addHint($contextname, $fmf_code.$device['id'], "Custom:FOLLOWME".$device['id']);
34         }
35       }
36
37       $ringlist = findmefollow_full_list();
38       if (is_array($ringlist)) {
39         foreach($ringlist as $item) {
40           $grpnum = ltrim($item['0']);
41           $grp = findmefollow_get($grpnum);
42           
43           $strategy = $grp['strategy'];
44           $grptime = $grp['grptime'];
45           $grplist = $grp['grplist'];
46           $postdest = $grp['postdest'];
47           $grppre = (isset($grp['grppre'])?$grp['grppre']:'');
48           $annmsg_id = $grp['annmsg_id'];
49           $dring = $grp['dring'];
50
51           $needsconf = $grp['needsconf'];
52           $remotealert_id = $grp['remotealert_id'];
53           $toolate_id = $grp['toolate_id'];
54           $ringing = $grp['ringing'];
55           $pre_ring = $grp['pre_ring'];
56
57           if($ringing == 'Ring' || empty($ringing) ) {
58             $dialopts = '${DIAL_OPTIONS}';
59           } else {
60             // We need the DIAL_OPTIONS variable
61             $sops = sql("SELECT value from globals where variable='DIAL_OPTIONS'", "getRow");
62             $dialopts = "m(${ringing})".str_replace('r', '', $sops[0]);
63           }
64
65           // Direct target to Follow-Me come here bypassing the followme/ddial conditional check
66           //
67           $ext->add($contextname, 'FM'.$grpnum, '', new ext_goto("FM$grpnum","$grpnum"));
68
69           //
70           // If the followme is configured for extension dialing to go to the the extension and not followme then
71           // go there. This is often used in VmX Locater functionality when the user does not want the followme
72           // to automatically be called but only if chosen by the caller as an alternative to going to voicemail
73           //
74           $ext->add($contextname, $grpnum, '', new ext_set('__EXTTOCALL','${EXTEN}'));
75           $ext->add($contextname, $grpnum, '', new ext_gotoif('$[ "${DB(AMPUSER/'.$grpnum.'/followme/ddial)}" = "EXTENSION" ]', 'ext-local,'.$grpnum.',1'));
76           $ext->add($contextname, $grpnum, 'FM'.$grpnum, new ext_macro('user-callerid'));
77
78           // block voicemail until phone is answered at which point a macro should be called on the answering
79           // line to clear this flag so that subsequent transfers can occur, if already set by a the caller
80           // then don't change.
81           //
82           $ext->add($contextname, $grpnum, '', new ext_gotoif('$["foo${BLKVM_OVERRIDE}" = "foo"]', 'skipdb'));
83           $ext->add($contextname, $grpnum, '', new ext_gotoif('$["${DB(${BLKVM_OVERRIDE})}" = "TRUE"]', 'skipov'));
84
85           $ext->add($contextname, $grpnum, 'skipdb', new ext_setvar('__NODEST', ''));
86           $ext->add($contextname, $grpnum, '', new ext_setvar('__BLKVM_OVERRIDE', 'BLKVM/${EXTEN}/${CHANNEL}'));
87           $ext->add($contextname, $grpnum, '', new ext_setvar('__BLKVM_BASE', '${EXTEN}'));
88           $ext->add($contextname, $grpnum, '', new ext_setvar('DB(${BLKVM_OVERRIDE})', 'TRUE'));
89
90           // Remember if NODEST was set later, but clear it in case the call is answered so that subsequent
91           // transfers work.
92           //
93           $ext->add($contextname, $grpnum, 'skipov', new ext_setvar('RRNODEST', '${NODEST}'));
94           $ext->add($contextname, $grpnum, 'skipvmblk', new ext_setvar('__NODEST', '${EXTEN}'));
95
96           $ext->add($contextname, $grpnum, '', new ext_gosubif('$[${DB_EXISTS(AMPUSER/'.$grpnum.'/followme/changecid)} = 1 & "${DB(AMPUSER/'.$grpnum.'/followme/changecid)}" != "default" & "${DB(AMPUSER/'.$grpnum.'/followme/changecid)}" != ""]', 'sub-fmsetcid,s,1'));
97
98
99           // deal with group CID prefix
100           // but strip only if you plan on setting a new one
101           if ($grppre != '') {
102             $ext->add($contextname, $grpnum, '', new ext_gotoif('$["foo${RGPREFIX}" = "foo"]', 'REPCID'));
103             $ext->add($contextname, $grpnum, '', new ext_gotoif('$["${RGPREFIX}" != "${CALLERID(name):0:${LEN(${RGPREFIX})}}"]', 'REPCID'));
104             $ext->add($contextname, $grpnum, '', new ext_noop('Current RGPREFIX is ${RGPREFIX}....stripping from Caller ID'));
105             $ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)', '${CALLERID(name):${LEN(${RGPREFIX})}}'));
106             $ext->add($contextname, $grpnum, '', new ext_setvar('_RGPREFIX', ''));
107             $ext->add($contextname, $grpnum, 'REPCID', new ext_noop('CALLERID(name) is ${CALLERID(name)}'));
108             $ext->add($contextname, $grpnum, '', new ext_setvar('_RGPREFIX', $grppre));
109             $ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)','${RGPREFIX}${CALLERID(name)}'));
110           }
111           // recording stuff
112           $ext->add($contextname, $grpnum, '', new ext_setvar('RecordMethod','Group'));
113           $ext->add($contextname, $grpnum, '', new ext_macro('record-enable','${DB(AMPUSER/'."$grpnum/followme/grplist)}".',${RecordMethod}'));
114
115           // MODIFIED (PL)
116           // Add Alert Info if set but don't override and already set value (could be from ringgroup, directdid, etc.)
117           //
118           if ((isset($dring) ? $dring : '') != '') {
119             // If ALERTINFO is set, then skip to the next set command. This was modified to two lines because the previous
120             // IF() couldn't handle ':' as part of the string. The jump to PRIORITY+2 allows for now destination label
121             // which is needed in the 2.3 version.
122             $ext->add($contextname, $grpnum, '', new ext_gotoif('$["x${ALERT_INFO}"!="x"]','$[${PRIORITY}+2])}'));
123             $ext->add($contextname, $grpnum, '', new ext_setvar("__ALERT_INFO", str_replace(';', '\;', $dring) ));
124           }
125           // If pre_ring is set, then ring this number of seconds prior to moving on
126           if ((isset($strategy) ? substr($strategy,0,strlen('ringallv2')) : '') != 'ringallv2') {
127             $ext->add($contextname, $grpnum, '', new ext_gotoif('$[$[ "${DB(AMPUSER/'.$grpnum.'/followme/prering)}" = "0" ] | $[ "${DB(AMPUSER/'.$grpnum.'/followme/prering)}" = "" ]] ', 'skipsimple'));
128             $ext->add($contextname, $grpnum, '', new ext_macro('simple-dial',$grpnum.',${DB(AMPUSER/'."$grpnum/followme/prering)}"));
129           }
130
131           // group dial
132           $ext->add($contextname, $grpnum, 'skipsimple', new ext_setvar('RingGroupMethod',$strategy));
133           $ext->add($contextname, $grpnum, '', new ext_setvar('_FMGRP',$grpnum));
134           if ((isset($annmsg_id) ? $annmsg_id : '')) {
135             $annmsg = recordings_get_file($annmsg_id);
136             // should always answer before playing anything, shouldn't we ?
137             $ext->add($contextname, $grpnum, '', new ext_gotoif('$[$["${DIALSTATUS}" = "ANSWER"] | $["foo${RRNODEST}" != "foo"]]','DIALGRP'));     
138             $ext->add($contextname, $grpnum, '', new ext_answer(''));
139             $ext->add($contextname, $grpnum, '', new ext_wait(1));
140             $ext->add($contextname, $grpnum, '', new ext_playback($annmsg));
141           }
142
143           // Create the confirm target
144           $len=strlen($grpnum)+4;
145           $remotealert = recordings_get_file($remotealert_id);
146           $toolate = recordings_get_file($toolate_id);
147           $ext->add("fmgrps", "_RG-${grpnum}-.", '', new ext_macro('dial','${DB(AMPUSER/'."$grpnum/followme/grptime)},".
148             "M(confirm^${remotealert}^${toolate}^${grpnum})$dialopts".',${EXTEN:'.$len.'}'));
149
150           // If grpconf == ENABLED call with confirmation ELSE call normal
151           $ext->add($contextname, $grpnum, 'DIALGRP', new
152               ext_gotoif('$[ "${DB(AMPUSER/'.$grpnum.'/followme/grpconf)}" = "ENABLED" ]', 'doconfirm'));
153
154           // Normal call
155           if ((isset($strategy) ? substr($strategy,0,strlen('ringallv2')) : '') != 'ringallv2') {
156             $ext->add($contextname, $grpnum, '', new ext_macro('dial','${DB(AMPUSER/'."$grpnum/followme/grptime)},$dialopts,".'${DB(AMPUSER/'."$grpnum/followme/grplist)}"));
157           } else {
158             $ext->add($contextname, $grpnum, '', new ext_macro('dial','$[ ${DB(AMPUSER/'.$grpnum.'/followme/grptime)} + ${DB(AMPUSER/'.$grpnum.'/followme/prering)} ],'.$dialopts.',${DB(AMPUSER/'.$grpnum.'/followme/grplist)}'));
159           }
160           $ext->add($contextname, $grpnum, '', new ext_goto('nextstep'));
161
162           // Call Confirm call
163           if ((isset($strategy) ? substr($strategy,0,strlen('ringallv2')) : '') != 'ringallv2') {
164             $ext->add($contextname, $grpnum, 'doconfirm', new ext_macro('dial-confirm','${DB(AMPUSER/'."$grpnum/followme/grptime)},$dialopts,".'${DB(AMPUSER/'."$grpnum/followme/grplist)},".$grpnum));
165           } else {
166             $ext->add($contextname, $grpnum, 'doconfirm', new ext_macro('dial-confirm','$[ ${DB(AMPUSER/'.$grpnum.'/followme/grptime)} + ${DB(AMPUSER/'.$grpnum.'/followme/prering)} ],'.$dialopts.',${DB(AMPUSER/'.$grpnum.'/followme/grplist)},'.$grpnum));
167           }
168
169           $ext->add($contextname, $grpnum, 'nextstep', new ext_setvar('RingGroupMethod',''));
170
171           // Did the call come from a queue or ringgroup, if so, don't go to the destination, just end and let
172           // the queue or ringgroup decide what to do next
173           //
174           $ext->add($contextname, $grpnum, '', new ext_gotoif('$["foo${RRNODEST}" != "foo"]', 'nodest'));
175           $ext->add($contextname, $grpnum, '', new ext_setvar('__NODEST', ''));
176
177           $ext->add($contextname, $grpnum, '', new ext_dbdel('${BLKVM_OVERRIDE}'));
178
179           // where next?
180           if ((isset($postdest) ? $postdest : '') != '') {
181             $ext->add($contextname, $grpnum, '', new ext_goto($postdest));
182           } else {
183             $ext->add($contextname, $grpnum, '', new ext_hangup(''));
184           }
185           $ext->add($contextname, $grpnum, 'nodest', new ext_noop('SKIPPING DEST, CALL CAME FROM Q/RG: ${RRNODEST}'));
186         }
187
188         /*
189           ASTDB Settings:
190           AMPUSER/nnn/followme/changecid default | did | fixed | extern
191           AMPUSER/nnn/followme/fixedcid XXXXXXXX
192
193           changecid:
194             default   - works as always, same as if not present
195             fixed     - set to the fixedcid
196             extern    - set to the fixedcid if the call is from the outside only
197             did       - set to the DID that the call came in on or leave alone, treated as foreign
198             forcedid  - set to the DID that the call came in on or leave alone, not treated as foreign
199           
200           BLKVM_BASE - has the exten num called, hoaky if that goes away but for now use it
201         */
202         if (count($ringlist)) {
203           $contextname = 'sub-fmsetcid';
204           $exten = 's';
205           $ext->add($contextname, $exten, '', new ext_goto('1','s-${DB(AMPUSER/${BLKVM_BASE}/followme/changecid)}'));
206
207           $exten = 's-fixed';
208           $ext->add($contextname, $exten, '', new ext_execif('$["${REGEX("^[\+]?[0-9]+$" ${DB(AMPUSER/${BLKVM_BASE}/followme/fixedcid)})}" = "1"]', 'Set', '__TRUNKCIDOVERRIDE=${DB(AMPUSER/${BLKVM_BASE}/followme/fixedcid)}'));
209           $ext->add($contextname, $exten, '', new ext_return(''));
210
211           $exten = 's-extern';
212           $ext->add($contextname, $exten, '', new ext_execif('$["${REGEX("^[\+]?[0-9]+$" ${DB(AMPUSER/${BLKVM_BASE}/followme/fixedcid)})}" == "1" & "${FROM_DID}" != ""]', 'Set', '__TRUNKCIDOVERRIDE=${DB(AMPUSER/${BLKVM_BASE}/followme/fixedcid)}'));
213           $ext->add($contextname, $exten, '', new ext_return(''));
214
215           $exten = 's-did';
216           $ext->add($contextname, $exten, '', new ext_execif('$["${REGEX("^[\+]?[0-9]+$" ${FROM_DID})}" = "1"]', 'Set', '__REALCALLERIDNUM=${FROM_DID}'));
217           $ext->add($contextname, $exten, '', new ext_return(''));
218
219           $exten = 's-forcedid';
220           $ext->add($contextname, $exten, '', new ext_execif('$["${REGEX("^[\+]?[0-9]+$" ${FROM_DID})}" = "1"]', 'Set', '__TRUNKCIDOVERRIDE=${FROM_DID}'));
221           $ext->add($contextname, $exten, '', new ext_return(''));
222
223           $exten = '_s-.';
224           $ext->add($contextname, $exten, '', new ext_noop('Unknown value for AMPUSER/${BLKVM_BASE}/followme/changecid of ${DB(AMPUSER/${BLKVM_BASE}/followme/changecid)} set to "default"'));
225           $ext->add($contextname, $exten, '', new ext_setvar('DB(AMPUSER/${BLKVM_BASE}/followme/changecid)', 'default'));
226           $ext->add($contextname, $exten, '', new ext_return(''));
227         }
228       }
229     break;
230   }
231 }
232
233 function findmefollow_add($grpnum,$strategy,$grptime,$grplist,$postdest,$grppre='',$annmsg_id='',$dring,$needsconf,$remotealert_id,$toolate_id,$ringing,$pre_ring,$ddial,$changecid='default',$fixedcid='') {
234   global $amp_conf;
235   global $astman;
236   global $db;
237
238   $sql = "INSERT INTO findmefollow (grpnum, strategy, grptime, grppre, grplist, annmsg_id, postdest, dring, needsconf, remotealert_id, toolate_id, ringing, pre_ring) VALUES ('".$db->escapeSimple($grpnum)."', '".$db->escapeSimple($strategy)."', ".$db->escapeSimple($grptime).", '".$db->escapeSimple($grppre)."', '".$db->escapeSimple($grplist)."', '".$db->escapeSimple($annmsg_id)."', '".$db->escapeSimple($postdest)."', '".$db->escapeSimple($dring)."', '$needsconf', '$remotealert_id', '$toolate_id', '$ringing', '$pre_ring')";
239   $results = sql($sql);
240
241   if ($astman) {
242     $astman->database_put("AMPUSER",$grpnum."/followme/prering",isset($pre_ring)?$pre_ring:'');
243     $astman->database_put("AMPUSER",$grpnum."/followme/grptime",isset($grptime)?$grptime:'');
244     $astman->database_put("AMPUSER",$grpnum."/followme/grplist",isset($grplist)?$grplist:'');
245
246     $needsconf = isset($needsconf)?$needsconf:'';
247     $confvalue = ($needsconf == 'CHECKED')?'ENABLED':'DISABLED';
248     $astman->database_put("AMPUSER",$grpnum."/followme/grpconf",$confvalue);
249
250     $ddial      = isset($ddial)?$ddial:'';
251     $ddialvalue = ($ddial == 'CHECKED')?'EXTENSION':'DIRECT';
252     $astman->database_put("AMPUSER",$grpnum."/followme/ddial",$ddialvalue);
253
254     $astman->database_put("AMPUSER",$grpnum."/followme/changecid",$changecid);
255     $fixedcid = preg_replace("/[^0-9\+]/" ,"", trim($fixedcid));
256     $astman->database_put("AMPUSER",$grpnum."/followme/fixedcid",$fixedcid);
257   } else {
258     fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
259   }
260 }
261
262 function findmefollow_del($grpnum) {
263   global $amp_conf;
264   global $astman;
265   global $db;
266
267   $results = sql("DELETE FROM findmefollow WHERE grpnum = '".$db->escapeSimple($grpnum)."'","query");
268
269   if ($astman) {
270     $astman->database_deltree("AMPUSER/".$grpnum."/followme");
271   } else {
272     fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
273   }
274 }
275
276 function findmefollow_full_list() {
277   $results = sql("SELECT grpnum FROM findmefollow ORDER BY CAST(grpnum as UNSIGNED)","getAll",DB_FETCHMODE_ASSOC);
278   foreach ($results as $result) {
279     if (isset($result['grpnum']) && checkRange($result['grpnum'])) {
280       $grps[] = array($result['grpnum']);
281     }
282   }
283   if (isset($grps))
284     return $grps;
285   else
286     return null;
287 }
288
289 function findmefollow_list($get_all=false) {
290
291   global $db;
292   $sql = "SELECT grpnum FROM findmefollow ORDER BY CAST(grpnum as UNSIGNED)";
293   $results = $db->getCol($sql);
294   if(DB::IsError($results)) {
295     $results = null;
296   }
297   if (isset($results)) {
298     foreach($results as $result) {
299       if ($get_all || checkRange($result)){
300         $grps[] = $result;
301       }
302     }
303   }
304   if (isset($grps)) {
305     return $grps;
306   }
307   else {
308     return null;
309   }
310 }
311
312 // This gets the list of all active users so that the Find Me Follow display can limit the options to only created users.
313 // the returned arrays contain [0]:extension [1]:name
314 //
315 // This was pulled straight out of previous 1.x version, might need cleanup laster
316 //
317 function findmefollow_allusers() {
318         global $db;
319         $sql = "SELECT extension,name FROM users ORDER BY extension";
320         $results = $db->getAll($sql);
321         if(DB::IsError($results)) {
322                 $results = null;
323         }
324         foreach($results as $result){
325                 if (checkRange($result[0])){
326                         $users[] = array($result[0],$result[1]);
327                 }
328         }
329         if (isset($users)) sort($users);
330         return $users;
331 }
332
333 // Only check astdb if check_astdb is not 0. For some reason, this fails if the asterisk manager code
334 // is included (executed) by all calls to this function. This results in silently not generating the
335 // extensions_additional.conf file. page.findmefollow.php does set it to 1 which means that when running
336 // the GUI, any changes not reflected in SQL will be detected and written back to SQL so that they are
337 // in sync. Ideally, anything that changes the astdb should change SQL. (in some ways, these should both
338 // not be here but ...
339 //
340 // Need to go back and confirm at some point that the $check_astdb error is still there and deal with it.
341 // as variables like $ddial get introduced to only be in astdb, the result array will not include them
342 // if not able to get to astdb. (I suspect in 2.2 and beyond this may all be fixed).
343 //
344 function findmefollow_get($grpnum, $check_astdb=0) {
345   global $amp_conf;
346   global $astman;
347   global $db;
348
349   $results = sql("SELECT grpnum, strategy, grptime, grppre, grplist, annmsg_id, postdest, dring, needsconf, remotealert_id, toolate_id, ringing, pre_ring, voicemail FROM findmefollow INNER JOIN `users` ON `extension` = `grpnum` WHERE grpnum = '".$db->escapeSimple($grpnum)."'","getRow",DB_FETCHMODE_ASSOC);
350   if (!isset($results['voicemail'])) {
351     $results['voicemail'] = sql("SELECT `voicemail` FROM `users` WHERE `extension` = '".$db->escapeSimple($grpnum)."'","getOne");
352   }
353
354   if ($check_astdb) {
355     if ($astman) {
356       $astdb_prering = $astman->database_get("AMPUSER",$grpnum."/followme/prering");
357       $astdb_grptime = $astman->database_get("AMPUSER",$grpnum."/followme/grptime");
358       $astdb_grplist = $astman->database_get("AMPUSER",$grpnum."/followme/grplist");
359       $astdb_grpconf = $astman->database_get("AMPUSER",$grpnum."/followme/grpconf");
360
361       $astdb_changecid = strtolower($astman->database_get("AMPUSER",$grpnum."/followme/changecid"));
362       switch($astdb_changecid) {
363         case 'default':
364         case 'did':
365         case 'forcedid':
366         case 'fixed':
367         case 'extern':
368           break;
369         default:
370           $astdb_changecid = 'default';
371       }
372       $results['changecid'] = $astdb_changecid;
373       $fixedcid = $astman->database_get("AMPUSER",$grpnum."/followme/fixedcid");
374       $results['fixedcid'] = preg_replace("/[^0-9\+]/" ,"", trim($fixedcid));
375     } else {
376       fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
377     }
378       $astdb_ddial   = $astman->database_get("AMPUSER",$grpnum."/followme/ddial");                                     
379     // If the values are different then use what is in astdb as it may have been changed.
380     //
381     $changed=0;
382     if (!isset($results['pre_ring'])) {
383       $results['pre_ring'] = '';
384     }
385     if (!isset($results['grptime'])) {
386       $results['grptime'] = '';
387     }
388     if (!isset($results['grplist'])) {
389       $results['grplist'] = '';
390     }
391     if (!isset($results['needsconf'])) {
392       $results['needsconf'] = '';
393     }
394     if (($astdb_prering != $results['pre_ring']) && ($astdb_prering >= 0)) {
395       $results['pre_ring'] = $astdb_prering;
396       $changed=1;
397     }
398     if (($astdb_grptime != $results['grptime']) && ($astdb_grptime > 0)) {
399       $results['grptime'] = $astdb_grptime;
400       $changed=1;
401     }
402     if ((trim($astdb_grplist) != trim($results['grplist'])) && (trim($astdb_grplist) != '')) {
403       $results['grplist'] = $astdb_grplist;
404       $changed=1;
405     }
406
407     if (trim($astdb_grpconf) == 'ENABLED') {
408       $confvalue = 'CHECKED';
409     } elseif (trim($astdb_grpconf) == 'DISABLED') {
410       $confvalue = '';
411     } else {
412       //Bogus value, should not get here but treat as disabled
413       $confvalue = '';
414     }
415     if ($confvalue != trim($results['needsconf'])) {
416       $results['needsconf'] = $confvalue;
417       $changed=1;
418     }
419
420     // Not in sql so no sanity check needed
421     //
422     if (trim($astdb_ddial) == 'EXTENSION') {
423       $ddial = 'CHECKED';
424     } elseif (trim($astdb_ddial) == 'DIRECT') {
425       $ddial = '';
426     } else {
427       //Bogus value, should not get here but treat as disabled
428       $ddial = '';
429     }
430     $results['ddial'] = $ddial;
431
432     if ($changed) {
433       $sql = "UPDATE findmefollow SET grptime = '".$results['grptime']."', grplist = '".
434         $db->escapeSimple(trim($results['grplist']))."', pre_ring = '".$results['pre_ring'].
435         "', needsconf = '".$results['needsconf']."' WHERE grpnum = '".$db->escapeSimple($grpnum)."' LIMIT 1";
436       $sql_results = sql($sql);
437     }
438   } // if check_astdb
439
440   return $results;
441 }
442
443 function findmefollow_configpageinit($dispnum) {
444   global $currentcomponent;
445
446   if ( ($dispnum == 'users' || $dispnum == 'extensions') ) {
447     $currentcomponent->addguifunc('findmefollow_configpageload');
448   }
449 }
450
451 function findmefollow_configpageload() {
452   global $currentcomponent;
453
454   $viewing_itemid =  isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
455   $action =  isset($_REQUEST['action'])?$_REQUEST['action']:null;
456   if ( $viewing_itemid != '' && $action != 'del') {
457     $set_findmefollow = findmefollow_list();
458     $grpURL = $_SERVER['PHP_SELF'].'?'.'display=findmefollow&extdisplay=GRP-'.$viewing_itemid;
459     if (is_array($set_findmefollow)) {
460       if (in_array($viewing_itemid,$set_findmefollow)) {
461         $grpTEXT = _("Edit Follow Me Settings");
462         $icon = "images/user_go.png";
463       } else {
464         $grpTEXT = _("Add Follow Me Settings");
465         $icon = "images/user_add.png";
466       }
467     } else {
468       $grpTEXT = _("Add Follow Me Settings");
469       $icon = "images/user_add.png";
470     }
471     $label = '<span><img width="16" height="16" border="0" title="Delete Extension" alt="" src="'.$icon.'"/>&nbsp;'.$grpTEXT.'</span>';
472     $currentcomponent->addguielem('_top', new gui_link('findmefollowlink', $label, $grpURL));
473   }
474 }
475
476 function findmefollow_check_destinations($dest=true) {
477   global $active_modules;
478
479   $destlist = array();
480   if (is_array($dest) && empty($dest)) {
481     return $destlist;
482   }
483   $sql = "SELECT grpnum, postdest, name FROM findmefollow INNER JOIN users ON grpnum = extension ";
484   if ($dest !== true) {
485     $sql .= "WHERE postdest in ('".implode("','",$dest)."')";
486   }
487   $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
488
489   //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
490
491   foreach ($results as $result) {
492     $thisdest = $result['postdest'];
493     $thisid   = $result['grpnum'];
494     $destlist[] = array(
495       'dest' => $thisdest,
496       'description' => sprintf(_("Follow-Me: %s (%s)"),$thisid,$result['name']),
497       'edit_url' => 'config.php?display=findmefollow&extdisplay=GRP-'.urlencode($thisid),
498     );
499   }
500   return $destlist;
501 }
502
503 function findmefollow_recordings_usage($recording_id) {
504   global $active_modules;
505
506   $results = sql("SELECT `grpnum` FROM `findmefollow` WHERE `annmsg_id` = '$recording_id' OR `remotealert_id` = '$recording_id' OR `toolate_id` = '$recording_id'","getAll",DB_FETCHMODE_ASSOC);
507   if (empty($results)) {
508     return array();
509   } else {
510     //$type = isset($active_modules['ivr']['type'])?$active_modules['ivr']['type']:'setup';
511     foreach ($results as $result) {
512       $usage_arr[] = array(
513         'url_query' => 'config.php?display=findmefollow&extdisplay=GRP-'.urlencode($result['grpnum']),
514         'description' => sprintf(_("Follow-Me User: %s"),$result['grpnum']),
515       );
516     }
517     return $usage_arr;
518   }
519 }
520
521 function findmefollow_fmf_toggle($c) {
522   global $ext;
523   global $amp_conf;
524   global $version;
525
526   $DEVSTATE = version_compare($version, "1.6", "ge") ? "DEVICE_STATE" : "DEVSTATE";
527
528   $id = "app-fmf-toggle"; // The context to be included
529   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
530
531   $ext->add($id, $c, '', new ext_goto('start','s',$id));
532   $c = 's';
533
534   $ext->add($id, $c, 'start', new ext_answer(''));
535   $ext->add($id, $c, '', new ext_wait('1'));
536   $ext->add($id, $c, '', new ext_macro('user-callerid'));
537
538   $ext->add($id, $c, '', new ext_gotoif('$["${DB(AMPUSER/${AMPUSER}/followme/ddial)}" = "EXTENSION"]', 'activate'));
539   $ext->add($id, $c, '', new ext_gotoif('$["${DB(AMPUSER/${AMPUSER}/followme/ddial)}" = "DIRECT"]', 'deactivate','end'));
540
541   $ext->add($id, $c, 'deactivate', new ext_setvar('DB(AMPUSER/${AMPUSER}/followme/ddial)', 'EXTENSION'));
542   if ($amp_conf['USEDEVSTATE']) {
543     $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE'));
544     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
545   }
546   if ($amp_conf['FCBEEPONLY']) {
547     $ext->add($id, $c, 'hook_off', new ext_playback('beep')); // $cmd,n,Playback(...)
548   } else {
549     $ext->add($id, $c, 'hook_off', new ext_playback('followme&de-activated'));
550   }
551   $ext->add($id, $c, 'end', new ext_macro('hangupcall'));
552
553   $ext->add($id, $c, 'activate', new ext_setvar('DB(AMPUSER/${AMPUSER}/followme/ddial)', 'DIRECT'));
554   if ($amp_conf['USEDEVSTATE']) {
555     $ext->add($id, $c, '', new ext_setvar('STATE', 'INUSE'));
556     $ext->add($id, $c, '', new ext_gosub('1', 'sstate', $id));
557   }
558   if ($amp_conf['FCBEEPONLY']) {
559     $ext->add($id, $c, 'hook_on', new ext_playback('beep')); // $cmd,n,Playback(...)
560   } else {
561     $ext->add($id, $c, 'hook_on', new ext_playback('followme&activated'));
562   }
563   $ext->add($id, $c, '', new ext_macro('hangupcall'));
564
565   if ($amp_conf['USEDEVSTATE']) {
566   $c = 'sstate';
567     $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${AMPUSER}/device'));
568     $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return'));
569     $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}'));
570     $ext->add($id, $c, '', new ext_setvar('ITER', '1'));
571     $ext->add($id, $c, 'begin', new ext_setvar($DEVSTATE.'(Custom:FOLLOWME${CUT(DEVICES,&,${ITER})})','${STATE}'));
572     $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]'));
573     $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin'));
574     $ext->add($id, $c, 'return', new ext_return());
575   }
576 }
577 ?>
Note: See TracBrowser for help on using the browser.