/** * Display the options a user can configure for this extension * * @return null * @access public */ public function display_options() { // Create a form key for preventing CSRF attacks $form_key = 'login_redirect'; add_form_key($form_key); // Is the form being submitted if ($this->request->is_set_post('submit')) { // Is the submitted form is valid if (!check_form_key($form_key)) { trigger_error($this->user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); } // Check that the entered topics are valid $this->topic_valid($this->request->variable('redirect_announce_topic_id', ''), $this->user->lang('INVALID_ANNOUNCEMENT_TOPIC')); $this->topic_valid($this->request->variable('redirect_welcome_topic_id', ''), $this->user->lang('INVALID_WELCOME_TOPIC')); $this->topic_valid($this->request->variable('redirect_group_topic_id', ''), $this->user->lang('INVALID_GROUP_TOPIC')); // If no errors, process the form data // Set the options the user configured $this->set_options(); // Add option settings change action to the admin log $phpbb_log = $this->container->get('log'); $phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_LOGIN_REDIRECT'); // Option settings have been updated and logged // Confirm this to the user and provide link back to previous page trigger_error($this->user->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); } // Set output vars for display in the template $this->template->assign_vars(array('REDIRECT_ANNOUNCE' => isset($this->config['redirect_announce']) ? $this->config['redirect_announce'] : '', 'REDIRECT_ANNOUNCE_PRIORITY' => isset($this->config['redirect_announce_priority']) ? $this->config['redirect_announce_priority'] : '', 'REDIRECT_ANNOUNCE_REFRESH' => isset($this->config['redirect_announce_refresh']) ? $this->config['redirect_announce_refresh'] : '', 'REDIRECT_ANNOUNCE_TOPIC_ID' => isset($this->config['redirect_announce_topic_id']) ? $this->config['redirect_announce_topic_id'] : '', 'REDIRECT_ANY_ANNOUNCE' => isset($this->config['redirect_any_announce']) ? $this->config['redirect_any_announce'] : '', 'REDIRECT_ENABLED' => isset($this->config['redirect_enabled']) ? $this->config['redirect_enabled'] : '', 'REDIRECT_GROUP' => isset($this->config['redirect_group']) ? $this->config['redirect_group'] : '', 'REDIRECT_GROUP_ALL' => isset($this->config['redirect_group_all']) ? $this->config['redirect_group_all'] : '', 'REDIRECT_GROUP_REFRESH' => isset($this->config['redirect_group_refresh']) ? $this->config['redirect_group_refresh'] : '', 'REDIRECT_GROUP_TOPIC_ID' => isset($this->config['redirect_group_topic_id']) ? $this->config['redirect_group_topic_id'] : '', 'REDIRECT_WELCOME' => isset($this->config['redirect_welcome']) ? $this->config['redirect_welcome'] : '', 'REDIRECT_WELCOME_REFRESH' => isset($this->config['redirect_welcome_refresh']) ? $this->config['redirect_welcome_refresh'] : '', 'REDIRECT_WELCOME_TOPIC_ID' => isset($this->config['redirect_welcome_topic_id']) ? $this->config['redirect_welcome_topic_id'] : '', 'S_REDIRECT_GROUP_OPTIONS' => group_select_options($this->config['redirect_group_id'], false, false), 'U_ACTION' => $this->u_action)); }
/** * Display the general settings a user can configure for this extension * * @return null * @access public */ public function display_settings() { // Define the name of the form for use as a form key add_form_key('ppde_settings'); // Create an array to collect errors that will be output to the user $errors = array(); $this->submit_settings(); // Set output vars for display in the template $this->template->assign_vars(array('S_ERROR' => $this->check_config(sizeof($errors)), 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'U_ACTION' => $this->u_action, 'PPDE_ACCOUNT_ID' => $this->check_config($this->config['ppde_account_id'], 'string', ''), 'PPDE_DEFAULT_CURRENCY' => $this->container->get('skouat.ppde.controller')->build_currency_select_menu($this->config['ppde_default_currency']), 'PPDE_DEFAULT_VALUE' => $this->check_config($this->config['ppde_default_value'], 'integer', 0), 'PPDE_DROPBOX_VALUE' => $this->check_config($this->config['ppde_dropbox_value'], 'string', '1,2,3,4,5,10,20,25,50,100'), 'S_PPDE_DROPBOX_ENABLE' => $this->check_config($this->config['ppde_dropbox_enable']), 'S_PPDE_ENABLE' => $this->check_config($this->config['ppde_enable']), 'S_PPDE_HEADER_LINK' => $this->check_config($this->config['ppde_header_link']), 'S_PPDE_IPN_AG_ENABLE' => $this->check_config($this->config['ppde_ipn_autogroup_enable']), 'S_PPDE_IPN_AG_GROUP_AS_DEFAULT' => $this->check_config($this->config['ppde_ipn_group_as_default']), 'S_PPDE_IPN_ENABLE' => $this->check_config($this->config['ppde_ipn_enable']), 'S_PPDE_IPN_GROUP_OPTIONS' => group_select_options($this->config['ppde_ipn_group_id']), 'S_PPDE_IPN_LOGGING' => $this->check_config($this->config['ppde_ipn_logging']), 'PPDE_SANDBOX_ADDRESS' => $this->check_config($this->config['ppde_sandbox_address'], 'string', ''), 'S_PPDE_SANDBOX_ENABLE' => $this->check_config($this->config['ppde_sandbox_enable']), 'S_PPDE_SANDBOX_FOUNDER_ENABLE' => $this->check_config($this->config['ppde_sandbox_founder_enable']), 'PPDE_RAISED' => $this->check_config($this->config['ppde_raised'], 'float', 0), 'PPDE_GOAL' => $this->check_config($this->config['ppde_goal'], 'float', 0), 'PPDE_USED' => $this->check_config($this->config['ppde_used'], 'float', 0), 'S_PPDE_STATS_INDEX_ENABLE' => $this->check_config($this->config['ppde_stats_index_enable']), 'S_PPDE_RAISED_ENABLE' => $this->check_config($this->config['ppde_raised_enable']), 'S_PPDE_GOAL_ENABLE' => $this->check_config($this->config['ppde_goal_enable']), 'S_PPDE_USED_ENABLE' => $this->check_config($this->config['ppde_used_enable']))); }
function main($id, $mode) { global $user, $template, $phpbb_root_path, $phpbb_admin_path, $table_prefix, $db; global $phpbb_container; $controller = $phpbb_container->get('alg.adminnotifications.adminnotifications_handler'); $this->tpl_name = 'acp_adminnotifications'; $this->page_title = 'ACP_ADMINNOTIFICATIONS_SETTINGS'; $user->add_lang('acp/permissions'); $form_key = 'acp_adminnotifications'; add_form_key($form_key); $sql = "SELECT * from " . $table_prefix . "adminnotifications ORDER BY create_time DESC"; $result = $db->sql_query($sql); if (is_array($result) || is_object($result)) { foreach ($result as $row) { $template->assign_block_vars('notysaved', array('NOTY_ID' => $row['noty_id'], 'NOTY_TITLE' => $row['noty_title'], 'NOTY_CONTENT' => $row['noty_content'], 'NOTY_TOOLTIP' => $controller->character_limit($row['noty_content'], 60), 'CREATE_TIME' => $row['create_time'] ? $user->format_date($row['create_time'], "d/m/Y H:i") : 0, 'PARSE_TYPE' => $row['parse_type'])); } $db->sql_freeresult($result); } $exclude_guests = array(); $exclude_ids[] = acp_adminnotifications_module::GUESTS; $exclude_ids[] = acp_adminnotifications_module::BOTS; $template->assign_vars(array('S_ADMINNOTIFICATIONS_PAGE' => true, 'S_GROUP_OPTIONS' => group_select_options(false, $exclude_ids, false), 'U_ADMINNOTIFICATIONS_PATH' => './../adminnotifications/')); }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; $user->add_lang('acp/email'); $this->tpl_name = 'acp_email'; $this->page_title = 'ACP_MASS_EMAIL'; $form_key = 'acp_email'; add_form_key($form_key); // Set some vars $submit = isset($_POST['submit']) ? true : false; $error = array(); $usernames = request_var('usernames', '', true); $group_id = request_var('g', 0); $subject = utf8_normalize_nfc(request_var('subject', '', true)); $message = utf8_normalize_nfc(request_var('message', '', true)); // Do the job ... if ($submit) { // Error checking needs to go here ... if no subject and/or no message then skip // over the send and return to the form $use_queue = isset($_POST['send_immediately']) ? false : true; $priority = request_var('mail_priority_flag', MAIL_NORMAL_PRIORITY); if (!check_form_key($form_key)) { $error[] = $user->lang['FORM_INVALID']; } if (!$subject) { $error[] = $user->lang['NO_EMAIL_SUBJECT']; } if (!$message) { $error[] = $user->lang['NO_EMAIL_MESSAGE']; } if (!sizeof($error)) { if ($usernames) { // If giving usernames the admin is able to email inactive users too... $sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang FROM ' . USERS_TABLE . ' WHERE ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', explode("\n", $usernames))) . ' AND user_allow_massemail = 1 ORDER BY user_lang, user_notify_type'; // , SUBSTRING(user_email FROM INSTR(user_email, '@')) } else { if ($group_id) { $sql_ary = array('SELECT' => 'u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type', 'FROM' => array(USERS_TABLE => 'u', USER_GROUP_TABLE => 'ug'), 'WHERE' => 'ug.group_id = ' . $group_id . ' AND ug.user_pending = 0 AND u.user_id = ug.user_id AND u.user_allow_massemail = 1 AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')', 'ORDER_BY' => 'u.user_lang, u.user_notify_type'); } else { $sql_ary = array('SELECT' => 'u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'u.user_allow_massemail = 1 AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')', 'ORDER_BY' => 'u.user_lang, u.user_notify_type'); } // Mail banned or not if (!isset($_REQUEST['mail_banned_flag'])) { $sql_ary['WHERE'] .= ' AND (b.ban_id IS NULL OR b.ban_exclude = 1)'; $sql_ary['LEFT_JOIN'] = array(array('FROM' => array(BANLIST_TABLE => 'b'), 'ON' => 'u.user_id = b.ban_userid')); } $sql = $db->sql_build_query('SELECT', $sql_ary); } $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); if (!$row) { $db->sql_freeresult($result); trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); } $i = $j = 0; // Send with BCC, no more than 50 recipients for one mail (to not exceed the limit) $max_chunk_size = 50; $email_list = array(); $old_lang = $row['user_lang']; $old_notify_type = $row['user_notify_type']; do { if ($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email'] || $row['user_notify_type'] == NOTIFY_IM && $row['user_jabber'] || $row['user_notify_type'] == NOTIFY_BOTH && ($row['user_email'] || $row['user_jabber'])) { if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type) { $i = 0; if (sizeof($email_list)) { $j++; } $old_lang = $row['user_lang']; $old_notify_type = $row['user_notify_type']; } $email_list[$j][$i]['lang'] = $row['user_lang']; $email_list[$j][$i]['method'] = $row['user_notify_type']; $email_list[$j][$i]['email'] = $row['user_email']; $email_list[$j][$i]['name'] = $row['username']; $email_list[$j][$i]['jabber'] = $row['user_jabber']; $i++; } } while ($row = $db->sql_fetchrow($result)); $db->sql_freeresult($result); // Send the messages include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx; include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx; $messenger = new messenger($use_queue); $errored = false; for ($i = 0, $size = sizeof($email_list); $i < $size; $i++) { $used_lang = $email_list[$i][0]['lang']; $used_method = $email_list[$i][0]['method']; for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++) { $email_row = $email_list[$i][$j]; $messenger->{sizeof($email_list[$i]) == 1 ? 'to' : 'bcc'}($email_row['email'], $email_row['name']); $messenger->im($email_row['jabber'], $email_row['name']); } $messenger->template('admin_send_email', $used_lang); $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']); $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']); $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']); $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip); $messenger->subject(htmlspecialchars_decode($subject)); $messenger->set_mail_priority($priority); $messenger->assign_vars(array('CONTACT_EMAIL' => $config['board_contact'], 'MESSAGE' => htmlspecialchars_decode($message))); if (!$messenger->send($used_method)) { $errored = true; } } unset($email_list); $messenger->save_queue(); if ($usernames) { $usernames = explode("\n", $usernames); add_log('admin', 'LOG_MASS_EMAIL', implode(', ', utf8_normalize_nfc($usernames))); } else { if ($group_id) { $group_name = get_group_name($group_id); } else { // Not great but the logging routine doesn't cope well with localising on the fly $group_name = $user->lang['ALL_USERS']; } add_log('admin', 'LOG_MASS_EMAIL', $group_name); } if (!$errored) { $message = $use_queue ? $user->lang['EMAIL_SENT_QUEUE'] : $user->lang['EMAIL_SENT']; trigger_error($message . adm_back_link($this->u_action)); } else { $message = sprintf($user->lang['EMAIL_SEND_ERROR'], '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=logs&mode=critical') . '">', '</a>'); trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING); } } } // Exclude bots and guests... $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name IN ('BOTS', 'GUESTS')"; $result = $db->sql_query($sql); $exclude = array(); while ($row = $db->sql_fetchrow($result)) { $exclude[] = $row['group_id']; } $db->sql_freeresult($result); $select_list = '<option value="0"' . (!$group_id ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>'; $select_list .= group_select_options($group_id, $exclude); $s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>'; $s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>'; $s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>'; $template->assign_vars(array('S_WARNING' => sizeof($error) ? true : false, 'WARNING_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'U_ACTION' => $this->u_action, 'S_GROUP_OPTIONS' => $select_list, 'USERNAMES' => $usernames, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=acp_email&field=usernames'), 'SUBJECT' => $subject, 'MESSAGE' => $message, 'S_PRIORITY_OPTIONS' => $s_priority_options)); }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx; global $request, $phpbb_container, $phpbb_dispatcher; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; $this->page_title = 'ACP_GROUPS_MANAGE'; $form_key = 'acp_groups'; add_form_key($form_key); if ($mode == 'position') { $this->manage_position(); return; } if (!function_exists('group_user_attributes')) { include $phpbb_root_path . 'includes/functions_user.' . $phpEx; } // Check and set some common vars $action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : $request->variable('action', '')); $group_id = $request->variable('g', 0); $mark_ary = $request->variable('mark', array(0)); $name_ary = $request->variable('usernames', '', true); $leader = $request->variable('leader', 0); $default = $request->variable('default', 0); $start = $request->variable('start', 0); $update = isset($_POST['update']) ? true : false; /** @var \phpbb\group\helper $group_helper */ $group_helper = $phpbb_container->get('group_helper'); // Clear some vars $group_row = array(); // Grab basic data for group, if group_id is set and exists if ($group_id) { $sql = 'SELECT g.*, t.teampage_position AS group_teampage FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . TEAMPAGE_TABLE . ' t ON (t.group_id = g.group_id) WHERE g.group_id = ' . $group_id; $result = $db->sql_query($sql); $group_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$group_row) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check if the user is allowed to manage this group if set to founder only. if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) { trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } } // Which page? switch ($action) { case 'approve': case 'demote': case 'promote': if (!check_form_key($form_key)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } // Approve, demote or promote $group_name = $group_helper->get_name($group_row['group_name']); $error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name); if (!$error) { switch ($action) { case 'demote': $message = 'GROUP_MODS_DEMOTED'; break; case 'promote': $message = 'GROUP_MODS_PROMOTED'; break; case 'approve': $message = 'USERS_APPROVED'; break; } trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } break; case 'default': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } else { if (empty($mark_ary)) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } } if (confirm_box(true)) { $group_name = $group_helper->get_name($group_row['group_name']); group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'set_default_on_all': if (confirm_box(true)) { $group_name = $group_helper->get_name($group_row['group_name']); $start = 0; do { $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\tORDER BY user_id"; $result = $db->sql_query_limit($sql, 200, $start); $mark_ary = array(); if ($row = $db->sql_fetchrow($result)) { do { $mark_ary[] = $row['user_id']; } while ($row = $db->sql_fetchrow($result)); group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); $start = sizeof($mark_ary) < 200 ? 0 : $start + 200; } else { $start = 0; } $db->sql_freeresult($result); } while ($start); trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'deleteusers': if (empty($mark_ary)) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } case 'delete': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } else { if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } } if (confirm_box(true)) { $error = ''; switch ($action) { case 'delete': if (!$auth->acl_get('a_groupdel')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $error = group_delete($group_id, $group_row['group_name']); break; case 'deleteusers': $group_name = $group_helper->get_name($group_row['group_name']); $error = group_user_del($group_id, $mark_ary, false, $group_name); break; } $back_link = $action == 'delete' ? $this->u_action : $this->u_action . '&action=list&g=' . $group_id; if ($error) { trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING); } $message = $action == 'delete' ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE'; trigger_error($user->lang[$message] . adm_back_link($back_link)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'addusers': if (!check_form_key($form_key)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$name_ary) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } $name_ary = array_unique(explode("\n", $name_ary)); $group_name = $group_helper->get_name($group_row['group_name']); // Add user/s to group if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row)) { trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } $message = $leader ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); break; case 'edit': case 'add': if (!function_exists('display_forums')) { include $phpbb_root_path . 'includes/functions_display.' . $phpEx; } if ($action == 'edit' && !$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($action == 'add' && !$auth->acl_get('a_groupadd')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $error = array(); $user->add_lang('ucp'); // Setup avatar data for later $avatars_enabled = false; $avatar_drivers = null; $avatar_data = null; $avatar_error = array(); if ($config['allow_avatar']) { /* @var $phpbb_avatar_manager \phpbb\avatar\manager */ $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the group_ prefix $avatar_data = \phpbb\avatar\manager::clean_row($group_row, 'group'); if (!isset($avatar_data['id'])) { $avatar_data['id'] = 'g' . $group_id; } } if ($request->is_set_post('avatar_delete')) { if (confirm_box(true)) { $avatar_data['id'] = substr($avatar_data['id'], 1); $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, GROUPS_TABLE, 'group_'); $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array('avatar_delete' => true, 'i' => $id, 'mode' => $mode, 'g' => $group_id, 'action' => $action))); } } // Did we submit? if ($update) { if (!check_form_key($form_key)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $group_name = $request->variable('group_name', '', true); $group_desc = $request->variable('group_desc', '', true); $group_type = $request->variable('group_type', GROUP_FREE); $allow_desc_bbcode = $request->variable('desc_parse_bbcode', false); $allow_desc_urls = $request->variable('desc_parse_urls', false); $allow_desc_smilies = $request->variable('desc_parse_smilies', false); $submit_ary = array('colour' => $request->variable('group_colour', ''), 'rank' => $request->variable('group_rank', 0), 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0, 'teampage' => isset($_REQUEST['group_teampage']) ? 1 : 0, 'message_limit' => $request->variable('group_message_limit', 0), 'max_recipients' => $request->variable('group_max_recipients', 0), 'founder_manage' => 0, 'skip_auth' => $request->variable('group_skip_auth', 0)); if ($user->data['user_type'] == USER_FOUNDER) { $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; } if ($config['allow_avatar']) { // Handle avatar $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) { $driver = $phpbb_avatar_manager->get_driver($driver_name); $result = $driver->process_form($request, $template, $user, $avatar_data, $avatar_error); if ($result && empty($avatar_error)) { $result['avatar_type'] = $driver_name; $submit_ary = array_merge($submit_ary, $result); } } else { $driver = $phpbb_avatar_manager->get_driver($avatar_data['avatar_type']); if ($driver) { $driver->delete($avatar_data); } // Removing the avatar $submit_ary['avatar_type'] = ''; $submit_ary['avatar'] = ''; $submit_ary['avatar_width'] = 0; $submit_ary['avatar_height'] = 0; } // Merge any avatar errors into the primary error array $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); } /* * Validate the length of "Maximum number of allowed recipients per * private message" setting. We use 16777215 as a maximum because it matches * MySQL unsigned mediumint maximum value which is the lowest amongst DBMSes * supported by phpBB3. Also validate the submitted colour value. */ $validation_checks = array('max_recipients' => array('num', false, 0, 16777215), 'colour' => array('hex_colour', true)); /** * Request group data and operate on it * * @event core.acp_manage_group_request_data * @var string action Type of the action: add|edit * @var int group_id The group id * @var array group_row Array with new group data * @var array error Array of errors, if you add errors * ensure to update the template variables * S_ERROR and ERROR_MSG to display it * @var string group_name The group name * @var string group_desc The group description * @var int group_type The group type * @var bool allow_desc_bbcode Allow bbcode in group description: true|false * @var bool allow_desc_urls Allow urls in group description: true|false * @var bool allow_desc_smilies Allow smiles in group description: true|false * @var array submit_ary Array with new group data * @var array validation_checks Array with validation data * @since 3.1.0-b5 */ $vars = array('action', 'group_id', 'group_row', 'error', 'group_name', 'group_desc', 'group_type', 'allow_desc_bbcode', 'allow_desc_urls', 'allow_desc_smilies', 'submit_ary', 'validation_checks'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_group_request_data', compact($vars))); if ($validation_error = validate_data($submit_ary, $validation_checks)) { // Replace "error" string with its real, localised form $error = array_merge($error, $validation_error); } if (!sizeof($error)) { // Only set the rank, colour, etc. if it's changed or if we're adding a new // group. This prevents existing group members being updated if no changes // were made. // However there are some attributes that need to be set everytime, // otherwise the group gets removed from the feature. $set_attributes = array('legend', 'teampage'); $group_attributes = array(); $test_variables = array('rank' => 'int', 'colour' => 'string', 'avatar' => 'string', 'avatar_type' => 'string', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', 'legend' => 'int', 'teampage' => 'int', 'message_limit' => 'int', 'max_recipients' => 'int', 'founder_manage' => 'int', 'skip_auth' => 'int'); /** * Initialise data before we display the add/edit form * * @event core.acp_manage_group_initialise_data * @var string action Type of the action: add|edit * @var int group_id The group id * @var array group_row Array with new group data * @var array error Array of errors, if you add errors * ensure to update the template variables * S_ERROR and ERROR_MSG to display it * @var string group_name The group name * @var string group_desc The group description * @var int group_type The group type * @var bool allow_desc_bbcode Allow bbcode in group description: true|false * @var bool allow_desc_urls Allow urls in group description: true|false * @var bool allow_desc_smilies Allow smiles in group description: true|false * @var array submit_ary Array with new group data * @var array test_variables Array with variables for test * @since 3.1.0-b5 */ $vars = array('action', 'group_id', 'group_row', 'error', 'group_name', 'group_desc', 'group_type', 'allow_desc_bbcode', 'allow_desc_urls', 'allow_desc_smilies', 'submit_ary', 'test_variables'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_group_initialise_data', compact($vars))); foreach ($test_variables as $test => $type) { if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test] || isset($group_attributes['group_avatar']) && strpos($test, 'avatar') === 0 || in_array($test, $set_attributes))) { settype($submit_ary[$test], $type); $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; } } if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) { $group_perm_from = $request->variable('group_perm_from', 0); // Copy permissions? // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred. // We do not limit on one auth category because this can lead to incomplete permissions being tricky to fix for the admin, roles being assigned or added non-default permissions. // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise. if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) { $sql = 'SELECT group_founder_manage FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . $group_perm_from; $result = $db->sql_query($sql); $check_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // Check the group if non-founder if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0)) { // From the mysql documentation: // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. // Due to this we stay on the safe side if we do the insertion "the manual way" // Copy permisisons from/to the acl groups table (only group_id gets changed) $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' WHERE group_id = ' . $group_perm_from; $result = $db->sql_query($sql); $groups_sql_ary = array(); while ($row = $db->sql_fetchrow($result)) { $groups_sql_ary[] = array('group_id' => (int) $group_id, 'forum_id' => (int) $row['forum_id'], 'auth_option_id' => (int) $row['auth_option_id'], 'auth_role_id' => (int) $row['auth_role_id'], 'auth_setting' => (int) $row['auth_setting']); } $db->sql_freeresult($result); // Now insert the data $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary); $auth->acl_clear_prefetch(); } } $cache->destroy('sql', array(GROUPS_TABLE, TEAMPAGE_TABLE)); $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); } } if (sizeof($error)) { $error = array_map(array(&$user, 'lang'), $error); $group_rank = $submit_ary['rank']; $group_desc_data = array('text' => $group_desc, 'allow_bbcode' => $allow_desc_bbcode, 'allow_smilies' => $allow_desc_smilies, 'allow_urls' => $allow_desc_urls); } } else { if (!$group_id) { $group_name = $request->variable('group_name', '', true); $group_desc_data = array('text' => '', 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true); $group_rank = 0; $group_type = GROUP_OPEN; } else { $group_name = $group_row['group_name']; $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']); $group_type = $group_row['group_type']; $group_rank = $group_row['group_rank']; } } $sql = 'SELECT * FROM ' . RANKS_TABLE . ' WHERE rank_special = 1 ORDER BY rank_title'; $result = $db->sql_query($sql); $rank_options = '<option value="0"' . (!$group_rank ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>'; while ($row = $db->sql_fetchrow($result)) { $selected = $group_rank && $row['rank_id'] == $group_rank ? ' selected="selected"' : ''; $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>'; } $db->sql_freeresult($result); $type_free = $group_type == GROUP_FREE ? ' checked="checked"' : ''; $type_open = $group_type == GROUP_OPEN ? ' checked="checked"' : ''; $type_closed = $group_type == GROUP_CLOSED ? ' checked="checked"' : ''; $type_hidden = $group_type == GROUP_HIDDEN ? ' checked="checked"' : ''; // Load up stuff for avatars if ($config['allow_avatar']) { $avatars_enabled = false; $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); foreach ($avatar_drivers as $current_driver) { $driver = $phpbb_avatar_manager->get_driver($current_driver); $avatars_enabled = true; $template->set_filenames(array('avatar' => $driver->get_acp_template_name())); if ($driver->prepare_form($request, $template, $user, $avatar_data, $avatar_error)) { $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); $driver_upper = strtoupper($driver_name); $template->assign_block_vars('avatar_drivers', array('L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar'))); } } } $avatar = phpbb_get_group_avatar($group_row, 'GROUP_AVATAR', true); if (isset($phpbb_avatar_manager) && !$update) { // Merge any avatar errors into the primary error array $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); } $back_link = $request->variable('back_link', ''); switch ($back_link) { case 'acp_users_groups': $u_back = append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&mode=groups&u=' . $request->variable('u', 0)); break; default: $u_back = $this->u_action; break; } $template->assign_vars(array('S_EDIT' => true, 'S_ADD_GROUP' => $action == 'add' ? true : false, 'S_GROUP_PERM' => $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth') ? true : false, 'S_INCLUDE_SWATCH' => true, 'S_ERROR' => sizeof($error) ? true : false, 'S_SPECIAL_GROUP' => $group_type == GROUP_SPECIAL ? true : false, 'S_USER_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'S_AVATARS_ENABLED' => $config['allow_avatar'] && $avatars_enabled, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'GROUP_NAME' => $group_helper->get_name($group_name), 'GROUP_INTERNAL_NAME' => $group_name, 'GROUP_DESC' => $group_desc_data['text'], 'GROUP_RECEIVE_PM' => isset($group_row['group_receive_pm']) && $group_row['group_receive_pm'] ? ' checked="checked"' : '', 'GROUP_FOUNDER_MANAGE' => isset($group_row['group_founder_manage']) && $group_row['group_founder_manage'] ? ' checked="checked"' : '', 'GROUP_LEGEND' => isset($group_row['group_legend']) && $group_row['group_legend'] ? ' checked="checked"' : '', 'GROUP_TEAMPAGE' => isset($group_row['group_teampage']) && $group_row['group_teampage'] ? ' checked="checked"' : '', 'GROUP_MESSAGE_LIMIT' => isset($group_row['group_message_limit']) ? $group_row['group_message_limit'] : 0, 'GROUP_MAX_RECIPIENTS' => isset($group_row['group_max_recipients']) ? $group_row['group_max_recipients'] : 0, 'GROUP_COLOUR' => isset($group_row['group_colour']) ? $group_row['group_colour'] : '', 'GROUP_SKIP_AUTH' => !empty($group_row['group_skip_auth']) ? ' checked="checked"' : '', 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], 'S_DESC_SMILIES_CHECKED' => $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, $user->data['user_type'] == USER_FOUNDER ? false : 0), 'AVATAR' => empty($avatar) ? '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />' : $avatar, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : '', 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, 'GROUP_FREE' => $type_free, 'GROUP_OPEN' => $type_open, 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, 'U_BACK' => $u_back, 'U_ACTION' => "{$this->u_action}&action={$action}&g={$group_id}", 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string())); /** * Modify group template data before we display the form * * @event core.acp_manage_group_display_form * @var string action Type of the action: add|edit * @var bool update Do we display the form only * or did the user press submit * @var int group_id The group id * @var array group_row Array with new group data * @var string group_name The group name * @var int group_type The group type * @var array group_desc_data The group description data * @var string group_rank The group rank * @var string rank_options The rank options * @var array error Array of errors, if you add errors * ensure to update the template variables * S_ERROR and ERROR_MSG to display it * @since 3.1.0-b5 */ $vars = array('action', 'update', 'group_id', 'group_row', 'group_desc_data', 'group_name', 'group_type', 'group_rank', 'rank_options', 'error'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_group_display_form', compact($vars))); return; break; case 'list': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } /* @var $pagination \phpbb\pagination */ $pagination = $phpbb_container->get('pagination'); $this->page_title = 'GROUP_MEMBERS'; // Grab the leaders - always, on every page... $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\tAND ug.group_leader = 1\n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $template->assign_block_vars('leader', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&action=edit&u={$row['user_id']}"), 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $db->sql_freeresult($result); // Total number of group members (non-leaders) $sql = 'SELECT COUNT(user_id) AS total_members FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\tAND group_leader = 0"; $result = $db->sql_query($sql); $total_members = (int) $db->sql_fetchfield('total_members'); $db->sql_freeresult($result); $s_action_options = ''; $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE'); foreach ($options as $option => $lang) { $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>'; } $base_url = $this->u_action . "&action={$action}&g={$group_id}"; $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_members, $config['topics_per_page'], $start); $template->assign_vars(array('S_LIST' => true, 'S_GROUP_SPECIAL' => $group_row['group_type'] == GROUP_SPECIAL ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'GROUP_NAME' => $group_helper->get_name($group_row['group_name']), 'U_ACTION' => $this->u_action . "&g={$group_id}", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=list&field=usernames'), 'U_DEFAULT_ALL' => "{$this->u_action}&action=set_default_on_all&g={$group_id}")); // Grab the members $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\tAND ug.group_leader = 0\n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $pending = false; while ($row = $db->sql_fetchrow($result)) { if ($row['user_pending'] && !$pending) { $template->assign_block_vars('member', array('S_PENDING' => true)); $pending = true; } $template->assign_block_vars('member', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&action=edit&u={$row['user_id']}"), 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $db->sql_freeresult($result); return; break; } $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_GROUP_ADD' => $auth->acl_get('a_groupadd') ? true : false)); // Get us all the groups $sql = 'SELECT g.group_id, g.group_name, g.group_type FROM ' . GROUPS_TABLE . ' g ORDER BY g.group_type ASC, g.group_name'; $result = $db->sql_query($sql); $lookup = $cached_group_data = array(); while ($row = $db->sql_fetchrow($result)) { $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : 'normal'; // used to determine what type a group is $lookup[$row['group_id']] = $type; // used for easy access to the data within a group $cached_group_data[$type][$row['group_id']] = $row; $cached_group_data[$type][$row['group_id']]['total_members'] = 0; } $db->sql_freeresult($result); // How many people are in which group? $sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id FROM ' . USER_GROUP_TABLE . ' ug WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . ' GROUP BY ug.group_id'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $type = $lookup[$row['group_id']]; $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members']; } $db->sql_freeresult($result); // The order is... normal, then special ksort($cached_group_data); foreach ($cached_group_data as $type => $row_ary) { if ($type == 'special') { $template->assign_block_vars('groups', array('S_SPECIAL' => true)); } foreach ($row_ary as $group_id => $row) { $group_name = !empty($user->lang['G_' . $row['group_name']]) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; $template->assign_block_vars('groups', array('U_LIST' => "{$this->u_action}&action=list&g={$group_id}", 'U_EDIT' => "{$this->u_action}&action=edit&g={$group_id}", 'U_DELETE' => $auth->acl_get('a_groupdel') ? "{$this->u_action}&action=delete&g={$group_id}" : '', 'S_GROUP_SPECIAL' => $row['group_type'] == GROUP_SPECIAL ? true : false, 'GROUP_NAME' => $group_name, 'TOTAL_MEMBERS' => $row['total_members'])); } } }
function main($id, $mode) { global $db, $user, $auth, $template, $phpbb_container, $request; global $config, $phpbb_root_path, $phpEx; if (!function_exists('user_get_id_name')) { include $phpbb_root_path . 'includes/functions_user.' . $phpEx; } if (!class_exists('auth_admin')) { include $phpbb_root_path . 'includes/acp/auth.' . $phpEx; } $this->permissions = $phpbb_container->get('acl.permissions'); $auth_admin = new auth_admin(); $user->add_lang('acp/permissions'); add_permission_language(); $this->tpl_name = 'acp_permissions'; // Trace has other vars if ($mode == 'trace') { $user_id = $request->variable('u', 0); $forum_id = $request->variable('f', 0); $permission = $request->variable('auth', ''); $this->tpl_name = 'permission_trace'; if ($user_id && isset($auth_admin->acl_options['id'][$permission]) && $auth->acl_get('a_viewauth')) { $this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $this->permissions->get_permission_lang($permission)); $this->permission_trace($user_id, $forum_id, $permission); return; } trigger_error('NO_MODE', E_USER_ERROR); } // Copy forum permissions if ($mode == 'setting_forum_copy') { $this->tpl_name = 'permission_forum_copy'; if ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth')) { $this->page_title = 'ACP_FORUM_PERMISSIONS_COPY'; $this->copy_forum_permissions(); return; } trigger_error('NO_MODE', E_USER_ERROR); } // Set some vars $action = $request->variable('action', array('' => 0)); $action = key($action); $action = isset($_POST['psubmit']) ? 'apply_permissions' : $action; $all_forums = $request->variable('all_forums', 0); $subforum_id = $request->variable('subforum_id', 0); $forum_id = $request->variable('forum_id', array(0)); $username = $request->variable('username', array(''), true); $usernames = $request->variable('usernames', '', true); $user_id = $request->variable('user_id', array(0)); $group_id = $request->variable('group_id', array(0)); $select_all_groups = $request->variable('select_all_groups', 0); $form_name = 'acp_permissions'; add_form_key($form_name); // If select all groups is set, we pre-build the group id array (this option is used for other screens to link to the permission settings screen) if ($select_all_groups) { // Add default groups to selection $sql_and = !$config['coppa_enable'] ? " AND group_name <> 'REGISTERED_COPPA'" : ''; $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_type = ' . GROUP_SPECIAL . "\n\t\t\t\t{$sql_and}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $group_id[] = $row['group_id']; } $db->sql_freeresult($result); } // Map usernames to ids and vice versa if ($usernames) { $username = explode("\n", $usernames); } unset($usernames); if (sizeof($username) && !sizeof($user_id)) { user_get_id_name($user_id, $username); if (!sizeof($user_id)) { trigger_error($user->lang['SELECTED_USER_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING); } } unset($username); // Build forum ids (of all forums are checked or subforum listing used) if ($all_forums) { $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' ORDER BY left_id'; $result = $db->sql_query($sql); $forum_id = array(); while ($row = $db->sql_fetchrow($result)) { $forum_id[] = (int) $row['forum_id']; } $db->sql_freeresult($result); } else { if ($subforum_id) { $forum_id = array(); foreach (get_forum_branch($subforum_id, 'children') as $row) { $forum_id[] = (int) $row['forum_id']; } } } // Define some common variables for every mode $permission_scope = strpos($mode, '_global') !== false ? 'global' : 'local'; // Showing introductionary page? if ($mode == 'intro') { $this->page_title = 'ACP_PERMISSIONS'; $template->assign_vars(array('S_INTRO' => true)); return; } switch ($mode) { case 'setting_user_global': case 'setting_group_global': $this->permission_dropdown = array('u_', 'm_', 'a_'); $permission_victim = $mode == 'setting_user_global' ? array('user') : array('group'); $this->page_title = $mode == 'setting_user_global' ? 'ACP_USERS_PERMISSIONS' : 'ACP_GROUPS_PERMISSIONS'; break; case 'setting_user_local': case 'setting_group_local': $this->permission_dropdown = array('f_', 'm_'); $permission_victim = $mode == 'setting_user_local' ? array('user', 'forums') : array('group', 'forums'); $this->page_title = $mode == 'setting_user_local' ? 'ACP_USERS_FORUM_PERMISSIONS' : 'ACP_GROUPS_FORUM_PERMISSIONS'; break; case 'setting_admin_global': case 'setting_mod_global': $this->permission_dropdown = strpos($mode, '_admin_') !== false ? array('a_') : array('m_'); $permission_victim = array('usergroup'); $this->page_title = $mode == 'setting_admin_global' ? 'ACP_ADMINISTRATORS' : 'ACP_GLOBAL_MODERATORS'; break; case 'setting_mod_local': case 'setting_forum_local': $this->permission_dropdown = $mode == 'setting_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup'); $this->page_title = $mode == 'setting_mod_local' ? 'ACP_FORUM_MODERATORS' : 'ACP_FORUM_PERMISSIONS'; break; case 'view_admin_global': case 'view_user_global': case 'view_mod_global': $this->permission_dropdown = $mode == 'view_admin_global' ? array('a_') : ($mode == 'view_user_global' ? array('u_') : array('m_')); $permission_victim = array('usergroup_view'); $this->page_title = $mode == 'view_admin_global' ? 'ACP_VIEW_ADMIN_PERMISSIONS' : ($mode == 'view_user_global' ? 'ACP_VIEW_USER_PERMISSIONS' : 'ACP_VIEW_GLOBAL_MOD_PERMISSIONS'); break; case 'view_mod_local': case 'view_forum_local': $this->permission_dropdown = $mode == 'view_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup_view'); $this->page_title = $mode == 'view_mod_local' ? 'ACP_VIEW_FORUM_MOD_PERMISSIONS' : 'ACP_VIEW_FORUM_PERMISSIONS'; break; default: trigger_error('NO_MODE', E_USER_ERROR); break; } $template->assign_vars(array('L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'])); // Get permission type $permission_type = $request->variable('type', $this->permission_dropdown[0]); if (!in_array($permission_type, $this->permission_dropdown)) { trigger_error($user->lang['WRONG_PERMISSION_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } // Handle actions if (strpos($mode, 'setting_') === 0 && $action) { switch ($action) { case 'delete': if (confirm_box(true)) { // All users/groups selected? $all_users = isset($_POST['all_users']) ? true : false; $all_groups = isset($_POST['all_groups']) ? true : false; if ($all_users || $all_groups) { $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type); if ($all_users && sizeof($items['user_ids'])) { $user_id = $items['user_ids']; } else { if ($all_groups && sizeof($items['group_ids'])) { $group_id = $items['group_ids']; } } } if (sizeof($user_id) || sizeof($group_id)) { $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id); } else { trigger_error($user->lang['NO_USER_GROUP_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); } } else { if (isset($_POST['cancel'])) { $u_redirect = $this->u_action . '&type=' . $permission_type; foreach ($forum_id as $fid) { $u_redirect .= '&forum_id[]=' . $fid; } redirect($u_redirect); } $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'action' => array($action => 1), 'user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'type' => $permission_type); if (isset($_POST['all_users'])) { $s_hidden_fields['all_users'] = 1; } if (isset($_POST['all_groups'])) { $s_hidden_fields['all_groups'] = 1; } confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); } break; case 'apply_permissions': if (!isset($_POST['setting'])) { send_status_line(403, 'Forbidden'); trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->set_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; case 'apply_all_permissions': if (!isset($_POST['setting'])) { send_status_line(403, 'Forbidden'); trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->set_all_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; } } // Go through the screens/options needed and present them in correct order foreach ($permission_victim as $victim) { switch ($victim) { case 'forum_dropdown': if (sizeof($forum_id)) { $this->check_existence('forum', $forum_id); continue 2; } $template->assign_vars(array('S_SELECT_FORUM' => true, 'S_FORUM_OPTIONS' => make_forum_select(false, false, true, false, false))); break; case 'forums': if (sizeof($forum_id)) { $this->check_existence('forum', $forum_id); continue 2; } $forum_list = make_forum_select(false, false, true, false, false, false, true); // Build forum options $s_forum_options = ''; foreach ($forum_list as $f_id => $f_row) { $s_forum_options .= '<option value="' . $f_id . '"' . ($f_row['selected'] ? ' selected="selected"' : '') . ($f_row['disabled'] ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>'; } // Build subforum options $s_subforum_options = $this->build_subforum_options($forum_list); $template->assign_vars(array('S_SELECT_FORUM' => true, 'S_FORUM_OPTIONS' => $s_forum_options, 'S_SUBFORUM_OPTIONS' => $s_subforum_options, 'S_FORUM_ALL' => true, 'S_FORUM_MULTIPLE' => true)); break; case 'user': if (sizeof($user_id)) { $this->check_existence('user', $user_id); continue 2; } $template->assign_vars(array('S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=select_victim&field=username&select_single=true'))); break; case 'group': if (sizeof($group_id)) { $this->check_existence('group', $group_id); continue 2; } $template->assign_vars(array('S_SELECT_GROUP' => true, 'S_GROUP_OPTIONS' => group_select_options(false, false, false))); break; case 'usergroup': case 'usergroup_view': $all_users = isset($_POST['all_users']) ? true : false; $all_groups = isset($_POST['all_groups']) ? true : false; if (sizeof($user_id) && !$all_users || sizeof($group_id) && !$all_groups) { if (sizeof($user_id)) { $this->check_existence('user', $user_id); } if (sizeof($group_id)) { $this->check_existence('group', $group_id); } continue 2; } // Now we check the users... because the "all"-selection is different here (all defined users/groups) $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type); if ($all_users && sizeof($items['user_ids'])) { $user_id = $items['user_ids']; continue 2; } if ($all_groups && sizeof($items['group_ids'])) { $group_id = $items['group_ids']; continue 2; } $template->assign_vars(array('S_SELECT_USERGROUP' => $victim == 'usergroup' ? true : false, 'S_SELECT_USERGROUP_VIEW' => $victim == 'usergroup_view' ? true : false, 'S_DEFINED_USER_OPTIONS' => $items['user_ids_options'], 'S_DEFINED_GROUP_OPTIONS' => $items['group_ids_options'], 'S_ADD_GROUP_OPTIONS' => group_select_options(false, $items['group_ids'], false), 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=add_user&field=username&select_single=true'))); break; } // The S_ALLOW_SELECT parameter below is a measure to lower memory usage. // If there are more than 5 forums selected the admin is not able to select all users/groups too. // We need to see if the number of forums can be increased or need to be decreased. // Setting permissions screen $s_hidden_fields = build_hidden_fields(array('user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'type' => $permission_type)); $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_VICTIM' => true, 'S_ALLOW_ALL_SELECT' => sizeof($forum_id) > 5 ? false : true, 'S_CAN_SELECT_USER' => $auth->acl_get('a_authusers') ? true : false, 'S_CAN_SELECT_GROUP' => $auth->acl_get('a_authgroups') ? true : false, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); // Let the forum names being displayed if (sizeof($forum_id)) { $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_id) . ' ORDER BY left_id ASC'; $result = $db->sql_query($sql); $forum_names = array(); while ($row = $db->sql_fetchrow($result)) { $forum_names[] = $row['forum_name']; } $db->sql_freeresult($result); $template->assign_vars(array('S_FORUM_NAMES' => sizeof($forum_names) ? true : false, 'FORUM_NAMES' => implode($user->lang['COMMA_SEPARATOR'], $forum_names))); } return; } // Setting permissions screen $s_hidden_fields = build_hidden_fields(array('user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'type' => $permission_type)); // Do not allow forum_ids being set and no other setting defined (will bog down the server too much) if (sizeof($forum_id) && !sizeof($user_id) && !sizeof($group_id)) { trigger_error($user->lang['ONLY_FORUM_DEFINED'] . adm_back_link($this->u_action), E_USER_WARNING); } $template->assign_vars(array('S_PERMISSION_DROPDOWN' => sizeof($this->permission_dropdown) > 1 ? $this->build_permission_dropdown($this->permission_dropdown, $permission_type, $permission_scope) : false, 'L_PERMISSION_TYPE' => $this->permissions->get_type_lang($permission_type), 'U_ACTION' => $this->u_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); if (strpos($mode, 'setting_') === 0) { $template->assign_vars(array('S_SETTING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('set', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_NO); $auth_admin->display_mask('set', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } else { $template->assign_vars(array('S_VIEWING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('view', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_NEVER); $auth_admin->display_mask('view', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache, $phpbb_log, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $phpbb_dispatcher; $user->add_lang('acp/email'); $this->tpl_name = 'acp_email'; $this->page_title = 'ACP_MASS_EMAIL'; $form_key = 'acp_email'; add_form_key($form_key); // Set some vars $submit = isset($_POST['submit']) ? true : false; $error = array(); $usernames = $request->variable('usernames', '', true); $usernames = !empty($usernames) ? explode("\n", $usernames) : array(); $group_id = $request->variable('g', 0); $subject = $request->variable('subject', '', true); $message = $request->variable('message', '', true); // Do the job ... if ($submit) { // Error checking needs to go here ... if no subject and/or no message then skip // over the send and return to the form $use_queue = isset($_POST['send_immediately']) ? false : true; $priority = $request->variable('mail_priority_flag', MAIL_NORMAL_PRIORITY); if (!check_form_key($form_key)) { $error[] = $user->lang['FORM_INVALID']; } if (!$subject) { $error[] = $user->lang['NO_EMAIL_SUBJECT']; } if (!$message) { $error[] = $user->lang['NO_EMAIL_MESSAGE']; } if (!sizeof($error)) { if (!empty($usernames)) { // If giving usernames the admin is able to email inactive users too... $sql_ary = array('SELECT' => 'username, user_email, user_jabber, user_notify_type, user_lang', 'FROM' => array(USERS_TABLE => ''), 'WHERE' => $db->sql_in_set('username_clean', array_map('utf8_clean_string', $usernames)) . ' AND user_allow_massemail = 1', 'ORDER_BY' => 'user_lang, user_notify_type'); } else { if ($group_id) { $sql_ary = array('SELECT' => 'u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type', 'FROM' => array(USERS_TABLE => 'u', USER_GROUP_TABLE => 'ug'), 'WHERE' => 'ug.group_id = ' . $group_id . ' AND ug.user_pending = 0 AND u.user_id = ug.user_id AND u.user_allow_massemail = 1 AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')', 'ORDER_BY' => 'u.user_lang, u.user_notify_type'); } else { $sql_ary = array('SELECT' => 'u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'u.user_allow_massemail = 1 AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')', 'ORDER_BY' => 'u.user_lang, u.user_notify_type'); } // Mail banned or not if (!isset($_REQUEST['mail_banned_flag'])) { $sql_ary['WHERE'] .= ' AND (b.ban_id IS NULL OR b.ban_exclude = 1)'; $sql_ary['LEFT_JOIN'] = array(array('FROM' => array(BANLIST_TABLE => 'b'), 'ON' => 'u.user_id = b.ban_userid')); } } /** * Modify sql query to change the list of users the email is sent to * * @event core.acp_email_modify_sql * @var array sql_ary Array which is used to build the sql query * @since 3.1.2-RC1 */ $vars = array('sql_ary'); extract($phpbb_dispatcher->trigger_event('core.acp_email_modify_sql', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); if (!$row) { $db->sql_freeresult($result); trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); } $i = $j = 0; // Send with BCC // Maximum number of bcc recipients $max_chunk_size = (int) $config['email_max_chunk_size']; $email_list = array(); $old_lang = $row['user_lang']; $old_notify_type = $row['user_notify_type']; do { if ($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email'] || $row['user_notify_type'] == NOTIFY_IM && $row['user_jabber'] || $row['user_notify_type'] == NOTIFY_BOTH && ($row['user_email'] || $row['user_jabber'])) { if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type) { $i = 0; if (sizeof($email_list)) { $j++; } $old_lang = $row['user_lang']; $old_notify_type = $row['user_notify_type']; } $email_list[$j][$i]['lang'] = $row['user_lang']; $email_list[$j][$i]['method'] = $row['user_notify_type']; $email_list[$j][$i]['email'] = $row['user_email']; $email_list[$j][$i]['name'] = $row['username']; $email_list[$j][$i]['jabber'] = $row['user_jabber']; $i++; } } while ($row = $db->sql_fetchrow($result)); $db->sql_freeresult($result); // Send the messages include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx; include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx; $messenger = new messenger($use_queue); $errored = false; $email_template = 'admin_send_email'; $template_data = array('CONTACT_EMAIL' => phpbb_get_board_contact($config, $phpEx), 'MESSAGE' => htmlspecialchars_decode($message)); $generate_log_entry = true; /** * Modify email template data before the emails are sent * * @event core.acp_email_send_before * @var string email_template The template to be used for sending the email * @var string subject The subject of the email * @var array template_data Array with template data assigned to email template * @var bool generate_log_entry If false, no log entry will be created * @var array usernames Usernames which will be displayed in log entry, if it will be created * @var int group_id The group this email will be sent to * @var bool use_queue If true, email queue will be used for sending * @var int priority Priority of sent emails * @since 3.1.3-RC1 */ $vars = array('email_template', 'subject', 'template_data', 'generate_log_entry', 'usernames', 'group_id', 'use_queue', 'priority'); extract($phpbb_dispatcher->trigger_event('core.acp_email_send_before', compact($vars))); for ($i = 0, $size = sizeof($email_list); $i < $size; $i++) { $used_lang = $email_list[$i][0]['lang']; $used_method = $email_list[$i][0]['method']; for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++) { $email_row = $email_list[$i][$j]; $messenger->{sizeof($email_list[$i]) == 1 ? 'to' : 'bcc'}($email_row['email'], $email_row['name']); $messenger->im($email_row['jabber'], $email_row['name']); } $messenger->template($email_template, $used_lang); $messenger->anti_abuse_headers($config, $user); $messenger->subject(htmlspecialchars_decode($subject)); $messenger->set_mail_priority($priority); $messenger->assign_vars($template_data); if (!$messenger->send($used_method)) { $errored = true; } } unset($email_list); $messenger->save_queue(); if ($generate_log_entry) { if (!empty($usernames)) { $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MASS_EMAIL', false, array(implode(', ', utf8_normalize_nfc($usernames)))); } else { if ($group_id) { $group_name = get_group_name($group_id); } else { // Not great but the logging routine doesn't cope well with localising on the fly $group_name = $user->lang['ALL_USERS']; } $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MASS_EMAIL', false, array($group_name)); } } if (!$errored) { $message = $use_queue ? $user->lang['EMAIL_SENT_QUEUE'] : $user->lang['EMAIL_SENT']; trigger_error($message . adm_back_link($this->u_action)); } else { $message = sprintf($user->lang['EMAIL_SEND_ERROR'], '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=logs&mode=critical') . '">', '</a>'); trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING); } } } // Exclude bots and guests... $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name IN ('BOTS', 'GUESTS')"; $result = $db->sql_query($sql); $exclude = array(); while ($row = $db->sql_fetchrow($result)) { $exclude[] = $row['group_id']; } $db->sql_freeresult($result); $select_list = '<option value="0"' . (!$group_id ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>'; $select_list .= group_select_options($group_id, $exclude); $s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>'; $s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>'; $s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>'; $template_data = array('S_WARNING' => sizeof($error) ? true : false, 'WARNING_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'U_ACTION' => $this->u_action, 'S_GROUP_OPTIONS' => $select_list, 'USERNAMES' => implode("\n", $usernames), 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=acp_email&field=usernames'), 'SUBJECT' => $subject, 'MESSAGE' => $message, 'S_PRIORITY_OPTIONS' => $s_priority_options); /** * Modify custom email template data before we display the form * * @event core.acp_email_display * @var array template_data Array with template data assigned to email template * @var array exclude Array with groups which are excluded from group selection * @var array usernames Usernames which will be displayed in form * * @since 3.1.4-RC1 */ $vars = array('template_data', 'exclude', 'usernames'); extract($phpbb_dispatcher->trigger_event('core.acp_email_display', compact($vars))); $template->assign_vars($template_data); }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; $this->page_title = 'ACP_GROUPS_MANAGE'; include $phpbb_root_path . 'includes/functions_user.' . $phpEx; // Check and set some common vars $action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : request_var('action', '')); $group_id = request_var('g', 0); $mark_ary = request_var('mark', array(0)); $name_ary = request_var('usernames', ''); $leader = request_var('leader', 0); $default = request_var('default', 0); $start = request_var('start', 0); $update = isset($_POST['update']) ? true : false; // Clear some vars $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false; $group_row = array(); // Grab basic data for group, if group_id is set and exists if ($group_id) { $sql = 'SELECT * FROM ' . GROUPS_TABLE . " \n\t\t\t\tWHERE group_id = {$group_id}"; $result = $db->sql_query($sql); $group_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$group_row) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action)); } } // Which page? switch ($action) { case 'approve': case 'demote': case 'promote': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action)); } // Approve, demote or promote group_user_attributes($action, $group_id, $mark_ary, false, $group_id ? $group_row['group_name'] : false); switch ($action) { case 'demote': $message = 'GROUP_MODS_DEMOTED'; break; case 'promote': $message = 'GROUP_MODS_PROMOTED'; break; case 'approve': $message = 'USERS_APPROVED'; break; } trigger_error($user->lang[$message] . adm_back_link($this->u_action)); break; case 'default': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action)); } if (confirm_box(true)) { if (!sizeof($mark_ary)) { $start = 0; do { $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id} \n\t\t\t\t\t\t\t\tORDER BY user_id"; $result = $db->sql_query_limit($sql, 200, $start); $mark_ary = array(); if ($row = $db->sql_fetchrow($result)) { do { $mark_ary[] = $row['user_id']; } while ($row = $db->sql_fetchrow($result)); group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row); $start = sizeof($mark_ary) < 200 ? 0 : $start + 200; } else { $start = 0; } $db->sql_freeresult($result); } while ($start); } else { group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row); } trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'deleteusers': case 'delete': if (confirm_box(true)) { if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action)); } $error = ''; switch ($action) { case 'delete': if (!$auth->acl_get('a_groupdel')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action)); } $error = group_delete($group_id, $group_row['group_name']); break; case 'deleteusers': $error = group_user_del($group_id, $mark_ary, false, $group_row['group_name']); break; } if ($error) { trigger_error($user->lang[$error] . adm_back_link($this->u_action)); } $message = $action == 'delete' ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'addusers': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action)); } if (!$name_ary) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action)); } $name_ary = array_unique(explode("\n", $name_ary)); // Add user/s to group if ($error = group_user_add($group_id, false, $name_ary, $group_row['group_name'], $default, $leader, 0, $group_row)) { trigger_error($user->lang[$error] . adm_back_link($this->u_action)); } $message = $action == 'addleaders' ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); break; case 'edit': case 'add': $data = $submit_ary = array(); if ($action == 'edit' && !$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action)); } if ($action == 'add' && !$auth->acl_get('a_groupadd')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action)); } $error = array(); $user->add_lang('ucp'); $avatar_select = basename(request_var('avatar_select', '')); $category = basename(request_var('category', '')); // Did we submit? if ($update) { $group_name = request_var('group_name', '', true); $group_desc = request_var('group_desc', '', true); $group_type = request_var('group_type', GROUP_FREE); $allow_desc_bbcode = request_var('desc_parse_bbcode', false); $allow_desc_urls = request_var('desc_parse_urls', false); $allow_desc_smilies = request_var('desc_parse_smilies', false); $data['uploadurl'] = request_var('uploadurl', ''); $data['remotelink'] = request_var('remotelink', ''); $delete = request_var('delete', ''); $submit_ary = array('colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0, 'message_limit' => request_var('group_message_limit', 0)); if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) { $data['width'] = request_var('width', ''); $data['height'] = request_var('height', ''); // Avatar stuff $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3)); if (!($error = validate_data($data, $var_ary))) { $data['user_id'] = "g{$group_id}"; if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); } else { if ($data['remotelink']) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error); } } } } else { if ($avatar_select && $config['allow_avatar_local']) { // check avatar gallery if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) { $submit_ary['avatar_type'] = AVATAR_GALLERY; list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select); $submit_ary['avatar'] = $category . '/' . $avatar_select; } } else { if ($delete) { $submit_ary['avatar'] = ''; $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0; } } } if (isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']) || $group_row['group_avatar'] != $submit_ary['avatar']) || $delete) { if (isset($group_row['group_avatar']) && $group_row['group_avatar']) { avatar_delete($group_row['group_avatar']); } } if (!sizeof($error)) { // Only set the rank, colour, etc. if it's changed or if we're adding a new // group. This prevents existing group members being updated if no changes // were made. $group_attributes = array(); $test_variables = array('rank', 'colour', 'avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'receive_pm', 'legend', 'message_limit'); foreach ($test_variables as $test) { if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test])) { $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; } } if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) { $group_perm_from = request_var('group_perm_from', 0); // Copy permissions? if ($group_perm_from && $action == 'add') { // From the mysql documentation: // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. // Due to this we stay on the safe side if we do the insertion "the manual way" // Copy permisisons from/to the acl groups table (only group_id gets changed) $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' WHERE group_id = ' . $group_perm_from; $result = $db->sql_query($sql); $groups_sql_ary = array(); while ($row = $db->sql_fetchrow($result)) { $groups_sql_ary[] = array('group_id' => (int) $group_id, 'forum_id' => (int) $row['forum_id'], 'auth_option_id' => (int) $row['auth_option_id'], 'auth_role_id' => (int) $row['auth_role_id'], 'auth_setting' => (int) $row['auth_setting']); } $db->sql_freeresult($result); // Now insert the data if (sizeof($groups_sql_ary)) { switch (SQL_LAYER) { case 'mysql': case 'mysql4': case 'mysqli': $db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $groups_sql_ary)); break; default: foreach ($groups_sql_ary as $ary) { $db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary)); } break; } } $auth->acl_clear_prefetch(); } $cache->destroy('sql', GROUPS_TABLE); $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); } } if (sizeof($error)) { $group_rank = $submit_ary['rank']; $group_desc_data = array('text' => $group_desc, 'allow_bbcode' => $allow_desc_bbcode, 'allow_smilies' => $allow_desc_smilies, 'allow_urls' => $allow_desc_urls); } } else { if (!$group_id) { $group_name = request_var('group_name', '', true); $group_desc_data = array('text' => '', 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true); $group_rank = 0; $group_type = GROUP_OPEN; } else { $group_name = $group_row['group_name']; $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield']); $group_type = $group_row['group_type']; $group_rank = $group_row['group_rank']; } } $sql = 'SELECT * FROM ' . RANKS_TABLE . ' WHERE rank_special = 1 ORDER BY rank_title'; $result = $db->sql_query($sql); $rank_options = '<option value="0"' . (!$group_rank ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>'; while ($row = $db->sql_fetchrow($result)) { $selected = $group_rank && $row['rank_id'] == $group_rank ? ' selected="selected"' : ''; $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>'; } $db->sql_freeresult($result); $type_free = $group_type == GROUP_FREE ? ' checked="checked"' : ''; $type_open = $group_type == GROUP_OPEN ? ' checked="checked"' : ''; $type_closed = $group_type == GROUP_CLOSED ? ' checked="checked"' : ''; $type_hidden = $group_type == GROUP_HIDDEN ? ' checked="checked"' : ''; if (isset($group_row['group_avatar']) && $group_row['group_avatar']) { switch ($group_row['group_avatar_type']) { case AVATAR_UPLOAD: $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/'; break; case AVATAR_GALLERY: $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/'; break; } $avatar_img .= $group_row['group_avatar']; $avatar_img = '<img src="' . $avatar_img . '" width="' . $group_row['group_avatar_width'] . '" height="' . $group_row['group_avatar_height'] . '" alt="" />'; } else { $avatar_img = '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />'; } $display_gallery = isset($_POST['display_gallery']) ? true : false; if ($config['allow_avatar_local'] && $display_gallery) { avatar_gallery($category, $avatar_select, 4); } $back_link = request_var('back_link', ''); switch ($back_link) { case 'acp_users_groups': $u_back = append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&mode=groups&u=' . request_var('u', 0)); break; default: $u_back = $this->u_action; break; } $template->assign_vars(array('S_EDIT' => true, 'S_ADD_GROUP' => $action == 'add' ? true : false, 'S_INCLUDE_SWATCH' => true, 'S_CAN_UPLOAD' => $can_upload, 'S_ERROR' => sizeof($error) ? true : false, 'S_SPECIAL_GROUP' => $group_type == GROUP_SPECIAL ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'GROUP_NAME' => $group_type == GROUP_SPECIAL ? $user->lang['G_' . $group_name] : $group_name, 'GROUP_INTERNAL_NAME' => $group_name, 'GROUP_DESC' => $group_desc_data['text'], 'GROUP_RECEIVE_PM' => isset($group_row['group_receive_pm']) && $group_row['group_receive_pm'] ? ' checked="checked"' : '', 'GROUP_LEGEND' => isset($group_row['group_legend']) && $group_row['group_legend'] ? ' checked="checked"' : '', 'GROUP_MESSAGE_LIMIT' => isset($group_row['group_message_limit']) ? $group_row['group_message_limit'] : 0, 'GROUP_COLOUR' => isset($group_row['group_colour']) ? $group_row['group_colour'] : '', 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], 'S_DESC_SMILIES_CHECKED' => $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(0), 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'GROUP_AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', 'GROUP_AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : '', 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, 'GROUP_FREE' => $type_free, 'GROUP_OPEN' => $type_open, 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, 'U_BACK' => $u_back, 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.{$phpEx}", 'form=settings&name=group_colour'), 'UA_SWATCH' => append_sid("{$phpbb_admin_path}swatch.{$phpEx}", 'form=settings&name=group_colour', false), 'U_ACTION' => "{$this->u_action}&action={$action}&g={$group_id}", 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))); return; break; case 'list': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action)); } $this->page_title = 'GROUP_MEMBERS'; // Total number of group leaders $sql = 'SELECT COUNT(user_id) AS total_leaders FROM ' . USER_GROUP_TABLE . " \n\t\t\t\t\tWHERE group_id = {$group_id} \n\t\t\t\t\t\tAND group_leader = 1"; $result = $db->sql_query($sql); $total_leaders = (int) $db->sql_fetchfield('total_leaders'); $db->sql_freeresult($result); // Total number of group members (non-leaders) $sql = 'SELECT COUNT(user_id) AS total_members FROM ' . USER_GROUP_TABLE . " \n\t\t\t\t\tWHERE group_id = {$group_id} \n\t\t\t\t\t\tAND group_leader <> 1"; $result = $db->sql_query($sql); $total_members = (int) $db->sql_fetchfield('total_members'); $db->sql_freeresult($result); // Grab the members $sql = 'SELECT u.user_id, u.username, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug \n\t\t\t\t\tWHERE ug.group_id = {$group_id} \n\t\t\t\t\t\tAND u.user_id = ug.user_id \n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $leader = $member = 0; $group_data = array('leader' => array(), 'member' => array()); while ($row = $db->sql_fetchrow($result)) { $type = $row['group_leader'] ? 'leader' : 'member'; $group_data[$type][${$type}]['user_id'] = $row['user_id']; $group_data[$type][${$type}]['group_id'] = $row['group_id']; $group_data[$type][${$type}]['username'] = $row['username']; $group_data[$type][${$type}]['user_regdate'] = $row['user_regdate']; $group_data[$type][${$type}]['user_posts'] = $row['user_posts']; $group_data[$type][${$type}]['user_pending'] = $row['user_pending'] ? 1 : 0; ${$type}++; } $db->sql_freeresult($result); $s_action_options = ''; $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE'); foreach ($options as $option => $lang) { $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>'; } $template->assign_vars(array('S_LIST' => true, 'S_GROUP_SPECIAL' => $group_row['group_type'] == GROUP_SPECIAL ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&action={$action}&g={$group_id}", $total_members, $config['topics_per_page'], $start, true), 'U_ACTION' => $this->u_action . "&g={$group_id}", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=list&field=usernames'))); foreach ($group_data['leader'] as $row) { $template->assign_block_vars('leader', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&action=edit&u={$row['user_id']}"), 'USERNAME' => $row['username'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $pending = false; foreach ($group_data['member'] as $row) { if ($row['user_pending'] && !$pending) { $template->assign_block_vars('member', array('S_PENDING' => true)); $pending = true; } $template->assign_block_vars('member', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&action=edit&u={$row['user_id']}"), 'USERNAME' => $row['username'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } return; break; } $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_GROUP_ADD' => $auth->acl_get('a_groupadd') ? true : false)); $sql = 'SELECT g.group_id, g.group_name, g.group_type, COUNT(ug.user_id) AS total_members FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (g.group_id = ug.group_id) GROUP BY g.group_id, g.group_name, g.group_type ORDER BY g.group_type ASC, g.group_name'; $result = $db->sql_query($sql); $special = $normal = 0; $group_ary = array(); while ($row = $db->sql_fetchrow($result)) { $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : 'normal'; $group_ary[$type][${$type}]['group_id'] = $row['group_id']; $group_ary[$type][${$type}]['group_name'] = $row['group_name']; $group_ary[$type][${$type}]['group_type'] = $row['group_type']; $group_ary[$type][${$type}]['total_members'] = $row['total_members']; ${$type}++; } $db->sql_freeresult($result); ksort($group_ary); $special_toggle = false; foreach ($group_ary as $type => $row_ary) { if ($type == 'special') { $template->assign_block_vars('groups', array('S_SPECIAL' => true)); } foreach ($row_ary as $row) { $group_id = $row['group_id']; $group_name = !empty($user->lang['G_' . $row['group_name']]) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; $template->assign_block_vars('groups', array('U_LIST' => "{$this->u_action}&action=list&g={$group_id}", 'U_DEFAULT' => "{$this->u_action}&action=default&g={$group_id}", 'U_EDIT' => "{$this->u_action}&action=edit&g={$group_id}", 'U_DELETE' => $auth->acl_get('a_groupdel') ? "{$this->u_action}&action=delete&g={$group_id}" : '', 'S_GROUP_SPECIAL' => $row['group_type'] == GROUP_SPECIAL ? true : false, 'GROUP_NAME' => $group_name, 'TOTAL_MEMBERS' => $row['total_members'])); } } }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; $user->add_lang('acp/email'); $this->tpl_name = 'acp_email'; $this->page_title = 'ACP_MASS_EMAIL'; // Set some vars $submit = isset($_POST['submit']) ? true : false; $error = array(); $usernames = request_var('usernames', ''); $group_id = request_var('g', 0); $subject = request_var('subject', '', true); $message = request_var('message', '', true); // Do the job ... if ($submit) { // Error checking needs to go here ... if no subject and/or no message then skip // over the send and return to the form $use_queue = isset($_POST['send_immediatly']) ? false : true; $priority = request_var('mail_priority_flag', MAIL_NORMAL_PRIORITY); if (!$subject) { $error[] = $user->lang['NO_EMAIL_SUBJECT']; } if (!$message) { $error[] = $user->lang['NO_EMAIL_MESSAGE']; } if (!sizeof($error)) { if ($usernames) { $usernames = implode(', ', preg_replace('#^[\\s]*?(.*?)[\\s]*?$#e', "\"'\" . \$db->sql_escape('\\1') . \"'\"", explode("\n", $usernames))); $sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang FROM ' . USERS_TABLE . " \n\t\t\t\t\t\tWHERE username IN ({$usernames})\n\t\t\t\t\t\t\tAND user_allow_massemail = 1\n\t\t\t\t\t\tORDER BY user_lang, user_notify_type"; // , SUBSTRING(user_email FROM INSTR(user_email, '@')) } else { if ($group_id) { $sql = 'SELECT u.user_email, u.username, u.user_lang, u.user_jabber, u.user_notify_type FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug \n\t\t\t\t\t\t\tWHERE ug.group_id = {$group_id} \n\t\t\t\t\t\t\t\tAND ug.user_pending = 0\n\t\t\t\t\t\t\t\tAND u.user_id = ug.user_id \n\t\t\t\t\t\t\t\tAND u.user_allow_massemail = 1\n\t\t\t\t\t\t\tORDER BY u.user_lang, u.user_notify_type"; } else { $sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang FROM ' . USERS_TABLE . ' WHERE user_allow_massemail = 1 ORDER BY user_lang, user_notify_type'; } } $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action)); } $i = $j = 0; // Send with BCC, no more than 50 recipients for one mail (to not exceed the limit) $max_chunk_size = 50; $email_list = array(); $old_lang = $row['user_lang']; $old_notify_type = $row['user_notify_type']; do { if ($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email'] || $row['user_notify_type'] == NOTIFY_IM && $row['user_jabber'] || $row['user_notify_type'] == NOTIFY_BOTH && $row['user_email'] && $row['user_jabber']) { if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type) { $i = 0; $j++; $old_lang = $row['user_lang']; $old_notify_type = $row['user_notify_type']; } $email_list[$j][$i]['lang'] = $row['user_lang']; $email_list[$j][$i]['method'] = $row['user_notify_type']; $email_list[$j][$i]['email'] = $row['user_email']; $email_list[$j][$i]['name'] = $row['username']; $email_list[$j][$i]['jabber'] = $row['user_jabber']; $i++; } } while ($row = $db->sql_fetchrow($result)); $db->sql_freeresult($result); // Send the messages include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx; include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx; $messenger = new messenger($use_queue); $errored = false; for ($i = 0, $size = sizeof($email_list); $i < $size; $i++) { $used_lang = $email_list[$i][0]['lang']; $used_method = $email_list[$i][0]['method']; for ($j = 0, $list_size = sizeof($email_list[$i]); $j < $list_size; $j++) { $email_row = $email_list[$i][$j]; $messenger->{sizeof($email_list[$i]) == 1 ? 'to' : 'bcc'}($email_row['email'], $email_row['name']); $messenger->im($email_row['jabber'], $email_row['name']); } $messenger->template('admin_send_email', $used_lang); $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']); $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']); $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']); $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip); $messenger->subject(html_entity_decode($subject)); $messenger->replyto($config['board_email']); $messenger->set_mail_priority($priority); $messenger->assign_vars(array('SITENAME' => $config['sitename'], 'CONTACT_EMAIL' => $config['board_contact'], 'MESSAGE' => html_entity_decode($message))); if (!$messenger->send($used_method)) { $errored = true; } } unset($email_list); $messenger->save_queue(); if ($group_id) { $group_name = get_group_name($group_id); } else { // Not great but the logging routine doesn't cope well with localising on the fly $group_name = $user->lang['ALL_USERS']; } add_log('admin', 'LOG_MASS_EMAIL', $group_name); if (!$errored) { $message = $use_queue ? $user->lang['EMAIL_SENT_QUEUE'] : $user->lang['EMAIL_SENT']; } else { $message = sprintf($user->lang['EMAIL_SEND_ERROR'], '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=logs&mode=critical') . '">', '</a>'); } trigger_error($message . adm_back_link($this->u_action)); } } // Exclude bots... $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name = 'BOTS'"; $result = $db->sql_query($sql); $bot_group_id = (int) $db->sql_fetchfield('group_id'); $db->sql_freeresult($result); $select_list = '<option value="0"' . (!$group_id ? ' selected="selected"' : '') . '>' . $user->lang['ALL_USERS'] . '</option>'; $select_list .= group_select_options($group_id, array($bot_group_id)); $s_priority_options = '<option value="' . MAIL_LOW_PRIORITY . '">' . $user->lang['MAIL_LOW_PRIORITY'] . '</option>'; $s_priority_options .= '<option value="' . MAIL_NORMAL_PRIORITY . '" selected="selected">' . $user->lang['MAIL_NORMAL_PRIORITY'] . '</option>'; $s_priority_options .= '<option value="' . MAIL_HIGH_PRIORITY . '">' . $user->lang['MAIL_HIGH_PRIORITY'] . '</option>'; $template->assign_vars(array('S_WARNING' => sizeof($error) ? true : false, 'WARNING_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'U_ACTION' => $this->u_action, 'S_GROUP_OPTIONS' => $select_list, 'USERNAMES' => $usernames, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=acp_email&field=usernames'), 'SUBJECT' => $subject, 'MESSAGE' => $message, 'S_PRIORITY_OPTIONS' => $s_priority_options)); }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; $this->page_title = 'ACP_GROUPS_MANAGE'; $form_key = 'acp_groups'; add_form_key($form_key); include $phpbb_root_path . 'includes/functions_user.' . $phpEx; // Check and set some common vars $action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : request_var('action', '')); $group_id = request_var('g', 0); $mark_ary = request_var('mark', array(0)); $name_ary = request_var('usernames', '', true); $leader = request_var('leader', 0); $default = request_var('default', 0); $start = request_var('start', 0); $update = isset($_POST['update']) ? true : false; // Clear some vars $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false; $group_row = array(); // Grab basic data for group, if group_id is set and exists if ($group_id) { $sql = 'SELECT * FROM ' . GROUPS_TABLE . "\n\t\t\t\tWHERE group_id = {$group_id}"; $result = $db->sql_query($sql); $group_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$group_row) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check if the user is allowed to manage this group if set to founder only. if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) { trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } } // Which page? switch ($action) { case 'approve': case 'demote': case 'promote': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } // Approve, demote or promote $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; $error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name); if (!$error) { switch ($action) { case 'demote': $message = 'GROUP_MODS_DEMOTED'; break; case 'promote': $message = 'GROUP_MODS_PROMOTED'; break; case 'approve': $message = 'USERS_APPROVED'; break; } trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } break; case 'default': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } if (confirm_box(true)) { $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; if (!sizeof($mark_ary)) { $start = 0; do { $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tORDER BY user_id"; $result = $db->sql_query_limit($sql, 200, $start); $mark_ary = array(); if ($row = $db->sql_fetchrow($result)) { do { $mark_ary[] = $row['user_id']; } while ($row = $db->sql_fetchrow($result)); group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); $start = sizeof($mark_ary) < 200 ? 0 : $start + 200; } else { $start = 0; } $db->sql_freeresult($result); } while ($start); } else { group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); } trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'deleteusers': case 'delete': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } else { if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } } if (confirm_box(true)) { $error = ''; switch ($action) { case 'delete': if (!$auth->acl_get('a_groupdel')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $error = group_delete($group_id, $group_row['group_name']); break; case 'deleteusers': $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; $error = group_user_del($group_id, $mark_ary, false, $group_name); break; } $back_link = $action == 'delete' ? $this->u_action : $this->u_action . '&action=list&g=' . $group_id; if ($error) { trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING); } $message = $action == 'delete' ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE'; trigger_error($user->lang[$message] . adm_back_link($back_link)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'addusers': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$name_ary) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } $name_ary = array_unique(explode("\n", $name_ary)); $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; // Add user/s to group if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row)) { trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } $message = $leader ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); break; case 'edit': case 'add': include $phpbb_root_path . 'includes/functions_display.' . $phpEx; $data = $submit_ary = array(); if ($action == 'edit' && !$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($action == 'add' && !$auth->acl_get('a_groupadd')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $error = array(); $user->add_lang('ucp'); $avatar_select = basename(request_var('avatar_select', '')); $category = basename(request_var('category', '')); // Did we submit? if ($update) { if (!check_form_key($form_key)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $group_name = utf8_normalize_nfc(request_var('group_name', '', true)); $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true)); $group_type = request_var('group_type', GROUP_FREE); $allow_desc_bbcode = request_var('desc_parse_bbcode', false); $allow_desc_urls = request_var('desc_parse_urls', false); $allow_desc_smilies = request_var('desc_parse_smilies', false); $data['uploadurl'] = request_var('uploadurl', ''); $data['remotelink'] = request_var('remotelink', ''); $data['width'] = request_var('width', ''); $data['height'] = request_var('height', ''); $delete = request_var('delete', ''); $submit_ary = array('colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0, 'message_limit' => request_var('group_message_limit', 0), 'max_recipients' => request_var('group_max_recipients', 0), 'founder_manage' => 0, 'skip_auth' => request_var('group_skip_auth', 0)); if ($user->data['user_type'] == USER_FOUNDER) { $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; } if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) { // Avatar stuff $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3)); if (!($error = validate_data($data, $var_ary))) { $data['user_id'] = "g{$group_id}"; if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); } else { if ($data['remotelink']) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error); } } } } else { if ($avatar_select && $config['allow_avatar_local']) { // check avatar gallery if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) { $submit_ary['avatar_type'] = AVATAR_GALLERY; list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select); $submit_ary['avatar'] = $category . '/' . $avatar_select; } } else { if ($delete) { $submit_ary['avatar'] = ''; $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0; } else { if ($data['width'] && $data['height']) { // Only update the dimensions? if ($config['avatar_max_width'] || $config['avatar_max_height']) { if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) { $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']); } } if (!sizeof($error)) { if ($config['avatar_min_width'] || $config['avatar_min_height']) { if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) { $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']); } } } if (!sizeof($error)) { $submit_ary['avatar_width'] = $data['width']; $submit_ary['avatar_height'] = $data['height']; } } } } } if (isset($submit_ary['avatar']) && $submit_ary['avatar'] && !isset($group_row['group_avatar']) || $delete) { if (isset($group_row['group_avatar']) && $group_row['group_avatar']) { avatar_delete('group', $group_row, true); } } // Validate the length of "Maximum number of allowed recipients per private message" setting. // We use 16777215 as a maximum because it matches MySQL unsigned mediumint maximum value // which is the lowest amongst DBMSes supported by phpBB3 if ($max_recipients_error = validate_data($submit_ary, array('max_recipients' => array('num', false, 0, 16777215)))) { // Replace "error" string with its real, localised form $error = array_merge($error, array_map(array(&$user, 'lang'), $max_recipients_error)); } if (!sizeof($error)) { // Only set the rank, colour, etc. if it's changed or if we're adding a new // group. This prevents existing group members being updated if no changes // were made. $group_attributes = array(); $test_variables = array('rank' => 'int', 'colour' => 'string', 'avatar' => 'string', 'avatar_type' => 'int', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', 'legend' => 'int', 'message_limit' => 'int', 'max_recipients' => 'int', 'founder_manage' => 'int', 'skip_auth' => 'int'); foreach ($test_variables as $test => $type) { if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test])) { settype($submit_ary[$test], $type); $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; } } if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) { $group_perm_from = request_var('group_perm_from', 0); // Copy permissions? // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred. // We do not limit on one auth category because this can lead to incomplete permissions being tricky to fix for the admin, roles being assigned or added non-default permissions. // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise. if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) { $sql = 'SELECT group_founder_manage FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . $group_perm_from; $result = $db->sql_query($sql); $check_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // Check the group if non-founder if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0)) { // From the mysql documentation: // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. // Due to this we stay on the safe side if we do the insertion "the manual way" // Copy permisisons from/to the acl groups table (only group_id gets changed) $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' WHERE group_id = ' . $group_perm_from; $result = $db->sql_query($sql); $groups_sql_ary = array(); while ($row = $db->sql_fetchrow($result)) { $groups_sql_ary[] = array('group_id' => (int) $group_id, 'forum_id' => (int) $row['forum_id'], 'auth_option_id' => (int) $row['auth_option_id'], 'auth_role_id' => (int) $row['auth_role_id'], 'auth_setting' => (int) $row['auth_setting']); } $db->sql_freeresult($result); // Now insert the data $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary); $auth->acl_clear_prefetch(); } } $cache->destroy('sql', GROUPS_TABLE); $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); } } if (sizeof($error)) { $group_rank = $submit_ary['rank']; $group_desc_data = array('text' => $group_desc, 'allow_bbcode' => $allow_desc_bbcode, 'allow_smilies' => $allow_desc_smilies, 'allow_urls' => $allow_desc_urls); } } else { if (!$group_id) { $group_name = utf8_normalize_nfc(request_var('group_name', '', true)); $group_desc_data = array('text' => '', 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true); $group_rank = 0; $group_type = GROUP_OPEN; } else { $group_name = $group_row['group_name']; $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']); $group_type = $group_row['group_type']; $group_rank = $group_row['group_rank']; } } $sql = 'SELECT * FROM ' . RANKS_TABLE . ' WHERE rank_special = 1 ORDER BY rank_title'; $result = $db->sql_query($sql); $rank_options = '<option value="0"' . (!$group_rank ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>'; while ($row = $db->sql_fetchrow($result)) { $selected = $group_rank && $row['rank_id'] == $group_rank ? ' selected="selected"' : ''; $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>'; } $db->sql_freeresult($result); $type_free = $group_type == GROUP_FREE ? ' checked="checked"' : ''; $type_open = $group_type == GROUP_OPEN ? ' checked="checked"' : ''; $type_closed = $group_type == GROUP_CLOSED ? ' checked="checked"' : ''; $type_hidden = $group_type == GROUP_HIDDEN ? ' checked="checked"' : ''; $avatar_img = !empty($group_row['group_avatar']) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />'; $display_gallery = isset($_POST['display_gallery']) ? true : false; if ($config['allow_avatar_local'] && $display_gallery) { avatar_gallery($category, $avatar_select, 4); } $back_link = request_var('back_link', ''); switch ($back_link) { case 'acp_users_groups': $u_back = append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&mode=groups&u=' . request_var('u', 0)); break; default: $u_back = $this->u_action; break; } $template->assign_vars(array('S_EDIT' => true, 'S_ADD_GROUP' => $action == 'add' ? true : false, 'S_GROUP_PERM' => $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth') ? true : false, 'S_INCLUDE_SWATCH' => true, 'S_CAN_UPLOAD' => $can_upload, 'S_ERROR' => sizeof($error) ? true : false, 'S_SPECIAL_GROUP' => $group_type == GROUP_SPECIAL ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'S_USER_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'GROUP_NAME' => $group_type == GROUP_SPECIAL ? $user->lang['G_' . $group_name] : $group_name, 'GROUP_INTERNAL_NAME' => $group_name, 'GROUP_DESC' => $group_desc_data['text'], 'GROUP_RECEIVE_PM' => isset($group_row['group_receive_pm']) && $group_row['group_receive_pm'] ? ' checked="checked"' : '', 'GROUP_FOUNDER_MANAGE' => isset($group_row['group_founder_manage']) && $group_row['group_founder_manage'] ? ' checked="checked"' : '', 'GROUP_LEGEND' => isset($group_row['group_legend']) && $group_row['group_legend'] ? ' checked="checked"' : '', 'GROUP_MESSAGE_LIMIT' => isset($group_row['group_message_limit']) ? $group_row['group_message_limit'] : 0, 'GROUP_MAX_RECIPIENTS' => isset($group_row['group_max_recipients']) ? $group_row['group_max_recipients'] : 0, 'GROUP_COLOUR' => isset($group_row['group_colour']) ? $group_row['group_colour'] : '', 'GROUP_SKIP_AUTH' => !empty($group_row['group_skip_auth']) ? ' checked="checked"' : '', 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], 'S_DESC_SMILIES_CHECKED' => $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, $user->data['user_type'] == USER_FOUNDER ? false : 0), 'AVATAR' => $avatar_img, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : '', 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, 'GROUP_FREE' => $type_free, 'GROUP_OPEN' => $type_open, 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, 'U_BACK' => $u_back, 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.{$phpEx}", 'form=settings&name=group_colour'), 'U_ACTION' => "{$this->u_action}&action={$action}&g={$group_id}", 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))); return; break; case 'list': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->page_title = 'GROUP_MEMBERS'; // Grab the leaders - always, on every page... $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\tAND ug.group_leader = 1\n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $template->assign_block_vars('leader', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&action=edit&u={$row['user_id']}"), 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $db->sql_freeresult($result); // Total number of group members (non-leaders) $sql = 'SELECT COUNT(user_id) AS total_members FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\tAND group_leader = 0"; $result = $db->sql_query($sql); $total_members = (int) $db->sql_fetchfield('total_members'); $db->sql_freeresult($result); $s_action_options = ''; $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE'); foreach ($options as $option => $lang) { $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>'; } $template->assign_vars(array('S_LIST' => true, 'S_GROUP_SPECIAL' => $group_row['group_type'] == GROUP_SPECIAL ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&action={$action}&g={$group_id}", $total_members, $config['topics_per_page'], $start, true), 'GROUP_NAME' => $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'], 'U_ACTION' => $this->u_action . "&g={$group_id}", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=list&field=usernames'), 'U_DEFAULT_ALL' => "{$this->u_action}&action=default&g={$group_id}")); // Grab the members $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\tAND ug.group_leader = 0\n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $pending = false; while ($row = $db->sql_fetchrow($result)) { if ($row['user_pending'] && !$pending) { $template->assign_block_vars('member', array('S_PENDING' => true)); $pending = true; } $template->assign_block_vars('member', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&action=edit&u={$row['user_id']}"), 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $db->sql_freeresult($result); return; break; } $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_GROUP_ADD' => $auth->acl_get('a_groupadd') ? true : false)); // Get us all the groups $sql = 'SELECT g.group_id, g.group_name, g.group_type FROM ' . GROUPS_TABLE . ' g ORDER BY g.group_type ASC, g.group_name'; $result = $db->sql_query($sql); $lookup = $cached_group_data = array(); while ($row = $db->sql_fetchrow($result)) { $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : 'normal'; // used to determine what type a group is $lookup[$row['group_id']] = $type; // used for easy access to the data within a group $cached_group_data[$type][$row['group_id']] = $row; $cached_group_data[$type][$row['group_id']]['total_members'] = 0; } $db->sql_freeresult($result); // How many people are in which group? $sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id FROM ' . USER_GROUP_TABLE . ' ug WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . ' GROUP BY ug.group_id'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $type = $lookup[$row['group_id']]; $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members']; } $db->sql_freeresult($result); // The order is... normal, then special ksort($cached_group_data); foreach ($cached_group_data as $type => $row_ary) { if ($type == 'special') { $template->assign_block_vars('groups', array('S_SPECIAL' => true)); } foreach ($row_ary as $group_id => $row) { $group_name = !empty($user->lang['G_' . $row['group_name']]) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; $template->assign_block_vars('groups', array('U_LIST' => "{$this->u_action}&action=list&g={$group_id}", 'U_EDIT' => "{$this->u_action}&action=edit&g={$group_id}", 'U_DELETE' => $auth->acl_get('a_groupdel') ? "{$this->u_action}&action=delete&g={$group_id}" : '', 'S_GROUP_SPECIAL' => $row['group_type'] == GROUP_SPECIAL ? true : false, 'GROUP_NAME' => $group_name, 'TOTAL_MEMBERS' => $row['total_members'])); } } }
function main($id, $mode) { global $db, $user, $auth, $template, $cache, $request, $table_prefix, $points_config, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container; $this->config_text = $phpbb_container->get('config_text'); $this->request = $request; $user->add_lang('acp/common'); $this->page_title = $user->lang('ACP_POINTS_SETTINGS'); add_form_key('acp_points'); $points_config = $cache->get('points_config'); $points_values = $cache->get('points_values'); define('CONFIG_TEXT_TABLE', $table_prefix . 'config_text'); $data = $this->config_text->get_array(array('points_name', 'ultimate_points_version')); if ($request->is_set_post('submit_config')) { if (!check_form_key('vipaka/points')) { trigger_error('FORM_INVALID'); } $data['points_name'] = $this->request->variable('points_name', '', true); $data['ultimate_points_version'] = $this->request->variable('ultimate_points_version', '', true); $config->set('points_enable', $request->variable('points_enable', 0)); $this->config_text->set_array(array('points_name' => $data['points_name'], 'ultimate_points_version' => $data['ultimate_points_version'])); trigger_error($user->lang('ACP_POINTS_SETTING_SAVED') . adm_back_link($this->u_action)); } define('POINTS_TABLE', $table_prefix . 'points_values'); switch ($mode) { case 'points': $this->page_title = $user->lang('ACP_POINTS_INDEX_TITLE'); $this->tpl_name = 'acp_points_main'; $submit = request_var('submit', ''); if ($submit) { if (!check_form_key('acp_points')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Values for phpbb_config $points_name = utf8_normalize_nfc(request_var('points_name', '', true)); $points_enable = request_var('points_enable', 0); // Values for phpbb_points_config $points_disablemsg = utf8_normalize_nfc(request_var('points_disablemsg', '', true)); $transfer_enable = request_var('transfer_enable', 0); $transfer_pm_enable = request_var('transfer_pm_enable', 0); $comments_enable = request_var('comments_enable', 0); $stats_enable = request_var('stats_enable', 0); $logs_enable = request_var('logs_enable', 0); $images_topic_enable = request_var('images_topic_enable', 0); $images_memberlist_enable = request_var('images_memberlist_enable', 0); $gallery_deny_view = request_var('gallery_deny_view', 0); // Values for phpbb_points_values $sql_ary = array('number_show_per_page' => request_var('number_show_per_page', 0), 'number_show_top_points' => request_var('number_show_top_points', 0), 'points_per_attach' => round(request_var('points_per_attach', 0.0), 2), 'points_per_attach_file' => round(request_var('points_per_attach_file', 0.0), 2), 'points_per_poll' => round(request_var('points_per_poll', 0.0), 2), 'points_per_poll_option' => round(request_var('points_per_poll_option', 0.0), 2), 'points_per_topic_word' => round(request_var('points_per_topic_word', 0.0), 2), 'points_per_topic_character' => round(request_var('points_per_topic_character', 0.0), 2), 'points_per_post_word' => round(request_var('points_per_post_word', 0.0), 2), 'points_per_post_character' => round(request_var('points_per_post_character', 0.0), 2), 'reg_points_bonus' => round(request_var('reg_points_bonus', 0.0), 2), 'points_per_warn' => round(request_var('points_per_warn', 0.0), 2), 'gallery_upload' => round(request_var('gallery_upload', 0.0), 2), 'gallery_remove' => round(request_var('gallery_remove', 0.0), 2), 'gallery_view' => round(request_var('gallery_view', 0.0), 2)); // Check if number_show_per_page is at least 5 $per_page_check = request_var('number_show_per_page', 0); if ($per_page_check < 5) { trigger_error($user->lang['POINTS_SHOW_PER_PAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Update values in phpbb_config if ($points_name != $config['points_name']) { set_config('points_name', $points_name); } if ($points_enable != $config['points_enable']) { set_config('points_enable', $points_enable); } // Update values in phpbb_points_config if ($points_disablemsg != $points_config['points_disablemsg']) { set_points_config('points_disablemsg', $points_disablemsg); } if ($transfer_enable != $points_config['transfer_enable']) { set_points_config('transfer_enable', $transfer_enable); } if ($transfer_pm_enable != $points_config['transfer_pm_enable']) { set_points_config('transfer_pm_enable', $transfer_pm_enable); } if ($comments_enable != $points_config['comments_enable']) { set_points_config('comments_enable', $comments_enable); } if ($stats_enable != $points_config['stats_enable']) { set_points_config('stats_enable', $stats_enable); } if ($logs_enable != $points_config['logs_enable']) { set_points_config('logs_enable', $logs_enable); } if ($images_topic_enable != $points_config['images_topic_enable']) { set_points_config('images_topic_enable', $images_topic_enable); } if ($images_memberlist_enable != $points_config['images_memberlist_enable']) { set_points_config('images_memberlist_enable', $images_memberlist_enable); } if ($gallery_deny_view != $points_config['gallery_deny_view']) { set_points_config('gallery_deny_view', $gallery_deny_view); } // Update values in phpbb_points_values $sql = 'UPDATE ' . POINTS_VALUES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary); $db->sql_query($sql); // Add logs add_log('admin', 'LOG_MOD_POINTS_SETTINGS'); trigger_error($user->lang['POINTS_CONFIG_SUCCESS'] . adm_back_link($this->u_action)); } else { $template->assign_vars(array('POINTS_DISABLEMSG' => $points_config['points_disablemsg'], 'TRANSFER_ENABLE' => $points_config['transfer_enable'], 'TRANSFER_PM_ENABLE' => $points_config['transfer_pm_enable'], 'COMMENTS_ENABLE' => $points_config['comments_enable'], 'STATS_ENABLE' => $points_config['stats_enable'], 'LOGS_ENABLE' => $points_config['logs_enable'], 'IMAGES_TOPIC_ENABLE' => $points_config['images_topic_enable'], 'IMAGES_MEMBERLIST_ENABLE' => $points_config['images_memberlist_enable'], 'GALLERY_DENY_VIEW' => $points_values['gallery_deny_view'], 'POINTS_NAME' => $config['points_name'], 'POINTS_PER_ATTACH' => $points_values['points_per_attach'], 'POINTS_PER_ATTACH_FILE' => $points_values['points_per_attach_file'], 'POINTS_PER_POLL' => $points_values['points_per_poll'], 'POINTS_PER_POLL_OPTION' => $points_values['points_per_poll_option'], 'POINTS_PER_TOPIC_WORD' => $points_values['points_per_topic_word'], 'POINTS_PER_TOPIC_CHARACTER' => $points_values['points_per_topic_character'], 'POINTS_PER_POST_WORD' => $points_values['points_per_post_word'], 'POINTS_PER_POST_CHARACTER' => $points_values['points_per_post_character'], 'POINTS_PER_WARN' => $points_values['points_per_warn'], 'REG_POINTS_BONUS' => $points_values['reg_points_bonus'], 'NUMBER_SHOW_TOP_POINTS' => $points_values['number_show_top_points'], 'NUMBER_SHOW_PER_PAGE' => $points_values['number_show_per_page'], 'POINTS_ENABLE' => $config['points_enable'] ? true : false, 'GALLERY_UPLOAD' => $points_values['gallery_upload'], 'GALLERY_REMOVE' => $points_values['gallery_remove'], 'GALLERY_VIEW' => $points_values['gallery_view'])); } // Delete all userlogs $reset_pointslogs = isset($_POST['action_points_logs']) ? true : false; if ($reset_pointslogs) { if (confirm_box(true)) { define('POINTS_LOG_TABLE', $table_prefix . 'points_log'); if (!$auth->acl_get('a_points')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } switch ($db->sql_layer) { case 'sqlite': case 'firebird': $db->sql_query('DELETE FROM ' . POINTS_LOG_TABLE); break; default: $db->sql_query('TRUNCATE TABLE ' . POINTS_LOG_TABLE); break; } add_log('admin', 'LOG_RESYNC_POINTSLOGSCOUNTS'); trigger_error($user->lang['LOG_RESYNC_POINTSLOGSCOUNTS'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('action_points_logs' => true)); // Display mode confirm_box(false, $user->lang['RESYNC_POINTSLOGS_CONFIRM'], $s_hidden_fields); } } // Delete all userpoints $reset_points_user = isset($_POST['action_points']) ? true : false; if ($reset_points_user) { if (confirm_box(true)) { if (!$auth->acl_get('a_points')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_points = 0'); add_log('admin', 'LOG_RESYNC_POINTSCOUNTS'); trigger_error($user->lang['LOG_RESYNC_POINTSCOUNTS'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('action_points' => true)); // Display mode confirm_box(false, $user->lang['RESYNC_POINTS_CONFIRM'], $s_hidden_fields); } } // Transfer or set points for groups $group_transfer = isset($_POST['group_transfer']) ? true : false; $group_transfer_points = request_var('group_transfer_points', 0.0); $func = request_var('func', ''); $group_id = request_var('group_id', 0); $pm_subject = utf8_normalize_nfc(request_var('pm_subject', '', true)); $pm_text = utf8_normalize_nfc(request_var('pm_text', '', true)); $sql_array = array('SELECT' => 'group_id, group_name, group_type', 'FROM' => array(GROUPS_TABLE => 'g'), 'ORDER_BY' => 'group_name'); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $total_groups = $db->sql_affectedrows($result); $db->sql_freeresult($result); $template->assign_vars(array('U_SMILIES' => append_sid("{$phpbb_root_path}posting.{$phpEx}", 'mode=smilies'), 'S_GROUP_OPTIONS' => group_select_options($total_groups), 'U_ACTION' => $this->u_action)); // Update the points if ($group_transfer) { if (!check_form_key('acp_points')) { // trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_array = array('SELECT' => 'group_type, group_name', 'FROM' => array(GROUPS_TABLE => 'g'), 'WHERE' => 'group_id = ' . (int) $group_id); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $group_name = $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']; // Check if we try transfering to BOTS or GUESTS if ($row['group_name'] == 'BOTS' || $row['group_name'] == 'GUESTS') { trigger_error($user->lang['POINTS_GROUP_TRANSFER_SEL_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_array = array('SELECT' => 'user_id', 'FROM' => array(USER_GROUP_TABLE => 'g'), 'WHERE' => 'user_pending <> ' . TRUE . ' AND group_id = ' . (int) $group_id); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $user_ids = array(); while ($row = $db->sql_fetchrow($result)) { $user_ids[] = $row['user_id']; } $db->sql_freeresult($result); if (sizeof($user_ids)) { if ($func == 'add') { $sql = "UPDATE " . USERS_TABLE . "\n SET user_points = user_points + {$group_transfer_points}\n WHERE " . $db->sql_in_set('user_id', $user_ids); add_log('admin', 'LOG_GROUP_TRANSFER_ADD'); } if ($func == 'substract') { $sql = "UPDATE " . USERS_TABLE . "\n SET user_points = user_points - {$group_transfer_points}\n WHERE " . $db->sql_in_set('user_id', $user_ids); add_log('admin', 'LOG_GROUP_TRANSFER_ADD'); } if ($func == 'set') { $sql = "UPDATE " . USERS_TABLE . "\n SET user_points = {$group_transfer_points}\n WHERE " . $db->sql_in_set('user_id', $user_ids); add_log('admin', 'LOG_GROUP_TRANSFER_SET'); } $result = $db->sql_query($sql); // Send PM, if pm subject and pm comment is entered if ($pm_subject != '' || $pm_text != '') { if ($pm_subject == '' || $pm_text == '') { trigger_error($user->lang['POINTS_GROUP_TRANSFER_PM_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } else { $sql_array = array('SELECT' => 'user_id, group_id', 'FROM' => array(USER_GROUP_TABLE => 'g'), 'WHERE' => 'user_pending <> ' . TRUE . ' AND group_id = ' . (int) $group_id); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $group_to = array(); while ($row = $db->sql_fetchrow($result)) { $group_to[$row['group_id']] = 'to'; } $poll = $uid = $bitfield = $options = ''; generate_text_for_storage($pm_subject, $uid, $bitfield, $options, false, false, false); generate_text_for_storage($pm_text, $uid, $bitfield, $options, true, true, true); include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx; $pm_data = array('address_list' => array('g' => $group_to), 'from_user_id' => $user->data['user_id'], 'from_username' => 'Points Transfer', 'icon_id' => 0, 'from_user_ip' => $user->data['user_ip'], 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $pm_text, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid); submit_pm('post', $pm_subject, $pm_data, false); $db->sql_freeresult($result); } $message = $user->lang['POINTS_GROUP_TRANSFER_PM_SUCCESS'] . adm_back_link($this->u_action); trigger_error($message); } else { $message = $user->lang['POINTS_GROUP_TRANSFER_SUCCESS'] . adm_back_link($this->u_action); trigger_error($message); } } } // phpBB Gallery integration if (isset($config['gallery_total_images'])) { $template->assign_vars(array('S_GALLERY_EXIST' => true, 'POINTS_NAME' => $config['points_name'])); } $template->assign_vars(array('S_POINTS_MAIN' => true, 'S_POINTS_ACTIVATED' => $config['points_enable'] ? true : false, 'U_ACTION' => $this->u_action)); break; case 'lottery': $this->page_title = 'ACP_POINTS_LOTTERY_TITLE'; $this->tpl_name = 'acp_points_lottery'; $action = request_var('action', ''); $submit = request_var('submit', ''); $lottery_data = $errors = array(); if ($submit) { if (!check_form_key('acp_points')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Get current lottery_base_amount $current_lottery_jackpot = $points_values['lottery_jackpot']; $current_lottery_base_amount = $points_values['lottery_base_amount']; // Values for phpbb_points_config $lottery_enable = request_var('lottery_enable', 0); $lottery_multi_ticket_enable = request_var('lottery_multi_ticket_enable', 0); $display_lottery_stats = request_var('display_lottery_stats', 0); // Values for phpbb_points_values $lottery_base_amount = round(request_var('lottery_base_amount', 0.0), 2); $lottery_draw_period = request_var('lottery_draw_period', 0) * 3600; $lottery_ticket_cost = round(request_var('lottery_ticket_cost', 0.0), 2); $lottery_name = utf8_normalize_nfc(request_var('lottery_name', '', true)); $lottery_chance = round(request_var('lottery_chance', 0.0), 2); $lottery_max_tickets = round(request_var('lottery_max_tickets', 0.0), 2); $lottery_pm_from = request_var('lottery_pm_from', 0); $lottery_current_jackpot = round(request_var('lottery_current_jackpot', 0.0), 2); $lottery_calc = request_var('lottery_last_draw_time', 0); // Calculate next lottery time $lottery_last_draw_time = $lottery_calc - $lottery_draw_period; // Check entered lottery chance - has to be max 100 if ($lottery_chance > 100) { trigger_error($user->lang['LOTTERY_CHANCE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // If base amount increases, increase jackpot if ($lottery_base_amount > $current_lottery_base_amount) { $this->set_points_values('lottery_jackpot', $current_lottery_jackpot + $lottery_base_amount - $current_lottery_base_amount); } // Update values in phpbb_points_config if ($lottery_enable != $points_config['lottery_enable']) { set_points_config('lottery_enable', $lottery_enable); } if ($lottery_multi_ticket_enable != $points_config['lottery_multi_ticket_enable']) { set_points_config('lottery_multi_ticket_enable', $lottery_multi_ticket_enable); } if ($lottery_last_draw_time > 0) { $this->set_points_values('lottery_last_draw_time', $lottery_last_draw_time); } if ($display_lottery_stats != $points_config['display_lottery_stats']) { set_points_config('display_lottery_stats', $display_lottery_stats); } // Update values in phpbb_points_values $this->set_points_values('lottery_base_amount', $lottery_base_amount); // Check if 0 is entered. Must be > 0 if ($lottery_draw_period < 0) { trigger_error($user->lang['LOTTERY_DRAW_PERIOD_SHORT'] . adm_back_link($this->u_action), E_USER_WARNING); } else { $this->set_points_values('lottery_draw_period', $lottery_draw_period); } $this->set_points_values('lottery_ticket_cost', $lottery_ticket_cost); $this->set_points_values('lottery_name', $lottery_name); $this->set_points_values('lottery_chance', $lottery_chance); $this->set_points_values('lottery_max_tickets', $lottery_max_tickets); $this->set_points_values('lottery_jackpot', $lottery_current_jackpot); // Check, if the entered user_id really exists $sql_array = array('SELECT' => 'user_id', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $lottery_pm_from); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $id_exist = $db->sql_fetchfield('user_id'); $db->sql_freeresult($result); if ($lottery_pm_from == 0) { $this->set_points_values('lottery_pm_from', $lottery_pm_from); } else { if (empty($id_exist)) { trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); } else { $this->set_points_values('lottery_pm_from', $lottery_pm_from); } } // Set last draw time to current time, if draw period activated if ($points_values['lottery_last_draw_time'] == 0 && $points_values['lottery_draw_period'] != 0) { $this->set_points_values('lottery_last_draw_time', time()); } // Set last draw time to 0, if draw period deactivated if ($points_values['lottery_draw_period'] == 0) { $this->set_points_values('lottery_last_draw_time', 0); } // Add logs add_log('admin', 'LOG_MOD_POINTS_LOTTERY'); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } // Delete lottery history $reset_lottery_history = isset($_POST['action_lottery_history']) ? true : false; if ($reset_lottery_history) { if (confirm_box(true)) { if (!$auth->acl_get('a_points')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } switch ($db->sql_layer) { case 'sqlite': case 'firebird': $db->sql_query('DELETE FROM ' . POINTS_LOTTERY_HISTORY_TABLE); break; default: $db->sql_query('TRUNCATE TABLE ' . POINTS_LOTTERY_HISTORY_TABLE); break; } add_log('admin', 'LOG_RESYNC_LOTTERY_HISTORY'); trigger_error($user->lang['LOG_RESYNC_LOTTERY_HISTORY'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('action_lottery_history' => true)); // Display mode confirm_box(false, $user->lang['RESYNC_LOTTERY_HISTORY_CONFIRM'], $s_hidden_fields); } } $template->assign_vars(array('LOTTERY_BASE_AMOUNT' => $points_values['lottery_base_amount'], 'LOTTERY_CURRENT_JACKPOT' => $points_values['lottery_jackpot'], 'LOTTERY_DRAW_PERIOD' => $points_values['lottery_draw_period'] == 0 ? $points_values['lottery_draw_period'] : $points_values['lottery_draw_period'] / 3600, 'LOTTERY_NEXT_DRAWING' => $user->format_date($points_values['lottery_last_draw_time'] + $points_values['lottery_draw_period'], false, true), 'LOTTERY_TICKET_COST' => $points_values['lottery_ticket_cost'], 'LOTTERY_CASH_NAME' => $config['points_name'], 'LOTTERY_NAME' => $points_values['lottery_name'], 'LOTTERY_CHANCE' => $points_values['lottery_chance'], 'LOTTERY_MAX_TICKETS' => $points_values['lottery_max_tickets'], 'LOTTERY_PM_FROM' => $points_values['lottery_pm_from'], 'S_LOTTERY_ENABLE' => $points_config['lottery_enable'] ? true : false, 'S_LOTTERY_MULTI_TICKET_ENABLE' => $points_config['lottery_multi_ticket_enable'] ? true : false, 'S_DISPLAY_LOTTERY_STATS' => $points_config['display_lottery_stats'] ? true : false, 'S_LOTTERY' => true, 'U_ACTION' => $this->u_action)); break; case 'bank': $this->page_title = 'ACP_POINTS_BANK_TITLE'; $this->tpl_name = 'acp_points_bank'; $action = request_var('action', ''); $submit = request_var('submit', ''); $bank_data = $errors = array(); if ($submit) { if (!check_form_key('acp_points')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Values for phpbb_points_config $bank_enable = request_var('bank_enable', 0); // Values for phpbb_points_values $bank_interest = round(request_var('bank_interest', 0.0), 2); $bank_fees = round(request_var('bank_fees', 0.0), 2); $bank_pay_period = round(request_var('bank_pay_period', 0.0), 2) * 86400; $bank_min_withdraw = round(request_var('bank_min_withdraw', 0.0), 2); $bank_min_deposit = round(request_var('bank_min_deposit', 0.0), 2); $bank_interestcut = round(request_var('bank_interestcut', 0.0), 2); $bank_cost = round(request_var('bank_cost', 0.0), 2); $bank_name = utf8_normalize_nfc(request_var('bank_name', '', true)); // Check entered bank interesst - has to be max 100 and cannot be below 0 if ($bank_interest > 100 || $bank_interest < 0) { trigger_error($user->lang['BANK_INTEREST_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check entered bank fees - has to be max 100 and cannot be below 0 if ($bank_fees > 100 || $bank_fees < 0) { trigger_error($user->lang['BANK_FEES_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check the bank period if ($bank_pay_period < 0) { trigger_error($user->lang['BANK_PAY_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Update values in phpbb_points_config if ($bank_enable != $points_config['bank_enable']) { set_points_config('bank_enable', $bank_enable); } // Update values in phpbb_points_values $this->set_points_values('bank_interest', $bank_interest); $this->set_points_values('bank_fees', $bank_fees); $this->set_points_values('bank_pay_period', $bank_pay_period); $this->set_points_values('bank_min_withdraw', $bank_min_withdraw); $this->set_points_values('bank_min_deposit', $bank_min_deposit); $this->set_points_values('bank_interestcut', $bank_interestcut); $this->set_points_values('bank_cost', $bank_cost); $this->set_points_values('bank_name', $bank_name); // Add logs add_log('admin', 'LOG_MOD_POINTS_BANK'); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } // Delete all bank accounts $delete_bank_accounts = isset($_POST['action_bank_points']) ? true : false; if ($delete_bank_accounts) { define('POINTS_BANK_TABLE', $table_prefix . 'points_bank'); if (confirm_box(true)) { if (!$auth->acl_get('a_points')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } switch ($db->sql_layer) { case 'sqlite': case 'firebird': $db->sql_query('DELETE FROM ' . POINTS_BANK_TABLE); break; default: $db->sql_query('TRUNCATE TABLE ' . POINTS_BANK_TABLE); break; } add_log('admin', 'LOG_RESYNC_BANK_ACCOUNTS'); trigger_error($user->lang['LOG_RESYNC_BANK_ACCOUNTS'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('action_bank_points' => true)); // Display mode confirm_box(false, $user->lang['RESYNC_BANK_ACCOUNTS_CONFIRM'], $s_hidden_fields); } } $template->assign_vars(array('BANK_PAY_PERIOD' => $points_values['bank_pay_period'] == 0 ? $points_values['bank_pay_period'] : $points_values['bank_pay_period'] / 86400, 'BANK_POINTS_NAME' => $config['points_name'], 'BANK_FEES' => $points_values['bank_fees'], 'BANK_INTEREST' => $points_values['bank_interest'], 'BANK_MIN_WITHDRAW' => $points_values['bank_min_withdraw'], 'BANK_MIN_DEPOSIT' => $points_values['bank_min_deposit'], 'BANK_INTERESTCUT' => $points_values['bank_interestcut'], 'BANK_COST' => $points_values['bank_cost'], 'BANK_NAME' => $points_values['bank_name'], 'S_BANK_ENABLE' => $points_config['bank_enable'] ? true : false, 'S_POINTS_BANK' => true, 'U_ACTION' => $this->u_action)); break; case 'robbery': $this->page_title = 'ACP_POINTS_ROBBERY_TITLE'; $this->tpl_name = 'acp_points_robbery'; $action = request_var('action', ''); $submit = request_var('submit', ''); $robbery_data = $errors = array(); if ($submit) { if (!check_form_key('acp_points')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Values for phpbb_points_config $robbery_enable = request_var('robbery_enable', 0); $robbery_sendpm = request_var('robbery_sendpm', 0); $robbery_usage = request_var('robbery_usage', 0); // Values for phpbb_points_values $robbery_chance = round(request_var('robbery_chance', 0.0), 2); $robbery_loose = round(request_var('robbery_loose', 0.0), 2); $robbery_max_rob = round(request_var('robbery_max_rob', 0.0), 2); // Check, if entered robbery chance is 0 or below if ($robbery_chance <= 0) { trigger_error($user->lang['ROBBERY_CHANCE_MINIMUM'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check entered robbery chance - has to be max 100 if ($robbery_chance > 100) { trigger_error($user->lang['ROBBERY_CHANCE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check, if entered robbery loose is 0 or below if ($robbery_loose <= 0) { trigger_error($user->lang['ROBBERY_LOOSE_MINIMUM'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check entered robbery loose - has to be max 100 if ($robbery_loose > 100) { trigger_error($user->lang['ROBBERY_LOOSE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check, if entered robbery is 0 or below if ($robbery_max_rob <= 0) { trigger_error($user->lang['ROBBERY_MAX_ROB_MINIMUM'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check entered robbery max rob value - has to be max 100 if ($robbery_max_rob > 100) { trigger_error($user->lang['ROBBERY_MAX_ROB_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Update values in phpbb_points_config if ($robbery_enable != $points_config['robbery_enable']) { set_points_config('robbery_enable', $robbery_enable); } if ($robbery_sendpm != $points_config['robbery_sendpm']) { set_points_config('robbery_sendpm', $robbery_sendpm); } if ($robbery_usage != $points_config['robbery_usage']) { set_points_config('robbery_usage', $robbery_usage); } // Update values in phpbb_points_values $this->set_points_values('robbery_chance', $robbery_chance); $this->set_points_values('robbery_loose', $robbery_loose); $this->set_points_values('robbery_max_rob', $robbery_max_rob); // Add logs add_log('admin', 'LOG_MOD_POINTS_ROBBERY'); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } $template->assign_vars(array('ROBBERY_CHANCE' => $points_values['robbery_chance'], 'ROBBERY_LOOSE' => $points_values['robbery_loose'], 'ROBBERY_MAX_ROB' => $points_values['robbery_max_rob'], 'ROBBERY_USAGE' => $points_config['robbery_usage'] ? true : false, 'S_ROBBERY_ENABLE' => $points_config['robbery_enable'] ? true : false, 'S_ROBBERY_SENDPM' => $points_config['robbery_sendpm'] ? true : false, 'S_ROBBERY' => true, 'U_ACTION' => $this->u_action)); break; case 'userguide': $this->page_title = 'ACP_POINTS_USERGUIDE_TITLE'; $this->tpl_name = 'acp_points_userguide'; $template->assign_vars(array('S_IN_POINTS_USERGUIDE' => true, 'L_BACK_TO_TOP' => $user->lang['BACK_TO_TOP'], 'ICON_BACK_TO_TOP' => '<img src="' . $phpbb_admin_path . 'images/icon_up.gif" style="vertical-align: middle;" alt="' . $user->lang['BACK_TO_TOP'] . '" title="' . $user->lang['BACK_TO_TOP'] . '" />')); $user->add_lang_ext('points', false, true); // Pull the array data from the lang pack foreach ($user->help as $help_ary) { if ($help_ary[0] == '--') { $template->assign_block_vars('userguide_block', array('BLOCK_TITLE' => $help_ary[1])); continue; } $template->assign_block_vars('userguide_block.userguide_row', array('USERGUIDE_QUESTION' => $help_ary[0], 'USERGUIDE_ANSWER' => $help_ary[1])); } break; case 'forumpoints': $this->page_title = 'ACP_POINTS_FORUM_TITLE'; $this->tpl_name = 'acp_points_forum'; $action = request_var('action', ''); $submit = request_var('submit', ''); $forum_data = $errors = array(); $extension_points_list = request_var('points_extension', array(0)); $extension_points_costs = request_var('points_extension_costs', array(0.0)); $set_point_switches = request_var('action_point_switches', ''); $set_point_values = request_var('action_point_values', ''); // Update forum points switches if ($set_point_switches) { if (!check_form_key('acp_points')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Get config values $pertopic_enable = request_var('pertopic_enable', 0); $perpost_enable = request_var('perpost_enable', 0); $peredit_enable = request_var('peredit_enable', 0); // Update config values if ($pertopic_enable != $points_config['pertopic_enable']) { set_points_config('pertopic_enable', $pertopic_enable); } if ($perpost_enable != $points_config['perpost_enable']) { set_points_config('perpost_enable', $perpost_enable); } if ($peredit_enable != $points_config['peredit_enable']) { set_points_config('peredit_enable', $peredit_enable); } // Add logs add_log('admin', 'LOG_MOD_POINTS_FORUM_SWITCH'); trigger_error($user->lang['FORUM_POINT_SETTINGS_UPDATED'] . adm_back_link($this->u_action)); } // Update forum points values if ($set_point_values) { if (confirm_box(true)) { $forum_topic = round(request_var('forum_topic', 0.0), 2); $forum_post = round(request_var('forum_post', 0.0), 2); $forum_edit = round(request_var('forum_edit', 0.0), 2); $forum_costs = request_var('forum_costs', 1); // Update values in phpbb_points_values $this->set_points_values('forum_topic', $forum_topic); $this->set_points_values('forum_post', $forum_post); $this->set_points_values('forum_edit', $forum_edit); // Update all forum points and attachment costs $data = array('forum_pertopic' => $forum_topic, 'forum_perpost' => $forum_post, 'forum_peredit' => $forum_edit, 'forum_costs' => $forum_costs); $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $data); $db->sql_query($sql); // Add logs add_log('admin', 'LOG_MOD_POINTS_FORUM'); trigger_error($user->lang['FORUM_POINT_SETTINGS_UPDATED'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('forum_topic' => request_var('forum_topic', 0.0), 'forum_post' => request_var('forum_post', 0.0), 'forum_edit' => request_var('forum_edit', 0.0), 'forum_costs' => request_var('forum_costs', 1), 'mode' => $mode, 'action' => $action, 'action_point_values' => true)); confirm_box(false, 'FORUM_POINT_UPDATE', $s_hidden_fields); } } $add_extension_points = request_var('points_extension', 0); $add_extension_points_costs = request_var('points_extension_costs', 0.0); $template->assign_vars(array('FORUM_POINTS_NAME' => $config['points_name'], 'FORUM_TOPIC' => $points_values['forum_topic'], 'FORUM_POST' => $points_values['forum_post'], 'FORUM_EDIT' => $points_values['forum_edit'], 'PERTOPIC_ENABLE' => $points_config['pertopic_enable'], 'PERPOST_ENABLE' => $points_config['perpost_enable'], 'PEREDIT_ENABLE' => $points_config['peredit_enable'], 'S_FORUMPOINTS' => true, 'FORUM_COSTS' => false, 'ADD_EXTENSION_POINTS' => isset($add_extension_points) ? $add_extension_points : '', 'ADD_EXTENSION_POINTS_COSTS' => isset($add_extension_points_costs) ? $add_extension_points_costs : '', 'POINTS_NAME' => $config['points_name'], 'U_ACTION' => $this->u_action)); $sql = 'SELECT points_extension, points_extension_costs FROM ' . EXTENSIONS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if ($set_point_values) { if (confirm_box(true)) { $extension_points_list = request_var('points_extension', array(0)); $extension_points_costs = request_var('points_extension_costs', 0); $extensions_points = array(); for ($i = 0, $size = sizeof($extension_points_list); $i < $size; $i++) { $extensions_points[$extension_points_list[$i]] = true; } print_r($extension_points_cost); $new_extension_points = isset($extensions_points[$row['extension_id']]) ? 1 : 0; if ($row['points_extension'] != $new_extension_points) { $sql = 'UPDATE ' . EXTENSIONS_TABLE . ' SET points_extension = ' . (int) $new_extension_points . ' WHERE extension_id = ' . $row['extension_id']; $db->sql_query($sql); add_log('admin', 'LOG_ATTACH_POINTS_EXT_UPDATE', $row['extension']); } if ($row['points_extension_costs'] != $extension_points_costs[$row['extension_id']]) { $sql = 'UPDATE ' . EXTENSIONS_TABLE . ' SET points_extension_costs = ' . (double) $extension_points_costs[$row['extension_id']] . ' WHERE extension_id = ' . $row['extension_id']; $db->sql_query($sql); add_log('admin', 'LOG_ATTACH_POINTS_EXT_UPDATE', $row['extension']); } } } $template->assign_vars(array('EXTENSION_POINTS' => $row['points_extension'], 'EXTENSION_POINTS_COSTS' => $row['points_extension_costs'])); } break; } $template->assign_vars(array('U_ACTION' => $this->u_action, 'VIPAKA_POINTS_ENABLE' => $config['points_enable'])); }
function main($id, $mode) { global $db, $user, $auth, $template, $cache; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx; include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx; $auth_admin = new auth_admin(); $user->add_lang('acp/permissions'); $user->add_lang('acp/permissions_phpbb'); $this->tpl_name = 'acp_permissions'; // Trace has other vars if ($mode == 'trace') { $user_id = request_var('u', 0); $forum_id = request_var('f', 0); $permission = request_var('auth', ''); $this->tpl_name = 'permission_trace'; if ($user_id && isset($auth_admin->option_ids[$permission]) && $auth->acl_get('a_viewauth')) { $this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $user->lang['acl_' . $permission]['lang']); $this->permission_trace($user_id, $forum_id, $permission); return; } trigger_error('NO_MODE'); } // Set some vars $action = request_var('action', array('' => 0)); $action = key($action); $action = isset($_POST['psubmit']) ? 'apply_permissions' : $action; $all_forums = request_var('all_forums', 0); $subforum_id = request_var('subforum_id', 0); $forum_id = request_var('forum_id', array(0)); $username = request_var('username', array(''), true); $usernames = request_var('usernames', '', true); $user_id = request_var('user_id', array(0)); $group_id = request_var('group_id', array(0)); $select_all_groups = request_var('select_all_groups', 0); // If select all groups is set, we pre-build the group id array (this option is used for other screens to link to the permission settings screen) if ($select_all_groups) { // Add default groups to selection $sql_and = $config['coppa_hide_groups'] ? " AND group_name NOT IN ('INACTIVE_COPPA', 'REGISTERED_COPPA')" : ''; $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_type = ' . GROUP_SPECIAL . "\n\t\t\t\t{$sql_and}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $group_id[] = $row['group_id']; } $db->sql_freeresult($result); } // Map usernames to ids and vice versa if ($usernames) { $username = explode("\n", $usernames); } unset($usernames); if (sizeof($username) && !sizeof($user_id)) { user_get_id_name($user_id, $username); if (!sizeof($user_id)) { trigger_error($user->lang['SELECTED_USER_NOT_EXIST'] . adm_back_link($this->u_action)); } } unset($username); // Build forum ids (of all forums are checked or subforum listing used) if ($all_forums) { $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' ORDER BY left_id'; $result = $db->sql_query($sql); $forum_id = array(); while ($row = $db->sql_fetchrow($result)) { $forum_id[] = $row['forum_id']; } $db->sql_freeresult($result); } else { if ($subforum_id) { $forum_id = array(); foreach (get_forum_branch($subforum_id, 'children') as $row) { $forum_id[] = $row['forum_id']; } } } // Define some common variables for every mode $error = array(); $permission_scope = strpos($mode, '_global') !== false ? 'global' : 'local'; // Showing introductionary page? if ($mode == 'intro') { $this->page_title = 'ACP_PERMISSIONS'; $template->assign_vars(array('S_INTRO' => true)); return; } switch ($mode) { case 'setting_user_global': case 'setting_group_global': $this->permission_dropdown = array('u_', 'm_', 'a_'); $permission_victim = $mode == 'setting_user_global' ? array('user') : array('group'); $this->page_title = $mode == 'setting_user_global' ? 'ACP_USERS_PERMISSIONS' : 'ACP_GROUPS_PERMISSIONS'; break; case 'setting_user_local': case 'setting_group_local': $this->permission_dropdown = array('f_', 'm_'); $permission_victim = $mode == 'setting_user_local' ? array('user', 'forums') : array('group', 'forums'); $this->page_title = $mode == 'setting_user_local' ? 'ACP_USERS_FORUM_PERMISSIONS' : 'ACP_GROUPS_FORUM_PERMISSIONS'; break; case 'setting_admin_global': case 'setting_mod_global': $this->permission_dropdown = strpos($mode, '_admin_') !== false ? array('a_') : array('m_'); $permission_victim = array('usergroup'); $this->page_title = $mode == 'setting_admin_global' ? 'ACP_ADMINISTRATORS' : 'ACP_GLOBAL_MODERATORS'; break; case 'setting_mod_local': case 'setting_forum_local': $this->permission_dropdown = $mode == 'setting_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup'); $this->page_title = $mode == 'setting_mod_local' ? 'ACP_FORUM_MODERATORS' : 'ACP_FORUM_PERMISSIONS'; break; case 'view_admin_global': case 'view_user_global': case 'view_mod_global': $this->permission_dropdown = $mode == 'view_admin_global' ? array('a_') : ($mode == 'view_user_global' ? array('u_') : array('m_')); $permission_victim = array('usergroup_view'); $this->page_title = $mode == 'view_admin_global' ? 'ACP_VIEW_ADMIN_PERMISSIONS' : ($mode == 'view_user_global' ? 'ACP_VIEW_USER_PERMISSIONS' : 'ACP_VIEW_GLOBAL_MOD_PERMISSIONS'); break; case 'view_mod_local': case 'view_forum_local': $this->permission_dropdown = $mode == 'view_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup_view'); $this->page_title = $mode == 'view_mod_local' ? 'ACP_VIEW_FORUM_MOD_PERMISSIONS' : 'ACP_VIEW_FORUM_PERMISSIONS'; break; default: trigger_error('INVALID_MODE'); } $template->assign_vars(array('L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'])); // Get permission type $permission_type = request_var('type', $this->permission_dropdown[0]); if (!in_array($permission_type, $this->permission_dropdown)) { trigger_error($user->lang['WRONG_PERMISSION_TYPE'] . adm_back_link($this->u_action)); } // Handle actions if (strpos($mode, 'setting_') === 0 && $action) { switch ($action) { case 'delete': $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id); break; case 'apply_permissions': if (!isset($_POST['setting'])) { trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action)); } $this->set_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; case 'apply_all_permissions': if (!isset($_POST['setting'])) { trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action)); } $this->set_all_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; } } // Setting permissions screen $s_hidden_fields = build_hidden_fields(array('user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'type' => $permission_type)); // Go through the screens/options needed and present them in correct order foreach ($permission_victim as $victim) { switch ($victim) { case 'forum_dropdown': if (sizeof($forum_id)) { $this->check_existence('forum', $forum_id); continue 2; } $template->assign_vars(array('S_SELECT_FORUM' => true, 'S_FORUM_OPTIONS' => make_forum_select(false, false, true, false, false))); break; case 'forums': if (sizeof($forum_id)) { $this->check_existence('forum', $forum_id); continue 2; } $forum_list = make_forum_select(false, false, true, false, false, true); // Build forum options $s_forum_options = ''; foreach ($forum_list as $f_id => $f_row) { $s_forum_options .= '<option value="' . $f_id . '"' . $f_row['selected'] . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>'; } // Build subforum options $s_subforum_options = $this->build_subforum_options($forum_list); $template->assign_vars(array('S_SELECT_FORUM' => true, 'S_FORUM_OPTIONS' => $s_forum_options, 'S_SUBFORUM_OPTIONS' => $s_subforum_options, 'S_FORUM_ALL' => true, 'S_FORUM_MULTIPLE' => true)); break; case 'user': if (sizeof($user_id)) { $this->check_existence('user', $user_id); continue 2; } $template->assign_vars(array('S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=select_victim&field=username'))); break; case 'group': if (sizeof($group_id)) { $this->check_existence('group', $group_id); continue 2; } $template->assign_vars(array('S_SELECT_GROUP' => true, 'S_GROUP_OPTIONS' => group_select_options(false))); break; case 'usergroup': case 'usergroup_view': if (sizeof($user_id) || sizeof($group_id)) { if (sizeof($user_id)) { $this->check_existence('user', $user_id); } if (sizeof($group_id)) { $this->check_existence('group', $group_id); } continue 2; } $sql_forum_id = $permission_scope == 'global' ? 'AND a.forum_id = 0' : (sizeof($forum_id) ? 'AND a.forum_id IN (' . implode(', ', $forum_id) . ')' : 'AND a.forum_id <> 0'); $sql_permission_option = "AND o.auth_option LIKE '" . $db->sql_escape($permission_type) . "%'"; $sql = $db->sql_build_query('SELECT_DISTINCT', array('SELECT' => 'u.username, u.user_regdate, u.user_id', 'FROM' => array(USERS_TABLE => 'u', ACL_OPTIONS_TABLE => 'o', ACL_USERS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), 'ON' => 'a.auth_role_id = r.role_id')), 'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)\n\t\t\t\t\t\t\t{$sql_permission_option}\n\t\t\t\t\t\t\t{$sql_forum_id}\n\t\t\t\t\t\t\tAND u.user_id = a.user_id", 'ORDER_BY' => 'u.username, u.user_regdate ASC')); $result = $db->sql_query($sql); $s_defined_user_options = ''; $defined_user_ids = array(); while ($row = $db->sql_fetchrow($result)) { $s_defined_user_options .= '<option value="' . $row['user_id'] . '">' . $row['username'] . '</option>'; $defined_user_ids[] = $row['user_id']; } $db->sql_freeresult($result); $sql = $db->sql_build_query('SELECT_DISTINCT', array('SELECT' => 'g.group_type, g.group_name, g.group_id', 'FROM' => array(GROUPS_TABLE => 'g', ACL_OPTIONS_TABLE => 'o', ACL_GROUPS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), 'ON' => 'a.auth_role_id = r.role_id')), 'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)\n\t\t\t\t\t\t\t{$sql_permission_option}\n\t\t\t\t\t\t\t{$sql_forum_id}\n\t\t\t\t\t\t\tAND g.group_id = a.group_id", 'ORDER_BY' => 'g.group_type DESC, g.group_name ASC')); $result = $db->sql_query($sql); $s_defined_group_options = ''; $defined_group_ids = array(); while ($row = $db->sql_fetchrow($result)) { $s_defined_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>'; $defined_group_ids[] = $row['group_id']; } $db->sql_freeresult($result); // Now we check the users... because the "all"-selection is different here (all defined users/groups) $all_users = isset($_POST['all_users']) ? true : false; $all_groups = isset($_POST['all_groups']) ? true : false; if ($all_users && sizeof($defined_user_ids)) { $user_id = $defined_user_ids; continue 2; } if ($all_groups && sizeof($defined_group_ids)) { $group_id = $defined_group_ids; continue 2; } $template->assign_vars(array('S_SELECT_USERGROUP' => $victim == 'usergroup' ? true : false, 'S_SELECT_USERGROUP_VIEW' => $victim == 'usergroup_view' ? true : false, 'S_DEFINED_USER_OPTIONS' => $s_defined_user_options, 'S_DEFINED_GROUP_OPTIONS' => $s_defined_group_options, 'S_ADD_GROUP_OPTIONS' => group_select_options(false, $defined_group_ids), 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=add_user&field=username'))); break; } $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_VICTIM' => true, 'S_CAN_SELECT_USER' => $auth->acl_get('a_authusers') ? true : false, 'S_CAN_SELECT_GROUP' => $auth->acl_get('a_authgroups') ? true : false, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); // Let the forum names being displayed if (sizeof($forum_id)) { $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id IN (' . implode(', ', $forum_id) . ') ORDER BY forum_name ASC'; $result = $db->sql_query($sql); $forum_names = array(); while ($row = $db->sql_fetchrow($result)) { $forum_names[] = $row['forum_name']; } $db->sql_freeresult($result); $template->assign_vars(array('S_FORUM_NAMES' => sizeof($forum_names) ? true : false, 'FORUM_NAMES' => implode(', ', $forum_names))); } return; } // Do not allow forum_ids being set and no other setting defined (will bog down the server too much) if (sizeof($forum_id) && !sizeof($user_id) && !sizeof($group_id)) { trigger_error($user->lang['ONLY_FORUM_DEFINED'] . adm_back_link($this->u_action)); } $template->assign_vars(array('S_PERMISSION_DROPDOWN' => sizeof($this->permission_dropdown) > 1 ? $this->build_permission_dropdown($this->permission_dropdown, $permission_type) : false, 'L_PERMISSION_TYPE' => $user->lang['ACL_TYPE_' . strtoupper($permission_type)], 'U_ACTION' => $this->u_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); if (strpos($mode, 'setting_') === 0) { $template->assign_vars(array('S_SETTING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('set', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_UNSET); $auth_admin->display_mask('set', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } else { $template->assign_vars(array('S_VIEWING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('view', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_NO); $auth_admin->display_mask('view', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } }
function main($id, $mode) { global $db, $user, $auth, $template, $cache, $phpEx; global $config, $phpbb_root_path, $phpbb_admin_path; include $phpbb_root_path . 'includes/functions_user.' . $phpEx; include $phpbb_root_path . 'includes/functions_invite.' . $phpEx; $user->add_lang(array('ucp', 'mods/info_acp_invite', 'acp/board', 'acp/email')); $invite = new invite(); $action = request_var('action', ''); $submit = isset($_POST['submit']) ? true : false; $error = array(); foreach ($invite->config as $k => $v) { $new_config[$k] = utf8_normalize_nfc(request_var($k, $v, true)); } $form_key = 'acp_invite'; add_form_key($form_key); if (request_var('version_check', false)) { $mode = 'version'; } if (!$invite->config['enable']) { $error[] = $user->lang['ACP_IAF_DISABLED']; } if ($invite->config['enable'] && !$config['email_enable']) { $error[] = sprintf($user->lang['ERROR_EMAIL_DISABLED'], append_sid("{$phpbb_admin_path}index.{$phpEx}?i=board&mode=email")); } switch ($mode) { case 'overview': $this->page_title = 'ACP_INVITE_OVERVIEW'; $this->tpl_name = 'acp_invite_overview'; // Calculate stats $days_installed = (time() - $invite->config['tracking_time']) / 86400; $invitations_per_day = sprintf('%.2f', $invite->config['num_invitations'] / $days_installed); $registrations_per_day = sprintf('%.2f', $invite->config['num_registrations'] / $days_installed); $referrals_per_day = sprintf('%.2f', $invite->config['num_referrals'] / $days_installed); $install_date = $user->format_date($invite->config['tracking_time']); // Version check $latest_version_info = $update_to_date = false; if (($latest_version_info = $this->latest_version_info(request_var('versioncheck_force', false))) === false) { $template->assign_var('S_VERSIONCHECK_FAIL', true); } else { $latest_version_info = explode("\n", $latest_version_info); $up_to_date = phpbb_version_compare($invite->config['version'], trim($latest_version_info[0]), '<') ? false : true; } if ($action) { if (!confirm_box(true)) { switch ($action) { case 'sync_referral_data': $confirm = true; $confirm_lang = 'ACP_INVITE_CONFIRM_SYNC_REFERRAL_DATA'; break; default: $confirm = false; break; } if ($confirm) { confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action))); } } else { switch ($action) { case 'sync_referral_data': // Get an idea of which users need to be updated $sql = 'SELECT invite_user_id, register_user_id, invite_time FROM ' . INVITE_LOG_TABLE . ' WHERE register_key_used = 1'; $result = $db->sql_query($sql); $uid_array = $db->sql_fetchrowset($result); $db->sql_freeresult($result); for ($i = 0; $i < sizeof($uid_array); $i++) { if ($invite->config['referral_invitation_bridge']) { $sql = 'SELECT COUNT(referrer_id) AS is_existent FROM ' . INVITE_REFERRALS_TABLE . ' WHERE referrer_id = ' . (int) $uid_array[$i]['invite_user_id'] . ' AND referral_id = ' . (int) $uid_array[$i]['register_user_id']; $result = $db->sql_query($sql); $exists = $db->sql_fetchfield('is_existent'); $db->sql_freeresult($result); if (!$exists) { $sql_ary = array('user_referrer_id' => $uid_array[$i]['invite_user_id'], 'user_referrer_name' => $invite->user_return_data($uid_array[$i]['invite_user_id'], 'user_id', 'username_clean')); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . (int) $uid_array[$i]['register_user_id']; $result = $db->sql_query($sql); $db->sql_freeresult($result); $sql_ary = array('referrer_id' => $uid_array[$i]['invite_user_id'], 'referral_id' => $uid_array[$i]['register_user_id'], 'time' => $uid_array[$i]['invite_time']); $sql = 'INSERT INTO ' . INVITE_REFERRALS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); } } else { $sql_ary = array('user_referrer_id' => 0, 'user_referrer_name' => ''); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . (int) $uid_array[$i]['register_user_id']; $result = $db->sql_query($sql); $db->sql_freeresult($result); $sql = 'DELETE FROM ' . INVITE_REFERRALS_TABLE . ' WHERE referrer_id = ' . (int) $uid_array[$i]['invite_user_id'] . ' AND referral_id = ' . (int) $uid_array[$i]['register_user_id']; $db->sql_query($sql); $sql = 'SELECT COUNT(referrer_id) AS total_referrals FROM ' . INVITE_REFERRALS_TABLE; $result = $db->sql_query($sql); $total_referrals = $db->sql_fetchfield('total_referrals'); $db->sql_freeresult($result); $sql = 'UPDATE ' . INVITE_CONFIG_TABLE . ' SET config_value = ' . (int) $total_referrals . ' WHERE config_name = "num_referrals"'; $result = $db->sql_query($sql); $db->sql_freeresult($result); $sql = 'SELECT COUNT(referrer_id) AS user_referrals FROM ' . INVITE_REFERRALS_TABLE . ' WHERE referrer_id = ' . (int) $uid_array[$i]['invite_user_id']; $result = $db->sql_query($sql); $user_referrals = $db->sql_fetchfield('user_referrals'); $db->sql_freeresult($result); $sql = 'UPDATE ' . USERS_TABLE . ' SET user_referrals = ' . $user_referrals . ' WHERE user_id = ' . (int) $uid_array[$i]['invite_user_id']; $result = $db->sql_query($sql); $db->sql_freeresult($result); } // Synch stats $sql = 'SELECT COUNT(referrer_id) AS total_referrals FROM ' . INVITE_REFERRALS_TABLE; $result = $db->sql_query($sql); $total_referrals = $db->sql_fetchfield('total_referrals'); $db->sql_freeresult($result); $sql = 'UPDATE ' . INVITE_CONFIG_TABLE . ' SET config_value = ' . (int) $total_referrals . ' WHERE config_name = "num_referrals"'; $result = $db->sql_query($sql); $sql = 'SELECT COUNT(referrer_id) AS user_referrals FROM ' . INVITE_REFERRALS_TABLE . ' WHERE referrer_id = ' . (int) $uid_array[$i]['invite_user_id']; $result = $db->sql_query($sql); $user_referrals = $db->sql_fetchfield('user_referrals'); $db->sql_freeresult($result); $sql = 'UPDATE ' . USERS_TABLE . ' SET user_referrals = ' . $user_referrals . ' WHERE user_id = ' . (int) $uid_array[$i]['invite_user_id']; $result = $db->sql_query($sql); } break; default: trigger_error('NO_MODE', E_USER_ERROR); break; } add_log('admin', 'LOG_INVITE_' . strtoupper($action)); trigger_error($user->lang['ACP_INVITE_' . strtoupper($action) . '_SUCCESS'] . adm_back_link($this->u_action)); } } if ($submit) { if (!check_form_key($form_key)) { $error[] = $user->lang['FORM_INVALID']; } foreach ($new_config as $k => $v) { $invite->set_config($k, $v); } add_log('admin', 'LOG_INVITE_SETTINGS_UPDATED'); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } foreach ($new_config as $k => $v) { $template->assign_vars(array('S_' . strtoupper($k) => $v)); } $template->assign_vars(array('ERROR' => sizeof($error) ? array_pop($error) : '', 'TOTAL_INVITATIONS' => $invite->config['num_invitations'], 'INVITATIONS_PER_DAY' => $invitations_per_day, 'TOTAL_SUCCESSFUL_INVITATIONS' => $invite->config['num_registrations'], 'SUCCESSFUL_INVITATIONS_PER_DAY' => $registrations_per_day, 'TOTAL_REFERRALS' => $invite->config['num_referrals'], 'REFERRALS_PER_DAY' => $referrals_per_day, 'INSTALL_DATE' => $install_date, 'INVITE_VERSION' => $invite->config['version'], 'U_ACTION' => $this->u_action, 'U_VERSIONCHECK' => $this->u_action . '&version_check=1', 'U_VERSIONCHECK_FORCE' => $this->u_action . '&versioncheck_force=1', 'S_VERSION_UP_TO_DATE' => $up_to_date, 'S_SETTINGS_AUTH' => $auth->acl_get('acl_a_invite_settings') ? true : false, 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false)); break; case 'version': $this->page_title = 'ACP_INVITE_OVERVIEW'; $this->tpl_name = 'acp_invite_overview'; $user->add_lang('install'); $errstr = ''; $errno = 0; $info = $this->latest_version_info(request_var('versioncheck_force', false), true); if ($info === false) { trigger_error('VERSIONCHECK_FAIL', E_USER_WARNING); } $info = explode("\n", $info); $latest_version = trim($info[0]); $announcement_url = trim($info[1]); $announcement_url = strpos($announcement_url, '&') === false ? str_replace('&', '&', $announcement_url) : $announcement_url; $update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx); $next_feature_version = $next_feature_announcement_url = false; if (isset($info[2]) && trim($info[2]) !== '') { $next_feature_version = trim($info[2]); $next_feature_announcement_url = trim($info[3]); } $up_to_date = phpbb_version_compare($invite->config['version'], $latest_version, '<') ? false : true; $template->assign_vars(array('S_VERSION_CHECK' => true, 'S_UP_TO_DATE' => $up_to_date, 'U_VERSIONCHECK_FORCE' => $this->u_action . '&version_check=1&versioncheck_force=1', 'LATEST_VERSION' => '<strong style="color:#228822">' . $latest_version . '</strong>', 'CURRENT_VERSION' => '<strong style="color:#' . ($up_to_date ? '228822' : 'BC2A4D') . '">' . $invite->config['version'] . '</strong>', 'NEXT_FEATURE_VERSION' => $next_feature_version, 'UPDATE_INSTRUCTIONS' => sprintf($user->lang['ACP_INVITE_UPDATE_INSTRUCTIONS'], $announcement_url, $update_link), 'UPGRADE_INSTRUCTIONS' => $next_feature_version ? $user->lang('INVITE_UPGRADE_INSTRUCTIONS', $next_feature_version, $next_feature_announcement_url) : false)); break; case 'settings': case 'referral_settings': $this->page_title = $mode == 'referral_settings' ? 'ACP_REFERRAL_SETTINGS' : 'ACP_INVITE_SETTINGS'; $this->tpl_name = $mode == 'referral_settings' ? 'acp_invite_referral' : 'acp_invite'; $queue_time_m = request_var('queue_time_m', floor($invite->config['queue_time'] / 60)); $queue_time_s = request_var('queue_time_s', $invite->config['queue_time'] % 60); if (!$invite->config['enable_invitation'] && $mode == 'settings') { $error[] = $user->lang['ACP_INVITATION_DISABLED']; } if (!$invite->config['enable_referral'] && $mode == 'referral_settings') { $error[] = $user->lang['ACP_REFERRAL_DISABLED']; } if ($submit) { $new_config['queue_time'] = $queue_time_s + $queue_time_m * 60; $check_ary = array('queue_time' => array('num', true, 1, 9999999999), 'message_min_chars' => array('num', true, 1, 9999), 'message_max_chars' => array('num', false, 1, 9999), 'subject_min_chars' => array('num', false, 1, 999), 'subject_max_chars' => array('num', false, 1, 999)); $error = validate_data($new_config, $check_ary); if (!check_form_key($form_key)) { $error[] = $user->lang['FORM_INVALID']; } // No errors.. continue! if (!sizeof($error)) { foreach ($new_config as $k => $v) { $invite->set_config($k, $v); } add_log('admin', 'LOG_INVITE_SETTINGS_UPDATED'); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } foreach ($new_config as $k => $v) { $template->assign_vars(array('S_' . strtoupper($k) => $v)); } $template->assign_vars(array('ERROR' => sizeof($error) ? array_pop($error) : '', 'S_VALUE_EMAIL' => EMAIL, 'S_VALUE_PM' => PM, 'S_VALUE_OPTIONAL' => OPTIONAL, 'S_GROUP_SELECT' => group_select_options($new_config['key_group'], false, 0), 'S_EMAIL_ENABLE' => $config['email_enable'] ? true : false, 'S_SELECT_LANGUAGE' => $this->build_select('language', '', $new_config['invite_language_select']), 'S_SELECT_PROFILE_LOCATION' => $this->build_select('profile_location'), 'S_SELECT_PROFILE_TYPE' => $this->build_select('profile_type'), 'S_SELECT_REFERRAL_PROFILE_LOCATION' => $this->build_select('referral_profile_location'), 'S_SELECT_REFERRAL_PROFILE_TYPE' => $this->build_select('referral_profile_type'), 'S_PRIORITY_OPTIONS' => $this->build_select('priority', '', $new_config['invite_priority_flag']), 'S_QUEUE_TIME_M' => $queue_time_m, 'S_QUEUE_TIME_S' => $queue_time_s, 'U_ACTION' => $this->u_action)); if ($invite->ultimate_points_installed()) { $template->assign_vars(array('S_ULTIMATE_POINTS_INSTALLED' => true)); } if ($invite->cash_installed()) { global $cash; $template->assign_vars(array('S_CASH_INSTALLED' => true, 'S_CASH_CURRENCY_INVITE' => $cash->get_currencies($invite->config['cash_id_invite'], true), 'S_CASH_CURRENCY_REGISTER' => $cash->get_currencies($invite->config['cash_id_register'], true))); } break; case 'templates': $this->page_title = 'ACP_INVITE_TEMPLATES'; $this->tpl_name = 'acp_invite_templates'; $select = isset($_POST['select']) ? true : false; $tpl_type = request_var('template_type', '', true); $tpl_lang = request_var('template_language', $user->data['user_lang'], true); $tpl_subject = $select ? $invite->get_template("{$tpl_type}_subject.txt", $tpl_lang) : ''; $tpl_message = $select ? $invite->get_template("{$tpl_type}_message.txt", $tpl_lang) : ''; if ($submit) { $tpl_subject = request_var('template_subject', $invite->get_template("{$tpl_type}_subject.txt", $tpl_lang), true); $tpl_message = request_var('template_message', $invite->get_template("{$tpl_type}_message.txt", $tpl_lang), true); if (!check_form_key($form_key)) { $error[] = $user->lang['FORM_INVALID']; } // No errors.. continue! if (!sizeof($error)) { $invite->set_template($tpl_subject, "{$tpl_type}_subject.txt", $tpl_lang); $invite->set_template($tpl_message, "{$tpl_type}_message.txt", $tpl_lang); add_log('admin', 'LOG_INVITE_TEMPLATES_UPDATED'); trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } } // Output wildcard tables $wildcards['general'] = $this->print_wildcard_array($invite, 'general'); $wildcards['user'] = $this->print_wildcard_array($invite, 'user'); foreach ($wildcards as $type => $data) { foreach ($data as $wildcard => $example_value) { $template->assign_block_vars($type . '_wildcards', array('WILDCARD' => $wildcard, 'EXAMPLE_VALUE' => $example_value)); } } $template->assign_vars(array('ERROR' => sizeof($error) ? array_pop($error) : '', 'TEMPLATE_SUBJECT' => $tpl_subject, 'TEMPLATE_MESSAGE' => $tpl_message, 'S_EDIT_TEMPLATE' => $select ? true : false, 'S_TEMPLATE_TYPE_SELECT' => $this->build_select('message', $invite->INVITE_MESSAGE_TYPE, $tpl_type), 'S_TEMPLATE_LANGUAGE_SELECT' => language_select($tpl_lang))); break; case 'log': $this->page_title = 'ACP_INVITE_LOG'; $this->tpl_name = 'acp_invite_log'; $this->log_type = LOG_INVITE; $start = request_var('start', 0); $show_info = request_var('info', 0); $marked = request_var('mark', array(0)); $filter = request_var('filter', 'all'); $deletemark = isset($_POST['delmarked']) ? true : false; $deleteall = isset($_POST['delall']) ? true : false; $entries_per_page = 25; // Sort keys $sort_days = request_var('st', 0); $sort_key = request_var('sk', 't'); $sort_dir = request_var('sd', 'd'); $sort_user = request_var('ui', '', true); // Delete entries if requested and able if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) { if (confirm_box(true)) { $where_sql = ''; if ($deletemark && sizeof($marked)) { $sql_in = array(); foreach ($marked as $mark) { $sql_in[] = $mark; } $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in); unset($sql_in); } if ($where_sql || $deleteall) { $sql = 'DELETE FROM ' . LOG_TABLE . "\n\t\t\t\t\t\t\t\tWHERE log_type = {$this->log_type}\n\t\t\t\t\t\t\t\t{$where_sql}"; $db->sql_query($sql); } add_log('admin', 'LOG_INVITE_LOG_CLEARED'); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('start' => $start, 'delmarked' => $deletemark, 'delall' => $deleteall, 'mark' => $marked, 'st' => $sort_days, 'sk' => $sort_key, 'sd' => $sort_dir, 'i' => $id, 'mode' => $mode, 'action' => $action))); } } // Sorting $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']); $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation'); $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); // Define where and sort sql for use in displaying logs $sql_where = $sort_days ? time() - $sort_days * 86400 : 0; $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC'); $sql_user = $invite->user_return_data($db->sql_escape(utf8_clean_string($sort_user)), 'username_clean', 'user_id'); // Grab log data $log_data = array(); $log_count = 0; view_log('invite', $log_data, $log_count, $entries_per_page, $start, $sql_user, $filter, $sql_user, $sql_where, $sql_sort); $u_sort_param .= $sql_user ? "&ui={$sort_user}" : ''; $log_count = $sql_user ? $log_count : ($sort_user ? 0 : $log_count); $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_FILTER' => $this->build_select('filter', '', $filter), 'S_ON_PAGE' => on_page($log_count, $entries_per_page, $start), 'PAGINATION' => generate_pagination($this->u_action . "&{$u_sort_param}", $log_count, $entries_per_page, $start, true), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_SORT_USER' => $sort_user ? $sort_user : '', 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'), 'S_USER_ENTRY' => empty($sort_user) ? true : $sql_user)); foreach ($log_data as $row) { // Remove info to fix the bug 'Invitation log - Details' $u_sort_param = $show_info ? str_replace("&info={$show_info}", '', $u_sort_param) : $u_sort_param; $data = array(); $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'REPORTEE_USERNAME' => $row['reportee_username'] && $row['user_id'] != $row['reportee_id'] ? $row['reportee_username_full'] : '', 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'DATA' => sizeof($data) ? implode(' | ', $data) : '', 'ID' => $row['id'])); } break; } }
function main($id, $mode) { global $db, $cache, $config, $user, $lang, $auth, $template, $cms_admin; add_permission_language(); include_once IP_ROOT_PATH . 'includes/class_auth_admin.' . PHP_EXT; $auth_admin = new auth_admin(); // Set some vars $action = request_var('paction', array('' => 0)); $action = key($action); $action = isset($_POST['psubmit']) ? 'apply_permissions' : $action; $all_forums = request_var('all_forums', 0); $subforum_id = request_var('subforum_id', 0); $forum_id = request_var('forum_id', array(0)); $id_type = request_var('id_type', ''); $id_types_array = array('forum', 'block', 'layout', 'layout_special'); $id_type = in_array($id_type, $id_types_array) ? $id_type : $id_types_array[0]; $this->id_type = $id_type; $username = request_var('username', array(''), true); $usernames = request_var('usernames', '', true); $user_id = request_var('user_id', array(0)); $group_id = request_var('group_id', array(0)); $select_all_groups = request_var('select_all_groups', 0); $form_name = 'acp_permissions'; add_form_key($form_name); $this->tpl_name = 'cms_permissions.tpl'; $this->u_action = append_sid($cms_admin->root . '?mode=auth&pmode=' . $mode); /* // Trace has other vars if ($mode == 'trace') { $user_id = request_var('u', 0); $forum_id = request_var('f', 0); $permission = request_var('auth', ''); $this->tpl_name = 'cms_permission_trace.tpl'; if ($user_id && isset($auth_admin->acl_options['id'][$permission])) { $this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $user->lang['acl_' . $permission]['lang']); $this->permission_trace($user_id, $forum_id, $permission); return; } trigger_error('NO_MODE', E_USER_ERROR); } */ // If select all groups is set, we pre-build the group id array (this option is used for other screens to link to the permission settings screen) if ($select_all_groups) { $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_single_user = 0'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $group_id[] = $row['group_id']; } $db->sql_freeresult($result); } // Map usernames to ids and vice versa if ($usernames) { $username = explode("\n", $usernames); } unset($usernames); if (sizeof($username) && !sizeof($user_id)) { user_get_id_name($user_id, $username); if (!sizeof($user_id)) { trigger_error($user->lang['SELECTED_USER_NOT_EXIST'] . page_back_link($this->u_action), E_USER_WARNING); } } unset($username); // Define some common variables for every mode $error = array(); $permission_scope = strpos($mode, '_global') !== false ? 'global' : 'local'; // Showing introductionary page? if ($mode == 'intro') { $this->page_title = 'CMS_PERMISSIONS'; $template->assign_vars(array('S_INTRO' => true)); return; } switch ($mode) { case 'setting_admin_global': case 'setting_mod_global': $this->permission_dropdown = strpos($mode, '_admin_') !== false ? array('a_') : array('m_'); $permission_victim = array('usergroup'); $this->page_title = $mode == 'setting_admin_global' ? 'CMS_PERMISSIONS_ADMINS' : 'CMS_PERMISSIONS_MODS'; break; case 'setting_cms_user_global': case 'setting_cms_group_global': $this->permission_dropdown = array('cms_', 'pl_', 'u_'); $permission_victim = array('usergroup'); //$permission_victim = ($mode == 'setting_cms_user_global') ? array('user') : array('group'); $this->page_title = $mode == 'setting_cms_user_global' ? 'CMS_PERMISSIONS_CMS_USERS' : 'CMS_PERMISSIONS_CMS_GROUPS'; break; case 'setting_cms_user_local': case 'setting_cms_group_local': $this->permission_dropdown = $this->id_type == 'layout' ? array('cmsl_') : ($this->id_type == 'layout_special' ? array('cmss_') : array('cmsb_')); $permission_victim = array('cms', 'usergroup'); //$permission_victim = ($mode == 'setting_cms_user_local') ? array('user') : array('group'); $this->page_title = $mode == 'setting_cms_user_local' ? 'CMS_PERMISSIONS_CMS_USERS' : 'CMS_PERMISSIONS_CMS_GROUPS'; break; case 'setting_plugins_user_global': case 'setting_plugins_group_global': $this->permission_dropdown = array('pl_', 'cms_', 'u_'); $permission_victim = array('usergroup'); //$permission_victim = ($mode == 'setting_plugins_user_global') ? array('user') : array('group'); $this->page_title = $mode == 'setting_plugins_user_global' ? 'CMS_PERMISSIONS_PLUGINS_USERS' : 'CMS_PERMISSIONS_PLUGINS_GROUPS'; break; case 'setting_user_global': case 'setting_group_global': $this->permission_dropdown = array('u_', 'cms_', 'pl_'); $permission_victim = $mode == 'setting_user_global' ? array('user') : array('group'); $this->page_title = $mode == 'setting_user_global' ? 'CMS_PERMISSIONS_USERS' : 'CMS_PERMISSIONS_GROUPS'; break; case 'setting_user_local': case 'setting_group_local': $this->permission_dropdown = array('f_', 'm_'); $permission_victim = $mode == 'setting_user_local' ? array('user') : array('group'); $this->page_title = $mode == 'setting_user_local' ? 'ACP_USERS_FORUM_PERMISSIONS' : 'ACP_GROUPS_FORUM_PERMISSIONS'; break; case 'setting_mod_local': case 'setting_forum_local': $this->permission_dropdown = $mode == 'setting_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup'); $this->page_title = $mode == 'setting_mod_local' ? 'ACP_FORUM_MODERATORS' : 'ACP_FORUM_PERMISSIONS'; break; case 'view_admin_global': case 'view_user_global': case 'view_mod_global': $this->permission_dropdown = $mode == 'view_admin_global' ? array('a_') : ($mode == 'view_user_global' ? array('u_') : array('m_')); $permission_victim = array('usergroup_view'); $this->page_title = $mode == 'view_admin_global' ? 'CMS_PERMISSIONS_ADMINS' : ($mode == 'view_user_global' ? 'CMS_PERMISSIONS_USERS' : 'CMS_PERMISSIONS_MODS'); break; case 'view_mod_local': case 'view_forum_local': $this->permission_dropdown = $mode == 'view_mod_local' ? array('m_') : array('f_'); $permission_victim = array('usergroup_view'); $this->page_title = $mode == 'view_mod_local' ? 'ACP_VIEW_FORUM_MOD_PERMISSIONS' : 'ACP_VIEW_FORUM_PERMISSIONS'; break; default: trigger_error('NO_MODE', E_USER_ERROR); break; } $template->assign_vars(array('L_TITLE' => $lang[$this->page_title], 'L_EXPLAIN' => $lang[$this->page_title . '_EXPLAIN'])); // Get permission type $permission_type = request_var('type', $this->permission_dropdown[0]); if (!in_array($permission_type, $this->permission_dropdown)) { trigger_error($user->lang['WRONG_PERMISSION_TYPE'] . page_back_link($this->u_action), E_USER_WARNING); } // Handle actions if (strpos($mode, 'setting_') === 0 && $action) { switch ($action) { case 'delete': if (confirm_box(true)) { // All users/groups selected? $all_users = isset($_POST['all_users']) ? true : false; $all_groups = isset($_POST['all_groups']) ? true : false; if ($all_users || $all_groups) { $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type); if ($all_users && sizeof($items['user_ids'])) { $user_id = $items['user_ids']; } elseif ($all_groups && sizeof($items['group_ids'])) { $group_id = $items['group_ids']; } } if (sizeof($user_id) || sizeof($group_id)) { $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id); } else { trigger_error($user->lang['NO_USER_GROUP_SELECTED'] . page_back_link($this->u_action), E_USER_WARNING); } } else { if (isset($_POST['cancel'])) { $u_redirect = $this->u_action . '&type=' . $permission_type; foreach ($forum_id as $fid) { $u_redirect .= '&forum_id[]=' . $fid; } redirect($u_redirect); } $s_hidden_fields = array('i' => $id, 'pmode' => $mode, 'paction' => array($action => 1), 'user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'id_type' => $this->id_type, 'type' => $permission_type); if (isset($_POST['all_users'])) { $s_hidden_fields['all_users'] = 1; } if (isset($_POST['all_groups'])) { $s_hidden_fields['all_groups'] = 1; } confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); } break; case 'apply_permissions': if (!isset($_POST['setting'])) { trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . page_back_link($this->u_action), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . page_back_link($this->u_action), E_USER_WARNING); } $this->set_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; case 'apply_all_permissions': if (!isset($_POST['setting'])) { trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . page_back_link($this->u_action), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . page_back_link($this->u_action), E_USER_WARNING); } $this->set_all_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; } } // Setting permissions screen $s_hidden_fields_array = array('user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id); $s_hidden_fields = build_hidden_fields($s_hidden_fields_array); $s_hidden_fields_extra = true; // Go through the screens/options needed and present them in correct order foreach ($permission_victim as $victim) { switch ($victim) { case 'cms': if (sizeof($forum_id)) { $this->check_existence($this->id_type, $forum_id); continue 2; } // We don't have anything selected, so we need to unset these types, because they will be set properly in template... $s_hidden_fields_extra = false; unset($s_hidden_fields_array['id_type']); unset($s_hidden_fields_array['type']); $ids = array(); $ids_data = array(); $types_array = array('l' => 'layout', 's' => 'layout_special', 'b' => 'block'); foreach ($types_array as $type_key => $type_value) { $s_options = ''; $ids_data = $this->check_existence($type_value, $ids, true); foreach ($ids_data as $id_data) { $option_name = $id_data['name']; if ($type_key == 's') { $option_name = isset($lang['auth_view_' . strtolower($option_name)]) ? $lang['auth_view_' . strtolower($option_name)] : (isset($lang['cms_page_name_' . strtolower($option_name)]) ? $lang['cms_page_name_' . strtolower($option_name)] : ucfirst($option_name)); } $s_options .= '<option value="' . (int) $id_data['id'] . '">' . $option_name . ' [' . (int) $id_data['id'] . ']' . '</option>'; } $template->assign_vars(array('S_CMS_' . strtoupper($type_key) . '_OPTIONS' => $s_options)); } $template->assign_vars(array('S_SELECT_CMS' => true)); break; case 'user': case 'group': if (sizeof($user_id)) { $this->check_existence('user', $user_id); continue 2; } if (sizeof($group_id)) { $this->check_existence('group', $group_id); continue 2; } $template->assign_vars(array('S_SELECT_USER' => true, 'S_SELECT_GROUP' => true, 'U_FIND_USERNAME' => append_sid(IP_ROOT_PATH . CMS_PAGE_SEARCH . '?mode=searchuser'), 'S_GROUP_OPTIONS' => group_select_options(false, false, false))); break; case 'usergroup': case 'usergroup_view': $all_users = isset($_POST['all_users']) ? true : false; $all_groups = isset($_POST['all_groups']) ? true : false; if (sizeof($user_id) && !$all_users || sizeof($group_id) && !$all_groups) { if (sizeof($user_id)) { $this->check_existence('user', $user_id); } if (sizeof($group_id)) { $this->check_existence('group', $group_id); } continue 2; } // Now we check the users... because the "all"-selection is different here (all defined users/groups) $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type); if ($all_users && sizeof($items['user_ids'])) { $user_id = $items['user_ids']; continue 2; } if ($all_groups && sizeof($items['group_ids'])) { $group_id = $items['group_ids']; continue 2; } $template->assign_vars(array('S_SELECT_USERGROUP' => $victim == 'usergroup' ? true : false, 'S_SELECT_USERGROUP_VIEW' => $victim == 'usergroup_view' ? true : false, 'S_DEFINED_USER_OPTIONS' => $items['user_ids_options'], 'S_DEFINED_GROUP_OPTIONS' => $items['group_ids_options'], 'S_ADD_GROUP_OPTIONS' => group_select_options(false, $items['group_ids'], false), 'U_FIND_USERNAME' => append_sid(IP_ROOT_PATH . CMS_PAGE_SEARCH . '?mode=searchuser'))); break; } // Let the item names being displayed if (sizeof($forum_id)) { $ids_data = $this->check_existence($this->id_type, $forum_id); $forum_names = array(); foreach ($ids_data as $id_data) { $forum_names[] = $id_data['name']; } $template->assign_vars(array('S_FORUM_NAMES' => sizeof($forum_names) ? true : false, 'FORUM_NAMES' => implode(', ', $forum_names))); } if (!empty($s_hidden_fields_extra)) { // Setting other hidden fields $s_hidden_fields_array = array('id_type' => $this->id_type, 'type' => $permission_type); $s_hidden_fields .= build_hidden_fields($s_hidden_fields_array); } // The S_ALLOW_SELECT parameter below is a measure to lower memory usage. // If there are more than 5 forums selected the admin is not able to select all users/groups too. // We need to see if the number of forums can be increased or need to be decreased. $template->assign_vars(array('U_ACTION' => $this->u_action, 'U_ACTION_USERS' => str_replace('_group_global', '_user_global', $this->u_action), 'U_ACTION_GROUPS' => str_replace('_user_global', '_group_global', $this->u_action), 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_VICTIM' => true, 'S_ALLOW_ALL_SELECT' => false, 'S_CAN_SELECT_USER' => true, 'S_CAN_SELECT_GROUP' => true, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); return; } $template->assign_vars(array('S_PERMISSION_DROPDOWN' => sizeof($this->permission_dropdown) > 1 ? $this->build_permission_dropdown($this->permission_dropdown, $permission_type, $permission_scope) : false, 'L_PERMISSION_TYPE' => $user->lang['ACL_TYPE_' . strtoupper($permission_type)], 'U_ACTION' => $this->u_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); if (strpos($mode, 'setting_') === 0) { $template->assign_vars(array('S_SETTING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('set', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_NO); $auth_admin->display_mask('set', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } else { $template->assign_vars(array('S_VIEWING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('view', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_NEVER); $auth_admin->display_mask('view', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } }
public function display_points() { // Grab some vars $action = $this->request->variable('action', ''); $id = $this->request->variable('id', 0); // Read out config data $sql_array = array('SELECT' => 'config_name, config_value', 'FROM' => array($this->points_config_table => 'c')); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $points_config[$row['config_name']] = $row['config_value']; } $this->db->sql_freeresult($result); $this->template->assign_vars(array_change_key_case($points_config, CASE_UPPER)); // Read out values data $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_values_table => 'v')); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $points_values = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Form key add_form_key('acp_points'); $this->template->assign_vars(array('BASE' => $this->u_action)); $submit = $this->request->variable('submit', ''); if ($submit) { if (!check_form_key('acp_points')) { trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Values for phpbb_config $points_name = $this->request->variable('points_name', '', true); $points_enable = $this->request->variable('points_enable', 0); // Values for phpbb_points_config $points_disablemsg = $this->request->variable('points_disablemsg', '', true); $transfer_enable = $this->request->variable('transfer_enable', 0); $transfer_pm_enable = $this->request->variable('transfer_pm_enable', 0); $comments_enable = $this->request->variable('comments_enable', 0); $uplist_enable = $this->request->variable('uplist_enable', 0); $stats_enable = $this->request->variable('stats_enable', 0); $logs_enable = $this->request->variable('logs_enable', 0); $images_topic_enable = $this->request->variable('images_topic_enable', 0); $images_memberlist_enable = $this->request->variable('images_memberlist_enable', 0); // Values for phpbb_points_values $sql_ary = array('transfer_fee' => $this->request->variable('transfer_fee', 0), 'number_show_per_page' => $this->request->variable('number_show_per_page', 0), 'number_show_top_points' => $this->request->variable('number_show_top_points', 0), 'points_per_attach' => round($this->request->variable('points_per_attach', 0.0), 2), 'points_per_attach_file' => round($this->request->variable('points_per_attach_file', 0.0), 2), 'points_per_poll' => round($this->request->variable('points_per_poll', 0.0), 2), 'points_per_poll_option' => round($this->request->variable('points_per_poll_option', 0.0), 2), 'points_per_topic_word' => round($this->request->variable('points_per_topic_word', 0.0), 2), 'points_per_topic_character' => round($this->request->variable('points_per_topic_character', 0.0), 2), 'points_per_post_word' => round($this->request->variable('points_per_post_word', 0.0), 2), 'points_per_post_character' => round($this->request->variable('points_per_post_character', 0.0), 2), 'reg_points_bonus' => round($this->request->variable('reg_points_bonus', 0.0), 2), 'points_bonus_chance' => round($this->request->variable('points_bonus_chance', 0.0), 2), 'points_bonus_min' => round($this->request->variable('points_bonus_min', 0.0), 2), 'points_bonus_max' => round($this->request->variable('points_bonus_max', 0.0), 2), 'points_per_warn' => round($this->request->variable('points_per_warn', 0.0), 2)); // Check if number_show_per_page is at least 5 $per_page_check = $this->request->variable('number_show_per_page', 0); if ($per_page_check < 5) { trigger_error($this->user->lang['POINTS_SHOW_PER_PAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check if Transfer Fee percent is not more than 100% if ($sql_ary['transfer_fee'] > 100) { trigger_error($this->user->lang['POINTS_TRANSFER_FEE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Update values in phpbb_config if ($points_name != $this->config['points_name']) { $this->config->set('points_name', $points_name); } if ($points_enable != $this->config['points_enable']) { $this->config->set('points_enable', $points_enable); } // Update values in phpbb_points_config if ($points_disablemsg != $points_config['points_disablemsg']) { $this->functions_points->set_points_config('points_disablemsg', $points_disablemsg); } if ($transfer_enable != $points_config['transfer_enable']) { $this->functions_points->set_points_config('transfer_enable', $transfer_enable); } if ($transfer_pm_enable != $points_config['transfer_pm_enable']) { $this->functions_points->set_points_config('transfer_pm_enable', $transfer_pm_enable); } if ($comments_enable != $points_config['comments_enable']) { $this->functions_points->set_points_config('comments_enable', $comments_enable); } if ($uplist_enable != $points_config['uplist_enable']) { $this->functions_points->set_points_config('uplist_enable', $uplist_enable); } if ($stats_enable != $points_config['stats_enable']) { $this->functions_points->set_points_config('stats_enable', $stats_enable); } if ($logs_enable != $points_config['logs_enable']) { $this->functions_points->set_points_config('logs_enable', $logs_enable); } if ($images_topic_enable != $points_config['images_topic_enable']) { $this->functions_points->set_points_config('images_topic_enable', $images_topic_enable); } if ($images_memberlist_enable != $points_config['images_memberlist_enable']) { $this->functions_points->set_points_config('images_memberlist_enable', $images_memberlist_enable); } // Update values in phpbb_points_values $sql = 'UPDATE ' . $this->points_values_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary); $this->db->sql_query($sql); // Add logs $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_MOD_POINTS_SETTINGS'); trigger_error($this->user->lang['POINTS_CONFIG_SUCCESS'] . adm_back_link($this->u_action)); } else { $this->template->assign_vars(array('POINTS_NAME' => $this->config['points_name'], 'POINTS_PER_ATTACH' => $points_values['points_per_attach'], 'POINTS_PER_ATTACH_FILE' => $points_values['points_per_attach_file'], 'POINTS_PER_POLL' => $points_values['points_per_poll'], 'POINTS_PER_POLL_OPTION' => $points_values['points_per_poll_option'], 'POINTS_PER_TOPIC_WORD' => $points_values['points_per_topic_word'], 'POINTS_PER_TOPIC_CHARACTER' => $points_values['points_per_topic_character'], 'POINTS_PER_POST_WORD' => $points_values['points_per_post_word'], 'POINTS_PER_POST_CHARACTER' => $points_values['points_per_post_character'], 'POINTS_PER_WARN' => $points_values['points_per_warn'], 'REG_POINTS_BONUS' => $points_values['reg_points_bonus'], 'POINTS_BONUS_CHANCE' => $points_values['points_bonus_chance'], 'POINTS_BONUS_MIN' => $points_values['points_bonus_min'], 'POINTS_BONUS_MAX' => $points_values['points_bonus_max'], 'NUMBER_SHOW_TOP_POINTS' => $points_values['number_show_top_points'], 'NUMBER_SHOW_PER_PAGE' => $points_values['number_show_per_page'], 'TRANSFER_FEE' => $points_values['transfer_fee'], 'POINTS_ENABLE' => $this->config['points_enable'] ? true : false)); } // Delete all userlogs $reset_pointslogs = isset($_POST['action_points_logs']) ? true : false; if ($reset_pointslogs) { if (confirm_box(true)) { if (!$this->auth->acl_get('a_points')) { trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_layer = $this->db->get_sql_layer(); switch ($sql_layer) { case 'sqlite': case 'firebird': $this->db->sql_query('DELETE FROM ' . $this->table_points_log); break; default: $this->db->sql_query('TRUNCATE TABLE ' . $this->table_points_log); break; } $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_RESYNC_POINTSLOGSCOUNTS'); trigger_error($this->user->lang['LOG_RESYNC_POINTSLOGSCOUNTS'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('action_points_logs' => true)); // Display mode confirm_box(false, $this->user->lang['RESYNC_POINTSLOGS_CONFIRM'], $s_hidden_fields); } } // Delete all userpoints $reset_points_user = isset($_POST['action_points']) ? true : false; if ($reset_points_user) { if (confirm_box(true)) { if (!$this->auth->acl_get('a_points')) { trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_points = 0'); $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_RESYNC_POINTSCOUNTS'); trigger_error($this->user->lang['LOG_RESYNC_POINTSCOUNTS'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('action_points' => true)); // Display mode confirm_box(false, $this->user->lang['RESYNC_POINTS_CONFIRM'], $s_hidden_fields); } } // Transfer or set points for groups $group_transfer = isset($_POST['group_transfer']) ? true : false; $group_transfer_points = $this->request->variable('group_transfer_points', 0.0); $func = $this->request->variable('func', ''); $group_id = $this->request->variable('group_id', 0); $pm_subject = $this->request->variable('pm_subject', '', true); $pm_text = $this->request->variable('pm_text', '', true); $sql_array = array('SELECT' => 'group_id, group_name, group_type', 'FROM' => array(GROUPS_TABLE => 'g'), 'ORDER_BY' => 'group_name'); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $total_groups = $this->db->sql_affectedrows($result); $this->db->sql_freeresult($result); $this->template->assign_vars(array('U_SMILIES' => append_sid("{$this->phpbb_root_path}posting.{$this->phpEx}", 'mode=smilies'), 'S_GROUP_OPTIONS' => group_select_options($total_groups), 'U_ACTION' => $this->u_action)); // Update the points if ($group_transfer) { if (!check_form_key('acp_points')) { trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_array = array('SELECT' => 'group_type, group_name', 'FROM' => array(GROUPS_TABLE => 'g'), 'WHERE' => 'group_id = ' . (int) $group_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $group_name = $row['group_type'] == GROUP_SPECIAL ? $this->user->lang['G_' . $row['group_name']] : $row['group_name']; // Check if we try transfering to BOTS or GUESTS if ($row['group_name'] == 'BOTS' || $row['group_name'] == 'GUESTS') { trigger_error($this->user->lang['POINTS_GROUP_TRANSFER_SEL_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_array = array('SELECT' => 'user_id', 'FROM' => array(USER_GROUP_TABLE => 'g'), 'WHERE' => 'user_pending <> ' . true . ' AND group_id = ' . (int) $group_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $user_ids = array(); while ($row = $this->db->sql_fetchrow($result)) { $user_ids[] = $row['user_id']; } $this->db->sql_freeresult($result); if (sizeof($user_ids)) { $userdata_group = implode(', ', $user_ids); if ($func == 'add') { $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = user_points + {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})"; $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_ADD'); } if ($func == 'substract') { $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = user_points - {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})"; $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_ADD'); } if ($func == 'set') { $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})"; $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_SET'); } $result = $this->db->sql_query($sql); // Send PM, if pm subject and pm comment is entered if ($pm_subject != '' || $pm_text != '') { if ($pm_subject == '' || $pm_text == '') { trigger_error($this->user->lang['POINTS_GROUP_TRANSFER_PM_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } else { $sql_array = array('SELECT' => 'user_id, group_id', 'FROM' => array(USER_GROUP_TABLE => 'g'), 'WHERE' => 'user_pending <> ' . true . ' AND group_id = ' . (int) $group_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $group_to = array(); while ($row = $this->db->sql_fetchrow($result)) { $group_to[$row['group_id']] = 'to'; } // and notify PM to recipient of rating: require_once $this->phpbb_root_path . 'includes/functions_privmsgs.' . $this->phpEx; $poll = $uid = $bitfield = $options = ''; generate_text_for_storage($pm_subject, $uid, $bitfield, $options, false, false, false); generate_text_for_storage($pm_text, $uid, $bitfield, $options, true, true, true); $pm_data = array('address_list' => array('g' => $group_to), 'from_user_id' => $this->user->data['user_id'], 'from_username' => 'Points Transfer', 'icon_id' => 0, 'from_user_ip' => $this->user->data['user_ip'], 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $pm_text, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid); submit_pm('post', $pm_subject, $pm_data, false); $this->db->sql_freeresult($result); } $message = $this->user->lang['POINTS_GROUP_TRANSFER_PM_SUCCESS'] . adm_back_link($this->u_action); trigger_error($message); } else { $message = $this->user->lang['POINTS_GROUP_TRANSFER_SUCCESS'] . adm_back_link($this->u_action); trigger_error($message); } } } $this->template->assign_vars(array('S_POINTS_MAIN' => true, 'S_POINTS_ACTIVATED' => $this->config['points_enable'] ? true : false, 'U_ACTION' => $this->u_action)); // Version check $this->user->add_lang(array('install', 'acp/extensions', 'migrator')); $ext_name = 'dmzx/ultimatepoints'; $md_manager = new \phpbb\extension\metadata_manager($ext_name, $this->config, $this->phpbb_extension_manager, $this->template, $this->user, $this->phpbb_root_path); try { $this->metadata = $md_manager->get_metadata('all'); } catch (\phpbb\extension\exception $e) { trigger_error($e, E_USER_WARNING); } $md_manager->output_template_data(); try { $updates_available = $this->version_check($md_manager, $this->request->variable('versioncheck_force', false)); $this->template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')))); foreach ($updates_available as $branch => $version_data) { $this->template->assign_block_vars('updates_available', $version_data); } } catch (\RuntimeException $e) { $this->template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $this->user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : '')); } }