Ejemplo n.º 1
0
             $emailadres = filter_var(trim($_POST['emailadres']), FILTER_VALIDATE_EMAIL);
             if (!$emailadres) {
                 $_SESSION['message'] = 'Voer een geldig e-mailadres in.';
             } else {
                 $role = 2;
                 // is leraar
                 $account_activated = 0;
                 //account is nog niet geactiveerd, dit wordt pas gedaan als gebruiker eerste keer inlogt.
                 $generated_password = generate_random_password();
                 $wachtwoord = password_hash($generated_password, PASSWORD_BCRYPT);
                 $email_code = md5($voornaam + microtime());
                 $gegevens = ["voornaam" => $voornaam, "tussenvoegsel" => $tussenvoegsel, "achternaam" => $achternaam, "emailadres" => $emailadres, "email_code" => $email_code, "wachtwoord" => $wachtwoord, "account_activated" => $account_activated, "role" => $role, "docent_afkorting" => $docent_afkorting];
                 //checken of email en afkorting uniek zijn
                 if (checkIfUserExists($gegevens["emailadres"]) === FALSE) {
                     //leraar toevoegen
                     addTeacher($gegevens);
                     //wachtwoord mailen naar gebruiker
                     $mail_gegevens = ["emailadres" => $gegevens["emailadres"], "voornaam" => $gegevens["voornaam"], "tussenvoegsel" => $gegevens["tussenvoegsel"], "achternaam" => $gegevens["achternaam"], "wachtwoord" => $generated_password];
                     $mail_content = createTempPasswordMail($mail_gegevens);
                     sendMail($mail_content);
                 } else {
                     //email adres is al in gebruik.
                     $_SESSION['message'] = "Email adres is al in gebruik";
                 }
             }
         }
     }
 } else {
     // voor als een docent bewerkt wordt
     $gebruiker_id = filter_var(trim($_POST['gebruiker_id']), FILTER_SANITIZE_STRING);
     $voornaam = filter_var(trim($_POST['voornaam']), FILTER_SANITIZE_STRING);
Ejemplo n.º 2
0
             } else {
                 $role = 2;
                 // is leraar
                 $account_activated = 0;
                 //account is nog niet geactiveerd, dit wordt pas gedaan als gebruiker eerste keer inlogt.
                 $generated_password = generate_random_password();
                 $wachtwoord = password_hash($generated_password, PASSWORD_BCRYPT);
                 $email_code = md5($voornaam + microtime());
                 //returned $generated_password
                 $gegevens = ["voornaam" => $voornaam, "tussenvoegsel" => $tussenvoegsel, "achternaam" => $achternaam, "emailadres" => $emailadres, "email_code" => $email_code, "generated_password" => $generated_password, "wachtwoord" => $wachtwoord, "account_activated" => $account_activated, "role" => $role, "docent_afkorting" => $docent_afkorting];
                 //checken of email en afkorting uniek zijn
                 if (checkIfUserExists($gegevens["emailadres"]) === FALSE) {
                     //email adres niet in gebruik, dus gebruiker kan worden toegevoegd.
                     // gegevens inserten
                     addUser($gegevens);
                     addTeacher($gegevens["emailadres"], $gegevens["docent_afkorting"]);
                     //nog niet af!!
                     //wachtwoord mailen naar gebruiker
                     $mail_content = createTempPasswordMail($gegevens);
                     sendMail($mail_content);
                 } else {
                     //email adres in gebruik gebruiker wordt op de hoogte gesteld dat dit email adres bezet is.
                     $_SESSION['message'] = "Email adres is al in gebruik";
                 }
             }
         }
     }
 } else {
     // voor als een docent bewerkt wordt
     $gebruiker_id = filter_var(trim($_POST['gebruiker_id']), FILTER_SANITIZE_STRING);
     $voornaam = filter_var(trim($_POST['voornaam']), FILTER_SANITIZE_STRING);
Ejemplo n.º 3
0
function saveUser($servername, $username, $password, $db, $port, $name, $type, $active, $classes)
{
    $conn = mysqli_connect($servername, $username, $password, $db, $port);
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    $sql = "SELECT * FROM user WHERE userName = \"{$name}\"";
    $result = mysqli_query($conn, $sql);
    if ($result) {
        if (mysqli_num_rows($result) > 0) {
            /*person exists*/
            $sql = "SELECT us.type\n\t\t\t\t\tFROM user as u\n\t\t\t\t\tJOIN usertype as us\n\t\t\t\t\tON u.userID = us.userID\n\t\t\t\t\tWHERE u.userName = \"{$name}\"\n\t\t\t\t\tAND us.type = \"{$type}\"";
            $result = mysqli_query($conn, $sql);
            if (mysqli_num_rows($result) > 0) {
                /*user has had this type before */
                mysqli_close($conn);
                return true;
            }
            $sql = "SELECT userID FROM user WHERE userName = \"{$name}\"";
            $result = mysqli_query($conn, $sql);
            $userID = mysqli_fetch_assoc($result)["userID"];
            $sql = "INSERT INTO usertype (userID, type)\n\t\t\t\t\tVALUES ({$userID}, \"{$type}\");";
            $result = mysqli_query($conn, $sql);
            if ($type = "Instructor") {
                addTeacher($servername, $username, $password, $db, $port, $name, $active);
            }
            mysqli_close($conn);
            return true;
            /*
            while ($row = mysqli_fetch_assoc($result)) {
            	echo "userID: " . $row["userID"] . " Name: " . $row["userName"];
            }
            */
        } else {
            /*add the new person*/
            $sql = "INSERT INTO user (userName)\n\t\t\t\t\tVALUES (\"{$name}\")";
            mysqli_query($conn, $sql);
            $id = mysqli_insert_id($conn);
            $sql = "INSERT INTO usertype (userID, type)\n\t\t\t\t\tVALUES ({$id}, \"{$type}\");";
            foreach (array_keys($classes) as $class) {
                $sql .= "INSERT INTO attending (userID, title)\n\t\t\t\t\t\t VALUES ({$id}, \"{$class}\");";
            }
            if (!mysqli_multi_query($conn, $sql)) {
                mysqli_close($conn);
                die("Error: " . mysqli_error($conn));
            }
            if ($type = "Instructor") {
                addTeacher($servername, $username, $password, $db, $port, $name, $active);
            }
            mysqli_close($conn);
            return False;
        }
    } else {
        mysqli_close($conn);
        die("Error: " . mysqli_error($conn));
    }
}
Ejemplo n.º 4
0
            // arrays
            $teachers_array = $_GET['teachers_array'];
            $days_array = $_GET['days_array'];
            $css_top_array = $_GET['css_top_array'];
            $css_left_array = $_GET['css_left_array'];
            $css_bg_array = $_GET['css_bg_array'];
            $css_fore_array = $_GET['css_fore_array'];
            // handle connection
            $connection = (include 'connection.php');
            if ($connection == null) {
                fwrite($fh, date("m/d/Y h:i:s a", time()) . "...ERROR Line#34 (get_data.php): Error while connecting to server: " . PHP_EOL);
            } else {
                emptyTable($fh, $connection, 'teachers');
                // store teachers
                for ($i = 0; $i < count($teachers_array); $i++) {
                    // add teacher
                    $teacher = $teachers_array[$i];
                    $css_top = $css_top_array[$i];
                    $css_left = $css_left_array[$i];
                    $css_bg = $css_bg_array[$i];
                    $css_fore = $css_fore_array[$i];
                    fwrite($fh, "TEACHER: " . $teacher . " " . $days_array[$i] . "\n");
                    $dayID = getTeacherDayID($fh, $connection, $days_array[$i]);
                    addTeacher($fh, $connection, $teacher, $css_top, $css_left, $css_bg, $css_fore, $dayID);
                }
            }
            fclose($fh);
        } else {
        }
    }
}