Zikula_Core
[ class tree: Zikula_Core ] [ index: Zikula_Core ] [ all elements ]

Source for file pnUser.php

Documentation is available at pnUser.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2001, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnUser.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Core
  10.  * @subpackage pnAPI
  11. */
  12.  
  13. /**
  14.  * Defines
  15.  */
  16.  
  17. /**
  18.  * Data types for User Properties
  19.  */
  20. define('UDCONST_MANDATORY'-1)// indicates a core field that can't be removed
  21. define('UDCONST_CORE'0)// indicates a core field (HACK, to be removed?)
  22. define('UDCONST_STRING'1);
  23. define('UDCONST_TEXT'2);
  24. define('UDCONST_FLOAT'3);
  25. define('UDCONST_INTEGER'4);
  26.  
  27. /**
  28.  * Log the user in
  29.  *
  30.  * @param uname the name of the user logging in
  31.  * @param pass the password of the user logging in
  32.  * @param rememberme whether $ or not to remember this login
  33.  * @param checkPassword bool true whether or not to check the password
  34.  * @return bool true if the user successfully logged in, false otherwise
  35.  */
  36. function pnUserLogIn($uname$pass$rememberme=false$checkPassword=true)
  37. {
  38.     if (pnUserLoggedIn()) {
  39.         return true;
  40.     }
  41.  
  42.     $uservars pnModGetVar('Users');
  43.  
  44.     if (!pnVarValidate($uname(($uservars['loginviaoption']==1'email' 'uname'))) {
  45.         return false;
  46.     }
  47.  
  48.     // get the database connection
  49.     pnModDBInfoLoad('Users''Users');
  50.     pnModDBInfoLoad('Profile''Profile');
  51.     pnModAPILoad('Users''user'true);
  52.  
  53.     $uname strtolower ($uname);
  54.     if (!pnModAvailable('AuthPN')) {
  55.         if (!isset($uservars['loginviaoption']|| $uservars['loginviaoption'== 0{
  56.             $user DBUtil::selectObjectByID('users'$uname'uname'nullnullnullfalse'lower');
  57.         else {
  58.             $user DBUtil::selectObjectByID('users'$uname'email'nullnullnullfalse'lower');
  59.         }
  60.  
  61.         if (!$user{
  62.             return false;
  63.         }
  64.  
  65.         // check if the account is active
  66.         if (isset($user['activated']&& $user['activated']=='0'{
  67.             // account inactive, deny login
  68.             return false;
  69.         else if ($user['activated']=='2'{
  70.             // we need a session var here that can have 3 states
  71.             // 0: account needs to be activated, this is the value after
  72.             //    we detected this
  73.             // 1: account needs to activated, user check the accept checkbox
  74.             // 2: everything is ok
  75.             // have we been here before?
  76.             $confirmtou SessionUtil::getVar('confirmtou'0);
  77.             switch($confirmtou{
  78.                 case 0:
  79.                     // continue if legal module is active and and configured to
  80.                     // use the terms of use
  81.                     if (pnModAvailable('legal')) {
  82.                         $tou pnModGetVar('legal''termsofuse');
  83.                         if ($tou==1{
  84.                             // users must confirm terms of use before before he can continue
  85.                             // we redirect him to the login screen
  86.                             // to ensure that he reads this reminder
  87.                             SessionUtil::setVar('confirmtou'0);
  88.                             return false;
  89.                         }
  90.                     }
  91.                     break;
  92.                 case 1// user has accepted the terms of use - continue
  93.                     break;
  94.                 case 2:
  95.                 default:
  96.             }
  97.         }
  98.  
  99.         $uid $user['uid'];
  100.  
  101.         // password check doesn't apply to HTTP(S) based login
  102.         if ($checkPassword{
  103.             $upass $user['pass'];
  104.             $pnuser_hash_number $user['hash_method'];
  105.             $hashmethodsarray   pnModAPIFunc('Users''user''gethashmethods'array('reverse' => true));
  106.  
  107.             $hpass DataUtil::hash($pass$hashmethodsarray[$pnuser_hash_number]);
  108.             if ($hpass != $upass{
  109.                 return false;
  110.             }
  111.  
  112.             // Check stored hash matches the current system type, if not convert it.
  113.             $system_hash_method $uservars['hash_method'];
  114.             if ($system_hash_method != $hashmethodsarray[$pnuser_hash_number]{
  115.                 $newhash DataUtil::hash($pass$system_hash_method);
  116.                 $hashtonumberarray pnModAPIFunc('Users''user''gethashmethods');
  117.  
  118.                 $obj array('uid'         => $uid,
  119.                              'pass'        => $newhash,
  120.                              'hash_method' => $hashtonumberarray[$system_hash_method]);
  121.                 $result DBUtil::updateObject($obj'users''''uid');
  122.  
  123.                 if (!$result{
  124.                     return false;
  125.                 }
  126.             }
  127.         }
  128.  
  129.         // Storing Last Login date
  130.         if ($uservars['savelastlogindate']{
  131.             if (!pnUserSetVar('lastlogin'date("Y-m-d H:i:s"time())$uid)) {
  132.                 // show messages but continue
  133.                 LogUtil::registerError(_UNABLETOSAVELOGINDATE);
  134.             }
  135.         }
  136.     else {
  137.         $authmodules explode(','pnModGetVar('AuthPN','authmodules'));
  138.         foreach ($authmodules as $authmodule{
  139.             $authmodule trim($authmodule);
  140.             if (pnModAvailable($authmodule&& pnModAPILoad($authmodule'user')) {
  141.                 $uid pnModAPIFunc($authmodule'user''login',
  142.                         array('uname' => $uname'pass' => $pass'rememberme' => $rememberme'checkPassword' => $checkPassword));
  143.                 if ($uid{
  144.                     break;
  145.                 }
  146.             }
  147.         }
  148.         if (!$uid{
  149.             return false;
  150.         }
  151.     }
  152.  
  153.     if (!defined('_PNINSTALLVER')) {
  154.         SessionUtil::requireSession();
  155.     }
  156.  
  157.     // Set session variables
  158.     SessionUtil::setVar('uid'(int)$uid);
  159.     if (!empty($rememberme)) {
  160.         SessionUtil::setVar('rememberme'1);
  161.     }
  162.  
  163.     if (isset($confirmtou&& $confirmtou==1{
  164.         // if we get here, the user did accept the terms of use
  165.         // now update the status
  166.         pnUserSetVar('activated'1(int)$uid);
  167.         SessionUtil::delVar('confirmtou');
  168.     }
  169.  
  170.     // now we've logged in the permissions previously calculated are invalid
  171.     $GLOBALS['authinfogathered'][$uid0;
  172.  
  173.     return true;
  174. }
  175.  
  176. /**
  177.  * Log the user in via the REMOTE_USER SERVER property. This routine simply
  178.  * checks if the REMOTE_USER exists in the PN environment: if he does a
  179.  * session is created for him, regardless of the password being used.
  180.  *
  181.  * @return bool true if the user successfully logged in, false otherwise
  182.  */
  183. function pnUserLogInHTTP()
  184. {
  185.     $uname pnServerGetVar('REMOTE_USER');
  186.     $hSec  pnConfigGetVar('session_http_login_high_security'true);
  187.     $rc    pnUserLogIn($unamenullfalsefalse);
  188.     if ($rc && $hSec{
  189.         pnConfigSetVar('seclevel''High');
  190.     }
  191.  
  192.     return $rc;
  193. }
  194.  
  195. /**
  196.  * Log the user out
  197.  *
  198.  * @public
  199.  * @return bool true if the user successfully logged out, false otherwise
  200.  */
  201. function pnUserLogOut()
  202. {
  203.     if (pnUserLoggedIn()) {
  204.         if (pnModAvailable('AuthPN')) {
  205.             $authmodules explode(','pnModGetVar('AuthPN','authmodules'));
  206.             foreach ($authmodules as $authmodule{
  207.                 $authmodule trim($authmodule);
  208.                 if (pnModAvailable($authmodule&& pnModAPILoad($authmodule'user')) {
  209.                     if (!$result pnModAPIFunc($authmodule'user''logout')) {
  210.                         return false;
  211.                     }
  212.                 }
  213.             }
  214.         }
  215.  
  216.         // delete logged on user the session
  217.         // SessionUtil::delVar('rememberme');
  218.         // SessionUtil::delVar('uid');
  219.         session_destroy();
  220.     }
  221.  
  222.     return true;
  223. }
  224.  
  225. /**
  226.  * is the user logged in?
  227.  *
  228.  * @public
  229.  * @returns bool true if the user is logged in, false if they are not
  230.  */
  231. function pnUserLoggedIn()
  232. {
  233.     return (bool)SessionUtil::getVar('uid');
  234. }
  235.  
  236. /**
  237.  * get all user variables
  238.  *
  239.  * @access public
  240.  * @author Gregor J. Rothfuss
  241.  * @since 1.33 - 2002/02/07
  242.  * @param uid the user id of the user
  243.  * @return array an associative array with all variables for a user
  244.  */
  245. function pnUserGetVars($uid$force false)
  246. {
  247.     if (!is_numeric($uid)) {
  248.         return false;
  249.     }
  250.  
  251.     static $cache array();
  252.     static $props;
  253.  
  254.     // caching
  255.     if (isset($cache[$uid]&& !$force{
  256.         return $cache[$uid];
  257.     }
  258.  
  259.     // load the database information
  260.     pnModDBInfoLoad('Profile''Profile');
  261.     pnModDBInfoLoad('Users''Users');
  262.  
  263.     // get table/column info
  264.     $pntable     pnDBGetTables();
  265.     $propcolumn  $pntable['user_property_column'];
  266.     $datacolumn  $pntable['user_data_column'];
  267.  
  268.     // create an empty array to hold the user vars
  269.     $vars array();
  270.  
  271.     // get user info
  272.     $user DBUtil::selectObjectByID ('users'$uid'uid');
  273.     // user can be false (error) or empty array (no such user)
  274.     if (empty($user)) {
  275.         return false;
  276.     }        
  277.     if ($user == false{
  278.         return LogUtil::registerError (_GETFAILED);
  279.     }
  280.  
  281.     // duplicate column info with 'pn_' prefix
  282.     foreach ($user as $k=>$v{
  283.         // special case: do not duplicate attributes, meta data and categories information
  284.         if (($k <> '__ATTRIBUTES__'&& ($k <> '__META__'&& ($k <> '__CATEGORIES__')) {
  285.             $k2 'pn_' $k;
  286.             $user[$k2$v;
  287.         }
  288.     }
  289.  
  290.     // get dynamic properties
  291.     if (!isset($props)) {
  292.         $where "$propcolumn[prop_dtype] >= 1 ";
  293.         $sort  "$propcolumn[prop_weight] ASC";
  294.         $props DBUtil::selectObjectArray ('user_property'$where$sort);
  295.     }
  296.  
  297.     // get user dynamic properties
  298.     $where "$datacolumn[uda_uid]=DataUtil::formatForStore($uid);
  299.     $userprops DBUtil::selectObjectArray ('user_data'$where''-1-1'uda_propid');
  300.  
  301.     // assign dynamic property data
  302.     foreach ($props as $prop{
  303.         $id     $prop['prop_id'];
  304.         $label  $prop['prop_label'];
  305.         $vars[$label]  = isset($userprops[$id]$userprops[$id]['uda_value'null;
  306.     }
  307.  
  308.     $vars array_merge ($user$vars);
  309.     $cache[$uid$vars;
  310.     return($vars);
  311. }
  312.  
  313. /**
  314.  * get a user variable
  315.  *
  316.  * @public
  317.  * @author Jim McDonald
  318.  * @param name the name of the variable
  319.  * @param uid the user to get the variable for
  320.  * @param default the default value to return if the specified variable doesn't exist
  321.  * @return string the value of the user variable if successful, false otherwise
  322.  */
  323. function pnUserGetVar($name$uid=-1$default=false)
  324. {
  325.     static $vars array();
  326.  
  327.     if (empty($name)) {
  328.         return;
  329.     }
  330.  
  331.     // bug fix #1311 [landseer]
  332.     if (isset($uid&& !is_numeric($uid) ) {
  333.         return;
  334.     }
  335.  
  336.     if ($uid == -1{
  337.         $uid SessionUtil::getVar('uid');
  338.     }
  339.     if (empty($uid)) {
  340.         return;
  341.     }
  342.  
  343.     // Get this user's variables if not already obtained
  344.     if (!isset($vars[$uid])) {
  345.         $vars[$uidpnUserGetVars($uid);
  346.     }
  347.  
  348.     // Return the variable
  349.     if (isset($vars[$uid][$name])) {
  350.         return $vars[$uid][$name];
  351.     }
  352.  
  353.     return $default;
  354. }
  355.  
  356. /**
  357.  * set a user variable
  358.  *
  359.  * @access public
  360.  * @author Gregor J. Rothfuss
  361.  * @since 1.23 - 2002/02/01
  362.  * @param name the name of the variable
  363.  * @param value the value of the variable
  364.  * @param uid the user to set the variable for
  365.  * @return bool true if the set was successful, false otherwise
  366.  */
  367. function pnUserSetVar($name$value$uid = -1)
  368. {
  369.     $pntable pnDBGetTables();
  370.  
  371.     if (empty($name)) {
  372.         return false;
  373.     }
  374.     if (!isset($value)) {
  375.         return false;
  376.     }
  377.  
  378.     if ($uid == -1{
  379.         $uid SessionUtil::getVar('uid');
  380.     }
  381.     if (empty($uid)) {
  382.         return false;
  383.     }
  384.  
  385.     if (pnUserFieldAlias($name)) {
  386.         // this value comes from the users table
  387.         $obj array('uid' => $uid,
  388.                      $name => $value);
  389.         return (bool)DBUtil::updateObject($obj'users''''uid');
  390.     }
  391.  
  392.     $propertiestable $pntable['user_property'];
  393.     $datatable $pntable['user_data'];
  394.     $propcolumns $pntable['user_property_column'];
  395.     $datacolumns $pntable['user_data_column'];
  396.  
  397.     $name pnUserDynamicAlias($name);
  398.  
  399.     // Confirm that this is a known value
  400.     $property DBUtil::selectObjectByID('user_property'$name'prop_label');
  401.  
  402.     if (!$property{
  403.         return false;
  404.     }
  405.  
  406.     $id $property['prop_id'];
  407.     $type $property['prop_dtype'];
  408.     $validation unserialize($property['prop_validation']);
  409.  
  410.     // Combining fields, TODO: Extend to other types than only EXTDATE
  411.     // Must check type, if EXTDATE { implode } else { serialize }
  412.     if (is_array($value)) {
  413.         if ($validation['displaytype'== 6{
  414.             $value implode('-'$value);
  415.         else {
  416.             $value serialize(array_values($value));
  417.         }
  418.     }
  419.  
  420.     // check for existence of the variable in user data
  421.     $where "WHERE $datacolumns[uda_propid] = 'DataUtil::formatForStore($id"'
  422.               AND   $datacolumns[uda_uid] = 'DataUtil::formatForStore($uid"'";
  423.     $userdata DBUtil::selectObject('user_data'$where);
  424.  
  425.     // jgm - this won't work in databases that care about typing
  426.     // but this should get fixed when we move to the dynamic user
  427.     // variables setup
  428.     // TODO: do some checking with $type to maybe do conditional sql
  429.     if (!$userdata{
  430.         // record does not exist
  431.         $obj array('uda_propid' => $id,
  432.                      'uda_uid'    => $uid,
  433.                      'uda_value'  => $value);
  434.         $result DBUtil::insertObject($obj'user_data''uda_id');
  435.     else {
  436.         // existing record
  437.         $obj array('uda_value' => $value);
  438.         $result DBUtil::updateObject($obj,'user_data'$where);
  439.     }
  440.  
  441.     return (bool)$result;
  442. }
  443.  
  444.  
  445. function pnUserSetPassword($pass)
  446. {
  447.     $method pnModGetVar('Users''hash_method');
  448.     $hashmethodsarray pnModAPIFunc('Users''user''gethashmethods');
  449.     pnUserSetVar('pass'DataUtil::hash($pass$method));
  450.     pnUserSetVar('hash_method'$hashmethodsarray[$method]);
  451. }
  452.  
  453.  
  454. /**
  455.  * delete the contents of a user variable
  456.  *
  457.  * @access public
  458.  * @author Gregor J. Rothfuss
  459.  * @since 1.23 - 2002/02/01
  460.  * @param name the name of the variable
  461.  * @param uid the user to delete the variable for
  462.  * @return string true on success, false on failure
  463.  */
  464. function pnUserDelVar($name$uid = -1)
  465. {
  466.     $pntable pnDBGetTables();
  467.     $datacolumns $pntable['user_data_column'];
  468.  
  469.     // Prevent deletion of core fields (duh)
  470.     if (empty($name|| ($name == 'uid'|| ($name == 'email'||
  471.        ($name == 'password'|| ($name == 'uname')) {
  472.         return false;
  473.     }
  474.  
  475.     if ($uid == -1{
  476.         $uid SessionUtil::getVar('uid');
  477.     }
  478.     if (empty($uid)) {
  479.         return false;
  480.     }
  481.  
  482.     if (pnUserFieldAlias($name)) {
  483.         // this value comes from the users table
  484.         $obj array('uid' => $uid,
  485.                      $name => '');
  486.         return (bool)DBUtil::updateObject($obj'users''''uid');
  487.     }
  488.  
  489.     // get property id for cascading delete later
  490.     $result DBUtil::selectObjectByID('user_property'$name'prop_label');
  491.     if ($result{
  492.         $id $result['prop_id'];
  493.         // delete variable from user data for all users
  494.         $where "WHERE $datacolumns[uda_propid] = 'DataUtil::formatForStore($id)  "'
  495.                   AND   $datacolumns[uda_uid]    = 'DataUtil::formatForStore($uid"'";
  496.         $result DBUtil::deleteWhere('user_data'$where);
  497.     }
  498.  
  499.     return (bool)$result;
  500. }
  501.  
  502. /**
  503.  * get the user's theme
  504.  * <br />
  505.  * This function will return the current theme for the user.
  506.  * Order of theme priority:
  507.  *  - page-specific
  508.  *  - category
  509.  *  - user
  510.  *  - system
  511.  *
  512.  * @public
  513.  * @return string the name of the user's theme
  514.  ***/
  515. function pnUserGetTheme($force false)
  516. {
  517.     static $theme;
  518.     if (isset($theme|| !$force{
  519.         return $theme;
  520.     }
  521.  
  522.     // Page-specific theme
  523.     $pagetheme FormUtil::getPassedValue('theme'null'GETPOST');
  524.     $type      FormUtil::getPassedValue('type'null'GETPOST');
  525.     $qstring   pnServerGetVar('QUERY_STRING');
  526.     if (!empty($pagetheme)) {
  527.         $themeinfo ThemeUtil::getInfo(ThemeUtil::getIDFromName($pagetheme));
  528.         if ($themeinfo['state'== PNTHEME_STATE_ACTIVE &&
  529.              ($themeinfo['user'|| $themeinfo['system'||
  530.               ($themeinfo['admin'&& ($type == 'admin' || stristr($qstring'admin.php'))))
  531.             && is_dir('themes/'.DataUtil::formatForOS($themeinfo['directory']))) {
  532.             $theme $themeinfo['name'];
  533.             return $themeinfo['name'];
  534.         }
  535.     }
  536.  
  537.     // check for an admin theme
  538.     if (($type == 'admin' || stristr($qstring'admin.php')) && SecurityUtil::checkPermission('::''::'ACCESS_EDIT)) {
  539.         $admintheme pnModGetVar('Admin''admintheme');
  540.         if (!empty($admintheme)) {
  541.             $themeinfo ThemeUtil::getInfo(ThemeUtil::getIDFromName($admintheme));
  542.             if ($themeinfo && $themeinfo['state'== PNTHEME_STATE_ACTIVE && is_dir('themes/'.DataUtil::formatForOS($themeinfo['directory']))) {
  543.                 $theme $themeinfo['name'];
  544.                 return $themeinfo['name'];
  545.             }
  546.         }
  547.     }
  548.  
  549.     // set a new theme for the user
  550.     $newtheme FormUtil::getPassedValue('newtheme'null'GETPOST');
  551.     if (!empty($newtheme&& pnConfigGetVar('theme_change')) {
  552.         $themeinfo ThemeUtil::getInfo(ThemeUtil::getIDFromName($newtheme));
  553.         if ($themeinfo && $themeinfo['state'== PNTHEME_STATE_ACTIVE && is_dir('themes/'.DataUtil::formatForOS($themeinfo['directory']))) {
  554.             if (pnUserLoggedIn()) {
  555.                 pnUserSetVar('theme'$newtheme);
  556.             else {
  557.                 SessionUtil::setVar('theme'$newtheme);
  558.             }
  559.             $theme $themeinfo['name'];
  560.             return $themeinfo['name'];
  561.         }
  562.     }
  563.  
  564.     // User theme
  565.     if (pnConfigGetVar('theme_change')) {
  566.         if ((pnUserLoggedIn())) {
  567.             $usertheme pnUserGetVar('theme');
  568.         else {
  569.             $usertheme SessionUtil::getVar('theme');
  570.         }
  571.         $themeinfo ThemeUtil::getInfo(ThemeUtil::getIDFromName($usertheme));
  572.         if ($themeinfo && $themeinfo['state'== PNTHEME_STATE_ACTIVE && is_dir('themes/'.DataUtil::formatForOS($themeinfo['directory']))) {
  573.             $theme $themeinfo['name'];
  574.             return $themeinfo['name'];
  575.         }
  576.     }
  577.  
  578.     // default site theme
  579.     $defaulttheme pnConfigGetVar('Default_Theme');
  580.     $themeinfo ThemeUtil::getInfo(ThemeUtil::getIDFromName($defaulttheme));
  581.     if ($themeinfo && $themeinfo['state'== PNTHEME_STATE_ACTIVE && is_dir('themes/'.DataUtil::formatForOS($themeinfo['directory']))) {
  582.         $theme $themeinfo['name'];
  583.         return $themeinfo['name'];
  584.     }
  585.  
  586.     $theme 'ExtraLite';
  587.     return $theme;
  588. }
  589.  
  590. /**
  591.  * get the user's language
  592.  *
  593.  * @public <br>
  594.  *  jgm - the language parameter should be a user variable, not a
  595.  *         session variable
  596.  * @return string the name of the user's language
  597.  */
  598. function pnUserGetLang()
  599. {
  600.     $lang SessionUtil::getVar('lang');
  601.     if (!empty($lang)) {
  602.         return $lang;
  603.     }
  604.  
  605.     return pnConfigGetVar('language');
  606. }
  607.  
  608. /**
  609.  * get the options for commenting
  610.  * <br>
  611.  * This function is deprecated, use <code>pnUserGetcommentArray()</code> in
  612.  * conjunction with <code>pnModURL()</code> to produce relevant URLs
  613.  *
  614.  * @deprecated
  615.  * @public
  616.  * @return string the comment options string
  617.  */
  618. function pnUserGetCommentOptions($implode=true)
  619. {
  620.     if (pnUserLoggedIn()) {
  621.         $mode pnUserGetVar('umode');
  622.         $order pnUserGetVar('uorder');
  623.         $thold pnUserGetVar('thold');
  624.     }
  625.  
  626.     if (empty($mode)) {
  627.         $mode 'thread';
  628.     }
  629.  
  630.     if (empty($order)) {
  631.         $order 0;
  632.     }
  633.  
  634.     if (empty($thold)) {
  635.         $thold 0;
  636.     }
  637.  
  638.     if ($implode{
  639.         return("mode=$mode&amp;order=$order&amp;thold=$thold");
  640.     }
  641.  
  642.     $array array('mode' => $mode'order' => $order'thold' => $thold);
  643.     return $array;
  644. }
  645.  
  646. /**
  647.  * get the options for commenting
  648.  *
  649.  * @public
  650.  * @return array the comment options array
  651.  */
  652. {
  653.     if (pnUserLoggedIn()) {
  654.         $mode pnUserGetVar('umode');
  655.         $order pnUserGetVar('uorder');
  656.         $thold pnUserGetVar('thold');
  657.     }
  658.  
  659.     if (empty($mode)) {
  660.         $mode 'thread';
  661.     }
  662.  
  663.     if (empty($order)) {
  664.     $order 0;
  665.     }
  666.  
  667.     if (empty($thold)) {
  668.         $thold 0;
  669.     }
  670.  
  671.     $array array('mode' => $mode'order' => $order'thold' => $thold);
  672.     return $array;
  673. }
  674.  
  675. /**
  676.  * get a list of user information
  677.  *
  678.  * @public
  679.  * @return array array of user arrays
  680.  */
  681. function pnUserGetAll($sortby 'uname'$sortorder 'ASC'$limit 0$startnum 1$activated ''$regexpfield ''$regexpression ='')
  682. {
  683.     $dbconn pnDBGetConn(true);
  684.     $pntable pnDBGetTables();
  685.  
  686.     pnModDBInfoLoad('Profile''Profile');
  687.     pnModDBInfoLoad('Users''Users');
  688.  
  689.     $propcolumn  $pntable['user_property_column'];
  690.     $datacolumn  $pntable['user_data_column'];
  691.     $userstable  =  $pntable['users'];
  692.     $userscolumn &$pntable['users_column'];
  693.  
  694.     $where "$propcolumn[prop_dtype] >= '1'";
  695.     $sort  "$propcolumn[prop_weight] ASC";
  696.     $props DBUtil::selectObjectArray ('user_property'$where$sort);
  697.  
  698.     $dynsql '';
  699.     foreach ($props as $prop{
  700.         $dynsql .= "MAX(IF($datacolumn[uda_propid]='$prop[prop_id]', $datacolumn[uda_value], NULL)) as $prop[prop_label]";
  701.     }
  702.  
  703.     // needs changes before being converted to DBUtil
  704.     $sql "SELECT     $dynsql
  705.                        $userscolumn[uid]             as uid,
  706.                        $userscolumn[uname]           as uname,
  707.                        $userscolumn[email]           as email,
  708.                        $userscolumn[storynum]        as storynum,
  709.                        $userscolumn[theme]           as theme,
  710.                        $userscolumn[user_theme]      as user_theme,
  711.                        $userscolumn[ublock]          as ublock,
  712.                        $userscolumn[ublockon]        as ublockon,
  713.                        $userscolumn[counter]         as counter,
  714.                        $userscolumn[activated]       as activated,
  715.                        $userscolumn[lastlogin]       as lastlogin,
  716.                        $userscolumn[validfrom]       as validfrom,
  717.                        $userscolumn[validuntil]      as validuntil,
  718.                        $userscolumn[hash_method]     as hash_method
  719.             FROM       $pntable[user_data]
  720.             RIGHT JOIN $pntable[users]
  721.             ON         $datacolumn[uda_uid] = $userscolumn[uid] ";
  722.  
  723.     $where '';
  724.     if (!empty($regexpfield&& (array_key_exists($regexpfield$userscolumn)) && !empty($regexpression)) {
  725.         $where 'WHERE ' $userscolumn[$regexpfield]' REGEXP "' DataUtil::formatForStore($regexpression'"';
  726.     }
  727.     if (!empty($activated&& is_numeric($activated&& array_key_exists('activated'$userscolumn)) {
  728.         if (!empty($where)) {
  729.             $where .= ' AND ';
  730.         else {
  731.             $where ' WHERE ';
  732.         }
  733.         $where .= "$userscolumn[activated] != '".DataUtil::formatForStore($activated)."'";
  734.     }
  735.  
  736.     $groupby " GROUP BY $userscolumn[uname] ";
  737.  
  738.     $sort '';
  739.     if (!empty($sortby)) {
  740.         if (array_key_exists($sortby$userscolumn)) {
  741.             $sort "ORDER BY $userscolumn[$sortby] $sortorder//sorty by .....
  742.         else {
  743.             $sort "ORDER BY $sortby $sortorder//sorty by dynamic.....
  744.         }
  745.         if ($sortby != 'uname'{
  746.             $sort .= "$userscolumn[uname] ASC ";
  747.         }
  748.     }
  749.  
  750.     $sql $sql $where $groupby $sort;
  751.  
  752.     if (is_numeric($limit&& $limit != {
  753.         $result $dbconn->SelectLimit($sql$numitems$startnum-1);
  754.     else {
  755.         $result $dbconn->Execute($sql);
  756.     }
  757.  
  758.     if ($dbconn->ErrorNo(!= 0{
  759.         return;
  760.     }
  761.  
  762.     if ($result->EOF{
  763.         $return false;
  764.         return $return;
  765.     }
  766.  
  767.     $resarray array();
  768.     $vars array('_UREALNAME'      => 'name',
  769.                   '_UREALEMAIL'     => 'email',
  770.                   '_UFAKEMAIL'      => 'femail',
  771.                   '_YOURHOMEPAGE'   => 'url',
  772.                   '_TIMEZONEOFFSET' => 'timezone_offset',
  773.                   '_YOURAVATAR'     => 'user_avatar',
  774.                   '_YICQ'           => 'user_icq',
  775.                   '_YAIM'           => 'user_aim',
  776.                   '_YYIM'           => 'user_yim',
  777.                   '_YMSNM'          => 'user_msnm',
  778.                   '_YLOCATION'      => 'user_from',
  779.                   '_YOCCUPATION'    => 'user_occ',
  780.                   '_YINTERESTS'     => 'user_intrest',
  781.                   '_SIGNATURE'      => 'user_sig',
  782.                   '_EXTRAINFO'      => 'bio');
  783.  
  784.     for(!$result->EOF$result->MoveNext()) {
  785.  
  786.         $item $result->GetRowAssoc(2)// WARNING: NEED 2 = user-defined fieldnames
  787.         foreach($item as $key => $value{
  788.             if (array_key_exists($key$vars)) {
  789.                 $item[$vars[$key]] $value;
  790.             }
  791.         }
  792.  
  793.         $resarray[$item['uid']] $item;
  794.  
  795.     }
  796.  
  797.     $result->Close();
  798.  
  799.     return $resarray;
  800.  
  801. }
  802.  
  803. /**
  804.  * Get the uid of a user from the username
  805.  *
  806.  * @access public
  807.  * @author Michael Halbrook
  808.  * @since 1.18 - 19/04/2004
  809.  * @param uname the username
  810.  * @return mixed userid if found, false if not
  811.  */
  812. function pnUserGetIDFromName($uname)
  813. {
  814.     if (empty($uname)) {
  815.         return false;
  816.     }
  817.  
  818.     $result DBUtil::selectObjectByID('users'$uname'uname');
  819.     return (isset($result['uid']$result['uid'false);
  820. }
  821.  
  822. /**
  823.  * Checks the alias and returns if we save the data in the
  824.  * user_data table or the users table.
  825.  * This should be removed if we ever go fully dynamic
  826.  *
  827.  * @access private
  828.  * @author F. Chestnut
  829.  * @since 1.26 - 19/04/2004
  830.  * @param label the alias of the field to check
  831.  * @return true if found, false if not, void upon error
  832.  */
  833. function pnUserFieldAlias($label)
  834. {
  835.  
  836.     if (empty($label)) {
  837.         return false;
  838.     }
  839.  
  840.     $vars array('email',
  841.                   'user_regdate',
  842.                   'user_viewemail',
  843.                   'user_theme',
  844.                   'pass',
  845.                   'storynum',
  846.                   'umode',
  847.                   'uorder',
  848.                   'thold',
  849.                   'noscore',
  850.                   'ublockon',
  851.                   'ublock',
  852.                   'theme',
  853.                   'commentmax',
  854.                   'counter',
  855.                   'activated',
  856.                   'lastlogin',
  857.                   'validfrom',
  858.                   'validuntil',
  859.                   'hash_method');
  860.  
  861.     return in_array($label$vars);
  862. }
  863.  
  864. /** TEMPORARY FIX
  865.  * Checks the alias and returns PROP_ID.
  866.  *
  867.  * @access private
  868.  * @author F. Chestnut
  869.  * @since 1.26 - 19/04/2004
  870.  * @param label the alias of the field to check
  871.  * @return true if found, false if not, void upon error
  872.  */
  873. function pnUserDynamicAlias($label)
  874. {
  875.  
  876.     if (empty($label)) {
  877.         return false;
  878.     }
  879.  
  880.     $vars array('name'            => '_UREALNAME',
  881.                   'email'           => '_UREALEMAIL',
  882.                   'femail'          => '_UFAKEMAIL',
  883.                   'url'             => '_YOURHOMEPAGE',
  884.                   'timezone_offset' => '_TIMEZONEOFFSET',
  885.                   'user_avatar'     => '_YOURAVATAR',
  886.                   'user_icq'        => '_YICQ',
  887.                   'user_aim'        => '_YAIM',
  888.                   'user_yim'        => '_YYIM',
  889.                   'user_msnm'       => '_YMSNM',
  890.                   'user_from'       => '_YLOCATION',
  891.                   'user_occ'        => '_YOCCUPATION',
  892.                   'user_intrest'    => '_YINTERESTS',
  893.                   'user_sig'        => '_SIGNATURE',
  894.                   'bio'             => '_EXTRAINFO');
  895.  
  896.     if (array_key_exists($label$vars)) {
  897.         return $vars[$label];
  898.     }
  899.  
  900.     return $label;
  901.  
  902. }
  903.  
  904. /* Checks the PROP_ID and returns the alias.
  905.  *
  906.  * @access private
  907.  * @author F. Chestnut
  908.  * @since 1.26 - 19/04/2004
  909.  * @param label $ the alias of the field to check
  910.  * @return true if found, false if not, void upon error
  911.  */
  912. function pnUserAliasFromID($propid='')
  913. {
  914.     if (empty($propid)) {
  915.         return false;
  916.     }
  917.  
  918.     $vars array('_UREALNAME'      => 'name',
  919.                   '_UREALEMAIL'     => 'email',
  920.                   '_UFAKEMAIL'      => 'femail',
  921.                   '_YOURHOMEPAGE'   => 'url',
  922.                   '_TIMEZONEOFFSET' => 'timezone_offset',
  923.                   '_YOURAVATAR'     => 'user_avatar',
  924.                   '_YICQ'           => 'user_icq',
  925.                   '_YAIM'           => 'user_aim',
  926.                   '_YYIM'           => 'user_yim',
  927.                   '_YMSNM'          => 'user_msnm',
  928.                   '_YLOCATION'      => 'user_from',
  929.                   '_YOCCUPATION'    => 'user_occ',
  930.                   '_YINTERESTS'     => 'user_intrest',
  931.                   '_SIGNATURE'      => 'user_sig',
  932.                   '_EXTRAINFO'      => 'bio');
  933.  
  934.     if (array_key_exists($propid$vars)) {
  935.         return $vars[$propid];
  936.     }
  937.  
  938.     return false;
  939.  
  940. }

Documentation generated on Fri, 18 Jul 2008 21:55:10 +0200 by phpDocumentor 1.4.1