/
var
/
www
/
html
/
stengineers
/
admin
/
Upload FileeE
HOME
<?php header('Access-Control-Allow-Origin: *'); require_once('dbconnection.php'); error_reporting(0); $nmenu_active = "active"; include 'header.php'; ?> <div class="container"> <div class="card o-hidden border-0 shadow-lg my-5"> <div class="card-body p-0"> <!-- Nested Row within Card Body --> <div class="row"> <!-- <div class="col-lg-5 d-none d-lg-block bg-register-image"></div> --> <div class="col-lg-12"> <div class="p-5"> <div class="text-center"> <h1 class="h4 text-gray-900 mb-4">Add News & Events</h1> </div> <form class="user"> <div class="form-group row"> <div class="col-sm-6 mb-3 mb-sm-0"> <input type="text" class="form-control form-control-solid" id="title" name="title" placeholder="Title"> <div class="audit_error" style="color:red;" id="titleErr"></div> </div> <div class="col-sm-6"> <input type="text" class="form-control form-control-solid" id="alt_content" name="alt_content" placeholder="Alt Content"> <div class="audit_error" style="color:red;" id="alt_contentErr"></div> </div> </div> <div class="form-group row"> <div class="col-sm-6 mb-3 mb-sm-0"> <input type="text" class="form-control form-control-solid" id="news_url" name="news_url" placeholder="News Url"> <div class="audit_error" style="color:red;" id="News_urlErr"></div> </div> <div class="col-sm-6"> <select class="form-control form-control-solid" name="status" id="status" > <option value="">Select Status</option> <option value="active">Active</option> <option value="inactive">Inactive</option> </select> <div class="audit_error" style="color:red;" id="statusErr"></div> </div> </div> <div class="form-group row"> <div class="col-sm-6"> <select class="form-control form-control-solid" name="news_type" id="news_type" > <option value="">Select News Type</option> <option value="Upcoming Events">Upcoming Events</option> <option value="Completed">Completed</option> </select> <div class="audit_error" style="color:red;" id="news_Err"></div> </div> <div class="col-sm-6"> <input type="date" class="form-control form-control-solid" id="event_date" name="event_date" placeholder="Event Date"> <div class="audit_error" style="color:red;" id="event_Err"></div> </div> </div> <div class="form-group row"> <!-- <div class="col-sm-1"> <img src="" id="bgimg" width="50" height="50" > </div> <div class="col-sm-5 mb-3 mb-sm-0"> <input type="hidden" id='blog_img' name="blog_img"> <form method="post" action="" enctype="multipart/form-data" id="myform"> <div class="form-control form-control-solid" style="padding-bottom: 45px !important;display: grid;grid-template-columns: 1fr auto;"> <input type="file" id="blogfile" name="blogfile" /> <button type="button" class="btn btn-success" value="Upload" id="blog_upload">Blog image <i class="fas fa-upload"></i></button> </div> </form> <div class="audit_error" style="color:red;" id="blog_imgErr"></div> </div> --> <div class="col-sm-2"> <img src="" id="tpimg" width="50" height="50" > </div> <div class="col-sm-10"> <input type="hidden" id='thumb_img' name="thumb_img"> <form method="post" action="" enctype="multipart/form-data" id="myform"> <!-- <img src="" id="img" width="250" height="250" style="display: none;"> --> <div class="form-control form-control-solid" style="padding-bottom: 45px !important;display: grid;grid-template-columns: 1fr auto;"> <input type="file" id="thumbfile" name="thumbfile" /> <button type="button" class="btn btn-success" value="Upload" id="thumb_upload">Upload Thumb image <i class="fas fa-upload"></i></button> </div> </form> <div class="audit_error" style="color:red;" id="thumb_imgErr"></div> </div> </div> <div class="form-group row"> <div class="col-sm-12"> <input type="hidden" id='gal_img' name="gal_img"> <form method="post" action="" enctype="multipart/form-data" id="myform"> <div class="form-control form-control-solid" style="padding-bottom: 45px !important;display: grid;grid-template-columns: 1fr auto;"> <input type="file" id="galfile" name="galfile[]" multiple /> <button type="button" class="btn btn-success" value="Upload" id="gal_upload">Upload Gallery image <i class="fas fa-upload"></i></button> </div><br> <div id="galimg"></div> </form> <div class="audit_error" style="color:red;" id="gal_imgErr"></div> </div> </div> <div class="form-group"> <textarea class="form-control form-control-solid" id="description" placeholder="Description" name="description" rows="3"></textarea> <div class="audit_error" style="color:red;" id="descriptionErr"></div> </div> <div class="form-group row"> <div id="summernote"></div> <div class="audit_error" style="color:red;" id="bcontentErr"></div> </div> <div class="form-group row text-center"> <button type="button" onclick="validateclientForm1()" id="client-submit" class="btn btn-primary" value="Add News" data-keyboard="false">Add News</button> </div> <div id="succ-client-alert" style='color: green;'></div> <div id="fail-client-alert" style='color: red;'></div> </form> <hr> </div> </div> </div> </div> </div> </div> <script type="text/javascript"> $(document).ready(function(){ $("#gal_upload").click(function(){ var fd = new FormData(); var totalfiles = document.getElementById('galfile').files.length; for (var index = 0; index < totalfiles; index++) { fd.append("files[]", document.getElementById('galfile').files[index]); } $.ajax({ url: 'api/news-upload.php', type: 'post', data: fd, contentType: false, processData: false, success: function(response){ var response = JSON.parse(response); if(response != 0){ // $('#galimg').append('<img src="'+response[index]+'" width="200px;" height="200px">'); for (var index = 0; index < response.length; ++index) { var data= response[index]; console.log("data",data); $('#galimg').append('<img class="btn-delete" style="width:25px; height:25px;" src="img/remove-icon.png" onclick=deleteimg(\'' + name + '\',"'+data+'") />','<img src="'+data+'" width="200px;" height="200px" style="margin-right:10px">'); } $("#gal_img").val(response); // $("#edit_frontimgname").val(response); // $('#galimg').html(responseObject); // $("#gal_img").show(); // Display image element }else{ alert('file not uploaded'); } }, }); }); }); </script> <script type="text/javascript"> $(document).ready(function(){ $("#thumb_upload").click(function(){ var fd = new FormData(); var files = $('#thumbfile')[0].files[0]; fd.append('file',files); $.ajax({ url: 'api/newsthum-upload.php', type: 'post', data: fd, contentType: false, processData: false, success: function(response){ if(response != 0){ $("#tpimg").attr("src",response); $("#thumb_img").val(response); // $("#img").show(); // Display image element }else{ alert('file not uploaded'); } }, }); }); }); </script> <script> $('#summernote').summernote({ placeholder: 'News Content', tabsize: 2, height: 120, toolbar: [ ['style', ['style']], ['font', ['bold', 'underline', 'clear']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], ['insert', ['link', 'picture', 'video']], ['view', ['fullscreen', 'codeview', 'help']] ] }); </script> <script type="text/javascript"> function printError(elemId, hintMsg) { document.getElementById(elemId).innerHTML = hintMsg; } function validateclientForm1() { $('#succ-client-alert').html(''); $('#fail-client-alert').html(''); var title = $('#title').val(); var alt_content = $('#alt_content').val(); var news_url = $('#news_url').val(); var description = $('#description').val(); var news_type = $('#news_type').val(); var event_date = $('#event_date').val(); var status = $('#status').val(); var gal_img = $('#gal_img').val(); // var news_img = "" ; // var blog_img = $("#blog_img").val(); var thumb_img = $("#thumb_img").val(); var bcontent = $(".note-editable").html(); // var bcontent = $('#summernote').summernote(); var titleErr = thumb_imgErr = gal_imgErr = News_urlErr = event_Err = descriptionErr = news_Err = statusErr = bcontentErr = true; if(title == "") { printError("titleErr", "Enter News Title"); } else { printError("titleErr", ""); titleErr = false; } if(news_url == "") { printError("News_urlErr", "Enter News Url"); } else { printError("News_urlErr", ""); News_urlErr = false; } if(description == "") { printError("descriptionErr", "Enter short description"); } else { printError("descriptionErr", ""); descriptionErr = false; } if(gal_img == "") { printError("gal_imgErr", "Upload Gallery Image"); } else { printError("gal_imgErr", ""); gal_imgErr = false; } if(thumb_img == "") { printError("thumb_imgErr", "Upload News Image"); } else { printError("thumb_imgErr", ""); thumb_imgErr = false; } if(status == "") { printError("statusErr", "Select status"); } else { printError("statusErr", ""); statusErr = false; } if(news_type == "") { printError("news_Err", "Select News Type"); } else { printError("news_Err", ""); news_Err = false; } if(event_date == "") { printError("event_Err", "Enter Event Date"); } else { printError("event_Err", ""); event_Err = false; } if(bcontent == '<p><br></p>' || bcontent=='') { printError("bcontentErr", "Enter News Content"); } else { printError("bcontentErr", ""); bcontentErr = false; } if((titleErr || thumb_imgErr || News_urlErr || news_Err || event_Err || gal_imgErr || descriptionErr || statusErr || bcontentErr ) == true) { alert("sd") return false; } else{ $.ajax({ url: 'api/admin-news.php', type: 'POST', data:{title:title, news_url:news_url, alt_content:alt_content, status:status, description:description,news_type:news_type,event_date:event_date, gal_img:gal_img, thumb_img:thumb_img, bcontent:bcontent, referer:"ezioaws", action:"addnews"}, success: function(data) { console.log(data.status,'data'); var data = JSON.parse(data); if(data.status=="success") { $('#succ-client-alert').html('Added Successfully'); $('#fail-client-alert').html(''); setTimeout(function() { window.location.href="news_events.php"; }, 1000); } else { $('#succ-client-alert').html(''); $('#fail-client-alert').html(data.message); } } }); } } </script> <?php include 'footer.php'?>