MSV FM

dot.antimicrobial@66.96.161.157: ~ $
Path : /hermes/bosweb/b1536/exactflashing.com/wp-content/themes/hello-elementor/
File Upload :
Current < : /hermes/bosweb/b1536/exactflashing.com/wp-content/themes/hello-elementor/functions.php

<?php
/**
 * Theme functions and definitions  
 *
 * @package HelloElementor
 */

if ( ! defined( 'ABSPATH' ) ) { 
	exit; // Exit if accessed directly.
}

define( 'HELLO_ELEMENTOR_VERSION', '2.6.1' );   

if ( ! isset( $content_width ) ) {
	$content_width = 800; // Pixels.
}

if ( ! function_exists( 'hello_elementor_setup' ) ) {
	/**
	 * Set up theme support.
	 *
	 * @return void
	 */
	function hello_elementor_setup() {
		if ( is_admin() ) {
			hello_maybe_update_theme_version_in_db();
		}

		$hook_result = apply_filters_deprecated( 'elementor_hello_theme_load_textdomain', [ true ], '2.0', 'hello_elementor_load_textdomain' );
		if ( apply_filters( 'hello_elementor_load_textdomain', $hook_result ) ) {
			load_theme_textdomain( 'hello-elementor', get_template_directory() . '/languages' );
		}

		$hook_result = apply_filters_deprecated( 'elementor_hello_theme_register_menus', [ true ], '2.0', 'hello_elementor_register_menus' );
		if ( apply_filters( 'hello_elementor_register_menus', $hook_result ) ) {
			register_nav_menus( [ 'menu-1' => __( 'Header', 'hello-elementor' ) ] );
			register_nav_menus( [ 'menu-2' => __( 'Footer', 'hello-elementor' ) ] );
		}

		$hook_result = apply_filters_deprecated( 'elementor_hello_theme_add_theme_support', [ true ], '2.0', 'hello_elementor_add_theme_support' );
		if ( apply_filters( 'hello_elementor_add_theme_support', $hook_result ) ) {
			add_theme_support( 'post-thumbnails' );
			add_theme_support( 'automatic-feed-links' );
			add_theme_support( 'title-tag' );
			add_theme_support(
				'html5',
				[
					'search-form',
					'comment-form',
					'comment-list',
					'gallery',
					'caption',
					'script',
					'style',
				]
			);
			add_theme_support(
				'custom-logo',
				[
					'height'      => 100,
					'width'       => 350,
					'flex-height' => true,
					'flex-width'  => true,
				]
			);

			/*
			 * Editor Style.
			 */
			add_editor_style( 'classic-editor.css' );

			/*
			 * Gutenberg wide images.
			 */
			add_theme_support( 'align-wide' );

			/*
			 * WooCommerce.
			 */
			$hook_result = apply_filters_deprecated( 'elementor_hello_theme_add_woocommerce_support', [ true ], '2.0', 'hello_elementor_add_woocommerce_support' );
			if ( apply_filters( 'hello_elementor_add_woocommerce_support', $hook_result ) ) {
				// WooCommerce in general.
				add_theme_support( 'woocommerce' );
				// Enabling WooCommerce product gallery features (are off by default since WC 3.0.0).
				// zoom.
				add_theme_support( 'wc-product-gallery-zoom' );
				// lightbox.
				add_theme_support( 'wc-product-gallery-lightbox' );
				// swipe.
				add_theme_support( 'wc-product-gallery-slider' );
			}
		}
	}
}

add_action( 'after_setup_theme', 'hello_elementor_setup' );

function hello_maybe_update_theme_version_in_db() {
	$theme_version_option_name = 'hello_theme_version';
	// The theme version saved in the database.
	$hello_theme_db_version = get_option( $theme_version_option_name );

	// If the 'hello_theme_version' option does not exist in the DB, or the version needs to be updated, do the update.
	if ( ! $hello_theme_db_version || version_compare( $hello_theme_db_version, HELLO_ELEMENTOR_VERSION, '<' ) ) {
		update_option( $theme_version_option_name, HELLO_ELEMENTOR_VERSION );
	}
}

if ( ! function_exists( 'hello_elementor_scripts_styles' ) ) {
	/**
	 * Theme Scripts & Styles.
	 *
	 * @return void
	 */
	function hello_elementor_scripts_styles() {
		$enqueue_basic_style = apply_filters_deprecated( 'elementor_hello_theme_enqueue_style', [ true ], '2.0', 'hello_elementor_enqueue_style' );
		$min_suffix          = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';

		if ( apply_filters( 'hello_elementor_enqueue_style', $enqueue_basic_style ) ) {
			wp_enqueue_style(
				'hello-elementor',
				get_template_directory_uri() . '/style' . $min_suffix . '.css',
				[],
				HELLO_ELEMENTOR_VERSION
			);
		}

		if ( apply_filters( 'hello_elementor_enqueue_theme_style', true ) ) {
			wp_enqueue_style(
				'hello-elementor-theme-style',
				get_template_directory_uri() . '/theme' . $min_suffix . '.css',
				[],
				HELLO_ELEMENTOR_VERSION
			);
		}
	}
}
add_action( 'wp_enqueue_scripts', 'hello_elementor_scripts_styles' );

if ( ! function_exists( 'hello_elementor_register_elementor_locations' ) ) {
	/**
	 * Register Elementor Locations.
	 *
	 * @param ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager $elementor_theme_manager theme manager.
	 *
	 * @return void
	 */
	function hello_elementor_register_elementor_locations( $elementor_theme_manager ) {
		$hook_result = apply_filters_deprecated( 'elementor_hello_theme_register_elementor_locations', [ true ], '2.0', 'hello_elementor_register_elementor_locations' );
		if ( apply_filters( 'hello_elementor_register_elementor_locations', $hook_result ) ) {
			$elementor_theme_manager->register_all_core_location();
		}
	}
}
add_action( 'elementor/theme/register_locations', 'hello_elementor_register_elementor_locations' );

if ( ! function_exists( 'hello_elementor_content_width' ) ) {
	/**
	 * Set default content width.
	 *
	 * @return void
	 */
	function hello_elementor_content_width() {
		$GLOBALS['content_width'] = apply_filters( 'hello_elementor_content_width', 800 );
	}
}
add_action( 'after_setup_theme', 'hello_elementor_content_width', 0 );

if ( is_admin() ) {
	require get_template_directory() . '/includes/admin-functions.php';
}

/**
 * If Elementor is installed and active, we can load the Elementor-specific Settings & Features
*/

// Allow active/inactive via the Experiments
require get_template_directory() . '/includes/elementor-functions.php';

/**
 * Include customizer registration functions
*/
function hello_register_customizer_functions() {
	if ( is_customize_preview() ) {
		require get_template_directory() . '/includes/customizer-functions.php';
	}
}
add_action( 'init', 'hello_register_customizer_functions' );

if ( ! function_exists( 'hello_elementor_check_hide_title' ) ) {
	/**
	 * Check hide title.
	 *
	 * @param bool $val default value.
	 *
	 * @return bool
	 */
	function hello_elementor_check_hide_title( $val ) {
		if ( defined( 'ELEMENTOR_VERSION' ) ) {
			$current_doc = Elementor\Plugin::instance()->documents->get( get_the_ID() );
			if ( $current_doc && 'yes' === $current_doc->get_settings( 'hide_title' ) ) {
				$val = false;
			}
		}
		return $val;
	}
}
add_filter( 'hello_elementor_page_title', 'hello_elementor_check_hide_title' );

/**
 * Wrapper function to deal with backwards compatibility.
 */
if ( ! function_exists( 'hello_elementor_body_open' ) ) {
	function hello_elementor_body_open() {
		if ( function_exists( 'wp_body_open' ) ) {
			wp_body_open();
		} else {
			do_action( 'wp_body_open' );
		}
	}
}

add_action("admin_enqueue_scripts","custom_css");


function custom_css(){
$base_url=get_bloginfo('wpurl');
$css_path=$base_url."/wp-content/themes/hello-elementor/includes/css/custom-styles.css";
    wp_register_style( 'custom-styles', $css_path);
    wp_enqueue_style( 'custom-styles');
}

add_action("admin_enqueue_scripts","custom_js");

function custom_js(){
$base_url=get_bloginfo('wpurl');	
$js_path=$base_url."/wp-content/themes/hello-elementor/includes/js/custom-script.js"; 
    wp_register_script( 'custom-script', $js_path);
    wp_enqueue_script( 'custom-script');
    $base_url=get_bloginfo('wpurl');
	$ajax_url = array(
	    'test' => $base_url,
	);
    wp_add_inline_script( 'custom-script', 'var myThemeParams = ' . wp_json_encode( $ajax_url ), 'before' );
     // wp_localize_script('custom-script', 'myThemeParams', $ajax_url);

}


add_action("wp_head","custom_script");
function custom_script(){
$base_url=get_bloginfo('wpurl');	
?>
<script>
 	jQuery(document).ready(function(){
 		var animal_site_base_url="<?php echo get_bloginfo('wpurl');?>";
	});
</script>
<?php
}

add_action('admin_menu', 'admin_dashboard_menus');
function admin_dashboard_menus()

{
    add_menu_page('Clients-dashboard', 'Clients', 'manage_options', 'cad-dashboard','clients_detailes','dashicons-admin-multisite');
    add_menu_page('Members-dashboard', 'Members', 'manage_options', 'mad-dashboard','members_detailes','dashicons-admin-users');
    add_menu_page('Animals-dashboard', 'Animals', 'manage_options', 'aad-dashboard','animals_detailes','dashicons-pets');
    add_menu_page('Report-dashboard', 'Report', 'manage_options', 'rad-dashboard','report_detailes','dashicons-welcome-learn-more');
}

$current_url=admin_url();
function report_detailes(){
    global $wpdb;	
 	$clientDet=$wpdb->get_results($wpdb->prepare("SELECT * FROM `client_detailes`"));   

 	?>
 	<div class="admin_report"> 
 		<p>Client</p>
 		<div class="sub_report_cont">
	  		<select>
	 			<option value="all">All</option>
	 			<?php
	 			 foreach($clientDet as $detailes){
	 			?>
	 			<option value="<?php echo $detailes->client_id; ?>"><?php echo $detailes->name; ?></option>
	 		    <?php
	 		     }
	 		    ?>

	 		</select>
	 		<button type="button" class="print_pdf">Print</button>			
 		</div>

 	</div>
 	<?php
}
function clients_detailes(){
    $url=$current_url."admin.php?page=cad-dashboard";
    include_once  plugin_dir_path( __FILE__ ) . 'includes/cma_client.php';	
    $cma_client = new Cma_Client();
	    if(isset($_GET['action'])){  

	      if($_GET['action'] == 'add_client'){ 

             include_once  plugin_dir_path( __FILE__ ) . 'template-parts/add_client_form.php';

	    	}

	       else if ($_GET['action'] == 'edit_client') {

             include_once  plugin_dir_path( __FILE__ ) . 'template-parts/edit_client.php';         
	       }
	       else if ($_GET['action'] == 'edit_save') {  	

           	  $edit_client_id= $_GET['Client_id'];	        	
           	  $edit_client_name=$_POST["edit_client_name"];
              $edit_client_add1=$_POST["edit_client_add1"];
              $edit_client_add2=$_POST["edit_client_add2"];
              $edit_client_city=$_POST["edit_client_city"];
              $edit_client_state=$_POST["edit_client_state"];
              $edit_client_country=$_POST["edit_client_country"];
              $edit_client_post_code=$_POST["edit_client_post_code"];
              $edit_client_mobile=$_POST["edit_client_mobile"];
              $edit_client_email=$_POST["edit_client_email"];
              $edit_client_email_copy=$_POST["edit_client_email_copy"];
              $edit_client_email_sup1=$_POST["edit_client_email_sup1"];
              $edit_client_email_sup2=$_POST["edit_client_email_sup2"];
              $edit_client_email_sup3=$_POST["edit_client_email_sup3"];
              $edit_client_active_det=$_POST["edit_client_active_det"];         
              $edit_client_last_job_no=$_POST["edit_client_last_job_no"];

              $client_det = $cma_client->edit_save_client($edit_client_id,$edit_client_name,$edit_client_add1,$edit_client_add2,$edit_client_city,$edit_client_state,$edit_client_country,$edit_client_post_code,$edit_client_mobile,$edit_client_email,$edit_client_units_ms,$edit_client_email_sup1,$edit_client_email_sup2,$edit_client_email_sup3,$edit_client_active_det,$edit_client_last_job_no,$edit_client_email_copy);    	       	
             $all_client_detailes = $cma_client->get_client();
             include_once  plugin_dir_path( __FILE__ ) . 'template-parts/clients.php';
             header("Location: $url");     

	       }	       
	       else if ($_GET['action'] == 'del_client') {

           	 $client_id= $_GET['Client_id'];	
           	 $del_client_det = $cma_client->delete_client($client_id);
             $all_client_detailes = $cma_client->get_client();
             include_once  plugin_dir_path( __FILE__ ) . 'template-parts/clients.php';
             header("Location: $url");   

	       }	
	       else if ($_GET['action'] == 'save_new_client') {

           	  $add_client_email_copy = $_POST["add_client_email_copy"];
           	  $add_client_name=$_POST["add_client_name"];
              $add_client_add1=$_POST["add_client_add1"];
              $add_client_add2=$_POST["add_client_add2"];
              $add_client_city=$_POST["add_client_city"];
              $add_client_state=$_POST["add_client_state"];
              $add_client_country=$_POST["add_client_country"];
              $add_client_post_code=$_POST["add_client_post_code"];
              $add_client_mobile=$_POST["add_client_mobile"];
              $add_client_email=$_POST["add_client_email"];
              $add_client_units_ms=$_POST["add_client_units_ms"];
              $add_client_email_sup1=$_POST["add_client_email_sup1"];
              $add_client_email_sup2=$_POST["add_client_email_sup2"];
              $add_client_email_sup3=$_POST["add_client_email_sup3"];
              $add_client_active_det=$_POST["add_client_active_det"];         
              $add_client_last_job_no=$_POST["add_client_last_job_no"];

              $client_det = $cma_client->add_client($add_client_name,$add_client_add1,$add_client_add2,$add_client_city,$add_client_state,$add_client_country,$add_client_post_code,$add_client_mobile,$add_client_email,$add_client_email_copy,$add_client_units_ms,$add_client_email_sup1,$add_client_email_sup2,$add_client_email_sup3,$add_client_active_det,$add_client_last_job_no); 


              	$all_client_detailes = $cma_client->get_client();
	           	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/clients.php';
	           	header("Location: $url");       

	       }	              
	    }else{
           $all_client_detailes = $cma_client->get_client();   	    	
           include_once  plugin_dir_path( __FILE__ ) . 'template-parts/clients.php';   
	    }
} 

function members_detailes(){

    $url=$current_url."admin.php?page=mad-dashboard";
    include_once  plugin_dir_path( __FILE__ ) . 'includes/cma_member.php';	
    $cma_member = new Cma_member();

	    if(isset($_GET['action'])){
           if($_GET['action'] == 'add_member'){
             include_once  plugin_dir_path( __FILE__ ) . 'template-parts/add_members.php';
	    	}
	       else if ($_GET['action'] == 'edit_member') {
             include_once  plugin_dir_path( __FILE__ ) . 'template-parts/edit_members.php';
	       }
	       else if ($_GET['action'] == 'del_member') {
           	 $member_id= $_GET['member_id'];	
           	 $del_client_det = $cma_member->delete_member($member_id);
	          header("Location: $url");     
	       }
	       else if ($_GET['action'] == 'edit_save') {  	
           	  $edit_member_id= $_GET['member_id'];	
           	  $edit_member_client_id=$_POST["edit_member_client_id"];
              $edit_member_fst_name=$_POST["edit_member_fst_name"];
              $edit_member_sur_name=$_POST["edit_member_sur_name"];
              $edit_member_password=$_POST["edit_member_password"];
              $edit_member_mobile=$_POST["edit_member_mobile"];
              $edit_member_email=$_POST["edit_member_email"];
              $edit_member_lst_email=$_POST["edit_member_lst_email"];
              $edit_member_lst_email_date=$_POST["edit_member_lst_email_date"];              
              $edit_member_num_emails=$_POST["edit_member_num_emails"];
              $edit_member_active_det=$_POST["edit_member_active_det"];
              $member_det = $cma_member->edit_save_member($edit_member_id,$edit_member_client_id,$edit_member_fst_name,$edit_member_sur_name,$edit_member_password,$edit_member_mobile,$edit_member_email,$edit_member_lst_email,$edit_member_lst_email_date,$edit_member_num_emails,$edit_member_active_det); 

	          	
	          header("Location: $url");    

	       }		       	
	       else if ($_GET['action'] == 'save_new_member') {

           	  $add_member_client_id=$_POST["add_member_client_id"];
              $add_member_fst_name=$_POST["add_member_fst_name"];
              $add_member_sur_name=$_POST["add_member_sur_name"];
              $add_member_password=$_POST["add_member_password"]; 
              $add_member_mobile=$_POST["add_member_mobile"];
              $add_member_email=$_POST["add_member_email"];
              $add_member_lst_email=$_POST["add_member_lst_email"];
              $add_member_lst_email_date=$_POST["add_member_lst_email_date"];              
              $add_member_num_emails=$_POST["add_member_num_emails"];
              $add_member_active_det=$_POST["add_member_active_det"];
              $add_member_level=$_POST["add_member_level"];
              $member_det = $cma_member->add_member($add_member_client_id,$add_member_fst_name,$add_member_sur_name,$add_member_password,$add_member_mobile,$add_member_email,$add_member_lst_email,$add_member_lst_email_date,$add_member_num_emails,$add_member_active_det,$add_member_level);  

              if($member_det != "Email ALready Exists") {
              		
		           	header("Location: $url");
              }
              else {
              	$error = "Email ALready Exists";
              	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/add_members.php';
              }

                     	       	
	       }	              
	    }
	    else {
	    	   	global $wpdb;
	    	   	$member_data = array();
	    	   	$idx = 0;
	           	$all_member_detailes = $cma_member->get_member();
	           	foreach ($all_member_detailes as $members3) {	
	           		$clientname_data = $wpdb->get_results($wpdb->prepare("SELECT name FROM  client_detailes where client_id = $members3->client_id"));
		           	$member_data[$idx]['member_id'] = $members3->member_id;
		           	$member_data[$idx]['client_name'] = $clientname_data[0]->name;
		           	$member_data[$idx]['first_name'] = $members3->first_name;
		           	$member_data[$idx]['surname'] = $members3->surname;
		           	$member_data[$idx]['mobile'] = $members3->mobile;
		           	$member_data[$idx]['email'] = $members3->email;
		           	$member_data[$idx]['last_email_job_no'] = $members3->last_email_job_no;
		           	$member_data[$idx]['last_email_date'] = $members3->last_email_date;
		           	$member_data[$idx]['number_emails'] = $members3->number_emails;
		           	$member_data[$idx]['active'] = $members3->active;
		           	$idx++;
           		}
           		include_once  plugin_dir_path( __FILE__ ) . 'template-parts/members.php'; 
	    }	
    
}

