Files
OpenDRS/distfiles/login.php

151 lines
4.4 KiB
PHP

<?php
/*
login.php
OpenDRS Online Discrepancy Reporting System
Copyright (C) 2026 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("common.php");
if (array_key_exists('print',$_REQUEST)) {
$print=true;
} else {
$print=false;
}
// import incoming arrays
if ($print) {
// if printer friendly was clicked, values will be passed in serialized
// form as "all_parameters" so we need to load those into $incoming[]
$incoming=unserialize($_REQUEST['all_parameters']);
} else {
// copy $_REQUEST[] to $incoming[]
$incoming=arrayCopy($_REQUEST);
}
// extract incoming array keys into variables
extract($incoming, EXTR_SKIP);
/*
* possible keys are:
* userid
* userlogin
* pass
* login
* cancel
*/
if (!isset($userlogin)) $userlogin=NULL;
if (!isset($pass)) $pass=NULL;
if (isset($cancel)) {
session_destroy();
} else {
$cancel=false;
}
$appname=APP_NAME;
if ($print) {
$mbgcolor=P_MENUBG_COLOR;
} else {
$mbgcolor=MENUBG_COLOR;
}
framework("begin","$appname","Login Page",$print);
//echo "_REQUEST array <br>";
//var_dump($_REQUEST);
//echo "<br><hr> incoming array <br>";
//var_dump($incoming);
pagetable("begin");
if(!$print){
pageblock("left","begin");
$printable=false;
sidemenu($printable);
pageblock("left","end");
}
pageblock("right","begin");
if (isset($login)) {
// get the id from the userlogin
$userid=dblookup($drs_db,"users","login","id",$userlogin);
$useractive=dblookup($drs_db,"users","id","active",$userid);
// log me in
$pwhash=mysqli_fetch_row(mysqli_query($drs_db,"select password_hash from users where id=\"$userid\""))[0];
if ($userid) {
if ($useractive) {
if (password_verify($pass, $pwhash)) {
$_SESSION['userid']=$userid;
echo "
<script>location.assign(\"login.php\");</script>
";
} else {
$admins=mysqli_query($drs_db,"select firstname,lastname from users where active is true and role=\"".ADMIN."\"");
echo "
Incorrect password. Please <a href=\"login.php\">try again</a>.<br><br>
Forgot your password? Contact an administrator:<br><br>
";
while ($adminrow=mysqli_fetch_assoc($admins)) {
$firstname=$adminrow["firstname"];
$lastname=$adminrow["lastname"];
echo "$firstname $lastname <br>";
}
}
} else {
$admins=mysqli_query($drs_db,"select firstname,lastname from users where active is true and role=\"".ADMIN."\"");
echo "
Your account is inactive. Please contact one of these administrators:<br><br>
";
while ($adminrow=mysqli_fetch_assoc($admins)) {
$firstname=$adminrow["firstname"];
$lastname=$adminrow["lastname"];
echo "$firstname $lastname <br>";
}
}
} else {
$admins=mysqli_query($drs_db,"select firstname,lastname from users where active is true and role=\"".ADMIN."\"");
echo "
Incorrect password. Please <a href=\"login.php\">try again</a>.<br><br>
Forgot your password? Contact an administrator:<br><br>
";
while ($adminrow=mysqli_fetch_assoc($admins)) {
$firstname=$adminrow["firstname"];
$lastname=$adminrow["lastname"];
echo "$firstname $lastname <br>";
}
}
} else if ($cancel) {
echo "
<script>location.assign(\"login.php\");</script>
";
} else {
if (!isset($_SESSION['userid'])) {
// show the login form
echo "
<form method=\"post\" action=\"login.php\">
Login: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" name=\"userlogin\" size=\"40\">
<br><br>
Password: &nbsp;<input type=\"password\" name=\"pass\" size=\"40\"><br><br>
<input type=\"submit\" name=\"login\" value=\"Log In\">&nbsp;&nbsp;&nbsp;&nbsp;
<input type=\"submit\" name=\"cancel\" value=\"Cancel\"><br>
</form>
<br><hr>
";
} else {
$userid=$_SESSION['userid'];
$firstname=mysqli_fetch_row(mysqli_query($drs_db,"select firstname from users where id=\"$userid\""))[0];
echo "
Welcome $firstname. Please select a menu option at the left to continue.<br><hr>
";
}
}
pageblock("right","end");
pagetable("end");
framework("end","","",$print);
?>