<commit_before><?php
function can_edit($args) {
    return ($_SESSION["student-id"] === $args["from"])
        && ($args["verdict"] == 0);
}
function can_see($args) {
    return (($_SESSION["student-id"] === $args["from"])
        && ($args["verdict"] == 0))
        || ($args["verdict"] > 0);
}
?>
<?php if($_SERVER['REQUEST_METHOD'] === "POST") : // User edits this klandring ?>
<?php else: // User is just view this klanndring ?>
<div class="panel panel-default">
    <div class="panel-heading">Klandring</div>
    <div class="panel-body">
<?php if(can_edit($arguements)) : ?>
<form action="/klandring/<?php echo $arguements["id"]; ?>" id="edit-klandring" method="POST">
    <div class="form-group">
        <div class="input-group">
            <span class="input-group-addon">Titel</span>
            <input type="text" class="form-control" name="title" value="<?php echo $arguements["title"]; ?>" required>
        </div>
        <br>
        <div class="input-group">
            <select name="klandret" required>
                <option value="">Vælg person</option>
<?php
$db = new mysqli(MYSQL_PROVIDER, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
$db->set_charset("utf8");
$sql = "SELECT id, name FROM student WHERE 1";
$result = $db->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<option value='" . $row["id"] . ($row["id"] === $arguements["to"] ? "' selected" : "'") . ">" . $row["name"] . "</option>";
    }
}
$result->free();
$db->close();
?><commit_msg>Added edit functionality to the klandring<commit_after><?php
function can_edit($args) {
    return ($_SESSION["student-id"] === $args["from"])
        && ($args["verdict"] == 0);
}
function can_see($args) {
    return can_edit($args) // If we can edit it
        || $args["verdict"] > 0; // or it has been decided.
}
?>
<?php if($_SERVER['REQUEST_METHOD'] === "POST") : // User edits this klandring ?>
<?php 
if(!can_edit($arguements)) {
    echo "WHAT THE FUCK DID YOU DO!";
    die();
}
$db = new mysqli(MYSQL_PROVIDER, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
$db->set_charset("utf8");

$title       = $db->real_escape_string($_POST["title"]);
$to          = $db->real_escape_string($_POST["klandret"]);
$description = $db->real_escape_string($_POST["description"]);
$sql = "UPDATE klandring SET title = '$title', description = '$description', `to` = '$to' WHERE id = " . $arguements["id"] . ";";

$db->query($sql);
$db->close();
header("Location: /klandring/" .  $arguements["id"]);
?>
<?php else: // User is just view this klanndring ?>
<div class="panel panel-default">
    <div class="panel-heading">Klandring</div>
    <div class="panel-body">
<?php if(can_edit($arguements)) : ?>
<form action="/klandring/<?php echo $arguements["id"]; ?>" id="edit-klandring" method="POST">
    <div class="form-group">
        <div class="input-group">
            <span class="input-group-addon">Titel</span>
            <input type="text" class="form-control" name="title" value="<?php echo $arguements["title"]; ?>" required>
        </div>
        <br>
        <div class="input-group">
            <select name="klandret" required>
                <option value="">Vælg person</option>
<?php
$db = new mysqli(MYSQL_PROVIDER, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
$db->set_charset("utf8");
$sql = "SELECT id, name FROM student WHERE 1";
$result = $db->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<option value='" . $row["id"] . ($row["id"] === $arguements["to"] ? "' selected" : "'") . ">" . $row["name"] . "</option>";
    }
}
$result->free();
$db->close();
?>
{'fraction_non_alphanumeric': 0.22397390595270453, 'fraction_numerical': 0.0032617559119325905, 'mean_word_length': 3.717948717948718, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3073202', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1260, 'n_words': 273}