3 // Provide feedback about slice(s)
5 // Mark Huang <mlhuang@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
12 require_once 'plc_session.php';
16 require_once 'plc_drupal.php';
17 drupal_set_title('Slice Feedback');
18 include 'plc_header.php';
20 if (isset($_REQUEST['slices']) && is_array($_REQUEST['slices'])) {
21 $slice_names = $_REQUEST['slices'];
22 $selected = 'selected="selected"';
24 $slice_names = array();
27 // Return all slices and users of those slices
28 $slices = $adm->GetSlices($slice_names, array('name', 'person_ids'));
31 if (isset($_REQUEST['email'])) {
32 // Email Address Verification with PHP
33 // http://www.devshed.com/c/a/PHP/Email-Address-Verification-with-PHP/
34 // checks proper syntax
35 $email = $_REQUEST['email'];
36 if (preg_match("/^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9\.-]+$/", $email)) {
37 list($username, $domain) = explode('@', $email);
38 // prevent default domain from being appended
40 // check if the domain has MX records, or is at least resolvable
41 if (getmxrr($domain, $mxhosts) || checkdnsrr($domain, 'ANY')) {
42 $valid_email = $email;
48 if (isset($_REQUEST['comments'])) {
49 $comments = $_REQUEST['comments'];
52 if (isset($_REQUEST['submitted']) && isset($valid_email) && $slices) {
53 foreach ($slices as $slice) {
56 if (defined('PLC_MAIL_SLICE_ADDRESS')) {
57 $to[] = str_replace('SLICE', $slice['name'], PLC_MAIL_SLICE_ADDRESS);
59 // Get all users in the slices
60 foreach ($adm->GetPersons($slice['person_ids'], array('person_id', 'email'))
62 $to[] = $person['email'];
66 $to = array_unique($to);
68 $headers = "Content-type: text/plain\r\n";
69 $headers .= "From: $valid_email\r\n";
70 $headers .= "Reply-To: $valid_email\r\n";
71 $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
73 $subject = PLC_NAME . " Slice Feedback - " . $slice['name'];
75 $message = $subject . "\r\n";
79 $message .= PLC_NAME . " has received feedback from $valid_email regarding\r\n";
80 $message .= "your slice:\r\n";
82 $message .= strip_tags($comments) . "\r\n";
85 $message .= "Please contact $valid_email at your convenience.\r\n";
87 // XXX API should handle this, since it handles Unicode
88 // properly. Since neither PHP4 nor PHP5 can pass Unicode via XML-RPC right
89 // now anyway, though, it doesn't really ematter.
90 if (PLC_MAIL_ENABLED) {
91 mail(implode(", ", $to), $subject, $message, $headers);
95 // Pause to limit spams
102 <p>Thank you for your feedback. The principals responsible for each
103 slice will respond to your concerns as soon as possible.</p>
109 print "To: " . implode(", ", $to) . "\r\n";
110 print htmlspecialchars($headers);
112 print htmlspecialchars($message);
118 $self = $_SERVER['PHP_SELF'];
119 if (!empty($_SERVER['QUERY_STRING'])) {
120 $self .= "?" . $_SERVER['QUERY_STRING'];
125 <p>Select the slices for which you would like to provide feedback.</p>
127 <form method="post" action="$self">
131 $select_size = min(10, count($slices));
132 print "<select name=\"slices[]\" size=\"$select_size\" multiple=\"multiple\">";
133 foreach ($slices as $slice) {
134 $slice_name = htmlspecialchars($slice['name']);
135 print "<option $selected value=\"$slice_name\">$slice_name</option>";
139 $email = htmlspecialchars($email);
140 $comments = htmlspecialchars($comments);
144 <p>Briefly describe your concerns in the <b>Comments</b> field, provide a
145 <b>Contact E-mail</b> address, and click <b>Send</b>.</p>
148 <b>Contact E-mail</b><br />
149 <input type="text" name="email" size="40" value="$email" /><br />
151 <b>Comments</b><br />
152 <textarea rows="10" cols="80" name="comments">$comments</textarea><br />
154 <input type="submit" name="submitted" value="Send" />
162 include 'plc_footer.php';