예제 #1
0
 /**
  * Saving mail template settings
  */
 public static function save_mail_settings()
 {
     // If there is nothing, do noting
     if (!array_key_exists('questions_settings_save', $_POST)) {
         return;
     }
     // Verifying nonce
     if (!isset($_POST['questions_save_settings_field']) || !wp_verify_nonce($_POST['questions_save_settings_field'], 'questions_save_settings')) {
         return;
     }
     update_option('questions_thankyou_participating_subject_template', $_POST['questions_thankyou_participating_subject_template']);
     update_option('questions_invitation_subject_template', qu_prepare_post_data($_POST['questions_invitation_subject_template']));
     update_option('questions_reinvitation_subject_template', qu_prepare_post_data($_POST['questions_reinvitation_subject_template']));
     update_option('questions_thankyou_participating_text_template', qu_prepare_post_data($_POST['questions_thankyou_participating_text_template']));
     update_option('questions_invitation_text_template', qu_prepare_post_data($_POST['questions_invitation_text_template']));
     update_option('questions_reinvitation_text_template', qu_prepare_post_data($_POST['questions_reinvitation_text_template']));
     update_option('questions_mail_from_name', qu_prepare_post_data($_POST['questions_mail_from_name']));
     update_option('questions_mail_from_email', $_POST['questions_mail_from_email']);
 }
예제 #2
0
 /**
  * Processing entered data
  * @since 1.0.0
  */
 public function process_response()
 {
     global $questions_survey_id;
     // Form ID was posted or die
     if (!array_key_exists('questions_id', $_POST)) {
         return;
     }
     $questions_survey_id = $_POST['questions_id'];
     // WP Nonce Check
     if (!wp_verify_nonce($_POST['_wpnonce'], 'questions-' . $questions_survey_id)) {
         return;
     }
     // Survey exists or die
     if (!qu_form_exists($questions_survey_id)) {
         return;
     }
     // Checking restrictions
     if (TRUE !== $this->check_restrictions($questions_survey_id)) {
         return;
     }
     // Setting up session if not exists
     if (!isset($_SESSION)) {
         session_start();
     }
     // If session has data, get it!
     if (isset($_SESSION['questions_response'])) {
         $saved_response = $_SESSION['questions_response'][$questions_survey_id];
     }
     do_action('questions_before_process_response', $_POST);
     $response = array();
     $this->finished = FALSE;
     // Getting data of posted step
     $survey_response = array();
     if (array_key_exists('questions_response', $_POST)) {
         $survey_response = $_POST['questions_response'];
     }
     $survey_actual_step = (int) $_POST['questions_actual_step'];
     // Validating response values and setting up error variables
     $this->validate_response($questions_survey_id, $survey_response, $survey_actual_step);
     // Adding / merging Values to response var
     if (isset($saved_response)) {
         // Replacing old values by key
         if (is_array($survey_response) && count($survey_response) > 0) {
             foreach ($survey_response as $key => $answer) {
                 $saved_response[$key] = qu_prepare_post_data($answer);
             }
         }
         $response = $saved_response;
     } else {
         $response = $survey_response;
     }
     $response = apply_filters('questions_process_response', $response);
     // Storing values in Session
     $_SESSION['questions_response'][$questions_survey_id] = $response;
     $this->save_response();
     do_action('questions_after_process_response', $_POST);
 }