function animals_detailes() {
	
		$url = $current_url."admin.php?page=aad-dashboard"; 
		include_once  plugin_dir_path( __FILE__ ) . 'includes/cma_animal.php';	
	    $cma_animal = new Cma_Animal();
         $profile_id = um_profile_id();  
         if($profile_id==1){
            $member_id=-1;
         }else{
         $user_meta = get_userdata($profile_id);            
         $email = $user_meta->user_email;
         $role = $user_meta->roles[0];
         $get_member_id = $wpdb->get_results($wpdb->prepare("SELECT member_id FROM member_detailes WHERE email = '".$email."'"));
            $member_id = $get_member_id[0]->member_id;            
         }	    
	    if(isset($_GET['action'])){
           if($_GET['action'] == 'add_animal'){
             include_once  plugin_dir_path( __FILE__ ) . 'template-parts/add_animal.php'; 
	    	}
	       else if ($_GET['action'] == 'edit_animal') {

             	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/edit_animal.php';
	       }
	       elseif($_GET['action'] == 'del_animal') {
	       		$animal_id= $_GET['id'];	
           	 	$del_animal_det = $cma_animal->delete_animal($animal_id);

             	$all_animal_detailes = $cma_animal->get_animals();
             	$animal_data = array();
			    global $wpdb;
		    	$idx = 0;
		    	foreach($all_animal_detailes as $animal_details) {
		    		$clientname = $wpdb->get_results($wpdb->prepare("SELECT name FROM  client_detailes where client_id = $animal_details->client_id"));
		    		$animal_data[$idx]['client_name'] = $clientname[0]->name;
		    		$animal_data[$idx]['id'] = $animal_details->id;
		    		$animal_data[$idx]['client_id'] = $animal_details->client_id;
		    		$animal_data[$idx]['filter1'] = $animal_details->filter1;
		    		$animal_data[$idx]['filter2'] = $animal_details->filter2;
		    		$idx++;
		    	} 

	          	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/animals.php';
	          	header("Location: $url");  
	       }
	       else if ($_GET['action'] == 'editsave_animal') {
	       		$edit_animal_id= $_GET['animal_id'];	
	       		$id= $_GET['id'];	
	       		if (isset($_FILES['edit_animal_upld_file']['tmp_name'])){

				    $file = $_FILES['edit_animal_upld_file']['tmp_name'];
				    $filename = $_FILES['edit_animal_upld_file']['name'];
				    $filename = str_replace(' ', '_', $filename);				    
				    $folder = ABSPATH.'wp-content/uploads/animal-selected/';
				    $handle=$folder.$filename;
				    global $wpdb;
					$get_file_name = $wpdb->get_results($wpdb->prepare("SELECT file_name FROM animal_detailes WHERE id = $id"));		
					$file_name=$get_file_name[0]->file_name;
                    // $img_url =  str_replace("https://","/home3/sbsofkvq/",$handle);
                    // echo $handle;
                    // echo "hghgh";
                    // echo $file_name;
                    // die();
					if($handle!=$folder){
					 if(file_exists($handle)){
					    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
					    $charactersLength = strlen($characters);
					    $randomString = '';
					    for ($i = 0; $i < 2; $i++) {
					        $randomString .= $characters[random_int(0, $charactersLength - 1)];
					    }
					 
						$randm_key= "_".$randomString;

						$extension_pos = strrpos($handle, '.'); 
						$path = substr($handle, 0, $extension_pos) . $randm_key . substr($handle, $extension_pos);
						$handle=$path;
					    move_uploaded_file($file,$handle);						   	  
					 }						
					}	    
			    }
			    $client = $_POST['edit_animal_client_id']; 
				$add_animal_filter1 = $_POST['edit_animal_filter1']; 
				$add_animal_filter2 = $_POST['edit_animal_filter2'];
				$edit_animal_file = $_POST['edit_animal_file'];
				$edit_animal_opta = $_POST['edit_animal_opta'];
				$edit_animal_optb = $_POST['edit_animal_optb'];
				$edit_animal_optc = $_POST['edit_animal_optc'];
				$edit_animal_optd = $_POST['edit_animal_optd'];
				$edit_animal_opte = $_POST['edit_animal_opte'];
				$edit_animal_optf = $_POST['edit_animal_optf'];
				$edit_animal_optg = $_POST['edit_animal_optg'];		
				$edit_animal_optp = $_POST['edit_animal_optp'];			
				$edit_animal_optv = $_POST['edit_animal_optv'];
				$edit_animal_optw = $_POST['edit_animal_optw'];
				$edit_animal_optx = $_POST['edit_animal_optx'];
				$edit_animal_opty = $_POST['edit_animal_opty'];
				$edit_animal_optz = $_POST['edit_animal_optz'];
				$edit_animal_opta_def = $_POST['edit_animal_opta_def'];
				$edit_animal_optb_def = $_POST['edit_animal_optb_def'];
				$edit_animal_optc_def = $_POST['edit_animal_optc_def'];
				$edit_animal_optd_def = $_POST['edit_animal_optd_def'];
				$edit_animal_opte_def = $_POST['edit_animal_opte_def'];
				$edit_animal_optf_def = $_POST['edit_animal_optf_def'];
				$edit_animal_optg_def = $_POST['edit_animal_optg_def'];	
				$edit_animal_optp_def = $_POST['edit_animal_optp_def'];		
				$edit_animal_optv_def = $_POST['edit_animal_optv_def'];
				$edit_animal_optw_def = $_POST['edit_animal_optw_def'];
				$edit_animal_optx_def = $_POST['edit_animal_optx_def'];
				$edit_animal_opty_def = $_POST['edit_animal_opty_def'];
				$edit_animal_optz_def = $_POST['edit_animal_optz_def'];				
				$add_animal_active_det = $_POST['edit_animal_active_det'];

			   	if($handle == $folder) {
			   		$animal_data_update = $cma_animal->updateanimal_without_file($id,$edit_animal_id,$add_animal_filter1,$add_animal_filter2,$edit_animal_file,$edit_animal_opta,$edit_animal_optb,$edit_animal_optc,$edit_animal_optd,$edit_animal_opte,$edit_animal_optf,$edit_animal_optg,$edit_animal_optp,$edit_animal_optv,$edit_animal_optw,$edit_animal_optx,$edit_animal_opty,$edit_animal_optz,$edit_animal_opta_def,$edit_animal_optb_def,$edit_animal_optc_def,$edit_animal_optd_def,$edit_animal_opte_def,$edit_animal_optf_def,$edit_animal_optg_def,$edit_animal_optp_def,$edit_animal_optv_def,$edit_animal_optw_def,$edit_animal_optx_def,$edit_animal_opty_def,$edit_animal_optz_def,$add_animal_active_det,$member_id);
			   	}
			   	else {
				    $animal_data_update = $cma_animal->update_animal($id,$edit_animal_id,$handle,$add_animal_filter1,$add_animal_filter2,$edit_animal_file,$edit_animal_opta,$edit_animal_optb,$edit_animal_optc,$edit_animal_optd,$edit_animal_opte,$edit_animal_optf,$edit_animal_optg,$edit_animal_optp,$edit_animal_optv,$edit_animal_optw,$edit_animal_optx,$edit_animal_opty,$edit_animal_optz,$edit_animal_opta_def,$edit_animal_optb_def,$edit_animal_optc_def,$edit_animal_optd_def,$edit_animal_opte_def,$edit_animal_optf_def,$edit_animal_optg_def,$edit_animal_optp_def,$edit_animal_optv_def,$edit_animal_optw_def,$edit_animal_optx_def,$edit_animal_opty_def,$edit_animal_optz_def,$add_animal_active_det,$member_id);

			    
			   	}

			    $all_animal_detailes = $cma_animal->get_animals();	 
			    $animal_data = array();
			    global $wpdb;
		    	$idx = 0;
		    	foreach($all_animal_detailes as $animal_details) {
		    		$clientname = $wpdb->get_results($wpdb->prepare("SELECT name FROM  client_detailes where client_id = $animal_details->client_id"));
		    		$animal_data[$idx]['client_name'] = $clientname[0]->name;
		    		$animal_data[$idx]['id'] = $animal_details->id;
		    		$animal_data[$idx]['client_id'] = $animal_details->client_id;
		    		$animal_data[$idx]['filter1'] = $animal_details->filter1;
		    		$animal_data[$idx]['filter2'] = $animal_details->filter2;
		    		$idx++;
		    	} 
	           	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/animals.php';
	           	header("Location: $url"); 

	       }	
	       else if ($_GET['action'] == 'save_animal') { 

		       	if (isset($_FILES['add_animal_upld_file']['tmp_name'])){

				    $file = $_FILES['add_animal_upld_file']['tmp_name'];
				    $filename = $_FILES['add_animal_upld_file']['name'];
				    $filename = str_replace(' ', '_', $filename);
				    $folder = ABSPATH.'wp-content/uploads/animal-selected/';
				    $handle = $folder.$filename ;	
					 if(file_exists($handle)){
					    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
					    $charactersLength = strlen($characters);
					    $randomString = '';
					    for ($i = 0; $i < 2; $i++) {
					        $randomString .= $characters[random_int(0, $charactersLength - 1)];
					    }
					 
						$randm_key= "_".$randomString;

						$extension_pos = strrpos($handle, '.'); 
						$path = substr($handle, 0, $extension_pos) . $randm_key . substr($handle, $extension_pos);
						$handle=$path;   	  
					 }				    			  
					move_uploaded_file($file,$handle);
			    }
			    $client = $_POST['add_animal_client_id'];
			    $add_animal_filter1 = $_POST['add_animal_filter1']; 
			    $add_animal_filter2 = $_POST['add_animal_filter2'];
			    $add_animal_file = $_POST['add_animal_file'];
			    $add_animal_opta = $_POST['add_animal_opta'];
			    $add_animal_optb = $_POST['add_animal_optb'];
			    $add_animal_optc = $_POST['add_animal_optc'];
			    $add_animal_optd = $_POST['add_animal_optd'];
			    $add_animal_opte = $_POST['add_animal_opte'];
			    $add_animal_optf = $_POST['add_animal_optf'];
			    $add_animal_optg = $_POST['add_animal_optg'];		
			    $add_animal_optp = $_POST['add_animal_optp'];				    	    
			    $add_animal_optv = $_POST['add_animal_optv'];
			    $add_animal_optw = $_POST['add_animal_optw'];
			    $add_animal_optx = $_POST['add_animal_optx']; 
			    $add_animal_opty = $_POST['add_animal_opty'];
			    $add_animal_optz = $_POST['add_animal_optz'];
			    $add_animal_opta_def = $_POST['add_animal_opta_def'];
			    $add_animal_optb_def = $_POST['add_animal_optb_def'];
			    $add_animal_optc_def = $_POST['add_animal_optc_def'];
			    $add_animal_optd_def = $_POST['add_animal_optd_def'];
			    $add_animal_opte_def = $_POST['add_animal_opte_def'];
			    $add_animal_optf_def = $_POST['add_animal_optf_def'];
			    $add_animal_optg_def = $_POST['add_animal_optg_def'];		
			    $add_animal_optp_def = $_POST['add_animal_optp_def'];		
			    $add_animal_optv_def = $_POST['add_animal_optv_def'];
			    $add_animal_optw_def = $_POST['add_animal_optw_def'];
			    $add_animal_optx_def = $_POST['add_animal_optx_def']; 
			    $add_animal_opty_def = $_POST['add_animal_opty_def'];
			    $add_animal_optz_def = $_POST['add_animal_optz_def'];

			    $add_animal_active_det = $_POST['add_animal_active_det'];
			    $animal_data = $cma_animal->add_animal($client,$handle,$add_animal_filter1,$add_animal_filter2,$add_animal_file,$add_animal_opta,$add_animal_optb,$add_animal_optc,$add_animal_optd,$add_animal_opte,$add_animal_optf,$add_animal_optg,$add_animal_optp,$add_animal_optv,$add_animal_optw,$add_animal_optx,$add_animal_opty,$add_animal_optz,$add_animal_active_det,$add_animal_opta_def,$add_animal_optb_def,$add_animal_optc_def,$add_animal_optd_def,$add_animal_opte_def,$add_animal_optf_def,$add_animal_optg_def,$add_animal_optp_def,$add_animal_optv_def,$add_animal_optw_def,$add_animal_optx_def,$add_animal_opty_def,$add_animal_optz_def,$member_id);

			    $all_animal_detailes = $cma_animal->get_animals();	 
			    $animal_data = array();
			    global $wpdb;
		    	$idx = 0;
		    	foreach($all_animal_detailes as $animal_details) {
		    		$clientname = $wpdb->get_results($wpdb->prepare("SELECT name FROM  client_detailes where client_id = $animal_details->client_id"));
		    		$animal_data[$idx]['client_name'] = $clientname[0]->name;
		    		$animal_data[$idx]['id'] = $animal_details->id;
		    		$animal_data[$idx]['client_id'] = $animal_details->client_id;
		    		$animal_data[$idx]['filter1'] = $animal_details->filter1;
		    		$animal_data[$idx]['filter2'] = $animal_details->filter2;
		    		$idx++;
		    	} 
	           	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/animals.php';
	           	header("Location: $url");    
	       }	               
	    }
	    else {
	    	$all_animal_detailes = $cma_animal->get_animals();
	    	$animal_data = array();
	    	global $wpdb;
	    	$idx = 0;
	    	foreach($all_animal_detailes as $animal_details) {
	    		$clientname = $wpdb->get_results($wpdb->prepare("SELECT name FROM  client_detailes where client_id = $animal_details->client_id"));
	    		$animal_data[$idx]['client_name'] = $clientname[0]->name;
	    		$animal_data[$idx]['id'] = $animal_details->id;
	    		$animal_data[$idx]['client_id'] = $animal_details->client_id;
	    		$animal_data[$idx]['filter1'] = $animal_details->filter1;
	    		$animal_data[$idx]['filter2'] = $animal_details->filter2;
	    		$animal_data[$idx]['filename'] = $animal_details->file_name;
	    		$animal_data[$idx]['created_at'] = $animal_details->created_at;
	    		$animal_data[$idx]['filetext'] = $animal_details->filename;
	    		$idx++;
	    	}
         	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/animals.php';
	    }  

}

add_action( 'wp_ajax_nopriv_add_new_filter_type', 'add_new_filter_type' );
add_action( 'wp_ajax_add_new_filter_type', 'add_new_filter_type' );


function add_new_filter_type() {
	global $wpdb;
	$new_type = $_POST['new_type']; 
	$get_filters = $wpdb->get_results($wpdb->prepare("SELECT * FROM `animal_filters` WHERE type='filter1' AND name='".$new_type."'"));
	if(empty($get_filters)) {
		$wpdb->insert('animal_filters', array(
			'type' => 'filter1',
			'name' => "$new_type",
		));
		$inserted_id = $wpdb->insert_id;
		
		echo json_encode($inserted_id);
		die();
	}
	else {
		echo json_encode('already exists');
		die();
	}
	
}



add_action( 'wp_ajax_nopriv_add_new_filter2_type', 'add_new_filter2_type' );
add_action( 'wp_ajax_add_new_filter2_type', 'add_new_filter2_type' );

function add_new_filter2_type() {
	global $wpdb;
	$filter2new_type = $_POST['filter2new_type']; 
	$get_filter2 = $wpdb->get_results($wpdb->prepare("SELECT * FROM `animal_filters` WHERE type='filter2' AND name='".$filter2new_type."'"));
	if(empty($get_filter2)) {
		$wpdb->insert('animal_filters', array(
			'type' => 'filter2',
			'name' => "$filter2new_type",
		));
		$inserted_id = $wpdb->insert_id;
		echo json_encode($inserted_id);
		die();
	}
	else {
		echo json_encode('already exists');
		die();
	}
	
}


add_action( 'wp_ajax_nopriv_delete_animal_image', 'delete_animal_image' );
add_action( 'wp_ajax_delete_animal_image', 'delete_animal_image' );


function delete_animal_image() {

	$id = $_POST['id'];
	global $wpdb;
	$wpdb->get_results($wpdb->prepare("UPDATE animal_detailes SET file_name = '' WHERE id='".$id."'"));
	echo json_encode('success') ;
	die();

}





/* add new tab called "mytab" */

add_filter('um_account_page_default_tabs_hook', 'my_custom_tab_in_um', 100 );
function my_custom_tab_in_um( $tabs ) {
	$profile_id = um_profile_id();  
	$user_meta = get_userdata($profile_id);

	$email = $user_meta->user_email;
	$role = $user_meta->roles[0];


	if($role == 'um_client') {
		$tabs[100]['clientmembers']['icon'] = 'um-faicon-pencil';
		$tabs[100]['clientmembers']['title'] = 'Members';
		$tabs[100]['clientmembers']['custom'] = true;
		$tabs[100]['clientmembers']['show_button'] = false;

		$tabs[101]['clientjobs']['icon'] = 'um-faicon-pencil';
		$tabs[101]['clientjobs']['title'] = 'Jobs';
		$tabs[101]['clientjobs']['custom'] = true;
		$tabs[101]['clientjobs']['show_button'] = false;

		$tabs[102]['clientanimal']['icon'] = 'um-faicon-pencil';
		$tabs[102]['clientanimal']['title'] = 'Flashing Selection';
		$tabs[102]['clientanimal']['custom'] = true;
		$tabs[102]['clientanimal']['show_button'] = false;

		$tabs[103]['clientanimal_mod']['icon'] = 'um-faicon-pencil';
		$tabs[103]['clientanimal_mod']['title'] = 'View/Edit/Delete Selection';
		$tabs[103]['clientanimal_mod']['custom'] = true;
		$tabs[103]['clientanimal_mod']['show_button'] = false;

		$tabs[104]['clientemail']['icon'] = 'um-faicon-pencil';
		$tabs[104]['clientemail']['title'] = 'Email Supplier';
		$tabs[104]['clientemail']['custom'] = true;
		$tabs[104]['clientemail']['show_button'] = false;

		$tabs[1000]['clientlogout']['icon'] = 'um-icon-android-exit';
		$tabs[1000]['clientlogout']['title'] = 'Log Out';
		$tabs[1000]['clientlogout']['custom'] = true;
		$tabs[1000]['clientlogout']['show_button'] = false;			
	}
	if($role == 'um_member') {

		$tabs[101]['clientjobs']['icon'] = 'um-faicon-pencil';
		$tabs[101]['clientjobs']['title'] = 'Jobs';
		$tabs[101]['clientjobs']['custom'] = true;
		$tabs[101]['clientjobs']['show_button'] = false;

		$tabs[102]['clientanimal']['icon'] = 'um-faicon-pencil';
		$tabs[102]['clientanimal']['title'] = 'Flashing Selection';
		$tabs[102]['clientanimal']['custom'] = true;
		$tabs[102]['clientanimal']['show_button'] = false;


		$tabs[103]['clientanimal_mod']['icon'] = 'um-faicon-pencil';
		$tabs[103]['clientanimal_mod']['title'] = 'View/Edit/Delete Selection';
		$tabs[103]['clientanimal_mod']['custom'] = true;
		$tabs[103]['clientanimal_mod']['show_button'] = false;

		$tabs[104]['clientemail']['icon'] = 'um-faicon-pencil';
		$tabs[104]['clientemail']['title'] = 'Email Supplier';
		$tabs[104]['clientemail']['custom'] = true;
		$tabs[104]['clientemail']['show_button'] = false;

		$tabs[1000]['clientlogout']['icon'] = 'um-icon-android-exit';
		$tabs[1000]['clientlogout']['title'] = 'Log Out';
		$tabs[1000]['clientlogout']['custom'] = true;
		$tabs[1000]['clientlogout']['show_button'] = false;		
	}	


	return $tabs;
}
	
/* make our new tab hookable */ 

add_action('um_account_tab__clientmembers', 'um_account_tab__clientmembers');
function um_account_tab__clientmembers( $info ) {
	global $ultimatemember;
	extract( $info );

	$output = $ultimatemember->account->get_tab_output('clientmembers');
	if ( $output ) { 
		echo $output; 
	}
}
add_action('um_account_tab__clientanimal', 'um_account_tab__clientanimal');
function um_account_tab__clientanimal( $info ) {
	global $ultimatemember;
	extract( $info );

	$output = $ultimatemember->account->get_tab_output('clientanimal');
	if ( $output ) { 
		echo $output; 
	}
}
add_action('um_account_tab__clientanimal_mod', 'um_account_tab__clientanimal_mod');
function um_account_tab__clientanimal_mod( $info ) {
	global $ultimatemember;
	extract( $info );

	$output = $ultimatemember->account->get_tab_output('clientanimal_mod');
	if ( $output ) { 
		echo $output; 
	}
}
add_action('um_account_tab__clientjobs', 'um_account_tab__clientjobs');
function um_account_tab__clientjobs( $info ) {
	global $ultimatemember;
	extract( $info );

	$output = $ultimatemember->account->get_tab_output('clientjobs');
	if ( $output ) { 
		echo $output; 
	}
}
add_action('um_account_tab__clientemail', 'um_account_tab__clientemail');
function um_account_tab__clientemail( $info ) {
	global $ultimatemember;
	extract( $info );

	$output = $ultimatemember->account->get_tab_output('clientemail');
	if ( $output ) { 
		echo $output; 
	}
}
add_action('um_account_tab__clientlogout', 'um_account_tab__clientlogout');
function um_account_tab__clientlogout( $info ) {
	global $ultimatemember;
	extract( $info );

	$output = $ultimatemember->account->get_tab_output('clientlogout');
	if ( $output ) { 
		echo $output; 
	}
}
/* Finally we add some content in the tab */


add_filter('um_account_content_hook_clientlogout', 'um_account_content_hook_clientlogout');
function um_account_content_hook_clientlogout( $output ){
	ob_start();
    ?>
    <div class="logout_container">
      <p>Are you sure you want to logout your account?To logout click on logout button below.</p>
       <?php
       $base_url=get_bloginfo('wpurl');
       $logout_link=$base_url."/test-page/";
       ?>
      <a href="<?php echo $logout_link; ?>" class="real_url"><input type="button" class="um_account_logout" value="Logout"></a>
    </div>
    <style>
     #um_field_general_user_email{
     	display: none !important;
     }
     #um_field_general_last_name{
     	display: none !important;
     }    
     #um_field_general_first_name{
     	display: none !important;
     }     
	 .selected-job-animals [type=button]:focus{
	    color: #000 !important;
	    background: #EFEE22 !important;
	    border: 2px solid #A6C7B9 !important;
	 }   	
 	.um_account_logout{
	    color: #fff;
	    padding: 8px 40px;
	    border: none;
	    margin-right: 20px;
	    background: #F15E42;
	    border-radius: 5px;
	    margin-top: 18px;
	    margin-right: 0;
	    font-size: 18px !important;	       	
	}   
	.logout_container{
		text-align: center;
	    position: absolute;
	    top: 50%;
	    left: 50%;
	    /* width: 200px; */
	    height: 200px;
	    margin: -100px 0 0 -100px;	
	    font-size: 17px;
        font-weight: 400;
	}	
    </style>
    <?php

	$output .= ob_get_contents();
	ob_end_clean();
	return $output;
}

add_filter('um_account_content_hook_clientanimal_mod', 'um_account_content_hook_clientanimal_mod');
function um_account_content_hook_clientanimal_mod( $output ){
	ob_start();

	include_once  plugin_dir_path( __FILE__ ) . 'includes/cma_frontendanimals_mod.php';
    $frontend_animals = new OCR_Front_end_animals_mod();
    $profile_id = um_profile_id(); 
	$user_meta = get_userdata($profile_id);
    global $wpdb;
	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$user_meta->user_email."'"));
	$client_id=$get_clientid[0]->client_id;
	$current_company = $get_clientid[0]->client_id;
	$get_selected_jobnos = $frontend_animals->get_jobs_mod($current_company);
	// $get_selected_animals = $frontend_animals->get_animals_mod($current_company);
	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientAnimalsMod.php';	
	$output .= ob_get_contents(); 
	ob_end_clean();
	return $output;
} 

add_filter('um_account_content_hook_clientmembers', 'um_account_content_hook_clientmembers');
function um_account_content_hook_clientmembers( $output ){
	ob_start();
	

    include_once  plugin_dir_path( __FILE__ ) . 'includes/cma-client_front_end.php';
    $client_front_end = new OCR_Front_end_client();

    $profile_id = um_profile_id(); 
	$user_meta = get_userdata($profile_id); 
  
	global $wpdb;
	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$user_meta->user_email."'"));
	$current_company = $get_clientid[0]->client_id;
	$current_company_name = $wpdb->get_results($wpdb->prepare("SELECT name FROM client_detailes WHERE client_id = '".$current_company."'"));

    if($_GET['action'] == 'edit_member') {
    	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientTabEditMember.php';
    }
    elseif($_GET['action'] == 'add_member') {
    	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientTabAddMember.php';
    }
    else {

	    $get_clients = $client_front_end->get_clients($current_company);
	    $getclients_data = array();
	    $idx = 0;
	    foreach ($get_clients as $getclients) {	 
	    	$clientname_data = $wpdb->get_results($wpdb->prepare("SELECT name FROM  client_detailes where client_id = $getclients->client_id"));
	    	$getclients_data[$idx]['member_id'] = $getclients->member_id;
	    	$getclients_data[$idx]['first_name'] = $getclients->first_name;
	    	$getclients_data[$idx]['surname'] = $getclients->surname;
	    	$getclients_data[$idx]['mobile'] = $getclients->mobile;
	    	$getclients_data[$idx]['email'] = $getclients->email;
	    	$getclients_data[$idx]['last_email_job_no'] = $getclients->last_email_job_no;
	    	$getclients_data[$idx]['last_email_date'] = $getclients->last_email_date;
	    	$getclients_data[$idx]['number_emails'] = $getclients->number_emails;
	    	$getclients_data[$idx]['active'] = $getclients->active;
	    	$getclients_data[$idx]['clientname'] = $clientname_data[0]->name;
	    	$idx++;
	    }
    	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientTabMembers.php';
    }
		
	$output .= ob_get_contents();
	ob_end_clean();
	return $output;
}

