Profile-View.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /**
  15. * View a summary.
  16. * @param int $memID id_member
  17. */
  18. function summary($memID)
  19. {
  20. global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $scripturl, $smcFunc;
  21. // Attempt to load the member's profile data.
  22. if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
  23. fatal_lang_error('not_a_user', false);
  24. // Set up the stuff and load the user.
  25. $context += array(
  26. 'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']),
  27. 'can_send_pm' => allowedTo('pm_send'),
  28. 'can_send_email' => allowedTo('send_email_to_members'),
  29. 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']),
  30. 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1,
  31. );
  32. $context['member'] = &$memberContext[$memID];
  33. $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner']));
  34. // Set a canonical URL for this page.
  35. $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;
  36. // Are there things we don't show?
  37. $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
  38. // See if they have broken any warning levels...
  39. list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
  40. if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
  41. $context['warning_status'] = $txt['profile_warning_is_muted'];
  42. elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
  43. $context['warning_status'] = $txt['profile_warning_is_moderation'];
  44. elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
  45. $context['warning_status'] = $txt['profile_warning_is_watch'];
  46. // They haven't even been registered for a full day!?
  47. $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
  48. if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
  49. $context['member']['posts_per_day'] = $txt['not_applicable'];
  50. else
  51. $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
  52. // Set the age...
  53. if (empty($context['member']['birth_date']))
  54. {
  55. $context['member'] += array(
  56. 'age' => $txt['not_applicable'],
  57. 'today_is_birthday' => false
  58. );
  59. }
  60. else
  61. {
  62. list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
  63. $datearray = getdate(forum_time());
  64. $context['member'] += array(
  65. 'age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
  66. 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day
  67. );
  68. }
  69. if (allowedTo('moderate_forum'))
  70. {
  71. // Make sure it's a valid ip address; otherwise, don't bother...
  72. if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
  73. $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
  74. else
  75. $context['member']['hostname'] = '';
  76. $context['can_see_ip'] = true;
  77. }
  78. else
  79. $context['can_see_ip'] = false;
  80. if (!empty($modSettings['who_enabled']))
  81. {
  82. include_once($sourcedir . '/Who.php');
  83. $action = determineActions($user_profile[$memID]['url']);
  84. if ($action !== false)
  85. $context['member']['action'] = $action;
  86. }
  87. // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
  88. if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum'))
  89. {
  90. $context['activate_type'] = $context['member']['is_activated'];
  91. // What should the link text be?
  92. $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
  93. // Should we show a custom message?
  94. $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
  95. }
  96. // Is the signature even enabled on this forum?
  97. $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
  98. // How about, are they banned?
  99. $context['member']['bans'] = array();
  100. if (allowedTo('moderate_forum'))
  101. {
  102. // Can they edit the ban?
  103. $context['can_edit_ban'] = allowedTo('manage_bans');
  104. $ban_query = array();
  105. $ban_query_vars = array(
  106. 'time' => time(),
  107. );
  108. $ban_query[] = 'id_member = ' . $context['member']['id'];
  109. $ban_query[] = constructBanQueryIP($memberContext[$memID]['ip']);
  110. // Do we have a hostname already?
  111. if (!empty($context['member']['hostname']))
  112. {
  113. $ban_query[] = '({string:hostname} LIKE hostname)';
  114. $ban_query_vars['hostname'] = $context['member']['hostname'];
  115. }
  116. // Check their email as well...
  117. if (strlen($context['member']['email']) != 0)
  118. {
  119. $ban_query[] = '({string:email} LIKE bi.email_address)';
  120. $ban_query_vars['email'] = $context['member']['email'];
  121. }
  122. // So... are they banned? Dying to know!
  123. $request = $smcFunc['db_query']('', '
  124. SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register,
  125. bg.cannot_login, bg.reason
  126. FROM {db_prefix}ban_items AS bi
  127. INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time}))
  128. WHERE (' . implode(' OR ', $ban_query) . ')',
  129. $ban_query_vars
  130. );
  131. while ($row = $smcFunc['db_fetch_assoc']($request))
  132. {
  133. // Work out what restrictions we actually have.
  134. $ban_restrictions = array();
  135. foreach (array('access', 'register', 'login', 'post') as $type)
  136. if ($row['cannot_' . $type])
  137. $ban_restrictions[] = $txt['ban_type_' . $type];
  138. // No actual ban in place?
  139. if (empty($ban_restrictions))
  140. continue;
  141. // Prepare the link for context.
  142. $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
  143. $context['member']['bans'][$row['id_ban_group']] = array(
  144. 'reason' => empty($row['reason']) ? '' : '<br /><br /><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'],
  145. 'cannot' => array(
  146. 'access' => !empty($row['cannot_access']),
  147. 'register' => !empty($row['cannot_register']),
  148. 'post' => !empty($row['cannot_post']),
  149. 'login' => !empty($row['cannot_login']),
  150. ),
  151. 'explanation' => $ban_explanation,
  152. );
  153. }
  154. $smcFunc['db_free_result']($request);
  155. }
  156. loadCustomFields($memID);
  157. }
  158. /**
  159. * Show all posts by the current user
  160. * @todo This function needs to be split up properly.
  161. *
  162. * @param int $memID id_member
  163. */
  164. function showPosts($memID)
  165. {
  166. global $txt, $user_info, $scripturl, $modSettings;
  167. global $context, $user_profile, $sourcedir, $smcFunc, $board;
  168. // Some initial context.
  169. $context['start'] = (int) $_REQUEST['start'];
  170. $context['current_member'] = $memID;
  171. // Create the tabs for the template.
  172. $context[$context['profile_menu_name']]['tab_data'] = array(
  173. 'title' => $txt['showPosts'],
  174. 'description' => $txt['showPosts_help'],
  175. 'icon' => 'profile_sm.png',
  176. 'tabs' => array(
  177. 'messages' => array(
  178. ),
  179. 'topics' => array(
  180. ),
  181. 'attach' => array(
  182. ),
  183. ),
  184. );
  185. // Set the page title
  186. $context['page_title'] = $txt['showPosts'] . ' - ' . $user_profile[$memID]['real_name'];
  187. // Is the load average too high to allow searching just now?
  188. if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
  189. fatal_lang_error('loadavg_show_posts_disabled', false);
  190. // If we're specifically dealing with attachments use that function!
  191. if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
  192. return showAttachments($memID);
  193. // Are we just viewing topics?
  194. $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
  195. // If just deleting a message, do it and then redirect back.
  196. if (isset($_GET['delete']) && !$context['is_topics'])
  197. {
  198. checkSession('get');
  199. // We need msg info for logging.
  200. $request = $smcFunc['db_query']('', '
  201. SELECT subject, id_member, id_topic, id_board
  202. FROM {db_prefix}messages
  203. WHERE id_msg = {int:id_msg}',
  204. array(
  205. 'id_msg' => (int) $_GET['delete'],
  206. )
  207. );
  208. $info = $smcFunc['db_fetch_row']($request);
  209. $smcFunc['db_free_result']($request);
  210. // Trying to remove a message that doesn't exist.
  211. if (empty($info))
  212. redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
  213. // We can be lazy, since removeMessage() will check the permissions for us.
  214. require_once($sourcedir . '/RemoveTopic.php');
  215. removeMessage((int) $_GET['delete']);
  216. // Add it to the mod log.
  217. if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
  218. logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
  219. // Back to... where we are now ;).
  220. redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
  221. }
  222. // Default to 10.
  223. if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
  224. $_REQUEST['viewscount'] = '10';
  225. if ($context['is_topics'])
  226. $request = $smcFunc['db_query']('', '
  227. SELECT COUNT(*)
  228. FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
  229. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
  230. WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
  231. AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  232. AND t.approved = {int:is_approved}'),
  233. array(
  234. 'current_member' => $memID,
  235. 'is_approved' => 1,
  236. 'board' => $board,
  237. )
  238. );
  239. else
  240. $request = $smcFunc['db_query']('', '
  241. SELECT COUNT(*)
  242. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  243. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  244. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  245. AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  246. AND m.approved = {int:is_approved}'),
  247. array(
  248. 'current_member' => $memID,
  249. 'is_approved' => 1,
  250. 'board' => $board,
  251. )
  252. );
  253. list ($msgCount) = $smcFunc['db_fetch_row']($request);
  254. $smcFunc['db_free_result']($request);
  255. $request = $smcFunc['db_query']('', '
  256. SELECT MIN(id_msg), MAX(id_msg)
  257. FROM {db_prefix}messages AS m
  258. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  259. AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  260. AND m.approved = {int:is_approved}'),
  261. array(
  262. 'current_member' => $memID,
  263. 'is_approved' => 1,
  264. 'board' => $board,
  265. )
  266. );
  267. list ($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request);
  268. $smcFunc['db_free_result']($request);
  269. $reverse = false;
  270. $range_limit = '';
  271. $maxIndex = (int) $modSettings['defaultMaxMessages'];
  272. // Make sure the starting place makes sense and construct our friend the page index.
  273. $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex);
  274. $context['current_page'] = $context['start'] / $maxIndex;
  275. // Reverse the query if we're past 50% of the pages for better performance.
  276. $start = $context['start'];
  277. $reverse = $_REQUEST['start'] > $msgCount / 2;
  278. if ($reverse)
  279. {
  280. $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages'];
  281. $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages'];
  282. }
  283. // Guess the range of messages to be shown.
  284. if ($msgCount > 1000)
  285. {
  286. $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + .1 * ($max_msg_member - $min_msg_member));
  287. // Make a bigger margin for topics only.
  288. if ($context['is_topics'])
  289. {
  290. $margin *= 5;
  291. $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
  292. }
  293. else
  294. $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
  295. }
  296. // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks.
  297. $looped = false;
  298. while (true)
  299. {
  300. if ($context['is_topics'])
  301. {
  302. $request = $smcFunc['db_query']('', '
  303. SELECT
  304. b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg,
  305. t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg
  306. FROM {db_prefix}topics AS t
  307. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  308. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  309. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  310. WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
  311. AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
  312. AND ' . $range_limit) . '
  313. AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  314. AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
  315. ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . '
  316. LIMIT ' . $start . ', ' . $maxIndex,
  317. array(
  318. 'current_member' => $memID,
  319. 'is_approved' => 1,
  320. 'board' => $board,
  321. )
  322. );
  323. }
  324. else
  325. {
  326. $request = $smcFunc['db_query']('', '
  327. SELECT
  328. b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg,
  329. t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled,
  330. m.subject, m.poster_time, m.approved
  331. FROM {db_prefix}messages AS m
  332. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  333. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  334. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  335. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  336. AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
  337. AND ' . $range_limit) . '
  338. AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  339. AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
  340. ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . '
  341. LIMIT ' . $start . ', ' . $maxIndex,
  342. array(
  343. 'current_member' => $memID,
  344. 'is_approved' => 1,
  345. 'board' => $board,
  346. )
  347. );
  348. }
  349. // Make sure we quit this loop.
  350. if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
  351. break;
  352. $looped = true;
  353. $range_limit = '';
  354. }
  355. // Start counting at the number of the first message displayed.
  356. $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
  357. $context['posts'] = array();
  358. $board_ids = array('own' => array(), 'any' => array());
  359. while ($row = $smcFunc['db_fetch_assoc']($request))
  360. {
  361. // Censor....
  362. censorText($row['body']);
  363. censorText($row['subject']);
  364. // Do the code.
  365. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
  366. // And the array...
  367. $context['posts'][$counter += $reverse ? -1 : 1] = array(
  368. 'body' => $row['body'],
  369. 'counter' => $counter,
  370. 'alternate' => $counter % 2,
  371. 'category' => array(
  372. 'name' => $row['cname'],
  373. 'id' => $row['id_cat']
  374. ),
  375. 'board' => array(
  376. 'name' => $row['bname'],
  377. 'id' => $row['id_board']
  378. ),
  379. 'topic' => $row['id_topic'],
  380. 'subject' => $row['subject'],
  381. 'start' => 'msg' . $row['id_msg'],
  382. 'time' => timeformat($row['poster_time']),
  383. 'timestamp' => forum_time(true, $row['poster_time']),
  384. 'id' => $row['id_msg'],
  385. 'can_reply' => false,
  386. 'can_mark_notify' => false,
  387. 'can_delete' => false,
  388. 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()),
  389. 'approved' => $row['approved'],
  390. );
  391. if ($user_info['id'] == $row['id_member_started'])
  392. $board_ids['own'][$row['id_board']][] = $counter;
  393. $board_ids['any'][$row['id_board']][] = $counter;
  394. }
  395. $smcFunc['db_free_result']($request);
  396. // All posts were retrieved in reverse order, get them right again.
  397. if ($reverse)
  398. $context['posts'] = array_reverse($context['posts'], true);
  399. // These are all the permissions that are different from board to board..
  400. if ($context['is_topics'])
  401. $permissions = array(
  402. 'own' => array(
  403. 'post_reply_own' => 'can_reply',
  404. ),
  405. 'any' => array(
  406. 'post_reply_any' => 'can_reply',
  407. 'mark_any_notify' => 'can_mark_notify',
  408. )
  409. );
  410. else
  411. $permissions = array(
  412. 'own' => array(
  413. 'post_reply_own' => 'can_reply',
  414. 'delete_own' => 'can_delete',
  415. ),
  416. 'any' => array(
  417. 'post_reply_any' => 'can_reply',
  418. 'mark_any_notify' => 'can_mark_notify',
  419. 'delete_any' => 'can_delete',
  420. )
  421. );
  422. // For every permission in the own/any lists...
  423. foreach ($permissions as $type => $list)
  424. {
  425. foreach ($list as $permission => $allowed)
  426. {
  427. // Get the boards they can do this on...
  428. $boards = boardsAllowedTo($permission);
  429. // Hmm, they can do it on all boards, can they?
  430. if (!empty($boards) && $boards[0] == 0)
  431. $boards = array_keys($board_ids[$type]);
  432. // Now go through each board they can do the permission on.
  433. foreach ($boards as $board_id)
  434. {
  435. // There aren't any posts displayed from this board.
  436. if (!isset($board_ids[$type][$board_id]))
  437. continue;
  438. // Set the permission to true ;).
  439. foreach ($board_ids[$type][$board_id] as $counter)
  440. $context['posts'][$counter][$allowed] = true;
  441. }
  442. }
  443. }
  444. // Clean up after posts that cannot be deleted and quoted.
  445. $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
  446. foreach ($context['posts'] as $counter => $dummy)
  447. {
  448. $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
  449. $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
  450. }
  451. }
  452. /**
  453. * Show all the attachments of a user.
  454. *
  455. * @param int $memID id_member
  456. */
  457. function showAttachments($memID)
  458. {
  459. global $txt, $user_info, $scripturl, $modSettings, $board;
  460. global $context, $user_profile, $sourcedir, $smcFunc;
  461. // OBEY permissions!
  462. $boardsAllowed = boardsAllowedTo('view_attachments');
  463. // Make sure we can't actually see anything...
  464. if (empty($boardsAllowed))
  465. $boardsAllowed = array(-1);
  466. require_once($sourcedir . '/Subs-List.php');
  467. // This is all the information required for a group listing.
  468. $listOptions = array(
  469. 'id' => 'attachments',
  470. 'width' => '100%',
  471. 'items_per_page' => $modSettings['defaultMaxMessages'],
  472. 'no_items_label' => $txt['show_attachments_none'],
  473. 'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;sort=filename;u=' . $memID,
  474. 'default_sort_col' => 'filename',
  475. 'get_items' => array(
  476. 'function' => 'list_getAttachments',
  477. 'params' => array(
  478. $boardsAllowed,
  479. $memID,
  480. ),
  481. ),
  482. 'get_count' => array(
  483. 'function' => 'list_getNumAttachments',
  484. 'params' => array(
  485. $boardsAllowed,
  486. $memID,
  487. ),
  488. ),
  489. 'data_check' => array(
  490. 'class' => create_function('$data', '
  491. return $data[\'approved\'] ? \'\' : \'approvebg\';
  492. ')
  493. ),
  494. 'columns' => array(
  495. 'filename' => array(
  496. 'header' => array(
  497. 'value' => $txt['show_attach_downloads'],
  498. 'class' => 'lefttext',
  499. 'style' => 'width: 25%',
  500. ),
  501. 'data' => array(
  502. 'db' => 'filename',
  503. ),
  504. 'sort' => array(
  505. 'default' => 'a.filename',
  506. 'reverse' => 'a.filename DESC',
  507. ),
  508. ),
  509. 'downloads' => array(
  510. 'header' => array(
  511. 'value' => $txt['show_attach_downloads'],
  512. 'style' => 'width: 12%',
  513. ),
  514. 'data' => array(
  515. 'db' => 'downloads',
  516. ),
  517. 'sort' => array(
  518. 'default' => 'a.downloads',
  519. 'reverse' => 'a.downloads DESC',
  520. ),
  521. ),
  522. 'subject' => array(
  523. 'header' => array(
  524. 'value' => $txt['message'],
  525. 'class' => 'lefttext',
  526. 'style' => 'width: 30%',
  527. ),
  528. 'data' => array(
  529. 'db' => 'subject',
  530. ),
  531. 'sort' => array(
  532. 'default' => 'm.subject',
  533. 'reverse' => 'm.subject DESC',
  534. ),
  535. ),
  536. 'posted' => array(
  537. 'header' => array(
  538. 'value' => $txt['show_attach_posted'],
  539. 'class' => 'lefttext',
  540. ),
  541. 'data' => array(
  542. 'db' => 'posted',
  543. ),
  544. ),
  545. ),
  546. );
  547. // Create the request list.
  548. createList($listOptions);
  549. }
  550. function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID)
  551. {
  552. global $smcFunc, $board, $modSettings, $context;
  553. // Retrieve some attachments.
  554. $request = $smcFunc['db_query']('', '
  555. SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic,
  556. m.id_board, m.poster_time, m.subject, b.name
  557. FROM {db_prefix}attachments AS a
  558. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
  559. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  560. WHERE a.attachment_type = {int:attachment_type}
  561. AND a.id_msg != {int:no_message}
  562. AND m.id_member = {int:current_member}' . (!empty($board) ? '
  563. AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
  564. AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  565. AND m.approved = {int:is_approved}') . '
  566. ORDER BY {raw:sort}
  567. LIMIT {int:offset}, {int:limit}',
  568. array(
  569. 'boards_list' => $boardsAllowed,
  570. 'attachment_type' => 0,
  571. 'no_message' => 0,
  572. 'current_member' => $memID,
  573. 'is_approved' => 1,
  574. 'board' => $board,
  575. 'sort' => $sort,
  576. 'offset' => $start,
  577. 'limit' => $items_per_page,
  578. )
  579. );
  580. $attachments = array();
  581. while ($row = $smcFunc['db_fetch_assoc']($request))
  582. $attachments[] = array(
  583. 'id' => $row['id_attach'],
  584. 'filename' => $row['filename'],
  585. 'downloads' => $row['downloads'],
  586. 'subject' => censorText($row['subject']),
  587. 'posted' => timeformat($row['poster_time']),
  588. 'msg' => $row['id_msg'],
  589. 'topic' => $row['id_topic'],
  590. 'board' => $row['id_board'],
  591. 'board_name' => $row['name'],
  592. 'approved' => $row['approved'],
  593. );
  594. $smcFunc['db_free_result']($request);
  595. return $attachments;
  596. }
  597. function list_getNumAttachments($boardsAllowed, $memID)
  598. {
  599. global $board, $smcFunc, $modSettings, $context;
  600. // Get the total number of attachments they have posted.
  601. $request = $smcFunc['db_query']('', '
  602. SELECT COUNT(*)
  603. FROM {db_prefix}attachments AS a
  604. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
  605. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
  606. WHERE a.attachment_type = {int:attachment_type}
  607. AND a.id_msg != {int:no_message}
  608. AND m.id_member = {int:current_member}' . (!empty($board) ? '
  609. AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
  610. AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
  611. AND m.approved = {int:is_approved}'),
  612. array(
  613. 'boards_list' => $boardsAllowed,
  614. 'attachment_type' => 0,
  615. 'no_message' => 0,
  616. 'current_member' => $memID,
  617. 'is_approved' => 1,
  618. 'board' => $board,
  619. )
  620. );
  621. list ($attachCount) = $smcFunc['db_fetch_row']($request);
  622. $smcFunc['db_free_result']($request);
  623. return $attachCount;
  624. }
  625. /**
  626. * Gets the user stats for display
  627. *
  628. * @param int $memID id_member
  629. */
  630. function statPanel($memID)
  631. {
  632. global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;
  633. $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
  634. // Is the load average too high to allow searching just now?
  635. if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
  636. fatal_lang_error('loadavg_userstats_disabled', false);
  637. // General user statistics.
  638. $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
  639. $timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
  640. $context['time_logged_in'] = ($timeDays > 0 ? $timeDays . $txt['totalTimeLogged2'] : '') . ($timeHours > 0 ? $timeHours . $txt['totalTimeLogged3'] : '') . floor(($user_profile[$memID]['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged4'];
  641. $context['num_posts'] = comma_format($user_profile[$memID]['posts']);
  642. // Number of topics started.
  643. $result = $smcFunc['db_query']('', '
  644. SELECT COUNT(*)
  645. FROM {db_prefix}topics
  646. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  647. AND id_board != {int:recycle_board}' : ''),
  648. array(
  649. 'current_member' => $memID,
  650. 'recycle_board' => $modSettings['recycle_board'],
  651. )
  652. );
  653. list ($context['num_topics']) = $smcFunc['db_fetch_row']($result);
  654. $smcFunc['db_free_result']($result);
  655. // Number polls started.
  656. $result = $smcFunc['db_query']('', '
  657. SELECT COUNT(*)
  658. FROM {db_prefix}topics
  659. WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  660. AND id_board != {int:recycle_board}' : '') . '
  661. AND id_poll != {int:no_poll}',
  662. array(
  663. 'current_member' => $memID,
  664. 'recycle_board' => $modSettings['recycle_board'],
  665. 'no_poll' => 0,
  666. )
  667. );
  668. list ($context['num_polls']) = $smcFunc['db_fetch_row']($result);
  669. $smcFunc['db_free_result']($result);
  670. // Number polls voted in.
  671. $result = $smcFunc['db_query']('distinct_poll_votes', '
  672. SELECT COUNT(DISTINCT id_poll)
  673. FROM {db_prefix}log_polls
  674. WHERE id_member = {int:current_member}',
  675. array(
  676. 'current_member' => $memID,
  677. )
  678. );
  679. list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
  680. $smcFunc['db_free_result']($result);
  681. // Format the numbers...
  682. $context['num_topics'] = comma_format($context['num_topics']);
  683. $context['num_polls'] = comma_format($context['num_polls']);
  684. $context['num_votes'] = comma_format($context['num_votes']);
  685. // Grab the board this member posted in most often.
  686. $result = $smcFunc['db_query']('', '
  687. SELECT
  688. b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
  689. FROM {db_prefix}messages AS m
  690. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  691. WHERE m.id_member = {int:current_member}
  692. AND b.count_posts = {int:count_enabled}
  693. AND {query_see_board}
  694. GROUP BY b.id_board
  695. ORDER BY message_count DESC
  696. LIMIT 10',
  697. array(
  698. 'current_member' => $memID,
  699. 'count_enabled' => 0,
  700. )
  701. );
  702. $context['popular_boards'] = array();
  703. while ($row = $smcFunc['db_fetch_assoc']($result))
  704. {
  705. $context['popular_boards'][$row['id_board']] = array(
  706. 'id' => $row['id_board'],
  707. 'posts' => $row['message_count'],
  708. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  709. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  710. 'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
  711. 'total_posts' => $row['num_posts'],
  712. 'total_posts_member' => $user_profile[$memID]['posts'],
  713. );
  714. }
  715. $smcFunc['db_free_result']($result);
  716. // Now get the 10 boards this user has most often participated in.
  717. $result = $smcFunc['db_query']('profile_board_stats', '
  718. SELECT
  719. b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
  720. CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
  721. FROM {db_prefix}messages AS m
  722. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  723. WHERE m.id_member = {int:current_member}
  724. AND {query_see_board}
  725. GROUP BY b.id_board, b.num_posts
  726. ORDER BY percentage DESC
  727. LIMIT 10',
  728. array(
  729. 'current_member' => $memID,
  730. )
  731. );
  732. $context['board_activity'] = array();
  733. while ($row = $smcFunc['db_fetch_assoc']($result))
  734. {
  735. $context['board_activity'][$row['id_board']] = array(
  736. 'id' => $row['id_board'],
  737. 'posts' => $row['message_count'],
  738. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  739. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  740. 'percent' => comma_format((float) $row['percentage'], 2),
  741. 'posts_percent' => (float) $row['percentage'],
  742. 'total_posts' => $row['num_posts'],
  743. );
  744. }
  745. $smcFunc['db_free_result']($result);
  746. // Posting activity by time.
  747. $result = $smcFunc['db_query']('user_activity_by_time', '
  748. SELECT
  749. HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
  750. COUNT(*) AS post_count
  751. FROM {db_prefix}messages
  752. WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
  753. AND id_topic > {int:top_ten_thousand_topics}' : '') . '
  754. GROUP BY hour',
  755. array(
  756. 'current_member' => $memID,
  757. 'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
  758. 'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
  759. )
  760. );
  761. $maxPosts = $realPosts = 0;
  762. $context['posts_by_time'] = array();
  763. while ($row = $smcFunc['db_fetch_assoc']($result))
  764. {
  765. // Cast as an integer to remove the leading 0.
  766. $row['hour'] = (int) $row['hour'];
  767. $maxPosts = max($row['post_count'], $maxPosts);
  768. $realPosts += $row['post_count'];
  769. $context['posts_by_time'][$row['hour']] = array(
  770. 'hour' => $row['hour'],
  771. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
  772. 'posts' => $row['post_count'],
  773. 'posts_percent' => 0,
  774. 'is_last' => $row['hour'] == 23,
  775. );
  776. }
  777. $smcFunc['db_free_result']($result);
  778. if ($maxPosts > 0)
  779. for ($hour = 0; $hour < 24; $hour++)
  780. {
  781. if (!isset($context['posts_by_time'][$hour]))
  782. $context['posts_by_time'][$hour] = array(
  783. 'hour' => $hour,
  784. 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
  785. 'posts' => 0,
  786. 'posts_percent' => 0,
  787. 'relative_percent' => 0,
  788. 'is_last' => $hour == 23,
  789. );
  790. else
  791. {
  792. $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
  793. $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
  794. }
  795. }
  796. // Put it in the right order.
  797. ksort($context['posts_by_time']);
  798. // Custom stats (just add a template_layer to add it to the template!)
  799. call_integration_hook('integrate_profile_stats', array($memID));
  800. }
  801. /**
  802. * @todo needs a description
  803. *
  804. * @param int $memID id_member
  805. */
  806. function tracking($memID)
  807. {
  808. global $sourcedir, $context, $txt, $scripturl, $modSettings, $user_profile;
  809. $subActions = array(
  810. 'activity' => array('trackActivity', $txt['trackActivity']),
  811. 'ip' => array('TrackIP', $txt['trackIP']),
  812. 'edits' => array('trackEdits', $txt['trackEdits']),
  813. 'logins' => array('TrackLogins', $txt['trackLogins']),
  814. );
  815. $context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'activity';
  816. // @todo what is $types? it is never set so this will never be true
  817. if (isset($types[$context['tracking_area']][1]))
  818. require_once($sourcedir . '/' . $types[$context['tracking_area']][1]);
  819. // Create the tabs for the template.
  820. $context[$context['profile_menu_name']]['tab_data'] = array(
  821. 'title' => $txt['tracking'],
  822. 'description' => $txt['tracking_description'],
  823. 'icon' => 'profile_sm.png',
  824. 'tabs' => array(
  825. 'activity' => array(),
  826. 'ip' => array(),
  827. 'edits' => array(),
  828. ),
  829. );
  830. // Moderation must be on to track edits.
  831. if (empty($modSettings['modlog_enabled']))
  832. unset($context[$context['profile_menu_name']]['tab_data']['edits']);
  833. // Set a page title.
  834. $context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];
  835. // Pass on to the actual function.
  836. $context['sub_template'] = $subActions[$context['tracking_area']][0];
  837. $subActions[$context['tracking_area']][0]($memID);
  838. }
  839. /**
  840. * @todo needs a description
  841. *
  842. * @param int $memID id_member
  843. */
  844. function trackActivity($memID)
  845. {
  846. global $scripturl, $txt, $modSettings, $sourcedir;
  847. global $user_profile, $context, $smcFunc;
  848. // Verify if the user has sufficient permissions.
  849. isAllowedTo('moderate_forum');
  850. $context['last_ip'] = $user_profile[$memID]['member_ip'];
  851. if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
  852. $context['last_ip2'] = $user_profile[$memID]['member_ip2'];
  853. $context['member']['name'] = $user_profile[$memID]['real_name'];
  854. // Set the options for the list component.
  855. $listOptions = array(
  856. 'id' => 'track_user_list',
  857. 'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
  858. 'items_per_page' => $modSettings['defaultMaxMessages'],
  859. 'no_items_label' => $txt['no_errors_from_user'],
  860. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
  861. 'default_sort_col' => 'date',
  862. 'get_items' => array(
  863. 'function' => 'list_getUserErrors',
  864. 'params' => array(
  865. 'le.id_member = {int:current_member}',
  866. array('current_member' => $memID),
  867. ),
  868. ),
  869. 'get_count' => array(
  870. 'function' => 'list_getUserErrorCount',
  871. 'params' => array(
  872. 'id_member = {int:current_member}',
  873. array('current_member' => $memID),
  874. ),
  875. ),
  876. 'columns' => array(
  877. 'ip_address' => array(
  878. 'header' => array(
  879. 'value' => $txt['ip_address'],
  880. ),
  881. 'data' => array(
  882. 'sprintf' => array(
  883. 'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID. '">%1$s</a>',
  884. 'params' => array(
  885. 'ip' => false,
  886. ),
  887. ),
  888. ),
  889. 'sort' => array(
  890. 'default' => 'le.ip',
  891. 'reverse' => 'le.ip DESC',
  892. ),
  893. ),
  894. 'message' => array(
  895. 'header' => array(
  896. 'value' => $txt['message'],
  897. ),
  898. 'data' => array(
  899. 'sprintf' => array(
  900. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  901. 'params' => array(
  902. 'message' => false,
  903. 'url' => false,
  904. ),
  905. ),
  906. ),
  907. ),
  908. 'date' => array(
  909. 'header' => array(
  910. 'value' => $txt['date'],
  911. ),
  912. 'data' => array(
  913. 'db' => 'time',
  914. ),
  915. 'sort' => array(
  916. 'default' => 'le.id_error DESC',
  917. 'reverse' => 'le.id_error',
  918. ),
  919. ),
  920. ),
  921. 'additional_rows' => array(
  922. array(
  923. 'position' => 'after_title',
  924. 'value' => $txt['errors_desc'],
  925. 'class' => 'windowbg2',
  926. 'style' => 'padding: 1ex 2ex;',
  927. ),
  928. ),
  929. );
  930. // Create the list for viewing.
  931. require_once($sourcedir . '/Subs-List.php');
  932. createList($listOptions);
  933. // @todo cache this
  934. // If this is a big forum, or a large posting user, let's limit the search.
  935. if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
  936. {
  937. $request = $smcFunc['db_query']('', '
  938. SELECT MAX(id_msg)
  939. FROM {db_prefix}messages AS m
  940. WHERE m.id_member = {int:current_member}',
  941. array(
  942. 'current_member' => $memID,
  943. )
  944. );
  945. list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
  946. $smcFunc['db_free_result']($request);
  947. // There's no point worrying ourselves with messages made yonks ago, just get recent ones!
  948. $min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
  949. }
  950. // Default to at least the ones we know about.
  951. $ips = array(
  952. $user_profile[$memID]['member_ip'],
  953. $user_profile[$memID]['member_ip2'],
  954. );
  955. // @todo cache this
  956. // Get all IP addresses this user has used for his messages.
  957. $request = $smcFunc['db_query']('', '
  958. SELECT poster_ip
  959. FROM {db_prefix}messages
  960. WHERE id_member = {int:current_member}
  961. ' . (isset($min_msg_member) ? '
  962. AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
  963. GROUP BY poster_ip',
  964. array(
  965. 'current_member' => $memID,
  966. 'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
  967. 'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
  968. )
  969. );
  970. $context['ips'] = array();
  971. while ($row = $smcFunc['db_fetch_assoc']($request))
  972. {
  973. $context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['poster_ip'] . ';u=' . $memID . '">' . $row['poster_ip'] . '</a>';
  974. $ips[] = $row['poster_ip'];
  975. }
  976. $smcFunc['db_free_result']($request);
  977. // Now also get the IP addresses from the error messages.
  978. $request = $smcFunc['db_query']('', '
  979. SELECT COUNT(*) AS error_count, ip
  980. FROM {db_prefix}log_errors
  981. WHERE id_member = {int:current_member}
  982. GROUP BY ip',
  983. array(
  984. 'current_member' => $memID,
  985. )
  986. );
  987. $context['error_ips'] = array();
  988. while ($row = $smcFunc['db_fetch_assoc']($request))
  989. {
  990. $context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
  991. $ips[] = $row['ip'];
  992. }
  993. $smcFunc['db_free_result']($request);
  994. // Find other users that might use the same IP.
  995. $ips = array_unique($ips);
  996. $context['members_in_range'] = array();
  997. if (!empty($ips))
  998. {
  999. // Get member ID's which are in messages...
  1000. $request = $smcFunc['db_query']('', '
  1001. SELECT mem.id_member
  1002. FROM {db_prefix}messages AS m
  1003. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1004. WHERE m.poster_ip IN ({array_string:ip_list})
  1005. GROUP BY mem.id_member
  1006. HAVING mem.id_member != {int:current_member}',
  1007. array(
  1008. 'current_member' => $memID,
  1009. 'ip_list' => $ips,
  1010. )
  1011. );
  1012. $message_members = array();
  1013. while ($row = $smcFunc['db_fetch_assoc']($request))
  1014. $message_members[] = $row['id_member'];
  1015. $smcFunc['db_free_result']($request);
  1016. // Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
  1017. if (!empty($message_members))
  1018. {
  1019. $request = $smcFunc['db_query']('', '
  1020. SELECT id_member, real_name
  1021. FROM {db_prefix}members
  1022. WHERE id_member IN ({array_int:message_members})',
  1023. array(
  1024. 'message_members' => $message_members,
  1025. 'ip_list' => $ips,
  1026. )
  1027. );
  1028. while ($row = $smcFunc['db_fetch_assoc']($request))
  1029. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  1030. $smcFunc['db_free_result']($request);
  1031. }
  1032. $request = $smcFunc['db_query']('', '
  1033. SELECT id_member, real_name
  1034. FROM {db_prefix}members
  1035. WHERE id_member != {int:current_member}
  1036. AND member_ip IN ({array_string:ip_list})',
  1037. array(
  1038. 'current_member' => $memID,
  1039. 'ip_list' => $ips,
  1040. )
  1041. );
  1042. while ($row = $smcFunc['db_fetch_assoc']($request))
  1043. $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
  1044. $smcFunc['db_free_result']($request);
  1045. }
  1046. }
  1047. /**
  1048. * Get the number of user errors
  1049. *
  1050. * @param string $where
  1051. * @param array $where_vars = array()
  1052. * @return string number of user errors
  1053. */
  1054. function list_getUserErrorCount($where, $where_vars = array())
  1055. {
  1056. global $smcFunc;
  1057. $request = $smcFunc['db_query']('', '
  1058. SELECT COUNT(*) AS error_count
  1059. FROM {db_prefix}log_errors
  1060. WHERE ' . $where,
  1061. $where_vars
  1062. );
  1063. list ($count) = $smcFunc['db_fetch_row']($request);
  1064. $smcFunc['db_free_result']($request);
  1065. // @todo cast this to an integer
  1066. return $count;
  1067. }
  1068. /**
  1069. * @todo needs a description
  1070. *
  1071. * @param int $start
  1072. * @param int $items_per_page
  1073. * @param string $sort
  1074. * @param string $where
  1075. * @param array $where_vars
  1076. * @return array error messages
  1077. */
  1078. function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
  1079. {
  1080. global $smcFunc, $txt, $scripturl;
  1081. // Get a list of error messages from this ip (range).
  1082. $request = $smcFunc['db_query']('', '
  1083. SELECT
  1084. le.log_time, le.ip, le.url, le.message, IFNULL(mem.id_member, 0) AS id_member,
  1085. IFNULL(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
  1086. FROM {db_prefix}log_errors AS le
  1087. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
  1088. WHERE ' . $where . '
  1089. ORDER BY ' . $sort . '
  1090. LIMIT ' . $start . ', ' . $items_per_page,
  1091. array_merge($where_vars, array(
  1092. 'guest_title' => $txt['guest_title'],
  1093. ))
  1094. );
  1095. $error_messages = array();
  1096. while ($row = $smcFunc['db_fetch_assoc']($request))
  1097. $error_messages[] = array(
  1098. 'ip' => $row['ip'],
  1099. 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
  1100. 'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
  1101. 'url' => $row['url'],
  1102. 'time' => timeformat($row['log_time']),
  1103. 'timestamp' => forum_time(true, $row['log_time']),
  1104. );
  1105. $smcFunc['db_free_result']($request);
  1106. return $error_messages;
  1107. }
  1108. /**
  1109. * @todo needs a description
  1110. *
  1111. * @param string $where
  1112. * @param array $where_vars
  1113. * @return string count of messages matching the IP
  1114. */
  1115. function list_getIPMessageCount($where, $where_vars = array())
  1116. {
  1117. global $smcFunc;
  1118. $request = $smcFunc['db_query']('', '
  1119. SELECT COUNT(*) AS message_count
  1120. FROM {db_prefix}messages AS m
  1121. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1122. WHERE {query_see_board} AND ' . $where,
  1123. $where_vars
  1124. );
  1125. list ($count) = $smcFunc['db_fetch_row']($request);
  1126. $smcFunc['db_free_result']($request);
  1127. // @todo cast to integer
  1128. return $count;
  1129. }
  1130. /**
  1131. * @todo needs a description
  1132. *
  1133. * @param int $start
  1134. * @param int $items_per_page
  1135. * @param string $sort
  1136. * @param string $where
  1137. * @param array $where_vars
  1138. * @return array an array of messages
  1139. */
  1140. function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
  1141. {
  1142. global $smcFunc, $txt, $scripturl;
  1143. // Get all the messages fitting this where clause.
  1144. // @todo SLOW This query is using a filesort.
  1145. $request = $smcFunc['db_query']('', '
  1146. SELECT
  1147. m.id_msg, m.poster_ip, IFNULL(mem.real_name, m.poster_name) AS display_name, mem.id_member,
  1148. m.subject, m.poster_time, m.id_topic, m.id_board
  1149. FROM {db_prefix}messages AS m
  1150. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1151. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1152. WHERE {query_see_board} AND ' . $where . '
  1153. ORDER BY ' . $sort . '
  1154. LIMIT ' . $start . ', ' . $items_per_page,
  1155. array_merge($where_vars, array(
  1156. ))
  1157. );
  1158. $messages = array();
  1159. while ($row = $smcFunc['db_fetch_assoc']($request))
  1160. $messages[] = array(
  1161. 'ip' => $row['poster_ip'],
  1162. 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
  1163. 'board' => array(
  1164. 'id' => $row['id_board'],
  1165. 'href' => $scripturl . '?board=' . $row['id_board']
  1166. ),
  1167. 'topic' => $row['id_topic'],
  1168. 'id' => $row['id_msg'],
  1169. 'subject' => $row['subject'],
  1170. 'time' => timeformat($row['poster_time']),
  1171. 'timestamp' => forum_time(true, $row['poster_time'])
  1172. );
  1173. $smcFunc['db_free_result']($request);
  1174. return $messages;
  1175. }
  1176. /**
  1177. * @todo needs a description
  1178. *
  1179. * @param int $memID = 0 id_member
  1180. */
  1181. function TrackIP($memID = 0)
  1182. {
  1183. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1184. global $context, $smcFunc;
  1185. // Can the user do this?
  1186. isAllowedTo('moderate_forum');
  1187. if ($memID == 0)
  1188. {
  1189. $context['ip'] = $user_info['ip'];
  1190. loadTemplate('Profile');
  1191. loadLanguage('Profile');
  1192. $context['sub_template'] = 'trackIP';
  1193. $context['page_title'] = $txt['profile'];
  1194. $context['base_url'] = $scripturl . '?action=trackip';
  1195. }
  1196. else
  1197. {
  1198. $context['ip'] = $user_profile[$memID]['member_ip'];
  1199. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1200. }
  1201. // Searching?
  1202. if (isset($_REQUEST['searchip']))
  1203. $context['ip'] = trim($_REQUEST['searchip']);
  1204. if (preg_match('/^\d{1,3}\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$/', $context['ip']) == 0 && isValidIPv6($context['ip']) === false)
  1205. fatal_lang_error('invalid_tracking_ip', false);
  1206. $ip_var = str_replace('*', '%', $context['ip']);
  1207. $ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}';
  1208. if (empty($context['tracking_area']))
  1209. $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
  1210. $request = $smcFunc['db_query']('', '
  1211. SELECT id_member, real_name AS display_name, member_ip
  1212. FROM {db_prefix}members
  1213. WHERE member_ip ' . $ip_string,
  1214. array(
  1215. 'ip_address' => $ip_var,
  1216. )
  1217. );
  1218. $context['ips'] = array();
  1219. while ($row = $smcFunc['db_fetch_assoc']($request))
  1220. $context['ips'][$row['member_ip']][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
  1221. $smcFunc['db_free_result']($request);
  1222. ksort($context['ips']);
  1223. // Gonna want this for the list.
  1224. require_once($sourcedir . '/Subs-List.php');
  1225. // Start with the user messages.
  1226. $listOptions = array(
  1227. 'id' => 'track_message_list',
  1228. 'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
  1229. 'start_var_name' => 'messageStart',
  1230. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1231. 'no_items_label' => $txt['no_messages_from_ip'],
  1232. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1233. 'default_sort_col' => 'date',
  1234. 'get_items' => array(
  1235. 'function' => 'list_getIPMessages',
  1236. 'params' => array(
  1237. 'm.poster_ip ' . $ip_string,
  1238. array('ip_address' => $ip_var),
  1239. ),
  1240. ),
  1241. 'get_count' => array(
  1242. 'function' => 'list_getIPMessageCount',
  1243. 'params' => array(
  1244. 'm.poster_ip ' . $ip_string,
  1245. array('ip_address' => $ip_var),
  1246. ),
  1247. ),
  1248. 'columns' => array(
  1249. 'ip_address' => array(
  1250. 'header' => array(
  1251. 'value' => $txt['ip_address'],
  1252. ),
  1253. 'data' => array(
  1254. 'sprintf' => array(
  1255. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1256. 'params' => array(
  1257. 'ip' => false,
  1258. ),
  1259. ),
  1260. ),
  1261. 'sort' => array(
  1262. 'default' => 'INET_ATON(m.poster_ip)',
  1263. 'reverse' => 'INET_ATON(m.poster_ip) DESC',
  1264. ),
  1265. ),
  1266. 'poster' => array(
  1267. 'header' => array(
  1268. 'value' => $txt['poster'],
  1269. ),
  1270. 'data' => array(
  1271. 'db' => 'member_link',
  1272. ),
  1273. ),
  1274. 'subject' => array(
  1275. 'header' => array(
  1276. 'value' => $txt['subject'],
  1277. ),
  1278. 'data' => array(
  1279. 'sprintf' => array(
  1280. 'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
  1281. 'params' => array(
  1282. 'topic' => false,
  1283. 'id' => false,
  1284. 'subject' => false,
  1285. ),
  1286. ),
  1287. ),
  1288. ),
  1289. 'date' => array(
  1290. 'header' => array(
  1291. 'value' => $txt['date'],
  1292. ),
  1293. 'data' => array(
  1294. 'db' => 'time',
  1295. ),
  1296. 'sort' => array(
  1297. 'default' => 'm.id_msg DESC',
  1298. 'reverse' => 'm.id_msg',
  1299. ),
  1300. ),
  1301. ),
  1302. 'additional_rows' => array(
  1303. array(
  1304. 'position' => 'after_title',
  1305. 'value' => $txt['messages_from_ip_desc'],
  1306. 'class' => 'windowbg2',
  1307. 'style' => 'padding: 1ex 2ex;',
  1308. ),
  1309. ),
  1310. );
  1311. // Create the messages list.
  1312. createList($listOptions);
  1313. // Set the options for the error lists.
  1314. $listOptions = array(
  1315. 'id' => 'track_user_list',
  1316. 'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
  1317. 'start_var_name' => 'errorStart',
  1318. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1319. 'no_items_label' => $txt['no_errors_from_ip'],
  1320. 'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
  1321. 'default_sort_col' => 'date2',
  1322. 'get_items' => array(
  1323. 'function' => 'list_getUserErrors',
  1324. 'params' => array(
  1325. 'le.ip ' . $ip_string,
  1326. array('ip_address' => $ip_var),
  1327. ),
  1328. ),
  1329. 'get_count' => array(
  1330. 'function' => 'list_getUserErrorCount',
  1331. 'params' => array(
  1332. 'ip ' . $ip_string,
  1333. array('ip_address' => $ip_var),
  1334. ),
  1335. ),
  1336. 'columns' => array(
  1337. 'ip_address2' => array(
  1338. 'header' => array(
  1339. 'value' => $txt['ip_address'],
  1340. ),
  1341. 'data' => array(
  1342. 'sprintf' => array(
  1343. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
  1344. 'params' => array(
  1345. 'ip' => false,
  1346. ),
  1347. ),
  1348. ),
  1349. 'sort' => array(
  1350. 'default' => 'INET_ATON(le.ip)',
  1351. 'reverse' => 'INET_ATON(le.ip) DESC',
  1352. ),
  1353. ),
  1354. 'display_name' => array(
  1355. 'header' => array(
  1356. 'value' => $txt['display_name'],
  1357. ),
  1358. 'data' => array(
  1359. 'db' => 'member_link',
  1360. ),
  1361. ),
  1362. 'message' => array(
  1363. 'header' => array(
  1364. 'value' => $txt['message'],
  1365. ),
  1366. 'data' => array(
  1367. 'sprintf' => array(
  1368. 'format' => '%1$s<br /><a href="%2$s">%2$s</a>',
  1369. 'params' => array(
  1370. 'message' => false,
  1371. 'url' => false,
  1372. ),
  1373. ),
  1374. ),
  1375. ),
  1376. 'date2' => array(
  1377. 'header' => array(
  1378. 'value' => $txt['date'],
  1379. ),
  1380. 'data' => array(
  1381. 'db' => 'time',
  1382. ),
  1383. 'sort' => array(
  1384. 'default' => 'le.id_error DESC',
  1385. 'reverse' => 'le.id_error',
  1386. ),
  1387. ),
  1388. ),
  1389. 'additional_rows' => array(
  1390. array(
  1391. 'position' => 'after_title',
  1392. 'value' => $txt['errors_from_ip_desc'],
  1393. 'class' => 'windowbg2',
  1394. 'style' => 'padding: 1ex 2ex;',
  1395. ),
  1396. ),
  1397. );
  1398. // Create the error list.
  1399. createList($listOptions);
  1400. $context['single_ip'] = strpos($context['ip'], '*') === false;
  1401. if ($context['single_ip'])
  1402. {
  1403. $context['whois_servers'] = array(
  1404. 'afrinic' => array(
  1405. 'name' => $txt['whois_afrinic'],
  1406. 'url' => 'http://www.afrinic.net/cgi-bin/whois?searchtext=' . $context['ip'],
  1407. 'range' => array(41, 154, 196),
  1408. ),
  1409. 'apnic' => array(
  1410. 'name' => $txt['whois_apnic'],
  1411. 'url' => 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
  1412. 'range' => array(58, 59, 60, 61, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
  1413. 125, 126, 133, 150, 153, 163, 171, 202, 203, 210, 211, 218, 219, 220, 221, 222),
  1414. ),
  1415. 'arin' => array(
  1416. 'name' => $txt['whois_arin'],
  1417. 'url' => 'http://whois.arin.net/rest/ip/' . $context['ip'],
  1418. 'range' => array(7, 24, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 96, 97, 98, 99,
  1419. 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 146, 147, 148, 149,
  1420. 152, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174,
  1421. 192, 198, 199, 204, 205, 206, 207, 208, 209, 216),
  1422. ),
  1423. 'lacnic' => array(
  1424. 'name' => $txt['whois_lacnic'],
  1425. 'url' => 'http://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
  1426. 'range' => array(186, 187, 189, 190, 191, 200, 201),
  1427. ),
  1428. 'ripe' => array(
  1429. 'name' => $txt['whois_ripe'],
  1430. 'url' => 'http://www.db.ripe.net/whois?searchtext=' . $context['ip'],
  1431. 'range' => array(62, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  1432. 141, 145, 151, 188, 193, 194, 195, 212, 213, 217),
  1433. ),
  1434. );
  1435. foreach ($context['whois_servers'] as $whois)
  1436. {
  1437. // Strip off the "decimal point" and anything following...
  1438. if (in_array((int) $context['ip'], $whois['range']))
  1439. $context['auto_whois_server'] = $whois;
  1440. }
  1441. }
  1442. }
  1443. /**
  1444. * Tracks a users logins.
  1445. *
  1446. * @param int $memID = 0 id_member
  1447. */
  1448. function TrackLogins($memID = 0)
  1449. {
  1450. global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
  1451. global $context, $smcFunc;
  1452. // Gonna want this for the list.
  1453. require_once($sourcedir . '/Subs-List.php');
  1454. if ($memID == 0)
  1455. $context['base_url'] = $scripturl . '?action=trackip';
  1456. else
  1457. $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
  1458. // Start with the user messages.
  1459. $listOptions = array(
  1460. 'id' => 'track_logins_list',
  1461. 'title' => $txt['trackLogins'],
  1462. 'no_items_label' => $txt['trackLogins_none_found'],
  1463. 'base_href' => $context['base_url'],
  1464. 'get_items' => array(
  1465. 'function' => 'list_getLogins',
  1466. 'params' => array(
  1467. 'id_member = {int:current_member}',
  1468. array('current_member' => $memID),
  1469. ),
  1470. ),
  1471. 'get_count' => array(
  1472. 'function' => 'list_getLoginCount',
  1473. 'params' => array(
  1474. 'id_member = {int:current_member}',
  1475. array('current_member' => $memID),
  1476. ),
  1477. ),
  1478. 'columns' => array(
  1479. 'time' => array(
  1480. 'header' => array(
  1481. 'value' => $txt['date'],
  1482. ),
  1483. 'data' => array(
  1484. 'db' => 'time',
  1485. ),
  1486. ),
  1487. 'ip' => array(
  1488. 'header' => array(
  1489. 'value' => $txt['ip_address'],
  1490. ),
  1491. 'data' => array(
  1492. 'sprintf' => array(
  1493. 'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
  1494. 'params' => array(
  1495. 'ip' => false,
  1496. 'ip2' => false
  1497. ),
  1498. ),
  1499. ),
  1500. ),
  1501. ),
  1502. 'additional_rows' => array(
  1503. array(
  1504. 'position' => 'after_title',
  1505. 'value' => $txt['trackLogins_desc'],
  1506. 'class' => 'windowbg2',
  1507. 'style' => 'padding: 1ex 2ex;',
  1508. ),
  1509. ),
  1510. );
  1511. // Create the messages list.
  1512. createList($listOptions);
  1513. $context['sub_template'] = 'show_list';
  1514. $context['default_list'] = 'track_logins_list';
  1515. }
  1516. /**
  1517. * Callback for trackLogins for counting history.
  1518. *
  1519. * @param string $where
  1520. * @param array $where_vars
  1521. * @return string count of messages matching the IP
  1522. */
  1523. function list_getLoginCount($where, $where_vars = array())
  1524. {
  1525. global $smcFunc;
  1526. $request = $smcFunc['db_query']('', '
  1527. SELECT COUNT(*) AS message_count
  1528. FROM {db_prefix}member_logins
  1529. WHERE id_member = {int:id_member}',
  1530. array(
  1531. 'id_member' => $where_vars['current_member'],
  1532. )
  1533. );
  1534. list ($count) = $smcFunc['db_fetch_row']($request);
  1535. $smcFunc['db_free_result']($request);
  1536. // @todo cast to integer
  1537. return $count;
  1538. }
  1539. /**
  1540. * Callback for trackLogins data.
  1541. *
  1542. * @param int $start
  1543. * @param int $items_per_page
  1544. * @param string $sort
  1545. * @param string $where
  1546. * @param array $where_vars
  1547. * @return array an array of messages
  1548. */
  1549. function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
  1550. {
  1551. global $smcFunc, $txt, $scripturl;
  1552. $request = $smcFunc['db_query']('', '
  1553. SELECT time, ip, ip2
  1554. FROM {db_prefix}member_logins
  1555. WHERE {int:id_member}
  1556. ORDER BY time DESC',
  1557. array(
  1558. 'id_member' => $where_vars['current_member'],
  1559. )
  1560. );
  1561. $logins = array();
  1562. while ($row = $smcFunc['db_fetch_assoc']($request))
  1563. $logins[] = array(
  1564. 'time' => timeformat($row['time']),
  1565. 'ip' => $row['ip'],
  1566. 'ip2' => $row['ip2'],
  1567. );
  1568. $smcFunc['db_free_result']($request);
  1569. return $logins;
  1570. }
  1571. /**
  1572. * @todo needs a description
  1573. *
  1574. * @param int $memID id_member
  1575. */
  1576. function trackEdits($memID)
  1577. {
  1578. global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;
  1579. require_once($sourcedir . '/Subs-List.php');
  1580. // Get the names of any custom fields.
  1581. $request = $smcFunc['db_query']('', '
  1582. SELECT col_name, field_name, bbc
  1583. FROM {db_prefix}custom_fields',
  1584. array(
  1585. )
  1586. );
  1587. $context['custom_field_titles'] = array();
  1588. while ($row = $smcFunc['db_fetch_assoc']($request))
  1589. $context['custom_field_titles']['customfield_' . $row['col_name']] = array(
  1590. 'title' => $row['field_name'],
  1591. 'parse_bbc' => $row['bbc'],
  1592. );
  1593. $smcFunc['db_free_result']($request);
  1594. // Set the options for the error lists.
  1595. $listOptions = array(
  1596. 'id' => 'edit_list',
  1597. 'title' => $txt['trackEdits'],
  1598. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1599. 'no_items_label' => $txt['trackEdit_no_edits'],
  1600. 'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
  1601. 'default_sort_col' => 'time',
  1602. 'get_items' => array(
  1603. 'function' => 'list_getProfileEdits',
  1604. 'params' => array(
  1605. $memID,
  1606. ),
  1607. ),
  1608. 'get_count' => array(
  1609. 'function' => 'list_getProfileEditCount',
  1610. 'params' => array(
  1611. $memID,
  1612. ),
  1613. ),
  1614. 'columns' => array(
  1615. 'action' => array(
  1616. 'header' => array(
  1617. 'value' => $txt['trackEdit_action'],
  1618. ),
  1619. 'data' => array(
  1620. 'db' => 'action_text',
  1621. ),
  1622. ),
  1623. 'before' => array(
  1624. 'header' => array(
  1625. 'value' => $txt['trackEdit_before'],
  1626. ),
  1627. 'data' => array(
  1628. 'db' => 'before',
  1629. ),
  1630. ),
  1631. 'after' => array(
  1632. 'header' => array(
  1633. 'value' => $txt['trackEdit_after'],
  1634. ),
  1635. 'data' => array(
  1636. 'db' => 'after',
  1637. ),
  1638. ),
  1639. 'time' => array(
  1640. 'header' => array(
  1641. 'value' => $txt['date'],
  1642. ),
  1643. 'data' => array(
  1644. 'db' => 'time',
  1645. ),
  1646. 'sort' => array(
  1647. 'default' => 'id_action DESC',
  1648. 'reverse' => 'id_action',
  1649. ),
  1650. ),
  1651. 'applicator' => array(
  1652. 'header' => array(
  1653. 'value' => $txt['trackEdit_applicator'],
  1654. ),
  1655. 'data' => array(
  1656. 'db' => 'member_link',
  1657. ),
  1658. ),
  1659. ),
  1660. );
  1661. // Create the error list.
  1662. createList($listOptions);
  1663. $context['sub_template'] = 'show_list';
  1664. $context['default_list'] = 'edit_list';
  1665. }
  1666. /**
  1667. * How many edits?
  1668. *
  1669. * @param int $memID id_member
  1670. * @return string number of profile edits
  1671. */
  1672. function list_getProfileEditCount($memID)
  1673. {
  1674. global $smcFunc;
  1675. $request = $smcFunc['db_query']('', '
  1676. SELECT COUNT(*) AS edit_count
  1677. FROM {db_prefix}log_actions
  1678. WHERE id_log = {int:log_type}
  1679. AND id_member = {int:owner}',
  1680. array(
  1681. 'log_type' => 2,
  1682. 'owner' => $memID,
  1683. )
  1684. );
  1685. list ($edit_count) = $smcFunc['db_fetch_row']($request);
  1686. $smcFunc['db_free_result']($request);
  1687. // @todo cast to integer
  1688. return $edit_count;
  1689. }
  1690. /**
  1691. * @todo needs a description
  1692. *
  1693. * @param int $start
  1694. * @param int $items_per_page
  1695. * @param string $sort
  1696. * @param int $memID
  1697. * @return array
  1698. */
  1699. function list_getProfileEdits($start, $items_per_page, $sort, $memID)
  1700. {
  1701. global $smcFunc, $txt, $scripturl, $context;
  1702. // Get a list of error messages from this ip (range).
  1703. $request = $smcFunc['db_query']('', '
  1704. SELECT
  1705. id_action, id_member, ip, log_time, action, extra
  1706. FROM {db_prefix}log_actions
  1707. WHERE id_log = {int:log_type}
  1708. AND id_member = {int:owner}
  1709. ORDER BY ' . $sort . '
  1710. LIMIT ' . $start . ', ' . $items_per_page,
  1711. array(
  1712. 'log_type' => 2,
  1713. 'owner' => $memID,
  1714. )
  1715. );
  1716. $edits = array();
  1717. $members = array();
  1718. while ($row = $smcFunc['db_fetch_assoc']($request))
  1719. {
  1720. $extra = @unserialize($row['extra']);
  1721. if (!empty($extra['applicator']))
  1722. $members[] = $extra['applicator'];
  1723. // Work out what the name of the action is.
  1724. if (isset($txt['trackEdit_action_' . $row['action']]))
  1725. $action_text = $txt['trackEdit_action_' . $row['action']];
  1726. elseif (isset($txt[$row['action']]))
  1727. $action_text = $txt[$row['action']];
  1728. // Custom field?
  1729. elseif (isset($context['custom_field_titles'][$row['action']]))
  1730. $action_text = $context['custom_field_titles'][$row['action']]['title'];
  1731. else
  1732. $action_text = $row['action'];
  1733. // Parse BBC?
  1734. $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
  1735. $edits[] = array(
  1736. 'id' => $row['id_action'],
  1737. 'ip' => $row['ip'],
  1738. 'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
  1739. 'member_link' => $txt['trackEdit_deleted_member'],
  1740. 'action' => $row['action'],
  1741. 'action_text' => $action_text,
  1742. 'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
  1743. 'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
  1744. 'time' => timeformat($row['log_time']),
  1745. );
  1746. }
  1747. $smcFunc['db_free_result']($request);
  1748. // Get any member names.
  1749. if (!empty($members))
  1750. {
  1751. $request = $smcFunc['db_query']('', '
  1752. SELECT
  1753. id_member, real_name
  1754. FROM {db_prefix}members
  1755. WHERE id_member IN ({array_int:members})',
  1756. array(
  1757. 'members' => $members,
  1758. )
  1759. );
  1760. $members = array();
  1761. while ($row = $smcFunc['db_fetch_assoc']($request))
  1762. $members[$row['id_member']] = $row['real_name'];
  1763. $smcFunc['db_free_result']($request);
  1764. foreach ($edits as $key => $value)
  1765. if (isset($members[$value['id_member']]))
  1766. $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
  1767. }
  1768. return $edits;
  1769. }
  1770. /**
  1771. * @todo needs a description
  1772. *
  1773. * @param int $memID id_member
  1774. */
  1775. function showPermissions($memID)
  1776. {
  1777. global $scripturl, $txt, $board, $modSettings;
  1778. global $user_profile, $context, $user_info, $sourcedir, $smcFunc;
  1779. // Verify if the user has sufficient permissions.
  1780. isAllowedTo('manage_permissions');
  1781. loadLanguage('ManagePermissions');
  1782. loadLanguage('Admin');
  1783. loadTemplate('ManageMembers');
  1784. // Load all the permission profiles.
  1785. require_once($sourcedir . '/ManagePermissions.php');
  1786. loadPermissionProfiles();
  1787. $context['member']['id'] = $memID;
  1788. $context['member']['name'] = $user_profile[$memID]['real_name'];
  1789. $context['page_title'] = $txt['showPermissions'];
  1790. $board = empty($board) ? 0 : (int) $board;
  1791. $context['board'] = $board;
  1792. // Determine which groups this user is in.
  1793. if (empty($user_profile[$memID]['additional_groups']))
  1794. $curGroups = array();
  1795. else
  1796. $curGroups = explode(',', $user_profile[$memID]['additional_groups']);
  1797. $curGroups[] = $user_profile[$memID]['id_group'];
  1798. $curGroups[] = $user_profile[$memID]['id_post_group'];
  1799. // Load a list of boards for the jump box - except the defaults.
  1800. $request = $smcFunc['db_query']('order_by_board_order', '
  1801. SELECT b.id_board, b.name, b.id_profile, b.member_groups, IFNULL(mods.id_member, 0) AS is_mod
  1802. FROM {db_prefix}boards AS b
  1803. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
  1804. WHERE {query_see_board}',
  1805. array(
  1806. 'current_member' => $memID,
  1807. )
  1808. );
  1809. $context['boards'] = array();
  1810. $context['no_access_boards'] = array();
  1811. while ($row = $smcFunc['db_fetch_assoc']($request))
  1812. {
  1813. if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
  1814. $context['no_access_boards'][] = array(
  1815. 'id' => $row['id_board'],
  1816. 'name' => $row['name'],
  1817. 'is_last' => false,
  1818. );
  1819. elseif ($row['id_profile'] != 1 || $row['is_mod'])
  1820. $context['boards'][$row['id_board']] = array(
  1821. 'id' => $row['id_board'],
  1822. 'name' => $row['name'],
  1823. 'selected' => $board == $row['id_board'],
  1824. 'profile' => $row['id_profile'],
  1825. 'profile_name' => $context['profiles'][$row['id_profile']]['name'],
  1826. );
  1827. }
  1828. $smcFunc['db_free_result']($request);
  1829. if (!empty($context['no_access_boards']))
  1830. $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
  1831. $context['member']['permissions'] = array(
  1832. 'general' => array(),
  1833. 'board' => array()
  1834. );
  1835. // If you're an admin we know you can do everything, we might as well leave.
  1836. $context['member']['has_all_permissions'] = in_array(1, $curGroups);
  1837. if ($context['member']['has_all_permissions'])
  1838. return;
  1839. $denied = array();
  1840. // Get all general permissions.
  1841. $result = $smcFunc['db_query']('', '
  1842. SELECT p.permission, p.add_deny, mg.group_name, p.id_group
  1843. FROM {db_prefix}permissions AS p
  1844. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
  1845. WHERE p.id_group IN ({array_int:group_list})
  1846. ORDER BY p.add_deny DESC, p.permission, mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name',
  1847. array(
  1848. 'group_list' => $curGroups,
  1849. 'newbie_group' => 4,
  1850. )
  1851. );
  1852. while ($row = $smcFunc['db_fetch_assoc']($result))
  1853. {
  1854. // We don't know about this permission, it doesn't exist :P.
  1855. if (!isset($txt['permissionname_' . $row['permission']]))
  1856. continue;
  1857. if (empty($row['add_deny']))
  1858. $denied[] = $row['permission'];
  1859. // Permissions that end with _own or _any consist of two parts.
  1860. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  1861. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  1862. else
  1863. $name = $txt['permissionname_' . $row['permission']];
  1864. // Add this permission if it doesn't exist yet.
  1865. if (!isset($context['member']['permissions']['general'][$row['permission']]))
  1866. $context['member']['permissions']['general'][$row['permission']] = array(
  1867. 'id' => $row['permission'],
  1868. 'groups' => array(
  1869. 'allowed' => array(),
  1870. 'denied' => array()
  1871. ),
  1872. 'name' => $name,
  1873. 'is_denied' => false,
  1874. 'is_global' => true,
  1875. );
  1876. // Add the membergroup to either the denied or the allowed groups.
  1877. $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
  1878. // Once denied is always denied.
  1879. $context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  1880. }
  1881. $smcFunc['db_free_result']($result);
  1882. $request = $smcFunc['db_query']('', '
  1883. SELECT
  1884. bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
  1885. b.id_profile, CASE WHEN mods.id_member IS NULL THEN 0 ELSE 1 END AS is_moderator') . '
  1886. FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
  1887. INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
  1888. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})') . '
  1889. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
  1890. WHERE bp.id_profile = {raw:current_profile}
  1891. AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
  1892. AND (mods.id_member IS NOT NULL OR bp.id_group != {int:moderator_group})'),
  1893. array(
  1894. 'current_board' => $board,
  1895. 'group_list' => $curGroups,
  1896. 'current_member' => $memID,
  1897. 'current_profile' => empty($board) ? '1' : 'b.id_profile',
  1898. 'moderator_group' => 3,
  1899. )
  1900. );
  1901. while ($row = $smcFunc['db_fetch_assoc']($request))
  1902. {
  1903. // We don't know about this permission, it doesn't exist :P.
  1904. if (!isset($txt['permissionname_' . $row['permission']]))
  1905. continue;
  1906. // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
  1907. if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
  1908. $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
  1909. else
  1910. $name = $txt['permissionname_' . $row['permission']];
  1911. // Create the structure for this permission.
  1912. if (!isset($context['member']['permissions']['board'][$row['permission']]))
  1913. $context['member']['permissions']['board'][$row['permission']] = array(
  1914. 'id' => $row['permission'],
  1915. 'groups' => array(
  1916. 'allowed' => array(),
  1917. 'denied' => array()
  1918. ),
  1919. 'name' => $name,
  1920. 'is_denied' => false,
  1921. 'is_global' => empty($board),
  1922. );
  1923. $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
  1924. $context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
  1925. }
  1926. $smcFunc['db_free_result']($request);
  1927. }
  1928. /**
  1929. * View a members warnings?
  1930. *
  1931. * @param int $memID id_member
  1932. */
  1933. function viewWarning($memID)
  1934. {
  1935. global $modSettings, $context, $sourcedir, $txt, $scripturl;
  1936. // Firstly, can we actually even be here?
  1937. if (!allowedTo('issue_warning') && (empty($modSettings['warning_show']) || ($modSettings['warning_show'] == 1 && !$context['user']['is_owner'])))
  1938. fatal_lang_error('no_access', false);
  1939. // Make sure things which are disabled stay disabled.
  1940. $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
  1941. $modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
  1942. $modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
  1943. // Let's use a generic list to get all the current warnings, and use the issue warnings grab-a-granny thing.
  1944. require_once($sourcedir . '/Subs-List.php');
  1945. require_once($sourcedir . '/Profile-Actions.php');
  1946. $listOptions = array(
  1947. 'id' => 'view_warnings',
  1948. 'title' => $txt['profile_viewwarning_previous_warnings'],
  1949. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1950. 'no_items_label' => $txt['profile_viewwarning_no_warnings'],
  1951. 'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
  1952. 'default_sort_col' => 'log_time',
  1953. 'get_items' => array(
  1954. 'function' => 'list_getUserWarnings',
  1955. 'params' => array(
  1956. $memID,
  1957. ),
  1958. ),
  1959. 'get_count' => array(
  1960. 'function' => 'list_getUserWarningCount',
  1961. 'params' => array(
  1962. $memID,
  1963. ),
  1964. ),
  1965. 'columns' => array(
  1966. 'log_time' => array(
  1967. 'header' => array(
  1968. 'value' => $txt['profile_warning_previous_time'],
  1969. ),
  1970. 'data' => array(
  1971. 'db' => 'time',
  1972. ),
  1973. 'sort' => array(
  1974. 'default' => 'lc.log_time DESC',
  1975. 'reverse' => 'lc.log_time',
  1976. ),
  1977. ),
  1978. 'reason' => array(
  1979. 'header' => array(
  1980. 'value' => $txt['profile_warning_previous_reason'],
  1981. 'style' => 'width: 50%',
  1982. ),
  1983. 'data' => array(
  1984. 'db' => 'reason',
  1985. ),
  1986. ),
  1987. 'level' => array(
  1988. 'header' => array(
  1989. 'value' => $txt['profile_warning_previous_level'],
  1990. ),
  1991. 'data' => array(
  1992. 'db' => 'counter',
  1993. ),
  1994. 'sort' => array(
  1995. 'default' => 'lc.counter DESC',
  1996. 'reverse' => 'lc.counter',
  1997. ),
  1998. ),
  1999. ),
  2000. 'additional_rows' => array(
  2001. array(
  2002. 'position' => 'after_title',
  2003. 'value' => $txt['profile_viewwarning_desc'],
  2004. 'class' => 'smalltext',
  2005. 'style' => 'padding: 2ex;',
  2006. ),
  2007. ),
  2008. );
  2009. // Create the list for viewing.
  2010. require_once($sourcedir . '/Subs-List.php');
  2011. createList($listOptions);
  2012. // Create some common text bits for the template.
  2013. $context['level_effects'] = array(
  2014. 0 => '',
  2015. $modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
  2016. $modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
  2017. $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
  2018. );
  2019. $context['current_level'] = 0;
  2020. foreach ($context['level_effects'] as $limit => $dummy)
  2021. if ($context['member']['warning'] >= $limit)
  2022. $context['current_level'] = $limit;
  2023. }
  2024. ?>