function validateUser($username, $password) { $conn = connectToDataBase(); $sql = "SELECT * FROM User WHERE userName = \"" . $username . "\" AND userPassword = \"" . $password . "\""; $result = mysqli_query($conn, $sql); $array = array(); if (mysqli_num_rows($result) > 0) { $array["response"] = "accepted"; $sql = "SELECT rolId, institutionId\n FROM HasRole hr, WorksInInstitution wi\n WHERE hr.userName = \"" . $username . "\" AND\n hr.userName = wi.userName;"; $result = mysqli_query($conn, $sql); if ($row = mysqli_fetch_assoc($result)) { $array["rolId"] = $row["rolId"]; $array["institutionId"] = $row["institutionId"]; $array["userName"] = $username; startSession($array); } } else { $array["response"] = "declined"; } closeDb($conn); echo json_encode($array); }
function getGraphByGrade($curp, $gradeId) { $conn = connectToDataBase(); $sql = "SELECT Co.name, gradeObtained FROM Course Co, ReportCard R\n WHERE R.CURP = \"" . $curp . "\" AND R.gradeId = " . $gradeId . " AND\n Co.courseId = R.courseId;"; $result = mysqli_query($conn, $sql); $courses = array(); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $materia = new Materia(); $materia->name = $row["name"]; $materia->grade = $row["gradeObtained"]; array_push($courses, $materia); } $res = array(); $res["n"] = count($courses); $res["materias"] = $courses; echo json_encode($res); } else { echo "error"; } closeDb($conn); }
function insertInstitution($name, $email, $phone, $address) { $conn = connectToDataBase(); $sql = "INSERT INTO Institution (name, email, phone, address) VALUES (\"" . $name . "\", \"" . $email . "\", \"" . $phone . "\", \"" . $address . "\");"; if (mysqli_query($conn, $sql)) { echo "1"; } else { echo "0"; } closeDb($conn); }
function getRolesFromDb() { $conn = connectToDataBase(); $sql = "SELECT * FROM Rol"; $result = mysqli_query($conn, $sql); $json = array(); if (mysqli_num_rows($result) > 0) { $json["status"] = "correct"; $json["num"] = mysqli_num_rows($result); $option = ""; while ($row = mysqli_fetch_assoc($result)) { $option .= "<option value=\"" . $row["rolId"] . "\">" . $row["name"] . "</option>"; } $json["data"] = $option; echo $option; } else { $json["status"] = "wrong"; } closeDb($conn); }