
<div class="breadcrumb">
    <h1>Xcare Default Goto Set up </h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
    </ul>
</div>
<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo (isset($successMsg) && $successMsg!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($successMsg)."</div>" : '' ; ?>
    <?php echo (isset($failedMsg) && $failedMsg!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($failedMsg)."</div>" : '' ?>
   
    <div id="status_msg" style="display: none;"><div class="alert alert-success"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>
    <div id="alert_msg" style="display: none;"><div class="alert alert-danger"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>

    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <div class="card-title mb-3">GoTo API Setting</div>
                <form action="" id='frm-gotosetting' method="post" enctype="multipart/form-data">
                    
                    <div class="row">
                        <div class="col-md-6 form-group mb-3">
                            <label for="goto_clientId">Client ID <span class="asterisk">*</span></label>
                            <?php $goToSetting = $xcaredefultDetail;?>
                            <input type="text" name="goto_clientId" class="form-control" id="goto_clientId" value="<?php echo (isset($goToSetting) && isset($goToSetting['clientid'])) ? $goToSetting['clientid'] : ""; ?>">
                            <div class="invalid-tooltip" id="msg_goto_clientId"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            
                        </div>
                        
                        <div class="col-md-6 form-group mb-3">
                            <label for="goto_client_secret">Client Secret<span class="asterisk">*</span></label>
                            <input type="text" name="goto_client_secret" class="form-control" id="goto_client_secret" value="<?php echo (isset($goToSetting) && isset($goToSetting['clientsecret'])) ? $goToSetting['clientsecret'] : ""; ?>">
                            <div class="invalid-tooltip" id="msg_goto_client_secret"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            <label for="goto_code">Code </label>
                            <!-- <span class="asterisk">*</span> -->
                            <textarea id="goto_code" name="goto_code" class="form-control" rows="7" cols="50"></textarea>
                            <div class="invalid-tooltip" id="msg_goto_code"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3">
                            
                        </div>
                        <div class="col-md-6">
                            <input type="submit"  class="btn btn-primary" id="get_code" name="get_code" value="Get Code">
                            &emsp;&emsp;
                            <input type="submit" class="btn btn-primary" id="get_token" name="get_token" value="Get Token">

                            <!-- <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Get Token"> -->
                        </div>

                        <!-- <div class="col-md-6">
                            <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Get Token">
                        </div> -->
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
   $("#frm-gotosetting" ).on( "submit", function(e) {
      e.preventDefault();
      
      var btn= $(this).find("input[type=submit]:focus").val();
      if(btn == 'Get Code'){
        var goto_clientId = $("#goto_clientId").val();
        var goto_client_secret = $("#goto_client_secret").val();

          if($("#goto_clientId").val()==''){
              $("#goto_clientId").addClass('error');
              $("#goto_clientId").focus();
              $("#msg_goto_clientId").html('Please input clientId').show();
              return false;
          }else if($("#goto_client_secret").val()==''){
              if(goto_clientId !=''){
                  $("#goto_clientId").removeClass('error');
                  $("#msg_goto_clientId").hide();
              }
              $("#goto_client_secret").addClass('error');
              $("#goto_client_secret").focus();
              $("#msg_goto_client_secret").html('Please input client secret').show();
              return false;
          }else{
              if(goto_client_secret !=''){
                  $("#goto_client_secret").removeClass('error');
                  $("#msg_goto_client_secret").hide();
              }

              $(".loader-bubble").show();
              $.ajax({      
                  url: "xcare_goto_setup.php",
                  data: 
                  { 
                      act:"getcode",
                      goto_clientId:goto_clientId,goto_client_secret:goto_client_secret,
                  },
                  method: 'POST',
                  success: function(data){
                      $(".loader-bubble").hide();
                      $("#alert_msg").hide();
                      $("#alert_msg").html(data);
                  }
              });
          } 
      }

      if(btn == 'Get Token'){
         var goto_clientId = $("#goto_clientId").val();
         var goto_client_secret = $("#goto_client_secret").val();
         var goto_code = $("#goto_code").val();

           if($("#goto_clientId").val()==''){
              $("#goto_clientId").addClass('error');
              $("#goto_clientId").focus();
              $("#msg_goto_clientId").html('Please input clientId').show();
              return false;
           }else if($("#goto_client_secret").val()==''){
              if(goto_clientId !=''){
                  $("#goto_clientId").removeClass('error');
                  $("#msg_goto_clientId").hide();
              }

              $("#goto_client_secret").addClass('error');
              $("#goto_client_secret").focus();
              $("#msg_goto_client_secret").html('Please input client secret').show();
              return false;
           }else if($("#goto_code").val()==''){
              if(goto_client_secret !=''){
                  $("#goto_client_secret").removeClass('error');
                  $("#msg_goto_client_secret").hide();
              }

              $("#goto_goto_code").addClass('error');
              $("#goto_goto_code").focus();
              $("#msg_goto_code").html('Please input code').show();
              return false;
           }else{
              if(goto_code !=''){
                  $("#goto_goto_code").removeClass('error');
                  $("#msg_goto_code").hide();
              }

              $(".loader-bubble").show();
              $.ajax({      
                  url: "xcare_goto_setup.php",
                  data:{ 
                      act:"addcodetoken",
                      goto_clientId:goto_clientId,goto_client_secret:goto_client_secret,goto_code:goto_code,
                  },
                  method: 'POST',
                  success: function(msg){

                        if(msg=='success'){
                            $(".loader-bubble").hide();
                            $.toast({
                                heading: '</em>',
                                text: 'GoToSetting updated successfully...',
                                position: 'top-right',
                                stack: false,
                                showHideTransition: 'slide',
                                icon: 'success'
                            });
                            $("#goto_code").val('');
                            $("#goto_clientId").val('');
                            $("#goto_client_secret").val('');
                           
                        }else{
                            $(".loader-bubble").hide();
                            $.toast({
                                //heading: 'Positioning',
                                heading: '</em>',
                                text: msg,
                                position: 'top-right',
                                stack: false,
                                showHideTransition: 'slide',
                                icon: 'error'
                            });

                        }
                  }
              });
           }
        }
    });
</script>