<commit_before><?php

session_start();
require_once('auth.php');
require_once('twitteroauth/twitteroauth.php');
require_once('common.php');
require_once('config.php');

// DB connection
mysql_connect(DB_SERVER,DB_USER,DB_PASS);
@mysql_select_db(DB_NAME) or die( "Unable to select database");

// Get user id for display, either from a username lookup (/user/blah) or from session (/view).
if (isset($_GET['username'])) {
    $query = "SELECT * FROM users WHERE username='" . mysql_real_escape_string($_GET['username']) . "'";
    $userResult = mysql_query($query);
    $row = mysql_fetch_assoc($userResult);
    $uid = $row['uid'];
} else {
    $uid = $_SESSION['uid'];
}

$content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <head>
	<link type="text/css" rel="stylesheet" media="all" href="/default.css" />

  </head>
  <body>';
$content .= makeHistoryTable($uid);
$content .= '</body></html>';
echo($content);

mysql_close();


function makeHistoryTable($uid) {

    $query = "SELECT * FROM promises WHERE uid='" . mysql_real_escape_string($uid) . "'";
    $promiseResult = mysql_query($query);
    
    $content .= "<table class=\"historytable\"><tr><td></td>";
    
    // Make the month headers
    $months = createDatesArray("F");
    $month1 = $months[0];
    for ($i = 1; $i <= 28; $i++) {
        if ($months[$i] != $month1) {
            $month2 = $months[$i];
            $switchpoint = $i;
            break;
        }
    }
    // Shorten if only 1 day width to fit it in
    if ($switchpoint == 1) {
        $month1 = substr($month1,0,3);
    } else if ($switchpoint == 27) {
        $month2 = substr($month2,0,3);
    }
    $content .= "<td class=\"month\" colspan=" . $switchpoint . ">" . $month1 . "</td>";
    if ($switchpoint < 28) {
        $content .= "<td class=\"month\" colspan=" . (28-$switchpoint) . ">" . $month2 . "</td>";
    }
    $content .= "</tr>";
    
    // Make the date headers
    $content .= "<tr><td></td>";
    $dates = createDatesArray("D<b\\r>jS");
    $today = date("D<b\\r>jS", strtotime("today"));
    foreach ($dates as $date) {
        // Highlight today's date
        if ($date == $today) {
            $content .= "<td class=\"date\"><strong>" . $date . "</strong></td>";
        } else {
            $content .= "<td class=\"date\">" . $date . "</td>";
        }
    }
    $content .= "</tr>";
    $dates = createDatesArray("Y-m-d");
    while ($promise = mysql_fetch_assoc($promiseResult)) {
        $content .= "<tr><td class=\"promise\">" . $promise['promise'] . "</td>";
        foreach ($dates as $date) {
            $query = "SELECT * FROM records WHERE uid='" . mysql_real_escape_string($uid) . "' AND pid='" . mysql_real_escape_string($promise['pid']) . "' AND date='" . mysql_real_escape_string($date) . "'";
            $recordResult = mysql_query($query);
            if (mysql_num_rows($recordResult) > 0) {
                $row = mysql_fetch_assoc($recordResult);
                if ($row['kept'] == "YES") {
                    $color = "#88ff88";
                } else if ($row['kept'] == "NO") {
                    $color = "#ff8888";
                } else /* WAITING */ {
                    $color = "#bbbbbb";
                }
            } else {
                $color = "#dddddd";
            }
            $content .= "<td style=\"background:" . $color . "\">" . $kept . "</td>";
        }
        $content .= "</tr>";
        
    }
    // User is generating their own table, offer a link to add more promises.
    if ($_SESSION['uid'] == $uid) {
        $content .= "<tr><td class=\"promise\"><a href=\"/manage\">add a";
        if (mysql_num_rows($promiseResult) > 0) { $content .= "nother"; }
        $content .= " promise?</a></td></tr>";
    } else if (mysql_num_rows($promiseResult) == 0) {
        // Other user's blank table
        $content .= "<tr><td class=\"promise\">no promises set yet!</td></tr>";
    }
    
    $content .= "</table>";
    
    return $content;
    
}

