admin-default.php 61.4 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	Description: Controller for most admin pages which just contain options


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

22
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
23
	header('Location: ../../../');
24 25
	exit;
}
Scott committed
26

27 28 29 30 31
require_once QA_INCLUDE_DIR . 'db/admin.php';
require_once QA_INCLUDE_DIR . 'db/maxima.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/options.php';
require_once QA_INCLUDE_DIR . 'app/admin.php';
Scott committed
32 33


Scott committed
34
// Pages handled by this controller: general, emails, users, layout, viewing, lists, posting, permissions, feeds, spam, caching, mailing
35

36
$adminsection = strtolower(qa_request_part(1));
Scott committed
37 38


Scott committed
39
// Get list of categories and all options
Scott committed
40

41
$categories = qa_db_select_with_pending(qa_db_category_nav_selectspec(null, true));
Scott committed
42 43


Scott committed
44
// See if we need to redirect
Scott committed
45

46 47
if (empty($adminsection)) {
	$subnav = qa_admin_sub_navigation();
Scott committed
48

49 50 51 52 53
	if (isset($subnav[@$_COOKIE['qa_admin_last']]))
		qa_redirect($_COOKIE['qa_admin_last']);
	elseif (count($subnav)) {
		reset($subnav);
		qa_redirect(key($subnav));
Scott committed
54
	}
55
}
Scott committed
56 57


Scott committed
58
// Check admin privileges (do late to allow one DB query)
Scott committed
59

60 61
if (!qa_admin_check_privileges($qa_content))
	return $qa_content;
Scott committed
62 63


Scott committed
64
// For non-text options, lists of option types, minima and maxima
Scott committed
65

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
$optiontype = array(
	'avatar_message_list_size' => 'number',
	'avatar_profile_size' => 'number',
	'avatar_q_list_size' => 'number',
	'avatar_q_page_a_size' => 'number',
	'avatar_q_page_c_size' => 'number',
	'avatar_q_page_q_size' => 'number',
	'avatar_store_size' => 'number',
	'avatar_users_size' => 'number',
	'caching_catwidget_time' => 'number',
	'caching_q_start' => 'number',
	'caching_q_time' => 'number',
	'caching_qlist_time' => 'number',
	'columns_tags' => 'number',
	'columns_users' => 'number',
	'feed_number_items' => 'number',
	'flagging_hide_after' => 'number',
	'flagging_notify_every' => 'number',
	'flagging_notify_first' => 'number',
	'hot_weight_a_age' => 'number',
	'hot_weight_answers' => 'number',
	'hot_weight_q_age' => 'number',
	'hot_weight_views' => 'number',
	'hot_weight_votes' => 'number',
	'logo_height' => 'number-blank',
	'logo_width' => 'number-blank',
	'mailing_per_minute' => 'number',
	'max_len_q_title' => 'number',
	'max_num_q_tags' => 'number',
	'max_rate_ip_as' => 'number',
	'max_rate_ip_cs' => 'number',
	'max_rate_ip_flags' => 'number',
	'max_rate_ip_logins' => 'number',
	'max_rate_ip_messages' => 'number',
	'max_rate_ip_qs' => 'number',
	'max_rate_ip_registers' => 'number',
	'max_rate_ip_uploads' => 'number',
	'max_rate_ip_votes' => 'number',
	'max_rate_user_as' => 'number',
	'max_rate_user_cs' => 'number',
	'max_rate_user_flags' => 'number',
	'max_rate_user_messages' => 'number',
	'max_rate_user_qs' => 'number',
	'max_rate_user_uploads' => 'number',
	'max_rate_user_votes' => 'number',
	'min_len_a_content' => 'number',
	'min_len_c_content' => 'number',
	'min_len_q_content' => 'number',
	'min_len_q_title' => 'number',
	'min_num_q_tags' => 'number',
	'moderate_points_limit' => 'number',
	'page_size_activity' => 'number',
	'page_size_ask_check_qs' => 'number',
	'page_size_ask_tags' => 'number',
	'page_size_home' => 'number',
	'page_size_hot_qs' => 'number',
	'page_size_pms' => 'number',
	'page_size_q_as' => 'number',
	'page_size_qs' => 'number',
	'page_size_related_qs' => 'number',
	'page_size_search' => 'number',
	'page_size_tag_qs' => 'number',
	'page_size_tags' => 'number',
	'page_size_una_qs' => 'number',
	'page_size_users' => 'number',
	'page_size_wall' => 'number',
	'pages_prev_next' => 'number',
	'q_urls_title_length' => 'number',
	'show_fewer_cs_count' => 'number',
	'show_fewer_cs_from' => 'number',
	'show_full_date_days' => 'number',
	'smtp_port' => 'number',

139
	'allow_anonymous_naming' => 'checkbox',
140 141
	'allow_change_usernames' => 'checkbox',
	'allow_close_questions' => 'checkbox',
142
	'allow_close_own_questions' => 'checkbox',
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
	'allow_login_email_only' => 'checkbox',
	'allow_multi_answers' => 'checkbox',
	'allow_private_messages' => 'checkbox',
	'allow_user_walls' => 'checkbox',
	'allow_self_answer' => 'checkbox',
	'allow_view_q_bots' => 'checkbox',
	'avatar_allow_gravatar' => 'checkbox',
	'avatar_allow_upload' => 'checkbox',
	'avatar_default_show' => 'checkbox',
	'caching_enabled' => 'checkbox',
	'captcha_on_anon_post' => 'checkbox',
	'captcha_on_feedback' => 'checkbox',
	'captcha_on_register' => 'checkbox',
	'captcha_on_reset_password' => 'checkbox',
	'captcha_on_unapproved' => 'checkbox',
	'captcha_on_unconfirmed' => 'checkbox',
	'comment_on_as' => 'checkbox',
	'comment_on_qs' => 'checkbox',
	'confirm_user_emails' => 'checkbox',
	'confirm_user_required' => 'checkbox',
	'do_ask_check_qs' => 'checkbox',
	'do_close_on_select' => 'checkbox',
	'do_complete_tags' => 'checkbox',
	'do_count_q_views' => 'checkbox',
	'do_example_tags' => 'checkbox',
	'extra_field_active' => 'checkbox',
	'extra_field_display' => 'checkbox',
	'feed_for_activity' => 'checkbox',
	'feed_for_hot' => 'checkbox',
	'feed_for_qa' => 'checkbox',
	'feed_for_questions' => 'checkbox',
	'feed_for_search' => 'checkbox',
	'feed_for_tag_qs' => 'checkbox',
	'feed_for_unanswered' => 'checkbox',
	'feed_full_text' => 'checkbox',
	'feed_per_category' => 'checkbox',
	'feedback_enabled' => 'checkbox',
	'flagging_of_posts' => 'checkbox',
	'follow_on_as' => 'checkbox',
	'links_in_new_window' => 'checkbox',
	'logo_show' => 'checkbox',
	'mailing_enabled' => 'checkbox',
	'moderate_anon_post' => 'checkbox',
	'moderate_by_points' => 'checkbox',
	'moderate_edited_again' => 'checkbox',
	'moderate_notify_admin' => 'checkbox',
	'moderate_unapproved' => 'checkbox',
	'moderate_unconfirmed' => 'checkbox',
	'moderate_users' => 'checkbox',
	'neat_urls' => 'checkbox',
	'notify_admin_q_post' => 'checkbox',
	'notify_users_default' => 'checkbox',
	'q_urls_remove_accents' => 'checkbox',
196
	'recalc_hotness_q_view' => 'checkbox',
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	'register_notify_admin' => 'checkbox',
	'show_c_reply_buttons' => 'checkbox',
	'show_compact_numbers' => 'checkbox',
	'show_custom_answer' => 'checkbox',
	'show_custom_ask' => 'checkbox',
	'show_custom_comment' => 'checkbox',
	'show_custom_footer' => 'checkbox',
	'show_custom_header' => 'checkbox',
	'show_custom_home' => 'checkbox',
	'show_custom_in_head' => 'checkbox',
	'show_custom_register' => 'checkbox',
	'show_custom_sidebar' => 'checkbox',
	'show_custom_sidepanel' => 'checkbox',
	'show_custom_welcome' => 'checkbox',
	'show_home_description' => 'checkbox',
	'show_message_history' => 'checkbox',
	'show_notice_visitor' => 'checkbox',
	'show_notice_welcome' => 'checkbox',
	'show_post_update_meta' => 'checkbox',
	'show_register_terms' => 'checkbox',
	'show_selected_first' => 'checkbox',
	'show_url_links' => 'checkbox',
	'show_user_points' => 'checkbox',
	'show_user_titles' => 'checkbox',
	'show_view_counts' => 'checkbox',
	'show_view_count_q_page' => 'checkbox',
	'show_when_created' => 'checkbox',
	'site_maintenance' => 'checkbox',
	'smtp_active' => 'checkbox',
	'smtp_authenticate' => 'checkbox',
	'suspend_register_users' => 'checkbox',
	'tag_separator_comma' => 'checkbox',
	'use_microdata' => 'checkbox',
	'minify_html' => 'checkbox',
	'votes_separated' => 'checkbox',
	'voting_on_as' => 'checkbox',
Scott committed
233
	'voting_on_cs' => 'checkbox',
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
	'voting_on_q_page_only' => 'checkbox',
	'voting_on_qs' => 'checkbox',

	'smtp_password' => 'password',
);

$optionmaximum = array(
	'feed_number_items' => QA_DB_RETRIEVE_QS_AS,
	'max_len_q_title' => QA_DB_MAX_TITLE_LENGTH,
	'page_size_activity' => QA_DB_RETRIEVE_QS_AS,
	'page_size_ask_check_qs' => QA_DB_RETRIEVE_QS_AS,
	'page_size_ask_tags' => QA_DB_RETRIEVE_QS_AS,
	'page_size_home' => QA_DB_RETRIEVE_QS_AS,
	'page_size_hot_qs' => QA_DB_RETRIEVE_QS_AS,
	'page_size_pms' => QA_DB_RETRIEVE_MESSAGES,
	'page_size_qs' => QA_DB_RETRIEVE_QS_AS,
	'page_size_related_qs' => QA_DB_RETRIEVE_QS_AS,
	'page_size_search' => QA_DB_RETRIEVE_QS_AS,
	'page_size_tag_qs' => QA_DB_RETRIEVE_QS_AS,
	'page_size_tags' => QA_DB_RETRIEVE_TAGS,
	'page_size_una_qs' => QA_DB_RETRIEVE_QS_AS,
	'page_size_users' => QA_DB_RETRIEVE_USERS,
	'page_size_wall' => QA_DB_RETRIEVE_MESSAGES,
);

