function node_makemeeting_simplepoll_insert in Make Meeting Scheduler 6
node_insert()
Parameters
mixed $node:
File
- ./
makemeeting_simplepoll.module, line 306 - Make Meeting Simple Poll module
Code
function node_makemeeting_simplepoll_insert($node) {
global $user;
// creating custom urls
$poll_url = makemeeting_keygen(10);
while (db_result(db_query("SELECT COUNT(*) FROM {makemeeting_poll_heads} WHERE url = '%s'", $poll_url)) > 0) {
$poll_url = makemeeting_keygen(10);
}
$admin_url = makemeeting_keygen(25);
while (db_result(db_query("SELECT COUNT(*) FROM {makemeeting_poll_heads} WHERE url = '%s'", $admin_url)) > 0) {
$admin_url = makemeeting_keygen(25);
}
// saving the poll options
db_query("INSERT INTO {makemeeting_poll_heads} \n (nid, vid, uid, anonym_name, anonym_email, email_notification, poll_type, url, admin_url, multiple_allowed, secure, maybe_option) \n VALUES \n ('%d', '%d', '%d', '%s', '%s', '%d', '%d', '%s', '%s', '%d', '%d', '%d')", $node->nid, $node->vid, $user->uid, $node->anonym['user_name'], $node->anonym['user_email'], $node->email['email_notification'], 2, $poll_url, $admin_url, $node->poll_options['multiple_allowed'], $node->poll_options['secure'], 0);
// saving the answers for the question
foreach ($node->ans['answers'] as $value) {
db_query("INSERT INTO {makemeeting_poll_rows} (nid, answer_text, type) VALUES (%d, '%s', 2)", $node->nid, $value);
}
// set drupal messages
drupal_set_message(l(t("Poll page URL: !url", array(
"!url" => url('makemeeting/' . $poll_url, array(
"absolute" => TRUE,
)),
)), "makemeeting/" . $poll_url));
drupal_set_message(l(t("Admin page URL: !url", array(
"!url" => url('makemeeting/' . $admin_url, array(
"absolute" => TRUE,
)),
)), "makemeeting/" . $admin_url));
// send an email message
$mail = "";
if ($user->uid > 0 && valid_email_address($user->mail)) {
$mail = $user->mail;
}
elseif (valid_email_address($node->anonym['user_email'])) {
$mail = $node->anonym['user_email'];
}
if ($mail != "") {
if ($user->uid > 0) {
$name = $user->name;
}
elseif (isset($node->anonym['user_name'])) {
$name = $node->anonym['user_name'];
}
else {
t("user");
}
$params = array(
"name" => $name,
"poll_url" => $poll_url,
"admin_url" => $admin_url,
);
drupal_mail('makemeeting', 'create_new_poll', $mail, language_default(), $params);
}
}