Changeset 2410
- Timestamp:
- 09/13/06 22:40:48 (7 years ago)
- Files:
-
- modules/branches/2.2/recordings/functions.inc.php (modified) (3 diffs)
- modules/branches/2.2/recordings/install.php (modified) (1 diff)
- modules/branches/2.2/recordings/page.recordings.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.2/recordings/functions.inc.php
r2173 r2410 3 3 // Source and Destination Dirctories for recording 4 4 $recordings_save_path = "/tmp/"; 5 //if ( (isset($amp_conf['ASTVARLIBDIR'])?$amp_conf['ASTVARLIBDIR']:'') == '') { 6 if ( (isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'') =='') { 7 $recordings_astsnd_path = "/var/lib/asterisk"; 8 } else { 9 // $recordings_astsnd_path = $amp_conf['ASTVARLIBDIR']; 10 $recordinds_astsnd_path = $asterisk_conf['astvarlibdir']; 11 } 5 $recordings_astsnd_path = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 12 6 $recordings_astsnd_path .= "/sounds/"; 13 7 … … 92 86 } 93 87 } 88 89 function recordings_get_file($id) { 90 $res = recordings_get($id); 91 return $res['filename']; 92 } 94 93 95 94 … … 122 121 global $recordings_astsnd_path; 123 122 124 // Check to make sure we can actually read the file 125 if (!is_readable($recordings_astsnd_path.$filename)) { 126 print "<p>Unable to add ".$recordings_astsnd_path.$filename." - Can not read file!</p>"; 127 return false; 128 } 129 // Now, we don't want a .wav or .gsm on the end if there is one. 130 if (strstr($filename, '.wav') || strstr($filename, '.gsm')) 131 $nowav = substr($filename, 0, -4); 132 sql("INSERT INTO recordings values ('', '$displayname', '$nowav', 'No long description available')"); 123 // Check to make sure we can actually read the file if it has an extension (if it doesn't, 124 // it was put here by system recordings, so we know it's there. 125 if (preg_match("/\.(au|g723|g723sf|g726-\d\d|g729|gsm|h263|ilbc|ogg|pcm|[au]law|[au]l|mu|sln|raw|vox|WAV|wav|wav49)$/", $filename)) { 126 if (!is_readable($recordings_astsnd_path.$filename)) { 127 print "<p>Unable to add ".$recordings_astsnd_path.$filename." - Can not read file!</p>"; 128 return false; 129 } 130 $fname = preg_replace("/\.(au|g723|g723sf|g726-\d\d|g729|gsm|h263|ilbc|ogg|pcm|[au]law|[au]l|mu|sln|raw|vox|WAV|wav|wav49)$/", "", $filename); 131 132 } else { 133 $fname = $filename; 134 } 135 sql("INSERT INTO recordings values ('', '$displayname', '$fname', 'No long description available')"); 133 136 return true; 134 137 135 138 } 136 139 137 function recordings_update($id, $rname, $descr) { 138 $results = sql("UPDATE recordings SET displayname = \"$rname\", description = \"$descr\" WHERE id = \"$id\""); 139 } 140 function recordings_update($id, $rname, $descr, $_REQUEST) { 141 142 // Update the descriptive fields 143 $results = sql("UPDATE recordings SET displayname = \"$rname\", description = \"$descr\" WHERE id = \"$id\""); 144 145 // Build the file list from _REQUEST 146 $astsnd = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 147 $astsnd .= "/sounds/"; 148 $sysrecs = recordings_readdir($astsnd, strlen($astsnd)+1); 149 $recordings = Array(); 150 151 // Set the file names from the submitted page, sysrec[N] 152 foreach ($_REQUEST as $key => $val) { 153 $res = strpos($key, 'sysrec'); 154 if ($res !== false) { 155 $recordings[substr($key,6)]=$sysrecs[$val]; 156 } 157 } 158 159 // Stick the filename in the database 160 recordings_set_file($id, implode('&', $recordings)); 161 162 // In _REQUEST there are also various actions (possibly) 163 // up[N] - Move file id N up one place 164 // down[N] - Move fid N down one place 165 // del[N] - Delete fid N 166 167 foreach ($_REQUEST as $key => $val) { 168 $up = strpos($key, "up"); 169 $down = strpos($key, "down"); 170 $del = strpos($key, "del"); 171 if ( $up !== false ) { 172 $up = substr($key, 2); 173 recordings_move_file_up($id, $up); 174 } 175 if ($del !== false ) { 176 $del = substr($key,3); 177 recordings_delete_file($id, $del); 178 } 179 if ($down !== false ) { 180 $down = substr($key,4); 181 recordings_move_file_down($id, $down); 182 } 183 } 184 } 185 186 function recordings_move_file_up($id, $src) { 187 $files = recordings_get_file($id); 188 if ($src === 0 || $src < 0) { return false; } // Should never happen, up shouldn't appear whten fid=0 189 $tmparr = explode('&', $files); 190 $tmp = $tmparr[$src-1]; 191 $tmparr[$src-1] = $tmparr[$src]; 192 $tmparr[$src] = $tmp; 193 recordings_set_file($id, implode('&', $tmparr)); 194 } 195 function recordings_move_file_down($id, $src) { 196 $files = recordings_get_file($id); 197 $tmparr = explode('&', $files); 198 $tmp = $tmparr[$src+1]; 199 $tmparr[$src+1] = $tmparr[$src]; 200 $tmparr[$src] = $tmp; 201 recordings_set_file($id, implode('&', $tmparr)); 202 } 203 function recordings_delete_file($id, $src) { 204 $files = recordings_get_file($id); 205 $tmparr = explode('&', $files); 206 $tmp = Array(); 207 $counter = 0; 208 foreach ($tmparr as $file) { 209 if ($counter != $src) { $tmp[] = $file; } 210 $counter++; 211 } 212 recordings_set_file($id, implode('&', $tmp)); 213 } 214 140 215 141 216 function recordings_del($id) { 142 $results = sql("DELETE FROM recordings WHERE id = \"$id\""); 143 } 217 $results = sql("DELETE FROM recordings WHERE id = \"$id\""); 218 } 219 220 function recordings_set_file($id, $filename) { 221 // Strip off any dangling &'s on the end: 222 $filename = rtrim($filename, '&'); 223 $results = sql("UPDATE recordings SET filename = \"$filename\" WHERE id = \"$id\""); 224 } 225 226 227 228 function recordings_readdir($snddir) { 229 $files = recordings_getdir($snddir); 230 $ptr = 0; 231 foreach ($files as $fnam) { 232 $files[$ptr] = substr($fnam, strlen($snddir)+1); 233 $ptr++; 234 } 235 // Strip off every possible file extension 236 $flist = preg_replace("/\.(au|g723|g723sf|g726-\d\d|g729|gsm|h263|ilbc|ogg|pcm|[au]law|[au]l|mu|sln|raw|vox|WAV|wav|wav49)$/", "", $files); 237 sort($flist); 238 return array_unique($flist); 239 } 240 241 function recordings_getdir($snddir) { 242 $dir = opendir($snddir); 243 $files = Array(); 244 while ($fn = readdir($dir)) { 245 if ($fn == '.' || $fn == '..') { continue; } 246 if (is_dir($snddir.'/'.$fn)) { 247 $files = array_merge(recordings_getdir($snddir.'/'.$fn), $files); 248 continue; 249 } 250 $files[] = $snddir.'/'.$fn; 251 } 252 return $files; 253 } 254 255 144 256 145 257 ?> modules/branches/2.2/recordings/install.php
r2167 r2410 28 28 // load up any recordings that might be in the directory 29 29 $recordings_directory = $recordings_astsnd_path."custom/"; 30 31 if (!file_exists($recordings_directory)) { 32 mkdir ($recordings_directory); 33 } 30 34 if (!is_writable($recordings_directory)) { 31 35 print "<h2>Error</h2><br />I can not access the directory $recordings_directory. "; modules/branches/2.2/recordings/page.recordings.php
r2338 r2410 20 20 $rname = isset($_REQUEST['rname'])?$_REQUEST['rname']:''; 21 21 $usersnum = isset($_REQUEST['usersnum'])?$_REQUEST['usersnum']:''; 22 $sysrec = isset($_REQUEST['sysrec'])?$_REQUEST['sysrec']:''; 22 23 if (empty($usersnum)) { 23 24 $dest = "unnumbered-"; … … 40 41 switch ($action) { 41 42 43 case "system": 44 recording_sidebar(-1, null); 45 recording_sysfiles(); 46 break; 47 case "newsysrec": 48 $astsnd = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 49 $astsnd .= "/sounds/"; 50 $sysrecs = recordings_readdir($astsnd, strlen($astsnd)+1); 51 if (recordings_add($sysrecs[$sysrec], $sysrecs[$sysrec])) { 52 $id = recordings_get_id($sysrecs[$sysrec]); 53 } else { 54 $id = 0; 55 } 56 recording_sidebar($id, null); 57 recording_editpage($id, null); 58 needreload(); 59 break; 42 60 case "recorded": 43 61 // Clean up the filename, take out any nasty characters … … 61 79 62 80 case "edit": 63 $filename = $_REQUEST['filename']; 64 if (file_exists($recordings_astsnd_path."{$filename}.wav")) { 65 copy($recordings_astsnd_path."{$filename}.wav", $recordings_save_path."{$dest}ivrrecording.wav"); 66 } elseif (file_exists($recordings_astsnd_path."{$filename}.gsm")) { 67 copy($recordings_astsnd_path."{$filename}.gsm", $recordings_save_path."{$dest}ivrrecording.gsm"); 68 } else { 69 echo '<div class="content"><h5>'._("Unable to locate").' '.$recordings_astsnd_path.$filename.' '._("with a wav or gsm suffix").'</h5>'; 81 $arr = recordings_get($id); 82 $filename=$arr['filename']; 83 // Check all possibilities of uploaded file types. 84 $valid = Array("au","g723","g723sf","g729","gsm","h263","ilbc","ogg","pcm","alaw","ulaw","al","ul","mu","sln","raw","vox","WAV","wav","wav49"); 85 $fileexists = false; 86 if (strpos($filename, '&') === false) { 87 foreach ($valid as $xtn) { 88 $checkfile = $recordings_astsnd_path.$filename.".".$xtn; 89 if (file_exists($checkfile)) { 90 copy($checkfile, $recordings_save_path."{$dest}ivrrecording.wav"); 91 $fileexists = true; 92 } 93 } 94 if ($fileexists === false) { 95 echo '<div class="content"><h5>'._("Unable to locate").' '.$recordings_astsnd_path.$filename.' '._("with a a valid suffix").'</h5>'; 96 } 70 97 } 71 98 … … 75 102 76 103 case "edited": 77 recordings_update($id, $rname, $notes );104 recordings_update($id, $rname, $notes, $_REQUEST); 78 105 recording_sidebar($id, $usersnum); 79 106 recording_editpage($id, $usersnum); 80 107 echo '<div class="content"><h5>'._("System Recording").' "'.$rname.'" '._("Updated").'!</h5></div>'; 108 needreload(); 81 109 break; 82 110 83 111 case "delete"; 84 112 recordings_del($id); 113 needreload(); 85 114 86 115 default: … … 124 153 </form> 125 154 <?php 126 127 155 if (isset($_FILES['ivrfile']['tmp_name']) && is_uploaded_file($_FILES['ivrfile']['tmp_name'])) { 128 156 if (empty($usersnum)) { … … 157 185 </tr> 158 186 </table> 187 159 188 <h6><?php echo _("Click \"SAVE\" when you are satisfied with your recording")?> 160 189 <input name="Submit" type="submit" value="<?php echo _("Save")?>"></h6> … … 184 213 <input type="hidden" name="display" value="recordings"> 185 214 <input type="hidden" name="usersnum" value="<?php echo $num ?>"> 186 <input type="hidden" name="filename" value="<?php echo $this_recording['filename'] ?>">187 215 <input type="hidden" name="id" value="<?php echo $id ?>"> 188 216 <table> … … 197 225 </tr> 198 226 </table> 227 <hr /> 228 Files:<br /> 229 <table> 230 <?php 231 $rec = recordings_get($id); 232 $fn = $rec['filename']; 233 $files = explode('&', $fn); 234 $counter = 0; 235 $arraymax = count($files)-1; 236 foreach ($files as $item) { 237 recordings_display_sndfile($item, $counter, $arraymax); 238 $counter++; 239 } 240 recordings_display_sndfile('', $counter); 241 ?> 242 </table> 199 243 <input name="Submit" type="submit" value="<?php echo _("Save")?>"></h6> 200 244 <?php recordings_form_jscript(); ?> … … 208 252 <div class="rnav"> 209 253 <li><a id="<?php echo empty($id)?'current':'nul' ?>" href="config.php?display=recordings&usersnum=<?php echo urlencode($num) ?>"><?php echo _("Add Recording")?></a></li> 254 <li><a id="<?php echo ($id===-1)?'current':'nul' ?>" href="config.php?display=recordings&action=system"><?php echo _("Built-in Recordings")?></a></li> 210 255 <?php 211 256 $wrapat = 18; … … 217 262 echo "action=edit&"; 218 263 echo "usersnum=".urlencode($num)."&"; 219 echo "filename=".urlencode($tresult[2])."&";264 // echo "filename=".urlencode($tresult[2])."&"; 220 265 echo "id={$tresult[0]}\">"; 221 266 $dispname = $tresult[1]; … … 258 303 } 259 304 305 function recording_sysfiles() { 306 $astsnd = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 307 $astsnd .= "/sounds/"; 308 $sysrecs = recordings_readdir($astsnd, strlen($astsnd)+1); 260 309 ?> 310 <div class="content"> 311 <h2><?php echo _("System Recordings")?></h2> 312 <h3><?php echo _("Built-in Recordings") ?></h3> 313 <h5><?php echo _("Select System Recording:")?></h5> 314 <form name="xtnprompt" action="<?php $_SERVER['PHP_SELF'] ?>" method="post"> 315 <input type="hidden" name="action" value="newsysrec"> 316 <input type="hidden" name="display" value="recordings"> 317 <select name="sysrec"/> 318 <?php 319 $srcount=0; 320 foreach ($sysrecs as $sr) { 321 // echo '<option value="'.$vmc.'"'.($vmc == $ivr_details['dircontext'] ? ' SELECTED' : '').'>'.$vmc."</option>\n"; 322 echo '<option value="'.$srcount.'">'.$sr."</option>\n"; 323 $srcount++; 324 } 325 ?> 326 </select> 327 <input name="Submit" type="submit" value="<?php echo _("Go"); ?>"> 328 <p /> 329 </div> 330 <?php 331 } 332 333 function recordings_display_sndfile($item, $count, $max) { 334 // Note that when using this, it needs a <table> definition around it. 335 $astsnd = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 336 $astsnd .= "/sounds/"; 337 $sysrecs = recordings_readdir($astsnd, strlen($astsnd)+1); 338 print "<tr><td><select name='sysrec$count'>\n"; 339 echo '<option value=""'.($item == '' ? ' SELECTED' : '')."></option>\n"; 340 $srcount = 0; 341 foreach ($sysrecs as $sr) { 342 echo '<option value="'.$srcount.'"'.($sr == $item ? ' SELECTED' : '').'>'.$sr."</option>\n"; 343 $srcount++; 344 } 345 print "</select></td>\n"; 346 if ($count==0) { 347 print "<td></td>\n"; 348 } else { 349 echo '<td><input name="up'.$count.'" type="submit" value="'._("Move Up")."\"></td>\n"; 350 } 351 if ($count > $max) { 352 print "<td></td>\n"; 353 } else { 354 echo '<td><input name="down'.$count.'" type="submit" value="'._("Move Down")."\"></td>\n"; 355 } 356 echo '<td><input name="del'.$count.'" type="submit" value="'._("Delete")."\"></td>\n"; 357 print "</tr>\n"; 358 } 359 360 ?>
