Umfragen
email-bg.php
Go to the documentation of this file.
1 <?php
2 /*
3  * email.background.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 
26 function make_result_link($poll){
27  if( defined('APP_ROOT_URL') ){
28  $url = APP_ROOT_URL."/backend/results.show.php?pollID={$poll->ID}&view_html";
29  }else{
30  $url='Der Link ist leider nicht verfügbar. Bitte direkt in der Umfragesoftware nachschauen.';
31  }
32  return $url;
33 }
34 
35 function make_edit_link($poll){
36  if( defined('APP_ROOT_URL') ){
37  $url = APP_ROOT_URL."/backend/edit.php?pollID={$poll->ID}";
38  }else{
39  $url='Der Link ist leider nicht verfügbar. Bitte direkt in der Umfragesoftware nachschauen.';
40  }
41  return $url;
42 }
43 
44 function get_text_nonAnonymous_insert($poll,$job){
45 $url = make_result_link($poll);
46 $url2 = make_edit_link($poll);
47 
48 $name = "";
49 $txt = "
50 Die Umfragesoftware informiert:
51 -------------------------------
52 
53 {$job["fullName"]} hat an der Umfrage \"{$poll->name}\" teilgenommen.
54 Die Ergebnisse können auf folgender Seite eingesehen werden:
55 $url
56 
57 Einstellungen zu dieser Umfrage:
58 $url2
59 ";
60 return $txt;
61 }
62 
63 function get_text_nonAnonymous_update($poll,$job){
64 $url = make_result_link($poll);
65 $url2 = make_edit_link($poll);
66 $name = "";
67 $txt = "
68 Die Umfragesoftware informiert:
69 -------------------------------
70 
71 {$job["fullName"]} hat seine Angaben zur Umfrage \"{$poll->name}\" aktualisiert.
72 Die Ergebnisse können auf folgender Seite eingesehen werden:
73 $url
74 
75 Einstellungen zu dieser Umfrage:
76 $url2
77 ";
78 return $txt;
79 
80 }
81 
82 function get_text_Anonymous_insert($poll,$job){
83 $url = make_result_link($poll);
84 $url2 = make_edit_link($poll);
85 $name = "";
86 $txt = "
87 Die Umfragesoftware informiert:
88 -------------------------------
89 
90 Jemand hat an der Umfrage \"{$poll->name}\" teilgenommen.
91 Die Ergebnisse können auf folgender Seite eingesehen werden:
92 $url
93 
94 Einstellungen zu dieser Umfrage:
95 $url2
96 ";
97 return $txt;
98 
99 }
100 
101 require_once("../config.php");
102 require_once("../inc/user.class.php");
103 require_once("../inc/tools.php");
104 require_once("../inc/check_login.php");
105 
106 require_once("../inc/db.class.php");
107 require_once("../inc/config.class.php");
108 require_once("../inc/auth.class.php");
109 
110 require_once("../inc/poll.class.php");
111 require_once("../inc/email.class.php");
112 require_once("../inc/messages.class.php");
113 require_once("../inc/html.class.php");
114 
115 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
117 $config->load();
118 
120 
121 // get all emails we want send and proceed them
122 $jobs = $db->email_stack_get_all();
123 if( $jobs !== false ){
124  foreach( $jobs as $job ){
125  // load poll
126  $poll = new poll();
127  if( $poll->load_from_id($db,intval($job["pollID"])) ){
128 
129  // get text for INSERTED results
130  if( $job["type"] == "insert" ){
131  if( $poll->anonymous == false ){ // use name if not anon
132  $txt = get_text_nonAnonymous_insert($poll,$job);
133  }else{
134  $txt = get_text_Anonymous_insert($poll,$job);
135  }
136 
137  // get text for UPDATED results
138  }else if( $job["type"] == "update" ){
139  if( $poll->anonymous == false ){ // cannot update on non anonymous
140  $txt = get_text_nonAnonymous_update($poll,$job);
141  }
142  }
143 
144  // get email address
145  if( isset($txt) ){
146  $user = new user();
147  $user->load_info_ID($au,$poll->owner);
148  $user->load_config($db,$user->name);
149  $address = $user->get_config("email");
150  }
151 
152  // send email if we have an address to send to
153  if( (isset($txt)) AND ($address != "") ){
154  $email = new email();
155  $success = $email->email_users( $address , $user->fullName , "Umfragesoftware FCS" , $txt );
156  }
157 
158  } // end if poll found
159 
160  // delete job when done
161  $db->email_stack_del($job["ID"]);
162  }
163 }
164 
165 
166 ?>