*
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
include_once $_SERVER['DOCUMENT_ROOT'] . "/include/dbconnopen.php";
include_once $_SERVER['DOCUMENT_ROOT'] . "/core/include/setup_user.php";
user_enforce_has_access($Bickerdike_id);
include "../../header.php";
include "../header.php";
include "../classes/user.php";
$user = new Bickerdike_User();
$user->load_with_user_id($_GET['id']);
?>

<!--
Shows basic info, programs participated in, health data, surveys, and a graph of survey results.
-->


<script type="text/javascript">
    $(document).ready(function() {
        $('#participants_selector').addClass('selected');
        $('.edit_space').hide();
        $("a.add_new").hover(function() {
            $(this).addClass("selected");
        }, function() {
include $_SERVER['DOCUMENT_ROOT'] . "/include/dbconnopen.php";
include $_SERVER['DOCUMENT_ROOT'] . "/core/include/setup_user.php";
user_enforce_has_access($Bickerdike_id, $DataEntryAccess);
/*Checks so that a person doesn't have two pre surveys for the same program (for example).
 */
/*First checks whether the survey is pre, post, or later.*/
if ($_POST['type'] == 1) {
    $type = 'Pre';
} elseif ($_POST['type'] == 2) {
    $type = 'Post';
} elseif ($_POST['type'] == 3) {
    $type = '3 months later';
}
/*then gets the user so that it can use his/her name in the response.*/
include "../classes/user.php";
$user = new Bickerdike_User();
$user->load_with_user_id($_POST['user']);
/*then gets the program so that it can use its name in the response.*/
include "../classes/program.php";
$program = new Program();
$program->load_with_program_id($_POST['program']);
/*finds surveys that match type, user, and program (if any)*/
include "../include/dbconnopen.php";
$user_sqlsafe = mysqli_real_escape_string($cnnBickerdike, $_POST['user']);
$program_sqlsafe = mysqli_real_escape_string($cnnBickerdike, $_POST['program']);
$type_sqlsafe = mysqli_real_escape_string($cnnBickerdike, $_POST['type']);
$check_duplicate_sqlsafe = "SELECT COUNT(Participant_Survey_ID) FROM Participant_Survey_Responses WHERE User_ID='" . $user_sqlsafe . "'\r\n    AND Program_ID='" . $program_sqlsafe . "' AND Pre_Post_Late='" . $type_sqlsafe . "'";
$is_duplicate = mysqli_query($cnnBickerdike, $check_duplicate_sqlsafe);
$duplicate = mysqli_fetch_row($is_duplicate);
/*if surveys exist that meet those conditions, issue a warning:*/
if ($duplicate[0] > 0) {
    ?>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#participants_selector').addClass('selected');
        });
    </script>

    <div class="content_wide">
        <h3>Edit Survey Information</h3><hr/><br/>

        <?php 
    /*
     * Get all programs the user was involved with, in case the program was entered incorrectly:
     */
    include "../classes/user.php";
    $user = new Bickerdike_User();
    $user->load_with_user_id($response['User_ID']);
    $programs = $user->get_programs();
    ?>
        <a href="user_profile.php?id=<?php 
    echo $response['User_ID'];
    ?>
">Return to user profile</a><br/>
        Program in which survey was filled out: <select id="program_id">
            <option value="">-----</option>
            <?php 
    //list of all programs the surveyed person has been listed as a participant in:
    while ($program = mysqli_fetch_array($programs)) {
        ?>
                <option value="<?php 
        echo $program['Program_ID'];
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
include_once $_SERVER['DOCUMENT_ROOT'] . "/include/dbconnopen.php";
include_once $_SERVER['DOCUMENT_ROOT'] . "/core/include/setup_user.php";
user_enforce_has_access($Bickerdike_id);
include "../../header.php";
include "../header.php";
include "../include/datepicker.php";
$_GET['user'];
include "../classes/user.php";
$user = new Bickerdike_User();
$user->load_with_user_id($_GET['user']);
?>

<!--Add a new survey!-->

<script type="text/javascript">
    $(document).ready(function() {
        $('#parent_survey').hide();
        $('#adult_survey').hide();
        $('#youth_survey').hide();
        $('#participants_selector').addClass('selected');
    });

</script>