Example #1
0
function myalerts_acp_manage_alert_types()
{
    global $mybb, $lang, $page, $db, $cache;
    $alertTypeManager = MybbStuff_MyAlerts_AlertTypeManager::getInstance();
    $alertTypes = $alertTypeManager->getAlertTypes();
    if (strtolower($mybb->request_method) == 'post') {
        if (!verify_post_check($mybb->get_input('my_post_key'))) {
            flash_message($lang->invalid_post_verify_key2, 'error');
            admin_redirect("index.php?module=config-myalerts_alert_types");
        }
        $enabledAlertTypes = $mybb->get_input('alert_types_enabled', MyBB::INPUT_ARRAY);
        $canBeUserDisabled = $mybb->get_input('alert_types_can_be_user_disabled', MyBB::INPUT_ARRAY);
        $enabledAlertTypes = array_map('intval', array_keys($enabledAlertTypes));
        $canBeUserDisabled = array_map('intval', array_keys($canBeUserDisabled));
        $updateArray = array();
        foreach ($alertTypes as $alertType) {
            $type = MybbStuff_MyAlerts_Entity_AlertType::unserialize($alertType);
            $type->setEnabled(in_array($type->getId(), $enabledAlertTypes));
            $type->setCanBeUserDisabled(in_array($type->getId(), $canBeUserDisabled));
            $updateArray[] = $type;
        }
        $alertTypeManager->updateAlertTypes($updateArray);
        flash_message($lang->myalerts_alert_types_updated, 'success');
        admin_redirect("index.php?module=config-myalerts_alert_types");
    } else {
        $page->output_header($lang->myalerts_alert_types);
        $form = new Form('index.php?module=config-myalerts_alert_types', 'post');
        $table = new Table();
        $table->construct_header($lang->myalerts_alert_type_code);
        $table->construct_header($lang->myalerts_alert_type_enabled, array('width' => '5%', 'class' => 'align_center'));
        $table->construct_header($lang->myalerts_alert_type_can_be_user_disabled, array('width' => '10%', 'class' => 'align_center'));
        $noResults = false;
        if (!empty($alertTypes)) {
            foreach ($alertTypes as $type) {
                $alertCode = htmlspecialchars_uni($type['code']);
                $table->construct_cell($alertCode);
                $table->construct_cell($form->generate_check_box('alert_types_enabled[' . $type['id'] . ']', '', '', array('checked' => $type['enabled'])));
                $table->construct_cell($form->generate_check_box('alert_types_can_be_user_disabled[' . $type['id'] . ']', '', '', array('checked' => $type['can_be_user_disabled'])));
                $table->construct_row();
            }
        } else {
            $table->construct_cell($lang->myalerts_no_alert_types, array('colspan' => 2));
            $table->construct_row();
            $noResults = true;
        }
        $table->output($lang->myalerts_alert_types);
        if (!$noResults) {
            $buttons[] = $form->generate_submit_button($lang->myalerts_update_alert_types);
            $form->output_submit_wrapper($buttons);
        }
        $form->end();
        $page->output_footer();
    }
}
Example #2
0
            }
            if ($perms[$calendar_permission] != 1) {
                $all_checked = false;
            }
            if ($perms[$calendar_permission] == 1) {
                $perms_checked[$calendar_permission] = 1;
            } else {
                $perms_checked[$calendar_permission] = 0;
            }
            $all_check .= "\$('#permissions_{$usergroup['gid']}_{$calendar_permission}').prop('checked', this.checked);\n";
            $perm_check .= "\$('#permissions_{$usergroup['gid']}_{$calendar_permission}').prop('checked', {$value});\n";
        }
        $default_click = "if(\$(this).is(':checked')) { {$perm_check} }";
        $reset_default = "if(!\$(this).is(':checked')) { \$('#permissions_{$usergroup['gid']}_all').prop('checked', false); }\n";
        $usergroup['title'] = htmlspecialchars_uni($usergroup['title']);
        $table->construct_cell("<strong>{$usergroup['title']}</strong><br /><small style=\"vertical-align: middle;\">" . $form->generate_check_box("default_permissions[{$usergroup['gid']}];", 1, "", array("id" => "default_permissions_{$usergroup['gid']}", "checked" => $default_checked, "onclick" => $default_click)) . " <label for=\"default_permissions_{$usergroup['gid']}\">{$lang->permissions_use_group_default}</label></small>");
        $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][canviewcalendar]", 1, "", array("id" => "permissions_{$usergroup['gid']}_canviewcalendar", "checked" => $perms_checked['canviewcalendar'], "onclick" => $reset_default)), array('class' => 'align_center'));
        $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][canaddevents]", 1, "", array("id" => "permissions_{$usergroup['gid']}_canaddevents", "checked" => $perms_checked['canaddevents'], "onclick" => $reset_default)), array('class' => 'align_center'));
        $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][canbypasseventmod]", 1, "", array("id" => "permissions_{$usergroup['gid']}_canbypasseventmod", "checked" => $perms_checked['canbypasseventmod'], "onclick" => $reset_default)), array('class' => 'align_center'));
        $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][canmoderateevents]", 1, "", array("id" => "permissions_{$usergroup['gid']}_canmoderateevents", "checked" => $perms_checked['canmoderateevents'], "onclick" => $reset_default)), array('class' => 'align_center'));
        $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][all]", 1, "", array("id" => "permissions_{$usergroup['gid']}_all", "checked" => $all_checked, "onclick" => $all_check)), array('class' => 'align_center'));
        $table->construct_row();
    }
    $table->output("{$lang->calendar_permissions_for} {$calendar['name']}");
    if (!$no_results) {
        $buttons[] = $form->generate_submit_button($lang->save_permissions);
        $form->output_submit_wrapper($buttons);
    }
    $form->end();
    $page->output_footer();
}
Example #3
0
    $page->add_breadcrumb_item($lang->duplicate_theme, "index.php?module=style-themes&amp;action=duplicate&amp;tid={$theme['tid']}");
    $page->output_header("{$lang->themes} - {$lang->duplicate_theme}");
    $sub_tabs['edit_stylesheets'] = array('title' => $lang->edit_stylesheets, 'link' => "index.php?module=style-themes&amp;action=edit&amp;tid={$mybb->input['tid']}");
    $sub_tabs['add_stylesheet'] = array('title' => $lang->add_stylesheet, 'link' => "index.php?module=style-themes&amp;action=add_stylesheet&amp;tid={$mybb->input['tid']}");
    $sub_tabs['export_theme'] = array('title' => $lang->export_theme, 'link' => "index.php?module=style-themes&amp;action=export&amp;tid={$mybb->input['tid']}", 'description' => $lang->export_theme_desc);
    $sub_tabs['duplicate_theme'] = array('title' => $lang->duplicate_theme, 'link' => "index.php?module=style-themes&amp;action=duplicate&amp;tid={$mybb->input['tid']}", 'description' => $lang->duplicate_theme_desc);
    $page->output_nav_tabs($sub_tabs, 'duplicate_theme');
    if ($errors) {
        $page->output_inline_error($errors);
    } else {
        $mybb->input['duplicate_templates'] = true;
    }
    $form = new Form("index.php?module=style-themes&amp;action=duplicate&amp;tid={$theme['tid']}", "post");
    $form_container = new FormContainer($lang->duplicate_theme);
    $form_container->output_row($lang->new_name, $lang->new_name_duplicate_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name');
    $form_container->output_row($lang->advanced_options, "", $form->generate_check_box('duplicate_templates', '1', $lang->duplicate_templates, array('checked' => $mybb->input['duplicate_templates'], 'id' => 'duplicate_templates')) . "<br /><small>{$lang->duplicate_templates_desc}</small>");
    $form_container->end();
    $buttons[] = $form->generate_submit_button($lang->duplicate_theme);
    $form->output_submit_wrapper($buttons);
    $form->end();
    $page->output_footer();
}
if ($mybb->input['action'] == "add") {
    $plugins->run_hooks("admin_style_themes_add");
    $query = $db->simple_select("themes", "tid, name");
    while ($theme = $db->fetch_array($query)) {
        $themes[$theme['tid']] = $theme['name'];
    }
    if ($mybb->request_method == "post") {
        if (!$mybb->input['name']) {
            $errors[] = $lang->error_missing_name;
Example #4
0
     case "username":
         $sort_field = "u.username";
         break;
     default:
         $sort_field = "a.filename";
         $mybb->input['sortby'] = "filename";
 }
 if ($mybb->input['order'] != "desc") {
     $mybb->input['order'] = "asc";
 }
 $page->add_breadcrumb_item($lang->results);
 $page->output_header($lang->index_find_attachments);
 $page->output_nav_tabs($sub_tabs, 'find_attachments');
 $form = new Form("index.php?module=forum-attachments&amp;action=delete", "post");
 $table = new Table();
 $table->construct_header($form->generate_check_box('checkall', '1', '', array('class' => 'checkall')), array('width' => 1));
 $table->construct_header($lang->attachments, array('colspan' => 2));
 $table->construct_header($lang->size, array('width' => '10%', 'class' => 'align_center'));
 $table->construct_header($lang->posted_by, array('width' => '20%', 'class' => 'align_center'));
 $table->construct_header($lang->thread, array('width' => '25%', 'class' => 'align_center'));
 $table->construct_header($lang->downloads, array('width' => '10%', 'class' => 'align_center'));
 $table->construct_header($lang->date_uploaded, array("class" => "align_center"));
 // Fetch matching attachments
 $query = $db->query("\n\t\t\t\tSELECT a.*, p.tid, p.fid, t.subject, p.uid, p.username, u.username AS user_username\n\t\t\t\tFROM " . TABLE_PREFIX . "attachments a\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "posts p ON (p.pid=a.pid)\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=a.uid)\n\t\t\t\tWHERE {$search_sql}\n\t\t\t\tORDER BY {$sort_field} {$mybb->input['order']}\n\t\t\t\tLIMIT {$start}, {$mybb->input['perpage']}\n\t\t\t");
 while ($attachment = $db->fetch_array($query)) {
     build_attachment_row($attachment, $table, true);
 }
 // Need to draw pagination for this result set
 if ($num_results > $mybb->input['perpage']) {
     $pagination_url = "index.php?module=forum-attachments&amp;results=1";
     $pagination_vars = array('perpage', 'sortby', 'order', 'filename', 'mimetype', 'username', 'fid', 'downloads', 'downloads_dir', 'dateuploaded', 'dateuploaded_dir', 'filesize', 'filesize_dir');
Example #5
0
             if ($lang->{$title_lang}) {
                 $optionsexp[1] = $lang->{$title_lang};
             }
             if ($type[0] == "select") {
                 $option_list[$optionsexp[0]] = htmlspecialchars_uni($optionsexp[1]);
             } else {
                 if ($type[0] == "radio") {
                     if ($setting['value'] == $optionsexp[0]) {
                         $option_list[$i] = $form->generate_radio_button($element_name, $optionsexp[0], htmlspecialchars_uni($optionsexp[1]), array('id' => $element_id . '_' . $i, "checked" => 1, 'class' => $element_id));
                     } else {
                         $option_list[$i] = $form->generate_radio_button($element_name, $optionsexp[0], htmlspecialchars_uni($optionsexp[1]), array('id' => $element_id . '_' . $i, 'class' => $element_id));
                     }
                 } else {
                     if ($type[0] == "checkbox") {
                         if ($setting['value'] == $optionsexp[0]) {
                             $option_list[$i] = $form->generate_check_box($element_name, $optionsexp[0], htmlspecialchars_uni($optionsexp[1]), array('id' => $element_id . '_' . $i, "checked" => 1, 'class' => $element_id));
                         } else {
                             $option_list[$i] = $form->generate_check_box($element_name, $optionsexp[0], htmlspecialchars_uni($optionsexp[1]), array('id' => $element_id . '_' . $i, 'class' => $element_id));
                         }
                     }
                 }
             }
         }
         if ($type[0] == "select") {
             $setting_code = $form->generate_select_box($element_name, $option_list, $setting['value'], array('id' => $element_id));
         } else {
             $setting_code = implode("<br />", $option_list);
         }
         $option_list = array();
     }
 }
