<script>

$(document).ready(function() {
    var institution = <?php echo $InstitutionID; ?>;
    var userID = $('#user_id').val();


    $.ajax({
        type: "POST",
        url: "../../controller/scripts/parent/assignment/ekene_select_child.php",
        data: {
          
              institution: institution,
              userID: userID
           
        },
    
        success: function (output) { 

           
            $("#ekene_cilds_id").html(output);
    
        }
    });


   
        
});
$('body').on('change', '#ekene_cilds_id', function () { 
    
    var campusID = $("#ekene_cilds_id option:selected").data("id");
    var studentid = $("#ekene_cilds_id option:selected").val();
    $("#ekene_child_hidden").val(campusID);

$('#ekene_select_assignment_term').html('<option>  <span class="visually-hidden">Loading...</span></option>'); 
    
    $.ajax({
        type: "POST",
        url: "../../controller/scripts/parent/assignment/ekene_select_termalias.php",
        data: {
        
              campus: campusID
           
        },
    
        success: function (output) { 
            
           
            $("#ekene_select_assignment_term").html(output);
    
        }
    });

    $('#ekene_select_assignment_subject').html('<option>  <span class="visually-hidden">Loading...</span></option>'); 
    $.ajax({
        type: "POST",
        url: "../../controller/scripts/parent/assignment/ekene_select_subject.php",
        data: {
          
              campus: campusID,
              userID: studentid
           
        },
    
        success: function (output) { 

     
           
            $("#ekene_select_assignment_subject").html(output);
    
        }
    });

});


$('body').on('click', '#ekene_load_assignment_question', function () { 

    ekeneloadconassignmentcontent();

});  


function  ekeneloadconassignmentcontent()
{



    $('#ekene_display_student_behavioural').html('<center><i class="fa fa-spinner fa-spin fs-3"></i></center>');
    var campusID = $("#ekene_child_hidden").val();
    var studentid = $("#ekene_cilds_id option:selected").val();
   
    // var diplay_class = $('#ekene_select_assignment_class option:selected').val();
    // var usertype = $('#user_type_holder').val();
    var ekene_subject = $('#ekene_select_assignment_subject option:selected').val();
    var session = $('#ekene_display_behavioural_session option:selected').val();
    var term = $('#ekene_select_assignment_term option:selected').val();
    
        
    $.ajax({
        type: "POST",
        url: "../../controller/scripts/parent/assignment/ekene_appendcard.php",
        data: {

            ekene_campus: campusID,
            userID: studentid,
            session: session,
            term: term,
           
            ekene_subject: ekene_subject
          
        },

        success: function (output) { 
        
      
            
            $('#ekene_display_student_behavioural').html(output);
           
            
        
        },
    });

}

$('body').on('click', '#ekene_download_fullassignment', function () { 
    var campusID = $("#ekene_child_hidden").val();
    var studentid = $("#ekene_cilds_id option:selected").val();
     
    var assignmentsettingsid = $(this).data("id");
    var ekene_subject = $('#ekene_select_assignment_subject option:selected').val();
    
 

    $.ajax({
        type: "POST",
        url: '../../controller/scripts/parent/assignment/ekene_dowload_assignment.php',
        data: {
            campusid: campusID,
        
            assignmentsettingsid: assignmentsettingsid,
            userID: studentid,
            ekene_subject: ekene_subject
    
            
        },

        success: function (response) {


        
              $("#downloadassignmentekene").html(response);
              $(".answer").hide();
           
            


        },

   });
});


$('body').on('click', '#ekene_print', function () {

    const element = document.getElementById("downloadassignmentekene");

    // Set the filename in the output option
    const options = {

    filename: "Assigment.pdf",
    margin: 10, 
    };

    // Generate the PDF with html2pdf and save it with the specified filename
    html2pdf().from(element).set(options).save();

});

// $("body").on('click', '#ekene_view_fullassignment', function () {
//     var assignmentid = $(this).data("id");
//     var campusid = $(this).data("cam");
//     var questionCounter = 1;
//     var questionCounterone = 1;

//     $.ajax({
//         type: "POST",
//         url: '../../controller/scripts/student/assignment/ekene_view_assignment_one.php',
//         data: {
//             assignmentid: assignmentid,
           
            
//             campusid: campusid
          
//         },

//         success: function (response) {

