Umfragen
index.php
Go to the documentation of this file.
1 <?php
2 /*
3  * backend/index.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("../config.php");
26 require_once(DOCUMENT_ROOT."/inc/user.class.php");
27 require_once(DOCUMENT_ROOT."/inc/tools.php");
28 
29 require_once(DOCUMENT_ROOT."/inc/check_login.php");
30 check_login();
31 
32 require_once(DOCUMENT_ROOT."/inc/db.class.php");
33 require_once(DOCUMENT_ROOT."/inc/config.class.php");
34 require_once(DOCUMENT_ROOT."/inc/auth.class.php");
35 
36 require_once(DOCUMENT_ROOT."/inc/poll.class.php");
37 require_once(DOCUMENT_ROOT."/inc/html.class.php");
38 require_once(DOCUMENT_ROOT."/inc/messages.class.php");
41 make_session();
42 
43 $page = "index";
44 if( (isset($_GET["page"])) AND ($_GET["page"] != "") ){
45  if( $_GET["page"] == "archive" ){
46  $page = "archive";
47  }else if( $_GET["page"] == "templates" ){
48  $page = "templates";
49  }
50 }
51 
52 
53 check_login();
54 $super_admins = explode(",",SUPER_ADMIN);
55 if( in_array( $_SESSION["user"]->ID ,$super_admins ) ){
56  $is_super_admin = true;
57 }
58 
59 
60 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
62 $config->load();
63 
64 
65 // filter polls ... if user is superadmin display all polls , else display only own polls
66 $poll_list_complete = $db->get_all_polls_array();
67 $poll_list = array();
68 $polls = array();
69 $template_list = array();
70 $templates = array();
71 
72 // filter ownership
73 $all_poll_list = array();
74 if( $is_super_admin ){
76 }else{
77  foreach( $poll_list_complete as $p){
78  if( ($p["owner"] == $_SESSION["user"]->ID) ){
79  $all_poll_list[] = $p;
80  }
81  // not owner of shared templates
82  else if( ($p["status"] == STATUS_SHARED_TEMPLATE) AND (isset($_SESSION["user"]->group)) ){
83  $groups = explode(",",$p["groups"]);
84  if( (in_array($_SESSION["user"]->group,$groups)) OR (in_array("*",$groups)) ){
85  $all_poll_list[] = $p;
86  }
87  } // end if template
88  }
89 }
90 
91 // filter status
92 $poll_list_normal = array();
96 foreach( $all_poll_list as $p ){
97  if( $p["status"] == STATUS_TEMPLATE ){
98  $poll_list_template[] = $p;
99  }else if( $p["status"] == STATUS_SHARED_TEMPLATE ){
101  }else if( $p["status"] == STATUS_ARCHIVE ){
102  $poll_list_archive[] = $p;
103  }else{
104  $poll_list_normal[] = $p;
105  }
106 }
107 
108 // load polls
109 $polls_normal = array();
110 $polls_template = array();
112 $polls_archive = array();
113 if( $page == "index" ){
114  foreach($poll_list_normal as $p){
115  $pp = new poll();
116  $pp->load_from_id($db,$p["ID"]);
117  $polls_normal[] = $pp;
118  }
119 }else if($page == "templates"){
120  foreach($poll_list_template as $p){
121  $pp = new poll();
122  $pp->load_from_id($db,$p["ID"]);
123  $polls_template[] = $pp;
124  }
125  foreach($poll_list_shared_template as $p){
126  $pp = new poll();
127  $pp->load_from_id($db,$p["ID"]);
128  $polls_shared_template[] = $pp;
129  }
130 }else if($page == "archive"){
131  foreach($poll_list_archive as $p){
132  $pp = new poll();
133  $pp->load_from_id($db,$p["ID"]);
134  $polls_archive[] = $pp;
135  }
136 }
137 
138 
139 
140 
141 HTML::doctype();
142 HTML::head('',1); // extra header section , level of deepness for relative paths
143 
144 
145 $navbar = array( 0 => array("name"=>"Backend","href"=>"index.php","onclick"=>"") );
146 if( $page == "templates" ){
147  $navbar[] = array( "name"=>"Vorlagen" , "href"=>"index.php?page=templates" , "onclick"=>"");
148  HTML::menu($navbar); // navbar array
149 }else if($page == "archive"){
150  $navbar[] = array( "name"=>"Archiv" , "href"=>"index.php?page=archive" , "onclick"=>"");
151  HTML::menu($navbar); // navbar array
152 }else{
153  HTML::menu();
154 }
155 
156 
157 $messages->display_messages();
158 $messages->del_all_messages();
159 
160 if( $page == "index" ){
161  echo "<br/>";
162  echo "<table id='linkbox_backend_index'><tr>";
163  echo "<td><a href='index.php?page=archive'> <img src='".APP_ROOT."/icons/32/package-x-generic.png' alt='' /> </a> </td>";
164  echo "<td style='vertical-align:middle;font-size:1.2em;padding-right:2em;'><a href='index.php?page=archive' style=''> zum Archiv</a> </td>";
165 
166  echo "<td><a href='index.php?page=templates'> <img src='".APP_ROOT."/icons/32/edit-paste.png' alt=''/> </a> </td>";
167  echo "<td style='vertical-align:middle;font-size:1.2em;'> <a href='index.php?page=templates' style=''>zu den Vorlagen</a> </td>";
168  echo "</tr></table>";
169 
170  if( sizeof($polls_normal)>0 ){
171  echo "<table class='backend_poll_table' style='margin-top:1.5em'>";
172  if($is_super_admin === false){
173  echo "<tr class='table_header'> <th>ID</th> <th>Name</th> <th>Status</th> <th>Ablaufdatum</th> <th>Bearbeiten</th> </tr>";
174  }else{
175  echo "<tr class='table_header'> <th>ID</th> <th>Name</th> <th>Status</th> <th>Ablaufdatum</th> <th>von</th> <th>Bearbeiten</th> </tr>";
176  }
177  $c=0;
178  $status_mapping = array(
179  STATUS_NORMAL => array("name"=>"aktiv" , "css"=>"status_active"),
180  STATUS_INCOMPLETE => array("name"=>"inaktiv" , "css"=>"status_inactive"),
181  STATUS_USER_DEACTIVATED => array("name"=>"deaktiviert" , "css"=>"status_deactivated") );
182  foreach($polls_normal as $poll){
183  if(intval($poll->status) != STATUS_DELETED){
184  $rowc = $c%2;
185  $timeout = $poll->get_timeout_string();
186  $ts = $poll->get_timeout_timestamp();
187  $color_class="status_active";
188  $status_string = "";
189  if($poll->status == STATUS_NORMAL){
190  $status_string = "aktiv";
191  }
192  if($ts < time()){
193  $status_string = "abgelaufen";
194  $color_class="status_timeout";
195  }
196  if($poll->status == STATUS_INCOMPLETE){
197  $status_string = "inaktiv";
198  $color_class="status_inactive";
199  }
200  if($poll->status == STATUS_USER_DEACTIVATED){
201  $color_class="status_deactivated";
202  $status_string = "deaktiviert";
203  }
204  $edited = "";
205  if( (isset($_SESSION["last_poll_edit"])) AND ($_SESSION["last_poll_edit"] == $poll->ID) ){
206  $edited = "poll_last_edit";
207  unset($_SESSION["last_poll_edit"]);
208  }
209 
210 
211  echo "<tr class='line{$rowc} $edited'>";
212  // POLL ID
213  echo "<td class=''>{$poll->ID}</td>";
214  // POLL TITLE
215  echo "<td class='table_colored_col{$rowc}'> <a href='edit.php?pollID={$poll->ID}' style='color:black;text-decoration:none;' title='Bearbeiten' id='poll{$poll->ID}'> {$poll->name} </a> </td>";
216  // POLL STATUS
217  echo "<td><div class='status_indicator_container'>";
218  echo "<span class='{$color_class} status_indicator' id='status_indicator_pID{$poll->ID}'>$status_string</span>";
219  echo "<ul class='status_submenu'>";
220  foreach(array(STATUS_NORMAL,STATUS_USER_DEACTIVATED) as $stat){
221  echo "<li class='{$status_mapping[$stat]["css"]}' id='status_button_pID{$poll->ID}_sID{$stat}'>{$status_mapping[$stat]["name"]}</li>";
222  }
223  echo "</ul>";
224  echo "</div></td>"; // ends status
225  // POLL TIMEOUT
226  echo "<td>$timeout</td>";
227  // OWNER
228  if($is_super_admin === true){
229  echo "<td>{$poll->owner_fn}</td>";
230  }
231  // POLL EDIT
232  echo "<td style='vertical-align:top;width:130px' >";
233  // edit
234  echo "<a href='edit.php?pollID={$poll->ID}' title='Bearbeiten'><img src='".APP_ROOT."/icons/22/preferences-system.png' alt='edit'/></a>";
235  // duplicate
236  echo "<a href='action.poll.php?pollID={$poll->ID}&amp;action=duplicate' title='Kopieren'><img src='".APP_ROOT."/icons/22/edit-copy.png' alt='duplicate'/></a>";
237  //delete
238  echo "<a href='action.poll.php?pollID={$poll->ID}&amp;action=rm' title='Löschen'><img src='".APP_ROOT."/icons/22/edit-delete.png' alt='delete'/></a>";
239  // make template
240  echo "<span style='margin-left:7px'>&nbsp;</span>";
241  echo "<a href='action.poll.php?pollID={$poll->ID}&amp;action=set_template' title='Als Vorlage kopieren'><img src='".APP_ROOT."/icons/22/edit-paste.png' alt='set_template'/></a>";
242  // archive
243  echo "<a href='action.poll.php?pollID={$poll->ID}&amp;action=archive' title='Archivieren'><img src='".APP_ROOT."/icons/22/package-x-generic.png' alt='archive'/></a>";
244  echo "</td>";
245 
246  echo "</tr>";
247  ++$c;
248  }
249  }
250 
251  echo "</table>";
252  }else{
253  echo "";
254  }
255 
256  echo "<h2><a id='umfrage_hinzufügen'>Neue Umfrage hinzufügen</a></h2>";
257  echo "<form action='action.poll.php' method='POST'>";
258 
259  // name
260  echo "<label for='poll_name'>Bitte gebe der neuen Umfrage einen Namen: </label>";
261  echo "<input type='text' name='poll_name' id='poll_name' size='50'/> <br/><br/>";
262  // type
263  //echo "<input type='hidden' name='poll_type' value='simple'/>";
264  // public/anonymous
265  echo "<fieldset id='optional_new_poll' style='max-width:15em;'>";
266  echo "<legend style='color:#5E5E5E'>Optionale Angaben</legend>";
267  echo "<input style='margin-left:0em' type='checkbox' name='poll_anonymous' id='poll_anonymous' value='true'/>
268  <label for='poll_anonymous'>Anonyme Umfrage</label><br/>";
269  echo "<input style='margin-left:0em' type='checkbox' name='poll_public' id='poll_public' value='true'/>
270  <label for='poll_public'>Öffentliche Umfrage</label><br/>";
271  echo "</fieldset>";
272 
273  echo "<br/><input type='submit' name='add_poll' value='Hinzufügen'/> ";
274  echo "</form>";
275 
276  echo "<h2><a id='umfrage_import'>Umfrage importieren</a></h2>";
277  echo '<form enctype="multipart/form-data" action="action.poll.php?action=import_XML_poll" method="POST" style="margin-top:.5em">';
278  echo "<span style=''>Datei hochladen: </span>";
279  echo '<input name="pollxmlfile" type="file" />';
280  echo '<input type="submit" value="hochladen" />';
281  echo '</form>';
282 
283 
284 
285 
286 }else if( $page == "templates" ){
287 
288  // PRIVATE TEMLATES
289  echo "<h2> <img src='".APP_ROOT."/icons/32/edit-paste.png' style='vertical-align:middle' alt=''/> Private Vorlagen</h2>";
290  if( sizeof($polls_template)>0 ){
291  echo "<table class='backend_poll_table'>";
292  echo "<tr class='table_header'> <th>ID</th> <th>Name</th> <th>edit</th> </tr>";
293  $c =0;
294  foreach( $polls_template as $template ){
295  $r = $c%2;
296  $edited = "";
297  if( (isset($_SESSION["last_poll_edit"])) AND ($_SESSION["last_poll_edit"] == $template->ID) ){
298  $edited = "poll_last_edit";
299  unset($_SESSION["last_poll_edit"]);
300  }
301 
302  echo "<tr class='line$r $edited'>";
303  echo "<td>{$template->ID}</td>";
304 
305  echo "<td><a id='poll{$template->ID}' href='edit.php?pollID={$template->ID}' style='color:black;text-decoration:none;' >{$template->name}</a></td>";
306  echo "<td>";
307  // edit
308  echo "<a href='edit.php?pollID={$template->ID}' title='Bearbeiten' ><img src='".APP_ROOT."/icons/22/preferences-system.png' alt='edit'/></a>";
309  // copy
310  echo "<a href='action.poll.php?pollID={$template->ID}&amp;action=duplicate' title='Kopieren' ><img src='".APP_ROOT."/icons/22/edit-copy.png' alt='duplicate'/></a>";
311  // delete
312  echo "<a href='action.poll.php?pollID={$template->ID}&amp;action=rm' title='Löschen' ><img src='".APP_ROOT."/icons/22/edit-delete.png' alt='delete'/></a>";
313  // archive
314  echo "<span style='margin-left:7px'>&nbsp;</span>";
315  echo "<a href='action.poll.php?pollID={$template->ID}&amp;action=archive' title='Archivieren'><img src='".APP_ROOT."/icons/22/package-x-generic.png' alt='archive'/></a>";
316  // share
317  echo "<a href='action.poll.php?pollID={$template->ID}&amp;action=share' title='Vorlage teilen'><img src='".APP_ROOT."/icons/22/share-template.png' alt='share'/></a>";
318 
319  echo "</td>";
320  echo "</tr>";
321  ++$c;
322  }
323  echo "</table>";
324  }else{
325  echo "<p>Keine Vorlagen</p>";
326  }
327 
328  // MY PUBLIC TEMPLATES
329  echo "<h2> <img src='".APP_ROOT."/icons/32/share-template.png' style='vertical-align:middle' alt=''/> Geteilte Vorlagen</h2>";
330  //$au = new LDAPauth(LDAP_HOST , LDAP_PORT , LDAP_ROOTDN);
331  $au = make_auth_object();
332  $map = $au->get_gid_to_name_mapping();
333  unset($au);
334  if( sizeof($polls_shared_template) >0 ){
335  echo "<table class='backend_poll_table'>";
336  echo "<tr class='table_header'> <th>ID</th> <th>Name</th> <th>geteilt mit</th> <th>edit</th> </tr>";
337  $c =0;
338  foreach( $polls_shared_template as $template ){
339  if( $template->owner == $_SESSION["user"]->ID ){
340  if( in_array("*",$template->groups) ){
341  $shared_with = "Alle";
342  }else{
343  $shared_with = "";
344  foreach( $template->groups as $gr ){
345  if( isset( $map[$gr] ) ){
346  $shared_with = $shared_with."{$map[$gr]}, ";
347  }
348  }
349  $shared_with =trim($shared_with,", ");
350  }
351 
352  $edited = "";
353  if( (isset($_SESSION["last_poll_edit"])) AND ($_SESSION["last_poll_edit"] == $template->ID) ){
354  $edited = "poll_last_edit";
355  unset($_SESSION["last_poll_edit"]);
356  }
357 
358  $r = $c%2;
359  echo "<tr class='line$r $edited'>";
360  echo "<td>{$template->ID}</td>";
361  echo "<td><a id='poll{$template->ID}' href='edit.php?pollID={$template->ID}' style='color:black;text-decoration:none;' >{$template->name}</a></td>";
362  echo "<td>$shared_with</td>";
363  echo "<td>";
364  // edit
365  echo "<a href='edit.php?pollID={$template->ID}' title='Bearbeiten' ><img src='".APP_ROOT."/icons/22/preferences-system.png' alt='edit'/></a>";
366  // copy
367  echo "<a href='action.poll.php?pollID={$template->ID}&amp;action=duplicate' title='Kopieren' ><img src='".APP_ROOT."/icons/22/edit-copy.png' alt='duplicate'/></a>";
368  // delete
369  echo "<a href='action.poll.php?pollID={$template->ID}&amp;action=unshare' title='nicht mehr teilen' ><img src='".APP_ROOT."/icons/22/share-template-delete.png' alt='unshare'/></a>";
370  //echo "<span style='margin-left:7px'>&nbsp;</span>";
371  // archive
372  //echo "<a href='edit.php?pollID={$template->ID}&action=archive' title='Archivieren'><img src='".APP_ROOT."/icons/22/package-x-generic.png' alt='archive'/></a>";
373  echo "</td>";
374  echo "</tr>";
375  ++$c;
376  }
377  }
378  echo "</table>";
379  }else{
380  echo "<p>Keine Vorlagen</p>";
381  }
382 
383  // OTHER PUBLIC TEMPLATES
384  echo "<h2> <img src='".APP_ROOT."/icons/32/share-template.png' style='vertical-align:middle' alt=''/> Vorlagen, die andere teilen</h2>";
385  if( sizeof($polls_shared_template) > 0){
386  echo "<table class='backend_poll_table'>";
387  echo "<tr class='table_header'> <th>ID</th> <th>Name</th> <th>von</th> <th>edit</th> </tr>";
388  $c =0;
389  foreach( $polls_shared_template as $template ){
390  if( $template->owner != $_SESSION["user"]->ID ){
391  $r = $c%2;
392  $edited = "";
393  if( (isset($_SESSION["last_poll_edit"])) AND ($_SESSION["last_poll_edit"] == $template->ID) ){
394  $edited = "poll_last_edit";
395  unset($_SESSION["last_poll_edit"]);
396  }
397 
398  echo "<tr class='line$r $edited'>";
399  echo "<td>{$template->ID}</td>";
400  if($is_super_admin){
401  echo "<td><a id='poll{$template->ID}' href='edit.php?pollID={$template->ID}' style='color:black;text-decoration:none;' >{$template->name}</a></td>";
402  }else{
403  echo "<td>{$template->name}</td>";
404  }
405  echo "<td>{$template->owner_fn}</td>";
406  echo "<td>";
407  if( $is_super_admin ){
408  // edit
409  echo "<a href='edit.php?pollID={$template->ID}' title='Bearbeiten' ><img src='".APP_ROOT."/icons/22/preferences-system.png' alt='edit'/></a>";
410  }
411  // copy
412  echo "<a href='action.poll.php?pollID={$template->ID}&amp;action=duplicate' title='Kopieren' ><img src='".APP_ROOT."/icons/22/edit-copy.png' alt='duplicate'/></a>";
413  if( $is_super_admin){
414  // delete
415  echo "<a href='action.poll.php?pollID={$template->ID}&amp;action=rm' title='Löschen' ><img src='".APP_ROOT."/icons/22/edit-delete.png' alt='delete'/></a>";
416  // archive
417  //echo "<a href='edit.php?pollID={$template->ID}&action=archive' title='Archivieren'><img src='".APP_ROOT."/icons/22/package-x-generic.png' alt='archive'/></a>";
418  }
419  echo "</td>";
420  echo "</tr>";
421  ++$c;
422  }
423  }
424  echo "</table>";
425  }else{
426  echo "<p>Keine Vorlagen</p>";
427  }
428 
429 
430 
431 }else if($page == "archive"){
432  echo "<h2>Archivierte Umfragen</h2>";
433  if( sizeof($polls_archive) > 0 ){
434  echo "<table class='backend_poll_table'>";
435  echo "<tr class='table_header'> <th>ID</th> <th>Name</th> <th>edit</th> </tr>";
436  $c =0;
437  foreach( $polls_archive as $poll ){
438  $r = $c%2;
439  $edited = "";
440  if( (isset($_SESSION["last_poll_edit"])) AND ($_SESSION["last_poll_edit"] == $poll->ID) ){
441  $edited = "poll_last_edit";
442  unset($_SESSION["last_poll_edit"]);
443  }
444 
445  echo "<tr class='line$r $edited'>";
446  echo "<td>{$poll->ID}</td>";
447  echo "<td><a id='poll{$poll->ID}'>{$poll->name}</a></td>";
448  echo "<td>";
449  // edit
450  echo "<a href='edit.php?pollID={$poll->ID}' title='Bearbeiten' ><img src='".APP_ROOT."/icons/22/preferences-system.png' alt='edit'/></a>";
451  // delete
452  echo "<a href='action.poll.php?pollID={$poll->ID}&amp;action=rm' title='Löschen' ><img src='".APP_ROOT."/icons/22/edit-delete.png' alt='delete'/></a>";
453  // copy
454  echo "<a href='action.poll.php?pollID={$poll->ID}&amp;action=duplicate' title='Kopieren' ><img src='".APP_ROOT."/icons/22/edit-copy.png' alt='duplicate'/></a>";
455  // copy
456  echo "<a href='action.poll.php?pollID={$poll->ID}&amp;action=unarchive' title='Wiederherstellen' ><img src='".APP_ROOT."/icons/22/extract-archive.png' alt='unarchive'/></a>";
457  echo "</td>";
458  echo "</tr>";
459  ++$c;
460  }
461  echo "</table>";
462  }else{
463  echo "<p>Keine archivierten Umfragen</p>";
464  }
465 }
466 
467 HTML::FOOT();
468 
469 ?>