/** * Function to sending out approval notices to moderators. * * - It checks who needs to receive approvals notifications and sends emails. */ public function approval_notification() { global $scripturl, $txt; $db = database(); // Grab all the items awaiting approval and sort type then board - clear up any things that are no longer relevant. $request = $db->query('', ' SELECT aq.id_msg, aq.id_attach, aq.id_event, m.id_topic, m.id_board, m.subject, t.id_first_msg, b.id_profile FROM {db_prefix}approval_queue AS aq INNER JOIN {db_prefix}messages AS m ON (m.id_msg = aq.id_msg) INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)', array()); $notices = array(); $profiles = array(); while ($row = $db->fetch_assoc($request)) { // If this is no longer around we'll ignore it. if (empty($row['id_topic'])) { continue; } // What type is it? if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) { $type = 'topic'; } elseif ($row['id_attach']) { $type = 'attach'; } else { $type = 'msg'; } // Add it to the array otherwise. $notices[$row['id_board']][$type][] = array('subject' => $row['subject'], 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']); // Store the profile for a bit later. $profiles[$row['id_board']] = $row['id_profile']; } $db->free_result($request); // Delete it all! $db->query('', ' DELETE FROM {db_prefix}approval_queue', array()); // If nothing quit now. if (empty($notices)) { return true; } // Now we need to think about finding out *who* can approve - this is hard! // First off, get all the groups with this permission and sort by board. $request = $db->query('', ' SELECT id_group, id_profile, add_deny FROM {db_prefix}board_permissions WHERE permission = {string:approve_posts} AND id_profile IN ({array_int:profile_list})', array('profile_list' => $profiles, 'approve_posts' => 'approve_posts')); $perms = array(); $addGroups = array(1); while ($row = $db->fetch_assoc($request)) { // Sorry guys, but we have to ignore guests AND members - it would be too many otherwise. if ($row['id_group'] < 2) { continue; } $perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group']; // Anyone who can access has to be considered. if ($row['add_deny']) { $addGroups[] = $row['id_group']; } } $db->free_result($request); // Grab the moderators if they have permission! $mods = array(); $members = array(); if (in_array(2, $addGroups)) { require_once SUBSDIR . '/Boards.subs.php'; $all_mods = allBoardModerators(true); // Make sure they get included in the big loop. $members = array_keys($all_mods); foreach ($all_mods as $row) { $mods[$row['id_member']][$row['id_board']] = true; } } // Come along one and all... until we reject you ;) $request = $db->query('', ' SELECT id_member, real_name, email_address, lngfile, id_group, additional_groups, mod_prefs FROM {db_prefix}members WHERE id_group IN ({array_int:additional_group_list}) OR FIND_IN_SET({raw:additional_group_list_implode}, additional_groups) != 0' . (empty($members) ? '' : ' OR id_member IN ({array_int:member_list})') . ' ORDER BY lngfile', array('additional_group_list' => $addGroups, 'member_list' => $members, 'additional_group_list_implode' => implode(', additional_groups) != 0 OR FIND_IN_SET(', $addGroups))); $members = array(); while ($row = $db->fetch_assoc($request)) { // Check whether they are interested. if (!empty($row['mod_prefs'])) { list(, , $pref_binary) = explode('|', $row['mod_prefs']); if (!($pref_binary & 4)) { continue; } } $members[$row['id_member']] = array('id' => $row['id_member'], 'groups' => array_merge(explode(',', $row['additional_groups']), array($row['id_group'])), 'language' => $row['lngfile'], 'email' => $row['email_address'], 'name' => $row['real_name']); } $db->free_result($request); // Get the mailing stuff. require_once SUBSDIR . '/Mail.subs.php'; // Need the below for loadLanguage to work! loadEssentialThemeData(); $current_language = ''; // Finally, loop through each member, work out what they can do, and send it. foreach ($members as $id => $member) { $emailbody = ''; // Load the language file as required. if (empty($current_language) || $current_language != $member['language']) { $current_language = loadLanguage('EmailTemplates', $member['language'], false); } // Loop through each notice... foreach ($notices as $board => $notice) { $access = false; // Can they mod in this board? if (isset($mods[$id][$board])) { $access = true; } // Do the group check... if (!$access && isset($perms[$profiles[$board]]['add'])) { // They can access?! if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) { $access = true; } // If they have deny rights don't consider them! if (isset($perms[$profiles[$board]]['deny'])) { if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups'])) { $access = false; } } } // Finally, fix it for admins! if (in_array(1, $member['groups'])) { $access = true; } // If they can't access it then give it a break! if (!$access) { continue; } foreach ($notice as $type => $items) { // Build up the top of this section. $emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" . '------------------------------------------------------' . "\n"; foreach ($items as $item) { $emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n"; } $emailbody .= "\n"; } } if ($emailbody == '') { continue; } $replacements = array('REALNAME' => $member['name'], 'BODY' => $emailbody); $emaildata = loadEmailTemplate('scheduled_approval', $replacements, $current_language); // Send the actual email. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 2); } // All went well! return true; }
/** * Report for showing all the forum staff members - quite a feat! * functions ending with "Report" are responsible for generating data * for reporting. * they are all called from action_index. * never access the context directly, but use the data handling * functions to do so. */ public function action_staff() { global $txt; require_once SUBSDIR . '/Members.subs.php'; require_once SUBSDIR . '/Boards.subs.php'; require_once SUBSDIR . '/Membergroups.subs.php'; // Fetch all the board names. $boards = fetchBoardsInfo('all'); $moderators = allBoardModerators(true); $boards_moderated = array(); foreach ($moderators as $id_member => $rows) { foreach ($rows as $row) { $boards_moderated[$id_member][] = $row['id_board']; } } // Get a list of global moderators (i.e. members with moderation powers). $global_mods = array_intersect(membersAllowedTo('moderate_board', 0), membersAllowedTo('approve_posts', 0), membersAllowedTo('remove_any', 0), membersAllowedTo('modify_any', 0)); // How about anyone else who is special? $allStaff = array_merge(membersAllowedTo('admin_forum'), membersAllowedTo('manage_membergroups'), membersAllowedTo('manage_permissions'), array_keys($moderators), $global_mods); // Make sure everyone is there once - no admin less important than any other! $allStaff = array_unique($allStaff); // This is a bit of a cop out - but we're protecting their forum, really! if (count($allStaff) > 300) { fatal_lang_error('report_error_too_many_staff'); } // Get all the possible membergroups! $all_groups = getBasicMembergroupData(array('all'), array(), null, false); $groups = array(0 => $txt['full_member']); foreach ($all_groups as $row) { $groups[$row['id']] = empty($row['online_color']) ? $row['name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['name'] . '</span>'; } // All the fields we'll show. $staffSettings = array('position' => $txt['report_staff_position'], 'moderates' => $txt['report_staff_moderates'], 'posts' => $txt['report_staff_posts'], 'last_login' => $txt['report_staff_last_login']); // Do it in columns, it's just easier. setKeys('cols'); // Get the latest activated member's display name. $result = getBasicMemberData($allStaff, array('moderation' => true, 'sort' => 'real_name')); foreach ($result as $row) { // Each member gets their own table!. newTable($row['real_name'], '', 'left', 'auto', 'left', 200, 'center'); // First off, add in the side key. addData($staffSettings); // Create the main data array. $staffData = array('position' => isset($groups[$row['id_group']]) ? $groups[$row['id_group']] : $groups[0], 'posts' => $row['posts'], 'last_login' => standardTime($row['last_login']), 'moderates' => array()); // What do they moderate? if (in_array($row['id_member'], $global_mods)) { $staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>'; } elseif (isset($boards_moderated[$row['id_member']])) { // Get the names foreach ($boards_moderated[$row['id_member']] as $board) { if (isset($boards[$board])) { $staffData['moderates'][] = $boards[$board]['name']; } } $staffData['moderates'] = implode(', ', $staffData['moderates']); } else { $staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>'; } // Next add the main data. addData($staffData); } }