Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function add_frontend_scripts() {
- if( ! is_admin() ) {
- wp_register_style( 'custom-stylesheet1', plugins_url('/css/quiz-style.css', __FILE__) );
- wp_enqueue_script('jquery');
- wp_enqueue_style( 'custom-stylesheet1' );
- }
- }
- add_action('init', 'add_frontend_scripts');
- add_filter('the_content','folio3_survey');
- //Callback function
- function folio3_survey($content)
- {
- if ( isset( $_POST['question1'] )) {
- $_data = array(
- "questions" => array(1,2,3,4,5,6,7,8,9,10),
- "option" => array($_POST['question1'],$_POST['question2'],$_POST['question3'],$_POST['question4'],$_POST['question5'],$_POST['question6'],$_POST['question7'],$_POST['question8'],$_POST['question9'],$_POST['question10'])
- );
- ob_start();
- echo $content;
- $type_data = folio3_process_form($_data);
- $implode_type_data = implode(",", $type_data);
- $encode_implode_type_data = urlencode($implode_type_data);
- return ob_get_clean();
- }
- if (is_page( 'quiz' )) {
- global $wpdb;
- $randomFact = $wpdb->get_results( "SELECT * FROM folio3_survey_questions");
- $NumRows = count((array) $randomFact);
- $RandNum = rand(0, $NumRows);
- ob_start();
- echo $content;
- ?>
- <form method="post" class="not--started card" id="survey" action="" onsubmit="return validate()">
- <!-- Form Goes Here -->
- </form>
- <?php
- return ob_get_clean();
- }
- else {
- return $content;
- }
- }
- function folio3_process_form($_data)
- {
- global $wpdb;
- $sum_segment1=0;
- $sum_segment2=0;
- $sum_segment3=0;
- $sum_segment4=0;
- for($i=0; $i<10; $i++)
- {
- $randomFact = $wpdb->get_results( "SELECT * FROM folio3_survey_option_values WHERE question_id =". $_data['questions'][$i] ." AND `option` = ".$_data['option'][$i]);
- $sum_segment1= $sum_segment1 + $randomFact[0]->option_segment1_value;
- $sum_segment2= $sum_segment2 + $randomFact[0]->option_segment2_value;
- $sum_segment3= $sum_segment3 + $randomFact[0]->option_segment3_value;
- $sum_segment4= $sum_segment4 + $randomFact[0]->option_segment4_value;
- }
- $sum_segment1 = exp($sum_segment1 + (-1.674));
- $sum_segment2 = exp($sum_segment2 + (-0.489));
- $sum_segment3 = exp($sum_segment3 + (2.223));
- $sum_segment4 = exp($sum_segment4 + (-0.06));
- $probablity_segment1 = round((($sum_segment1/($sum_segment1+$sum_segment2+$sum_segment3+$sum_segment4)) * 100),0);
- $probablity_segment2 = round((($sum_segment2/($sum_segment1+$sum_segment2+$sum_segment3+$sum_segment4)) * 100),0);
- $probablity_segment3 = round((($sum_segment3/($sum_segment1+$sum_segment2+$sum_segment3+$sum_segment4)) * 100),0);
- $probablity_segment4 = round((($sum_segment4/($sum_segment1+$sum_segment2+$sum_segment3+$sum_segment4)) * 100),0);
- $type_data = array();
- if ($probablity_segment1 >= 34.38):
- $entrepreneur_type = "Explorer";
- $type_data['type'] = $entrepreneur_type;
- $type_data['url'] = "/explorer";
- goto end;
- elseif ($probablity_segment4 >= 39.06):
- $entrepreneur_type = "Driver";
- $type_data['type'] = $entrepreneur_type;
- $type_data['url'] = "/driver";
- goto end;
- elseif ($probablity_segment2 >= 50.00):
- $entrepreneur_type = "Crusader";
- $type_data['type'] = $entrepreneur_type;
- $type_data['url'] = "/crusader";
- goto end;
- else:
- $entrepreneur_type = "Captain";
- $type_data['type'] = $entrepreneur_type;
- $type_data['url'] = "/captain";
- endif;
- end:
- //Save to DB
- $gender = $_POST['gender'];
- $role = $_POST['role'];
- $revenue = $_POST['annual_revenue'];
- $industry = $_POST['work_your_company'];
- $email = $_POST['email'];
- $type = $type_data['type'];
- $url = $type_data['url'];
- $wpdb->insert( 'quiz_entries',
- array(
- 'gender' => $gender,
- 'email' => $email,
- 'role' => $role,
- 'revenue' => $revenue,
- 'industry' => $industry,
- 'type' => $type
- )
- );
- return $type_data;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement