function jobman_display_apply_generated($foundjob = false, $job = NULL, $cat = NULL)
{
    global $current_user, $si_image_captcha, $wp_version;
    $options = get_option('jobman_options');
    $content = '';
    if (!empty($cat)) {
        $cat = get_term_by('slug', $cat, 'jobman_category');
    }
    if ($foundjob) {
        $content .= '<p>' . __('Title', 'jobman') . ': <a href="' . get_page_link($job->ID) . '">' . $job->post_title . '</a></p>';
    }
    if (!$foundjob) {
        if (!empty($options['app_job_select'])) {
            $content .= '<p><strong>' . __('Select the jobs you would like to apply for', 'jobman') . '</strong>: ' . jobman_generate_job_select($cat, $options['app_job_select']) . '</p>';
        }
        if (!empty($options['app_cat_select'])) {
            $content .= '<p><strong>' . __('Select the categories that you are interested in', 'jobman') . '</strong>: ' . jobman_generate_cat_select($cat, $options['app_cat_select']) . '</p>';
        }
    }
    $fields = $options['fields'];
    $start = true;
    $content .= '<p>' . __('Fields marked with an asterisk (*) must be filled out before submitting.', 'jobman') . '</p>';
    if (count($fields) > 0) {
        uasort($fields, 'jobman_sort_fields');
        $rowcount = 1;
        $totalrowcount = 1;
        $tablecount = 1;
        foreach ($fields as $id => $field) {
            if (array_key_exists('categories', $field) && count($field['categories']) > 0) {
                // If there are cats defined for this field, check that either the job has one of those categories, or we're submitting to that category
                if (empty($cat) || !in_array($cat->term_id, $field['categories'])) {
                    continue;
                }
            }
            if ($start && 'heading' != $field['type']) {
                $content .= "<table class='job-apply-table table{$tablecount}'>";
                $tablecount++;
                $rowcount = 1;
            }
            $data = trim(strip_tags($field['data']));
            // Auto-populate logged in user email address
            if ($id == $options['application_email_from'] && '' == $data && is_user_logged_in()) {
                $data = $current_user->user_email;
            }
            if ('heading' != $field['type']) {
                $content .= "<tr class='row{$rowcount} totalrow{$totalrowcount} field{$id} ";
                $content .= $rowcount % 2 ? 'odd' : 'even';
                $content .= "'>";
            }
            $mandatory = '';
            if ($field['mandatory']) {
                $mandatory = ' *';
            }
            switch ($field['type']) {
                case 'text':
                case 'radio':
                case 'checkbox':
                case 'textarea':
                case 'date':
                case 'file':
                case 'select':
                case 'geoloc':
                    if ('' != $field['label']) {
                        $content .= "<th scope='row'>{$field['label']}{$mandatory}</th>";
                    } else {
                        $content .= '<td class="th"></td>';
                    }
                    $content .= '<td>' . jobman_app_field_input_html($id, $field, $data, $mandatory) . '</td></tr>';
                    break;
                case 'heading':
                    if (!$start) {
                        $content .= '</table>';
                    }
                    $content .= "<h3>{$field['label']}</h3>";
                    $content .= "<table class='job-apply-table table{$tablecount}'>";
                    $tablecount++;
                    $totalrowcount--;
                    $rowcount = 0;
                    break;
                case 'html':
                    $content .= '<td colspan="2">' . jobman_app_field_input_html($id, $field, $data) . '</td></tr>';
                    break;
                case 'blank':
                    $content .= '<td colspan="2">&nbsp;</td></tr>';
                    break;
            }
            $start = false;
            $rowcount++;
            $totalrowcount++;
        }
    }
    $content .= '<tr><td colspan="2">&nbsp;</td></tr>';
    if (isset($si_image_captcha) && $options['plugins']['sicaptcha']) {
        // SI CAPTCHA echos directly to screen. We need to redirect that to our $content buffer.
        ob_start();
        if ($wp_version[0] > 2) {
            $si_image_captcha->si_captcha_comment_form_wp3();
        } else {
            $si_image_captcha->si_captcha_comment_form();
        }
        $content .= '<tr><td colspan="2">' . ob_get_contents() . '</td></tr>';
        ob_end_clean();
    }
    $content .= '<tr><td colspan="2" class="submit"><input type="submit" name="submit"  class="button-primary" value="' . __('Submit Your Application', 'jobman') . '" /></td></tr>';
    $content .= '</table>';
    return $content;
}
function jobman_app_shortcode($atts, $content, $tag)
{
    global $jobman_shortcode_job, $jobman_shortcode_categories;
    $options = get_option('jobman_options');
    switch ($tag) {
        case 'job_links':
            $jobs = array();
            if (NULL != $jobman_shortcode_job) {
                $jobs[] = $jobman_shortcode_job->ID;
            }
            if (array_key_exists('jobman-joblist', $_REQUEST)) {
                $jobs = array_merge($jobs, $_REQUEST['jobman-joblist']);
            }
            if (empty($jobs)) {
                return NULL;
            }
            $jobstr = array();
            foreach ($jobs as $job) {
                $data = get_post($job);
                if (empty($data)) {
                    continue;
                }
                $jobstr[] = "<a href='" . get_page_link($data->ID) . "'>{$data->post_title}</a>";
            }
            return implode(', ', $jobstr);
        case 'job_app_submit':
            return '<input type="submit" name="submit"  class="button-primary" value="' . do_shortcode($content) . '" />';
        case 'job_list':
            $atts = shortcode_atts(array('type' => 'select'), $atts);
            $gencat = NULL;
            if (!empty($jobman_shortcode_categories)) {
                $gencat = $jobman_shortcode_categories[0];
            }
            return jobman_generate_job_select($gencat, $atts['type']);
        case 'cat_list':
            $atts = shortcode_atts(array('type' => 'select'), $atts);
            $gencat = NULL;
            if (!empty($jobman_shortcode_categories)) {
                $gencat = $jobman_shortcode_categories[0];
            }
            return jobman_generate_cat_select($gencat, $atts['type']);
    }
}