Newer
Older
moodlog_web / habit_ui.php
<?php
/*
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
*/
session_start();
include('config.php');
include('habit.php');
$error = "";

if(isset($_REQUEST['password']) && md5($_REQUEST['password']) == $password){
	$_SESSION['loggedin'] = true;
}

if( $_SERVER['HTTP_USER_AGENT'] == $password)
	$_SESSION['loggedin'] = true;


function getMyUrl(){
  $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
    $host = $_SERVER['HTTP_HOST'];
    $port = $_SERVER['SERVER_PORT'];

    // Exclude standard ports to prevent redundancy in the URL
    if (($protocol === 'http' && $port != 80) || ($protocol === 'https' && $port != 443)) {
        $url = "$protocol://$host";
    } else {
        $url = "$protocol://$host";
    }

    return $url;   
}

?>

<html>
	<head>

		<link rel="stylesheet" href="/deps/all.css" >

		<script type="text/javascript" src="/deps/d3.v3.min.js"></script>
		<script type="text/javascript" src="/deps/cal-heatmap.min.js"></script>
		<link rel="stylesheet" href="/deps/cal-heatmap.css" />

		<link href="/deps/google-fonts.css" rel="stylesheet">
		<link rel="stylesheet" href="/deps/jquery-ui.css">
		<link rel="stylesheet" href="/deps/fa.css">
  		<script src="/deps/jquery-1.12.4.js"></script>
  		<script src="/deps/jquery-ui.js"></script>
		<link rel="stylesheet" href="habit_ui_style.css" >

		<script src="habit_ui_script.js"></script>
	</head>
	<body>
		
		<center>
			<?php if($error <> ""){echo $error; } ?>



			<div class="habit-container-wrapper">


<?php

$fileContent = file_get_contents($habitlog);
if ($fileContent === false) {
    die("Error reading the file.");
}
$resultArray = habit_parse_file($fileContent);

foreach ($resultArray as $section) {
	$align = "";
	$buttonClass = "";
	$buttText = "";
	if($section['Category'][0] == "d"){

		$type = "day";
		$cat = "(daily)";
		if($section['Category'][1] == "+"){
			$align = "good";
			$calCol = "#58e81b";
			$title1 = "Streak";
			$title2 = "Missed";
			$title3 = "Top";
			$result1 = habit_get_stat_streak($section['Activity'], $moodlog);
			$result2 = habit_get_stat_missed($section['Activity'], $moodlog);
			$result3 = habit_get_stat_top($section['Activity'], $moodlog);

		}
		if($section['Category'][1] == "-"){
			$align = "bad";
			$calCol = "#e81b1b";
			$title1 = "Streak";
			$title2 = "Total";
			$title3 = "Top";
			$result1 = habit_get_stat_missed($section['Activity'], $moodlog);
			$result2 = habit_get_stat_year($section['Activity'], $moodlog);
			$result3 = habit_get_stat_top_missing($section['Activity'], $moodlog);
		}
		$todayCheck = habit_check_daily($section['Activity'], $moodlog);
		if ($todayCheck) {
		    $buttonClass = 'button-'.$align;
		}
	}
	if($section['Category'][0] == "w"){
		$multiplier = $section['Category'][1];
		$type = "week";
		$cat = "(weekly x $multiplier)";
		$align = "good";
		$title1 = "Streak";
		$title2 = "Missed";
		$title3 = "Top";
		$result1 = habit_get_stat_streak_week($section['Activity'], $multiplier, $moodlog);
		$result2 = habit_get_stat_missed_week($section['Activity'], $multiplier, $moodlog);
		$result3 = habit_get_stat_top_week($section['Activity'], $multiplier, $moodlog);

		$todayCheck = habit_check_daily($section['Activity'], $moodlog);
		$weekCount = habit_count_weekly($section['Activity'], $moodlog);

		if( $weekCount < $section['Category'][1] )
			if($todayCheck)
				$buttText = $weekCount;
		if($weekCount >= $multiplier)
		    	$buttonClass = 'button-done';
		if( $todayCheck ) {
		    $buttonClass = 'button-neut';
		    if($weekCount >= $multiplier)
		    	$buttonClass = 'button-good';
		}	

	}
	
	

	echo '
				<div class="habit-container" id="'.$section['Activity'].'">
			    	<div class="habit-log">
			    		 <button class="habit-log-button '.$buttonClass.'" onClick="updateHabit(\''.$section['Activity'].'\')">'.$buttText.'</button>
			    	</div>
			    	<div class="habit-main">
			    		<div class="'.$align.' habit-title">#'.$section['Activity'].' <div class="habit-timescale">'.$cat.'</div></div>
			    		<div class="habit-desc">'.$section['Description'].'</div>
			    	</div>
			    	<div class="habit-info">
				    	<div class="habit-score"><div class="score-title">'.$title1.'</div><div class="score-result result1">'.$result1.'</div></div>
				    	<div class="habit-score"><div class="score-title">'.$title2.'</div><div class="score-result result2">'.$result2.'</div></div>
				    	<div class="habit-score"><div class="score-title">'.$title3.'</div><div class="score-result result3">'.$result3.'</div></div>
					</div>
			    </div>
	';
	

}

?>



			    </div>
			</div>

		</center> 
	</body>
</html>