<?php
class bbCMB_list_widget extends WP_Widget {
	function __construct() {
		parent::__construct(false, $name = __('Call Me Back'));
	}
	function form( $instance ) {
		if(isset($instance['cmb_top_header'])) {
			$cmb_top_header  = $instance['cmb_top_header'];
		} else {
			$cmb_top_header  = 'CALL ME BACK !';
		}
		if(isset($instance['cmb_top_text'])) {
			$cmb_top_text  = $instance['cmb_top_text'];
		} else {
			$cmb_top_text  = 'LEAVE YOUR NUMBER, OUR TEAM WILL CONTACT YOU BACK SHORTLY';
		}
		if(isset($instance['cmb_widget_theme'])) {
			$cmb_widget_theme  = $instance['cmb_widget_theme'];
		} else {
			$cmb_widget_theme  = 'white';
		}
		if(isset($instance['cmb_name_activate'])) {
			$cmb_name_activate = $instance['cmb_name_activate'];
		} else {
			$cmb_name_activate = '';
		}
		if(isset($instance['cmb_phone_activate'])) {
			$cmb_phone_activate = $instance['cmb_phone_activate'];
		} else {
			$cmb_phone_activate = '';
		}
		if(isset($instance['cmb_email_activate'])) {
			$cmb_email_activate = $instance['cmb_email_activate'];
		} else {
			$cmb_email_activate = '';
		}
		if(isset($instance['cmb_message_activate'])) {
			$cmb_message_activate = $instance['cmb_message_activate'];
		} else {
			$cmb_message_activate = '';
		}
		if(isset($instance['cmb_fromto_activate'])) {
			$cmb_fromto_activate = $instance['cmb_fromto_activate'];
		} else {
			$cmb_fromto_activate = '';
		}
		if(isset($instance['cmb_fromto_activate'])) {
			$cmb_fromto_activate = $instance['cmb_fromto_activate'];
		} else {
			$cmb_fromto_activate = '';
		}
		if(isset($instance['cmb_name_required'])) {
			$cmb_name_required = $instance['cmb_name_required'];
		} else {
			$cmb_name_required = '';
		}
		if(isset($instance['cmb_phone_required'])) {
			$cmb_phone_required = $instance['cmb_phone_required'];
		} else {
			$cmb_phone_required = '';
		}
		if(isset($instance['cmb_email_required'])) {
			$cmb_email_required = $instance['cmb_email_required'];
		} else {
			$cmb_email_required = '';
		}
		if(isset($instance['cmb_message_required'])) {
			$cmb_message_required = $instance['cmb_message_required'];
		} else {
			$cmb_message_required = '';
		}
		if(isset($instance['cmb_fromto_required'])) {
			$cmb_fromto_required = $instance['cmb_fromto_required'];
		} else {
			$cmb_fromto_required = '';
		}
?>

<p>
<div>
  <label><?php echo __( 'Header Text:', 'bbCMBHeaderText' ); ?></label>
</div>
<div>
  <input class="widefat mmy_widget" name="<?php echo $this->get_field_name( 'cmb_top_header' ); ?>" type="text" value="<?php echo esc_attr( $cmb_top_header ); ?>" />
</div>
</p>
<p>
<div>
  <label><?php echo __( 'Top Text:', 'bbCMBHeaderText' ); ?></label>
</div>
<div>
  <input class="widefat mmy_widget" name="<?php echo $this->get_field_name( 'cmb_top_text' ); ?>" type="text" value="<?php echo esc_attr( $cmb_top_text ); ?>" />
</div>
</p>
<p>
<div>
  <label><?php echo __( 'Widget Box Style:', 'bbCMBHeaderText' ); ?></label>
</div>
<div>
  <select class="widefat" name="<?php echo $this->get_field_name( 'cmb_widget_theme' ); ?>">
    <option value="" <?php if(esc_attr( $cmb_widget_theme ) == ''){echo 'selected';}?>>Default Theme Style</option>
    <option value="A" <?php if(esc_attr( $cmb_widget_theme ) == 'A'){echo 'selected';}?>>Theme A</option>
    <option value="B" <?php if(esc_attr( $cmb_widget_theme ) == 'B'){echo 'selected';}?>>Theme B</option>
    <option value="C" <?php if(esc_attr( $cmb_widget_theme ) == 'C'){echo 'selected';}?>>Theme C</option>
    <option value="D" <?php if(esc_attr( $cmb_widget_theme ) == 'D'){echo 'selected';}?>>Theme D</option>
    <option value="E" <?php if(esc_attr( $cmb_widget_theme ) == 'E'){echo 'selected';}?>>Theme E</option>
    <option value="F" <?php if(esc_attr( $cmb_widget_theme ) == 'F'){echo 'selected';}?>>Theme F</option>
    <option value="G" <?php if(esc_attr( $cmb_widget_theme ) == 'G'){echo 'selected';}?>>Theme G</option>
  </select>
</div>
</p>
<p>
<div style="margin-bottom:5px;"><u><b>Box Option</b></u></div>
<input <?php if($cmb_name_activate == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_name_activate" name="<?php echo $this->get_field_name( 'cmb_name_activate' ); ?>" type="checkbox">
<label for="cmb_name_activate">Enable Name Box</label>
<br/>
<input <?php if($cmb_phone_activate == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_phone_activate" name="<?php echo $this->get_field_name( 'cmb_phone_activate' ); ?>" type="checkbox">
<label for="cmb_phone_activate">Enable Phone Box</label>
<br/>
<input <?php if($cmb_email_activate == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_email_activate" name="<?php echo $this->get_field_name( 'cmb_email_activate' ); ?>" type="checkbox">
<label for="cmb_email_activate">Enable Email Box</label>
<br/>
<input <?php if($cmb_message_activate == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_message_activate" name="<?php echo $this->get_field_name( 'cmb_message_activate' ); ?>" type="checkbox">
<label for="cmb_message_activate">Enable Message Box</label>
<br/>
<input <?php if($cmb_fromto_activate == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_fromto_activate" name="<?php echo $this->get_field_name( 'cmb_fromto_activate' ); ?>" type="checkbox">
<label for="cmb_fromto_activate">Enable From and To Time</label>
</p>
<p>
<div style="margin-bottom:5px;"><u><b>Box Validate Option</b></u></div>
<input <?php if($cmb_name_required == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_name_required" name="<?php echo $this->get_field_name( 'cmb_name_required' ); ?>" type="checkbox">
<label for="cmb_name_required">Name Required ?</label>
<br/>
<input <?php if($cmb_phone_required == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_phone_required" name="<?php echo $this->get_field_name( 'cmb_phone_required' ); ?>" type="checkbox">
<label for="cmb_phone_required">Phone Required?</label>
<br/>
<input <?php if($cmb_email_required == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_email_required" name="<?php echo $this->get_field_name( 'cmb_email_required' ); ?>" type="checkbox">
<label for="cmb_email_required">Email Required?</label>
<br/>
<input <?php if($cmb_message_required == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_message_required" name="<?php echo $this->get_field_name( 'cmb_message_required' ); ?>" type="checkbox">
<label for="cmb_message_required">Message Required?</label>
<br/>
<input <?php if($cmb_fromto_required == 'on') {echo 'checked'; }?> class="checkbox" id="cmb_fromto_required" name="<?php echo $this->get_field_name( 'cmb_fromto_required' ); ?>" type="checkbox">
<label for="cmb_fromto_required">From and To Time Required?</label>
</p>
<?php
	}
	function update( $new_instance, $old_instance ) {
		$instance               				= $old_instance;
		$instance['cmb_top_header']      		= sanitize_text_field( $new_instance['cmb_top_header'] );
		$instance['cmb_top_text'] 				= sanitize_text_field( $new_instance['cmb_top_text'] );
		$instance['cmb_widget_theme'] 			= sanitize_text_field( $new_instance['cmb_widget_theme'] );
		$instance['cmb_name_activate'] 			= sanitize_text_field( $new_instance['cmb_name_activate'] );
		$instance['cmb_phone_activate'] 		= sanitize_text_field( $new_instance['cmb_phone_activate'] );
		$instance['cmb_email_activate']  		= sanitize_text_field( $new_instance['cmb_email_activate'] );
		$instance['cmb_message_activate'] 		= sanitize_text_field( $new_instance['cmb_message_activate'] );
		$instance['cmb_fromto_activate'] 		= sanitize_text_field( $new_instance['cmb_fromto_activate'] );
		$instance['cmb_name_required'] 			= sanitize_text_field( $new_instance['cmb_name_required'] );
		$instance['cmb_phone_required'] 		= sanitize_text_field( $new_instance['cmb_phone_required'] );
		$instance['cmb_email_required'] 		= sanitize_text_field( $new_instance['cmb_email_required'] );
		$instance['cmb_message_required'] 		= sanitize_text_field( $new_instance['cmb_message_required'] );
		$instance['cmb_fromto_required'] 		= sanitize_text_field( $new_instance['cmb_fromto_required'] );
		return $instance;
	}
	function widget( $args, $instance ) {
		$page_url = '';
		$get_options_val = get_option('cmb_setting_options');
		extract( $args );
		$_cmb_name_text = 'Name';
		$_cmb_phone_text = 'Phone';
		$_cmb_email_text = 'Email';
		$_cmb_message_text = 'Message';
		$_cmb_from_text = 'From';
		$_cmb_to_text = 'Top';
	?>
<div class="widget">
  <div class="cmb_w_success_box"><?php echo $get_options_val['cmb_popup_success_text']; ?></div>
  <div class="cmb-container">
    <div class="cmb-header"> <span> <?php echo $instance['cmb_top_header']; ?></span>
      <p><?php echo $instance['cmb_top_text']; ?></p>
    </div>
    <div class="cmb-line"></div>
    <div id="cmb-body">
      <?php if(isset($instance['cmb_name_activate']) && $instance['cmb_name_activate'] == 'on') {?>
	  <div class="cmb-user-info">
        <input id="cmb_w_name" name="cmb_w_name" <?php if(isset($instance['cmb_name_required']) && $instance['cmb_name_required'] == 'on') {echo "data-required='1'";} else {echo "data-required='0'";}?> placeholder="<?php echo $get_options_val['cmb_popup_name_text']; ?>" type="text">
        <div class="cmb-w-errors" id="cmb_w_name_info">
          <div></div>
          <span><?php echo $get_options_val['cmb_popup_name_text']; ?> <?php echo $get_options_val['cmb_popup_required_text']; ?></span> </div>
      </div>
	  <?php } ?>
	  <?php if(isset($instance['cmb_email_activate']) && $instance['cmb_email_activate'] == 'on') {?>
      <div class="cmb-user-info">
        <input id="cmb_w_email" <?php if(isset($instance['cmb_email_required']) && $instance['cmb_email_required'] == 'on') {echo "data-required='1'";} else {echo "data-required='0'";}?> name="cmb_w_email" placeholder="<?php echo $get_options_val['cmb_popup_email_text']; ?>" type="text">
        <div class="cmb-w-errors" id="cmb_w_email_info">
          <div></div>
          <span><?php echo $get_options_val['cmb_popup_email_text']; ?> <?php echo $get_options_val['cmb_popup_required_text']; ?></span> </div>
      </div>
	  <?php } ?>
	  <?php if(isset($instance['cmb_phone_activate']) && $instance['cmb_phone_activate'] == 'on') {?>
      <div class="cmb-user-info">
        <input id="cmb_w_phone" name="cmb_w_phone" <?php if(isset($instance['cmb_phone_required']) && $instance['cmb_phone_required'] == 'on') {echo "data-required='1'";} else {echo "data-required='0'";}?> placeholder="<?php echo $get_options_val['cmb_popup_phone_text']; ?>" type="text">
        <div class="cmb-w-errors" id="cmb_w_phone_info">
          <div></div>
          <span><?php echo $get_options_val['cmb_popup_phone_text']; ?> <?php echo $get_options_val['cmb_popup_required_text']; ?></span> </div>
      </div>
	  <?php } ?>
	  <?php if(isset($instance['cmb_message_activate']) && $instance['cmb_message_activate'] == 'on') {?>
      <div class="cmb-user-info">
        <textarea id="cmb_w_message" name="cmb_w_message" <?php if(isset($instance['cmb_message_required']) && $instance['cmb_message_required'] == 'on') {echo "data-required='1'";} else {echo "data-required='0'";}?> placeholder="<?php echo $get_options_val['cmb_popup_message_text']; ?>"></textarea>
        <div class="cmb-w-errors" id="cmb_w_message_info">
          <div></div>
          <span><?php echo $get_options_val['cmb_popup_message_text']; ?> <?php echo $get_options_val['cmb_popup_required_text']; ?></span> </div>
      </div>
	  <?php } ?>
	  <?php if(isset($instance['cmb_fromto_activate']) && $instance['cmb_fromto_activate'] == 'on') {?>
      <div class="cmb-time clearfix">
        <div class="cmb-from"> <span><?php echo $get_options_val['cmb_popup_from_text']; ?></span> <span>
          <input id="cmb_w_from" name="cmb_w_from" <?php if(isset($instance['cmb_fromto_required']) && $instance['cmb_fromto_required'] == 'on') {echo "data-required='1'";} else {echo "data-required='0'";}?> placeholder="00:00" class="cmbtimepicker" autocomplete="off" type="text">
          </span> </div>
        <div class="cmb-to"> <span><?php echo $get_options_val['cmb_popup_to_text']; ?></span> <span>
          <input id="cmb_w_to" name="cmb_w_to" <?php if(isset($instance['cmb_fromto_required']) && $instance['cmb_fromto_required'] == 'on') {echo "data-required='1'";} else {echo "data-required='0'";}?> placeholder="00:00" class="cmbtimepicker" autocomplete="off" type="text">
          </span> </div>
        <div class="cmb-w-errors cmb_time_req" id="cmb_w_from_info">
          <div></div>
          <span><?php echo $get_options_val['cmb_popup_from_text']; ?> <?php echo $get_options_val['cmb_popup_required_text']; ?></span> </div>
		  
		  <div class="cmb-w-errors cmb_time_req" style="margin-left:125px;" id="cmb_w_to_info">
          <div></div>
          <span><?php echo $get_options_val['cmb_popup_to_text']; ?> <?php echo $get_options_val['cmb_popup_required_text']; ?></span> </div>
      </div>
	  <?php } ?>
	  <div style="clear:both;"></div>
      <div class="cmb_button_area">
	  	<div class="cmb_w_loader"><img src="<?php echo plugins_url();?>/call-me-back/icon/loader.gif" /></div>
        <div><button type="button" onclick="cmbWidgetSubmit();" class="cmbbtn cmb_btn_w_style">Call me</button></div>
      </div>
    </div>
  </div>
</div>
<style type="text/css">
<?php if(isset($instance['cmb_widget_theme']) && $instance['cmb_widget_theme'] == 'B') { ?>
.cmb-header, #cmb-body {
    background: #5cb85c  none repeat scroll 0 0 !important;
    border-color: #3d4041 !important;;
    color: #ffffff !important;;
}
#cmb-body input[type="text"], .cmb-user-info textarea {
	background-color:#ffffff !important;
	color: #000000 !important;
}
.cmb-line{
	background-color: #3d4041 !important;
}
<?php } else if(isset($instance['cmb_widget_theme']) && $instance['cmb_widget_theme'] == 'C') { ?>
.cmb-header, #cmb-body {
    background: #d9534f  none repeat scroll 0 0 !important;
    border-color: #3d4041 !important;;
    color: #ffffff !important;;
}
#cmb-body input[type="text"], .cmb-user-info textarea {
	background-color:#ffffff !important;
	color: #000000 !important;
}
.cmb-line{
	background-color: #ffffff !important;
}
<?php } else if(isset($instance['cmb_widget_theme']) && $instance['cmb_widget_theme'] == 'D') { ?>
.cmb-header, #cmb-body {
    background: #f0ad4e  none repeat scroll 0 0 !important;
    border-color: #3d4041 !important;;
    color: #ffffff !important;;
}
#cmb-body input[type="text"], .cmb-user-info textarea {
	background-color:#ffffff !important;
	color: #000000 !important;
}
.cmb-line{
	background-color: #ffffff !important;
}
<?php } else if(isset($instance['cmb_widget_theme']) && $instance['cmb_widget_theme'] == 'E') { ?>
.cmb-header, #cmb-body {
    background: #337ab7  none repeat scroll 0 0 !important;
    border-color: #3d4041 !important;;
    color: #ffffff !important;;
}
#cmb-body input[type="text"], .cmb-user-info textarea {
	background-color:#ffffff !important;
	color: #000000 !important;
}
.cmb-line{
	background-color: #ffffff !important;
}
<?php } else if(isset($instance['cmb_widget_theme']) && $instance['cmb_widget_theme'] == 'F') { ?>
.cmb-header, #cmb-body {
    background: #5bc0de  none repeat scroll 0 0 !important;
    border-color: #3d4041 !important;;
    color: #ffffff !important;;
}
#cmb-body input[type="text"], .cmb-user-info textarea {
	background-color:#ffffff !important;
	color: #000000 !important;
}
.cmb-line{
	background-color: #ffffff !important;
}
<?php } else if(isset($instance['cmb_widget_theme']) && $instance['cmb_widget_theme'] == 'G') { ?>
.cmb-header, #cmb-body {
    background: #ffffff  none repeat scroll 0 0 !important;
    border-color: #3d4041 !important;
    color: #000000 !important;
}
.cmb-header p {
	color:#000000 !important;
}
#cmb-body input[type="text"], .cmb-user-info textarea {
	background-color:#ffffff !important;
	color: #000000 !important;
}
.cmb-line{
	background-color: #ffffff !important;
}
<?php } ?>
</style>
<input type="hidden" id="cmb_ajax_post_w_url" value="<?php echo admin_url( 'admin-ajax.php' ); ?>" />
<?php } } ?>
