<? global $vis_language; ?>

<section class="padder">
   <section class="panel-default">
      <div class="panel-body">
         <form id="vis_smtp_form" name="vis_smtp_form" method="post" class="form-horizontal">
         <div class="form-group">
         <div class="col-sm-10">
                  <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio" name="vis_checktype" id="vis_checktype1" value="0" onclick="showsmtp();" checked="checked"/><i></i>
                  PHP mail</label> </div>
                  <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio" name="vis_checktype" id="vis_checktype2" onclick="showsmtp();" value="1" /><i></i>
                  SMTP mail
                  </label> 
                  </div>
                  
         </div>
         <div id="divphpmail">
         <div class="col-sm-12">
           <div class="notes" style="padding-top:5px;"><p>This system uses php mail function to send outgoing emails, if you wish to set smtp please add your smtp login details.</p></div>
           </div>
           </div>
         </div>
         <div id="divsmtp" style="display:none;">
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTHOSTNAME']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text"  name="vis_host" id="vis_host" >
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTPORT']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_port" id="vis_port" >
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTUSERNAME']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="text" name="vis_username" id="vis_username" >
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTPASSWORD']; ?></label>
               <div class="col-sm-10">
                  <input class="form-control input-sm" type="password" name="vis_password" id="vis_password"  >
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTSSL']; ?></label>
               <div class="col-sm-10">
                  <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio" name="vis_ssl" id="vis_ssl1" value="0" checked="checked"/><i></i>
                  <? echo $vis_language['TXTNONE']; ?></label> </div>
                  <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio" name="vis_ssl" id="vis_ssl2" value="1" /><i></i>
                  SSL
                  </label> </div>
                  <div class="radio i-checks m-r-lg pull-left"><label>
                  <input type="radio" name="vis_ssl" id="vis_ssl3" value="2"/><i></i>
                  TLS
                  </label> </div>
               </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label"><? echo $vis_language['TXTSMTPAUTHENTICATION']; ?></label>
               <div class="col-sm-10">
				   <div class="checkbox i-checks m-r-lg pull-left">
                  <label>
                  <input type="checkbox" name="vis_smtp_auth" id="vis_smtp_auth" value="1"/><i></i></label></div>
               </div>
            </div>
             <div class="line b-b line-lg pull-in"></div>
             <br />
             <div class="form-group">
                     <div class="col-sm-12 text-left">
                     <?=$operation['view_note']?>
                     </div>
                     </div>  
            </div>
            <div class="line b-b line-lg pull-in"></div>
            <br />
             
            <div class="form-group">
            <div class="col-sm-10 text-right">
            </div>
               <div class="col-sm-2 text-right">
                  <button type="button" class="btn btn-primary" onclick="return checksmtpdata();">Done</button>
                  <div id="loading"></div>
               </div>
            </div>
     
      </form>
      </div>
   </section>
</section>
<script>
   $(".selectpicker").selectpicker();
      
   function showsmtp()
   {
	   var checktype=$("input[name='vis_checktype']:checked").val();
	   if(checktype==1)
	   {
		   $('#divphpmail').hide();
		   $('#divsmtp').show();
	   }else{
		   $('#divsmtp').hide();
		   $('#divphpmail').show();
	   }
	   
   }
   
function checksmtpdata()
{ 
 $("#loading").show();
 var checktype=$("input[name='vis_checktype']:checked").val();
 if(checktype==1)
 {
	$.ajax({
            url: 'index.php',
            type: "POST",
           data: { 'vis_action': $("#vis_smtp_form").serialize(), 'vis_module': 'setting', 'vis_operation': 'add_smtp_popup', 'vis_form': 'vis_smtp_form' },
           success: function(data) {
				 if(data!='')
				 {
				  if(data==1)
					{
						$("#loading").hide();
						//$("#vis_global_msg_div").visInterface("load_global_message", '<div class="alert-success">Operation completed successfully</div>');
						vis_update_first_loginclose();
						loadtips();
	 					$('#ajaxModal').modal('toggle');
						//$("#vis_details_list").visExecution("load_operations",{"vis_module":"setting", "vis_operation":"popup_info"});
						//set_active_tab('info');
					}else{
						$("#vis_global_msg_div").visInterface("load_global_message", data);
						$("#loading").hide();
					}
				 }else{
					 $("#vis_global_msg_div").visInterface("load_global_message", 'Authentication or connection error');
					 $("#loading").hide();
				 }
              }
           
        });
		
 }else{
	 vis_update_first_loginclose();
	 loadtips();
	 $('#ajaxModal').modal('toggle');
	// $("#vis_details_list").visExecution("load_operations",{"vis_module":"setting", "vis_operation":"popup_info"});
	//set_active_tab('info');
 }
		
}

function vis_update_first_loginclose(){
	var data = {'vis_firstlogin':'0' };
    $.ajax({
		url: 'index.php?vis_module=home&vis_operation=update_firsttime_status',
		data: data,
		type: "POST",
		dataType: "json",
		success: function(data) {
			//$('#ajaxModal').modal('toggle');
		},
		error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
	});
}



</script>
