function survey_test($atts, $content = null)
{
    global $wpdb;
    global $survey_salt;
    //Empty the database and restart it.
    if (isset($_GET['restart'])) {
        //Truncate the created tables for this plugin
        $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "survey");
        $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "survey_questions");
        $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "survey_answers");
        $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "survey_users");
        $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "survey_user_answers");
    }
    $survey1 = new survey(FALSE, "Survey 1");
    $question1 = $survey1->add_question(question::truefalse, "True/False: Order 1", -1, -1, 1);
    $question1->add_answer("TF Answer 1 DONT SHOW THIS!", 1);
    $question2 = $survey1->add_question(question::multichoice, "Multiple Choice: Order 2", -1, -1, 2);
    $question2->add_answer("MC Answer 1", 1);
    $question2->add_answer("MC Answer 2");
    $question2->add_answer("MC Answer 3", 3);
    $question3 = $survey1->add_question(question::dropdown, "Dropdown: Order 3", -1, -1, 3);
    $question3->add_answer("DD Answer 1");
    $question3->add_answer("DD Answer 2", 2);
    $question4 = $survey1->add_question(question::multiselect, "Multiple Select: Order 4", -1, -1, 1);
    $question4->add_answer("MS Answer 2", 2);
    $question4->add_answer("MS Answer 1", 1);
    $question4->add_answer("MS Answer 3", 3);
    $question5 = $survey1->add_question(question::shortanswer, "Short Answer: Order 6", -1, -1, 6);
    $question5->add_answer("SA Answer 1 DONT SHOW THIS!", 1);
    $question6 = $survey1->add_question(question::longanswer, "Long Answer: Order 5", -1, -1, 5);
    $question6->add_answer("LA Answer 1 DONT SHOW THIS!", 1);
    $question7 = $survey1->add_question(question::multichoiceother, "Multiple Choice Other: Order 7", -1, -1, 7);
    $question7->add_answer("MCO Answer 1");
    $question7->add_answer("MCO Answer 2");
    $question8 = new question(FALSE, question::multiselectother, "Multiple Select Other: Order 8", -1, -1, 8);
    $question8->add_answer("MSO Answer 1");
    $question8->add_answer("MSO Answer 2");
    $survey1->add_qobject($question8);
    //$survey1->output_survey();
    debug($survey1);
    //Empty the database and restart it.
    if (isset($_GET['restart'])) {
        $insert = $wpdb->insert($wpdb->prefix . 'survey_users', array('username' => 'tester', 'password' => sha1('tester' . $survey_salt, true), 'fullname' => 'Test User'), array('%s', '%s', '%s'));
        $id = $insert ? $wpdb->insert_id : FALSE;
        if ($id !== FALSE) {
            var_dump(bin2hex(sha1('tester' . $survey_salt, true)));
            var_dump(bin2hex($wpdb->get_var("SELECT password FROM {$wpdb->prefix}survey_users WHERE id={$id}")));
        } else {
            echo "Failed to insert!";
            var_dump(bin2hex(sha1('test' . $survey_salt, true)));
        }
        $post = array('menu_order' => 0, 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => get_current_user_id(), 'post_content' => "[survey-page id={$survey1->id}]", 'post_name' => 'test-survey-page', 'post_status' => 'publish', 'post_title' => 'Test Survey Page', 'post_type' => 'page');
        wp_insert_post($post, true);
    }
}
Ejemplo n.º 2
0
 /**
  * 
  * @param Int $survey_id
  * @return Object containing all Survey columns
  */
 public function edit()
 {
     if (isset($_GET["id"])) {
         $id = $_GET["id"];
     }
     /*** set a template variable ***/
     $this->registry->template->welcome = 'Edit Survey';
     $model = new survey($id);
     $survey = $model->find();
     $this->registry->template->survey = $survey[0];
     /*** load the edit template ***/
     $this->registry->template->show($this->name, 'edit');
 }
Ejemplo n.º 3
0
<?php

