Umfragen
tools.php
Go to the documentation of this file.
1 <?php
2 
3 if( !isset($config_included) ){
4  die("config not loaded");
5 }
6 
12 function make_auth_object(){
13  if( AUTH_METHOD == "LDAP" ){
14  $au = new LDAPauth(LDAP_HOST , LDAP_PORT , LDAP_ROOTDN);
15  }else if(AUTH_METHOD == "MYSQL"){
16  $au = new MYSQLauth(AUTH_DB_HOST , AUTH_DB_PORT , AUTH_DB_NAME , AUTH_DB_USER , AUTH_DB_PASS);
17  }
18  if( isset($au) ){
19  return $au;
20  }else{
21  throw new Exception("Fehlkonfiguration der Authentifizierungsmethode");
22  }
23 }
24 
30 function make_session(){
31  if( !isset($_SESSION) ){
32  session_start();
33  }
34  if( !class_exists("user") ){
35  throw new exception("The user class was not found. Please include it BEFORE tools.php");
36  }
37  if( (!isset($_SESSION["user"])) OR ( (isset($_SESSION["user"])) AND (! $_SESSION["user"] instanceof user) ) ){
38  $_SESSION["user"] = new user();
39  }
40  return true;
41 }
42 
43 
44 
52 function load_poll_from_http_request($db,$method="GET"){
53  if( class_exists("poll") ){
54  $poll = new poll();
55  }else{
56  throw new Exception("Pollclass not loaded!");
57  }
58  if( !$db instanceof db ){
59  throw new Exception("No database object given!");
60  }
61  if( $method == "GET" ){
62  if( !isset($_GET["pollID"]) ){
63  return "Es muss eine UmfragenID angegeben werden!";
64  }
65  if( !( ($_GET["pollID"] != "") AND (is_numeric($_GET["pollID"])) ) ){
66  return "Die umfragen ID muss numerisch sein";
67  }
68  if (!$poll->load_from_id($db, intval($_GET["pollID"]) ) ){
69  return "Die angeforderte Umfrage existiert nicht (mehr)";
70  }
71 
72 
73  }else if( $method == "POST" ){
74  if( !isset($_POST["pollID"]) ){
75  return "Es muss eine UmfragenID angegeben werden!";
76  }
77  if( !( ($_POST["pollID"] != "") AND (is_numeric($_POST["pollID"])) ) ){
78  return "Die umfragen ID muss numerisch sein";
79  }
80  if (!$poll->load_from_id($db, intval($_POST["pollID"]) ) ){
81  return "Die angeforderte Umfrage existiert nicht (mehr)";
82  }
83 
84  }else{
85  throw new Exception("Invalid value for method parameter");
86  }
87 
88  return $poll;
89 }
90 
91 
99 function load_widget_from_http_request($poll,$method="GET"){
100 
101  if( !$poll instanceof poll ){
102  throw new Exception("No poll Object given");
103  }
104 
105  if( $method == "GET" ){
106  if( !isset($_GET["widgetID"]) ){
107  return "Es muss eine Widget ID angegeben werden!";
108  }
109  if( !( ($_GET["widgetID"] != "") AND (is_numeric($_GET["widgetID"])) ) ){
110  return "Die Widget ID muss numerisch sein" ;
111  }
112  $widget = $poll->get_widget_by_id( intval($_GET["widgetID"]) );
113 
114  }else if( $method == "POST" ){
115  if( !isset($_POST["widgetID"]) ){
116  return "Es muss eine Widget ID angegeben werden!";
117  }
118  if( !( ($_POST["widgetID"] != "") AND (is_numeric($_POST["widgetID"])) ) ){
119  return "Die Widget ID muss numerisch sein" ;
120  }
121  $widget = $poll->get_widget_by_id( intval($_POST["widgetID"]) );
122 
123  }else{
124  throw new Exception("Invalid value for method parameter");
125  }
126 
127  if( !isset($widget) ){
128  return "Widget existiert leider nicht (mehr)";
129  }else{
130  return $widget;
131  }
132 
133 }
134 
135 // ! no ending newLine
136 ?>