$optionminimum = array(
	'flagging_hide_after' => 2,
	'flagging_notify_every' => 1,
	'flagging_notify_first' => 1,
	'max_num_q_tags' => 2,
	'max_rate_ip_logins' => 1,
	'min_len_a_content' => 1,
	'min_len_c_content' => 1,
	'min_len_q_title' => 1,
	'page_size_activity' => 1,
	'page_size_ask_check_qs' => 3,
	'page_size_ask_tags' => 3,
	'page_size_home' => 1,
	'page_size_hot_qs' => 1,
	'page_size_pms' => 1,
	'page_size_q_as' => 1,
	'page_size_qs' => 1,
	'page_size_search' => 1,
	'page_size_tag_qs' => 1,
	'page_size_tags' => 1,
	'page_size_users' => 1,
	'page_size_wall' => 1,
);
Scott committed
282 283


Scott committed
284
// Define the options to show (and some other visual stuff) based on request
Scott committed
285

286 287
$formstyle = 'tall';
$checkboxtodisplay = null;
Scott committed
288

289 290 291
$maxpermitpost = max(qa_opt('permit_post_q'), qa_opt('permit_post_a'));
if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
	$maxpermitpost = max($maxpermitpost, qa_opt('permit_post_c'));
Scott committed
292

293 294 295 296 297
switch ($adminsection) {
	case 'general':
		$subtitle = 'admin/general_title';
		$showoptions = array('site_title', 'site_url', 'neat_urls', 'site_language', 'site_theme', 'site_theme_mobile', 'site_text_direction', 'tags_or_categories', 'site_maintenance');
		break;
Scott committed
298

299 300 301 302 303 304
	case 'emails':
		$subtitle = 'admin/emails_title';
		$showoptions = array(
			'from_email', 'feedback_email', 'notify_admin_q_post', 'feedback_enabled', 'email_privacy',
			'smtp_active', 'smtp_address', 'smtp_port', 'smtp_secure', 'smtp_authenticate', 'smtp_username', 'smtp_password'
		);
Scott committed
305

306 307 308 309 310 311 312 313 314
		$checkboxtodisplay = array(
			'smtp_address' => 'option_smtp_active',
			'smtp_port' => 'option_smtp_active',
			'smtp_secure' => 'option_smtp_active',
			'smtp_authenticate' => 'option_smtp_active',
			'smtp_username' => 'option_smtp_active && option_smtp_authenticate',
			'smtp_password' => 'option_smtp_active && option_smtp_authenticate',
		);
		break;
Scott committed
315

316 317
	case 'users':
		$subtitle = 'admin/users_title';
Scott committed
318

319
		$showoptions = array('show_notice_visitor', 'notice_visitor');
Scott committed
320

321 322
		if (!QA_FINAL_EXTERNAL_USERS) {
			require_once QA_INCLUDE_DIR . 'util/image.php';
Scott committed
323

324
			array_push($showoptions, 'show_custom_register', 'custom_register', 'show_register_terms', 'register_terms', 'show_notice_welcome', 'notice_welcome', 'show_custom_welcome', 'custom_welcome',
325
				'', 'allow_login_email_only', 'allow_change_usernames', 'register_notify_admin', 'suspend_register_users', '', 'block_bad_usernames',
326 327
				'', 'allow_private_messages', 'show_message_history', 'page_size_pms', 'allow_user_walls', 'page_size_wall',
				'', 'avatar_allow_gravatar');
Scott committed
328

329 330 331
			if (qa_has_gd_image())
				array_push($showoptions, 'avatar_allow_upload', 'avatar_store_size', 'avatar_default_show');
		}
Scott committed
332

333
		$showoptions[] = '';
Scott committed
334

335 336
		if (!QA_FINAL_EXTERNAL_USERS)
			$showoptions[] = 'avatar_profile_size';
Scott committed
337

338 339
		array_push($showoptions, 'avatar_users_size', 'avatar_q_page_q_size', 'avatar_q_page_a_size', 'avatar_q_page_c_size',
			'avatar_q_list_size', 'avatar_message_list_size');
Scott committed
340

341 342 343 344 345 346 347 348 349 350
		$checkboxtodisplay = array(
			'custom_register' => 'option_show_custom_register',
			'register_terms' => 'option_show_register_terms',
			'custom_welcome' => 'option_show_custom_welcome',
			'notice_welcome' => 'option_show_notice_welcome',
			'notice_visitor' => 'option_show_notice_visitor',
			'show_message_history' => 'option_allow_private_messages',
			'avatar_store_size' => 'option_avatar_allow_upload',
			'avatar_default_show' => 'option_avatar_allow_gravatar || option_avatar_allow_upload',
		);
Scott committed
351

352 353 354 355 356 357 358 359 360 361
		if (!QA_FINAL_EXTERNAL_USERS) {
			$checkboxtodisplay = array_merge($checkboxtodisplay, array(
				'page_size_pms' => 'option_allow_private_messages && option_show_message_history',
				'page_size_wall' => 'option_allow_user_walls',
				'avatar_profile_size' => 'option_avatar_allow_gravatar || option_avatar_allow_upload',
				'avatar_users_size' => 'option_avatar_allow_gravatar || option_avatar_allow_upload',
				'avatar_q_page_q_size' => 'option_avatar_allow_gravatar || option_avatar_allow_upload',
				'avatar_q_page_a_size' => 'option_avatar_allow_gravatar || option_avatar_allow_upload',
				'avatar_q_page_c_size' => 'option_avatar_allow_gravatar || option_avatar_allow_upload',
				'avatar_q_list_size' => 'option_avatar_allow_gravatar || option_avatar_allow_upload',
362
				'avatar_message_list_size' => '(option_avatar_allow_gravatar || option_avatar_allow_upload) && (option_allow_private_messages || option_allow_user_walls)',
363 364
			));
		}
Scott committed
365

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
		$formstyle = 'wide';
		break;

	case 'layout':
		$subtitle = 'admin/layout_title';
		$showoptions = array('logo_show', 'logo_url', 'logo_width', 'logo_height', '', 'show_custom_sidebar', 'custom_sidebar', 'show_custom_sidepanel', 'custom_sidepanel', 'show_custom_header', 'custom_header', 'show_custom_footer', 'custom_footer', 'show_custom_in_head', 'custom_in_head', 'show_custom_home', 'custom_home_heading', 'custom_home_content', 'show_home_description', 'home_description', '');

		$checkboxtodisplay = array(
			'logo_url' => 'option_logo_show',
			'logo_width' => 'option_logo_show',
			'logo_height' => 'option_logo_show',
			'custom_sidebar' => 'option_show_custom_sidebar',
			'custom_sidepanel' => 'option_show_custom_sidepanel',
			'custom_header' => 'option_show_custom_header',
			'custom_footer' => 'option_show_custom_footer',
			'custom_in_head' => 'option_show_custom_in_head',
			'custom_home_heading' => 'option_show_custom_home',
			'custom_home_content' => 'option_show_custom_home',
			'home_description' => 'option_show_home_description',
		);
		break;

	case 'viewing':
		$subtitle = 'admin/viewing_title';
		$showoptions = array(
391
			'q_urls_title_length', 'q_urls_remove_accents', 'do_count_q_views', 'show_view_counts', 'show_view_count_q_page', 'recalc_hotness_q_view', '',
Scott committed
392
			'voting_on_qs', 'voting_on_q_page_only', 'voting_on_as', 'voting_on_cs', 'votes_separated', '',
393 394
			'show_url_links', 'links_in_new_window', 'show_when_created', 'show_full_date_days'
		);
Scott committed
395

396 397 398
		if (count(qa_get_points_to_titles())) {
			$showoptions[] = 'show_user_titles';
		}
Scott committed
399

400 401 402 403
		array_push($showoptions,
			'show_user_points', 'show_post_update_meta', 'show_compact_numbers', 'use_microdata', 'minify_html', '',
			'sort_answers_by', 'show_selected_first', 'page_size_q_as', 'show_a_form_immediate'
		);
Scott committed
404

405 406 407
		if (qa_opt('comment_on_qs') || qa_opt('comment_on_as')) {
			array_push($showoptions, 'show_fewer_cs_from', 'show_fewer_cs_count', 'show_c_reply_buttons');
		}
Scott committed
408

409
		$showoptions[] = '';
Scott committed
410

411
		$widgets = qa_db_single_select(qa_db_widgets_selectspec());
Scott committed
412

413 414 415 416
		foreach ($widgets as $widget) {
			if ($widget['title'] == 'Related Questions') {
				array_push($showoptions, 'match_related_qs', 'page_size_related_qs', '');
				break;
417
			}
418
		}
Scott committed
419

420
		$showoptions[] = 'pages_prev_next';
Scott committed
421

422
		$formstyle = 'wide';
Scott committed
423

424 425 426
		$checkboxtodisplay = array(
			'show_view_counts' => 'option_do_count_q_views',
			'show_view_count_q_page' => 'option_do_count_q_views',
427
			'recalc_hotness_q_view' => 'option_do_count_q_views',
428 429 430 431 432
			'votes_separated' => 'option_voting_on_qs || option_voting_on_as',
			'voting_on_q_page_only' => 'option_voting_on_qs',
			'show_full_date_days' => 'option_show_when_created',
		);
		break;
Scott committed
433

434 435
	case 'lists':
		$subtitle = 'admin/lists_title';
Scott committed
436

437
		$showoptions = array('page_size_home', 'page_size_activity', 'page_size_qs', 'page_size_hot_qs', 'page_size_una_qs');
Scott committed
438

439 440
		if (qa_using_tags())
			$showoptions[] = 'page_size_tag_qs';
Scott committed
441

442
		$showoptions[] = '';
Scott committed
443

444 445
		if (qa_using_tags())
			array_push($showoptions, 'page_size_tags', 'columns_tags');
Scott committed
446

447
		array_push($showoptions, 'page_size_users', 'columns_users', '');
Scott committed
448

449
		$searchmodules = qa_load_modules_with('search', 'process_search');
Scott committed
450

451 452
		if (count($searchmodules))
			$showoptions[] = 'search_module';
Scott committed
453

454
		$showoptions[] = 'page_size_search';
Scott committed
455

456
		array_push($showoptions, '', 'admin/hotness_factors', 'hot_weight_q_age', 'hot_weight_a_age', 'hot_weight_answers', 'hot_weight_votes');
Scott committed
457

458 459
		if (qa_opt('do_count_q_views'))
			$showoptions[] = 'hot_weight_views';
Scott committed
460

461
		$formstyle = 'wide';
Scott committed
462

463
		break;
Scott committed
464

465 466
	case 'posting':
		$getoptions = qa_get_options(array('tags_or_categories'));
Scott committed
467

468
		$subtitle = 'admin/posting_title';
Scott committed
469

470
		$showoptions = array('do_close_on_select', 'allow_close_questions', 'allow_close_own_questions', 'allow_self_answer', 'allow_multi_answers', 'follow_on_as', 'comment_on_qs', 'comment_on_as', 'allow_anonymous_naming', '');
Scott committed
471

472 473
		if (count(qa_list_modules('editor')) > 1)
			array_push($showoptions, 'editor_for_qs', 'editor_for_as', 'editor_for_cs', '');
Scott committed
474

475
		array_push($showoptions, 'show_custom_ask', 'custom_ask', 'extra_field_active', 'extra_field_prompt', 'extra_field_display', 'extra_field_label', 'show_custom_answer', 'custom_answer', 'show_custom_comment', 'custom_comment', '');
Scott committed
476

477
		array_push($showoptions, 'min_len_q_title', 'max_len_q_title', 'min_len_q_content');
Scott committed
478

479 480
		if (qa_using_tags())
			array_push($showoptions, 'min_num_q_tags', 'max_num_q_tags', 'tag_separator_comma');
Scott committed
481

482
		array_push($showoptions, 'min_len_a_content', 'min_len_c_content', 'notify_users_default');
Scott committed
483

484
		array_push($showoptions, '', 'block_bad_words', '', 'do_ask_check_qs', 'match_ask_check_qs', 'page_size_ask_check_qs', '');
Scott committed
485

486 487
		if (qa_using_tags())
			array_push($showoptions, 'do_example_tags', 'match_example_tags', 'do_complete_tags', 'page_size_ask_tags');
Scott committed
488

489
		$formstyle = 'wide';
Scott committed
490

491
		$checkboxtodisplay = array(
492
			'allow_close_own_questions' => 'option_allow_close_questions',
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
			'editor_for_cs' => 'option_comment_on_qs || option_comment_on_as',
			'custom_ask' => 'option_show_custom_ask',
			'extra_field_prompt' => 'option_extra_field_active',
			'extra_field_display' => 'option_extra_field_active',
			'extra_field_label' => 'option_extra_field_active && option_extra_field_display',
			'extra_field_label_hidden' => '!option_extra_field_display',
			'extra_field_label_shown' => 'option_extra_field_display',
			'custom_answer' => 'option_show_custom_answer',
			'show_custom_comment' => 'option_comment_on_qs || option_comment_on_as',
			'custom_comment' => 'option_show_custom_comment && (option_comment_on_qs || option_comment_on_as)',
			'min_len_c_content' => 'option_comment_on_qs || option_comment_on_as',
			'match_ask_check_qs' => 'option_do_ask_check_qs',
			'page_size_ask_check_qs' => 'option_do_ask_check_qs',
			'match_example_tags' => 'option_do_example_tags',
			'page_size_ask_tags' => 'option_do_example_tags || option_do_complete_tags',
		);
		break;
Scott committed
510

511 512
	case 'permissions':
		$subtitle = 'admin/permissions_title';
Scott committed
513

514
		$permitoptions = qa_get_permit_options();
Scott committed
515

516 517
		$showoptions = array();
		$checkboxtodisplay = array();
Scott committed
518

519 520
		foreach ($permitoptions as $permitoption) {
			$showoptions[] = $permitoption;
Scott committed
521

522 523 524
			if ($permitoption == 'permit_view_q_page') {
				$showoptions[] = 'allow_view_q_bots';
				$checkboxtodisplay['allow_view_q_bots'] = 'option_permit_view_q_page<' . qa_js(QA_PERMIT_ALL);
Scott committed
525

526 527 528 529
			} else {
				$showoptions[] = $permitoption . '_points';
				$checkboxtodisplay[$permitoption . '_points'] = '(option_' . $permitoption . '==' . qa_js(QA_PERMIT_POINTS) .
					')||(option_' . $permitoption . '==' . qa_js(QA_PERMIT_POINTS_CONFIRMED) . ')||(option_' . $permitoption . '==' . qa_js(QA_PERMIT_APPROVED_POINTS) . ')';
Scott committed
530
			}
531
		}
Scott committed
532

533 534
		$formstyle = 'wide';
		break;
Scott committed
535

536 537
	case 'feeds':
		$subtitle = 'admin/feeds_title';
Scott committed
538

539
		$showoptions = array('feed_for_questions', 'feed_for_qa', 'feed_for_activity');
Scott committed
540

541
		array_push($showoptions, 'feed_for_hot', 'feed_for_unanswered');
Scott committed
542

543 544
		if (qa_using_tags())
			$showoptions[] = 'feed_for_tag_qs';
Scott committed
545

546 547
		if (qa_using_categories())
			$showoptions[] = 'feed_per_category';
Scott committed
548

549
		array_push($showoptions, 'feed_for_search', '', 'feed_number_items', 'feed_full_text');
Scott committed
550

551
		$formstyle = 'wide';
Scott committed
552

553 554 555 556 557 558 559
		$checkboxtodisplay = array(
			'feed_per_category' => 'option_feed_for_qa || option_feed_for_questions || option_feed_for_unanswered || option_feed_for_activity',
		);
		break;

	case 'spam':
		$subtitle = 'admin/spam_title';
Scott committed
560

561
		$showoptions = array();
Scott committed
562

563
		$getoptions = qa_get_options(array('feedback_enabled', 'permit_post_q', 'permit_post_a', 'permit_post_c'));
Scott committed
564

565
		if (!QA_FINAL_EXTERNAL_USERS)
566
			array_push($showoptions, 'confirm_user_emails', 'confirm_user_required', 'moderate_users', '');
Scott committed
567

568 569 570
		$captchamodules = qa_list_modules('captcha');

		if (count($captchamodules)) {
Scott committed
571
			if (!QA_FINAL_EXTERNAL_USERS)
572
				array_push($showoptions, 'captcha_on_register', 'captcha_on_reset_password');
Scott committed
573

574 575
			if ($maxpermitpost > QA_PERMIT_USERS)
				$showoptions[] = 'captcha_on_anon_post';
Scott committed
576

577 578
			if ($maxpermitpost > QA_PERMIT_APPROVED)
				$showoptions[] = 'captcha_on_unapproved';
Scott committed
579

580 581
			if ($maxpermitpost > QA_PERMIT_CONFIRMED)
				$showoptions[] = 'captcha_on_unconfirmed';
Scott committed
582

583 584
			if ($getoptions['feedback_enabled'])
				$showoptions[] = 'captcha_on_feedback';
Scott committed
585

586 587
			$showoptions[] = 'captcha_module';
		}
Scott committed
588

589
		$showoptions[] = '';
Scott committed
590

591 592
		if ($maxpermitpost > QA_PERMIT_USERS)
			$showoptions[] = 'moderate_anon_post';
Scott committed
593

594 595
		if ($maxpermitpost > QA_PERMIT_APPROVED)
			$showoptions[] = 'moderate_unapproved';
Scott committed
596

597 598
		if ($maxpermitpost > QA_PERMIT_CONFIRMED)
			$showoptions[] = 'moderate_unconfirmed';
Scott committed
599

600 601
		if ($maxpermitpost > QA_PERMIT_EXPERTS)
			array_push($showoptions, 'moderate_by_points', 'moderate_points_limit', 'moderate_edited_again', 'moderate_notify_admin', 'moderate_update_time', '');
Scott committed
602

603
		array_push($showoptions, 'flagging_of_posts', 'flagging_notify_first', 'flagging_notify_every', 'flagging_hide_after', '');
Scott committed
604

605
		array_push($showoptions, 'block_ips_write', '');
Scott committed
606

607 608
		if (!QA_FINAL_EXTERNAL_USERS)
			array_push($showoptions, 'max_rate_ip_registers', 'max_rate_ip_logins', '');
Scott committed
609

610
		array_push($showoptions, 'max_rate_ip_qs', 'max_rate_user_qs', 'max_rate_ip_as', 'max_rate_user_as');
Scott committed
611

612 613
		if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
			array_push($showoptions, 'max_rate_ip_cs', 'max_rate_user_cs');
Scott committed
614

615
		$showoptions[] = '';
Scott committed
616

Scott committed
617
		if (qa_opt('voting_on_qs') || qa_opt('voting_on_as') || qa_opt('voting_on_cs'))
618
			array_push($showoptions, 'max_rate_ip_votes', 'max_rate_user_votes');
619

620
		array_push($showoptions, 'max_rate_ip_flags', 'max_rate_user_flags', 'max_rate_ip_uploads', 'max_rate_user_uploads');
621

622 623
		if (qa_opt('allow_private_messages') || qa_opt('allow_user_walls'))
			array_push($showoptions, 'max_rate_ip_messages', 'max_rate_user_messages');
624

625
		$formstyle = 'wide';
Scott committed
626

627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
		$checkboxtodisplay = array(
			'confirm_user_required' => 'option_confirm_user_emails',
			'captcha_on_unapproved' => 'option_moderate_users',
			'captcha_on_unconfirmed' => 'option_confirm_user_emails && !(option_moderate_users && option_captcha_on_unapproved)',
			'captcha_module' => 'option_captcha_on_register || option_captcha_on_anon_post || (option_confirm_user_emails && option_captcha_on_unconfirmed) || (option_moderate_users && option_captcha_on_unapproved) || option_captcha_on_reset_password || option_captcha_on_feedback',
			'moderate_unapproved' => 'option_moderate_users',
			'moderate_unconfirmed' => 'option_confirm_user_emails && !(option_moderate_users && option_moderate_unapproved)',
			'moderate_points_limit' => 'option_moderate_by_points',
			'moderate_points_label_off' => '!option_moderate_by_points',
			'moderate_points_label_on' => 'option_moderate_by_points',
			'moderate_edited_again' => 'option_moderate_anon_post || (option_confirm_user_emails && option_moderate_unconfirmed) || (option_moderate_users && option_moderate_unapproved) || option_moderate_by_points',
			'flagging_hide_after' => 'option_flagging_of_posts',
			'flagging_notify_every' => 'option_flagging_of_posts',
			'flagging_notify_first' => 'option_flagging_of_posts',
			'max_rate_ip_flags' => 'option_flagging_of_posts',
			'max_rate_user_flags' => 'option_flagging_of_posts',
		);
Scott committed
644

645 646 647
		$checkboxtodisplay['moderate_notify_admin'] = $checkboxtodisplay['moderate_edited_again'];
		$checkboxtodisplay['moderate_update_time'] = $checkboxtodisplay['moderate_edited_again'];
		break;
Scott committed
648

649 650 651
	case 'caching':
		$subtitle = 'admin/caching_title';
		$formstyle = 'wide';
Scott committed
652

Scott committed
653
		$showoptions = array('caching_enabled', 'caching_driver', 'caching_q_start', 'caching_q_time', 'caching_catwidget_time');
Scott committed
654

655
		break;
Scott committed
656

657 658
	case 'mailing':
		require_once QA_INCLUDE_DIR . 'app/mailing.php';
Scott committed
659

660
		$subtitle = 'admin/mailing_title';
Scott committed
661

662 663
		$showoptions = array('mailing_enabled', 'mailing_from_name', 'mailing_from_email', 'mailing_subject', 'mailing_body', 'mailing_per_minute');
		break;
Scott committed
664

665 666 667
	default:
		$pagemodules = qa_load_modules_with('page', 'match_request');
		$request = qa_request();
Scott committed
668

669 670 671 672
		foreach ($pagemodules as $pagemodule) {
			if ($pagemodule->match_request($request))
				return $pagemodule->process_request($request);
		}
Scott committed
673

674 675 676
		return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
		break;
}
Scott committed
677 678


