You are here

function node_makemeeting_insert in Make Meeting Scheduler 6

Same name and namespace in other branches
  1. 7 makemeeting.module \node_makemeeting_insert()

node_insert implementation

File

./makemeeting.module, line 422
Make Meeting module

Code

function node_makemeeting_insert($node) {
  global $user;

  //  print_r($node);
  // poll_head
  // generate the poll urls and save them
  $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);
  }

  // save 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_notification, 1, $poll_url, $admin_url, $node->poll_options['multiple_allowed'], $node->poll_options['secure'], $node->poll_options['maybe_option']);

  // we get the selected dates and options in $node->calendar
  // collecting the form datas in makemeeting_calendarselector_process()
  foreach ($node->calendar as $day => $options_array) {
    db_query("INSERT INTO {makemeeting_poll_rows} (nid, answer_text, type) VALUES (%d, '%s', %d)", $node->nid, $day, 1);
    $answer_id = db_result(db_query("SELECT MAX(answer_id) FROM {makemeeting_poll_rows}"));
    foreach ($options_array as $option) {
      db_query("INSERT INTO {makemeeting_poll_alters (answer_id, alter_text) VALUES (%d, '%s')", $answer_id, $option);
    }
  }

  // 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
  $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);
  }
  drupal_goto('makemeeting/' . $poll_url);
}