function tdomf_show_form_hacker()
{
    global $wp_version;
    $form_id = false;
    if (isset($_REQUEST['form'])) {
        $form_id = $_REQUEST['form'];
    } else {
        $form_id = tdomf_get_first_form_id();
    }
    if ($form_id == false || !tdomf_form_exists($form_id)) {
        ?>
    <div class="wrap">
       <h2><?php 
        _e('Form Hacker', 'tdomf');
        ?>
</h2>
       <p><?php 
        if (is_numeric($form_id)) {
            printf(__('Invalid Form ID %s specified!'), $form_id);
        } else {
            _e('No Form ID specified!');
        }
        ?>
</p>
    </div>
  <?php 
    } else {
        if (isset($_REQUEST['diff'])) {
            ?>
    <div class="wrap">
          <?php 
            tdomf_form_hacker_diff($form_id);
            ?>
    </div> <!-- wrap -->
  <?php 
        } else {
            $mode = tdomf_generate_default_form_mode($form_id);
            $mode .= '-hack';
            tdomf_form_hacker_actions($form_id);
            $message = tdomf_get_error_messages(true, $form_id);
            if (!empty($message)) {
                ?>
        <div id="message" class="updated fade"><p><?php 
                echo $message;
                ?>
</p></div>
    <?php 
            }
            tdomf_forms_top_toolbar($form_id, 'tdomf_show_form_hacker');
            $form_ids = tdomf_get_form_ids();
            ?>
        
        <div class="wrap">
        <?php 
            if (!isset($_REQUEST['text'])) {
                ?>
          <h2><?php 
                printf(__("Form Hacker for Form %d: \"%s\"", "tdomf"), $form_id, tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id));
                ?>
</h2>            
        <?php 
            } else {
                ?>
          <h2><?php 
                printf(__("Message Hacker for Form %d: \"%s\"", "tdomf"), $form_id, tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id));
                ?>
</h2>            
        <?php 
            }
            ?>

          <script type="text/javascript">
            function tdomfHideHelp() {
                jQuery('#tdomf_help').attr('class','hidden');
                jQuery('#tdomf_show_help').attr('class','');
                jQuery('#tdomf_hide_help').attr('class','hidden');
            }
            function tdomfShowHelp() {
                jQuery('#tdomf_help').attr('class','');
                jQuery('#tdomf_show_help').attr('class','hidden');
                jQuery('#tdomf_hide_help').attr('class','');
            }
          </script>
          
          <?php 
            tdomf_forms_under_title_toolbar($form_id, 'tdomf_show_form_hacker');
            ?>
    
          <?php 
            if (isset($_REQUEST['text'])) {
                ?>
           
          <!-- <div id="tdomf_help" class='hidden'> -->
          
          <?php 
                $code_on = false;
                if (isset($_REQUEST['code'])) {
                    $code_on = true;
                }
                ?>
          
          <p><?php 
                _e("You can use this page to modify any messages outputed from TDOMF for your form. From here you can change the post published messages, post held in moderation, etc. etc.", "tdomf");
                ?>
</p>
            
          <?php 
                if (version_compare($wp_version, "2.8-beta2", ">=")) {
                    if (!$code_on) {
                        ?>
              <p><a href="admin.php?page=tdomf_show_form_hacker&text&code&form=<?php 
                        echo $form_id;
                        ?>
"><?php 
                        _e("Enable Code Syntax Highlighting...", 'tdomf');
                        ?>
</a></p>
          <?php 
                    } else {
                        ?>
              <p><a href="admin.php?page=tdomf_show_form_hacker&text&form=<?php 
                        echo $form_id;
                        ?>
"><?php 
                        _e("Disable Code Syntax Highlighting...", 'tdomf');
                        ?>
</a></p>
          <?php 
                    }
                }
                ?>
          
          <?php 
                $form_edit = tdomf_get_option_form(TDOMF_OPTION_FORM_EDIT, $form_id);
                ?>
 
          
          <p><?php 
                _e("PHP code can be included in the hacked messages. Also TDOMF will automatically expand these macro strings:", "tdomf");
                ?>
             <ul>
             <li><?php 
                printf(__("<code>%s</code> - User name of the currently logged in user", "tdomf"), TDOMF_MACRO_USERNAME);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - IP of the current visitor", "tdomf"), TDOMF_MACRO_IP);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - The ID of the current form (which is currently %d)", "tdomf"), TDOMF_MACRO_FORMID, $form_id);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Name of the Form (set in options)", "tdomf"), TDOMF_MACRO_FORMNAME);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Form Description (set in options)", "tdomf"), TDOMF_MACRO_FORMDESCRIPTION);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Submission Errors", "tdomf"), TDOMF_MACRO_SUBMISSIONERRORS);
                ?>
             <?php 
                if ($form_edit) {
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - URL of Post/Page being edited", "tdomf"), TDOMF_MACRO_SUBMISSIONURL);
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - Original Submission Date", "tdomf"), TDOMF_MACRO_SUBMISSIONDATE);
                    ?>
             
             <li><?php 
                    printf(__("<code>%s</code> - Original Submission Time", "tdomf"), TDOMF_MACRO_SUBMISSIONTIME);
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - Title of Post/Page being edited", "tdomf"), TDOMF_MACRO_SUBMISSIONTITLE);
                    ?>
             <?php 
                } else {
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - URL of Submission", "tdomf"), TDOMF_MACRO_SUBMISSIONURL);
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - Date of Submission", "tdomf"), TDOMF_MACRO_SUBMISSIONDATE);
                    ?>
             
             <li><?php 
                    printf(__("<code>%s</code> - Time of Submission", "tdomf"), TDOMF_MACRO_SUBMISSIONTIME);
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - Title of Submission", "tdomf"), TDOMF_MACRO_SUBMISSIONTITLE);
                    ?>
             <?php 
                }
                ?>
             </ul>
          </p>
          
          <!-- </div> -->
          
          <form method="post" name="formhackermsgs" id="formhackermsgs">
          <?php 
                if (function_exists('wp_nonce_field')) {
                    wp_nonce_field('tdomf-form-hacker');
                }
                ?>
          
          <p class="submit">
          <input type="submit" value="<?php 
                _e('Save &raquo;', 'tdomf');
                ?>
" id="tdomf_hack_messages_save" name="tdomf_hack_messages_save" />
          <input type="submit" value="<?php 
                _e('Reset &raquo;', 'tdomf');
                ?>
