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.

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