Skip to content

Commit d84a6bd

Browse files
committed
Starting refactor in to a single page app.
- This commit basically changes the entire file structure of how schedulemaker looks and is deployed. - AngularJS and UI-router will be doing all the routing on the front-end. - nodejs with gulpjs for the asset pipeline - Various js code/php code refactoring to support new system
1 parent 98e4c9a commit d84a6bd

23 files changed

+834
-1192
lines changed

.gitignore

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
# Ignore PhpStorm files
2-
.idea
1+
#### PROJECT IGNORES ####
32

43
# Ignore configuration files
54
inc/config.php
65

76
# Ignore schedule images
87
img/schedules/*.png
98

9+
# Ignore node_modules dependencies
10+
node_modules/*
11+
12+
# Ignore built files
13+
assets/build/*
14+
!assets/build/.gitkeep
15+
16+
#### EDITOR IGNORES####
17+
18+
# Ignore PhpStorm files
19+
.idea
20+
1021
# Ignore Eclipse files
1122
.settings
1223
.project
1324
.buildpath
1425

1526
# Ignore VisualStudio files
16-
/*.phpproj*
17-
/*.sln
18-
/*.suo
19-
/WebEssentials-Settings.json
27+
*.phpproj*
28+
*.sln
29+
*.suo
30+
WebEssentials-Settings.json

.htaccess

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
11
RewriteEngine On
2-
RewriteRule ^schedule/([^/]*)(?:/([^/]*))?$ /schedule.php?id=$1&mode=$2 [L]
2+
3+
#Legacy Rewrites
4+
RewriteCond %{QUERY_STRING} ^id=(.*)$ [NC]
5+
RewriteRule ^schedule.php$ /schedule/%1? [NC,L,R=301]
6+
7+
RewriteRule ^index.php$ / [L,R=301]
8+
RewriteRule ^generate.php$ /generate [L,R=301]
9+
RewriteRule ^browse.php$ /browse [L,R=301]
10+
RewriteRule ^roulette.php$ /search [L,R=301]
11+
12+
13+
# Let old ScheduleMaker handle Resig's schedules for now
14+
RewriteCond %{QUERY_STRING} ^mode=old&id=(.*)$ [NC]
15+
RewriteRule ^schedule.php$ http://schedule-old.csh.rit.edu/schedule.php [NC,L,R=301]
16+
17+
RewriteCond %{REQUEST_FILENAME} !-d
18+
RewriteCond %{REQUEST_FILENAME}\.php -f
19+
RewriteRule ^api/([^/]*)(?:/([^/]*))*$ api/$1.php [L]
20+
21+
# Don't rewrite files or directories
22+
RewriteCond %{REQUEST_FILENAME} -f [OR]
23+
RewriteCond %{REQUEST_FILENAME} -d
24+
RewriteRule ^ - [L]
25+
26+
# Rewrite everything else to index.html to allow html5 state links
27+
RewriteRule ^ index.php [L]

schedule.php renamed to api/schedule.php

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
////////////////////////////////////////////////////////////////////////////
1010

1111
// REQUIRED FILES //////////////////////////////////////////////////////////
12-
require_once('./inc/config.php');
13-
require_once('./inc/databaseConn.php');
14-
require_once('./inc/timeFunctions.php');
12+
require_once('../inc/config.php');
13+
require_once('../inc/databaseConn.php');
14+
require_once('../inc/timeFunctions.php');
1515

1616
// FUNCTIONS ///////////////////////////////////////////////////////////////
1717

@@ -190,80 +190,15 @@ function queryOldId($id) {
190190

191191
// MAIN EXECUTION //////////////////////////////////////////////////////////
192192

193+
$path = explode('/', $_SERVER['REQUEST_URI']);
194+
195+
$id = (empty($path[3]))? '': hexdec($path[3]);
193196
// Determine the output mode
194-
$mode = (empty($_REQUEST['mode'])) ? "schedule" : $_REQUEST['mode'];
197+
$mode = (empty($path[4])) ? "json" : $path[4];
198+
195199

196200
// Switch on the mode
197201
switch($mode) {
198-
case "print":
199-
// PRINTABLE SCHEDULE //////////////////////////////////////////////
200-
// No header, no footer, just the schedule
201-
202-
$LAYOUT_MODE = 'print';
203-
require "./inc/header.inc";
204-
205-
if($_GET['id'] != 'render') {
206-
$id = hexdec($_GET['id']);
207-
if($id > 0) {
208-
$schedule = getScheduleFromId($id);
209-
// Translate the schedule into json
210-
$json = json_encode($schedule);
211-
212-
?>
213-
<script>var reloadSchedule = <?=$json?>;</script>
214-
<?
215-
}
216-
}
217-
?>
218-
<div ng-controller="printScheduleCtrl">
219-
<div class="container hidden-print" ng-show="schedule.length > 0">
220-
<div class="vert-spacer-static-md"></div>
221-
<div class="panel panel-default">
222-
<div class="panel-heading">
223-
<h3 class="panel-title">Print Options <small>For best results, print landscape, turn off headings/footers, and set the margins to .25"</small></h3>
224-
</div>
225-
<div class="panel-body form-horizontal">
226-
<div class="row">
227-
<div class="col-sm-5">
228-
<div class="form-group">
229-
<label for="printOptions-heading" class="col-sm-4 control-label">Heading:</label>
230-
<div class="col-sm-8">
231-
<input id="printOptions-heading" class="form-control" type="input" ng-model="heading">
232-
</div>
233-
</div>
234-
</div>
235-
<div class="col-sm-5">
236-
<div class="form-group">
237-
<label for="printOptions-theme" class="col-sm-4 control-label">Theme:</label>
238-
<div class="col-sm-8">
239-
<select id="printOptions-theme" class="form-control" ng-model="printTheme" ng-options="opt.value as opt.label for opt in printThemeOptions"></select>
240-
</div>
241-
</div>
242-
</div>
243-
<div class="col-sm-2">
244-
<button ng-click="print()" type="button" class="btn btn-info btn-block"><i class="fa fa-print"></i> Print</button>
245-
</div>
246-
</div>
247-
</div>
248-
</div>
249-
</div>
250-
<h2 id="print_header" class="center" ng-bind="heading"></h2>
251-
<div ng-switch="schedule.length > 0">
252-
<div ng-class="printTheme" ng-switch-when="true" schedule print="true"></div>
253-
<div ng-switch-when="false" class="container">
254-
<div class="vert-spacer-static-md"></div>
255-
<div class="alert alert-info">
256-
<i class="fa fa-exclamation-circle"></i> Please press the print button in the previous window if you wish to print a schedule.
257-
</div>
258-
</div>
259-
</div>
260-
</div>
261-
262-
<?
263-
require "./inc/footer.inc";
264-
265-
266-
break;
267202

268203
case "ical":
269204
// iCAL FORMAT SCHEDULE ////////////////////////////////////////////
@@ -317,7 +252,6 @@ function queryOldId($id) {
317252

318253
case "schedule":
319254
// DEFAULT SCHEDULE FORMAT /////////////////////////////////////////
320-
$id = hexdec($_GET['id']);
321255
$schedule = getScheduleFromId($id);
322256

323257
// Make sure the schedule exists
@@ -363,16 +297,12 @@ function queryOldId($id) {
363297
header('Content-type: application/json');
364298

365299
// Required parameters
366-
if(empty($_GET['id'])) {
300+
if(empty($id)) {
367301
die(json_encode(array("error"=>true, "msg"=>"You must provide a schedule")));
368302
}
369-
370-
// Database connection is required
371-
require_once("inc/databaseConn.php");
372-
require_once("inc/timeFunctions.php");
373-
303+
374304
// Pull the schedule and output it as json
375-
$schedule = getScheduleFromId(hexdec($_GET['id']));
305+
$schedule = getScheduleFromId($id);
376306
if ( $schedule == NULL ) {
377307
echo json_encode(array(
378308
'error' => true,

api/status.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
////////////////////////////////////////////////////////////////////////////
3+
// STATUS
4+
//
5+
// @file status.php
6+
// @descrip IT ALWAYS WORKS!!!
7+
// @author Ben Russell ([email protected])
8+
////////////////////////////////////////////////////////////////////////////
9+
10+
// FUNCTIONS ///////////////////////////////////////////////////////////////
11+
function timeElapsed($time) {
12+
// Initialize the return string
13+
$return = "";
14+
15+
// Divide off days
16+
$days = floor($time / (60 * 60 * 24));
17+
if($days) {
18+
$return .= "{$days} days ";
19+
$time -= $days * 60 * 60 * 24;
20+
}
21+
22+
// Divide off hours
23+
$hours = floor($time / (60 * 60));
24+
if($hours) {
25+
$return .= "{$hours}:";
26+
$time -= $hours * 60 * 60;
27+
} else {
28+
$return .= "00:";
29+
}
30+
31+
// Divide off minutes
32+
$mins = floor($time / 60);
33+
if($mins) {
34+
$return .= "{$mins}:";
35+
$time -= $mins * 60;
36+
} else {
37+
$return .= "00:";
38+
}
39+
40+
// Divide off seconds
41+
$return .= str_pad($time, 2, "0", STR_PAD_LEFT);
42+
43+
return $return;
44+
}
45+
46+
// REQUIRED FILES //////////////////////////////////////////////////////////
47+
require_once("../inc/databaseConn.php");
48+
49+
// MAIN EXECUTION //////////////////////////////////////////////////////////
50+
// Look up the last 20 scrape reports and store into an array
51+
$query = "SELECT * FROM scrapelog ORDER BY timeStarted DESC LIMIT 20";
52+
$result = mysql_query($query);
53+
$lastLogs = array();
54+
while($row = mysql_fetch_assoc($result)) {
55+
$lastLogs[] = $row;
56+
}
57+
echo json_encode($lastLogs);

assets/build/.gitkeep

Whitespace-only changes.

browse.php renamed to assets/src/templates/browse.html

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,3 @@
1-
<?php
2-
////////////////////////////////////////////////////////////////////////////
3-
// SCHEDULE MAKER
4-
//
5-
// @author Ben Russell ([email protected])
6-
//
7-
// @file roulette.php
8-
// @descrip Browse Courses. This page is gonna be awesome. You can browse the
9-
// different courses in the database and then do fun things with them
10-
////////////////////////////////////////////////////////////////////////////
11-
12-
// REQUIRED FILES //////////////////////////////////////////////////////////
13-
require_once "./inc/config.php";
14-
require_once "./inc/databaseConn.php";
15-
require_once "./inc/timeFunctions.php";
16-
17-
// FUNCTIONS ///////////////////////////////////////////////////////////////
18-
19-
/**
20-
* Parses a term and returns an array of the results
21-
* @param string $term
22-
* @return string[]
23-
*/
24-
function parseTerm($term) {
25-
// Determine the term based on the year
26-
$termType = substr($term, -1);
27-
$year = substr($term, 0, 4);
28-
$nextYear = (string) ((int) $year + 1);
29-
if($term > 20130) {
30-
// Semesters
31-
switch($termType) {
32-
case 1:
33-
return array("Fall", $year);
34-
case 3:
35-
return array("Winter Intersession", $nextYear);
36-
case 5:
37-
return array("Spring", $nextYear);
38-
case 8:
39-
return array("Summer", $nextYear);
40-
default:
41-
return array("Unknown", "");
42-
}
43-
} else {
44-
// Based on the last number of the quarter, return a title
45-
switch($termType) {
46-
case 1:
47-
return array("Fall", $year);
48-
case 2:
49-
return array("Winter", $year);
50-
case 3:
51-
return array("Spring", $nextYear);
52-
case 4:
53-
return array("Summer", $nextYear);
54-
default:
55-
return array("Unknown", "");
56-
}
57-
}
58-
}
59-
60-
// Do we have a term specified?
61-
$term = (empty($_GET['term']) || !is_numeric($_GET['term'])) ? $CURRENT_QUARTER : $_GET['term'];
62-
63-
$parsedTerm = parseTerm($term);
64-
65-
// MAIN EXECUTION //////////////////////////////////////////////////////////
66-
require "./inc/header.inc";
67-
68-
// Display the fancy dropdown thingy that allows one to traverse the
69-
// list of courses
70-
?>
711
<div class="container" ng-controller="BrowseCtrl">
722
<div class="row">
733
<div class="col-md-8">
@@ -81,7 +11,7 @@ function parseTerm($term) {
8111
<div class="control-group">
8212
<label class="col-sm-6 control-label" for="term">Term:</label>
8313
<div class="col-sm-6">
84-
<?= getTermField("state.requestOptions.term"); ?>
14+
<div select-term></div>
8515
</div>
8616
</div>
8717
</div>
@@ -187,9 +117,4 @@ function parseTerm($term) {
187117
<div pinned course-cart></div>
188118
</div>
189119
</div>
190-
</div>
191-
192-
193-
<?
194-
require "./inc/footer.inc";
195-
?>
120+
</div>

0 commit comments

Comments
 (0)