" id="tdomf_hack_messages_reset" name="tdomf_hack_messages_reset" />
          </p>
          
          <?php 
                if (!tdomf_get_option_form(TDOMF_OPTION_MODERATION, $form_id) && !tdomf_get_option_form(TDOMF_OPTION_REDIRECT, $form_id)) {
                    ?>
              <h3><?php 
                    if ($form_edit) {
                        _e('Contribution Approved', 'tdomf');
                    } else {
                        _e('Submission Published', 'tdomf');
                    }
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_publish" id="tdomf_msg_sub_publish" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_PUBLISH, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
                    
          <?php 
                if (intval(tdomf_get_option_form(TDOMF_OPTION_QUEUE_PERIOD, $form_id)) > 0 && !tdomf_get_option_form(TDOMF_OPTION_MODERATION, $form_id)) {
                    ?>
              <h3><?php 
                    _e('Submission Queued', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_future" id="tdomf_msg_sub_future" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_FUTURE, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <?php 
                if (get_option(TDOMF_OPTION_SPAM)) {
                    ?>
              <h3><?php 
                    if ($form_edit) {
                        _e('Contribution is Spam', 'tdomf');
                    } else {
                        _e('Submission is Spam', 'tdomf');
                    }
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_spam" id="tdomf_msg_sub_spam" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_SPAM, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <?php 
                if (tdomf_get_option_form(TDOMF_OPTION_MODERATION, $form_id)) {
                    ?>
              <h3><?php 
                    if ($form_edit) {
                        _e('Contribution awaiting Moderation', 'tdomf');
                    } else {
                        _e('Submission awaiting Moderation', 'tdomf');
                    }
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_mod" id="tdomf_msg_sub_mod" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_MOD, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <h3><?php 
                if ($form_edit) {
                    _e('Contribution contains Errors', 'tdomf');
                } else {
                    _e('Submission contains Errors', 'tdomf');
                }
                ?>
</h3>
          <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_error" id="tdomf_msg_sub_error" <?php 
                if ($code_on) {
                    ?>
class="codepress .php"<?php 
                }
                ?>
 ><?php 
                echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_ERROR, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                ?>
</textarea>
          <br/><br/>
          
          <h3><?php 
                _e('Banned User', 'tdomf');
                ?>
</h3>
          <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_banned_user" id="tdomf_msg_perm_banned_user" <?php 
                if ($code_on) {
                    ?>
class="codepress .php"<?php 
                }
                ?>
 ><?php 
                echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_BANNED_USER, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                ?>
</textarea>
          <br/><br/>

          <h3><?php 
                _e('Banned IP', 'tdomf');
                ?>
</h3>          
          <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_banned_ip" id="tdomf_msg_perm_banned_ip" <?php 
                if ($code_on) {
                    ?>
class="codepress .php"<?php 
                }
                ?>
 ><?php 
                echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_BANNED_IP, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                ?>
</textarea>
          <br/><br/>
          
          <?php 
                $throttle_rules = tdomf_get_option_form(TDOMF_OPTION_THROTTLE_RULES, $form_id);
                if (is_array($throttle_rules) && !empty($throttle_rules)) {
                    ?>
              <h3><?php 
                    _e('Throttled Submission', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_throttle" id="tdomf_msg_perm_throttle" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_THROTTLE, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <?php 
                if (!tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id)) {
                    ?>
              <h3><?php 
                    _e('Denied User', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_invalid_user" id="tdomf_msg_perm_invalid_user" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_INVALID_USER, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <?php 
                if (!tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id)) {
                    ?>
              <h3><?php 
                    _e('Banned Unregistered User', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_invalid_nouser" id="tdomf_msg_perm_invalid_nouser" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_INVALID_NOUSER, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>

          <?php 
                if ($form_edit) {
                    ?>

              <?php 
                    /*if(tdomf_get_option_form(TDOMF_OPTION_AJAX_EDIT,$form_id)) {*/
                    ?>
              
                 <h3><?php 
                    _e('\'Edit Post\' Link Text', 'tdomf');
                    ?>
</h3>
                 <textarea title="true" rows="5" cols="70" name="tdomf_msg_edit_post_link" id="tdomf_msg_edit_post_link" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_ADD_EDIT_LINK_TEXT, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
                 <br/><br/>
             
              <?php 
                    /*}*/
                    ?>
              
              <h3><?php 
                    _e('Invalid Post for Form', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_invalid_post" id="tdomf_msg_invalid_post" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_INVALID_POST, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
              
              <h3><?php 
                    _e('Invalid Form for Post', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_invalid_form" id="tdomf_msg_invalid_form" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_INVALID_FORM, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
              
              <h3><?php 
                    _e('Locked Post', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_locked_post" id="tdomf_msg_locked_post" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_LOCKED_POST, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
              
              <?php 
                    if (get_option(TDOMF_OPTION_SPAM)) {
                        ?>

                 <h3><?php 
                        _e('Spam Edit on Post', 'tdomf');
                        ?>
</h3>
                 <textarea title="true" rows="5" cols="70" name="tdomf_msg_spam_edit_on_post" id="tdomf_msg_spam_edit_on_post" <?php 
                        if ($code_on) {
                            ?>
class="codepress .php"<?php 
                        }
                        ?>
 ><?php 
                        echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SPAM_EDIT_ON_POST, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                        ?>
</textarea>
                 <br/><br/>
                  
              <?php 
                    }
                    ?>
              
             <h3><?php 
                    _e('Unapproved Edit on Post', 'tdomf');
                    ?>
</h3>
             <textarea title="true" rows="5" cols="70" name="tdomf_msg_unapproved_edit_on_post" id="tdomf_msg_unapproved_edit_on_post" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_UNAPPROVED_EDIT_ON_POST, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
             <br/><br/>

          <?php 
                }
                ?>
          
          <?php 
                do_action('tdomf_form_hacker_messages_bottom', $form_id, $mode);
                ?>
                    
          <span class="submit">
          <input type="submit" value="<?php 
                _e('Save &raquo;', 'tdomf');
                ?>
" id="tdomf_hack_messages_save" name="tdomf_hack_messages_save" />
          <input type="submit" value="<?php 
                _e('Reset &raquo;', 'tdomf');
                ?>
" id="tdomf_hack_messages_reset" name="tdomf_hack_messages_reset" />
          </span>
          
          </form>
          
          <?php 
            } else {
                ?>
          
          <!-- <div id="tdomf_help" class='hidden'> -->
          
          <p><?php 
                _e("You can use this page to hack the generated HTML code for your form without modifing the code of TDOMF. Please only do this if you know what you are doing. From here you can modify titles, default values, re-arrange fields, etc. etc.", "tdomf");
                ?>
</p>
             
          <p><?php 
                _e('Do not modify or remove the "name" and "id" attributes of fields as this is what the widgets and TDOMF use to get input values for processing', 'tdomf');
                ?>
</p>
             
          <p><?php 
                printf(__("Every time a form is generated, it creates a unique key. If you hack the form, make sure you keep <code>%s</code> (and also <code>%s</code>) within the form. TDOMF will replace this string with the unique key.", "tdomf"), TDOMF_MACRO_FORMKEY, TDOMF_MACRO_FORMURL);
                ?>
</p>
          
          <p><?php 
                _e("PHP code can be included in the hacked form. Also TDOMF will automatically expand these macro strings:", "tdomf");
                ?>
             <ul>
             <li><?php 
                printf(__("<code>%s</code> - User name of the currently logged in user", "tdomf"), TDOMF_MACRO_USERNAME);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - IP of the current visitor", "tdomf"), TDOMF_MACRO_IP);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - The form's unique key", "tdomf"), TDOMF_MACRO_FORMKEY);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - The current URL of the form", "tdomf"), TDOMF_MACRO_FORMURL);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - The ID of the current form (which is currently %d)", "tdomf"), TDOMF_MACRO_FORMID, $form_id);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Name of the Form (set in options)", "tdomf"), TDOMF_MACRO_FORMNAME);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Form Description (set in options)", "tdomf"), TDOMF_MACRO_FORMDESCRIPTION);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Form Output (such as preview, errors, etc.). This is automatically encapsulated in a div called tdomf_form_message (and tdomf_form_preview for preview)", "tdomf"), TDOMF_MACRO_FORMMESSAGE);
                ?>
             <li><?php 
                printf(__("<code>%swidget-name%s</code> - Original, unmodified output from 'widget-name'", "tdomf"), TDOMF_MACRO_WIDGET_START, TDOMF_MACRO_END);
                ?>
             </ul>
          </p>
          
          <!-- </div> -->
 
          <form method="post" name="formhacker" id="formhacker">
          <?php 
                if (function_exists('wp_nonce_field')) {
                    wp_nonce_field('tdomf-form-hacker');
                }
                ?>
      
          <p class="submit">
          <input type="submit" value="<?php 
                _e('Save &raquo;', 'tdomf');
                ?>
" id="tdomf_form_hack_save" name="tdomf_form_hack_save" />
          <input type="submit" value="<?php 
                _e('Reset &raquo;', 'tdomf');
                ?>
" id="tdomf_form_hack_reset" name="tdomf_form_hack_reset" />
          </p>
          
          <?php 
                if (tdomf_widget_is_preview_avaliable($form_id)) {
                    ?>
          
              <h3><?php 
                    _e('Core Form', 'tdomf');
                    ?>
</h3>
              
          <?php 
                }
                ?>
          
            <?php 
                $cur_form = tdomf_generate_form($form_id, $mode);
                $form = $cur_form;
                $hacked_form = tdomf_get_option_form(TDOMF_OPTION_FORM_HACK, $form_id);
                if ($hacked_form != false) {
                    $form = $hacked_form;
                }
                ?>
                  
            <?php 
                if ($hacked_form != false) {
                    ?>
              <?php 
                    _e("You can diff the hacked form to see what you have changed", "tdomf");
                    ?>
              <ul>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                    echo $form_id;
                    ?>
&mode=<?php 
                    echo $mode;
                    ?>
&diff&form1=hack&form2=cur"><?php 
                    _e("Diff Hacked Form with Current Form", "tdomf");
                    ?>
</a></li>
              <?php 
                    $org_form = tdomf_get_option_form(TDOMF_OPTION_FORM_HACK_ORIGINAL, $form_id);
                    if (trim($cur_form) != trim($org_form)) {
                        ?>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                        echo $form_id;
                        ?>
&mode=<?php 
                        echo $mode;
                        ?>
&diff&form2=hack&form1=org"><?php 
                        _e("Diff Hacked Form with Previous Form", "tdomf");
                        ?>
</a></li>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                        echo $form_id;
                        ?>
&mode=<?php 
                        echo $mode;
                        ?>
&diff&form2=cur&form1=org"><?php 
                        _e("Diff Current Form with Previous Form", "tdomf");
                        ?>
</a></li>
                    <?php 
                    }
                    ?>
              </ul>
            <?php 
                }
                ?>
                  
            <textarea title="true" rows="30" cols="100" name="tdomf_form_hack" id="tdomf_form_hack" class="codepress .php" ><?php 
                echo htmlentities($form, ENT_NOQUOTES, get_bloginfo('charset'));
                ?>
</textarea>
            
          <br/><br/>
          
          <?php 
                if (tdomf_widget_is_preview_avaliable($form_id)) {
                    ?>
          
              <h3><?php 
                    _e('Form Preview', 'tdomf');
                    ?>
</h3>
              
              <?php 
                    $cur_preview = tdomf_preview_form(array('tdomf_form_id' => $form_id), $mode);
                    $preview = $cur_preview;
                    $hacked_preview = tdomf_get_option_form(TDOMF_OPTION_FORM_PREVIEW_HACK, $form_id);
                    if ($hacked_preview != false) {
                        $preview = $hacked_preview;
                    }
                    ?>
              
              <?php 
                    if ($hacked_preview != false) {
                        ?>
              <?php 
                        _e("You can diff the hacked preview to see what you have changed", "tdomf");
                        ?>
              <ul>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                        echo $form_id;
                        ?>
&mode=<?php 
                        echo $mode;
                        ?>
&diff&form1=hack&form2=cur&type=preview"><?php 
                        _e("Diff Hacked Preview with Current Preview", "tdomf");
                        ?>
</a></li>
              <?php 
                        $org_preview = tdomf_get_option_form(TDOMF_OPTION_FORM_PREVIEW_HACK_ORIGINAL, $form_id);
                        if (trim($cur_preview) != trim($org_preview)) {
                            ?>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                            echo $form_id;
                            ?>
&mode=<?php 
                            echo $mode;
                            ?>
&diff&form2=hack&form1=org&type=preview"><?php 
                            _e("Diff Hacked Preview with Previous Preview", "tdomf");
                            ?>
</a></li>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                            echo $form_id;
                            ?>
&mode=<?php 
                            echo $mode;
                            ?>
&diff&form2=cur&form1=org&type=preview"><?php 
                            _e("Diff Current Preview with Previous Preview", "tdomf");
                            ?>
</a></li>
                    <?php 
                        }
                        ?>
              </ul>
            <?php 
                    }
                    ?>
                    
                    
              <textarea title="true" rows="15" cols="100" name="tdomf_form_preview_hack" id="tdomf_form_preview_hack" class="codepress .php"><?php 
                    echo htmlentities($preview, ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
                
              <br/><br/>
                
          <?php 
                }
                ?>

          <!-- @TODO Validation Message Hacker -->
          <!-- @TODO Upload Form Hacker -->     
          <?php 
                do_action('tdomf_form_hacker_bottom', $form_id, $mode);
                ?>
          
          <span class="submit">
          <input type="submit" value="<?php 
                _e('Save &raquo;', 'tdomf');
                ?>
" id="tdomf_form_hack_save" name="tdomf_form_hack_save" />
          <input type="submit" value="<?php 
                _e('Reset &raquo;', 'tdomf');
                ?>
" id="tdomf_form_hack_reset" name="tdomf_form_hack_reset" />
          </span>
          
          </form>
          
          <!-- @TODO: warning about updated form (with dismiss link) -->
          
          <?php 
            }
            ?>
          
        </div>
    <?php 
        }
    }
}
function tdomf_show_form_export($form_id)
{
    if (!tdomf_form_exists($form_id)) {
        ?>
    <div><font color="red"><?php 
        printf(__("Form id %d does not exist!", "tdomf"), $form_id);
        ?>
</font></div>
  <?php 
    } else {
        ?>
    
    <div class="wrap">
    
    <h2><?php 
        printf(__("Export and Import Form %d Configuration:\"%s\"", "tdomf"), $form_id, tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id));
        ?>
</h2>
    
    <?php 
        tdomf_forms_under_title_toolbar($form_id, 'tdomf_show_form_export_menu');
        ?>
      
     <?php 
        $export_url = get_bloginfo('wpurl') . "?tdomf_export={$form_id}";
        $export_url = wp_nonce_url($export_url, 'tdomf-export-' . $form_id);
        ?>
    
     <p>
        <?php 
        printf(__('To export the configuration of this file, just <a href="%s">save this link</a>. To import, just use the form below to select a previousily exported file and click "Import"', "tdomf"), $export_url);
        ?>
     </p>
     </p>
    
     <form enctype="multipart/form-data" method="post" action="admin.php?page=tdomf_show_form_export_menu&form=<?php 
        echo $form_id;
        ?>
">
        <label for="import_file"><b><?php 
        _e("Form saved configuration to import: ");
        ?>
</b></label>
        <!-- <input type="hidden" name="MAX_FILE_SIZE" value="3000000" /> -->
        <input type="hidden" name='form_id' id='form_id' value='<?php 
        echo $form_id;
        ?>
'>
        <input type='file' name='import_file' id='import_file' size='30' />
        <input type="submit" name="tdomf_import" id="tdomf_import" value="<?php 
        _e("Import", "tdomf");
        ?>
" />
        <?php 
        wp_nonce_field('tdomf-import-' . $form_id);
        ?>
     </form>
     
  </div> <!-- wrap -->
  
  <?php 
    }
}
function tdomf_show_form_options($form_id)
{
    global $wp_version;
    if (!tdomf_form_exists($form_id)) {
        ?>
    <div class="wrap"><font color="red"><?php 
        printf(__("Form id %d does not exist!", "tdomf"), $form_id);
        ?>
</font></div>
  <?php 
    } else {
        ?>
    
    <?php 
        $pages = tdomf_get_option_form(TDOMF_OPTION_CREATEDPAGES, $form_id);
        $updated_pages = false;
        if ($pages != false) {
            $updated_pages = array();
            foreach ($pages as $page_id) {
                if (get_permalink($page_id) != false) {
                    $updated_pages[] = $page_id;
                }
            }
            if (count($updated_pages) == 0) {
                $updated_pages = false;
            }
            tdomf_set_option_form(TDOMF_OPTION_CREATEDPAGES, $updated_pages, $form_id);
        }
        ?>

    
    <div class="wrap">
    
    <h2><?php 
        printf(__("Form %d Options", "tdomf"), $form_id);
        ?>
</h2>
    
    <?php 
        tdomf_forms_under_title_toolbar($form_id);
        ?>
     
          <?php 
        if ($updated_pages == false) {
            ?>
          
             <?php 
            $create_form_link = "admin.php?page=tdomf_show_form_options_menu&action=create_form_page&form={$form_id}";
            if (function_exists('wp_nonce_url')) {
                $create_form_link = wp_nonce_url($create_form_link, 'tdomf-create-form-page');
            }
            ?>
    <p><a href="<?php 
            echo $create_form_link;
            ?>
"><?php 
            _e("Create a page with this form automatically &raquo;", "tdomf");
            ?>
</a></p>
          <?php 
        }
        ?>
          
    <?php 
        if (tdomf_wp23()) {
            ?>
          <p><a href="admin.php?page=tdomf_show_form_menu&form=<?php 
            echo $form_id;
            ?>
"><?php 
            printf(__("Widgets for Form %d &raquo;", "tdomf"), $form_id);
            ?>
</a></p>
    <?php 
        }
        ?>
    
    <br/>
    
    <form method="post" action="admin.php?page=tdomf_show_form_options_menu&form=<?php 
        echo $form_id;
        ?>
">

    <input type="hidden" id="tdomf_form_id" name="tdomf_form_id" value="<?php 
        echo $form_id;
        ?>
" />
    <?php 
        if (function_exists('wp_nonce_field')) {
            wp_nonce_field('tdomf-options-save');
        }
        ?>
    
    <div id="form_options_tabs" class="tabs">
    <ul>
        <li><a href="#form_gen"><span><?php 
        _e('General', 'tdomf');
        ?>
</span></a></li>
        <li><a href="#form_access"><span><?php 
        _e('Access Control', 'tdomf');
        ?>
</span></a></li>
        <li><a href="#form_new"><span><?php 
        _e('Submitting', 'tdomf');
        ?>
</span></a></li>
        <li><a href="#form_edit"><span><?php 
        _e('Editing', 'tdomf');
        ?>
</span></a></li>
        <li><a href="#form_moderation"><span><?php 
        _e('Moderation', 'tdomf');
        ?>
</span></a></li>
        <li><a href="#form_throttling"><span><?php 
        _e('Throttling', 'tdomf');
        ?>
</span></a></li>
        <li><a href="#form_spam"><span><?php 
        _e('Spam Protection', 'tdomf');
        ?>
</span></a></li>
    </ul>

    <div id="form_gen">

<?php 
        $form_name = tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id);
        ?>
    <p>
        <label for="tdomf_form_name">
            <?php 
        _e("Form Name:", "tdomf");
        ?>
        </label>
        <input type="text" name="tdomf_form_name" id="tdomf_form_name" value="<?php 
        if ($form_name) {
            echo htmlentities(stripslashes($form_name), ENT_QUOTES, get_bloginfo('charset'));
        }
        ?>
" />
	</p>    
     
   <?php 
        $form_descp = tdomf_get_option_form(TDOMF_OPTION_DESCRIPTION, $form_id);
        ?>
   <p>
        <label for="tdomf_form_descp">   
            <?php 
        _e('Form Description', "tdomf");
        ?>
<br/>
        </label>
        <textarea cols="80" rows="3" name="tdomf_form_descp" id="tdomf_form_descp"><?php 
        if ($form_descp) {
            echo htmlentities(stripslashes($form_descp), ENT_NOQUOTES, get_bloginfo('charset'));
        }
        ?>
</textarea>
   </p>

    <script type="text/javascript">
         //<![CDATA[
        
          function tdomf_enable_use_type_posts() {
            var flag = document.getElementById("tdomf_use_type_posts").checked;
            var flag_edit = document.getElementById("tdomf_mode_edit").checked;
            var flag_new = document.getElementById("tdomf_mode_new").checked;
            if(flag_new) {
                document.getElementById("tdomf_def_cat").disabled = !flag;
            }
            if(flag_edit) {
                //document.getElementById("tdomf_edit_cat_only").disabled = !flag;
                document.getElementById("tdomf_edit_cats").disabled = !flag;
            }
          }
          
          function tdomf_enable_edit() {
            var flag = !document.getElementById("tdomf_mode_edit").checked;
            var flag_posts = document.getElementById("tdomf_use_type_posts").checked;
            
            // disable 'new' options
            
            var flag_posts = document.getElementById("tdomf_use_type_posts").checked;
            if(flag_posts) {
                document.getElementById("tdomf_def_cat").disabled = !flag;
            }
            document.getElementById("tdomf_queue_period").disabled = !flag;
            document.getElementById("tdomf_queue_on_all").disabled = !flag;

            // re-enable 'edit' options
            
            document.getElementById("tdomf_edit_tdomf_only").disabled = flag;
            if(flag_posts) {
                //document.getElementById("tdomf_edit_cat_only").disabled = flag;
                document.getElementById("tdomf_edit_cats").disabled = flag;
            }
            
            document.getElementById("tdomf_ajax_edit").disabled = flag;
            document.getElementById("tdomf_add_edit_link_none").disabled = flag;
            <?php 
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) {
            ?>
 
                document.getElementById("tdomf_add_edit_link_your_submissions").disabled = flag;
            <?php 
        }
        ?>
            document.getElementById("tdomf_add_edit_link_custom").disabled = flag;
            document.getElementById("tdomf_add_edit_link_custom_url").disabled = flag;
            
            document.getElementById("tdomf_auto_edit_link_none").disabled = flag;
            <?php 
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) {
            ?>
 
                document.getElementById("tdomf_auto_edit_link_your_submissions").disabled = flag;
            <?php 
        }
        ?>
            document.getElementById("tdomf_auto_edit_link_custom").disabled = flag;
            document.getElementById("tdomf_auto_edit_link_custom_url").disabled = flag;
            
            document.getElementById("tdomf_author_edit").disabled = flag;
            document.getElementById("tdomf_time_edit").disabled = flag;

            // enable / disable tabs
            
            <?php 
        if (version_compare($wp_version, "2.8-beta2", ">=")) {
            ?>
            var selected = jQuery("#form_options_tabs").data('selected.tabs');
            if(!flag) {
                jQuery("#form_options_tabs").tabs("enable",3);
                if(selected == 1) {
                    jQuery("#form_options_tabs").tabs("select",3);
                }
                jQuery("#form_options_tabs").tabs("disable",2);
            } else {
                jQuery("#form_options_tabs").tabs("enable",2);
                if(selected == 2) {
                    jQuery("#form_options_tabs").tabs("select",2);
                }
                jQuery("#form_options_tabs").tabs("disable",3);
            }
            <?php 
        } else {
            ?>
            var selected = jQuery("#form_options_tabs > ul").data('selected.tabs');                
            if(!flag) {
                jQuery("#form_options_tabs > ul").tabs("enable",3);
                if(selected == 1) {
                    jQuery("#form_options_tabs > ul").tabs("select",3);
                }
                jQuery("#form_options_tabs > ul").tabs("disable",2);
            } else {
                jQuery("#form_options_tabs > ul").tabs("enable",2);
                if(selected == 2) {
                    jQuery("#form_options_tabs > ul").tabs("select",2);
                }
                jQuery("#form_options_tabs > ul").tabs("disable",3);
            }
            <?php 
        }
        ?>
          }
          
          function tdomf_enable_new() {
            var flag = !document.getElementById("tdomf_mode_new").checked;
            
            // re-enable 'new' options
            
            var flag_posts = document.getElementById("tdomf_use_type_posts").checked;
            if(flag_posts) {
                document.getElementById("tdomf_def_cat").disabled = flag;
            }
            document.getElementById("tdomf_queue_period").disabled = flag;
            document.getElementById("tdomf_queue_on_all").disabled = flag;            
            
            // disable 'edit' options
            
            document.getElementById("tdomf_edit_tdomf_only").disabled = !flag;
            if(flag_posts) {
                //document.getElementById("tdomf_edit_cat_only").disabled = !flag;
                document.getElementById("tdomf_edit_cats").disabled = !flag;
            }
            
            document.getElementById("tdomf_ajax_edit").disabled = flag;
            document.getElementById("tdomf_add_edit_link_none").disabled = flag;
            <?php 
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) {
            ?>
 
                document.getElementById("tdomf_add_edit_link_your_submissions").disabled = flag;
            <?php 
        }
        ?>
            document.getElementById("tdomf_add_edit_link_custom").disabled = flag;
            document.getElementById("tdomf_add_edit_link_custom_url").disabled = flag;
            
            document.getElementById("tdomf_auto_edit_link_none").disabled = flag;
            <?php 
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) {
            ?>
 
                document.getElementById("tdomf_auto_edit_link_your_submissions").disabled = flag;
            <?php 
        }
        ?>
            document.getElementById("tdomf_auto_edit_link_custom").disabled = flag;
            document.getElementById("tdomf_auto_edit_link_custom_url").disabled = flag;
            
            document.getElementById("tdomf_author_edit").disabled = !flag;
            document.getElementById("tdomf_time_edit").disabled = !flag;
            
            // enable / disable tabs
            
            <?php 
        if (version_compare($wp_version, "2.8-beta2", ">=")) {
            ?>
            var selected = jQuery("#form_options_tabs").data('selected.tabs');
            if(!flag) {
                jQuery("#form_options_tabs").tabs("enable",2);
                if(selected == 2) {
                    jQuery("#form_options_tabs").tabs("select",2);
                }
                jQuery("#form_options_tabs").tabs("disable",3);
            } else {
                jQuery("#form_options_tabs").tabs("enable",3);
                if(selected == 1) {
                    jQuery("#form_options_tabs").tabs("select",3);
                }
                jQuery("#form_options_tabs").tabs("disable",2);
            }                
            <?php 
        } else {
            ?>
            var selected = jQuery("#form_options_tabs > ul").data('selected.tabs');
            if(!flag) {
                jQuery("#form_options_tabs > ul").tabs("enable",2);
                if(selected == 2) {
                    jQuery("#form_options_tabs > ul").tabs("select",2);
                }
                jQuery("#form_options_tabs > ul").tabs("disable",3);
            } else {
                jQuery("#form_options_tabs > ul").tabs("enable",3);
                if(selected == 1) {
                    jQuery("#form_options_tabs > ul").tabs("select",3);
                }
                jQuery("#form_options_tabs > ul").tabs("disable",2);
            }
            <?php 
        }
        ?>
          }
    //-->
    </script>
   
    <?php 
        $use_page = tdomf_get_option_form(TDOMF_OPTION_SUBMIT_PAGE, $form_id);
        ?>
    <?php 
        $edit_form = tdomf_get_option_form(TDOMF_OPTION_FORM_EDIT, $form_id);
        ?>
    
    
    <script type="text/javascript">
         //<![CDATA[
         jQuery(document).ready(function(){
         <?php 
        if (!$edit_form) {
            ?>
           <?php 
            if (version_compare($wp_version, "2.8-beta2", ">=")) {
                ?>
           jQuery("#form_options_tabs").tabs("disable",3);               
           <?php 
            } else {
                ?>
           jQuery("#form_options_tabs > ul").tabs("disable",3);
           <?php 
            }
            ?>
         <?php 
        } else {
            ?>
           <?php 
            if (version_compare($wp_version, "2.8-beta2", ">=")) {
                ?>
           jQuery("#form_options_tabs").tabs("disable",2);               
           <?php 
            } else {
                ?>
           jQuery("#form_options_tabs > ul").tabs("disable",2);
           <?php 
            }
            ?>
         <?php 
        }
        ?>
         });
    //-->
    </script>
    
	<p>
        <?php 
        _e('This form will be used to', 'tdomf');
        ?>
        <input type="radio" name="tdomf_mode" id="tdomf_mode_new" value="new" <?php 
        if (!$edit_form) {
            echo "checked";
        }
        ?>
 onChange="tdomf_enable_new();" ><?php 
        _e('submit new or', 'tdomf');
        ?>
        <input type="radio" name="tdomf_mode" id="tdomf_mode_edit" value="edit" <?php 
        if ($edit_form) {
            echo "checked";
        }
        ?>
 onChange="tdomf_enable_edit();" ><?php 
        _e('edit existing ', 'tdomf');
        ?>
        <input type="radio" name="tdomf_use_type" id="tdomf_use_type_posts" value="post" <?php 
        if (!$use_page) {
            echo "checked";
        }
        ?>
 onChange="tdomf_enable_use_type_posts();" ><?php 
        _e('Posts or', 'tdomf');
        ?>
        <input type="radio" name="tdomf_use_type" id="tdomf_use_type_pages" value="page" <?php 
        if ($use_page) {
            echo "checked";
        }
        ?>
 onChange="tdomf_enable_use_type_posts();" ><?php 
        _e('Pages', 'tdomf');
        ?>
    </p>   

     <p>
    </p>  
    
    <p>
        <?php 
        $on_preview = tdomf_get_option_form(TDOMF_OPTION_PREVIEW, $form_id);
        ?>
        <input type="checkbox" name="tdomf_preview" id="tdomf_preview"  <?php 
        if ($on_preview) {
            echo "checked";
        }
        ?>
 >
        <label for="tdomf_include_sub">
            <?php 
        _e("Enable Preview", "tdomf");
        ?>
        </label>
        <br/>
        
        <?php 
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) {
            ?>
            <?php 
            $inc_sub = tdomf_get_option_form(TDOMF_OPTION_INCLUDED_YOUR_SUBMISSIONS, $form_id);
            ?>
            <input type="checkbox" name="tdomf_include_sub" id="tdomf_include_sub" <?php 
            if ($inc_sub) {
                echo "checked";
            }
            ?>
 >
            <label for="tdomf_include_sub">
               <?php 
            _e("Include on 'Your Submissions' page", "tdomf");
            ?>
            </label>
            <br/>
        <?php 
        }
        ?>
        
        <?php 
        $ajax = tdomf_get_option_form(TDOMF_OPTION_AJAX, $form_id);
        ?>
        <input type="checkbox" name="tdomf_ajax" id="tdomf_ajax"  <?php 
        if ($ajax) {
            echo "checked";
        }
        ?>
 >
        <label for="tdomf_ajax">
            <?php 
        _e("Enable AJAX", "tdomf");
        ?>
        </label>
    </p>
        
    <?php 
        $from_email = tdomf_get_option_form(TDOMF_OPTION_FROM_EMAIL, $form_id);
        ?>
    <p>
        <label for="tdomf_from_email">
	        <?php 
        _e("'From Email' Address to use in notifications to users. Leave blank for Wordpress default.", "tdomf");
        ?>
