2016-05-27 10 views
0

背景:地元の海洋ラジオクルーザーをオンラインで見ることを検討しています。 SDR経由で受信されるネットは、mp3ファイルとしてエンコードするためにSOXにパイプされます。ファイルは専用のディレクトリ(/ data)、命名規則(YY)(MM)(DD)の.mp3でサーバーにアップロードされます。この時点でプロジェクトはテストモードにあり、ファイルは毎日記録されたりアップロードされたりするとは限りませんScandir()からPHPカレンダスクリプトに配列を挿入する

目標:配列の/ dataディレクトリを解析し、ファイル命名規則に一致する日付のカレンダーセルの背景を再描画するサーバー側(PHP)カレンダスクリプト。強調表示されたセルをクリックすると、関連付けられたファイルが開きます。

ステータス:非常にシンプルな(しかし、適切な)カレンダースクリプトを外部ライブラリもなく、CSS(コードに従う)してください。 PHPの経験は限られており、錆びています。 scandir()関数と目的を達成するための他の必要なビットをどのように、どこに統合するかはわかりません。援助が高く評価されました

<html> 
<head> 
    <title>Boot Key Calendar Test</title> 
</head> 
<body> 

<?php 
    $monthNames = Array(
     "January", 
     "February", 
     "March", 
     "April", 
     "May", 
     "June", 
     "July", 
     "August", 
     "September", 
     "October", 
     "November", 
     "December" 
    ); 

    if (!isset($_REQUEST["month"])) 
     $_REQUEST["month"] = date("n"); 
    if (!isset($_REQUEST["year"])) 
     $_REQUEST["year"] = date("Y"); 

    $cMonth = $_REQUEST["month"]; 
    $cYear = $_REQUEST["year"]; 

    $prev_year = $cYear; 
    $next_year = $cYear; 
    $prev_month = $cMonth - 1; 
    $next_month = $cMonth + 1; 

    if ($prev_month == 0) 
     { 
     $prev_month = 12; 
     $prev_year = $cYear - 1; 
     } 
    if ($next_month == 13) 
     { 
     $next_month = 1; 
     $next_year = $cYear + 1; 
     } 
?> 
<br><br> 
<table width="400" border="2" align="center"> 
<tr align="center"> 
<td bgcolor="#999999" style="color:#FFFFFF"> 
<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td width="50%" align="left"> <a href="<?php 
    echo $_SERVER["PHP_SELF"] . "?month=" . $prev_month . "&year=" .  $prev_year; 
?>" style="color:#FFFFFF">Previous</a></td> 
<td width="50%" align="right"><a href="<?php 
     echo $_SERVER["PHP_SELF"] . "?month=" . $next_month . "&year=" .  $next_year; 
?>" style="color:#FFFFFF">Next</a> </td> 
</tr> 
</table> 
</td> 
</tr> 
<tr> 
<td align="center"> 
<table width="100%" border="0" cellpadding="2" cellspacing="2"> 
<tr align="center"> 
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php 
    echo $monthNames[$cMonth - 1] . ' ' . $cYear; 
?></strong></td> 
</tr> 
<tr> 
<td align="center" bgcolor="#999999" style="color:#FFFFFF"> <strong>S</strong></td> 
<td align="center" bgcolor="#999999" style="color:#FFFFFF"> <strong>M</strong></td> 
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> 
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> 
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> 
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong> </td> 
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong> </td> 
</tr> 

<?php 
    $timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear); 
    $maxday = date("t", $timestamp); 
    $thismonth = getdate($timestamp); 
    $startday = $thismonth['wday']; 
    for ($i = 0; $i < ($maxday + $startday); $i++) 
     { 
     if (($i % 7) == 0) 
      echo "<tr>"; 
     if ($i < $startday) 
      echo "<td></td>"; 
     else 
      echo "<td align='center' valign='middle' height='40px'>" .  ($i - $startday + 1) . "</td>"; 
     if (($i % 7) == 6) 
      echo "</tr>"; 
     } 
?> 

</table> 
</td> 
</tr> 
</table> 

<br><br> 


</body> 
</html> 

の作業例はhttp://bootkeycruisers.net/calendar.php

答えて

0

でこれは動作します:

<?php 
    $monthNames = Array(
     "January", 
     "February", 
     "March", 
     "April", 
     "May", 
     "June", 
     "July", 
     "August", 
     "September", 
     "October", 
     "November", 
     "December" 
    ); 
    if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); 
    if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); 
    $cMonth = $_REQUEST["month"]; 
    $cYear = $_REQUEST["year"]; 
    $prev_year = $cYear; 
    $next_year = $cYear; 
    $prev_month = $cMonth - 1; 
    $next_month = $cMonth + 1; 
    if ($prev_month == 0) 
     { 
     $prev_month = 12; 
     $prev_year = $cYear - 1; 
     } 
    if ($next_month == 13) 
     { 
     $next_month = 1; 
     $next_year = $cYear + 1; 
     } 
    ?> 
    <br /><br /> 
    <table width="400" border="2" align="center"> 
    <tr align="center"> 
    <td bgcolor="#999999" style="color:#FFFFFF"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td width="50%" align="left"> <a href="<?php 
    echo $_SERVER["PHP_SELF"] . "?month=" . $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> 
    <td width="50%" align="right"><a href="<?php 
    echo $_SERVER["PHP_SELF"] . "?month=" . $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a> </td> 
    </tr> 
    </table> 
    </td> 
    </tr> 
    <tr> 
    <td align="center"> 
    <table width="100%" border="0" cellpadding="2" cellspacing="2"> 
    <tr align="center"> 
    <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php 
    echo $monthNames[$cMonth - 1] . ' ' . $cYear; ?></strong></td> 
    </tr> 
    <tr> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td> 
    <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> 
    </tr> 
    <?php 
    $timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear); 
    $maxday = date("t", $timestamp); 
    $thismonth = getdate($timestamp); 
    $startday = $thismonth['wday']; 
    for ($i = 0; $i < ($maxday + $startday); $i++) 
     { 
     if (($i % 7) == 0) echo "<tr>"; 
     if ($i < $startday) echo "<td></td>"; 
     else 
      { 
     $class = 'inactive'; 
     $display = ($i - $startday + 1); 
     $month = str_pad($cMonth, 2, 0, STR_PAD_LEFT); 
     $day = str_pad(($i - $startday + 1) , 2, 0, STR_PAD_LEFT); 
     $date = $cYear . $month . $day; 
     if (is_file("data/$date.mp3")) 
      { 
      $class = 'active'; 
      $display = "<a href='?d=$date'>" . ($i - $startday + 1) . "</a>"; 
      } 
     echo "<td align='center' valign='middle' height='40px' class='$class'>$display</td>"; 
      } 
     } 
    ?> 
    </table> 
    </td> 
    </tr> 
    </table> 
    <br><br> 
    <?php 
    if (isset($_GET['d'])) 
     { 
     if (is_file("data/{$_GET['d']}.mp3")) 
      { 
    ?> 
    <center> 
    <audio controls autoplay> 
    <source src="data/<?php 
     echo htmlentities($_GET['d']); ?>.mp3" type="audio/mpeg"> 
     Your browser does not support the audio element. 
    </audio> 
    </center 
    <?php 
      } 
     } 

    ?> 
関連する問題