| Server IP : 74.208.250.37 / Your IP : 216.73.217.68 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : miferval ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/brainwavemx/resources/templates/admin/ |
Upload File : |
<?php
$this->layout('admin/layout/mainEdit', [
'title' => $post['action'],
'env' => $env,
'tags' => $tags
]);
if (!isset($post['id_post']) ) {
$id_post = 0;
$title = '';
$url_name = '';
$resume = '';
$content = '';
$metaD = '';
$metaT = '';
$id_author = 1;
$publish = date('Y-m-d H:i:s');
$image = '';
$frontpage = 0;
$modalTitle = 'Add Image';
} else {
$id_post = $post['id_post'];
$title = $post['title'];
$url_name = $post['url_name'];
$resume = $post['resume'];
$content = $post['content'];
$metaD = $post['meta_description'];
$metaT = $post['meta_tags'];
$id_author = $post['id_user'];;
$publish = date('Y-m-d H:i:s');
$image = $post['image'];
$frontpage = $post['is_frontpage'];
$modalTitle = 'Update Image';
}
$pt = [];
if (!empty($postTags)) {
//print_r($postTags);//debug
foreach ($postTags as $postT) {
array_push($pt, $postT['id_tag']);
}
}
//print_r($pt);//debug
?>
<div id="main">
<div class="container-fluid">
<div class="row pt-2 mb-2 border-bottom">
<div class="col-md-2">
<h4 id="action" class="text-dark font-weight-bolder">
<?= $post['action'] ?>
</h4>
</div>
<div class="col-md-10">
<div id="alertMessage" class="alert text-center h5"></div>
</div>
</div>
<div class="pb-2">
<form method="post">
<input type="hidden" name="id_post" id="id_post" value="<?= $id_post ?>">
<div class="row">
<div class="col-md-10">
<div class="form-group pb-2">
<label for="title" class="h4">Post Title</label>
<input id="postTitle" type="text" name="title" value="<?= $title ?>" class="form-control" />
</div>
<div class="form-group pb-2">
<label for="postUrl" class="h4">Post URL</label>
<input id="postUrl" type="text" name="url_name" value="<?= $url_name ?>" class="form-control" />
</div>
<div class="form-group pb-2">
<label for="title" class="h4">Post Content</label>
<div id="postContent" class="form-control"><?= $content ?></div>
</div>
<div class="form-group pb-2">
<label for="title" class="h4">Post Resume</label>
<textarea id="postResume" class="form-control"><?= $resume ?></textarea>
</div>
<div class="form-group pb-2">
<label for="metaDescription" class="h4">Meta Description</label>
<input id="metaDescription" type="text" name="metaDescription" value="<?= $metaD ?>" class="form-control" />
</div>
<div class="form-group pb-2">
<label for="metaTags" class="h4">Meta Tags</label>
<input id="metaTags" type="text" name="meta_tags" value="<?= $metaT ?>" class="form-control" />
</div>
</div>
<div class="col-md-2">
<div class="form-group pb-2">
<div class="row">
<div class="col-6">
<label for="image" class="h4">Post Image</label>
</div>
<div class="col-6">
<?php if (!empty($image)) : ?>
<div id="update_image" class="btn btn-primary ms-2 mb-2" data-bs-toggle="modal" data-bs-target="#imageModal">Edit Image</div>
<?php else : ?>
<div id="create_image"class="btn btn-warning ms-2 mb-2" data-bs-toggle="modal" data-bs-target="#imageModal">Add Image</div>
<?php endif; ?>
</div>
</div>
<input id="image" type="text" name="image" value="<?= $image ?>" class="form-control" />
<div id="image_box" class="pt-2" >
<img id="image_view" src="<?= $image ?>" class="img-fluid">
</div>
</div>
<div class="form-group pb-2">
<div class="pb-2">
<label for="author" class="h4">Author</label>
</div>
<select name="author" id="author" class="form-control">
<option value="0">Select</option>
<?php foreach ($authors as $author) : ?>
<?php
$selected = $id_author == $author['id_user'] ?
'selected="selected"' :
'';
?>
<option value="<?= $author['id_user'] ?>" <?= $selected ?>>
<?= $author['firstname'] ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group pb-2">
<div class="pb-2">
<label for="author" class="h4">Is FrontPage</label>
</div>
<div>
<?php
if ($frontpage == 0) {
$yes = '';
$no = 'checked';
} else {
$yes = 'checked';
$no = '';
}
?>
<label>Yes</label>
<input type="radio"
name="is_frontpage"
value="1"
<?= $yes ?> />
</div>
<div>
<label>No</label>
<input type="radio"
name="is_frontpage"
value="0"
<?= $no ?> />
</div>
</div>
<div class="form-group pb-2">
<div class="pb-2">
<label for="author" class="h4">Tags</label>
</div>
<?php foreach ($tags as $tag) : ?>
<?php if (!empty($pt)) {
in_array($tag['id_tag'], $pt) ?
$checked = 'checked' :
$checked = '';
} else {
$checked = '';
}
?>
<div>
<input type="checkbox"
class="posttag"
id="<?= $tag['id_tag'] ?>"
data-id="<?= $tag['id_tag'] ?>"
data-id_post="<?= $id_post ?>"
<?= $checked ?>>
<label for="<?= $tag['tag_url'] ?>">
<?= $tag['tag_name'] ?>
</label>
</div>
<?php endforeach; ?>
</div>
<div class="form-group pb-2">
<label for="publishDate" class="h4">Publish Date</label>
<input id="publishDate" type="text" name="publishDate" value="<?= $publish ?>" class="form-control" />
</div>
</div>
</div>
<div class="pb-2">
<div id="postSubmit" class="btn btn-primary form-control">submit</div>
</div>
</form>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="imageModal" tabindex="-1" aria-labelledby="imageModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content p-2">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><?= $modalTitle ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div id="alert_image" class="alert text-center m-0"> </div>
<form
id="fileupload"
action=""
method="POST"
enctype="multipart/form-data"
>
<input type="hidden" name="id_post" value="<?= $id_post ?>">
<input type="hidden" name="do" value="<?= $post['action'] ?>" />
<input type="hidden" id="validate_file" value="0" name="validate_file">
<div class="row bg-light pt-2">
<div class="col-12">
<div class="btn btn-success fileinput-button">
<i class="fa fa-plus d-inline"></i>
<span>Select File</span>
<input type="file" name="files[]" multiple />
</div>
<div class="btn btn-primary text-center"
data-file=""
data-name=""
data-size=""
data-content=""
id="file_save">
<i class="fa fa-upload"></i>
<span>Confirm</span>
</div>
<div class="btn btn-warning text-center text-white"
data-file=""
data-name=""
data-size=""
id="file_cancel">
<i class="fa fa-ban"></i>
<span>Cancel</span>
</div>
<div class="btn btn-primary d-none" id="submit_image">Save Changes</div>
</div>
</div>
<div class="row bg-light">
<div class="col-lg-4 py-2 text-center" id="archivo">
</div>
<div class="col-lg-3 py-2">
<label>File Name</label>
<input type="text" name="file_name" id="file_name"
class="form-control" />
</div>
<div class="col-lg-2 py-2">
<label>Size</label>
<input type="text" class="form-control bg-light" id="file_size" disabled />
</div>
</div>
<div class="row py-2">
<div class="col-12">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$('#postTitle').on('focusout', function(){
var title = $('#postTitle').val();
$.ajax({
type : 'POST',
url : '/<?= $env['ADMIN'] ?>/post/url-name',
data : {
'title' : title
},
success : function(response) {
console.log('response' + response);
$('#postUrl').val(response);
}
});
});
$('.posttag').on('change', function(){
if ($(this).is(':checked')) {
var tag = 1;
} else {
var tag = 0;
}
var id_tag = $(this).data('id');
var id_post = $(this).data('id_post');
if (id_post !== 0 ) {
console.log(id_tag + ' / ' + tag);
$.ajax({
type : 'POST',
url : '/<?= $env['ADMIN'] ?>/post/tags',
data : {
'tag' : tag,
'id_tag' : id_tag,
'id_post' : id_post
},
success : function(response) {
}
});
}
});
$('#postSubmit').on('click', function(){
var id_post = $('#id_post').val();
var content = tinymce.activeEditor.getContent();
//var resume = tinymce.get('postResume').getContent();
var resume = $('#postResume').val();
var title = $('#postTitle').val();
var url_name = $('#postUrl').val();
var image = $('#image').val();
var metadesc = $('#metaDescription').val();
var metatags = $('#metaTags').val();
var publish = $('#publishDate').val();
var is_frontpage = $('input[name="is_frontpage"]:checked').val();
console.debug('resume: ' + title);
console.debug('resume: ' + resume);
console.debug(content);
$.ajax({
type : 'POST',
url : '/<?= $env['ADMIN'] ?>/post/process',
data : {
'id_post' : id_post,
'title' : title,
'url_name' : url_name,
'resume' : resume,
'content' : content,
'image' : image,
'meta_description' : metadesc,
'meta_tags' : metatags,
'publish_date' : publish,
'is_frontpage' : is_frontpage },
success : function(response) {
var data = JSON.parse(response);
console.log('message' + data.message);
window.scrollTo(0, 0);
$('#id_post').val(data.id_post);
$('#action').html('Update Post');
$("#alertMessage").addClass("alert-success").
removeClass("d-none").
html("Post has been saved");
setTimeout(function() {
$("#alertMessage").removeClass("alert-success").
html(" ");
}, 3000);
}
});
});
$("input:file").change(function (){
var fileObject = event.target.files[0];
var fileName = event.target.files[0].name;
var fileType = event.target.files[0].type;
var fileSize = event.target.files[0].size;
var file = URL.createObjectURL(event.target.files[0]);
console.log('file: '+file);
console.log('name: '+fileName);
console.log('type: '+fileType);
console.log('size: '+fileSize);
$("#archivo").html('<img src="'+file+'" class="img-fluid">');
$("#file_name").val(fileName);
$("#file_size").val(fileSize);
$("#file_save").data('file',fileObject);
$("#file_save").data('name',fileName);
$("#file_save").data('size',fileSize);
$("#validate_file").val(1);
});
$("#file_save").click(function(){
var file = $(this).data('file');
var content = $(this).data('content');
var fileName = file.name;
var fileSize = file.size;
var fileType = file.type;
const reader = new FileReader();
reader.addEventListener("load", function () {
// convert image file to base64 string
var archivo = reader.result;
var data = {'file': archivo,'name':fileName,'size':fileSize,'type':fileType,'content' : content} ;
console.log(data);
$.ajax({
type :'POST',
data : data,
url : '/<?= $env['ADMIN'] ?>/post/imageupload',
success : function(html){
console.log('debug_1: ' + html);
var result = $.parseJSON(html);
console.log('debug_2: ' + result);
if(result.error.length == 0){
$("#validate_file").val(2);
$("#file_name").val(result.fileName);
$("#alert_image").addClass('alert-success').
html('Archivo Confirmado').
delay(3000).fadeOut(function(){
$(this).removeClass("alert-success").
removeAttr('style').
html(' ');
});
$("#submit_image").removeClass('d-none');
}else{
$("#alert_image").addClass('alert-danger').
html(result.error).
delay(3000).fadeOut(function(){
$(this).removeClass("alert-danger").removeAttr('style').
html(' ');
});
$("#validate_file").val(0);
}
}
});
});
if (file) {
reader.readAsDataURL(file);
}
});
$("#file_cancel").click(function(){
if($("#file_name").val().length !== 0){
$("#alert_image").addClass('alert-warning').
html('Archivo Cancelado').
delay(3000).fadeOut(function(){
$(this).removeClass("alert-warning").
removeAttr('style').
html(' ');
});
$("#submit_image").addClass('d-none');
}
clearFile();
//TODO borrar archivo del servidor si ya fue validado
});
function clearFile(){
$("#file_name").val('');
$("#file_size").html('');
$("#archivo").html('');
$("#file_save").data('file','');
$("#file_save").data('name','');
$("#file_save").data('size','');
$("#validate_file").val(0);
}
$("#submit_image").click(function(){
var archivo = $("#validate_file").val();
switch(archivo){
case '0' :
var message = 'es necesario seleccionar un archivo';
console.log(message);
$("#alert_image").addClass('alert-danger').html(message).
delay(3000).fadeOut(function(){
$(this).removeClass("alert-danger").removeAttr('style').
html(' ');
});
break;
case '1' :
var message = 'es necesario confirmar el archivo';
console.log(message);
$("#alert_image").addClass('alert-danger').html(message).
delay(3000).fadeOut(function(){
$(this).removeClass("alert-danger").removeAttr('style').
html(' ');
});
break;
case '2' :
$("#alert_image").addClass('alert-loading');
var dataString = $("#fileupload").serialize();
console.log('submit: ' + dataString);
$.ajax({
type : 'POST',
data : dataString,
url :'/<?= $env['ADMIN'] ?>/post/imageupload',
success : function(response){
//reset fileupload form
$("#alert_image").removeClass('alert-loading');
clearFile();
document.getElementById("fileupload").reset();
//closeModal();
//
$("#image_view").attr('src', response);;
$("#image").val(response);
}
});
break;
default:
}
});
</script>
</div>