<br/>
        </label>
        <input type="text" name="tdomf_from_email" id="tdomf_from_email" size="80" value="<?php 
        if ($from_email) {
            echo htmlentities($from_email, ENT_QUOTES, get_bloginfo('charset'));
        }
        ?>
" >
	</p>
  
    <?php 
        $widget_count = tdomf_get_option_form(TDOMF_OPTION_WIDGET_INSTANCES, $form_id);
        if ($widget_count == false) {
            $widget_count = 9;
        }
        ?>
	<p>
        <label for="tdomf_widget_count">
            <?php 
        _e("Number of multiple-instances Widgets to have on Form Widgets page:", "tdomf");
        ?>
        </label>
        <input type="text" name="tdomf_widget_count" id="tdomf_widget_count" size="3" value="<?php 
        echo htmlentities(strval($widget_count), ENT_QUOTES, get_bloginfo('charset'));
        ?>
" />
	</p>
    
    </div><!-- /form_gen -->
    
    <div id="form_access">
    
    <p><?php 
        _e("You can control access to the form based on user roles, capabilities or by specific users. You can chose \"Unregistered Users\" if you want anyone to be able to access the form, including visitors to your site that do not have user accounts. The old behaviour of TDO Mini Forms allowed any user with the ability to publish posts automatic access to the form. This behaviour can now be turned off or on as required.", "tdomf");
        ?>
