From: Anthony Talarico Date: Wed, 1 Aug 2018 13:39:06 +0000 (-0400) Subject: adding management option for the job postings page id, so that it doesn't have to... X-Git-Tag: v1.0.0~1^2~5 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=2f96811e78aa131f459a5900db0fe00720150e77;p=WP-Plugins%2Fglm-member-db-jobs.git adding management option for the job postings page id, so that it doesn't have to be hardcoded using management option for the job posting page form action instead of hardcoding the page url --- diff --git a/index.php b/index.php index 64eba29..dc2f4ff 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_JOBS_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_JOBS_PLUGIN_DB_VERSION', '0.0.3'); +define('GLM_MEMBERS_JOBS_PLUGIN_DB_VERSION', '0.0.4'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_JOBS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/models/admin/management/jobsImport.php b/models/admin/management/jobsImport.php index 7684086..cc97d1e 100644 --- a/models/admin/management/jobsImport.php +++ b/models/admin/management/jobsImport.php @@ -17,6 +17,7 @@ * option, which is to display the members dashboard. * */ + class GlmMembersAdmin_management_jobsImport { @@ -104,174 +105,211 @@ class GlmMembersAdmin_management_jobsImport $import = false; $importNotice = ''; $option = ''; + $pageIdEmpty = false; + + $sql = "SELECT list_page_id FROM " . GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . "management"; + $list_page_id = $this->wpdb->get_results($sql, 'ARRAY_A'); + + if(!empty($list_page_id)){ + $list_page_id = $list_page_id[0]['list_page_id']; + }else{ + $pageIdEmpty = true; + } + + if(is_numeric( $_REQUEST['list_page_id'])){ + $page_id = $_REQUEST['list_page_id']; + } else if(!$pageIdEmpty && !is_numeric( $_REQUEST['list_page_id'])) { + $page_id = $list_page_id; + }else{ + $page_id = 0; + } if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') { $option = $_REQUEST['option']; } switch($option) { - case 'upload_file': - // We're given a CSV file. - // We need to parse it out. File must have header line. - // $file_data = $file_headers = $data = $members = array(); + case 'list_page_id': + if(!$pageIdEmpty){ + $sql = "UPDATE ". GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX. "management SET list_page_id = ". $page_id ." WHERE id = 1"; + $this->wpdb->query($sql); + }else{ + $this->wpdb->insert( + GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'management', + array( + 'list_page_id' => $page_id + ), + array( '%d','%d' ) + ); + } + $sql = "SELECT list_page_id FROM " . GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . "management"; + $list_page_id = $this->wpdb->get_results($sql, 'ARRAY_A'); + $list_page_id = $list_page_id[0]['list_page_id']; + break; + case 'upload_file': + // We're given a CSV file. + // We need to parse it out. File must have header line. + // $file_data = $file_headers = $data = $members = array(); - // if ( isset( $_FILES ) && isset( $_FILES['file_upload'] ) && ( $fh = fopen( $_FILES['file_upload']['tmp_name'], 'r' ) ) !== false ) { - // $row = 0; - // while( ( $data = fgetcsv( $fh, 1000, ',' ) ) !== false ) { - // if ( $row === 0 ) { - // // First row grab as headers. - // $file_headers = $data; - // } else { - // // All other rows are data. - // $file_data[] = array_combine( $file_headers, $data ); - // } - // $row++; - // } - // fclose( $fh ); - // } - // $resultMessage .= $this->importMemberData( $file_data ); - //$resultMessage .= '
$file_data: ' . print_r( $file_data, true ) . '
'; - // break; - - case 'importJobs': - global $wpdb; - $table = GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'jobs'; - $members_table = GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members'; - - define('BASE_URL', 'http://www.migcsa.org'); - define('PG_DSN', 'pgsql: host=ds4 dbname=migcsa2_update user=postgres'); - - try { - $dsn = PG_DSN; - $driverOptions = array( - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ); - $dbh = new PDO($dsn, null, null, $driverOptions); - $dbh->setAttribute( - PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION - ); - // JOBS - $job_titles_sql = "SELECT * FROM job_department;"; - $stmt = $dbh->query($job_titles_sql); - $job_titles = $stmt->fetchAll(PDO::FETCH_ASSOC); - $title_results = []; + // if ( isset( $_FILES ) && isset( $_FILES['file_upload'] ) && ( $fh = fopen( $_FILES['file_upload']['tmp_name'], 'r' ) ) !== false ) { + // $row = 0; + // while( ( $data = fgetcsv( $fh, 1000, ',' ) ) !== false ) { + // if ( $row === 0 ) { + // // First row grab as headers. + // $file_headers = $data; + // } else { + // // All other rows are data. + // $file_data[] = array_combine( $file_headers, $data ); + // } + // $row++; + // } + // fclose( $fh ); + // } + // $resultMessage .= $this->importMemberData( $file_data ); + //$resultMessage .= '
$file_data: ' . print_r( $file_data, true ) . '
'; + // break; - foreach($job_titles as $key=>$value){ - // - $this->wpdb->insert( GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'job_titles', - array( - 'old_id'=>$value['id'], - 'job_title'=>$value['name'] - ), - array( - '%d', - '%s' - ) - ); - $title_results[$value['id']] = array('new_id'=>$this->wpdb->insert_id, 'title'=>$value['name']); - } + case 'importJobs': + global $wpdb; + $table = GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'jobs'; + $members_table = GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members'; + + define('BASE_URL', 'http://www.migcsa.org'); + define('PG_DSN', 'pgsql: host=ds4 dbname=migcsa2_update user=postgres'); - $job_sql = "SELECT * FROM job ORDER BY id;"; - $stmt = $dbh->query($job_sql); - $jobs = $stmt->fetchAll(PDO::FETCH_ASSOC); - foreach($jobs as $key=>$value){ - $sql = "SELECT id FROM $members_table WHERE old_member_id = " . $value['member']; - $new_id = $wpdb->get_var($sql); - $post_exp = false; - if( $value['post'] == "30 days" ){ - $post_exp = 30; - }else if( $value['post'] == "60 days" ){ - $post_exp = 60; - } + try { + $dsn = PG_DSN; + $driverOptions = array( + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ); + $dbh = new PDO($dsn, null, null, $driverOptions); + $dbh->setAttribute( + PDO::ATTR_ERRMODE, + PDO::ERRMODE_EXCEPTION + ); + // JOBS + $job_titles_sql = "SELECT * FROM job_department;"; + $stmt = $dbh->query($job_titles_sql); + $job_titles = $stmt->fetchAll(PDO::FETCH_ASSOC); + $title_results = []; + + foreach($job_titles as $key=>$value){ + // + $this->wpdb->insert( GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'job_titles', + array( + 'old_id'=>$value['id'], + 'job_title'=>$value['name'] + ), + array( + '%d', + '%s' + ) + ); + $title_results[$value['id']] = array('new_id'=>$this->wpdb->insert_id, 'title'=>$value['name']); + } + + $job_sql = "SELECT * FROM job ORDER BY id;"; + $stmt = $dbh->query($job_sql); + $jobs = $stmt->fetchAll(PDO::FETCH_ASSOC); + foreach($jobs as $key=>$value){ + $sql = "SELECT id FROM $members_table WHERE old_member_id = " . $value['member']; + $new_id = $wpdb->get_var($sql); + $post_exp = false; + if( $value['post'] == "30 days" ){ + $post_exp = 30; + }else if( $value['post'] == "60 days" ){ + $post_exp = 60; + } - $this->wpdb->insert( $table, - array( - 'old_id'=>$value['id'], - 'title'=>$title_results[$value['departmentid']]['new_id'], - 'descr'=>$value['descr'], - 'company'=>$value['operation'], - 'salary'=>$value['salary'], - 'descr'=>$value['descr'], - 'resume_location'=>$value['location'], - 'email_location'=>$value['contactemail'], - 'contact_name'=>$value['contactname'], - 'contact_phone'=>$value['contactphone'], - 'active'=>$value['visable'], - 'facility_operation'=>$value['course_operations'], - 'duration'=>$value['duration'], - 'benefits'=>$value['bentext'], - 'post_date'=>$value['ds'], - 'updated'=>$value['ds'], - 'requirements'=>$value['requirements'], - 'member'=>$new_id, - 'position_available'=>$value['position_available'], - 'duration'=>$value['duration'], - 'deadline'=>$value['deadline'], - 'job_expiration'=>$post_exp, - 'job_location'=>$value['joblocation'], - ), - array( - '%d', - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s', - '%d', - '%s', - '%s', - '%s', - '%d', - '%s', - ) - ); - } - // echo '
', print_r($jobs), '
'; + $this->wpdb->insert( $table, + array( + 'old_id'=>$value['id'], + 'title'=>$title_results[$value['departmentid']]['new_id'], + 'descr'=>$value['descr'], + 'company'=>$value['operation'], + 'salary'=>$value['salary'], + 'descr'=>$value['descr'], + 'resume_location'=>$value['location'], + 'email_location'=>$value['contactemail'], + 'contact_name'=>$value['contactname'], + 'contact_phone'=>$value['contactphone'], + 'active'=>$value['visable'], + 'facility_operation'=>$value['course_operations'], + 'duration'=>$value['duration'], + 'benefits'=>$value['bentext'], + 'post_date'=>$value['ds'], + 'updated'=>$value['ds'], + 'requirements'=>$value['requirements'], + 'member'=>$new_id, + 'position_available'=>$value['position_available'], + 'duration'=>$value['duration'], + 'deadline'=>$value['deadline'], + 'job_expiration'=>$post_exp, + 'job_location'=>$value['joblocation'], + ), + array( + '%d', + '%d', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%d', + '%s', + '%s', + '%s', + '%d', + '%s', + ) + ); + } + // echo '
', print_r($jobs), '
'; + + } catch(PDOException $e) { + echo '
'.print_r($e, true).'
'; + } - } catch(PDOException $e) { - echo '
'.print_r($e, true).'
'; - } - - if ( isset( $_REQUEST['start'] ) ) { - $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); - } else { - $start = 0; - } - // global $wpdb; - - - $url = get_site_url() . '/wp-admin/admin.php?page=glm-members-admin-menu-management&glm_action=jobImport&option=importJobs'; - $limit = 200; - - $count = 0; + if ( isset( $_REQUEST['start'] ) ) { + $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); + } else { + $start = 0; + } + // global $wpdb; + + + $url = get_site_url() . '/wp-admin/admin.php?page=glm-members-admin-menu-management&glm_action=jobImport&option=importJobs'; + $limit = 200; + + $count = 0; - $resultMessage = "
Start: $start
"; - $start += $limit; - $resultMessage .= "

Next

"; + $resultMessage = "
Start: $start
"; + $start += $limit; + $resultMessage .= "

Next

"; + + break; - break; - - default: + default: break; } + $templateData = array( 'success' => $success, 'option' => $option, - 'resultMessage' => $resultMessage + 'resultMessage' => $resultMessage, + 'listPageId' => $page_id ); // Return status, suggested view, and data to controller diff --git a/models/front/jobs/list.php b/models/front/jobs/list.php index 7c94135..0a92d0c 100644 --- a/models/front/jobs/list.php +++ b/models/front/jobs/list.php @@ -111,8 +111,15 @@ class GlmMembersFront_jobs_list extends GlmDatajobs $members_only_page = get_option(GLM_MEMBERS_PLUGIN_OPTION_MEMBERS_ONLY_ID); $is_members_only = is_in_tree($members_only_page); $job_titles = new GlmDataJobTitles($this->wpdb,$this->config); - - + $listUrl = GLM_MEMBERS_JOBS_SITE_BASE_URL ."/job-postings"; + + $sql = "SELECT list_page_id FROM " . GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . "management"; + $list_page_id = $this->wpdb->get_results($sql, 'ARRAY_A'); + + if(!empty($list_page_id)){ + $listUrl = get_permalink($list_page_id[0]['list_page_id']); + } + if( $exclude_jobs && ( !$is_members_only && $members_only ) ){ $job_titles_where .= "AND id NOT IN ( $exclude_jobs ) "; $jobs_where .= "AND title NOT IN ( $exclude_jobs ) "; @@ -146,6 +153,7 @@ class GlmMembersFront_jobs_list extends GlmDatajobs 'jobTitles' => $job_titles, 'siteBaseUrl' => GLM_MEMBERS_JOBS_SITE_BASE_URL, 'currentUrl' => GLM_MEMBERS_JOBS_PLUGIN_CURRENT_URL, + 'listUrl' => $listUrl ); // Return status, any suggested view, and any data to controller diff --git a/setup/adminTabs.php b/setup/adminTabs.php index c467e61..e39af60 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -73,7 +73,7 @@ if (current_user_can('glm_members_members')) { function($addOnTabs) { $newTabs = array( array( - 'text' => 'Jobs Import', + 'text' => 'Jobs', 'menu' => 'management', 'action' => 'jobsImport' ), diff --git a/setup/databaseScripts/create_database_V0.0.3.sql b/setup/databaseScripts/create_database_V0.0.3.sql deleted file mode 100644 index fae5e98..0000000 --- a/setup/databaseScripts/create_database_V0.0.3.sql +++ /dev/null @@ -1,90 +0,0 @@ --- Gaslight Media Members Database - Job Postings --- File Created: 11/20/17 15:27:15 --- Database Version: 0.0.3 --- Database Creation Script --- --- This file is called to create a new set of tables for this --- add-on for the most receint database version for this add-on. --- --- There should only be one such file in this directory --- --- To permit each query below to be executed separately, --- all queries must be separated by a line with four dashes - --- Conditions Table -CREATE TABLE {prefix}jobs ( - id INT NOT NULL AUTO_INCREMENT, - old_id int NULL , - title int NULL , - descr TEXT NULL , - salary TINYTEXT NULL , - email_location TINYTEXT NULL , - resume_location TINYTEXT NULL , - contact_name TINYTEXT NULL , - contact_phone TINYTEXT NULL , - post_date DATETIME NULL, - updated DATETIME NULL, - active BOOL NULL, - facility_operation TEXT NULL, - requirements TEXT NULL, - benefits TEXT NULL , - job_location TINYTEXT NULL , - job_expiration INT NULL, - duration TINYTEXT NULL , - deadline TINYTEXT NULL , - company TINYTEXT NULL , - repost TINYTEXT NULL , - position_available TINYTEXT NULL , - member INT NULL, - PRIMARY KEY (id) -); - ----- - --- Job Titles -CREATE TABLE {prefix}job_titles ( - id INT NOT NULL AUTO_INCREMENT, - old_id INT NULL, - job_title TINYTEXT NULL , - PRIMARY KEY (id) -); - ----- - --- Event Email Notifications -CREATE TABLE {prefix}email_notifications ( - id INT NOT NULL AUTO_INCREMENT, - job_declined_message TEXT NULL, -- Event declined message - job_approved_message TEXT NULL, -- Event approved message - job_to_email TINYTEXT NULL, -- To Email Address - job_from_email TINYTEXT NULL, -- From Email Address - job_email_notification TEXT NULL, -- Email notification message - PRIMARY KEY (id) -); - ----- - --- Set default event email settings -INSERT INTO {prefix}email_notifications - ( id, job_declined_message, job_approved_message ) - VALUES - ( 1, 'The Job parameters do not comply with our event guidelines.', 'Your Job has been approved.' ) -; - ----- - --- Job Titles default entries in table --- INSERT INTO {prefix}job_titles ( id,old_id,job_title) VALUES --- (1,1, 'Supervisor'),(2,1,'Groundskeeper'),(3,1,'Janitor'); - ----- - --- Job Titles default entries in table --- INSERT INTO {prefix}jobs ( --- id,old_id,title,descr,salary, email_location,resume_location,contact_name,contact_phone,post_date,updated,visible, --- facility_operation,requirements,job_location,job_expiration,duration,deadline,position_available, --- company,member,benefits --- ) VALUES ( 1,1, 1,"DESCRIPTION",'SALARY', 'EMAIL LOCATION', 'RESUME LOCATION','CONTACT NAME', '453-3443', NOW(),NOW(), true, --- 'facility operations', 'REQUIREMENTS', 'JOB LOCATION', 30, 'JOB DURATION', 'DEADLINE', 'POSITION AVAILABLE', --- 'COMPANY', 1, 'JOB BENEFITS' --- ); \ No newline at end of file diff --git a/setup/databaseScripts/create_database_V0.0.4.sql b/setup/databaseScripts/create_database_V0.0.4.sql new file mode 100644 index 0000000..312dc05 --- /dev/null +++ b/setup/databaseScripts/create_database_V0.0.4.sql @@ -0,0 +1,99 @@ +-- Gaslight Media Members Database - Job Postings +-- File Created: 11/20/17 15:27:15 +-- Database Version: 0.0.3 +-- Database Creation Script +-- +-- This file is called to create a new set of tables for this +-- add-on for the most receint database version for this add-on. +-- +-- There should only be one such file in this directory +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Conditions Table +CREATE TABLE {prefix}jobs ( + id INT NOT NULL AUTO_INCREMENT, + old_id int NULL , + title int NULL , + descr TEXT NULL , + salary TINYTEXT NULL , + email_location TINYTEXT NULL , + resume_location TINYTEXT NULL , + contact_name TINYTEXT NULL , + contact_phone TINYTEXT NULL , + post_date DATETIME NULL, + updated DATETIME NULL, + active BOOL NULL, + facility_operation TEXT NULL, + requirements TEXT NULL, + benefits TEXT NULL , + job_location TINYTEXT NULL , + job_expiration INT NULL, + duration TINYTEXT NULL , + deadline TINYTEXT NULL , + company TINYTEXT NULL , + repost TINYTEXT NULL , + position_available TINYTEXT NULL , + member INT NULL, + PRIMARY KEY (id) +); + +---- + +-- Job Titles +CREATE TABLE {prefix}job_titles ( + id INT NOT NULL AUTO_INCREMENT, + old_id INT NULL, + job_title TINYTEXT NULL , + PRIMARY KEY (id) +); + +---- + +-- Event Email Notifications +CREATE TABLE {prefix}email_notifications ( + id INT NOT NULL AUTO_INCREMENT, + job_declined_message TEXT NULL, -- Event declined message + job_approved_message TEXT NULL, -- Event approved message + job_to_email TINYTEXT NULL, -- To Email Address + job_from_email TINYTEXT NULL, -- From Email Address + job_email_notification TEXT NULL, -- Email notification message + PRIMARY KEY (id) +); + +---- + +-- Event Email Notifications +CREATE TABLE {prefix}management ( + id INT NOT NULL AUTO_INCREMENT, + list_page_id INT NULL, + PRIMARY KEY (id) +); + +---- + +-- Set default event email settings +INSERT INTO {prefix}email_notifications + ( id, job_declined_message, job_approved_message ) + VALUES + ( 1, 'The Job parameters do not comply with our event guidelines.', 'Your Job has been approved.' ) +; + +---- + +-- Job Titles default entries in table +-- INSERT INTO {prefix}job_titles ( id,old_id,job_title) VALUES +-- (1,1, 'Supervisor'),(2,1,'Groundskeeper'),(3,1,'Janitor'); + +---- + +-- Job Titles default entries in table +-- INSERT INTO {prefix}jobs ( +-- id,old_id,title,descr,salary, email_location,resume_location,contact_name,contact_phone,post_date,updated,visible, +-- facility_operation,requirements,job_location,job_expiration,duration,deadline,position_available, +-- company,member,benefits +-- ) VALUES ( 1,1, 1,"DESCRIPTION",'SALARY', 'EMAIL LOCATION', 'RESUME LOCATION','CONTACT NAME', '453-3443', NOW(),NOW(), true, +-- 'facility operations', 'REQUIREMENTS', 'JOB LOCATION', 30, 'JOB DURATION', 'DEADLINE', 'POSITION AVAILABLE', +-- 'COMPANY', 1, 'JOB BENEFITS' +-- ); \ No newline at end of file diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 61a0e8b..35200ae 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -37,4 +37,5 @@ $glmMembersjobsDbVersions = array( '0.0.1' => array('version' => '0.0.1', 'tables' => 2, 'date' => '09/08/2017'), '0.0.2' => array('version' => '0.0.2', 'tables' => 2, 'date' => '11/21/2017'), '0.0.3' => array('version' => '0.0.3', 'tables' => 3, 'date' => '12/21/2017'), + '0.0.4' => array('version' => '0.0.4', 'tables' => 4, 'date' => '07/31/2018'), ); diff --git a/setup/databaseScripts/update_database_V0.0.4.sql b/setup/databaseScripts/update_database_V0.0.4.sql new file mode 100644 index 0000000..f5ef249 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.4.sql @@ -0,0 +1,14 @@ +-- Gaslight Media Members Database - Events Add-On +-- File Created: 2017-08-04 +-- Database Version: 0.0.4 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Event Email Notifications +CREATE TABLE {prefix}management ( + id INT NOT NULL AUTO_INCREMENT, + list_page_id INT NULL, + PRIMARY KEY (id) +); \ No newline at end of file diff --git a/views/admin/management/jobsImport.html b/views/admin/management/jobsImport.html index d99958b..19e3a97 100644 --- a/views/admin/management/jobsImport.html +++ b/views/admin/management/jobsImport.html @@ -1,4 +1,13 @@ {include file='admin/management/header.html'} +

Job List Page

+ +
+
+ Page ID: + + +
+

Jobs Importer

diff --git a/views/front/jobs/list.html b/views/front/jobs/list.html index 2f488ed..457e246 100644 --- a/views/front/jobs/list.html +++ b/views/front/jobs/list.html @@ -1,6 +1,7 @@