Exemplo n.º 1
0
function PortalPollsDisplay($value, $name)
{
    global $THIS_RET;
    static $js_included = false;
    $poll_id = $THIS_RET['ID'];
    //get poll:
    $poll_RET = DBGet(DBQuery("SELECT EXCLUDED_USERS, VOTES_NUMBER, DISPLAY_VOTES FROM PORTAL_POLLS WHERE ID='" . $poll_id . "'"));
    $poll_questions_RET = DBGet(DBQuery("SELECT ID, QUESTION, OPTIONS, TYPE, VOTES FROM PORTAL_POLL_QUESTIONS WHERE PORTAL_POLL_ID='" . $poll_id . "' ORDER BY ID"));
    if (!$poll_RET || !$poll_questions_RET) {
        return ErrorMessage(array('Poll does not exist'));
    }
    //should never be displayed, so do not translate
    //verify if user is in excluded users list (format = '|[profile_id]:[user_id]')
    $profile_id = User('PROFILE_ID');
    if ($profile_id != 0) {
        //modif Francois: call right Student/Staff ID
        $user_id = UserStaffID();
    } else {
        $user_id = UserStudentID();
    }
    $excluded_user = '******' . $profile_id . ':' . $user_id;
    if (mb_strpos($poll_RET[1]['EXCLUDED_USERS'], $excluded_user) !== false) {
        return PortalPollsVotesDisplay($poll_id, $poll_RET[1]['DISPLAY_VOTES'], $poll_questions_RET, $poll_RET[1]['VOTES_NUMBER']);
    }
    //user already voted, display votes
    $PollForm = '';
    if (!$js_included) {
        $PollForm .= includeOnceJquery();
        $PollForm .= '<script type="text/javascript" src="assets/js/jquery.form.js"></script>';
        $PollForm .= '<script type="text/javascript">
			$(document).ready(function() {
				$(\'.formPortalPoll\').ajaxForm({ //send the votes in AJAX
					success: function(data,status,xhr,form) {
						$(form).parent().html(data);
					}
				});
			});
		</script>';
        $js_included = true;
    }
    $PollForm .= '<div id="divPortalPoll' . $poll_id . '" style="max-height:350px; overflow-y:auto;"><form method="POST" class="formPortalPoll" action="ProgramFunctions/PortalPolls.fnc.php"><input type="hidden" name="profile_id" value="' . $profile_id . '" /><input type="hidden" name="user_id" value="' . $user_id . '" /><input type="hidden" name="total_votes_string" value="' . _('Total Participants') . '" /><input type="hidden" name="poll_completed_string" value="' . _('Poll completed') . '" /><TABLE  class="width-100p cellspacing-0">';
    foreach ($poll_questions_RET as $question) {
        $PollForm .= '<TR><TD><b>' . $question['QUESTION'] . '</b></TD><TD><TABLE class="width-100p cellspacing-0">';
        $options_array = explode('<br />', nl2br($question['OPTIONS']));
        $checked = true;
        foreach ($options_array as $option_nb => $option_label) {
            if ($question['TYPE'] == 'multiple_radio') {
                $PollForm .= '<TR><TD><label><input type="radio" name="votes[' . $poll_id . '][' . $question['ID'] . ']" value="' . $option_nb . '" ' . ($checked ? 'checked' : '') . ' /> ' . $option_label . '</label></TD></TR>' . "\n";
            } else {
                //multiple
                $PollForm .= '<TR><TD><label><input type="checkbox" name="votes[' . $poll_id . '][' . $question['ID'] . '][]" value="' . $option_nb . '" /> ' . $option_label . '</label></TD></TR>' . "\n";
            }
            $checked = false;
        }
        $PollForm .= '</TABLE></TD></TR>';
    }
    $PollForm .= '</TD></TR></TABLE><P><input type="submit" value="' . _('Submit') . '" /></P></form></div>';
    return $PollForm;
}
Exemplo n.º 2
0
function _makePollVotes($value, $name)
{
    global $THIS_RET, $questions_RET;
    if ($THIS_RET['ID']) {
        $poll_id = $THIS_RET['ID'];
        $poll_questions_RET = DBGet(DBQuery("SELECT QUESTION, VOTES, OPTIONS FROM PORTAL_POLL_QUESTIONS WHERE PORTAL_POLL_ID='" . $poll_id . "'"));
        $votes_display_RET = DBGet(DBQuery("SELECT DISPLAY_VOTES FROM PORTAL_POLLS WHERE ID='" . $poll_id . "'"));
        if (empty($value)) {
            return CheckboxInput($votes_display_RET[1]['DISPLAY_VOTES'], "values[" . $THIS_RET['ID'] . "][DISPLAY_VOTES]", _('Results Display'));
        }
        include_once 'ProgramFunctions/PortalPolls.fnc.php';
        return CheckboxInput($votes_display_RET[1]['DISPLAY_VOTES'], "values[" . $poll_id . "][DISPLAY_VOTES]", _('Results Display')) . PortalPollsVotesDisplay($poll_id, true, $poll_questions_RET, $value);
    } else {
        return CheckboxInput('', "values[new][DISPLAY_VOTES]", _('Results Display'), '', true);
    }
}