/**
     * This is the admin settings page for search engines.
     */
    public function action_engineSettings_display()
    {
        global $context, $txt, $scripturl;
        // Initialize the form
        $this->_initEngineSettingsForm();
        $config_vars = $this->_engineSettings->settings();
        // Set up a message.
        $context['settings_message'] = sprintf($txt['spider_settings_desc'], $scripturl . '?action=admin;area=logs;sa=pruning;' . $context['session_var'] . '=' . $context['session_id']);
        require_once SUBSDIR . '/SearchEngines.subs.php';
        require_once SUBSDIR . '/Membergroups.subs.php';
        $groups = getBasicMembergroupData(array('globalmod', 'postgroups', 'protected', 'member'));
        foreach ($groups as $row) {
            $config_vars['spider_group'][2][$row['id']] = $row['name'];
        }
        // Make sure it's valid - note that regular members are given id_group = 1 which is reversed in Load.php - no admins here!
        if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) {
            $_POST['spider_group'] = 0;
        }
        // We'll want this for our easy save.
        require_once SUBSDIR . '/SettingsForm.class.php';
        // Setup the template.
        $context['page_title'] = $txt['settings'];
        $context['sub_template'] = 'show_settings';
        // Are we saving them - are we??
        if (isset($_GET['save'])) {
            // security checks
            checkSession();
            // notify the interested addons or integrations
            call_integration_hook('integrate_save_search_engine_settings');
            // save the results!
            Settings_Form::save_db($config_vars);
            // make sure to rebuild the cache with updated results
            recacheSpiderNames();
            // We're done with this.
            redirectexit('action=admin;area=sengines;sa=settings');
        }
        // Set up some details for the template.
        $context['post_url'] = $scripturl . '?action=admin;area=sengines;save;sa=settings';
        $context['settings_title'] = $txt['settings'];
        // Do some javascript.
        $javascript_function = '
			function disableFields()
			{
				disabledState = document.getElementById(\'spider_mode\').value == 0;';
        foreach ($config_vars as $variable) {
            if ($variable[1] != 'spider_mode') {
                $javascript_function .= '
				if (document.getElementById(\'' . $variable[1] . '\'))
					document.getElementById(\'' . $variable[1] . '\').disabled = disabledState;';
            }
        }
        $javascript_function .= '
			}
			disableFields();';
        addInlineJavascript($javascript_function, true);
        // Prepare the settings...
        Settings_Form::prepare_db($config_vars);
    }
 /**
  * This function allows a user to select the membergroups to send their mailing to.
  *
  * What it does:
  * - Called by ?action=admin;area=news;sa=mailingmembers.
  * - Requires the send_mail permission.
  * - Form is submitted to ?action=admin;area=news;mailingcompose.
  *
  * @uses the ManageNews template and email_members sub template.
  */
 public function action_mailingmembers()
 {
     global $txt, $context;
     require_once SUBSDIR . '/Membergroups.subs.php';
     require_once SUBSDIR . '/News.subs.php';
     // Setup the template
     $context['page_title'] = $txt['admin_newsletters'];
     $context['sub_template'] = 'email_members';
     loadJavascriptFile('suggest.js', array('defer' => true));
     // We need group data, including which groups we have and who is in them
     $allgroups = getBasicMembergroupData(array('all'), array(), null, true);
     $groups = $allgroups['groups'];
     // All of the members in post based and member based groups
     $pg = array();
     foreach ($allgroups['postgroups'] as $postgroup) {
         $pg[] = $postgroup['id'];
     }
     $mg = array();
     foreach ($allgroups['membergroups'] as $membergroup) {
         $mg[] = $membergroup['id'];
     }
     // How many are in each group
     $mem_groups = membersInGroups($pg, $mg, true, true);
     foreach ($mem_groups as $id_group => $member_count) {
         if (isset($groups[$id_group]['member_count'])) {
             $groups[$id_group]['member_count'] += $member_count;
         } else {
             $groups[$id_group]['member_count'] = $member_count;
         }
     }
     // Generate the include and exclude group select lists for the template
     foreach ($groups as $group) {
         $groups[$group['id']]['status'] = 'on';
         $groups[$group['id']]['is_postgroup'] = in_array($group['id'], $pg);
     }
     $context['groups'] = array('select_group' => $txt['admin_newsletters_select_groups'], 'member_groups' => $groups);
     foreach ($groups as $group) {
         $groups[$group['id']]['status'] = 'off';
     }
     $context['exclude_groups'] = array('select_group' => $txt['admin_newsletters_exclude_groups'], 'member_groups' => $groups);
     // Needed if for the PM option in the mail to all
     $context['can_send_pm'] = allowedTo('pm_send');
 }
 protected function populateGroupList($selected_groups)
 {
     global $txt;
     require_once SUBSDIR . '/Membergroups.subs.php';
     loadTemplate('GenericHelpers');
     // We need group data, including which groups we have and who is in them
     $allgroups = getBasicMembergroupData(array('all'), array(), null, true);
     $groups = $allgroups['groups'];
     $groups[-1] = array('id' => -1, 'name' => $txt['guests'], 'member_count' => 0);
     ksort($groups);
     // All of the members in post based and member based groups
     $pg = array();
     foreach ($allgroups['postgroups'] as $postgroup) {
         $pg[] = $postgroup['id'];
     }
     $mg = array();
     foreach ($allgroups['membergroups'] as $membergroup) {
         $mg[] = $membergroup['id'];
     }
     // How many are in each group
     $mem_groups = membersInGroups($pg, $mg, true, true);
     foreach ($mem_groups as $id_group => $member_count) {
         if (isset($groups[$id_group]['member_count'])) {
             $groups[$id_group]['member_count'] += $member_count;
         } else {
             $groups[$id_group]['member_count'] = $member_count;
         }
     }
     foreach ($groups as $group) {
         $groups[$group['id']]['status'] = in_array($group['id'], $selected_groups) ? 'on' : 'off';
         $groups[$group['id']]['is_postgroup'] = in_array($group['id'], $pg);
     }
     return array('select_group' => $txt['dismissnotices_groups_show_notice'], 'member_groups' => $groups);
 }
Example #4
0
 /**
  * Adding, editing and deleting subscriptions.
  *
  * - Accessed from ?action=admin;area=paidsubscribe;sa=modify.
  */
 public function action_modify()
 {
     global $context, $txt;
     require_once SUBSDIR . '/PaidSubscriptions.subs.php';
     $context['sub_id'] = isset($_REQUEST['sid']) ? (int) $_REQUEST['sid'] : 0;
     $context['action_type'] = $context['sub_id'] ? isset($_REQUEST['delete']) ? 'delete' : 'edit' : 'add';
     // Setup the template.
     $context['sub_template'] = $context['action_type'] == 'delete' ? 'delete_subscription' : 'modify_subscription';
     $context['page_title'] = $txt['paid_' . $context['action_type'] . '_subscription'];
     // Delete it?
     if (isset($_POST['delete_confirm']) && isset($_REQUEST['delete'])) {
         checkSession();
         validateToken('admin-pmsd');
         deleteSubscription($context['sub_id']);
         call_integration_hook('integrate_delete_subscription', array($context['sub_id']));
         redirectexit('action=admin;area=paidsubscribe;view');
     }
     // Saving?
     if (isset($_POST['save'])) {
         checkSession();
         validateToken('admin-pms');
         // Some cleaning...
         $isActive = isset($_POST['active']) ? 1 : 0;
         $isRepeatable = isset($_POST['repeatable']) ? 1 : 0;
         $allowpartial = isset($_POST['allow_partial']) ? 1 : 0;
         $reminder = isset($_POST['reminder']) ? (int) $_POST['reminder'] : 0;
         $emailComplete = strlen($_POST['emailcomplete']) > 10 ? trim($_POST['emailcomplete']) : '';
         // Is this a fixed one?
         if ($_POST['duration_type'] == 'fixed') {
             // Clean the span.
             $span = $_POST['span_value'] . $_POST['span_unit'];
             // Sort out the cost.
             $cost = array('fixed' => sprintf('%01.2f', strtr($_POST['cost'], ',', '.')));
             // There needs to be something.
             if (empty($_POST['span_value']) || empty($_POST['cost'])) {
                 fatal_lang_error('paid_no_cost_value');
             }
         } else {
             $span = 'F';
             $cost = array('day' => sprintf('%01.2f', strtr($_POST['cost_day'], ',', '.')), 'week' => sprintf('%01.2f', strtr($_POST['cost_week'], ',', '.')), 'month' => sprintf('%01.2f', strtr($_POST['cost_month'], ',', '.')), 'year' => sprintf('%01.2f', strtr($_POST['cost_year'], ',', '.')));
             if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year'])) {
                 fatal_lang_error('paid_all_freq_blank');
             }
         }
         $cost = serialize($cost);
         // Yep, time to do additional groups.
         $addgroups = array();
         if (!empty($_POST['addgroup'])) {
             foreach ($_POST['addgroup'] as $id => $dummy) {
                 $addgroups[] = (int) $id;
             }
         }
         $addgroups = implode(',', $addgroups);
         // Is it new?!
         if ($context['action_type'] == 'add') {
             $insert = array('name' => $_POST['name'], 'desc' => $_POST['desc'], 'isActive' => $isActive, 'span' => $span, 'cost' => $cost, 'prim_group' => $_POST['prim_group'], 'addgroups' => $addgroups, 'isRepeatable' => $isRepeatable, 'allowpartial' => $allowpartial, 'emailComplete' => $emailComplete, 'reminder' => $reminder);
             $sub_id = insertSubscription($insert);
         } else {
             $ignore_active = countActiveSubscriptions($context['sub_id']);
             $update = array('is_active' => $isActive, 'id_group' => !empty($_POST['prim_group']) ? $_POST['prim_group'] : 0, 'repeatable' => $isRepeatable, 'allow_partial' => $allowpartial, 'reminder' => $reminder, 'current_subscription' => $context['sub_id'], 'name' => $_POST['name'], 'desc' => $_POST['desc'], 'length' => $span, 'cost' => $cost, 'additional_groups' => !empty($addgroups) ? $addgroups : '', 'email_complete' => $emailComplete);
             updateSubscription($update, $ignore_active);
         }
         call_integration_hook('integrate_save_subscription', array($context['action_type'] == 'add' ? $sub_id : $context['sub_id'], $_POST['name'], $_POST['desc'], $isActive, $span, $cost, $_POST['prim_group'], $addgroups, $isRepeatable, $allowpartial, $emailComplete, $reminder));
         redirectexit('action=admin;area=paidsubscribe;view');
     }
     // Defaults.
     if ($context['action_type'] == 'add') {
         $context['sub'] = array('name' => '', 'desc' => '', 'cost' => array('fixed' => 0), 'span' => array('value' => '', 'unit' => 'D'), 'prim_group' => 0, 'add_groups' => array(), 'active' => 1, 'repeatable' => 1, 'allow_partial' => 0, 'duration' => 'fixed', 'email_complete' => '', 'reminder' => 0);
     } else {
         $context['sub'] = getSubscriptionDetails($context['sub_id']);
         // Does this have members who are active?
         $context['disable_groups'] = countActiveSubscriptions($context['sub_id']);
     }
     // Load up all the groups.
     require_once SUBSDIR . '/Membergroups.subs.php';
     $context['groups'] = getBasicMembergroupData(array('permission'));
     // This always happens.
     createToken($context['action_type'] == 'delete' ? 'admin-pmsd' : 'admin-pms');
 }
 /**
  * Search the member list, using one or more criteria.
  *
  * What it does:
  * - Called by ?action=admin;area=viewmembers;sa=search.
  * - Requires the moderate_forum permission.
  * - form is submitted to action=admin;area=viewmembers;sa=query.
  *
  * @uses the search_members sub template of the ManageMembers template.
  */
 public function action_search()
 {
     global $context, $txt;
     // Get a list of all the membergroups and postgroups that can be selected.
     require_once SUBSDIR . '/Membergroups.subs.php';
     $groups = getBasicMembergroupData(array(), array('moderator'), null, true);
     $context['membergroups'] = $groups['membergroups'];
     $context['postgroups'] = $groups['postgroups'];
     $context['page_title'] = $txt['admin_members'];
     $context['sub_template'] = 'search_members';
     unset($groups);
 }
Example #6
0
 /**
  * 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);
     }
 }
 /**
  * This function handles adding a membergroup and setting some initial properties.
  *
  * What it does:
  * -Called by ?action=admin;area=membergroups;sa=add.
  * -It requires the manage_membergroups permission.
  * -Allows to use a predefined permission profile or copy one from another group.
  * -Redirects to action=admin;area=membergroups;sa=edit;group=x.
  *
  * @uses the new_group sub template of ManageMembergroups.
  */
 public function action_add()
 {
     global $context, $txt, $modSettings;
     require_once SUBSDIR . '/Membergroups.subs.php';
     // A form was submitted, we can start adding.
     if (isset($_POST['group_name']) && trim($_POST['group_name']) != '') {
         checkSession();
         validateToken('admin-mmg');
         $postCountBasedGroup = isset($_POST['min_posts']) && (!isset($_POST['postgroup_based']) || !empty($_POST['postgroup_based']));
         $_POST['group_type'] = !isset($_POST['group_type']) || $_POST['group_type'] < 0 || $_POST['group_type'] > 3 || $_POST['group_type'] == 1 && !allowedTo('admin_forum') ? 0 : (int) $_POST['group_type'];
         // @todo Check for members with same name too?
         // Don't allow copying of a real priviledged person!
         require_once SUBSDIR . '/Permission.subs.php';
         loadIllegalPermissions();
         $id_group = getMaxGroupID() + 1;
         $minposts = !empty($_POST['min_posts']) ? (int) $_POST['min_posts'] : '-1';
         addMembergroup($id_group, $_POST['group_name'], $minposts, $_POST['group_type']);
         call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup));
         // Update the post groups now, if this is a post group!
         if (isset($_POST['min_posts'])) {
             updateStats('postgroups');
         }
         // You cannot set permissions for post groups if they are disabled.
         if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) {
             $_POST['perm_type'] = '';
         }
         if ($_POST['perm_type'] == 'predefined') {
             // Set default permission level.
             require_once SUBSDIR . '/ManagePermissions.subs.php';
             setPermissionLevel($_POST['level'], $id_group, null);
         } elseif ($_POST['perm_type'] == 'copy' || $_POST['perm_type'] == 'inherit') {
             $copy_id = $_POST['perm_type'] == 'copy' ? (int) $_POST['copyperm'] : (int) $_POST['inheritperm'];
             // Are you a powerful admin?
             if (!allowedTo('admin_forum')) {
                 $copy_type = membergroupById($copy_id);
                 // Protected groups are... well, protected!
                 if ($copy_type['group_type'] == 1) {
                     fatal_lang_error('membergroup_does_not_exist');
                 }
             }
             // Don't allow copying of a real priviledged person!
             require_once SUBSDIR . '/Permission.subs.php';
             loadIllegalPermissions();
             copyPermissions($id_group, $copy_id, $context['illegal_permissions']);
             copyBoardPermissions($id_group, $copy_id);
             // Also get some membergroup information if we're copying and not copying from guests...
             if ($copy_id > 0 && $_POST['perm_type'] == 'copy') {
                 updateCopiedGroup($id_group, $copy_id);
             } elseif ($_POST['perm_type'] == 'inherit') {
                 updateInheritedGroup($id_group, $copy_id);
             }
         }
         // Make sure all boards selected are stored in a proper array.
         $changed_boards = array();
         $accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
         $changed_boards['allow'] = array();
         $changed_boards['deny'] = array();
         $changed_boards['ignore'] = array();
         foreach ($accesses as $group_id => $action) {
             $changed_boards[$action][] = (int) $group_id;
         }
         foreach (array('allow', 'deny') as $board_action) {
             // Only do this if they have special access requirements.
             if (!empty($changed_boards[$board_action])) {
                 assignGroupToBoards($id_group, $changed_boards, $board_action);
             }
         }
         // If this is joinable then set it to show group membership in people's profiles.
         if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) {
             updateSettings(array('show_group_membership' => 1));
         }
         // Rebuild the group cache.
         updateSettings(array('settings_updated' => time()));
         // We did it.
         logAction('add_group', array('group' => $_POST['group_name']), 'admin');
         // Go change some more settings.
         redirectexit('action=admin;area=membergroups;sa=edit;group=' . $id_group);
     }
     // Just show the 'add membergroup' screen.
     $context['page_title'] = $txt['membergroups_new_group'];
     $context['sub_template'] = 'new_group';
     $context['post_group'] = isset($_REQUEST['postgroup']);
     $context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
     $context['allow_protected'] = allowedTo('admin_forum');
     if (!empty($modSettings['deny_boards_access'])) {
         loadLanguage('ManagePermissions');
     }
     $context['groups'] = getBasicMembergroupData(array('globalmod'), array(), 'min_posts, id_group != {int:global_mod_group}, group_name');
     require_once SUBSDIR . '/Boards.subs.php';
     $context += getBoardList();
     // Include a list of boards per category for easy toggling.
     foreach ($context['categories'] as $category) {
         $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
     }
     createToken('admin-mmg');
 }
 /**
  * Supporting function for the members maintenance area.
  */
 public function action_members()
 {
     global $context, $txt;
     require_once SUBSDIR . '/Membergroups.subs.php';
     // Get all membergroups - for deleting members and the like.
     $context['membergroups'] = getBasicMembergroupData(array('all'));
     // Show that we completed this action
     if (isset($_REQUEST['done']) && $_REQUEST['done'] == 'recountposts') {
         $context['maintenance_finished'] = array('errors' => array(sprintf($txt['maintain_done'], $txt['maintain_recountposts'])));
     }
     loadJavascriptFile('suggest.js');
     // Set up the sub-template
     $context['sub_template'] = 'maintain_members';
 }
 /**
  * This function allows the admin to register a new member by hand.
  *
  * - It also allows assigning a primary group to the member being registered.
  * - Accessed by ?action=admin;area=regcenter;sa=register
  * - Requires the moderate_forum permission.
  *
  * @uses Register template, admin_register sub-template.
  */
 public function action_register()
 {
     global $txt, $context, $scripturl, $user_info;
     if (!empty($_POST['regSubmit'])) {
         checkSession();
         validateToken('admin-regc');
         foreach ($_POST as $key => $dummy) {
             if (!is_array($_POST[$key])) {
                 $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
             }
         }
         $regOptions = array('interface' => 'admin', 'username' => $_POST['user'], 'email' => $_POST['email'], 'password' => $_POST['password'], 'password_check' => $_POST['password'], 'check_reserved_name' => true, 'check_password_strength' => true, 'check_email_ban' => false, 'send_welcome_email' => isset($_POST['emailPassword']) || empty($_POST['password']), 'require' => isset($_POST['emailActivate']) ? 'activation' : 'nothing', 'memberGroup' => empty($_POST['group']) || !allowedTo('manage_membergroups') ? 0 : (int) $_POST['group']);
         require_once SUBSDIR . '/Members.subs.php';
         $reg_errors = Error_Context::context('register', 0);
         $memberID = registerMember($regOptions, 'register');
         // If there are "important" errors and you are not an admin: log the first error
         // Otherwise grab all of them and don't log anything
         $error_severity = $reg_errors->hasErrors(1) && !$user_info['is_admin'] ? 1 : null;
         foreach ($reg_errors->prepareErrors($error_severity) as $error) {
             fatal_error($error, $error_severity === null ? false : 'general');
         }
         if (!empty($memberID)) {
             $context['new_member'] = array('id' => $memberID, 'name' => $_POST['user'], 'href' => $scripturl . '?action=profile;u=' . $memberID, 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $memberID . '">' . $_POST['user'] . '</a>');
             $context['registration_done'] = sprintf($txt['admin_register_done'], $context['new_member']['link']);
         }
     }
     // Load the assignable member groups.
     if (allowedTo('manage_membergroups')) {
         require_once SUBSDIR . '/Membergroups.subs.php';
         if (allowedTo('admin_forum')) {
             $includes = array('admin', 'globalmod', 'member');
         } else {
             $includes = array('globalmod', 'member', 'custom');
         }
         $groups = array();
         $membergroups = getBasicMembergroupData($includes, array('hidden', 'protected'));
         foreach ($membergroups as $membergroup) {
             $groups[$membergroup['id']] = $membergroup['name'];
         }
         $context['member_groups'] = $groups;
     } else {
         $context['member_groups'] = array();
     }
     // Basic stuff.
     addInlineJavascript('disableAutoComplete();', true);
     $context['sub_template'] = 'admin_register';
     $context['page_title'] = $txt['registration_center'];
     createToken('admin-regc');
 }