Skip to content

Commit ce49139

Browse files
committed
Added possibility to delete multiple open questions
1 parent a33c07c commit ce49139

File tree

5 files changed

+84
-30
lines changed

5 files changed

+84
-30
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Version 2.8.0-alpha2 - 2012-
1111
- added new and improved frontend and backend user interface based on Twitter Bootstrap (Thorsten)
1212
- added improved advanced search in subcategories (Thorsten)
1313
- added possibility to close and delete open questions (Peter Caesar)
14+
- added possibility to delete multiple open questions (Thorsten)
1415
- added user control panel (Thorsten)
1516
- added support for Composer (Thorsten)
1617
- added online verification check (Thorsten, Florian)

phpmyfaq/admin/ajax.records.php

+21
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,25 @@
114114
print $PMF_LANG['err_NotAuth'];
115115
}
116116
break;
117+
118+
// delete open questions
119+
case 'delete_question':
120+
if ($permission['delquestion']) {
121+
122+
$checks = array(
123+
'filter' => FILTER_VALIDATE_INT,
124+
'flags' => FILTER_REQUIRE_ARRAY
125+
);
126+
$questionIds = PMF_Filter::filterInputArray(INPUT_POST, array('questions' => $checks));
127+
128+
if (!is_null($questionIds['questions'])) {
129+
foreach ($questionIds['questions'] as $questionId) {
130+
$faq->deleteQuestion((int)$questionId);
131+
}
132+
}
133+
print $PMF_LANG['ad_entry_delsuc'];
134+
} else {
135+
print $PMF_LANG['err_NotAuth'];
136+
}
137+
break;
117138
}

phpmyfaq/admin/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
case "saveentry": require_once 'record.save.php'; break;
321321
case "delentry": require_once 'record.delete.php'; break;
322322
case "delatt": require_once 'record.delatt.php'; break;
323-
case "question": require_once 'record.delquestion.php'; break;
323+
case "question": require_once 'record.questions.php'; break;
324324
case 'comments': require_once 'record.comments.php'; break;
325325
// news administraion
326326
case 'news':

phpmyfaq/admin/record.delquestion.php renamed to phpmyfaq/admin/record.questions.php

+56-25
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
exit();
2323
}
2424

25+
printf("<header><h2>%s</h2></header>", $PMF_LANG['msgOpenQuestions']);
26+
2527
if ($permission['delquestion']) {
2628

2729
$category = new PMF_Category($faqConfig, false);
2830
$category->setUser($current_admin_user);
2931
$category->setGroups($current_admin_groups);
3032
$date = new PMF_Date($faqConfig);
3133
$questionId = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
32-
$delete = PMF_Filter::filterInput(INPUT_GET, 'delete', FILTER_SANITIZE_STRING, 'no');
3334

3435
$toggle = PMF_Filter::filterInput(INPUT_GET, 'is_visible', FILTER_SANITIZE_STRING);
3536
if ($toggle == 'toggle') {
@@ -39,31 +40,32 @@
3940
}
4041
}
4142

42-
printf("<header><h2>%s</h2></header>", $PMF_LANG['msgOpenQuestions']);
43-
44-
if ($delete == 'yes') {
45-
$faq->deleteQuestion($questionId);
46-
printf('<p class="alert alert-success">%s</p>', $PMF_LANG['ad_entry_delsuc']);
47-
}
43+
print '<div id="returnMessage"></div>';
4844

4945
$openquestions = $faq->getAllOpenQuestions();
5046

