JezK
Edit File: license_management.php
<?php if (session_id() == "") { session_start(); } //~ print_r($_SESSION); if ($_SESSION['child']['current_academic_id'] != $_SESSION['child']['choosen_academic_id']) { echo "<script>alert('Licenses can not be managed for past Academic Years');</script>"; echo "<script>location.replace('academicyear_management.php');</script>"; } include("header.php"); include_once("school_admin_access.php"); $admin = new adminaccess(); //~ echo 12324; //$school_id = $_SESSION['log_school_id']; $school_id = $_SESSION['child']['log_school_id']; //$school_id ='1'; $acadamic_id = $_SESSION['child']['current_academic_id']; $choosen_acc_id = $_SESSION['child']['choosen_academic_id']; $details = $admin->get_classes_byschool_total($school_id, $choosen_acc_id); $students_count = $admin->get_students_byschool($school_id, $acadamic_id); //$students_count = $student->check_student_count_add($school_id,$acadamic_id,$choosen_acc_id); /*if($details){ foreach($details as $key=>$row) { if($ [$key]['junior_status'] == '1'){ $class_id = $details[$key]['class_id']; } } }*/ //$section_byclass =$admin->get_section_byclass($details[0]['class_id']); $class_id = $_SESSION['child']['stu_class_id_licence']; $section_byclass = $admin->get_sections_data_byclass($class_id); //$school_licene_count =$admin->check_license_count($school_id); $check_license_sets = $admin->check_license_sets_count($school_id); //echo "<pre>"; //print_r($check_license_sets); //$distribute_licene_count =$admin->check_distributelicense_count($school_id,$choosen_acc_id); $licencecount = '0'; if ($check_license_sets) { foreach ($check_license_sets as $key => $val) { $licencecount = $licencecount + $val['license_count']; $licence_ids[] = $val['school_license_id']; //~ print_r($licence_ids); //~ exit; } } //echo "count ".$licencecount; if ($licence_ids) { $ids = implode(",", $licence_ids); } $distribute_licene_count = $admin->check_distributelicense_count_new($ids); if (!isset($_GET['cresult'])) { unset($_SESSION['child']['stu_class_id_licence']); unset($_SESSION['child']['section_id_licence']); } ?> <style> select { width: 62px !important; background-color: #FFF; border: 1px solid #CCC; } .lice_details { font-size: 14px; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-size: 13px; padding-top: 10px; } .lice_details_but { width: 89px; height: 30px; padding-top: 4px; margin-top: 3px; } .licensebtn { margin-right: 20px; font-family: Arial, Helvetica, sans-serif; font-size: 14px; padding: 4px 10px; } @font-face { font-family: myfont; src: url(Courier.ttf); } </style> <body style=" overflow-x: hidden;"> <div class="row" style="margin-top: 30px;margin-left:10px;"> <div class="col-md-5 text-left" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:24px; "> <i class="fa-solid fa-bookmark" title=" License management" style="font-size: 20px;margin: 0px 3px 0px 0px;"></i> Distribute Licenses </div> <div class="col-md-6 text-end"> <button type="button" id="deactivate_btn" class="btn btn-outline-secondary licensebtn"> Deactivate </button> <button type="button" id="generate_btn" class="btn btn-outline-secondary licensebtn"> Generate License </button> <button type="button" id="email_send_btn" class="btn btn-outline-secondary licensebtn"> Email License </button> </div> </div> <form class="form-horizontal"> <div class="row"> <div class="form-group row col-md-6"> <div class=" col-md-5 offset-1 text-md-end"> <b style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;color:#666666;">Total Number of Licenses</b> </div> <div class="col-md-6"> <b style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;"><?= $licencecount ?></b> </div> </div> </div> <div class="row my-3"> <div class="form-group row col-md-6"> <div class=" col-md-5 offset-1 text-md-end"> <b style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;color:#666666; ">Number of Licenses Distributed</b> </div> <div class="col-md-6"> <b style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;"><?= $distribute_licene_count['distributedcount'] ?></b> </div> </div> </div> <div class="row my-3"> <div class="form-group row col-md-6"> <div class="col-md-5 offset-1 text-md-end"> <b style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;color:#666666;">Choose Class</b><span style="color:#FF0000;">*</span> </div> <div class="col-md-6"> <select class="form-select" id="classes" name="classes" style="height:29px; font-size:13px; width:300px!important;padding-bottom:0;" tabindex="1"> <option selected="selected" value=''>--Select Class--</option> <?php foreach ($details as $key => $row) { /*if($details[$key]['junior_status'] == '1'){ $selected = "selected=selected"; }else { $selected = ""; }*/ if ($_SESSION['child']['stu_class_id_licence'] == $row['class_id']) { $selected = "selected=selected"; } else { $selected = ""; } echo "<option value='{$row['class_id']}'{$selected}>{$row['class_name']}</option>"; } ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_class" style="color:#990000; display:none;"></div> <!--- end error--> </div> </div> </div> <div class="row"> <div class="form-group row col-md-6"> <div class="col-md-5 offset-1 text-md-end"> <b style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px;color:#666666;">Choose Section</b><span style="color:#FF0000;">*</span> </div> <div class="col-md-6"> <select class="form-select" id="sections" name="sections" style="height:29px; font-size:13px; width:300px!important;" tabindex="2"> <option selected="selected" value=''>--Select Section--</option> <?php if (count($section_byclass) > 0) { foreach ($section_byclass as $key => $row) { if ($row['section_id'] == $_SESSION['child']['section_id_licence']) { $selected = "selected=selected"; } else { $selected = ""; } echo "<option value='{$row['section_id']}'{$selected}>{$row['section_name']}</option>"; } } ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_section" style="color:#990000; display:none;"></div> <!--- end error--> </div> </div> </div> </form> <div class="row" style="margin-left:10px;margin-right:10px;"> <div id="license" class="col-md-12 centered" style="font-family: Arial, Helvetica, sans-serif;margin-top:30px;"> <input type="hidden" name="students_data" id="students_data" value=""> <input type="hidden" name="students_data_val" id="students_data_val" value=""> <input type="hidden" name="total_licences" id="total_licences" value="<?= $licencecount ?>"> <input type="hidden" name="distribute_licences" id="distribute_licences" value="<?= $distribute_licene_count['distributedcount'] ?>"> </div> </div> <script src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script> <script src="//cdn.datatables.net/buttons/1.1.2/js/buttons.print.min.js"></script> <script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script> <script src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script> <script src="//cdn.datatables.net/buttons/1.1.2/js/buttons.html5.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script> <script type="text/javascript" language="javascript" class="init"> function test(val, stuval, status, mail) { var studentids = $('#studentids').val(); var stu_data = $('#students_data').val(); var stu_data_val = $('#students_data_val').val(); var stu_data_sta = $('#students_data_sta').val(); var stu_data_mail = $('#students_data_mail').val(); var checked = $('#student_ids_data' + stuval).is(":checked"); if (checked == true) { if (stu_data != '') { stu_value = stu_data + "," + val; stuids_value = stu_data_val + "," + stuval; stu_status = stu_data_sta + "," + status; stu_mail = stu_data_mail + "," + mail; // alert(stuids_value); $('#students_data').val(stu_value); $('#students_data_val').val(stuids_value); $('#students_data_sta').val(stu_status); var stu_data_check = $('#students_data').val(); if (studentids.length == stu_data_check.length) { $("#select-all").prop("checked", true); } } else { $('#students_data').val(val); $('#students_data_val').val(stuval); $('#students_data_sta').val(status); $('#students_data_mail').val(mail); } } else { // alert('test'); $("#select-all").prop("checked", false); var stu_data = $('#students_data').val(); var stu_data_val = $('#students_data_val').val(); var stu_status = $('#students_data_sta').val(); var stu_mail = $('#students_data_mail').val(); var stu_data = stu_data.replace(val, ""); stu_data = stu_data.replace(",,", ","); stu_data = stu_data.replace(/^,/g, ''); stu_data = stu_data.replace(/,$/g, ''); var stu_data_val = stu_data_val.replace(stuval, ""); stu_data_val = stu_data_val.replace(",,", ","); stu_data_val = stu_data_val.replace(/^,/g, ''); stu_data_val = stu_data_val.replace(/,$/g, ''); var stu_status = stu_status.replace(status, ""); stu_status = stu_status.replace(",,", ","); stu_status = stu_status.replace(/^,/g, ''); stu_status = stu_status.replace(/,$/g, ''); var stu_mail = stu_mail.replace(mail, ""); $('#students_data').val(stu_data); $('#students_data_val').val(stu_data_val); $('#students_data_sta').val(stu_status); $('#students_data_mail').val(stu_mail); } } function selct_all(source) { var txt = ''; var txtkeys = ''; var txtstatus = ''; var txtmail = ''; if (source.checked == true) { checkboxes = document.getElementsByName('student_ids_data[]'); checkboxes_values = document.getElementsByName('student_ids_data_values[]'); checkboxes_stattus = document.getElementsByName('student_ids_data_status[]'); checkboxes_mail = document.getElementsByName('student_ids_data_mail[]'); for (var i = 0, n = checkboxes.length; i < n; i++) { checkboxes[i].checked = source.checked; txt = txt + checkboxes[i].value + "," txtkeys = txtkeys + checkboxes_values[i].value + "," txtstatus = txtstatus + checkboxes_stattus[i].value + "," txtmail = txtmail + checkboxes_mail[i].value + "," // alert(txt); } $('#students_data').val(txt); $('#students_data_val').val(txtkeys); $('#students_data_sta').val(txtstatus); $('#students_data_mail').val(txtmail); } else { //alert('uncheck for all'); for (var i = 0, n = checkboxes.length; i < n; i++) { checkboxes[i].checked = source.checked; } txt = ''; txtkeys = ''; txtstatus = ''; txtmail = ''; $('#students_data').val(txt); $('#students_data_val').val(txtkeys); $('#students_data_sta').val(txtstatus); $('#students_data_mail').val(txtmail); } } function status_change(stuid, status) { var totallicences = '<?= $licencecount ?>'; //var totallicences = $('#total_licences').val(); var dicount = $('#distribute_licences').val(); if ((Number(totallicences) <= Number(dicount)) && (status == 1)) { alert('You already consumed all student licenses. Please purchase additional licenses to reactivate.'); return false; } if (status == '0') { r = confirm("Do you want to Deactivate the student?"); } else { r = confirm("Do you want to Activate the student?"); } if (r == true) { $.ajax({ url: "ajaxconditions.php", type: "POST", data: "action=" + "change_status" + "&stuid=" + stuid + "&status=" + status, success: function(result) { // alert(result); //return false; //if(result == "success"){ //if(status == '0'){ // alert("Student Deactivated successfully"); //}else { // alert("Student Activated successfully"); //} window.location = 'license_management.php?cresult=success'; //} }, error: function(e) { } }); } else { return false; } } $('#student_ids_data').click(function(event) { if (1 == 1) { alert('test'); } }); $(document).ready(function() { var classname = $('#classes').find('option:selected').text(); var secname = $('#sections').find('option:selected').text(); $('#err_class').hide(); $('#err_section').hide(); var class_id = $("#classes").val(); var sec_id = $("#sections").val(); // $("#students").load("students_data.php",{classid:class_id,sec_id:sec_id},function(data){ $.post("license_data.php", { classid: class_id, sec_id: sec_id }, function(data) { document.getElementById("license").innerHTML = data; /*$('#myTable').DataTable({ columnDefs: [ { orderable: false, targets: [0] } ], "pageLength":100, stateSave: true, dom: 'T<"clear">lfrtip', "oLanguage": { "sSearch": "" }, tableTools: { "aButtons": [ { "sExtends": "xls", "mColumns": [0, 1, 2, 3, 4, 5,6,7,8] }, { "sExtends": "pdf", "sPdfOrientation": "landscape", "mColumns": [0, 1, 2, 3, 4, 5,6,7,8] }, { "sExtends": "print", "mColumns": [0, 1, 2, 3, 4, 5,6,7,8] } ] } }); $('div.dataTables_filter input').attr('placeholder', 'Search');*/ $('#myTable').DataTable({ "columnDefs": [{ "targets": 0, "orderable": false }], dom: 'B<"clear">lfrtip', "iDisplayLength": 100, stateSave: true, buttons: [{ extend: 'print', title: '<center><h3><?php echo $_SESSION['child']['school_name'] ?></h3></center>', message: 'License Management<br>Academic Year:<?php echo $_SESSION[child][choosen_year_name] ?> ClassName:' + classname + ' Sectionname:' + secname + '<br>', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7] } }, { extend: 'pdfHtml5', title: '<?php echo $_SESSION['child']['school_name'] ?>', message: 'License Management\nAcademic Year:<?php echo $_SESSION[child][choosen_year_name] ?>\tClassName:' + classname + '\tSectionname:' + secname + '\n', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7] } }, { extend: 'excelHtml5', title: '<?php echo $_SESSION['child']['school_name'] ?>', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7] } } ] }); }); $('#deactivate_btn').click(function(event) { var result = confirm("Do you want to Deactivate the selected students?"); if (result == true) { var student_ids = $('#students_data').val(); var student_status = $('#students_data_sta').val(); if ((student_status.indexOf('Active') > -1 && student_status.indexOf('Deactivated') > -1) || (student_status.indexOf('Active') > -1 && student_status.indexOf('Inactive') > -1) || (student_status.indexOf('Deactivated') > -1 && student_status.indexOf('Inactive') > -1)) { alert("Please choose only Active students for deactivation"); return false; } else { if (student_ids != '') { $.ajax({ url: "ajaxconditions.php", type: "POST", data: "action=" + "deactive_license" + "&data=" + student_ids, success: function(result) { //alert(result); if (result == "check") { alert("Please choose only Active students for deactivation"); return false; } else if (result == "inactive") { alert("You can not Deactivate an Inactive student"); return false; } else { //if(result == "sucess") { //alert("Selected Licenses has been Deactivated successfully"); window.location = 'license_management.php?cresult=success'; //} } }, error: function(e) { //alert('Prasa'); } }); } else { alert('Please select the student List'); return false; } } } else { return false; } }); $('#email_send_btn').click(function(event) { var result = confirm("Do you want to Email License for the selected students?"); if (result == true) { var student_ids = $('#students_data').val(); var students_data_val = $('#students_data_val').val(); var student_status = $('#students_data_sta').val(); var student_mail_status = $('#students_data_mail').val(); if ((student_status.indexOf('Active') > -1 && student_status.indexOf('Deactivated') > -1) || (student_status.indexOf('Active') > -1 && student_status.indexOf('Inactive') > -1) || (student_status.indexOf('Deactivated') > -1 && student_status.indexOf('Inactive') > -1)) { alert("Please choose only Active students for emailing Licenses"); return false; } else if (student_status.indexOf('Inactive') > -1) { alert("License Email cannot be delivered for an Inactive Student"); return false; } else if (student_status.indexOf('Deactivated') > -1) { alert("License Email cannot be delivered for a Deactivate student"); return false; } else { if (student_ids != '') { $.ajax({ url: "ajaxconditions.php", type: "POST", data: "action=" + "send_mails_license" + "&data=" + students_data_val, success: function(result) { //alert(result); if (result == "check") { alert("Please choose only Active students for emailing Licenses"); return false; } else { //alert(result); alert("License Email sent successfully"); window.location = 'license_management.php?cresult=success'; } }, error: function(e) { } }); } else { alert('Please select the student List'); return false; } } } else { return false; } }); $('#generate_btn').click(function(event) { var result = confirm("Do you want to Generate License for the selected students?"); // alert(); if (result == true) { //alert('test'); var student_status = $('#students_data_sta').val(); // alert(student_status); // ~ console.log(student_status); var student_ids = $('#students_data').val(); // alert(students_data); // ~ console.log(student_ids); var students_data_val = $('#students_data_val').val(); // alert(students_data_val); //~ console.log(student_data_val); //alert(students_data_val); var licence_count123 = $('#total_licences').val(); var licence_count = '<?= $licencecount ?>'; var distribute_count = $('#distribute_licences').val(); var choosen_acc_id = '<?= $choosen_acc_id ?>'; var remain_count = licence_count - distribute_count; if ((student_status.indexOf('Active') > -1 && student_status.indexOf('Deactivated') > -1) || (student_status.indexOf('Active') > -1 && student_status.indexOf('Inactive') > -1) || (student_status.indexOf('Deactivated') > -1 && student_status.indexOf('Inactive') > -1)) { alert("Please choose only Inactive students for License Generation"); return false; } else if (student_status.indexOf('Active') > -1 || student_status.indexOf('Deactivated') > -1) { alert("License for this student has been already generated, you cannot regenerate the license"); return false; } else { if (student_ids != '') { $.ajax({ url: "ajaxconditions.php", type: "POST", data: "action=" + "generate_license" + "&data=" + students_data_val + "&remain=" + remain_count + "&distribute_count=" + distribute_count + "&acadamic_id=" + choosen_acc_id, success: function(result) { if (result == "exceedlimit" && remain_count > 0) { alert('You are left with only ' + remain_count + ' Licenses. You can choose a maximum of ' + remain_count + ' Students for License generation'); return false; } else if (result == "exceedlimit" && remain_count == 0) { alert('You already consumed all student licenses. Please purchase additional licenses to generate.'); return false; } else if (result == "check") { alert("Please choose only Inactive students for License Generation"); return false; } else { //alert(result); alert("License Generated successfully"); window.location = 'license_management.php?cresult=success'; } }, error: function(e) { } }); } else { alert('Please select the student List'); return false; } } } else { return false; } }); $('#student_ids_data').click(function(event) { if (1 == 1) { alert('test'); } }); $('#select-all').click(function(event) { alert('hai') var vals = ''; for (var i = 0; i < student_ids_data_values.length; i++) { alert(student_ids_data_value[i]); } if (this.checked) { // Iterate each checkbox $(':checkbox').each(function() { this.checked = true; if ($(this).val() != '') { vals += "," + $(this).val(); } }); } else { $(':checkbox').each(function() { this.checked = false; }); } $('#students_data').val(vals); $('#students_data_val').val(vals_data); }); $("#classes").change(function() { $('#err_class').hide(); if ($(this).val() == 0) { //alert("Choose Class"); $('#err_class').show(); $('#err_class').text('Please choose Class'); section_option = '<option selected="selected" value="" >--Select Section--</option>'; $("#sections").html(section_option); return false; } else { var x = $(this).val(); $.ajax({ url: "ajaxcalls.php", type: "POST", data: "mode=" + "choose_class" + "&data=" + x, success: function(result) { var result2 = eval("(" + result + ")"); var section_option = '<option value="0">Choose Section</option>'; for (var i = 0; i < result2.length; i++) { section_option += '<option value="' + result2[i].section_id + '">' + result2[i].section_name + '</option>'; } $("#sections").html(section_option); }, error: function(e) { } }); } }); $("#sections").change(function() { var classname = $('#classes').find('option:selected').text(); var secname = $('#sections').find('option:selected').text(); $('#err_section').hide(); if ($("#classes").val() == 0) { //alert("Choose Class"); $('#err_class').show(); $('#err_class').text('Please choose Class'); return false; } else { if ($("#sections").val() == 0) { //alert("Choose Sections"); $('#err_section').show(); $('#err_section').text('Please choose Section'); return false; } else { var class_id = $("#classes").val(); var sec_id = $("#sections").val(); // $("#students").load("students_data.php",{classid:class_id,sec_id:sec_id},function(data){ $.post("license_data.php", { classid: class_id, sec_id: sec_id }, function(data) { // alert(data); document.getElementById("license").innerHTML = data; /* $('#myTable').DataTable({ columnDefs: [ { orderable: false, targets: [0] } ], "pageLength":100, stateSave: true, dom: 'T<"clear">lfrtip', "oLanguage": { "sSearch": "" }, tableTools: { "aButtons": [ { "sExtends": "xls", "mColumns": [0, 1, 2, 3, 4, 5,6,7,8] }, { "sExtends": "pdf", "sPdfOrientation": "landscape", "mColumns": [0, 1, 2, 3, 4, 5,6,7,8] }, { "sExtends": "print", "mColumns": [0, 1, 2, 3, 4, 5,6,7,8] } ] } }); $('div.dataTables_filter input').attr('placeholder', 'Search'); */ $('#myTable').DataTable({ "columnDefs": [{ "targets": 0, "orderable": false }], dom: 'B<"clear">lfrtip', "iDisplayLength": 100, stateSave: true, buttons: [{ extend: 'print', title: '<center><h3><?php echo $_SESSION['child']['school_name'] ?></h3></center>', message: 'License Management<br>Academic Year:<?php echo $_SESSION[child][choosen_year_name] ?> ClassName:' + classname + ' Sectionname:' + secname + '<br>', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7] } }, { extend: 'pdfHtml5', title: '<?php echo $_SESSION['child']['school_name'] ?>', message: 'License Management\nAcademic Year:<?php echo $_SESSION[child][choosen_year_name] ?>\tClassName:' + classname + '\tSectionname:' + secname + '\n', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7] } }, { extend: 'excelHtml5', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7] } } ] }); }); //}); } } }); $('#myTable').dataTable({ "aoColumnDefs": [{ 'bSortable': false, 'aTargets': [1] }] }); $('#myTable').DataTable({ dom: 'T<"clear">lfrtip', "oLanguage": { "sSearch": "" }, tableTools: { "aButtons": [ "xls", { "sExtends": "pdf", "sPdfOrientation": "landscape", "sPdfMessage": "Your custom message would go here." }, "print" ] } }); $('div.dataTables_filter input').attr('placeholder', 'Search'); }); </script> </body> </html>