function createDatesArray($format) {
    $days = array();
    $y = date("y", strtotime("sunday"));
    $m = date("m", strtotime("sunday"));<commit_msg>The "add another promise" link wasn't breaking out of the IFRAME, fixed that.<commit_after><?php

session_start();
require_once('auth.php');
require_once('twitteroauth/twitteroauth.php');
require_once('common.php');
require_once('config.php');

// DB connection
mysql_connect(DB_SERVER,DB_USER,DB_PASS);
@mysql_select_db(DB_NAME) or die( "Unable to select database");

// Get user id for display, either from a username lookup (/user/blah) or from session (/view).
if (isset($_GET['username'])) {
    $query = "SELECT * FROM users WHERE username='" . mysql_real_escape_string($_GET['username']) . "'";
    $userResult = mysql_query($query);
    $row = mysql_fetch_assoc($userResult);
    $uid = $row['uid'];
} else {
    $uid = $_SESSION['uid'];
}

$content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <head>
	<link type="text/css" rel="stylesheet" media="all" href="/default.css" />

  </head>
  <body>';
$content .= makeHistoryTable($uid);
$content .= '</body></html>';
echo($content);

mysql_close();


function makeHistoryTable($uid) {

    $query = "SELECT * FROM promises WHERE uid='" . mysql_real_escape_string($uid) . "'";
    $promiseResult = mysql_query($query);
    
    $content .= "<table class=\"historytable\"><tr><td></td>";
    
    // Make the month headers
    $months = createDatesArray("F");
    $month1 = $months[0];
    for ($i = 1; $i <= 28; $i++) {
        if ($months[$i] != $month1) {
            $month2 = $months[$i];
            $switchpoint = $i;
            break;
        }
    }
    // Shorten if only 1 day width to fit it in
    if ($switchpoint == 1) {
        $month1 = substr($month1,0,3);
    } else if ($switchpoint == 27) {
        $month2 = substr($month2,0,3);
    }
    $content .= "<td class=\"month\" colspan=" . $switchpoint . ">" . $month1 . "</td>";
    if ($switchpoint < 28) {
        $content .= "<td class=\"month\" colspan=" . (28-$switchpoint) . ">" . $month2 . "</td>";
    }
    $content .= "</tr>";
    
    // Make the date headers
    $content .= "<tr><td></td>";
    $dates = createDatesArray("D<b\\r>jS");
    $today = date("D<b\\r>jS", strtotime("today"));
    foreach ($dates as $date) {
        // Highlight today's date
        if ($date == $today) {
            $content .= "<td class=\"date\"><strong>" . $date . "</strong></td>";
        } else {
            $content .= "<td class=\"date\">" . $date . "</td>";
        }
    }
    $content .= "</tr>";
    $dates = createDatesArray("Y-m-d");
    while ($promise = mysql_fetch_assoc($promiseResult)) {
        $content .= "<tr><td class=\"promise\">" . $promise['promise'] . "</td>";
        foreach ($dates as $date) {
            $query = "SELECT * FROM records WHERE uid='" . mysql_real_escape_string($uid) . "' AND pid='" . mysql_real_escape_string($promise['pid']) . "' AND date='" . mysql_real_escape_string($date) . "'";
            $recordResult = mysql_query($query);
            if (mysql_num_rows($recordResult) > 0) {
                $row = mysql_fetch_assoc($recordResult);
                if ($row['kept'] == "YES") {
                    $color = "#88ff88";
                } else if ($row['kept'] == "NO") {
                    $color = "#ff8888";
                } else /* WAITING */ {
                    $color = "#bbbbbb";
                }
            } else {
                $color = "#dddddd";
            }
            $content .= "<td style=\"background:" . $color . "\">" . $kept . "</td>";
        }
        $content .= "</tr>";
        
    }
    // User is generating their own table, offer a link to add more promises.
    if ($_SESSION['uid'] == $uid) {
        $content .= "<tr><td class=\"promise\"><a href=\"/manage\" target=\"_top\">add a";
        if (mysql_num_rows($promiseResult) > 0) { $content .= "nother"; }
        $content .= " promise?</a></td></tr>";
    } else if (mysql_num_rows($promiseResult) == 0) {
        // Other user's blank table
        $content .= "<tr><td class=\"promise\">no promises set yet!</td></tr>";
    }
    
    $content .= "</table>";
    
    return $content;
    
}

function createDatesArray($format) {
    $days = array();
    $y = date("y", strtotime("sunday"));
    $m = date("m", strtotime("sunday"));
{'fraction_non_alphanumeric': 0.20892448512585812, 'fraction_numerical': 0.010983981693363844, 'mean_word_length': 2.431880643894778, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1726844', 'n_tokens_mistral': 2943, 'n_tokens_neox': 2820, 'n_words': 624}