5147
if (count($openquestions) > 0) {
5248
?>
53-
<table class="table table-striped">
54-
<thead>
55-
<tr>
56-
<th><?php print $PMF_LANG['ad_entry_author']; ?></th>
57-
<th><?php print $PMF_LANG['ad_entry_theme']; ?></th>
58-
<th><?php print $PMF_LANG['ad_entry_visibility']; ?>?</th>
59-
<th><?php print $PMF_LANG['ad_gen_delete']; ?>?</th>
60-
</tr>
61-
</thead>
62-
<tbody>
49+
<form id="questionSelection" name="questionSelection" method="post">
50+
<table class="table table-striped">
51+
<thead>
52+
<tr>
53+
<th></th>
54+
<th><?php print $PMF_LANG['ad_entry_author']; ?></th>
55+
<th><?php print $PMF_LANG['ad_entry_theme']; ?></th>
56+
<th colspan="2"><?php print $PMF_LANG['ad_entry_visibility']; ?>?</th>
57+
</tr>
58+
</thead>
59+
<tbody>
6360
<?php
6461
foreach ($openquestions as $question) {
6562
?>
6663
<tr>
64+
<td>
65+
<input id="questions[]"
66+
name="questions[]"
67+
value="<?php print $question['id']; ?>" type="checkbox" />
68+
</td>
6769
<td>
6870
<?php print $date->format(PMF_Date::createIsoDate($question['created'])); ?>
6971
<br />
@@ -72,20 +74,16 @@
7274
</a>
7375
</td>
7476
<td>
75-
<div id="PMF_openQuestionsCategory"><?php print $category->categoryName[$question['category_id']]['name'] ?></div>
77+
<strong><?php print $category->categoryName[$question['category_id']]['name'] ?></strong>
7678
<br />
7779
<?php print $question['question'] ?>
7880
</td>
7981
<td>
8082
<a href="?action=question&amp;id=<?php print $question['id']; ?>&amp;is_visible=toggle">
81-
<?php print (('Y' == $question['is_visible']) ? $PMF_LANG['ad_gen_no'] : $PMF_LANG['ad_gen_yes']); ?>
83+
<?php print ('Y' == $question['is_visible']) ? $PMF_LANG['ad_gen_no'] : $PMF_LANG['ad_gen_yes']; ?>
8284
</a>
8385
</td>
8486
<td>
85-
<a onclick="return confirm('<?php print $PMF_LANG['ad_user_del_3'] ?>'); return false;" href="?action=question&amp;id=<?php print $question['id']; ?>&amp;delete=yes">
86-
<?php print $PMF_LANG['ad_gen_delete']; ?>
87-
</a>
88-
<br />
8987
<?php if ($faqConfig->get('records.enableCloseQuestion') && $question['answer_id']) { ?>
9088
<a href="?action=editentry&amp;id=<?php print $question['answer_id']; ?>&amp;lang=<?php print $LANGCODE; ?>">
9189
<?php print $PMF_LANG['msg2answerFAQ']; ?>
@@ -101,8 +99,41 @@
10199
<?php
102100
}
103101
?>
104-
</tbody>
105-
</table>
102+
</tbody>
103+
</table>
104+
</form>
105+
106+
<p>
107+
<input class="btn-danger" id="submitDeleteQuestions" type="submit" name="submit"
108+
value="<?php print $PMF_LANG["ad_entry_delete"]; ?>" />
109+
</p>
110+
111+
<script type="text/javascript">
112+
/* <![CDATA[ */
113+
$('#submitDeleteQuestions').click(function() { deleteQuestions(); return false; });
114+
115+
function deleteQuestions()
116+
{
117+
var questions = $('#questionSelection').serialize();
118+
119+
$('#returnMessage').empty();
120+
$.ajax({
121+
type: 'POST',
122+
url: 'index.php?action=ajax&ajax=records&ajaxaction=delete_question',
123+
data: questions,
124+
success: function(msg) {
125+
$('#saving_data_indicator').html('<img src="images/indicator.gif" /> deleting ...');
126+
$('tr td input:checked').parent().parent().fadeOut('slow');
127+
$('#saving_data_indicator').fadeOut('slow');
128+
$('#returnMessage').
129+
html('<p class="alert alert-success">' + msg + '</p>');
130+
}
131+
});
132+
return false;
133+
}
134+
135+
/* ]]> */
136+
</script>
106137
<?php
107138
} else {
108139
print $PMF_LANG['msgNoQuestionsAvailable'];

phpmyfaq/inc/Faq.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -1615,17 +1615,18 @@ public function getLatest()
16151615
* @param integer $question_id
16161616
* @return boolean
16171617
*/
1618-
function deleteQuestion($question_id)
1618+
function deleteQuestion($questionId)
16191619
{
1620-
$query = sprintf('
1620+
$delete = sprintf('
16211621
DELETE FROM
16221622
%sfaqquestions
16231623
WHERE
16241624
id = %d',
16251625
SQLPREFIX,
1626-
$question_id);
1626+
$questionId
1627+
);
16271628

1628-
$this->_config->getDb()->query($query);
1629+
$this->_config->getDb()->query($delete);
16291630
return true;
16301631
}
16311632

0 commit comments

Comments
 (0)