2025-01-07 03:02:25 +01:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
require 'dbcon.php';
|
|
|
|
|
|
|
|
function validate($inputData){
|
|
|
|
global $conn;
|
|
|
|
$validatedData = mysqli_real_escape_string($conn, $inputData);
|
|
|
|
return trim($validatedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
function redirect($url, $status, $alertLevel="secondary")
|
|
|
|
{
|
|
|
|
$_SESSION['status'] = $status;
|
|
|
|
$_SESSION['alertLevel'] = $alertLevel;
|
|
|
|
header('Location: '.$url);
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function logoutSession(){
|
|
|
|
unset($_SESSION['auth']);
|
|
|
|
unset($_SESSION['loggedInUserID']);
|
|
|
|
unset($_SESSION['loggedInUserRole']);
|
|
|
|
}
|
|
|
|
|
|
|
|
function alertMessage($level="info")
|
|
|
|
{
|
|
|
|
if(isset($_SESSION['status']))
|
|
|
|
{
|
|
|
|
echo '<div class="alert alert-'.$_SESSION['alertLevel'].'" role="alert">'.$_SESSION['status'].'
|
|
|
|
</div>';
|
|
|
|
unset($_SESSION['status']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkParamId($paramType)
|
|
|
|
{
|
|
|
|
if(isset($_GET[$paramType]))
|
|
|
|
{
|
|
|
|
if($_GET[$paramType] != null)
|
|
|
|
{
|
|
|
|
return $_GET[$paramType];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 'keine ID gefunden';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 'keine ID angegeben';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAll($columnname,$tablename,$conditionvalue = "")
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
$column = validate($columnname);
|
|
|
|
$table = validate($tablename);
|
|
|
|
//$condition = validate($conditionvalue);
|
|
|
|
$query = "SELECT $column FROM $table $conditionvalue";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2025-01-14 07:44:19 +01:00
|
|
|
function saveResetToken($userId, $token, $expiry) {
|
|
|
|
global $conn;
|
|
|
|
$userId = validate($userId);
|
|
|
|
$token = validate($token);
|
|
|
|
$expiry = validate($expiry);
|
|
|
|
|
|
|
|
$query = "UPDATE users SET reset_token='$token', reset_token_expiry='$expiry' WHERE userid='$userId'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2025-01-07 03:02:25 +01:00
|
|
|
function getById($tableName, $id)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
$table = validate($tableName);
|
|
|
|
$id = validate($id);
|
|
|
|
|
|
|
|
$query = "SELECT * FROM $table WHERE id='$id' LIMIT 1";
|
|
|
|
$result = mysqli_Query($conn, $query);
|
|
|
|
|
|
|
|
if($result)
|
|
|
|
{
|
|
|
|
if(mysqli_num_rows($result) == 1)
|
|
|
|
{
|
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
|
|
$response = [
|
|
|
|
'status' => 200,
|
|
|
|
'message' => 'Daten konnten abgerufen werden',
|
|
|
|
'data' => $row
|
|
|
|
];
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$response = [
|
|
|
|
'status' => 404,
|
|
|
|
'message' => 'Keinen Eintrag gefunden'
|
|
|
|
];
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$response = [
|
|
|
|
'status' => 500,
|
|
|
|
'message' => 'Ein Fehler ist aufgetreten'
|
|
|
|
];
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getByCategoryId($tableName, $id)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
$table = validate($tableName);
|
|
|
|
$id = validate($id);
|
|
|
|
|
|
|
|
$query = "SELECT * FROM $table WHERE id='$id' LIMIT 1";
|
|
|
|
$result = mysqli_Query($conn, $query);
|
|
|
|
|
|
|
|
if($result)
|
|
|
|
{
|
|
|
|
if(mysqli_num_rows($result) == 1)
|
|
|
|
{
|
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
|
|
$response = [
|
|
|
|
'status' => 200,
|
|
|
|
'message' => 'Daten konnten abgerufen werden',
|
|
|
|
'data' => $row
|
|
|
|
];
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$response = [
|
|
|
|
'status' => 404,
|
|
|
|
'message' => 'Keinen Eintrag gefunden'
|
|
|
|
];
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$response = [
|
|
|
|
'status' => 500,
|
|
|
|
'message' => 'Ein Fehler ist aufgetreten'
|
|
|
|
];
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function archiveQuery($tablename, $id)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$table = validate($tablename);
|
|
|
|
$id = validate($id);
|
|
|
|
|
|
|
|
$query = "UPDATE $table SET status='archived' WHERE id='$id' LIMIT 1";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function reactivateQuery($tablename, $id)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$table = validate($tablename);
|
|
|
|
$id = validate($id);
|
|
|
|
|
|
|
|
$query = "UPDATE $table SET status='active' WHERE id='$id' LIMIT 1";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteQuery($tablename, $id, $limit = "")
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$table = validate($tablename);
|
|
|
|
$id = validate($id);
|
|
|
|
|
|
|
|
$query = "DELETE FROM $table WHERE id='$id' '$limit'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllClasses($status)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
if(!$status) {$querystatus = "";}
|
|
|
|
elseif($status){$querystatus = "WHERE status='$status'";}
|
|
|
|
$query = "SELECT id, CONCAT(sek, ' ', type, ' - ', name) AS display_name FROM tbl_classes $querystatus ORDER BY display_name ASC";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
$classOptions = array();
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$classOptions[$row['id']] = $row['display_name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getStudentCountsPerClass() {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$classOptions = getAllClasses('active');
|
|
|
|
$classCounts = array();
|
|
|
|
|
|
|
|
if (!empty($classOptions)) {
|
|
|
|
foreach ($classOptions as $classID => $className) {
|
|
|
|
$query = "SELECT COUNT(*) as count FROM tbl_students WHERE class = $classID AND (status='active' OR status='disabled')";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
$count = $row['count'];
|
|
|
|
} else {
|
|
|
|
$count = 0;
|
|
|
|
}
|
|
|
|
$classCounts[$classID] = $count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classCounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createEnumSelect($tableName, $columnName, $selectedValue = '', $valueLabels = [])
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$query = "SHOW COLUMNS FROM $tableName LIKE '$columnName'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
$enumStr = $row['Type'];
|
|
|
|
|
|
|
|
$enumValues = explode(",", str_replace("'", "", substr($enumStr, 5, -1)));
|
|
|
|
foreach ($enumValues as $enumValue) {
|
|
|
|
$enumLabel = isset($valueLabels[$enumValue]) ? $valueLabels[$enumValue] : ucfirst($enumValue);
|
|
|
|
$selected = ($enumValue == $selectedValue) ? 'selected' : '';
|
|
|
|
echo "<option value='$enumValue' $selected>$enumLabel</option>";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "<select name='$columnName' required class='form-select'><option value=''>Fehler beim Abrufen der Werte</option></select>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createEnumSelectFiltered($tableName, $columnName, $selectedValue = '', $valueLabels = []) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$query = "SHOW COLUMNS FROM $tableName LIKE '$columnName'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
$enumStr = $row['Type'];
|
|
|
|
|
|
|
|
$enumValues = explode(",", str_replace("'", "", substr($enumStr, 5, -1)));
|
|
|
|
foreach ($enumValues as $enumValue) {
|
|
|
|
if (isset($valueLabels[$enumValue])) {
|
|
|
|
$enumLabel = $valueLabels[$enumValue];
|
|
|
|
$selected = ($enumValue == $selectedValue) ? 'selected' : '';
|
|
|
|
echo "<option value='$enumValue' $selected>$enumLabel</option>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "<select name='$columnName' required class='form-select'><option value=''>Fehler beim Abrufen der Werte</option></select>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getArchivedStudentsWithActiveClasses() {
|
|
|
|
global $conn;
|
|
|
|
$query = "SELECT
|
|
|
|
tbl_students.id AS student_id,
|
|
|
|
tbl_students.firstname AS student_firstname,
|
|
|
|
tbl_students.lastname AS student_lastname,
|
|
|
|
tbl_students.userid AS student_userid,
|
|
|
|
CONCAT(tbl_classes.sek, ' ', tbl_classes.type, ' - ', tbl_classes.name) AS display_name
|
|
|
|
FROM tbl_students
|
|
|
|
INNER JOIN tbl_classes ON tbl_students.class = tbl_classes.id
|
|
|
|
WHERE tbl_students.status = 'archived' AND tbl_classes.status != 'archived'";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
$students = array();
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$students[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $students;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteArchivedStudentsWithActiveClasses($students) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
foreach ($students as $student) {
|
|
|
|
$student_id = $student['student_id'];
|
|
|
|
$query = "DELETE FROM tbl_students WHERE id='$student_id'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function reactivateArchivedStudentsWithActiveClasses($students) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
foreach ($students as $student) {
|
|
|
|
$student_id = $student['student_id'];
|
|
|
|
$query = "UPDATE tbl_students SET status='active' WHERE id='$student_id'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getArchivedClasses() {
|
|
|
|
global $conn;
|
|
|
|
$query = "SELECT
|
|
|
|
tbl_classes.id AS class_id,
|
|
|
|
CONCAT(tbl_classes.sek, ' ', tbl_classes.type, ' - ', tbl_classes.name) AS display_name,
|
|
|
|
GROUP_CONCAT(
|
|
|
|
CONCAT(tbl_students.firstname, ' ', tbl_students.lastname, ' (ID: ', tbl_students.userid, ')')
|
|
|
|
SEPARATOR '<br>'
|
|
|
|
) AS students
|
|
|
|
FROM tbl_classes
|
|
|
|
LEFT JOIN tbl_students ON tbl_classes.id = tbl_students.class
|
|
|
|
WHERE tbl_classes.status = 'archived' AND tbl_students.status = 'archived'
|
|
|
|
GROUP BY tbl_classes.id";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$classes[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getClassesGroupedByLevel($status)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
if (!$status) {
|
|
|
|
$querystatus = "";
|
|
|
|
} elseif ($status) {
|
|
|
|
$querystatus = "WHERE status='$status'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = "SELECT id, sek, CONCAT(sek, ' ', type, ' - ', name) AS display_name FROM tbl_classes $querystatus ORDER BY sek ASC, display_name ASC";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
$groupedClasses = array();
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$level = $row['sek'];
|
|
|
|
|
|
|
|
// Erstelle ein neues Array für die Stufe, wenn es noch nicht existiert
|
|
|
|
if (!isset($groupedClasses[$level])) {
|
|
|
|
$groupedClasses[$level] = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Füge die Klasse zur entsprechenden Stufe hinzu
|
|
|
|
$groupedClasses[$level][] = array(
|
|
|
|
'id' => $row['id'],
|
|
|
|
'display_name' => $row['display_name']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $groupedClasses;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAssignedItems($tableName, $primaryId, $secondaryColumn, $primaryColumn)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$primaryId = validate($primaryId);
|
|
|
|
|
|
|
|
$query = "SELECT $secondaryColumn FROM $tableName WHERE $primaryColumn = '$primaryId'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
$assignedItems = array();
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$assignedItems[] = $row[$secondaryColumn];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $assignedItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getStudentInformation($id)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$id = validate($id);
|
|
|
|
|
|
|
|
$query = "SELECT
|
|
|
|
tbl_students.id,
|
|
|
|
tbl_students.firstname,
|
|
|
|
tbl_students.lastname,
|
|
|
|
tbl_students.userid,
|
|
|
|
tbl_students.status,
|
|
|
|
tbl_students.dateofbirth,
|
|
|
|
tbl_students.gender,
|
|
|
|
tbl_students.class,
|
|
|
|
tbl_students.emailstudent,
|
|
|
|
tbl_students.emailparent1,
|
|
|
|
tbl_students.emailparent2,
|
|
|
|
CONCAT(tbl_classes.sek, ' ', tbl_classes.type, ' - ', tbl_classes.name) AS classDisplayName
|
|
|
|
FROM tbl_students
|
|
|
|
JOIN tbl_classes ON tbl_students.class = tbl_classes.id
|
|
|
|
WHERE tbl_students.id = '$id'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if($result)
|
|
|
|
{
|
|
|
|
if(mysqli_num_rows($result) == 1)
|
|
|
|
{
|
|
|
|
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
|
|
$response = [
|
|
|
|
'data' => $row
|
|
|
|
];
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCategories($id)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$id = validate($id);
|
|
|
|
|
|
|
|
$query = "SELECT
|
|
|
|
tbl_students.id,
|
|
|
|
tbl_categories.id AS category_id,
|
|
|
|
tbl_categories.name
|
|
|
|
FROM
|
|
|
|
tbl_students
|
|
|
|
JOIN
|
|
|
|
tbl_classes ON tbl_students.class = tbl_classes.id
|
|
|
|
JOIN
|
|
|
|
tbl_assign_categories_classes ON tbl_classes.id = tbl_assign_categories_classes.class_id
|
|
|
|
JOIN
|
|
|
|
tbl_categories ON tbl_assign_categories_classes.category_id = tbl_categories.id
|
|
|
|
WHERE
|
|
|
|
tbl_students.id = '$id'";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if($result) {
|
|
|
|
$categories = array();
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$categories[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $categories;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getForms($student_id)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$student_id = validate($student_id);
|
|
|
|
|
|
|
|
$query = "SELECT
|
|
|
|
tbl_forms.id AS form_id,
|
|
|
|
tbl_forms.name AS form_name,
|
|
|
|
tbl_forms.deadline AS deadline
|
|
|
|
FROM
|
|
|
|
tbl_forms
|
|
|
|
JOIN
|
|
|
|
tbl_assign_forms_classes ON tbl_forms.id = tbl_assign_forms_classes.form_id
|
|
|
|
JOIN
|
|
|
|
tbl_students ON tbl_assign_forms_classes.class_id = tbl_students.class
|
|
|
|
WHERE
|
|
|
|
tbl_students.id = '$student_id'";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if($result) {
|
|
|
|
$forms = array();
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$forms[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $forms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getClassesPerCategory($category_id){
|
|
|
|
global $conn;
|
|
|
|
$category_id = validate($category_id);
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
SELECT tbl_classes.id,
|
|
|
|
tbl_classes.sek,
|
|
|
|
CONCAT(tbl_classes.sek, ' ', tbl_classes.type, ' - ', tbl_classes.name) AS classDisplayName
|
|
|
|
FROM tbl_classes
|
|
|
|
LEFT JOIN tbl_assign_categories_classes ON tbl_classes.id = tbl_assign_categories_classes.class_id
|
|
|
|
WHERE tbl_classes.status = 'active'
|
|
|
|
AND (tbl_assign_categories_classes.category_id = '$category_id' OR tbl_assign_categories_classes.category_id IS NULL)
|
|
|
|
ORDER BY sek ASC, classDisplayName ASC
|
|
|
|
";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query); // Annahme: $conn ist Ihre MySQL-Verbindung
|
|
|
|
|
|
|
|
// Hier können Sie die verfügbaren Klassen für die Anzeige verwenden
|
|
|
|
if ($result) {
|
|
|
|
$classes = array();
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$classes[] = $row; // Hier können Sie die Klasse anzeigen oder in Ihrer Anwendung verwenden
|
|
|
|
}
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getClassesPerForm($form_id){
|
|
|
|
global $conn;
|
|
|
|
$form_id = validate($form_id);
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
SELECT tbl_classes.id,
|
|
|
|
tbl_classes.sek,
|
|
|
|
CONCAT(tbl_classes.sek, ' ', tbl_classes.type, ' - ', tbl_classes.name) AS classDisplayName
|
|
|
|
FROM tbl_classes
|
|
|
|
INNER JOIN tbl_assign_forms_classes ON tbl_classes.id = tbl_assign_forms_classes.class_id
|
|
|
|
WHERE tbl_classes.status = 'active'
|
|
|
|
AND (tbl_assign_forms_classes.form_id = '$form_id')
|
|
|
|
ORDER BY sek ASC, classDisplayName ASC
|
|
|
|
";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query); // Annahme: $conn ist Ihre MySQL-Verbindung
|
|
|
|
|
|
|
|
// Hier können Sie die verfügbaren Klassen für die Anzeige verwenden
|
|
|
|
if ($result) {
|
|
|
|
$classes = array();
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$classes[] = $row; // Hier können Sie die Klasse anzeigen oder in Ihrer Anwendung verwenden
|
|
|
|
}
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getClassesPerFormContent($formcontent_id){
|
|
|
|
global $conn;
|
|
|
|
$formcontent_id = validate($formcontent_id);
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
SELECT tbl_classes.id,
|
|
|
|
tbl_classes.sek,
|
|
|
|
CONCAT(tbl_classes.sek, ' ', tbl_classes.type, ' - ', tbl_classes.name) AS classDisplayName
|
|
|
|
FROM tbl_classes
|
|
|
|
INNER JOIN tbl_assign_formcontents_classes ON tbl_classes.id = tbl_assign_formcontents_classes.class_id
|
|
|
|
WHERE tbl_classes.status = 'active'
|
|
|
|
AND (tbl_assign_formcontents_classes.formcontent_id = '$formcontent_id')
|
|
|
|
ORDER BY sek ASC, classDisplayName ASC
|
|
|
|
";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$classes = array();
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$classes[] = $row;
|
|
|
|
}
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTeachers()
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
// Führe die Abfrage aus
|
|
|
|
$query = "SELECT CONCAT(firstname, ' ', lastname) AS name, id FROM tbl_teachers ORDER BY name ASC";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
// Überprüfe, ob die Abfrage erfolgreich war
|
|
|
|
if (!$result) {
|
|
|
|
die("Fehler beim Ausführen der Abfrage: " . mysqli_error($conn));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch die Ergebnisse und speichere nur die benötigten Informationen
|
|
|
|
$data = array();
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$data[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCourseTeacher($id)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
// Führe die Abfrage aus
|
|
|
|
$query = "SELECT CONCAT(firstname, ' ', lastname) AS name FROM tbl_teachers WHERE id='$id'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
// Holen Sie den Datensatz aus dem Ergebnis
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
// Rückgabe des Namens des Kursleiters
|
|
|
|
return $row['name'];
|
|
|
|
} else {
|
|
|
|
// Rückgabe eines leeren Strings im Fehlerfall
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCourseDatesByCourseID($courseID)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$courseID = validate($courseID);
|
|
|
|
|
|
|
|
$query = "SELECT * FROM tbl_coursedates WHERE course_id='$courseID'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
$courseDates = array();
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$courseDates[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $courseDates;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCoursesByClassAndCategory($classID, $categoryID)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$classID = validate($classID);
|
|
|
|
$categoryID = validate($categoryID);
|
|
|
|
|
|
|
|
$query = "SELECT
|
|
|
|
tbl_courses.id,
|
|
|
|
tbl_courses.name,
|
|
|
|
tbl_courses.slogan
|
|
|
|
FROM
|
|
|
|
tbl_courses
|
|
|
|
INNER JOIN
|
|
|
|
tbl_assign_courses_classes ON tbl_courses.id = tbl_assign_courses_classes.course_id
|
|
|
|
INNER JOIN
|
|
|
|
tbl_categories ON tbl_courses.category_id = tbl_categories.id
|
|
|
|
INNER JOIN
|
|
|
|
tbl_classes ON tbl_assign_courses_classes.class_id = tbl_classes.id
|
|
|
|
WHERE
|
|
|
|
tbl_classes.id = '$classID' AND tbl_categories.id = '$categoryID'";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if($result) {
|
|
|
|
$courses = array();
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$courses[] = $row;
|
|
|
|
}
|
|
|
|
return $courses;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDeadline($categoryID, $classID)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$categoryID = validate($categoryID);
|
|
|
|
$classID = validate($classID);
|
|
|
|
|
|
|
|
// Zuerst prüfen, ob die Deadline für die Kategorie festgelegt ist
|
|
|
|
$query = "SELECT registration, showuntil, showuntil_set, deadline_set, deadline FROM tbl_categories WHERE id='$categoryID'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
if (($row['registration'] == 'yes') && ($row['deadline_set'] == 'yes')) {
|
|
|
|
return $row['deadline'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'yes') && ($row['deadline_set'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT MAX(tbl_courses.deadline) AS max_deadline
|
|
|
|
FROM tbl_courses
|
|
|
|
INNER JOIN tbl_assign_courses_classes ON tbl_courses.id = tbl_assign_courses_classes.course_id
|
|
|
|
WHERE tbl_courses.category_id='$categoryID' AND tbl_assign_courses_classes.class_id='$classID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['max_deadline'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'no') && ($row['showuntil_set'] == 'yes')) {
|
|
|
|
return $row['showuntil'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'no') && ($row['showuntil_set'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT MAX(tbl_courses.show_until) AS max_showuntil
|
|
|
|
FROM tbl_courses
|
|
|
|
INNER JOIN tbl_assign_courses_classes ON tbl_courses.id = tbl_assign_courses_classes.course_id
|
|
|
|
WHERE tbl_courses.category_id='$categoryID' AND tbl_assign_courses_classes.class_id='$classID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['max_showuntil'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline oder show_until aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT MAX(CASE
|
|
|
|
WHEN tbl_courses.registration = 'yes' THEN tbl_courses.deadline
|
|
|
|
WHEN tbl_courses.registration = 'no' THEN tbl_courses.show_until
|
|
|
|
ELSE NULL
|
|
|
|
END) AS max_deadline_or_showuntil
|
|
|
|
FROM tbl_courses
|
|
|
|
INNER JOIN tbl_assign_courses_classes ON tbl_courses.id = tbl_assign_courses_classes.course_id
|
|
|
|
WHERE tbl_courses.category_id='$categoryID' AND tbl_assign_courses_classes.class_id='$classID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['max_deadline_or_showuntil'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null; // Rückgabe von null, wenn keine Deadline gefunden wurde
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCourseDeadline($courseID)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$courseID = validate($courseID);
|
|
|
|
|
|
|
|
|
|
|
|
// Abfrage, um die Kategorie-ID des Kurses zu finden
|
|
|
|
$query = "SELECT category_id FROM tbl_courses WHERE id='$courseID'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result && mysqli_num_rows($result) > 0) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
$categoryID = $row['category_id'];
|
|
|
|
|
|
|
|
// Abfrage, um den Namen der Kategorie anhand der Kategorie-ID zu finden
|
|
|
|
$query = "SELECT registration, showuntil, showuntil_set, deadline_set, deadline FROM tbl_categories WHERE id='$categoryID'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result && mysqli_num_rows($result) > 0) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
if (($row['registration'] == 'yes') && ($row['deadline_set'] == 'yes')) {
|
|
|
|
return $row['deadline'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'yes') && ($row['deadline_set'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT deadline FROM tbl_courses WHERE id='$courseID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['deadline'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'no') && ($row['showuntil_set'] == 'yes')) {
|
|
|
|
return $row['showuntil'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'no') && ($row['showuntil_set'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT show_until FROM tbl_courses WHERE id='$courseID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['show_until'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline oder show_until aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT (CASE
|
|
|
|
WHEN registration = 'yes' THEN deadline
|
|
|
|
WHEN registration = 'no' THEN show_until
|
|
|
|
ELSE NULL
|
|
|
|
END) AS deadline_or_showuntil
|
|
|
|
FROM tbl_courses
|
|
|
|
WHERE id='$courseID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['deadline_or_showuntil'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// Zuerst prüfen, ob die Deadline für die Kategorie festgelegt ist
|
|
|
|
$query = "SELECT registration, showuntil, showuntil_set, deadline_set, deadline FROM tbl_categories WHERE id='$categoryID'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
if (($row['registration'] == 'yes') && ($row['deadline_set'] == 'yes')) {
|
|
|
|
return $row['deadline'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'yes') && ($row['deadline_set'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT MAX(tbl_courses.deadline) AS max_deadline
|
|
|
|
FROM tbl_courses
|
|
|
|
INNER JOIN tbl_assign_courses_classes ON tbl_courses.id = tbl_assign_courses_classes.course_id
|
|
|
|
WHERE tbl_courses.category_id='$categoryID' AND tbl_assign_courses_classes.class_id='$classID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['max_deadline'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'no') && ($row['showuntil_set'] == 'yes')) {
|
|
|
|
return $row['showuntil'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'no') && ($row['showuntil_set'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT MAX(tbl_courses.show_until) AS max_showuntil
|
|
|
|
FROM tbl_courses
|
|
|
|
INNER JOIN tbl_assign_courses_classes ON tbl_courses.id = tbl_assign_courses_classes.course_id
|
|
|
|
WHERE tbl_courses.category_id='$categoryID' AND tbl_assign_courses_classes.class_id='$classID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['max_showuntil'];
|
|
|
|
}
|
|
|
|
if (($row['registration'] == 'custom')) {
|
|
|
|
// Abfrage, um die neueste Deadline oder show_until aller Kurse der Kategorie und Klasse zu finden
|
|
|
|
$courseQuery = "SELECT MAX(CASE
|
|
|
|
WHEN tbl_courses.registration = 'yes' THEN tbl_courses.deadline
|
|
|
|
WHEN tbl_courses.registration = 'no' THEN tbl_courses.show_until
|
|
|
|
ELSE NULL
|
|
|
|
END) AS max_deadline_or_showuntil
|
|
|
|
FROM tbl_courses
|
|
|
|
INNER JOIN tbl_assign_courses_classes ON tbl_courses.id = tbl_assign_courses_classes.course_id
|
|
|
|
WHERE tbl_courses.category_id='$categoryID' AND tbl_assign_courses_classes.class_id='$classID'";
|
|
|
|
$courseResult = mysqli_query($conn, $courseQuery);
|
|
|
|
$courseRow = mysqli_fetch_assoc($courseResult);
|
|
|
|
return $courseRow['max_deadline_or_showuntil'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null; // Rückgabe von null, wenn keine Deadline gefunden wurde
|
|
|
|
}
|
|
|
|
|
|
|
|
function getActiveStudentsByCategory($categoryID) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$categoryID = validate($categoryID);
|
|
|
|
|
|
|
|
// Abfrage, um alle aktiven Schüler abzurufen, die einer bestimmten Kategorie zugewiesen sind
|
|
|
|
$query = "SELECT DISTINCT tbl_students.id, tbl_students.class, tbl_students.firstname, tbl_students.lastname, CONCAT(tbl_students.firstname, ' ', tbl_students.lastname) AS name
|
|
|
|
FROM tbl_students
|
|
|
|
INNER JOIN tbl_assign_categories_classes ON tbl_students.class = tbl_assign_categories_classes.class_id
|
|
|
|
WHERE tbl_assign_categories_classes.category_id = '$categoryID'
|
|
|
|
AND tbl_students.status != 'archived'";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
$students = [];
|
|
|
|
|
|
|
|
if ($result && mysqli_num_rows($result) > 0) {
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$students[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $students;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getStudentCourseData($studentID, $courseID) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$studentID = validate($studentID);
|
|
|
|
$courseID = validate($courseID);
|
|
|
|
|
|
|
|
// Abfrage, um die Daten des Schülers für den angegebenen Kurs abzurufen
|
|
|
|
$query = "SELECT * FROM tbl_assign_students_courses
|
|
|
|
WHERE student_id='$studentID' AND course_id='$courseID'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result && mysqli_num_rows($result) > 0) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getCoursesByCategory($categoryID) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$categoryID = validate($categoryID);
|
|
|
|
|
|
|
|
// Abfrage, um alle Kurse abzurufen, die einer bestimmten Kategorie zugeordnet sind
|
|
|
|
$query = "SELECT * FROM tbl_courses WHERE category_id = '$categoryID'";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
$courses = [];
|
|
|
|
|
|
|
|
if ($result && mysqli_num_rows($result) > 0) {
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$courses[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $courses;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getStudentAssignments($studentID)
|
|
|
|
{
|
|
|
|
global $conn;
|
|
|
|
$studentID = validate($studentID);
|
|
|
|
$query = "SELECT * FROM tbl_assign_students_courses WHERE student_id = $studentID";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$assignments = array();
|
|
|
|
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$assignments[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $assignments;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-14 07:44:19 +01:00
|
|
|
function updatePassword($userId, $newPassword) {
|
|
|
|
global $conn;
|
|
|
|
$userId = validate($userId);
|
|
|
|
$newPassword = validate($newPassword);
|
|
|
|
|
|
|
|
$query = "UPDATE users SET password='$newPassword' WHERE id='$userId'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteResetToken($userId) {
|
|
|
|
global $conn;
|
|
|
|
$userId = validate($userId);
|
|
|
|
|
|
|
|
$query = "UPDATE users SET reset_token=NULL, reset_token_expiry=NULL WHERE id='$userId'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2025-01-07 03:02:25 +01:00
|
|
|
function isStudentRegisteredForCourse($studentId, $courseId) {
|
|
|
|
// Hier eine Abfrage zur Datenbank machen, um zu prüfen, ob ein Eintrag in tbl_assign_students_courses existiert
|
|
|
|
global $conn; // Annahme, dass $conn die Datenbankverbindung ist
|
|
|
|
$query = "SELECT COUNT(*) FROM tbl_assign_students_courses WHERE student_id = ? AND course_id = ?";
|
|
|
|
$stmt = $conn->prepare($query);
|
|
|
|
$stmt->bind_param('ii', $studentId, $courseId);
|
|
|
|
$stmt->execute();
|
|
|
|
$stmt->bind_result($count);
|
|
|
|
$stmt->fetch();
|
|
|
|
$stmt->close();
|
|
|
|
|
2025-01-14 14:21:19 +01:00
|
|
|
return $count = 0;
|
2025-01-07 03:02:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Function to get all courses assigned to a student
|
|
|
|
function getAllAssignedCourses($studentID) {
|
|
|
|
global $conn;
|
|
|
|
$assignedCourses = array();
|
|
|
|
|
|
|
|
$query = "SELECT course_id FROM tbl_assign_students_courses WHERE student_id = '$studentID'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$assignedCourses[] = $row['course_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $assignedCourses;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllAssignedCoursesByCategory($studentID, $categoryID) {
|
|
|
|
global $conn;
|
|
|
|
$assignedCourses = array();
|
|
|
|
|
|
|
|
$query = "SELECT tac.course_id FROM tbl_assign_students_courses tac
|
|
|
|
JOIN tbl_courses tc ON tac.course_id = tc.id
|
|
|
|
WHERE tac.student_id = '$studentID' AND tc.category_id = '$categoryID'";
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$assignedCourses[] = $row['course_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $assignedCourses;
|
|
|
|
}
|
|
|
|
|
2025-01-14 14:21:19 +01:00
|
|
|
// Funktion, die alle Schüler zählt, die einer Klasse zugewiesen sind, die der Kategorie und dem Kurs zugeordnet ist
|
|
|
|
function countAllStudentsInCourse($courseID) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
// Abfrage, um alle Schüler zu zählen, deren Klasse der Kategorie und dem Kurs zugeordnet ist
|
|
|
|
$query = "
|
|
|
|
SELECT COUNT(DISTINCT s.id)
|
|
|
|
FROM tbl_students s
|
|
|
|
INNER JOIN tbl_assign_categories_classes acc ON s.class = acc.class_id
|
|
|
|
INNER JOIN tbl_assign_courses_classes acc_courses ON acc.class_id = acc_courses.class_id
|
|
|
|
WHERE acc_courses.course_id = '$courseID'
|
|
|
|
AND acc.category_id = (
|
|
|
|
SELECT category_id FROM tbl_courses WHERE id = '$courseID'
|
|
|
|
)
|
|
|
|
";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_row($result);
|
|
|
|
return $row[0]; // Gibt die Anzahl der Schüler zurück
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // Falls keine Schüler gefunden wurden
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Funktion, um Schüler nach Status zu zählen
|
|
|
|
function countStudentsByStatus($courseID, $status) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
// SQL-Abfrage, um die Anzahl der Schüler mit einem bestimmten Status zu zählen
|
|
|
|
$query = "
|
|
|
|
SELECT COUNT(DISTINCT s.id)
|
|
|
|
FROM tbl_students s
|
|
|
|
INNER JOIN tbl_assign_categories_classes acc ON s.class = acc.class_id
|
|
|
|
INNER JOIN tbl_assign_courses_classes acc_courses ON acc.class_id = acc_courses.class_id
|
|
|
|
INNER JOIN tbl_assign_students_courses asc_tbl ON asc_tbl.student_id = s.id
|
|
|
|
WHERE acc_courses.course_id = '$courseID'
|
|
|
|
AND acc.category_id = (
|
|
|
|
SELECT category_id FROM tbl_courses WHERE id = '$courseID'
|
|
|
|
)
|
|
|
|
AND asc_tbl.status = '$status'
|
|
|
|
";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_row($result);
|
|
|
|
return $row[0]; // Gibt die Anzahl der Schüler mit diesem Status zurück
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // Falls keine Schüler gefunden wurden
|
|
|
|
}
|
|
|
|
|
|
|
|
function countStudentsWithoutSelection($classID, $categoryID) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
SELECT COUNT(DISTINCT s.id) AS no_selection_count
|
|
|
|
FROM tbl_students s
|
|
|
|
LEFT JOIN tbl_assign_students_courses asc_tbl
|
|
|
|
ON asc_tbl.student_id = s.id
|
|
|
|
AND asc_tbl.course_id IN (
|
|
|
|
SELECT id
|
|
|
|
FROM tbl_courses
|
|
|
|
WHERE category_id = '$categoryID'
|
|
|
|
)
|
|
|
|
WHERE s.class = '$classID'
|
|
|
|
AND asc_tbl.course_id IS NULL
|
|
|
|
";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
return $row['no_selection_count'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // Falls keine Schüler gefunden wurden
|
|
|
|
}
|
|
|
|
|
|
|
|
function countStudentsInClass($classID) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
SELECT COUNT(*) AS student_count
|
|
|
|
FROM tbl_students
|
|
|
|
WHERE class = '$classID'
|
|
|
|
";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
return $row['student_count'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // Falls keine Schüler in der Klasse gefunden wurden
|
|
|
|
}
|
|
|
|
|
|
|
|
function countStudentsWithSelection($classID, $categoryID) {
|
|
|
|
global $conn;
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
SELECT COUNT(DISTINCT s.id) AS selected_count
|
|
|
|
FROM tbl_students s
|
|
|
|
JOIN tbl_assign_students_courses asc_tbl
|
|
|
|
ON s.id = asc_tbl.student_id
|
|
|
|
WHERE s.class = '$classID'
|
|
|
|
AND asc_tbl.course_id IN (
|
|
|
|
SELECT id
|
|
|
|
FROM tbl_courses
|
|
|
|
WHERE category_id = '$categoryID'
|
|
|
|
)
|
|
|
|
";
|
|
|
|
|
|
|
|
$result = mysqli_query($conn, $query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
return $row['selected_count'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // Falls keine Schüler mit einer Auswahl gefunden wurden
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-01-07 03:02:25 +01:00
|
|
|
?>
|