Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "simple_parse.php";
- function endsWith($haystack, $needle) {
- // search forward starting from end minus needle length characters
- return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
- }
- $htmlString = "<table border =1 style = 'border-spacing:0' class = 'table'>";
- $htmlString .= "<tr>";
- $htmlString .= "<th rowspan = '2'>#</th>";
- $htmlString .= "<th rowspan = '2'>ID</th>";
- $htmlString .= "<th rowspan = '2'>Trial Mode</th>";
- $htmlString .= "<th rowspan = '2'>Working BASELINE</th>";
- $htmlString .= "<th rowspan = '2'>Total Impairment Score</th>";
- $htmlString .= "<th rowspan = '2'>Breathalyzer Number</th>";
- $htmlString .= "<th rowspan = '2'>Impairment Type</th>";
- $htmlString .= "<th rowspan = '2'>Trial start time</th>";
- $htmlString .= "<th rowspan = '2'>Trial end time</th>";
- $htmlString .= "<th rowspan = '2'>T1ART</th>";
- $htmlString .= "<th rowspan = '2'>T1AED</th>";
- $htmlString .= "<th rowspan = '2'>T1PWS</th>";
- $htmlString .= "<th rowspan = '2'>T2AED</th>";
- //$htmlString .= "<th rowspan = '2'>T2PMC</th>";
- $htmlString .= "<th rowspan = '2'>T2ERRCT</th>";
- $htmlString .= "<th rowspan = '2'>T2ART</th>";
- $htmlString .= "<th rowspan = '2'>T2TIME</th>";
- $htmlString .= "<th rowspan = '2'>T3PERNOT</th>";
- $htmlString .= "<th rowspan = '2'>T3ERRCT</th>";
- $htmlString .= "<th rowspan = '2'>T4TOTAL</th>";
- $htmlString .= "<th rowspan = '2'>T4LEFT</th>";
- $htmlString .= "<th rowspan = '2'>T4RIGHT</th>";
- $htmlString .= "<th rowspan = '2'>Total Impairment</th>";
- $htmlString .= "<th colspan = '5'>Task1</th>";
- $htmlString .= "<th colspan = '6'>Task2</th>";
- $htmlString .= "<th colspan = '5'>Task3</th>";
- $htmlString .= "<th colspan = '3'>Task4</th>";
- $htmlString .= "<th rowspan = '2'>Device</th>";
- $htmlString .= "<th rowspan = '2'>DB ver</th>";
- $htmlString .= "</tr><tr>";
- $htmlString .= "<th>Reaction Time</th>";
- $htmlString .= "<th>Total Distance</th>";
- $htmlString .= "<th>Total Shapes</th>";
- $htmlString .= "<th>Wrong Shape Count</th>";
- $htmlString .= "<th>Total Screen Shapes</th>";
- $htmlString .= "<th>Missed Circles</th>";
- $htmlString .= "<th>Number you entered</th>";
- $htmlString .= "<th>Reaction Time</th>";
- $htmlString .= "<th>Total circles count</th>";
- $htmlString .= "<th>Your 60 seconds estimation</th>";
- $htmlString .= "<th>Total Error Distance</th>";
- $htmlString .= "<th>Number of squares that appeared</th>";
- $htmlString .= "<th>Number that player entered</th>";
- $htmlString .= "<th>Difference</th>";
- $htmlString .= "<th>Time for your finger in circle</th>";
- $htmlString .= "<th>Percentage</th>";
- $htmlString .= "<th>Total distance</th>";
- $htmlString .= "<th>Distance moved standing on LEFT leg</th>";
- $htmlString .= "<th>Distance moved standing on RIGHT leg</th>";
- $htmlString .= "</tr>";
- $servername = "localhost";
- $username = "druipelc_druid";
- $password = "PmDgTiFdAeUCyWeiDev822%";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password);
- // Check connection
- if (!$conn) {
- echo '{}'; exit;
- }
- mysqli_select_db($conn, 'druipelc_druid');
- $result = 0;
- if (isset($_POST['id']) && ctype_alnum($_POST['id']))
- $result = mysqli_query($conn, "select * from druid_data where PEOPLE_ID like '{$_POST['id']}' order by PEOPLE_ID, mode");
- else
- $result = mysqli_query($conn, "select * from druid_data order by PEOPLE_ID, mode");
- $no = 0;
- while ($row = mysqli_fetch_assoc($result))
- {
- $no++;
- $row['PEOPLE_DATA'] = json_decode($row['PEOPLE_DATA'], true);
- if ($row['PEOPLE_DATA'] == null) continue;
- if (!isset($row['device']) || $row['device'] == '') $row['device'] = '-';
- $row['PEOPLE_DATA']['Task1']['Reaction Time'] = str_replace('" ', '.', $row['PEOPLE_DATA']['Task1']['Reaction Time']);
- $row['PEOPLE_DATA']['Task1']['Total Distance'] = str_replace('"', '', $row['PEOPLE_DATA']['Task1']['Total Distance']);
- $row['PEOPLE_DATA']['Task2']['Reaction time'] = str_replace('"', '', $row['PEOPLE_DATA']['Task2']['Reaction time']);
- if (!endsWith($row['PEOPLE_DATA']['Task2']['Your 60 seconds estimation'], "slow"))
- $row['PEOPLE_DATA']['Task2']['Your 60 seconds estimation'] = str_replace('" fast', '', $row['PEOPLE_DATA']['Task2']['Your 60 seconds estimation']);
- else $row['PEOPLE_DATA']['Task2']['Your 60 seconds estimation'] = '-' . str_replace('" slow', '', $row['PEOPLE_DATA']['Task2']['Your 60 seconds estimation']);
- $row['PEOPLE_DATA']['Task3']['Time for your finger in circle'] = str_replace('"', '', $row['PEOPLE_DATA']['Task3']['Time for your finger in circle']);
- $row['PEOPLE_DATA']['Task3']['Percentage'] = str_replace('%', '', $row['PEOPLE_DATA']['Task3']['Percentage']);
- $row['PEOPLE_DATA']['Task2']['Total Error Distance'] = str_replace('"', '', $row['PEOPLE_DATA']['Task2']['Total Error Distance']);
- $row['PEOPLE_DATA']['Task4']['Total distance'] = str_replace('"', '', $row['PEOPLE_DATA']['Task4']['Total distance']);
- $row['PEOPLE_DATA']['Task4']['Distance moved standing on LEFT leg'] = str_replace('"', '', $row['PEOPLE_DATA']['Task4']['Distance moved standing on LEFT leg']);
- $row['PEOPLE_DATA']['Task4']['Distance moved standing on RIGHT leg'] = str_replace('"', '', $row['PEOPLE_DATA']['Task4']['Distance moved standing on RIGHT leg']);
- $T1ART = $row['PEOPLE_DATA']['Task1']['Reaction Time'] * 1.0 / $row['PEOPLE_DATA']['Task1']['Total shapes'];
- $T1AED = $row['PEOPLE_DATA']['Task1']['Total Screen Shapes'] == 0 ? 'NaN' : $row['PEOPLE_DATA']['Task1']['Total Distance'] * 1.0 / $row['PEOPLE_DATA']['Task1']['Total Screen Shapes'];
- $T1PWS = $row['PEOPLE_DATA']['Task1']['Wrong Shape Count'] * 1.0 / $row['PEOPLE_DATA']['Task1']['Total shapes'];
- $T2AED = $row['PEOPLE_DATA']['Task2']['Total Count of circles'] == 0? 'NaN' : $row['PEOPLE_DATA']['Task2']['Total Error Distance'] * 1.0 / $row['PEOPLE_DATA']['Task2']['Total Count of circles'];
- $T2PMC = 0;//$row['PEOPLE_DATA']['Task2']['Total Count of circles'] == 0? 'NaN' : $row['PEOPLE_DATA']['Task2']['Missed circles'] * 1.0 / $row['PEOPLE_DATA']['Task2']['Total Count of circles'];
- $T2ERRCT = abs($row['PEOPLE_DATA']['Task2']['Total Count of circles'] - $row['PEOPLE_DATA']['Task2']['Number (of circles) you entered']);
- $T2ART = $row['PEOPLE_DATA']['Task2']['Total Count of circles'] == 0? 'NaN' : $row['PEOPLE_DATA']['Task2']['Reaction time'] / $row['PEOPLE_DATA']['Task2']['Total Count of circles'];
- $T2TIME = abs($row['PEOPLE_DATA']['Task2']['Your 60 seconds estimation']);
- $T3PERNOT = 100 - $row['PEOPLE_DATA']['Task3']['Percentage'];
- $T3ERRCT = abs($row['PEOPLE_DATA']['Task3']['Difference']);
- $T4TOTAL = $row['PEOPLE_DATA']['Task4']['Total distance'];
- $T4LEFT = $row['PEOPLE_DATA']['Task4']['Distance moved standing on LEFT leg'];
- $T4RIGHT = $row['PEOPLE_DATA']['Task4']['Distance moved standing on RIGHT leg'];
- $htmlString .= "<tr><td>$no</td>";
- $htmlString .= "<td>{$row['PEOPLE_ID']}</td>";
- $htmlString .= "<td>{$row['mode']}</td>";
- if (isset($row['PEOPLE_DATA']['baselineScore']))
- $htmlString .= "<td>{$row['PEOPLE_DATA']['baselineScore']}</td>";
- else $htmlString .= "<td>-</td>";
- if (isset($row['PEOPLE_DATA']['totalScore']))
- $htmlString .= "<td>{$row['PEOPLE_DATA']['totalScore']}</td>";
- else $htmlString .= "<td>-</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Breathalyzer Number']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Impairment Type']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Start Time']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['End Time']}</td>";
- $htmlString .= "<td>$T1ART</td>";
- $htmlString .= "<td>$T1AED</td>";
- $htmlString .= "<td>$T1PWS</td>";
- $htmlString .= "<td>$T2AED</td>";
- // $htmlString .= "<td>$T2PMC</td>";
- $htmlString .= "<td>$T2ERRCT</td>";
- $htmlString .= "<td>$T2ART</td>";
- $htmlString .= "<td>$T2TIME</td>";
- $htmlString .= "<td>$T3PERNOT</td>";
- $htmlString .= "<td>$T3ERRCT</td>";
- $htmlString .= "<td>$T4TOTAL</td>";
- $htmlString .= "<td>$T4LEFT</td>";
- $htmlString .= "<td>$T4RIGHT</td>";
- $TOTALIMPAIRMENT = $T1ART + $T1AED + $T1PWS + $T2AED + $T2PMC + $T2ERRCT + $T2ARC + $T2TIME + $T3PERNOT + $T3ERRCT + $T4TOTAL + $T4LEFT + $T4RIGHT;
- $htmlString .= "<td>-</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task1']['Reaction Time']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task1']['Total Distance']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task1']['Total shapes']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task1']['Wrong Shape Count']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task1']['Total Screen Shapes']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task2']['Missed circles']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task2']['Number (of circles) you entered']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task2']['Reaction time']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task2']['Total Count of circles']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task2']['Your 60 seconds estimation']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task2']['Total Error Distance']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task3']['Number of squares that appeared']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task3']['Number that player entered']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task3']['Difference']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task3']['Time for your finger in circle']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task3']['Percentage']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task4']['Total distance']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task4']['Distance moved standing on LEFT leg']}</td>";
- $htmlString .= "<td>{$row['PEOPLE_DATA']['Task4']['Distance moved standing on RIGHT leg']}</td>";
- $htmlString .= "<td>{$row['device']}</td>";
- $htmlString .= "<td>{$row['version']}</td>";
- $htmlString .= "</tr>";
- }
- $htmlString .= "</table>";
- $cols = array('ID', 'Trial Mode', 'Working BASELINE', 'Total Impairment Score', 'Breathalyzer Number', 'Impairment Type', 'Date', 'Start Time', 'End Time', 'T1ART', 'T1AED', 'T1PWS', 'T2AED', /*'T2PMC',*/ 'T2ERRCT', 'T2ART', 'T2TIME', 'T3PERNOT', 'T3ERRCT', 'T4TOTAL', 'T4LEFT', 'T4RIGHT','Total Impairment', 'Reaction Time(Task1)', 'Total Distance(Task1)', 'Total Shapes(Task1)', 'Wrong Shapes Count(Task1)', 'Total Screen Shapes(Task1)',
- 'Missed Circles(Task2)', 'Number (of circles) you entered(Task2)', 'Reaction Time(Task2)', 'Total Count of Circles(Task2)', 'Your 60 seconds estimation(Task2)', 'Total Error Distance(Task2)',
- 'Number of squares that appeared(Task3)', 'Number that player entered(Task3)', 'Difference(Task3)', 'Time for your finger in circle(Task3)', 'Percentage(Task3)',
- 'Total Distance(Task4)', 'Distance moved standing on LEFT leg(Task4)', 'Distance moved standing on RIGHT leg(Task4)', 'Device', 'DB version');
- if (isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'export_to_csv' ) {
- $html = str_get_html($htmlString);
- header('Content-type: text/csv');
- header('Content-Disposition: attachment; filename=druid.csv');
- $fp = fopen("php://output", "w");
- fputcsv($fp, $cols);
- foreach($html->find('tr') as $rindex => $element)
- {
- if ($rindex < 2) continue;
- $td = array();
- $tdArray = $element->find('td');
- foreach($tdArray as $index => $row)
- {
- if ($index == 7)
- {
- $date_arr = explode(' ', $row->plaintext);
- $date_ele = explode('/', $date_arr[0]);
- $td[] = " {$date_ele[2]}-{$date_ele[0]}-{$date_ele[1]}";
- $td[] = $date_arr[1];
- }
- else if ($index == 8)
- {
- $date_arr = explode(' ', $row->plaintext);
- $td[] = $date_arr[1];
- }
- else if ($index > 0) {
- if ($index != sizeof($tdArray) - 2 && ($index == 3 || $index == 4 || $index == 5 || $index >= 9))
- $td[] = (float)($row->plaintext);
- else
- $td[] = $row->plaintext;
- }
- }
- if (sizeof($td) > 0) fputcsv($fp, $td);
- }
- fclose($fp);
- }
- else {
- ?>
- <head>
- <style type = 'text/css'>
- th, td
- {
- text-align:center !important;
- }
- th
- {
- background: #2980b9;
- border: 1px solid black;
- vertical-align:middle;
- color:white;
- }
- </style>
- <title>DRUID data</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
- <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
- </head>
- <body>
- <form method = 'post' action = ''>
- <label>Enter ID:</label>
- <input type = text name = 'id' value = '<?php echo $_POST['id']; ?>'>
- <button type = submit onclick = 'document.getElementById("submit").value = ""; '> Go </button>
- <button type = submit onclick = 'document.getElementById("submit").value = "export_to_csv"; '> Export to CSV </button>
- <input type = hidden name = 'submit' id = 'submit'>
- </form>
- <?php echo $htmlString; ?>
- </body>
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement