Skip to content

Commit 86eb732

Browse files
authored
Merge pull request #411 from creativecommons/removing-voucher
remove voucher process
2 parents ba13211 + b4e49f8 commit 86eb732

File tree

2 files changed

+89
-13
lines changed

2 files changed

+89
-13
lines changed

plugins/cc-global-network/admin/assets/js/script.js

+40
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,46 @@ jQuery(document).ready(function ($) {
151151
});
152152
});
153153
}
154+
$.removeVoucher = function (id, name, applicant_id) {
155+
$('#remove-voucher-for-sure').off('click');
156+
$('#remove-voucher-modal').find('.name-display').html(name);
157+
tb_show("Remove voucher", "#TB_inline?width=600&height=350&inlineId=remove-voucher-modal");
158+
$('#close-remove-voucher').on('click', function (e) {
159+
e.preventDefault();
160+
tb_remove();
161+
return false;
162+
});
163+
$('#remove-voucher-for-sure').on('click', function (e) {
164+
var sec = $('#remove_voucher_nonce').val(),
165+
this_button = $(this);
166+
$.ajax({
167+
url: wpApiSettings.ajax_url,
168+
type: 'POST',
169+
data: {
170+
action: 'remove_voucher',
171+
user_id: id,
172+
applicant_id: applicant_id,
173+
sec: sec
174+
},
175+
beforeSend: function () {
176+
this_button.text('Working...');
177+
},
178+
success: function (data) {
179+
this_button.text("Yes, I'm sure");
180+
$('#alert-messages').html('');
181+
if (data.trim() == 'ok') {
182+
$('#alert-messages').append('<div class="updated notice is-dismissible"><p>The voucher was removed succesfully</p></div>').find('.notice').delay(3200).fadeOut(300);
183+
tb_remove();
184+
location.reload();
185+
}
186+
if (data.trim() == 'error') {
187+
$('#alert-messages').append('<div class="error notice is-dismissible"><p>There was an error sending your request</p></div>').find('.notice').delay(3200).fadeOut(300);
188+
}
189+
tb_remove();
190+
}
191+
});
192+
});
193+
}
154194
$.askVoucher = function (id, name, applicant_id) {
155195
$('#ask-voucher-for-sure').off('click');
156196
$('#ask-clarification-modal').find('.name-display').html(name);

plugins/cc-global-network/admin/user-application-page.php

+49-13
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ function ccgn_application_users_page_render_details ( $applicant_id, $state ) {
645645
$applicant_votes = ccgn_application_votes_counts($applicant_id);
646646
$asked_class = '';
647647
$who_asked = '';
648-
//print_r($voucher);
649648
if (empty($asked_info['user_id'])) {
650649
$log_user = ccgn_ask_clarification_log_get_id($applicant_id);
651650
foreach ($log_user as $entry) {
@@ -667,7 +666,6 @@ function ccgn_application_users_page_render_details ( $applicant_id, $state ) {
667666
$user_is_asked_for_clarification = $asked_info['status'];
668667
}
669668
echo '<div class="ccgn-box applicant '.$asked_class.'">';
670-
//echo '<div class="icon"><span class="dashicons dashicons-admin-users"></span></div>';
671669
echo '<h3 class="applicant-name">'.$voucher['name'].'</h3>';
672670
echo '<span class="date">'.$voucher['date'].'</span>';
673671
if ($user_is_asked_for_clarification) {
@@ -687,28 +685,33 @@ function ccgn_application_users_page_render_details ( $applicant_id, $state ) {
687685
if (($voucher['vouched'] == 'Yes') && (ccgn_current_user_is_final_approver($applicant_id) || ccgn_current_user_is_membership_council($applicant_id)) ) {
688686
echo '<a href="#" onClick="$.askVoucher('.$voucher['id'].',\''.$voucher['name'].'\','.$applicant_id.')" class="button">Ask for clarification</a>';
689687
}
688+
if (current_user_can( 'administrator' ) && ($voucher['vouched'] == 'No')) {
689+
echo '<br><a href="#" class="button-primary" style="background-color: #dc3232;" onClick="$.removeVoucher('.$voucher['id'].',\''.$voucher['name'].'\','.$applicant_id.')" class="button">Remove this voucher</a>';
690+
}
690691

691692
echo '</div>';
692693
}
693694
echo '</div>';
694-
// echo cgn_application_users_page_vouch_responses (
695-
// $applicant_id,
696-
// true
697-
// );
698695
add_thickbox();
696+
echo '<div id="remove-voucher-modal" style="display:none;">';
697+
echo '<h2>You are about to remove this voucher: <span class="name-display"></span></h2>';
698+
echo '<p>That means that you think the vouch is not correct and the applicant needs to choose another voucher</p>';
699+
echo '<p>this process will send an email to the applicant in order to choose a new voucher the status will be updated to "update-vouchers" </p>';
700+
echo '<p>Are you sure you want to do this? </p>';
701+
echo '<br>';
702+
echo wp_nonce_field('remove_voucher', 'remove_voucher_nonce', true, false);
703+
echo '<div class="buttons">';
704+
echo '<button id="close-remove-voucher" class="button close-window">Close</button> ';
705+
echo "<button id=\"remove-voucher-for-sure\" class=\"button button-primary ask-voucher-for-sure\">Yes, I'm sure</button>";
706+
echo '</div>';
707+
echo '</div>';
699708
echo '<div id="ask-clarification-modal" style="display:none;">';
700709
echo '<h2>You are about to ask for clarification to the voucher: <span class="name-display"></span></h2>';
701710
echo '<p>That means you think the text supporting this application is not enough, is not clear or is not helpful for you to approve this application. If that is the case, you can ask the voucher to clarify.</p>';
702-
703-
704711
echo '<div class="log-content" id="log-content-ask-voucher">';
705712
echo '<p>This already was requested by: </p>';
706713
echo '<div class="inner-scroll medium">';
707714
echo '<ol class="log-entries" id="log-entry-ask-voucher">';
708-
709-
//foreach ($log as $entry) {
710-
// echo '<li><div class="log-entry"><strong>'.$entry['ask_user_name'].'</strong> asked on <span class="date">'.$entry['date'].'</span></div></li>';
711-
//}
712715
echo '</ol>';
713716
echo '</div>';
714717
echo '<p>There is no need to send this email again to the voucher. In case you consider that necessary, you can do it again.</p>';
@@ -721,7 +724,6 @@ function ccgn_application_users_page_render_details ( $applicant_id, $state ) {
721724
echo '<button id="close-ask-voucher" class="button close-window">Close</button> ';
722725
echo "<button id=\"ask-voucher-for-sure\" class=\"button button-primary ask-voucher-for-sure\">Yes, I'm sure</button>";
723726
echo '</div>';
724-
//echo '</p>';
725727
echo '</div>';
726728
echo '<div id="change-voucher-modal" style="display:none;">';
727729
echo '<h2>You are about to change the current voucher: <span class="name-display"></span></h2>';
@@ -886,6 +888,40 @@ function ccgn_ajax_ask_voucher()
886888
add_action('wp_ajax_nopriv_ask_voucher', 'ccgn_ajax_ask_voucher');
887889
add_action('wp_ajax_ask_voucher', 'ccgn_ajax_ask_voucher');
888890

891+
function ccgn_ajax_remove_voucher()
892+
{
893+
$user_id = $_POST['user_id'];
894+
$applicant_id = $_POST['applicant_id'];
895+
if (check_ajax_referer('remove_voucher', 'sec') && (!empty($user_id))) {
896+
$entries = ccgn_entries_referring_to_user($applicant_id,'Vouch For Applicant');
897+
$entry_id = null;
898+
foreach ($entries as $entry) {
899+
if ($entry['form_id'] == 44) {
900+
$entry_id = $entry['id'];
901+
break;
902+
}
903+
}
904+
$created_by_applicant = ccgn_entries_created_by_user($applicant_id,41);
905+
foreach ($created_by_applicant as $form_entry) {
906+
if ($form_entry['form_id'] == 41) {
907+
if ($form_entry['1'] == $user_id ) {
908+
GFAPI::update_entry_field($form_entry['id'], '1', '');
909+
} elseif ($form_entry['2'] == $user_id) {
910+
GFAPI::update_entry_field($form_entry['id'], '2', '');
911+
}
912+
}
913+
}
914+
GFAPI::delete_entry( $entry_id );
915+
_ccgn_registration_user_set_stage( $applicant_id, 'update-vouchers' );
916+
ccgn_registration_email_voucher_cannot( $applicant_id, $user_id );
917+
echo 'ok';
918+
}
919+
exit(0);
920+
}
921+
922+
add_action('wp_ajax_nopriv_remove_voucher', 'ccgn_ajax_remove_voucher');
923+
add_action('wp_ajax_remove_voucher', 'ccgn_ajax_remove_voucher');
924+
889925
function ccgn_ajax_change_voucher()
890926
{
891927
$voucher_id = esc_attr($_POST['voucher_id']);

0 commit comments

Comments
 (0)