Updates on the email notifications
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 11 Dec 2015 14:19:17 +0000 (09:19 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 11 Dec 2015 14:19:17 +0000 (09:19 -0500)
I have the setting page working and storing the emails.
Each property taxomony has a setting for name and email that will be
used for the application form.

controllers/admin.php
controllers/front.php
glm-employment.php
views/optionsPage.php

index 27b4899..07bb7c3 100644 (file)
@@ -29,7 +29,7 @@ class staffords_employment_admin
         $this->wpdb = $wpdb;
         $jobs = new staffords_employment_job($path);
         add_action('admin_menu', array($this, 'add_job_menus'));
-        add_action('admin-init', array($this, 'job_settings_init') );
+        add_action('admin_init', array($this, 'job_settings_init') );
     }
 
     /**
@@ -94,24 +94,86 @@ class staffords_employment_admin
 
     public function job_settings_init()
     {
-        register_setting(STAFFORDS_EMP_SETTINGS, STAFFORDS_EMP_SETTINGS);
-        add_filter(
-            'option_page_capability_job-setting-group',
-            array($this, 'staffords_option_page_capability')
+        //add_filter(
+            //'option_page_capability_job-setting-group',
+            //array($this, 'staffords_option_page_capability')
+        //);
+        add_settings_section(
+            'staffordsjobs_setting_section_two',
+            'Edit Confirmations',
+            array($this, 'staffords_settings_two_section_callback'),
+            'staffordsjobs_settings'
+        );
+        add_settings_field(
+            'thank_you_text',
+            'Thank You Message',
+            array($this, 'glmclientinfoRenderTextArea'),
+            'staffordsjobs_settings',
+            'staffordsjobs_setting_section_two',
+            'thank_you_text'
         );
         add_settings_section(
-            'staffordsjobs_main',
-            __('Edit Jobs Settings', 'wordpress'),
+            'staffordsjobs_setting_section',
+            'Edit Notifications',
             array($this, 'staffords_settings_section_callback'),
-            'job-setting-group'
+            'staffordsjobs_settings'
         );
         $fieldNames = array(
             array(
-                'name'  => 'notificationEmail',
-                'label' => 'Notification Email Address',
+                'name'  => 'notification_name',
+                'label' => 'Staffords Notify: Name',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'notification_email',
+                'label' => 'Staffords Notify: Email',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'from_name',
+                'label' => 'From: Name',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'from_email',
+                'label' => 'From: Email',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'replyto_name',
+                'label' => 'Reply-To: Name',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'replyto_email',
+                'label' => 'Reply-To: Email',
                 'type'  => 'text'
+            ),
+            array(
+                'name'  => 'notification_message',
+                'label' => 'Notification Message',
+                'type'  => 'textarea'
+            ),
+        );
+        $terms = get_terms(
+            STAFFORDS_EMP_TAX_DEPARTMENTS,
+            array(
+                'hide_empty' => false
             )
         );
+        foreach ($terms as $term) {
+            $termArray[] = $term->name;
+            $fieldNames[] = array(
+                'name'  => $term->slug . '_notification_name',
+                'label' => $term->name . ': Name',
+                'type'  => 'text'
+            );
+            $fieldNames[] = array(
+                'name'  => $term->slug . '_notification_email',
+                'label' => $term->name . ': Email',
+                'type'  => 'text'
+            );
+        }
 
         foreach ($fieldNames as $field) {
             $this->staffords_add_setting_text_field(
@@ -120,6 +182,7 @@ class staffords_employment_admin
                 $field['type']
             );
         }
+        register_setting(STAFFORDS_EMP_SETTINGS, STAFFORDS_EMP_SETTING_NAME);
     }
 
     public function staffords_add_setting_text_field($name, $label, $type)
@@ -140,10 +203,10 @@ class staffords_employment_admin
         }
         add_settings_field(
             $name,
-            __($label, 'wordpress'),
+            $label,
             array($this, $callback),
-            'job-setting-group',
-            STAFFORDS_EMP_SETTINGS,
+            'staffordsjobs_settings',
+            'staffordsjobs_setting_section',
             $name
         );
     }
@@ -169,6 +232,11 @@ class staffords_employment_admin
         echo __('Employment Form Email Notification', 'wordpress');
     }
 
+    public function staffords_settings_two_section_callback()
+    {
+        echo __('Employment Form Thank You', 'wordpress');
+    }
+
     public function staffords_option_page_capability()
     {
         return STAFFORDS_EMP_NEW_CAPABILITY;
index 4698bbc..68cbea8 100644 (file)
@@ -111,16 +111,63 @@ class staffords_employment_front
         return $form;
     }
 
+    public function get_job_application_properties()
+    {
+        if (!$this->appId) {
+            return false;
+        }
+
+        $sql = "
+        SELECT *
+          FROM " . $this->wpdb->prefix . STAFFORDS_EMP_FORM_TABLE . "
+         WHERE application = $this->appId
+           AND form_part = 1";
+        $form = $this->wpdb->get_row($sql, ARRAY_A);
+        $formsData = unserialize($form['form_data']);
+        //echo '<pre>data from form part table:  ' . print_r($formsData, true) . '</pre>';
+        $options = array();
+        foreach ( $formsData as $row ) {
+            foreach ( $row as $elem ) {
+                if ( $elem['name'] == 'location_preference' ) {
+                    foreach ( $elem['opts'] as $opt ) {
+                        if ( $opt['checked'] ) {
+                            $options[] = str_replace( 'location_preference_', '', $opt['name'] );
+                        }
+                    }
+                }
+            }
+        }
+        return $options;
+    }
+
     public function email_owner()
     {
-        $to      = 'steve@localhost';
-        $name    = 'Person Test';
-        $email   = 'user@gaslightmedia.com';
-        $message .= "A new employment application has been submitted. To review this "
-            . "application, log into your "
-            . "Web site administration area.\n\n";
-        $message .= admin_url() . "edit.php?post_type@staffords_jobs&page=applications\n\n";
-        $headers = "From: Online Employment Application Form <server@gaslightmedia.com>\r\nReply-To: {$name} <{$email}>";
+        $properies_applied_for = $this->get_job_application_properties();
+        $plugin_options = get_option(STAFFORDS_EMP_SETTING_NAME);
+        if ($jobId = filter_var($_REQUEST['job'], FILTER_VALIDATE_INT)) {
+            $jobData  = get_post($jobId);
+            $this->jobTitle = $jobTitle = $jobData->post_title;
+        }
+        // get the notification emails for this plugin
+        $fromName  = $plugin_options['from_name'];
+        $from      = $plugin_options['from_email'];
+        $to        = $plugin_options['notification_email'];
+        $name      = $plugin_name['replyto_name'];
+        $email     = $plugin_name['replyto_email'];
+        $message   = $plugin_options['notification_message'];
+        $message  .= admin_url() . "edit.php?post_type=staffords_jobs&page=applications\n\n";
+        $headers   = array();
+        $headers[] = "From: {$fromName} <{$from}>";
+        $headers[] = "Reply-To: {$name} <{$email}>";
+        foreach ( $properies_applied_for as $cc_email ) {
+             $headers[] = "Cc: " . $plugin_options[$cc_email . '_notification_name'] . " <" . $plugin_options[$cc_email . '_notification_email']. ">";
+        }
+        // get the property for this application
+
+        $depTax = wp_get_post_terms( $job->ID, STAFFORDS_EMP_TAX_DEPARTMENTS, 'name' );
+        foreach ($depTax as $depTerm) {
+            $deps[] = $depTerm->name;
+        }
         wp_mail(
             $to,
             'New Online Application Submission',
index 66d5d1c..93e994f 100644 (file)
@@ -14,6 +14,7 @@ defined('ABSPATH') or die();
  */
 define('STAFFORDS_EMP_PLUGIN_PATH_FILE', __FILE__);
 define('STAFFORDS_EMP_VERSION', '0.2.1');
+define('STAFFORDS_EMP_SETTING_NAME', 'staffordsjobs_settings');
 define('STAFFORDS_EMP_SETTINGS', 'staffordsjobs_settings');
 define('STAFFORDS_EMP_NEW_CAPABILITY', 'staffordsjobs_edit_jobs');
 define('STAFFORDS_EMP_BUILT_IN_CAPABILITY', 'edit_posts');
index 1ad3c8e..0c8005e 100644 (file)
@@ -1,9 +1,14 @@
+<style>
+table.form-table th {width: 250px; text-align: right;}
+table.form-table td input[type=text] {width: 400px;}
+table.form-table td textarea {width: 500px; height: 200px;}
+</style>
 <div class="wrap">
     <form action="options.php" method="post">
         <h2>Employment Plugin Settings</h2>
         <?php
-            settings_fields('job-setting-group');
-            do_settings_sections('job-setting-group');
+            settings_fields(STAFFORDS_EMP_SETTINGS);
+            do_settings_sections(STAFFORDS_EMP_SETTINGS);
             submit_button();
         ?>
     </form>