You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.7 KiB
PHTML

12 years ago
<?php
11 years ago
/**
* Returns all members of given angeltype.
* @param Angeltype $angeltype
*/
function Users_by_angeltype($angeltype) {
return sql_select("
SELECT `User`.*, `UserAngelTypes`.`id` as `user_angeltype_id`, `UserAngelTypes`.`confirm_user_id`
FROM `User`
JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id`
WHERE `UserAngelTypes`.`angeltype_id`=" . sql_escape($angeltype['id']) . "
ORDER BY `Nick`");
}
11 years ago
/**
* Returns User id array
*/
function mUserList() {
$user_source = sql_select("SELECT `UID` FROM `User`");
if ($user_source === false)
return false;
if (count($user_source) > 0)
return $user_source;
return null;
}
/**
* Strip unwanted characters from a users nick.
*
* @param string $nick
*/
function User_validate_Nick($nick) {
return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick);
}
12 years ago
/**
* Returns user by id.
11 years ago
*
* @param $id UID
12 years ago
*/
function User($id) {
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1");
11 years ago
if ($user_source === false)
return false;
11 years ago
if (count($user_source) > 0)
12 years ago
return $user_source[0];
return null;
}
11 years ago
/**
* Returns user by id (limit informations.
*
* @param $id UID
11 years ago
*/
function mUser_Limit($id) {
$user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `ICQ`, `jabber`, `Avatar` FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1");
if ($user_source === false)
return false;
if (count($user_source) > 0)
return $user_source[0];
return null;
}
/**
* Returns User by api_key.
11 years ago
*
* @param string $api_key
* User api key
* @return Matching user, null or false on error
*/
function User_by_api_key($api_key) {
$user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1");
11 years ago
if ($user === false)
return false;
if (count($user) == 0)
return null;
return $user[0];
}
/**
* Returns User by email.
*
* @param string $email
* @return Matching user, null or false on error
*/
function User_by_email($email) {
$user = sql_select("SELECT * FROM `User` WHERE `email`='" . sql_escape($email) . "' LIMIT 1");
if ($user === false)
return false;
if (count($user) == 0)
return null;
return $user[0];
}
/**
* Returns User by password token.
*
* @param string $token
* @return Matching user, null or false on error
*/
function User_by_password_recovery_token($token) {
$user = sql_select("SELECT * FROM `User` WHERE `password_recovery_token`='" . sql_escape($token) . "' LIMIT 1");
if ($user === false)
return false;
if (count($user) == 0)
return null;
return $user[0];
}
/**
* Generates a new api key for given user.
11 years ago
*
* @param User $user
*/
function User_reset_api_key(&$user) {
$user['api_key'] = md5($user['Nick'] . time() . rand());
$result = sql_query("UPDATE `User` SET `api_key`='" . sql_escape($user['api_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
11 years ago
if ($result === false)
return false;
engelsystem_log("API key resetted.");
}
/**
* Generates a new password recovery token for given user.
*
* @param User $user
*/
function User_generate_password_recovery_token(&$user) {
$user['password_recovery_token'] = md5($user['Nick'] . time() . rand());
$result = sql_query("UPDATE `User` SET `password_recovery_token`='" . sql_escape($user['password_recovery_token']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
if ($result === false)
return false;
engelsystem_log("Password recovery for " . $user['Nick'] . " started.");
return $user['password_recovery_token'];
}
11 years ago
?>