<?php

/*  Alternate WebKit
(C) 2012-2014 by Alternate Tools
-----------------------------------------------------

File:         list_surveyresults.php
Description:  Administrative overview of all survey results

*/

    include "../modules/class_survey.php";
    include "../modules/class_surveylist.php";
    include "../modules/mod_admin.php";


    // Check privileges
    check_login();
    if (user_is_customer() == true)
    {
        log_out();
        return;
    }
    if (user_is_reporter() == true || isset ($_POST['surl_Cancel']))
    {
        header ("location: " . $ADMIN_MAIN_SITE);
        return;
    }

    // Delete survey result?
    if (isset ($_POST['surl_DeleteSurveyResult']))
    {
        header ('Location: ' . $ADMIN_MODIFY_SURVEYRESULTS_SITE . '?id=' . $_POST['surl_SurveyResultId'] . '&action=delete');
        return;
    }

    // Display
    print_admin_header(get_translation('admin_surveyl_head'), true, get_translation('admin_login_logout'), $ADMIN_HELP_FILE . '#n1-6', true, get_translation('admin_backtomain'));
    $sur = new cSurvey;
    $surList = new cSurveyList;

    $sur->SetFolder($SURVEY_FOLDER);
    $surList->SetFolder($SURVEY_FOLDER);
    $surList->LoadSurveyList();

    $surList->SortByDate(false);
    $listOfSurveyResults = $surList->GetSurveyList();

    // No entries?
    if (count($listOfSurveyResults) < 1)
        echo_r ('<p>&nbsp;' . get_translation('admin_noentries') . '</p>');
    for ($d = 0; $d < count($listOfSurveyResults); $d ++)
    {
        $sur->LoadSurveyFromId($listOfSurveyResults[$d]);

        echo_r('<hr>');
        echo_r('<table width="100%" border="0">');
        echo_r('  <tr>');
        echo_r('    <td width="90%">');
        echo_r('    <table width="100%" border="0">');
        echo_r('      <tr>');
        echo_r('        <td width="50%">');
        echo_r('       ' . get_translation('admin_survey_id') . ': ' . $sur->GetId() . '<br>');
        echo_r('       ' . get_translation('admin_survey_date') . ': ' . $sur->GetDate() . '<br>');
        echo_r('       ' . get_translation('admin_survey_title') . ': ' . $sur->GetTitle() . '<br>');
        echo_r('       <b>' . get_translation('admin_survey_question') . ': ' . $sur->GetQuestion() . '</b><br>');
        echo_r('       ' . get_translation('admin_survey_answer') . ': ' . $sur->GetSelectedOption() . '<br>');
        echo_r('        </td>');
        echo_r('        <td width="50%">');
        $inputNames = explode(";", $sur->GetInputNames());
        $inputValues = explode(";", $sur->GetInputValues());
        for ($i = 0; $i < count($inputNames); $i ++)
        {
            echo_r('       ' . $inputNames[$i] . ': ' . $inputValues[$i] . '<br>');
        }
        echo_r('        </td>');
        echo_r('      </tr>');
        echo_r('    </table>');

        echo_r('    </td>');
        echo_r('    <td width="10%">');
        echo_r('    <form method="post" action="">');
        echo_r('    <input type="hidden" value="' . $sur->GetId() . '" name="surl_SurveyResultId">  ');
        if (user_is_admin() == true)
            echo_r('    <input type="submit"  class="side_btn" value="' . get_translation('admin_delete') . '" name="surl_DeleteSurveyResult">  ');
        echo_r('    </form>');
        echo_r('    </td>');
        echo_r('  </tr>');
        echo_r('</table>');
    }
    print_bottom_links("surl_Cancel", get_translation('admin_ok'));

    print_admin_footer();
?>