PageRenderTime 49ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/profile.php

https://github.com/Dratone/EveBB
PHP | 2002 lines | 1578 code | 335 blank | 89 comment | 656 complexity | 7998ceeefe2444520437ec0513b69c59 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Copyright (C) 2008-2010 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. define('PUN_ROOT', dirname(__FILE__).'/');
  8. require PUN_ROOT.'include/common.php';
  9. // Include UTF-8 function
  10. require PUN_ROOT.'include/utf8/substr_replace.php';
  11. require PUN_ROOT.'include/utf8/ucwords.php'; // utf8_ucwords needs utf8_substr_replace
  12. require PUN_ROOT.'include/utf8/strcasecmp.php';
  13. if ($pun_user['is_guest'] && $pun_config['o_hide_stats'] == '1') {
  14. message($lang_common['No permission']);
  15. } //End if.
  16. $action = isset($_GET['action']) ? $_GET['action'] : null;
  17. $section = isset($_GET['section']) ? $_GET['section'] : null;
  18. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  19. if ($id < 2)
  20. message($lang_common['Bad request']);
  21. if ($action != 'change_pass' || !isset($_GET['key']))
  22. {
  23. if ($pun_user['g_read_board'] == '0')
  24. message($lang_common['No view']);
  25. else if ($pun_user['g_view_users'] == '0' && ($pun_user['is_guest'] || $pun_user['id'] != $id))
  26. message($lang_common['No permission']);
  27. }
  28. // Load the profile.php/register.php language file
  29. require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
  30. // Load the profile.php language file
  31. require PUN_ROOT.'lang/'.$pun_user['language'].'/profile.php';
  32. if ($action == 'del_group') {
  33. if ($pun_user['g_id'] != PUN_ADMIN) {
  34. message($lang_common['No permission']);
  35. } //End if.
  36. confirm_referrer('profile.php');
  37. $g_id = intval($_GET['g_id']);
  38. //Need to get some details.
  39. $sql = "SELECT group_id FROM ".$db->prefix."users WHERE id=".$id;
  40. if (!$result = $db->query($sql)) {
  41. if (defined('PUN_DEBUG')) {
  42. error('Unable to fetch user information.', __FILE__, __LINE__, $db->error());
  43. } //End if.
  44. message('Unable to fetch user information.');
  45. } //End if.
  46. if ($db->num_rows($result) != 1) {
  47. if (defined('PUN_DEBUG')) {
  48. error('User information is incomplete.', __FILE__, __LINE__, $db->error());
  49. } //End if.
  50. message('User information is incomplete.');
  51. } //End if.
  52. $result = $db->fetch_assoc($result);
  53. if ($result['group_id'] == $g_id) {
  54. //Lets see if they are in any other groups...
  55. $sql = "SELECT group_id FROM ".$db->prefix."groups_users WHERE user_id=".$id." ORDER BY group_id ASC";
  56. if (!$result = $db->query($sql)) {
  57. if (defined('PUN_DEBUG')) {
  58. error('Unable to fetch group information.', __FILE__, __LINE__, $db->error());
  59. } //End if.
  60. message('Unable to fetch group information.');
  61. } //End if.
  62. $new_g_id = $pun_config['o_eve_restricted_group'];
  63. if ($db->num_rows($result) > 0) {
  64. $result = $db->fetch_assoc($result);
  65. $new_g_id = $result['group_id']; //Move the to the highest group, numerically speaking.
  66. } //End if.
  67. //We update their main group...
  68. $sql = "UPDATE ".$db->prefix."users SET group_id=".$new_g_id." WHERE id=".$id;
  69. if (!$result = $db->query($sql)) {
  70. if (defined('PUN_DEBUG')) {
  71. error('Unable to update user information.', __FILE__, __LINE__, $db->error());
  72. } //End if.
  73. message('Unable to update user information.');
  74. } //End if.
  75. } //End if.
  76. $sql = "DELETE FROM ".$db->prefix."groups_users WHERE user_id=".$id." AND group_id=".$g_id;
  77. if (!$db->query($sql)) {
  78. if (defined('PUN_DEBUG')) {
  79. error('Unable to delete group from table.', __FILE__, __LINE__, $db->error());
  80. } //End if.
  81. message($lang_common['Bad request']);
  82. } //End if.
  83. redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['delete_group_redirect']);
  84. } //End if.
  85. if ($action == 'add_group' && !isset($_POST['delete_user'])) {
  86. if ($pun_user['g_id'] != PUN_ADMIN) {
  87. message($lang_common['No permission']);
  88. } //End if.
  89. confirm_referrer('profile.php');
  90. $g_id = intval($_GET['g_id']);
  91. if ($g_id < 1 || $g_id == PUN_GUEST) {
  92. if (defined('PUN_DEBUG')) {
  93. error('You have specified an incorrect group id.', __FILE__, __LINE__, $db->error());
  94. } //End if.
  95. message($lang_common['Bad request']);
  96. } //End if.
  97. $fields = array(
  98. 'user_id' => $id,
  99. 'group_id' => $g_id,
  100. );
  101. if (!$db->insert_or_update($fields, array('user_id', 'group_id'), $db->prefix.'groups_users')) {
  102. if (defined('PUN_DEBUG')) {
  103. error('Unable to add group to table.', __FILE__, __LINE__, $db->error());
  104. } //End if.
  105. message($lang_common['Bad request']);
  106. } //End if.
  107. redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['add_group_redirect']);
  108. } //End if.
  109. if ($action == 'change_pass')
  110. {
  111. if (isset($_GET['key']))
  112. {
  113. // If the user is already logged in we shouldn't be here :)
  114. if (!$pun_user['is_guest'])
  115. {
  116. header('Location: index.php');
  117. exit;
  118. }
  119. $key = $_GET['key'];
  120. $result = $db->query('SELECT * FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch new password', __FILE__, __LINE__, $db->error());
  121. $cur_user = $db->fetch_assoc($result);
  122. if ($key == '' || $key != $cur_user['activate_key'])
  123. message($lang_profile['Pass key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
  124. else
  125. {
  126. $db->query('UPDATE '.$db->prefix.'users SET password=\''.$cur_user['activate_string'].'\', activate_string=NULL, activate_key=NULL'.(!empty($cur_user['salt']) ? ', salt=NULL' : '').' WHERE id='.$id) or error('Unable to update password', __FILE__, __LINE__, $db->error());
  127. message($lang_profile['Pass updated'], true);
  128. }
  129. }
  130. // Make sure we are allowed to change this users password
  131. if ($pun_user['id'] != $id)
  132. {
  133. if (!$pun_user['is_admmod']) // A regular user trying to change another users password?
  134. message($lang_common['No permission']);
  135. else if ($pun_user['g_moderator'] == '1') // A moderator trying to change a users password?
  136. {
  137. $result = $db->query('SELECT u.group_id, g.g_moderator FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON (g.g_id=u.group_id) WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  138. if (!$db->num_rows($result))
  139. message($lang_common['Bad request']);
  140. list($group_id, $is_moderator) = $db->fetch_row($result);
  141. if ($pun_user['g_mod_edit_users'] == '0' || $pun_user['g_mod_change_passwords'] == '0' || $group_id == PUN_ADMIN || $is_moderator == '1')
  142. message($lang_common['No permission']);
  143. }
  144. }
  145. if (isset($_POST['form_sent']))
  146. {
  147. if ($pun_user['is_admmod'])
  148. confirm_referrer('profile.php');
  149. $old_password = isset($_POST['req_old_password']) ? pun_trim($_POST['req_old_password']) : '';
  150. $new_password1 = pun_trim($_POST['req_new_password1']);
  151. $new_password2 = pun_trim($_POST['req_new_password2']);
  152. if ($new_password1 != $new_password2)
  153. message($lang_prof_reg['Pass not match']);
  154. if (pun_strlen($new_password1) < 4)
  155. message($lang_prof_reg['Pass too short']);
  156. $result = $db->query('SELECT * FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch password', __FILE__, __LINE__, $db->error());
  157. $cur_user = $db->fetch_assoc($result);
  158. $authorized = false;
  159. if (!empty($cur_user['password']))
  160. {
  161. $old_password_hash = pun_hash($old_password);
  162. if ($cur_user['password'] == $old_password_hash || $pun_user['is_admmod'])
  163. $authorized = true;
  164. }
  165. if (!$authorized)
  166. message($lang_profile['Wrong pass']);
  167. $new_password_hash = pun_hash($new_password1);
  168. $db->query('UPDATE '.$db->prefix.'users SET password=\''.$new_password_hash.'\''.(!empty($cur_user['salt']) ? ', salt=NULL' : '').' WHERE id='.$id) or error('Unable to update password', __FILE__, __LINE__, $db->error());
  169. if ($pun_user['id'] == $id)
  170. pun_setcookie($pun_user['id'], $new_password_hash, time() + $pun_config['o_timeout_visit']);
  171. redirect('profile.php?section=essentials&amp;id='.$id, $lang_profile['Pass updated redirect']);
  172. }
  173. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['Profile'], $lang_profile['Change pass']);
  174. $required_fields = array('req_old_password' => $lang_profile['Old pass'], 'req_new_password1' => $lang_profile['New pass'], 'req_new_password2' => $lang_profile['Confirm new pass']);
  175. $focus_element = array('change_pass', ((!$pun_user['is_admmod']) ? 'req_old_password' : 'req_new_password1'));
  176. define('PUN_ACTIVE_PAGE', 'profile');
  177. require PUN_ROOT.'header.php';
  178. ?>
  179. <div class="blockform">
  180. <h2><span><?php echo $lang_profile['Change pass'] ?></span></h2>
  181. <div class="box">
  182. <form id="change_pass" method="post" action="profile.php?action=change_pass&amp;id=<?php echo $id ?>" onsubmit="return process_form(this)">
  183. <div class="inform">
  184. <input type="hidden" name="form_sent" value="1" />
  185. <fieldset>
  186. <legend><?php echo $lang_profile['Change pass legend'] ?></legend>
  187. <div class="infldset">
  188. <?php if (!$pun_user['is_admmod']): ?> <label class="required"><strong><?php echo $lang_profile['Old pass'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br />
  189. <input type="password" name="req_old_password" size="16" /><br /></label>
  190. <?php endif; ?> <label class="conl required"><strong><?php echo $lang_profile['New pass'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br />
  191. <input type="password" name="req_new_password1" size="16" /><br /></label>
  192. <label class="conl required"><strong><?php echo $lang_profile['Confirm new pass'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br />
  193. <input type="password" name="req_new_password2" size="16" /><br /></label>
  194. <p class="clearb"><?php echo $lang_profile['Pass info'] ?></p>
  195. </div>
  196. </fieldset>
  197. </div>
  198. <p class="buttons"><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  199. </form>
  200. </div>
  201. </div>
  202. <?php
  203. require PUN_ROOT.'footer.php';
  204. }
  205. else if ($action == 'change_email')
  206. {
  207. // Make sure we are allowed to change this users email
  208. if ($pun_user['id'] != $id)
  209. {
  210. if (!$pun_user['is_admmod']) // A regular user trying to change another users email?
  211. message($lang_common['No permission']);
  212. else if ($pun_user['g_moderator'] == '1') // A moderator trying to change a users email?
  213. {
  214. $result = $db->query('SELECT u.group_id, g.g_moderator FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON (g.g_id=u.group_id) WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  215. if (!$db->num_rows($result))
  216. message($lang_common['Bad request']);
  217. list($group_id, $is_moderator) = $db->fetch_row($result);
  218. if ($pun_user['g_mod_edit_users'] == '0' || $group_id == PUN_ADMIN || $is_moderator == '1')
  219. message($lang_common['No permission']);
  220. }
  221. }
  222. if (isset($_GET['key']))
  223. {
  224. $key = $_GET['key'];
  225. $result = $db->query('SELECT activate_string, activate_key FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch activation data', __FILE__, __LINE__, $db->error());
  226. list($new_email, $new_email_key) = $db->fetch_row($result);
  227. if ($key == '' || $key != $new_email_key)
  228. message($lang_profile['Email key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
  229. else
  230. {
  231. $db->query('UPDATE '.$db->prefix.'users SET email=activate_string, activate_string=NULL, activate_key=NULL WHERE id='.$id) or error('Unable to update email address', __FILE__, __LINE__, $db->error());
  232. message($lang_profile['Email updated'], true);
  233. }
  234. }
  235. else if (isset($_POST['form_sent']))
  236. {
  237. if (pun_hash($_POST['req_password']) !== $pun_user['password'])
  238. message($lang_profile['Wrong pass']);
  239. require PUN_ROOT.'include/email.php';
  240. // Validate the email address
  241. $new_email = strtolower(trim($_POST['req_new_email']));
  242. if (!is_valid_email($new_email))
  243. message($lang_common['Invalid email']);
  244. // Check if it's a banned email address
  245. if (is_banned_email($new_email))
  246. {
  247. if ($pun_config['p_allow_banned_email'] == '0')
  248. message($lang_prof_reg['Banned email']);
  249. else if ($pun_config['o_mailing_list'] != '')
  250. {
  251. $mail_subject = $lang_common['Banned email notification'];
  252. $mail_message = sprintf($lang_common['Banned email change message'], $pun_user['username'], $new_email)."\n";
  253. $mail_message .= sprintf($lang_common['User profile'], get_base_url().'/profile.php?id='.$id)."\n";
  254. $mail_message .= "\n".'--'."\n".$lang_common['Email signature'];
  255. pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
  256. }
  257. }
  258. // Check if someone else already has registered with that email address
  259. $result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE email=\''.$db->escape($new_email).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  260. if ($db->num_rows($result))
  261. {
  262. if ($pun_config['p_allow_dupe_email'] == '0')
  263. message($lang_prof_reg['Dupe email']);
  264. else if ($pun_config['o_mailing_list'] != '')
  265. {
  266. while ($cur_dupe = $db->fetch_assoc($result))
  267. $dupe_list[] = $cur_dupe['username'];
  268. $mail_subject = $lang_common['Duplicate email notification'];
  269. $mail_message = sprintf($lang_common['Duplicate email change message'], $pun_user['username'], implode(', ', $dupe_list))."\n";
  270. $mail_message .= sprintf($lang_common['User profile'], get_base_url().'/profile.php?id='.$id)."\n";
  271. $mail_message .= "\n".'--'."\n".$lang_common['Email signature'];
  272. pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
  273. }
  274. }
  275. $new_email_key = random_pass(8);
  276. $db->query('UPDATE '.$db->prefix.'users SET activate_string=\''.$db->escape($new_email).'\', activate_key=\''.$new_email_key.'\' WHERE id='.$id) or error('Unable to update activation data', __FILE__, __LINE__, $db->error());
  277. // Load the "activate email" template
  278. $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/activate_email.tpl'));
  279. // The first row contains the subject
  280. $first_crlf = strpos($mail_tpl, "\n");
  281. $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
  282. $mail_message = trim(substr($mail_tpl, $first_crlf));
  283. $mail_message = str_replace('<username>', $pun_user['username'], $mail_message);
  284. $mail_message = str_replace('<base_url>', get_base_url(), $mail_message);
  285. $mail_message = str_replace('<activation_url>', get_base_url().'/profile.php?action=change_email&id='.$id.'&key='.$new_email_key, $mail_message);
  286. $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);
  287. pun_mail($new_email, $mail_subject, $mail_message);
  288. message($lang_profile['Activate email sent'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.', true);
  289. }
  290. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['Profile'], $lang_profile['Change email']);
  291. $required_fields = array('req_new_email' => $lang_profile['New email'], 'req_password' => $lang_common['Password']);
  292. $focus_element = array('change_email', 'req_new_email');
  293. define('PUN_ACTIVE_PAGE', 'profile');
  294. require PUN_ROOT.'header.php';
  295. ?>
  296. <div class="blockform">
  297. <h2><span><?php echo $lang_profile['Change email'] ?></span></h2>
  298. <div class="box">
  299. <form id="change_email" method="post" action="profile.php?action=change_email&amp;id=<?php echo $id ?>" id="change_email" onsubmit="return process_form(this)">
  300. <div class="inform">
  301. <fieldset>
  302. <legend><?php echo $lang_profile['Email legend'] ?></legend>
  303. <div class="infldset">
  304. <input type="hidden" name="form_sent" value="1" />
  305. <label class="required"><strong><?php echo $lang_profile['New email'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /><input type="text" name="req_new_email" size="50" maxlength="80" /><br /></label>
  306. <label class="required"><strong><?php echo $lang_common['Password'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /><input type="password" name="req_password" size="16" /><br /></label>
  307. <p><?php echo $lang_profile['Email instructions'] ?></p>
  308. </div>
  309. </fieldset>
  310. </div>
  311. <p class="buttons"><input type="submit" name="new_email" value="<?php echo $lang_common['Submit'] ?>" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  312. </form>
  313. </div>
  314. </div>
  315. <?php
  316. require PUN_ROOT.'footer.php';
  317. }
  318. else if ($action == 'upload_avatar' || $action == 'upload_avatar2')
  319. {
  320. if ($pun_config['o_avatars'] == '0')
  321. message($lang_profile['Avatars disabled']);
  322. if ($pun_user['id'] != $id && !$pun_user['is_admmod'])
  323. message($lang_common['No permission']);
  324. if (isset($_POST['form_sent']))
  325. {
  326. if (!isset($_FILES['req_file']))
  327. message($lang_profile['No file']);
  328. $uploaded_file = $_FILES['req_file'];
  329. // Make sure the upload went smooth
  330. if (isset($uploaded_file['error']))
  331. {
  332. switch ($uploaded_file['error'])
  333. {
  334. case 1: // UPLOAD_ERR_INI_SIZE
  335. case 2: // UPLOAD_ERR_FORM_SIZE
  336. message($lang_profile['Too large ini']);
  337. break;
  338. case 3: // UPLOAD_ERR_PARTIAL
  339. message($lang_profile['Partial upload']);
  340. break;
  341. case 4: // UPLOAD_ERR_NO_FILE
  342. message($lang_profile['No file']);
  343. break;
  344. case 6: // UPLOAD_ERR_NO_TMP_DIR
  345. message($lang_profile['No tmp directory']);
  346. break;
  347. default:
  348. // No error occured, but was something actually uploaded?
  349. if ($uploaded_file['size'] == 0)
  350. message($lang_profile['No file']);
  351. break;
  352. }
  353. }
  354. if (is_uploaded_file($uploaded_file['tmp_name']))
  355. {
  356. // Preliminary file check, adequate in most cases
  357. $allowed_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
  358. if (!in_array($uploaded_file['type'], $allowed_types))
  359. message($lang_profile['Bad type']);
  360. // Make sure the file isn't too big
  361. if ($uploaded_file['size'] > $pun_config['o_avatars_size'])
  362. message($lang_profile['Too large'].' '.forum_number_format($pun_config['o_avatars_size']).' '.$lang_profile['bytes'].'.');
  363. // Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions
  364. if (!@move_uploaded_file($uploaded_file['tmp_name'], PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp'))
  365. message($lang_profile['Move failed'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
  366. list($width, $height, $type,) = @getimagesize(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');
  367. // Determine type
  368. if ($type == IMAGETYPE_GIF)
  369. $extension = '.gif';
  370. else if ($type == IMAGETYPE_JPEG)
  371. $extension = '.jpg';
  372. else if ($type == IMAGETYPE_PNG)
  373. $extension = '.png';
  374. else
  375. {
  376. // Invalid type
  377. @unlink(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');
  378. message($lang_profile['Bad type']);
  379. }
  380. // Now check the width/height
  381. if (empty($width) || empty($height) || $width > $pun_config['o_avatars_width'] || $height > $pun_config['o_avatars_height'])
  382. {
  383. @unlink(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp');
  384. message($lang_profile['Too wide or high'].' '.$pun_config['o_avatars_width'].'x'.$pun_config['o_avatars_height'].' '.$lang_profile['pixels'].'.');
  385. }
  386. // Delete any old avatars and put the new one in place
  387. delete_avatar($id);
  388. @rename(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.'.tmp', PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.$extension);
  389. @chmod(PUN_ROOT.$pun_config['o_avatars_dir'].'/'.$id.$extension, 0644);
  390. }
  391. else
  392. message($lang_profile['Unknown failure']);
  393. redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar upload redirect']);
  394. }
  395. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['Profile'], $lang_profile['Upload avatar']);
  396. $required_fields = array('req_file' => $lang_profile['File']);
  397. $focus_element = array('upload_avatar', 'req_file');
  398. define('PUN_ACTIVE_PAGE', 'profile');
  399. require PUN_ROOT.'header.php';
  400. ?>
  401. <div class="blockform">
  402. <h2><span><?php echo $lang_profile['Upload avatar'] ?></span></h2>
  403. <div class="box">
  404. <form id="upload_avatar" method="post" enctype="multipart/form-data" action="profile.php?action=upload_avatar2&amp;id=<?php echo $id ?>" onsubmit="return process_form(this)">
  405. <div class="inform">
  406. <fieldset>
  407. <legend><?php echo $lang_profile['Upload avatar legend'] ?></legend>
  408. <div class="infldset">
  409. <input type="hidden" name="form_sent" value="1" />
  410. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $pun_config['o_avatars_size'] ?>" />
  411. <label class="required"><strong><?php echo $lang_profile['File'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /><input name="req_file" type="file" size="40" /><br /></label>
  412. <p><?php echo $lang_profile['Avatar desc'].' '.$pun_config['o_avatars_width'].' x '.$pun_config['o_avatars_height'].' '.$lang_profile['pixels'].' '.$lang_common['and'].' '.forum_number_format($pun_config['o_avatars_size']).' '.$lang_profile['bytes'].' ('.file_size($pun_config['o_avatars_size']).').' ?></p>
  413. </div>
  414. </fieldset>
  415. </div>
  416. <p class="buttons"><input type="submit" name="upload" value="<?php echo $lang_profile['Upload'] ?>" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  417. </form>
  418. </div>
  419. </div>
  420. <?php
  421. require PUN_ROOT.'footer.php';
  422. }
  423. else if ($action == 'delete_avatar')
  424. {
  425. if ($pun_user['id'] != $id && !$pun_user['is_admmod'])
  426. message($lang_common['No permission']);
  427. confirm_referrer('profile.php');
  428. delete_avatar($id);
  429. redirect('profile.php?section=personality&amp;id='.$id, $lang_profile['Avatar deleted redirect']);
  430. }
  431. else if (isset($_POST['update_group_membership']))
  432. {
  433. if ($pun_user['g_id'] > PUN_ADMIN)
  434. message($lang_common['No permission']);
  435. confirm_referrer('profile.php');
  436. $new_group_id = intval($_POST['group_id']);
  437. $db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$id) or error('Unable to change user group', __FILE__, __LINE__, $db->error());
  438. // Regenerate the users info cache
  439. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  440. require PUN_ROOT.'include/cache.php';
  441. generate_users_info_cache();
  442. $result = $db->query('SELECT g_moderator FROM '.$db->prefix.'groups WHERE g_id='.$new_group_id) or error('Unable to fetch group', __FILE__, __LINE__, $db->error());
  443. $new_group_mod = $db->result($result);
  444. //Now lets remove the new group from the multiple group support table.
  445. $sql = "DELETE FROM ".$db->prefix."groups_users WHERE user_id=".$id." AND group_id=".$new_group_id;
  446. if (!$db->query($sql)) {
  447. if (defined('PUN_DEBUG')) {
  448. error('Unable to delete extra group from table.');
  449. } //End if.
  450. } //End if.
  451. // If the user was a moderator or an administrator, we remove him/her from the moderator list in all forums as well
  452. if ($new_group_id != PUN_ADMIN && $new_group_mod != '1') {
  453. $result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
  454. while ($cur_forum = $db->fetch_assoc($result)) {
  455. $cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
  456. if (in_array($id, $cur_moderators)) {
  457. $username = array_search($id, $cur_moderators);
  458. unset($cur_moderators[$username]);
  459. $cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
  460. $db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
  461. } //End if.
  462. } //End while loop.
  463. } //End if
  464. redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Group membership redirect']);
  465. }
  466. else if (isset($_POST['update_forums']))
  467. {
  468. if ($pun_user['g_id'] > PUN_ADMIN)
  469. message($lang_common['No permission']);
  470. confirm_referrer('profile.php');
  471. // Get the username of the user we are processing
  472. $result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  473. $username = $db->result($result);
  474. $moderator_in = (isset($_POST['moderator_in'])) ? array_keys($_POST['moderator_in']) : array();
  475. // Loop through all forums
  476. $result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
  477. while ($cur_forum = $db->fetch_assoc($result))
  478. {
  479. $cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
  480. // If the user should have moderator access (and he/she doesn't already have it)
  481. if (in_array($cur_forum['id'], $moderator_in) && !in_array($id, $cur_moderators))
  482. {
  483. $cur_moderators[$username] = $id;
  484. uksort($cur_moderators, 'utf8_strcasecmp');
  485. $db->query('UPDATE '.$db->prefix.'forums SET moderators=\''.$db->escape(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
  486. }
  487. // If the user shouldn't have moderator access (and he/she already has it)
  488. else if (!in_array($cur_forum['id'], $moderator_in) && in_array($id, $cur_moderators))
  489. {
  490. unset($cur_moderators[$username]);
  491. $cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
  492. $db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
  493. }
  494. }
  495. redirect('profile.php?section=admin&amp;id='.$id, $lang_profile['Update forums redirect']);
  496. }
  497. else if (isset($_POST['ban']))
  498. {
  499. if ($pun_user['g_id'] != PUN_ADMIN && ($pun_user['g_moderator'] != '1' || $pun_user['g_mod_ban_users'] == '0'))
  500. message($lang_common['No permission']);
  501. redirect('admin_bans.php?add_ban='.$id, $lang_profile['Ban redirect']);
  502. }
  503. else if (isset($_POST['delete_user']) || isset($_POST['delete_user_comply']))
  504. {
  505. if ($pun_user['g_id'] > PUN_ADMIN)
  506. message($lang_common['No permission']);
  507. confirm_referrer('profile.php');
  508. // Get the username and group of the user we are deleting
  509. $result = $db->query('SELECT group_id, username FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  510. list($group_id, $username) = $db->fetch_row($result);
  511. if ($group_id == PUN_ADMIN)
  512. message($lang_profile['No delete admin message']);
  513. if (isset($_POST['delete_user_comply']))
  514. {
  515. // If the user is a moderator or an administrator, we remove him/her from the moderator list in all forums as well
  516. $result = $db->query('SELECT g_moderator FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to fetch group', __FILE__, __LINE__, $db->error());
  517. $group_mod = $db->result($result);
  518. if ($group_id == PUN_ADMIN || $group_mod == '1')
  519. {
  520. $result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
  521. while ($cur_forum = $db->fetch_assoc($result))
  522. {
  523. $cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
  524. if (in_array($id, $cur_moderators))
  525. {
  526. unset($cur_moderators[$username]);
  527. $cur_moderators = (!empty($cur_moderators)) ? '\''.$db->escape(serialize($cur_moderators)).'\'' : 'NULL';
  528. $db->query('UPDATE '.$db->prefix.'forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
  529. }
  530. }
  531. }
  532. // Delete any subscriptions
  533. $db->query('DELETE FROM '.$db->prefix.'topic_subscriptions WHERE user_id='.$id) or error('Unable to delete topic subscriptions', __FILE__, __LINE__, $db->error());
  534. $db->query('DELETE FROM '.$db->prefix.'forum_subscriptions WHERE user_id='.$id) or error('Unable to delete forum subscriptions', __FILE__, __LINE__, $db->error());
  535. // Remove him/her from the online list (if they happen to be logged in)
  536. $db->query('DELETE FROM '.$db->prefix.'online WHERE user_id='.$id) or error('Unable to remove user from online list', __FILE__, __LINE__, $db->error());
  537. //Delete their api data, keep the character data.
  538. remove_api_keys($id);
  539. // Should we delete all posts made by this user?
  540. if (isset($_POST['delete_posts']))
  541. {
  542. require PUN_ROOT.'include/search_idx.php';
  543. @set_time_limit(0);
  544. // Find all posts made by this user
  545. $result = $db->query('SELECT p.id, p.topic_id, t.forum_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE p.poster_id='.$id) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
  546. if ($db->num_rows($result))
  547. {
  548. while ($cur_post = $db->fetch_assoc($result))
  549. {
  550. // Determine whether this post is the "topic post" or not
  551. $result2 = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$cur_post['topic_id'].' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  552. if ($db->result($result2) == $cur_post['id'])
  553. delete_topic($cur_post['topic_id']);
  554. else
  555. delete_post($cur_post['id'], $cur_post['topic_id']);
  556. update_forum($cur_post['forum_id']);
  557. }
  558. }
  559. } else {
  560. // Set all his/her posts to guest
  561. $db->query('UPDATE '.$db->prefix.'posts SET poster_id=1 WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $db->error());
  562. } //End if - else.
  563. //Let plugins do their own thing.
  564. foreach ($_HOOKS['users'] as $hook) {
  565. $hook->user_deleted($id);
  566. } //End foreach().
  567. // Delete the user
  568. $db->query('DELETE FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to delete user', __FILE__, __LINE__, $db->error());
  569. // New PMS
  570. require PUN_ROOT.'include/pms_new/common_pmsn.php';
  571. pmsn_user_delete($id, 2);
  572. $db->query('DELETE FROM '.$db->prefix.'pms_new_block WHERE bl_id='.$id.' OR bl_user_id='.$id) or error('Unable to delete user in pms_new_block', __FILE__, __LINE__, $db->error());
  573. // New PMS
  574. // Delete user avatar
  575. delete_avatar($id);
  576. // Regenerate the users info cache
  577. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  578. require PUN_ROOT.'include/cache.php';
  579. generate_users_info_cache();
  580. redirect('index.php', $lang_profile['User delete redirect']);
  581. }
  582. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['Profile'], $lang_profile['Confirm delete user']);
  583. define('PUN_ACTIVE_PAGE', 'profile');
  584. require PUN_ROOT.'header.php';
  585. ?>
  586. <div class="blockform">
  587. <h2><span><?php echo $lang_profile['Confirm delete user'] ?></span></h2>
  588. <div class="box">
  589. <form id="confirm_del_user" method="post" action="profile.php?id=<?php echo $id ?>">
  590. <div class="inform">
  591. <fieldset>
  592. <legend><?php echo $lang_profile['Confirm delete legend'] ?></legend>
  593. <div class="infldset">
  594. <p><?php echo $lang_profile['Confirmation info'].' <strong>'.pun_htmlspecialchars($username).'</strong>.' ?></p>
  595. <div class="rbox">
  596. <label><input type="checkbox" name="delete_posts" value="1" checked="checked" /><?php echo $lang_profile['Delete posts'] ?><br /></label>
  597. </div>
  598. <p class="warntext"><strong><?php echo $lang_profile['Delete warning'] ?></strong></p>
  599. </div>
  600. </fieldset>
  601. </div>
  602. <p class="buttons"><input type="submit" name="delete_user_comply" value="<?php echo $lang_profile['Delete'] ?>" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  603. </form>
  604. </div>
  605. </div>
  606. <?php
  607. require PUN_ROOT.'footer.php';
  608. }
  609. else if (isset($_POST['form_sent']))
  610. {
  611. // Fetch the user group of the user we are editing
  612. $result = $db->query('SELECT u.username, u.group_id, g.g_moderator FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON (g.g_id=u.group_id) WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  613. if (!$db->num_rows($result))
  614. message($lang_common['Bad request']);
  615. list($old_username, $group_id, $is_moderator) = $db->fetch_row($result);
  616. if ($pun_user['id'] != $id && // If we arent the user (i.e. editing your own profile)
  617. (!$pun_user['is_admmod'] || // and we are not an admin or mod
  618. ($pun_user['g_id'] != PUN_ADMIN && // or we aren't an admin and ...
  619. ($pun_user['g_mod_edit_users'] == '0' || // mods aren't allowed to edit users
  620. $group_id == PUN_ADMIN || // or the user is an admin
  621. $is_moderator)))) // or the user is another mod
  622. message($lang_common['No permission']);
  623. if ($pun_user['is_admmod'])
  624. confirm_referrer('profile.php');
  625. $username_updated = false;
  626. // Validate input depending on section
  627. switch ($section)
  628. {
  629. case 'essentials':
  630. {
  631. $form = array(
  632. 'timezone' => floatval($_POST['form']['timezone']),
  633. 'dst' => isset($_POST['form']['dst']) ? '1' : '0',
  634. 'time_format' => intval($_POST['form']['time_format']),
  635. 'date_format' => intval($_POST['form']['date_format']),
  636. );
  637. // Make sure we got a valid language string
  638. if (isset($_POST['form']['language']))
  639. {
  640. $languages = forum_list_langs();
  641. $form['language'] = pun_trim($_POST['form']['language']);
  642. if (!in_array($form['language'], $languages))
  643. message($lang_common['Bad request']);
  644. }
  645. if ($pun_user['is_admmod'])
  646. {
  647. $form['admin_note'] = pun_trim($_POST['admin_note']);
  648. // Are we allowed to change usernames?
  649. if ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && $pun_user['g_mod_rename_users'] == '1'))
  650. {
  651. $form['username'] = pun_trim($_POST['req_username']);
  652. if ($form['username'] != $old_username)
  653. {
  654. // Check username
  655. require PUN_ROOT.'lang/'.$pun_user['language'].'/register.php';
  656. $errors = array();
  657. check_username($form['username'], $id);
  658. if (!empty($errors))
  659. message($errors[0]);
  660. $username_updated = true;
  661. } //End if.
  662. }
  663. // We only allow administrators to update the post count
  664. if ($pun_user['g_id'] == PUN_ADMIN)
  665. $form['num_posts'] = intval($_POST['num_posts']);
  666. }
  667. if ($pun_config['o_regs_verify'] == '0' || $pun_user['is_admmod'])
  668. {
  669. require PUN_ROOT.'include/email.php';
  670. // Validate the email address
  671. $form['email'] = strtolower(trim($_POST['req_email']));
  672. if (!is_valid_email($form['email']))
  673. message($lang_common['Invalid email']);
  674. }
  675. break;
  676. }
  677. case 'personal':
  678. {
  679. $form = array(
  680. 'realname' => pun_trim($_POST['form']['realname']),
  681. 'url' => pun_trim($_POST['form']['url']),
  682. 'location' => pun_trim($_POST['form']['location']),
  683. );
  684. // Add http:// if the URL doesn't contain it already (while allowing https://, too)
  685. if ($form['url'] != '' && !preg_match('#^https?://#i', $form['url']))
  686. $form['url'] = 'http://'.$form['url'];
  687. if ($pun_user['g_id'] == PUN_ADMIN)
  688. $form['title'] = pun_trim($_POST['title']);
  689. else if ($pun_user['g_set_title'] == '1')
  690. {
  691. $form['title'] = pun_trim($_POST['title']);
  692. if ($form['title'] != '')
  693. {
  694. // A list of words that the title may not contain
  695. // If the language is English, there will be some duplicates, but it's not the end of the world
  696. $forbidden = array('member', 'moderator', 'administrator', 'banned', 'guest', utf8_strtolower($lang_common['Member']), utf8_strtolower($lang_common['Moderator']), utf8_strtolower($lang_common['Administrator']), utf8_strtolower($lang_common['Banned']), utf8_strtolower($lang_common['Guest']));
  697. if (in_array(utf8_strtolower($form['title']), $forbidden))
  698. message($lang_profile['Forbidden title']);
  699. }
  700. }
  701. break;
  702. }
  703. case 'messaging':
  704. {
  705. $form = array(
  706. 'jabber' => pun_trim($_POST['form']['jabber']),
  707. 'icq' => pun_trim($_POST['form']['icq']),
  708. 'msn' => pun_trim($_POST['form']['msn']),
  709. 'aim' => pun_trim($_POST['form']['aim']),
  710. 'yahoo' => pun_trim($_POST['form']['yahoo']),
  711. );
  712. // If the ICQ UIN contains anything other than digits it's invalid
  713. if (preg_match('/[^0-9]/', $form['icq']))
  714. message($lang_prof_reg['Bad ICQ']);
  715. break;
  716. }
  717. case 'personality':
  718. {
  719. $form = array();
  720. // Clean up signature from POST
  721. if ($pun_config['o_signatures'] == '1')
  722. {
  723. $form['signature'] = pun_linebreaks(pun_trim($_POST['signature']));
  724. // Validate signature
  725. if (pun_strlen($form['signature']) > $pun_config['p_sig_length'])
  726. message(sprintf($lang_prof_reg['Sig too long'], $pun_config['p_sig_length'], pun_strlen($form['signature']) - $pun_config['p_sig_length']));
  727. else if (substr_count($form['signature'], "\n") > ($pun_config['p_sig_lines']-1))
  728. message(sprintf($lang_prof_reg['Sig too many lines'], $pun_config['p_sig_lines']));
  729. else if ($form['signature'] && $pun_config['p_sig_all_caps'] == '0' && is_all_uppercase($form['signature']) && !$pun_user['is_admmod'])
  730. $form['signature'] = utf8_ucwords(utf8_strtolower($form['signature']));
  731. // Validate BBCode syntax
  732. if ($pun_config['p_sig_bbcode'] == '1')
  733. {
  734. require PUN_ROOT.'include/parser.php';
  735. $errors = array();
  736. $form['signature'] = preparse_bbcode($form['signature'], $errors, true);
  737. if(count($errors) > 0)
  738. message('<ul><li>'.implode('</li><li>', $errors).'</li></ul>');
  739. }
  740. }
  741. break;
  742. }
  743. case 'display':
  744. {
  745. $form = array(
  746. 'disp_topics' => pun_trim($_POST['form']['disp_topics']),
  747. 'disp_posts' => pun_trim($_POST['form']['disp_posts']),
  748. 'show_smilies' => isset($_POST['form']['show_smilies']) ? '1' : '0',
  749. 'show_img' => isset($_POST['form']['show_img']) ? '1' : '0',
  750. 'show_img_sig' => isset($_POST['form']['show_img_sig']) ? '1' : '0',
  751. 'show_avatars' => isset($_POST['form']['show_avatars']) ? '1' : '0',
  752. 'show_sig' => isset($_POST['form']['show_sig']) ? '1' : '0',
  753. );
  754. if ($form['disp_topics'] != '')
  755. {
  756. $form['disp_topics'] = intval($form['disp_topics']);
  757. if ($form['disp_topics'] < 3)
  758. $form['disp_topics'] = 3;
  759. else if ($form['disp_topics'] > 75)
  760. $form['disp_topics'] = 75;
  761. }
  762. if ($form['disp_posts'] != '')
  763. {
  764. $form['disp_posts'] = intval($form['disp_posts']);
  765. if ($form['disp_posts'] < 3)
  766. $form['disp_posts'] = 3;
  767. else if ($form['disp_posts'] > 75)
  768. $form['disp_posts'] = 75;
  769. }
  770. // Make sure we got a valid style string
  771. if (isset($_POST['form']['style']))
  772. {
  773. $styles = forum_list_styles();
  774. $form['style'] = pun_trim($_POST['form']['style']);
  775. if (!in_array($form['style'], $styles))
  776. message($lang_common['Bad request']);
  777. }
  778. break;
  779. }
  780. case 'privacy':
  781. {
  782. $form = array(
  783. 'email_setting' => intval($_POST['form']['email_setting']),
  784. 'notify_with_post' => isset($_POST['form']['notify_with_post']) ? '1' : '0',
  785. 'auto_notify' => isset($_POST['form']['auto_notify']) ? '1' : '0',
  786. );
  787. if ($form['email_setting'] < 0 || $form['email_setting'] > 2)
  788. $form['email_setting'] = $pun_config['o_default_email_setting'];
  789. break;
  790. }
  791. default:
  792. message($lang_common['Bad request']);
  793. }
  794. // Single quotes around non-empty values and NULL for empty values
  795. $temp = array();
  796. foreach ($form as $key => $input)
  797. {
  798. $value = ($input !== '') ? '\''.$db->escape($input).'\'' : 'NULL';
  799. $temp[] = $key.'='.$value;
  800. }
  801. if (empty($temp))
  802. message($lang_common['Bad request']);
  803. $db->query('UPDATE '.$db->prefix.'users SET '.implode(',', $temp).' WHERE id='.$id) or error('Unable to update profile', __FILE__, __LINE__, $db->error());
  804. // If we changed the username we have to update some stuff
  805. if ($username_updated)
  806. {
  807. // New PMS
  808. $db->query('UPDATE '.$db->prefix.'pms_new_topics SET starter=\''.$db->escape($form['username']).'\' WHERE starter_id='.$id) or error('Unable to update pms_new_topics', __FILE__, __LINE__, $db->error());
  809. $db->query('UPDATE '.$db->prefix.'pms_new_topics SET to_user=\''.$db->escape($form['username']).'\' WHERE to_id='.$id) or error('Unable to update pms_new_topics', __FILE__, __LINE__, $db->error());
  810. $db->query('UPDATE '.$db->prefix.'pms_new_posts SET poster=\''.$db->escape($form['username']).'\' WHERE poster_id='.$id) or error('Unable to update pms_new_posts', __FILE__, __LINE__, $db->error());
  811. $db->query('UPDATE '.$db->prefix.'pms_new_block SET bl_user=\''.$db->escape($form['username']).'\' WHERE bl_user_id='.$id) or error('Unable to update ms_new_block', __FILE__, __LINE__, $db->error());
  812. // New PMS
  813. $db->query('UPDATE '.$db->prefix.'posts SET poster=\''.$db->escape($form['username']).'\' WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $db->error());
  814. $db->query('UPDATE '.$db->prefix.'posts SET edited_by=\''.$db->escape($form['username']).'\' WHERE edited_by=\''.$db->escape($old_username).'\'') or error('Unable to update posts', __FILE__, __LINE__, $db->error());
  815. $db->query('UPDATE '.$db->prefix.'topics SET poster=\''.$db->escape($form['username']).'\' WHERE poster=\''.$db->escape($old_username).'\'') or error('Unable to update topics', __FILE__, __LINE__, $db->error());
  816. $db->query('UPDATE '.$db->prefix.'topics SET last_poster=\''.$db->escape($form['username']).'\' WHERE last_poster=\''.$db->escape($old_username).'\'') or error('Unable to update topics', __FILE__, __LINE__, $db->error());
  817. $db->query('UPDATE '.$db->prefix.'forums SET last_poster=\''.$db->escape($form['username']).'\' WHERE last_poster=\''.$db->escape($old_username).'\'') or error('Unable to update forums', __FILE__, __LINE__, $db->error());
  818. $db->query('UPDATE '.$db->prefix.'online SET ident=\''.$db->escape($form['username']).'\' WHERE ident=\''.$db->escape($old_username).'\'') or error('Unable to update online list', __FILE__, __LINE__, $db->error());
  819. // If the user is a moderator or an administrator we have to update the moderator lists
  820. $result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  821. $group_id = $db->result($result);
  822. $result = $db->query('SELECT g_moderator FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to fetch group', __FILE__, __LINE__, $db->error());
  823. $group_mod = $db->result($result);
  824. if ($group_id == PUN_ADMIN || $group_mod == '1')
  825. {
  826. $result = $db->query('SELECT id, moderators FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
  827. while ($cur_forum = $db->fetch_assoc($result))
  828. {
  829. $cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
  830. if (in_array($id, $cur_moderators))
  831. {
  832. unset($cur_moderators[$old_username]);
  833. $cur_moderators[$form['username']] = $id;
  834. uksort($cur_moderators, 'utf8_strcasecmp');
  835. $db->query('UPDATE '.$db->prefix.'forums SET moderators=\''.$db->escape(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
  836. }
  837. }
  838. }
  839. }
  840. redirect('profile.php?section='.$section.'&amp;id='.$id, $lang_profile['Profile redirect']);
  841. }
  842. //$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  843. // add "g.g_pm, u.messages_enable," - New PMS
  844. $result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, u.last_visit, u.messages_enable, g.g_id, g.g_user_title, g.g_moderator, g.g_pm FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  845. if (!$db->num_rows($result))
  846. message($lang_common['Bad request']);
  847. $user = $db->fetch_assoc($result);
  848. /* EVE-BB Multi-group support.*/
  849. $user['group_ids'] = array();
  850. //We only look at their other groups if they aren't set as the purge group as primary.
  851. if ($pun_user['g_id'] != $pun_config['o_eve_restricted_group']) {
  852. $sql = "SELECT group_id FROM ".$db->prefix."groups_users WHERE user_id=".$pun_user['id'];
  853. $result = $db->query($sql) or error('Unable to fetch group list', __FILE__, __LINE__, $db->error());
  854. while ($row = $db->fetch_assoc($result)) {
  855. $user['group_ids'][] = $row['group_id'];
  856. } //End while loop.
  857. } //End if.
  858. /* EVE-BB Multi-group support.*/
  859. $last_post = format_time($user['last_post']);
  860. if ($user['signature'] != '')
  861. {
  862. require PUN_ROOT.'include/parser.php';
  863. $parsed_signature = parse_signature($user['signature']);
  864. }
  865. // View or edit?
  866. if ($pun_user['id'] != $id && // If we arent the user (i.e. editing your own profile)
  867. (!$pun_user['is_admmod'] || // and we are not an admin or mod
  868. ($pun_user['g_id'] != PUN_ADMIN && // or we aren't an admin and ...
  869. ($pun_user['g_mod_edit_users'] == '0' || // mods aren't allowed to edit users
  870. $user['g_id'] == PUN_ADMIN || // or the user is an admin
  871. $user['g_moderator'] == '1'))))
  872. {
  873. $user_personal = array();
  874. $char = fetch_selected_character($id);
  875. $user_personal[] = '<dt>'.$lang_common['Username'].'</dt>';
  876. $user_personal[] = '<dd>'.(($pun_config['o_eve_use_iga']) == '1' ? $char['character_name'] : pun_htmlspecialchars($user['username'])).(($_SESSION['igb']) ? '&nbsp;&nbsp;<a href="#" onclick="CCPEVE.showInfo(1377, '.$char['character_id'].'); return false">[Info]</a>' : '').'</dd>';
  877. $user_title_field = get_title($user);
  878. $user_personal[] = '<dt>'.$lang_common['Title'].'</dt>';
  879. $user_personal[] = '<dd>'.(($pun_config['o_censoring'] == '1') ? censor_words($user_title_field) : $user_title_field).'</dd>';
  880. if ($user['realname'] != '')
  881. {
  882. $user_personal[] = '<dt>'.$lang_profile['Realname'].'</dt>';
  883. $user_personal[] = '<dd>'.pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['realname']) : $user['realname']).'</dd>';
  884. }
  885. if ($user['location'] != '')
  886. {
  887. $user_personal[] = '<dt>'.$lang_profile['Location'].'</dt>';
  888. $user_personal[] = '<dd>'.pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['location']) : $user['location']).'</dd>';
  889. }
  890. if ($user['url'] != '')
  891. {
  892. $user['url'] = pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['url']) : $user['url']);
  893. $user_personal[] = '<dt>'.$lang_profile['Website'].'</dt>';
  894. $user_personal[] = '<dd><span class="website"><a href="'.$user['url'].'">'.$user['url'].'</a></span></dd>';
  895. }
  896. if ($user['email_setting'] == '0' && !$pun_user['is_guest'] && $pun_user['g_send_email'] == '1')
  897. $email_field = '<a href="mailto:'.$user['email'].'">'.$user['email'].'</a>';
  898. else if ($user['email_setting'] == '1' && !$pun_user['is_guest'] && $pun_user['g_send_email'] == '1')
  899. $email_field = '<a href="misc.php?email='.$id.'">'.$lang_common['Send email'].'</a>';
  900. else
  901. $email_field = '';
  902. if ($email_field != '')
  903. {
  904. $user_personal[] = '<dt>'.$lang_common['Email'].'</dt>';
  905. $user_personal[] = '<dd><span class="email">'.$email_field.'</span></dd>';
  906. }
  907. if ($_SESSION['igb']) {
  908. $user_personal[] = '<dt>'.$lang_common['Evemail'].'</dt>';
  909. $user_personal[] = '<dd><span class="evemail"><a href="#" onclick="CCPEVE.sendMail('.$char['character_id'].', \'Re: \', \'-\'); return false">'.$lang_common['Evemail'].'</a></span></dd>';
  910. } //End if.
  911. // New PMS
  912. if (!$pun_user['is_guest'] && $pun_config['o_pms_enabled'] == '1' && $pun_user['g_pm'] == 1 && $pun_user['messages_enable'] == 1)
  913. if ($user['g_pm'] == 1 && $user['messages_enable'] == 1)
  914. {
  915. $user_personal[] = '<dt>'.$lang_common['PM'].'</dt>';
  916. $user_personal[] = '<dd><span class="pmsnew"><a href="pmsnew.php?mdl=post&amp;uid='.$id.'">'.$lang_common['PMsend'].'</a></span></dd>';
  917. }
  918. // New PMS
  919. $user_messaging = array();
  920. if ($user['jabber'] != '')
  921. {
  922. $user_messaging[] = '<dt>'.$lang_profile['Jabber'].'</dt>';
  923. $user_messaging[] = '<dd>'.pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['jabber']) : $user['jabber']).'</dd>';
  924. }
  925. if ($user['icq'] != '')
  926. {
  927. $user_messaging[] = '<dt>'.$lang_profile['ICQ'].'</dt>';
  928. $user_messaging[] = '<dd>'.$user['icq'].'</dd>';
  929. }
  930. if ($user['msn'] != '')
  931. {
  932. $user_messaging[] = '<dt>'.$lang_profile['MSN'].'</dt>';
  933. $user_messaging[] = '<dd>'.pun_htmlspecialchars(($pun_config['o_censoring'] == '1') ? censor_words($user['msn']) : $user['msn']).'</dd>';
  934. }
  935. if ($user['aim'] != '')
  936. {
  937. $us

Large files files are truncated, but you can click here to view the full file