function survey_page($atts, $content = null) { global $wpdb; $user_id = get_survey_user_session(); if ($user_id !== FALSE) { //Grab the users name so we can display it later. $prepared = $wpdb->prepare("SELECT fullname FROM {$wpdb->prefix}survey_users WHERE id=%d", $user_id); $fullname = $wpdb->get_var($prepared); //Create the logout string depending on the URL type. $logout = strstr($_SERVER['REQUEST_URI'], '?') === FALSE ? "?logout=1" : "&logout=1"; } if ($user_id !== FALSE) { $survey = new survey($atts['id']); echo "<h3>{$survey->name}</h3>\n"; echo "<div id='survey-logout'>\r\n You are currently logged in as {$fullname}, \r\n <a href='{$_SERVER['REQUEST_URI']}{$logout}'>click here to logout</a>\r\n </div>"; for ($i = 1; $i <= $survey->pages; $i++) { echo $survey->output_survey($i); } } else { survey_registration(NULL); } }
<?php @(require_once '../../../wp-config.php'); global $wpdb; $user_id = get_survey_user_session(); if ($user_id === FALSE) { die; //Don't do anything if they aren't logged in. } //Set up the form data in a way that's more accessible. $form = array(); foreach ($_POST['form'] as $posted) { //If it's an array of data, set it up that way. if (substr($posted['name'], -2) == '[]') { $form[substr($posted['name'], 0, -2)][] = $posted['value']; } else { $form[$posted['name']] = $posted['value']; } } $survey = new survey($form['survey-id']); $answers = $survey->get_answers($form); //Save each answer into the database. foreach ($answers as $question_id => $answer) { //Answers can be an array, so just seperate the answers by a two semi-colons and space if they are. if (is_array($answer)) { $answer = implode(';; ', $answer); } $query = "SELECT answer FROM {$wpdb->prefix}survey_user_answers WHERE user=%d AND question=%d"; $prepared = $wpdb->prepare($query, $user_id, $question_id); $answered = $wpdb->get_row($prepared); if ($answered === NULL) {
private function set_answer() { global $wpdb; $user_id = get_survey_user_session(); $query = "SELECT answer FROM {$wpdb->prefix}survey_user_answers WHERE user=%d AND question=%d"; $prepared = $wpdb->prepare($query, $user_id, $this->id); $answer = $wpdb->get_var($prepared); //Sets the answer to an array of the answers for multiple select questions if ($this->questiontype == self::multiselect || $this->questiontype == self::multiselectother) { $answer = explode(';; ', $answer); } return $answer; }