Scott committed
679
// Filter out blanks to get list of valid options
Scott committed
680

681 682 683 684 685
$getoptions = array();
foreach ($showoptions as $optionname) {
	if (strlen($optionname) && (strpos($optionname, '/') === false)) // empties represent spacers in forms
		$getoptions[] = $optionname;
}
Scott committed
686 687


Scott committed
688
// Process user actions
Scott committed
689

690
$errors = array();
Scott committed
691

692 693 694
$recalchotness = false;
$startmailing = false;
$securityexpired = false;
Scott committed
695

696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
$formokhtml = null;

// If the post_max_size is exceeded then the $_POST array is empty so no field processing can be done
if (qa_post_limit_exceeded())
	$errors['avatar_default_show'] = qa_lang('main/file_upload_limit_exceeded');
else {
	if (qa_clicked('doresetoptions')) {
		if (!qa_check_form_security_code('admin/' . $adminsection, qa_post_text('code')))
			$securityexpired = true;

		else {
			qa_reset_options($getoptions);
			$formokhtml = qa_lang_html('admin/options_reset');
		}
	} elseif (qa_clicked('dosaveoptions')) {
		if (!qa_check_form_security_code('admin/' . $adminsection, qa_post_text('code')))
			$securityexpired = true;

		else {
			foreach ($getoptions as $optionname) {
				$optionvalue = qa_post_text('option_' . $optionname);

718
				if (@$optiontype[$optionname] == 'number' || @$optiontype[$optionname] == 'checkbox' ||
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
					(@$optiontype[$optionname] == 'number-blank' && strlen($optionvalue))
				)
					$optionvalue = (int)$optionvalue;

				if (isset($optionmaximum[$optionname]))
					$optionvalue = min($optionmaximum[$optionname], $optionvalue);

				if (isset($optionminimum[$optionname]))
					$optionvalue = max($optionminimum[$optionname], $optionvalue);

				switch ($optionname) {
					case 'site_url':
						if (substr($optionvalue, -1) != '/') // seems to be a very common mistake and will mess up URLs
							$optionvalue .= '/';
						break;

					case 'hot_weight_views':
					case 'hot_weight_answers':
					case 'hot_weight_votes':
					case 'hot_weight_q_age':
					case 'hot_weight_a_age':
						if (qa_opt($optionname) != $optionvalue)
							$recalchotness = true;
						break;

					case 'block_ips_write':
						require_once QA_INCLUDE_DIR . 'app/limits.php';
						$optionvalue = implode(' , ', qa_block_ips_explode($optionvalue));
						break;

					case 'block_bad_words':
750
					case 'block_bad_usernames':
751 752 753
						require_once QA_INCLUDE_DIR . 'util/string.php';
						$optionvalue = implode(' , ', qa_block_words_explode($optionvalue));
						break;
Scott committed
754 755
				}

756 757
				qa_set_option($optionname, $optionvalue);
			}
Scott committed
758

759
			$formokhtml = qa_lang_html('admin/options_saved');
Scott committed
760

Scott committed
761
			// Uploading default avatar
762 763
			if (is_array(@$_FILES['avatar_default_file'])) {
				$avatarfileerror = $_FILES['avatar_default_file']['error'];
Scott committed
764

765 766 767 768 769
				// Note if $_FILES['avatar_default_file']['error'] === 1 then upload_max_filesize has been exceeded
				if ($avatarfileerror === 1) {
					$errors['avatar_default_show'] = qa_lang('main/file_upload_limit_exceeded');
				} elseif ($avatarfileerror === 0 && $_FILES['avatar_default_file']['size'] > 0) {
					require_once QA_INCLUDE_DIR . 'util/image.php';
Scott committed
770

771
					$oldblobid = qa_opt('avatar_default_blobid');
Scott committed
772

773
					$toobig = qa_image_file_too_big($_FILES['avatar_default_file']['tmp_name'], qa_opt('avatar_store_size'));
Scott committed
774

775 776 777 778
					if ($toobig) {
						$errors['avatar_default_show'] = qa_lang_sub('main/image_too_big_x_pc', (int)($toobig * 100));
					} else {
						$imagedata = qa_image_constrain_data(file_get_contents($_FILES['avatar_default_file']['tmp_name']), $width, $height, qa_opt('avatar_store_size'));
Scott committed
779

780 781
						if (isset($imagedata)) {
							require_once QA_INCLUDE_DIR . 'app/blobs.php';
Scott committed
782

783
							$newblobid = qa_create_blob($imagedata, 'jpeg');
Scott committed
784

785 786 787 788 789 790
							if (isset($newblobid)) {
								qa_set_option('avatar_default_blobid', $newblobid);
								qa_set_option('avatar_default_width', $width);
								qa_set_option('avatar_default_height', $height);
								qa_set_option('avatar_default_show', 1);
							}
Scott committed
791

792 793 794 795
							if (strlen($oldblobid))
								qa_delete_blob($oldblobid);
						} else {
							$errors['avatar_default_show'] = qa_lang_sub('main/image_not_read', implode(', ', qa_gd_image_formats()));
Scott committed
796 797 798 799 800
						}
					}
				}
			}
		}
801 802
	}
}
Scott committed
803 804


