annotate forum/Sources/Profile-Actions.php @ 87:df86d318892b website

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