//register script

function load_custom_wp_admin_style($hook) {
if($hook != 'settings_page_swot-email-status') {
return;
}
// Register the script
wp_register_script( 'my_custom_adminscript', plugin_dir_url( __FILE__ ) . 'js/admin/adminscript.js', array('jquery') );
// Localize the script with new data
$translation_array = array(
'cresscap_nonce' => wp_create_nonce('swot-form')
);
wp_localize_script( 'my_custom_adminscript', 'adminscript_swotform', $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( 'my_custom_adminscript' );

}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
/*admin section add scripts*/



/*add menu page in admin area*/
function swot_email_status() 
{

    $args = array(
        'post_type'  => 'swot',
        'posts_per_page' => -1,
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key'     => 'initial_email_status',
                'value'   => array('0', '1'),
                'compare' => 'IN',
            ),
        ),
    );
    $total_waiting_query = new WP_Query( $args );
    $total_waiting =  $total_waiting_query->post_count;
        // echo "Last SQL-Query: {$total_waiting_query->request}";
    wp_reset_query();


    $args = array(
        'post_type'  => 'swot',
        'posts_per_page' => -1,
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key'     => 'initial_email_status',
                'value'   => '2',
                'compare' => '=',
            ),
        ),
    );
    $total_sent_query = new WP_Query( $args );
    $total_sent =  $total_sent_query->post_count;
    wp_reset_query();

    echo '
    ';
}
/*admin section enqueue scripts*/
/*add menu page in admin area*/


/*jquery to make a request*/
jQuery(document).ready(function(){
	jQuery('#send_swot_email_submit').click(function(){
		jQuery(this).prop('disabled', true);
		var send_swot_email_result = jQuery('#send_swot_email_result');
		send_swot_email_result.html('Processing...').show();

		jQuery.ajax({
	        type: 'POST',
	        url: ajaxurl,
	        dataType: 'json',
	        data: {
	            'action':   'send_swot_email_submit',
	            'cresscap_nonce' : adminscript_swotform.cresscap_nonce
	        },
    
	    success: function (response) {
	    	jQuery('#send_swot_email_submit').prop('disabled', false);
	        // console.log(response);
	        send_swot_email_result.html('');
	        if( response.failed_mails )
			{
				var result;
				result = 'Not able to deliver email to : '+ response.failed_mails;
				send_swot_email_result.html(result).show();
			}
			if( response.success_mails )
			{
				var result;
				result = 'Email successfully delivered to : '+ response.success_mails;
				send_swot_email_result.html(result).show();
				// setTimeout(function(){ location.reload(true); }, 2000);

			}
	       
	    }

    });
/*jquery to make a request*/

Advertisements