21 return str_replace(
"{name}",$name,$this->err_msg);
29 public function test($str){
30 if( ($this->exp ==
"") OR ($str ==
"") ){
33 $r = preg_match_all($this->exp,$str);
34 if( (
$r === 0) OR (
$r ===
false) ){
56 $exp->desc_tiny =
"0-9";
57 $exp->desc_short =
"Nur zahlen";
58 $exp->desc_long =
"Nur Ganzzahlen (0-9) erlaubt.";
59 $exp->err_msg =
"Die Frage <b>{name}</b> muss mit einer Ganzzahl beantwortet werden.";
61 $exp->exp =
"/^\d*$/";
62 $this->
regexp[ $exp->exp ] = $exp;
65 $exp2->desc_tiny =
"-12,3";
66 $exp2->desc_short =
"Zahlen mit - und ,";
67 $exp2->desc_long =
"Nur Zahlen erlaubt, optional: komma und -";
68 $exp2->err_msg =
"Die Frage <b>{name}</b> muss mit einer einer Zahl beantwortet werden. (erlaubte Zeichen sind 0-9 - ,) z.B: -123,45";
69 $exp2->name =
"float";
70 $exp2->exp =
"/^-{0,1}\d*(:?,{0,1}\d)$/";
71 $this->
regexp[ $exp2->exp ] = $exp2;
74 $exp3->desc_tiny =
"1-F";
75 $exp3->desc_short =
"Hexadezimalzahlen (0-F)";
76 $exp3->desc_long =
"Nur Hexadecimalzahlen erlaubt:0-F";
77 $exp3->err_msg =
"Die Frage <b>{name}</b> muss mit einer einer Hexadezimalzahl beantwortet werden. (erlaubte Zeichen sind 0-f, 0-F) z.B: 4B0000";
79 $exp3->exp =
"/^[[:xdigit:]]*$/";
80 $this->
regexp[ $exp3->exp ] = $exp3;
89 if(
$name ==
"regexp" ){
93 if( isset($this->
config[
"regexp"]) ){
94 unset($this->
config[
"regexp"]);
105 if(
$name ==
"regexp" ){
106 if( (isset($this->
config[
"regexp"])) AND ($this->
config[
"regexp"] !=
"") ){
108 return $this->
regexp[ $this->config[
"regexp"] ];
122 echo
"<select name='widget_regexp'>";
123 echo
"<option value=''>Keine festlegung</option>";
124 foreach( $this->
regexp as $reg){
125 if( (isset($conf)) AND ($conf->exp == $reg->exp) ){
126 echo
"<option value='{$reg->name}' selected='selected'> {$reg->desc_short} </option>";
128 echo
"<option value='{$reg->name}'> {$reg->desc_short} </option>";
135 if( (isset($_POST[
"widget_regexp"])) AND ($_POST[
"widget_regexp"] !=
"") ){
136 foreach( $this->
regexp as $exp ){
137 if( $exp->name === $_POST[
"widget_regexp"] ){
149 if($this->is_required){
150 $req =
"<span class='required_asterisk'>*</span>";
154 if( $font_bold ==
true){ $font_bold =
"font-weight:bold"; }
else{ $font_bold=
""; }
159 $regexp =
"<span style='color:#4B0000;font-size:80%;'>(".$reg->desc_long.
")</span>";
163 echo
"<label for='{$this->name}' style='$font_bold' >{$this->dispName} $req</label> <br/>";
164 echo
"<span class='widget_indent'></span><input type='text' name='{$this->name}' id='{$this->name}' style='margin-top:4px;width:15em'/> $regexp <br/>";
165 echo
"</div>".PHP_EOL;
170 if( (isset($this->
name)) ){
171 if( isset($this->dispName) ){
174 $value = htmlspecialchars($this->
value,ENT_QUOTES,
"UTF-8",
true);
175 $font_family= $this->
get_config(
"font-family");
179 if( $font_family !=
""){ $font_family =
"font-family:".$font_family; }
180 if( $font_size !=
""){ $font_size =
"font-size:".$font_size; }
181 if( $font_bold ==
true){ $font_bold =
"font-weight:bold"; }
else{ $font_bold=
""; }
186 $regexp =
"<span style='color:#4B0000;font-size:80%;'>(".$reg->desc_long.
")</span>";
189 if($this->is_required){
190 $req =
"<span class='required_asterisk'>*</span>";
192 echo
"<div class='widget_container text_widget' style='$font_family;$font_size'>";
193 echo
"<label for='{$this->name}' style='$font_bold' class='widget_question'>$n $req</label> <br/>";
194 echo
"<span class='widget_indent'></span><input type='text' name='{$this->name}' id='{$this->name}' value='{$value}' style='margin-top:4px;width:15em' /> $regexp <br/>";
195 echo
"</div>".PHP_EOL;
197 throw new Exception(
"Widget name or default value not set");
202 if( isset($this->dispName) ){
206 $value = htmlspecialchars($this->
value,ENT_QUOTES,
"UTF-8",
true);
207 $font_family= $this->
get_config(
"font-family");
211 $margin_left= $this->
get_config(
"margin-left");
212 $margin_right= $this->
get_config(
"margin-right");
214 if( $font_family !=
""){ $font_family =
"font-family:".$font_family; }
215 if( $font_size !=
""){ $font_size =
"font-size:".$font_size; }
216 if( $font_bold ==
true){ $font_bold =
"font-weight:bold"; }
else{ $font_bold=
""; }
217 if( $width != -1){ $width =
"width:{$width}em"; }
else{ $width=
""; }
218 if( $margin_left != 0){ $margin_left =
"margin-left:{$margin_left}em"; }
else{ $margin_left=
""; }
219 if( $margin_right != 0){ $margin_right =
"margin-right:{$margin_right}em"; }
else{ $margin_right=
""; }
221 if($this->is_required){
222 $req =
"<span class='required_asterisk'>*</span>";
224 echo
"<div class='widget_container text_child_widget' style='$font_family;$font_size'>";
226 echo
"<input type='text' name='{$this->name}' id='{$this->name}' value='{$value}' style='margin-top:4px;$width;$margin_left;$margin_right't placeholder='{$this->dispName}' title='{$this->dispName}'/><br/>";
227 echo
"</div>".PHP_EOL;
238 if( (!isset($this->
name)) OR ($this->
name ==
"") ){
241 if( strlen($_POST[ $this->
name ]) < 256){
243 $err = $reg->test($_POST[ $this->name ]);
244 if(
$err ===
false ){
245 return $reg->make_err($this->dispName);
252 return "Das Textfeld <b>{$this->dispName}</b> enthält mehr als 256 Zeichen! Bitte kürtze deine Antwort etwas.";