PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/qa-include/pages/admin/admin-categories.php

http://github.com/q2a/question2answer
PHP | 649 lines | 482 code | 138 blank | 29 comment | 73 complexity | b5f0985af5dfa00de0b5f71073621db8 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. Question2Answer by Gideon Greenspan and contributors
  4. http://www.question2answer.org/
  5. Description: Controller for admin page for editing categories
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. More about this license: http://www.question2answer.org/license.php
  15. */
  16. if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
  17. header('Location: ../../../');
  18. exit;
  19. }
  20. require_once QA_INCLUDE_DIR . 'app/admin.php';
  21. require_once QA_INCLUDE_DIR . 'db/selects.php';
  22. require_once QA_INCLUDE_DIR . 'db/admin.php';
  23. require_once QA_INCLUDE_DIR . 'app/format.php';
  24. // Get relevant list of categories
  25. $editcategoryid = qa_post_text('edit');
  26. if (!isset($editcategoryid))
  27. $editcategoryid = qa_get('edit');
  28. if (!isset($editcategoryid))
  29. $editcategoryid = qa_get('addsub');
  30. $categories = qa_db_select_with_pending(qa_db_category_nav_selectspec($editcategoryid, true, false, true));
  31. // Check admin privileges (do late to allow one DB query)
  32. if (!qa_admin_check_privileges($qa_content))
  33. return $qa_content;
  34. // Work out the appropriate state for the page
  35. $editcategory = @$categories[$editcategoryid];
  36. if (isset($editcategory)) {
  37. $parentid = qa_get('addsub');
  38. if (isset($parentid))
  39. $editcategory = array('parentid' => $parentid);
  40. } else {
  41. if (qa_clicked('doaddcategory'))
  42. $editcategory = array();
  43. elseif (qa_clicked('dosavecategory')) {
  44. $parentid = qa_post_text('parent');
  45. $editcategory = array('parentid' => strlen($parentid) ? $parentid : null);
  46. }
  47. }
  48. $setmissing = qa_post_text('missing') || qa_get('missing');
  49. $setparent = !$setmissing && (qa_post_text('setparent') || qa_get('setparent')) && isset($editcategory['categoryid']);
  50. $hassubcategory = false;
  51. foreach ($categories as $category) {
  52. if (!strcmp($category['parentid'], $editcategoryid))
  53. $hassubcategory = true;
  54. }
  55. // Process saving options
  56. $savedoptions = false;
  57. $securityexpired = false;
  58. if (qa_clicked('dosaveoptions')) {
  59. if (!qa_check_form_security_code('admin/categories', qa_post_text('code')))
  60. $securityexpired = true;
  61. else {
  62. qa_set_option('allow_no_category', (int)qa_post_text('option_allow_no_category'));
  63. qa_set_option('allow_no_sub_category', (int)qa_post_text('option_allow_no_sub_category'));
  64. $savedoptions = true;
  65. }
  66. }
  67. // Process saving an old or new category
  68. if (qa_clicked('docancel')) {
  69. if ($setmissing || $setparent)
  70. qa_redirect(qa_request(), array('edit' => $editcategory['categoryid']));
  71. elseif (isset($editcategory['categoryid']))
  72. qa_redirect(qa_request());
  73. else
  74. qa_redirect(qa_request(), array('edit' => @$editcategory['parentid']));
  75. } elseif (qa_clicked('dosetmissing')) {
  76. if (!qa_check_form_security_code('admin/categories', qa_post_text('code')))
  77. $securityexpired = true;
  78. else {
  79. $inreassign = qa_get_category_field_value('reassign');
  80. qa_db_category_reassign($editcategory['categoryid'], $inreassign);
  81. qa_redirect(qa_request(), array('recalc' => 1, 'edit' => $editcategory['categoryid']));
  82. }
  83. } elseif (qa_clicked('dosavecategory')) {
  84. if (!qa_check_form_security_code('admin/categories', qa_post_text('code')))
  85. $securityexpired = true;
  86. elseif (qa_post_text('dodelete')) {
  87. if (!$hassubcategory) {
  88. $inreassign = qa_get_category_field_value('reassign');
  89. qa_db_category_reassign($editcategory['categoryid'], $inreassign);
  90. qa_db_category_delete($editcategory['categoryid']);
  91. qa_redirect(qa_request(), array('recalc' => 1, 'edit' => $editcategory['parentid']));
  92. }
  93. } else {
  94. require_once QA_INCLUDE_DIR . 'util/string.php';
  95. $inname = qa_post_text('name');
  96. $incontent = qa_post_text('content');
  97. $inparentid = $setparent ? qa_get_category_field_value('parent') : $editcategory['parentid'];
  98. $inposition = qa_post_text('position');
  99. $errors = array();
  100. // Check the parent ID
  101. $incategories = qa_db_select_with_pending(qa_db_category_nav_selectspec($inparentid, true));
  102. // Verify the name is legitimate for that parent ID
  103. if (empty($inname))
  104. $errors['name'] = qa_lang('main/field_required');
  105. elseif (qa_strlen($inname) > QA_DB_MAX_CAT_PAGE_TITLE_LENGTH)
  106. $errors['name'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TITLE_LENGTH);
  107. else {
  108. foreach ($incategories as $category) {
  109. if (!strcmp($category['parentid'], $inparentid) &&
  110. strcmp($category['categoryid'], @$editcategory['categoryid']) &&
  111. qa_strtolower($category['title']) == qa_strtolower($inname)
  112. ) {
  113. $errors['name'] = qa_lang('admin/category_already_used');
  114. }
  115. }
  116. }
  117. // Verify the slug is legitimate for that parent ID
  118. for ($attempt = 0; $attempt < 100; $attempt++) {
  119. switch ($attempt) {
  120. case 0:
  121. $inslug = qa_post_text('slug');
  122. if (!isset($inslug))
  123. $inslug = implode('-', qa_string_to_words($inname));
  124. break;
  125. case 1:
  126. $inslug = qa_lang_sub('admin/category_default_slug', $inslug);
  127. break;
  128. default:
  129. $inslug = qa_lang_sub('admin/category_default_slug', $attempt - 1);
  130. break;
  131. }
  132. $matchcategoryid = qa_db_category_slug_to_id($inparentid, $inslug); // query against DB since MySQL ignores accents, etc...
  133. if (!isset($inparentid))
  134. $matchpage = qa_db_single_select(qa_db_page_full_selectspec($inslug, false));
  135. else
  136. $matchpage = null;
  137. if (empty($inslug))
  138. $errors['slug'] = qa_lang('main/field_required');
  139. elseif (qa_strlen($inslug) > QA_DB_MAX_CAT_PAGE_TAGS_LENGTH)
  140. $errors['slug'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
  141. elseif (preg_match('/[\\+\\/]/', $inslug))
  142. $errors['slug'] = qa_lang_sub('admin/slug_bad_chars', '+ /');
  143. elseif (!isset($inparentid) && qa_admin_is_slug_reserved($inslug)) // only top level is a problem
  144. $errors['slug'] = qa_lang('admin/slug_reserved');
  145. elseif (isset($matchcategoryid) && strcmp($matchcategoryid, @$editcategory['categoryid']))
  146. $errors['slug'] = qa_lang('admin/category_already_used');
  147. elseif (isset($matchpage))
  148. $errors['slug'] = qa_lang('admin/page_already_used');
  149. else
  150. unset($errors['slug']);
  151. if (isset($editcategory['categoryid']) || !isset($errors['slug'])) // don't try other options if editing existing category
  152. break;
  153. }
  154. // Perform appropriate database action
  155. if (empty($errors)) {
  156. require_once QA_INCLUDE_DIR . 'app/cookies.php';
  157. if (isset($editcategory['categoryid'])) { // changing existing category
  158. qa_db_category_rename($editcategory['categoryid'], $inname, $inslug);
  159. $recalc = false;
  160. if ($setparent) {
  161. qa_db_category_set_parent($editcategory['categoryid'], $inparentid);
  162. $recalc = true;
  163. } else {
  164. qa_db_category_set_content($editcategory['categoryid'], $incontent);
  165. qa_db_category_set_position($editcategory['categoryid'], $inposition);
  166. $recalc = $hassubcategory && $inslug !== $editcategory['tags'];
  167. }
  168. qa_report_event('cat_edit', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array(
  169. 'categoryid' => $editcategory['categoryid'],
  170. 'parentid' => isset($inparentid)?$inparentid:null,
  171. 'content' => isset($incontent)?$incontent:null,
  172. 'position' => isset($inposition)?$inposition:null,
  173. 'name' => $inname,
  174. 'slug' => $inslug,
  175. ));
  176. qa_redirect(qa_request(), array('edit' => $editcategory['categoryid'], 'saved' => true, 'recalc' => (int)$recalc));
  177. } else { // creating a new one
  178. $categoryid = qa_db_category_create($inparentid, $inname, $inslug);
  179. qa_db_category_set_content($categoryid, $incontent);
  180. if (isset($inposition))
  181. qa_db_category_set_position($categoryid, $inposition);
  182. qa_report_event('cat_new', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array(
  183. 'categoryid' => $categoryid,
  184. 'parentid' => $inparentid,
  185. 'content' => isset($incontent)?$incontent:null,
  186. 'position' => isset($inposition)?$inposition:null,
  187. 'name' => $inname,
  188. 'slug' => $inslug,
  189. ));
  190. qa_redirect(qa_request(), array('edit' => $inparentid, 'added' => true));
  191. }
  192. }
  193. }
  194. }
  195. // Prepare content for theme
  196. $qa_content = qa_content_prepare();
  197. $qa_content['title'] = qa_lang_html('admin/admin_title') . ' - ' . qa_lang_html('admin/categories_title');
  198. $qa_content['error'] = $securityexpired ? qa_lang_html('admin/form_security_expired') : qa_admin_page_error();
  199. if ($setmissing) {
  200. $qa_content['form'] = array(
  201. 'tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"',
  202. 'style' => 'tall',
  203. 'fields' => array(
  204. 'reassign' => array(
  205. 'label' => isset($editcategory)
  206. ? qa_lang_html_sub('admin/category_no_sub_to', qa_html($editcategory['title']))
  207. : qa_lang_html('admin/category_none_to'),
  208. 'loose' => true,
  209. ),
  210. ),
  211. 'buttons' => array(
  212. 'save' => array(
  213. 'tags' => 'id="dosaveoptions"', // just used for qa_recalc_click()
  214. 'label' => qa_lang_html('main/save_button'),
  215. ),
  216. 'cancel' => array(
  217. 'tags' => 'name="docancel"',
  218. 'label' => qa_lang_html('main/cancel_button'),
  219. ),
  220. ),
  221. 'hidden' => array(
  222. 'dosetmissing' => '1', // for IE
  223. 'edit' => @$editcategory['categoryid'],
  224. 'missing' => '1',
  225. 'code' => qa_get_form_security_code('admin/categories'),
  226. ),
  227. );
  228. qa_set_up_category_field($qa_content, $qa_content['form']['fields']['reassign'], 'reassign',
  229. $categories, @$editcategory['categoryid'], qa_opt('allow_no_category'), qa_opt('allow_no_sub_category'));
  230. } elseif (isset($editcategory)) {
  231. $qa_content['form'] = array(
  232. 'tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"',
  233. 'style' => 'tall',
  234. 'ok' => qa_get('saved') ? qa_lang_html('admin/category_saved') : (qa_get('added') ? qa_lang_html('admin/category_added') : null),
  235. 'fields' => array(
  236. 'name' => array(
  237. 'id' => 'name_display',
  238. 'tags' => 'name="name" id="name"',
  239. 'label' => qa_lang_html(count($categories) ? 'admin/category_name' : 'admin/category_name_first'),
  240. 'value' => qa_html(isset($inname) ? $inname : @$editcategory['title']),
  241. 'error' => qa_html(@$errors['name']),
  242. ),
  243. 'questions' => array(),
  244. 'delete' => array(),
  245. 'reassign' => array(),
  246. 'slug' => array(
  247. 'id' => 'slug_display',
  248. 'tags' => 'name="slug"',
  249. 'label' => qa_lang_html('admin/category_slug'),
  250. 'value' => qa_html(isset($inslug) ? $inslug : @$editcategory['tags']),
  251. 'error' => qa_html(@$errors['slug']),
  252. ),
  253. 'content' => array(
  254. 'id' => 'content_display',
  255. 'tags' => 'name="content"',
  256. 'label' => qa_lang_html('admin/category_description'),
  257. 'value' => qa_html(isset($incontent) ? $incontent : @$editcategory['content']),
  258. 'error' => qa_html(@$errors['content']),
  259. 'rows' => 2,
  260. ),
  261. ),
  262. 'buttons' => array(
  263. 'save' => array(
  264. 'tags' => 'id="dosaveoptions"', // just used for qa_recalc_click
  265. 'label' => qa_lang_html(isset($editcategory['categoryid']) ? 'main/save_button' : 'admin/add_category_button'),
  266. ),
  267. 'cancel' => array(
  268. 'tags' => 'name="docancel"',
  269. 'label' => qa_lang_html('main/cancel_button'),
  270. ),
  271. ),
  272. 'hidden' => array(
  273. 'dosavecategory' => '1', // for IE
  274. 'edit' => @$editcategory['categoryid'],
  275. 'parent' => @$editcategory['parentid'],
  276. 'setparent' => (int)$setparent,
  277. 'code' => qa_get_form_security_code('admin/categories'),
  278. ),
  279. );
  280. if ($setparent) {
  281. unset($qa_content['form']['fields']['delete']);
  282. unset($qa_content['form']['fields']['reassign']);
  283. unset($qa_content['form']['fields']['questions']);
  284. unset($qa_content['form']['fields']['content']);
  285. $qa_content['form']['fields']['parent'] = array(
  286. 'label' => qa_lang_html('admin/category_parent'),
  287. );
  288. $childdepth = qa_db_category_child_depth($editcategory['categoryid']);
  289. qa_set_up_category_field($qa_content, $qa_content['form']['fields']['parent'], 'parent',
  290. isset($incategories) ? $incategories : $categories, isset($inparentid) ? $inparentid : @$editcategory['parentid'],
  291. true, true, QA_CATEGORY_DEPTH - 1 - $childdepth, @$editcategory['categoryid']);
  292. $qa_content['form']['fields']['parent']['options'][''] = qa_lang_html('admin/category_top_level');
  293. @$qa_content['form']['fields']['parent']['note'] .= qa_lang_html_sub('admin/category_max_depth_x', QA_CATEGORY_DEPTH);
  294. } elseif (isset($editcategory['categoryid'])) { // existing category
  295. if ($hassubcategory) {
  296. $qa_content['form']['fields']['name']['note'] = qa_lang_html('admin/category_no_delete_subs');
  297. unset($qa_content['form']['fields']['delete']);
  298. unset($qa_content['form']['fields']['reassign']);
  299. } else {
  300. $qa_content['form']['fields']['delete'] = array(
  301. 'tags' => 'name="dodelete" id="dodelete"',
  302. 'label' =>
  303. '<span id="reassign_shown">' . qa_lang_html('admin/delete_category_reassign') . '</span>' .
  304. '<span id="reassign_hidden" style="display:none;">' . qa_lang_html('admin/delete_category') . '</span>',
  305. 'value' => 0,
  306. 'type' => 'checkbox',
  307. );
  308. $qa_content['form']['fields']['reassign'] = array(
  309. 'id' => 'reassign_display',
  310. 'tags' => 'name="reassign"',
  311. );
  312. qa_set_up_category_field($qa_content, $qa_content['form']['fields']['reassign'], 'reassign',
  313. $categories, $editcategory['parentid'], true, true, null, $editcategory['categoryid']);
  314. }
  315. $qa_content['form']['fields']['questions'] = array(
  316. 'label' => qa_lang_html('admin/total_qs'),
  317. 'type' => 'static',
  318. 'value' => '<a href="' . qa_path_html('questions/' . qa_category_path_request($categories, $editcategory['categoryid'])) . '">' .
  319. ($editcategory['qcount'] == 1
  320. ? qa_lang_html_sub('main/1_question', '1', '1')
  321. : qa_lang_html_sub('main/x_questions', qa_format_number($editcategory['qcount']))
  322. ) . '</a>',
  323. );
  324. if ($hassubcategory && !qa_opt('allow_no_sub_category')) {
  325. $nosubcount = qa_db_count_categoryid_qs($editcategory['categoryid']);
  326. if ($nosubcount) {
  327. $qa_content['form']['fields']['questions']['error'] =
  328. strtr(qa_lang_html('admin/category_no_sub_error'), array(
  329. '^q' => qa_format_number($nosubcount),
  330. '^1' => '<a href="' . qa_path_html(qa_request(), array('edit' => $editcategory['categoryid'], 'missing' => 1)) . '">',
  331. '^2' => '</a>',
  332. ));
  333. }
  334. }
  335. qa_set_display_rules($qa_content, array(
  336. 'position_display' => '!dodelete',
  337. 'slug_display' => '!dodelete',
  338. 'content_display' => '!dodelete',
  339. 'parent_display' => '!dodelete',
  340. 'children_display' => '!dodelete',
  341. 'reassign_display' => 'dodelete',
  342. 'reassign_shown' => 'dodelete',
  343. 'reassign_hidden' => '!dodelete',
  344. ));
  345. } else { // new category
  346. unset($qa_content['form']['fields']['delete']);
  347. unset($qa_content['form']['fields']['reassign']);
  348. unset($qa_content['form']['fields']['slug']);
  349. unset($qa_content['form']['fields']['questions']);
  350. $qa_content['focusid'] = 'name';
  351. }
  352. if (!$setparent) {
  353. $pathhtml = qa_category_path_html($categories, @$editcategory['parentid']);
  354. if (count($categories)) {
  355. $qa_content['form']['fields']['parent'] = array(
  356. 'id' => 'parent_display',
  357. 'label' => qa_lang_html('admin/category_parent'),
  358. 'type' => 'static',
  359. 'value' => (strlen($pathhtml) ? $pathhtml : qa_lang_html('admin/category_top_level')),
  360. );
  361. $qa_content['form']['fields']['parent']['value'] =
  362. '<a href="' . qa_path_html(qa_request(), array('edit' => @$editcategory['parentid'])) . '">' .
  363. $qa_content['form']['fields']['parent']['value'] . '</a>';
  364. if (isset($editcategory['categoryid'])) {
  365. $qa_content['form']['fields']['parent']['value'] .= ' - ' .
  366. '<a href="' . qa_path_html(qa_request(), array('edit' => $editcategory['categoryid'], 'setparent' => 1)) .
  367. '" style="white-space: nowrap;">' . qa_lang_html('admin/category_move_parent') . '</a>';
  368. }
  369. }
  370. $positionoptions = array();
  371. $previous = null;
  372. $passedself = false;
  373. foreach ($categories as $key => $category) {
  374. if (!strcmp($category['parentid'], @$editcategory['parentid'])) {
  375. if (isset($previous))
  376. $positionhtml = qa_lang_html_sub('admin/after_x', qa_html($passedself ? $category['title'] : $previous['title']));
  377. else
  378. $positionhtml = qa_lang_html('admin/first');
  379. $positionoptions[$category['position']] = $positionhtml;
  380. if (!strcmp($category['categoryid'], @$editcategory['categoryid']))
  381. $passedself = true;
  382. $previous = $category;
  383. }
  384. }
  385. if (isset($editcategory['position']))
  386. $positionvalue = $positionoptions[$editcategory['position']];
  387. else {
  388. $positionvalue = isset($previous) ? qa_lang_html_sub('admin/after_x', qa_html($previous['title'])) : qa_lang_html('admin/first');
  389. $positionoptions[1 + @max(array_keys($positionoptions))] = $positionvalue;
  390. }
  391. $qa_content['form']['fields']['position'] = array(
  392. 'id' => 'position_display',
  393. 'tags' => 'name="position"',
  394. 'label' => qa_lang_html('admin/position'),
  395. 'type' => 'select',
  396. 'options' => $positionoptions,
  397. 'value' => $positionvalue,
  398. );
  399. if (isset($editcategory['categoryid'])) {
  400. $catdepth = count(qa_category_path($categories, $editcategory['categoryid']));
  401. if ($catdepth < QA_CATEGORY_DEPTH) {
  402. $childrenhtml = '';
  403. foreach ($categories as $category) {
  404. if (!strcmp($category['parentid'], $editcategory['categoryid'])) {
  405. $childrenhtml .= (strlen($childrenhtml) ? ', ' : '') .
  406. '<a href="' . qa_path_html(qa_request(), array('edit' => $category['categoryid'])) . '">' . qa_html($category['title']) . '</a>' .
  407. ' (' . $category['qcount'] . ')';
  408. }
  409. }
  410. if (!strlen($childrenhtml))
  411. $childrenhtml = qa_lang_html('admin/category_no_subs');
  412. $childrenhtml .= ' - <a href="' . qa_path_html(qa_request(), array('addsub' => $editcategory['categoryid'])) .
  413. '" style="white-space: nowrap;"><b>' . qa_lang_html('admin/category_add_sub') . '</b></a>';
  414. $qa_content['form']['fields']['children'] = array(
  415. 'id' => 'children_display',
  416. 'label' => qa_lang_html('admin/category_subs'),
  417. 'type' => 'static',
  418. 'value' => $childrenhtml,
  419. );
  420. } else {
  421. $qa_content['form']['fields']['name']['note'] = qa_lang_html_sub('admin/category_no_add_subs_x', QA_CATEGORY_DEPTH);
  422. }
  423. }
  424. }
  425. } else {
  426. $qa_content['form'] = array(
  427. 'tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"',
  428. 'ok' => $savedoptions ? qa_lang_html('admin/options_saved') : null,
  429. 'style' => 'tall',
  430. 'fields' => array(
  431. 'intro' => array(
  432. 'label' => qa_lang_html('admin/categories_introduction'),
  433. 'type' => 'static',
  434. ),
  435. ),
  436. 'buttons' => array(
  437. 'save' => array(
  438. 'tags' => 'name="dosaveoptions" id="dosaveoptions"',
  439. 'label' => qa_lang_html('main/save_button'),
  440. ),
  441. 'add' => array(
  442. 'tags' => 'name="doaddcategory"',
  443. 'label' => qa_lang_html('admin/add_category_button'),
  444. ),
  445. ),
  446. 'hidden' => array(
  447. 'code' => qa_get_form_security_code('admin/categories'),
  448. ),
  449. );
  450. if (count($categories)) {
  451. unset($qa_content['form']['fields']['intro']);
  452. $navcategoryhtml = '';
  453. foreach ($categories as $category) {
  454. if (!isset($category['parentid'])) {
  455. $navcategoryhtml .=
  456. '<a href="' . qa_path_html('admin/categories', array('edit' => $category['categoryid'])) . '">' .
  457. qa_html($category['title']) .
  458. '</a> - ' .
  459. ($category['qcount'] == 1
  460. ? qa_lang_html_sub('main/1_question', '1', '1')
  461. : qa_lang_html_sub('main/x_questions', qa_format_number($category['qcount']))
  462. ) . '<br/>';
  463. }
  464. }
  465. $qa_content['form']['fields']['nav'] = array(
  466. 'label' => qa_lang_html('admin/top_level_categories'),
  467. 'type' => 'static',
  468. 'value' => $navcategoryhtml,
  469. );
  470. $qa_content['form']['fields']['allow_no_category'] = array(
  471. 'label' => qa_lang_html('options/allow_no_category'),
  472. 'tags' => 'name="option_allow_no_category"',
  473. 'type' => 'checkbox',
  474. 'value' => qa_opt('allow_no_category'),
  475. );
  476. if (!qa_opt('allow_no_category')) {
  477. $nocatcount = qa_db_count_categoryid_qs(null);
  478. if ($nocatcount) {
  479. $qa_content['form']['fields']['allow_no_category']['error'] =
  480. strtr(qa_lang_html('admin/category_none_error'), array(
  481. '^q' => qa_format_number($nocatcount),
  482. '^1' => '<a href="' . qa_path_html(qa_request(), array('missing' => 1)) . '">',
  483. '^2' => '</a>',
  484. ));
  485. }
  486. }
  487. $qa_content['form']['fields']['allow_no_sub_category'] = array(
  488. 'label' => qa_lang_html('options/allow_no_sub_category'),
  489. 'tags' => 'name="option_allow_no_sub_category"',
  490. 'type' => 'checkbox',
  491. 'value' => qa_opt('allow_no_sub_category'),
  492. );
  493. } else
  494. unset($qa_content['form']['buttons']['save']);
  495. }
  496. if (qa_get('recalc')) {
  497. $qa_content['form']['ok'] = '<span id="recalc_ok">' . qa_lang_html('admin/recalc_categories') . '</span>';
  498. $qa_content['form']['hidden']['code_recalc'] = qa_get_form_security_code('admin/recalc');
  499. $qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION;
  500. $qa_content['script_var']['qa_warning_recalc'] = qa_lang('admin/stop_recalc_warning');
  501. $qa_content['script_onloads'][] = array(
  502. "qa_recalc_click('dorecalccategories', document.getElementById('dosaveoptions'), null, 'recalc_ok');"
  503. );
  504. }
  505. $qa_content['navigation']['sub'] = qa_admin_sub_navigation();
  506. return $qa_content;