add_filter('um_account_content_hook_clientanimal', 'um_account_content_hook_clientanimal');
function um_account_content_hook_clientanimal( $output ){
	ob_start();

	include_once  plugin_dir_path( __FILE__ ) . 'includes/cma_frontendanimals.php';
    $frontend_animals = new OCR_Front_end_animals();

    if($_GET['action'] == 'animal_description') {
     	$profile_id = um_profile_id(); 
		$user_meta = get_userdata($profile_id);
    	global $wpdb;
		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$user_meta->user_email."'"));
		$client_id=$get_clientid[0]->client_id;   	
    	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientAnimalDesc.php';
    }
    else {
    	$profile_id = um_profile_id(); 
		$user_meta = get_userdata($profile_id);
    	global $wpdb;
		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$user_meta->user_email."'"));
		$client_id=$get_clientid[0]->client_id;
		$current_company = $get_clientid[0]->client_id;
	    $get_jobnos = $frontend_animals->get_jobs($current_company);
		include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientAnimals.php';	
	}	
		
		
	$output .= ob_get_contents(); 
	ob_end_clean();
	return $output;
} 
add_filter('um_account_content_hook_clientjobs', 'um_account_content_hook_clientjobs');
function um_account_content_hook_clientjobs( $output ){
	ob_start();

	include_once  plugin_dir_path( __FILE__ ) . 'includes/cma-job_frontend.php';
    $job_frontend = new OCR_Front_end_job();

	if($_GET['action'] == 'add_job') {
		include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientAddJobs.php';
	}
	elseif($_GET['action'] == 'edit_job') {
		include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientEditJobs.php';
	}
	else {
		$profile_id = um_profile_id(); 
		$user_meta = get_userdata($profile_id);
		global $wpdb;
		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$user_meta->user_email."'"));
		$current_company = $get_clientid[0]->client_id;
		$jobs_data = $job_frontend->get_jobs($current_company);
		include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendClientJobs.php';
	}
	
				
		
	$output .= ob_get_contents();
	ob_end_clean();
	return $output;
}
add_filter('um_account_content_hook_clientemail', 'um_account_content_hook_clientemail');
function um_account_content_hook_clientemail( $output ){
	ob_start(); 


	include_once  plugin_dir_path( __FILE__ ) . 'includes/cma_frontendemailsupply.php';
    $frontend_emailsupply = new OCR_Front_end_emailsupply();
    $profile_id = um_profile_id(); 
	$user_meta = get_userdata($profile_id);
	global $wpdb;
	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$user_meta->user_email."'"));
	$current_company = $get_clientid[0]->client_id;
	$jobs_data_for_email = $frontend_emailsupply->get_jobs_for_emailsupply($current_company);
	include_once  plugin_dir_path( __FILE__ ) . 'template-parts/frontend/frontendEmailSupplier.php';


	$output .= ob_get_contents();
	ob_end_clean();
	return $output;
}


add_action('wp_footer','adding_frontend_scripts');

function adding_frontend_scripts() {
	?>
	<script>
		jQuery(document).ready(function() {
        var animalsel_base_url="<?php echo get_bloginfo('wpurl');?>";
        var ajax_url=animalsel_base_url+"/wp-admin/admin-ajax.php";
			jQuery('.um_edit_member_sav_det').click(function() {
				jQuery('.editmembergifmodal').css('display','block');
				var member_id = jQuery('.um_member_id').val();
				var current_company = jQuery('.current_company').val();
				var um_edit_member_fst_name = jQuery('.um_edit_member_fst_name').val();
				var um_edit_member_sur_name = jQuery('.um_edit_member_sur_name').val();
				var um_edit_member_password = jQuery('.um_edit_member_password').val();
				var um_edit_member_mobile = jQuery('.um_edit_member_mobile').val();
				var um_edit_member_email = jQuery('.um_edit_member_email').val();
				var um_edit_member_lst_email = jQuery('.um_edit_member_lst_email').val();
				var um_edit_member_lst_email_date = jQuery('.um_edit_member_lst_email_date').val();
				var um_edit_member_num_emails = jQuery('.um_edit_member_num_emails').val();
				var um_edit_member_active_det = jQuery('.um_edit_member_active_det').val();
				if(um_edit_member_fst_name != '' && um_edit_member_sur_name != '' && um_edit_member_password != '' && um_edit_member_mobile != '' && um_edit_member_email != '' && um_edit_member_active_det != '') {
					jQuery.ajax({
		                    type: 'POST',
		                    dataType: 'json',
		                    url: ajax_url,
		                    data: {
		                      action: 'frontendeditmember',
		                      member_id: member_id,
		                      current_company: current_company,
		                      um_edit_member_fst_name: um_edit_member_fst_name,
		                      um_edit_member_sur_name: um_edit_member_sur_name,
		                      um_edit_member_password: um_edit_member_password,
		                      um_edit_member_mobile: um_edit_member_mobile,
		                      um_edit_member_email: um_edit_member_email,
		                      um_edit_member_lst_email: um_edit_member_lst_email,
		                      um_edit_member_lst_email_date: um_edit_member_lst_email_date,
		                      um_edit_member_num_emails: um_edit_member_num_emails,
		                      um_edit_member_active_det: um_edit_member_active_det
		                    },
		                    success: function(response) {
		                      console.log(response);
		                      if(response == "success") {
		                      	window.location.href = animalsel_base_url+"/um_my-account/clientmembers";
		                      	jQuery('.editmembergifmodal').css('display','none');
		                      }
		                    }, 
		                    error: function(xhr, status, error,response) {
		                       console.log(error);
		                       var err = eval("(" + xhr.responseText + ")");
		                       console.log(xhr);
		                    }
	      			});
				}
      			else{

      				jQuery('.editmembergifmodal').css('display','none');
      				jQuery('.editmember-error').css('display','block');
      				window.scrollTo(0,0);
      			}

			});
 

			jQuery('.um_Del_img').click(function() {
				var id = jQuery(this).attr('data-id');
				jQuery('.delmembergifmodal').css('display','block');
				jQuery.ajax({
	                    type: 'POST',
	                    dataType: 'json',
	                    url: ajax_url,
	                    data: {
	                      action: 'frontenddeletemember',
	                      id: id	                      
	                    },
	                    success: function(response) {
	                      console.log(response);
	                      if(response == "success") {
	                      	window.location.href = animalsel_base_url+"/um_my-account/clientmembers";
	                      	jQuery('.delmembergifmodal').css('display','none');
	                      }
	                    }, 
	                    error: function(xhr, status, error,response) {
	                       console.log(error);
	                       var err = eval("(" + xhr.responseText + ")");
	                       console.log(xhr);
	                    }
      			});


			});

			jQuery('.um_add_member_sav_det').click(function() {
				jQuery('.addmembergifmodal').css('display','block');
				var current_company = jQuery('.current_company').val();
				var um_add_member_fst_name = jQuery('.um_add_member_fst_name').val();
				var um_add_member_sur_name = jQuery('.um_add_member_sur_name').val();
				var um_add_member_mobile = jQuery('.um_add_member_mobile').val();
				var um_add_member_email = jQuery('.um_add_member_email').val();
				var um_add_member_password = jQuery('.um_add_member_password').val();
				var um_add_member_level = jQuery('.um_add_member_level').val();
				var um_add_member_lst_email = jQuery('.um_add_member_lst_email').val();
				var um_add_member_lst_email_date = jQuery('.um_add_member_lst_email_date').val();
				var um_add_member_num_emails = jQuery('.um_add_member_num_emails').val();
				var um_add_member_active_det = jQuery('.um_add_member_active_det').val();

				if(um_add_member_fst_name != '' && um_add_member_sur_name != '' && um_add_member_mobile != '' && um_add_member_email != '' && um_add_member_password != '' && um_add_member_level != '' && um_add_member_active_det != '') {

					jQuery('.addmember-error').css('display','none');  

					jQuery.ajax({
	                    type: 'POST',
	                    dataType: 'json',
	                    url: ajax_url,
	                    data: {
	                      action: 'frontendaddmember',
	                      current_company: current_company,	                      
	                      um_add_member_fst_name: um_add_member_fst_name,	                      
	                      um_add_member_sur_name: um_add_member_sur_name,	                      
	                      um_add_member_mobile: um_add_member_mobile,	                      
	                      um_add_member_email: um_add_member_email,	                      
	                      um_add_member_password: um_add_member_password,	                      
	                      um_add_member_level: um_add_member_level,	                      
	                      um_add_member_lst_email: um_add_member_lst_email,	                      
	                      um_add_member_lst_email_date: um_add_member_lst_email_date,	                      
	                      um_add_member_num_emails: um_add_member_num_emails,	                      
	                      um_add_member_active_det: um_add_member_active_det                      
	                    },
	                    success: function(response) {
	                      console.log(response);
	                      if(response == "success") {
	                      	window.location.href = animalsel_base_url+"/um_my-account/clientmembers";
	                      	jQuery('.addmembergifmodal').css('display','none');
	                      }
	                    }, 
	                    error: function(xhr, status, error,response) {
	                       console.log(error);
	                       var err = eval("(" + xhr.responseText + ")");
	                       console.log(xhr);
	                    }
      				}); 

				}
				else {

					jQuery('.addmembergifmodal').css('display','none');
					jQuery('.addmember-error').css('display','block');
					window.scrollTo(0, 0);

				}



			});

			jQuery('.um_add_job_sav_det').click(function() {
				jQuery('.addjobgifmodal').css('display','block');
				var um_add_job_extension = jQuery('.um_add_job_extension').val();
				var um_add_job_project = jQuery('.um_add_job_project').val();
				var um_add_job_customer_name = jQuery('.um_add_job_customer_name').val();
				var um_add_address1 = jQuery('.um_add_address1').val();
				var um_add_address2 = jQuery('.um_add_address2').val();
				var um_add_job_city = jQuery('.um_add_job_city').val();
				var um_add_job_state = jQuery('.um_add_job_state').val();
				var um_add_job_site_address = jQuery('.um_add_job_site_address').val();
				var um_add_job_delivery_inst = jQuery('.um_add_job_delivery_inst').val();
				var um_add_job_date = jQuery('.um_add_job_date').val();
				var um_add_job_lst_email_date = jQuery('.um_add_job_lst_email_date').val();

				if(um_add_job_extension != '') {

					jQuery('.addjob-error').css('display','none');

					jQuery.ajax({
	                    type: 'POST',
	                    dataType: 'json',
	                    url: ajax_url,
	                    data: {
	                      action: 'frontendaddjob',
	                      um_add_job_extension: um_add_job_extension,	                      
	                      um_add_job_project: um_add_job_project,	                      
	                      um_add_job_customer_name: um_add_job_customer_name,	                      
	                      um_add_address1: um_add_address1,	                      
	                      um_add_address2: um_add_address2,	                      
	                      um_add_job_city: um_add_job_city,	                      
	                      um_add_job_state: um_add_job_state,	                      
	                      um_add_job_site_address: um_add_job_site_address,	                      
	                      um_add_job_delivery_inst: um_add_job_delivery_inst,	                      
	                      um_add_job_date: um_add_job_date,	                      
	                      um_add_job_lst_email_date: um_add_job_lst_email_date                                       
	                    },
	                    success: function(response) {
	                      console.log(response);
	                      if(response == "success") {
	                      	window.location.href=animalsel_base_url+"/um_my-account/clientjobs/";
	                      	jQuery('.addjobgifmodal').css('display','none');
	                      }	              
	                    }, 
	                    error: function(xhr, status, error,response) {
	                       console.log(error);
	                       var err = eval("(" + xhr.responseText + ")");
	                       console.log(xhr);
	                    }
      				});

				}
				else {
					jQuery('.addjobgifmodal').css('display','none');
					jQuery('.addjob-error').css('display','block');
					window.scrollTo(0, 0);
				}
				


			});

			jQuery('.um_Del_img_job').click(function() {

				var id = jQuery(this).attr('data-id');

				jQuery('.deljobgifmodal').css('display','block');

				jQuery.ajax({
	                    type: 'POST',
	                    dataType: 'json',
	                    url: ajax_url,
	                    data: {
	                      action: 'frontenddeletejob',
	                      id: id	                      
	                    },
	                    success: function(response) {
	                      console.log(response);
	                      if(response == "success") {
	                      	window.location.href = animalsel_base_url+"/um_my-account/clientjobs/";
	                      	jQuery('.deljobgifmodal').css('display','none');
	                      }
	                    }, 
	                    error: function(xhr, status, error,response) {
	                       console.log(error);
	                       var err = eval("(" + xhr.responseText + ")");
	                       console.log(xhr);
	                    }
      			});

			});

			jQuery('.um_add_editjob_sav_det').click(function() {
				jQuery('.editjobgifmodal').css('display','block');
				var job_id = jQuery('.job_id').val();
				var um_add_editjob_extension = jQuery('.um_add_editjob_extension').val();
				var um_add_editjob_project = jQuery('.um_add_editjob_project').val();
				var um_add_editjob_customer_name = jQuery('.um_add_editjob_customer_name').val();
				var um_add_address1 = jQuery('.um_add_address1').val();
				var um_add_address2 = jQuery('.um_add_address2').val();
				var um_add_editjob_city = jQuery('.um_add_editjob_city').val();
				var um_add_editjob_state = jQuery('.um_add_editjob_state').val();
				var um_add_editjob_site_address = jQuery('.um_add_editjob_site_address').val();
				var um_add_editjob_delivery_inst = jQuery('.um_add_editjob_delivery_inst').val();
				var um_add_editjob_date = jQuery('.um_add_editjob_date').val();
				var um_add_editjob_lst_email_date = jQuery('.um_add_editjob_lst_email_date').val();

				if(um_add_editjob_extension != '' && um_add_editjob_project != '' && um_add_editjob_customer_name != '' && um_add_address1 != '' && um_add_address2 != '' && um_add_editjob_city != '' && um_add_editjob_state != '' && um_add_editjob_site_address != '' && um_add_editjob_delivery_inst != '' && um_add_editjob_date != '' && um_add_editjob_lst_email_date != '') {

					jQuery('.editjob-error').css('display','none');

					jQuery.ajax({
	                    type: 'POST',
	                    dataType: 'json',
	                    url: ajax_url,
	                    data: {
	                      action: 'frontendeditjobsave',
	                      job_id: job_id,	                      
	                      um_add_editjob_extension: um_add_editjob_extension,	                      
	                      um_add_editjob_project: um_add_editjob_project,	                      
	                      um_add_editjob_customer_name: um_add_editjob_customer_name,	                      
	                      um_add_address1: um_add_address1,	                      
	                      um_add_address2: um_add_address2,	                      
	                      um_add_editjob_city: um_add_editjob_city,	                      
	                      um_add_editjob_state: um_add_editjob_state,	                      
	                      um_add_editjob_site_address: um_add_editjob_site_address,	                      
	                      um_add_editjob_delivery_inst: um_add_editjob_delivery_inst,	                      
	                      um_add_editjob_date: um_add_editjob_date,	                      
	                      um_add_editjob_lst_email_date: um_add_editjob_lst_email_date,	                      
	                    },
	                    success: function(response) {
	                      if(response == "success") {
	                      	window.location.href = animalsel_base_url+"/um_my-account/clientjobs/";
	                      	jQuery('.editjobgifmodal').css('display','none');
	                      }
	                    }, 
	                    error: function(xhr, status, error,response) {
	                       console.log(error);
	                       var err = eval("(" + xhr.responseText + ")");
	                       console.log(xhr);
	                    }
      				});

				}
				else {
					jQuery('.editjobgifmodal').css('display','none');
					jQuery('.editjob-error').css('display','block');
					window.scrollTo(0, 0);
				}



			});

			jQuery('.um-getanimals-btn').click(function() {

				var job_no = jQuery('.um-jobs-options').val();
				console.log(job_no);
				if(job_no != 'select' && job_no != '') {
					jQuery('.gifmodal').css('display','block');

					jQuery.ajax({
	                    type: 'POST',
	                    dataType: 'json',
	                    url: ajax_url,
	                    data: {
	                      action: 'frontendgetanimals',
	                      job_no: job_no	                      
	                    },
	                    success: function(data) {
	                      console.log(data);
	                      var filter_1=data[0]["filter_1"];
	                      var filter_2=data[1]["filter_2"];
	                      var response=data[2]["files"];
	                      if(filter_1!=""){
						  jQuery(".um-show-filterbtnfilter1").each(function(i, obj) {
								if(jQuery.trim(jQuery(this).text())==filter_1){
			                      jQuery(this).trigger("click");
								}
							});	 	                      	
	                      }
	                      if(filter_2!=""){
						  jQuery(".um-show-filterbtnfilter2").each(function(i, obj) {
								if(jQuery.trim(jQuery(this).text())==filter_2){
			                      jQuery(this).trigger("click");
								}
							});		                      	
	                      }

							                     
	                      jQuery(".um-show-filterbtnfilter1").text()
	                      // jQuery('.gifmodal').css('display','none');
	                      // return;
	                      if(response != 'no_images') {
	                      	  jQuery('.um-jobno').css('display','none');
		                      jQuery('.um-job-choosen').text(job_no);
		                      jQuery('.um-job-selected').css('display','flex');
		                      jQuery('.selected-job-animals').css('display','block');
		      				  for(var i = 0; i < response.length;i++) {
		      				  	let file_name = response[i]['filename'];
		      				  	if(response[i]['filename'] != '') {
		      				  		var file = file_name.replace("/home3/sbsofkvq/", "https://");
									const file_array = file_name.split("/");
									var filename = file_array[8].replace(".jpg", "");
		      				  	}
								else {
									var file = file_name.replace("/home3/sbsofkvq/", "https://");
								}

								var id=response[i]["id"];
								if(id==undefined){
									id="";
								}
								var clientid=response[i]["clientid"];
								if(clientid==undefined){
									clientid="";
								}								
								var color=response[i]["color"];
								if(color==undefined){
									color="";
								}								
								var coating=response[i]["coating"];
								if(coating==undefined){
									coating="";
								}									
								var thickness=response[i]["thickness"];
								if(thickness==undefined){
									thickness="";
								}
								var type=response[i]["type"];
								if(type==undefined){
									type="";
								}																	
								var no_of=response[i]["no_of"];
								if(no_of==undefined){
									no_of="";
								}		
								var size_of=response[i]["size_of"];
								if(size_of==undefined){
									size_of="";
								}	
								var reference=response[i]["reference"];
								if(reference==undefined){
									reference="";
								}																								
								var option_a_val=response[i]["option_a_val"];
								if(option_a_val==undefined){
									option_a_val="";
								}	
								var option_a_def=response[i]["option_a_def"];
								if(option_a_def==undefined){
									option_a_def="";
									var option_a_def_val='data-a-def="'+option_a_def+'"';
								}else{
									var option_a_def_val='data-a-def="'+option_a_def+'"';
								}

								var option_b_val=response[i]["option_b_val"];
								if(option_b_val==undefined){
									option_b_val="";
								}	
								var option_b_def=response[i]["option_b_def"];
								if(option_b_def==undefined){
									option_b_def="";
									var option_b_def_val='data-b-def="'+option_b_def+'"';								
								}else{
									var option_b_def_val='data-b-def="'+option_b_def+'"';
								}
																
								var option_c_val=response[i]["option_c_val"];
								if(option_c_val==undefined){
									option_c_val="";
								}		
								var option_c_def=response[i]["option_c_def"];
								if(option_c_def==undefined){
									option_c_def="";
									var option_c_def_val='data-c-def="'+option_c_def+'"';
								}else{
									var option_c_def_val='data-c-def="'+option_c_def+'"';
								}
	

								var option_d_val=response[i]["option_d_val"];
								if(option_d_val==undefined){
									option_d_val="";
								}
		
								var option_d_def=response[i]["option_d_def"];
								if(option_d_def==undefined){
									option_d_def="";
									var option_d_def_val='data-d-def="'+option_d_def+'"';									
								}else{
									var option_d_def_val='data-d-def="'+option_d_def+'"';
								}	

								var option_e_val=response[i]["option_e_val"];
								if(option_e_val==undefined){
									option_e_val="";
								}		
								var option_e_def=response[i]["option_e_def"];
								if(option_e_def==undefined){
									option_e_def="";
									var option_e_def_val='data-e-def="'+option_e_def+'"';	
								}else{
									var option_e_def_val='data-e-def="'+option_e_def+'"';
								}	

								var option_f_val=response[i]["option_f_val"];
								if(option_f_val==undefined){
									option_f_val="";
								}		
								var option_f_def=response[i]["option_f_def"];
								if(option_f_def==undefined){
									option_f_def="";
									var option_f_def_val='data-e-def="'+option_f_def+'"';	
								}else{
									var option_f_def_val='data-f-def="'+option_f_def+'"';
								}	

								var option_g_val=response[i]["option_g_val"];
								if(option_g_val==undefined){
									option_g_val="";
								}		

								var option_g_def=response[i]["option_g_def"];
								if(option_g_def==undefined){
									option_g_def="";
									var option_g_def_val='data-e-def="'+option_g_def+'"';									
								}else{
									var option_g_def_val='data-g-def="'+option_g_def+'"';
								}	

								var option_p_val=response[i]["option_p_val"];
								if(option_p_val==undefined){
									option_p_val="";
								}			
								var option_p_def=response[i]["option_p_def"];
								if(option_p_def==undefined){
									option_p_def="";
									var option_p_def_val='data-p-def="'+option_p_def+'"';									
								}else{
									var option_p_def_val='data-p-def="'+option_p_def+'"';
								}

								var option_v_val=response[i]["option_v_val"];
								if(option_v_val==undefined){
									option_v_val="";
								}	
								var option_v_def=response[i]["option_v_def"];
								if(option_v_def==undefined){
									option_v_def="";
									var option_v_def_val='data-v-def="'+option_v_def+'"';
								}else{
									var option_v_def_val='data-v-def="'+option_v_def+'"';
								}																	
								var option_w_val=response[i]["option_w_val"];
								if(option_w_val==undefined){
									option_w_val="";
								}			
								var option_w_def=response[i]["option_w_def"];
								if(option_w_def==undefined){
									option_w_def="";
									var option_w_def_val='data-w-def="'+option_w_def+'"';									
								}else{
									var option_w_def_val='data-w-def="'+option_w_def+'"';
								}	

								var option_x_val=response[i]["option_x_val"];
								if(option_x_val==undefined){
									option_x_val="";
								}		

								var option_x_def=response[i]["option_x_def"];
								if(option_x_def==undefined){
									option_x_def="";
									var option_x_def_val='data-x-def="'+option_x_def+'"';									
								}else{
									var option_x_def_val='data-x-def="'+option_x_def+'"';
								}																
								var option_y_val=response[i]["option_y_val"];
								if(option_y_val==undefined){
									option_y_val="";
								}		
								var option_y_def=response[i]["option_y_def"];
								if(option_y_def==undefined){
									option_y_def="";
									var option_y_def_val='data-y-def="'+option_y_def+'"';									
								}else{
									var option_y_def_val='data-y-def="'+option_y_def+'"';
								}	

								var option_z_val=response[i]["option_z_val"];
								if(option_z_val==undefined){
									option_z_val="";
								}	

								var option_z_def=response[i]["option_z_def"];
								if(option_z_def==undefined){
									option_z_def="";
									var option_z_def_val='data-z-def="'+option_z_def+'"';									
								}else{
									var option_z_def_val='data-z-def="'+option_z_def+'"';
								}	

								if(response[i]["option_a"]=="yes"){
                                  var option_a='data-a="'+option_a_val+'"';

								}else{
                                  var option_a="";
								}
								if(response[i]["option_b"]=="yes"){
                                  var option_b='data-b="'+option_b_val+'"';
								}else{
                                  var option_b="";
								}                                 
								if(response[i]["option_c"]=="yes"){
                                  var option_c='data-c="'+option_c_val+'"';
								}else{
                                  var option_c="";
								}
								if(response[i]["option_d"]=="yes"){
                                  var option_d='data-d="'+option_d_val+'"';
								}else{
                                  var option_d="";
								}
								if(response[i]["option_e"]=="yes"){
                                  var option_e='data-e="'+option_e_val+'"';
								}else{
                                  var option_e="";
								}
								if(response[i]["option_f"]=="yes"){
                                  var option_f='data-f="'+option_f_val+'"';
								}else{
                                  var option_f="";
								}
								if(response[i]["option_g"]=="yes"){
                                  var option_g='data-g="'+option_g_val+'"';
								}else{
                                  var option_g="";
								}
								if(response[i]["option_p"]=="yes"){
                                  var option_p='data-p="'+option_p_val+'"';
								}else{
                                  var option_p="";
								}															
								if(response[i]["option_v"]=="yes"){
                                  var option_v='data-v="'+option_v_val+'"';
								}else{
                                  var option_v="";
								}
								if(response[i]["option_w"]=="yes"){
                                  var option_w='data-w="'+option_w_val+'"';
								}else{
                                  var option_w="";
								}
								if(response[i]["option_x"]=="yes"){
                                  var option_x='data-x="'+option_x_val+'"';
								}else{
                                  var option_x="";
								}										
								if(response[i]["option_y"]=="yes"){
                                  var option_y='data-y="'+option_y_val+'"';
								}else{
                                  var option_y="";
								}	
								if(response[i]["option_z"]=="yes"){
                                  var option_z='data-z="'+option_z_val+'"';
								}else{
                                  var option_z="";
								}



		      				  	jQuery('.show-animals-images').append('<div class="animal-img"><input type="hidden" class="img-clicked" value="no"><input type="hidden" class="img_data_store img_data_'+id+'" data-id="'+id+'" data-clientid="'+clientid+'" data-jobno="'+job_no+'" data-color="'+color+'" data-coating="'+coating+'" data-thickness="'+thickness+'" data-type="'+type+'" '+option_a+' '+option_a_def_val+' '+option_b+' '+option_b_def_val+' '+option_c+' '+option_c_def_val+' '+option_d+' '+option_d_def_val+' '+option_e+' '+option_e_def_val+' '+option_f+' '+option_f_def_val+' '+option_g+' '+option_g_def_val+' '+option_p+' '+option_p_def_val+' '+option_v+' '+option_v_def_val+' '+option_w+' '+option_w_def_val+' '+option_x+' '+option_x_def_val+' '+option_y+' '+option_y_def_val+' '+option_z+' '+option_z_def_val+'data-size="'+size_of+'" data-noof="'+no_of+'" data-ref="'+reference+'"><div class="img-bg"><img width="250" height="200" src="'+file+'" class="job-images"></div><div class="overlay"><a class="check-icon"><i class="fa fa-check"></i></a></div><div class="overlay_remove"><a class="check-icon-remove"><i class="fa fa-times"></i></a></div><div class="overlay_view"><a class="check-icon-view" data-animal="'+response[i]["file_name"]+'" data-id="'+id+'" data-clientid="'+clientid+'"><i class="fa fa-eye"></i></a></div><p class="img-name" style="margin: 0!important;padding-left: 4px !important;">'+response[i]["file_name"]+'</p><span class="tickmark">&#10004;</span></div>');
		      				  	if(response[i]['directview'] == 'yes') {
		      				  		var view = 'yes';
		      				  	}

		      				  }
		      				  jQuery('.um-animal-fields').append('<div class="save_animals_container"><div class="animals-save"><button type="button" class="upload_ok">Upload My Image</button><button type="button" class="return-job-animals">Return To Main Menu</button><button type="button" class="save-job-animals" saved-images="true">Save Selection</button></div></div>');
		      				  jQuery('.um-getanimal-err').css('display','none');
		      				  jQuery('.gifmodal').css('display','none');
		      				  if(view == 'yes') {
		      				  	jQuery('.img-clicked').val('yes');
		      				  }
	                      }
	                      else {
	                      	jQuery('.gifmodal').css('display','none');
	                      	console.log('no images for this job id');
	                      }
	                      
	                      if(jQuery(".animal-img").find(".img-clicked").val()=="yes")
	                      {
	                      	jQuery(".animal-img").css("background","#EFEE22");
	                      }
	      				     
	                    }, 
	                    error: function(xhr, status, error,response) {
	                       console.log(error);
	                       var err = eval("(" + xhr.responseText + ")");
	                       console.log(xhr);
	                    }
	                      
      				});

				}
				else {
					jQuery('.um-getanimal-err').css('display','block');
				}

			}); 

			jQuery(document).on('click','.return-job-animals',function() {
				var selected_img_count=0;
				jQuery(".img-clicked").each(function(i, obj) {
					if(jQuery(this).val()=="yes"){
                      selected_img_count++;
					}
				});
				if(selected_img_count==0){
					jQuery(".save-job-animals").attr('saved-images','true');
				}
				var saved_images =jQuery(".save-job-animals").attr('saved-images');

				location.reload();					

			});

			jQuery(document).on('mouseover','.animal-img',function() {
				var img_selected = jQuery(this).find('.img-clicked').val();
				if(img_selected == 'no') {
					jQuery(this).find('.overlay').css('opacity','1');
					
				}
				if(img_selected == 'yes') {
					jQuery(this).find('.overlay_remove').css('opacity','1');
					jQuery(this).find('.overlay_view').css('opacity','1');
					
				}

			});
			jQuery(document).on('mouseout','.animal-img',function() {
				jQuery(this).find('.overlay').css('opacity','0');
				jQuery(this).find('.overlay_remove').css('opacity','0');
				jQuery(this).find('.overlay_view').css('opacity','0');
				jQuery(this).find('.job-images').css('background','');
			});

			jQuery(document).on('click','.check-icon',function() {
				jQuery(".img-clicked").each(function(i, obj) {
                 jQuery(this).val('no');
				 jQuery(this).parent().css("background","revert");                 
				});					
			
				var saved_images =jQuery(".save-job-animals").attr('saved-images','false');
				jQuery(this).parent().parent().find('.img-clicked').val('yes');
				if(jQuery(this).parent().parent().find('.img-clicked').val()=='yes'){
				  jQuery(this).parent().parent().css("background","#EFEE22");
				}
				var job_id = jQuery('.um-jobs-options').val();
				var id = jQuery('.um-jobs-options').val();
				var clientid = jQuery('.um-jobs-options').val();
				jQuery('img_data_'+id).attr('data-id',id);
				jQuery('img_data_'+id).attr('data-clientid',clientid);
				jQuery('img_data_'+id).attr('data-jobno',job_id);

				
			});

			jQuery(document).on('click','.check-icon-remove',function() {
				jQuery(this).parent().parent().find('.img-clicked').val('no');
				if(jQuery(this).parent().parent().find('.img-clicked').val()=='no'){
				  	jQuery(this).parent().parent().css("background","revert");
				}				
			});

			jQuery(document).on('click','.check-icon-view',function() {
				jQuery('.frnt-save-msg').css('display','none'); 
                jQuery('.popup_options').css("display","none");
	            jQuery('.view-optiona input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionb input').removeClass('model_mandatory_field');
	            jQuery('.view-optionc input').removeClass('model_mandatory_field');	
	            jQuery('.view-optiond input').removeClass('model_mandatory_field');	
	            jQuery('.view-optione input').removeClass('model_mandatory_field');
	            jQuery('.view-optionf input').removeClass('model_mandatory_field');
	            jQuery('.view-optiong input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionp input').removeClass('model_mandatory_field');
	            jQuery('.view-optionv input').removeClass('model_mandatory_field');
	            jQuery('.view-optionw input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionx input').removeClass('model_mandatory_field');
	            jQuery('.view-optiony input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionz input').removeClass('model_mandatory_field');		                        	            	                        

				// jQuery('.gifmodal').css('display','block');
				var animal = jQuery(this).attr('data-animal');
				var id = jQuery(this).attr('data-id');			
				var clientid = jQuery(this).attr('data-clientid');	
				var job_id = jQuery('.um-jobs-options').val();
				var jobid = jQuery('.img_data_'+id).attr('data-jobno');
	            var color = jQuery('.img_data_'+id).attr('data-color');
	            var coating = jQuery('.img_data_'+id).attr('data-coating');
	            var thickness = jQuery('.img_data_'+id).attr('data-thickness');
	            var type = jQuery('.img_data_'+id).attr('data-type');
	            var opta_def = jQuery('.img_data_'+id).attr('data-a-def');
	            var optb_def = jQuery('.img_data_'+id).attr('data-b-def');
	            var optc_def = jQuery('.img_data_'+id).attr('data-c-def');
	            var optd_def = jQuery('.img_data_'+id).attr('data-d-def');
	            var opte_def = jQuery('.img_data_'+id).attr('data-e-def');
	            var optf_def = jQuery('.img_data_'+id).attr('data-f-def');
	            var optg_def = jQuery('.img_data_'+id).attr('data-g-def');	  
	            var optp_def = jQuery('.img_data_'+id).attr('data-p-def');	 	                      
	            var optv_def = jQuery('.img_data_'+id).attr('data-v-def');
	            var optw_def = jQuery('.img_data_'+id).attr('data-w-def');
	            var optx_def = jQuery('.img_data_'+id).attr('data-x-def');
	            var opty_def = jQuery('.img_data_'+id).attr('data-y-def');
	            var optz_def = jQuery('.img_data_'+id).attr('data-z-def');
	            var size = jQuery('.img_data_'+id).attr('data-size');
	            var noof = jQuery('.img_data_'+id).attr('data-noof');
	            var ref = jQuery('.img_data_'+id).attr('data-ref');

                var img_src=jQuery('.img_data_'+id).parent().find(".job-images").attr("src");
                 jQuery(".current_animal_img_view").attr("src",img_src);
	             jQuery('.view_details').val(clientid);                     
	             jQuery('.view_details').attr('data-id',id); 
	             jQuery('.modal_color').val("");
	             jQuery('.modal_coating').val("");
	             jQuery('.modal_thickness').val("");
	             jQuery('.modal_type').val("");
	             jQuery('.modal_optiona').val(opta_def);
	             jQuery('.modal_optionb').val(optb_def);
	             jQuery('.modal_optionc').val(optc_def);
	             jQuery('.modal_optiond').val(optd_def);
	             jQuery('.modal_optione').val(opte_def);
	             jQuery('.modal_optionf').val(optf_def);
	             jQuery('.modal_optiong').val(optg_def);
	             jQuery('.modal_optionp').val(optp_def);	             
	             jQuery('.modal_optionv').val(optv_def);
	             jQuery('.modal_optionw').val(optw_def);
	             jQuery('.modal_optionx').val(optx_def);
	             jQuery('.modal_optiony').val(opty_def);
	             jQuery('.modal_optionz').val(optz_def);
	             jQuery('.modal_size').val("");
	             jQuery('.modal_noof').val("");
	             jQuery('.modal_ref').val("");
	             jQuery('.modal_client').val(job_id); 

                console.log(id);

				if (typeof jQuery('.img_data_'+id).data('a') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optiona').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optiona input').addClass('model_mandatory_field');	
				} 				 
				if (typeof jQuery('.img_data_'+id).data('b') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optionb').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optionb input').addClass('model_mandatory_field');	
				}              
				if (typeof jQuery('.img_data_'+id).data('c') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optionc').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optionc input').addClass('model_mandatory_field');
				}  
				if (typeof jQuery('.img_data_'+id).data('d') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optiond').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optiond input').addClass('model_mandatory_field');	
				}              
				if (typeof jQuery('.img_data_'+id).data('e') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optione').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optione input').addClass('model_mandatory_field');
				}  
				if (typeof jQuery('.img_data_'+id).data('f') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optionf').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optionf input').addClass('model_mandatory_field');	
				}              
				if (typeof jQuery('.img_data_'+id).data('g') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optiong').css('display','flex');
	                jQuery('.viewanimal_modal .view-optiong input').addClass('model_mandatory_field');	
				}  		
				if (typeof jQuery('.img_data_'+id).data('p') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optionp').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optionp input').addClass('model_mandatory_field');	
				}  
				if (typeof jQuery('.img_data_'+id).data('v') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optionv').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optionv input').addClass('model_mandatory_field');
				}              
				if (typeof jQuery('.img_data_'+id).data('w') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optionw').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optionw input').addClass('model_mandatory_field');
				}  
				if (typeof jQuery('.img_data_'+id).data('x') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optionx').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optionx input').addClass('model_mandatory_field');	
				}  
				if (typeof jQuery('.img_data_'+id).data('y') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optiony').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optiony input').addClass('model_mandatory_field');	
				}              
				if (typeof jQuery('.img_data_'+id).data('z') !== 'undefined') {
	             	jQuery('.viewanimal_modal .view-optionz').css('display','flex');
	             	jQuery('.viewanimal_modal .view-optionz input').addClass('model_mandatory_field');
				}  
				if(jQuery(this).parent().parent().find('.img-clicked').val()=='yes'){
	             jQuery('#viewanimal').css('display','block');	
				}             

			});

			jQuery('.viewanimal-close').click(function() {
				jQuery('#viewanimal').css('display','none'); 
	            jQuery('.view-optiona input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionb input').removeClass('model_mandatory_field');
	            jQuery('.view-optionc input').removeClass('model_mandatory_field');	
	            jQuery('.view-optiond input').removeClass('model_mandatory_field');	
	            jQuery('.view-optione input').removeClass('model_mandatory_field');
	            jQuery('.view-optionf input').removeClass('model_mandatory_field');
	            jQuery('.view-optiong input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionp input').removeClass('model_mandatory_field');
	            jQuery('.view-optionv input').removeClass('model_mandatory_field');
	            jQuery('.view-optionw input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionx input').removeClass('model_mandatory_field');
	            jQuery('.view-optiony input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionz input').removeClass('model_mandatory_field');					
			});

			jQuery('.view_save').click(function() {
	            jQuery(".frnt-end-error-msg").css("display","none");
				jQuery('.frnt-save-msg').css('display','none'); 				
				var animal_sno = jQuery('.view_details').attr('data-id');
				console.log("animalno"+animal_sno);
				var clientid = jQuery('.view_details').val();
				var job_no = jQuery('.modal_client').val();
				var modal_color = jQuery('.modal_color').val();
				var modal_coating = jQuery('.modal_coating').val();
				var modal_thickness = jQuery('.modal_thickness').val();
				var modal_type = jQuery('.modal_type').val();
				var modal_optiona = jQuery('.modal_optiona').val();
				var modal_optionb = jQuery('.modal_optionb').val();
				var modal_optionc = jQuery('.modal_optionc').val();
				var modal_optiond = jQuery('.modal_optiond').val();
				var modal_optione = jQuery('.modal_optione').val();
				var modal_optionf = jQuery('.modal_optionf').val();
				var modal_optiong = jQuery('.modal_optiong').val();
				var modal_optionp = jQuery('.modal_optionp').val();				
				var modal_optionv = jQuery('.modal_optionv').val();
				var modal_optionw = jQuery('.modal_optionw').val();
				var modal_optionx = jQuery('.modal_optionx').val();
				var modal_optiony = jQuery('.modal_optiony').val();
				var modal_optionz = jQuery('.modal_optionz').val();
				var modal_size = jQuery('.modal_size').val();
				var modal_noof = jQuery('.modal_noof').val();
				// var modal_ref = jQuery('.modal_ref').val();
                               
				if (typeof jQuery('.img_data_'+animal_sno).data('id') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-id',animal_sno);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('clientid') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-clientid',clientid);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('jobno') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-jobno',job_no);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('color') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-color',modal_color);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('coating') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-coating',modal_coating);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('thickness') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-thickness',modal_thickness);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('type') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-type',modal_type);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('a') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-a',modal_optiona);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('b') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-b',modal_optionb);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('c') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-c',modal_optionc);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('d') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-d',modal_optiond);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('e') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-e',modal_optione);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('f') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-f',modal_optionf);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('g') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-g',modal_optiong);
				}  		
				if (typeof jQuery('.img_data_'+animal_sno).data('p') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-p',modal_optionp);	
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('v') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-v',modal_optionv);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('w') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-w',modal_optionw);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('x') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-x',modal_optionx);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('y') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-y',modal_optiony);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('z') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-z',modal_optionz);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('size') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-size',modal_size);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('noof') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-noof',modal_noof);
				}              
				// if (typeof jQuery('.img_data_'+animal_sno).data('ref') !== 'undefined') {
				// jQuery('.img_data_'+animal_sno).attr('data-ref',modal_ref);
				// } 

				var bool=false;

               if(jQuery(".viewanimal_modal .model_mandatory_field").is(":visible")){
	 				jQuery(".viewanimal_modal .model_mandatory_field").each(function(){
	 					var current_val=jQuery(this).val();
	 					console.log(current_val);
		                 if(current_val==""){
		                    bool=true;
		                 }
	                });   
               }
				console.log(bool);
                if(bool==true){               	
                	   jQuery(".frnt-end-error-msg").css("display","block");
                	   return;
                }else{
				       jQuery('.frnt-save-msg').css('display','block');                 	
	                   jQuery(".frnt-end-error-msg").css("display","none");
					   setTimeout( function(){ 
				       jQuery('#viewanimal').css('display','none'); 
						  }  , 1000 );	                   
					       
                }
             jQuery(".save-job-animals").trigger("click");
			});

			jQuery('.upload_view_save').click(function() {
	            jQuery(".upload-modal-content .frnt-end-error-msg").css("display","none");
				
				var animal_sno = jQuery('.upload-modal-content .view_details').attr('data-id');
				console.log("animalno"+animal_sno);
				var clientid = jQuery('.upload-modal-content .view_details').val();
				var job_no = jQuery('.upload-modal-content .modal_client').val();
				var modal_color = jQuery('.upload-modal-content .modal_color').val();
				var modal_coating = jQuery('.upload-modal-content .modal_coating').val();
				var modal_thickness = jQuery('.upload-modal-content .modal_thickness').val();
				var modal_type = jQuery('.upload-modal-content .modal_type').val();
				var modal_optiona = jQuery('.upload-modal-content .modal_optiona').val();
				var modal_optionb = jQuery('.upload-modal-content .modal_optionb').val();
				var modal_optionc = jQuery('.upload-modal-content .modal_optionc').val();
				var modal_optiond = jQuery('.upload-modal-content .modal_optiond').val();
				var modal_optione = jQuery('.upload-modal-content .modal_optione').val();
				var modal_optionf = jQuery('.upload-modal-content .modal_optionf').val();
				var modal_optiong = jQuery('.upload-modal-content .modal_optiong').val();
				var modal_optionp = jQuery('.upload-modal-content .modal_optionp').val();				
				var modal_optionv = jQuery('.upload-modal-content .modal_optionv').val();
				var modal_optionw = jQuery('.upload-modal-content .modal_optionw').val();
				var modal_optionx = jQuery('.upload-modal-content .modal_optionx').val();
				var modal_optiony = jQuery('.upload-modal-content .modal_optiony').val();
				var modal_optionz = jQuery('.upload-modal-content .modal_optionz').val();
				var modal_size = jQuery('.upload-modal-content .modal_size').val();
				var modal_noof = jQuery('.upload-modal-content .modal_noof').val();
				// var modal_ref = jQuery('.modal_ref').val();
                               
				if (typeof jQuery('.img_data_'+animal_sno).data('jobno') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-jobno',job_no);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('color') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-color',modal_color);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('coating') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-coating',modal_coating);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('thickness') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-thickness',modal_thickness);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('type') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-type',modal_type);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('a') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-a',modal_optiona);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('b') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-b',modal_optionb);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('c') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-c',modal_optionc);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('d') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-d',modal_optiond);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('e') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-e',modal_optione);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('f') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-f',modal_optionf);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('g') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-g',modal_optiong);
				}  		
				if (typeof jQuery('.img_data_'+animal_sno).data('p') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-p',modal_optionp);	
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('v') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-v',modal_optionv);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('w') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-w',modal_optionw);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('x') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-x',modal_optionx);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('y') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-y',modal_optiony);
				}              
				if (typeof jQuery('.img_data_'+animal_sno).data('z') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-z',modal_optionz);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('size') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-size',modal_size);
				}  
				if (typeof jQuery('.img_data_'+animal_sno).data('noof') !== 'undefined') {
				jQuery('.img_data_'+animal_sno).attr('data-noof',modal_noof);
				}              
				// if (typeof jQuery('.img_data_'+animal_sno).data('ref') !== 'undefined') {
				// jQuery('.img_data_'+animal_sno).attr('data-ref',modal_ref);
				// } 
			});

            jQuery(document).on('click','.upload_ok',function() {
		       jQuery(".current_animal_img").attr("src","");	
		       jQuery(".current_animal_img").css("display","none");             	
		       jQuery(".upld-frnt-save-msg").css("display","none");             	
         		jQuery('.up_fields').val("");       
				jQuery('.upload-modal').css("display","block");
				var job_id=jQuery('.um-job-choosen').text();
				jQuery('.modal_client').val(job_id);
				jQuery('.upload_image_container .viewanimal-modal').css("display","block");

            });
			jQuery(document).on('click','.upload-close',function() {

				jQuery('.upload-modal').css("display","none");
	            jQuery('.view-optiona input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionb input').removeClass('model_mandatory_field');
	            jQuery('.view-optionc input').removeClass('model_mandatory_field');	
	            jQuery('.view-optiond input').removeClass('model_mandatory_field');	
	            jQuery('.view-optione input').removeClass('model_mandatory_field');
	            jQuery('.view-optionf input').removeClass('model_mandatory_field');
	            jQuery('.view-optiong input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionp input').removeClass('model_mandatory_field');
	            jQuery('.view-optionv input').removeClass('model_mandatory_field');
	            jQuery('.view-optionw input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionx input').removeClass('model_mandatory_field');
	            jQuery('.view-optiony input').removeClass('model_mandatory_field');	
	            jQuery('.view-optionz input').removeClass('model_mandatory_field');	

			});	

            jQuery(document).on('click','.upload_image_ok',function() {
            jQuery(".upld-frnt-save-msg").css("display","none");
			var job_id=jQuery('.upload_image_container .modal_client').val();
			var client_id=jQuery('.img_data_store').attr('data-clientid');
			var fileSelect = document.getElementById('fileinput');
			var bool=false;

				var modal_color = jQuery('.upload_image_container .modal_color').val();
				var modal_coating = jQuery('.upload_image_container .modal_coating').val();
				var modal_thickness = jQuery('.upload_image_container .modal_thickness').val();
				var modal_type = jQuery('.upload_image_container .modal_type').val();
				var modal_optiona = jQuery('.upload_image_container .modal_optiona').val();
				var modal_optionb = jQuery('.upload_image_container .modal_optionb').val();
				var modal_optionc = jQuery('.upload_image_container .modal_optionc').val();
				var modal_optiond = jQuery('.upload_image_container .modal_optiond').val();
				var modal_optione = jQuery('.upload_image_container .modal_optione').val();
				var modal_optionf = jQuery('.upload_image_container .modal_optionf').val();
				var modal_optiong = jQuery('.upload_image_container .modal_optiong').val();
				var modal_optionp = jQuery('.upload_image_container .modal_optionp').val();				
				var modal_optionv = jQuery('.upload_image_container .modal_optionv').val();
				var modal_optionw = jQuery('.upload_image_container .modal_optionw').val();
				var modal_optionx = jQuery('.upload_image_container .modal_optionx').val();
				var modal_optiony = jQuery('.upload_image_container .modal_optiony').val();
				var modal_optionz = jQuery('.upload_image_container .modal_optionz').val();
				var modal_size = jQuery('.upload_image_container .modal_size').val();
				var modal_noof = jQuery('.upload_image_container .modal_noof').val();    			
             if(jQuery(".upload-modal-content .up_mandatory_field").is(":visible")){
	 		     jQuery(".upload-modal-content .up_mandatory_field").each(function(){
	 					var current_val=jQuery(this).val();
	 					console.log(current_val);
		                 if(current_val==""){
		                    bool=true;
		                 }
	              });   
             }

            if(bool==true){               	
                jQuery(".upload-modal-content .frnt-end-error-msg").css("display","block");
                return;
            }else{
	            jQuery(".upload-modal-content .frnt-end-error-msg").css("display","none");
            }

			var files = fileSelect.files;
		    var form = new FormData();  
		    for (var i = 0; i < files.length; i++) {
			   var file = files[i];
			  form.set('photos', file, file.name);
			 }   

			 form.append('action','custom_upload_img');
			 form.append('job_id',job_id);
			 form.append('client_id',client_id); 	
			 form.append('modal_color',modal_color);
			 form.append('modal_coating',modal_coating); 				 	    			
			 form.append('modal_thickness',modal_thickness); 	
			 form.append('modal_type',modal_type); 				 	    			
			 form.append('modal_optiona',modal_optiona); 				 	    			
			 form.append('modal_optionb',modal_optionb); 				 	    			
			 form.append('modal_optionc',modal_optionc); 				 	    			
			 form.append('modal_optiond',modal_optiond); 				 	    			
			 form.append('modal_optione',modal_optione); 				 	    			
			 form.append('modal_optionf',modal_optionf); 				 	    			
			 form.append('modal_optiong',modal_optiong); 				 	    			
			 form.append('modal_optionp',modal_optionp); 				 	    			
			 form.append('modal_optionv',modal_optionv); 				 	    			
			 form.append('modal_optionx',modal_optionx); 				 	    			
			 form.append('modal_optiony',modal_optiony); 				 	    			
			 form.append('modal_optionz',modal_optionz); 				 	    			
			 form.append('modal_size',modal_size); 				 	    			
			 form.append('modal_noof',modal_noof); 				 	    						 	    			
			             jQuery.ajax({
			                type: 'POST',
		                    url: animalsel_base_url+'/wp-admin/admin-ajax.php',
		                    data: form, 
		                    dataType: 'json',
		                    contentType: false,
		                    processData: false,                
			                success: function(response){
			                  var data = response;
			                  console.log(response);
	                          jQuery('.view_details').attr('data-id',response[0]["id"]);	
		      				  	let file_name = response[0]['handle'];

								var file = file_name.replace("/home3/sbsofkvq/", "https://");
								// const file_array = file_name.split("/");
								// var filename = file_array[8].replace(".jpg", "");			                  	      				  	
			                  // jQuery('.show-animals-images').append('<div class="animal-img"><input type="hidden" class="img-clicked" value="no"><input type="hidden" class="img_data_store img_data_'+response[0]["id"]+'" data-id="'+response[0]["id"]+'" data-clientid="'+response[0]["clientid"]+'" data-jobno="'+response[0]["job_id"]+'" data-color="" data-coating="" data-thickness="" data-type="" data-a="" data-b="" data-c="" data-d="" data-e="" data-f="" data-g="" data-p="" data-v="" data-w="" data-x="" data-y="" data-z="" data-size="" data-noof="" data-ref=""><div class="img-bg"><img width="250" height="200" src="'+file+'" class="job-images"></div><div class="overlay"><a class="check-icon img_data_'+response[0]["id"]+' "><i class="fa fa-check"></i></a></div><div class="overlay_remove"><a class="check-icon-remove"><i class="fa fa-times"></i></a></div><div class="overlay_view"><a class="check-icon-view" data-animal="'+response[0]["filename"]+'" data-id="'+response[0]["id"]+'" data-clientid="'+response[0]["clientid"]+'"><i class="fa fa-eye"></i></a></div><p class="img-name" style="margin: 0!important;padding-left: 4px !important;">'+response[0]["filename"]+'</p><span class="tickmark">&#10004;</span></div>');
 			                  jQuery(".upload_view_save").trigger("click");
 			                  jQuery('.img_data_'+response[0]["id"]+'').trigger("click"); 	
                              jQuery(".upld-frnt-save-msg").css("display","block"); 		
			                  setTimeout(function () {
 			                  jQuery('.upload-modal').css("display","none");
			                  }, 1000);    
			                  },
			                 error:function(ts){
			                     alert('There is some technical issue please contact admin');
			                     jQuery('.close').trigger('click');
			                 }
			             });
			        });
			jQuery(document).on('click','.save-job-animals',function() {
				var filters = [];	

					$('.animal_filters .checked').each(function(i, obj) {
						var value = jQuery(this).attr('data-filter');
						var type = jQuery(this).attr('data-type');
						filters.push({
						    filtertype : type,
						    filtername : value,
						});
					});

				var saved_images =jQuery(this).attr('saved-images','true');
				var job_id=jQuery('.um-job-choosen').text();
				const images_data = [];

				const no_images_data = [];
				
				var counter = 0;
				$('.img_data_store').each(function(i, obj) {
					var checked = jQuery(this).parent().find('.img-clicked').val();
					if(checked == 'yes') {
						images_data.push({
						    id : jQuery(this).attr('data-id') ,
						    clientid : jQuery(this).attr('data-clientid') ,
						    jobno : jQuery(this).attr('data-jobno'), 
						    color : jQuery(this).attr('data-color') ,
						    coating : jQuery(this).attr('data-coating') ,
						    thickness : jQuery(this).attr('data-thickness') ,
						    type : jQuery(this).attr('data-type') ,
						    a : jQuery(this).attr('data-a'), 
						    b : jQuery(this).attr('data-b') ,
						    c : jQuery(this).attr('data-c') ,
						    d : jQuery(this).attr('data-d') ,
						    e : jQuery(this).attr('data-e') ,
						    f : jQuery(this).attr('data-f') ,
						    g : jQuery(this).attr('data-g') ,
						    p : jQuery(this).attr('data-p') ,						    
						    v : jQuery(this).attr('data-v') ,
						    w : jQuery(this).attr('data-w') ,
						    x : jQuery(this).attr('data-x') ,
						    y : jQuery(this).attr('data-y') ,
						    z : jQuery(this).attr('data-z') ,
						    size : jQuery(this).attr('data-size') ,
						    noof : jQuery(this).attr('data-noof') ,
						    ref : jQuery(this).attr('data-ref') ,
						});
						counter++;
					}					
				});
				var indx=0;
				$('.img_data_store').each(function(i, obj) {
					var checked = jQuery(this).parent().find('.img-clicked').val();				
					if(checked == 'no') {
							no_images_data.push({
							    id : jQuery(this).attr('data-id'),
							});
							indx++;
					}					
				});		

					jQuery.ajax({
		                    type: 'POST',
		                    dataType: 'json',
		                    url: ajax_url,
		                    data: {
		                      action: 'frontendstoreanimalimages',	 
		                      images_data: images_data,
		                      no_images_data: no_images_data,
		                      job_id:job_id,
		                      filters:filters                                                     
		                    },
		                    success: function(response) {
		                      console.log(response);	
                                    
		                    }, 
		                    error: function(xhr, status, error,response) {
		                       console.log(error);
		                       var err = eval("(" + xhr.responseText + ")");
		                       console.log(xhr);
		                    }
	      			});

				jQuery(".img-clicked").each(function(i, obj) {
                 jQuery(this).val('no');
				 jQuery(this).parent().css("background","revert");                 
				});	
			});


			jQuery(document).on('click','.um-show-filterbtnfilter1',function() {
				jQuery(".um-show-filterbtnfilter1").removeClass('checked');				
				var selected_img_count=0;
				jQuery(".img-clicked").each(function(i, obj) {
					if(jQuery(this).val()=="yes"){
                      selected_img_count++;
					}
				});
				if(selected_img_count==0){
					jQuery(".save-job-animals").attr('saved-images','true');
				}	
			
				if(jQuery(this).find('.filter-selected').css('display') == 'block') {

					jQuery('.gifmodal').css('display','block');

					jQuery(this).find('.filter-selected').css('display','none');
					jQuery(this).removeClass('checked');
            
					jQuery(".um-show-filterbtnall").removeClass('checked');	
					jQuery(".filterAll-selected").css("display","none");				 
					var $all = 'no';	
				}
				else {

					jQuery('.gifmodal').css('display','block'); 

					jQuery('.filter1-selected').each(function() {
						jQuery(this).css('display','none');
					});	          
					jQuery('.um-show-filterbtnfilter1 .checked').each(function() {
					    jQuery(this).removeClass('checked');
					});	 

					jQuery(this).find('.filter-selected').css('display','block');
					jQuery(this).addClass('checked');

					jQuery(".um-show-filterbtnall").removeClass('checked');
					jQuery(".filterAll-selected").css("display","none");		
					var $all = 'yes';	
				}

				var $this = jQuery(this);
				show_filtered_images($this,$all);
			});

			jQuery(document).on('click','.um-show-filterbtnfilter2',function() {
				var selected_img_count=0;
				jQuery(".img-clicked").each(function(i, obj) {
					if(jQuery(this).val()=="yes"){
                      selected_img_count++;
					}
				});
				if(selected_img_count==0){
					jQuery(".save-job-animals").attr('saved-images','true');
				}	
					
				jQuery(".um-show-filterbtnfilter2").removeClass('checked');	
				if(jQuery(this).find('.filter-selected').css('display') == 'block') {

					jQuery('.gifmodal').css('display','block');
					
					jQuery(this).find('.filter-selected').css('display','none');
					jQuery(this).removeClass('checked');
            
					jQuery(".um-show-filterbtnall").removeClass('checked');	
					jQuery(".filterAll-selected").css("display","none");

					var $all = 'no';	
				}
				else {

					jQuery('.gifmodal').css('display','block');
					jQuery('.filter2-selected').each(function() {
						jQuery(this).css('display','none');
					});	          
					jQuery('.um-show-filterbtnfilter2 .checked').each(function() {
					    jQuery(this).removeClass('checked');
					});	 
					jQuery(this).find('.filter-selected').css('display','block');
					jQuery(this).addClass('checked');

					jQuery(".um-show-filterbtnall").removeClass('checked');
					jQuery(".filterAll-selected").css("display","none");

					var $all = 'yes';	
				}
				var $this = jQuery(this);
				show_filtered_images($this,$all);
			});

			jQuery(document).on('click','.um-show-filterbtnall',function() {
				jQuery(".um-show-filterbtnfilter1").removeClass('checked');				
				jQuery(".um-show-filterbtnfilter2").removeClass('checked');				
				var selected_img_count=0;
				jQuery(".img-clicked").each(function(i, obj) {
					if(jQuery(this).val()=="yes"){
                      selected_img_count++;
					}
				});
				if(selected_img_count==0){
					jQuery(".save-job-animals").attr('saved-images','true');
				}	
					
				jQuery('.filter-selected').each(function() {
						jQuery(this).css('display','none');
				});	          
				jQuery('.um-show-filterbtn .checked').each(function() {
					    jQuery(this).removeClass('checked');
				});	 				
				if(jQuery(this).find('.filterAll-selected').css('display') == 'block') {
					jQuery('.gifmodal').css('display','block');
					jQuery(this).find('.filterAll-selected').css('display','none');
					jQuery(this).removeClass('checked');

					jQuery(this).attr('data-filter','')
					var $all = '';	
				}
				else {
					jQuery('.gifmodal').css('display','block');
					jQuery(this).find('.filterAll-selected').css('display','block');
					jQuery(this).addClass('checked');
							
					jQuery(this).attr('data-filter','all')					
					var $all = '';
				}
				var $this = jQuery(this);	
				var $filter="filter2";							
				show_filtered_images($this,$all);
			});

			function show_filtered_images($this,$all) {

	            console.log(jQuery(".animal-img").find(".img-clicked").val());
	            console.log("hkgyhjgb");                 
				jQuery('.animal-img').each(function() {
						// jQuery(this).find(".img-clicked").val()=="yes";
	            if(jQuery(this).find(".img-clicked").val()=="yes")
	              {
	                jQuery(this).css("background-color","#EFEE22");
	              }							
				});	  	
			
				var job_no = jQuery('.um-jobs-options').val();				
                var all_filters=jQuery(".animal_filters_all .checked" ).attr('data-filter');

				var filters = [];		
				var count = 0;
				var all = all_filters;

				console.log(all); 

				
					$('.animal_filters .checked').each(function(i, obj) {
						var value = jQuery(this).attr('data-filter');
						var type = jQuery(this).attr('data-type');
						filters.push({
						    filtertype : type,
						    filtername : value,
						});
					});	
                    var checked_length=jQuery(".animal_filters .checked").length;
	                if((all!="all") && (checked_length==0)){
                        jQuery(".um-show-filterbtnall").trigger("click");
						// jQuery('.filterAll-selected').css('display','block');
						// jQuery('.filterAll-selected').addClass('checked');
						all='all';
						jQuery('.filterAll-selected').attr('data-filter','all');                    
	                }

					jQuery.ajax({
	                    type: 'POST',
	                    dataType: 'json',
	                    url: ajax_url,
	                    data: {
	                      action: 'frontendgetfilterimages',	 
	                      filters: filters,
	                      job_no:job_no,                                    
	                      all: all                                                     
	                    },

	                    success: function(response) {
	                    	console.log(response);
	     	               //  jQuery('.gifmodal').css('display','none');                	
	                    	// return;
	                      	console.log(Array.isArray(response));
	                      	if(Array.isArray(response) == 'false') {
	                      		response = jQuery.parseJSON(response);
	                      	}
	                      	console.log(response);
	                      	jQuery('.show-animals-images').empty();
	                      	for(var i = 0; i < response.length;i++) {

		      				  	let file_name = response[i]['filename'];
		      				  	console.log(file_name) ;
								var file = file_name.replace("/home3/sbsofkvq/", "https://");
								const file_array = file_name.split("/");
								var filename = file_array[8].replace(".jpg", "");


								var id=response[i]["id"];
								if(id==undefined){
									id="";
								}
								var clientid=response[i]["clientid"];
								if(clientid==undefined){
									clientid="";
								}								
								var color=response[i]["color"];
								if(color==undefined){
									color="";
								}								
								var coating=response[i]["coating"];
								if(coating==undefined){
									coating="";
								}									
								var thickness=response[i]["thickness"];
								if(thickness==undefined){
									thickness="";
								}		
								var type=response[i]["type"];
								if(type==undefined){
									type="";
								}																
								var no_of=response[i]["no_of"];
								if(no_of==undefined){
									no_of="";
								}		
								var size_of=response[i]["size_of"];
								if(size_of==undefined){
									size_of="";
								}	
								var reference=response[i]["reference"];
								if(reference==undefined){
									reference="";
								}																								
								var option_a_val=response[i]["option_a_val"];
								if(option_a_val==undefined){
									option_a_val="";
								}	
								var option_a_def=response[i]["option_a_def"];
								if(option_a_def==undefined){
									option_a_def="";
									var option_a_def_val='data-a-def="'+option_a_def+'"';
								}else{
									var option_a_def_val='data-a-def="'+option_a_def+'"';
								}

								var option_b_val=response[i]["option_b_val"];
								if(option_b_val==undefined){
									option_b_val="";
								}	
								var option_b_def=response[i]["option_b_def"];
								if(option_b_def==undefined){
									option_b_def="";
									var option_b_def_val='data-b-def="'+option_b_def+'"';								
								}else{
									var option_b_def_val='data-b-def="'+option_b_def+'"';
								}
																
								var option_c_val=response[i]["option_c_val"];
								if(option_c_val==undefined){
									option_c_val="";
								}		
								var option_c_def=response[i]["option_c_def"];
								if(option_c_def==undefined){
									option_c_def="";
									var option_c_def_val='data-c-def="'+option_c_def+'"';
								}else{
									var option_c_def_val='data-c-def="'+option_c_def+'"';
								}
	

								var option_d_val=response[i]["option_d_val"];
								if(option_d_val==undefined){
									option_d_val="";
								}
		
								var option_d_def=response[i]["option_d_def"];
								if(option_d_def==undefined){
									option_d_def="";
									var option_d_def_val='data-d-def="'+option_d_def+'"';									
								}else{
									var option_d_def_val='data-d-def="'+option_d_def+'"';
								}	

								var option_e_val=response[i]["option_e_val"];
								if(option_e_val==undefined){
									option_e_val="";
								}		
								var option_e_def=response[i]["option_e_def"];
								if(option_e_def==undefined){
									option_e_def="";
									var option_e_def_val='data-e-def="'+option_e_def+'"';	
								}else{
									var option_e_def_val='data-e-def="'+option_e_def+'"';
								}	

								var option_f_val=response[i]["option_f_val"];
								if(option_f_val==undefined){
									option_f_val="";
								}		
								var option_f_def=response[i]["option_f_def"];
								if(option_f_def==undefined){
									option_f_def="";
									var option_f_def_val='data-e-def="'+option_f_def+'"';	
								}else{
									var option_f_def_val='data-f-def="'+option_f_def+'"';
								}	

								var option_g_val=response[i]["option_g_val"];
								if(option_g_val==undefined){
									option_g_val="";
								}		

								var option_g_def=response[i]["option_g_def"];
								if(option_g_def==undefined){
									option_g_def="";
									var option_g_def_val='data-e-def="'+option_g_def+'"';									
								}else{
									var option_g_def_val='data-g-def="'+option_g_def+'"';
								}	

								var option_p_val=response[i]["option_p_val"];
								if(option_p_val==undefined){
									option_p_val="";
								}			
								var option_p_def=response[i]["option_p_def"];
								if(option_p_def==undefined){
									option_p_def="";
									var option_p_def_val='data-p-def="'+option_p_def+'"';									
								}else{
									var option_p_def_val='data-p-def="'+option_p_def+'"';
								}

								var option_v_val=response[i]["option_v_val"];
								if(option_v_val==undefined){
									option_v_val="";
								}	
								var option_v_def=response[i]["option_v_def"];
								if(option_v_def==undefined){
									option_v_def="";
									var option_v_def_val='data-v-def="'+option_v_def+'"';
								}else{
									var option_v_def_val='data-v-def="'+option_v_def+'"';
								}																	
								var option_w_val=response[i]["option_w_val"];
								if(option_w_val==undefined){
									option_w_val="";
								}			
								var option_w_def=response[i]["option_w_def"];
								if(option_w_def==undefined){
									option_w_def="";
									var option_w_def_val='data-w-def="'+option_w_def+'"';									
								}else{
									var option_w_def_val='data-w-def="'+option_w_def+'"';
								}	

								var option_x_val=response[i]["option_x_val"];
								if(option_x_val==undefined){
									option_x_val="";
								}		

								var option_x_def=response[i]["option_x_def"];
								if(option_x_def==undefined){
									option_x_def="";
									var option_x_def_val='data-x-def="'+option_x_def+'"';									
								}else{
									var option_x_def_val='data-x-def="'+option_x_def+'"';
								}																
								var option_y_val=response[i]["option_y_val"];
								if(option_y_val==undefined){
									option_y_val="";
								}		
								var option_y_def=response[i]["option_y_def"];
								if(option_y_def==undefined){
									option_y_def="";
									var option_y_def_val='data-y-def="'+option_y_def+'"';									
								}else{
									var option_y_def_val='data-y-def="'+option_y_def+'"';
								}	

								var option_z_val=response[i]["option_z_val"];
								if(option_z_val==undefined){
									option_z_val="";
								}	

								var option_z_def=response[i]["option_z_def"];
								if(option_z_def==undefined){
									option_z_def="";
									var option_z_def_val='data-z-def="'+option_z_def+'"';									
								}else{
									var option_z_def_val='data-z-def="'+option_z_def+'"';
								}	



								if(response[i]["option_a"]=="yes"){
                                  var option_a='data-a="'+option_a_val+'"';

								}else{
                                  var option_a="";
								}
								if(response[i]["option_b"]=="yes"){
                                  var option_b='data-b="'+option_b_val+'"';
								}else{
                                  var option_b="";
								}                                 
								if(response[i]["option_c"]=="yes"){
                                  var option_c='data-c="'+option_c_val+'"';
								}else{
                                  var option_c="";
								}
								if(response[i]["option_d"]=="yes"){
                                  var option_d='data-d="'+option_d_val+'"';
								}else{
                                  var option_d="";
								}
								if(response[i]["option_e"]=="yes"){
                                  var option_e='data-e="'+option_e_val+'"';
								}else{
                                  var option_e="";
								}
								if(response[i]["option_f"]=="yes"){
                                  var option_f='data-f="'+option_f_val+'"';
								}else{
                                  var option_f="";
								}
								if(response[i]["option_g"]=="yes"){
                                  var option_g='data-g="'+option_g_val+'"';
								}else{
                                  var option_g="";
								}
								if(response[i]["option_p"]=="yes"){
                                  var option_p='data-p="'+option_p_val+'"';
								}else{
                                  var option_p="";
								}															
								if(response[i]["option_v"]=="yes"){
                                  var option_v='data-v="'+option_v_val+'"';
								}else{
                                  var option_v="";
								}
								if(response[i]["option_w"]=="yes"){
                                  var option_w='data-w="'+option_w_val+'"';
								}else{
                                  var option_w="";
								}
								if(response[i]["option_x"]=="yes"){
                                  var option_x='data-x="'+option_x_val+'"';
								}else{
                                  var option_x="";
								}										
								if(response[i]["option_y"]=="yes"){
                                  var option_y='data-y="'+option_y_val+'"';
								}else{
                                  var option_y="";
								}	
								if(response[i]["option_z"]=="yes"){
                                  var option_z='data-z="'+option_z_val+'"';
								}else{
                                  var option_z="";
								}



		      				  	jQuery('.show-animals-images').append('<div class="animal-img"><input type="hidden" class="img-clicked" value="no"><input type="hidden" class="img_data_store img_data_'+id+'" data-id="'+id+'" data-clientid="'+clientid+'" data-jobno="'+job_no+'" data-color="'+color+'" data-coating="'+coating+'" data-thickness="'+thickness+'" data-type="'+type+'" '+option_a+' '+option_a_def_val+' '+option_b+' '+option_b_def_val+' '+option_c+' '+option_c_def_val+' '+option_d+' '+option_d_def_val+' '+option_e+' '+option_e_def_val+' '+option_f+' '+option_f_def_val+' '+option_g+' '+option_g_def_val+' '+option_p+' '+option_p_def_val+' '+option_v+' '+option_v_def_val+' '+option_w+' '+option_w_def_val+' '+option_x+' '+option_x_def_val+' '+option_y+' '+option_y_def_val+' '+option_z+' '+option_z_def_val+'data-size="'+size_of+'" data-noof="'+no_of+'" data-ref="'+reference+'"><div class="img-bg"><img width="250" height="200" src="'+file+'" class="job-images"></div><div class="overlay"><a class="check-icon"><i class="fa fa-check"></i></a></div><div class="overlay_remove"><a class="check-icon-remove"><i class="fa fa-times"></i></a></div><div class="overlay_view"><a class="check-icon-view" data-animal="'+response[i]["file_name"]+'" data-id="'+id+'" data-clientid="'+clientid+'"><i class="fa fa-eye"></i></a></div><p class="img-name" style="margin: 0!important;padding-left: 4px !important;">'+response[i]["file_name"]+'</p><span class="tickmark">&#10004;</span></div>');
		      				  	if(response[i]["jobstatus"]=="yes"){
		      				  	    jQuery(".animal-img").find(".img-clicked").val("yes");
		      				  	}		
		      				  	}
		      				  	

					           if(jQuery(".animal-img").find(".img-clicked").val()=="yes")
					            {
					              	jQuery(".animal-img").css("background","#EFEE22");
					            }		      				  	
	                      jQuery('.gifmodal').css('display','none');                                         
	                    }, 
	                    error: function(xhr, status, error,response) {
	                    	jQuery('.gifmodal').css('display','none'); 
	                       console.log(error);
	                       var err = eval("(" + xhr.responseText + ")");
	                       console.log(xhr);
	                    }
      			});
			}

			jQuery(document).on('change','.emailsupply_jobid',function() {
				var job_id = jQuery('.emailsupply_jobid').val();
					jQuery.ajax({
		                    type: 'POST',
		                    dataType: 'json',
		                    url: ajax_url,
		                    data: {
		                      action: 'frontendgetjobdetailsemail',	 
		                      job_id: job_id                                                     
		                    },
		                    success: function(response) {
		                      console.log(response);
		                      for(var i = 0; i < response.length;i++) {
		                      	jQuery('.email_jobsiteadd').val(response[i]['site_address']);
		                      	jQuery('.email_job_date').val(response[i]['date']);
		                      	jQuery('.email_jobcustomername').val(response[i]['customer_name']);
		                      	jQuery('.email_jobdeliveryinstructions').val(response[i]['delivery_instructions']);
		                      	jQuery('.email_job_ccto').val(response[i]['email']);
		                      	jQuery('.email_job_cctocopy').val(response[i]['email_copy']);
		                      }			                                            
		                    }, 
		                    error: function(xhr, status, error,response) {
		                       console.log(error);
		                       var err = eval("(" + xhr.responseText + ")");
		                       console.log(xhr);
		                    }
	      			});
			});

			jQuery(document).on('click','.um_send_email',function() {
				var job_no = jQuery('.emailsupply_jobid').val();
				var site_address = jQuery('.email_jobsiteadd').val();
				var date = jQuery('.email_job_date').val();
				var customer_name = jQuery('.email_jobcustomername').val();
				var delivery_address = jQuery('.email_jobdeliveryinstructions').val();
				var send_to = jQuery('.email_job_sendto').val();
				var user_email = jQuery('.email_job_ccto').val();
				var email_copy = jQuery('.email_job_cctocopy').val();
				var clientid = jQuery('.email_supply_clientid').val();
		        jQuery(".email_sent_modal").css("display","none");					
				jQuery.ajax({
		                    type: 'POST',
		                    dataType: 'json',
		                    url: ajax_url,
		                    data: {
		                      action: 'frontendsendemail',	 
		                      job_no: job_no,                                                     
		                      site_address: site_address,                                                     
		                      date: date,                                                     
		                      customer_name: customer_name,                                                     
		                      delivery_address: delivery_address,                                                     
		                      send_to: send_to,                                                     
		                      user_email: user_email,                                                     
		                      email_copy: email_copy,                                                     
		                      clientid: clientid                                                   
		                    },
		                    success: function(response) {
		                      console.log(response);
		                      jQuery(".email_sent_modal").css("display","block");	                                            
		                    }, 
		                    error: function(xhr, status, error,response) {
		                       console.log(error);
		                       var err = eval("(" + xhr.responseText + ")");
		                       console.log(xhr);
		                    }
	      			});
			});
			jQuery(".email_sent_close").click(function(){
        		 jQuery(".email_sent_modal").css("display","none");	      
			});

            // jQuery(document).on("click",".um-account-link",function(){
            // 	console.log("fdfsfcd");
            //    event.preventDefault();
            //   console.log("hlooo");
            //   console.log(jQuery(this).attr('href'));
            // });			
			jQuery(".um-account-link").click(function(){
              var current_url=jQuery(this).attr('href');
              jQuery(this).attr('data-tab','');
			  window.location.href =current_url;	              
            });	
		});
	</script>
	<?php
}


add_action( 'wp_ajax_nopriv_frontendeditmember', 'frontendeditmember' );
add_action( 'wp_ajax_frontendeditmember', 'frontendeditmember' );


function frontendeditmember() {

	$member_id = $_POST['member_id'];
 	$edit_member_client_id = $_POST['current_company'];
    $edit_member_fst_name = $_POST["um_edit_member_fst_name"];
    $edit_member_sur_name = $_POST["um_edit_member_sur_name"];
    $edit_member_password = $_POST["um_edit_member_password"];
    $edit_member_mobile = $_POST["um_edit_member_mobile"];
    $edit_member_email = $_POST["um_edit_member_email"];
    $edit_member_lst_email = $_POST["um_edit_member_lst_email"];
    $edit_member_lst_email_date = $_POST["um_edit_member_lst_email_date"];              
    $edit_member_num_emails = $_POST["um_edit_member_num_emails"];
    $edit_member_active_det = $_POST["um_edit_member_active_det"];

	global $wpdb;
    $member_update_data = $wpdb->get_results($wpdb->prepare("UPDATE member_detailes SET client_id=$edit_member_client_id,first_name='".$edit_member_fst_name."',surname='".$edit_member_sur_name."',password='".$edit_member_password."',mobile='".$edit_member_mobile."',email='".$edit_member_email."',active='".$edit_member_active_det."',last_email_job_no='".$edit_member_lst_email."',last_email_date='".$edit_member_lst_email_date."',number_emails='".$edit_member_num_emails."' WHERE member_id=$member_id"));
	echo json_encode('success');
	die();
}



