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.

458 lines
15 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file admin/admin_users.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. define('IN_uF', true);
  11. //include files
  12. include('./../config.php');
  13. include('./../includes/constants.php');
  14. include('./../includes/class_db.php');
  15. include('./../includes/class_error.php');
  16. //connect to database
  17. DataBase::db_connect();
  18. include('./../includes/sessions.php');
  19. include('./../includes/class_user.php');
  20. include('./../common.php');
  21. include('./../includes/admin/class_main.php');
  22. include('./../includes/class_topic.php');
  23. include('./../includes/classes/secure.php');
  24. $default_lang = Admin_Over::DefaultLang();
  25. include('./../lngs/'.$default_lang.'/admin.php');
  26. sess_del_invalid($_SESSION['uid']);
  27. sess_register($_SESSION['uid']);
  28. sess_delete_old();
  29. if (User::UserInformation($_SESSION['uid'],'rank')!=2)
  30. {
  31. admin_message_forum($lng['yournotadmin'],'../index.php');
  32. }
  33. if (!isset($_GET['mode']))
  34. {
  35. header('Location: admin_users.php?mode=view');
  36. }
  37. switch($_GET['mode'])
  38. {
  39. case 'delete':
  40. {
  41. $uid = intval($_GET['id']);
  42. //delete from users table
  43. $sql = "DELETE FROM ".USERS_TABLE." WHERE `u_id`='$uid'";
  44. DataBase::sql_query($sql,'GENERAL','Could not delete user.');
  45. //delete from PM SentBox table
  46. $sql = "DELETE FROM ".PM_SENTBOX_TABLE." WHERE `u_n_id`='$uid'";
  47. DataBase::sql_query($sql,'GENERAL','Could not delete user sentbox messages.');
  48. //update PM InBox table -> change u_n_id to Anonymous
  49. $sql = "UPDATE ".PM_INBOX_TABLE." SET `u_n_id`='-1' WHERE `u_n_id`='$uid'";
  50. DataBase::sql_query($sql,'GENERAL','Could not update user inbox messages.');
  51. //update user posts -> change u_id to Anonymous
  52. $sql = "UPDATE ".POSTS_TABLE." SET `u_id`='-1' WHERE `u_id`='$uid'";
  53. DataBase::sql_query($sql,'GENERAL','Could edit post.');
  54. //update shoutbox messages -> change u_id to Anonymous
  55. $sql = "UPDATE ".SHOUTBOX_TABLE." SET `u_id`='-1' WHERE `u_id`='$uid'";
  56. DataBase::sql_query($sql,'GENERAL','Could edit shoutbox messages.');
  57. //update user topics -> change u_id to Anonymous
  58. $sql = "UPDATE ".TOPICS_TABLE." SET `author`='-1' WHERE `author`='$uid'";
  59. DataBase::sql_query($sql,'GENERAL','Could edit post.');
  60. //back to admin users
  61. admin_message_forum($lng['user_deleted'],'admin_users.php');
  62. break;
  63. }
  64. case 'edit':
  65. {
  66. $uid = intval($_GET['id']);
  67. $msg='';
  68. $errors = true;
  69. if (isset($_POST['email']))
  70. {
  71. if ( ereg ("^.+@.+\..+$", $_POST['email']))
  72. {
  73. //if user changing password...
  74. if ($_POST['password']!='')
  75. {
  76. if (md5($_POST['password'])==User::UserInformation($_SESSION['uid'],'pass'))
  77. {
  78. if ($_POST['newpassword']==$_POST['confirmpassword'])
  79. {
  80. User::UpdatePassword($_SESSION['uid'], md5(strip_tags($_POST['newpassword'])));
  81. $errors = false;
  82. }
  83. else
  84. {
  85. $message=$lng['incorrect_password2'];
  86. $msg = './template/post_error_body.tpl';
  87. }
  88. }
  89. else
  90. {
  91. $message=$lng['incorrect_password'];
  92. $msg = './template/post_error_body.tpl';
  93. }
  94. }
  95. else
  96. {
  97. if ($_POST['default_skin']!='-1')
  98. {
  99. if ($_POST['default_lang']!='-1')
  100. {
  101. if ($_POST['limit_tpid']!='-1')
  102. {
  103. if ($_POST['limit_ftid']!='-1')
  104. {
  105. if ($_POST['limit_users']!='-1')
  106. {
  107. if (strlen(trim($_POST['sig']))<$forum_config['sig_len'])
  108. {
  109. $errors = false;
  110. }
  111. else
  112. {
  113. $message = $lng['signature_too_long'];
  114. $msg = './template/post_error_body.tpl';
  115. }
  116. }
  117. else
  118. {
  119. $message = $lng['no_limit_users'];
  120. $msg = './template/post_error_body.tpl';
  121. }
  122. }
  123. else
  124. {
  125. $message = $lng['no_limit_ftid'];
  126. $msg = './template/post_error_body.tpl';
  127. }
  128. }
  129. else
  130. {
  131. $message = $lng['no_limit_tpid'];
  132. $msg = './template/post_error_body.tpl';
  133. }
  134. }
  135. else
  136. {
  137. $message=$lng['invalid_lang'];
  138. $msg = './template/post_error_body.tpl';
  139. }
  140. }
  141. else
  142. {
  143. $message=$lng['invalid_skin'];
  144. $msg = './template/post_error_body.tpl';
  145. }
  146. }
  147. if (!$errors)
  148. {
  149. $_POST['ggnumber']=strip_tags($_POST['ggnumber']);
  150. $_POST['interests']=strip_tags($_POST['interests']);
  151. $_POST['sig']=Secure::TagsReplace($_POST['sig']);
  152. $allow_shoutbox = (isset($_POST['allow_shoutbox'])) ? '1' : 0;
  153. if (isset($_FILES['avatar_file']['tmp_name']))
  154. {
  155. $extension = substr($_FILES['avatar_file']['name'],(strlen($_FILES['avatar_file']['name'])-3));
  156. if (($extension == 'jpg') or ($extension == 'gif'))
  157. {
  158. if (file_exists(AV_CATALOG.'av-'.$_SESSION['uid'].'.jpg'))
  159. {
  160. unlink(AV_CATALOG.'av-'.$_SESSION['uid'].'.jpg');
  161. }
  162. if (file_exists(AV_CATALOG.'av-'.$_SESSION['uid'].'.gif'))
  163. {
  164. unlink(AV_CATALOG.'av-'.$_SESSION['uid'].'.gif');
  165. }
  166. move_uploaded_file($_FILES['avatar_file']['tmp_name'], AV_CATALOG.'av-'.$_SESSION['uid'].'.'.$extension);
  167. $_POST['avatar'] = AV_CATALOG.'av-'.$_SESSION['uid'].'.'.$extension;
  168. }
  169. else
  170. {
  171. $_POST['avatar'] = strip_tags($_POST['avatar']);
  172. }
  173. }
  174. else
  175. {
  176. $_POST['avatar'] = strip_tags($_POST['avatar']);
  177. }
  178. User::UpdateAdminPools($uid,strip_tags($_POST['posts']),$_POST['user_rank'],$_POST['user_active'], strip_tags($_POST['nick']));
  179. User::UpdateProfile($uid,$_POST['ggnumber'],$_POST['email'],$_POST['interests'], $_POST['sig'],$_POST['avatar'],$_POST['allow_qr'],$_POST['allow_email'],$_POST['allow_gg'],$_POST['default_skin'],$_POST['default_lang'], $_POST['limit_tpid'],$_POST['limit_ftid'], $_POST['limit_users'], $allow_shoutbox);
  180. admin_message_forum($lng['profile_modernized'],'admin_users.php?mode=edit&id='.$uid);
  181. }
  182. }
  183. else
  184. {
  185. $message=$lng['invalid_email'];
  186. $msg = './template/post_error_body.tpl';
  187. }
  188. }
  189. $sql = "SELECT * FROM ".USERS_TABLE." WHERE `u_id`='$uid'";
  190. $userinfo = @mysql_fetch_array(DataBase::sql_query($sql,'GENERAL','Could not obtain user information'));
  191. if ($userinfo['rank']=='')
  192. {
  193. admin_message_forum($lng['no_user'],'admin_users.php?mode=view');
  194. }
  195. //add skin variables
  196. $skin = array(
  197. //labels profile
  198. 'L.admin_users'=>$lng['admin_users'],
  199. 'lnick'=>$lng['user_name'],
  200. 'lpass'=>$lng['lpassw'],
  201. 'lnewpass'=>$lng['new_password'],
  202. 'lcpass'=>$lng['confirm_password'],
  203. 'lemail'=>'E-mail',
  204. 'lgg'=>$lng['gg_number'],
  205. 'lallow_gg'=>$lng['allow_gg'],
  206. 'lallow_email'=>$lng['allow_email'],
  207. 'lallow_qr'=>$lng['allow_qr'],
  208. 'linterests'=>$lng['luinterests'],
  209. 'lsig'=>$lng['sig'],
  210. 'lavaddr'=>$lng['picture_adress'],
  211. 'lovpr'=>$lng['general_settings'],
  212. 'L.select_value'=>$lng['select_value'],
  213. 'L.limit_users'=>$lng['limit_users'],
  214. 'OPTIONS.limit_users'=>Admin_Over::AddPages2($userinfo['limit_users']),
  215. 'L.posts_in_topic'=>$lng['limit_posts'],
  216. 'OPTIONS.limit_tpid'=>Admin_Over::AddPages2($userinfo['limit_tpid']),
  217. 'L.topics_in_forum'=>$lng['limit_topics'],
  218. 'OPTIONS.limit_ftid'=>Admin_Over::AddPages2($userinfo['limit_ftid']),
  219. 'lupr'=>$lng['profile_settings'],
  220. 'lspr'=>$lng['signature_settings'],
  221. 'ladmpr'=>$lng['admin_settings'],
  222. 'luser_rank'=>$lng['user_rank'],
  223. 'luser_actived'=>$lng['user_actived'],
  224. 'lposts'=>$lng['posts'],
  225. 'posts'=>$userinfo['posts'],
  226. 'ldefault_lang'=>$lng['default_lang'],
  227. 'default_lang'=>Admin_Over::AddLangs(),
  228. 'l2default_lang'=>$lng['select_lang'],
  229. 'ldefault_skin'=>$lng['default_skin2'],
  230. 'default_skin'=>Admin_Over::AddSkins(),
  231. 'l2default_skin'=>$lng['select_skin'],
  232. 'lapr'=>$lng['avatar_settings'],
  233. 'lsubmit'=>$lng['save'],
  234. 'allow'=>$lng['allow'],
  235. 'lreset'=>$lng['reset'],
  236. 'nick'=>$userinfo['nick'],
  237. 'user'=>$lng['user'],
  238. 'lallow_shoutbox'=>$lng['allow_shoutbox'],
  239. 'allow_shoutbox'=>($userinfo['view_shoutbox']==1) ? 'checked="checked"' : '',
  240. //options profile
  241. 'sig'=>$userinfo['sig'],
  242. 'avatar'=>$userinfo['avatar'],
  243. 'interests'=>$userinfo['interests'],
  244. 'email'=>$userinfo['email'],
  245. 'gg'=>$userinfo['gg'],
  246. //options values
  247. 'option_no_gg'=>($userinfo['allow_gg']==0) ? 'checked="checked"' : '',
  248. 'option_no_email'=>($userinfo['allow_email']==0) ? 'checked="checked"' : '',
  249. 'option_no_qr'=>($userinfo['allow_qr']==0) ? 'checked="checked"' : '',
  250. 'option_yes_gg'=>($userinfo['allow_gg']==1) ? 'checked="checked"' : '',
  251. 'option_yes_email'=>($userinfo['allow_email']==1) ? 'checked="checked"' : '',
  252. 'option_yes_qr'=>($userinfo['allow_qr']==1) ? 'checked="checked"' : '',
  253. 'option_no_ua'=>($userinfo['active']==0) ? 'checked="checked"' : '',
  254. 'option_yes_ua'=>($userinfo['active']==1) ? 'checked="checked"' : '',
  255. //user rank
  256. 'option_0_rank'=>($userinfo['rank']==0) ? 'checked="checked"' : '',
  257. 'option_1_rank'=>($userinfo['rank']==1) ? 'checked="checked"' : '',
  258. 'option_2_rank'=>($userinfo['rank']==2) ? 'checked="checked"' : '',
  259. 'no'=>$lng['no'],
  260. 'lavfile'=>$lng['avatar_file'],
  261. 'yes'=>$lng['yes']
  262. );
  263. if ($msg=='')
  264. {
  265. $msg = './template/blank.tpl';
  266. }
  267. Admin_Over::GenerateHeader();
  268. include('./template/user_edit_body.tpl');
  269. include('./template/overall_footer.tpl');;
  270. break;
  271. }
  272. case 'view':
  273. {
  274. if (isset($_GET['page'])&&($_GET['page']!=1))
  275. {
  276. if (!is_numeric($_GET['page']))
  277. {
  278. die('Hacking attempt');
  279. }
  280. $value = ($_GET['page']-1)*30;
  281. $limit = 'LIMIT '.$value . ', 30';
  282. $page = $_GET['page'];
  283. }
  284. else
  285. {
  286. $limit = 'LIMIT 0, 30';
  287. $page=1;
  288. }
  289. $count = @mysql_fetch_array(DataBase::sql_query("SELECT COUNT(`u_id`) as `u_id`
  290. FROM ".USERS_TABLE,'GENERAL','Could not obtain count amout of users'));
  291. $count = $count['u_id'];
  292. $count = ceil($count /30);
  293. if(isset($_GET['page']) && ($_GET['page']>$count))
  294. {
  295. message_forum($lng['invalidpage'],'admin_users.php');
  296. }
  297. if (isset($_COOKIE['users_desc'], $_POST['desc']))
  298. {
  299. unset($_COOKIE['users_desc']);
  300. }
  301. if (isset($_POST['sort'],$_COOKIE['users_sort']))
  302. {
  303. unset($_COOKIE['users_sort']);
  304. }
  305. if (!isset($_COOKIE['users_desc']))
  306. {
  307. if (isset($_POST['desc']))
  308. {
  309. switch($_POST['desc'])
  310. {
  311. case 'yes':
  312. {
  313. @setcookie('users_desc','desc',time()+3600);
  314. $_COOKIE['users_desc'] = 'desc';
  315. $desc = 'DESC';
  316. break;
  317. }
  318. case 'no':
  319. {
  320. @setcookie('users_desc','no',time()+3600);
  321. $_COOKIE['users_desc'] = 'no';
  322. $desc = '';
  323. break;
  324. }
  325. }
  326. }
  327. else
  328. {
  329. @setcookie('users_desc','no',time()+3600);
  330. $_COOKIE['users_desc'] = 'no';
  331. $desc = '';
  332. }
  333. }
  334. else
  335. {
  336. $desc = ($_COOKIE['users_desc']=='desc') ? 'DESC' : '';
  337. }
  338. if (!isset($_COOKIE['users_sort']))
  339. {
  340. if (isset($_POST['sort']))
  341. {
  342. switch($_POST['sort'])
  343. {
  344. case 'regdate':
  345. {
  346. @setcookie('users_sort','regdate',time()+3600);
  347. $_COOKIE['users_sort'] = 'regdate';
  348. break;
  349. }
  350. case 'lastvisit':
  351. {
  352. @setcookie('users_sort','lastvisit',time()+3600);
  353. $_COOKIE['users_sort'] = 'lastvisit';
  354. break;
  355. }
  356. case 'uname':
  357. {
  358. @setcookie('users_sort','uname',time()+3600);
  359. $_COOKIE['users_sort'] = 'uname';
  360. break;
  361. }
  362. case 'posts':
  363. {
  364. @setcookie('users_sort','posts',time()+3600);
  365. $_COOKIE['users_sort'] = 'posts';
  366. break;
  367. }
  368. }
  369. }
  370. else
  371. {
  372. @setcookie('users_sort','regdate',time()+3600);
  373. $_COOKIE['users_sort'] = 'regdate';
  374. }
  375. }
  376. //add skin variables
  377. $skin = array(
  378. 'ldesc' => $lng['desc'],
  379. 'lselectusers'=>$lng['sort_u_by'],
  380. 'ltitle'=>$lng['admin_users'],
  381. 'lregdate'=>$lng['luregister'],
  382. 'llastvisit'=>$lng['lulastvisit'],
  383. 'lposts'=>$lng['posts'],
  384. 'luname'=>$lng['user_name'],
  385. 'lgo'=>$lng['lgo'],
  386. 'desc_yes_option'=>(($_COOKIE['users_desc']=='desc') || ((isset ($_POST['desc'])) && ($_POST['desc']=='yes'))) ? 'selected="selected"' : '',
  387. 'desc_no_option'=>(($_COOKIE['users_desc']=='no') || ((isset ($_POST['desc'])) && ($_POST['desc']=='no'))) ? 'selected="selected"' : '',
  388. 'regdate_option'=>(($_COOKIE['users_sort']=='regdate') || ((isset ($_POST['sort'])) && ($_POST['sort']=='posts'))) ? 'selected="selected"' : '',
  389. 'lastvisit_option'=>(($_COOKIE['users_sort']=='lastvisit') || ((isset ($_POST['sort'])) && ($_POST['sort']=='lastvisit'))) ? 'selected="selected"' : '',
  390. 'posts_option'=>(($_COOKIE['users_sort']=='posts') || ((isset ($_POST['sort'])) && ($_POST['sort']=='posts'))) ? 'selected="selected"' : '',
  391. 'uname_option'=>(($_COOKIE['users_sort']=='uname') || ((isset ($_POST['sort'])) && ($_POST['sort']=='uname'))) ? 'selected="selected"' : '',
  392. 'lyes'=>$lng['yes'],
  393. 'lno'=>$lng['no']
  394. );
  395. //do it!
  396. Admin_Over::GenerateHeader();
  397. include('./template/users_beam_body.tpl');
  398. switch($_COOKIE['users_sort'])
  399. {
  400. case 'regdate':
  401. {
  402. $sql = "SELECT `u_id`,`nick`, `rank`, `regdate`, `lastvisit`, `posts` FROM `".USERS_TABLE."` WHERE `u_id`>0 ORDER BY `regdate` $desc $limit;";
  403. break;
  404. }
  405. case 'lastvisit':
  406. {
  407. $sql = "SELECT `u_id`,`nick`, `rank`, `regdate`, `lastvisit`, `posts` FROM `".USERS_TABLE."` WHERE `u_id`>0 ORDER BY `lastvisit` $desc $limit;";
  408. break;
  409. }
  410. case 'uname':
  411. {
  412. $sql = "SELECT `u_id`,`nick`, `rank`, `regdate`, `lastvisit`, `posts` FROM `".USERS_TABLE."` WHERE `u_id`>0 ORDER BY `nick` $desc $limit;";
  413. break;
  414. }
  415. case 'posts':
  416. {
  417. $sql = "SELECT `u_id`,`nick`, `rank`, `regdate`, `lastvisit`, `posts` FROM `".USERS_TABLE."` WHERE `u_id`>0 ORDER BY `posts` $desc $limit;";
  418. break;
  419. }
  420. }
  421. $query = DataBase::sql_query($sql,'CRITICAL','Could not obtain user information.');
  422. while($result = mysql_fetch_array($query))
  423. {
  424. $skin = array(
  425. 'id'=>$result['u_id'],
  426. 'uname'=>Topic::UserName($result['nick'], $result['rank']),
  427. 'regdate'=>date('d-m-Y, G:i',$result['regdate']),
  428. 'lastvisit'=>($result['lastvisit']!='0') ? date('d-m-Y, G:i',$result['lastvisit']) : $lng['never'],
  429. 'posts'=>$result['posts'],
  430. 'c_del_user'=>$lng['c_delete_user']
  431. );
  432. include('./template/user_item_add_body.tpl');
  433. }
  434. $skin = array(
  435. 'option_pages'=>Admin_Over::AddPages(),
  436. 'lwith'=>$lng['with'],
  437. 'lpage'=>$lng['page'],
  438. 'lpages'=>$count
  439. );
  440. include('./template/users_end_body.tpl');
  441. include('./template/overall_footer.tpl');
  442. break;
  443. }
  444. default:
  445. {
  446. header('Location: admin_users.php?mode=view');
  447. break;
  448. }
  449. }
  450. ?>