qa-page-admin-pages.php 18.5 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-pages.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Controller for admin page for editing custom pages and external links


	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
	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-app-admin.php';
	require_once QA_INCLUDE_DIR.'qa-app-format.php';
	require_once QA_INCLUDE_DIR.'qa-db-selects.php';

Scott Vivian committed
36

Gideon Greenspan committed
37 38 39 40 41
//	Get current list of pages and determine the state of this admin page

	$pageid=qa_post_text('edit');
	if (!isset($pageid))
		$pageid=qa_get('edit');
Scott Vivian committed
42

Gideon Greenspan committed
43
	list($pages, $editpage)=qa_db_select_with_pending(
Gideon Greenspan committed
44 45 46
		qa_db_pages_selectspec(),
		isset($pageid) ? qa_db_page_full_selectspec($pageid, true) : null
	);
Scott Vivian committed
47

Gideon Greenspan committed
48 49 50
	if ((qa_clicked('doaddpage') || qa_clicked('doaddlink') || qa_get('doaddlink') || qa_clicked('dosavepage')) && !isset($editpage)) {
		$editpage=array('title' => qa_get('text'), 'tags' => qa_get('url'), 'nav' => qa_get('nav'), 'position' => 1);
		$isexternal=qa_clicked('doaddlink') || qa_get('doaddlink') || qa_post_text('external');
Scott Vivian committed
51

Gideon Greenspan committed
52 53
	} elseif (isset($editpage))
		$isexternal=$editpage['flags'] & QA_PAGE_FLAGS_EXTERNAL;
Scott Vivian committed
54

Gideon Greenspan committed
55 56 57 58 59

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

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


Gideon Greenspan committed
62
//	Define an array of navigation settings we can change, option name => language key
Scott Vivian committed
63

Gideon Greenspan committed
64
	$hascustomhome=qa_has_custom_home();
Scott Vivian committed
65

Gideon Greenspan committed
66 67 68 69 70 71 72 73 74 75 76 77
	$navoptions=array(
		'nav_home' => 'main/nav_home',
		'nav_activity' => 'main/nav_activity',
		 $hascustomhome ? 'nav_qa_not_home' : 'nav_qa_is_home' => $hascustomhome ? 'main/nav_qa' : 'admin/nav_qa_is_home',
		'nav_questions' => 'main/nav_qs',
		'nav_hot' => 'main/nav_hot',
		'nav_unanswered' => 'main/nav_unanswered',
		'nav_tags' => 'main/nav_tags',
		'nav_categories' => 'main/nav_categories',
		'nav_users' => 'main/nav_users',
		'nav_ask' => 'main/nav_ask',
	);
Scott Vivian committed
78

Gideon Greenspan committed
79 80 81 82 83 84 85 86 87 88 89 90 91
	$navpaths=array(
		'nav_home' => '',
		'nav_activity' => 'activity',
		'nav_qa_not_home' => 'qa',
		'nav_qa_is_home' => '',
		'nav_questions' => 'questions',
		'nav_hot' => 'hot',
		'nav_unanswered' => 'unanswered',
		'nav_tags' => 'tags',
		'nav_categories' => 'categories',
		'nav_users' => 'users',
		'nav_ask' => 'ask',
	);
Scott Vivian committed
92

Gideon Greenspan committed
93 94
	if (!qa_opt('show_custom_home'))
		unset($navoptions['nav_home']);
Scott Vivian committed
95

Gideon Greenspan committed
96 97 98 99 100 101 102 103 104
	if (!qa_using_categories())
		unset($navoptions['nav_categories']);

	if (!qa_using_tags())
		unset($navoptions['nav_tags']);


//	Process saving an old or new page

Gideon Greenspan committed
105 106
	$securityexpired=false;

