$_SESSION['error'] = "You can only validate users from your own centre"; } else { if (!$newUser->email || $newPriv == 10 && $newUser->getPrivilege() == 99 || $newPriv == 15 && $newUser->getPrivilege() == 98) { $_SESSION['error'] = "An error has occurred."; } else { $newUser->setPrivilege($newPriv); // Data entry privilege $password = $newUser->generatePassword(); // Generate new password $newUser->setPassword($password, $user->getKey()); // Set it for the user $email = $newUser->writeEmail('created', $user, $password); // Send email with username and password $mail = $trial->sendEmail($email); if ($mail) { $newUser->saveToDB(); if (isset($_SESSION['message'])) { $_SESSION['message'] = "Users successfully validated."; } else { $_SESSION['message'] = "User successfully validated."; } } elseif ($_SERVER['HTTP_HOST'] == 'localhost') { $_SESSION['message'] = "User validated - Password {$password}"; $newUser->saveToDB(); } else { $_SESSION['error'] = "An error has occurred sending email, please try again."; } } } } }