</p>
   
	<?php 
        if (!isset($wp_roles)) {
            $wp_roles = new WP_Roles();
        }
        $roles = $wp_roles->role_objects;
        $access_roles = array();
        $publish_roles = array();
        foreach ($roles as $role) {
            if (!isset($role->capabilities['publish_posts'])) {
                if ($role->name != get_option('default_role')) {
                    array_push($access_roles, $role->name);
                } else {
                    $def_role = $role->name;
                }
            } else {
                array_push($publish_roles, $role->name);
            }
        }
        rsort($access_roles);
        rsort($publish_roles);
        $caps = tdomf_get_all_caps();
        $can_reg = get_option('users_can_register');
        ?>


          
          <script type="text/javascript">
         //<![CDATA[
          function tdomf_unreg_user() {
            var flag = document.getElementById("tdomf_special_access_anyone").checked;
            var flag2 = document.getElementById("tdomf_user_publish_override").checked;
            <?php 
        if (isset($def_role)) {
            ?>
            document.getElementById("tdomf_access_<?php 
            echo $def_role;
            ?>
").disabled = flag;
            document.getElementById("tdomf_access_<?php 
            echo $def_role;
            ?>
").checked = flag;
            <?php 
        }
        ?>
            <?php 
        foreach ($access_roles as $role) {
            ?>
            document.getElementById("tdomf_access_<?php 
            echo $role;
            ?>
").disabled = flag;
            document.getElementById("tdomf_access_<?php 
            echo $role;
            ?>
").checked = flag;
            <?php 
        }
        ?>
            <?php 
        foreach ($caps as $cap) {
            ?>
            document.getElementById("tdomf_access_caps_<?php 
            echo $cap;
            ?>
").disabled = flag;
            document.getElementById("tdomf_access_caps_<?php 
            echo $cap;
            ?>
").checked = flag;
            <?php 
        }
        ?>
            document.getElementById("tdomf_access_users_list").disabled = flag;
            if(flag) {
               document.getElementById("tdomf_access_users_list").value = "";
            }
            if(!flag2) {
            <?php 
        foreach ($publish_roles as $role) {
            ?>
            document.getElementById("tdomf_access_<?php 
            echo $role;
            ?>
").disabled = flag;
            document.getElementById("tdomf_access_<?php 
            echo $role;
            ?>
").checked = flag;
            <?php 
        }
        ?>
            }
           }
           <?php 
        if (isset($def_role) && $can_reg) {
            ?>
           function tdomf_def_role() {
              var flag = document.getElementById("tdomf_access_<?php 
            echo $def_role;
            ?>
").checked;
              var flag2 = document.getElementById("tdomf_user_publish_override").checked;
              <?php 
            foreach ($access_roles as $role) {
                ?>
               document.getElementById("tdomf_access_<?php 
                echo $role;
                ?>
").checked = flag;
              <?php 
            }
            ?>
                 if(!flag2) {
                 <?php 
            foreach ($publish_roles as $role) {
                ?>
                    document.getElementById("tdomf_access_<?php 
                echo $role;
                ?>
").checked = flag;
                 <?php 
            }
            ?>
                 }
              <?php 
            foreach ($caps as $cap) {
                ?>
             document.getElementById("tdomf_access_caps_<?php 
                echo $cap;
                ?>
").disabled = flag;
             document.getElementById("tdomf_access_caps_<?php 
                echo $cap;
                ?>
").checked = flag;
             <?php 
            }
            ?>
              <?php 
            foreach ($access_roles as $role) {
                ?>
              document.getElementById("tdomf_access_<?php 
                echo $role;
                ?>
").disabled = flag;
              <?php 
            }
            ?>
              if(!flag2) {
              <?php 
            foreach ($publish_roles as $role) {
                ?>
                 document.getElementById("tdomf_access_<?php 
                echo $role;
                ?>
").disabled = flag;
              <?php 
            }
            ?>
              }
             document.getElementById("tdomf_access_users_list").disabled = flag;
            if(flag) {
               document.getElementById("tdomf_access_users_list").value = "";
            }
           }
           <?php 
        }
        ?>
           
           function tdomf_publish_user() {
            var flag = document.getElementById("tdomf_user_publish_override").checked;
            <?php 
        if (isset($def_role) && $can_reg) {
            ?>
            var flag2 = document.getElementById("tdomf_access_<?php 
            echo $def_role;
            ?>
").checked;
            if(!flag2) {
            <?php 
        }
        ?>
                <?php 
        foreach ($publish_roles as $role) {
            ?>
                document.getElementById("tdomf_access_<?php 
            echo $role;
            ?>
").checked = flag;
                document.getElementById("tdomf_access_<?php 
            echo $role;
            ?>
").disabled = flag;
                <?php 
        }
        ?>

            <?php 
        if (isset($def_role) && $can_reg) {
            ?>
            }
            <?php 
        }
        ?>
           }
           //-->
           </script>

           <p>
           
          <label for="tdomf_special_access_anyone">
   <input value="tdomf_special_access_anyone" type="checkbox" name="tdomf_special_access_anyone" id="tdomf_special_access_anyone" <?php 
        if (tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id) != false) {
            ?>
checked<?php 
        }
        ?>
 onClick="tdomf_unreg_user();" />
   <?php 
        _e("Unregistered Users (i.e. everyone)", "tdomf");
        ?>
           </label>
           
           <br/>

           <?php 
        $author_edit = tdomf_get_option_form(TDOMF_OPTION_ALLOW_AUTHOR, $form_id);
        ?>
           
           <input type="checkbox" name="tdomf_author_edit" id="tdomf_author_edit" <?php 
        if (!$edit_form) {
            echo 'disabled';
        }
        ?>
 <?php 
        if ($author_edit) {
            echo 'checked';
        }
        ?>
 />
          <label for="tdomf_author_edit">
          <?php 
        _e("Original Submitter (registered users only)", "tdomf");
        ?>
          </label>   
           
          <br/>
          
          <?php 
        $can_publish = tdomf_get_option_form(TDOMF_OPTION_ALLOW_PUBLISH, $form_id);
        ?>
          
          <input type="checkbox" 
                 name="tdomf_user_publish_override" id="tdomf_user_publish_override"
                 <?php 
        if ($can_publish) {
            ?>
 checked <?php 
        }
        ?>
                 onClick="tdomf_publish_user();" />
          <label for="tdomf_user_publish_override">
          <?php 
        _e("Users with rights to publish posts.", "tdomf");
        ?>
          </label>   

           </p>
          
           <div id="options_access_tabs" class="tabs">
              <ul>
                <li><a href="#access_roles"><span><?php 
        _e('Roles', 'tdomf');
        ?>
</span></a></li>
                <li><a href="#access_caps"><span><?php 
        _e('Capabilities', 'tdomf');
        ?>
</span></a></li>
                <li><a href="#access_users"><span><?php 
        _e('Specific Users', 'tdomf');
        ?>
</span></a></li>
              </ul>
           
           <div id="access_roles">
           <p><?php 
        _e('Select roles that can access the form. If you allow free user registration and pick the default role, this means that a user must just be logged in to access the form.', 'tdomf');
        ?>
</p>
           
           <p>
          <?php 
        if (isset($def_role)) {
            ?>
             <label for="tdomf_access_<?php 
            echo $def_role;
            ?>
">
             <input value="tdomf_access_<?php 
            echo $def_role;
            ?>
" type="checkbox"
                    name="tdomf_access_<?php 
            echo $def_role;
            ?>
" id="tdomf_access_<?php 
            echo $def_role;
            ?>
"  
                    <?php 
            if (isset($wp_roles->role_objects[$def_role]->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id])) {
                ?>
 checked <?php 
            }
            ?>
 
                    onClick="tdomf_def_role()" 
                    <?php 
            if (tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id) != false) {
                ?>
 checked disabled <?php 
            }
            ?>
 />
             <?php 
            if (function_exists('translate_with_context')) {
                $role_name = translate_with_context($wp_roles->role_names[$def_role]);
            } else {
                $role_name = $wp_roles->role_names[$def_role];
            }
            ?>
             <?php 
            echo $role_name . " " . __("(newly registered users)");
            ?>
             </label><br/>
          <?php 
        }
        ?>

          <?php 
        foreach ($access_roles as $role) {
            ?>
             <label for="tdomf_access_<?php 
            echo $role;
            ?>
">
             <input value="tdomf_access_<?php 
            echo $role;
            ?>
" type="checkbox" 
                    name="tdomf_access_<?php 
            echo $role;
            ?>
" id="tdomf_access_<?php 
            echo $role;
            ?>
" 
                    <?php 
            if (isset($wp_roles->role_objects[$role]->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id])) {
                ?>
 checked <?php 
            }
            ?>
                    <?php 
            if (isset($def_role) && isset($wp_roles->role_objects[$def_role]->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id]) && $can_reg) {
                ?>
 checked disabled <?php 
            }
            ?>
                    <?php 
            if (tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id) != false) {
                ?>
 checked disabled <?php 
            }
            ?>
 />
             <?php 
            if (function_exists('translate_with_context')) {
                echo translate_with_context($wp_roles->role_names[$role]);
            } else {
                echo $wp_roles->role_names[$role];
            }
            ?>
             </label><br/>
          <?php 
        }
        ?>
          
          <?php 
        foreach ($publish_roles as $role) {
            ?>
             <label for="tdomf_access_<?php 
            echo $role;
            ?>
">
             <input value="tdomf_access_<?php 
            echo $role;
            ?>
" type="checkbox" 
                    name="tdomf_access_<?php 
            echo $role;
            ?>
" id="tdomf_access_<?php 
            echo $role;
            ?>
"
                    <?php 
            if ($can_publish) {
                ?>
 checked disabled <?php 
            }
            ?>
                    <?php 
            if (isset($wp_roles->role_objects[$role]->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id])) {
                ?>
 checked <?php 
            }
            ?>
                    <?php 
            if (isset($def_role) && isset($wp_roles->role_objects[$def_role]->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id]) && $can_reg) {
                ?>
 checked disabled <?php 
            }
            ?>
                    <?php 
            if (tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id) != false) {
                ?>
 checked disabled <?php 
            }
            ?>
 />
             <?php 
            if (function_exists('translate_with_context')) {
                printf(__('%s (can publish posts)', 'tdomf'), translate_with_context($wp_roles->role_names[$role]));
            } else {
                printf(__('%s (can publish posts)', 'tdomf'), $wp_roles->role_names[$role]);
            }
            ?>
             </label><br/>
          <?php 
        }
        ?>
          </p>
          </div> <!-- access_roles -->
           
          <div id="access_caps">
          <p><?php 
        _e('Capabilities are specific access rights. Roles are groupings of capabilities. Individual users can be given individual capabilities outside their assigned Role using external plugins. You can optionally select additional capabilities that give access to the form.', 'tdomf');
        ?>
</p>
          
          <?php 
        $access_caps = tdomf_get_option_form(TDOMF_OPTION_ALLOW_CAPS, $form_id);
        if ($access_caps == false) {
            $access_caps = array();
        }
        ?>
          
          <div id="access_caps_list"><p>
          <?php 
        foreach ($caps as $cap) {
            ?>
             <input value="tdomf_access_caps_<?php 
            echo $cap;
            ?>
" type="checkbox" 
                    name="tdomf_access_caps_<?php 
            echo $cap;
            ?>
" id="tdomf_access_caps_<?php 
            echo $cap;
            ?>
"
                    <?php 
            if (isset($def_role) && isset($wp_roles->role_objects[$def_role]->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id]) && $can_reg) {
                ?>
 checked disabled <?php 
            }
            ?>
                    <?php 
            if (in_array($cap, $access_caps)) {
                ?>
 checked <?php 
            }
            ?>
                    <?php 
            if (tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id) != false) {
                ?>
 checked disabled <?php 
            }
            ?>
 />
             <label for="tdomf_access_caps_<?php 
            echo $cap;
            ?>
">
             <?php 
            if (function_exists('translate_with_context')) {
                echo translate_with_context($cap);
            } else {
                echo $cap;
            }
            ?>
             </label><br/>
          <?php 
        }
        ?>
          </p></div> <!-- access_caps_list -->
          
          </div> <!-- access_caps -->
          
          <div id="access_users">
          
          <?php 
        $allow_users = tdomf_get_option_form(TDOMF_OPTION_ALLOW_USERS, $form_id);
        $tdomf_access_users_list = "";
        if (is_array($allow_users)) {
            $tdomf_access_users_list = array();
            foreach ($allow_users as $allow_user) {
                $allow_user = get_userdata($allow_user);
                $tdomf_access_users_list[] = $allow_user->user_login;
            }
            sort($tdomf_access_users_list);
            $tdomf_access_users_list = join(' ', $tdomf_access_users_list);
        }
        ?>
          
          <p><?php 
        _e('You can specify additional specific users who can access the form. Just list their login names seperated by spaces in the box provide', 'tdomf');
        ?>
</p>
          
          <textarea cols="80" rows="3" 
                    name="tdomf_access_users_list" id="tdomf_access_users_list"
                    <?php 
        if (isset($def_role) && isset($wp_roles->role_objects[$def_role]->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id]) && $can_reg) {
            ?>
 checked disabled /></textarea>
                    <?php 
        } else {
            if (tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id) != false) {
                ?>
 checked disabled /></textarea> 
                    <?php 
            } else {
                ?>
 /><?php 
                echo $tdomf_access_users_list;
                ?>
</textarea><?php 
            }
        }
        ?>
          
          </div> <!-- access_users -->
          
       </div> <!-- options_access_tabs -->
           
       <p>
       
          <?php 
        $allow_time = tdomf_get_option_form(TDOMF_OPTION_ALLOW_TIME, $form_id);
        if ($allow_time === false || $allow_time < 0) {
            $allow_time = "";
        }
        ?>
       
          <label for="tdomf_time_edit">
          <?php 
        _e('Allow post or page to be edited for ');
        ?>
          <input type="text" name="tdomf_time_edit" id="tdomf_time_edit" size="5" value="<?php 
        echo $allow_time;
        ?>
" <?php 
        if (!$edit_form) {
            ?>
disabled <?php 
        }
        ?>
 />
          <?php 
        _e(' Seconds (1 hour = 3600 seconds) after post is published.');
        ?>
          </label>

       </p>
    
    </div> <!-- form_access -->

    <div id="form_new">
    
    <?php 
        $def_cat = tdomf_get_option_form(TDOMF_DEFAULT_CATEGORY, $form_id);
        ?>
    <p>
       <label for="tdomf_def_cat">
	       <?php 
        _e("Default Category of new submissions", "tdomf");
        ?>
       </label>
	   <SELECT NAME="tdomf_def_cat" id="tdomf_def_cat" <?php 
        if ($use_page) {
            ?>
disabled<?php 
        }
        ?>
 >
	   <?php 
        $cats = get_categories("get=all");
        if (!empty($cats)) {
            foreach ($cats as $c) {
                if ($c->term_id == $def_cat) {
                    echo "<OPTION VALUE=\"{$c->term_id}\" selected>{$c->category_nicename}\n";
                } else {
                    echo "<OPTION VALUE=\"{$c->term_id}\">{$c->category_nicename}\n";
                }
            }
        }
        ?>
        </select>
    </p>
    
	<p>
	<?php 
        _e('You can set submissions from this form that are published/approved to be queued before appearing on the site. Just set the period of time between each post and TDOMF will schedule approved submissions from this form. A value of 0 or -1 disables this option. You can also choose to schedule posts after any post in the system or just TDOMF posts.', "tdomf");
        ?>
	</p>
    
    <?php 
        $tdomf_queue_on_all = tdomf_get_option_form(TDOMF_OPTION_QUEUE_ON_ALL, $form_id);
        ?>
        <input type="checkbox" name="tdomf_queue_on_all" id="tdomf_queue_on_all"  <?php 
        if ($tdomf_queue_on_all) {
            echo "checked";
        }
        ?>
 >
        <label for="tdomf_queue_on_all">
            <?php 
        _e("Queue after all posts (i.e. not just posts submitted to TDOMF)", "tdomf");
        ?>
        </label>
    
    <?php 
        $tdomf_queue_period = intval(tdomf_get_option_form(TDOMF_OPTION_QUEUE_PERIOD, $form_id));
        ?>
	<p>
	<input type="text" name="tdomf_queue_period" id="tdomf_queue_period" size="5" value="<?php 
        echo htmlentities($tdomf_queue_period, ENT_QUOTES, get_bloginfo('charset'));
        ?>
" />
    <?php 
        _e("Seconds (1 day = 86400 seconds)", "tdomf");
        ?>
	</p>
    
    </div> <!-- form_new -->
    
    <div id="form_edit">
    
       <p>
        <?php 
        $edit_restrict_tdomf = tdomf_get_option_form(TDOMF_OPTION_EDIT_RESTRICT_TDOMF, $form_id);
        ?>
        <input type="checkbox" name="tdomf_edit_tdomf_only" id="tdomf_edit_tdomf_only" <?php 
        if ($edit_restrict_tdomf) {
            ?>
checked<?php 
        }
        ?>
 >
        <label for="tdomf_edit_tdomf_only"><?php 
        _e("Restrict editing to posts or pages that were submitted by TDO Mini Forms", "tdomf");
        ?>
</label>
        
        <br/>

        <?php 
        $edit_restrict_cats = tdomf_get_option_form(TDOMF_OPTION_EDIT_RESTRICT_CATS, $form_id);
        if (!is_array($edit_restrict_cats)) {
            $edit_restrict_cats = "";
        } else {
            $edit_restrict_cats = join(",", $edit_restrict_cats);
        }
        ?>
        
                
        <?php 
        $edit_page_form = tdomf_get_option_form(TDOMF_OPTION_EDIT_PAGE_FORM, $form_id);
        ?>
        <input type="checkbox" name="tdomf_edit_page_form" id="tdomf_edit_page_form" <?php 
        if ($edit_page_form) {
            ?>
checked<?php 
        }
        ?>
 >
        <label for="tdomf_edit_tdomf_only"><?php 
        _e("Allow editing of pages (or posts) that contain TDO-Mini-Form forms", "tdomf");
        ?>
</label>
        
        <br/><br/>
        
               
        <label for="tdomf_edit_cats">
        <?php 
        _e("Restrict editing to posts in these categories only:", "tdomf");
        ?>
<br/>
        <small><?php 
        _e("(List category ids seperated by a comma)", "tdomf");
        ?>
<br/></small>
        </label>
        <input type="text" name="tdomf_edit_cats" id="tdomf_edit_cats" size="80" value="<?php 
        echo $edit_restrict_cats;
        ?>
" <?php 
        if ($use_page) {
            ?>
disabled<?php 
        }
        ?>
 />

        <br/><br/>
        
        <?php 
        $ajax_edit = tdomf_get_option_form(TDOMF_OPTION_AJAX_EDIT, $form_id);
        ?>
        <input type="checkbox" name="tdomf_ajax_edit" id="tdomf_ajax_edit" <?php 
        if ($ajax_edit) {
            ?>
checked<?php 
        }
        ?>
 >
        <label for="tdomf_ajax_edit"><?php 
        _e("Inline Editing (requires javascript in browser, will fall back to one of the options below)", "tdomf");
        ?>
</label>
        <br/>
        
        <?php 
        $add_edit_link = tdomf_get_option_form(TDOMF_OPTION_ADD_EDIT_LINK, $form_id);
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS) == false && $add_edit_link == 'your_submissions') {
            $add_edit_link = 'none';
        }
        if ($updated_pages == false && $auto_edit_link == 'page') {
            $add_edit_link = 'none';
        }
        ?>
        
        <input type="radio" name="tdomf_add_edit_link" id="tdomf_add_edit_link_none" value="none" <?php 
        if (!$add_edit_link || $add_edit_link == 'none') {
            ?>
checked<?php 
        }
        ?>
 >
        <label for="tdomf_add_edit_link_none">
            <?php 
        _e('Do not add a link to edit form at end of post', 'tdomf');
        ?>
        </label>
        <br/>
        <?php 
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) {
            ?>
            <input type="radio" name="tdomf_add_edit_link" id="tdomf_add_edit_link_your_submissions" value="your_submissions" <?php 
            if ($add_edit_link == 'your_submissions') {
                ?>
checked<?php 
            }
            ?>
>
            <label for="tdomf_add_edit_link_your_submissions">
                <?php 
            _e('Add a link to Form on Your Submissions at end of post', 'tdomf');
            ?>
            </label>
            <br/>
        <?php 
        }
        ?>
        <?php 
        if ($updated_pages != false) {
            ?>
            <input type="radio" name="tdomf_add_edit_link" id="tdomf_add_edit_link_page" value="page" <?php 
            if ($add_edit_link == 'page') {
                ?>
checked<?php 
            }
            ?>
>
            <label for="tdomf_add_edit_link_page">
                <?php 
            _e('Add a link to Page created for Form at end of post', 'tdomf');
            ?>
            </label>
            <br/>
        <?php 
        }
        ?>
        <input type="radio" name="tdomf_add_edit_link" id="tdomf_add_edit_link_custom" value="custom" 
            <?php 
        if ($add_edit_link !== false && $add_edit_link != 'none' && $add_edit_link != 'page' && $add_edit_link != 'your_submissions') {
            ?>
checked<?php 
        }
        ?>
>
        <label for="tdomf_add_edit_link_custom">
            <?php 
        _e('Add a link to a Custom URL at the end of post', 'tdomf');
        ?>
        </label>
        <br/>
        <input type="text" name="tdomf_add_edit_link_custom_url" id="tdomf_add_edit_link_custom_url" size="80" 
            <?php 
        if ($add_edit_link !== false && $add_edit_link != 'none' && $add_edit_link != 'page' && $add_edit_link != 'your_submissions') {
            ?>
value="<?php 
            echo $add_edit_link;
            ?>
" <?php 
        } else {
            ?>
value="http://" <?php 
        }
        ?>
/>

            <br/><br/>
        
        <p>
        <?php 
        _e('If your theme supports it, the edit link can be automatically updated to point to a TDOMF form instead of Wordpress\' backend. But TDOMF cannot change the permissions under which it shows. I.e. This edit link will appear according to Wordpress access rules and not the rules you set here.', 'tdomf');
        ?>
        </p>
        
        <?php 
        $auto_edit_link = tdomf_get_option_form(TDOMF_OPTION_AUTO_EDIT_LINK, $form_id);
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS) == false && $auto_edit_link == 'your_submissions') {
            $auto_edit_link = 'none';
        }
        if ($updated_pages == false && $auto_edit_link == 'page') {
            $auto_edit_link = 'none';
        }
        ?>
        
        <input type="radio" name="tdomf_auto_edit_link" id="tdomf_auto_edit_link_none" value="none" <?php 
        if (!$auto_edit_link || $auto_edit_link == 'none') {
            ?>
checked<?php 
        }
        ?>
