From 46c53f05c94be7df136f6dbab34ce42db741a0ed Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 16 Dec 2014 11:03:01 -0500 Subject: [PATCH] Add resume file and archive, unarchive, delete abilities can unarchive from archived list can delete from archived list only can do bulk actions of archive, unarchive,delete. can add resume file to applications. --- config/settings1.php | 6 +- config/settings2.php | 6 ++ controllers/front.php | 45 +++++++++- glm-employment.php | 11 ++- models/database.php | 1 + models/list-applications.php | 142 ++++++++++++++++++++++++++------ views/admin/applicationList.php | 2 +- views/front/formTemplate.php | 8 +- 8 files changed, 183 insertions(+), 38 deletions(-) diff --git a/config/settings1.php b/config/settings1.php index 6894d8b..97aad9d 100644 --- a/config/settings1.php +++ b/config/settings1.php @@ -279,16 +279,12 @@ $had_violations_in_past_three_years_how_many = [ 'label' => 'How Many', 'grid' => 4 ]; -if ($jobId = filter_var($_REQUEST['job'], FILTER_VALIDATE_INT)) { - $jobData = get_post($jobId); - $jobTitle = $jobData->post_title; -} $position_applied_for = [ 'type' => 'text', 'name' => 'position_applied_for', 'label' => 'Position Applied For', 'grid' => 6, - 'value' => $jobTitle + 'value' => $this->jobTitle ]; $date_available_for_work = [ 'type' => 'text', diff --git a/config/settings2.php b/config/settings2.php index e6fb83b..799b538 100644 --- a/config/settings2.php +++ b/config/settings2.php @@ -316,6 +316,11 @@ for ($i = 1; $i <= 3; ++$i) { 'grid' => 3 ]; } +$resume_file = [ + 'type' => 'file', + 'label' => 'Upload your resume', + 'grid' => 12 +]; $form = [ ['type' => 'header', 'label' => 'Driver Experience and Qualification'], [$date_of_birth, $date_of_birth_explain], @@ -346,4 +351,5 @@ $form = [ [$traffic_convictions_locations1, $traffic_convictions_date1, $traffic_convictions_charge1, $traffic_convictions_penalty1], [$traffic_convictions_locations2, $traffic_convictions_date2, $traffic_convictions_charge2, $traffic_convictions_penalty2], [$traffic_convictions_locations3, $traffic_convictions_date3, $traffic_convictions_charge3, $traffic_convictions_penalty3], + [$resume_file] ]; diff --git a/controllers/front.php b/controllers/front.php index 858cda4..ad53b0a 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -25,9 +25,11 @@ class glm_employment_front public $fname; public $lname; public $mname; + public $job; public $resume; public $appId; public $formId; + public $jobTitle; // class constants const FORM_VAR = 'applyOnline'; @@ -108,7 +110,6 @@ class glm_employment_front $this->appId = $appId = filter_var($_REQUEST['appId'], FILTER_VALIDATE_INT); $form = $this->form_process($formPart); // echo '
'.print_r('appId:' . $this->appId, true).'
'; -// echo '
'.print_r($_POST, true).'
'; // echo '
'.print_r('fname:' . $this->fname, true).'
'; // echo '
'.print_r('form:' . $form, true).'
'; // wp_die('test'); @@ -138,12 +139,39 @@ class glm_employment_front break; default: unset($_SESSION['glmJobsApplication'], $_SESSION['glmJobsAppForm']); + if ($jobId = filter_var($_REQUEST['job'], FILTER_VALIDATE_INT)) { + $jobData = get_post($jobId); + $this->jobTitle = $jobTitle = $jobData->post_title; + } $formPart = 1; - $form = $this->load_form_settings($formPart); + $form = $this->load_form_settings($formPart); include $this->frontViewDir . '/' . self::FORM_TEMPLATE; break; } -// echo '
'.print_r($_SESSION, true).'
'; + } + + public function store_resume_file() + { + echo '
'.print_r($form, true).'
'; + if (!$appId = filter_var($_REQUEST['appId'], FILTER_VALIDATE_INT)) { + return false; + } + echo '
'.print_r($_FILES, true).'
'; + preg_match("%\.[A-Za-z]*$%", $_FILES['resume_file']['name'], $ext); + $size = getImageSize($_FILES['resume_file']['tmp_name']); + $resumeFile = tempnam(GLM_EMP_UPLOAD_DIR, "RESUME"); + unlink($resumeFile); + $resumeFile = $resumeFile.$ext[0]; + if (move_uploaded_file($_FILES['resume_file']['tmp_name'], $resumeFile)) { + $resumeFile = basename($resumeFile); + $this->wpdb->update( + $this->appTable, + array('resume' => $resumeFile), + array('id' => $appId), + array('%s'), + array('%d') + ); + } } public function store_application_data($form) @@ -159,13 +187,15 @@ class glm_employment_front 'create_time' => date('Y-m-d, h:i:s a'), 'fname' => $this->fname, 'lname' => $this->lname, - 'mname' => $this->mname + 'mname' => $this->mname, + 'position' => $this->job ), array( '%s', '%s', '%s', '%s', + '%d' ) ); $this->appId = $this->wpdb->insert_id; @@ -221,6 +251,10 @@ class glm_employment_front ); } + if (isset($_FILES['resume_file']) && !$_FILES['resume_file']['error']) { + $this->store_resume_file($form); + } + $this->formId = $this->wpdb->insert_id; $_SESSION['glmJobsAppForm'] = array( 'id' => $this->formId, @@ -232,6 +266,9 @@ class glm_employment_front { $this->clean_post(); $form = $this->load_form_settings($part); + if ($jobId = filter_var($_REQUEST['job'], FILTER_VALIDATE_INT)) { + $this->job = $jobId; + } foreach ($form as $rowKey => $row) { if ($row['type'] != 'header') { diff --git a/glm-employment.php b/glm-employment.php index 042e6de..03ef072 100644 --- a/glm-employment.php +++ b/glm-employment.php @@ -11,13 +11,22 @@ defined('ABSPATH') or die(); define('GLM_EMP_PLUGIN_PATH_FILE', __FILE__); -define('GLM_EMP_VERSION', '1.0'); +define('GLM_EMP_VERSION', '0.0.1'); define('GLM_EMP_VRS_OPTION_NAME', 'glm_jobs_db_version'); define('GLM_EMP_POST_TYPE', 'glm_jobs'); define('GLM_EMP_TAX_CATEGORIES', 'glm_jobscategory'); define('GLM_EMP_TAX_DEPARTMENTS', 'glm_jobsdepartment'); define('GLM_EMP_APPLICATION_TABLE', 'glm_jobs_application'); define('GLM_EMP_FORM_TABLE', 'glm_jobs_app_form'); +$wp_upload_dir = wp_upload_dir(); +define('GLM_EMP_UPLOAD_DIR', $wp_upload_dir['basedir'] . '/glm-emp/'); +define('GLM_EMP_UPLOAD_URL', $wp_upload_dir['baseurl'] . '/glm-emp/'); +if (!is_dir(GLM_EMP_UPLOAD_DIR)) { + // create the upload directory + $oldUmask = umask(0); + mkdir(GLM_EMP_UPLOAD_DIR, 0770); + umask($oldUmask); +} require_once 'controllers/admin.php'; require_once 'controllers/front.php'; diff --git a/models/database.php b/models/database.php index 0b73952..31caccc 100644 --- a/models/database.php +++ b/models/database.php @@ -56,6 +56,7 @@ class glm_employment_models_database fname TEXT NOT NULL, lname TEXT NOT NULL, mname TEXT DEFAULT '' NOT NULL, + position BIGINT(20) DEFAULT 0 NOT NULL, resume TEXT DEFAULT '' NOT NULL, archived BOOLEAN DEFAULT false NOT NULL, UNIQUE KEY id (id) diff --git a/models/list-applications.php b/models/list-applications.php index 6c72df8..b30a648 100644 --- a/models/list-applications.php +++ b/models/list-applications.php @@ -23,7 +23,6 @@ class List_Applications extends GLM_List_Table { $where = array(); if ($_POST['s']) { -// var_dump($_POST); $search = filter_var($_REQUEST['s'], FILTER_SANITIZE_STRING); $where[] = "CONCAT(UPPER(fname), UPPER(lname)) like '%".strtoupper($search)."%'"; } @@ -33,13 +32,12 @@ class List_Applications extends GLM_List_Table $where[] = "archived <> true"; } $sql = " - SELECT id as ID,fname,lname,create_time + SELECT id as ID,fname,lname,create_time,archived,position,resume FROM " . $this->wpdb->prefix . GLM_EMP_APPLICATION_TABLE . " "; if (!empty($where)) { $sql .= " WHERE ".implode(" AND ", $where); } -// var_dump($sql); return $this->wpdb->get_results( $sql, ARRAY_A @@ -72,6 +70,8 @@ class List_Applications extends GLM_List_Table case 'lname': case 'position': case 'create_time': + case 'archived': + case 'resume': return $item[$column_name]; default: return print_r($item,true); //Show the whole array for troubleshooting purposes @@ -96,24 +96,46 @@ class List_Applications extends GLM_List_Table * @return string Text to be placed inside the column (movie title only) **************************************************************************/ function column_fname($item){ - //Build row actions - $actions = array( - 'view' => sprintf( - 'View', - GLM_EMP_POST_TYPE, - $_REQUEST['page'], - 'view', - $item['ID'] - ), - 'archive' => sprintf( - 'Archive', - GLM_EMP_POST_TYPE, - $_REQUEST['page'], - 'archive', - $item['ID'] - ), - ); + $urlFormat = '?post_type=%s&page=%s&action=%s&application=%s&archived=%d'; + if ($archivedList = filter_var($_REQUEST['archived'], FILTER_VALIDATE_BOOLEAN)) { + $actions = array( + 'unarchive' => sprintf( + 'Unarchive', + GLM_EMP_POST_TYPE, + $_REQUEST['page'], + 'unarchive', + $item['ID'], + $_REQUEST['archived'] + ), + 'delete' => sprintf( + 'Delete Permanently', + GLM_EMP_POST_TYPE, + $_REQUEST['page'], + 'delete', + $item['ID'], + $_REQUEST['archived'] + ), + ); + } else { + $actions = array( + 'view' => sprintf( + 'View', + GLM_EMP_POST_TYPE, + $_REQUEST['page'], + 'view', + $item['ID'] + ), + 'archive' => sprintf( + 'Archive', + GLM_EMP_POST_TYPE, + $_REQUEST['page'], + 'archive', + $item['ID'] + ) + ); + } + //Return the title contents return sprintf('%1$s (id:%2$s)%3$s', @@ -123,6 +145,30 @@ class List_Applications extends GLM_List_Table ); } + function column_position($item) + { + if ($item['position']) { + $jobData = get_post($item['position']); + return $jobData->post_title; + } else { + return ''; + } + } + + function column_resume($item) + { + if ($item['resume'] && is_file(GLM_EMP_UPLOAD_DIR . $item['resume'])) { + $format = 'Resume File'; + return sprintf( + $format, + GLM_EMP_UPLOAD_URL, + $item['resume'] + ); + } else { + return ''; + } + } + /** ************************************************************************ * REQUIRED if displaying checkboxes or using bulk actions! The 'cb' column @@ -160,6 +206,7 @@ class List_Applications extends GLM_List_Table 'cb' => '', //Render a checkbox instead of text 'fname' => 'First Name', 'lname' => 'Last Name', + 'resume' => 'Resume File', 'position' => 'Position', 'create_time' => 'Created' ); @@ -207,9 +254,17 @@ class List_Applications extends GLM_List_Table * @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles' **************************************************************************/ function get_bulk_actions() { - $actions = array( - 'archive' => 'Archive' - ); + if ($archivedList = filter_var($_REQUEST['archived'], FILTER_VALIDATE_BOOLEAN)) { + $actions = array( + 'delete' => 'Delete Permanently', + 'unarchive' => 'Unarchive' + ); + } else { + $actions = array( + 'archive' => 'Archive' + ); + } + return $actions; } @@ -225,7 +280,26 @@ class List_Applications extends GLM_List_Table //Detect when a bulk action is being triggered... if( 'delete'===$this->current_action() ) { - wp_die('Items deleted (or they would be if we had items to delete)!'); +// wp_die('Items deleted (or they would be if we had items to delete)!'); + $applications = filter_var( + $_REQUEST['application'], + FILTER_VALIDATE_INT, + array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_FORCE_ARRAY) + ); + $appId = filter_var($_REQUEST['application'], FILTER_VALIDATE_INT); + if (!$applications && $appId) { + $applications[0] = $appId; + } + foreach ($applications as $app) { + $sql = " + DELETE FROM " . $this->wpdb->prefix . GLM_EMP_APPLICATION_TABLE ." + WHERE id = {$app}"; + $this->wpdb->query($sql); + $sql = " + DELETE FROM " . $this->wpdb->prefix . GLM_EMP_FORM_TABLE ." + WHERE application = {$app}"; + $this->wpdb->query($sql); + } } if( 'archive'===$this->current_action() ) { $applications = filter_var( @@ -244,9 +318,25 @@ class List_Applications extends GLM_List_Table WHERE id = {$app}"; $this->wpdb->query($sql); } -// wp_die('Items archived (or they would be if we had items to archive)!'); } - + if( 'unarchive'===$this->current_action() ) { + $applications = filter_var( + $_REQUEST['application'], + FILTER_VALIDATE_INT, + array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_FORCE_ARRAY) + ); + $appId = filter_var($_REQUEST['application'], FILTER_VALIDATE_INT); + if (!$applications && $appId) { + $applications[0] = $appId; + } + foreach ($applications as $app) { + $sql = " + UPDATE " . $this->wpdb->prefix . GLM_EMP_APPLICATION_TABLE ." + SET archived = false + WHERE id = {$app}"; + $this->wpdb->query($sql); + } + } } diff --git a/views/admin/applicationList.php b/views/admin/applicationList.php index 8bca340..d318cfd 100644 --- a/views/admin/applicationList.php +++ b/views/admin/applicationList.php @@ -5,7 +5,7 @@ if ($search = filter_var($_REQUEST['s'], FILTER_SANITIZE_STRING)) { } ?> diff --git a/views/front/formTemplate.php b/views/front/formTemplate.php index c97ebd2..2993c1e 100644 --- a/views/front/formTemplate.php +++ b/views/front/formTemplate.php @@ -15,12 +15,15 @@

-
+ + + +

@@ -75,6 +78,9 @@ + + +