Umfragen
line.class.php
Go to the documentation of this file.
1 <?php
2 
3 
4 class line extends widget implements iWidget, output_widget{
5 
6  public $typ = "line";
7  public $direct_result = true;
8 
9  public $colors = array(
10  '#000000',
11  '#eeeeec','#d3d7cf','#babdb6',
12  '#888a85','#555753','#2e3436',
13  '#fce94f','#edd400','#c4a000',
14  '#fcaf3e','#f57900','#ce5c00',
15  '#e9b96e','#c17d11','#8f5902',
16  '#8ae234','#73d216','#4e9a06',
17  '#729fcf','#3465a4','#204a87',
18  '#ad7fa8','#75507b','#5c3566',
19  '#ef2929','#cc0000','#a40000' );
20 
21  public $spaces = array('0.5','1','2');
22 
23  public function set_default_values($db){
24  $this->set_dispName("Separator");
25  }
26 
27  function set_value($value,$type="hr"){
28  if ($type == "hr" ){
29  if( $value != ""){
30  if( (strlen($value) == 7) OR (strlen($value) == 4) ){
31  if( substr($value,0,1) == "#" ){
32  if( is_numeric( "0x".substr($value,1) ) ){
33  $this->value = "color:$value;background-color:$value";//htmlspecialchars($value,ENT_QUOTES,"UTF-8",true);
34  return true;
35  }else{
36  return "Ungültige html Notation";
37  }
38  }else{
39  return "Bitte Eingabe mit # beginnen";
40  }
41  }else{
42  return "Ungültige html Notation";
43  }
44  }else{
45  return "Bitte Farbwert eingeben";
46  }
47  }else if ($type == "space"){
48  if(is_numeric($value)){
49  $value = floatval($value);
50  if( ($value >0 ) AND ($value < 10) ){
51  $value = number_format($value,2,".","");
52  $this->value = "height:{$value}em";
53  return true;
54  }else{
55  return "Wert muss zwischen 0 und 10 liegen.";
56  }
57  }else{
58  return "Bitte numerischen Wert für die Höhenangabe eingeben.";
59  }
60  }
61  return false;
62  }
63 
64  function get_value($name){
65  $attr_list = explode(";",$this->value);
66 
67  $color= "";
68  $height = "";
69  if( sizeof($attr_list) > 0){
70  foreach($attr_list as $attr){
71  $v = explode(":",$attr);
72  if($v[0] == "color"){
73  $color = $v[1];
74  }else if($v[0] == "height"){
75  $height = $v[1];
76  $height = trim($height,"em");
77  }
78  }
79  }
80 
81  if($name == "color"){
82  return $color;
83  }else if ($name == "height"){
84  return $height;
85  }else{
86  return "";
87  }
88 
89  }
90 
91 
92  public function display_type_edit(){
93  $color = $this->get_value("color");
94  $height = $this->get_value("height");
95  echo "<select name='line_style'>";
96  if(($color != "") OR (($color == "") AND ($height=="") ) ){
97  echo "<option value='hr' selected='selected'> Horizontale Linie </option>";
98  echo "<option value='space' > Abstand </option>";
99  }else{
100  echo "<option value='hr'> Horizontale Linie </option>";
101  echo "<option value='space' selected='selected' > Abstand </option>";
102  }
103  echo "</select>";
104  }
105 
106  public function handle_type_edit(){
107  if (isset($_POST["line_style"])){
108  if( $_POST["line_style"] == "hr" ){
109  return "hr";
110  }else if($_POST["line_style"] == "space"){
111  return "space";
112  }
113  }
114  return false;
115  }
116 
117  public function display_space_edit(){
118  $height = $this->get_value("height");
119  $default_vals = array( "klein" => "0.5" , "mittel" => "1", "groß" => "2");
120 
121  echo "Höhe auswählen:";
122  echo "<select name='space_sel'>";
123  $is_def_si = false;
124  foreach( array_keys($default_vals) as $val ){
125  if( $height == $default_vals[$val] ){
126  echo "<option value='{$default_vals[$val]}' selected='selected'>{$val}</option>";
127  $is_def_si = true;
128  }else{
129  echo "<option value='{$default_vals[$val]}' >{$val}</option>";
130  }
131  }
132  echo "</select>";
133 
134  echo "<span style='margin-left:3em;margin-right:3em'> oder </span>";
135  echo "eigene Höhe eingeben:";
136  if($is_def_si == false){
137  echo "<input type='text' name='line_size' value='$height' size='4' />";
138  }else{
139  echo "<input type='text' name='line_size' value='' size='4' />";
140  }
141  }
142 
143  public function handle_space_edit(){
144  // custom space
145  if( (isset($_POST["line_size"])) AND ($_POST["line_size"] != "") ){
146  $err = $this->set_value($_POST["line_size"],"space");
147  if( $err !== true ){
148  return $err;
149  }
150  // on of the list
151  }else if( isset($_POST["space_sel"]) ){
152  $err = $this->set_value($_POST["space_sel"],"space");
153  if( $err !== true ){
154  return $err;
155  }
156  }else{
157  return "Bitte Größe angeben.";
158  }
159  return true;
160  }
161 
162 
163  public function display_color_edit(){
164  /*
165  $colors = array(
166  '#fce94f','#fcaf3e','#e9b96e','#8ae234','#729fcf','#ad7fa8','#ef2929','#eeeeec','#888a85',
167  '#edd400','#f57900','#c17d11','#73d216','#3465a4','#75507b','#cc0000','#d3d7cf','#555753',
168  '#c4a000','#ce5c00','#8f5902','#4e9a06','#204a87','#5c3566','#a40000','#babdb6','#2e3436' );
169  */
170  $col = $this->get_value("color");
171  if ($col == ""){
172  $col="#000000";
173  }
174 
175  echo "Farbe auswählen";
176  echo "<select name='color_sel'>";
177  $is_def_col = false;
178  foreach($this->colors as $color){
179  if($color == $col){
180  $is_def_col = true;
181  echo "<option value='$color' style='background-color:$color' selected='selected'>$color</option>";
182  }else{
183  echo "<option value='$color' style='background-color:$color' >$color</option>";
184  }
185  }
186  echo "</select>";
187  echo "<span style='margin-left:3em;margin-right:3em'> oder </span>";
188 
189  echo "Farbe eingeben:";
190  if($is_def_col == false){
191  echo "<input type='text' name='line_color' value='$col' size='10' />";
192  }else{
193  echo "<input type='text' name='line_color' value='' size='10' />";
194  }
195  }
196 
197 
198  public function handle_color_edit(){
199  // cusom color
200  if( (isset($_POST["line_color"])) AND ($_POST["line_color"] != "") ){
201  $err = $this->set_value($_POST["line_color"],"hr");
202  if( $err !== true ){
203  return $err;
204  }
205  // on of the color list
206  }else if( (isset($_POST["color_sel"])) AND (in_array($_POST["color_sel"],$this->colors)) ){
207  $err = $this->set_value($_POST["color_sel"],"hr");
208  if( $err !== true ){
209  return $err;
210  }
211  }else{
212  return "Bitte Farbwert angeben.";
213  }
214  return true;
215  }
216 
217 
218  public function save_line($db){
219  return $db->update_widget_field($this,"value",$this->value);
220  }
221 
222 
223  function display_edit(){
224  $color = $this->get_value("color");
225  $lasted="";
226  if( (isset($_SESSION["last_widget_edit"])) AND ($_SESSION["last_widget_edit"] == $this->ID) ){
227  $lasted = " widget_last_edit";
228  unset( $_SESSION["last_widget_edit"] );
229  }
230 
231  $this->display_edit_begin();
232  if($color != ""){
233  echo "<div style='padding-top:2em;padding-bottom:1.5em;margin:0px;'><hr style='width:70%;{$this->value}'/></div>";
234  }else{
235  echo "<div style='{$this->value}'>&nbsp;</div>";
236  }
237  echo "</div>";
238  }
239 
240  function display(){
241  $color = $this->get_value("color");
242  if($color != ""){
243  echo "<hr style='width:70%;margin-top:2em;margin-bottom:1.5em;{$this->value}'/>";
244  }else{
245  echo "<div style='{$this->value}'></div>";
246  }
247  }
248 
249 
250  function handle_inpt(){
251  return true;
252  }
253 
254 }
255 // ! no ending newLine
256 ?>