<commit_before><?php

require 'taiga.php';
require '../vendor/autoload.php';

// Initialize
$type = 0;
$types[] = array('id' => 0, 'name' => '');
$level = 0;
$levels[] = array('id' => 0, 'name' => '');

$status = array('id' => 0, 'name' => 'Ny');

$comments = array();

// Get information from Taiga
if($auth = taiga_login()) {

    $types = array_merge($types, taiga_get_issue_types($auth));
    $levels = array_merge($levels, taiga_get_severity_levels($auth));

    if (isset($_POST["submit"])) {
        $name = isset_get($_POST, 'name');
        $email = isset_get($_POST, 'email');
        $subject = isset_get($_POST, 'subject');
        $type = intval(isset_get($_POST, 'type'));
        $level = intval(isset_get($_POST, 'level'));
        $description = isset_get($_POST, 'description');
        $human = isset_get($_POST, 'human');

        // Check if title has been entered
        if (!$subject) {
            $errSubject = 'Skriv inn en kort beskrivende tekst';
        }

        //Check if message has been entered
        if (!$description) {
            $errDesc = 'Skriv inn din tilbakemelding';
        }

        // Check if type has been selected
        if (!$type) {
            $errType = 'Velg type tilbakemelding';
        }

        // Check if severity level has been selected
        if (!$level) {
            $errLevel = 'Velg alvorlighetsgrad';
        }

        // Check if name has been entered
        if (!$name) {
            $errName = 'Skriv inn ditt navn';
        }

        // Check if email has been entered and is valid
        if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Skriv inn en gyldig e-postadresse';
        }

        //Check if simple anti-bot test is correct
        if (intval($human) !== 5) {
            $errHuman = 'Ditt svar er feil, prøv igjen';
        }

        // If there are no errors, send the email
        if (!$errSubject && !$errDesc && !$errType && !$errLevel && !$errName && !$errEmail && !$errHuman) {
            if (isset($_GET['id'])) {
                $issue = taiga_edit_issue_by_ref($auth, $_GET['id']);
            } else {
                $issue = taiga_create_issue($auth);
            }
            if ($issue) {
                $ref = $issue['ref'];
                $result = '<div class="alert alert-success">Takk! <a href="' . $ref . '">Tilbakemelding ' . $ref . '</a> er registrert. Vi vil ta kontakt når din tilbakemelding er behandlet. </div>';

                if(isset($issue['id'])) {
                    $comments = taiga_get_issue_comments($auth, $issue['id']);
                } else {
                    notify('Tilbakemelding ' . $ref . ' er registrert', $email, $result);
                }
            }
        }
        if (!isset($result) && !($errSubject || $errDesc || $errType || $errLevel || $errName || $errEmail || $errHuman)) {
            $result = '<div class="alert alert-danger">Beklager, din henvendelse kunne ikke registres.</div>';
        }
    } else {
        if (isset($_GET['id'])) {
            if ($issue = taiga_get_issue_by_ref($auth, $_GET['id'])) {
                $subject = isset_get($issue, 'subject');
                $type = isset_get($issue, 'type');
                $status = isset_get($issue, 'status_extra_info');
		        $assigned = isset_get($issue, 'assigned_to_extra_info');
		        $level = isset_get($issue, 'severity');
                $description = isset_get($issue, 'description');
                if ($attrs = taiga_get_issue_attributes($auth, $issue['id'])) {
                    $attrs = $attrs['attributes_values'];
                    $name = isset_get($attrs, '1164');
                    $email = isset_get($attrs, '1165');
                }
                $comments = taiga_get_issue_comments($auth, $issue['id']);
            }
        }
    }
} else {
    $result = '<div class="alert alert-danger">Beklager, din henvendelse kan ikke registres. Prøv igjen senere.</div>';
}
?>
<commit_msg>Added SMTP support<commit_after><?php

require 'taiga.php';
require '../vendor/autoload.php';

// Initialize
$type = 0;
$types[] = array('id' => 0, 'name' => '');
$level = 0;
$levels[] = array('id' => 0, 'name' => '');

