function markAsVoted($user, $voting_id) { $votings = $user["votings"]; if (has_voted($user, $voting_id) && !in_array($voting_id, $votings)) { $votings[] = $voting_id; } }
$wpdb->insert("{$wpdb->prefix}favorite", compact('post_id', 'user_id')); wp_send_json(TRUE); } else { $wpdb->delete("{$wpdb->prefix}favorite", compact('post_id', 'user_id')); wp_send_json(FALSE); } }, 10); add_action('wp_ajax_user_post_vote', function () { global $wpdb; $wpdb instanceof \wpdb; $Input = new \jptt\core\Input(); $userdata = get_userdata(get_current_user_id()); $post_id = (int) $Input->get('post_id'); $user_id = (int) $userdata->ID; $vote_value = (int) $Input->get('post_id'); if (!has_voted($post_id, $user_id)) { $wpdb->insert("{$wpdb->prefix}voted", compact('post_id', 'user_id', 'vote_value')); wp_send_json(TRUE); } else { wp_send_json(FALSE); } }, 10); add_action('wp_ajax_user_post_visited', function () { $Input = new \jptt\core\Input(); $post_id = (int) $Input->get('post_id'); $visit_count = (int) get_post_meta($post_id, '_visit_count', TRUE); $visit_last_ip = get_post_meta($post_id, '_visit_last_ip', TRUE); $visit_ip = ip2long($Input->ip_address()); if (in_array($visit_ip, (array) $visit_last_ip)) { wp_send_json(FALSE); }
function module_poll() { $activepolls = display_results(); if (strlen($activepolls) > 160) { echo '<div class="poll">'; } if (isset($_SESSION['valid_user'])) { if (!isset($_REQUEST['pollaction'])) { $pollaction = ""; } else { $pollaction = $_REQUEST['pollaction']; } if ($pollaction == "votecast") { $pollid = $_REQUEST['pollid']; $regvote = "INSERT INTO vote VALUES (" . $pollid . ", '" . $_SESSION['valid_user'] . "'," . $_REQUEST['chosenalt'] . ");"; $result = DB_insert($regvote); if ($result) { echo "Takk for din stemme. Resultatet under oppdateres neste gang du viser siden."; } else { echo "Databaseproblem - din stemme ble ikke registrert. Skriv gjerne en lynforumpost om nøyaktig hva som skjedde, her er en bug et sted."; } } $current_time = date('Y-m-d H:i'); //echo $current_time; $findpolls = "SELECT pollid, title FROM poll WHERE time_opened < '" . $current_time . "' AND time_closed > '" . $current_time . "';"; $pollresult = DB_get_table($findpolls); //echo $findpolls; $num_polls = DB_rows_affected($pollresult); while ($rowpoll = DB_next_row($pollresult)) { $pollid = $rowpoll['pollid']; if (!has_voted($_SESSION['valid_user'], $pollid)) { if (!isset($findalt)) { echo '<table class="polltable">'; echo '<tr><td colspan=2 class="pollheader">Stem!</td></tr>'; } echo '<tr><td colspan=2 class="polltitle">' . $rowpoll['title'] . '</td></tr>'; $findalt = "SELECT pollid, question,questionid FROM pollquestion WHERE pollid =" . $pollid . ";"; $result = DB_get_table($findalt); $num_results = DB_rows_affected($result); if ($num_results > 0) { form_start_post(); form_hidden("pollid", $pollid); form_hidden("pollaction", "votecast"); while ($row = DB_next_row($result)) { echo '<tr><td class="pollquestion">' . $row['question']; echo '</td><td><input type="radio" value="' . $row['questionid'] . '" name="chosenalt"></td></tr>'; } echo '<tr><td colspan=2 class="pollinput">'; form_submit("s", "Stem"); echo '</td></tr>'; form_end(); } } } if (isset($findalt)) { echo '</table>'; } } // Vis resultater for alle aktive polls if (strlen($activepolls) > 160) { echo $activepolls . '</div>'; } }
foreach ($questions as $question) { $line = array(); $formatoptions->para = false; $content = format_text($question->content, FORMAT_MOODLE, $formatoptions); $user = get_record('user', 'id', $question->userid); if ($question->anonymous) { $a->user = get_string('anonymous', 'hotquestion'); } else { $a->user = '******' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $course->id . '">' . fullname($user) . '</a>'; } $a->time = userdate($question->time) . ' (' . get_string('early', 'assignment', format_time(time() - $question->time)) . ')'; $info = '<div class="author">' . get_string('authorinfo', 'hotquestion', $a) . '</div>'; $line[] = $content . $info; $heat = $question->count; if (has_capability('mod/hotquestion:vote', $context) && $question->userid != $USER->id) { if (!has_voted($question->id)) { $heat .= ' <a href="view.php?id=' . $cm->id . '&action=vote&q=' . $question->id . '"><img src="' . $CFG->pixpath . '/s/yes.gif" title="' . get_string('vote', 'hotquestion') . '" alt="' . get_string('vote', 'hotquestion') . '"/></a>'; } else { /* temply disable unvote to see effect $heat .= ' <a href="view.php?id='.$cm->id.'&action=unvote&q='.$question->id.'"><img src="'.$CFG->pixpath.'/s/no.gif" title="'.get_string('unvote', 'hotquestion') .'" alt="'. get_string('unvote', 'hotquestion') .'"/></a>'; */ } } $line[] = $heat; $table->data[] = $line; } //for print_table($table); } else { print_simple_box(get_string('noquestions', 'hotquestion'), 'center', '70%'); }
function cast_vote($webid, $message_id, $vote) { // insert a new vote if the user didn't vote already if (has_voted($webid, $message_id, true) == false) { $sql = "INSERT INTO votes SET "; $sql .= "webid='" . mysql_real_escape_string($webid) . "', "; $sql .= "timestamp='" . time() . "', "; $sql .= "message_id='" . mysql_real_escape_string($message_id) . "', "; $sql .= "vote='" . mysql_real_escape_string($vote) . "'"; $result = mysql_query($sql); if (!$result) { return $sql; } else { // return the current counter for the given message mysql_free_result($result); if ($vote == 1) { return get_yes_votes($message_id); } else { if ($vote == 0) { return get_no_votes($message_id); } } } } else { // update the user's vote (yes -> no / no -> yes) $sql = "UPDATE votes SET "; $sql .= "timestamp='" . time() . "', "; $sql .= "vote='" . mysql_real_escape_string($vote) . "' "; $sql .= "WHERE webid='" . mysql_real_escape_string($webid) . "' "; $sql .= "AND message_id='" . mysql_real_escape_string($message_id) . "'"; $result = mysql_query($sql); if (!$result) { return 0; } else { // return the current counter for the given message if ($vote == 1) { return get_yes_votes($message_id); } else { if ($vote == 0) { return get_no_votes($message_id); } } } } }
function create_link($ip, $poll) { return has_voted($ip, $poll) ? "yearendpoll.php" : "yearendpoll.php?poll=" . $poll; }
function record_ip($match_id, $voted_band) { $voter_ip = $_SERVER['REMOTE_ADDR']; if (has_voted($match_id) == false) { $insert = "INSERT INTO mrm_votes VALUES (id, '" . $match_id . "', '" . $voter_ip . "', '" . $voted_band . "')"; $result = mysql_query($insert); if (!$result) { echo $insert . "<br>"; die('Error Inserting VI.'); } } }
function add_new_vote($poll_id, $vote_value_id) { global $vote_error_message; // Make sure vote wasn't left blank if (empty($vote_value_id)) { global $NO_VOTE_SELECTED_ERROR_MSG; $vote_error_message = $NO_VOTE_SELECTED_ERROR_MSG; return FALSE; } // Validate poll ID if (!is_valid_poll_id($poll_id)) { vote_die('ERROR: An invalid poll ID was submitted.'); } // Get poll object global $VALID_POLLS; $poll = $VALID_POLLS[$poll_id]; // Validate vote value ID if (!is_valid_vote($poll, $vote_value_id)) { vote_die('ERROR: An invalid vote was submitted.'); } // Lock vote_lock($poll_id, LOCK_EX); // Check for duplicate vote attempt $ipaddress = $_SERVER['REMOTE_ADDR']; global $PREVENT_DUPLICATE_VOTES; if ($PREVENT_DUPLICATE_VOTES && has_voted($poll_id, $ipaddress)) { global $DUPLICATE_VOTE_ERROR_MSG; $vote_error_message = $DUPLICATE_VOTE_ERROR_MSG; vote_unlock(); return FALSE; } // Add vote vote_history_add($poll_id, $ipaddress, $vote_value_id); vote_summary_add($poll_id, $vote_value_id); // Unlock vote_unlock(); return TRUE; }
die; $page_file = "yearendpoll.php"; $page_title = "Year End Poll"; require "functions/main_fns.php"; require "functions/year_end_poll_fns.php"; require "partials/_header.php"; $ip = $_SERVER['REMOTE_ADDR']; $current_poll = $_GET['poll']; $polls = get_poll_names(); $votes = $_POST['year_end_votes']; $poll_form = $_POST['poll']; $vote_count = $_POST['write_in_value'] == '' ? count($votes) : count($votes) + 1; if ($vote_count != max_picks_for($poll_form)) { echo "<div class=\"row\" id=\"flash\">\n\n <div class=\"twelve columns top-spacer_20 center error\">Wow, this is embarrassing...<br>It seems that you didn't pick enough, please try again.</div>\n\n \n</div>"; } else { if (has_voted($ip, $poll_form) == false) { $insert = add_votes_for($poll_form, $votes); if ($poll_form == 'songs') { add_song_votes_for($ip, $votes, $_POST['write_in_value']); } if ($_POST['write_in_value']) { $insert = add_manual_vote_for($ip, $poll_form, $_POST['write_in_value']); } if ($insert) { add_ip($ip, $poll_form); echo "<div class=\"row\" id=\"flash\">\n\n <div class=\"twelve columns top-spacer_20 center success\">Thanks!<br>Your votes have been recorded!</div>\n\n \n</div>"; } } } if ($_POST['contest_form']) { $name = $_POST['name'];