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

Revision 6716, 6.4 kB (checked in by p_lindheimer, 4 years ago)

fixes #3196 Merged revisions 6714-6715 via svnmerge from
http://svn.freepbx.org/modules/branches/2.5

........

r6714 | p_lindheimer | 2008-09-14 10:18:41 -0700 (Sun, 14 Sep 2008) | 1 line


fixes #3196 typo in index

........

r6715 | p_lindheimer | 2008-09-14 10:19:17 -0700 (Sun, 14 Sep 2008) | 1 line


Module Publish Script: announcement 2.5.1.4

........

Line 
1 <?php
2
3 function announcement_destinations() {
4   // return an associative array with destination and description
5   $extens = array();
6   foreach (announcement_list() as $row) {
7     $extens[] = array('destination' => 'app-announcement-'.$row[0].',s,1', 'description' => $row[1]);
8   }
9   return $extens;
10 }
11
12 function announcement_getdest($exten) {
13   return array('app-announcement-'.$exten.',s,1');
14 }
15
16 function announcement_getdestinfo($dest) {
17   global $active_modules;
18
19   if (substr(trim($dest),0,17) == 'app-announcement-') {
20     $exten = explode(',',$dest);
21     $exten = substr($exten[0],17);
22
23     $thisexten = announcement_get($exten);
24     if (empty($thisexten)) {
25       return array();
26     } else {
27       $type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
28       return array('description' => 'Annoucement : '.$thisexten['description'],
29                    'edit_url' => 'config.php?display=announcement&type='.$type.'&extdisplay='.urlencode($exten),
30                   );
31     }
32   } else {
33     return false;
34   }
35 }
36
37 function announcement_get_config($engine) {
38   global $ext;
39   switch ($engine) {
40     case 'asterisk':
41       foreach (announcement_list() as $row) {
42         if (! $row[6]) {
43           $ext->add('app-announcement-'.$row[0], 's', '', new ext_gotoif('$["${CDR(disposition)}" = "ANSWERED"]','begin'));
44           $ext->add('app-announcement-'.$row[0], 's', '', new ext_answer(''));
45           $ext->add('app-announcement-'.$row[0], 's', '', new ext_wait('1'));
46         }
47         $ext->add('app-announcement-'.$row[0], 's', 'begin', new ext_noop('Playing announcement '.$row[1]));
48         if ($row[3] || $row[7]) {
49           // allow skip
50           if ($row[7]) {
51             $ext->add('app-announcement-'.$row[0], 's', '', new ext_responsetimeout(1));
52           }
53           $ext->add('app-announcement-'.$row[0], 's', 'play', new ext_background($row[2].'|nm'));
54           if ($row[7]) {
55             $ext->add('app-announcement-'.$row[0], 's', '', new ext_waitexten(''));
56           }
57          
58           if ($row[3]) {
59             $ext->add('app-announcement-'.$row[0], '_X', '', new ext_noop('User skipped announcement'));
60             if ($row[5]) {
61               $ext->add('app-announcement-'.$row[0], '_X', '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));
62             } else {
63               $ext->add('app-announcement-'.$row[0], '_X', '', new ext_goto($row[4]));
64             }
65           }
66           if ($row[7]) {
67             $ext->add('app-announcement-'.$row[0], $row[7], '', new ext_goto('s,play'));
68           }
69         } else {
70           $ext->add('app-announcement-'.$row[0], 's', '', new ext_playback($row[2].',noanswer'));
71         }
72
73         // if repeat_msg enabled then set exten to t to allow for the key to be pressed, otherwise play message and go
74         $exten = $row[7] ? 't':'s';
75         if ($row[5]) {
76           $ext->add('app-announcement-'.$row[0], $exten, '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));
77           if ($row[3] || $row[7])
78             $ext->add('app-announcement-'.$row[0], 'i', '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));
79         } else {
80           $ext->add('app-announcement-'.$row[0], $exten, '', new ext_goto($row[4]));
81           if ($row[3] || $row[7])
82             $ext->add('app-announcement-'.$row[0], 'i', '', new ext_goto($row[4]));
83         }
84        
85       }
86     break;
87   }
88 }
89
90 function announcement_list() {
91   global $db;
92   $sql = "SELECT announcement_id, description, recording, allow_skip, post_dest, return_ivr, noanswer, repeat_msg FROM announcement ORDER BY description ";
93   $results = $db->getAll($sql);
94   if(DB::IsError($results)) {
95     die_freepbx($results->getMessage()."<br><br>Error selecting from announcement"); 
96   }
97   return $results;
98 }
99
100 function announcement_get($announcement_id) {
101   global $db;
102   $sql = "SELECT announcement_id, description, recording, allow_skip, post_dest, return_ivr, noanswer, repeat_msg FROM announcement WHERE announcement_id = '".addslashes($announcement_id)."'";
103   $row = $db->getRow($sql,DB_FETCHMODE_ASSOC);
104   if(DB::IsError($row)) {
105     die_freepbx($row->getMessage()."<br><br>Errpr selecting row from announcement"); 
106   }
107   // Added Associative query above but put positional indexes back to maintain backward compatibility
108   //
109   $i = 0;
110   foreach ($row as $item) {
111     $row[$i] = $item;
112     $i++;
113   }
114   return $row;
115 }
116
117 function announcement_add($description, $recording, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg) {
118   global $db;
119   $sql = "INSERT INTO announcement (description, recording, allow_skip, post_dest, return_ivr, noanswer, repeat_msg) VALUES (".
120     "'".addslashes($description)."', ".
121     "'".addslashes($recording)."', ".
122     "'".($allow_skip ? 1 : 0)."', ".
123     "'".addslashes($post_dest)."', ".
124     "'".($return_ivr ? 1 : 0)."', ".
125     "'".($noanswer ? 1 : 0)."', ".
126     "'".addslashes($repeat_msg)."')";
127   $result = $db->query($sql);
128   if(DB::IsError($result)) {
129     die_freepbx($result->getMessage().$sql);
130   }
131 }
132
133 function announcement_delete($announcement_id) {
134   global $db;
135   $sql = "DELETE FROM announcement WHERE announcement_id = ".addslashes($announcement_id);
136   $result = $db->query($sql);
137   if(DB::IsError($result)) {
138     die_freepbx($result->getMessage().$sql);
139   }
140  
141 }
142
143 function announcement_edit($announcement_id, $description, $recording, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg) {
144   global $db;
145   $sql = "UPDATE announcement SET ".
146     "description = '".addslashes($description)."', ".
147     "recording = '".addslashes($recording)."', ".
148     "allow_skip = '".($allow_skip ? 1 : 0)."', ".
149     "post_dest = '".addslashes($post_dest)."', ".
150     "return_ivr = '".($return_ivr ? 1 : 0)."', ".
151     "noanswer = '".($noanswer ? 1 : 0)."', ".
152     "repeat_msg = '".addslashes($repeat_msg)."' ".
153     "WHERE announcement_id = ".addslashes($announcement_id);
154   $result = $db->query($sql);
155   if(DB::IsError($result)) {
156     die_freepbx($result->getMessage().$sql);
157   }
158 }
159
160 function announcement_check_destinations($dest=true) {
161   global $active_modules;
162
163   $destlist = array();
164   if (is_array($dest) && empty($dest)) {
165     return $destlist;
166   }
167   $sql = "SELECT announcement_id, post_dest, description FROM announcement ";
168   if ($dest !== true) {
169     $sql .= "WHERE post_dest in ('".implode("','",$dest)."')";
170   }
171   $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
172
173   $type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
174
175   foreach ($results as $result) {
176     $thisdest = $result['post_dest'];
177     $thisid   = $result['announcement_id'];
178     $destlist[] = array(
179       'dest' => $thisdest,
180       'description' => 'Announcement: '.$result['description'],
181       'edit_url' => 'config.php?display=announcement&type='.$type.'&extdisplay='.urlencode($thisid),
182     );
183   }
184   return $destlist;
185 }
186
187 ?>
Note: See TracBrowser for help on using the browser.