|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SKien\Formgenerator; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Element to select file(s) for upload supporting drag'n drop. |
|
9
|
|
|
* |
|
10
|
|
|
* @package Formgenerator |
|
11
|
|
|
* @author Stefanius <[email protected]> |
|
12
|
|
|
* @copyright MIT License - see the LICENSE file for details |
|
13
|
|
|
*/ |
|
14
|
|
|
class FormDropFile extends FormInput |
|
15
|
|
|
{ |
|
16
|
|
|
protected string $strSelectTxt = 'Datei auswählen...'; |
|
17
|
|
|
protected string $strDropTxt = 'oder hierher ziehen.'; |
|
18
|
|
|
protected bool $bMultiSelect = false; |
|
19
|
|
|
protected int $iRows = -1; |
|
20
|
|
|
protected int $iCols = -1; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Create a element to upload file(s) supporting drag'n drop. |
|
24
|
|
|
* @param string $strName |
|
25
|
|
|
* @param int $iCols |
|
26
|
|
|
* @param int $iRows |
|
27
|
|
|
* @param string $strWidth |
|
28
|
|
|
* @param int $wFlags |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(string $strName, int $iCols = 2, int $iRows = -1, string $strWidth = '95%', int $wFlags = 0) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->iCols = $iCols; |
|
33
|
|
|
$this->iRows = $iRows; |
|
34
|
|
|
parent::__construct($strName, $strWidth, $wFlags); |
|
35
|
|
|
|
|
36
|
|
|
$this->bMultiSelect = $this->oFlags->isSet(FormFlags::MULTI_SELECT); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritDoc} |
|
41
|
|
|
* @see \SKien\Formgenerator\FormElement::fromXML() |
|
42
|
|
|
* @internal |
|
43
|
|
|
*/ |
|
44
|
|
|
static public function fromXML(\DOMElement $oXMLElement, FormCollection $oFormParent) : ?FormElement |
|
45
|
|
|
{ |
|
46
|
|
|
$strText = self::getAttribString($oXMLElement, 'text'); |
|
47
|
|
|
$wFlags = self::getAttribFlags($oXMLElement); |
|
48
|
|
|
$strLabelFor = self::getAttribString($oXMLElement, 'for'); |
|
49
|
|
|
$oFormElement = new self($strText, $wFlags, $strLabelFor); |
|
|
|
|
|
|
50
|
|
|
$oFormParent->add($oFormElement); |
|
51
|
|
|
$oFormElement->readAdditionalXML($oXMLElement); |
|
52
|
|
|
return $oFormElement; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Build the HTML-notation for the static text |
|
57
|
|
|
* @return string |
|
58
|
|
|
* @internal |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getHTML() : string |
|
61
|
|
|
{ |
|
62
|
|
|
$this->processFlags(); |
|
63
|
|
|
$this->setSize(); |
|
64
|
|
|
$strHTML = $this->buildContainerDiv(); |
|
65
|
|
|
|
|
66
|
|
|
$strStyle = ''; |
|
67
|
|
|
if ($this->iRows > 0) { |
|
68
|
|
|
$strStyle = 'style="height: ' . (30 + $this->iRows * 26) . 'px"'; |
|
69
|
|
|
} |
|
70
|
|
|
$strHTML .= ' <div class="dropfile" ' . $strStyle . '>' . PHP_EOL; |
|
71
|
|
|
$strHTML .= ' <label>' . PHP_EOL; |
|
72
|
|
|
$strHTML .= ' <span class="fileselect">Dateien auswählen</span>' . PHP_EOL; |
|
73
|
|
|
$strHTML .= ' <span class="droptext">oder hierher ziehen.</span>' . PHP_EOL; |
|
74
|
|
|
$strHTML .= ' <input type="file" name="files[]" multiple />' . PHP_EOL; |
|
75
|
|
|
$strHTML .= ' </label>' . PHP_EOL; |
|
76
|
|
|
$strHTML .= ' <div class="selectedfiles"></div>' . PHP_EOL; |
|
77
|
|
|
$strHTML .= ' </div>' . PHP_EOL; |
|
78
|
|
|
|
|
79
|
|
|
$strHTML .= '</div>' . PHP_EOL; |
|
80
|
|
|
|
|
81
|
|
|
return $strHTML; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|