function ModifySettings() { global $modSettings, $context, $settings, $db_prefix, $txt, $boarddir, $sourcedir; loadTemplate('ManageCalendar'); $context['page_title'] = $txt['calendar_settings']; $context['sub_template'] = 'modify_settings'; // A file we need to show permissions inline. require_once $sourcedir . '/ManagePermissions.php'; $calendarPermissions = array('calendar_view', 'calendar_post', 'calendar_edit_own', 'calendar_edit_any'); // A form was submitted. if (isset($_POST['sc'], $_POST['cal_days_for_index'])) { checkSession(); // Although the display settings are combined to the user, they are seperate to the database. $toSet['cal_showholidaysonindex'] = $_POST['cal_showholidays'] == 'index' || $_POST['cal_showholidays'] == 'all' ? '1' : '0'; $toSet['cal_showbdaysonindex'] = $_POST['cal_showbdays'] == 'index' || $_POST['cal_showbdays'] == 'all' ? '1' : '0'; $toSet['cal_showeventsonindex'] = $_POST['cal_showevents'] == 'index' || $_POST['cal_showevents'] == 'all' ? '1' : '0'; $toSet['cal_showholidaysoncalendar'] = $_POST['cal_showholidays'] == 'cal' || $_POST['cal_showholidays'] == 'all' ? '1' : '0'; $toSet['cal_showbdaysoncalendar'] = $_POST['cal_showbdays'] == 'cal' || $_POST['cal_showbdays'] == 'all' ? '1' : '0'; $toSet['cal_showeventsoncalendar'] = $_POST['cal_showevents'] == 'cal' || $_POST['cal_showevents'] == 'all' ? '1' : '0'; updateSettings(array('cal_enabled' => isset($_POST['cal_enabled']) ? '1' : '0', 'cal_daysaslink' => isset($_POST['cal_daysaslink']) ? '1' : '0', 'cal_showweeknum' => isset($_POST['cal_showweeknum']) ? '1' : '0', 'cal_days_for_index' => (int) $_POST['cal_days_for_index'], 'cal_showholidaysonindex' => $toSet['cal_showholidaysonindex'], 'cal_showbdaysonindex' => $toSet['cal_showbdaysonindex'], 'cal_showeventsonindex' => $toSet['cal_showeventsonindex'], 'cal_showholidaysoncalendar' => $toSet['cal_showholidaysoncalendar'], 'cal_showbdaysoncalendar' => $toSet['cal_showbdaysoncalendar'], 'cal_showeventsoncalendar' => $toSet['cal_showeventsoncalendar'], 'cal_defaultboard' => (int) $_POST['cal_defaultboard'], 'cal_allow_unlinked' => isset($_POST['cal_allow_unlinked']) ? '1' : '0', 'cal_minyear' => (int) $_POST['cal_minyear'], 'cal_maxyear' => (int) $_POST['cal_maxyear'], 'cal_bdaycolor' => $_POST['cal_bdaycolor'], 'cal_eventcolor' => $_POST['cal_eventcolor'], 'cal_holidaycolor' => $_POST['cal_holidaycolor'], 'cal_allowspan' => isset($_POST['cal_allowspan']) ? '1' : '0', 'cal_maxspan' => (int) $_POST['cal_maxspan'], 'cal_showInTopic' => isset($_POST['cal_showInTopic']) ? '1' : '0')); save_inline_permissions($calendarPermissions); updateStats('calendar'); // Ensure we redirect incase the change in settings means the tabs are outdated. redirectexit('action=managecalendar;sa=settings'); } // Load the boards list. $context['cal_boards'] = array(''); $request = db_query("\n\t\tSELECT b.ID_BOARD, b.name AS bName, c.name AS cName\n\t\tFROM {$db_prefix}boards AS b\n\t\t\tLEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)", __FILE__, __LINE__); while ($row = mysql_fetch_assoc($request)) { $context['cal_boards'][$row['ID_BOARD']] = $row['cName'] . ' - ' . $row['bName']; } mysql_free_result($request); // Initialize the inline permission settings. init_inline_permissions($calendarPermissions); // Setup the display settings, just for better UI ;) $context['cal_showholidays'] = empty($modSettings['cal_showholidaysonindex']) ? empty($modSettings['cal_showholidaysoncalendar']) ? 'never' : 'cal' : (empty($modSettings['cal_showholidaysoncalendar']) ? 'index' : 'all'); $context['cal_showbdays'] = empty($modSettings['cal_showbdaysonindex']) ? empty($modSettings['cal_showbdaysoncalendar']) ? 'never' : 'cal' : (empty($modSettings['cal_showbdaysoncalendar']) ? 'index' : 'all'); $context['cal_showevents'] = empty($modSettings['cal_showeventsonindex']) ? empty($modSettings['cal_showeventsoncalendar']) ? 'never' : 'cal' : (empty($modSettings['cal_showeventsoncalendar']) ? 'index' : 'all'); }
function prepareDBSettingContext(&$config_vars) { global $txt, $helptxt, $context, $modSettings, $sourcedir; loadLanguage('Help'); $context['config_vars'] = array(); $inlinePermissions = array(); $bbcChoice = array(); foreach ($config_vars as $config_var) { // HR? if (!is_array($config_var)) { $context['config_vars'][] = $config_var; } else { // If it has no name it doesn't have any purpose! if (empty($config_var[1])) { continue; } // Special case for inline permissions if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) { $inlinePermissions[] = $config_var[1]; } elseif ($config_var[0] == 'permissions') { continue; } // Are we showing the BBC selection box? if ($config_var[0] == 'bbc') { $bbcChoice[] = $config_var[1]; } $context['config_vars'][$config_var[1]] = array('label' => isset($config_var['text_label']) ? $config_var['text_label'] : (isset($txt[$config_var[1]]) ? $txt[$config_var[1]] : (isset($config_var[3]) && !is_array($config_var[3]) ? $config_var[3] : '')), 'help' => isset($helptxt[$config_var[1]]) ? $config_var[1] : '', 'type' => $config_var[0], 'size' => !empty($config_var[2]) && !is_array($config_var[2]) ? $config_var[2] : (in_array($config_var[0], array('int', 'float')) ? 6 : 0), 'data' => array(), 'name' => $config_var[1], 'value' => isset($modSettings[$config_var[1]]) ? $config_var[0] == 'select' ? $modSettings[$config_var[1]] : htmlspecialchars($modSettings[$config_var[1]]) : (in_array($config_var[0], array('int', 'float')) ? 0 : ''), 'disabled' => false, 'invalid' => !empty($config_var['invalid']), 'javascript' => '', 'var_message' => !empty($config_var['message']) && isset($txt[$config_var['message']]) ? $txt[$config_var['message']] : '', 'preinput' => isset($config_var['preinput']) ? $config_var['preinput'] : '', 'postinput' => isset($config_var['postinput']) ? $config_var['postinput'] : ''); // If this is a select box handle any data. if (!empty($config_var[2]) && is_array($config_var[2])) { // If we allow multiple selections, we need to adjust a few things. if ($config_var[0] == 'select' && !empty($config_var['multiple'])) { $context['config_vars'][$config_var[1]]['name'] .= '[]'; $context['config_vars'][$config_var[1]]['value'] = unserialize($context['config_vars'][$config_var[1]]['value']); } // If it's associative if (isset($config_var[2][0]) && is_array($config_var[2][0])) { $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; } else { foreach ($config_var[2] as $key => $item) { $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); } } } // Finally allow overrides - and some final cleanups. foreach ($config_var as $k => $v) { if (!is_numeric($k)) { if (substr($k, 0, 2) == 'on') { $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; } else { $context['config_vars'][$config_var[1]][$k] = $v; } } // See if there are any other labels that might fit? if (isset($txt['setting_' . $config_var[1]])) { $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; } elseif (isset($txt['groups_' . $config_var[1]])) { $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; } } // Set the subtext in case it's part of the label. // !!! Temporary. Preventing divs inside label tags. $divPos = strpos($context['config_vars'][$config_var[1]]['label'], '<div'); if ($divPos !== false) { $context['config_vars'][$config_var[1]]['subtext'] = preg_replace('~</?div[^>]*>~', '', substr($context['config_vars'][$config_var[1]]['label'], $divPos)); $context['config_vars'][$config_var[1]]['label'] = substr($context['config_vars'][$config_var[1]]['label'], 0, $divPos); } } } // If we have inline permissions we need to prep them. if (!empty($inlinePermissions) && allowedTo('manage_permissions')) { require_once $sourcedir . '/ManagePermissions.php'; init_inline_permissions($inlinePermissions, isset($context['permissions_excluded']) ? $context['permissions_excluded'] : array()); } // What about any BBC selection boxes? if (!empty($bbcChoice)) { // What are the options, eh? $temp = parse_bbc(false); $bbcTags = array(); foreach ($temp as $tag) { $bbcTags[] = $tag['tag']; } $bbcTags = array_unique($bbcTags); $totalTags = count($bbcTags); // The number of columns we want to show the BBC tags in. $numColumns = isset($context['num_bbc_columns']) ? $context['num_bbc_columns'] : 3; // Start working out the context stuff. $context['bbc_columns'] = array(); $tagsPerColumn = ceil($totalTags / $numColumns); $col = 0; $i = 0; foreach ($bbcTags as $tag) { if ($i % $tagsPerColumn == 0 && $i != 0) { $col++; } $context['bbc_columns'][$col][] = array('tag' => $tag, 'show_help' => isset($helptxt[$tag])); $i++; } // Now put whatever BBC options we may have into context too! $context['bbc_sections'] = array(); foreach ($bbcChoice as $bbc) { $context['bbc_sections'][$bbc] = array('title' => isset($txt['bbc_title_' . $bbc]) ? $txt['bbc_title_' . $bbc] : $txt['bbcTagsToUse_select'], 'disabled' => empty($modSettings['bbc_disabled_' . $bbc]) ? array() : $modSettings['bbc_disabled_' . $bbc], 'all_selected' => empty($modSettings['bbc_disabled_' . $bbc])); } } }
function GeneralPermissionSettings() { global $context, $db_prefix, $modSettings, $sourcedir, $txt; $context['page_title'] = $txt['permission_settings_title']; if (!empty($_POST['save_settings'])) { checkSession(); // If the by-board setting has been disabled, remove local permissions. if (!empty($modSettings['permission_enable_by_board']) && empty($_POST['permission_enable_by_board'])) { db_query("\n\t\t\t\tUPDATE {$db_prefix}boards\n\t\t\t\tSET permission_mode = 0", __FILE__, __LINE__); db_query("\n\t\t\t\tDELETE FROM {$db_prefix}board_permissions\n\t\t\t\tWHERE ID_BOARD != 0", __FILE__, __LINE__); } elseif (empty($modSettings['permission_enable_by_board']) && !empty($_POST['permission_enable_by_board'])) { // Fetch the existing global board permissions. $request = db_query("\n\t\t\t\tSELECT permission, ID_GROUP, addDeny\n\t\t\t\tFROM {$db_prefix}board_permissions\n\t\t\t\tWHERE ID_BOARD = 0", __FILE__, __LINE__); $perm = array(); while ($row = mysql_fetch_assoc($request)) { $perm[$row['ID_GROUP']][$row['addDeny']][] = $row['permission']; } mysql_free_result($request); // Cycle through all boards with restrictions. $request = db_query("\n\t\t\t\tSELECT ID_BOARD, permission_mode\n\t\t\t\tFROM {$db_prefix}boards AS b\n\t\t\t\tWHERE permission_mode > 1", __FILE__, __LINE__); $insertRows = array(); $boards = array(); while ($row = mysql_fetch_assoc($request)) { $boards[] = $row['ID_BOARD']; foreach ($perm as $ID_GROUP => $perm_array) { if (!in_array('moderate_board', $perm_array[1])) { if ($row['permission_mode'] == 4) { $perm_array[1] = array_diff($perm_array[1], array('post_reply_own', 'post_reply_any')); } if ($row['permission_mode'] >= 3) { $perm_array[1] = array_diff($perm_array[1], array('post_new')); } if ($row['permission_mode'] >= 2) { $perm_array[1] = array_diff($perm_array[1], array('poll_post')); } } foreach ($perm_array as $deny => $permissions) { foreach ($permissions as $permission) { $insertRows[] = "('{$permission}', {$row['ID_BOARD']}, {$ID_GROUP}, {$deny})"; } } } } mysql_free_result($request); if (!empty($insertRows)) { db_query("\n\t\t\t\t\tINSERT INTO {$db_prefix}board_permissions\n\t\t\t\t\t\t(permission, ID_BOARD, ID_GROUP, addDeny)\n\t\t\t\t\tVALUES " . implode(', ', $insertRows), __FILE__, __LINE__); } if (!empty($boards)) { db_query("\n\t\t\t\t\tUPDATE {$db_prefix}boards\n\t\t\t\t\tSET permission_mode = 1\n\t\t\t\t\tWHERE ID_BOARD IN (" . implode(', ', $boards) . ')', __FILE__, __LINE__); } } updateSettings(array('permission_enable_deny' => empty($_POST['permission_enable_deny']) ? '0' : '1', 'permission_enable_postgroups' => empty($_POST['permission_enable_postgroups']) ? '0' : '1', 'permission_enable_by_board' => empty($_POST['permission_enable_by_board']) ? '0' : '1')); // Clear all deny permissions...if we want that. if (empty($modSettings['permission_enable_deny'])) { db_query("\n\t\t\t\tDELETE FROM {$db_prefix}permissions\n\t\t\t\tWHERE addDeny = 0", __FILE__, __LINE__); db_query("\n\t\t\t\tDELETE FROM {$db_prefix}board_permissions\n\t\t\t\tWHERE addDeny = 0", __FILE__, __LINE__); } // Make sure there are no postgroup based permissions left. if (empty($modSettings['permission_enable_postgroups'])) { // Get a list of postgroups. $post_groups = array(); $request = db_query("\n\t\t\t\tSELECT ID_GROUP\n\t\t\t\tFROM {$db_prefix}membergroups\n\t\t\t\tWHERE minPosts != -1", __FILE__, __LINE__); while ($row = mysql_fetch_assoc($request)) { $post_groups[] = $row['ID_GROUP']; } mysql_free_result($request); // Remove'em. db_query("\n\t\t\t\tDELETE FROM {$db_prefix}permissions\n\t\t\t\tWHERE ID_GROUP IN (" . implode(', ', $post_groups) . ')', __FILE__, __LINE__); db_query("\n\t\t\t\tDELETE FROM {$db_prefix}board_permissions\n\t\t\t\tWHERE ID_GROUP IN (" . implode(', ', $post_groups) . ')', __FILE__, __LINE__); } save_inline_permissions(array('manage_permissions')); } init_inline_permissions(array('manage_permissions'), array(-1)); $context['sub_template'] = 'general_permission_settings'; }
function EditBoardSettings() { global $context, $txt, $db_prefix, $sourcedir, $modSettings; $context['page_title'] = $txt[41] . ' - ' . $txt['settings']; loadTemplate('ManageBoards'); $context['sub_template'] = 'modify_general_settings'; // Needed for the inline permission functions. require_once $sourcedir . '/ManagePermissions.php'; if (!empty($_POST['save_settings'])) { checkSession(); updateSettings(array('countChildPosts' => empty($_POST['countChildPosts']) ? '0' : '1', 'recycle_enable' => empty($_POST['recycle_enable']) ? '0' : '1', 'recycle_board' => (int) $_POST['recycle_board'])); // Save the permissions. save_inline_permissions(array('manage_boards')); } // Get a list of boards. $context['boards'] = array(); $request = db_query("\n\t\tSELECT b.ID_BOARD, b.name AS bName, c.ID_CAT, c.name AS cName\n\t\tFROM {$db_prefix}boards AS b\n\t\t\tLEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)", __FILE__, __LINE__); while ($row = mysql_fetch_assoc($request)) { $context['boards'][] = array('id' => $row['ID_BOARD'], 'name' => $row['bName'], 'is_recycle' => !empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $row['ID_BOARD'], 'category' => array('id' => $row['ID_CAT'], 'name' => $row['cName'])); } mysql_free_result($request); // Initialize permissions. init_inline_permissions(array('manage_boards'), array(-1)); }
function ManageAvatarSettings() { global $txt, $context, $db_prefix, $modSettings, $sourcedir; $context['page_title'] = $txt['smf201']; $context['description'] = $txt['smf202']; $context['selected'] = 'avatar_settings'; $context['sub_template'] = 'avatars'; // Perform a test to see if the GD module is installed. $testGD = get_extension_funcs('gd'); $context['gd_installed'] = !empty($testGD); // We need this file for the inline permission settings. require_once $sourcedir . '/ManagePermissions.php'; // Let's save the avatar settings. if (!empty($_POST['avatarSettings'])) { checkSession(); // Store the changed mod settings. updateSettings(array('avatar_directory' => $_POST['avatar_directory'], 'avatar_url' => $_POST['avatar_url'], 'avatar_download_external' => empty($_POST['avatar_download_external']) ? '0' : '1', 'avatar_max_width_upload' => (int) $_POST['avatar_max_width_upload'], 'avatar_max_height_upload' => (int) $_POST['avatar_max_height_upload'], 'avatar_resize_upload' => empty($_POST['avatar_resize_upload']) ? '0' : '1', 'avatar_download_png' => empty($_POST['avatar_download_png']) ? '0' : '1', 'custom_avatar_enabled' => empty($_POST['custom_avatar_enabled']) ? '0' : '1')); // Only update these settings if they are not disabled by JavaScript. if (empty($_POST['avatar_download_external'])) { updateSettings(array('avatar_max_width_external' => empty($_POST['avatar_max_width_external']) ? 0 : (int) $_POST['avatar_max_width_external'], 'avatar_max_height_external' => empty($_POST['avatar_max_height_external']) ? 0 : (int) $_POST['avatar_max_height_external'], 'avatar_action_too_large' => $_POST['avatar_action_too_large'])); } if (!empty($_POST['custom_avatar_enabled'])) { updateSettings(array('custom_avatar_dir' => $_POST['custom_avatar_dir'], 'custom_avatar_url' => $_POST['custom_avatar_url'])); } // Save the adjusted permissions. save_inline_permissions(array('profile_server_avatar', 'profile_upload_avatar', 'profile_remote_avatar')); } init_inline_permissions(array('profile_server_avatar', 'profile_upload_avatar', 'profile_remote_avatar'), array(-1)); $context['valid_avatar_dir'] = is_dir($modSettings['avatar_directory']); $context['valid_custom_avatar_dir'] = empty($modSettings['custom_avatar_enabled']) || is_dir($modSettings['custom_avatar_dir']) && is_writable($modSettings['custom_avatar_dir']); }
function ModifyMembergroupSettings() { global $context, $db_prefix, $sourcedir, $modSettings, $txt; $context['sub_template'] = 'membergroup_settings'; $context['page_title'] = $txt['membergroups_settings']; // Needed for the inline permission functions. require_once $sourcedir . '/ManagePermissions.php'; if (!empty($_POST['save_settings'])) { checkSession(); // Save the permissions. save_inline_permissions(array('manage_membergroups')); } // Initialize permissions. init_inline_permissions(array('manage_membergroups'), array(-1)); }
function EditSearchSettings() { global $txt, $context, $sourcedir; $context['page_title'] = $txt['search_settings_title']; $context['sub_template'] = 'modify_settings'; // Including a file needed for inline permissions. require_once $sourcedir . '/ManagePermissions.php'; // A form was submitted. if (isset($_POST['save'])) { checkSession(); updateSettings(array('simpleSearch' => isset($_POST['simpleSearch']) ? '1' : '0', 'search_results_per_page' => (int) $_POST['search_results_per_page'], 'search_max_results' => (int) $_POST['search_max_results'])); // Save the permissions. save_inline_permissions(array('search_posts')); } // Initialize permissions. init_inline_permissions(array('search_posts')); }
function ModifyNewsSettings() { global $context, $db_prefix, $sourcedir, $modSettings, $txt; $context['page_title'] = $txt[7] . ' - ' . $txt['settings']; $context['sub_template'] = 'news_settings'; // Needed for the inline permission functions. require_once $sourcedir . '/ManagePermissions.php'; if (!empty($_POST['save_settings'])) { checkSession(); updateSettings(array('xmlnews_enable' => empty($_POST['xmlnews_enable']) ? '0' : '1', 'xmlnews_maxlen' => (int) $_POST['xmlnews_maxlen'])); // Save the permissions. save_inline_permissions(array('edit_news', 'send_mail')); } // Initialize permissions. init_inline_permissions(array('edit_news', 'send_mail'), array(-1)); }