<?php
function wpcr_scripts_to_wpcfe( $scripts ){
	$scripts[] = 'ajax-receiving-script';
	return $scripts;
}
function wpcr_shipment_bulk_scanner(){
	?>
	<button class="bulk-barcode-scan btn btn-secondary btn-sm" data-toggle="modal" data-target="#wpcr-bulk-barcode-modal"><?php esc_html_e('Bulk Update', 'wpcargo-receiving'); ?></button>
	<?php
}
function wpcr_bulk_barcode_modal() {
	$current_user = wp_get_current_user();
	global $wpcargo;
	require_once( WPCARGO_RECEIVING_PATH.'/templates/bulk-barcode.tpl.php' );
}
function wpcr_receiver_roles(){
	$receiver_roles = array( 'wpcargo_employee', 'administrator' );
	return apply_filters( 'wpcr_receiver_roles', $receiver_roles );
}
function can_receive_wpcr(){
	$current_user 	= wp_get_current_user();
	$user_roles 	= $current_user->roles;
	if( !empty( array_intersect( $user_roles, wpcr_receiver_roles() ) ) ){
		return true;
	}
	return false;
}
function wpcr_restriction_message(){
	return esc_html__("Sorry you don't have enough permission to access this page.", 'wpcargo-receiving');
}
function wpcr_license_message(){
	return esc_html__("Please activate you license to use this functionality.", 'wpcargo-receiving');
}
function wpcr_get_frontend_page(){
	global $wpdb;
	$sql 			= "SELECT `ID` FROM {$wpdb->prefix}posts WHERE `post_content` LIKE '%[wpcr-update]%' AND `post_status` LIKE 'publish' LIMIT 1";
	$shortcode_id 	= $wpdb->get_var( $sql );
	if( ! $shortcode_id ){
		// Create post object
		$receiving = array(
			'post_title'    => __('Receiving', 'wpcargo-parcel-quotation'),
			'post_content'  => '[wpcr-update]',
			'post_status'   => 'publish',
			'post_type'   	=> 'page',
		);	
		// Insert the post into the database
		$shortcode_id = wp_insert_post( $receiving );		
	}
	if( $shortcode_id ){
		update_post_meta( $shortcode_id, '_wp_page_template', 'dashboard.php');
	}
	return $shortcode_id;
}