$status = array('id' => 0, 'name' => 'Ny');

$comments = array();

// Get information from Taiga
if($auth = taiga_login()) {

    $types = array_merge($types, taiga_get_issue_types($auth));
    $levels = array_merge($levels, taiga_get_severity_levels($auth));

    if (isset($_POST["submit"])) {
        $name = isset_get($_POST, 'name');
        $email = isset_get($_POST, 'email');
        $subject = isset_get($_POST, 'subject');
        $type = intval(isset_get($_POST, 'type'));
        $level = intval(isset_get($_POST, 'level'));
        $description = isset_get($_POST, 'description');
        $human = isset_get($_POST, 'human');

        // Check if title has been entered
        if (!$subject) {
            $errSubject = 'Skriv inn en kort beskrivende tekst';
        }

        //Check if message has been entered
        if (!$description) {
            $errDesc = 'Skriv inn din tilbakemelding';
        }

        // Check if type has been selected
        if (!$type) {
            $errType = 'Velg type tilbakemelding';
        }

        // Check if severity level has been selected
        if (!$level) {
            $errLevel = 'Velg alvorlighetsgrad';
        }

        // Check if name has been entered
        if (!$name) {
            $errName = 'Skriv inn ditt navn';
        }

        // Check if email has been entered and is valid
        if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Skriv inn en gyldig e-postadresse';
        }

        //Check if simple anti-bot test is correct
        if (intval($human) !== 5) {
            $errHuman = 'Ditt svar er feil, prøv igjen';
        }

        // If there are no errors, send the email
        if (!$errSubject && !$errDesc && !$errType && !$errLevel && !$errName && !$errEmail && !$errHuman) {
            if (isset($_GET['id'])) {
                $issue = taiga_edit_issue_by_ref($auth, $_GET['id']);
            } else {
                $issue = taiga_create_issue($auth);
            }
            if ($issue) {
                $ref = $issue['ref'];
                $result = 'Takk! <a href="' . $ref . '">Tilbakemelding ' . $ref . '</a> er registrert. Vi vil ta kontakt når din tilbakemelding er behandlet.';

                if(isset($issue['id'])) {
                    $comments = taiga_get_issue_comments($auth, $issue['id']);
                } else {
                    $result = 'Takk! <a href="' . $ref . '">Tilbakemelding ' . $ref . '</a> er registrert. ';
                    if(notify('Tilbakemelding ' . $ref . ' er registrert', $email, $result)) {
                        $result .= 'Kvittering er sendt til ' . $email . '. ';
                    }
                    $result .= 'Vi vil ta kontakt når din tilbakemelding er behandlet.';

                }
                $result = '<div class="alert alert-success">' . $result . '</div>';
            }
        }
        if (!isset($result) && !($errSubject || $errDesc || $errType || $errLevel || $errName || $errEmail || $errHuman)) {
            $result = '<div class="alert alert-danger">Beklager, din henvendelse kunne ikke registres.</div>';
        }
    } else {
        if (isset($_GET['id'])) {
            if ($issue = taiga_get_issue_by_ref($auth, $_GET['id'])) {
                $subject = isset_get($issue, 'subject');
                $type = isset_get($issue, 'type');
                $status = isset_get($issue, 'status_extra_info');
		        $assigned = isset_get($issue, 'assigned_to_extra_info');
		        $level = isset_get($issue, 'severity');
                $description = isset_get($issue, 'description');
                if ($attrs = taiga_get_issue_attributes($auth, $issue['id'])) {
                    $attrs = $attrs['attributes_values'];
                    $name = isset_get($attrs, '1164');
                    $email = isset_get($attrs, '1165');
                }
                $comments = taiga_get_issue_comments($auth, $issue['id']);
            }
        }
    }
} else {
    $result = '<div class="alert alert-danger">Beklager, din henvendelse kan ikke registres. Prøv igjen senere.</div>';
}
?>

{'fraction_non_alphanumeric': 0.16257337965736193, 'fraction_numerical': 0.0033544986222594944, 'mean_word_length': 2.0007189072609632, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 35, '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': '2322191', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2556, 'n_words': 617}