using management option for the job posting page form action instead of hardcoding the page url
* 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');
* option, which is to display the members dashboard.
*
*/
+
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 .= '<pre>$file_data: ' . print_r( $file_data, true ) . '</pre>';
- // 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 .= '<pre>$file_data: ' . print_r( $file_data, true ) . '</pre>';
+ // 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 '<pre>', print_r($jobs), '</pre>';
+ $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 '<pre>', print_r($jobs), '</pre>';
+
+ } catch(PDOException $e) {
+ echo '<pre>'.print_r($e, true).'</pre>';
+ }
- } catch(PDOException $e) {
- echo '<pre>'.print_r($e, true).'</pre>';
- }
-
- 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 = "<pre>Start: $start</pre>";
- $start += $limit;
- $resultMessage .= "<p><a class='next-import-btn' href=\"". $url . "&limit=$limit&start=$start\">Next</a></p>";
+ $resultMessage = "<pre>Start: $start</pre>";
+ $start += $limit;
+ $resultMessage .= "<p><a class='next-import-btn' href=\"". $url . "&limit=$limit&start=$start\">Next</a></p>";
+
+ 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
$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 ) ";
'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
function($addOnTabs) {
$newTabs = array(
array(
- 'text' => 'Jobs Import',
+ 'text' => 'Jobs',
'menu' => 'management',
'action' => 'jobsImport'
),
+++ /dev/null
--- 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
--- /dev/null
+-- 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
'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'),
);
--- /dev/null
+-- 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
{include file='admin/management/header.html'}
+<h2>Job List Page</h2>
+
+<div style="margin: 10px 0;">
+ <form action="{$thisUrl}?page={$thisPage}&glm_action=jobsImport&option=list_page_id" method="post" enctype="multipart/form-data">
+ <span>Page ID: </span>
+ <input type="text" name="list_page_id" id="list-page-id" {if $listPageId} value="{$listPageId}" {/if}>
+ <input type="submit" value="Save">
+ </form>
+</div>
<h2>Jobs Importer</h2>
<div class="front-job-listings-wrapper">
<div class="job-title-search glm-row">
- <form class="front-job-search" action="{$siteBaseUrl}job-postings" method="post" enctype="multipart/form-data">
+
+ <form class="front-job-search" action="{$listUrl}" method="post" enctype="multipart/form-data">
<select name="job_titles" id="job_title_dropdown">
<option value="">Show All</option>
{foreach $jobTitles as $jtitle=>$title}