0; } /* * Log an error, warning, or notice */ function logError(string $level, string $error) : void { global $_SCROTT; $_SCROTT[$level][] = $error; } /* * Get an array of all errors, warnings, or notices */ function getErrors(string $level) : array { global $_SCROTT; return $_SCROTT[$level]; } /* * Save an uploaded file and impose some constraints on supplied * data. Caller can optionally pass some strings by reference to * be given the supplied file's original name and mime-type. * Maxsize is in bytes. If this function returns false, the * appropriate error will be logged. */ function saveFile(array $file, string $path, int $maxsize, ?array $allowedMime = NULL, ?string &$origName = NULL, ?string &$origMime = NULL) : bool { if ($file['error'] > 0) { if ($file['error'] != UPLOAD_ERR_NO_FILE) logError(ERROR, "An unknown error occurred"); return false; } if ($file['size'] > $maxsize) { logError(ERROR, "File must be no larger than " . $maxsize . " bytes"); return false; } if (is_array($allowedMime) && array_search($file['type'], $allowedMime) === false) { logError(ERROR, "File type is not supported"); return false; } if (!move_uploaded_file($file['tmp_name'], $path)) { logError(ERROR, "Error saving uploaded file"); return false; } $origName = $file['name']; $origMime = $file['type']; return true; } /* * Send an email message using database-stored configuration * parameters. If config is not established, delivery is * not attempted. Send status (t/f) is returned. */ function sendEmail(string $subject, user $rcpt, string $mesg, ?string $attachPath = NULL, ?string $attachName = NULL, bool $overrideEmailConf = false) : bool { if (settings::smtpServer() == "") return false; if (!$overrideEmailConf && !$rcpt->emailConf) return true; if ($rcpt->email == "") return true; $mail = new PHPMailer(); $mail->isSMTP(); $mail->SMTPAuth = true; $mail->Host = settings::smtpServer(); $mail->Username = settings::smtpUname(); $mail->Password = settings::smtpPasswd(); $mail->SMTPSecure = settings::smtpSecurity(); $mail->Port = settings::smtpPort(); $mail->setFrom(settings::smtpEmailAddress()); $mail->addAddress($rcpt->email, $rcpt->getDisplayName()); $mail->Subject = $subject; $mail->Body = $mesg; if ($attachPath && $attachName) $mail->addAttachment($attachPath, $attachName); return $mail->send(); } ?>