header_remove();
# depending on the server, you may want to comment this out.
header("Content-Type: application/rss+xml");
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>AIS Ideology Sorter</title>
<description>A public opinion survey</description>

<?php 
$url = "http://{$_SERVER['HTTP_HOST']}" . preg_replace("/\\/feed.*\$/", "/", $_SERVER["REQUEST_URI"]);
echo "<atom:link href=\"{$url}feed/\" rel=\"self\" type=\"application/rss+xml\" />\n";
echo "<link>{$url}</link>\n";
include_once "../secrets.php";
$db = new MySQLi($sqlhost, $sqluser, $sqlpass, $sqldb);
include_once "../ais.php";
$survey = new survey($db);
$survey->feed_items(25);
?>


</channel>
</rss>

Ejemplo n.º 4
0
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<?php 
$errmess = "Erroneous information in GET parameters!";
$id1 = $_GET["id1"];
$id2 = $_GET["id2"];
if ($id1 > $id2) {
    $holder = $id1;
    $id1 = $id2;
    $id2 = $holder;
}
echo "<title>";
if ($id1 && $id2 && $id1 != $id2) {
    include_once "secrets.php";
    $db = new MySQLi($sqlhost, $sqluser, $sqlpass, $sqldb);
    include_once "ais.php";
    $survey = new survey($db);
    $ideology1 = $survey->ideology_name($id1);
    $ideology2 = $survey->ideology_name($id2);
    echo $ideology1 && $ideology2 ? "Comparing \"{$ideology1}\" and \"{$ideology2}\"" : $errmess;
} else {
    echo "{$errmess}\n";
}
echo "</title>\n";
?>
<link rel="stylesheet" type="text/css" href="ais3.css" />
</head>
<body>
<h3><a href=".">home</a></h3>
<?php 
$survey->compare($id1, $id2);
?>
$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) {
        $wpdb->insert($wpdb->prefix . "survey_user_answers", array('user' => $user_id, 'question' => $question_id, 'answer' => $answer), array('%d', '%d', '%s'));
    } elseif ($answered !== NULL && $answer != $answered->answer) {
        $wpdb->update($wpdb->prefix . "survey_user_answers", array('answer' => $answer), array('user' => $user_id, 'question' => $question_id), array('%s'), array('%d', '%d', '%s'));
    }
