Ticket #1206: functions.inc.php.orig

File functions.inc.php.orig, 4.4 kB (added by ubanov, 6 years ago)

The original version of the file functions.inc.php, I send the file in order to could make the diff from both files.

Line 
1 <?php /* $Id: functions.inc.php 1951 2006-05-23 21:12:17Z mheydon1973 $ */
2
3 // The destinations this module provides
4 // returns a associative arrays with keys 'destination' and 'description'
5 function ringgroups_destinations() {
6   //get the list of ringgroups
7   $results = ringgroups_list();
8  
9   // return an associative array with destination and description
10   if (isset($results)) {
11     foreach($results as $result){
12         $thisgrp = ringgroups_get(ltrim($result['0']));
13         $extens[] = array('destination' => 'ext-group,'.ltrim($result['0']).',1', 'description' => $thisgrp['description'].' <'.ltrim($result['0']).'>');
14     }
15   }
16  
17   if (isset($extens))
18     return $extens;
19   else
20     return null;
21 }
22
23 /*  Generates dialplan for ringgroups
24   We call this with retrieve_conf
25 */
26 function ringgroups_get_config($engine) {
27   global $ext;  // is this the best way to pass this?
28   switch($engine) {
29     case "asterisk":
30       $ext->addInclude('from-internal-additional','ext-group');
31       $contextname = 'ext-group';
32       $ringlist = ringgroups_list();
33       if (is_array($ringlist)) {
34         foreach($ringlist as $item) {
35           $grpnum = ltrim($item['0']);
36           $grp = ringgroups_get($grpnum);
37          
38           $strategy = $grp['strategy'];
39           $grptime = $grp['grptime'];
40           $grplist = $grp['grplist'];
41           $postdest = $grp['postdest'];
42           $grppre = $grp['grppre'];
43           $annmsg = (isset($grp['annmsg'])?$grp['annmsg']:'');
44           $alertinfo = $grp['alertinfo'];
45          
46           $ext->add($contextname, $grpnum, '', new ext_macro('user-callerid'));
47           // check for old prefix
48           $ext->add($contextname, $grpnum, '', new ext_gotoif('$["${CALLERID(name):0:${LEN(${RGPREFIX})}}" != "${RGPREFIX}"]', 'NEWPREFIX'));
49           // strip off old prefix
50           $ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)','${CALLERID(name):${LEN(${RGPREFIX})}}'));
51           // set new prefix
52           $ext->add($contextname, $grpnum, 'NEWPREFIX', new ext_setvar('RGPREFIX',$grppre));
53           // add prefix to callerid name
54           $ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)','${RGPREFIX}${CALLERID(name)}'));
55           // Set Alert_Info
56           if ($alertinfo != '') {
57             $ext->add($contextname, $grpnum, '', new ext_setvar('_ALERT_INFO',$alertinfo));
58           }
59           // recording stuff
60           $ext->add($contextname, $grpnum, '', new ext_setvar('RecordMethod','Group'));
61           $ext->add($contextname, $grpnum, '', new ext_macro('record-enable',$grplist.',${RecordMethod}'));
62           // group dial
63           $ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod',$strategy));
64           if ($annmsg != '') {
65             $ext->add($contextname, $grpnum, '', new ext_answer(''));
66             $ext->add($contextname, $grpnum, '', new ext_wait(1));
67             $ext->add($contextname, $grpnum, '', new ext_playback($annmsg));
68           }
69           $ext->add($contextname, $grpnum, 'DIALGRP', new ext_macro('dial',$grptime.',${DIAL_OPTIONS},'.$grplist));
70           $ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod',''));
71           // where next?
72           if ((isset($postdest) ? $postdest : '') != '')
73             $ext->add($contextname, $grpnum, '', new ext_goto($postdest));
74           else
75             $ext->add($contextname, $grpnum, '', new ext_hangup(''));
76         }
77       }
78     break;
79   }
80 }
81
82 function ringgroups_add($grpnum,$strategy,$grptime,$grplist,$postdest,$desc,$grppre='',$annmsg='',$alertinfo) {
83   $results = sql("INSERT INTO ringgroups (grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, description, alertinfo) VALUES (".$grpnum.", '".str_replace("'", "''", $strategy)."', ".str_replace("'", "''", $grptime).", '".str_replace("'", "''", $grppre)."', '".str_replace("'", "''", $grplist)."', '".str_replace("'", "''", $annmsg)."', '".str_replace("'", "''", $postdest)."', '".str_replace("'", "''", $desc)."', '".str_replace("'", "''", $alertinfo)."')");
84 }
85
86 function ringgroups_del($grpnum) {
87   $results = sql("DELETE FROM ringgroups WHERE grpnum = $grpnum","query");
88 }
89
90 function ringgroups_list() {
91   $results = sql("SELECT grpnum, description FROM ringgroups ORDER BY grpnum","getAll",DB_FETCHMODE_ASSOC);
92   foreach ($results as $result) {
93     if (isset($result['grpnum']) && checkRange($result['grpnum'])) {
94       $grps[] = array($result['grpnum'], $result['description']);
95     }
96   }
97   if (isset($grps))
98     return $grps;
99   else
100     return null;
101 }
102
103 function ringgroups_get($grpnum) {
104   $results = sql("SELECT grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, description, alertinfo FROM ringgroups WHERE grpnum = $grpnum","getRow",DB_FETCHMODE_ASSOC);
105   return $results;
106 }
107 ?>