add_action( 'wp_ajax_nopriv_frontenddeletemember', 'frontenddeletemember' );
add_action( 'wp_ajax_frontenddeletemember', 'frontenddeletemember' );

function frontenddeletemember() {

	$id = $_POST['id'];

	global $wpdb;

    $data = $wpdb->get_results($wpdb->prepare("SELECT * FROM member_detailes WHERE member_id=$id"));
    $email=$data[0]->email; 
    $user = get_user_by( 'email', $email );
    $userId = $user->ID; 
    wp_delete_user($userId);   
    $wpdb->get_results($wpdb->prepare("DELETE FROM member_detailes WHERE member_id = $id"));      
	echo json_encode('success');
	die();

}


add_action( 'wp_ajax_nopriv_frontendaddmember', 'frontendaddmember' );
add_action( 'wp_ajax_frontendaddmember', 'frontendaddmember' );

function frontendaddmember() {

	$current_company = $_POST['current_company'];
 	$um_add_member_fst_name = $_POST['um_add_member_fst_name'];
    $um_add_member_sur_name = $_POST["um_add_member_sur_name"];
    $um_add_member_mobile = $_POST["um_add_member_mobile"];
    $um_add_member_email = $_POST["um_add_member_email"];
    $um_add_member_password = $_POST["um_add_member_password"];
    $um_add_member_level = $_POST["um_add_member_level"];
    $um_add_member_lst_email = $_POST["um_add_member_lst_email"];
    $um_add_member_lst_email_date = $_POST["um_add_member_lst_email_date"];
    $um_add_member_num_emails = $_POST["um_add_member_num_emails"];
    $um_add_member_active_det = $_POST["um_add_member_active_det"];

    
 	global $wpdb;
    if($um_add_member_level == 'level_2_client') {  
        $level2_username = $um_add_member_email;
        $level2_password = $um_add_member_password;
        $level2_email = $um_add_member_email;

        if(!username_exists($um_add_member_email)) {
	        $member_data = $wpdb->get_results($wpdb->prepare("INSERT INTO member_detailes (client_id, first_name, surname, password,mobile, email,level,active,last_email_job_no,last_email_date,number_emails) VALUES ('".$current_company."','".$um_add_member_fst_name."','".$um_add_member_sur_name."', '".$um_add_member_password."', '".$um_add_member_mobile."','".$um_add_member_email."','".$um_add_member_level."','".$um_add_member_active_det."','".$um_add_member_lst_email."','".$um_add_member_lst_email_date."','".$um_add_member_num_emails."')"));


	        $user_id = wp_create_user($level2_username,$level2_password,$level2_email);
	        $user = new WP_User($user_id);
	        $user->set_role('um_client');

	        echo json_encode('success');

        }
        else {

        	echo json_encode("Email ALready Exists");
        }
          
    }
    elseif ($um_add_member_level == 'level_3_member') {
	    $level3_username = $um_add_member_email;
	    $level3_password = $um_add_member_password;
	    $level3_email = $um_add_member_email;

	    if(!username_exists($um_add_member_email)) {
	       	$member_data = $wpdb->get_results($wpdb->prepare("INSERT INTO member_detailes (client_id, first_name, surname, password,mobile, email,level,active,last_email_job_no,last_email_date,number_emails) VALUES ('".$current_company."','".$um_add_member_fst_name."','".$um_add_member_sur_name."', '".$um_add_member_password."', '".$um_add_member_mobile."','".$um_add_member_email."','".$um_add_member_level."','".$um_add_member_active_det."','".$um_add_member_lst_email."','".$um_add_member_lst_email_date."','".$um_add_member_num_emails."')"));

	        $user_id = wp_create_user($level3_username,$level3_password,$level3_email);
	        $user = new WP_User($user_id);
	        $user->set_role('um_member');

	       	echo json_encode('success');

	    }
	    else {
	        echo json_encode("Email ALready Exists");
	    }
    }


	die();
}

add_action( 'wp_ajax_nopriv_frontendaddjob', 'frontendaddjob' );
add_action( 'wp_ajax_frontendaddjob', 'frontendaddjob' );

function frontendaddjob() {

	global $wpdb;

	$um_add_job_extension = $_POST['um_add_job_extension'];
 	$um_add_job_project = $_POST['um_add_job_project'];
    $um_add_job_customer_name = $_POST["um_add_job_customer_name"];
    $um_add_address1 = $_POST["um_add_address1"];
    $um_add_address2 = $_POST["um_add_address2"];
    $um_add_job_city = $_POST["um_add_job_city"];
    $um_add_job_state = $_POST["um_add_job_state"];
    $um_add_job_site_address = $_POST["um_add_job_site_address"];
    $um_add_job_delivery_inst = $_POST["um_add_job_delivery_inst"];
    $um_add_job_date = $_POST["um_add_job_date"];
    $um_add_job_lst_email_date = $_POST["um_add_job_lst_email_date"];

    $profile_id = um_profile_id();  
	$user_meta = get_userdata($profile_id);

	$email = $user_meta->user_email;
	$role = $user_meta->roles[0];
 
    if($profile_id==1){
       $member_id=-1;
    }else{
    $user_meta = get_userdata($profile_id);            
    $email = $user_meta->user_email;
    $role = $user_meta->roles[0];
    $get_member_id = $wpdb->get_results($wpdb->prepare("SELECT member_id FROM member_detailes WHERE email = '".$email."'"));
    $member_id = $get_member_id[0]->member_id;            
    }	
    if($role == 'um_client') {

    	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}
	if($role == 'um_member') {

		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}

	$client_id = $get_clientid[0]->client_id;

	$wpdb->insert('job_details', array(
			'client_id' => $client_id,
			'member_id' => $member_id,
			'extension' => "$um_add_job_extension",
			'project' => "$um_add_job_project",
			'customer_name' => "$um_add_job_customer_name",
			'address1' => "$um_add_address1",
			'address2' => "$um_add_address2",
			'city' => "$um_add_job_city",
			'state' => "$um_add_job_state",
			'site_address' => "$um_add_job_site_address",
			'delivery_instructions' => "$um_add_job_delivery_inst",
			'date' => "$um_add_job_date",
			'last_email_date' => "$um_add_job_lst_email_date",
	));
	$inserted_id = $wpdb->insert_id;

	$job_id = $um_add_job_extension;
	$wpdb->get_results($wpdb->prepare("UPDATE job_details SET job_no = '".$job_id."' WHERE id = $inserted_id"));
	print_r(json_encode("success"));
	die();

}

add_action( 'wp_ajax_nopriv_frontenddeletejob', 'frontenddeletejob' );
add_action( 'wp_ajax_frontenddeletejob', 'frontenddeletejob' );

function frontenddeletejob() {

	$id = $_POST['id'];

	global $wpdb;
    $wpdb->get_results($wpdb->prepare("DELETE FROM job_details WHERE job_no = '".$id."'"));

	echo json_encode('success');
	die();
}

add_action( 'wp_ajax_nopriv_frontendeditjobsave', 'frontendeditjobsave' );
add_action( 'wp_ajax_frontendeditjobsave', 'frontendeditjobsave' );

function frontendeditjobsave() {

	$job_id = $_POST['job_id'];
	$um_add_editjob_extension = $_POST['um_add_editjob_extension'];
	$um_add_editjob_project = $_POST['um_add_editjob_project'];
	$um_add_editjob_customer_name = $_POST['um_add_editjob_customer_name'];
	$um_add_address1 = $_POST['um_add_address1'];
	$um_add_address2 = $_POST['um_add_address2'];
	$um_add_editjob_city = $_POST['um_add_editjob_city'];
	$um_add_editjob_state = $_POST['um_add_editjob_state'];
	$um_add_editjob_site_address = $_POST['um_add_editjob_site_address'];
	$um_add_editjob_delivery_inst = $_POST['um_add_editjob_delivery_inst'];
	$um_add_editjob_date = $_POST['um_add_editjob_date'];
	$um_add_editjob_lst_email_date = $_POST['um_add_editjob_lst_email_date'];


	global $wpdb;
	$profile_id = um_profile_id();  
	$user_meta = get_userdata($profile_id);

	$email = $user_meta->user_email;
	$role = $user_meta->roles[0];

    if($role == 'um_client') {

    	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}
	if($role == 'um_member') {

		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}

	$client_id = $get_clientid[0]->client_id;

	$wpdb->get_results($wpdb->prepare("UPDATE job_details SET client_id = $client_id , extension = '".$um_add_editjob_extension."',project='".$um_add_editjob_project."',customer_name = '".$um_add_editjob_customer_name."',address1='".$um_add_address1."',address2='".$um_add_address2."',city='".$um_add_editjob_city."',state='".$um_add_editjob_state."',site_address='".$um_add_editjob_site_address."',delivery_instructions='".$um_add_editjob_delivery_inst."',date='".$um_add_editjob_date."',last_email_date='".$um_add_editjob_lst_email_date."'  WHERE job_no = '".$job_id."'"));
	echo json_encode('success');
	die();
}


add_action( 'wp_ajax_nopriv_frontendgetanimals', 'frontendgetanimals' );
add_action( 'wp_ajax_frontendgetanimals', 'frontendgetanimals' );

function frontendgetanimals() {

	$job_no = $_POST['job_no']; 

	$profile_id = um_profile_id();  
	$user_meta = get_userdata($profile_id);

	$email = $user_meta->user_email;
	$role = $user_meta->roles[0];
	$files=array();
	$data=array();
	global $wpdb;

	if($role == 'um_client') {

    	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}
	if($role == 'um_member') {

		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}

	$client_id = $get_clientid[0]->client_id;

	$get_animal_snos = $wpdb->get_results($wpdb->prepare("SELECT filter_1,filter_2 FROM job_details WHERE client_id = $client_id AND job_no = '".$job_no."'"));

        $selected_filter1=$get_animal_snos[0]->filter_1;
        $selected_filter2=$get_animal_snos[0]->filter_2;
	    $data[0]["filter_1"]=$selected_filter1;
	    $data[1]["filter_2"]=$selected_filter2;

		$get_animals = $wpdb->get_results($wpdb->prepare("SELECT * FROM animal_detailes WHERE client_id = $client_id And type=''"));

			$idx = 0;

			foreach($get_animals as $animal_det) {

					$files[$idx]['id'] = $animal_det->id;
					$files[$idx]['clientid'] = $animal_det->client_id;
					$files[$idx]['filename'] = $animal_det->file_name;
					$files[$idx]['file_name'] = $animal_det->filename;
					$files[$idx]['directview'] = 'no';
					$files[$idx]['option_a'] = $animal_det->option_a;
					$files[$idx]['option_a_def'] = $animal_det->option_a_def;
					$files[$idx]['option_b'] = $animal_det->option_b;
					$files[$idx]['option_b_def'] = $animal_det->option_b_def;
					$files[$idx]['option_c'] = $animal_det->option_c;
					$files[$idx]['option_c_def'] = $animal_det->option_c_def;
					$files[$idx]['option_d'] = $animal_det->option_d;
					$files[$idx]['option_d_def'] = $animal_det->option_d_def;
					$files[$idx]['option_e'] = $animal_det->option_e;	
					$files[$idx]['option_e_def'] = $animal_det->option_e_def;	
					$files[$idx]['option_f'] = $animal_det->option_f;
					$files[$idx]['option_f_def'] = $animal_det->option_f_def;
					$files[$idx]['option_g'] = $animal_det->option_g;
					$files[$idx]['option_g_def'] = $animal_det->option_g_def;
					$files[$idx]['option_p'] = $animal_det->option_p;
					$files[$idx]['option_p_def'] = $animal_det->option_p_def;
					$files[$idx]['option_v'] = $animal_det->option_v;
					$files[$idx]['option_v_def'] = $animal_det->option_v_def;
					$files[$idx]['option_w'] = $animal_det->option_w;
					$files[$idx]['option_w_def'] = $animal_det->option_w_def;
					$files[$idx]['option_x'] = $animal_det->option_x;		
					$files[$idx]['option_x_def'] = $animal_det->option_x_def;		
					$files[$idx]['option_y'] = $animal_det->option_y;
					$files[$idx]['option_y_def'] = $animal_det->option_y_def;
					$files[$idx]['option_z'] = $animal_det->option_z;					
					$files[$idx]['option_z_def'] = $animal_det->option_z_def;					

			$get_animal_job_det = $wpdb->get_results($wpdb->prepare("SELECT * FROM job_animals WHERE client_id = $client_id AND animal_sno = $animal_det->id"));

			 $idx++;				  
		   }
			
	    $data[2]["files"]=$files;

	print_r(json_encode($data));
	die();
}

