Changeset 6128
- Timestamp:
- 07/23/08 00:28:50 (4 years ago)
- Files:
-
- modules/branches/2.5/announcement/functions.inc.php (modified) (7 diffs)
- modules/branches/2.5/announcement/install.php (modified) (3 diffs)
- modules/branches/2.5/announcement/install.sql (deleted)
- modules/branches/2.5/announcement/module.xml (modified) (2 diffs)
- modules/branches/2.5/announcement/page.announcement.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.5/announcement/functions.inc.php
r5841 r6128 5 5 $extens = array(); 6 6 foreach (announcement_list() as $row) { 7 $extens[] = array('destination' => 'app-announcement-'.$row[ 0].',s,1', 'description' => $row[1]);7 $extens[] = array('destination' => 'app-announcement-'.$row['announcement_id'].',s,1', 'description' => $row[1]); 8 8 } 9 9 return $extens; … … 35 35 } 36 36 37 function announcement_recordings_usage($recording_id) { 38 global $active_modules; 39 40 $results = sql("SELECT announcement_id, description FROM announcement WHERE recording_id = '$recording_id'","getAll",DB_FETCHMODE_ASSOC); 41 if (empty($results)) { 42 return array(); 43 } else { 44 $type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup'; 45 foreach ($results as $result) { 46 $usage_arr[] = array( 47 'url_query' => 'config.php?display=announcement&type='.$type.'&extdisplay='.urlencode($result['announcement_id']), 48 'description' => "Announcement: ".$result['description'], 49 ); 50 } 51 return $usage_arr; 52 } 53 } 54 37 55 function announcement_get_config($engine) { 38 56 global $ext; … … 40 58 case 'asterisk': 41 59 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')); 60 $recording = recordings_get_file($row['recording_id']); 61 if (! $row['noanswer']) { 62 $ext->add('app-announcement-'.$row['announcement_id'], 's', '', new ext_gotoif('$["${CDR(disposition)}" = "ANSWERED"]','begin')); 63 $ext->add('app-announcement-'.$row['announcement_id'], 's', '', new ext_answer('')); 64 $ext->add('app-announcement-'.$row['announcement_id'], 's', '', new ext_wait('1')); 46 65 } 47 $ext->add('app-announcement-'.$row[ 0], 's', 'begin', new ext_noop('Playing announcement '.$row[1]));48 if ($row[ 3] || $row[7]) {66 $ext->add('app-announcement-'.$row['announcement_id'], 's', 'begin', new ext_noop('Playing announcement '.$row['description'])); 67 if ($row['allow_skip'] || $row['repeat_msg']) { 49 68 // allow skip 50 if ($row[ 7]) {51 $ext->add('app-announcement-'.$row[ 0], 's', '', new ext_responsetimeout(3));69 if ($row['repeat_msg']) { 70 $ext->add('app-announcement-'.$row['announcement_id'], 's', '', new ext_responsetimeout(3)); 52 71 } 53 $ext->add('app-announcement-'.$row[ 0], 's', 'play', new ext_background($row[2].'|nm'));72 $ext->add('app-announcement-'.$row['announcement_id'], 's', 'play', new ext_background($recording.'|nm')); 54 73 55 if ($row[ 3]) {56 $ext->add('app-announcement-'.$row[ 0], '_X', '', new ext_noop('User skipped announcement'));57 if ($row[ 5]) {58 $ext->add('app-announcement-'.$row[ 0], '_X', '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));74 if ($row['allow_skip']) { 75 $ext->add('app-announcement-'.$row['announcement_id'], '_X', '', new ext_noop('User skipped announcement')); 76 if ($row['return_ivr']) { 77 $ext->add('app-announcement-'.$row['announcement_id'], '_X', '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row['post_dest'].':${IVR_CONTEXT},return,1')); 59 78 } else { 60 $ext->add('app-announcement-'.$row[ 0], '_X', '', new ext_goto($row[4]));79 $ext->add('app-announcement-'.$row['announcement_id'], '_X', '', new ext_goto($row['post_dest'])); 61 80 } 62 81 } 63 if ($row[ 7]) {64 $ext->add('app-announcement-'.$row[ 0], $row[7], '', new ext_goto('s,play'));82 if ($row['repeat_msg']) { 83 $ext->add('app-announcement-'.$row['announcement_id'], $row['repeat_msg'], '', new ext_goto('s,play')); 65 84 } 66 85 } else { 67 $ext->add('app-announcement-'.$row[ 0], 's', '', new ext_playback($row[2].',noanswer'));86 $ext->add('app-announcement-'.$row['announcement_id'], 's', '', new ext_playback($recording.',noanswer')); 68 87 } 69 88 70 89 // if repeat_msg enabled then set exten to t to allow for the key to be pressed, otherwise play message and go 71 $exten = $row[ 7] ? 't':'s';72 if ($row[ 5]) {73 $ext->add('app-announcement-'.$row[ 0], $exten, '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));74 if ($row[ 3] || $row[7])75 $ext->add('app-announcement-'.$row[ 0], 'i', '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row[4].':${IVR_CONTEXT},return,1'));90 $exten = $row['repeat_msg'] ? 't':'s'; 91 if ($row['return_ivr']) { 92 $ext->add('app-announcement-'.$row['announcement_id'], $exten, '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row['post_dest'].':${IVR_CONTEXT},return,1')); 93 if ($row['allow_skip'] || $row['repeat_msg']) 94 $ext->add('app-announcement-'.$row['announcement_id'], 'i', '', new ext_gotoif('$["x${IVR_CONTEXT}" = "x"]', $row['post_dest'].':${IVR_CONTEXT},return,1')); 76 95 } else { 77 $ext->add('app-announcement-'.$row[ 0], $exten, '', new ext_goto($row[4]));78 if ($row[ 3] || $row[7])79 $ext->add('app-announcement-'.$row[ 0], 'i', '', new ext_goto($row[4]));96 $ext->add('app-announcement-'.$row['announcement_id'], $exten, '', new ext_goto($row['post_dest'])); 97 if ($row['allow_skip'] || $row['repeat_msg']) 98 $ext->add('app-announcement-'.$row['announcement_id'], 'i', '', new ext_goto($row['post_dest'])); 80 99 } 81 100 … … 87 106 function announcement_list() { 88 107 global $db; 89 $sql = "SELECT announcement_id, description, recording , allow_skip, post_dest, return_ivr, noanswer, repeat_msg FROM announcement ORDER BY description ";90 $results = $db->getAll($sql );108 $sql = "SELECT announcement_id, description, recording_id, allow_skip, post_dest, return_ivr, noanswer, repeat_msg FROM announcement ORDER BY description "; 109 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 91 110 if(DB::IsError($results)) { 92 111 die_freepbx($results->getMessage()."<br><br>Error selecting from announcement"); 93 112 } 113 114 // Make array backward compatible. 115 $count = 0; 116 foreach($results as $item) { 117 $results[$count][0] = $item['announcement_id']; 118 $results[$count][1] = $item['description']; 119 $results[$count][2] = $item['recording_id']; 120 $results[$count][3] = $item['allow_skip']; 121 $results[$count][4] = $item['post_dest']; 122 $results[$count][5] = $item['return_ivr']; 123 $results[$count][6] = $item['noanswer']; 124 $results[$count][7] = $item['repeat_msg']; 125 $count++; 126 } 94 127 return $results; 95 128 } … … 97 130 function announcement_get($announcement_id) { 98 131 global $db; 99 $sql = "SELECT announcement_id, description, recording , allow_skip, post_dest, return_ivr, noanswer, repeat_msg FROM announcement WHERE announcement_id = '".addslashes($announcement_id)."'";132 $sql = "SELECT announcement_id, description, recording_id, allow_skip, post_dest, return_ivr, noanswer, repeat_msg FROM announcement WHERE announcement_id = '".addslashes($announcement_id)."'"; 100 133 $row = $db->getRow($sql,DB_FETCHMODE_ASSOC); 101 134 if(DB::IsError($row)) { … … 112 145 } 113 146 114 function announcement_add($description, $recording , $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg) {115 global $db; 116 $sql = "INSERT INTO announcement (description, recording , allow_skip, post_dest, return_ivr, noanswer, repeat_msg) VALUES (".147 function announcement_add($description, $recording_id, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg) { 148 global $db; 149 $sql = "INSERT INTO announcement (description, recording_id, allow_skip, post_dest, return_ivr, noanswer, repeat_msg) VALUES (". 117 150 "'".addslashes($description)."', ". 118 "'". addslashes($recording)."', ".151 "'".$recording_id."', ". 119 152 "'".($allow_skip ? 1 : 0)."', ". 120 153 "'".addslashes($post_dest)."', ". … … 138 171 } 139 172 140 function announcement_edit($announcement_id, $description, $recording , $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg) {173 function announcement_edit($announcement_id, $description, $recording_id, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg) { 141 174 global $db; 142 175 $sql = "UPDATE announcement SET ". 143 176 "description = '".addslashes($description)."', ". 144 "recording = '".addslashes($recording)."', ".177 "recording_id = '".$recording_id."', ". 145 178 "allow_skip = '".($allow_skip ? 1 : 0)."', ". 146 179 "post_dest = '".addslashes($post_dest)."', ". modules/branches/2.5/announcement/install.php
r4767 r6128 1 1 <?php 2 if (! function_exists("out")) { 3 function out($text) { 4 echo $text."<br />"; 5 } 6 } 7 8 if (! function_exists("outn")) { 9 function outn($text) { 10 echo $text; 11 } 12 } 2 13 3 14 global $db; … … 8 19 announcement_id integer NOT NULL PRIMARY KEY $autoincrement, 9 20 description VARCHAR( 50 ), 10 recording VARCHAR( 255 ),21 recording_id INTEGER, 11 22 allow_skip INT, 12 23 post_dest VARCHAR( 255 ), … … 83 94 } 84 95 96 // Version 2.5 migrate to recording ids 97 // 98 outn(_("Checking if recordings need migration..")); 99 $sql = "SELECT recording_id FROM announcement"; 100 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 101 if(DB::IsError($check)) { 102 // Add recording_id field 103 // 104 out("migrating"); 105 outn(_("adding recording_id field..")); 106 $sql = "ALTER TABLE announcement ADD recording_id INTEGER"; 107 $result = $db->query($sql); 108 if(DB::IsError($result)) { 109 out(_("fatal error")); 110 die_freepbx($result->getDebugInfo()); 111 } else { 112 out(_("ok")); 113 } 114 115 // Get all the valudes and replace them with recording_id 116 // 117 outn(_("migrate to recording ids..")); 118 $sql = "SELECT `announcement_id`, `recording` FROM `announcement`"; 119 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 120 if(DB::IsError($results)) { 121 out(_("fatal error")); 122 die_freepbx($results->getDebugInfo()); 123 } 124 $migrate_arr = array(); 125 $count = 0; 126 foreach ($results as $row) { 127 if (trim($row['recording']) != '') { 128 $rec_id = recordings_get_or_create_id($row['recording'], 'announcement'); 129 $migrate_arr[] = array($rec_id, $row['announcement_id']); 130 $count++; 131 } 132 } 133 if ($count) { 134 $compiled = $db->prepare('UPDATE `announcement` SET `recording_id` = ? WHERE `announcement_id` = ?'); 135 $result = $db->executeMultiple($compiled,$migrate_arr); 136 if(DB::IsError($result)) { 137 out(_("fatal error")); 138 die_freepbx($result->getDebugInfo()); 139 } 140 } 141 out(sprintf(_("migrated %s entries"),$count)); 142 143 // Now remove the old recording field replaced by new id field 144 // 145 outn(_("dropping recording field..")); 146 $sql = "ALTER TABLE `announcement` DROP `recording`"; 147 $result = $db->query($sql); 148 if(DB::IsError($result)) { 149 out(_("no recording field???")); 150 } else { 151 out(_("ok")); 152 } 153 154 } else { 155 out("already migrated"); 156 } 157 85 158 ?> modules/branches/2.5/announcement/module.xml
r6068 r6128 2 2 <rawname>announcement</rawname> 3 3 <name>Announcements</name> 4 <version>2.5. 0</version>4 <version>2.5.1</version> 5 5 <changelog> 6 *2.5.1* #2063 Migrate recordings to recording ids 6 7 *2.5.0* #2845 tabindex 7 8 *2.4.0.3* #2872 mispelled Announcement … … 31 32 </description> 32 33 <depends> 33 <version>2.4.0</version> 34 <version>2.5.0alpha1</version> 35 <module>recordings ge 3.3.8</module> 34 36 </depends> 35 37 <menuitems> modules/branches/2.5/announcement/page.announcement.php
r5919 r6128 19 19 $announcement_id = isset($_POST['announcement_id']) ? $_POST['announcement_id'] : false; 20 20 $description = isset($_POST['description']) ? $_POST['description'] : ''; 21 $recording = isset($_POST['recording']) ? $_POST['recording'] : '';21 $recording_id = isset($_POST['recording_id']) ? $_POST['recording_id'] : ''; 22 22 $allow_skip = isset($_POST['allow_skip']) ? $_POST['allow_skip'] : 0; 23 23 $return_ivr = isset($_POST['return_ivr']) ? $_POST['return_ivr'] : 0; … … 34 34 switch ($action) { 35 35 case 'add': 36 announcement_add($description, $recording , $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg);36 announcement_add($description, $recording_id, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg); 37 37 needreload(); 38 38 redirect_standard(); 39 39 break; 40 40 case 'edit': 41 announcement_edit($announcement_id, $description, $recording , $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg);41 announcement_edit($announcement_id, $description, $recording_id, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg); 42 42 needreload(); 43 43 redirect_standard('extdisplay'); … … 75 75 $row = announcement_get($extdisplay); 76 76 77 $description = $row[ 1];78 $recording = $row[2];79 $allow_skip = $row[ 3];80 $post_dest = $row[ 4];81 $return_ivr = $row[ 5];82 $noanswer = $row[ 6];83 $repeat_msg = $row[ 7];77 $description = $row['description']; 78 $recording_id = $row['recording_id']; 79 $allow_skip = $row['allow_skip']; 80 $post_dest = $row['post_dest']; 81 $return_ivr = $row['return_ivr']; 82 $noanswer = $row['noanswer']; 83 $repeat_msg = $row['repeat_msg']; 84 84 85 85 } … … 101 101 <td><a href="#" class="info"><?php echo _("Recording")?><span><?php echo _("Message to be played.<br>To add additional recordings use the \"System Recordings\" MENU to the left")?></span></a></td> 102 102 <td> 103 <select name="recording " tabindex="<?php echo ++$tabindex;?>">103 <select name="recording_id" tabindex="<?php echo ++$tabindex;?>"> 104 104 <?php 105 105 $tresults = recordings_list(); 106 $default = (isset($recording ) ? $recording: '');106 $default = (isset($recording_id) ? $recording_id : ''); 107 107 if (isset($tresults[0])) { 108 108 foreach ($tresults as $tresult) { 109 echo '<option value="'.$tresult[ 2].'"'.($tresult[2] == $default ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";109 echo '<option value="'.$tresult['id'].'"'.($tresult['id'] == $default ? ' SELECTED' : '').'>'.$tresult['displayname']."</option>\n"; 110 110 } 111 111 }
