Skip to content

Commit

Permalink
Add link to download all of your CourseRoad data as a JSON file
Browse files Browse the repository at this point in the history
  • Loading branch information
dannybd committed Jan 27, 2019
1 parent b976985 commit dcb9dbe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
24 changes: 24 additions & 0 deletions download.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

require 'functions.php';

$athena = $_SESSION['athena'];
isset($athena) or die('Sorry, please log in again.');

header('Content-type: text/javascript');
header('Content-Disposition: attachment; filename="courseroad.'.$athena.'.json"');

$data = array('athena' => $athena);
$data = $data + CourseRoadDB::getUserPrefs($athena);
$data['roads'] = array();

$roads = CourseRoadDB::getSavedRoads($athena);
foreach ($roads as $road) {
$road['classes'] = json_decode(CourseRoadDB::decrypt($road['classes']), true);
$road['majors'] = json_decode(CourseRoadDB::decrypt($road['majors']), true);
$data['roads'][] = $road;
}

echo json_encode($data);

die();
8 changes: 7 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@
<br>
<?php
if ($loggedin) {
echo "Hello, <strong>$athena</strong>! ";
echo <<<EOD
Hello, <strong>$athena</strong>!<br>
<br>
New:
<a href="download.php">click here</a>
to download all of your CourseRoad data.
EOD;
} else {
if (!$_SESSION['triedcert']) {
echo <<<EOD
Expand Down

0 comments on commit dcb9dbe

Please sign in to comment.