wahlhelfer/admin/add-question.php
2014-05-15 18:49:45 +02:00

114 lines
3.3 KiB
PHP

<?php
include('../config/config.php');
include(ADMIN_HTML.'html.inc.php');
include(ADMIN_INCLUDES.'functions.php');
checkLoginAdmin();
if ( isset($_POST['submit']) )
{
if ( !empty($_POST['question']) )
{
$insQry = "INSERT INTO tbl_questions
SET
Heading = '".clean($_POST['title'])."',
Question = '".clean($_POST['question'])."'";
mysql_query($insQry);
}
$redirectUrl = 'view-questions.php';
$_SESSION['succesMessage'] = 4;
header("Location: $redirectUrl");
}
startHtml($title = "Add Question");
tophead($title);
leftNav();
?>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "simple",
// update validation status on change
onchange_callback: function(editor) {
tinyMCE.triggerSave();
$("#" + editor.id).valid();
}
});
$(function() {
var validator = $("#addQuestForm").submit(function() {
// update underlying textarea before submit validation
tinyMCE.triggerSave();
}).validate({
ignore: "",
rules: {
title: "required",
question: "required"
},
messages: {
title: "Enter question title.",
question: "Enter question."
},
errorPlacement: function(label, element) {
// position error label after generated textarea
if (element.is("textarea")) {
label.insertAfter(element.next());
} else {
label.insertAfter(element)
}
}
});
validator.focusInvalid = function() {
// put focus on tinymce on submit validation
if( this.settings.focusInvalid ) {
try {
var toFocus = $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []);
if (toFocus.is("textarea")) {
tinyMCE.get(toFocus.attr("id")).focus();
} else {
toFocus.filter(":visible").focus();
}
} catch(e) {
// ignore IE throwing errors when focusing hidden elements
}
}
}
});
</script>
<section id="main" class="column">
<article class="module width_full">
<header>
<h3>Add Question</h3>
</header>
<form name="addQuestForm" id="addQuestForm" action="" method="post">
<fieldset style="margin:15px">
<table width="100%">
<tr>
<td>
<label>Title</label>
<input type="text" name="title" id="title" />
</td>
</tr>
<tr>
<td>
<label>Question</label>
<span class="tinyMCE"><textarea id="question" name="question" rows="15" cols="80" style="width: 99%;float:left;"></textarea></span>
<label for="question" class="error" style="display:none;">Enter Question Description</label>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" id="submit" value="Add Record" />
<input type="button" name="cancel" id="cancel" value="Cancel" onclick="window.location='<?php echo ADMIN_URL;?>view-questions.php'" />
</td>
</tr>
</table>
</fieldset>
</form>
</article>
<div class="spacer"></div>
</section>
<?php
endHtml();
?>