>
        <label for="tdomf_auto_edit_link_none">
            <?php 
        _e('Do not auto-modify \'Edit Post\' link', 'tdomf');
        ?>
        </label>
        <br/>
        <?php 
        if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS)) {
            ?>
            <input type="radio" name="tdomf_auto_edit_link" id="tdomf_auto_edit_link_your_submissions" value="your_submissions" <?php 
            if ($auto_edit_link == 'your_submissions') {
                ?>
checked<?php 
            }
            ?>
>
            <label for="tdomf_auto_edit_link_your_submissions">
                <?php 
            _e('Auto-modify \'Edit Post\' link (if avaliable in theme) to point to Form on Your Submissions', 'tdomf');
            ?>
            </label>
            <br/>
        <?php 
        }
        ?>
        <?php 
        if ($updated_pages != false) {
            ?>
            <input type="radio" name="tdomf_auto_edit_link" id="tdomf_auto_edit_link_page" value="page" <?php 
            if ($auto_edit_link == 'page') {
                ?>
checked<?php 
            }
            ?>
>
            <label for="tdomf_auto_edit_link_page">
                <?php 
            _e('Auto-modify \'Edit Post\' link (if avaliable in theme) to point to Page created for Form', 'tdomf');
            ?>
            </label>
            <br/>
        <?php 
        }
        ?>
        <input type="radio" name="tdomf_auto_edit_link" id="tdomf_auto_edit_link_custom" value="custom" 
            <?php 
        if ($auto_edit_link !== false && $auto_edit_link != 'none' && $auto_edit_link != 'page' && $auto_edit_link != 'your_submissions') {
            ?>
checked<?php 
        }
        ?>