function survey_submit_question_ajax_callback()
{
    check_ajax_referer('survey_submit_question_nonce', 'security');
    //Make sure they're logged in with the appropriate permissions.
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    //Set up the basic structure for the question array.
    $question = array('qtype' => '', 'qtext' => '', 'answers' => array());
    //This array will keep track of all of the answer ids being edited.
    $edit = array();
    //Fill in the array properly using the posted data.
    foreach ($_POST['question'] as $posted) {
        //If the name is answer then it's a brand new answer and not being edited.
        if ($posted['name'] == 'answer') {
            $question['answers'][] = $posted['value'];
        } elseif (strstr($posted['name'], '-answer') !== FALSE) {
            $answer_id = strstr($posted['name'], '-answer', TRUE);
            $question['answers'][$answer_id] = $posted['value'];
            $edit[] = $answer_id;
        } else {
            $question[$posted['name']] = $posted['value'];
        }
    }
    //If the question is being edited, then this will use the id of that question to create the qobject.
    if (isset($question['survey_edit'])) {
        $qobject = new question(intval($question['survey_edit']));
        $qobject->edit_question($question['qtext']);
        $qobject->edit_type($question['qtype']);
        $qobject->edit_dependency($question['depquestion'], $question['depanswer']);
    } else {
        $qobject = new question(FALSE, $question['qtype'], $question['qtext'], $question['depquestion'], $question['depanswer']);
    }
    switch ($question['qtype']) {
        case question::truefalse:
        case question::shortanswer:
        case question::longanswer:
            //These question types don't have answers.
            break;
        default:
            foreach ($question['answers'] as $answer_id => $answer) {
                //If the answer id is in the array, then it must be edited, otherwise it's a new answer.
                if (in_array($answer_id, $edit)) {
                    $qobject->edit_answer($answer_id, $answer);
                } else {
                    $qobject->add_answer($answer);
                }
            }
    }
    //Don't add a new question to the survey list if it's being edited.
    if (!isset($question['survey_edit'])) {
        $survey = new survey(intval($_POST['survey']));
        $survey->add_qobject($qobject);
    }
    echo "Success!";
    die;
    // this is required to return a proper result
}
Ejemplo n.º 7
0
Archivo: map.php Proyecto: n8chz/survey
The responses &ldquo;strongly disagree,&rdquo; &ldquo;disagree,&rdquo; &ldquo;neutral or no opinion,&rdquo; &ldquo;agree,&rdquo; and &ldquo;strongly agree&rdquo;
are represented by the numbers -2, -1, 0, 1 and 2, respectively.
When the responses of two respondents to a survey item are multipled,
the result will be positive if the two responses are on the same side of neutral,
negative if on opposite sides of neutral,
and zero if either response is neutral.
The numbers thus obtained for each survey item are added together
into a rough measure of agreement or disagreement,
as the case may be,
between two respondents.
Following the link for one of the compared ideologies
will give a side-by-side comparison of the two responses for each survey item.</p>
SPIEL;
echo "<!-- ideology #{$id} -->\n";
include_once "ais.php";
$survey = new survey($db);
echo "<div class=\"friends\">\n";
echo "<h2>Likely allies:</h2>\n";
$survey->friends_and_foes($id, "friend");
echo "</div>\n<div class=\"foes\">\n";
echo "<h2>Likely rivals:</h2>\n";
$survey->friends_and_foes($id, "foe");
echo "</div>\n";
?>


</body>

</html>

Ejemplo n.º 8
0
<!DOCTYPE HTML>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>Recently added ideologies</title>
<link rel="stylesheet" type="text/css" href="ais3.css" />
</head>
<body>
<h3><a href=".">home</a></h3>
<h2>Recently added ideologies:</h2>
<?php 
include_once "secrets.php";
$db = new MySQLi($sqlhost, $sqluser, $sqlpass, $sqldb);
include_once "ais.php";
$survey = new survey($db);
$survey->recent(35);
?>
</body>
</html>

Ejemplo n.º 9
0
fwrite($secrets, "\$sqlpass=\"{$sqlpass}\";\n");
fwrite($secrets, "\$sqldb=\"{$sqldb}\";\n");
fwrite($secrets, "\$privatekey=\"{$privatekey}\";\n");
fwrite($secrets, "\$publickey=\"{$publickey}\";\n");
fwrite($secrets, "?>\n");
fclose($secrets);
chmod("secrets.php", 0600);
$db = new MySQLi("localhost", $sqluser, $sqlpass);
echo "<!-- database attached -->\n";
$db->query("create database if not exists {$sqldb}");
echo "<!-- " . $db->error . " -->\n";
$db->query("use {$sqldb}");
echo "<!-- " . $db->error . " -->\n";
include_once "ais.php";
echo "<!-- ais.php included -->\n";
$survey = new survey($db);
echo "<!-- survey object created -->\n";
$survey->disp_existing_sections();
?>
</fieldset>
</fieldset>
<fieldset>
<button id="addsec" type="button" onclick="addSection();">Add section</button>
</fieldset>
<fieldset>
<input type="submit" id="submit" value="Save changes" />
</fieldset>
</form>
<script type="text/JavaScript">