Scott committed
805
// Mailings management
Scott committed
806

807 808 809 810 811 812 813 814 815 816 817 818 819
if ($adminsection == 'mailing') {
	if (qa_clicked('domailingtest') || qa_clicked('domailingstart') || qa_clicked('domailingresume') || qa_clicked('domailingcancel')) {
		if (!qa_check_form_security_code('admin/' . $adminsection, qa_post_text('code'))) {
			$securityexpired = true;
		} else {
			if (qa_clicked('domailingtest')) {
				$email = qa_get_logged_in_email();

				if (qa_mailing_send_one(qa_get_logged_in_userid(), qa_get_logged_in_handle(), $email, qa_get_logged_in_user_field('emailcode')))
					$formokhtml = qa_lang_html_sub('admin/test_sent_to_x', qa_html($email));
				else
					$formokhtml = qa_lang_html('main/general_error');
			}
Scott committed
820

821 822 823 824
			if (qa_clicked('domailingstart')) {
				qa_mailing_start();
				$startmailing = true;
			}
Scott committed
825

826 827
			if (qa_clicked('domailingresume'))
				$startmailing = true;
Scott committed
828

829 830
			if (qa_clicked('domailingcancel'))
				qa_mailing_stop();
Scott committed
831
		}
832
	}
Scott committed
833

834
	$mailingprogress = qa_mailing_progress_message();
Scott committed
835

836 837
	if (isset($mailingprogress)) {
		$formokhtml = qa_html($mailingprogress);
Scott committed
838

839 840 841
		$checkboxtodisplay = array(
			'mailing_enabled' => '0',
		);
Scott committed
842

843 844 845 846 847 848 849 850 851 852
	} else {
		$checkboxtodisplay = array(
			'mailing_from_name' => 'option_mailing_enabled',
			'mailing_from_email' => 'option_mailing_enabled',
			'mailing_subject' => 'option_mailing_enabled',
			'mailing_body' => 'option_mailing_enabled',
			'mailing_per_minute' => 'option_mailing_enabled',
			'domailingtest' => 'option_mailing_enabled',
			'domailingstart' => 'option_mailing_enabled',
		);
Scott committed
853
	}
854
}
Scott committed
855 856


Scott committed
857
// Get the actual options
Scott committed
858

859
$options = qa_get_options($getoptions);
Scott committed
860 861


Scott committed
862
// Prepare content for theme
Scott committed
863

864
$qa_content = qa_content_prepare();
Scott committed
865

866 867
$qa_content['title'] = qa_lang_html('admin/admin_title') . ' - ' . qa_lang_html($subtitle);
$qa_content['error'] = $securityexpired ? qa_lang_html('admin/form_security_expired') : qa_admin_page_error();
Scott committed
868

869
$qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION;
Scott committed
870

