function widget($args, $instance)
 {
     extract($args);
     echo $before_widget;
     //retrieve all options stored in DB
     $options = bos_searchbox_retrieve_all_user_options();
     if (empty($options)) {
         $options = bos_searchbox_retrieve_all_options();
     }
     // if no user customization, then use the defaults value
     $preview = false;
     //This is the front-end searchbox
     bos_create_searchbox($options, $preview);
     echo $after_widget;
 }
function bos_searchbox_settings_field($args)
{
    // get options value from the database
    $options = bos_searchbox_retrieve_all_user_options();
    if (empty($options)) {
        $options = bos_searchbox_retrieve_all_options();
    }
    // if no user customization, then use the defaults value
    $fields_array = $args[0];
    if (!empty($options[$fields_array])) {
        $fields_value = $options[$fields_array];
    } else {
        $fields_value = '';
    }
    $output = '';
    // echo the fields
    if ($args[1] == 'text') {
        $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" id="' . $args[0] . '" type="' . $args[1] . '" ';
        if (!empty($args[3])) {
            $output .= ' maxlength="' . $args[3] . '" ';
        }
        if (!empty($args[4])) {
            $output .= ' size="' . $args[4] . '" ';
        }
        // If default plugin values empty show default values  ( but for aid as we do not want the default aid is shown on the input field )
        if ($args[0] == 'aid' && ($fields_value == BOS_DEFAULT_AID || empty($fields_value) || $fields_value == '' || $fields_value == ' ' || !is_numeric($fields_value))) {
            $fields_value = '';
            $aid_placeholder = 'placeholder="Ex. ' . BOS_DEFAULT_AID . ' "';
        } else {
            $aid_placeholder = '';
        }
        if ($args[0] == 'maintitle' && ($fields_value == '' || empty($fields_value))) {
            $fields_value = __('Need a hotel?', BOS_TEXT_DOMAIN);
        }
        if ($args[0] == 'checkin' && ($fields_value == '' || empty($fields_value))) {
            $fields_value = __('Check-in date', BOS_TEXT_DOMAIN);
        }
        if ($args[0] == 'checkout' && ($fields_value == '' || empty($fields_value))) {
            $fields_value = __('Check-out date', BOS_TEXT_DOMAIN);
        }
        if ($args[0] == 'submit' && ($fields_value == '' || empty($fields_value))) {
            $fields_value = __('search', BOS_TEXT_DOMAIN);
        }
        $output .= 'value="' . $fields_value . '" ' . $aid_placeholder . ' />&nbsp;' . __($args[2], BOS_TEXT_DOMAIN);
    } elseif ($args[1] == 'checkbox') {
        if ($args[0] == 'calendar' || $args[0] == 'flexible_dates') {
            $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" id="' . $args[0] . '" type="' . $args[1] . '"  value="1" ' . checked(1, $fields_value, false) . ' />';
        }
        // $args[ 0 ] == 'calendar' ||  $args[ 0 ] == 'flexible_dates'
    } elseif ($args[1] == 'radio') {
        if ($args[0] == 'month_format') {
            //if( empty( $fields_value ) ) { $fields_value = 'short' ; }// set defaults value
            $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" class="' . $args[0] . '" type="' . $args[1] . '"  value="long" ' . checked('long', $fields_value, false) . ' />&nbsp;' . __('long', BOS_TEXT_DOMAIN);
            $output .= '&nbsp;<input name="bos_searchbox_user_options[' . $fields_array . ']" class="' . $args[0] . '" type="' . $args[1] . '"  value="short" ' . checked('short', $fields_value, false) . ' />&nbsp;' . __('short', BOS_TEXT_DOMAIN);
        }
        // $args[ 0 ] == 'month_format'
        if ($args[0] == 'logodim') {
            //if( empty( $fields_value ) ) { $fields_value = 'blue_150x25' ; }// set defaults value
            $bgcolor = $options['bgcolor'] ? $options['bgcolor'] : '#FEBA02';
            $output .= '<span id="bos_img_blue_logo" class="bos_logo_dim_box" style="background: ' . $bgcolor . ';"><img  src="' . BOS_IMG_PLUGIN_DIR . '/booking_logotype_blue_150x25.png" alt="Booking.com logo" /></span>';
            $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" class="' . $args[0] . '" type="' . $args[1] . '"  value="blue_150x25"  ' . checked('blue_150x25', $fields_value, false) . ' />&nbsp;( 150x25 )&nbsp;';
            $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" class="' . $args[0] . '" type="' . $args[1] . '"  value="blue_200x33"  ' . checked('blue_200x33', $fields_value, false) . ' />&nbsp;( 200x33 )&nbsp;';
            $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" class="' . $args[0] . '" type="' . $args[1] . '"  value="blue_300x50" ' . checked('blue_300x50', $fields_value, false) . ' />&nbsp;( 300x50 )&nbsp;';
            $output .= '<br /><br />';
            $output .= '<span id="bos_img_white_logo" class="bos_logo_dim_box" style="background: ' . $bgcolor . ';"><img src="' . BOS_IMG_PLUGIN_DIR . '/booking_logotype_white_150x25.png" alt="Booking.com logo" /></span>';
            $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" class="' . $args[0] . '" type="' . $args[1] . '"  value="white_150x25" ' . checked('white_150x25', $fields_value, false) . ' />&nbsp;( 150x25 )&nbsp;';
            $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" class="' . $args[0] . '" type="' . $args[1] . '"  value="white_200x33" ' . checked('white_200x33', $fields_value, false) . ' />&nbsp;( 200x33 )&nbsp;';
            $output .= '<input name="bos_searchbox_user_options[' . $fields_array . ']" class="' . $args[0] . '" type="' . $args[1] . '"  value="white_300x50" ' . checked('white_300x50', $fields_value, false) . ' />&nbsp;( 300x50 )&nbsp;';
        }
        // $args[ 0 ] == 'logodim'
    } elseif ($args[1] == 'select') {
        $output .= '<select name="bos_searchbox_user_options[' . $fields_array . ']" id="' . $args[0] . '" >';
        $output .= '<option value="left" ' . selected('left', $fields_value, false) . ' >' . __('left', BOS_TEXT_DOMAIN) . '</option>';
        $output .= '<option value="center" ' . selected('center', $fields_value, false) . ' >' . __('center', BOS_TEXT_DOMAIN) . '</option>';
        $output .= '<option value="right" ' . selected('right', $fields_value, false) . ' >' . __('right', BOS_TEXT_DOMAIN) . '</option>';
        $output .= '</select>';
    }
    // $args[ 0 ] == 'logopos'
    echo $output;
}