Skip to content

Commit

Permalink
Store and use period settings for registered users.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejs committed Jan 11, 2009
1 parent 7e04a46 commit 755c1da
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
6 changes: 3 additions & 3 deletions layout.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
function layout_shows($start, $end, $message, $minrating=1, $null=1)
function layout_shows($start, $end, $message, $name, $minrating=1, $null=1)
{
global $client;
$shows = $client->getShows($start, $end, $minrating, $null);
if (!($shows or $null))
return;
if($null){ ?>
<tr class='Infoa' onclick='toggle(this);' unrated="<?php echo $null==2?"on":"off" ?>" minrating='<?php echo $minrating; ?>'>
<tr class='Infoa' id=<?php echo $name; ?> onclick='toggle(this);' unrated="<?php echo $null==2?"on":"off" ?>" minrating='<?php echo $minrating; ?>'>
<?php } else{ ?>
<tr class='Infob' unrated="on" minrating='<?php echo $minrating; ?>'>
<tr class='Infob' id=<?php echo $name; ?> unrated="on" minrating='<?php echo $minrating; ?>'>
<?php } ?>
<td colspan='4' style='text-align: center'><?php echo $message ?></td>
</tr>
Expand Down
27 changes: 27 additions & 0 deletions models.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function update_show(){
if ($_GET) $this->setShow($_GET["show"], $_GET["rating"]);
}

public function getTimeFlag($period) {
return $period != "tomorrow" ? 2 : 1;
}

public function update_groups(){
if ($_GET) $this->setGroup($_GET["period"], $_GET["to"]);
}

public function setGroup($group, $to){ }

public function getShowInstance($start, $end, $name){
$channellist = array();
foreach ($this->channels as $channel) {
Expand Down Expand Up @@ -73,6 +83,23 @@ public function __construct($name){
parent::__construct();
}

public function setGroup($group, $to){
$mapping = array('now'=>'onnow', 'soon'=>'soon', 'later'=>'today', 'tomorrow'=>'tomorrow');
run_sql('UPDATE user SET '.$mapping[$group].' = '.( $to == 'on'? 1 : 0 ).' WHERE username = "'.escape($this->name).'" ;');
}

public function getTimeFlag($period) {
$mapping = array('now'=>'onnow', 'soon'=>'soon', 'later'=>'today', 'tomorrow'=>'tomorrow');
$result = run_sql('SELECT '.$mapping[$period].' FROM user WHERE username="'.escape($this->name).'" ;');
if (mysql_num_rows($result) > 0){
$row = mysql_fetch_row($result);
return $row[0] == '1' ? 2 : 1;
}
else {
return $period != "tomorrow" ? 2 : 1;
}
}

public function setShow($name, $rating){
if ($rating){
$result = run_sql('SELECT * FROM tvshowrating WHERE username="'.escape($this->name).'" AND showname="'.escape($name).'";');
Expand Down
4 changes: 3 additions & 1 deletion register.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ function validate($username, $password, $passwordtwo){

if (validate($user_name, $password, $passwordtwo)){
# add user to database
$result = run_sql('INSERT user SET username ="'.escape($user_name).'", password = SHA1(CONCAT(SHA1("'.escape($user_name).'"), "'.escape($password).'")), created= NOW();');
$query = 'INSERT user SET username ="'.escape($user_name).'", password = SHA1(CONCAT(SHA1("'.escape($user_name).'"), "'.escape($password).'")), created= NOW(), ';
$query = $query." onnow = 1, soon = 1, today = 1, tomorrow = 0 ;";
$result = run_sql($query);

# set active channels
foreach($_SESSION['channels'] as $channelData){
Expand Down
10 changes: 10 additions & 0 deletions toggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
require_once("config.php");
require_once("models.php");

session_start();
$client = load_user();
$client->update_groups();
if ($_GET && $_GET["ajax"]);
else header('Location: tvlisting.php');
?>
10 changes: 5 additions & 5 deletions tvlisting.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ function convertTime($offset){
<div id="main">
<table id="ShowInformation">
<tbody class="tbody">
<?php layout_shows(convertTime(0)." < endtime ", "starttime < ".convertTime(0), "On Now", 2, 2); ?>
<?php layout_shows(convertTime(0)." < starttime ", "starttime < ".convertTime(2)." AND starttime < ".convertDate(1), "Soon", 3, 2); ?>
<?php layout_shows(convertTime(2)." < starttime ", "starttime < ".convertDate(1), "Later Today", 4, 2); ?>
<?php layout_shows(convertDate(1)." < starttime ", "starttime < ".convertDate(2), "Tomorrow", 4, 1); ?>
<?php layout_shows(convertTime(0)." < endtime ", "starttime < ".convertTime(0), "On Now", 'now', 2, $client->getTimeFlag("now")); ?>
<?php layout_shows(convertTime(0)." < starttime ", "starttime < ".convertTime(2)." AND starttime < ".convertDate(1), "Soon", 'soon', 3, $client->getTimeFlag("soon")); ?>
<?php layout_shows(convertTime(2)." < starttime ", "starttime < ".convertDate(1), "Later Today", 'later', 4, $client->getTimeFlag("later")); ?>
<?php layout_shows(convertDate(1)." < starttime ", "starttime < ".convertDate(2), "Tomorrow", 'tomorrow', 4, $client->getTimeFlag("tomorrow")); ?>
<?php for($c = 2; $c < 7; $c += 1){
$tmp = getdate(time()+($c*24*60*60));
layout_shows(convertDate($c)." < starttime ", "starttime < ".convertDate($c+1), "${tmp['mday']} ${tmp['month']} ${tmp['year']}", 5, 0);
layout_shows(convertDate($c)." < starttime ", "starttime < ".convertDate($c+1), "${tmp['mday']} ${tmp['month']} ${tmp['year']}", "plus${c}days", 5, 0);
} ?>
</tbody>
</table>
Expand Down
1 change: 1 addition & 0 deletions tvphp.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function toggle(item) {
item.showUnrated = item.showUnrated ? false : true;
else
item.showUnrated = !(item.getAttribute("unrated") == "on");
touch(""+location.protocol+"//"+location.host+'/toggle.php?period='+item.id+'&to='+(item.showUnrated ? "on" : "off")+"&ajax=1");
setVisibilities();
}

Expand Down

0 comments on commit 755c1da

Please sign in to comment.