function qa_set_up_category_field(&$qa_content, &$field, $fieldname, $navcategories, $categoryid, $allownone, $allownosub, $maxdepth = null, $excludecategoryid = null) { $pathcategories = qa_category_path($navcategories, $categoryid); $startpath = ''; foreach ($pathcategories as $category) { $startpath .= '/' . $category['categoryid']; } if (isset($maxdepth)) { $maxdepth = min(QA_CATEGORY_DEPTH, $maxdepth); } else { $maxdepth = QA_CATEGORY_DEPTH; } $qa_content['script_rel'][] = 'qa-content/qa-ask.js?' . QA_VERSION; $qa_content['script_onloads'][] = sprintf('qa_category_select(%s, %s);', qa_js($fieldname), qa_js($startpath)); $qa_content['script_var']['qa_cat_exclude'] = $excludecategoryid; $qa_content['script_var']['qa_cat_allownone'] = (int) $allownone; $qa_content['script_var']['qa_cat_allownosub'] = (int) $allownosub; $qa_content['script_var']['qa_cat_maxdepth'] = $maxdepth; $field['type'] = 'select'; $field['tags'] = sprintf('name="%s_0" id="%s_0" onchange="qa_category_select(%s);"', $fieldname, $fieldname, qa_js($fieldname)); $field['options'] = array(); // create the menu that will be shown if Javascript is disabled if ($allownone) { $field['options'][''] = qa_lang_html('main/no_category'); } // this is also copied to first menu created by Javascript $keycategoryids = array(); if ($allownosub) { $category = @$navcategories[$categoryid]; $upcategory = @$navcategories[$category['parentid']]; // first get supercategories while (isset($upcategory)) { $keycategoryids[$upcategory['categoryid']] = true; $upcategory = @$navcategories[$upcategory['parentid']]; } $keycategoryids = array_reverse($keycategoryids, true); $depth = count($keycategoryids); // number of levels above if (isset($category)) { $depth++; // to count category itself foreach ($navcategories as $navcategory) { // now get siblings and self if (!strcmp($navcategory['parentid'], $category['parentid'])) { $keycategoryids[$navcategory['categoryid']] = true; } } } if ($depth < $maxdepth) { foreach ($navcategories as $navcategory) { // now get children, if not too deep if (!strcmp($navcategory['parentid'], $categoryid)) { $keycategoryids[$navcategory['categoryid']] = true; } } } } else { $haschildren = false; foreach ($navcategories as $navcategory) { // check if it has any children if (!strcmp($navcategory['parentid'], $categoryid)) { $haschildren = true; break; } } if (!$haschildren) { $keycategoryids[$categoryid] = true; } // show this category if it has no children } foreach ($keycategoryids as $keycategoryid => $dummy) { if (strcmp($keycategoryid, $excludecategoryid)) { $field['options'][$keycategoryid] = qa_category_path_html($navcategories, $keycategoryid); } } $field['value'] = @$field['options'][$categoryid]; $field['note'] = '<div id="' . $fieldname . '_note">' . '<noscript style="color:red;">' . qa_lang_html('question/category_js_note') . '</noscript>' . '</div>'; }
$nosubcount = qa_db_count_categoryid_qs($editcategory['categoryid']); if ($nosubcount) { $qa_content['form']['fields']['questions']['error'] = strtr(qa_lang_html('admin/category_no_sub_error'), array('^q' => number_format($nosubcount), '^1' => '<a href="' . qa_path_html(qa_request(), array('edit' => $editcategory['categoryid'], 'missing' => 1)) . '">', '^2' => '</a>')); } } qa_set_display_rules($qa_content, array('position_display' => '!dodelete', 'slug_display' => '!dodelete', 'content_display' => '!dodelete', 'parent_display' => '!dodelete', 'children_display' => '!dodelete', 'reassign_display' => 'dodelete', 'reassign_shown' => 'dodelete', 'reassign_hidden' => '!dodelete')); } else { // new category unset($qa_content['form']['fields']['delete']); unset($qa_content['form']['fields']['reassign']); unset($qa_content['form']['fields']['slug']); unset($qa_content['form']['fields']['questions']); $qa_content['focusid'] = 'name'; } if (!$setparent) { $pathhtml = qa_category_path_html($categories, @$editcategory['parentid']); if (count($categories)) { $qa_content['form']['fields']['parent'] = array('id' => 'parent_display', 'label' => qa_lang_html('admin/category_parent'), 'type' => 'static', 'value' => strlen($pathhtml) ? $pathhtml : qa_lang_html('admin/category_top_level')); $qa_content['form']['fields']['parent']['value'] = '<a href="' . qa_path_html(qa_request(), array('edit' => @$editcategory['parentid'])) . '">' . $qa_content['form']['fields']['parent']['value'] . '</a>'; if (isset($editcategory['categoryid'])) { $qa_content['form']['fields']['parent']['value'] .= ' - ' . '<a href="' . qa_path_html(qa_request(), array('edit' => $editcategory['categoryid'], 'setparent' => 1)) . '" style="white-space: nowrap;">' . qa_lang_html('admin/category_move_parent') . '</a>'; } } $positionoptions = array(); $previous = null; $passedself = false; foreach ($categories as $key => $category) { if (!strcmp($category['parentid'], @$editcategory['parentid'])) { if (isset($previous)) { $positionhtml = qa_lang_html_sub('admin/after_x', qa_html($passedself ? $category['title'] : $previous['title'])); } else {