function node_makemeeting_insert in Make Meeting Scheduler 7
Same name and namespace in other branches
- 6 makemeeting.module \node_makemeeting_insert()
Implementation of hook_node_insert()
File
- ./
makemeeting.module, line 518 - Make Meeting module
Code
function node_makemeeting_insert($node) {
global $user;
// Poll_head
// generate the poll urls and save them
$poll_url = _makemeeting_generate_url('url', 10);
$admin_url = _makemeeting_generate_url('admin_url', 25);
// save the poll options
$values = array(
'nid' => $node->nid,
'vid' => $node->vid,
'uid' => $user->uid,
'email_notification' => $node->email_notification,
'poll_type' => 1,
'url' => $poll_url,
'admin_url' => $admin_url,
'multiple_allowed' => $node->poll_options['multiple_allowed'],
'secure' => $node->poll_options['secure'],
'maybe_option' => $node->poll_options['maybe_option'],
);
$query = db_insert('makemeeting_poll_heads')
->fields($values);
if (isset($node->anonym)) {
$query
->fields(array(
'anonym_name' => $node->anonym['user_name'],
'anonym_email' => $node->anonym['user_email'],
));
}
$query
->execute();
// we get the selected dates and options in $node->calendar
// collecting the form datas in makemeeting_calendarselector_process()
if (isset($node->calendar)) {
foreach ($node->calendar as $day => $options_array) {
$values = array(
'nid' => $node->nid,
'answer_text' => $day,
'type' => 1,
);
$answer_id = db_insert('makemeeting_poll_rows')
->fields($values)
->execute();
foreach ($options_array as $option) {
$values = array(
'answer_id' => $answer_id,
'alter_text' => $option,
);
db_insert('makemeeting_poll_alters')
->fields($values)
->execute();
}
}
}
// setting the output texts: the url of the poll page and the admin page
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
if ($node->email_notification) {
$mail = $name = "";
if ($user->uid > 0) {
$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'];
}
$params = array(
"name" => $name,
"poll_url" => $poll_url,
"admin_url" => $admin_url,
);
drupal_mail('makemeeting', 'create_new_poll', $mail, language_default(), $params);
}
}
drupal_goto('makemeeting/' . $poll_url);
}