0
votes

I am not as proficient with PHP as I like to think I am and am struggling with something that I hoped is quite simple.

Basically, for a radio station website the script reads from a Google Doc (spreadsheet), and displays the show on air at the time the user is on the site, and what is on next.

I am trying to additionally include the next show in the list (so have the show on air, the next one and the one after that).

However I am completely stuck and keep causing parse errors.

Would be really grateful for any help!

Thanks

Martyn

<?php 
// Now On Air and who's on next ...

// Default city Time
$default="Europe/London";
date_default_timezone_set($default);

$days=array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");

// What time is it right now
$now=time();
$year=date("Y");
$month=date("m");
$day=date("d");
$dow=strtoupper(date("D"));

// https://docs.google.com/spreadsheet/xxxx
$schedule ="http://spreadsheets.google.com/feeds/cells/xxxx";

// Get the Google Docs Spreadsheet
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL,"$schedule"); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); 
$pres = curl_exec($curl); 
curl_close($curl); 
$xml_pres = simplexml_load_string($pres); 

// Build an array of the schedule
$build=array();
foreach ($xml_pres->entry as $item) {
$col=ord(substr($item->title,0,1))-65;
$row=substr($item->title,1);
$build[$row][$col]=$item->content;
}
$rend=$row;

// how many lines in the array ...
$count=count($build);

// 0=day
// 1=start time
// 2=end time
// 3=show name
// 4=description
// 5=presenter
// 6=photo
// 7=link
// 


// Example: $build[$i][4] is the description of line number $i

// Find out who is on the air right now
$flag=0;
for($i=2;$i<=$rend;$i++){

// day of week conversion
if(strtoupper($build[$i][0])=="SUNDAY"){
$dw="SUN";
}
if(strtoupper($build[$i][0])=="MONDAY"){
$dw="MON";
}
if(strtoupper($build[$i][0])=="TUESDAY"){
$dw="TUE";
}
if(strtoupper($build[$i][0])=="WEDNESDAY"){
$dw="WED";
}
if(strtoupper($build[$i][0])=="THURSDAY"){
$dw="THU";
}
if(strtoupper($build[$i][0])=="FRIDAY"){
$dw="FRI";
}
if(strtoupper($build[$i][0])=="SATURDAY"){
$dw="SAT";
}

   if($dow==$dw && $flag==0){
        $start_time=strtotime($year."-".$month."-".$day." ".$build[$i][1]);
           if($build[$i][1]=="00:00:00"){
           $startt="00:00am";
           }
           else{
           $startt=date("g:00a", $start_time+($timeadjust*60*60));
           }
        $stop=$build[$i][2];
        if($stop=="0:00:00" || $stop=="00:00:00"){
        $stop="23:59:00";
        }
        $stop_time=strtotime($year."-".$month."-".$day." ".$stop);
              if($stop=="23:59:00"){
              $stopt="Midnight";
              }
              else{
              $stopt=date("g:00a", $stop_time+($timeadjust*60*60));
              }
            if($now >= $start_time && $now < $stop_time){
            $photo="/nophoto.jpg";
            if($build[$i][6]){
            $photo=$build[$i][6];
         
		 }
		
         
            echo"
           <img src='$photo' alt='{$build[$i][5]}' title='{$build[$i][5]}' style='float:left'><br><span id='onairtext'>On Air Now:</span><br><span id='djname'><a href='{$build[$i][7]}'>{$build[$i][3]}</a></span><br><span id='showtime'>$startt - $stopt</span><br><img src='/djspacer.jpg' border='0'><br>
            ";
            $next=$i+1;
               if($next > $rend){
                $next=2;
                }
                
$np=0;
for($q=$next; $q<=$rend; $q++){
    $no=strtolower($build[$q][3]);
    if($no=="no programming" || $np==1){
    // nothing
    }
    else{
    $next=$q;
    $np=1;
    
$flag=0;
$year="2011";
$month="11";
$day="20";

if(strtoupper($build[$next][0])=="SUNDAY"){$day="20";}
if(strtoupper($build[$next][0])=="MONDAY"){$day="21";}
if(strtoupper($build[$next][0])=="TUESDAY"){$day="22";}
if(strtoupper($build[$next][0])=="WEDNESDAY"){$day="23";}
if(strtoupper($build[$next][0])=="THURSDAY"){$day="24";}
if(strtoupper($build[$next][0])=="FRIDAY"){$day="25";}
if(strtoupper($build[$next][0])=="SATURDAY"){$day="26";}
$start_time=strtotime($year."-".$month."-".$day." ".$build[$next][1]);
$startt=date("g:00a", $start_time+($timeadjust*60*60));
        $photox="/nophoto.jpg";
            if($build[$next][6]){
            $photox=$build[$next][6];
        }     
            echo"
            <img src='$photox' alt='{$build[$next][5]}' title='{$build[$next][5]}' style='float:left'><span id='showtime'><b>Next:</b>&nbsp;$startt<br><a href='{$build[$next][7]}'>{$build[$next][3]}</a></span>
	
            ";
            $flag=1;    
    }
}
            
                
        }    
    }
}


?>
2
It would be a good idea to give us an idea of how the spreadsheet is formatted, as this will help - Luke P
Basically each show has its own row with the arrays at the top of the columns start time, end time, show name etc each have one column. Monday 00:00 to 07:00 is first, followed by Monday 07:00 to 10:00 and continues like this for a whole week. - Martyn G

2 Answers

0
votes

Managed to work this out by duplicating:

$next=$i+1; if($next > $rend){ $next=2;

By adding another unique name and adding +2 for the first line.

Also duplicating the day builds with this new name and also a unique name for the photo each time. Now showing 3 upcoming shows. Perfect.

0
votes

hi martyn how dose this work if u dont mind me asking