Sisesta oma kasutajanimi ja me saadame parooli sinu e-posti aadressile
(mis on määratud sinu kasutajainfos). Kui teie kasutajainfos
pole e-posti aadressi määratud, teavitatakse teie parooli kaotsiminekust VIKO
kooliadministraatorit.
EOHTML;
}
function create_message($title, $message)
{
return <<
EOHTML;
}
function send_password_to_user($user, $password)
{
mail(
$user['email'],
"VIKO: Paroolivahetus",
<<"
);
}
function send_notice_to_admin($admin_email, $user_without_password)
{
mail(
$admin_email,
"VIKO: Kasutaja $user_without_password[username] kaotas parooli",
<<"
);
}
function get_school_admins( $school_id )
{
$result = mysql_query("
SELECT *
FROM Users
WHERE LEVEL = 2
AND school_id = $school_id
LIMIT 1"
);
if ( mysql_num_rows($result) > 0 )
{
$school_admin_list = array();
while ( $school_admin = mysql_fetch_array($result) )
{
$school_admin_list[] = $school_admin;
}
return $school_admin_list;
}
else
{
return false;
}
}
if ( isset($_POST['submit']) && isset($_POST['username']) )
{
// if user with that name exists
if ( $userinfo = get_user_info($_POST['username']) )
{
// if user has e-mail address, send new password to this e-mail
// The following test only checks for e-mail address existance,
// the check for address correctness has to be performed in some
// other place, where e-mail address is entered.
// Actually this test really shouldn't be needed, as entering
// e-mail address when adding users or registering to user
// is required anyway, but some users are probably registered
// before this requirement was implemented.
if ( strlen($userinfo['email']) > 0 )
{
// generate new password consisting of 8 alphanumeric characters
$new_password = Text_Password::create(8, 'unpronounceable', 'alphanumeric');
// change the password
save_password($userinfo['username'], $new_password);
// e-mail password to user
send_password_to_user($userinfo, $new_password);
// display success message
echo create_message(
"Parool edukalt muudetud",
"Uus parool on saadetud kasutaja '$userinfo[username]' e-posti aadressile."
);
}
else
{
// find out who is the school-admin of this user
if ( $school_admin_list = get_school_admins( $userinfo["school_id"] ) )
{
// send notice to all admins of this school
// NOTE: I'm not sure, this is the best behaviour, but it's
// better than sending note only to one random admin.
foreach ( $school_admin_list as $school_admin )
{
send_notice_to_admin($school_admin['email'], $userinfo);
}
echo create_message(
"E-posti aadress puudub!",
"Kasutajal '$userinfo[username]' pole e-posti aadressi määratud, ".
"mistõttu pole võimalik automaatselt uut parooli saata. ".
"Teade teie probleemist sisselogimisel on edastatud teie kooli administraatorile."
);
}
else
{
die("Viga andmebaasis! Kooliadministraator puudub.");
}
}
}
else
{
// when user doesn't exist, display error message
echo create_message(
"Kasutajat $_POST[username] ei eksisteeri!",
"Kasutajanime '$_POST[username]' ei leitud VIKO kasutajate hulgast. ".
"Kontrolli kas oled oma kasutajanime õigesti sisestanud."
);
echo create_ask_username_form();
}
}
else
{
echo create_ask_username_form();
}
echo create_backlink();
?>