svn:keywords
[plewww.git] / planetlab / pub / feedback.php
1 <?php
2 //
3 // Provide feedback about slice(s)
4 //
5 // Mark Huang <mlhuang@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
7 //
8 // $Id$
9 //
10
11 // Get API handle
12 require_once 'plc_session.php';
13 global $adm;
14
15 // Get sorting functions
16 require_once 'plc_sorts.php';
17
18 // Print header
19 require_once 'plc_drupal.php';
20 drupal_set_title('Slice Feedback');
21 include 'plc_header.php';
22
23 if (isset($_REQUEST['slices']) && is_array($_REQUEST['slices'])) {
24   $slice_names = $_REQUEST['slices'];
25   $selected = 'selected="selected"';
26 } else {
27   $slice_names = array();
28 }
29
30 // Return all slices and users of those slices
31 $slices = $adm->GetSlices($slice_names, array('name', 'person_ids'));
32
33 $email = "";
34 if (isset($_REQUEST['email'])) {
35   // Email Address Verification with PHP
36   // http://www.devshed.com/c/a/PHP/Email-Address-Verification-with-PHP/
37   // checks proper syntax
38   $email = $_REQUEST['email'];  
39   if (preg_match("/^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9\.-]+$/", $email)) {
40     list($username, $domain) = split('@', $email);
41     // prevent default domain from being appended
42     $domain .= ".";
43     // check if the domain has MX records, or is at least resolvable
44     if (getmxrr($domain, $mxhosts) || checkdnsrr($domain, 'ANY')) {
45       $valid_email = $email;
46     }
47   }
48 }
49
50 $comments = "";
51 if (isset($_REQUEST['comments'])) {
52   $comments = $_REQUEST['comments'];
53 }
54
55 if (isset($_REQUEST['submitted']) && isset($valid_email) && $slices) {
56   foreach ($slices as $slice) {
57     $to = array();
58
59     if (defined('PLC_MAIL_SLICE_ADDRESS')) {
60       $to[] = str_replace('SLICE', $slice['name'], PLC_MAIL_SLICE_ADDRESS);
61     } else {
62       // Get all users in the slices
63       foreach ($adm->GetPersons($slice['person_ids'], array('person_id', 'email'))
64                as $person) {
65         $to[] = $person['email'];
66       }
67     }
68
69     $to = array_unique($to);
70
71     $headers  = "Content-type: text/plain\r\n";
72     $headers .= "From: $valid_email\r\n";
73     $headers .= "Reply-To: $valid_email\r\n";
74     $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
75
76     $subject  = PLC_NAME . " Slice Feedback - " . $slice['name'];
77
78     $message  = $subject . "\r\n";
79     $message .= "\r\n";
80
81     // Print comments
82     $message .= PLC_NAME . " has received feedback from $valid_email regarding\r\n";
83     $message .= "your slice:\r\n";
84     $message .= "\r\n";
85     $message .= strip_tags($comments) . "\r\n";
86     $message .= "\r\n";
87     
88     $message .= "Please contact $valid_email at your convenience.\r\n";
89
90     // XXX API should handle this, since it handles Unicode
91     // properly. Since neither PHP4 nor PHP5 can pass Unicode via XML-RPC right
92     // now anyway, though, it doesn't really ematter.
93     if (PLC_MAIL_ENABLED) {
94       mail(implode(", ", $to), $subject, $message, $headers);
95     }
96   }
97    
98   // Pause to limit spams
99   sleep(5);
100
101   echo <<<EOF
102
103 <h1>Thank You</h1>
104
105 <p>Thank you for your feedback. The principals responsible for each
106 slice will respond to your concerns as soon as possible.</p>
107
108 EOF;
109
110   if (PLC_WWW_DEBUG) {
111     print '<pre>';
112     print "To: " . implode(", ", $to) . "\r\n";
113     print htmlspecialchars($headers);
114     print "\r\n";
115     print htmlspecialchars($message);
116     print '</pre>';
117   }
118
119 } else {
120
121   $self = $_SERVER['PHP_SELF'];
122   if (!empty($_SERVER['QUERY_STRING'])) {
123     $self .= "?" . $_SERVER['QUERY_STRING'];
124   }
125
126   echo <<<EOF
127
128 <p>Select the slices for which you would like to provide feedback.</p>
129
130 <form method="post" action="$self">
131
132 EOF;
133
134 $select_size = min(10, count($slices));
135 print "<select name=\"slices[]\" size=\"$select_size\" multiple=\"multiple\">";
136 foreach ($slices as $slice) {
137   $slice_name = htmlspecialchars($slice['name']);
138   print "<option $selected value=\"$slice_name\">$slice_name</option>";
139 }
140 print '</select>';
141
142 $email = htmlspecialchars($email);
143 $comments = htmlspecialchars($comments);
144
145 echo <<<EOF
146
147 <p>Briefly describe your concerns in the <b>Comments</b> field, provide a
148 <b>Contact E-mail</b> address, and click <b>Send</b>.</p>
149
150 <p>
151 <b>Contact E-mail</b><br />
152 <input type="text" name="email" size="40" value="$email" /><br />
153
154 <b>Comments</b><br />
155 <textarea rows="10" cols="80" name="comments">$comments</textarea><br />
156
157 <input type="submit" name="submitted" value="Send" />
158
159 </form>
160
161 EOF;
162
163 }
164
165 include 'plc_footer.php';