<?php
/* $Id$ */

if(isset($this->ERROR) && count($this->ERROR) > 0) {
    foreach($this->ERROR as $err)
        echo '<h2 class="error">'.$err.'</h2>';
}

?>
<script type="text/javascript">
<!--
	var counter = 1;
	
	var msgError = "<?php echo $this->t("error"); ?>";
	var msgChooseFile = "<?php echo $this->t("upload_choose_file"); ?>";
	var msgChooseName = "<?php echo $this->t("upload_choose_name"); ?>";
	var msgNamingFilename = "<?php echo $this->t("naming_filename"); ?>";
	var msgNamingCounter = "<?php echo $this->t("naming_count"); ?>";
	
    function checkFormular()
    {
		/*
		// TODO removed cause of server side validation and no valid framework
        if (document.getElementById("userfile").value == '') {
            showJSError(msgError, msgChooseFile);
            return false;
        }
        if (document.getElementById("name").value == '') {
            showJSError(msgError, msgChooseName);
            return false;
        }
		*/
        return true;
    }

	function addUploadBox()
	{
		boexli = document.getElementById("uploadFileBox");
		var neueBR = document.createElement("br");
		var neueBoexli = document.createElement("input");
		var neueBoexliType = document.createAttribute("type");
		neueBoexliType.nodeValue = "file";
		neueBoexli.setAttributeNode(neueBoexliType);
		var neueBoexliName = document.createAttribute("name");
		neueBoexliName.nodeValue = "userfile[]";
		neueBoexli.setAttributeNode(neueBoexliName);
		boexli.insertBefore(neueBR,document.getElementById('endSpacer'));
		boexli.insertBefore(neueBoexli,document.getElementById('endSpacer'));
		counter++;
		if(counter == 2) {
			boexli2 = document.getElementById("namingMethod");
			boexli2.innerHTML = '<input type="radio" name="namingType" value="namingFile" checked="checked" id="namingFile"> <label for="namingFile">' + msgNamingFilename + '</label>';
			boexli2.innerHTML += '<br><input type="radio" name="namingType" value="namingCount" id="namingCount"> <label for="namingCount">' + msgNamingCounter + '</label>';
		}
	}
// -->
</script>

<form name="uploadForm" id="uploadForm" action="<?php echo $this->ACTION_LINK; ?>" method="post" ENCTYPE="multipart/form-data" onSubmit="return checkFormular();">
  <table cellspacing="0" class="tablesorter">
    <thead>
    	<tr>
    		<th colspan="2"><?php echo $this->t("upload_title"); ?></th>
    	</tr>
    </thead>
    <tbody>  
      <tr class="row1">
        <td align="left"><?php echo $this->t("choose_file"); ?><br/>
                    (max. <?php echo ini_get('upload_max_filesize'); ?> / File)</td>
        <td align="left" id="uploadFileBox">
			<input type="file" name="userfile[]" />
			<span id="endSpacer"></span>
			<br /><a href="#" onClick="addUploadBox();return false;">[+] <?php echo $this->t("choose_more_files"); ?></a>
		</td>
      </tr>
      <tr class="row2">
        <td align="left"><?php echo $this->t("name"); ?></td>
        <td align="left">
			<input type="text" name="data[name]" id="name" maxlength="200" size="35" value="<?php echo $this->DATA_NAME; ?>">
			<div id="namingMethod"></div>
		</td>
      </tr>
      <tr class="row1">
			<td align="left" valign="top"><?php echo $this->t("unique_name"); ?></td>
			<td align="left">
				<input type="text" name="data[unique_name]" id="unique_name" maxlength="200" size="35" value="<?php echo $this->UNIQUE_NAME; ?>">
				<div><?php echo $this->t("replacer"); ?>: {NAME}, {FILENAME}, {COUNTER}</div>
			</td>
      </tr>
      <tr class="row2">
        <td align="left" valign="top"><?php echo $this->t("description"); ?></td>
        <td align="left"><textarea name="data[description]" id="description" rows="5" cols="40" wrap=""><?php echo $this->DATA_DESCRIPTION; ?></textarea></td>
      </tr>
      <tr class="row1">
        <td align="left"><?php echo $this->t("language"); ?></td>
        <td align="left">
            <select name="data[langid]" id="langid">
			    <?php foreach($this->LANGUAGES as $langName => $langID) : ?>
                <option value="<?php echo $langID; ?>"<?php if($this->LANGUAGE_SELECTED == $langID) { ?> selected<?php } ?>><?php echo $langName; ?></option>
                <?php endforeach; ?>
            </select>
        </td>
      </tr>
      <tr class="row2">
        <td align="left" valign="top"><?php echo $this->t("category"); ?></td>
        <td align="left"><?php echo $this->CATEGORY_SELECTOR; ?></td>
      </tr>
    </tbody>
  </table>
    <button type="submit"><?php echo $this->t("process_upload"); ?></button>
</form>