function PHP_files_cleaner_actions()
{
    global $lang, $mybb, $sub_tabs;
    $lang->load('PHP_files_cleaner_acp');
    $sub_tabs['PHP_files_cleaner'] = array('title' => $lang->PHP_files_cleaner, 'link' => 'index.php?module=tools-system_health&amp;action=clean_PHP_files', 'description' => $lang->PHP_files_cleaner_info);
    if ($mybb->input['action'] == 'do_clean_PHP_files' && $mybb->request_method == 'post') {
        $errors = array();
        $lead = $mybb->get_input('leading', MyBB::INPUT_ARRAY);
        $trail = $mybb->get_input('trailing', MyBB::INPUT_ARRAY);
        if (!$mybb->settings['PHP_files_cleaner_leading'] && !$mybb->settings['PHP_files_cleaner_trailing']) {
            $errors[] = $lang->PHP_files_cleaner_nothing_enabled;
        }
        if (empty($lead) && empty($trail)) {
            $errors[] = $lang->PHP_files_cleaner_nothing_chosen;
        }
        if (!$errors) {
            $leadandtrail = array_unique(array_merge($lead, $trail));
            $nonchangeable = array();
            foreach ($leadandtrail as $filename) {
                $fullfilename = MYBB_ROOT . $filename;
                if (is_readable($fullfilename) && is_writable($fullfilename)) {
                    $file = file_get_contents($fullfilename);
                    // Remove BOM and leading whitespace
                    if ($mybb->settings['PHP_files_cleaner_leading'] && in_array($filename, $lead)) {
                        $file = preg_replace('/^\\x{FEFF}?\\s*/u', '', $file);
                    }
                    // Remove ending tag and trailing whitespace
                    if ($mybb->settings['PHP_files_cleaner_trailing'] && in_array($filename, $trail)) {
                        $file = preg_replace('/(\\s*\\?>)?\\s*$/', '', $file);
                    }
                    file_put_contents($fullfilename, $file);
                } else {
                    $nonchangeable[] = htmlspecialchars_uni($filename);
                }
            }
            if ($nonchangeable) {
                flash_message($lang->sprintf($lang->PHP_files_cleaner_nonchangeable, implode($lang->comma, $nonchangeable)), 'error');
            } else {
                flash_message($lang->PHP_files_cleaner_success, 'success');
            }
            admin_redirect('index.php?module=tools-system_health&amp;action=clean_PHP_files');
        } else {
            $mybb->input['action'] = 'clean_PHP_files';
        }
    }
    if ($mybb->input['action'] == 'clean_PHP_files') {
        global $page;
        $page->add_breadcrumb_item($lang->PHP_files_cleaner);
        $page->output_header($lang->PHP_files_cleaner);
        $page->output_nav_tabs($sub_tabs, 'PHP_files_cleaner');
        if (!empty($errors)) {
            $page->output_inline_error($errors);
        }
        $table = new Table();
        if (!$mybb->settings['PHP_files_cleaner_leading'] && !$mybb->settings['PHP_files_cleaner_trailing']) {
            $table->construct_cell($lang->PHP_files_cleaner_nothing_enabled);
            $table->construct_row();
        } else {
            $leading = $trailing = array();
            $diriterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(MYBB_ROOT));
            $phpfiles = new RegexIterator($diriterator, '/\\.php$/i', RegexIterator::GET_MATCH);
            foreach ($phpfiles as $filename => $info) {
                if (is_readable($filename)) {
                    $contents = file_get_contents($filename);
                    if ($mybb->settings['PHP_files_cleaner_leading'] && preg_match('/^\\x{FEFF}?\\s*/u', $contents, $matches) && $matches[0]) {
                        $leading[] = $filename;
                    }
                    if ($mybb->settings['PHP_files_cleaner_trailing'] && preg_match('/(\\s*\\?>)?\\s*$/', $contents, $matches) && $matches[0]) {
                        $trailing[] = $filename;
                    }
                }
            }
            // Filenames sorted by the number of issues
            $cnt = array_count_values(array_merge($leading, $trailing));
            arsort($cnt);
            $allfiles = array_keys($cnt);
            if (empty($allfiles)) {
                $table->construct_cell($lang->PHP_files_cleaner_nothing_found);
                $table->construct_row();
            } else {
                $form = new Form('index.php?module=tools-system_health&amp;action=do_clean_PHP_files', 'post');
                $table->construct_header($lang->PHP_files_cleaner_filename);
                $table->construct_header($lang->PHP_files_cleaner_leading, array('class' => 'align_center'));
                $table->construct_header($lang->PHP_files_cleaner_trailing, array('class' => 'align_center'));
                $table->construct_header($form->generate_check_box('allbox', 1, '', array('class' => 'checkall', 'checked' => 1)), array('style' => 'text-align: right;'));
                foreach ($allfiles as $filename) {
                    $clean_filename = htmlspecialchars_uni(str_replace(MYBB_ROOT, '', $filename));
                    $leading_cbox = in_array($filename, $leading) ? $form->generate_check_box('leading[]', $clean_filename, '', array('checked' => 1)) : '';
                    $trailing_cbox = in_array($filename, $trailing) ? $form->generate_check_box('trailing[]', $clean_filename, '', array('checked' => 1)) : '';
                    $table->construct_cell($clean_filename);
                    $table->construct_cell($leading_cbox, array('class' => 'align_center'));
                    $table->construct_cell($trailing_cbox, array('class' => 'align_center'));
                    $table->construct_cell('');
                    $table->construct_row();
                }
            }
        }
        $table->output($lang->PHP_files_cleaner);
        if (!empty($allfiles)) {
            $buttons[] = $form->generate_submit_button($lang->PHP_files_cleaner_clean, array('name' => 'clean'));
            $form->output_submit_wrapper($buttons);
            $form->end();
        }
        $page->output_footer();
    }
}
Example #7
0
    $form_container->output_row_header($lang->mass_edit_show_clickable, array("width" => 165));
    $form_container->output_row_header($lang->smilie_delete, array("class" => "align_center", 'width' => '5%'));
    $query = $db->simple_select("smilies", "*", "", array('order_by' => 'disporder'));
    while ($smilie = $db->fetch_array($query)) {
        $smilie['image'] = str_replace("{theme:imgdir}", $theme['imgdir'], $smilie['image']);
        if (my_strpos($smilie['image'], "p://") || substr($smilie['image'], 0, 1) == "/") {
            $image = $smilie['image'];
        } else {
            $image = "../" . $smilie['image'];
        }
        $form_container->output_cell("<img src=\"{$image}\" alt=\"\" />", array("class" => "align_center", "width" => 1));
        $form_container->output_cell($form->generate_text_box("name[{$smilie['sid']}]", $smilie['name'], array('id' => 'name', 'style' => 'width: 98%')));
        $form_container->output_cell($form->generate_text_box("find[{$smilie['sid']}]", $smilie['find'], array('id' => 'find', 'style' => 'width: 95%')));
        $form_container->output_cell($form->generate_text_box("disporder[{$smilie['sid']}]", $smilie['disporder'], array('id' => 'disporder', 'style' => 'width: 80%')));
        $form_container->output_cell($form->generate_yes_no_radio("showclickable[{$smilie['sid']}]", $smilie['showclickable']), array("class" => "align_center"));
        $form_container->output_cell($form->generate_check_box("delete[{$smilie['sid']}]", 1, $mybb->input['delete']), array("class" => "align_center"));
        $form_container->construct_row();
    }
    if ($form_container->num_rows() == 0) {
        $form_container->output_cell($lang->no_smilies, array('colspan' => 6));
        $form_container->construct_row();
    }
    $form_container->end();
    $buttons[] = $form->generate_submit_button($lang->save_smilies);
    $buttons[] = $form->generate_reset_button($lang->reset);
    $form->output_submit_wrapper($buttons);
    $form->end();
    $page->output_footer();
}
if (!$mybb->input['action']) {
    $plugins->run_hooks("admin_config_smilies_start");
Example #8
0
 }
 $tabs = array("general" => $lang->general, "forums_posts" => $lang->forums_posts, "users_permissions" => $lang->users_permissions, "misc" => $lang->misc, "modcp" => $lang->mod_cp);
 $tabs = $plugins->run_hooks("admin_user_groups_edit_graph_tabs", $tabs);
 $page->output_tab_control($tabs);
 echo "<div id=\"tab_general\">";
 $form_container = new FormContainer($lang->general);
 $form_container->output_row($lang->title . " <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 $form_container->output_row($lang->short_description, "", $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
 $form_container->output_row($lang->username_style, $lang->username_style_desc, $form->generate_text_box('namestyle', $mybb->input['namestyle'], array('id' => 'namestyle')), 'namestyle');
 $form_container->output_row($lang->user_title, $lang->user_title_desc, $form->generate_text_box('usertitle', $mybb->input['usertitle'], array('id' => 'usertitle')), 'usertitle');
 $stars = "<table cellpadding=\"3\"><tr><td>" . $form->generate_numeric_field('stars', $mybb->input['stars'], array('class' => 'field50', 'id' => 'stars', 'min' => 0)) . "</td><td>" . $form->generate_text_box('starimage', $mybb->input['starimage'], array('id' => 'starimage')) . "</td></tr>";
 $stars .= "<tr><td><small>{$lang->stars}</small></td><td><small>{$lang->star_image}</small></td></tr></table>";
 $form_container->output_row($lang->user_stars, $lang->user_stars_desc, $stars, "stars");
 $form_container->output_row($lang->group_image, $lang->group_image_desc, $form->generate_text_box('image', $mybb->input['image'], array('id' => 'image')), 'image');
 $general_options = array();
 $general_options[] = $form->generate_check_box("showmemberlist", 1, $lang->member_list, array("checked" => $mybb->input['showmemberlist']));
 if ($usergroup['gid'] != "1" && $usergroup['gid'] != "5") {
     $general_options[] = $form->generate_check_box("showforumteam", 1, $lang->forum_team, array("checked" => $mybb->input['showforumteam']));
 }
 $general_options[] = $form->generate_check_box("isbannedgroup", 1, $lang->is_banned_group, array("checked" => $mybb->input['isbannedgroup']));
 $form_container->output_row($lang->general_options, "", "<div class=\"group_settings_bit\">" . implode("</div><div class=\"group_settings_bit\">", $general_options) . "</div>");
 if ($usergroup['type'] != 1) {
     $public_options = array($form->generate_check_box("joinable", 1, $lang->user_joinable, array("checked" => $mybb->input['joinable'])), $form->generate_check_box("moderate", 1, $lang->moderate_join_requests, array("checked" => $mybb->input['moderate'])), $form->generate_check_box("invite", 1, $lang->invite_only, array("checked" => $mybb->input['invite'])), $form->generate_check_box("candisplaygroup", 1, $lang->can_set_as_display_group, array("checked" => $mybb->input['candisplaygroup'])));
     $form_container->output_row($lang->publicly_joinable_options, "", "<div class=\"group_settings_bit\">" . implode("</div><div class=\"group_settings_bit\">", $public_options) . "</div>");
 }
 $admin_options = array($form->generate_check_box("issupermod", 1, $lang->is_super_mod, array("checked" => $mybb->input['issupermod'])), $form->generate_check_box("canmodcp", 1, $lang->can_access_mod_cp, array("checked" => $mybb->input['canmodcp'])), $form->generate_check_box("cancp", 1, $lang->can_access_admin_cp, array("checked" => $mybb->input['cancp'])));
 $form_container->output_row($lang->moderation_administration_options, "", "<div class=\"group_settings_bit\">" . implode("</div><div class=\"group_settings_bit\">", $admin_options) . "</div>");
 $form_container->end();
 echo "</div>";
 //
 // FORUMS AND POSTS
Example #9
0
            $value = (int) $value;
        }
        unset($value);
    }
    $group_checked = array('all' => '', 'custom' => '', 'none' => '');
    if ($mybb->input['editableby'] == -1) {
        $group_checked['all'] = 'checked="checked"';
    } elseif ($mybb->input['editableby'] != '') {
        $group_checked['custom'] = 'checked="checked"';
    } else {
        $group_checked['none'] = 'checked="checked"';
    }
    print_selection_javascript();
    $select_code = "\n\t<dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\">\n\t\t<dt><label style=\"display: block;\"><input type=\"radio\" name=\"editableby\" value=\"all\" {$group_checked['all']} class=\"editableby_forums_groups_check\" onclick=\"checkAction('editableby');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt>\n\t\t<dt><label style=\"display: block;\"><input type=\"radio\" name=\"editableby\" value=\"custom\" {$group_checked['custom']} class=\"editableby_forums_groups_check\" onclick=\"checkAction('editableby');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt>\n\t\t<dd style=\"margin-top: 4px;\" id=\"editableby_forums_groups_custom\" class=\"editableby_forums_groups\">\n\t\t\t<table cellpadding=\"4\">\n\t\t\t\t<tr>\n\t\t\t\t\t<td valign=\"top\"><small>{$lang->groups_colon}</small></td>\n\t\t\t\t\t<td>" . $form->generate_group_select('select[editableby][]', $selected_values, array('id' => 'editableby', 'multiple' => true, 'size' => 5)) . "</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</dd>\n\t\t<dt><label style=\"display: block;\"><input type=\"radio\" name=\"editableby\" value=\"none\" {$group_checked['none']} class=\"editableby_forums_groups_check\" onclick=\"checkAction('editableby');\" style=\"vertical-align: middle;\" /> <strong>{$lang->none}</strong></label></dt>\n\t</dl>\n\t<script type=\"text/javascript\">\n\t\tcheckAction('editableby');\n\t</script>";
    $form_container->output_row($lang->editableby, $lang->editableby_desc, $select_code, '', array(), array('id' => 'row_editableby'));
    $parser_options = array($form->generate_check_box('allowhtml', 1, $lang->parse_allowhtml, array('checked' => $mybb->input['allowhtml'], 'id' => 'allowhtml')), $form->generate_check_box('allowmycode', 1, $lang->parse_allowmycode, array('checked' => $mybb->input['allowmycode'], 'id' => 'allowmycode')), $form->generate_check_box('allowsmilies', 1, $lang->parse_allowsmilies, array('checked' => $mybb->input['allowsmilies'], 'id' => 'allowsmilies')), $form->generate_check_box('allowimgcode', 1, $lang->parse_allowimgcode, array('checked' => $mybb->input['allowimgcode'], 'id' => 'allowimgcode')), $form->generate_check_box('allowvideocode', 1, $lang->parse_allowvideocode, array('checked' => $mybb->input['allowvideocode'], 'id' => 'allowvideocode')));
    $form_container->output_row($lang->parser_options, '', implode('<br />', $parser_options), '', array(), array('id' => 'row_parser_options'));
    $form_container->end();
    $buttons[] = $form->generate_submit_button($lang->save_profile_field);
    $form->output_submit_wrapper($buttons);
    $form->end();
    echo '<script type="text/javascript" src="./jscripts/peeker.js?ver=1804"></script>
	<script type="text/javascript">
		$(document).ready(function() {
				new Peeker($("#fieldtype"), $("#row_maxlength, #row_regex, #row_parser_options"), /text|textarea/);
				new Peeker($("#fieldtype"), $("#row_fieldlength"), /select|multiselect/);
				new Peeker($("#fieldtype"), $("#row_options"), /select|radio|checkbox/);
				// Add a star to the extra row since the "extra" is required if the box is shown
				add_star("row_maxlength");
				add_star("row_fieldlength");
				add_star("row_options");
Example #10
0
function threadfields_add_edit_handler(&$tf, $update)
{
    global $mybb, $page, $lang, $db, $plugins, $sub_tabs;
    global $form;
    if ($update) {
        $title = $lang->edit_threadfield;
    } else {
        $title = $lang->add_threadfield;
    }
    $props = xthreads_threadfields_props();
    if ($mybb->request_method == 'post') {
        foreach ($props as $field => &$prop) {
            if ($field == 'field') {
                $field = 'newfield';
            }
            // cause you can't "continue" in a switch statement, lol...
            if ($field == 'forums' || $field == 'editable_gids' || $field == 'viewable_gids' || $field == 'filemaxsize' || $field == 'multival') {
                continue;
            }
            if ($prop['datatype'] == 'string') {
                $mybb->input[$field] = trim($mybb->input[$field]);
            } else {
                $mybb->input[$field] = (int) $mybb->input[$field];
            }
        }
        $mybb->input['textmask'] = str_replace("", '', $mybb->input['textmask']);
        $mybb->input['filemaxsize'] = xthreads_size_to_bytes($mybb->input['filemaxsize']);
        $mybb->input['fileimage_mindim'] = strtolower(trim($mybb->input['fileimage_mindim']));
        $mybb->input['fileimage_maxdim'] = strtolower(trim($mybb->input['fileimage_maxdim']));
        if (!xthreads_empty($mybb->input['formatmap'])) {
            $fm = array();
            $fms = str_replace("{\n}", "\r", str_replace("\r", '', $mybb->input['formatmap']));
            foreach (explode("\n", $fms) as $map) {
                $map = str_replace("\r", "\n", $map);
                $p = strpos($map, '{|}');
                if (!$p) {
                    continue;
                }
                // can't be zero index either - blank display format used for that
                $fmkey = substr($map, 0, $p);
                if (isset($fm[$fmkey])) {
                    $errors[] = $lang->sprintf($lang->error_dup_formatmap, htmlspecialchars_uni($fmkey));
                    unset($fm);
                    break;
                }
                $fm[$fmkey] = substr($map, $p + 3);
            }
            if (isset($fm)) {
                $mybb->input['formatmap'] = serialize($fm);
            }
        }
        if (is_array($mybb->input['forums'])) {
            $mybb->input['forums'] = implode(',', array_unique(array_map('intval', array_map('trim', $mybb->input['forums']))));
            if (empty($mybb->input['forums'])) {
                $mybb->input['forums'] = '';
            }
        } else {
            $mybb->input['forums'] = trim($mybb->input['forums']);
            if ($mybb->input['forums']) {
                $mybb->input['forums'] = implode(',', array_unique(array_map('intval', array_map('trim', explode(',', $mybb->input['forums'])))));
            }
            if (!$mybb->input['forums']) {
                $mybb->input['forums'] = '';
            }
        }
        if ($mybb->input['editable'] == '99') {
            if (is_array($mybb->input['editable_gids'])) {
                $mybb->input['editable_gids'] = implode(',', array_unique(array_map('intval', array_map('trim', $mybb->input['editable_gids']))));
                if (empty($mybb->input['editable_gids'])) {
                    $mybb->input['editable_gids'] = '';
                }
            } else {
                $mybb->input['editable_gids'] = trim($mybb->input['editable_gids']);
                if ($mybb->input['editable_gids']) {
                    $mybb->input['editable_gids'] = implode(',', array_unique(array_map('intval', array_map('trim', explode(',', $mybb->input['editable_gids'])))));
                }
                if (!$mybb->input['editable_gids']) {
                    $mybb->input['editable_gids'] = '';
                }
            }
            if ($mybb->input['editable_gids']) {
                $mybb->input['editable'] = 0;
            } else {
                $mybb->input['editable'] = XTHREADS_EDITABLE_NONE;
            }
            // no group ids selected
        } else {
            $mybb->input['editable'] = min_max((int) $mybb->input['editable'], XTHREADS_EDITABLE_ALL, XTHREADS_EDITABLE_NONE);
            $mybb->input['editable_gids'] = '';
        }
        $mybb->input['hidefield'] = 0;
        foreach (array('input' => XTHREADS_HIDE_INPUT, 'thread' => XTHREADS_HIDE_THREAD) as $k => $v) {
            if ($mybb->input['hidefield_' . $k]) {
                $mybb->input['hidefield'] |= $v;
            }
        }
        if (!xthreads_empty($mybb->input['editable_values'])) {
            $ev = array();
            $evs = str_replace("{\n}", "\r", str_replace("\r", '', $mybb->input['editable_values']));
            foreach (explode("\n", $evs) as $editable_value) {
                $editable_value = str_replace("\r", "\n", $editable_value);
                $p = strpos($editable_value, '{|}');
                if ($p === false) {
                    continue;
                }
                $evkey = substr($editable_value, 0, $p);
                if (isset($ev[$evkey])) {
                    $errors[] = $lang->sprintf($lang->error_dup_editable_value, htmlspecialchars_uni($evkey));
                    unset($ev);
                    break;
                }
                $ev[$evkey] = array_unique(array_map('intval', explode(',', substr($editable_value, $p + 3))));
                // remove '0' element
                if (($zerorm = array_search(0, $ev[$evkey])) !== false) {
                    unset($ev[$evkey][$zerorm]);
                }
            }
            if (isset($ev)) {
                $mybb->input['editable_values'] = serialize($ev);
            }
        }
        if (is_array($mybb->input['viewable_gids'])) {
            $mybb->input['viewable_gids'] = implode(',', array_unique(array_map('intval', array_map('trim', $mybb->input['viewable_gids']))));
            if (empty($mybb->input['viewable_gids'])) {
                $mybb->input['viewable_gids'] = '';
            }
        } else {
            $mybb->input['viewable_gids'] = trim($mybb->input['viewable_gids']);
            if ($mybb->input['viewable_gids']) {
                $mybb->input['viewable_gids'] = implode(',', array_unique(array_map('intval', array_map('trim', explode(',', $mybb->input['viewable_gids'])))));
            }
            if (!$mybb->input['viewable_gids']) {
                $mybb->input['viewable_gids'] = '';
            }
        }
        $mybb->input['sanitize'] = min_max((int) $mybb->input['sanitize'], XTHREADS_SANITIZE_HTML, XTHREADS_SANITIZE_NONE);
        //if($mybb->input['sanitize'] == XTHREADS_SANITIZE_PARSER) {
        $parser_opts = array('parser_nl2br' => XTHREADS_SANITIZE_PARSER_NL2BR, 'parser_nobadw' => XTHREADS_SANITIZE_PARSER_NOBADW, 'parser_html' => XTHREADS_SANITIZE_PARSER_HTML, 'parser_mycode' => XTHREADS_SANITIZE_PARSER_MYCODE, 'parser_mycodeimg' => XTHREADS_SANITIZE_PARSER_MYCODEIMG, 'parser_mycodevid' => XTHREADS_SANITIZE_PARSER_VIDEOCODE, 'parser_smilies' => XTHREADS_SANITIZE_PARSER_SMILIES);
        foreach ($parser_opts as $opt => $n) {
            if ($mybb->input[$opt]) {
                $mybb->input['sanitize'] |= $n;
            }
        }
        //}
        $mybb->input['inputtype'] = min_max((int) $mybb->input['inputtype'], XTHREADS_INPUT_TEXT, XTHREADS_INPUT_FILE_URL);
        if (xthreads_empty($mybb->input['title'])) {
            $errors[] = $lang->error_missing_title;
        }
        if (xthreads_empty($mybb->input['newfield'])) {
            $errors[] = $lang->error_missing_field;
        }
        if (!xthreads_empty($mybb->input['textmask'])) {
            // test for bad regex
            xthreads_catch_errorhandler();
            @preg_match('~' . str_replace('~', '\\~', $mybb->input['textmask']) . '~si', 'testvalue');
            restore_error_handler();
            if (!empty($GLOBALS['_previous_error'])) {
                $errmsg =& $GLOBALS['_previous_error'][1];
                if (substr($errmsg, 0, 12) == 'preg_match()') {
                    $p = strpos($errmsg, ':', 12);
                    if ($p) {
                        $errmsg = trim(substr($errmsg, $p + 1));
                    } else {
                        $errmsg = trim(substr($errmsg, 12));
                    }
                    $errors[] = $lang->sprintf($lang->error_bad_textmask, $errmsg);
                }
            }
        }
        switch ($mybb->input['inputtype']) {
            case XTHREADS_INPUT_SELECT:
            case XTHREADS_INPUT_RADIO:
            case XTHREADS_INPUT_CHECKBOX:
                $mybb->input['sanitize'] = $mybb->input['inputtype'] == XTHREADS_INPUT_SELECT ? XTHREADS_SANITIZE_HTML : XTHREADS_SANITIZE_NONE;
                $mybb->input['textmask'] = '';
                // must have value defined
                if (xthreads_empty($mybb->input['vallist'])) {
                    $errors[] = $lang->error_require_valllist;
                }
                break;
            case XTHREADS_INPUT_TEXTAREA:
            case XTHREADS_INPUT_FILE:
            case XTHREADS_INPUT_FILE_URL:
                $mybb->input['allowfilter'] = 0;
                $mybb->input['vallist'] = '';
                break;
            case XTHREADS_INPUT_TEXT:
                $mybb->input['vallist'] = '';
        }
        if ($mybb->input['multival_enable'] || $mybb->input['inputtype'] == XTHREADS_INPUT_CHECKBOX) {
            if (xthreads_empty($mybb->input['multival'])) {
                $errors[] = $lang->error_require_multival_delimiter;
            }
            // force textual datatype
            if ($mybb->input['datatype'] !== XTHREADS_DATATYPE_TEXT) {
                $mybb->input['datatype'] = XTHREADS_DATATYPE_TEXT;
            }
        } else {
            $mybb->input['multival'] = '';
        }
        if ($mybb->input['use_formhtml']) {
            if (xthreads_empty($mybb->input['formhtml'])) {
                $errors[] = $lang->error_require_formhtml;
            }
        } else {
            $mybb->input['formhtml'] = '';
        }
        if ($mybb->input['datatype'] !== XTHREADS_DATATYPE_TEXT) {
            // verify value list if applicable
            /* if($mybb->input['inputtype'] == XTHREADS_INPUT_SELECT || $mybb->input['inputtype'] == XTHREADS_INPUT_RADIO) {
            				// maybe we won't do this...
            			} */
            $mybb->input['datatype'] = min_max($mybb->input['datatype'], XTHREADS_DATATYPE_TEXT, XTHREADS_DATATYPE_FLOAT);
        }
        $mybb->input['fileimage'] = '';
        if ($mybb->input['filereqimg']) {
            if ($mybb->input['fileimage_mindim'] && !preg_match('~^[0-9]+x[0-9]+$~', $mybb->input['fileimage_mindim'])) {
                $errors[] = $lang->error_invalid_min_dims;
            }
            if ($mybb->input['fileimage_maxdim'] && !preg_match('~^[0-9]+x[0-9]+$~', $mybb->input['fileimage_maxdim'])) {
                $errors[] = $lang->error_invalid_max_dims;
            }
            if ($mybb->input['fileimage_mindim']) {
                $mybb->input['fileimage'] = $mybb->input['fileimage_mindim'];
            } else {
                $mybb->input['fileimage'] = '0x0';
            }
            if ($mybb->input['fileimage_maxdim']) {
                $mybb->input['fileimage'] .= '|' . $mybb->input['fileimage_maxdim'];
            }
        }
        //if($mybb->input['fileimgthumbs']) {
        // TODO: verify format
        //if(!preg_match('~^[0-9]+x[0-9]+(\\|[0-9]+x[0-9]+)*$~', $mybb->input['fileimgthumbs']))
        //	$errors[] = $lang->error_invalid_thumb_dims;
        //}
        if ($update) {
            // check that sent field name is valid
            // and whilst we're here, check for bad conversions (eg file -> textbox)
            $oldfield = $db->fetch_array($db->simple_select('threadfields', '*', 'field="' . $db->escape_string($mybb->input['field']) . '"'));
            if (empty($oldfield)) {
                $errors[] = $lang->error_bad_old_field;
            } else {
                switch ($oldfield['inputtype']) {
                    case XTHREADS_INPUT_FILE:
                    case XTHREADS_INPUT_FILE_URL:
                        if ($oldfield['inputtype'] != $mybb->input['inputtype']) {
                            $errors['error_invalid_inputtype'] = $lang->error_invalid_inputtype;
                        }
                        break;
                    default:
                        if ($mybb->input['inputtype'] == XTHREADS_INPUT_FILE || $mybb->input['inputtype'] == XTHREADS_INPUT_FILE_URL) {
                            $errors['error_invalid_inputtype'] = $lang->error_invalid_inputtype;
                        }
                }
            }
        }
        if (!xthreads_empty($mybb->input['newfield'])) {
            if ($mybb->input['newfield'] == 'tid') {
                $errors[] = $lang->error_field_name_tid;
            } elseif (strlen($mybb->input['newfield']) > 50) {
                $errors[] = $lang->error_field_name_too_long;
            } elseif (!preg_match('~^[a-zA-Z0-9_]+$~', $mybb->input['newfield'])) {
                $errors[] = $lang->error_field_name_invalid;
            } elseif (isset($mybb->input['newfield'][2]) && $mybb->input['newfield'][0] == '_' && $mybb->input['newfield'][1] == '_') {
                // don't allow fields starting with "__" (reserved for special use)
                // in hindsight, special uses (eg filters) really should've used something like '~' so we don't need to do this, but it's too late now
                $errors[] = $lang->error_field_name_reserved;
            } elseif (!$update || $mybb->input['field'] != $mybb->input['newfield']) {
                $ftest = $db->fetch_field($db->simple_select('threadfields', 'field', 'field="' . $db->escape_string($mybb->input['newfield']) . '"'), 'field');
                if (!xthreads_empty($ftest)) {
                    $errors[] = $lang->error_field_name_in_use;
                }
            }
        }
        // check for syntax errors in conditionals
        // this is a bit tricky because we need the cache function to build the conditional for checking
        if ($update) {
            $test_tf = array_merge($oldfield, $mybb->input);
        } else {
            $test_tf = $mybb->input;
        }
        xthreads_buildtfcache_parseitem($test_tf);
        // test for bad conditional syntax
        foreach (array('defaultval', 'blankval', 'inputformat', 'inputvalidate', 'dispformat', 'dispitemformat', 'unviewableval', 'formhtml', 'formhtml_item') as $condcheck) {
            if ($test_tf[$condcheck] && !xthreads_check_evalstr($test_tf[$condcheck])) {
                if ($condcheck == 'formhtml_item') {
                    $condcheck = 'formhtml';
                }
                $tflangkey = 'threadfields_' . $condcheck;
                $errors[] = $lang->sprintf($lang->error_bad_conditional, $lang->{$tflangkey});
            }
        }
        if (!xthreads_empty($test_tf['formatmap'])) {
            foreach ($test_tf['formatmap'] as &$fm) {
                if ($fm && !xthreads_check_evalstr($fm)) {
                    $errors[] = $lang->sprintf($lang->error_bad_conditional, $lang->threadfields_formatmap);
                    break;
                }
            }
        }
        if (!xthreads_empty($test_tf['fileimgthumbs'])) {
            foreach ($test_tf['fileimgthumbs'] as $thumb => $chain) {
                if ($chain) {
                    if (!xthreads_check_evalstr('".$img->' . $chain . '."')) {
                        $errors[] = $lang->sprintf($lang->error_bad_conditional, $lang->threadfields_fileimgthumbs);
                        break;
                    }
                }
            }
        }
        if (!$errors) {
            $new_tf = array();
            foreach (array_keys($props) as $field) {
                if ($field == 'field') {
                    $new_tf[$field] = $db->escape_string($mybb->input['newfield']);
                } else {
                    $new_tf[$field] = $db->escape_string($mybb->input[$field]);
                }
            }
            if ($mybb->input['inputtype'] == XTHREADS_INPUT_FILE) {
                if (xthreads_empty($mybb->input['multival'])) {
                    $fieldtype = xthreads_db_fielddef('int', null, true) . ' not null default 0';
                } else {
                    $fieldtype = 'varchar(255) not null default ""';
                }
                // we'll stick a hard limit of 25 files
            } elseif ($mybb->input['inputtype'] == XTHREADS_INPUT_FILE_URL) {
                $fieldtype = 'varchar(255) not null default ""';
            } else {
                switch ($new_tf['datatype']) {
                    case XTHREADS_DATATYPE_INT:
                    case XTHREADS_DATATYPE_UINT:
                        $fieldtype = xthreads_db_fielddef('int', null, $new_tf['datatype'] == XTHREADS_DATATYPE_UINT) . ' default null';
                        break;
                    case XTHREADS_DATATYPE_BIGINT:
                    case XTHREADS_DATATYPE_BIGUINT:
                        $fieldtype = xthreads_db_fielddef('bigint', null, $new_tf['datatype'] == XTHREADS_DATATYPE_BIGUINT) . ' default null';
                        break;
                    case XTHREADS_DATATYPE_FLOAT:
                        $fieldtype = 'double default null';
                        break;
                    default:
                        switch ($mybb->input['inputtype']) {
                            case XTHREADS_INPUT_TEXTAREA:
                                $fieldtype = 'text not null';
                                break;
                            case XTHREADS_INPUT_SELECT:
                            case XTHREADS_INPUT_RADIO:
                                if ($new_tf['multival'] === '' || $mybb->input['inputtype'] == XTHREADS_INPUT_RADIO) {
                                    $fieldtype = 'varchar(255) not null default ""';
                                    $using_long_varchar = false;
                                    break;
                                }
                            default:
                                if ($new_tf['allowfilter']) {
                                    // initially, try 1024 chars
                                    $fieldtype = 'varchar(1024) not null default ""';
                                    $using_long_varchar = true;
                                } else {
                                    $fieldtype = 'text not null';
                                }
                        }
                }
            }
            if ($update) {
                $plugins->run_hooks('admin_config_threadfields_edit_commit');
                $db->update_query('threadfields', $new_tf, 'field="' . $db->escape_string($mybb->input['field']) . '"');
                $alterations = array();
                // TODO: perhaps only run this query if necessary
                //if($mybb->input['field'] != $mybb->input['newfield'])
                $alterfield_base = 'CHANGE `' . $db->escape_string($mybb->input['field']) . '` `' . $new_tf['field'] . '` ';
                $alterations['field'] = $alterfield_base . $fieldtype;
                if ((bool) $new_tf['allowfilter'] != (bool) $oldfield['allowfilter']) {
                    if ($new_tf['allowfilter']) {
                        $alterations['addkey'] = 'ADD KEY `' . $new_tf['field'] . '` (`' . $new_tf['field'] . '`)';
                    } else {
                        $alterations['dropkey'] = 'DROP KEY `' . $db->escape_string($mybb->input['field']) . '`';
                    }
                } elseif ($new_tf['allowfilter'] && $mybb->input['field'] != $mybb->input['newfield']) {
                    // change key name - only way to do this in MySQL appears to be recreating the key...
                    $alterations['dropkey'] = 'DROP KEY `' . $db->escape_string($mybb->input['field']) . '`';
                    $alterations['addkey'] = 'ADD KEY `' . $new_tf['field'] . '` (`' . $new_tf['field'] . '`)';
                }
                if (!empty($alterations)) {
                    $qry_base = 'ALTER TABLE `' . $db->table_prefix . 'threadfields_data` ';
                    if ($using_long_varchar) {
                        if (!$db->write_query($qry_base . implode(', ', $alterations), true)) {
                            $alterations['field'] = $alterfield_base . str_replace('varchar(1024)', 'varchar(255)', $fieldtype);
                            $db->write_query($qry_base . implode(', ', $alterations));
                        }
                    } else {
                        $db->write_query($qry_base . implode(', ', $alterations));
                    }
                    if ($mybb->input['field'] != $mybb->input['newfield'] && ($new_tf['inputtype'] == XTHREADS_INPUT_FILE || $new_tf['inputtype'] == XTHREADS_INPUT_FILE_URL)) {
                        // need to update xtattachments table too!
                        $db->update_query('xtattachments', array('field' => $new_tf['field']), 'field="' . $db->escape_string($mybb->input['field']) . '"');
                    }
                }
            } else {
                $plugins->run_hooks('admin_config_threadfields_add_commit');
                $db->insert_query('threadfields', $new_tf);
                $addkey = '';
                if ($new_tf['allowfilter']) {
                    $addkey .= ', ADD KEY (`' . $new_tf['field'] . '`)';
                }
                $qry_base = 'ALTER TABLE `' . $db->table_prefix . 'threadfields_data` ADD COLUMN `' . $new_tf['field'] . '` ';
                if ($using_long_varchar) {
                    if (!$db->write_query($qry_base . $fieldtype . $addkey, true)) {
                        $db->write_query($qry_base . str_replace('varchar(1024)', 'varchar(255)', $fieldtype) . $addkey);
                    }
                } else {
                    $db->write_query($qry_base . $fieldtype . $addkey);
                }
            }
            // Log admin action
            log_admin_action($new_tf['field'], htmlspecialchars_uni($mybb->input['title']));
            xthreads_buildtfcache();
            if ($update) {
                flash_message($lang->success_updated_threadfield, 'success');
            } else {
                flash_message($lang->success_added_threadfield, 'success');
            }
            admin_redirect(xthreads_admin_url('config', 'threadfields'));
        }
    }
    $page->add_breadcrumb_item($title);
    $page->output_header($lang->custom_threadfields . ' - ' . $title);
    echo '<noscript>';
    $page->output_alert($lang->threadfields_enable_js);
    echo '</noscript>';
    if (!$update) {
        $page->output_nav_tabs($sub_tabs, 'threadfields_add');
    }
    if ($update) {
        $form = new Form(xthreads_admin_url('config', 'threadfields') . '&amp;action=edit&amp;field=' . urlencode($tf['field']), 'post');
    } else {
        $form = new Form(xthreads_admin_url('config', 'threadfields&amp;action=add'), 'post');
    }
    if ($errors) {
        $page->output_inline_error($errors);
        $GLOBALS['data'] =& $mybb->input;
    } else {
        $GLOBALS['data'] =& $tf;
    }
    global $data;
    global $form_container;
    $form_container = new FormContainer($title);
    $form_container->output_row($lang->threadfields_title . ' <em>*</em>', $lang->threadfields_title_desc, $form->generate_text_box('title', $data['title'], array('id' => 'title')), 'title');
    if (isset($data['newfield'])) {
        $key =& $data['newfield'];
    } else {
        $key =& $data['field'];
    }
    $form_container->output_row($lang->threadfields_name . ' <em>*</em>', $lang->threadfields_name_desc, $form->generate_text_box('newfield', $key, array('id' => 'newfield')), 'newfield');
    if ($data['forums'] && !is_array($data['forums'])) {
        $data['forums'] = array_map('intval', array_map('trim', explode(',', $data['forums'])));
    }
    $form_container->output_row($lang->threadfields_forums, $lang->threadfields_forums_desc, $form->generate_forum_select('forums[]', $data['forums'], array('multiple' => true, 'size' => 5)), 'forums');
    $hidefield_boxes = '';
    foreach (array('input' => XTHREADS_HIDE_INPUT, 'thread' => XTHREADS_HIDE_THREAD) as $k => $v) {
        $l = 'threadfields_hidefield_' . $k;
        $ld = 'threadfields_hidefield_' . $k . '_desc';
        $hidefield_boxes .= $form->generate_check_box('hidefield_' . $k, '1', $lang->{$l}, array('checked' => (bool) ($data['hidefield'] & $v))) . '<div style="margin-left: 2.25em;" class="description">' . $lang->{$ld} . '</div>';
    }
    $form_container->output_row($lang->threadfields_hidefield, $lang->threadfields_hidefield_desc, $hidefield_boxes, 'hidefield');
    $inputtypes = array(XTHREADS_INPUT_TEXT => $lang->threadfields_inputtype_text, XTHREADS_INPUT_TEXTAREA => $lang->threadfields_inputtype_textarea, XTHREADS_INPUT_SELECT => $lang->threadfields_inputtype_select, XTHREADS_INPUT_RADIO => $lang->threadfields_inputtype_radio, XTHREADS_INPUT_CHECKBOX => $lang->threadfields_inputtype_checkbox, XTHREADS_INPUT_FILE => $lang->threadfields_inputtype_file);
    if ($update) {
        // disable some conversions as they are not possible
        if (isset($errors['error_invalid_inputtype'])) {
            // but if invalid type is supplied, don't lock the user in either
            $inputtype = $oldfield['inputtype'];
        } else {
            $inputtype = $data['inputtype'];
        }
        if ($inputtype == XTHREADS_INPUT_FILE || $inputtype == XTHREADS_INPUT_FILE_URL) {
            foreach ($inputtypes as $k => &$v) {
                if ($k != $inputtype) {
                    unset($inputtypes[$k]);
                }
            }
        } else {
            unset($inputtypes[XTHREADS_INPUT_FILE], $inputtypes[XTHREADS_INPUT_FILE_URL]);
        }
    }
    // TODO: weird issue where inputtype isn't being set...
    if (!ini_get('file_uploads')) {
        $lang->threadfields_file_name_info .= '<div style="color: red; font-style: italic;">' . $lang->threadfields_file_upload_disabled_warning . '</div>';
    }
    make_form_row('inputtype', 'select_box', $inputtypes, '<div id="inputtype_file_explain" style="font-size: 0.95em; margin-top: 1em;">' . $lang->threadfields_file_name_info . '</div>');
    make_form_row('disporder', 'text_box');
    $form_container->end();
    unset($GLOBALS['form_container']);
    global $form_container;
    $form_container = new FormContainer($lang->threadfields_cat_input);
    if ($data['editable_gids'] && !is_array($data['editable_gids'])) {
        $data['editable_gids'] = array_map('intval', array_map('trim', explode(',', $data['editable_gids'])));
    }
    if (!empty($data['editable_gids'])) {
        $data['editable'] = 99;
    }
    make_form_row('editable', 'select_box', array(XTHREADS_EDITABLE_ALL => $lang->threadfields_editable_everyone, XTHREADS_EDITABLE_REQ => $lang->threadfields_editable_requied, XTHREADS_EDITABLE_MOD => $lang->threadfields_editable_mod, XTHREADS_EDITABLE_ADMIN => $lang->threadfields_editable_admin, XTHREADS_EDITABLE_NONE => $lang->threadfields_editable_none, 99 => $lang->threadfields_editable_bygroup));
    $form_container->output_row($lang->threadfields_editable_gids, $lang->threadfields_editable_gids_desc, xt_generate_group_select('editable_gids[]', $data['editable_gids'], array('multiple' => true, 'size' => 5)), 'editable_gids', array(), array('id' => 'row_editable_gids'));
    make_form_row('maxlen', 'text_box');
    make_form_row('vallist', 'text_area');
    make_form_row('fileexts', 'text_box');
    if (!is_int(2147483648)) {
        // detect 32-bit PHP
        $lang->threadfields_filemaxsize_desc .= $lang->threadfields_filemaxsize_desc_2gbwarn;
    }
    // PHP upload limits
    $upload_max_filesize = @ini_get('upload_max_filesize');
    $post_max_size = @ini_get('post_max_size');
    // TODO: maybe also pull in [ file_uploads, max_file_uploads, max_input_time ] ?
    if ($upload_max_filesize || $post_max_size) {
        $lang->threadfields_filemaxsize_desc .= '<br /><br />' . $lang->threadfields_filemaxsize_desc_phplimit;
        if (!$lang->limit_upload_max_filesize) {
            $lang->load('config_attachment_types');
        }
        if ($upload_max_filesize) {
            $lang->threadfields_filemaxsize_desc .= '<br />' . $lang->sprintf($lang->limit_upload_max_filesize, $upload_max_filesize);
        }
        if ($post_max_size) {
            $lang->threadfields_filemaxsize_desc .= '<br />' . $lang->sprintf($lang->limit_post_max_size, $post_max_size);
        }
    }
    make_form_row('filemaxsize', 'text_box');
    make_form_row('filemagic', 'text_box');
    $data['filereqimg'] = $data['fileimage'] ? 1 : 0;
    if (!function_exists('imagecreate')) {
        $lang->threadfields_filereqimg_desc .= $lang->threadfields_filereqimg_desc_nogd;
    }
    make_form_row('filereqimg', 'yes_no_radio');
    unset($data['filereqimg']);
    $data['fileimage_mindim'] = $data['fileimage_maxdim'] = '';
    if ($data['fileimage']) {
        list($min, $max) = explode('|', $data['fileimage']);
        if ($min === '0x0') {
            $min = '';
        }
        $data['fileimage_mindim'] = $min;
        $data['fileimage_maxdim'] = $max;
    }
    make_form_row('fileimage_mindim', 'text_box');
    make_form_row('fileimage_maxdim', 'text_box');
    unset($data['fileimage_mindim'], $data['fileimage_maxdim']);
    make_form_row('fileimgthumbs', 'text_box');
    $data['multival_enable'] = $data['multival'] !== '' ? 1 : 0;
    make_form_row('multival_enable', 'yes_no_radio');
    unset($data['multival_enable']);
    make_form_row('multival_limit', 'text_box');
    make_form_row('textmask', 'text_box');
    make_form_row('inputformat', 'text_area', array('style' => 'font-family: monospace'));
    make_form_row('inputvalidate', 'text_area', array('style' => 'font-family: monospace'));
    if (!is_array($data['editable_values'])) {
        $ev = @unserialize($data['editable_values']);
        if (is_array($ev)) {
            $data['editable_values'] =& $ev;
        }
    }
    if (is_array($data['editable_values'])) {
        $evtxt = '';
        foreach ($data['editable_values'] as $k => &$v) {
            // don't need to htmlspecialchar - it'll be done for us
            $evtxt .= str_replace("\n", "{\n}", $k) . '{|}' . implode(',', $v) . "\n";
        }
        $data['editable_values'] =& $evtxt;
    }
    make_form_row('editable_values', 'text_area', array('style' => 'font-family: monospace'));
    $form_container->end();
    unset($GLOBALS['form_container']);
    global $form_container;
    $form_container = new FormContainer($lang->threadfields_cat_inputfield);
    make_form_row('desc', 'text_box');
    make_form_row('defaultval', 'text_area', array('style' => 'font-family: monospace'));
    make_form_row('fieldwidth', 'text_box');
    make_form_row('fieldheight', 'text_box');
    make_form_row('tabstop', 'yes_no_radio');
    $data['use_formhtml'] = $data['formhtml'] !== '' ? 1 : 0;
    make_form_row('use_formhtml', 'yes_no_radio');
    unset($data['use_formhtml']);
    $lang->threadfields_formhtml .= ' <em>*</em>';
    make_form_row('formhtml', 'text_area', array('style' => 'font-family: monospace'));
    $form_container->end();
    unset($GLOBALS['form_container']);
    global $form_container;
    $form_container = new FormContainer($lang->threadfields_cat_output);
    $sanitize = $data['sanitize'];
    $data['sanitize'] &= XTHREADS_SANITIZE_MASK;
    make_form_row('sanitize', 'select_box', array(XTHREADS_SANITIZE_HTML => $lang->threadfields_sanitize_plain, XTHREADS_SANITIZE_HTML_NL => $lang->threadfields_sanitize_plain_nl, XTHREADS_SANITIZE_PARSER => $lang->threadfields_sanitize_mycode, XTHREADS_SANITIZE_NONE => $lang->threadfields_sanitize_none));
    $parser_opts = array('parser_nl2br' => $sanitize & XTHREADS_SANITIZE_PARSER_NL2BR, 'parser_nobadw' => $sanitize & XTHREADS_SANITIZE_PARSER_NOBADW, 'parser_html' => $sanitize & XTHREADS_SANITIZE_PARSER_HTML, 'parser_mycode' => $sanitize & XTHREADS_SANITIZE_PARSER_MYCODE, 'parser_mycodeimg' => $sanitize & XTHREADS_SANITIZE_PARSER_MYCODEIMG, 'parser_mycodevid' => $sanitize & XTHREADS_SANITIZE_PARSER_VIDEOCODE, 'parser_smilies' => $sanitize & XTHREADS_SANITIZE_PARSER_SMILIES);
    if ($mybb->version_code < 1600) {
        unset($parser_opts['parser_mycodevid']);
    }
    $parser_opts_str = '';
    foreach ($parser_opts as $opt => $checked) {
        $langstr = 'threadfields_sanitize_' . $opt;
        $parser_opts_str .= '<div style="display: block;">' . $form->generate_check_box($opt, 1, $lang->{$langstr}, array('checked' => $checked ? 1 : 0)) . '</div>';
    }
    $form_container->output_row($lang->threadfields_sanitize_parser, $lang->threadfields_sanitize_parser_desc, $parser_opts_str, 'sanitize_parser', array(), array('id' => 'parser_opts'));
    make_form_row('blankval', 'text_area', array('style' => 'font-family: monospace'));
    make_form_row('dispformat', 'text_area', array('style' => 'font-family: monospace'));
    $lang->threadfields_multival .= ' <em>*</em>';
    make_form_row('multival', 'text_box');
    $lang->threadfields_multival = substr($lang->threadfields_multival, 0, -11);
    make_form_row('dispitemformat', 'text_area', array('style' => 'font-family: monospace'));
    if (!is_array($data['formatmap'])) {
        $fm = @unserialize($data['formatmap']);
        if (is_array($fm)) {
            $data['formatmap'] =& $fm;
        }
    }
    if (is_array($data['formatmap'])) {
        $fmtxt = '';
        foreach ($data['formatmap'] as $k => &$v) {
            // don't need to htmlspecialchar - it'll be done for us
            $fmtxt .= str_replace("\n", "{\n}", $k . '{|}' . $v) . "\n";
        }
        $data['formatmap'] =& $fmtxt;
    }
    make_form_row('formatmap', 'text_area', array('style' => 'font-family: monospace'));
    if ($data['viewable_gids'] && !is_array($data['viewable_gids'])) {
        $data['viewable_gids'] = array_map('intval', array_map('trim', explode(',', $data['viewable_gids'])));
    }
    $form_container->output_row($lang->threadfields_viewable_gids, $lang->threadfields_viewable_gids_desc, xt_generate_group_select('viewable_gids[]', $data['viewable_gids'], array('multiple' => true, 'size' => 5, 'id' => 'viewable_gids')), 'viewable_gids', array(), array('id' => 'row_viewable_gids'));
    make_form_row('unviewableval', 'text_area', array('style' => 'font-family: monospace'));
    $form_container->end();
    unset($GLOBALS['form_container']);
    // this will currently be empty if a file input is chosen...
    global $form_container;
    $form_container = new FormContainer($lang->threadfields_cat_misc);
    make_form_row('allowfilter', 'select_box', array(XTHREADS_FILTER_NONE => $lang->threadfields_filter_none, XTHREADS_FILTER_EXACT => $lang->threadfields_filter_exact, XTHREADS_FILTER_PREFIX => $lang->threadfields_filter_prefix, XTHREADS_FILTER_ANYWHERE => $lang->threadfields_filter_anywhere, XTHREADS_FILTER_WILDCARD => $lang->threadfields_filter_wildcard));
    make_form_row('datatype', 'select_box', array(XTHREADS_DATATYPE_TEXT => $lang->threadfields_datatype_text, XTHREADS_DATATYPE_INT => $lang->threadfields_datatype_int, XTHREADS_DATATYPE_UINT => $lang->threadfields_datatype_uint, XTHREADS_DATATYPE_BIGINT => $lang->threadfields_datatype_bigint, XTHREADS_DATATYPE_BIGUINT => $lang->threadfields_datatype_biguint, XTHREADS_DATATYPE_FLOAT => $lang->threadfields_datatype_float));
    $form_container->end();
    unset($GLOBALS['form_container']);
    if ($update) {
        $buttons[] = $form->generate_submit_button($lang->update_threadfield);
    } else {
        $buttons[] = $form->generate_submit_button($lang->add_threadfield);
    }
    $form->output_submit_wrapper($buttons);
    $form->end();
    ?>
<script type="text/javascript">
<!--
	var xt_inited = false;
	function xt_visi(o,v) {
		document.getElementById(o).style.display = (v ? '':'none');
	}
	document.getElementById('sanitize').onchange = function() {
		xt_visi('parser_opts', this.options[this.selectedIndex].value == "<?php 
    echo XTHREADS_SANITIZE_PARSER;
    ?>
" && document.getElementById('row_sanitize').style.display != 'none');
	};
	
	function xt_multival_enable() {
		var si = parseInt(document.getElementById('inputtype').options[document.getElementById('inputtype').selectedIndex].value);
		var checkboxIn = (si == <?php 
    echo XTHREADS_INPUT_CHECKBOX;
    ?>
);
		var pureFileIn = (si == <?php 
    echo XTHREADS_INPUT_FILE;
    ?>
);
		var fileIn = (pureFileIn || si == <?php 
    echo XTHREADS_INPUT_FILE_URL;
    ?>
);
		e = checkboxIn; // forced
		
		var datatypeText = (document.getElementById('datatype').options[document.getElementById('datatype').selectedIndex].value == "<?php 
    echo XTHREADS_DATATYPE_TEXT;
    ?>
");
		xt_visi('row_multival_enable', checkboxIn || ((
			si != <?php 
    echo XTHREADS_INPUT_RADIO;
    ?>
 && (datatypeText || pureFileIn)
		)));
		
		if(!e) e = (document.getElementById('multival_enable_yes').checked && document.getElementById('row_multival_enable').style.display != 'none');
		xt_visi('row_multival', e);
		xt_visi('row_multival_limit', e);
		xt_visi('row_dispitemformat', e);
		datatypeVisible = (!e && !checkboxIn && !fileIn);
		xt_visi('row_datatype', datatypeVisible);
		
		// hide some sanitise options (if browser supports it)
		var sanitizeOptShow = ((datatypeVisible && !datatypeText) ? 'none' : '');
		for(i in document.getElementById('sanitize').options) {
			var optItem = document.getElementById('sanitize').options[i];
			if(!optItem) continue; // fix IE6 bug
			if(optItem.value == "<?php 
    echo XTHREADS_SANITIZE_HTML_NL;
    ?>
" || optItem.value == "<?php 
    echo XTHREADS_SANITIZE_NONE;
    ?>
") {
				// our target
				if(sanitizeOptShow == 'none' && document.getElementById('sanitize').selectedIndex == i)
					document.getElementById('sanitize').selectedIndex = 0;
				optItem.style.display = sanitizeOptShow;
			}
		}
		
		dispfmt_obj = document.getElementById('dispformat');
		fileVal = "<a href=\"{URL}\">{FILENAME}</a>";
		nonFileVal = "{VALUE}";
		if(pureFileIn) {
			if(e) {
				if(document.getElementById('dispitemformat').value == nonFileVal) {
					if(dispfmt_obj.value == nonFileVal)
						document.getElementById('dispitemformat').value = fileVal;
					else {
						// swap dispformat <-> dispitemformat
						document.getElementById('dispitemformat').value = dispfmt_obj.value;
						dispfmt_obj.value = nonFileVal;
					}
				}
				if(dispfmt_obj.value == fileVal)
					dispfmt_obj.value = nonFileVal;
			} else {
				if(dispfmt_obj.value == nonFileVal) {
					dispfmt_obj.value = fileVal;
					if(document.getElementById('dispitemformat').value != nonFileVal) {
						// maybe swap?
						var DIFval = document.getElementById('dispitemformat').value.toUpperCase();
						if((function(s){
							for(i in s)
								if(DIFval.indexOf("{"+s[i]+"}") > -1)
									return true;
							return false;
						})(
							["DOWNLOADS","DOWNLOADS_FRIENDLY","FILENAME","UPLOADMIME","URL","FILESIZE","FILESIZE_FRIENDLY","MD5HASH","UPLOADTIME","UPLOAD_TIME","UPLOAD_DATE","UPDATETIME","UPDATE_TIME","UPDATE_DATE","THUMBS","DIMS","MODIFIED"]
						)) {
							dispfmt_obj.value = document.getElementById('dispitemformat').value;
							document.getElementById('dispitemformat').value = nonFileVal;
						}
					}
				}
				if(document.getElementById('dispitemformat').value == fileVal)
					document.getElementById('dispitemformat').value = nonFileVal;
			}
		} else {
			if(document.getElementById('dispitemformat').value == fileVal)
				document.getElementById('dispitemformat').value = nonFileVal;
			if(dispfmt_obj.value == fileVal)
				dispfmt_obj.value = nonFileVal;
		}
	}
	document.getElementById('multival_enable_yes').onclick = xt_multival_enable;
	document.getElementById('multival_enable_no').onclick = xt_multival_enable;
	
	(document.getElementById('use_formhtml_yes').onclick = document.getElementById('use_formhtml_no').onclick = xt_use_formhtml = function() {
		xt_visi('row_formhtml', document.getElementById('use_formhtml_yes').checked);
		xt_visi('formhtml_desc_js', true);
	})();
	
	function xt_filereqimg() {
		var e = (document.getElementById('filereqimg_yes').checked && document.getElementById('row_filereqimg').style.display != 'none');
		xt_visi('row_fileimage_mindim', e);
		xt_visi('row_fileimage_maxdim', e);
		xt_visi('row_fileimgthumbs', e);
	}
	document.getElementById('filereqimg_yes').onclick = xt_filereqimg;
	document.getElementById('filereqimg_no').onclick = xt_filereqimg;
	
	
	(document.getElementById('inputtype').onchange = function() {
		var si = parseInt(this.options[this.selectedIndex].value);
		
		var pureFileIn = (si == <?php 
    echo XTHREADS_INPUT_FILE;
    ?>
);
		var fileIn = (pureFileIn || si == <?php 
    echo XTHREADS_INPUT_FILE_URL;
    ?>
);
		var radioIn = (si == <?php 
    echo XTHREADS_INPUT_RADIO;
    ?>
);
		var checkboxIn = (si == <?php 
    echo XTHREADS_INPUT_CHECKBOX;
    ?>
);
		var selectBoxIn = (si == <?php 
    echo XTHREADS_INPUT_SELECT;
    ?>
);
		var selectIn = (selectBoxIn || radioIn || checkboxIn);
		var textAreaIn = (si == <?php 
    echo XTHREADS_INPUT_TEXTAREA;
    ?>
);
		var textIn = (textAreaIn || si == <?php 
    echo XTHREADS_INPUT_TEXT;
    ?>
);
		xt_visi('row_sanitize', !fileIn && !selectIn);
		document.getElementById('sanitize').onchange();
		
		xt_visi('inputtype_file_explain', pureFileIn);
		
		xt_visi('row_allowfilter', !fileIn && !textAreaIn);
		xt_visi('row_formatmap', !fileIn);
		xt_visi('row_editable_values', !fileIn);
		xt_visi('row_defaultval', !pureFileIn);
		
		xt_visi('row_textmask', textIn);
		xt_visi('row_inputformat', !fileIn);
		xt_visi('row_maxlen', textIn);
		xt_visi('row_fieldwidth', textIn || fileIn || selectBoxIn);
		xt_visi('row_fieldheight', textAreaIn || selectBoxIn);
		
		xt_visi('row_vallist', selectIn);
		
		//xt_visi('row_datatype', !checkboxIn && !fileIn);
		//xt_visi('row_multival_enable', !checkboxIn && !radioIn && !fileIn);
		xt_multival_enable();
		
		xt_visi('row_filemagic', pureFileIn);
		xt_visi('row_fileexts', pureFileIn);
		xt_visi('row_filemaxsize', pureFileIn);
		xt_visi('row_filereqimg', pureFileIn);
		xt_filereqimg();
		
		if(textAreaIn) {
			if(document.getElementById('sanitize').options[document.getElementById('sanitize').selectedIndex].value == "<?php 
    echo XTHREADS_SANITIZE_HTML;
    ?>
")
				document.getElementById('sanitize').selectedIndex++;
		} else if(textIn) {
			if(document.getElementById('sanitize').options[document.getElementById('sanitize').selectedIndex].value == "<?php 
    echo XTHREADS_SANITIZE_HTML_NL;
    ?>
")
				document.getElementById('sanitize').selectedIndex--;
		}
		
		var setFormhtml = true;
		if(document.getElementById('use_formhtml_yes').checked) {
			if(!xt_inited)
				setFormhtml = (document.getElementById("formhtml").value == "");
			else
				setFormhtml = confirm("<?php 
    echo xt_js_str_escape($lang->threadfields_formhtml_js_reset_warning);
    ?>
");
			if(setFormhtml) {
				document.getElementById('use_formhtml_no').checked = true;
			}
			xt_use_formhtml();
		}
		switch(si) {
			<?php 
    foreach (array(XTHREADS_INPUT_TEXTAREA, XTHREADS_INPUT_SELECT, XTHREADS_INPUT_CHECKBOX, XTHREADS_INPUT_RADIO, XTHREADS_INPUT_FILE, XTHREADS_INPUT_TEXT) as $inputtype) {
        $formhtml_info = xthreads_default_threadfields_formhtml($inputtype);
        $formhtml_desc = '';
        foreach ($formhtml_info[1] as $fhvar) {
            $langvar = 'threadfields_formhtml_desc_' . strtolower($fhvar);
            $formhtml_desc .= '<li><code>{' . $fhvar . '}</code>: ' . $lang->{$langvar} . '</li>';
        }
        echo '
				case ' . $inputtype . ':
					if(setFormhtml) document.getElementById("formhtml").value = "' . xt_js_str_escape($formhtml_info[0]) . '";
					document.getElementById("formhtml_desc_ul_js").innerHTML = "' . xt_js_str_escape($formhtml_desc) . '";
					break;';
    }
    ?>
		}
	}).apply(document.getElementById('inputtype'));
	
	(document.getElementById('datatype').onchange = function() {
		//var isText = this.options[this.selectedIndex].value == "<?php 
    echo XTHREADS_DATATYPE_TEXT;
    ?>
";
		//xt_visi('row_multival_enable', isText);
		xt_multival_enable();
	}).apply(document.getElementById('datatype'));
	
	(document.getElementById('editable').onchange = function() {
		xt_visi('row_editable_gids', this.options[this.selectedIndex].value == "99");
	}).apply(document.getElementById('editable'));
	
	(document.getElementById('viewable_gids').onchange = function() {
		var e=false;
		var o=document.getElementById('viewable_gids').options;
		for(i=0; i<o.length; i++)
			if(e = o[i].selected) // no, I do mean =, not ==
				break;
		xt_visi('row_unviewableval', e);
	}).apply(document.getElementById('viewable_gids'));
	
	<?php 
    $textmask_types = array('anything' => '^.*$', 'digit' => '^\\d+$', 'alphadigit' => '^[a-z0-9]+$', 'number' => '^(-?)([0-9]*)(?:\\.(\\d*))?(?:e([+-]?\\d*))?$', 'date' => '^(0?[1-9]|[12]\\d|3[01])/(0?[1-9]|1[012])/((?:19|20)\\d\\d)$', 'date_us' => '^(0?[1-9]|1[012])/(0?[1-9]|[12]\\d|3[01])/((?:19|20)\\d\\d)$', 'uri' => '^([^:/?#]+)\\:((//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?)$', 'url' => '^([a-z0-9]+)\\://([^/?#]+)(/([^\\r\\n"<>#?]*)(\\?([^\\r\\n"<>#]*))?(#([^\\r\\n"<>]*))?)?$', 'httpurl' => '^(https?)\\://([^/?#]+)(/([^\\r\\n"<>#?]*)(\\?([^\\r\\n"<>#]*))?(#([^\\r\\n"<>]*))?)?$', 'email' => '^(.+)@([a-z0-9_.\\-]+)$', 'emailr' => '^([^ "(),:;<>@\\[\\\\\\]]+)@([a-z0-9_.\\-]+)$', 'css' => '^[a-z0-9_\\- ]+$', 'color' => '^[a-z\\-]+|#?[0-9a-f]{6}$');
    ?>
	document.getElementById('textmask').parentNode.innerHTML =
			'<select name="textmask_select" id="textmask_select">' +
<?php 
    foreach ($textmask_types as $type => &$mask) {
        $langvar = 'threadfields_textmask_' . $type;
        echo '			\'<option value="', $type, '">', $lang->{$langvar}, '</option>\' +
';
    }
    ?>
			'<option value="custom">'+<?php 
    echo "'", $lang->threadfields_textmask_custom, "'";
    ?>
+'</option>' +
			'</select> ' + document.getElementById('textmask').parentNode.innerHTML + '<div id="textmask_select_descriptions" style="font-size: smaller; padding-top: 0.5em;">' +
<?php 
    foreach ($textmask_types as $type => &$mask) {
        $langvar = 'threadfields_textmask_' . $type . '_desc';
        if (property_exists($lang, $langvar)) {
            echo '			\'<div id="textmask_selector_desc_', $type, '" style="display: none;">', xt_js_str_escape($lang->{$langvar}), '</div>\' +
';
        }
    }
    ?>
			'</div>';
	var textmaskMapping = {
<?php 
    $comma = '';
    foreach ($textmask_types as $type => &$mask) {
        echo $comma, '		', $type, ': "', xt_js_str_escape($mask), '"';
        if (!$comma) {
            $comma = ',
';
        }
    }
    ?>

	};
	// determine which option to be selected by default
	(function() {
		// we can only index by number, and as we're a little lazy, create a name -> index map
		var textmaskSelectOpts = document.getElementById('textmask_select').options;
		var textmaskSelectMap = {};
		for(i=0; i<textmaskSelectOpts.length; i++) {
			textmaskSelectMap[textmaskSelectOpts[i].value] = i;
		}
		
		var mask = document.getElementById('textmask').value;
		for(var maskName in textmaskMapping) {
			if(mask == textmaskMapping[maskName]) {
				document.getElementById('textmask_select').selectedIndex = textmaskSelectMap[maskName];
				textmaskSelectUpdated();
				return;
			}
		}
		document.getElementById('textmask_select').selectedIndex = textmaskSelectMap["custom"];
	})();
	document.getElementById('textmask_select').onchange = function() {
		var maskName = this.options[this.selectedIndex].value;
		if(textmaskMapping[maskName])
			document.getElementById('textmask').value = textmaskMapping[maskName];
		textmaskSelectUpdated();
	};
	document.getElementById('textmask_select').onkeypress = document.getElementById('textmask_select').onkeydown = document.getElementById('textmask_select').onkeyup = function(e) {
		document.getElementById('textmask_select').onchange();
		return true;
	};
	function textmaskSelectUpdated() {
		var maskName = document.getElementById('textmask_select').options[document.getElementById('textmask_select').selectedIndex].value;
		var d = (maskName != "custom");
		document.getElementById('textmask').readOnly = d;
		document.getElementById('textmask').tabIndex = (d?'-1':''); // note, this is non-standard
		document.getElementById('textmask').style.background = (d ? "#F0F0F0":"");
		document.getElementById('textmask').style.color = (d ? "#808080":"");
		
		var o = document.getElementById('textmask_select_descriptions').childNodes;
		for(i=0; i<o.length; i++) {
			if(o[i].id == "textmask_selector_desc_"+maskName)
				o[i].style.display = "";
			else
				o[i].style.display = "none";
		}
	}
	document.getElementById('textmask').onfocus = function() {
		if(this.readOnly)
			document.getElementById('textmask_select').focus();
	};
	xt_inited = true;
//-->
</script>
<script type="text/javascript" src="jscripts/xtofedit.js?xtver=<?php 
    echo XTHREADS_VERSION;
    ?>
"></script>
<script type="text/javascript">
<!--
xtOFEditorLang.confirmFormSubmit = "<?php 
    echo $lang->xthreads_js_confirm_form_submit;
    ?>
";
xtOFEditorLang.windowTitle = "<?php 
    echo $lang->xthreads_js_edit_value;
    ?>
";
xtOFEditorLang.saveButton = "<?php 
    echo $lang->xthreads_js_save_changes;
    ?>
";
xtOFEditorLang.closeSaveChanges = "<?php 
    echo $lang->xthreads_js_close_save_changes;
    ?>
";

var fmtMapEditor = new xtOFEditor();
fmtMapEditor.src = document.getElementById('formatmap');
fmtMapEditor.loadFunc = function(s) {
	var a = s.replace(/\r/g, "").replace(/\{\n\}/g, "\r").split("\n");
	var data = [];
	for(var i=0; i<a.length; i++) {
		a[i] = a[i].replace(/\r/g, "\n");
		var p = a[i].indexOf("{|}");
		if(p < 0) continue;
		data.push([ a[i].substring(0, p), a[i].substring(p+3) ]);
	}
	return data;
};
fmtMapEditor.saveFunc = function(a) {
	var ret = "";
	for(var i=0; i<a.length; i++) {
		ret += a[i].join("{|}").replace(/\n/g, "{\n}") + "\n";
	}
	return ret;
};
fmtMapEditor.fields = [
	{title: "<?php 
    echo $lang->xthreads_js_formatmap_from;
    ?>
", width: '45%', elemFunc: fmtMapEditor.textAreaFunc},
	{title: "<?php 
    echo $lang->xthreads_js_formatmap_to;
    ?>
", width: '55%', elemFunc: fmtMapEditor.textAreaFunc}
];

fmtMapEditor.copyStyles=true;
fmtMapEditor.init();

var editValEditor = new xtOFEditor();
editValEditor.src = document.getElementById('editable_values');
editValEditor.loadFunc = function(s) {
	var a = s.replace(/\r/g, "").replace(/\{\n\}/g, "\r").split("\n");
	var data = [];
	for(var i=0; i<a.length; i++) {
		a[i] = a[i].replace(/\r/g, "\n");
		var p = a[i].indexOf("{|}");
		if(p < 0) continue;
		data.push([ a[i].substring(0, p), a[i].substring(p+3).split(",") ]);
	}
	return data;
};
editValEditor.saveFunc = function(a) {
	var ret = "";
	for(var i=0; i<a.length; i++) {
		ret += a[i][0].replace(/\n/g, "{\n}") + "{|}" + a[i][1].join(",") + "\n";
	}
	return ret;
};
editValEditor.fields = [
	{title: "<?php 
    echo $lang->xthreads_js_formatmap_from;
    ?>
", width: '50%', elemFunc: editValEditor.textAreaFunc},
	{title: "<?php 
    echo $lang->xthreads_js_editable_values_groups;
    ?>
", width: '50%', elemFunc: function(c) {
		var o = appendNewChild(c, "select");
		o.multiple = true;
		o.size = 3;
		o.style.width = '100%';
		o.innerHTML = '<?php 
    foreach ($GLOBALS['cache']->read('usergroups') as $group) {
        echo '<option value="' . $group['gid'] . '">' . xt_js_str_escape(htmlspecialchars_uni(strip_tags($group['title']))) . '</option>';
    }
    ?>
';
		return o;
	}}
];

editValEditor.copyStyles=true;
editValEditor.init();

//-->
</script><?php 
    $page->output_footer();
}
Example #11
0
 }
 if ($mybb->input['toaddress']) {
     $additional_sql_criteria .= " AND toaddress LIKE '%" . $db->escape_string($mybb->input['toaddress']) . "%'";
     $additional_criteria[] = "toaddress='" . urlencode($mybb->input['toaddress']) . "'";
     $form->generate_hidden_field("toaddress", $mybb->input['toaddress']);
 }
 if ($mybb->input['error']) {
     $additional_sql_criteria .= " AND error LIKE '%" . $db->escape_string($mybb->input['error']) . "%'";
     $additional_criteria[] = "error='" . urlencode($mybb->input['error']) . "'";
     $form->generate_hidden_field("error", $mybb->input['error']);
 }
 if ($additional_criteria) {
     $additional_criteria = "&amp;" . implode("&amp;", $additional_criteria);
 }
 $table = new Table();
 $table->construct_header($form->generate_check_box("checkall", 1, '', array('class' => 'checkall')));
 $table->construct_header($lang->subject);
 $table->construct_header($lang->to, array("class" => "align_center", "width" => "20%"));
 $table->construct_header($lang->error_message, array("class" => "align_center", "width" => "30%"));
 $table->construct_header($lang->date_sent, array("class" => "align_center", "width" => "20%"));
 $query = $db->query("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "mailerrors\n\t\tWHERE 1=1 {$additional_sql_criteria}\n\t\tORDER BY dateline DESC\n\t\tLIMIT {$start}, {$per_page}\n\t");
 while ($log = $db->fetch_array($query)) {
     $log['subject'] = htmlspecialchars_uni($log['subject']);
     $log['toemail'] = htmlspecialchars_uni($log['toemail']);
     $log['error'] = htmlspecialchars_uni($log['error']);
     $log['dateline'] = date($mybb->settings['dateformat'], $log['dateline']) . ", " . date($mybb->settings['timeformat'], $log['dateline']);
     $table->construct_cell($form->generate_check_box("log[{$log['eid']}]", $log['eid'], ''));
     $table->construct_cell("<a href=\"javascript:MyBB.popupWindow('index.php?module=tools/mailerrors&amp;action=view&amp;eid={$log['eid']}', 'log_entry', 450, 450);\">{$log['subject']}</a>");
     $find_from = "<div class=\"float_right\"><a href=\"index.php?module=tools/mailerrors&amp;toaddress={$log['toaddress']}\"><img src=\"styles/{$page->style}/images/icons/find.gif\" title=\"{$lang->fine_emails_to_addr}\" alt=\"{$lang->find}\" /></a></div>";
     $table->construct_cell("{$find_from}<div>{$log['toaddress']}</div>");
     $table->construct_cell($log['error']);
Example #12
0
function asb_admin_custom_boxes()
{
    global $lang, $mybb, $db, $page, $html, $min;
    if ($mybb->input['mode'] == 'export') {
        if ((int) $mybb->input['id'] == 0) {
            flash_message($lang->asb_custom_export_error, 'error');
            admin_redirect($html->url(array("action" => 'custom_boxes')));
        }
        $this_custom = new Custom_type($mybb->input['id']);
        if (!$this_custom->is_valid()) {
            flash_message($lang->asb_custom_export_error, 'error');
            admin_redirect($html->url(array("action" => 'custom_boxes')));
        }
        $this_custom->export();
        exit;
    }
    if ($mybb->input['mode'] == 'delete') {
        // info good?
        if ((int) $mybb->input['id'] == 0) {
            flash_message($lang->asb_add_custom_box_delete_failure, 'error');
            admin_redirect($html->url(array("action" => 'custom_boxes')));
        }
        // nuke it
        $this_custom = new Custom_type($mybb->input['id']);
        // success?
        if (!$this_custom->remove()) {
            flash_message($lang->asb_add_custom_box_delete_failure, 'error');
            admin_redirect($html->url(array("action" => 'custom_boxes')));
        }
        // :)
        flash_message($lang->asb_add_custom_box_delete_success, 'success');
        asb_cache_has_changed();
        admin_redirect($html->url(array("action" => 'custom_boxes')));
    }
    // POSTing?
    if ($mybb->request_method == 'post') {
        if ($mybb->input['mode'] == 'import') {
            if (!$_FILES['file'] || $_FILES['file']['error'] == 4) {
                flash_message($lang->asb_custom_import_no_file, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            if ($_FILES['file']['error']) {
                flash_message($lang->sprintf($lang->asb_custom_import_file_error, $_FILES['file']['error']), 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
                flash_message($lang->asb_custom_import_file_upload_error, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            $contents = @file_get_contents($_FILES['file']['tmp_name']);
            @unlink($_FILES['file']['tmp_name']);
            if (!trim($contents)) {
                flash_message($lang->asb_custom_import_file_empty, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            require_once MYBB_ROOT . 'inc/class_xml.php';
            $parser = new XMLParser($contents);
            $tree = $parser->get_tree();
            if (!is_array($tree) || empty($tree)) {
                flash_message($lang->asb_custom_import_file_empty, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            if (!is_array($tree['asb_custom_sideboxes']) || empty($tree['asb_custom_sideboxes'])) {
                if (!is_array($tree['adv_sidebox']) || !is_array($tree['adv_sidebox']['custom_sidebox'])) {
                    flash_message($lang->asb_custom_import_file_empty, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes')));
                }
                $results = asb_legacy_custom_import($tree);
                if (!is_array($results)) {
                    flash_message($results, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes')));
                }
                $custom = new Custom_type($results);
            } else {
                $custom = new Custom_type();
                if (!$custom->import($contents)) {
                    flash_message($lang->asb_custom_import_fail_generic, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes')));
                }
            }
            if (!$custom->save()) {
                flash_message($lang->asb_custom_box_save_failure, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            flash_message($lang->asb_custom_import_save_success, 'success');
            admin_redirect($html->url(array("action" => 'custom_boxes', "id" => $custom->get('id'))));
        } else {
            // saving?
            if ($mybb->input['save_box_submit'] == 'Save') {
                if (!$mybb->input['box_name'] || !$mybb->input['box_content']) {
                    flash_message($lang->asb_custom_box_save_failure_no_content, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes')));
                }
                $this_custom = new Custom_type((int) $mybb->input['id']);
                // get the info
                $this_custom->set('title', $mybb->input['box_name']);
                $this_custom->set('description', $mybb->input['box_description']);
                $this_custom->set('content', $mybb->input['box_content']);
                $this_custom->set('wrap_content', $mybb->input['wrap_content'] == 'yes');
                // success?
                if (!$this_custom->save()) {
                    flash_message($lang->asb_custom_box_save_failure, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes', "id" => $this_custom->get('id'))));
                }
                flash_message($lang->asb_custom_box_save_success, 'success');
                asb_cache_has_changed();
                admin_redirect($html->url(array("action" => 'custom_boxes', "id" => $this_custom->get('id'))));
            }
        }
    }
    $page->add_breadcrumb_item($lang->asb, $html->url());
    if ($mybb->input['mode'] == 'edit') {
        $queryadmin = $db->simple_select('adminoptions', '*', "uid='{$mybb->user['uid']}'");
        $admin_options = $db->fetch_array($queryadmin);
        if ($admin_options['codepress'] != 0) {
            $page->extra_header .= <<<EOF
\t<link type="text/css" href="./jscripts/codepress/languages/codepress-mybb.css" rel="stylesheet" id="cp-lang-style"/>
\t<script type="text/javascript" src="./jscripts/codepress/codepress.js"></script>
\t<script type="text/javascript">
\t<!--
\t\tCodePress.language = 'mybb';
\t// -->
\t</script>
EOF;
        }
        $this_box = new Custom_type((int) $mybb->input['id']);
        $action = $lang->asb_add_custom;
        if ($this_box->get('id')) {
            $specify_box = '&amp;id=' . $this_box->get('id');
            $currently_editing = $lang->asb_editing . ': <strong>' . $this_box->get('title') . '</strong>';
            $action = $lang->asb_edit . ' ' . $this_box->get('title');
        } else {
            // new box
            $specify_box = '';
            $sample_content = <<<EOF
<tr>
\t\t<td class="trow1">{$lang->asb_sample_content_line1} (HTML)</td>
\t</tr>
\t<tr>
\t\t<td class="trow2">{$lang->asb_sample_content_line2}</td>
\t</tr>
\t<tr>
\t\t<td class="trow1"><strong>{$lang->asb_sample_content_line3}</td>
\t</tr>
EOF;
            $this_box->set('content', $sample_content);
            $this_box->set('wrap_content', true);
        }
        $page->extra_header .= <<<EOF
\t<link rel="stylesheet" type="text/css" href="styles/asb_acp.css" media="screen" />
\t<script src="jscripts/asb/asb{$min}.js" type="text/javascript"></script>
EOF;
        $page->add_breadcrumb_item($lang->asb_custom_boxes, $html->url(array("action" => 'custom_boxes')));
        $page->add_breadcrumb_item($lang->asb_add_custom);
        $page->output_header("{$lang->asb} - {$action}");
        asb_output_tabs('asb_add_custom');
        $form = new Form($html->url(array("action" => 'custom_boxes')) . $specify_box, 'post', 'edit_box');
        $form_container = new FormContainer($currently_editing);
        $form_container->output_cell($lang->asb_name);
        $form_container->output_cell($lang->asb_description);
        $form_container->output_cell($lang->asb_custom_box_wrap_content);
        $form_container->output_row('');
        // name
        $form_container->output_cell($form->generate_text_box('box_name', $this_box->get('title'), array("id" => 'box_name')));
        // description
        $form_container->output_cell($form->generate_text_box('box_description', $this_box->get('description')));
        // wrap content?
        $form_container->output_cell($form->generate_check_box('wrap_content', 'yes', $lang->asb_custom_box_wrap_content_desc, array("checked" => $this_box->get('wrap_content'))));
        $form_container->output_row('');
        $form_container->output_cell('Content:', array("colspan" => 3));
        $form_container->output_row('');
        // content
        $form_container->output_cell($form->generate_text_area('box_content', $this_box->get('content'), array("id" => 'box_content', 'class' => 'codepress mybb', 'style' => 'width: 100%; height: 240px;')), array("colspan" => 3));
        $form_container->output_row('');
        // finish form
        $form_container->end();
        $buttons[] = $form->generate_submit_button('Save', array('name' => 'save_box_submit'));
        $form->output_submit_wrapper($buttons);
        $form->end();
        if ($admin_options['codepress'] != 0) {
            echo <<<EOF
\t\t<script type="text/javascript">
\t\t<!--
\t\t\tEvent.observe('edit_box', 'submit', function() {
\t\t\t\tif (\$('box_content_cp')) {
\t\t\t\t\tvar area = \$('box_content_cp');
\t\t\t\t\tarea.id = 'box_content';
\t\t\t\t\tarea.value = box_content.getCode();
\t\t\t\t\tarea.disabled = false;
\t\t\t\t}
\t\t\t});
\t\t// -->
\t\t</script>
EOF;
            // build link bar and ACP footer
            asb_output_footer('edit_custom');
        }
    }
    $page->extra_header .= <<<EOF
\t<link rel="stylesheet" type="text/css" href="styles/asb_acp.css" media="screen" />
\t<script src="jscripts/asb/asb{$min}.js" type="text/javascript"></script>
EOF;
    $page->add_breadcrumb_item($lang->asb_custom_boxes);
    $page->output_header("{$lang->asb} - {$lang->asb_custom_boxes}");
    asb_output_tabs('asb_custom');
    $new_box_url = $html->url(array("action" => 'custom_boxes', "mode" => 'edit'));
    $new_box_link = $html->link($new_box_url, $lang->asb_add_custom_box_types, array("style" => 'font-weight: bold;', "title" => $lang->asb_add_custom_box_types, "icon" => "{$mybb->settings['bburl']}/inc/plugins/asb/images/add.png"), array("alt" => '+', "style" => 'margin-bottom: -3px;', "title" => $lang->asb_add_custom_box_types));
    echo $new_box_link . '<br /><br />';
    $table = new Table();
    $table->construct_header($lang->asb_name);
    $table->construct_header($lang->asb_custom_box_desc);
    $table->construct_header($lang->asb_controls, array("colspan" => 2));
    $custom = asb_get_all_custom();
    // if there are saved types . . .
    if (is_array($custom) && !empty($custom)) {
        // display them
        foreach ($custom as $this_custom) {
            $data = $this_custom->get('data');
            // name (edit link)
            $edit_url = $html->url(array("action" => 'custom_boxes', "mode" => 'edit', "id" => $data['id']));
            $edit_link = $html->link($edit_url, $data['title'], array("title" => $lang->asb_edit, "style" => 'font-weight: bold;'));
            $table->construct_cell($edit_link, array("width" => '30%'));
            // description
            if ($data['description']) {
                $description = $data['description'];
            } else {
                $description = "<em>{$lang->asb_no_description}</em>";
            }
            $table->construct_cell($description, array("width" => '60%'));
            // options popup
            $popup = new PopupMenu('box_' . $data['id'], $lang->asb_options);
            // edit
            $popup->add_item($lang->asb_edit, $edit_url);
            // delete
            $popup->add_item($lang->asb_delete, $html->url(array("action" => 'custom_boxes', "mode" => 'delete', "id" => $data['id'])), "return confirm('{$lang->asb_custom_del_warning}');");
            // export
            $popup->add_item($lang->asb_custom_export, $html->url(array("action" => 'custom_boxes', "mode" => 'export', "id" => $data['id'])));
            // popup cell
            $table->construct_cell($popup->fetch(), array("width" => '10%'));
            // finish the table
            $table->construct_row();
        }
    } else {
        // no saved types
        $table->construct_cell($lang->asb_no_custom_boxes, array("colspan" => 4));
        $table->construct_row();
    }
    $table->output($lang->asb_custom_box_types);
    echo '<br /><br />';
    $import_form = new Form($html->url(array("action" => 'custom_boxes', "mode" => 'import')), 'post', '', 1);
    $import_form_container = new FormContainer($lang->asb_custom_import);
    $import_form_container->output_row($lang->asb_custom_import_select_file, '', $import_form->generate_file_upload_box('file'));
    $import_form_container->end();
    $import_buttons[] = $import_form->generate_submit_button($lang->asb_custom_import, array('name' => 'import'));
    $import_form->output_submit_wrapper($import_buttons);
    $import_form->end();
    // build link bar and ACP footer
    asb_output_footer('custom');
}
Example #13
0
 if ($mybb->input['toemail']) {
     $additional_sql_criteria .= " AND l.toemail LIKE '%{$toemail}%'";
     $additional_criteria[] = "toemail=" . urlencode($mybb->input['toemail']);
     $to_filter = $mybb->input['toemail'];
 }
 if (!empty($additional_criteria)) {
     $additional_criteria = "&amp;" . implode("&amp;", $additional_criteria);
 } else {
     $additional_criteria = '';
 }
 $page->output_header($lang->user_email_log);
 $sub_tabs['maillogs'] = array('title' => $lang->user_email_log, 'link' => "index.php?module=tools-maillogs", 'description' => $lang->user_email_log_desc);
 $page->output_nav_tabs($sub_tabs, 'maillogs');
 $form = new Form("index.php?module=tools-maillogs&amp;action=prune", "post");
 $table = new Table();
 $table->construct_header($form->generate_check_box("allbox", 1, '', array('class' => 'checkall')));
 $table->construct_header($lang->subject, array("colspan" => 2));
 $table->construct_header($lang->from, array("class" => "align_center", "width" => "20%"));
 $table->construct_header($lang->to, array("class" => "align_center", "width" => "20%"));
 $table->construct_header($lang->date_sent, array("class" => "align_center", "width" => "20%"));
 $table->construct_header($lang->ip_address, array("class" => "align_center", 'width' => '10%'));
 $query = $db->query("\n\t\tSELECT l.*, r.username AS to_username, f.username AS from_username, t.subject AS thread_subject\n\t\tFROM " . TABLE_PREFIX . "maillogs l\n\t\tLEFT JOIN " . TABLE_PREFIX . "users r ON (r.uid=l.touid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "users f ON (f.uid=l.fromuid)\n\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=l.tid)\n\t\tWHERE 1=1 {$additional_sql_criteria}\n\t\tORDER BY l.dateline DESC\n\t\tLIMIT {$start}, {$per_page}\n\t");
 while ($log = $db->fetch_array($query)) {
     $table->construct_cell($form->generate_check_box("log[{$log['mid']}]", $log['mid'], ''), array("width" => 1));
     $log['subject'] = htmlspecialchars_uni($log['subject']);
     $log['dateline'] = date($mybb->settings['dateformat'], $log['dateline']) . ", " . date($mybb->settings['timeformat'], $log['dateline']);
     if ($log['type'] == 2) {
         if ($log['thread_subject']) {
             $log['thread_subject'] = htmlspecialchars_uni($log['thread_subject']);
             $thread_link = "<a href=\"../" . get_thread_link($log['tid']) . "\">" . $log['thread_subject'] . "</a>";
         } else {
Example #14
0
         }
         if ($perms[$forum_permission] != 1) {
             $all_checked = false;
         }
         if ($perms[$forum_permission] == 1) {
             $perms_checked[$forum_permission] = 1;
         } else {
             $perms_checked[$forum_permission] = 0;
         }
         $all_check .= "\$('permissions_{$usergroup['gid']}_{$forum_permission}').checked = \$('permissions_{$usergroup['gid']}_all').checked;\n";
         $perm_check .= "\$('permissions_{$usergroup['gid']}_{$forum_permission}').checked = {$value};\n";
     }
     $default_click = "if(this.checked == true) { {$perm_check} }";
     $reset_default = "\$('default_permissions_{$usergroup['gid']}').checked = false; if(this.checked == false) { \$('permissions_{$usergroup['gid']}_all').checked = false; }\n";
     $usergroup['title'] = htmlspecialchars_uni($usergroup['title']);
     $form_container->output_cell("<strong>{$usergroup['title']}</strong><br /><small style=\"vertical-align: middle;\">" . $form->generate_check_box("default_permissions[{$usergroup['gid']}];", 1, "", array("id" => "default_permissions_{$usergroup['gid']}", "checked" => $default_checked, "onclick" => $default_click)) . " <label for=\"default_permissions_{$usergroup['gid']}\">{$lang->permissions_use_group_default}</label></small>");
     foreach ($field_list as $forum_permission) {
         $form_container->output_cell($form->generate_check_box("permissions[{$usergroup['gid']}][{$forum_permission}]", 1, "", array("id" => "permissions_{$usergroup['gid']}_{$forum_permission}", "checked" => $perms_checked[$forum_permission], "onclick" => $reset_default)), array('class' => 'align_center'));
     }
     $form_container->output_cell($form->generate_check_box("permissions[{$usergroup['gid']}][all]", 1, "", array("id" => "permissions_{$usergroup['gid']}_all", "checked" => $all_checked, "onclick" => $all_check)), array('class' => 'align_center'));
     if (!$default_checked) {
         $form_container->output_cell("<a href=\"index.php?module=forum/management&amp;action=permissions&amp;pid={$perms['pid']}\">{$lang->edit_permissions}</a>", array("class" => "align_center"));
     } else {
         $form_container->output_cell("<a href=\"index.php?module=forum/management&amp;action=permissions&amp;gid={$usergroup['gid']}&amp;fid={$fid}\">{$lang->set_permissions}</a>", array("class" => "align_center"));
     }
     $form_container->construct_row();
 }
 $form_container->end();
 $buttons = array();
 $buttons[] = $form->generate_submit_button($lang->update_forum_permissions);
 $buttons[] = $form->generate_reset_button($lang->reset);
Example #15
0
 $form_container = new FormContainer($lang->downloads_dlmngr_edit);
 // create the save flag
 echo $form->generate_hidden_field("save", "save", array('id' => "save")) . "\n";
 // display the text fields
 // output_row(title, desc, item, something I just set to the same as the ID)
 // generate_INPUTTYPE(name, vlaue, array(html modifiers))
 $form_container->output_row($lang->downloads_dlmngr_title, $lang->downloads_dlmngr_title_desc, $form->generate_text_box('title', $dlitem['title'], array('id' => 'title')), 'title');
 $form_container->output_row($lang->downloads_dlmngr_desc_short, $lang->downloads_dlmngr_desc_short_desc, $form->generate_text_box('desc_short', $dlitem['desc_short'], array('id' => 'desc_short')), 'desc_short');
 $form_container->output_row($lang->downloads_dlmngr_description, $lang->downloads_dlmngr_description_desc, $form->generate_text_area('description', $dlitem['description'], array('id' => 'description', 'style' => 'width: 100%;')), 'description');
 $form_container->output_row($lang->downloads_dlmngr_fid, $lang->downloads_dlmngr_fid_desc, $form->generate_forum_select('fid', $dlitem['fid'], array('id' => 'fid', 'main_option' => $lang->none)), 'fid');
 $query = $db->simple_select("downloads_catlist", "*", "1=1");
 while ($cat = $db->fetch_array($query)) {
     $categories[$cat['catid']] = $cat['title'];
 }
 $form_container->output_row($lang->downloads_dlmngr_cat, $lang->downloads_dlmngr_cat_desc, $form->generate_select_box('cat', $categories, $dlitem['cat'], array('id' => 'cat')), 'cat');
 $form_container->output_row($lang->downloads_dlmngr_grpflag, $lang->downloads_dlmngr_grpflag_desc, $form->generate_check_box('grpflag', '1', $lang->downloads_dlmngr_grpflag_desc_option, array('checked' => $dlitem['grpflag'])), 'grpflag');
 $query = $db->simple_select("usergroups", "gid, title", "gid != '1'", array('order_by' => 'title'));
 while ($usergroup = $db->fetch_array($query)) {
     $options[$usergroup['gid']] = $usergroup['title'];
     $display_group_options[$usergroup['gid']] = $usergroup['title'];
 }
 $form_container->output_row($lang->downloads_dlmngr_grpflag, $lang->downloads_dlmngr_grpflag_desc, $form->generate_select_box('grplist[]', $options, $dlitem['grplist'], array('multiple' => true, 'size' => 5)), 'grplist');
 $form_container->output_row($lang->downloads_dlmngr_preview, $lang->downloads_dlmngr_preview_desc, $form->generate_text_box('preview', $dlitem['preview'], array('id' => 'preview')), 'preview');
 $form_container->output_row($lang->downloads_dlmngr_filename, $lang->downloads_dlmngr_filename_desc, $form->generate_text_box('filename', $dlitem['filename'], array('id' => 'filename')), 'filename');
 // end the container
 $form_container->end();
 // add the save button
 $buttons[] = $form->generate_submit_button($lang->downloads_dlmngr_save);
 // display and end
 $form->output_submit_wrapper($buttons);
 $form->end();
Example #16
0
		<dt><label style="display: block;"><input type="radio" name="import" value="1" ' . $import_checked[2] . ' class="imports_check" onclick="checkAction(\'import\');" style="vertical-align: middle;" /> ' . $lang->url . '</label></dt>
		<dd style="margin-top: 0; margin-bottom: 0; width: 100%;" id="import_1" class="imports">
		<table cellpadding="4">
				<tr>
					<td>' . $form->generate_text_box("url", $mybb->input['file']) . '</td>
				</tr>
		</table></dd>
	</dl>
	<script type="text/javascript">
	checkAction(\'import\');
	</script>';
    $form_container = new FormContainer($lang->import_a_theme);
    $form_container->output_row($lang->import_from, $lang->import_from_desc, $actions, 'file');
    $form_container->output_row($lang->parent_theme, $lang->parent_theme_desc, $form->generate_select_box('tid', $themes, $mybb->input['tid'], array('id' => 'tid')), 'tid');
    $form_container->output_row($lang->new_name, $lang->new_name_desc, $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name');
    $form_container->output_row($lang->advanced_options, "", $form->generate_check_box('version_compat', '1', $lang->ignore_version_compatibility, array('checked' => $mybb->input['version_compat'], 'id' => 'version_compat')) . "<br /><small>{$lang->ignore_version_compat_desc}</small><br />" . $form->generate_check_box('import_stylesheets', '1', $lang->import_stylesheets, array('checked' => $mybb->input['import_stylesheets'], 'id' => 'import_stylesheets')) . "<br /><small>{$lang->import_stylesheets_desc}</small><br />" . $form->generate_check_box('import_templates', '1', $lang->import_templates, array('checked' => $mybb->input['import_templates'], 'id' => 'import_templates')) . "<br /><small>{$lang->import_templates_desc}</small>");
    $form_container->end();
    $buttons[] = $form->generate_submit_button($lang->import_theme);
    $form->output_submit_wrapper($buttons);
    $form->end();
    $page->output_footer();
}
if ($mybb->input['action'] == "export") {
    $plugins->run_hooks("admin_style_themes_export");
    $query = $db->simple_select("themes", "*", "tid='" . intval($mybb->input['tid']) . "'");
    $theme = $db->fetch_array($query);
    // Does the theme not exist?
    if (!$theme['tid']) {
        flash_message($lang->error_invalid_theme, 'error');
        admin_redirect("index.php?module=style-themes");
    }
Example #17
0
                $automatic_text_check = true;
                $text_display = 'display: none';
                $automatic_display = 'display: none;';
            }
        } else {
            if ($mybb->input['format'] == 1 && $mybb->input['type'] != 1) {
                $text_display = 'display: none;';
            } else {
                if ($mybb->input['format'] == 0 || $mybb->input['type'] == 1) {
                    $html_display = 'display: none';
                }
            }
        }
        echo "<div id=\"message_html\" style=\"{$html_display}\">";
        $form_container = new FormContainer("{$lang->send_mass_mail}: {$lang->step_one} - {$lang->define_html_message}");
        $form_container->output_row("{$lang->define_html_message_desc}:", $html_personalisation, $form->generate_text_area('htmlmessage', $input['htmlmessage'], array('id' => 'htmlmessage', 'rows' => 15, 'cols ' => 70, 'style' => 'width: 95%')) . "<div id=\"automatic_display\" style=\"{$automatic_display}\">" . $form->generate_check_box('automatic_text', 1, $lang->auto_gen_plain_text, array('checked' => $automatic_text_check, "id" => "automatic_text")) . "</div>");
        $form_container->end();
        echo "</div>";
        echo "<div id=\"message_text\" style=\"{$text_display}\">";
        $form_container = new FormContainer("{$lang->send_mass_mail}: {$lang->step_one} - {$lang->define_text_version}");
        $form_container->output_row("{$lang->define_text_version_desc}:", $text_personalisation, $form->generate_text_area('message', $input['message'], array('id' => 'message', 'rows' => 15, 'cols ' => 70, 'style' => 'width: 95%')));
        $form_container->end();
        echo "</div>";
        echo "\n\t\t<script type=\"text/javascript\">\n\t\tfunction ToggleFormat()\n\t\t{\n\t\t\tvar v = \$('format').options[\$('format').selectedIndex].value;\n\t\t\tif(v == 2)\n\t\t\t{\n\t\t\t\t\$('automatic_display').show();\n\t\t\t\t\$('message_html').show();\n\t\t\t\tif(\$('automatic_text').checked)\n\t\t\t\t{\n\t\t\t\t\t\$('message_text').hide();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t\$('message_text').show();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(v == 1)\n\t\t\t{\n\t\t\t\t\$('message_text').hide();\n\t\t\t\t\$('message_html').show();\n\t\t\t\t\$('automatic_display').hide();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t\$('message_text').show();\n\t\t\t\t\$('message_html').hide();\n\t\t\t}\n\t\t}\n\t\tEvent.observe(\$('format'), 'change', ToggleFormat);\n\n\t\tfunction ToggleType()\n\t\t{\n\t\t\tvar v = \$('type_pm').checked;\n\t\t\tif(v == true)\n\t\t\t{\n\t\t\t\t\$('message_html').hide();\n\t\t\t\t\$('message_text').show();\n\t\t\t\t\$('format_container').hide();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t\$('message_html').show();\n\t\t\t\t\$('format_container').show();\n\t\t\t\tToggleFormat();\n\t\t\t}\n\t\t}\n\t\tEvent.observe(\$('type_pm'), 'click', ToggleType);\n\t\tEvent.observe(\$('type_email'), 'click', ToggleType);\n\t\tToggleType();\n\n\t\tfunction ToggleAutomatic()\n\t\t{\n\t\t\tvar v = \$('automatic_text').checked;\n\t\t\tif(v == true)\n\t\t\t{\n\t\t\t\t\$('message_text').hide();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t\$('message_text').show();\n\t\t\t}\n\t\t}\n\n\t\tEvent.observe(\$('automatic_text'), 'click', ToggleAutomatic);\n\t\t\n\t\tfunction insertText(value, textarea)\n\t\t{\n\t\t\t// Internet Explorer\n\t\t\tif(document.selection)\n\t\t\t{\n\t\t\t\ttextarea.focus();\n\t\t\t\tvar selection = document.selection.createRange();\n\t\t\t\tselection.text = value;\n\t\t\t}\n\t\t\t// Firefox\n\t\t\telse if(textarea.selectionStart || textarea.selectionStart == '0')\n\t\t\t{\n\t\t\t\tvar start = textarea.selectionStart;\n\t\t\t\tvar end = textarea.selectionEnd;\n\t\t\t\ttextarea.value = textarea.value.substring(0, start)\t+ value\t+ textarea.value.substring(end, textarea.value.length);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttextarea.value += value;\n\t\t\t}\n\t\t}\n\t\t\n\t\t</script>";
        $buttons[] = $form->generate_submit_button($lang->next_step);
        $form->output_submit_wrapper($buttons);
        $form->end();
        $page->output_footer();
    }
}
if ($mybb->input['action'] == "delete") {
Example #18
0
         $sub_tabs['add_multiple'] = array('title' => $lang->add_multiple_post_icons, 'link' => "index.php?module=config/post_icons&amp;action=add_multiple", 'description' => $lang->add_multiple_post_icons_desc);
         $page->output_nav_tabs($sub_tabs, 'add_multiple');
         $form = new Form("index.php?module=config/post_icons&amp;action=add_multiple", "post", "add_multiple");
         echo $form->generate_hidden_field("step", "2");
         echo $form->generate_hidden_field("pathfolder", $path);
         $form_container = new FormContainer($lang->add_multiple_post_icons);
         $form_container->output_row_header($lang->image, array("class" => "align_center", 'width' => '10%'));
         $form_container->output_row_header($lang->name);
         $form_container->output_row_header($lang->add, array("class" => "align_center", 'width' => '5%'));
         foreach ($icons as $key => $file) {
             $ext = get_extension($file);
             $find = str_replace("." . $ext, "", $file);
             $name = ucfirst($find);
             $form_container->output_cell("<img src=\"../" . $path . $file . "\" alt=\"\" /><br /><small>{$file}</small>", array("class" => "align_center", "width" => 1));
             $form_container->output_cell($form->generate_text_box("name[{$file}]", $name, array('id' => 'name', 'style' => 'width: 98%')));
             $form_container->output_cell($form->generate_check_box("include[{$file}]", 1, "", array('checked' => 1)), array("class" => "align_center"));
             $form_container->construct_row();
         }
         if ($form_container->num_rows() == 0) {
             flash_message($lang->error_no_images, 'error');
             admin_redirect("index.php?module=config/post_icons&action=add_multiple");
         }
         $form_container->end();
         $buttons[] = $form->generate_submit_button($lang->save_post_icons);
         $form->output_submit_wrapper($buttons);
         $form->end();
         $page->output_footer();
         exit;
     }
 } else {
     $path = $mybb->input['pathfolder'];
Example #19
0
 if ($forum_data['type'] == "f") {
     $create_a_options_f['checked'] = true;
 } else {
     $create_a_options_c['checked'] = true;
 }
 $form_container = new FormContainer($lang->edit_forum);
 $form_container->output_row($lang->forum_type, $lang->forum_type_desc, $form->generate_radio_button('type', 'f', $lang->forum, $create_a_options_f) . "<br />\n" . $form->generate_radio_button('type', 'c', $lang->category, $create_a_options_c));
 $form_container->output_row($lang->title . " <em>*</em>", "", $form->generate_text_box('title', $forum_data['title'], array('id' => 'title')), 'title');
 $form_container->output_row($lang->description, "", $form->generate_text_area('description', $forum_data['description'], array('id' => 'description')), 'description');
 $form_container->output_row($lang->parent_forum . " <em>*</em>", $lang->parent_forum_desc, $form->generate_forum_select('pid', $forum_data['pid'], array('id' => 'pid', 'main_option' => $lang->none)), 'pid');
 $form_container->output_row($lang->display_order, "", $form->generate_numeric_field('disporder', $forum_data['disporder'], array('id' => 'disporder', 'min' => 0)), 'disporder');
 $form_container->end();
 $form_container = new FormContainer($lang->additional_forum_options);
 $form_container->output_row($lang->forum_link, $lang->forum_link_desc, $form->generate_text_box('linkto', $forum_data['linkto'], array('id' => 'linkto')), 'linkto');
 $form_container->output_row($lang->forum_password, $lang->forum_password_desc, $form->generate_text_box('password', $forum_data['password'], array('id' => 'password')), 'password');
 $access_options = array($form->generate_check_box('active', 1, $lang->forum_is_active . "<br />\n<small>{$lang->forum_is_active_desc}</small>", array('checked' => $forum_data['active'], 'id' => 'active')), $form->generate_check_box('open', 1, $lang->forum_is_open . "<br />\n<small>{$lang->forum_is_open_desc}</small>", array('checked' => $forum_data['open'], 'id' => 'open')));
 $form_container->output_row($lang->access_options, "", "<div class=\"forum_settings_bit\">" . implode("</div><div class=\"forum_settings_bit\">", $access_options) . "</div>");
 $styles = array('0' => $lang->use_default);
 $query = $db->simple_select("themes", "tid,name", "name!='((master))' AND name!='((master-backup))'", array('order_by' => 'name'));
 while ($style = $db->fetch_array($query)) {
     $styles[$style['tid']] = $style['name'];
 }
 $style_options = array($form->generate_check_box('overridestyle', 1, $lang->override_user_style, array('checked' => $forum_data['overridestyle'], 'id' => 'overridestyle')), $lang->forum_specific_style . "<br />\n" . $form->generate_select_box('style', $styles, $forum_data['style'], array('id' => 'style')));
 $form_container->output_row($lang->style_options, "", "<div class=\"forum_settings_bit\">" . implode("</div><div class=\"forum_settings_bit\">", $style_options) . "</div>");
 $display_methods = array('0' => $lang->dont_display_rules, '1' => $lang->display_rules_inline, '3' => $lang->display_rules_inline_new, '2' => $lang->display_rules_link);
 $forum_rules = array($lang->display_method . "<br />\n" . $form->generate_select_box('rulestype', $display_methods, $forum_data['rulestype'], array('checked' => $forum_data['rulestype'], 'id' => 'rulestype')), $lang->title . "<br />\n" . $form->generate_text_box('rulestitle', $forum_data['rulestitle'], array('checked' => $forum_data['rulestitle'], 'id' => 'rulestitle')), $lang->rules . "<br />\n" . $form->generate_text_area('rules', $forum_data['rules'], array('checked' => $forum_data['rules'], 'id' => 'rules')));
 $form_container->output_row($lang->forum_rules, "", "<div class=\"forum_settings_bit\">" . implode("</div><div class=\"forum_settings_bit\">", $forum_rules) . "</div>");
 $default_date_cut = array(0 => $lang->board_default, 1 => $lang->datelimit_1day, 5 => $lang->datelimit_5days, 10 => $lang->datelimit_10days, 20 => $lang->datelimit_20days, 50 => $lang->datelimit_50days, 75 => $lang->datelimit_75days, 100 => $lang->datelimit_100days, 365 => $lang->datelimit_lastyear, 9999 => $lang->datelimit_beginning);
 $default_sort_by = array("" => $lang->board_default, "subject" => $lang->sort_by_subject, "lastpost" => $lang->sort_by_lastpost, "starter" => $lang->sort_by_starter, "started" => $lang->sort_by_started, "rating" => $lang->sort_by_rating, "replies" => $lang->sort_by_replies, "views" => $lang->sort_by_views);
 $default_sort_order = array("" => $lang->board_default, "asc" => $lang->sort_order_asc, "desc" => $lang->sort_order_desc);
 $view_options = array($lang->default_date_cut . "<br />\n" . $form->generate_select_box('defaultdatecut', $default_date_cut, $forum_data['defaultdatecut'], array('checked' => $forum_data['defaultdatecut'], 'id' => 'defaultdatecut')), $lang->default_sort_by . "<br />\n" . $form->generate_select_box('defaultsortby', $default_sort_by, $forum_data['defaultsortby'], array('checked' => $forum_data['defaultsortby'], 'id' => 'defaultsortby')), $lang->default_sort_order . "<br />\n" . $form->generate_select_box('defaultsortorder', $default_sort_order, $forum_data['defaultsortorder'], array('checked' => $forum_data['defaultsortorder'], 'id' => 'defaultsortorder')));
function akismet_admin()
{
    global $mybb, $db, $page, $lang;
    if ($page->active_action != "akismet") {
        return;
    }
    $page->add_breadcrumb_item($lang->akismet);
    if ($mybb->input['delete_all'] && $mybb->request_method == "post") {
        // User clicked no
        if ($mybb->input['no']) {
            admin_redirect("index.php?module=forum-akismet");
        }
        if ($mybb->request_method == "post") {
            // Delete the template
            $db->delete_query("posts", "visible = '-4'");
            // Log admin action
            log_admin_action();
            flash_message($lang->success_deleted_spam, 'success');
            admin_redirect("index.php?module=forum-akismet");
        } else {
            $page->output_confirm_action("index.php?module=forum-akismet&amp;delete_all=1", $lang->confirm_spam_deletion);
        }
    }
    if ($mybb->input['unmark'] && $mybb->request_method == "post") {
        $unmark = $mybb->input['akismet'];
        if (empty($unmark)) {
            flash_message($lang->error_unmark, 'error');
            admin_redirect("index.php?module=forum-akismet");
        }
        $posts_in = '';
        $comma = '';
        foreach ($unmark as $key => $val) {
            $posts_in .= $comma . intval($key);
            $comma = ',';
        }
        $query = $db->simple_select("posts", "pid, tid", "pid IN ({$posts_in}) AND replyto = '0'");
        while ($post = $db->fetch_array($query)) {
            $threadp[] = $post['tid'];
        }
        if (!is_array($threadp)) {
            $threadp = array();
        }
        $thread_list = implode(',', $threadp);
        $query = $db->query("\r\n\t\t\tSELECT p.tid, f.usepostcounts, p.uid, p.fid, p.dateline, p.replyto, t.lastpost, t.lastposter, t.lastposteruid, t.subject\r\n\t\t\tFROM " . TABLE_PREFIX . "posts p\r\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\r\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "forums f ON (f.fid=p.fid)\r\n\t\t\tWHERE p.pid IN ({$posts_in}) AND p.visible = '-4'\r\n\t\t");
        while ($post = $db->fetch_array($query)) {
            // Fetch the last post for this forum
            $query2 = $db->query("\r\n\t\t\t\tSELECT tid, lastpost, lastposter, lastposteruid, subject\r\n\t\t\t\tFROM " . TABLE_PREFIX . "threads\r\n\t\t\t\tWHERE fid='{$post['fid']}' AND visible='1' AND closed NOT LIKE 'moved|%'\r\n\t\t\t\tORDER BY lastpost DESC\r\n\t\t\t\tLIMIT 0, 1\r\n\t\t\t");
            $lastpost = $db->fetch_array($query2);
            if ($post['lastpost'] > $lastpost['lastpost']) {
                $lastpost['lastpost'] = $post['lastpost'];
                $lastpost['lastposter'] = $post['lastposter'];
                $lastpost['lastposteruid'] = $post['lastposteruid'];
                $lastpost['subject'] = $post['subject'];
                $lastpost['tid'] = $post['tid'];
            }
            $update_count = array("lastpost" => intval($lastpost['lastpost']), "lastposter" => $db->escape_string($lastpost['lastposter']), "lastposteruid" => intval($lastpost['lastposteruid']), "lastposttid" => intval($lastpost['tid']), "lastpostsubject" => $db->escape_string($lastpost['subject']));
            $db->update_query("forums", $update_count, "fid='{$post['fid']}'");
            $query2 = $db->query("\r\n\t\t\t\tSELECT u.uid, u.username, p.username AS postusername, p.dateline\r\n\t\t\t\tFROM " . TABLE_PREFIX . "posts p\r\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=p.uid)\r\n\t\t\t\tWHERE p.tid='{$post['tid']}' AND p.visible='1' OR p.pid = '{$post['pid']}'\r\n\t\t\t\tORDER BY p.dateline DESC\r\n\t\t\t\tLIMIT 1");
            $lastpost = $db->fetch_array($query2);
            $query2 = $db->query("\r\n\t\t\t\tSELECT u.uid, u.username, p.username AS postusername, p.dateline\r\n\t\t\t\tFROM " . TABLE_PREFIX . "posts p\r\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=p.uid)\r\n\t\t\t\tWHERE p.tid='{$post['tid']}'\r\n\t\t\t\tORDER BY p.dateline ASC\r\n\t\t\t\tLIMIT 0,1\r\n\t\t\t");
            $firstpost = $db->fetch_array($query2);
            if (!$firstpost['username']) {
                $firstpost['username'] = $firstpost['postusername'];
            }
            if (!$lastpost['username']) {
                $lastpost['username'] = $lastpost['postusername'];
            }
            if (!$lastpost['dateline']) {
                $lastpost['username'] = $firstpost['username'];
                $lastpost['uid'] = $firstpost['uid'];
                $lastpost['dateline'] = $firstpost['dateline'];
            }
            $lastpost['username'] = $db->escape_string($lastpost['username']);
            $firstpost['username'] = $db->escape_string($firstpost['username']);
            $query2 = $db->simple_select("users", "akismetstopped", "uid='{$post['uid']}'");
            $akismetstopped = $db->fetch_field($query2, "akismetstopped") - 1;
            if ($akismetstopped < 0) {
                $akismetstopped = 0;
            }
            $db->update_query("users", array('akismetstopped' => $akismetstopped), "uid='{$post['uid']}'");
            $update_array = array('username' => $firstpost['username'], 'uid' => intval($firstpost['uid']), 'lastpost' => intval($lastpost['dateline']), 'lastposter' => $lastpost['username'], 'lastposteruid' => intval($lastpost['uid']));
            $db->update_query("threads", $update_array, "tid='{$post['tid']}'");
            if ($post['usepostcounts'] != 0) {
                $db->write_query("UPDATE " . TABLE_PREFIX . "users SET postnum=postnum+1 WHERE uid = '{$post['uid']}'");
            }
            $newthreads = $newreplies = 0;
            if ($post['replyto'] == 0) {
                ++$newthreads;
            } else {
                ++$newreplies;
            }
            update_thread_counters($post['tid'], array('replies' => '+' . $newreplies));
            update_forum_counters($post['fid'], array('threads' => '+' . $newthreads, 'posts' => '+1'));
        }
        $approve = array("visible" => 1);
        if ($thread_list) {
            $db->update_query("threads", $approve, "tid IN ({$thread_list})");
        }
        $db->update_query("posts", $approve, "pid IN ({$posts_in})");
        // Log admin action
        log_admin_action();
        flash_message($lang->success_unmarked, 'success');
        admin_redirect("index.php?module=forum-akismet");
    }
    if ($mybb->input['delete'] && $mybb->request_method == "post") {
        $deletepost = $mybb->input['akismet'];
        if (empty($deletepost)) {
            flash_message($lang->error_deletepost, 'error');
            admin_redirect("index.php?module=forum-akismet");
        }
        $posts_in = '';
        $comma = '';
        foreach ($deletepost as $key => $val) {
            $posts_in .= $comma . intval($key);
            $comma = ',';
        }
        $query = $db->simple_select("posts", "pid, tid", "pid IN ({$posts_in}) AND replyto = '0'");
        while ($post = $db->fetch_array($query)) {
            $threadp[$post['pid']] = $post['tid'];
        }
        if (!is_array($threadp)) {
            $threadp = array();
        }
        require_once MYBB_ROOT . "inc/functions_upload.php";
        foreach ($deletepost as $pid => $val) {
            if (array_key_exists($pid, $threadp)) {
                $db->delete_query("posts", "pid IN ({$posts_in})");
                $db->delete_query("attachments", "pid IN ({$posts_in})");
                // Get thread info
                $query = $db->simple_select("threads", "poll", "tid='" . $threadp[$pid] . "'");
                $poll = $db->fetch_field($query, 'poll');
                // Delete threads, redirects, favorites, polls, and poll votes
                $db->delete_query("threads", "tid='" . $threadp[$pid] . "'");
                $db->delete_query("threads", "closed='moved|" . $threadp[$pid] . "'");
                $db->delete_query("threadsubscriptions", "tid='" . $threadp[$pid] . "'");
                $db->delete_query("polls", "tid='" . $threadp[$pid] . "'");
                $db->delete_query("pollvotes", "pid='{$poll}'");
            }
            // Remove attachments
            remove_attachments($pid);
            // Delete the post
            $db->delete_query("posts", "pid='{$pid}'");
        }
        // Log admin action
        log_admin_action();
        flash_message($lang->success_spam_deleted, 'success');
        admin_redirect("index.php?module=forum-akismet");
    }
    if (!$mybb->input['action']) {
        require MYBB_ROOT . "inc/class_parser.php";
        $parser = new postParser();
        $page->output_header($lang->akismet);
        $form = new Form("index.php?module=forum-akismet", "post");
        $table = new Table();
        $table->construct_header($form->generate_check_box("checkall", 1, '', array('class' => 'checkall')), array('width' => '5%'));
        $table->construct_header("Title / Username / Post", array('class' => 'align_center'));
        $mybb->input['page'] = intval($mybb->input['page']);
        if ($mybb->input['page'] > 0) {
            $start = $mybb->input['page'] * 20;
        } else {
            $start = 0;
        }
        $query = $db->simple_select("posts", "COUNT(pid) as spam", "visible = '-4'");
        $total_rows = $db->fetch_field($query, 'spam');
        if ($start > $total_rows) {
            $start = $total_rows - 20;
        }
        if ($start < 0) {
            $start = 0;
        }
        $query = $db->simple_select("posts", "*", "visible = '-4'", array('limit_start' => $start, 'limit' => '20', 'order_by' => 'dateline', 'order_dir' => 'desc'));
        while ($post = $db->fetch_array($query)) {
            if ($post['uid'] != 0) {
                $username = "******"../" . str_replace("{uid}", $post['uid'], PROFILE_URL) . "\" target=\"_blank\">" . format_name($post['username'], $post['usergroup'], $post['displaygroup']) . "</a>";
            } else {
                $username = $post['username'];
            }
            $table->construct_cell($form->generate_check_box("akismet[{$post['pid']}]", 1, ''));
            $table->construct_cell("<span style=\"float: right;\">{$lang->username} {$username}</span> <span style=\"float: left;\">{$lang->title}: " . htmlspecialchars_uni($post['subject']) . " <strong>(" . my_date($mybb->settings['dateformat'], $post['dateline']) . ", " . my_date($mybb->settings['timeformat'], $post['dateline']) . ")</strong></span>");
            $table->construct_row();
            $parser_options = array("allow_html" => 0, "allow_mycode" => 0, "allow_smilies" => 0, "allow_imgcode" => 0, "me_username" => $post['username'], "filter_badwords" => 1);
            $post['message'] = $parser->parse_message($post['message'], $parser_options);
            $table->construct_cell($post['message'], array("colspan" => 2));
            $table->construct_row();
        }
        $num_rows = $table->num_rows();
        if ($num_rows == 0) {
            $table->construct_cell($lang->no_spam_found, array("class" => "align_center", "colspan" => 2));
            $table->construct_row();
        }
        $table->output($lang->detected_spam_messages);
        echo "<br />" . draw_admin_pagination($mybb->input['page'], 20, $total_rows, "index.php?module=forum-akismet&amp;page={page}");
        $buttons[] = $form->generate_submit_button($lang->unmark_selected, array('name' => 'unmark'));
        $buttons[] = $form->generate_submit_button($lang->deleted_selected, array('name' => 'delete'));
        if ($num_rows > 0) {
            $buttons[] = $form->generate_submit_button($lang->delete_all, array('name' => 'delete_all', 'onclick' => "return confirm('{$lang->confirm_spam_deletion}');"));
        }
        $form->output_submit_wrapper($buttons);
        $form->end();
        $page->output_footer();
    }
    exit;
}
Example #21
0
 $tabs = array("general" => $lang->general, "forums_posts" => $lang->forums_posts, "users_permissions" => $lang->users_permissions, "misc" => $lang->misc);
 $plugins->run_hooks_by_ref("admin_user_groups_edit_graph_tabs", $tabs);
 $page->output_tab_control($tabs);
 echo "<div id=\"tab_general\">";
 $form_container = new FormContainer($lang->general);
 $form_container->output_row($lang->title . " <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 $form_container->output_row($lang->short_description, "", $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
 $form_container->output_row($lang->username_style, $lang->username_style_desc, $form->generate_text_box('namestyle', $mybb->input['namestyle'], array('id' => 'namestyle')), 'namestyle');
 $form_container->output_row($lang->user_title, $lang->user_title_desc, $form->generate_text_box('usertitle', $mybb->input['usertitle'], array('id' => 'usertitle')), 'usertitle');
 $stars = "<table cellpadding=\"3\"><tr><td>" . $form->generate_text_box('stars', $mybb->input['stars'], array('class' => 'field50', 'id' => 'stars')) . "</td><td>" . $form->generate_text_box('starimage', $mybb->input['starimage'], array('id' => 'starimage')) . "</td></tr>";
 $stars .= "<tr><td><small>{$lang->stars}</small></td><td><small>{$lang->star_image}</small></td></tr></table>";
 $form_container->output_row($lang->user_stars, $lang->user_stars_desc, $stars, "stars");
 $form_container->output_row($lang->group_image, $lang->group_image_desc, $form->generate_text_box('image', $mybb->input['image'], array('id' => 'image')), 'image');
 $general_options = array();
 if ($usergroup['gid'] != "1" && $usergroup['gid'] != "5") {
     $general_options[] = $form->generate_check_box("showforumteam", 1, $lang->forum_team, array("checked" => $mybb->input['showforumteam']));
 }
 $general_options[] = $form->generate_check_box("isbannedgroup", 1, $lang->is_banned_group, array("checked" => $mybb->input['isbannedgroup']));
 $form_container->output_row($lang->general_options, "", "<div class=\"group_settings_bit\">" . implode("</div><div class=\"group_settings_bit\">", $general_options) . "</div>");
 if ($usergroup['type'] != 1) {
     $public_options = array($form->generate_check_box("joinable", 1, $lang->user_joinable, array("checked" => $mybb->input['joinable'])), $form->generate_check_box("moderate", 1, $lang->moderate_join_requests, array("checked" => $mybb->input['moderate'])), $form->generate_check_box("candisplaygroup", 1, $lang->can_set_as_display_group, array("checked" => $mybb->input['candisplaygroup'])));
     $form_container->output_row($lang->publicly_joinable_options, "", "<div class=\"group_settings_bit\">" . implode("</div><div class=\"group_settings_bit\">", $public_options) . "</div>");
 }
 $admin_options = array($form->generate_check_box("issupermod", 1, $lang->is_super_mod, array("checked" => $mybb->input['issupermod'])), $form->generate_check_box("canmodcp", 1, $lang->can_access_mod_cp, array("checked" => $mybb->input['canmodcp'])), $form->generate_check_box("cancp", 1, $lang->can_access_admin_cp, array("checked" => $mybb->input['cancp'])));
 $form_container->output_row($lang->moderation_administration_options, "", "<div class=\"group_settings_bit\">" . implode("</div><div class=\"group_settings_bit\">", $admin_options) . "</div>");
 $form_container->end();
 echo "</div>";
 //
 // FORUMS AND POSTS
 //
 echo "<div id=\"tab_forums_posts\">";