//             var jsonDatacate = JSON.parse(response);
//             $('#ekeneloadtheoryappendquestionsjon').val(0);
//             $("#ekeneloadappededinputheresavechangetheory").empty();
           
//             $('#ekeneloadobjectiveappendquestionsjon').val(0);
//             $("#ekeneloadappededinputheresavechangeobjective").empty();
//             for (var i = 0; i < jsonDatacate.length; i++) {
                   
//                 // Access the properties you need here
        
//                 var itemnew = jsonDatacate[i];
             
//                 //  var spotName = item.spot_name;
//                  var AssignmentQuestion = itemnew.id;
//                  var assignmentquestionid = itemnew.assignmentid;
//                  var questionnew = itemnew.question;
//                  var optionAnew = itemnew.optionA;
//                  var optionBnew = itemnew.optionB;
//                  var optionCnew = itemnew.optionC;
//                  var optionDnew = itemnew.optionD;
//                  var CampusIDnew = itemnew.CampusID;
                 
//                 //  var answernew = itemnew.answer;
//                  var AssignmentCategorynew = itemnew.AssignmentCategory;
      

//                  if(AssignmentCategorynew == "Theory")
//                  {
            
//                     var ekeneloadinputtag = questionCounterone++;

                    
//                       var ekene_theoryquestion = `<div style="color: black;"class="ekeneremoveappendentheoryjson${ekeneloadinputtag}">
//                     <div class="col-12" style="display: flex;">
//                     <strong class="ekene_general_class_remove_inputtheory ekenetheoryquestjson" data-cam="${CampusIDnew}" data-status="${assignmentquestionid}" data-assignment_question="${AssignmentQuestion}">
//                         Question ${ekeneloadinputtag}: ${questionnew}
//                     </strong>

//                       </div>
//                       &nbsp; <textarea class="mymce textarea_questiontheory question mb-4 generaledit" data-status="edit" rows="3" cols="80" name="area"></textarea></br>
//                   </div>`;
             
//                   $('#ekeneloadappededinputheresavechangetheory').append(ekene_theoryquestion);
                  
//                   $('.mymce').summernote();
//                  }
//                  else
//                  {
                   
//                     var ekeneloadinputtag = questionCounter++;

//                     var ekene_objectivequestion =  `<div class="card g-3">
//                     <div class="card-body ekeneremoveappendenobjjson ekeneremoveappendenobjjson${ekeneloadinputtag}">
//                         <strong style="font-weight: bold;" class="objectivestrongtext" data-assignment_questionobjective="${AssignmentQuestion}">Question ${ekeneloadinputtag}: ${questionnew}</strong>
//                     </div>
//                     <ul class="list-group list-group-flush">
//                         <li class="list-group-item">
//                             <div class="row">
//                                 <div class="col-12">
//                                 <div class="option" style="display: inline-block; white-space: nowrap;">
//                                 <input type="radio" name="ekeneobjquest${AssignmentQuestion}" value="A"> A) ${optionAnew}
//                             </div>

//                             </div>
//                         </li>
                        
//                         <li class="list-group-item">
//                             <div class="row">
//                                 <div class="col-12">
//                                     <div class="option">
//                                         <input type="radio" name="ekeneobjquest${AssignmentQuestion}" value="B"> B) ${optionBnew}
//                                     </div>
//                                 </div>
//                             </div>
//                         </li>
                        
//                         <li class="list-group-item">
//                             <div class="row">
//                                 <div class="col-12">
//                                     <div class="option">
//                                         <input type="radio" name="ekeneobjquest${AssignmentQuestion}" value="C"> C) ${optionCnew}
//                                     </div>
//                                 </div>
//                             </div>
//                         </li>
                        
//                         <li class="list-group-item">
//                             <div class="row">
//                                 <div class="col-12">
//                                     <div class="option">
//                                         <input type="radio" name="ekeneobjquest${AssignmentQuestion}" value="D"> D) ${optionDnew}
//                                     </div>
//                                 </div>
//                             </div>
//                         </li>
//                     </ul>
//                 </div>`;
                
                
                
//                       $('#ekeneloadappededinputheresavechangeobjective').append(ekene_objectivequestion);
                
//                  }

               
//             }



//         }

//      }); 
// });

// $('body').on('click', '#studentsubmitassignment', function () {
    
