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