2016-05-27 9 views
0

Hintergrund: Suche nach lokalen Marine Radio Cruisernetz online. Netz empfangen über SDR piped zu sox für die Kodierung als mp3-Datei. Datei auf Server im dedizierten Verzeichnis (/ data) hochgeladen, Namenskonvention (YY) (MM) (DD) .mp3 Zu diesem Zeitpunkt befindet sich das Projekt im Testmodus und Dateien werden nicht immer aufgezeichnet oder hochgeladen.Array von Scandir() in PHP einfügen Kalenderskript

Ziel: Serverseitiges (PHP) Kalenderskript, das das Verzeichnis/data für ein Array analysiert und den Hintergrund der Kalenderzellen für Datumsangaben neu einfärbt, die mit der Dateinamenskonvention übereinstimmen. Wenn Sie auf eine markierte Zelle klicken, wird die zugehörige Datei geöffnet.

Status: Haben Sie sehr einfach (aber ausreichend?) Kalender-Skript ohne externe Bibliotheken oder CSS (Code folgt). Php Erfahrung begrenzt und rostig. Unsicher, wie und wo scandir() - Funktion und andere benötigte Bits integriert werden sollen, um das Ziel zu erreichen. Hilfe geschätzt.

<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> 

Arbeitsbeispiel bei http://bootkeycruisers.net/calendar.php

Antwort

0

Dies funktioniert:

<?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 
      } 
     } 

    ?>