Source for file pnUser.php
Documentation is available at pnUser.php
* Zikula Application Framework
* @copyright (c) 2001, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: pnUser.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* Data types for User Properties
define('UDCONST_MANDATORY', - 1); // indicates a core field that can't be removed
define('UDCONST_CORE', 0); // indicates a core field (HACK, to be removed?)
* @param uname $ the name of the user logging in
* @param pass $ the password of the user logging in
* @param rememberme whether $ or not to remember this login
* @param checkPassword bool true whether or not to check the password
* @return bool true if the user successfully logged in, false otherwise
function pnUserLogIn($uname, $pass, $rememberme= false, $checkPassword= true)
if (!pnVarValidate($uname, (($uservars['loginviaoption']== 1) ? 'email' : 'uname'))) {
// get the database connection
if (!isset ($uservars['loginviaoption']) || $uservars['loginviaoption'] == 0) {
// check if the account is active
if (isset ($user['activated']) && $user['activated']== '0') {
// account inactive, deny login
} else if ($user['activated']== '2') {
// we need a session var here that can have 3 states
// 0: account needs to be activated, this is the value after
// 1: account needs to activated, user check the accept checkbox
// have we been here before?
// continue if legal module is active and and configured to
// users must confirm terms of use before before he can continue
// we redirect him to the login screen
// to ensure that he reads this reminder
case 1: // user has accepted the terms of use - continue
// password check doesn't apply to HTTP(S) based login
$pnuser_hash_number = $user['hash_method'];
$hashmethodsarray = pnModAPIFunc('Users', 'user', 'gethashmethods', array('reverse' => true));
$hpass = DataUtil::hash($pass, $hashmethodsarray[$pnuser_hash_number]);
// Check stored hash matches the current system type, if not convert it.
$system_hash_method = $uservars['hash_method'];
if ($system_hash_method != $hashmethodsarray[$pnuser_hash_number]) {
$hashtonumberarray = pnModAPIFunc('Users', 'user', 'gethashmethods');
$obj = array('uid' => $uid,
'hash_method' => $hashtonumberarray[$system_hash_method]);
// Storing Last Login date
if ($uservars['savelastlogindate']) {
// show messages but continue
foreach ($authmodules as $authmodule) {
$authmodule = trim($authmodule);
array('uname' => $uname, 'pass' => $pass, 'rememberme' => $rememberme, 'checkPassword' => $checkPassword));
if (!empty($rememberme)) {
if (isset ($confirmtou) && $confirmtou== 1) {
// if we get here, the user did accept the terms of use
// now we've logged in the permissions previously calculated are invalid
$GLOBALS['authinfogathered'][$uid] = 0;
* Log the user in via the REMOTE_USER SERVER property. This routine simply
* checks if the REMOTE_USER exists in the PN environment: if he does a
* session is created for him, regardless of the password being used.
* @return bool true if the user successfully logged in, false otherwise
* @return bool true if the user successfully logged out, false otherwise
foreach ($authmodules as $authmodule) {
$authmodule = trim($authmodule);
if (!$result = pnModAPIFunc($authmodule, 'user', 'logout')) {
// delete logged on user the session
// SessionUtil::delVar('rememberme');
// SessionUtil::delVar('uid');
* @returns bool true if the user is logged in, false if they are not
* @author Gregor J. Rothfuss
* @since 1.33 - 2002/02/07
* @param uid $ the user id of the user
* @return array an associative array with all variables for a user
if (isset ($cache[$uid]) && !$force) {
// load the database information
$propcolumn = $pntable['user_property_column'];
$datacolumn = $pntable['user_data_column'];
// create an empty array to hold the user vars
// user can be false (error) or empty array (no such user)
// duplicate column info with 'pn_' prefix
foreach ($user as $k=> $v) {
// special case: do not duplicate attributes, meta data and categories information
if (($k <> '__ATTRIBUTES__') && ($k <> '__META__') && ($k <> '__CATEGORIES__')) {
// get dynamic properties
$where = "$propcolumn[prop_dtype] >= 1 ";
$sort = "$propcolumn[prop_weight] ASC";
// get user dynamic properties
// assign dynamic property data
foreach ($props as $prop) {
$label = $prop['prop_label'];
$vars[$label] = isset ($userprops[$id]) ? $userprops[$id]['uda_value'] : null;
* @param name $ the name of the variable
* @param uid $ the user to get the variable for
* @param default $ the default value to return if the specified variable doesn't exist
* @return string the value of the user variable if successful, false otherwise
// bug fix #1311 [landseer]
// Get this user's variables if not already obtained
if (!isset ($vars[$uid])) {
if (isset ($vars[$uid][$name])) {
return $vars[$uid][$name];
* @author Gregor J. Rothfuss
* @since 1.23 - 2002/02/01
* @param name $ the name of the variable
* @param value $ the value of the variable
* @param uid $ the user to set the variable for
* @return bool true if the set was successful, false otherwise
if (pnUserFieldAlias($name)) {
// this value comes from the users table
$obj = array('uid' => $uid,
$propertiestable = $pntable['user_property'];
$datatable = $pntable['user_data'];
$propcolumns = $pntable['user_property_column'];
$datacolumns = $pntable['user_data_column'];
$name = pnUserDynamicAlias($name);
// Confirm that this is a known value
$id = $property['prop_id'];
$type = $property['prop_dtype'];
$validation = unserialize($property['prop_validation']);
// Combining fields, TODO: Extend to other types than only EXTDATE
// Must check type, if EXTDATE { implode } else { serialize }
if ($validation['displaytype'] == 6) {
// check for existence of the variable in user data
// jgm - this won't work in databases that care about typing
// but this should get fixed when we move to the dynamic user
// TODO: do some checking with $type to maybe do conditional sql
$obj = array('uda_propid' => $id,
$obj = array('uda_value' => $value);
$hashmethodsarray = pnModAPIFunc('Users', 'user', 'gethashmethods');
* delete the contents of a user variable
* @author Gregor J. Rothfuss
* @since 1.23 - 2002/02/01
* @param name $ the name of the variable
* @param uid $ the user to delete the variable for
* @return string true on success, false on failure
$datacolumns = $pntable['user_data_column'];
// Prevent deletion of core fields (duh)
if (empty($name) || ($name == 'uid') || ($name == 'email') ||
($name == 'password') || ($name == 'uname')) {
if (pnUserFieldAlias($name)) {
// this value comes from the users table
$obj = array('uid' => $uid,
// get property id for cascading delete later
$id = $result['prop_id'];
// delete variable from user data for all users
* This function will return the current theme for the user.
* Order of theme priority:
* @return string the name of the user's theme
if (isset ($theme) || !$force) {
if (!empty($pagetheme)) {
($themeinfo['user'] || $themeinfo['system'] ||
($themeinfo['admin'] && ($type == 'admin' || stristr($qstring, 'admin.php'))))
$theme = $themeinfo['name'];
return $themeinfo['name'];
// check for an admin theme
if (!empty($admintheme)) {
$theme = $themeinfo['name'];
return $themeinfo['name'];
// set a new theme for the user
$theme = $themeinfo['name'];
return $themeinfo['name'];
$theme = $themeinfo['name'];
return $themeinfo['name'];
$theme = $themeinfo['name'];
return $themeinfo['name'];
* get the user's language
* jgm - the language parameter should be a user variable, not a
* @return string the name of the user's language
* get the options for commenting
* This function is deprecated, use <code>pnUserGetcommentArray()</code> in
* conjunction with <code>pnModURL()</code> to produce relevant URLs
* @return string the comment options string
return("mode=$mode&order=$order&thold=$thold");
$array = array('mode' => $mode, 'order' => $order, 'thold' => $thold);
* get the options for commenting
* @return array the comment options array
$array = array('mode' => $mode, 'order' => $order, 'thold' => $thold);
* get a list of user information
* @return array array of user arrays
function pnUserGetAll($sortby = 'uname', $sortorder = 'ASC', $limit = 0, $startnum = 1, $activated = '', $regexpfield = '', $regexpression = '')
$propcolumn = $pntable['user_property_column'];
$datacolumn = $pntable['user_data_column'];
$userstable = $pntable['users'];
$userscolumn = &$pntable['users_column'];
$where = "$propcolumn[prop_dtype] >= '1'";
$sort = "$propcolumn[prop_weight] ASC";
foreach ($props as $prop) {
$dynsql .= "MAX(IF($datacolumn[uda_propid]='$prop[prop_id]', $datacolumn[uda_value], NULL)) as $prop[prop_label], ";
// needs changes before being converted to DBUtil
$userscolumn[uid] as uid,
$userscolumn[uname] as uname,
$userscolumn[email] as email,
$userscolumn[storynum] as storynum,
$userscolumn[theme] as theme,
$userscolumn[user_theme] as user_theme,
$userscolumn[ublock] as ublock,
$userscolumn[ublockon] as ublockon,
$userscolumn[counter] as counter,
$userscolumn[activated] as activated,
$userscolumn[lastlogin] as lastlogin,
$userscolumn[validfrom] as validfrom,
$userscolumn[validuntil] as validuntil,
$userscolumn[hash_method] as hash_method
RIGHT JOIN $pntable[users]
ON $datacolumn[uda_uid] = $userscolumn[uid] ";
if (!empty($regexpfield) && (array_key_exists($regexpfield, $userscolumn)) && !empty($regexpression)) {
$groupby = " GROUP BY $userscolumn[uname] ";
$sort = "ORDER BY $userscolumn[$sortby] " . $sortorder; //sorty by .....
$sort = "ORDER BY $sortby " . $sortorder; //sorty by dynamic.....
if ($sortby != 'uname') {
$sort .= ", $userscolumn[uname] ASC ";
$sql = $sql . $where . $groupby . $sort;
$result = $dbconn->SelectLimit($sql, $numitems, $startnum- 1);
$result = $dbconn->Execute($sql);
if ($dbconn->ErrorNo() != 0) {
$vars = array('_UREALNAME' => 'name',
'_UREALEMAIL' => 'email',
'_UFAKEMAIL' => 'femail',
'_YOURHOMEPAGE' => 'url',
'_TIMEZONEOFFSET' => 'timezone_offset',
'_YOURAVATAR' => 'user_avatar',
'_YLOCATION' => 'user_from',
'_YOCCUPATION' => 'user_occ',
'_YINTERESTS' => 'user_intrest',
'_SIGNATURE' => 'user_sig',
for(; !$result->EOF; $result->MoveNext()) {
$item = $result->GetRowAssoc(2); // WARNING: NEED 2 = user-defined fieldnames
foreach($item as $key => $value) {
$item[$vars[$key]] = $value;
$resarray[$item['uid']] = $item;
* Get the uid of a user from the username
* @author Michael Halbrook
* @since 1.18 - 19/04/2004
* @param uname $ the username
* @return mixed userid if found, false if not
return (isset ($result['uid']) ? $result['uid'] : false);
* Checks the alias and returns if we save the data in the
* user_data table or the users table.
* This should be removed if we ever go fully dynamic
* @since 1.26 - 19/04/2004
* @param label $ the alias of the field to check
* @return true if found, false if not, void upon error
function pnUserFieldAlias($label)
* Checks the alias and returns PROP_ID.
* @since 1.26 - 19/04/2004
* @param label $ the alias of the field to check
* @return true if found, false if not, void upon error
function pnUserDynamicAlias($label)
$vars = array('name' => '_UREALNAME',
'email' => '_UREALEMAIL',
'femail' => '_UFAKEMAIL',
'url' => '_YOURHOMEPAGE',
'timezone_offset' => '_TIMEZONEOFFSET',
'user_avatar' => '_YOURAVATAR',
'user_from' => '_YLOCATION',
'user_occ' => '_YOCCUPATION',
'user_intrest' => '_YINTERESTS',
'user_sig' => '_SIGNATURE',
/* Checks the PROP_ID and returns the alias.
* @since 1.26 - 19/04/2004
* @param label $ the alias of the field to check
* @return true if found, false if not, void upon error
$vars = array('_UREALNAME' => 'name',
'_UREALEMAIL' => 'email',
'_UFAKEMAIL' => 'femail',
'_YOURHOMEPAGE' => 'url',
'_TIMEZONEOFFSET' => 'timezone_offset',
'_YOURAVATAR' => 'user_avatar',
'_YLOCATION' => 'user_from',
'_YOCCUPATION' => 'user_occ',
'_YINTERESTS' => 'user_intrest',
'_SIGNATURE' => 'user_sig',
|