>
        <label for="tdomf_auto_edit_link_custom">
            <?php 
        _e('Auto-modify \'Edit Post\' link (if avaliable in theme) to point to a custom URL', 'tdomf');
        ?>
        </label>
        <br/>
        <input type="text" name="tdomf_auto_edit_link_custom_url" id="tdomf_auto_edit_link_custom_url" size="80"
            <?php 
        if ($auto_edit_link !== false && $auto_edit_link != 'none' && $auto_edit_link != 'page' && $auto_edit_link != 'your_submissions') {
            ?>
value="<?php 
            echo $auto_edit_link;
            ?>
" <?php 
        } else {
            ?>
value="http://" <?php 
        }
        ?>
/>

        <br/>
        
       </p>
    
    </div> <!-- form_edit -->
    
    <div id="form_moderation">

    <?php 
        $on_mod = tdomf_get_option_form(TDOMF_OPTION_MODERATION, $form_id);
        ?>
	
    <p>
        <input type="checkbox" name="tdomf_moderation" id="tdomf_moderation"  	<?php 
        if ($on_mod) {
            echo "checked";
        }
        ?>
 >
        <label for="tdomf_moderation">
            <?php 
        _e("Enable Moderation", "tdomf");
        ?>
        </label>
    </p>
    
    <p>
    
    <?php 
        $user_publish_auto = tdomf_get_option_form(TDOMF_OPTION_PUBLISH_NO_MOD, $form_id);
        ?>
    <input type="checkbox" name="tdomf_user_publish_auto" id="tdomf_user_publish_auto" <?php 
        if ($user_publish_auto) {
            ?>
 checked <?php 
        }
        ?>
 />
    <label for="tdomf_user_publish_auto">
        <?php 
        _e("Users with publish rights will have their posts automatically published", "tdomf");
        ?>