871 872
$qa_content['form'] = array(
	'ok' => $formokhtml,
Scott committed
873

874
	'tags' => 'method="post" action="' . qa_self_html() . '" name="admin_form" onsubmit="document.forms.admin_form.has_js.value=1; return true;"',
Scott committed
875

876
	'style' => $formstyle,
Scott committed
877

878
	'fields' => array(),
Scott committed
879

880 881 882 883
	'buttons' => array(
		'save' => array(
			'tags' => 'id="dosaveoptions"',
			'label' => qa_lang_html('admin/save_options_button'),
Scott committed
884 885
		),

886 887 888
		'reset' => array(
			'tags' => 'name="doresetoptions" onclick="return confirm(' . qa_js(qa_lang_html('admin/reset_options_confirm')) . ');"',
			'label' => qa_lang_html('admin/reset_options_button'),
Scott committed
889
		),
890
	),
Scott committed
891

892 893 894 895 896 897
	'hidden' => array(
		'dosaveoptions' => '1', // for IE
		'has_js' => '0',
		'code' => qa_get_form_security_code('admin/' . $adminsection),
	),
);
Scott committed
898

899 900 901
if ($recalchotness) {
	$qa_content['form']['ok'] = '<span id="recalc_ok"></span>';
	$qa_content['form']['hidden']['code_recalc'] = qa_get_form_security_code('admin/recalc');
Scott committed
902

903
	$qa_content['script_var']['qa_warning_recalc'] = qa_lang('admin/stop_recalc_warning');
Scott committed
904

905 906 907
	$qa_content['script_onloads'][] = array(
		"qa_recalc_click('dorecountposts', document.getElementById('dosaveoptions'), null, 'recalc_ok');"
	);
Scott committed
908

909 910 911
} elseif ($startmailing) {
	if (qa_post_text('has_js')) {
		$qa_content['form']['ok'] = '<span id="mailing_ok">' . qa_html($mailingprogress) . '</span>';
Scott committed
912

913 914 915
		$qa_content['script_onloads'][] = array(
			"qa_mailing_start('mailing_ok', 'domailingpause');"
		);
Scott committed
916

917
	} else { // rudimentary non-Javascript version of mass mailing loop
Scott committed
918
		echo '<code>';
Scott committed
919

920 921
		while (true) {
			qa_mailing_perform_step();
Scott committed
922

923
			$message = qa_mailing_progress_message();
Scott committed
924

925 926
			if (!isset($message))
				break;
Scott committed
927

928
			echo qa_html($message) . str_repeat('    ', 1024) . "<br>\n";
Scott committed
929

930 931
			flush();
			sleep(1);
Scott committed
932 933
		}

Scott committed
934
		echo qa_lang_html('admin/mailing_complete').'</code><p><a href="'.qa_path_html('admin/mailing').'">'.qa_lang_html('admin/admin_title').' - '.qa_lang_html('admin/mailing_title').'</a>';
Scott committed
935

936
		qa_exit();
Scott committed
937
	}
938
}
Scott committed
939 940


941 942 943 944 945 946
function qa_optionfield_make_select(&$optionfield, $options, $value, $default)
{
	$optionfield['type'] = 'select';
	$optionfield['options'] = $options;
	$optionfield['value'] = isset($options[qa_html($value)]) ? $options[qa_html($value)] : @$options[$default];
}
Scott committed
947

948
$indented = false;
Scott committed
949

