Changeset 5982

Show
Ignore:
Timestamp:
07/10/08 19:16:26 (4 years ago)
Author:
p_lindheimer
Message:

#2899 create optional feature codes linked to system recordings so user can change them

Files:

Legend:

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

    r5891 r5982  
    4242        } 
    4343      } 
     44 
     45      // Now generate the Feature Codes to edit recordings 
     46      // 
     47      $recordings = recordings_list(); 
     48      foreach ($recordings as $item) { 
     49 
     50        // Get the feature code, and do a sanity check if it is not suppose to be active and delete it 
     51        // 
     52        if ($item['fcode'] != 0) { 
     53          $fcc = new featurecode($modulename, 'edit-recording-'.$item['id']); 
     54          $fcode = $fcc->getCodeActive(); 
     55          unset($fcc); 
     56        } else { 
     57          $fcc = new featurecode('recordings', 'edit-recording-'.$item['id']); 
     58          $fcc->delete(); 
     59          unset($fcc);   
     60          continue; // loop back to foreach 
     61        } 
     62 
     63        if ($fcode != '') { 
     64          // Do a sanity check, there should be no compound files 
     65          // 
     66          if (strpos($item['filename'], '&') === false && trim($item['filename']) != '') { 
     67            $fcode_pass = (trim($item['fcode_pass']) != '') ? ','.$item['fcode_pass'] : ''; 
     68            $ext->add($appcontext, $fcode, '', new ext_macro('user-callerid')); 
     69            $ext->add($appcontext, $fcode, '', new ext_wait('2')); 
     70            $ext->add($appcontext, $fcode, '', new ext_macro('systemrecording', 'docheck,'.$item['filename'].$fcode_pass)); 
     71            //$ext->add($appcontext, $fcode, '', new ext_macro('hangup')); 
     72          } 
     73        } 
     74      } 
    4475    break; 
    4576  } 
    46 }       
     77} 
    4778 
    4879function recordings_get_id($fn) { 
     
    70101  // somee checking in here for it. 
    71102 
    72         $sql = "SELECT * FROM recordings where displayname <> '__invalid' ORDER BY displayname"; 
    73         $results = $db->getAll($sql); 
    74         if(DB::IsError($results)) { 
    75                 $results = null; 
    76         } 
    77         return $results; 
     103  $sql = "SELECT * FROM recordings where displayname <> '__invalid' ORDER BY displayname"; 
     104  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     105  if(DB::IsError($results)) { 
     106    return array(); 
     107  } 
     108  // Make array backward compatible, put first 4 columns as numeric 
     109  $count = 0; 
     110  foreach($results as $item) { 
     111    $results[$count][0] = $item['id']; 
     112    $results[$count][1] = $item['displayname']; 
     113    $results[$count][2] = $item['filename']; 
     114    $results[$count][3] = $item['description']; 
     115    $count++; 
     116  } 
     117  return $results; 
    78118} 
    79119 
     
    110150} 
    111151 
    112 function recordings_update($id, $rname, $descr, $_REQUEST) { 
     152function recordings_update($id, $rname, $descr, $_REQUEST, $fcode=0, $fcode_pass='') { 
    113153 
    114154  // Update the descriptive fields 
    115   $results = sql("UPDATE recordings SET displayname = \"$rname\", description = \"$descr\" WHERE id = \"$id\""); 
     155  $fcode_pass = preg_replace("/[^0-9*]/" ,"", trim($fcode_pass)); 
     156  $results = sql("UPDATE recordings SET displayname = '".addslashes($rname)."', description = '".addslashes($descr)."', fcode='$fcode', fcode_pass='".$fcode_pass."' WHERE id = '$id'"); 
    116157   
    117158  // Build the file list from _REQUEST 
     
    121162 
    122163  // Set the file names from the submitted page, sysrec[N] 
    123   foreach ($_REQUEST as $key => $val) { 
    124     $res = strpos($key, 'sysrec'); 
    125     if ($res !== false) { 
    126       // strip out any relative paths, since this is coming from a URL 
    127       str_replace('..','',$val); 
    128  
    129       $recordings[substr($key,6)]=$val; 
    130     } 
    131   } 
    132  
    133   // Stick the filename in the database 
    134   recordings_set_file($id, implode('&', $recordings)); 
     164  // We don't set if feature code was selected, we use what was already there 
     165  // because the fields will have been disabled and won't be accessible in the 
     166  // $_REQUEST array anyhow 
     167  // 
     168  if ($fcode != 1) { 
     169    // delete the feature code if it existed 
     170    // 
     171    $fcc = new featurecode('recordings', 'edit-recording-'.$id); 
     172    $fcc->delete(); 
     173    unset($fcc);   
     174    foreach ($_REQUEST as $key => $val) { 
     175      $res = strpos($key, 'sysrec'); 
     176      if ($res !== false) { 
     177        // strip out any relative paths, since this is coming from a URL 
     178        str_replace('..','',$val); 
     179 
     180        $recordings[substr($key,6)]=$val; 
     181      } 
     182    } 
     183 
     184    // Stick the filename in the database 
     185    recordings_set_file($id, implode('&', $recordings)); 
     186  } else { 
     187    // Add the feature code if it is needed 
     188    // 
     189    $fcc = new featurecode('recordings', 'edit-recording-'.$id); 
     190    $fcc->setDescription("Edit Recording: $rname"); 
     191    $fcc->setDefault('*29'.$id); 
     192    $fcc->update(); 
     193    unset($fcc);   
     194  } 
    135195 
    136196  // In _REQUEST there are also various actions (possibly)  
     
    193253function recordings_del($id) { 
    194254  $results = sql("DELETE FROM recordings WHERE id = \"$id\""); 
     255 
     256  // delete the feature code if it existed 
     257  $fcc = new featurecode('recordings', 'edit-recording-'.$id); 
     258  $fcc->delete(); 
     259  unset($fcc);   
    195260} 
    196261 
     
    198263  // Strip off any dangling &'s on the end: 
    199264  $filename = rtrim($filename, '&'); 
    200   $results = sql("UPDATE recordings SET filename = \"$filename\" WHERE id = \"$id\""); 
     265  $results = sql("UPDATE recordings SET filename = '".addslashes($filename)."' WHERE id = '$id'"); 
    201266} 
    202267 
  • modules/branches/2.5/recordings/install.php

    r5891 r5982  
    44global $asterisk_conf; 
    55global $db; 
     6 
     7if (! function_exists("out")) { 
     8  function out($text) { 
     9    echo $text."<br />"; 
     10  } 
     11} 
     12 
     13if (! function_exists("outn")) { 
     14  function outn($text) { 
     15    echo $text; 
     16  } 
     17} 
     18 
    619$recordings_astsnd_path = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 
    720$recordings_astsnd_path .= "/sounds/"; 
     
    7891  } 
    7992 } 
     93 
     94  // Version 2.5 upgrade 
     95  outn(_("checking for fcode field..")); 
     96  $sql = "SELECT `fcode` FROM recordings"; 
     97  $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
     98  if(DB::IsError($check)) { 
     99    // add new field 
     100    $sql = "ALTER TABLE recordings ADD `fcode` TINYINT( 1 ) DEFAULT 0 ;"; 
     101    $result = $db->query($sql); 
     102    if(DB::IsError($result)) { 
     103      die_freepbx($result->getDebugInfo()); 
     104    } 
     105    out(_("OK")); 
     106  } else { 
     107    out(_("already exists")); 
     108  } 
     109  outn(_("checking for fcode_pass field..")); 
     110  $sql = "SELECT `fcode_pass` FROM recordings"; 
     111  $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
     112  if(DB::IsError($check)) { 
     113    // add new field 
     114    $sql = "ALTER TABLE recordings ADD `fcode_pass` VARCHAR( 20 ) NULL ;"; 
     115    $result = $db->query($sql); 
     116    if(DB::IsError($result)) { 
     117      die_freepbx($result->getDebugInfo()); 
     118    } 
     119    out(_("OK")); 
     120  } else { 
     121    out(_("already exists")); 
     122  } 
    80123?> 
  • modules/branches/2.5/recordings/module.xml

    r5810 r5982  
    22  <rawname>recordings</rawname> 
    33  <name>Recordings</name> 
    4   <version>3.3.6.2</version> 
     4  <version>3.3.7</version> 
    55  <candisable>no</candisable> 
    66  <canuninstall>no</canuninstall> 
     
    99  <description>Creates and manages system recordings, used by many other modules (eg, IVR).</description> 
    1010  <changelog> 
     11    *3.3.7.0* Version 2.5 
    1112    *3.3.6.2* #2604, #2843 fix mal-formed html tags, Russian Translation 
    1213    *3.3.6.1* #2591, enhance code so bad directory copy errors are reported 
  • modules/branches/2.5/recordings/page.recordings.php

    r5972 r5982  
    2222$sysrec = isset($_REQUEST['sysrec'])?$_REQUEST['sysrec']:''; 
    2323$suffix = isset($_REQUEST['suffix']) && trim($_REQUEST['suffix'] != "") ? $_REQUEST['suffix'] : 'wav'; 
     24 
     25$fcode  = isset($_REQUEST['fcode']) && $_REQUEST['fcode'] != '' ? 1 : 0; 
     26$fcode_pass = isset($_REQUEST['fcode_pass'])?$_REQUEST['fcode_pass']:''; 
     27 
     28$fcbase = '*29'; 
     29$default_pos = 0; 
    2430 
    2531$astsnd = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 
     
    128134     
    129135  case "edited": 
    130     recordings_update($id, $rname, $notes, $_REQUEST); 
     136    recordings_update($id, $rname, $notes, $_REQUEST, $fcode, $fcode_pass); 
    131137    recording_sidebar($id, $usersnum); 
    132138    recording_editpage($id, $usersnum); 
     
    224230} 
    225231 
    226 function recording_editpage($id, $num) { ?> 
    227    
     232function recording_editpage($id, $num) {  
     233  global $fcbase; 
     234  global $default_pos; 
     235  global $fcode; 
     236  global $fcode_pass; 
     237?> 
    228238  <div class="content"> 
    229239  <h2><?php echo _("System Recordings")?></h2> 
     
    240250  $label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/sound_delete.png"/>&nbsp;'.$tlabel.'</span>'; 
    241251  echo "<a href=".$delURL.">".$label."</a>"; 
    242   echo "<i style='font-size: x-small'>("; 
     252  echo "<i style='font-size: x-small'>&nbsp;("; 
    243253  echo _("Note, does not delete file from computer"); 
    244254  echo ")</i>"; 
     
    259269        <td>&nbsp;<textarea name="notes" rows="3" cols="40" tabindex="<?php echo ++$tabindex;?>"><?php echo $this_recording['description'] ?></textarea></td> 
    260270  </tr> 
    261   </table> 
    262   <hr /> 
    263   <?php echo _("Files");?>:<br /> 
    264   <table> 
    265   <?php  
    266   $rec = recordings_get($id); 
     271 
     272<?php  
     273  // This was being called twice: $rec = recordings_get($id); 
     274  $rec = $this_recording; 
    267275  $fn = $rec['filename']; 
    268276  $files = explode('&', $fn); 
    269277  $counter = 0; 
    270278  $arraymax = count($files)-1; 
     279  $sndfile_html = ""; 
     280  foreach ($files as $item) { 
     281    $sndfile_html .=  recordings_display_sndfile($item, $counter, $arraymax, $recordings_astsnd_path, $rec['fcode']); 
     282    $counter++; 
     283  }  
     284  $sndfile_html .=  recordings_display_sndfile('', $counter, $arraymax, $recordings_astsnd_path, $rec['fcode']); 
     285  if ($arraymax == 0 && isset($files[0]) && substr($files[0],0,7) == 'custom/') { 
     286?> 
     287  <tr> 
     288    <td><a class="info" href="#"><?php echo _("Link to Feature Code")?><span><?php echo _("Check this box to create an options feature code that will allow this recording to be changed directly.")?></span></a>: 
     289    </td> 
     290    <td> 
     291  <input type='checkbox' tabindex="<?php echo ++$tabindex;?>"name='fcode' id="fcode" <?php if ($rec['fcode']=="1") { echo 'CHECKED'; }?> OnClick="resetDefaultSound();"; return true;'><?php echo sprintf(_("Optional Feature Code %s"),$fcbase.$id)?> 
     292    </td> 
     293  </tr> 
     294  <tr> 
     295    <td><a href="#" class="info"><?php echo _("Feature Code Password");?><span><?php echo _("Optional password to protect access to this feature code which allows a user to re-record it.");?></span></a></td> 
     296    <td><input type="text" name="fcode_pass" id="fcode_pass" value="<?php echo $rec['fcode_pass'] ?>" tabindex="<?php echo ++$tabindex;?>"></td> 
     297  </tr> 
     298<?php  
     299  } else { 
     300?> 
     301  <tr> 
     302    <td colspan="2"><a class="info" href="#"><?php echo _("Direct Access Feature Code Not Available")?><span><?php echo _("Direct Access Feature Codes for recordings are not available for built in system recordings or compound recordings made of multipe individual ones.")?></span></a>: 
     303    </td> 
     304  </tr> 
     305<?php  
     306  } 
     307?> 
     308 
     309  <tr><td colspan="2"><hr /></td></tr> 
     310  </table> 
     311  <?php echo _("Files");?>:<br /> 
     312  <table> 
     313  <?php  
    271314  // globals seem to busted in PHP5 define here for now 
    272315  $recordings_astsnd_path = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 
    273316  $recordings_astsnd_path .= "/sounds/"; 
    274317 
    275   foreach ($files as $item) { 
    276     recordings_display_sndfile($item, $counter, $arraymax, $recordings_astsnd_path); 
    277     $counter++; 
    278   }  
    279   recordings_display_sndfile('', $counter, $arraymax, $recordings_astsnd_path); 
     318  // recordings_display_sndfile functions need to be run above so we have $default_pos set 
     319  // 
     320  echo $sndfile_html; 
    280321  ?> 
    281322  </table> 
     
    283324  <?php recordings_popup_jscript(); ?>   
    284325  <?php recordings_form_jscript(); ?>  
     326  <script language="javascript"> 
     327  <!-- Begin 
     328  var sysrec0_idx; 
     329  function initPage() { 
     330    sysrec0_idx = document.getElementById("sysrec0").selectedIndex; 
     331    alert('Got here with sysrec0_idx as:'.sysrec0_idx); 
     332  } 
     333  function resetDefaultSound() { 
     334    if (document.getElementById('fcode').checked) { 
     335      document.getElementById('sysrec0').selectedIndex=<?php echo $default_pos ?>; 
     336      document.getElementById('sysrec1').selectedIndex=0; 
     337 
     338      document.getElementById('sysrec0').disabled=true; 
     339      document.getElementById('sysrec1').disabled=true; 
     340      document.getElementById('play0').style.visibility='hidden'; 
     341      document.getElementById('play1').style.visibility='hidden'; 
     342      document.getElementById('down0').style.visibility='hidden'; 
     343      document.getElementById('up1').style.visibility='hidden'; 
     344      document.getElementById('del0').style.visibility='hidden'; 
     345      document.getElementById('del1').style.visibility='hidden'; 
     346    } else { 
     347      document.getElementById('sysrec0').disabled=false; 
     348      document.getElementById('sysrec1').disabled=false; 
     349      document.getElementById('play0').style.visibility='visible'; 
     350      document.getElementById('play1').style.visibility='visible'; 
     351      document.getElementById('down0').style.visibility='visible'; 
     352      document.getElementById('up1').style.visibility='visible'; 
     353      document.getElementById('del0').style.visibility='visible'; 
     354      document.getElementById('del1').style.visibility='visible'; 
     355    } 
     356  } 
     357  // End --> 
     358  </script> 
    285359  </form> 
    286360  </div> 
     
    386460} 
    387461 
    388 function recordings_display_sndfile($item, $count, $max, $astpath) { 
     462function recordings_display_sndfile($item, $count, $max, $astpath, $fcode) { 
     463  global $default_pos; 
    389464  global $amp_conf; 
     465 
     466  $disabled_state = $fcode == 0 ? "" : "disabled='true' "; 
     467  $hidden_state = $fcode == 0 ? "" : "style='visibility:hidden' "; 
     468 
     469  $html_text = ""; 
    390470  // Note that when using this, it needs a <table> definition around it. 
    391471  $astsnd = isset($asterisk_conf['astvarlibdir'])?$asterisk_conf['astvarlibdir']:'/var/lib/asterisk'; 
    392472  $astsnd .= "/sounds/"; 
    393473  $sysrecs = recordings_readdir($astsnd, strlen($astsnd)+1); 
    394   print "<tr><td><select id='sysrec$count' name='sysrec$count'>\n"; 
    395   echo '<option value=""'.($item == '' ? ' SELECTED' : '')."></option>\n"; 
     474  $html_txt .=  "<tr><td><select $disabled_state id='sysrec$count' name='sysrec$count'>\n"; 
     475  $html_txt .=  '<option value=""'.($item == '' ? ' SELECTED' : '')."></option>\n"; 
     476  $index=0; 
    396477  foreach ($sysrecs as $sr) { 
    397     echo '<option value="'.$sr.'"'.($sr == $item ? ' SELECTED' : '').">$sr</option>\n"; 
    398   } 
    399   print "</select></td>\n"; 
    400  
    401   echo "<td>"; 
     478    $html_txt .=  '<option value="'.$sr.'"'.($sr == $item ? ' SELECTED' : '').">$sr</option>\n"; 
     479    if ($sr == $item) { 
     480      $default_pos = $index+1; 
     481    } 
     482    $index++; 
     483  } 
     484  $html_txt .=  "</select></td>\n"; 
     485 
     486  $html_txt .=  "<td>"; 
    402487  $audio=$astpath; 
    403488 
     
    405490  $recurl="modules/recordings/popup.php?cryptpass=$REC_CRYPT_PASSWORD&recording=$audio"; 
    406491 
    407   echo "<a href='#' type='submit' onClick=\"javascript:popUp('$recurl',document.prompt.sysrec$count); return false;\" input='foo'  >"; 
    408         echo "<img border='0' width='20'  height='20' src='images/play.png' title='Click here to play this recording' />"; 
    409         echo "</img></td>"; 
     492  $html_txt .=  "<a href='#' $hidden_state type='submit' id='play$count' onClick=\"javascript:popUp('$recurl',document.prompt.sysrec$count); return false;\" input='foo'>"; 
     493 $html_txt .= "<img border='0' width='20'  height='20' src='images/play.png' title='Click here to play this recording' />"; 
     494 $html_txt .= "</img></td>"; 
    410495 
    411496  if ($count==0) { 
    412      print "<td></td>\n";  
     497     $html_txt .= "<td></td>\n";  
    413498  } else { 
    414     echo "<img border='0' width='3' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
    415     echo '<td><input name="up'.$count.'" width=10 height=20 border=5  title="Move Up" type="image" src="images/scrollup.gif"  value="'._("Move Up").'"/>'
    416     print "</td>\n";  
     499    $html_txt .= "<img border='0' width='3' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
     500    $html_txt .=  "<td><input $hidden_state name='up$count' id='up$count' width=10 height=20 border=5  title='Move Up' type='image' src='images/scrollup.gif'  value='"._("Move Up")."'>"
     501    $html_txt .= "</td>\n";  
    417502  } if ($count > $max) { 
    418     print "<td></td>\n";  
     503    $html_txt .= "<td></td>\n";  
    419504  } else { 
    420     echo "<img border='0' width='3' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
    421     echo '<td><input name="down'.$count.'" width=10 height=20 border=0 title="Move Down" type="image" src="images/scrolldown.gif"  value="'._("Move Down")."\">\n"; 
    422     echo "<img border='0' width='3' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
    423     print "</td>\n";  
    424   } 
    425   echo '<td><input name="del'.$count.'" type="image" border=0 title="Delete" src="images/trash.png" value="'._("Delete")."\">\n"; 
    426   echo "<img border='0' width='9' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
    427   echo "<img border='0' width='9' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
    428   print "</td>\n";  
    429  
    430   print "</tr>\n"; 
    431 
    432  
    433 ?> 
     505    $html_txt .=  "<img border='0' width='3' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
     506    $html_txt .=  "<td><input $hidden_state name='down$count' id='down$count' width=10 height=20 border=0 title='Move Down' type='image' src='images/scrolldown.gif'  value='"._("Move Down")."'>\n"; 
     507    $html_txt .=  "<img border='0' width='3' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
     508    $html_txt .=  "</td>\n";  
     509  } 
     510  $html_txt .=  "<td><input $hidden_state name='del$count' id='del$count' type='image' border=0 title='Delete' src='images/trash.png' value='"._("Delete")."'>\n"; 
     511  $html_txt .=  "<img border='0' width='9' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
     512  $html_txt .=  "<img border='0' width='9' height='11' style='float: none; margin-left: 0px; margin-bottom: 0px;' src='images/blank.gif' />"; 
     513  $html_txt .=  "</td>\n";  
     514 
     515  $html_txt .=  "</tr>\n"; 
     516  return $html_txt; 
     517
     518 
     519?>