Location: PHPKode > projects > WebVCR+ > favorites.php
<?php
 // $Id: favorites.php,v 1.12 2003/01/29 01:36:06 pyromanfo Exp $
 // $Author: pyromanfo $

include("lib/functions.php");


print_header_open();
print "<script src=\"popup.js\"></script>";
print_title ("favorites");
print_header_close();

if ($del != '') {
	$progs = get_favorites($del);
	
	$sql->query("delete from favorites where priority='$del'");
        $sql->query("update program set record=0, flag=0 where pname='".$del."'");

	# update the remaining favorites, if they conflicted with one of the newly deleted favorites
        $result = $sql->query("select priority from favorites order by priority");
        while ($priorities[] = $sql->fetch_array($result) );
        array_pop($priorities);
       foreach($progs as $pid)  {
		derecord($pid);
		foreach($priorities as $pri)  {
			$pri = $pri[0];
			$fav_progs = get_favorites($pri);
			foreach($fav_progs as $fav)  {
				$chk_result = $sql->query("select A.pid from program as A, program as B where 
						A.pid=$fav and B.pid=$pid
					     AND ((A.start <= B.start AND B.start < A.stop) OR
	                	             (A.start < B.stop AND B.stop <= A.stop) OR
        		                     (A.start = B.start AND A.stop = B.stop))");
				$count = mysql_num_rows($chk_result);
				if ($count != 0)
					record($fav,4);
			}
		}
	}
						
}

if ($pri != '' && $priold != '')  {
	addslashes($pri);
	addslashes($priold);
	$sql->query("update favorites set priority='999999' where priority='".$priold."'");
        $sql->query("update favorites set priority='".$priold."' where priority='".$pri."'");
        $sql->query("update favorites set priority='".$pri."' where priority='999999'");
	# now update the recording of the new program
	if ($priold < $pri)  #only update the recording of the now higher priority program (lowest number)
                foreach(get_favorites($priold) as $pid)  {
	                derecord($pid);
        	        record($pid,4);
        	}
	else
                foreach(get_favorites($pri) as $pid)  {
                        derecord($pid);
                        record($pid,4);
                }


}
if ($update_favs == 1)  {
	$result = $sql->query("select priority from favorites order by priority");
	while ($priorities[] = $sql->fetch_array($result) );
        array_pop($priorities);
	foreach ($priorities as $pri)  {
		$pri = $pri[0];
		if ($sid[$pri] == '')
			$sid[$pri] = "NULL";

		if ($ftime[$pri] != "NULL")
			$ftime[$pri]="'".$ftime[$pri].":00'";

		# set the day of the week, 1=Sunday ... 7=Saturday
		# arbitrary dates starting at Dec 15th, 2002
		# since only DAYOFWEKK(fday) is used, the rest is random
		if ($fday[$pri] == 1)
			$fday[$pri] = "'2002-12-15'";
		if ($fday[$pri] == 2)
			$fday[$pri] = "'2002-12-16'";
		if ($fday[$pri] == 3)
			$fday[$pri] = "'2002-12-17'";
		if ($fday[$pri] == 4)
			$fday[$pri] = "'2002-12-18'";
		if ($fday[$pri] == 5)
			$fday[$pri] = "'2002-12-19'";
		if ($fday[$pri] == 6)
			$fday[$pri] = "'2002-12-20'";
		if ($fday[$pri] == 7)
			$fday[$pri] = "'2002-12-21'";

		# first, unrecord all favorites, because they may not be favorites after update
		# notice you can't just derecord, as they need to be cleared of favorite status as well
		foreach(get_favorites($pri) as $pid)  {
			$sql->query("update program set flag=0,record=0 where pid=$pid");
		}
		$sql->query("update favorites set fday=".($fday[$pri])." where priority=$pri");
		$sql->query("update favorites set ftime=".($ftime[$pri])." where priority=$pri");
		$sql->query("update favorites set sid=".($sid[$pri])." where priority=$pri");
                $sql->query("update favorites set frerun=".($frerun[$pri])." where priority=$pri");



		# now that updated, update program database
		foreach(get_favorites($pri) as $pid)  {
			record($pid,4);                        
		}

	}
}
if ($add != '') {
	$add = urldecode($add);
	addslashes($add);
	# find the next highest priority to add
	$result = $sql->query("select MAX(priority) AS priority from favorites");
	list($pri) = $sql->fetch_array($result);
	$pri++;
	$sql->query("insert into favorites values (NULL,NULL,'".$add."',NULL,NULL,NULL,'$pri')");
	$pids = get_favorites($pri);
	foreach($pids as $pid)
		record($pid,4);
	print "Favorite $add added!<br>\n<a href=\"Javascript:history.back()\"> Back </a>\n";
	
} else {
	print "<FORM ACTION=\"favorites.php\" METHOD=POST>\n";

	$fav_result = $sql->query("select fname,priority,DAYOFWEEK(fday),TIME_FORMAT(ftime,'%k:%i'),sid,frerun from favorites order by priority");
	print "<table border=0 width=80%><tr bgcolor=\"#006666\"><td>
	        <font color=\"#FFFFFF\"><b>Favorites</b> </font></td><td bgcolor=\"#FFFFFF\" align=right><a href=\"javascript:LaunchPopup('fav_help.html','640','480','1');\">Help</a></td>
		</tr><tr bgcolor=\"#FFFFFF\">
		<td colspan=2>
		<table border=0 cellspacing=0 width=100%>";
	$count = mysql_num_rows($fav_result);
	# read all entries into an array
	while ( $fav_data[] = $sql->fetch_array($fav_result) );
	$num=0;

	#get rid of phantom entry due to failing fetch_array call
	array_pop($fav_data);
	
	# days of week
	$dow = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	#now display list of info
	foreach ($fav_data as $data)  {
                print "<tr><td>$data[0]</td>";
		print "<td>";
		print_select_station("sid[".$data[1]."]",$data[4]);
		print "<br>\n";
		print "<select name=\"fday[".$data[1]."]\">\n";
                if ($data[2] == '')
                        print "<option value=\"NULL\" selected>Everyday\n";
                else print "<option value=\"NULL\">Everyday\n";

		for($day=1; $day<8; $day++)  {
			if ($day==$data[2])
				print "<option value=\"$day\" selected>".($dow[$day-1])."\n";
			else print "<option value=\"$day\">".($dow[$day-1])."\n";
		}
		print "</select>\n";

                print "<select name=\"ftime[".$data[1]."]\">\n";
		if ($data[3] == '')
			print "<option value=\"NULL\" selected>Anytime\n";
		else print "<option value=\"NULL\">Anytime\n";

                for($hr=0; $hr<24; $hr++)  {

			$temp_hr = $hr % 12;

			if ($hr >= 12)
				$suffix = "PM";
			else $suffix="AM";

			if ($temp_hr == 0)  
				$temp_hr = 12;
			
                        if (($hr.":00")==$data[3])
                                print "<option value=\"".$hr.":00\" selected>$temp_hr:00$suffix\n";
                        else print "<option value=\"".$hr.":00\">$temp_hr:00$suffix\n";
                        if (($hr.":30")==$data[3])
                                print "<option value=\"".$hr.":30\" selected>$temp_hr:30$suffix\n";
                        else print "<option value=\"".$hr.":30\">$temp_hr:30$suffix\n";

                }
                print "</select><br>\n";
		
		# rerun select box
		print "<select name=\"frerun[".$data[1]."]\">\n";
		if ($data[5] == '')  {
			print " <option value=\"NULL\" selected>All Episodes</option>
				<option value=\"1\">Only Rerun Episodes</option>
				<option value=\"0\">Only New Episodes</option>\n";
		} else if ($data[5] == 1)  {
                        print " <option value=\"NULL\">All Episodes</option>
				<option value=\"1\" selected>Only Rerun Episodes</option>
                                <option value=\"0\">Only New Episodes</option>\n";
		} else if ($data[5] == 0)  {
                        print " <option value=\"NULL\" selected>All Episodes</option>
				<option value=\"1\">Only Rerun Episodes</option>
                                <option value=\"0\" selected>Only New Episodes</option>\n";		
		}
		print "</select></td>\n";

                if ($num==0) #first in list
                        print"<td align=right>
                        <a href=\"$PHP_SELF?pri=".($fav_data[$num+1][1])."&priold=".$data[1]."\"><img border=0 src=\"images/down.gif\"></a></td>";
                else if (($num+1)==$count)  #last in list
                        print"<td align=right>                                                                                                              <a href=\"$PHP_SELF?pri=".($fav_data[$num-1][1])."&priold=".$data[1]."\"><img border=0 src=\"images/up.gif\"></a></td>";
                      else  #normal entry
                        print"<td align=right>
                        <a href=\"$PHP_SELF?pri=".($fav_data[$num-1][1])."&priold=".$data[1]."\"><img border=0 src=\"images/up.gif\"></a><br>
                        <a href=\"$PHP_SELF?pri=".($fav_data[$num+1][1])."&priold=".$data[1]."\"><img border=0 src=\"images/down.gif\"></a></td>";


		print "<td align=right><a href=\"$PHP_SELF?del=".$data[1]."\">Delete</a></td></tr>\n";
		$num++;
		print "<tr><td></td></tr>\n";
                print "<tr><td></td></tr>\n";


	}
	if ($count == 0)  // nothing was found
		print "<tr><td>No Favorites Set!</td></tr>\n";
	print "</table>";
	print "<tr><td align=center><input type=\"hidden\" name=\"update_favs\" value=\"1\"><input type=\"submit\" name=\"update\" value=\"Save Settings\"></td></tr>\n";
	print "</table></form>";
}
print_page_close();
?>

Return current item: WebVCR+