<?php declare(strict_types=1);

// needs globals $qrbApi, $qrbCfg

// included by index.php for each input file

// Creates an upload form.
// Variables:
//   inputDataType: QrbDataType
//   language:      one of "de", "fr", "it", "en" or "" (no or default language)
//   titleText:     text key, translated text is shown before file upload control
//   showDefLang:   optional flag: if present and true and multi-language 
//                  then the default langauge is displayed after the title
//   infoText:      optional info text key; if present 
//                  then an info icon is shown with the translated text
//   submitText:    text key, translated text is shown on the submit button
//   inputFileKey:  rendered into "name" attribute of the submit button
//                  one of the XXX_KEY constants in QrBillsUpload.php

?>
  <form action="#upload-result" method="post" enctype="multipart/form-data">
    <div class="row g-1 uploadFile">
      <div class="col-auto uploadFileItem uploadFileTitle">
        <span>
<?php
// check if input file exists ...
$inputDataExists = $qrbApi->checkInputDataExists($inputDataType, $language);

if ($inputDataExists != NULL) {
    // ... and if so, build a link to it
    print '<a href="' . $inputDataExists . '">';
}

print $qrbApi->xl($titleText);

if ($inputDataExists != NULL) {
    // ... and close the link
    print '</a>';
}

if (isset($showDefLang) && ($showDefLang === true) && $qrbCfg->getMultiLanguage())  {
    // append default language in brackets
    print ' (' . $qrbCfg->getDefaultLanguage() . ')';
}

if (isset($infoText)) {
    // optional info text exists: build the info popover with the info text
?>
          <span class="iconPopover">
            <a  class="btn btn-dark" 
                tabindex="0" 
                role="button" 
                data-bs-html="true" 
                data-bs-toggle="popover" 
                data-bs-trigger="focus" 
                data-bs-title="
<?php
    print $qrbApi->xl($titleText); 
?>
                "
                data-bs-content="
<?php
    print $qrbApi->xl($infoText); 
?>
                "
            >
              i
            </a>
          </span>
<?php
} // if (isset($infoText))
?>
        </span>
      </div>
      <div class="col-auto uploadFileItem">
<?php
print '<input type="file" class="form-control" name="' . $inputFileKey . '" />';
?>
      </div>
      <div class="col-auto uploadFileItem uploadFileSubmit">
        <button type="submit" 
                name="submit" 
                class="btn btn-dark">
<?php
print $qrbApi->xl($submitText); 
?>
        </button>
      </div>
    </div>
  </form>

<?php
// unset all variables
unset($inputDataType);
unset($language);
unset($titleText);
unset($showDefLang);
unset($infoText);
unset($submitText);
unset($inputFileKey);
?>
