<?php 

if ( ! defined( 'ABSPATH' ) ) exit;

class WP_Widget_Contact extends WP_Widget {

	function __construct() {
		$widget_ops = array('classname' => 'ut_widget_contact', 'ut_widget_contact_description' => __( 'Insert your contact data in here!', 'unitedthemes') );
		parent::__construct('ut_contact', __('United Themes - Contact', 'unitedthemes'), $widget_ops);
		$this->alt_option_name = 'ut_widget_contact';

	}
	
	function form($instance) {
	
	$title    = ( isset($instance['title']) ) ? $instance['title'] : '';
	$address  = ( isset($instance['address']) ) ? $instance['address'] : '';
	$phone    = ( isset($instance['phone']) ) ? $instance['phone'] : '';
	$fax      = ( isset($instance['fax']) ) ? $instance['fax'] : '';
    $internet = (isset($instance['internet']) ) ? $instance['internet'] : '';
	$email    = ( isset($instance['email']) ) ? $instance['email'] : '';
	
	?>

    <label><?php _e('Title', 'unitedthemes'); ?>: <input type="text" style="width:100%;" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" value="<?php echo esc_attr( $title ); ?>" /></label>
    <label><?php _e('Address', 'unitedthemes'); ?>: <textarea class="widefat" rows="16" cols="20" id="<?php echo esc_attr( $this->get_field_id('address') ); ?>" name="<?php echo esc_attr( $this->get_field_name('address') ); ?>"><?php echo esc_html( $address ); ?></textarea></label>
	<label><?php _e('Phone', 'unitedthemes'); ?>: <input type="text" style="width:100%;" id="<?php echo esc_attr( $this->get_field_id('phone') ); ?>" name="<?php echo esc_attr( $this->get_field_name('phone') ); ?>" value="<?php echo esc_attr( $phone ); ?>" /></label>
    <label><?php _e('Fax', 'unitedthemes'); ?>: <input type="text" style="width:100%;" id="<?php echo esc_attr( $this->get_field_id('fax') ); ?>" name="<?php echo esc_attr( $this->get_field_name('fax') ); ?>" value="<?php echo esc_attr( $fax ); ?>" /></label>
    <label><?php _e('Internet', 'unitedthemes'); ?>: <input type="text" style="width:100%;" id="<?php echo esc_attr( $this->get_field_id('internet') ); ?>" name="<?php echo esc_attr( $this->get_field_name('internet') ); ?>" value="<?php echo esc_attr( $internet ); ?>" /></label>
    <label><?php _e('Email', 'unitedthemes'); ?>: <input type="text" style="width:100%;" id="<?php echo esc_attr( $this->get_field_id('email') ); ?>" name="<?php echo esc_attr( $this->get_field_name('email') ); ?>" value="<?php echo esc_attr( $email ); ?>" /></label>

	
	<?php

    }

    function update($new_instance, $old_instance) {
        return $new_instance;
    }

    function widget( $args, $instance ){

	extract( $args );
	extract( $instance );

	if( $title )
	    $title = $before_title.do_shortcode($title).$after_title;

	$text = ( isset($text) ) ? do_shortcode( $text ) : '';
	$text.= '<ul>';
	
	if(!empty($address)) {
		
        $text.= '<li class="ut-address"><div>';
		$text.= wpautop( $address ).'</div></li>';	
        
	}
	
	if(!empty($phone)) {
		
        $text.= '<li class="ut-phone"><div>';
		$text.= $phone.'</div></li>';	
        
	}
	
	if(!empty($fax)) {
		
        $text.= '<li class="ut-fax"><div>';
		$text.= $fax.'</div></li>';		
        
	}

    if(!empty($internet)) {

        $text.= '<li class="ut-internet"><div><a href="' . esc_url( $internet ) . '">'. $internet .'</a>';
        $text.= $internet.'</div></li>';

    }

	if(!empty($email)) {
		
        $text.= '<li class="ut-email"><div><a href="mailto:' . esc_attr( $email ) . '">'. $email .'</a>';
		$text.= '</div></li>';	
        
	}

	
	
	$text.= '</ul>';

	echo "$before_widget
	    	$title
			$text
		  $after_widget";
    }

}