Gideon Greenspan committed
107 108 109 110
	if (qa_clicked('docancel'))
		$editpage=null;

	elseif (qa_clicked('dosaveoptions') || qa_clicked('doaddpage') || qa_clicked('doaddlink')) {
Gideon Greenspan committed
111 112 113
		if (!qa_check_form_security_code('admin/pages', qa_post_text('code')))
			$securityexpired=true;
		else foreach ($navoptions as $optionname => $langkey)
Gideon Greenspan committed
114 115 116 117 118
			qa_set_option($optionname, (int)qa_post_text('option_'.$optionname));

	} elseif (qa_clicked('dosavepage')) {
		require_once QA_INCLUDE_DIR.'qa-db-admin.php';
		require_once QA_INCLUDE_DIR.'qa-util-string.php';
Scott Vivian committed
119

Gideon Greenspan committed
120 121 122 123
		if (!qa_check_form_security_code('admin/pages', qa_post_text('code')))
			$securityexpired=true;
		else {
			$reloadpages=false;
Scott Vivian committed
124

Gideon Greenspan committed
125 126
			if (qa_post_text('dodelete')) {
				qa_db_page_delete($editpage['pageid']);
Scott Vivian committed
127

Gideon Greenspan committed
128 129 130
				$searchmodules=qa_load_modules_with('search', 'unindex_page');
				foreach ($searchmodules as $searchmodule)
					$searchmodule->unindex_page($editpage['pageid']);
Scott Vivian committed
131

Gideon Greenspan committed
132 133
				$editpage=null;
				$reloadpages=true;
Scott Vivian committed
134

Gideon Greenspan committed
135
			} else {
Gideon Greenspan committed
136 137 138 139 140 141 142
				$inname=qa_post_text('name');
				$inposition=qa_post_text('position');
				$inpermit=(int)qa_post_text('permit');
				$inurl=qa_post_text('url');
				$innewwindow=qa_post_text('newwindow');
				$inheading=qa_post_text('heading');
				$incontent=qa_post_text('content');
Scott Vivian committed
143

Gideon Greenspan committed
144
				$errors=array();
Scott Vivian committed
145

Gideon Greenspan committed
146
			//	Verify the name (navigation link) is legitimate
Scott Vivian committed
147

Gideon Greenspan committed
148 149 150 151
				if (empty($inname))
					$errors['name']=qa_lang('main/field_required');
				elseif (qa_strlen($inname)>QA_DB_MAX_CAT_PAGE_TITLE_LENGTH)
					$errors['name']=qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TITLE_LENGTH);
Scott Vivian committed
152

Gideon Greenspan committed
153
				if ($isexternal) {
Scott Vivian committed
154

Gideon Greenspan committed
155
				//	Verify the url is legitimate (vaguely)
Scott Vivian committed
156

Gideon Greenspan committed
157 158 159 160
					if (empty($inurl))
						$errors['url']=qa_lang('main/field_required');
					elseif (qa_strlen($inurl)>QA_DB_MAX_CAT_PAGE_TAGS_LENGTH)
						$errors['url']=qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
Scott Vivian committed
161

Gideon Greenspan committed
162
				} else {
Scott Vivian committed
163

Gideon Greenspan committed
164
				//	Verify the heading is legitimate
Scott Vivian committed
165

Gideon Greenspan committed
166 167
					if (qa_strlen($inheading)>QA_DB_MAX_TITLE_LENGTH)
						$errors['heading']=qa_lang_sub('main/max_length_x', QA_DB_MAX_TITLE_LENGTH);
Scott Vivian committed
168

Gideon Greenspan committed
169
				//	Verify the slug is legitimate (and try some defaults if we're creating a new page, and it's not)
Scott Vivian committed
170

Gideon Greenspan committed
171 172 173 174 175 176 177
					for ($attempt=0; $attempt<100; $attempt++) {
						switch ($attempt) {
							case 0:
								$inslug=qa_post_text('slug');
								if (!isset($inslug))
									$inslug=implode('-', qa_string_to_words($inname));
								break;
Scott Vivian committed
178

Gideon Greenspan committed
179 180 181
							case 1:
								$inslug=qa_lang_sub('admin/page_default_slug', $inslug);
								break;
Scott Vivian committed
182

Gideon Greenspan committed
183 184 185 186
							default:
								$inslug=qa_lang_sub('admin/page_default_slug', $attempt-1);
								break;
						}
Scott Vivian committed
187

Gideon Greenspan committed
188 189 190 191
						list($matchcategoryid, $matchpage)=qa_db_select_with_pending(
							qa_db_slugs_to_category_id_selectspec($inslug),
							qa_db_page_full_selectspec($inslug, false)
						);
Scott Vivian committed
192

Gideon Greenspan committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206
						if (empty($inslug))
							$errors['slug']=qa_lang('main/field_required');
						elseif (qa_strlen($inslug)>QA_DB_MAX_CAT_PAGE_TAGS_LENGTH)
							$errors['slug']=qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
						elseif (preg_match('/[\\+\\/]/', $inslug))
							$errors['slug']=qa_lang_sub('admin/slug_bad_chars', '+ /');
						elseif (qa_admin_is_slug_reserved($inslug))
							$errors['slug']=qa_lang('admin/slug_reserved');
						elseif (isset($matchpage) && ($matchpage['pageid']!=@$editpage['pageid']))
							$errors['slug']=qa_lang('admin/page_already_used');
						elseif (isset($matchcategoryid))
							$errors['slug']=qa_lang('admin/category_already_used');
						else
							unset($errors['slug']);
Scott Vivian committed
207

Gideon Greenspan committed
208
						if (isset($editpage['pageid']) || !isset($errors['slug'])) // don't try other options if editing existing page
Gideon Greenspan committed
209 210 211
							break;
					}
				}
Scott Vivian committed
212

Gideon Greenspan committed
213
			//	Perform appropriate database action
Scott Vivian committed
214

Gideon Greenspan committed
215
				if (isset($editpage['pageid'])) { // changing existing page
Gideon Greenspan committed
216
					if ($isexternal)
Gideon Greenspan committed
217 218 219 220 221
						qa_db_page_set_fields($editpage['pageid'],
							isset($errors['name']) ? $editpage['title'] : $inname,
							QA_PAGE_FLAGS_EXTERNAL | ($innewwindow ? QA_PAGE_FLAGS_NEW_WINDOW : 0),
							isset($errors['url']) ? $editpage['tags'] : $inurl,
							null, null, $inpermit);
Scott Vivian committed
222

Gideon Greenspan committed
223
					else {
Gideon Greenspan committed
224 225 226
						$setheading=isset($errors['heading']) ? $editpage['heading'] : $inheading;
						$setslug=isset($errors['slug']) ? $editpage['tags'] : $inslug;
						$setcontent=isset($errors['content']) ? $editpage['content'] : $incontent;
Scott Vivian committed
227

Gideon Greenspan committed
228 229 230 231
						qa_db_page_set_fields($editpage['pageid'],
							isset($errors['name']) ? $editpage['title'] : $inname,
							0,
							$setslug, $setheading, $setcontent, $inpermit);
Scott Vivian committed
232

Gideon Greenspan committed
233 234 235
						$searchmodules=qa_load_modules_with('search', 'unindex_page');
						foreach ($searchmodules as $searchmodule)
							$searchmodule->unindex_page($editpage['pageid']);
Scott Vivian committed
236

Gideon Greenspan committed
237
						$indextext=qa_viewer_text($setcontent, 'html');
Scott Vivian committed
238

Gideon Greenspan committed
239 240
						$searchmodules=qa_load_modules_with('search', 'index_page');
						foreach ($searchmodules as $searchmodule)
Gideon Greenspan committed
241
							$searchmodule->index_page($editpage['pageid'], $setslug, $setheading, $setcontent, 'html', $indextext);
Gideon Greenspan committed
242
					}
Scott Vivian committed
243

Gideon Greenspan committed
244
					qa_db_page_move($editpage['pageid'], substr($inposition, 0, 1), substr($inposition, 1));
Scott Vivian committed
245

Gideon Greenspan committed
246
					$reloadpages=true;
Scott Vivian committed
247

Gideon Greenspan committed
248 249 250 251
					if (empty($errors))
						$editpage=null;
					else
						$editpage=@$pages[$editpage['pageid']];
Scott Vivian committed
252

Gideon Greenspan committed
253 254 255 256 257 258
				} else { // creating a new one
					if (empty($errors)) {
						if ($isexternal)
							$pageid=qa_db_page_create($inname, QA_PAGE_FLAGS_EXTERNAL | ($innewwindow ? QA_PAGE_FLAGS_NEW_WINDOW : 0), $inurl, null, null, $inpermit);
						else {
							$pageid=qa_db_page_create($inname, 0, $inslug, $inheading, $incontent, $inpermit);
Scott Vivian committed
259

Gideon Greenspan committed
260
							$indextext=qa_viewer_text($incontent, 'html');
Scott Vivian committed
261

Gideon Greenspan committed
262 263 264 265
							$searchmodules=qa_load_modules_with('search', 'index_page');
							foreach ($searchmodules as $searchmodule)
								$searchmodule->index_page($pageid, $inslug, $inheading, $incontent, 'html', $indextext);
						}
Scott Vivian committed
266

Gideon Greenspan committed
267
						qa_db_page_move($pageid, substr($inposition, 0, 1), substr($inposition, 1));
Scott Vivian committed
268

Gideon Greenspan committed
269 270 271
						$editpage=null;
						$reloadpages=true;
					}
Gideon Greenspan committed
272
				}
Scott Vivian committed
273

Gideon Greenspan committed
274
				if (qa_clicked('dosaveview') && empty($errors) && !$isexternal)
Scott Vivian committed
275
					qa_redirect($inslug);
Gideon Greenspan committed
276
			}
Scott Vivian committed
277

Gideon Greenspan committed
278 279 280 281
			if ($reloadpages) {
				qa_db_flush_pending_result('navpages');
				$pages=qa_db_select_with_pending(qa_db_pages_selectspec());
			}
Gideon Greenspan committed
282 283
		}
	}