//     var assignmentid = $(".ekenetheoryquestjson").data("status");
//     var campusid = $(".ekenetheoryquestjson").data("cam");
//     var userID = $('#user_id').val();
//     var subjectid = $('#ekene_select_assignment_subject').val();
//     var textareaquestion = [];
//     var textareaquestiontheory = [];
//     var assignmentquestiontheoryid = [];
//     var Answer = [];


    
  
//     // var Answer = [];
//     // var assignmenttype = [];
//     // var assignmenttypefortheory = [];


// // Check if at least one textarea with the class 'textarea_questiontheory' exists
//         if ($('.textarea_questiontheory').length > 0) {

//             $.each($(".textarea_questiontheory"), function () {
//                 var question_value = $(this).val();
                
//                 // Check if the value is empty or equal to '###||'
//                 if (question_value === '' || question_value === '###||') {
//                     textareaquestiontheory.push('');
//                 } else {
//                     textareaquestiontheory.push(question_value + '###||');
                   
//                 }
        
//             });

//             $.each($(".ekenetheoryquestjson"), function () {
//                 var question_checktheory = $(this).data("assignment_question")
//                 // if (question_check == '') {
//                 //     textareaquestion.push('');
//                 // } else {
//                     assignmentquestiontheoryid.push(question_checktheory);
//                     // assignmenttype.push($(this).data('status'));
//                 // }
//             });
        

//         } else {
//             // The textarea does not exist
//             console.log('Textarea with the class "textarea_questiontheory" does not exist.');
//         }

//         if ($('.objectivestrongtext').length > 0) {

//             $.each($(".objectivestrongtext"), function () {
//                 var question_check = $(this).data("assignment_questionobjective")
//                 // if (question_check == '') {
//                 //     textareaquestion.push('');
//                 // } else {
//                     textareaquestion.push(question_check);
//                     // assignmenttype.push($(this).data('status'));
//                 // }
//             });
        
          
//            $.each($(".answer :checked"), function () {
//             var question_check = $(this).val();
//             // if (question_check == '') {
//             //     textareaquestion.push('');
//             // } else {
//                 Answer.push(question_check);
//             });

//         }
//         else
//         {

//         }

    
 
    

      


   



   

// //     // // Check if no radio button is checked
// //     // if (Answer.length === 0) {
// //     //    alert("hello");
// //     // } else {
// //     //    alert("uu");
// //     // }


//     var textareaquestiontheory1 = textareaquestiontheory.some(function (value) {
//         return value.trim() == '';
//     });
    
// alert
// // // alert(textareaquestiontheory1);

    
//    if (textareaquestiontheory1)
//    {
//     $.wnoty({
//         type: 'warning',
//         message: "Please fill in all the required fields",
//         autohideDelay: 5000
//     });
//    }
//    else if(Answer.length === 0)
//    {
//     $.wnoty({
//         type: 'warning',
//         message: "No objective Answered",
//         autohideDelay: 5000
//     });
//    }
//    else
//    {
  
//     $.ajax({
//         type: "POST",
//         url: '../../controller/scripts/student/assignment/studentsubmit.php',
//         data: {
//             assignmentid: assignmentid,
//             campusid: campusid,
//             userID: userID,
//             subjectid: subjectid,
//             textareaquestiontheory: textareaquestiontheory,
//             assignmentquestiontheoryid: assignmentquestiontheoryid,
//             textareaquestion: textareaquestion,
//             Answer: Answer
//         },
    
//         success: function (response) {
//             if (response == 10) {

//                 $.wnoty({
//                     type: 'success',
//                     message: "Submitted successfully..",
//                     autohideDelay: 5000
//                 });

//              $("#student_answermodal").modal("hide");
//                $.ajax({
//                 type: "POST",
//                 url: "../../controller/scripts/student/assignment/ekene_appendcard.php",
//                 data: {
        
//                     ekene_campus: campusid,
//                     userID: userID,
                   
//                     ekene_subject: subjectid
                  
//                 },
        
//                 success: function (output) { 
                
//                     $('#ekene_display_student_behavioural').html(output);
                   
//                 },
//             });
        
//             } else {

//                 $.wnoty({
//                     type: 'danger',
//                     message: "Failed",
//                     autohideDelay: 5000
//                 });
               
//             }
//         }
//      });
//    }



   
// });


</script>