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

Revision 6971, 4.9 kB (checked in by p_lindheimer, 4 years ago)

fixes #3272 Merged revisions r6969 - r6970 via svnmerge from
http://svn.freepbx.org/modules/branches/2.5

........

r6969 | p_lindheimer | 2008-10-12 14:15:16 -0700 (Sun, 12 Oct 2008) | 1 line


Auto Check-in of any outstanding patches

........

r6970 | p_lindheimer | 2008-10-12 14:15:26 -0700 (Sun, 12 Oct 2008) | 1 line


Module Publish Script: callback 2.5.0.2

........

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php /* $Id */
2
3 // returns a associative arrays with keys 'destination' and 'description'
4 function callback_destinations() {
5   //get the list of meetmes
6   $results = callback_list();
7
8   // return an associative array with destination and description
9   if (isset($results)) {
10     foreach($results as $result){
11         $extens[] = array('destination' => 'callback,'.$result['callback_id'].',1', 'description' => $result['description']);
12     }
13     return $extens;
14   } else {
15     return null;
16   }
17 }
18
19 function callback_getdest($exten) {
20   return array('callback,'.$exten.',1');
21 }
22
23 function callback_getdestinfo($dest) {
24   global $active_modules;
25
26   if (substr(trim($dest),0,9) == 'callback,') {
27     $exten = explode(',',$dest);
28     $exten = $exten[1];
29     $thisexten = callback_get($exten);
30     if (empty($thisexten)) {
31       return array();
32     } else {
33       //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
34       return array('description' => 'Callback : '.$thisexten['description'],
35                    'edit_url' => 'config.php?display=callback&itemid='.urlencode($exten),
36                   );
37     }
38   } else {
39     return false;
40   }
41 }
42
43 function callback_check_destinations($dest=true) {
44   global $active_modules;
45
46   $destlist = array();
47   if (is_array($dest) && empty($dest)) {
48     return $destlist;
49   }
50   $sql = "SELECT callback_id, destination, description FROM callback ";
51   if ($dest !== true) {
52     $sql .= "WHERE destination in ('".implode("','",$dest)."')";
53   }
54   $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
55
56   $type = isset($active_modules['callback']['type'])?$active_modules['callback']['type']:'setup';
57
58   foreach ($results as $result) {
59     $thisdest = $result['destination'];
60     $thisid   = $result['callback_id'];
61     $destlist[] = array(
62       'dest' => $thisdest,
63       'description' => sprintf(_("Callback: %s"),$result['description']),
64       'edit_url' => 'config.php?display=callback&type='.$type.'&itemid='.urlencode($thisid),
65     );
66   }
67   return $destlist;
68 }
69
70 /*  Generates dialplan for callback
71   We call this with retrieve_conf
72 */
73 function callback_get_config($engine) {
74   global $ext;  // is this the best way to pass this?
75   global $asterisk_conf;
76   switch($engine) {
77     case "asterisk":
78       $timelist = callback_list();
79       if(is_array($timelist)) {
80         foreach($timelist as $item) {
81           //$thisitem = callback_get(ltrim($item['callback_id']));
82           // add dialplan
83          
84           // use callbacknum if avail, otherwise use cidnum
85           $callback_num = (empty($item['callbacknum']) ? '${CALLERID(number)}' : $item['callbacknum']);
86           $ext->add('callback', $item['callback_id'], '', new ext_setvar("CALL",$callback_num));
87          
88           //substitute commas with periods to keep asterisk dialplan variables happy
89           $callback_destination = str_replace(",",".",$item['destination']);
90           $ext->add('callback', $item['callback_id'], '', new ext_setvar("DESTINATION",$callback_destination));
91          
92           // set sleep time
93           $sleep = (empty($item['sleep']) ? '0' : $item['sleep']);
94           $ext->add('callback', $item['callback_id'], '', new ext_setvar("SLEEP",$sleep));
95          
96           // kick off the callback script - run in background (&) so we can hangup
97           $ext->add('callback', $item['callback_id'], '', new ext_system((empty($asterisk_conf['astvarlib']) ? '/var/lib/asterisk' : $asterisk_conf['astvarlib']).'/bin/callback ${CALL} ${DESTINATION} ${SLEEP} &'));
98          
99           //hangup
100           $ext->add('callback', $item['callback_id'], '', new ext_hangup(''));
101         }
102        
103       }
104     break;
105   }
106 }
107
108 //get the existing meetme extensions
109 function callback_list() {
110   $results = sql("SELECT * FROM callback","getAll",DB_FETCHMODE_ASSOC);
111   if(is_array($results)){
112     foreach($results as $result){
113       // check to see if we have a dept match for the current AMP User.
114       if (checkDept($result['deptname'])){
115         // return this item's dialplan destination, and the description
116         $allowed[] = $result;
117       }
118     }
119   }
120   if (isset($allowed)) {
121     return $allowed;
122   } else {
123     return null;
124   }
125 }
126
127 function callback_get($id){
128   //get all the variables for the meetme
129   $results = sql("SELECT * FROM callback WHERE callback_id = '$id'","getRow",DB_FETCHMODE_ASSOC);
130   return $results;
131 }
132
133 function callback_del($id){
134   $results = sql("DELETE FROM callback WHERE callback_id = '$id'","query");
135 }
136
137 function callback_add($post){
138   if(!callback_chk($post))
139     return false;
140   extract($post);
141   if(empty($description)) $description = ${$goto0.'0'};
142   $results = sql("INSERT INTO callback (description,callbacknum,destination,deptname,sleep) values (\"$description\",\"$callbacknum\",\"${$goto0.'0'}\",\"$deptname\",\"$sleep\")");
143 }
144
145 function callback_edit($id,$post){
146   if(!callback_chk($post))
147     return false;
148   extract($post);
149   if(empty($description)) $description = ${$goto0.'0'};
150   $results = sql("UPDATE callback SET description = \"$description\", callbacknum = \"$callbacknum\", destination = \"${$goto0.'0'}\", deptname = \"$deptname\", sleep = \"$sleep\" WHERE callback_id = \"$id\"");
151 }
152
153 // ensures post vars is valid
154 function callback_chk($post){
155   return true;
156 }
157 ?>
Note: See TracBrowser for help on using the browser.