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/misc_functions.php');
  23. include('./../includes/classes/class_topic.php');
  24. include('./../includes/classes/class_posting.php');
  25. include('./../includes/classes/secure.php');
  26. $default_lang = Admin_Over::DefaultLang();
  27. include('./../lngs/'.$default_lang.'/admin.php');
  28. SessDelInvalid();
  29. SessRegister();
  30. SessDeleteOld();
  31. if (User::UserInformation($_SESSION['uid'],'rank')!=2)
  32. {
  33. admin_message_forum($lng['yournotadmin'],'../index.php');
  34. }
  35. if (!isset($_GET['mode']))
  36. {
  37. header('Location: admin_users.php?mode=view');
  38. }
  39. switch($_GET['mode'])
  40. {
  41. case 'delete':
  42. {
  43. $uid = intval($_GET['id']);
  44. //delete from users table
  45. $sql = "DELETE FROM ".USERS_TABLE." WHERE `u_id`='$uid'";
  46. DataBase::sql_query($sql,GENERAL,'Could not delete user.');
  47. //delete from PM SentBox table
  48. $sql = "DELETE FROM ".PM_SENTBOX_TABLE." WHERE `u_n_id`='$uid'";
  49. DataBase::sql_query($sql,GENERAL,'Could not delete user sentbox messages.');
  50. //update PM InBox table -> change u_n_id to Anonymous
  51. $sql = "UPDATE ".PM_INBOX_TABLE." SET `u_n_id`='-1' WHERE `u_n_id`='$uid'";
  52. DataBase::sql_query($sql,GENERAL,'Could not update user inbox messages.');
  53. //update user posts -> change u_id to Anonymous
  54. $sql = "UPDATE ".POSTS_TABLE." SET `u_id`='-1' WHERE `u_id`='$uid'";
  55. DataBase::sql_query($sql,GENERAL,'Could edit post.');
  56. //update shoutbox messages -> change u_id to Anonymous
  57. $sql = "UPDATE ".SHOUTBOX_TABLE." SET `u_id`='-1' WHERE `u_id`='$uid'";
  58. DataBase::sql_query($sql,GENERAL,'Could edit shoutbox messages.');
  59. //update user topics -> change u_id to Anonymous
  60. $sql = "UPDATE ".TOPICS_TABLE." SET `author`='-1' WHERE `author`='$uid'";
  61. DataBase::sql_query($sql,GENERAL,'Could edit post.');
  62. //back to admin users
  63. admin_message_forum($lng['user_deleted'],'admin_users.php');
  64. break;
  65. }
  66. case 'edit':
  67. {
  68. $uid = intval($_GET['id']);
  69. $msg='';
  70. $errors = true;
  71. if (isset($_POST['email']))
  72. {
  73. if ( ereg ("^.+@.+\..+$", $_POST['email']))
  74. {
  75. //if user changing password...
  76. if ($_POST['password']!='')
  77. {
  78. if (md5($_POST['password'])==User::UserInformation($_SESSION['uid'],'pass'))
  79. {
  80. if ($_POST['newpassword']==$_POST['confirmpassword'])
  81. {
  82. User::UpdatePassword($_SESSION['uid'], md5(strip_tags($_POST['newpassword'])));
  83. $errors = false;
  84. }
  85. else
  86. {
  87. $message=$lng['incorrect_password2'];
  88. $msg = './template/post_error_body.tpl';
  89. }
  90. }
  91. else
  92. {
  93. $message=$lng['incorrect_password'];
  94. $msg = './template/post_error_body.tpl';
  95. }
  96. }
  97. else
  98. {
  99. if ($_POST['default_skin']!='-1')
  100. {
  101. if ($_POST['default_lang']!='-1')
  102. {
  103. if ($_POST['limit_tpid']!='-1')
  104. {
  105. if ($_POST['limit_ftid']!='-1')
  106. {
  107. if ($_POST['limit_users']!='-1')
  108. {
  109. if (strlen(trim($_POST['sig']))<$forum_config['sig_len'])
  110. {
  111. $errors = false;
  112. }
  113. else
  114. {
  115. $message = $lng['signature_too_long'];
  116. $msg = './template/post_error_body.tpl';
  117. }
  118. }
  119. else
  120. {
  121. $message = $lng['no_limit_users'];
  122. $msg = './template/post_error_body.tpl';
  123. }
  124. }
  125. else
  126. {
  127. $message = $lng['no_limit_ftid'];
  128. $msg = './template/post_error_body.tpl';
  129. }
  130. }
  131. else
  132. {
  133. $message = $lng['no_limit_tpid'];
  134. $msg = './template/post_error_body.tpl';
  135. }
  136. }
  137. else
  138. {
  139. $message=$lng['invalid_lang'];
  140. $msg = './template/post_error_body.tpl';
  141. }
  142. }
  143. else
  144. {
  145. $message=$lng['invalid_skin'];
  146. $msg = './template/post_error_body.tpl';
  147. }
  148. }
  149. if (!$errors)
  150. {
  151. $_POST['ggnumber']=strip_tags($_POST['ggnumber']);
  152. $_POST['interests']=strip_tags($_POST['interests']);
  153. $_POST['sig']=Secure::TagsReplace($_POST['sig']);
  154. $allow_shoutbox = (isset($_POST['allow_shoutbox'])) ? '1' : 0;
  155. if (isset($_FILES['avatar_file']['tmp_name']))
  156. {
  157. $extension = substr($_FILES['avatar_file']['name'],(strlen($_FILES['avatar_file']['name'])-3));
  158. if (($extension == 'jpg') or ($extension == 'gif'))
  159. {
  160. if (file_exists(AV_CATALOG.'av-'.$_SESSION['uid'].'.jpg'))
  161. {
  162. unlink(AV_CATALOG.'av-'.$_SESSION['uid'].'.jpg');
  163. }
  164. if (file_exists(AV_CATALOG.'av-'.$_SESSION['uid'].'.gif'))
  165. {
  166. unlink(AV_CATALOG.'av-'.$_SESSION['uid'].'.gif');
  167. }
  168. move_uploaded_file($_FILES['avatar_file']['tmp_name'], AV_CATALOG.'av-'.$_SESSION['uid'].'.'.$extension);
  169. $_POST['avatar'] = AV_CATALOG.'av-'.$_SESSION['uid'].'.'.$extension;
  170. }
  171. else
  172. {
  173. $_POST['avatar'] = strip_tags($_POST['avatar']);
  174. }
  175. }
  176. else
  177. {
  178. $_POST['avatar'] = strip_tags($_POST['avatar']);
  179. }
  180. User::UpdateAdminPools($uid,strip_tags($_POST['posts']),$_POST['user_rank'],$_POST['user_active'], strip_tags($_POST['nick']));
  181. 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);
  182. admin_message_forum($lng['profile_modernized'],'admin_users.php?mode=edit&id='.$uid);
  183. }
  184. }
  185. else
  186. {
  187. $message=$lng['invalid_email'];
  188. $msg = './template/post_error_body.tpl';
  189. }
  190. }
  191. $sql = "SELECT * FROM ".USERS_TABLE." WHERE `u_id`='$uid'";
  192. $userinfo = DataBase::fetch(DataBase::sql_query($sql,GENERAL,'Could not obtain user information'));
  193. if ($userinfo['rank']=='')
  194. {
  195. admin_message_forum($lng['no_user'],'admin_users.php?mode=view');
  196. }
  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'=>ListPages($userinfo['limit_users']),
  217. 'L.posts_in_topic'=>$lng['limit_posts'],
  218. 'OPTIONS.limit_tpid'=>ListPages($userinfo['limit_tpid']),
  219. 'L.topics_in_forum'=>$lng['limit_topics'],
  220. 'OPTIONS.limit_ftid'=>ListPages($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'=>ListDir('../lngs', $userinfo['lang']),
  230. 'l2default_lang'=>$lng['select_lang'],
  231. 'ldefault_skin'=>$lng['default_skin2'],
  232. 'default_skin'=>ListDir('../skins', $userinfo['skin']),
  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 = DataBase::fetch(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 = DataBase::fetch($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'=>ListPages($page, $count),
  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. ?>