| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_Agent_Roles' ) ) : |
| 7 |
|
| 8 |
final class WPSC_Agent_Roles { |
| 9 |
|
| 10 |
/** |
| 11 |
* Initialize this class |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
public static function init() { |
| 16 |
|
| 17 |
// Get agent roles ajax register. |
| 18 |
add_action( 'wp_ajax_wpsc_get_agent_roles', array( __CLASS__, 'get_agent_roles' ) ); |
| 19 |
|
| 20 |
// Add agent role. |
| 21 |
add_action( 'wp_ajax_wpsc_get_add_agent_role', array( __CLASS__, 'get_add_agent_role' ) ); |
| 22 |
add_action( 'wp_ajax_wpsc_set_add_agent_role', array( __CLASS__, 'set_add_agent_role' ) ); |
| 23 |
|
| 24 |
// clone agent role. |
| 25 |
add_action( 'wp_ajax_wpsc_get_clone_agent_role', array( __CLASS__, 'get_clone_agent_role' ) ); |
| 26 |
|
| 27 |
// Edit agent role. |
| 28 |
add_action( 'wp_ajax_wpsc_get_edit_agent_role', array( __CLASS__, 'get_edit_agent_role' ) ); |
| 29 |
add_action( 'wp_ajax_wpsc_set_edit_agent_role', array( __CLASS__, 'set_edit_agent_role' ) ); |
| 30 |
|
| 31 |
// Delete agent role. |
| 32 |
add_action( 'wp_ajax_wpsc_delete_agent_role', array( __CLASS__, 'delete_agent_role' ) ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Get agent roles ajax callback function |
| 37 |
* |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
public static function get_agent_roles() { |
| 41 |
|
| 42 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 43 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 44 |
} |
| 45 |
$roles = get_option( 'wpsc-agent-roles', array() );?> |
| 46 |
|
| 47 |
<div class="wpsc-setting-header"> |
| 48 |
<h2><?php esc_attr_e( 'Agent Roles', 'supportcandy' ); ?></h2> |
| 49 |
</div> |
| 50 |
<div class="wpsc-setting-section-body"> |
| 51 |
<div class="wpsc-dock-container"> |
| 52 |
<?php |
| 53 |
printf( |
| 54 |
/* translators: Click here to see the documentation */ |
| 55 |
esc_attr__( '%s to see the documentation!', 'supportcandy' ), |
| 56 |
'<a href="https://supportcandy.net/docs/add-new-agent-role/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>' |
| 57 |
); |
| 58 |
?> |
| 59 |
</div> |
| 60 |
<div class="wpsc-setting-cards-container"> |
| 61 |
<div style="width: 100%;"> |
| 62 |
<table class="agent-role-list-table wpsc-setting-tbl"> |
| 63 |
<thead> |
| 64 |
<tr> |
| 65 |
<th><?php esc_attr_e( 'Role', 'supportcandy' ); ?></th> |
| 66 |
<th><?php esc_attr_e( 'Actions', 'supportcandy' ); ?></th> |
| 67 |
</tr> |
| 68 |
</thead> |
| 69 |
<tbody> |
| 70 |
<?php |
| 71 |
if ( $roles ) : |
| 72 |
foreach ( $roles as $key => $role ) : |
| 73 |
?> |
| 74 |
<tr> |
| 75 |
<td> <span class="title"><?php echo esc_attr( $role['label'] ); ?></span> </td> |
| 76 |
<td> |
| 77 |
<span class="wpsc-link" onclick="wpsc_get_edit_agent_role(<?php echo esc_attr( $key ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_edit_agent_role' ) ); ?>');"><?php esc_attr_e( 'Edit', 'supportcandy' ); ?></span> | |
| 78 |
<span class="wpsc-link" onclick="wpsc_get_clone_agent_role(<?php echo esc_attr( $key ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_clone_agent_role' ) ); ?>');"><?php esc_attr_e( 'Clone', 'supportcandy' ); ?></span> |
| 79 |
<?php |
| 80 |
if ( intval( $key ) > 2 ) : |
| 81 |
?> |
| 82 |
| <span class="wpsc-link" onclick="wpsc_delete_agent_role(<?php echo esc_attr( $key ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_delete_agent_role' ) ); ?>');"><?php esc_attr_e( 'Delete', 'supportcandy' ); ?></span> |
| 83 |
<?php |
| 84 |
endif |
| 85 |
?> |
| 86 |
</td> |
| 87 |
</tr> |
| 88 |
<?php |
| 89 |
endforeach; |
| 90 |
endif; |
| 91 |
?> |
| 92 |
</tbody> |
| 93 |
</table> |
| 94 |
<script> |
| 95 |
jQuery('table.agent-role-list-table').DataTable({ |
| 96 |
order: [[1, "asc"]], |
| 97 |
pageLength: 20, |
| 98 |
bLengthChange: false, |
| 99 |
columnDefs: [ |
| 100 |
{ targets: [0,-1], orderable: false }, |
| 101 |
{ targets: -1, searchable: false }, |
| 102 |
{ targets: '_all', className: 'dt-left' } |
| 103 |
], |
| 104 |
layout: { |
| 105 |
topStart: { |
| 106 |
buttons: [ |
| 107 |
{ |
| 108 |
text: '<?php esc_attr_e( 'Add new', 'supportcandy' ); ?>', |
| 109 |
className: 'wpsc-button small primary', |
| 110 |
action: function ( e, dt, node, config ) { |
| 111 |
jQuery( '.wpsc-setting-section-body' ).html( supportcandy.loader_html ); |
| 112 |
var data = { action: 'wpsc_get_add_agent_role' , _ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_add_agent_role' ) ); ?>' }; |
| 113 |
jQuery.post( |
| 114 |
supportcandy.ajax_url, |
| 115 |
data, |
| 116 |
function (response) { |
| 117 |
jQuery( '.wpsc-setting-section-body' ).html( response ); |
| 118 |
} |
| 119 |
); |
| 120 |
} |
| 121 |
} |
| 122 |
], |
| 123 |
} |
| 124 |
}, |
| 125 |
language: supportcandy.translations.datatables |
| 126 |
}); |
| 127 |
</script> |
| 128 |
</div> |
| 129 |
</div> |
| 130 |
</div> |
| 131 |
<?php |
| 132 |
wp_die(); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Add agent role UI |
| 137 |
* |
| 138 |
* @return void |
| 139 |
*/ |
| 140 |
public static function get_add_agent_role() { |
| 141 |
|
| 142 |
if ( check_ajax_referer( 'wpsc_get_add_agent_role', '_ajax_nonce', false ) != 1 ) { |
| 143 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 144 |
} |
| 145 |
|
| 146 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 147 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 148 |
} |
| 149 |
|
| 150 |
$title = esc_attr__( 'Add new', 'supportcandy' ); |
| 151 |
|
| 152 |
?> |
| 153 |
<form action="#" onsubmit="return false;" class="frm-add-agent-role"> |
| 154 |
<div class="wpsc-input-group"> |
| 155 |
<div class="label-container"> |
| 156 |
<label for=""> |
| 157 |
<?php esc_attr_e( 'Label', 'supportcandy' ); ?> |
| 158 |
<span class="required-char">*</span> |
| 159 |
</label> |
| 160 |
</div> |
| 161 |
<input id="label" type="text" name="label" autocomplete="off"> |
| 162 |
</div> |
| 163 |
|
| 164 |
<table id="wpsc_add_agent_role"> |
| 165 |
<thead> |
| 166 |
<tr> |
| 167 |
<th><?php esc_attr_e( 'Capability', 'supportcandy' ); ?></th> |
| 168 |
<th style="padding: 10px;"><input type="checkbox" id="wpsc-all-una"><?php esc_attr_e( 'Unassigned', 'supportcandy' ); ?></th> |
| 169 |
<th style="padding: 10px;"><input type="checkbox" id="wpsc-all-ame"><?php esc_attr_e( 'Assigned to me', 'supportcandy' ); ?></th> |
| 170 |
<th style="padding: 10px;"><input type="checkbox" id="wpsc-all-ao"><?php esc_attr_e( 'Assigned to others', 'supportcandy' ); ?></th> |
| 171 |
</tr> |
| 172 |
</thead> |
| 173 |
|
| 174 |
<tbody> |
| 175 |
<tr> |
| 176 |
<td><label for=""><?php esc_attr_e( 'View Tickets', 'supportcandy' ); ?></label></td> |
| 177 |
<td><input name="caps[]" type="checkbox" value="view-unassigned" class="wpsc-una"></td> |
| 178 |
<td><input name="caps[]" type="checkbox" value="view-assigned-me" class="wpsc-ame"></td> |
| 179 |
<td><input name="caps[]" type="checkbox" value="view-assigned-others" class="wpsc-ao"></td> |
| 180 |
</tr> |
| 181 |
|
| 182 |
<tr> |
| 183 |
<td><label for=""><?php esc_attr_e( 'Reply Tickets', 'supportcandy' ); ?></label></td> |
| 184 |
<td><input name="caps[]" type="checkbox" value="reply-unassigned" class="wpsc-una"></td> |
| 185 |
<td><input name="caps[]" type="checkbox" value="reply-assigned-me" class="wpsc-ame"></td> |
| 186 |
<td><input name="caps[]" type="checkbox" value="reply-assigned-others" class="wpsc-ao"></td> |
| 187 |
</tr> |
| 188 |
|
| 189 |
<tr> |
| 190 |
<td><label for=""><?php esc_attr_e( 'Private Notes', 'supportcandy' ); ?></label></td> |
| 191 |
<td><input name="caps[]" type="checkbox" value="pn-unassigned" class="wpsc-una"></td> |
| 192 |
<td><input name="caps[]" type="checkbox" value="pn-assigned-me" class="wpsc-ame"></td> |
| 193 |
<td><input name="caps[]" type="checkbox" value="pn-assigned-others" class="wpsc-ao"></td> |
| 194 |
</tr> |
| 195 |
|
| 196 |
<tr> |
| 197 |
<td><label for=""><?php esc_attr_e( 'Duplicate Ticket', 'supportcandy' ); ?></label></td> |
| 198 |
<td><input name="caps[]" type="checkbox" value="dt-unassigned" class="wpsc-una"></td> |
| 199 |
<td><input name="caps[]" type="checkbox" value="dt-assigned-me" class="wpsc-ame"></td> |
| 200 |
<td><input name="caps[]" type="checkbox" value="dt-assigned-others" class="wpsc-ao"></td> |
| 201 |
</tr> |
| 202 |
|
| 203 |
<tr> |
| 204 |
<td><label for=""><?php esc_attr_e( 'Assign Agents', 'supportcandy' ); ?></label></td> |
| 205 |
<td><input name="caps[]" type="checkbox" value="aa-unassigned" class="wpsc-una"></td> |
| 206 |
<td><input name="caps[]" type="checkbox" value="aa-assigned-me" class="wpsc-ame"></td> |
| 207 |
<td><input name="caps[]" type="checkbox" value="aa-assigned-others" class="wpsc-ao"></td> |
| 208 |
</tr> |
| 209 |
|
| 210 |
<tr> |
| 211 |
<td><label for=""><?php esc_attr_e( 'Change Status', 'supportcandy' ); ?></label></td> |
| 212 |
<td><input name="caps[]" type="checkbox" value="cs-unassigned" class="wpsc-una"></td> |
| 213 |
<td><input name="caps[]" type="checkbox" value="cs-assigned-me" class="wpsc-ame"></td> |
| 214 |
<td><input name="caps[]" type="checkbox" value="cs-assigned-others" class="wpsc-ao"></td> |
| 215 |
</tr> |
| 216 |
|
| 217 |
<tr> |
| 218 |
<td><label for=""><?php esc_attr_e( 'Change Ticket Fields', 'supportcandy' ); ?></label></td> |
| 219 |
<td><input name="caps[]" type="checkbox" value="ctf-unassigned" class="wpsc-una"></td> |
| 220 |
<td><input name="caps[]" type="checkbox" value="ctf-assigned-me" class="wpsc-ame"></td> |
| 221 |
<td><input name="caps[]" type="checkbox" value="ctf-assigned-others" class="wpsc-ao"></td> |
| 222 |
</tr> |
| 223 |
|
| 224 |
<tr> |
| 225 |
<td><label for=""><?php esc_attr_e( 'Change Agent Only Fields', 'supportcandy' ); ?></label></td> |
| 226 |
<td><input name="caps[]" type="checkbox" value="caof-unassigned" class="wpsc-una"></td> |
| 227 |
<td><input name="caps[]" type="checkbox" value="caof-assigned-me" class="wpsc-ame"></td> |
| 228 |
<td><input name="caps[]" type="checkbox" value="caof-assigned-others" class="wpsc-ao"></td> |
| 229 |
</tr> |
| 230 |
|
| 231 |
<tr> |
| 232 |
<td><label for=""><?php esc_attr_e( 'Change Raised By', 'supportcandy' ); ?></label></td> |
| 233 |
<td><input name="caps[]" type="checkbox" value="crb-unassigned" class="wpsc-una"></td> |
| 234 |
<td><input name="caps[]" type="checkbox" value="crb-assigned-me" class="wpsc-ame"></td> |
| 235 |
<td><input name="caps[]" type="checkbox" value="crb-assigned-others" class="wpsc-ao"></td> |
| 236 |
</tr> |
| 237 |
|
| 238 |
<tr> |
| 239 |
<td><label for=""><?php esc_attr_e( 'Modify Additional Recipients', 'supportcandy' ); ?></label></td> |
| 240 |
<td><input name="caps[]" type="checkbox" value="ar-unassigned" class="wpsc-una"></td> |
| 241 |
<td><input name="caps[]" type="checkbox" value="ar-assigned-me" class="wpsc-ame"></td> |
| 242 |
<td><input name="caps[]" type="checkbox" value="ar-assigned-others" class="wpsc-ao"></td> |
| 243 |
</tr> |
| 244 |
|
| 245 |
<tr> |
| 246 |
<td><label for=""><?php esc_attr_e( 'Edit Threads', 'supportcandy' ); ?></label></td> |
| 247 |
<td><input name="caps[]" type="checkbox" value="eth-unassigned" class="wpsc-una"></td> |
| 248 |
<td><input name="caps[]" type="checkbox" value="eth-assigned-me" class="wpsc-ame"></td> |
| 249 |
<td><input name="caps[]" type="checkbox" value="eth-assigned-others" class="wpsc-ao"></td> |
| 250 |
</tr> |
| 251 |
|
| 252 |
<tr> |
| 253 |
<td><label for=""><?php esc_attr_e( 'Delete Threads', 'supportcandy' ); ?></label></td> |
| 254 |
<td><input name="caps[]" type="checkbox" value="dth-unassigned" class="wpsc-una"></td> |
| 255 |
<td><input name="caps[]" type="checkbox" value="dth-assigned-me" class="wpsc-ame"></td> |
| 256 |
<td><input name="caps[]" type="checkbox" value="dth-assigned-others" class="wpsc-ao"></td> |
| 257 |
</tr> |
| 258 |
|
| 259 |
<tr> |
| 260 |
<td><label for=""><?php esc_attr_e( 'View Logs', 'supportcandy' ); ?></label></td> |
| 261 |
<td><input name="caps[]" type="checkbox" value="vl-unassigned" class="wpsc-una"></td> |
| 262 |
<td><input name="caps[]" type="checkbox" value="vl-assigned-me" class="wpsc-ame"></td> |
| 263 |
<td><input name="caps[]" type="checkbox" value="vl-assigned-others" class="wpsc-ao"></td> |
| 264 |
</tr> |
| 265 |
|
| 266 |
<tr> |
| 267 |
<td><label for=""><?php esc_attr_e( 'Delete Ticket', 'supportcandy' ); ?></label></td> |
| 268 |
<td><input name="caps[]" type="checkbox" value="dtt-unassigned" class="wpsc-una"></td> |
| 269 |
<td><input name="caps[]" type="checkbox" value="dtt-assigned-me" class="wpsc-ame"></td> |
| 270 |
<td><input name="caps[]" type="checkbox" value="dtt-assigned-others" class="wpsc-ao"></td> |
| 271 |
</tr> |
| 272 |
|
| 273 |
<tr> |
| 274 |
<td><label for=""><?php esc_attr_e( 'Modify Tags', 'supportcandy' ); ?></label></td> |
| 275 |
<td><input name="caps[]" type="checkbox" value="tt-unassigned" class="wpsc-una"></td> |
| 276 |
<td><input name="caps[]" type="checkbox" value="tt-assigned-me" class="wpsc-ame"></td> |
| 277 |
<td><input name="caps[]" type="checkbox" value="tt-assigned-others" class="wpsc-ao"></td> |
| 278 |
</tr> |
| 279 |
|
| 280 |
<tr> |
| 281 |
<td><label for=""><?php esc_attr_e( 'Archive tickets', 'supportcandy' ); ?></label></td> |
| 282 |
<td><input name="caps[]" type="checkbox" value="at-unassigned" class="wpsc-una"></td> |
| 283 |
<td><input name="caps[]" type="checkbox" value="at-assigned-me" class="wpsc-ame"></td> |
| 284 |
<td><input name="caps[]" type="checkbox" value="at-assigned-others" class="wpsc-ao"></td> |
| 285 |
</tr> |
| 286 |
|
| 287 |
<?php do_action( 'wpsc_add_agent_role_ticket_permissions' ); ?> |
| 288 |
</tbody> |
| 289 |
</table> |
| 290 |
|
| 291 |
<div class="wpsc-input-group" style="margin-top: 20px;"> |
| 292 |
<div class="label-container"> |
| 293 |
<label for=""><?php esc_attr_e( 'Other permissions', 'supportcandy' ); ?></label> |
| 294 |
</div> |
| 295 |
<div class="checkbox-group"> |
| 296 |
<div> |
| 297 |
<input name="caps[]" type="checkbox" value="backend-access"> |
| 298 |
<span><?php esc_attr_e( 'WP dashboard access', 'supportcandy' ); ?></span> |
| 299 |
</div> |
| 300 |
<div> |
| 301 |
<input name="caps[]" type="checkbox" value="create-as"> |
| 302 |
<span><?php esc_attr_e( 'Create ticket on others behalf', 'supportcandy' ); ?></span> |
| 303 |
</div> |
| 304 |
<div> |
| 305 |
<input name="caps[]" type="checkbox" value="dtt-access"> |
| 306 |
<span><?php esc_attr_e( 'Deleted filter access', 'supportcandy' ); ?></span> |
| 307 |
</div> |
| 308 |
<div> |
| 309 |
<input name="caps[]" type="checkbox" value="eci-access"> |
| 310 |
<span><?php esc_attr_e( 'Edit customer info', 'supportcandy' ); ?></span> |
| 311 |
</div> |
| 312 |
<div> |
| 313 |
<input name="caps[]" type="checkbox" value="dash-access"> |
| 314 |
<span><?php esc_attr_e( 'Dashboard access', 'supportcandy' ); ?></span> |
| 315 |
</div> |
| 316 |
<div> |
| 317 |
<input name="caps[]" type="checkbox" value="at-access"> |
| 318 |
<span><?php esc_attr_e( 'Archive ticket access', 'supportcandy' ); ?></span> |
| 319 |
</div> |
| 320 |
<div> |
| 321 |
<input name="caps[]" type="checkbox" value="at-delete-access"> |
| 322 |
<span><?php esc_attr_e( 'Archive ticket Permanent delete access', 'supportcandy' ); ?></span> |
| 323 |
</div> |
| 324 |
<?php do_action( 'wpsc_add_agent_role_other_permissions' ); ?> |
| 325 |
</div> |
| 326 |
</div> |
| 327 |
<input type="hidden" name="action" value="wpsc_set_add_agent_role"> |
| 328 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_add_agent_role' ) ); ?>"> |
| 329 |
</form> |
| 330 |
|
| 331 |
<button class="wpsc-button small primary" onclick="wpsc_set_add_agent_role(this);"> |
| 332 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?> |
| 333 |
</button> |
| 334 |
<button class="wpsc-button small secondary" onclick="wpsc_get_agent_roles();"> |
| 335 |
<?php esc_attr_e( 'Cancel', 'supportcandy' ); ?> |
| 336 |
</button> |
| 337 |
|
| 338 |
<script> |
| 339 |
// check all unassigned action. |
| 340 |
jQuery('#wpsc-all-una').change(function () { |
| 341 |
if( jQuery(this).is(':checked') ) { |
| 342 |
jQuery(".wpsc-una").prop('checked','checked'); |
| 343 |
} else { |
| 344 |
jQuery(".wpsc-una").removeAttr('checked'); |
| 345 |
} |
| 346 |
}); |
| 347 |
jQuery(".wpsc-una").change(function() { |
| 348 |
if( jQuery('.wpsc-una:checked').length == jQuery('.wpsc-una').length ) { |
| 349 |
jQuery('#wpsc-all-una').prop('checked','checked'); |
| 350 |
}else { |
| 351 |
jQuery('#wpsc-all-una').removeAttr('checked'); |
| 352 |
} |
| 353 |
}) |
| 354 |
|
| 355 |
// check all assigned me action. |
| 356 |
jQuery('#wpsc-all-ame').change(function () { |
| 357 |
if( jQuery(this).is(':checked') ) { |
| 358 |
jQuery(".wpsc-ame").prop('checked','checked'); |
| 359 |
} else { |
| 360 |
jQuery(".wpsc-ame").removeAttr('checked'); |
| 361 |
} |
| 362 |
}); |
| 363 |
jQuery(".wpsc-ame").change(function() { |
| 364 |
if( jQuery('.wpsc-ame:checked').length == jQuery('.wpsc-ame').length ) { |
| 365 |
jQuery('#wpsc-all-ame').prop('checked','checked'); |
| 366 |
}else { |
| 367 |
jQuery('#wpsc-all-ame').removeAttr('checked'); |
| 368 |
} |
| 369 |
}) |
| 370 |
|
| 371 |
// check all assigned to other action. |
| 372 |
jQuery('#wpsc-all-ao').change(function () { |
| 373 |
if( jQuery(this).is(':checked') ) { |
| 374 |
jQuery(".wpsc-ao").prop('checked','checked'); |
| 375 |
} else { |
| 376 |
jQuery(".wpsc-ao").removeAttr('checked'); |
| 377 |
} |
| 378 |
}); |
| 379 |
jQuery(".wpsc-ao").change(function() { |
| 380 |
if( jQuery('.wpsc-ao:checked').length == jQuery('.wpsc-ao').length ) { |
| 381 |
jQuery('#wpsc-all-ao').prop('checked','checked'); |
| 382 |
}else { |
| 383 |
jQuery('#wpsc-all-ao').removeAttr('checked'); |
| 384 |
} |
| 385 |
}) |
| 386 |
|
| 387 |
jQuery('#wpsc_add_agent_role').DataTable({ |
| 388 |
ordering: false, |
| 389 |
pageLength: 20, |
| 390 |
bLengthChange: false, |
| 391 |
columnDefs: [ |
| 392 |
{ targets: -1, searchable: false }, |
| 393 |
{ targets: '_all', className: 'dt-left' } |
| 394 |
], |
| 395 |
language: supportcandy.translations.datatables, |
| 396 |
bPaginate: false, |
| 397 |
bInfo: false, |
| 398 |
}); |
| 399 |
</script> |
| 400 |
<?php |
| 401 |
wp_die(); |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* Set add agent role |
| 406 |
* |
| 407 |
* @return void |
| 408 |
*/ |
| 409 |
public static function set_add_agent_role() { |
| 410 |
|
| 411 |
if ( check_ajax_referer( 'wpsc_set_add_agent_role', '_ajax_nonce', false ) != 1 ) { |
| 412 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 413 |
} |
| 414 |
|
| 415 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 416 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 417 |
} |
| 418 |
|
| 419 |
$label = isset( $_POST['label'] ) ? sanitize_text_field( wp_unslash( $_POST['label'] ) ) : ''; |
| 420 |
if ( ! $label ) { |
| 421 |
wp_die( 'Label not available' ); |
| 422 |
} |
| 423 |
|
| 424 |
$caps = isset( $_POST['caps'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['caps'] ) ) ) : array(); |
| 425 |
if ( ! $caps ) { |
| 426 |
wp_die( 'caps not found' ); |
| 427 |
} |
| 428 |
|
| 429 |
$roles = get_option( 'wpsc-agent-roles' ); |
| 430 |
|
| 431 |
$roles[] = apply_filters( |
| 432 |
'wpsc_set_add_agent_role', |
| 433 |
array( |
| 434 |
'label' => $label, |
| 435 |
'caps' => array( |
| 436 |
'backend-access' => in_array( 'backend-access', $caps ) ? true : false, |
| 437 |
'create-as' => in_array( 'create-as', $caps ) ? true : false, |
| 438 |
'view-unassigned' => in_array( 'view-unassigned', $caps ) ? true : false, |
| 439 |
'view-assigned-me' => in_array( 'view-assigned-me', $caps ) ? true : false, |
| 440 |
'view-assigned-others' => in_array( 'view-assigned-others', $caps ) ? true : false, |
| 441 |
'reply-unassigned' => in_array( 'reply-unassigned', $caps ) ? true : false, |
| 442 |
'reply-assigned-me' => in_array( 'reply-assigned-me', $caps ) ? true : false, |
| 443 |
'reply-assigned-others' => in_array( 'reply-assigned-others', $caps ) ? true : false, |
| 444 |
'pn-unassigned' => in_array( 'pn-unassigned', $caps ) ? true : false, |
| 445 |
'pn-assigned-me' => in_array( 'pn-assigned-me', $caps ) ? true : false, |
| 446 |
'pn-assigned-others' => in_array( 'pn-assigned-others', $caps ) ? true : false, |
| 447 |
'aa-unassigned' => in_array( 'aa-unassigned', $caps ) ? true : false, |
| 448 |
'aa-assigned-me' => in_array( 'aa-assigned-me', $caps ) ? true : false, |
| 449 |
'aa-assigned-others' => in_array( 'aa-assigned-others', $caps ) ? true : false, |
| 450 |
'cs-unassigned' => in_array( 'cs-unassigned', $caps ) ? true : false, |
| 451 |
'cs-assigned-me' => in_array( 'cs-assigned-me', $caps ) ? true : false, |
| 452 |
'cs-assigned-others' => in_array( 'cs-assigned-others', $caps ) ? true : false, |
| 453 |
'ctf-unassigned' => in_array( 'ctf-unassigned', $caps ) ? true : false, |
| 454 |
'ctf-assigned-me' => in_array( 'ctf-assigned-me', $caps ) ? true : false, |
| 455 |
'ctf-assigned-others' => in_array( 'ctf-assigned-others', $caps ) ? true : false, |
| 456 |
'caof-unassigned' => in_array( 'caof-unassigned', $caps ) ? true : false, |
| 457 |
'caof-assigned-me' => in_array( 'caof-assigned-me', $caps ) ? true : false, |
| 458 |
'caof-assigned-others' => in_array( 'caof-assigned-others', $caps ) ? true : false, |
| 459 |
'crb-unassigned' => in_array( 'crb-unassigned', $caps ) ? true : false, |
| 460 |
'crb-assigned-me' => in_array( 'crb-assigned-me', $caps ) ? true : false, |
| 461 |
'crb-assigned-others' => in_array( 'crb-assigned-others', $caps ) ? true : false, |
| 462 |
'eth-unassigned' => in_array( 'eth-unassigned', $caps ) ? true : false, |
| 463 |
'eth-assigned-me' => in_array( 'eth-assigned-me', $caps ) ? true : false, |
| 464 |
'eth-assigned-others' => in_array( 'eth-assigned-others', $caps ) ? true : false, |
| 465 |
'dth-unassigned' => in_array( 'dth-unassigned', $caps ) ? true : false, |
| 466 |
'dth-assigned-me' => in_array( 'dth-assigned-me', $caps ) ? true : false, |
| 467 |
'dth-assigned-others' => in_array( 'dth-assigned-others', $caps ) ? true : false, |
| 468 |
'vl-unassigned' => in_array( 'vl-unassigned', $caps ) ? true : false, |
| 469 |
'vl-assigned-me' => in_array( 'vl-assigned-me', $caps ) ? true : false, |
| 470 |
'vl-assigned-others' => in_array( 'vl-assigned-others', $caps ) ? true : false, |
| 471 |
'dtt-unassigned' => in_array( 'dtt-unassigned', $caps ) ? true : false, |
| 472 |
'dtt-assigned-me' => in_array( 'dtt-assigned-me', $caps ) ? true : false, |
| 473 |
'dtt-assigned-others' => in_array( 'dtt-assigned-others', $caps ) ? true : false, |
| 474 |
'dtt-access' => in_array( 'dtt-access', $caps ) ? true : false, |
| 475 |
'dt-unassigned' => in_array( 'dt-unassigned', $caps ) ? true : false, |
| 476 |
'dt-assigned-me' => in_array( 'dt-assigned-me', $caps ) ? true : false, |
| 477 |
'dt-assigned-others' => in_array( 'dt-assigned-others', $caps ) ? true : false, |
| 478 |
'ar-unassigned' => in_array( 'ar-unassigned', $caps ) ? true : false, |
| 479 |
'ar-assigned-me' => in_array( 'ar-assigned-me', $caps ) ? true : false, |
| 480 |
'ar-assigned-others' => in_array( 'ar-assigned-others', $caps ) ? true : false, |
| 481 |
'eci-access' => in_array( 'eci-access', $caps ) ? true : false, |
| 482 |
'dash-access' => in_array( 'dash-access', $caps ) ? true : false, |
| 483 |
'tt-unassigned' => in_array( 'tt-unassigned', $caps ) ? true : false, |
| 484 |
'tt-assigned-me' => in_array( 'tt-assigned-me', $caps ) ? true : false, |
| 485 |
'tt-assigned-others' => in_array( 'tt-assigned-others', $caps ) ? true : false, |
| 486 |
'at-unassigned' => in_array( 'at-unassigned', $caps ) ? true : false, |
| 487 |
'at-assigned-me' => in_array( 'at-assigned-me', $caps ) ? true : false, |
| 488 |
'at-assigned-others' => in_array( 'at-assigned-others', $caps ) ? true : false, |
| 489 |
'at-access' => in_array( 'at-access', $caps ) ? true : false, |
| 490 |
'at-delete-access' => in_array( 'at-delete-access', $caps ) ? true : false, |
| 491 |
|
| 492 |
), |
| 493 |
), |
| 494 |
$caps |
| 495 |
); |
| 496 |
|
| 497 |
update_option( 'wpsc-agent-roles', $roles ); |
| 498 |
|
| 499 |
do_action( 'wpsc_after_add_agent_role', array_key_last( $roles ) ); |
| 500 |
wp_die(); |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* Clone existing agent role. |
| 505 |
* |
| 506 |
* @return void |
| 507 |
*/ |
| 508 |
public static function get_clone_agent_role() { |
| 509 |
|
| 510 |
if ( check_ajax_referer( 'wpsc_get_clone_agent_role', '_ajax_nonce', false ) != 1 ) { |
| 511 |
wp_send_json_error( 'Unauthorized request!', 400 ); |
| 512 |
} |
| 513 |
|
| 514 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 515 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 516 |
} |
| 517 |
|
| 518 |
$id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; |
| 519 |
if ( ! $id ) { |
| 520 |
wp_send_json_error( 'Incorrect request!', 400 ); |
| 521 |
} |
| 522 |
|
| 523 |
$roles = get_option( 'wpsc-agent-roles', array() ); |
| 524 |
$roles[] = array( |
| 525 |
'label' => $roles[ $id ]['label'] . ' clone', |
| 526 |
'caps' => $roles[ $id ]['caps'], |
| 527 |
); |
| 528 |
|
| 529 |
update_option( 'wpsc-agent-roles', $roles ); |
| 530 |
|
| 531 |
do_action( 'wpsc_after_clone_agent_role', array_key_last( $roles ), $id ); |
| 532 |
|
| 533 |
wp_die(); |
| 534 |
} |
| 535 |
|
| 536 |
/** |
| 537 |
* Edit agent role UI |
| 538 |
* |
| 539 |
* @return void |
| 540 |
*/ |
| 541 |
public static function get_edit_agent_role() { |
| 542 |
|
| 543 |
if ( check_ajax_referer( 'wpsc_get_edit_agent_role', '_ajax_nonce', false ) != 1 ) { |
| 544 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 545 |
} |
| 546 |
|
| 547 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 548 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 549 |
} |
| 550 |
|
| 551 |
$role_id = isset( $_POST['role_id'] ) ? intval( $_POST['role_id'] ) : 0; |
| 552 |
if ( ! $role_id ) { |
| 553 |
wp_die( 'role_id not found!' ); |
| 554 |
} |
| 555 |
|
| 556 |
$roles = get_option( 'wpsc-agent-roles', array() ); |
| 557 |
$role = isset( $roles[ $role_id ] ) ? $roles[ $role_id ] : array(); |
| 558 |
if ( ! $role ) { |
| 559 |
wp_die( 'Role not available!' ); |
| 560 |
} |
| 561 |
|
| 562 |
?> |
| 563 |
<form action="#" onsubmit="return false;" class="frm-edit-agent-role"> |
| 564 |
|
| 565 |
<div class="wpsc-input-group"> |
| 566 |
<div class="label-container"> |
| 567 |
<label for=""> |
| 568 |
<?php esc_attr_e( 'Label', 'supportcandy' ); ?> |
| 569 |
<span class="required-char">*</span> |
| 570 |
</label> |
| 571 |
</div> |
| 572 |
<input id="label" type="text" name="label" autocomplete="off" value="<?php echo esc_attr( $role['label'] ); ?>"> |
| 573 |
</div> |
| 574 |
|
| 575 |
<table id="wpsc_edit_agent_role"> |
| 576 |
<thead> |
| 577 |
<tr> |
| 578 |
<th><?php esc_attr_e( 'Capability', 'supportcandy' ); ?></th> |
| 579 |
<th style="padding: 10px;"><input type="checkbox" id="wpsc-all-una"><?php esc_attr_e( 'Unassigned', 'supportcandy' ); ?></th> |
| 580 |
<th style="padding: 10px;"><input type="checkbox" id="wpsc-all-ame"><?php esc_attr_e( 'Assigned to me', 'supportcandy' ); ?></th> |
| 581 |
<th style="padding: 10px;"><input type="checkbox" id="wpsc-all-ao"><?php esc_attr_e( 'Assigned to others', 'supportcandy' ); ?></th> |
| 582 |
</tr> |
| 583 |
</thead> |
| 584 |
<tbody> |
| 585 |
<tr> |
| 586 |
<td><label for=""><?php esc_attr_e( 'View Tickets', 'supportcandy' ); ?></label></td> |
| 587 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['view-unassigned'], 1 ); ?> value="view-unassigned" class="wpsc-una"></td> |
| 588 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['view-assigned-me'], 1 ); ?> value="view-assigned-me" class="wpsc-ame"></td> |
| 589 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['view-assigned-others'], 1 ); ?> value="view-assigned-others" class="wpsc-ao"></td> |
| 590 |
</tr> |
| 591 |
|
| 592 |
<tr> |
| 593 |
<td><label for=""><?php esc_attr_e( 'Reply Tickets', 'supportcandy' ); ?></label></td> |
| 594 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['reply-unassigned'], 1 ); ?> value="reply-unassigned" class="wpsc-una"></td> |
| 595 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['reply-assigned-me'], 1 ); ?> value="reply-assigned-me" class="wpsc-ame"></td> |
| 596 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['reply-assigned-others'], 1 ); ?> value="reply-assigned-others" class="wpsc-ao"></td> |
| 597 |
</tr> |
| 598 |
|
| 599 |
<tr> |
| 600 |
<td><label for=""><?php esc_attr_e( 'Private Notes', 'supportcandy' ); ?></label></td> |
| 601 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['pn-unassigned'], 1 ); ?> value="pn-unassigned" class="wpsc-una"></td> |
| 602 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['pn-assigned-me'], 1 ); ?> value="pn-assigned-me" class="wpsc-ame"></td> |
| 603 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['pn-assigned-others'], 1 ); ?> value="pn-assigned-others" class="wpsc-ao"></td> |
| 604 |
</tr> |
| 605 |
|
| 606 |
<tr> |
| 607 |
<td><label for=""><?php esc_attr_e( 'Duplicate Ticket', 'supportcandy' ); ?></label></td> |
| 608 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dt-unassigned'], 1 ); ?> value="dt-unassigned" class="wpsc-una"></td> |
| 609 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dt-assigned-me'], 1 ); ?> value="dt-assigned-me" class="wpsc-ame"></td> |
| 610 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dt-assigned-others'], 1 ); ?> value="dt-assigned-others" class="wpsc-ao"></td> |
| 611 |
</tr> |
| 612 |
|
| 613 |
<tr> |
| 614 |
<td><label for=""><?php esc_attr_e( 'Assign Agents', 'supportcandy' ); ?></label></td> |
| 615 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['aa-unassigned'], 1 ); ?> value="aa-unassigned" class="wpsc-una"></td> |
| 616 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['aa-assigned-me'], 1 ); ?> value="aa-assigned-me" class="wpsc-ame"></td> |
| 617 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['aa-assigned-others'], 1 ); ?> value="aa-assigned-others" class="wpsc-ao"></td> |
| 618 |
</tr> |
| 619 |
|
| 620 |
<tr> |
| 621 |
<td><label for=""><?php esc_attr_e( 'Change Status', 'supportcandy' ); ?></label></td> |
| 622 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['cs-unassigned'], 1 ); ?> value="cs-unassigned" class="wpsc-una"></td> |
| 623 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['cs-assigned-me'], 1 ); ?> value="cs-assigned-me" class="wpsc-ame"></td> |
| 624 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['cs-assigned-others'], 1 ); ?> value="cs-assigned-others" class="wpsc-ao"></td> |
| 625 |
</tr> |
| 626 |
|
| 627 |
<tr> |
| 628 |
<td><label for=""><?php esc_attr_e( 'Change Ticket Fields', 'supportcandy' ); ?></label></td> |
| 629 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['ctf-unassigned'], 1 ); ?> value="ctf-unassigned" class="wpsc-una"></td> |
| 630 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['ctf-assigned-me'], 1 ); ?> value="ctf-assigned-me" class="wpsc-ame"></td> |
| 631 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['ctf-assigned-others'], 1 ); ?> value="ctf-assigned-others" class="wpsc-ao"></td> |
| 632 |
</tr> |
| 633 |
|
| 634 |
<tr> |
| 635 |
<td><label for=""><?php esc_attr_e( 'Change Agent Only Fields', 'supportcandy' ); ?></label></td> |
| 636 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['caof-unassigned'], 1 ); ?> value="caof-unassigned" class="wpsc-una"></td> |
| 637 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['caof-assigned-me'], 1 ); ?> value="caof-assigned-me" class="wpsc-ame"></td> |
| 638 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['caof-assigned-others'], 1 ); ?> value="caof-assigned-others" class="wpsc-ao"></td> |
| 639 |
</tr> |
| 640 |
|
| 641 |
<tr> |
| 642 |
<td><label for=""><?php esc_attr_e( 'Change Raised By', 'supportcandy' ); ?></label></td> |
| 643 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['crb-unassigned'], 1 ); ?> value="crb-unassigned" class="wpsc-una"></td> |
| 644 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['crb-assigned-me'], 1 ); ?> value="crb-assigned-me" class="wpsc-ame"></td> |
| 645 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['crb-assigned-others'], 1 ); ?> value="crb-assigned-others" class="wpsc-ao"></td> |
| 646 |
</tr> |
| 647 |
|
| 648 |
<tr> |
| 649 |
<td><label for=""><?php esc_attr_e( 'Modify Additional Recipients', 'supportcandy' ); ?></label></td> |
| 650 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['ar-unassigned'], 1 ); ?> value="ar-unassigned" class="wpsc-una"></td> |
| 651 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['ar-assigned-me'], 1 ); ?> value="ar-assigned-me" class="wpsc-ame"></td> |
| 652 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['ar-assigned-others'], 1 ); ?> value="ar-assigned-others" class="wpsc-ao"></td> |
| 653 |
</tr> |
| 654 |
|
| 655 |
<tr> |
| 656 |
<td><label for=""><?php esc_attr_e( 'Edit Threads', 'supportcandy' ); ?></label></td> |
| 657 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['eth-unassigned'], 1 ); ?> value="eth-unassigned" class="wpsc-una"></td> |
| 658 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['eth-assigned-me'], 1 ); ?> value="eth-assigned-me" class="wpsc-ame"></td> |
| 659 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['eth-assigned-others'], 1 ); ?> value="eth-assigned-others" class="wpsc-ao"></td> |
| 660 |
</tr> |
| 661 |
|
| 662 |
<tr> |
| 663 |
<td><label for=""><?php esc_attr_e( 'Delete Threads', 'supportcandy' ); ?></label></td> |
| 664 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dth-unassigned'], 1 ); ?> value="dth-unassigned" class="wpsc-una"></td> |
| 665 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dth-assigned-me'], 1 ); ?> value="dth-assigned-me" class="wpsc-ame"></td> |
| 666 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dth-assigned-others'], 1 ); ?> value="dth-assigned-others" class="wpsc-ao"></td> |
| 667 |
</tr> |
| 668 |
|
| 669 |
<tr> |
| 670 |
<td><label for=""><?php esc_attr_e( 'View Logs', 'supportcandy' ); ?></label></td> |
| 671 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['vl-unassigned'], 1 ); ?> value="vl-unassigned" class="wpsc-una"></td> |
| 672 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['vl-assigned-me'], 1 ); ?> value="vl-assigned-me" class="wpsc-ame"></td> |
| 673 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['vl-assigned-others'], 1 ); ?> value="vl-assigned-others" class="wpsc-ao"></td> |
| 674 |
</tr> |
| 675 |
|
| 676 |
<tr> |
| 677 |
<td><label for=""><?php esc_attr_e( 'Delete Ticket', 'supportcandy' ); ?></label></td> |
| 678 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dtt-unassigned'], 1 ); ?> value="dtt-unassigned" class="wpsc-una"></td> |
| 679 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dtt-assigned-me'], 1 ); ?> value="dtt-assigned-me" class="wpsc-ame"></td> |
| 680 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['dtt-assigned-others'], 1 ); ?> value="dtt-assigned-others" class="wpsc-ao"></td> |
| 681 |
</tr> |
| 682 |
|
| 683 |
<tr> |
| 684 |
<td><label for=""><?php esc_attr_e( 'Modify Tags', 'supportcandy' ); ?></label></td> |
| 685 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['tt-unassigned'], 1 ); ?> value="tt-unassigned" class="wpsc-una"></td> |
| 686 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['tt-assigned-me'], 1 ); ?> value="tt-assigned-me" class="wpsc-ame"></td> |
| 687 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['tt-assigned-others'], 1 ); ?> value="tt-assigned-others" class="wpsc-ao"></td> |
| 688 |
</tr> |
| 689 |
|
| 690 |
<tr> |
| 691 |
<td><label for=""><?php esc_attr_e( 'Archive ticket', 'supportcandy' ); ?></label></td> |
| 692 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['at-unassigned'], 1 ); ?> value="at-unassigned" class="wpsc-una"></td> |
| 693 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['at-assigned-me'], 1 ); ?> value="at-assigned-me" class="wpsc-ame"></td> |
| 694 |
<td><input name="caps[]" type="checkbox" <?php checked( $role['caps']['at-assigned-others'], 1 ); ?> value="at-assigned-others" class="wpsc-ao"></td> |
| 695 |
</tr> |
| 696 |
<?php do_action( 'wpsc_edit_agent_role_ticket_permissions', $role ); ?> |
| 697 |
</tbody> |
| 698 |
</table> |
| 699 |
<div class="wpsc-input-group" style="margin-top: 20px;"> |
| 700 |
<div class="label-container"> |
| 701 |
<label for=""><?php esc_attr_e( 'Other permissions', 'supportcandy' ); ?></label> |
| 702 |
</div> |
| 703 |
<div class="checkbox-group"> |
| 704 |
<div> |
| 705 |
<input name="caps[]" type="checkbox" <?php checked( $role['caps']['backend-access'], 1 ); ?> value="backend-access"> |
| 706 |
<span><?php esc_attr_e( 'WP dashboard access', 'supportcandy' ); ?></span> |
| 707 |
</div> |
| 708 |
<div> |
| 709 |
<input name="caps[]" type="checkbox" <?php checked( $role['caps']['create-as'], 1 ); ?> value="create-as"> |
| 710 |
<span><?php esc_attr_e( 'Create ticket on others behalf', 'supportcandy' ); ?></span> |
| 711 |
</div> |
| 712 |
<div> |
| 713 |
<input name="caps[]" type="checkbox" <?php checked( $role['caps']['dtt-access'], 1 ); ?> value="dtt-access"> |
| 714 |
<span><?php esc_attr_e( 'Deleted filter access', 'supportcandy' ); ?></span> |
| 715 |
</div> |
| 716 |
<div> |
| 717 |
<input name="caps[]" type="checkbox" <?php checked( $role['caps']['eci-access'], 1 ); ?> value="eci-access"> |
| 718 |
<span><?php esc_attr_e( 'Edit customer info', 'supportcandy' ); ?></span> |
| 719 |
</div> |
| 720 |
<div> |
| 721 |
<input name="caps[]" type="checkbox" <?php checked( $role['caps']['dash-access'], 1 ); ?> value="dash-access"> |
| 722 |
<span><?php esc_attr_e( 'Dashboard access', 'supportcandy' ); ?></span> |
| 723 |
</div> |
| 724 |
<div> |
| 725 |
<input name="caps[]" type="checkbox" <?php checked( $role['caps']['at-access'], 1 ); ?> value="at-access"> |
| 726 |
<span><?php esc_attr_e( 'Archive ticket access', 'supportcandy' ); ?></span> |
| 727 |
</div> |
| 728 |
<div> |
| 729 |
<input name="caps[]" type="checkbox" <?php checked( $role['caps']['at-delete-access'], 1 ); ?> value="at-delete-access"> |
| 730 |
<span><?php esc_attr_e( 'Archive ticket Permanent delete access', 'supportcandy' ); ?></span> |
| 731 |
</div> |
| 732 |
<?php do_action( 'wpsc_edit_agent_role_other_permissions', $role ); ?> |
| 733 |
</div> |
| 734 |
</div> |
| 735 |
<input type="hidden" name="role_id" value="<?php echo esc_attr( $role_id ); ?>"> |
| 736 |
<input type="hidden" name="action" value="wpsc_set_edit_agent_role"> |
| 737 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_edit_agent_role' ) ); ?>"> |
| 738 |
</form> |
| 739 |
<button class="wpsc-button small primary" onclick="wpsc_set_edit_agent_role();"> |
| 740 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?> |
| 741 |
</button> |
| 742 |
<button class="wpsc-button small secondary" onclick="wpsc_get_agent_roles();"> |
| 743 |
<?php esc_attr_e( 'Cancel', 'supportcandy' ); ?> |
| 744 |
</button> |
| 745 |
|
| 746 |
<script> |
| 747 |
// check all unassigned action. |
| 748 |
jQuery('#wpsc-all-una').change(function () { |
| 749 |
if( jQuery(this).is(':checked') ) { |
| 750 |
jQuery(".wpsc-una").prop('checked','checked'); |
| 751 |
} else { |
| 752 |
jQuery(".wpsc-una").removeAttr('checked'); |
| 753 |
} |
| 754 |
}); |
| 755 |
jQuery(".wpsc-una").change(function() { |
| 756 |
if( jQuery('.wpsc-una:checked').length == jQuery('.wpsc-una').length ) { |
| 757 |
jQuery('#wpsc-all-una').prop('checked','checked'); |
| 758 |
}else { |
| 759 |
jQuery('#wpsc-all-una').removeAttr('checked'); |
| 760 |
} |
| 761 |
}); |
| 762 |
jQuery(".wpsc-una").trigger("change"); |
| 763 |
|
| 764 |
// check all assigned me action. |
| 765 |
jQuery('#wpsc-all-ame').change(function () { |
| 766 |
if( jQuery(this).is(':checked') ) { |
| 767 |
jQuery(".wpsc-ame").prop('checked','checked'); |
| 768 |
} else { |
| 769 |
jQuery(".wpsc-ame").removeAttr('checked'); |
| 770 |
} |
| 771 |
}); |
| 772 |
jQuery(".wpsc-ame").change(function() { |
| 773 |
if( jQuery('.wpsc-ame:checked').length == jQuery('.wpsc-ame').length ) { |
| 774 |
jQuery('#wpsc-all-ame').prop('checked','checked'); |
| 775 |
}else { |
| 776 |
jQuery('#wpsc-all-ame').removeAttr('checked'); |
| 777 |
} |
| 778 |
}); |
| 779 |
jQuery(".wpsc-ame").trigger('change'); |
| 780 |
|
| 781 |
// check all assigned to other action. |
| 782 |
jQuery('#wpsc-all-ao').change(function () { |
| 783 |
if( jQuery(this).is(':checked') ) { |
| 784 |
jQuery(".wpsc-ao").prop('checked','checked'); |
| 785 |
} else { |
| 786 |
jQuery(".wpsc-ao").removeAttr('checked'); |
| 787 |
} |
| 788 |
}); |
| 789 |
jQuery(".wpsc-ao").change(function() { |
| 790 |
if( jQuery('.wpsc-ao:checked').length == jQuery('.wpsc-ao').length ) { |
| 791 |
jQuery('#wpsc-all-ao').prop('checked','checked'); |
| 792 |
}else { |
| 793 |
jQuery('#wpsc-all-ao').removeAttr('checked'); |
| 794 |
} |
| 795 |
}); |
| 796 |
jQuery(".wpsc-ao").trigger('change'); |
| 797 |
|
| 798 |
jQuery('#wpsc_edit_agent_role').DataTable({ |
| 799 |
ordering: false, |
| 800 |
pageLength: 20, |
| 801 |
bLengthChange: false, |
| 802 |
columnDefs: [ |
| 803 |
{ targets: -1, searchable: false }, |
| 804 |
{ targets: '_all', className: 'dt-left' } |
| 805 |
], |
| 806 |
language: supportcandy.translations.datatables, |
| 807 |
bPaginate: false, |
| 808 |
bInfo: false, |
| 809 |
}); |
| 810 |
</script> |
| 811 |
<?php |
| 812 |
wp_die(); |
| 813 |
} |
| 814 |
|
| 815 |
/** |
| 816 |
* Set edit agent role |
| 817 |
* |
| 818 |
* @return void |
| 819 |
*/ |
| 820 |
public static function set_edit_agent_role() { |
| 821 |
|
| 822 |
if ( check_ajax_referer( 'wpsc_set_edit_agent_role', '_ajax_nonce', false ) != 1 ) { |
| 823 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 824 |
} |
| 825 |
|
| 826 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 827 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 828 |
} |
| 829 |
|
| 830 |
$role_id = isset( $_POST['role_id'] ) ? intval( $_POST['role_id'] ) : 0; |
| 831 |
if ( ! $role_id ) { |
| 832 |
wp_die( 'role_id not found!' ); |
| 833 |
} |
| 834 |
|
| 835 |
$roles = get_option( 'wpsc-agent-roles', array() ); |
| 836 |
$role = isset( $roles[ $role_id ] ) ? $roles[ $role_id ] : array(); |
| 837 |
if ( ! $role ) { |
| 838 |
wp_die( 'Role not available!' ); |
| 839 |
} |
| 840 |
|
| 841 |
$label = isset( $_POST['label'] ) ? sanitize_text_field( wp_unslash( $_POST['label'] ) ) : ''; |
| 842 |
if ( ! $label ) { |
| 843 |
wp_die( 'Label not available' ); |
| 844 |
} |
| 845 |
|
| 846 |
$caps = isset( $_POST['caps'] ) ? array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['caps'] ) ) ) : array(); |
| 847 |
if ( ! $caps ) { |
| 848 |
wp_die( 'caps not found' ); |
| 849 |
} |
| 850 |
|
| 851 |
$roles[ $role_id ] = apply_filters( |
| 852 |
'wpsc_set_edit_agent_role', |
| 853 |
array( |
| 854 |
'label' => $label, |
| 855 |
'caps' => array( |
| 856 |
'backend-access' => in_array( 'backend-access', $caps ) ? true : false, |
| 857 |
'create-as' => in_array( 'create-as', $caps ) ? true : false, |
| 858 |
'view-unassigned' => in_array( 'view-unassigned', $caps ) ? true : false, |
| 859 |
'view-assigned-me' => in_array( 'view-assigned-me', $caps ) ? true : false, |
| 860 |
'view-assigned-others' => in_array( 'view-assigned-others', $caps ) ? true : false, |
| 861 |
'reply-unassigned' => in_array( 'reply-unassigned', $caps ) ? true : false, |
| 862 |
'reply-assigned-me' => in_array( 'reply-assigned-me', $caps ) ? true : false, |
| 863 |
'reply-assigned-others' => in_array( 'reply-assigned-others', $caps ) ? true : false, |
| 864 |
'pn-unassigned' => in_array( 'pn-unassigned', $caps ) ? true : false, |
| 865 |
'pn-assigned-me' => in_array( 'pn-assigned-me', $caps ) ? true : false, |
| 866 |
'pn-assigned-others' => in_array( 'pn-assigned-others', $caps ) ? true : false, |
| 867 |
'aa-unassigned' => in_array( 'aa-unassigned', $caps ) ? true : false, |
| 868 |
'aa-assigned-me' => in_array( 'aa-assigned-me', $caps ) ? true : false, |
| 869 |
'aa-assigned-others' => in_array( 'aa-assigned-others', $caps ) ? true : false, |
| 870 |
'cs-unassigned' => in_array( 'cs-unassigned', $caps ) ? true : false, |
| 871 |
'cs-assigned-me' => in_array( 'cs-assigned-me', $caps ) ? true : false, |
| 872 |
'cs-assigned-others' => in_array( 'cs-assigned-others', $caps ) ? true : false, |
| 873 |
'ctf-unassigned' => in_array( 'ctf-unassigned', $caps ) ? true : false, |
| 874 |
'ctf-assigned-me' => in_array( 'ctf-assigned-me', $caps ) ? true : false, |
| 875 |
'ctf-assigned-others' => in_array( 'ctf-assigned-others', $caps ) ? true : false, |
| 876 |
'caof-unassigned' => in_array( 'caof-unassigned', $caps ) ? true : false, |
| 877 |
'caof-assigned-me' => in_array( 'caof-assigned-me', $caps ) ? true : false, |
| 878 |
'caof-assigned-others' => in_array( 'caof-assigned-others', $caps ) ? true : false, |
| 879 |
'crb-unassigned' => in_array( 'crb-unassigned', $caps ) ? true : false, |
| 880 |
'crb-assigned-me' => in_array( 'crb-assigned-me', $caps ) ? true : false, |
| 881 |
'crb-assigned-others' => in_array( 'crb-assigned-others', $caps ) ? true : false, |
| 882 |
'eth-unassigned' => in_array( 'eth-unassigned', $caps ) ? true : false, |
| 883 |
'eth-assigned-me' => in_array( 'eth-assigned-me', $caps ) ? true : false, |
| 884 |
'eth-assigned-others' => in_array( 'eth-assigned-others', $caps ) ? true : false, |
| 885 |
'dth-unassigned' => in_array( 'dth-unassigned', $caps ) ? true : false, |
| 886 |
'dth-assigned-me' => in_array( 'dth-assigned-me', $caps ) ? true : false, |
| 887 |
'dth-assigned-others' => in_array( 'dth-assigned-others', $caps ) ? true : false, |
| 888 |
'vl-unassigned' => in_array( 'vl-unassigned', $caps ) ? true : false, |
| 889 |
'vl-assigned-me' => in_array( 'vl-assigned-me', $caps ) ? true : false, |
| 890 |
'vl-assigned-others' => in_array( 'vl-assigned-others', $caps ) ? true : false, |
| 891 |
'dtt-unassigned' => in_array( 'dtt-unassigned', $caps ) ? true : false, |
| 892 |
'dtt-assigned-me' => in_array( 'dtt-assigned-me', $caps ) ? true : false, |
| 893 |
'dtt-assigned-others' => in_array( 'dtt-assigned-others', $caps ) ? true : false, |
| 894 |
'dtt-access' => in_array( 'dtt-access', $caps ) ? true : false, |
| 895 |
'dt-unassigned' => in_array( 'dt-unassigned', $caps ) ? true : false, |
| 896 |
'dt-assigned-me' => in_array( 'dt-assigned-me', $caps ) ? true : false, |
| 897 |
'dt-assigned-others' => in_array( 'dt-assigned-others', $caps ) ? true : false, |
| 898 |
'ar-unassigned' => in_array( 'ar-unassigned', $caps ) ? true : false, |
| 899 |
'ar-assigned-me' => in_array( 'ar-assigned-me', $caps ) ? true : false, |
| 900 |
'ar-assigned-others' => in_array( 'ar-assigned-others', $caps ) ? true : false, |
| 901 |
'eci-access' => in_array( 'eci-access', $caps ) ? true : false, |
| 902 |
'dash-access' => in_array( 'dash-access', $caps ) ? true : false, |
| 903 |
'tt-unassigned' => in_array( 'tt-unassigned', $caps ) ? true : false, |
| 904 |
'tt-assigned-me' => in_array( 'tt-assigned-me', $caps ) ? true : false, |
| 905 |
'tt-assigned-others' => in_array( 'tt-assigned-others', $caps ) ? true : false, |
| 906 |
'at-unassigned' => in_array( 'at-unassigned', $caps ) ? true : false, |
| 907 |
'at-assigned-me' => in_array( 'at-assigned-me', $caps ) ? true : false, |
| 908 |
'at-assigned-others' => in_array( 'at-assigned-others', $caps ) ? true : false, |
| 909 |
'at-access' => in_array( 'at-access', $caps ) ? true : false, |
| 910 |
'at-delete-access' => in_array( 'at-delete-access', $caps ) ? true : false, |
| 911 |
), |
| 912 |
), |
| 913 |
$role, |
| 914 |
$caps |
| 915 |
); |
| 916 |
|
| 917 |
// Update backend access user capabilities. |
| 918 |
if ( $role['caps']['backend-access'] !== $roles[ $role_id ]['caps']['backend-access'] ) { |
| 919 |
|
| 920 |
$response = WPSC_Agent::find( |
| 921 |
array( |
| 922 |
'items_per_page' => 0, |
| 923 |
'meta_query' => array( |
| 924 |
'relation' => 'AND', |
| 925 |
array( |
| 926 |
'slug' => 'role', |
| 927 |
'compare' => '=', |
| 928 |
'val' => $role_id, |
| 929 |
), |
| 930 |
array( |
| 931 |
'slug' => 'is_active', |
| 932 |
'compare' => '=', |
| 933 |
'val' => 1, |
| 934 |
), |
| 935 |
), |
| 936 |
) |
| 937 |
); |
| 938 |
foreach ( $response['results'] as $agent ) { |
| 939 |
|
| 940 |
if ( $roles[ $role_id ]['caps']['backend-access'] && ! $agent->user->has_cap( 'wpsc_agent' ) ) { |
| 941 |
$agent->user->add_cap( 'wpsc_agent' ); |
| 942 |
} |
| 943 |
|
| 944 |
if ( ! $roles[ $role_id ]['caps']['backend-access'] && $agent->user->has_cap( 'wpsc_agent' ) ) { |
| 945 |
$agent->user->remove_cap( 'wpsc_agent' ); |
| 946 |
} |
| 947 |
} |
| 948 |
} |
| 949 |
|
| 950 |
update_option( 'wpsc-agent-roles', $roles ); |
| 951 |
do_action( 'wpsc_agent_role_update', $role_id ); |
| 952 |
wp_die(); |
| 953 |
} |
| 954 |
|
| 955 |
/** |
| 956 |
* Delete agent role |
| 957 |
*/ |
| 958 |
public static function delete_agent_role() { |
| 959 |
|
| 960 |
if ( check_ajax_referer( 'wpsc_delete_agent_role', '_ajax_nonce', false ) != 1 ) { |
| 961 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 962 |
} |
| 963 |
|
| 964 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 965 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 966 |
} |
| 967 |
|
| 968 |
$role_id = isset( $_POST['role_id'] ) ? intval( $_POST['role_id'] ) : 0; |
| 969 |
if ( ! $role_id ) { |
| 970 |
wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 971 |
} |
| 972 |
|
| 973 |
$roles = get_option( 'wpsc-agent-roles', array() ); |
| 974 |
$role = isset( $roles[ $role_id ] ) ? $roles[ $role_id ] : array(); |
| 975 |
if ( ! $role ) { |
| 976 |
wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 977 |
} |
| 978 |
|
| 979 |
if ( $role_id <= 2 ) { |
| 980 |
wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); |
| 981 |
} |
| 982 |
|
| 983 |
$args = array( |
| 984 |
'meta_query' => array( |
| 985 |
'relation' => 'AND', |
| 986 |
array( |
| 987 |
'slug' => 'role', |
| 988 |
'compare' => '=', |
| 989 |
'val' => $role_id, |
| 990 |
), |
| 991 |
array( |
| 992 |
'slug' => 'is_active', |
| 993 |
'compare' => '=', |
| 994 |
'val' => 1, |
| 995 |
), |
| 996 |
), |
| 997 |
); |
| 998 |
$agents = WPSC_Agent::count( $args ); |
| 999 |
if ( $agents ) { |
| 1000 |
wp_send_json_error( 'The role can not be deleted if existing agents are associated with it!', 400 ); |
| 1001 |
} |
| 1002 |
|
| 1003 |
unset( $roles[ $role_id ] ); |
| 1004 |
do_action( 'wpsc_after_delete_agent_role', $role_id ); |
| 1005 |
update_option( 'wpsc-agent-roles', $roles ); |
| 1006 |
|
| 1007 |
wp_die(); |
| 1008 |
} |
| 1009 |
} |
| 1010 |
endif; |
| 1011 |
|
| 1012 |
WPSC_Agent_Roles::init(); |
| 1013 |
|