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