/*
Ejemplo n.º 10
0
   <fieldset>
    <legend><span id="heading">Take the survey</span><br />
     <span id="guide">Choose a name for your school of thought, or ideology.
     Please do not include any personal identifying information in this name.
     <b>Understand that your responses to this survey, while anonymous, will be released into the public domain!</b>
     If this is not OK with you, please do not continue.</span>
    </legend>
    <label for="ideology">I call my system of thought</label>
    <input type="text" name="ideology" id="ideology" autofocus required />
   </fieldset>
   <fieldset id="questions">
    <?php 
require_once "secrets.php";
$db = new MySQLi($sqlhost, $sqluser, $sqlpass, $sqldb);
require_once "ais.php";
$survey = new survey($db);
echo "<!-- new survey created -->\n";
$survey->generate_questionnaire();
?>
   </fieldset>
   <fieldset id="enter">
    <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LelGMgSAAAAALGrw3q6biIBsXpLO4lDRIxqC1by"></script>
    <noscript>
     <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LelGMgSAAAAALGrw3q6biIBsXpLO4lDRIxqC1by" height="300" width="500">
     </iframe><br/>
     <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
     <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
    </noscript>
    <input type="submit" value="Enter responses" />
   </fieldset>
  </form>
Ejemplo n.º 11
0
<!DOCTYPE HTML>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<?php 
$q = $_GET["q"];
echo "<title>Analysis of question #{$q}</title>\n";
?>
<link rel="stylesheet" type="text/css" href="ais3.css" />
</head>
<body>
<h3><a href=".">home</a></h3>
<?php 
include_once "secrets.php";
$db = new MySQLi($sqlhost, $sqluser, $sqlpass, $sqldb);
include_once "ais.php";
$survey = new survey($db);
$question = $survey->question_text($q);
echo "<p>Proposition:</p>\n";
echo "<h2>{$question}</h2>\n";
$survey->bar_graph($q);
$survey->correlate_question($q);
?>
</body>
</html>

Ejemplo n.º 12
0
<?php 
require_once 'secrets.php';
require_once 'recaptchalib.php';
# reCAPTCHA server-side code from http://code.google.com/apis/recaptcha/docs/php.html
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
echo "<!-- response obtained from reCAPTCHA -->\n";
if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    //die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
    //     "(reCAPTCHA said: " . $resp->error . ")");
    echo "</head><body><form>\n       <h3>reCAPTCHA phrase not correct!</h3>\n       <input type=\"button\" value=\"Back to Previous Page\"\n       onClick=\"javascript: history.go(-1)\">\n       </form></body>";
    #h/t http://www.web-source.net/javascript_back.htm
} else {
    // Your code here to handle a successful verification
    $db = new MySQLi($sqlhost, $sqluser, $sqlpass, $sqldb);
    echo "<!-- Database on board -->\n";
    require_once "ais.php";
    $survey = new survey($db);
    echo "<!-- Survey created -->\n";
    $survey->tabulate($_POST);
    echo "<!-- Survey tabulated -->\n";
    $survey->spool_data_file();
    shell_exec('chmod 0755 mkidmap.py');
    shell_exec('./mkidmap.py');
    shell_exec('chmod 0311 mkidmap.py');
    echo "</head>\n";
}
?>

</html>
Ejemplo n.º 13
0
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>Construct a Likert-scale survey</title>
<link rel="stylesheet" type="text/css" href="ais3.css" />
</head>
<body>
<?php 
echo "<!-- \n\n";
print_r($_POST);
echo "\n-->\n";
# post variables passed to this file:
# spiel, delsection[], delquestion[][], question[][], section[]
include_once "secrets.php";
$db = new MySQLi($sqlhost, $sqluser, $sqlpass, $sqldb);
include_once "ais.php";
$survey = new survey($db);
if (isset($_POST["spiel"])) {
    $charcount = file_put_contents("spiel.txt", $_POST["spiel"]);
    echo "<!-- {$charcount} characters in new spiel! -->\n";
    chmod("spiel.txt", 0600);
}
if (isset($_POST["delsection"])) {
    $survey->del_sections($_POST["delsection"]);
}
if (isset($_POST["question"])) {
    $survey->add_questions($_POST["question"]);
}
if (isset($_POST["delquestion"])) {
    $survey->del_questions($_POST["delquestion"]);
}
if (isset($_POST["section"])) {