‘fieldset’ AND c.nid = %d ORDER BY c.weight”, $nid);
while ($row = db_fetch_object($result)) {
$header[] = $row->form_key;
$cid[$row->cid] = $row->form_key;
}
return $cid;
}
function assign_record ($nid, $cid, $row, &$record) {
$record[‘FormID’] = $nid;
$record[‘SubmissionID’] = $row->sid;
$record[‘User’] = $row->user;
$record[‘Date’] = date(‘d-m-Y’, $row->submitted);
$field = $cid[$row->cid];
if (preg_match(‘/”filepath”;s:(d+):”([^”]+)/’, $row->data, $matches))
$value = “http://www.aipass.org/” . $matches[2];
else
$value = $row->data;
if (array_key_exists($field, $record))
$record[$field] = $record[$field] . ‘ ‘ . $value;
else
$record[$field] = $value;
}
function get_webform_submissions ($nid, &$header, &$record) {
$cid = get_webform_fields($nid, $header);
$record = array();
$result = db_query(“SELECT s.*, sd.sid, sd.cid, sd.no, sd.data FROM {webform_submitted_data} as sd LEFT JOIN {webform_submissions} as s on (sd.sid = s.sid) WHERE s.nid = %d”, $nid);
while ($row = db_fetch_object($result)) {
assign_record($nid, $cid, $row, $record[$row->sid]);
}
return count($record);
}
function get_webform_submission ($nid, $sid) {
$result = db_query(“SELECT s.*, sd.sid, sd.cid, sd.no, sd.data FROM {webform_submitted_data} as sd LEFT JOIN {webform_submissions} as s on (sd.sid = s.sid) WHERE s.nid = %d AND sd.sid = %d”, $nid, $sid);
$row = db_fetch_object($result);
if ($row) {
$cid = get_webform_fields($nid, $header);
assign_record($nid, $cid, $row, $record);
while ($row = db_fetch_object($result)) {
assign_record($nid, $cid, $row, $record);
}
return $record;
} else
return NULL;
}
function sendhtmlemail ($from, $to, $subject, $contents) {
$headers = array(
‘MIME-Version’ => ‘1.0’,
‘Content-Type’ => ‘text/html; charset=UTF-8; format=flowed’,
‘Content-Transfer-Encoding’ => ‘8Bit’,
‘X-Mailer’ => ‘Drupal’,
‘Sender’ => $from,
‘Errors-To’ => $from,
‘Return-Path’ => $from
);
drupal_mail(‘submission’, $to, $subject, $contents, $from, $headers);
}
function sendattachemail ($from, $to, $subject, $contents, $attachment_name, $attachment_type, $attachment_contents) {
$random_hash = md5(date(‘r’, time()));
$headers = array(
‘MIME-Version’ => ‘1.0’,
‘Content-Type’ => ‘multipart/mixed; boundary=”‘ . $random_hash . ‘”‘,
‘Content-Transfer-Encoding’ => ‘8Bit’,
‘X-Mailer’ => ‘Drupal’,
‘Sender’ => $from,
‘Errors-To’ => $from,
‘Return-Path’ => $from
);
$body = “–” . $random_hash . “nContent-Type: text/html; charset=windows-1252nn”;
$body = $body . $contents;
$body = $body . “n–” . $random_hash . “n”;
$body = $body . “Content-Description: File Transfern”;
$body = $body . “Content-Type: ” . $attachment_type . “n”;
$body = $body . ‘Content-Disposition: attachment; filename=”‘ . $attachment_name . ‘”‘ . “n”;
$body = $body . “Content-Transfer-Encoding: binarynn”;
$body = $body . $attachment_contents;
$body = $body . “–” . $random_hash . “–n”;
drupal_mail(‘submission’, $to, $subject, $body, $from, $headers);
print(“Sent report ” . $subject);
}
$nid = $_GET[‘form’];
if ($nid == NULL) {
print(get_webform_submissions(4098, $header, $formdata) . ” abstract presentati da soci
“);
print(get_webform_submissions(4101, $header, $formdata) . ” abstract presentati da aspiranti soci
“);
print(get_webform_submissions(4099, $header, $formdata) . ” simposi
“);
print(get_webform_submissions(4100, $header, $formdata) . ” iscritti al congresso
“);
print(get_webform_submissions(4108, $header, $formdata) . ” domande premi migliori presentazioni
“);
} elseif ($nid == ‘user’) {
$filename = ‘user_report.html’;
$subject = “User list”;
$body = “User list”;
$table = ‘
| Cognome | Nome | Citta | Posizione | Iscrizione | |
| ‘ . $user->{profile_cognome} . ‘ | ‘ . $user->{profile_nome} . ‘ | ‘ . $user->{profile_citta} . ‘ | ‘ . $user->{profile_statusaccademico} . ‘ | ‘ . $user->{users_mail} . ‘ | ‘ . $user->{profile_sperimentale} . ‘ |
n”;
sendattachemail(“aipsperimentale@gmail.com”, “aipsperimentale@gmail.com”, $subject, $body, $filename, “text/html”, $table);
} else {
$count = get_webform_submissions($nid, $header, $formdata);
if ($count > 0) {
$filename = ‘form_report_’ . $nid . ‘.html’;
$subject = “Report for form ” . $nid;
$body = “Report for form ” . $nid;
$table = ‘
| ‘ . $field . ‘ |
| ‘ . nl2br(htmlentities($submission[$field], ENT_QUOTES, ‘UTF-8’)) . ‘ |
n”;
echo($table);
sendattachemail(“aipsperimentale@gmail.com”, “aipsperimentale@gmail.com”, $subject, $body, $filename, “text/html”, $table);
}
else
print(“Error”);
}
?>
condividi su