Ejemplo n.º 1
0
 eta.professor.getSections(req.session["userid"], (sections: eta.Section[]) => {
     if (!sections) {
         callback({ errcode: eta.http.InternalError });
         return;
     }
     if (sections.length > 0) {
         if (eta.section.hasCurrentSections(sections, eta.term.getCurrent().id)) {
             res.redirect("/track/professor");
             return;
         }
     }
     // falls to here if they're not a current student or professor
     eta.athlete.isDirector(req.session["userid"], (isAthleteDirector: boolean) => {
         if (isAthleteDirector === null) {
             callback({ errcode: eta.http.InternalError });
             return;
         }
         if (isAthleteDirector) {
             res.redirect("/track/athlete");
             return;
         }
         // falls to here if they're not a current student, professor or director
         callback({}); // just display the "error" page
     });
 });
Ejemplo n.º 2
0
 public render(req: express.Request, res: express.Response, callback: (env: { [key: string]: any }) => void): void {
     if (!eta.params.test(req.body, ["student"])) {
         callback({ errcode: eta.http.InvalidParameters });
         return;
     }
     if (req.body.section) { // acting as professor
         eta.section.getByID(req.body.section, (section: eta.Section) => {
             if (!section) {
                 callback({ errcode: eta.http.InternalError });
                 return;
             }
             // the prof isn't the one logged in
             if (section.professor != req.session["userid"]) {
                 callback({ errcode: eta.http.Forbidden });
                 return;
             }
             this.fetchResults(req, res, callback);
         });
     } else { // acting as athlete director
         eta.athlete.isDirector(req.session["userid"], (isAthleteDirector: boolean) => {
             if (isAthleteDirector === null) {
                 callback({ errcode: eta.http.InternalError });
                 return;
             }
             if (!isAthleteDirector) {
                 res.redirect("/track/index");
                 return;
             }
             this.fetchResults(req, res, callback);
         });
     }
 }
Ejemplo n.º 3
0
 public render(req: express.Request, res: express.Response, callback: (env: { [key: string]: any }) => void): void {
     if (!eta.params.test(req.query, ["id"])) {
         callback({ errcode: eta.http.InvalidParameters });
         return;
     }
     eta.section.getByID(req.query.id, (section: eta.Section) => {
         if (!section) {
             callback({ errcode: eta.http.NotFound });
             return;
         }
         // the prof isn't the one logged in
         if (section.professor != req.session["userid"]) {
             callback({ errcode: eta.http.Forbidden });
             return;
         }
         let isPastWeek: boolean = !!req.query.isPastWeek;
         let pastWeekSql: string = `AND DATE(Visit.timeIn) >= (CURDATE() - INTERVAL 7 DAY)`;
         let sql: string = `
             SELECT
                 Person.id,
                 Person.firstName,
                 Person.lastName,
                 VisitCount.count AS visitCount,
                 VisitCount.duration AS visitDuration
             FROM
                 StudentSection
                     LEFT JOIN Person ON
                         StudentSection.student = Person.id
                     LEFT JOIN (
                         SELECT
                             Visit.student AS student,
                             COUNT(DISTINCT Visit.student, Visit.timeIn) AS count,
                             ROUND(SUM(TIME_TO_SEC(TIMEDIFF(Visit.timeOut, Visit.timeIn))) / 3600, 2) AS duration
                         FROM
                             Visit
                         WHERE
                             Visit.section REGEXP ?
                             ${isPastWeek ? pastWeekSql : ""}
                         GROUP BY Visit.student
                     ) VisitCount ON
                         StudentSection.student = VisitCount.student
             WHERE
                 StudentSection.section = ? AND
                 StudentSection.status = 'E'`;
         eta.db.query(sql, [req.query.id, req.query.id], (err: eta.DBError, rows: any[]) => {
             if (err) {
                 eta.logger.dbError(err);
                 callback({ errcode: eta.http.InternalError });
                 return;
             }
             callback({
                 "section": section,
                 "students": rows,
                 "isPastWeek": isPastWeek
             });
         });
     });
 }
Ejemplo n.º 4
0
 eta.student.get(req.session["userid"], (student: eta.Student) => {
     if (!student) {
         callback({ errcode: eta.http.InternalError });
         return;
     }
     if (student.sections.length == 0
         || !eta.section.hasCurrentSections(student.sections, eta.term.getCurrent().id)) {
         res.redirect("/track/index");
         return;
     }
     let sql: string = `
         SELECT
             LOWER(TIME_FORMAT(Visit.timeIn, '%l:%i %p')) AS timeIn,
             LOWER(TIME_FORMAT(Visit.timeOut, '%l:%i %p')) AS timeOut,
             ROUND(TIME_TO_SEC(TIMEDIFF(Visit.timeOut, Visit.timeIn)) / 3600, 2) AS totalHours,
             DATE_FORMAT(Visit.timeIn, '%c/%e/%Y') AS date,
             GROUP_CONCAT(DISTINCT CONCAT(Course.subject, ' ', Course.number) ORDER BY Course.subject, Course.number SEPARATOR ', ') AS courses
         FROM
             Visit
                 RIGHT JOIN Section ON
                     Visit.section REGEXP Section.id
                 RIGHT JOIN Course ON
                     Section.course = Course.id
         WHERE
             Visit.term = ? AND
             Visit.student = ?
         GROUP BY Visit.student, Visit.timeIn
         ORDER BY Visit.timeIn`;
     eta.db.query(sql, [eta.term.getCurrent().id, req.session["userid"]], (err: eta.DBError, rows: any[]) => {
         if (err) {
             eta.logger.dbError(err);
             callback({ errcode: eta.http.InternalError });
             return;
         }
         let totalHours: number = 0;
         for (let i: number = 0; i < rows.length; i++) {
             totalHours += rows[i].totalHours;
         }
         eta.person.getByID(req.session["userid"], (person: eta.Person) => {
             if (!person) {
                 callback({ errcode: eta.http.InternalError });
                 return;
             }
             callback({
                 "visits": rows,
                 "name": person.firstName + " " + person.lastName,
                 "totalHours": totalHours.toFixed(2)
             });
         });
     });
 });
Ejemplo n.º 5
0
 eta.section.getByProfessor(req.session["userid"], (rawSections: eta.Section[]) => {
     if (!rawSections) {
         callback({ errcode: eta.http.InternalError });
         return;
     }
     let sections: eta.Section[] = eta.section.removePrevious(rawSections, eta.term.getCurrent().id);
     if (sections.length === 0) { // no sections at all or no current sections
         res.redirect("/track/index");
         return;
     }
     sections.sort(eta.section.sort);
     eta.person.getByID(req.session["userid"], (person: eta.Person) => {
         if (!person) {
             callback({ errcode: eta.http.InternalError });
             return;
         }
         callback({
             "name": person.firstName + " " + person.lastName,
             "sections": sections
         });
     });
 });