JezK
Edit File: access_modules.php
<?php include('header.php'); $response=$db->getFeature(); foreach($response as $val) { $optionData.= '<option class="" value='.$val['id'].' class="text-capitalize">'.$val['feature'].'</option>'; } if(isset($_POST['submit'])) { $application_name=$_POST['application_name']; $application_client=$_POST['application_client']; $function_hall_name=$_POST['function_hall_name']; $lodge_name=$_POST['lodge_name']; if(isset($_FILES["application_logo"]["name"])) { $t = $_FILES["application_logo"]["tmp_name"]; $n = $_FILES["application_logo"]["name"]; $p=strtotime(date('d-m-Y H:i:s')); $k=substr(str_shuffle($p),0,5); $tfname=$k.$n; if(move_uploaded_file($t, "../uploads/".$tfname)) { $application_logo=$tfname; } } // print_r($_POST); // print_r($_FILES);exit; $status=$db->updateApplicationDetails($application_name,$application_logo,$function_hall_name,$lodge_name,$application_client); if($status==1) { echo "<script>alert('Application details added successfully');</script>"; echo "<script>location.replace('access_modules.php');</script>"; }else if($status==0) { echo "<script>alert('Application details adding failed');</script>"; } } if(isset($_POST['submit_add'])) { $feature_name=$_POST['feature_name']; $status=$db->addFeature($feature_name); if($status==1) { echo "<script>alert('Feature added successfully');</script>"; echo "<script>location.replace('access_modules.php');</script>"; }else if($status==0) { echo "<script>alert('Feature adding failed');</script>"; } } if(isset($_POST['submit_del'])) { $feature_name=$_POST['feature_name']; $status=$db->delFeature($feature_name); if($status==1) { echo "<script>alert('Feature deleted successfully');</script>"; echo "<script>location.replace('access_modules.php');</script>"; }else if($status==0) { echo "<script>alert('Feature deleting failed');</script>"; } } $features_list=$db->getAppFeatures(); $features = ''; if(!empty($features_list)) { $i=1; foreach($features_list as $list) { if ($i<=2) { $features.=' <label class="checkbox-inline"> <input type="checkbox" id="feature'.$i.'" name="feature[]" value="'.$list['id'].'" onchange="hideinput('.$list['id'].',event)">'.$list['feature'].' </label> '; } else { $features.=' <label class="checkbox-inline"> <input type="checkbox" id="feature'.$i.'" name="feature[]" value="'.$list['id'].'" >'.$list['feature'].' </label> '; } $i++; } } ?> <script> function selectimage() { document.getElementById("modules").classList.add('active'); } function validation() { $('#err_name').text(""); $('#err_logo').text(""); $('#err_client').text(""); $('#err_feature').text(""); $('#err_feature1').text(""); $('#err_feature2').text(""); $('#divhallCount').text(""); $('#divlodgeCount').text(""); var nameregex = /^[a-zA-Z ]*$/; var function_hall_name = document.getElementsByName('function_hall_name[]'); var lodge_name = document.getElementsByName('lodge_name[]'); var halls_count = 0; var lodge_count = 0; if (function_hall_name.length>0) { for (var i = 0; i < function_hall_name.length; i++) { if (function_hall_name[i].value!='') { if (!nameregex.test(function_hall_name[i].value)) { halls_count++; } } } } if (lodge_name.length>0) { for (var j = 0; j < lodge_name.length; j++) { if (lodge_name[j].value!='') { if (!nameregex.test(lodge_name[j].value)) { lodge_count++; } } } } if($("#application_name").val()=='') { $('#err_name').text("Please enter the Application Name").css("color", "red"); return false; } else if(!nameregex.test($("#application_name").val())) { $('#err_name').text("Application Name should be alphabets").css("color", "red"); return false; } else if($("#application_client").val() == '') { $('#err_client').text("Please Enter Application Client Name").css("color", "red"); return false; } else if(!nameregex.test($("#application_client").val())) { $('#err_client').text("Client Name should be alphabets").css("color", "red"); return false; } else if($('#application_logo').val().trim()=='') { $('#err_logo').text("Please Select Application Logo").css("color", "red"); return false; } else if($('input[name="feature[]"]:checked').length === 0) { $('#err_feature').text("Please select at least one feature").css("color", "red"); return false; } else if(halls_count>0) { $('#err_feature1').text("Some of the function hall names not valid. Please enter valid function hall name").css("color", "red"); return false; } else if(lodge_count>0) { $('#err_feature2').text("Some of the lodge names not valid. Please enter valid lodge name").css("color", "red"); return false; } } function featureValidation() { var nameregex = /^[a-zA-Z ]*$/; if($("#feature_name").val()=='') { $('#err_addfeature').text("Please Enter Feature Name").css("color", "red"); return false; } else if(!nameregex.test($("#feature_name").val())) { $('#err_addfeature').text("Feature Name should be alphabets").css("color", "red"); return false; } } </script> <style> .md-checkbox label:not(:empty) { padding-left: 0.75em; } .md-checkbox label:before, .md-checkbox label:after { content: ""; position: absolute; left: 0; top: 0; } .md-checkbox { position: relative; margin: 1em 0; text-align: left; } .md-checkbox input[type="checkbox"]:checked+label:before { background: #337ab7; border: none; } .md-checkbox label:before { width: 1.25em; height: 1.25em; background: #fff; border: 2px solid rgba(0, 0, 0, 0.54); border-radius: 0.125em; cursor: pointer; transition: background .3s; } .md-checkbox input[type="checkbox"]:checked+label:after { transform: translate(0.25em, 0.3365384615em) rotate(-45deg); width: 0.75em; height: 0.375em; border: 0.125em solid #fff; border-top-style: none; border-right-style: none; } .md-checkbox input[type="checkbox"] { outline: 0; visibility: hidden; width: 1.25em; margin: 0; display: block; float: left; font-size: inherit; } .md-checkbox label { cursor: pointer; display: inline; line-height: 1.25em; vertical-align: top; clear: both; padding-left: 1px; } label { margin-bottom:10px; } .modal-dialog{ left:inherit; } </style> <!-- Page Content --> <div id="page-content-wrapper"> <div class="container-fluid"> <div class="row border-code"> <div class="col-lg-12 background-bar"> <a href="#menu-toggle" class="btn btn-default" id="menu-toggle"><i class="fa fa-bars" aria-hidden="true"></i></a> </div> </div> <br> <div class="row"> <div class="col-lg-12"> <h2 class="heading">Application Details</h2> <!-- <a class="addBtn" data-toggle="modal" style="cursor:pointer;" data-target="#accessModel">Assign Access</a> --> <div class="col-sm-6 col-sm-offset-3"> <div class="table-responsive1"> <form action="" method="post" enctype="multipart/form-data" onSubmit="return validation()"> <div class="row"> <div class="col-sm-12 labelInner"><label>Application Name</label></div> <div class="col-sm-12"> <input type="text" id="application_name" name="application_name" placeholder="Application Name" class="form-control form-input" > <div class="text-center" id="err_name"></div> </div><br> <div class="col-sm-12 labelInner"><label>Application Client Name</label></div> <div class="col-sm-12"> <input type="text" id="application_client" name="application_client" placeholder="Application Client" class="form-control form-input" > <div class="text-center" id="err_client"></div> </div> <br> <div class="col-sm-12 labelInner"><label>Application Logo</label></div> <div class="col-sm-12"><input type="file" class="form-control form-input accept-image" id="application_logo" name="application_logo" > <img class="img-preview" src="" /> <div class="text-center" id="err_logo"></div> </div> </div> <br> <div class="col-sm-12 labelInner " style="margin-top:10px;"> <label>Features :</label> <?php echo $features;?> <button type="button" class="btn" onclick="showAddFeatureModal()">+</button> <button type="button" class="btn" onclick="showdeleteFeatureModal()">-</button> <div id="err_feature"></div> </div> <br> <div class="col-sm-12" id="count1" style="margin-top:10px;"> <div class="col-sm-12 labelInner"><label>Number of function Halls</label></div> <div class="col-sm-12 labelInner"> <input type="text" id="functionhallcount" name="functionhallcount" onKeyPress="return isNumber(event)" placeholder="Number of functionHall" class="form-control " > <div class="text-center" id="divhallCount"></div> <div class=""> <div class=" text-right" style="margin-top:10px;"> <button type="button" class="btn" onclick="addfunctionhall(0)" >Add Hall</button> </div> <div id="err_feature1"></div> <div class="addhall0 hall00 "> <label>Function Hall Name</label> <input type="text" id="function_hall_name" name="function_hall_name[]" placeholder="Function Hall" class="form-control" > </div> </div> <br> </div> </div> <br> <div class="col-sm-12" id="count2" style="margin-top:10px;"> <div class="col-sm-12 labelInner"><label>Number of Lodges</label></div> <div class="col-sm-12"> <input type="text" id="lodgecount" name="lodgecount" onKeyPress="return isNumber(event)" placeholder="Number of Lodges" class="form-control " > <div class="text-center" id="divlodgeCount"></div> <div class=""> <div class=" text-right" style="margin-top:10px;"> <button type="button" onclick="addlodge(0)" >Add Lodge</button> </div> <div id="err_feature2"></div> <div class="addlodge0 lodge00 "> <div class="labelInner"><label>Lodge Name</label></div> <div class=""><input type="text" id="lodge_name" name="lodge_name[]" placeholder="Lodge Name" class="form-control " > </div> </div> </div> <br> </div> </div> <br> <div class="text-center"> <input type="submit" id="submit" name="submit" class="btn submit-login" value="SUBMIT"> </div> <br> </div> </form> </div> </div> </div> </div> </div> </div> <!-- /#page-content-wrapper --> </div> <!-- Add Feature Modal --> <div class="modal fade" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <!-- Modal Header --> <form method="post" onSubmit="return featureValidation()"> <div class="modal-header"> <h4 class="modal-title">Add Feature</h4> <button type="button" class="close" data-dismiss="modal">×</button> </div> <!-- Modal body --> <div class="modal-body "> <div class="col-sm-12"> <span >Feature Name:</span> <input type="text" style="width:80%;" id="feature_name" name="feature_name" value="" required> <div class="text-center" id="err_addfeature"></div> </div> </div> <!-- Modal footer --> <div class="modal-footer"> <button type="submit" id="submit_add" name="submit_add" class="btn" >Add</button> <button type="button" class="btn" onclick="clearData()" data-dismiss="modal">Cancel</button> </div> </form> </div> </div> </div> <!-- Delete feature model --> <div class="modal fade" id="myModal1"> <div class="modal-dialog"> <div class="modal-content"> <!-- Modal Header --> <form method="post"> <div class="modal-header"> <h4 class="modal-title">Delete Feature</h4> <button type="button" class="close" data-dismiss="modal">×</button> </div> <!-- Modal body --> <div class="modal-body "> <div class="col-sm-12"> <div class="form-group"> <label for="sel1">Select list:</label> <select class="form-control" id="sel1" name="feature_name"> <?php echo $optionData; ?> </select> </div> <div class="text-center" id="err_addfeature"></div> </div> </div> <!-- Modal footer --> <div class="modal-footer"> <button type="submit" id="submit_del" name="submit_del" class="btn" >Delete</button> <button type="button" class="btn" onclick="clearData()" data-dismiss="modal">Cancel</button> </div> </form> </div> </div> </div> <script> $(document).ready(function(){ $("#count1").css("display","none"); $("#count2").css("display","none"); $('.accept-image').change(function() { //alert(); //console.log("krify"); var file = $(this).prop("files")[0]; var reExp = /(\.jpg|\.jpeg|\.png)$/i console.log(file); if(!reExp.exec(file.name)) { $(this).val(); alert('Please select valid image') $(this).removeProp('files'); $(this).val(''); return false } if(file.size>5242880) { alert('Please select a image of max size 5 MB') $(this).removeProp('files'); $(this).val(''); return false } else { readURL(this) } }); }); function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { //console.log(e); //$('.img-preview').attr('src', e.target.result).height(200).width(200); var image = new Image(); image.src = e.target.result; image.onload = function () { var height = this.height; var width = this.width; //alert('width'+width); //alert('Height'+height); //return false; $('.img-preview').attr('src', e.target.result).height(200).width(200); /*if (width!= 252 || height!=354) { alert("Please upload an image as per the dimension 252x354."); $("#video_file").val(''); return false; } else { $('.img-preview').attr('src', e.target.result).height(200).width(200); }*/ }; } reader.readAsDataURL(input.files[0]); } } function addfunctionhall(data) { var a=$('.addhall'+data).length; var count=$("#functionhallcount").val(); $("#divhallCount").text(" "); if(a<count) { var c=a-1; jQuery('.hall'+data+c).after('\ <div class="addhall'+data+' hall'+data+a+'">\ <div class="labelInner"><label>Function Hall Name</label></div>\ <div class="inputDiv"><div class="inputWithAddIcon"><input type="text" id="function_hall_name'+a+'" name="function_hall_name[]" placeholder="Function Hall" class="form-control " required>\ </div>\ <div class=" text-right">\ <input type="button" class="btn btn-danger" onclick="return removemoretext('+a+');" value="X" />\ </div></div>'); } else { if ($("#functionhallcount").val()) { $("#divhallCount").text("You can't exceed the count of function halls").css('color','red'); } else { $("#divhallCount").text("Please enter the number of function halls do you want.").css('color','red'); } } } function showAddFeatureModal() { $('#myModal').modal('show'); } function showdeleteFeatureModal() { $('#myModal1').modal('show'); } function clearData() { $("#feature_name").val(''); } function removemoretext(aq) { jQuery('.hall0'+aq).remove(); } function addlodge(data) { var a=$('.addlodge'+data).length; var count=$("#lodgecount").val(); $("#divlodgeCount").text(" "); if(a<count) { var c=a-1; jQuery('.lodge'+data+c).after('\ <div class="addlodge'+data+' lodge'+data+a+'">\ <div><label>Lodge Name</label></div>\ <div class="inputDiv"><div class="inputWithAddIcon"><input type="text" id="lodge_name'+a+'" name="lodge_name[]" placeholder="Lodge Name" class="form-control " required>\ </div>\ <div class=" text-right">\ <input type="button" class="btn btn-danger" onclick="return removemoretext1('+a+');" value="X" />\ </div></div>'); } else { if ($("#lodgecount").val()) { $("#divlodgeCount").text("You can't exceed the count of lodges").css('color','red'); } else { $("#divlodgeCount").text("Please enter the number of lodges do you want.").css('color','red'); } } } function removemoretext1(aq){ jQuery('.lodge0'+aq).remove(); } function hideinput(type,event) { if(type==1) { if(event.target.checked) { $("#count1").css("display","Block"); } else if(!event.target.checked) { $("#count1").css("display","none"); } } else if(type==2) { if(event.target.checked) { $("#count2").css("display","block"); } else if(!event.target.unchecked) { $("#count2").css("display","none"); } } } </script> <script> function validateNumber(event) { var key = window.event ? event.keyCode : event.which; if (event.keyCode === 8 || event.keyCode === 46) { return true; } else if ( key < 48 || key > 57 ) { return false; } else { return true; } } function isNumber(evt) { var iKeyCode = (evt.which) ? evt.which : evt.keyCode if (iKeyCode != 43 &&iKeyCode != 46 && iKeyCode > 31 && (iKeyCode < 48 || iKeyCode > 57)) return false; return true; } </script> <?php include('footer.html'); ?>