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';
15 // Get sorting functions
16 require_once 'plc_sorts.php';
19 require_once 'plc_drupal.php';
20 drupal_set_title('Slice Feedback');
21 include 'plc_header.php';
23 if (isset($_REQUEST['slices']) && is_array($_REQUEST['slices'])) {
24 $slice_names = $_REQUEST['slices'];
25 $selected = 'selected="selected"';
27 $slice_names = array();
30 // Return all slices and users of those slices
31 $slices = $adm->GetSlices($slice_names, array('name', 'person_ids'));
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
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;
51 if (isset($_REQUEST['comments'])) {
52 $comments = $_REQUEST['comments'];
55 if (isset($_REQUEST['submitted']) && isset($valid_email) && $slices) {
56 foreach ($slices as $slice) {
59 if (defined('PLC_MAIL_SLICE_ADDRESS')) {
60 $to[] = str_replace('SLICE', $slice['name'], PLC_MAIL_SLICE_ADDRESS);
62 // Get all users in the slices
63 foreach ($adm->GetPersons($slice['person_ids'], array('person_id', 'email'))
65 $to[] = $person['email'];
69 $to = array_unique($to);
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";
76 $subject = PLC_NAME . " Slice Feedback - " . $slice['name'];
78 $message = $subject . "\r\n";
82 $message .= PLC_NAME . " has received feedback from $valid_email regarding\r\n";
83 $message .= "your slice:\r\n";
85 $message .= strip_tags($comments) . "\r\n";
88 $message .= "Please contact $valid_email at your convenience.\r\n";
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);
98 // Pause to limit spams
105 <p>Thank you for your feedback. The principals responsible for each
106 slice will respond to your concerns as soon as possible.</p>
112 print "To: " . implode(", ", $to) . "\r\n";
113 print htmlspecialchars($headers);
115 print htmlspecialchars($message);
121 $self = $_SERVER['PHP_SELF'];
122 if (!empty($_SERVER['QUERY_STRING'])) {
123 $self .= "?" . $_SERVER['QUERY_STRING'];
128 <p>Select the slices for which you would like to provide feedback.</p>
130 <form method="post" action="$self">
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>";
142 $email = htmlspecialchars($email);
143 $comments = htmlspecialchars($comments);
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>
151 <b>Contact E-mail</b><br />
152 <input type="text" name="email" size="40" value="$email" /><br />
154 <b>Comments</b><br />
155 <textarea rows="10" cols="80" name="comments">$comments</textarea><br />
157 <input type="submit" name="submitted" value="Send" />
165 include 'plc_footer.php';