function jobman_store_application($jobid, $cat) { global $current_user; get_currentuserinfo(); $cat = get_term_by('slug', $cat, 'jobman_category'); $filter_err = jobman_check_filters($jobid, $cat); if ($filter_err != -1) { // Failed filter rules return $filter_err; } $dir = dirname($_SERVER['SCRIPT_FILENAME']); if (!file_exists("{$dir}/wp-admin/includes/file.php")) { $dir = WP_CONTENT_DIR . '/..'; } require_once "{$dir}/wp-admin/includes/file.php"; require_once "{$dir}/wp-admin/includes/image.php"; require_once "{$dir}/wp-admin/includes/media.php"; $options = get_option('jobman_options'); $fields = $options['fields']; $job = NULL; if (-1 != $jobid) { $job = get_post($jobid); } // Workaround for WP to Twitter plugin tweeting about new application $_POST['jd_tweet_this'] = 'no'; // Check for recent applications for the same job by the same user if (!empty($current_user) && $current_user->ID > 0 && -1 != $jobid) { $args = array('post_status' => 'private', 'post_type' => 'jobman_app', 'author' => $current_user->ID, 'meta_key' => 'job', 'meta_value' => $jobid, 'suppress_filters' => false); add_filter('posts_where', 'jobman_dupe_app_check_where'); $posts = get_posts($args); remove_filter('posts_where', 'jobman_dupe_app_check_where'); if (!empty($posts)) { return -2; } } $page = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'private', 'post_type' => 'jobman_app', 'post_content' => '', 'post_title' => __('Application', 'jobman'), 'post_parent' => $options['main_page']); $appid = wp_insert_post($page); // Add the categories to the application $append = false; if (NULL != $cat && term_exists($cat->slug, 'jobman_category')) { wp_set_object_terms($appid, $cat->slug, 'jobman_category', false); $append = true; } if (NULL != $job) { // Get parent (job) categories, and apply them to application $parentcats = wp_get_object_terms($job->ID, 'jobman_category'); foreach ($parentcats as $pcat) { if (term_exists($pcat->slug, 'jobman_category')) { wp_set_object_terms($appid, $pcat->slug, 'jobman_category', $append); $append = true; } } } if (array_key_exists('jobman-catselect', $_REQUEST) && !empty($_REQUEST['jobman-catselect']) && is_array($_REQUEST['jobman-catselect'])) { // Get any categories selected from the category dropdown foreach ($_REQUEST['jobman-catselect'] as $bonuscat) { if (term_exists($bonuscat, 'jobman_category')) { wp_set_object_terms($appid, $bonuscat, 'jobman_category', $append); $append = true; } } } // Add the jobs to the application $jobs = array(); if (-1 != $jobid) { $jobs[] = $jobid; } if (array_key_exists('jobman-joblist', $_REQUEST)) { $joblist = explode(',', $_REQUEST['jobman-joblist']); $jobs = array_merge($jobs, $joblist); } // Add any extra jobs to the application if (array_key_exists('jobman-jobselect', $_REQUEST) && !empty($_REQUEST['jobman-jobselect'])) { if (is_array($_REQUEST['jobman-jobselect'])) { $jobs = array_merge($jobs, $_REQUEST['jobman-jobselect']); } else { $jobs[] = $_REQUEST['jobman-jobselect']; } } $jobs = array_unique($jobs); foreach ($jobs as $data) { add_post_meta($appid, 'job', $data, false); } $errors = array(); if (count($fields) > 0) { foreach ($fields as $fid => $field) { if ($field['type'] != 'file' && (!array_key_exists("jobman-field-{$fid}", $_REQUEST) || '' == $_REQUEST["jobman-field-{$fid}"])) { continue; } if ('file' == $field['type'] && !array_key_exists("jobman-field-{$fid}", $_FILES)) { continue; } $data = ''; switch ($field['type']) { case 'file': if (is_uploaded_file($_FILES["jobman-field-{$fid}"]['tmp_name'])) { $data = media_handle_upload("jobman-field-{$fid}", $appid, array('post_status' => 'private')); if (is_wp_error($data)) { // Upload failed, move to next field $errors[] = $data; continue 2; } add_post_meta($data, '_jobman_attachment', 1, true); add_post_meta($data, '_jobman_attachment_upload', 1, true); } break; case 'geoloc': if ($_REQUEST["jobman-field-original-display-{$fid}"] == $_REQUEST["jobman-field-display-{$fid}"]) { $data = $_REQUEST["jobman-field-{$fid}"]; } else { $data = $_REQUEST["jobman-field-display-{$fid}"]; } add_post_meta($appid, "data-display{$fid}", $_REQUEST["jobman-field-display-{$fid}"], true); break; default: if (is_array($_REQUEST["jobman-field-{$fid}"])) { $data = implode(', ', $_REQUEST["jobman-field-{$fid}"]); } else { $data = $_REQUEST["jobman-field-{$fid}"]; } } add_post_meta($appid, "data{$fid}", $data, true); } } jobman_email_application($appid); if (!empty($errors)) { return $errors; } // No error return -1; }
function jobman_application_details_layout($appid) { $options = get_option('jobman_options'); if (array_key_exists('jobman-email', $_REQUEST)) { check_admin_referer('jobman-reemail-application'); jobman_email_application($appid, $_REQUEST['jobman-email']); } if (array_key_exists('new-interview', $_REQUEST)) { jobman_interview_new(); } if (array_key_exists('comment', $_REQUEST)) { jobman_store_comment(); } ?> <div id="jobman-application" class="wrap"> <h2><?php _e('Job Manager: Application Details', 'jobman'); ?> </h2> <div class="printicon"><a href="javascript:window.print()"><img src="<?php echo JOBMAN_URL; ?> /images/print-icon.png" /></a></div> <a href="?page=jobman-list-applications" class="backlink">←<?php _e('Back to Application List', 'jobman'); ?> </a> <?php $widths = array('59%', '39%'); $functions = array(array('jobman_application_display_details'), array('jobman_comments', 'jobman_application_email_form')); $titles = array(array(__('Application', 'jobman')), array(__('Application Comments', 'jobman'), __('Share Application', 'jobman'))); $params = array(array(array($appid)), array(array($appid, true), array())); if ($options['interviews']) { $functions[1] = array_insert($functions[1], 1, 'jobman_interview_application'); $titles[1] = array_insert($titles[1], 1, __('Interviews', 'jobman')); $params[1] = array_insert($params[1], 1, array($appid, 'summary')); } jobman_create_dashboard($widths, $functions, $titles, $params); ?> <a href="?page=jobman-list-applications" class="backlink">←<?php _e('Back to Application List', 'jobman'); ?> </a> </div> <?php }