Add resume file and archive, unarchive, delete abilities
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 16 Dec 2014 16:03:01 +0000 (11:03 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 16 Dec 2014 16:03:01 +0000 (11:03 -0500)
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
config/settings2.php
controllers/front.php
glm-employment.php
models/database.php
models/list-applications.php
views/admin/applicationList.php
views/front/formTemplate.php

index 6894d8b..97aad9d 100644 (file)
@@ -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',
index e6fb83b..799b538 100644 (file)
@@ -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]
 ];
index 858cda4..ad53b0a 100644 (file)
@@ -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 '<pre>'.print_r('appId:' . $this->appId, true).'</pre>';
-//                echo '<pre>'.print_r($_POST, true).'</pre>';
 //                echo '<pre>'.print_r('fname:' . $this->fname, true).'</pre>';
 //                echo '<pre>'.print_r('form:' . $form, true).'</pre>';
 //                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 '<pre>'.print_r($_SESSION, true).'</pre>';
+    }
+
+    public function store_resume_file()
+    {
+        echo '<pre>'.print_r($form, true).'</pre>';
+        if (!$appId = filter_var($_REQUEST['appId'], FILTER_VALIDATE_INT)) {
+            return false;
+        }
+        echo '<pre>'.print_r($_FILES, true).'</pre>';
+        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') {
index 042e6de..03ef072 100644 (file)
 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';
index 0b73952..31caccc 100644 (file)
@@ -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)
index 6c72df8..b30a648 100644 (file)
@@ -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 <td> (movie title only)
      **************************************************************************/
     function column_fname($item){
-
         //Build row actions
-        $actions = array(
-            'view'    => sprintf(
-                '<a href="?post_type=%s&page=%s&action=%s&application=%s">View</a>',
-                GLM_EMP_POST_TYPE,
-                $_REQUEST['page'],
-                'view',
-                $item['ID']
-            ),
-            'archive' => sprintf(
-                '<a href="?post_type=%s&page=%s&action=%s&application=%s">Archive</a>',
-                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(
+                    '<a href="'.$urlFormat.'">Unarchive</a>',
+                    GLM_EMP_POST_TYPE,
+                    $_REQUEST['page'],
+                    'unarchive',
+                    $item['ID'],
+                    $_REQUEST['archived']
+                ),
+                'delete' => sprintf(
+                    '<a href="'.$urlFormat.'">Delete Permanently</a>',
+                    GLM_EMP_POST_TYPE,
+                    $_REQUEST['page'],
+                    'delete',
+                    $item['ID'],
+                    $_REQUEST['archived']
+                ),
+            );
+        } else {
+            $actions = array(
+                'view'    => sprintf(
+                    '<a href="?post_type=%s&page=%s&action=%s&application=%s">View</a>',
+                    GLM_EMP_POST_TYPE,
+                    $_REQUEST['page'],
+                    'view',
+                    $item['ID']
+                ),
+                'archive' => sprintf(
+                    '<a href="?post_type=%s&page=%s&action=%s&application=%s">Archive</a>',
+                    GLM_EMP_POST_TYPE,
+                    $_REQUEST['page'],
+                    'archive',
+                    $item['ID']
+                )
+            );
+        }
+
 
         //Return the title contents
         return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%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  = '<a href="%s%s">Resume File</a>';
+            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'          => '<input type="checkbox" />', //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);
+            }
+        }
     }
 
 
index 8bca340..d318cfd 100644 (file)
@@ -5,7 +5,7 @@ if ($search = filter_var($_REQUEST['s'], FILTER_SANITIZE_STRING)) {
 }
 ?>
 <ul class="subsubsub">
-    <li class="all"><a href="edit.php?post_type=<?php echo GLM_EMP_POST_TYPE;?>&page=applications">All</a> |</li>
+    <li class="all"><a href="edit.php?post_type=<?php echo GLM_EMP_POST_TYPE;?>&page=applications">Unarchived</a> |</li>
     <li class="all"><a href="edit.php?post_type=<?php echo GLM_EMP_POST_TYPE;?>&page=applications&archived=1">Archived</a></li>
 </ul>
 
index c97ebd2..2993c1e 100644 (file)
 <div class="row">
     <div class="small-12 columns">
         <h1><?php echo $formTitle;?></h1>
-        <form method="post" action="<?php echo $formAction;?>">
+        <form method="post" action="<?php echo $formAction;?>" enctype="multipart/form-data">
             <input type="hidden" name="<?php echo self::FORM_VAR;?>" value="1">
             <input type="hidden" name="form_part" value="<?php echo $formPart;?>" />
             <?php if ($appId):?>
             <input type="hidden" name="appId" value="<?php echo $appId;?>">
             <?php endif;?>
+            <?php if ($jobId):?>
+            <input type="hidden" name="job" value="<?php echo $jobId;?>">
+            <?php endif;?>
             <?php foreach($form as $row):?>
             <?php if ($row['type'] == 'header') :?>
                 <h3><?php echo $row['label'];?></h3>
@@ -75,6 +78,9 @@
                             <?php case 'static':?>
                                 <?php echo $field['value'];?>
                             <?php break;?>
+                            <?php case 'file':?>
+                                <input type="file" name="resume_file">
+                            <?php break;?>
                             <?php case 'textarea':?>
                             <textarea
                                 <?php if ($field['error']){echo 'class="error"';}?>