<?php
class Custom_Toll_Free extends WP_Widget {
	function Custom_Toll_Free() {
		$widget_ops = array('classname' => 'Custom_Toll_Free', 'description' => 'The Toll Free Site' );
		$this->WP_Widget('Custom_Toll_Free', THEMESTUDIO_THEME_NAME.' Toll free', $widget_ops);
	}

	function widget($args, $instance) {
		extract($args, EXTR_SKIP);

		echo $before_widget;
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
		$link_image = empty($instance['link_image']) ? '' : apply_filters('widget_link_image', $instance['link_image']);
		$desc 	 = empty($instance['desc']) ? '' : apply_filters('widget_desc', $instance['desc']);
		$title_phone	 = empty($instance['title_phone']) ? '' : apply_filters('widget_title_phone', $instance['title_phone']);
		$phone 	 = empty($instance['phone']) ? '' : apply_filters('widget_phone', $instance['phone']);
		
		if($title){ 
			echo $before_title.$title.$after_title; 
		}
		
		?>
		
		<div class="any_questions">
			<?php if ($link_image): ?>
            	<img src="<?php echo $link_image; ?>" alt="" />
			<?php endif; ?>
			<?php if ($desc): ?>
            	<p><?php echo $desc; ?></p>
			<?php endif; ?>
			<?php if ($phone || $title_phone): ?>
            	<div class="clearfix mar_top1"></div>
            	<h3><?php if($title_phone){ echo '<i>'.$title_phone.'</i>'; } ?>  <?php if($phone){ echo $phone; } ?></h3>
			<?php endif; ?>
        </div>
			
		<?php

		
		echo $after_widget;
		
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] 		= strip_tags($new_instance['title']);
		$instance['link_image'] = strip_tags($new_instance['link_image']);
		$instance['desc'] 		= strip_tags($new_instance['desc']);
		$instance['title_phone']= strip_tags($new_instance['title_phone']);
		$instance['phone'] 		= strip_tags($new_instance['phone']);

		return $instance;
	}

	function form($instance) {
		$instance 	= wp_parse_args( (array) $instance, array('title'=>'Toll free', 'link_image' => get_template_directory_uri().'/assets/images/site-img06.jpg', 'desc' => 'If you have any questions, feel free to call us toll-free', 'title_phone' => 'Toll-free:', 'phone' => '1-234-567-8900'));
		$title 		= strip_tags($instance['title']);
		$link_image = strip_tags($instance['link_image']);
		$desc 		= strip_tags($instance['desc']);
		$title_phone= strip_tags($instance['title_phone']);
		$phone 		= strip_tags($instance['phone']);

?>
		<p>
			<label for="<?php echo $this->get_field_id('title'); ?>">
				Widget title: 
				<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
			</label>
		</p>
		<p>
			<label for="<?php echo $this->get_field_id('link_image'); ?>">
				Link Image: 
				<input class="widefat" id="<?php echo $this->get_field_id('link_image'); ?>" name="<?php echo $this->get_field_name('link_image'); ?>" type="text" value="<?php echo esc_attr($link_image); ?>" />
			</label>
		</p>
		<p>
			<label for="<?php echo $this->get_field_id('desc'); ?>">
				Description: 
				<input class="widefat" id="<?php echo $this->get_field_id('desc'); ?>" name="<?php echo $this->get_field_name('desc'); ?>" type="text" value="<?php echo esc_attr($desc); ?>" />
			</label>
		</p>
		<p>
			<label for="<?php echo $this->get_field_id('title_phone'); ?>">
				Title Phone: 
				<input class="widefat" id="<?php echo $this->get_field_id('title_phone'); ?>" name="<?php echo $this->get_field_name('title_phone'); ?>" type="text" value="<?php echo esc_attr($title_phone); ?>" />
			</label>
		</p>
		<p>
			<label for="<?php echo $this->get_field_id('phone'); ?>">
				Phone: 
				<input class="widefat" id="<?php echo $this->get_field_id('phone'); ?>" name="<?php echo $this->get_field_name('phone'); ?>" type="text" value="<?php echo esc_attr($phone); ?>" />
			</label>
		</p>
<?php
	}
}

register_widget('Custom_Toll_Free');
?>