950 951 952
foreach ($showoptions as $optionname) {
	if (empty($optionname)) {
		$indented = false;
Scott committed
953

954 955 956
		$qa_content['form']['fields'][] = array(
			'type' => 'blank'
		);
Scott committed
957

958 959 960 961 962
	} elseif (strpos($optionname, '/') !== false) {
		$qa_content['form']['fields'][] = array(
			'type' => 'static',
			'label' => qa_lang_html($optionname),
		);
Scott committed
963

964
		$indented = true;
Scott committed
965

966 967 968 969
	} else {
		$type = @$optiontype[$optionname];
		if ($type == 'number-blank')
			$type = 'number';
Scott committed
970

971
		$value = $options[$optionname];
Scott committed
972

973 974 975 976 977 978 979 980
		$optionfield = array(
			'id' => $optionname,
			'label' => ($indented ? '&ndash; ' : '') . qa_lang_html('options/' . $optionname),
			'tags' => 'name="option_' . $optionname . '" id="option_' . $optionname . '"',
			'value' => qa_html($value),
			'type' => $type,
			'error' => qa_html(@$errors[$optionname]),
		);
Scott committed
981

982 983
		if (isset($optionmaximum[$optionname]))
			$optionfield['note'] = qa_lang_html_sub('admin/maximum_x', $optionmaximum[$optionname]);
Scott committed
984

985 986
		$feedrequest = null;
		$feedisexample = false;
Scott committed
987

988 989 990
		switch ($optionname) { // special treatment for certain options
			case 'site_language':
				require_once QA_INCLUDE_DIR . 'util/string.php';
Scott committed
991

992
				qa_optionfield_make_select($optionfield, qa_admin_language_options(), $value, '');
Scott committed
993

994 995 996 997
				$optionfield['suffix'] = strtr(qa_lang_html('admin/check_language_suffix'), array(
					'^1' => '<a href="' . qa_html(qa_path_to_root() . 'qa-include/qa-check-lang.php') . '">',
					'^2' => '</a>',
				));
Scott committed
998

999 1000 1001
				if (!qa_has_multibyte())
					$optionfield['error'] = qa_lang_html('admin/no_multibyte');
				break;
Scott committed
1002

1003 1004
			case 'neat_urls':
				$neatoptions = array();
Scott committed
1005

1006 1007 1008 1009 1010 1011 1012
				$rawoptions = array(
					QA_URL_FORMAT_NEAT,
					QA_URL_FORMAT_INDEX,
					QA_URL_FORMAT_PARAM,
					QA_URL_FORMAT_PARAMS,
					QA_URL_FORMAT_SAFEST,
				);
Scott committed
1013

1014 1015
				foreach ($rawoptions as $rawoption) {
					$neatoptions[$rawoption] =
Scott committed
1016
						'<iframe src="' . qa_path_html('url/test/' . QA_URL_TEST_STRING, array('dummy' => '', 'param' => QA_URL_TEST_STRING), null, $rawoption) . '" width="20" height="16" style="vertical-align:middle; border:0" scrolling="no"></iframe>&nbsp;' .
1017 1018 1019 1020 1021 1022 1023 1024
						'<small>' .
						qa_html(urldecode(qa_path('123/why-do-birds-sing', null, '/', $rawoption))) .
						(($rawoption == QA_URL_FORMAT_NEAT) ? strtr(qa_lang_html('admin/neat_urls_note'), array(
							'^1' => '<a href="http://www.question2answer.org/htaccess.php" target="_blank">',
							'^2' => '</a>',
						)) : '') .
						'</small>';
				}
Scott committed
1025

1026
				qa_optionfield_make_select($optionfield, $neatoptions, $value, QA_URL_FORMAT_SAFEST);
Scott committed
1027

1028 1029 1030
				$optionfield['type'] = 'select-radio';
				$optionfield['note'] = qa_lang_html_sub('admin/url_format_note', '<span style=" ' . qa_admin_url_test_html() . '/span>');
				break;
Scott committed
1031

1032 1033 1034 1035 1036
			case 'site_theme':
			case 'site_theme_mobile':
				$themeoptions = qa_admin_theme_options();
				if (!isset($themeoptions[$value]))
					$value = 'Classic'; // check here because we also need $value for qa_addon_metadata()
Scott committed
1037

1038
				qa_optionfield_make_select($optionfield, $themeoptions, $value, 'Classic');
Scott committed
1039

1040 1041 1042 1043 1044
				$metadataUtil = new Q2A_Util_Metadata();
				$themedirectory = QA_THEME_DIR . $value;
				$metadata = $metadataUtil->fetchFromAddonPath($themedirectory);
				if (empty($metadata)) {
					// limit theme parsing to first 8kB
1045
					$contents = @file_get_contents($themedirectory . '/qa-styles.css', false, null, 0, 8192);
1046 1047
					$metadata = qa_addon_metadata($contents, 'Theme');
				}
Scott committed
1048

1049 1050 1051 1052
				if (strlen(@$metadata['version']))
					$namehtml = 'v' . qa_html($metadata['version']);
				else
					$namehtml = '';
Scott committed
1053

1054 1055 1056
				if (strlen(@$metadata['uri'])) {
					if (!strlen($namehtml))
						$namehtml = qa_html($value);
Scott committed
1057

1058 1059
					$namehtml = '<a href="' . qa_html($metadata['uri']) . '">' . $namehtml . '</a>';
				}
Scott committed
1060

1061 1062 1063
				$authorhtml = '';
				if (strlen(@$metadata['author'])) {
					$authorhtml = qa_html($metadata['author']);
Scott committed
1064

1065 1066
					if (strlen(@$metadata['author_uri']))
						$authorhtml = '<a href="' . qa_html($metadata['author_uri']) . '">' . $authorhtml . '</a>';
Scott committed
1067

1068
					$authorhtml = qa_lang_html_sub('main/by_x', $authorhtml);
Scott committed
1069

1070
				}
Scott committed
1071

1072 1073 1074
				$updatehtml = '';
				if (strlen(@$metadata['version']) && strlen(@$metadata['update_uri'])) {
					$elementid = 'version_check_' . $optionname;
Scott committed
1075

1076
					$updatehtml = '(<span id="' . $elementid . '">...</span>)';
Scott committed
1077

1078
					$qa_content['script_onloads'][] = array(
1079
						"qa_version_check(" . qa_js($metadata['update_uri']) . ", " . qa_js($metadata['version'], true) . ", " . qa_js($elementid) . ", false);"
1080
					);
Scott committed
1081

1082
				}
Scott committed
1083

1084 1085
				$optionfield['suffix'] = $namehtml . ' ' . $authorhtml . ' ' . $updatehtml;
				break;
Scott committed
1086

1087 1088 1089 1090
			case 'site_text_direction':
				$directions = array('ltr' => 'LTR', 'rtl' => 'RTL');
				qa_optionfield_make_select($optionfield, $directions, $value, 'ltr');
				break;
Scott committed
1091

1092 1093 1094 1095 1096 1097 1098
			case 'tags_or_categories':
				qa_optionfield_make_select($optionfield, array(
					'' => qa_lang_html('admin/no_classification'),
					't' => qa_lang_html('admin/tags'),
					'c' => qa_lang_html('admin/categories'),
					'tc' => qa_lang_html('admin/tags_and_categories'),
				), $value, 'tc');
Scott committed
1099

1100
				$optionfield['error'] = '';
Scott committed
1101

1102 1103
				if (qa_opt('cache_tagcount') && !qa_using_tags())
					$optionfield['error'] .= qa_lang_html('admin/tags_not_shown') . ' ';
Scott committed
1104

1105 1106 1107 1108 1109
				if (!qa_using_categories()) {
					foreach ($categories as $category) {
						if ($category['qcount']) {
							$optionfield['error'] .= qa_lang_html('admin/categories_not_shown');
							break;
Scott committed
1110 1111
						}
					}
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
				}
				break;

			case 'smtp_secure':
				qa_optionfield_make_select($optionfield, array(
					'' => qa_lang_html('options/smtp_secure_none'),
					'ssl' => 'SSL',
					'tls' => 'TLS',
				), $value, '');
				break;

			case 'custom_sidebar':
			case 'custom_sidepanel':
			case 'custom_header':
			case 'custom_footer':
			case 'custom_in_head':
			case 'home_description':
				unset($optionfield['label']);
				$optionfield['rows'] = 6;
				break;

			case 'custom_home_content':
				$optionfield['rows'] = 16;
				break;

			case 'show_custom_register':
			case 'show_register_terms':
			case 'show_custom_welcome':
			case 'show_notice_welcome':
			case 'show_notice_visitor':
				$optionfield['style'] = 'tall';
				break;

			case 'custom_register':
			case 'register_terms':
			case 'custom_welcome':
			case 'notice_welcome':
			case 'notice_visitor':
				unset($optionfield['label']);
				$optionfield['style'] = 'tall';
				$optionfield['rows'] = 3;
				break;

			case 'avatar_allow_gravatar':
				$optionfield['label'] = strtr($optionfield['label'], array(
					'^1' => '<a href="http://www.gravatar.com/" target="_blank">',
					'^2' => '</a>',
				));
Scott committed
1160

1161
				if (!qa_has_gd_image()) {
Scott committed
1162
					$optionfield['style'] = 'tall';
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
					$optionfield['error'] = qa_lang_html('admin/no_image_gd');
				}
				break;

			case 'avatar_store_size':
			case 'avatar_profile_size':
			case 'avatar_users_size':
			case 'avatar_q_page_q_size':
			case 'avatar_q_page_a_size':
			case 'avatar_q_page_c_size':
			case 'avatar_q_list_size':
			case 'avatar_message_list_size':
				$optionfield['note'] = qa_lang_html('admin/pixels');
				break;

			case 'avatar_default_show':
				$qa_content['form']['tags'] .= 'enctype="multipart/form-data"';
				$optionfield['label'] .= ' <span style="margin:2px 0; display:inline-block;">' .
					qa_get_avatar_blob_html(qa_opt('avatar_default_blobid'), qa_opt('avatar_default_width'), qa_opt('avatar_default_height'), 32) .
					'</span> <input name="avatar_default_file" type="file" style="width:16em;">';
				break;

			case 'logo_width':
			case 'logo_height':
				$optionfield['suffix'] = qa_lang_html('admin/pixels');
				break;

			case 'pages_prev_next':
				qa_optionfield_make_select($optionfield, array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5), $value, 3);
				break;

			case 'columns_tags':
			case 'columns_users':
				qa_optionfield_make_select($optionfield, array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5), $value, 2);
				break;

			case 'min_len_q_title':
			case 'q_urls_title_length':
			case 'min_len_q_content':
			case 'min_len_a_content':
			case 'min_len_c_content':
				$optionfield['note'] = qa_lang_html('admin/characters');
				break;

1207 1208 1209 1210
			case 'recalc_hotness_q_view':
				$optionfield['note'] = '<span class="qa-form-wide-help" title="' . qa_lang_html('admin/recalc_hotness_q_view_note') . '">?</span>';
				break;

1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
			case 'min_num_q_tags':
			case 'max_num_q_tags':
				$optionfield['note'] = qa_lang_html_sub('main/x_tags', ''); // this to avoid language checking error: a_lang('main/1_tag')
				break;

			case 'show_full_date_days':
				$optionfield['note'] = qa_lang_html_sub('main/x_days', '');
				break;

			case 'sort_answers_by':
				qa_optionfield_make_select($optionfield, array(
					'created' => qa_lang_html('options/sort_time'),
					'votes' => qa_lang_html('options/sort_votes'),
				), $value, 'created');
				break;

			case 'page_size_q_as':
				$optionfield['note'] = qa_lang_html_sub('main/x_answers', '');
				break;

			case 'show_a_form_immediate':
				qa_optionfield_make_select($optionfield, array(
					'always' => qa_lang_html('options/show_always'),
					'if_no_as' => qa_lang_html('options/show_if_no_as'),
					'never' => qa_lang_html('options/show_never'),
				), $value, 'if_no_as');
				break;

			case 'show_fewer_cs_from':
			case 'show_fewer_cs_count':
				$optionfield['note'] = qa_lang_html_sub('main/x_comments', '');
				break;

			case 'match_related_qs':
			case 'match_ask_check_qs':
			case 'match_example_tags':
				qa_optionfield_make_select($optionfield, qa_admin_match_options(), $value, 3);
				break;

			case 'block_bad_words':
1251
			case 'block_bad_usernames':
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
				$optionfield['style'] = 'tall';
				$optionfield['rows'] = 4;
				$optionfield['note'] = qa_lang_html('admin/block_words_note');
				break;

			case 'editor_for_qs':
			case 'editor_for_as':
			case 'editor_for_cs':
				$editors = qa_list_modules('editor');

				$selectoptions = array();

				foreach ($editors as $editor) {
					$selectoptions[qa_html($editor)] = strlen($editor) ? qa_html($editor) : qa_lang_html('admin/basic_editor');

					if ($editor == $value) {
						$module = qa_load_module('editor', $editor);

						if (method_exists($module, 'admin_form')) {
							$optionfield['note'] = '<a href="' . qa_admin_module_options_path('editor', $editor) . '">' . qa_lang_html('admin/options') . '</a>';
						}
Scott committed
1273
					}
1274
				}
Scott committed
1275

1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
				qa_optionfield_make_select($optionfield, $selectoptions, $value, '');
				break;

			case 'show_custom_ask':
			case 'extra_field_active':
			case 'show_custom_answer':
			case 'show_custom_comment':
				$optionfield['style'] = 'tall';
				break;

			case 'custom_ask':
			case 'custom_answer':
			case 'custom_comment':
				$optionfield['style'] = 'tall';
				unset($optionfield['label']);
				$optionfield['rows'] = 3;
				break;

			case 'extra_field_display':
				$optionfield['style'] = 'tall';
				$optionfield['label'] = '<span id="extra_field_label_hidden" style="display:none;">' . $optionfield['label'] . '</span><span id="extra_field_label_shown">' . qa_lang_html('options/extra_field_display_label') . '</span>';
				break;

			case 'extra_field_prompt':
			case 'extra_field_label':
				$optionfield['style'] = 'tall';
				unset($optionfield['label']);
				break;

			case 'search_module':
				foreach ($searchmodules as $modulename => $module) {
					$selectoptions[qa_html($modulename)] = strlen($modulename) ? qa_html($modulename) : qa_lang_html('options/option_default');

Scott committed
1309
					if ($modulename == $value && method_exists($module, 'admin_form')) {
1310
						$optionfield['note'] = '<a href="' . qa_admin_module_options_path('search', $modulename) . '">' . qa_lang_html('admin/options') . '</a>';
Scott committed
1311
					}
1312
				}
Scott committed
1313

1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
				qa_optionfield_make_select($optionfield, $selectoptions, $value, '');
				break;

			case 'hot_weight_q_age':
			case 'hot_weight_a_age':
			case 'hot_weight_answers':
			case 'hot_weight_votes':
			case 'hot_weight_views':
				$optionfield['note'] = '/ 100';
				break;

			case 'moderate_by_points':
				$optionfield['label'] = '<span id="moderate_points_label_off" style="display:none;">' . $optionfield['label'] . '</span><span id="moderate_points_label_on">' . qa_lang_html('options/moderate_points_limit') . '</span>';
				break;

			case 'moderate_points_limit':
				unset($optionfield['label']);
				$optionfield['note'] = qa_lang_html('admin/points');
				break;

			case 'flagging_hide_after':
			case 'flagging_notify_every':
			case 'flagging_notify_first':
				$optionfield['note'] = qa_lang_html_sub('main/x_flags', '');
				break;

			case 'block_ips_write':
				$optionfield['style'] = 'tall';
				$optionfield['rows'] = 4;
				$optionfield['note'] = qa_lang_html('admin/block_ips_note');
				break;

			case 'allow_view_q_bots':
				$optionfield['note'] = $optionfield['label'];
				unset($optionfield['label']);
				break;

			case 'permit_view_q_page':
1352
			case 'permit_view_new_users_page':
1353
			case 'permit_view_special_users_page':
1354 1355 1356 1357 1358
			case 'permit_post_q':
			case 'permit_post_a':
			case 'permit_post_c':
			case 'permit_vote_q':
			case 'permit_vote_a':
Scott committed
1359
			case 'permit_vote_c':
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
			case 'permit_vote_down':
			case 'permit_edit_q':
			case 'permit_retag_cat':
			case 'permit_edit_a':
			case 'permit_edit_c':
			case 'permit_edit_silent':
			case 'permit_flag':
			case 'permit_close_q':
			case 'permit_select_a':
			case 'permit_hide_show':
			case 'permit_moderate':
			case 'permit_delete_hidden':
			case 'permit_anon_view_ips':
			case 'permit_view_voters_flaggers':
			case 'permit_post_wall':
				$dopoints = true;

				if ($optionname == 'permit_retag_cat')
					$optionfield['label'] = qa_lang_html(qa_using_categories() ? 'profile/permit_recat' : 'profile/permit_retag') . ':';
				else
					$optionfield['label'] = qa_lang_html('profile/' . $optionname) . ':';

1382
				if (in_array($optionname, array('permit_view_q_page', 'permit_view_new_users_page', 'permit_view_special_users_page', 'permit_post_q', 'permit_post_a', 'permit_post_c', 'permit_anon_view_ips')))
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
					$widest = QA_PERMIT_ALL;
				elseif ($optionname == 'permit_close_q' || $optionname == 'permit_select_a' || $optionname == 'permit_moderate' || $optionname == 'permit_hide_show')
					$widest = QA_PERMIT_POINTS;
				elseif ($optionname == 'permit_delete_hidden')
					$widest = QA_PERMIT_EDITORS;
				elseif ($optionname == 'permit_view_voters_flaggers' || $optionname == 'permit_edit_silent')
					$widest = QA_PERMIT_EXPERTS;
				else
					$widest = QA_PERMIT_USERS;

				if ($optionname == 'permit_view_q_page') {
					$narrowest = QA_PERMIT_APPROVED;
					$dopoints = false;
1396
				} elseif ($optionname == 'permit_view_special_users_page' || $optionname == 'permit_view_new_users_page') {
1397 1398
					$narrowest = QA_PERMIT_SUPERS;
					$dopoints = false;
1399 1400 1401 1402
				} elseif ($optionname == 'permit_edit_c' || $optionname == 'permit_close_q' || $optionname == 'permit_select_a' || $optionname == 'permit_moderate' || $optionname == 'permit_hide_show' || $optionname == 'permit_anon_view_ips')
					$narrowest = QA_PERMIT_MODERATORS;
				elseif ($optionname == 'permit_post_c' || $optionname == 'permit_edit_q' || $optionname == 'permit_retag_cat' || $optionname == 'permit_edit_a' || $optionname == 'permit_flag')
					$narrowest = QA_PERMIT_EDITORS;
Scott committed
1403
				elseif ($optionname == 'permit_vote_q' || $optionname == 'permit_vote_a' || $optionname == 'permit_vote_c' || $optionname == 'permit_post_wall')
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
					$narrowest = QA_PERMIT_APPROVED_POINTS;
				elseif ($optionname == 'permit_delete_hidden' || $optionname == 'permit_edit_silent')
					$narrowest = QA_PERMIT_ADMINS;
				elseif ($optionname == 'permit_view_voters_flaggers')
					$narrowest = QA_PERMIT_SUPERS;
				else
					$narrowest = QA_PERMIT_EXPERTS;

				$permitoptions = qa_admin_permit_options($widest, $narrowest, (!QA_FINAL_EXTERNAL_USERS) && qa_opt('confirm_user_emails'), $dopoints);

				if (count($permitoptions) > 1) {
					qa_optionfield_make_select($optionfield, $permitoptions, $value,
						($value == QA_PERMIT_CONFIRMED) ? QA_PERMIT_USERS : min(array_keys($permitoptions)));
				} else {
					$optionfield['type'] = 'static';
					$optionfield['value'] = reset($permitoptions);
				}
				break;

			case 'permit_post_q_points':
			case 'permit_post_a_points':
			case 'permit_post_c_points':
			case 'permit_vote_q_points':
			case 'permit_vote_a_points':
Scott committed
1428
			case 'permit_vote_c_points':
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478
			case 'permit_vote_down_points':
			case 'permit_flag_points':
			case 'permit_edit_q_points':
			case 'permit_retag_cat_points':
			case 'permit_edit_a_points':
			case 'permit_edit_c_points':
			case 'permit_close_q_points':
			case 'permit_select_a_points':
			case 'permit_hide_show_points':
			case 'permit_moderate_points':
			case 'permit_delete_hidden_points':
			case 'permit_anon_view_ips_points':
			case 'permit_post_wall_points':
				unset($optionfield['label']);
				$optionfield['type'] = 'number';
				$optionfield['prefix'] = qa_lang_html('admin/users_must_have') . '&nbsp;';
				$optionfield['note'] = qa_lang_html('admin/points');
				break;

			case 'feed_for_qa':
				$feedrequest = 'qa';
				break;

			case 'feed_for_questions':
				$feedrequest = 'questions';
				break;

			case 'feed_for_hot':
				$feedrequest = 'hot';
				break;

			case 'feed_for_unanswered':
				$feedrequest = 'unanswered';
				break;

			case 'feed_for_activity':
				$feedrequest = 'activity';
				break;

			case 'feed_per_category':
				if (count($categories)) {
					$category = reset($categories);
					$categoryslug = $category['tags'];

				} else
					$categoryslug = 'example-category';

				if (qa_opt('feed_for_qa'))
					$feedrequest = 'qa';
				elseif (qa_opt('feed_for_questions'))
Scott committed
1479
					$feedrequest = 'questions';
1480
				else
Scott committed
1481 1482
					$feedrequest = 'activity';

1483 1484 1485
				$feedrequest .= '/' . $categoryslug;
				$feedisexample = true;
				break;
Scott committed
1486

1487 1488
			case 'feed_for_tag_qs':
				$populartags = qa_db_select_with_pending(qa_db_popular_tags_selectspec(0, 1));
Scott committed
1489

1490 1491 1492 1493 1494
				if (count($populartags)) {
					reset($populartags);
					$feedrequest = 'tag/' . key($populartags);
				} else
					$feedrequest = 'tag/singing';
Scott committed
1495

1496 1497
				$feedisexample = true;
				break;
Scott committed
1498

1499 1500 1501 1502
			case 'feed_for_search':
				$feedrequest = 'search/why do birds sing';
				$feedisexample = true;
				break;
Scott committed
1503

1504 1505 1506
			case 'moderate_users':
				$optionfield['note'] = '<a href="' . qa_path_html('admin/users', null, null, null, 'profile_fields') . '">' . qa_lang_html('admin/registration_fields') . '</a>';
				break;
Scott committed
1507

1508 1509
			case 'captcha_module':
				$captchaoptions = array();
Scott committed
1510

1511 1512
				foreach ($captchamodules as $modulename) {
					$captchaoptions[qa_html($modulename)] = qa_html($modulename);
Scott committed
1513

1514 1515 1516 1517 1518
					if ($modulename == $value) {
						$module = qa_load_module('captcha', $modulename);

						if (method_exists($module, 'admin_form')) {
							$optionfield['note'] = '<a href="' . qa_admin_module_options_path('captcha', $modulename) . '">' . qa_lang_html('admin/options') . '</a>';
Scott committed
1519 1520
						}
					}
1521
				}
Scott committed
1522

1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
				qa_optionfield_make_select($optionfield, $captchaoptions, $value, '');
				break;

			case 'moderate_update_time':
				qa_optionfield_make_select($optionfield, array(
					'0' => qa_lang_html('options/time_written'),
					'1' => qa_lang_html('options/time_approved'),
				), $value, '0');
				break;

			case 'max_rate_ip_as':
			case 'max_rate_ip_cs':
			case 'max_rate_ip_flags':
			case 'max_rate_ip_logins':
			case 'max_rate_ip_messages':
			case 'max_rate_ip_qs':
			case 'max_rate_ip_registers':
			case 'max_rate_ip_uploads':
			case 'max_rate_ip_votes':
				$optionfield['note'] = qa_lang_html('admin/per_ip_hour');
				break;

			case 'max_rate_user_as':
			case 'max_rate_user_cs':
			case 'max_rate_user_flags':
			case 'max_rate_user_messages':
			case 'max_rate_user_qs':
			case 'max_rate_user_uploads':
			case 'max_rate_user_votes':
				unset($optionfield['label']);
				$optionfield['note'] = qa_lang_html('admin/per_user_hour');
				break;

			case 'mailing_per_minute':
				$optionfield['suffix'] = qa_lang_html('admin/emails_per_minute');
				break;

1560 1561 1562 1563 1564 1565 1566
			case 'caching_driver':
				qa_optionfield_make_select($optionfield, array(
					'filesystem' => qa_lang_html('options/caching_filesystem'),
					'memcached' => qa_lang_html('options/caching_memcached'),
				), $value, 'filesystem');
				break;

1567 1568 1569 1570 1571 1572 1573 1574
			case 'caching_q_time':
			case 'caching_qlist_time':
			case 'caching_catwidget_time':
				$optionfield['note'] = qa_lang_html_sub('main/x_minutes', '');
				break;
			case 'caching_q_start':
				$optionfield['note'] = qa_lang_html_sub('main/x_days', '');
				break;
Scott committed
1575 1576
		}

