Changeset 2410

Show
Ignore:
Timestamp:
09/13/06 22:40:48 (7 years ago)
Author:
qldrob
Message:

Tentative support for linking recordings together, as well as the ability to use system recordings. It still has a few bugs in it, so not publishing a module.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.2/recordings/functions.inc.php

    r2173 r2410  
    33// Source and Destination Dirctories for recording 
    44$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'; 
    126$recordings_astsnd_path .= "/sounds/"; 
    137 
     
    9286  } 
    9387} 
     88 
     89function recordings_get_file($id) { 
     90  $res = recordings_get($id); 
     91  return $res['filename']; 
     92} 
    9493   
    9594 
     
    122121  global $recordings_astsnd_path; 
    123122 
    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')"); 
    133136  return true; 
    134137   
    135138} 
    136139 
    137 function recordings_update($id, $rname, $descr) { 
    138    $results = sql("UPDATE recordings SET displayname = \"$rname\", description = \"$descr\" WHERE id = \"$id\""); 
    139 
     140function 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 
     186function 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
     195function 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
     203function 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   
    140215 
    141216function recordings_del($id) { 
    142    $results = sql("DELETE FROM recordings WHERE id = \"$id\""); 
    143 
     217  $results = sql("DELETE FROM recordings WHERE id = \"$id\""); 
     218
     219 
     220function 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 
     228function 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   
     241function 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   
    144256 
    145257?> 
  • modules/branches/2.2/recordings/install.php

    r2167 r2410  
    2828// load up any recordings that might be in the directory 
    2929$recordings_directory = $recordings_astsnd_path."custom/"; 
     30 
     31if (!file_exists($recordings_directory)) {  
     32  mkdir ($recordings_directory); 
     33} 
    3034if (!is_writable($recordings_directory)) { 
    3135  print "<h2>Error</h2><br />I can not access the directory $recordings_directory. "; 
  • modules/branches/2.2/recordings/page.recordings.php

    r2338 r2410  
    2020$rname = isset($_REQUEST['rname'])?$_REQUEST['rname']:''; 
    2121$usersnum = isset($_REQUEST['usersnum'])?$_REQUEST['usersnum']:''; 
     22$sysrec = isset($_REQUEST['sysrec'])?$_REQUEST['sysrec']:''; 
    2223if (empty($usersnum)) { 
    2324  $dest = "unnumbered-"; 
     
    4041switch ($action) { 
    4142   
     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; 
    4260  case "recorded": 
    4361    // Clean up the filename, take out any nasty characters 
     
    6179     
    6280  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      } 
    7097    } 
    7198     
     
    75102     
    76103  case "edited": 
    77     recordings_update($id, $rname, $notes); 
     104    recordings_update($id, $rname, $notes, $_REQUEST); 
    78105    recording_sidebar($id, $usersnum); 
    79106    recording_editpage($id, $usersnum); 
    80107    echo '<div class="content"><h5>'._("System Recording").' "'.$rname.'" '._("Updated").'!</h5></div>'; 
     108    needreload(); 
    81109    break; 
    82110     
    83111  case "delete"; 
    84112    recordings_del($id); 
     113    needreload(); 
    85114     
    86115  default: 
     
    124153  </form> 
    125154  <?php 
    126  
    127155  if (isset($_FILES['ivrfile']['tmp_name']) && is_uploaded_file($_FILES['ivrfile']['tmp_name'])) { 
    128156    if (empty($usersnum)) { 
     
    157185    </tr> 
    158186  </table> 
     187   
    159188  <h6><?php echo _("Click \"SAVE\" when you are satisfied with your recording")?> 
    160189  <input name="Submit" type="submit" value="<?php echo _("Save")?>"></h6>  
     
    184213  <input type="hidden" name="display" value="recordings"> 
    185214  <input type="hidden" name="usersnum" value="<?php echo $num ?>"> 
    186   <input type="hidden" name="filename" value="<?php echo $this_recording['filename'] ?>"> 
    187215  <input type="hidden" name="id" value="<?php echo $id ?>"> 
    188216  <table> 
     
    197225  </tr> 
    198226  </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> 
    199243  <input name="Submit" type="submit" value="<?php echo _("Save")?>"></h6> 
    200244  <?php recordings_form_jscript(); ?>  
     
    208252        <div class="rnav"> 
    209253        <li><a id="<?php echo empty($id)?'current':'nul' ?>" href="config.php?display=recordings&amp;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&amp;action=system"><?php echo _("Built-in Recordings")?></a></li> 
    210255<?php 
    211256    $wrapat = 18; 
     
    217262                        echo "action=edit&amp;"; 
    218263                        echo "usersnum=".urlencode($num)."&amp;"; 
    219                         echo "filename=".urlencode($tresult[2])."&amp;"; 
     264//                        echo "filename=".urlencode($tresult[2])."&amp;"; 
    220265                        echo "id={$tresult[0]}\">"; 
    221266                        $dispname = $tresult[1]; 
     
    258303} 
    259304 
     305function 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); 
    260309?> 
     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 
     333function 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?>