Scott Vivian committed
284 285


Gideon Greenspan committed
286
//	Prepare content for theme
Scott Vivian committed
287

Gideon Greenspan committed
288 289
	$qa_content=qa_content_prepare();

Scott Vivian committed
290
	$qa_content['title']=qa_lang_html('admin/admin_title').' - '.qa_lang_html('admin/pages_title');
Gideon Greenspan committed
291
	$qa_content['error']=$securityexpired ? qa_lang_html('admin/form_security_expired') : qa_admin_page_error();
Gideon Greenspan committed
292 293 294

	if (isset($editpage)) {
		$positionoptions=array();
Scott Vivian committed
295

Gideon Greenspan committed
296 297
		if (!$isexternal)
			$positionoptions['_'.max(1, @$editpage['position'])]=qa_lang_html('admin/no_link');
Scott Vivian committed
298

Gideon Greenspan committed
299 300 301 302 303 304
		$navlangkey=array(
			'B' => 'admin/before_main_menu',
			'M' => 'admin/after_main_menu',
			'O' => 'admin/opposite_main_menu',
			'F' => 'admin/after_footer',
		);
Scott Vivian committed
305

Gideon Greenspan committed
306 307 308 309
		foreach ($navlangkey as $nav => $langkey) {
			$previous=null;
			$passedself=false;
			$maxposition=0;
Scott Vivian committed
310

Gideon Greenspan committed
311 312 313 314 315 316
			foreach ($pages as $key => $page)
				if ($page['nav']==$nav) {
					if (isset($previous))
						$positionhtml=qa_lang_html_sub('admin/after_x_tab', qa_html($passedself ? $page['title'] : $previous['title']));
					else
						$positionhtml=qa_lang_html($langkey);
Scott Vivian committed
317

Gideon Greenspan committed
318 319
					if ($page['pageid']==@$editpage['pageid'])
						$passedself=true;
Scott Vivian committed
320

Gideon Greenspan committed
321 322
					$maxposition=max($maxposition, $page['position']);
					$positionoptions[$nav.$page['position']]=$positionhtml;
Scott Vivian committed
323

Gideon Greenspan committed
324 325
					$previous=$page;
				}
Scott Vivian committed
326

Gideon Greenspan committed
327 328 329 330 331
			if ((!isset($editpage['pageid'])) || $nav!=@$editpage['nav']) {
				$positionvalue=isset($previous) ? qa_lang_html_sub('admin/after_x_tab', qa_html($previous['title'])) : qa_lang_html($langkey);
				$positionoptions[$nav.(isset($previous) ? (1+$maxposition) : 1)]=$positionvalue;
			}
		}
Scott Vivian committed
332

Gideon Greenspan committed
333
		$positionvalue=@$positionoptions[$editpage['nav'].$editpage['position']];
Scott Vivian committed
334

Gideon Greenspan committed
335
		$permitoptions=qa_admin_permit_options(QA_PERMIT_ALL, QA_PERMIT_ADMINS, false, false);
Gideon Greenspan committed
336
		$permitvalue=@$permitoptions[isset($inpermit) ? $inpermit : $editpage['permit']];
Scott Vivian committed
337

Gideon Greenspan committed
338
		$qa_content['form']=array(
Gideon Greenspan committed
339
			'tags' => 'method="post" action="'.qa_path_html(qa_request()).'"',
Scott Vivian committed
340

Gideon Greenspan committed
341
			'style' => 'tall',
Scott Vivian committed
342

Gideon Greenspan committed
343 344
			'fields' => array(
				'name' => array(
Gideon Greenspan committed
345
					'tags' => 'name="name" id="name"',
Gideon Greenspan committed
346 347 348 349
					'label' => qa_lang_html($isexternal ? 'admin/link_name' : 'admin/page_name'),
					'value' => qa_html(isset($inname) ? $inname : @$editpage['title']),
					'error' => qa_html(@$errors['name']),
				),
Scott Vivian committed
350

Gideon Greenspan committed
351
				'delete' => array(
Gideon Greenspan committed
352
					'tags' => 'name="dodelete" id="dodelete"',
Gideon Greenspan committed
353 354 355 356
					'label' => qa_lang_html($isexternal ? 'admin/delete_link' : 'admin/delete_page'),
					'value' => 0,
					'type' => 'checkbox',
				),
Scott Vivian committed
357

Gideon Greenspan committed
358 359
				'position' => array(
					'id' => 'position_display',
Gideon Greenspan committed
360
					'tags' => 'name="position"',
Gideon Greenspan committed
361 362 363 364 365
					'label' => qa_lang_html('admin/position'),
					'type' => 'select',
					'options' => $positionoptions,
					'value' => $positionvalue,
				),
Scott Vivian committed
366

Gideon Greenspan committed
367 368
				'permit' => array(
					'id' => 'permit_display',
Gideon Greenspan committed
369
					'tags' => 'name="permit"',
Gideon Greenspan committed
370 371 372 373 374
					'label' => qa_lang_html('admin/permit_to_view'),
					'type' => 'select',
					'options' => $permitoptions,
					'value' => $permitvalue,
				),
Scott Vivian committed
375

Gideon Greenspan committed
376 377
				'slug' => array(
					'id' => 'slug_display',
Gideon Greenspan committed
378
					'tags' => 'name="slug"',
Gideon Greenspan committed
379 380 381 382
					'label' => qa_lang_html('admin/page_slug'),
					'value' => qa_html(isset($inslug) ? $inslug : @$editpage['tags']),
					'error' => qa_html(@$errors['slug']),
				),
Scott Vivian committed
383

Gideon Greenspan committed
384 385
				'url' => array(
					'id' => 'url_display',
Gideon Greenspan committed
386
					'tags' => 'name="url"',
Gideon Greenspan committed
387 388 389 390
					'label' => qa_lang_html('admin/link_url'),
					'value' => qa_html(isset($inurl) ? $inurl : @$editpage['tags']),
					'error' => qa_html(@$errors['url']),
				),
Scott Vivian committed
391

Gideon Greenspan committed
392 393
				'newwindow' => array(
					'id' => 'newwindow_display',
Gideon Greenspan committed
394
					'tags' => 'name="newwindow"',
Gideon Greenspan committed
395 396 397 398
					'label' => qa_lang_html('admin/link_new_window'),
					'value' => (isset($innewwindow) ? $innewwindow : (@$editpage['flags'] & QA_PAGE_FLAGS_NEW_WINDOW)) ? 1 : 0,
					'type' => 'checkbox',
				),
Scott Vivian committed
399

Gideon Greenspan committed
400 401
				'heading' => array(
					'id' => 'heading_display',
Gideon Greenspan committed
402
					'tags' => 'name="heading"',
Gideon Greenspan committed
403 404 405 406
					'label' => qa_lang_html('admin/page_heading'),
					'value' => qa_html(isset($inheading) ? $inheading : @$editpage['heading']),
					'error' => qa_html(@$errors['heading']),
				),
Scott Vivian committed
407

Gideon Greenspan committed
408 409
				'content' => array(
					'id' => 'content_display',
Gideon Greenspan committed
410
					'tags' => 'name="content"',
Gideon Greenspan committed
411 412 413 414 415 416 417 418 419 420 421
					'label' => qa_lang_html('admin/page_content_html'),
					'value' => qa_html(isset($incontent) ? $incontent : @$editpage['content']),
					'error' => qa_html(@$errors['content']),
					'rows' => 16,
				),
			),

			'buttons' => array(
				'save' => array(
					'label' => qa_lang_html(isset($editpage['pageid']) ? 'main/save_button' : ($isexternal ? 'admin/add_link_button' : 'admin/add_page_button')),
				),
Scott Vivian committed
422

Gideon Greenspan committed
423 424 425 426
				'saveview' => array(
					'tags' => 'name="dosaveview"',
					'label' => qa_lang_html('admin/save_view_button'),
				),
Scott Vivian committed
427

Gideon Greenspan committed
428
				'cancel' => array(
Gideon Greenspan committed
429
					'tags' => 'name="docancel"',
Gideon Greenspan committed
430 431 432
					'label' => qa_lang_html('main/cancel_button'),
				),
			),
Scott Vivian committed
433

Gideon Greenspan committed
434 435 436 437
			'hidden' => array(
				'dosavepage' => '1', // for IE
				'edit' => @$editpage['pageid'],
				'external' => (int)$isexternal,
Gideon Greenspan committed
438
				'code' => qa_get_form_security_code('admin/pages'),
Gideon Greenspan committed
439 440
			),
		);
Scott Vivian committed
441

Gideon Greenspan committed
442 443 444 445
		if ($isexternal) {
			unset($qa_content['form']['fields']['slug']);
			unset($qa_content['form']['fields']['heading']);
			unset($qa_content['form']['fields']['content']);
Scott Vivian committed
446

Gideon Greenspan committed
447 448 449 450
		} else {
			unset($qa_content['form']['fields']['url']);
			unset($qa_content['form']['fields']['newwindow']);
		}
Scott Vivian committed
451

Gideon Greenspan committed
452 453 454 455 456 457 458 459
		if (isset($editpage['pageid']))
			qa_set_display_rules($qa_content, array(
				'position_display' => '!dodelete',
				'permit_display' => '!dodelete',
				($isexternal ? 'url_display' : 'slug_display') => '!dodelete',
				($isexternal ? 'newwindow_display' : 'heading_display') => '!dodelete',
				'content_display' => '!dodelete',
			));
Scott Vivian committed
460

Gideon Greenspan committed
461 462 463 464
		else {
			unset($qa_content['form']['fields']['slug']);
			unset($qa_content['form']['fields']['delete']);
		}
Scott Vivian committed
465

Gideon Greenspan committed
466 467
		if ($isexternal || !isset($editpage['pageid']))
			unset($qa_content['form']['buttons']['saveview']);
Scott Vivian committed
468

Gideon Greenspan committed
469
		$qa_content['focusid']='name';
Scott Vivian committed
470

Gideon Greenspan committed
471 472 473 474 475
	} else {

	//	List of standard navigation links

		$qa_content['form']=array(
Gideon Greenspan committed
476
			'tags' => 'method="post" action="'.qa_self_html().'"',
Scott Vivian committed
477

Gideon Greenspan committed
478
			'style' => 'tall',
Scott Vivian committed
479

Gideon Greenspan committed
480 481 482 483
			'fields' => array(),

			'buttons' => array(
				'save' => array(
Gideon Greenspan committed
484
					'tags' => 'name="dosaveoptions"',
Gideon Greenspan committed
485 486 487 488
					'label' => qa_lang_html('main/save_button'),
				),

				'addpage' => array(
Gideon Greenspan committed
489
					'tags' => 'name="doaddpage"',
Gideon Greenspan committed
490 491 492 493
					'label' => qa_lang_html('admin/add_page_button'),
				),

				'addlink' => array(
Gideon Greenspan committed
494
					'tags' => 'name="doaddlink"',
Gideon Greenspan committed
495 496 497
					'label' => qa_lang_html('admin/add_link_button'),
				),
			),
Scott Vivian committed
498

Gideon Greenspan committed
499 500 501
			'hidden' => array(
				'code' => qa_get_form_security_code('admin/pages'),
			),
Gideon Greenspan committed
502
		);
Scott Vivian committed
503

Gideon Greenspan committed
504 505 506 507 508 509 510 511
		$qa_content['form']['fields']['navlinks']=array(
			'label' => qa_lang_html('admin/nav_links_explanation'),
			'type' => 'static',
			'tight' => true,
		);

		foreach ($navoptions as $optionname => $langkey) {
			$qa_content['form']['fields'][$optionname]=array(
Gideon Greenspan committed
512 513
				'label' => '<a href="'.qa_path_html($navpaths[$optionname]).'">'.qa_lang_html($langkey).'</a>',
				'tags' => 'name="option_'.$optionname.'"',
Gideon Greenspan committed
514 515 516 517
				'type' => 'checkbox',
				'value' => qa_opt($optionname),
			);
		}
Scott Vivian committed
518

Gideon Greenspan committed
519 520 521 522 523 524 525
		$qa_content['form']['fields'][]=array(
			'type' => 'blank'
		);

	//	List of suggested plugin pages

		$listhtml='';
Scott Vivian committed
526

Gideon Greenspan committed
527
		$pagemodules=qa_load_modules_with('page', 'suggest_requests');
Scott Vivian committed
528

Gideon Greenspan committed
529 530
		foreach ($pagemodules as $tryname => $trypage) {
			$suggestrequests=$trypage->suggest_requests();
Scott Vivian committed
531

Gideon Greenspan committed
532
			foreach ($suggestrequests as $suggestrequest) {
Gideon Greenspan committed
533
				$listhtml.='<li><b><a href="'.qa_path_html($suggestrequest['request']).'">'.qa_html($suggestrequest['title']).'</a></b>';
Scott Vivian committed
534

Gideon Greenspan committed
535 536 537
				$listhtml.=qa_lang_html_sub('admin/plugin_module', qa_html($tryname));

				$listhtml.=strtr(qa_lang_html('admin/add_link_link'), array(
Gideon Greenspan committed
538 539
					'^1' => '<a href="'.qa_path_html(qa_request(), array('doaddlink' => 1, 'text' => $suggestrequest['title'], 'url' => $suggestrequest['request'], 'nav' => @$suggestrequest['nav'])).'">',
					'^2' => '</a>',
Gideon Greenspan committed
540
				));
Scott Vivian committed
541

Gideon Greenspan committed
542
				if (method_exists($trypage, 'admin_form'))
Gideon Greenspan committed
543
					$listhtml.=' - <a href="'.qa_admin_module_options_path('page', $tryname).'">'.qa_lang_html('admin/options').'</a>';
Scott Vivian committed
544

Gideon Greenspan committed
545
				$listhtml.='</li>';
Gideon Greenspan committed
546 547 548 549 550 551 552
			}
		}

		if (strlen($listhtml))
			$qa_content['form']['fields']['plugins']=array(
				'label' => qa_lang_html('admin/plugin_pages_explanation'),
				'type' => 'custom',
Gideon Greenspan committed
553
				'html' => '<ul style="margin-bottom:0;">'.$listhtml.'</ul>',
Gideon Greenspan committed
554
			);
Scott Vivian committed
555

Gideon Greenspan committed
556 557 558
	//	List of custom pages or links

		$listhtml='';
Scott Vivian committed
559

Gideon Greenspan committed
560
		foreach ($pages as $page) {
Gideon Greenspan committed
561
			$listhtml.='<li><b><a href="'.qa_custom_page_url($page).'">'.qa_html($page['title']).'</a></b>';
Scott Vivian committed
562

Gideon Greenspan committed
563
			$listhtml.=strtr(qa_lang_html(($page['flags'] & QA_PAGE_FLAGS_EXTERNAL) ? 'admin/edit_link' : 'admin/edit_page'), array(
Gideon Greenspan committed
564 565
				'^1' => '<a href="'.qa_path_html('admin/pages', array('edit' => $page['pageid'])).'">',
				'^2' => '</a>',
Gideon Greenspan committed
566
			));
Scott Vivian committed
567

Gideon Greenspan committed
568
			$listhtml.='</li>';
Gideon Greenspan committed
569
		}
Scott Vivian committed
570

Gideon Greenspan committed
571 572 573
		$qa_content['form']['fields']['pages']=array(
			'label' => strlen($listhtml) ? qa_lang_html('admin/click_name_edit') : qa_lang_html('admin/pages_explanation'),
			'type' => 'custom',
Gideon Greenspan committed
574
			'html' => strlen($listhtml) ? '<ul style="margin-bottom:0;">'.$listhtml.'</ul>' : null,
Gideon Greenspan committed
575 576 577 578 579
		);
	}

	$qa_content['navigation']['sub']=qa_admin_sub_navigation();

Scott Vivian committed
580

Gideon Greenspan committed
581 582 583 584 585 586
	return $qa_content;


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