root/contributed_modules/modules/cidpopup/functions.inc.php

Revision 12025, 7.1 kB (checked in by mbrevda, 1 year ago)

fix splice point for 2.9, this needs rooling, just want to make sure there are no reported issues first

Line 
1 <?php
2
3 /* cidpopup_get_config()
4  *
5  * generate the required gosub() target that will handle our script and provide feedback
6  * to the agent (the beep).
7 **/
8 function cidpopup_get_config($engine) {
9   global $ext;
10   switch ($engine) {
11     case 'asterisk':
12       $context = 'sub-cidpost';
13       $exten = 's';
14       $ext->add($context, $exten, '', new ext_playback('beep'));
15       $ext->add($context, $exten, '', new ext_agi('${DOPOSTAGI}'));
16       $ext->add($context, $exten, '', new ext_return(''));
17     break;
18   }
19 }
20
21 /* cidpopup_hookGet_config()
22  *
23  * splice into the auto-confirm and auto-blkvm macros to launch our AGI script since these are
24  * tacked onto every ringgoup.
25 **/
26 function cidpopup_hookGet_config($engine) {
27   global $ext;
28   switch($engine) {
29     case "asterisk":
30       // First splice the auto-confirm routines used by ringgoups
31       //
32       $priority = 'no_such_priority_end';
33       $macro = 'macro-auto-confirm';
34       $ext->splice($macro,'s',$priority,new ext_gosubif('$["${DOPOSTAGI}" != ""]','sub-cidpost,s,1'));
35       $macro = 'macro-auto-blkvm';
36       $ext->splice($macro,'s',$priority,new ext_gosubif('$["${DOPOSTAGI}" != ""]','sub-cidpost,s,1'));
37
38       // Now splice each ringgoup that has this set
39       //
40       $context = 'ext-group';
41       $priority = 'skipvmblk';
42       $groups = cidpopup_list('ringgroups');
43       foreach ($groups as $group) {
44         $exten = $group['id'];
45
46         //Sanity check for blank extensions from past bug
47         if ($exten == "") {
48           continue;
49         }
50
51         $popup_info = cidpopup_instance_get($group['postagi']);
52         if (!empty($popup_info)) {
53           $ext->splice($context,$exten,$priority,new ext_setvar('_DOPOSTAGI',$popup_info['popup_script']));
54           $ext->splice($context,$exten,$priority,new ext_setvar('_POSTIPADDR',$popup_info['ipaddr']));
55           $ext->splice($context,$exten,$priority,new ext_setvar('_SAVEDCID','${CALLERID(all)}'));
56         }
57       }
58     break;
59   }
60 }
61
62 /* cidpopup_display_text()
63  *
64  * display the select box that is hooked into the Ring Group to choose a PopUp instance.
65 **/
66 function cidpopup_display_text($type, $viewing_itemid) {
67   $cidpopup_id = cidpopup_get($type,$viewing_itemid);
68   $html = '<tr><td colspan="2"><h5>';
69   $html .= _("Post Answer CID PopUps");
70   $html .= '<hr></h5></td></tr>';
71   $html .= '<tr>';
72   $html .= '<td valign="top"><a href="#" class="info">';
73   $html .= _("PopUp Instance").'<span>'._("Select the PopUp Instance you want executed upon an agent answering a call.").'.</span></a>:</td>';
74
75   $tresults = cidpopup_instance_list();
76   $default = (isset($cidpopup_id) ? $cidpopup_id : '');
77
78   $html .= '<td><select name="cidpopup_id" tabindex="<?php echo ++$tabindex;?>">';
79   $html .= '<option value="">'._("None")."</option>";
80   if (isset($tresults[0])) {
81     foreach ($tresults as $tresult) {
82       $html .=  '<option value="'.$tresult['cidpopup_id'].'"'.($tresult['cidpopup_id'] == $default ? ' SELECTED' : '').'>'.$tresult['description']."</option>\n";
83     }
84   }
85   $html .= '</select></td></tr>';
86   return $html;
87 }
88
89 /* cidpopup_hook_ringgroups()
90  *
91  * explicitly hook into ringgroups with the PopUp selections
92 **/
93 function cidpopup_hook_ringgroups($viewing_itemid, $target_menuid) {
94   return cidpopup_display_text('ringgroups', ltrim($viewing_itemid, "GRP-"));
95 }
96
97 /* cidpopup_hookProcess_ringgroups()
98  *
99  * process the hook after being submitted from the ringgroup page
100 **/
101 function cidpopup_hookProcess_ringgroups($viewing_itemid, $request) {
102
103   $viewing_itemid = ltrim($viewing_itemid, "GRP-");
104
105   if (!isset($request['action'])) {
106     return;
107   }
108
109   $cidpopup_id = isset($request['cidpopup_id'])?$request['cidpopup_id']:'';
110
111   switch ($request['action']) {
112     case 'addGRP':
113     case 'edtGRP': 
114       cidpopup_update('ringgroups', $viewing_itemid, $cidpopup_id);
115     break;
116     case 'delGRP':
117       cidpopup_del('ringgroups', $request['account']);
118     break;
119   }
120 }
121
122
123 /* cidpopup__XXXX() functions
124  *
125  * These functions are responsible for maintaining the list of Ring Groups
126  * (or eventually other module types) that have been hooked with a popup and
127  * the associated agi script/IP address instance to use.
128 **/
129
130 function cidpopup_get($type, $xtn) {
131   global $db;
132
133   $cidpopup_agi = $db->getOne("SELECT `postagi` FROM `cidpopup` WHERE `type` = '$type' AND `id` = '$xtn'");
134   if(DB::IsError($cidpopup_arr)) {
135     die_freepbx($cidpopup_arr->getDebugInfo()."<br><br>".'selecting from cidpopup table'); 
136   }
137   return $cidpopup_agi;
138 }
139
140 function cidpopup_update($type, $ext, $cidpopup_id) {
141   global $db;
142
143   sql("DELETE FROM `cidpopup` WHERE `type` = '$type' AND `id` = '$ext'");
144
145   $cidpopup_id = $db->escapeSimple(trim($cidpopup_id));
146   if ($cidpopup_id != '') {
147     $sql = "INSERT INTO `cidpopup` (`type`, `id`, `postagi`) VALUES ('$type','$ext','$cidpopup_id')";
148     sql($sql);
149   }
150 }
151
152 function cidpopup_del($type, $ext) {
153   sql("DELETE FROM `cidpopup` WHERE `type` = '$type' AND `id` = '$ext'");
154 }
155
156 function cidpopup_list($type = '') {
157   global $db;
158
159   $sql = "SELECT * FROM `cidpopup`";
160   if ($type != '') {
161     $sql .= " WHERE `type` = '$type'";
162   }
163   $cidpopup_agi = sql($sql,'getAll',DB_FETCHMODE_ASSOC);
164   return $cidpopup_agi;
165 }
166
167
168 /* cidpopup_instance_XXXX() functions
169  *
170  * These functions are responsible for maintaining the list of agi script / IP Address
171  * pairs that are presented as a select box into the Ring Groups that use them to choose
172  * if and where to send popup messages to.
173 **/
174
175 function cidpopup_instance_add($description, $popup_script, $ipaddr) {
176   global $db;
177   $sql = "INSERT INTO `cidpopup_instance` (`description`, `popup_script`, `ipaddr`) VALUES (".
178     "'".$db->escapeSimple($description)."', ".
179     "'".$db->escapeSimple($popup_script)."', ".
180     "'".$db->escapeSimple($ipaddr)."')";
181   $result = $db->query($sql);
182   if(DB::IsError($result)) {
183     die_freepbx($result->getMessage().$sql);
184   }
185 }
186
187 function cidpopup_instance_edit($cidpopup_id, $description, $popup_script, $ipaddr) {
188   global $db;
189   $sql = "UPDATE `cidpopup_instance` SET ".
190     "`description` = '".$db->escapeSimple($description)."', ".
191     "`popup_script` = '".$db->escapeSimple($popup_script)."', ".
192     "`ipaddr` = '".$db->escapeSimple($ipaddr)."' ".
193     "WHERE `cidpopup_id` = ".$db->escapeSimple($cidpopup_id);
194   $result = $db->query($sql);
195   if(DB::IsError($result)) {
196     die_freepbx($result->getMessage().$sql);
197   }
198 }
199
200 function cidpopup_instance_delete($cidpopup_id) {
201   global $db;
202   $sql = "DELETE FROM `cidpopup_instance` WHERE `cidpopup_id` = ".$db->escapeSimple($cidpopup_id);
203   $result = $db->query($sql);
204   if(DB::IsError($result)) {
205     die_freepbx($result->getMessage().$sql);
206   }
207 }
208
209 function cidpopup_instance_list() {
210   global $db;
211   $sql = "SELECT `cidpopup_id`, `description`, `ipaddr`, `popup_script` FROM `cidpopup_instance` ORDER BY `description`";
212   $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
213   if(DB::IsError($results)) {
214     die_freepbx($results->getMessage()."<br><br>Error selecting from cidpopup_instance in cidpopup_instance_list");
215   }
216   return $results;
217 }
218
219 function cidpopup_instance_get($cidpopup_id) {
220   global $db;
221   $sql = "SELECT `cidpopup_id`, `description`, `ipaddr`, `popup_script` FROM `cidpopup_instance` WHERE `cidpopup_id` = ".$db->escapeSimple($cidpopup_id);
222   $row = $db->getRow($sql, DB_FETCHMODE_ASSOC);
223   if(DB::IsError($row)) {
224     die_freepbx($row->getMessage()."<br><br>Error selecting row from cidpopup_instance in cidpopup_instance_get"); 
225   }
226   return $row;
227 }
228
229 ?>
Note: See TracBrowser for help on using the browser.