functions.common.user.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* $Id: functions.common.user.php 2934 2007-04-20 17:35:09Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * add New User
  17. *
  18. * @param $newUser
  19. * @param $pass1
  20. * @param $userType
  21. */
  22. function addNewUser($newUser, $pass1, $userType) {
  23. global $cfg, $db;
  24. $create_time = time();
  25. $record = array(
  26. 'user_id'=>strtolower($newUser),
  27. 'password'=>md5($pass1),
  28. 'hits'=>0,
  29. 'last_visit'=>$create_time,
  30. 'time_created'=>$create_time,
  31. 'user_level'=>$userType,
  32. 'hide_offline'=>"0",
  33. 'theme'=>$cfg["default_theme"],
  34. 'language_file'=>$cfg["default_language"],
  35. 'state'=>1
  36. );
  37. $sTable = 'tf_users';
  38. $sql = $db->GetInsertSql($sTable, $record);
  39. $result = $db->Execute($sql);
  40. if ($db->ErrorNo() != 0) dbError($sql);
  41. // flush session-cache
  42. cacheFlush();
  43. }
  44. /**
  45. * UpdateUserProfile
  46. *
  47. * @param $user_id
  48. * @param $pass1
  49. * @param $hideOffline
  50. * @param $theme
  51. * @param $language
  52. */
  53. function UpdateUserProfile($user_id, $pass1, $hideOffline, $theme, $language) {
  54. global $cfg, $db;
  55. if (empty($hideOffline) || $hideOffline == "" || !isset($hideOffline))
  56. $hideOffline = "0";
  57. // update values
  58. $rec = array();
  59. if ($pass1 != "") {
  60. $rec['password'] = md5($pass1);
  61. AuditAction($cfg["constants"]["update"], $cfg['_PASSWORD']);
  62. }
  63. $sql = "select * from tf_users where user_id = ".$db->qstr($user_id);
  64. $rs = $db->Execute($sql);
  65. if ($db->ErrorNo() != 0) dbError($sql);
  66. $rec['hide_offline'] = $hideOffline;
  67. $rec['theme'] = $theme;
  68. $rec['language_file'] = $language;
  69. $sql = $db->GetUpdateSQL($rs, $rec);
  70. if ($sql != "") {
  71. $result = $db->Execute($sql);
  72. if ($db->ErrorNo() != 0) dbError($sql);
  73. // flush session-cache
  74. cacheFlush($cfg["user"]);
  75. }
  76. }
  77. ?>