/lenasys/0.1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/0.1

« back to all changes in this revision

Viewing changes to trunk/DuggaSys/quizAjax/getStudentCourseRegistrations.php

  • Committer: Henrik G.
  • Date: 2013-03-26 23:22:55 UTC
  • Revision ID: henrik.gustavsson@his.se-20130326232255-ik6snyatlbkf3zs1
First seed of Lenasys ... Needs to be Organized Further

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
////Returns "loginSuccess=>true" if student login name and password is correct and list of course registrations the student is registered for, else "loginSuccess=>false";
 
3
////Parameters: loginName, password
 
4
////Returns loginSucces: true/false, array(courseName, courseOccasion)
 
5
 
 
6
//Prevents browsers (IE) from caching the response
 
7
header('Cache-Control: no-cache, must-revalidate');
 
8
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
 
9
header('Content-type: application/json; charset=utf-8'); 
 
10
 
 
11
include "dbconnect.php";
 
12
 
 
13
$queryString="SELECT Student.ssn
 
14
                          FROM Student
 
15
                          WHERE Student.loginName=:LOGINNAME
 
16
                                AND Student.passw=:PASSW;";
 
17
$stmt = $pdo->prepare($queryString);
 
18
$stmt->bindParam(':LOGINNAME', $_POST['loginName']);
 
19
$stmt->bindParam(':PASSW', $_POST['password']);
 
20
$stmt->execute();
 
21
$count=$stmt->rowCount();
 
22
if($count==1){ //login successfull
 
23
        $studentData=$stmt->fetch(PDO::FETCH_ASSOC);
 
24
        $queryString="SELECT StudentCourseRegistration.courseName, StudentCourseRegistration.courseOccasion
 
25
                                  FROM StudentCourseRegistration
 
26
                                  WHERE studentSsn=:SSN;";
 
27
        $stmt = $pdo->prepare($queryString);
 
28
        $stmt->bindParam(':SSN', $studentData['ssn']);
 
29
        $stmt->execute();
 
30
        $listOfCourseRegistrations=array();
 
31
        $courseRegistrations=$stmt->fetchAll(PDO::FETCH_ASSOC);
 
32
        foreach($courseRegistrations as $row){
 
33
                array_push($listOfCourseRegistrations, array('courseName'=>$row['courseName'],'courseOccasion'=>$row['courseOccasion']));
 
34
        }
 
35
        echo json_encode(array('loginSuccess' => 'true','courseRegistrations'=>$listOfCourseRegistrations));
 
36
} else {
 
37
        echo json_encode(array('loginSuccess' => 'false'));
 
38
}
 
39
 
 
40
?>
 
 
b'\\ No newline at end of file'