*/
public function add_job_menus()
{
- //add_submenu_page(
- //'edit.php?post_type=' . GLM_EMP_POST_TYPE,
- //'applications',
- //'Applications',
- //'edit_posts',
- //'applications',
- //array($this, 'get_applications')
- //);
+ add_submenu_page(
+ 'edit.php?post_type=' . GLM_EMP_POST_TYPE,
+ 'applications',
+ 'Applications',
+ 'edit_posts',
+ 'applications',
+ array($this, 'get_applications')
+ );
+ add_submenu_page(
+ 'edit.php?post_type=' . GLM_EMP_POST_TYPE,
+ 'import',
+ 'Import',
+ 'edit_posts',
+ 'import',
+ array($this, 'import')
+ );
add_submenu_page(
'edit.php?post_type=' . GLM_EMP_POST_TYPE,
'settings',
case 'view':
$this->view_application();
break;
+ case 'print':
+ echo '<pre>' . print_r( $_REQUEST, true ) . '</pre>';
+ if ( $id = filter_var( $_REQUEST['application'], FILTER_VALIDATE_INT ) ) {
+ echo '<pre>' . print_r( $this->get_application_by_id($id), true ) . '</pre>';
+ }
+ break;
default:
$this->show_applications();
break;
}
}
+ public function get_application_by_id($id)
+ {
+ global $wpdb;
+ return $wpdb->get_row("SELECT * FROM {$wpdb->prefix}" . GLM_EMP_APPLICATION_TABLE . " WHERE id = $id");
+ }
+
+ /**
+ * import
+ *
+ * Includes a form then takes the uploaded csv file and imports the applications
+ * Will try to get the position id correct by referencing the title
+ *
+ * How to export out the applications to csv file from psql
+ *
+ * COPY (SELECT a.id,t.title_name AS position,a.resume_file,a.fname,a.lname,a.mname,a.create_date,a.archived
+ * FROM application a
+ * LEFT OUTER JOIN employment e ON (e.employment_id = a.employment_id)
+ * LEFT OUTER JOIN title t ON (t.title_id = e.title_id)) to '/tmp/applications.csv' delimiter ',' CSV HEADER;
+ */
+ public function import()
+ {
+ $action = (isset($_REQUEST['action']))
+ ? filter_var($_REQUEST['action'], FILTER_SANITIZE_STRING)
+ : null;
+ switch ($action) {
+ case 'upload':
+ //$this->upload_file();
+ echo '<pre>' . print_r( $_POST, true ) . '</pre>';
+ echo '<pre>' . print_r( $_FILES, true ) . '</pre>';
+ if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
+ return new WP_Error('upload_error', $uploads['error']);
+ }
+ $importUploadFile = $uploads['basedir'] . '/applicationImportFile.csv';
+ echo '<pre>' . print_r( $uploads, true ) . '</pre>';
+ echo '<pre>' . print_r( $importUploadFile, true ) . '</pre>';
+ if ( isset( $_FILES['glm_emp_import'] )
+ && !$_FILES['glm_emp_import']['error']
+ && $_FILES['glm_emp_import']['size'] > 0
+ && move_uploaded_file( $_FILES['glm_emp_import']['tmp_name'], $importUploadFile ) ) {
+ $contents = $this->readCsvFile($importUploadFile);
+ //echo '<pre>' . print_r( $contents, true ) . '</pre>';
+ foreach ( $contents as $row ) {
+ $this->addApplicationRecord($row);
+ }
+ }
+ break;
+ default:
+ $this->show_import_form();
+ break;
+ }
+ }
+
+ public function addApplicationRecord($data)
+ {
+ echo '<pre>' . print_r( $data, true ) . '</pre>';
+ global $wpdb;
+ // if data has a position then check for a matching job record
+ if ( $data['position'] ) {
+ $sql = "
+ SELECT ID
+ FROM {$wpdb->prefix}posts
+ WHERE post_type = '" . GLM_EMP_POST_TYPE . "'
+ AND post_title = '" . $test . "'";
+ $preSql = "SELECT ID
+ FROM {$wpdb->prefix}posts
+ WHERE post_type = %s
+ AND post_title = %s";
+ $sql = $wpdb->prepare($preSql, GLM_EMP_POST_TYPE, $data['position']);
+ $position = $wpdb->get_var( $sql );
+ } else {
+ $position = 0;
+ }
+ if ( $data['archived'] == 't' ) {
+ $archived = 1;
+ } else {
+ $archived = 0;
+ }
+ $import_data = array(
+ 'id' => $data['id'],
+ 'create_time' => $data['create_date'],
+ 'fname' => $data['fname'],
+ 'lname' => $data['lname'],
+ 'mname' => $data['mname'],
+ 'position' => $position,
+ 'resume' => $data['resume_file'],
+ 'archived' => $archived
+ );
+ echo '<pre>' . print_r( $import_data, true ) . '</pre>';
+ $return = $wpdb->insert(
+ $this->wpdb->prefix . GLM_EMP_APPLICATION_TABLE,
+ $import_data,
+ array(
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%d'
+ )
+ );
+ if (!$return) {
+ echo '<p style="color:red;">failed to insert: ' . $wpdb->last_error . '</p>';
+ }
+ echo '<p>Record Insert: ' . ( ($return) ? '<span style="color:green;">Success</span>' : '<span style="color:red;">Failed!</span>' ) . '</p>';
+ }
+
+ public function readCsvFile($importUploadFile)
+ {
+ $fp = fopen($importUploadFile, 'r');
+ if (!$fp) {
+ return false;
+ }
+ $data = array();
+ $index = 0;
+ while ( ( $line = fgetcsv( $fp ) ) !== false ) {
+ if ( $index == 0 ) {
+ $headers = $line;
+ } else {
+ $data[] = array_combine( $headers, $line );
+ }
+ //echo '<pre>' . print_r( $line, true ) . '</pre>';
+ ++$index;
+ }
+ fclose($fp);
+ return $data;
+ }
+
+ /**
+ * show_import_form
+ *
+ * Pulls in the form for the upload
+ *
+ * @access public
+ * @return void
+ */
+ public function show_import_form()
+ {
+ $viewPath = $this->pluginDirName . 'views/admin/';
+ include $viewPath . 'import-form.php';
+ }
+
/**
* View the application for one id
*/
public function view_application()
{
- wp_enqueue_script(
- 'foundation',
- get_template_directory_uri() . '/js/app.js',
- 'jquery',
- '1.0',
- true
- );
- wp_enqueue_style('foundation', get_template_directory_uri() . '/css/app.js');
+ //wp_enqueue_script(
+ //'foundation',
+ //get_template_directory_uri() . '/js/app.js',
+ //'jquery',
+ //'1.0',
+ //true
+ //);
+ //wp_enqueue_style('foundation', get_template_directory_uri() . '/css/app.js');
$id = filter_var($_REQUEST['application'], FILTER_VALIDATE_INT);
$sql = "
SELECT *
} else {
$where[] = "archived <> true";
}
- $where[] = "(SELECT count(*) FROM "
- . $this->wpdb->prefix . GLM_EMP_FORM_TABLE . " glm_ft WHERE glm_ft.form_part = 7 AND glm_ft.application = glm_at.id)";
+ //$where[] = "(SELECT count(*) FROM "
+ //. $this->wpdb->prefix . GLM_EMP_FORM_TABLE . " glm_ft WHERE glm_ft.form_part = 7 AND glm_ft.application = glm_at.id)";
$sql = "
- SELECT id as ID,fname,lname,create_time,archived,position,resume
+ SELECT id as ID,fname,lname,DATE(create_time) as create_time,archived,position,resume
FROM " . $this->wpdb->prefix . GLM_EMP_APPLICATION_TABLE . " glm_at
";
if (!empty($where)) {
),
);
} else {
+ $pdf_file_name = GLM_EMP_UPLOAD_DIR . $item['create_time'] . '-' . $item['ID'] . '.pdf' ;
+ $pdf_file_name_url = GLM_EMP_UPLOAD_URL . $item['create_time'] . '-' . $item['ID'] . '.pdf' ;
+ if ( is_file($pdf_file_name ) ) {
+ $printAction = sprintf(
+ '<a href="%s" target="_blank">Print</a>',
+ $pdf_file_name_url
+ );
+ } else {
+ $printAction = '';
+ }
$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']
- ),
+ 'print' => $printAction,
'archive' => sprintf(
'<a href="?post_type=%s&page=%s&action=%s&application=%s">Archive</a>',
GLM_EMP_POST_TYPE,
GLM_EMP_UPLOAD_URL,
$item['resume']
);
+ } else if ( $item['resume'] ) {
+ return $item['resume'] . ' not found in ' . GLM_EMP_UPLOAD_DIR;
} else {
return '';
}
/**
* First, lets decide how many records per page to show
*/
- $per_page = 5;
+ $per_page = 20;
/**