/
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'; $news_id = $_GET['id']; $row1=mysqli_query($con,"select * from news_events as a where a.id='$news_id'"); $row2=mysqli_fetch_array($row1); $title = $row2['title']; $thumb_img = $row2['thump_image']; $gal_img = $row2['gal_img']; $bcontent = $row2['news_content']; $alt_content = $row2['alt_content']; $news_url = $row2['news_url']; $description = $row2['description']; $news_type = $row2['news_type']; $event_date = $row2['event_date']; $status = $row2['status']; $gallery_array = explode(",", $gal_img); // $gallery_json =json_encode($gallery_array); ?> <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">Edit News & Events</h1> </div> <form class="user"> <input type="hidden" id='edit_gallery' name="edit_gallery"> <input type="hidden" class="form-control form-control-solid" id="news_id" name="news_id" value="<?php echo $news_id ?>" placeholder="Title"> <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" value="<?php echo $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" value="<?php echo $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" value="<?php echo $news_url ?>" placeholder="Blog 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</option> --> <option value="active" <?php if($status == 'active') { ?> selected="selected"<?php } ?>>Active</option> <option value="inactive" <?php if($status == 'inactive') { ?> selected="selected"<?php } ?>>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" <?php if($news_type == 'Upcoming Events') { ?> selected="selected"<?php } ?>>Upcoming Events</option> <option value="Completed" <?php if($news_type == 'Completed') { ?> selected="selected"<?php } ?>>Completed</option> </select> <div class="audit_error" style="color:red;" id="news_type_Err"></div> </div> <div class="col-sm-6"> <input type="date" class="form-control form-control-solid" id="event_date" name="event_date" value="<?php echo $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="<?php echo $news_img ?>" id="bgimg" width="50" height="50" > </div> <div class="col-sm-5 mb-3 mb-sm-0"> <input type="hidden" id='news_img' name="news_img" value="<?php echo $news_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 id="succ-image-alert" style='color: green;'></div> <div class="audit_error" style="color:red;" id="news_imgErr"></div> </div> --> <div class="col-sm-2"> <img src="<?php echo $thumb_img ?>" id="tpimg" width="50" height="50" > </div> <div class="col-sm-10"> <input type="hidden" id='thumb_img' name="thumb_img" value="<?php echo $thumb_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="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 id="succ-thumb-alert" style='color: green;'></div> <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" value='' > --> <input type="hidden" id='gallery_array' name="gallery_array[]" value="<?php echo $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="<?php echo $gallery_array ?>" id="gal_upload">Click Here to Upload Gallery image <i class="fas fa-upload"></i></button> --> <button type="button" class="btn btn-success" value="<?php echo $gal_img ?>" id="gal_upload">Upload Gallery image <i class="fas fa-upload"></i></button> </div> <br> <div id='galimg'> <?php for ($i=0; $i < count($gallery_array) ; $i++) { if($gallery_array[$i]!="") { echo "<span id='galimgdels$i'><img class=btn-delete style=width:20px; height:20px src=img/remove-icon.png onclick=deleteimg('".$gallery_array[$i]."','".$i."') /> ,<img src='".$gallery_array[$i]."' width=200px height=200px class='dele' ></span>"; } } ?> </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" ><?php echo $description ?></textarea> <div class="audit_error" style="color:red;" id="descriptionErr"></div> </div> <div class="form-group row"> <div id="summernote"><?php echo $bcontent ?></div> <div class="audit_error" style="color:red;" id="bcontentErr"></div> </div> <div class="form-group row text-center"> <button type="button" onclick="validateclientForm()" id="client-submit" class="btn btn-primary" value="Update Blog" data-keyboard="false">Update News</button> <!-- <a href="login.html" class="btn btn-primary"> Submit </a> --> </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(){ $("#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); $('#succ-thumb-alert').html("image uploaded"); // $("#img").show(); // Display image element }else{ alert('file not uploaded'); } }, }); }); }); </script> <script type="text/javascript"> $(document).ready(function(){ $("#gal_upload").click(function(){ // gallery = JSON.parse(gallery); 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){ var nimg = ""; for (var index = 0; index < response.length; ++index) { var data= response[index]; $('#galimg').append("<span id='galimgdelss"+index+"'><img class=btn-delete style=width:20px; height:20px; src=img/remove-icon.png onclick=deleteimgs('"+data+"','"+index+"') /><img src='"+data+"' width=200px height=200px style=margin-right:10px class=dele></span>"); nimg+=","+data; } var gallery_array =$('#gallery_array').val(); var newVal = gallery_array + nimg; $('#gallery_array').val(newVal); }else{ alert('file not uploaded'); } }, }); }); }); </script> <script> function deleteimg(data,ival) { if (confirm("Are you really want to delete ?")) { $("#galimgdels"+ival).hide(); var gallery_array =$('#gallery_array').val(); var nimg = gallery_array.replace(data,''); $('#gallery_array').val(nimg); } } function deleteimgs(data,ival) { if (confirm("Are you really want to delete ?")) { $("#galimgdelss"+ival).hide(); var gallery_array =$('#gallery_array').val(); var nimg = gallery_array.replace(data,''); $('#gallery_array').val(nimg); } } </script> <script> $('#summernote').summernote({ placeholder: 'Blog 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 validateclientForm() { $('#succ-client-alert').html(''); $('#fail-client-alert').html(''); var news_id = $('#news_id').val(); 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 news_img = $("#news_img").val(); var gallery_array = $('#gallery_array').val(); var thumb_img = $("#thumb_img").val(); var bcontent = $(".note-editable").html(); // var bcontent = $('#summernote').summernote(); console.log(thumb_img,"images") var titleErr = thumb_imgErr = news_urlErr = gal_imgErr = descriptionErr = news_type_Err = event_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(thumb_img == "") { printError("thumb_imgErr", "Upload News Image"); } else { printError("thumb_imgErr", ""); thumb_imgErr = false; } if(gallery_array == "") { printError("gal_imgErr", "Upload Gallery Image"); } else { printError("gal_imgErr", ""); gal_imgErr = false; } if(status == "") { printError("statusErr", "Select Status"); } else { printError("statusErr", ""); statusErr = false; } if(news_type == "") { printError("news_type_Err", "Enter News Type"); } else { printError("news_type_Err", ""); news_type_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_type_Err || gal_imgErr || event_Err || descriptionErr || statusErr || bcontentErr ) == true) { return false; } else{ $.ajax({ url: 'api/admin-news.php', type: 'POST', data:{title:title, id:news_id, news_url:news_url,gal_img:gallery_array, alt_content:alt_content, status:status,event_date:event_date, description:description, news_type:news_type, thumb_img:thumb_img, bcontent:bcontent, referer:"ezioaws", action:"updatenews1"}, success: function(data) { console.log(data.status,'data'); var data = JSON.parse(data); if(data.status=="success") { $('#succ-client-alert').html(data.message); $('#fail-client-alert').html(''); setTimeout(function() { window.location.href="news_events.php"; }, 2000); } else { $('#succ-client-alert').html(''); $('#fail-client-alert').html(data.message); } } }); } } </script> <?php include 'footer.php'?>