Newer
Older
moodlog_web / index.php
0xRoM on 6 Jan 2024 21 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. if(!isset($_SESSION['loggedin']) || isset($_GET['logout'])){
  17. if(isset($_SESSION['loggedin']))
  18. unset($_SESSION['loggedin']);
  19. include('login.html');
  20. die();
  21. }
  22.  
  23. /***
  24. * actions here for API / AJAX
  25. */
  26. if(isset($_GET['action'])){
  27. switch ($_GET['action']) {
  28. case 'main_cal': // get unfiltered main cal averages - output JSON
  29. header('Content-Type: application/json');
  30. $result = main_cal();
  31. echo "{".$result."}";
  32. break;
  33. case 'filtered_cal': // get filtered main cal averages (filter=+test-test@test-test...) - output JSON
  34. header('Content-Type: application/json');
  35. if(isset($_GET['filter'])){
  36. $result = filtered_cal($_GET['filter']);
  37. echo "{".$result."}";
  38. }else{
  39. echo "0";
  40. }
  41. break;
  42. case 'date': // get specific date's log - output HTML
  43. if(isset($_GET['date'])){
  44. $result = today($_GET['date']);
  45. echo $result;
  46. }else{
  47. echo "0";
  48. }
  49. break;
  50. case 'date_average': // get specific date's average - output no.
  51. if(isset($_GET['date'])){
  52. $result = day_avg($_GET['date']);
  53. echo $result;
  54. }else{
  55. echo "0";
  56. }
  57. break;
  58. case 'latest': // get latest 5 tags - output JSON
  59. if(isset($_GET['tag'])){
  60. $result = latest($_GET['tag']);
  61. echo $result;
  62. }else{
  63. echo "0";
  64. }
  65. break;
  66. case 'top': // get top 5 tags - output JSON
  67. if(isset($_GET['tag'])){
  68. $result = toptag($_GET['tag']);
  69. echo $result;
  70. }else{
  71. echo "0";
  72. }
  73. break;
  74. case 'alltag': // get all tags in popularity order - output JSON
  75. $result = alltag();
  76. echo $result;
  77. break;
  78. case 'save':
  79. if(isset($_GET['log'])){ // save a new moodlog
  80. $result = new_log($_GET['log']);
  81. echo $result;
  82. }else{
  83. echo "0";
  84. }
  85. break;
  86. case 'habit_cal_daily': // get unfiltered main cal averages - output JSON
  87. header('Content-Type: application/json');
  88. if(isset($_GET['habit'])){
  89. $result = habit_cal_daily($_GET['habit']);
  90. echo $result;
  91. }else{
  92. echo "0";
  93. }
  94. break;
  95. case 'habit_cal_weekly': // get unfiltered main cal averages - output JSON
  96. header('Content-Type: application/json');
  97. if(isset($_GET['habit'])){
  98. $result = habit_cal_weekly($_GET['habit']);
  99. echo $result;
  100. }else{
  101. echo "0";
  102. }
  103. break;
  104. case 'habit_update': // get unfiltered main cal averages - output JSON
  105. header('Content-Type: application/json');
  106. if(isset($_GET['habit'])){
  107. habit_update($_GET['habit'], $moodlog);
  108. $result = habit_get_json($_GET['habit'], $moodlog, $habitlog);
  109. echo $result;
  110. }else{
  111. echo "0";
  112. }
  113. break;
  114. case 'habit_all_stats': // get unfiltered main cal averages - output JSON
  115. header('Content-Type: application/json');
  116. $result = habit_get_json_all( $moodlog, $habitlog );
  117. echo $result;
  118. break;
  119. default:
  120. # code...
  121. break;
  122. }
  123. die();
  124. }
  125.  
  126. //$result = today("2018-09-13");
  127. //echo $result;
  128.  
  129. function today($ymd){
  130. global $moodlog;
  131. $ymd = strtotime($ymd);
  132. $dateTime = new \DateTime(null, new DateTimeZone('Europe/London'));
  133. $dateTime->setTimestamp($ymd);
  134. $date = $dateTime->format('Y-m-d');
  135. $ymd2 = date("Y-m-d", strtotime("$date"));
  136. //echo $ymd2;
  137.  
  138. //$returnstring = "<div class=\"sub-header\">$justdate</div>\n";
  139. $returnstring = "<div class=\"sub-header\">$ymd2</div>\n";
  140. $count = 0;
  141.  
  142. $moodfile = @fopen($moodlog, "r");
  143. if ($moodfile) {
  144. while (($line = fgets($moodfile)) !== false) {
  145. /***
  146. * if date < cutoff stop adding
  147. */
  148. $cutoff = $date = strtotime(date("Y-m-d", strtotime("$ymd2 -0 day")));
  149.  
  150. $newpos = array();
  151. $newneg = array();
  152. $newcon = array();
  153. $newtag = array();
  154. $newstr = "";
  155.  
  156. $split1 = explode("[", $line);
  157. $split2 = explode("]", $split1[1]);
  158. $words = explode(" ", $split2[1]);
  159. foreach($words as $word){
  160. if($word <> ""){
  161. switch (mb_substr($word[0], 0, 1)) {
  162. case '+':
  163. $newpos[] = $word;
  164. break;
  165. case '-':
  166. $newneg[] = $word;
  167. break;
  168. case '@':
  169. $newcon[] = $word;
  170. break;
  171. case '#':
  172. $newtag[] = $word;
  173. break;
  174. default:
  175. $newstr .= " $word";
  176. break;
  177. }
  178. }
  179. }
  180.  
  181. $datetime = $split1[0];
  182. if(strtotime($datetime) < $cutoff)
  183. break;
  184. $justdate = date("Y-m-d", strtotime($datetime));
  185. if(strtotime($ymd2) == strtotime($justdate)){
  186. $count++;
  187. $mood = $split2[0];
  188. $fulldate = date("Y-m-d H:i", strtotime($datetime));
  189. $returnstring .= "<span class=\"datehist\">$fulldate</span>\n<span class=\"hpyhist\">[$mood]</span><span class=\"pretexthist\">$newstr</span>\n";
  190.  
  191. foreach($newpos as $pos)
  192. $returnstring .= "<span class=\"preposhist\" onclick=\"addFilterPos($(this).text());\">$pos</span>\n";
  193. foreach($newneg as $neg)
  194. $returnstring .= "<span class=\"preneghist\" onclick=\"addFilterNeg($(this).text());\">$neg</span>\n";
  195. foreach($newcon as $con)
  196. $returnstring .= "<span class=\"preconhist\" onclick=\"addFilterCon($(this).text());\">$con</span>\n";
  197. foreach($newtag as $tag)
  198. $returnstring .= "<span class=\"pretaghist\" onclick=\"addFilterTag($(this).text());\">$tag</span>\n";
  199. $returnstring .= "<br />";
  200. }
  201. }
  202. fclose($moodfile);
  203. return ($count > 0)? $returnstring : "0";
  204. } else {
  205. return "!ERROR! File: ".$moodfile." doesn't exist. !ERROR!<br />";
  206. }
  207. }
  208.  
  209. function main_cal(){
  210. global $moodlog;
  211. $toreturn = "";
  212. $moodfile = @fopen($moodlog, "r");
  213. if ($moodfile) {
  214. $newtimes = array();
  215. while (($line = fgets($moodfile)) !== false) {
  216. /***
  217. * if date < cutoff stop adding
  218. */
  219. $cutoff = $date = strtotime(date("Y-m-d", strtotime("-10 month")));
  220.  
  221. $split1 = explode("[", $line);
  222. $split2 = explode("]", $split1[1]);
  223.  
  224. $datetime = $split1[0];
  225. if(strtotime($datetime) < $cutoff)
  226. break;
  227.  
  228. $mood = $split2[0];
  229. //$justdate = date("Y-m-d", strtotime($datetime));
  230. //$dt2 = explode("-", $datetime);
  231. //$dtd = explode(" ", $dt2[2]);
  232. //$dateTime = new \DateTime(null, new DateTimeZone('Europe/London'));
  233. //$dateTime->setDate($dt2[0], $dt2[1], $dtd[0]);
  234. //$justdate = $dateTime->format('Y-m-d');
  235. $dtd = explode(" ", $datetime);
  236. $justdate = $dtd[0];
  237. if($mood != 0){
  238. $newtimes[$justdate][] = $mood;
  239. }
  240. }
  241. fclose($moodfile);
  242. foreach($newtimes as $date=>$md){
  243. $average = round(array_sum($md) / count($md));
  244. //$datetime = strtotime($date);
  245. $dt22 = explode("-", $date);
  246. $dtd2 = explode(" ", $dt22[2]);
  247. $dateTime = new \DateTime(null, new DateTimeZone('Europe/London'));
  248. $dateTime->setDate($dt22[0], $dt22[1], $dtd2[0]);
  249. $dateTime->setTime(12, 0, 0); // Set the time to 1am
  250. $justdate2 = $dateTime->getTimestamp();
  251.  
  252. $toreturn .= "\"$justdate2\":$average,";
  253. }
  254.  
  255. return substr($toreturn, 0, -1);
  256. } else {
  257. return "!ERROR! File: ".$moodfile." doesn't exist. !ERROR!<br />";
  258. }
  259. }
  260.  
  261. function filtered_cal($filter){
  262. global $moodlog;
  263. $toreturn = "";
  264.  
  265. $pattern = '/(?=[+-@][a-zA-Z0-9])/';
  266. $limit = -1;
  267. $flags = PREG_SPLIT_NO_EMPTY;
  268. $tags = preg_split ($pattern, $filter, $limit, $flags);
  269.  
  270. $moodfile = @fopen($moodlog, "r");
  271. if ($moodfile) {
  272. $newtimes = array();
  273. while (($line = fgets($moodfile)) !== false) {
  274. /***
  275. * if date < cutoff stop adding
  276. */
  277. $cutoff = $date = strtotime(date("Y-m-d", strtotime("-10 month")));
  278.  
  279. $split1 = explode("[", $line);
  280. $split2 = explode("]", $split1[1]);
  281.  
  282. $datetime = $split1[0];
  283. if(strtotime($datetime) < $cutoff)
  284. break;
  285.  
  286. $mood = $split2[0];
  287. $justdate = date("Y-m-d", strtotime($datetime));
  288.  
  289. $words = explode(" ", $split2[1]);
  290. foreach($words as $word){
  291. $word = trim($word);
  292. if (in_array($word, $tags, true))
  293. $newtimes[$justdate][] = $mood;
  294. }
  295. }
  296. fclose($moodfile);
  297. foreach($newtimes as $date=>$md){
  298. $average = round(array_sum($md) / count($md));
  299. $datetime = strtotime("$date");
  300. $toreturn .= "\"$datetime\":$average,";
  301. }
  302.  
  303. return substr($toreturn, 0, -1);
  304. } else {
  305. return "!ERROR! File: ".$moodfile." doesn't exist. !ERROR!<br />";
  306. }
  307. }
  308.  
  309. function day_avg($ymd){
  310. global $moodlog;
  311. $mood = array();
  312. $average = 0;
  313.  
  314. $moodfile = @fopen($moodlog, "r");
  315. //$date = date("Y-m-d", $ymd);
  316. //$date = date("Y-m-d", strtotime("$date +1 day"));
  317.  
  318. $dateTime = new \DateTime(null, new DateTimeZone('Europe/London'));
  319. $dateTime->setTimestamp($ymd);
  320. $date = $dateTime->format('Y-m-d');
  321. $date = date("Y-m-d", strtotime("$date"));
  322.  
  323. //$currentTime = new DateTime();
  324. //$currentTime = DateTime::createFromFormat( 'U', $ymd );
  325. //$date = $currentTime->format( 'c' );
  326.  
  327. $cutoff = strtotime("$date -0 day");
  328. //echo $date." cutoff: ".$cutoff;
  329. //$date = new DateTime();
  330. //$date->setTimestamp($ymd);
  331. //echo $date->format('U = Y-m-d H:i:s') . "\n";
  332.  
  333. if ($moodfile) {
  334. while (($line = fgets($moodfile)) !== false) {
  335.  
  336. $split1 = explode("[", $line);
  337. $split2 = explode("]", $split1[1]);
  338.  
  339. $datetime = $split1[0];
  340. if(strtotime($datetime) < $cutoff)
  341. break;
  342.  
  343. if(strncmp($date, $datetime, 10) == 0 )
  344. $mood[] = $split2[0];
  345. }
  346. // echo "$ymd ";
  347. // echo $date;
  348. // print_r($mood);
  349. if($mood)
  350. $average = round(array_sum($mood) / count($mood));
  351. return $average;
  352. } else {
  353. return "0";
  354. }
  355. }
  356.  
  357. function latest($tag){
  358. global $moodlog;
  359. $count = 0;
  360.  
  361. $newpos = array();
  362. $newneg = array();
  363. $newcon = array();
  364.  
  365. $moodfile = @fopen($moodlog, "r");
  366. if ($moodfile) {
  367. while (($line = fgets($moodfile)) !== false) {
  368.  
  369. $newstr = "";
  370.  
  371. $split1 = explode("[", $line);
  372. $split2 = explode("]", $split1[1]);
  373. $words = explode(" ", $split2[1]);
  374. foreach($words as $word){
  375. if($word <> ""){
  376. switch (mb_substr($word[0], 0, 1)) {
  377. case '+':
  378. $newpos[] = trim($word);
  379. break;
  380. case '-':
  381. $newneg[] = trim($word);
  382. break;
  383. case '@':
  384. $newcon[] = trim($word);
  385. break;
  386. }
  387. }
  388. }
  389.  
  390. }
  391. fclose($moodfile);
  392. switch ($tag) {
  393. case 'pos':
  394. $newpos = array_unique($newpos);
  395. $newArray = array_slice($newpos, 0, 5, false);
  396. break;
  397. case 'neg':
  398. $newneg = array_unique($newneg);
  399. $newArray = array_slice($newneg, 0, 5, false);
  400. break;
  401. case 'con':
  402. $newcon = array_unique($newcon);
  403. $newArray = array_slice($newcon, 0, 5, false);
  404. break;
  405. default:
  406. return 0;
  407. break;
  408. }
  409. return json_encode($newArray);
  410. } else {
  411. return "!ERROR! File: ".$moodfile." doesn't exist. !ERROR!<br />";
  412. }
  413. }
  414.  
  415. function toptag($tag){
  416. global $moodlog;
  417. $count = 0;
  418.  
  419. $newpos = array();
  420. $newneg = array();
  421. $newcon = array();
  422.  
  423. $moodfile = @fopen($moodlog, "r");
  424. if ($moodfile) {
  425. while (($line = fgets($moodfile)) !== false) {
  426.  
  427. $newstr = "";
  428.  
  429. $split1 = explode("[", $line);
  430. $split2 = explode("]", $split1[1]);
  431. $words = explode(" ", $split2[1]);
  432. foreach($words as $word){
  433. if($word <> ""){
  434. switch (mb_substr($word[0], 0, 1)) {
  435. case '+':
  436. $newpos[] = trim($word);
  437. break;
  438. case '-':
  439. $newneg[] = trim($word);
  440. break;
  441. case '@':
  442. $newcon[] = trim($word);
  443. break;
  444. }
  445. }
  446. }
  447.  
  448. }
  449. fclose($moodfile);
  450. switch ($tag) {
  451. case 'pos':
  452. $acv=array_count_values($newpos);
  453. arsort($acv);
  454. $result=array_keys($acv);
  455. $newArray = array_slice($result, 0, 5, false);
  456. break;
  457. case 'neg':
  458. $acv=array_count_values($newneg);
  459. arsort($acv);
  460. $result=array_keys($acv);
  461. $newArray = array_slice($result, 0, 5, false);
  462. break;
  463. case 'con':
  464. $acv=array_count_values($newcon);
  465. arsort($acv);
  466. $result=array_keys($acv);
  467. $newArray = array_slice($result, 0, 5, false);
  468. break;
  469. default:
  470. return 0;
  471. break;
  472. }
  473. return json_encode($newArray);
  474. } else {
  475. return "!ERROR! File: ".$moodfile." doesn't exist. !ERROR!<br />";
  476. }
  477. }
  478.  
  479. function alltag(){
  480. global $moodlog;
  481. $count = 0;
  482.  
  483. $newtag= array();
  484.  
  485. $moodfile = @fopen($moodlog, "r");
  486. if ($moodfile) {
  487. while (($line = fgets($moodfile)) !== false) {
  488.  
  489. $newstr = "";
  490.  
  491. $split1 = explode("[", $line);
  492. $split2 = explode("]", $split1[1]);
  493. $words = explode(" ", $split2[1]);
  494. foreach($words as $word){
  495. if($word <> ""){
  496. switch (mb_substr($word[0], 0, 1)) {
  497. case '+':
  498. $newtag[] = trim($word);
  499. break;
  500. case '-':
  501. $newtag[] = trim($word);
  502. break;
  503. case '@':
  504. $newtag[] = trim($word);
  505. break;
  506. }
  507. }
  508. }
  509. }
  510. fclose($moodfile);
  511. $acv=array_count_values($newtag);
  512. arsort($acv);
  513. $result=array_keys($acv);
  514. return json_encode($result);
  515. } else {
  516. return "!ERROR! File: ".$moodfile." doesn't exist. !ERROR!<br />";
  517. }
  518. }
  519.  
  520. function new_log($log){
  521. global $moodlog;
  522. $pattern = '/(?=[+-@|][a-zA-Z0-9])/';
  523. $limit = -1;
  524. $flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE;
  525. $result = preg_split ($pattern, $log, $limit, $flags);
  526. //print_r($result);
  527.  
  528. $timestamp = date("Y-m-d H:i");
  529. $no = rtrim($result[0], "|");
  530. $msg = "";
  531. $pos = "";
  532. $neg = "";
  533. $con = "";
  534.  
  535. foreach($result as $item){
  536. switch ($item[0]) {
  537. case '|':
  538. $msg .= substr($item, 1)." ";
  539. break;
  540. case '+':
  541. $pos .= "$item ";
  542. break;
  543. case '-':
  544. $neg .= "$item ";
  545. break;
  546. case '@':
  547. $con .= "$item ";
  548. break;
  549. }
  550. }
  551. $toadd = "$timestamp [$no] ".$msg.$pos.$neg.$con."\n";
  552. $toadd .= file_get_contents($moodlog);
  553. file_put_contents($moodlog, $toadd);
  554. echo "1";
  555. }
  556.  
  557. function getMyUrl(){
  558. $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
  559. $host = $_SERVER['HTTP_HOST'];
  560. $port = $_SERVER['SERVER_PORT'];
  561.  
  562. // Exclude standard ports to prevent redundancy in the URL
  563. if (($protocol === 'http' && $port != 80) || ($protocol === 'https' && $port != 443)) {
  564. $url = "$protocol://$host";
  565. } else {
  566. $url = "$protocol://$host";
  567. }
  568.  
  569. return $url;
  570. }
  571.  
  572. ?>
  573.  
  574. <html>
  575. <head>
  576.  
  577. <link rel="stylesheet" href="/deps/all.css" >
  578.  
  579. <script type="text/javascript" src="/deps/d3.v3.min.js"></script>
  580. <script type="text/javascript" src="/deps/cal-heatmap.min.js"></script>
  581. <link rel="stylesheet" href="/deps/cal-heatmap.css" />
  582.  
  583. <link href="/deps/google-fonts.css" rel="stylesheet">
  584. <link rel="stylesheet" href="/deps/jquery-ui.css">
  585. <link rel="stylesheet" href="/deps/fa.css">
  586. <script src="/deps/jquery-1.12.4.js"></script>
  587. <script src="/deps/jquery-ui.js"></script>
  588. <link rel="stylesheet" href="/style.css" >
  589.  
  590. <script src="/script.js"></script>
  591. <script src="/habit.js"></script>
  592. </head>
  593. <body>
  594. <center>
  595. <?php if($error <> ""){echo $error; } ?>
  596.  
  597. <div class="banner">
  598. <div class="header"><a href="/?logout"><i class="fas fa-heartbeat" ></i></a> moodlog.txt</div>
  599.  
  600. <div class="new-log">
  601. <input type="range" id="happyval" value="5" min="1" max="10"/>
  602. <input class="input" id="tags" placeholder="(+,-,@) description"/>
  603. <input type="button" value="+" onClick="updatePretext();"/>
  604. <input type="button" value="add" class="add" onClick="submitMood();"/>
  605. </div>
  606. <div class="preview">
  607. <span class="date">2018-09-11 20:27</span><span class="hpyno">[5]</span><span class="pretext" onClick="updatePretext();"></span></div>
  608.  
  609. <div class="filter" style="display:none">
  610. <span class="filtitle">Filters:</span>
  611. <span class="fas fa-search" style="float:right;font-size:15px;" onclick="applyFilters();"></span>
  612. </div>
  613. </div>
  614.  
  615. <div id="cal-heatmap"></div>
  616.  
  617. <div class="top10s">
  618. <div class="toppos">
  619. <div class="sub-header">Top 5 positive</div>
  620. </div>
  621. <div class="topneg">
  622. <div class="sub-header">Top 5 negative</div>
  623. </div>
  624. <div class="topcon">
  625. <div class="sub-header">Top 5 context</div>
  626. </div>
  627. <div class="latpos">
  628. <div class="sub-header">Latest 5 positive</div>
  629. </div>
  630. <div class="latneg">
  631. <div class="sub-header">Latest 5 negative</div>
  632. </div>
  633. <div class="latcon">
  634. <div class="sub-header">Latest 5 context</div>
  635. </div>
  636. </div>
  637.  
  638. <div class="fullday">
  639. <div class="previewhist">
  640. <?php
  641. $result = today(date("Y-m-d"));
  642. if($result != "0")
  643. echo $result;
  644. ?>
  645. </div>
  646. </div>
  647.  
  648. <div class="habit-main-title">Habits</div>
  649.  
  650. <div class="habit-container-wrapper">
  651.  
  652.  
  653. <?php
  654.  
  655. $fileContent = file_get_contents($habitlog);
  656. if ($fileContent === false) {
  657. die("Error reading the file.");
  658. }
  659. $resultArray = habit_parse_file($fileContent);
  660.  
  661. foreach ($resultArray as $section) {
  662. $align = "";
  663. $buttonClass = "";
  664. $buttText = "";
  665. if($section['Category'][0] == "d"){
  666.  
  667. $type = "day";
  668. $cat = "(daily)";
  669. if($section['Category'][1] == "+"){
  670. $align = "good";
  671. $calCol = "#58e81b";
  672. $title1 = "Streak";
  673. $title2 = "Missed";
  674. $title3 = "Top";
  675. $result1 = habit_get_stat_streak($section['Activity'], $moodlog);
  676. $result2 = habit_get_stat_missed($section['Activity'], $moodlog);
  677. $result3 = habit_get_stat_top($section['Activity'], $moodlog);
  678.  
  679. }
  680. if($section['Category'][1] == "-"){
  681. $align = "bad";
  682. $calCol = "#e81b1b";
  683. $title1 = "Streak";
  684. $title2 = "Total (Year)";
  685. $title3 = "Top";
  686. $result1 = habit_get_stat_missed($section['Activity'], $moodlog);
  687. $result2 = habit_get_stat_year($section['Activity'], $moodlog);
  688. $result3 = habit_get_stat_top_missing($section['Activity'], $moodlog);
  689. }
  690. $todayCheck = habit_check_daily($section['Activity'], $moodlog);
  691. if ($todayCheck) {
  692. $buttonClass = 'button-'.$align;
  693. }
  694. }
  695. if($section['Category'][0] == "w"){
  696. $multiplier = $section['Category'][1];
  697. $type = "week";
  698. $cat = "(weekly x $multiplier)";
  699. $align = "good";
  700. $title1 = "Streak";
  701. $title2 = "Missed";
  702. $title3 = "Top";
  703. $result1 = habit_get_stat_streak_week($section['Activity'], $multiplier, $moodlog);
  704. $result2 = habit_get_stat_missed_week($section['Activity'], $multiplier, $moodlog);
  705. $result3 = habit_get_stat_top_week($section['Activity'], $multiplier, $moodlog);
  706.  
  707. $todayCheck = habit_check_daily($section['Activity'], $moodlog);
  708. $weekCount = habit_count_weekly($section['Activity'], $moodlog);
  709.  
  710. if( $weekCount < $section['Category'][1] )
  711. if($todayCheck)
  712. $buttText = $weekCount;
  713. if($weekCount >= $multiplier)
  714. $buttonClass = 'button-done';
  715. if( $todayCheck ) {
  716. $buttonClass = 'button-neut';
  717. if($weekCount >= $multiplier)
  718. $buttonClass = 'button-good';
  719. }
  720.  
  721. }
  722. // for creating the calendar
  723. $calendar = "";
  724. if($type == "day"){
  725. $calendar = '<div id="habit-cal-'.$section['Activity'].'" class="habit-cal-day"></div>';
  726. }
  727. if($type == "week"){
  728. $weekCal = create_new_weekly_cal();
  729. $calendar = '<div id="habit-cal-'.$section['Activity'].'" class="habit-cal-week">'.$weekCal.'</div>';
  730. }
  731.  
  732. // echo "Category: {$section['Category']}<br />
  733. // <!--Value: {$section['Value']}<br />-->
  734. // Activity: {$section['Activity']}<br />
  735. // Description: {$section['Description']}<br />
  736. // $stats<br />
  737. // <br />";
  738. echo '
  739. <div class="habit-container" id="'.$section['Activity'].'">
  740. <div class="habit-log">
  741. <button class="habit-log-button '.$buttonClass.'" onClick="updateHabit(\''.$section['Activity'].'\')">'.$buttText.'</button>
  742. </div>
  743. <div class="'.$align.' habit-title">#'.$section['Activity'].' <div class="habit-timescale">'.$cat.'</div></div>
  744. <div class="habit-desc">'.$section['Description'].'</div>
  745. <div class="habit-score"><div class="score-title">'.$title1.'</div><div class="result1">'.$result1.'</div></div>
  746. <div class="habit-score"><div class="score-title">'.$title2.'</div><div class="result2">'.$result2.'</div></div>
  747. <div class="habit-score"><div class="score-title">'.$title3.'</div><div class="result3">'.$result3.'</div></div>
  748. '.$calendar.'
  749. </div>
  750. ';
  751. if($type == "day"){
  752. $urlToGet = getMyUrl();
  753. $urlToGet .= "/index.php?action=habit_cal_daily&habit=".$section['Activity'];
  754. echo ('
  755. <script>
  756. calHeatMapInstances[\''.$section['Activity'].'\'] = initializeDailyCalendar(\'#habit-cal-'.$section['Activity'].'\', {
  757. data: "'.$urlToGet.'",
  758. id: "'.$section['Activity'].'",
  759. legendColors: {
  760. min: "'.$calCol.'",
  761. max: "'.$calCol.'",
  762. },
  763. });
  764. </script>');
  765. }
  766. if($type == "week"){
  767. echo '<script>update_weekly_cal("'.$section['Activity'].'", '.$multiplier.');</script>';
  768. }
  769. }
  770.  
  771. ?>
  772.  
  773.  
  774.  
  775. </div>
  776. </div>
  777.  
  778. </center>
  779. </body>
  780. </html>
Buy Me A Coffee