Modifiyng Calendar Script to Link to Existing Files

Background: Looking to put local marine radio cruisers net online. Net being received via SDR piped to sox for encoding as mp3 file. File uploaded to server in dedicated directory (/data), naming convention (YY)(MM)(DD).mp3 At this time the project is in test mode, and files are not always recorded or uploaded daily

Goal: Server side (PHP) calendar script which will parse the /data directory for an array and recolor the calendar cells background for dates matching the files naming convention. Clicking on a highlighted cell will open the associated file.

Status: Have very simple (but adequate?) calendar script with no exterior libraries or css (code follows). Php experience limited and rusty. Unsure how and where to integrate scandir() function and other required bits to achieve goal. Assistance appreciated.

[code]

Boot Key Calendar Test <?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; } ?>



Previous Next
<?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 ""; if($i < $startday) echo ""; else echo ""; if(($i % 7) == 6 ) echo ""; } ?>
<?php echo $monthNames[$cMonth-1].' '.$cYear; ?>
S M T W T F S
". ($i - $startday + 1) . "



<?php $dir = "/data/"; // Sort in descending order $b = scandir($dir,1); print_r($b); ?> [/code]

As a “noob” unable to post link to working example on server… Sorry
TIA

David
Onboard S/V Solitaire
Boot Key Harbor

Edit to above…

Please ignore code below line 75. Had tagged the function on the end of the page to test scandir() function. Since removed.

Sorry

If you want to alter the calendar, the directory scanning will need to be before that is parsed.

What I think* you are wanting:

Exactly!! Associated filenames in array scanned from /data would be:
20160913.mp3
20160922.mp3
20160925.mp3
20160927.mp3

[php]<?php
$dir = “data/”;
$audio_file = scandir($dir);
print_r($audio_file);
?>[/php]

Returns: (actural current content)
[php]Array ( [0] => . [1] => … [2] => 20160518.mp3 [3] => 20160521.mp3 [4] => 20160522.mp3 [5] => 20160523.mp3 [6] => 20160526.mp3 [7] => 20160527.mp3 )[/php]

You don’t actually need to scan the directory at all. Take the following,

[php]$month = str_pad($cMonth, 2, 0, STR_PAD_LEFT);
$day = str_pad(($i - $startday + 1), 2, 0, STR_PAD_LEFT);
$date = $cYear . $month . $day;
$class = is_file( “data/$date.mp3”) ? ‘active’ : ‘inactive’;
echo “

” . ($i - $startday + 1) . “”;
[/php]

And the css:
[php]

.active {
background-color: #00ff99;
}
.inactive {
background-color: #fff;
}

[/php]

astonecipher… That is slicker than cat guts on a doorknob. Spent all day messing with suggestions from another forum with no joy. Your code worked in 5 minutes. Tks so much. Now how to make those nicely highlighted cells clickable. I will be investigating that this evening and tommorow, but if you can post a solution as elegant as this one I would be eternally grateful. Would let me go back to the hardware end where I am much more comfortable.

Working example available at

http://bootkeycruisers.net/calendar.php

Code below shows germaine portion of code in initial post modified per astoncipher suggestions for anyone following along.

[code]

Boot Key Calendar Test .active { background-color: #00ff99; } .inactive { background-color: #fff; } [/code]

[php]<?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 “

”;
if($i < $startday) echo “”;

$month = str_pad($cMonth, 2, 0, STR_PAD_LEFT);
$day = str_pad(($i - $startday + 1), 2, 0, STR_PAD_LEFT);
$date = $cYear . $month . $day;
$class = is_file( “data/$date.mp3”) ? ‘active’ : ‘inactive’;
echo “

” . ($i - $startday + 1) . “”;
}
?>[/php]

Really appreciate the assistance. The Cruisers Net in Boot Key Harbor is listened to every morning by most boats here in the harbor. Our local “newspaper” as it were. During the winter snow-bird season we have upwards of 300 boats on the moorings and in the anchorages and many of the departing vessels would like to keep track of “As The Harbor Churns” while they are back in their home ports as well as those of us who might miss the net in the morning while at work or elsewhere. Hence this project to put us online. Hope to be able to more or less automate the system (rpi3 + sdr receiver) so we won’t miss a broadcast and eventually all the dates will be filled in green. Not expected to ever be real-time but an hour delay is the goal. Some of the nets in season run over an hour and the upload time on our available bandwidth precludes a real-time option. Anyway, be assured that when we have our “Grand Opening” yourself and phphelp.com will get credit for your invaluable assistance.

David ONeill
Onboard S/V Solitaire
Boot Key Harbor
Marathon Fl

I was a Floridian for 20+ years, so what the hell!

You want a numeric day or the entire area clickable?

How do you want the page loaded? I would think if they are playing something, you would want another page opened that shows the mp3?

Two parts,

The player just above the closing body tag:
[php]<?php
if( isset( $_GET[‘d’] ) ){
if ( is_file( “data/{$_GET[‘d’]}.txt”)){
?>


Your browser does not support the audio element.

<?php } } ?> [/php]

Modified attachment code:

[php]if ($i < $startday)
echo “

”;
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 = “” . ($i - $startday + 1) . “”;
}
echo “$display”;
}[/php]

WOW… Not bad for an ex “Floridiot”. Hope for the rest of us. Now that all is working, and I have a basic understanding of what is going on, I can pretty it all up for the main page. Had to make one change to get the player to show up
[php]if ( is_file( “data/{$_GET[‘d’]}.txt”)){[/php]
to
[php]if ( is_file( “data/{$_GET[‘d’]}.mp3”)){[/php]

Seems to be working great
Tks again for the straight dope

eh, I don’t have mp3’s to test with, but txt files are easy.

Sponsor our Newsletter | Privacy Policy | Terms of Service