264 lines
12 KiB
PHP
264 lines
12 KiB
PHP
|
<style>
|
||
|
form label.error,
|
||
|
#titleerr {
|
||
|
color: red;
|
||
|
font-size: 13px;
|
||
|
}
|
||
|
</style>
|
||
|
<main class="wraper responsive-width" id="main">
|
||
|
<div class="from-group">
|
||
|
<a href="<?php echo base_url() ?>admin/notifications"><button type="button" class="btn btn-dark btn-sm">Back</button></a>
|
||
|
</div>
|
||
|
<!-- admin template section -->
|
||
|
<div class="admin_tempblock">
|
||
|
<div class="admin_tempsec">
|
||
|
<div class="admin_sec">
|
||
|
<form action=" <?php echo base_url() ?>admin/notification_form" id="notificationForm" method="post">
|
||
|
<!-- <form action=" <?php echo base_url() ?>admin/notification_form" onSubmit="return notifyFormValidation(this, event)" method="post"> -->
|
||
|
<div class="subsec_sec">
|
||
|
<div class="subject_l w-50 subject_l_notifn subject_l_full_width">
|
||
|
<div class="subject_lsec">
|
||
|
<div class="subject_lhead">Send Notification</div>
|
||
|
<div class="subject_lformarea">
|
||
|
<div class="form-group notification_form-group">
|
||
|
<label for="">Title of Notifications*</label>
|
||
|
<input type="text" data-altName="Title of Notification" name="notification_title" class="form-control" placeholder="Enter title">
|
||
|
<div id="titleerr" style="display:none"></div>
|
||
|
</div>
|
||
|
<div class="form-group assign_subject notification_form-group">
|
||
|
<label>Send notification to*</label>
|
||
|
<select data-altName="Send Notification to" id="sendNotificationDropDown" name="notification_to" onchange="getNotificationData(this.value)" class="form-control">
|
||
|
<option selected disabled value="">Choose Options</option>
|
||
|
<option value="teacher">Send to Teacher</option>
|
||
|
<option value="student">Send to Student</option>
|
||
|
<option value="both">Send to Teacher & Student</option>
|
||
|
</select>
|
||
|
</div>
|
||
|
|
||
|
<div class="send_to_studnt commonNotifClass" id="send_student" style="display:none;">
|
||
|
<div class="form-group assign_subject notification_form-group">
|
||
|
<label>Student*</label>
|
||
|
<select data-altName="Student" id="studentDropDown" name="student_classroom" class="form-control" placeholder="Select Subject">
|
||
|
<option selected disabled value="">Select Classroom</option>
|
||
|
</select>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="send_to_teachr commonNotifClass" id="send_teacher" style="display:none;">
|
||
|
<div class="form-group assign_subject notification_form-group">
|
||
|
<label>Teacher*</label>
|
||
|
<select data-altName="Teacher" id="teacherDropDown" name="teacher_name" class="form-control" placeholder="Select Subject">
|
||
|
<option selected disabled value="">Select Teacher</option>
|
||
|
|
||
|
</select>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="send_to_teachrNStu commonNotifClass" id="teacherAndStudent" style="display : none">
|
||
|
<div class="row">
|
||
|
<div class="col-md-6 col-12 col-sm-12">
|
||
|
<div class="form-group assign_subject ">
|
||
|
<label>Student*</label>
|
||
|
<select data-altName="Student" id="StudentBoth" name="student_classroom" class="form-control" placeholder="Select Subject">
|
||
|
<option selected disabled value="">Select Classroom</option>
|
||
|
</select>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="col-md-6 col-12 col-sm-12">
|
||
|
<div class="form-group assign_subject ">
|
||
|
<label>Teacher*</label>
|
||
|
<select data-altName="Teacher" id="TeacherBoth" name="teacher_name" class="form-control" placeholder="Select Subject">
|
||
|
<option selected disabled value="">Select Teacher</option>
|
||
|
</select>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="txt-submit" style="display:none">
|
||
|
<div class="form-group">
|
||
|
<label for=""> Description</label>
|
||
|
<textarea class="form-control" data-altName="Description" name="description" rows="6" placeholder="Add some description of your course..."></textarea>
|
||
|
</div>
|
||
|
<div id="errMsg" class="mt-3 mb-3" style="display:none">
|
||
|
<p class="p-1 text-danger"></p>
|
||
|
</div>
|
||
|
<input type="submit" class="subject_addbtn" value="Send">
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</form>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<!-- admin template section end -->
|
||
|
</main>
|
||
|
<!--End right-top side-->
|
||
|
|
||
|
<script>
|
||
|
$(document).on('keypress', function(e) {
|
||
|
if (e.which == 13) {
|
||
|
$('form').submit();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
$(document).ready(function() {
|
||
|
|
||
|
let url = window.location.pathname.split('/');
|
||
|
let postUrl = url[1] + '/' + url[2];
|
||
|
|
||
|
jQuery.validator.addMethod("alphanumeric", function(value, element) {
|
||
|
return this.optional(element) || /^[a-z0-9\-\s]+$/i.test(value);
|
||
|
}, "Please enter alphanumeric Characters only");
|
||
|
|
||
|
$("#notificationForm").validate({
|
||
|
|
||
|
rules: {
|
||
|
|
||
|
notification_title: {
|
||
|
required: true,
|
||
|
minlength: 3,
|
||
|
alphanumeric: true
|
||
|
},
|
||
|
student_classroom: "required",
|
||
|
teacher_name: "required",
|
||
|
description: {
|
||
|
required: true,
|
||
|
minlength: 5
|
||
|
}
|
||
|
},
|
||
|
|
||
|
|
||
|
messages: {
|
||
|
notification_title: {
|
||
|
required: "Please Provide a Notification title",
|
||
|
minlength: "Please enter more than 3 Characters"
|
||
|
},
|
||
|
student_classroom: "Please select a Classroom",
|
||
|
teacher_name: "Please select a teacher name",
|
||
|
description: {
|
||
|
required: "Please provide a description",
|
||
|
minlength: "Please enter more than 5 Characters"
|
||
|
},
|
||
|
|
||
|
},
|
||
|
submitHandler: function(form, e) {
|
||
|
|
||
|
var inputValue = $("input[name='notification_title']", form).val();
|
||
|
inputValue = inputValue.toLowerCase();
|
||
|
|
||
|
let flag = false;
|
||
|
|
||
|
$.ajax({
|
||
|
url: '<?php echo base_url() ?>admin/ajax_validate_notification_name',
|
||
|
data: {
|
||
|
value: inputValue,
|
||
|
},
|
||
|
type: 'POST',
|
||
|
async: false,
|
||
|
success: function(data) {
|
||
|
console.log(data);
|
||
|
if (data == 'success') {
|
||
|
flag = true
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
if (flag) {
|
||
|
form.submit();
|
||
|
} else {
|
||
|
$('#titleerr').show();
|
||
|
$('#titleerr').text('This notification name already exists.');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
});
|
||
|
</script>
|
||
|
|
||
|
<script>
|
||
|
const getNotificationData = function(val) {
|
||
|
$('#txt-submit').show();
|
||
|
let returnedValue = '';
|
||
|
|
||
|
$.ajax({
|
||
|
url: '<?php echo base_url() ?>admin/ajax_fetch_notifications_data',
|
||
|
data: {
|
||
|
value: val
|
||
|
},
|
||
|
type: 'POST',
|
||
|
async: false,
|
||
|
success: function(data) {
|
||
|
returnedValue = JSON.parse(data);
|
||
|
}
|
||
|
})
|
||
|
$('#studentDropDown').empty();
|
||
|
$('#teacherDropDown').empty();
|
||
|
|
||
|
// If selected value is teachers
|
||
|
if (val == 'teacher') {
|
||
|
|
||
|
$('.commonNotifClass').hide();
|
||
|
|
||
|
$.each(returnedValue, function(index) {
|
||
|
let idNum = returnedValue[index]['id'] < 9 ? '0' + returnedValue[index]['id'] : returnedValue[index]['id'];
|
||
|
if (index == 0) {
|
||
|
$('#teacherDropDown')
|
||
|
.append($("<option></option>")
|
||
|
.attr("value", '')
|
||
|
.text('Select a teacher'));
|
||
|
}
|
||
|
$('#teacherDropDown')
|
||
|
.append($("<option></option>")
|
||
|
.attr("value", returnedValue[index]['id'])
|
||
|
.text(returnedValue[index]['teacher_name'] + ' - ' + idNum));
|
||
|
});
|
||
|
$('#send_teacher').show();
|
||
|
|
||
|
} else if (val == 'student') {
|
||
|
|
||
|
$('.commonNotifClass').hide();
|
||
|
|
||
|
$.each(returnedValue, function(index) {
|
||
|
if (index == 0) {
|
||
|
$('#studentDropDown')
|
||
|
.append($("<option></option>")
|
||
|
.attr("value", '')
|
||
|
.text('Select a classroom'));
|
||
|
}
|
||
|
$('#studentDropDown')
|
||
|
.append($("<option></option>")
|
||
|
.attr("value", returnedValue[index]['id'])
|
||
|
.text(returnedValue[index]['classroom_name']));
|
||
|
});
|
||
|
$('#send_student').show();
|
||
|
|
||
|
} else if (val == 'both') {
|
||
|
|
||
|
$('.commonNotifClass').hide();
|
||
|
|
||
|
let StudentInfo = returnedValue['student'];
|
||
|
let TeacherInfo = returnedValue['teachers'];
|
||
|
|
||
|
$.each(TeacherInfo, function(index) {
|
||
|
$('#TeacherBoth')
|
||
|
.append($("<option></option>")
|
||
|
.attr("value", TeacherInfo[index]['id'])
|
||
|
.text(TeacherInfo[index]['teacher_name']));
|
||
|
});
|
||
|
|
||
|
|
||
|
$.each(StudentInfo, function(index) {
|
||
|
$('#StudentBoth')
|
||
|
.append($("<option></option>")
|
||
|
.attr("value", StudentInfo[index]['id'])
|
||
|
.text(StudentInfo[index]['classroom_name']));
|
||
|
});
|
||
|
$('#teacherAndStudent').show();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
</script>
|