Changeset 6555

Show
Ignore:
Timestamp:
09/04/08 00:00:26 (3 months ago)
Author:
p_lindheimer
Message:

closes #3156 adds an option to add a streaming category in addition to the normal categories. The streaming source is located in a .cusotm file in a directory where the sound files would normally go. When choosing a streaming source, it allows for the application= line data to be set vs. uploading files

Files:

Legend:

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

    r4914 r6555  
    22 
    33function music_list($path) { 
    4         global $amp_conf; 
    54        $i = 1; 
    65        $arraycount = 0; 
     
    3332function music_rmdirr($dirname) 
    3433{ 
    35     // Sanity check 
    36     if (!file_exists($dirname)) { 
    37         print "$dirname Doesn't exist\n"; 
    38         return false; 
    39    
     34       // Sanity check 
     35       if (!file_exists($dirname)) { 
     36               print "$dirname Doesn't exist\n"; 
     37               return false; 
     38       
    4039  
    41     // Simple delete for a file 
    42     if (is_file($dirname)) { 
    43         return unlink($dirname); 
    44    
     40       // Simple delete for a file 
     41       if (is_file($dirname)) { 
     42               return unlink($dirname); 
     43       
    4544  
    46     // Loop through the folder 
    47     $dir = dir($dirname); 
    48     while (false !== $entry = $dir->read()) { 
    49         // Skip pointers 
    50         if ($entry == '.' || $entry == '..') { 
    51             continue; 
    52        
     45       // Loop through the folder 
     46       $dir = dir($dirname); 
     47       while (false !== $entry = $dir->read()) { 
     48               // Skip pointers 
     49               if ($entry == '.' || $entry == '..') { 
     50                       continue; 
     51               
    5352  
    54         // Recurse 
    55         music_rmdirr("$dirname/$entry"); 
    56    
     53               // Recurse 
     54               music_rmdirr("$dirname/$entry"); 
     55       
    5756  
    58     // Clean up 
    59     $dir->close(); 
    60     return rmdir($dirname); 
     57       // Clean up 
     58       $dir->close(); 
     59       return rmdir($dirname); 
    6160} 
    6261 
  • modules/branches/2.5/music/page.music.php

    r6303 r6555  
    2121$display='music'; 
    2222 
    23 global $asterisk_conf; 
     23global $amp_conf; 
    2424 
    2525if ($category == "default") { 
    26         $path_to_dir = $asterisk_conf['astvarlibdir']."/mohmp3"; //path to directory u want to read. 
     26        $path_to_dir = $amp_conf['ASTVARLIBDIR']."/mohmp3"; //path to directory u want to read. 
    2727} else { 
    28         $path_to_dir = $asterisk_conf['astvarlibdir']."/mohmp3/$category"; //path to directory u want to read. 
     28        $path_to_dir = $amp_conf['ASTVARLIBDIR']."/mohmp3/$category"; //path to directory u want to read. 
    2929} 
    3030 
     
    3333        touch($path_to_dir."/.random"); 
    3434        createmusicconf(); 
     35        needreload(); 
    3536} 
    3637if (strlen($randoff)) { 
    3738        unlink($path_to_dir."/.random"); 
    3839        createmusicconf(); 
     40        needreload(); 
    3941} 
    4042switch ($action) { 
     43        case "addednewstream": 
     44        case "editednewstream": 
     45                $stream = isset($_REQUEST['stream'])?$_REQUEST['stream']:''; 
     46                makestreamcatergory($path_to_dir,$stream); 
     47                createmusicconf(); 
     48                needreload(); 
     49                redirect_standard(); 
    4150        case "addednew": 
    42                 makemusiccategory($path_to_dir,$category);  
     51                makemusiccategory($path_to_dir);  
    4352                createmusicconf(); 
    4453                needreload(); 
     
    5160        break; 
    5261        case "delete": 
     62                //$fh = fopen("/tmp/music.log","a"); 
     63                //fwrite($fh,print_r($_REQUEST,true)); 
    5364                music_rmdirr("$path_to_dir");  
    54                 $path_to_dir = $asterisk_conf['astvarlibdir']."/mohmp3"; //path to directory u want to read. 
     65                $path_to_dir = $amp_conf['ASTVARLIBDIR']."/mohmp3"; //path to directory u want to read. 
    5566                $category='default'; 
    5667                createmusicconf(); 
     
    6576<div class="rnav"><ul> 
    6677    <li><a href="config.php?display=<?php echo urlencode($display)?>&action=add"><?php echo _("Add Music Category")?></a></li> 
     78    <li><a href="config.php?display=<?php echo urlencode($display)?>&action=addstream"><?php echo _("Add Streaming Category")?></a></li> 
    6779 
    6880<?php 
    6981//get existing trunk info 
    70 $tresults = music_list($asterisk_conf['astvarlibdir']."/mohmp3"); 
     82$tresults = music_list($amp_conf['ASTVARLIBDIR']."/mohmp3"); 
    7183if (isset($tresults)) { 
    7284        foreach ($tresults as $tresult) { 
     
    8294<?php 
    8395function createmusicconf() { 
    84         global $asterisk_conf; 
    8596        global $amp_conf; 
    8697 
    8798        $File_Write=""; 
    88         $tresults = music_list($asterisk_conf['astvarlibdir']."/mohmp3"); 
     99        $tresults = music_list($amp_conf['ASTVARLIBDIR']."/mohmp3"); 
    89100        if (isset($tresults)) { 
    90101                foreach ($tresults as $tresult)  { 
     
    98109                        } 
    99110                        if ($tresult != "default" ) { 
    100                                 $dir = $asterisk_conf['astvarlibdir']."/mohmp3/{$tresult}/"; 
     111                                $dir = $amp_conf['ASTVARLIBDIR']."/mohmp3/{$tresult}/"; 
    101112                        } else { 
    102                                 $dir = $asterisk_conf['astvarlibdir']."/mohmp3/"; 
    103                         } 
    104                         if (file_exists("{$dir}.random")) { 
     113                                $dir = $amp_conf['ASTVARLIBDIR']."/mohmp3/"; 
     114                        } 
     115                        if (file_exists("{$dir}.custom")) { 
     116                                $application = file_get_contents("{$dir}.custom"); 
     117                                $File_Write.="[{$tresult}]\nmode=custom\napplication=$application\n"; 
     118                        } else if (file_exists("{$dir}.random")) { 
    105119                                $File_Write.="[{$tresult}]\nmode=files\ndirectory={$dir}\nrandom=yes\n"; 
    106120                        } else { 
     
    119133 
    120134        fclose($handle); 
    121  
    122         needreload(); 
    123 
    124  
    125 function makemusiccategory($category) { 
    126         mkdir("$path_to_dir/$category", 0755);  
     135
     136 
     137function makestreamcatergory($path_to_dir,$stream) { 
     138        if (!is_dir($path_to_dir)) { 
     139                makemusiccategory($path_to_dir); 
     140        } 
     141        $fh=fopen("$path_to_dir/.custom","w"); 
     142        fwrite($fh,$stream); 
     143        fclose($fh); 
     144
     145 
     146function makemusiccategory($path_to_dir) { 
     147        mkdir("$path_to_dir", 0755);  
    127148} 
    128149  
     
    289310 
    290311<?php 
     312        } else if ($action == 'addstream') { 
     313        ?> 
     314        <form name="addstream" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return addstream_onsubmit();"> 
     315        <input type="hidden" name="display" value="<?php echo $display?>"> 
     316        <input type="hidden" name="action" value="addednewstream"> 
     317        <table> 
     318        <tr><td colspan="2"><h5><?php echo _("Add Streaming Category")?><hr></h5></td></tr> 
     319        <tr> 
     320                <td><a href="#" class="info"><?php echo _("Category Name:")?><span><?php echo _("Allows you to Set up Different Categories for music on hold.  This is useful if you would like to specify different Hold Music or Commercials for various ACD Queues.")?> </span></a></td> 
     321                <td><input type="text" name="category" value=""></td> 
     322        </tr> 
     323        <tr> 
     324                <td><a href="#" class="info"><?php echo _("Application:")?><span><?php echo _("This is the \"application=\" line used to provide the streaming details to Asterisk. See information on musiconhold.conf configuration for different audio and internet streaming source options.")?> </span></a></td> 
     325                <td><input type="text" name="stream" size="80" value=""></td> 
     326        </tr> 
     327        <tr> 
     328                <td colspan="2"><br><h6><input name="Submit" type="submit" value='<?php echo _("Submit Changes")?>' ></h6></td>          
     329        </tr> 
     330        </table> 
     331<script language="javascript"> 
     332<!-- 
     333 
     334var theForm = document.addstream; 
     335theForm.category.focus(); 
     336 
     337function addstream_onsubmit() { 
     338        var msgInvalidCategoryName = "<?php echo _('Please enter a valid Category Name'); ?>"; 
     339        var msgInvalidStreamName = "<?php echo _('Please enter a streaming application command and arguments'); ?>"; 
     340        var msgReservedCategoryName = "<?php echo _('Categories: \"none\" and \"default\" are reserved names. Please enter a different name'); ?>"; 
     341 
     342        defaultEmptyOK = false; 
     343        if (!isAlphanumeric(theForm.category.value)) 
     344                return warnInvalid(theForm.category, msgInvalidCategoryName); 
     345        if (theForm.category.value == "default" || theForm.category.value == "none") 
     346                return warnInvalid(theForm.category, msgReservedCategoryName); 
     347        if (isEmpty(theForm.stream.value)) 
     348                return warnInvalid(theForm.stream, msgInvalidStreamName); 
     349         
     350        return true; 
     351} 
     352 
     353//--> 
     354</script> 
     355 
     356        </form> 
     357        <br><br><br><br><br> 
     358 
     359<?php 
    291360} else { 
    292361?> 
     
    294363        <h5><?php echo _("Category:")?> <?php echo $category=="default"?_("default"):$category;?></h5> 
    295364<?php   
     365        if (file_exists("{$path_to_dir}/.custom")) { 
     366                $application = file_get_contents("{$path_to_dir}/.custom"); 
     367        } else { 
     368                $application = false; 
     369        } 
    296370        if ($category!="default") { 
    297                 $delURL = $_SERVER['PHP_SELF'].'?dsplay='.urlencode($display).'&action=delete&category='.urlencode($category); 
    298                 $tlabel = sprintf(_("Delete Music Category %s"),$category); 
     371                $delURL = $_SERVER['PHP_SELF'].'?display='.urlencode($display).'&action=delete&category='.urlencode($category); 
     372                $tlabel = sprintf(($application === false)?_("Delete Music Category %s"):_("Delete Streaming Category"),$category); 
    299373                $label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/core_delete.png"/>&nbsp;'.$tlabel.'</span>'; 
    300374?> 
     
    302376<?php   
    303377        } 
     378        if ($application !== false) { 
     379        ?> 
     380                <form name="editstream" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return editstream_onsubmit();"> 
     381                <input type="hidden" name="display" value="<?php echo $display?>"> 
     382                <input type="hidden" name="action" value="editednewstream"> 
     383                <table> 
     384                <tr><td colspan="2"><h5><?php echo _("Edit Streaming Category").": $category"?><hr></h5></td></tr> 
     385                <tr> 
     386                        <td><a href="#" class="info"><?php echo _("Application:")?><span><?php echo _("This is the \"application=\" line used to provide the streaming details to Asterisk. See information on musiconhold.conf configuration for different audio and internet streaming source options.")?> </span></a></td> 
     387                        <td><input type="text" name="stream" size="80" value="<?php echo $application?>"></td> 
     388                </tr> 
     389                <tr> 
     390                        <td colspan="2"><br><h6><input name="Submit" type="submit" value='<?php echo _("Submit Changes")?>' ></h6></td>          
     391                </tr> 
     392                </table> 
     393<script language="javascript"> 
     394<!-- 
     395 
     396var theForm = document.editstream; 
     397theForm.stream.focus(); 
     398 
     399function editstream_onsubmit() { 
     400        var msgInvalidStreamName = "<?php echo _('Please enter a streaming application command and arguments'); ?>"; 
     401 
     402        defaultEmptyOK = false; 
     403        if (isEmpty(theForm.stream.value)) 
     404                return warnInvalid(theForm.stream, msgInvalidStreamName); 
     405         
     406        return true; 
     407} 
     408//--> 
     409</script> 
     410 
     411                </form> 
     412                <br><br><br><br><br> 
     413 
     414<?php 
     415        } else { // normal moh dir 
    304416?> 
    305417 
     
    376488        $file_array = build_list(); 
    377489        $numf = count($file_array); 
     490        } // normal moh dir 
    378491 
    379492 
     
    396509                } 
    397510        } 
    398         $file_array = build_list(); 
    399         draw_list($file_array, $path_to_dir, $category); 
     511        if ($application === false) { 
     512                $file_array = build_list(); 
     513                draw_list($file_array, $path_to_dir, $category); 
     514        } 
    400515        ?> 
    401516        <br><br><br><br><br><br> 
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads