Exemple #1
0
 /**
  * Singleton method to provide a token object 
  * with the default tokens and descriptions.
  * 
  * @since 2.0
  */
 public static function getTokenObject()
 {
     if (!is_a(self::$instance, "Wpsqt_Tokens")) {
         self::$instance = new Wpsqt_Tokens();
         self::$instance->addToken("USER_NAME", "The name of the user who has taken the quiz or survey.")->addToken("QUIZ_NAME", "The name of the quiz that has been taken, <strong>same as %SURVEY_NAME%</strong>.")->addToken("SURVEY_NAME", "The name of the survey that has been taken, <strong>same as %QUIZ_NAME%</strong>.")->addToken("DATE_EU", "The date the quiz or survey was taken in EU format.")->addToken("DATE_US", "The date the quiz or survey was taken in US format.")->addToken("SCORE", "Score gained in quiz, only works if automarking is enabled.")->addToken("SCORE_PERCENTAGE", "Score gained in quiz, in a percentage.")->addToken("SCORE_PASSFAIL", "Shows either 'Pass' or 'Fail' depending on score.")->addToken("SCORE_COMPETENT", "Shows either 'Competent' or 'Not yet competent' depending on pass or fail.")->addToken("RESULT_URL", "A link to mark the results in the dashboard.")->addToken("RESULT_VIEW_URL", "A link to view the results in the dashboard.")->addToken("DATETIME_EU", "The date and time the quiz or survey was taken in EU format.")->addToken("DATETIME_US", "The date and time the quiz or survey was taken in US format.")->addToken("IP_ADDRESS", "The IP address of the user who has taken the quiz or survey.")->addToken("HOSTNAME", "The hostname of the IP address of the user who has taken the quiz or survey.")->addToken("USER_AGENT", "The user agent of the user who has taken the quiz or survey.")->addToken("USER_EMAIL", "The email address of the user who has taken the quiz or survey.")->addToken("USER_FNAME", "The first name of the user")->addToken("USER_LNAME", "The last name of the user")->addToken("TB_B", "Toggle block of information after this tag")->addToken("TB_E", "End of block of information to be toggled");
     }
     return apply_filters("wpsqt_replacement_tokens", self::$instance);
 }
 /**
  * Singleton method to provide a token object 
  * with the default tokens and descriptions.
  * 
  * @since 2.0
  */
 public static function getTokenObject()
 {
     if (!is_a(self::$instance, "Wpsqt_Tokens")) {
         self::$instance = new Wpsqt_Tokens();
         self::$instance->addToken("USER_NAME", "The name of the user who has taken the quiz or survey.")->addToken("QUIZ_NAME", "The name of the quiz that has been taken, <strong>same as %SURVEY_NAME%</strong>.")->addToken("SURVEY_NAME", "The name of the survey that has been taken, <strong>same as %QUIZ_NAME%</strong>.")->addToken("DATE_EU", "The date the quiz or survey was taken in EU format.")->addToken("DATE_US", "The date the quiz or survey was taken in US format.")->addToken("SCORE", "Score gained in quiz, only works if automarking is enabled.")->addToken("SCORE_PERCENTAGE", "Score gained in quiz, in a percentage.")->addToken("RESULT_URL", "A link to view the results in the dashboard.")->addToken("DATETIME_EU", "The date and time the quiz or survey was taken in EU format.")->addToken("DATETIME_US", "The date and time the quiz or survey was taken in US format.")->addToken("IP_ADDRESS", "The IP address of the user who has taken the quiz or survey.")->addToken("HOSTNAME", "The hostname of the IP address of the user who has taken the quiz or survey.")->addToken("USER_AGENT", "The user agent of the user who has taken the quiz or survey.")->addToken("USER_EMAIL", "The email address of the user who has taken the quiz or survey.")->addToken("USER_FNAME", "The first name of the user")->addToken("USER_LNAME", "The last name of the user");
     }
     return apply_filters("wpsqt_replacement_tokens", self::$instance);
 }
Exemple #3
0
 /**
  * Sends the notificatione mail.
  * 
  * @since 2.0
  */
 public static function sendMail()
 {
     global $wpdb;
     $quizName = $_SESSION['wpsqt']['current_id'];
     $objTokens = Wpsqt_Tokens::getTokenObject();
     $objTokens->setDefaultValues();
     $emailMessage = $_SESSION['wpsqt'][$quizName]['details']['email_template'];
     if (empty($emailMessage)) {
         $emailMessage = get_option('wpsqt_email_template');
     }
     if (empty($emailMessage)) {
         $emailMessage = 'There is a new result to view' . PHP_EOL . PHP_EOL;
         $emailMessage .= 'Person Name : %USER_NAME%' . PHP_EOL;
         $emailMessage .= 'IP Address : %IP_ADDRESS%' . PHP_EOL;
         $emailMessage .= 'Result can be viewed at %RESULT_URL%' . PHP_EOL;
     }
     $emailMessage = $objTokens->doReplacement($emailMessage);
     $quizDetails = $_SESSION['wpsqt'][$quizName]['details'];
     $emailTemplate = empty($quizDetails['email_template']) ? get_option('wpsqt_email_template') : $quizDetails['email_template'];
     $fromEmail = get_option('wpsqt_from_email') ? get_option('wpsqt_from_email') : get_option('admin_email');
     $role = get_option('wpsqt_email_role');
     $personName = isset($_SESSION['wpsqt'][$quizName]['person']['user_name']) && !empty($_SESSION['wpsqt'][$quizName]['person']['user_name']) ? $_SESSION['wpsqt'][$quizName]['person']['user_name'] : 'Anonymous';
     if (!empty($role) && $role != 'none') {
         $this_role = "'[[:<:]]" . $role . "[[:>:]]'";
         $query = "SELECT * \n\t  \t\t\t\t  FROM " . $wpdb->users . " \n\t  \t\t\t\t  WHERE ID = ANY \n\t  \t\t\t\t  \t(\n\t  \t\t\t\t  \t\tSELECT user_id \n\t  \t\t\t\t  \t\tFROM " . $wpdb->usermeta . " \n\t  \t\t\t\t  \t\tWHERE meta_key = 'wp_capabilities' \n\t  \t\t\t\t  \t\t\tAND meta_value RLIKE " . $this_role . "\n\t\t\t\t\t\t) \n\t  \t\t\t\t  ORDER BY user_nicename ASC LIMIT 10000";
         $users = $wpdb->get_results($query, ARRAY_A);
         $emailList = array();
         foreach ($users as $user) {
             $emailList[] = $user['user_email'];
         }
     }
     if (isset($_SESSION['wpsqt'][$quizName]['details']['send_user']) && $_SESSION['wpsqt'][$quizName]['details']['send_user'] == "yes" && isset($_SESSION['wpsqt'][$quizName]['person']['email'])) {
         self::_sendRespondentMail($_SESSION['wpsqt'][$quizName]['person']['email']);
     }
     if ($_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant') {
         $emailTrue = true;
     } elseif ($_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-100' && $percentRight == 100) {
         $emailTrue = true;
     } elseif ($_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-75' && $percentRight > 75) {
         $emailTrue = true;
     } elseif ($_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-50' && $percentRight > 50) {
         $emailTrue = true;
     }
     if (!isset($emailList) || empty($emailList) || $emailTrue === TRUE) {
         $emailAddress = get_option('wpsqt_contact_email');
         if (!empty($_SESSION['wpsqt'][$quizName]['details']['notification_email'])) {
             $emailList[] = $_SESSION['wpsqt'][$quizName]['details']['notification_email'];
         }
     }
     $type = ucfirst($_SESSION['wpsqt'][$quizName]['details']['type']);
     $blogname = get_bloginfo('name');
     $emailSubject = $type . ' Notification From ' . $blogname;
     $headers = 'From: ' . $blogname . ' <' . $fromEmail . '>' . "\r\n";
     if (isset($emailList) && is_array($emailList)) {
         foreach ($emailList as $emailAddress) {
             wp_mail($emailAddress, $emailSubject, $emailMessage, $headers);
         }
     }
 }
Exemple #4
0
 /**
  * Handles doing quiz and survey insertions into 
  * the database. Starts of creating the form object
  * using either Wpsqt_Form_Quiz or Wpsqt_Form_Survey
  * then it moves on to check and see if 
  * 
  * 
  * @since 2.0
  */
 protected function _doInsert()
 {
     $className = "Wpsqt_Form_" . ucfirst($this->_subsection);
     $objForm = new $className();
     $this->_pageVars = array('objForm' => $objForm, 'objTokens' => Wpsqt_Tokens::getTokenObject());
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $errorMessages = $objForm->getMessages($_POST);
         $details = $_POST;
         unset($details['wpsqt_nonce']);
         if (empty($errorMessages)) {
             $details = Wpsqt_Form::getSavableArray($details);
             $this->_pageVars['id'] = Wpsqt_System::insertItemDetails($details, strtolower($this->_subsection));
             do_action('wpsqt_' . strtolower($this->_subsection) . '_addnew');
             $this->_pageView = "admin/misc/redirect.php";
             $this->_pageVars['redirectLocation'] = WPSQT_URL_MAIN . "&section=sections&subsection=" . strtolower($this->_subsection) . "&id=" . $this->_pageVars['id'] . "&new=1";
         } else {
             $objForm->setValues($details);
             $this->_pageVars['errorArray'] = $errorMessages;
         }
     }
 }
