--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Development
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+/**
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_management_jobsImport
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ /**
+ * Constructor
+ *
+ * This contractor sets up this model. At this time that only includes
+ * storing away the WordPress data object.
+ *
+ * @return object Class object
+ *
+ */
+ public function __construct ($wpdb, $config)
+ {
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ }
+
+ public function addScheme($url, $scheme = 'http://')
+ {
+ return parse_url($url, PHP_URL_SCHEME) === null ?
+ $scheme . $url : $url;
+ }
+
+ /**
+ * Perform Model Action
+ *
+ * This method does the work for this model and returns any resulting data
+ *
+ * @return array Status and data array
+ *
+ * 'status'
+ *
+ * True if successful and false if there was a fatal failure.
+ *
+ * 'menuItemRedirect'
+ *
+ * If not false, provides a menu item the controller should
+ * execute after this one. Normally if this is used, there would also be a
+ * modelRedirect value supplied as well.
+ *
+ * 'modelRedirect'
+ *
+ * If not false, provides an action the controller should execute after
+ * this one.
+ *
+ * 'view'
+ *
+ * A suggested view name that the controller should use instead of the
+ * default view for this model or false to indicate that the default view
+ * should be used.
+ *
+ * 'data'
+ *
+ * Data that the model is returning for use in merging with the view to
+ * produce output.
+ *
+ */
+ public function modelAction ($actionData = false)
+ {
+
+
+ $resultMessage = '';
+ $success = false;
+ $haveMembers = false;
+ $import = false;
+ $importNotice = '';
+ $option = '';
+
+ 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();
+
+ // 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 'importItems':
+ $table = GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'jobs';
+ 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);
+
+ foreach($job_titles as $key=>$value){
+ $wpdb->insert( GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'job_titles',
+ array(
+ 'old_id'=>$value['id'],
+ 'job_title'=>$value['name']
+ ),
+ array(
+ '%d',
+ '%s'
+ )
+ );
+ }
+ $job_sql = "SELECT * FROM job ORDER BY id;";
+ $stmt = $dbh->query($job_sql);
+ $jobs = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach($jobs as $key=>$value){
+ // echo '<pre>', print_r($value), '</pre>';
+ $post_date = false;
+ // echo $value ['operation'] . " : " . $value['requirements'] . " | <br>";
+ // echo '<br>';
+ if( $value['post'] == "30 days" ){
+ $post_date = 30;
+ }else if( $value['post'] == "60 days" ){
+ $post_date = 60;
+ }
+ // $url
+ // $wpdb->insert( $table,
+ // array(
+ // 'old_id'=>$value['id'],
+ // 'title'=>$value['departmentid'],
+ // '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'],
+ // 'visible'=>$value['visable'],
+ // 'facility_operation'=>$value['course_operations'],
+ // 'duration'=>$value['duration'],
+ // 'benefits'=>$value['bentext'],
+ // 'post_date'=>$value['ds'],
+ // 'requirements'=>$value['requirements'],
+ // 'member'=>$value['member'],
+ // 'position_available'=>$value['position_available'],
+ // 'duration'=>$value['duration'],
+ // 'deadline'=>$value['deadline'],
+ // 'job_expiration'=>$post_date,
+ // 'job_location'=>$value['joblocation'],
+ // ),
+ // array(
+ // '%d',
+ // '%d',
+ // '%s',
+ // '%s',
+ // '%s',
+ // '%s',
+ // '%s',
+ // '%s',
+ // '%s',
+ // '%s',
+ // '%d',
+ // '%s',
+ // '%s',
+ // '%s',
+ // '%d',
+ // '%s',
+ // '%d',
+ // '%s',
+ // '%s',
+ // '%s',
+ // '%d',
+ // '%s',
+ // )
+ // );
+ }
+ echo '<pre>', print_r($jobs), '</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;
+
+ // $sql = "SELECT name,mother_name,misc_info, courier_date FROM chxctyitem LIMIT $limit OFFSET $start";
+ // $jobs = $wpdb->get_results( $sql, ARRAY_A );
+
+ $count = 0;
+ // foreach($jobs as $column=>$data ){
+ // $count++;
+ // // $insert = array();
+
+ // }
+// echo '<pre>', print_r($insert), '</pre>';
+ // $wpdb->insert($table, $insert);
+
+ $resultMessage = "<pre>Start: $start</pre>";
+ $start += $limit;
+ $resultMessage .= "<p><a class='next-import-btn' href=\"". $url . "&limit=$limit&start=$start\">Next</a></p>";
+
+ break;
+
+ default:
+ break;
+ }
+
+ $templateData = array(
+ 'success' => $success,
+ 'option' => $option,
+ 'resultMessage' => $resultMessage
+ );
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => true,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/management/jobsImport.html',
+ 'data' => $templateData
+ );
+ }
+}