| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $wpdb,$wppmfunction,$current_user; |
| 6 |
$wppm_users_role = get_option('wppm_user_role'); |
| 7 |
$settings = get_option("wppm-ap-modal"); |
| 8 |
$task_id = isset($_POST['task_id']) ? absint(sanitize_text_field(wp_unslash($_POST['task_id']))) : '' ; |
| 9 |
$proj_id = isset($_POST['proj_id']) ? absint(sanitize_text_field(wp_unslash($_POST['proj_id']))) : '' ; |
| 10 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_permission('assign_task_users',$task_id))) {exit;} |
| 11 |
$task = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wppm_task where id = '".esc_sql($task_id)."'" ); |
| 12 |
$project_data = $wppmfunction->get_project($task->project); |
| 13 |
if(!empty($project_data['users'])){ |
| 14 |
$proj_users = explode(',',$project_data['users']); |
| 15 |
} |
| 16 |
if($task->users != null){ |
| 17 |
$users = explode(",",$task->users); |
| 18 |
} |
| 19 |
ob_start(); |
| 20 |
?> |
| 21 |
<form id="frm_get_task_users"> |
| 22 |
<div id="wppm_get_task_users"> |
| 23 |
<input type="text" id="wppm_task_user_name" class="wppm_task_user_name form-control regi_user_autocomplete ui-autocomplete-input" name="task_user_name" autocomplete="off" placeholder="<?php echo esc_attr__('Search User...','taskbuilder');?>"> |
| 24 |
<div class="wppm_filter_display_container" id="wppm_task_users_display_container"> |
| 25 |
<?php |
| 26 |
if(!empty($users)){ |
| 27 |
foreach($users as $user){ |
| 28 |
if( (!empty($proj_users)) && in_array($user,$proj_users)){ |
| 29 |
?> |
| 30 |
<div id="wppm_task_user_display_container_<?php echo esc_attr($user)?>" class="row wppm_task_user_display_container"> |
| 31 |
<?php |
| 32 |
$userdata = get_userdata( $user ); ?> |
| 33 |
<div class="flex-container col-sm-4"> |
| 34 |
<span class="wppm_filter_display_text"> |
| 35 |
<?php echo esc_html($userdata->display_name); ?> |
| 36 |
<input type="hidden" name="user_names[]" value="<?php echo esc_attr($user) ?>"> |
| 37 |
</span> |
| 38 |
</div> |
| 39 |
<div class="col-sm-4 wppm_delete_user_icon"> |
| 40 |
<span onclick="wppm_remove_task_user_filter(<?php echo esc_attr($user)?>);"><img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/trash.svg'); ?>" alt="delete"></span> |
| 41 |
</div> |
| 42 |
</div> |
| 43 |
<?php } ?> |
| 44 |
<?php } |
| 45 |
} else{ |
| 46 |
?><span id="wppm_assign_to_none_task"><?php echo esc_html_e('None','taskbuilder');?> </span><?php |
| 47 |
} ?> |
| 48 |
</div> |
| 49 |
<input type="hidden" name="action" value="wppm_set_task_users" /> |
| 50 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wppm_set_task_users' ) ); ?>"> |
| 51 |
<input type="hidden" id="wppm_task_id" name="task_id" value="<?php echo esc_attr($task_id) ?>" /> |
| 52 |
</div> |
| 53 |
</form> |
| 54 |
<style> |
| 55 |
li { |
| 56 |
color:<?php echo esc_attr( $settings['body-text-color'])?>!important; |
| 57 |
} |
| 58 |
</style> |
| 59 |
<script> |
| 60 |
jQuery(document).ready(function(){ |
| 61 |
jQuery("input[name='task_user_name']").keypress(function(e) { |
| 62 |
//Enter key |
| 63 |
if (e.which == 13) { |
| 64 |
return false; |
| 65 |
} |
| 66 |
}); |
| 67 |
jQuery( ".wppm_task_user_name" ).autocomplete({ |
| 68 |
minLength: 1, |
| 69 |
appendTo: jQuery('.wppm_task_user_name').parent(), |
| 70 |
source: function( request, response ) { |
| 71 |
var term = request.term; |
| 72 |
request = { |
| 73 |
action: 'wppm_filter_autocomplete', |
| 74 |
term : term, |
| 75 |
field : 'task_user_name', |
| 76 |
task_id:<?php echo esc_attr($task_id) ?>, |
| 77 |
proj_id:<?php echo esc_attr($proj_id) ?> |
| 78 |
} |
| 79 |
jQuery.getJSON( wppm_admin.ajax_url, request, function( data, status, xhr ) { |
| 80 |
response(data); |
| 81 |
}); |
| 82 |
}, |
| 83 |
select: function (event, ui) { |
| 84 |
var html_str = '<div id="wppm_task_user_display_container_'+ui.item.user_id+'" class="row wppm_task_user_display_container">' |
| 85 |
+'<div class="flex-container col-sm-4">' |
| 86 |
+'<span class="wppm_filter_display_text">' |
| 87 |
+ui.item.label |
| 88 |
+'<input type="hidden" name="user_names[]" value="'+ui.item.user_id+'">' |
| 89 |
+'</span>' |
| 90 |
+'</div>' |
| 91 |
+'<div class="col-sm-4 wppm_delete_user_icon">' |
| 92 |
+'<span onclick="wppm_remove_task_user_filter('+ui.item.user_id+');"><img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/trash.svg'); ?>" alt="delete"></span>' |
| 93 |
+'</div>' |
| 94 |
+'</div>'; |
| 95 |
jQuery('#wppm_assign_to_none_task').hide(); |
| 96 |
jQuery('#wppm_get_task_users #wppm_task_users_display_container').append(html_str); |
| 97 |
jQuery(this).val(''); return false; |
| 98 |
} |
| 99 |
}).focus(function() { |
| 100 |
jQuery(this).autocomplete("search", ""); |
| 101 |
}); |
| 102 |
|
| 103 |
}); |
| 104 |
</script> |
| 105 |
<?php |
| 106 |
$body = ob_get_clean(); |
| 107 |
ob_start(); |
| 108 |
?> |
| 109 |
<button type="button" class="btn <?php echo ($proj_id!="0") ? 'wppm_popup_close': 'wppm_task_popup_close' ?> " onclick="<?php echo ($proj_id!=0) ? "wppm_modal_close()":"wppm_task_modal_close()"?>"><?php echo esc_html_e('Close','taskbuilder');?></button> |
| 110 |
<button type="button" class="btn <?php echo ($proj_id!="0") ? 'wppm_popup_action': 'wppm_task_popup_action' ?> " onclick="wppm_set_task_users(<?php echo esc_attr($proj_id) ?>);"><?php echo esc_html_e('Save','taskbuilder');?></button> |
| 111 |
<?php |
| 112 |
$footer = ob_get_clean(); |
| 113 |
|
| 114 |
$output = array( |
| 115 |
'body' => $body, |
| 116 |
'footer' => $footer |
| 117 |
); |
| 118 |
|
| 119 |
echo wp_json_encode($output); |