$this->wpdb = $wpdb;
$jobs = new glm_employment_job($path);
add_action('admin_menu', array($this, 'add_job_menus'));
+ add_action('admin_init', array($this, 'job_settings_init') );
}
/**
'applications',
array($this, 'get_applications')
);
-// add_submenu_page(
-// 'edit.php?post_type=' . GLM_EMP_POST_TYPE,
-// 'settings',
-// 'Settings',
-// 'manage_options',
-// 'job_settings',
-// array($this, 'show_job_settings')
-// );
+ add_submenu_page(
+ 'edit.php?post_type=' . GLM_EMP_POST_TYPE,
+ 'settings',
+ 'Settings',
+ GLM_EMP_NEW_CAPABILITY,
+ GLM_EMP_SETTINGS,
+ array($this, 'show_job_settings')
+ );
+ }
+
+ static public function activate_plugin()
+ {
+ staffords_employment_admin::add_capability();
+ }
+
+ static public function deactivate_plugin()
+ {
+ staffords_employment_admin::remove_capability();
+ }
+
+ static public function add_capability()
+ {
+ $roles = get_editable_roles();
+ foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+ if (isset($roles[$key]) && $role->has_cap(GLM_EMP_BUILT_IN_CAPABILITY)) {
+ $role->add_cap(GLM_EMP_NEW_CAPABILITY);
+ }
+ }
+ }
+
+ static public function remove_capability()
+ {
+ $roles = get_editable_roles();
+ foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+ if (isset($roles[$key]) && $role->has_cap(GLM_EMP_NEW_CAPABILITY)) {
+ $role->remove_cap(GLM_EMP_NEW_CAPABILITY);
+ }
+ }
+ }
+
+ public function staffords_settings_exist()
+ {
+ if (false == get_option(GLM_EMP_SETTINGS)) {
+ add_option(GLM_EMP_SETTINGS);
+ }
+ }
+
+ public function job_settings_init()
+ {
+ 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, 'render_textarea_field'),
+ 'staffordsjobs_settings',
+ 'staffordsjobs_setting_section_two',
+ 'thank_you_text'
+ );
+ add_settings_section(
+ 'staffordsjobs_setting_section',
+ 'Edit Notifications',
+ array($this, 'staffords_settings_section_callback'),
+ 'staffordsjobs_settings'
+ );
+ $fieldNames = array(
+ array(
+ 'name' => 'notification_name',
+ 'label' => 'Online Form Notify: Name',
+ 'type' => 'text'
+ ),
+ array(
+ 'name' => 'notification_email',
+ 'label' => 'Online Form 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'
+ ),
+ );
+
+ foreach ($fieldNames as $field) {
+ $this->staffords_add_setting_text_field(
+ $field['name'],
+ $field['label'],
+ $field['type']
+ );
+ }
+ register_setting(GLM_EMP_SETTINGS, GLM_EMP_SETTING_NAME, array($this, 'sanitize_options'));
+ }
+
+ public function sanitize_options($input)
+ {
+ if ( !$valid_notification_email = $this->validate_email_string($input['notification_email']) ) {
+ add_settings_error(
+ GLM_EMP_SETTINGS,
+ 'setting-error-notify-email',
+ 'invalid email for Online Form Notify: Email',
+ 'error'
+ );
+ }
+ if ( !$valid_reply_email = $this->validate_email_string($input['replyto_email']) ) {
+ add_settings_error(
+ GLM_EMP_SETTINGS,
+ 'setting-error-notify-email',
+ 'invalid email for Reply-To: Email',
+ 'error'
+ );
+ }
+ $terms = get_terms(
+ GLM_EMP_TAX_DEPARTMENTS,
+ array(
+ 'hide_empty' => false
+ )
+ );
+ foreach ( $terms as $term ) {
+ if ( !$valid_email = $this->validate_email_string( $input[$term->slug . '_notification_email'] ) ) {
+ add_settings_error(
+ GLM_EMP_SETTINGS,
+ 'setting-error-notify-email',
+ 'invalid email for ' . $term->name . ': Email',
+ 'error'
+ );
+ }
+ }
+ return $input;
+ }
+
+ public function validate_email_string($string)
+ {
+ if ( isset( $string ) && strpos( $string, ',' ) ) {
+ $emails = explode( ',', $string );
+ foreach ( $emails as $email ) {
+ $validEmail = filter_var(trim($email), FILTER_VALIDATE_EMAIL);
+ if ( !$validEmail ) {
+ return false;
+ }
+ }
+ } else if ( isset( $string ) && $string ) {
+ $validEmail = filter_var($string, FILTER_VALIDATE_EMAIL);
+ if ( !$validEmail ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public function staffords_add_setting_text_field($name, $label, $type)
+ {
+ switch ($type) {
+ case 'text':
+ $callback = 'render_text_field';
+ break;
+ case 'textarea':
+ $callback = 'render_textarea_field';
+ break;
+ case 'state':
+ $callback = 'glmclientinfoRenderStateSelect';
+ break;
+ default:
+ return false;
+ break;
+ }
+ add_settings_field(
+ $name,
+ $label,
+ array($this, $callback),
+ 'staffordsjobs_settings',
+ 'staffordsjobs_setting_section',
+ $name
+ );
+ }
+
+ public function render_text_field($fieldName)
+ {
+ static $options;
+ if (!$options) {
+ $options = get_option(GLM_EMP_SETTINGS);
+ }
+ include $this->pluginDirName . 'views/text.php';
+ }
+
+ public function render_textarea_field($fieldName)
+ {
+ static $options;
+ $options = get_option(GLM_EMP_SETTINGS);
+ include $this->pluginDirName . 'views/textArea.php';
+ }
+
+ public function staffords_settings_section_callback()
+ {
+ 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 GLM_EMP_NEW_CAPABILITY;
}
/**
*/
public function show_job_settings()
{
- echo '<p>Job Settings</p>';
+ if (current_user_can(GLM_EMP_NEW_CAPABILITY)) {
+ include $this->pluginDirName . 'views/optionsPage.php';
+ } else {
+ include $this->pluginDirName . 'views/deniedAccess.php';
+ }
}
/**
'1.0',
true
);
- wp_enqueue_style('foundation',
- get_template_directory_uri() . '/css/app.js');
+ wp_enqueue_style('foundation', get_template_directory_uri() . '/css/app.js');
$id = filter_var($_REQUEST['application'], FILTER_VALIDATE_INT);
$sql = "
SELECT *
return $form;
}
+ public function email_owner()
+ {
+ $properies_applied_for = $this->get_job_application_properties();
+ $plugin_options = get_option(GLM_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_options['replyto_name'];
+ $email = $plugin_options['replyto_email'];
+ $message = $plugin_options['notification_message'] . "\n";
+ $message .= '<a href="' . admin_url() . 'edit.php?post_type=staffords_jobs&page=applications">' . get_bloginfo('name') . ' Admin Area</a>.' . "\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, GLM_EMP_TAX_DEPARTMENTS, 'name' );
+ foreach ($depTax as $depTerm) {
+ $deps[] = $depTerm->name;
+ }
+ add_filter( 'wp_mail_content_type', array( $this, 'set_html_content_type' ) );
+ $html_head = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>Online Application Form</title>
+</head>
+<body>
+ <!-- {{{ body -->
+ <p>
+ <font size="4" face="arial, sans-serif">
+ <b>New Online Application Submission</b>
+ </font>
+ </p>
+ <table cellspacing="0" cellpadding="0" bgcolor="#c0c0c0" border="0">
+ <tr>
+ <td>
+ <table cellspacing="1" cellpadding="5" border="0" bgcolor="#c0c0c0" width="400">
+ <tr flexy:if="v[element]" bgcolor="#c0c0c0">
+ <td bgcolor="#ffffff">
+ ';
+ $html_foot = '
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table cellspacing="0" cellpadding="10" border="0" width="400">
+ <tr>
+ <td bgcolor="#eeeeee">
+ <font size="1" face="arial, sans-serif">
+ To ensure the delivery of these e-mails to your inbox, please add ' . $from . ' to your e-mail Address Book or Safe List.
+ </font>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+
+ </table>
+ <!-- }}} -->
+</body>
+</html>';
+
+ wp_mail(
+ $to,
+ 'New Online Application Submission',
+ $html_head . nl2br( $message ) . $html_foot,
+ $headers
+ );
+
+ remove_filter( 'wp_mail_content_type', array( $this, 'set_html_content_type' ) );
+ }
+
+ public function set_html_content_type()
+ {
+ return 'text/html';
+ }
+
/**
* Show the application form
*/
// next form part
++$formPart;
if ($formPart == self::FINAL_FORM) {
+ $plugin_options = get_option(GLM_EMP_SETTING_NAME);
include $this->frontViewDir . '/' . self::SUCCESS_TEMPLATE;
unset($_SESSION['glmJobsApplication'], $_SESSION['glmJobsAppForm']);
+ $this->email_owner();
} else {
$form = $this->load_form_settings($formPart);
include $this->frontViewDir . '/' . self::FORM_TEMPLATE;