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

Revision 4901, 4.6 kB (checked in by p_lindheimer, 5 years ago)

#2172 replace deprecated use of | with ,

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_get_config($engine) {
13   global $ext;
14   switch ($engine) {
15     case 'asterisk':
16       foreach (announcement_list() as $row) {
17         if (! $row[6]) {
18           $ext->add('app-announcement-'.$row[0], 's', '', new ext_gotoif('$["${CDR(disposition)}" = "ANSWERED"]','begin'));
19           $ext->add('app-announcement-'.$row[0], 's', '', new ext_answer(''));
20           $ext->add('app-announcement-'.$row[0], 's', '', new ext_wait('1'));
21         }
22         $ext->add('app-announcement-'.$row[0], 's', 'begin', new ext_noop('Playing announcement '.$row[1]));
23         if ($row[3] || $row[7]) {
24           // allow skip
25           if ($row[7]) {
26             $ext->add('app-announcement-'.$row[0], 's', '', new ext_responsetimeout(3));
27           }
28           $ext->add('app-announcement-'.$row[0], 's', 'play', new ext_background($row[2].'|nm'));
29          
30           if ($row[3]) {
31             $ext->add('app-announcement-'.$row[0], '_X', '', new ext_noop('User skipped announcement'));
32             if ($row[5]) {
33               $ext->add('app-announcement-'.$row[0], '_X', '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));
34             } else {
35               $ext->add('app-announcement-'.$row[0], '_X', '', new ext_goto($row[4]));
36             }
37           }
38           if ($row[7]) {
39             $ext->add('app-announcement-'.$row[0], $row[7], '', new ext_goto('s,play'));
40           }
41         } else {
42           $ext->add('app-announcement-'.$row[0], 's', '', new ext_playback($row[2].',noanswer'));
43         }
44
45         // if repeat_msg enabled then set exten to t to allow for the key to be pressed, otherwise play message and go
46         $exten = $row[7] ? 't':'s';
47         if ($row[5]) {
48           $ext->add('app-announcement-'.$row[0], $exten, '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));
49           if ($row[3] || $row[7])
50             $ext->add('app-announcement-'.$row[0], 'i', '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));
51         } else {
52           $ext->add('app-announcement-'.$row[0], $exten, '', new ext_goto($row[4]));
53           if ($row[3] || $row[7])
54             $ext->add('app-announcement-'.$row[0], 'i', '', new ext_goto($row[4]));
55         }
56        
57       }
58     break;
59   }
60 }
61
62 function announcement_list() {
63   global $db;
64   $sql = "SELECT announcement_id, description, recording, allow_skip, post_dest, return_ivr, noanswer, repeat_msg FROM announcement ORDER BY description ";
65   $results = $db->getAll($sql);
66   if(DB::IsError($results)) {
67     die_freepbx($results->getMessage()."<br><br>Error selecting from announcement"); 
68   }
69   return $results;
70 }
71
72 function announcement_get($announcement_id) {
73   global $db;
74   $sql = "SELECT announcement_id, description, recording, allow_skip, post_dest, return_ivr, noanswer, repeat_msg FROM announcement WHERE announcement_id = ".addslashes($announcement_id);
75   $row = $db->getRow($sql);
76   if(DB::IsError($row)) {
77     die_freepbx($row->getMessage()."<br><br>Errpr selecting row from announcement"); 
78   }
79   return $row;
80 }
81
82 function announcement_add($description, $recording, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg) {
83   global $db;
84   $sql = "INSERT INTO announcement (description, recording, allow_skip, post_dest, return_ivr, noanswer, repeat_msg) VALUES (".
85     "'".addslashes($description)."', ".
86     "'".addslashes($recording)."', ".
87     "'".($allow_skip ? 1 : 0)."', ".
88     "'".addslashes($post_dest)."', ".
89     "'".($return_ivr ? 1 : 0)."', ".
90     "'".($noanswer ? 1 : 0)."', ".
91     "'".addslashes($repeat_msg)."')";
92   $result = $db->query($sql);
93   if(DB::IsError($result)) {
94     die_freepbx($result->getMessage().$sql);
95   }
96 }
97
98 function announcement_delete($announcement_id) {
99   global $db;
100   $sql = "DELETE FROM announcement WHERE announcement_id = ".addslashes($announcement_id);
101   $result = $db->query($sql);
102   if(DB::IsError($result)) {
103     die_freepbx($result->getMessage().$sql);
104   }
105  
106 }
107
108 function announcement_edit($announcement_id, $description, $recording, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg) {
109   global $db;
110   $sql = "UPDATE announcement SET ".
111     "description = '".addslashes($description)."', ".
112     "recording = '".addslashes($recording)."', ".
113     "allow_skip = '".($allow_skip ? 1 : 0)."', ".
114     "post_dest = '".addslashes($post_dest)."', ".
115     "return_ivr = '".($return_ivr ? 1 : 0)."', ".
116     "noanswer = '".($noanswer ? 1 : 0)."', ".
117     "repeat_msg = '".addslashes($repeat_msg)."' ".
118     "WHERE announcement_id = ".addslashes($announcement_id);
119   $result = $db->query($sql);
120   if(DB::IsError($result)) {
121     die_freepbx($result->getMessage().$sql);
122   }
123 }
124
125 ?>
Note: See TracBrowser for help on using the browser.