function makemeeting_simplepoll_update_poll_submit in Make Meeting Scheduler 6
makemeeting_simplepoll_update_poll_submit()
_state
Parameters
mixed $form:
File
- ./
makemeeting_simplepoll.module, line 721 - Make Meeting Simple Poll module
Code
function makemeeting_simplepoll_update_poll_submit($form, &$form_state) {
// load the node
$node_id = db_result(db_query("SELECT nid FROM {makemeeting_poll_heads} WHERE admin_url = '%s'", $form_state['values']['poll_admin_url']));
$node = node_load($node_id);
// save node options
$node->title = $form_state['values']['title'];
$node->body = $form_state['values']['body'];
node_save($node);
// save poll options
db_query("UPDATE {makemeeting_poll_heads} SET anonym_name = '%s', anonym_email = '%s', email_notification = %d, multiple_allowed = %d, secure = %d, maybe_option = %d WHERE nid = %d", $form_state['values']['anonym']['user_name'], $form_state['values']['anonym']['user_email'], $form_state['values']['email_notification'], $form_state['values']['poll_options']['multiple_allowed'], $form_state['values']['poll_options']['secure'], $form_state['values']['poll_options']['maybe_option'], $node_id);
// save or update answers
$active_answer_ids = array();
// walk through the answers
foreach ($form_state['values']['ans']['answers'] as $ans_id => $val) {
// check if it's already in the db
$is_answer = db_result(db_query("SELECT COUNT(*) FROM {makemeeting_poll_rows} WHERE answer_id = %d", $ans_id));
if ($is_answer == 1) {
// if yes, update
db_query("UPDATE {makemeeting_poll_rows} SET answer_text = '%s' WHERE answer_id = %d", $val, $ans_id);
}
else {
// if no, insert
db_query("INSERT INTO {makemeeting_poll_rows} (nid, answer_text, type) VALUES (%d, '%s', 2)", $node_id, $val);
// get the inserted id
$ans_id = db_result(db_query("SELECT MAX(answer_id) FROM {makemeeting_poll_rows}"));
}
// saving the active answer id's for further check
$active_answer_ids[] = $ans_id;
}
// we collect all the answers that are in the database
$all_answer_ids = array();
$result = db_query("SELECT answer_id FROM {makemeeting_poll_rows WHERE nid = %d", $node_id);
while ($row = db_fetch_array($result)) {
$all_answer_ids[] = $row['answer_id'];
}
// if there is an id wich isn't in active_answer_ids, we deleting it, because
// we removed it from the edit page
foreach ($all_answer_ids as $ans_id) {
if (array_search($ans_id, $active_answer_ids) === FALSE) {
db_query("DELETE FROM {makemeeting_poll_rows} WHERE answer_id = %d", $ans_id);
db_query("DELETE FROM {makemeeting_poll_votes} WHERE answer_id = %d", $ans_id);
}
}
drupal_set_message(t("Saved."));
return;
}