add_action( 'wp_ajax_nopriv_custom_upload_img', 'custom_upload_img' );
add_action( 'wp_ajax_custom_upload_img', 'custom_upload_img' );

function custom_upload_img() {
     $modal_color= $_POST['modal_color'];	
     $modal_coating= $_POST['modal_coating'];	
     $modal_thickness= $_POST['modal_thickness'];	
     $modal_type= $_POST['modal_type'];	
     $modal_optiona= $_POST['modal_optiona'];	
     $modal_optionb= $_POST['modal_optionb'];	
     $modal_optionc= $_POST['modal_optionc'];	
     $modal_optiond= $_POST['modal_optiond'];	
     $modal_optione= $_POST['modal_optione'];	
     $modal_optionf= $_POST['modal_optionf'];	
     $modal_optiong= $_POST['modal_optiong'];	
     $modal_optionp= $_POST['modal_optionp'];	
     $modal_optionv= $_POST['modal_optionv'];	
     $modal_optionw= $_POST['modal_optionw'];	
     $modal_optionx= $_POST['modal_optionx'];	
     $modal_optiony= $_POST['modal_optiony'];	
     $modal_optionz= $_POST['modal_optionz'];	
     $modal_size= $_POST['modal_size'];	
     $modal_noof= $_POST['modal_noof'];	

     $job_id= $_POST['job_id'];
     // $client_id =  $_POST['client_id'];     
     $file =  $_FILES['photos'];
 	 $tempfile = $_FILES['photos']['tmp_name'];
 	 $name = $_FILES['photos']['name'];
 	 $name = str_replace(' ', '_', $name);
     global $wpdb;
	 $folder = ABSPATH.'wp-content/uploads/animal-selected/';

	 $handle = $folder.$name ; 

	 if(file_exists($handle)){
	    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	    $charactersLength = strlen($characters);
	    $randomString = '';
	    for ($i = 0; $i < 2; $i++) {
	        $randomString .= $characters[random_int(0, $charactersLength - 1)];
	    }
	 
		$randm_key= "_".$randomString;

		$extension_pos = strrpos($handle, '.'); 
		$path = substr($handle, 0, $extension_pos) . $randm_key . substr($handle, $extension_pos);
		$handle=$path;   	  
	 }

	 move_uploaded_file($tempfile,$handle);
     $profile_id = um_profile_id();  
	 $user_meta = get_userdata($profile_id);

	 $email = $user_meta->user_email;
	 $role = $user_meta->roles[0];

     if($role == 'um_client') {

    	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));
	 }
	 if($role == 'um_member') {

		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));
	 }

     if($profile_id==1){
        $member_id=-1;
     }else{

     $get_member_id = $wpdb->get_results($wpdb->prepare("SELECT member_id FROM member_detailes WHERE email = '".$email."'"));
         $member_id = $get_member_id[0]->member_id;            
     }		 

	$client_id = $get_clientid[0]->client_id;

         $wpdb->insert('animal_detailes', array(
            'client_id'=> $client_id,
            'member_id'=> $member_id,
            'filename' => "$name",
            'file_name'=> "$handle",
            'option_a' => "no",
            'option_b' => "no",
            'option_c' => "no",
            'option_d' => "no",
            'option_e' => "no",
            'option_f' => "no",
            'option_g' => "no", 
            'option_p' => "no",                     
            'option_v' => "no",
            'option_w' => "no",
            'option_x' => "no",
            'option_y' => "no",
            'option_z' => "no",
            'status'  => "inactive",                                             
            'type'  => "custom upload($job_id)"                                            
         ));
         $inserted_id = $wpdb->insert_id;		


		 $wpdb->get_results($wpdb->prepare("INSERT INTO job_animals (animal_sno,client_id,job_id,color,coating,thickness,type,option_a,option_b,option_c,option_d,option_e,option_f,option_g,option_p,option_v,option_w,option_x,option_y,option_z,size_of,no_of) VALUES($inserted_id,'".$client_id."','".$job_id."','".$modal_color."','".$modal_coating."','".$modal_thickness."','".$modal_type."','".$modal_optiona."','".$modal_optionb."','".$modal_optionc."','".$modal_optiond."','".$modal_optione."','".$modal_optionf."','".$modal_optiong."','".$modal_optionp."','".$modal_optionv."','".$modal_optionw."','".$modal_optionx."','".$modal_optiony."','".$modal_optionz."','".$modal_size."','".$modal_noof."')"));         

	     $files=array();
		 // $files[0]['id'] = $inserted_id;
		 $files[0]['id'] = $inserted_id;
		 $files[0]['clientid'] = $client_id;
		 $files[0]['job_id'] = $job_id;
		 $files[0]['filename'] = $name;
		 $files[0]['handle'] = $handle;

		print_r(json_encode($files));
		die();
}

add_action( 'wp_ajax_nopriv_frontendstoreanimalimages', 'frontendstoreanimalimages' );
add_action( 'wp_ajax_frontendstoreanimalimages', 'frontendstoreanimalimages' );

function frontendstoreanimalimages() {
	global $wpdb;
	$images_data = $_POST['images_data'];
    $no_images_data=$_POST['no_images_data'];
    $job_id=$_POST['job_id'];
    $filters=$_POST['filters'];
	$profile_id = um_profile_id();  
	$user_meta = get_userdata($profile_id);

	$email = $user_meta->user_email;
	$role = $user_meta->roles[0];
	$files=array();


	if($role == 'um_client') {

    	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}
	if($role == 'um_member') {

		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}

	$client_id = $get_clientid[0]->client_id;

	$filter1_values="";
	$filter2_values="";
		$i = 0;
		foreach($filters as $filter_values) {
			$filtertype=$filter_values['filtertype'];
			if($filtertype=='filter1'){
                $filter1_values=$filter_values['filtername'];
			}
			if($filtertype=='filter2'){
                $filter2_values=$filter_values['filtername'];
			}
			$i++;
		}


	$wpdb->get_results($wpdb->prepare("UPDATE job_details SET filter_1 = '".$filter1_values."',filter_2 = '".$filter2_values."' WHERE client_id = $client_id AND job_no= '".$job_id."'"));		

	// if(!empty($no_images_data)) {
	// 	for($indx = 0;$indx < count($no_images_data);$indx++) {
	// 		$get_result = $wpdb->get_results($wpdb->prepare("DELETE FROM job_animals WHERE animal_sno = '".$no_images_data[$indx]['id']."' AND job_id= '".$job_id."' "));
	// 		}
	// }    
	if(!empty($images_data)) {
		for($idx = 0;$idx < count($images_data);$idx++) {
			$get_result = $wpdb->get_results($wpdb->prepare("SELECT * FROM job_animals WHERE animal_sno = '".$images_data[$idx]['id']."' AND job_id= '".$job_id."' "));

				$wpdb->get_results($wpdb->prepare("INSERT INTO job_animals (animal_sno,client_id,job_id,color,coating,thickness,type,option_a,option_b,option_c,option_d,option_e,option_f,option_g,option_p,option_v,option_w,option_x,option_y,option_z,size_of,no_of,reference) VALUES('".$images_data[$idx]['id']."','".$images_data[$idx]['clientid']."','".$images_data[$idx]['jobno']."','".$images_data[$idx]['color']."','".$images_data[$idx]['coating']."','".$images_data[$idx]['thickness']."','".$images_data[$idx]['type']."','".$images_data[$idx]['a']."','".$images_data[$idx]['b']."','".$images_data[$idx]['c']."','".$images_data[$idx]['d']."','".$images_data[$idx]['e']."','".$images_data[$idx]['f']."','".$images_data[$idx]['g']."','".$images_data[$idx]['p']."','".$images_data[$idx]['v']."','".$images_data[$idx]['w']."','".$images_data[$idx]['x']."','".$images_data[$idx]['y']."','".$images_data[$idx]['z']."','".$images_data[$idx]['size']."','".$images_data[$idx]['noof']."','".$images_data[$idx]['ref']."')"));
			
		}
	}
	

	print_r(json_encode("success"));
	die();
}


add_action( 'wp_ajax_nopriv_frontendgetfilterimages', 'frontendgetfilterimages' );
add_action( 'wp_ajax_frontendgetfilterimages', 'frontendgetfilterimages' );

function frontendgetfilterimages() {
	$job_no = $_POST['job_no']; 
	$filters = $_POST['filters'];
	$all = $_POST['all'];
	global $wpdb;
	$profile_id = um_profile_id();  
	$user_meta = get_userdata($profile_id);

	$email = $user_meta->user_email;
	$role = $user_meta->roles[0];
	global $wpdb;

	if($role == 'um_client') {

    	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}
	if($role == 'um_member') {

		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}

	$client_id = $get_clientid[0]->client_id;

	$get_animal_snos = $wpdb->get_results($wpdb->prepare("SELECT animal_sno FROM job_animals WHERE client_id = $client_id AND job_id = '".$job_no."'"));

	// if(empty($get_animal_snos)) {	

	$filter1=array();
	$filter2=array();
		$i = 0;
		foreach($filters as $filter_values) {
			$filtertype=$filter_values['filtertype'];
			if($filtertype=='filter1'){
                $filter1[$i]=$filter_values['filtername'];
			}
			if($filtertype=='filter2'){
                $filter2[$i]=$filter_values['filtername'];
			}
			// $get_filter_animals[$i] = $wpdb->get_results($wpdb->prepare("SELECT * FROM animal_detailes WHERE '".$values."' IN (filter1,filter2) AND client_id = $client_id")); 
			$i++;
		}
         
        $filter1_values='';

		foreach($filter1 as $filter1values) {
 
        $filter1_values.="'".$filter1values."'".",";

		}
        $filter1_values=substr($filter1_values, 0, -1);

        $filter2_values='';

		foreach($filter2 as $filter2values) {
 
        $filter2_values.="'".$filter2values."'".",";

		}
        $filter2_values=substr($filter2_values, 0, -1);

		$query="SELECT * FROM animal_detailes WHERE ";
        if($all=="all"){
             $query.="client_id = $client_id And filter1!='' And filter2!='' And type in ('custom upload(".$job_no.")','')";
        }
		else if(count($filter1)!=0 && count($filter2)!=0){
             $query.="((filter1 IN ($filter1_values)) AND (filter2 IN ($filter2_values) )) AND client_id = $client_id AND type=''";
		}
		else if(count($filter1)!=0){
             $query.="(filter1 IN ($filter1_values)) AND client_id = $client_id AND type=''";
		}else if(count($filter2)!=0){
             $query.="(filter2 IN ($filter2_values) ) AND client_id = $client_id AND type=''";
		}

		// if(count($filter1)
		global $wpdb;
		$filter_files = array();
		$get_filter_animals= $wpdb->get_results($wpdb->prepare("$query"));
		$index = 0;
		if(count($get_filter_animals)!=0){

		foreach($get_filter_animals as $values) {
                    $filter_files[$index]['jobstatus'] = "no";	
					$filter_files[$index]['id'] = $values->id;
					$filter_files[$index]['clientid'] = $values->client_id;
					$filter_files[$index]['filename'] = $values->file_name;
					$filter_files[$index]['file_name'] = $values->filename;
					$filter_files[$index]['id'] = $values->id;
					$filter_files[$index]['clientid'] = $values->client_id;
					$filter_files[$index]['filename'] = $values->file_name;
					$filter_files[$index]['file_name'] = $values->filename;
					$filter_files[$index]['directview'] = 'no';
					$filter_files[$index]['option_a'] = $values->option_a;
					$filter_files[$index]['option_a_def'] = $values->option_a_def;
					$filter_files[$index]['option_b'] = $values->option_b;
					$filter_files[$index]['option_b_def'] = $values->option_b_def;
					$filter_files[$index]['option_c'] = $values->option_c;
					$filter_files[$index]['option_c_def'] = $values->option_c_def;
					$filter_files[$index]['option_d'] = $values->option_d;
					$filter_files[$index]['option_d_def'] = $values->option_d_def;
					$filter_files[$index]['option_e'] = $values->option_e;	
					$filter_files[$index]['option_e_def'] = $values->option_e_def;	
					$filter_files[$index]['option_f'] = $values->option_f;
					$filter_files[$index]['option_f_def'] = $values->option_f_def;
					$filter_files[$index]['option_g'] = $values->option_g;
					$filter_files[$index]['option_g_def'] = $values->option_g_def;
					$filter_files[$index]['option_v'] = $values->option_v;
					$filter_files[$index]['option_v_def'] = $values->option_v_def;
					$filter_files[$index]['option_w'] = $values->option_w;
					$filter_files[$index]['option_w_def'] = $values->option_w_def;
					$filter_files[$index]['option_x'] = $values->option_x;		
					$filter_files[$index]['option_x_def'] = $values->option_x_def;		
					$filter_files[$index]['option_y'] = $values->option_y;
					$filter_files[$index]['option_y_def'] = $values->option_y_def;
					$filter_files[$index]['option_z'] = $values->option_z;	
					$filter_files[$index]['option_z_def'] = $values->option_z_def;	

		    	$get_animal_job_det = $wpdb->get_results($wpdb->prepare("SELECT * FROM job_animals WHERE client_id = $client_id AND animal_sno = $values->id"));

				foreach($get_animal_job_det as $getanimals) {

					$filter_files[$index]['s_no'] = $getanimals->s_no;
					$filter_files[$index]['animal_sno'] = $getanimals->animal_sno;
					$filter_files[$index]['job_id'] = $getanimals->job_id;
					$filter_files[$index]['color'] = $getanimals->color;
					$filter_files[$index]['coating'] = $getanimals->coating;
					$filter_files[$index]['thickness'] = $getanimals->thickness;
					$filter_files[$index]['type'] = $getanimals->type;
					$filter_files[$index]['option_a_val'] = $getanimals->option_a;
					$filter_files[$index]['option_b_val'] = $getanimals->option_b;
					$filter_files[$index]['option_c_val'] = $getanimals->option_c;
					$filter_files[$index]['option_d_val'] = $getanimals->option_d;
					$filter_files[$index]['option_e_val'] = $getanimals->option_e;	
					$filter_files[$index]['option_f_val'] = $getanimals->option_f;
					$filter_files[$index]['option_g_val'] = $getanimals->option_g;
					$filter_files[$index]['option_v_val'] = $getanimals->option_v;
					$filter_files[$index]['option_w_val'] = $getanimals->option_w;
					$filter_files[$index]['option_x_val'] = $getanimals->option_x;		
					$filter_files[$index]['option_y_val'] = $getanimals->option_y;
					$filter_files[$index]['option_z_val'] = $getanimals->option_z;
					$filter_files[$index]['size_of'] = $getanimals->size_of;	
					$filter_files[$index]['no_of'] = $getanimals->no_of;	
					$filter_files[$index]['reference'] = $getanimals->reference;			


				  }

					$index++;
			 }	
	 }

	$filter_files = array_map("unserialize", array_unique(array_map("serialize", $filter_files)));
	// }
	

	print_r(json_encode($filter_files));
	die();
}

add_action( 'wp_ajax_nopriv_frontendgetjobdetailsemail', 'frontendgetjobdetailsemail' );
add_action( 'wp_ajax_frontendgetjobdetailsemail', 'frontendgetjobdetailsemail' );

function frontendgetjobdetailsemail() {

	$job_id = $_POST['job_id'];
	global $wpdb;
	$get_jobdetails = $wpdb->get_results($wpdb->prepare("SELECT * FROM job_details WHERE job_no = '".$job_id."' "));
	$idx = 0;
	foreach($get_jobdetails as $jobdetails) {
		$jobdata[$idx]['site_address'] = $jobdetails->site_address;
		$jobdata[$idx]['date'] = $jobdetails->date;
		$jobdata[$idx]['customer_name'] = $jobdetails->customer_name;
		$jobdata[$idx]['delivery_instructions'] = $jobdetails->delivery_instructions;

		$client_emails = $wpdb->get_results($wpdb->prepare("SELECT * FROM client_detailes WHERE client_id = $jobdetails->client_id"));
		foreach($client_emails as $emails){
			$jobdata[$idx]['email'] = $emails->email;
			$jobdata[$idx]['email_copy'] = $emails->email_copy;
		}
		$idx++;
	}

	print_r(json_encode($jobdata));
	die();
}


add_action( 'wp_ajax_nopriv_frontendsendemail', 'frontendsendemail' );
add_action( 'wp_ajax_frontendsendemail', 'frontendsendemail' );