Exemple #5
0
 /**
  * Handles the doing updating of quiz and surveys.
  * Firstly it gets the quiz or survey details using
  * either getQuizDetails or getSurveyDetails. Then 
  * creates the page form using either Wpsqt_Form_Quiz
  * or Wpsqt_Form_Survey. Then it checks to see if it's
  * a post request if so it then checks to see if it 
  * assigns $_POST as the details for the quiz or survey.
  * At which point it does a validation call to see if
  * there are any error messages if not it does an update
  * call using either Wpsqt_System::updateQuizDetails or
  * Wpsqt_System::updateSurveyDetails. 
  * 
  * Uses $this->_subsection to find out if it's to use
  * Quiz or Survey functions.
  * 
  * @since 2.0
  */
 protected function _doUpdate()
 {
     $this->_pageView = "admin/quiz/create.php";
     $details = Wpsqt_Form::getInsertableArray(Wpsqt_System::getItemDetails($_GET['id'], strtolower($this->_subsection)));
     $className = "Wpsqt_Form_" . ucfirst($this->_subsection);
     $objForm = new $className();
     $this->_pageVars = array('objForm' => $objForm, 'objTokens' => Wpsqt_Tokens::getTokenObject());
     if ($_SERVER['REQUEST_METHOD'] == "POST" && !isset($_POST['new-page'])) {
         $errorMessages = $objForm->getMessages($_POST);
         $details = $_POST;
         $details['wpsqt_id'] = $_GET['id'];
         unset($details['wpsqt_nonce']);
         if (empty($errorMessages)) {
             Wpsqt_System::updateItemDetails(Wpsqt_Form::getSavableArray($details), $_GET['subsection']);
             do_action('wpsqt_' . strtolower($this->_subsection) . '_edit');
             $this->_pageVars['successMessage'] = ucfirst($this->_subsection) . " updated!";
         } else {
             $this->_pageVars['errorArray'] = $errorMessages;
         }
     }
     $objForm->setValues($details);
 }
Exemple #6
0
<?php

// Set up the token object
require_once WPSQT_DIR . '/lib/Wpsqt/Tokens.php';
$objTokens = Wpsqt_Tokens::getTokenObject();
$objTokens->setDefaultValues();
?>

<?php 
$pollName = $quizName;
$pollId = $_SESSION['wpsqt'][$pollName]['details']['id'];
if ($_SESSION['wpsqt'][$pollName]['details']['finish_display'] == 'Poll results') {
    require_once WPSQT_DIR . '/lib/Wpsqt/Page.php';
    require_once WPSQT_DIR . '/lib/Wpsqt/Page/Main/Results/Poll.php';
    Wpsqt_Page_Main_Results_Poll::displayResults($pollId);
} else {
    if (!empty($_SESSION['wpsqt'][$pollName]['details']['finish_message'])) {
        $message = $_SESSION['wpsqt'][$pollName]['details']['finish_message'];
        $message = $objTokens->doReplacement($message);
        echo nl2br($message);
    } else {
        echo '<h2>';
        _e('Thank you for taking the poll.', 'wp-survey-and-quiz-tool');
        echo '</h2>';
    }
}
 /**
  * Checks to see if the singleton is working and if it's holding the 
  * tokens we expect it to have.
  * 
  * @since 2.0
  */
 public function testSingleton()
 {
     $objTokens = Wpsqt_Tokens::getTokenObject();
     $descriptionHtml = "<ul>";
     $descriptionHtml .= "<li><strong>%USER_NAME%</strong> - The name of the user who has taken the quiz or survey.</li>";
     $descriptionHtml .= "<li><strong>%QUIZ_NAME%</strong> - The name of the quiz that has been taken, <strong>same as %SURVEY_NAME%</strong>.</li>";
     $descriptionHtml .= "<li><strong>%SURVEY_NAME%</strong> - The name of the survey that has been taken, <strong>same as %QUIZ_NAME%</strong>.</li>";
     $descriptionHtml .= "<li><strong>%DATE_EU%</strong> - The date the quiz or survey was taken in EU format.</li>";
     $descriptionHtml .= "<li><strong>%DATE_US%</strong> - The date the quiz or survey was taken in US format.</li>";
     $descriptionHtml .= "<li><strong>%SCORE%</strong> - Score gained in quiz, only works if automarking is enabled.</li>";
     $descriptionHtml .= "<li><strong>%RESULT_URL%</strong> - A link to view the results in the dashboard.</li>";
     $descriptionHtml .= "<li><strong>%DATETIME_EU%</strong> - The date and time the quiz or survey was taken in EU format.</li>";
     $descriptionHtml .= "<li><strong>%DATETIME_US%</strong> - The date and time the quiz or survey was taken in US format.</li>";
     $descriptionHtml .= "<li><strong>%IP_ADDRESS%</strong> - The IP address of the user who has taken the quiz or survey.</li>";
     $descriptionHtml .= "<li><strong>%HOSTNAME%</strong> - The hostname of the IP address of the user who has taken the quiz or survey.</li>";
     $descriptionHtml .= "<li><strong>%USER_AGENT%</strong> - The user agent of the user who has taken the quiz or survey.</li>";
     $descriptionHtml .= "</ul>";
     $this->assertEquals($descriptionHtml, $objTokens->getDescriptions(), "The html doesn't match what was expected");
 }
Exemple #8
0
 public function process()
 {
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         update_option("wpsqt_number_of_items", $_POST['wpsqt_items']);
         update_option("wpsqt_email_role", $_POST['wpsqt_email_role']);
         update_option("wpsqt_required_role", $_POST['wpsqt_required_role']);
         update_option("wpsqt_email_template", $_POST['wpsqt_email_template']);
         update_option("wpsqt_chart_bg", $_POST['wpsqt_chart_bg']);
         update_option("wpsqt_chart_colour", $_POST['wpsqt_chart_colour']);
         update_option("wpsqt_chart_width", $_POST['wpsqt_chart_width']);
         update_option("wpsqt_chart_height", $_POST['wpsqt_chart_height']);
         update_option("wpsqt_chart_text_colour", $_POST['wpsqt_chart_text_colour']);
         update_option("wpsqt_chart_text_size", $_POST['wpsqt_chart_text_size']);
         update_option("wpsqt_chart_abbreviation", $_POST['wpsqt_chart_abbreviation']);
         update_option("wpsqt_support_us", $_POST['wpsqt_support_us']);
         update_option("wpsqt_from_email", $_POST['wpsqt_from_email']);
         update_option("wpsqt_contact_email", $_POST['wpsqt_email']);
         update_option("wpsqt_docraptor_api", $_POST['wpsqt_docraptor_api']);
         update_option("wpsqt_pdf_template", $_POST['wpsqt_pdf_template']);
         // Update the capabilities to all the roles that are allowed
         // Remove the cap from all roles
         global $wp_roles;
         foreach ($wp_roles->role_names as $role => $name) {
             $roleDef = get_role($role);
             $roleDef->remove_cap('wpsqt-manage');
         }
         // Apply the cap only to roles allowed
         switch ($_POST['wpsqt_required_role']) {
             case 'subscriber':
                 $role = get_role('subscriber');
                 $role->add_cap('wpsqt-manage');
             case 'contributor':
                 $role = get_role('contributor');
                 $role->add_cap('wpsqt-manage');
             case 'author':
                 $role = get_role('author');
                 $role->add_cap('wpsqt-manage');
             case 'editor':
                 $role = get_role('editor');
                 $role->add_cap('wpsqt-manage');
             case 'administrator':
                 $role = get_role('administrator');
                 $role->add_cap('wpsqt-manage');
         }
     }
     $this->_pageVars['objTokens'] = Wpsqt_Tokens::getTokenObject();
     $this->_pageVars['numberOfItems'] = get_option("wpsqt_number_of_items");
     $this->_pageVars['emailRole'] = get_option("wpsqt_email_role");
     $this->_pageVars['requiredRole'] = get_option("wpsqt_required_role");
     $this->_pageVars['emailTemplate'] = get_option("wpsqt_email_template");
     $this->_pageVars['chartBg'] = get_option("wpsqt_chart_bg");
     $this->_pageVars['chartColour'] = get_option("wpsqt_chart_colour");
     $this->_pageVars['chartWidth'] = get_option("wpsqt_chart_width");
     $this->_pageVars['chartHeight'] = get_option("wpsqt_chart_height");
     $this->_pageVars['chartTextColour'] = get_option("wpsqt_chart_text_colour");
     $this->_pageVars['chartTextSize'] = get_option("wpsqt_chart_text_size");
     $this->_pageVars['chartAbbreviation'] = get_option("wpsqt_chart_abbreviation");
     $this->_pageVars['supportUs'] = get_option("wpsqt_support_us");
     $this->_pageVars['fromEmail'] = get_option("wpsqt_from_email");
     $this->_pageVars['email'] = get_option("wpsqt_contact_email");
     $this->_pageVars['docraptorApi'] = get_option("wpsqt_docraptor_api");
     $this->_pageVars['pdfTemplate'] = get_option("wpsqt_pdf_template");
     $this->_pageView = "admin/misc/options.php";
 }