Profile-Actions.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. <?php
  2. /**
  3. * This file handles actions made on a user's profile.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2011 Simple Machines
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('Hacking attempt...');
  16. /**
  17. * Activate an account.
  18. *
  19. * @param int $memID the member ID
  20. */
  21. function activateAccount($memID)
  22. {
  23. global $sourcedir, $context, $user_profile, $modSettings, $user_info;
  24. isAllowedTo('moderate_forum');
  25. if (isset($_REQUEST['save']) && isset($user_profile[$memID]['is_activated']) && $user_profile[$memID]['is_activated'] != 1)
  26. {
  27. // If we are approving the deletion of an account, we do something special ;)
  28. if ($user_profile[$memID]['is_activated'] == 4)
  29. {
  30. require_once($sourcedir . '/Subs-Members.php');
  31. deleteMembers($context['id_member']);
  32. redirectexit();
  33. }
  34. // Let the integrations know of the activation.
  35. call_integration_hook('integrate_activate', array($user_profile[$memID]['member_name']));
  36. // Actually update this member now, as it guarantees the unapproved count can't get corrupted.
  37. updateMemberData($context['id_member'], array('is_activated' => $user_profile[$memID]['is_activated'] >= 10 ? 11 : 1, 'validation_code' => ''));
  38. // Log what we did?
  39. require_once($sourcedir . '/Logging.php');
  40. logAction('approve_member', array('member' => $memID), 'admin');
  41. // If we are doing approval, update the stats for the member just in case.
  42. if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 13, 14)))
  43. updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
  44. // Make sure we update the stats too.
  45. updateStats('member', false);
  46. }
  47. // Leave it be...
  48. redirectexit('action=profile;u=' . $memID . ';area=summary');
  49. }
  50. /**
  51. * Issue/manage an user's warning status.
  52. *
  53. * @param int $memID
  54. */
  55. function issueWarning($memID)
  56. {
  57. global $txt, $scripturl, $modSettings, $user_info, $mbname;
  58. global $context, $cur_profile, $memberContext, $smcFunc, $sourcedir;
  59. // Get all the actual settings.
  60. list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
  61. // This stores any legitimate errors.
  62. $issueErrors = array();
  63. // Doesn't hurt to be overly cautious.
  64. if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
  65. fatal_lang_error('no_access', false);
  66. // Make sure things which are disabled stay disabled.
  67. $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
  68. $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
  69. $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
  70. $context['warning_limit'] = allowedTo('admin_forum') ? 0 : $modSettings['user_limit'];
  71. $context['member']['warning'] = $cur_profile['warning'];
  72. $context['member']['name'] = $cur_profile['real_name'];
  73. // What are the limits we can apply?
  74. $context['min_allowed'] = 0;
  75. $context['max_allowed'] = 100;
  76. if ($context['warning_limit'] > 0)
  77. {
  78. // Make sure we cannot go outside of our limit for the day.
  79. $request = $smcFunc['db_query']('', '
  80. SELECT SUM(counter)
  81. FROM {db_prefix}log_comments
  82. WHERE id_recipient = {int:selected_member}
  83. AND id_member = {int:current_member}
  84. AND comment_type = {string:warning}
  85. AND log_time > {int:day_time_period}',
  86. array(
  87. 'current_member' => $user_info['id'],
  88. 'selected_member' => $memID,
  89. 'day_time_period' => time() - 86400,
  90. 'warning' => 'warning',
  91. )
  92. );
  93. list ($current_applied) = $smcFunc['db_fetch_row']($request);
  94. $smcFunc['db_free_result']($request);
  95. $context['min_allowed'] = max(0, $cur_profile['warning'] - $current_applied - $context['warning_limit']);
  96. $context['max_allowed'] = min(100, $cur_profile['warning'] - $current_applied + $context['warning_limit']);
  97. }
  98. // Defaults.
  99. $context['warning_data'] = array(
  100. 'reason' => '',
  101. 'notify' => '',
  102. 'notify_subject' => '',
  103. 'notify_body' => '',
  104. );
  105. // Are we saving?
  106. if (isset($_POST['save']))
  107. {
  108. // Security is good here.
  109. checkSession('post');
  110. // This cannot be empty!
  111. $_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
  112. if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
  113. $issueErrors[] = 'warning_no_reason';
  114. $_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
  115. // If the value hasn't changed it's either no JS or a real no change (Which this will pass)
  116. if ($_POST['warning_level'] == 'SAME')
  117. $_POST['warning_level'] = $_POST['warning_level_nojs'];
  118. $_POST['warning_level'] = (int) $_POST['warning_level'];
  119. $_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
  120. if ($_POST['warning_level'] < $context['min_allowed'])
  121. $_POST['warning_level'] = $context['min_allowed'];
  122. elseif ($_POST['warning_level'] > $context['max_allowed'])
  123. $_POST['warning_level'] = $context['max_allowed'];
  124. // Do we actually have to issue them with a PM?
  125. $id_notice = 0;
  126. if (!empty($_POST['warn_notify']) && empty($issueErrors))
  127. {
  128. $_POST['warn_sub'] = trim($_POST['warn_sub']);
  129. $_POST['warn_body'] = trim($_POST['warn_body']);
  130. if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
  131. $issueErrors[] = 'warning_notify_blank';
  132. // Send the PM?
  133. else
  134. {
  135. require_once($sourcedir . '/Subs-Post.php');
  136. $from = array(
  137. 'id' => 0,
  138. 'name' => $context['forum_name'],
  139. 'username' => $context['forum_name'],
  140. );
  141. sendpm(array('to' => array($memID), 'bcc' => array()), $_POST['warn_sub'], $_POST['warn_body'], false, $from);
  142. // Log the notice!
  143. $smcFunc['db_insert']('',
  144. '{db_prefix}log_member_notices',
  145. array(
  146. 'subject' => 'string-255', 'body' => 'string-65534',
  147. ),
  148. array(
  149. $smcFunc['htmlspecialchars']($_POST['warn_sub']), $smcFunc['htmlspecialchars']($_POST['warn_body']),
  150. ),
  151. array('id_notice')
  152. );
  153. $id_notice = $smcFunc['db_insert_id']('{db_prefix}log_member_notices', 'id_notice');
  154. }
  155. }
  156. // Just in case - make sure notice is valid!
  157. $id_notice = (int) $id_notice;
  158. // What have we changed?
  159. $level_change = $_POST['warning_level'] - $cur_profile['warning'];
  160. // No errors? Proceed! Only log if you're not the owner.
  161. if (empty($issueErrors))
  162. {
  163. // Log what we've done!
  164. if (!$context['user']['is_owner'])
  165. $smcFunc['db_insert']('',
  166. '{db_prefix}log_comments',
  167. array(
  168. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
  169. 'log_time' => 'int', 'id_notice' => 'int', 'counter' => 'int', 'body' => 'string-65534',
  170. ),
  171. array(
  172. $user_info['id'], $user_info['name'], 'warning', $memID, $cur_profile['real_name'],
  173. time(), $id_notice, $level_change, $_POST['warn_reason'],
  174. ),
  175. array('id_comment')
  176. );
  177. // Make the change.
  178. updateMemberData($memID, array('warning' => $_POST['warning_level']));
  179. // Leave a lovely message.
  180. $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
  181. }
  182. else
  183. {
  184. // Get the base stuff done.
  185. loadLanguage('Errors');
  186. $context['custom_error_title'] = $txt['profile_warning_errors_occured'];
  187. // Fill in the suite of errors.
  188. $context['post_errors'] = array();
  189. foreach ($issueErrors as $error)
  190. $context['post_errors'][] = $txt[$error];
  191. // Try to remember some bits.
  192. $context['warning_data'] = array(
  193. 'reason' => $_POST['warn_reason'],
  194. 'notify' => !empty($_POST['warn_notify']),
  195. 'notify_subject' => isset($_POST['warn_sub']) ? $_POST['warn_sub'] : '',
  196. 'notify_body' => isset($_POST['warn_body']) ? $_POST['warn_body'] : '',
  197. );
  198. }
  199. // Show the new improved warning level.
  200. $context['member']['warning'] = $_POST['warning_level'];
  201. }
  202. $context['page_title'] = $txt['profile_issue_warning'];
  203. // Let's use a generic list to get all the current warnings
  204. require_once($sourcedir . '/Subs-List.php');
  205. // Work our the various levels.
  206. $context['level_effects'] = array(
  207. 0 => $txt['profile_warning_effect_none'],
  208. $modSettings['warning_watch'] => $txt['profile_warning_effect_watch'],
  209. $modSettings['warning_moderate'] => $txt['profile_warning_effect_moderation'],
  210. $modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
  211. );
  212. $context['current_level'] = 0;
  213. foreach ($context['level_effects'] as $limit => $dummy)
  214. if ($context['member']['warning'] >= $limit)
  215. $context['current_level'] = $limit;
  216. $listOptions = array(
  217. 'id' => 'view_warnings',
  218. 'title' => $txt['profile_viewwarning_previous_warnings'],
  219. 'items_per_page' => $modSettings['defaultMaxMessages'],
  220. 'no_items_label' => $txt['profile_viewwarning_no_warnings'],
  221. 'base_href' => $scripturl . '?action=profile;area=issuewarning;sa=user;u=' . $memID,
  222. 'default_sort_col' => 'log_time',
  223. 'get_items' => array(
  224. 'function' => 'list_getUserWarnings',
  225. 'params' => array(
  226. $memID,
  227. ),
  228. ),
  229. 'get_count' => array(
  230. 'function' => 'list_getUserWarningCount',
  231. 'params' => array(
  232. $memID,
  233. ),
  234. ),
  235. 'columns' => array(
  236. 'issued_by' => array(
  237. 'header' => array(
  238. 'value' => $txt['profile_warning_previous_issued'],
  239. 'style' => 'width: 20%;',
  240. ),
  241. 'data' => array(
  242. 'function' => create_function('$warning', '
  243. return $warning[\'issuer\'][\'link\'];
  244. '
  245. ),
  246. ),
  247. 'sort' => array(
  248. 'default' => 'lc.member_name DESC',
  249. 'reverse' => 'lc.member_name',
  250. ),
  251. ),
  252. 'log_time' => array(
  253. 'header' => array(
  254. 'value' => $txt['profile_warning_previous_time'],
  255. 'style' => 'width: 30%;',
  256. ),
  257. 'data' => array(
  258. 'db' => 'time',
  259. ),
  260. 'sort' => array(
  261. 'default' => 'lc.log_time DESC',
  262. 'reverse' => 'lc.log_time',
  263. ),
  264. ),
  265. 'reason' => array(
  266. 'header' => array(
  267. 'value' => $txt['profile_warning_previous_reason'],
  268. ),
  269. 'data' => array(
  270. 'function' => create_function('$warning', '
  271. global $scripturl, $txt, $settings;
  272. $ret = \'
  273. <div class="floatleft">
  274. \' . $warning[\'reason\'] . \'
  275. </div>\';
  276. if (!empty($warning[\'id_notice\']))
  277. $ret .= \'
  278. <div class="floatright">
  279. <a href="\' . $scripturl . \'?action=moderate;area=notice;nid=\' . $warning[\'id_notice\'] . \'" onclick="window.open(this.href, \\\'\\\', \\\'scrollbars=yes,resizable=yes,width=400,height=250\\\');return false;" target="_blank" class="new_win" title="\' . $txt[\'profile_warning_previous_notice\'] . \'"><img src="\' . $settings[\'images_url\'] . \'/filter.png" alt="" /></a>
  280. </div>\';
  281. return $ret;'),
  282. ),
  283. ),
  284. 'level' => array(
  285. 'header' => array(
  286. 'value' => $txt['profile_warning_previous_level'],
  287. 'style' => 'width: 6%;',
  288. ),
  289. 'data' => array(
  290. 'db' => 'counter',
  291. ),
  292. 'sort' => array(
  293. 'default' => 'lc.counter DESC',
  294. 'reverse' => 'lc.counter',
  295. ),
  296. ),
  297. ),
  298. );
  299. // Create the list for viewing.
  300. require_once($sourcedir . '/Subs-List.php');
  301. createList($listOptions);
  302. // Are they warning because of a message?
  303. if (isset($_REQUEST['msg']) && 0 < (int) $_REQUEST['msg'])
  304. {
  305. $request = $smcFunc['db_query']('', '
  306. SELECT subject
  307. FROM {db_prefix}messages AS m
  308. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  309. WHERE id_msg = {int:message}
  310. AND {query_see_board}
  311. LIMIT 1',
  312. array(
  313. 'message' => (int) $_REQUEST['msg'],
  314. )
  315. );
  316. if ($smcFunc['db_num_rows']($request) != 0)
  317. {
  318. $context['warning_for_message'] = (int) $_REQUEST['msg'];
  319. list ($context['warned_message_subject']) = $smcFunc['db_fetch_row']($request);
  320. }
  321. $smcFunc['db_free_result']($request);
  322. }
  323. // Didn't find the message?
  324. if (empty($context['warning_for_message']))
  325. {
  326. $context['warning_for_message'] = 0;
  327. $context['warned_message_subject'] = '';
  328. }
  329. // Any custom templates?
  330. $context['notification_templates'] = array();
  331. $request = $smcFunc['db_query']('', '
  332. SELECT recipient_name AS template_title, body
  333. FROM {db_prefix}log_comments
  334. WHERE comment_type = {string:warntpl}
  335. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  336. array(
  337. 'warntpl' => 'warntpl',
  338. 'generic' => 0,
  339. 'current_member' => $user_info['id'],
  340. )
  341. );
  342. while ($row = $smcFunc['db_fetch_assoc']($request))
  343. {
  344. // If we're not warning for a message skip any that are.
  345. if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
  346. continue;
  347. $context['notification_templates'][] = array(
  348. 'title' => $row['template_title'],
  349. 'body' => $row['body'],
  350. );
  351. }
  352. $smcFunc['db_free_result']($request);
  353. // Setup the "default" templates.
  354. foreach (array('spamming', 'offence', 'insulting') as $type)
  355. $context['notification_templates'][] = array(
  356. 'title' => $txt['profile_warning_notify_title_' . $type],
  357. 'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
  358. );
  359. // Replace all the common variables in the templates.
  360. foreach ($context['notification_templates'] as $k => $name)
  361. $context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
  362. }
  363. /**
  364. * Get the number of warnings a user has.
  365. *
  366. * @param int $memID
  367. * @return int Total number of warnings for the user
  368. */
  369. function list_getUserWarningCount($memID)
  370. {
  371. global $smcFunc;
  372. $request = $smcFunc['db_query']('', '
  373. SELECT COUNT(*)
  374. FROM {db_prefix}log_comments
  375. WHERE id_recipient = {int:selected_member}
  376. AND comment_type = {string:warning}',
  377. array(
  378. 'selected_member' => $memID,
  379. 'warning' => 'warning',
  380. )
  381. );
  382. list ($total_warnings) = $smcFunc['db_fetch_row']($request);
  383. $smcFunc['db_free_result']($request);
  384. return $total_warnings;
  385. }
  386. /**
  387. * Get the data about a users warnings.
  388. *
  389. * @param int $start
  390. * @param int $items_per_page
  391. * @param string $sort
  392. * @param int $memID, the member ID
  393. * @return array the preview warnings
  394. */
  395. function list_getUserWarnings($start, $items_per_page, $sort, $memID)
  396. {
  397. global $smcFunc, $scripturl;
  398. $request = $smcFunc['db_query']('', '
  399. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name,
  400. lc.log_time, lc.body, lc.counter, lc.id_notice
  401. FROM {db_prefix}log_comments AS lc
  402. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  403. WHERE lc.id_recipient = {int:selected_member}
  404. AND lc.comment_type = {string:warning}
  405. ORDER BY ' . $sort . '
  406. LIMIT ' . $start . ', ' . $items_per_page,
  407. array(
  408. 'selected_member' => $memID,
  409. 'warning' => 'warning',
  410. )
  411. );
  412. $previous_warnings = array();
  413. while ($row = $smcFunc['db_fetch_assoc']($request))
  414. {
  415. $previous_warnings[] = array(
  416. 'issuer' => array(
  417. 'id' => $row['id_member'],
  418. 'link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name'] . '</a>') : $row['member_name'],
  419. ),
  420. 'time' => timeformat($row['log_time']),
  421. 'reason' => $row['body'],
  422. 'counter' => $row['counter'] > 0 ? '+' . $row['counter'] : $row['counter'],
  423. 'id_notice' => $row['id_notice'],
  424. );
  425. }
  426. $smcFunc['db_free_result']($request);
  427. return $previous_warnings;
  428. }
  429. /**
  430. * Present a screen to make sure the user wants to be deleted
  431. *
  432. * @param int $memID, the member ID
  433. */
  434. function deleteAccount($memID)
  435. {
  436. global $txt, $context, $user_info, $modSettings, $cur_profile, $smcFunc;
  437. if (!$context['user']['is_owner'])
  438. isAllowedTo('profile_remove_any');
  439. elseif (!allowedTo('profile_remove_any'))
  440. isAllowedTo('profile_remove_own');
  441. // Permissions for removing stuff...
  442. $context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
  443. // Can they do this, or will they need approval?
  444. $context['needs_approval'] = $context['user']['is_owner'] && !empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum');
  445. $context['page_title'] = $txt['deleteAccount'] . ': ' . $cur_profile['real_name'];
  446. }
  447. /**
  448. * Actually delete an account.
  449. *
  450. * @param $profile_vars
  451. * @param $post_errors
  452. * @param int $memID, the member ID
  453. */
  454. function deleteAccount2($profile_vars, $post_errors, $memID)
  455. {
  456. global $user_info, $sourcedir, $context, $cur_profile, $modSettings, $smcFunc;
  457. // Try get more time...
  458. @set_time_limit(600);
  459. // @todo Add a way to delete pms as well?
  460. if (!$context['user']['is_owner'])
  461. isAllowedTo('profile_remove_any');
  462. elseif (!allowedTo('profile_remove_any'))
  463. isAllowedTo('profile_remove_own');
  464. checkSession();
  465. $old_profile = &$cur_profile;
  466. // Too often, people remove/delete their own only account.
  467. if (in_array(1, explode(',', $old_profile['additional_groups'])) || $old_profile['id_group'] == 1)
  468. {
  469. // Are you allowed to administrate the forum, as they are?
  470. isAllowedTo('admin_forum');
  471. $request = $smcFunc['db_query']('', '
  472. SELECT id_member
  473. FROM {db_prefix}members
  474. WHERE (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0)
  475. AND id_member != {int:selected_member}
  476. LIMIT 1',
  477. array(
  478. 'admin_group' => 1,
  479. 'selected_member' => $memID,
  480. )
  481. );
  482. list ($another) = $smcFunc['db_fetch_row']($request);
  483. $smcFunc['db_free_result']($request);
  484. if (empty($another))
  485. fatal_lang_error('at_least_one_admin', 'critical');
  486. }
  487. // This file is needed for the deleteMembers function.
  488. require_once($sourcedir . '/Subs-Members.php');
  489. // Do you have permission to delete others profiles, or is that your profile you wanna delete?
  490. if ($memID != $user_info['id'])
  491. {
  492. isAllowedTo('profile_remove_any');
  493. // Now, have you been naughty and need your posts deleting?
  494. // @todo Should this check board permissions?
  495. if ($_POST['remove_type'] != 'none' && allowedTo('moderate_forum'))
  496. {
  497. // Include RemoveTopics - essential for this type of work!
  498. require_once($sourcedir . '/RemoveTopic.php');
  499. // First off we delete any topics the member has started - if they wanted topics being done.
  500. if ($_POST['remove_type'] == 'topics')
  501. {
  502. // Fetch all topics started by this user within the time period.
  503. $request = $smcFunc['db_query']('', '
  504. SELECT t.id_topic
  505. FROM {db_prefix}topics AS t
  506. WHERE t.id_member_started = {int:selected_member}',
  507. array(
  508. 'selected_member' => $memID,
  509. )
  510. );
  511. $topicIDs = array();
  512. while ($row = $smcFunc['db_fetch_assoc']($request))
  513. $topicIDs[] = $row['id_topic'];
  514. $smcFunc['db_free_result']($request);
  515. // Actually remove the topics.
  516. // @todo This needs to check permissions, but we'll let it slide for now because of moderate_forum already being had.
  517. removeTopics($topicIDs);
  518. }
  519. // Now delete the remaining messages.
  520. $request = $smcFunc['db_query']('', '
  521. SELECT m.id_msg
  522. FROM {db_prefix}messages AS m
  523. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic
  524. AND t.id_first_msg != m.id_msg)
  525. WHERE m.id_member = {int:selected_member}',
  526. array(
  527. 'selected_member' => $memID,
  528. )
  529. );
  530. // This could take a while... but ya know it's gonna be worth it in the end.
  531. while ($row = $smcFunc['db_fetch_assoc']($request))
  532. {
  533. if (function_exists('apache_reset_timeout'))
  534. @apache_reset_timeout();
  535. removeMessage($row['id_msg']);
  536. }
  537. $smcFunc['db_free_result']($request);
  538. }
  539. // Only delete this poor members account if they are actually being booted out of camp.
  540. if (isset($_POST['deleteAccount']))
  541. deleteMembers($memID);
  542. }
  543. // Do they need approval to delete?
  544. elseif (empty($post_errors) && !empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
  545. {
  546. // Setup their account for deletion ;)
  547. updateMemberData($memID, array('is_activated' => 4));
  548. // Another account needs approval...
  549. updateSettings(array('unapprovedMembers' => true), true);
  550. }
  551. // Also check if you typed your password correctly.
  552. elseif (empty($post_errors))
  553. {
  554. deleteMembers($memID);
  555. require_once($sourcedir . '/LogInOut.php');
  556. LogOut(true);
  557. redirectexit();
  558. }
  559. }
  560. /**
  561. * Function for doing all the paid subscription stuff - kinda.
  562. *
  563. * @param int $memID
  564. */
  565. function subscriptions($memID)
  566. {
  567. global $context, $txt, $sourcedir, $modSettings, $smcFunc, $scripturl;
  568. // Load the paid template anyway.
  569. loadTemplate('ManagePaid');
  570. loadLanguage('ManagePaid');
  571. // Load all of the subscriptions.
  572. require_once($sourcedir . '/ManagePaid.php');
  573. loadSubscriptions();
  574. $context['member']['id'] = $memID;
  575. // Remove any invalid ones.
  576. foreach ($context['subscriptions'] as $id => $sub)
  577. {
  578. // Work out the costs.
  579. $costs = @unserialize($sub['real_cost']);
  580. $cost_array = array();
  581. if ($sub['real_length'] == 'F')
  582. {
  583. foreach ($costs as $duration => $cost)
  584. {
  585. if ($cost != 0)
  586. $cost_array[$duration] = $cost;
  587. }
  588. }
  589. else
  590. {
  591. $cost_array['fixed'] = $costs['fixed'];
  592. }
  593. if (empty($cost_array))
  594. unset($context['subscriptions'][$id]);
  595. else
  596. {
  597. $context['subscriptions'][$id]['member'] = 0;
  598. $context['subscriptions'][$id]['subscribed'] = false;
  599. $context['subscriptions'][$id]['costs'] = $cost_array;
  600. }
  601. }
  602. // Work out what gateways are enabled.
  603. $gateways = loadPaymentGateways();
  604. foreach ($gateways as $id => $gateway)
  605. {
  606. $gateways[$id] = new $gateway['display_class']();
  607. if (!$gateways[$id]->gatewayEnabled())
  608. unset($gateways[$id]);
  609. }
  610. // No gateways yet?
  611. if (empty($gateways))
  612. fatal_error($txt['paid_admin_not_setup_gateway']);
  613. // Get the current subscriptions.
  614. $request = $smcFunc['db_query']('', '
  615. SELECT id_sublog, id_subscribe, start_time, end_time, status, payments_pending, pending_details
  616. FROM {db_prefix}log_subscribed
  617. WHERE id_member = {int:selected_member}',
  618. array(
  619. 'selected_member' => $memID,
  620. )
  621. );
  622. $context['current'] = array();
  623. while ($row = $smcFunc['db_fetch_assoc']($request))
  624. {
  625. // The subscription must exist!
  626. if (!isset($context['subscriptions'][$row['id_subscribe']]))
  627. continue;
  628. $context['current'][$row['id_subscribe']] = array(
  629. 'id' => $row['id_sublog'],
  630. 'sub_id' => $row['id_subscribe'],
  631. 'hide' => $row['status'] == 0 && $row['end_time'] == 0 && $row['payments_pending'] == 0,
  632. 'name' => $context['subscriptions'][$row['id_subscribe']]['name'],
  633. 'start' => timeformat($row['start_time'], false),
  634. 'end' => $row['end_time'] == 0 ? $txt['not_applicable'] : timeformat($row['end_time'], false),
  635. 'pending_details' => $row['pending_details'],
  636. 'status' => $row['status'],
  637. 'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
  638. );
  639. if ($row['status'] == 1)
  640. $context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
  641. }
  642. $smcFunc['db_free_result']($request);
  643. // Simple "done"?
  644. if (isset($_GET['done']))
  645. {
  646. $_GET['sub_id'] = (int) $_GET['sub_id'];
  647. // Must exist but let's be sure...
  648. if (isset($context['current'][$_GET['sub_id']]))
  649. {
  650. // What are the details like?
  651. $current_pending = @unserialize($context['current'][$_GET['sub_id']]['pending_details']);
  652. if (!empty($current_pending))
  653. {
  654. $current_pending = array_reverse($current_pending);
  655. foreach ($current_pending as $id => $sub)
  656. {
  657. // Just find one and change it.
  658. if ($sub[0] == $_GET['sub_id'] && $sub[3] == 'prepay')
  659. {
  660. $current_pending[$id][3] = 'payback';
  661. break;
  662. }
  663. }
  664. // Save the details back.
  665. $pending_details = serialize($current_pending);
  666. $smcFunc['db_query']('', '
  667. UPDATE {db_prefix}log_subscribed
  668. SET payments_pending = payments_pending + 1, pending_details = {string:pending_details}
  669. WHERE id_sublog = {int:current_subscription_id}
  670. AND id_member = {int:selected_member}',
  671. array(
  672. 'current_subscription_id' => $context['current'][$_GET['sub_id']]['id'],
  673. 'selected_member' => $memID,
  674. 'pending_details' => $pending_details,
  675. )
  676. );
  677. }
  678. }
  679. $context['sub_template'] = 'paid_done';
  680. return;
  681. }
  682. // If this is confirmation then it's simpler...
  683. if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
  684. {
  685. // Hopefully just one.
  686. foreach ($_POST['sub_id'] as $k => $v)
  687. $ID_SUB = (int) $k;
  688. if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
  689. fatal_lang_error('paid_sub_not_active');
  690. // Simplify...
  691. $context['sub'] = $context['subscriptions'][$ID_SUB];
  692. $period = 'xx';
  693. if ($context['sub']['flexible'])
  694. $period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
  695. // Check we have a valid cost.
  696. if ($context['sub']['flexible'] && $period == 'xx')
  697. fatal_lang_error('paid_sub_not_active');
  698. // Sort out the cost/currency.
  699. $context['currency'] = $modSettings['paid_currency_code'];
  700. $context['recur'] = $context['sub']['repeatable'];
  701. if ($context['sub']['flexible'])
  702. {
  703. // Real cost...
  704. $context['value'] = $context['sub']['costs'][$_POST['cur'][$ID_SUB]];
  705. $context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
  706. // The period value for paypal.
  707. $context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
  708. }
  709. else
  710. {
  711. // Real cost...
  712. $context['value'] = $context['sub']['costs']['fixed'];
  713. $context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']);
  714. // Recur?
  715. preg_match('~(\d*)(\w)~', $context['sub']['real_length'], $match);
  716. $context['paypal_unit'] = $match[1];
  717. $context['paypal_period'] = $match[2];
  718. }
  719. // Setup the gateway context.
  720. $context['gateways'] = array();
  721. foreach ($gateways as $id => $gateway)
  722. {
  723. $fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
  724. if (!empty($fields['form']))
  725. $context['gateways'][] = $fields;
  726. }
  727. // Bugger?!
  728. if (empty($context['gateways']))
  729. fatal_error($txt['paid_admin_not_setup_gateway']);
  730. // Now we are going to assume they want to take this out ;)
  731. $new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
  732. if (isset($context['current'][$context['sub']['id']]))
  733. {
  734. // What are the details like?
  735. $current_pending = array();
  736. if ($context['current'][$context['sub']['id']]['pending_details'] != '')
  737. $current_pending = @unserialize($context['current'][$context['sub']['id']]['pending_details']);
  738. // Don't get silly.
  739. if (count($current_pending) > 9)
  740. $current_pending = array();
  741. $pending_count = 0;
  742. // Only record real pending payments as will otherwise confuse the admin!
  743. foreach ($current_pending as $pending)
  744. if ($pending[3] == 'payback')
  745. $pending_count++;
  746. if (!in_array($new_data, $current_pending))
  747. {
  748. $current_pending[] = $new_data;
  749. $pending_details = serialize($current_pending);
  750. $smcFunc['db_query']('', '
  751. UPDATE {db_prefix}log_subscribed
  752. SET payments_pending = {int:pending_count}, pending_details = {string:pending_details}
  753. WHERE id_sublog = {int:current_subscription_item}
  754. AND id_member = {int:selected_member}',
  755. array(
  756. 'pending_count' => $pending_count,
  757. 'current_subscription_item' => $context['current'][$context['sub']['id']]['id'],
  758. 'selected_member' => $memID,
  759. 'pending_details' => $pending_details,
  760. )
  761. );
  762. }
  763. }
  764. // Never had this before, lovely.
  765. else
  766. {
  767. $pending_details = serialize(array($new_data));
  768. $smcFunc['db_insert']('',
  769. '{db_prefix}log_subscribed',
  770. array(
  771. 'id_subscribe' => 'int', 'id_member' => 'int', 'status' => 'int', 'payments_pending' => 'int', 'pending_details' => 'string-65534',
  772. 'start_time' => 'int', 'vendor_ref' => 'string-255',
  773. ),
  774. array(
  775. $context['sub']['id'], $memID, 0, 0, $pending_details,
  776. time(), '',
  777. ),
  778. array('id_sublog')
  779. );
  780. }
  781. // Change the template.
  782. $context['sub_template'] = 'choose_payment';
  783. // Quit.
  784. return;
  785. }
  786. else
  787. $context['sub_template'] = 'user_subscription';
  788. }
  789. ?>