<br/>
    </label>
    
    <?php 
        $redirect = tdomf_get_option_form(TDOMF_OPTION_REDIRECT, $form_id);
        ?>
    <input type="checkbox" name="tdomf_redirect" id="tdomf_redirect" <?php 
        if ($redirect) {
            echo "checked";
        }
        ?>
 >
    <label for="tdomf_redirect">
        <?php 
        _e("If automatically published, redirect to Published Post", "tdomf");
        ?>
<br/>
    </label>
    
    <?php 
        $mod_email_on_pub = tdomf_get_option_form(TDOMF_OPTION_MOD_EMAIL_ON_PUB, $form_id);
        ?>
    <input type="checkbox" name="tdomf_mod_email_on_pub" id="tdomf_mod_email_on_pub" <?php 
        if ($mod_email_on_pub) {
            echo "checked";
        }
        ?>
 >
    <label for="tdomf_mod_email_on_pub">
        <?php 
        _e("Send Moderation Email even for automatically Published Post", "tdomf");
        ?>
<br/>
    </label>
    
	</p>

    <p>
    <b><?php 
        _e('Send Moderation Email Notification to:', 'tdomf');
        ?>
</b><br/><br/>

	 <?php 
        $notify_roles = tdomf_get_option_form(TDOMF_NOTIFY_ROLES, $form_id);
        if ($notify_roles != false) {
            $notify_roles = explode(';', $notify_roles);
        }
        $admin_emails = tdomf_get_option_form(TDOMF_OPTION_ADMIN_EMAILS, $form_id);
        ?>

	 <?php 
        foreach ($roles as $role) {
            if (isset($role->capabilities['edit_others_posts']) && isset($role->capabilities['publish_posts'])) {
                ?>
		     <input value="tdomf_notify_<?php 
                echo $role->name;
                ?>
" type="checkbox" name="tdomf_notify_<?php 
                echo $role->name;
                ?>
" id="tdomf_notify_<?php 
                echo $role->name;
                ?>
" <?php 
                if ($notify_roles != false && in_array($role->name, $notify_roles)) {
                    ?>
checked<?php 
                }
                ?>
 />
             <label for="tdomf_notify_<?php 
                echo $role->name;
                ?>
">
          <?php 
                if (function_exists('translate_with_context')) {
                    echo translate_with_context($wp_roles->role_names[$role->name]);
                } else {
                    echo $wp_roles->role_names[$role->name];
                }
                ?>
          <br/>
		     </label>
		     <?php 
            }
        }
        ?>
         <br/>

    <?php 
        _e("Specific Email Addresses (seperate with spaces)", "tdomf");
        ?>
