<?php
class WAS_PostAddon
{
 public function __construct()
 {
	 add_action( 'add_meta_boxes', array( &$this, 'add_post_scheduler_metabox' ) );
	 add_action( 'save_post', array( &$this, 'save' ) ); 
 }
 public function add_post_scheduler_metabox()
 {
	add_meta_box( 'woocommerce-availability-scheduler', esc_html__('Availability Scheduler', 'woocommerce-availability-scheduler'), array( &$this, 'render_scheduler_availability_box' ), 'product' , 'advanced', 'high');
 }

 public static function get_post_meta($post_id)
 {
	global $was_product_model;
	return $was_product_model->get_all_product_meta($post_id);
 }
 private function save_post_meta($post_id)
 {
	 global $was_product_model;
	$was_product_model->save_product_meta($post_id);
 }	
 public function save( $post_id ) 
 {
	
		/*
		 * We need to verify this came from the our screen and with proper authorization,
		 * because save_post can be triggered at other times.
		 */
		
		// Check if our nonce is set.
		if ( ! isset( $_POST['was_input_fields_nonce'] ) )
			return $post_id;

		$nonce = $_POST['was_input_fields_nonce'];

		// Verify that the nonce is valid.
		if ( ! wp_verify_nonce( $nonce, 'was_input_fields' ) )
			return $post_id;

		// If this is an autosave, our form has not been submitted,
                //     so we don't want to do anything.
		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
			return $post_id;

		// Sanitize the user input.
		
		// Update the meta field.
		$this->save_post_meta($post_id);
	}
	
