/** Fügt einen Benutzer hinzu. * * @param string $email Die E-Mail Adresse des Benutzers (zum Versenden der E-Mail benötigt) * @param integer $class ID der zugehörigen Klasse * @param integer $type Typ des Benutzers (access_level) (0: admin; 1: teacher; 2: user) * @param string $realname Der "echte" Name des Benutzers * @param float $valid Anzahl Wochen, die vergehen, bis die Registrierung abläuft * @return bool false im Fehlerfall, es wird eine Warnung oder ein Fehler erzeugt */ public function addUser($email, $class = 0, $type = 2, $realname = null, $valid = 2) { if (!$this->permitted) { return false; } // Werte validieren $type = intval($type); $valid = floatval($valid); $class = intval($class); $error = false; if ($type < 0 || $type > 2) { $this->throwWarning('The access level of the new user is invalid.'); $error = true; } if ($valid < 1 || $valid > 5) { $this->throwWarning('The user must be enabled or disabled. There was an invalid value.'); $error = true; } $email = parseEmail($email); if (!$email) { $this->throwWarning('The given e-mail address is invalid.'); $error = true; } // Prüfen ob Fehler aufgetreten if ($error) { return false; } $valid = date('Y-m-d H:i:s', time() + $valid * 630000); // Registrierungshash $hash = md5(uniqid(microtime(), true)) . '-' . uniqid(); // Benutzer in DB hinzufügen $db = getDB(); if (!$db->query('addUser', array('hash' => $hash, 'accessLevel' => $type, 'realName' => $realname, 'email' => $email, 'valid' => $valid, 'class' => $class))) { return $this->throwError('While creating the new user, a technical error occurred. The user wasn\'t created.'); } // Einladungsmail vorbereiten $link = new Template(SYS_MAIL_INVITE_LINK); $link->assign('hash', $hash); $link->assign('id', $db->insertID); $tmpl = new Template(SYS_MAIL_INVITE_MAIL); $tmpl->setTitle(SYS_MAIL_INVITE_SUBJECT); $tmpl->assign('name', $realname); $tmpl->assign('link', $link); // Einladungsmail senden if (!mail($email, SYS_MAIL_INVITE_SUBJECT, $tmpl, 'Content-Type: text/html; charset=utf-8' . PHP_EOL . 'From: ' . SYS_NOREPLY)) { return $this->throwError('A technical error occurred: The e-mail with the invitation link has not been sent. The user has not been invited.'); } return true; }