Umfragen
email.php
Go to the documentation of this file.
1 <?php
2 /*
3  * email.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("../inc/user.class.php");
27 require_once("../inc/tools.php");
28 require_once("../inc/check_login.php");
29 
30 require_once("../inc/db.class.php");
31 require_once("../inc/config.class.php");
32 require_once("../inc/auth.class.php");
33 
34 require_once("../inc/poll.class.php");
35 require_once("../inc/email.class.php");
36 require_once("../inc/messages.class.php");
37 require_once("../inc/html.class.php");
38 
39 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
41 $config->load();
42 
43 make_session();
45 $mail = new email();
47 
48 $page = "mail";
49 // SET VARS
50 if ( (isset($_GET["pollID"])) AND
51  (is_numeric($_GET["pollID"])) AND
52  ($_GET["pollID"] != "")
53  )
54 {
55  $poll = new poll();
56  if (!$poll->load_from_id($db, intval($_GET["pollID"]) ) ){
57  die("Umfrage existiert nicht.");
58  }
59 
60 }else{
61  header("Location: index.php");
62  exit();
63 }
64 
65 
66 check_login();
67 
68 $teachers = explode(",",TEACHER_GROUP);
69 // edit needs ownership or admin rights AND BE TEACHER
70 if( ( (intval($_SESSION["user"]->ID) == intval($poll->owner) )
71  AND ( in_array("{$_SESSION["user"]->group}",$teachers )) )
72  OR ( in_array("{$_SESSION["user"]->ID}",explode(",",SUPER_ADMIN) ))
73  ){
74 
75 }else{
76  die("Email versenden nicht erlaubt!");
77 }
78 
79 /*
80 if( isset($_GET["action"]) ){
81 
82  // WIDGET move up
83  if( ($_GET["action"] == "mvup") AND (isset($widget)) ){
84  $poll->move_widget($db,$widget->index,$widget->index-1);
85  header("location: edit.php?pollID={$poll->ID}");
86  exit();
87  // WIDGET move down
88  }else if( ($_GET["action"] == "mvdwn") AND (isset($widget) ) ){
89  $poll->move_widget($db,$widget->index,$widget->index+1);
90  header("location: edit.php?pollID={$poll->ID}");
91  exit();
92  }
93 }
94 * */
95 
96 $to = array();
97 if( in_array("*",$poll->groups) ){
98  $to = $teachers;
99 }else{
100  foreach($poll->groups as $gr){
101  if( in_array($gr,$teachers) ){
102  $to[] = $gr;
103  }
104  }
105 }
106 
107 if( empty($to) ){
108  $page = "no addressList";
109 }
110 
111 // HANDLE SEND
112 $res = $mail->handle_email_edit($poll,$au);
113 if( isset($res) ){
114  if($res !== true ){
115  $messages->add_message(new errorMessage($res) );
116  $page = "mail";
117  }else{
118  $messages->add_message(new infoMessage("Die Email wurde erfolgreich verschickt.") );
119  header("Location: email.php?pollID={$poll->ID}");
120  exit();
121  }
122 }
123 
124 
125 
126 HTML::doctype();
127 HTML::head("",1); // extra header section , level of deepness for relative paths
128 $navbar = array(
129  0 => array("name"=>"Backend","href"=>"index.php","onclick"=>"") ,
130  1 => array( "name"=>"Umfrage {$poll->ID} Bearbeiten" , "href"=>"edit.php?pollID={$poll->ID}" , "onclick"=>""),
131  2 => array("name"=>"Email versenden","href"=>"email.php?pollID={$poll->ID}","onclick"=>"")
132 );
133 
134 HTML::menu($navbar); // navbar array
135 
136 // messages
137 $messages->display_messages();
138 $messages->del_all_messages();
139 
140 
141 
142 if( $page == "mail" ){
143  $name = $_SESSION["user"]->fullName;
144  $url='Der Link ist leider nicht verfügbar. Bitte direkt in der Umfragesoftware nachschauen.';
145  if( defined('APP_ROOT_URL') ){
146  $url = APP_ROOT_URL."/page.php?pID={$poll->hashID}";
147  }
148 
149  // subject and message
150  if( (isset($_POST["email_subject"])) AND ($_POST["email_subject"] != "") ){
151  $subject = $_POST["email_subject"];
152  }else{
153  $subject = "Neue Umfrage: {$poll->name}";
154  }
155 
156  if( (isset($_POST["email_message"])) AND ($_POST["email_message"] != "") ){
157  $message = $_POST["email_message"];
158  }else{
159 $message=
160 "
161 Die Umfragesoftware informiert:
162 -------------------------------
163 
164 $name hat die Umfrage \"{$poll->name}\" veröffentlicht.
165 
166 Die Umfrage kann auf folgender Internetseite ausgefüllt werden:
167 $url
168 
169 Vielen Dank für die Teilname.
170 ";
171  }
172 
173  echo "<form action='' method='POST'>";
174  $mail->display_email_edit($poll,$au,$subject,$message);
175  echo "<input type='submit' name='send_email' value='Email absenden' style='margin-top:.3em'>";
176  echo "</form>";
177 }else if( $page == "no addressList"){
178  echo "<p>Emails können nur an Gruppen gesendet werden, an die die Umfrage auch gerichtet ist.</p>";
179  echo "<p>Bitte in der Klassenbeschränkung der Umfrageeinstellungen mindestens einer der folgenden Gruppen auswählen.</p>";
180  $map = $au->get_gid_to_name_mapping($groups_whitelist);
181  echo "<ul>";
182  foreach( $teachers as $t ){
183  echo "<li>{$map[$t]}</li>";
184  }
185  echo "</ul>";
186 }
187 
188 
189 
190 /*
191 
192 }else if( $edit == "confirm widget remove" ){
193  print_warning("<b>{$widget->dispName}</b> mit der ID <b>{$widget->ID}</b> in der Umfrage <b>{$poll->name}</b> wirklich löschen?");
194  echo "<form method='POST' action=''>";
195  echo "<input type='submit' name='cancel_action' value='Abbrechen' />";
196  echo "<input type='submit' name='rmwid_confirm' value='Ja, wirklich' />";
197  echo "</form>";
198 }else if( $edit == "confirm poll remove"){
199  print_warning("Umfrage <b>{$poll->name}</b> mit der ID <b>{$poll->ID}</b> wirklich löschen?");
200  echo "<form method='POST' action=''>";
201  echo "<input type='submit' name='cancel_action' value='Abbrechen' />";
202  echo "<input type='submit' name='rmpoll_confirm' value='Ja, wirklich' />";
203  echo "</form>";
204 }
205 */
206 
207 
208 HTML::foot();
209 
210 ?>