 function render_scheduler_availability_box($post) 
	{ 
		global $wp_roles,$wccm_customer_model, $was_product_model;
		
		$js_options = array(
			'before_message' =>esc_html__('Before sale message', 'woocommerce-availability-scheduler'),
			'placeholder_message' => esc_html__('Message', 'woocommerce-availability-scheduler')
		);
		wp_enqueue_style( 'was-select2-style', WCAS_PLUGIN_PATH.'/css/select2.min.css' ); 
		wp_enqueue_style( 'was-datetimepicker-css', WCAS_PLUGIN_PATH.'/css/vendor/datepicker/jquery.datetimepicker.min.css' );
		wp_enqueue_style( 'was-timepicker-css', WCAS_PLUGIN_PATH.'/css/timePicker.css' );
		wp_enqueue_style( 'was-admin', WCAS_PLUGIN_PATH.'/css/admin-availability-box.css' );
		wp_enqueue_style('was-timepicker');		
		
		wp_enqueue_script('jquery-ui-datepicker');
		wp_enqueue_script('jquery-ui-jquery-ui-slider');
		wp_enqueue_script( 'selectWoo');
		wp_enqueue_script('was-datetimepicker-js', WCAS_PLUGIN_PATH.'/js/vendor/datepicker/jquery.datetimepicker.full.min.js', array('jquery'));  //adds datetime controls 
		wp_enqueue_script('was-ui-js', WCAS_PLUGIN_PATH.'/js/jquery-ui.js', array('jquery'));  
		wp_enqueue_script('was-timepicker-js', WCAS_PLUGIN_PATH.'/js/jquery.timePicker.min.js', array('jquery'));		
		wp_enqueue_script('was-admin-availability-box' ,  WCAS_PLUGIN_PATH. '/js/was-admin-availability-box.js',  array('jquery' ));	
	
		wp_register_script('was-admin-product-detail-page', WCAS_PLUGIN_PATH.'/js/was-admin-product-detail-page.js', array('jquery')); 
		wp_localize_script( 'was-admin-product-detail-page', 'wcas', $js_options);
		wp_enqueue_script('was-admin-product-detail-page' );	
		// Display the form, using the current value.
		$days = $was_product_model->get_product_meta( $post->ID, '_was_period', true);
		$start_times = $was_product_model->get_product_meta( $post->ID, '_was_start_time', true);
		$end_times = $was_product_model->get_product_meta( $post->ID, '_was_end_time', true);
		$product_page_msg = $was_product_model->get_product_meta( $post->ID, '_was_product_page_msg', true);
		$product_page_during_msg = $was_product_model->get_product_meta( $post->ID, '_was_product_page_during_msg', true);
		$product_page_after_msg = $was_product_model->get_product_meta( $post->ID, '_was_product_page_after_msg', true);
		$shop_page_msg = $was_product_model->get_product_meta( $post->ID, '_was_shop_page_msg', true);
		$shop_page_during_msg = $was_product_model->get_product_meta( $post->ID, '_was_shop_page_during_msg', true);
		$shop_page_after_msg = $was_product_model->get_product_meta( $post->ID, '_was_shop_page_after_msg', true);
		$countdown_to_start = $was_product_model->get_product_meta( $post->ID, '_was_countdown_to_start', true);
		$countdown_to_end = $was_product_model->get_product_meta( $post->ID, '_was_countdown_to_end', true);
		$was_hide = $was_product_model->get_product_meta( $post->ID, '_was_hide', true);
		$was_total_sales_limit = $was_product_model->get_product_meta( $post->ID, '_was_total_sales_limit', true);
		$where_countdown_to_start = $was_product_model->get_product_meta( $post->ID, '_was_where_countdown_to_start', true);
		$where_countdown_to_end = $was_product_model->get_product_meta( $post->ID, '_was_where_countdown_to_end', true);
		$where_sales_progressbar = $was_product_model->get_product_meta( $post->ID, '_was_where_sales_progressbar', true);
		$expiring_date = $was_product_model->get_product_meta( $post->ID, '_was_expiring_date', true);
		$visible_after_expiring_date = $was_product_model->get_product_meta( $post->ID, '_was_visible_after_expiring_date', true);
		$show_countdown_to_expiration_date = $was_product_model->get_product_meta( $post->ID, '_was_show_countdown_to_expiration_date', true);
		$expired_shop_message = $was_product_model->get_product_meta( $post->ID, '_was_expired_shop_message', true);
		$expired_product_message = $was_product_model->get_product_meta( $post->ID, '_was_expired_product_message', true);
		$before_expiration_shop_message = $was_product_model->get_product_meta( $post->ID, '_was_before_expiration_shop_message', true);
		$before_expiration_product_message = $was_product_model->get_product_meta( $post->ID, '_was_before_expiration_product_message', true);
		$allowed_roles = $was_product_model->get_product_meta( $post->ID, '_was_customer_roles', true);
		$customers_ids = $was_product_model->get_product_meta( $post->ID, '_was_customer_ids', true);
		$customer_roles_restriction_type = $was_product_model->get_product_meta( $post->ID, '_was_customer_roles_restriction_type', true);
		$customer_roles_restriction_message = $was_product_model->get_product_meta( $post->ID, '_was_customer_roles_restriction_message', true);
		$time_offset = WAS_OptionsMenu::get_option('time_offset');
		
		
		wp_nonce_field( 'was_input_fields', 'was_input_fields_nonce' );
		?>
		
		<h3 class="was-title"><?php esc_html_e('Current server date', 'woocommerce-availability-scheduler'); ?></h3>
		<p>
			<?php esc_html_e('Product availability is set using server time. Current server time is: ', 'woocommerce-availability-scheduler'); ?>
			<strong><?php echo date("l", strtotime($time_offset.' minutes')).", ".date("H:i", strtotime($time_offset.' minutes')); ?></strong> ( <?php echo $time_offset.' '.__('minute(s) offset. To change offset value, go to Bulk availability -> options menu', 'woocommerce-availability-scheduler');?> )
		</p>
		
		<h3 class="was-title"><?php esc_html_e('Today total product sales', 'woocommerce-availability-scheduler'); ?></h3>
		<p>
			<?php 
				$total_sales = $was_product_model->get_today_product_total_sales($post->ID); 
				$total_sales = isset($total_sales) ? $total_sales : 0;
				echo esc_html__('Today total sales: ', 'woocommerce-availability-scheduler').'<strong>'.$total_sales.'</strong>';
			?>
		</p>
		
		<h3 class="was-title"><?php esc_html_e('Expiring date & messages', 'woocommerce-availability-scheduler'); ?></h3>
		<p>
			<?php esc_html_e('The product will be no longer available after this date (will be set as \'draft\'). Leave empty if product hasn\'t an expiration date.', 'woocommerce-availability-scheduler'); ?>
			<br/><br/>
			<input type="text" name="_was_expiring_date" class="wcas_expiring-date" value="<?php echo $expiring_date; ?>"></input><button class="button" id="was_clear_expiring_date_button"><?php esc_html_e('Clear','woocommerce-availability-scheduler'); ?></button>
		</p>
		<p style="margin-top:20px; margin-bottom:20px;" class="was-form-field checkbox-par">	
			<label for="_was_visible_after_expiring_date"><?php esc_html_e('Leave the product visible (but unpurcasable) after expring date?', 'woocommerce-availability-scheduler'); ?></label>
			<input name="_was_visible_after_expiring_date" type="checkbox" value="1" <?php if($visible_after_expiring_date) echo 'checked="checked"';?>>
			
		</p>
		<p style="margin-top:20px; margin-bottom:20px;" class="was-form-field checkbox-par">	
			<label for="_was_show_countdown_to_expiration_date"><?php esc_html_e('Show countdown to expiration date?', 'woocommerce-availability-scheduler'); ?></label>
			<input name="_was_show_countdown_to_expiration_date" type="checkbox" value="1" <?php if($show_countdown_to_expiration_date) echo 'checked="checked"';?>>
			
		</p>
		
		<h4 class="was-title"><?php esc_html_e('Messages before product expiration ','woocommerce-availability-scheduler'); ?></h4>
		<p style="display:block; margin-top: 10px;">
			<label><?php esc_html_e('Use the following text area to display a message in the Shop (first box) and Product (second box) pages after the product exires (if still visible).', 'woocommerce-availability-scheduler'); ?></label><br/>
			<textarea placeholder="<?php esc_html_e('Shop message', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_before_expiration_shop_message"  ><?php if(isset($before_expiration_shop_message)) echo $before_expiration_shop_message; ?></textarea>
			<textarea placeholder="<?php esc_html_e('Product message'); ?>" rows="5" cols="30" name="_was_before_expiration_product_message"  ><?php if(isset($before_expiration_product_message)) echo $before_expiration_product_message; ?></textarea>
		</p>
		<h4 class="was-title"><?php esc_html_e('Messages after product expiration (if still visible)','woocommerce-availability-scheduler'); ?></h4>
		<p style="display:block; margin-top: 10px;">
			<label><?php esc_html_e('Use the following text area to display a message in the Shop (first box) and Product (second box) .', 'woocommerce-availability-scheduler'); ?></label><br/>
			<textarea placeholder="<?php esc_html_e('Shop message', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_expired_shop_message"  ><?php if(isset($expired_shop_message)) echo $expired_shop_message; ?></textarea>
			<textarea placeholder="<?php esc_html_e('Product message'); ?>" rows="5" cols="30" name="_was_expired_product_message"  ><?php if(isset($expired_product_message)) echo $expired_product_message; ?></textarea>
		</p>
						
					
		<div class="spacer"></div>
		
		<div id="wcas_tabs">
			<?php 
			$day_names = array(0 => 'Monday',1 => 'Tuesday',2 => 'Wednesday',3 => 'Thursday',4 => 'Friday',5 => 'Saturday',6 => 'Sunday');
			 ?>
			 <ul>
			 <?php for ($day=0; $day<7; $day++): ?>
				<li><a href="#tabs-<?php echo $day;?>"><?php esc_html_e($day_names[$day], 'woocommerce-availability-scheduler'); ?></a></li>
			 <?php endfor; ?>
			 </ul>
			
			<?php for ($day=0; $day<7; $day++): ?>
				<div id="tabs-<?php echo $day;?>">
						<p class="was-form-field">
							<label ><?php esc_html_e('Assign this configuration to the selected days', 'woocommerce-availability-scheduler'); ?></label>
							<input name="_was_assign_this_configuration_to_days[<?php echo $day; ?>][0]"  type="checkbox" value="0" ><?php esc_html_e('Monday', 'woocommerce-availability-scheduler'); ?></input>
							<input name="_was_assign_this_configuration_to_days[<?php echo $day; ?>][1]"  type="checkbox" value="1" ><?php esc_html_e('Tuesday', 'woocommerce-availability-scheduler'); ?></input>
							<input name="_was_assign_this_configuration_to_days[<?php echo $day; ?>][2]"  type="checkbox" value="2" ><?php esc_html_e('Wednesday', 'woocommerce-availability-scheduler'); ?></input>
							<input name="_was_assign_this_configuration_to_days[<?php echo $day; ?>][3]"  type="checkbox" value="3" ><?php esc_html_e('Thursday', 'woocommerce-availability-scheduler'); ?></input>
							<input name="_was_assign_this_configuration_to_days[<?php echo $day; ?>][4]"  type="checkbox" value="4" ><?php esc_html_e('Friday', 'woocommerce-availability-scheduler'); ?></input>
							<input name="_was_assign_this_configuration_to_days[<?php echo $day; ?>][5]"  type="checkbox" value="5" ><?php esc_html_e('Saturday', 'woocommerce-availability-scheduler'); ?></input>
							<input name="_was_assign_this_configuration_to_days[<?php echo $day; ?>][6]"  type="checkbox" value="6" ><?php esc_html_e('Sunday', 'woocommerce-availability-scheduler'); ?></input>
						
						</p>
						<p class="was-form-field">
							<label for="_was_period[<?php echo $day;?>]"><?php esc_html_e('Purchase period', 'woocommerce-availability-scheduler'); ?></label>
							<select name="_was_period[<?php echo $day;?>]" class="was_select_box" data-id="<?php echo $day;?>">
							  <option value="0" <?php if(isset($days[$day]) && $days[$day] == 0) echo 'selected'?>><?php esc_html_e('Throughout the day', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="1" <?php if(isset($days[$day]) && $days[$day] == 1) echo 'selected'?>><?php esc_html_e('Available during the selected time range', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="3" <?php if(isset($days[$day]) && $days[$day] == 3) echo 'selected'?>><?php esc_html_e('Unavailable during the selected time range', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="2" <?php if(isset($days[$day]) && $days[$day] == 2) echo 'selected'?>><?php esc_html_e('Disabled for this day', 'woocommerce-availability-scheduler'); ?></option>
							</select>
						</p>
						<p class="was-form-field ">
							<label for="_was_start_time[<?php echo $day;?>]"><?php esc_html_e('Start time', 'woocommerce-availability-scheduler'); ?></label>
							<input name="_was_start_time[<?php echo $day;?>]" class="wcas_start-time" id="time<?php echo ($day*2);?>" type="text" value="<?php if(isset($start_times[$day])) echo $start_times[$day]; else echo '08:00'; ?>" size="10" autocomplete="OFF" data-id="<?php echo $day*2;?>"disabled>
						</p>
						<p class="was-form-field ">	
							<label for="_was_end_time[<?php echo $day;?>]"><?php esc_html_e('End time', 'woocommerce-availability-scheduler'); ?></label>
							<input name="_was_end_time[<?php echo $day;?>]" class="wcas_end-time"   id="time<?php echo ($day*2)+1;?>" type="text" value="<?php if(isset($end_times[$day])) echo $end_times[$day]; else echo '09:00'; ?>" size="10" autocomplete="OFF" data-id="<?php echo ($day*2)+1;?>" disabled>
						</p>
						
						<h3 class="was-title"><?php  esc_html_e('Roles restriction', 'woocommerce-availability-scheduler');?></h3>
						<p><?php esc_html_e('Apply the current availability rule only to selected user roles. The excluded roles will be considered as unauthorized and will not be able to buy the product. <strong>Example:</strong> creating a rule where a product is unavailable from 8:00 to 10:00 for "customer" role, it will make the "administrator" role as unauthorized. It means, that he will be never be able to purchase the product. The "customer" instead will be able to pruchase it before 8:00 or after 10:00', 'woocommerce-availability-scheduler');?><br/>
							<?php // esc_html_e('If at least a role has been selected the product will be made unavailable for not logged users.', 'woocommerce-availability-scheduler');?></p>
						
						<select name="_was_customer_roles_restriction_type[<?php echo $day;?>]">
							<option value="apply_to_selected" <?php if(isset($customer_roles_restriction_type[$day]) && $customer_roles_restriction_type[$day] == "apply_to_selected") echo 'selected="selected"'; ?>><?php  esc_html_e('Apply to selected roles', 'woocommerce-availability-scheduler');?></option>
							<option value="except_the_selected" <?php if(isset($customer_roles_restriction_type[$day]) && $customer_roles_restriction_type[$day] == "except_the_selected") echo 'selected="selected"'; ?>><?php  esc_html_e('Apply to all except the selected roles', 'woocommerce-availability-scheduler');?></option>
						</select>
						<p><strong><?php  esc_html_e('Select roles (leave empty to apply rule to all logged and not logged users)', 'woocommerce-availability-scheduler');?></strong></p>
						<select class="js-role-select" name="_was_customer_roles[<?php echo $day;?>][]" multiple='multiple'> 
							<?php 
									//$first_time = !isset($options['_was_customer_roles']) ? true:false;
									foreach( $wp_roles->roles as $role_code => $role_data)
									{
										$selected = '';		
										/* if($role_code != 'administrator') */
										{
											if(isset($allowed_roles[$day]))
												 foreach($allowed_roles[$day] as $role)
													if($role == $role_code)
															$selected = ' selected="selected" '; 
													
											echo '<option value="'.$role_code.'" '.$selected.'>'.$role_data['name'].'</option>';
										}
									}
									if(isset($allowed_roles[$day]))
										foreach($allowed_roles[$day] as $role)
											if($role == 'translate')
													$selected = ' selected="selected" '; 
								?>
						</select>
						<br/>
						<p><strong><?php esc_html_e('Message showed to non authorized users', 'woocommerce-availability-scheduler'); ?></strong></p>
						<textarea id="_was_customer_roles_restriction_message[<?php echo $day?>]"  placeholder="<?php esc_html_e('Type a message to show to non authorized roles', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_customer_roles_restriction_message[<?php echo $day;?>]"  ><?php if(isset($customer_roles_restriction_message) && isset($customer_roles_restriction_message[$day])) echo $customer_roles_restriction_message[$day]; ?></textarea>
						
								
						<h3 class="was-title" style="margin-top:25px;"><?php esc_html_e('Shop page messages', 'woocommerce-availability-scheduler'); ?></h3>
						<p class="was-form-field ">	
							<p><strong>HTML code is accepted. You can also use [start_time] and [end_time] shortcodes to display start and end times directly in to the message</strong></p>
							<textarea id="shop_page_msg<?php echo $day?>" placeholder="<?php esc_html_e('Before sale message', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_shop_page_msg[<?php echo $day;?>]" ><?php if(isset($shop_page_msg[$day])) echo $shop_page_msg[$day]; ?></textarea>
							<textarea id="shop_page_during_msg<?php echo $day?>" class="message_box_hidable" placeholder="<?php esc_html_e('During sale message', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_shop_page_during_msg[<?php echo $day;?>]"  ><?php if(isset($shop_page_during_msg[$day])) echo $shop_page_during_msg[$day]; ?></textarea>
							<textarea id="shop_page_after_msg<?php echo $day?>" class="message_box_hidable" placeholder="<?php esc_html_e('After sale message', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_shop_page_after_msg[<?php echo $day;?>]"  ><?php if(isset($shop_page_after_msg[$day])) echo $shop_page_after_msg[$day]; ?></textarea>
						</p>
						<h3  class="was-title" style="margin-top:25px;"><?php esc_html_e('Product page messages', 'woocommerce-availability-scheduler'); ?></h3>
						<p class="was-form-field ">	
							<p><strong><?php esc_html_e('HTML code is accepted. You can also use [start_time] and [end_time] shortcodes to display start and end times directly in to the message', 'woocommerce-availability-scheduler'); ?>s</strong></p>
							<textarea id="product_page_msg<?php echo $day?>" placeholder="<?php esc_html_e('Before sale message', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_product_page_msg[<?php echo $day;?>]"  ><?php if(isset($product_page_msg[$day])) echo $product_page_msg[$day]; ?></textarea>
							<textarea id="product_page_during_msg<?php echo $day?>" class="message_box_hidable" placeholder="<?php esc_html_e('During sale message', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_product_page_during_msg[<?php echo $day;?>]"  ><?php if(isset($product_page_during_msg[$day])) echo $product_page_during_msg[$day]; ?></textarea>
							<textarea id="product_page_after_msg<?php echo $day?>" class="message_box_hidable" placeholder="<?php esc_html_e('After sale message', 'woocommerce-availability-scheduler'); ?>" rows="5" cols="30" name="_was_product_page_after_msg[<?php echo $day;?>]"  ><?php if(isset($product_page_after_msg[$day])) echo $product_page_after_msg[$day]; ?></textarea>
						</p>
						<h3  class="was-title" style="margin-top:25px;"><?php esc_html_e('Hide product', 'woocommerce-availability-scheduler'); ?></h3>
						<p style="margin-top:50px;" class="was-form-field checkbox-par">	
							<label for="_was_hide[<?php echo $day;?>]"><?php esc_html_e('Hide product during unavailability period? (product will be setted as draft)', 'woocommerce-availability-scheduler'); ?></label>
							<input name="_was_hide[<?php echo $day;?>]" type="checkbox" value="1" <?php if(isset($was_hide[$day])) echo "checked"; ?>>
						</p>
						
						<h3  class="was-title" style="margin-top:80px;"><?php esc_html_e('Total sales limit', 'woocommerce-availability-scheduler'); ?></h3>
						<p style="margin-top:50px;" class="was-form-field checkbox-par">	
							<label style="height:90px;" for="_was_total_sales_limit[<?php echo $day;?>]"><?php esc_html_e('After the following value of total sales, the item will be unavaiable.', 'woocommerce-availability-scheduler'); ?><br/>
								<strong><?php esc_html_e('Leave 0 to disable this feature.', 'woocommerce-availability-scheduler'); ?></strong>
							</label>
							<input name="_was_total_sales_limit[<?php echo $day;?>]" type="number" value="<?php if(isset($was_total_sales_limit[$day]) && isset($was_total_sales_limit[$day])) echo $was_total_sales_limit[$day]; else echo 0; ?>" step="1" min="0"  required>
							<p><small><strong><?php esc_html_e('Note:', 'woocommerce-availability-scheduler'); ?></strong> <?php esc_html_e('Purchase will be disabled at sales limit reach even if the end time has not been reached in case of "Time range avaialability" period or it the "Throught the day" options has been selected.', 'woocommerce-availability-scheduler'); ?></small></p>
							</p>
						<p class="was-form-field" style="margin-top:40px;">
							<label for="_was_where_sales_progressbar[<?php echo $day;?>]"><?php esc_html_e('Would you like to display a progress bar display current day sales on total sale?', 'woocommerce-availability-scheduler'); ?></label>
							<select name="_was_where_sales_progressbar[<?php echo $day;?>]" class="was_select_box" >
							  <option value="0" <?php if(isset($where_sales_progressbar[$day]) && $where_sales_progressbar[$day] == 0) echo 'selected'?>><?php esc_html_e('No', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="1" <?php if(isset($where_sales_progressbar[$day]) && $where_sales_progressbar[$day] == 1) echo 'selected'?>><?php esc_html_e('Shop page', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="2" <?php if(isset($where_sales_progressbar[$day]) && $where_sales_progressbar[$day] == 2) echo 'selected'?>><?php esc_html_e('Product page', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="3" <?php if(isset($where_sales_progressbar[$day]) && $where_sales_progressbar[$day] == 3) echo 'selected'?>><?php esc_html_e('Both', 'woocommerce-availability-scheduler'); ?></option>
							</select>
						</p>
						
						
						<h3  class="was-title" style="margin-top:80px;"><?php esc_html_e('Countdown', 'woocommerce-availability-scheduler'); ?></h3>
						<p style="margin-top:50px;" class="was-form-field checkbox-par">	
							<label for="_was_countdown_to_start[<?php echo $day;?>]"><?php esc_html_e('Use countdown to start time?', 'woocommerce-availability-scheduler'); ?></label>
							<input name="_was_countdown_to_start[<?php echo $day;?>]" type="checkbox" value="1" <?php if(isset($countdown_to_start[$day])) echo "checked"; ?>>
						</p>
						<p class="was-form-field">
							<label for="_was_where_countdown_to_start[<?php echo $day;?>]"><?php esc_html_e('Where do you want to use start timer?', 'woocommerce-availability-scheduler'); ?></label>
							<select name="_was_where_countdown_to_start[<?php echo $day;?>]" class="was_select_box" >
							  <option value="0" <?php if(isset($where_countdown_to_start[$day]) && $where_countdown_to_start[$day] == 0) echo 'selected'?>><?php esc_html_e('Shop page', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="1" <?php if(isset($where_countdown_to_start[$day]) && $where_countdown_to_start[$day] == 1) echo 'selected'?>><?php esc_html_e('Product page', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="2" <?php if(isset($where_countdown_to_start[$day]) && $where_countdown_to_start[$day] == 2) echo 'selected'?>><?php esc_html_e('Both', 'woocommerce-availability-scheduler'); ?></option>
							</select>
						</p>
						<p><br/></p>
						<p class="was-form-field checkbox-par">	
							<label for="_was_countdown_to_end[<?php echo $day;?>]"><?php esc_html_e('Use countdown to end time?', 'woocommerce-availability-scheduler'); ?></label>
							<input name="_was_countdown_to_end[<?php echo $day;?>]" type="checkbox" value="1" <?php if(isset($countdown_to_end[$day])) echo "checked"; ?>>
						</p>
						<p class="was-form-field">
							<label for="_was_where_countdown_to_end[<?php echo $day;?>]"><?php esc_html_e('Where do you want to use end timer?', 'woocommerce-availability-scheduler'); ?></label>
							<select name="_was_where_countdown_to_end[<?php echo $day;?>]" class="was_select_box" >
							  <option value="0" <?php if(isset($where_countdown_to_end[$day]) && $where_countdown_to_end[$day] == 0) echo 'selected'?>><?php esc_html_e('Shop page', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="1" <?php if(isset($where_countdown_to_end[$day]) && $where_countdown_to_end[$day] == 1) echo 'selected'?>><?php esc_html_e('Product page', 'woocommerce-availability-scheduler'); ?></option>
							  <option value="2" <?php if(isset($where_countdown_to_end[$day]) && $where_countdown_to_end[$day] == 2) echo 'selected'?>><?php esc_html_e('Both', 'woocommerce-availability-scheduler'); ?></option>
							</select>
						</p>
						
						
				</div>
			<?php endfor; ?>
		</div>
		
		<?php
	}
}
?>