qa-page-admin-default.php 60.3 KB
Newer Older
Gideon Greenspan committed
1
<?php
Scott Vivian committed
2

Gideon Greenspan committed
3
/*
Gideon Greenspan committed
4
	Question2Answer by Gideon Greenspan and contributors
Gideon Greenspan committed
5 6 7

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-page-admin-default.php
	Version: See define()s at top of qa-include/qa-base.php
	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.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
	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
*/

	if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
		header('Location: ../');
		exit;
	}

	require_once QA_INCLUDE_DIR.'qa-db-admin.php';
	require_once QA_INCLUDE_DIR.'qa-db-maxima.php';
	require_once QA_INCLUDE_DIR.'qa-db-selects.php';
	require_once QA_INCLUDE_DIR.'qa-app-options.php';
	require_once QA_INCLUDE_DIR.'qa-app-admin.php';
Scott Vivian committed
37 38


Scott Vivian committed
39
	$adminsection = strtolower(qa_request_part(1));
Scott Vivian committed
40 41


Gideon Greenspan committed
42
//	Get list of categories and all options
Scott Vivian committed
43

Scott Vivian committed
44
	$categories = qa_db_select_with_pending(qa_db_category_nav_selectspec(null, true));
Scott Vivian committed
45

Gideon Greenspan committed
46 47 48 49

//	See if we need to redirect

	if (empty($adminsection)) {
Scott Vivian committed
50
		$subnav = qa_admin_sub_navigation();
Gideon Greenspan committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

		if (isset($subnav[@$_COOKIE['qa_admin_last']]))
			qa_redirect($_COOKIE['qa_admin_last']);
		elseif (count($subnav)) {
			reset($subnav);
			qa_redirect(key($subnav));
		}
	}


//	Check admin privileges (do late to allow one DB query)

	if (!qa_admin_check_privileges($qa_content))
		return $qa_content;


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

Scott Vivian committed
69
	$optiontype = array(
Gideon Greenspan committed
70
		'avatar_message_list_size' => 'number',
Gideon Greenspan committed
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
		'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',
		'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',
Gideon Greenspan committed
115
		'moderate_points_limit' => 'number',
Gideon Greenspan committed
116 117 118 119 120
		'page_size_activity' => 'number',
		'page_size_ask_check_qs' => 'number',
		'page_size_ask_tags' => 'number',
		'page_size_home' => 'number',
		'page_size_hot_qs' => 'number',
Scott committed
121
		'page_size_pms' => 'number',
Gideon Greenspan committed
122 123 124 125 126 127 128 129
		'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',
Gideon Greenspan committed
130
		'page_size_wall' => 'number',
Gideon Greenspan committed
131 132 133 134 135 136
		'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',
Scott Vivian committed
137

Gideon Greenspan committed
138 139
		'allow_change_usernames' => 'checkbox',
		'allow_close_questions' => 'checkbox',
Gideon Greenspan committed
140
		'allow_login_email_only' => 'checkbox',
Gideon Greenspan committed
141 142
		'allow_multi_answers' => 'checkbox',
		'allow_private_messages' => 'checkbox',
Gideon Greenspan committed
143
		'allow_user_walls' => 'checkbox',
Gideon Greenspan committed
144 145
		'allow_self_answer' => 'checkbox',
		'allow_view_q_bots' => 'checkbox',
Gideon Greenspan committed
146
		'approve_user_required' => 'checkbox',
Gideon Greenspan committed
147 148 149 150 151 152 153
		'avatar_allow_gravatar' => 'checkbox',
		'avatar_allow_upload' => 'checkbox',
		'avatar_default_show' => 'checkbox',
		'captcha_on_anon_post' => 'checkbox',
		'captcha_on_feedback' => 'checkbox',
		'captcha_on_register' => 'checkbox',
		'captcha_on_reset_password' => 'checkbox',
Gideon Greenspan committed
154
		'captcha_on_unapproved' => 'checkbox',
Gideon Greenspan committed
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
		'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',
Gideon Greenspan committed
184
		'moderate_edited_again' => 'checkbox',
Gideon Greenspan committed
185
		'moderate_notify_admin' => 'checkbox',
Gideon Greenspan committed
186
		'moderate_unapproved' => 'checkbox',
Gideon Greenspan committed
187
		'moderate_unconfirmed' => 'checkbox',
Gideon Greenspan committed
188
		'moderate_users' => 'checkbox',
Gideon Greenspan committed
189 190 191 192
		'neat_urls' => 'checkbox',
		'notify_admin_q_post' => 'checkbox',
		'notify_users_default' => 'checkbox',
		'q_urls_remove_accents' => 'checkbox',
Gideon Greenspan committed
193
		'register_notify_admin' => 'checkbox',
Gideon Greenspan committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
		'show_c_reply_buttons' => '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',
210
		'show_register_terms' => 'checkbox',
Gideon Greenspan committed
211 212 213 214 215
		'show_selected_first' => 'checkbox',
		'show_url_links' => 'checkbox',
		'show_user_points' => 'checkbox',
		'show_user_titles' => 'checkbox',
		'show_view_counts' => 'checkbox',
Gideon Greenspan committed
216
		'show_view_count_q_page' => 'checkbox',
Gideon Greenspan committed
217 218 219 220 221 222 223 224 225 226
		'show_when_created' => 'checkbox',
		'site_maintenance' => 'checkbox',
		'smtp_active' => 'checkbox',
		'smtp_authenticate' => 'checkbox',
		'suspend_register_users' => 'checkbox',
		'tag_separator_comma' => 'checkbox',
		'votes_separated' => 'checkbox',
		'voting_on_as' => 'checkbox',
		'voting_on_q_page_only' => 'checkbox',
		'voting_on_qs' => 'checkbox',
Scott Vivian committed
227

Gideon Greenspan committed
228 229
		'smtp_password' => 'password',
	);
Scott Vivian committed
230

Scott Vivian committed
231
	$optionmaximum = array(
Gideon Greenspan committed
232 233 234 235 236 237 238
		'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,
Scott committed
239
		'page_size_pms' => QA_DB_RETRIEVE_MESSAGES,
Gideon Greenspan committed
240 241 242 243 244 245 246
		'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,
Gideon Greenspan committed
247
		'page_size_wall' => QA_DB_RETRIEVE_MESSAGES,
Gideon Greenspan committed
248
	);
Scott Vivian committed
249

Scott Vivian committed
250
	$optionminimum = array(
Gideon Greenspan committed
251 252 253 254
		'flagging_hide_after' => 2,
		'flagging_notify_every' => 1,
		'flagging_notify_first' => 1,
		'max_num_q_tags' => 2,
Gideon Greenspan committed
255
		'max_rate_ip_logins' => 1,
Gideon Greenspan committed
256 257 258 259 260
		'page_size_activity' => 1,
		'page_size_ask_check_qs' => 3,
		'page_size_ask_tags' => 3,
		'page_size_home' => 1,
		'page_size_hot_qs' => 1,
Scott committed
261
		'page_size_pms' => 1,
Gideon Greenspan committed
262 263 264 265 266 267
		'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,
Gideon Greenspan committed
268
		'page_size_wall' => 1,
Gideon Greenspan committed
269
	);
Scott Vivian committed
270

Gideon Greenspan committed
271 272

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

Scott Vivian committed
274 275
	$formstyle = 'tall';
	$checkboxtodisplay = null;
Scott Vivian committed
276

Scott Vivian committed
277
	$maxpermitpost = max(qa_opt('permit_post_q'), qa_opt('permit_post_a'));
Gideon Greenspan committed
278
	if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
Scott Vivian committed
279
		$maxpermitpost = max($maxpermitpost, qa_opt('permit_post_c'));
Scott Vivian committed
280

