<p>The Spring 2007 will be available in the coming weeks.</p><p></p> The website links on this schedule are not affiliated with or hosted by Manhattan Neighborhood Network, therefore MNN is not responsible for their content.</p>
<?php
/*
* Name: schedule.php
* Author: Jacob Redding & Hailu Dyami
* Date: April 24th, 2007
* Purpose: Displays a simple multi-row "table" from the on-air scheduling DB. Allows users to
* search past and future shows
* Comments: This is working towards a more permanent solution
*/
//Constants
$NOSHOWS_MSG = "Nothing scheduled for that time/date/topic combination, please try a different combination.";
$DATABASE_ERROR = "<div align=\"center\">We apologize but there was an error connecting to the database, the schedule can not be viewed at this time<br> Please try again later</div>";
error_reporting(0);
//Variables
$allowed_days_in_past=14; //max days allowed in the past
$allowed_days_in_future=14; //max days allowed in the future
$channel = 34; //default channel
$dayfromuser = time();; //Default date to display
$category = ""; //Default category, blanks means all
//Grab the GET variables
if ($_GET['topic']) { $topic = $_GET['topic']; }
if ($_GET['Date']) { $Date = $_GET['Date']; }
//Build the start and end times
$time = $dayfromuser;
//Make sure that the start and end time do not go before or after the allow min/max times
$past_time = time() - ($allowed_days_in_past * 24 * 60 * 60);
$future_time = time() + ($allowed_days_in_future * 24 * 60 * 60);
if ($time < $past_time OR $time > $future_time) { $time = time(); }
//Grab the beginning of the day
$start_time = mktime(1, 0, 0, date('m', $time),date('d', $time),date('Y', $time));
$end_time = $start_time + (24 * 60 * 60);
//Build the Query
$query= "SELECT schedule.project_no, project.name, project.narrative, project.runtime, schedule.channel, project.content_type_no, content_type.name, schedule.starts, project.public_email, project.public_url, project.public_contact_info FROM schedule " .
"LEFT JOIN project on project.no = schedule.project_no " .
"LEFT JOIN project_member on project_member.project_no = project.no AND execute_producer =TRUE " .
"LEFT JOIN content_type on project.content_type_no = content_type.no " .
"LEFT JOIN topic on project.topic_no = topic.no " .
//We have to append 3 zeros to the unixtimestamp because Ocean 7 (developers of the database) decided to
//attempt to create a to-the-millisecond unix timestamp although their implementation was very poor
"WHERE schedule.starts >= ". $start_time . "000" .
" AND " .
" schedule.ends <= " . $end_time . "000" .
" AND schedule.channel='". $channel."'";
//if there's a topic narrow search to only the topic and escape string
if ($topic) {
$topic = mysql_real_escape_string($topic);
$query .= " AND content_type.name = '$topic' ";
}
if ($Date) {
$Date = mysql_real_escape_string($Date);
$query .= " WHERE schedule.starts >= " . '$Date' . "000";
}
//**********sorts by start time************
$query .=" ORDER BY schedule.starts, schedule.channel ASC ";
//Below this point output is possible so we need to create HTML tags
//Add Javascript
?>
<?php
//Connect to DB
$pgconn = pg_connect("host=216.164.83.163 port=5432 dbname=mnno7app user=extwebaccount password=webbyboy") or die($DATABASE_ERROR);
//Execute the Query
$schedule_results = pg_query($query) or die($DATABASE_ERROR); //executes a query
//Output the results using theme_table(formatting to be controlled via CSS; schedule.css in the same directory)
//We actually have to modify the implementation of theme_table to() pass html 'class' attributes later
//make header argument for theme_table
$header = array("Time", "Title", "Description", "Topic");
//manualy defines $row each time, then adds $row as a line of $rows, overwrites $row to start a new line for $rows
while($pgresult = pg_fetch_array($schedule_results))
{
//Because Ocean 7 attempted to create a to-the-millisecond UNIX timestamp this code is created. the last 3 zeros must be stripped
//The time is also 3 hours off... whatever.
$starts = substr($pgresult["starts"],1,strlen($string)-3) + (2*60*60);
//The time (Ocean 7 error) is a bit screwed up so if the minutes are larger than 20 minutes then we'll put it on the half-hour
// if less than 20 minutes then on the hour. You can thank Ocean 7 for this one.. uggh.
$minutes = date('i', $starts);
if ( $minutes >= 20 ) {
$minutes = "30";
} else {
$minutes = "00";
}
$hours = date('h', $starts);
$ampm = date('a', $starts);
$oSevenTime = $hours.":".$minutes.$ampm;
//oSeven's the var that theme_table uses to populate the start times
$row["starts"] = $oSevenTime;
$row["title"] = $pgresult[1];
$row["narrative"] = $pgresult['narrative'];
$row["topic"] = $pgresult[6];
$rows[] = $row;
};
$schedtable = theme_table($header, $rows);
//end table definition
/*
*******************Use forms api to create the dropdowns***************
*/
//Go to Postgres and pull the various topics that are available for this date/time/channel.
$sql = "SELECT content_type.name, content_type.no FROM schedule ".
"LEFT JOIN project on project.no = schedule.project_no ".
"LEFT JOIN content_type on project.content_type_no = content_type.no " .
//Limit to only the dateselect. minding the starting and end time of the day
"WHERE schedule.starts >= ". $start_time . "000" .
" AND " .
" schedule.ends <= " . $end_time . "000" .
" AND schedule.channel='". $channel."'".
//Drop the empty names
" AND content_type.name <> ''" .
" GROUP BY content_type.name, content_type.no ORDER BY content_type.name ASC";
$fieldset = pg_query($sql) or die($DATABASE_ERROR);
//****************date selector**************
//First today's date
$time = time();
//max days prior to today
$subtract_days = ($allowed_days_in_past * 24 * 60 * 60);
$day_in_past = mktime(0,0,0, date('m', $time), date('d', $time),date('Y', $time)) - $subtract_days;
//max days in the future
$add_days = ($allowed_days_in_future * 24 * 60 * 60);
$day_in_future = mktime(0,0,0, date('m', $time), date('d', $time),date('Y', $time)) + $add_days;
//Add the Show All option
$Doptions[""] = 'Show All';
//iterate to populate options array
for($i = $day_in_past; $i <= $day_in_future; $i = $i + (1 * 24 * 60 * 60))
{
$Doptions["?Date=".$i."000"] = t(date('D m/d/y', $i));
}
$default_date = t('');
if ($Date) { $default_date = "?Date=".$i."000"; }
//name the form
$Dformname = "datedropdown";
$form['dates'] = array(
'#type' => 'select',
'#name' => "$Dformname",
'#id' => "$Dformname",
'#title' => t('Select a Date'),
'#default_value' => $default_date,
'#options' => $Doptions,
'#description' => '',
'#multiple' => $multiple = FALSE,
'#required' => $required = FALSE,
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$Dformname').options[document.getElementById('$Dformname').selectedIndex].value"),
#
);
$date_form = drupal_get_form('$Dformname', $form);
//*************topic selector**************
//Add the Show All option
$options[""] = 'Show All';
//Put the data into an options array
while($sqlresult = pg_fetch_array($fieldset))
{
$options["?topic=".$sqlresult[name]] = t($sqlresult[name]);
}
$default_topic = t('');
if ($topic) { $default_topic = "?topic=".$topic; }
$formname = "topicdropdown";
//reset variable for use of another form
$form = array();
$form['topics'] = array(
'#type' => 'select',
'#name' => "$formname",
'#id' => "$formname",
'#title' => t('Select a Topic'),
'#default_value' => $default_topic,
'#options' => $options,
'#description' => '',
'#multiple' => $multiple = FALSE,
'#required' => $required = FALSE,
'#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
#
);
$topic_form = drupal_get_form('topics', $form);
//************Output************
echo $topic_form;
echo $date_form;
echo $schedtable;
?>