*/ class Admission_App_Manager_Admin { /** * @since 1.0.0 * @access private * @var string $admission_app_manager The ID of this plugin. */ private $admission_app_manager; /** * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * * @param string $admission_app_manager The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $admission_app_manager, $version ) { $this->admission_app_manager = $admission_app_manager; $this->version = $version; $this->load_dependencies(); } public function load_dependencies() { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/helpers/admission-app-manager-application.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-admission-app-manager-app-dashboard.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-admission-app-manager-importer.php'; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->admission_app_manager, plugin_dir_url( __FILE__ ) . 'css/admission-app-manager-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { wp_enqueue_script( $this->admission_app_manager, plugin_dir_url( __FILE__ ) . 'js/admission-app-manager-admin.js', array( 'jquery' ), $this->version, false ); } /** * Menu settings */ public function aam_add_main_menu_item() { add_menu_page( __( 'Admission AppManager', 'admission-app-manager' ), __( 'Admission AppManager', 'admission-app-manager' ), 'edit_aam_applications', 'aam', 'init_dashboard', 'dashicons-welcome-learn-more' ); add_submenu_page( 'aam', __( 'Dashboard', 'admission-app-manager' ), __( 'Dashboard', 'admission-app-manager' ), 'edit_aam_applications', 'aam', 'init_dashboard' ); add_submenu_page( 'aam', 'Settings', 'Settings', 'manage_options', 'aam_settings', 'aam_settings' ); add_submenu_page( 'aam', 'Import', 'Import', 'edit_aam_applications', 'aam_import', 'aam_init_importer' ); } /** * Add custom fields to user profile * * @param $user */ public function aam_consultant_custom_fields( $user ) { if ( $user->roles[0] === 'consultant' ) { ?>

Consultant data

ID ); ?>
/> Monday
  /> Tuesday
  /> Wednesday
  /> Thursday
  /> Friday
  /> Saturday
  /> Sunday

Placeholders: %name% - uploader name, %file% - file name

Placeholders: %name% - uploader name, %other% - other party name, %file% - file name, %link% - file link

_aam_bo_days_form( $user, 'consultant' ); } } /** * Save user settings on profile save * * @param $user_id */ public function aam_save_consultant_custom_fields( $user_id ) { if ( isset( $_POST['aam_from'] ) ) { update_user_meta( $user_id, 'aam_from', sanitize_text_field( $_POST['aam_from'] ) ); } if ( isset( $_POST['aam_bcc'] ) ) { update_user_meta( $user_id, 'aam_bcc', sanitize_text_field( $_POST['aam_bcc'] ) ); } if ( isset( $_POST['aam_off_days'] ) ) { update_user_meta( $user_id, 'aam_off_days', $_POST['aam_off_days'] ); } else { delete_user_meta( $user_id, 'aam_off_days' ); } if ( isset( $_POST['aam_uploader_email_template'] ) ) { update_user_meta( $user_id, 'aam_uploader_email_template', $_POST['aam_uploader_email_template'] ); } if ( isset( $_POST['aam_other_email_template'] ) ) { update_user_meta( $user_id, 'aam_other_email_template', $_POST['aam_other_email_template'] ); } if ( isset( $_POST['aam_application_email_before'] ) ) { update_user_meta( $user_id, 'aam_application_email_before', $_POST['aam_application_email_before'] ); } if ( isset( $_POST['aam_application_email_after'] ) ) { update_user_meta( $user_id, 'aam_application_email_after', $_POST['aam_application_email_after'] ); } } /** * Add consultant assignment option to client profile * * @param $user */ public function aam_client_custom_fields( $user ) { if ( $user->roles[0] == 'client' ) { $assigned = get_the_author_meta( 'aam_assigned_consultant', $user->ID ); $consultants = get_users( array( 'role' => 'Consultant' ) ); ?>

Client data

_aam_bo_days_form( $user, 'client' ); } private function _aam_bo_days_form( $user, $usertype = 'client' ) { if ( $user->roles[0] == $usertype ) { $bo_days = get_the_author_meta( 'aam_bo_days', $user->ID ); if ( ! $bo_days || ! is_array( $bo_days ) ) { $bo_days = array( array( 'from' => '', 'to' => '' ) ); } ?>

Blackout days

$range ) : ?>
X  +
roles[0] == 'school' ) { $assigned = get_the_author_meta( 'aam_assigned_school', $user->ID ); $schools = get_posts( array( 'post_type' => 'school', 'posts_per_page' => - 1 ) ); ?>

School options

0 ? $application[0]['application_id'] : false; $documents = array(); if ( $application_id ) { $combination_data = get_post_meta( $application_id, '_aam_application_combination', true ); if ( isset( $combination_data['combination'] ) ) { $combination_documents = get_post_meta( $combination_data['combination'], '_aam_combination_documents', true ); if ( $combination_documents && count( $combination_documents ) > 0 ) { foreach ( $combination_documents as $document ) { $send_check = get_post_meta( $document['type'], '_aam_type_send', true ); if ( $send_check && $send_check === 'on' ) { if ( ! isset( $documents[ $document['type'] ] ) ) { $documents[ $document['type'] ] = array(); } $documents[ $document['type'] ][] = array( 'prompt' => $document['prompt'], 'required' => $document['required'] ); } } } } } //send emails $client_id = get_post_meta( $application_id, '_aam_application_client', true ); $client = get_userdata( $client_id ); $client_email = $client->user_email; $current_user = wp_get_current_user(); $from = get_user_meta( $current_user->ID, 'aam_from', true ); $bcc = get_user_meta( $current_user->ID, 'aam_bcc', true ); $before_text = get_user_meta( $current_user->ID, 'aam_application_email_before', true ); $after_text = get_user_meta( $current_user->ID, 'aam_application_email_after', true ); $headers = array(); $headers[] = 'Content-Type: text/html; charset=UTF-8'; $headers[] = 'From: ' . $current_user->display_name . ' <' . ( $from ? $from : $current_user->user_email ) . '>'; if ( $bcc ) { $headers[] = 'Bcc: ' . $bcc; } foreach ( $documents as $document_id => $prompts ) { $document_data = get_post( $document_id ); $body = nl2br( $before_text ); $body .= ''; $body .= nl2br( $after_text ); wp_mail( $client_email, 'Prompts for ' . $document_data->post_title, $body, $headers ); } } /** * Send all application deadlines to client on application save * * @param $application */ public function aam_send_deadlines_to_client( $application ) { $application_id = count( $application ) > 0 ? $application[0]['application_id'] : false; $sorted = array(); if ( $application ) { $current = null; foreach ( $application as $step ) { if ( ! isset( $sorted[ $step['document_id'] ] ) ) { $document_data = get_post( $step['document_type'] ); $sorted[ $step['document_id'] ] = array( 'id' => $step['id'], 'document' => $document_data->post_title, 'prompt' => $step['prompt'], 'type' => $step['document_type'], 'weight' => $step['document_weight'], 'required' => $step['required'], 'active' => $step['active'], 'items' => array() ); } $sorted[ $step['document_id'] ]['items'][] = $step; } } //send emails $client_id = get_post_meta( $application_id, '_aam_application_client', true ); $client = get_userdata( $client_id ); $client_email = $client->user_email; $current_user = wp_get_current_user(); $before_text = get_user_meta( $current_user->ID, 'aam_application_email_before', true ); $after_text = get_user_meta( $current_user->ID, 'aam_application_email_after', true ); $from = get_user_meta( $current_user->ID, 'aam_from', true ); $bcc = get_user_meta( $current_user->ID, 'aam_bcc', true ); $i = 1; $body = nl2br( $before_text ); foreach ( $sorted as $sk => $step ) : $body .= '' . $step['document'] . ' - ' . $step['prompt'] . ''; $body .= ''; $i ++; endforeach; $body .= nl2br( $after_text ); $headers = array(); $headers[] = 'Content-Type: text/html; charset=UTF-8'; $headers[] = 'From: ' . $current_user->display_name . ' <' . ( $from ? $from : $current_user->user_email ) . '>'; if ( $bcc ) { $headers[] = 'Bcc: ' . $bcc; } wp_mail( $client_email, 'Application deadlines', $body, $headers ); } /** * Redirect user after successful login. * * @param string $redirect_to URL to redirect to. * @param string $request URL the user is coming from. * @param object $user Logged user's data. * * @return string */ public function aam_login_redirect( $redirect_to, $request, $user ) { //is there a user to check? if ( isset( $user->roles ) && is_array( $user->roles ) ) { if ( in_array( 'client', $user->roles ) ) { // if user is client first get applications page id $settings = get_option( 'aam_settings', array() ); if ( isset( $settings['applications_page'] ) ) { return get_permalink( $settings['applications_page'] ); } return $redirect_to; } else if ( in_array( 'consultant', $user->roles ) ) { return admin_url( 'edit.php?post_type=application' ); } else { return $redirect_to; } } else { return $redirect_to; } } /** * Remove all dashboard widgets */ public function remove_dashboard_meta() { remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' );//since 3.8 } /** * Force single column widget on admin dashboard * * @param $columns * * @return mixed */ public function aam_screen_layout_columns( $columns ) { $columns['dashboard'] = 1; return $columns; } /** * Force single column widget on admin dashboard * @return int */ public function aam_screen_layout_dashboard() { return 1; } /** * Add a widget to the dashboard. * * This function is hooked into the 'wp_dashboard_setup' action below. */ public function aam_add_dashboard_widgets() { wp_add_dashboard_widget( 'aam_dashboard_widget', // Widget slug. 'Admission AppManager', // Title. array( &$this, 'aam_dashboard_widget_function' ) // Display function. ); } /** * Create the function to output the contents of our Dashboard Widget. */ public function aam_dashboard_widget_function() { global $wpdb; $is_admin = current_user_can( 'manage_options' ); $is_consultant = current_user_can( 'manage_clients' ); $modifier = ""; if ( $is_consultant && ! $is_admin ) { $consultant_id = get_current_user_id(); $modifier .= " and um.meta_value = $consultant_id "; } $q = ''; if ( isset( $_POST['q'] ) && isset( $_POST['action'] ) && $_POST['action'] == 'aam-widget-search' ) { $q = $_POST['q']; $modifier .= " and (p.post_title like '%%%s%%' or us1.user_login like '%%%s%%' or us2.user_login like '%%%s%%') "; } $query = "select p.ID, p.post_title, pm1.meta_value as completed, us1.ID as client_id, us1.user_login as client_login, us2.ID as consultant_id, us2.user_login as consultant_login from wp_posts as p left join wp_postmeta as pm1 on p.ID = pm1.post_id and pm1.meta_key = '_aam_total_completion' left join wp_postmeta as pm2 on pm2.post_id = p.ID and pm2.meta_key = '_aam_application_client' left join wp_users as us1 on us1.ID = pm2.meta_value left join wp_usermeta as um on um.user_id = us1.ID and um.meta_key = 'aam_assigned_consultant' left join wp_users as us2 on us2.ID = um.meta_value where pm1.meta_value < 100 $modifier order by us2.user_login, us1.user_login;"; $data = $wpdb->get_results( $wpdb->prepare( $query, $q, $q, $q ) ); if ( $is_admin ) { $transformed = array(); foreach ( $data as $row ) { if ( ! isset( $transformed[ $row->consultant_id ] ) ) { $transformed[ $row->consultant_id ] = array( 'consultant_login' => $row->consultant_login, 'clients' => array() ); } if ( ! isset( $transformed[ $row->consultant_id ]['clients'][ $row->client_id ] ) ) { $transformed[ $row->consultant_id ]['clients'][ $row->client_id ] = array( 'client_login' => $row->client_login, 'applications' => array() ); } $transformed[ $row->consultant_id ]['clients'][ $row->client_id ]['applications'][] = $row; } ?> client_id ] ) ) { $transformed[ $row->client_id ] = array( 'client_login' => $row->client_login, 'applications' => array() ); } $transformed[ $row->client_id ]['applications'][] = $row; } ?>