Skip to content
Newer
Older
100644 285 lines (174 sloc) 6.44 KB
fba9163 @jdurno Adding files
authored
1 <?php
2
3 /* send.php */
4 /* Send problem reports to those who can deal with them*/
5 /* Takes user details and citation data and formats them into a useful message */
6 /* Last modified: Nov. 2 2011 J. Durno*/
7
8 /*
9 copyright 2011,2012 University of Victoria Libraries
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24 */
25
26 include_once "../includes/contextobject.inc.php";
27 include_once "../includes/Mailer.class.php";
28
29 /* specify where to forward users to */
30 $forwardTo = 'http://library.uvic.ca/extfiles/360Link/problem/';
31
32
33 session_start();
34
35 /* Specify the recipient of the message here */
36 $toAddress = '';
37
38
39 /* just for testing */
40 /*
41 foreach ($_REQUEST as $ind => $var) {
42 echo "$ind => $var <br />";
43 }
44 exit;
45 */
46
47 //array for the requestor's details to live in
48 $r = array();
49
50 //get the requestor's details
51 $r['Name'] = isset($_REQUEST['req_name']) ? $_REQUEST['req_name'] : NULL;
52 $r['Email'] = isset($_REQUEST['req_sender']) ? $_REQUEST['req_sender'] : NULL;
53 $r['Telephone'] = isset($_REQUEST['req_tele']) ? $_REQUEST['req_tele'] : NULL;
54 $r['Location'] = isset($_REQUEST['location']) ? $_REQUEST['location'] : NULL;
55 $r['Patron Type'] = isset($_REQUEST['ptype']) ? $_REQUEST['ptype'] : NULL;
56 $problem = isset($_REQUEST['problem']) ? $_REQUEST['problem'] : NULL;
57 $qstring = isset($_REQUEST['qstring']) ? $_REQUEST['qstring'] : NULL;
58 $msgTitle = isset($_REQUEST['msgtitle']) ? $_REQUEST['msgtitle'] : NULL;
59 $stillReq = isset($_REQUEST['required']) ? $_REQUEST['required'] : NULL;
60
61 if ($msgTitle) {
62 if ($msgTitle > 50) {
63 $WidgetText = substr($string, 0, strrpos(substr($string, 0, 50), ' '));
64 }
65 }
66
67
68
69 //get some server variables
70 $referer = $_SERVER['HTTP_REFERER'];
71 $userAgent = $_SERVER['HTTP_USER_AGENT'];
72 $remoteAddr = $_SERVER['REMOTE_ADDR'];
73
74
75 //if no name or email submitted, go away
76 if ( empty($r['Name']) || empty($r['Email']) || empty($r['Location']) || empty($problem) ) {
77
78 $message = "Sorry, you need to complete all the required fields, otherwise your request cannot be sent";
79 $return_loc = $forwardTo . 'index.php?' . $qstring;
80 go_away($message, $return_loc);
81 }
82
83 //if email address does not contain an @ sign, it's probably form spam
84 //this works because the '@' sign cannot be the first character in the string
85 if (!strpos($r['Email'], '@')) {
86 $message = "Sorry, your email address appears to be invalid. Your form submission cannot be processed.";
87 $return_loc = $forwardTo . 'index.php?' . $qstring;
88 go_away($message, $return_loc);
89 }
90
91 //initialize the ctx object
92 $ctx_obj = new ContextObject($qstring);
93
94
95 //create the message body by combining requestor details, item details, and some administrative info
96
97
98
99 $message_body = '<p><b>Problem Report</b></p>';
100 $message_body .= nl2br($problem);
101
102 $message_body .= '<p><b>User Data</b></p>';
103 $message_body .= formatRequestorDetails($r);
104
105 $message_body .= '<p><b>Metadata</b></p>';
106 $message_body .= formatRequestedItem();
107
108 $message_body .= '<p><b>OpenURL Link</b></p>';
109 $message_body .= 'http://lg5jh7pa3n.search.serialssolutions.com/?' . $qstring;
110
111
112 $senderInfo = '<p><font size="-1">';
113 $senderInfo .= '<b>Sent From:</b> ' . $remoteAddr . '<br />';
114 $senderInfo .= '<b>User Agent:</b> ' . $userAgent . '<br />';
115 $senderInfo .= '<b>Date &amp; Time</b> ' . date('M j, Y g:i:s a') . '<br />';
116 $senderInfo .= '</font></p>';
117 $message_body .= $senderInfo;
118
119 //just for testing
120 /*
121 echo $message_body;
122 exit;
123 */
124
125 $myMailer = new Mailer;
126 $myMailer->setFromName($r['Name']);
127 $myMailer->setFromAddress($r['Email']);
128 $myMailer->setToAddress( $toAddress );
129 $myMailer->setSubjectLine( '360 Link Problem: ' . $msgTitle );
130 $myMailer->setContent($message_body);
131 $myMailer->setHTML(TRUE);
132
133 if ( $myMailer->sendEmail() ) {
134 $message = 'Thank you. Your problem report has been sent.';
135 $return_loc = $forwardTo . 'ack.php';
136 } else {
137 $message = 'Sorry, there was a problem with your form submission. Please try again.';
138 $return_loc = $forwardTo . 'index.php?' . $_SERVER['QUERY_STRING'];
139 }
140
141
142 go_away($message, $return_loc);
143
144
145
146
147 function go_away($message = NULL, $location = NULL) {
148
149 global $_SESSION;
150 global $forwardTo;
151
152 if ($message) {
153 $_SESSION['message'] = $message;
154 }
155
156 if($location) {
157 header( 'location: ' . $location );
158 } else {
159 header( 'location: ' . $forwardTo . 'ack.php' );
160 }
161
162 exit;
163 }
164
165
166
167
168
169
170 //make sure the form parameters aren't too messy
171 function cleanVar($var) {
172
173
174 //trim whitespace
175 $var = trim($var);
176
177 //can't contain html
178 $var = strip_tags($var);
179
180 //can't be more than 400 characters
181 if (strlen($var) > 5000) {
182 $var = substr($var, 0, 5000);
183 }
184
185
186 return $var;
187
188 }
189
190
191 function formatRequestorDetails ($r) {
192
193 $formatted = '<table border="1">';
194
195 foreach ($r as $ind => $var) {
196
197 if (!is_null($var)) {
198
199 $var = cleanVar($var);
200 $formatted .= '<tr><td><strong>' . $ind . '</strong></td>';
201 $formatted .= '<td>' . $var . '</td></tr>';
202 }
203
204 }
205
206 $formatted .= '</table>';
207
208 return $formatted;
209
210
211
212 }
213
214 function formatRequestedItem() {
215
216 global $ctx_obj;
217
218 $formatted = '<table border="1">' . "\n";
219 $tackOn = '';
220
221 foreach ($ctx_obj->labelList as $field => $label) {
222
223 if (in_array($field, $ctx_obj->fieldList)) {
224
225 if (in_array($field, $ctx_obj->adminFieldList)) {
226
227 $tackOn .= '<tr><td><strong>';
228
229 $tackOn .= $label;
230
231 $tackOn .= '</strong></td><td>';
232
233 if (is_array($ctx_obj->$field)) {
234
235 $tackOn .= $ctx_obj->formatArrayAsString($ctx_obj->$field) . "\n";
236 } else {
237 $tackOn .= $ctx_obj->$field;
238 }
239
240 $tackOn .= '</td></tr>';
241
242
243 } else {
244
245 $formatted .= '<tr><td><strong>';
246
247 $formatted .= $label;
248
249 $formatted .= '</strong></td><td>';
250
251 if (is_array($ctx_obj->$field)) {
252
253 $formatted .= $ctx_obj->formatArrayAsString($ctx_obj->$field) . "\n";
254 } else {
255 $formatted .= $ctx_obj->$field;
256 }
257
258 $formatted .= '</td></tr>' . "\n";
259
260 }
261 }
262
263 }
264
265 $formatted .= $tackOn;
266
267 $formatted .= '</table>';
268
269 return $formatted;
270
271 }
272
273
274
275
276
277
278
279
280
281
282
283
284 ?>
Something went wrong with that request. Please try again.