</b>
	<input type="text" name="tdomf_admin_emails" id="tdomf_admin_emails" size="80" value="<?php 
        if ($admin_emails) {
            echo htmlentities(stripslashes($admin_emails), ENT_QUOTES, get_bloginfo('charset'));
        }
        ?>
" />
         
	 </p>

    
    </div> <!-- form_moderation -->
    
    <div id="form_throttling">

	<p>
	<?php 
        _e('You can add rules to throttle input based on registered user accounts and/or IP addresses. Make sure you save any form configuration changes to your form before adding or removing any throttling rules.', "tdomf");
        ?>
	</p>
   
    <?php 
        printf(__("<table border=\"0\">\n                     <tr><td>Only %s submissions/contributions per</td>\n                     <td>%s</td>\n                     <td>%s(optionally) per %s Seconds (1 hour = 3600 seconds)</td>\n                     <td>%s</td>\n                     </tr>\n                     </table>", "tdomf"), '<input type="text" name="tdomf_throttle_rule_count" id="tdomf_throttle_rule_count" size="3" value="10" /> 
                      <select id="tdomf_throttle_rule_sub_type" name="tdomf_throttle_rule_sub_type" >
                      <option value="unapproved" selected />' . __("unapproved", "tdomf") . '
                      <option value="any" />' . __("any", "tdomf") . '
                      </select>', '<input type="radio" name="tdomf_throttle_rule_user_type" id="tdomf_throttle_rule_user_type" value="user" />' . __("registered user", "tdomf") . '<br/>
                      <input type="radio" name="tdomf_throttle_rule_user_type" id="tdomf_throttle_rule_user_type" value="ip" checked />' . __("IP", "tdomf"), '<input type="checkbox" name="tdomf_throttle_rule_opt1" id="tdomf_throttle_rule_opt1" checked >', '<input type="text" name="tdomf_throttle_rule_time" id="tdomf_throttle_rule_time" size="3" value="3600" />', '<input type="submit" name="tdomf_add_throttle_rule" id="tdomf_add_throttle_rule" value="' . __("Add", "tdomf") . ' &raquo;">');
        ?>

    <?php 
        $throttle_rules = tdomf_get_option_form(TDOMF_OPTION_THROTTLE_RULES, $form_id);
        if (is_array($throttle_rules) && !empty($throttle_rules)) {
            ?>
    
    <p><b><?php 
            _e("Current Throttle Rules", "tdomf");
            ?>
</b>
    <ul>
    <?php 
            foreach ($throttle_rules as $id => $throttle_rule) {
                $option_string = "";
                if ($throttle_rule['opt1']) {
                    $option_string = sprintf(__("per %s Seconds", "tdomf"), $throttle_rule['time']);
                }
                ?>
        <li>
        <?php 
                printf(__("(%d) Only %d %s submissions/contributions per %s %s", "tdomf"), $id, $throttle_rule['count'], $throttle_rule['sub_type'], $throttle_rule['type'], $option_string);
                ?>
        <input type="submit" name="tdomf_remove_throttle_rule_<?php 
                echo $id;
                ?>
" id="tdomf_remove_throttle_rule_<?php 
                echo $id;
                ?>
" value="<?php 
                _e("Remove", "tdomf");
                ?>
 &raquo;">
        </li>
    <?php 
            }
            ?>
    </ul>
    </p>
    
          <?php 
        } else {
            ?>
              <p><b><?php 
            _e("No Throttling Rules currently set.", "tdomf");
            ?>
</b></p>
          <?php 
        }
        ?>
        
    </div> <!-- form_throttling -->
    
    <div id="form_spam">
    
    <?php 
        tdomf_show_spam_options($form_id);
        ?>
    
    </div> <!-- form_spam -->
    
    <br/>
    
  <table border="0"><tr>

    <td>
    <input type="hidden" name="save_settings" value="0" />
    <input type="submit" name="tdomf_save_button" id="tdomf_save_button" value="<?php 
        _e("Save", "tdomf");
        ?>
 &raquo;" />
	</form>
    </td>

    <td>
    <form method="post" action="admin.php?page=tdomf_show_form_options_menu&form=<?php 
        echo $form_id;
        ?>
">
    <input type="submit" name="refresh" value="Refresh" />
    </form>
    </td>

    </tr></table>

    </div> <!-- wrap -->
    
  <?php 
    }
}