foreach ($widgetmodules as $tryname => $trywidget) {
         if (method_exists($trywidget, 'allow_region')) {
             $listhtml .= '<li><b>' . qa_html($tryname) . '</b>';
             $listhtml .= strtr(qa_lang_html('admin/add_widget_link'), array('^1' => '<a href="' . qa_path_html('admin/layoutwidgets', array('title' => $tryname)) . '">', '^2' => '</a>'));
             if (method_exists($trywidget, 'admin_form')) {
                 $listhtml .= strtr(qa_lang_html('admin/widget_global_options'), array('^1' => '<a href="' . qa_admin_module_options_path('widget', $tryname) . '">', '^2' => '</a>'));
             }
             $listhtml .= '</li>';
         }
     }
     if (strlen($listhtml)) {
         $qa_content['form']['fields']['plugins'] = array('label' => qa_lang_html('admin/widgets_explanation'), 'style' => 'tall', 'type' => 'custom', 'html' => '<ul style="margin-bottom:0;">' . $listhtml . '</ul>');
     }
     $widgets = qa_db_single_select(qa_db_widgets_selectspec());
     $listhtml = '';
     $placeoptions = qa_admin_place_options();
     foreach ($widgets as $widget) {
         $listhtml .= '<li><b>' . qa_html($widget['title']) . '</b> - ' . '<a href="' . qa_path_html('admin/layoutwidgets', array('edit' => $widget['widgetid'])) . '">' . @$placeoptions[$widget['place']] . '</a>';
         $listhtml .= '</li>';
     }
     if (strlen($listhtml)) {
         $qa_content['form']['fields']['widgets'] = array('label' => qa_lang_html('admin/active_widgets_explanation'), 'type' => 'custom', 'html' => '<ul style="margin-bottom:0;">' . $listhtml . '</ul>');
     }
     break;
 case 'permissions':
     $qa_content['form']['fields']['permit_block'] = array('type' => 'static', 'label' => qa_lang_html('options/permit_block'), 'value' => qa_lang_html('options/permit_moderators'));
     if (!QA_FINAL_EXTERNAL_USERS) {
         $qa_content['form']['fields']['permit_approve_users'] = array('type' => 'static', 'label' => qa_lang_html('options/permit_approve_users'), 'value' => qa_lang_html('options/permit_moderators'));
         $qa_content['form']['fields']['permit_create_experts'] = array('type' => 'static', 'label' => qa_lang_html('options/permit_create_experts'), 'value' => qa_lang_html('options/permit_moderators'));
         $qa_content['form']['fields']['permit_see_emails'] = array('type' => 'static', 'label' => qa_lang_html('options/permit_see_emails'), 'value' => qa_lang_html('options/permit_admins'));
         $qa_content['form']['fields']['permit_delete_users'] = array('type' => 'static', 'label' => qa_lang_html('options/permit_delete_users'), 'value' => qa_lang_html('options/permit_admins'));
                    qa_db_widget_set_fields($widgetid, $intags);
                } else {
                    $widgetid = qa_db_widget_create($intitle, $intags);
                }
                qa_db_widget_move($widgetid, substr($inposition, 0, 2), substr($inposition, 2));
            }
            qa_redirect('admin/layout');
        }
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('admin/admin_title') . ' - ' . qa_lang_html('admin/layout_title');
$qa_content['error'] = $securityexpired ? qa_lang_html('admin/form_security_expired') : qa_admin_page_error();
$positionoptions = array();
$placeoptionhtml = qa_admin_place_options();
$regioncodes = array('F' => 'full', 'M' => 'main', 'S' => 'side');
foreach ($placeoptionhtml as $place => $optionhtml) {
    $region = $regioncodes[substr($place, 0, 1)];
    $widgetallowed = method_exists($module, 'allow_region') && $module->allow_region($region);
    if ($widgetallowed) {
        foreach ($widgets as $widget) {
            if ($widget['place'] == $place && $widget['title'] == $editwidget['title'] && $widget['widgetid'] !== @$editwidget['widgetid']) {
                $widgetallowed = false;
            }
        }
    }
    // don't allow two instances of same widget in same place
    if ($widgetallowed) {
        $previous = null;
        $passedself = false;