PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/public/index.php

https://github.com/RobertGonzalez/healthtracker
PHP | 793 lines | 746 code | 22 blank | 25 comment | 73 complexity | 33b8e85ba0d092ecd40c62c789028353 MD5 | raw file
  1. <?php
  2. /*
  3. Configuration
  4. */
  5. //ini_set('display_errors',1);
  6. //error_reporting(E_ALL);
  7. include("class/database.php");
  8. include("class/user.php");
  9. include("class/activeUser.php");
  10. session_start();
  11. $dbh=database::get_instance();
  12. if(!empty($_SESSION['activeUser']) && $_SESSION['activeUser'] instanceof activeUser && $_SESSION['activeUser']->online()){
  13. /* process all user forms here so no additional refreshes are needed.
  14. eventually move off page and ajax the entire thing.
  15. */
  16. if(isset($_POST['displayName'])){
  17. $displayName=$_POST['displayName'];
  18. $goalWeight=$_POST['goalWeight'];
  19. $public=$_POST['public'];
  20. $_SESSION['activeUser']->setGoalWeight($goalWeight);
  21. $_SESSION['activeUser']->setDisplayName($displayName);
  22. $_SESSION['activeUser']->setPublic($public);
  23. }
  24. if(isset($_POST['walkingExcercise'])){
  25. if($_POST['newDate']>''){
  26. $error=false;
  27. $date=explode("-",$_POST['newDate']);
  28. if(sizeof($date)!=3){
  29. $errorMsg[]="Please enter in a valid date.";
  30. $error=true;
  31. }
  32. if(!checkdate($date[1],$date[2],$date[0])){
  33. $errorMsg[]="Please enter in a valid date.";
  34. $error=true;
  35. }
  36. $date=implode("-",$date);
  37. $newWalking=(int)$_POST['newWalking'];
  38. $newJogging=(int)$_POST['newJogging'];
  39. $newRunning=(int)$_POST['newRunning'];
  40. if(!$error){
  41. $measurementEntries=$dbh->prepare("
  42. INSERT INTO `WalkingExcercise`(`userID`,`date`,`walking`,`jogging`,`running`)
  43. VALUES(:userID, :date, :walking, :jogging, :running)
  44. ");
  45. $measurementEntries->execute(array("userID" => $_SESSION['activeUser']->getUserID(),"date"=>$date,
  46. "walking"=>$newWalking,"jogging"=>$newJogging,"running"=>$newRunning));
  47. }
  48. }
  49. if(isset($_POST['id'])){
  50. //print_r($_POST);
  51. $count=sizeof($_POST['id']);
  52. for($i=0;$i<$count;$i++){
  53. $error=false;
  54. $id=(int)$_POST['id'][$i];
  55. $date=explode("-",$_POST['date'][$i]);
  56. if(sizeof($date)!=3){
  57. $errorMsg[]="Please enter in a valid date.";
  58. $error=true;
  59. }
  60. if(!checkdate($date[1],$date[2],$date[0])){
  61. $errorMsg[]="Please enter in a valid date.";
  62. $error=true;
  63. }
  64. $date=implode("-",$date);
  65. $newWalking=(int)$_POST['walking'][$i];
  66. $newJogging=(int)$_POST['jogging'][$i];
  67. $newRunning=(int)$_POST['running'][$i];
  68. if(!$error){
  69. $excerciseEntries=$dbh->prepare("
  70. UPDATE `WalkingExcercise`
  71. SET
  72. `date`= :date,
  73. `walking`= :walking,
  74. `jogging`= :jogging,
  75. `running`= :running
  76. WHERE `id`= :id
  77. ");
  78. $excerciseEntries->execute(array("date"=>$date,
  79. "walking"=>$newWalking,"jogging"=>$newJogging,"running"=>$newRunning,"id"=>$id));
  80. }
  81. }
  82. }
  83. }
  84. if(isset($_POST['deleteExcercise'])){
  85. $id=(int)$_POST['id'];
  86. $excerciseEntries=$dbh->prepare("DELETE FROM `WalkingExcercise` WHERE `id`= :id");
  87. $excerciseEntries->execute(array("id"=>$id));
  88. echo "true";
  89. die();
  90. }
  91. if(isset($_POST['weightEntries'])){
  92. if($_POST['newDate']>''){
  93. $error=false;
  94. $date=explode("-",$_POST['newDate']);
  95. if(sizeof($date)!=3){
  96. $errorMsg[]="Please enter in a valid date.";
  97. $error=true;
  98. }
  99. if(!checkdate($date[1],$date[2],$date[0])){
  100. $errorMsg[]="Please enter in a valid date.";
  101. $error=true;
  102. }
  103. $date=implode("-",$date);
  104. $newEntry=(float)$_POST['newEntry'];
  105. if(!$error){
  106. $weightEntries=$dbh->prepare("
  107. INSERT INTO `Weight`(`userID`,`date`,`entry`)
  108. VALUES(:userID, :date, :entry)
  109. ");
  110. $weightEntries->execute(array("userID" => $_SESSION['activeUser']->getUserID(),"date"=>$date,
  111. "entry"=>$newEntry));
  112. }
  113. }
  114. if(isset($_POST['id'])){
  115. //print_r($_POST);
  116. $count=sizeof($_POST['id']);
  117. for($i=0;$i<$count;$i++){
  118. $error=false;
  119. $id=(int)$_POST['id'][$i];
  120. $date=explode("-",$_POST['date'][$i]);
  121. if(sizeof($date)!=3){
  122. $errorMsg[]="Please enter in a valid date.";
  123. $error=true;
  124. }
  125. if(!checkdate($date[1],$date[2],$date[0])){
  126. $errorMsg[]="Please enter in a valid date.";
  127. $error=true;
  128. }
  129. $date=implode("-",$date);
  130. $entry=(float)$_POST['entry'][$i];
  131. if(!$error){
  132. $weightEntries=$dbh->prepare("
  133. UPDATE `Weight`
  134. SET
  135. `date`= :date,
  136. `entry`= :entry
  137. WHERE `id`= :id
  138. ");
  139. $weightEntries->execute(array("id" => $id,"date"=>$date,
  140. "entry"=>$entry));
  141. }
  142. }
  143. }
  144. }
  145. if(isset($_POST['deleteWeight'])){
  146. $id=(int)$_POST['id'];
  147. $excerciseEntries=$dbh->prepare("DELETE FROM `Weight` WHERE `id`= :id");
  148. $excerciseEntries->execute(array("id"=>$id));
  149. echo "true";
  150. die();
  151. }
  152. if(isset($_POST['measurements'])){
  153. if($_POST['newDate']>''){
  154. $error=false;
  155. $date=explode("-",$_POST['newDate']);
  156. if(sizeof($date)!=3){
  157. $errorMsg[]="Please enter in a valid date.";
  158. $error=true;
  159. }
  160. if(!checkdate($date[1],$date[2],$date[0])){
  161. $errorMsg[]="Please enter in a valid date.";
  162. $error=true;
  163. }
  164. $date=implode("-",$date);
  165. $newChest=(float)$_POST['newChest'];
  166. $newWaist=(float)$_POST['newWaist'];
  167. $newHips=(float)$_POST['newHips'];
  168. $newArm=(float)$_POST['newArm'];
  169. $newLeg=(float)$_POST['newLeg'];
  170. if(!$error){
  171. $weightEntries=$dbh->prepare("
  172. INSERT INTO `Measurements`(`userID`,`date`,`chest`,`waist`,`hips`,`arm`,`leg`)
  173. VALUES(:userID, :date, :chest, :waist, :hips, :arm, :leg)");
  174. $weightEntries->execute(array("userID" => $_SESSION['activeUser']->getUserID(),"date"=>$date,
  175. "chest"=>$newChest,"waist"=>$newWaist,"hips"=>$newHips,"arm"=>$newArm,"leg"=>$newLeg));
  176. }
  177. }
  178. if(isset($_POST['id'])){
  179. //print_r($_POST);
  180. $count=sizeof($_POST['id']);
  181. for($i=0;$i<$count;$i++){
  182. $error=false;
  183. $id=(int)$_POST['id'][$i];
  184. $date=explode("-",$_POST['date'][$i]);
  185. if(sizeof($date)!=3){
  186. $errorMsg[]="Please enter in a valid date.";
  187. $error=true;
  188. }
  189. if(!checkdate($date[1],$date[2],$date[0])){
  190. $errorMsg[]="Please enter in a valid date.";
  191. $error=true;
  192. }
  193. $date=implode("-",$date);
  194. $entry=(float)$_POST['entry'][$i];
  195. $chest=(float)$_POST['chest'][$i];
  196. $waist=(float)$_POST['waist'][$i];
  197. $hips=(float)$_POST['hips'][$i];
  198. $arm=(float)$_POST['arm'][$i];
  199. $leg=(float)$_POST['leg'][$i];
  200. if(!$error){
  201. $measurementsEntries=$dbh->prepare("
  202. UPDATE `Measurements`
  203. SET
  204. `date`= :date,
  205. `chest`= :chest,
  206. `waist`= :waist,
  207. `hips`= :hips,
  208. `arm`= :arm,
  209. `leg`= :leg
  210. WHERE `id`= :id
  211. ");
  212. $measurementsEntries->execute(array("id" => $id,"date"=>$date,
  213. "chest"=>$chest,"waist" => $waist,"hips" => $hips,"arm" => $arm,"leg" => $leg));
  214. }
  215. }
  216. }
  217. }
  218. if(isset($_POST['deleteMeasurements'])){
  219. $id=(int)$_POST['id'];
  220. $measurementsEntries=$dbh->prepare("DELETE FROM `Measurements` WHERE `id`= :id");
  221. $measurementsEntries->execute(array("id"=>$id));
  222. echo "true";
  223. die();
  224. }
  225. }
  226. if(!isset($_SESSION['activeUser'])){
  227. $_SESSION['activeUser']=null;
  228. }
  229. if(isset($_GET['logout'])){
  230. $_SESSION['activeUser']=null;
  231. }
  232. if((isset($_GET['login']) && ($_SESSION['activeUser']==null)) || (isset($_GET['state']) && $_GET['state'])){
  233. $app_id = "315302831857063";
  234. $app_secret = "7194e1b0ba11c5d02d8be698565251d9";
  235. $my_url = "http://www.charlesdthompson.com/weight/index.php";
  236. $code = $_REQUEST["code"];
  237. if(empty($code)) {
  238. $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
  239. $dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
  240. . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
  241. . $_SESSION['state'];
  242. echo("<script> top.location.href='" . $dialog_url . "'</script>");
  243. }
  244. if($_REQUEST['state'] == $_SESSION['state']) {
  245. $token_url = "https://graph.facebook.com/oauth/access_token?"
  246. . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
  247. . "&client_secret=" . $app_secret . "&code=" . $code;
  248. $response = @file_get_contents($token_url);
  249. $params = null;
  250. parse_str($response, $params);
  251. $graph_url = "https://graph.facebook.com/me?access_token="
  252. . $params['access_token'];
  253. $fbInfo = json_decode(file_get_contents($graph_url));
  254. // the below line registers this person if they are not , otherwise it just logs them in.
  255. $_SESSION['activeUser']=new activeUser(
  256. $fbInfo->id,
  257. $fbInfo->link,
  258. $fbInfo->name,$params->access_token,$fbInfo->username
  259. );
  260. header('Location: index.php');
  261. //print_r($_SESSION);
  262. }
  263. else {
  264. echo("The state does not match. You may be a victim of CSRF.");
  265. }
  266. }
  267. if(!isset($_GET['id'])){
  268. if($_SESSION['activeUser']!=null){
  269. $_GET['id']=$_SESSION['activeUser']->getUserID();
  270. }else{
  271. $_GET['id']=1;
  272. }
  273. }
  274. $user=user::get_instance($_GET['id']);
  275. if(!$user->getInitializationFailed()){
  276. $modules=array("Weight","WalkingExcercise","Measurements");
  277. $fields=array(
  278. "Weight" => array("Date" => "date","Weight in Lbs" => "entry"),
  279. "WalkingExcercise" => array("Date" => "date","Walking" => "walking","Jogging" => "jogging","Running" => "running"),
  280. "Measurements"=>
  281. array("Date" => "date", "Chest" => "chest", "Waist" => "waist", "Hips" => "hips",
  282. "Arm" => "arm", "Leg" => "leg"
  283. )
  284. );
  285. foreach($modules as $name){
  286. $selectFields=implode(",",$fields[$name]);
  287. $$name=$dbh->prepare("SELECT $selectFields FROM $name WHERE `userID` = :userID");
  288. }reset($modules);
  289. $getLabels=$dbh->prepare("SELECT `label`,`chartType` FROM `labels` WHERE `table`= :table");
  290. }
  291. ?>
  292. <!doctype html>
  293. <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
  294. <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
  295. <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
  296. <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
  297. <head>
  298. <meta charset="utf-8">
  299. <title></title>
  300. <meta name="description" content="">
  301. <style type="text/css">
  302. #content{
  303. width:990px;
  304. margin:0 auto;
  305. background:beige;
  306. height:100%;
  307. }
  308. #controls{
  309. text-align:center;
  310. padding:10px;
  311. }
  312. #userTab{
  313. display:none;
  314. }
  315. #ui-datepicker-div{
  316. display:none;
  317. }
  318. html,body{
  319. height:100%;
  320. margin:0;
  321. }
  322. <?php
  323. if(sizeof($modules)>0){
  324. foreach($modules as $name){
  325. ?>
  326. #<?php echo $name;?>Container{
  327. width:49% !important;
  328. float:left;
  329. }
  330. #<?php echo $name;?>Table_length{
  331. display:none !important;
  332. }
  333. #<?php echo $name;?>Chart{
  334. margin-top:10px;
  335. float:right;
  336. width:49%;
  337. }
  338. <?php
  339. }reset($modules);
  340. }
  341. ?>
  342. .fb-login-button{
  343. padding:5px;
  344. text-align:right;
  345. }
  346. </style>
  347. <meta name="viewport" content="width=device-width">
  348. <link rel="stylesheet" href="css/style.css">
  349. <script src="js/libs/modernizr-2.5.3.min.js"></script>
  350. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  351. <script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script><script type="text/javascript" src="js/dataTables.js"></script>
  352. <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js"></script>
  353. <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" />
  354. <?php include 'testing/php-ofc-library/open-flash-chart.php'; ?>
  355. <script type="text/javascript">
  356. $(document).ready(function() {
  357. <?php
  358. if(sizeof($modules)>0){
  359. foreach($modules as $name){?>
  360. $('#<?php echo $name; ?>Table').dataTable( {
  361. "sPaginationType": "full_numbers",
  362. "iDisplayLength": 7
  363. } );
  364. <?php }reset($modules);}?>
  365. $("#viewGraphs").click(function(event) {
  366. event.preventDefault();
  367. $('#userTab').hide();
  368. $('.chart').show();
  369. $('object').show();
  370. $('hr').show();
  371. });
  372. $("#enterData").click(function(event) {
  373. event.preventDefault();
  374. $('.chart').hide();
  375. $('object').hide();
  376. $('hr').hide();
  377. $('#userTab').show();
  378. });
  379. <?php
  380. if($_SESSION['activeUser']!=null && $_SESSION['activeUser']->newUser()){
  381. ?>
  382. $('.chart').hide();
  383. $('object').hide();
  384. $('hr').hide();
  385. $('#userTab').show();
  386. <?php
  387. }
  388. ?>
  389. $( ".date" ).datepicker();
  390. $( ".date" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
  391. $('.date').each(function(index,element){
  392. $(this).val($(this).attr('rel'));
  393. });
  394. $(".deleteExcercise").click(function(event){
  395. event.preventDefault();
  396. var deleteID=$(this).parent().parent().attr('id');
  397. $.post("index2.php", { deleteExcercise: "true", id: deleteID },function(data){
  398. window.location.reload();
  399. } );
  400. });
  401. $(".deleteWeight").click(function(event){
  402. event.preventDefault();
  403. var deleteID=$(this).parent().parent().attr('id');
  404. $.post("index2.php", { deleteWeight: "true", id: deleteID },function(data){
  405. window.location.reload();
  406. } );
  407. });
  408. //
  409. $(".deleteMeasurements").click(function(event){
  410. event.preventDefault();
  411. var deleteID=$(this).parent().parent().attr('id');
  412. $.post("index2.php", { deleteMeasurements: "true", id: deleteID },function(data){
  413. window.location.reload();
  414. } );
  415. });
  416. } );
  417. </script>
  418. <?php
  419. include("class/function.generateChartData.php");
  420. if(sizeof($modules)>0){
  421. foreach($modules as $module){
  422. $$module=get_chart_data($module,$fields[$module],$$module,$getLabels);
  423. }
  424. }
  425. ?>
  426. <script type="text/javascript" src="testing/swfobject.js"></script>
  427. <script type="text/javascript">
  428. <?php
  429. if(sizeof($modules)>0){
  430. foreach($modules as $module){
  431. echo "
  432. swfobject.embedSWF('testing/open-flash-chart.swf', '".$module."Chart', '350', '320', '9.0.0', 'expressInstall.swf',{'get-data':'get_$module'});
  433. ";
  434. }
  435. }
  436. ?>
  437. function ofc_ready(){}
  438. function findSWF(movieName) {
  439. if (navigator.appName.indexOf("Microsoft")!= -1) {
  440. return window[movieName];
  441. } else {
  442. return document[movieName];
  443. }
  444. }
  445. <?php
  446. if(sizeof($modules)>0){
  447. foreach($modules as $module){
  448. $result=$$module;
  449. echo "var $module = ".$result.";";
  450. echo "
  451. function get_$module(){
  452. return JSON.stringify($module)
  453. }";
  454. }
  455. }
  456. ?>
  457. </script>
  458. </head>
  459. <body>
  460. <!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->
  461. <header>
  462. </header>
  463. <div id="content">
  464. <?php
  465. if($_SESSION['activeUser']!=null && $_SESSION['activeUser']->online()){
  466. ?>
  467. <div id="controls">
  468. <a href="" id="viewGraphs">View Graphs</a> | <a href="" id="enterData">Enter Data</a> | <a href="?logout">Logout</a>
  469. </div>
  470. <div id="userTab">
  471. <form name="basicUserInfo" method="POST">
  472. Greetings <input type="text" name="displayName" value="<?php echo htmlentities($_SESSION['activeUser']->getDisplayName());?>" size="20" />. Your goal weight is currently
  473. listed at <input type="text" name="goalWeight" size="5" value="<?php echo htmlentities($_SESSION['activeUser']->getGoalWeight());?>" /> lbs. In addition,
  474. your profile is currently set to
  475. <select name="public">
  476. <option value="0" <?php if($_SESSION['activeUser']->getPublic()<1){ echo "selected='selected'";} ?>>Hidden</option>
  477. <option value="1" <?php if($_SESSION['activeUser']->getPublic()>0){ echo "selected='selected'";} ?>>Public</option>
  478. </select>. <input type="submit" value="Update Settings" />
  479. </form>
  480. <div style="float: left;margin-right:20px;" style="width: 48%;">
  481. <form name="excerciseEntries" method="POST">
  482. <table>
  483. <thead>
  484. <th>
  485. Date
  486. </th>
  487. <th>
  488. Walking In Seconds
  489. </th>
  490. <th>
  491. Jogging
  492. </th>
  493. <th>
  494. Running
  495. </th>
  496. <th></th>
  497. </thead>
  498. <tr>
  499. <td colspan="5">
  500. <div style="text-align: right;">
  501. <input type="submit" name="walkingExcercise" value="Add/Edit Records" />
  502. </div>
  503. </td>
  504. </tr>
  505. <tr>
  506. <td>
  507. <input type="text" name="newDate" size="10" class="date" value="" />
  508. </td>
  509. <td>
  510. <input type="text" name="newWalking" size="10" value="" />
  511. </td>
  512. <td>
  513. <input type="text" name="newJogging" size="10" value="" />
  514. </td>
  515. <td>
  516. <input type="text" name="newRunning" size="10" value="" />
  517. </td>
  518. <td>
  519. </td>
  520. </tr>
  521. <?php
  522. $excerciseEntries=$dbh->prepare("SELECT `id`,`date`,`walking`,`jogging`,`running` FROM `WalkingExcercise` WHERE `userID` = :userID ORDER BY `date` DESC");
  523. $excerciseEntries->execute(array("userID" => $_SESSION['activeUser']->getUserID()));
  524. foreach($excerciseEntries->fetchAll(PDO::FETCH_CLASS) as $entry){
  525. ?>
  526. <tr id="<?php echo $entry->id;?>">
  527. <td>
  528. <input type="hidden" name="id[]" value="<?php echo $entry->id;?>" />
  529. <input type="text" class="date" name="date[]" size="10" value="<?php echo $entry->date;?>" rel="<?php echo $entry->date;?>" />
  530. </td>
  531. <td>
  532. <input type="text" name="walking[]" size="10" value="<?php echo $entry->walking;?>" />
  533. </td>
  534. <td>
  535. <input type="text" name="jogging[]" size="10" value="<?php echo $entry->jogging;?>" />
  536. </td>
  537. <td>
  538. <input type="text" name="running[]" size="10" value="<?php echo $entry->running;?>" />
  539. </td>
  540. <td>
  541. <a class="deleteExcercise" href="">Delete Entry</a>
  542. </td>
  543. </tr>
  544. <?php
  545. }
  546. ?>
  547. </table>
  548. </form>
  549. </div>
  550. <div style="float: left;margin-left:20px;" style="width: 48%;">
  551. <form name="weightEntries" method="POST">
  552. <table>
  553. <thead>
  554. <th>
  555. Date
  556. </th>
  557. <th>
  558. Entry in Lbs
  559. </th>
  560. <th></th>
  561. </thead>
  562. <tr>
  563. <td colspan="3">
  564. <div style="text-align: right;">
  565. <input type="submit" name="weightEntries" value="Add/Edit Records" />
  566. </div>
  567. </td>
  568. </tr>
  569. <tr>
  570. <td>
  571. <input type="text" name="newDate" size="10" class="date" value="" />
  572. </td>
  573. <td>
  574. <input type="text" name="newEntry" size="10" value="" />
  575. </td>
  576. <td>
  577. </td>
  578. </tr>
  579. <?php
  580. $weightEntries=$dbh->prepare("SELECT `id`,`date`,`entry` FROM `Weight` WHERE `userID` = :userID ORDER BY `date` DESC");
  581. $weightEntries->execute(array("userID" => $_SESSION['activeUser']->getUserID()));
  582. foreach($weightEntries->fetchAll(PDO::FETCH_CLASS) as $entry){
  583. ?>
  584. <tr id="<?php echo $entry->id;?>">
  585. <td>
  586. <input type="hidden" name="id[]" value="<?php echo $entry->id;?>" />
  587. <input type="text" class="date" name="date[]" size="10" value="<?php echo $entry->date;?>" rel="<?php echo $entry->date;?>" />
  588. </td>
  589. <td>
  590. <input type="text" name="entry[]" size="10" value="<?php echo $entry->entry;?>" />
  591. </td>
  592. <td>
  593. <a class="deleteWeight" href="">Delete Entry</a>
  594. </td>
  595. </tr>
  596. <?php
  597. }
  598. ?>
  599. </table>
  600. </form>
  601. </div>
  602. <br style="clear: both;" />
  603. <div style="float: left;" style="width: 48%;">
  604. <form name="measurementEntries" method="POST">
  605. <table>
  606. <thead>
  607. <th>
  608. Date
  609. </th>
  610. <th>
  611. Chest in Inches
  612. </th>
  613. <th>
  614. Waist
  615. </th>
  616. <th>
  617. Hips
  618. </th>
  619. <th>
  620. Left Arm
  621. </th>
  622. <th>
  623. Left Leg
  624. </th>
  625. <th></th>
  626. </thead>
  627. <tr>
  628. <td colspan="7">
  629. <div style="text-align: right;">
  630. <input type="submit" name="measurements" value="Add/Edit Records" />
  631. </div>
  632. </td>
  633. </tr>
  634. <tr>
  635. <td>
  636. <input type="text" name="newDate" size="10" class="date" value="" />
  637. </td>
  638. <td>
  639. <input type="text" name="newChest" size="10" value="" />
  640. </td>
  641. <td>
  642. <input type="text" name="newWaist" size="10" value="" />
  643. </td>
  644. <td>
  645. <input type="text" name="newHips" size="10" value="" />
  646. </td>
  647. <td>
  648. <input type="text" name="newArm" size="10" value="" />
  649. </td>
  650. <td>
  651. <input type="text" name="newLeg" size="10" value="" />
  652. </td>
  653. <td>
  654. </td>
  655. </tr>
  656. <?php
  657. $measurementEntries=$dbh->prepare("SELECT `id`,`date`,`chest`,`waist`,`hips`,`arm`,`leg` FROM `Measurements` WHERE `userID` = :userID ORDER BY `date` DESC");
  658. $measurementEntries->execute(array("userID" => $_SESSION['activeUser']->getUserID()));
  659. foreach($measurementEntries->fetchAll(PDO::FETCH_CLASS) as $entry){
  660. ?>
  661. <tr id="<?php echo $entry->id;?>">
  662. <td>
  663. <input type="hidden" name="id[]" value="<?php echo $entry->id;?>" />
  664. <input type="text" class="date" name="date[]" size="10" value="<?php echo $entry->date;?>" rel="<?php echo $entry->date;?>" />
  665. </td>
  666. <td>
  667. <input type="text" name="chest[]" size="10" value="<?php echo $entry->chest;?>" />
  668. </td>
  669. <td>
  670. <input type="text" name="waist[]" size="10" value="<?php echo $entry->waist;?>" />
  671. </td>
  672. <td>
  673. <input type="text" name="hips[]" size="10" value="<?php echo $entry->hips;?>" />
  674. </td>
  675. <td>
  676. <input type="text" name="arm[]" size="10" value="<?php echo $entry->arm;?>" />
  677. </td>
  678. <td>
  679. <input type="text" name="leg[]" size="10" value="<?php echo $entry->leg;?>" />
  680. </td>
  681. <td>
  682. <a class="deleteMeasurements" href="">Delete Entry</a>
  683. </td>
  684. </tr>
  685. <?php
  686. }
  687. ?>
  688. </table>
  689. </form>
  690. </div>
  691. <br style="clear: both;" />
  692. </div>
  693. <?php
  694. }
  695. else{
  696. ?>
  697. <div class="fb-login-button"><a href="?login">Login with Facebook</a></div>
  698. <?php
  699. }
  700. if($user->getInitializationFailed()){
  701. echo "<p>The user you are trying to view does not appear to be valid.</p>";
  702. }
  703. if(sizeof($modules)){
  704. foreach($modules as $name){
  705. //if($count%3==0){break;}
  706. ?>
  707. <div id="<?php echo $name;?>Container" class="chart" width="50%">
  708. <table id="<?php echo $name; ?>Table" width="100%" class="<?php echo $name; ?>Table">
  709. <thead>
  710. <tr>
  711. <?php
  712. foreach($fields[$name] as $index => $value){
  713. ?>
  714. <th style="padding-top: 20px;">
  715. <?php echo $index; ?>
  716. </th>
  717. <?php
  718. if(!isset($values))$values=json_decode($$name);
  719. }
  720. ?>
  721. </tr>
  722. </thead>
  723. <tbody>
  724. <?php
  725. $i=0;
  726. /* todo: show in descending order on date */
  727. foreach($values->x_axis->labels->labels as $date){
  728. ?>
  729. <tr>
  730. <td style="text-align: center;">
  731. <?php echo $date;?>
  732. </td>
  733. <?php
  734. $columns=$values->elements[0]->values[$i];
  735. if(is_array($columns)){
  736. foreach($columns as $value){
  737. if(is_numeric($value))echo "<td style='text-align: center;'>$value</td>";
  738. //print_r($value);
  739. //echo"</td>";
  740. }
  741. }else{
  742. if($name=="Measurements"){
  743. for($y=0;$y<sizeof($values->elements);$y++){
  744. if(isset($values->elements[$y]->values[$i]) && is_numeric($values->elements[$y]->values[$i]))echo "<td style='text-align: center;'>".$values->elements[$y]->values[$i]."</td>";
  745. }
  746. }else{
  747. echo "<td style='text-align: center;'>$columns</td>";
  748. }
  749. }
  750. ?>
  751. </tr>
  752. <?php
  753. $i++;
  754. }
  755. unset($values);
  756. ?>
  757. </tbody>
  758. </table>
  759. </div>
  760. <div id="<?php echo $name;?>Chart" class="chart"></div>
  761. <br style="clear: both;" />
  762. <hr />
  763. <?php //$count++;
  764. }
  765. }
  766. ?>
  767. </div>
  768. <footer>
  769. </footer>
  770. </body>
  771. </html>