1577 1578 1579
		if (isset($feedrequest) && $value) {
			$optionfield['note'] = '<a href="' . qa_path_html(qa_feed_request($feedrequest)) . '">' . qa_lang_html($feedisexample ? 'admin/feed_link_example' : 'admin/feed_link') . '</a>';
		}
Scott committed
1580

1581 1582 1583
		$qa_content['form']['fields'][$optionname] = $optionfield;
	}
}
Scott committed
1584 1585


Scott committed
1586
// Extra items for specific pages
Scott committed
1587

1588 1589 1590
switch ($adminsection) {
	case 'users':
		require_once QA_INCLUDE_DIR . 'app/format.php';
Scott committed
1591

1592 1593
		if (!QA_FINAL_EXTERNAL_USERS) {
			$userfields = qa_db_single_select(qa_db_userfields_selectspec());
Scott committed
1594 1595 1596

			$listhtml = '';

1597 1598
			foreach ($userfields as $userfield) {
				$listhtml .= '<li><b>' . qa_html(qa_user_userfield_label($userfield)) . '</b>';
Scott committed
1599

1600 1601
				$listhtml .= strtr(qa_lang_html('admin/edit_field'), array(
					'^1' => '<a href="' . qa_path_html('admin/userfields', array('edit' => $userfield['fieldid'])) . '">',
Scott committed
1602 1603 1604 1605 1606 1607
					'^2' => '</a>',
				));

				$listhtml .= '</li>';
			}

1608 1609 1610
			$listhtml .= '<li><b><a href="' . qa_path_html('admin/userfields') . '">' . qa_lang_html('admin/add_new_field') . '</a></b></li>';

			$qa_content['form']['fields'][] = array('type' => 'blank');
Scott committed
1611

1612 1613 1614
			$qa_content['form']['fields']['userfields'] = array(
				'label' => qa_lang_html('admin/profile_fields'),
				'id' => 'profile_fields',
Scott committed
1615 1616
				'style' => 'tall',
				'type' => 'custom',
1617
				'html' => strlen($listhtml) ? '<ul style="margin-bottom:0;">' . $listhtml . '</ul>' : null,
Scott committed
1618
			);
1619
		}
Scott committed
1620

1621
		$qa_content['form']['fields'][] = array('type' => 'blank');
Scott committed
1622

1623
		$pointstitle = qa_get_points_to_titles();
Scott committed
1624

1625
		$listhtml = '';
Scott committed
1626

1627 1628 1629
		foreach ($pointstitle as $points => $title) {
			$listhtml .= '<li><b>' . $title . '</b> - ' . (($points == 1) ? qa_lang_html_sub('main/1_point', '1', '1')
					: qa_lang_html_sub('main/x_points', qa_html(qa_format_number($points))));
Scott committed
1630

1631 1632 1633 1634
			$listhtml .= strtr(qa_lang_html('admin/edit_title'), array(
				'^1' => '<a href="' . qa_path_html('admin/usertitles', array('edit' => $points)) . '">',
				'^2' => '</a>',
			));
Scott committed
1635

1636 1637
			$listhtml .= '</li>';
		}
Scott committed
1638

1639
		$listhtml .= '<li><b><a href="' . qa_path_html('admin/usertitles') . '">' . qa_lang_html('admin/add_new_title') . '</a></b></li>';
Scott committed
1640

1641 1642 1643 1644 1645 1646 1647
		$qa_content['form']['fields']['usertitles'] = array(
			'label' => qa_lang_html('admin/user_titles'),
			'style' => 'tall',
			'type' => 'custom',
			'html' => strlen($listhtml) ? '<ul style="margin-bottom:0;">' . $listhtml . '</ul>' : null,
		);
		break;
Scott committed
1648

1649 1650 1651 1652
	case 'layout':
		$listhtml = '';

		$widgetmodules = qa_load_modules_with('widget', 'allow_template');
Scott committed
1653

1654 1655 1656
		foreach ($widgetmodules as $tryname => $trywidget) {
			if (method_exists($trywidget, 'allow_region')) {
				$listhtml .= '<li><b>' . qa_html($tryname) . '</b>';
Scott committed
1657

1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
				$listhtml .= strtr(qa_lang_html('admin/add_widget_link'), array(
					'^1' => '<a href="' . qa_path_html('admin/layoutwidgets', array('title' => $tryname)) . '">',
					'^2' => '</a>',
				));

				if (method_exists($trywidget, 'admin_form'))
					$listhtml .= strtr(qa_lang_html('admin/widget_global_options'), array(
						'^1' => '<a href="' . qa_admin_module_options_path('widget', $tryname) . '">',
						'^2' => '</a>',
					));
Scott committed
1668 1669 1670

				$listhtml .= '</li>';
			}
1671
		}
Scott committed
1672

1673 1674 1675 1676 1677 1678 1679 1680
		if (strlen($listhtml)) {
			$qa_content['form']['fields']['plugins'] = array(
				'label' => qa_lang_html('admin/widgets_explanation'),
				'style' => 'tall',
				'type' => 'custom',
				'html' => '<ul style="margin-bottom:0;">' . $listhtml . '</ul>',
			);
		}
Scott committed
1681

1682
		$widgets = qa_db_single_select(qa_db_widgets_selectspec());
Scott committed
1683

1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
		$listhtml = '';

		$placeoptions = qa_admin_place_options();

		foreach ($widgets as $widget) {
			$listhtml .= '<li><b>' . qa_html($widget['title']) . '</b> - ' .
				'<a href="' . qa_path_html('admin/layoutwidgets', array('edit' => $widget['widgetid'])) . '">' .
				@$placeoptions[$widget['place']] . '</a>';

			$listhtml .= '</li>';
		}

		if (strlen($listhtml)) {
			$qa_content['form']['fields']['widgets'] = array(
				'label' => qa_lang_html('admin/active_widgets_explanation'),
				'type' => 'custom',
				'html' => '<ul style="margin-bottom:0;">' . $listhtml . '</ul>',
Scott committed
1701
			);
1702
		}
Scott committed
1703

1704
		break;
Scott committed
1705

1706 1707 1708 1709 1710 1711
	case 'permissions':
		$qa_content['form']['fields']['permit_block'] = array(
			'type' => 'static',
			'label' => qa_lang_html('options/permit_block'),
			'value' => qa_lang_html('options/permit_moderators'),
		);
Scott committed
1712

1713 1714 1715 1716 1717 1718
		if (!QA_FINAL_EXTERNAL_USERS) {
			$qa_content['form']['fields']['permit_approve_users'] = array(
				'type' => 'static',
				'label' => qa_lang_html('options/permit_approve_users'),
				'value' => qa_lang_html('options/permit_moderators'),
			);
Scott committed
1719

1720 1721 1722 1723 1724
			$qa_content['form']['fields']['permit_create_experts'] = array(
				'type' => 'static',
				'label' => qa_lang_html('options/permit_create_experts'),
				'value' => qa_lang_html('options/permit_moderators'),
			);
Scott committed
1725

1726 1727 1728 1729 1730
			$qa_content['form']['fields']['permit_see_emails'] = array(
				'type' => 'static',
				'label' => qa_lang_html('options/permit_see_emails'),
				'value' => qa_lang_html('options/permit_admins'),
			);
Scott committed
1731

1732 1733 1734 1735 1736
			$qa_content['form']['fields']['permit_delete_users'] = array(
				'type' => 'static',
				'label' => qa_lang_html('options/permit_delete_users'),
				'value' => qa_lang_html('options/permit_admins'),
			);
Scott committed
1737

1738 1739 1740 1741 1742
			$qa_content['form']['fields']['permit_create_eds_mods'] = array(
				'type' => 'static',
				'label' => qa_lang_html('options/permit_create_eds_mods'),
				'value' => qa_lang_html('options/permit_admins'),
			);
Scott committed
1743

1744 1745 1746 1747 1748 1749
			$qa_content['form']['fields']['permit_create_admins'] = array(
				'type' => 'static',
				'label' => qa_lang_html('options/permit_create_admins'),
				'value' => qa_lang_html('options/permit_supers'),
			);
		}
Scott committed
1750

1751
		break;
Scott committed
1752

1753 1754
	case 'mailing':
		require_once QA_INCLUDE_DIR . 'util/sort.php';
Scott committed
1755

1756 1757 1758
		if (isset($mailingprogress)) {
			unset($qa_content['form']['buttons']['save']);
			unset($qa_content['form']['buttons']['reset']);
Scott committed
1759

1760 1761
			if ($startmailing) {
				unset($qa_content['form']['hidden']['dosaveoptions']);
Scott committed
1762

1763 1764
				foreach ($showoptions as $optionname)
					$qa_content['form']['fields'][$optionname]['type'] = 'static';
Scott committed
1765

1766
				$qa_content['form']['fields']['mailing_body']['value'] = qa_html(qa_opt('mailing_body'), true);
Scott committed
1767

1768 1769 1770 1771
				$qa_content['form']['buttons']['stop'] = array(
					'tags' => 'name="domailingpause" id="domailingpause"',
					'label' => qa_lang_html('admin/pause_mailing_button'),
				);
Scott committed
1772

1773 1774 1775 1776
			} else {
				$qa_content['form']['buttons']['resume'] = array(
					'tags' => 'name="domailingresume"',
					'label' => qa_lang_html('admin/resume_mailing_button'),
Scott committed
1777 1778
				);

1779 1780 1781
				$qa_content['form']['buttons']['cancel'] = array(
					'tags' => 'name="domailingcancel"',
					'label' => qa_lang_html('admin/cancel_mailing_button'),
Scott committed
1782 1783
				);
			}
1784 1785
		} else {
			$qa_content['form']['buttons']['spacer'] = array();
Scott committed
1786

1787 1788 1789 1790
			$qa_content['form']['buttons']['test'] = array(
				'tags' => 'name="domailingtest" id="domailingtest"',
				'label' => qa_lang_html('admin/send_test_button'),
			);
1791

1792 1793 1794 1795 1796
			$qa_content['form']['buttons']['start'] = array(
				'tags' => 'name="domailingstart" id="domailingstart"',
				'label' => qa_lang_html('admin/start_mailing_button'),
			);
		}
Scott committed
1797

1798 1799 1800 1801 1802 1803
		if (!$startmailing) {
			$qa_content['form']['fields']['mailing_enabled']['note'] = qa_lang_html('admin/mailing_explanation');
			$qa_content['form']['fields']['mailing_body']['rows'] = 12;
			$qa_content['form']['fields']['mailing_body']['note'] = qa_lang_html('admin/mailing_unsubscribe');
		}
		break;
Scott committed
1804

1805
	case 'caching':
Scott committed
1806 1807
		$cacheDriver = Q2A_Storage_CacheFactory::getCacheDriver();
		$qa_content['error'] = $cacheDriver->getError();
Scott committed
1808 1809 1810 1811 1812 1813 1814 1815 1816
		$cacheStats = $cacheDriver->getStats();

		$qa_content['form_2'] = array(
			'tags' => 'method="post" action="' . qa_path_html('admin/recalc') . '"',

			'title' => qa_lang_html('admin/caching_cleanup'),

			'style' => 'wide',

Scott committed
1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829
			'fields' => array(
				'cache_files' => array(
					'type' => 'static',
					'label' => qa_lang_html('admin/caching_num_items'),
					'value' => qa_html(qa_format_number($cacheStats['files'])),
				),
				'cache_size' => array(
					'type' => 'static',
					'label' => qa_lang_html('admin/caching_space_used'),
					'value' => qa_html(qa_format_number($cacheStats['size'] / 1048576, 1) . ' MB'),
				),
			),

Scott committed
1830
			'buttons' => array(
Scott committed
1831 1832 1833 1834 1835
				'delete_expired' => array(
					'label' => qa_lang_html('admin/caching_delete_expired'),
					'tags' => 'name="docachetrim" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/delete_stop')) . ', \'cachetrim_note\');"',
					'note' => '<span id="cachetrim_note"></span>',
				),
Scott committed
1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
				'delete_all' => array(
					'label' => qa_lang_html('admin/caching_delete_all'),
					'tags' => 'name="docacheclear" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/delete_stop')) . ', \'cacheclear_note\');"',
					'note' => '<span id="cacheclear_note"></span>',
				),
			),

			'hidden' => array(
				'code' => qa_get_form_security_code('admin/recalc'),
			),
		);
1847 1848
		break;
}
Scott committed
1849 1850


1851 1852
if (isset($checkboxtodisplay))
	qa_set_display_rules($qa_content, $checkboxtodisplay);
Scott committed
1853

1854
$qa_content['navigation']['sub'] = qa_admin_sub_navigation();
Scott committed
1855 1856


1857
return $qa_content;