Esempio n. 1
0
function acf_create_post($post_id)
{
    // bail early if not a new post
    if ($post_id !== 'new_post') {
        return $post_id;
    } elseif ($_SESSION['form_type'] == 'basic_form') {
        // vars
        $form_type = $_SESSION['form_type'];
        global $wpdb;
        $app_id = $wpdb->get_var("SELECT MAX(term_id) FROM {$wpdb->terms}");
        // create app id session variable
        $_SESSION['app_id'] = $app_id;
        // Create a new post
        $post = array('post_status' => 'publish', 'post_type' => $form_type, 'post_content' => 'This is my post.', 'post_title' => 'Basic Form for App ' . $app_id);
        // insert the post
        $post_id = wp_insert_post($post);
        // clean up the app id
        $app_ids = array($app_id);
        $app_ids = array_map('intval', $app_ids);
        $app_ids = array_unique($app_ids);
        // insert the newly created app taxonomy for this post
        wp_set_object_terms($post_id, $app_ids, 'app_name');
        //add the app to the developer if they are logged in
        if (isset($_SESSION['developer_id'])) {
            //
            wp_set_object_terms($_SESSION['developer_id'], $app_ids, 'app_name', true);
        } else {
        }
        // create basic form id session variable
        $_SESSION['basic_form_id'] = $post_id;
        // return the new ID
        return $post_id;
        // remove basic form session variable to prevent duplicates
        unset($_SESSION['form_type']);
    } else {
        //get current app id
        $app_id = $_SESSION['app_id'];
        $form_type = $_SESSION['form_type'];
        $form_name = form_name($form_type);
        // Create a new post
        $post = array('post_status' => 'publish', 'post_type' => $form_type, 'post_content' => 'This is my post.', 'post_title' => $form_name . ' Form for App ' . $app_id);
        // insert the post
        $post_id = wp_insert_post($post);
        //clean up the app id
        $app_ids = array($app_id);
        $app_ids = array_map('intval', $app_ids);
        $app_ids = array_unique($app_ids);
        //add the app to the equality form just created
        wp_set_object_terms($post_id, $app_ids, 'app_name');
        // return the new ID
        return $post_id;
    }
    //END CREATION OF ANY OTHER FORM POST
}
Esempio n. 2
0
   
	        
    <div class="container">
	    <div id="find-active" class="<?php 
echo $form;
?>
">
	     <?php 
yes_no_forms('your_app');
?>
	     
	    </div>
	    <div class="page-header">
        <h3>
          <?php 
echo form_name($form);
?>
          <h4></h4>
        </h3>
        <hr>
        
 <?php 
