Umfragen
test2.php
Go to the documentation of this file.
1 <?php
2 /*
3  * test2.php
4  *
5  * Copyright 2012 Johannes <jojo@jojo-42>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  *
22  *
23  */
24 /*
25 require_once("inc/db.class.php");
26 require_once("inc/widget.class.php");
27 require_once("inc/poll.class.php");
28 
29 $d= new db("jojo","isabelle","umfragen","localhost");
30 
31 define('LDAP_SERVER', 'localhost');
32 define('LDAP_PORT', 389);
33 define('LDAP_TOP', 'dc=jojo,dc=local');
34 
35 require("inc/auth.class.php");
36 $au = new LDAPauth(LDAP_SERVER , LDAP_PORT , LDAP_TOP);
37 */
38 
39 
40 ?>
41 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
42  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
43 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44 
45 <head>
46  <title>untitled</title>
47  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
48  <meta name="generator" content="Geany 0.21" />
49  <link href="JS/jquery/css/smoothness/jquery-ui-1.10.0.custom" rel="stylesheet">
50  <link href="CSS/style.css" rel="stylesheet" type="text/css">
51 
52  <script src="JS/jquery/jquery-1.9.0.js"></script>
53  <script src="JS/jquery/jquery-ui-1.10.0.custom.js"></script>
54  <script src="JS/Chart.js"></script>
55  <style type="text/css">
56 
57 
58 
59  </style>
60 </head>
61 
62 <body>
63 <pre>
64 <?php
65 
66 require_once("config.php");
67 require_once("inc/tools.php");
68 require_once("inc/db.class.php");
69 require_once("inc/config.class.php");
70 require_once("inc/auth.class.php");
71 require_once("inc/poll.class.php");
72 require_once("inc/messages.class.php");
73 require_once("inc/chart.class.php");
74 require_once("inc/xml.class.php");
75 require_once("inc/user.class.php");
76 if( !(isset($_SESSION)) ){
77  session_start();
78 }
79 
80 //require_once("inc/html.class.php");
81 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
83 $config->load();
84 
85 //$au = new LDAPauth(LDAP_HOST , LDAP_PORT , LDAP_ROOTDN);
87 
88 if((isset($_GET["ID"])) AND (is_numeric($_GET["ID"])) ){
89  $pID=intval($_GET["ID"]);
90 }else {
91  $pID = 200;
92 }
93 $poll = new poll();
94 $poll->load_from_id($db,$pID);
95 
96 
97 /*
98 $messages = new messageHandler();
99 
100 
101 $testmsg = new errorMessage();
102 $testmsg->setMessage("erster Fehler");
103 $messages->add_message($testmsg);
104 
105 $testmsg2 = new errorMessage("zweiter Fehler");
106 $messages->add_message($testmsg2);
107 
108 
109 $testmsg3 = new warningMessage("erste warnung");
110 $messages->add_message($testmsg3);
111 
112 $testmsg4 = new warningMessage("zweite warnung");
113 $messages->add_message($testmsg4);
114 
115 
116 $testmsg5 = new infoMessage("erste info");
117 $messages->add_message($testmsg5);
118 
119 $testmsg6 = new infoMessage("zweite info");
120 $messages->add_message($testmsg6);
121 
122 $testmsg7 = new errorMessage("dritter Fehler");
123 $messages->add_message($testmsg7);
124 
125 $testmsg8 = new errorMessage("vierter Fehler");
126 $messages->add_message($testmsg8);
127 
128 
129 $messages->display_errorMessages();
130 $messages->display_infoMessages();
131 $messages->display_warningMessages();
132 
133 $messages->del_all_messages();
134  */
135 //$messages->del_all_messages();
136 
137 //$db->duplicate_poll(1);
138 //echo "<pre>";
139 //var_dump($_SESSION);
140 //var_dump($poll);
141 
142 
143 
144 //var_dump($_POST);
145 //var_dump($poll);
146 
147 
148 //$db->garbage_collect_result_table($poll);
149 /*
150 $w = $poll->get_widget_by_id(7);
151 $w->option_list[2]->config= array();
152 $w->option_list[2]->serialize_config();
153 echo PHP_EOL."serialized?".PHP_EOL;
154 var_dump($w->option_list[2]->config);
155 $w->option_list[2]->unserialize_config();
156 echo PHP_EOL."UNserialized?".PHP_EOL;
157 var_dump($w->option_list[2]->config);
158 //$db->duplicate_widget(163,6);
159 */
160 /*
161 echo "</pre>";
162 echo "<form action='' method='POST'>";
163 echo "<input type='submit' name='add_option_ID1' title='Option Einfügen' value='' style='padding:0px;margin:0px;background-color:transparent;background-image:url( ".APP_ROOT."/icons/22/preferences-system.png );background-repeat:no-repeat;width:25px;height:25px;' />";
164 echo "</form>";
165 */
166 //var_dump ($poll->move_widget($db,0,4));
167 /*
168 $err = array();
169 
170 if( isset($_POST["save"]) ){
171  $err["name"] = $poll->handle_name_edit();
172  $err["groups"] = $poll->handle_groups_edit($au);
173  $err["timeout"] = $poll->handle_timeout_edit();
174  $err["status"] = $poll->handle_status_edit($db);
175 
176  $attrs = array_keys($err);
177  for( $i=0 ; $i < sizeof($err) ; ++$i){
178  $e = $err[ $attrs[$i] ];
179  if( $e === true){
180  if($attrs[$i] == "name"){
181  $poll->save_name($db);
182  }else if($attrs[$i] == "groups"){
183  $poll->save_groups($db);
184  }else if($attrs[$i] == "timeout"){
185  $poll->save_timeout($db);
186  }
187  }else{
188  print_err($e);
189  }
190  }
191 }
192 
193 
194 echo "<form method='POST' action=''>";
195 $poll->display_name_edit();
196 echo "<br/>";
197 $poll->display_groups_edit($au);
198 echo "<br/>";
199 $poll->display_timeout_edit();
200 echo "<br/>";
201 $poll->display_status_edit();
202 echo "<br/>";
203 echo "<input type='submit' name='save' value='Speichern'/>";
204 echo "</form>";
205 */
206 
207 /*
208 $l = $au->get_all_groups();
209 //$l = array(500,503);
210 echo "<pre>";
211 var_dump(sizeof($au->get_all_users_from_grouplist($l)));
212 echo "</pre>";
213 */
214 //$db->export_to_csv($poll);
215 /*
216 $w= new matrix();
217 $opt = new matrixOption();
218 $quest = new matrixQuestion();
219 
220 $w->name = "a";
221 $w->dispName = "a";
222 $w->pollID = $poll->ID;
223 
224 $opt->set_dispName("Option1");
225 $opt->set_value("Option1");
226 $quest->set_dispName("Option1");
227 
228 $w->insert_option(-1,$opt);
229 $w->insert_question(-1,$quest);
230 
231 $poll->insert_widget(-1,$w);
232 
233 var_dump($poll);
234 
235 $db->insert_widget($w,$poll->type);
236 */
237 /*
238 $data = array(
239  array(
240  "a" => "65",
241  "b" => "59",
242  "c" => "90",
243  "d" => "81",
244  "e" => "56",
245  "f" => "55",
246  "g" => "40"
247  ),
248  array(
249  "a" => "28",
250  "b" => "48",
251  "c" => "40",
252  "d" => "19",
253  "e" => "96",
254  "f" => "27",
255  "g" => "100"
256  )
257 );
258 */
259 
260 
261 /*
262 echo "<pre>";
263 var_dump($data);
264 echo "</pre>";
265 */
266 //$poll->load_widget_result_count($db);
267 
268 
269 //$chart = new barChart(array(),$data);
270 //$chart->display();
271 //$widget = $poll->get_widget_by_id(2);
272 //$wchart = new radioButtonListChart($widget);
273 //$wchart= chart_factory($widget);
274 //$wchart->display();
275 
276 //$widget = $poll->get_widget_by_id(9);
277 //$db->rename_result_column($widget,"wid1_1");
278 //$db->convert_polltype_S2A($poll);
279 //$db->convert_polltype_A2S($poll);
280 
281 //var_dump($db->is_results_empty(269));
282 /*
283 require( "inc/email.class.php" );
284 
285 if( !isset($config_included) ){
286  die("config not loaded");
287 }
288 
289 $mail = new email();
290 
291 var_dump($mail->handle_email_edit($au));
292 
293 
294 if( (isset($_POST["send_email"])) ){
295  if( (isset($_POST["email_subject"]))
296  AND ($_POST["email_subject"] != "")
297  AND ($_POST["email_message"] != "")
298  AND (isset($_POST["email_message"])) ){
299  //$subject = htmlspecialchars( $_POST["email_subject"] , ENT_QUOTES , "UTF-8",true);
300  $subject = strip_tags( $_POST["email_subject"] );
301  $subject = mb_convert_encoding($subject,"ISO-8859-1","UTF-8");
302 
303  //$message = htmlspecialchars( $_POST["email_message"] , ENT_QUOTES , "UTF-8",true);
304  $message = strip_tags( $_POST["email_message"] );
305  $message = mb_convert_encoding($message,"ISO-8859-1","UTF-8");
306 
307  $res = $mail->email($au,$subject,$message);
308  if( $res === true ){
309  echo "Email erfolgreich versendet.";
310  }
311  }
312 }
313 
314 //$mail->sendmail();
315 //$mail->email($au,"Test subject","testMessage",$to=array("all") );
316 //var_dump($mail->email($au,"Test subject","testMessage"));
317 
318 //$info = $au->get_user_info($poll->owner);
319 //$name = $info["fullName"];
320 $name = $_SESSION["fullName"];
321 
322 $url='Der Link ist leider nicht verfügbar. Bitte direkt in der Umfragesoftware nachschauen.';
323 if( defined('APP_ROOT_URL') ){
324  $url = APP_ROOT_URL."/page.php?pID={$poll->ID}";
325 }
326 
327 
328 $subject = "Neue Umfrage: {$poll->name}";
329 $message=
330 "
331 Die Umfragesoftware informiert:
332 -------------------------------
333 
334 $name hat die Umfrage \"{$poll->name}\" veröffentlicht.
335 
336 Die Umfrage kann auf folgender Internetseite ausgefüllt werden:
337 $url
338 
339 Vielen Dank für die Teilname.
340 ";
341 
342 echo "<form action='' method='POST'>";
343 $mail->display_email_edit($au,$subject,$message);
344 echo "<input type='submit' name='send_email' value='Email absenden'>";
345 echo "</form>";
346 
347 
348 //var_dump($db->update_visited_polls("1000",""));
349 //var_dump($db->get_visited_polls_for_user("1000"));
350 echo "<pre>";
351 //var_dump($au->get_all_groups( $groups_whitelist) );
352 //var_dump($au->get_gid_to_name_mapping( $groups_whitelist) );
353 //var_dump( $db->klassenliste($au,$poll) );
354 $widget = $poll->get_widget_by_id(34);
355 $xmlobj = new xml();
356 $xml = $xmlobj->export($widget);
357 
358 //pretty print
359 
360 $dom = new DOMDocument('1.0');
361 $dom->preserveWhiteSpace = false;
362 $dom->formatOutput = true;
363 $dom->loadXML($xml);
364 echo htmlspecialchars($dom->saveXML(),ENT_QUOTES,"UTF-8");
365 
366 var_dump( $xmlobj->import($xml) );
367 echo '
368 <form enctype="multipart/form-data" action="__URL__" method="POST">
369  <label for="pollxmlfile">Datei</label>
370  <input name="pollxmlfile" type="file" id="pollxmlfile"/>
371  <input type="submit" value="hochladen" />
372 </form>
373 ';
374 
375 var_dump($widget);
376 
377 $xml = $widget->xmlExport();
378 
379 //pretty print
380 $dom = new DOMDocument('1.0');
381 $dom->preserveWhiteSpace = false;
382 $dom->formatOutput = true;
383 $dom->loadXML($xml);
384 echo htmlspecialchars($dom->saveXML(),ENT_QUOTES,"UTF-8");
385 //echo htmlspecialchars($xml,ENT_QUOTES,"UTF-8");
386 
387 
388 $sxe = new SimpleXMLElement($xml);
389 $typ = (string) $sxe->typ;
390 if( $typ == "text" ){
391  $widget2 = new text();
392 }else if ($typ == "radioButtonList"){
393  $widget2 = new radioButtonList();
394 }else if ($typ == "checkBoxSingle"){
395  $widget2 = new checkBoxSingle();
396 }else if ($typ == "checkBoxList"){
397  $widget2 = new checkBoxList();
398 }else if ($typ == "matrix"){
399  $widget2 = new matrix();
400 }else if ($typ == "longtext"){
401  $widget2 = new longtext();
402 }else if ($typ == "label"){
403  $widget2 = new label();
404 }else if ($typ == "line"){
405  $widget2 = new line();
406 }
407 //$widget2 = new text();
408 $widget2->xmlImport($xml);
409 var_dump($widget2);
410 
411 
412 $xml = $sxe->asXML();
413 
414 $sxe2 = new SimpleXMLElement($xml);
415 var_dump($widget2);
416 
417 
418 $widget = $poll->get_widget_by_id(34);
419 
420 
421 $opt1 = $widget->option_list[2];
422 $opt2 = $widget->option_list[3];
423 $opt3 = $widget->option_list[4];
424 $opt4 = $widget->option_list[5];
425 
426 $test = new object_list(200,34);
427 
428 $test[] = $opt1;
429 $test[] = $opt2;
430 $test[] = $opt3;
431 
432 //var_dump($test);
433 
434 foreach($test as $t){
435  echo $t->index."->".$t->ID.PHP_EOL;
436 }
437 
438 $test[1] = $opt4;
439 
440 echo "--".PHP_EOL;
441 
442 foreach($test as $t){
443  echo $t->index."->".$t->ID.PHP_EOL;
444 }
445 
446 echo "--".PHP_EOL;
447 
448 //unset($test[1]) ;
449 $test->delete_by_ID(40);
450 
451 foreach($test as $t){
452  echo $t->index."->".$t->ID.PHP_EOL;
453 }
454 
455 
456 echo "--".PHP_EOL;
457 //var_dump( $widget->get_option_by_id(37) );
458 var_dump( sizeof($widget->option_list) );
459 //var_dump($test);
460 
461 
462 $widget = $poll->get_widget_by_id(36);
463 echo "---addW--".PHP_EOL;
464 $db->add_widget_to_result_table($widget);
465 echo "---GC--".PHP_EOL;
466 $db->garbage_collect_result_table($poll);
467 */
468 
469 //var_dump( $au->get_projects_for_user("jojo") );
470 //var_dump( $au->get_all_users_from_grouplist( array("550","551","552","501") ) );
471 //$widget = $poll->get_widget_by_id(6);
472 //var_dump( $db->get_schedule_widget_data($widget) );
473 
474 /*
475 $poll->set_config("email_notif",array("update","insert"));
476 $poll->save_config($db);
477 */
478 /*
479 function make_url($sort,$order){
480  $qarr = explode("&",$_SERVER['QUERY_STRING']);
481  $qarr_n = array();
482  $sort_passed = false;
483  $order_passed = false;
484  // go through query string
485  foreach( $qarr as $q ){
486  if( (substr($q,0,5) == "sort=") ){
487  if( ($sort_passed === false) ){
488  $qarr_n[] = "sort=$sort";
489  $sort_passed = true;
490  }else{
491  // ignore duplicates
492  }
493 
494  }else if( ($q == "asc") OR ($q == "desc") ){
495  if( ($order_passed === false) ){
496  $qarr_n[] = "$order";
497  $order_passed = true;
498  }else{
499  // ignore duplicates
500  }
501  }else{
502  // copy other
503  $qarr_n[] = "$q";
504  }
505  }
506 
507  $url = $_SERVER[ 'SCRIPT_NAME' ]."?";
508  $url .= implode("&",$qarr_n);
509  echo $url;
510 }
511 
512 
513 $str = "rgb(63, 169, 221)
514 rgb(63, 90, 221)
515 rgb(116, 63, 221)
516 rgb(195, 63, 221)
517 rgb(221, 63, 169)
518 rgb(221, 63, 90)
519 rgb(221, 116, 63)
520 rgb(221, 195, 63)
521 rgb(169, 221, 63)
522 rgb(90, 221, 63)
523 rgb(63, 221, 116)
524 rgb(63, 221, 195)";
525 
526 $ar = explode("\n",$str);
527 
528 foreach($ar as $c){
529  $cc = explode("(",$c);
530  $ccc = explode(")",$cc[1]);
531  echo "\"".$cc[0]."a(".$ccc[0].", 0.5)".$ccc[1]."\", ";
532 }
533 echo PHP_EOL;
534 foreach($ar as $c){
535  $cc = explode("(",$c);
536  $ccc = explode(")",$cc[1]);
537  echo "\"".$cc[0]."a(".$ccc[0].", 1)".$ccc[1]."\", ";
538 }
539 
540 
541 //$cases = array( "12" , "+12" , "-12" , "12.5" , "12,5" , "1.012,5" , "11,.2" , "12a" , "12,a1" , "1a2,5" );
542 $cases = array( "12" , "AB56" , "F5" , "45A" , "45S" , "86s" , "95f5a" , "h45" , "12,1" , "1a2,5" );
543 
544 foreach($cases as $case){
545  echo "$case :".PHP_EOL;
546  var_dump( preg_match("/^[[:xdigit:]]*$/",$case) );
547  echo PHP_EOL;
548 }
549 
550 
551 if(isset($_POST["test_subm"]) ){
552  var_dump( preg_match("/^-{0,1}\d*(:?(\.{0,1}|,{0,1})\d)$/",$_POST["test"]) );
553 }
554 echo "<form method='post' action=''>";
555 echo "<input name='test'/>";
556 echo "<input type='submit' name='test_subm' value='test_subm' />";
557 echo "</form>";
558 
559 
560 class test{
561 
562  private $ID = "";
563 
564 
565  public function __isset($name){
566  if( $name == "ID" ){
567  return isset($this->ID) AND ($this->ID != "");
568  }
569  }
570 
571 }
572 
573 $t = new test();
574 var_dump( isset($t->ID) );
575 
576 */
577 
578 $data = array();
579 $data["labels"] = array("a","b");
580 $data["datasets"] = array();
581 
582 $data["datasets"][] = array(1,6,3,8,5,6,4,4,6,5,4);
583 $data["datasets"][] = array(8,7,4,6,5,4,4,8,5,6,4);
584 $data["datasets"][] = array(5,4,6,4,1,3,3,4,5,8,7);
585 $data["datasets"][] = array(3,2,5,4,5,4,5,6,4,3,1);
586 
587 
588 $data2 = array(1,2,3,4,6,8,7,4,4,1,4,4,7,4,6,4,4,4,1,2,6,6,7);
589 
594 
595 echo "<div style='background-color:white'>";
596 $chart1->display();
597 $chart2->display();
598 $chart3->display();
599 $chart4->display();
600 echo "</div>";
601 
602 
603 ?>
604 
605 
606 
607 </pre>
608 <br/>
609 
610 <?php
611 $poll->load_widget_result_count($db);
612 
613 $widget = $poll->get_widget_by_id(34);
614 $widget->set_config("chartType","pieChart");
615 $widget->chart_display();
616 
617 ?>
618 <!--
619 <ul class="nav">
620  <li><a href="" class="navitem1 navitem" >bla bla bla</a></li>
621  <li><a href="" class="navitem2 navitem">bla bla bla</a></li>
622  <li><a href="" class="navitem3 navitem">bla bla bla</a></li>
623  <li><a href="" class="navitem4 navitem">bla bla bla</a></li>
624 </ul>
625 
626 <span class="test"></span>
627 -->
628 </body>
629 
630 </html>