Skip to content

Commit

Permalink
Merge pull request #46 from laposa/feature/survery-delete-entries
Browse files Browse the repository at this point in the history
Add delete entries
  • Loading branch information
norbertlaposa committed Sep 8, 2023
2 parents aa40f27 + 40b2fe3 commit f3ab1c6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
13 changes: 11 additions & 2 deletions controllers/bo/component/survey_detail.php
Expand Up @@ -13,16 +13,21 @@ class Onyx_Controller_Bo_Component_Survey_Detail extends Onyx_Controller_Bo_Comp
*/

public function mainAction() {

if (is_numeric($this->GET['id'])) $survey_id = $this->GET['id'];
else {
msg("Survey ID is not numeric", 'error');
return false;
}

require_once('models/education/education_survey.php');

$this->Survey = new education_survey();

if ($_SERVER['REQUEST_METHOD'] === "POST" && $_POST['action'] == 'delete-entries') {
$this->deleteEntries($survey_id);
return true;
}

$survey_detail = $this->Survey->getFullDetail($survey_id);

Expand Down Expand Up @@ -103,5 +108,9 @@ public function displayAnswer($answer_detail) {
$this->tpl->assign('ANSWER', $answer_detail);
$this->tpl->parse('content.question.answer_list.item');
}

public function deleteEntries($survey_id) {
$this->Survey->deleteEntries($survey_id);
}
}

13 changes: 13 additions & 0 deletions models/education/education_survey.php
Expand Up @@ -374,4 +374,17 @@ public function getAllResults($survey_id, $relation_subject = false)
} else return false;
}


public function deleteEntries($survey_id)
{
if (!is_numeric($survey_id)) return false;

$sql = "DELETE FROM education_survey_entry WHERE survey_id = $survey_id";

msg("Deleted entries for survey $survey_id");

$this->executeSql($sql);

return true;
}
}
16 changes: 16 additions & 0 deletions templates/bo/component/survey_detail.html
Expand Up @@ -2,7 +2,18 @@
<!-- BEGIN: content -->
{MESSAGES}
<div id="sub-content" class="two-column-page page survey-detail fibonacci-1-5">
<script type="text/javascript">

$(function() {
var form = document.querySelector('.delete-entries-form');
if (form) {
form.addEventListener("submit", function(e) {
return confirm("Are you sure you want to delete all entries?") ? true : e.preventDefault();
})
}
});

</script>
<div class="content">
<div class="page-wrapper">

Expand Down Expand Up @@ -73,6 +84,11 @@ <h2>{SURVEY.title|htmlspecialchars}</h2>
<a class="button add" title="Add new question" onclick="makeAjaxRequest('#sub-content', '/request/bo/component/survey_question_add~survey_id={SURVEY.id}~'); return false" href="#sub_content"><span>Add a New Question</span></a>
<a class="button edit" title="Edit survey - Update basic information" href="/backoffice/surveys/{SURVEY.id}/edit"><span>Edit Survey Properties</span></a>
<a class="button" href="/request/bo/export/csv_survey_entries?survey_id={SURVEY.id}"><span>Export {SURVEY.usage_count} Entries</span></a>
<form style="display: inline;" class="delete-entries-form" method="post">
<input type="hidden" name="csrf_token" value="{CSRF_TOKEN}" />
<input type="hidden" name="action" value="delete-entries">
<button type="submit" class="button remove" href="/request/bo/export/csv_survey_entries?survey_id={SURVEY.id}"><span>Delete entries</span></button>
</form>
</p>

</div>
Expand Down

0 comments on commit f3ab1c6

Please sign in to comment.