Newer
Older
moodlog_web / habit_ui.php
  1. <?php
  2. /*
  3. ini_set('display_errors', 1);
  4. ini_set('display_startup_errors', 1);
  5. error_reporting(E_ALL);
  6. */
  7. session_start();
  8. include('config.php');
  9. include('habit.php');
  10. $error = "";
  11.  
  12. if(isset($_REQUEST['password']) && md5($_REQUEST['password']) == $password){
  13. $_SESSION['loggedin'] = true;
  14. }
  15.  
  16. if( $_SERVER['HTTP_USER_AGENT'] == $password)
  17. $_SESSION['loggedin'] = true;
  18.  
  19.  
  20. function getMyUrl(){
  21. $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
  22. $host = $_SERVER['HTTP_HOST'];
  23. $port = $_SERVER['SERVER_PORT'];
  24.  
  25. // Exclude standard ports to prevent redundancy in the URL
  26. if (($protocol === 'http' && $port != 80) || ($protocol === 'https' && $port != 443)) {
  27. $url = "$protocol://$host";
  28. } else {
  29. $url = "$protocol://$host";
  30. }
  31.  
  32. return $url;
  33. }
  34.  
  35. ?>
  36.  
  37. <html>
  38. <head>
  39.  
  40. <link rel="stylesheet" href="/deps/all.css" >
  41.  
  42. <script type="text/javascript" src="/deps/d3.v3.min.js"></script>
  43. <script type="text/javascript" src="/deps/cal-heatmap.min.js"></script>
  44. <link rel="stylesheet" href="/deps/cal-heatmap.css" />
  45.  
  46. <link href="/deps/google-fonts.css" rel="stylesheet">
  47. <link rel="stylesheet" href="/deps/jquery-ui.css">
  48. <link rel="stylesheet" href="/deps/fa.css">
  49. <script src="/deps/jquery-1.12.4.js"></script>
  50. <script src="/deps/jquery-ui.js"></script>
  51. <link rel="stylesheet" href="habit_ui_style.css" >
  52.  
  53. <script src="habit_ui_script.js"></script>
  54. </head>
  55. <body>
  56. <center>
  57. <?php if($error <> ""){echo $error; } ?>
  58.  
  59.  
  60.  
  61. <div class="habit-container-wrapper">
  62.  
  63.  
  64. <?php
  65.  
  66. $fileContent = file_get_contents($habitlog);
  67. if ($fileContent === false) {
  68. die("Error reading the file.");
  69. }
  70. $resultArray = habit_parse_file($fileContent);
  71.  
  72. foreach ($resultArray as $section) {
  73. $align = "";
  74. $buttonClass = "";
  75. $buttText = "";
  76. if($section['Category'][0] == "d"){
  77.  
  78. $type = "day";
  79. $cat = "(daily)";
  80. if($section['Category'][1] == "+"){
  81. $align = "good";
  82. $calCol = "#58e81b";
  83. $title1 = "Streak";
  84. $title2 = "Missed";
  85. $title3 = "Top";
  86. $result1 = habit_get_stat_streak($section['Activity'], $moodlog);
  87. $result2 = habit_get_stat_missed($section['Activity'], $moodlog);
  88. $result3 = habit_get_stat_top($section['Activity'], $moodlog);
  89.  
  90. }
  91. if($section['Category'][1] == "-"){
  92. $align = "bad";
  93. $calCol = "#e81b1b";
  94. $title1 = "Streak";
  95. $title2 = "Total";
  96. $title3 = "Top";
  97. $result1 = habit_get_stat_missed($section['Activity'], $moodlog);
  98. $result2 = habit_get_stat_year($section['Activity'], $moodlog);
  99. $result3 = habit_get_stat_top_missing($section['Activity'], $moodlog);
  100. }
  101. $todayCheck = habit_check_daily($section['Activity'], $moodlog);
  102. if ($todayCheck) {
  103. $buttonClass = 'button-'.$align;
  104. }
  105. }
  106. if($section['Category'][0] == "w"){
  107. $multiplier = $section['Category'][1];
  108. $type = "week";
  109. $cat = "(weekly x $multiplier)";
  110. $align = "good";
  111. $title1 = "Streak";
  112. $title2 = "Missed";
  113. $title3 = "Top";
  114. $result1 = habit_get_stat_streak_week($section['Activity'], $multiplier, $moodlog);
  115. $result2 = habit_get_stat_missed_week($section['Activity'], $multiplier, $moodlog);
  116. $result3 = habit_get_stat_top_week($section['Activity'], $multiplier, $moodlog);
  117.  
  118. $todayCheck = habit_check_daily($section['Activity'], $moodlog);
  119. $weekCount = habit_count_weekly($section['Activity'], $moodlog);
  120.  
  121. if( $weekCount < $section['Category'][1] )
  122. if($todayCheck)
  123. $buttText = $weekCount;
  124. if($weekCount >= $multiplier)
  125. $buttonClass = 'button-done';
  126. if( $todayCheck ) {
  127. $buttonClass = 'button-neut';
  128. if($weekCount >= $multiplier)
  129. $buttonClass = 'button-good';
  130. }
  131.  
  132. }
  133.  
  134. echo '
  135. <div class="habit-container" id="'.$section['Activity'].'">
  136. <div class="habit-log">
  137. <button class="habit-log-button '.$buttonClass.'" onClick="updateHabit(\''.$section['Activity'].'\')">'.$buttText.'</button>
  138. </div>
  139. <div class="habit-main">
  140. <div class="'.$align.' habit-title">#'.$section['Activity'].' <div class="habit-timescale">'.$cat.'</div></div>
  141. <div class="habit-desc">'.$section['Description'].'</div>
  142. </div>
  143. <div class="habit-info">
  144. <div class="habit-score"><div class="score-title">'.$title1.'</div><div class="score-result result1">'.$result1.'</div></div>
  145. <div class="habit-score"><div class="score-title">'.$title2.'</div><div class="score-result result2">'.$result2.'</div></div>
  146. <div class="habit-score"><div class="score-title">'.$title3.'</div><div class="score-result result3">'.$result3.'</div></div>
  147. </div>
  148. </div>
  149. ';
  150.  
  151. }
  152.  
  153. ?>
  154.  
  155.  
  156.  
  157. </div>
  158. </div>
  159.  
  160. </center>
  161. </body>
  162. </html>
Buy Me A Coffee