class_mcQuickform2.inc.php
7.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
/**
* @copyright (c) 2014, netz.coop eG
*/
class mcQuickform2 {
private static $DesignOptions = array(
'size' => 80,
'maxlength' => 255
);
public static function getQuickform( $param_id, $param_method = 'post', $param_url='', $attributes = null, $trackSubmit = true) {
// $form = new HTML_QuickForm2($param_id, $param_method);
if(!$param_url) {
$param_url = 'index.php?action=';
}
$form = new HTML_QuickForm2($param_id, $param_method, $param_url );
return $form;
}
/**
*
* @param HTML_QuickForm2 $param_form
* @param array $param_Values -- array( 'keyname1' => 'value', )
*/
public static function setValues(HTML_QuickForm2 &$param_form, array $param_Values) {
if(!empty($param_Values)) {
$param_form->addDataSource(new HTML_QuickForm2_DataSource_Array($param_Values));
}
}
public static function getHiddenForm(HTML_QuickForm2 &$param_form, $param_keyname, $param_value) {
$el = $param_form->addElement('hidden', $param_keyname)->setValue($param_value);
// anscheinend muss value bei addElement angegeben werden!!
// if(!is_null($param_value)) {
// $el->setValue($param_value);
// }
return $el;
}
public static function getFieldset(HTML_QuickForm2 &$param_form, $param_label) {
return $param_form->addElement('fieldset')->setLabel(mcLanguage::getWord($param_label));
}
public static function getEmailForm(HTML_QuickForm2 &$param_form, $param_keyname, $param_label, $param_value=null, array $param_options=null, array $param_rules=null) {
return self::getTextForm($param_form, $param_keyname, $param_label, $param_value, $param_options, $param_rules);
}
public static function getTextareaForm(HTML_QuickForm2 &$param_form, $param_keyname, $param_label, $param_value=null, array $param_options=null, array $param_rules=null) {
// $t =& $quickform->createElement("textarea", "comment", 'Kommentar',$attrs);
$name = $param_form->addElement('textarea', $param_keyname, $param_label);
// $name->setRows("10");
// $name->setCols("90");
return $name;
}
public static function getTextForm(HTML_QuickForm2 &$param_form, $param_keyname, $param_label, $param_value=null, array $param_options=null, array $param_rules=null) {
if(is_null($param_options)) {
$options = self::$DesignOptions;
} else {
$options = $param_options;
}
$name = $param_form->addElement('text', $param_keyname, $options);
$name->setLabel(mcLanguage::getWord($param_label));
$name->addFilter('trim');
if(!is_null($param_rules)) {
// $param_rules = array('required' => 'Please enter your name')
foreach($param_rules as $rule => $label) {
$name->addRule($rule, $label);
}
}
if(!is_null($param_value)) {
$name->setValue($param_value);
}
return $name;
}
public static function getSelectForm(HTML_QuickForm2 &$param_form, $param_keyname, $param_label, array $param_values) {
$element = $param_form->addElement('select', $param_keyname);
$element->loadOptions($param_values);
$element->setLabel(mcLanguage::getWord($param_label));
return $element;
}
public static function getFileForm(HTML_QuickForm2 &$param_form, $param_keyname='file', $param_label='File') {
$element =& $param_form->addElement('file', $param_keyname, 'Datei:');
$element->setLabel(mcLanguage::getWord($param_label));
$param_form->setMaxFileSize(mcConfig::getConfig('maxfilesize'));
// $param_form->addRule($param_keyname, mcLanguage::getWord('fileToBig'),'maxfilesize', mcConfig::getConfig('maxfilesize'));
// $param_form->addRule($param_keyname, mcLanguage::getWord('onlyFileMime').' ('.$param_mimetype,'mimetype'.')', $param_mimetype);
return $element;
}
/**
*
* @param HTML_QuickForm2 $param_form
* @param type $param_keyname
* @param type $param_label
* @param array $param_options
* @param type $param_value -- '2008-04-12 00:00:00' || time() || array('Y'=>'2004', 'm' => '05', 'd' => '05', 'H' => '03', 'i' => '10', 's' => '20')
* @return type
*/
public static function getDateForm(HTML_QuickForm2 &$param_form, $param_keyname, $param_label, array $param_options=null, $param_value=null) {
// $param_form->addDataSource(new HTML_QuickForm2_DataSource_Array(array(
// 'testDate' => time(),
// )));
if(is_null($param_options)) {
$param_options = array(
'language' => 'de',
'format' => 'Y-m-d H:i:s',
// 'format' => 'dlY H:i:s'
// 'format' => 'd-F-Y',
'minYear' => 2000, // Erstes Jahr
'maxYear' => 2020, // Letztes Jahr
'optionIncrement' => array(
'i' => 5, // Schrittweite Min
's' => 10 // Schrittweite Sek
)
);
}
$element = $param_form->addElement('date', $param_keyname,'title', $param_options);
$element->setLabel(mcLanguage::getWord($param_label));
if($param_value) {
$element->setValue($param_value);
}
return $element;
}
public static function getSubmitForm(HTML_QuickForm2 &$param_form, $param_keyname='submit', $param_label='submit') {
$element = $param_form->addElement('submit', 'submit');
$element->setLabel(mcLanguage::getWord($param_label));
return $element;
}
}
class mcQuickForm extends mcQuickform2 {
private static $quickform = null;
private static $file = null;
public static function start($param_FormName) {
self::$quickform = new HTML_QuickForm2($param_FormName, "post", 'index.php?action=' );
}
public static function file($param_element_name='datei', $param_maxfilesize=null, $param_mimetype=null) {
self::$file = self::$quickform->addElement('file', $param_element_name, mcLanguage::getWord('fileForm'));
// self::$quickform->setMaxFileSize($maxfilesize);
if($param_maxfilesize!=null) {
// Regel zum Pruefen der Dateigroesse
self::$quickform->addRule($param_element_name, mcLanguage::getWord('fileToBig'),'maxfilesize', $param_maxfilesize);
}
if($param_mimetype!=null) {
self::$quickform->addRule($param_element_name, mcLanguage::getWord('onlyFileMime').' ('.$param_mimetype,'mimetype'.')', $param_mimetype);
}
}
public static function procedure() {
// if (self::$quickform->validate()) {
//
//// if (self::$file->isUploadedFile()) {
//
//// self::$file->moveUploadedFile('/tmp');
//
// $fileInfo = self::$file->getValue();
//
// print_r($fileInfo);
//
//// }
//
// } else {
//
// self::$quickform->display();
//
// }
if (false===self::$quickform->validate()) {
self::$quickform->display();
echo self::$quickform;
}
else
{
// D::show(self::$quickform,1,1,1);
// Daten auslesen
$datei = self::$quickform->getElement('datei');
// D::show(self::$quickform,' '.self::$quickform->elementExists('datei'),1,1);
$daten= $datei->getValue();
// Fehler aufgetreten?
if (0!=$datei['error'])
{
echo 'Ein Fehler ist aufgetreten';
}
else
{
// Datei verschieben
if (false === $datei->moveUploadedFile('/daten'))
{
if (false===copy ($daten['tmp_name'], "/daten/$daten[name]")) {
die ('Konnte Datei nicht kopieren ');
}
}
// Informationen zur Datei ausgeben
echo "Name: $daten[name]<br />";
echo "MIME-Type: $daten[type]<br />";
echo "Temporärer Name: $daten[tmp_name]<br />";
echo "Größe: $daten[size]<br />";
}
}
}
public static function end() {
self::$quickform->addElement( 'button', 'SubmitButton', array('type' => 'submit'), array('content' => mcLanguage::getWord('save')) );
}
public static function getForm() {
return self::$quickform;
}
}
//{
//
// $fsText = $quickform->addElement('fieldset')->setLabel(Language::getWord('edit_Zinsbenachrichtigung_Textfeld'));
//
// $defaults = array();
//
// $qf_Subject = $fsText->addElement('textarea', 'edit_Zinsbenachrichtigung_Textfeld', array('style' => self::$Zinsbenachrichtigung_Textfeld_Size ), array('label' => Language::getWord('edit').' '.Language::getWord('Text').':'));
// $defaults['edit_Zinsbenachrichtigung_Textfeld'] = $TextfeldActiveRecord->text;
//
// $quickform->addDataSource(new HTML_QuickForm2_DataSource_Array($defaults));
//
//
//
//
//}
?>