A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
6.7 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file includes/classes/class_user.php
  5. * @version $Id: classes/class_user.php 15 2009-05-01 17:06:40Z pioder $
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. if ( !defined('IN_uF') )
  11. {
  12. die('Hacking attempt');
  13. }
  14. class User
  15. {
  16. function LastUser()
  17. {
  18. global $lastuser;
  19. $usr = $lastuser['nick'];
  20. $uid = $lastuser['u_id'];
  21. return '<a href="user.php?id='.$uid.'" class="fstandard">'.$usr.'</a>';
  22. }
  23. function UserInformation($uid, $inf)
  24. {
  25. $sql = "SELECT `$inf` FROM ".USERS_TABLE." WHERE u_id='$uid';";
  26. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain user information.');
  27. $result = DataBase::fetch($query);
  28. $result = $result[$inf];
  29. return $result;
  30. }
  31. function UserIdByNick($nick)
  32. {
  33. $sql = "SELECT * FROM `".USERS_TABLE."` WHERE `nick`='$nick';";
  34. $result = DataBase::fetch(DataBase::sql_query($sql,GENERAL,'Could not obtain user information.'));
  35. $result = $result['u_id'];
  36. /*if ($result=='')
  37. {
  38. message_forum('nick failed','admin_groups.php');
  39. }*/
  40. return $result;
  41. }
  42. function AddToGroup($uid, $gid)
  43. {
  44. $last= DataBase::new_id(USERS_GROUP_TABLE);
  45. $sql = "INSERT INTO `".USERS_GROUP_TABLE."` VALUES ('$last','$uid', '$gid')";
  46. DataBase::sql_query($sql,GENERAL,'Could not add user to group.');
  47. }
  48. function DeleteFromGroup($uid, $gid)
  49. {
  50. $sql = "DELETE FROM `".USERS_GROUP_TABLE."` WHERE `u_id`='$uid' AND `g_id`='$gid'";
  51. DataBase::sql_query($sql,GENERAL,'Could not delete user for group.');
  52. }
  53. function LogedAs($sid, $uid)
  54. {
  55. global $lng;
  56. global $userdata;
  57. if ($uid>0)
  58. {
  59. $nick = $userdata['nick'];
  60. return(''.$lng['youareloggedas'].' <a href="user.php?id='.$uid.'" class="fstandard"><b>'.$nick.'</b></a>');
  61. }
  62. else
  63. {
  64. return($lng['youarenotlogd']);
  65. }
  66. }
  67. function PostWithForum($posts)
  68. {
  69. $result2 = TotalPosts();
  70. if($result2>0)
  71. {
  72. $result3 = ($posts/$result2*100);
  73. $result3 = round($result3,2);
  74. return($result3);
  75. }
  76. else
  77. {
  78. return(0);
  79. }
  80. }
  81. function LastRegVisit($uid, $mode)
  82. {
  83. global $lng;
  84. $result = User::UserInformation($uid,$mode);
  85. if ($result=='0')
  86. {
  87. return($lng['never']);
  88. }
  89. else
  90. {
  91. $date = date('d-m-Y, G:i',$result);
  92. return($date);
  93. }
  94. }
  95. function UserRank($rank)
  96. {
  97. global $lng;
  98. global $forum_config;
  99. switch($rank)
  100. {
  101. case '0': {$result=$lng['user']; break; }
  102. case '1': {$result='<font color="'.$forum_config['color_mod'].'"><b>'.$lng['mod'].'</b></font>'; break; }
  103. case '2': {$result='<font color="'.$forum_config['color_admin'].'"><b>'.$lng['admin'].'</b></font>'; break; }
  104. }
  105. return($result);
  106. }
  107. function RankAdminMod($uid)
  108. {
  109. if ($uid>0)
  110. {
  111. $sql = "SELECT * FROM ".USERS_TABLE." WHERE u_id='$uid'";
  112. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain user`s rank information.');
  113. $result = DataBase::fetch($query);
  114. $rank = $result['rank'];
  115. if (($rank=='1') or ($rank=='2'))
  116. {
  117. return '1';
  118. }
  119. else
  120. {
  121. return '0';
  122. }
  123. }
  124. else
  125. {
  126. return '0';
  127. }
  128. }
  129. function UpdateProfile($uid, $gg, $email, $interests, $sig, $avatar, $allow_qr, $allow_email, $allow_gg, $skin, $lang, $limit_tpid, $limit_ftid, $limit_users, $allow_shoutbox)
  130. {
  131. $sql ="UPDATE `".USERS_TABLE."` SET
  132. `gg` = '$gg',
  133. `email` = '$email',
  134. `allow_gg` = '$allow_gg',
  135. `allow_email` = '$allow_email',
  136. `allow_qr` = '$allow_qr',
  137. `interests` = '$interests',
  138. `sig` = '$sig',
  139. `avatar` = '$avatar',
  140. `skin`='$skin',
  141. `lang`='$lang',
  142. `limit_tpid` = '$limit_tpid',
  143. `limit_ftid` = '$limit_ftid',
  144. `view_shoutbox` = '$allow_shoutbox',
  145. `limit_users` = '$limit_users'
  146. WHERE `u_id` ='$uid' LIMIT 1 ;";
  147. DataBase::sql_query($sql,CRITICAL,'Could not update user information');
  148. }
  149. function UpdateAdminPools($uid, $posts, $rank, $active, $nick)
  150. {
  151. $sql ="UPDATE `".USERS_TABLE."` SET
  152. `posts` = '$posts',
  153. `rank` = '$rank',
  154. `active` = '$active',
  155. `nick` = '$nick'
  156. WHERE `u_id` ='$uid' LIMIT 1 ;";
  157. DataBase::sql_query($sql,CRITICAL,'Could not update user information');
  158. }
  159. function UpdatePassword($uid, $pass)
  160. {
  161. $sql ="UPDATE `".USERS_TABLE."` SET
  162. `pass` = '$pass'
  163. WHERE `u_id` ='$uid' LIMIT 1 ;";
  164. DataBase::sql_query($sql,CRITICAL,'Could not update user information');
  165. }
  166. function CreateProfile($nick, $pass, $email, $gg, $allow_gg, $allow_email, $allow_qr, $sig, $av, $interests)
  167. {
  168. global $forum_config;
  169. $last = DataBase::new_id(USERS_TABLE);
  170. $time = time();
  171. $sql = "INSERT INTO ".USERS_TABLE." VALUES
  172. ('$last', '$nick', '$pass', '$email', '0', '$time', '0', '$gg', '$allow_gg', '$allow_email', '$allow_qr', '".$forum_config['view_shoutbox']."', '".$forum_config['defaultskin']."', '".$forum_config['defaultlang']."','".$forum_config['limit_tpid']."', '".$forum_config['limit_ftid']."', '".$forum_config['limit_users']."', '$sig', '$av', '1','0','$interests');";
  173. DataBase::sql_query($sql,CRITICAL,'Could not create new user');
  174. }
  175. function UserMsgs()
  176. {
  177. $uid = $_SESSION['uid'];
  178. if($uid>0)
  179. {
  180. $sql = "SELECT count(*) as `m_id` FROM ".PM_INBOX_TABLE." WHERE `u_id`='$uid' AND `read`='0'";
  181. $result = DataBase::fetch(DataBase::sql_query($sql,GENERAL,'Could not obtain amounts PM of User.'));
  182. $result = $result['m_id'];
  183. if ($result>0)
  184. {
  185. return '<font color="red">'.$result.'</font>';
  186. }
  187. else
  188. {
  189. return $result;
  190. }
  191. }
  192. }
  193. function UserAddWarn($uid, $value, $motive)
  194. {
  195. global $lng;
  196. $sql = "INSERT INTO `".WARNINGS_TABLE."` ( `w_id` , `u_id` , `value` , `motive` ) VALUES('','$uid','$value','$motive');";
  197. DataBase::sql_query($sql,GENERAL,'Could not add new warn.');
  198. if (User::UserLevelWarns($uid)==100)
  199. {
  200. $ban_ip = '0.0.0.0';
  201. $ban_uid = $uid;
  202. $ban_motive = $lng['warns_ban'];
  203. $sql = "INSERT INTO ".BANLIST_TABLE." VALUES ('', '$ban_uid', '$ban_ip', '$ban_motive')";
  204. DataBase::sql_query($sql,GENERAL,'Could not update add ban.');
  205. }
  206. }
  207. function UserLevelWarns($uid)
  208. {
  209. $level =0;
  210. $sql = "SELECT `u_id`,`value` FROM `".WARNINGS_TABLE."` WHERE `u_id`='$uid'";
  211. $query = DataBase::sql_query($sql,'GENERAL','Could not obtain user warns information');
  212. $result = DataBase::num_rows($query);
  213. while ($result = @DataBase::fetch($query))
  214. {
  215. if ($result['value']=='-')
  216. {
  217. $level = $level -1;
  218. }
  219. else
  220. {
  221. $level = $level +1;
  222. }
  223. }
  224. //version 1.0 Alpha 2
  225. //delete second query
  226. if ($level>0)
  227. {
  228. $level = $level*10;
  229. }
  230. return $level;
  231. }
  232. }
  233. ?>