function frontendsendemail() {  

	$job_no = $_POST['job_no'];
	$site_address = $_POST['site_address'];
	$date = $_POST['date'];
	$customer_name = $_POST['customer_name'];
	$delivery_address = $_POST['delivery_address'];
	$send_to = $_POST['send_to'];
	$user_email = $_POST['user_email'];
	$email_copy = $_POST['email_copy'];
	$clientid = $_POST['clientid'];
	$email_data = array();

	global $wpdb;
    $get_clientmail = $wpdb->get_results($wpdb->prepare("SELECT * FROM client_detailes WHERE client_id = $clientid"));

    $get_clientjobdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM job_details WHERE client_id = $clientid AND job_no = '".$job_no."' "));

    $get_clientjobanimals = $wpdb->get_results($wpdb->prepare("SELECT * FROM job_animals WHERE client_id = $clientid AND job_id = '".$job_no."' "));

    $idx = 0;
    foreach($get_clientjobanimals as $jobanimals) {
    	$get_animals = $wpdb->get_results($wpdb->prepare("SELECT * FROM animal_detailes WHERE client_id = $clientid AND id = $jobanimals->animal_sno"));
    	if($jobanimals->color != '') {
    		$email_data[$idx]['color'] = $jobanimals->color;
    	}
    	if($jobanimals->coating != '') {
    		$email_data[$idx]['coating'] = $jobanimals->coating;
    	}
    	if($jobanimals->thickness != '') {
    		$email_data[$idx]['thickness'] = $jobanimals->thickness;
    	}
    	if($jobanimals->type != '') {
    		$email_data[$idx]['type'] = $jobanimals->type;
    	}
    	if($jobanimals->option_a != '') {
    		$email_data[$idx]['option_a'] = $jobanimals->option_a;
    	}
    	if($jobanimals->option_b != '') {
    		$email_data[$idx]['option_b'] = $jobanimals->option_b;
    	}
    	if($jobanimals->option_c != '') {
    		$email_data[$idx]['option_c'] = $jobanimals->option_c;
    	}
    	if($jobanimals->option_d != '') {
    		$email_data[$idx]['option_d'] = $jobanimals->option_d;
    	}
    	if($jobanimals->option_e != '') {
    		$email_data[$idx]['option_e'] = $jobanimals->option_e;
    	}    	
    	if($jobanimals->option_f != '') {
    		$email_data[$idx]['option_f'] = $jobanimals->option_f;
    	}    	
    	if($jobanimals->option_g != '') {
    		$email_data[$idx]['option_g'] = $jobanimals->option_g;
    	}    	
    	if($jobanimals->option_p != '') {
    		$email_data[$idx]['option_p'] = $jobanimals->option_p;
    	}    	
    	if($jobanimals->option_v != '') {
    		$email_data[$idx]['option_v'] = $jobanimals->option_v;
    	}
    	if($jobanimals->option_w != '') {
    		$email_data[$idx]['option_w'] = $jobanimals->option_w;
    	}
    	if($jobanimals->option_x != '') {
    		$email_data[$idx]['option_x'] = $jobanimals->option_x;
    	}
    	if($jobanimals->option_y != '') {
    		$email_data[$idx]['option_y'] = $jobanimals->option_y;
    	}
    	if($jobanimals->option_z != '') {
    		$email_data[$idx]['option_z'] = $jobanimals->option_z;
    	}
    	if($jobanimals->size_of != '') {
    		$email_data[$idx]['size'] = $jobanimals->size_of;
    	}
    	if($jobanimals->no_of != '') {
    		$email_data[$idx]['no_of'] = $jobanimals->no_of;
    	}
    	if($jobanimals->reference != '') {
    		$email_data[$idx]['reference'] = $jobanimals->reference;
    	}
    	foreach($get_animals as $animals) {
    		$email_data[$idx]['filename'] = $animals->filename;
    		$email_data[$idx]['image'] = $animals->file_name;
    	}
    	$idx++;
    }

    if($send_to == 'email_supply1') {
    	$send_email = $get_clientmail[0]->email_supply1;
    }
    if($send_to == 'email_supply2') {
    	$send_email = $get_clientmail[0]->email_supply2;
    }
    if($send_to == 'email_supply3') {
    	$send_email = $get_clientmail[0]->email_supply3;
    }

    $profile_id = um_profile_id(); 
	$user_meta = get_userdata($profile_id); 

    $header = "From:lokeswari@sbsoftwareservices.com \r\n";
    if($email_copy == '') {
    	$header .= "CC:$user_email \r\n";
    }
    else {
        $header .= "CC:$user_email,$email_copy \r\n";
    }
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-type: text/html; charset=utf-8\r\n";

    $current_date = date("d/m/Y");

    foreach($email_data as $key => $data) {

    	if($data['color'] != '') {
    		$animal_html .= '<p class="animalcontent_color">Color<span class="email_separator">: </span>'.$data['color'].'</p>';
    	}
    	if($data['coating'] != '') {
    		$animal_html .= '<p class="animalcontent_coating">Coating<span class="email_separator">: </span>'.$data['coating'].'</p>';
    	}
    	if($data['thickness'] != '') {
    		$animal_html .= '<p class="animalcontent_thickness">Thickness<span class="email_separator">: </span>'.$data['thickness'].'</p>';
    	}
    	if($data['type'] != '') {
    		$animal_html .= '<p class="animalcontent_type">Type<span class="email_separator">: </span>'.$data['type'].'</p>';
    	}
    	if($data['option_a'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optiona">A<span class="email_separator">: </span>'.$data['option_a'].'</p>';
    	}
    	if($data['option_b'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optionb">B<span class="email_separator">: </span>'.$data['option_b'].'</p>';
    	}
    	if($data['option_c'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optionc">C<span class="email_separator">: </span>'.$data['option_c'].'</p>';
    	}
    	if($data['option_d'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optiond">D<span class="email_separator">: </span>'.$data['option_d'].'</p>';
    	}
    	if($data['option_e'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optione">E<span class="email_separator">: </span>'.$data['option_e'].'</p>';
    	}    	
    	if($data['option_f'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optione">F<span class="email_separator">: </span>'.$data['option_f'].'</p>';
    	}    	
    	if($data['option_g'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optione">G<span class="email_separator">: </span>'.$data['option_g'].'</p>';
    	}    	
    	if($data['option_p'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optione">P<span class="email_separator">: </span>'.$data['option_p'].'</p>';
    	}
    	if($data['option_v'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optionv">V<span class="email_separator">: </span>'.$data['option_v'].'</p>';
    	}
    	if($data['option_w'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optionw">W<span class="email_separator">: </span>'.$data['option_w'].'</p>';
    	}
    	if($data['option_x'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optionx">X<span class="email_separator">: </span>'.$data['option_x'].'</p>';
    	}
    	if($data['option_y'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optiony">Y<span class="email_separator">: </span>'.$data['option_y'].'</p>';
    	}
    	if($data['option_z'] != '') {
    		$animalcontent_html .= '<p class="animalcontent_optionz">Z<span class="email_separator">: </span>'.$data['option_z'].'</p>';
    	}
    	if($data['size'] != '') {
    		$animalcontenthtml .= '<p class="animalcontent_size">Length<span class="email_separator">: </span>'.$data['size'].'</p>';
    	}
    	if($data['no_of'] != '') {
    		$animalcontenthtml .= '<p class="animalcontent_no_of">No Off<span class="email_separator">: </span>'.$data['no_of'].'</p>';
    	}
    	if($data['reference'] != '') {
    		$animalcontenthtml .= '<p class="animalcontent_reference">Reference<span class="email_separator">: </span>'.$data['reference'].'</p>';
    	}
    	if($data['filename'] != '') {
    		$filename = $data['filename'];
    	}
    	if($data['image'] != '') {
    		$image =  str_replace("/home3/sbsofkvq/","https://",$data['image']);
    	}

    	$animalhtml .= 	'
    						    						<div class="email_body_animal_content">
    							<div class="emailbody_animal_content" style="display: inline-flex;border-bottom: 1px solid #000;width:100%;">
    								<div class="email_body_animal_left" style="width: 80%;">
    									<div>
    										'.$animal_html.'
    										<div style="border-bottom: 1px dashed #000;width: 100px;"></div>
    									</div>
    									<div>
    										'.$animalcontent_html.'
    									</div>  
    									<div style="display:flex;column-gap: 25px;">
    										'.$animalcontenthtml.'
    									</div>				
    								</div>
    								<div class="email_body_animal_right" style="position: absolute;top: 1070px;left: 168px;width:auto;">
    									<div style="margin-left: 8px;margin-bottom: 20px;margin-right: 8px;margin-top: 20px;background: #EFEE22;border: 3px solid #EAE671;border-radius: 4px;">
    										<div>	
    											<img src="'.$image.'" style="width: 200px;height: 150px;object-fit: cover;">					
    										</div>
    										<p>'.$filename.'</p>
    									</div>
    								</div>
    							</div>
    						</div>
    					';

    	$animal_html = '';
    	$animalcontent_html = '';
    	$animalcontenthtml = '';
    	$filename = '';
    	$image = '';

    }

    $email_body = 	'
    					<div class="email_body">
    						<div class="email_bodyheading">
    							<h2 style="text-align: center;">Animal Order</h2>
    						</div>
    						<div class="email_body_content" style="display: flex;border-bottom: 1px solid #000;">
    							<div class="email_body_left" style="width: 80%;">
    								<p class="content_company">Company Name<span class="email_separator">: </span>'.$get_clientmail[0]->name.'</p>
    								<p class="content_address1">Address1<span class="email_separator">: </span>'.$get_clientmail[0]->address1.'</p>
    								<p class="content_address2">Address2<span class="email_separator">: </span>'.$get_clientmail[0]->address2.'</p>
    								<p class="content_city">City<span class="email_separator">: </span>'.$get_clientmail[0]->city.'</p>
    								<p class="content_state">State<span class="email_separator">: </span>'.$get_clientmail[0]->state.'</p>
    								<p class="content_zipcode">Zipcode<span class="email_separator">: </span>'.$get_clientmail[0]->zip_code.'</p>
    							</div>
    							<div class="email_body_right">
    								<p class="content_phone">Phone<span class="email_separator">: </span>'.$get_clientmail[0]->phone.'</p>
    								<p class="content_email">Email<span class="email_separator">: </span>'.$get_clientmail[0]->email.'</p>
    							</div>
    						</div>

    						<div class="email_body_job_content" style="border-bottom: 1px solid #000;">
    							<div class="email_body_job_left">
    								<p class="jobcontent_currentdate">Date<span class="email_separator">: </span>'.$current_date.'</p>
    								<p class="jobcontent_company">Job Number<span class="email_separator">: </span>'.$get_clientjobdata[0]->job_no.'</p>
    								<p class="jobcontent_project">Project<span class="email_separator">: </span>'.$get_clientjobdata[0]->project.'</p>
    								<p class="jobcontent_customername">Customer Name<span class="email_separator">: </span>'.$get_clientjobdata[0]->customer_name.'</p>
    								<p class="jobcontent_address1">Address1<span class="email_separator">: </span>'.$get_clientjobdata[0]->address1.'</p>
    								<p class="jobcontent_address2">Address2<span class="email_separator">: </span>'.$get_clientjobdata[0]->address2.'</p>
    								<p class="jobcontent_city">City<span class="email_separator">: </span>'.$get_clientjobdata[0]->city.'</p>
    								<p class="jobcontent_state">State<span class="email_separator">: </span>'.$get_clientjobdata[0]->state.'</p>
    								<p class="jobcontent_siteaddress">Site Address<span class="email_separator">: </span>'.$get_clientjobdata[0]->site_address.'</p>
    								<p class="jobcontent_deliveryinst">Delivery Instructions<span class="email_separator">: </span>'.$get_clientjobdata[0]->delivery_instructions.'</p>
    								<p class="jobcontent_date">Date<span class="email_separator">: </span>'.$get_clientjobdata[0]->date.'</p>
    								<p class="jobcontent_orderedby">Ordered By<span class="email_separator">: </span>'.$user_meta->display_name.'</p>
    							</div>
    						</div>
    							
    						<div>
    							'.$animalhtml.'
    						</div>
    					</div>
    				';

    mail($send_email,"Order Details",$email_body,$header);
    mail($user_email,"Order Details",$email_body,$header);
    mail($email_copy,"Order Details",$email_body,$header);
    $profile_id = um_profile_id();  
    if($profile_id==1){
        $member_id=-1;
    }else{
        $user_meta = get_userdata($profile_id);            
        $email = $user_meta->user_email;
        $role = $user_meta->roles[0];
        $get_member_id = $wpdb->get_results($wpdb->prepare("SELECT member_id,number_emails,client_id FROM member_detailes WHERE email = '".$email."'"));
        $client_id= $get_member_id[0]->client_id; 
        $member_id = $get_member_id[0]->member_id;            
        $last_email_date=date('Y/m/d H:i:s');
        $number_emails_count = $get_member_id[0]->number_emails; 
        if($number_emails_count==""||$number_emails_count==NULL){
        $number_emails=1;
        }else{
        $number_emails=$number_emails_count+1;
        }
        
        $wpdb->get_results($wpdb->prepare("UPDATE member_detailes SET last_email_job_no = '".$job_no."',last_email_date = '".$last_email_date."',number_emails = '".$number_emails."' WHERE member_id = $member_id"));
        $wpdb->get_results($wpdb->prepare("UPDATE client_detailes SET last_email_job_no = '".$job_no."',last_email_date = '".$last_email_date."',number_emails = '".$number_emails."',last_email_member_id=$member_id WHERE client_id = $client_id"));
        $wpdb->get_results($wpdb->prepare("UPDATE job_details SET last_email_date = '".$last_email_date."' WHERE member_id=$member_id AND job_no = '".$job_no."'"));                
       }

		print_r(json_encode($email_data));
		die();

}

$user_id = wp_get_current_user();

$animal_site_base_url=get_bloginfo('wpurl');
add_action( 'um_user_login', 'my_user_login', 10, 1 );
function my_user_login( $args ) {
$url=$animal_site_base_url."/um_my-account/clientjobs/";
wp_redirect( $url );
}

add_action( 'um_on_login_before_redirect', 'my_on_login_before_redirect', 10, 1 );
function my_on_login_before_redirect( $user_id ) {
$url=$animal_site_base_url."/um_my-account/clientjobs/";
wp_redirect( $url );
}

add_action( 'wp_ajax_nopriv_selected_job_mod', 'selected_job_mod' );
add_action( 'wp_ajax_selected_job_mod', 'selected_job_mod' );
function selected_job_mod() {
	$change_val = $_POST['change_val']; 
	$client_id = $_POST['client_id']; 
      global $wpdb;
      $jobs_data = $wpdb->get_results($wpdb->prepare("SELECT animal_detailes.filename ,animal_detailes.id,job_animals.s_no FROM animal_detailes JOIN job_animals ON animal_detailes.id = job_animals.animal_sno WHERE job_id='".$change_val."' And animal_detailes.client_id=$client_id ORDER By animal_detailes.created_at"));	
    // $html="<option value =''>Select</option>"; 
     $html ="";
     $count=0;
     if(count($jobs_data)!=0){
	 	foreach($jobs_data as $data) {
			$html .="<option value='$data->s_no' animal-id='$data->id' >$data->filename</option>";
			$count++;
		}    	
     }

	print_r(json_encode($html));
	die();
};

add_action( 'wp_ajax_nopriv_selected_animal_view', 'selected_animal_view' );
add_action( 'wp_ajax_selected_animal_view', 'selected_animal_view' );
function selected_animal_view() {
	$um_file_id = $_POST['um_file_id']; 
	$client_id = $_POST['client_id']; 
	$job_id = $_POST['job_id']; 
	$job_animal_id = $_POST['job_animal_id']; 	
	$files=array();
	global $wpdb;
    $idx=0;
			$get_animals = $wpdb->get_results($wpdb->prepare("SELECT * FROM animal_detailes WHERE client_id = $client_id AND id = $um_file_id  And type in ('custom upload(".$job_id.")','')"));

			foreach($get_animals as $animal_det) {

					$files[$idx]['id'] = $animal_det->id;
					$files[$idx]['clientid'] = $animal_det->client_id;
					$files[$idx]['img_src'] = $animal_det->file_name;
					$files[$idx]['file_name'] = $animal_det->filename;
					$files[$idx]['directview'] = 'yes';
					$files[$idx]['option_a'] = $animal_det->option_a;
					$files[$idx]['option_b'] = $animal_det->option_b;
					$files[$idx]['option_c'] = $animal_det->option_c;
					$files[$idx]['option_d'] = $animal_det->option_d;
					$files[$idx]['option_e'] = $animal_det->option_e;	
					$files[$idx]['option_f'] = $animal_det->option_f;
					$files[$idx]['option_g'] = $animal_det->option_g;
					$files[$idx]['option_p'] = $animal_det->option_p;
					$files[$idx]['option_v'] = $animal_det->option_v;
					$files[$idx]['option_w'] = $animal_det->option_w;
					$files[$idx]['option_x'] = $animal_det->option_x;		
					$files[$idx]['option_y'] = $animal_det->option_y;
					$files[$idx]['option_z'] = $animal_det->option_z;					

			$get_animal_job_det = $wpdb->get_results($wpdb->prepare("SELECT * FROM job_animals WHERE client_id = $client_id AND animal_sno = $um_file_id AND s_no=$job_animal_id"));
            if(!empty($get_animal_job_det)){
				foreach($get_animal_job_det as $getanimals) {

					$files[$idx]['s_no'] = $getanimals->s_no;
					$files[$idx]['animal_sno'] = $getanimals->animal_sno;
					$files[$idx]['job_id'] = $getanimals->job_id;
					$files[$idx]['color'] = $getanimals->color;
					$files[$idx]['coating'] = $getanimals->coating;
					$files[$idx]['thickness'] = $getanimals->thickness;
					$files[$idx]['type'] = $getanimals->type;
					$files[$idx]['option_a_val'] = $getanimals->option_a;
					$files[$idx]['option_b_val'] = $getanimals->option_b;
					$files[$idx]['option_c_val'] = $getanimals->option_c;
					$files[$idx]['option_d_val'] = $getanimals->option_d;
					$files[$idx]['option_e_val'] = $getanimals->option_e;	
					$files[$idx]['option_f_val'] = $getanimals->option_f;
					$files[$idx]['option_g_val'] = $getanimals->option_g;
					$files[$idx]['option_p_val'] = $getanimals->option_p;
					$files[$idx]['option_v_val'] = $getanimals->option_v;
					$files[$idx]['option_w_val'] = $getanimals->option_w;
					$files[$idx]['option_x_val'] = $getanimals->option_x;		
					$files[$idx]['option_y_val'] = $getanimals->option_y;
					$files[$idx]['option_z_val'] = $getanimals->option_z;
					$files[$idx]['size_of'] = $getanimals->size_of;	
					$files[$idx]['no_of'] = $getanimals->no_of;	
					$files[$idx]['reference'] = $getanimals->reference;				
             }
         }
       $idx++;     
     }

	print_r(json_encode($files)); 
	die();
};

add_action( 'wp_ajax_nopriv_animal_mod_save', 'animal_mod_save' );
add_action( 'wp_ajax_animal_mod_save', 'animal_mod_save' );
function animal_mod_save() {
    global $wpdb;	
	$job_no = $_POST['job_no']; 
	$id = $_POST['id']; 
	$job_animal_id = $_POST['job_animal_id']; 
	$modal_color = $_POST['modal_color']; 
	$modal_coating = $_POST['modal_coating']; 
	$modal_thickness = $_POST['modal_thickness']; 
	$modal_type = $_POST['modal_type']; 
	$modal_optiona = $_POST['modal_optiona']; 
	$modal_optionb = $_POST['modal_optionb']; 
	$modal_optionc = $_POST['modal_optionc']; 
	$modal_optiond = $_POST['modal_optiond']; 	
	$modal_optione = $_POST['modal_optione']; 
	$modal_optionf = $_POST['modal_optionf']; 
	$modal_optiong = $_POST['modal_optiong']; 	
	$modal_optionp = $_POST['modal_optionp']; 
	$modal_optionv = $_POST['modal_optionv']; 
	$modal_optionw = $_POST['modal_optionw']; 	
	$modal_optionx = $_POST['modal_optionx']; 
	$modal_optiony = $_POST['modal_optiony']; 
	$modal_optionz = $_POST['modal_optionz']; 
	$modal_size = $_POST['modal_size']; 
	$modal_noof = $_POST['modal_noof']; 

	$profile_id = um_profile_id();  
	$user_meta = get_userdata($profile_id);

	$email = $user_meta->user_email;
	$role = $user_meta->roles[0];


	if($role == 'um_client') {

    	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}
	if($role == 'um_member') {

		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}

	$client_id = $get_clientid[0]->client_id;



	$wpdb->get_results($wpdb->prepare("UPDATE job_animals SET color = '".$modal_color."',coating = '".$modal_coating."',thickness = '".$modal_thickness."',type = '".$modal_type."',option_a = '".$modal_optiona."',option_b = '".$modal_optionb."',option_c = '".$modal_optionc."',option_d = '".$modal_optiond."',option_e = '".$modal_optione."',option_f = '".$modal_optionf."',option_g = '".$modal_optiong."',option_p = '".$modal_optionp."',option_v = '".$modal_optionv."',option_w = '".$modal_optionw."',option_x = '".$modal_optionx."',option_y = '".$modal_optiony."',option_z = '".$modal_optionz."',size_of = '".$modal_size."',no_of = '".$modal_noof."' WHERE animal_sno = $id AND job_id= '".$job_no."' AND s_no=$job_animal_id"));

	echo(json_encode("updated"));
	die();	
}

add_action( 'wp_ajax_nopriv_animal_mod_delete', 'animal_mod_delete' );
add_action( 'wp_ajax_animal_mod_delete', 'animal_mod_delete' );
function animal_mod_delete() {
    global $wpdb;	
	$job_no = $_POST['job_no']; 
	$id = $_POST['id']; 
	$job_animal_id = $_POST['job_animal_id']; 

	$profile_id = um_profile_id();  
	$user_meta = get_userdata($profile_id);

	$email = $user_meta->user_email;
	$role = $user_meta->roles[0];


	if($role == 'um_client') {

    	$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}
	if($role == 'um_member') {

		$get_clientid = $wpdb->get_results($wpdb->prepare("SELECT client_id FROM member_detailes WHERE email = '".$email."'"));

	}

	$client_id = $get_clientid[0]->client_id;



	$wpdb->get_results($wpdb->prepare("DELETE FROM job_animals WHERE animal_sno = $id AND job_id= '".$job_no."' AND s_no=$job_animal_id"));

	echo(json_encode("DELETE FROM job_animals WHERE animal_sno = $id AND job_id= '".$job_no."' AND s_no=$job_animal_id"));
	die();	
}



add_action('um_after_account_general', 'showExtraFields', 100);
function showExtraFields()
{   
	global $wpdb;
    $profile_id = um_profile_id();  
    if($profile_id==1){
        $member_id=-1;
    }else{
        $user_meta = get_userdata($profile_id);            
        $email = $user_meta->user_email;
        $role = $user_meta->roles[0];
        $get_member_id = $wpdb->get_results($wpdb->prepare("SELECT member_id,number_emails FROM member_detailes WHERE email = '".$email."'"));
        $member_id = $get_member_id[0]->member_id;            

        $member_detailes=$wpdb->get_results($wpdb->prepare("SELECT * FROM member_detailes WHERE member_id = $member_id"));
       }	
?>

<div id="um_field_custom_user_first_name" class="um-field um-field-text  um-field-user_email um-field-text um-field-type_text">
	<div class="um-field-label">
	    <label for="user_email">First Name</label>
	    <div class="um-clear"></div>
   </div>
   <div class="um-field-area">
   	<input autocomplete="off" class="um-form-field valid um_user_first_name" type="text" name="um_user_first_name"  value="<?php echo $member_detailes[0]->first_name;?>" >
  </div>
</div>
<div id="um_field_custom_user_last_name" class="um-field um-field-text  um-field-user_email um-field-text um-field-type_text">
	<div class="um-field-label">
	    <label for="user_email">Last Name</label>
	    <div class="um-clear"></div>
   </div>
   <div class="um-field-area">
   	<input autocomplete="off" class="um-form-field valid um_custom_user_last_name" type="text" name="um_custom_user_last_name"  value="<?php echo $member_detailes[0]->surname;?>">
  </div>
</div>
<div id="um_field_custom_user_mobile" class="um-field um-field-text  um-field-user_email um-field-text um-field-type_text">
	<div class="um-field-label">
	    <label for="user_email">Mobile</label>
	    <div class="um-clear"></div>
   </div>
   <div class="um-field-area">
   	<input autocomplete="off" class="um-form-field valid um_custom_user_mobile" type="text" name="um_custom_user_mobile"  value="<?php echo $member_detailes[0]->mobile;?>">
  </div>
</div>
<div id="um_field_custom_user_email" class="um-field um-field-text  um-field-user_email um-field-text um-field-type_text">
	<div class="um-field-label">
	    <label for="user_email">Password</label>
	    <div class="um-clear"></div>
   </div>
   <div class="um-field-area">
   	<input autocomplete="off" class="um-form-field valid um_custom_user_password" type="text" name="um_custom_user_password"  value="<?php echo $member_detailes[0]->password;?>">
  </div>
</div>
<div id="um_field_custom_user_update" class="um-field um-field-text  um-field-user_update um-field-text um-field-type_text">

   <div class="um-field-area">
   	<input class="um_custom_user_update um-form-field valid um_custom_user_update" type="button" name="um_custom_user_update"  value="update">
  </div>
</div>
<style type="text/css">
.um-account-main #um_account_submit_general{
display: none !important;
}
</style>
<script type="text/javascript">
	jQuery(document).ready(function(){
		jQuery(".um_custom_user_update").click(function() {
			var animalsel_base_url="<?php echo get_bloginfo('wpurl');?>";
			var ajax_url=animalsel_base_url+"/wp-admin/admin-ajax.php";
			var first_name=jQuery(".um_user_first_name").val();
			var lastname=jQuery(".um_custom_user_last_name").val();
			var phn_num=jQuery(".um_custom_user_mobile").val();
			var password=jQuery(".um_custom_user_password").val();
					jQuery.ajax({
		                    type: 'POST',
		                    dataType: 'json',
		                    url: ajax_url,
		                    data: {
		                      action: 'um_update_account_det',
		                      first_name: first_name,
		                      lastname: lastname,
		                      phn_num: phn_num,
		                      password: password
		                    },
		                    success: function(response) {
		                      location.reload();
		                      console.log(response);
		                    }, 
		                    error: function(xhr, status, error,response) {
		                       console.log(error);
		                       var err = eval("(" + xhr.responseText + ")");
		                       console.log(xhr);
		                    }
	      			});			
		})
	})
</script>
<?php
}

add_action( 'wp_ajax_nopriv_um_update_account_det', 'um_update_account_det' );
add_action( 'wp_ajax_um_update_account_det', 'um_update_account_det' );
function um_update_account_det() {
$first_name=$_POST['first_name'];
$lastname=$_POST['lastname'];
$phn_num=$_POST['phn_num'];
$password=$_POST['password'];
	global $wpdb;
    $profile_id = um_profile_id();  
    if($profile_id==1){
        $member_id=-1;
    }else{
        $user_meta = get_userdata($profile_id);            
        $email = $user_meta->user_email;
        $role = $user_meta->roles[0];
        $get_member_id = $wpdb->get_results($wpdb->prepare("SELECT member_id,number_emails FROM member_detailes WHERE email = '".$email."'"));
        $member_id = $get_member_id[0]->member_id;            
        $member_detailes=$wpdb->get_results($wpdb->prepare("SELECT * FROM member_detailes WHERE member_id = $member_id"));
        $db_password = $member_detailes[0]->password;        
        $wpdb->get_results($wpdb->prepare("UPDATE member_detailes SET 	first_name = '".$first_name."',surname = '".$lastname."',password = '".$password."',mobile = '".$phn_num."' WHERE member_id = $member_id"));
        if($db_password!=$password){

        wp_set_password( $password, $profile_id );  
		 print_r(json_encode($db_password."".$password));
		 die();                	
        }   
       }
   print_r(json_encode("success"));
   die();
}