Gideon Greenspan committed
281 282
	switch ($adminsection) {
		case 'general':
Scott Vivian committed
283
			$subtitle = 'admin/general_title';
Scott committed
284
			$showoptions = array('site_title', 'site_url', 'neat_urls', 'site_language', 'site_theme', 'site_theme_mobile', 'site_text_direction', 'tags_or_categories', 'site_maintenance');
Gideon Greenspan committed
285
			break;
Scott Vivian committed
286

Gideon Greenspan committed
287
		case 'emails':
Scott Vivian committed
288 289
			$subtitle = 'admin/emails_title';
			$showoptions = array(
Gideon Greenspan committed
290 291 292
				'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 Vivian committed
293

Scott Vivian committed
294
			$checkboxtodisplay = array(
Gideon Greenspan committed
295 296 297 298 299 300 301 302
				'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 Vivian committed
303

Gideon Greenspan committed
304
		case 'users':
Scott Vivian committed
305
			$subtitle = 'admin/users_title';
Gideon Greenspan committed
306

Scott Vivian committed
307
			$showoptions = array('show_notice_visitor', 'notice_visitor');
Gideon Greenspan committed
308 309 310

			if (!QA_FINAL_EXTERNAL_USERS) {
				require_once QA_INCLUDE_DIR.'qa-util-image.php';
Scott Vivian committed
311

312
				array_push($showoptions, 'show_custom_register', 'custom_register', 'show_register_terms', 'register_terms', 'show_notice_welcome', 'notice_welcome', 'show_custom_welcome', 'custom_welcome');
Scott Vivian committed
313

Scott committed
314
				array_push($showoptions, '' ,'allow_login_email_only', 'allow_change_usernames', 'allow_private_messages', 'show_message_history', 'page_size_pms', 'allow_user_walls', 'page_size_wall', '', 'avatar_allow_gravatar');
Scott Vivian committed
315

Gideon Greenspan committed
316 317 318
				if (qa_has_gd_image())
					array_push($showoptions, 'avatar_allow_upload', 'avatar_store_size', 'avatar_default_show');
			}
Scott Vivian committed
319

Scott Vivian committed
320
			$showoptions[] = '';
Scott Vivian committed
321

Gideon Greenspan committed
322
			if (!QA_FINAL_EXTERNAL_USERS)
Scott Vivian committed
323
				$showoptions[] = 'avatar_profile_size';
Scott Vivian committed
324

Gideon Greenspan committed
325 326
			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 Vivian committed
327

Scott Vivian committed
328
			$checkboxtodisplay = array(
Gideon Greenspan committed
329
				'custom_register' => 'option_show_custom_register',
330
				'register_terms' => 'option_show_register_terms',
Gideon Greenspan committed
331 332 333 334 335 336 337
				'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 Vivian committed
338

Gideon Greenspan committed
339
			if (!QA_FINAL_EXTERNAL_USERS)
Scott Vivian committed
340
				$checkboxtodisplay = array_merge($checkboxtodisplay, array(
Scott committed
341
					'page_size_pms' => 'option_allow_private_messages && option_show_message_history',
Gideon Greenspan committed
342
					'page_size_wall' => 'option_allow_user_walls',
Gideon Greenspan committed
343 344 345 346 347 348
					'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',
Gideon Greenspan committed
349
					'avatar_message_list_size' => 'option_allow_private_messages || option_allow_user_walls',
Gideon Greenspan committed
350
				));
Scott Vivian committed
351

Scott Vivian committed
352
			$formstyle = 'wide';
Gideon Greenspan committed
353
			break;
Scott Vivian committed
354

Gideon Greenspan committed
355
		case 'layout':
Scott Vivian committed
356 357
			$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', '');
Scott Vivian committed
358

Scott Vivian committed
359
			$checkboxtodisplay = array(
Gideon Greenspan committed
360 361 362 363 364 365 366 367 368 369 370 371 372
				'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;
Scott Vivian committed
373

Gideon Greenspan committed
374
		case 'viewing':
Scott Vivian committed
375 376
			$subtitle = 'admin/viewing_title';
			$showoptions = array('q_urls_title_length', 'q_urls_remove_accents', 'do_count_q_views', 'show_view_counts', 'show_view_count_q_page', '', 'voting_on_qs', 'voting_on_q_page_only', 'voting_on_as', 'votes_separated', '', 'show_url_links', 'links_in_new_window', 'show_when_created', 'show_full_date_days');
Scott Vivian committed
377

Gideon Greenspan committed
378
			if (count(qa_get_points_to_titles()))
Scott Vivian committed
379
				$showoptions[] = 'show_user_titles';
Scott Vivian committed
380

Gideon Greenspan committed
381
			array_push($showoptions, 'show_user_points', '', 'sort_answers_by', 'show_selected_first', 'page_size_q_as', 'show_a_form_immediate');
Scott Vivian committed
382

Gideon Greenspan committed
383
			if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
Gideon Greenspan committed
384
				array_push($showoptions, 'show_fewer_cs_from', 'show_fewer_cs_count', 'show_c_reply_buttons');
Scott Vivian committed
385

Scott Vivian committed
386
			$showoptins[] = '';
Scott Vivian committed
387

Scott Vivian committed
388
			$widgets = qa_db_single_select(qa_db_widgets_selectspec());
Scott Vivian committed
389

Gideon Greenspan committed
390
			foreach ($widgets as $widget)
Scott Vivian committed
391
				if ($widget['title'] == 'Related Questions') {
Gideon Greenspan committed
392 393 394
					array_push($showoptions, 'match_related_qs', 'page_size_related_qs', '');
					break;
				}
Scott Vivian committed
395

Scott Vivian committed
396
			$showoptions[] = 'pages_prev_next';
Gideon Greenspan committed
397

Scott Vivian committed
398
			$formstyle = 'wide';
Gideon Greenspan committed
399

Scott Vivian committed
400
			$checkboxtodisplay = array(
Gideon Greenspan committed
401
				'show_view_counts' => 'option_do_count_q_views',
Gideon Greenspan committed
402
				'show_view_count_q_page' => 'option_do_count_q_views',
Gideon Greenspan committed
403 404 405 406 407
				'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 Vivian committed
408

Gideon Greenspan committed
409
		case 'lists':
Scott Vivian committed
410
			$subtitle = 'admin/lists_title';
Scott Vivian committed
411

Scott Vivian committed
412
			$showoptions = array('page_size_home', 'page_size_activity', 'page_size_qs', 'page_size_hot_qs', 'page_size_una_qs');
Scott Vivian committed
413

Gideon Greenspan committed
414
			if (qa_using_tags())
Scott Vivian committed
415
				$showoptions[] = 'page_size_tag_qs';
Scott Vivian committed
416

Scott Vivian committed
417
			$showoptions[] = '';
Scott Vivian committed
418

Gideon Greenspan committed
419 420
			if (qa_using_tags())
				array_push($showoptions, 'page_size_tags', 'columns_tags');
Scott Vivian committed
421

Gideon Greenspan committed
422
			array_push($showoptions, 'page_size_users', 'columns_users', '');
Scott Vivian committed
423

Scott Vivian committed
424
			$searchmodules = qa_load_modules_with('search', 'process_search');
Scott Vivian committed
425

Gideon Greenspan committed
426
			if (count($searchmodules))
Scott Vivian committed
427
				$showoptions[] = 'search_module';
Scott Vivian committed
428

Scott Vivian committed
429
			$showoptions[] = 'page_size_search';
Scott Vivian committed
430

Gideon Greenspan committed
431
			array_push($showoptions, '', 'admin/hotness_factors', 'hot_weight_q_age', 'hot_weight_a_age', 'hot_weight_answers', 'hot_weight_votes');
Scott Vivian committed
432

Gideon Greenspan committed
433
			if (qa_opt('do_count_q_views'))
Scott Vivian committed
434
				$showoptions[] = 'hot_weight_views';
Scott Vivian committed
435

Scott Vivian committed
436
			$formstyle = 'wide';
Scott Vivian committed
437

Gideon Greenspan committed
438
			break;
Scott Vivian committed
439

Gideon Greenspan committed
440
		case 'posting':
Scott Vivian committed
441
			$getoptions = qa_get_options(array('tags_or_categories'));
Scott Vivian committed
442

Scott Vivian committed
443
			$subtitle = 'admin/posting_title';
Gideon Greenspan committed
444

Scott Vivian committed
445
			$showoptions = array('do_close_on_select', 'allow_close_questions', 'allow_self_answer', 'allow_multi_answers', 'follow_on_as', 'comment_on_qs', 'comment_on_as', '');
Scott Vivian committed
446

Gideon Greenspan committed
447 448
			if (count(qa_list_modules('editor'))>1)
				array_push($showoptions, 'editor_for_qs', 'editor_for_as', 'editor_for_cs', '');
Scott Vivian committed
449

Gideon Greenspan committed
450
			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 Vivian committed
451

Gideon Greenspan committed
452
			array_push($showoptions, 'min_len_q_title', 'max_len_q_title', 'min_len_q_content');
Scott Vivian committed
453

Gideon Greenspan committed
454 455
			if (qa_using_tags())
				array_push($showoptions, 'min_num_q_tags', 'max_num_q_tags', 'tag_separator_comma');
Scott Vivian committed
456

Gideon Greenspan committed
457
			array_push($showoptions, 'min_len_a_content', 'min_len_c_content', 'notify_users_default');
Scott Vivian committed
458

Gideon Greenspan committed
459
			array_push($showoptions, '', 'block_bad_words', '', 'do_ask_check_qs', 'match_ask_check_qs', 'page_size_ask_check_qs', '');
Gideon Greenspan committed
460 461 462 463

			if (qa_using_tags())
				array_push($showoptions, 'do_example_tags', 'match_example_tags', 'do_complete_tags', 'page_size_ask_tags');

Scott Vivian committed
464
			$formstyle = 'wide';
Gideon Greenspan committed
465

Scott Vivian committed
466
			$checkboxtodisplay = array(
Gideon Greenspan committed
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
				'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 Vivian committed
484

Gideon Greenspan committed
485
		case 'permissions':
Scott Vivian committed
486
			$subtitle = 'admin/permissions_title';
Scott Vivian committed
487

Scott Vivian committed
488
			$permitoptions = qa_get_permit_options();
Scott Vivian committed
489

Scott Vivian committed
490 491
			$showoptions = array();
			$checkboxtodisplay = array();
Scott Vivian committed
492

Gideon Greenspan committed
493
			foreach ($permitoptions as $permitoption) {
Scott Vivian committed
494
				$showoptions[] = $permitoption;
Scott Vivian committed
495

Scott Vivian committed
496 497 498
				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 Vivian committed
499

Scott Vivian committed
500 501 502 503
				}
				else {
					$showoptions[] = $permitoption.'_points';
					$checkboxtodisplay[$permitoption.'_points'] = '(option_'.$permitoption.'=='.qa_js(QA_PERMIT_POINTS).
Gideon Greenspan committed
504
						')||(option_'.$permitoption.'=='.qa_js(QA_PERMIT_POINTS_CONFIRMED).')||(option_'.$permitoption.'=='.qa_js(QA_PERMIT_APPROVED_POINTS).')';
Gideon Greenspan committed
505 506
				}
			}
Scott Vivian committed
507

Scott Vivian committed
508
			$formstyle = 'wide';
Gideon Greenspan committed
509
			break;
Scott Vivian committed
510

Gideon Greenspan committed
511
		case 'feeds':
Scott Vivian committed
512
			$subtitle = 'admin/feeds_title';
Scott Vivian committed
513

Scott Vivian committed
514
			$showoptions = array('feed_for_questions', 'feed_for_qa', 'feed_for_activity');
Scott Vivian committed
515

Gideon Greenspan committed
516
			array_push($showoptions, 'feed_for_hot', 'feed_for_unanswered');
Scott Vivian committed
517

Gideon Greenspan committed
518
			if (qa_using_tags())
Scott Vivian committed
519
				$showoptions[] = 'feed_for_tag_qs';
Scott Vivian committed
520

Gideon Greenspan committed
521
			if (qa_using_categories())
Scott Vivian committed
522
				$showoptions[] = 'feed_per_category';
Scott Vivian committed
523

Gideon Greenspan committed
524
			array_push($showoptions, 'feed_for_search', '', 'feed_number_items', 'feed_full_text');
Scott Vivian committed
525

Scott Vivian committed
526
			$formstyle = 'wide';
Gideon Greenspan committed
527

Scott Vivian committed
528
			$checkboxtodisplay = array(
Gideon Greenspan committed
529 530 531
				'feed_per_category' => 'option_feed_for_qa || option_feed_for_questions || option_feed_for_unanswered || option_feed_for_activity',
			);
			break;
Scott Vivian committed
532

Gideon Greenspan committed
533
		case 'spam':
Scott Vivian committed
534
			$subtitle = 'admin/spam_title';
Scott Vivian committed
535

Scott Vivian committed
536
			$showoptions = array();
Scott Vivian committed
537

Scott Vivian committed
538
			$getoptions = qa_get_options(array('feedback_enabled', 'permit_post_q', 'permit_post_a', 'permit_post_c'));
Scott Vivian committed
539

Gideon Greenspan committed
540
			if (!QA_FINAL_EXTERNAL_USERS)
Gideon Greenspan committed
541
				array_push($showoptions, 'confirm_user_emails', 'confirm_user_required', 'moderate_users', 'approve_user_required', 'register_notify_admin', 'suspend_register_users', '');
Scott Vivian committed
542

Scott Vivian committed
543
			$captchamodules = qa_list_modules('captcha');
Scott Vivian committed
544

Gideon Greenspan committed
545 546 547
			if (count($captchamodules)) {
				if (!QA_FINAL_EXTERNAL_USERS)
					array_push($showoptions, 'captcha_on_register', 'captcha_on_reset_password');
Scott Vivian committed
548

Gideon Greenspan committed
549
				if ($maxpermitpost > QA_PERMIT_USERS)
Scott Vivian committed
550
					$showoptions[] = 'captcha_on_anon_post';
Scott Vivian committed
551

Gideon Greenspan committed
552
				if ($maxpermitpost > QA_PERMIT_APPROVED)
Scott Vivian committed
553
					$showoptions[] = 'captcha_on_unapproved';
Scott Vivian committed
554

Gideon Greenspan committed
555
				if ($maxpermitpost > QA_PERMIT_CONFIRMED)
Scott Vivian committed
556
					$showoptions[] = 'captcha_on_unconfirmed';
Scott Vivian committed
557

Gideon Greenspan committed
558
				if ($getoptions['feedback_enabled'])
Scott Vivian committed
559
					$showoptions[] = 'captcha_on_feedback';
Scott Vivian committed
560

Scott Vivian committed
561
				$showoptions[] = 'captcha_module';
Gideon Greenspan committed
562
			}
Scott Vivian committed
563

Scott Vivian committed
564
			$showoptions[] = '';
Scott Vivian committed
565

Gideon Greenspan committed
566
			if ($maxpermitpost > QA_PERMIT_USERS)
Scott Vivian committed
567
				$showoptions[] = 'moderate_anon_post';
Scott Vivian committed
568

Gideon Greenspan committed
569
			if ($maxpermitpost > QA_PERMIT_APPROVED)
Scott Vivian committed
570
				$showoptions[] = 'moderate_unapproved';
Scott Vivian committed
571

Gideon Greenspan committed
572
			if ($maxpermitpost > QA_PERMIT_CONFIRMED)
Scott Vivian committed
573
				$showoptions[] = 'moderate_unconfirmed';
Scott Vivian committed
574

Gideon Greenspan committed
575
			if ($maxpermitpost > QA_PERMIT_EXPERTS)
Gideon Greenspan committed
576
				array_push($showoptions, 'moderate_by_points', 'moderate_points_limit', 'moderate_edited_again', 'moderate_notify_admin', 'moderate_update_time', '');
Scott Vivian committed
577

Gideon Greenspan committed
578
			array_push($showoptions, 'flagging_of_posts', 'flagging_notify_first', 'flagging_notify_every', 'flagging_hide_after', '');
Scott Vivian committed
579

Gideon Greenspan committed
580 581 582 583
			array_push($showoptions, 'block_ips_write', '');

			if (!QA_FINAL_EXTERNAL_USERS)
				array_push($showoptions, 'max_rate_ip_registers', 'max_rate_ip_logins', '');
Scott Vivian committed
584

Gideon Greenspan committed
585 586
			array_push($showoptions, 'max_rate_ip_qs', 'max_rate_user_qs', 'max_rate_ip_as', 'max_rate_user_as');

Gideon Greenspan committed
587
			if (qa_opt('comment_on_qs') || qa_opt('comment_on_as'))
Gideon Greenspan committed
588
				array_push($showoptions, 'max_rate_ip_cs', 'max_rate_user_cs');
Scott Vivian committed
589

Scott Vivian committed
590
			$showoptions[] = '';
Scott Vivian committed
591

Gideon Greenspan committed
592 593 594 595
			if (qa_opt('voting_on_qs') || qa_opt('voting_on_as'))
				array_push($showoptions, 'max_rate_ip_votes', 'max_rate_user_votes');

			array_push($showoptions, 'max_rate_ip_flags', 'max_rate_user_flags', 'max_rate_ip_uploads', 'max_rate_user_uploads');
Scott Vivian committed
596

Gideon Greenspan committed
597
			if (qa_opt('allow_private_messages') || qa_opt('allow_user_walls'))
Gideon Greenspan committed
598
				array_push($showoptions, 'max_rate_ip_messages', 'max_rate_user_messages');
Scott Vivian committed
599

Scott Vivian committed
600
			$formstyle = 'wide';
Gideon Greenspan committed
601

Scott Vivian committed
602
			$checkboxtodisplay = array(
Gideon Greenspan committed
603
				'confirm_user_required' => 'option_confirm_user_emails',
Gideon Greenspan committed
604 605 606 607 608 609
				'approve_user_required' => 'option_moderate_users',
				'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)',
Gideon Greenspan committed
610 611 612
				'moderate_points_limit' => 'option_moderate_by_points',
				'moderate_points_label_off' => '!option_moderate_by_points',
				'moderate_points_label_on' => 'option_moderate_by_points',
Gideon Greenspan committed
613
				'moderate_edited_again' => 'option_moderate_anon_post || (option_confirm_user_emails && option_moderate_unconfirmed) || (option_moderate_users && option_moderate_unapproved) || option_moderate_by_points',
Gideon Greenspan committed
614 615 616 617 618 619
				'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 Vivian committed
620

Scott Vivian committed
621 622
			$checkboxtodisplay['moderate_notify_admin'] = $checkboxtodisplay['moderate_edited_again'];
			$checkboxtodisplay['moderate_update_time'] = $checkboxtodisplay['moderate_edited_again'];
Gideon Greenspan committed
623
			break;
Scott Vivian committed
624

Gideon Greenspan committed
625 626
		case 'mailing':
			require_once QA_INCLUDE_DIR.'qa-app-mailing.php';
Scott Vivian committed
627

Scott Vivian committed
628
			$subtitle = 'admin/mailing_title';
Gideon Greenspan committed
629

Scott Vivian committed
630
			$showoptions = array('mailing_enabled', 'mailing_from_name', 'mailing_from_email', 'mailing_subject', 'mailing_body', 'mailing_per_minute');
Gideon Greenspan committed
631
			break;
Scott Vivian committed
632

Gideon Greenspan committed
633
		default:
Scott Vivian committed
634 635
			$pagemodules = qa_load_modules_with('page', 'match_request');
			$request = qa_request();
Scott Vivian committed
636

Gideon Greenspan committed
637 638 639 640 641 642 643
			foreach ($pagemodules as $pagemodule)
				if ($pagemodule->match_request($request))
					return $pagemodule->process_request($request);

			return include QA_INCLUDE_DIR.'qa-page-not-found.php';
			break;
	}
Scott Vivian committed
644

Gideon Greenspan committed
645 646

//	Filter out blanks to get list of valid options
Scott Vivian committed
647

Scott Vivian committed
648
	$getoptions = array();
Gideon Greenspan committed
649
	foreach ($showoptions as $optionname)
Scott Vivian committed
650 651
		if (strlen($optionname) && (strpos($optionname, '/') === false)) // empties represent spacers in forms
			$getoptions[] = $optionname;
Gideon Greenspan committed
652 653 654


//	Process user actions
Scott Vivian committed
655

Scott Vivian committed
656
	$errors = array();
Gideon Greenspan committed
657

Scott Vivian committed
658 659 660
	$recalchotness = false;
	$startmailing = false;
	$securityexpired = false;
Scott Vivian committed
661

Scott Vivian committed
662
	$formokhtml = null;
Scott Vivian committed
663

664
	// If the post_max_size is exceeded then the $_POST array is empty so no field processing can be done
665
	if (qa_post_limit_exceeded())
666 667 668 669 670
		$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;
Scott Vivian committed
671

672 673 674
			else {
				qa_reset_options($getoptions);
				$formokhtml = qa_lang_html('admin/options_reset');
Gideon Greenspan committed
675
			}
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
		} 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);

					if (
							(@$optiontype[$optionname] == 'number') ||
							(@$optiontype[$optionname] == 'checkbox') ||
							((@$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 . 'qa-app-limits.php';
							$optionvalue = implode(' , ', qa_block_ips_explode($optionvalue));
							break;

						case 'block_bad_words':
							require_once QA_INCLUDE_DIR . 'qa-util-string.php';
							$optionvalue = implode(' , ', qa_block_words_explode($optionvalue));
							break;
					}
Scott Vivian committed
722

723 724
					qa_set_option($optionname, $optionvalue);
				}
Scott Vivian committed
725

726
				$formokhtml = qa_lang_html('admin/options_saved');
Scott Vivian committed
727

728 729 730
				//	Uploading default avatar
				if (is_array(@$_FILES['avatar_default_file'])) {
					$avatarfileerror = $_FILES['avatar_default_file']['error'];
Scott Vivian committed
731

732 733 734 735 736
					// 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 . 'qa-util-image.php';
Scott Vivian committed
737

738
						$oldblobid = qa_opt('avatar_default_blobid');
Scott Vivian committed
739

740
						$toobig = qa_image_file_too_big($_FILES['avatar_default_file']['tmp_name'], qa_opt('avatar_store_size'));
Scott Vivian committed
741

742 743
						if ($toobig)
							$errors['avatar_default_show'] = qa_lang_sub('main/image_too_big_x_pc', (int) ($toobig * 100));
Scott Vivian committed
744

745 746
						else {
							$imagedata = qa_image_constrain_data(file_get_contents($_FILES['avatar_default_file']['tmp_name']), $width, $height, qa_opt('avatar_store_size'));
Scott Vivian committed
747

748 749
							if (isset($imagedata)) {
								require_once QA_INCLUDE_DIR . 'qa-app-blobs.php';
Scott Vivian committed
750

751
								$newblobid = qa_create_blob($imagedata, 'jpeg');
Scott Vivian committed
752

753 754 755 756 757 758
								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 Vivian committed
759

760 761 762 763 764
								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 Vivian committed
765
					}
Gideon Greenspan committed
766
				}
Gideon Greenspan committed
767 768 769 770 771
			}
		}


//	Mailings management
Scott Vivian committed
772

Scott Vivian committed
773
	if ($adminsection == 'mailing') {
Gideon Greenspan committed
774 775
		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')))
Scott Vivian committed
776
				$securityexpired = true;
Scott Vivian committed
777

Gideon Greenspan committed
778 779
			else {
				if (qa_clicked('domailingtest')) {
Scott Vivian committed
780
					$email = qa_get_logged_in_email();
Scott Vivian committed
781

Gideon Greenspan committed
782
					if (qa_mailing_send_one(qa_get_logged_in_userid(), qa_get_logged_in_handle(), $email, qa_get_logged_in_user_field('emailcode')))
Scott Vivian committed
783
						$formokhtml = qa_lang_html_sub('admin/test_sent_to_x', qa_html($email));
Gideon Greenspan committed
784
					else
Scott Vivian committed
785
						$formokhtml = qa_lang_html('main/general_error');
Gideon Greenspan committed
786
				}
Scott Vivian committed
787

Gideon Greenspan committed
788 789
				if (qa_clicked('domailingstart')) {
					qa_mailing_start();
Scott Vivian committed
790
					$startmailing = true;
Gideon Greenspan committed
791
				}
Scott Vivian committed
792

Gideon Greenspan committed
793
				if (qa_clicked('domailingresume'))
Scott Vivian committed
794
					$startmailing = true;
Scott Vivian committed
795

Gideon Greenspan committed
796 797 798
				if (qa_clicked('domailingcancel'))
					qa_mailing_stop();
			}
Gideon Greenspan committed
799
		}
Scott Vivian committed
800

Scott Vivian committed
801
		$mailingprogress = qa_mailing_progress_message();
Scott Vivian committed
802

Gideon Greenspan committed
803
		if (isset($mailingprogress)) {
Scott Vivian committed
804
			$formokhtml = qa_html($mailingprogress);
Gideon Greenspan committed
805

Scott Vivian committed
806
			$checkboxtodisplay = array(
Gideon Greenspan committed
807 808
				'mailing_enabled' => '0',
			);
Scott Vivian committed
809

Scott Vivian committed
810 811 812
		}
		else {
			$checkboxtodisplay = array(
Gideon Greenspan committed
813 814 815 816 817 818 819 820 821 822 823
				'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 Vivian committed
824 825

//	Get the actual options
Gideon Greenspan committed
826

Scott Vivian committed
827
	$options = qa_get_options($getoptions);
Gideon Greenspan committed
828

Scott Vivian committed
829

Gideon Greenspan committed
830 831
//	Prepare content for theme

Scott Vivian committed
832
	$qa_content = qa_content_prepare();
Gideon Greenspan committed
833

Scott Vivian committed
834 835
	$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();
Gideon Greenspan committed
836

Scott Vivian committed
837
	$qa_content['script_rel'][] = 'qa-content/qa-admin.js?'.QA_VERSION;
Scott Vivian committed
838

Scott Vivian committed
839
	$qa_content['form'] = array(
Gideon Greenspan committed
840
		'ok' => $formokhtml,
Scott Vivian committed
841

Gideon Greenspan committed
842
		'tags' => 'method="post" action="'.qa_self_html().'" name="admin_form" onsubmit="document.forms.admin_form.has_js.value=1; return true;"',
Scott Vivian committed
843

Gideon Greenspan committed
844
		'style' => $formstyle,
Scott Vivian committed
845

Gideon Greenspan committed
846
		'fields' => array(),
Scott Vivian committed
847

Gideon Greenspan committed
848 849
		'buttons' => array(
			'save' => array(
Gideon Greenspan committed
850
				'tags' => 'id="dosaveoptions"',
Gideon Greenspan committed
851 852
				'label' => qa_lang_html('admin/save_options_button'),
			),
Scott Vivian committed
853

Gideon Greenspan committed
854
			'reset' => array(
Gideon Greenspan committed
855
				'tags' => 'name="doresetoptions"',
Gideon Greenspan committed
856 857 858
				'label' => qa_lang_html('admin/reset_options_button'),
			),
		),
Scott Vivian committed
859

Gideon Greenspan committed
860 861 862
		'hidden' => array(
			'dosaveoptions' => '1', // for IE
			'has_js' => '0',
Gideon Greenspan committed
863
			'code' => qa_get_form_security_code('admin/'.$adminsection),
Gideon Greenspan committed
864 865 866 867
		),
	);

	if ($recalchotness) {
Scott Vivian committed
868 869
		$qa_content['form']['ok'] = '<span id="recalc_ok"></span>';
		$qa_content['form']['hidden']['code_recalc'] = qa_get_form_security_code('admin/recalc');
Scott Vivian committed
870

Scott Vivian committed
871
		$qa_content['script_var']['qa_warning_recalc'] = qa_lang('admin/stop_recalc_warning');
Scott Vivian committed
872

Scott Vivian committed
873
		$qa_content['script_onloads'][] = array(
Gideon Greenspan committed
874
			"qa_recalc_click('dorecountposts', document.getElementById('dosaveoptions'), null, 'recalc_ok');"
Gideon Greenspan committed
875 876
		);

Scott Vivian committed
877 878
	}
	elseif ($startmailing) {
Scott Vivian committed
879

Gideon Greenspan committed
880
		if (qa_post_text('has_js')) {
Scott Vivian committed
881
			$qa_content['form']['ok'] = '<span id="mailing_ok">'.qa_html($mailingprogress).'</span>';
Scott Vivian committed
882

Scott Vivian committed
883
			$qa_content['script_onloads'][] = array(
Gideon Greenspan committed
884 885
				"qa_mailing_start('mailing_ok', 'domailingpause');"
			);
Scott Vivian committed
886

Scott Vivian committed
887 888
		}
		else { // rudimentary non-Javascript version of mass mailing loop
Gideon Greenspan committed
889
			echo '<tt>';
Scott Vivian committed
890

Gideon Greenspan committed
891 892 893
			while (true) {
				qa_mailing_perform_step();

Scott Vivian committed
894
				$message = qa_mailing_progress_message();
Scott Vivian committed
895

Gideon Greenspan committed
896 897
				if (!isset($message))
					break;
Scott Vivian committed
898

Gideon Greenspan committed
899
				echo qa_html($message).str_repeat('    ', 1024)."<br>\n";
Scott Vivian committed
900

Gideon Greenspan committed
901 902 903
				flush();
				sleep(1);
			}
Scott Vivian committed
904

Gideon Greenspan committed
905
			echo qa_lang_html('admin/mailing_complete').'</tt><p><a href="'.qa_path_html('admin/mailing').'">'.qa_lang_html('admin/admin_title').' - '.qa_lang_html('admin/mailing_title').'</a>';
Scott Vivian committed
906

Gideon Greenspan committed
907 908 909
			qa_exit();
		}
	}
Scott Vivian committed
910

Gideon Greenspan committed
911 912 913

	function qa_optionfield_make_select(&$optionfield, $options, $value, $default)
	{
Scott Vivian committed
914 915 916
		$optionfield['type'] = 'select';
		$optionfield['options'] = $options;
		$optionfield['value'] = isset($options[qa_html($value)]) ? $options[qa_html($value)] : @$options[$default];
Gideon Greenspan committed
917
	}
Scott Vivian committed
918

Scott Vivian committed
919
	$indented = false;
Scott Vivian committed
920

Gideon Greenspan committed
921 922
	foreach ($showoptions as $optionname)
		if (empty($optionname)) {
Scott Vivian committed
923
			$indented = false;
Scott Vivian committed
924

Scott Vivian committed
925
			$qa_content['form']['fields'][] = array(
Gideon Greenspan committed
926 927
				'type' => 'blank'
			);
Scott Vivian committed
928

Scott Vivian committed
929 930 931
		}
		elseif (strpos($optionname, '/') !== false) {
			$qa_content['form']['fields'][] = array(
Gideon Greenspan committed
932 933 934 935
				'type' => 'static',
				'label' => qa_lang_html($optionname),
			);

Scott Vivian committed
936
			$indented = true;
Scott Vivian committed
937

Scott Vivian committed
938 939 940 941 942
		}
		else {
			$type = @$optiontype[$optionname];
			if ($type == 'number-blank')
				$type = 'number';
Scott Vivian committed
943

Scott Vivian committed
944
			$value = $options[$optionname];
Scott Vivian committed
945

Scott Vivian committed
946
			$optionfield = array(
Gideon Greenspan committed
947 948
				'id' => $optionname,
				'label' => ($indented ? '&ndash; ' : '').qa_lang_html('options/'.$optionname),
Gideon Greenspan committed
949
				'tags' => 'name="option_'.$optionname.'" id="option_'.$optionname.'"',
Gideon Greenspan committed
950 951 952 953
				'value' => qa_html($value),
				'type' => $type,
				'error' => qa_html(@$errors[$optionname]),
			);
Scott Vivian committed
954

Gideon Greenspan committed
955
			if (isset($optionmaximum[$optionname]))
Scott Vivian committed
956
				$optionfield['note'] = qa_lang_html_sub('admin/maximum_x', $optionmaximum[$optionname]);
Scott Vivian committed
957

Scott Vivian committed
958 959
			$feedrequest = null;
			$feedisexample = false;
Scott Vivian committed
960

Gideon Greenspan committed
961 962 963
			switch ($optionname) { // special treatment for certain options
				case 'site_language':
					require_once QA_INCLUDE_DIR.'qa-util-string.php';
Scott Vivian committed
964

Gideon Greenspan committed
965
					qa_optionfield_make_select($optionfield, qa_admin_language_options(), $value, '');
Scott Vivian committed
966

Scott Vivian committed
967
					$optionfield['suffix'] = strtr(qa_lang_html('admin/check_language_suffix'), array(
Gideon Greenspan committed
968 969
						'^1' => '<a href="'.qa_html(qa_path_to_root().'qa-include/qa-check-lang.php').'">',
						'^2' => '</a>',
Gideon Greenspan committed
970
					));
Scott Vivian committed
971

Gideon Greenspan committed
972
					if (!qa_has_multibyte())
Scott Vivian committed
973
						$optionfield['error'] = qa_lang_html('admin/no_multibyte');
Gideon Greenspan committed
974
					break;
Scott Vivian committed
975

Gideon Greenspan committed
976
				case 'neat_urls':
Scott Vivian committed
977
					$neatoptions = array();
Gideon Greenspan committed
978

Scott Vivian committed
979
					$rawoptions = array(
Gideon Greenspan committed
980 981 982 983 984 985
						QA_URL_FORMAT_NEAT,
						QA_URL_FORMAT_INDEX,
						QA_URL_FORMAT_PARAM,
						QA_URL_FORMAT_PARAMS,
						QA_URL_FORMAT_SAFEST,
					);
Scott Vivian committed
986

Scott Vivian committed
987 988
					foreach ($rawoptions as $rawoption) {
						$neatoptions[$rawoption] =
Gideon Greenspan committed
989 990
							'<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" frameborder="0"></iframe>&nbsp;'.
							'<small>'.
Gideon Greenspan committed
991
							qa_html(urldecode(qa_path('123/why-do-birds-sing', null, '/', $rawoption))).
Scott Vivian committed
992
							(($rawoption == QA_URL_FORMAT_NEAT) ? strtr(qa_lang_html('admin/neat_urls_note'), array(
Gideon Greenspan committed
993 994
								'^1' => '<a href="http://www.question2answer.org/htaccess.php" target="_blank">',
								'^2' => '</a>',
Gideon Greenspan committed
995
							)) : '').
Gideon Greenspan committed
996
							'</small>';
Scott Vivian committed
997
					}
Scott Vivian committed
998

Gideon Greenspan committed
999
					qa_optionfield_make_select($optionfield, $neatoptions, $value, QA_URL_FORMAT_SAFEST);
Scott Vivian committed
1000

Scott Vivian committed
1001 1002
					$optionfield['type'] = 'select-radio';
					$optionfield['note'] = qa_lang_html_sub('admin/url_format_note', '<span style=" '.qa_admin_url_test_html().'/span>');
Gideon Greenspan committed
1003
					break;
Scott Vivian committed
1004

Gideon Greenspan committed
1005 1006
				case 'site_theme':
				case 'site_theme_mobile':
Scott Vivian committed
1007
					$themeoptions = qa_admin_theme_options();
Gideon Greenspan committed
1008
					if (!isset($themeoptions[$value]))
Scott Vivian committed
1009
						$value = 'Classic'; // check here because we also need $value for qa_addon_metadata()
Scott Vivian committed
1010

Gideon Greenspan committed
1011
					qa_optionfield_make_select($optionfield, $themeoptions, $value, 'Classic');
Scott Vivian committed
1012

1013 1014 1015
					// limit theme parsing to first 8kB
					$contents = file_get_contents(QA_THEME_DIR.$value.'/qa-styles.css', false, NULL, -1, 8192);
					$metadata = qa_addon_metadata($contents, 'Theme');
Scott Vivian committed
1016

Gideon Greenspan committed
1017
					if (strlen(@$metadata['version']))
Scott Vivian committed
1018
						$namehtml = 'v'.qa_html($metadata['version']);
Gideon Greenspan committed
1019
					else
Scott Vivian committed
1020
						$namehtml = '';
Scott Vivian committed
1021

Gideon Greenspan committed
1022 1023
					if (strlen(@$metadata['uri'])) {
						if (!strlen($namehtml))
Scott Vivian committed
1024
							$namehtml = qa_html($value);
Scott Vivian committed
1025

Scott Vivian committed
1026
						$namehtml = '<a href="'.qa_html($metadata['uri']).'">'.$namehtml.'</a>';
Gideon Greenspan committed
1027
					}
Scott Vivian committed
1028

Scott Vivian committed
1029
					$authorhtml = '';
Gideon Greenspan committed
1030
					if (strlen(@$metadata['author'])) {
Scott Vivian committed
1031
						$authorhtml = qa_html($metadata['author']);
Scott Vivian committed
1032

Gideon Greenspan committed
1033
						if (strlen(@$metadata['author_uri']))
Scott Vivian committed
1034
							$authorhtml = '<a href="'.qa_html($metadata['author_uri']).'">'.$authorhtml.'</a>';
Scott Vivian committed
1035

Scott Vivian committed
1036
						$authorhtml = qa_lang_html_sub('main/by_x', $authorhtml);
Scott Vivian committed
1037

Scott Vivian committed
1038
					}
Scott Vivian committed
1039

Scott Vivian committed
1040
					$updatehtml = '';
Gideon Greenspan committed
1041
					if (strlen(@$metadata['version']) && strlen(@$metadata['update'])) {
Scott Vivian committed
1042
						$elementid = 'version_check_'.$optionname;
Scott Vivian committed
1043

Scott Vivian committed
1044
						$updatehtml = '(<span id="'.$elementid.'">...</span>)';
Scott Vivian committed
1045

Scott Vivian committed
1046
						$qa_content['script_onloads'][] = array(
1047
							"qa_version_check(".qa_js($metadata['update']).", 'Theme', ".qa_js($metadata['version'], true).", ".qa_js($elementid).");"
Gideon Greenspan committed
1048 1049
						);

Scott Vivian committed
1050
					}
Scott Vivian committed
1051

Scott Vivian committed
1052
					$optionfield['suffix'] = $namehtml.' '.$authorhtml.' '.$updatehtml;
Gideon Greenspan committed
1053
					break;
Scott Vivian committed
1054

Scott committed
1055 1056 1057 1058 1059
				case 'site_text_direction':
					$directions = array('ltr'=>'LTR', 'rtl'=>'RTL');
					qa_optionfield_make_select($optionfield, $directions, $value, 'ltr');
					break;

Gideon Greenspan committed
1060 1061 1062 1063 1064 1065 1066 1067
				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 Vivian committed
1068
					$optionfield['error'] = '';
Scott Vivian committed
1069

Gideon Greenspan committed
1070
					if (qa_opt('cache_tagcount') && !qa_using_tags())
Scott Vivian committed
1071
						$optionfield['error'] .= qa_lang_html('admin/tags_not_shown').' ';
Scott Vivian committed
1072

Gideon Greenspan committed
1073 1074 1075
					if (!qa_using_categories())
						foreach ($categories as $category)
							if ($category['qcount']) {
Scott Vivian committed
1076
								$optionfield['error'] .= qa_lang_html('admin/categories_not_shown');
Gideon Greenspan committed
1077 1078 1079
								break;
							}
					break;
Scott Vivian committed
1080

Gideon Greenspan committed
1081 1082 1083 1084 1085 1086 1087
				case 'smtp_secure':
					qa_optionfield_make_select($optionfield, array(
						'' => qa_lang_html('options/smtp_secure_none'),
						'ssl' => 'SSL',
						'tls' => 'TLS',
					), $value, '');
					break;
Scott Vivian committed
1088

Gideon Greenspan committed
1089 1090 1091 1092 1093 1094 1095
				case 'custom_sidebar':
				case 'custom_sidepanel':
				case 'custom_header':
				case 'custom_footer':
				case 'custom_in_head':
				case 'home_description':
					unset($optionfield['label']);
Scott Vivian committed
1096
					$optionfield['rows'] = 6;
Gideon Greenspan committed
1097
					break;
Scott Vivian committed
1098

Gideon Greenspan committed
1099
				case 'custom_home_content':
Scott Vivian committed
1100
					$optionfield['rows'] = 16;
Gideon Greenspan committed
1101
					break;
Scott Vivian committed
1102

Gideon Greenspan committed
1103
				case 'show_custom_register':
1104
				case 'show_register_terms':
Gideon Greenspan committed
1105 1106 1107
				case 'show_custom_welcome':
				case 'show_notice_welcome':
				case 'show_notice_visitor':
Scott Vivian committed
1108
					$optionfield['style'] = 'tall';
Gideon Greenspan committed
1109
					break;
Scott Vivian committed
1110

Gideon Greenspan committed
1111
				case 'custom_register':
1112
				case 'register_terms':
Gideon Greenspan committed
1113 1114 1115 1116
				case 'custom_welcome':
				case 'notice_welcome':
				case 'notice_visitor':
					unset($optionfield['label']);
Scott Vivian committed
1117 1118
					$optionfield['style'] = 'tall';
					$optionfield['rows'] = 3;
Gideon Greenspan committed
1119
					break;
Scott Vivian committed
1120

Gideon Greenspan committed
1121
				case 'avatar_allow_gravatar':
Scott Vivian committed
1122
					$optionfield['label'] = strtr($optionfield['label'], array(
Gideon Greenspan committed
1123 1124
						'^1' => '<a href="http://www.gravatar.com/" target="_blank">',
						'^2' => '</a>',
Gideon Greenspan committed
1125
					));
Scott Vivian committed
1126

Gideon Greenspan committed
1127
					if (!qa_has_gd_image()) {
Scott Vivian committed
1128 1129
						$optionfield['style'] = 'tall';
						$optionfield['error'] = qa_lang_html('admin/no_image_gd');
Gideon Greenspan committed
1130 1131
					}
					break;
Scott Vivian committed
1132

Gideon Greenspan committed
1133 1134 1135 1136 1137 1138 1139
				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':
Gideon Greenspan committed
1140
				case 'avatar_message_list_size':
Scott Vivian committed
1141
					$optionfield['note'] = qa_lang_html('admin/pixels');
Gideon Greenspan committed
1142 1143 1144
					break;

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

Gideon Greenspan committed
1151 1152
				case 'logo_width':
				case 'logo_height':
Scott Vivian committed
1153
					$optionfield['suffix'] = qa_lang_html('admin/pixels');
Gideon Greenspan committed
1154
					break;
Scott Vivian committed
1155

Gideon Greenspan committed
1156 1157 1158
				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;
Scott Vivian committed
1159

Gideon Greenspan committed
1160 1161 1162 1163
				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;
Scott Vivian committed
1164

Gideon Greenspan committed
1165 1166 1167 1168 1169
				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':
Scott Vivian committed
1170
					$optionfield['note'] = qa_lang_html('admin/characters');
Gideon Greenspan committed
1171
					break;
Scott Vivian committed
1172

Gideon Greenspan committed
1173 1174
				case 'min_num_q_tags':
				case 'max_num_q_tags':
Scott Vivian committed
1175
					$optionfield['note'] = qa_lang_html_sub('main/x_tags', ''); // this to avoid language checking error: a_lang('main/1_tag')
Gideon Greenspan committed
1176
					break;
Scott Vivian committed
1177

Gideon Greenspan committed
1178
				case 'show_full_date_days':
Scott Vivian committed
1179
					$optionfield['note'] = qa_lang_html_sub('main/x_days', '');
Gideon Greenspan committed
1180
					break;
Scott Vivian committed
1181

Gideon Greenspan committed
1182 1183 1184 1185 1186 1187
				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;
Scott Vivian committed
1188

Gideon Greenspan committed
1189
				case 'page_size_q_as':
Scott Vivian committed
1190
					$optionfield['note'] = qa_lang_html_sub('main/x_answers', '');
Gideon Greenspan committed
1191
					break;
Scott Vivian committed
1192

Gideon Greenspan committed
1193 1194 1195 1196 1197 1198 1199
				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;
Scott Vivian committed
1200

Gideon Greenspan committed
1201 1202
				case 'show_fewer_cs_from':
				case 'show_fewer_cs_count':
Scott Vivian committed
1203
					$optionfield['note'] = qa_lang_html_sub('main/x_comments', '');
Gideon Greenspan committed
1204
					break;
Scott Vivian committed
1205

Gideon Greenspan committed
1206 1207 1208 1209 1210
				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;
Scott Vivian committed
1211

Gideon Greenspan committed
1212
				case 'block_bad_words':
Scott Vivian committed
1213 1214 1215
					$optionfield['style'] = 'tall';
					$optionfield['rows'] = 4;
					$optionfield['note'] = qa_lang_html('admin/block_words_note');
Gideon Greenspan committed
1216
					break;
Scott Vivian committed
1217

Gideon Greenspan committed
1218 1219 1220
				case 'editor_for_qs':
				case 'editor_for_as':
				case 'editor_for_cs':
Scott Vivian committed
1221
					$editors = qa_list_modules('editor');
Scott Vivian committed
1222

Scott Vivian committed
1223 1224
					$selectoptions = array();
					$optionslinks = false;
Gideon Greenspan committed
1225 1226

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

Scott Vivian committed
1229 1230
						if ($editor == $value) {
							$module = qa_load_module('editor', $editor);
Scott Vivian committed
1231

Gideon Greenspan committed
1232
							if (method_exists($module, 'admin_form'))
Scott Vivian committed
1233
								$optionfield['note'] = '<a href="'.qa_admin_module_options_path('editor', $editor).'">'.qa_lang_html('admin/options').'</a>';
Gideon Greenspan committed
1234 1235
						}
					}
Scott Vivian committed
1236

Gideon Greenspan committed
1237 1238
					qa_optionfield_make_select($optionfield, $selectoptions, $value, '');
					break;
Scott Vivian committed
1239

Gideon Greenspan committed
1240 1241 1242 1243
				case 'show_custom_ask':
				case 'extra_field_active':
				case 'show_custom_answer':
				case 'show_custom_comment':
Scott Vivian committed
1244
					$optionfield['style'] = 'tall';
Gideon Greenspan committed
1245
					break;
Scott Vivian committed
1246

Gideon Greenspan committed
1247 1248 1249
				case 'custom_ask':
				case 'custom_answer':
				case 'custom_comment':
Scott Vivian committed
1250
					$optionfield['style'] = 'tall';
Gideon Greenspan committed
1251
					unset($optionfield['label']);
Scott Vivian committed
1252
					$optionfield['rows'] = 3;
Gideon Greenspan committed
1253
					break;
Scott Vivian committed
1254

Gideon Greenspan committed
1255
				case 'extra_field_display':
Scott Vivian committed
1256 1257
					$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>';
Gideon Greenspan committed
1258
					break;
Scott Vivian committed
1259

Gideon Greenspan committed
1260 1261
				case 'extra_field_prompt':
				case 'extra_field_label':
Scott Vivian committed
1262
					$optionfield['style'] = 'tall';
Gideon Greenspan committed
1263 1264
					unset($optionfield['label']);
					break;
Scott Vivian committed
1265

Gideon Greenspan committed
1266 1267
				case 'search_module':
					foreach ($searchmodules as $modulename => $module) {
Scott Vivian committed
1268
						$selectoptions[qa_html($modulename)] = strlen($modulename) ? qa_html($modulename) : qa_lang_html('options/option_default');
Gideon Greenspan committed
1269

Scott Vivian committed
1270 1271
						if (($modulename == $value) && method_exists($module, 'admin_form'))
							$optionfield['note'] = '<a href="'.qa_admin_module_options_path('search', $modulename).'">'.qa_lang_html('admin/options').'</a>';
Gideon Greenspan committed
1272
					}
Scott Vivian committed
1273

Gideon Greenspan committed
1274 1275
					qa_optionfield_make_select($optionfield, $selectoptions, $value, '');
					break;
Scott Vivian committed
1276 1277

				case 'hot_weight_q_age':
Gideon Greenspan committed
1278 1279 1280 1281
				case 'hot_weight_a_age':
				case 'hot_weight_answers':
				case 'hot_weight_votes':
				case 'hot_weight_views':
Scott Vivian committed
1282
					$optionfield['note'] = '/ 100';
Gideon Greenspan committed
1283
					break;
Scott Vivian committed
1284

Gideon Greenspan committed
1285
				case 'moderate_by_points':
Scott Vivian committed
1286
					$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>';
Gideon Greenspan committed
1287
					break;
Scott Vivian committed
1288

Gideon Greenspan committed
1289 1290
				case 'moderate_points_limit';
					unset($optionfield['label']);
Scott Vivian committed
1291
					$optionfield['note'] = qa_lang_html('admin/points');
Gideon Greenspan committed
1292
					break;
Scott Vivian committed
1293

Gideon Greenspan committed
1294 1295 1296
				case 'flagging_hide_after':
				case 'flagging_notify_every':
				case 'flagging_notify_first':
Scott Vivian committed
1297
					$optionfield['note'] = qa_lang_html_sub('main/x_flags', '');
Gideon Greenspan committed
1298
					break;
Scott Vivian committed
1299

Gideon Greenspan committed
1300
				case 'block_ips_write':
Scott Vivian committed
1301 1302 1303
					$optionfield['style'] = 'tall';
					$optionfield['rows'] = 4;
					$optionfield['note'] = qa_lang_html('admin/block_ips_note');
Gideon Greenspan committed
1304
					break;
Scott Vivian committed
1305

Gideon Greenspan committed
1306
				case 'allow_view_q_bots':
Scott Vivian committed
1307
					$optionfield['note'] = $optionfield['label'];
Gideon Greenspan committed
1308 1309
					unset($optionfield['label']);
					break;
Scott Vivian committed
1310

Gideon Greenspan committed
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
				case 'permit_view_q_page':
				case 'permit_post_q':
				case 'permit_post_a':
				case 'permit_post_c':
				case 'permit_vote_q':
				case 'permit_vote_a':
				case 'permit_vote_down':
				case 'permit_edit_q':
				case 'permit_retag_cat':
				case 'permit_edit_a':
				case 'permit_edit_c':
Gideon Greenspan committed
1322
				case 'permit_edit_silent':
Gideon Greenspan committed
1323 1324 1325 1326 1327 1328 1329
				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':
Gideon Greenspan committed
1330 1331
				case 'permit_view_voters_flaggers':
				case 'permit_post_wall':
Scott Vivian committed
1332
					$dopoints = true;
Scott Vivian committed
1333

Scott Vivian committed
1334 1335
					if ($optionname == 'permit_retag_cat')
						$optionfield['label'] = qa_lang_html(qa_using_categories() ? 'profile/permit_recat' : 'profile/permit_retag').':';
Gideon Greenspan committed
1336
					else
Scott Vivian committed
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
						$optionfield['label'] = qa_lang_html('profile/'.$optionname).':';

					if ( ($optionname == 'permit_view_q_page') || ($optionname == 'permit_post_q') || ($optionname == 'permit_post_a') || ($optionname == 'permit_post_c') || ($optionname == 'permit_anon_view_ips') )
						$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;
Gideon Greenspan committed
1347
					else
Scott Vivian committed
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
						$widest = QA_PERMIT_USERS;

					if ($optionname == 'permit_view_q_page') {
						$narrowest = QA_PERMIT_APPROVED;
						$dopoints = false;
					}
					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;
					elseif ( ($optionname == 'permit_vote_q') || ($optionname == 'permit_vote_a') || ($optionname == 'permit_post_wall') )
						$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;
Gideon Greenspan committed
1364
					else
Scott Vivian committed
1365
						$narrowest = QA_PERMIT_EXPERTS;
Scott Vivian committed
1366

Scott Vivian committed
1367
					$permitoptions = qa_admin_permit_options($widest, $narrowest, (!QA_FINAL_EXTERNAL_USERS) && qa_opt('confirm_user_emails'), $dopoints);
Scott Vivian committed
1368

Scott Vivian committed
1369
					if (count($permitoptions)>1) {
Gideon Greenspan committed
1370
						qa_optionfield_make_select($optionfield, $permitoptions, $value,
Scott Vivian committed
1371 1372
							($value == QA_PERMIT_CONFIRMED) ? QA_PERMIT_USERS : min(array_keys($permitoptions)));
					}
Gideon Greenspan committed
1373
					else {
Scott Vivian committed
1374 1375
						$optionfield['type'] = 'static';
						$optionfield['value'] = reset($permitoptions);
Gideon Greenspan committed
1376 1377
					}
					break;
Scott Vivian committed
1378

Gideon Greenspan committed
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
				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':
				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':
Gideon Greenspan committed
1396
				case 'permit_post_wall_points':
Gideon Greenspan committed
1397
					unset($optionfield['label']);
Scott Vivian committed
1398 1399 1400
					$optionfield['type'] = 'number';
					$optionfield['prefix'] = qa_lang_html('admin/users_must_have').'&nbsp;';
					$optionfield['note'] = qa_lang_html('admin/points');
Gideon Greenspan committed
1401
					break;
Scott Vivian committed
1402

Gideon Greenspan committed
1403
				case 'feed_for_qa':
Scott Vivian committed
1404
					$feedrequest = 'qa';
Gideon Greenspan committed
1405 1406 1407
					break;

				case 'feed_for_questions':
Scott Vivian committed
1408
					$feedrequest = 'questions';
Gideon Greenspan committed
1409 1410 1411
					break;

				case 'feed_for_hot':
Scott Vivian committed
1412
					$feedrequest = 'hot';
Gideon Greenspan committed
1413 1414 1415
					break;

				case 'feed_for_unanswered':
Scott Vivian committed
1416
					$feedrequest = 'unanswered';
Gideon Greenspan committed
1417 1418 1419
					break;

				case 'feed_for_activity':
Scott Vivian committed
1420
					$feedrequest = 'activity';
Gideon Greenspan committed
1421
					break;
Scott Vivian committed
1422

Gideon Greenspan committed
1423 1424
				case 'feed_per_category':
					if (count($categories)) {
Scott Vivian committed
1425 1426
						$category = reset($categories);
						$categoryslug = $category['tags'];
Gideon Greenspan committed
1427

Scott Vivian committed
1428 1429 1430
					}
					else
						$categoryslug = 'example-category';
Scott Vivian committed
1431

Gideon Greenspan committed
1432
					if (qa_opt('feed_for_qa'))
Scott Vivian committed
1433
						$feedrequest = 'qa';
Gideon Greenspan committed
1434
					elseif (qa_opt('feed_for_questions'))
Scott Vivian committed
1435
						$feedrequest = 'questions';
Gideon Greenspan committed
1436
					else
Scott Vivian committed
1437
						$feedrequest = 'activity';
Scott Vivian committed
1438

Scott Vivian committed
1439 1440
					$feedrequest .= '/'.$categoryslug;
					$feedisexample = true;
Gideon Greenspan committed
1441
					break;
Scott Vivian committed
1442

Gideon Greenspan committed
1443
				case 'feed_for_tag_qs':
Scott Vivian committed
1444
					$populartags = qa_db_select_with_pending(qa_db_popular_tags_selectspec(0, 1));
Scott Vivian committed
1445

Gideon Greenspan committed
1446 1447
					if (count($populartags)) {
						reset($populartags);
Scott Vivian committed
1448 1449 1450 1451
						$feedrequest = 'tag/'.key($populartags);
					}
					else
						$feedrequest = 'tag/singing';
Scott Vivian committed
1452

Scott Vivian committed
1453
					$feedisexample = true;
Gideon Greenspan committed
1454 1455 1456
					break;

				case 'feed_for_search':
Scott Vivian committed
1457 1458
					$feedrequest = 'search/why do birds sing';
					$feedisexample = true;
Gideon Greenspan committed
1459
					break;
Scott Vivian committed
1460

Gideon Greenspan committed
1461
				case 'moderate_users':
Scott Vivian committed
1462
					$optionfield['note'] = '<a href="'.qa_path_html('admin/users', null, null, null, 'profile_fields').'">'.qa_lang_html('admin/registration_fields').'</a>';
Gideon Greenspan committed
1463
					break;
Scott Vivian committed
1464

Gideon Greenspan committed
1465
				case 'captcha_module':
Scott Vivian committed
1466
					$captchaoptions = array();
Gideon Greenspan committed
1467 1468

					foreach ($captchamodules as $modulename) {
Scott Vivian committed
1469
						$captchaoptions[qa_html($modulename)] = qa_html($modulename);
Gideon Greenspan committed
1470

Scott Vivian committed
1471 1472
						if ($modulename == $value) {
							$module = qa_load_module('captcha', $modulename);
Scott Vivian committed
1473

Gideon Greenspan committed
1474
							if (method_exists($module, 'admin_form'))
Scott Vivian committed
1475
								$optionfield['note'] = '<a href="'.qa_admin_module_options_path('captcha', $modulename).'">'.qa_lang_html('admin/options').'</a>';
Gideon Greenspan committed
1476 1477
						}
					}
Scott Vivian committed
1478

Gideon Greenspan committed
1479 1480
					qa_optionfield_make_select($optionfield, $captchaoptions, $value, '');
					break;
Scott Vivian committed
1481

Gideon Greenspan committed
1482 1483 1484 1485 1486
				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');
Scott Vivian committed
1487 1488
					break;

Gideon Greenspan committed
1489 1490 1491 1492 1493 1494 1495 1496 1497
				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':
Scott Vivian committed
1498
					$optionfield['note'] = qa_lang_html('admin/per_ip_hour');
Gideon Greenspan committed
1499
					break;
Scott Vivian committed
1500

Gideon Greenspan committed
1501 1502 1503 1504 1505 1506 1507 1508
				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']);
Scott Vivian committed
1509
					$optionfield['note'] = qa_lang_html('admin/per_user_hour');
Gideon Greenspan committed
1510
					break;
Scott Vivian committed
1511

Gideon Greenspan committed
1512
				case 'mailing_per_minute':
Scott Vivian committed
1513
					$optionfield['suffix'] = qa_lang_html('admin/emails_per_minute');
Gideon Greenspan committed
1514
					break;
Gideon Greenspan committed
1515 1516 1517
			}

			if (isset($feedrequest) && $value)
Scott Vivian committed
1518
				$optionfield['note'] = '<a href="'.qa_path_html(qa_feed_request($feedrequest)).'">'.qa_lang_html($feedisexample ? 'admin/feed_link_example' : 'admin/feed_link').'</a>';
Gideon Greenspan committed
1519

Scott Vivian committed
1520
			$qa_content['form']['fields'][$optionname] = $optionfield;
Gideon Greenspan committed
1521
		}
Scott Vivian committed
1522

Gideon Greenspan committed
1523 1524 1525 1526 1527 1528

//	Extra items for specific pages

	switch ($adminsection) {
		case 'users':
			if (!QA_FINAL_EXTERNAL_USERS) {
Scott Vivian committed
1529
				$userfields = qa_db_single_select(qa_db_userfields_selectspec());
Scott Vivian committed
1530

Scott Vivian committed
1531
				$listhtml = '';
Scott Vivian committed
1532

Gideon Greenspan committed
1533
				foreach ($userfields as $userfield) {
Scott Vivian committed
1534
					$listhtml .= '<li><b>'.qa_html(qa_user_userfield_label($userfield)).'</b>';
Scott Vivian committed
1535

Scott Vivian committed
1536
					$listhtml .= strtr(qa_lang_html('admin/edit_field'), array(
Gideon Greenspan committed
1537 1538
						'^1' => '<a href="'.qa_path_html('admin/userfields', array('edit' => $userfield['fieldid'])).'">',
						'^2' => '</a>',
Gideon Greenspan committed
1539
					));
Scott Vivian committed
1540

Scott Vivian committed
1541
					$listhtml .= '</li>';
Gideon Greenspan committed
1542
				}
Scott Vivian committed
1543

Scott Vivian committed
1544
				$listhtml .= '<li><b><a href="'.qa_path_html('admin/userfields').'">'.qa_lang_html('admin/add_new_field').'</a></b></li>';
Scott Vivian committed
1545

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

Scott Vivian committed
1548
				$qa_content['form']['fields']['userfields'] = array(
Gideon Greenspan committed
1549
					'label' => qa_lang_html('admin/profile_fields'),
Gideon Greenspan committed
1550
					'id' => 'profile_fields',
Gideon Greenspan committed
1551 1552
					'style' => 'tall',
					'type' => 'custom',
Gideon Greenspan committed
1553
					'html' => strlen($listhtml) ? '<ul style="margin-bottom:0;">'.$listhtml.'</ul>' : null,
Gideon Greenspan committed
1554 1555
				);
			}
Scott Vivian committed
1556

Scott Vivian committed
1557
			$qa_content['form']['fields'][] = array('type' => 'blank');
Gideon Greenspan committed
1558

Scott Vivian committed
1559
			$pointstitle = qa_get_points_to_titles();
Gideon Greenspan committed
1560

Scott Vivian committed
1561
			$listhtml = '';
Scott Vivian committed
1562

Gideon Greenspan committed
1563
			foreach ($pointstitle as $points => $title) {
Scott Vivian committed
1564
				$listhtml .= '<li><b>'.$title.'</b> - '.(($points == 1) ? qa_lang_html_sub('main/1_point', '1', '1')
Gideon Greenspan committed
1565 1566
				: qa_lang_html_sub('main/x_points', qa_html(number_format($points))));

Scott Vivian committed
1567
				$listhtml .= strtr(qa_lang_html('admin/edit_title'), array(
Gideon Greenspan committed
1568 1569
					'^1' => '<a href="'.qa_path_html('admin/usertitles', array('edit' => $points)).'">',
					'^2' => '</a>',
Gideon Greenspan committed
1570 1571
				));

Scott Vivian committed
1572
				$listhtml .= '</li>';
Gideon Greenspan committed
1573 1574
			}

Scott Vivian committed
1575
			$listhtml .= '<li><b><a href="'.qa_path_html('admin/usertitles').'">'.qa_lang_html('admin/add_new_title').'</a></b></li>';
Gideon Greenspan committed
1576

Scott Vivian committed
1577
			$qa_content['form']['fields']['usertitles'] = array(
Gideon Greenspan committed
1578 1579 1580
				'label' => qa_lang_html('admin/user_titles'),
				'style' => 'tall',
				'type' => 'custom',
Gideon Greenspan committed
1581
				'html' => strlen($listhtml) ? '<ul style="margin-bottom:0;">'.$listhtml.'</ul>' : null,
Gideon Greenspan committed
1582 1583
			);
			break;
Scott Vivian committed
1584

Gideon Greenspan committed
1585
		case 'layout':
Scott Vivian committed
1586
			$listhtml = '';
Scott Vivian committed
1587

Scott Vivian committed
1588
			$widgetmodules = qa_load_modules_with('widget', 'allow_template');
Scott Vivian committed
1589

Gideon Greenspan committed
1590 1591
			foreach ($widgetmodules as $tryname => $trywidget)
				if (method_exists($trywidget, 'allow_region')) {
Scott Vivian committed
1592
					$listhtml .= '<li><b>'.qa_html($tryname).'</b>';
Scott Vivian committed
1593

Scott Vivian committed
1594
					$listhtml .= strtr(qa_lang_html('admin/add_widget_link'), array(
Gideon Greenspan committed
1595 1596
						'^1' => '<a href="'.qa_path_html('admin/layoutwidgets', array('title' => $tryname)).'">',
						'^2' => '</a>',
Gideon Greenspan committed
1597
					));
Scott Vivian committed
1598

Gideon Greenspan committed
1599
					if (method_exists($trywidget, 'admin_form'))
Scott Vivian committed
1600
						$listhtml .= strtr(qa_lang_html('admin/widget_global_options'), array(
Gideon Greenspan committed
1601 1602
							'^1' => '<a href="'.qa_admin_module_options_path('widget', $tryname).'">',
							'^2' => '</a>',
Gideon Greenspan committed
1603
						));
Scott Vivian committed
1604

Scott Vivian committed
1605
					$listhtml .= '</li>';
Gideon Greenspan committed
1606
				}
Scott Vivian committed
1607

Gideon Greenspan committed
1608
			if (strlen($listhtml))
Scott Vivian committed
1609
				$qa_content['form']['fields']['plugins'] = array(
Gideon Greenspan committed
1610 1611 1612
					'label' => qa_lang_html('admin/widgets_explanation'),
					'style' => 'tall',
					'type' => 'custom',
Gideon Greenspan committed
1613
					'html' => '<ul style="margin-bottom:0;">'.$listhtml.'</ul>',
Gideon Greenspan committed
1614
				);
Scott Vivian committed
1615

Scott Vivian committed
1616
			$widgets = qa_db_single_select(qa_db_widgets_selectspec());
Scott Vivian committed
1617

Scott Vivian committed
1618
			$listhtml = '';
Scott Vivian committed
1619

Scott Vivian committed
1620
			$placeoptions = qa_admin_place_options();
Scott Vivian committed
1621

Gideon Greenspan committed
1622
			foreach ($widgets as $widget) {
Scott Vivian committed
1623
				$listhtml .= '<li><b>'.qa_html($widget['title']).'</b> - '.
Gideon Greenspan committed
1624 1625
					'<a href="'.qa_path_html('admin/layoutwidgets', array('edit' => $widget['widgetid'])).'">'.
					@$placeoptions[$widget['place']].'</a>';
Scott Vivian committed
1626

Scott Vivian committed
1627
				$listhtml .= '</li>';
Gideon Greenspan committed
1628
			}
Scott Vivian committed
1629

Gideon Greenspan committed
1630
			if (strlen($listhtml))
Scott Vivian committed
1631
				$qa_content['form']['fields']['widgets'] = array(
Gideon Greenspan committed
1632 1633
					'label' => qa_lang_html('admin/active_widgets_explanation'),
					'type' => 'custom',
Gideon Greenspan committed
1634
					'html' => '<ul style="margin-bottom:0;">'.$listhtml.'</ul>',
Gideon Greenspan committed
1635
				);
Scott Vivian committed
1636

Gideon Greenspan committed
1637
			break;
Scott Vivian committed
1638

Gideon Greenspan committed
1639
		case 'permissions':
Scott Vivian committed
1640
			$qa_content['form']['fields']['permit_block'] = array(
Gideon Greenspan committed
1641 1642 1643 1644
				'type' => 'static',
				'label' => qa_lang_html('options/permit_block'),
				'value' => qa_lang_html('options/permit_moderators'),
			);
Scott Vivian committed
1645

Gideon Greenspan committed
1646
			if (!QA_FINAL_EXTERNAL_USERS) {
Scott Vivian committed
1647
				$qa_content['form']['fields']['permit_approve_users'] = array(
Gideon Greenspan committed
1648 1649 1650 1651
					'type' => 'static',
					'label' => qa_lang_html('options/permit_approve_users'),
					'value' => qa_lang_html('options/permit_moderators'),
				);
Scott Vivian committed
1652

Scott Vivian committed
1653
				$qa_content['form']['fields']['permit_create_experts'] = array(
Gideon Greenspan committed
1654 1655 1656 1657
					'type' => 'static',
					'label' => qa_lang_html('options/permit_create_experts'),
					'value' => qa_lang_html('options/permit_moderators'),
				);
Scott Vivian committed
1658

Scott Vivian committed
1659
				$qa_content['form']['fields']['permit_see_emails'] = array(
Gideon Greenspan committed
1660 1661 1662 1663
					'type' => 'static',
					'label' => qa_lang_html('options/permit_see_emails'),
					'value' => qa_lang_html('options/permit_admins'),
				);
Scott Vivian committed
1664

Scott Vivian committed
1665
				$qa_content['form']['fields']['permit_delete_users'] = array(
Gideon Greenspan committed
1666 1667 1668 1669
					'type' => 'static',
					'label' => qa_lang_html('options/permit_delete_users'),
					'value' => qa_lang_html('options/permit_admins'),
				);
Scott Vivian committed
1670

Scott Vivian committed
1671
				$qa_content['form']['fields']['permit_create_eds_mods'] = array(
Gideon Greenspan committed
1672 1673 1674 1675
					'type' => 'static',
					'label' => qa_lang_html('options/permit_create_eds_mods'),
					'value' => qa_lang_html('options/permit_admins'),
				);
Scott Vivian committed
1676

Scott Vivian committed
1677
				$qa_content['form']['fields']['permit_create_admins'] = array(
Gideon Greenspan committed
1678 1679 1680 1681
					'type' => 'static',
					'label' => qa_lang_html('options/permit_create_admins'),
					'value' => qa_lang_html('options/permit_supers'),
				);
Scott Vivian committed
1682

Gideon Greenspan committed
1683 1684
			}
			break;
Scott Vivian committed
1685

Gideon Greenspan committed
1686 1687
		case 'mailing':
			require_once QA_INCLUDE_DIR.'qa-util-sort.php';
Scott Vivian committed
1688

Gideon Greenspan committed
1689 1690 1691
			if (isset($mailingprogress)) {
				unset($qa_content['form']['buttons']['save']);
				unset($qa_content['form']['buttons']['reset']);
Scott Vivian committed
1692

Gideon Greenspan committed
1693 1694 1695 1696
				if ($startmailing) {
					unset($qa_content['form']['hidden']['dosaveoptions']);

					foreach ($showoptions as $optionname)
Scott Vivian committed
1697
						$qa_content['form']['fields'][$optionname]['type'] = 'static';
Scott Vivian committed
1698

Scott Vivian committed
1699
					$qa_content['form']['fields']['mailing_body']['value'] = qa_html(qa_opt('mailing_body'), true);
Gideon Greenspan committed
1700

Scott Vivian committed
1701
					$qa_content['form']['buttons']['stop'] = array(
Gideon Greenspan committed
1702
						'tags' => 'name="domailingpause" id="domailingpause"',
Gideon Greenspan committed
1703 1704 1705
						'label' => qa_lang_html('admin/pause_mailing_button'),
					);

Scott Vivian committed
1706 1707 1708
				}
				else {
					$qa_content['form']['buttons']['resume'] = array(
Gideon Greenspan committed
1709
						'tags' => 'name="domailingresume"',
Gideon Greenspan committed
1710 1711 1712
						'label' => qa_lang_html('admin/resume_mailing_button'),
					);

Scott Vivian committed
1713
					$qa_content['form']['buttons']['cancel'] = array(
Gideon Greenspan committed
1714
						'tags' => 'name="domailingcancel"',
Gideon Greenspan committed
1715 1716 1717
						'label' => qa_lang_html('admin/cancel_mailing_button'),
					);
				}
Scott Vivian committed
1718 1719 1720
			}
			else {
				$qa_content['form']['buttons']['spacer'] = array();
Scott Vivian committed
1721

Scott Vivian committed
1722
				$qa_content['form']['buttons']['test'] = array(
Gideon Greenspan committed
1723
					'tags' => 'name="domailingtest" id="domailingtest"',
Gideon Greenspan committed
1724 1725 1726
					'label' => qa_lang_html('admin/send_test_button'),
				);

Scott Vivian committed
1727
				$qa_content['form']['buttons']['start'] = array(
Gideon Greenspan committed
1728
					'tags' => 'name="domailingstart" id="domailingstart"',
Gideon Greenspan committed
1729 1730 1731
					'label' => qa_lang_html('admin/start_mailing_button'),
				);
			}
Scott Vivian committed
1732

Gideon Greenspan committed
1733
			if (!$startmailing) {
Scott Vivian committed
1734 1735 1736
				$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');
Gideon Greenspan committed
1737 1738 1739
			}
			break;
	}
Scott Vivian committed
1740

Gideon Greenspan committed
1741 1742 1743 1744

	if (isset($checkboxtodisplay))
		qa_set_display_rules($qa_content, $checkboxtodisplay);

Scott Vivian committed
1745
	$qa_content['navigation']['sub'] = qa_admin_sub_navigation();
Gideon Greenspan committed
1746

Scott Vivian committed
1747

Gideon Greenspan committed
1748 1749 1750 1751 1752 1753
	return $qa_content;


/*
	Omit PHP closing tag to help avoid accidental output
*/