diff --git a/plugins/cc-global-network/admin/assets/css/admin_styles.css b/plugins/cc-global-network/admin/assets/css/admin_styles.css index a118d60..a154f63 100644 --- a/plugins/cc-global-network/admin/assets/css/admin_styles.css +++ b/plugins/cc-global-network/admin/assets/css/admin_styles.css @@ -88,4 +88,135 @@ } .dataTable tbody tr.green-mark { background-color: #cff9cf; +} + +/*USER PROFILE*/ +.title-container { + display: flex; + align-items: center; +} +.title-container.with-borders { + padding: 1rem 0; + border-top: 1px solid #e4e4e4; + border-bottom: 1px solid #e4e4e4; +} +.big-name { + font-size: 2.2rem; + display: inline-block; +} +.badge { + display: inline-block; + padding: .7rem; + margin-left: 1rem; + font-size: .8rem; + color: white; +} +.inner-scroll { + border-top: 1px solid #e4e4e4; + border-bottom: 5px solid #e4e4e4; + overflow-y: auto; +} +.inner-scroll.medium { + height: 90px; +} +.log-entry { + padding: .5rem 0; + font-size: .7rem; + border-bottom: 1px solid #f0f0f0; +} +.log-entry .date { + font-style: italic; +} +.badge.individual { + background-color: #ca4a1f; +} +.badge.institutional { + background-color: #00b9eb; +} +table.ccgn-profile { + display: none; + border-top: 5px solid #e6e6e6; +} +table.ccgn-profile tr td { + padding: .8rem 1rem; + border-bottom: 1px solid #e6e6e6; +} +table.ccgn-profile tr td.title { + font-weight: bold; + text-transform: uppercase; + text-align: right; +} +.display-details { + text-decoration: none; + display: block; + padding: .5rem; + background-color: #e6e6e6; + color: #666; + transition: all .5s ease; +} +.display-details .dashicons { + transition: all .5s ease; +} +.display-details.opened .dashicons { + transform: rotate(-180deg); +} +.applicant-columns { + display: flex; + margin-top: 2rem; + flex-wrap: wrap; +} +.applicant-columns .ccgn-box { + padding: .5rem 1.5rem 1rem 1.5rem; + margin-right: 1rem; + background-color: white; + border-radius: .2rem; + box-shadow: 0 1px 4px rgba(0,0,0,.2); +} +.applicant-columns .ccgn-box.asked-box { + background-color: #fef6e1; +} +.applicant-columns .ccgn-box.applicant { + text-align: center; +} +.applicant-columns .ccgn-box .icon .dashicons { + font-size: 3rem; + width: 3rem; + height: 3rem; +} +.applicant-columns .ccgn-box .date { + color: #999; + font-style: italic; + font-size: .7rem; +} +.applicant-columns .ccgn-box .applicant-reason { + width: 15rem; +} +.preview-details { + margin-bottom: 2rem; +} +.preview-details td { + padding: .5rem; + width: 50%; + vertical-align: top; +} +.preview-details td h6 { + margin: 1rem 0; + font-size: 1.3rem; + font-weight: bold; +} +.button.tiny { + font-size: .7rem; + padding: 0 .5rem; +} +#input_changeVoucher_chosen { + width: 100% !important; +} +#TB_ajaxContent { + position: relative; + padding-bottom: 4rem !important; +} +#TB_ajaxContent .buttons { + position: absolute; + bottom: .5rem; + padding: .5rem; } \ No newline at end of file diff --git a/plugins/cc-global-network/admin/assets/js/script.js b/plugins/cc-global-network/admin/assets/js/script.js index d364ccd..4c05b4e 100644 --- a/plugins/cc-global-network/admin/assets/js/script.js +++ b/plugins/cc-global-network/admin/assets/js/script.js @@ -8,22 +8,22 @@ $.fn.dataTable.ext.search.push( date_start = $('#date-start').val(), date_end = $('#date-end').val(), column_date = data[7]; - if ((member_type != '') && ((settings.sTableId == 'ccgn-table-applications-approval') || (settings.sTableId == 'ccgn-list-new-individuals') ) ) { + if ((member_type != '') && ((settings.sTableId == 'ccgn-table-applications-approval') || (settings.sTableId == 'ccgn-list-new-individuals'))) { if (member_type == column_member_type) { return true; } else { return false; } - } else if (((date_start != '') || (date_end != '')) && (settings.sTableId == 'ccgn-list-new-individuals' )) { + } else if (((date_start != '') || (date_end != '')) && (settings.sTableId == 'ccgn-list-new-individuals')) { var target_date = new Date(column_date), - from_date = ( date_start != '' ) ? new Date(date_start) : new Date(wpApiSettings.site_epoch), - to_date = ( date_end != '' ) ? new Date(date_end) : Date.now(); - if ( (target_date >= from_date) && (target_date <= to_date ) ) { - return true; - } else { - return false; - } - } + from_date = (date_start != '') ? new Date(date_start) : new Date(wpApiSettings.site_epoch), + to_date = (date_end != '') ? new Date(date_end) : Date.now(); + if ((target_date >= from_date) && (target_date <= to_date)) { + return true; + } else { + return false; + } + } else { return true; } @@ -33,36 +33,35 @@ function format(d) { // `d` is the original data object for the row return '' + '' + - '' + - '' + + '' + + '' + - '' + - '' + + '' + + '' + '' + '' + - '' + - '' + - + '' + + '' + '' + '' + '' + '' + - '' + - '' + + '' + + '' + '' + '
Vouchers declined' + d.vouches_declined + 'Vouchers declined' + d.vouches_declined + 'Votes for' + d.votes_for + 'Votes for' + d.votes_for + '
Vouchers for' + d.vouches_for + 'Vouchers for' + d.vouches_for + 'Votes against' + d.votes_against + '
Vouchers against'+ d.vouches_against +'Vouchers against' + d.vouches_against + '
'; } -jQuery(document).ready(function($){ - $.resetVouchers = function(id) { +jQuery(document).ready(function ($) { + $.resetVouchers = function (id) { $('#reset-vouchers-for-sure').off('click'); tb_show("Reset Vouchers", "#TB_inline?width=600&height=250&inlineId=resetvouchers-modal"); - $('#close-reset-vouchers').on('click', function(e){ + $('#close-reset-vouchers').on('click', function (e) { e.preventDefault(); tb_remove(); return false; }); - $('#reset-vouchers-for-sure').on('click', function(e){ + $('#reset-vouchers-for-sure').on('click', function (e) { var sec = $('#reset_vouchers_nonce').val(), this_button = $(this); $.ajax({ @@ -85,7 +84,122 @@ jQuery(document).ready(function($){ $('#search-all-members').trigger('click'); } if (data == 'error') { - $('#alert-messages').append('

There was an error restoring the vouching state

').find('.notice').delay(3200).fadeOut(300); + $('#alert-messages').append('

There was an error restoring the vouching state

').find('.notice').delay(3200).fadeOut(300); + tb_remove(); + } + } + }); + }); + } + $.changeVoucher = function (applicantId, voucherName, currentVoucher,theOtherVoucher,position) { + $('#change-voucher-for-sure').off('click'); + $('#input_changeVoucher option[disabled="disabled"]').removeAttr('disabled'); + $('#change-voucher-modal').find('.name-display').html(voucherName); //Display the voucher name that will be changed + $('#change-voucher-modal').find('#input_changeVoucher').val(currentVoucher); + $('#input_changeVoucher option[value="'+theOtherVoucher+'"]').attr('disabled','disabled'); + $("#input_changeVoucher").trigger("chosen:updated"); + tb_show("Change current voucher", "#TB_inline?width=600&height=300&inlineId=change-voucher-modal"); + $('#close-change-voucher').on('click', function (e) { + e.preventDefault(); + tb_remove(); + return false; + }); + $('#change-voucher-for-sure').on('click', function (e) { + var sec = $('#change_voucher_nonce').val(), + this_button = $(this), + new_voucher = $("#input_changeVoucher").val(); + $.ajax({ + url: wpApiSettings.ajax_url, + type: 'POST', + data: { + action: 'change_voucher', + voucher_id: currentVoucher, + applicant_id: applicantId, + position: position, + new_voucher: new_voucher, + sec: sec + }, + beforeSend: function () { + this_button.text('Working...'); + }, + success: function (data) { + this_button.text("Yes, I'm sure"); + $('#alert-messages').html(''); + if (data == 'ok') { + tb_remove(); + //$('#alert-messages').append('

The request was sended to the user

').find('.notice').delay(3200).fadeOut(300); + console.log('ok'); + location.reload(); + + } + if (data == 'error') { + console.log('error'); + $('#alert-messages').append('

There was an error sending your request

').find('.notice').delay(3200).fadeOut(300); + tb_remove(); + } + } + }); + }); + } + $.askVoucher = function (id, name, applicant_id) { + $('#ask-voucher-for-sure').off('click'); + $('#ask-clarification-modal').find('.name-display').html(name); + tb_show("Ask for clarification to voucher", "#TB_inline?width=600&height=350&inlineId=ask-clarification-modal"); + $('#log-content-ask-voucher').hide(); + var logList = $('#log-entry-ask-voucher'); + logList.html(''); + $.ajax({ + url: wpApiSettings.ajax_url, + type: 'POST', + data: { + action: 'ask_voucher_log', + applicant_id: applicant_id, + voucher_id: id + }, + success: function (data) { + converted_data = JSON.parse(data); + console.log(logList); + if (converted_data.length > 0) { + converted_data.forEach(function(element){ + console.log(element); + logList.append('
  • ' + element.ask_user_name + ' on ' + element.date + '
  • '); + }); + $('#log-content-ask-voucher').show(); + } else { + $('#log-content-ask-voucher').hide(); + } + } + }); + $('#close-ask-voucher').on('click', function (e) { + e.preventDefault(); + tb_remove(); + return false; + }); + $('#ask-voucher-for-sure').on('click', function (e) { + var sec = $('#ask_voucher_nonce').val(), + this_button = $(this); + $.ajax({ + url: wpApiSettings.ajax_url, + type: 'POST', + data: { + action: 'ask_voucher', + user_id: id, + applicant_id: applicant_id, + sec: sec + }, + beforeSend: function () { + this_button.text('Working...'); + }, + success: function (data) { + this_button.text("Yes, I'm sure"); + $('#alert-messages').html(''); + if (data == 'ok') { + tb_remove(); + $('#alert-messages').append('

    The request was sended to the user

    ').find('.notice').delay(3200).fadeOut(300); + $('#search-all-members').trigger('click'); + } + if (data == 'error') { + $('#alert-messages').append('

    There was an error sending your request

    ').find('.notice').delay(3200).fadeOut(300); tb_remove(); } } @@ -93,12 +207,12 @@ jQuery(document).ready(function($){ }); } var table1 = $('#ccgn-table-applications-approval').DataTable({ - 'columns': [ + 'columns': [ { - "className": 'details-control', - "orderable": false, - "data": null, - "defaultContent": '' + "className": 'details-control', + "orderable": false, + "data": null, + "defaultContent": '' }, { 'data': 'applicant' }, { 'data': 'applicant_type' }, @@ -106,29 +220,29 @@ jQuery(document).ready(function($){ { 'data': 'vouching_status' }, { 'data': 'voting_status' }, { 'data': 'application_date' } - ], - 'columnDefs': [ - { - targets: 1, - 'render': function (data, type, row, meta) { - return '' + data+''; - } - } - ], - 'ajax': { - 'url': wpApiSettings.root + 'commoners/v2/application-approval/list', - 'type': 'POST', - 'beforeSend': function (xhr) { - xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce); - }, - 'data': { 'current_user': wpApiSettings.current_user } - }, - rowCallback: function(row, data) { - if (data.already_voted_by_me == 'yes') { - $(row).addClass('green-mark'); - } - } - }); + ], + 'columnDefs': [ + { + targets: 1, + 'render': function (data, type, row, meta) { + return '' + data + ''; + } + } + ], + 'ajax': { + 'url': wpApiSettings.root + 'commoners/v2/application-approval/list', + 'type': 'POST', + 'beforeSend': function (xhr) { + xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce); + }, + 'data': { 'current_user': wpApiSettings.current_user } + }, + rowCallback: function (row, data) { + if (data.already_voted_by_me == 'yes') { + $(row).addClass('green-mark'); + } + } + }); var table_members = $('#ccgn-list-new-individuals').DataTable({ 'columns': [ { 'data': 'display_name' }, @@ -154,7 +268,7 @@ jQuery(document).ready(function($){ 'beforeSend': function (xhr) { xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce); }, - 'data': { + 'data': { 'current_user': wpApiSettings.current_user, 'start_date': wpApiSettings.site_epoch, 'end_date': wpApiSettings.date_now @@ -221,12 +335,12 @@ jQuery(document).ready(function($){ }, { 'targets': 7, - 'render' : function(data, type, row, meta) { + 'render': function (data, type, row, meta) { var output = ''; if (wpApiSettings.is_sub_admin != 'yes') { output += ''; - output += ''; - output += ''; + output += ''; + output += ''; output += ''; } else { output += 'No actions'; @@ -234,9 +348,9 @@ jQuery(document).ready(function($){ return output; } } - ] + ] }); - $('#search-all-members').on('click', function(e){ + $('#search-all-members').on('click', function (e) { e.preventDefault; var obj = $(this); $.ajax({ @@ -246,11 +360,11 @@ jQuery(document).ready(function($){ obj.text('Loading...'); xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce); }, - 'data': { + 'data': { 'current_user': wpApiSettings.current_user, 'search_user': $('#user_id').val() }, - success: function(data) { + success: function (data) { table_search_users.clear(); table_search_users.rows.add(data); table_search_users.draw(); @@ -274,14 +388,14 @@ jQuery(document).ready(function($){ tr.addClass('shown'); } }); - $('#member_type').on('change',function () { + $('#member_type').on('change', function () { table1.draw(); table_members.draw(); }); $('.ui-datepicker-input').on('change', function () { table_members.draw(); }); - $('.email-list').on('click', function(e){ + $('.email-list').on('click', function (e) { $('#emails-modal').find('p').html( table_members .columns(1, { search: 'applied' }) @@ -295,5 +409,45 @@ jQuery(document).ready(function($){ $('.ui-datepicker-input').datepicker({ dateFormat: 'yy-mm-dd' }); - + $('.display-details').on('click', function (e) { + e.preventDefault(); + var obj = $(this), + target = obj.data('target'); + obj.toggleClass('opened'); + $(target).slideToggle('fast'); + return false; + }); + $('#input_changeVoucher').chosen({}); + + $('#set-new-vouch-reason').on('click', function(e) { + e.preventDefault(); + var obj = $(this), + new_reason = $('#clarification_voucher').val(), + entry_id = obj.data('entry-id'), + sec = $('#clarification_voucher_nonce').val(); + $.ajax({ + url: wpApiSettings.ajax_url, + type: 'POST', + data: { + action: 'reason_voucher', + entry_id: entry_id, + new_reason: new_reason, + sec: sec + }, + beforeSend: function () { + obj.text('Working...'); + }, + success: function (data) { + obj.text("Set new reason"); + $('#change-voucher-messages').html(''); + if (data == 'ok') { + location.reload(); + } + if (data == 'error') { + $('#change-voucher-messages').append('

    There was an error sending your request

    ').find('.notice').delay(3200).fadeOut(300); + } + } + }); + return false; + }); }); \ No newline at end of file diff --git a/plugins/cc-global-network/admin/options-emails.php b/plugins/cc-global-network/admin/options-emails.php index 5f7d469..48cd9fc 100644 --- a/plugins/cc-global-network/admin/options-emails.php +++ b/plugins/cc-global-network/admin/options-emails.php @@ -311,6 +311,27 @@ function ccgn_settings_emails_chapter_contact_wrapper () { > + + + + From: ' - . $voter->display_name - . '

    Voted: ' + $result .= '

    '; + $result .= '

    '. $voter->display_name . '

    ' + .'

    Voted:' . $vote[ CCGN_GF_VOTE_APPROVE_MEMBERSHIP_APPLICATION ] . '

    '; + $result .= '
    '; } return $result; } @@ -418,11 +418,10 @@ function ccgn_application_format_legal_approval ( $applicant_id, $state ) { function ccgn_application_user_page_render_change_vouchers ( $applicant_id, $state ) { if ( current_user_can( 'ccgn_pre_approve' ) ) { - echo _('

    Change Vouch Requests

    '); if ( $state == CCGN_APPLICATION_STATE_VOUCHING ) { echo '

    '; + . '" class="button">'; echo _('Change vouch requests for applicant.'); echo '

    '; } else { @@ -463,37 +462,179 @@ function ccgn_application_users_page_render_state ( $applicant_id, $state ) { function ccgn_application_users_page_render_details ( $applicant_id, $state ) { echo _('

    Membership Application Details

    '); + echo '
    '; echo _('

    Details Provided By Applicant

    '); echo ccgn_user_page_applicant_profile_text( $applicant_id ); - echo _('

    Vouchers Requested

    '); - $voucher_choices = ccgn_application_vouchers ( $applicant_id ); - echo '

    Original request date: ' - . $voucher_choices['date_created'] - . '

    '; - if (! is_null ( $voucher_choices[ 'date_updated' ] ) ) { - echo '

    Updated request date: ' - . $voucher_choices['date_updated'] - . '

    '; - } - echo ccgn_application_users_page_vouchers( $applicant_id ); + echo '

    Vouchers information

    '; + echo '
    '; + echo '
    '; + echo _('

    Vouchers Requested

    '); + $voucher_choices = ccgn_application_vouchers ( $applicant_id ); + + echo '

    Original request date: ' + . date('Y-m-d', strtotime($voucher_choices['date_created'])) + . '

    '; + if (! is_null ( $voucher_choices[ 'date_updated' ] ) ) { + echo '

    Updated request date: ' + . date('Y-m-d', strtotime($voucher_choices['date_updated'])) + . '

    '; + } + echo ccgn_application_users_page_vouchers( $applicant_id ); + echo '
    '; + if ( $state != CCGN_APPLICATION_STATE_RECEIVED ) { - ccgn_application_user_page_render_change_vouchers ( - $applicant_id, - $state - ); - echo _('

    Vouches Received

    '); - echo ccgn_application_users_page_vouch_counts ( $applicant_id ); - echo _('

    Vouches

    '); - echo ccgn_application_users_page_vouch_responses ( + echo '
    '; + echo _('

    Vouches Received

    '); + echo ccgn_application_users_page_vouch_counts ( $applicant_id ); + ccgn_application_user_page_render_change_vouchers( + $applicant_id, + $state + ); + echo '
    '; + + $clarification_mode = get_user_meta(get_current_user_id(), 'ccgn_need_to_clarify_vouch_reason', true); + if ( isset($_GET['clarification']) && $clarification_mode ) { + echo '
    '; + echo '
    '; + echo '
    '; + echo ''; + echo '

    Clarification of your voucher

    '; + echo '
    '; + $form_id = RGFormsModel::get_form_id(CCGN_GF_VOUCH); + + $search_criteria = array(); + $search_criteria['field_filters'][] + = array( + 'key' => 'created_by', + 'value' => get_current_user_id(), + ); + $search_criteria['field_filters'][] + = array( + 'key' => CCGN_GF_VOUCH_APPLICANT_ID_FIELD, + 'value' => $applicant_id, + ); + $get_the_entries = GFAPI::get_entries( + $form_id, + $search_criteria, + array( + array( + 'key' => 'date_created', + 'direction' => 'ASC', + 'is_numeric' => false + ) + ) + ); + //echo '
    '; print_r($get_the_entries); echo '
    '; + $entry_id = $get_the_entries[0]['id']; + + echo wp_nonce_field('clarification_voucher', 'clarification_voucher_nonce', true, false); + echo '

    '; + echo ''; + echo '
    '; + } + echo '

    '; + echo _('

    Vouchers list

    '); + echo '
    '; + $vouchers = ccgn_application_users_page_vouch_responses_data( $applicant_id, true ); + foreach ($vouchers as $voucher) { + $asked = get_user_meta($voucher['id'], 'ccgn_need_to_clarify_vouch_reason', true); + $asked_class = ($asked) ? ' asked-box' : ''; + echo '
    '; + //echo '
    '; + echo '

    '.$voucher['name'].'

    '; + echo ''.$voucher['date'].''; + if ($asked) { + echo '
    Asked for clarification'; + } + echo '

    ' . $voucher['reason'] . '

    '; + echo '

    Vouched: '.$voucher['vouched'].'

    '; + if (($voucher['vouched'] == 'Yes') && (ccgn_current_user_is_final_approver($applicant_id) || ccgn_current_user_is_membership_council($applicant_id)) ) { + echo 'Ask for clarification'; + } + echo '
    '; + } + echo '
    '; + // echo cgn_application_users_page_vouch_responses ( + // $applicant_id, + // true + // ); + add_thickbox(); + echo ''; + echo ''; + + } else { + echo '
    '; } - echo _('

    Global Council Approval

    '); - echo _('

    Votes Received

    '); - echo ccgn_application_users_page_vote_counts ( $applicant_id ); + echo _('

    Global Council Approval

    '); + echo '
    '; + echo '
    '; + echo _('

    Votes Received

    '); + echo ccgn_application_users_page_vote_counts ( $applicant_id ); + echo '
    '; + echo '
    '; echo _('

    Votes

    '); - echo ccgn_application_users_page_vote_responses ( $applicant_id ); + echo '
    '; + echo ccgn_application_users_page_vote_responses ( $applicant_id ); + echo '
    '; } function ccgn_application_users_page () { @@ -557,3 +698,97 @@ function ccgn_application_user_link( $actions, $user_object ) { } return $actions; } + +// Ajax function +// Executed in the UI when a MC member ask to a voucher for clarification +// @user_id : user to be notified +function ccgn_ajax_ask_voucher() +{ + $user_id = $_POST['user_id']; + $applicant_id = $_POST['applicant_id']; + if (check_ajax_referer('ask_voucher', 'sec') && (!empty($user_id))) { + ccgn_ask_email_vouching_request($applicant_id,$user_id); + //set user state to clarification of the reason to vouch applicant + update_user_meta($user_id,'ccgn_need_to_clarify_vouch_reason',1); + ccgn_ask_clarification_log_append($applicant_id,$user_id); + echo 'ok'; + } + exit(0); +} +add_action('wp_ajax_nopriv_ask_voucher', 'ccgn_ajax_ask_voucher'); +add_action('wp_ajax_ask_voucher', 'ccgn_ajax_ask_voucher'); + +function ccgn_ajax_change_voucher() +{ + $voucher_id = esc_attr($_POST['voucher_id']); + $applicant_id = esc_attr($_POST['applicant_id']); + $position = esc_attr($_POST['position']); + $new_voucher = esc_attr( $_POST['new_voucher'] ); + + if (check_ajax_referer('change_voucher', 'sec') && (!empty($new_voucher))) { + + $form_id = RGFormsModel::get_form_id(CCGN_GF_CHOOSE_VOUCHERS); + + $search_criteria = array(); + $search_criteria['field_filters'][] + = array( + 'key' => 'created_by', + 'value' => $applicant_id, + ); + + $get_the_entries = GFAPI::get_entries( + $form_id, + $search_criteria, + array( + array( + 'key' => 'date_created', + 'direction' => 'ASC', + 'is_numeric' => false + ) + ) + ); + $entry_id = $get_the_entries[0]['id']; + $update_date = GFAPI::update_entry_field($entry_id, 'date_updated', date('Y-m-d H:m:s')); + $change_voucher_result = GFAPI::update_entry_field($entry_id, $position, $new_voucher); + if ($change_voucher_result) { + //send email to the new voucher + $send_mail = ccgn_registration_email_vouching_request( + $applicant_id, + $new_voucher + ); + echo 'ok'; + } else { + echo 'error'; + } + } else { + echo 'error'; + } + exit(0); +} +add_action('wp_ajax_nopriv_change_voucher', 'ccgn_ajax_change_voucher'); +add_action('wp_ajax_change_voucher', 'ccgn_ajax_change_voucher'); + +// Save new reason to vouch in order to clarify the reason of the vouched user +function ccgn_ajax_modify_reason_voucher() +{ + $user_id = get_current_user_id(); + $applicant_id = esc_attr($_POST['applicant_id']); + $new_reason = esc_attr($_POST['new_reason']); + $entry_id = esc_attr($_POST['entry_id']); + if (check_ajax_referer('clarification_voucher', 'sec') && (!empty($user_id)) && (!empty($entry_id)) && (!empty($new_reason)) ) { + //ccgn_ask_email_vouching_request($applicant_id, $user_id); + $update_date = GFAPI::update_entry_field($entry_id, 'date_updated', date('Y-m-d H:m:s')); + $reasonchange_result = GFAPI::update_entry_field($entry_id, CCGN_GF_VOUCH_REASON,$new_reason); + if ($reasonchange_result) { + echo 'ok'; + update_user_meta($user_id, 'ccgn_need_to_clarify_vouch_reason', 0); + } else { + echo 'error'; + } + } else { + echo 'error'; + } + exit(0); +} +add_action('wp_ajax_nopriv_reason_voucher', 'ccgn_ajax_modify_reason_voucher'); +add_action('wp_ajax_reason_voucher', 'ccgn_ajax_modify_reason_voucher'); \ No newline at end of file diff --git a/plugins/cc-global-network/includes/application-state.php b/plugins/cc-global-network/includes/application-state.php index a9f30bf..ebc413e 100644 --- a/plugins/cc-global-network/includes/application-state.php +++ b/plugins/cc-global-network/includes/application-state.php @@ -457,4 +457,57 @@ function ccgn_show_current_application_status($user_id) { $current_state['step'] = $steps[$current_status['stage']]; $current_state['date'] = $current_status['date']; return $current_state; +} + +//Remove old applications left in custom state +//The main reason is to wipe old applications considered abandoned +function ccgn_get_old_applications_with_state($state, $months_ago) +{ + $args = array( + 'role' => 'new-user', + 'posts_per_page' => -1, + 'date_query' => array( + array( + 'column' => 'user_registered', + 'before' => $months_ago . ' months ago' + ) + ), + 'meta_query' => array( + array( + 'key' => 'ccgn-application-state', + 'value' => $state + ) + ) + ); + $query = new WP_User_Query($args); + return $query; +} +function ccgn_list_old_applications_with_state($state, $months_ago) +{ + $query = ccgn_get_old_applications_with_state($state, $months_ago); + echo '-------------------------------------------------------------------------------------' . "\n"; + echo 'LISTING USERS WITH THE STATE "' . $state . '" AND REGISTERED ' . $months_ago . ' MONTHS AGO' . "\n"; + echo '-------------------------------------------------------------------------------------' . "\n"; + foreach ($query->get_results() as $user) { + $user_id = $user->data->ID; + echo $user_id . ' - ' . $user->data->display_name . '( ' . $user->data->user_login . ' ) - registered on: ' . $user->data->user_registered . "\n"; + } +} +function ccgn_remove_old_applications_with_state($state, $months_ago) +{ + $query = ccgn_get_old_applications_with_state($state, $months_ago); + foreach ($query->get_results() as $user) { + $user_id = $user->data->ID; + $user_name = $user->data->display_name; + $user_login = $user->data->user_login; + _ccgn_application_delete_entries_created_by($user_id); + delete_user_meta($user_id, CCGN_APPLICATION_TYPE); + delete_user_meta($user_id, CCGN_APPLICATION_STATE); + delete_user_meta($user_id, CCGN_USER_IS_AUTOVOUCHED); + + $delete = wp_delete_user($user_id); + if ($delete) { + echo 'DELETED USER: ' . $user_id . ' - ' . $user_name . '( ' . $user_login . ' )' . "\n"; + } + } } \ No newline at end of file diff --git a/plugins/cc-global-network/includes/format-applicant-profile.php b/plugins/cc-global-network/includes/format-applicant-profile.php index f33d0ff..c9cb3c6 100644 --- a/plugins/cc-global-network/includes/format-applicant-profile.php +++ b/plugins/cc-global-network/includes/format-applicant-profile.php @@ -83,9 +83,9 @@ function ccgn_vp_format_field ( $entry, $item ) { ); // Make sure the entry has a value for this item if( $value ) { - $html = '

    ' - . $item[ 0 ] . '
    ' - . $value + $html = '' + . ''. $item[ 0 ] . '' + . ''.$value.'' . '

    '; } return $html; @@ -113,11 +113,53 @@ function ccgn_vp_format_avatar ( $entry ) { // Format the relevant fields from the Applicant Details form as html. -function ccgn_vouching_form_profile_format( $entry, $map ) { - $html = '
    '; +function ccgn_vouching_form_profile_format( $entry, $map, $applicant_id ) { + $is_individual = ccgn_user_is_individual_applicant($entry['created_by']); + $statement = ($is_individual) ? $entry[3] : $entry[6]; + $bio = $entry[2]; + $html = ''; + if (!is_admin()){ + $the_user = get_user_by('ID', $applicant_id); + $html .= '

    '.$the_user->display_name.'

    '; + } + $html .= '
    '; + $html .= ''; + $html .= ''; + $html .= ''; + if ($is_individual): + $html .= ''; + endif; + $html .= ''; + $html .= '
    '; + $html .= '
    Membership Statement
    '; + $html .= ccgn_vp_clean_string($statement); + $html .= '
    '; + $html .= '
    Brief Biography
    '; + $html .= ccgn_vp_clean_string($bio); + $html .= '
    '; + $html .= 'View more applicant details '; + $html .= ''; + if (is_admin()) { + if ($is_individual) { + unset($map[2]); + unset($map[3]); + } else { + unset($map[4]); + } + } else { + if ($is_individual) { + unset($map[0]); + unset($map[1]); + } else { + unset($map[2]); + } + } + unset ($statement); + unset ($bio); foreach( $map as $item ) { $html .= ccgn_vp_format_field( $entry, $item ); } + $html .= '
    '; $html .= '
    '; return $html; } @@ -131,7 +173,8 @@ function ccgn_vouching_form_individual_profile_text ( $applicant_id ) { //. ccgn_vp_format_avatar( $entry ) . ccgn_vouching_form_profile_format( $entry, - CCGN_GF_DETAILS_VOUCH_MAP + CCGN_GF_DETAILS_VOUCH_MAP, + $applicant_id ); } @@ -139,7 +182,8 @@ function ccgn_vouching_form_institution_profile_text ( $applicant_id ) { return '

    Institutional Applicant

    ' . ccgn_vouching_form_profile_format( ccgn_details_institution_form_entry ( $applicant_id ), - CCGN_GF_INSTITUTION_DETAILS_VOUCH_MAP + CCGN_GF_INSTITUTION_DETAILS_VOUCH_MAP, + $applicant_id ); } @@ -157,9 +201,9 @@ function ccgn_vouching_form_applicant_profile_text ( $applicant_id ) { function ccgn_user_page_individual_profile_text ( $applicant_id ) { $entry = ccgn_details_individual_form_entry( $applicant_id ); - return '

    Individual Applicant

    ' - //. ccgn_vp_format_avatar ( $entry ) - . ccgn_applicant_display_name_formatted ( $applicant_id ) + + return //. ccgn_vp_format_avatar ( $entry ) + ccgn_applicant_display_name_formatted ( $applicant_id ) . ccgn_vouching_form_profile_format( $entry, CCGN_GF_DETAILS_USER_PAGE_MAP @@ -167,8 +211,7 @@ function ccgn_user_page_individual_profile_text ( $applicant_id ) { } function ccgn_user_page_institution_profile_text ( $applicant_id ) { - return '

    Institutional Applicant

    ' - . ccgn_applicant_display_name_formatted ( $applicant_id ) + return ccgn_applicant_display_name_formatted ( $applicant_id ) .ccgn_vouching_form_profile_format( ccgn_details_institution_form_entry ( $applicant_id ), CCGN_GF_INSTITUTION_DETAILS_USER_PAGE_MAP @@ -195,12 +238,83 @@ function ccgn_applicant_display_name ( $applicant_id ) { function ccgn_applicant_display_name_formatted ( $applicant_id ) { if ( ccgn_user_is_individual_applicant ( $applicant_id ) ) { - return '

    Applicant Name
    ' - . get_user_by( 'ID', $applicant_id)->display_name + return '

    ' + . '' .get_user_by( 'ID', $applicant_id)->display_name. '' + . 'Individual Applicant' . '

    '; } else { - return '

    Institution Name
    ' - . ccgn_institutional_applicant_name ( $applicant_id ) + return '

    ' + . '' . ccgn_institutional_applicant_name ( $applicant_id ) .'' + . 'Institutional Applicant' . '

    '; } } + +/////////////////////////////////////////////////////////////////////////////// +// Log ask for Clarification +/////////////////////////////////////////////////////////////////////////////// + +define('CCGN_CLARIFICATION_LOG_REG_PROP', 'ccgn-ask-clarification-log'); + +function ccgn_ask_clarification_log_get() +{ + return get_option(CCGN_CLARIFICATION_LOG_REG_PROP, array()); +} +function ccgn_ask_clarification_log_get_id($applicant_id) { + $log = ccgn_ask_clarification_log_get(); + return $log[$applicant_id]; +} +function ccgn_ask_clarification_log_get_id_ajax() +{ + $applicant_id = esc_attr($_POST['applicant_id']); + $voucher_id = esc_attr($_POST['voucher_id']); + $log = ccgn_ask_clarification_log_get(); + $return_log = array(); + foreach ($log[$applicant_id] as $entry) { + if ($entry['voucher_id'] == $voucher_id) { + $return_log[] = $entry; + } + } + echo json_encode($return_log); + exit(0); +} +add_action('wp_ajax_nopriv_ask_voucher_log', 'ccgn_ask_clarification_log_get_id_ajax'); +add_action('wp_ajax_ask_voucher_log', 'ccgn_ask_clarification_log_get_id_ajax'); +function ccgn_ask_clarification_log_ensure($today) +{ + $option = ccgn_ask_clarification_log_get(); + $days = array_keys($option); + // Oldest to newest + sort($days); + // No entry for today? Insert it + if ($days[count($days) - 1] != $today) { + $option[$today] = array(); + } + // Too many entries? Remove the oldest + if (count($option) > CCGN_CLARIFICATION_LOG_REG_TRUNCATE) { + unset($option[$days[0]]); + } + return $option; +} + +function ccgn_ask_clarification_log_set($log_structure) +{ + update_option(CCGN_CLARIFICATION_LOG_REG_PROP, $log_structure); +} + +function ccgn_ask_clarification_log_append( + $applicant_id, + $voucher_id +) { + $today = date('Y-m-d'); + $log = ccgn_ask_clarification_log_get(); + $log[$applicant_id][] = array( + 'applicant_id' => $applicant_id, + 'date' => $today, + 'voucher_id' => $voucher_id, + 'ask_user_id' => get_current_user_id(), + 'applicant_name' => get_user_by('ID', $applicant_id)->display_name, + 'ask_user_name' => get_user_by('ID', get_current_user_id())->display_name, + ); + ccgn_ask_clarification_log_set($log); +} \ No newline at end of file diff --git a/plugins/cc-global-network/includes/gravityforms-interaction.php b/plugins/cc-global-network/includes/gravityforms-interaction.php index 8e4d4df..cfadcb0 100644 --- a/plugins/cc-global-network/includes/gravityforms-interaction.php +++ b/plugins/cc-global-network/includes/gravityforms-interaction.php @@ -548,7 +548,9 @@ function ccgn_reopen_application_auto_closed_because_cannots( . $update_date ); // Delete votes from user if there are - ccgn_delete_vote_entries_from_user($applicant_id); + + ccgn_delete_vote_entries_from_user( $applicant_id ); + // Restore the user to the new-user role ccgn_user_level_set_applicant_new($applicant_id); // Set the application to be in the update vouchers stage @@ -558,6 +560,7 @@ function ccgn_reopen_application_auto_closed_because_cannots( return true; } // Delete vote entries from an applicant in order to restore the application status + function ccgn_delete_vote_entries_from_user($applicant_id) { $entries = ccgn_application_votes($applicant_id); @@ -842,6 +845,7 @@ function ccgn_application_vouches_counts ( $applicant_id ) { 'cannot' => $cannot ); } + //Return true if the applicant can be voted function ccgn_application_can_be_voted( $applicant_id ) { $vouches = ccgn_application_vouches_counts( $applicant_id ); @@ -1802,16 +1806,42 @@ function ccgn_application_users_page_vouch_responses ( } return $result; } +//The same function up here but we get the result on an array +//in order to get only the data +function ccgn_application_users_page_vouch_responses_data( + $applicant_id, + $full_date = false +) { + $result = ''; + $vouches = ccgn_application_vouches($applicant_id); + $vouches_list = array(); + foreach ($vouches as $vouch) { + $voucher = get_user_by('ID', $vouch['created_by']); + $vouch_date = ccgn_entry_created_or_updated($vouch); + if (!$full_date) { + $vouch_date = explode(' ', $vouch_date)[0]; + } + $the_vouch = array(); + $the_vouch['id'] = $vouch['created_by']; + $the_vouch['name'] = $voucher->display_name; + $the_vouch['date'] = $vouch_date; + $the_vouch['vouched'] = $vouch[CCGN_GF_VOUCH_DO_YOU_VOUCH]; + $the_vouch['reason'] = $vouch[CCGN_GF_VOUCH_REASON]; + + $vouches_list[] = $the_vouch; + } + return $vouches_list; +} // Format the count of vouches function ccgn_application_users_page_vouch_counts ( $applicant_id ) { $counts = ccgn_application_vouches_counts( $applicant_id ); - return '

    Cannot: ' + return '

    Cannot: ' . $counts['cannot'] - . '

    Yes: ' + . '

    Yes: ' . $counts['yes'] - . '

    No: ' + . '

    No: ' . $counts['no'] . '

    '; } @@ -1821,8 +1851,24 @@ function ccgn_application_users_page_vouch_counts ( $applicant_id ) { function ccgn_application_users_page_vouchers ( $applicant_id ) { $result = ''; $vouchers = ccgn_application_vouchers_users ( $applicant_id ); + $vouch_data = ccgn_application_users_page_vouch_responses_data( + $applicant_id, + true + ); + $position = 1; foreach ( $vouchers as $voucher ) { - $result .= '

    ' . $voucher->display_name . '

    '; + $data = array(); + $other_voucher = 0; // get the other voucher ID in case if vouched is "yes". this means that we have to disable the name in the select box + foreach ($vouch_data as $vouch_item) { + if ($voucher->ID == $vouch_item['id']) { + $data = $vouch_item; + } else if ( ($voucher->ID != $vouch_item['id']) && ($vouch_item['vouched'] == 'Yes') ) { + $other_voucher = $vouch_item['id']; + } + } + $action_button = (ccgn_current_user_is_final_approver() && ($data['vouched'] != 'Yes') && ($data['vouched'] != 'No') ) ? ' ' : ''; + $result .= '

    ' . $voucher->display_name . $action_button .'

    '; + $position++; } return $result; } @@ -1940,4 +1986,4 @@ function ccgn_new_legal_approvals_declined_since ( $start_date, $end_date ) { $end_date, CCGN_GF_LEGAL_APPROVAL_APPROVED_NO ); -} +} \ No newline at end of file diff --git a/plugins/cc-global-network/includes/registration-form-emails.php b/plugins/cc-global-network/includes/registration-form-emails.php index 214e650..46faa4d 100644 --- a/plugins/cc-global-network/includes/registration-form-emails.php +++ b/plugins/cc-global-network/includes/registration-form-emails.php @@ -215,6 +215,20 @@ function ccgn_registration_email_to_voucher ( $applicant_id, ); } +function ccgn_ask_email_to_voucher ( $applicant_id, + $voucher_id, + $email_option ) { + $applicant = get_user_by( 'ID', $applicant_id ); + $voucher = get_user_by( 'ID', $voucher_id ); + ccgn_registration_email( + $applicant->user_nicename, + $applicant->ID, + $voucher->user_nicename, + $voucher->user_email, + $email_option + ); +} + function ccgn_registration_email_application_received ( $applicant_id ) { ccgn_registration_email_to_applicant( $applicant_id, @@ -283,6 +297,15 @@ function ccgn_registration_email_notify_legal_insititution_approved ( 'ccgn-email-notify-legal' ); } +function ccgn_ask_email_vouching_request ( $applicant_id, + $voucher_id ) { + ccgn_ask_email_to_voucher( + $applicant_id, + $voucher_id, + 'ccgn-email-ask-voucher' + ); +} + //////////////////////////////////////////////////////////////////////////////// // Use the name and address from our settings for emails diff --git a/plugins/cc-global-network/public/vouching-form-shortcode.php b/plugins/cc-global-network/public/vouching-form-shortcode.php index 05bbceb..673c80b 100644 --- a/plugins/cc-global-network/public/vouching-form-shortcode.php +++ b/plugins/cc-global-network/public/vouching-form-shortcode.php @@ -56,7 +56,7 @@ function ccgn_vouching_requests_for_me ( $voucher_id ) { function ccgn_vouching_requests_render ( $voucher_id ) { $requests = ccgn_vouching_requests_for_me ( $voucher_id ); if ( $requests !== [] ) { - echo _( "

    Current Vouching Requests