예제 #3
0
 /**
  * Saving data
  *
  * @param int $form_id
  * @since 1.0.0
  */
 public static function save_form($form_id)
 {
     global $questions_global, $wpdb;
     if (!array_key_exists('questions', $_REQUEST)) {
         return;
     }
     if (array_key_exists('questions-duplicate-survey', $_REQUEST)) {
         return;
     }
     if (wp_is_post_revision($form_id)) {
         return;
     }
     if (!array_key_exists('post_type', $_POST)) {
         return;
     }
     if ('questions' != $_POST['post_type']) {
         return;
     }
     $survey_elements = $_POST['questions'];
     $survey_deleted_formelements = $_POST['questions_deleted_formelements'];
     $survey_deleted_answers = $_POST['questions_deleted_answers'];
     $survey_participiant_restrictions = $_POST['questions_participiants_restrictions_select'];
     $survey_show_results = $_POST['show_results'];
     $questions_participiants = $_POST['questions_participiants'];
     $start_date = $_POST['start_date'];
     $end_date = $_POST['end_date'];
     /**
      * Saving Restrictions
      */
     update_post_meta($form_id, 'participiant_restrictions', $survey_participiant_restrictions);
     /**
      * Saving if results have to be shown after participating
      */
     update_post_meta($form_id, 'show_results', $survey_show_results);
     /**
      * Saving start and end date
      */
     update_post_meta($form_id, 'start_date', $start_date);
     update_post_meta($form_id, 'end_date', $end_date);
     $survey_deleted_formelements = explode(',', $survey_deleted_formelements);
     /**
      * Deleting deleted answers
      */
     if (is_array($survey_deleted_formelements) && count($survey_deleted_formelements) > 0) {
         foreach ($survey_deleted_formelements as $deleted_question) {
             $wpdb->delete($questions_global->tables->questions, array('id' => $deleted_question));
             $wpdb->delete($questions_global->tables->answers, array('question_id' => $deleted_question));
         }
     }
     $survey_deleted_answers = explode(',', $survey_deleted_answers);
     /*
      * Deleting deleted answers
      */
     if (is_array($survey_deleted_answers) && count($survey_deleted_answers) > 0) {
         foreach ($survey_deleted_answers as $deleted_answer) {
             $wpdb->delete($questions_global->tables->answers, array('id' => $deleted_answer));
         }
     }
     /*
      * Saving elements
      */
     foreach ($survey_elements as $key => $survey_question) {
         if ('widget_formelement_XXnrXX' == $key) {
             continue;
         }
         $question_id = (int) $survey_question['id'];
         $question = '';
         $sort = (int) $survey_question['sort'];
         $type = $survey_question['type'];
         if (array_key_exists('question', $survey_question)) {
             $question = qu_prepare_post_data($survey_question['question']);
         }
         $answers = array();
         $settings = array();
         if (array_key_exists('answers', $survey_question)) {
             $answers = $survey_question['answers'];
         }
         if (array_key_exists('settings', $survey_question)) {
             $settings = $survey_question['settings'];
         }
         // Saving question
         if ('' != $question_id) {
             // Updating if question already exists
             $wpdb->update($questions_global->tables->questions, array('question' => $question, 'sort' => $sort, 'type' => $type), array('id' => $question_id));
         } else {
             // Adding new question
             $wpdb->insert($questions_global->tables->questions, array('questions_id' => $form_id, 'question' => $question, 'sort' => $sort, 'type' => $type));
             $question_id = $wpdb->insert_id;
         }
         do_action('questions_save_form_after_saving_question', $survey_question, $question_id);
         /*
          * Saving answers
          */
         if (is_array($answers) && count($answers) > 0) {
             foreach ($answers as $answer) {
                 $answer_id = (int) $answer['id'];
                 $answer_text = qu_prepare_post_data($answer['answer']);
                 $answer_sort = (int) $answer['sort'];
                 $answer_section = '';
                 if (array_key_exists('section', $answer)) {
                     $answer_section = $answer['section'];
                 }
                 if ('' != $answer_id) {
                     $wpdb->update($questions_global->tables->answers, array('answer' => $answer_text, 'section' => $answer_section, 'sort' => $answer_sort), array('id' => $answer_id));
                 } else {
                     $wpdb->insert($questions_global->tables->answers, array('question_id' => $question_id, 'answer' => $answer_text, 'section' => $answer_section, 'sort' => $answer_sort));
                     $answer_id = $wpdb->insert_id;
                 }
                 do_action('questions_save_form_after_saving_answer', $survey_question, $answer_id);
             }
         }
         /*
          * Saving question settings
          */
         if (is_array($settings) && count($settings) > 0) {
             foreach ($settings as $name => $setting) {
                 $sql = $wpdb->prepare("SELECT COUNT(*) FROM {$questions_global->tables->settings} WHERE question_id = %d AND name = %s", $question_id, $name);
                 $count = $wpdb->get_var($sql);
                 if ($count > 0) {
                     $wpdb->update($questions_global->tables->settings, array('value' => qu_prepare_post_data($settings[$name])), array('question_id' => $question_id, 'name' => $name));
                 } else {
                     $wpdb->insert($questions_global->tables->settings, array('name' => $name, 'question_id' => $question_id, 'value' => qu_prepare_post_data($settings[$name])));
                 }
             }
         }
     }
     $questions_participiant_ids = explode(',', $questions_participiants);
     $sql = "DELETE FROM {$questions_global->tables->participiants} WHERE survey_id = %d";
     $sql = $wpdb->prepare($sql, $form_id);
     $wpdb->query($sql);
     if (is_array($questions_participiant_ids) && count($questions_participiant_ids) > 0) {
         foreach ($questions_participiant_ids as $user_id) {
             $wpdb->insert($questions_global->tables->participiants, array('survey_id' => $form_id, 'user_id' => $user_id));
         }
     }
     do_action('questions_save_form', $form_id);
     // Preventing duplicate saving
     remove_action('save_post', array(__CLASS__, 'save_form'), 50);
 }