//if they want to enable the form you must update the basic qualifying questions.
if ($_GET['enable'] == 'enable') {
    update_basic_form($form);
}
//if safety form check for answered questions then give warning
if ($_GET['begin_safety']) {
    $begin_safety = 1;
} else {
    $begin_safety = count_single_form_answered($form, $tax_id);
Esempio n. 3
0
function form_pass_fail($type, $app_id, $page)
{
    // first check if form exists for app id
    $posts = get_posts(array('post_type' => $type, 'tax_query' => array(array('taxonomy' => 'app_name', 'field' => 'term_id', 'terms' => $app_id))));
    //set initial score to ZERO
    $score = 0;
    // now get the potential questions with answers
    $fields = get_field_objects($posts[0]->ID);
    //echo '<pre>'; print_r($posts); echo '</pre>';
    //this check should apply for all forms
    if (empty($posts)) {
        // 19991 represents incomplete for now
        $score = '199912';
    } elseif ($type == 'ps_form') {
        //check first question, decide what to do if NO
        if ($fields['ps_q1']['value'] == 'NO') {
            $score = 'not relevant';
        }
        foreach ($fields as $field) {
            switch ($field['value']) {
                case 'SELECT ANSWER':
                    $score = 19991;
                    break;
                case -999:
                    //all nos represent absolute fail
                    // -999 represents fail for now
                    $score = -999;
                    break;
                default:
                    // pass logic for Privacy and Security Only
                    $score = 1;
                    break;
            }
        }
    } elseif ($type == 'safety_form') {
        //check first question, decide what to do if NO
        if ($fields['safety_q1']['value'] == 'NO') {
            $score = 'not relevant';
        } elseif ($fields['safety_q6']['value'] == -999) {
            //this no represents absolute fail
            $score = -999;
        } else {
            foreach ($fields as $field) {
                if ($field['value'] == 'SELECT ANSWER') {
                    // 19991 represents incomplete for now
                    $score = 19990;
                }
            }
            if ($fields['safety_q2']['value'] != 'SELECT ANSWER') {
                $score = $score + $fields['safety_q2']['value'];
            }
            if ($fields['safety_q3']['value'] != 'SELECT ANSWER') {
                $score = $score + 1;
            }
            if ($fields['safety_q4']['value'] != 'SELECT ANSWER') {
                $score = $score + 1;
            }
            if ($fields['safety_q5']['value'] != 'SELECT ANSWER') {
                $score = $score + 1;
            }
            if ($fields['safety_q6']['value'] != 'SELECT ANSWER') {
                $score = $score + 1;
            }
        }
    } elseif ($type == 'io_form') {
        //check first question, decide what to do if NO
        if ($fields['io_q0']['value'] == 'NO') {
            $score = 'not relevant';
            //break;
        }
        foreach ($fields as $field) {
            switch ($field['value']) {
                case 'SELECT ANSWER':
                    $score = 19991;
                    break;
                default:
                    // pass logic for interoperability all transparent
                    // may need to change to add all questions
                    $score = 1;
                    break;
            }
        }
    } elseif ($type == 'od_form') {
        //check first question, decide what to do if NO
        if ($fields['od_q0']['value'] == 'NO') {
            $score = 'not relevant';
            //break;
        }
        if ($fields['od_q3']['value'] == -999) {
            //this no represents absolute fail
            $score = -999;
            break;
        }
        foreach ($fields as $field) {
            if ($field['value'] == 'SELECT ANSWER') {
                // 19991 represents incomplete for now
                $score = '19990';
            }
        }
        if ($fields['od_q2']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['od_q7']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['od_q1']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['od_q5']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['od_q6']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['od_q4']['value'] != 'SELECT ANSWER') {
            $score = $score + $fields['od_q2']['value'];
        }
    } elseif ($type == 'equality_form') {
        //check first question, decide what to do if NO
        foreach ($fields as $field) {
            switch ($field['value']) {
                case 'SELECT ANSWER':
                    $score = 19991;
                    break 2;
                case -999:
                    //all nos represent absolute fail
                    // -999 represents fail for now
                    $score = -999;
                    break 2;
                default:
                    // pass logic for Privacy and Security Only
                    $score = 1;
                    break 2;
            }
        }
    } elseif ($type == 'qu_form') {
        //check first question, decide what to do if NO
        $score = 0;
        foreach ($fields as $field) {
            switch ($field['value']) {
                case 'SELECT ANSWER':
                    $score = 19991;
                    break 1;
                case -999:
                    //all nos represent absolute fail
                    // -999 represents fail for now
                    $score = -999;
                    break 1;
                default:
                    // pass logic for Privacy and Security Only
                    $score = $score + $field['value'];
                    break 1;
            }
        }
    } elseif ($type == 'ts_form') {
        //check first question, decide what to do if NO
        $score = 0;
        foreach ($fields as $field) {
            switch ($field['value']) {
                case 'SELECT ANSWER':
                    $score = 19991;
                    break 1;
                case -999:
                    //all nos represent absolute fail
                    // -999 represents fail for now
                    $score = -999;
                    break 1;
                default:
                    // pass logic for tech stability Only
                    // do we need to add up the 1s
                    $score = $score + $field['value'];
                    break 1;
            }
        }
    } elseif ($type == 'eff_form') {
        foreach ($fields as $field) {
            if ($field['value'] == 'SELECT ANSWER') {
                // 19991 represents incomplete for now
                $score = 19990;
            }
            if ($field['value'] == -999) {
                //  represents automative fail
                $score = -999;
                break;
            }
        }
        if ($fields['eff_q1']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q3']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q5']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q7']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q9']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q12']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q14']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q16']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q18']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q20']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q23']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q25']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q27']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q28']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q30']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q32']['value'] != 'SELECT ANSWER') {
            $score = $score + 1;
        }
        if ($fields['eff_q2']['value'] != 'SELECT ANSWER') {
            $score = $score + $fields['eff_q2']['value'];
        }
        if ($fields['eff_q8']['value'] != 'SELECT ANSWER') {
            $score = $score + $fields['eff_q8']['value'];
        }
        if ($fields['eff_q22']['value'] != 'SELECT ANSWER') {
            $score = $score + $fields['eff_q24']['value'];
        }
        if ($fields['eff_q24']['value'] != 'SELECT ANSWER') {
            $score = $score + $fields['eff_q24']['value'];
        }
        if ($fields['eff_q26']['value'] != 'SELECT ANSWER') {
            $score = $score + $fields['eff_q26']['value'];
        }
        if ($fields['eff_q29']['value'] != 'SELECT ANSWER') {
            $score = $score + $fields['eff_q29']['value'];
        }
        if ($fields['eff_q31']['value'] != 'SELECT ANSWER') {
            $score = $score + $fields['eff_q31']['value'];
        }
    } else {
        //nothing for now until decide on final outcome
    }
    // last chance to check of form is relevant from Basic Form Answers
    // get form basic answer results
    $answers = get_posts(array('post_type' => 'basic_form', 'numberposts' => -1, 'tax_query' => array(array('taxonomy' => 'app_name', 'field' => 'id', 'terms' => $app_id))));
    // go through questions to turn forms on and off
    //The Safety Form
    if (get_field('basics_q2', $answers[0]->ID) == 'NO' && $type == 'safety_form') {
        $score = 'NOTNEEDED';
    }
    //The Interoperability Form
    if (get_field('basics_q4', $answers[0]->ID) == 'NO' && $type == 'io_form') {
        $score = 'NOTNEEDED';
    }
    //The Open Data Form
    if (get_field('basics_q5', $answers[0]->ID) == 'NO' && $type == 'od_form') {
        $score = 'NOTNEEDED';
    }
    //The Privacy & Security Form
    if (get_field('basics_q3', $answers[0]->ID) == 'NO' && $type == 'ps_form') {
        $score = 'NOTNEEDED';
    }
    // get thresholds to test with
    list($bs, $eh, $bp) = create_threasholds($type);
    switch ($score) {
        case $score == "NOTNEEDED":
            $level = 'Not relevant';
            $alert = 'alert-info';
            break;
        case $score > 5000:
            $alert = 'alert-warning';
            $text = 'You have not yet completed this section.';
            $level = 'Incomplete';
            $test = 1;
            break;
        case $score < 1:
            // any negative number at this point is a fail
            $alert = 'alert-danger';
            $text = 'Your app has failed evaluation for 1 or more reasons.  Please see red below to correct';
            $level = 'Failed';
            $test = -1;
            break;
        case $score >= $bs && $score < $eh:
            $alert = 'alert-success';
            $text = 'Your app has passed this section.';
            $level = 'Basic';
            $test = 2;
            break;
        case $score >= $eh && $score < $bp:
            $alert = 'alert-success';
            $text = 'Your app has passed this section.';
            $level = 'Enhanced';
            $test = 3;
            break;
        case $score >= $bp && $score < 2000:
            $alert = 'alert-success';
            $text = 'Your app has passed this section.';
            $level = 'Best Practice';
            $test = 4;
            break;
    }
    if ($page == 'single_form') {
        $out = '<div class="alert ' . $alert . '  "><h3> ' . $text . '</h3></div>';
        //echo '<h2>SCORE ';
        //echo $score;
        //echo '</h2>';
        echo $out;
    } elseif ($page == 'app_name') {
        $out = '<li class="list-group-item">';
        $out .= '<span class="badge ' . $alert . '">' . $level . '</span><b>';
        $out .= form_name($type);
        $out .= '</b></li>';
        echo $out;
    } elseif ($page == 'just_score') {
        return $test;
    }
}
Esempio n. 4
0
function form_post_key_exists(array $form)
{
    return post_key_exists(form_name($form));
}