Ejemplo n.º 1
0
 /**
  * Showing results of a question
  * @param array $atts Arguments which can be added to the shortcode
  * @return string $html HTML of results
  */
 public static function question_results($atts)
 {
     global $wpdb, $questions_global;
     $atts = shortcode_atts(array('id' => ''), $atts);
     if ('' == $atts['id']) {
         _e('Please enter a question id in the survey shortcode!', 'questions-locale');
         return;
     }
     $sql = $wpdb->prepare("SELECT questions_id FROM {$questions_global->tables->questions} WHERE id = %d", $atts['id']);
     $survey_id = $wpdb->get_var($sql);
     $survey = new Questions_Form($survey_id);
     $ordered_data = Questions_AbstractData::order_for_charting($survey->get_responses($atts['id'], FALSE));
     $html = '';
     foreach ($ordered_data['questions'] as $question_id => $question) {
         $html .= Questions_ChartCreator_Dimple::show_bars($question, $ordered_data['data'][$question_id]);
     }
     return $html;
 }
Ejemplo n.º 2
0
 /**
  * Survey form
  *
  * Creating form HTML
  *
  * @param int $form_id
  * @return string $html
  * @since 1.0.0
  */
 private function survey_form($form_id)
 {
     global $questions_response_errors, $questions_survey_id;
     $questions_survey_id = $form_id;
     $form = new Questions_Form($form_id);
     do_action('before_survey_form');
     if (array_key_exists('questions_next_step', $_POST) && 0 == count($questions_response_errors)) {
         $next_step = (int) $_POST['questions_next_step'];
     } else {
         if (array_key_exists('questions_actual_step', $_POST)) {
             $next_step = (int) $_POST['questions_actual_step'];
         } else {
             $next_step = 0;
         }
     }
     if (array_key_exists('questions_submission_back', $_POST)) {
         $next_step = (int) $_POST['questions_actual_step'] - 1;
     }
     $actual_step = $next_step;
     $html = '<form name="questions" id="questions" action="' . $_SERVER['REQUEST_URI'] . '" method="POST">';
     $html .= '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce('questions-' . $form_id) . '" />';
     $step_count = $form->get_step_count();
     if (0 != $step_count) {
         $html .= '<div class="questions-pagination">' . sprintf(__('Step <span class="questions-highlight-number">%d</span> of <span class="questions-highlight-number">%s</span>', 'questions-locale'), $actual_step + 1, $step_count + 1) . '</div>';
     }
     $elements = $this->get_elements($form_id, $actual_step);
     if (is_array($elements) && count($elements) > 0) {
         foreach ($elements as $element) {
             if (!$element->splits_form) {
                 $html .= $element->draw();
             } else {
                 $next_step += 1;
                 break;
             }
         }
     } else {
         return FALSE;
     }
     if (0 < $actual_step) {
         $html .= '<input type="submit" name="questions_submission_back" value="' . __('Previous Step', 'questions-locale') . '"> ';
     }
     if ($actual_step == $next_step) {
         $html .= '<input type="submit" name="questions_submission" value="' . __('Finish Survey', 'questions-locale') . '">';
     } else {
         $html .= '<input type="submit" name="questions_submission" value="' . __('Next Step', 'questions-locale') . '">';
     }
     $html .= '<input type="hidden" name="questions_next_step" value="' . $next_step . '" />';
     $html .= '<input type="hidden" name="questions_actual_step" value="' . $actual_step . '" />';
     $html .= '<input type="hidden" name="questions_id" value="' . $form_id . '" />';
     $html .= '</form>';
     return $html;
 }
Ejemplo n.º 3
0
 /**
  * Dublicating survey AJAX
  *
  * @since 1.0.0
  */
 public static function ajax_duplicate_form()
 {
     $form_id = $_REQUEST['form_id'];
     $form = get_post($form_id);
     if ('questions' != $form->post_type) {
         return;
     }
     $form = new Questions_Form($form_id);
     $new_form_id = $form->duplicate(TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE);
     $post = get_post($new_form_id);
     $response = array('survey_id' => $new_form_id, 'post_title' => $post->post_title, 'admin_url' => site_url('/wp-admin/post.php?post=' . $new_form_id . '&action=edit'));
     echo json_encode($response);
     die;
 }