<commit_before><?php

require_once('../header.php');

function getSurvey($id) {
  $db = new Database();
  $db->query('SELECT * FROM surveys WHERE id = :id');
  $db->bind(':id', $id);
  return $db->single();
}

function getQuestions($id) {
  $db = new Database();
  $db->query('SELECT * FROM questions WHERE survey_id = :survey_id');
  $db->bind(':survey_id', $id);
  return $db->resultset();
}

function getStudents($id) {
  $db = new Database();
  $db->query('SELECT * FROM students WHERE survey_id = :survey_id');
  $db->bind(':survey_id', $id);
  return $db->resultset();
}

function getModules($id) {
  $db = new Database();
  $db->query('SELECT * FROM modules WHERE survey_id = :survey_id');
  $db->bind(':survey_id', $id);
  return $db->resultset();
}

$survey = getSurvey($_GET['id']);

?>

<div class="page-header">
<h2><?php echo $survey['title'] ?> <span class="small"><?php echo $survey['subtitle'] ?></span>
<a href="delete?id=<?php echo $survey['id']; ?>" class="btn btn-danger pull-right">Delete Survey</a></h2>
</div>

<div role="tabpanel">

  <ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="#questions" aria-controls="questions" role="tab" data-toggle="tab">Questions</a></li>
    <li role="presentation"><a href="#students" aria-controls="students" role="tab" data-toggle="tab">Students</a></li>
    <li role="presentation"><a href="#modules" aria-controls="modules" role="tab" data-toggle="tab">Modules</a></li>
  </ul>

  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="questions">
      <?php
        $questions = getQuestions($survey['id']);
      ?>
      <h2>Survey Questions <span class="small">(Once per questionnaire)</span></h2>
      <table id="survey-question-table" class="table">
        <thead>
          <tr>
            <th>Question Text (en)</th>
            <th>Question Text (cy)</th>
          </tr>
        </thead>
        <tbody>
          <?php foreach ($questions as $question) { ?>
          <tr class="question-table-row">
            <td><?php echo $question['text_en']; ?></td>
            <td><?php echo $question['text_cy']; ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>

      <h2>Repeated Questions <span class="small">(Repeated every module)</span></h2>
      <table id="repeated-question-table" class="table">
        <thead>
          <tr>
            <th>Question Text (en)</th>
            <th>Question Text (cy)</th>
          </tr>
        </thead>
        <tbody>
          <?php foreach ($questions as $question) { ?>
          <tr class="question-table-row">
            <td><?php echo $question['text_en']; ?></td>
            <td><?php echo $question['text_cy']; ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>

      <h2>Module Specific Questions <span class="small">(Ask a specific question)</span></h2>
      <table id="module-question-table" class="table">
        <thead>
          <tr>
            <th>Module</th>
            <th>Question Text (en)</th>
            <th>Question Text (cy)</th>
          </tr>
        </thead>
        <tbody>
          <?php foreach ($questions as $question) { ?>
          <tr class="question-table-row">
            <td><?php echo $question['module']; ?></td>
            <td><?php echo $question['text_en']; ?></td>
            <td><?php echo $question['text_cy']; ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>
    </div>
    <div role="tabpanel" class="tab-pane" id="students">
      <h2>Students</h2>
      <ul>
      <?php
      $students = getStudents($survey['id']);
      foreach ($students as $student) {
        echo '<li>'.$student['token'].' - '.$student['aber_id'].'</li>';
      } ?>
      </ul>
    </div>
    <div role="tabpanel" class="tab-pane" id="modules">
      <h2>Modules</h2>
      <ul>
      <?php
      $modules = getModules($survey['id']);
      foreach ($modules as $module) {
        echo '<li>'.$module['module_code'].' - '.$module['title'].'</li>';
      } ?>
      </ul>
    </div>
  </div>

</div>

<?php require_once('../footer.php'); ?>
<commit_msg>Fix question arrays<commit_after><?php

require_once('../header.php');

function getSurvey($id) {
  $db = new Database();
  $db->query('SELECT * FROM surveys WHERE id = :id');
  $db->bind(':id', $id);
  return $db->single();
}

function getQuestions($id, $module = null) {
  $db = new Database();
  if ($module != null) {
    $db->query('SELECT * FROM questions WHERE survey_id = :survey_id AND module = :module');
    $db->bind(':module', $module);
  } else {
    $db->query('SELECT * FROM questions WHERE survey_id = :survey_id AND module IS NULL');
  }
  $db->bind(':survey_id', $id);
  return $db->resultset();
}

function getStudents($id) {
  $db = new Database();
  $db->query('SELECT * FROM students WHERE survey_id = :survey_id');
  $db->bind(':survey_id', $id);
  return $db->resultset();
}

function getModules($id) {
  $db = new Database();
  $db->query('SELECT * FROM modules WHERE survey_id = :survey_id');
  $db->bind(':survey_id', $id);
  return $db->resultset();
}

$survey = getSurvey($_GET['id']);

?>

<div class="page-header">
<h2><?php echo $survey['title'] ?> <span class="small"><?php echo $survey['subtitle'] ?></span>
<a href="delete?id=<?php echo $survey['id']; ?>" class="btn btn-danger pull-right">Delete Survey</a></h2>
</div>

<div role="tabpanel">

  <ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="#questions" aria-controls="questions" role="tab" data-toggle="tab">Questions</a></li>
    <li role="presentation"><a href="#students" aria-controls="students" role="tab" data-toggle="tab">Students</a></li>
    <li role="presentation"><a href="#modules" aria-controls="modules" role="tab" data-toggle="tab">Modules</a></li>
  </ul>

  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="questions">
      <?php $questions_global = getQuestions($survey['id'], null); ?>
      <h2>Survey Questions <span class="small">(Once per questionnaire)</span></h2>
      <table id="survey-question-table" class="table">
        <thead>
          <tr>
            <th>Question Text (en)</th>
            <th>Question Text (cy)</th>
          </tr>
        </thead>
        <tbody>
          <?php foreach ($questions_global as $question) { ?>
          <tr class="question-table-row">
            <td><?php echo $question['text_en']; ?></td>
            <td><?php echo $question['text_cy']; ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>

      <?php $questions_repeated = getQuestions($survey['id'], '0'); ?>
      <h2>Repeated Questions <span class="small">(Repeated every module)</span></h2>
      <table id="repeated-question-table" class="table">
        <thead>
          <tr>
            <th>Question Text (en)</th>
            <th>Question Text (cy)</th>
          </tr>
        </thead>
        <tbody>
          <?php foreach ($questions_repeated as $question) { ?>
          <tr class="question-table-row">
            <td><?php echo $question['text_en']; ?></td>
            <td><?php echo $question['text_cy']; ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>

      <h2>Module Specific Questions <span class="small">(Ask a specific question)</span></h2>
      <table id="module-question-table" class="table">
        <thead>
          <tr>
            <th>Module</th>
            <th>Question Text (en)</th>
            <th>Question Text (cy)</th>
          </tr>
        </thead>
        <tbody>
          <?php
          $modules = getModules($survey['id']);
          foreach ($modules as $module) {
            $questions_module = getQuestions($survey['id'], $module['module_code']);
            foreach ($questions_module as $question) { ?>
            <tr class="question-table-row">
              <td><?php echo $question['module']; ?></td>
              <td><?php echo $question['text_en']; ?></td>
              <td><?php echo $question['text_cy']; ?></td>
            </tr>
            <?php }
            } ?>
        </tbody>
      </table>
    </div>
    <div role="tabpanel" class="tab-pane" id="students">
      <h2>Students</h2>
      <ul>
      <?php
      $students = getStudents($survey['id']);
      foreach ($students as $student) {
        echo '<li>'.$student['token'].' - '.$student['aber_id'].'</li>';
      } ?>
      </ul>
    </div>
    <div role="tabpanel" class="tab-pane" id="modules">
      <h2>Modules</h2>
      <ul>
      <?php
      foreach ($modules as $module) {
        echo '<li>'.$module['module_code'].' - '.$module['title'].'</li>';
      } ?>
      </ul>
    </div>
  </div>

</div>

<?php require_once('../footer.php'); ?>

{'fraction_non_alphanumeric': 0.21313901855857909, 'fraction_numerical': 0.002846407833314357, 'mean_word_length': 2.611842105263158, 'pattern_counts': {'":': 0, '<': 274, '<?xml version=': 0, '>': 300, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4647530', 'n_tokens_mistral': 2889, 'n_tokens_neox': 2872, 'n_words': 603}